libs: Import vdso parsing lib from kernel tree
PATCH v2 1/2 libs: Import vdso parsing lib from kernel tree
This imports the vdso symbol parsing library from the kernel tree.
---
V2: New patch.
include/parse_vdso.h | 16 +++ libs/libltpvdso/Makefile | 11 ++ libs/libltpvdso/README | 1 + libs/libltpvdso/parse_vdso.c | 269 +++++++++++++++++++++++++++++++++++ 4 files changed, 297 insertions(+) create mode 100644 include/parse_vdso.h create mode 100644 libs/libltpvdso/Makefile create mode 100644 libs/libltpvdso/README create mode 100644 libs/libltpvdso/parse_vdso.c
include/parse_vdso.h new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Linaro Limited. All rights reserved. +* Author: Viresh Kumar <[email protected]> +*/ + +#ifndef PARSE_VDSO_H__ +#define PARSE_VDSO_H__ + +#include <stdint.h> + +extern void vdso_init_from_auxv (void *auxv); +extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); +extern void *vdso_sym (const char *version,const char *name); + +#endif /* PARSE_VDSO_H__ */
libs/libltpvdso/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) International Business Machines Corp., 2001 + +top_srcdir ?= ../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +LIB := libltpvdso.a + +include $(top_srcdir)/include/mk/lib.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
libs/libltpvdso/README new file +1 -0
@@ -0,0 +1 @@ +Copied from kernel tree: tools/testing/selftests/vDSO/parse_vdso.c
libs/libltpvdso/parse_vdso.c new file +269 -0
269 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v2 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
An issue was reported recently where a bug was found during successive reading of 64 bit time on arm32 platforms. Add a test for that.
https://github.com/richfelker/musl-cross-make/issues/96
---
V2:
- Test vDSOs as well and overall improved test.
runtest/syscalls | 1 + .../kernel/syscalls/clock_gettime/.gitignore | 1 + .../kernel/syscalls/clock_gettime/Makefile | 5 +- .../syscalls/clock_gettime/clock_gettime04.c | 197 ++++++++++++++++++ 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
runtest/syscalls +1 -0
@@ -96,6 +96,7 @@ clock_nanosleep04 clock_nanosleep04 clock_gettime01 clock_gettime01 clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 +clock_gettime04 clock_gettime04 leapsec01 leapsec01 clock_settime01 clock_settime01
testcases/kernel/syscalls/clock_gettime/.gitignore +1 -0
@@ -1,4 +1,5 @@ clock_gettime01 clock_gettime02 clock_gettime03 +clock_gettime04 leapsec01
testcases/kernel/syscalls/clock_gettime/Makefile +4 -1
@@ -3,8 +3,11 @@ top_srcdir ?= ../../../.. +LTPLIBS = ltpvdso + include $(top_srcdir)/include/mk/testcases.mk LDLIBS+=-lrt +clock_gettime04: LDLIBS += -lltpvdso -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v2 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Quoted 10 lines · Viresh Kumar
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +10
-0+static void find_vdso_helpers (void ) +{ +/* +* Some vDSO exports its clock_gettime() implementation with a different +* name and version from other architectures, so we need to handle it as +* a special case. +*/ +#if defined(__powerpc__) || defined(__powerpc64__) +const char *version ="LINUX_2.6.15" ; +const char *name ="__kernel_clock_gettime" ;
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c line 68
Quoted 10 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +10
-0+#elif defined(__aarch64__) +const char *version ="LINUX_2.6.39" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__s390__) +const char *version ="LINUX_2.6.29" ; +const char *name ="__kernel_clock_gettime" ; +#else +const char *version ="LINUX_2.6" ; +const char *name ="__vdso_clock_gettime" ; +#endif
I see that risc-v uses version="LINUX_4.15", and nds32 uses "LINUX_4", the other ones look correct.
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c line 155
Quoted 8 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +8
-0+ ret = tv->gettime (clks[i],tst_ts_get (&ts)); +if (ret) { +if (errno !=ENOSYS ) { +tst_res (TFAIL |TERRNO ,"%s: clock_gettime() failed (%d)" , +tst_clock_name (clks[i]), j); + } +continue ; + }
Is this a test case failure, or does it still succeed after skipping a call? When any of the variants (in particular vdso_clock_gettime64) don't exist, I think you just need to continue without printing anything. Note that older kernels before v5.1 don't have the clock_gettime64 syscall, while riscv and future architectures as well as kernels with CONFIG_COMPAT_32BIT_TIME=n don't have clock_gettime(),
and some architectures don't have a vdso, or only the time32 version of it.
Arnd
Arnd
PATCH v2 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Quoted 16 lines · Arnd Bergmann
Quoted 15 lines · Viresh Kumar
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +15
-0+static void find_vdso_helpers (void ) +{ +/* +* Some vDSO exports its clock_gettime() implementation with a different +* name and version from other architectures, so we need to handle it as +* a special case. +*/ +#if defined(__powerpc__) || defined(__powerpc64__) +const char *version ="LINUX_2.6.15" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__aarch64__) +const char *version ="LINUX_2.6.39" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__s390__) +const char *version ="LINUX_2.6.29" ;
Quoted 8 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c line 68
Quoted 5 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +5
-0+const char *name ="__kernel_clock_gettime" ; +#else +const char *version ="LINUX_2.6" ; +const char *name ="__vdso_clock_gettime" ; +#endif I see that risc-v uses version="LINUX_4.15", and nds32 uses "
LINUX_4", the other ones look correct.
My bad, I only looked at man page of vdso for clock_gettime(), while I looked at kernel source for clock_gettime64() :(
Quoted 10 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c line 155
Quoted 8 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +8
-0+ ret = tv->gettime (clks[i],tst_ts_get (&ts)); +if (ret) { +if (errno !=ENOSYS ) { +tst_res (TFAIL |TERRNO ,"%s: clock_gettime() failed (%d)" , +tst_clock_name (clks[i]), j); + } +continue ; + }Is this a test case failure, or does it still succeed after skipping a call?
"continue" takes us to the next variant for the current test loop (out of 10000 loops). So we don't exit here, though this reports a failure and that will be visible in the output. But because we continue here, we will also see a TPASS at the end for the same clock. So if the test was running for CLOCK_REALTIME, then we will see both FAIL and PASS in output. I didn't wanted to abandon the test in such a case and so kept it like that.
Quoted 2 lines
When any of the variants (in particular
vdso_clock_gettime64) don't exist, I think you just need to continue without printing anything.
That is exactly why we are looking for ENOSYS here. The other code (which you removed) explicitly sets the error to ENOSYS if clock_gettime64() or clock_gettime() vdso isn't available. And so we won't print an error here. Though the setup routine will print only once if the vdso wasn't available, as general information.
Quoted 5 lines
Note that older kernels before v5.1 don't have the
clock_gettime64syscall, while riscv and future architectures as well as kernels withCONFIG_COMPAT_32BIT_TIME=ndon't haveclock_gettime(),
and some architectures don't have a vdso, or only the time32 version of it.
Signature · 1 line
viresh
PATCH v2 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Quoted 11 lines · Viresh Kumar
Quoted 2 lines · Arnd Bergmann
When any of the variants (in particular
vdso_clock_gettime64) don't exist, I think you just need to continue without printing anything.That is exactly why we are looking for ENOSYS here. The other code (which you removed) explicitly sets the error to ENOSYS if
clock_gettime64()orclock_gettime()vdso isn't available. And so we won't print an error here. Though the setup routine will print only once if the vdso wasn't available, as general information.
Ok, got it, I misread the != ENOSYS check for ==ENOSYS.
Arnd
PATCH v3 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
In reply to Viresh KumarAn issue was reported recently where a bug was found during successive reading of 64 bit time on arm32 platforms. Add a test for that.
https://github.com/richfelker/musl-cross-make/issues/96
---
V3:
- Add version info for riscv and nds32
- Don't print PASS along with FAIL for failure cases.
runtest/syscalls | 1 + .../kernel/syscalls/clock_gettime/.gitignore | 1 + .../kernel/syscalls/clock_gettime/Makefile | 5 +- .../syscalls/clock_gettime/clock_gettime04.c | 208 ++++++++++++++++++ 4 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
runtest/syscalls +1 -0
@@ -96,6 +96,7 @@ clock_nanosleep04 clock_nanosleep04 clock_gettime01 clock_gettime01 clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 +clock_gettime04 clock_gettime04 leapsec01 leapsec01 clock_settime01 clock_settime01
testcases/kernel/syscalls/clock_gettime/.gitignore +1 -0
@@ -1,4 +1,5 @@ clock_gettime01 clock_gettime02 clock_gettime03 +clock_gettime04 leapsec01
testcases/kernel/syscalls/clock_gettime/Makefile +4 -1
@@ -3,8 +3,11 @@ top_srcdir ?= ../../../.. +LTPLIBS = ltpvdso + include $(top_srcdir)/include/mk/testcases.mk LDLIBS+=-lrt +clock_gettime04: LDLIBS += -lltpvdso -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v3 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Quoted 7 lines · Viresh Kumar
An issue was reported recently where a bug was found during successive reading of 64 bit time on arm32 platforms. Add a test for that.
https://github.com/richfelker/musl-cross-make/issues/96
Signed-off-by Viresh Kumar <[email protected]>
There was one more thing I had originally suggested as an optional thing to test for:
- ensure that CLOCK_REALTIME_COARSE/CLOCK_MONOTONIC_COARSE is at most clock_getres() nanoseconds behind CLOCK_REALTIME/CLOCK_MONOTONIC, and never ahead of it.
It's probably too much to put into this test, and I'm not sure we really need to test for it. Are you still looking into this, or do you think we should stop here?
Arnd
PATCH v3 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Quoted 10 lines · Arnd Bergmann
There was one more thing I had originally suggested as an optional thing to test for:
- ensure that CLOCK_REALTIME_COARSE/CLOCK_MONOTONIC_COARSE is at most
clock_getres()nanoseconds behind CLOCK_REALTIME/CLOCK_MONOTONIC, and never ahead of it.It's probably too much to put into this test, and I'm not sure we really need to test for it. Are you still looking into this, or do you think we should stop here?
Sorry, I missed replying to it. When you suggest something, you suggest too much (which is good) and I get lost implementing all of it :)
Can you have a look at the attached test? This is already merged in LTP and does what you are asking to some level (not exactly though) and so I thought we don't need to do it again.
Signature · 8 lines
viresh -------------- next part -------------- A non-text attachment was scrubbed... Name: clock_gettime03.c Type: text/x-csrc Size: 3613 bytes Desc: not available URL: <http://lists.linux.it/pipermail/ltp/attachments/20200612/5971a5bc/attachment.c>
PATCH v3 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
In reply to Viresh KumarHi!
Quoted 60 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +60
-0+typedef int (*gettime_t )(clockid_t clk_id,void *ts); +static gettime_t ptr_vdso_gettime, ptr_vdso_gettime64; + +static inline int _vdso_gettime (gettime_t vdso,clockid_t clk_id,void *ts) +{ +if (!vdso) { + errno =ENOSYS ; +return -1 ; + } + +return vdso (clk_id, ts); +} + +static inline int vdso_gettime (clockid_t clk_id,void *ts) +{ +return _vdso_gettime (ptr_vdso_gettime, clk_id, ts); +} + +static inline int vdso_gettime64 (clockid_t clk_id,void *ts) +{ +return _vdso_gettime (ptr_vdso_gettime64, clk_id, ts); +} + +static void find_vdso_helpers (void ) +{ +/* +* Some vDSO exports its clock_gettime() implementation with a different +* name and version from other architectures, so we need to handle it as +* a special case. +*/ +#if defined(__powerpc__) || defined(__powerpc64__) +const char *version ="LINUX_2.6.15" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__aarch64__) +const char *version ="LINUX_2.6.39" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__s390__) +const char *version ="LINUX_2.6.29" ; +const char *name ="__kernel_clock_gettime" ; +#elif defined(__nds32__) +const char *version ="LINUX_4" ; +const char *name ="__vdso_clock_gettime" ; +#elif defined(__riscv) +const char *version ="LINUX_4.15" ; +const char *name ="__vdso_clock_gettime" ; +#else +const char *version ="LINUX_2.6" ; +const char *name ="__vdso_clock_gettime" ; +#endif + +const char *version64 ="LINUX_2.6" ; +const char *name64 ="__vdso_clock_gettime64" ; + +unsigned long sysinfo_ehdr =getauxval (AT_SYSINFO_EHDR ); + +if (!sysinfo_ehdr) { +tst_res (TINFO ,"Couldn't find AT_SYSINFO_EHDR" ); +return ; + } +
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c line 95
Quoted 10 lines
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +10
-0+vdso_init_from_sysinfo_ehdr (sysinfo_ehdr); + + ptr_vdso_gettime =vdso_sym (version, name); +if (!ptr_vdso_gettime) +tst_res (TINFO ,"Couldn't find vdso_gettime()" ); + + ptr_vdso_gettime64 =vdso_sym (version64, name64); +if (!ptr_vdso_gettime64) +tst_res (TINFO ,"Couldn't find vdso_gettime64()" ); +}
Shouldn't we put this code into the vdso lib so that we can add vdso variant to all clock_gettime() tests?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
In reply to Viresh KumarAn issue was reported recently where a bug was found during successive reading of 64 bit time on arm32 platforms. Add a test for that.
https://github.com/richfelker/musl-cross-make/issues/96
---
V4: Moved some code to vdso_helpers.c
include/parse_vdso.h | 6 + libs/libltpvdso/vdso_helpers.c | 69 ++++++++ runtest/syscalls | 1 + .../kernel/syscalls/clock_gettime/.gitignore | 1 + .../kernel/syscalls/clock_gettime/Makefile | 3 + .../syscalls/clock_gettime/clock_gettime04.c | 162 ++++++++++++++++++ 6 files changed, 242 insertions(+) create mode 100644 libs/libltpvdso/vdso_helpers.c create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
include/parse_vdso.h +6 -0
@@ -28,8 +28,14 @@* * These are the prototypes: */ + +#include <time.h> +extern void vdso_init_from_auxv (void *auxv);extern void vdso_init_from_sysinfo_ehdr (uintptr_t base);extern void *vdso_sym (const char *version,const char *name); +typedef int (*gettime_t )(clockid_t clk_id,void *ts); +void find_clock_gettime_vdso (gettime_t *ptr_vdso_gettime, +gettime_t *ptr_vdso_gettime64);#endif /* PARSE_VDSO_H__ */
libs/libltpvdso/vdso_helpers.c new file +69 -0
69 lines not on this page · raw message
runtest/syscalls +1 -0
@@ -96,6 +96,7 @@ clock_nanosleep04 clock_nanosleep04 clock_gettime01 clock_gettime01 clock_gettime02 clock_gettime02 clock_gettime03 clock_gettime03 +clock_gettime04 clock_gettime04 leapsec01 leapsec01 clock_settime01 clock_settime01
testcases/kernel/syscalls/clock_gettime/.gitignore +1 -0
@@ -1,4 +1,5 @@ clock_gettime01 clock_gettime02 clock_gettime03 +clock_gettime04 leapsec01
testcases/kernel/syscalls/clock_gettime/Makefile +3 -0
@@ -3,8 +3,11 @@ top_srcdir ?= ../../../.. +LTPLIBS = ltpvdso + include $(top_srcdir)/include/mk/testcases.mk LDLIBS+=-lrt +clock_gettime04: LDLIBS += -lltpvdso include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v4 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Hi!
Applied, thanks a lot.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 2/2 syscalls/clock_gettime: Add test to check bug during successive readings
Hi!
Quoted 1 line
Applied, thanks a lot.
With a minor change, indentifiers starting with underscore(s) are reserved for libc and kernel headers, we shall not use them, hence I renamed the _vdso_gettime() to do_vdso_gettime().
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 libs: Import vdso parsing lib from kernel tree
In reply to Viresh KumarHi!
Pushed with minor changes, thanks.
* Moved the comment about the function usage to the header
* Fixed some compiler warnings
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 libs: Import vdso parsing lib from kernel tree
Quoted 6 lines · Cyril Hrubis
Hi!
Pushed with minor changes, thanks.* Moved the comment about the function usage to the header
* Fixed some compiler warnings
I avoided these so in future we can simply copy paste the file from kernel tree to get more updates, and so we keep the delta between them to none.
Signature · 1 line
viresh
PATCH v2 1/2 libs: Import vdso parsing lib from kernel tree
Hi!
Quoted 9 lines
Quoted 5 lines
Pushed with minor changes, thanks.
* Moved the comment about the function usage to the header
* Fixed some compiler warnings
I avoided these so in future we can simply copy paste the file from kernel tree to get more updates, and so we keep the delta between them to none.
These were minor changes, so we can copy the file over and redo them.
Also it looks like the kernel Makefile does not enable warnings at all, which probably is not optimal, but who am I to complain...
Signature · 2 lines
Cyril Hrubis [email protected]