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=1796114432; b=Mjg01V0C6BSEllkSBt/nFW+6NaoRP8kmmdxrdsee88RIzq7TmvlAmJiSK8h/dFrJ038i a8yToZRcxOjjVPPFZ6bunmrpO/1zRxkvFyl8n1c7fHcgpt9wGCig176BCohIkHKeZpIgV W+mtNfffv+766h1WzVH79vVVtokvSDL1QMz90Tohtz4WbvhIfS9JU39yXuVilcKCyiSNj Iz/n27BuMsKJDck4+eGtjgEERSUORoVT8ArfUoK6IJVrCoxQuiThv+VMYkv8vwGPJFD54 AhaT99F0Swl6+Fp1tQeGrsIDFQcml1PaKAiSDxj/3x1jLOPcw98E/aL4y1jqeAESlCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796114432; 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-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=FjsuC2R2e05AKcbppFejoTr1qjOF18I0S7QiHWAPNa0=; b=5Sit/t/OmCaYal8HEzUrBH0izvmNujXyiRoDf40MwiQq6aini8R4lBuBugZeUx1IbjVE 7mUcQQA4RZwITqk8nZTimrlPg4B+LuqvRlaDToGUq9orX0+gIZT/gmfVDtKGdBrDyteFf tYwV+KUJQKwva9hu3l3BkcNMDDNcZuTPHXhYJq9CCwIXF2zzcwKkT18bO5SJrEjHE+F8j MHxac+PouHfZS9T+gvXI1pEZFA2H96V3P3+c3+h38+XobNwhTWkPS25rPlaEyHfe6fKf1 NSX6OvBeJxL1DV7rilqZj9uUCB0O39iTeLs24yiQeOly8Ibp9oJtbG6mQfcKK2hBgNQ== 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=nDxxY5lN; 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 DDDE0606A339; Tue, 1 Dec 2026 08:40:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DDDE0606A339 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) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=nDxxY5lN Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B12ZnHm645663; Tue, 1 Dec 2026 08:40:01 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=FjsuC2 R2e05AKcbppFejoTr1qjOF18I0S7QiHWAPNa0=; b=nDxxY5lN7H5HPN7OFCqi6n I2N67aEOSBzi3vK458H75BUkydf5axjoALp7tmiY9lBKop2dYr28nLSqKCioK54J nKUvtF4TjvpqP6zFb0LXAGxvWQmi2T52FYT8ptNcXd1IW9fDESJUTp/156Yny7QC wQrNVCXtFU3nJPiQkJYBCe+0G8CQZpcCNwNtNdmN/AbFoVPET7LmPTbnubOEAej+ jrE7PoDd8gplt7wUmLerlkiG6zS7dwvsC+a4iGzfiZVV1AL0E/eZF1SKoZvEAMgv MYi8qa4rIcx1cBTdRr7YNra4mQborOP9ILW8tL6eWZkfiDQXAPxdYKoQ3b8IGu+w == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pp5usrs-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 08:40:00 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B17Yt4h2305741; Tue, 1 Dec 2026 08:39:59 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4j8a9k0e2g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 08:39:59 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B18dw7N25494164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 08:39:58 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 84E9E58045; Tue, 1 Dec 2026 08:39:58 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2F6858050; Tue, 1 Dec 2026 08:39:52 +0000 (GMT) Received: from [9.123.8.233] (unknown [9.123.8.233]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 08:39:52 +0000 (GMT) Message-ID: Date: Tue, 1 Dec 2026 14:09:51 +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] net/smc: abort old connection when peer reuses RMB element To: Andrew Stellman , "D. Wythe" , Dust Li , Sidraya Jayagond Cc: Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Willem de Bruijn , linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org References: <20261129001734.78551-1-bugs@stellman-greene.com> Content-Language: en-US From: Mahanta Jambigi In-Reply-To: <20261129001734.78551-1-bugs@stellman-greene.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-GUID: Ipd2hfJT8VcUc1dSU_nNSjw3avDBUiN_ X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfX+5SVebMZQMG1 i6UeK83mY878GvajWbILmbpv4MVL4n/Ejn9iSLCEEIDVox5Savll6OosbPh6x/ZCRub1jNgEPHW 2PAmfwyPxnSNMrucJykCj7XUuTHsawQ= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAzNCBTYWx0ZWRfX1aXrpdlPTRH7 9gsnoee9cqnhdbbyAGLs4FLCdezDuBg/lrp/sC1o9evAwpsRfNP/SGC5474Y/JW+d5Q25BqANDF j+jZYk1xtZexLAJOZuREyLnc1xqIviqduFymTIcGF53Y8S97Grv6xGzVHll9VLLkD4AwpxuTxo9 tCbxPDLIi3+C7vqjoTMFG+9H8qtOd11hd0t70qVioRLcEZ6OViEsErrM1CEOKQilauOLzgxSTkc oyl7tT9TbslSI3ekFyfxETT+M1m3enfFh9IaJo/56i6TwRIhMTGkKWoC+mau665MONgnPckh9hN 7QmUNfmdtbgbkvIMPIhDbUzIt87k/w3LsQdwPC5UvrvdpKxt/wvO2Z1HtSt9nsqSURTHHAfc/vT nWINnceGTVp2n8vn9jgOGsLRMPZaaXa6eiC9ODpNzqaKjF4kGKE+Z3JeRXqFTcUb6bzLiYycPhU E9xLvwgZGKTaarGkI/g== X-Authority-Analysis: v=2.4 cv=Ae8kjHXG c=1 sm=1 tr=0 ts=6b0e87e1 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=NEAV23lmAAAA:8 a=9FA5dTSvAAAA:8 a=HoI2d6UjbjL24NhbiikA:9 a=QEXdDO2ut3YA:10 a=SJrKH111sO7Rm7Y-nST0:22 X-Proofpoint-ORIG-GUID: ZmaMjw-9tdnqSJAEGb6nMOlMZsw_FjhP 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-01_01,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010034 On 29/11/26 5:47 am, Andrew Stellman wrote: > From: Andrew Stellman > > If a peer repeats an RMB rkey and DMA address in a later CLC handshake, > smc_rtoken_add() reuses the existing rtoken slot. If the peer also > repeats the RMB element index, two connections in the link group write > to the same peer buffer. The rkey and DMA address are not per connection. The peer registers its RMB once per link, and smc_tx_rdma_write() adds tx_off and the element offset to lgr->rtokens[conn->rtoken_idx][link->link_idx].dma_addr. Every connection to the same peer on that link therefore shares the rtoken slot by design, and the duplicate that matters is only peer_rmbe_idx. As written the paragraph reads like the shared rtoken is the bug; worth rewording around the element index. > > After resolving the rtoken, abort any existing connection that has the > same rtoken and element index. Set rtoken_idx to -1 in > smc_conn_create() so a connection still in its handshake can't match. > Both handshake paths already hold the new socket's lock, so take the > old one with lock_sock_nested(), and keep that lock class when > smc_close_active_abort() drops and retakes it. > > The abort is synchronous because, from the source, queueing the old > connection's abort_work instead looks unsafe: a close path can call > smc_conn_free() with the socket lock held and wait in > cancel_work_sync() for that work, which needs the same lock, and a > cancelled work item never drops the socket reference taken for it. That cancelled-work reference leak is being fixed separately in "net/smc: fix sock reference leak on abort_work cancel". Once it lands, the asynchronous variant deserves another look, since it would remove the lock nesting that the comment above is about. > > This changes existing behaviour: when a peer presents an rtoken and > element index that another connection on the link group is using, the > older connection is now aborted. > > Tested on mainline in arm64 QEMU with KASAN, lockdep and SoftRoCE. With > a test-only peer that repeated the first connection's rtoken and element > index in a second ACCEPT and a second CONFIRM, the old server socket > read the second connection's data before the patch; after it, send() on > both old sockets failed with EPIPE, with no lockdep or KASAN warning. > Ordinary two-connection traffic passed with and without the patch. > > The issue was found by Claude Opus 5 running Quality Playbook, an > LLM-driven code review tool: > https://github.com/andrewstellman/quality-playbook > The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with > Claude Opus 5.5, and both were reviewed by me. > > Fixes: bd4ad57718cc ("smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR") > Signed-off-by: Andrew Stellman > --- > A reproducer is available on request. > > net/smc/af_smc.c | 2 +- > net/smc/smc_close.c | 20 +++++++++++++------- > net/smc/smc_close.h | 2 +- > net/smc/smc_core.c | 46 +++++++++++++++++++++++++++++++++++++++++---- > 4 files changed, 57 insertions(+), 13 deletions(-) > > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index bfc0c7e71a12b4..fbf710f4308818 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -356,7 +356,7 @@ int smc_release(struct socket *sock) > > if (old_state == SMC_INIT && sk->sk_state == SMC_ACTIVE && > !smc->use_fallback) > - smc_close_active_abort(smc); > + smc_close_active_abort(smc, false); > > rc = __smc_release(smc); > > diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c > index 736abfbd2aafaa..88c82a7b74efd9 100644 > --- a/net/smc/smc_close.c > +++ b/net/smc/smc_close.c > @@ -111,7 +111,7 @@ int smc_close_abort(struct smc_connection *conn) > return smc_cdc_get_slot_and_msg_send(conn); > } > > -static void smc_close_cancel_work(struct smc_sock *smc) > +static void smc_close_cancel_work(struct smc_sock *smc, bool nested) > { > struct sock *sk = &smc->sk; > > @@ -120,13 +120,16 @@ static void smc_close_cancel_work(struct smc_sock *smc) > sock_put(sk); > if (cancel_delayed_work_sync(&smc->conn.tx_work)) > sock_put(sk); > - lock_sock(sk); > + if (nested) > + lock_sock_nested(sk, SINGLE_DEPTH_NESTING); > + else > + lock_sock(sk); > } > > /* terminate smc socket abnormally - active abort > * link group is terminated, i.e. RDMA communication no longer possible > */ > -void smc_close_active_abort(struct smc_sock *smc) > +void smc_close_active_abort(struct smc_sock *smc, bool nested) > { > struct sock *sk = &smc->sk; > bool release_clcsock = false; > @@ -141,7 +144,7 @@ void smc_close_active_abort(struct smc_sock *smc) > case SMC_APPCLOSEWAIT1: > case SMC_APPCLOSEWAIT2: > sk->sk_state = SMC_PEERABORTWAIT; > - smc_close_cancel_work(smc); > + smc_close_cancel_work(smc, nested); > if (sk->sk_state != SMC_PEERABORTWAIT) > break; > sk->sk_state = SMC_CLOSED; > @@ -151,7 +154,7 @@ void smc_close_active_abort(struct smc_sock *smc) > case SMC_PEERCLOSEWAIT2: > case SMC_PEERFINCLOSEWAIT: > sk->sk_state = SMC_PEERABORTWAIT; > - smc_close_cancel_work(smc); > + smc_close_cancel_work(smc, nested); > if (sk->sk_state != SMC_PEERABORTWAIT) > break; > sk->sk_state = SMC_CLOSED; > @@ -163,7 +166,7 @@ void smc_close_active_abort(struct smc_sock *smc) > case SMC_PROCESSABORT: > case SMC_APPFINCLOSEWAIT: > sk->sk_state = SMC_PEERABORTWAIT; > - smc_close_cancel_work(smc); > + smc_close_cancel_work(smc, nested); > if (sk->sk_state != SMC_PEERABORTWAIT) > break; > sk->sk_state = SMC_CLOSED; > @@ -183,7 +186,10 @@ void smc_close_active_abort(struct smc_sock *smc) > if (release_clcsock) { > release_sock(sk); > smc_clcsock_release(smc); > - lock_sock(sk); > + if (nested) > + lock_sock_nested(sk, SINGLE_DEPTH_NESTING); > + else > + lock_sock(sk); > } > } > > diff --git a/net/smc/smc_close.h b/net/smc/smc_close.h > index 634fea2b7c95b1..1fa9bc211f4751 100644 > --- a/net/smc/smc_close.h > +++ b/net/smc/smc_close.h > @@ -25,6 +25,6 @@ int smc_close_shutdown_write(struct smc_sock *smc); > void smc_close_init(struct smc_sock *smc); > void smc_clcsock_release(struct smc_sock *smc); > int smc_close_abort(struct smc_connection *conn); > -void smc_close_active_abort(struct smc_sock *smc); > +void smc_close_active_abort(struct smc_sock *smc, bool nested); Not a bug, but the flag is threaded through three shared helpers for one new caller. A private __smc_close_active_abort(smc, nested) would keep the existing signature and callers untouched. > > #endif /* SMC_CLOSE_H */ > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > index a3164201c14204..cb45c36cdce66d 100644 > --- a/net/smc/smc_core.c > +++ b/net/smc/smc_core.c > @@ -1537,7 +1537,7 @@ static void smc_sk_wake_ups(struct smc_sock *smc) > } > > /* kill a connection */ > -static void smc_conn_kill(struct smc_connection *conn, bool soft) > +static void smc_conn_kill(struct smc_connection *conn, bool soft, bool nested) > { > struct smc_sock *smc = container_of(conn, struct smc_sock, conn); > > @@ -1571,7 +1571,7 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft) > smc_cdc_wait_pend_tx_wr(conn); > } > smc_lgr_unregister_conn(conn); > - smc_close_active_abort(smc); > + smc_close_active_abort(smc, nested); > } > > static void smc_lgr_cleanup(struct smc_link_group *lgr) > @@ -1625,7 +1625,7 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft) > * link group by a retried handshake in the meantime. > */ > if (conn->lgr == lgr) > - smc_conn_kill(conn, soft); > + smc_conn_kill(conn, soft, false); > release_sock(&smc->sk); > sock_put(&smc->sk); /* sock_hold above */ > read_lock_bh(&lgr->conns_lock); > @@ -1788,7 +1788,7 @@ static void smc_conn_abort_work(struct work_struct *work) > struct smc_sock *smc = container_of(conn, struct smc_sock, conn); > > lock_sock(&smc->sk); > - smc_conn_kill(conn, true); > + smc_conn_kill(conn, true, false); > release_sock(&smc->sk); > sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */ > } > @@ -2024,6 +2024,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) > spinlock_t *lgr_lock; > int rc = 0; > > + conn->rtoken_idx = -1; > lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list : > &smc_lgr_list.list; > lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock : > @@ -2757,6 +2758,42 @@ int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey) > return -ENOENT; > } > > +/* Abort a connection if the peer reuses its RMB element for this handshake. */ > +static void smc_rtoken_resolve_conflict(struct smc_connection *conn, u8 rmbe_idx) > +{ > + struct smc_link_group *lgr = conn->lgr; > + struct smc_connection *old; > + struct smc_sock *old_smc; > + struct rb_node *node; > + > + for (;;) { > + read_lock_bh(&lgr->conns_lock); > + for (node = rb_first(&lgr->conns_all); node; node = rb_next(node)) { > + old = rb_entry(node, struct smc_connection, alert_node); > + if (old != conn && !old->freed && > + old->rtoken_idx >= 0 && > + old->rtoken_idx == conn->rtoken_idx && > + old->peer_rmbe_idx == rmbe_idx) > + break; > + } > + if (!node) { > + read_unlock_bh(&lgr->conns_lock); > + return; > + } > + old_smc = container_of(old, struct smc_sock, conn); > + sock_hold(&old_smc->sk); > + read_unlock_bh(&lgr->conns_lock); > + > + lock_sock_nested(&old_smc->sk, SINGLE_DEPTH_NESTING); Can two handshakes deadlock here? Both handshake workers hold their own socket lock for the whole handshake: smc_connect_work() takes smc->sk before __smc_connect(), and smc_listen_work() holds new_smc->sk until smc_listen_out(). This takes the second socket's lock while the first is still held, and SINGLE_DEPTH_NESTING is a lockdep annotation, not a deadlock prevention. Two connections that resolve the same peer element at the same time then form a cycle: A holds sk(A) and takes sk(B), B holds sk(B) and takes sk(A). The window is small, rtoken_idx is set just before the scan, but the peer controls the timing: two connections opened together with the same rmbe_idx put both workers into it, and both sleep in D state with their locks held. That is a remote hang against smc_hs_wq, and it comes from exactly the duplicated element this patch is about. A correct peer never hands one element to two live connections, so this is buggy or hostile peer territory rather than normal traffic, but it is the case the patch has to survive. > + if (old->lgr == lgr && old->alert_token_local && !old->freed && > + old->rtoken_idx == conn->rtoken_idx && > + old->peer_rmbe_idx == rmbe_idx) > + smc_conn_kill(old, true, true); > + release_sock(&old_smc->sk); > + sock_put(&old_smc->sk); > + } > +} > + > /* save rkey and dma_addr received from peer during clc handshake */ > int smc_rmb_rtoken_handling(struct smc_connection *conn, > struct smc_link *lnk, > @@ -2766,6 +2803,7 @@ int smc_rmb_rtoken_handling(struct smc_connection *conn, > clc->r0.rmb_rkey); > if (conn->rtoken_idx < 0) > return conn->rtoken_idx; > + smc_rtoken_resolve_conflict(conn, clc->r0.rmbe_idx); On the client this runs with smc_client_lgr_pending held: smc_connect_rdma() takes the mutex before smc_conn_create() and releases it after smc_rmb_rtoken_handling(). If the resolve blocks on an old connection's socket lock, for example a passive connection still waiting for its CONFIRM, which holds that lock for the CLC timeout, then every client-side connect stalls behind the global mutex. Either move the resolve outside the mutex or make it non-blocking for handshaking connections, as above.