🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20189

Re: [PATCH v3 net-next 5/7] tcp: Allocate all new skb before collapsing.

#20189
From: netdev-bot+sashiko
Date: Sat, 21 Nov 2026 18:48
112 lines
12336 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · 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).

- [Medium] In tcp_collapse() (net/ipv4/tcp_input.c), the new
  TCP_COLLAPSE_MAX_TOTAL_SIZE overlap check throws away the whole…

--

tcp: Allocate all new skb before collapsing.

This commit changes tcp_collapse() to preallocate every new skb for a
sub-range into a temporary pool before copying. An alloc_skb() failure
then no longer leaves partially collapsed duplicates in the queue. To
bound that preallocation, the sub-range is capped at
TCP_COLLAPSE_MAX_TOTAL_SIZE, except when the range is a single first skb.
Overlapping OOO ranges that go over the cap are skipped.

> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 27ed9ba11ec9c..990e348963734 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -5822,6 +5822,11 @@ static struct sk_buff *tcp_skb_next(struct sk_buff *skb, struct sk_buff_head *li
>  #define TCP_COLLAPSE_SCALING_RATIO				\
>  	((TCP_COLLAPSE_MAX_SIZE << TCP_RMEM_TO_WIN_SCALE) /	\
>  	 (SKB_TRUESIZE(TCP_COLLAPSE_MAX_SIZE)))
> +/* Cap pool preallocation per sub-range to at most 16 skbs in seq
> + * space.  A single first skb exceeding this is still collapsed,
> + * whereas an exceeding overlapping ofo range is skipped.
> + */
> +#define TCP_COLLAPSE_MAX_TOTAL_SIZE (TCP_COLLAPSE_MAX_SIZE * 16)
>  
>  static bool tcp_collapse_skb_bloated(const struct sk_buff *skb,
>  				     u32 start, u8 scaling_ratio)

[ ... ]

> @@ -5926,8 +5933,9 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>  		}
>  
>  		if (!overlap &&
> -		    !tcp_collapse_skb_bloated(n, sub_end,
> -					      TCP_COLLAPSE_SCALING_RATIO))
> +		    (TCP_SKB_CB(n)->end_seq - start >= TCP_COLLAPSE_MAX_TOTAL_SIZE ||
> +		     !tcp_collapse_skb_bloated(n, sub_end,
> +					       TCP_COLLAPSE_SCALING_RATIO)))
>  			break;
>  
>  		sub_end = TCP_SKB_CB(n)->end_seq;
> @@ -5935,25 +5943,38 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>  		n = tcp_skb_next(n, list);
>  	}
>  
> +	if (sub_end != TCP_SKB_CB(skb)->end_seq &&
> +	    sub_end - start >= TCP_COLLAPSE_MAX_TOTAL_SIZE)
> +		goto skip;

[Severity: Medium]
Does this goto skip discard the whole [start, sub_end) range in
tcp_collapse()? That would include the bloated non-overlapping skbs
gathered before the overlapping one.

In the second loop, the new size cap is only checked when overlap is
false. An OOO skb where

    overlap = !list && before(TCP_SKB_CB(n)->seq, sub_end);

is true gets added to sub_end with no size check. If that pushes
sub_end - start past TCP_COLLAPSE_MAX_TOTAL_SIZE, skip sets
start = sub_end and skb = n. None of the earlier skbs get collapsed,
even though they were collapsed before this patch.

Would it work to collapse only the prefix and stop before the skb that
the overlapping one overlaps? tcp_data_queue_ofo() inserts a partial
overlap after its predecessor, so the rbtree ordering should still hold.

TCP_COLLAPSE_MAX_TOTAL_SIZE is 16 * SKB_MAX_ORDER(0, 0). With 4 KiB pages
that is 60416 bytes of sequence space, which is less than one 64 KB
GRO/TSO skb. Can a single overlapping retransmit that was re-segmented
or GRO-aggregated trigger this?

As an example, take contiguous bloated OOO skbs A1..A15 (about 22 KB),
followed by B, which partially overlaps A15 and extends about 40 KB
further.

Before this patch the range is collapsed, saving roughly 16 KB of
truesize. After it, nothing is collapsed, and the same thing happens on
every prune while B stays queued. tcp_prune_queue() then falls back to
tcp_prune_ofo_queue(), which drops OOO data.

The commit message says:

    Legitimate overlaps (retransmits with a different segmentation)
    only involve a few skbs, so if an overlapping OOO chain reaches
    the limit, we simply skip it.

