Article View: linux.kernel.netdev
Article #27567Re: [PATCH net] tcp: fix scheduler starvation in tcp_sendmsg_locked()
From: netdev-bot+sashiko
Date: Sun, 06 Dec 2026 02:13
Date: Sun, 06 Dec 2026 02:13
185 lines
14225 bytes
14225 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch adds an unconditional cond_resched() in
tcp_sendmsg_locked() (net/ipv4/tcp.c:1271).
- [Medium] The commit message puts the root cause in __release_sock():
its 16-skb cond_resched() counter is the local `int nb = 0`…
--
tcp: fix scheduler starvation in tcp_sendmsg_locked()
This patch adds a cond_resched() call at the existing 16-skb checkpoint in
tcp_sendmsg_locked(), right after sk_flush_backlog(). Without it, repeated
short backlog flushes on PREEMPT_NONE kernels never reach the cond_resched()
inside __release_sock(), and the CPU hits a soft lockup.
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 80de376a9d2ef..5b9e07db6ee26 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
[ ... ]
> @@ -1262,8 +1263,13 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> goto wait_for_space;
>
> if (unlikely(process_backlog >= 16)) {
> + bool restart_needed;
> +
> process_backlog = 0;
> - if (sk_flush_backlog(sk))
> + restart_needed = sk_flush_backlog(sk);
> + /* Check for rescheduling every 16 newly allocated skbs. */
> + cond_resched();
[Severity: High]
Is tcp_sendmsg_locked() always called from a context that can sleep? This
cond_resched() now runs every time process_backlog reaches 16, even when
sk_flush_backlog() found no backlog.
Some in-tree callers seem to reach tcp_sendmsg_locked() with BH disabled.
One is kTLS device offload from the RX softirq:
tcp_rcv_established()
tcp_check_space()
tcp_new_space()
sk->sk_write_space() == tls_write_space()
tls_device_write_space()
tls_push_partial_record()
tls_push_sg()
tcp_sendmsg_locked()
tls_device_write_space() switches to GFP_ATOMIC because it runs in that
context:
net/tls/tls_device.c:tls_device_write_space() {
...
sk->sk_allocation = GFP_ATOMIC;
tls_push_partial_record(sk, ctx,
MSG_DONTWAIT | MSG_NOSIGNAL |
MSG_SENDPAGE_DECRYPTED);
...
}
Another is ESP-in-TCP, reached from xfrm_trans_reinject() under
local_bh_disable() and rcu_read_lock():
xfrm_trans_reinject()
esp_output_tcp_finish() /* rcu_read_lock() + bh_lock_sock() */
espintcp_push_skb()
espintcp_sendskb_locked()
skb_send_sock_locked()
__skb_send_sock()
tcp_sendmsg_locked()
net/ipv6/esp6.c has the same code. espintcp_release() is also registered as
sk_prot->release_cb, and release_sock() calls it with sk_lock.slock held
through spin_lock_bh(). It pushes queued ESP skbs into tcp_sendmsg_locked()
as well.
Before this patch, the only scheduling point on these paths was inside
__release_sock(), which is reached through sk_flush_backlog(). The socket is
not user-owned in these contexts, so the backlog is empty and
sk_flush_backlog() returns false.
Now any single call that allocates 17 or more skbs reaches cond_resched().
A peer can cause that by advertising a small window, because
tcp_bound_to_half_wnd() limits size_goal to max_window/2. MSG_DONTWAIT
avoids the wait_for_space sleep but does not avoid this checkpoint.
With CONFIG_DEBUG_ATOMIC_SLEEP, will __might_resched() print "BUG: sleeping
function called from invalid context" here?
On !CONFIG_PREEMPTION kernels, should_resched(0) is false in softirq
context, so __cond_resched() falls through to rcu_all_qs():
kernel/sched/core.c:__cond_resched() {
if (should_resched(0) && !irqs_disabled()) {
preempt_schedule_common();
return 1;
}
...
#ifndef CONFIG_PREEMPT_RCU
rcu_all_qs();
#endif
return 0;
}
Could this report a quiescent state while still inside the rcu_read_lock()
sections held by xfrm_trans_reinject() and esp_output_tcp_finish(), or the
NET_RX softirq? If so, a grace period could end while objects such as the
RX skb's noref dst are still in use.
Would it be safer to call cond_resched() only when sk_flush_backlog()
returned true, or to move it into __sk_flush_backlog() after the unlock? A
non-empty backlog implies the socket is user-owned in process context.
> + if (restart_needed)
> goto restart;
> }
> first_skb = tcp_rtx_and_write_queues_empty(sk);
[Severity: Medium]
The commit message traces the root cause to __release_sock(), whose 16-skb
counter is local to each invocation:
net/core/sock.c:__release_sock() {
...
int nb = 0;
...
if (!(++nb & 15))
cond_resched();
...
}
The patch only changes one caller, tcp_sendmsg_locked(). Do other loops
that flush the backlog repeatedly still have the same gap?
tcp_recvmsg_locked() keeps looping while the backlog is non-empty, and it
calls __sk_flush_backlog() directly:
net/ipv4/tcp.c:tcp_recvmsg_locked() {
...
if (copied >= target && !READ_ONCE(sk->sk_backlog.tail))
break;
...
if (copied >= target) {
/* Do not sleep, just process backlog. */
__sk_flush_backlog(sk);
} else {
tcp_cleanup_rbuf(sk, copied);
err = sk_wait_data(sk, &timeo, last);
...
}
When copied < target, sk_wait_data() goes through sk_wait_event() and
release_sock()->__release_sock(), which resets nb again. If data has
already arrived, wait_woken() is skipped and only lock_sock() runs.
tls_rx_rec_wait() and tls_read_flush_backlog() in net/tls/tls_sw.c also
call sk_flush_backlog() inside receive loops.
None of these loops has its own cond_resched(). With a large len, could the
pattern the commit message describes ("Repeated calls that each consume a
short backlog can avoid cond_resched() indefinitely") also starve the
scheduler on the receive side?
Putting the cond_resched() in __sk_flush_backlog() after spin_unlock_bh()
would cover all of these callers. Could the commit message explain why a
fix in only this caller was chosen?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261205012134.1218271-1-tahsin%40meta.com
Technical Details
Message-ID:
<179652321690.3148.12264992033294773363@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378203-linux-kernel-netdev=dewy.ruReferences:
<20261205012134.1218271-1-tahsin@meta.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378203-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] tcp: fix scheduler starvation in tcp_sendmsg_locked() Date: Sun, 06 Dec 2026 02:13:36 +0000 Organization: Usenet Network Message-ID: <179652321690.3148.12264992033294773363@kernel.org> References: <20261205012134.1218271-1-tahsin@meta.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3166495"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:YmTDakbLi6sCF/uvy/YZWCblAic= sha256:e8NsMAFq0Bo9vSzNiaUaV9y3Tcz5QQ9a0K7eBTOb4cM= sha1:T2sBPY8rovfqN2nJArEu5Z6dTPI= sha256:AbBU4KCVo+87UN0XRtSggeNPKqltDEAab0zZD60+7To= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 53B70117F0C; Sun, 6 Dec 2026 05:13:58 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.54 X-Spam-Status: No, score=-3.54 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id baOqmsg0V4Hb; Sun, 6 Dec 2026 05:13:51 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-378203-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 93498116DD9; Sun, 6 Dec 2026 05:13:41 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 90BA5323C3; Sun, 6 Dec 2026 02:13:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796523219; b=PpDledEhQEhOvUalTxmF/RX9maYxU8r3AVlG3W/q05gtacIhwAuwcuaRFO7Yvf6uafX4 P50lW0ekQs5kCkNxF9tQvgbJwFvC1kN3kROSw/dWZ444ox67qV6UUUuTMA1PaC4JZPijq yQuuR238WYKbrFpjShyMOca/0bUNpxixTysjt5Vbwy2wKu3SU0b155EYeee4jpF9Muz12 rPDZIZEb41z2g2S8Zjto1YIWs3T8le8GOdKhkyjo/t4jLB9/pfvGykk2Cv0ZfySGuky34 SgRLHe47vqeeQxKgwwWz/hmsHi/AQdZz5em1ffqDufexXLiTCtJax8eYeuDcYsLuz+w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796523219; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=NpwBiY4foHKYKv8gugsLJREKTdzJjb12MjxiLVvoPBE=; b=AY8wE2FxAu6WCdDogm/U5HcHSe5m9AGPbeXfKkl6pI254NFuMuLKZtt+RyXCSDNM+YT1 0FcFbXmppsse4iHeXGoRNsLVdv5rbmGZ+q5d34+Ieq+Lj+6jmPZH/2WXz7o5u0kRtwwHT QGbiahFrBSRhVKCwUTUcKK4BY7Sa6Qckv+qSf6EYYQYf6rSoUMosyh7cEaWEFWL7Vayvl tREVygmla5sg9C8wxediT0Rb6bZBkWRYwmO02XXoY0VJYIgbjJgpEfmL+rfgythoe6KP9 zlm0hpk6+XfcXHhP2Teu/wO8Cl9eDggc7fb9Vwvv26YGR362vunz32JI4EugwN0xcbg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a0nJz+sm; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A3FC606A334; Sun, 6 Dec 2026 02:13:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a0nJz+sm X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796523218; b=q7M35VDVY2+xIqPlTqa9jAjrjZA17iGQKnKdTPKLISwD8Yqaw+iopXL/3bWq6cAUhJSP u+VUdJVUvMmdnGBuiB7pfB36WSXi/yoaaBN0t2Sscz7DbIImzQrDjczQEBrvt/msLxcvO 24rPbbDiB6DyCDn29OxbQizpX01CxT+71MHUMqRn9uas9Jpk3dd8AcnpsbLFrAI8PY9Pj QEeKByZZDrrjDgGPZjXsVVwxLyC6VlHuaSEiC6b3P8MQbNpW3Ps5amyDvOCy3pxy+hImc od23DVY277uYARQiWwrxrpaiYqNR1TDnfR37MO34af0+MSuR/ibMW/Gxy4g8SUPfjGA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796523218; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=NpwBiY4foHKYKv8gugsLJREKTdzJjb12MjxiLVvoPBE=; b=FEa6l7+9kf94SUnbdYWCFWYVYh1UyjOHocrJm6m6ZIaP/NQKqZY7hzk0uQYNdIUAfINA JS48HGEmFLAlUbmlRivs6eVmkgL0DnE1ES+0BvC2ovzzqXse8k6DDnOBqoxkLvsv9ioSd 2ydzfswxi04J1qmtaIXf/tjWRcTZbsZRNcIKW4JLlHtomkqNPkxFJrgCcxlooORyeLb/A feiXpNHEfS9NTKE+nVAd6SrFFRP0go6IWfKndWYFmXyhvfRk2pv8w9ekZYgvMTVL443rs RkkJdh2sWuL4xOaWaFGEl75Fk1peAJhAR0FHBOoacFzzrWG0x4fZDyeAy/4g0tnbZEw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a0nJz+sm; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87852606A321; Sun, 6 Dec 2026 02:13:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68E1B1F0092B; Sun, 6 Dec 2026 02:13:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796523218; bh=NpwBiY4foHKYKv8gugsLJREKTdzJjb12MjxiLVvoPBE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=a0nJz+smvPZUNe9WljMhJ3MOsCMCoS/5+1lVU3ORMx6FlCVbUqManhWhmt6ziUXyW OeY0KoP4QPO3BTGX3LPPUPVxeBF6N1PohRM7wG9Kj+tOWPBtPMIOo+X2KZEODZQWz2 yBhF3IOb/ml+QutMHWxW/Droq2i9XkcYDzSfMa/tkTXjCyhc1OBDBJ6Grq1HMVl+vd OToVro3hKQmzkrdVK0jjRXXajVsoL9KgQ9OIsuR21zo05H/1JCxDTFNxa8NMdiQ13k uOgB92/GpdHfbEsneyjjgfICxhT0ME6ovTALprxovSo6Ul4b4gEfd7+SfNPu073NZ6 0aBXno6wJTmjw== X-Cc: netdev@vger.kernel.org, edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, sgzhang@google.com, joe@dama.to, stable@vger.kernel.org X-In-Reply-To: <20261205012134.1218271-1-tahsin@meta.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list