[PATCH bpf-next] selftests/bpf: Skip some verifier tests on BTFless kernels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mark seven tests as requiring vmlinux btf. Check whether vmlinux btf is
available, and if not, skip them.

Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx>
---
 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(+)

diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 9be395d9dc64..dc696aa2b9e9 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -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);
 }
diff --git a/tools/testing/selftests/bpf/verifier/d_path.c b/tools/testing/selftests/bpf/verifier/d_path.c
index b988396379a7..08613013f828 100644
--- a/tools/testing/selftests/bpf/verifier/d_path.c
+++ b/tools/testing/selftests/bpf/verifier/d_path.c
@@ -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,
 },
diff --git a/tools/testing/selftests/bpf/verifier/map_ptr.c b/tools/testing/selftests/bpf/verifier/map_ptr.c
index 637f9293bda8..c6e075dadac6 100644
--- a/tools/testing/selftests/bpf/verifier/map_ptr.c
+++ b/tools/testing/selftests/bpf/verifier/map_ptr.c
@@ -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",
diff --git a/tools/testing/selftests/bpf/verifier/map_ptr_mixing.c b/tools/testing/selftests/bpf/verifier/map_ptr_mixing.c
index 1f2b8c4cb26d..75afb8fc3aad 100644
--- a/tools/testing/selftests/bpf/verifier/map_ptr_mixing.c
+++ b/tools/testing/selftests/bpf/verifier/map_ptr_mixing.c
@@ -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)",
-- 
2.25.4




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux