Skip to content

Commit 85981e0

Browse files
olsajirianakryiko
authored andcommitted
selftests/bpf: Add test for recursion counts of perf event link tracepoint
Adding selftest that puts kprobe on bpf_fentry_test1 that calls bpf_printk and invokes bpf_trace_printk tracepoint. The bpf_trace_printk tracepoint has test[234] programs attached to it. Because kprobe execution goes through bpf_prog_active check, programs attached to the tracepoint will fail the recursion check and increment the recursion_misses stats. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Song Liu <song@kernel.org> Reviewed-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/bpf/20230920213145.1941596-10-jolsa@kernel.org
1 parent 59e83c0 commit 85981e0

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <test_progs.h>
33
#include "missed_kprobe.skel.h"
44
#include "missed_kprobe_recursion.skel.h"
5+
#include "missed_tp_recursion.skel.h"
56

67
/*
78
* Putting kprobe on bpf_fentry_test1 that calls bpf_kfunc_common_test
@@ -89,10 +90,49 @@ static void test_missed_kprobe_recursion(void)
8990
missed_kprobe_recursion__destroy(skel);
9091
}
9192

93+
/*
94+
* Putting kprobe on bpf_fentry_test1 that calls bpf_printk and invokes
95+
* bpf_trace_printk tracepoint. The bpf_trace_printk tracepoint has test[234]
96+
* programs attached to it.
97+
*
98+
* Because kprobe execution goes through bpf_prog_active check, programs
99+
* attached to the tracepoint will fail the recursion check and increment
100+
* the recursion_misses stats.
101+
*/
102+
static void test_missed_tp_recursion(void)
103+
{
104+
LIBBPF_OPTS(bpf_test_run_opts, topts);
105+
struct missed_tp_recursion *skel;
106+
int err, prog_fd;
107+
108+
skel = missed_tp_recursion__open_and_load();
109+
if (!ASSERT_OK_PTR(skel, "missed_tp_recursion__open_and_load"))
110+
goto cleanup;
111+
112+
err = missed_tp_recursion__attach(skel);
113+
if (!ASSERT_OK(err, "missed_tp_recursion__attach"))
114+
goto cleanup;
115+
116+
prog_fd = bpf_program__fd(skel->progs.trigger);
117+
err = bpf_prog_test_run_opts(prog_fd, &topts);
118+
ASSERT_OK(err, "test_run");
119+
ASSERT_EQ(topts.retval, 0, "test_run");
120+
121+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test1)), 0, "test1_recursion_misses");
122+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test2)), 1, "test2_recursion_misses");
123+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test3)), 1, "test3_recursion_misses");
124+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test4)), 1, "test4_recursion_misses");
125+
126+
cleanup:
127+
missed_tp_recursion__destroy(skel);
128+
}
129+
92130
void test_missed(void)
93131
{
94132
if (test__start_subtest("perf_kprobe"))
95133
test_missed_perf_kprobe();
96134
if (test__start_subtest("kprobe_recursion"))
97135
test_missed_kprobe_recursion();
136+
if (test__start_subtest("tp_recursion"))
137+
test_missed_tp_recursion();
98138
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include "vmlinux.h"
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
/*
9+
* No tests in here, just to trigger 'bpf_fentry_test*'
10+
* through tracing test_run
11+
*/
12+
SEC("fentry/bpf_modify_return_test")
13+
int BPF_PROG(trigger)
14+
{
15+
return 0;
16+
}
17+
18+
SEC("kprobe/bpf_fentry_test1")
19+
int test1(struct pt_regs *ctx)
20+
{
21+
bpf_printk("test");
22+
return 0;
23+
}
24+
25+
SEC("tp/bpf_trace/bpf_trace_printk")
26+
int test2(struct pt_regs *ctx)
27+
{
28+
return 0;
29+
}
30+
31+
SEC("tp/bpf_trace/bpf_trace_printk")
32+
int test3(struct pt_regs *ctx)
33+
{
34+
return 0;
35+
}
36+
37+
SEC("tp/bpf_trace/bpf_trace_printk")
38+
int test4(struct pt_regs *ctx)
39+
{
40+
return 0;
41+
}

0 commit comments

Comments
 (0)