Skip to contentSkip to conversation

selftests/bpf: fix selftest after random:urandom_read tracepoint removal

PATCH Superseded Andrii Nakryiko 3 participants 3 messages Mar 25, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 selftests/bpf: fix selftest after random:urandom_read tracepoint removal

14c174633f34 ("random: remove unused tracepoints") removed all the tracepoints from drivers/char/random.c, one of which, random:urandom_read, was used by stacktrace_build_id selftest to trigger stack trace capture from two different kernel code paths.

Fix breakage by switching to kprobing chacha_block_generic() function which is also called in both code paths that selftest uses for triggering.

---
 tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +1 -1
index 36a707e7c7a7..698fef6d90bc 100644
@@ -47,7 +47,7 @@ struct random_urandom_args {
 	int input_left;
 };
 
-SEC("tracepoint/random/urandom_read")
+SEC("kprobe/chacha_block_generic")
 int oncpu(struct random_urandom_args *args)
 {
 	__u32 max_len = sizeof(struct bpf_stack_build_id)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 19 lines · Andrii Nakryiko

14c174633f34 ("random: remove unused tracepoints") removed all the tracepoints from drivers/char/random.c, one of which, random:urandom_read, was used by stacktrace_build_id selftest to trigger stack trace capture from two different kernel code paths.

Fix breakage by switching to kprobing chacha_block_generic() function which is also called in both code paths that selftest uses for triggering.

---
  tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +0 -0
index 36a707e7c7a7..698fef6d90bc 100644

tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c struct random_urandom_args { · line 50

Quoted 5 lines
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +1 -1
@@ -47,7 +47,7 @@ struct random_urandom_args {
  	int input_left;
  };
 
-SEC("tracepoint/random/urandom_read")
+SEC("kprobe/chacha_block_generic")

I tried this and it doesn't work in my environment. But changing to
SEC("kprobe/urandom_read")
works.

Also, if using kprobe, maybe rename 'struct random_urandom_args' to 'struct pt_regs'? Also, the struct random_urandom_args definition can be removed.

Quoted 3 lines
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +0 -0
  int oncpu(struct random_urandom_args *args)
  {
  	__u32 max_len = sizeof(struct bpf_stack_build_id)
#2 lore raw
Quoted 26 lines · Yonghong Song
Quoted 22 lines · Andrii Nakryiko

14c174633f34 ("random: remove unused tracepoints") removed all the tracepoints from drivers/char/random.c, one of which, random:urandom_read, was used by stacktrace_build_id selftest to trigger stack trace capture from two different kernel code paths.

Fix breakage by switching to kprobing chacha_block_generic() function which is also called in both code paths that selftest uses for triggering.

---
  tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +0 -0
index 36a707e7c7a7..698fef6d90bc 100644
@@ -47,7 +47,7 @@ struct random_urandom_args {
      int input_left;
  };
 
Quoted 7 lines

tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c struct random_urandom_args { · line 50

Quoted 2 lines
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +1 -1
-SEC("tracepoint/random/urandom_read")
+SEC("kprobe/chacha_block_generic")

I tried this and it doesn't work in my environment. But changing to
SEC("kprobe/urandom_read")
works.

I noticed flakiness locally as well. Switching to kprobe/urandom_read seems to work well, thanks!

Quoted 4 lines

Also, if using kprobe, maybe rename 'struct random_urandom_args' to 'struct pt_regs'? Also, the struct random_urandom_args definition can be removed.

yep, missed the need to clean this up. I'll send v2 shortly.

Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c +0 -0
  int oncpu(struct random_urandom_args *args)
  {
      __u32 max_len = sizeof(struct bpf_stack_build_id)