All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stefan Metzmacher" <metze@samba.org>, linux-rdma@vger.kernel.org
Cc: "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH 2/3] RDMA/cm: add ib_cm_reject_pending_connect()
Date: Wed, 02 Dec 2026 12:50:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-245799@kernel.org> (raw)
In-Reply-To: <82e30641e75a574b3f98766b63cc603ebf0b8222.1796215022.git.metze@samba.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] RDMA/cm: unmatchable REJ sent before REP in
  ib_cm_reject_pending_connect()
--

commit 4b27fca63a8905d689ea7a1a5659bc7e21ff263b
Author: Stefan Metzmacher <metze@samba.org>

RDMA/cm: add ib_cm_reject_pending_connect()

This commit adds ib_cm_reject_pending_connect() to atomically check the
CM state, reject a pending active connection under cm_id_priv->lock, and
return the prior state to the caller.

> diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
> index d16fc71ed5e6c..9d43097a6ef02 100644
> --- a/drivers/infiniband/core/cm.c
> +++ b/drivers/infiniband/core/cm.c
> @@ -3025,6 +3025,40 @@ int ib_send_cm_rej(struct ib_cm_id *cm_id, enum ib_cm_rej_reason reason,
>  }
>  EXPORT_SYMBOL(ib_send_cm_rej);
>  
> +int ib_cm_reject_pending_connect(struct ib_cm_id *cm_id,
> +				 enum ib_cm_state *old_state)
> +{
> +	struct cm_id_private *cm_id_priv =
> +		container_of(cm_id, struct cm_id_private, id);
> +	unsigned long flags;
> +	int ret = -EINVAL;
> +
> +	spin_lock_irqsave(&cm_id_priv->lock, flags);
> +	*old_state = cm_id->state;
> +	switch (cm_id->state) {
> +	case IB_CM_REQ_SENT:
> +	case IB_CM_MRA_REQ_RCVD:
> +	case IB_CM_REP_RCVD:
> +	case IB_CM_MRA_REP_SENT:
> +		/*
> +		 * cm_send_rej_locked() moves the cm_id to IB_CM_IDLE
> +		 * before it sends the REJ, so the connect is aborted
> +		 * even if sending the REJ fails, the peer then
> +		 * notices via its own timeout.
> +		 */
> +		cm_send_rej_locked(cm_id_priv, IB_CM_REJ_CONSUMER_DEFINED,
> +				   NULL, 0, NULL, 0);
> +		ret = 0;
> +		break;

[Severity: High]
Does sending IB_CM_REJ_CONSUMER_DEFINED with a NULL ARI in IB_CM_REQ_SENT
and IB_CM_MRA_REQ_RCVD produce a REJ MAD that the passive peer cannot
match?

Before a REP arrives, cm_id_priv->id.remote_id is still 0.  On the passive
side, cm_acquire_rejected_id() only looks up the connection by the remote
CA GUID in the ARI and remote_id when the reason is IB_CM_REJ_TIMEOUT:

drivers/infiniband/core/cm.c:cm_acquire_rejected_id() {
	if (IBA_GET(CM_REJ_REASON, rej_msg) == IB_CM_REJ_TIMEOUT) {
		cm_id_priv = cm_find_remote_id(
			*((__be64 *)IBA_GET_MEM_PTR(CM_REJ_ARI, rej_msg)),
			remote_id);
	} else if (IBA_GET(CM_REJ_MESSAGE_REJECTED, rej_msg) ==
		   CM_MSG_RESPONSE_REQ)
		cm_id_priv = cm_acquire_id(
			cpu_to_be32(IBA_GET(CM_REJ_REMOTE_COMM_ID, rej_msg)),
			0);
	else
		cm_id_priv = cm_acquire_id(
			cpu_to_be32(IBA_GET(CM_REJ_REMOTE_COMM_ID, rej_msg)),
			remote_id);
}

With IB_CM_REJ_CONSUMER_DEFINED, cm_acquire_rejected_id() takes the final
else branch with CM_REJ_REMOTE_COMM_ID == 0, fails to find the cm_id, and
drops the REJ.  Because cm_send_rej_locked() also resets cm_id->state to
IB_CM_IDLE, a later cm_destroy_id() will no longer send the
IB_CM_REJ_TIMEOUT with node_guid in the ARI that it previously sent,
leaving the passive peer's connection and REP retries dangling until they
time out.

Should IB_CM_REQ_SENT and IB_CM_MRA_REQ_RCVD pass IB_CM_REJ_TIMEOUT and
&cm_id_priv->id.device->node_guid in the ARI, matching cm_destroy_id()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796215022.git.metze@samba.org?part=2

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

Thread overview: 7+ 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 ` [PATCH 1/3] RDMA/cm: cancel the outstanding REQ or REP in ib_send_cm_rej() Stefan Metzmacher
2026-12-02 12:38 ` [PATCH 2/3] RDMA/cm: add ib_cm_reject_pending_connect() Stefan Metzmacher
2026-12-02 12:50   ` sashiko-bot [this message]
2026-12-02 12:38 ` [PATCH 3/3] RDMA/cma: reject a pending IB/RoCE connect in rdma_disconnect() Stefan Metzmacher
2026-12-02 13:02   ` sashiko-bot
2026-12-02 13:02 ` [PATCH 0/3] " sashiko-bot

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=sashiko-outbox-245799@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.