Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: kuniyu@google.com
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
Subject: Re: [PATCH v3 net-next 5/7] tcp: Allocate all new skb before collapsing.
Date: Sat, 21 Nov 2026 18:48:49 +0000	[thread overview]
Message-ID: <179528692954.3135.2145920714638368553@kernel.org> (raw)
In-Reply-To: <20261119071649.374106-6-kuniyu@google.com>

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

  parent reply	other threads:[~2026-11-21 18:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:15 [PATCH v3 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue Kuniyuki Iwashima
2026-11-19  7:15 ` [PATCH v3 net-next 1/7] tcp: Refactor the first loop in tcp_collapse() Kuniyuki Iwashima
2026-11-21 18:48   ` netdev-bot+sashiko
2026-11-19  7:15 ` [PATCH v3 net-next 2/7] tcp: Don't collapse high density skb Kuniyuki Iwashima
2026-11-19  7:15 ` [PATCH v3 net-next 3/7] tcp: Stop collapsing if not bloated Kuniyuki Iwashima
2026-11-19  7:39   ` Eric Dumazet
2026-11-20 14:58   ` Matthieu Baerts
2026-11-21 18:48   ` netdev-bot+sashiko
2026-11-19  7:15 ` [PATCH v3 net-next 4/7] tcp: Skip collapsing if collapsed skb is less-dense Kuniyuki Iwashima
2026-11-19  7:41   ` Eric Dumazet
2026-11-19  7:15 ` [PATCH v3 net-next 5/7] tcp: Allocate all new skb before collapsing Kuniyuki Iwashima
2026-11-19  7:44   ` Eric Dumazet
2026-11-19 20:02     ` Kuniyuki Iwashima
2026-11-21 18:48   ` netdev-bot+sashiko [this message]
2026-11-19  7:15 ` [PATCH v3 net-next 6/7] tcp: Batch memory accounting in tcp_collapse() Kuniyuki Iwashima
2026-11-19  7:15 ` [PATCH v3 net-next 7/7] selftest: packetdrill: Add test for tcp_collapse() Kuniyuki Iwashima
2026-11-19  7:45   ` Eric Dumazet
2026-11-21 19:00 ` [PATCH v3 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179528692954.3135.2145920714638368553@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@google.com \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox