public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time
@ 2020-04-26 13:31 Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
                   ` (9 more replies)
  0 siblings, 10 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch series converts clock_adjtime to support 64 bit time (by using
clock_adjtime64) when __ASSUME_TIME64_SYSCALLS is defined.

This change required introduction of two new internal types - struct
__ntptimeval64 and struct __timex64 to accomodate 64 bit time on architectures
with __TIMESIZE != 64 and __WORDSIZE == 32.
In several places in the glibc the struct timeval has been replaced with struct
__timeval64.

As a result new, 64 bit supporting functions:
__adjtime64
__adjtimex64
__ntp_gettime64
__ntp_gettimex64

were introduced.

The introduced struct __timex64 is a copy of Linux kernel's struct 
__kernel_timex (v5.6) introduced for properly handling data for clock_adjtime64
syscall.
As the struct's __kernel_timex size is the same as for archs with 
__WORDSIZE == 64, proper padding and data types conversion (i.e. long to long
long) had to be added for architectures with __WORDSIZE == 32 && 
__TIMESIZE != 64.

Moreover, the clock_adjtime64 syscall handling in Linux kernel has been broken
up till v5.4.

Lukasz Majewski (10):
  y2038: include: Move struct __timeval64 definition to a separate file
  y2038: Introduce struct __timex64 - new internal glibc type
  y2038: Provide conversion helpers for struct __timex64
  y2038: linux: Provide __clock_adjtime64 implementation
  y2038: linux: Provide ___adjtimex64 implementation
  y2038: linux: Provide __adjtime64 implementation
  y2038: Introduce struct __ntptimeval64 - new internal glibc type
  y2038: Provide conversion helpers for struct __ntptimeval64
  y2038: linux: Provide __ntp_gettime64 implementation
  y2038: linux: Provide __ntp_gettimex64 implementation

 include/struct___timeval64.h                |  17 ++
 include/sys/time.h                          |   9 ++
 include/time.h                              |  15 +-
 sysdeps/unix/sysv/linux/Makefile            |   2 +-
 sysdeps/unix/sysv/linux/adjtime.c           |  26 +++-
 sysdeps/unix/sysv/linux/adjtimex.c          |  21 ++-
 sysdeps/unix/sysv/linux/clock_adjtime.c     |  64 ++++++++
 sysdeps/unix/sysv/linux/include/sys/timex.h | 162 ++++++++++++++++++++
 sysdeps/unix/sysv/linux/ntp_gettime.c       |  24 ++-
 sysdeps/unix/sysv/linux/ntp_gettimex.c      |  24 ++-
 sysdeps/unix/sysv/linux/syscalls.list       |   1 -
 11 files changed, 337 insertions(+), 28 deletions(-)
 create mode 100644 include/struct___timeval64.h
 create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c

-- 
2.20.1


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

* [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 15:18   ` Alistair Francis
  2020-04-28 14:24   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type Lukasz Majewski
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

The struct __timeval64's definition has been moved from ./include/time.h to
./include/struct___timeval64.h.

This change would prevent from polluting other glibc namespaces (when
headers are modified to support 64 bit time on architectures with
__WORDSIZE==32).

Now it is possible to just include definition of this particular structure
when needed.
---
 include/struct___timeval64.h | 17 +++++++++++++++++
 include/time.h               | 15 +--------------
 2 files changed, 18 insertions(+), 14 deletions(-)
 create mode 100644 include/struct___timeval64.h

diff --git a/include/struct___timeval64.h b/include/struct___timeval64.h
new file mode 100644
index 0000000000..05cf2f26fc
--- /dev/null
+++ b/include/struct___timeval64.h
@@ -0,0 +1,17 @@
+#ifndef _STRUCT_TIMEVAL64_H
+#define _STRUCT_TIMEVAL64_H
+
+#if __TIMESIZE == 64
+# define __timeval64 timeval
+#else
+/* The glibc Y2038-proof struct __timeval64 structure for a time value.
+   This structure is NOT supposed to be passed to the Linux kernel.
+   Instead, it shall be converted to struct __timespec64 and time shall
+   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
+struct __timeval64
+{
+  __time64_t tv_sec;         /* Seconds */
+  __suseconds64_t tv_usec;       /* Microseconds */
+};
+#endif
+#endif /* _STRUCT_TIMEVAL64_H  */
diff --git a/include/time.h b/include/time.h
index 1c103a4cb2..fe4da9ca10 100644
--- a/include/time.h
+++ b/include/time.h
@@ -4,6 +4,7 @@
 #ifndef _ISOMAC
 # include <bits/types/struct_timeval.h>
 # include <struct___timespec64.h>
+# include <struct___timeval64.h>
 # include <bits/types/locale_t.h>
 # include <stdbool.h>
 # include <time/mktime-internal.h>
@@ -73,20 +74,6 @@ struct __itimerspec64
 };
 #endif
 
-#if __TIMESIZE == 64
-# define __timeval64 timeval
-#else
-/* The glibc Y2038-proof struct __timeval64 structure for a time value.
-   This structure is NOT supposed to be passed to the Linux kernel.
-   Instead, it shall be converted to struct __timespec64 and time shall
-   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
-struct __timeval64
-{
-  __time64_t tv_sec;         /* Seconds */
-  __suseconds64_t tv_usec;       /* Microseconds */
-};
-#endif
-
 #if __TIMESIZE == 64
 # define __utimbuf64 utimbuf
 # define __itimerval64 itimerval
-- 
2.20.1


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

* [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 15:22   ` Alistair Francis
  2020-04-28 14:34   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64 Lukasz Majewski
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's
struct __kernel_timex (v5.6) introduced for properly handling data for
clock_adjtime64 syscall.
As the struct's __kernel_timex size is the same as for archs with
__WORDSIZE == 64, proper padding and data types conversion (i.e. long to long
long) had to be added for architectures with __WORDSIZE == 32 &&
__TIMESIZE != 64.

Moreover, it stores time in struct __timeval64 rather than struct
timeval, which makes it Y2038-proof.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index 319d566608..f25081639b 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -25,5 +25,43 @@
 
 libc_hidden_proto (__adjtimex)
 
+#  include <struct___timeval64.h>
+/* Local definition of 64 bit time supporting timex struct */
+#  if __TIMESIZE == 64
+#   define __timex64 timex
+#  else
+
+struct __timex64
+{
+  unsigned int modes;          /* mode selector */
+  int :32;                     /* pad */
+  long long offset;            /* time offset (usec) */
+  long long freq;              /* frequency offset (scaled ppm) */
+  long long maxerror;          /* maximum error (usec) */
+  long long esterror;          /* estimated error (usec) */
+  int status;                  /* clock command/status */
+  int :32;                     /* pad */
+  long long constant;          /* pll time constant */
+  long long precision;         /* clock precision (usec) (read only) */
+  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */
+  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */
+  long long tick;              /* (modified) usecs between clock ticks */
+  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
+  long long jitter;            /* pps jitter (us) (ro) */
+  int shift;                   /* interval duration (s) (shift) (ro) */
+  int :32;                     /* pad */
+  long long stabil;            /* pps stability (scaled ppm) (ro) */
+  long long jitcnt;            /* jitter limit exceeded (ro) */
+  long long calcnt;            /* calibration intervals (ro) */
+  long long errcnt;            /* calibration errors (ro) */
+  long long stbcnt;            /* stability limit exceeded (ro) */
+
+  int tai;                     /* TAI offset (ro) */
+
+  int  :32; int  :32; int  :32; int  :32;
+  int  :32; int  :32; int  :32; int  :32;
+  int  :32; int  :32; int  :32;
+};
+#  endif
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */
-- 
2.20.1


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

* [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 15:22   ` Alistair Francis
  2020-04-28 15:56   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

Those functions allow easy conversion between Y2038 safe, glibc internal
struct __timex64 and struct timex.

Those functions are put in Linux specific sys/timex.h file, as putting
them into glibc's local include/time.h would cause build break on HURD as
it doesn't support struct timex related syscalls.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index f25081639b..bab6b28920 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -25,6 +25,7 @@
 
 libc_hidden_proto (__adjtimex)
 
+#  include <time.h>
 #  include <struct___timeval64.h>
 /* Local definition of 64 bit time supporting timex struct */
 #  if __TIMESIZE == 64
@@ -63,5 +64,65 @@ struct __timex64
   int  :32; int  :32; int  :32;
 };
 #  endif
+
+/* Convert a known valid struct timex into a struct __timex64.  */
+static inline struct __timex64
+valid_timex_to_timex64 (const struct timex tx)
+{
+  struct __timex64 tx64;
+
+  tx64.modes = tx.modes;
+  tx64.offset = tx.offset;
+  tx64.freq = tx.freq;
+  tx64.maxerror = tx.maxerror;
+  tx64.esterror = tx.esterror;
+  tx64.status = tx.status;
+  tx64.constant = tx.constant;
+  tx64.precision = tx.precision;
+  tx64.tolerance = tx.tolerance;
+  tx64.time = valid_timeval_to_timeval64 (tx.time);
+  tx64.tick = tx.tick;
+  tx64.ppsfreq = tx.ppsfreq;
+  tx64.jitter = tx.jitter;
+  tx64.shift = tx.shift;
+  tx64.stabil = tx.stabil;
+  tx64.jitcnt = tx.jitcnt;
+  tx64.calcnt = tx.calcnt;
+  tx64.errcnt = tx.errcnt;
+  tx64.stbcnt = tx.stbcnt;
+  tx64.tai = tx.tai;
+
+  return tx64;
+}
+
+/* Convert a known valid struct __timex64 into a struct timex.  */
+static inline struct timex
+valid_timex64_to_timex (const struct __timex64 tx64)
+{
+  struct timex tx;
+
+  tx.modes = tx64.modes;
+  tx.offset = tx64.offset;
+  tx.freq = tx64.freq;
+  tx.maxerror = tx64.maxerror;
+  tx.esterror = tx64.esterror;
+  tx.status = tx64.status;
+  tx.constant = tx64.constant;
+  tx.precision = tx64.precision;
+  tx.tolerance = tx64.tolerance;
+  tx.time = valid_timeval64_to_timeval (tx64.time);
+  tx.tick = tx64.tick;
+  tx.ppsfreq = tx64.ppsfreq;
+  tx.jitter = tx64.jitter;
+  tx.shift = tx64.shift;
+  tx.stabil = tx64.stabil;
+  tx.jitcnt = tx64.jitcnt;
+  tx.calcnt = tx64.calcnt;
+  tx.errcnt = tx64.errcnt;
+  tx.stbcnt = tx64.stbcnt;
+  tx.tai = tx64.tai;
+
+  return tx;
+}
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */
-- 
2.20.1


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

