Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ermenson.sec@gmail.com
Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com,
	sidraya@linux.ibm.com, mjambigi@linux.ibm.com,
	tonylu@linux.alibaba.com, guwen@linux.alibaba.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, willemb@google.com, horms@kernel.org,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
Date: Thu, 03 Dec 2026 13:31:58 +0000	[thread overview]
Message-ID: <179630471879.3146.18045828641124881081@kernel.org> (raw)
In-Reply-To: <20261202131243.664308-1-ermenson.sec@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The "per-peer" lock is really one of 64 bucket mutexes.
- [Medium] This finding is about the first-contact ADD_LINK phase that
  the patch moved out from under smc_server_lgr_pending.
- [Medium] Before the patch, smc_server_lgr_pending covered the whole
  window in which a new first-contact link group has no active link:…
- [Low] In smc_listen_work() (net/smc/af_smc.c), smc_server_lgr_pending
  is now released right after smc_clc_send_accept().
- [Low] smc_server_peer_pending_lock() mixes the proposal's RoCEv2 GID
  (v2_ext->roce) into the key whenever smcr_indicated(pclc->hdr.typev2)…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  smc_llc_srv_rkey_exchange() (net/smc/smc_llc.c:1347-1386) has a loop…

--

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

With this patch, smc_listen_work() releases smc_server_lgr_pending once
the CLC ACCEPT has been sent. It adds 64 mutexes, picked by a jhash of
the proposal's peer system id and gids, and holds the chosen one across
the CLC CONFIRM wait and smc_listen_rdma_finish(). The goal is to stop a
silent peer from stalling unrelated server-side SMC-R handshakes.

> 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);

[Severity: Low]
Should the v2 GID be mixed in only when the proposal really is a v2 one?

Here v2_ext->roce goes into the key whenever typev2 indicates SMC-R and
smc_get_clc_v2_ext() returns a pointer. smc_listen_v2_check() is
stricter. It honours typev2 only when pclc->hdr.version > SMC_V1, and it
clears SMC_V2 from ini->smcr_version when the v2 extension is missing or
eid_cnt is zero.

smc_find_rdma_v2_device_serv() copies smc_v2_ext->roce into
ini->peer_gid only if SMC_V2 is still set. It can also clear SMC_V2 on an
EID mismatch, when no v2 device is found, or when rdma init/reg fails.

In each of those cases smcr_lgr_match() compares only ini->peer_gid,
which is pclc->lcl.gid (plus the MAC for v1). The key still depends on
v2_ext->roce bytes that the match never looks at.

Can two proposals from one peer that agree on everything smcr_lgr_match()
compares then hash to different buckets, so that each one creates a
first-contact link group?

This also makes two of the new comments inaccurate. The comment above
says the helper hashes "the fields of the proposal that smcr_lgr_match()
compares", but the match compares one gid, chosen by version, not both.
The comment in smc_listen_work() says the proposal "has already been
received and validated", but the key ignores hdr.version and the results
of that validation.

Would gating the v2 GID on pclc->hdr.version > SMC_V1, as
smc_listen_v2_check() does, at least make the two sides agree on the
version check?

> +
> +	return &smc_server_peer_pending[key & (SMC_SERVER_PEER_PENDING_SIZE - 1)];
> +}

[Severity: Medium]
Is "per peer" an accurate name for this lock? It is one of 64 mutexes,
picked by jhash with a fixed initval of 0 over proposal bytes the server
does not authenticate: lcl.id_for_peer, lcl.gid and, for SMC-R v2,
v2_ext->roce. The bucket is held across the CLC CONFIRM wait, which the
peer paces, and across the rest of smc_listen_rdma_finish().

There seem to be three ways this falls short of the changelog's "This
confines the CLC CONFIRM wait of an unresponsive peer to that peer".

First, an honest unrelated peer whose key lands in a stalled peer's
bucket still waits up to CLC_WAIT_TIME. With N stalled peers the chance
of that is 1 - (63/64)^N, and the changelog does not mention it.

Second, on the v2 path lcl.id_for_peer and lcl.gid are never checked. An
honest v2-only Linux proposal leaves lcl zeroed, because
smc_clc_send_proposal() fills lcl only when typev1 indicates SMC-R.
Since the hash is fixed, a victim's bucket can be computed offline from
its RoCEv2 gid. About 64 silent connections can also fill every bucket,
which brings back the host-wide stall.

Third, up to 64 half-established first-contact link groups, each with a
QP and registered RMB/sndbuf, can now be pending at once. Before, there
could be at most one.

