]> git.baikalelectronics.ru Git - kernel.git/commit
block: hold ->invalidate_lock in blkdev_fallocate
authorMing Lei <ming.lei@redhat.com>
Thu, 23 Sep 2021 02:37:51 +0000 (10:37 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 24 Sep 2021 17:06:58 +0000 (11:06 -0600)
commit46192141ed92cecab6e9e76ec504b0b2753be583
tree86c4b040a5325188562ef075c9256d32de6fdff7
parent31729cd1f1f02c15c8d5dc9ad63b73ef07a71aa3
block: hold ->invalidate_lock in blkdev_fallocate

When running ->fallocate(), blkdev_fallocate() should hold
mapping->invalidate_lock to prevent page cache from being accessed,
otherwise stale data may be read in page cache.

Without this patch, blktests block/009 fails sometimes. With this patch,
block/009 can pass always.

Also as Jan pointed out, no pages can be created in the discarded area
while you are holding the invalidate_lock, so remove the 2nd
truncate_bdev_range().

Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20210923023751.1441091-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/fops.c