From: netdev-bot+sashiko@kernel.org
To: edumazet@kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
willemb@google.com, kuniyu@google.com, horms@kernel.org,
netdev@vger.kernel.org, jiayuan.chen@linux.dev
Subject: Re: [PATCH net-next] net: do not over-estimate truesize in zerocopy_fill_skb_from_iter()
Date: Sat, 21 Nov 2026 19:35:16 +0000 [thread overview]
Message-ID: <179528971611.3135.7627191622615262722@kernel.org> (raw)
In-Reply-To: <20261119101538.3229466-1-edumazet@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
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).
- [High] The new merge accounting in zerocopy_fill_skb_from_iter()
(net/core/datagram.c) assumes that this skb's truesize already paid…
- [Low] The patch says the problem was found with an AI coding assistant,
but only in the text after the '---' separator.
--
net: do not over-estimate truesize in zerocopy_fill_skb_from_iter()
This commit changes how zerocopy_fill_skb_from_iter() accounts truesize.
Each new frag now charges one page. A chunk merged into the last frag
only charges the pages that frag did not already cover. Before, the code
charged PAGE_ALIGN(copied + start) for every iov_iter_get_pages2() batch.
Link: https://lore.kernel.org/netdev/20261119090828.343748-1-jiayuan.chen@linux.dev/
> ---
> This was found with an AI coding assistant, while reviewing
> the patch in the Link above, which mentions 8 one-byte iovecs being
> charged 32768 bytes.
[ ... ]
> With this patch, both cases add 4096 bytes. Kernel selftests were
> not run.
[Severity: Low]
This isn't a bug, but this text is below the --- separator, so git am
will drop it. The committed changelog would then not say that the problem
was found with an AI coding assistant. The reproducer results and the
note that selftests were not run would also be lost.
Documentation/process/generated-content.rst says:
if a tool was used to find a problem addressed by a change, that should
be noted in the changelog.
Could the tool attribution, and maybe the testing note, move above the
Signed-off-by block?
> diff --git a/net/core/datagram.c b/net/core/datagram.c
> index 489d92fe6dae8..8c418c3adf1c9 100644
> --- a/net/core/datagram.c
> +++ b/net/core/datagram.c
> @@ -659,7 +659,6 @@ int zerocopy_fill_skb_from_iter(struct sk_buff *skb,
>
> skb->data_len += copied;
> skb->len += copied;
> - skb->truesize += PAGE_ALIGN(copied + start);
>
> head = compound_head(pages[n]);
> order = compound_order(head);
> @@ -680,6 +679,11 @@ int zerocopy_fill_skb_from_iter(struct sk_buff *skb,
>
> if (head == skb_frag_page(last) &&
> start == skb_frag_off(last) + skb_frag_size(last)) {
> + /* Only account the pages this frag
> + * did not already cover.
> + */
> + skb->truesize += PAGE_ALIGN(start + size) -
> + PAGE_ALIGN(start);
> + skb_frag_size_add(last, size);
[Severity: High]
This seems to assume that this skb's truesize already pays for every page
the last frag covers. Is that always true?
It holds for frags created earlier by zerocopy_fill_skb_from_iter()
itself. But TCP tail skbs can end with a frag that was charged per byte,
and the frag's geometry alone does not show which pages this skb paid
for.
tso_fragment() in net/ipv4/tcp_output.c moves exactly nlen bytes of
truesize to the remainder skb:
buff->truesize += nlen;
skb->truesize -= nlen;
...
skb_split(skb, buff, len);
skb_split() usually leaves buff with a last frag that ends mid-page.
skb_zerocopy_clone() gives buff the same uarg, and msg_zerocopy_realloc()
reuses that uarg for contiguous sends. buff then becomes
tcp_write_queue_tail(), and tcp_sendmsg_locked() appends the next
MSG_ZEROCOPY chunk to it via skb_zerocopy_iter_stream().
The MSG_SPLICE_PAGES path in tcp_sendmsg_locked() is similar.
skb_splice_from_iter() charges only the spliced bytes:
out:
skb_len_add(skb, spliced);
Suppose a following MSG_ZEROCOPY sendmsg continues in the same page. It
matches the merge condition with a mid-page start, and the chunk ends
inside the page. PAGE_ALIGN(start + size) - PAGE_ALIGN(start) is then 0,
while skb->len grows by up to PAGE_SIZE - 1.
For example:
- a zerocopy send of 2048 bytes from page P is charged 4096
- tso_fragment() splits at 1000 bytes, and buff gets frag [P, 1000, 1048]
with truesize 1048
- a zerocopy send of bytes 2048..4095 of P merges into that frag and is
charged PAGE_ALIGN(4096) - PAGE_ALIGN(2048) = 0
- buff now holds 3096 bytes of frag data against 1048 bytes of truesize
Before this patch, the same send was charged PAGE_ALIGN(2048 + 2048) =
4096, so frag truesize never dropped below len.
This under-charges sk_wmem_queued and sk_forward_alloc. Over loopback,
can it also hit the WARN in skb_try_coalesce()?
skb_orphan_frags_rx()->skb_copy_ubufs() copies the payload into new
kernel pages without touching truesize. tcp_add_backlog() or
tcp_try_coalesce() then reach:
net/core/skbuff.c:skb_try_coalesce() {
...
delta = from->truesize - SKB_TRUESIZE(skb_end_offset(from));
...
if (WARN_ON_ONCE(delta < 0 || delta < len))
return false;
...
}
The receiver's rmem accounting would also under-count the pages that
skb_copy_ubufs() allocated.
This looks reachable without privileges. One way is SO_ZEROCOPY on a TCP
socket with MSG_ZEROCOPY sends of a contiguous buffer in sizes that are
not page multiples, while cwnd or rwnd forces tso_fragment() on the tail
skb. Another is splice or sendfile of part of a page, followed by a
MSG_ZEROCOPY send of the rest of that page.
Would it help to charge at least the merged bytes here, for example the
larger of the page delta and size? Another option is to track which pages
this skb has actually charged.
> /* We combined this page, we need to release
> * a reference. Since compound pages refcount
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119101538.3229466-1-edumazet%40kernel.org
prev parent reply other threads:[~2026-11-21 19:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 10:15 [PATCH net-next] net: do not over-estimate truesize in zerocopy_fill_skb_from_iter() Eric Dumazet
2026-11-21 19:11 ` Kuniyuki Iwashima
2026-11-21 19:35 ` 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=179528971611.3135.7627191622615262722@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.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