trigger() in struct_ops_arena.c and its three siblings puts the __BPF_FEATURE_ADDR_SPACE_CAST guard inside the function, so without arena support the body is gone and the program falls through to "return 0". The host side then does err = bpf_prog_test_run_opts(bpf_program__fd(trigger), &topts); ASSERT_OK(err, "test_run"); ASSERT_EQ(topts.retval, 0, "trigger_retval"); and passes, having run a program that did nothing. Two tests report OK under a stock bpf-gcc on that basis: arena_arg and arena_autobind. The other two, arena_member and arena_member_render, need a testmod BTF carrying the arena type tag and are not reached without one, but are fixed the same way. These are not driven by test_loader, so __skip_without_arena does not reach them. Use the flag-in-.data pattern linked_externs.c already uses for the same situation: the program exports skip_tests, and the host checks it before attaching and reports SKIP. Signed-off-by: Vineet Gupta --- .../bpf/prog_tests/test_struct_ops_arena.c | 27 +++++++++++++++++++ .../selftests/bpf/progs/struct_ops_arena.c | 10 +++++++ .../bpf/progs/struct_ops_arena_autobind.c | 10 +++++++ .../bpf/progs/struct_ops_arena_member.c | 10 +++++++ .../progs/struct_ops_arena_member_render.c | 10 +++++++ 5 files changed, 67 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c index e7580b9f0fc2..11b7dab77ff7 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c @@ -31,6 +31,12 @@ static void arena_arg(void) if (!ASSERT_OK_PTR(skel, "struct_ops_arena__open_and_load")) return; + if (skel->data->skip_tests) { + printf("%s:SKIP: no addr_space_cast support in the BPF compiler\n", __func__); + test__skip(); + goto out; + } + link = bpf_map__attach_struct_ops(skel->maps.testmod_arena); if (!ASSERT_OK_PTR(link, "attach_struct_ops")) goto out; @@ -142,6 +148,13 @@ static void arena_member(void) if (!ASSERT_OK_PTR(skel, "struct_ops_arena_member__open_and_load")) return; + if (skel->data->skip_tests) { + printf("%s:SKIP: no addr_space_cast support in the BPF compiler\n", __func__); + test__skip(); + struct_ops_arena_member__destroy(skel); + return; + } + attach_and_trigger(skel->maps.testmod_arena_member, skel->progs.trigger); struct_ops_arena_member__destroy(skel); } @@ -186,6 +199,13 @@ static void arena_autobind(void) assert_prog_map(bpf_program__fd(skel->progs.test_arena_cb), info.id, "test_arena_cb"); assert_prog_map(bpf_program__fd(skel->progs.unrelated), info.id, "unrelated"); + if (skel->data->skip_tests) { + printf("%s:SKIP: no addr_space_cast support in the BPF compiler\n", __func__); + test__skip(); + struct_ops_arena_autobind__destroy(skel); + return; + } + attach_and_trigger(skel->maps.testmod_arena_autobind, skel->progs.trigger); out: struct_ops_arena_autobind__destroy(skel); @@ -268,6 +288,13 @@ static void arena_member_render(void) if (!ASSERT_OK_PTR(skel, "struct_ops_arena_member_render__open_and_load")) return; + if (skel->data->skip_tests) { + printf("%s:SKIP: no addr_space_cast support in the BPF compiler\n", __func__); + test__skip(); + struct_ops_arena_member_render__destroy(skel); + return; + } + attach_and_trigger(skel->maps.testmod_arena_member_render, skel->progs.trigger); struct_ops_arena_member_render__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena.c b/tools/testing/selftests/bpf/progs/struct_ops_arena.c index 8aa8639df91f..612ca868c8fe 100644 --- a/tools/testing/selftests/bpf/progs/struct_ops_arena.c +++ b/tools/testing/selftests/bpf/progs/struct_ops_arena.c @@ -83,6 +83,16 @@ struct bpf_testmod_ops3 testmod_arena = { .test_arena_multislot = (void *)test_arena_multislot_cb, }; +/* + * These tests are not driven by test_loader, so __skip_without_arena + * cannot reach them; the host side reads this flag and skips instead. + */ +#ifdef __BPF_FEATURE_ADDR_SPACE_CAST +bool skip_tests __attribute((__section__(".data"))) = false; +#else +bool skip_tests = true; +#endif + SEC("syscall") int trigger(void *ctx) { diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena_autobind.c b/tools/testing/selftests/bpf/progs/struct_ops_arena_autobind.c index 495faa0f4a8b..de026d901dcb 100644 --- a/tools/testing/selftests/bpf/progs/struct_ops_arena_autobind.c +++ b/tools/testing/selftests/bpf/progs/struct_ops_arena_autobind.c @@ -42,6 +42,16 @@ int unrelated(void *ctx) return 0; } +/* + * These tests are not driven by test_loader, so __skip_without_arena + * cannot reach them; the host side reads this flag and skips instead. + */ +#ifdef __BPF_FEATURE_ADDR_SPACE_CAST +bool skip_tests __attribute((__section__(".data"))) = false; +#else +bool skip_tests = true; +#endif + SEC("syscall") int trigger(void *ctx) { diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena_member.c b/tools/testing/selftests/bpf/progs/struct_ops_arena_member.c index a2218cd81619..4ec0aead3e95 100644 --- a/tools/testing/selftests/bpf/progs/struct_ops_arena_member.c +++ b/tools/testing/selftests/bpf/progs/struct_ops_arena_member.c @@ -77,6 +77,16 @@ struct bpf_testmod_ops3 testmod_arena_member = { .test_arena_member = (void *)test_arena_member_cb, }; +/* + * These tests are not driven by test_loader, so __skip_without_arena + * cannot reach them; the host side reads this flag and skips instead. + */ +#ifdef __BPF_FEATURE_ADDR_SPACE_CAST +bool skip_tests __attribute((__section__(".data"))) = false; +#else +bool skip_tests = true; +#endif + SEC("syscall") int trigger(void *ctx) { diff --git a/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c b/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c index 09b4c740bdca..3ccbc6e71626 100644 --- a/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c +++ b/tools/testing/selftests/bpf/progs/struct_ops_arena_member_render.c @@ -60,6 +60,16 @@ struct bpf_testmod_ops3 testmod_arena_member_render = { .test_arena_member = (void *)test_arena_member_render_cb, }; +/* + * These tests are not driven by test_loader, so __skip_without_arena + * cannot reach them; the host side reads this flag and skips instead. + */ +#ifdef __BPF_FEATURE_ADDR_SPACE_CAST +bool skip_tests __attribute((__section__(".data"))) = false; +#else +bool skip_tests = true; +#endif + SEC("syscall") int trigger(void *ctx) { -- 2.53.0-Meta