]> git.baikalelectronics.ru Git - kernel.git/commit
block: loop: fix deadlock between open and remove
authorChristoph Hellwig <hch@lst.de>
Sat, 5 Jun 2021 14:09:50 +0000 (17:09 +0300)
committerJens Axboe <axboe@kernel.dk>
Fri, 11 Jun 2021 17:50:54 +0000 (11:50 -0600)
commitaf5479deef7f613648a8099fd87d2b373454cec7
tree57bb97c10809dfe355358a61c0e0c53abd8aab61
parentdff3390767a6b236eb6ed5d73669dfef4e3117ef
block: loop: fix deadlock between open and remove

Commit d7ec1776d26b ("block: take bd_mutex around delete_partitions in
del_gendisk") adds disk->part0->bd_mutex in del_gendisk(), this way
causes the following AB/BA deadlock between removing loop and opening
loop:

 1) loop_control_ioctl(LOOP_CTL_REMOVE)
     -> mutex_lock(&loop_ctl_mutex)
     -> del_gendisk
         -> mutex_lock(&disk->part0->bd_mutex)

 2) blkdev_get_by_dev
     -> mutex_lock(&disk->part0->bd_mutex)
     -> lo_open
         -> mutex_lock(&loop_ctl_mutex)

Add a new Lo_deleting state to remove the need for clearing
->private_data and thus holding loop_ctl_mutex in the ioctl
LOOP_CTL_REMOVE path.

Based on an analysis and earlier patch from
Ming Lei <ming.lei@redhat.com>.

Reported-by: Colin Ian King <colin.king@canonical.com>
Fixes: d7ec1776d26b ("block: take bd_mutex around delete_partitions in del_gendisk")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20210605140950.5800-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c
drivers/block/loop.h