Article View: linux.kernel.netdev
Article #21941Re: [PATCH net-next] tcp: use order-0 page frags in tcp_collapse()
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 16:27
Date: Tue, 24 Nov 2026 16:27
123 lines
12370 bytes
12370 bytes
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
Technical Details
Message-ID:
<179553765702.3135.10078888309251944054@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370571-linux-kernel-netdev=dewy.ruReferences:
<20261123154708.360226-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370571-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next] tcp: use order-0 page frags in tcp_collapse() Date: Tue, 24 Nov 2026 16:27:37 +0000 Organization: Usenet Network Message-ID: <179553765702.3135.10078888309251944054@kernel.org> References: <20261123154708.360226-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="4179662"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:iPhE8ygIO/zcTNg8axy8vtsyMJw= sha256:CGTJG6tjG7BFI+sUymz3L1YRl+Q+2qkwBBikzIc0ZXo= sha1:TxQKzfhoRmItrU7jyoV2/+cbXeQ= sha256:rufmEwuOwZYaTyLHw1Gl5lBxbSG5TsxW4WJjNWWqNmI= 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 B7C5C125E2E; Tue, 24 Nov 2026 19:27:55 +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 JsheRJejbsD0; Tue, 24 Nov 2026 19:27:51 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370571-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 7F57D125E2C; Tue, 24 Nov 2026 19:27:41 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 974B134640; Tue, 24 Nov 2026 16:27:39 +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=1795537659; b=E5oX2DDDXzw64a0EsGa5nfOB1cj80r4gqM+92dS1mZhXIsvzo0rvtYPbANEsl0y9kFGE aZ2BvSMnM/2xMQVXdx8GpNYlHodIQ1CpqP+RtVM1Q4B1lNZZoj3eUQIa8PtIW9G+48q+u 5bNE68ylT6aZ5W/bjml4CJdnAdMkxk8Z5mce/cZAl6bEsVmnO4pZQAC8jBeHlWfosn9jn YO0O3RZncUQ9LptEcgbgubAcKCiQ/4K+xQm2pwWdo4gNUGM9mtobpKu6h2Lwo2XggW69v 9DMqayJSrKbMwtaHQ3xNxC60N/0i9OLUZQB3EJCTx6B6O5CRSW1VPd3oaS5oY8I/hyQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795537659; 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=4L1pAx1aJ9UiuZlP1S95Mk5NDr/KAS3Rr/m1DST9u5I=; b=VBDw6VPZApnXi/VjlzCatODfbJkktmFpRxh0gMGaI2bSeRJs15Yt78UMKL7YVWRp0D2S 0A+FIGA/5wUF4YGo8xmov0hER/EavTKHtCN/anhB6bUNYJqQ5f3lnwpJLPnM09ZwBo7+O rnM1rZOQLcsbih73YNgtH7tU+CRV2diqkfDEe8vnhFdMeVHOdW6qBB2JcWOn6taOCp9W2 pPgzFHx832ykSTeQhIzipW4nY4JpudCYDCbmxPYGC5nnXPj/qDpswEwHDdWpAc3niYxSX 1w6q7NwahekK0b+FmohQJcS1a6eYcxpe/LVGdDBDNKZq1VfHdt62s2nh2FE+DX/GgzQ== 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="MKor/yir"; 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 5BC8B606A331; Tue, 24 Nov 2026 16:27:39 +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=MKor/yir 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=1795537658; b=B4OlMVMr4o97QPYoDWjK99c6ifM7J8u8wJ2dSAQaZrKPBIrEqSAeAk/D1nZqojOJB4Vp p4Mlfqzec0bHaX3ReqJY97WLgSxpN3YOg8mxePrSie64WGpoin8xt4fSnMSfs5BQrBLaa 54kXex6fDqeohzj8YMj6TnY1WzEp4CDmjrm6xSeUQUEeOF7cpnJEbiLcI9bTBzyQuhB6n WeF8ENPs+/ZTzM9AcOqHEZQN/QrKeAskCBoB2S3yfKEiZ5u+Xu1dDTpQ/VfCo4Cm5QPSD gPBfGbSsadSLm8beTGYI30G6MHb7Vir3tglxf3lzVxodKAOrdQYvfPYHP64Bt9gTzKw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795537658; 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=4L1pAx1aJ9UiuZlP1S95Mk5NDr/KAS3Rr/m1DST9u5I=; b=1bp0fHkNz8eBv+B4nV6om9m2IJBsoIkjobEnwgFITXOyN5OhCOhGoCs6jbuDxpU/zeUI r1sJZdGHQekCWKfVIO+JjmQjIfMORtsPgjiqn0ixm8PCn4lzq4EcNUIxEtQpzHd61A71U Qv0Q/7lHB5D2fTGVPIc+1OVOF4Fh+MLrWV9UDk3twVGjUcR/m48ftbds8vFxeJpmG/hPI /sxc34rewC3FXUs9v2ll+tNxp8ShA499A2ZaQW0qWCT2kxaqqsP/dmHO6942sF8u/7187 TtNL+Of5gWzr+iXru7etwV9HmYDKf8lFGihurAJvPscQ1hpHKKj1zyIlTvt8ii66byg== 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="MKor/yir"; 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 7B146606A338 for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 16:27:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 816371F000F2; Tue, 24 Nov 2026 16:27:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795537658; bh=4L1pAx1aJ9UiuZlP1S95Mk5NDr/KAS3Rr/m1DST9u5I=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=MKor/yirXmDmsFP8rvn0bTvpo2dhVP9mVLnTLa1oyYuB2yX8DHQWuGHClb7yNK9AD 81Z2/7JhkR36t4Hx+6b+mn2Zdgw+UihDv6x0jOKIcXBYW8Do0KD+Kh8UuqtccJ2QLB sp0ueZRr2kz5PQ69dSVOa+fHTaSt9V11ssMkfMMT6Y1v7PCwrExfgZzwQdTt/sycYV Tj1XHyqhtCX/QghfIU5syUydYcEnakt2THXxwFeUF0SlkI03suw8YIH3BiYleiozj2 fJZVzBNwy8NDm4qoIgydaeP2CMMXf3D+jjdtOewjgxj7ti3EGqXVFPmU+oiLtTtu+7 ghXynh5HevS9A== X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, kuniyu@google.com, ncardwell@google.com, horms@kernel.org, netdev@vger.kernel.org X-In-Reply-To: <20261123154708.360226-1-edumazet@kernel.org> X-sashiko-severity: Medium 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