* [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (2 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64 Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 22:12   ` Alistair Francis
  2020-04-28 17:00   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch replaces auto generated wrapper (as described in
sysdeps/unix/sysv/linux/syscalls.list) for clock_adjtime with one which adds
extra support for reading 64 bit time values on machines with __TIMESIZE != 64.

To achieve this goal new __clock_adjtime64 explicit 64 bit function for
adjusting Linux clock has been added.
Moreover, a 32 bit version - __clock_adjtime has been refactored to internally
use __clock_adjtime64.

The __clock_adjtime is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversions between 64 bit
struct __timespec64 and struct timespec.

The new __clock_adjtime64 syscall available from Linux 5.1+ has been used, when
applicable.
Up till v5.4 in the Linux kernel there was a bug preventing this call from
obtaining correct struct's timex time.tv_sec time after time_t overflow
(i.e. not being Y2038 safe).

Build tests:
- ./src/scripts/build-many-glibcs.py glibcs

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

Linux kernel, headers and minimal kernel version for glibc build test matrix:
- Linux v5.1 (with clock_adjtime64) 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 clock_adjtime64
  syscall.

- Linux v4.19 (no clock_adjtime64 support) with default minimal kernel version
  for contemporary glibc (3.2.0)
  This kernel doesn't support clock_adjtime64 syscall, so the fallback to
  clock_adjtime 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.
---
 sysdeps/unix/sysv/linux/Makefile            |  2 +-
 sysdeps/unix/sysv/linux/clock_adjtime.c     | 64 +++++++++++++++++++++
 sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +
 sysdeps/unix/sysv/linux/syscalls.list       |  1 -
 4 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 089a4899d5..dfb200eccf 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
 		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
-		   timerfd_gettime timerfd_settime
+		   timerfd_gettime timerfd_settime clock_adjtime
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables
diff --git a/sysdeps/unix/sysv/linux/clock_adjtime.c b/sysdeps/unix/sysv/linux/clock_adjtime.c
new file mode 100644
index 0000000000..cbab6bf345
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/clock_adjtime.c
@@ -0,0 +1,64 @@
+/* clock_adjtime -- tune kernel clock
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If
+   not, see <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include <sys/timex.h>
+#include <kernel-features.h>
+
+int
+__clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
+{
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_adjtime64
+#  define __NR_clock_adjtime64 __NR_clock_adjtime
+# endif
+	return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
+#else
+  int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
+  if ((ret >= TIME_OK && ret <= TIME_ERROR) || errno != ENOSYS)
+    return ret;
+
+  struct timex tx32 = valid_timex64_to_timex (*tx64);
+  int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32);
+  *tx64 = valid_timex_to_timex64 (tx32);
+
+  return retval;
+#endif
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__clock_adjtime64)
+
+int
+__clock_adjtime (const clockid_t clock_id, struct timex *tx)
+{
+	struct __timex64 tx64;
+  int retval;
+
+  tx64 = valid_timex_to_timex64 (*tx);
+  retval = __clock_adjtime64 (clock_id, &tx64);
+  *tx = valid_timex64_to_timex (tx64);
+
+  return retval;
+}
+#endif
+libc_hidden_def (__clock_adjtime);
+strong_alias (__clock_adjtime, clock_adjtime)
diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index bab6b28920..f1bb364db4 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -30,6 +30,7 @@ libc_hidden_proto (__adjtimex)
 /* Local definition of 64 bit time supporting timex struct */
 #  if __TIMESIZE == 64
 #   define __timex64 timex
+#   define __clock_adjtime64 __clock_adjtime
 #  else
 
 struct __timex64
@@ -63,6 +64,8 @@ struct __timex64
   int  :32; int  :32; int  :32; int  :32;
   int  :32; int  :32; int  :32;
 };
+extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
+libc_hidden_proto (__clock_adjtime64);
 #  endif
 
 /* Convert a known valid struct timex into a struct __timex64.  */
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index e40f993495..d7d73e8fcb 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -4,7 +4,6 @@ alarm		-	alarm		i:i	alarm
 bdflush		EXTRA	bdflush		i:ii	__compat_bdflush	bdflush@GLIBC_2.0:GLIBC_2.23
 capget		EXTRA	capget		i:pp	capget
 capset		EXTRA	capset		i:pp	capset
-clock_adjtime	EXTRA	clock_adjtime	i:ip	__clock_adjtime		clock_adjtime
 create_module	EXTRA	create_module	3	__compat_create_module	create_module@GLIBC_2.0:GLIBC_2.23
 delete_module	EXTRA	delete_module	3	delete_module
 epoll_create	EXTRA	epoll_create	i:i	epoll_create
-- 
2.20.1


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

* [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (3 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 22:12   ` Alistair Francis
  2020-04-28 17:14   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch provides new ___adjtimex64 explicit 64 bit function for adjusting
Linux kernel clock.

Internally, the __clock_adjtime64 syscall is used. This patch is necessary
for having architectures with __WORDSIZE == 32 Y2038 safe.

Moreover, a 32 bit version - ___adjtimex has been refactored to internally
use ___adjtimex64.

The ___adjtimex is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
timex and 64 bit struct __timex64.

Last but not least, in ___adjtimex64 function the __clock_adjtime syscall has
been replaced with __clock_adjtime64 to support 64 bit time on architectures
with __WORDSIZE == 32 and __TIMESIZE != 64.

Build tests:
./src/scripts/build-many-glibcs.py glibcs

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

Above tests were performed with Y2038 redirection applied as well as without to
test the proper usage of both ___adjtimex64 and ___adjtimex.
---
 sysdeps/unix/sysv/linux/adjtimex.c          | 21 +++++++++++++++++++--
 sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/adjtimex.c b/sysdeps/unix/sysv/linux/adjtimex.c
index ebc17476a7..683cc65696 100644
--- a/sysdeps/unix/sysv/linux/adjtimex.c
+++ b/sysdeps/unix/sysv/linux/adjtimex.c
@@ -20,11 +20,28 @@
 #include <sysdep.h>
 
 int
-___adjtimex (struct timex *buf)
+___adjtimex64 (struct __timex64 *tx64)
 {
-  return __clock_adjtime (CLOCK_REALTIME, buf);
+  return __clock_adjtime64 (CLOCK_REALTIME, tx64);
 }
 
+#if __TIMESIZE != 64
+libc_hidden_def (___adjtimex64)
+
+int
+___adjtimex (struct timex *tx)
+{
+  struct __timex64 tx64;
+  int retval;
+
+  tx64 = valid_timex_to_timex64 (*tx);
+  retval = ___adjtimex64 (&tx64);
+  *tx = valid_timex64_to_timex (tx64);
+
+  return retval;
+}
+#endif
+
 #ifdef VERSION_adjtimex
 weak_alias (___adjtimex, __wadjtimex);
 weak_alias (___adjtimex, __wnadjtime);
diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index f1bb364db4..fdfffe2f3a 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -31,6 +31,7 @@ libc_hidden_proto (__adjtimex)
 #  if __TIMESIZE == 64
 #   define __timex64 timex
 #   define __clock_adjtime64 __clock_adjtime
+#   define ___adjtimex64 ___adjtimex
 #  else
 
 struct __timex64
@@ -66,6 +67,8 @@ struct __timex64
 };
 extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
 libc_hidden_proto (__clock_adjtime64);
+extern int ___adjtimex64 (struct __timex64 *tx64);
+libc_hidden_proto (___adjtimex64)
 #  endif
 
 /* Convert a known valid struct timex into a struct __timex64.  */
-- 
2.20.1


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

* [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (4 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-27 22:14   ` Alistair Francis
  2020-04-28 18:33   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type Lukasz Majewski
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch provides new __adjtime64 explicit 64 bit function for adjusting
Linux kernel clock.

Internally, the __clock_adjtime64 syscall is used instead of __adjtimex. This
patch is necessary for having architectures with __WORDSIZE == 32 Y2038 safe.

Moreover, a 32 bit version - __adjtime has been refactored to internally use
__adjtime64.

The __adjtime is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
timeval and 64 bit struct __timeval64.


Build tests:
./src/scripts/build-many-glibcs.py glibcs

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

Above tests were performed with Y2038 redirection applied as well as without to
test the proper usage of both __adjtime64 and __adjtime.
---
 include/sys/time.h                |  9 +++++++++
 sysdeps/unix/sysv/linux/adjtime.c | 26 ++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/include/sys/time.h b/include/sys/time.h
index 8153d75033..567e4b7562 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -26,6 +26,15 @@ extern int __settimezone (const struct timezone *__tz)
 	attribute_hidden;
 extern int __adjtime (const struct timeval *__delta,
 		      struct timeval *__olddelta);
+
+#  include <struct___timeval64.h>
+#  if __TIMESIZE == 64
+#   define __adjtime64 __adjtime
+#  else
+extern int __adjtime64 (const struct __timeval64 *itv,
+                        struct __timeval64 *otv);
+libc_hidden_proto (__adjtime64)
+#  endif
 extern int __getitimer (enum __itimer_which __which,
 			struct itimerval *__value);
 extern int __setitimer (enum __itimer_which __which,
diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
index c142f4f6ea..f7ec24b43a 100644
--- a/sysdeps/unix/sysv/linux/adjtime.c
+++ b/sysdeps/unix/sysv/linux/adjtime.c
@@ -24,13 +24,13 @@
 #define MIN_SEC	(INT_MIN / 1000000L + 2)
 
 int
-__adjtime (const struct timeval *itv, struct timeval *otv)
+__adjtime64 (const struct __timeval64 *itv, struct __timeval64 *otv)
 {
-  struct timex tntx;
+  struct __timex64 tntx;
 
   if (itv)
     {
-      struct timeval tmp;
+      struct __timeval64 tmp;
 
       /* We will do some check here. */
       tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
@@ -43,7 +43,7 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
   else
     tntx.modes = ADJ_OFFSET_SS_READ;
 
-  if (__glibc_unlikely (__adjtimex (&tntx) < 0))
+  if (__glibc_unlikely (__clock_adjtime64 (CLOCK_REALTIME, &tntx) < 0))
     return -1;
 
   if (otv)
@@ -62,6 +62,24 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
   return 0;
 }
 
+#if __TIMESIZE != 64
+libc_hidden_def (__adjtime64)
+
+int
+__adjtime (const struct timeval *itv, struct timeval *otv)
+{
+  struct __timeval64 itv64, otv64;
+  int retval;
+
+  itv64 = valid_timeval_to_timeval64 (*itv);
+  retval = __adjtime64 (&itv64, otv != NULL ? &otv64 : NULL);
+  if (otv != NULL)
+	  *otv = valid_timeval64_to_timeval (otv64);
+
+  return retval;
+}
+#endif
+
 #ifdef VERSION_adjtime
 weak_alias (__adjtime, __wadjtime);
 default_symbol_version (__wadjtime, adjtime, VERSION_adjtime);
-- 
2.20.1


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

* [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (5 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-28 18:41   ` Adhemerval Zanella
  2020-04-26 13:31 ` [PATCH 08/10] y2038: Provide conversion helpers for struct __ntptimeval64 Lukasz Majewski
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This type is a glibc's "internal" type to get time parameters data from
Linux kernel (NTP daemon interface). It stores time in struct __timeval64
rather than struct timeval, which makes it Y2038-proof.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index fdfffe2f3a..73c9addb3e 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -32,6 +32,7 @@ libc_hidden_proto (__adjtimex)
 #   define __timex64 timex
 #   define __clock_adjtime64 __clock_adjtime
 #   define ___adjtimex64 ___adjtimex
+#   define __ntptimeval64 ntptimeval
 #  else
 
 struct __timex64
@@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
 libc_hidden_proto (__clock_adjtime64);
 extern int ___adjtimex64 (struct __timex64 *tx64);
 libc_hidden_proto (___adjtimex64)
+
+struct __ntptimeval64
+{
+  struct __timeval64 time;	/* current time (ro) */
+  long int maxerror;	/* maximum error (us) (ro) */
+  long int esterror;	/* estimated error (us) (ro) */
+  long int tai;		/* TAI offset (ro) */
+
+  long int __glibc_reserved1;
+  long int __glibc_reserved2;
+  long int __glibc_reserved3;
+  long int __glibc_reserved4;
+};
 #  endif
 
 /* Convert a known valid struct timex into a struct __timex64.  */
-- 
2.20.1


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

* [PATCH 08/10] y2038: Provide conversion helpers for struct __ntptimeval64
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (6 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 09/10] y2038: linux: Provide __ntp_gettime64 implementation Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 10/10] y2038: linux: Provide __ntp_gettimex64 implementation Lukasz Majewski
  9 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

Those functions allow easy conversion between Y2038 safe, glibc internal
struct __ntptimeval64 and struct ntptimeval.

The reserved fields (i.e. __glibc_reserved{1234}) during conversion are
zeroed as well, to provide behavior similar to one in ntp_gettimex function
(where those are cleared before the struct ntptimeval is returned).

Those functions are put in Linux specific sys/timex.h file, as putting
them into glibc's local include/time.h would cause build break on HURD as
it doesn't support struct timex related syscalls.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 36 +++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index 73c9addb3e..5743fb2fc8 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -144,5 +144,41 @@ valid_timex64_to_timex (const struct __timex64 tx64)
 
   return tx;
 }
+
+/* Convert a known valid struct ntptimeval into a struct __ntptimeval64.  */
+static inline struct __ntptimeval64
+valid_ntptimeval_to_ntptimeval64 (const struct ntptimeval ntv)
+{
+  struct __ntptimeval64 ntv64;
+
+  ntv64.time = valid_timeval_to_timeval64 (ntv.time);
+  ntv64.maxerror = ntv.maxerror;
+  ntv64.esterror = ntv.esterror;
+  ntv64.tai = ntv.tai;
+  ntv64.__glibc_reserved1 = 0;
+  ntv64.__glibc_reserved2 = 0;
+  ntv64.__glibc_reserved3 = 0;
+  ntv64.__glibc_reserved4 = 0;
+
+  return ntv64;
+}
+
+/* Convert a known valid struct __ntptimeval64 into a struct ntptimeval.  */
+static inline struct ntptimeval
+valid_ntptimeval64_to_ntptimeval (const struct __ntptimeval64 ntp64)
+{
+  struct ntptimeval ntp;
+
+  ntp.time = valid_timeval64_to_timeval (ntp64.time);
+  ntp.maxerror = ntp64.maxerror;
+  ntp.esterror = ntp64.esterror;
+  ntp.tai = ntp64.tai;
+  ntp.__glibc_reserved1 = 0;
+  ntp.__glibc_reserved2 = 0;
+  ntp.__glibc_reserved3 = 0;
+  ntp.__glibc_reserved4 = 0;
+
+  return ntp;
+}
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */
-- 
2.20.1


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

* [PATCH 09/10] y2038: linux: Provide __ntp_gettime64 implementation
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (7 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 08/10] y2038: Provide conversion helpers for struct __ntptimeval64 Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  2020-04-26 13:31 ` [PATCH 10/10] y2038: linux: Provide __ntp_gettimex64 implementation Lukasz Majewski
  9 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch provides new __ntp_gettime64 explicit 64 bit function for getting
time parameters via NTP interface.

Internally, the __clock_adjtime64 syscall is used instead of __adjtimex. This
patch is necessary for having architectures with __WORDSIZE == 32 Y2038 safe.

Moreover, a 32 bit version - __ntp_gettime has been refactored to internally
use __ntp_gettime64.

The __ntp_gettime is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
ntptimeval and 64 bit struct __ntptimeval64.

Build tests:
./src/scripts/build-many-glibcs.py glibcs

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

Above tests were performed with Y2038 redirection applied as well as without to
test the proper usage of both __ntp_gettime64 and __ntp_gettime.
---
 sysdeps/unix/sysv/linux/include/sys/timex.h |  4 ++++
 sysdeps/unix/sysv/linux/ntp_gettime.c       | 24 ++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index 5743fb2fc8..a00ce7138f 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -33,6 +33,7 @@ libc_hidden_proto (__adjtimex)
 #   define __clock_adjtime64 __clock_adjtime
 #   define ___adjtimex64 ___adjtimex
 #   define __ntptimeval64 ntptimeval
+#   define __ntp_gettime64 __ntp_gettime
 #  else
 
 struct __timex64
@@ -83,6 +84,9 @@ struct __ntptimeval64
   long int __glibc_reserved3;
   long int __glibc_reserved4;
 };
+extern int __ntp_gettime64 (struct __ntptimeval64 *ntv);
+libc_hidden_proto (__ntp_gettime64)
+
 #  endif
 
 /* Convert a known valid struct timex into a struct __timex64.  */
diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c b/sysdeps/unix/sysv/linux/ntp_gettime.c
index c8d6a197dc..21aeffadeb 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettime.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
@@ -17,6 +17,7 @@
 
 #define ntp_gettime ntp_gettime_redirect
 
+#include <time.h>
 #include <sys/timex.h>
 
 #undef ntp_gettime
@@ -27,15 +28,32 @@
 
 
 int
-ntp_gettime (struct ntptimeval *ntv)
+__ntp_gettime64 (struct __ntptimeval64 *ntv)
 {
-  struct timex tntx;
+  struct __timex64 tntx;
   int result;
 
   tntx.modes = 0;
-  result = __adjtimex (&tntx);
+  result = __clock_adjtime64 (CLOCK_REALTIME, &tntx);
   ntv->time = tntx.time;
   ntv->maxerror = tntx.maxerror;
   ntv->esterror = tntx.esterror;
   return result;
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__ntp_gettime64)
+
+int
+__ntp_gettime (struct ntptimeval *ntv)
+{
+  struct __ntptimeval64 ntv64;
+  int result;
+
+  result = __ntp_gettime64 (&ntv64);
+  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
+
+  return result;
+}
+#endif
+strong_alias (__ntp_gettime, ntp_gettime)
-- 
2.20.1


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

* [PATCH 10/10] y2038: linux: Provide __ntp_gettimex64 implementation
  2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
                   ` (8 preceding siblings ...)
  2020-04-26 13:31 ` [PATCH 09/10] y2038: linux: Provide __ntp_gettime64 implementation Lukasz Majewski
@ 2020-04-26 13:31 ` Lukasz Majewski
  9 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-26 13:31 UTC (permalink / raw)
  To: Joseph Myers, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab, Lukasz Majewski

This patch provides new __ntp_gettimex64 explicit 64 bit function for getting
time parameters via NTP interface.

The call to __adjtimex in __ntp_gettime64 function has been replaced with
direct call to __clock_adjtime64 syscall, to simplify the code.

Moreover, a 32 bit version - __ntp_gettimex has been refactored to internally
use __ntp_gettimex64.

The __ntp_gettimex is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
ntptimeval and 64 bit struct __ntptimeval64.

Build tests:
./src/scripts/build-many-glibcs.py glibcs

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

Above tests were performed with Y2038 redirection applied as well as without to
test the proper usage of both __ntp_gettimex64 and __ntp_gettimex.
---
 sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +++
 sysdeps/unix/sysv/linux/ntp_gettimex.c      | 24 ++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index a00ce7138f..2e4ed6053c 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -34,6 +34,7 @@ libc_hidden_proto (__adjtimex)
 #   define ___adjtimex64 ___adjtimex
 #   define __ntptimeval64 ntptimeval
 #   define __ntp_gettime64 __ntp_gettime
+#   define __ntp_gettimex64 __ntp_gettimex
 #  else
 
 struct __timex64
@@ -86,6 +87,8 @@ struct __ntptimeval64
 };
 extern int __ntp_gettime64 (struct __ntptimeval64 *ntv);
 libc_hidden_proto (__ntp_gettime64)
+extern int __ntp_gettimex64 (struct __ntptimeval64 *ntv);
+libc_hidden_proto (__ntp_gettimex64)
 
 #  endif
 
diff --git a/sysdeps/unix/sysv/linux/ntp_gettimex.c b/sysdeps/unix/sysv/linux/ntp_gettimex.c
index 0f26d4806e..7d0328c6ca 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettimex.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettimex.c
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <time.h>
 #include <sys/timex.h>
 
 #ifndef MOD_OFFSET
@@ -23,13 +24,13 @@
 
 
 int
-ntp_gettimex (struct ntptimeval *ntv)
+__ntp_gettimex64 (struct __ntptimeval64 *ntv)
 {
-  struct timex tntx;
+  struct __timex64 tntx;
   int result;
 
   tntx.modes = 0;
-  result = __adjtimex (&tntx);
+  result = __clock_adjtime64 (CLOCK_REALTIME, &tntx);
   ntv->time = tntx.time;
   ntv->maxerror = tntx.maxerror;
   ntv->esterror = tntx.esterror;
@@ -40,3 +41,20 @@ ntp_gettimex (struct ntptimeval *ntv)
   ntv->__glibc_reserved4 = 0;
   return result;
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__ntp_gettimex64)
+
+int
+__ntp_gettimex (struct ntptimeval *ntv)
+{
+  struct __ntptimeval64 ntv64;
+  int result;
+
+  result = __ntp_gettimex64 (&ntv64);
+  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
+
+  return result;
+}
+#endif
+strong_alias (__ntp_gettimex, ntp_gettimex)
-- 
2.20.1


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

* Re: [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file
  2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
@ 2020-04-27 15:18   ` Alistair Francis
  2020-04-28 14:24   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 15:18 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> The struct __timeval64's definition has been moved from ./include/time.h to
> ./include/struct___timeval64.h.
>
> This change would prevent from polluting other glibc namespaces (when
> headers are modified to support 64 bit time on architectures with
> __WORDSIZE==32).
>
> Now it is possible to just include definition of this particular structure
> when needed.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  include/struct___timeval64.h | 17 +++++++++++++++++
>  include/time.h               | 15 +--------------
>  2 files changed, 18 insertions(+), 14 deletions(-)
>  create mode 100644 include/struct___timeval64.h
>
> diff --git a/include/struct___timeval64.h b/include/struct___timeval64.h
> new file mode 100644
> index 0000000000..05cf2f26fc
> --- /dev/null
> +++ b/include/struct___timeval64.h
> @@ -0,0 +1,17 @@
> +#ifndef _STRUCT_TIMEVAL64_H
> +#define _STRUCT_TIMEVAL64_H
> +
> +#if __TIMESIZE == 64
> +# define __timeval64 timeval
> +#else
> +/* The glibc Y2038-proof struct __timeval64 structure for a time value.
> +   This structure is NOT supposed to be passed to the Linux kernel.
> +   Instead, it shall be converted to struct __timespec64 and time shall
> +   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
> +struct __timeval64
> +{
> +  __time64_t tv_sec;         /* Seconds */
> +  __suseconds64_t tv_usec;       /* Microseconds */
> +};
> +#endif
> +#endif /* _STRUCT_TIMEVAL64_H  */
> diff --git a/include/time.h b/include/time.h
> index 1c103a4cb2..fe4da9ca10 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -4,6 +4,7 @@
>  #ifndef _ISOMAC
>  # include <bits/types/struct_timeval.h>
>  # include <struct___timespec64.h>
> +# include <struct___timeval64.h>
>  # include <bits/types/locale_t.h>
>  # include <stdbool.h>
>  # include <time/mktime-internal.h>
> @@ -73,20 +74,6 @@ struct __itimerspec64
>  };
>  #endif
>
> -#if __TIMESIZE == 64
> -# define __timeval64 timeval
> -#else
> -/* The glibc Y2038-proof struct __timeval64 structure for a time value.
> -   This structure is NOT supposed to be passed to the Linux kernel.
> -   Instead, it shall be converted to struct __timespec64 and time shall
> -   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
> -struct __timeval64
> -{
> -  __time64_t tv_sec;         /* Seconds */
> -  __suseconds64_t tv_usec;       /* Microseconds */
> -};
> -#endif
> -
>  #if __TIMESIZE == 64
>  # define __utimbuf64 utimbuf
>  # define __itimerval64 itimerval
> --
> 2.20.1
>

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

* Re: [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type
  2020-04-26 13:31 ` [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type Lukasz Majewski
@ 2020-04-27 15:22   ` Alistair Francis
  2020-04-28 14:34   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 15:22 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's
> struct __kernel_timex (v5.6) introduced for properly handling data for
> clock_adjtime64 syscall.
> As the struct's __kernel_timex size is the same as for archs with
> __WORDSIZE == 64, proper padding and data types conversion (i.e. long to long
> long) had to be added for architectures with __WORDSIZE == 32 &&
> __TIMESIZE != 64.
>
> Moreover, it stores time in struct __timeval64 rather than struct
> timeval, which makes it Y2038-proof.
>
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index 319d566608..f25081639b 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -25,5 +25,43 @@
>
>  libc_hidden_proto (__adjtimex)
>
> +#  include <struct___timeval64.h>
> +/* Local definition of 64 bit time supporting timex struct */
> +#  if __TIMESIZE == 64
> +#   define __timex64 timex
> +#  else
> +
> +struct __timex64
> +{
> +  unsigned int modes;          /* mode selector */
> +  int :32;                     /* pad */
> +  long long offset;            /* time offset (usec) */
> +  long long freq;              /* frequency offset (scaled ppm) */
> +  long long maxerror;          /* maximum error (usec) */
> +  long long esterror;          /* estimated error (usec) */
> +  int status;                  /* clock command/status */
> +  int :32;                     /* pad */
> +  long long constant;          /* pll time constant */
> +  long long precision;         /* clock precision (usec) (read only) */
> +  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */
> +  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */
> +  long long tick;              /* (modified) usecs between clock ticks */
> +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
> +  long long jitter;            /* pps jitter (us) (ro) */
> +  int shift;                   /* interval duration (s) (shift) (ro) */
> +  int :32;                     /* pad */
> +  long long stabil;            /* pps stability (scaled ppm) (ro) */
> +  long long jitcnt;            /* jitter limit exceeded (ro) */
> +  long long calcnt;            /* calibration intervals (ro) */
> +  long long errcnt;            /* calibration errors (ro) */
> +  long long stbcnt;            /* stability limit exceeded (ro) */
> +
> +  int tai;                     /* TAI offset (ro) */
> +
> +  int  :32; int  :32; int  :32; int  :32;
> +  int  :32; int  :32; int  :32; int  :32;
> +  int  :32; int  :32; int  :32;
> +};
> +#  endif
>  # endif /* _ISOMAC */
>  #endif /* sys/timex.h */
> --
> 2.20.1
>

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

* Re: [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64
  2020-04-26 13:31 ` [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64 Lukasz Majewski
@ 2020-04-27 15:22   ` Alistair Francis
  2020-04-28 15:56   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 15:22 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> Those functions allow easy conversion between Y2038 safe, glibc internal
> struct __timex64 and struct timex.
>
> Those functions are put in Linux specific sys/timex.h file, as putting
> them into glibc's local include/time.h would cause build break on HURD as
> it doesn't support struct timex related syscalls.
>
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++
>  1 file changed, 61 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index f25081639b..bab6b28920 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -25,6 +25,7 @@
>
>  libc_hidden_proto (__adjtimex)
>
> +#  include <time.h>
>  #  include <struct___timeval64.h>
>  /* Local definition of 64 bit time supporting timex struct */
>  #  if __TIMESIZE == 64
> @@ -63,5 +64,65 @@ struct __timex64
>    int  :32; int  :32; int  :32;
>  };
>  #  endif
> +
> +/* Convert a known valid struct timex into a struct __timex64.  */
> +static inline struct __timex64
> +valid_timex_to_timex64 (const struct timex tx)
> +{
> +  struct __timex64 tx64;
> +
> +  tx64.modes = tx.modes;
> +  tx64.offset = tx.offset;
> +  tx64.freq = tx.freq;
> +  tx64.maxerror = tx.maxerror;
> +  tx64.esterror = tx.esterror;
> +  tx64.status = tx.status;
> +  tx64.constant = tx.constant;
> +  tx64.precision = tx.precision;
> +  tx64.tolerance = tx.tolerance;
> +  tx64.time = valid_timeval_to_timeval64 (tx.time);
> +  tx64.tick = tx.tick;
> +  tx64.ppsfreq = tx.ppsfreq;
> +  tx64.jitter = tx.jitter;
> +  tx64.shift = tx.shift;
> +  tx64.stabil = tx.stabil;
> +  tx64.jitcnt = tx.jitcnt;
> +  tx64.calcnt = tx.calcnt;
> +  tx64.errcnt = tx.errcnt;
> +  tx64.stbcnt = tx.stbcnt;
> +  tx64.tai = tx.tai;
> +
> +  return tx64;
> +}
> +
> +/* Convert a known valid struct __timex64 into a struct timex.  */
> +static inline struct timex
> +valid_timex64_to_timex (const struct __timex64 tx64)
> +{
> +  struct timex tx;
> +
> +  tx.modes = tx64.modes;
> +  tx.offset = tx64.offset;
> +  tx.freq = tx64.freq;
> +  tx.maxerror = tx64.maxerror;
> +  tx.esterror = tx64.esterror;
> +  tx.status = tx64.status;
> +  tx.constant = tx64.constant;
> +  tx.precision = tx64.precision;
> +  tx.tolerance = tx64.tolerance;
> +  tx.time = valid_timeval64_to_timeval (tx64.time);
> +  tx.tick = tx64.tick;
> +  tx.ppsfreq = tx64.ppsfreq;
> +  tx.jitter = tx64.jitter;
> +  tx.shift = tx64.shift;
> +  tx.stabil = tx64.stabil;
> +  tx.jitcnt = tx64.jitcnt;
> +  tx.calcnt = tx64.calcnt;
> +  tx.errcnt = tx64.errcnt;
> +  tx.stbcnt = tx64.stbcnt;
> +  tx.tai = tx64.tai;
> +
> +  return tx;
> +}
>  # endif /* _ISOMAC */
>  #endif /* sys/timex.h */
> --
> 2.20.1
>

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

* Re: [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation
  2020-04-26 13:31 ` [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
@ 2020-04-27 22:12   ` Alistair Francis
  2020-04-28 17:00   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 22:12 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> This patch replaces auto generated wrapper (as described in
> sysdeps/unix/sysv/linux/syscalls.list) for clock_adjtime with one which adds
> extra support for reading 64 bit time values on machines with __TIMESIZE != 64.
>
> To achieve this goal new __clock_adjtime64 explicit 64 bit function for
> adjusting Linux clock has been added.
> Moreover, a 32 bit version - __clock_adjtime has been refactored to internally
> use __clock_adjtime64.
>
> The __clock_adjtime is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between 64 bit
> struct __timespec64 and struct timespec.
>
> The new __clock_adjtime64 syscall available from Linux 5.1+ has been used, when
> applicable.
> Up till v5.4 in the Linux kernel there was a bug preventing this call from
> obtaining correct struct's timex time.tv_sec time after time_t overflow
> (i.e. not being Y2038 safe).
>
> Build tests:
> - ./src/scripts/build-many-glibcs.py glibcs
>
> 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
>
> Linux kernel, headers and minimal kernel version for glibc build test matrix:
> - Linux v5.1 (with clock_adjtime64) 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 clock_adjtime64
>   syscall.
>
> - Linux v4.19 (no clock_adjtime64 support) with default minimal kernel version
>   for contemporary glibc (3.2.0)
>   This kernel doesn't support clock_adjtime64 syscall, so the fallback to
>   clock_adjtime 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.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  sysdeps/unix/sysv/linux/Makefile            |  2 +-
>  sysdeps/unix/sysv/linux/clock_adjtime.c     | 64 +++++++++++++++++++++
>  sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +
>  sysdeps/unix/sysv/linux/syscalls.list       |  1 -
>  4 files changed, 68 insertions(+), 2 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c
>
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 089a4899d5..dfb200eccf 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
>                    eventfd eventfd_read eventfd_write prlimit \
>                    personality epoll_wait tee vmsplice splice \
>                    open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
> -                  timerfd_gettime timerfd_settime
> +                  timerfd_gettime timerfd_settime clock_adjtime
>
>  CFLAGS-gethostid.c = -fexceptions
>  CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables
> diff --git a/sysdeps/unix/sysv/linux/clock_adjtime.c b/sysdeps/unix/sysv/linux/clock_adjtime.c
> new file mode 100644
> index 0000000000..cbab6bf345
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/clock_adjtime.c
> @@ -0,0 +1,64 @@
> +/* clock_adjtime -- tune kernel clock
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public License as
> +   published by the Free Software Foundation; either version 2.1 of the
> +   License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; see the file COPYING.LIB.  If
> +   not, see <https://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <time.h>
> +#include <sysdep.h>
> +#include <sys/timex.h>
> +#include <kernel-features.h>
> +
> +int
> +__clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
> +{
> +#ifdef __ASSUME_TIME64_SYSCALLS
> +# ifndef __NR_clock_adjtime64
> +#  define __NR_clock_adjtime64 __NR_clock_adjtime
> +# endif
> +       return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
> +#else
> +  int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
> +  if ((ret >= TIME_OK && ret <= TIME_ERROR) || errno != ENOSYS)
> +    return ret;
> +
> +  struct timex tx32 = valid_timex64_to_timex (*tx64);
> +  int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32);
> +  *tx64 = valid_timex_to_timex64 (tx32);
> +
> +  return retval;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__clock_adjtime64)
> +
> +int
> +__clock_adjtime (const clockid_t clock_id, struct timex *tx)
> +{
> +       struct __timex64 tx64;
> +  int retval;
> +
> +  tx64 = valid_timex_to_timex64 (*tx);
> +  retval = __clock_adjtime64 (clock_id, &tx64);
> +  *tx = valid_timex64_to_timex (tx64);
> +
> +  return retval;
> +}
> +#endif
> +libc_hidden_def (__clock_adjtime);
> +strong_alias (__clock_adjtime, clock_adjtime)
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index bab6b28920..f1bb364db4 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -30,6 +30,7 @@ libc_hidden_proto (__adjtimex)
>  /* Local definition of 64 bit time supporting timex struct */
>  #  if __TIMESIZE == 64
>  #   define __timex64 timex
> +#   define __clock_adjtime64 __clock_adjtime
>  #  else
>
>  struct __timex64
> @@ -63,6 +64,8 @@ struct __timex64
>    int  :32; int  :32; int  :32; int  :32;
>    int  :32; int  :32; int  :32;
>  };
> +extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
> +libc_hidden_proto (__clock_adjtime64);
>  #  endif
>
>  /* Convert a known valid struct timex into a struct __timex64.  */
> diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> index e40f993495..d7d73e8fcb 100644
> --- a/sysdeps/unix/sysv/linux/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/syscalls.list
> @@ -4,7 +4,6 @@ alarm           -       alarm           i:i     alarm
>  bdflush                EXTRA   bdflush         i:ii    __compat_bdflush        bdflush@GLIBC_2.0:GLIBC_2.23
>  capget         EXTRA   capget          i:pp    capget
>  capset         EXTRA   capset          i:pp    capset
> -clock_adjtime  EXTRA   clock_adjtime   i:ip    __clock_adjtime         clock_adjtime
>  create_module  EXTRA   create_module   3       __compat_create_module  create_module@GLIBC_2.0:GLIBC_2.23
>  delete_module  EXTRA   delete_module   3       delete_module
>  epoll_create   EXTRA   epoll_create    i:i     epoll_create
> --
> 2.20.1
>

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

* Re: [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation
  2020-04-26 13:31 ` [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
@ 2020-04-27 22:12   ` Alistair Francis
  2020-04-28 17:14   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 22:12 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> This patch provides new ___adjtimex64 explicit 64 bit function for adjusting
> Linux kernel clock.
>
> Internally, the __clock_adjtime64 syscall is used. This patch is necessary
> for having architectures with __WORDSIZE == 32 Y2038 safe.
>
> Moreover, a 32 bit version - ___adjtimex has been refactored to internally
> use ___adjtimex64.
>
> The ___adjtimex is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
> timex and 64 bit struct __timex64.
>
> Last but not least, in ___adjtimex64 function the __clock_adjtime syscall has
> been replaced with __clock_adjtime64 to support 64 bit time on architectures
> with __WORDSIZE == 32 and __TIMESIZE != 64.
>
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs
>
> 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
>
> Above tests were performed with Y2038 redirection applied as well as without to
> test the proper usage of both ___adjtimex64 and ___adjtimex.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  sysdeps/unix/sysv/linux/adjtimex.c          | 21 +++++++++++++++++++--
>  sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +++
>  2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/adjtimex.c b/sysdeps/unix/sysv/linux/adjtimex.c
> index ebc17476a7..683cc65696 100644
> --- a/sysdeps/unix/sysv/linux/adjtimex.c
> +++ b/sysdeps/unix/sysv/linux/adjtimex.c
> @@ -20,11 +20,28 @@
>  #include <sysdep.h>
>
>  int
> -___adjtimex (struct timex *buf)
> +___adjtimex64 (struct __timex64 *tx64)
>  {
> -  return __clock_adjtime (CLOCK_REALTIME, buf);
> +  return __clock_adjtime64 (CLOCK_REALTIME, tx64);
>  }
>
> +#if __TIMESIZE != 64
> +libc_hidden_def (___adjtimex64)
> +
> +int
> +___adjtimex (struct timex *tx)
> +{
> +  struct __timex64 tx64;
> +  int retval;
> +
> +  tx64 = valid_timex_to_timex64 (*tx);
> +  retval = ___adjtimex64 (&tx64);
> +  *tx = valid_timex64_to_timex (tx64);
> +
> +  return retval;
> +}
> +#endif
> +
>  #ifdef VERSION_adjtimex
>  weak_alias (___adjtimex, __wadjtimex);
>  weak_alias (___adjtimex, __wnadjtime);
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index f1bb364db4..fdfffe2f3a 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -31,6 +31,7 @@ libc_hidden_proto (__adjtimex)
>  #  if __TIMESIZE == 64
>  #   define __timex64 timex
>  #   define __clock_adjtime64 __clock_adjtime
> +#   define ___adjtimex64 ___adjtimex
>  #  else
>
>  struct __timex64
> @@ -66,6 +67,8 @@ struct __timex64
>  };
>  extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
>  libc_hidden_proto (__clock_adjtime64);
> +extern int ___adjtimex64 (struct __timex64 *tx64);
> +libc_hidden_proto (___adjtimex64)
>  #  endif
>
>  /* Convert a known valid struct timex into a struct __timex64.  */
> --
> 2.20.1
>

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

* Re: [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation
  2020-04-26 13:31 ` [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
@ 2020-04-27 22:14   ` Alistair Francis
  2020-04-28 18:33   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Alistair Francis @ 2020-04-27 22:14 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Florian Weimer, Andreas Schwab

On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> This patch provides new __adjtime64 explicit 64 bit function for adjusting
> Linux kernel clock.
>
> Internally, the __clock_adjtime64 syscall is used instead of __adjtimex. This
> patch is necessary for having architectures with __WORDSIZE == 32 Y2038 safe.
>
> Moreover, a 32 bit version - __adjtime has been refactored to internally use
> __adjtime64.
>
> The __adjtime is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
> timeval and 64 bit struct __timeval64.
>
>
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs
>
> 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
>
> Above tests were performed with Y2038 redirection applied as well as without to
> test the proper usage of both __adjtime64 and __adjtime.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  include/sys/time.h                |  9 +++++++++
>  sysdeps/unix/sysv/linux/adjtime.c | 26 ++++++++++++++++++++++----
>  2 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/include/sys/time.h b/include/sys/time.h
> index 8153d75033..567e4b7562 100644
> --- a/include/sys/time.h
> +++ b/include/sys/time.h
> @@ -26,6 +26,15 @@ extern int __settimezone (const struct timezone *__tz)
>         attribute_hidden;
>  extern int __adjtime (const struct timeval *__delta,
>                       struct timeval *__olddelta);
> +
> +#  include <struct___timeval64.h>
> +#  if __TIMESIZE == 64
> +#   define __adjtime64 __adjtime
> +#  else
> +extern int __adjtime64 (const struct __timeval64 *itv,
> +                        struct __timeval64 *otv);
> +libc_hidden_proto (__adjtime64)
> +#  endif
>  extern int __getitimer (enum __itimer_which __which,
>                         struct itimerval *__value);
>  extern int __setitimer (enum __itimer_which __which,
> diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
> index c142f4f6ea..f7ec24b43a 100644
> --- a/sysdeps/unix/sysv/linux/adjtime.c
> +++ b/sysdeps/unix/sysv/linux/adjtime.c
> @@ -24,13 +24,13 @@
>  #define MIN_SEC        (INT_MIN / 1000000L + 2)
>
>  int
> -__adjtime (const struct timeval *itv, struct timeval *otv)
> +__adjtime64 (const struct __timeval64 *itv, struct __timeval64 *otv)
>  {
> -  struct timex tntx;
> +  struct __timex64 tntx;
>
>    if (itv)
>      {
> -      struct timeval tmp;
> +      struct __timeval64 tmp;
>
>        /* We will do some check here. */
>        tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
> @@ -43,7 +43,7 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
>    else
>      tntx.modes = ADJ_OFFSET_SS_READ;
>
> -  if (__glibc_unlikely (__adjtimex (&tntx) < 0))
> +  if (__glibc_unlikely (__clock_adjtime64 (CLOCK_REALTIME, &tntx) < 0))
>      return -1;
>
>    if (otv)
> @@ -62,6 +62,24 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
>    return 0;
>  }
>
> +#if __TIMESIZE != 64
> +libc_hidden_def (__adjtime64)
> +
> +int
> +__adjtime (const struct timeval *itv, struct timeval *otv)
> +{
> +  struct __timeval64 itv64, otv64;
> +  int retval;
> +
> +  itv64 = valid_timeval_to_timeval64 (*itv);
> +  retval = __adjtime64 (&itv64, otv != NULL ? &otv64 : NULL);
> +  if (otv != NULL)
> +         *otv = valid_timeval64_to_timeval (otv64);
> +
> +  return retval;
> +}
> +#endif
> +
>  #ifdef VERSION_adjtime
>  weak_alias (__adjtime, __wadjtime);
>  default_symbol_version (__wadjtime, adjtime, VERSION_adjtime);
> --
> 2.20.1
>

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

* Re: [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file
  2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
  2020-04-27 15:18   ` Alistair Francis
@ 2020-04-28 14:24   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 14:24 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> The struct __timeval64's definition has been moved from ./include/time.h to
> ./include/struct___timeval64.h.
> 
> This change would prevent from polluting other glibc namespaces (when
> headers are modified to support 64 bit time on architectures with
> __WORDSIZE==32).
> 
> Now it is possible to just include definition of this particular structure
> when needed.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  include/struct___timeval64.h | 17 +++++++++++++++++
>  include/time.h               | 15 +--------------
>  2 files changed, 18 insertions(+), 14 deletions(-)
>  create mode 100644 include/struct___timeval64.h
> 
> diff --git a/include/struct___timeval64.h b/include/struct___timeval64.h
> new file mode 100644
> index 0000000000..05cf2f26fc
> --- /dev/null
> +++ b/include/struct___timeval64.h
> @@ -0,0 +1,17 @@
> +#ifndef _STRUCT_TIMEVAL64_H
> +#define _STRUCT_TIMEVAL64_H
> +
> +#if __TIMESIZE == 64
> +# define __timeval64 timeval
> +#else
> +/* The glibc Y2038-proof struct __timeval64 structure for a time value.
> +   This structure is NOT supposed to be passed to the Linux kernel.
> +   Instead, it shall be converted to struct __timespec64 and time shall
> +   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
> +struct __timeval64
> +{
> +  __time64_t tv_sec;         /* Seconds */
> +  __suseconds64_t tv_usec;       /* Microseconds */
> +};
> +#endif
> +#endif /* _STRUCT_TIMEVAL64_H  */

Ok.

> diff --git a/include/time.h b/include/time.h
> index 1c103a4cb2..fe4da9ca10 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -4,6 +4,7 @@
>  #ifndef _ISOMAC
>  # include <bits/types/struct_timeval.h>
>  # include <struct___timespec64.h>
> +# include <struct___timeval64.h>
>  # include <bits/types/locale_t.h>
>  # include <stdbool.h>
>  # include <time/mktime-internal.h>
> @@ -73,20 +74,6 @@ struct __itimerspec64
>  };
>  #endif
>  
> -#if __TIMESIZE == 64
> -# define __timeval64 timeval
> -#else
> -/* The glibc Y2038-proof struct __timeval64 structure for a time value.
> -   This structure is NOT supposed to be passed to the Linux kernel.
> -   Instead, it shall be converted to struct __timespec64 and time shall
> -   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
> -struct __timeval64
> -{
> -  __time64_t tv_sec;         /* Seconds */
> -  __suseconds64_t tv_usec;       /* Microseconds */
> -};
> -#endif
> -
>  #if __TIMESIZE == 64
>  # define __utimbuf64 utimbuf
>  # define __itimerval64 itimerval
> 

Ok.

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

* Re: [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type
  2020-04-26 13:31 ` [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type Lukasz Majewski
  2020-04-27 15:22   ` Alistair Francis
@ 2020-04-28 14:34   ` Adhemerval Zanella
  2020-04-29 21:45     ` Lukasz Majewski
  1 sibling, 1 reply; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 14:34 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's
> struct __kernel_timex (v5.6) introduced for properly handling data for
> clock_adjtime64 syscall.
> As the struct's __kernel_timex size is the same as for archs with
> __WORDSIZE == 64, proper padding and data types conversion (i.e. long to long
> long) had to be added for architectures with __WORDSIZE == 32 &&
> __TIMESIZE != 64.
> 
> Moreover, it stores time in struct __timeval64 rather than struct
> timeval, which makes it Y2038-proof.
> 
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs

LGTM, with just two nits about code formatting and and type specification.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index 319d566608..f25081639b 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -25,5 +25,43 @@
>  
>  libc_hidden_proto (__adjtimex)
>  
> +#  include <struct___timeval64.h>
> +/* Local definition of 64 bit time supporting timex struct */
> +#  if __TIMESIZE == 64
> +#   define __timex64 timex
> +#  else
> +
> +struct __timex64
> +{
> +  unsigned int modes;          /* mode selector */
> +  int :32;                     /* pad */
> +  long long offset;            /* time offset (usec) */
> +  long long freq;              /* frequency offset (scaled ppm) */
> +  long long maxerror;          /* maximum error (usec) */
> +  long long esterror;          /* estimated error (usec) */
> +  int status;                  /* clock command/status */
> +  int :32;                     /* pad */
> +  long long constant;          /* pll time constant */
> +  long long precision;         /* clock precision (usec) (read only) */
> +  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */
> +  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */
> +  long long tick;              /* (modified) usecs between clock ticks */
> +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
> +  long long jitter;            /* pps jitter (us) (ro) */
> +  int shift;                   /* interval duration (s) (shift) (ro) */
> +  int :32;                     /* pad */
> +  long long stabil;            /* pps stability (scaled ppm) (ro) */
> +  long long jitcnt;            /* jitter limit exceeded (ro) */
> +  long long calcnt;            /* calibration intervals (ro) */
> +  long long errcnt;            /* calibration errors (ro) */
> +  long long stbcnt;            /* stability limit exceeded (ro) */
> +
> +  int tai;                     /* TAI offset (ro) */
> +
> +  int  :32; int  :32; int  :32; int  :32;
> +  int  :32; int  :32; int  :32; int  :32;
> +  int  :32; int  :32; int  :32;

Not sure which is the code guidelines for unnamed bit fields, indent
places one field per line:

  [...]   
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  [...]


> +};
> +#  endif
>  # endif /* _ISOMAC */
>  #endif /* sys/timex.h */
> 

Use 'long long int' instead of 'long long'.

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

* Re: [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64
  2020-04-26 13:31 ` [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64 Lukasz Majewski
  2020-04-27 15:22   ` Alistair Francis
@ 2020-04-28 15:56   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 15:56 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> Those functions allow easy conversion between Y2038 safe, glibc internal
> struct __timex64 and struct timex.
> 
> Those functions are put in Linux specific sys/timex.h file, as putting
> them into glibc's local include/time.h would cause build break on HURD as
> it doesn't support struct timex related syscalls.
> 
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/include/sys/timex.h | 61 +++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index f25081639b..bab6b28920 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -25,6 +25,7 @@
>  
>  libc_hidden_proto (__adjtimex)
>  
> +#  include <time.h>
>  #  include <struct___timeval64.h>
>  /* Local definition of 64 bit time supporting timex struct */
>  #  if __TIMESIZE == 64
> @@ -63,5 +64,65 @@ struct __timex64
>    int  :32; int  :32; int  :32;
>  };
>  #  endif
> +
> +/* Convert a known valid struct timex into a struct __timex64.  */
> +static inline struct __timex64
> +valid_timex_to_timex64 (const struct timex tx)
> +{
> +  struct __timex64 tx64;
> +
> +  tx64.modes = tx.modes;
> +  tx64.offset = tx.offset;
> +  tx64.freq = tx.freq;
> +  tx64.maxerror = tx.maxerror;
> +  tx64.esterror = tx.esterror;
> +  tx64.status = tx.status;
> +  tx64.constant = tx.constant;
> +  tx64.precision = tx.precision;
> +  tx64.tolerance = tx.tolerance;
> +  tx64.time = valid_timeval_to_timeval64 (tx.time);
> +  tx64.tick = tx.tick;
> +  tx64.ppsfreq = tx.ppsfreq;
> +  tx64.jitter = tx.jitter;
> +  tx64.shift = tx.shift;
> +  tx64.stabil = tx.stabil;
> +  tx64.jitcnt = tx.jitcnt;
> +  tx64.calcnt = tx.calcnt;
> +  tx64.errcnt = tx.errcnt;
> +  tx64.stbcnt = tx.stbcnt;
> +  tx64.tai = tx.tai;
> +
> +  return tx64;
> +}
> +

Ok.

> +/* Convert a known valid struct __timex64 into a struct timex.  */
> +static inline struct timex
> +valid_timex64_to_timex (const struct __timex64 tx64)
> +{
> +  struct timex tx;
> +
> +  tx.modes = tx64.modes;
> +  tx.offset = tx64.offset;
> +  tx.freq = tx64.freq;
> +  tx.maxerror = tx64.maxerror;
> +  tx.esterror = tx64.esterror;
> +  tx.status = tx64.status;
> +  tx.constant = tx64.constant;
> +  tx.precision = tx64.precision;
> +  tx.tolerance = tx64.tolerance;
> +  tx.time = valid_timeval64_to_timeval (tx64.time);
> +  tx.tick = tx64.tick;
> +  tx.ppsfreq = tx64.ppsfreq;
> +  tx.jitter = tx64.jitter;
> +  tx.shift = tx64.shift;
> +  tx.stabil = tx64.stabil;
> +  tx.jitcnt = tx64.jitcnt;
> +  tx.calcnt = tx64.calcnt;
> +  tx.errcnt = tx64.errcnt;
> +  tx.stbcnt = tx64.stbcnt;
> +  tx.tai = tx64.tai;
> +
> +  return tx;
> +}
>  # endif /* _ISOMAC */
>  #endif /* sys/timex.h */
> 

Ok.

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

* Re: [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation
  2020-04-26 13:31 ` [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
  2020-04-27 22:12   ` Alistair Francis
@ 2020-04-28 17:00   ` Adhemerval Zanella
  2020-04-29 21:43     ` Lukasz Majewski
  1 sibling, 1 reply; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 17:00 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> This patch replaces auto generated wrapper (as described in
> sysdeps/unix/sysv/linux/syscalls.list) for clock_adjtime with one which adds
> extra support for reading 64 bit time values on machines with __TIMESIZE != 64.
> 
> To achieve this goal new __clock_adjtime64 explicit 64 bit function for
> adjusting Linux clock has been added.
> Moreover, a 32 bit version - __clock_adjtime has been refactored to internally
> use __clock_adjtime64.
> 
> The __clock_adjtime is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between 64 bit
> struct __timespec64 and struct timespec.
> 
> The new __clock_adjtime64 syscall available from Linux 5.1+ has been used, when
> applicable.
> Up till v5.4 in the Linux kernel there was a bug preventing this call from
> obtaining correct struct's timex time.tv_sec time after time_t overflow
> (i.e. not being Y2038 safe).
> 
> Build tests:
> - ./src/scripts/build-many-glibcs.py glibcs
> 
> 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
> 
> Linux kernel, headers and minimal kernel version for glibc build test matrix:
> - Linux v5.1 (with clock_adjtime64) 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 clock_adjtime64
>   syscall.
> 
> - Linux v4.19 (no clock_adjtime64 support) with default minimal kernel version
>   for contemporary glibc (3.2.0)
>   This kernel doesn't support clock_adjtime64 syscall, so the fallback to
>   clock_adjtime 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.
> ---
>  sysdeps/unix/sysv/linux/Makefile            |  2 +-
>  sysdeps/unix/sysv/linux/clock_adjtime.c     | 64 +++++++++++++++++++++
>  sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +
>  sysdeps/unix/sysv/linux/syscalls.list       |  1 -
>  4 files changed, 68 insertions(+), 2 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c
> 
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 089a4899d5..dfb200eccf 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
>  		   eventfd eventfd_read eventfd_write prlimit \
>  		   personality epoll_wait tee vmsplice splice \
>  		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
> -		   timerfd_gettime timerfd_settime
> +		   timerfd_gettime timerfd_settime clock_adjtime
>  
>  CFLAGS-gethostid.c = -fexceptions
>  CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables

Ok.

> diff --git a/sysdeps/unix/sysv/linux/clock_adjtime.c b/sysdeps/unix/sysv/linux/clock_adjtime.c
> new file mode 100644
> index 0000000000..cbab6bf345
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/clock_adjtime.c
> @@ -0,0 +1,64 @@
> +/* clock_adjtime -- tune kernel clock
> +   Copyright (C) 2020 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public License as
> +   published by the Free Software Foundation; either version 2.1 of the
> +   License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; see the file COPYING.LIB.  If
> +   not, see <https://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <time.h>
> +#include <sysdep.h>
> +#include <sys/timex.h>
> +#include <kernel-features.h>
> +
> +int
> +__clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
> +{
> +#ifdef __ASSUME_TIME64_SYSCALLS
> +# ifndef __NR_clock_adjtime64
> +#  define __NR_clock_adjtime64 __NR_clock_adjtime
> +# endif
> +	return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);

Ok.

> +#else
> +  int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
> +  if ((ret >= TIME_OK && ret <= TIME_ERROR) || errno != ENOSYS)
> +    return ret;

I see no point in issuing the non y2038 syscall for a return value not
in the define TIME_* constants.  I think so such cases it just return
the value to caller.

> +
> +  struct timex tx32 = valid_timex64_to_timex (*tx64);

This does not handle 'time' overflow for ADJ_SETOFFSET case (which might
ending setting an invalid time).  I think we should follow other y2038 
safe implementation and return EOVERFLOW in such case.  Something like:

  if (tx64->modes & ADJ_SETOFFSET
      && ! in_time_t_range (tx64.time.tv_sec))
    { 
      __set_errno (EOVERFLOW);
      return -1;
    }

> +  int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32);
> +  *tx64 = valid_timex_to_timex64 (tx32);
> +
> +  return retval;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__clock_adjtime64)
> +
> +int
> +__clock_adjtime (const clockid_t clock_id, struct timex *tx)
> +{
> +	struct __timex64 tx64;

Wrong identation.

> +  int retval;
> +
> +  tx64 = valid_timex_to_timex64 (*tx);
> +  retval = __clock_adjtime64 (clock_id, &tx64);
> +  *tx = valid_timex64_to_timex (tx64);
> +
> +  return retval;
> +}
> +#endif> +libc_hidden_def (__clock_adjtime);
> +strong_alias (__clock_adjtime, clock_adjtime)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index bab6b28920..f1bb364db4 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -30,6 +30,7 @@ libc_hidden_proto (__adjtimex)
>  /* Local definition of 64 bit time supporting timex struct */
>  #  if __TIMESIZE == 64
>  #   define __timex64 timex
> +#   define __clock_adjtime64 __clock_adjtime
>  #  else
>  

Ok.

>  struct __timex64
> @@ -63,6 +64,8 @@ struct __timex64
>    int  :32; int  :32; int  :32; int  :32;
>    int  :32; int  :32; int  :32;
>  };
> +extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
> +libc_hidden_proto (__clock_adjtime64);
>  #  endif
>  
>  /* Convert a known valid struct timex into a struct __timex64.  */

Ok.

> diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> index e40f993495..d7d73e8fcb 100644
> --- a/sysdeps/unix/sysv/linux/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/syscalls.list
> @@ -4,7 +4,6 @@ alarm		-	alarm		i:i	alarm
>  bdflush		EXTRA	bdflush		i:ii	__compat_bdflush	bdflush@GLIBC_2.0:GLIBC_2.23
>  capget		EXTRA	capget		i:pp	capget
>  capset		EXTRA	capset		i:pp	capset
> -clock_adjtime	EXTRA	clock_adjtime	i:ip	__clock_adjtime		clock_adjtime
>  create_module	EXTRA	create_module	3	__compat_create_module	create_module@GLIBC_2.0:GLIBC_2.23
>  delete_module	EXTRA	delete_module	3	delete_module
>  epoll_create	EXTRA	epoll_create	i:i	epoll_create
> 

Ok.

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

* Re: [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation
  2020-04-26 13:31 ` [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
  2020-04-27 22:12   ` Alistair Francis
@ 2020-04-28 17:14   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 17:14 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> This patch provides new ___adjtimex64 explicit 64 bit function for adjusting
> Linux kernel clock.
> 
> Internally, the __clock_adjtime64 syscall is used. This patch is necessary
> for having architectures with __WORDSIZE == 32 Y2038 safe.
> 
> Moreover, a 32 bit version - ___adjtimex has been refactored to internally
> use ___adjtimex64.
> 
> The ___adjtimex is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
> timex and 64 bit struct __timex64.
> 
> Last but not least, in ___adjtimex64 function the __clock_adjtime syscall has
> been replaced with __clock_adjtime64 to support 64 bit time on architectures
> with __WORDSIZE == 32 and __TIMESIZE != 64.
> 
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs
> 
> 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
> 
> Above tests were performed with Y2038 redirection applied as well as without to
> test the proper usage of both ___adjtimex64 and ___adjtimex.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/adjtimex.c          | 21 +++++++++++++++++++--
>  sysdeps/unix/sysv/linux/include/sys/timex.h |  3 +++
>  2 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/adjtimex.c b/sysdeps/unix/sysv/linux/adjtimex.c
> index ebc17476a7..683cc65696 100644
> --- a/sysdeps/unix/sysv/linux/adjtimex.c
> +++ b/sysdeps/unix/sysv/linux/adjtimex.c
> @@ -20,11 +20,28 @@
>  #include <sysdep.h>
>  
>  int
> -___adjtimex (struct timex *buf)
> +___adjtimex64 (struct __timex64 *tx64)
>  {
> -  return __clock_adjtime (CLOCK_REALTIME, buf);
> +  return __clock_adjtime64 (CLOCK_REALTIME, tx64);
>  }
>  

Ok.

> +#if __TIMESIZE != 64
> +libc_hidden_def (___adjtimex64)
> +
> +int
> +___adjtimex (struct timex *tx)
> +{
> +  struct __timex64 tx64;
> +  int retval;
> +
> +  tx64 = valid_timex_to_timex64 (*tx);
> +  retval = ___adjtimex64 (&tx64);
> +  *tx = valid_timex64_to_timex (tx64);
> +
> +  return retval;
> +}
> +#endif
> +
>  #ifdef VERSION_adjtimex
>  weak_alias (___adjtimex, __wadjtimex);
>  weak_alias (___adjtimex, __wnadjtime);

Ok.

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
> index f1bb364db4..fdfffe2f3a 100644
> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h
> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
> @@ -31,6 +31,7 @@ libc_hidden_proto (__adjtimex)
>  #  if __TIMESIZE == 64
>  #   define __timex64 timex
>  #   define __clock_adjtime64 __clock_adjtime
> +#   define ___adjtimex64 ___adjtimex
>  #  else
>  
>  struct __timex64
> @@ -66,6 +67,8 @@ struct __timex64
>  };
>  extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
>  libc_hidden_proto (__clock_adjtime64);
> +extern int ___adjtimex64 (struct __timex64 *tx64);
> +libc_hidden_proto (___adjtimex64)
>  #  endif
>  
>  /* Convert a known valid struct timex into a struct __timex64.  */
> 

Ok.

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

* Re: [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation
  2020-04-26 13:31 ` [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
  2020-04-27 22:14   ` Alistair Francis
@ 2020-04-28 18:33   ` Adhemerval Zanella
  1 sibling, 0 replies; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 18:33 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> This patch provides new __adjtime64 explicit 64 bit function for adjusting
> Linux kernel clock.
> 
> Internally, the __clock_adjtime64 syscall is used instead of __adjtimex. This
> patch is necessary for having architectures with __WORDSIZE == 32 Y2038 safe.
> 
> Moreover, a 32 bit version - __adjtime has been refactored to internally use
> __adjtime64.
> 
> The __adjtime is now supposed to be used on systems still supporting 32
> bit time (__TIMESIZE != 64) - hence the necessary conversions between struct
> timeval and 64 bit struct __timeval64.
> 
> 
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs
> 
> 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
> 
> Above tests were performed with Y2038 redirection applied as well as without to
> test the proper usage of both __adjtime64 and __adjtime.

LGTM with a indentation nit below.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  include/sys/time.h                |  9 +++++++++
>  sysdeps/unix/sysv/linux/adjtime.c | 26 ++++++++++++++++++++++----
>  2 files changed, 31 insertions(+), 4 deletions(-)
> 
> diff --git a/include/sys/time.h b/include/sys/time.h
> index 8153d75033..567e4b7562 100644
> --- a/include/sys/time.h
> +++ b/include/sys/time.h
> @@ -26,6 +26,15 @@ extern int __settimezone (const struct timezone *__tz)
>  	attribute_hidden;
>  extern int __adjtime (const struct timeval *__delta,
>  		      struct timeval *__olddelta);
> +
> +#  include <struct___timeval64.h>
> +#  if __TIMESIZE == 64
> +#   define __adjtime64 __adjtime
> +#  else
> +extern int __adjtime64 (const struct __timeval64 *itv,
> +                        struct __timeval64 *otv);
> +libc_hidden_proto (__adjtime64)
> +#  endif
>  extern int __getitimer (enum __itimer_which __which,
>  			struct itimerval *__value);
>  extern int __setitimer (enum __itimer_which __which,

Ok.

> diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
> index c142f4f6ea..f7ec24b43a 100644
> --- a/sysdeps/unix/sysv/linux/adjtime.c
> +++ b/sysdeps/unix/sysv/linux/adjtime.c
> @@ -24,13 +24,13 @@
>  #define MIN_SEC	(INT_MIN / 1000000L + 2)
>  
>  int
> -__adjtime (const struct timeval *itv, struct timeval *otv)
> +__adjtime64 (const struct __timeval64 *itv, struct __timeval64 *otv)
>  {
> -  struct timex tntx;
> +  struct __timex64 tntx;
>  
>    if (itv)
>      {
> -      struct timeval tmp;
> +      struct __timeval64 tmp;
>  
>        /* We will do some check here. */
>        tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
> @@ -43,7 +43,7 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
>    else
>      tntx.modes = ADJ_OFFSET_SS_READ;
>  
> -  if (__glibc_unlikely (__adjtimex (&tntx) < 0))
> +  if (__glibc_unlikely (__clock_adjtime64 (CLOCK_REALTIME, &tntx) < 0))
>      return -1;
>  
>    if (otv)
> @@ -62,6 +62,24 @@ __adjtime (const struct timeval *itv, struct timeval *otv)
>    return 0;
>  }

Ok.

>  
> +#if __TIMESIZE != 64
> +libc_hidden_def (__adjtime64)
> +
> +int
> +__adjtime (const struct timeval *itv, struct timeval *otv)
> +{
> +  struct __timeval64 itv64, otv64;
> +  int retval;
> +
> +  itv64 = valid_timeval_to_timeval64 (*itv);
> +  retval = __adjtime64 (&itv64, otv != NULL ? &otv64 : NULL);
> +  if (otv != NULL)
> +	  *otv = valid_timeval64_to_timeval (otv64);

Indentation seems off.

> +
> +  return retval;
> +}
> +#endif
> +
>  #ifdef VERSION_adjtime
>  weak_alias (__adjtime, __wadjtime);
>  default_symbol_version (__wadjtime, adjtime, VERSION_adjtime);
> 

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

* Re: [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type
  2020-04-26 13:31 ` [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type Lukasz Majewski
@ 2020-04-28 18:41   ` Adhemerval Zanella
  2020-04-29 21:28     ` Lukasz Majewski
  0 siblings, 1 reply; 28+ messages in thread
From: Adhemerval Zanella @ 2020-04-28 18:41 UTC (permalink / raw)
  To: Lukasz Majewski, Joseph Myers
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab



On 26/04/2020 10:31, Lukasz Majewski wrote:
> @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64);
>  libc_hidden_proto (__clock_adjtime64);
>  extern int ___adjtimex64 (struct __timex64 *tx64);
>  libc_hidden_proto (___adjtimex64)
> +
> +struct __ntptimeval64
> +{
> +  struct __timeval64 time;	/* current time (ro) */
> +  long int maxerror;	/* maximum error (us) (ro) */
> +  long int esterror;	/* estimated error (us) (ro) */
> +  long int tai;		/* TAI offset (ro) */
> +
> +  long int __glibc_reserved1;
> +  long int __glibc_reserved2;
> +  long int __glibc_reserved3;
> +  long int __glibc_reserved4;

Why does it need the extra reserved fields?

> +};
>  #  endif
>  
>  /* Convert a known valid struct timex into a struct __timex64.  */
> 

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

* Re: [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type
  2020-04-28 18:41   ` Adhemerval Zanella
@ 2020-04-29 21:28     ` Lukasz Majewski
  2020-05-07 18:32       ` Lukasz Majewski
  0 siblings, 1 reply; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-29 21:28 UTC (permalink / raw)
  To: Adhemerval Zanella
  Cc: Joseph Myers, Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]

Hi Adhemerval,

> On 26/04/2020 10:31, Lukasz Majewski wrote:
> > @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t
> > clock_id, struct __timex64 *tx64); libc_hidden_proto
> > (__clock_adjtime64); extern int ___adjtimex64 (struct __timex64
> > *tx64); libc_hidden_proto (___adjtimex64)
> > +
> > +struct __ntptimeval64
> > +{
> > +  struct __timeval64 time;	/* current time (ro) */
> > +  long int maxerror;	/* maximum error (us) (ro) */
> > +  long int esterror;	/* estimated error (us) (ro) */
> > +  long int tai;		/* TAI offset (ro) */
> > +
> > +  long int __glibc_reserved1;
> > +  long int __glibc_reserved2;
> > +  long int __glibc_reserved3;
> > +  long int __glibc_reserved4;  
> 
> Why does it need the extra reserved fields?

I've followed the definition of in-glibc ntptimeval definition in
sysdeps/unix/sysv/linux/sys/timex.h

As the __ntptimeval64 is not passed to the kernel (it gets its values
based on struct __timex64), IMHO it would be safe to remove them.

> 
> > +};
> >  #  endif
> >  
> >  /* Convert a known valid struct timex into a struct __timex64.  */
> >   




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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation
  2020-04-28 17:00   ` Adhemerval Zanella
@ 2020-04-29 21:43     ` Lukasz Majewski
  0 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-29 21:43 UTC (permalink / raw)
  To: Adhemerval Zanella
  Cc: Joseph Myers, Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 9241 bytes --]

Hi Adhemerval,

> On 26/04/2020 10:31, Lukasz Majewski wrote:
> > This patch replaces auto generated wrapper (as described in
> > sysdeps/unix/sysv/linux/syscalls.list) for clock_adjtime with one
> > which adds extra support for reading 64 bit time values on machines
> > with __TIMESIZE != 64.
> > 
> > To achieve this goal new __clock_adjtime64 explicit 64 bit function
> > for adjusting Linux clock has been added.
> > Moreover, a 32 bit version - __clock_adjtime has been refactored to
> > internally use __clock_adjtime64.
> > 
> > The __clock_adjtime is now supposed to be used on systems still
> > supporting 32 bit time (__TIMESIZE != 64) - hence the necessary
> > conversions between 64 bit struct __timespec64 and struct timespec.
> > 
> > The new __clock_adjtime64 syscall available from Linux 5.1+ has
> > been used, when applicable.
> > Up till v5.4 in the Linux kernel there was a bug preventing this
> > call from obtaining correct struct's timex time.tv_sec time after
> > time_t overflow (i.e. not being Y2038 safe).
> > 
> > Build tests:
> > - ./src/scripts/build-many-glibcs.py glibcs
> > 
> > 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
> > 
> > Linux kernel, headers and minimal kernel version for glibc build
> > test matrix:
> > - Linux v5.1 (with clock_adjtime64) 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
> > clock_adjtime64 syscall.
> > 
> > - Linux v4.19 (no clock_adjtime64 support) with default minimal
> > kernel version for contemporary glibc (3.2.0)
> >   This kernel doesn't support clock_adjtime64 syscall, so the
> > fallback to clock_adjtime 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.
> > ---
> >  sysdeps/unix/sysv/linux/Makefile            |  2 +-
> >  sysdeps/unix/sysv/linux/clock_adjtime.c     | 64
> > +++++++++++++++++++++ sysdeps/unix/sysv/linux/include/sys/timex.h |
> >  3 + sysdeps/unix/sysv/linux/syscalls.list       |  1 -
> >  4 files changed, 68 insertions(+), 2 deletions(-)
> >  create mode 100644 sysdeps/unix/sysv/linux/clock_adjtime.c
> > 
> > diff --git a/sysdeps/unix/sysv/linux/Makefile
> > b/sysdeps/unix/sysv/linux/Makefile index 089a4899d5..dfb200eccf
> > 100644 --- a/sysdeps/unix/sysv/linux/Makefile
> > +++ b/sysdeps/unix/sysv/linux/Makefile
> > @@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2
> > readahead sysctl \ eventfd eventfd_read eventfd_write prlimit \
> >  		   personality epoll_wait tee vmsplice splice \
> >  		   open_by_handle_at mlock2 pkey_mprotect pkey_set
> > pkey_get \
> > -		   timerfd_gettime timerfd_settime
> > +		   timerfd_gettime timerfd_settime clock_adjtime
> >  
> >  CFLAGS-gethostid.c = -fexceptions
> >  CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables  
> 
> Ok.
> 
> > diff --git a/sysdeps/unix/sysv/linux/clock_adjtime.c
> > b/sysdeps/unix/sysv/linux/clock_adjtime.c new file mode 100644
> > index 0000000000..cbab6bf345
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/clock_adjtime.c
> > @@ -0,0 +1,64 @@
> > +/* clock_adjtime -- tune kernel clock
> > +   Copyright (C) 2020 Free Software Foundation, Inc.
> > +   This file is part of the GNU C Library.
> > +
> > +   The GNU C Library is free software; you can redistribute it
> > and/or
> > +   modify it under the terms of the GNU Lesser General Public
> > License as
> > +   published by the Free Software Foundation; either version 2.1
> > of the
> > +   License, or (at your option) any later version.
> > +
> > +   The GNU C Library is distributed in the hope that it will be
> > useful,
> > +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > GNU
> > +   Lesser General Public License for more details.
> > +
> > +   You should have received a copy of the GNU Lesser General Public
> > +   License along with the GNU C Library; see the file COPYING.LIB.
> >  If
> > +   not, see <https://www.gnu.org/licenses/>.  */
> > +
> > +#include <errno.h>
> > +#include <stdlib.h>
> > +#include <time.h>
> > +#include <sysdep.h>
> > +#include <sys/timex.h>
> > +#include <kernel-features.h>
> > +
> > +int
> > +__clock_adjtime64 (const clockid_t clock_id, struct __timex64
> > *tx64) +{
> > +#ifdef __ASSUME_TIME64_SYSCALLS
> > +# ifndef __NR_clock_adjtime64
> > +#  define __NR_clock_adjtime64 __NR_clock_adjtime
> > +# endif
> > +	return INLINE_SYSCALL_CALL (clock_adjtime64, clock_id,
> > tx64);  
> 
> Ok.
> 
> > +#else
> > +  int ret = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
> > +  if ((ret >= TIME_OK && ret <= TIME_ERROR) || errno != ENOSYS)
> > +    return ret;  
> 
> I see no point in issuing the non y2038 syscall for a return value not
> in the define TIME_* constants.  I think so such cases it just return
> the value to caller.

Could you be more specific?

We do call 32 bit clock_adjtime only when:

- ret is not in correct TIME_* range

or

- errno == ENOSYS (not available on the system due to old kernel)


Would you instead prefer to just have:

if (errno != ENOSYS)
  return ret;


> 
> > +
> > +  struct timex tx32 = valid_timex64_to_timex (*tx64);  
> 
> This does not handle 'time' overflow for ADJ_SETOFFSET case (which
> might ending setting an invalid time).  I think we should follow
> other y2038 safe implementation and return EOVERFLOW in such case.
> Something like:
> 
>   if (tx64->modes & ADJ_SETOFFSET
>       && ! in_time_t_range (tx64.time.tv_sec))
>     { 
>       __set_errno (EOVERFLOW);
>       return -1;
>     }
> 

I've thought about it as well. 

However, the time.tv_{u}sec used when ADJ_SETOFFSET is set is only
added to the current kernel time [1]. It is very unlikely that we will
provide offset value, which would overflow 32 bits tv_sec.

However, if you prefer I can add the above check as well.

[1] - http://man7.org/linux/man-pages/man2/adjtimex.2.html

> > +  int retval = INLINE_SYSCALL_CALL (clock_adjtime, clock_id,
> > &tx32);
> > +  *tx64 = valid_timex_to_timex64 (tx32);
> > +
> > +  return retval;
> > +#endif
> > +}
> > +
> > +#if __TIMESIZE != 64
> > +libc_hidden_def (__clock_adjtime64)
> > +
> > +int
> > +__clock_adjtime (const clockid_t clock_id, struct timex *tx)
> > +{
> > +	struct __timex64 tx64;  
> 
> Wrong identation.
> 

I will double check it.

> > +  int retval;
> > +
> > +  tx64 = valid_timex_to_timex64 (*tx);
> > +  retval = __clock_adjtime64 (clock_id, &tx64);
> > +  *tx = valid_timex64_to_timex (tx64);
> > +
> > +  return retval;
> > +}  
> > +#endif> +libc_hidden_def (__clock_adjtime);  
> > +strong_alias (__clock_adjtime, clock_adjtime)  
> 
> Ok.
> 
> > diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h
> > b/sysdeps/unix/sysv/linux/include/sys/timex.h index
> > bab6b28920..f1bb364db4 100644 ---
> > a/sysdeps/unix/sysv/linux/include/sys/timex.h +++
> > b/sysdeps/unix/sysv/linux/include/sys/timex.h @@ -30,6 +30,7 @@
> > libc_hidden_proto (__adjtimex) /* Local definition of 64 bit time
> > supporting timex struct */ #  if __TIMESIZE == 64
> >  #   define __timex64 timex
> > +#   define __clock_adjtime64 __clock_adjtime
> >  #  else
> >    
> 
> Ok.
> 
> >  struct __timex64
> > @@ -63,6 +64,8 @@ struct __timex64
> >    int  :32; int  :32; int  :32; int  :32;
> >    int  :32; int  :32; int  :32;
> >  };
> > +extern int __clock_adjtime64 (const clockid_t clock_id, struct
> > __timex64 *tx64); +libc_hidden_proto (__clock_adjtime64);
> >  #  endif
> >  
> >  /* Convert a known valid struct timex into a struct __timex64.  */
> >  
> 
> Ok.
> 
> > diff --git a/sysdeps/unix/sysv/linux/syscalls.list
> > b/sysdeps/unix/sysv/linux/syscalls.list index
> > e40f993495..d7d73e8fcb 100644 ---
> > a/sysdeps/unix/sysv/linux/syscalls.list +++
> > b/sysdeps/unix/sysv/linux/syscalls.list @@ -4,7 +4,6 @@
> > alarm		-	alarm		i:i	alarm
> > bdflush		EXTRA	bdflush
> > i:ii	__compat_bdflush	bdflush@GLIBC_2.0:GLIBC_2.23
> > capget		EXTRA	capget
> > i:pp	capget capset		EXTRA	capset
> > 	i:pp	capset -clock_adjtime	EXTRA
> > clock_adjtime	i:ip	__clock_adjtime
> > clock_adjtime create_module	EXTRA
> > create_module	3	__compat_create_module
> > create_module@GLIBC_2.0:GLIBC_2.23 delete_module
> > EXTRA	delete_module	3	delete_module
> > epoll_create	EXTRA	epoll_create	i:i
> > epoll_create 
> 
> Ok.




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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type
  2020-04-28 14:34   ` Adhemerval Zanella
@ 2020-04-29 21:45     ` Lukasz Majewski
  0 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-04-29 21:45 UTC (permalink / raw)
  To: Adhemerval Zanella
  Cc: Joseph Myers, Alistair Francis, Alistair Francis, GNU C Library,
	Florian Weimer, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 4038 bytes --]

Hi Adhemerval,

> On 26/04/2020 10:31, Lukasz Majewski wrote:
> > The introduced glibc's 'internal' struct __timex64 is a copy of
> > Linux kernel's struct __kernel_timex (v5.6) introduced for properly
> > handling data for clock_adjtime64 syscall.
> > As the struct's __kernel_timex size is the same as for archs with
> > __WORDSIZE == 64, proper padding and data types conversion (i.e.
> > long to long long) had to be added for architectures with
> > __WORDSIZE == 32 && __TIMESIZE != 64.
> > 
> > Moreover, it stores time in struct __timeval64 rather than struct
> > timeval, which makes it Y2038-proof.
> > 
> > Build tests:
> > ./src/scripts/build-many-glibcs.py glibcs  
> 
> LGTM, with just two nits about code formatting and and type
> specification.
> 
> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> 
> > ---
> >  sysdeps/unix/sysv/linux/include/sys/timex.h | 38
> > +++++++++++++++++++++ 1 file changed, 38 insertions(+)
> > 
> > diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h
> > b/sysdeps/unix/sysv/linux/include/sys/timex.h index
> > 319d566608..f25081639b 100644 ---
> > a/sysdeps/unix/sysv/linux/include/sys/timex.h +++
> > b/sysdeps/unix/sysv/linux/include/sys/timex.h @@ -25,5 +25,43 @@
> >  
> >  libc_hidden_proto (__adjtimex)
> >  
> > +#  include <struct___timeval64.h>
> > +/* Local definition of 64 bit time supporting timex struct */
> > +#  if __TIMESIZE == 64
> > +#   define __timex64 timex
> > +#  else
> > +
> > +struct __timex64
> > +{
> > +  unsigned int modes;          /* mode selector */
> > +  int :32;                     /* pad */
> > +  long long offset;            /* time offset (usec) */
> > +  long long freq;              /* frequency offset (scaled ppm) */
> > +  long long maxerror;          /* maximum error (usec) */
> > +  long long esterror;          /* estimated error (usec) */
> > +  int status;                  /* clock command/status */
> > +  int :32;                     /* pad */
> > +  long long constant;          /* pll time constant */
> > +  long long precision;         /* clock precision (usec) (read
> > only) */
> > +  long long tolerance;         /* clock frequency tolerance (ppm)
> > (ro) */
> > +  struct __timeval64 time;     /* (read only, except for
> > ADJ_SETOFFSET) */
> > +  long long tick;              /* (modified) usecs between clock
> > ticks */
> > +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro)
> > */
> > +  long long jitter;            /* pps jitter (us) (ro) */
> > +  int shift;                   /* interval duration (s) (shift)
> > (ro) */
> > +  int :32;                     /* pad */
> > +  long long stabil;            /* pps stability (scaled ppm) (ro)
> > */
> > +  long long jitcnt;            /* jitter limit exceeded (ro) */
> > +  long long calcnt;            /* calibration intervals (ro) */
> > +  long long errcnt;            /* calibration errors (ro) */
> > +  long long stbcnt;            /* stability limit exceeded (ro) */
> > +
> > +  int tai;                     /* TAI offset (ro) */
> > +
> > +  int  :32; int  :32; int  :32; int  :32;
> > +  int  :32; int  :32; int  :32; int  :32;
> > +  int  :32; int  :32; int  :32;  
> 
> Not sure which is the code guidelines for unnamed bit fields, indent
> places one field per line:
> 
>   [...]   
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   int:32;
>   [...]
> 
> 
> > +};
> > +#  endif
> >  # endif /* _ISOMAC */
> >  #endif /* sys/timex.h */
> >   
> 
> Use 'long long int' instead of 'long long'.

I took the structure directly from v5.6 linux kernel - I will fix those
issues.


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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type
  2020-04-29 21:28     ` Lukasz Majewski
@ 2020-05-07 18:32       ` Lukasz Majewski
  0 siblings, 0 replies; 28+ messages in thread
From: Lukasz Majewski @ 2020-05-07 18:32 UTC (permalink / raw)
  To: Adhemerval Zanella
  Cc: Florian Weimer, GNU C Library, Andreas Schwab, Alistair Francis,
	Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]

Hi Adhemerval,

> Hi Adhemerval,
> 
> > On 26/04/2020 10:31, Lukasz Majewski wrote:  
> > > @@ -69,6 +70,19 @@ extern int __clock_adjtime64 (const clockid_t
> > > clock_id, struct __timex64 *tx64); libc_hidden_proto
> > > (__clock_adjtime64); extern int ___adjtimex64 (struct __timex64
> > > *tx64); libc_hidden_proto (___adjtimex64)
> > > +
> > > +struct __ntptimeval64
> > > +{
> > > +  struct __timeval64 time;	/* current time (ro) */
> > > +  long int maxerror;	/* maximum error (us) (ro) */
> > > +  long int esterror;	/* estimated error (us) (ro) */
> > > +  long int tai;		/* TAI offset (ro) */
> > > +
> > > +  long int __glibc_reserved1;
> > > +  long int __glibc_reserved2;
> > > +  long int __glibc_reserved3;
> > > +  long int __glibc_reserved4;    
> > 
> > Why does it need the extra reserved fields?  
> 
> I've followed the definition of in-glibc ntptimeval definition in
> sysdeps/unix/sysv/linux/sys/timex.h
> 
> As the __ntptimeval64 is not passed to the kernel (it gets its values
> based on struct __timex64), IMHO it would be safe to remove them.

Those fields are present and cleared in the legacy ntptimeval
structure exported to user programs. To avoid any odd regressions (who
knows how this is used in the legacy code) and to facilitate the
conversion to 64 bit time - I do think that the new struct
__ntptimeval64 shall have those as well.

> 
> >   
> > > +};
> > >  #  endif
> > >  
> > >  /* Convert a known valid struct timex into a struct __timex64.
> > > */ 
> 
> 
> 
> 
> 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




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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-05-07 18:32 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 13:31 [PATCH 00/10] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
2020-04-26 13:31 ` [PATCH 01/10] y2038: include: Move struct __timeval64 definition to a separate file Lukasz Majewski
2020-04-27 15:18   ` Alistair Francis
2020-04-28 14:24   ` Adhemerval Zanella
2020-04-26 13:31 ` [PATCH 02/10] y2038: Introduce struct __timex64 - new internal glibc type Lukasz Majewski
2020-04-27 15:22   ` Alistair Francis
2020-04-28 14:34   ` Adhemerval Zanella
2020-04-29 21:45     ` Lukasz Majewski
2020-04-26 13:31 ` [PATCH 03/10] y2038: Provide conversion helpers for struct __timex64 Lukasz Majewski
2020-04-27 15:22   ` Alistair Francis
2020-04-28 15:56   ` Adhemerval Zanella
2020-04-26 13:31 ` [PATCH 04/10] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
2020-04-27 22:12   ` Alistair Francis
2020-04-28 17:00   ` Adhemerval Zanella
2020-04-29 21:43     ` Lukasz Majewski
2020-04-26 13:31 ` [PATCH 05/10] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
2020-04-27 22:12   ` Alistair Francis
2020-04-28 17:14   ` Adhemerval Zanella
2020-04-26 13:31 ` [PATCH 06/10] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
2020-04-27 22:14   ` Alistair Francis
2020-04-28 18:33   ` Adhemerval Zanella
2020-04-26 13:31 ` [PATCH 07/10] y2038: Introduce struct __ntptimeval64 - new internal glibc type Lukasz Majewski
2020-04-28 18:41   ` Adhemerval Zanella
2020-04-29 21:28     ` Lukasz Majewski
2020-05-07 18:32       ` Lukasz Majewski
2020-04-26 13:31 ` [PATCH 08/10] y2038: Provide conversion helpers for struct __ntptimeval64 Lukasz Majewski
2020-04-26 13:31 ` [PATCH 09/10] y2038: linux: Provide __ntp_gettime64 implementation Lukasz Majewski
2020-04-26 13:31 ` [PATCH 10/10] y2038: linux: Provide __ntp_gettimex64 implementation Lukasz Majewski

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 read-only IMAP folder(s) and NNTP newsgroup(s).