Skip to content

Commit b4f3dc9

Browse files
olsajiriKernel Patches Daemon
authored andcommitted
selftests/bpf: Add stacktrace ips test for fentry/fexit
Adding test that attaches fentry/fexitand verifies the ORC stacktrace matches expected functions. The test is only for ORC unwinder to keep it simple. Signed-off-by: Jiri Olsa <[email protected]>
1 parent 588f204 commit b4f3dc9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,53 @@ static void test_stacktrace_ips_kprobe(bool retprobe)
183183
stacktrace_ips__destroy(skel);
184184
}
185185

186+
static void test_stacktrace_ips_trampoline(bool retprobe)
187+
{
188+
LIBBPF_OPTS(bpf_test_run_opts, topts);
189+
struct stacktrace_ips *skel;
190+
191+
skel = stacktrace_ips__open_and_load();
192+
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
193+
return;
194+
195+
if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
196+
test__skip();
197+
goto cleanup;
198+
}
199+
200+
if (retprobe) {
201+
skel->links.fexit_test = bpf_program__attach_trace(skel->progs.fexit_test);
202+
if (!ASSERT_OK_PTR(skel->links.fexit_test, "bpf_program__attach_trace"))
203+
goto cleanup;
204+
} else {
205+
skel->links.fentry_test = bpf_program__attach_trace(skel->progs.fentry_test);
206+
if (!ASSERT_OK_PTR(skel->links.fentry_test, "bpf_program__attach_trace"))
207+
goto cleanup;
208+
}
209+
210+
trigger_module_test_read(1);
211+
212+
load_kallsyms();
213+
214+
if (retprobe) {
215+
check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 4,
216+
ksym_get_addr("bpf_testmod_stacktrace_test_3"),
217+
ksym_get_addr("bpf_testmod_stacktrace_test_2"),
218+
ksym_get_addr("bpf_testmod_stacktrace_test_1"),
219+
ksym_get_addr("bpf_testmod_test_read"));
220+
} else {
221+
check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 5,
222+
ksym_get_addr("bpf_testmod_stacktrace_test"),
223+
ksym_get_addr("bpf_testmod_stacktrace_test_3"),
224+
ksym_get_addr("bpf_testmod_stacktrace_test_2"),
225+
ksym_get_addr("bpf_testmod_stacktrace_test_1"),
226+
ksym_get_addr("bpf_testmod_test_read"));
227+
}
228+
229+
cleanup:
230+
stacktrace_ips__destroy(skel);
231+
}
232+
186233
static void __test_stacktrace_ips(void)
187234
{
188235
if (test__start_subtest("kprobe_multi"))
@@ -195,6 +242,10 @@ static void __test_stacktrace_ips(void)
195242
test_stacktrace_ips_kprobe(false);
196243
if (test__start_subtest("kretprobe"))
197244
test_stacktrace_ips_kprobe(true);
245+
if (test__start_subtest("fentry"))
246+
test_stacktrace_ips_trampoline(false);
247+
if (test__start_subtest("fexit"))
248+
test_stacktrace_ips_trampoline(true);
198249
}
199250
#else
200251
static void __test_stacktrace_ips(void)

tools/testing/selftests/bpf/progs/stacktrace_ips.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,24 @@ int rawtp_test(void *ctx)
5353
return 0;
5454
}
5555

56+
SEC("fentry/bpf_testmod_stacktrace_test")
57+
int fentry_test(struct pt_regs *ctx)
58+
{
59+
/*
60+
* Skip 2 bpf_program/trampoline stack entries:
61+
* - bpf_prog_bd1f7a949f55fb03_fentry_test
62+
* - bpf_trampoline_182536277701
63+
*/
64+
stack_key = bpf_get_stackid(ctx, &stackmap, 2);
65+
return 0;
66+
}
67+
68+
SEC("fexit/bpf_testmod_stacktrace_test")
69+
int fexit_test(struct pt_regs *ctx)
70+
{
71+
/* Skip 2 bpf_program/trampoline stack entries, check fentry_test. */
72+
stack_key = bpf_get_stackid(ctx, &stackmap, 2);
73+
return 0;
74+
}
75+
5676
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)