bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Skip some verifier tests on BTFless kernels
@ 2020-09-21 18:42 Ilya Leoshkevich
  2020-09-23 18:13 ` Andrii Nakryiko
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Leoshkevich @ 2020-09-21 18:42 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Andrii Nakryiko, 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 <iii@linux.ibm.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Skip some verifier tests on BTFless kernels
  2020-09-21 18:42 [PATCH bpf-next] selftests/bpf: Skip some verifier tests on BTFless kernels Ilya Leoshkevich
@ 2020-09-23 18:13 ` Andrii Nakryiko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2020-09-23 18:13 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens, Vasily Gorbik

On Mon, Sep 21, 2020 at 11:42 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> Mark seven tests as requiring vmlinux btf. Check whether vmlinux btf is
> available, and if not, skip them.
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---

Ilya,

These changes look good to me, though kernel BTF has been a
requirement for successful BPF selftests run for a while now, so I'm
not sure if we want to do this... It will be up to Alexei and Daniel
to decide, I suppose. I'm fine either way.

But in any case, it seems like patchworks lost your patch, so please
resend it so that it's visible there and can go through normal patch
review workflow. Thanks!

>  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(+)
>

[...]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-23 18:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 18:42 [PATCH bpf-next] selftests/bpf: Skip some verifier tests on BTFless kernels Ilya Leoshkevich
2020-09-23 18:13 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).