public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	Jan Kara <jack@suse.cz>, Ming Lei <ming.lei@redhat.com>,
	Damien Le Moal <Damien.LeMoal@wdc.com>
Subject: Re: [PATCH 1/2] block: Hold invalidate_lock in BLKDISCARD ioctl
Date: Tue, 9 Nov 2021 12:59:22 +0100	[thread overview]
Message-ID: <20211109115922.GD5955@quack2.suse.cz> (raw)
In-Reply-To: <20211109104723.835533-2-shinichiro.kawasaki@wdc.com>

On Tue 09-11-21 19:47:22, Shin'ichiro Kawasaki wrote:
> 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.
> 
> Fixes: 351499a172c0 ("block: Invalidate cache on discard v2")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Cc: stable@vger.kernel.org # v5.15

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/ioctl.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/block/ioctl.c b/block/ioctl.c
> index d6af0ac97e57..9fa87f64f703 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -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,
> -- 
> 2.33.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2021-11-09 11:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-09 10:47 [PATCH 0/2] block: Fix stale page cache of discard or zero out ioctl Shin'ichiro Kawasaki
2021-11-09 10:47 ` [PATCH 1/2] block: Hold invalidate_lock in BLKDISCARD ioctl Shin'ichiro Kawasaki
2021-11-09 11:59   ` Jan Kara [this message]
2021-11-09 10:47 ` [PATCH 2/2] block: Hold invalidate_lock in BLKZEROOUT ioctl Shin'ichiro Kawasaki
2021-11-09 11:59   ` Jan Kara
2021-11-09 11:07 ` [PATCH 0/2] block: Fix stale page cache of discard or zero out ioctl Ming Lei
2021-11-09 11:59   ` Jan Kara
2021-11-09 12:49     ` Shinichiro Kawasaki
2021-11-09 14:33 ` Jens Axboe
2021-11-10  1:13   ` Shinichiro Kawasaki
2021-11-09 17:11 ` Jens Axboe
2021-11-10  6:37 ` Chaitanya Kulkarni
2021-11-10  6:47   ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211109115922.GD5955@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=Damien.LeMoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox