nbd: add a flush_workqueue in nbd_start_device
Subsystems (2)
PATCH v2 1/1 nbd: add a flush_workqueue in nbd_start_device
When kzalloc fail, may cause trying to destroy the workqueue from inside the workqueue.
If num_connections is m (2 < m), and NO.1 ~ NO.n (1 < n < m) kzalloc are successful. The NO.(n + 1) failed. Then, nbd_start_device will return ENOMEM to nbd_start_device_ioctl, and nbd_start_device_ioctl will return immediately without running flush_workqueue. However, we still have n recv threads. If nbd_release run first, recv threads may have to drop the last config_refs and try to destroy the workqueue from inside the workqueue.
To fix it, add a flush_workqueue in nbd_start_device.
--- drivers/block/nbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/block/nbd.c +10 -0
@@ -1265,6 +1265,16 @@ static int nbd_start_device(struct nbd_device *nbd) args =kzalloc (sizeof (*args),GFP_KERNEL );if (!args) {sock_shutdown (nbd); +/* +* If num_connections is m (2 < m), +* and NO.1 ~ NO.n(1 < n < m) kzallocs are successful. +* But NO.(n + 1) failed. We still have n recv threads. +* So, add flush_workqueue here to prevent recv threads +* dropping the last config_refs and trying to destroy +* the workqueue from inside the workqueue. +*/ +if (i) +flush_workqueue (nbd->recv_workq);return -ENOMEM ; }sk_set_memalloc (config->socks[i]->sock->sk);
Signature · 1 line
2.17.2
ping
Quoted 43 lines · Sun Ke
When kzalloc fail, may cause trying to destroy the workqueue from inside the workqueue.
If
num_connectionsis m (2 < m), and NO.1 ~ NO.n (1 < n < m) kzalloc are successful. The NO.(n + 1) failed. Then,nbd_start_devicewill return ENOMEM tonbd_start_device_ioctl, andnbd_start_device_ioctlwill return immediately without runningflush_workqueue. However, we still have n recv threads. Ifnbd_releaserun first, recv threads may have to drop the lastconfig_refsand try to destroy the workqueue from inside the workqueue.To fix it, add a
flush_workqueueinnbd_start_device.Fixes e9e006f5fcf2 ("nbd: fix max number of supported devs")Signed-off-by Sun Ke <[email protected]>--- drivers/block/nbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/block/nbd.c +10
-0@@ -1265,6 +1265,16 @@ static int nbd_start_device(struct nbd_device *nbd) args =kzalloc (sizeof (*args),GFP_KERNEL );if (!args) {sock_shutdown (nbd); +/* +* If num_connections is m (2 < m), +* and NO.1 ~ NO.n(1 < n < m) kzallocs are successful. +* But NO.(n + 1) failed. We still have n recv threads. +* So, add flush_workqueue here to prevent recv threads +* dropping the last config_refs and trying to destroy +* the workqueue from inside the workqueue. +*/ +if (i) +flush_workqueue (nbd->recv_workq);return -ENOMEM ; }sk_set_memalloc (config->socks[i]->sock->sk);
Jens Axboe
maintainerQuoted 1 line · sunke (E)
ping
Maybe I forgot to reply, but I queued it up last week:
Signature · 1 line
Jens Axboe