Skip to content

Commit 5c959d7

Browse files
Keith BuschChristoph Hellwig
authored andcommitted
nvme-pci: fix rapid add remove sequence
A surprise removal may fail to tear down request queues if it is racing with the initial asynchronous probe. If that happens, the remove path won't see the queue resources to tear down, and the controller reset path may create a new request queue on a removed device, but will not be able to make forward progress, deadlocking the pci removal. Protect setting up non-blocking resources from a shutdown by holding the same mutex, and transition to the CONNECTING state after these resources are initialized so the probe path may see the dead controller state before dispatching new IO. Link: https://bugzilla.kernel.org/show_bug.cgi?id=202081 Reported-by: Alex Gagniuc <[email protected]> Signed-off-by: Keith Busch <[email protected]> Tested-by: Alex Gagniuc <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent e7ad43c commit 5c959d7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/nvme/host/pci.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,16 +2557,7 @@ static void nvme_reset_work(struct work_struct *work)
25572557
if (dev->ctrl.ctrl_config & NVME_CC_ENABLE)
25582558
nvme_dev_disable(dev, false);
25592559

2560-
/*
2561-
* Introduce CONNECTING state from nvme-fc/rdma transports to mark the
2562-
* initializing procedure here.
2563-
*/
2564-
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) {
2565-
dev_warn(dev->ctrl.device,
2566-
"failed to mark controller CONNECTING\n");
2567-
goto out;
2568-
}
2569-
2560+
mutex_lock(&dev->shutdown_lock);
25702561
result = nvme_pci_enable(dev);
25712562
if (result)
25722563
goto out;
@@ -2585,6 +2576,17 @@ static void nvme_reset_work(struct work_struct *work)
25852576
*/
25862577
dev->ctrl.max_hw_sectors = NVME_MAX_KB_SZ << 1;
25872578
dev->ctrl.max_segments = NVME_MAX_SEGS;
2579+
mutex_unlock(&dev->shutdown_lock);
2580+
2581+
/*
2582+
* Introduce CONNECTING state from nvme-fc/rdma transports to mark the
2583+
* initializing procedure here.
2584+
*/
2585+
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) {
2586+
dev_warn(dev->ctrl.device,
2587+
"failed to mark controller CONNECTING\n");
2588+
goto out;
2589+
}
25882590

25892591
result = nvme_init_identify(&dev->ctrl);
25902592
if (result)

0 commit comments

Comments
 (0)