Skip to content

Commit 1c05839

Browse files
Mike Christieaxboe
authored andcommitted
nbd: fix shutdown and recv work deadlock v2
This fixes a regression added with: commit e9e006f Author: Mike Christie <[email protected]> Date: Sun Aug 4 14:10:06 2019 -0500 nbd: fix max number of supported devs where we can deadlock during device shutdown. The problem occurs if the recv_work's nbd_config_put occurs after nbd_start_device_ioctl has returned and the userspace app has droppped its reference via closing the device and running nbd_release. The recv_work nbd_config_put call would then drop the refcount to zero and try to destroy the config which would try to do destroy_workqueue from the recv work. This patch just has nbd_start_device_ioctl do a flush_workqueue when it wakes so we know after the ioctl returns running works have exited. This also fixes a possible race where we could try to reuse the device while old recv_works are still running. Cc: [email protected] Fixes: e9e006f ("nbd: fix max number of supported devs") Signed-off-by: Mike Christie <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d7bd15a commit 1c05839

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,10 +1296,10 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
12961296
mutex_unlock(&nbd->config_lock);
12971297
ret = wait_event_interruptible(config->recv_wq,
12981298
atomic_read(&config->recv_threads) == 0);
1299-
if (ret) {
1299+
if (ret)
13001300
sock_shutdown(nbd);
1301-
flush_workqueue(nbd->recv_workq);
1302-
}
1301+
flush_workqueue(nbd->recv_workq);
1302+
13031303
mutex_lock(&nbd->config_lock);
13041304
nbd_bdev_reset(bdev);
13051305
/* user requested, ignore socket errors */

0 commit comments

Comments
 (0)