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

selftests/bpf: Use vmlinux.h for BPF programs

Some of the bpf test progs still use linux/libc headers.
Let's use vmlinux.h instead like the rest of test progs.
This will also ease cross compiling.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250821030254.398826-1-hengqi.chen@gmail.com

authored by

Hengqi Chen and committed by
Andrii Nakryiko
21aeabb6 78e097fb

+11 -36
+1 -6
tools/testing/selftests/bpf/progs/loop1.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2019 Facebook 3 - #include <linux/sched.h> 4 - #include <linux/ptrace.h> 5 - #include <stdint.h> 6 - #include <stddef.h> 7 - #include <stdbool.h> 8 - #include <linux/bpf.h> 3 + #include "vmlinux.h" 9 4 #include <bpf/bpf_helpers.h> 10 5 #include <bpf/bpf_tracing.h> 11 6
+1 -6
tools/testing/selftests/bpf/progs/loop2.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2019 Facebook 3 - #include <linux/sched.h> 4 - #include <linux/ptrace.h> 5 - #include <stdint.h> 6 - #include <stddef.h> 7 - #include <stdbool.h> 8 - #include <linux/bpf.h> 3 + #include "vmlinux.h" 9 4 #include <bpf/bpf_helpers.h> 10 5 #include <bpf/bpf_tracing.h> 11 6
+1 -6
tools/testing/selftests/bpf/progs/loop3.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // Copyright (c) 2019 Facebook 3 - #include <linux/sched.h> 4 - #include <linux/ptrace.h> 5 - #include <stdint.h> 6 - #include <stddef.h> 7 - #include <stdbool.h> 8 - #include <linux/bpf.h> 3 + #include "vmlinux.h" 9 4 #include <bpf/bpf_helpers.h> 10 5 #include <bpf/bpf_tracing.h> 11 6
+7 -14
tools/testing/selftests/bpf/progs/loop6.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 - #include <linux/ptrace.h> 4 - #include <stddef.h> 5 - #include <linux/bpf.h> 3 + #include <vmlinux.h> 4 + #include <bpf/bpf_core_read.h> 6 5 #include <bpf/bpf_helpers.h> 7 6 #include <bpf/bpf_tracing.h> 8 7 #include "bpf_misc.h" ··· 24 25 25 26 #define SG_CHAIN 0x01UL 26 27 #define SG_END 0x02UL 27 - 28 - struct scatterlist { 29 - unsigned long page_link; 30 - unsigned int offset; 31 - unsigned int length; 32 - }; 33 28 34 29 #define sg_is_chain(sg) ((sg)->page_link & SG_CHAIN) 35 30 #define sg_is_last(sg) ((sg)->page_link & SG_END) ··· 55 62 return sgp; 56 63 } 57 64 58 - int config = 0; 65 + int run_once = 0; 59 66 int result = 0; 60 67 61 68 SEC("kprobe/virtqueue_add_sgs") ··· 66 73 __u64 length1 = 0, length2 = 0; 67 74 unsigned int i, n, len; 68 75 69 - if (config != 0) 76 + if (run_once != 0) 70 77 return 0; 71 78 72 79 for (i = 0; (i < VIRTIO_MAX_SGS) && (i < out_sgs); i++) { 73 80 __sink(out_sgs); 74 81 for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX); 75 82 sgp = __sg_next(sgp)) { 76 - bpf_probe_read_kernel(&len, sizeof(len), &sgp->length); 83 + len = BPF_CORE_READ(sgp, length); 77 84 length1 += len; 78 85 n++; 79 86 } ··· 83 90 __sink(in_sgs); 84 91 for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX); 85 92 sgp = __sg_next(sgp)) { 86 - bpf_probe_read_kernel(&len, sizeof(len), &sgp->length); 93 + len = BPF_CORE_READ(sgp, length); 87 94 length2 += len; 88 95 n++; 89 96 } 90 97 } 91 98 92 - config = 1; 99 + run_once = 1; 93 100 result = length2 - length1; 94 101 return 0; 95 102 }
+1 -4
tools/testing/selftests/bpf/progs/test_overhead.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2019 Facebook */ 3 - #include <stdbool.h> 4 - #include <stddef.h> 5 - #include <linux/bpf.h> 6 - #include <linux/ptrace.h> 3 + #include "vmlinux.h" 7 4 #include <bpf/bpf_helpers.h> 8 5 #include <bpf/bpf_tracing.h> 9 6