Article View: linux.kernel.netdev
Article #13340[PATCH v2 net] tcp: cubic: avoid looping in bictcp_update() TCP friendliness code
From: Eric Dumazet
Date: Mon, 09 Nov 2026 17:23
Date: Mon, 09 Nov 2026 17:23
58 lines
9500 bytes
9500 bytes
The TCP friendliness part of bictcp_update() does:
delta = (cwnd * scale) >> 3;
while (ca->ack_cnt > delta) {
ca->ack_cnt -= delta;
ca->tcp_cwnd++;
}
A BPF congestion control can store any value in tp->snd_cwnd,
tp->snd_ssthresh and icsk_ca_priv, then call the cubictcp_cong_avoid()
kfunc or switch the socket to CUBIC. A zero delta (or a huge ack_cnt)
then hangs the CPU in ACK processing.
Make sure delta is at least 1, and replace the loop with a division,
done only when ack_cnt > delta (at most about once per RTT).
Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/netdev/179363987528.3131.2987776489427079887@kernel.org/
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
v2: fix the loop itself instead of sanitizing snd_cwnd at entry points.
v1: https://lore.kernel.org/netdev/20261106133748.2181133-1-edumazet@kernel.org/
Discovered by an AI code review agent (Sashiko), confirmed by
code inspection only, not triggered.
net/ipv4/tcp_cubic.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
index a88e4bf86150f06eb3c0d3da99761e5d45c8f6a3..e74dabde34324d4d4764afda7022fafcdbcecbfe 100644
--- a/net/ipv4/tcp_cubic.c
+++ b/net/ipv4/tcp_cubic.c
@@ -298,10 +298,16 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd, u32 acked)
if (tcp_friendliness) {
u32 scale = beta_scale;
- delta = (cwnd * scale) >> 3;
- while (ca->ack_cnt > delta) { /* update tcp cwnd */
- ca->ack_cnt -= delta;
- ca->tcp_cwnd++;
+ /* BPF congestion controls can call us with any cwnd
+ * and ack_cnt: cwnd * scale can wrap and give a zero delta,
+ * and a loop could run up to 2^32 times.
+ */
+ delta = max((cwnd * scale) >> 3, 1U);
+ if (ca->ack_cnt > delta) { /* update tcp cwnd */
+ u32 n = (ca->ack_cnt - 1) / delta;
+
+ ca->ack_cnt -= n * delta;
+ ca->tcp_cwnd += n;
}
if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */
--
2.53.0
Technical Details
Message-ID:
<20261109172356.3113732-1-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359481-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359481-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH v2 net] tcp: cubic: avoid looping in bictcp_update() TCP friendliness code Date: Mon, 9 Nov 2026 18:23:56 +0100 Organization: Usenet Network Message-ID: <20261109172356.3113732-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="410750"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:GYNj02fFU7R/zGcpMmfHFmSk1IA= sha256:tEYPotp8GT8FWukvBYqyRte4xVNCUhy2xgUTzJdpvew= sha1:FnN2ZR5jMDsxGEJaSttOorkzqsg= sha256:664C9eYCV0hno4L94DIeyRkY3cgqg6pq7dx2xlGrrEU= 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 0A8131138B1; Mon, 9 Nov 2026 20:25:31 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, 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 XAuqaGM1bEfE; Mon, 9 Nov 2026 20:25:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-359481-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 793551138A6; Mon, 9 Nov 2026 20:25:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 9D491608C0E; Mon, 9 Nov 2026 17:24:02 +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=1794245041; b=H54HKRRDImkUiXHPPs5HdchI9dKnqY+5mkg578YXq7NuAIG34iy8sbFZjti4kB05pSqm QKSCFP0erH0Iry93QKa17IadMBobixi4J2Uc6gH9spzqzIv2oL69T+9aGOO2LdJPkW77S Or8sCmQ10cp//Ahw9Eqsyj3xWkSew1Tlhl1k2iB2VZn0JIGVgw0AH4MudyT38G0bLhIVm yKD4pE/VEM1Qgas/gLFB+HMKyLrldDKnxOn4emPdi+hgexFrNBXI6+tKRYaE9eL/P7l5f CZmEKvg7LPxwvufzMhGLVBak7Fi5rHl7R78NdgeC8xaEgcuIqjdYCjbLi8kkWYSm86w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794245041; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=SkI4TIX22rtuyPPaLwG1CdpRN3yueyM1ryT+FhQmelE=; b=Zie9TRd5yRQFp3sh6Uiy2Duqd0tZleAGssqJ9X2wU6j8XINkoavM8jQMpn+eSvqwP0yf fHmPGp1/61mJrr/n3zIlcHMqdFrJ1sgevZDOhBOvSAaANg1Jg5smU2HzJvHEiWl+B29/j fcjyfjRSbVDUA5PCOI41r8rY/pVps/lZbhpzPnLk0vrU0xNTHUVio9hpUFLH3K6D/aTUU Fd5rekaOwKhwf6/uFZODwZugZnM8vrzDEj6pHlQ0yN0ps64bJS+wB8KxtLW7JTVoaorcS 91DQDg64UygAYCBYC48L5gGLfO1gpQwYYArOEW13T3wSS75X+kFMFOc39UN4Utg6qGg== 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=P6VmrDH+; 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 9906D606A331; Mon, 9 Nov 2026 17:24:01 +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=P6VmrDH+ 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=1794245040; b=O82RLd9wZuksvqC8ScSLaJ7s/V26jVzLPA8Y4rDUkdyUV3LyGdzEUTdiiO42Y1X5FM8O 5FK4PK1fP2gQMy8aAQ9WOCaTgCoVf/TAEuzqjPTVb9GpQY6Dok4cowaVYXFhph4pCsZ9y W7YHsoidQD2g2pBTBh5C0ZQHEb05E+2GBSFIkEm1ingNKWqQKq0g83d2Q18ZCvvYoorK/ UZmPfmOvWBdpIe8D0oZjLmGJ0vmdIbQJsvBlw+d6E8JXqNdbRofFoq65x30xNuMulFGKf mz8GHSNCGpICAsRhRH61nR9jZfGO2WxPoN0LvdDkKtvND5m+gDItoJT4plJcQNMcNvA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794245040; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=SkI4TIX22rtuyPPaLwG1CdpRN3yueyM1ryT+FhQmelE=; b=YarabVbgIk2s1dPMsGLVbBlypOHC8bdYRd5cu56dlQMGqUMqLP2PgCwjF3sCGDuSiVXu NJ//wjyfHRPMFWZLEEJDBBgzeZx0QObq4+pILVOIxvvbu+oj82Cz4S+NomaTlQ3olNuzq KaAhwPJQ3K8JJxwWyisdpgWK0Uv2jNxvHOW7+5kTJQN5oYSAseQSa46O0tT80wiXJg126 RWoNdq8Q2r/y4TIMvsLs8sWbGaPmGpWqAlfNyZoZZBbQa1MctitGd/rrEHIbCIK4Ay3i5 5rfXCwH9cgUlcrcnY9IcnHcgKO2OAGFLdRTR5Yf+3NLDXAyuUj7klbPg4qUZebl0R4Q== 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=P6VmrDH+; 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 7AE64606A31C for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 17:24:00 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07C171F0089F; Mon, 9 Nov 2026 17:23:57 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794245040; bh=SkI4TIX22rtuyPPaLwG1CdpRN3yueyM1ryT+FhQmelE=; h=From:To:Cc:Subject:Date; b=P6VmrDH+k0vJlsN7oWARydBIiKOfMGwtm5z/w69iy6JOmqDVeFeGPeGNEqkSjRqt2 CfcNbSSRaBCF89m/HLiNVIGIy5++fTz5fVrKWq7HW8nNnfZ7Mdo/9mDvBsnTEyprH3 Ff4bawYp8+eK2A6eAoBkExmq8dsXUZmgw4oAIQp5HvqIaX+PTtM3qKmOHmZ2f+VZXB WuBoUCU75C+OIRQpe+4xDddxuqp8hRDI7tzCfI1iAfKtYszsmWi31buUzE2uSFBRAE sRk8mQE5PpxEn4t8tm+NYd8Su+CUP3RhjyZpdAj1wLS28JJbJAj1vfvUGWCKYL04DC aN+AiSTVNrBXg== X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>, Sashiko <sashiko-bot@kernel.org> X-Mailer: git-send-email 2.53.0 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