Article View: linux.kernel.netdev
Article #20210Re: [PATCH net-next] net: do not over-estimate truesize in zerocopy_fill_skb_from_iter()
From: netdev-bot+sashiko
Date: Sat, 21 Nov 2026 19:35
Date: Sat, 21 Nov 2026 19:35
157 lines
13678 bytes
13678 bytes
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
Technical Details
Message-ID:
<179528971611.3135.7627191622615262722@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368431-linux-kernel-netdev=dewy.ruReferences:
<20261119101538.3229466-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368431-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <179528971611.3135.7627191622615262722@kernel.org> References: <20261119101538.3229466-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3476586"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:5doAAYndiS+NKYIDUB3OIQsE5P8= sha256:hM2mqa2AILUS7DLLRWcIwsZ4/M+hZOky0dpIntofdGM= sha1:U6eE494T54Ni1LW84yLefxs2e18= sha256:o80AQw/nBR/BVKjsVvRIRJULAC0Y0qpv4hPQwCjTTqI= 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 1F153115BD0; Sat, 21 Nov 2026 22:35:35 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 FJ610PEE2Acz; Sat, 21 Nov 2026 22:35:31 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368431-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 404A5115BCE; Sat, 21 Nov 2026 22:35:22 +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 2871437CF3; Sat, 21 Nov 2026 19:35:18 +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=1795289718; b=jMf+fbpe88a2xdye8JHztcFhLNUV3FlSikbIKuBPP0+nJDQXsAWBlmuavITd0QKXwchm ukYqs427VapnG8ezwwGke43PAm8/XvXMjJK/q6o6wEAxSXU4eapHh2XQgyTC5OiDNyOrA UIcebiAJVmolfYnvq6A+ZWHHGA0BTeJ0fyNR03Q8emDZpiicG4zpf5c9++MMsV62hJXoh iQYYiaial0X2vbLxynWF79497NA0kwKgaV2JEONa6/0QhMYXuWTBcTk0VE7S94jnIniTK FBcJzAohgOWnrWdHYz/ure9+4X5vmE+ii9FtvLSJ8oc3vg7TDVXMkSEMxvzcneetceQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795289718; 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=6CN2gJNDMBoiZ0kP/OYJnDTB0ekHy0tOCfyENNeW4Ns=; b=tqI6X+LEIHxb+ycEnqcXJ16IRldX6hLsfatUK8XvfZEWqgOo6V6K5PPzb8eqmIrmL93j y+LTtRYeUWKuxjIpBZK87oH+p2s9a3HeJegZ7ya1ODXbCDLFNXDzrNLCAwc39aDL+pqNs 0qbwtvB4GBGF9k2MUzMRifWEs9rDJmVAk/sHeh1d+f23g+y15lhxrZr64B2l5tMm0phab lEIZEOGPebqQtpc63bXRM52zNZcJ/+9Iuptkh3ke+7V0AESYkh+6VxyCWmxVqNzs0ndCj rvTsxk2SJeGT4l8VHlw4kUyEjFW+Boynhg1INln5Xxqk4ESi/+F1BjBJdX0N+sTRaFg== 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=CXbFkFWb; 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 F30F0606A32A; Sat, 21 Nov 2026 19:35:17 +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=CXbFkFWb 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=1795289717; b=kbwiB/NiH07CiHAqek6xj29hjpsUzC2sbS+NkQJvZAEVYnB51Q0j5xjyADAEW27dc3Fc PJudEu91syiQ4IuhAKboH7RMSESV7OXLTby4PX6KnS6A+7T2+fdrPQe2X4IPqUBeupPh+ jC/G/QkxN06QJoPFby9Elict4L3O3HCXwfwzCXlEH665kjd8hR2ZroNSah0f8+0rIDBCJ 53HO/w5KLwf97i+5CHsSpty+Q+YRJdxYYGleUUh7E+9z7ePkvvsnqGrJY4RKSLjYx1FoY 2lv+wqWw3cB1qQ0+DK9VSKLynnJPNx7ha+DrntrzPIIOHeucbCHIMM30N7UtPlhG6qQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795289717; 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=6CN2gJNDMBoiZ0kP/OYJnDTB0ekHy0tOCfyENNeW4Ns=; b=rSgc2N8AkGKG8rDxdL6plar6IvxYj+n7d0fiWuDWNfQdl7RX8rWN9IjaBd6aVDIc94KF Wh1lMXGju5csMh+NGGT7kRGXKdoEr8XRCMW5iuoU3RHgBMlGabO/nZQKhTrKiW7Vp97oa HilB23z5xi+CEwb9n39Vs4mizvADK1dEmofdJD+QGik8R+UP3Oa1wJn9lV2LVJmg27qgl 96dBjgpALA5dJraTgeRa2icWbOCoRDSHmeldW8yZEDUEo+0RklrnEN87rE/i7t485bi04 Bm+c+oq4JVvghHbmU06uLsaN4OQoKA7I2ex3oVySHpLYmbDaWfLCPulFCO381IYJb6g== 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=CXbFkFWb; 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 1D828606A33A for <netdev@vger.kernel.org>; Sat, 21 Nov 2026 19:35:17 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8413A1F000C4; Sat, 21 Nov 2026 19:35:16 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795289717; bh=6CN2gJNDMBoiZ0kP/OYJnDTB0ekHy0tOCfyENNeW4Ns=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=CXbFkFWbxl+tueznEajlYa35Xl5kos2bLxAAt257JUvxKUM3Ti4+QUK+9uHMXSbjo 57Q4ZSOkBpIkiVNBzz4Z5tQ/2nUs9oQjr221+7hxmK5Md7n6bJxjwnBPy92EEloP2I n7LFU+kh/2mMl4Hbpn5KlziLmXoH5Bz/fuakdbTsO7vMAHyBNrkQM2549nBE6K9SMl kR0eZe5PZYSPg4Osad9ntGZOwYF5vRkRE/TL3R7C1NG+EwfaMz8hOQg4CuwgBPF+uw SCHsTG73ctUOKG/YMhjIbsFJ0xt9bpDojR5ohpbijagUgWsdT1XuDg9SVwPlnE5oQ9 yKjxdLaUJW1mg== X-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 X-In-Reply-To: <20261119101538.3229466-1-edumazet@kernel.org> X-sashiko-severity: High 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