selftests/bpf: Skip some verifier tests on BTFless kernels
Subsystems (3)
PATCH RESEND 1/1 selftests/bpf: Skip some verifier tests on BTFless kernels
Mark seven tests as requiring vmlinux btf. Check whether vmlinux btf is available, and if not, skip them.
Signed-off-by Ilya Leoshkevich <[email protected]>
---
Resending due to patchwork having missed the original submission:
https://lore.kernel.org/bpf/[email protected]/
tools/testing/selftests/bpf/test_verifier.c | 24 +++++++++++++++++++
tools/testing/selftests/bpf/verifier/d_path.c | 2 ++ .../testing/selftests/bpf/verifier/map_ptr.c | 4 ++++ .../selftests/bpf/verifier/map_ptr_mixing.c | 1 + 4 files changed, 31 insertions(+)
tools/testing/selftests/bpf/test_verifier.c +24 -0
@@ -30,8 +30,10 @@#include <linux/bpf.h> #include <linux/if_ether.h> #include <linux/btf.h> +#include <linux/err.h> #include <bpf/bpf.h> +#include <bpf/btf.h> #include <bpf/libbpf.h> #ifdef HAVE_GENHDR
@@ -115,6 +117,7 @@ struct bpf_test { };enum bpf_attach_type expected_attach_type;const char *kfunc; +bool need_vmlinux_btf; };/* Note we want this to be 64 bit aligned so that the end of our array is
@@ -926,6 +929,19 @@ static bool cmp_str_seq(const char *log, const char *exp)return true; } +static bool vmlinux_btf_available; + +static void probe_vmlinux_btf (void ) +{ +struct btf *btf_vmlinux; + + btf_vmlinux =libbpf_find_kernel_btf (); +if (IS_ERR (btf_vmlinux)) +return ; +btf__free (btf_vmlinux); + vmlinux_btf_available = true; +} +static void do_test_single (struct bpf_test *test,bool unpriv,int *passes,int *errors) {
@@ -940,6 +956,12 @@ static void do_test_single(struct bpf_test *test, bool unpriv,__u32 pflags;int i, err; +if (test->need_vmlinux_btf && !vmlinux_btf_available) { +printf ("SKIP (no vmlinux BTF)\n" ); + skips++; + goto done; + } +for (i =0 ; i <MAX_NR_MAPS ; i++) map_fds[i] =-1 ;
@@ -1097,6 +1119,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,close (fd_prog);for (i =0 ; i <MAX_NR_MAPS ; i++)close (map_fds[i]); +done:sched_yield ();return ; fail_log:
@@ -1230,5 +1253,6 @@ int main(int argc, char **argv) }bpf_semi_rand_init (); +probe_vmlinux_btf ();return do_test (unpriv, from, to); }
tools/testing/selftests/bpf/verifier/d_path.c +2 -0
@@ -15,6 +15,7 @@ .prog_type = BPF_PROG_TYPE_TRACING, .expected_attach_type = BPF_TRACE_FENTRY, .kfunc = "dentry_open", + .need_vmlinux_btf = true, }, { "d_path reject",
@@ -34,4 +35,5 @@ .prog_type = BPF_PROG_TYPE_TRACING, .expected_attach_type = BPF_TRACE_FENTRY, .kfunc = "d_path", + .need_vmlinux_btf = true, },
tools/testing/selftests/bpf/verifier/map_ptr.c +4 -0
@@ -12,6 +12,7 @@ .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .result = REJECT, .errstr = "R1 is bpf_array invalid negative access: off=-8", + .need_vmlinux_btf = true, }, { "bpf_map_ptr: write rejected",
@@ -29,6 +30,7 @@ .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .result = REJECT, .errstr = "only read from bpf_array is supported", + .need_vmlinux_btf = true, }, { "bpf_map_ptr: read non-existent field rejected",
@@ -44,6 +46,7 @@ .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .result = REJECT, .errstr = "cannot access ptr member ops with moff 0 in struct bpf_map with off 1 size 4", + .need_vmlinux_btf = true, }, { "bpf_map_ptr: read ops field accepted",
@@ -59,6 +62,7 @@ .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .result = ACCEPT, .retval = 1, + .need_vmlinux_btf = true, }, { "bpf_map_ptr: r = 0, map_ptr = map_ptr + r",
tools/testing/selftests/bpf/verifier/map_ptr_mixing.c +1 -0
@@ -57,6 +57,7 @@ .fixup_map_array_48b = { 13 }, .result = REJECT, .errstr = "only read from bpf_array is supported", + .need_vmlinux_btf = true, }, { "cond: two branches returning different map pointers for lookup (tail, tail)",
Signature · 1 line
2.25.4
Quoted 7 lines · Ilya Leoshkevich
Mark seven tests as requiring vmlinux btf. Check whether vmlinux btf is available, and if not, skip them.
Signed-off-by Ilya Leoshkevich <[email protected]>---
Ok, given no one objects, I'll ack this. test_progs won't succeed if kernel is built without BTF, so in environment where we test these tests will always run.
Acked-by Andrii Nakryiko <[email protected]>
Quoted 4 lines
Resending due to patchwork having missed the original submission:
[...]