> -----Original Message-----
> From: Tianyi Gao <[email protected]>
> Sent: Tuesday, November 10, 2026 4:57 AM
> To: [email protected]; [email protected]; Alexei Starovoitov
> <[email protected]>; Daniel Borkmann <[email protected]>; Andrii
> Nakryiko <[email protected]>; Martin KaFai Lau <[email protected]>;
> Jakub Kicinski <[email protected]>; Jesper Dangaard Brouer
> <[email protected]>
> Cc: John Fastabend <[email protected]>; Stanislav Fomichev
> <[email protected]>; Lorenzo Bianconi <[email protected]>; Vladimir
> Vdovin <[email protected]>; David S. Miller <[email protected]>; Eric
> Dumazet <[email protected]>; Paolo Abeni <[email protected]>; Simon
> Horman <[email protected]>; Andrew Lunn <[email protected]>; Donald
> Hunter <[email protected]>; Eduard Zingerman <[email protected]>;
> Kumar Kartikeya Dwivedi <[email protected]>; Song Liu <[email protected]>;
> Yonghong Song <[email protected]>; Jiri Olsa <[email protected]>;
> Emil Tsalapatis <[email protected]>; Ihor Solodrai
> <[email protected]>; Nguyen, Anthony L
> <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>; Fijalkowski, Maciej
> <[email protected]>; Lobakin, Aleksander
> <[email protected]>; Karlsson, Magnus
> <[email protected]>; Vyavahare, Tushar
> <[email protected]>; Jason Xing <[email protected]>;
> Nikolay Aleksandrov <[email protected]>; Madalin Bucur
> <[email protected]>; Ioana Ciornei <[email protected]>; Jonathan
> Corbet <[email protected]>; Shuah Khan <[email protected]>; Shuah
> Khan <[email protected]>; Randy Dunlap <[email protected]>; Nathan
> Chancellor <[email protected]>; Nick Desaulniers
> <[email protected]>; Bill Wendling <[email protected]>; Justin
> Stitt <[email protected]>; Chris J Arges <[email protected]>;
> Jakub Sitnicki <[email protected]>; [email protected]; linux-
> [email protected]; [email protected];
> [email protected]; [email protected]; Tianyi Gao
> <[email protected]>
> Subject: [PATCH bpf-next 14/15] selftests/bpf: Test the load kfuncs on
> cpumap and veth
> 
> Add a test for the load kfuncs on each path of the xdp_skb_ext_to_skb
> test. On XDP_PASS, the program that stores the values reads them back.
> On cpumap and veth, the program after the redirect reads them. Each test
> case compares them with the stored values. A load that finds no entry,
> also after bpf_xdp_skb_ext_del(), must return -ENODATA.
> 
> With BPF_F_TEST_XDP_LIVE_FRAMES, a recycled page still holds the entries
> of the previous packet. The live_frames test checks that a load returns
> -ENODATA there.
> 
> Signed-off-by: Tianyi Gao <[email protected]>
> ---
>  .../selftests/bpf/prog_tests/xdp_skb_ext.c    | 47 +++++++++++------
>  .../selftests/bpf/progs/test_xdp_skb_ext.c    | 50 ++++++++++++++++++-
>  tools/testing/selftests/bpf/xdp_skb_ext.h     |  2 +-
>  3 files changed, 81 insertions(+), 18 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_skb_ext.c
> b/tools/testing/selftests/bpf/prog_tests/xdp_skb_ext.c
> index 64c6f0268d60..0811c09b7747 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_skb_ext.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_skb_ext.c
> @@ -7,7 +7,6 @@
>  #include "test_xdp_skb_ext.skel.h"
>  #include "xdp_skb_ext_success.skel.h"
>  #include "xdp_skb_ext_failure.skel.h"
> -#include "xdp_dummy.skel.h"
> 
>  #define XDP_RSS_TYPE_L3_IPV4 BIT(0)
>  #define XDP_RSS_TYPE_L4 BIT(3)
> @@ -167,7 +166,9 @@ static void set_case(struct test_xdp_skb_ext *skel,
>       skel->bss->want = c->want;
>       skel->bss->del_hash = c->del_hash;
>       memset(&skel->bss->have, 0, sizeof(skel->bss->have));
> +     memset(&skel->bss->loaded, 0, sizeof(skel->bss->loaded));
>       skel->bss->store_err = 0;
> +     skel->bss->load_err = 0;
>       skel->bss->pkts_seen_tc = 0;
>  }
> 
> @@ -191,8 +192,6 @@ static void check_have(struct test_xdp_skb_ext
> *skel)
>       bool unnecessary = (want->fields & SKB_EXT_FIELD_CSUM) &&
>                          want->ip_summed == XDP_CHECKSUM_UNNECESSARY;
> 
> -     if (!wait_pkt(skel))
> -             return;
>       ASSERT_EQ(skel->bss->store_err, 0, "store_err");
>       ASSERT_EQ(have->hash, want->rx_hash, "hash");
>       ASSERT_EQ(have->l4_hash, !!(want->rx_hash_type &
> XDP_RSS_TYPE_L4), @@ -208,6 +207,24 @@ static void check_have(struct
> test_xdp_skb_ext *skel)
>                 "csum_level");
>  }
> 
> +static void check_loaded(struct test_xdp_skb_ext *skel) {
> +     const struct xdp_skb_ext_vals *want = &skel->bss->want;
> +     const struct xdp_skb_ext_vals *loaded = &skel->bss->loaded;
> +
> +     ASSERT_EQ(skel->bss->load_err, 0, "load_err");
> +     ASSERT_EQ(loaded->fields, want->fields, "loaded_fields");
> +     ASSERT_EQ(loaded->rx_hash, want->rx_hash, "loaded_rx_hash");
> +     ASSERT_EQ(loaded->rx_hash_type, want->rx_hash_type,
> +               "loaded_rx_hash_type");
> +     ASSERT_EQ(loaded->rx_vlan_proto, want->rx_vlan_proto,
> +               "loaded_rx_vlan_proto");
> +     ASSERT_EQ(loaded->rx_vlan_tci, want->rx_vlan_tci,
> +               "loaded_rx_vlan_tci");
> +     ASSERT_EQ(loaded->ip_summed, want->ip_summed,
> "loaded_ip_summed");
> +     ASSERT_EQ(loaded->csum_level, want->csum_level,
> "loaded_csum_level");
> +}
> +
>  static void test_frames(struct test_xdp_skb_ext *skel, const char
> *path,
>                       enum xdp_skb_ext_deliver deliver, int ifindex)  {
> @@ -232,9 +249,12 @@ static void test_frames(struct test_xdp_skb_ext
> *skel, const char *path,
>               if (!test__start_subtest(name))
>                       continue;
>               set_case(skel, &skb_ext_cases[i]);
> -             if (ASSERT_OK(bpf_prog_test_run_opts(prog_fd, &opts),
> -                           "test_run"))
> -                     check_have(skel);
> +             if (!ASSERT_OK(bpf_prog_test_run_opts(prog_fd, &opts),
> +                            "test_run") ||
> +                 !wait_pkt(skel))
> +                     continue;
> +             check_have(skel);
> +             check_loaded(skel);
>       }
>  }
> 
> @@ -266,6 +286,7 @@ static void test_veth_skb(struct test_xdp_skb_ext
> *skel, struct bpf_link *link,
>               goto out;
>       if (deliver == DELIVER_CPUMAP) {
>               check_have(skel);
> +             check_loaded(skel);
>               goto out;
>       }
>       ASSERT_EQ(skel->bss->store_err, 0, "store_err"); @@ -275,6 +296,7
> @@ static void test_veth_skb(struct test_xdp_skb_ext *skel, struct
> bpf_link *link,
>       ASSERT_EQ(have->vlan_tci, 0, "vlan_tci");
>       ASSERT_EQ(have->ip_summed, CHECKSUM_NONE, "ip_summed");
>       ASSERT_EQ(have->csum_level, 0, "csum_level");
> +     check_loaded(skel);
>  out:
>       close(sock);
>  }
> @@ -292,7 +314,6 @@ void test_xdp_skb_ext_to_skb(void)  {
>       struct bpf_cpumap_val val = { .qsize = 192 };
>       int ifindex_src, ifindex_dst, tc_prog_fd;
> -     struct xdp_dummy *skel_dummy = NULL;
>       struct test_xdp_skb_ext *skel = NULL;
>       struct bpf_link *link = NULL;
>       struct netns_obj *ns = NULL;
> @@ -330,18 +351,13 @@ void test_xdp_skb_ext_to_skb(void)
>           tc_prog_attach("veth_dst", tc_prog_fd, -1))
>               goto out;
> 
> +     val.bpf_prog.fd = bpf_program__fd(skel->progs.cpumap_load);
>       if (!ASSERT_OK(bpf_map_update_elem(bpf_map__fd(skel-
> >maps.cpu_map),
>                                          &key, &val, 0), "add cpumap
> entry"))
>               goto out;
> 
> -     skel_dummy = xdp_dummy__open_and_load();
> -     if (!ASSERT_OK_PTR(skel_dummy, "xdp_dummy__open_and_load"))
> -             goto out;
> -
> -     /* veth_dst takes xdp_frames only with an XDP program */
> -     link = bpf_program__attach_xdp(skel_dummy->progs.xdp_dummy_prog,
> -                                    ifindex_dst);
> -     if (!ASSERT_OK_PTR(link, "attach xdp_dummy"))
> +     link = bpf_program__attach_xdp(skel->progs.veth_load,
> ifindex_dst);
> +     if (!ASSERT_OK_PTR(link, "attach veth_load"))
>               goto out;
> 
>       test_frames(skel, "pass", DELIVER_PASS, ifindex_src); @@ -354,7
> +370,6 @@ void test_xdp_skb_ext_to_skb(void)
> 
>  out:
>       bpf_link__destroy(link);
> -     xdp_dummy__destroy(skel_dummy);
>       test_xdp_skb_ext__destroy(skel);
>       netns_free(ns);
>  }
> diff --git a/tools/testing/selftests/bpf/progs/test_xdp_skb_ext.c
> b/tools/testing/selftests/bpf/progs/test_xdp_skb_ext.c
> index a63206ff993d..34db1a986f3b 100644
> --- a/tools/testing/selftests/bpf/progs/test_xdp_skb_ext.c
> +++ b/tools/testing/selftests/bpf/progs/test_xdp_skb_ext.c
> @@ -1,5 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #include <vmlinux.h>
> +#include <errno.h>
>  #include "xdp_skb_ext.h"
>  #include <bpf/bpf_endian.h>
>  #include <bpf/bpf_helpers.h>
> @@ -14,6 +15,8 @@ SEC("xdp")
>  int live_frames(struct xdp_md *ctx)
>  {
>       __u8 *mark = (void *)(long)ctx->data;
> +     enum xdp_rss_hash_type rss_type;
> +     __u32 hash;
> 
>       if (mark + 1 > (__u8 *)(long)ctx->data_end)
>               return XDP_DROP;
> @@ -25,6 +28,9 @@ int live_frames(struct xdp_md *ctx)
>                       reused_ok++;
>                       bpf_xdp_adjust_meta(ctx, MAX_META_LEN);
>               }
> +             if (bpf_xdp_skb_ext_load_rx_hash(ctx, &hash, &rss_type) !=
> +                 -ENODATA)
> +                     reused_bad++;
>       }
>       if (bpf_xdp_skb_ext_store_rx_hash(ctx, 1,
> XDP_RSS_TYPE_L4_IPV4_TCP) ||
>           bpf_xdp_skb_ext_store_rx_vlan(ctx, bpf_htons(ETH_P_8021Q), 1)
> || @@ -51,7 +57,34 @@ enum xdp_skb_ext_deliver deliver;  struct
> xdp_skb_ext_vals want;  bool del_hash;  struct xdp_skb_ext_have have; -
> int pkts_seen_tc;
> +struct xdp_skb_ext_vals loaded;
> +int pkts_seen_tc, load_err;
> +
> +static void load_all(struct xdp_md *ctx) {
> +     int err;
> +
> +     err = bpf_xdp_skb_ext_load_rx_hash(ctx, &loaded.rx_hash,
> +                                        &loaded.rx_hash_type);
> +     if (!err)
> +             loaded.fields |= SKB_EXT_FIELD_HASH;
> +     else if (err != -ENODATA)
> +             load_err++;
> +
> +     err = bpf_xdp_skb_ext_load_rx_vlan(ctx, &loaded.rx_vlan_proto,
> +                                        &loaded.rx_vlan_tci);
> +     if (!err)
> +             loaded.fields |= SKB_EXT_FIELD_VLAN;
> +     else if (err != -ENODATA)
> +             load_err++;
> +
> +     err = bpf_xdp_skb_ext_load_rx_csum(ctx, &loaded.ip_summed,
> +                                        &loaded.csum_level);
> +     if (!err)
> +             loaded.fields |= SKB_EXT_FIELD_CSUM;
> +     else if (err != -ENODATA)
> +             load_err++;
> +}
> 
>  SEC("xdp")
>  int xdp_store(struct xdp_md *ctx)
> @@ -99,6 +132,21 @@ int xdp_store(struct xdp_md *ctx)
>               return bpf_redirect_map(&cpu_map, 0, 0);
>       if (deliver == DELIVER_VETH)
>               return bpf_redirect(ifindex_out, 0);
> +     load_all(ctx);
> +     return XDP_PASS;
> +}
> +
> +SEC("xdp/cpumap")
> +int cpumap_load(struct xdp_md *ctx)
> +{
> +     load_all(ctx);
> +     return XDP_PASS;
> +}
> +
> +SEC("xdp")
> +int veth_load(struct xdp_md *ctx)
> +{
> +     load_all(ctx);
>       return XDP_PASS;
>  }
> 
> diff --git a/tools/testing/selftests/bpf/xdp_skb_ext.h
> b/tools/testing/selftests/bpf/xdp_skb_ext.h
> index 11feee2fa31c..64d4a0511d0a 100644
> --- a/tools/testing/selftests/bpf/xdp_skb_ext.h
> +++ b/tools/testing/selftests/bpf/xdp_skb_ext.h
> @@ -30,7 +30,7 @@ enum xdp_skb_ext_deliver {
>       DELIVER_VETH,
>  };
> 
> -/* The entries that the XDP program stores */
> +/* The entries that the XDP programs store or load */
>  struct xdp_skb_ext_vals {
>       __u32 rx_hash;
>       __u32 rx_hash_type;
> --
> 2.56.0

Reviewed-by: Aleksandr Loktionov <[email protected]>

Reply via email to