Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Update xdp_context_test_run test to check maximum metadata size

Update the selftest to check that the metadata size check takes the
xdp_frame size into account in bpf_prog_test_run. The original
check (for meta size 256) was broken because the data frame supplied was
smaller than this, triggering a different EINVAL return. So supply a
larger data frame for this test to make sure we actually exercise the
check we think we are.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Reviewed-by: Amery Hung <ameryhung@gmail.com>
Link: https://lore.kernel.org/r/20260105114747.1358750-2-toke@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Toke Høiland-Jørgensen and committed by
Alexei Starovoitov
ab86d0bf e558cca2

+11 -3
+11 -3
tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c
··· 47 47 struct test_xdp_context_test_run *skel = NULL; 48 48 char data[sizeof(pkt_v4) + sizeof(__u32)]; 49 49 char bad_ctx[sizeof(struct xdp_md) + 1]; 50 + char large_data[256]; 50 51 struct xdp_md ctx_in, ctx_out; 51 52 DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, 52 53 .data_in = &data, ··· 95 94 test_xdp_context_error(prog_fd, opts, 4, sizeof(__u32), sizeof(data), 96 95 0, 0, 0); 97 96 98 - /* Meta data must be 255 bytes or smaller */ 99 - test_xdp_context_error(prog_fd, opts, 0, 256, sizeof(data), 0, 0, 0); 100 - 101 97 /* Total size of data must be data_end - data_meta or larger */ 102 98 test_xdp_context_error(prog_fd, opts, 0, sizeof(__u32), 103 99 sizeof(data) + 1, 0, 0, 0); ··· 113 115 /* The egress cannot be specified */ 114 116 test_xdp_context_error(prog_fd, opts, 0, sizeof(__u32), sizeof(data), 115 117 0, 0, 1); 118 + 119 + /* Meta data must be 216 bytes or smaller (256 - sizeof(struct 120 + * xdp_frame)). Test both nearest invalid size and nearest invalid 121 + * 4-byte-aligned size, and make sure data_in is large enough that we 122 + * actually hit the check on metadata length 123 + */ 124 + opts.data_in = large_data; 125 + opts.data_size_in = sizeof(large_data); 126 + test_xdp_context_error(prog_fd, opts, 0, 217, sizeof(large_data), 0, 0, 0); 127 + test_xdp_context_error(prog_fd, opts, 0, 220, sizeof(large_data), 0, 0, 0); 116 128 117 129 test_xdp_context_test_run__destroy(skel); 118 130 }