]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Use vmlinux.h for BPF programs
authorHengqi Chen <hengqi.chen@gmail.com>
Thu, 21 Aug 2025 03:02:54 +0000 (03:02 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 21 Aug 2025 18:32:25 +0000 (11:32 -0700)
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
tools/testing/selftests/bpf/progs/loop1.c
tools/testing/selftests/bpf/progs/loop2.c
tools/testing/selftests/bpf/progs/loop3.c
tools/testing/selftests/bpf/progs/loop6.c
tools/testing/selftests/bpf/progs/test_overhead.c

index 50e66772c0467c67e18a91cddcb3f4b9745857ce..b0fa26fb476080308cb0e910a10b665f0311d620 100644 (file)
@@ -1,11 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2019 Facebook
-#include <linux/sched.h>
-#include <linux/ptrace.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 
index 947bb7e988c21d9c6a83591fc3477c8b98fde783..0227409d4b0e0c69af1085cd763b6461f625cb9f 100644 (file)
@@ -1,11 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2019 Facebook
-#include <linux/sched.h>
-#include <linux/ptrace.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 
index 717dab14322be5bef64b9205061169dd602bdaa3..5d1c9a775e6bbbf4fc74c0dcf63973f78c4b1b99 100644 (file)
@@ -1,11 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2019 Facebook
-#include <linux/sched.h>
-#include <linux/ptrace.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <linux/bpf.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 
index e4ff97fbcce184ed34690e5539e785d0ddd50d53..dd36aff4fba360398e8afc96bb8373a6e554a23f 100644 (file)
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <linux/ptrace.h>
-#include <stddef.h>
-#include <linux/bpf.h>
+#include <vmlinux.h>
+#include <bpf/bpf_core_read.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include "bpf_misc.h"
@@ -26,12 +25,6 @@ char _license[] SEC("license") = "GPL";
 #define SG_CHAIN       0x01UL
 #define SG_END         0x02UL
 
-struct scatterlist {
-       unsigned long   page_link;
-       unsigned int    offset;
-       unsigned int    length;
-};
-
 #define sg_is_chain(sg)                ((sg)->page_link & SG_CHAIN)
 #define sg_is_last(sg)         ((sg)->page_link & SG_END)
 #define sg_chain_ptr(sg)       \
@@ -62,7 +55,7 @@ static inline struct scatterlist *get_sgp(struct scatterlist **sgs, int i)
        return sgp;
 }
 
-int config = 0;
+int run_once = 0;
 int result = 0;
 
 SEC("kprobe/virtqueue_add_sgs")
@@ -73,14 +66,14 @@ int BPF_KPROBE(trace_virtqueue_add_sgs, void *unused, struct scatterlist **sgs,
        __u64 length1 = 0, length2 = 0;
        unsigned int i, n, len;
 
-       if (config != 0)
+       if (run_once != 0)
                return 0;
 
        for (i = 0; (i < VIRTIO_MAX_SGS) && (i < out_sgs); i++) {
                __sink(out_sgs);
                for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX);
                     sgp = __sg_next(sgp)) {
-                       bpf_probe_read_kernel(&len, sizeof(len), &sgp->length);
+                       len = BPF_CORE_READ(sgp, length);
                        length1 += len;
                        n++;
                }
@@ -90,13 +83,13 @@ int BPF_KPROBE(trace_virtqueue_add_sgs, void *unused, struct scatterlist **sgs,
                __sink(in_sgs);
                for (n = 0, sgp = get_sgp(sgs, i); sgp && (n < SG_MAX);
                     sgp = __sg_next(sgp)) {
-                       bpf_probe_read_kernel(&len, sizeof(len), &sgp->length);
+                       len = BPF_CORE_READ(sgp, length);
                        length2 += len;
                        n++;
                }
        }
 
-       config = 1;
+       run_once = 1;
        result = length2 - length1;
        return 0;
 }
index abb7344b531f4536fd000ba716c8d953188f0307..5edf3cdc213d0441f1dff2c7ab57a5967d9338e3 100644 (file)
@@ -1,9 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2019 Facebook */
-#include <stdbool.h>
-#include <stddef.h>
-#include <linux/bpf.h>
-#include <linux/ptrace.h>
+#include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>