[PATCH 1/3] RDMA/cm: cancel the outstanding REQ or REP in ib_send_cm_rej()
From: Stefan Metzmacher
Date: Wed Dec 02 2026 - 07:38:55 EST
ib_send_cm_rej() is allowed in IB_CM_REQ_SENT and IB_CM_MRA_REQ_RCVD,
but it only moves the cm_id to IB_CM_IDLE and sends the REJ, while our
REQ stays outstanding. It is retried and its send buffer keeps a
reference on the cm_id until all retries timed out, so a following
ib_destroy_cm_id(), which finds IB_CM_IDLE and doesn't cancel anything,
waits that long in cm_destroy_id(), about 76 seconds with the rdma_cm
defaults. The peer also keeps getting the REQ after the REJ.
This is needed for the following patch "RDMA/cma: reject a pending
IB/RoCE connect in rdma_disconnect()", which aborts a connect without
an answer from the peer, when the rdma_cm_id is destroyed afterwards:
cm_destroy_id+0x23b/0x630 [ib_cm]
ib_destroy_cm_id+0x10/0x20 [ib_cm]
_destroy_id+0xd8/0x390 [rdma_cm]
destroy_id_handler_unlock+0x56/0xb0 [rdma_cm]
rdma_destroy_id+0x21/0x30 [rdma_cm]
smbdirect_socket_destroy_sync+0x48f/0x9c0 [smbdirect]
cm_destroy_id() already cancelled the outstanding REQ (and our REP in
IB_CM_REP_SENT and IB_CM_MRA_REP_RCVD) before calling
cm_send_rej_locked(), so move that into cm_send_rej_locked() for all
callers.
Fixes: a977049dacde ("[PATCH] IB: Add the kernel CM implementation")
Cc: stable@xxxxxxxxxxxxxxx
Cc: Bernard Metzler <bernard.metzler@xxxxxxxxx>
Cc: Leon Romanovsky <leon@xxxxxxxxxx>
Cc: Jason Gunthorpe <jgg@xxxxxxxx>
Cc: Yunseong Kim <yunseong.kim@xxxxxxxx>
Cc: Yunseong Kim <yunseong.kim@xxxxxxxxxxxx>
Cc: Jacob Moroni <jmoroni@xxxxxxxxxx>
Cc: Bart Van Assche <bvanassche@xxxxxxx>
Cc: Ammar Ratnani <ammrat13@xxxxxxxxx>
Cc: Chuck Lever <cel@xxxxxxxxxx>
Cc: Li Xiasong <lixiasong1@xxxxxxxxxx>
Cc: Trond Myklebust <trondmy@xxxxxxxxxx>
Cc: Trond Myklebust <trondmy@xxxxxxxxx>
Cc: Anna Schumaker <anna@xxxxxxxxxx>
Cc: Jeff Layton <jlayton@xxxxxxxxxx>
Cc: NeilBrown <neil@xxxxxxxxxx>
Cc: Olga Kornievskaia <okorniev@xxxxxxxxxx>
Cc: Dai Ngo <Dai.Ngo@xxxxxxxxxx>
Cc: Tom Talpey <tom@xxxxxxxxxx>
Cc: Yue Haibing <yuehaibing@xxxxxxxxxx>
Cc: Zhang Changzhong <zhangchangzhong@xxxxxxxxxx>
Cc: Wei Yongjun <weiyongjun1@xxxxxxxxxx>
Cc: Tim Menninger <tmenninger@xxxxxxxxxxxxxxxx>
Cc: linux-rdma@xxxxxxxxxxxxxxx
Cc: linux-nfs@xxxxxxxxxxxxxxx
Cc: linux-cifs@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Stefan Metzmacher <metze@xxxxxxxxx>
---
drivers/infiniband/core/cm.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 5347b7519a8d..d16fc71ed5e6 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -1095,7 +1095,6 @@ static void cm_destroy_id(struct ib_cm_id *cm_id, int err)
break;
case IB_CM_REQ_SENT:
case IB_CM_MRA_REQ_RCVD:
- ib_cancel_mad(cm_id_priv->msg);
cm_send_rej_locked(cm_id_priv, IB_CM_REJ_TIMEOUT,
&cm_id_priv->id.device->node_guid,
sizeof(cm_id_priv->id.device->node_guid),
@@ -1113,7 +1112,6 @@ static void cm_destroy_id(struct ib_cm_id *cm_id, int err)
break;
case IB_CM_REP_SENT:
case IB_CM_MRA_REP_RCVD:
- ib_cancel_mad(cm_id_priv->msg);
cm_send_rej_locked(cm_id_priv, IB_CM_REJ_CONSUMER_DEFINED, NULL,
0, NULL, 0);
goto retest;
@@ -2965,6 +2963,13 @@ static int cm_send_rej_locked(struct cm_id_private *cm_id_priv,
switch (state) {
case IB_CM_REQ_SENT:
case IB_CM_MRA_REQ_RCVD:
+ /*
+ * Our REQ is still outstanding, it would otherwise be
+ * retried and keep a reference on the cm_id until all
+ * retries timed out.
+ */
+ ib_cancel_mad(cm_id_priv->msg);
+ fallthrough;
case IB_CM_REQ_RCVD:
case IB_CM_MRA_REQ_SENT:
case IB_CM_REP_RCVD:
@@ -2979,6 +2984,8 @@ static int cm_send_rej_locked(struct cm_id_private *cm_id_priv,
break;
case IB_CM_REP_SENT:
case IB_CM_MRA_REP_RCVD:
+ /* the same for our outstanding REP */
+ ib_cancel_mad(cm_id_priv->msg);
cm_enter_timewait(cm_id_priv);
msg = cm_alloc_msg(cm_id_priv);
if (IS_ERR(msg))
--
2.43.0