Skip to content

Commit dd405a2

Browse files
seehearfeelKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Skip callback tests if jit is disabled in test_verifier
If CONFIG_BPF_JIT_ALWAYS_ON is not set and bpf_jit_enable is 0, there exist 6 failed tests. [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled [root@linux bpf]# ./test_verifier | grep FAIL #106/p inline simple bpf_loop call FAIL #107/p don't inline bpf_loop call, flags non-zero FAIL #108/p don't inline bpf_loop call, callback non-constant FAIL #109/p bpf_loop_inline and a dead func FAIL #110/p bpf_loop_inline stack locations for loop vars FAIL #111/p inline bpf_loop call in a big program FAIL Summary: 768 PASSED, 15 SKIPPED, 6 FAILED The test log shows that callbacks are not allowed in non-JITed programs, interpreter doesn't support them yet, thus these tests should be skipped if jit is disabled, just handle this case in do_test_single(). With this patch: [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled [root@linux bpf]# ./test_verifier | grep FAIL Summary: 768 PASSED, 21 SKIPPED, 0 FAILED Signed-off-by: Tiezhu Yang <[email protected]> Acked-by: Hou Tao <[email protected]> Acked-by: Song Liu <[email protected]>
1 parent 604b530 commit dd405a2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
1ULL << CAP_BPF)
7575
#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
7676
static bool unpriv_disabled = false;
77+
static bool jit_disabled;
7778
static int skips;
7879
static bool verbose = false;
7980
static int verif_log_level = 0;
@@ -1622,6 +1623,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
16221623
alignment_prevented_execution = 0;
16231624

16241625
if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {
1626+
if (fd_prog < 0 && saved_errno == EINVAL && jit_disabled) {
1627+
for (i = 0; i < prog_len; i++, prog++) {
1628+
if (!insn_is_pseudo_func(prog))
1629+
continue;
1630+
printf("SKIP (callbacks are not allowed in non-JITed programs)\n");
1631+
skips++;
1632+
goto close_fds;
1633+
}
1634+
}
1635+
16251636
if (fd_prog < 0) {
16261637
printf("FAIL\nFailed to load prog '%s'!\n",
16271638
strerror(saved_errno));
@@ -1844,6 +1855,8 @@ int main(int argc, char **argv)
18441855
return EXIT_FAILURE;
18451856
}
18461857

1858+
jit_disabled = !is_jit_enabled();
1859+
18471860
/* Use libbpf 1.0 API mode */
18481861
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
18491862

0 commit comments

Comments
 (0)