]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/bpf: Make test_tc_tunnel.bpf.c compatible with big endian platforms
authorAlexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Mon, 27 Oct 2025 14:51:54 +0000 (15:51 +0100)
committerMartin KaFai Lau <martin.lau@kernel.org>
Wed, 29 Oct 2025 18:07:26 +0000 (11:07 -0700)
commit86433db9325693561794ac8072732cda1167a1ac
treef5a57ba8c5e3286b4b587f3295496ab569a4bff1
parent1d5137c8d1ace4b85c458b5efe524c83d2f2ef72
selftests/bpf: Make test_tc_tunnel.bpf.c compatible with big endian platforms

When trying to run bpf-based encapsulation in a s390x environment, some
parts of test_tc_tunnel.bpf.o do not encapsulate correctly the traffic,
leading to tests failures. Adding some logs shows for example that
packets about to be sent on an interface with the ip6vxlan_eth program
attached do not have the expected value 5 in the ip header ihl field,
and so are ignored by the program.

This phenomenon appears when trying to cross-compile the selftests,
rather than compiling it from a virtualized host: the selftests build
system may then wrongly pick some host headers. If <asm/byteorder.h>
ends up being picked on the host (and if the host has a endianness
different from the target one), it will then expose wrong endianness
defines (e.g __LITTLE_ENDIAN_BITFIELD instead of __BIT_ENDIAN_BITFIELD),
and it will for example mess up the iphdr structure layout used in the
ebpf program.

To prevent this, directly use the vmlinux.h header generated by the
selftests build system rather than including directly specific kernel
headers. As a consequence, add some missing definitions that are not
exposed by vmlinux.h, and adapt the bitfield manipulations to allow
building and using the program on both types of platforms.

Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20251027-tc_tunnel-v3-2-505c12019f9d@bootlin.com
tools/testing/selftests/bpf/progs/test_tc_tunnel.c