selftests/bpf: Use vmlinux.h for BPF programs
Subsystems (3)
PATCH v2 1/1 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.
--- tools/testing/selftests/bpf/progs/loop1.c | 7 +------ tools/testing/selftests/bpf/progs/loop2.c | 7 +------ tools/testing/selftests/bpf/progs/loop3.c | 7 +------ tools/testing/selftests/bpf/progs/loop6.c | 15 ++++----------- tools/testing/selftests/bpf/progs/test_overhead.c | 5 +---- 5 files changed, 8 insertions(+), 33 deletions(-)
tools/testing/selftests/bpf/progs/loop1.c +1 -6
@@ -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>
tools/testing/selftests/bpf/progs/loop2.c +1 -6
@@ -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>
tools/testing/selftests/bpf/progs/loop3.c +1 -6
@@ -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>
tools/testing/selftests/bpf/progs/loop6.c +4 -11
@@ -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) \
@@ -80,7 +73,7 @@ int BPF_KPROBE(trace_virtqueue_add_sgs, void *unused, struct scatterlist **sgs,__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,7 +83,7 @@ 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++; }
tools/testing/selftests/bpf/progs/test_overhead.c +1 -4
@@ -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>
Signature · 1 line
2.43.5
Quoted 5 lines · Hengqi Chen
Some of the bpf test progs still use linux/libc headers. Let's use
vmlinux.hinstead like the rest of test progs. This will also ease cross compiling.
Quoted 9 lines
Signed-off-by Hengqi Chen <[email protected]>--- tools/testing/selftests/bpf/progs/loop1.c | 7 +------ tools/testing/selftests/bpf/progs/loop2.c | 7 +------ tools/testing/selftests/bpf/progs/loop3.c | 7 +------ tools/testing/selftests/bpf/progs/loop6.c | 15 ++++----------- tools/testing/selftests/bpf/progs/test_overhead.c | 5 +---- 5 files changed, 8 insertions(+), 33 deletions(-)
I'm getting this:
progs/loop6.c:58:5: error: redefinition of 'config' as different kind of symbol
58 | int config = 0;
| CLNG-BPF [test_progs] sock_addr_kern.bpf.o
^
/data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:71906:25:
note: previous definition is here
71906 | typedef struct config_s config;
| ^progs/loop6.c:69:6: error: unexpected type name 'config': expected expression
69 | if (config != 0)
| ^
CLNG-BPF [test_progs] sock_destroy_prog.bpf.oprogs/loop6.c:92:9: error: expected identifier or '('
92 | config = 1;
| ^
So let's rename a too generically named variable?
pw-bot: cr
[...]
Quoted 37 lines · Andrii Nakryiko
Quoted 5 lines · Hengqi Chen
Some of the bpf test progs still use linux/libc headers. Let's use
vmlinux.hinstead like the rest of test progs. This will also ease cross compiling.Quoted 9 lines
Signed-off-by Hengqi Chen <[email protected]>--- tools/testing/selftests/bpf/progs/loop1.c | 7 +------ tools/testing/selftests/bpf/progs/loop2.c | 7 +------ tools/testing/selftests/bpf/progs/loop3.c | 7 +------ tools/testing/selftests/bpf/progs/loop6.c | 15 ++++----------- tools/testing/selftests/bpf/progs/test_overhead.c | 5 +---- 5 files changed, 8 insertions(+), 33 deletions(-)I'm getting this:
progs/loop6.c:58:5: error: redefinition of 'config' as different kind of symbol
58 | int config = 0;
| CLNG-BPF [test_progs] sock_addr_kern.bpf.o
^
/data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:71906:25:
note: previous definition is here
71906 | typedef structconfig_sconfig;
| ^progs/loop6.c:69:6: error: unexpected type name 'config': expected expression
69 | if (config != 0)
| ^
CLNG-BPF [test_progs] sock_destroy_prog.bpf.oprogs/loop6.c:92:9: error: expected identifier or '('
92 | config = 1;
| ^
Quoted 2 lines
So let's rename a too generically named variable?
OK. Will rename to run_once based on the context as AI suggested.
Quoted 4 lines
pw-bot: cr
[...]