* [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake
@ 2026-12-03 15:35 Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Ermenson Junior
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:35 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
netdev, linux-rdma, linux-s390
v1: https://lore.kernel.org/netdev/20261202131243.664308-1-ermenson.sec@gmail.com/
v1 serialized per peer with a mutex hashed on proposal fields. Mahanta
asked what a duplicate link group costs and said he would rather see the
exact fix. The Sashiko bot found the hash reading the IP prefix area as
a gid for an SMCv1 proposal. v2 drops the hash and takes the exact
route.
To answer the question in the archive: a duplicate link group is
harmless for correctness, because the ACCEPT carries first_contact_local
and the client creates a matching group, and because a group at
max_conns already makes the server create siblings today. It is not free
in resources: lgr_cnt is a counter and not a cap, and an idle server
group is held SMC_LGR_FREE_DELAY_SERV, 600 seconds.
The series grew to four patches because of the bot's other point. Patch
4 takes the whole of smc_listen_rdma_finish() out from under the global
mutex, including the first-contact ADD_LINK phase, and a joining
connection of the same peer can then block on rmbs_lock or
llc_conf_mutex with no timeout while holding that mutex. Patches 1 and 2
bound the flow it would be waiting on, so they come first. Patch 3 fills
a new link's peer gid and mac at creation, which patch 4 needs because
the new match compares them before the CONFIRM arrives.
Patches 1 and 2 stand alone and fix the High issue the bot raised on v1
as pre-existing.
Ermenson Junior (4):
net/smc: bound the SMC-Rv1 add-link rkey exchange
net/smc: check the ADD_LINK_CONT send result in the server rkey
exchange
net/smc: set a new link's peer gid and mac at creation
net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait
net/smc/af_smc.c | 46 ++++++++---
net/smc/smc_core.c | 191 +++++++++++++++++++++++++++++++++++++++++++++
net/smc/smc_core.h | 21 +++++
net/smc/smc_llc.c | 58 ++++++++++++--
net/smc/smc_llc.h | 7 ++
5 files changed, 304 insertions(+), 19 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange
2026-12-03 15:35 [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake Ermenson Junior
@ 2026-12-03 15:35 ` Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server " Ermenson Junior
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:35 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
netdev, linux-rdma, linux-s390
smc_llc_srv_rkey_exchange() and smc_llc_cli_rkey_exchange() drive the
SMC-Rv1 ADD_LINK_CONT exchange with a loop whose termination condition
is re-read from the peer on every round:
do {
...
qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME,
SMC_LLC_ADD_LINK_CONT);
...
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++) {
smc_rtoken_set(...);
num_rkeys_recv--;
}
...
} while (num_rkeys_send || num_rkeys_recv);
num_rkeys_recv is taken from each ADD_LINK_CONT message the peer sends
and is decremented by at most SMC_LLC_RKEYS_PER_CONT_MSG, which is 2. A
peer that answers num_rkeys=255 every time leaves it at 253 at the
bottom of every round, so the condition never goes false.
num_rkeys_send does not help: it reaches zero on its own, after which
the local side keeps emitting ADD_LINK_CONT messages with num_rkeys=0
while the peer's half of the condition holds the loop open. There is no
iteration count, no deadline and no total work budget, so the peer
decides both how many rounds the exchange takes and, by replying just
inside SMC_LLC_WAIT_TIME, how long each round lasts.
Both loops run with a module-global mutex held. On the server,
smc_llc_srv_rkey_exchange() is reached from smc_listen_work() through
smc_listen_rdma_finish() and smcr_serv_conf_first_link(), between
mutex_lock(&smc_server_lgr_pending) and its matching unlock, so every
incoming SMC connection on the host waits behind it. On the client,
smcr_clnt_conf_first_link() is called from smc_connect_rdma() inside
the smc_client_lgr_pending region, so a hostile server stalls every
outgoing SMC connection on the host. lgr->rmbs_lock and
lgr->llc_conf_mutex are held across the loop as well.
Bound the exchange in both directions. An ADD_LINK_CONT message carries
at most SMC_LLC_RKEYS_PER_CONT_MSG rkeys and a link group holds at most
SMC_RMBS_PER_LGR_MAX of them, so a peer that keeps to the protocol
never needs more than DIV_ROUND_UP(SMC_RMBS_PER_LGR_MAX,
SMC_LLC_RKEYS_PER_CONT_MSG) messages, which is 128, and anything beyond
that is a protocol error. Cap the rounds at that derived limit and give
the exchange as a whole a deadline: the round cap on its own would
still allow 128 * SMC_LLC_WAIT_TIME of held mutex, and a deadline on
its own would still allow an unbounded number of instant rounds under
it. Neither check rejects a message a conforming peer can send.
SMC_LLC_RKEY_EXCHG_TIME is ten times the existing per-message timeout.
The exchange is reactive on a QP that is already up, so this is
generous; the value is a policy choice and easy to change if a
different one is preferred.
Aborting the exchange costs only the optional second link. No caller
propagates the result: smcr_clnt_conf_first_link() and
smcr_serv_conf_first_link() ignore it, smc_llc_process_cli_add_link()
ignores it, smc_llc_process_srv_add_link() uses it only to decide
whether to drop an asymmetric link, and smc_llc_cli_add_link() already
maps an rkey-exchange failure to rc = 0. A link group that hits either
limit keeps running on its first link instead of failing the
connection.
The SMC-Rv2 counterparts of this same trust in a peer-supplied count
were bounded in commit 2d1e7c5aaa33 ("net/smc: bound the peer rkey
counts in SMC-Rv2 LLC messages"). The v1 loops were left as they were;
this is the same field on the other side of the version test in
smc_llc_srv_add_link().
Not reproduced dynamically, and I want to be explicit about that. The
loop is on the SMC-Rv1 path, which needs a GID of type
IB_GID_TYPE_ROCE (smc_ib_determine_gid_rcu()); the soft-RoCE driver
publishes only IB_GID_TYPE_ROCE_UDP_ENCAP, so SMC-Rv1 cannot be
negotiated on an rxe setup, and I have no RoCEv1 hardware to test on.
The reasoning above is from source reading and the patch is
compile-tested only.
This patch was written with the help of an AI coding assistant (Claude).
Fixes: 87f88cda2128 ("net/smc: rkey processing for a new link as SMC
client")
Fixes: 57b499242cb8 ("net/smc: rkey processing for a new link as SMC
server")
Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
---
net/smc/smc_llc.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
net/smc/smc_llc.h | 7 +++++++
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index c9ccd8480369..818dd84e720f 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -111,6 +111,13 @@ struct smc_llc_msg_req_add_link_v2 {
#define SMC_LLC_RKEYS_PER_CONT_MSG 2
+/* An ADD_LINK_CONT message carries at most SMC_LLC_RKEYS_PER_CONT_MSG rkeys and
+ * a link group holds at most SMC_RMBS_PER_LGR_MAX of them, so a peer that keeps
+ * to the protocol never needs more messages than this to finish the exchange.
+ */
+#define SMC_LLC_RKEY_CONT_MSG_MAX \
+ DIV_ROUND_UP(SMC_RMBS_PER_LGR_MAX, SMC_LLC_RKEYS_PER_CONT_MSG)
+
struct smc_llc_msg_add_link_cont { /* type 0x03 */
struct smc_llc_hdr hd;
u8 link_num;
@@ -914,6 +921,8 @@ static int smc_llc_cli_rkey_exchange(struct smc_link *link,
u8 max, num_rkeys_send, num_rkeys_recv;
struct smc_llc_qentry *qentry;
struct smc_buf_desc *buf_pos;
+ unsigned long expire;
+ int rounds = 0;
int buf_lst;
int rc = 0;
int i;
@@ -921,9 +930,23 @@ static int smc_llc_cli_rkey_exchange(struct smc_link *link,
down_write(&lgr->rmbs_lock);
num_rkeys_send = lgr->conns_num;
buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
+ expire = jiffies + SMC_LLC_RKEY_EXCHG_TIME;
do {
- qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_TIME,
- SMC_LLC_ADD_LINK_CONT);
+ long timeo;
+
+ if (rounds++ >= SMC_LLC_RKEY_CONT_MSG_MAX) {
+ rc = -EPROTO;
+ break;
+ }
+ timeo = (long)(expire - jiffies);
+ if (timeo <= 0) {
+ rc = -ETIMEDOUT;
+ break;
+ }
+ if (timeo > SMC_LLC_WAIT_TIME)
+ timeo = SMC_LLC_WAIT_TIME;
+
+ qentry = smc_llc_wait(lgr, NULL, timeo, SMC_LLC_ADD_LINK_CONT);
if (!qentry) {
rc = -ETIMEDOUT;
break;
@@ -1352,6 +1375,8 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link,
u8 max, num_rkeys_send, num_rkeys_recv;
struct smc_llc_qentry *qentry = NULL;
struct smc_buf_desc *buf_pos;
+ unsigned long expire;
+ int rounds = 0;
int buf_lst;
int rc = 0;
int i;
@@ -1359,11 +1384,25 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link,
down_write(&lgr->rmbs_lock);
num_rkeys_send = lgr->conns_num;
buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
+ expire = jiffies + SMC_LLC_RKEY_EXCHG_TIME;
do {
+ long timeo;
+
+ if (rounds++ >= SMC_LLC_RKEY_CONT_MSG_MAX) {
+ rc = -EPROTO;
+ goto out;
+ }
+ timeo = (long)(expire - jiffies);
+ if (timeo <= 0) {
+ rc = -ETIMEDOUT;
+ goto out;
+ }
+ if (timeo > SMC_LLC_WAIT_TIME)
+ timeo = SMC_LLC_WAIT_TIME;
+
smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
&buf_lst, &buf_pos);
- qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME,
- SMC_LLC_ADD_LINK_CONT);
+ qentry = smc_llc_wait(lgr, link, timeo, SMC_LLC_ADD_LINK_CONT);
if (!qentry) {
rc = -ETIMEDOUT;
goto out;
diff --git a/net/smc/smc_llc.h b/net/smc/smc_llc.h
index 7e7a3162c68b..0a1c6c141a57 100644
--- a/net/smc/smc_llc.h
+++ b/net/smc/smc_llc.h
@@ -21,6 +21,13 @@
#define SMC_LLC_WAIT_TIME (2 * HZ)
#define SMC_LLC_TESTLINK_DEFAULT_TIME (30 * HZ)
+/* Total time budget for the rkey exchange of one SMC-Rv1 add-link flow, across
+ * all ADD_LINK_CONT messages. The peer decides how many messages the exchange
+ * takes, so the exchange as a whole needs a deadline and not only a per-message
+ * timeout.
+ */
+#define SMC_LLC_RKEY_EXCHG_TIME (SMC_LLC_WAIT_TIME * 10)
+
enum smc_llc_reqresp {
SMC_LLC_REQ,
SMC_LLC_RESP
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server rkey exchange
2026-12-03 15:35 [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Ermenson Junior
@ 2026-12-03 15:35 ` Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait Ermenson Junior
3 siblings, 1 reply; 9+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:35 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
netdev, linux-rdma, linux-s390
smc_llc_cli_rkey_exchange() checks what smc_llc_add_link_cont() returns
and leaves the loop when the send fails:
rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
&buf_lst, &buf_pos);
if (rc)
break;
smc_llc_srv_rkey_exchange() discards it and goes on to wait for a reply
to a message that was never transmitted, so the round can only end in
the wait timing out. Make the server side behave like the client side.
This is independent of the bounding in the previous patch and can be
dropped or deferred without affecting it.
This patch was written with the help of an AI coding assistant (Claude).
Fixes: 57b499242cb8 ("net/smc: rkey processing for a new link as SMC
server")
Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
---
net/smc/smc_llc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index 818dd84e720f..e41011d19b73 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -1400,8 +1400,10 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link,
if (timeo > SMC_LLC_WAIT_TIME)
timeo = SMC_LLC_WAIT_TIME;
- smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
- &buf_lst, &buf_pos);
+ rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
+ &buf_lst, &buf_pos);
+ if (rc)
+ goto out;
qentry = smc_llc_wait(lgr, link, timeo, SMC_LLC_ADD_LINK_CONT);
if (!qentry) {
rc = -ETIMEDOUT;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation
2026-12-03 15:35 [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server " Ermenson Junior
@ 2026-12-03 15:35 ` Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait Ermenson Junior
3 siblings, 1 reply; 9+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:35 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
netdev, linux-rdma, linux-s390
smcr_link_init() leaves lnk->peer_gid and lnk->peer_mac zero. They are
filled only once the peer's CLC accept or confirm has been processed, by
smc_link_save_peer_info(), which copies them out of smc_init_info. Both
values are already in smc_init_info when the link is created, so set them
there. This changes when the fields become valid, not what they hold.
peer_qpn, peer_psn and peer_mtu come from the CLC message and stay where
they are.
The add-link paths pass a zeroed smc_init_info, so the new link gets zeros
as before, and smc_llc_save_add_link_info() fills both from the ADD_LINK
message straight after.
No reader changes behaviour: the QP is programmed from the gid only after
the peer info is saved, smcr_lgr_match() looks at active links, and the
netlink and diag paths display the field.
Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
---
net/smc/smc_core.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index a3164201c142..d265e83f1845 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -824,6 +824,15 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
lnk->wr_rx_sge_cnt = 1;
lnk->wr_rx_buflen = SMC_WR_BUF_SIZE;
}
+ /* peer_qpn, peer_psn and peer_mtu come from the peer's CLC CONFIRM and
+ * are filled later by smc_link_save_peer_info(). The gid and the mac are
+ * already in ini here, and smc_link_save_peer_info() copies them from the
+ * same fields, so this changes when they become valid and not what they
+ * hold. The add-link callers pass a zeroed ini and overwrite both in
+ * smc_llc_save_add_link_info() straight after.
+ */
+ memcpy(lnk->peer_gid, ini->peer_gid, SMC_GID_SIZE);
+ memcpy(lnk->peer_mac, ini->peer_mac, sizeof(lnk->peer_mac));
get_device(&lnk->smcibdev->ibdev->dev);
atomic_inc(&lnk->smcibdev->lnk_cnt);
refcount_set(&lnk->refcnt, 1); /* link refcnt is set to 1 */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait
2026-12-03 15:35 [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake Ermenson Junior
` (2 preceding siblings ...)
2026-12-03 15:35 ` [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation Ermenson Junior
@ 2026-12-03 15:35 ` Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
3 siblings, 1 reply; 9+ messages in thread
From: Ermenson Junior @ 2026-12-03 15:35 UTC (permalink / raw)
To: alibuda, dust.li, sidraya, mjambigi
Cc: tonylu, guwen, davem, edumazet, kuba, pabeni, willemb, horms,
netdev, linux-rdma, linux-s390
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 goes silent holds the mutex for six seconds, and every other
server-side handshake on the host queues behind it. A lossy path does this
by accident. Commit 8270d9c21041 ("net/smc: Limit backlog connections")
already describes the lock as host wide.
Releasing it earlier was not possible: 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.
Make that link group findable instead. smcr_lgr_pending_match() matches a
link group with no active link whose link is still SMC_LNK_ACTIVATING,
comparing what smcr_lgr_match() compares. A connection that finds one
defers: smc_conn_create() returns with ini->pending_lgr holding a
reference, smc_listen_work() drops the mutex, waits, and looks again.
Waiters are woken where a link leaves SMC_LNK_ACTIVATING, in
smc_llc_link_active() and smcr_link_clear().
The mutex still covers smc_lgr_create(), which is load bearing: until the
list_add_tail() there the new link group is not on smc_lgr_list, so a
second connection in that window would find nothing to defer to.
What moves out from under the mutex is all of smc_listen_rdma_finish(),
not only the CONFIRM receive: smc_link_save_peer_info(),
smc_rmb_rtoken_handling(), smc_ib_ready_link() and
smcr_serv_conf_first_link(), which includes the LLC CONFIRM_LINK wait and,
for max_links > 1, the first-contact ADD_LINK phase. smc_llc_link_active()
runs before that phase, so once it has run a second connection of the peer
matches the link group normally and no longer defers. It can then block in
smc_buf_get_slot() on rmbs_lock or in smcr_buf_map_usable_links() on
llc_conf_mutex while holding smc_server_lgr_pending, waiting on the
first-contact worker's add-link flow. Those two waits have no timeout, so
this is only acceptable because the flow they wait on is bounded, which is
what the first two patches of this series do.
Deferrals repeat only inside a window of two CLC_WAIT_TIME opened by the
first, with each wait clipped to what remains, so a peer cannot park a
listen worker for longer than that window. Past it the worker creates a
link group as before. The window is wider than the longest a link can stay
in SMC_LNK_ACTIVATING, CLC_WAIT_TIME + SMC_LLC_WAIT_FIRST_TIME, so today
that fallback is not reachable. The margin is one second and depends on
those two constants.
Tested on v7.4-rc5, two kernels differing only by this series with
identical configs, soft-RoCE, peers in separate netns. An unrelated peer's
connect() during a silent peer's handshake: 4397.8 ms to 1.5 ms. In the
patched kernel a second connection of the same peer during a first contact
still waits 689.3 ms, which is what makes the first number attributable.
No lockdep report with PROVE_LOCKING and DEBUG_ATOMIC_SLEEP on.
Found and written with Claude (Anthropic), used interactively, reviewed and
tested by the author. Documentation/process/generated-content.rst asks for
this to be stated.
Signed-off-by: Ermenson Junior <ermenson.sec@gmail.com>
---
Notes for reviewers.
Lab: two kernels from v7.4-rc5 built by one script, empty .config diff
between them. defconfig + kvm_guest.config, SMC/SMC_DIAG/DIBS/RDMA_RXE in,
DIBS_LO off, PROVE_LOCKING + DEBUG_ATOMIC_SLEEP + DETECT_HUNG_TASK on, zero
build warnings. Peers in separate netns with an rxe device each. The silent
peer is its CLC CONFIRM dropped by NFQUEUE while it holds the socket open.
unpatched patched
sanity, no silent peer 1.7 ms 0.7 ms
silent peer, unrelated victim 4397.8 ms 1.5 ms
after drain 1.0 ms 0.8 ms
v1's control does not work here. Its same-peer connection is not a first
contact, so v2 neither defers nor takes the mutex and it returns in 0.6 ms
against 4163.4 ms unpatched. The control that does discriminate is a second
connection of the same peer during a first contact: 689.3 ms in the same
patched kernel where the unrelated peer saw 1.5 ms.
Link group ids, from SMC_NETLINK_GET_LGR_SMCR (ss --smc does not carry the
id). Both kernels, same result: first contact succeeds, one group with two
connections. First contact never completes, group torn down and a new one
built, one live at a time. Three connections of one peer, one group with
three connections.
Patch 1 is confirmed by that dumper: the ACTIVATING server link shows the
real peer gid with it and zeros without it, and without it the new match
never fires in the window this series opens.
Not measured. No tracepoint on the deferral path, so the single-group
results are consistent with it working and do not prove it ran. The
window-exceeded case is untested: I tried to stall ADD_LINK by dropping
RoCE
traffic and lost the race by 6 ms, so those phases are inconclusive, not
clean. One run per phase. Not covered: real hardware, SMC-D, SMC-Rv1
(soft-RoCE has only RoCEv2 gids), multi-link groups, s390.
A poweroff hung-task in smc_cdc_wait_pend_tx_wr appears on both kernels
with
an identical stack after the scenario ends. Not this series.
Per security-bugs.rst a reproducer for an AI-assisted finding is not posted
publicly. Mine is a few shell and C files including the netlink dumper, and
I will send them to any maintainer who asks.
net-next and no Fixes tag: the hold dates from 0cfdd8f92cac (2017) and was
documented as host wide in 8270d9c21041, so this changes how the handshake
is serialized rather than fixing a regression.
Tool use. Claude (Anthropic), driven interactively. It read net/smc, found
the hold and the active-link condition behind it, proposed the pending
match, and wrote the hunks, the lab and the measurement. Three independent
review passes ran before sending: the first found the new match comparing a
gid that is zero until after the CONFIRM, which patch 1 fixes, the second
found the wrong saved version restored on retry and that ini->ib_dev is
never cleared, the third cleared it.
net/smc/af_smc.c | 46 +++++++----
net/smc/smc_core.c | 190 ++++++++++++++++++++++++++++++++++++++++++++-
net/smc/smc_core.h | 21 +++++
net/smc/smc_llc.c | 5 ++
4 files changed, 245 insertions(+), 17 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a12..fb815b141ddd 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2415,6 +2415,14 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
smc_find_rdma_v2_device_serv(new_smc, pclc, ini);
if (ini->smcrv2.ib_dev_v2)
return 0;
+ /* A first contact of this peer is still establishing. Return now:
+ * trying V1 below would call smc_conn_create() a second time, and with
+ * the deferral already spent it would create a link group and leave
+ * this connection registered on it while the caller still waits and
+ * retries.
+ */
+ if (ini->pending_lgr)
+ return ini->rc;
/* check if RDMA V1 is available */
if (!prfx_rc) {
@@ -2524,12 +2532,27 @@ static void smc_listen_work(struct work_struct *work)
if (rc)
goto out_decl;
+ /* smc_find_rdma_v2_device_serv() rewrites ini->smcr_version on both its
+ * paths, so a retry has to start from the value negotiated above
+ */
+ ini->pending_smcr_version = ini->smcr_version;
+
+again:
mutex_lock(&smc_server_lgr_pending);
smc_rx_init(new_smc);
smc_tx_init(new_smc);
/* determine ISM or RoCE device used for connection */
rc = smc_listen_find_device(new_smc, pclc, ini);
+ if (ini->pending_lgr) {
+ /* a first contact of this peer is still establishing, so this
+ * connection must not create a second link group for it. Wait
+ * for that one with no lock held and look again.
+ */
+ mutex_unlock(&smc_server_lgr_pending);
+ smcr_wait_pending_lgr(ini);
+ goto again;
+ }
if (rc)
goto out_unlock;
@@ -2540,27 +2563,25 @@ static void smc_listen_work(struct work_struct *work)
if (rc)
goto out_unlock;
- /* SMC-D does not need this lock any more */
- if (ini->is_smcd)
- mutex_unlock(&smc_server_lgr_pending);
+ /* Link group creation is complete, so this lock is not needed across
+ * the peer-paced wait for the CLC CONFIRM below. A further connection
+ * of this peer now finds the link group through
+ * smcr_lgr_pending_match() and waits for it, which is what holding
+ * this mutex until the first link became active used to achieve.
+ */
+ mutex_unlock(&smc_server_lgr_pending);
/* receive SMC Confirm CLC message */
memset(buf, 0, sizeof(*buf));
cclc = (struct smc_clc_msg_accept_confirm *)buf;
rc = smc_clc_wait_msg(new_smc, cclc, sizeof(*buf),
SMC_CLC_CONFIRM, CLC_WAIT_TIME);
- if (rc) {
- if (!ini->is_smcd)
- goto out_unlock;
+ if (rc)
goto out_decl;
- }
rc = smc_clc_v2x_features_confirm_check(cclc, ini);
- if (rc) {
- if (!ini->is_smcd)
- goto out_unlock;
+ if (rc)
goto out_decl;
- }
/* fce smc release version is needed in smc_listen_rdma_finish,
* so save fce info here.
@@ -2572,8 +2593,7 @@ static void smc_listen_work(struct work_struct *work)
rc = smc_listen_rdma_finish(new_smc, cclc,
ini->first_contact_local, ini);
if (rc)
- goto out_unlock;
- mutex_unlock(&smc_server_lgr_pending);
+ goto out_decl;
}
smc_conn_save_peer_info(new_smc, cclc);
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index d265e83f1845..60e97155fa52 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -826,10 +826,11 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
}
/* peer_qpn, peer_psn and peer_mtu come from the peer's CLC CONFIRM and
* are filled later by smc_link_save_peer_info(). The gid and the mac are
- * already in ini here, and smc_link_save_peer_info() copies them from the
- * same fields, so this changes when they become valid and not what they
- * hold. The add-link callers pass a zeroed ini and overwrite both in
- * smc_llc_save_add_link_info() straight after.
+ * already known here, from the proposal on the server and from the
+ * accept on the client, and smc_link_save_peer_info() copies them from
+ * the same ini fields, so setting them now changes when they become
+ * valid and not what they become. The add-link callers pass a zeroed
+ * ini and overwrite both in smc_llc_save_add_link_info() afterwards.
*/
memcpy(lnk->peer_gid, ini->peer_gid, SMC_GID_SIZE);
memcpy(lnk->peer_mac, ini->peer_mac, sizeof(lnk->peer_mac));
@@ -1393,6 +1394,10 @@ static void __smcr_link_clear(struct smc_link *lnk)
lnk->state = SMC_LNK_UNUSED;
if (!atomic_dec_return(&smcibdev->lnk_cnt))
wake_up(&smcibdev->lnks_deleted);
+ /* a listen worker may be deferring to this link group, see
+ * smcr_wait_pending_lgr()
+ */
+ wake_up_all(&lgr->first_contact_waiter);
smc_lgr_put(lgr); /* lgr_hold in smcr_link_init() */
}
@@ -2007,6 +2012,153 @@ static bool smcr_lgr_match(struct smc_link_group *lgr, u8 smcr_version,
return false;
}
+/* Like smcr_lgr_match(), but for a link group whose first link has not become
+ * active yet. Such a link group is invisible to smcr_lgr_match(), which skips
+ * inactive links, so without this a second connection of the same peer creates
+ * a duplicate link group. The fields compared are the ones smcr_lgr_match()
+ * compares, taken from the link that is being activated. The peer_qpn
+ * clause of smcr_lgr_match() is absent because it only applies when the
+ * role is not SMC_SERV, and this only matches server side link groups.
+ */
+static bool smcr_lgr_pending_match(struct smc_link_group *lgr,
+ struct smc_init_info *ini, struct net *net)
+{
+ struct smc_link *lnk;
+ int i;
+
+ if (lgr->is_smcd || lgr->role != SMC_SERV ||
+ lgr->sync_err || lgr->terminating || lgr->freeing)
+ return false;
+ if (memcmp(lgr->peer_systemid, ini->peer_systemid, SMC_SYSTEMID_LEN))
+ return false;
+ /* the same clause the join loop in smc_conn_create() applies */
+ if (ini->smcd_version != SMC_V2 && lgr->vlan_id != ini->vlan_id)
+ return false;
+
+ /* Only a first contact is deferred to. A link group that is adding a
+ * further link also has a link in SMC_LNK_ACTIVATING, and a peer that
+ * has filled that group would then be delayed before creating the new
+ * group it needs.
+ */
+ for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++)
+ if (smc_link_active(&lgr->lnk[i]))
+ return false;
+
+ for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
+ lnk = &lgr->lnk[i];
+
+ if (lnk->state != SMC_LNK_ACTIVATING)
+ continue;
+ if (!rdma_dev_access_netns(lnk->smcibdev->ibdev, net))
+ return false;
+ if (!memcmp(lnk->peer_gid, ini->peer_gid, SMC_GID_SIZE) &&
+ (ini->smcr_version == SMC_V2 ||
+ !memcmp(lnk->peer_mac, ini->peer_mac, ETH_ALEN)))
+ return true;
+ }
+ return false;
+}
+
+/* True while a link group still has a link being activated and has not failed.
+ * Every outcome of a first contact leaves SMC_LNK_ACTIVATING: success through
+ * smc_llc_link_active(), failure through smcr_link_clear().
+ */
+static bool smcr_lgr_activating(struct smc_link_group *lgr)
+{
+ int i;
+
+ /* lnk[] is in the SMC-R arm of the link group union, so check the
+ * variant here rather than trusting the caller
+ */
+ if (lgr->is_smcd)
+ return false;
+ if (READ_ONCE(lgr->sync_err) || READ_ONCE(lgr->terminating) ||
+ READ_ONCE(lgr->freeing))
+ return false;
+ for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++)
+ if (READ_ONCE(lgr->lnk[i].state) == SMC_LNK_ACTIVATING)
+ return true;
+ return false;
+}
+
+/* A deferral parks this listen worker, so repeated deferrals need a bound.
+ * The window opens at the first deferral, not at the first call, and it is
+ * two CLC_WAIT_TIME wide so that it covers a first contact failing on its own
+ * CONFIRM timeout: without that room the second connection's wait always ends
+ * past the deadline and a third connection could still create the duplicate
+ * this is here to prevent. Past the window the worker creates a link group as
+ * it did before this patch.
+ */
+#define SMC_LGR_PENDING_WINDOW (2 * CLC_WAIT_TIME)
+
+static bool smcr_may_defer(struct smc_init_info *ini)
+{
+ return !ini->pending_armed ||
+ time_before(jiffies, ini->pending_deadline);
+}
+
+/* Find a link group of this peer whose first link is still being activated,
+ * and return it with a reference held, or NULL.
+ */
+static struct smc_link_group *smcr_lgr_find_pending(struct smc_init_info *ini,
+ struct net *net)
+{
+ struct smc_link_group *lgr, *found = NULL;
+
+ spin_lock_bh(&smc_lgr_list.lock);
+ list_for_each_entry(lgr, &smc_lgr_list.list, list) {
+ if (smcr_lgr_pending_match(lgr, ini, net)) {
+ smc_lgr_hold(lgr);
+ found = lgr;
+ break;
+ }
+ }
+ spin_unlock_bh(&smc_lgr_list.lock);
+ return found;
+}
+
+/* Wait for the link group that smc_conn_create() deferred to, then drop its
+ * reference. The caller must hold neither a link group lock nor
+ * smc_server_lgr_pending, so that the first contact being waited for can make
+ * progress. A timeout is not an error: the caller retries, and once the retry
+ * budget in smc_conn_create() is spent it creates a link group as before.
+ */
+void smcr_wait_pending_lgr(struct smc_init_info *ini)
+{
+ struct smc_link_group *lgr = ini->pending_lgr;
+ unsigned long left;
+
+ ini->pending_lgr = NULL;
+ /* smc_init_info_store_rc() keeps the first value stored, so the
+ * deferral's own rc has to go or it would mask the retry's. A decline
+ * reason an earlier ISM attempt stored is dropped with it, and the
+ * retry derives its own.
+ */
+ ini->rc = 0;
+ if (!lgr)
+ return;
+ /* smc_find_rdma_v2_device_serv() leaves ini->smcr_version rewritten,
+ * and nothing in net/smc ever clears ini->ib_dev, so a device that went
+ * away during the sleep would still pass the !ini->ib_dev test in
+ * smc_find_rdma_device(). Put both back to the state the first pass
+ * started from.
+ */
+ ini->smcr_version = ini->pending_smcr_version;
+ ini->ib_dev = NULL;
+ ini->ib_port = 0;
+ memset(ini->ib_gid, 0, sizeof(ini->ib_gid));
+
+ /* clipped to the window, so several deferrals cannot add up to more
+ * parked time than one deferral is allowed
+ */
+ left = ini->pending_deadline - jiffies;
+ if ((long)left > 0)
+ wait_event_timeout(lgr->first_contact_waiter,
+ !smcr_lgr_activating(lgr),
+ min_t(unsigned long, left, CLC_WAIT_TIME));
+ smc_lgr_put(lgr);
+}
+
static bool smcd_lgr_match(struct smc_link_group *lgr,
struct smcd_dev *smcismdev,
struct smcd_gid *peer_gid)
@@ -2084,6 +2236,36 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
return SMC_CLC_DECL_SYNCERR;
}
+ /* A first contact of this peer may still be establishing. Its link is
+ * not active yet, so the loop above cannot see its link group and
+ * would create a duplicate. Defer to it instead; the caller waits
+ * without holding smc_server_lgr_pending and retries.
+ */
+ if (role == SMC_SERV && !ini->is_smcd && ini->first_contact_local &&
+ smcr_may_defer(ini)) {
+ struct smc_link_group *pending;
+
+ pending = smcr_lgr_find_pending(ini, net);
+ if (pending) {
+ if (!ini->pending_armed) {
+ ini->pending_armed = 1;
+ ini->pending_deadline = jiffies +
+ SMC_LGR_PENDING_WINDOW;
+ }
+ ini->pending_lgr = pending;
+ /* ini->pending_lgr is the signal the listen worker
+ * acts on. The return value only has to be non-zero,
+ * and it must stay a valid CLC decline reason:
+ * smc_init_info_store_rc() takes a u32 and keeps the
+ * first value stored, and smc_listen_find_device() can
+ * return ini->rc for smc_listen_decline() to put on
+ * the wire. smcr_wait_pending_lgr() clears ini->rc
+ * before the retry, so this is never sent today.
+ */
+ return SMC_CLC_DECL_INTERR;
+ }
+ }
+
create:
if (ini->first_contact_local) {
rc = smc_lgr_create(smc, ini);
diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h
index bff4c9e17792..2dd9be7ef4f6 100644
--- a/net/smc/smc_core.h
+++ b/net/smc/smc_core.h
@@ -349,6 +349,10 @@ struct smc_link_group {
/* w4 next llc event */
wait_queue_head_t llc_msg_waiter;
/* w4 next llc msg */
+ wait_queue_head_t first_contact_waiter;
+ /* w4 1st link to leave
+ * SMC_LNK_ACTIVATING
+ */
struct smc_llc_flow llc_flow_lcl;
/* llc local control field */
struct smc_llc_flow llc_flow_rmt;
@@ -442,6 +446,22 @@ struct smc_init_info {
u8 ib_port;
u32 ib_clcqpn;
struct smc_init_info_smcrv2 smcrv2;
+ u8 pending_armed;
+ /* a deferral has happened and
+ * pending_deadline is set
+ */
+ u8 pending_smcr_version;
+ /* smcr_version before the first deferral */
+ unsigned long pending_deadline;
+ /* end of the window in which further
+ * deferrals are allowed, see
+ * smcr_may_defer()
+ */
+ struct smc_link_group *pending_lgr;
+ /* a first contact for this peer is still
+ * establishing; reference held, see
+ * smcr_wait_pending_lgr()
+ */
/* SMC-D */
struct smcd_gid ism_peer_gid[SMC_MAX_V2_ISM_DEVS + 1];
struct smcd_dev *ism_dev[SMC_MAX_V2_ISM_DEVS + 1];
@@ -597,6 +617,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
void smc_conn_free(struct smc_connection *conn);
int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
+void smcr_wait_pending_lgr(struct smc_init_info *ini);
int smc_core_init(void);
void smc_core_exit(void);
diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index e41011d19b73..b6582f8dc3a9 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -2268,6 +2268,7 @@ void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc)
spin_lock_init(&lgr->llc_flow_lock);
init_waitqueue_head(&lgr->llc_flow_waiter);
init_waitqueue_head(&lgr->llc_msg_waiter);
+ init_waitqueue_head(&lgr->first_contact_waiter);
init_rwsem(&lgr->llc_conf_mutex);
lgr->llc_testlink_time = READ_ONCE(net->smc.sysctl_smcr_testlink_time);
lgr->max_send_wr = (u16)(READ_ONCE(net->smc.sysctl_smcr_max_send_wr));
@@ -2306,6 +2307,10 @@ void smc_llc_link_active(struct smc_link *link)
SMC_LGR_ID_SIZE, &link->peer_link_uid,
link->smcibdev->ibdev->name, link->ibport);
link->state = SMC_LNK_ACTIVE;
+ /* a listen worker may be waiting for this link group to stop being a
+ * pending first contact, see smcr_wait_pending_lgr()
+ */
+ wake_up_all(&link->lgr->first_contact_waiter);
if (link->lgr->llc_testlink_time) {
link->llc_testlink_time = link->lgr->llc_testlink_time;
schedule_delayed_work(&link->llc_testlink_wrk,
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange
2026-12-03 15:35 ` [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Ermenson Junior
@ 2026-12-04 15:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 15:41 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 more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says "Neither check rejects a message a
conforming peer can send." That holds for the round cap but not for…
- [Low] The new overall deadline (SMC_LLC_RKEY_EXCHG_TIME) is only
checked at the top of each round.
--
net/smc: bound the SMC-Rv1 add-link rkey exchange
This commit limits the SMC-Rv1 ADD_LINK_CONT rkey exchange loops in
smc_llc_cli_rkey_exchange() and smc_llc_srv_rkey_exchange() to
SMC_LLC_RKEY_CONT_MSG_MAX (128) rounds. It also adds an overall deadline,
SMC_LLC_RKEY_EXCHG_TIME. A peer that keeps reporting num_rkeys=255 can no
longer keep the loop running forever.
> Cap the rounds at that derived limit and give
> the exchange as a whole a deadline: the round cap on its own would
> still allow 128 * SMC_LLC_WAIT_TIME of held mutex, and a deadline on
> its own would still allow an unbounded number of instant rounds under
> it. Neither check rejects a message a conforming peer can send.
[Severity: Low]
Is the last sentence accurate for the deadline? The round cap comes from
the protocol. SMC_LLC_RKEY_EXCHG_TIME is a fixed (SMC_LLC_WAIT_TIME * 10),
which is 20 seconds no matter how many rkeys need to be exchanged.
Before this patch, a peer only had to answer each ADD_LINK_CONT within
SMC_LLC_WAIT_TIME. A full 128 round exchange could therefore legitimately
take up to about 256 seconds.
Both smc_llc_cli_rkey_exchange() and smc_llc_srv_rkey_exchange() now run
this check at the top of each round:
timeo = (long)(expire - jiffies);
if (timeo <= 0) {
rc = -ETIMEDOUT;
...
}
A peer can answer every message within 2 seconds and still be aborted, if
its replies average more than about 156 ms per round over 128 rounds.
Slow rounds can have several causes:
- the peer blocks in smc_wr_tx_get_free_slot(), for up to
SMC_WR_TX_WAIT_FREE_SLOT_TIME
- workqueue latency
- a non-Linux SMC-Rv1 implementation
Nothing is logged when this happens. smc_llc_cli_add_link() sets rc = 0
and goes to out_clear_lnk. smc_llc_srv_add_link() goes to out_err. In both
cases the link group quietly runs without its second link.
Could the commit message say that the deadline can reject a slow but
conforming peer? Or could the deadline be derived from the number of
rounds instead?
> diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
> index c9ccd8480369c..818dd84e720fc 100644
> --- a/net/smc/smc_llc.c
> +++ b/net/smc/smc_llc.c
[ ... ]
> @@ -1359,11 +1384,25 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link,
> down_write(&lgr->rmbs_lock);
> num_rkeys_send = lgr->conns_num;
> buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
> + expire = jiffies + SMC_LLC_RKEY_EXCHG_TIME;
> do {
> + long timeo;
> +
> + if (rounds++ >= SMC_LLC_RKEY_CONT_MSG_MAX) {
> + rc = -EPROTO;
> + goto out;
> + }
> + timeo = (long)(expire - jiffies);
> + if (timeo <= 0) {
> + rc = -ETIMEDOUT;
> + goto out;
> + }
> + if (timeo > SMC_LLC_WAIT_TIME)
> + timeo = SMC_LLC_WAIT_TIME;
> +
> smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
> &buf_lst, &buf_pos);
> - qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME,
> - SMC_LLC_ADD_LINK_CONT);
> + qentry = smc_llc_wait(lgr, link, timeo, SMC_LLC_ADD_LINK_CONT);
[Severity: Low]
Can the exchange run past SMC_LLC_RKEY_EXCHG_TIME here? timeo is
computed and capped before smc_llc_add_link_cont(), then passed unchanged
to smc_llc_wait().
smc_llc_add_link_cont() can sleep:
smc_llc_add_link_cont()
smc_llc_add_pending_send()
smc_wr_tx_get_free_slot()
wait_event_interruptible_timeout(link->wr_tx_wait, ...,
SMC_WR_TX_WAIT_FREE_SLOT_TIME);
SMC_WR_TX_WAIT_FREE_SLOT_TIME is 10 * HZ. This wait can happen when all TX
slots are busy, for example when the peer delays completions.
Say a round starts with R jiffies left. It can block for up to 10 seconds
in the send, then still wait up to min(R, SMC_LLC_WAIT_TIME) for the
reply. The exchange can therefore end about 10 seconds past the deadline.
That is also how much longer rmbs_lock, llc_conf_mutex and
smc_server_lgr_pending can stay held.
The later patch in this series, "net/smc: check the ADD_LINK_CONT send
result in the server rkey exchange", only adds a return value check after
the send. It does not recompute timeo, so the overrun is still there at
the end of the series.
The client loop has a similar but smaller overrun. In
smc_llc_cli_rkey_exchange(), the send is the last step of a round, after
the deadline-checked wait:
smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
rc = smc_llc_add_link_cont(link, link_new, &num_rkeys_send,
&buf_lst, &buf_pos);
if (rc)
break;
} while (num_rkeys_send || num_rkeys_recv);
A send that blocks after the last wait can also run up to 10 seconds past
the deadline.
Would it work to compute timeo after smc_llc_add_link_cont() returns,
just before smc_llc_wait(), and abort if it is <= 0? Otherwise, the
comment on SMC_LLC_RKEY_EXCHG_TIME and the commit message could call the
deadline approximate.
> if (!qentry) {
> rc = -ETIMEDOUT;
> goto out;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203153514.1440337-1-ermenson.sec%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server rkey exchange
2026-12-03 15:35 ` [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server " Ermenson Junior
@ 2026-12-04 15:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 15:41 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 more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message for "net/smc: check the ADD_LINK_CONT send
result in the server rkey exchange" overstates the bug.
--
net/smc: check the ADD_LINK_CONT send result in the server rkey exchange
This patch makes smc_llc_srv_rkey_exchange() check the return value of
smc_llc_add_link_cont() and leave the loop when the send fails, which
matches smc_llc_cli_rkey_exchange(). Before the patch, the server side
ignored the send result and called smc_llc_wait() anyway.
> smc_llc_srv_rkey_exchange() discards it and goes on to wait for a reply
> to a message that was never transmitted, so the round can only end in
> the wait timing out. Make the server side behave like the client side.
[Severity: Low]
Is "can only end in the wait timing out" accurate for most send failures?
smc_llc_wait() is called with a non-NULL link. wait_event_timeout()
checks its wake condition before it sleeps:
net/smc/smc_llc.c:smc_llc_wait() {
wait_event_timeout(lgr->llc_msg_waiter,
(flow->qentry ||
(lnk && !smc_link_usable(lnk)) ||
list_empty(&lgr->list)),
time_out);
...
}
If smc_wr_tx_link_hold() fails, smc_llc_add_link_cont() returns -ENOLINK.
In that case the link is not sendable (INACTIVE or UNUSED), so
smc_link_usable() is already false and the wait returns immediately.
There are two other failure paths: ib_post_send() failing in
smc_wr_tx_send(), and the free slot wait in smc_wr_tx_get_free_slot()
timing out with -EPIPE. Both call smcr_link_down_cond_sched()
synchronously:
net/smc/smc_core.c:smcr_link_down_cond_sched() {
if (smc_link_downing(&lnk->state)) {
...
}
smc_link_downing() does cmpxchg(state, SMC_LNK_ACTIVE, SMC_LNK_INACTIVE).
The link is therefore already INACTIVE when smc_llc_wait() is entered,
so the wait again returns without sleeping.
A full SMC_LLC_WAIT_TIME wait seems to happen only in narrower cases:
- the link is still ACTIVE but its QP is not in RTS (-ENOLINK or
-EPIPE)
- the lgr is terminating but still on the list (-EBUSY)
The only caller, smc_llc_srv_add_link(), handles every non-zero rc the
same way:
rc = smc_llc_srv_rkey_exchange(link, link_new);
if (rc)
goto out_err;
So the patch seems to have two visible effects. The errno changes from
-ETIMEDOUT to the send error, and the narrow cases above fail sooner.
No exchange that used to succeed now fails, and none that used to fail
now succeeds. The code change looks correct and matches
smc_llc_cli_rkey_exchange().
Since the patch carries a Fixes: tag, could the commit message say that
the effect is limited to the errno and the shorter failure time in those
cases?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203153514.1440337-1-ermenson.sec%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation
2026-12-03 15:35 ` [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation Ermenson Junior
@ 2026-12-04 15:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 15:41 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 more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message never says why the change is needed, and it
hides a hard dependency.
- [Low] "No reader changes behaviour" is not accurate for user-visible
output.
- [Low] Both the commit message and the new comment in smcr_link_init()
say the add-link callers overwrite peer_gid/peer_mac in…
- [Low] The new comment in smcr_link_init() says "peer_qpn, peer_psn and
peer_mtu come from the peer's CLC CONFIRM".
--
net/smc: set a new link's peer gid and mac at creation
This patch makes smcr_link_init() copy peer_gid and peer_mac from
smc_init_info into the new link when the link is created. Before, both
stayed zero until smc_link_save_peer_info() ran after the CLC accept or
confirm. The add-link paths pass a zeroed smc_init_info and fill both
fields from the ADD_LINK message.
> smcr_link_init() leaves lnk->peer_gid and lnk->peer_mac zero. They are
> filled only once the peer's CLC accept or confirm has been processed, by
> smc_link_save_peer_info(), which copies them out of smc_init_info. Both
> values are already in smc_init_info when the link is created, so set them
> there. This changes when the fields become valid, not what they hold.
[Severity: Low]
The message explains why the change is harmless. Could it also say why
the change is needed?
As far as I can tell, the reason is the next patch in the series,
"net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait". That
patch adds smcr_lgr_pending_match(), which reads peer_gid and peer_mac of
links still in SMC_LNK_ACTIVATING:
if (!memcmp(lnk->peer_gid, ini->peer_gid, SMC_GID_SIZE) &&
(ini->smcr_version == SMC_V2 ||
!memcmp(lnk->peer_mac, ini->peer_mac, ETH_ALEN)))
These fields are only non-zero at that point because of this patch.
Neither commit message mentions the dependency.
smc_link_save_peer_info() in af_smc.c still does the same copy:
memcpy(link->peer_gid, ini->peer_gid, SMC_GID_SIZE);
memcpy(link->peer_mac, ini->peer_mac, sizeof(link->peer_mac));
So the patch writes the same values a second time rather than moving the
first write. Read on its own, the patch looks like a no-op cleanup that
could be dropped. If it were dropped, the next patch would still build,
but smcr_lgr_pending_match() would compare zeros against ini->peer_gid
and never match.
Would it make sense to state this dependency in the commit message?
> No reader changes behaviour: the QP is programmed from the gid only after
> the peer info is saved, smcr_lgr_match() looks at active links, and the
> netlink and diag paths display the field.
[Severity: Low]
Is "No reader changes behaviour" accurate for what user space sees?
smc_nl_handle_lgr() dumps every link that passes smc_link_usable().
smc_link_usable() rejects only SMC_LNK_UNUSED and SMC_LNK_INACTIVE, so
SMC_LNK_ACTIVATING links are dumped too:
net/smc/smc_core.c:smc_nl_handle_lgr() {
...
if (!smc_link_usable(&lgr->lnk[i]))
continue;
if (smc_nl_fill_lgr_link(lgr, &lgr->lnk[i], skb, cb))
...
}
smc_nl_fill_lgr_link() puts link->peer_gid into SMC_NLA_LINK_PEER_GID.
__smc_diag_dump() in smc_diag.c exports it as well.
On the server, smc_lgr_create() adds the link group to smc_lgr_list right
after smcr_link_init(). The link then stays ACTIVATING for the whole CLC
CONFIRM wait, which can last up to CLC_WAIT_TIME.
Netlink and diag dumps taken during that window used to show an all-zero
peer GID. They now show the GID from the proposal. This includes
handshakes that later time out and get cleared.
The value is the same one smc_link_save_peer_info() stores later, so this
looks harmless. Could the message describe this change rather than call
it a non-change?
The message also leaves out two other readers: the link selection loop in
smc_connect_rdma() and smc_llc_find_asym_link(). Neither seems to change
in practice:
- The smc_connect_rdma() loop also needs peer_qpn to match, and peer_qpn
is still 0.
- smc_llc_find_asym_link() never sees two links during a first contact.
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 34fd8f3e7939f..61d4d4b559caf 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -824,6 +824,15 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
> lnk->wr_rx_sge_cnt = 1;
> lnk->wr_rx_buflen = SMC_WR_BUF_SIZE;
> }
> + /* peer_qpn, peer_psn and peer_mtu come from the peer's CLC CONFIRM and
> + * are filled later by smc_link_save_peer_info(). The gid and the mac are
[Severity: Low]
Does this hold on the client side? Only the server takes these values
from the CLC CONFIRM, in smc_listen_rdma_finish():
smc_link_save_peer_info(link, cclc, ini);
On the client, smc_connect_rdma() passes the server's CLC ACCEPT:
if (ini->first_contact_local)
smc_link_save_peer_info(link, aclc, ini);
So for client first links, peer_qpn, peer_psn and peer_mtu come from the
ACCEPT. The commit message gets this right ("the peer's CLC accept or
confirm").
At the end of the series, the comment still names only CLC CONFIRM for
these fields. The same comment says the gid and mac come "from the
proposal on the server and from the accept on the client", so the comment
contradicts itself.
> + * already in ini here, and smc_link_save_peer_info() copies them from the
> + * same fields, so this changes when they become valid and not what they
> + * hold. The add-link callers pass a zeroed ini and overwrite both in
> + * smc_llc_save_add_link_info() straight after.
> + */
[Severity: Low]
Is "straight after" accurate for the server add-link path? It holds for
the client, where smc_llc_cli_add_link() calls
smc_llc_save_add_link_info() right after smcr_link_init().
In smc_llc_srv_add_link(), several steps run between the two calls,
including a blocking wait for the peer:
smc_llc_srv_add_link()
smcr_link_init()
smcr_buf_map_lgr()
smc_llc_send_add_link()
smc_llc_wait(..., SMC_LLC_WAIT_TIME, SMC_LLC_ADD_LINK)
...
smc_llc_save_add_link_info(link_new, add_llc);
The -ETIMEDOUT and -ENOLINK exits after smc_llc_wait() skip
smc_llc_save_add_link_info() entirely.
Later in the series, "net/smc: drop smc_server_lgr_pending across the CLC
CONFIRM wait" changes the comment to say "afterwards". This commit
message still says "straight after".
Could the comment be fixed in this patch rather than in a later one, and
the commit message updated to match?
The comment also reads like a changelog ("this changes when they become
valid and not what they hold"), and it still does at the end of the
series. It describes the patch rather than the code, which will read
oddly once merged.
Could it describe the code's behaviour instead?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203153514.1440337-1-ermenson.sec%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait
2026-12-03 15:35 ` [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait Ermenson Junior
@ 2026-12-04 15:41 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 15:41 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 8 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 4
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 commit message says the deferral fallback cannot be
reached today.
- [Medium] The patch exists to stop one remote peer from stalling every
server-side SMC handshake on the host by holding…
- [Medium] A server connection joining an existing SMC-R link group is
admitted in smc_conn_create() against…
- [Medium] smcr_lgr_pending_match() runs with only smc_lgr_list.lock
held.
- [Low] smcr_wait_pending_lgr() sets ini->rc = 0 (smc_core.c:2139).
- [Low] The wait predicate does not match the defer predicate or the
field comment.
- [Low] The new comment above the early return in
smc_listen_find_device() (af_smc.c:2424) says that trying V1 after a…
- [Low] The commit message says waiters are woken "where a link leaves
SMC_LNK_ACTIVATING, in smc_llc_link_active() and smcr_link_clear()".
--
net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait
This patch makes smc_listen_work() release smc_server_lgr_pending as soon
as the CLC ACCEPT has been sent. Before, the mutex was held across the
CLC CONFIRM wait and smc_listen_rdma_finish(). To avoid duplicate server
link groups, smc_conn_create() now defers to a matching first-contact link
group whose link is still SMC_LNK_ACTIVATING. The listen worker then waits
on a new first_contact_waiter queue and retries within a bounded window.
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index c0d905140a10a..307dd3f2acd68 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -2415,6 +2415,14 @@ static int smc_listen_find_device(struct smc_sock *new_smc,
> smc_find_rdma_v2_device_serv(new_smc, pclc, ini);
> if (ini->smcrv2.ib_dev_v2)
> return 0;
> + /* A first contact of this peer is still establishing. Return now:
> + * trying V1 below would call smc_conn_create() a second time, and with
> + * the deferral already spent it would create a link group and leave
> + * this connection registered on it while the caller still waits and
> + * retries.
> + */
> + if (ini->pending_lgr)
> + return ini->rc;
[Severity: Low]
This isn't a bug, but is the reason given in this comment accurate?
smcr_may_defer() does not use up a deferral. It keeps returning true for
the whole window:
return !ini->pending_armed ||
time_before(jiffies, ini->pending_deadline);
Right after a V2 deferral, a V1 smc_conn_create() could defer a second
time. It would then overwrite ini->pending_lgr without a smc_lgr_put(),
leaking the reference that smcr_lgr_find_pending() took. If the V1 peer
gid did not match, it could create a link group instead.
The early return prevents both. Could the comment describe the reference
hazard instead of a "deferral already spent"?
[ ... ]
> @@ -2540,27 +2563,25 @@ static void smc_listen_work(struct work_struct *work)
> if (rc)
> goto out_unlock;
>
> - /* SMC-D does not need this lock any more */
> - if (ini->is_smcd)
> - mutex_unlock(&smc_server_lgr_pending);
> + /* Link group creation is complete, so this lock is not needed across
> + * the peer-paced wait for the CLC CONFIRM below. A further connection
> + * of this peer now finds the link group through
> + * smcr_lgr_pending_match() and waits for it, which is what holding
> + * this mutex until the first link became active used to achieve.
> + */
> + mutex_unlock(&smc_server_lgr_pending);
[Severity: Medium]
Can a remote peer still hold smc_server_lgr_pending for longer than the
CLC_WAIT_TIME this patch removes?
A server connection that joins an existing link group still runs
smc_listen_find_device() under the mutex, and that path reaches:
smc_listen_find_device()
smc_find_rdma_v2_device_serv()
smc_listen_rdma_reg()
smcr_lgr_reg_rmbs()
smc_llc_flow_initiate(lgr, SMC_LLC_FLOW_RKEY)
smc_llc_do_confirm_rkey()
smc_llc_flow_initiate() waits up to SMC_LLC_WAIT_TIME * 10 per pass and
loops while a flow is busy. smc_llc_do_confirm_rkey() waits for the peer's
CONFIRM_RKEY response. A peer with an established link group that stalls
the RKEY flow while it opens new connections would keep the mutex held
across these waits.
There is a second case. Once smc_llc_link_active() has run in
smcr_serv_conf_first_link(), a second connection of the same peer joins
through smcr_lgr_match() while holding the mutex. Meanwhile the
first-contact worker does:
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);
}
The joiner then blocks with no timeout, either in
smcr_buf_map_usable_links() on down_read(&lgr->llc_conf_mutex) or in
smc_llc_flow_initiate().
The peer sets the pace of that phase: about 2s for the ADD_LINK response,
up to SMC_LLC_RKEY_EXCHG_TIME (20s) for the SMC-Rv1 rkey exchange, and 5s
for CONFIRM_LINK. That is roughly 27s on v1 and 7s on v2.
The commit message says:
Those two waits have no timeout, so this is only acceptable because
the flow they wait on is bounded, which is what the first two patches
of this series do.
Of those two patches, "net/smc: check the ADD_LINK_CONT send result in the
server rkey exchange" describes itself as independent and droppable. Only
"net/smc: bound the SMC-Rv1 add-link rkey exchange" adds a bound, and that
bound (20s) is larger than the 6s stall being fixed.
Is the host-wide stall still reachable through these join paths?
[Severity: Medium]
Does moving the unlock here break the rtoken admission check for joining
connections?
smc_conn_create() admits a joining server connection, under the mutex,
with:
(role == SMC_CLNT || ini->is_smcd ||
(lgr->conns_num < lgr->max_conns &&
!bitmap_full(lgr->rtokens_used_mask, SMC_RMBS_PER_LGR_MAX)))) {
The slot itself is reserved only after the ACCEPT:
smc_listen_rdma_finish()
smc_rmb_rtoken_handling()
smc_rtoken_add()
smc_rmb_reserve_rtoken_idx()
Before this patch the mutex was held until smc_listen_rdma_finish()
returned, so the check and the reservation were serialized. Now, with K
free rtoken slots, more than K concurrent joiners can pass the
bitmap_full() test.
The extra joiners then fail late. Either smc_rtoken_add() returns -ENOSPC
(SMC_CLC_DECL_ERR_RTOK), or the LLC CONFIRM_RKEY path answers RKEY_NEG.
They fall back to TCP, where before they would have created a new link
group.
[ ... ]
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index 61d4d4b559caf..aca10aa419aa4 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
[ ... ]
> @@ -1395,6 +1396,10 @@ static void __smcr_link_clear(struct smc_link *lnk)
> lnk->state = SMC_LNK_UNUSED;
> if (!atomic_dec_return(&smcibdev->lnk_cnt))
> wake_up(&smcibdev->lnks_deleted);
> + /* a listen worker may be deferring to this link group, see
> + * smcr_wait_pending_lgr()
> + */
> + wake_up_all(&lgr->first_contact_waiter);
> smc_lgr_put(lgr); /* lgr_hold in smcr_link_init() */
> }
[Severity: Low]
The commit message says:
Waiters are woken where a link leaves SMC_LNK_ACTIVATING, in
smc_llc_link_active() and smcr_link_clear().
This wakeup is in __smcr_link_clear(), which runs only when the last link
reference is dropped. It is not in smcr_link_clear() itself.
Are there other transitions that make the wait condition in
smcr_wait_pending_lgr() true without waking anyone?
smcr_lgr_link_deactivate_all() moves ACTIVATING links to INACTIVE but
wakes only the LLC queues:
if (smc_link_sendable(lnk))
lnk->state = SMC_LNK_INACTIVE;
}
wake_up_all(&lgr->llc_msg_waiter);
wake_up_all(&lgr->llc_flow_waiter);
smcr_lgr_activating() also tests lgr->sync_err and lgr->freeing. sync_err
is set in smc_clc_wait_msg() on a first-contact DECLINE, and freeing is
set in smc_lgr_claim(). Neither wakes first_contact_waiter.
Suppose the first-contact connection still holds its link reference while
the link group terminates. A deferring worker then stays parked until
min(left, CLC_WAIT_TIME) expires, using up its deferral window, even
though a retry could go ahead at once.
[ ... ]
> @@ -2009,6 +2014,153 @@ static bool smcr_lgr_match(struct smc_link_group *lgr, u8 smcr_version,
[ ... ]
> + for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
> + lnk = &lgr->lnk[i];
> +
> + if (lnk->state != SMC_LNK_ACTIVATING)
> + continue;
> + if (!rdma_dev_access_netns(lnk->smcibdev->ibdev, net))
> + return false;
[Severity: Medium]
Can lnk->smcibdev be NULL here?
This runs with only smc_lgr_list.lock held, and the paths that move a
link out of SMC_LNK_ACTIVATING and wipe it do not take that lock. One
example is the failure path of smc_llc_srv_add_link(), which holds only
llc_conf_mutex:
out_err:
if (link_new) {
link_new->state = SMC_LNK_INACTIVE;
smcr_link_clear(link_new, false);
}
On the final put, __smcr_link_clear() does memset(lnk, 0, ...), which
clears lnk->smcibdev.
Here is one way to get there:
- smc_llc_srv_add_link() has lnk_new in SMC_LNK_ACTIVATING.
- lnk[0] goes down, so the group has no ACTIVE link and passes the first
loop of smcr_lgr_pending_match().
- The ADD_LINK then fails and the new link is cleared.
A concurrent listen worker for the same peer may have read
state == SMC_LNK_ACTIVATING and been delayed before it loads
lnk->smcibdev. It would then dereference NULL->ibdev while holding
smc_lgr_list.lock and smc_server_lgr_pending.
smcr_lgr_match() has a similar check-then-dereference for ACTIVE links,
but this adds another instance for the ACTIVATING state.
[ ... ]
> +static bool smcr_lgr_activating(struct smc_link_group *lgr)
> +{
> + int i;
> +
> + /* lnk[] is in the SMC-R arm of the link group union, so check the
> + * variant here rather than trusting the caller
> + */
> + if (lgr->is_smcd)
> + return false;
> + if (READ_ONCE(lgr->sync_err) || READ_ONCE(lgr->terminating) ||
> + READ_ONCE(lgr->freeing))
> + return false;
> + for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++)
> + if (READ_ONCE(lgr->lnk[i].state) == SMC_LNK_ACTIVATING)
> + return true;
> + return false;
> +}
[Severity: Low]
Should this predicate match the one in smcr_lgr_pending_match()?
smcr_lgr_pending_match() will not defer to a group that has an ACTIVE
link. The first_contact_waiter comment says the queue waits for the "1st
link to leave SMC_LNK_ACTIVATING".
smcr_lgr_activating() instead keeps the waiter asleep while any link is
ACTIVATING, even when another link is already ACTIVE.
In smcr_serv_conf_first_link(), smc_llc_link_active() wakes the waiters.
Then, for max_links > 1, smc_llc_srv_add_link() puts a new link into
SMC_LNK_ACTIVATING.
A waiter that re-checks the condition after that point goes back to sleep
until the ADD_LINK flow ends or min(left, CLC_WAIT_TIME) expires. A retry
at that point would already match through smcr_lgr_match().
> +
> +/* A deferral parks this listen worker, so repeated deferrals need a bound.
> + * The window opens at the first deferral, not at the first call, and it is
> + * two CLC_WAIT_TIME wide so that it covers a first contact failing on its own
> + * CONFIRM timeout: without that room the second connection's wait always ends
> + * past the deadline and a third connection could still create the duplicate
> + * this is here to prevent. Past the window the worker creates a link group as
> + * it did before this patch.
> + */
> +#define SMC_LGR_PENDING_WINDOW (2 * CLC_WAIT_TIME)
> +
> +static bool smcr_may_defer(struct smc_init_info *ini)
> +{
> + return !ini->pending_armed ||
> + time_before(jiffies, ini->pending_deadline);
> +}
[Severity: Medium]
The commit message says:
The window is wider than the longest a link can stay in
SMC_LNK_ACTIVATING, CLC_WAIT_TIME + SMC_LLC_WAIT_FIRST_TIME, so today
that fallback is not reachable.
Is that bound correct?
SMC_LLC_WAIT_FIRST_TIME is used by smc_llc_cli_conf_link() and
smc_llc_srv_conf_link(), not by the server first-contact path.
smcr_serv_conf_first_link() makes up to two smcr_link_reg_buf() calls and
then does:
qentry = smc_llc_wait(link->lgr, link, SMC_LLC_WAIT_TIME,
SMC_LLC_CONFIRM_LINK);
if (!qentry) {
struct smc_clc_msg_decline dclc;
rc = smc_clc_wait_msg(smc, &dclc, sizeof(dclc),
SMC_CLC_DECLINE, CLC_WAIT_TIME_SHORT);
The CLC CONFIRM wait is not bounded by one CLC_WAIT_TIME either.
smc_clc_wait_msg() sets sk_rcvtimeo once. It then does a
MSG_PEEK | MSG_WAITALL header receive and a separate MSG_WAITALL body
receive, and each gets a fresh timeout. The commit message notes this
itself ("bounds only by CLC_WAIT_TIME per receive").
So a peer could keep the first-contact link ACTIVATING for about 15-16s
after the ACCEPT. Suppose a second connection of the same peer first
defers right after that ACCEPT. Its window closes at about 12s,
smcr_may_defer() returns false, and smc_conn_create() falls through to
smc_lgr_create(). The first link group is still on smc_lgr_list and still
ACTIVATING at that point.
Wouldn't that create the duplicate link group this patch is meant to
prevent?
Before this patch, smc_server_lgr_pending serialized these connections.
So "creates a link group as before", in the commit message and in the
comment above smcr_wait_pending_lgr(), does not seem to describe the same
behaviour.
[ ... ]
> +void smcr_wait_pending_lgr(struct smc_init_info *ini)
> +{
> + struct smc_link_group *lgr = ini->pending_lgr;
> + unsigned long left;
> +
> + ini->pending_lgr = NULL;
> + /* smc_init_info_store_rc() keeps the first value stored, so the
> + * deferral's own rc has to go or it would mask the retry's. A decline
> + * reason an earlier ISM attempt stored is dropped with it, and the
> + * retry derives its own.
> + */
> + ini->rc = 0;
[Severity: Low]
Can the retry actually derive its own ISM decline reason?
On the first pass, smc_find_ism_v2_device_serv() and
smc_find_ism_v1_device_serv() clear the version bits at not_found:
ini->smcd_version &= ~SMC_V2;
...
ini->smcd_version &= ~SMC_V1;
On the retry, both return early because those bits are now missing:
if (!(ini->smcd_version & SMC_V2) || !smcd_indicated(ini->smc_type_v2))
goto not_found;
smc_listen_work() saves and restores only smcr_version, through
pending_smcr_version, and not smcd_version. On the retry neither ISM probe
runs, so SMC_CLC_DECL_NOSMCD2DEV is never stored.
If the retry then ends in a decline, smc_listen_decline() sends prfx_rc
or an RDMA reason. The unpatched code would have sent the ISM reason
first.
Should smcd_version be saved and restored along with smcr_version, or
should the comment be changed?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203153514.1440337-1-ermenson.sec%40gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-04 15:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:35 [PATCH net-next v2 0/4] net/smc: stop a silent peer stalling every server handshake Ermenson Junior
2026-12-03 15:35 ` [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 2/4] net/smc: check the ADD_LINK_CONT send result in the server " Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 3/4] net/smc: set a new link's peer gid and mac at creation Ermenson Junior
2026-12-04 15:41 ` netdev-bot+sashiko
2026-12-03 15:35 ` [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait Ermenson Junior
2026-12-04 15:41 ` 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