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=1796364589; b=vwPjEajLzSU+qwVbt1EelWTZfg28Yq7X1GkFn2d0V6/IIRozdkQvy4hnUbVjUW5EqYyJ YlRea8RdIS4FZSv/Pz6YGY2NE6RPUYy9NhpYeKrtKfKx92ju3mYQTzR4aeoZbTtvAYHky u9Kp9AxRwc6Uk77OnNlH2MzKjEaxSn2WMrfMP3uRzL+WRwX9CvOrJ1g6Lm7XPjXEwWgF5 pYwnK0ZoAsADlFJhYdZN1zgFBUCbVm0K+LiCaDJbREUQ4XbeBKNxCu00BNcNsh47jiVgo SXStvZ/7/BNiVkpd8aNHoZB9QfantIoMlAoPWqhOL/qJQH9ke/aIS/jtPSUXeCK4JRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364589; 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-Details-Enc: X-Authority-Analysis:X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=YC64yks4GzCAeKBaYaKlUAnDvuqpS1vzwmEineAX0uw=; b=FF54DYiM6C46FokRRMdqDnZGe5VPGWAxiFF3dZ+gTJ9Uq1nDSbgpgbOvfw6YnBpw5Y4g 84BXbd2jNw1i2/u3lcCOOUhzxfQd5E2BElhyhrTwegKi2s000bKiAhal39jQG4dmZiJke pt5pFJ2FXhh/snscSJYnHDyOXzaK8AdFP2NTwbJkQLFlEMoqD41OnNrIvKZGnfnCkgL5A LnL/R8fJAASgdJ1ZztMoVCCg6GxesH2vi+xC6P5DKhOO4pGbCdqtIlat8vVbIRn1B/aoC 5H52G9rcZBfRsCuHca/YkKgyHn7b7DdBVh0LfcXekIcG87ogpeBA981uqv11VbYQMdw== 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=LWk6f89v; 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 2E5D8606A322; Fri, 4 Dec 2026 06:09:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E5D8606A322 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=LWk6f89v 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 6B45ZNjf1281910; Fri, 4 Dec 2026 06:09:43 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=YC64yk s4GzCAeKBaYaKlUAnDvuqpS1vzwmEineAX0uw=; b=LWk6f89vTDyj7wPWZ2MoXG KwkINuJfw0IVpB0xaxZrrWh0WGr80lh3WSUWROIc9p99oCB0yTiuQ7dgO0qysvSI WA0UJpZBvCbx/DHdwQeWupGEhab2aHRyJtwgShMyOLxGKmI3hZUyi1qUc1frz/fB KWWAkqiHNNDCjh4u5ruc0ORjNqqtMYP6XneWtASv5zlFW2LcRQwhWnD2qfgXS6Am R8HBcIDCSKi88PeQePtmRW4oDRVkf3ev7JdCOqybEq6vmVIOryxZEZrJ0i64pOng TKef24uqnbpyz/Bx5bF/t+NwmVSoCaxVAKg3X18ra/vebHc4vuNjKx5qzzCEG35g == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4jbqger3bc-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 06:09:42 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B40nFS21366245; Fri, 4 Dec 2026 06:09:42 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4jb7h9bg0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Dec 2026 06:09:41 +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 6B469fwC16908880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Dec 2026 06:09:41 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2FB515806A; Fri, 4 Dec 2026 06:09:41 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D96DE58059; Fri, 4 Dec 2026 06:09:00 +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:08:58 +0000 (GMT) Message-ID: Date: Fri, 4 Dec 2026 11:38: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 v2] net/smc: close non-accepted sockets without holding the listen lock To: Jiayi Zhang , "D. Wythe" , Dust Li , Sidraya Jayagond , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: Willem de Bruijn , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com References: <20261204055158.1897592-1-zhangjiayi1014@gmail.com> Content-Language: en-US From: Mahanta Jambigi In-Reply-To: <20261204055158.1897592-1-zhangjiayi1014@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-Details-Enc: AW1haW4tMjYxMjA0MDAyNCBTYWx0ZWRfX3teI1i5AESdv VdIKZk23WdtkCPfWt1PaiVZk6GuYT4musMSqp4ob1tyxRQJ0VMJ4PXNiYN1ThELF2JU0fzCQaIk aFHpmdw+vuemMLeltNCjdQXDO0o4PTUw+x9PNQgZzYVmW+C4hD+GXupuvpD01YRuUt4zfytMiyz 6gjgue+tlH8DsT9gk3/ZuMlksky0Uu+zWKcGyczNVv/dlLmx9vjYYVwxbGCmDPPPVZD6r3oJnlJ GzbQfgA5MLKfZ/WabXyPK3pMS6jApUqHFPv+tVtJYtTsLHQgRQwf5WwpCPF/X81bKJbME9Cae2c p1xqKpBdFUsz+nnRVMdN4hHFBHCGNHondErLwUbd0FFa0heLjIDq6ilwDlX9vgfy3EaLkA1EWa5 +XY4SNhaQrOTObaotFzScGgzzE5NRApXfpMK8cOjI9BiCUM21bZgggNZNAjyPdb5gANbeLYegPo ytrZ19lidfOHpxmYmfw== X-Authority-Analysis: v=2.4 cv=Au17T+9P c=1 sm=1 tr=0 ts=6b125927 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=edf1wS77AAAA:8 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=hSkVLCK3AAAA:8 a=qzb9SkrLV0g1AoguoWYA:9 a=QEXdDO2ut3YA:10 a=DcSpbTIhAlouE1Uv7lRv:22 a=cQPPKAXgyycSBL8etih5:22 X-Proofpoint-GUID: gUGj8EK1jXxqDYZv1itkq0CULgGj5vVv X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDAyNCBTYWx0ZWRfXzq3/UKmM9jg0 Zuug5E/P0MMtMpeWmugS0cJyG2T1K14j6Eh+oa68AGpOpEWlbBhvghganw4Db00sYFDsyvaZ4rP NN1ahPoLUJ7HrPNTIZXjOfpzqljHPPA= X-Proofpoint-ORIG-GUID: 5EypXnPvYWOW_4Z3akjLJIKxfa7y3v1I 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 adultscore=0 clxscore=1015 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040024 LGTM. Reviewed-by: Mahanta Jambigi On 04/12/26 11:21 am, Jiayi Zhang wrote: > syzbot reports a possible deadlock when a listening SMC socket is > closed: > > WARNING: possible circular locking dependency detected > ... > is trying to acquire lock: > ((work_completion)(&new_smc->smc_listen_work)), at: __flush_work > but task is already holding lock: > (sk_lock-AF_SMC/1), at: smc_release+0x3a5/0x620 net/smc/af_smc.c:353 > ... > -> #1 (sk_lock-AF_SMC/1): > lock_sock_nested+0x41/0xf0 net/core/sock.c:3909 > smc_listen_out+0xf2/0x4b0 net/smc/af_smc.c:1941 > ... > smc_listen_work+0x445/0x5040 net/smc/af_smc.c:2595 > -> #0 ((work_completion)(&new_smc->smc_listen_work)): > ... > cancel_work_sync+0xcc/0xf0 kernel/workqueue.c:4795 > smc_clcsock_release+0x5f/0xe0 net/smc/smc_close.c:29 > __smc_release+0x5c2/0x880 net/smc/af_smc.c:318 > smc_close_non_accepted+0xda/0x200 net/smc/af_smc.c:1871 > smc_close_cleanup_listen net/smc/smc_close.c:45 [inline] > smc_close_active+0x4ff/0x11a0 net/smc/smc_close.c:228 > __smc_release+0x634/0x880 net/smc/af_smc.c:294 > smc_release+0x1fc/0x620 net/smc/af_smc.c:361 > > smc_close_active() closes the sockets left on the accept queue of a > listening socket with smc_close_cleanup_listen() while it holds the lock > of the listening socket. Closing such a socket ends in > smc_clcsock_release(), which waits for the socket's smc_listen_work > with cancel_work_sync(). smc_listen_work() takes the lock of the > listening socket in smc_listen_out(). Commit fd57770dd198 ("net/smc: wait > for pending work before clcsock release_sock") added the > cancel_work_sync(). Because smc_listen_work() holds the lock of the new > socket, that commit made __smc_release() drop the socket's own lock > before smc_clcsock_release(). smc_close_cleanup_listen() still calls it > with the lock of the listening socket held. > > A socket on the accept queue has already passed that point: > smc_listen_out() puts it on the queue under the listen lock and does not > take that lock again. So this does not deadlock today, but lockdep > cannot tell the listen works apart and reports the dependency on every > such close. > > Close the non-accepted sockets after the listen lock is released, > together with the flush of tcp_listen_work that is already done there, > and take the lock again afterwards. > > smc_close_cleanup_listen() then walks the accept queue and updates > sk_ack_backlog of the listening socket without the listen lock. The > list is protected by accept_q_lock in smc_accept_enqueue() and > smc_accept_unlink(), but sk_acceptq_added() and sk_acceptq_removed() > rely on the listen lock, and smc_accept_dequeue() walks the list > without accept_q_lock. This is safe because nothing else adds to or > removes from the queue at this point: > > - Nothing is added. smc_close_active() has set the listening socket to > SMC_CLOSED under the listen lock, and smc_listen_out() checks the > state under the listen lock and closes a new socket itself instead > of queueing it. > > - Nothing is removed by accept(). The SMC_LISTEN case of > smc_close_active() is only reached from smc_release(), after the > last file reference is gone: smc_shutdown() returns -ENOTCONN for a > socket in SMC_LISTEN, and the other caller of __smc_release(), > smc_close_non_accepted(), only closes sockets created for incoming > connections, which are never in SMC_LISTEN. So accept() and poll() > cannot run on the listening socket any more. > > smc_listen_out() has checked the state under the lock since > commit 185a4caeecab ("net/smc: fix TOCTOU race between > smc_listen_out() and listener close"). A backport needs that commit > as well: without it, smc_listen_out() can queue a new socket after > the listening socket is closed, and that would race with the > unlocked walk. > > Fixes: fd57770dd198 ("net/smc: wait for pending work before clcsock release_sock") > Reported-by: syzbot+621fd56ba002faba6392@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=621fd56ba002faba6392 > Signed-off-by: Jiayi Zhang > --- > v2: > - changelog only, the code is unchanged: say why the accept queue > and sk_ack_backlog can be emptied without the listen lock, why > shutdown() cannot reach this path, and that a backport needs > 185a4caeecab (Mahanta Jambigi) > v1: https://lore.kernel.org/all/20261202175908.4136866-1-zhangjiayi1014@gmail.com/ > > Tested with the syzbot C reproducer and the kernel config of the > report, 5 QEMU instances of 10 minutes each: without the patch all 5 > report the lockdep splat; with the patch none of the 5 reports anything. > The net selftests were not run. > > Mahanta Jambigi's series "net/smc: keep clcsock until socket release" > (net-next v3, posted 2026-12-01) adds a comment to > smc_accept_dequeue() saying that the child and listener locks are held. > With this patch that is no longer true on the cleanup path from > smc_close_active(); Mahanta will adjust that comment in the series. > The two do not conflict textually. > > AI tools assisted with the analysis, the code and the changelog. > > net/smc/smc_close.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c > index 736abfb..2c98b77 100644 > --- a/net/smc/smc_close.c > +++ b/net/smc/smc_close.c > @@ -225,9 +225,9 @@ again: > write_unlock_bh(&smc->clcsock->sk->sk_callback_lock); > rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); > } > - smc_close_cleanup_listen(sk); > release_sock(sk); > flush_work(&smc->tcp_listen_work); > + smc_close_cleanup_listen(sk); > lock_sock(sk); > break; > case SMC_ACTIVE: