mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: linux-rdma@vger.kernel.org
Cc: metze@samba.org, stable@vger.kernel.org,
	Bernard Metzler <bernard.metzler@linux.dev>,
	Leon Romanovsky <leon@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	Yunseong Kim <yunseong.kim@est.tech>,
	Yunseong Kim <yunseong.kim@ericsson.com>,
	Jacob Moroni <jmoroni@google.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Ammar Ratnani <ammrat13@gmail.com>, Chuck Lever <cel@kernel.org>,
	Li Xiasong <lixiasong1@huawei.com>,
	Trond Myklebust <trondmy@kernel.org>,
	Trond Myklebust <trondmy@gmail.com>,
	Anna Schumaker <anna@kernel.org>,
	Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
	Yue Haibing <yuehaibing@huawei.com>,
	Zhang Changzhong <zhangchangzhong@huawei.com>,
	Wei Yongjun <weiyongjun1@huawei.com>,
	Tim Menninger <tmenninger@everpuredata.com>,
	linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] RDMA/cm: cancel the outstanding REQ or REP in ib_send_cm_rej()
Date: Wed,  2 Dec 2026 13:38:11 +0100	[thread overview]
Message-ID: <9e2e036743b7c6ea4c982b53fd9b2d878351c42a.1796215022.git.metze@samba.org> (raw)
In-Reply-To: <cover.1796215022.git.metze@samba.org>

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@vger.kernel.org
Cc: Bernard Metzler <bernard.metzler@linux.dev>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Yunseong Kim <yunseong.kim@est.tech>
Cc: Yunseong Kim <yunseong.kim@ericsson.com>
Cc: Jacob Moroni <jmoroni@google.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Ammar Ratnani <ammrat13@gmail.com>
Cc: Chuck Lever <cel@kernel.org>
Cc: Li Xiasong <lixiasong1@huawei.com>
Cc: Trond Myklebust <trondmy@kernel.org>
Cc: Trond Myklebust <trondmy@gmail.com>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: NeilBrown <neil@brown.name>
Cc: Olga Kornievskaia <okorniev@redhat.com>
Cc: Dai Ngo <Dai.Ngo@oracle.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Yue Haibing <yuehaibing@huawei.com>
Cc: Zhang Changzhong <zhangchangzhong@huawei.com>
Cc: Wei Yongjun <weiyongjun1@huawei.com>
Cc: Tim Menninger <tmenninger@everpuredata.com>
Cc: linux-rdma@vger.kernel.org
Cc: linux-nfs@vger.kernel.org
Cc: linux-cifs@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
---
 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


  reply	other threads:[~2026-12-02 12:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:38 [PATCH 0/3] RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect() Stefan Metzmacher
2026-12-02 12:38 ` Stefan Metzmacher [this message]
2026-12-02 12:38 ` [PATCH 2/3] RDMA/cm: add ib_cm_reject_pending_connect() Stefan Metzmacher
2026-12-02 12:38 ` [PATCH 3/3] RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect() Stefan Metzmacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e2e036743b7c6ea4c982b53fd9b2d878351c42a.1796215022.git.metze@samba.org \
    --to=metze@samba.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=ammrat13@gmail.com \
    --cc=anna@kernel.org \
    --cc=bernard.metzler@linux.dev \
    --cc=bvanassche@acm.org \
    --cc=cel@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=jlayton@kernel.org \
    --cc=jmoroni@google.com \
    --cc=leon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lixiasong1@huawei.com \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tmenninger@everpuredata.com \
    --cc=tom@talpey.com \
    --cc=trondmy@gmail.com \
    --cc=trondmy@kernel.org \
    --cc=weiyongjun1@huawei.com \
    --cc=yuehaibing@huawei.com \
    --cc=yunseong.kim@ericsson.com \
    --cc=yunseong.kim@est.tech \
    --cc=zhangchangzhong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®