[5/5] y2038: linux: Provide __timer_settime64 implementation
Commit Message
This patch provides new __timer_settime64 explicit 64 bit function for setting
flags, interval and value of specified timer.
Moreover, a 32 bit version - __timer_settime has been refactored to internally
use __timer_settime64.
The __timer_settime is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversion to 64 bit struct
__timespec64 from struct timespec (and opposite when old_value pointer is
provided).
The new __timer_settime64 syscall available from Linux 5.1+ has been used, when
applicable.
Build tests:
- The code has been tested on x86_64/x86 (native compilation):
make PARALLELMFLAGS="-j8" && make check PARALLELMFLAGS="-j8" && \\
make xcheck PARALLELMFLAGS="-j8"
- The glibc has been build tested (make PARALLELMFLAGS="-j8") for
x86 (i386), x86_64-x32, and armv7
Run-time tests:
- Run specific tests on ARM/x86 32bit systems (qemu):
https://github.com/lmajewski/meta-y2038 and run tests:
https://github.com/lmajewski/y2038-tests/commits/master
- Use of cross-test-ssh.sh for ARM (armv7):
make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck
Linux kernel, headers and minimal kernel version for glibc build test
matrix:
- Linux v5.1 (with timer_settime64) and glibc build with v5.1 as
minimal kernel version (--enable-kernel="5.1.0")
The __ASSUME_TIME64_SYSCALLS flag defined.
- Linux v5.1 and default minimal kernel version
The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports timer_settime64
syscall.
- Linux v4.19 (no timer_settime64 support) with default minimal kernel version
for contemporary glibc (3.2.0)
This kernel doesn't support timer_settime64 syscall, so the fallback to
timer_settime is tested.
Above tests were performed with Y2038 redirection applied as well as without
(so the __TIMESIZE != 64 execution path is checked as well).
No regressions were observed.
---
include/time.h | 9 ++++
sysdeps/unix/sysv/linux/timer_settime.c | 68 ++++++++++++++++++++++---
2 files changed, 71 insertions(+), 6 deletions(-)
Comments
Dear All,
> This patch provides new __timer_settime64 explicit 64 bit function
> for setting flags, interval and value of specified timer.
> Moreover, a 32 bit version - __timer_settime has been refactored to
> internally use __timer_settime64.
>
> The __timer_settime is now supposed to be used on systems still
> supporting 32 bit time (__TIMESIZE != 64) - hence the necessary
> conversion to 64 bit struct __timespec64 from struct timespec (and
> opposite when old_value pointer is provided).
>
> The new __timer_settime64 syscall available from Linux 5.1+ has been
> used, when applicable.
>
> Build tests:
> - The code has been tested on x86_64/x86 (native compilation):
> make PARALLELMFLAGS="-j8" && make check PARALLELMFLAGS="-j8" && \\
> make xcheck PARALLELMFLAGS="-j8"
>
> - The glibc has been build tested (make PARALLELMFLAGS="-j8") for
> x86 (i386), x86_64-x32, and armv7
>
> Run-time tests:
> - Run specific tests on ARM/x86 32bit systems (qemu):
> https://github.com/lmajewski/meta-y2038 and run tests:
> https://github.com/lmajewski/y2038-tests/commits/master
>
> - Use of cross-test-ssh.sh for ARM (armv7):
> make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh
> root@192.168.7.2' xcheck
>
> Linux kernel, headers and minimal kernel version for glibc build test
> matrix:
> - Linux v5.1 (with timer_settime64) and glibc build with v5.1 as
> minimal kernel version (--enable-kernel="5.1.0")
> The __ASSUME_TIME64_SYSCALLS flag defined.
>
> - Linux v5.1 and default minimal kernel version
> The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports
> timer_settime64 syscall.
>
> - Linux v4.19 (no timer_settime64 support) with default minimal
> kernel version for contemporary glibc (3.2.0)
> This kernel doesn't support timer_settime64 syscall, so the
> fallback to timer_settime is tested.
>
> Above tests were performed with Y2038 redirection applied as well as
> without (so the __TIMESIZE != 64 execution path is checked as well).
>
> No regressions were observed.
> ---
> include/time.h | 9 ++++
> sysdeps/unix/sysv/linux/timer_settime.c | 68
> ++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 6
> deletions(-)
>
> diff --git a/include/time.h b/include/time.h
> index 8b9a4b7a60..a46fd2f08a 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -186,6 +186,15 @@ extern int __timer_gettime64 (timer_t timerid,
> struct __itimerspec64 *value); libc_hidden_proto (__timer_gettime64);
> #endif
>
> +#if __TIMESIZE == 64
> +# define __timer_settime64 __timer_settime
> +#else
> +extern int __timer_settime64 (timer_t timerid, int flags,
> + const struct __itimerspec64 *value,
> + struct __itimerspec64 *ovalue);
> +libc_hidden_proto (__timer_settime64);
> +#endif
> +
> /* Compute the `struct tm' representation of T,
> offset OFFSET seconds east of UTC,
> and store year, yday, mon, mday, wday, hour, min, sec into *TP.
> diff --git a/sysdeps/unix/sysv/linux/timer_settime.c
> b/sysdeps/unix/sysv/linux/timer_settime.c index
> 51f24200aa..f847e3e44a 100644 ---
> a/sysdeps/unix/sysv/linux/timer_settime.c +++
> b/sysdeps/unix/sysv/linux/timer_settime.c @@ -20,17 +20,73 @@
> #include <stdlib.h>
> #include <time.h>
> #include <sysdep.h>
> +#include <kernel-features.h>
> #include "kernel-posix-timers.h"
>
> int
> -timer_settime (timer_t timerid, int flags, const struct itimerspec
> *value,
> - struct itimerspec *ovalue)
> +__timer_settime64 (timer_t timerid, int flags,
> + const struct __itimerspec64 *value,
> + struct __itimerspec64 *ovalue)
> {
> struct timer *kt = (struct timer *) timerid;
>
> - /* Delete the kernel timer object. */
> - int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
> - value, ovalue);
> +#ifdef __ASSUME_TIME64_SYSCALLS
> +# ifndef __NR_timer_settime64
> +# define __NR_timer_settime64 __NR_timer_settime
> +# endif
> + return INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags,
> value,
> + ovalue);
> +#else
> +# ifdef __NR_timer_settime64
> + int ret = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags,
> value,
> + ovalue);
> + if (ret == 0 || errno != ENOSYS)
> + return ret;
> +# endif
> + struct itimerspec its32, oits32;
>
> - return res;
> + if (! in_time_t_range ((value->it_value).tv_sec)
> + || ! in_time_t_range ((value->it_interval).tv_sec))
> + {
> + __set_errno (EOVERFLOW);
> + return -1;
> + }
> +
> + its32.it_interval = valid_timespec64_to_timespec
> (value->it_interval);
> + its32.it_value = valid_timespec64_to_timespec (value->it_value);
> +
> + int retval = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
> + &its32, ovalue ? &oits32 : NULL);
> + if (! retval && ovalue)
> + {
> + ovalue->it_interval = valid_timespec_to_timespec64
> (oits32.it_interval);
> + ovalue->it_value = valid_timespec_to_timespec64
> (oits32.it_value);
> + }
> +
> + return retval;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +int
> +__timer_settime (timer_t timerid, int flags, const struct itimerspec
> *value,
> + struct itimerspec *ovalue)
> +{
> + struct __itimerspec64 its64, oits64;
> + int retval;
> +
> + its64.it_interval = valid_timespec_to_timespec64
> (value->it_interval);
> + its64.it_value = valid_timespec_to_timespec64 (value->it_value);
> +
> + retval = __timer_settime64 (timerid, flags, &its64, ovalue ?
> &oits64 : NULL);
> + if (! retval && ovalue)
> + {
> + ovalue->it_interval = valid_timespec64_to_timespec
> (oits64.it_interval);
> + ovalue->it_value = valid_timespec64_to_timespec
> (oits64.it_value);
> + }
> +
> + return retval;
> }
> +#endif
> +weak_alias (__timer_settime, timer_settime)
> +libc_hidden_def (timer_settime)
Gentle ping,
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
On 11/11/2019 18:47, Lukasz Majewski wrote:
> This patch provides new __timer_settime64 explicit 64 bit function for setting
> flags, interval and value of specified timer.
> Moreover, a 32 bit version - __timer_settime has been refactored to internally
> use __timer_settime64.
>
> The __timer_settime is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversion to 64 bit struct
> __timespec64 from struct timespec (and opposite when old_value pointer is
> provided).
>
> The new __timer_settime64 syscall available from Linux 5.1+ has been used, when
> applicable.
>
> Build tests:
> - The code has been tested on x86_64/x86 (native compilation):
> make PARALLELMFLAGS="-j8" && make check PARALLELMFLAGS="-j8" && \\
> make xcheck PARALLELMFLAGS="-j8"
>
> - The glibc has been build tested (make PARALLELMFLAGS="-j8") for
> x86 (i386), x86_64-x32, and armv7
>
> Run-time tests:
> - Run specific tests on ARM/x86 32bit systems (qemu):
> https://github.com/lmajewski/meta-y2038 and run tests:
> https://github.com/lmajewski/y2038-tests/commits/master
Does it have any additional coverage not present in glibc tests? If yes, would
be possible to enhance glibc tests?
>
> - Use of cross-test-ssh.sh for ARM (armv7):
> make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck
>
> Linux kernel, headers and minimal kernel version for glibc build test
> matrix:
> - Linux v5.1 (with timer_settime64) and glibc build with v5.1 as
> minimal kernel version (--enable-kernel="5.1.0")
> The __ASSUME_TIME64_SYSCALLS flag defined.
>
> - Linux v5.1 and default minimal kernel version
> The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports timer_settime64
> syscall.
>
> - Linux v4.19 (no timer_settime64 support) with default minimal kernel version
> for contemporary glibc (3.2.0)
> This kernel doesn't support timer_settime64 syscall, so the fallback to
> timer_settime is tested.
>
> Above tests were performed with Y2038 redirection applied as well as without
> (so the __TIMESIZE != 64 execution path is checked as well).
>
> No regressions were observed.
LGTM with some changes below.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> include/time.h | 9 ++++
> sysdeps/unix/sysv/linux/timer_settime.c | 68 ++++++++++++++++++++++---
> 2 files changed, 71 insertions(+), 6 deletions(-)
>
> diff --git a/include/time.h b/include/time.h
> index 8b9a4b7a60..a46fd2f08a 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -186,6 +186,15 @@ extern int __timer_gettime64 (timer_t timerid, struct __itimerspec64 *value);
> libc_hidden_proto (__timer_gettime64);
> #endif
>
> +#if __TIMESIZE == 64
> +# define __timer_settime64 __timer_settime
> +#else
> +extern int __timer_settime64 (timer_t timerid, int flags,
> + const struct __itimerspec64 *value,
> + struct __itimerspec64 *ovalue);
> +libc_hidden_proto (__timer_settime64);
> +#endif
> +
> /* Compute the `struct tm' representation of T,
> offset OFFSET seconds east of UTC,
> and store year, yday, mon, mday, wday, hour, min, sec into *TP.
Ok, it follows current practice.
> diff --git a/sysdeps/unix/sysv/linux/timer_settime.c b/sysdeps/unix/sysv/linux/timer_settime.c
> index 51f24200aa..f847e3e44a 100644
> --- a/sysdeps/unix/sysv/linux/timer_settime.c
> +++ b/sysdeps/unix/sysv/linux/timer_settime.c
> @@ -20,17 +20,73 @@
> #include <stdlib.h>
> #include <time.h>
> #include <sysdep.h>
> +#include <kernel-features.h>
> #include "kernel-posix-timers.h"
>
> int
> -timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
> - struct itimerspec *ovalue)
> +__timer_settime64 (timer_t timerid, int flags,
> + const struct __itimerspec64 *value,
> + struct __itimerspec64 *ovalue)
> {
> struct timer *kt = (struct timer *) timerid;
>
> - /* Delete the kernel timer object. */
> - int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
> - value, ovalue);
> +#ifdef __ASSUME_TIME64_SYSCALLS
> +# ifndef __NR_timer_settime64
> +# define __NR_timer_settime64 __NR_timer_settime
> +# endif
> + return INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags, value,
> + ovalue);
> +#else
Use INLINE_SYSCALL_CALL.
> +# ifdef __NR_timer_settime64
> + int ret = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags, value,
> + ovalue);
> + if (ret == 0 || errno != ENOSYS)
> + return ret;
> +# endif
Ditto.
> + struct itimerspec its32, oits32;
>
> - return res;
> + if (! in_time_t_range ((value->it_value).tv_sec)
> + || ! in_time_t_range ((value->it_interval).tv_sec))
> + {
> + __set_errno (EOVERFLOW);
> + return -1;
> + }
Ok.
> +
> + its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
> + its32.it_value = valid_timespec64_to_timespec (value->it_value);
> +
> + int retval = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
> + &its32, ovalue ? &oits32 : NULL);
Use INLINE_SYSCALL_CALL.
> + if (! retval && ovalue)
Use explicit comparisons.
> + {
> + ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
> + ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
> + }
> +
> + return retval;
> +#endif
> +}
> +
Ok.
> +#if __TIMESIZE != 64
> +int
> +__timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
> + struct itimerspec *ovalue)
> +{
> + struct __itimerspec64 its64, oits64;
> + int retval;
> +
> + its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
> + its64.it_value = valid_timespec_to_timespec64 (value->it_value);
> +
> + retval = __timer_settime64 (timerid, flags, &its64, ovalue ? &oits64 : NULL);
> + if (! retval && ovalue)
Use explicit comparisons.
> + {
> + ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
> + ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
> + }
> +
> + return retval;
> }
> +#endif
> +weak_alias (__timer_settime, timer_settime)
> +libc_hidden_def (timer_settime)
>
Ok.
@@ -186,6 +186,15 @@ extern int __timer_gettime64 (timer_t timerid, struct __itimerspec64 *value);
libc_hidden_proto (__timer_gettime64);
#endif
+#if __TIMESIZE == 64
+# define __timer_settime64 __timer_settime
+#else
+extern int __timer_settime64 (timer_t timerid, int flags,
+ const struct __itimerspec64 *value,
+ struct __itimerspec64 *ovalue);
+libc_hidden_proto (__timer_settime64);
+#endif
+
/* Compute the `struct tm' representation of T,
offset OFFSET seconds east of UTC,
and store year, yday, mon, mday, wday, hour, min, sec into *TP.
@@ -20,17 +20,73 @@
#include <stdlib.h>
#include <time.h>
#include <sysdep.h>
+#include <kernel-features.h>
#include "kernel-posix-timers.h"
int
-timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
- struct itimerspec *ovalue)
+__timer_settime64 (timer_t timerid, int flags,
+ const struct __itimerspec64 *value,
+ struct __itimerspec64 *ovalue)
{
struct timer *kt = (struct timer *) timerid;
- /* Delete the kernel timer object. */
- int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
- value, ovalue);
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_timer_settime64
+# define __NR_timer_settime64 __NR_timer_settime
+# endif
+ return INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags, value,
+ ovalue);
+#else
+# ifdef __NR_timer_settime64
+ int ret = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags, value,
+ ovalue);
+ if (ret == 0 || errno != ENOSYS)
+ return ret;
+# endif
+ struct itimerspec its32, oits32;
- return res;
+ if (! in_time_t_range ((value->it_value).tv_sec)
+ || ! in_time_t_range ((value->it_interval).tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
+ its32.it_value = valid_timespec64_to_timespec (value->it_value);
+
+ int retval = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
+ &its32, ovalue ? &oits32 : NULL);
+ if (! retval && ovalue)
+ {
+ ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
+ ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
+ }
+
+ return retval;
+#endif
+}
+
+#if __TIMESIZE != 64
+int
+__timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
+ struct itimerspec *ovalue)
+{
+ struct __itimerspec64 its64, oits64;
+ int retval;
+
+ its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
+ its64.it_value = valid_timespec_to_timespec64 (value->it_value);
+
+ retval = __timer_settime64 (timerid, flags, &its64, ovalue ? &oits64 : NULL);
+ if (! retval && ovalue)
+ {
+ ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
+ ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
+ }
+
+ return retval;
}
+#endif
+weak_alias (__timer_settime, timer_settime)
+libc_hidden_def (timer_settime)