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 v2 net-next 7/7] selftest: packetdrill: Add test for tcp_collapse().
Date: Tue, 17 Nov 2026 23:13:43 +0000	[thread overview]
Message-ID: <179495722334.3136.9959346022100767379@kernel.org> (raw)
In-Reply-To: <20261116230555.2305867-8-kuniyu@google.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] tcp_rcv_collapse_bloated.pkt cannot catch a regression in the
  high-density/unread-bytes check, tcp_collapse_skb_bloated(), even…
- [Low] The last step of tcp_rcv_collapse_bloated.pkt claims to 'verify
  data integrity', but `read(4, ..., 300000) = 279900` only checks the…

--

selftest: packetdrill: Add test for tcp_collapse().

This adds a packetdrill test, tcp_rcv_collapse_bloated.pkt. It queues a
mix of high-density and low-density skbs, shrinks SO_RCVBUF to trigger
tcp_prune_queue()->tcp_collapse(), and then checks TcpExtTCPRcvCollapsed
to confirm that exactly 30 skbs were collapsed. It also changes
ksft_runner.sh to skip any script whose PAGE_SIZE define does not match
getconf PAGESIZE.

> diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse_bloated.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse_bloated.pkt
> new file mode 100644
> index 0000000000000..90e8be86968f8
> --- /dev/null
> +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse_bloated.pkt
> @@ -0,0 +1,135 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Test that tcp_collapse() only collapses bloated skb runs, skips leading
> +// and trailing high-density skbs, skips isolated bloated skbs when collapsing
> +// them would not shrink truesize, and properly recovers receive buffer space.

[ ... ]

> +// 1. Queue two high-density 62,000 B segments (each adds 15 pages of frag
> +// truesize with enough margin across NET_SKB_PAD, L1_CACHE_BYTES, and
> +// MAX_SKB_FRAGS configs).
> +// Read 100 bytes from the first one so before(skb->seq, tp->copied_seq) is true.
> +   +0 < P. 1:62001(62000) ack 1 win 65535
> +    * > .  1:1(0) ack 62001
> +   +0 read(4, ..., 100) = 100

[Severity: Low]
Can this test catch a regression in the density check itself?

The header comment says the test checks that tcp_collapse() skips
leading and trailing high-density skbs. The partial read here is meant to
cover the copied_seq case. However, every high-density skb is 62,000 B.
That is already larger than TCP_COLLAPSE_MAX_TOTAL_SIZE, which is
16 * 3776 = 60416 on 4K pages.

Because of this, two other checks in tcp_collapse() settle the outcome
for these skbs, whatever tcp_collapse_skb_bloated() returns. First, the
second loop stops any run from extending into a 62,000 B skb:

net/ipv4/tcp_input.c:tcp_collapse() {
    ...
		if ((list || !before(TCP_SKB_CB(n)->seq, sub_end)) &&
		    (TCP_SKB_CB(n)->end_seq - start >= TCP_COLLAPSE_MAX_TOTAL_SIZE ||
		     !tcp_collapse_skb_bloated(n, sub_end,
					       TCP_COLLAPSE_SCALING_RATIO)))
			break;
    ...
}

Second, the truesize comparison always skips a single 62,000 B skb:

	if (old_truesize <= new_truesize) {
		start = sub_end;
		skb = n;
		goto restart;
	}

Here new_truesize = 16 * SKB_TRUESIZE(3776) + compute_skb_truesize(~1.5K)
= 69632 + 2304 = 71936. That is above the roughly 65792 truesize implied
by the rmem figures in the test.

If tcp_collapse_skb_bloated() is forced to always return true, the walk
over the queue looks like this:

  skb1 (start = copied_seq = 101): breaks at skb2 because
      124001 - 101 >= 60416, then the truesize check skips it
  skb2: breaks at the isolated skb (63000 >= 60416), then skipped
  isolated skb: breaks at skb3 (63000 >= 60416); old 2304 <= new
      compute_skb_truesize(1000) = 2304, so skipped
  skb3: breaks at the first small skb, then skipped
  30-skb run: collapses, then breaks at the trailing skb
      (92000 >= 60416)
  trailing skb: the truesize check skips it

That still gives exactly 30 for TcpExtTCPRcvCollapsed, so the test
passes. It would also pass if the old before(TCP_SKB_CB(skb)->seq, start)
trigger came back in the first loop. In this test, the
!tcp_collapse_skb_bloated() break in the second loop never ends a run.

The test does catch the pre-series behaviour. But would a later
regression in tcp_collapse_skb_bloated(), or in the copied_seq-based
unread computation, pass this test unnoticed?

One option is to use high-density skbs small enough that a run stays
under TCP_COLLAPSE_MAX_TOTAL_SIZE, and where collapsing them would reduce
truesize. Then the density check would be what decides the outcome.

[ ... ]

> +// Read all remaining queued data to verify data integrity.
> +   +0 read(4, ..., 300000) = 279900

[Severity: Low]
Does this read() actually verify data integrity? With the "..." buffer
form, packetdrill only checks the return value. The injected payloads are
also all identical zero-filled bytes.

Suppose the copy loop in tcp_collapse() used the wrong offset or source
skb:

			int offset = start - TCP_SKB_CB(skb)->seq;
			...
				if (skb_copy_bits(skb, offset, skb_put(nskb, size), size))

or reordered bytes inside the collapsed range. read() would still return
279900, and the test would pass.

Should the comment say that this step only checks the byte count? Or
could the test send non-uniform payloads and verify their contents?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116230555.2305867-1-kuniyu%40google.com

      reply	other threads:[~2026-11-17 23:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 23:05 [PATCH v2 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 1/7] tcp: Refactor the first loop in tcp_collapse() Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 2/7] tcp: Don't collapse high density skb Kuniyuki Iwashima
2026-11-17 23:13   ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 3/7] tcp: Stop collapsing if not bloated Kuniyuki Iwashima
2026-11-17 23:13   ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 4/7] tcp: Skip collapsing if collapsed skb is less-dense Kuniyuki Iwashima
2026-11-17 23:13   ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 5/7] tcp: Allocate all new skb before collapsing Kuniyuki Iwashima
2026-11-17 23:13   ` netdev-bot+sashiko
2026-11-16 23:05 ` [PATCH v2 net-next 6/7] tcp: Batch memory accounting in tcp_collapse() Kuniyuki Iwashima
2026-11-16 23:05 ` [PATCH v2 net-next 7/7] selftest: packetdrill: Add test for tcp_collapse() Kuniyuki Iwashima
2026-11-17 23:13   ` netdev-bot+sashiko [this message]

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=179495722334.3136.9959346022100767379@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