The bpf selftest build will fail on the stable 5.15 tree with:
CC test_stub.o BINARY test_verifier In file included from /home/ubuntu/linux/tools/testing/selftests/bpf/verifier/tests.h:21, from test_verifier.c:432: /home/ubuntu/linux/tools/testing/selftests/bpf/verifier/calls.c:124:10: error: 'struct bpf_test' has no member named 'fixup_kfunc_btf_id' 124 | .fixup_kfunc_btf_id = { | ^~~~~~~~~~~~~~~~~~ /home/ubuntu/linux/tools/testing/selftests/bpf/verifier/calls.c:124:9: warning: braces around scalar initializer 124 | .fixup_kfunc_btf_id = { | ^
This is because of the fixup_kfunc_btf_id member in struct bpf_test added in commit 13c6a37d40 ("selftests/bpf: Add test for reg2btf_ids out of bounds access") from upstream.
We will need commit 0201b80772 ("selftests/bpf: Add test_verifier support to fixup kfunc call insns") from upstream to solve this build issue. Some backport work is needed for the 5.15 tree to skip fixup_map_timer related changes, which came from commit e60e6962c5 ("selftests/bpf: Add tests for restricted helpers").
Kumar Kartikeya Dwivedi (1): selftests/bpf: Add test_verifier support to fixup kfunc call insns
tools/testing/selftests/bpf/test_verifier.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
From: Kumar Kartikeya Dwivedi memxor@gmail.com
commit 0201b80772ac2b712bbbfe783cdb731fdfb4247e upstream.
This allows us to add tests (esp. negative tests) where we only want to ensure the program doesn't pass through the verifier, and also verify the error. The next commit will add the tests making use of this.
Signed-off-by: Kumar Kartikeya Dwivedi memxor@gmail.com Link: https://lore.kernel.org/r/20220114163953.1455836-9-memxor@gmail.com Signed-off-by: Alexei Starovoitov ast@kernel.org [PHLin: backport due to lack of fixup_map_timer] Signed-off-by: Po-Hsu Lin po-hsu.lin@canonical.com --- tools/testing/selftests/bpf/test_verifier.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 3a9e332..68a9a89 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -31,6 +31,7 @@ #include <linux/if_ether.h> #include <linux/btf.h>
+#include <bpf/btf.h> #include <bpf/bpf.h> #include <bpf/libbpf.h>
@@ -63,6 +64,11 @@ static bool unpriv_disabled = false; static int skips; static bool verbose = false;
+struct kfunc_btf_id_pair { + const char *kfunc; + int insn_idx; +}; + struct bpf_test { const char *descr; struct bpf_insn insns[MAX_INSNS]; @@ -88,6 +94,7 @@ struct bpf_test { int fixup_map_event_output[MAX_FIXUPS]; int fixup_map_reuseport_array[MAX_FIXUPS]; int fixup_map_ringbuf[MAX_FIXUPS]; + struct kfunc_btf_id_pair fixup_kfunc_btf_id[MAX_FIXUPS]; /* Expected verifier log output for result REJECT or VERBOSE_ACCEPT. * Can be a tab-separated sequence of expected strings. An empty string * means no log verification. @@ -718,6 +725,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type, int *fixup_map_event_output = test->fixup_map_event_output; int *fixup_map_reuseport_array = test->fixup_map_reuseport_array; int *fixup_map_ringbuf = test->fixup_map_ringbuf; + struct kfunc_btf_id_pair *fixup_kfunc_btf_id = test->fixup_kfunc_btf_id;
if (test->fill_helper) { test->fill_insns = calloc(MAX_TEST_INSNS, sizeof(struct bpf_insn)); @@ -903,6 +911,26 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type, fixup_map_ringbuf++; } while (*fixup_map_ringbuf); } + + /* Patch in kfunc BTF IDs */ + if (fixup_kfunc_btf_id->kfunc) { + struct btf *btf; + int btf_id; + + do { + btf_id = 0; + btf = btf__load_vmlinux_btf(); + if (btf) { + btf_id = btf__find_by_name_kind(btf, + fixup_kfunc_btf_id->kfunc, + BTF_KIND_FUNC); + btf_id = btf_id < 0 ? 0 : btf_id; + } + btf__free(btf); + prog[fixup_kfunc_btf_id->insn_idx].imm = btf_id; + fixup_kfunc_btf_id++; + } while (fixup_kfunc_btf_id->kfunc); + } }
struct libcap {
On Fri, Jul 01, 2022 at 09:08:58PM +0800, Po-Hsu Lin wrote:
From: Kumar Kartikeya Dwivedi memxor@gmail.com
commit 0201b80772ac2b712bbbfe783cdb731fdfb4247e upstream.
This allows us to add tests (esp. negative tests) where we only want to ensure the program doesn't pass through the verifier, and also verify the error. The next commit will add the tests making use of this.
Signed-off-by: Kumar Kartikeya Dwivedi memxor@gmail.com Link: https://lore.kernel.org/r/20220114163953.1455836-9-memxor@gmail.com Signed-off-by: Alexei Starovoitov ast@kernel.org [PHLin: backport due to lack of fixup_map_timer] Signed-off-by: Po-Hsu Lin po-hsu.lin@canonical.com
tools/testing/selftests/bpf/test_verifier.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Now queued up, thanks.
greg k-h
linux-stable-mirror@lists.linaro.org