[PATCH bpf-next 0/2] Clarify and Enhance XDP Rx Metadata Handling

From: Song Yoong Siang
Date: Tue Jul 01 2025 - 00:30:55 EST


This patch set improves the documentation and selftests for XDP Rx metadata
handling. The first patch clarifies the documentation around XDP metadata
layout and the use of bpf_xdp_adjust_meta. The second patch enhances the
BPF selftests to make XDP metadata handling more robust and portable across
different NICs.

Prior to this patch set, the user application retrieved the xdp_meta by
calculating backward from the data pointer, while the XDP program fill in
the xdp_meta by calculating backward from data_meta. This approach will
cause mismatch if there is device-reserved metadata.

|<---sizeof(xdp_meta)--|
| |
struct xdp_meta rx_desc->address
^ ^
| |
+----------+----------------------+------------+------+
| headroom | custom metadata | reserved | data |
+----------+----------------------+------------+------+
^ ^ ^
| | |
struct xdp_meta xdp_buff->data_meta xdp_buff->data
| |
|<---sizeof(xdp_meta)--|

Song Yoong Siang (2):
doc: clarify XDP Rx metadata layout and bpf_xdp_adjust_meta usage
selftests/bpf: Enhance XDP Rx Metadata Handling

Documentation/networking/xdp-rx-metadata.rst | 38 +++++++++++++++++++
.../selftests/bpf/prog_tests/xdp_metadata.c | 2 +-
.../selftests/bpf/progs/xdp_hw_metadata.c | 10 ++++-
.../selftests/bpf/progs/xdp_metadata.c | 8 +++-
tools/testing/selftests/bpf/xdp_hw_metadata.c | 2 +-
tools/testing/selftests/bpf/xdp_metadata.h | 7 ++++
6 files changed, 63 insertions(+), 4 deletions(-)

--
2.34.1