Skip to content

Commit b4b4b6c

Browse files
seehearfeelKernel Patches Daemon
authored andcommitted
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(). After including bpf/libbpf_internal.h, there exist some build errors: error: attempt to use poisoned "u32" error: attempt to use poisoned "u64" replace u32 and u64 with __u32 and __u64 to fix them. 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]>
1 parent 00686a3 commit b4b4b6c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "test_btf.h"
4242
#include "../../../include/linux/filter.h"
4343
#include "testing_helpers.h"
44+
#include "bpf/libbpf_internal.h"
4445

4546
#ifndef ENOTSUPP
4647
#define ENOTSUPP 524
@@ -74,6 +75,7 @@
7475
1ULL << CAP_BPF)
7576
#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
7677
static bool unpriv_disabled = false;
78+
static bool jit_disabled;
7779
static int skips;
7880
static bool verbose = false;
7981
static int verif_log_level = 0;
@@ -1143,8 +1145,8 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
11431145
} while (*fixup_map_xskmap);
11441146
}
11451147
if (*fixup_map_stacktrace) {
1146-
map_fds[12] = create_map(BPF_MAP_TYPE_STACK_TRACE, sizeof(u32),
1147-
sizeof(u64), 1);
1148+
map_fds[12] = create_map(BPF_MAP_TYPE_STACK_TRACE, sizeof(__u32),
1149+
sizeof(__u64), 1);
11481150
do {
11491151
prog[*fixup_map_stacktrace].imm = map_fds[12];
11501152
fixup_map_stacktrace++;
@@ -1203,7 +1205,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
12031205
}
12041206
if (*fixup_map_reuseport_array) {
12051207
map_fds[19] = __create_map(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
1206-
sizeof(u32), sizeof(u64), 1, 0);
1208+
sizeof(__u32), sizeof(__u64), 1, 0);
12071209
do {
12081210
prog[*fixup_map_reuseport_array].imm = map_fds[19];
12091211
fixup_map_reuseport_array++;
@@ -1622,6 +1624,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
16221624
alignment_prevented_execution = 0;
16231625

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

1859+
jit_disabled = !is_jit_enabled();
1860+
18471861
/* Use libbpf 1.0 API mode */
18481862
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
18491863

0 commit comments

Comments
 (0)