FAILED: patch "[PATCH] block: Hold invalidate_lock in BLKDISCARD ioctl" failed to apply to 4.19-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7607c44c157d343223510c8ffdf7206fdd2a6213 Mon Sep 17 00:00:00 2001
From: Shin'ichiro Kawasaki <[email protected]>
Date: Tue, 9 Nov 2021 19:47:22 +0900
Subject: [PATCH] block: Hold invalidate_lock in BLKDISCARD ioctl
When BLKDISCARD ioctl and data read race, the data read leaves stale page cache. To avoid the stale page cache, hold invalidate_lock of the block device file mapping. The stale page cache is observed when blktests test case block/009 is repeated hundreds of times.
This patch can be applied back to the stable kernel version v5.15.y with slight patch edit. Rework is required for older stable kernels.
block/ioctl.c +9 -3
@@ -113,6 +113,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,uint64_t range[2 ];uint64_t start, len;struct request_queue *q =bdev_get_queue (bdev); +struct inode *inode = bdev->bd_inode;int err;if (!(mode &FMODE_WRITE ))
@@ -135,12 +136,17 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,if (start + len >bdev_nr_bytes (bdev))return -EINVAL ; +filemap_invalidate_lock (inode->i_mapping); err =truncate_bdev_range (bdev, mode, start, start + len -1 );if (err) -return err; + goto fail; + + err =blkdev_issue_discard (bdev, start >>9 , len >>9 , +GFP_KERNEL , flags); -return blkdev_issue_discard (bdev, start >>9 , len >>9 , -GFP_KERNEL , flags); +fail: +filemap_invalidate_unlock (inode->i_mapping); +return err; } static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,