block: take bd_mutex around delete_partitions in del_gendisk
authorChristoph Hellwig <hch@lst.de>
Tue, 6 Apr 2021 06:22:56 +0000 (08:22 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 8 Apr 2021 16:24:36 +0000 (10:24 -0600)
There is nothing preventing an ioctl from trying do delete partition
concurrenly with del_gendisk, so take open_mutex to serialize against
that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210406062303.811835-6-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c
block/partitions/core.c

index 8303ec6..e3f3c23 100644 (file)
@@ -680,7 +680,11 @@ void del_gendisk(struct gendisk *disk)
         * disk is marked as dead (GENHD_FL_UP cleared).
         */
        down_write(&bdev_lookup_sem);
+
+       mutex_lock(&disk->part0->bd_mutex);
        blk_drop_partitions(disk);
+       mutex_unlock(&disk->part0->bd_mutex);
+
        fsync_bdev(disk->part0);
        __invalidate_device(disk->part0, true);
 
index 536f7c5..9fbaec4 100644 (file)
@@ -531,6 +531,8 @@ void blk_drop_partitions(struct gendisk *disk)
        struct disk_part_iter piter;
        struct block_device *part;
 
+       lockdep_assert_held(&disk->part0->bd_mutex);
+
        disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
        while ((part = disk_part_iter_next(&piter)))
                delete_partition(part);