All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix leaking minors of hidden disks
@ 2022-10-10 13:18 Christoph Hellwig
  2022-10-10 13:34 ` Keith Busch
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christoph Hellwig @ 2022-10-10 13:18 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, Daniel Wagner

The major/minor of a hidden gendisk is not propagated to the block
device because it is never registered using bdev_add.  But the lack of
bd_dev also causes the dynamic major minor number not to be freed.
Assign bd_dev manually to ensure the dynamic major minor gets freed.

Based on a patch by Keith Busch.

Fixes:  8ddcd653257c ("block: introduce GENHD_FL_HIDDEN")
Reported-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Daniel Wagner <dwagner@suse.de>
---
 block/genhd.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 514395361d7c5..17b33c62423df 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -507,6 +507,13 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
 		 */
 		dev_set_uevent_suppress(ddev, 0);
 		disk_uevent(disk, KOBJ_ADD);
+	} else {
+		/*
+		 * Even if the block_device for a hidden gendisk is not
+		 * registered, it needs to have a valid bd_dev so that the
+		 * freeing of the dynamic major works.
+		 */
+		disk->part0->bd_dev = MKDEV(disk->major, disk->first_minor);
 	}
 
 	disk_update_readahead(disk);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: fix leaking minors of hidden disks
  2022-10-10 13:18 [PATCH] block: fix leaking minors of hidden disks Christoph Hellwig
@ 2022-10-10 13:34 ` Keith Busch
  2022-10-10 14:49 ` Jens Axboe
  2022-10-12  6:20 ` Hannes Reinecke
  2 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2022-10-10 13:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: axboe, linux-block, Daniel Wagner

On Mon, Oct 10, 2022 at 3:19 PM Christoph Hellwig <hch@lst.de> wrote:
>
> The major/minor of a hidden gendisk is not propagated to the block
> device because it is never registered using bdev_add.  But the lack of
> bd_dev also causes the dynamic major minor number not to be freed.
> Assign bd_dev manually to ensure the dynamic major minor gets freed.

Looks good.

Reviewed-by: Keith Busch <kbusch@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: fix leaking minors of hidden disks
  2022-10-10 13:18 [PATCH] block: fix leaking minors of hidden disks Christoph Hellwig
  2022-10-10 13:34 ` Keith Busch
@ 2022-10-10 14:49 ` Jens Axboe
  2022-10-12  6:20 ` Hannes Reinecke
  2 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2022-10-10 14:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Daniel Wagner, linux-block

On Mon, 10 Oct 2022 15:18:57 +0200, Christoph Hellwig wrote:
> The major/minor of a hidden gendisk is not propagated to the block
> device because it is never registered using bdev_add.  But the lack of
> bd_dev also causes the dynamic major minor number not to be freed.
> Assign bd_dev manually to ensure the dynamic major minor gets freed.
> 
> Based on a patch by Keith Busch.
> 
> [...]

Applied, thanks!

[1/1] block: fix leaking minors of hidden disks
      commit: a0a6314ae774f8a5e52a599946aa2ad0db867b83

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: fix leaking minors of hidden disks
  2022-10-10 13:18 [PATCH] block: fix leaking minors of hidden disks Christoph Hellwig
  2022-10-10 13:34 ` Keith Busch
  2022-10-10 14:49 ` Jens Axboe
@ 2022-10-12  6:20 ` Hannes Reinecke
  2 siblings, 0 replies; 6+ messages in thread
From: Hannes Reinecke @ 2022-10-12  6:20 UTC (permalink / raw)
  To: Christoph Hellwig, axboe; +Cc: linux-block, Daniel Wagner

On 10/10/22 15:18, Christoph Hellwig wrote:
> The major/minor of a hidden gendisk is not propagated to the block
> device because it is never registered using bdev_add.  But the lack of
> bd_dev also causes the dynamic major minor number not to be freed.
> Assign bd_dev manually to ensure the dynamic major minor gets freed.
> 
> Based on a patch by Keith Busch.
> 
> Fixes:  8ddcd653257c ("block: introduce GENHD_FL_HIDDEN")
> Reported-by: Daniel Wagner <dwagner@suse.de>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Daniel Wagner <dwagner@suse.de>
> ---
>   block/genhd.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index 514395361d7c5..17b33c62423df 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -507,6 +507,13 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
>   		 */
>   		dev_set_uevent_suppress(ddev, 0);
>   		disk_uevent(disk, KOBJ_ADD);
> +	} else {
> +		/*
> +		 * Even if the block_device for a hidden gendisk is not
> +		 * registered, it needs to have a valid bd_dev so that the
> +		 * freeing of the dynamic major works.
> +		 */
> +		disk->part0->bd_dev = MKDEV(disk->major, disk->first_minor);
>   	}
>   
>   	disk_update_readahead(disk);

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: fix leaking minors of hidden disks
  2022-10-07 19:32 Keith Busch
@ 2022-10-07 19:36 ` Keith Busch
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2022-10-07 19:36 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-block, axboe, Christoph Hellwig, Daniel Wagner

On Fri, Oct 07, 2022 at 12:32:34PM -0700, Keith Busch wrote:
> +	if (disk->major == BLOCK_EXT_MAJOR)
> +		blk_free_ext_minor(disk->first_minor);
>  	iput(disk->part0->bd_inode);	/* frees the disk */
>  }

Oops, the above is missing the check for the hidden flag. V2 coming.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] block: fix leaking minors of hidden disks
@ 2022-10-07 19:32 Keith Busch
  2022-10-07 19:36 ` Keith Busch
  0 siblings, 1 reply; 6+ messages in thread
From: Keith Busch @ 2022-10-07 19:32 UTC (permalink / raw)
  To: linux-block, axboe; +Cc: Keith Busch, Christoph Hellwig, Daniel Wagner

From: Keith Busch <kbusch@kernel.org>

The major/minor of a hidden gendisk is not propagated to the block
device. This is required to suppress it from being visible. For these
disks, we need to handle freeing the dynamic minor directly when it's
released since bdev_free_inode() won't be able to.

Cc: Christoph Hellwig <hch@lst.de>
Reported-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/genhd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 514395361d7c..d46edf26320a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1166,6 +1166,8 @@ static void disk_release(struct device *dev)
 	if (test_bit(GD_ADDED, &disk->state) && disk->fops->free_disk)
 		disk->fops->free_disk(disk);
 
+	if (disk->major == BLOCK_EXT_MAJOR)
+		blk_free_ext_minor(disk->first_minor);
 	iput(disk->part0->bd_inode);	/* frees the disk */
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-12  6:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 13:18 [PATCH] block: fix leaking minors of hidden disks Christoph Hellwig
2022-10-10 13:34 ` Keith Busch
2022-10-10 14:49 ` Jens Axboe
2022-10-12  6:20 ` Hannes Reinecke
  -- strict thread matches above, loose matches on Subject: below --
2022-10-07 19:32 Keith Busch
2022-10-07 19:36 ` Keith Busch

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.