bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.
@ 2020-07-01 17:53 Hao Luo
  2020-07-01 18:04 ` Yonghong Song
  0 siblings, 1 reply; 3+ messages in thread
From: Hao Luo @ 2020-07-01 17:53 UTC (permalink / raw)
  To: netdev, bpf, linux-kernel, clang-built-linux
  Cc: sdf, Shuah Khan, Alexei Starovoitov, Andrii Nakryiko,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Hao Luo, linux-kselftest

The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing
programs. But in a kernel built by clang, which performs more aggresive
inlining, that function gets inlined into its caller SyS_nanosleep.
Therefore, even though fentry and kprobe do hook on the function,
they aren't triggered by the call to nanosleep in the test.

A possible fix is switching to use a function that is less likely to
be inlined, such as hrtimer_range_start_ns. The EXPORT_SYMBOL functions
shouldn't be inlined based on the description of [1], therefore safe
to use for this test. Also the arguments of this function include the
duration of sleep, therefore suitable for test verification.

[1] af3b56289be1 time: don't inline EXPORT_SYMBOL functions

Tested:
 In a clang build kernel, before this change, the test fails:

 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 switching 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>
Acked-by: Andrii Nakryiko <andriin@fb.com>
---
 Changelog since v1:
 - More accurate commit messages

 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;
 }
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.
  2020-07-01 17:53 [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns Hao Luo
@ 2020-07-01 18:04 ` Yonghong Song
  2020-07-01 22:17   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2020-07-01 18:04 UTC (permalink / raw)
  To: Hao Luo, netdev, bpf, linux-kernel, clang-built-linux
  Cc: sdf, Shuah Khan, Alexei Starovoitov, Andrii Nakryiko,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, John Fastabend,
	KP Singh, linux-kselftest



On 7/1/20 10:53 AM, Hao Luo wrote:
> The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing
> programs. But in a kernel built by clang, which performs more aggresive
> inlining, that function gets inlined into its caller SyS_nanosleep.
> Therefore, even though fentry and kprobe do hook on the function,
> they aren't triggered by the call to nanosleep in the test.
> 
> A possible fix is switching to use a function that is less likely to
> be inlined, such as hrtimer_range_start_ns. The EXPORT_SYMBOL functions
> shouldn't be inlined based on the description of [1], therefore safe
> to use for this test. Also the arguments of this function include the
> duration of sleep, therefore suitable for test verification.
> 
> [1] af3b56289be1 time: don't inline EXPORT_SYMBOL functions
> 
> Tested:
>   In a clang build kernel, before this change, the test fails:
> 
>   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 switching 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>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Thanks!
Acked-by: Yonghong Song <yhs@fb.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns.
  2020-07-01 18:04 ` Yonghong Song
@ 2020-07-01 22:17   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-07-01 22:17 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Hao Luo, Network Development, bpf, LKML, Clang-Built-Linux ML,
	Stanislav Fomichev, Shuah Khan, Alexei Starovoitov,
	Andrii Nakryiko, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	John Fastabend, KP Singh, open list:KERNEL SELFTEST FRAMEWORK

On Wed, Jul 1, 2020 at 11:04 AM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 7/1/20 10:53 AM, Hao Luo wrote:
> > The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing
> > programs. But in a kernel built by clang, which performs more aggresive
> > inlining, that function gets inlined into its caller SyS_nanosleep.
> > Therefore, even though fentry and kprobe do hook on the function,
> > they aren't triggered by the call to nanosleep in the test.
> >
> > A possible fix is switching to use a function that is less likely to
> > be inlined, such as hrtimer_range_start_ns. The EXPORT_SYMBOL functions
> > shouldn't be inlined based on the description of [1], therefore safe
> > to use for this test. Also the arguments of this function include the
> > duration of sleep, therefore suitable for test verification.
> >
> > [1] af3b56289be1 time: don't inline EXPORT_SYMBOL functions
> >
> > Tested:
> >   In a clang build kernel, before this change, the test fails:
> >
> >   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 switching 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>
> > Acked-by: Andrii Nakryiko <andriin@fb.com>
>
> Thanks!
> Acked-by: Yonghong Song <yhs@fb.com>

Applied. Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-01 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 17:53 [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns Hao Luo
2020-07-01 18:04 ` Yonghong Song
2020-07-01 22:17   ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).