[PATCH 0/3] RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect()

From: Stefan Metzmacher

Date: Wed Dec 02 2026 - 07:38:44 EST


Hi,

if rdma_disconnect() is called while an active IB/RoCE connect is still
waiting for the REP, ib_send_cm_dreq() and ib_send_cm_drep() fail, as
the connection is not established. Since commit ba88a28b47a7
("RDMA/core: Force disconnect if DREP and DREQ fail") the caller then
gets RDMA_CM_EVENT_DISCONNECTED for a connection that was never
established, while the REQ is still pending in ib_cm. RDMA_CM_CONNECT
covers both a pending and an established connection, so the rdma_cm
state doesn't distinguish them.

- The first patch lets ib_send_cm_rej() cancel our outstanding REQ
(or REP), otherwise a following rdma_destroy_id() waits about 76
seconds until all retries of the REQ timed out.

- The second patch adds ib_cm_reject_pending_connect(), which
rejects a pending active connect and returns the former state,
with the check and the REJ done atomically, so the caller knows
whether a REP arrived in between.

- The third patch uses it in rdma_disconnect(): a connect still
waiting for the REP is rejected and reported as
RDMA_CM_EVENT_CONNECT_ERROR with -ECONNABORTED. If the REP is already being processed, only the REJ
is sent, as the REP upcall reports the failed connect itself.
Without a QP (rdma_ucm), the caller keeps getting
RDMA_CM_EVENT_DISCONNECTED as before. If ib_cm is already idle, a
pending REJECTED or UNREACHABLE event reports the failed connect,
so no second event is forced. An established connection still
gets the forced RDMA_CM_EVENT_DISCONNECTED.

This came up in the discussion about ba88a28b47a7 with Ammar and Chuck:
https://lore.kernel.org/linux-nfs/f491838c-f364-41a3-b886-ec75d281bf03@xxxxxxxxx/
A larger series lets rdma_disconnect() abort a connection setup for
iWarp as well, on top of these two patches, I'll post it later.

These patches were developed with the help of Claude (Anthropic),
which was used for code analysis, writing parts of the code and the
commit messages. I reviewed all changes and take full responsibility
for them.

Testing: two hosts with rxe, Intel E810 (irdma) and ConnectX (mlx5) in
RoCEv2 mode: SMB over RDMA (cifs.ko/ksmbd.ko) connects against a
listener that never answers, aborted after about 5 seconds and by
killing the mounting processes, without waiting for the REQ retries,
and a user space rdma_cm test that aborts pending connects with
rdma_disconnect() or by destroying the QP or the rdma_cm_id first.
The established case (address removed or link down while connected)
works as before.

Base: linux-rdma/for-next (a8671ee9bde1).

Stefan Metzmacher (3):
RDMA/cm: cancel the outstanding REQ or REP in ib_send_cm_rej()
RDMA/cm: add ib_cm_reject_pending_connect()
RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect()

drivers/infiniband/core/cm.c | 45 +++++++++++-
drivers/infiniband/core/cma.c | 110 ++++++++++++++++++++++++++++
drivers/infiniband/core/cma_trace.h | 1 +
include/rdma/ib_cm.h | 17 +++++
4 files changed, 171 insertions(+), 2 deletions(-)

--
2.43.0