[PATCH net v3] net/rds: defer CM id destruction to a workqueue

From: Aibing Chen

Date: Tue Nov 17 2026 - 03:21:56 EST


rds_ib_laddr_check_cm() destroys the RDMA CM id it created while
rds_trans_get_preferred() holds rds_trans_sem for reading. The bind
path then takes rds_trans_sem and afterwards handler_mutex in
rdma_destroy_id(), while the CM callback path takes handler_mutex in
cma_ib_req_handler() and afterwards rds_trans_sem through
rds_conn_create(). lockdep reports the resulting cycle.

Queue the destruction on rds_wq instead, so that rds_trans_sem is
released before handler_mutex is taken. The work item is allocated
before the CM id is created and owns the id until rdma_destroy_id() has
run; if the allocation fails, the address check fails with -ENOMEM
rather than falling back to the synchronous destroy, which would bring
the deadlock back under memory pressure.

rds_ib_exit() flushes rds_wq after rds_trans_unregister() so that no
queued destroy runs after the module text is gone.

Reported-by: syzbot+ccdb5058c3df2d94811c@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Hillf Danton <hdanton@xxxxxxxx>
Suggested-by: Jason Gunthorpe <jgg@xxxxxxxx>
Suggested-by: Allison Henderson <achender@xxxxxxxxxx>
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
v3:
- allocate the work item before rdma_create_id() and fail with -ENOMEM
instead of falling back to the synchronous destroy, which would bring
the deadlock back under memory pressure.
- free the work item when rdma_create_id() fails and drop the now
redundant fallback in the out path.

v2:
- move the workqueue from RDMA core into RDS, as suggested in review.
- flush rds_wq in rds_ib_exit() so a queued destroy cannot run after
the module text is freed.
- add the Fixes tag, drop the Tested-by tags.

net/rds/ib.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index 4ea9838d0..44b46defa 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -391,6 +391,20 @@ static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
}
#endif

+struct rds_ib_destroy_work {
+ struct work_struct work;
+ struct rdma_cm_id *cm_id;
+};
+
+static void rds_ib_destroy_id_work(struct work_struct *work)
+{
+ struct rds_ib_destroy_work *w =
+ container_of(work, struct rds_ib_destroy_work, work);
+
+ rdma_destroy_id(w->cm_id);
+ kfree(w);
+}
+
/*
* Early RDS/IB was built to only bind to an address if there is an IPoIB
* device with that address set.
@@ -411,14 +425,28 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
#endif
struct sockaddr_in sin;
struct sockaddr *sa;
+ struct rds_ib_destroy_work *w;
bool isv4;

isv4 = ipv6_addr_v4mapped(addr);
+
+ /*
+ * The id is destroyed from rds_wq: rds_trans_get_preferred() calls this
+ * function with rds_trans_sem held for reading, and rdma_destroy_id()
+ * takes handler_mutex, which the CM callback path acquires before
+ * taking rds_trans_sem.
+ */
+ w = kzalloc_obj(*w, GFP_KERNEL);
+ if (!w)
+ return -ENOMEM;
+
/* Create a CMA ID restricted to IB devices and try to bind it. */
cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler,
NULL, RDMA_PS_TCP, IB_QPT_RC);
- if (IS_ERR(cm_id))
+ if (IS_ERR(cm_id)) {
+ kfree(w);
return PTR_ERR(cm_id);
+ }
ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA);
if (ret)
goto out;
@@ -484,7 +512,9 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
cm_id->device ? cm_id->device->node_type : -1);

out:
- rdma_destroy_id(cm_id);
+ INIT_WORK(&w->work, rds_ib_destroy_id_work);
+ w->cm_id = cm_id;
+ queue_work(rds_wq, &w->work);

return ret;
}
@@ -542,6 +572,11 @@ void rds_ib_exit(void)
rds_ib_sysctl_exit();
rds_ib_recv_exit();
rds_trans_unregister(&rds_ib_transport);
+ /*
+ * rds_ib_laddr_check_cm() may have queued rdma_destroy_id() on rds_wq;
+ * wait for it before the module text goes away.
+ */
+ flush_workqueue(rds_wq);
rds_ib_mr_exit();
}