> -----Original Message-----
> From: Vladimir Vdovin <[email protected]>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <[email protected]>; Donald Hunter
> <[email protected]>; Jakub Kicinski <[email protected]>; David S .
> Miller <[email protected]>; Eric Dumazet <[email protected]>;
> Paolo Abeni <[email protected]>; Simon Horman <[email protected]>;
> Alexei Starovoitov <[email protected]>; Daniel Borkmann
> <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John
> Fastabend <[email protected]>; Stanislav Fomichev
> <[email protected]>; Andrew Lunn <[email protected]>; Nguyen,
> Anthony L <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>; Lobakin, Aleksander
> <[email protected]>; Andrii Nakryiko <[email protected]>;
> Martin KaFai Lau <[email protected]>; Eduard Zingerman
> <[email protected]>; Song Liu <[email protected]>; Yonghong Song
> <[email protected]>; KP Singh <[email protected]>; Hao Luo
> <[email protected]>; Jiri Olsa <[email protected]>; Shuah Khan
> <[email protected]>; Fijalkowski, Maciej <[email protected]>
> Cc: Jakub Sitnicki <[email protected]>; Loktionov, Aleksandr
> <[email protected]>; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; Vladimir Vdovin <[email protected]>
> Subject: [PATCH bpf-next v4 5/6] selftests/bpf: Add
> bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
> 
> From: Lorenzo Bianconi <[email protected]>
> 
> Introduce the capability to dump HW rx checksum in xdp_hw_metadata
> program via bpf_xdp_metadata_rx_checksum() kfunc.
> 
> Signed-off-by: Lorenzo Bianconi <[email protected]>
> Signed-off-by: Vladimir Vdovin <[email protected]>
> ---
>  .../selftests/bpf/progs/xdp_hw_metadata.c     |  7 +++++
>  tools/testing/selftests/bpf/xdp_hw_metadata.c | 31
> +++++++++++++++++++
>  tools/testing/selftests/bpf/xdp_metadata.h    | 12 ++++---
>  3 files changed, 46 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> index 330ece2eabdb..5eeadb7e27cf 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> @@ -110,6 +110,13 @@ int rx(struct xdp_md *ctx)
>       else
>               meta->hint_valid |= XDP_META_FIELD_VLAN_TAG;
> 
> +     err = bpf_xdp_metadata_rx_checksum(ctx, &meta->ip_summed,
> +                                        &meta->cksum, &meta-
> >cksum_level);
> +     if (err)
> +             meta->rx_cksum_err = err;
> +     else
> +             meta->hint_valid |= XDP_META_FIELD_CHECKSUM;
> +
>       __sync_add_and_fetch(&pkts_redir, 1);
>       return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
> } diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c
> b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> index 6db3b5555a22..c63a70a54075 100644
> --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> @@ -8,6 +8,7 @@
>   * - Metadata verified:
>   *   - rx_timestamp
>   *   - rx_hash
> + *   - rx_checksum
>   *
>   * TX:
>   * - UDP 9091 packets trigger TX reply
> @@ -219,6 +220,30 @@ static void print_vlan_tci(__u16 tag)
>       printf("PCP=%u, DEI=%d, VID=0x%X\n", pcp, dei, vlan_id);  }
> 
> +static void print_rx_cksum(__u8 ip_summed, __u32 cksum, __u8
> +cksum_level) {
> +     const char *cksum_str;
> +
> +     switch (ip_summed) {
> +     case XDP_CHECKSUM_COMPLETE | XDP_CHECKSUM_UNNECESSARY:
> +             cksum_str = "CHECKSUM_COMPLETE,CHECKSUM_UNNECESSARY";
> +             break;
> +     case XDP_CHECKSUM_UNNECESSARY:
> +             cksum_str = "CHECKSUM_UNNECESSARY";
> +             break;
> +     case XDP_CHECKSUM_COMPLETE:
> +             cksum_str = "CHECKSUM_COMPLETE";
> +             break;
> +     case XDP_CHECKSUM_NONE:
> +     default:
> +             cksum_str = "CHECKSUM_NONE";
> +             break;
> +     }
> +
> +     printf("rx-cksum: %s, csum=0x%x, cksum_level=0x%x\n",
> +            cksum_str, cksum, cksum_level); }
> +
>  static void verify_xdp_metadata(void *data, clockid_t clock_id)  {
>       struct xdp_meta *meta;
> @@ -254,6 +279,12 @@ static void verify_xdp_metadata(void *data,
> clockid_t clock_id)
>               printf("No rx_vlan_tci or rx_vlan_proto, err=%d\n",
>                      meta->rx_vlan_tag_err);
>       }
> +
> +     if (meta->hint_valid & XDP_META_FIELD_CHECKSUM)
> +             print_rx_cksum(meta->ip_summed, meta->cksum,
> +                            meta->cksum_level);
> +     else
> +             printf("No rx_cksum, err=%d\n", meta->rx_cksum_err);
>  }
> 
>  static void verify_skb_metadata(int fd) diff --git
> a/tools/testing/selftests/bpf/xdp_metadata.h
> b/tools/testing/selftests/bpf/xdp_metadata.h
> index bca09b94af26..f864d4a8bd8c 100644
> --- a/tools/testing/selftests/bpf/xdp_metadata.h
> +++ b/tools/testing/selftests/bpf/xdp_metadata.h
> @@ -28,6 +28,7 @@ enum xdp_meta_field {
>       XDP_META_FIELD_TS       = BIT(0),
>       XDP_META_FIELD_RSS      = BIT(1),
>       XDP_META_FIELD_VLAN_TAG = BIT(2),
> +     XDP_META_FIELD_CHECKSUM = BIT(3),
>  };
> 
>  #define XDP_CHECKSUM_NONE            BIT(0)
> @@ -52,10 +53,13 @@ struct xdp_meta {
>               };
>               __s32 rx_vlan_tag_err;
>       };
> -     struct {
> -             __u32 ip_summed;
> -             __u32 cksum;
> -             __u8 cksum_level;
> +     union {
> +             struct {
> +                     __u32 ip_summed;
> +                     __u32 cksum;
> +                     __u8 cksum_level;
> +             };
> +             __s32 rx_cksum_err;
>       };
>       enum xdp_meta_field hint_valid;
>  };
> --
> 2.47.0

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

Reply via email to