The source comment also leaves the limits of the key to the changelog
instead of stating them.

Would it be worth seeding the hash with a random secret, for example via
net_get_random_once() or get_random_u32()? That is the usual netdev
approach for hashes over input from the peer, and it would at least stop
offline targeting of a bucket.

[ ... ]

> @@ -2531,18 +2567,25 @@ static void smc_listen_work(struct work_struct *work)
>  	/* determine ISM or RoCE device used for connection */
>  	rc = smc_listen_find_device(new_smc, pclc, ini);
>  	if (rc)
> -		goto out_unlock;
> +		goto out_unlock_global;
>  
>  	/* send SMC Accept CLC message */
>  	accept_version = ini->is_smcd ? ini->smcd_version : ini->smcr_version;
>  	rc = smc_clc_send_accept(new_smc, ini->first_contact_local,
>  				 accept_version, ini->negotiated_eid, ini);
>  	if (rc)
> -		goto out_unlock;
> +		goto out_unlock_global;
> +
> +	/* Link group creation is complete, so the global lock is not needed
> +	 * across the wait for the peer's CLC CONFIRM below. The per-peer lock
> +	 * still keeps further connections of this peer out of
> +	 * smc_conn_create() until the first link becomes active.
> +	 */
> +	mutex_unlock(&smc_server_lgr_pending);

[Severity: Low]
Is "Link group creation is complete" accurate here? The changelog says
the global lock is kept "for link group creation only". Dropping it at
this point takes all of smc_listen_rdma_finish() out from under
smc_server_lgr_pending, not only the CLC CONFIRM receive.

That covers smc_link_save_peer_info(), smc_rmb_rtoken_handling(),
smc_ib_ready_link() and smcr_serv_conf_first_link(). The last one
contains the LLC CONFIRM_LINK wait, the fallback CLC DECLINE wait,
smc_llc_link_active() and the second-link setup:

net/smc/af_smc.c:smcr_serv_conf_first_link() {
    ...
	if (link->lgr->max_links > 1) {
		down_write(&link->lgr->llc_conf_mutex);
		/* initial contact - try to establish second link */
		smc_llc_srv_add_link(link, NULL);
		up_write(&link->lgr->llc_conf_mutex);
	}
    ...
}

max_links > 1 is always true for v1 link groups
(SMC_LINKS_ADD_LNK_MAX). When the global lock is released, the new link
group has no active link and no second link yet.

The changelog's safety argument covers duplicate first-contact link
groups and rtoken filling for joiners. It does not cover this
first-contact ADD_LINK phase, which now runs alongside other workers that
hold the global mutex. The test notes also list multi-link link groups as
not covered.

Could the comment and changelog describe what actually moves out from
under the lock?

[Severity: Medium]
Can this create duplicate link groups for an honest peer?

Before this patch, smc_server_lgr_pending covered the whole window in
which a new first-contact link group has no active link. That window runs
from smc_conn_create() under smc_listen_find_device() until
smc_llc_link_active() in smcr_serv_conf_first_link(). Now only the
bucket mutex covers it, and smcr_lgr_match() skips inactive links:

net/smc/smc_core.c:smcr_lgr_match() {
    ...
	for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
		lnk = &lgr->lnk[i];

		if (!smc_link_active(lnk))
			continue;
    ...
}

Some second proposals from the same peer hash to a different bucket, for
example from a multi-port peer, after a v2 to v1 fallback, or with
different unused gid fields. Such a proposal takes the now free global
mutex, finds no match and creates another server-side link group. Each
duplicate costs an extra QP and buffers and, on v1, another add-link
attempt.

The changelog acknowledges this and names the exact alternative: let
smcr_lgr_match() see a pending link group. Multi-port RoCE peers with
v1/v2 fallback are a common SMC-R deployment.

Is losing the old guarantee acceptable here, or would the pending link
group approach be the better fix?

>  
> -	/* SMC-D does not need this lock any more */
> +	/* SMC-D does not need the per-peer lock past the ACCEPT either */
>  	if (ini->is_smcd)
> -		mutex_unlock(&smc_server_lgr_pending);
> +		mutex_unlock(pending_lock);

[ ... ]

> @@ -2573,7 +2616,7 @@ static void smc_listen_work(struct work_struct *work)
>  					    ini->first_contact_local, ini);
>  		if (rc)
>  			goto out_unlock;
> -		mutex_unlock(&smc_server_lgr_pending);
> +		mutex_unlock(pending_lock);

