From: netdev-bot+sashiko@kernel.org
To: edumazet@kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
kuniyu@google.com, ncardwell@google.com, horms@kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next] tcp: use order-0 page frags in tcp_collapse()
Date: Tue, 24 Nov 2026 16:27:37 +0000 [thread overview]
Message-ID: <179553765702.3135.10078888309251944054@kernel.org> (raw)
In-Reply-To: <20261123154708.360226-1-edumazet@kernel.org>
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] tcp: linear head in tcp_collapse() prevents
TCP_ZEROCOPY_RECEIVE
--
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -5983,34 +6034,47 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
> sub_end - start >= TCP_COLLAPSE_MAX_TOTAL_SIZE)
> goto skip;
>
> - /* Third, check if the new skbs have high density. */
> - nskbs = (sub_end - start) / TCP_COLLAPSE_MAX_SIZE;
> - new_truesize = nskbs * SKB_TRUESIZE(TCP_COLLAPSE_MAX_SIZE);
> -
> - remainder = (sub_end - start) % TCP_COLLAPSE_MAX_SIZE;
> - if (remainder) {
> - nskbs++;
> - new_truesize += skb_head_truesize(remainder, GFP_ATOMIC);
> - } else {
> - remainder = TCP_COLLAPSE_MAX_SIZE;
> - }
> + /* Third, check if the new skbs have high density.
> + *
> + * Payload is stored in order-0 page frags: one sk_buff can hold
> + * up to MAX_SKB_FRAGS pages, and truesize stays close to the
> + * payload size.
> + *
> + * What does not fill a page is stored in the linear part of
> + * the first new skb, unless a page is cheaper.
> + */
> + size = sub_end - start;
> + linear = size & ~PAGE_MASK;
> + if (linear > TCP_COLLAPSE_MAX_SIZE)
> + linear = 0;
> +
> + npages = DIV_ROUND_UP(size - linear, PAGE_SIZE);
> + new_truesize = skb_head_truesize(linear, GFP_ATOMIC) +
> + npages * PAGE_SIZE;
> + if (npages > MAX_SKB_FRAGS)
> + new_truesize += (DIV_ROUND_UP(npages, MAX_SKB_FRAGS) - 1) *
> + skb_head_truesize(0, GFP_ATOMIC);
>
> if (old_truesize <= new_truesize)
> goto skip;
>
> - while (nskbs--) {
> - nskb = alloc_skb(nskbs ? TCP_COLLAPSE_MAX_SIZE : remainder,
> - GFP_ATOMIC);
> + while (size > 0) {
> + int len = min_t(int, size - linear, MAX_SKB_FRAGS * PAGE_SIZE);
> +
> + nskb = tcp_collapse_alloc_skb(linear, len);
> if (!nskb)
> goto end;
>
> __skb_queue_tail(&pool, nskb);
> + size -= linear + len;
> + linear = 0;
> }
>
> while (before(start, sub_end)) {
> - int copy = min_t(int, TCP_COLLAPSE_MAX_SIZE, sub_end - start);
> + int copy;
>
> nskb = __skb_dequeue(&pool);
> + copy = nskb->len;
> memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
> TCP_SKB_CB(nskb)->has_rxtstamp = false;
> skb_copy_decrypted(nskb, skb);
[Severity: Medium]
The changelog says the collapsed page frags can be used by
TCP_ZEROCOPY_RECEIVE. Putting the sub-page remainder in the linear
part of the first new skb seems to defeat that for the whole skb.
When 1 <= linear <= TCP_COLLAPSE_MAX_SIZE, tcp_collapse_alloc_skb()
builds an skb with skb_headlen(nskb) == linear, followed by up to
MAX_SKB_FRAGS full pages.
In tcp_zerocopy_receive(), a read offset inside the head makes
skb_advance_to_frag() return NULL. The loop then breaks with nothing
mapped, and zc->recv_skip_hint is left at skb->len - offset. That is
the entire collapsed skb, not just skb_headlen(skb) - offset.
Without a copybuf, userspace is told to copy the whole skb. With a
copybuf, tcp_zc_handle_leftover() copies min(copybuf_len,
recv_skip_hint). That copy runs past the head into frags[0] and
leaves copied_seq at a non-zero offset_frag. Every later
TCP_ZEROCOPY_RECEIVE call on that skb then bails out on the
offset_frag check as well.
The tcp_rcv_collapse_bloated.pkt example from the changelog hits
exactly this case. 30000 bytes gives linear == 1328 ahead of the 7
pages, so none of those pages can be mapped. Any multi-page range
whose remainder fits in TCP_COLLAPSE_MAX_SIZE behaves the same way,
which is most of the non page-aligned ones.
This is not a regression compared to the old all-linear skbs. But
the zerocopy benefit claimed in the changelog mostly does not
materialise.
Would it be better to keep the remainder out of the head of a paged
skb? For example, it could go in a partially used last page frag, or
in its own small linear skb. That trades a little truesize for a
layout zerocopy can use. Or is zerocopy not a goal here, so the
changelog claim should be dropped?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123154708.360226-1-edumazet%40kernel.org
prev parent reply other threads:[~2026-11-24 16:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:47 [PATCH net-next] tcp: use order-0 page frags in tcp_collapse() Eric Dumazet
2026-11-24 16:27 ` 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=179553765702.3135.10078888309251944054@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=kuniyu@google.com \
--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