Re: Patch "block: fix scan partition for exclusively open device again" has been added to the 6.2-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 07, 2023 at 07:27:59AM -0700, Jens Axboe wrote:
> On 3/7/23 2:58 AM, gregkh@xxxxxxxxxxxxxxxxxxx wrote:
> > 
> > This is a note to let you know that I've just added the patch titled
> > 
> >     block: fix scan partition for exclusively open device again
> > 
> > to the 6.2-stable tree which can be found at:
> >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > 
> > The filename of the patch is:
> >      block-fix-scan-partition-for-exclusively-open-device-again.patch
> > and it can be found in the queue-6.2 subdirectory.
> > 
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@xxxxxxxxxxxxxxx> know about it.
> > 
> > 
> > From e5cfefa97bccf956ea0bb6464c1f6c84fd7a8d9f Mon Sep 17 00:00:00 2001
> > From: Yu Kuai <yukuai3@xxxxxxxxxx>
> > Date: Fri, 17 Feb 2023 10:22:00 +0800
> > Subject: block: fix scan partition for exclusively open device again
> > 
> > From: Yu Kuai <yukuai3@xxxxxxxxxx>
> > 
> > commit e5cfefa97bccf956ea0bb6464c1f6c84fd7a8d9f upstream.
> > 
> > As explained in commit 36369f46e917 ("block: Do not reread partition table
> > on exclusively open device"), reread partition on the device that is
> > exclusively opened by someone else is problematic.
> > 
> > This patch will make sure partition scan will only be proceed if current
> > thread open the device exclusively, or the device is not opened
> > exclusively, and in the later case, other scanners and exclusive openers
> > will be blocked temporarily until partition scan is done.
> > 
> > Fixes: 10c70d95c0f2 ("block: remove the bd_openers checks in blk_drop_partitions")
> > Cc: <stable@xxxxxxxxxxxxxxx>
> > Suggested-by: Jan Kara <jack@xxxxxxx>
> > Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
> > Reviewed-by: Christoph Hellwig <hch@xxxxxx>
> > Link: https://lore.kernel.org/r/20230217022200.3092987-3-yukuai1@xxxxxxxxxxxxxxx
> > Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > ---
> >  block/genhd.c |   30 ++++++++++++++++++++++++++----
> >  block/ioctl.c |    3 +--
> >  2 files changed, 27 insertions(+), 6 deletions(-)
> > 
> > --- a/block/genhd.c
> > +++ b/block/genhd.c
> > @@ -359,6 +359,7 @@ EXPORT_SYMBOL_GPL(disk_uevent);
> >  int disk_scan_partitions(struct gendisk *disk, fmode_t mode, void *owner)
> >  {
> >  	struct block_device *bdev;
> > +	int ret = 0;
> >  
> >  	if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
> >  		return -EINVAL;
> > @@ -371,11 +372,27 @@ int disk_scan_partitions(struct gendisk
> >  		return -EBUSY;
> >  
> >  	set_bit(GD_NEED_PART_SCAN, &disk->state);
> > -	bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL);
> > +	/*
> > +	 * If the device is opened exclusively by current thread already, it's
> > +	 * safe to scan partitons, otherwise, use bd_prepare_to_claim() to
> > +	 * synchronize with other exclusive openers and other partition
> > +	 * scanners.
> > +	 */
> > +	if (!(mode & FMODE_EXCL)) {
> > +		ret = bd_prepare_to_claim(disk->part0, disk_scan_partitions);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXCL, NULL);
> >  	if (IS_ERR(bdev))
> > -		return PTR_ERR(bdev);
> > -	blkdev_put(bdev, mode);
> > -	return 0;
> > +		ret =  PTR_ERR(bdev);
> > +	else
> > +		blkdev_put(bdev, mode);
> > +
> > +	if (!(mode & FMODE_EXCL))
> > +		bd_abort_claiming(disk->part0, disk_scan_partitions);
> > +	return ret;
> >  }
> >  
> >  /**
> > @@ -497,6 +514,11 @@ int __must_check device_add_disk(struct
> >  		if (ret)
> >  			goto out_unregister_bdi;
> >  
> > +		/* Make sure the first partition scan will be proceed */
> > +		if (get_capacity(disk) && !(disk->flags & GENHD_FL_NO_PART) &&
> > +		    !test_bit(GD_SUPPRESS_PART_SCAN, &disk->state))
> > +			set_bit(GD_NEED_PART_SCAN, &disk->state);
> > +
> >  		bdev_add(disk->part0, ddev->devt);
> >  		if (get_capacity(disk))
> >  			disk_scan_partitions(disk, FMODE_READ, NULL);
> > --- a/block/ioctl.c
> > +++ b/block/ioctl.c
> > @@ -528,8 +528,7 @@ static int blkdev_common_ioctl(struct fi
> >  			return -EACCES;
> >  		if (bdev_is_partition(bdev))
> >  			return -EINVAL;
> > -		return disk_scan_partitions(bdev->bd_disk, mode & ~FMODE_EXCL,
> > -					    file);
> > +		return disk_scan_partitions(bdev->bd_disk, mode, file);
> >  	case BLKTRACESTART:
> >  	case BLKTRACESTOP:
> >  	case BLKTRACETEARDOWN:
> 
> Turns out there was a bug in this one, fix is queued up here:
> 
> https://git.kernel.dk/cgit/linux-block/commit/?h=block-6.3&id=428913bce1e67ccb4dae317fd0332545bf8c9233
> 
> so we should probably drop this one for now until the fix hits
> mainline too.

Ok, now dropped from 6.1.y and 6.2.y.  Let us know when we can pick this
up and the fixup patch.

thanks,

greg k-h



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux