Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by "Loktionov, Aleksandr"
Fri, 13 Nov 2026 12:05
RE: [PATCH bpf-next 13/15] xdp: add kfuncs to load the stored RX metadata
Author: "Loktionov, Aleksandr"
Date: Fri, 13 Nov 2026 12:05
Date: Fri, 13 Nov 2026 12:05
185 lines
29562 bytes
29562 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 13/15] xdp: add kfuncs to load the stored RX
> metadata
>
> A program on cpumap or devmap cannot call the XDP RX metadata kfuncs,
> because they need a device-bound program. A program on veth can be bound
> to veth, but the veth callbacks return -ENODATA for an xdp_frame. So a
> program after the redirect cannot read the values that the program on
> the NIC stored.
>
> Add three kfuncs that read the skb core extension area:
> bpf_xdp_skb_ext_load_rx_hash(), bpf_xdp_skb_ext_load_rx_vlan() and
> bpf_xdp_skb_ext_load_rx_csum(). Each returns -ENODATA when its entry is
> not stored. They are in the same kfunc set as the store kfuncs, so they
> are not device-bound and need no driver callback. A program on the NIC
> can also read back the values that it stored.
>
> The RX metadata kfuncs could return the stored values instead. This
> patch does not do that. Relaxing bpf_dev_bound_kfunc_check() for cpumap
> is not trivial, and it changes these kfuncs for existing programs, which
> read the values from the RX descriptor of the bound device.
>
> Signed-off-by: Tianyi Gao <tianyi@cloudflare.com>
> ---
> net/core/xdp.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 91 insertions(+)
>
> diff --git a/net/core/xdp.c b/net/core/xdp.c index
> fdda072a5858..4df3984479a7 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -1081,6 +1081,15 @@ static const void *xdp_skb_ext_get(const struct
> xdp_skb_ext *ext,
> return (const void *)ext + off * XDP_SKB_EXT_ALIGN; }
>
> +static const void *xdp_skb_ext_load(const struct xdp_md *ctx,
> + enum xdp_skb_ext_id id)
> +{
> + const struct xdp_buff *xdp = (const struct xdp_buff *)ctx;
> + const struct xdp_skb_ext *ext = xdp_buff_skb_ext(xdp);
> +
> + return ext ? xdp_skb_ext_get(ext, id) : NULL; }
> +
> /**
> * xdp_skb_ext_to_skb - Set the stored RX metadata on an skb.
> * @skb: The skb that is built from the packet.
> @@ -1296,6 +1305,85 @@ __bpf_kfunc int bpf_xdp_skb_ext_del(struct xdp_md
> *ctx, enum xdp_skb_ext_id id)
> return 0;
> }
>
> +/**
> + * bpf_xdp_skb_ext_load_rx_hash - Load the stored RX hash of this
> packet.
> + * @ctx: XDP context pointer.
> + * @hash: Return value pointer.
> + * @rss_type: Return value pointer for RSS type, see &enum
> xdp_rss_hash_type.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + * * ``-ENODATA`` : the RX hash is not stored */ __bpf_kfunc int
> +bpf_xdp_skb_ext_load_rx_hash(const struct xdp_md *ctx,
> + u32 *hash,
> + enum xdp_rss_hash_type
> *rss_type) {
> + const struct xdp_skb_ext_hash *entry;
> +
> + entry = xdp_skb_ext_load(ctx, XDP_SKB_EXT_HASH);
> + if (!entry)
> + return -ENODATA;
> +
> + *hash = entry->val;
> + *rss_type = entry->type;
> +
> + return 0;
> +}
> +
> +/**
> + * bpf_xdp_skb_ext_load_rx_vlan - Load the stored VLAN tag of this
> packet.
> + * @ctx: XDP context pointer.
> + * @vlan_proto: Return value pointer for the TPID, in network byte
> order.
> + * @vlan_tci: Return value pointer for the TCI, in host byte order.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + * * ``-ENODATA`` : the VLAN tag is not stored */ __bpf_kfunc int
> +bpf_xdp_skb_ext_load_rx_vlan(const struct xdp_md *ctx,
> + __be16 *vlan_proto, u16
> *vlan_tci) {
> + const struct xdp_skb_ext_vlan *entry;
> +
> + entry = xdp_skb_ext_load(ctx, XDP_SKB_EXT_VLAN);
> + if (!entry)
> + return -ENODATA;
> +
> + *vlan_proto = entry->proto;
> + *vlan_tci = entry->tci;
> +
> + return 0;
> +}
> +
> +/**
> + * bpf_xdp_skb_ext_load_rx_csum - Load the stored RX checksum status of
> this
> + * packet.
> + * @ctx: XDP context pointer.
> + * @ip_summed: Return value pointer, ``XDP_CHECKSUM_NONE`` or
> + * ``XDP_CHECKSUM_UNNECESSARY``.
> + * @csum_level: Return value pointer for the checksum level.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + * * ``-ENODATA`` : the checksum status is not stored */ __bpf_kfunc
> +int bpf_xdp_skb_ext_load_rx_csum(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u8 *csum_level)
> +{
> + const struct xdp_skb_ext_csum *entry;
> +
> + entry = xdp_skb_ext_load(ctx, XDP_SKB_EXT_CSUM);
> + if (!entry)
> + return -ENODATA;
> +
> + *ip_summed = BIT(entry->ip_summed);
> + *csum_level = entry->level;
> +
> + return 0;
> +}
> +
> __bpf_kfunc_end_defs();
>
> BTF_KFUNCS_START(xdp_skb_ext_kfunc_ids)
> @@ -1303,6 +1391,9 @@ 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_store_rx_csum) BTF_ID_FLAGS(func, bpf_xdp_skb_ext_del)
> +BTF_ID_FLAGS(func, bpf_xdp_skb_ext_load_rx_hash) BTF_ID_FLAGS(func,
> +bpf_xdp_skb_ext_load_rx_vlan) BTF_ID_FLAGS(func,
> +bpf_xdp_skb_ext_load_rx_csum)
> 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