Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
@ 2026-12-02 13:12 Ermenson Junior
  2026-12-03  8:35 ` Mahanta Jambigi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ermenson Junior @ 2026-12-02 13:12 UTC (permalink / raw)
  To: alibuda, dust.li, sidraya, mjambigi
  Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
	netdev, linux-rdma, linux-s390, Ermenson Junior

On the SMC-R server path smc_listen_work() holds the module-global
smc_server_lgr_pending across the wait for the peer's CLC CONFIRM, which
smc_clc_wait_msg() bounds only by CLC_WAIT_TIME per receive. A peer that
sends its proposal, reads the ACCEPT and then stays silent holds the
mutex for six seconds or more, and every other server-side handshake on
the host waits behind it. Commit 8270d9c21041 ("net/smc: Limit backlog
connections") already describes the lock as host wide.

The mutex cannot simply be released earlier: a first-contact link group
has no active link until smcr_serv_conf_first_link() has run, after the
CONFIRM, and smcr_lgr_match() skips inactive links, so a second
connection of the same peer would create a duplicate link group.

So keep smc_server_lgr_pending for link group creation only, released
once the ACCEPT is out, and hold a per-peer mutex (one of 64, hashed on
the proposal's peer system id and both peer gids) across the whole
establishment phase. Lock order is per-peer, then global.

The key is a heuristic. It is exact when a peer's proposals that match
one link group carry the same gids, which holds for a single-port peer.
A multi-port peer whose proposal falls back from v2 to v1 can hash two
such proposals apart, and the server then creates a second link group
for that peer instead of joining the first. No key built from the
proposal can be exact, because v1 or v2 is chosen later, under the
global mutex; making smcr_lgr_match() see a pending link group would be
exact, and is not attempted here. Connections joining a link group over
different links can also land in different buckets. That is safe because
a joining peer sends CONFIRM_RKEY before its CLC CONFIRM, so
smc_llc_rmt_conf_rkey() has filled the rtoken row before the listen
worker looks for it; a peer that does not can only harm its own link
group.

This confines the CLC CONFIRM wait of an unresponsive peer to that peer.
It does not bound the peer-paced waits that remain under the global
mutex in smc_listen_rdma_reg() for a peer with an existing link group,
and it is no defence against a peer that chooses its key.

Tested on v7.4-rc5 with two kernels differing only by this patch, on
soft-RoCE with two RoCEv2 peers in separate network namespaces: an
unrelated peer's connect() during a silent peer's handshake went from
4024.5 ms to 0.5 ms, while a connect from the same peer still waits.
Details, limits and what was not covered follow the --- line.

The problem was found and this patch, its changelog and the test lab
were written with Claude (Anthropic), used interactively, and reviewed
and tested by the author; Documentation/process/generated-content.rst
asks for this to be stated, and more detail follows the --- line.

Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
---

Notes for reviewers, not for the commit message.

HOW THIS WAS TESTED

Two kernels built from v7.4-rc5 (fe6ff8d5d675) with the same config and the
same script, differing only by this patch, booted in qemu with the same
initramfs. x86_64 defconfig + kvm_guest.config, SMC/SMC_DIAG/INFINIBAND/
RDMA_RXE/DIBS built in, DIBS_LO off so SMC-R is selected rather than SMC-D,
PROVE_LOCKING and DETECT_HUNG_TASK on. Both kernels built with zero warnings.

Topology: two network namespaces joined by a veth pair, a soft-RoCE (rxe)
device on each end, one UEID configured, two AF_SMC listeners on the server.
No RDMA hardware. The silent peer is simulated by dropping its CLC CONFIRM
with an iptables NFQUEUE handler on the server's INPUT chain; the peer keeps
its socket open, so from the server's side this is exactly a peer that
completes the proposal, reads the ACCEPT and then says nothing.

The number that matters is how long an UNRELATED peer's connect() takes while
a silent peer is in flight. All times are the client's measured elapsed_ms,
all connects returned rc=0.

                                                   unpatched      patched
  no silent peer (sanity)                              0.6 ms       0.5 ms
  silent peer; victim is a second RoCEv2 peer,
    own namespace and rxe device, nothing rewritten 4024.5 ms       0.5 ms
  silent peer; victim is the SAME peer (control)    4170.1 ms    4352.1 ms
  silent peer with a rewritten system id (see below) 4196.2 ms      0.8 ms
  after everything drained                             0.6 ms       0.5 ms

The second row is the deployment that matters: two RoCEv2 peers, both
announcing the all-zero system id that a v2-only proposal carries, differing in
gid and in nothing else. The stalls are about four seconds rather than six
because the victim starts two seconds into the silent peer's six-second window.

The third row is the control and it is meant to stall on both kernels: two
first contacts of one peer still have to serialize, so a peer can still delay
itself. If that row had improved too, the improvement in the second row would
not have been attributable to the key.

A fast victim is only evidence if it really negotiated SMC, since a fallback to
TCP also returns rc=0 in well under a millisecond. The smc_switch_to_fallback
tracepoint was enabled for the whole run on both kernels; it fired exactly once
per run, at about 8 s, for the silent peer of an earlier phase timing out its
own CONFIRM_LINK wait (SMC_CLC_DECL_TIMEOUT_CL). No victim fell back.

Two things the lab made obvious, in the order I learned them. First, on
soft-RoCE no SMC-Rv1 can be offered (it needs IB_GID_TYPE_ROCE and rxe only has
RoCEv2 gids), and smc_clc_send_proposal() fills smc_clc_msg_local only when v1
is offered, so every proposal in this lab carries an all-zero id_for_peer. A
first version of this patch keyed the mutex on the system id alone, and the
only way to measure it was to rewrite id_for_peer in the attacker's proposal in
flight. That worked in the lab and would have isolated nothing on a real RoCEv2
deployment, where every peer announces the same zero id. The key now includes
the gid, and the decisive row above has two peers in separate namespaces with
their own rxe devices, differing in gid and in nothing else, with no field
rewritten. Second, that rewrite is itself the demonstration that the key is
chosen by the peer and authenticated by nothing, which is why the changelog
makes no claim against a peer that is trying.

In both kernels the silent peer's connection was confirmed to reach the
server's wait: its proposal was seen and its CONFIRM was dropped eight or
nine times over the 20 s it held the socket, eight on one kernel and nine on
the other. Without that check a fast victim would be indistinguishable from an
attack that never happened.

One thing in the logs I have not investigated: after the test, when the guest's
init runs poweroff with the silent peers' sockets still open, both kernels print
a hung-task report for poweroff in smc_cdc_wait_pend_tx_wr(). It is identical
on the unpatched kernel, so it is not this patch, and it is outside what I set
out to measure; I mention it so nobody finds it in a log and thinks it was
hidden.

No lockdep report of any kind appeared on the patched kernel, which is the
check that matters for the new lock order (per-peer mutex, then
smc_server_lgr_pending).

WHAT I COULD NOT DO, AND ONE MEASUREMENT I AM NOT QUOTING

Both peers are AF_SMC sockets in the same kernel, so a local client doing
first contact waits in smcr_clnt_conf_first_link() for a CONFIRM_LINK that
cannot arrive and holds smc_client_lgr_pending - the other global mutex - for
about five seconds. A remote attacker cannot touch that lock, but in this lab
it hides the effect of this patch: measured that way the victim went from
4333.5 ms to 3052.0 ms, and 3052 ms is within a millisecond of when the
attacker's own client gave up (5052.5 ms after it started, two seconds before
the victim). The rows above avoid this by letting each peer complete one
connection first, so the silent connection that follows is first contact on
neither side; its client returned in 1.6 ms and 1.7 ms and held no client-side
lock. I mention it because that contaminated pair of numbers is what the
obvious version of this experiment produces, and read alone it says the patch
does not work.

Not covered: real RDMA hardware, SMC-D, SMC-v1 (soft-RoCE offers only RoCEv2
GIDs, so a v1 proposal cannot be produced on it), link groups with more than
one link, and s390. The SMC-D path is unchanged by inspection, not by
measurement.

The reproducer is a set of shell and C files rather than a single script. It
is not inlined here; I will send it to whoever wants it.

No Fixes tag and net-next, deliberately: the behaviour is as old as the first
implementation (0cfdd8f92cac, 2017) and was documented as host-wide by the
maintainers in 8270d9c21041, and this is a change to how the handshake is
serialized, not a backport candidate.

Per Documentation/process/security-bugs.rst, a reproducer for an AI-assisted
finding is not posted to a public list. Mine is a few shell and C files for the
namespace lab above; I will send them to any maintainer who asks.

One observation from reading the surrounding code that I have NOT measured and
that this patch does not touch. On the SMC-Rv1 path, smc_llc_srv_rkey_exchange()
re-reads num_rkeys from each ADD_LINK_CONT the peer sends and loops while it is
non-zero, with no iteration cap; max_links is a fixed 2 on a v1 link group, so
every v1 first contact reaches it, and before this patch that was under
smc_server_lgr_pending. Commit 2d1e7c5aaa33 bounded the v2 twin of this loop
this year and left the v1 one as it was; smc_llc_cli_rkey_exchange() has the
same shape on the client side. I cannot measure it here because soft-RoCE
offers no RoCEv1 gid, so SMC-Rv1 cannot be negotiated on this lab. I will send
a bounded-counter patch for it separately rather than fold it in here.

checkpatch --strict reports no errors and no checks. It reports one "Unknown
commit id" warning, for 8270d9c21041, the only commit the changelog cites; git
was not available in the container where checkpatch ran, and the commit
resolves with the title used here.

Tool use, as Documentation/process/generated-content.rst asks. The tool was
Claude (Anthropic), driven interactively by me over one session. It read
net/smc at v7.4-rc5, located the hold across the CONFIRM wait and the
smcr_lgr_match() active-link condition behind it, proposed the per-peer key,
and wrote the hunk in this patch, the changelog, these notes, the kernel build
scripts and the namespace test (the guest init script and the netfilter helper
that drops or rewrites CLC messages in flight); it also ran the two-kernel
measurement. Four adversarial review passes by separate model instances were
run before sending and changed the key (system id alone to system id plus the
gids), the target tree (net to net-next) and several claims in the changelog
that did not survive them. I reviewed the patch and the measurement and
take responsibility for both.

 net/smc/af_smc.c | 62 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 55 insertions(+), 7 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a12..d2858e75fc1d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -26,6 +26,7 @@
 #include <linux/if_vlan.h>
 #include <linux/rcupdate_wait.h>
 #include <linux/ctype.h>
+#include <linux/jhash.h>
 #include <linux/splice.h>
 
 #include <net/sock.h>
@@ -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)];
+}
+
 static struct workqueue_struct	*smc_tcp_ls_wq;	/* wq for tcp listen work */
 struct workqueue_struct	*smc_hs_wq;	/* wq for handshake work */
 struct workqueue_struct	*smc_close_wq;	/* wq for close work */
@@ -2462,6 +2491,7 @@ static void smc_listen_work(struct work_struct *work)
 	struct smc_clc_msg_accept_confirm *cclc;
 	struct smc_clc_msg_proposal_area *buf;
 	struct smc_clc_msg_proposal *pclc;
+	struct mutex *pending_lock = NULL;
 	struct smc_init_info *ini = NULL;
 	u8 proposal_version = SMC_V1;
 	u8 accept_version;
@@ -2524,6 +2554,12 @@ static void smc_listen_work(struct work_struct *work)
 	if (rc)
 		goto out_decl;
 
+	/* The key comes from the proposal, which has already been received and
+	 * validated, so the per-peer lock can be taken first. Lock order is
+	 * always per-peer lock before smc_server_lgr_pending.
+	 */
+	pending_lock = smc_server_peer_pending_lock(pclc);
+	mutex_lock(pending_lock);
 	mutex_lock(&smc_server_lgr_pending);
 	smc_rx_init(new_smc);
 	smc_tx_init(new_smc);
@@ -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);
 
-	/* 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);
 
 	/* receive SMC Confirm CLC message */
 	memset(buf, 0, sizeof(*buf));
@@ -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);
 	}
 	smc_conn_save_peer_info(new_smc, cclc);
 
@@ -2589,8 +2632,10 @@ static void smc_listen_work(struct work_struct *work)
 	smc_listen_out_connected(new_smc);
 	goto out_free;
 
-out_unlock:
+out_unlock_global:
 	mutex_unlock(&smc_server_lgr_pending);
+out_unlock:
+	mutex_unlock(pending_lock);
 out_decl:
 	smc_listen_decline(new_smc, rc, ini ? ini->first_contact_local : 0,
 			   proposal_version);
@@ -3463,7 +3508,10 @@ static struct pernet_operations smc_net_stat_ops = {
 
 static int __init smc_init(void)
 {
-	int rc;
+	int i, rc;
+
+	for (i = 0; i < SMC_SERVER_PEER_PENDING_SIZE; i++)
+		mutex_init(&smc_server_peer_pending[i]);
 
 	rc = register_pernet_subsys(&smc_net_ops);
 	if (rc)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
  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
  2 siblings, 1 reply; 5+ messages in thread
From: Mahanta Jambigi @ 2026-12-03  8:35 UTC (permalink / raw)
  To: Ermenson Junior, alibuda, dust.li, sidraya
  Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
	netdev, linux-rdma, linux-s390

Hi Ermenson,

Thanks for the patch and the detailed notes. I went through the server
path and the locking and did not find a memory-safety or lock-order
problem; checkpatch --strict is clean.

One thing I would like to settle before it goes in: the duplicate link
group. The global lock was exact, the hash is not. A multi-port peer
whose proposal falls back from v2 to v1 can hash apart, and the server
creates a second link group for that peer instead of joining the first.
That is not only an attacker; a legitimate multi-port peer can hit it,
and it changes behaviour from joining the first lgr to two lgrs. What
happens to the peer and the resources in that case? If a duplicate lgr
is not harmless, I would rather see the exact fix you decline to
attempt: make smcr_lgr_match() see the pending link group, or key on
something the v1/v2 decision cannot split.

Thanks,
Mahanta

On 02/12/26 6:42 pm, Ermenson Junior wrote:
> On the SMC-R server path smc_listen_work() holds the module-global
> smc_server_lgr_pending across the wait for the peer's CLC CONFIRM, which
> smc_clc_wait_msg() bounds only by CLC_WAIT_TIME per receive. A peer that
> sends its proposal, reads the ACCEPT and then stays silent holds the
> mutex for six seconds or more, and every other server-side handshake on
> the host waits behind it. Commit 8270d9c21041 ("net/smc: Limit backlog
> connections") already describes the lock as host wide.
> 
> The mutex cannot simply be released earlier: a first-contact link group
> has no active link until smcr_serv_conf_first_link() has run, after the
> CONFIRM, and smcr_lgr_match() skips inactive links, so a second
> connection of the same peer would create a duplicate link group.
> 
> So keep smc_server_lgr_pending for link group creation only, released
> once the ACCEPT is out, and hold a per-peer mutex (one of 64, hashed on
> the proposal's peer system id and both peer gids) across the whole
> establishment phase. Lock order is per-peer, then global.
> 
> The key is a heuristic. It is exact when a peer's proposals that match
> one link group carry the same gids, which holds for a single-port peer.
> A multi-port peer whose proposal falls back from v2 to v1 can hash two
> such proposals apart, and the server then creates a second link group
> for that peer instead of joining the first. No key built from the
> proposal can be exact, because v1 or v2 is chosen later, under the
> global mutex; making smcr_lgr_match() see a pending link group would be
> exact, and is not attempted here. Connections joining a link group over
> different links can also land in different buckets. That is safe because
> a joining peer sends CONFIRM_RKEY before its CLC CONFIRM, so
> smc_llc_rmt_conf_rkey() has filled the rtoken row before the listen
> worker looks for it; a peer that does not can only harm its own link
> group.
> 
> This confines the CLC CONFIRM wait of an unresponsive peer to that peer.
> It does not bound the peer-paced waits that remain under the global
> mutex in smc_listen_rdma_reg() for a peer with an existing link group,
> and it is no defence against a peer that chooses its key.
> 
> Tested on v7.4-rc5 with two kernels differing only by this patch, on
> soft-RoCE with two RoCEv2 peers in separate network namespaces: an
> unrelated peer's connect() during a silent peer's handshake went from
> 4024.5 ms to 0.5 ms, while a connect from the same peer still waits.
> Details, limits and what was not covered follow the --- line.
> 
> The problem was found and this patch, its changelog and the test lab
> were written with Claude (Anthropic), used interactively, and reviewed
> and tested by the author; Documentation/process/generated-content.rst
> asks for this to be stated, and more detail follows the --- line.
> 
> Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
> ---
> 
> Notes for reviewers, not for the commit message.
> 
> HOW THIS WAS TESTED
> 
> Two kernels built from v7.4-rc5 (fe6ff8d5d675) with the same config and the
> same script, differing only by this patch, booted in qemu with the same
> initramfs. x86_64 defconfig + kvm_guest.config, SMC/SMC_DIAG/INFINIBAND/
> RDMA_RXE/DIBS built in, DIBS_LO off so SMC-R is selected rather than SMC-D,
> PROVE_LOCKING and DETECT_HUNG_TASK on. Both kernels built with zero warnings.
> 
> Topology: two network namespaces joined by a veth pair, a soft-RoCE (rxe)
> device on each end, one UEID configured, two AF_SMC listeners on the server.
> No RDMA hardware. The silent peer is simulated by dropping its CLC CONFIRM
> with an iptables NFQUEUE handler on the server's INPUT chain; the peer keeps
> its socket open, so from the server's side this is exactly a peer that
> completes the proposal, reads the ACCEPT and then says nothing.
> 
> The number that matters is how long an UNRELATED peer's connect() takes while
> a silent peer is in flight. All times are the client's measured elapsed_ms,
> all connects returned rc=0.
> 
>                                                    unpatched      patched
>   no silent peer (sanity)                              0.6 ms       0.5 ms
>   silent peer; victim is a second RoCEv2 peer,
>     own namespace and rxe device, nothing rewritten 4024.5 ms       0.5 ms
>   silent peer; victim is the SAME peer (control)    4170.1 ms    4352.1 ms
>   silent peer with a rewritten system id (see below) 4196.2 ms      0.8 ms
>   after everything drained                             0.6 ms       0.5 ms
> 
> The second row is the deployment that matters: two RoCEv2 peers, both
> announcing the all-zero system id that a v2-only proposal carries, differing in
> gid and in nothing else. The stalls are about four seconds rather than six
> because the victim starts two seconds into the silent peer's six-second window.
> 
> The third row is the control and it is meant to stall on both kernels: two
> first contacts of one peer still have to serialize, so a peer can still delay
> itself. If that row had improved too, the improvement in the second row would
> not have been attributable to the key.
> 
> A fast victim is only evidence if it really negotiated SMC, since a fallback to
> TCP also returns rc=0 in well under a millisecond. The smc_switch_to_fallback
> tracepoint was enabled for the whole run on both kernels; it fired exactly once
> per run, at about 8 s, for the silent peer of an earlier phase timing out its
> own CONFIRM_LINK wait (SMC_CLC_DECL_TIMEOUT_CL). No victim fell back.
> 
> Two things the lab made obvious, in the order I learned them. First, on
> soft-RoCE no SMC-Rv1 can be offered (it needs IB_GID_TYPE_ROCE and rxe only has
> RoCEv2 gids), and smc_clc_send_proposal() fills smc_clc_msg_local only when v1
> is offered, so every proposal in this lab carries an all-zero id_for_peer. A
> first version of this patch keyed the mutex on the system id alone, and the
> only way to measure it was to rewrite id_for_peer in the attacker's proposal in
> flight. That worked in the lab and would have isolated nothing on a real RoCEv2
> deployment, where every peer announces the same zero id. The key now includes
> the gid, and the decisive row above has two peers in separate namespaces with
> their own rxe devices, differing in gid and in nothing else, with no field
> rewritten. Second, that rewrite is itself the demonstration that the key is
> chosen by the peer and authenticated by nothing, which is why the changelog
> makes no claim against a peer that is trying.
> 
> In both kernels the silent peer's connection was confirmed to reach the
> server's wait: its proposal was seen and its CONFIRM was dropped eight or
> nine times over the 20 s it held the socket, eight on one kernel and nine on
> the other. Without that check a fast victim would be indistinguishable from an
> attack that never happened.
> 
> One thing in the logs I have not investigated: after the test, when the guest's
> init runs poweroff with the silent peers' sockets still open, both kernels print
> a hung-task report for poweroff in smc_cdc_wait_pend_tx_wr(). It is identical
> on the unpatched kernel, so it is not this patch, and it is outside what I set
> out to measure; I mention it so nobody finds it in a log and thinks it was
> hidden.
> 
> No lockdep report of any kind appeared on the patched kernel, which is the
> check that matters for the new lock order (per-peer mutex, then
> smc_server_lgr_pending).
> 
> WHAT I COULD NOT DO, AND ONE MEASUREMENT I AM NOT QUOTING
> 
> Both peers are AF_SMC sockets in the same kernel, so a local client doing
> first contact waits in smcr_clnt_conf_first_link() for a CONFIRM_LINK that
> cannot arrive and holds smc_client_lgr_pending - the other global mutex - for
> about five seconds. A remote attacker cannot touch that lock, but in this lab
> it hides the effect of this patch: measured that way the victim went from
> 4333.5 ms to 3052.0 ms, and 3052 ms is within a millisecond of when the
> attacker's own client gave up (5052.5 ms after it started, two seconds before
> the victim). The rows above avoid this by letting each peer complete one
> connection first, so the silent connection that follows is first contact on
> neither side; its client returned in 1.6 ms and 1.7 ms and held no client-side
> lock. I mention it because that contaminated pair of numbers is what the
> obvious version of this experiment produces, and read alone it says the patch
> does not work.
> 
> Not covered: real RDMA hardware, SMC-D, SMC-v1 (soft-RoCE offers only RoCEv2
> GIDs, so a v1 proposal cannot be produced on it), link groups with more than
> one link, and s390. The SMC-D path is unchanged by inspection, not by
> measurement.
> 
> The reproducer is a set of shell and C files rather than a single script. It
> is not inlined here; I will send it to whoever wants it.
> 
> No Fixes tag and net-next, deliberately: the behaviour is as old as the first
> implementation (0cfdd8f92cac, 2017) and was documented as host-wide by the
> maintainers in 8270d9c21041, and this is a change to how the handshake is
> serialized, not a backport candidate.
> 
> Per Documentation/process/security-bugs.rst, a reproducer for an AI-assisted
> finding is not posted to a public list. Mine is a few shell and C files for the
> namespace lab above; I will send them to any maintainer who asks.
> 
> One observation from reading the surrounding code that I have NOT measured and
> that this patch does not touch. On the SMC-Rv1 path, smc_llc_srv_rkey_exchange()
> re-reads num_rkeys from each ADD_LINK_CONT the peer sends and loops while it is
> non-zero, with no iteration cap; max_links is a fixed 2 on a v1 link group, so
> every v1 first contact reaches it, and before this patch that was under
> smc_server_lgr_pending. Commit 2d1e7c5aaa33 bounded the v2 twin of this loop
> this year and left the v1 one as it was; smc_llc_cli_rkey_exchange() has the
> same shape on the client side. I cannot measure it here because soft-RoCE
> offers no RoCEv1 gid, so SMC-Rv1 cannot be negotiated on this lab. I will send
> a bounded-counter patch for it separately rather than fold it in here.
> 
> checkpatch --strict reports no errors and no checks. It reports one "Unknown
> commit id" warning, for 8270d9c21041, the only commit the changelog cites; git
> was not available in the container where checkpatch ran, and the commit
> resolves with the title used here.
> 
> Tool use, as Documentation/process/generated-content.rst asks. The tool was
> Claude (Anthropic), driven interactively by me over one session. It read
> net/smc at v7.4-rc5, located the hold across the CONFIRM wait and the
> smcr_lgr_match() active-link condition behind it, proposed the per-peer key,
> and wrote the hunk in this patch, the changelog, these notes, the kernel build
> scripts and the namespace test (the guest init script and the netfilter helper
> that drops or rewrites CLC messages in flight); it also ran the two-kernel
> measurement. Four adversarial review passes by separate model instances were
> run before sending and changed the key (system id alone to system id plus the
> gids), the target tree (net to net-next) and several claims in the changelog
> that did not survive them. I reviewed the patch and the measurement and
> take responsibility for both.
> 
>  net/smc/af_smc.c | 62 ++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 55 insertions(+), 7 deletions(-)
> 
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index bfc0c7e71a12..d2858e75fc1d 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -26,6 +26,7 @@
>  #include <linux/if_vlan.h>
>  #include <linux/rcupdate_wait.h>
>  #include <linux/ctype.h>
> +#include <linux/jhash.h>
>  #include <linux/splice.h>
>  
>  #include <net/sock.h>
> @@ -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)];
> +}
> +
>  static struct workqueue_struct	*smc_tcp_ls_wq;	/* wq for tcp listen work */
>  struct workqueue_struct	*smc_hs_wq;	/* wq for handshake work */
>  struct workqueue_struct	*smc_close_wq;	/* wq for close work */
> @@ -2462,6 +2491,7 @@ static void smc_listen_work(struct work_struct *work)
>  	struct smc_clc_msg_accept_confirm *cclc;
>  	struct smc_clc_msg_proposal_area *buf;
>  	struct smc_clc_msg_proposal *pclc;
> +	struct mutex *pending_lock = NULL;
>  	struct smc_init_info *ini = NULL;
>  	u8 proposal_version = SMC_V1;
>  	u8 accept_version;
> @@ -2524,6 +2554,12 @@ static void smc_listen_work(struct work_struct *work)
>  	if (rc)
>  		goto out_decl;
>  
> +	/* The key comes from the proposal, which has already been received and
> +	 * validated, so the per-peer lock can be taken first. Lock order is
> +	 * always per-peer lock before smc_server_lgr_pending.
> +	 */
> +	pending_lock = smc_server_peer_pending_lock(pclc);
> +	mutex_lock(pending_lock);
>  	mutex_lock(&smc_server_lgr_pending);
>  	smc_rx_init(new_smc);
>  	smc_tx_init(new_smc);
> @@ -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);
>  
> -	/* 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);
>  
>  	/* receive SMC Confirm CLC message */
>  	memset(buf, 0, sizeof(*buf));
> @@ -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);
>  	}
>  	smc_conn_save_peer_info(new_smc, cclc);
>  
> @@ -2589,8 +2632,10 @@ static void smc_listen_work(struct work_struct *work)
>  	smc_listen_out_connected(new_smc);
>  	goto out_free;
>  
> -out_unlock:
> +out_unlock_global:
>  	mutex_unlock(&smc_server_lgr_pending);
> +out_unlock:
> +	mutex_unlock(pending_lock);
>  out_decl:
>  	smc_listen_decline(new_smc, rc, ini ? ini->first_contact_local : 0,
>  			   proposal_version);
> @@ -3463,7 +3508,10 @@ static struct pernet_operations smc_net_stat_ops = {
>  
>  static int __init smc_init(void)
>  {
> -	int rc;
> +	int i, rc;
> +
> +	for (i = 0; i < SMC_SERVER_PEER_PENDING_SIZE; i++)
> +		mutex_init(&smc_server_peer_pending[i]);
>  
>  	rc = register_pernet_subsys(&smc_net_ops);
>  	if (rc)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
  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
  2026-12-03 13:31 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-03 13:13 UTC (permalink / raw)
  To: Ermenson Junior
  Cc: linux-rdma, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
  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
@ 2026-12-03 13:31 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 13:31 UTC (permalink / raw)
  To: ermenson.sec
  Cc: alibuda, dust.li, sidraya, mjambigi, tonylu, guwen, davem,
	edumazet, kuba, pabeni, willemb, horms, netdev, linux-rdma,
	linux-s390

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally
  2026-12-03  8:35 ` Mahanta Jambigi
@ 2026-12-03 15:46   ` Ermenson Junior
  0 siblings, 0 replies; 5+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:46 UTC (permalink / raw)
  To: mjambigi, alibuda, dust.li, sidraya
  Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
	netdev, linux-rdma, linux-s390

Hi Mahanta,

A duplicate link group is harmless for correctness and not free in
resources, so I took your preferred route. v2 drops the hash.

Correctness: the ACCEPT carries ini->first_contact_local, and the client
side of smc_conn_create() then takes its "create new link group as well"
path, so both ends stay symmetric and no decline is sent. The
SMC_CLC_DECL_SYNCERR case below it is the mirror, server reuses and client
wanted new. Several groups per peer is already reachable too, since for
SMC_SERV the reuse condition refuses a group at max_conns or with a full
rtoken bitmap. And smcr_lgr_match() already compares the link's peer_gid,
so a peer varying its GID gets a fresh group with or without my patch.

Resources: lgr_cnt is a counter and not a cap, and an idle server side
group is held SMC_LGR_FREE_DELAY_SERV, 600 seconds, before
smc_lgr_free_work reclaims it. A multi-port peer falling back to v1 pays
double for ten minutes of idleness. Small, not nothing, and a behaviour
change nobody asked for.

The Sashiko bot's finding on this thread is also correct, and v2 removes the
function it was about. For the archive: smcr_indicated() is true for
SMC_TYPE_R, which is 0, so it is true for the reserved zero typev2 of a v1
proposal, and smc_get_clc_msg_smcd() then returns prop + 1 unchecked
because its guard only fires for smcd_indicated(typev1). The key mixed in
IP prefix bytes. It is a wrong-field read and not out of bounds, since
max_offset is computed inside struct smc_clc_msg_proposal_area.

v2 makes a link group that is still establishing findable, so a second
connection of the same peer defers to it, and the mutex no longer spans the
CONFIRM wait. It still covers smc_lgr_create(), which is needed: until the
list_add_tail() there the group is not on smc_lgr_list. Deferrals are
bounded by a window of two CLC_WAIT_TIME, which is wider than the longest a
link stays in SMC_LNK_ACTIVATING, so the create-anyway fallback is not
reachable at today's constants. One second of margin.

One thing v2 does not fix, since I claimed otherwise in v1: after the retry
joins, smcr_lgr_reg_rmbs() runs under the mutex and starts with
smc_llc_flow_initiate(), which sleeps while the first peer's ADD_LINK flow
is active. Unchanged by this series.

It grew to four patches. Taking the whole of smc_listen_rdma_finish() out
from under the mutex lets a joining connection of this peer block on
rmbs_lock or llc_conf_mutex with no timeout while holding it, waiting on
the first contact's add-link flow. The Sashiko bot raised that loop on v1
as pre-existing and it is unbounded, so patches 1 and 2 bound it and come
first. Patch 3 fills the peer gid and mac at creation, which patch 4 needs.

Unrelated peer's connect during a silent peer's handshake went 4397.8 ms to
1.5 ms. Your v1 control does not work here and the series notes say why.

v2: <20261203153514.1440337-1-ermenson.sec@gmail.com>

Thanks for the review.

Ermenson

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox