linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/23] y2038 cleanups
@ 2019-11-08 21:02 Arnd Bergmann
  2019-11-08 21:07 ` [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval Arnd Bergmann
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:02 UTC (permalink / raw)
  To: y2038
  Cc: linux-aio, linux-ia64, peterz, heiko.carstens, linux-mips,
	netdev, deepa.kernel, sparclinux, vincenzo.frascino, will,
	linux-arch, paul, deller, x86, sds, Arnd Bergmann, selinux,
	jdike, linux-alpha, linux-um, rostedt, john.stultz, viro, eparis,
	tglx, christian, rth, tony.luck, linux-parisc, sboyd, linux-api,
	linux-kernel, paul.burton, bcrl, ebiederm, richard,
	linux-fsdevel, linuxppc-dev, davem, green.hu

This is a series of cleanups for the y2038 work, mostly intended
for namespace cleaning: the kernel defines the traditional
time_t, timeval and timespec types that often lead to y2038-unsafe
code. Even though the unsafe usage is mostly gone from the kernel,
having the types and associated functions around means that we
can still grow new users, and that we may be missing conversions
to safe types that actually matter.

As there is no rush on any of these patches, I would either
queue them up in linux-next through my y2038 branch, or
Thomas could add them to the tip tree if he wants.

As mentioned in another series, this is part of a larger
effort to fix all the remaining bits and pieces that are
not completed yet from the y2038 conversion, and the full
set can be found at:

https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=y2038-endgame

Maintainers, please review and provide Acks.

Let me know if you have any opinion on whether we should do
the include last two patches of this series or not.

     Arnd

Arnd Bergmann (23):
  y2038: remove CONFIG_64BIT_TIME
  y2038: add __kernel_old_timespec and __kernel_old_time_t
  y2038: vdso: change timeval to __kernel_old_timeval
  y2038: vdso: change timespec to __kernel_old_timespec
  y2038: vdso: change time_t to __kernel_old_time_t
  y2038: vdso: nds32: open-code timespec_add_ns()
  y2038: vdso: powerpc: avoid timespec references
  y2038: ipc: remove __kernel_time_t reference from headers
  y2038: stat: avoid 'time_t' in 'struct stat'
  y2038: uapi: change __kernel_time_t to __kernel_old_time_t
  y2038: rusage: use __kernel_old_timeval
  y2038: syscalls: change remaining timeval to __kernel_old_timeval
  y2038: socket: remove timespec reference in timestamping
  y2038: make ns_to_compat_timeval use __kernel_old_timeval
  y2038: elfcore: Use __kernel_old_timeval for process times
  y2038: timerfd: Use timespec64 internally
  y2038: time: avoid timespec usage in settimeofday()
  y2038: itimer: compat handling to itimer.c
  y2038: use compat_{get,set}_itimer on alpha
  y2038: move itimer reset into itimer.c
  y2038: itimer: change implementation to timespec64
  [RFC] y2038: itimer: use ktime_t internally
  y2038: allow disabling time32 system calls

 arch/Kconfig                              |  11 +-
 arch/alpha/kernel/osf_sys.c               |  67 +-----
 arch/alpha/kernel/syscalls/syscall.tbl    |   4 +-
 arch/ia64/kernel/asm-offsets.c            |   2 +-
 arch/mips/include/uapi/asm/msgbuf.h       |   6 +-
 arch/mips/include/uapi/asm/sembuf.h       |   4 +-
 arch/mips/include/uapi/asm/shmbuf.h       |   6 +-
 arch/mips/include/uapi/asm/stat.h         |  16 +-
 arch/mips/kernel/binfmt_elfn32.c          |   4 +-
 arch/mips/kernel/binfmt_elfo32.c          |   4 +-
 arch/nds32/kernel/vdso/gettimeofday.c     |  61 +++--
 arch/parisc/include/uapi/asm/msgbuf.h     |   6 +-
 arch/parisc/include/uapi/asm/sembuf.h     |   4 +-
 arch/parisc/include/uapi/asm/shmbuf.h     |   6 +-
 arch/powerpc/include/asm/asm-prototypes.h |   3 +-
 arch/powerpc/include/asm/vdso_datapage.h  |   6 +-
 arch/powerpc/include/uapi/asm/msgbuf.h    |   6 +-
 arch/powerpc/include/uapi/asm/sembuf.h    |   4 +-
 arch/powerpc/include/uapi/asm/shmbuf.h    |   6 +-
 arch/powerpc/include/uapi/asm/stat.h      |   2 +-
 arch/powerpc/kernel/asm-offsets.c         |  18 +-
 arch/powerpc/kernel/syscalls.c            |   4 +-
 arch/powerpc/kernel/time.c                |   5 +-
 arch/powerpc/kernel/vdso32/gettimeofday.S |   6 +-
 arch/powerpc/kernel/vdso64/gettimeofday.S |   8 +-
 arch/sparc/include/uapi/asm/msgbuf.h      |   6 +-
 arch/sparc/include/uapi/asm/sembuf.h      |   4 +-
 arch/sparc/include/uapi/asm/shmbuf.h      |   6 +-
 arch/sparc/include/uapi/asm/stat.h        |  24 +-
 arch/sparc/vdso/vclock_gettime.c          |  36 +--
 arch/x86/entry/vdso/vclock_gettime.c      |   6 +-
 arch/x86/entry/vsyscall/vsyscall_64.c     |   4 +-
 arch/x86/include/uapi/asm/msgbuf.h        |   6 +-
 arch/x86/include/uapi/asm/sembuf.h        |   4 +-
 arch/x86/include/uapi/asm/shmbuf.h        |   6 +-
 arch/x86/um/vdso/um_vdso.c                |  12 +-
 fs/aio.c                                  |   2 +-
 fs/binfmt_elf.c                           |  12 +-
 fs/binfmt_elf_fdpic.c                     |  12 +-
 fs/compat_binfmt_elf.c                    |   4 +-
 fs/select.c                               |  10 +-
 fs/timerfd.c                              |  14 +-
 fs/utimes.c                               |   8 +-
 include/linux/compat.h                    |  19 +-
 include/linux/syscalls.h                  |  16 +-
 include/linux/time.h                      |   9 +-
 include/linux/time32.h                    |   2 +-
 include/linux/types.h                     |   2 +-
 include/trace/events/timer.h              |  29 +--
 include/uapi/asm-generic/msgbuf.h         |  12 +-
 include/uapi/asm-generic/posix_types.h    |   1 +
 include/uapi/asm-generic/sembuf.h         |   7 +-
 include/uapi/asm-generic/shmbuf.h         |  12 +-
 include/uapi/linux/cyclades.h             |   6 +-
 include/uapi/linux/elfcore.h              |   8 +-
 include/uapi/linux/errqueue.h             |   7 +
 include/uapi/linux/msg.h                  |   6 +-
 include/uapi/linux/ppp_defs.h             |   4 +-
 include/uapi/linux/resource.h             |   4 +-
 include/uapi/linux/sem.h                  |   4 +-
 include/uapi/linux/shm.h                  |   6 +-
 include/uapi/linux/time.h                 |   6 +-
 include/uapi/linux/time_types.h           |   5 +
 include/uapi/linux/utime.h                |   4 +-
 ipc/syscall.c                             |   2 +-
 kernel/compat.c                           |  24 --
 kernel/power/power.h                      |   2 +-
 kernel/sys.c                              |   4 +-
 kernel/sys_ni.c                           |  23 ++
 kernel/time/hrtimer.c                     |   2 +-
 kernel/time/itimer.c                      | 280 ++++++++++++++--------
 kernel/time/time.c                        |  32 ++-
 lib/vdso/gettimeofday.c                   |   4 +-
 net/core/scm.c                            |   6 +-
 net/socket.c                              |   2 +-
 security/selinux/hooks.c                  |  10 +-
 76 files changed, 501 insertions(+), 504 deletions(-)

-- 
2.20.0

Cc: rth@twiddle.net
Cc: tony.luck@intel.com
Cc: paul.burton@mips.com
Cc: green.hu@gmail.com
Cc: deller@gmx.de
Cc: mpe@ellerman.id.au
Cc: davem@davemloft.net
Cc: tglx@linutronix.de
Cc: x86@kernel.org
Cc: jdike@addtoit.com
Cc: richard@nod.at
Cc: viro@zeniv.linux.org.uk
Cc: bcrl@kvack.org
Cc: john.stultz@linaro.org
Cc: sboyd@kernel.org
Cc: rostedt@goodmis.org
Cc: arnd@arndb.de
Cc: vincenzo.frascino@arm.com
Cc: paul@paul-moore.com
Cc: sds@tycho.nsa.gov
Cc: eparis@parisplace.org
Cc: peterz@infradead.org
Cc: will@kernel.org
Cc: deepa.kernel@gmail.com
Cc: christian@brauner.io
Cc: heiko.carstens@de.ibm.com
Cc: christophe.leroy@c-s.fr
Cc: ebiederm@xmission.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-alpha@vger.kernel.org>
Cc: linux-ia64@vger.kernel.org>
Cc: linux-mips@vger.kernel.org>
Cc: linux-parisc@vger.kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org>
Cc: sparclinux@vger.kernel.org>
Cc: linux-um@lists.infradead.org>
Cc: linux-fsdevel@vger.kernel.org>
Cc: linux-aio@kvack.org>
Cc: linux-api@vger.kernel.org>
Cc: linux-arch@vger.kernel.org>
Cc: netdev@vger.kernel.org>
Cc: selinux@vger.kernel.org>


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

* [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
@ 2019-11-08 21:07 ` Arnd Bergmann
  2019-11-13 21:56   ` Thomas Gleixner
  2019-11-08 21:07 ` [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references Arnd Bergmann
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:07 UTC (permalink / raw)
  To: y2038, Greentime Hu, Vincent Chen, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, David S. Miller,
	Andy Lutomirski, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	x86, Jeff Dike, Richard Weinberger, Anton Ivanov
  Cc: Arnd Bergmann, linux-um, linux-kernel, Eric W. Biederman,
	H. Peter Anvin, sparclinux, Vincenzo Frascino, linuxppc-dev

The gettimeofday() function in vdso uses the traditional 'timeval'
structure layout, which will be incompatible with future versions of
glibc on 32-bit architectures that use a 64-bit time_t.

This interface is problematic for y2038, when time_t overflows on 32-bit
architectures, but the plan so far is that a libc with 64-bit time_t
will not call into the gettimeofday() vdso helper at all, and only
have a method for entering clock_gettime().  This means we don't have
to fix it here, though we probably want to add a new clock_gettime()
entry point using a 64-bit version of 'struct timespec' at some point.

Changing the vdso code to use __kernel_old_timeval helps isolate
this usage from the other ones that still need to be fixed properly,
and it gets us closer to removing the 'timeval' definition from the
kernel sources.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/nds32/kernel/vdso/gettimeofday.c |  6 +++---
 arch/powerpc/kernel/asm-offsets.c     |  8 ++++----
 arch/sparc/vdso/vclock_gettime.c      | 12 ++++++------
 arch/x86/entry/vsyscall/vsyscall_64.c |  2 +-
 arch/x86/um/vdso/um_vdso.c            |  4 ++--
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/nds32/kernel/vdso/gettimeofday.c b/arch/nds32/kernel/vdso/gettimeofday.c
index b02581891c33..1e69fd5b067b 100644
--- a/arch/nds32/kernel/vdso/gettimeofday.c
+++ b/arch/nds32/kernel/vdso/gettimeofday.c
@@ -230,10 +230,10 @@ notrace int __vdso_clock_getres(clockid_t clk_id, struct timespec *res)
 	return 0;
 }
 
-static notrace inline int gettimeofday_fallback(struct timeval *_tv,
+static notrace inline int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
 						struct timezone *_tz)
 {
-	register struct timeval *tv asm("$r0") = _tv;
+	register struct __kernel_old_timeval *tv asm("$r0") = _tv;
 	register struct timezone *tz asm("$r1") = _tz;
 	register int ret asm("$r0");
 
@@ -246,7 +246,7 @@ static notrace inline int gettimeofday_fallback(struct timeval *_tv,
 	return ret;
 }
 
-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+notrace int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	struct timespec ts;
 	struct vdso_data *vdata;
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 484f54dab247..827f4c354e13 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -393,8 +393,8 @@ int main(void)
 	OFFSET(CFG_DCACHE_LOGBLOCKSZ, vdso_data, dcache_log_block_size);
 #ifdef CONFIG_PPC64
 	OFFSET(CFG_SYSCALL_MAP64, vdso_data, syscall_map_64);
-	OFFSET(TVAL64_TV_SEC, timeval, tv_sec);
-	OFFSET(TVAL64_TV_USEC, timeval, tv_usec);
+	OFFSET(TVAL64_TV_SEC, __kernel_old_timeval, tv_sec);
+	OFFSET(TVAL64_TV_USEC, __kernel_old_timeval, tv_usec);
 	OFFSET(TVAL32_TV_SEC, old_timeval32, tv_sec);
 	OFFSET(TVAL32_TV_USEC, old_timeval32, tv_usec);
 	OFFSET(TSPC64_TV_SEC, timespec, tv_sec);
@@ -402,8 +402,8 @@ int main(void)
 	OFFSET(TSPC32_TV_SEC, old_timespec32, tv_sec);
 	OFFSET(TSPC32_TV_NSEC, old_timespec32, tv_nsec);
 #else
-	OFFSET(TVAL32_TV_SEC, timeval, tv_sec);
-	OFFSET(TVAL32_TV_USEC, timeval, tv_usec);
+	OFFSET(TVAL32_TV_SEC, __kernel_old_timeval, tv_sec);
+	OFFSET(TVAL32_TV_USEC, __kernel_old_timeval, tv_usec);
 	OFFSET(TSPC32_TV_SEC, timespec, tv_sec);
 	OFFSET(TSPC32_TV_NSEC, timespec, tv_nsec);
 #endif
diff --git a/arch/sparc/vdso/vclock_gettime.c b/arch/sparc/vdso/vclock_gettime.c
index fc5bdd14de76..a20c5030578d 100644
--- a/arch/sparc/vdso/vclock_gettime.c
+++ b/arch/sparc/vdso/vclock_gettime.c
@@ -74,7 +74,7 @@ notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 	return o0;
 }
 
-notrace static long vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
+notrace static long vdso_fallback_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	register long num __asm__("g1") = __NR_gettimeofday;
 	register long o0 __asm__("o0") = (long) tv;
@@ -304,7 +304,7 @@ __vdso_clock_gettime_stick(clockid_t clock, struct timespec *ts)
 }
 
 notrace int
-__vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+__vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	struct vvar_data *vvd = get_vvar_data();
 
@@ -312,7 +312,7 @@ __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
 		if (likely(tv != NULL)) {
 			union tstv_t {
 				struct timespec ts;
-				struct timeval tv;
+				struct __kernel_old_timeval tv;
 			} *tstv = (union tstv_t *) tv;
 			do_realtime(vvd, &tstv->ts);
 			/*
@@ -336,11 +336,11 @@ __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
 	return vdso_fallback_gettimeofday(tv, tz);
 }
 int
-gettimeofday(struct timeval *, struct timezone *)
+gettimeofday(struct __kernel_old_timeval *, struct timezone *)
 	__attribute__((weak, alias("__vdso_gettimeofday")));
 
 notrace int
-__vdso_gettimeofday_stick(struct timeval *tv, struct timezone *tz)
+__vdso_gettimeofday_stick(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	struct vvar_data *vvd = get_vvar_data();
 
@@ -348,7 +348,7 @@ __vdso_gettimeofday_stick(struct timeval *tv, struct timezone *tz)
 		if (likely(tv != NULL)) {
 			union tstv_t {
 				struct timespec ts;
-				struct timeval tv;
+				struct __kernel_old_timeval tv;
 			} *tstv = (union tstv_t *) tv;
 			do_realtime_stick(vvd, &tstv->ts);
 			/*
diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c
index e7c596dea947..76e62bcb8d87 100644
--- a/arch/x86/entry/vsyscall/vsyscall_64.c
+++ b/arch/x86/entry/vsyscall/vsyscall_64.c
@@ -184,7 +184,7 @@ bool emulate_vsyscall(unsigned long error_code,
 	 */
 	switch (vsyscall_nr) {
 	case 0:
-		if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) ||
+		if (!write_ok_or_segv(regs->di, sizeof(struct __kernel_old_timeval)) ||
 		    !write_ok_or_segv(regs->si, sizeof(struct timezone))) {
 			ret = -EFAULT;
 			goto check_fault;
diff --git a/arch/x86/um/vdso/um_vdso.c b/arch/x86/um/vdso/um_vdso.c
index 891868756a51..845336c11364 100644
--- a/arch/x86/um/vdso/um_vdso.c
+++ b/arch/x86/um/vdso/um_vdso.c
@@ -25,7 +25,7 @@ int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
 int clock_gettime(clockid_t, struct timespec *)
 	__attribute__((weak, alias("__vdso_clock_gettime")));
 
-int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	long ret;
 
@@ -34,7 +34,7 @@ int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
 
 	return ret;
 }
-int gettimeofday(struct timeval *, struct timezone *)
+int gettimeofday(struct __kernel_old_timeval *, struct timezone *)
 	__attribute__((weak, alias("__vdso_gettimeofday")));
 
 time_t __vdso_time(time_t *t)
-- 
2.20.0


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

* [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
  2019-11-08 21:07 ` [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval Arnd Bergmann
@ 2019-11-08 21:07 ` Arnd Bergmann
  2019-11-20 22:43   ` [Y2038] " Ben Hutchings
  2019-11-08 21:07 ` [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers Arnd Bergmann
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:07 UTC (permalink / raw)
  To: y2038, Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, Nicholas Piggin,
	Thomas Gleixner, linuxppc-dev, Allison Randal

As a preparation to stop using 'struct timespec' in the kernel,
change the powerpc vdso implementation:

- split up the vdso data definition to have equivalent members
   for seconds and nanoseconds instead of an xtime structure

- use timespec64 as an intermediate for the xtime update

- change the asm-offsets definition to be based the appropriate
  fixed-length types

This is only a temporary fix for changing the types, in order
to actually support a 64-bit safe vdso32 version of clock_gettime(),
the entire powerpc vdso should be replaced with the generic
lib/vdso/ implementation. If that happens first, this patch
becomes obsolete.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/powerpc/include/asm/vdso_datapage.h  |  6 ++++--
 arch/powerpc/kernel/asm-offsets.c         | 14 +++++---------
 arch/powerpc/kernel/time.c                |  5 +++--
 arch/powerpc/kernel/vdso32/gettimeofday.S |  6 ++----
 arch/powerpc/kernel/vdso64/gettimeofday.S |  8 ++++----
 5 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/vdso_datapage.h b/arch/powerpc/include/asm/vdso_datapage.h
index c61d59ed3b45..a115970a6809 100644
--- a/arch/powerpc/include/asm/vdso_datapage.h
+++ b/arch/powerpc/include/asm/vdso_datapage.h
@@ -81,7 +81,8 @@ struct vdso_data {
 	__u32 stamp_sec_fraction;		/* fractional seconds of stamp_xtime */
 	__s32 wtom_clock_nsec;			/* Wall to monotonic clock nsec */
 	__s64 wtom_clock_sec;			/* Wall to monotonic clock sec */
-	struct timespec stamp_xtime;		/* xtime as at tb_orig_stamp */
+	__s64 stamp_xtime_sec;			/* xtime secs as at tb_orig_stamp */
+	__s64 stamp_xtime_nsec;			/* xtime nsecs as at tb_orig_stamp */
    	__u32 syscall_map_64[SYSCALL_MAP_SIZE]; /* map of syscalls  */
    	__u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
 };
@@ -101,7 +102,8 @@ struct vdso_data {
 	__u32 tz_dsttime;		/* Type of dst correction	0x5C */
 	__s32 wtom_clock_sec;			/* Wall to monotonic clock */
 	__s32 wtom_clock_nsec;
-	struct timespec stamp_xtime;	/* xtime as at tb_orig_stamp */
+	__s32 stamp_xtime_sec;		/* xtime seconds as at tb_orig_stamp */
+	__s32 stamp_xtime_nsec;		/* xtime nsecs as at tb_orig_stamp */
 	__u32 stamp_sec_fraction;	/* fractional seconds of stamp_xtime */
    	__u32 syscall_map_32[SYSCALL_MAP_SIZE]; /* map of syscalls */
 	__u32 dcache_block_size;	/* L1 d-cache block size     */
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 827f4c354e13..f22bd6d1fe93 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -385,7 +385,8 @@ int main(void)
 	OFFSET(CFG_SYSCALL_MAP32, vdso_data, syscall_map_32);
 	OFFSET(WTOM_CLOCK_SEC, vdso_data, wtom_clock_sec);
 	OFFSET(WTOM_CLOCK_NSEC, vdso_data, wtom_clock_nsec);
-	OFFSET(STAMP_XTIME, vdso_data, stamp_xtime);
+	OFFSET(STAMP_XTIME_SEC, vdso_data, stamp_xtime_sec);
+	OFFSET(STAMP_XTIME_NSEC, vdso_data, stamp_xtime_nsec);
 	OFFSET(STAMP_SEC_FRAC, vdso_data, stamp_sec_fraction);
 	OFFSET(CFG_ICACHE_BLOCKSZ, vdso_data, icache_block_size);
 	OFFSET(CFG_DCACHE_BLOCKSZ, vdso_data, dcache_block_size);
@@ -395,18 +396,13 @@ int main(void)
 	OFFSET(CFG_SYSCALL_MAP64, vdso_data, syscall_map_64);
 	OFFSET(TVAL64_TV_SEC, __kernel_old_timeval, tv_sec);
 	OFFSET(TVAL64_TV_USEC, __kernel_old_timeval, tv_usec);
+#endif
+	OFFSET(TSPC64_TV_SEC, __kernel_timespec, tv_sec);
+	OFFSET(TSPC64_TV_NSEC, __kernel_timespec, tv_nsec);
 	OFFSET(TVAL32_TV_SEC, old_timeval32, tv_sec);
 	OFFSET(TVAL32_TV_USEC, old_timeval32, tv_usec);
-	OFFSET(TSPC64_TV_SEC, timespec, tv_sec);
-	OFFSET(TSPC64_TV_NSEC, timespec, tv_nsec);
 	OFFSET(TSPC32_TV_SEC, old_timespec32, tv_sec);
 	OFFSET(TSPC32_TV_NSEC, old_timespec32, tv_nsec);
-#else
-	OFFSET(TVAL32_TV_SEC, __kernel_old_timeval, tv_sec);
-	OFFSET(TVAL32_TV_USEC, __kernel_old_timeval, tv_usec);
-	OFFSET(TSPC32_TV_SEC, timespec, tv_sec);
-	OFFSET(TSPC32_TV_NSEC, timespec, tv_nsec);
-#endif
 	/* timeval/timezone offsets for use by vdso */
 	OFFSET(TZONE_TZ_MINWEST, timezone, tz_minuteswest);
 	OFFSET(TZONE_TZ_DSTTIME, timezone, tz_dsttime);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 694522308cd5..1fad5a04d083 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -885,7 +885,7 @@ static notrace u64 timebase_read(struct clocksource *cs)
 
 void update_vsyscall(struct timekeeper *tk)
 {
-	struct timespec xt;
+	struct timespec64 xt;
 	struct clocksource *clock = tk->tkr_mono.clock;
 	u32 mult = tk->tkr_mono.mult;
 	u32 shift = tk->tkr_mono.shift;
@@ -957,7 +957,8 @@ void update_vsyscall(struct timekeeper *tk)
 	vdso_data->tb_to_xs = new_tb_to_xs;
 	vdso_data->wtom_clock_sec = tk->wall_to_monotonic.tv_sec;
 	vdso_data->wtom_clock_nsec = tk->wall_to_monotonic.tv_nsec;
-	vdso_data->stamp_xtime = xt;
+	vdso_data->stamp_xtime_sec = xt.sec;
+	vdso_data->stamp_xtime_nsec = xt.nsec;
 	vdso_data->stamp_sec_fraction = frac_sec;
 	smp_wmb();
 	++(vdso_data->tb_update_count);
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S
index 4327665ad86f..37ba4c3d965b 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -15,10 +15,8 @@
 /* Offset for the low 32-bit part of a field of long type */
 #if defined(CONFIG_PPC64) && defined(CONFIG_CPU_BIG_ENDIAN)
 #define LOPART	4
-#define TSPEC_TV_SEC	TSPC64_TV_SEC+LOPART
 #else
 #define LOPART	0
-#define TSPEC_TV_SEC	TSPC32_TV_SEC
 #endif
 
 	.text
@@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
 	bl	__get_datapage@local
 	mr	r9, r3			/* datapage ptr in r9 */
 
-	lwz	r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
+	lwz	r3,STAMP_XTIME_SEC+LOWPART(r9)
 
 	cmplwi	r11,0			/* check if t is NULL */
 	beq	2f
@@ -268,7 +266,7 @@ __do_get_tspec:
 	 * as a 32.32 fixed-point number in r3 and r4.
 	 * Load & add the xtime stamp.
 	 */
-	lwz	r5,STAMP_XTIME+TSPEC_TV_SEC(r9)
+	lwz	r5,STAMP_XTIME_SEC+LOWPART(r9)
 	lwz	r6,STAMP_SEC_FRAC(r9)
 	addc	r4,r4,r6
 	adde	r3,r3,r5
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S
index 07bfe33fe874..1f24e411af80 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -116,8 +116,8 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	 * CLOCK_REALTIME_COARSE, below values are needed for MONOTONIC_COARSE
 	 * too
 	 */
-	ld      r4,STAMP_XTIME+TSPC64_TV_SEC(r3)
-	ld      r5,STAMP_XTIME+TSPC64_TV_NSEC(r3)
+	ld      r4,STAMP_XTIME_SEC(r3)
+	ld      r5,STAMP_XTIME_NSEC(r3)
 	bne     cr6,75f
 
 	/* CLOCK_MONOTONIC_COARSE */
@@ -220,7 +220,7 @@ V_FUNCTION_BEGIN(__kernel_time)
 	mr	r11,r3			/* r11 holds t */
 	bl	V_LOCAL_FUNC(__get_datapage)
 
-	ld	r4,STAMP_XTIME+TSPC64_TV_SEC(r3)
+	ld	r4,STAMP_XTIME_SEC(r3)
 
 	cmpldi	r11,0			/* check if t is NULL */
 	beq	2f
@@ -265,7 +265,7 @@ V_FUNCTION_BEGIN(__do_get_tspec)
 	mulhdu	r6,r6,r5		/* in units of 2^-32 seconds */
 
 	/* Add stamp since epoch */
-	ld	r4,STAMP_XTIME+TSPC64_TV_SEC(r3)
+	ld	r4,STAMP_XTIME_SEC(r3)
 	lwz	r5,STAMP_SEC_FRAC(r3)
 	or	r0,r4,r5
 	or	r0,r0,r6
-- 
2.20.0


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

* [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
  2019-11-08 21:07 ` [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval Arnd Bergmann
  2019-11-08 21:07 ` [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references Arnd Bergmann
@ 2019-11-08 21:07 ` Arnd Bergmann
  2019-11-20 22:49   ` [Y2038] " Ben Hutchings
  2019-11-08 21:07 ` [PATCH 09/23] y2038: stat: avoid 'time_t' in 'struct stat' Arnd Bergmann
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:07 UTC (permalink / raw)
  To: y2038, Ralf Baechle, Paul Burton, James Hogan,
	James E.J. Bottomley, Helge Deller, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, David S. Miller,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	Arnd Bergmann
  Cc: linux-arch, linux-parisc, linux-mips, linux-kernel,
	H. Peter Anvin, sparclinux, linuxppc-dev

There are two structures based on time_t that conflict between libc and
kernel: timeval and timespec. Both are now renamed to __kernel_old_timeval
and __kernel_old_timespec.

For time_t, the old typedef is still __kernel_time_t. There is nothing
wrong with that name, but it would be nice to not use that going forward
as this type is used almost only in deprecated interfaces because of
the y2038 overflow.

In the IPC headers (msgbuf.h, sembuf.h, shmbuf.h), __kernel_time_t is only
used for the 64-bit variants, which are not deprecated.

Change these to a plain 'long', which is the same type as __kernel_time_t
on all 64-bit architectures anyway, to reduce the number of users of the
old type.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/mips/include/uapi/asm/msgbuf.h    |  6 +++---
 arch/mips/include/uapi/asm/sembuf.h    |  4 ++--
 arch/mips/include/uapi/asm/shmbuf.h    |  6 +++---
 arch/parisc/include/uapi/asm/msgbuf.h  |  6 +++---
 arch/parisc/include/uapi/asm/sembuf.h  |  4 ++--
 arch/parisc/include/uapi/asm/shmbuf.h  |  6 +++---
 arch/powerpc/include/uapi/asm/msgbuf.h |  6 +++---
 arch/powerpc/include/uapi/asm/sembuf.h |  4 ++--
 arch/powerpc/include/uapi/asm/shmbuf.h |  6 +++---
 arch/sparc/include/uapi/asm/msgbuf.h   |  6 +++---
 arch/sparc/include/uapi/asm/sembuf.h   |  4 ++--
 arch/sparc/include/uapi/asm/shmbuf.h   |  6 +++---
 arch/x86/include/uapi/asm/msgbuf.h     |  6 +++---
 arch/x86/include/uapi/asm/sembuf.h     |  4 ++--
 arch/x86/include/uapi/asm/shmbuf.h     |  6 +++---
 include/uapi/asm-generic/msgbuf.h      | 12 ++++++------
 include/uapi/asm-generic/sembuf.h      |  7 +++----
 include/uapi/asm-generic/shmbuf.h      | 12 ++++++------
 18 files changed, 55 insertions(+), 56 deletions(-)

diff --git a/arch/mips/include/uapi/asm/msgbuf.h b/arch/mips/include/uapi/asm/msgbuf.h
index 46aa15b13e4e..9e0c2e230274 100644
--- a/arch/mips/include/uapi/asm/msgbuf.h
+++ b/arch/mips/include/uapi/asm/msgbuf.h
@@ -15,9 +15,9 @@
 #if defined(__mips64)
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	long msg_stime;			/* last msgsnd time */
+	long msg_rtime;			/* last msgrcv time */
+	long msg_ctime;			/* last change time */
 	unsigned long  msg_cbytes;	/* current number of bytes on queue */
 	unsigned long  msg_qnum;	/* number of messages in queue */
 	unsigned long  msg_qbytes;	/* max number of bytes on queue */
diff --git a/arch/mips/include/uapi/asm/sembuf.h b/arch/mips/include/uapi/asm/sembuf.h
index 60c89e6cb25b..43e1b4a2f68a 100644
--- a/arch/mips/include/uapi/asm/sembuf.h
+++ b/arch/mips/include/uapi/asm/sembuf.h
@@ -14,8 +14,8 @@
 #ifdef __mips64
 struct semid64_ds {
 	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
-	__kernel_time_t sem_otime;		/* last semop time */
-	__kernel_time_t sem_ctime;		/* last change time */
+	long		 sem_otime;		/* last semop time */
+	long		 sem_ctime;		/* last change time */
 	unsigned long	sem_nsems;		/* no. of semaphores in array */
 	unsigned long	__unused1;
 	unsigned long	__unused2;
diff --git a/arch/mips/include/uapi/asm/shmbuf.h b/arch/mips/include/uapi/asm/shmbuf.h
index 9b9bba3401f2..680bb95b2240 100644
--- a/arch/mips/include/uapi/asm/shmbuf.h
+++ b/arch/mips/include/uapi/asm/shmbuf.h
@@ -17,9 +17,9 @@
 struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 	size_t			shm_segsz;	/* size of segment (bytes) */
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	long			shm_atime;	/* last attach time */
+	long			shm_dtime;	/* last detach time */
+	long			shm_ctime;	/* last change time */
 	__kernel_pid_t		shm_cpid;	/* pid of creator */
 	__kernel_pid_t		shm_lpid;	/* pid of last operator */
 	unsigned long		shm_nattch;	/* no. of current attaches */
diff --git a/arch/parisc/include/uapi/asm/msgbuf.h b/arch/parisc/include/uapi/asm/msgbuf.h
index 6a2e9ab2ef8d..3b877335da38 100644
--- a/arch/parisc/include/uapi/asm/msgbuf.h
+++ b/arch/parisc/include/uapi/asm/msgbuf.h
@@ -16,9 +16,9 @@
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
 #if __BITS_PER_LONG == 64
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	long		 msg_stime;	/* last msgsnd time */
+	long		 msg_rtime;	/* last msgrcv time */
+	long		 msg_ctime;	/* last change time */
 #else
 	unsigned long	msg_stime_high;
 	unsigned long	msg_stime;	/* last msgsnd time */
diff --git a/arch/parisc/include/uapi/asm/sembuf.h b/arch/parisc/include/uapi/asm/sembuf.h
index 3c31163b1241..8241cf126018 100644
--- a/arch/parisc/include/uapi/asm/sembuf.h
+++ b/arch/parisc/include/uapi/asm/sembuf.h
@@ -16,8 +16,8 @@
 struct semid64_ds {
 	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
 #if __BITS_PER_LONG == 64
-	__kernel_time_t	sem_otime;		/* last semop time */
-	__kernel_time_t	sem_ctime;		/* last change time */
+	long		sem_otime;		/* last semop time */
+	long		sem_ctime;		/* last change time */
 #else
 	unsigned long	sem_otime_high;
 	unsigned long	sem_otime;		/* last semop time */
diff --git a/arch/parisc/include/uapi/asm/shmbuf.h b/arch/parisc/include/uapi/asm/shmbuf.h
index c89b3dd8db21..5da3089be65e 100644
--- a/arch/parisc/include/uapi/asm/shmbuf.h
+++ b/arch/parisc/include/uapi/asm/shmbuf.h
@@ -16,9 +16,9 @@
 struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 #if __BITS_PER_LONG == 64
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	long			shm_atime;	/* last attach time */
+	long			shm_dtime;	/* last detach time */
+	long			shm_ctime;	/* last change time */
 #else
 	unsigned long		shm_atime_high;
 	unsigned long		shm_atime;	/* last attach time */
diff --git a/arch/powerpc/include/uapi/asm/msgbuf.h b/arch/powerpc/include/uapi/asm/msgbuf.h
index 2b1b37797a47..969bd83e4d3d 100644
--- a/arch/powerpc/include/uapi/asm/msgbuf.h
+++ b/arch/powerpc/include/uapi/asm/msgbuf.h
@@ -11,9 +11,9 @@
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
 #ifdef __powerpc64__
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	long		 msg_stime;	/* last msgsnd time */
+	long		 msg_rtime;	/* last msgrcv time */
+	long		 msg_ctime;	/* last change time */
 #else
 	unsigned long  msg_stime_high;
 	unsigned long  msg_stime;	/* last msgsnd time */
diff --git a/arch/powerpc/include/uapi/asm/sembuf.h b/arch/powerpc/include/uapi/asm/sembuf.h
index 3f60946f77e3..008ae77c6746 100644
--- a/arch/powerpc/include/uapi/asm/sembuf.h
+++ b/arch/powerpc/include/uapi/asm/sembuf.h
@@ -26,8 +26,8 @@ struct semid64_ds {
 	unsigned long	sem_ctime_high;
 	unsigned long	sem_ctime;	/* last change time */
 #else
-	__kernel_time_t	sem_otime;	/* last semop time */
-	__kernel_time_t	sem_ctime;	/* last change time */
+	long		sem_otime;	/* last semop time */
+	long		sem_ctime;	/* last change time */
 #endif
 	unsigned long	sem_nsems;	/* no. of semaphores in array */
 	unsigned long	__unused3;
diff --git a/arch/powerpc/include/uapi/asm/shmbuf.h b/arch/powerpc/include/uapi/asm/shmbuf.h
index b591c4d7e4c5..00422b2f3c63 100644
--- a/arch/powerpc/include/uapi/asm/shmbuf.h
+++ b/arch/powerpc/include/uapi/asm/shmbuf.h
@@ -22,9 +22,9 @@
 struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 #ifdef __powerpc64__
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	long		shm_atime;	/* last attach time */
+	long		shm_dtime;	/* last detach time */
+	long		shm_ctime;	/* last change time */
 #else
 	unsigned long		shm_atime_high;
 	unsigned long		shm_atime;	/* last attach time */
diff --git a/arch/sparc/include/uapi/asm/msgbuf.h b/arch/sparc/include/uapi/asm/msgbuf.h
index ffc46c211d6d..eeeb91933280 100644
--- a/arch/sparc/include/uapi/asm/msgbuf.h
+++ b/arch/sparc/include/uapi/asm/msgbuf.h
@@ -13,9 +13,9 @@
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
 #if defined(__sparc__) && defined(__arch64__)
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	long msg_stime;			/* last msgsnd time */
+	long msg_rtime;			/* last msgrcv time */
+	long msg_ctime;			/* last change time */
 #else
 	unsigned long msg_stime_high;
 	unsigned long msg_stime;	/* last msgsnd time */
diff --git a/arch/sparc/include/uapi/asm/sembuf.h b/arch/sparc/include/uapi/asm/sembuf.h
index f3d309c2e1cd..cbcbaa4e7128 100644
--- a/arch/sparc/include/uapi/asm/sembuf.h
+++ b/arch/sparc/include/uapi/asm/sembuf.h
@@ -14,8 +14,8 @@
 struct semid64_ds {
 	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
 #if defined(__sparc__) && defined(__arch64__)
-	__kernel_time_t	sem_otime;		/* last semop time */
-	__kernel_time_t	sem_ctime;		/* last change time */
+	long		sem_otime;		/* last semop time */
+	long		sem_ctime;		/* last change time */
 #else
 	unsigned long	sem_otime_high;
 	unsigned long	sem_otime;		/* last semop time */
diff --git a/arch/sparc/include/uapi/asm/shmbuf.h b/arch/sparc/include/uapi/asm/shmbuf.h
index 06618b84822d..a5d7d8d681c4 100644
--- a/arch/sparc/include/uapi/asm/shmbuf.h
+++ b/arch/sparc/include/uapi/asm/shmbuf.h
@@ -14,9 +14,9 @@
 struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 #if defined(__sparc__) && defined(__arch64__)
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	long			shm_atime;	/* last attach time */
+	long			shm_dtime;	/* last detach time */
+	long			shm_ctime;	/* last change time */
 #else
 	unsigned long		shm_atime_high;
 	unsigned long		shm_atime;	/* last attach time */
diff --git a/arch/x86/include/uapi/asm/msgbuf.h b/arch/x86/include/uapi/asm/msgbuf.h
index 90ab9a795b49..7c5bb43ed8af 100644
--- a/arch/x86/include/uapi/asm/msgbuf.h
+++ b/arch/x86/include/uapi/asm/msgbuf.h
@@ -15,9 +15,9 @@
 
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	__kernel_long_t msg_stime;	/* last msgsnd time */
+	__kernel_long_t msg_rtime;	/* last msgrcv time */
+	__kernel_long_t msg_ctime;	/* last change time */
 	__kernel_ulong_t msg_cbytes;	/* current number of bytes on queue */
 	__kernel_ulong_t msg_qnum;	/* number of messages in queue */
 	__kernel_ulong_t msg_qbytes;	/* max number of bytes on queue */
diff --git a/arch/x86/include/uapi/asm/sembuf.h b/arch/x86/include/uapi/asm/sembuf.h
index 89de6cd9f0a7..7c1b156695ba 100644
--- a/arch/x86/include/uapi/asm/sembuf.h
+++ b/arch/x86/include/uapi/asm/sembuf.h
@@ -21,9 +21,9 @@ struct semid64_ds {
 	unsigned long	sem_ctime;	/* last change time */
 	unsigned long	sem_ctime_high;
 #else
-	__kernel_time_t	sem_otime;	/* last semop time */
+	long		sem_otime;	/* last semop time */
 	__kernel_ulong_t __unused1;
-	__kernel_time_t	sem_ctime;	/* last change time */
+	long		sem_ctime;	/* last change time */
 	__kernel_ulong_t __unused2;
 #endif
 	__kernel_ulong_t sem_nsems;	/* no. of semaphores in array */
diff --git a/arch/x86/include/uapi/asm/shmbuf.h b/arch/x86/include/uapi/asm/shmbuf.h
index 644421f3823b..f0305dc660c9 100644
--- a/arch/x86/include/uapi/asm/shmbuf.h
+++ b/arch/x86/include/uapi/asm/shmbuf.h
@@ -16,9 +16,9 @@
 struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 	size_t			shm_segsz;	/* size of segment (bytes) */
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	__kernel_long_t		shm_atime;	/* last attach time */
+	__kernel_long_t		shm_dtime;	/* last detach time */
+	__kernel_long_t		shm_ctime;	/* last change time */
 	__kernel_pid_t		shm_cpid;	/* pid of creator */
 	__kernel_pid_t		shm_lpid;	/* pid of last operator */
 	__kernel_ulong_t	shm_nattch;	/* no. of current attaches */
diff --git a/include/uapi/asm-generic/msgbuf.h b/include/uapi/asm-generic/msgbuf.h
index 9fe4881557cb..af95aa89012e 100644
--- a/include/uapi/asm-generic/msgbuf.h
+++ b/include/uapi/asm-generic/msgbuf.h
@@ -13,9 +13,9 @@
  * everyone just ended up making identical copies without specific
  * optimizations, so we may just as well all use the same one.
  *
- * 64 bit architectures typically define a 64 bit __kernel_time_t,
- * so they do not need the first three padding words.
- * On big-endian systems, the padding is in the wrong place.
+ * 64 bit architectures use a 64-bit long time field here, while
+ * 32 bit architectures have a pair of unsigned long values.
+ * On big-endian systems, the lower half is in the wrong place.
  *
  * Pad space is left for:
  * - 2 miscellaneous 32-bit values
@@ -24,9 +24,9 @@
 struct msqid64_ds {
 	struct ipc64_perm msg_perm;
 #if __BITS_PER_LONG == 64
-	__kernel_time_t msg_stime;	/* last msgsnd time */
-	__kernel_time_t msg_rtime;	/* last msgrcv time */
-	__kernel_time_t msg_ctime;	/* last change time */
+	long		 msg_stime;	/* last msgsnd time */
+	long		 msg_rtime;	/* last msgrcv time */
+	long		 msg_ctime;	/* last change time */
 #else
 	unsigned long	msg_stime;	/* last msgsnd time */
 	unsigned long	msg_stime_high;
diff --git a/include/uapi/asm-generic/sembuf.h b/include/uapi/asm-generic/sembuf.h
index 0bae010f1b64..137606018c6a 100644
--- a/include/uapi/asm-generic/sembuf.h
+++ b/include/uapi/asm-generic/sembuf.h
@@ -13,9 +13,8 @@
  * everyone just ended up making identical copies without specific
  * optimizations, so we may just as well all use the same one.
  *
- * 64 bit architectures use a 64-bit __kernel_time_t here, while
+ * 64 bit architectures use a 64-bit long time field here, while
  * 32 bit architectures have a pair of unsigned long values.
- * so they do not need the first two padding words.
  *
  * On big-endian systems, the padding is in the wrong place for
  * historic reasons, so user space has to reconstruct a time_t
@@ -29,8 +28,8 @@
 struct semid64_ds {
 	struct ipc64_perm sem_perm;	/* permissions .. see ipc.h */
 #if __BITS_PER_LONG == 64
-	__kernel_time_t	sem_otime;	/* last semop time */
-	__kernel_time_t	sem_ctime;	/* last change time */
+	long		sem_otime;	/* last semop time */
+	long		sem_ctime;	/* last change time */
 #else
 	unsigned long	sem_otime;	/* last semop time */
 	unsigned long	sem_otime_high;
diff --git a/include/uapi/asm-generic/shmbuf.h b/include/uapi/asm-generic/shmbuf.h
index e504422fc501..2bab955e0fed 100644
--- a/include/uapi/asm-generic/shmbuf.h
+++ b/include/uapi/asm-generic/shmbuf.h
@@ -13,9 +13,9 @@
  * everyone just ended up making identical copies without specific
  * optimizations, so we may just as well all use the same one.
  *
- * 64 bit architectures typically define a 64 bit __kernel_time_t,
- * so they do not need the first two padding words.
- * On big-endian systems, the padding is in the wrong place.
+ * 64 bit architectures use a 64-bit long time field here, while
+ * 32 bit architectures have a pair of unsigned long values.
+ * On big-endian systems, the lower half is in the wrong place.
  *
  *
  * Pad space is left for:
@@ -26,9 +26,9 @@ struct shmid64_ds {
 	struct ipc64_perm	shm_perm;	/* operation perms */
 	size_t			shm_segsz;	/* size of segment (bytes) */
 #if __BITS_PER_LONG == 64
-	__kernel_time_t		shm_atime;	/* last attach time */
-	__kernel_time_t		shm_dtime;	/* last detach time */
-	__kernel_time_t		shm_ctime;	/* last change time */
+	long			shm_atime;	/* last attach time */
+	long			shm_dtime;	/* last detach time */
+	long			shm_ctime;	/* last change time */
 #else
 	unsigned long		shm_atime;	/* last attach time */
 	unsigned long		shm_atime_high;
-- 
2.20.0


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

* [PATCH 09/23] y2038: stat: avoid 'time_t' in 'struct stat'
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
                   ` (2 preceding siblings ...)
  2019-11-08 21:07 ` [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers Arnd Bergmann
@ 2019-11-08 21:07 ` Arnd Bergmann
  2019-11-08 21:12 ` [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval Arnd Bergmann
  2019-11-13 21:40 ` [PATCH 00/23] y2038 cleanups Arnd Bergmann
  5 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:07 UTC (permalink / raw)
  To: y2038, Ralf Baechle, Paul Burton, James Hogan,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	David S. Miller
  Cc: sparclinux, linuxppc-dev, linux-kernel, Arnd Bergmann, linux-mips

The time_t definition may differ between user space and kernel space,
so replace time_t with an unambiguous 'long' for the mips and sparc.

The same structures also contain 'off_t', which has the same problem,
so replace that as well on those two architectures and powerpc.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/mips/include/uapi/asm/stat.h    | 16 ++++++++--------
 arch/powerpc/include/uapi/asm/stat.h |  2 +-
 arch/sparc/include/uapi/asm/stat.h   | 24 ++++++++++++------------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/arch/mips/include/uapi/asm/stat.h b/arch/mips/include/uapi/asm/stat.h
index 95416f366d7f..3d2a3b71845c 100644
--- a/arch/mips/include/uapi/asm/stat.h
+++ b/arch/mips/include/uapi/asm/stat.h
@@ -26,17 +26,17 @@ struct stat {
 	gid_t		st_gid;
 	unsigned	st_rdev;
 	long		st_pad2[2];
-	off_t		st_size;
+	long		st_size;
 	long		st_pad3;
 	/*
 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
 	 * but we don't have it under Linux.
 	 */
-	time_t		st_atime;
+	long		st_atime;
 	long		st_atime_nsec;
-	time_t		st_mtime;
+	long		st_mtime;
 	long		st_mtime_nsec;
-	time_t		st_ctime;
+	long		st_ctime;
 	long		st_ctime_nsec;
 	long		st_blksize;
 	long		st_blocks;
@@ -70,13 +70,13 @@ struct stat64 {
 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
 	 * but we don't have it under Linux.
 	 */
-	time_t		st_atime;
+	long		st_atime;
 	unsigned long	st_atime_nsec;	/* Reserved for st_atime expansion  */
 
-	time_t		st_mtime;
+	long		st_mtime;
 	unsigned long	st_mtime_nsec;	/* Reserved for st_mtime expansion  */
 
-	time_t		st_ctime;
+	long		st_ctime;
 	unsigned long	st_ctime_nsec;	/* Reserved for st_ctime expansion  */
 
 	unsigned long	st_blksize;
@@ -105,7 +105,7 @@ struct stat {
 	unsigned int		st_rdev;
 	unsigned int		st_pad1[3]; /* Reserved for st_rdev expansion */
 
-	off_t			st_size;
+	long			st_size;
 
 	/*
 	 * Actually this should be timestruc_t st_atime, st_mtime and st_ctime
diff --git a/arch/powerpc/include/uapi/asm/stat.h b/arch/powerpc/include/uapi/asm/stat.h
index afd25f2ff4e8..7871055e5e32 100644
--- a/arch/powerpc/include/uapi/asm/stat.h
+++ b/arch/powerpc/include/uapi/asm/stat.h
@@ -40,7 +40,7 @@ struct stat {
 	uid_t		st_uid;
 	gid_t		st_gid;
 	unsigned long	st_rdev;
-	off_t		st_size;
+	long		st_size;
 	unsigned long	st_blksize;
 	unsigned long	st_blocks;
 	unsigned long	st_atime;
diff --git a/arch/sparc/include/uapi/asm/stat.h b/arch/sparc/include/uapi/asm/stat.h
index b6ec4eb217f7..732c41720e24 100644
--- a/arch/sparc/include/uapi/asm/stat.h
+++ b/arch/sparc/include/uapi/asm/stat.h
@@ -14,12 +14,12 @@ struct stat {
 	uid_t   st_uid;
 	gid_t   st_gid;
 	unsigned int st_rdev;
-	off_t   st_size;
-	time_t  st_atime;
-	time_t  st_mtime;
-	time_t  st_ctime;
-	off_t   st_blksize;
-	off_t   st_blocks;
+	long    st_size;
+	long    st_atime;
+	long    st_mtime;
+	long    st_ctime;
+	long    st_blksize;
+	long    st_blocks;
 	unsigned long  __unused4[2];
 };
 
@@ -57,15 +57,15 @@ struct stat {
 	unsigned short	st_uid;
 	unsigned short	st_gid;
 	unsigned short	st_rdev;
-	off_t		st_size;
-	time_t		st_atime;
+	long		st_size;
+	long		st_atime;
 	unsigned long	st_atime_nsec;
-	time_t		st_mtime;
+	long		st_mtime;
 	unsigned long	st_mtime_nsec;
-	time_t		st_ctime;
+	long		st_ctime;
 	unsigned long	st_ctime_nsec;
-	off_t		st_blksize;
-	off_t		st_blocks;
+	long		st_blksize;
+	long		st_blocks;
 	unsigned long	__unused4[2];
 };
 
-- 
2.20.0


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

* [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
                   ` (3 preceding siblings ...)
  2019-11-08 21:07 ` [PATCH 09/23] y2038: stat: avoid 'time_t' in 'struct stat' Arnd Bergmann
@ 2019-11-08 21:12 ` Arnd Bergmann
  2019-11-11 12:44   ` Christian Brauner
  2019-11-13 22:39   ` Rafael J. Wysocki
  2019-11-13 21:40 ` [PATCH 00/23] y2038 cleanups Arnd Bergmann
  5 siblings, 2 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-08 21:12 UTC (permalink / raw)
  To: y2038, Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Alexander Viro, Rafael J. Wysocki, Pavel Machek, Len Brown,
	John Stultz, Thomas Gleixner
  Cc: Arnd Bergmann, linux-pm, Stephen Boyd, linux-api, linux-kernel,
	linux-fsdevel, linuxppc-dev, Christian Brauner

All of the remaining syscalls that pass a timeval (gettimeofday, utime,
futimesat) can trivially be changed to pass a __kernel_old_timeval
instead, which has a compatible layout, but avoids ambiguity with
the timeval type in user space.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/powerpc/include/asm/asm-prototypes.h |  3 ++-
 arch/powerpc/kernel/syscalls.c            |  4 ++--
 fs/select.c                               | 10 +++++-----
 fs/utimes.c                               |  8 ++++----
 include/linux/syscalls.h                  | 10 +++++-----
 kernel/power/power.h                      |  2 +-
 kernel/time/time.c                        |  2 +-
 7 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/asm-prototypes.h b/arch/powerpc/include/asm/asm-prototypes.h
index 8561498e653c..2c25dc079cb9 100644
--- a/arch/powerpc/include/asm/asm-prototypes.h
+++ b/arch/powerpc/include/asm/asm-prototypes.h
@@ -92,7 +92,8 @@ long sys_swapcontext(struct ucontext __user *old_ctx,
 long sys_debug_setcontext(struct ucontext __user *ctx,
 			  int ndbg, struct sig_dbg_op __user *dbg);
 int
-ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp);
+ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
+	   struct __kernel_old_timeval __user *tvp);
 unsigned long __init early_init(unsigned long dt_ptr);
 void __init machine_init(u64 dt_ptr);
 #endif
diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
index 3bfb3888e897..078608ec2e92 100644
--- a/arch/powerpc/kernel/syscalls.c
+++ b/arch/powerpc/kernel/syscalls.c
@@ -79,7 +79,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, size_t, len,
  * sys_select() with the appropriate args. -- Cort
  */
 int
-ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
+ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
 {
 	if ( (unsigned long)n >= 4096 )
 	{
@@ -89,7 +89,7 @@ ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, s
 		    || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
 		    || __get_user(outp, ((fd_set  __user * __user *)(buffer+2)))
 		    || __get_user(exp, ((fd_set  __user * __user *)(buffer+3)))
-		    || __get_user(tvp, ((struct timeval  __user * __user *)(buffer+4))))
+		    || __get_user(tvp, ((struct __kernel_old_timeval  __user * __user *)(buffer+4))))
 			return -EFAULT;
 	}
 	return sys_select(n, inp, outp, exp, tvp);
diff --git a/fs/select.c b/fs/select.c
index 53a0c149f528..11d0285d46b7 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -321,7 +321,7 @@ static int poll_select_finish(struct timespec64 *end_time,
 	switch (pt_type) {
 	case PT_TIMEVAL:
 		{
-			struct timeval rtv;
+			struct __kernel_old_timeval rtv;
 
 			if (sizeof(rtv) > sizeof(rtv.tv_sec) + sizeof(rtv.tv_usec))
 				memset(&rtv, 0, sizeof(rtv));
@@ -698,10 +698,10 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
 }
 
 static int kern_select(int n, fd_set __user *inp, fd_set __user *outp,
-		       fd_set __user *exp, struct timeval __user *tvp)
+		       fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
 {
 	struct timespec64 end_time, *to = NULL;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	int ret;
 
 	if (tvp) {
@@ -720,7 +720,7 @@ static int kern_select(int n, fd_set __user *inp, fd_set __user *outp,
 }
 
 SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
-		fd_set __user *, exp, struct timeval __user *, tvp)
+		fd_set __user *, exp, struct __kernel_old_timeval __user *, tvp)
 {
 	return kern_select(n, inp, outp, exp, tvp);
 }
@@ -810,7 +810,7 @@ SYSCALL_DEFINE6(pselect6_time32, int, n, fd_set __user *, inp, fd_set __user *,
 struct sel_arg_struct {
 	unsigned long n;
 	fd_set __user *inp, *outp, *exp;
-	struct timeval __user *tvp;
+	struct __kernel_old_timeval __user *tvp;
 };
 
 SYSCALL_DEFINE1(old_select, struct sel_arg_struct __user *, arg)
diff --git a/fs/utimes.c b/fs/utimes.c
index 1ba3f7883870..c952b6b3d8a0 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -161,9 +161,9 @@ SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
  * utimensat() instead.
  */
 static long do_futimesat(int dfd, const char __user *filename,
-			 struct timeval __user *utimes)
+			 struct __kernel_old_timeval __user *utimes)
 {
-	struct timeval times[2];
+	struct __kernel_old_timeval times[2];
 	struct timespec64 tstimes[2];
 
 	if (utimes) {
@@ -190,13 +190,13 @@ static long do_futimesat(int dfd, const char __user *filename,
 
 
 SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename,
-		struct timeval __user *, utimes)
+		struct __kernel_old_timeval __user *, utimes)
 {
 	return do_futimesat(dfd, filename, utimes);
 }
 
 SYSCALL_DEFINE2(utimes, char __user *, filename,
-		struct timeval __user *, utimes)
+		struct __kernel_old_timeval __user *, utimes)
 {
 	return do_futimesat(AT_FDCWD, filename, utimes);
 }
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 2f27bc9d5ef0..e665920fa359 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -51,7 +51,7 @@ struct statx;
 struct __sysctl_args;
 struct sysinfo;
 struct timespec;
-struct timeval;
+struct __kernel_old_timeval;
 struct __kernel_timex;
 struct timezone;
 struct tms;
@@ -732,7 +732,7 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
 asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache);
 
 /* kernel/time.c */
-asmlinkage long sys_gettimeofday(struct timeval __user *tv,
+asmlinkage long sys_gettimeofday(struct __kernel_old_timeval __user *tv,
 				struct timezone __user *tz);
 asmlinkage long sys_settimeofday(struct timeval __user *tv,
 				struct timezone __user *tz);
@@ -1082,9 +1082,9 @@ asmlinkage long sys_time32(old_time32_t __user *tloc);
 asmlinkage long sys_utime(char __user *filename,
 				struct utimbuf __user *times);
 asmlinkage long sys_utimes(char __user *filename,
-				struct timeval __user *utimes);
+				struct __kernel_old_timeval __user *utimes);
 asmlinkage long sys_futimesat(int dfd, const char __user *filename,
-			      struct timeval __user *utimes);
+			      struct __kernel_old_timeval __user *utimes);
 #endif
 asmlinkage long sys_futimesat_time32(unsigned int dfd,
 				     const char __user *filename,
@@ -1098,7 +1098,7 @@ asmlinkage long sys_getdents(unsigned int fd,
 				struct linux_dirent __user *dirent,
 				unsigned int count);
 asmlinkage long sys_select(int n, fd_set __user *inp, fd_set __user *outp,
-			fd_set __user *exp, struct timeval __user *tvp);
+			fd_set __user *exp, struct __kernel_old_timeval __user *tvp);
 asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
 				int timeout);
 asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events,
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 44bee462ff57..7cdc64dc2373 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -179,7 +179,7 @@ extern void swsusp_close(fmode_t);
 extern int swsusp_unmark(void);
 #endif
 
-struct timeval;
+struct __kernel_old_timeval;
 /* kernel/power/swsusp.c */
 extern void swsusp_show_speed(ktime_t, ktime_t, unsigned int, char *);
 
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 7eba7c9a7e3e..bc114f0be8f1 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -137,7 +137,7 @@ SYSCALL_DEFINE1(stime32, old_time32_t __user *, tptr)
 #endif /* __ARCH_WANT_SYS_TIME32 */
 #endif
 
-SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv,
+SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
 		struct timezone __user *, tz)
 {
 	if (likely(tv != NULL)) {
-- 
2.20.0


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

* Re: [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval
  2019-11-08 21:12 ` [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval Arnd Bergmann
@ 2019-11-11 12:44   ` Christian Brauner
  2019-11-13 22:39   ` Rafael J. Wysocki
  1 sibling, 0 replies; 18+ messages in thread
From: Christian Brauner @ 2019-11-11 12:44 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Len Brown, linux-pm, y2038, Rafael J. Wysocki, linux-kernel,
	Stephen Boyd, Paul Mackerras, Alexander Viro, Pavel Machek,
	linux-fsdevel, John Stultz, Thomas Gleixner, linux-api,
	linuxppc-dev, Christian Brauner

On Fri, Nov 08, 2019 at 10:12:11PM +0100, Arnd Bergmann wrote:
> All of the remaining syscalls that pass a timeval (gettimeofday, utime,
> futimesat) can trivially be changed to pass a __kernel_old_timeval
> instead, which has a compatible layout, but avoids ambiguity with
> the timeval type in user space.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Seems reasonable.
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

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

* Re: [PATCH 00/23] y2038 cleanups
  2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
                   ` (4 preceding siblings ...)
  2019-11-08 21:12 ` [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval Arnd Bergmann
@ 2019-11-13 21:40 ` Arnd Bergmann
  5 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-13 21:40 UTC (permalink / raw)
  To: y2038 Mailman List
  Cc: linux-aio, linux-ia64, Peter Zijlstra, Heiko Carstens,
	linux-mips, Networking, Deepa Dinamani, sparclinux,
	Vincenzo Frascino, Will Deacon, linux-arch, Paul Moore,
	Helge Deller, the arch/x86 maintainers, Stephen Smalley,
	SElinux list, Jeff Dike, alpha, linux-um, Steven Rostedt,
	John Stultz, Al Viro, Eric Paris, Thomas Gleixner,
	Christian Brauner, Richard Henderson, Tony Luck, Parisc List,
	Stephen Boyd, Linux API, linux-kernel, Paul Burton,
	Benjamin LaHaise, Eric W . Biederman, Richard Weinberger,
	Linux FS-devel Mailing List, linuxppc-dev, David Miller,
	Greentime Hu

On Fri, Nov 8, 2019 at 10:04 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> This is a series of cleanups for the y2038 work, mostly intended
> for namespace cleaning: the kernel defines the traditional
> time_t, timeval and timespec types that often lead to y2038-unsafe
> code. Even though the unsafe usage is mostly gone from the kernel,
> having the types and associated functions around means that we
> can still grow new users, and that we may be missing conversions
> to safe types that actually matter.
>
> As there is no rush on any of these patches, I would either
> queue them up in linux-next through my y2038 branch, or
> Thomas could add them to the tip tree if he wants.
>
> As mentioned in another series, this is part of a larger
> effort to fix all the remaining bits and pieces that are
> not completed yet from the y2038 conversion, and the full
> set can be found at:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=y2038-endgame
>
> Maintainers, please review and provide Acks.
>
> Let me know if you have any opinion on whether we should do
> the include last two patches of this series or not.
>
>      Arnd
>
> Arnd Bergmann (23):
>   y2038: remove CONFIG_64BIT_TIME
>   y2038: add __kernel_old_timespec and __kernel_old_time_t
>   y2038: vdso: change timeval to __kernel_old_timeval
>   y2038: vdso: change timespec to __kernel_old_timespec
>   y2038: vdso: change time_t to __kernel_old_time_t
>   y2038: vdso: nds32: open-code timespec_add_ns()
>   y2038: vdso: powerpc: avoid timespec references
>   y2038: ipc: remove __kernel_time_t reference from headers
>   y2038: stat: avoid 'time_t' in 'struct stat'
>   y2038: uapi: change __kernel_time_t to __kernel_old_time_t
>   y2038: rusage: use __kernel_old_timeval
>   y2038: syscalls: change remaining timeval to __kernel_old_timeval
>   y2038: socket: remove timespec reference in timestamping
>   y2038: make ns_to_compat_timeval use __kernel_old_timeval
>   y2038: elfcore: Use __kernel_old_timeval for process times
>   y2038: timerfd: Use timespec64 internally
>   y2038: time: avoid timespec usage in settimeofday()
>   y2038: itimer: compat handling to itimer.c
>   y2038: use compat_{get,set}_itimer on alpha
>   y2038: move itimer reset into itimer.c
>   y2038: itimer: change implementation to timespec64
>   [RFC] y2038: itimer: use ktime_t internally
>   y2038: allow disabling time32 system calls

I've dropped the "[RFC] y2038: itimer: use ktime_t internally" patch
for the moment,
and added two other patches from other series:

y2038: remove CONFIG_64BIT_TIME
y2038: socket: use __kernel_old_timespec instead of timespec

Tentatively pushed out the patches with the Acks I have received so
far to my y2038 branch on git.kernel.org so it gets included in linux-next.

If I hear no complaints, I'll send a pull request for the merge window,
along with the compat-ioctl series I have already queued up in the same
branch.

    Arnd

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

* Re: [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval
  2019-11-08 21:07 ` [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval Arnd Bergmann
@ 2019-11-13 21:56   ` Thomas Gleixner
  0 siblings, 0 replies; 18+ messages in thread
From: Thomas Gleixner @ 2019-11-13 21:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul Mackerras, H. Peter Anvin, sparclinux, Vincenzo Frascino,
	Anton Ivanov, Vincent Chen, y2038, Richard Weinberger, x86,
	Ingo Molnar, Jeff Dike, linux-um, Borislav Petkov, Greentime Hu,
	Andy Lutomirski, linux-kernel, Eric W. Biederman, linuxppc-dev,
	David S. Miller

On Fri, 8 Nov 2019, Arnd Bergmann wrote:

> The gettimeofday() function in vdso uses the traditional 'timeval'
> structure layout, which will be incompatible with future versions of
> glibc on 32-bit architectures that use a 64-bit time_t.
> 
> This interface is problematic for y2038, when time_t overflows on 32-bit
> architectures, but the plan so far is that a libc with 64-bit time_t
> will not call into the gettimeofday() vdso helper at all, and only
> have a method for entering clock_gettime().  This means we don't have
> to fix it here, though we probably want to add a new clock_gettime()
> entry point using a 64-bit version of 'struct timespec' at some point.
> 
> Changing the vdso code to use __kernel_old_timeval helps isolate
> this usage from the other ones that still need to be fixed properly,
> and it gets us closer to removing the 'timeval' definition from the
> kernel sources.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

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

* Re: [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval
  2019-11-08 21:12 ` [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval Arnd Bergmann
  2019-11-11 12:44   ` Christian Brauner
@ 2019-11-13 22:39   ` Rafael J. Wysocki
  1 sibling, 0 replies; 18+ messages in thread
From: Rafael J. Wysocki @ 2019-11-13 22:39 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Len Brown, linux-pm, y2038, linux-kernel, Stephen Boyd,
	Paul Mackerras, Alexander Viro, Pavel Machek, linux-fsdevel,
	John Stultz, Thomas Gleixner, linux-api, linuxppc-dev,
	Christian Brauner

On Friday, November 8, 2019 10:12:11 PM CET Arnd Bergmann wrote:
> All of the remaining syscalls that pass a timeval (gettimeofday, utime,
> futimesat) can trivially be changed to pass a __kernel_old_timeval
> instead, which has a compatible layout, but avoids ambiguity with
> the timeval type in user space.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

For the change in power/power.h

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  arch/powerpc/include/asm/asm-prototypes.h |  3 ++-
>  arch/powerpc/kernel/syscalls.c            |  4 ++--
>  fs/select.c                               | 10 +++++-----
>  fs/utimes.c                               |  8 ++++----
>  include/linux/syscalls.h                  | 10 +++++-----
>  kernel/power/power.h                      |  2 +-
>  kernel/time/time.c                        |  2 +-
>  7 files changed, 20 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/asm-prototypes.h b/arch/powerpc/include/asm/asm-prototypes.h
> index 8561498e653c..2c25dc079cb9 100644
> --- a/arch/powerpc/include/asm/asm-prototypes.h
> +++ b/arch/powerpc/include/asm/asm-prototypes.h
> @@ -92,7 +92,8 @@ long sys_swapcontext(struct ucontext __user *old_ctx,
>  long sys_debug_setcontext(struct ucontext __user *ctx,
>  			  int ndbg, struct sig_dbg_op __user *dbg);
>  int
> -ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp);
> +ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
> +	   struct __kernel_old_timeval __user *tvp);
>  unsigned long __init early_init(unsigned long dt_ptr);
>  void __init machine_init(u64 dt_ptr);
>  #endif
> diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
> index 3bfb3888e897..078608ec2e92 100644
> --- a/arch/powerpc/kernel/syscalls.c
> +++ b/arch/powerpc/kernel/syscalls.c
> @@ -79,7 +79,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, size_t, len,
>   * sys_select() with the appropriate args. -- Cort
>   */
>  int
> -ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
> +ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
>  {
>  	if ( (unsigned long)n >= 4096 )
>  	{
> @@ -89,7 +89,7 @@ ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, s
>  		    || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
>  		    || __get_user(outp, ((fd_set  __user * __user *)(buffer+2)))
>  		    || __get_user(exp, ((fd_set  __user * __user *)(buffer+3)))
> -		    || __get_user(tvp, ((struct timeval  __user * __user *)(buffer+4))))
> +		    || __get_user(tvp, ((struct __kernel_old_timeval  __user * __user *)(buffer+4))))
>  			return -EFAULT;
>  	}
>  	return sys_select(n, inp, outp, exp, tvp);
> diff --git a/fs/select.c b/fs/select.c
> index 53a0c149f528..11d0285d46b7 100644
> --- a/fs/select.c
> +++ b/fs/select.c
> @@ -321,7 +321,7 @@ static int poll_select_finish(struct timespec64 *end_time,
>  	switch (pt_type) {
>  	case PT_TIMEVAL:
>  		{
> -			struct timeval rtv;
> +			struct __kernel_old_timeval rtv;
>  
>  			if (sizeof(rtv) > sizeof(rtv.tv_sec) + sizeof(rtv.tv_usec))
>  				memset(&rtv, 0, sizeof(rtv));
> @@ -698,10 +698,10 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
>  }
>  
>  static int kern_select(int n, fd_set __user *inp, fd_set __user *outp,
> -		       fd_set __user *exp, struct timeval __user *tvp)
> +		       fd_set __user *exp, struct __kernel_old_timeval __user *tvp)
>  {
>  	struct timespec64 end_time, *to = NULL;
> -	struct timeval tv;
> +	struct __kernel_old_timeval tv;
>  	int ret;
>  
>  	if (tvp) {
> @@ -720,7 +720,7 @@ static int kern_select(int n, fd_set __user *inp, fd_set __user *outp,
>  }
>  
>  SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
> -		fd_set __user *, exp, struct timeval __user *, tvp)
> +		fd_set __user *, exp, struct __kernel_old_timeval __user *, tvp)
>  {
>  	return kern_select(n, inp, outp, exp, tvp);
>  }
> @@ -810,7 +810,7 @@ SYSCALL_DEFINE6(pselect6_time32, int, n, fd_set __user *, inp, fd_set __user *,
>  struct sel_arg_struct {
>  	unsigned long n;
>  	fd_set __user *inp, *outp, *exp;
> -	struct timeval __user *tvp;
> +	struct __kernel_old_timeval __user *tvp;
>  };
>  
>  SYSCALL_DEFINE1(old_select, struct sel_arg_struct __user *, arg)
> diff --git a/fs/utimes.c b/fs/utimes.c
> index 1ba3f7883870..c952b6b3d8a0 100644
> --- a/fs/utimes.c
> +++ b/fs/utimes.c
> @@ -161,9 +161,9 @@ SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
>   * utimensat() instead.
>   */
>  static long do_futimesat(int dfd, const char __user *filename,
> -			 struct timeval __user *utimes)
> +			 struct __kernel_old_timeval __user *utimes)
>  {
> -	struct timeval times[2];
> +	struct __kernel_old_timeval times[2];
>  	struct timespec64 tstimes[2];
>  
>  	if (utimes) {
> @@ -190,13 +190,13 @@ static long do_futimesat(int dfd, const char __user *filename,
>  
>  
>  SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename,
> -		struct timeval __user *, utimes)
> +		struct __kernel_old_timeval __user *, utimes)
>  {
>  	return do_futimesat(dfd, filename, utimes);
>  }
>  
>  SYSCALL_DEFINE2(utimes, char __user *, filename,
> -		struct timeval __user *, utimes)
> +		struct __kernel_old_timeval __user *, utimes)
>  {
>  	return do_futimesat(AT_FDCWD, filename, utimes);
>  }
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index 2f27bc9d5ef0..e665920fa359 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -51,7 +51,7 @@ struct statx;
>  struct __sysctl_args;
>  struct sysinfo;
>  struct timespec;
> -struct timeval;
> +struct __kernel_old_timeval;
>  struct __kernel_timex;
>  struct timezone;
>  struct tms;
> @@ -732,7 +732,7 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
>  asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache);
>  
>  /* kernel/time.c */
> -asmlinkage long sys_gettimeofday(struct timeval __user *tv,
> +asmlinkage long sys_gettimeofday(struct __kernel_old_timeval __user *tv,
>  				struct timezone __user *tz);
>  asmlinkage long sys_settimeofday(struct timeval __user *tv,
>  				struct timezone __user *tz);
> @@ -1082,9 +1082,9 @@ asmlinkage long sys_time32(old_time32_t __user *tloc);
>  asmlinkage long sys_utime(char __user *filename,
>  				struct utimbuf __user *times);
>  asmlinkage long sys_utimes(char __user *filename,
> -				struct timeval __user *utimes);
> +				struct __kernel_old_timeval __user *utimes);
>  asmlinkage long sys_futimesat(int dfd, const char __user *filename,
> -			      struct timeval __user *utimes);
> +			      struct __kernel_old_timeval __user *utimes);
>  #endif
>  asmlinkage long sys_futimesat_time32(unsigned int dfd,
>  				     const char __user *filename,
> @@ -1098,7 +1098,7 @@ asmlinkage long sys_getdents(unsigned int fd,
>  				struct linux_dirent __user *dirent,
>  				unsigned int count);
>  asmlinkage long sys_select(int n, fd_set __user *inp, fd_set __user *outp,
> -			fd_set __user *exp, struct timeval __user *tvp);
> +			fd_set __user *exp, struct __kernel_old_timeval __user *tvp);
>  asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
>  				int timeout);
>  asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events,
> diff --git a/kernel/power/power.h b/kernel/power/power.h
> index 44bee462ff57..7cdc64dc2373 100644
> --- a/kernel/power/power.h
> +++ b/kernel/power/power.h
> @@ -179,7 +179,7 @@ extern void swsusp_close(fmode_t);
>  extern int swsusp_unmark(void);
>  #endif
>  
> -struct timeval;
> +struct __kernel_old_timeval;
>  /* kernel/power/swsusp.c */
>  extern void swsusp_show_speed(ktime_t, ktime_t, unsigned int, char *);
>  
> diff --git a/kernel/time/time.c b/kernel/time/time.c
> index 7eba7c9a7e3e..bc114f0be8f1 100644
> --- a/kernel/time/time.c
> +++ b/kernel/time/time.c
> @@ -137,7 +137,7 @@ SYSCALL_DEFINE1(stime32, old_time32_t __user *, tptr)
>  #endif /* __ARCH_WANT_SYS_TIME32 */
>  #endif
>  
> -SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv,
> +SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
>  		struct timezone __user *, tz)
>  {
>  	if (likely(tv != NULL)) {
> 





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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-08 21:07 ` [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references Arnd Bergmann
@ 2019-11-20 22:43   ` Ben Hutchings
  2019-11-21 14:23     ` Arnd Bergmann
  0 siblings, 1 reply; 18+ messages in thread
From: Ben Hutchings @ 2019-11-20 22:43 UTC (permalink / raw)
  To: Arnd Bergmann, y2038, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman
  Cc: Greg Kroah-Hartman, linux-kernel, Nicholas Piggin,
	Thomas Gleixner, linuxppc-dev, Allison Randal

On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
[...]
> --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
> @@ -15,10 +15,8 @@
>  /* Offset for the low 32-bit part of a field of long type */
>  #if defined(CONFIG_PPC64) && defined(CONFIG_CPU_BIG_ENDIAN)
>  #define LOPART	4
> -#define TSPEC_TV_SEC	TSPC64_TV_SEC+LOPART
>  #else
>  #define LOPART	0
> -#define TSPEC_TV_SEC	TSPC32_TV_SEC
>  #endif
>  
>  	.text
> @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
>  	bl	__get_datapage@local
>  	mr	r9, r3			/* datapage ptr in r9 */
>  
> -	lwz	r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
> +	lwz	r3,STAMP_XTIME_SEC+LOWPART(r9)

"LOWPART" should be "LOPART".

>  
>  	cmplwi	r11,0			/* check if t is NULL */
>  	beq	2f
> @@ -268,7 +266,7 @@ __do_get_tspec:
>  	 * as a 32.32 fixed-point number in r3 and r4.
>  	 * Load & add the xtime stamp.
>  	 */
> -	lwz	r5,STAMP_XTIME+TSPEC_TV_SEC(r9)
> +	lwz	r5,STAMP_XTIME_SEC+LOWPART(r9)

Same here.

>  	lwz	r6,STAMP_SEC_FRAC(r9)
>  	addc	r4,r4,r6
>  	adde	r3,r3,r5
[...]

-- 
Ben Hutchings, Software Developer                         Codethink Ltd
https://www.codethink.co.uk/                 Dale House, 35 Dale Street
                                     Manchester, M1 2HF, United Kingdom


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

* Re: [Y2038] [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers
  2019-11-08 21:07 ` [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers Arnd Bergmann
@ 2019-11-20 22:49   ` Ben Hutchings
  2019-11-21 14:28     ` Arnd Bergmann
  0 siblings, 1 reply; 18+ messages in thread
From: Ben Hutchings @ 2019-11-20 22:49 UTC (permalink / raw)
  To: Arnd Bergmann, y2038, Ralf Baechle, Paul Burton, James Hogan,
	James E.J. Bottomley, Helge Deller, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, David S. Miller,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86
  Cc: linux-arch, linux-parisc, linux-mips, linux-kernel,
	H. Peter Anvin, sparclinux, linuxppc-dev

On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
[...]
> --- a/arch/x86/include/uapi/asm/sembuf.h
> +++ b/arch/x86/include/uapi/asm/sembuf.h
> @@ -21,9 +21,9 @@ struct semid64_ds {
>  	unsigned long	sem_ctime;	/* last change time */
>  	unsigned long	sem_ctime_high;
>  #else
> -	__kernel_time_t	sem_otime;	/* last semop time */
> +	long		sem_otime;	/* last semop time */
>  	__kernel_ulong_t __unused1;
> -	__kernel_time_t	sem_ctime;	/* last change time */
> +	long		sem_ctime;	/* last change time */
>  	__kernel_ulong_t __unused2;
>  #endif
>  	__kernel_ulong_t sem_nsems;	/* no. of semaphores in array */
[...]

We need to use __kernel_long_t here to do the right thing on x32.

Ben.

-- 
Ben Hutchings, Software Developer                         Codethink Ltd
https://www.codethink.co.uk/                 Dale House, 35 Dale Street
                                     Manchester, M1 2HF, United Kingdom


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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-20 22:43   ` [Y2038] " Ben Hutchings
@ 2019-11-21 14:23     ` Arnd Bergmann
  2019-11-21 16:25       ` Christophe Leroy
  0 siblings, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-21 14:23 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: y2038 Mailman List, linux-kernel, Nicholas Piggin,
	Paul Mackerras, Greg Kroah-Hartman, Thomas Gleixner,
	linuxppc-dev, Allison Randal

On Wed, Nov 20, 2019 at 11:43 PM Ben Hutchings
<ben.hutchings@codethink.co.uk> wrote:
>
> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
> [...]
> > --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
> > +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
> > @@ -15,10 +15,8 @@
> >  /* Offset for the low 32-bit part of a field of long type */
> >  #if defined(CONFIG_PPC64) && defined(CONFIG_CPU_BIG_ENDIAN)
> >  #define LOPART       4
> > -#define TSPEC_TV_SEC TSPC64_TV_SEC+LOPART
> >  #else
> >  #define LOPART       0
> > -#define TSPEC_TV_SEC TSPC32_TV_SEC
> >  #endif
> >
> >       .text
> > @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
> >       bl      __get_datapage@local
> >       mr      r9, r3                  /* datapage ptr in r9 */
> >
> > -     lwz     r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
> > +     lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
>
> "LOWPART" should be "LOPART".
>

Thanks, fixed both instances in a patch on top now. I considered folding
it into the original patch, but as it's close to the merge window I'd
rather not rebase it, and this way I also give you credit for finding the bug.

I'm surprised that the 0-day bot did not report this already.

Thanks fro the careful review!

        Arnd

commit 1c11ca7a0584ddede5b8c93057b40d31e8a96d3d (HEAD)
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Thu Nov 21 15:19:49 2019 +0100

    y2038: fix typo in powerpc vdso "LOPART"

    The earlier patch introduced a typo, change LOWPART back to
    LOPART.

    Fixes: 176ed98c8a76 ("y2038: vdso: powerpc: avoid timespec references")
    Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S
b/arch/powerpc/kernel/vdso32/gettimeofday.S
index a7180b0f4aa1..c8e6902cb01b 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -190,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
        bl      __get_datapage@local
        mr      r9, r3                  /* datapage ptr in r9 */

-       lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
+       lwz     r3,STAMP_XTIME_SEC+LOPART(r9)

        cmplwi  r11,0                   /* check if t is NULL */
        beq     2f
@@ -266,7 +266,7 @@ __do_get_tspec:
         * as a 32.32 fixed-point number in r3 and r4.
         * Load & add the xtime stamp.
         */
-       lwz     r5,STAMP_XTIME_SEC+LOWPART(r9)
+       lwz     r5,STAMP_XTIME_SEC+LOPART(r9)

        lwz     r6,STAMP_SEC_FRAC(r9)
        addc    r4,r4,r6
        adde    r3,r3,r5

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

* Re: [Y2038] [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers
  2019-11-20 22:49   ` [Y2038] " Ben Hutchings
@ 2019-11-21 14:28     ` Arnd Bergmann
  0 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-21 14:28 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: linux-arch, H. Peter Anvin, Parisc List, y2038 Mailman List,
	James Hogan, Helge Deller, the arch/x86 maintainers, linux-mips,
	Ralf Baechle, linux-kernel, James E.J. Bottomley, Paul Burton,
	Ingo Molnar, Paul Mackerras, sparclinux, Borislav Petkov,
	Thomas Gleixner, linuxppc-dev, David S. Miller

On Wed, Nov 20, 2019 at 11:49 PM Ben Hutchings
<ben.hutchings@codethink.co.uk> wrote:
>
> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
> [...]
> > --- a/arch/x86/include/uapi/asm/sembuf.h
> > +++ b/arch/x86/include/uapi/asm/sembuf.h
> > @@ -21,9 +21,9 @@ struct semid64_ds {
> >       unsigned long   sem_ctime;      /* last change time */
> >       unsigned long   sem_ctime_high;
> >  #else
> > -     __kernel_time_t sem_otime;      /* last semop time */
> > +     long            sem_otime;      /* last semop time */
> >       __kernel_ulong_t __unused1;
> > -     __kernel_time_t sem_ctime;      /* last change time */
> > +     long            sem_ctime;      /* last change time */
> >       __kernel_ulong_t __unused2;
> >  #endif
> >       __kernel_ulong_t sem_nsems;     /* no. of semaphores in array */
> [...]
>
> We need to use __kernel_long_t here to do the right thing on x32.

Good catch, thanks for the review!

I applied the patch below now on top.

       Arnd

commit c7ebd8a1c1825c3197732ea692cf3dde34a644f5 (HEAD)
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Thu Nov 21 15:25:04 2019 +0100

    y2038: ipc: fix x32 ABI breakage

    The correct type on x32 is 64-bit wide, same as for the other struct
    members around it, so use  __kernel_long_t in place of the original
    __kernel_time_t here, corresponding to the rest of the structure.

    Fixes: caf5e32d4ea7 ("y2038: ipc: remove __kernel_time_t reference
from headers")
    Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/arch/x86/include/uapi/asm/sembuf.h
b/arch/x86/include/uapi/asm/sembuf.h
index 7c1b156695ba..20cab43c4b15 100644
--- a/arch/x86/include/uapi/asm/sembuf.h
+++ b/arch/x86/include/uapi/asm/sembuf.h
@@ -21,9 +21,9 @@ struct semid64_ds {
        unsigned long   sem_ctime;      /* last change time */
        unsigned long   sem_ctime_high;
 #else
-       long            sem_otime;      /* last semop time */
+       __kernel_long_t sem_otime;      /* last semop time */
        __kernel_ulong_t __unused1;
-       long            sem_ctime;      /* last change time */
+       __kenrel_long_t sem_ctime;      /* last change time */
        __kernel_ulong_t __unused2;
 #endif
        __kernel_ulong_t sem_nsems;     /* no. of semaphores in array */

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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-21 14:23     ` Arnd Bergmann
@ 2019-11-21 16:25       ` Christophe Leroy
  2019-11-27 11:03         ` Arnd Bergmann
  0 siblings, 1 reply; 18+ messages in thread
From: Christophe Leroy @ 2019-11-21 16:25 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ben Hutchings, y2038 Mailman List, Greg Kroah-Hartman,
	linux-kernel, Nicholas Piggin, Paul Mackerras, Thomas Gleixner,
	linuxppc-dev, Allison Randal

Arnd Bergmann <arnd@arndb.de> a écrit :

> On Wed, Nov 20, 2019 at 11:43 PM Ben Hutchings
> <ben.hutchings@codethink.co.uk> wrote:
>>
>> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
>> [...]
>> > --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
>> > +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
>> > @@ -15,10 +15,8 @@
>> >  /* Offset for the low 32-bit part of a field of long type */
>> >  #if defined(CONFIG_PPC64) && defined(CONFIG_CPU_BIG_ENDIAN)
>> >  #define LOPART       4
>> > -#define TSPEC_TV_SEC TSPC64_TV_SEC+LOPART
>> >  #else
>> >  #define LOPART       0
>> > -#define TSPEC_TV_SEC TSPC32_TV_SEC
>> >  #endif
>> >
>> >       .text
>> > @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
>> >       bl      __get_datapage@local
>> >       mr      r9, r3                  /* datapage ptr in r9 */
>> >
>> > -     lwz     r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
>> > +     lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
>>
>> "LOWPART" should be "LOPART".
>>
>
> Thanks, fixed both instances in a patch on top now. I considered folding
> it into the original patch, but as it's close to the merge window I'd
> rather not rebase it, and this way I also give you credit for  
> finding the bug.

Take care, might conflict with  
https://github.com/linuxppc/linux/commit/5e381d727fe8834ca5a126f510194a7a4ac6dd3a

Christophe

>
> I'm surprised that the 0-day bot did not report this already.
>
> Thanks fro the careful review!
>
>         Arnd
>
> commit 1c11ca7a0584ddede5b8c93057b40d31e8a96d3d (HEAD)
> Author: Arnd Bergmann <arnd@arndb.de>
> Date:   Thu Nov 21 15:19:49 2019 +0100
>
>     y2038: fix typo in powerpc vdso "LOPART"
>
>     The earlier patch introduced a typo, change LOWPART back to
>     LOPART.
>
>     Fixes: 176ed98c8a76 ("y2038: vdso: powerpc: avoid timespec references")
>     Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
>     Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S
> b/arch/powerpc/kernel/vdso32/gettimeofday.S
> index a7180b0f4aa1..c8e6902cb01b 100644
> --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
> @@ -190,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
>         bl      __get_datapage@local
>         mr      r9, r3                  /* datapage ptr in r9 */
>
> -       lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
> +       lwz     r3,STAMP_XTIME_SEC+LOPART(r9)
>
>         cmplwi  r11,0                   /* check if t is NULL */
>         beq     2f
> @@ -266,7 +266,7 @@ __do_get_tspec:
>          * as a 32.32 fixed-point number in r3 and r4.
>          * Load & add the xtime stamp.
>          */
> -       lwz     r5,STAMP_XTIME_SEC+LOWPART(r9)
> +       lwz     r5,STAMP_XTIME_SEC+LOPART(r9)
>
>         lwz     r6,STAMP_SEC_FRAC(r9)
>         addc    r4,r4,r6
>         adde    r3,r3,r5



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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-21 16:25       ` Christophe Leroy
@ 2019-11-27 11:03         ` Arnd Bergmann
  2019-12-02 12:55           ` Christophe Leroy
  0 siblings, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2019-11-27 11:03 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Ben Hutchings, y2038 Mailman List, Greg Kroah-Hartman,
	linux-kernel, Nicholas Piggin, Paul Mackerras, Thomas Gleixner,
	linuxppc-dev, Allison Randal

On Thu, Nov 21, 2019 at 5:25 PM Christophe Leroy
<christophe.leroy@c-s.fr> wrote:
> Arnd Bergmann <arnd@arndb.de> a écrit :
> > On Wed, Nov 20, 2019 at 11:43 PM Ben Hutchings
> > <ben.hutchings@codethink.co.uk> wrote:
> >>
> >> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
> >> > @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
> >> >       bl      __get_datapage@local
> >> >       mr      r9, r3                  /* datapage ptr in r9 */
> >> >
> >> > -     lwz     r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
> >> > +     lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
> >>
> >> "LOWPART" should be "LOPART".
> >>
> >
> > Thanks, fixed both instances in a patch on top now. I considered folding
> > it into the original patch, but as it's close to the merge window I'd
> > rather not rebase it, and this way I also give you credit for
> > finding the bug.
>
> Take care, might conflict with
> https://github.com/linuxppc/linux/commit/5e381d727fe8834ca5a126f510194a7a4ac6dd3a

Sorry for my late reply. I see this commit and no other variant of it has
made it into linux-next by now, so I assume this is not getting sent for v5.5
and it's not stopping me from sending my own pull request.

Please let me know if I missed something and this will cause problems.

On a related note: are you still working on the generic lib/vdso support for
powerpc? Without that, future libc implementations that use 64-bit time_t
will have to use the slow clock_gettime64 syscall instead of the vdso,
which has a significant performance impact.

       Arnd

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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-11-27 11:03         ` Arnd Bergmann
@ 2019-12-02 12:55           ` Christophe Leroy
  2019-12-02 14:03             ` Arnd Bergmann
  0 siblings, 1 reply; 18+ messages in thread
From: Christophe Leroy @ 2019-12-02 12:55 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ben Hutchings, y2038 Mailman List, Greg Kroah-Hartman,
	linux-kernel, Nicholas Piggin, Paul Mackerras, Thomas Gleixner,
	linuxppc-dev, Allison Randal



Le 27/11/2019 à 12:03, Arnd Bergmann a écrit :
> On Thu, Nov 21, 2019 at 5:25 PM Christophe Leroy
> <christophe.leroy@c-s.fr> wrote:
>> Arnd Bergmann <arnd@arndb.de> a écrit :
>>> On Wed, Nov 20, 2019 at 11:43 PM Ben Hutchings
>>> <ben.hutchings@codethink.co.uk> wrote:
>>>>
>>>> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
>>>>> @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
>>>>>        bl      __get_datapage@local
>>>>>        mr      r9, r3                  /* datapage ptr in r9 */
>>>>>
>>>>> -     lwz     r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
>>>>> +     lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
>>>>
>>>> "LOWPART" should be "LOPART".
>>>>
>>>
>>> Thanks, fixed both instances in a patch on top now. I considered folding
>>> it into the original patch, but as it's close to the merge window I'd
>>> rather not rebase it, and this way I also give you credit for
>>> finding the bug.
>>
>> Take care, might conflict with
>> https://github.com/linuxppc/linux/commit/5e381d727fe8834ca5a126f510194a7a4ac6dd3a
> 
> Sorry for my late reply. I see this commit and no other variant of it has
> made it into linux-next by now, so I assume this is not getting sent for v5.5
> and it's not stopping me from sending my own pull request.
> 
> Please let me know if I missed something and this will cause problems.
> 
> On a related note: are you still working on the generic lib/vdso support for
> powerpc? Without that, future libc implementations that use 64-bit time_t
> will have to use the slow clock_gettime64 syscall instead of the vdso,
> which has a significant performance impact.

I have left this generic lib/vdso subject aside for the moment, because 
performance is disappointing and its architecture doesn't real fit with 
powerpc ABI.

 From a performance point of view, it is manipulating 64 bits vars where 
is could use 32 bits vars. Of course I understand that y2038 will anyway 
force the use of 64 bits for seconds, but at the time being powerpc32 
VDSO is using 32 bits vars for both secs and ns, it make the difference. 
Also, the generic VDSO is playing too much with data on stacks and 
associated memory read/write/copies, which kills performance on RISC 
processors like powerpc. Inlining do_hres() for instance significantly 
improves that as it allow handling the 'struct __kernel_timespec ts' on 
registers instead of using stack.

Regarding powerpc ABI, the issue is that errors shall be reported by 
setting the SO bit in CR register, and this cannot be done in C.
This means:
- The VDSO entry point must be in ASM and the generic VDSO C function 
must be called from there, it cannot be the VDSO entry point.
- The VDSO fallback (ie the system call) cannot be done from the generic 
VDSO C function, it must be called from the ASM as well.

Last point/question, what's the point in using 64 bits for nanoseconds 
on 32 bits arches ?

Christophe

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

* Re: [Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references
  2019-12-02 12:55           ` Christophe Leroy
@ 2019-12-02 14:03             ` Arnd Bergmann
  0 siblings, 0 replies; 18+ messages in thread
From: Arnd Bergmann @ 2019-12-02 14:03 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Ben Hutchings, y2038 Mailman List, Greg Kroah-Hartman,
	linux-kernel, Nicholas Piggin, Paul Mackerras, Thomas Gleixner,
	linuxppc-dev, Allison Randal

On Mon, Dec 2, 2019 at 1:55 PM Christophe Leroy <christophe.leroy@c-s.fr> wrote:
> Le 27/11/2019 à 12:03, Arnd Bergmann a écrit :
> > On Thu, Nov 21, 2019 at 5:25 PM Christophe Leroy
> > <christophe.leroy@c-s.fr> wrote:
> >> Arnd Bergmann <arnd@arndb.de> a écrit :
> >>> On Wed, Nov 20, 2019 at 11:43 PM Ben Hutchings
> >>> <ben.hutchings@codethink.co.uk> wrote:
> >>>>
> >>>> On Fri, 2019-11-08 at 22:07 +0100, Arnd Bergmann wrote:
> >>>>> @@ -192,7 +190,7 @@ V_FUNCTION_BEGIN(__kernel_time)
> >>>>>        bl      __get_datapage@local
> >>>>>        mr      r9, r3                  /* datapage ptr in r9 */
> >>>>>
> >>>>> -     lwz     r3,STAMP_XTIME+TSPEC_TV_SEC(r9)
> >>>>> +     lwz     r3,STAMP_XTIME_SEC+LOWPART(r9)
> >>>>
> >>>> "LOWPART" should be "LOPART".
> >>>>
> >>>
> >>> Thanks, fixed both instances in a patch on top now. I considered folding
> >>> it into the original patch, but as it's close to the merge window I'd
> >>> rather not rebase it, and this way I also give you credit for
> >>> finding the bug.
> >>
> >> Take care, might conflict with
> >> https://github.com/linuxppc/linux/commit/5e381d727fe8834ca5a126f510194a7a4ac6dd3a
> >
> > Sorry for my late reply. I see this commit and no other variant of it has
> > made it into linux-next by now, so I assume this is not getting sent for v5.5
> > and it's not stopping me from sending my own pull request.
> >
> > Please let me know if I missed something and this will cause problems.
> >
> > On a related note: are you still working on the generic lib/vdso support for
> > powerpc? Without that, future libc implementations that use 64-bit time_t
> > will have to use the slow clock_gettime64 syscall instead of the vdso,
> > which has a significant performance impact.
>
> I have left this generic lib/vdso subject aside for the moment, because
> performance is disappointing and its architecture doesn't real fit with
> powerpc ABI.
>
>  From a performance point of view, it is manipulating 64 bits vars where
> is could use 32 bits vars. Of course I understand that y2038 will anyway
> force the use of 64 bits for seconds, but at the time being powerpc32
> VDSO is using 32 bits vars for both secs and ns, it make the difference.

Do you think we could optimize the common code? This sounds like
it could improve things for other architectures as well.

> Also, the generic VDSO is playing too much with data on stacks and
> associated memory read/write/copies, which kills performance on RISC
> processors like powerpc. Inlining do_hres() for instance significantly
> improves that as it allow handling the 'struct __kernel_timespec ts' on
> registers instead of using stack.

That should be easy enough to change in the common code, as
long as adding 'inline' does not cause harm on x86 and arm.

> Regarding powerpc ABI, the issue is that errors shall be reported by
> setting the SO bit in CR register, and this cannot be done in C.
> This means:
> - The VDSO entry point must be in ASM and the generic VDSO C function
> must be called from there, it cannot be the VDSO entry point.
> - The VDSO fallback (ie the system call) cannot be done from the generic
> VDSO C function, it must be called from the ASM as well.

As far as I can tell, both the VDSO entry point and the fallback are
in architecture specific code on all architectures, so this does not
seem to be a show-stopper.

It also seems that they might be combined as long the current
powerpc code could be changed to use the generic vdso_data
structure definition: the existing code can keep being used for
gettimeofday(), clock_gettime(CLOCK_MONOTONIC, ...) and
clock_gettime(CLOCK_REALTIME), while the generic implementation
can be called for clock_gettime64(), clock_getres() and clock_gettime()
with other time clock IDs.

> Last point/question, what's the point in using 64 bits for nanoseconds
> on 32 bits arches ?

The __kernel_timespec structure is defined with two 64-bit members so
it has the same layout on both 32-bit and 64-bit architectures, which
lets us share the implementation of the compat syscall handlers
even on big-endian architectures, and it avoids accidentally leaking four
bytes of stack data when copying a timespec from kernel to user
space. The high 32 bits of the nanosecond are expected to always
be zero when copying to user space, and to be ignored when copied
into the kernel (see get_timespec64()).

Note that C99 and POSIX require tv_nsec to be 'long', so 64-bit
architectures have to make it 64-bit wide, and 32-bit architectures
end up including padding for it.

In the vdso_data, the "nsec" value is shifted, so it actually needs
more bits. I don't know if this is a strict requirement, or if we could
change it to be 32 bits non-shifted during the update at the cost
of losing 1 nanosecond of accuracy.

      Arnd

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

end of thread, other threads:[~2019-12-02 14:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 21:02 [PATCH 00/23] y2038 cleanups Arnd Bergmann
2019-11-08 21:07 ` [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval Arnd Bergmann
2019-11-13 21:56   ` Thomas Gleixner
2019-11-08 21:07 ` [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references Arnd Bergmann
2019-11-20 22:43   ` [Y2038] " Ben Hutchings
2019-11-21 14:23     ` Arnd Bergmann
2019-11-21 16:25       ` Christophe Leroy
2019-11-27 11:03         ` Arnd Bergmann
2019-12-02 12:55           ` Christophe Leroy
2019-12-02 14:03             ` Arnd Bergmann
2019-11-08 21:07 ` [PATCH 08/23] y2038: ipc: remove __kernel_time_t reference from headers Arnd Bergmann
2019-11-20 22:49   ` [Y2038] " Ben Hutchings
2019-11-21 14:28     ` Arnd Bergmann
2019-11-08 21:07 ` [PATCH 09/23] y2038: stat: avoid 'time_t' in 'struct stat' Arnd Bergmann
2019-11-08 21:12 ` [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval Arnd Bergmann
2019-11-11 12:44   ` Christian Brauner
2019-11-13 22:39   ` Rafael J. Wysocki
2019-11-13 21:40 ` [PATCH 00/23] y2038 cleanups Arnd Bergmann

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