linux-yocto/tools
Amery Hung d08b4193cd bpf: Support specifying linear xdp packet data size for BPF_PROG_TEST_RUN
[ Upstream commit fe9544ed1a ]

To test bpf_xdp_pull_data(), an xdp packet containing fragments as well
as free linear data area after xdp->data_end needs to be created.
However, bpf_prog_test_run_xdp() always fills the linear area with
data_in before creating fragments, leaving no space to pull data. This
patch will allow users to specify the linear data size through
ctx->data_end.

Currently, ctx_in->data_end must match data_size_in and will not be the
final ctx->data_end seen by xdp programs. This is because ctx->data_end
is populated according to the xdp_buff passed to test_run. The linear
data area available in an xdp_buff, max_linear_sz, is alawys filled up
before copying data_in into fragments.

This patch will allow users to specify the size of data that goes into
the linear area. When ctx_in->data_end is different from data_size_in,
only ctx_in->data_end bytes of data will be put into the linear area when
creating the xdp_buff.

While ctx_in->data_end will be allowed to be different from data_size_in,
it cannot be larger than the data_size_in as there will be no data to
copy from user space. If it is larger than the maximum linear data area
size, the layout suggested by the user will not be honored. Data beyond
max_linear_sz bytes will still be copied into fragments.

Finally, since it is possible for a NIC to produce a xdp_buff with empty
linear data area, allow it when calling bpf_test_init() from
bpf_prog_test_run_xdp() so that we can test XDP kfuncs with such
xdp_buff. This is done by moving lower-bound check to callers as most of
them already do except bpf_prog_test_run_skb(). The change also fixes a
bug that allows passing an xdp_buff with data < ETH_HLEN. This can
happen when ctx is used and metadata is at least ETH_HLEN.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20250922233356.3356453-7-ameryhung@gmail.com
Stable-dep-of: e558cca21779 ("bpf, test_run: Subtract size of xdp_frame from allowed metadata size")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2026-01-17 16:30:01 +01:00
..
accounting
arch x86/rdrand: Disable RDSEED on AMD Cyan Skillfish 2025-07-17 18:35:15 +02:00
bootconfig tools/bootconfig: Fix the wrong format specifier 2025-02-08 09:52:28 +01:00
bpf bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21 2025-11-24 10:29:22 +01:00
build tools build: Align warning options with perf 2025-10-19 16:30:43 +02:00
certs
cgroup
counter
crypto/ccp crypto: ccp - Fix some unfused tests 2023-11-20 11:59:18 +01:00
debugging
edid
firewire
firmware
gpio tools: gpio: remove the include directory on make clean 2025-09-09 18:56:34 +02:00
hv tools: hv: change permissions of NetworkManager configuration file 2024-12-27 13:58:46 +01:00
iio tools/iio: Add memory allocation failure check for trigger_name 2024-10-17 15:24:20 +02:00
include tools/nolibc/stdio: let perror work when NOLIBC_IGNORE_ERRNO is set 2026-01-11 15:21:17 +01:00
kvm/kvm_stat
laptop
leds
lib libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map 2026-01-11 15:21:53 +01:00
memory-model tools/memory-model: Fix bug in lock.cat 2024-08-03 08:54:21 +02:00
mm tools/mm/page_owner_sort: fix timestamp comparison for stable sorting 2026-01-11 15:22:17 +01:00
net/ynl tools: ynl-gen: validate 0 len strings from kernel 2025-06-04 14:42:16 +02:00
objtool objtool: Fix weak symbol detection 2026-01-11 15:21:13 +01:00
pci
pcmcia
perf perf tools: Fix split kallsyms DSO counting 2026-01-11 15:21:35 +01:00
power tools/power x86_energy_perf_policy: Prefer driver HWP limits 2025-11-24 10:29:23 +01:00
rcu
scripts tools/build: Fix s390(x) cross-compilation with clang 2025-08-28 16:28:17 +02:00
spi
testing bpf: Support specifying linear xdp packet data size for BPF_PROG_TEST_RUN 2026-01-17 16:30:01 +01:00
thermal
time
tracing tracing/tools: Fix incorrcet short option in usage text for --threads 2025-12-01 11:41:51 +01:00
usb usbip: tools: Fix detach_port() invalid port error path 2024-11-08 16:28:22 +01:00
verification tools/rv: Do not skip idle in trace 2025-08-15 12:08:49 +02:00
virtio
wmi
workqueue
Makefile