| From 1791bc489f0cf137b478e6948ced6f5974f211b3 Mon Sep 17 00:00:00 2001 | |
| From: Sasha Levin <sashal@kernel.org> | |
| Date: Wed, 28 Oct 2026 10:42:30 -0600 | |
| Subject: nvmet-rdma: disconnect a queue on device removal | |
| From: Chris Mason <mason@kernel.org> | |
| [ Upstream commit a4387799d4228866dc1746b466cd17e1c638d050 ] | |
| cma_remove_one() sends DEVICE_REMOVAL to the owner of every cm_id on | |
| the device and then waits, without timeout, until they're all | |
| destroyed. nvmet_rdma_device_removal() does nothing for a queue cm_id | |
| and leaves the queues to nvmet_rdma_remove_one(), which only works if | |
| that runs first. As a module it does, nvmet-rdma registers after | |
| rdma_cm. Built in, both register at the same initcall level and | |
| drivers/Makefile lists nvme/ ahead of infiniband/, so cma_remove_one() | |
| runs first and waits for cm_ids that only the later callback would | |
| destroy. Since the RDMA CM drops all later events for a cm_id once it | |
| has sent DEVICE_REMOVAL, a peer closing its connection doesn't help | |
| either. One connection from anyone who can reach the port hangs "rdma | |
| link delete" until something else ends the queue. | |
| Call nvmet_rdma_queue_disconnect() for the queue. It unlists the queue | |
| and queues the release work, which destroys the cm_id. Don't wait for | |
| it, rdma_destroy_id() waits for the handler to return, which was the | |
| deadlock before commit f1d4ef7d8883. | |
| Fixes: f1d4ef7d8883 ("nvmet-rdma: register ib_client to not deadlock in device removal") | |
| 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: Chris Mason <mason@kernel.org> | |
| 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/rdma.c | 17 ++++++++--------- | |
| 1 file changed, 8 insertions(+), 9 deletions(-) | |
| diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c | |
| index e7dbfa383c57d..ff387fc47885d 100644 | |
| --- a/drivers/nvme/target/rdma.c | |
| +++ b/drivers/nvme/target/rdma.c | |
| @@ -1782,10 +1782,13 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id, | |
| * queue cm_id and/or a device bound listener cm_id (where in this | |
| * case queue will be null). | |
| * | |
| - * We registered an ib_client to handle device removal for queues, | |
| - * so we only need to handle the listening port cm_ids. In this case | |
| - * we nullify the priv to prevent double cm_id destruction and destroying | |
| - * the cm_id implicitly by returning a non-zero rc to the callout. | |
| + * The RDMA CM waits until each cm_id of the device is destroyed, so a queue | |
| + * has to go now. Our ib_client also removes the queues, but it cannot be | |
| + * relied on here: built in, it is called after the RDMA CM's client. | |
| + * | |
| + * For a listening port cm_id we nullify the priv to prevent double cm_id | |
| + * destruction and destroying the cm_id implicitly by returning a non-zero | |
| + * rc to the callout. | |
| */ | |
| static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, | |
| struct nvmet_rdma_queue *queue) | |
| @@ -1793,11 +1796,7 @@ static int nvmet_rdma_device_removal(struct rdma_cm_id *cm_id, | |
| struct nvmet_rdma_port *port; | |
| if (queue) { | |
| - /* | |
| - * This is a queue cm_id. we have registered | |
| - * an ib_client to handle queues removal | |
| - * so don't interfere and just return. | |
| - */ | |
| + nvmet_rdma_queue_disconnect(queue); | |
| return 0; | |
| } | |
| -- | |
| 2.53.0 | |