block: delay freeing the gendisk
Subsystems (2)
PATCH 1/1 block: delay freeing the gendisk
blkdev_get_no_open acquires a reference to the block_device through the block device inode and then tries to acquire a device model reference to the gendisk. But at this point the disk migh already be freed (although the race is free). Fix this by only freeing the gendisk from the whole device bdevs ->free_inode callback as well.
Fixes 22ae8ce8b892 ("block: simplify bdev/disk lookup in blkdev_get")
Signed-off-by Christoph Hellwig <[email protected]>
--- block/genhd.c | 3 +-- fs/block_dev.c | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-)
block/genhd.c +1 -2
@@ -1079,10 +1079,9 @@ static void disk_release(struct device *dev)disk_release_events (disk);kfree (disk->random);xa_destroy (&disk->part_tbl); -bdput (disk->part0);if (test_bit (GD_QUEUE_REF , &disk->state) && disk->queue)blk_put_queue (disk->queue); -kfree (disk); +bdput (disk->part0); }struct class block_class = { .name ="block" ,
fs/block_dev.c +2 -0
@@ -812,6 +812,8 @@ static void bdev_free_inode(struct inode *inode)free_percpu (bdev->bd_stats);kfree (bdev->bd_meta_info); +if (!bdev_is_partition (bdev)) +kfree (disk);kmem_cache_free (bdev_cachep,BDEV_I (inode)); }
Signature · 1 line
2.30.2
Meh, as-is this doesn't even compile. I had accidentally commited the fixup in the following patch. I'll send the whole series in a bit, but the this particule patch once fixed is probably still a 5.14 candidate.