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=1796366227; b=iBM0pCMRYT8Z8zM9PqStxxwQRlTO0WF5frvvtCExNicrVLQxtNd6dV6dWxyZjebX0ukH ykK6I+8FdxF3gS451GJbiN0ifGxsjSvUw+uagI2hDBb2/BLlIygOgX+MQj1ijGHDdP6/V JMJfEXknVtZI0alliB0sb8I1UfN4+vWRVzwIm813tH3q464vNxxGjdQUNru4/TzDvFlZy C1nj7c9RpMdluWwupxm0JpnlHBwHSl5OCM9tEysofz1KLHaRLu9Rj0eQtEJrzd7n2Mu5X +xWr6O1OZRTp6hDvar9uQhE1i69UBQd2M/Zc8042GUpS+GDhWfX0rUjNiggKLIdWexg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366227; 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-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=cirNgFTbi6EPU8o9GK6yRGARvJXH3Rm03B9i10+sm8E=; b=hUOcUj5f2iC9Ut86RIg4uUqi62kKfpDSjkXaSEvwQoRnvS+GUBbYl2lRD/3UX6nrZXyC mKsxI9LYu0EdA1uBtzZ2DGYKHMM8YFrqSaZ1lWtcilWhUNMbxDvetqozAzU/2HSPqcWOY cQrKNem7khFCXnTbNRycTVDL8vMd1mxOqjH1TxuZnnnhDocP0BfUnFy8XOcfEgIR3mINS l+1J2eK72yvVVHiF4NF5I8Cjm0Xsun4k26jRBrZDT053uvb7vSTjqCi9MNBP6VRDidmff F1mtFWhDjRiQsUDfb+nhjxnjuq0RaslZ/EijPRvxzFu+pt78Jvdp52k1S/jQqnN3lfQ== 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=GWeo7LDN; 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 640E3606A322; Fri, 4 Dec 2026 06:37:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 640E3606A322 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=GWeo7LDN Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B45YlLv3833622; Fri, 4 Dec 2026 06:37: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=cirNgF Tbi6EPU8o9GK6yRGARvJXH3Rm03B9i10+sm8E=; b=GWeo7LDNGFXJklV7O9MfRo CHi0WI3ftFmVNjLZqPhXlTJsbXUKQW4OT33bwRnfsJwoyJ+aJBnU1qYQirjMYqEd 8J6ADHOxbCLt61Njg6gftHTAs6MOtTfow8eIFYeK5OVteKKhdyFWThaYkOQuinqW MHRhqPNi635ja70RGXWdgbyQ5Op7DJ7sH9L9CywTwAY0nzjQrr75bmy302c3uEtk 3RgoLOP2IRyypqXO6CY25m0XyW/bCn99InEEss9S3Iw4Q8x2V6rqnE40IGKb/1g7 O3omyNtRlT4y8Cb73fN7e65dKnG1S+Mhcsc+x+910GMHXTLy+7x00ypQTbkBHCeg == Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbqgcr5cg-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 06:37:01 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B46VWL5204559; Fri, 4 Dec 2026 06:37:00 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4jbjn9s10n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 06:37:00 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B46ax8A12321334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Dec 2026 06:36:59 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 725DF58059; Fri, 4 Dec 2026 06:36:59 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9692758058; Fri, 4 Dec 2026 06:36:53 +0000 (GMT) Received: from [9.123.8.233] (unknown [9.123.8.233]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 4 Dec 2026 06:36:53 +0000 (GMT) Message-ID: <16726245-1c75-4efa-b259-7d528ff58713@linux.ibm.com> Date: Fri, 4 Dec 2026 12:06:52 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v4] net/smc: serialize clcsock release against CDC receive path To: Qican Ma , 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, horms@kernel.org, willemb@google.com, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org References: <179635082914.26472.6075133370101625319@gmail.com> Content-Language: en-US From: Mahanta Jambigi In-Reply-To: <179635082914.26472.6075133370101625319@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-ORIG-GUID: flf5VNsT2dPTIlntcZh18LJDVUBRmUdg X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDAyNiBTYWx0ZWRfX9qaHa6hdGyxh JgmrcHCipYaWwiYSMp6sLL/u/MkWR0iTSdxI6cuPhiwwM9obG8XhZMAcq6JiwmFl1mI/2mA/DN8 0Rc+w4NZjkBHvAKRcnFaUKxC0evxzs3h98zedvOsL/PE1EzKhW0rkfjR2+xkK0v0cu4Hn7mn7LB imO+ha93tJzd8HYWv22vnwbdstIQ3PP9PkceBB+xmxS3RYa3/BZg1aFlcrH1QdtysNtfL0msR6y LXq6/BNfYPBr0vUVmzZimzszPFhMIXv8MFihwVpczSuOpDiuoICD7PLe3Yi9/+7znE1t7AIIwW/ y3jtH2MrE5xZK3eUtIazEisMLZCEq0lpbm6aG2KFtRqvdib+ud+HWJGG2rYem8xkthxK/ZDbkKx BmFq3hxn52XhPygdhejuD4Gf0D14q5ilCUGlFDbL8SxfUJdqKeuxWqsi2M8kIxKXh37GnYOHCk5 yRMIGQcxsY4b3Gw2bKw== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDAyNiBTYWx0ZWRfX+SlnqBa3JgIL DcsPHgFZ0i4Xr+PXkQMShLyNC+Ofoxt1Z7LK3Pju6jSKcpsMFm0ziRNExXTPiGSnBn/xcROdVZI PlXygJ91PGnlZgwnJJpno3nLkBZ315E= X-Authority-Analysis: v=2.4 cv=AdkkjHXG c=1 sm=1 tr=0 ts=6b125f8d cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=CxzF0ed8NGJbJwdaTaAA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: DTqDSscGA4zRVbScsPB-UHSkVmWd9CfW 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-04_01,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 suspectscore=0 clxscore=1015 impostorscore=0 spamscore=0 phishscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040026 Hi Qican, v4 fixes both accessors I flagged; the __smc_release() reorder and the Fixes tag are right. One thing: smc_tx_is_corked() returning true does not mean no RDMA write happens. smc_tx_should_cork() also requires sndbuf_space, so with a full sndbuf it still calls smc_tx_sndbuf_nonempty(), and the sndbuf copy happens before the cork check. If the goal is only to avoid the clcsock deref, reword that sentence; if it is to keep tx off a dying connection, check earlier and return an error. Thanks, Mahanta On 04/12/26 7:50 am, Qican Ma wrote: > In smc_cdc_msg_recv_action(), receiving a close or senddone flag writes > RCV_SHUTDOWN to smc->clcsock->sk->sk_shutdown while holding only > bh_lock_sock(&smc->sk). Meanwhile __smc_release() drops the socket lock > and calls smc_clcsock_release() (which clears smc->clcsock and calls > sock_release() under clcsock_release_lock) before calling > smc_conn_free(&smc->conn). Even on paths that call smc_conn_free() first, > an in-flight SMC-R softirq that already looked up the connection in > smc_cdc_rx_handler() can still enter smc_cdc_msg_recv() concurrently with > smc_clcsock_release() and dereference or write through a freed clcsock. > > Free the SMC connection before releasing clcsock in __smc_release(), > matching smc_close_active_abort() and smc_close_passive_work(). Because > smc_conn_free() sets conn->freed while lock_sock(sk) is held and > release_sock(sk) synchronizes on sk->sk_lock.slock before > smc_clcsock_release() runs, checking !smc->conn.freed under > bh_lock_sock(&smc->sk) in smc_cdc_msg_recv() guarantees that no CDC > handler accesses smc->clcsock once smc_clcsock_release() can start. > > The send path has the same class of race: smc_tx_is_corked() dereferences > smc->clcsock under lock_sock(), and a sendmsg() that acquires the socket > lock in the release window can still observe a detached or freed clcsock. > Guard it on the same conn->freed check (plus a NULL check); the access is > race-free because both the writer and this reader run under lock_sock(). > A dying connection is reported as corked so no further RDMA writes are > triggered while teardown is in progress. > > The freed flag is written under lock_sock() but read under bh_lock_sock() > in softirq context, so the writer side and the smc_conn_create() > initializer use WRITE_ONCE() and the CDC reader uses READ_ONCE() to avoid > a KCSAN data race, as pointed out by Willem de Bruijn. > > Found with an LLM-assisted code review tool and verified by inspection on > v7.4-rc4 (b6a9fa34ce4). Build-tested only; not runtime-tested due to lack > of an SMC-R/SMC-D setup. > > Fixes: 46c28dbd4c23 ("net/smc: no socket state changes in tasklet context") > Cc: stable@vger.kernel.org > Signed-off-by: Qican Ma > --- > v4: correct the Fixes: tag to 46c28dbd4c23, which introduced the > tasklet-context clcsock write, and extend the conn->freed guard to > the tx corking path, per Mahanta Jambigi's review. > v3: use WRITE_ONCE() for conn->freed in smc_conn_free() and > smc_conn_create(), READ_ONCE() for the CDC-side read, per Willem de > Bruijn's KCSAN data race review. > v2: resend via direct SMTP to fix line-wrapping corruption in v1; > verified clean git am on net/main both standalone and on top of > Bryam Vargas's v9 CDC cursor bounds series. > > net/smc/af_smc.c | 4 ++-- > net/smc/smc_cdc.c | 3 ++- > net/smc/smc_core.c | 4 ++-- > net/smc/smc_tx.c | 6 +++++- > 4 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index bfc0c7e71a12..1d8a602729c1 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -313,13 +313,13 @@ static int __smc_release(struct smc_sock *smc) > sk->sk_prot->unhash(sk); > > if (sk->sk_state == SMC_CLOSED) { > + if (!smc->use_fallback) > + smc_conn_free(&smc->conn); > if (smc->clcsock) { > release_sock(sk); > smc_clcsock_release(smc); > lock_sock(sk); > } > - if (!smc->use_fallback) > - smc_conn_free(&smc->conn); > } > > return rc; > diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c > index 32d6d03df321..34c654e6600b 100644 > --- a/net/smc/smc_cdc.c > +++ b/net/smc/smc_cdc.c > @@ -428,7 +428,8 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc) > { > sock_hold(&smc->sk); > bh_lock_sock(&smc->sk); > - smc_cdc_msg_recv_action(smc, cdc); > + if (!READ_ONCE(smc->conn.freed)) > + smc_cdc_msg_recv_action(smc, cdc); > bh_unlock_sock(&smc->sk); > sock_put(&smc->sk); /* no free sk in softirq-context */ > } > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > index a3164201c142..92efb1b457a9 100644 > --- a/net/smc/smc_core.c > +++ b/net/smc/smc_core.c > @@ -1284,7 +1284,7 @@ void smc_conn_free(struct smc_connection *conn) > */ > return; > > - conn->freed = 1; > + WRITE_ONCE(conn->freed, 1); > if (!smc_conn_lgr_valid(conn)) > /* Connection has already unregistered from > * link group. > @@ -2096,7 +2096,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) > smc_lgr_hold(conn->lgr); /* lgr_put in smc_conn_free() */ > if (!conn->lgr->is_smcd) > smcr_link_hold(conn->lnk); /* link_put in smc_conn_free() */ > - conn->freed = 0; > + WRITE_ONCE(conn->freed, 0); > conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE; > conn->local_tx_ctrl.len = SMC_WR_TX_SIZE; > conn->urg_state = SMC_URG_READ; > diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c > index 0f0c6df3bf2c..a69809474df5 100644 > --- a/net/smc/smc_tx.c > +++ b/net/smc/smc_tx.c > @@ -126,8 +126,12 @@ static int smc_tx_wait(struct smc_sock *smc, int flags) > > static bool smc_tx_is_corked(struct smc_sock *smc) > { > - struct tcp_sock *tp = tcp_sk(smc->clcsock->sk); > + struct tcp_sock *tp; > > + if (smc->conn.freed || !smc->clcsock) > + return true; > + > + tp = tcp_sk(smc->clcsock->sk); > return (tp->nonagle & TCP_NAGLE_CORK) ? true : false; > } >