From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398917; b=JgVcE9p6QXhTU8CtF5YsddKUPTLuReiM4W/QdEnEIHlxm4Ul9SXLXuPbVvI6mIgTE+1F 1ovdy4NTOLFzXkX8gN55OpuBrhzxL4Bso5QpHYWydTrCQ795Dd6UdpXIA6AvtUdvwMVOG bR+X4f2Ek7KvzAesEHgOzT6b/6ZLDMavqoBN6CcyL6GZljH99yEauiPIvlvilOu19XD5J RhyfScyCgAc3MEDIrTIzs9yX5rgNlc8qj40yHJscnR4VDu32Q17cHBuMUeZ6+IZfsXYVe NSnswbI+ju0sdTUhLn4TLGegDe+PoqEngQ+3wCTGFzWICIhFuedTcnShea92E3+Mdmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398917; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=/GtUmqDpC2R4SEYJHFmXVspz3Y5A4sZ8tumn2MoK/C4=; b=FxE+FJlvVMhloF2uBHnUjNgNseb6DhTM8/eGlRRwh9NidbQlR6PSbofvLDdD11oChspg W+L6eWgUxAUZEE7xI76tdLW/wJVNOc5b24UBul5Tx3O6V7UvhvLpgnfm/DlQXtuX2oyg0 RgdSbQaEoHgK5nNFGdBhNfBlvikKe5VNlPxl29Ypcjqx6EALWEqybdgUonXFr0EiTt5Rj kRKKOGpdEUEQIRYPat0GB2coAshvYvL5Ho/w+A4KbnJhhdO9o3BzkeZlBwi86zX05NYLw 0ysxoO4B8hZJysT5Z/GypSwMPimSzGSHMsrYL7WQ2NP3Zjp2jTvjUZ4oJJynjJr4kmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fQy3Trjb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F9FF606A335; Fri, 4 Dec 2026 15:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fQy3Trjb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36E6D1F000C2; Fri, 4 Dec 2026 15:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796398917; bh=/GtUmqDpC2R4SEYJHFmXVspz3Y5A4sZ8tumn2MoK/C4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fQy3TrjbBR4NB+7k7oR5DlD/n7mgISrMQ7m+wfAdcP/GJ5ix959Z6BwE7V8nXvvAj 05Y25Kwxts+nYX273XzP6m0u/RdoBFCPujT/yGfiShMJeXb9EGHMwPNKG1hpQwBT86 2NHN5P/OMGBj6OKGQcbk8JZ/xNhjE1cqixqG69CK244u2961iZX6gx5NyXJljQVkHl E04lCEn3uWg2iOyGAZM+JYx0DShWX6kl0YgeN6niBfmaQ/0utRJmQH9TRH9VyDsLjb Ol1hk79td1788oFvMjsW6/ziB6hwMuMms9dG4cxsWrImEKLrRmgg77sdFLbbKWksgP YJRHGwq7fyTGA== Subject: Re: [PATCH net-next v2 4/4] net/smc: drop smc_server_lgr_pending across the CLC CONFIRM wait From: netdev-bot+sashiko@kernel.org To: ermenson.sec@gmail.com Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com, mjambigi@linux.ibm.com, tonylu@linux.alibaba.com, guwen@linux.alibaba.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org Date: Fri, 04 Dec 2026 15:41:55 +0000 Message-ID: <179639891580.3146.17407654245577966338@kernel.org> In-Reply-To: <20261203153514.1440337-5-ermenson.sec@gmail.com> References: <20261203153514.1440337-5-ermenson.sec@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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