[Intel-wired-lan] [PATCH bpf v3 1/9] xdp: use modulo operation to calculate XDP frag tailroom

Loktionov, Aleksandr aleksandr.loktionov at intel.com
Tue Feb 17 15:10:45 UTC 2026



> -----Original Message-----
> From: Zaremba, Larysa <larysa.zaremba at intel.com>
> Sent: Tuesday, February 17, 2026 2:25 PM
> To: bpf at vger.kernel.org
> Cc: Zaremba, Larysa <larysa.zaremba at intel.com>; Claudiu Manoil
> <claudiu.manoil at nxp.com>; Vladimir Oltean <vladimir.oltean at nxp.com>;
> Wei Fang <wei.fang at nxp.com>; Clark Wang <xiaoning.wang at nxp.com>;
> Andrew Lunn <andrew+netdev at lunn.ch>; David S. Miller
> <davem at davemloft.net>; Eric Dumazet <edumazet at google.com>; Jakub
> Kicinski <kuba at kernel.org>; Paolo Abeni <pabeni at redhat.com>; Nguyen,
> Anthony L <anthony.l.nguyen at intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel at intel.com>; Alexei Starovoitov <ast at kernel.org>;
> Daniel Borkmann <daniel at iogearbox.net>; Jesper Dangaard Brouer
> <hawk at kernel.org>; John Fastabend <john.fastabend at gmail.com>;
> Stanislav Fomichev <sdf at fomichev.me>; Andrii Nakryiko
> <andrii at kernel.org>; Martin KaFai Lau <martin.lau at linux.dev>; Eduard
> Zingerman <eddyz87 at gmail.com>; Song Liu <song at kernel.org>; Yonghong
> Song <yonghong.song at linux.dev>; KP Singh <kpsingh at kernel.org>; Hao Luo
> <haoluo at google.com>; Jiri Olsa <jolsa at kernel.org>; Simon Horman
> <horms at kernel.org>; Shuah Khan <shuah at kernel.org>; Lobakin, Aleksander
> <aleksander.lobakin at intel.com>; Fijalkowski, Maciej
> <maciej.fijalkowski at intel.com>; Bastien Curutchet (eBPF Foundation)
> <bastien.curutchet at bootlin.com>; Vyavahare, Tushar
> <tushar.vyavahare at intel.com>; Jason Xing <kernelxing at tencent.com>;
> Ricardo B. Marlière <rbm at suse.com>; Eelco Chaudron
> <echaudro at redhat.com>; Lorenzo Bianconi <lorenzo at kernel.org>; Toke
> Hoiland-Jorgensen <toke at redhat.com>; imx at lists.linux.dev;
> netdev at vger.kernel.org; linux-kernel at vger.kernel.org; intel-wired-
> lan at lists.osuosl.org; linux-kselftest at vger.kernel.org; Loktionov,
> Aleksandr <aleksandr.loktionov at intel.com>; Dragos Tatulea
> <dtatulea at nvidia.com>
> Subject: [PATCH bpf v3 1/9] xdp: use modulo operation to calculate XDP
> frag tailroom
> 
> The current formula for calculating XDP tailroom in mbuf packets works
> only if each frag has its own page (if rxq->frag_size is PAGE_SIZE),
> this defeats the purpose of the parameter overall and without any
> indication leads to negative calculated tailroom on at least half of
> frags, if shared pages are used.
> 
> There are not many drivers that set rxq->frag_size. Among them:
> * i40e and enetc always split page uniformly between frags, use shared
>   pages
> * ice uses page_pool frags via libeth, those are power-of-2 and
> uniformly
>   distributed across page
> * idpf has variable frag_size with XDP on, so current API is not
> applicable
> * mlx5, mtk and mvneta use PAGE_SIZE or 0 as frag_size for page_pool
> 
> As for AF_XDP ZC, only ice, i40e and idpf declare frag_size for it.
> Modulo operation yields good results for aligned chunks, they are all
> power-of-2, between 2K and PAGE_SIZE. Formula without modulo fails
> when chunk_size is 2K. Buffers in unaligned mode are not distributed
> uniformly, so modulo operation would not work.
> 
> To accommodate unaligned buffers, we could define frag_size as data +
> tailroom, and hence do not subtract offset when calculating tailroom,
> but this would necessitate more changes in the drivers.
> 
> Define rxq->frag_size as an even portion of a page that fully belongs
> to a single frag. When calculating tailroom, locate the data start
> within such portion by performing a modulo operation on page offset.
> 
> Fixes: bf25146a5595 ("bpf: add frags support to the
> bpf_xdp_adjust_tail() API")
> Acked-by: Jakub Kicinski <kuba at kernel.org>
> Signed-off-by: Larysa Zaremba <larysa.zaremba at intel.com>
> ---
>  net/core/filter.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c index
> ba019ded773d..5f5489665c58 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4156,7 +4156,8 @@ static int bpf_xdp_frags_increase_tail(struct
> xdp_buff *xdp, int offset)
>  	if (!rxq->frag_size || rxq->frag_size > xdp->frame_sz)
>  		return -EOPNOTSUPP;
> 
> -	tailroom = rxq->frag_size - skb_frag_size(frag) -
> skb_frag_off(frag);
> +	tailroom = rxq->frag_size - skb_frag_size(frag) -
> +		   skb_frag_off(frag) % rxq->frag_size;
>  	if (unlikely(offset > tailroom))
>  		return -EINVAL;
> 
> --
> 2.52.0

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov at intel.com>


More information about the Intel-wired-lan mailing list