Skip to content

Commit 57385ae

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Make perf_buffer selftests work on 4.9 kernel again
Recent change to use tp/syscalls/sys_enter_nanosleep for perf_buffer selftests causes this selftest to fail on 4.9 kernel in libbpf CI ([0]): libbpf: prog 'handle_sys_enter': failed to attach to perf_event FD 6: Invalid argument libbpf: prog 'handle_sys_enter': failed to attach to tracepoint 'syscalls/sys_enter_nanosleep': Invalid argument It's not exactly clear why, because perf_event itself is created for this tracepoint, but I can't even compile 4.9 kernel locally, so it's hard to figure this out. If anyone has better luck and would like to help investigating this, I'd really appreciate this. For now, unblock CI by switching back to raw_syscalls/sys_enter, but reduce amount of unnecessary samples emitted by filter by process ID. Use explicit ARRAY map for that to make it work on 4.9 as well, because global data isn't yet supported there. Fixes: aa274f9 ("selftests/bpf: Fix possible/online index mismatch in perf_buffer test") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent fae1b05 commit 57385ae

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ int trigger_on_cpu(int cpu)
4646
void serial_test_perf_buffer(void)
4747
{
4848
int err, on_len, nr_on_cpus = 0, nr_cpus, i, j;
49+
int zero = 0, my_pid = getpid();
4950
struct perf_buffer_opts pb_opts = {};
5051
struct test_perf_buffer *skel;
5152
cpu_set_t cpu_seen;
@@ -71,6 +72,10 @@ void serial_test_perf_buffer(void)
7172
if (CHECK(!skel, "skel_load", "skeleton open/load failed\n"))
7273
goto out_close;
7374

75+
err = bpf_map_update_elem(bpf_map__fd(skel->maps.my_pid_map), &zero, &my_pid, 0);
76+
if (!ASSERT_OK(err, "my_pid_update"))
77+
goto out_close;
78+
7479
/* attach probe */
7580
err = test_perf_buffer__attach(skel);
7681
if (CHECK(err, "attach_kprobe", "err %d\n", err))

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,36 @@
66
#include <bpf/bpf_helpers.h>
77
#include <bpf/bpf_tracing.h>
88

9+
struct {
10+
__uint(type, BPF_MAP_TYPE_ARRAY);
11+
__type(key, int);
12+
__type(value, int);
13+
__uint(max_entries, 1);
14+
} my_pid_map SEC(".maps");
15+
916
struct {
1017
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
1118
__type(key, int);
1219
__type(value, int);
1320
} perf_buf_map SEC(".maps");
1421

15-
SEC("tp/syscalls/sys_enter_nanosleep")
22+
SEC("tp/raw_syscalls/sys_enter")
1623
int handle_sys_enter(void *ctx)
1724
{
25+
int zero = 0, *my_pid, cur_pid;
1826
int cpu = bpf_get_smp_processor_id();
1927

28+
my_pid = bpf_map_lookup_elem(&my_pid_map, &zero);
29+
if (!my_pid)
30+
return 1;
31+
32+
cur_pid = bpf_get_current_pid_tgid() >> 32;
33+
if (cur_pid != *my_pid)
34+
return 1;
35+
2036
bpf_perf_event_output(ctx, &perf_buf_map, BPF_F_CURRENT_CPU,
2137
&cpu, sizeof(cpu));
22-
return 0;
38+
return 1;
2339
}
2440

2541
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)