[Severity: Medium]
With the global mutex already dropped, can a joiner from a different
bucket end up holding smc_server_lgr_pending while it waits on this
worker's link group?

smc_listen_rdma_finish() holds the ADD_LINK LLC flow across
smcr_serv_conf_first_link():

net/smc/af_smc.c:smc_listen_rdma_finish() {
    ...
		smc_llc_flow_initiate(link->lgr, SMC_LLC_FLOW_ADD_LINK);
		reason_code = smcr_serv_conf_first_link(new_smc);
		smc_llc_flow_stop(link->lgr, &link->lgr->llc_flow_lcl);
    ...
}

smcr_serv_conf_first_link() makes the first link active, so the link
group can now be matched. If max_links > 1, it then holds llc_conf_mutex
for write across smc_llc_srv_add_link(). That function waits on the peer
for ADD_LINK and CONFIRM_LINK. On v1, smc_llc_srv_rkey_exchange() also
holds rmbs_lock for write. During all of this the worker holds only its
bucket mutex.

A second proposal from the same peer in another bucket can then match
the active link group under smc_server_lgr_pending and block while still
holding it:

smc_listen_work()
  mutex_lock(&smc_server_lgr_pending);
  smc_listen_find_device()
    ...
      smc_listen_rdma_init()
        smc_conn_create()      /* matches the active link group */
        smc_buf_create()
          __smc_buf_create()
            smc_buf_get_slot()           /* rmbs_lock */
            smcr_buf_map_usable_links()  /* down_read(llc_conf_mutex) */

Neither of those last two waits has a timeout. The joiner can also block
later in smc_listen_rdma_reg()->smcr_lgr_reg_rmbs()->
smc_llc_flow_initiate(SMC_LLC_FLOW_RKEY), which waits up to
SMC_LLC_WAIT_TIME * 10.

The host-wide mutex is then again held for as long as the peer chooses.
That stalls other server-side handshakes and also SMC-D client connects,
which take smc_server_lgr_pending too.

This is not a deadlock, since the first-contact worker never needs the
global or bucket mutex again. Before this patch, though, the first-contact
worker held the global mutex itself for this phase, so this chain across
workers did not exist.

Should the changelog's safety analysis cover this case?

[Severity: High]
This isn't a bug introduced by this patch, but the loop in
smc_llc_srv_rkey_exchange() reached from here has no iteration cap, and
the peer controls when it ends:

net/smc/smc_llc.c:smc_llc_srv_rkey_exchange() {
	down_write(&lgr->rmbs_lock);
    ...
	do {
    ...
		num_rkeys_recv = addc_llc->num_rkeys;
		max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG);
		for (i = 0; i < max; i++) {
    ...
			num_rkeys_recv--;
		}
		smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
	} while (num_rkeys_send || num_rkeys_recv);
    ...
}

Each round overwrites num_rkeys_recv with the value from the peer's
ADD_LINK_CONT. A peer that answers each one within SMC_LLC_WAIT_TIME with
num_rkeys = 255 keeps the listen worker in the loop forever. The worker
holds rmbs_lock and llc_conf_mutex for write, plus the ADD_LINK LLC flow,
the whole time.

Every SMC-Rv1 first contact can reach this through
smc_listen_rdma_finish()->smcr_serv_conf_first_link()->
smc_llc_srv_add_link(). A v1 link group has max_links =
SMC_LINKS_ADD_LNK_MAX, and ADD_LINK is sent even with only one device. An
established v1 link group can also reach it when the peer sends
REQ_ADD_LINK, via smc_llc_process_srv_add_link().

With this patch the first-contact worker holds only its bucket mutex
here. A joiner from the same peer that matches the link group still
blocks without a timeout in smc_buf_get_slot() or
smcr_buf_map_usable_links() while holding smc_server_lgr_pending.

Can the global mutex still be pinned indefinitely this way, stalling all
server-side SMC handshakes and SMC-D client connects on the host?

The notes after the --- line already mention this loop and a planned
patch that bounds it with a counter.

>  	}
>  	smc_conn_save_peer_info(new_smc, cclc);
>  

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202131243.664308-1-ermenson.sec%40gmail.com

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

Thread overview: 5+ 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 15:46   ` Ermenson Junior
2026-12-03 13:13 ` sashiko-bot
2026-12-03 13:31 ` netdev-bot+sashiko [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=179630471879.3146.18045828641124881081@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@kernel.org \
    --cc=ermenson.sec@gmail.com \
    --cc=guwen@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    --cc=willemb@google.com \
    /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