From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.145.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796556303; b=IK0eWxg+K4PyHchPqUIg7IDwXJ6scXZ4I0kePpzAPOfD0+OMW7aqPvjWBsdMuifxl/hA 94nC4pzlIw/zzIw3TRhFEmceRZxsc4T+2RKx2VOFQE8IFy0VM99JiO38M403gVXQBHvzR 03aXJpsDHRavRnMJKhhWw/Kak3vV0nFNc2tue9xfbiUMX7cJXlBxCuC/tmxly/WCO22ff tR3dXrqRI0Xu8hYD9/UxTet7mP5wFO6O5RtFjIgl9dwCdUJ3EVECHpxKT/dS/g02m9uve IhgeqMWEbsHmGzJaaobd6VpCtcHyPpUzna7W1Q4ep37+YDkcHW7uqk95NfZ5t/XG0xw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796556303; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Info:X-Proofpoint-GUID: X-Proofpoint-Virus-Version; bh=VfsolVH79Cm6N6y37RvWwxRxTDv1uR+T01nudIvHhLc=; b=1GWWbKG5xDpNoSVqW+/zfgZWHaY8eIOG/DfOcW19496ibLBVh0JN7/VRsaZFaUFsAM3g euLOYsTBqLtHtEwnUG9APo/rpnnCCDJ4RHJCteYcPa4sayd1dlfiAZfFKs7ZE4aGTVEMn bGZBDl6Gy9ymUqDoJUWSwE7TaOsG4CYq+lp79Y5SJ1LOvZdoRWpGbITONq+Ce0pwCiJ36 b2Rre9xLAyF+12KGseSCaBiFDqRIoMajZA8/VTHcE+dEysliB2eTQNFMrmmxLB2+YmxWM rD4ufZwjP++a+R4pyh5Yz4cJ3R1Yo7WXAfNjnR7vZ1Bgo4CUPNnwiY09JwqXe3jEISw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=G0vR7yj+; arc=none smtp.remote-ip=67.231.145.42 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 44089606A31F; Sun, 6 Dec 2026 11:25:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44089606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=G0vR7yj+ Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B6ALSOr1947738; Sun, 6 Dec 2026 03:24:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pps82601-s2048-2026-q3; bh=VfsolVH79 Cm6N6y37RvWwxRxTDv1uR+T01nudIvHhLc=; b=G0vR7yj+fvTegav7PsolprsUX 1Uw5YD50DsfPV0O8Kb8latW27D7mSkItgj6UBaBzOncgS/QQM2JAF/Yf07BfZWTU IH3esA4bqqAUB26TqdT33yIKzU1M+DvQiBsOHKyqq2+CALWjYQMQXE5eUJNfz/Jq 7GXCLaKSmt6UgB0iSJlt2VGHDGLZ/NL7iJX/4Wv44dgoqbmoge2cLjQc0I52C5er Hfydbsy/xIR+JAGTuFEoAE1npxEp4NyfNMgsq3SuLEjhi9RG/giRtSVnKdlVabKA 9XqV6Uis3RfhRR3IF+M36h7fwtcTQCX4gX2ZiwGlqWD+ztssl1EbgGwU2IaUg== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4jch61kjbt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 06 Dec 2026 03:24:55 -0800 (PST) Received: from localhost (2620:10d:c085:108::150d) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.57; Sun, 6 Dec 2026 11:24:54 +0000 From: Tahsin Erdogan To: CC: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Ray Zhang , Joe Damato , Subject: [PATCH net v2] tcp: fix scheduler starvation in tcp_sendmsg_locked() Date: Sun, 6 Dec 2026 03:24:32 -0800 Message-ID: <20261206112432.2391601-1-tahsin@meta.com> X-Mailer: git-send-email 2.56.1 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA2MDAzNiBTYWx0ZWRfX/iLiuHWSqMcx 5jmit3ADj6diQJ4ylll4SBB8J3N3nG8SvdpCIFu8JtzLdu+C7XteyfwvpKrrGXT+v8hz/Wkk54A lr+xMZDtuzsVO5mc5mM4ACrRlaMs7++MXmSQvZ+r5WO58kpZqBohArRb1woYEeHJE87xcPr7XDt k+bf2kC2VefUXM8XSvNI96t1MF5JrnQO+Nwa2vOTTeWzyfPtkjAPeJOk8h0cI2h7rNQ91q8DWMl /DHU6C8fLkqnIzLU/FGV3/8zGoGBCA3hRnsw8mcuALKqzcAkhZf4SvgypikVqOx47gST+Ku/bQL n920dVlDuzBY7V4BpFIAMstCXFWBo53X6Z16DnjNCQ354jDzxGKafn1awx0uAIQBqyqH1lXRX86 B0xLucAmdGmB9WMHs8Obqgeac4vcMI1ZzG/DBQq/qeTXieSk4236PyTgUODzubrmEUnKmQ/ku/Y vU4SIkGddqUUe9B0TwQ== X-Proofpoint-ORIG-GUID: dU_CdV0YVjvrSqhArTlAh_8GTMhyuTn_ X-Authority-Analysis: v=2.4 cv=aoQnmiZV c=1 sm=1 tr=0 ts=6b154607 cx=c_pps a=CB4LiSf2rd0gKozIdrpkBw==:117 a=CB4LiSf2rd0gKozIdrpkBw==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=PAz_-FQ8hEVmOPYdF0yf:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8 a=ri9ty9hU3IgYE5wOy2wA:9 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA2MDAzNiBTYWx0ZWRfX+XwmW259v+Ed NTi0vO/Sqb23V/ZZafGaljVJ9HPsSOQAMVVv0vSoKaYdqGEh9Of2VfTnikQs6lQpZhkZxEahWZt Nm4HCELlYa+q76v7HITbMApCGy+A0nY= X-Proofpoint-GUID: dU_CdV0YVjvrSqhArTlAh_8GTMhyuTn_ 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-06_03,2026-12-03_04,2025-10-01_01 On a non-preemptible kernel, a large TCP send can keep a CPU executing within tcp_sendmsg_locked() long enough to trigger the soft-lockup watchdog: watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [repro:139] Call trace: skb_free_head ... virtnet_poll_tx __napi_poll net_rx_action handle_softirqs ... __local_bh_enable_ip __release_sock __sk_flush_backlog tcp_sendmsg_locked tcp_sendmsg ... __sys_sendto Every 16 newly allocated SKBs, tcp_sendmsg_locked() calls sk_flush_backlog(). Incoming ACKs processed there release enough send memory for the send loop to continue, but flushing the backlog does not guarantee a scheduling point. Commit 16c610162d1f ("net: call cond_resched() less often in __release_sock()") reduced the cond_resched() checks from every backlog SKB to once every 16 SKBs, but left two gaps. First, the final SKB of each backlog pass was not counted. A pass containing a single SKB therefore did not advance the counter. Second, the counter was local to one __release_sock() invocation, so separate invocations that each processed fewer than 16 counted SKBs could not call cond_resched(). Commit c4e4056b2135 ("net: count last skb of each sk_backlog pass in __release_sock()") fixed the first gap by counting every SKB across all passes within one invocation. However, the counter still resets between separate sk_flush_backlog() calls. If each call processes fewer than 16 SKBs, none reaches the 16-SKB count needed to call cond_resched(). Repeated calls that each consume a short backlog can avoid cond_resched() indefinitely. Fix this in __release_sock() by calling cond_resched() at least once for every non-empty invocation without restoring the old per-SKB frequency. If the first backlog batch contains fewer than 16 SKBs, call cond_resched() when that batch ends and use its SKB count to space subsequent calls 16 SKBs apart. Keeping this policy in __release_sock() covers all backlog-draining callers and keeps cond_resched() at the existing point where the socket spinlock is released and bottom halves are enabled. We have observed this soft lockup repeatedly in production and reproduced it on demand on arm64 hardware. It is also reproducible on v6.18.66 with CONFIG_PREEMPT_NONE in an arm64 QEMU guest using two TCP connections over separate virtio NICs. A single 1.5 GiB send runs on CPU 0 while the second connection continuously sends from CPU 1. RX interrupts for both NICs are delivered to CPU 0, and the QEMU peers ACK every received segment. The watchdog reports CPU 0 stuck for 22 seconds, with 84-85% of its time spent in softirq context. Since v6.18.66 includes the backlog-pass fix, this confirms that fix alone does not prevent the lockup. With this change, the 1.5 GiB send completes without triggering the watchdog. PREEMPT_NONE is unavailable on arm64 starting with v7.0, so this arm64 reproducer does not apply to current upstream. The fix remains relevant to affected stable branches. Fixes: 16c610162d1f ("net: call cond_resched() less often in __release_sock()") Cc: stable@vger.kernel.org Signed-off-by: Tahsin Erdogan --- v2: - move the fix to __release_sock(), avoiding cond_resched() from BH-disabled tcp_sendmsg_locked() callers - guarantee at least one call per non-empty invocation, then space subsequent calls 16 SKBs apart - update the commit message to describe the new policy v1: https://lore.kernel.org/netdev/20261205012134.1218271-1-tahsin@meta.com/ net/core/sock.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/net/core/sock.c b/net/core/sock.c index 5ed63d2d8976..8dfe80ed7f6c 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3334,8 +3334,12 @@ void __release_sock(struct sock *sk) __acquires(&sk->sk_lock.slock) { struct sk_buff *skb, *next; + int last_resched_nb = 0; int nb = 0; + /* Call cond_resched() at least once per non-empty backlog drain. + * Space subsequent calls 16 SKBs apart. + */ while ((skb = sk->sk_backlog.head) != NULL) { sk->sk_backlog.head = sk->sk_backlog.tail = NULL; @@ -3350,10 +3354,22 @@ void __release_sock(struct sock *sk) skb = next; - if (!(++nb & 15)) + if (++nb - last_resched_nb == 16) { cond_resched(); + last_resched_nb = nb; + } } while (skb); + if (!last_resched_nb) { + /* The first batch had fewer than 16 SKBs, so + * cond_resched() was not called. Call it now to ensure + * at least one call, even if the backlog is not + * refilled. + */ + cond_resched(); + last_resched_nb = nb; + } + spin_lock_bh(&sk->sk_lock.slock); } base-commit: 6902a2bb708c4075d3de6ec18ab6a5864c4c1aa2 -- 2.56.1