| From d9e75e56cbc6c3609bd2db527e16762cda86f8b7 Mon Sep 17 00:00:00 2001 | |
| From: Sasha Levin <sashal@kernel.org> | |
| Date: Wed, 28 Oct 2026 10:41:49 -0600 | |
| Subject: nvme-loop: delete the controller if a reset fails | |
| From: Josef Bacik <josef@toxicpanda.com> | |
| [ Upstream commit bc2170d365861d29dce20f982093873baad09804 ] | |
| If the reconnect of a reset fails, nvme_loop_reset_ctrl_work() tears the | |
| controller down by hand with nvme_uninit_ctrl(). Since that was split | |
| from nvme_stop_ctrl() it no longer removes the namespaces, which hold | |
| references to the controller. A reset while the target no longer accepts | |
| the host (allow_any_host 0) is enough to get there: a sysfs reset hangs | |
| in kernfs_drain(), an ioctl reset leaves a controller stuck in | |
| CONNECTING with its block devices, the cntlid can't be reused, and | |
| module unload deletes the controller a second time and hits a | |
| use-after-free. | |
| Do what the other fabrics drivers do and call nvme_delete_ctrl(). The | |
| delete path quiesces the admin queue and only unquiesces it if the queue | |
| is live, which it isn't after a failed reset, so unquiesce it | |
| unconditionally before destroying it so a stuck request can't block the | |
| freeze. | |
| Fixes: d09f2b45f346 ("nvme: split nvme_uninit_ctrl into stop and uninit") | |
| Cc: Christoph Hellwig <hch@lst.de> | |
| Cc: Sagi Grimberg <sagi@grimberg.me> | |
| Cc: Chaitanya Kulkarni <kch@nvidia.com> | |
| Reviewed-by: Christoph Hellwig <hch@lst.de> | |
| Signed-off-by: Josef Bacik <josef@toxicpanda.com> | |
| Signed-off-by: Jens Axboe <axboe@kernel.dk> | |
| Signed-off-by: Keith Busch <kbusch@kernel.org> | |
| Signed-off-by: Sasha Levin <sashal@kernel.org> | |
| --- | |
| drivers/nvme/target/loop.c | 5 +++-- | |
| 1 file changed, 3 insertions(+), 2 deletions(-) | |
| diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c | |
| index e579a307798b9..80b67608eb155 100644 | |
| --- a/drivers/nvme/target/loop.c | |
| +++ b/drivers/nvme/target/loop.c | |
| @@ -420,6 +420,8 @@ static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl) | |
| static void nvme_loop_delete_ctrl_host(struct nvme_ctrl *ctrl) | |
| { | |
| nvme_loop_shutdown_ctrl(to_loop_ctrl(ctrl)); | |
| + /* Left quiesced if a failed reset has left no admin queue behind */ | |
| + nvme_unquiesce_admin_queue(ctrl); | |
| nvme_remove_admin_tag_set(ctrl); | |
| } | |
| @@ -483,9 +485,8 @@ static void nvme_loop_reset_ctrl_work(struct work_struct *work) | |
| nvme_cancel_admin_tagset(&ctrl->ctrl); | |
| nvme_loop_destroy_admin_queue(ctrl); | |
| out_disable: | |
| - nvme_remove_admin_tag_set(&ctrl->ctrl); | |
| dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); | |
| - nvme_uninit_ctrl(&ctrl->ctrl); | |
| + nvme_delete_ctrl(&ctrl->ctrl); | |
| } | |
| static const struct nvme_ctrl_ops nvme_loop_ctrl_ops = { | |
| -- | |
| 2.53.0 | |