Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: move trampoline_count to dedicated bpf_testmod target

trampoline_count fills all trampoline attachment slots for a single
target function and verifies that one extra attach fails with -E2BIG.

It currently targets bpf_modify_return_test, which is also used by
other selftests such as modify_return, get_func_ip_test, and
get_func_args_test. When such tests run in parallel, they can contend
for the same per-function trampoline quota and cause unexpected attach
failures. This issue is currently masked by harness serialization.

Move trampoline_count to a dedicated bpf_testmod target and register it
for fmod_ret attachment. Also route the final trigger through
trigger_module_test_read(), so the execution path exercises the same
dedicated target.

This keeps the test semantics unchanged while isolating it from other
selftests, so it no longer needs to run in serial mode. Remove the
TODO comment as well.

Tested:
./test_progs -t trampoline_count -vv
./test_progs -j$(nproc) -t trampoline_count -vv
./test_progs -j$(nproc) -t \
trampoline_count,modify_return,get_func_ip_test,get_func_args_test -vv
20 runs of:
./test_progs -j$(nproc) -t \
trampoline_count,modify_return,get_func_ip_test,get_func_args_test

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260324044949.869801-1-sun.jian.kdev@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Sun Jian and committed by
Alexei Starovoitov
7f5b0a60 d9d7125e

+27 -20
+3 -14
tools/testing/selftests/bpf/prog_tests/trampoline_count.c
··· 30 30 return prog; 31 31 } 32 32 33 - /* TODO: use different target function to run in concurrent mode */ 34 - void serial_test_trampoline_count(void) 33 + void test_trampoline_count(void) 35 34 { 36 35 char *file = "test_trampoline_count.bpf.o"; 37 36 char *const progs[] = { "fentry_test", "fmod_ret_test", "fexit_test" }; 38 - int bpf_max_tramp_links, err, i, prog_fd; 37 + int bpf_max_tramp_links, i; 39 38 struct bpf_program *prog; 40 39 struct bpf_link *link; 41 40 struct inst *inst; 42 - LIBBPF_OPTS(bpf_test_run_opts, opts); 43 41 44 42 bpf_max_tramp_links = get_bpf_max_tramp_links(); 45 43 if (!ASSERT_GE(bpf_max_tramp_links, 1, "bpf_max_tramp_links")) ··· 78 80 goto cleanup; 79 81 80 82 /* and finally execute the probe */ 81 - prog_fd = bpf_program__fd(prog); 82 - if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) 83 - goto cleanup; 84 - 85 - err = bpf_prog_test_run_opts(prog_fd, &opts); 86 - if (!ASSERT_OK(err, "bpf_prog_test_run_opts")) 87 - goto cleanup; 88 - 89 - ASSERT_EQ(opts.retval & 0xffff, 33, "bpf_modify_return_test.result"); 90 - ASSERT_EQ(opts.retval >> 16, 2, "bpf_modify_return_test.side_effect"); 83 + ASSERT_OK(trigger_module_test_read(256), "trigger_module_test_read"); 91 84 92 85 cleanup: 93 86 for (; i >= 0; i--) {
+6 -6
tools/testing/selftests/bpf/progs/test_trampoline_count.c
··· 3 3 #include <bpf/bpf_helpers.h> 4 4 #include <bpf/bpf_tracing.h> 5 5 6 - SEC("fentry/bpf_modify_return_test") 7 - int BPF_PROG(fentry_test, int a, int *b) 6 + SEC("fentry/bpf_testmod_trampoline_count_test") 7 + int BPF_PROG(fentry_test) 8 8 { 9 9 return 0; 10 10 } 11 11 12 - SEC("fmod_ret/bpf_modify_return_test") 13 - int BPF_PROG(fmod_ret_test, int a, int *b, int ret) 12 + SEC("fmod_ret/bpf_testmod_trampoline_count_test") 13 + int BPF_PROG(fmod_ret_test, int ret) 14 14 { 15 15 return 0; 16 16 } 17 17 18 - SEC("fexit/bpf_modify_return_test") 19 - int BPF_PROG(fexit_test, int a, int *b, int ret) 18 + SEC("fexit/bpf_testmod_trampoline_count_test") 19 + int BPF_PROG(fexit_test, int ret) 20 20 { 21 21 return 0; 22 22 }
+18
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
··· 470 470 471 471 int bpf_testmod_fentry_ok; 472 472 473 + noinline int bpf_testmod_trampoline_count_test(void) 474 + { 475 + return 0; 476 + } 477 + 473 478 noinline ssize_t 474 479 bpf_testmod_test_read(struct file *file, struct kobject *kobj, 475 480 const struct bin_attribute *bin_attr, ··· 552 547 bpf_testmod_fentry_test11(16, (void *)17, 18, 19, (void *)20, 553 548 21, 22, 23, 24, 25, 26) != 231) 554 549 goto out; 550 + 551 + bpf_testmod_trampoline_count_test(); 555 552 556 553 bpf_testmod_stacktrace_test_1(); 557 554 ··· 1909 1902 1910 1903 extern int bpf_fentry_test1(int a); 1911 1904 1905 + BTF_KFUNCS_START(bpf_testmod_trampoline_count_ids) 1906 + BTF_ID_FLAGS(func, bpf_testmod_trampoline_count_test) 1907 + BTF_KFUNCS_END(bpf_testmod_trampoline_count_ids) 1908 + 1909 + static const struct 1910 + btf_kfunc_id_set bpf_testmod_trampoline_count_fmodret_set = { 1911 + .owner = THIS_MODULE, 1912 + .set = &bpf_testmod_trampoline_count_ids, 1913 + }; 1914 + 1912 1915 static int bpf_testmod_init(void) 1913 1916 { 1914 1917 const struct btf_id_dtor_kfunc bpf_testmod_dtors[] = { ··· 1935 1918 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_testmod_kfunc_set); 1936 1919 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &bpf_testmod_kfunc_set); 1937 1920 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_testmod_kfunc_set); 1921 + ret = ret ?: register_btf_fmodret_id_set(&bpf_testmod_trampoline_count_fmodret_set); 1938 1922 ret = ret ?: register_bpf_struct_ops(&bpf_bpf_testmod_ops, bpf_testmod_ops); 1939 1923 ret = ret ?: register_bpf_struct_ops(&bpf_testmod_ops2, bpf_testmod_ops2); 1940 1924 ret = ret ?: register_bpf_struct_ops(&bpf_testmod_ops3, bpf_testmod_ops3);