linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/cma: Fix listener leak in rdma_cma_listen_on_all() failure
@ 2021-09-13  9:33 Tao Liu
  2021-09-13 11:16 ` Leon Romanovsky
  2021-09-14 19:54 ` Jason Gunthorpe
  0 siblings, 2 replies; 7+ messages in thread
From: Tao Liu @ 2021-09-13  9:33 UTC (permalink / raw)
  To: dledford, jgg, leon, haakon.bugge, shayd, avihaih
  Cc: linux-rdma, linux-kernel, thomas.liu

rdma_cma_listen_on_all() just destroy listener which lead to an error,
but not including those already added in listen_list. Then cm state
fallbacks to RDMA_CM_ADDR_BOUND.

When user destroys id, the listeners will not be destroyed, and
process stucks.

 task:rping state:D stack:   0 pid:19605 ppid: 47036 flags:0x00000084
 Call Trace:
  __schedule+0x29a/0x780
  ? free_unref_page_commit+0x9b/0x110
  schedule+0x3c/0xa0
  schedule_timeout+0x215/0x2b0
  ? __flush_work+0x19e/0x1e0
  wait_for_completion+0x8d/0xf0
  _destroy_id+0x144/0x210 [rdma_cm]
  ucma_close_id+0x2b/0x40 [rdma_ucm]
  __destroy_id+0x93/0x2c0 [rdma_ucm]
  ? __xa_erase+0x4a/0xa0
  ucma_destroy_id+0x9a/0x120 [rdma_ucm]
  ucma_write+0xb8/0x130 [rdma_ucm]
  vfs_write+0xb4/0x250
  ksys_write+0xb5/0xd0
  ? syscall_trace_enter.isra.19+0x123/0x190
  do_syscall_64+0x33/0x40
  entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: c80a0c52d85c ("RDMA/cma: Add missing error handling of listen_id")
Signed-off-by: Tao Liu <thomas.liu@ucloud.cn>
---
 drivers/infiniband/core/cma.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index c40791b..d8cea33 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1746,16 +1746,11 @@ static void cma_cancel_route(struct rdma_id_private *id_priv)
 	}
 }
 
-static void cma_cancel_listens(struct rdma_id_private *id_priv)
+static void _cma_cancel_listens(struct rdma_id_private *id_priv)
 {
 	struct rdma_id_private *dev_id_priv;
 
-	/*
-	 * Remove from listen_any_list to prevent added devices from spawning
-	 * additional listen requests.
-	 */
-	mutex_lock(&lock);
-	list_del(&id_priv->list);
+	lockdep_assert_held(&lock);
 
 	while (!list_empty(&id_priv->listen_list)) {
 		dev_id_priv = list_entry(id_priv->listen_list.next,
@@ -1768,6 +1763,18 @@ static void cma_cancel_listens(struct rdma_id_private *id_priv)
 		rdma_destroy_id(&dev_id_priv->id);
 		mutex_lock(&lock);
 	}
+}
+
+static void cma_cancel_listens(struct rdma_id_private *id_priv)
+{
+	/*
+	 * Remove from listen_any_list to prevent added devices from spawning
+	 * additional listen requests.
+	 */
+	mutex_lock(&lock);
+	list_del(&id_priv->list);
+
+	_cma_cancel_listens(id_priv);
 	mutex_unlock(&lock);
 }
 
@@ -2575,6 +2582,7 @@ static int cma_listen_on_all(struct rdma_id_private *id_priv)
 
 err_listen:
 	list_del(&id_priv->list);
+	_cma_cancel_listens(id_priv);
 	mutex_unlock(&lock);
 	if (to_destroy)
 		rdma_destroy_id(&to_destroy->id);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-16 13:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  9:33 [PATCH] RDMA/cma: Fix listener leak in rdma_cma_listen_on_all() failure Tao Liu
2021-09-13 11:16 ` Leon Romanovsky
2021-09-14 19:54 ` Jason Gunthorpe
2021-09-14 23:17   ` Leon Romanovsky
2021-09-16 13:57     ` Jason Gunthorpe
2021-09-15  6:34   ` Mark Zhang
2021-09-15 13:18     ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).