🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by "Loktionov, Aleksandr" Fri, 13 Nov 2026 12:04
RE: [PATCH bpf-next 04/15] xdp: add a kfunc to delete skb core extension entries
#15804
Author: "Loktionov, Aleksandr"
Date: Fri, 13 Nov 2026 12:04
136 lines
27747 bytes

> -----Original Message-----
> From: Tianyi Gao <tianyi@cloudflare.com>
> Sent: Tuesday, November 10, 2026 4:57 AM
> To: bpf@vger.kernel.org; netdev@vger.kernel.org; Alexei Starovoitov
> <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; Andrii
> Nakryiko <andrii@kernel.org>; Martin KaFai Lau <martin.lau@linux.dev>;
> Jakub Kicinski <kuba@kernel.org>; Jesper Dangaard Brouer
> <hawk@kernel.org>
> Cc: John Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Lorenzo Bianconi <lorenzo@kernel.org>; Vladimir
> Vdovin <deliran@verdict.gg>; David S. Miller <davem@davemloft.net>; Eric
> Dumazet <edumazet@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Simon
> Horman <horms@kernel.org>; Andrew Lunn <andrew+netdev@lunn.ch>; Donald
> Hunter <donald.hunter@gmail.com>; Eduard Zingerman <eddyz87@gmail.com>;
> Kumar Kartikeya Dwivedi <memxor@gmail.com>; Song Liu <song@kernel.org>;
> Yonghong Song <yonghong.song@linux.dev>; Jiri Olsa <jolsa@kernel.org>;
> Emil Tsalapatis <emil@etsalapatis.com>; Ihor Solodrai
> <ihor.solodrai@linux.dev>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Fijalkowski, Maciej
> <maciej.fijalkowski@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Karlsson, Magnus
> <magnus.karlsson@intel.com>; Vyavahare, Tushar
> <tushar.vyavahare@intel.com>; Jason Xing <kerneljasonxing@gmail.com>;
> Nikolay Aleksandrov <razor@blackwall.org>; Madalin Bucur
> <madalin.bucur@nxp.com>; Ioana Ciornei <ioana.ciornei@nxp.com>; Jonathan
> Corbet <corbet@lwn.net>; Shuah Khan <skhan@linuxfoundation.org>; Shuah
> Khan <shuah@kernel.org>; Randy Dunlap <rdunlap@infradead.org>; Nathan
> Chancellor <nathan@kernel.org>; Nick Desaulniers
> <ndesaulniers@google.com>; Bill Wendling <morbo@google.com>; Justin
> Stitt <justinstitt@google.com>; Chris J Arges <carges@cloudflare.com>;
> Jakub Sitnicki <jakub@cloudflare.com>; linux-doc@vger.kernel.org; linux-
> kselftest@vger.kernel.org; intel-wired-lan@lists.osuosl.org;
> llvm@lists.linux.dev; kernel-team@cloudflare.com; Tianyi Gao
> <tianyi@cloudflare.com>
> Subject: [PATCH bpf-next 04/15] xdp: add a kfunc to delete skb core
> extension entries
> 
> bpf_xdp_skb_ext_del() deletes the stored entry for an id. A program on
> cpumap or veth can use it to drop RX metadata that an earlier program
> stored.
> 
> Without the XDP_FLAGS_HAS_SKB_EXT flag, the kfunc does nothing, because
> the header bytes may then belong to the packet.
> 
> The kfunc only clears XDP_SKB_EXT_ENTRY_ACTIVE, so a later store of the
> same id reuses its offset. The flag and the size of the area stay the
> same, also after the last delete. To give the bytes back, the kfunc
> would have to move the entries after the deleted one. The cost is
> headroom that bpf_xdp_adjust_head() and bpf_xdp_adjust_meta() cannot
> use.
> 
> Signed-off-by: Tianyi Gao <tianyi@cloudflare.com>
> ---
> __skb_ext_del() frees struct skb_ext after the last delete, because it
> comes from a slab cache. The skb core extension area uses existing
> headroom, so it is not freed.
> ---
>  include/net/xdp.h |  8 ++++++++
>  net/core/xdp.c    | 26 ++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/include/net/xdp.h b/include/net/xdp.h index
> c888353425d4..23c976e92898 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -486,6 +486,14 @@ static __always_inline struct xdp_skb_ext
> *xdp_skb_ext(struct xdp_frame *frame)
>  	return (void *)(frame + 1);
>  }
> 
> +static __always_inline struct xdp_skb_ext * xdp_buff_skb_ext(const
> +struct xdp_buff *xdp) {
> +	if (!xdp_buff_has_skb_ext(xdp))
> +		return NULL;
> +	return xdp_skb_ext(xdp->data_hard_start);
> +}
> +
>  static __always_inline void *xdp_skb_ext_end(const struct xdp_buff
> *xdp)  {
>  	struct xdp_skb_ext *ext = xdp_skb_ext(xdp->data_hard_start);
> diff --git a/net/core/xdp.c b/net/core/xdp.c index
> 97dc0e403a78..2c1d5ec3311b 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -991,6 +991,7 @@ bool bpf_dev_bound_kfunc_id(u32 btf_id)  }
> 
>  #define XDP_SKB_EXT_CHUNKSIZEOF(x) DIV_ROUND_UP(sizeof(x),
> XDP_SKB_EXT_ALIGN)
> +/* A deleted entry keeps its offset, without this bit */
>  #define XDP_SKB_EXT_ENTRY_ACTIVE BIT(7)
> 
>  struct xdp_skb_ext_hash {
> @@ -1119,11 +1120,36 @@ __bpf_kfunc int
> bpf_xdp_skb_ext_store_rx_vlan(struct xdp_md *ctx,
>  	return 0;
>  }
> 
> +/**
> + * bpf_xdp_skb_ext_del - Delete a stored entry of this packet.
> + * @ctx: XDP context pointer.
> + * @id: Entry id, see &enum xdp_skb_ext_id.
> + *
> + * Return:
> + * * Returns 0 on success, also when the entry is not stored.
> + * * ``-EINVAL`` : @id is not a valid entry id  */ __bpf_kfunc int
> +bpf_xdp_skb_ext_del(struct xdp_md *ctx, enum xdp_skb_ext_id id) {
> +	struct xdp_buff *xdp = (struct xdp_buff *)ctx;
> +	struct xdp_skb_ext *ext;
> +
> +	if ((u32)id >= XDP_SKB_EXT_NUM)
> +		return -EINVAL;
> +
> +	ext = xdp_buff_skb_ext(xdp);
> +	if (ext)
> +		ext->offset[id] &= ~XDP_SKB_EXT_ENTRY_ACTIVE;
> +
> +	return 0;
> +}
> +
>  __bpf_kfunc_end_defs();
> 
>  BTF_KFUNCS_START(xdp_skb_ext_kfunc_ids)
>  BTF_ID_FLAGS(func, bpf_xdp_skb_ext_store_rx_hash)  BTF_ID_FLAGS(func,
> bpf_xdp_skb_ext_store_rx_vlan)
> +BTF_ID_FLAGS(func, bpf_xdp_skb_ext_del)
>  BTF_KFUNCS_END(xdp_skb_ext_kfunc_ids)
> 
>  static const struct btf_kfunc_id_set xdp_skb_ext_kfunc_set = {
> --
> 2.56.0

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads