From: Ammar Ratnani <ammrat13@gmail.com>
To: linux-rdma@vger.kernel.org
Cc: Ammar Ratnani <ammrat13@gmail.com>,
Ammar Ratnani <aratnani@nvidia.com>,
Kechen Lu <kechenl@nvidia.com>,
Mithun Maragiri <mmaragiri@nvidia.com>,
linux-kernel@vger.kernel.org, Leon Romanovsky <leon@kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>,
Namjae Jeon <linkinjeon@kernel.org>,
Paulo Alcantara <pc@manguebit.org>,
Stefan Metzmacher <metze@samba.org>, Tom Talpey <tom@talpey.com>,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Subject: [PATCH 1/2] infiniband: force disconnect if DREP and DREQ fail
Date: Tue, 8 Sep 2026 08:44:26 -0700 [thread overview]
Message-ID: <20260908154454.10966-2-ammrat13@gmail.com> (raw)
In-Reply-To: <20260908154454.10966-1-ammrat13@gmail.com>
When we call `rdma_disconnect`, it's possible that we fail to send both
a DREQ and a DREP. In that case, we currently either do nothing or move
into the `IB_CM_TIMEWAIT` state. Either way, we remain in the
`RDMA_CM_CONNECT` state. Anyone waiting for us to disconnect hangs.
Instead, while we're connected, when we call `rdma_disconnect`, and fail
to send both a DREQ and a DREP, mark the connection as disconnected.
Call the upper layer's handler for the disconnect, and destroy the
connection if instructed.
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: Stefan Metzmacher <metze@samba.org>
Cc: Tom Talpey <tom@talpey.com>
Cc: linux-rdma@vger.kernel.org
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ammar Ratnani <ammrat13@gmail.com>
---
drivers/infiniband/core/cma.c | 39 +++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 73170b15fc3d..1f1a8b4e160a 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -4823,6 +4823,34 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
}
EXPORT_SYMBOL(rdma_reject);
+/*
+ * Called from rdma_disconnect() when we know we're not receiving a callback.
+ * Emulate what that callback (in cma_ib_handler()) would have done.
+ *
+ * NOTE: Despite the name, this function will only actually disconnect when
+ * we're in the RDMA_CM_CONNECT state. Else, it does nothing.
+ */
+static int cma_force_disconnect(struct rdma_id_private *id_priv)
+{
+ struct cma_work *work;
+
+ work = kzalloc_obj(*work);
+ if (!work)
+ return -ENOMEM;
+
+ INIT_WORK(&work->work, cma_work_handler);
+ work->old_state = RDMA_CM_CONNECT;
+ work->new_state = RDMA_CM_DISCONNECT;
+ work->event.event = RDMA_CM_EVENT_DISCONNECTED;
+ work->event.status = -ECONNABORTED;
+
+ cma_id_get(id_priv);
+ work->id = id_priv;
+
+ queue_work(cma_wq, &work->work);
+ return 0;
+}
+
int rdma_disconnect(struct rdma_cm_id *id)
{
struct rdma_id_private *id_priv;
@@ -4838,12 +4866,15 @@ int rdma_disconnect(struct rdma_cm_id *id)
goto out;
/* Initiate or respond to a disconnect. */
trace_cm_disconnect(id_priv);
- if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) {
- if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0))
- trace_cm_sent_drep(id_priv);
- } else {
+ if (!ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) {
trace_cm_sent_dreq(id_priv);
+ goto out;
+ }
+ if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0)) {
+ trace_cm_sent_drep(id_priv);
+ goto out;
}
+ ret = cma_force_disconnect(id_priv);
} else if (rdma_cap_iw_cm(id->device, id->port_num)) {
ret = iw_cm_disconnect(id_priv->cm_id.iw, 0);
} else
--
2.55.0
next prev parent reply other threads:[~2026-09-08 15:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 15:44 [PATCH 0/2] smbdirect: don't hang on netdev reconfiguration Ammar Ratnani
2026-09-08 15:44 ` Ammar Ratnani [this message]
2026-09-08 15:44 ` [PATCH 2/2] infiniband: trace force disconnections Ammar Ratnani
2026-09-08 16:16 ` [PATCH 0/2] smbdirect: don't hang on netdev reconfiguration Stefan Metzmacher
2026-09-09 8:13 ` Ammar Ratnani
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=20260908154454.10966-2-ammrat13@gmail.com \
--to=ammrat13@gmail.com \
--cc=aratnani@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=kechenl@nvidia.com \
--cc=leon@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=metze@samba.org \
--cc=mmaragiri@nvidia.com \
--cc=pc@manguebit.org \
--cc=samba-technical@lists.samba.org \
--cc=tom@talpey.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®