From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3BA1606A330 for ; Fri, 4 Dec 2026 14:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=x3DsmbPf; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lKCOOIpZ Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 7F73F61C14; Fri, 4 Dec 2026 14:21:11 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id VmAUUaXx2aFY; Fri, 4 Dec 2026 14:21:10 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp3.osuosl.org 4CB3161B32 Authentication-Results: smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1796394070; b=g4WpU3BURhpb2ivHlKF0m+uQyC6kbb+/wpJ1JOhOh7nVFCXNMnf9Ufv/GHCVyyfgRR56 w5EQ31H1wpX7viKn68TempLRwXuKO6po/ov4hxTvPmRZEGi8P39PebWOCtAJW+q5mC/Yu 57I3nSF5h8nuetBmRKqaOyy77FYHsXZ0DHgiJdLCOtXdjGGRc8GQ2rC8PRxy5sBKV/5FA Qa7/cl+ol017/yXRmXUVggwxoHBYB2MfPtPU7TvfGsVZFYnlaLZp00UL5tEzZUdIyzL2c /ti5eFPExGSMBwIqRAQ8tq71+S/dS4c8iX5Kv7PMnO5LmDN+tRpGRTMPnZeM3Y73Abg== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1796394070; h=X-Comment:DKIM-Signature:X-Original-To:Delivered-To:Received: Received:X-Virus-Scanned:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Spam-Status:Received:ARC-Filter:Received-SPF:Received:Received: Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-BeenThere:X-Mailman-Version:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help: List-Subscribe:Errors-To; bh=fLxlJD9SaU8MGMA0ZOC/ItMalM/OTNVRNO/rC8C7Wm4=; b=tDz0E8zs+Ka6II9r62yc5BxRuYUgd3TrF1N1v4wnRKxZxbubsABvFKwM9AG18T3xPbfW XPpjAHoc+KZqpv1RB8xpEXLKm/X4jaTSSL6EMyw4lUPfmvyQni2hAegWQPId8h08A5J2X TdtV3b2PiVwf6JsP+xXsQRHUtmR0YiaocX3zP4ltO3KtbrlmFgdlMQrguorRkAr5OhqEL TA2gSYzzvmaIsIh+8CzyrYOvcO6iQx1YsFsYAiUkXg+BwxChCG+M/Prsv+6GR8UqUx/e3 JGJehBLbeE2ZG0mnVqWylG/3eEj8xjlsy+lVnrgMCd3Z99MI7dDdorh+b9uJSt7eBvg== ARC-Authentication-Results: i=1; smtp3.osuosl.org; arc=none smtp.remote-ip=140.211.166.142 X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1796394070; bh=fLxlJD9SaU8MGMA0ZOC/ItMalM/OTNVRNO/rC8C7Wm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=x3DsmbPfa2PevB/yr//jljtppT6XUgt5PzTGL9dJ+7oZFqb0TX8+8Rai+ZTdn9vjI woLmYvFwi0YtbtQVSU0LhsES0fcg9P007dJmqz32BJz9Q+d06Zv4F4jieeHING6aDt MXjpffwcRBAfgUitmuRQXeZjZv6+b0V/0icf0cSWAOn+IswFxoEgq1b0q9WGDawV95 u5a9+/DNjzW5/g9a192C+7TrXBAfLKbXj6gmUcOkXd3WmQ1++3tvVZUcumyndojzcT cZe5Ayw4IxE1OwUXmB7meggTz08PDTwP+9vOLf+a0kyye4NHFki5Lte6amGnTskhEr 9Nvfnf6XpLaWg== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id 4CB3161B32; Fri, 4 Dec 2026 14:21:10 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists1.osuosl.org (Postfix) with ESMTP id 5342E120 for ; Fri, 4 Dec 2026 14:21:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 50C3D85F7D for ; Fri, 4 Dec 2026 14:21:09 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id LAerqxHP1g3c for ; Fri, 4 Dec 2026 14:21:08 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.2 smtp1.osuosl.org 5FFE985ED0 Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=bjorn@kernel.org; receiver= Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lKCOOIpZ Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by smtp1.osuosl.org (Postfix) with ESMTPS id 5FFE985ED0 for ; Fri, 4 Dec 2026 14:21:05 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 75306443B9; Fri, 4 Dec 2026 14:21:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCE201F000C2; Fri, 4 Dec 2026 14:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796394065; bh=fLxlJD9SaU8MGMA0ZOC/ItMalM/OTNVRNO/rC8C7Wm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lKCOOIpZVJFMMbAkcXRnQ+v0L8cep1as3v+OAWmREN8PWvE0snTWt2DH7xTij4az0 E1+dbc0iWHTauRlTY2ktcUnizNb1qfZrr1sSnN+oKzlHB6YoSSMfjcUkLDmVnBx/Zb zUkvAVsF1/tR8xmOamGk9NhKtrIu+N76XMyht3Lkuu9u+eHGjbbxfONZL+Q6V7I53z xry7pFOXRf0PEd2DYA/kEt6kERxqOpFx27exsjx7WZznEe3TpyfgZIoydaPjbtOLcd G7pP9S6AYpwwlyrhwSis48L1Njjky+KLBh/K0wYwmt6MyWXlcP9N9e5YAs/q/eKnq2 zveIwnCQS3Bbg== From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Magnus Karlsson , Maciej Fijalkowski , Alexander Lobakin , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Andrew Lunn , Tony Nguyen , Przemek Kitszel , netdev@vger.kernel.org, bpf@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , intel-wired-lan@lists.osuosl.org, =?UTF-8?q?Cl=C3=A9ment=20Lecigne?= , Michal Swiatkowski , Sriram Yagnaraman , Kurt Kanzenbach , Michal Kubiak Subject: [PATCH net v4 3/5] xdp: Size zero-copy skbs from the data, not the frame size Date: Fri, 4 Dec 2026 15:20:23 +0100 Message-ID: <20261204142030.626820-4-bjorn@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204142030.626820-1-bjorn@kernel.org> References: <20261204142030.626820-1-bjorn@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 xdp_build_skb_from_zc() gives the skb head the frame size of the XSk buffer, with the skb shared info at its end. Only multi-buffer pools reserve tailroom, so a device may fill a single-buffer XSk frame to its end. Packet data then overwrites the whole shared info of the new skb, 320 bytes on x86_64, its flags, frag list and destructor_arg included. With 2K chunks, no UMEM headroom and the default MTU, a 1514 byte frame that XDP passes on ice, idpf or gve needs 256 + 1514 + 320 = 2090 bytes and gets 2048, and the sender controls the first 48 bytes. The last patch of this series lets multi-buffer pools and bpf_xdp_adjust_tail() reach the end of the frame as well. The copies of the head and the fragments also round the length up to 16 bytes, and read and write past the data, with 4K chunks past the end of the page. Size the head from the data, and copy the exact length. Heads larger than a page come from kmalloc, not the page pool. Found again by an AI code review agent, and the 2K case by reading the code. Reproduced out of tree, with a test module and the AF_XDP page-pool RFC on fbnic in QEMU. Reported-by: Clément Lecigne Link: https://lore.kernel.org/bpf/20260629072300.1664622-1-clecigne@google.com/ Fixes: 560d958c6c68 ("xsk: add generic XSk &xdp_buff -> skb conversion") Acked-by: Alexander Lobakin Reviewed-by: Maciej Fijalkowski Signed-off-by: Björn Töpel --- net/core/xdp.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/net/core/xdp.c b/net/core/xdp.c index 1d679e8fd649..33a6740b411f 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -709,7 +709,7 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb, } memcpy(page_address(page) + offset, skb_frag_address(frag), - LARGEST_ALIGN(len)); + len); __skb_fill_page_desc_noacc(sinfo, i, page, offset, len); tsize += truesize; @@ -723,6 +723,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb, return true; } +static struct sk_buff *xdp_zc_alloc_head(struct page_pool *pp, + struct net_device *dev, u32 size) +{ + u32 truesize = SKB_HEAD_ALIGN(size); + struct sk_buff *skb; + void *data; + + if (truesize > PAGE_SIZE) + return __netdev_alloc_skb(dev, size, GFP_ATOMIC | __GFP_NOWARN); + + data = page_pool_dev_alloc_va(pp, &truesize); + if (unlikely(!data)) + return NULL; + + skb = napi_build_skb(data, truesize); + if (unlikely(!skb)) + page_pool_free_va(pp, data, true); + + return skb; +} + /** * xdp_build_skb_from_zc - create an skb from XSk &xdp_buff * @xdp: source XSk buff @@ -730,7 +751,8 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb, * Similar to xdp_build_skb_from_buff(), but for XSk frames. Allocate an skb * head, new buffer for the head, copy the data and initialize the skb fields. * If there are frags, allocate new buffers for them and copy. - * Buffers are allocated from the system percpu pools to try recycling them. + * Buffers are allocated from the system percpu pools to try recycling them, + * except a head that does not fit into a page. * If new skb was built successfully, @xdp is returned to XSk pool's freelist. * On error, it remains untouched and the caller must take care of this. * @@ -738,33 +760,27 @@ static noinline bool xdp_copy_frags_from_zc(struct sk_buff *skb, */ struct sk_buff *xdp_build_skb_from_zc(struct xdp_buff *xdp) { + u32 size = xdp->data_end - xdp->data_hard_start; const struct xdp_rxq_info *rxq = xdp->rxq; u32 len = xdp->data_end - xdp->data_meta; - u32 truesize = xdp->frame_sz; struct sk_buff *skb = NULL; struct page_pool *pp; int metalen; - void *data; if (!IS_ENABLED(CONFIG_PAGE_POOL)) return NULL; local_lock_nested_bh(&system_page_pool.bh_lock); pp = this_cpu_read(system_page_pool.pool); - data = page_pool_dev_alloc_va(pp, &truesize); - if (unlikely(!data)) - goto out; - skb = napi_build_skb(data, truesize); - if (unlikely(!skb)) { - page_pool_free_va(pp, data, true); + skb = xdp_zc_alloc_head(pp, rxq->dev, size); + if (unlikely(!skb)) goto out; - } skb_mark_for_recycle(skb); skb_reserve(skb, xdp->data_meta - xdp->data_hard_start); - memcpy(__skb_put(skb, len), xdp->data_meta, LARGEST_ALIGN(len)); + memcpy(__skb_put(skb, len), xdp->data_meta, len); metalen = xdp->data - xdp->data_meta; if (metalen > 0) { -- 2.53.1