lkml.org 
[lkml]   [2020]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH bpf-next] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.
From
Date


On 6/30/20 11:49 AM, Hao Luo wrote:
> The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing
> programs. But it seems Clang may have done an aggressive optimization,
> causing fentry and kprobe to not hook on this function properly on a
> Clang build kernel.

Could you explain why it does not on clang built kernel? How did you
build the kernel? Did you use [thin]lto?

hrtimer_nanosleep is a global function who is called in several
different files. I am curious how clang optimization can make
function disappear, or make its function signature change, or
rename the function?

>
> A possible fix is switching to use a more reliable function, e.g. the
> ones exported to kernel modules such as hrtimer_range_start_ns. After
> we switch to using hrtimer_range_start_ns, the test passes again even
> on a clang build kernel.
>
> Tested:
> In a clang build kernel, the test fail even when the flags
> {fentry, kprobe}_called are set unconditionally in handle__kprobe()
> and handle__fentry(), which implies the programs do not hook on
> hrtimer_nanosleep() properly. This could be because clang's code
> transformation is too aggressive.
>
> test_vmlinux:PASS:skel_open 0 nsec
> test_vmlinux:PASS:skel_attach 0 nsec
> test_vmlinux:PASS:tp 0 nsec
> test_vmlinux:PASS:raw_tp 0 nsec
> test_vmlinux:PASS:tp_btf 0 nsec
> test_vmlinux:FAIL:kprobe not called
> test_vmlinux:FAIL:fentry not called
>
> After we switch to hrtimer_range_start_ns, the test passes.
>
> test_vmlinux:PASS:skel_open 0 nsec
> test_vmlinux:PASS:skel_attach 0 nsec
> test_vmlinux:PASS:tp 0 nsec
> test_vmlinux:PASS:raw_tp 0 nsec
> test_vmlinux:PASS:tp_btf 0 nsec
> test_vmlinux:PASS:kprobe 0 nsec
> test_vmlinux:PASS:fentry 0 nsec
>
> Signed-off-by: Hao Luo <haoluo@google.com>
> ---
> tools/testing/selftests/bpf/progs/test_vmlinux.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_vmlinux.c b/tools/testing/selftests/bpf/progs/test_vmlinux.c
> index 5611b564d3b1..29fa09d6a6c6 100644
> --- a/tools/testing/selftests/bpf/progs/test_vmlinux.c
> +++ b/tools/testing/selftests/bpf/progs/test_vmlinux.c
> @@ -63,20 +63,20 @@ int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id)
> return 0;
> }
>
> -SEC("kprobe/hrtimer_nanosleep")
> -int BPF_KPROBE(handle__kprobe,
> - ktime_t rqtp, enum hrtimer_mode mode, clockid_t clockid)
> +SEC("kprobe/hrtimer_start_range_ns")
> +int BPF_KPROBE(handle__kprobe, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
> + const enum hrtimer_mode mode)
> {
> - if (rqtp == MY_TV_NSEC)
> + if (tim == MY_TV_NSEC)
> kprobe_called = true;
> return 0;
> }
>
> -SEC("fentry/hrtimer_nanosleep")
> -int BPF_PROG(handle__fentry,
> - ktime_t rqtp, enum hrtimer_mode mode, clockid_t clockid)
> +SEC("fentry/hrtimer_start_range_ns")
> +int BPF_PROG(handle__fentry, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
> + const enum hrtimer_mode mode)
> {
> - if (rqtp == MY_TV_NSEC)
> + if (tim == MY_TV_NSEC)
> fentry_called = true;
> return 0;
> }
>

\
 
 \ /
  Last update: 2020-06-30 22:38    [W:0.100 / U:0.420 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site