netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time
@ 2020-03-14  0:27 Andrii Nakryiko
  2020-03-14  0:34 ` Martin KaFai Lau
  2020-03-17 18:56 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-03-14  0:27 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

Amazingly, some libc implementations don't call __NR_nanosleep syscall from
their nanosleep() APIs. Hammer it down with explicit syscall() call and never
get back to it again. Also simplify code for timespec initialization.

I verified that nanosleep is called w/ printk and in exactly same Linux image
that is used in Travis CI. So it should both sleep and call correct syscall.

v1->v2:
  - math is too hard, fix usec -> nsec convertion (Martin);
  - test_vmlinux has explicit nanosleep() call, convert that one as well.

Fixes: 4e1fd25d19e8 ("selftests/bpf: Fix usleep() implementation")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/testing/selftests/bpf/prog_tests/vmlinux.c |  2 +-
 tools/testing/selftests/bpf/test_progs.c         | 16 ++++++----------
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/vmlinux.c b/tools/testing/selftests/bpf/prog_tests/vmlinux.c
index 04939eda1325..72310cfc6474 100644
--- a/tools/testing/selftests/bpf/prog_tests/vmlinux.c
+++ b/tools/testing/selftests/bpf/prog_tests/vmlinux.c
@@ -11,7 +11,7 @@ static void nsleep()
 {
 	struct timespec ts = { .tv_nsec = MY_TV_NSEC };
 
-	(void)nanosleep(&ts, NULL);
+	(void)syscall(__NR_nanosleep, &ts, NULL);
 }
 
 void test_vmlinux(void)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index f85a06512541..dc12fd0de1c2 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -35,16 +35,12 @@ struct prog_test_def {
  */
 int usleep(useconds_t usec)
 {
-	struct timespec ts;
-
-	if (usec > 999999) {
-		ts.tv_sec = usec / 1000000;
-		ts.tv_nsec = usec % 1000000;
-	} else {
-		ts.tv_sec = 0;
-		ts.tv_nsec = usec;
-	}
-	return nanosleep(&ts, NULL);
+	struct timespec ts = {
+		.tv_sec = usec / 1000000,
+		.tv_nsec = (usec % 1000000) * 1000,
+	};
+
+	return syscall(__NR_nanosleep, &ts, NULL);
 }
 
 static bool should_run(struct test_selector *sel, int num, const char *name)
-- 
2.17.1


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

* Re: [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time
  2020-03-14  0:27 [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time Andrii Nakryiko
@ 2020-03-14  0:34 ` Martin KaFai Lau
  2020-03-17 18:56 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2020-03-14  0:34 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, andrii.nakryiko, kernel-team

On Fri, Mar 13, 2020 at 05:27:43PM -0700, Andrii Nakryiko wrote:
> Amazingly, some libc implementations don't call __NR_nanosleep syscall from
> their nanosleep() APIs. Hammer it down with explicit syscall() call and never
> get back to it again. Also simplify code for timespec initialization.
> 
> I verified that nanosleep is called w/ printk and in exactly same Linux image
> that is used in Travis CI. So it should both sleep and call correct syscall.
> 
> v1->v2:
>   - math is too hard, fix usec -> nsec convertion (Martin);
>   - test_vmlinux has explicit nanosleep() call, convert that one as well.
Acked-by: Martin KaFai Lau <kafai@fb.com>

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

* Re: [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time
  2020-03-14  0:27 [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time Andrii Nakryiko
  2020-03-14  0:34 ` Martin KaFai Lau
@ 2020-03-17 18:56 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-03-17 18:56 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, netdev, ast; +Cc: andrii.nakryiko, kernel-team

On 3/14/20 1:27 AM, Andrii Nakryiko wrote:
> Amazingly, some libc implementations don't call __NR_nanosleep syscall from
> their nanosleep() APIs. Hammer it down with explicit syscall() call and never
> get back to it again. Also simplify code for timespec initialization.
> 
> I verified that nanosleep is called w/ printk and in exactly same Linux image
> that is used in Travis CI. So it should both sleep and call correct syscall.
> 
> v1->v2:
>    - math is too hard, fix usec -> nsec convertion (Martin);
>    - test_vmlinux has explicit nanosleep() call, convert that one as well.
> 
> Fixes: 4e1fd25d19e8 ("selftests/bpf: Fix usleep() implementation")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied, thanks!

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

end of thread, other threads:[~2020-03-17 18:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-14  0:27 [PATCH v2 bpf-next] selftests/bpf: fix nanosleep for real this time Andrii Nakryiko
2020-03-14  0:34 ` Martin KaFai Lau
2020-03-17 18:56 ` Daniel Borkmann

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).