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=1796304720; b=tEP6vHru1dIKlbYbcQjsCEVLcOoLt2Z66OcTyELYExYmVDEIEgmlMSOwyRmd/GgdGTga XrpqtI51R/8UGYAqQi9RICwMMqoxv7LL8RURcsIIqN9VmhvEmMQ4E2EodPe2T0pPLiX1T IlTiDofilru/rBqgNK0ziKdIwYwmMF4W2lADHJzYhUzUOJVueD/jiQAo7O2t87c+OXCCs zL0lphxBTuYMSjY2vTzhgstcuJ5Vxhq1ryTmSpatRV/ywezrgcal6td8ZChGKZl5WlBEV fjcMW+sc9rLSyWqzdXScfg3qqAeZXrQAjCKRKlQPFgsav9uOmgHvF58dvwWDzHm/SjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304720; 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=vlsZ1yNtJfDiE5YoxAYByKeRst5AsWAQ/bPsMckuh+U=; b=k4ZhZvOiTd3myPMEjCAQqPKk5fQlK7SGl+uX9uE2eWTqiM1Ff+5zGWx3cmYWcXLuc9Fp 7P6d08ONBzpSoeELWuy0RM2BQK3P0HNEMDA7rby211l4UhgAvfgtZjCDTBOWa+Dh1zsK4 70nqnHnB/euAGhHyl70WiYvzUrMnbnqAcPuBm3fzMCMII+ENnnm35NzBXDdxa32lTri8e C/phXOnu0Sls8VcUbqDLtJXb2RI0ryCM6C3dn1XH6pdre1nTNP1VlMOsLCqNYmcUivy2N Y3AdflfFF8Z9aKhl/bQg4sRMf3OXZLy+Gw9CKRFt1nThR5Hpmp5FvAN8TtyaDs1Ivrw== 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=J6De3ikt; 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 A4BB2606A32F; Thu, 3 Dec 2026 13:32:00 +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=J6De3ikt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42B041F00896; Thu, 3 Dec 2026 13:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796304720; bh=vlsZ1yNtJfDiE5YoxAYByKeRst5AsWAQ/bPsMckuh+U=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=J6De3iktYastlS1y5Rw1lJ+WmMzkHteCrCSDtH4N2e3m9456E+GxOobdn8jnBjGH+ UhVn1JD22BF1xsTlYSCsoGJeq5dayM28lq7V8mZ/dGgsuAEiI7GL8V0vpTSFGTfzwy GBXh6o+XwJEeB00w3nrfwJsIXcmKryHi6pSI8dUcn2ayLcqQcSbwgjAx+A4DY47KH2 poEplpe2F+OiDS5xqT1mZZ2m+Q/b0nVI+u8LPaTFlAMKt0vGAkKcaE0JZbakOs1wEv j8q9VSHKHXQPVV2joyQA4GkUPrjaFZUMJavFjSnuSjXf/J3w+zAtMMgkFQarJ0TVaX nUtN2wWLDhbHg== Subject: Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally 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: Thu, 03 Dec 2026 13:31:58 +0000 Message-ID: <179630471879.3146.18045828641124881081@kernel.org> In-Reply-To: <20261202131243.664308-1-ermenson.sec@gmail.com> References: <20261202131243.664308-1-ermenson.sec@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-rdma@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 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