[Intel-wired-lan] [PATCH bpf-next v3 5/5] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog

Lorenzo Bianconi
2026-02-17T08:34:53Z

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 <lorenzo@kernel.org>
---
.../testing/selftests/bpf/progs/xdp_hw_metadata.c | 8 +++++++
tools/testing/selftests/bpf/xdp_hw_metadata.c | 25 ++++++++++++++++++++++
tools/testing/selftests/bpf/xdp_metadata.h | 10 ++++++---
3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
index 330ece2eabdb454da2bb2cbd297d2b2dd6efddc0..9113288fce54bb39dbb6b38e1f6badd0a8ef4cde 100644
--- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
@@ -110,6 +110,14 @@ int rx(struct xdp_md *ctx)
else
meta->hint_valid |= XDP_META_FIELD_VLAN_TAG;

+ err = bpf_xdp_metadata_rx_checksum(ctx,
+ (enum xdp_checksum *)&meta->ip_summed,
+ &meta->cksum_meta);
+ 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 3d8de0d4c96a7afdf5f60b2fdff73c22b876ce54..f1cf8490cc497b5dd75b8d839918fb85c2a0684d 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,25 @@ 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_meta)
+{
+ const char *cksum = "CHECKSUM_NONE";
+
+ switch (ip_summed) {
+ case XDP_CHECKSUM_UNNECESSARY:
+ cksum = "CHECKSUM_UNNECESSARY";
+ break;
+ case XDP_CHECKSUM_COMPLETE:
+ cksum = "CHECKSUM_COMPLETE";
+ break;
+ case XDP_CHECKSUM_NONE:
+ default:
+ break;
+ }
+
+ printf("rx-cksum: %s, csum_meta=0x%x\n", cksum, cksum_meta);
+}
+
static void verify_xdp_metadata(void *data, clockid_t clock_id)
{
struct xdp_meta *meta;
@@ -254,6 +274,11 @@ 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);
+ 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 837cd1efe6b5aebd0f62bae4c49d5bfd77db64bc..822e34390582b3d3660a25e725c9a622edbf635c 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 0
@@ -52,9 +53,12 @@ struct xdp_meta {
};
__s32 rx_vlan_tag_err;
};
- struct {
- __u8 ip_summed;
- __u32 cksum_meta;
+ union {
+ struct {
+ __u8 ip_summed;
+ __u32 cksum_meta;
+ };
+ __s32 rx_cksum_err;
};
enum xdp_meta_field hint_valid;
};

--
2.53.0