Is this accurate, given that the check counts bytes and not skbs? The
message also doesn't mention that the non-overlapping skbs before the
overlap are skipped as well.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119071649.374106-1-kuniyu%40google.com
Technical Details
Message-ID: <179528692954.3135.2145920714638368553@kernel.org>
Path: mbox-mo1.pugleaf.net!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-368405-linux-kernel-netdev=dewy.ru
References: <20261119071649.374106-6-kuniyu@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!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-368405-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v3 net-next 5/7] tcp: Allocate all new skb before collapsing.
Date: Sat, 21 Nov 2026 18:48:49 +0000
Organization: Usenet Network
Message-ID: <179528692954.3135.2145920714638368553@kernel.org>
References: <20261119071649.374106-6-kuniyu@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3469013"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lpNUoQhFm1BTlPOxMPe9ipFu5cI= sha256:oStYRMEW1tN9dW6BPxnv1dn35HxoBiW+lXNpusbgQUs=
	sha1:40rlwASLRWDdUDP40+sZaHRtO/0= sha256:uFcGawLq0TixOxGdsz9Hup3/0KJcfKmIn3EQKlPAl6A=
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 915A1115BB7; Sat, 21 Nov 2026 21:49:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 ZPxYqSDm9-E0;
	Sat, 21 Nov 2026 21:49:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368405-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 A198E115B7A; Sat, 21 Nov 2026 21:48:56 +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 D33FA3B807; Sat, 21 Nov 2026 18:48:51 +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=1795286931;
	b=A4OqN3uCQz0NgsWa3a2q4/PICE9lePmOze/FgSDkqsnKA1DWmwqFT6G6VzQT+fuaSx6w
	 7FopEktcZQ4NiMKRVr93kGOo9zdRfBanggHyp7Y6X5jP3rez2Z/Kn8b1QN9aifU817B/m
	 SrCHE2e/Nt2mQSI7ywSbeWZ4MiqK/MOztv2+QvD7TxOwLyd/T+LZDEPXis3bj9U4/YxWN
	 qXWcY8dKsbrtsfgoCBSFYGjpn65w/rhVl5iyspq84z7D+KlRtF748PM4kOzpy6PW95dTL
	 r0eYGArq2Q+wtqAIOCWG4kzYC4afmr0k87B6y/jolcYIPoCMl9AZOitySG4v2cUWD2Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795286931;
	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=16lpQsPZNjjC3ijLF2uUeyUfA1Z8rss5BZS9YEea6oI=;
	b=2yXGNgvX5XwWxQYtGOZGJp70Ww+A0oAdkcIMPICL5bKYyhBWeEIOaYSVJ3kKmC8XDQcv
	 pY2KiX8NbrBhYF3TTXrt6NlqiA6n69pFiPCq95Df6/UD+nRwQSUgCM3pEFQe0t2nDtgQ+
	 LgQhB59EVUM1GTXMLE9vV0EH1Hn7iIecHryce1rKm3BUMKOnNlMe7J9uONQ4bhfqHZRlj
	 +1zFOv4sMHne+ijx1I9tjqjz7+feDGXc0ZQvCF9IyjvNXSQgQZb3qREK6d59unJUFcfau
	 bMWJzSjonMFtuK1tFooGqGPbsBZpg/60nxqKMw7jFpeAsdgfSmznOXYsvOvxLApIzfA==
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=oh5HrPqG;
	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 AABA2606A335;
	Sat, 21 Nov 2026 18:48:51 +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=oh5HrPqG
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=1795286930;
	b=r7mL5/s4iGS/2UJOJThoA++9GXvsqgm7YrWV65sEFi3Xe95GKVdDGnszc27DvRSRVBNu
	 ++h5oXILXA2OW6P0Uw95mQmkc2ntDlDplHRdtie9ywwFrc8ZvHY7a/UUHhfNuo8TRY6af
	 XXjA0oW/TkFdHZfSGqR3KUc2nrglNo8C2BEPOmdL/MN4VEbZFvUVq8I4wvBKWEIw/y5JC
	 5pYABmZMtrVQ6VQeg4FdMTFLO4sfjeQf4/PNdolo0txvkko0xxUOZoSENbMn6wPKNO2+N
	 c46ZgM5nB6FbHlVSRhbd0zcO4rSTc1AH2SBDL4S8jtpIhf1W1hkFDVZAzvd04a4xjqA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795286930;
	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=16lpQsPZNjjC3ijLF2uUeyUfA1Z8rss5BZS9YEea6oI=;
	b=KBpDeabRtad8rfuGsrIJxm4zVcMn34poqM7doRmNd34rKW6JmTUGs9fgttvSvRXoSBRy
	 oAjze8cRcCBEpxNdRm+457HVby6LIrQUkgwp2FJ7vR0YAqUJ2sd4gBDnimg3bCQ7h13xP
	 efi2LHx3lrcEj9kgUTSHBBTsPwAXspx2DGyUJeqJ2xqQpSb3h7+HCCN3TdFTgMgdsXXH9
	 a7uhOBdGNP+hwJ9fpHAkBVb+rzTMGlAdPMjKzdQo51QT8Dwx35VhGhxQ3KW/4sFTxuUGV
	 St5x02+/DkGWP7wu3d2GfRspMk262w+JsJWVrfcxcTVLQzc+GleYvSkUU7TrChroa6A==
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=oh5HrPqG;
	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 CC4E0606A331;
	Sat, 21 Nov 2026 18:48:50 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 006491F000C6;
	Sat, 21 Nov 2026 18:48:49 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795286930;
	bh=16lpQsPZNjjC3ijLF2uUeyUfA1Z8rss5BZS9YEea6oI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=oh5HrPqGRkyO7ppJt6h4uSXlrvmNrWHNchgqdd6z6gxcKAeBPxGpJJyaFE2exta+c
	 8+Q1E8EcmvWswkOCt4RtRHKWOL0uja/zXXE2A0aKMuMlaBB+16sxSGI8Txwyuu6ytY
	 CdijdiMLqAWDs0g9B67aKg8C5r2T2qOzAnqs3BA9R7o0tFSq9LOc54Yj5n7DWkaeOr
	 Ex2YbDX4fI+VKowl9EldRvcTFFTW5p30eXeoscGmU4Oy4EZsXoPP7k5CMLy3MLhpx2
	 OG7jy5sFRh8hgLzo38Fstay8YIYP7uiurNCExNBP2fOoSHpSy9xe3jrYNzhRjW99Wt
	 qKu4PEbt+A3Bg==
X-Cc: edumazet@kernel.org, ncardwell@google.com, davem@davemloft.net,
 kuba@kernel.org, pabeni@redhat.com, matttbe@kernel.org, martineau@kernel.org,
 horms@kernel.org, kuni1840@gmail.com, netdev@vger.kernel.org,
 mptcp@lists.linux.dev
X-In-Reply-To: <20261119071649.374106-6-kuniyu@google.com>
X-sashiko-severity: Medium
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