Skip to content

Commit 59e83c0

Browse files
olsajirianakryiko
authored andcommitted
selftests/bpf: Add test for recursion counts of perf event link kprobe
Adding selftest that puts kprobe.multi on bpf_fentry_test1 that calls bpf_kfunc_common_test kfunc which has 3 perf event kprobes and 1 kprobe.multi attached. Because fprobe (kprobe.multi attach layear) does not have strict recursion check the kprobe's bpf_prog_active check is hit for test2-5. Disabling this test for arm64, because there's no fprobe support yet. 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> Acked-by: Hou Tao <houtao1@huawei.com> Link: https://lore.kernel.org/bpf/20230920213145.1941596-9-jolsa@kernel.org
1 parent 01e4ae4 commit 59e83c0

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

tools/testing/selftests/bpf/DENYLIST.aarch64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ fexit_test/fexit_many_args # fexit_many_args:FAIL:fexit_ma
1010
fill_link_info/kprobe_multi_link_info # bpf_program__attach_kprobe_multi_opts unexpected error: -95
1111
fill_link_info/kretprobe_multi_link_info # bpf_program__attach_kprobe_multi_opts unexpected error: -95
1212
fill_link_info/kprobe_multi_invalid_ubuff # bpf_program__attach_kprobe_multi_opts unexpected error: -95
13+
missed/kprobe_recursion # missed_kprobe_recursion__attach unexpected error: -95 (errno 95)

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <test_progs.h>
33
#include "missed_kprobe.skel.h"
4+
#include "missed_kprobe_recursion.skel.h"
45

56
/*
67
* Putting kprobe on bpf_fentry_test1 that calls bpf_kfunc_common_test
@@ -40,8 +41,58 @@ static void test_missed_perf_kprobe(void)
4041
missed_kprobe__destroy(skel);
4142
}
4243

44+
static __u64 get_missed_count(int fd)
45+
{
46+
struct bpf_prog_info info = {};
47+
__u32 len = sizeof(info);
48+
int err;
49+
50+
err = bpf_prog_get_info_by_fd(fd, &info, &len);
51+
if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
52+
return (__u64) -1;
53+
return info.recursion_misses;
54+
}
55+
56+
/*
57+
* Putting kprobe.multi on bpf_fentry_test1 that calls bpf_kfunc_common_test
58+
* kfunc which has 3 perf event kprobes and 1 kprobe.multi attached.
59+
*
60+
* Because fprobe (kprobe.multi attach layear) does not have strict recursion
61+
* check the kprobe's bpf_prog_active check is hit for test2-5.
62+
*/
63+
static void test_missed_kprobe_recursion(void)
64+
{
65+
LIBBPF_OPTS(bpf_test_run_opts, topts);
66+
struct missed_kprobe_recursion *skel;
67+
int err, prog_fd;
68+
69+
skel = missed_kprobe_recursion__open_and_load();
70+
if (!ASSERT_OK_PTR(skel, "missed_kprobe_recursion__open_and_load"))
71+
goto cleanup;
72+
73+
err = missed_kprobe_recursion__attach(skel);
74+
if (!ASSERT_OK(err, "missed_kprobe_recursion__attach"))
75+
goto cleanup;
76+
77+
prog_fd = bpf_program__fd(skel->progs.trigger);
78+
err = bpf_prog_test_run_opts(prog_fd, &topts);
79+
ASSERT_OK(err, "test_run");
80+
ASSERT_EQ(topts.retval, 0, "test_run");
81+
82+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test1)), 0, "test1_recursion_misses");
83+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test2)), 1, "test2_recursion_misses");
84+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test3)), 1, "test3_recursion_misses");
85+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test4)), 1, "test4_recursion_misses");
86+
ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test5)), 1, "test5_recursion_misses");
87+
88+
cleanup:
89+
missed_kprobe_recursion__destroy(skel);
90+
}
91+
4392
void test_missed(void)
4493
{
4594
if (test__start_subtest("perf_kprobe"))
4695
test_missed_perf_kprobe();
96+
if (test__start_subtest("kprobe_recursion"))
97+
test_missed_kprobe_recursion();
4798
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include "vmlinux.h"
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
#include "../bpf_testmod/bpf_testmod_kfunc.h"
6+
7+
char _license[] SEC("license") = "GPL";
8+
9+
/*
10+
* No tests in here, just to trigger 'bpf_fentry_test*'
11+
* through tracing test_run
12+
*/
13+
SEC("fentry/bpf_modify_return_test")
14+
int BPF_PROG(trigger)
15+
{
16+
return 0;
17+
}
18+
19+
SEC("kprobe.multi/bpf_fentry_test1")
20+
int test1(struct pt_regs *ctx)
21+
{
22+
bpf_kfunc_common_test();
23+
return 0;
24+
}
25+
26+
SEC("kprobe/bpf_kfunc_common_test")
27+
int test2(struct pt_regs *ctx)
28+
{
29+
return 0;
30+
}
31+
32+
SEC("kprobe/bpf_kfunc_common_test")
33+
int test3(struct pt_regs *ctx)
34+
{
35+
return 0;
36+
}
37+
38+
SEC("kprobe/bpf_kfunc_common_test")
39+
int test4(struct pt_regs *ctx)
40+
{
41+
return 0;
42+
}
43+
44+
SEC("kprobe.multi/bpf_kfunc_common_test")
45+
int test5(struct pt_regs *ctx)
46+
{
47+
return 0;
48+
}

0 commit comments

Comments
 (0)