From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=192.198.163.7 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796311020; b=GtRc+W/ETqgzBXP78hoZ4f656TWhgaXUP2kMXRuawHp7sjVuLZdyBWwQ7oCB8ttT2oBL 3iSehXgebL8ZzytyXRxbWZaOvH4P2++hX+/5lHs4ibclbtN+uVI9teaA5ksfCXrliZ4Cf 1/o6s9kTgEQsJsE8HWr87hfKuKsppbcy+Bd+WWdKMAB0KhwT8Oj9zps2U7Cb7u6hdDDb4 mRmsAYi6s0AeR/UCmltuY5fkQOuHXzN4BGOE6gDmFx7U7SWtB3IU9zCMiwbfFNH/2va7t 61EfD8nT2GG4T5pjvabW8UvY41NYACnypK99vZkjQnnOq69+YmB3W3bpOUBIVpIJ1xQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311020; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:Received: Received:Received:Received:Date:From:To:CC:Subject:Message-ID: References:Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-Exchange-RoutingPolicyChecked: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; bh=219t7dMXC133TGCWaETiHPL/T6NE+oRlTo7eTeb0SpY=; b=Y91qipJ21pJblFCcBnh6F6/LDaI7C8N3jc61LkbDGoVRpXIUrpJ+2U7JpmTyufSuJivm 54kqJsUs6mZyV80xYRWIKMZVMISpqE0WKKtLGKGhFQQSDZ+esX4qKYl3jJh/ODQK4Vf9T M69eOA0V/LSvfwHgQHOyVbcBMBjr1kYSp9aUkJbwu/WI9SJH5/dBDbRXgScMwhuo1qwI9 kn9zbvk4Z7FwKz9t9l8EzhoM+ohFXPr5zTuJJXvBeOJkhjgI7XmH6lUsOG25N2Atdctf9 ZQwixCK8LxRGe6ba4K7kQLUUiBhJK81ri0VURJ33GTwBssijKf2S13rpiysUJ8MGgsA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=UtjItpxU; arc=fail smtp.remote-ip=192.198.163.7 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25B1B606A32C; Thu, 3 Dec 2026 15:16:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 25B1B606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=UtjItpxU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796311021; x=1827847021; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=219t7dMXC133TGCWaETiHPL/T6NE+oRlTo7eTeb0SpY=; b=UtjItpxUGVYA21wB2hAN7x/NxRbiPFdxS9c6gSoWj4ZwHXcNGWEKjVpz 5zf65nUa5No7PQquTNTuSkvxR2A20iJqCylBwTXdRLqd5ZpyO2dhvIgW8 +xFDphrHyZ+okXictmXllL/tzpTSwF42C0C0xgOzQxRSdgzMnXi2fa7// FSeS1XUmqiaMy6HNo8nivt4Wt9KkHGkuUSklP1uEStv9rVs5TBcVnrfKj hx3G0vtGg1ndlkdWkx155u6ozUFxNtxwYo1yzFaah+zmKliqs8PVCZp9d T1oZi4LFbO89QoTq1MNmMa2hbsYGto/J1aFksGqhnMR1KPG5q4cwKzjvl w==; X-CSE-ConnectionGUID: MGHYk/xnQR6eIOvA4EmW/w== X-CSE-MsgGUID: F1I8PPOjQZWTjskFVq0DdA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5126496" X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="5126496" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 07:16:46 -0800 X-CSE-ConnectionGUID: DLqljCCvQ4aEC+4HFZqa0g== X-CSE-MsgGUID: yDlWkX5NQ263bcg8LOjJ9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,248,1794902400"; d="scan'208";a="13693830" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by orviesa003.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 07:16:45 -0800 Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 07:16:44 -0800 Received: from ORSEDG902.ED.cps.intel.com (10.7.248.12) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 07:16:44 -0800 Received: from SA9PR02CU001.outbound.protection.outlook.com (40.93.196.2) by edgegateway.intel.com (134.134.137.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 07:16:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ntEDSG3xwCsOIe6izysG/GhJ1+Qbb6opI7nX63ZZK5gAqx7+bhEGf6RvzkH6nbf4RZhdRx3YXYthVscBiPrExZUH/OiCEATomfMOWfqZ1BLsz8cN07rzrE3xQMYIvVYzIdIlDn/RU6TWWz+8B370ma+INSRT28vHAatuoeVQBX0opaSnhpyUKWOpNuy+oyPNBDjUUzLy1bFNIJ6QQPIBszYgt61TXWDCG6xPQ9LQTjcIx6YNMHP4gQDoavfxmpcig/3fmBX0R9vk5Rr2+2Bbmnpmo8sfRGiuU16UtZXkSdref9UQ6whNY0UgwlWdhs7SbSxoM7lbv0ksg1RBTzCHzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZxH/cvTVOe7gfLedDWaM9HhV8BqbmByG1tj8pgTlCCo=; b=MhC9hOs77wAD6Xz4FQu1r5cNqiIWkB5sz9vC3hi/SU8WsJFDoTFu5dEpDGqoSAn4J+7IPzuFsuhgf5paTB9e9hZ8JLuBzBYkFhyfEyZms3iMevx9gcBwMh4nrQjIDptDyMyFY20ouspk+Ld1K23fkXg3QHqlCr2TKZhnLRi9TkTSdXlMxDYRyimUGFBc+jVoZuK3tVEI8xn4UCqB2G1XVoQxgYkdbJe/FUx41nbq7pq2svK9r+5gR9NZlzAJAGhxZ7cKCPaPaxcEhARng9e/kfNTAqVFnoazz+tzo2/KS/26WUumuffHhEMZm5x6SapK96bYmocrXqUUx+cVwi1DDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from LV2PR11MB868673.namprd11.prod.outlook.com (2603:10b6:408:422::13) by CO1PR11MB4850.namprd11.prod.outlook.com (2603:10b6:303:9c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Thu, 3 Dec 2026 15:16:40 +0000 Received: from LV2PR11MB868673.namprd11.prod.outlook.com ([fe80::5bfd:6afe:a9db:b7de]) by LV2PR11MB868673.namprd11.prod.outlook.com ([fe80::5bfd:6afe:a9db:b7de%4]) with mapi id 15.21.0688.011; Thu, 3 Dec 2026 15:16:40 +0000 Date: Thu, 3 Dec 2026 16:16:23 +0100 From: Maciej Fijalkowski To: =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= CC: Magnus Karlsson , 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" , , , Simon Horman , Stanislav Fomichev , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , , =?iso-8859-1?Q?Cl=E9ment?= Lecigne , Michal Swiatkowski , Sriram Yagnaraman , Kurt Kanzenbach Subject: Re: [PATCH net v3 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Message-ID: References: <20261203095647.3448925-1-bjorn@kernel.org> <20261203095647.3448925-5-bjorn@kernel.org> Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261203095647.3448925-5-bjorn@kernel.org> X-ClientProxiedBy: TL2P290CA0014.ISRP290.PROD.OUTLOOK.COM (2603:1096:950:2::17) To LV2PR11MB868673.namprd11.prod.outlook.com (2603:10b6:408:422::13) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR11MB868673:EE_|CO1PR11MB4850:EE_ X-MS-Office365-Filtering-Correlation-Id: fa2f423d-c3f0-4955-3bc2-08df51506e3e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|23010399003|366016|1800799024|5023799004|4143699003|11063799006|6133799003|261009223027099003|22082099003|18002099003|56012099006|10067099003|261028144727099003|261102130727099003|261102123227099003|261022105027099003|261026121527099003|261021123027099003|261021121427099003|261026140227099003; X-Microsoft-Antispam-Message-Info: p8WY67OL5THheb+yRw6enfQ/GQj2BfMjpzWMEh6DR+5dRZyyl1yS0rz+8JsPIVWVI3Tz9xMDGnau99/tYy1MBrCxLYtnV41kpnTG3gKGTsK9oQ/n7//0ZgI1BwYcxSxzp9b7zBelnugV3i8PiWV9SKM5P/u80qAw2K3IpCJBPFeeisyN/m+KlGUPrdfpWCFd2NxFdE6Ck9aodX30PjhrLzbPO9WcPl2zUOyuM3DBegnCHr+HGLq/Ya+FN7lffOL6oT/VO+7vIuf7RNX74Ls1Y3BcKiKLhGpa/Wp7OKP14qaHsv+uI75V3gvdG62INRiNHy4ENl1D2O8PTkHU3HZfOdhfqDtM/udBmO3PY3OdMu+IPrYzl07l/7qafIu2Xo7AlzXZcp1SFU8mgL2EYdrACAq5GbmatixVjAAsEGI4+x2Wd2pL6NmtKw8M430hovsjGNFAkYcnXh8W7cAXEQ3b4YWQXzsT8vtlHl9px4FaMHgByPFGD1b3oweWwfh7P0bD1dMPBQpWR6PzbnHyNIl7YE0S8mHvtWEbG1jQSDM5UYLCMgdX94skR9UvYLEDY8fmNvGztI9u/H65IeTRuZUXWrP+4P4txPp7xMCcx6zn1/AlkgWh/V1jIKkVS/nGbMM1brk/kE07TEjTFE77XrvmbVFv+OY58qTi/1jyQAYgtJo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR11MB868673.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(23010399003)(366016)(1800799024)(5023799004)(4143699003)(11063799006)(6133799003)(261009223027099003)(22082099003)(18002099003)(56012099006)(10067099003)(261028144727099003)(261102130727099003)(261102123227099003)(261022105027099003)(261026121527099003)(261021123027099003)(261021121427099003)(261026140227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?deWFYCUaq7YUD4AK0/IEjamyXeD3NS3wZm/3PEj18BDNwOYd8CODXckPOV?= =?iso-8859-1?Q?nx9PHigZm4GKf3gZTPW8jduFCYz7+x7sfkxkFAFw3tfR5MFFcUWvj8LoOW?= =?iso-8859-1?Q?jrLapYqTK+twjUGLgEyLEXLmq1OOuiFRQpjNKZakCcZB0iIuok6OrBiCsN?= =?iso-8859-1?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ASqXu4q9+3nX01lwHFv+I/evJfEYZQI28mKOMyenfTHAAkSi7Le9mQvZm5Pr9blVSqIZzgIi+SylNIBw1y4zT0xm7Kz9Zj5H3ByX/QBB0kuhr43RBwgvTO0yw5D9J3n/6krv+x0nvv1pQNls5cslskNkxMxBYFS4UuxcyVTVxK57kmC1gV/zKnDxVA/NIUOiDF3vufAWepgFYP7C/Es/hbT7Z1zP+mUPrawbt5nQRNnXzUryZmiRijY473BDg== X-MS-Exchange-CrossTenant-Network-Message-Id: fa2f423d-c3f0-4955-3bc2-08df51506e3e X-MS-Exchange-CrossTenant-AuthSource: LV2PR11MB868673.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 15:16:40.1935 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dObGYE0cVoCT/5CcdB3uo5ZDH8F2wfSkMIeIiYc02KarHVoe+tn3B0Omuhm8bZGJpe7Ta9BQT+9wZQ3tMY2wPrUea/P9e/q74seH7FSS3Y0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB4850 X-OriginatorOrg: intel.com On Thu, Dec 03, 2026 at 10:56:45AM +0100, Björn Töpel wrote: > A packet that a driver receives in zero-copy mode over several buffers > keeps its shared info, the fragment list and its count, in the > tailroom of the UMEM chunk of its head. Userspace may write the UMEM > at any time, also while the kernel walks the fragments, and a > rewritten list or count makes the kernel read and write out of bounds. > > Keep the shared info in the buffer pool, which outlives its buffers > and the queues that point to it, and let the device write up to the > end of the chunk. One shared info per pool is enough, as a pool builds > one multi-buffer packet at a time. > > Buffers carry a flag for this, set again on every reuse, as drivers > may clear the flags of the buffers they receive into. > > Multi-buffer pools now give the device the whole chunk, as > single-buffer pools already do. Every UMEM accepts a larger headroom, > also in copy mode, and bpf_xdp_adjust_tail() can grow a zero-copy > packet up to the end of its chunk. > > A backport needs patches 1 to 3 of this series, which stop libeth and > the skb builders from relying on the old layout. > > Found by an AI code review agent, in its review of another series. Not > triggered at runtime. > > Suggested-by: Maciej Fijalkowski > Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX") > Signed-off-by: Björn Töpel Reviewed-by: Maciej Fijalkowski > --- > include/net/xdp.h | 32 ++++++++++++++++++++++++++------ > include/net/xdp_sock_drv.h | 26 ++++++-------------------- > include/net/xsk_buff_pool.h | 2 ++ > net/core/filter.c | 2 +- > net/xdp/xdp_umem.c | 3 +-- > net/xdp/xsk_buff_pool.c | 20 ++++++++++++-------- > 6 files changed, 48 insertions(+), 37 deletions(-) > > diff --git a/include/net/xdp.h b/include/net/xdp.h > index 07231adfb5f8..052402766988 100644 > --- a/include/net/xdp.h > +++ b/include/net/xdp.h > @@ -65,6 +65,10 @@ struct xdp_rxq_info { > u32 reg_state; > struct xdp_mem_info mem; > u32 frag_size; > + /* Shared info of buffers with %XDP_FLAGS_SINFO_EXT, in the XSk buffer > + * pool, set by xsk_pool_set_rxq_info(). > + */ > + struct skb_shared_info *ext_sinfo; > } ____cacheline_aligned; /* perf critical, avoid false-sharing */ > > struct xdp_txq_info { > @@ -81,6 +85,13 @@ enum xdp_buff_flags { > * XDP program is not attached. > */ > XDP_FLAGS_FRAGS_UNREADABLE = BIT(2), > + /* The shared info lives in &xdp_rxq_info.ext_sinfo, not at the end of > + * the frame, as userspace may write the frame. The frame reserves no > + * tailroom, so the data may reach its end. The pool builds one such > + * buffer at a time, so a consumer that uses the shared info later > + * must copy what it needs. > + */ > + XDP_FLAGS_SINFO_EXT = BIT(3), > }; > > struct xdp_buff { > @@ -178,17 +189,26 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start, > > /* Reserve memory area at end-of data area. > * > - * This macro reserves tailroom in the XDP buffer by limiting the > - * XDP/BPF data access to data_hard_end. Notice same area (and size) > - * is used for XDP_PASS, when constructing the SKB via build_skb(). > + * This reserves tailroom in the XDP buffer by limiting the XDP/BPF data > + * access to data_hard_end. Notice same area (and size) is used for > + * XDP_PASS, when constructing the SKB via build_skb(). Buffers with > + * %XDP_FLAGS_SINFO_EXT keep the shared info elsewhere and reserve none. > */ > -#define xdp_data_hard_end(xdp) \ > - ((xdp)->data_hard_start + (xdp)->frame_sz - \ > - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) > +static __always_inline void *xdp_data_hard_end(const struct xdp_buff *xdp) > +{ > + u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); > + > + if (xdp->flags & XDP_FLAGS_SINFO_EXT) > + tailroom = 0; > + return xdp->data_hard_start + xdp->frame_sz - tailroom; > +} > > static inline struct skb_shared_info * > xdp_get_shared_info_from_buff(const struct xdp_buff *xdp) > { > + if (xdp->flags & XDP_FLAGS_SINFO_EXT) > + return READ_ONCE(xdp->rxq)->ext_sinfo; > + > return (struct skb_shared_info *)xdp_data_hard_end(xdp); > } > > diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h > index a40ad3f90f13..ec74bf3ffa51 100644 > --- a/include/net/xdp_sock_drv.h > +++ b/include/net/xdp_sock_drv.h > @@ -41,11 +41,6 @@ static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool) > return XDP_PACKET_HEADROOM + pool->headroom; > } > > -static inline u32 xsk_pool_get_tailroom(bool mbuf) > -{ > - return mbuf ? SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : 0; > -} > - > static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool) > { > return pool->chunk_size; > @@ -58,18 +53,7 @@ static inline u32 __xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool) > > static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool) > { > - u32 frame_size = __xsk_pool_get_rx_frame_size(pool); > - struct xdp_umem *umem = pool->umem; > - bool mbuf; > - > - /* Reserve tailroom only for zero-copy pools that opted into > - * multi-buffer. The reserved area is used for skb_shared_info, > - * matching the XDP core's xdp_data_hard_end() layout. > - */ > - mbuf = pool->dev && (umem->flags & XDP_UMEM_SG_FLAG); > - frame_size -= xsk_pool_get_tailroom(mbuf); > - > - return ALIGN_DOWN(frame_size, 128); > + return ALIGN_DOWN(__xsk_pool_get_rx_frame_size(pool), 128); > } > > static inline u32 xsk_pool_get_rx_frag_step(struct xsk_buff_pool *pool) > @@ -152,7 +136,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp) > xp_free(pos); > } > > - xdp_get_shared_info_from_buff(xdp)->nr_frags = 0; > xdp_buff_clear_frags_flag(xdp); > out: > xp_free(xskb); > @@ -226,8 +209,11 @@ static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size) > xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM; > xdp->data_meta = xdp->data; > xdp->data_end = xdp->data + size; > - /* Frags flag is cleared when the frags of a head are released */ > - xdp->flags &= XDP_FLAGS_HAS_FRAGS; > + /* Frags flag is cleared when the frags of a head are released. The > + * shared info stays in the pool, see xp_set_rxq_info(), also for a > + * buffer whose flags a driver cleared. > + */ > + xdp->flags = (xdp->flags & XDP_FLAGS_HAS_FRAGS) | XDP_FLAGS_SINFO_EXT; > } > > static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool, > diff --git a/include/net/xsk_buff_pool.h b/include/net/xsk_buff_pool.h > index 02e89350faf9..ef4bbf7f66b9 100644 > --- a/include/net/xsk_buff_pool.h > +++ b/include/net/xsk_buff_pool.h > @@ -95,6 +95,8 @@ struct xsk_buff_pool { > * destructor callback. > */ > spinlock_t cq_prod_lock; > + /* Own cache lines, as zero-copy multi-buffer Rx writes it per packet */ > + struct skb_shared_info sinfo ____cacheline_aligned_in_smp; > struct xdp_buff_xsk *free_heads[]; > }; > > diff --git a/net/core/filter.c b/net/core/filter.c > index 53c042b267ab..3820c4edc14d 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4510,7 +4510,7 @@ BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset) > return bpf_xdp_frags_increase_tail(xdp, offset); > } > > - /* Notice that xdp_data_hard_end have reserved some tailroom */ > + /* Notice that xdp_data_hard_end may have reserved some tailroom */ > if (unlikely(data_end > data_hard_end)) > return -EINVAL; > > diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c > index ad72bd96905c..de8a2747ac9f 100644 > --- a/net/xdp/xdp_umem.c > +++ b/net/xdp/xdp_umem.c > @@ -195,8 +195,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) > if (!unaligned_chunks && chunks_rem) > return -EINVAL; > > - if (headroom > chunk_size - XDP_PACKET_HEADROOM - > - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - 128) > + if (headroom > chunk_size - XDP_PACKET_HEADROOM - 128) > return -EINVAL; > > if (mr->flags & XDP_UMEM_TX_METADATA_LEN) { > diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c > index 5ec092f7cb6f..28bdc63551bf 100644 > --- a/net/xdp/xsk_buff_pool.c > +++ b/net/xdp/xsk_buff_pool.c > @@ -107,6 +107,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, > xskb = &pool->heads[i]; > xskb->pool = pool; > xskb->xdp.frame_sz = umem->chunk_size - umem->headroom; > + xskb->xdp.flags = XDP_FLAGS_SINFO_EXT; > INIT_LIST_HEAD(&xskb->list_node); > if (pool->unaligned) > pool->free_heads[i] = xskb; > @@ -125,8 +126,15 @@ void xp_set_rxq_info(struct xsk_buff_pool *pool, struct xdp_rxq_info *rxq) > { > u32 i; > > + /* Userspace may write the UMEM. Keep the shared info in the pool, > + * and let the device write up to the end of each chunk. A NAPI may > + * still run on the buffers, so publish the shared info first. > + */ > + rxq->ext_sinfo = &pool->sinfo; > + /* Pairs with READ_ONCE(xdp->rxq) in xdp_get_shared_info_from_buff() */ > + smp_wmb(); > for (i = 0; i < pool->heads_cnt; i++) > - pool->heads[i].xdp.rxq = rxq; > + WRITE_ONCE(pool->heads[i].xdp.rxq, rxq); > } > EXPORT_SYMBOL(xp_set_rxq_info); > > @@ -229,12 +237,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, > segs = 1; > } > > - /* open-code xsk_pool_get_rx_frame_size() as pool->dev is not > - * set yet at this point; we are before getting down to driver > - */ > - frame_size = __xsk_pool_get_rx_frame_size(pool) - > - xsk_pool_get_tailroom(mbuf); > - frame_size = ALIGN_DOWN(frame_size, 128); > + frame_size = xsk_pool_get_rx_frame_size(pool); > > if (needed > frame_size * segs) { > err = -EINVAL; > @@ -629,7 +632,8 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool) > > xskb->xdp.data = xskb->xdp.data_hard_start + XDP_PACKET_HEADROOM; > xskb->xdp.data_meta = xskb->xdp.data; > - xskb->xdp.flags &= XDP_FLAGS_HAS_FRAGS; > + xskb->xdp.flags = (xskb->xdp.flags & XDP_FLAGS_HAS_FRAGS) | > + XDP_FLAGS_SINFO_EXT; > > if (pool->dev) > xp_dma_sync_for_device(pool, xskb->dma, pool->frame_len); > -- > 2.53.1-Meta >