[PATCH] nvmet-rdma: fix queue leak when connect backlog is exceeded

Xixin Liu posted 1 patch 1 month, 2 weeks ago
drivers/nvme/target/rdma.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
[PATCH] nvmet-rdma: fix queue leak when connect backlog is exceeded
Posted by Xixin Liu 1 month, 2 weeks ago
When pending disconnecting queues exceed the backlog limit, the
connect path only drops the device reference and leaks the newly
allocated queue and its IB resources.

Fixes: badc53620fe8 ("nvme: target: rdma: fix ndev refcount leak on queue connect")
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
 drivers/nvme/target/rdma.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index bdd28ce99..6273d26cd 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -1606,19 +1606,13 @@ static int nvmet_rdma_queue_connect(struct rdma_cm_id *cm_id,
 		mutex_unlock(&nvmet_rdma_queue_mutex);
 		if (pending > NVMET_RDMA_BACKLOG) {
 			ret = NVME_SC_CONNECT_CTRL_BUSY;
-			goto put_device;
+			goto free_queue;
 		}
 	}
 
 	ret = nvmet_rdma_cm_accept(cm_id, queue, &event->param.conn);
-	if (ret) {
-		/*
-		 * Don't destroy the cm_id in free path, as we implicitly
-		 * destroy the cm_id here with non-zero ret code.
-		 */
-		queue->cm_id = NULL;
+	if (ret)
 		goto free_queue;
-	}
 
 	mutex_lock(&nvmet_rdma_queue_mutex);
 	list_add_tail(&queue->queue_list, &nvmet_rdma_queue_list);
@@ -1627,6 +1621,11 @@ static int nvmet_rdma_queue_connect(struct rdma_cm_id *cm_id,
 	return 0;
 
 free_queue:
+	/*
+	 * Don't destroy the cm_id in free path, as we implicitly
+	 * destroy the cm_id here with non-zero ret code.
+	 */
+	queue->cm_id = NULL;
 	nvmet_rdma_free_queue(queue);
 put_device:
 	kref_put(&ndev->ref, nvmet_rdma_free_dev);
-- 
2.53.0
Re: [PATCH] nvmet-rdma: fix queue leak when connect backlog is exceeded
Posted by Keith Busch 1 month, 1 week ago
On Thu, Aug 13, 2026 at 02:42:01PM +0800, Xixin Liu wrote:
> When pending disconnecting queues exceed the backlog limit, the
> connect path only drops the device reference and leaks the newly
> allocated queue and its IB resources.

Thanks, applied to nvme-7.3.
Re: [PATCH] nvmet-rdma: fix queue leak when connect backlog is exceeded
Posted by Christoph Hellwig 1 month, 1 week ago
On Thu, Aug 13, 2026 at 02:42:01PM +0800, Xixin Liu wrote:
> When pending disconnecting queues exceed the backlog limit, the
> connect path only drops the device reference and leaks the newly
> allocated queue and its IB resources.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>