From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.82.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796215131; b=UZqXgJq2mtWwUslZGP5sSTtmmttGDphriiQ/awTcyjVd9ha9QBPpjiZ5wJ3jtnhKaZIk +b1ndQSSypaUtWg3G7Dyf8eRdAkb0miGFok7alUfRs7ufmtaj4szgcr5iYJCftxUJ2ubX edJe/uPGrk8FfL0RrZeO6nTXzRnEV1QJ3Ua8frs0PBpf1WzRONa+/ZzmTImlFgJ0ijzmJ dSngqbwysjRDyi/5t0TSWnIknnpr1P0YGaNaDTtPxG+9hBi4ESYUov8K1hXdhezlKuukX Az70fQiFR7UBcs8nS1NTjEV+3ywqbaNe8jy1fryVa6P22v9m7wSlngMU98V4xn3qMKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796215131; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=b1MZ4rQhITjoXEHbbYLbdqI59rvNOCM+I90Cu6sEtK0=; b=nHjaXKu4zhzAv3Wmq1Rg+B58EgJRDxBSklBChybrpPfYHLuaFYpFOX4mN1PFDdXBQ6gp EHCcxG1fqUpMkm0LaIyMUGRDAStJKFyAlEBgOE51GWoLM5i79ssvIZvcu4Ee1mQOSoUIL dTG8j8SS/Zn13ocY052BnctQZy3TUrMEERr+fTLHQSEaht3vH5/w8nVDAl5A8LwmWTj0A Qt53ZkrbaOxnLMxRNyOoj2x1AtCyTvFwB00G/FtBBDLx3yRv0VYxsA7xnQtxExnQPdFFL aVSkCGIyQLRxYmXlDEc+O1L7sCDrxCN6WFB9mrd9weJwPdEo+8SwgwCpoqG+fq75Zow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=UW2amIAG; arc=none smtp.remote-ip=144.76.82.148 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A06A1606A329; Wed, 2 Dec 2026 12:38:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A06A1606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=UW2amIAG DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-ID:Date:Cc:To:From; bh=b1MZ4rQhITjoXEHbbYLbdqI59rvNOCM+I90Cu6sEtK0=; b=UW2amIAGkm4OdF+An1g8V5cFvQ 3cdk6iXBkeJD8qgSThk/TY7NaUIH4KCl8M+JLaJnn6tGqcLo6pth6kMMYf9pBQLlBYUQ2wQvmxne1 wHagkP6sUSdQ7m79btjNxZ/Hq5rBX5oZ8bdvOwjQxS66OwiWhNcxJEeJ0FnFVu5af2N4PBtR7fF+Q MR8mzFzjzAL6HmbDIaRi/NVkSoQOnOKRKmk6SvrOaz9ITP9yBJwcWqu1mGkixXh0uUgyRGdmSf067 51Fj3zCQaHywOViU808+dSfAAz5DmW+9N6rCk6Tn/DBFf0ApoLCb3W1hnlywk1HPyg3voHs+OOZQu IOdEOL9YBrV9V017F+Lhfnj4VOfTSGV5wNJ2iXQ60IN296iW8w2ft1Xwdz1Khb0huSit7lpzZ+D8e +HJcHHAbA6dOR3fcrlZnw1rR6t7/WlCH+2oQnUWQU10SosmpOil5JjVcLaRghrDTiJLENDxpf81nq SLfPwwq39z5WQMMK3JrXSGc1; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1xYjbg-00000000fiP-3qhC; Wed, 02 Dec 2026 12:38:45 +0000 From: Stefan Metzmacher To: linux-rdma@vger.kernel.org Cc: metze@samba.org, stable@vger.kernel.org, Bernard Metzler , Leon Romanovsky , Jason Gunthorpe , Yunseong Kim , Yunseong Kim , Jacob Moroni , Bart Van Assche , Ammar Ratnani , Chuck Lever , Li Xiasong , Trond Myklebust , Trond Myklebust , Anna Schumaker , Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Yue Haibing , Zhang Changzhong , Wei Yongjun , Tim Menninger , linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect() Date: Wed, 2 Dec 2026 13:38:13 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 ib_cm_id 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 and a REP arriving later is ignored by cma without sending an RTU, so the peer only notices via its own timeouts. Instead reject the pending connect with ib_cm_reject_pending_connect(), which checks the state and sends the REJ atomically, and report RDMA_CM_EVENT_CONNECT_ERROR with -ECONNABORTED, moving to RDMA_CM_DISCONNECT, so another rdma_disconnect() doesn't generate a second event. The QP was already moved to error, so it can be drained and destroyed. So the caller, also in user space via rdma_ucm, gets the same kind of event as for a connect rejected by the peer. If the REP already arrived (IB_CM_REP_RCVD or, after ib_prepare_cm_mra(), IB_CM_MRA_REP_SENT), cma_ib_handler() is processing it under the handler_mutex. With a QP also reject it, but don't queue an event: cma_rep_recv() fails, as the QP is in error or ib_send_cm_rtu() fails after the REJ, and the REP upcall reports RDMA_CM_EVENT_CONNECT_ERROR itself. Without a QP the caller got RDMA_CM_EVENT_CONNECT_RESPONSE and its rdma_accept() fails after the REJ, so it still gets RDMA_CM_EVENT_DISCONNECTED as before, which librdmacm ignores if it created the QP. If ib_cm is already in IB_CM_IDLE while the rdma_cm_id is still in RDMA_CM_CONNECT, the connect already failed, e.g. the peer sent a REJ or our REQ timed out, and the pending RDMA_CM_EVENT_REJECTED or RDMA_CM_EVENT_UNREACHABLE reports it, so don't force a second event. The work for the event is allocated before the REJ is sent, so that a rejected connect is always reported. On the passive side, if rdma_disconnect() is called after the REP was sent, but before the RTU arrived, the caller still gets the forced RDMA_CM_EVENT_DISCONNECTED, as before. The new rdma_cma:cm_abort_connect trace event shows when this happens. Fixes: ba88a28b47a7 ("RDMA/core: Force disconnect if DREP and DREQ fail") Cc: stable@vger.kernel.org Cc: Bernard Metzler Cc: Leon Romanovsky Cc: Jason Gunthorpe Cc: Yunseong Kim Cc: Yunseong Kim Cc: Jacob Moroni Cc: Bart Van Assche Cc: Ammar Ratnani Cc: Chuck Lever Cc: Li Xiasong Cc: Trond Myklebust Cc: Trond Myklebust Cc: Anna Schumaker Cc: Jeff Layton Cc: NeilBrown Cc: Olga Kornievskaia Cc: Dai Ngo Cc: Tom Talpey Cc: Yue Haibing Cc: Zhang Changzhong Cc: Wei Yongjun Cc: Tim Menninger 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 --- drivers/infiniband/core/cma.c | 110 ++++++++++++++++++++++++++++ drivers/infiniband/core/cma_trace.h | 1 + 2 files changed, 111 insertions(+) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 337a49d1acf7..077a98cd2caa 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -4846,6 +4846,114 @@ static int cma_force_disconnect(struct rdma_id_private *id_priv) return 0; } +/* + * Called from rdma_disconnect() after the pending active connect was + * rejected locally: report it to the caller like any other failed + * connect. + */ +static struct cma_work *cma_alloc_abort_work(void) +{ + struct cma_work *work; + + work = kzalloc_obj(*work); + if (!work) + return NULL; + + INIT_WORK(&work->work, cma_work_handler); + /* + * Like cma_force_disconnect() move to RDMA_CM_DISCONNECT, so + * another rdma_disconnect() doesn't generate a second event. + */ + work->old_state = RDMA_CM_CONNECT; + work->new_state = RDMA_CM_DISCONNECT; + work->event.event = RDMA_CM_EVENT_CONNECT_ERROR; + work->event.status = -ECONNABORTED; + + return work; +} + +static void cma_queue_abort_work(struct rdma_id_private *id_priv, + struct cma_work *work) +{ + cma_id_get(id_priv); + work->id = id_priv; + + trace_cm_abort_connect(id_priv); + + queue_work(cma_wq, &work->work); +} + +/* + * Returns true if rdma_disconnect() is done with *ret, false if the + * connection is established (or closing) and needs a DREQ or DREP. + */ +static bool cma_ib_abort_pending_connect(struct rdma_id_private *id_priv, + int *ret) +{ + struct ib_cm_id *cm_id = id_priv->cm_id.ib; + enum ib_cm_state old_state; + struct cma_work *work; + + /* + * Allocated before the REJ, so that a rejected connect is + * always reported. + */ + work = cma_alloc_abort_work(); + if (!work) { + *ret = -ENOMEM; + return true; + } + + trace_cm_send_rej(id_priv); + if (ib_cm_reject_pending_connect(cm_id, &old_state)) { + kfree(work); + if (old_state == IB_CM_IDLE) { + /* + * The connect already failed, e.g. the peer sent + * a REJ or our REQ timed out, and the pending + * REJECTED or UNREACHABLE event reports it, or + * it was already aborted. + */ + *ret = 0; + return true; + } + return false; + } + + switch (old_state) { + case IB_CM_REQ_SENT: + case IB_CM_MRA_REQ_RCVD: + /* + * Still waiting for the REP, so no other event is pending + * for the connect: report it as failed connect. A REP + * arriving later is dropped by ib_cm. + */ + cma_queue_abort_work(id_priv, work); + *ret = 0; + return true; + default: + break; + } + + /* + * The REP arrived (IB_CM_REP_RCVD or IB_CM_MRA_REP_SENT). With a + * QP it is being processed by cma_ib_handler() under the + * handler_mutex: cma_rep_recv() fails, as the QP is in error or + * ib_send_cm_rtu() fails after the REJ, and the REP upcall + * reports RDMA_CM_EVENT_CONNECT_ERROR itself, so we must not + * queue a second event. + * + * Without a QP the caller got (or is about to get) + * RDMA_CM_EVENT_CONNECT_RESPONSE and its rdma_accept() fails + * after the REJ, so keep reporting RDMA_CM_EVENT_DISCONNECTED via + * cma_force_disconnect() as before, librdmacm ignores it if it + * created the QP. + */ + kfree(work); + *ret = id_priv->id.qp ? 0 : cma_force_disconnect(id_priv); + return true; +} + int rdma_disconnect(struct rdma_cm_id *id) { struct rdma_id_private *id_priv; @@ -4859,6 +4967,8 @@ int rdma_disconnect(struct rdma_cm_id *id) ret = cma_modify_qp_err(id_priv); if (ret) goto out; + if (cma_ib_abort_pending_connect(id_priv, &ret)) + 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)) { diff --git a/drivers/infiniband/core/cma_trace.h b/drivers/infiniband/core/cma_trace.h index 3d05d8e80856..b3f43c575851 100644 --- a/drivers/infiniband/core/cma_trace.h +++ b/drivers/infiniband/core/cma_trace.h @@ -62,6 +62,7 @@ DEFINE_CMA_FSM_EVENT(disconnect); DEFINE_CMA_FSM_EVENT(sent_drep); DEFINE_CMA_FSM_EVENT(sent_dreq); DEFINE_CMA_FSM_EVENT(force_disconnect); +DEFINE_CMA_FSM_EVENT(abort_connect); DEFINE_CMA_FSM_EVENT(id_destroy); TRACE_EVENT(cm_id_attach, -- 2.43.0