Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ermenson Junior" <ermenson.sec@gmail.com>
Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
Date: Thu, 03 Dec 2026 13:13:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-247832@kernel.org> (raw)
In-Reply-To: <20261202131243.664308-1-ermenson.sec@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/smc: missing SMCv1 check in
  smc_server_peer_pending_lock()
--

commit 96c005e08a29bc14d74ae1b6b0b09f1153e206a7
Author: Ermenson Junior <ermenson.sec@gmail.com>

net/smc: serialize the server establishment phase per peer, not globally

This commit replaces the hold of the global smc_server_lgr_pending mutex
across the server-side CLC CONFIRM wait with a per-peer mutex hashed on
the peer system ID and GIDs from the CLC proposal.

> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index c0d905140a10a..f2a8e32a2eea6 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
[ ... ]
> @@ -66,6 +67,34 @@ static DEFINE_MUTEX(smc_client_lgr_pending);	/* serialize link group
>  						 * creation on client
>  						 */
>  
> +/* Serialize the server-side establishment phase per peer, hashed on the
> + * fields of the proposal that smcr_lgr_match() compares: peer system id and
> + * both peer gids. The system id alone is all zero in a v2-only proposal.
> + * Keeps further connections of a peer out of smc_conn_create() until a new
> + * link group's first link is active, which is what smc_server_lgr_pending
> + * used to cover across the peer-paced CLC CONFIRM wait. See the changelog
> + * for what the key does not pin.
> + */
> +#define SMC_SERVER_PEER_PENDING_BITS	6
> +#define SMC_SERVER_PEER_PENDING_SIZE	BIT(SMC_SERVER_PEER_PENDING_BITS)
> +static struct mutex smc_server_peer_pending[SMC_SERVER_PEER_PENDING_SIZE];
> +
> +static struct mutex *
> +smc_server_peer_pending_lock(struct smc_clc_msg_proposal *pclc)
> +{
> +	struct smc_clc_v2_extension *v2_ext = NULL;
> +	u32 key;
> +
> +	key = jhash(pclc->lcl.id_for_peer, SMC_SYSTEMID_LEN, 0);
> +	key = jhash(pclc->lcl.gid, SMC_GID_SIZE, key);
> +	if (smcr_indicated(pclc->hdr.typev2))
> +		v2_ext = smc_get_clc_v2_ext(pclc);
> +	if (v2_ext)
> +		key = jhash(v2_ext->roce, SMC_GID_SIZE, key);
> +
> +	return &smc_server_peer_pending[key & (SMC_SERVER_PEER_PENDING_SIZE - 1)];
> +}

[Severity: Medium]
Should smc_server_peer_pending_lock() check pclc->hdr.version > SMC_V1
before inspecting pclc->hdr.typev2 and calling smc_get_clc_v2_ext(pclc)?

In an SMCv1 proposal header, the 2-bit typev2 field is reserved and set
to 0, which matches SMC_TYPE_R (0) and satisfies smcr_indicated().
When an SMC-Rv1 proposal does not indicate SMC-D (typev1 == SMC_TYPE_R,
iparea_offset == 0), smc_get_clc_msg_smcd() does not check iparea_offset
and returns (pclc + 1), which points into the IP prefix area rather than
a struct smc_clc_msg_smcd:

net/smc/smc_clc.h:smc_get_clc_msg_smcd() {
	if (smcd_indicated(prop->hdr.typev1) &&
	    ntohs(prop->iparea_offset) != sizeof(struct smc_clc_msg_smcd))
		return NULL;

	return (struct smc_clc_msg_smcd *)(prop + 1);
}

smc_get_clc_v2_ext() then reads prop_smcd->v2_ext_offset from the prefix
area (overlapping the first IPv6 prefix entry when ipv6_prefixes_cnt >= 1).
If those bytes fall between 1 and max_offset, v2_ext is non-NULL and 16
bytes from the buffer are hashed as v2_ext->roce.  Concurrent SMC-Rv1
first-contact handshakes from the same single-port peer (for example,
over IPv4 and IPv6) can then hash to different mutex buckets and race to
create duplicate link groups after smc_server_lgr_pending is released.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202131243.664308-1-ermenson.sec@gmail.com?part=1

      parent reply	other threads:[~2026-12-03 13:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:12 [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally Ermenson Junior
2026-12-03  8:35 ` Mahanta Jambigi
2026-12-03 13:13 ` sashiko-bot [this message]

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-247832@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=ermenson.sec@gmail.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox