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 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/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