From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796286935; b=QUL7ytF9TNl8PuRxS99znp6aPAlkJHTe1T94DIBLxmSoarWheKoYZJ1ee0vR8lM27eis VM8bZWrZ1L/wSAwdPfS9JWoekzFG9S+bN1fzTjXqKfQeRXddKKrGxJlkK2wKDHO6HLXOk cEhWwJLLFmuC8olTxKPE7NAojHNh76ge3WInBwG0YR4YVBIY2tXHhH4jF9twHKriTECHY 4zLzBH4JcK2hIuvJX3BV3O2GSFFAzhxHGByJIAIRKWQQlbYQbdlvFhAlJ69Prs7rkVW+h i/UcZ14R3stDC5E2S97pXIIy4vpAUqj/O0PuVlySHetessa4tFAQwNMPJqX8BpulSuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796286935; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=B1oCqb18LAaomxE8IEwYAV1TNH0fXzrjXGbIq3wzqUg=; b=jrssiLhUBALqT0UOVWa0jWykbUXar2AbZDlfhDhSs9dnEPa+X1gLaq3kWcUiCAEWQU0t cgpvQIZRSmjM5DCondwCgqW1AFE9jWy/2T2uIdEIb9PeaBFkwfdw15aXnKn3Oxa6eOq6p EnRt/6mKhgAFBhsIEXAZ16XX2bL48rnvblDOVfGC9pU0ra66k5qkXNwqWs/8DpYHlLYTG whEswxRXoA5KuD+U5valUNZ2qw9j5mgsBxGQ09UXhufEmcAtmR5eFd2V9rWfuNMoK9gR/ 2rMUZ+B7BSUQx0xjWR0Z3X3UV/WravblGF8y19ENtQjWOZD/SIiXh5tMtaF0IE8oEsw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=hbr0Sqv5; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 172E6606A322; Thu, 3 Dec 2026 08:35:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 172E6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=hbr0Sqv5 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B374Xhc2872250; Thu, 3 Dec 2026 08:35:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=B1oCqb 18LAaomxE8IEwYAV1TNH0fXzrjXGbIq3wzqUg=; b=hbr0Sqv5kRp1Ht2+KpGY71 C24Mgp5Pk52/y2FluUMS3/tvNwa9E6FIPZJLnXyUcKseJrg4HLGIIv9VONS1SoMD lnPHI8KNBK8pY5lLgojjy+pK8GoYx/aaHKNF3TRyAgM3j/9HauP7O49su5wFRAOn R4pp7yGBGaBJfZZWdk1NiTjKgiRp2J2++ThKWcpyxFjk+9/BFQJoBRKREyAXrV5O PJPRfedMXSjP7e8uPS+ZCmU7j/L2v/C3naGKoof/95FFS1KImxtRvGfcyC+8YOOV 4TGLBGEeNapLIoyvdTjBYrDZNrQFGL+kSg3zVP5WRBp75BOe5i++gulMXh8SdSMw == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pf460xy-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 03 Dec 2026 08:35:29 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B36nESK055255; Thu, 3 Dec 2026 08:35:28 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9ujnrpw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2026 08:35:28 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B38YZS116712196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Dec 2026 08:34:35 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0AD358054; Thu, 3 Dec 2026 08:35:27 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83C3E5804E; Thu, 3 Dec 2026 08:35:21 +0000 (GMT) Received: from [9.43.125.225] (unknown [9.43.125.225]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 3 Dec 2026 08:35:21 +0000 (GMT) Message-ID: Date: Thu, 3 Dec 2026 14:05:19 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next] net/smc: serialize the server establishment phase per peer, not globally To: Ermenson Junior , alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com Cc: 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 References: <20261202131243.664308-1-ermenson.sec@gmail.com> Content-Language: en-US From: Mahanta Jambigi In-Reply-To: <20261202131243.664308-1-ermenson.sec@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAzMDAzNCBTYWx0ZWRfXypyqfSw1FD7m CP0HAvlENf8/VxbW4ZGYHIsTVAF9+3lC3CZ5wh4ry9+FM0p3Gjzh6kWWeNv4VQ1UyC+S9at6j3I 0yPQ0i4JQiS5llVnwchCGYLTKiX9xUA= X-Proofpoint-ORIG-GUID: GLm_ElvKmCM2814DEdONPC7VvuEYfywH X-Proofpoint-GUID: LaA32dlU3rmYyXaTihT3IOU-rmN7GlWh X-Authority-Analysis: v=2.4 cv=R6eWitRX c=1 sm=1 tr=0 ts=6b1129d2 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=pGLkceISAAAA:8 a=AW8GaSBfLj6Vc3Cwp8IA:9 a=1DGu_mc03TnHL-rm:21 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAzMDAzNCBTYWx0ZWRfX7SKxhdMLdmri 8QTXfJM+RrwNgpAl0gCw07dnCeQIDKKDeVjp3v/poAdNcypf4ufiFMtUTR4lxfxzcScvyK+X55C 23yeNQscoJsJJWs4x+aKqmmNU9cLVkiz9K/yzQ2Rcn5ySJm9bcPbk2LB1aWyZ6GCPiLniH/D8HI SWGdUux+4YvL+uiIYtKsxkMjcXGbVNAqV7pgvUIjovJkuG4qEJ5up7Z3igWFc7o0Kp+54ljeLba q3914z3cc5ILopZiMGn8biVxD4ntO+ukRNEgJWVOTRKo/7nnGOS1YXOaVRbpRIR8Bapb0e2Ng+t dqFxX/J0/GTMaL64S6dSwgQZbg8t0PX7xAm9th8R2oOH7+GFhnsQsjfBi/DlK//t9vRkb2RWHBu ivr+rEYW2Ick0hmxR6qM0ljV39Ak9DS+rvffMNs9ahreR5qIa0NFtWoaKQWFzb0KsejPTu3XgOo LHTEDoBIz3QCYAEzqFA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-03_02,2026-12-02_07,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612030034 Hi Ermenson, Thanks for the patch and the detailed notes. I went through the server path and the locking and did not find a memory-safety or lock-order problem; checkpatch --strict is clean. One thing I would like to settle before it goes in: the duplicate link group. The global lock was exact, the hash is not. A multi-port peer whose proposal falls back from v2 to v1 can hash apart, and the server creates a second link group for that peer instead of joining the first. That is not only an attacker; a legitimate multi-port peer can hit it, and it changes behaviour from joining the first lgr to two lgrs. What happens to the peer and the resources in that case? If a duplicate lgr is not harmless, I would rather see the exact fix you decline to attempt: make smcr_lgr_match() see the pending link group, or key on something the v1/v2 decision cannot split. Thanks, Mahanta On 02/12/26 6:42 pm, Ermenson Junior wrote: > On the SMC-R server path smc_listen_work() holds the module-global > smc_server_lgr_pending across the wait for the peer's CLC CONFIRM, which > smc_clc_wait_msg() bounds only by CLC_WAIT_TIME per receive. A peer that > sends its proposal, reads the ACCEPT and then stays silent holds the > mutex for six seconds or more, and every other server-side handshake on > the host waits behind it. Commit 8270d9c21041 ("net/smc: Limit backlog > connections") already describes the lock as host wide. > > The mutex cannot simply be released earlier: a first-contact link group > has no active link until smcr_serv_conf_first_link() has run, after the > CONFIRM, and smcr_lgr_match() skips inactive links, so a second > connection of the same peer would create a duplicate link group. > > So keep smc_server_lgr_pending for link group creation only, released > once the ACCEPT is out, and hold a per-peer mutex (one of 64, hashed on > the proposal's peer system id and both peer gids) across the whole > establishment phase. Lock order is per-peer, then global. > > The key is a heuristic. It is exact when a peer's proposals that match > one link group carry the same gids, which holds for a single-port peer. > A multi-port peer whose proposal falls back from v2 to v1 can hash two > such proposals apart, and the server then creates a second link group > for that peer instead of joining the first. No key built from the > proposal can be exact, because v1 or v2 is chosen later, under the > global mutex; making smcr_lgr_match() see a pending link group would be > exact, and is not attempted here. Connections joining a link group over > different links can also land in different buckets. That is safe because > a joining peer sends CONFIRM_RKEY before its CLC CONFIRM, so > smc_llc_rmt_conf_rkey() has filled the rtoken row before the listen > worker looks for it; a peer that does not can only harm its own link > group. > > This confines the CLC CONFIRM wait of an unresponsive peer to that peer. > It does not bound the peer-paced waits that remain under the global > mutex in smc_listen_rdma_reg() for a peer with an existing link group, > and it is no defence against a peer that chooses its key. > > Tested on v7.4-rc5 with two kernels differing only by this patch, on > soft-RoCE with two RoCEv2 peers in separate network namespaces: an > unrelated peer's connect() during a silent peer's handshake went from > 4024.5 ms to 0.5 ms, while a connect from the same peer still waits. > Details, limits and what was not covered follow the --- line. > > The problem was found and this patch, its changelog and the test lab > were written with Claude (Anthropic), used interactively, and reviewed > and tested by the author; Documentation/process/generated-content.rst > asks for this to be stated, and more detail follows the --- line. > > Signed-off-by: Ermenson Junior > --- > > Notes for reviewers, not for the commit message. > > HOW THIS WAS TESTED > > Two kernels built from v7.4-rc5 (fe6ff8d5d675) with the same config and the > same script, differing only by this patch, booted in qemu with the same > initramfs. x86_64 defconfig + kvm_guest.config, SMC/SMC_DIAG/INFINIBAND/ > RDMA_RXE/DIBS built in, DIBS_LO off so SMC-R is selected rather than SMC-D, > PROVE_LOCKING and DETECT_HUNG_TASK on. Both kernels built with zero warnings. > > Topology: two network namespaces joined by a veth pair, a soft-RoCE (rxe) > device on each end, one UEID configured, two AF_SMC listeners on the server. > No RDMA hardware. The silent peer is simulated by dropping its CLC CONFIRM > with an iptables NFQUEUE handler on the server's INPUT chain; the peer keeps > its socket open, so from the server's side this is exactly a peer that > completes the proposal, reads the ACCEPT and then says nothing. > > The number that matters is how long an UNRELATED peer's connect() takes while > a silent peer is in flight. All times are the client's measured elapsed_ms, > all connects returned rc=0. > > unpatched patched > no silent peer (sanity) 0.6 ms 0.5 ms > silent peer; victim is a second RoCEv2 peer, > own namespace and rxe device, nothing rewritten 4024.5 ms 0.5 ms > silent peer; victim is the SAME peer (control) 4170.1 ms 4352.1 ms > silent peer with a rewritten system id (see below) 4196.2 ms 0.8 ms > after everything drained 0.6 ms 0.5 ms > > The second row is the deployment that matters: two RoCEv2 peers, both > announcing the all-zero system id that a v2-only proposal carries, differing in > gid and in nothing else. The stalls are about four seconds rather than six > because the victim starts two seconds into the silent peer's six-second window. > > The third row is the control and it is meant to stall on both kernels: two > first contacts of one peer still have to serialize, so a peer can still delay > itself. If that row had improved too, the improvement in the second row would > not have been attributable to the key. > > A fast victim is only evidence if it really negotiated SMC, since a fallback to > TCP also returns rc=0 in well under a millisecond. The smc_switch_to_fallback > tracepoint was enabled for the whole run on both kernels; it fired exactly once > per run, at about 8 s, for the silent peer of an earlier phase timing out its > own CONFIRM_LINK wait (SMC_CLC_DECL_TIMEOUT_CL). No victim fell back. > > Two things the lab made obvious, in the order I learned them. First, on > soft-RoCE no SMC-Rv1 can be offered (it needs IB_GID_TYPE_ROCE and rxe only has > RoCEv2 gids), and smc_clc_send_proposal() fills smc_clc_msg_local only when v1 > is offered, so every proposal in this lab carries an all-zero id_for_peer. A > first version of this patch keyed the mutex on the system id alone, and the > only way to measure it was to rewrite id_for_peer in the attacker's proposal in > flight. That worked in the lab and would have isolated nothing on a real RoCEv2 > deployment, where every peer announces the same zero id. The key now includes > the gid, and the decisive row above has two peers in separate namespaces with > their own rxe devices, differing in gid and in nothing else, with no field > rewritten. Second, that rewrite is itself the demonstration that the key is > chosen by the peer and authenticated by nothing, which is why the changelog > makes no claim against a peer that is trying. > > In both kernels the silent peer's connection was confirmed to reach the > server's wait: its proposal was seen and its CONFIRM was dropped eight or > nine times over the 20 s it held the socket, eight on one kernel and nine on > the other. Without that check a fast victim would be indistinguishable from an > attack that never happened. > > One thing in the logs I have not investigated: after the test, when the guest's > init runs poweroff with the silent peers' sockets still open, both kernels print > a hung-task report for poweroff in smc_cdc_wait_pend_tx_wr(). It is identical > on the unpatched kernel, so it is not this patch, and it is outside what I set > out to measure; I mention it so nobody finds it in a log and thinks it was > hidden. > > No lockdep report of any kind appeared on the patched kernel, which is the > check that matters for the new lock order (per-peer mutex, then > smc_server_lgr_pending). > > WHAT I COULD NOT DO, AND ONE MEASUREMENT I AM NOT QUOTING > > Both peers are AF_SMC sockets in the same kernel, so a local client doing > first contact waits in smcr_clnt_conf_first_link() for a CONFIRM_LINK that > cannot arrive and holds smc_client_lgr_pending - the other global mutex - for > about five seconds. A remote attacker cannot touch that lock, but in this lab > it hides the effect of this patch: measured that way the victim went from > 4333.5 ms to 3052.0 ms, and 3052 ms is within a millisecond of when the > attacker's own client gave up (5052.5 ms after it started, two seconds before > the victim). The rows above avoid this by letting each peer complete one > connection first, so the silent connection that follows is first contact on > neither side; its client returned in 1.6 ms and 1.7 ms and held no client-side > lock. I mention it because that contaminated pair of numbers is what the > obvious version of this experiment produces, and read alone it says the patch > does not work. > > Not covered: real RDMA hardware, SMC-D, SMC-v1 (soft-RoCE offers only RoCEv2 > GIDs, so a v1 proposal cannot be produced on it), link groups with more than > one link, and s390. The SMC-D path is unchanged by inspection, not by > measurement. > > The reproducer is a set of shell and C files rather than a single script. It > is not inlined here; I will send it to whoever wants it. > > No Fixes tag and net-next, deliberately: the behaviour is as old as the first > implementation (0cfdd8f92cac, 2017) and was documented as host-wide by the > maintainers in 8270d9c21041, and this is a change to how the handshake is > serialized, not a backport candidate. > > Per Documentation/process/security-bugs.rst, a reproducer for an AI-assisted > finding is not posted to a public list. Mine is a few shell and C files for the > namespace lab above; I will send them to any maintainer who asks. > > One observation from reading the surrounding code that I have NOT measured and > that this patch does not touch. On the SMC-Rv1 path, smc_llc_srv_rkey_exchange() > re-reads num_rkeys from each ADD_LINK_CONT the peer sends and loops while it is > non-zero, with no iteration cap; max_links is a fixed 2 on a v1 link group, so > every v1 first contact reaches it, and before this patch that was under > smc_server_lgr_pending. Commit 2d1e7c5aaa33 bounded the v2 twin of this loop > this year and left the v1 one as it was; smc_llc_cli_rkey_exchange() has the > same shape on the client side. I cannot measure it here because soft-RoCE > offers no RoCEv1 gid, so SMC-Rv1 cannot be negotiated on this lab. I will send > a bounded-counter patch for it separately rather than fold it in here. > > checkpatch --strict reports no errors and no checks. It reports one "Unknown > commit id" warning, for 8270d9c21041, the only commit the changelog cites; git > was not available in the container where checkpatch ran, and the commit > resolves with the title used here. > > Tool use, as Documentation/process/generated-content.rst asks. The tool was > Claude (Anthropic), driven interactively by me over one session. It read > net/smc at v7.4-rc5, located the hold across the CONFIRM wait and the > smcr_lgr_match() active-link condition behind it, proposed the per-peer key, > and wrote the hunk in this patch, the changelog, these notes, the kernel build > scripts and the namespace test (the guest init script and the netfilter helper > that drops or rewrites CLC messages in flight); it also ran the two-kernel > measurement. Four adversarial review passes by separate model instances were > run before sending and changed the key (system id alone to system id plus the > gids), the target tree (net to net-next) and several claims in the changelog > that did not survive them. I reviewed the patch and the measurement and > take responsibility for both. > > net/smc/af_smc.c | 62 ++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 55 insertions(+), 7 deletions(-) > > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index bfc0c7e71a12..d2858e75fc1d 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > > #include > @@ -66,6 +67,34 @@ static DEFINE_MUTEX(smc_client_lgr_pending); /* serialize link group > * creation on client > */ > > +/* Serialize the server-side establishment phase per peer, hashed on the > + * fields of the proposal that smcr_lgr_match() compares: peer system id and > + * both peer gids. The system id alone is all zero in a v2-only proposal. > + * Keeps further connections of a peer out of smc_conn_create() until a new > + * link group's first link is active, which is what smc_server_lgr_pending > + * used to cover across the peer-paced CLC CONFIRM wait. See the changelog > + * for what the key does not pin. > + */ > +#define SMC_SERVER_PEER_PENDING_BITS 6 > +#define SMC_SERVER_PEER_PENDING_SIZE BIT(SMC_SERVER_PEER_PENDING_BITS) > +static struct mutex smc_server_peer_pending[SMC_SERVER_PEER_PENDING_SIZE]; > + > +static struct mutex * > +smc_server_peer_pending_lock(struct smc_clc_msg_proposal *pclc) > +{ > + struct smc_clc_v2_extension *v2_ext = NULL; > + u32 key; > + > + key = jhash(pclc->lcl.id_for_peer, SMC_SYSTEMID_LEN, 0); > + key = jhash(pclc->lcl.gid, SMC_GID_SIZE, key); > + if (smcr_indicated(pclc->hdr.typev2)) > + v2_ext = smc_get_clc_v2_ext(pclc); > + if (v2_ext) > + key = jhash(v2_ext->roce, SMC_GID_SIZE, key); > + > + return &smc_server_peer_pending[key & (SMC_SERVER_PEER_PENDING_SIZE - 1)]; > +} > + > static struct workqueue_struct *smc_tcp_ls_wq; /* wq for tcp listen work */ > struct workqueue_struct *smc_hs_wq; /* wq for handshake work */ > struct workqueue_struct *smc_close_wq; /* wq for close work */ > @@ -2462,6 +2491,7 @@ static void smc_listen_work(struct work_struct *work) > struct smc_clc_msg_accept_confirm *cclc; > struct smc_clc_msg_proposal_area *buf; > struct smc_clc_msg_proposal *pclc; > + struct mutex *pending_lock = NULL; > struct smc_init_info *ini = NULL; > u8 proposal_version = SMC_V1; > u8 accept_version; > @@ -2524,6 +2554,12 @@ static void smc_listen_work(struct work_struct *work) > if (rc) > goto out_decl; > > + /* The key comes from the proposal, which has already been received and > + * validated, so the per-peer lock can be taken first. Lock order is > + * always per-peer lock before smc_server_lgr_pending. > + */ > + pending_lock = smc_server_peer_pending_lock(pclc); > + mutex_lock(pending_lock); > mutex_lock(&smc_server_lgr_pending); > smc_rx_init(new_smc); > smc_tx_init(new_smc); > @@ -2531,18 +2567,25 @@ static void smc_listen_work(struct work_struct *work) > /* determine ISM or RoCE device used for connection */ > rc = smc_listen_find_device(new_smc, pclc, ini); > if (rc) > - goto out_unlock; > + goto out_unlock_global; > > /* send SMC Accept CLC message */ > accept_version = ini->is_smcd ? ini->smcd_version : ini->smcr_version; > rc = smc_clc_send_accept(new_smc, ini->first_contact_local, > accept_version, ini->negotiated_eid, ini); > if (rc) > - goto out_unlock; > + goto out_unlock_global; > + > + /* Link group creation is complete, so the global lock is not needed > + * across the wait for the peer's CLC CONFIRM below. The per-peer lock > + * still keeps further connections of this peer out of > + * smc_conn_create() until the first link becomes active. > + */ > + mutex_unlock(&smc_server_lgr_pending); > > - /* SMC-D does not need this lock any more */ > + /* SMC-D does not need the per-peer lock past the ACCEPT either */ > if (ini->is_smcd) > - mutex_unlock(&smc_server_lgr_pending); > + mutex_unlock(pending_lock); > > /* receive SMC Confirm CLC message */ > memset(buf, 0, sizeof(*buf)); > @@ -2573,7 +2616,7 @@ static void smc_listen_work(struct work_struct *work) > ini->first_contact_local, ini); > if (rc) > goto out_unlock; > - mutex_unlock(&smc_server_lgr_pending); > + mutex_unlock(pending_lock); > } > smc_conn_save_peer_info(new_smc, cclc); > > @@ -2589,8 +2632,10 @@ static void smc_listen_work(struct work_struct *work) > smc_listen_out_connected(new_smc); > goto out_free; > > -out_unlock: > +out_unlock_global: > mutex_unlock(&smc_server_lgr_pending); > +out_unlock: > + mutex_unlock(pending_lock); > out_decl: > smc_listen_decline(new_smc, rc, ini ? ini->first_contact_local : 0, > proposal_version); > @@ -3463,7 +3508,10 @@ static struct pernet_operations smc_net_stat_ops = { > > static int __init smc_init(void) > { > - int rc; > + int i, rc; > + > + for (i = 0; i < SMC_SERVER_PEER_PENDING_SIZE; i++) > + mutex_init(&smc_server_peer_pending[i]); > > rc = register_pernet_subsys(&smc_net_ops); > if (rc)