Skip to content

Commit 8798902

Browse files
AsphalttAlexei Starovoitov
authored andcommitted
bpf: Add bpf_jit_supports_fsession()
The added fsession does not prevent running on those architectures, that haven't added fsession support. For example, try to run fsession tests on arm64: test_fsession_basic:PASS:fsession_test__open_and_load 0 nsec test_fsession_basic:PASS:fsession_attach 0 nsec check_result:FAIL:test_run_opts err unexpected error: -14 (errno 14) In order to prevent such errors, add bpf_jit_supports_fsession() to guard those architectures. Fixes: 2d419c4 ("bpf: add fsession support") Acked-by: Puranjay Mohan <puranjay@kernel.org> Tested-by: Puranjay Mohan <puranjay@kernel.org> Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/r/20260131144950.16294-2-leon.hwang@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent f0b5b3d commit 8798902

5 files changed

Lines changed: 40 additions & 8 deletions

File tree

arch/x86/net/bpf_jit_comp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,3 +4112,8 @@ bool bpf_jit_supports_timed_may_goto(void)
41124112
{
41134113
return true;
41144114
}
4115+
4116+
bool bpf_jit_supports_fsession(void)
4117+
{
4118+
return true;
4119+
}

include/linux/filter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ bool bpf_jit_supports_arena(void);
11671167
bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena);
11681168
bool bpf_jit_supports_private_stack(void);
11691169
bool bpf_jit_supports_timed_may_goto(void);
1170+
bool bpf_jit_supports_fsession(void);
11701171
u64 bpf_arch_uaddress_limit(void);
11711172
void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie);
11721173
u64 arch_bpf_timed_may_goto(void);

kernel/bpf/core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,11 @@ bool __weak bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
31443144
return false;
31453145
}
31463146

3147+
bool __weak bpf_jit_supports_fsession(void)
3148+
{
3149+
return false;
3150+
}
3151+
31473152
u64 __weak bpf_arch_uaddress_limit(void)
31483153
{
31493154
#if defined(CONFIG_64BIT) && defined(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE)

kernel/bpf/verifier.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24828,6 +24828,11 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
2482824828
case BPF_TRACE_FENTRY:
2482924829
case BPF_TRACE_FEXIT:
2483024830
case BPF_TRACE_FSESSION:
24831+
if (prog->expected_attach_type == BPF_TRACE_FSESSION &&
24832+
!bpf_jit_supports_fsession()) {
24833+
bpf_log(log, "JIT does not support fsession\n");
24834+
return -EOPNOTSUPP;
24835+
}
2483124836
if (!btf_type_is_func(t)) {
2483224837
bpf_log(log, "attach_btf_id %u is not a function\n",
2483324838
btf_id);

tools/testing/selftests/bpf/prog_tests/fsession_test.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ static void test_fsession_basic(void)
2929
struct fsession_test *skel = NULL;
3030
int err;
3131

32-
skel = fsession_test__open_and_load();
33-
if (!ASSERT_OK_PTR(skel, "fsession_test__open_and_load"))
32+
skel = fsession_test__open();
33+
if (!ASSERT_OK_PTR(skel, "fsession_test__open"))
34+
return;
35+
36+
err = fsession_test__load(skel);
37+
if (err == -EOPNOTSUPP) {
38+
test__skip();
39+
goto cleanup;
40+
}
41+
if (!ASSERT_OK(err, "fsession_test__load"))
3442
goto cleanup;
3543

3644
err = fsession_test__attach(skel);
@@ -47,8 +55,16 @@ static void test_fsession_reattach(void)
4755
struct fsession_test *skel = NULL;
4856
int err;
4957

50-
skel = fsession_test__open_and_load();
51-
if (!ASSERT_OK_PTR(skel, "fsession_test__open_and_load"))
58+
skel = fsession_test__open();
59+
if (!ASSERT_OK_PTR(skel, "fsession_test__open"))
60+
return;
61+
62+
err = fsession_test__load(skel);
63+
if (err == -EOPNOTSUPP) {
64+
test__skip();
65+
goto cleanup;
66+
}
67+
if (!ASSERT_OK(err, "fsession_test__load"))
5268
goto cleanup;
5369

5470
/* first attach */
@@ -94,6 +110,10 @@ static void test_fsession_cookie(void)
94110
bpf_program__set_autoload(skel->progs.test6, false);
95111

96112
err = fsession_test__load(skel);
113+
if (err == -EOPNOTSUPP) {
114+
test__skip();
115+
goto cleanup;
116+
}
97117
if (!ASSERT_OK(err, "fsession_test__load"))
98118
goto cleanup;
99119

@@ -111,10 +131,6 @@ static void test_fsession_cookie(void)
111131

112132
void test_fsession_test(void)
113133
{
114-
#if !defined(__x86_64__)
115-
test__skip();
116-
return;
117-
#endif
118134
if (test__start_subtest("fsession_test"))
119135
test_fsession_basic();
120136
if (test__start_subtest("fsession_reattach"))

0 commit comments

Comments
 (0)