All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org
Subject: Re: [PATCH 1/2] block: grab a device refcount in disk_uevent
Date: Thu, 1 Jul 2021 17:17:22 +0800	[thread overview]
Message-ID: <YN2IIiKUvquxqx6k@T590> (raw)
In-Reply-To: <20210701090232.GA31321@lst.de>

On Thu, Jul 01, 2021 at 11:02:32AM +0200, Christoph Hellwig wrote:
> On Thu, Jul 01, 2021 at 04:54:05PM +0800, Ming Lei wrote:
> > On Thu, Jul 01, 2021 at 10:16:37AM +0200, Christoph Hellwig wrote:
> > > Sending uevents requires the struct device to be alive.  To
> > > ensure that grab the device refcount instead of just an inode
> > > reference.
> > > 
> > > Fixes: bc359d03c7ec ("block: add a disk_uevent helper")
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > > ---
> > >  block/genhd.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/block/genhd.c b/block/genhd.c
> > > index 79aa40b4c39c..af4d2ab4a633 100644
> > > --- a/block/genhd.c
> > > +++ b/block/genhd.c
> > > @@ -365,12 +365,12 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action)
> > >  	xa_for_each(&disk->part_tbl, idx, part) {
> > >  		if (bdev_is_partition(part) && !bdev_nr_sectors(part))
> > >  			continue;
> > > -		if (!bdgrab(part))
> > > +		if (!kobject_get_unless_zero(&part->bd_device.kobj))
> > >  			continue;
> > 
> > ->bd_device is embedded in the block device, and it has same lifetime
> > with the block device, even part_release() calls bdput() to release this
> > device, so why doesn't work by holding a inode reference?
> 
> Because sending a uevent on a device that has device_del called on it
> is going to blow up.

But grabbing one reference can't prevent device_del() from being called.

IMO, if driver core doesn't allow to sending uevent on one deleted device,
it should return a failure instead of kernel panic.

Thanks,
Ming


  reply	other threads:[~2021-07-01  9:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01  8:16 two fixup for the block_device / hd_struct merge Christoph Hellwig
2021-07-01  8:16 ` [PATCH 1/2] block: grab a device refcount in disk_uevent Christoph Hellwig
2021-07-01  8:54   ` Ming Lei
2021-07-01  9:02     ` Christoph Hellwig
2021-07-01  9:17       ` Ming Lei [this message]
2021-07-01  9:27         ` Ming Lei
2021-07-01  9:49           ` Christoph Hellwig
2021-07-01  8:16 ` [PATCH 2/2] block: remove the bdgrab in blk_drop_partitions Christoph Hellwig
2021-07-01 16:21 ` two fixup for the block_device / hd_struct merge Jens Axboe

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=YN2IIiKUvquxqx6k@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.