On Sat 12-06-21 00:14:20, Tetsuo Handa wrote: > syzbot is reporting circular locking dependency between loop_ctl_mutex and > bdev->bd_mutex [1] due to commit c76f48eb5c084b1e ("block: take bd_mutex > around delete_partitions in del_gendisk"). > > But calling del_gendisk() from loop_remove() without loop_ctl_mutex held > triggers a different race problem regarding sysfs entry management. We > somehow need to serialize "add_disk() from loop_add()" and "del_gendisk() > from loop_remove()". Fortunately, since loop_control_ioctl() is called > with no locks held, we can use "sleep and retry" approach without risking > deadlock. > > Since "struct loop_device"->lo_disk->private_data is set to non-NULL at > loop_add() and is reset to NULL before calling loop_remove(), we can use > it as a flag for taking appropriate action ("sleep and retry" or "skip") > when loop_remove() is in progress. > > Link: https://syzkaller.appspot.com/bug?extid=61e04e51b7ac86930589 [1] > Reported-by: syzbot <syzbot+61e04e51b7ac86930589@xxxxxxxxxxxxxxxxxxxxxxxxx> > Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> > Tested-by: syzbot <syzbot+61e04e51b7ac86930589@xxxxxxxxxxxxxxxxxxxxxxxxx> > Fixes: c76f48eb5c084b1e ("block: take bd_mutex around delete_partitions in del_gendisk") Christoph seems to have already fixed this by 990e78116d380 ("block: loop: fix deadlock between open and remove"). Honza -- Jan Kara <jack@xxxxxxxx> SUSE Labs, CR