The series is a preparation series for individual architectures to use 64 bit time_t syscalls in compat and 32 bit emulation modes.
This is a follow up to the series Arnd Bergmann posted: https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html [1]
Big picture is as per the lwn article: https://lwn.net/Articles/643234/ [2]
The series is directed at converting posix clock syscalls: clock_gettime, clock_settime, clock_getres and clock_nanosleep to use a new data structure __kernel_timespec at syscall boundaries. __kernel_timespec maintains 64 bit time_t across all execution modes.
vdso will be handled as part of each architecture when they enable support for 64 bit time_t.
The compat syscalls are repurposed to provide backward compatibility by using them as native syscalls as well for 32 bit architectures. They will continue to use timespec at syscall boundaries.
CONFIG_64_BIT_TIME controls whether the syscalls use __kernel_timespec or timespec at syscall boundaries.
The series does the following: 1. Enable compat syscalls on 32 bit architectures. 2. Add a new __kernel_timespec type to be used as the data structure for all the new syscalls. 3. Add new config CONFIG_64BIT_TIME(intead of the CONFIG_COMPAT_TIME in [1] and [2] to switch to new definition of __kernel_timespec. It is the same as struct timespec otherwise. 4. Add new CONFIG_32BIT_TIME to conditionally compile compat syscalls.
* Changes since v1: * Introduce CONFIG_32BIT_TIME * Fixed zeroing out of higher order bits of tv_nsec * Included Arnd's changes to fix up use of compat headers
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile legacy time syscalls such as sys_nanosleep because this will need to enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to exclusively mark legacy syscalls.
Deepa Dinamani (10): compat: Make compat helpers independent of CONFIG_COMPAT include: Move compat_timespec/ timeval to compat_time.h compat: enable compat_get/put_timespec64 always arch: introduce CONFIG_64BIT_TIME arch: Introduce CONFIG_COMPAT_32BIT_TIME posix-clocks: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME include: Add new y2038 safe __kernel_timespec fix get_timespec64() for y2038 safe compat interfaces change time types to new y2038 safe __kernel_* types nanosleep: change time types to safe __kernel_* types
arch/Kconfig | 18 +++++++ arch/arm64/include/asm/compat.h | 11 ---- arch/arm64/include/asm/stat.h | 1 + arch/arm64/kernel/hw_breakpoint.c | 1 - arch/arm64/kernel/perf_regs.c | 2 +- arch/arm64/kernel/process.c | 1 - arch/mips/include/asm/compat.h | 11 ---- arch/mips/kernel/signal32.c | 2 +- arch/parisc/include/asm/compat.h | 11 ---- arch/powerpc/include/asm/compat.h | 11 ---- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/oprofile/backtrace.c | 2 +- arch/s390/hypfs/hypfs_sprp.c | 1 - arch/s390/include/asm/compat.h | 11 ---- arch/s390/include/asm/elf.h | 3 +- arch/s390/kvm/priv.c | 1 - arch/s390/pci/pci_clp.c | 1 - arch/sparc/include/asm/compat.h | 11 ---- arch/tile/include/asm/compat.h | 11 ---- arch/x86/events/core.c | 2 +- arch/x86/include/asm/compat.h | 11 ---- arch/x86/include/asm/ftrace.h | 2 +- arch/x86/include/asm/sys_ia32.h | 2 +- arch/x86/kernel/sys_x86_64.c | 2 +- drivers/s390/block/dasd_ioctl.c | 1 - drivers/s390/char/fs3270.c | 1 - drivers/s390/char/sclp_ctl.c | 1 - drivers/s390/char/vmcp.c | 1 - drivers/s390/cio/chsc_sch.c | 1 - drivers/s390/net/qeth_core_main.c | 2 +- drivers/staging/pi433/pi433_if.c | 2 +- include/linux/compat.h | 11 ++-- include/linux/compat_time.h | 23 +++++++++ include/linux/restart_block.h | 7 +-- include/linux/syscalls.h | 12 ++--- include/linux/time.h | 4 +- include/linux/time64.h | 10 +++- include/uapi/asm-generic/posix_types.h | 1 + include/uapi/linux/time.h | 7 +++ kernel/Makefile | 2 +- kernel/compat.c | 92 ++++++++++++++++++---------------- kernel/time/hrtimer.c | 10 ++-- kernel/time/posix-stubs.c | 12 +++-- kernel/time/posix-timers.c | 24 ++++++--- kernel/time/time.c | 10 +++- 45 files changed, 175 insertions(+), 190 deletions(-) create mode 100644 include/linux/compat_time.h
base-commit: b0a84f19a5161418d4360cd57603e94ed489915e
Many of the compat time syscalls are also repurposed as 32 bit native syscalls to provide backward compatibility while adding new y2038 safe sycalls. Enabling the helpers makes this possible.
Signed-off-by: Arnd Bergmann arnd@arndb.de Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/compat.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/compat.h b/include/linux/compat.h index 0fc36406f32c..b24aaf66feb4 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -8,8 +8,6 @@
#include <linux/types.h>
-#ifdef CONFIG_COMPAT - #include <linux/stat.h> #include <linux/param.h> /* for HZ */ #include <linux/sem.h> @@ -19,9 +17,11 @@ #include <linux/aio_abi.h> /* for aio_context_t */ #include <linux/unistd.h>
+#ifdef CONFIG_COMPAT #include <asm/compat.h> #include <asm/siginfo.h> #include <asm/signal.h> +#endif
#ifndef COMPAT_USE_64BIT_TIME #define COMPAT_USE_64BIT_TIME 0 @@ -58,6 +58,8 @@ } \ static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
+#ifdef CONFIG_COMPAT + #ifndef compat_user_stack_pointer #define compat_user_stack_pointer() current_user_stack_pointer() #endif @@ -771,7 +773,9 @@ static inline struct compat_timeval ns_to_compat_timeval(s64 nsec) #else /* !CONFIG_COMPAT */
#define is_compat_task() (0) +#ifndef in_compat_syscall static inline bool in_compat_syscall(void) { return false; } +#endif
#endif /* CONFIG_COMPAT */
All the current architecture specific defines for these are the same. Refactor these common defines to a common header file.
The new common linux/compat_time.h is also useful as it will eventually be used to hold all the defines that are needed for compat time types that support non y2038 safe types. New architectures need not have to define these new types as they will only use new y2038 safe syscalls. This file can be deleted after y2038 when we stop supporting non y2038 safe syscalls.
The patch also requires an operation similar to:
git grep "asm/compat.h" | cut -d ":" -f 1 | xargs -n 1 sed -i -e "s%asm/compat.h%linux/compat.h%g"
Cc: acme@kernel.org Cc: benh@kernel.crashing.org Cc: borntraeger@de.ibm.com Cc: catalin.marinas@arm.com Cc: cmetcalf@mellanox.com Cc: cohuck@redhat.com Cc: davem@davemloft.net Cc: deller@gmx.de Cc: devel@driverdev.osuosl.org Cc: gerald.schaefer@de.ibm.com Cc: gregkh@linuxfoundation.org Cc: heiko.carstens@de.ibm.com Cc: hoeppner@linux.vnet.ibm.com Cc: hpa@zytor.com Cc: jejb@parisc-linux.org Cc: jwi@linux.vnet.ibm.com Cc: linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-s390@vger.kernel.org Cc: mark.rutland@arm.com Cc: mingo@redhat.com Cc: mpe@ellerman.id.au Cc: oberpar@linux.vnet.ibm.com Cc: oprofile-list@lists.sf.net Cc: paulus@samba.org Cc: peterz@infradead.org Cc: ralf@linux-mips.org Cc: rostedt@goodmis.org Cc: rric@kernel.org Cc: schwidefsky@de.ibm.com Cc: sebott@linux.vnet.ibm.com Cc: sparclinux@vger.kernel.org Cc: sth@linux.vnet.ibm.com Cc: ubraun@linux.vnet.ibm.com Cc: will.deacon@arm.com Cc: x86@kernel.org Signed-off-by: Arnd Bergmann arnd@arndb.de Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com Acked-by: Steven Rostedt (VMware) rostedt@goodmis.org --- arch/arm64/include/asm/compat.h | 11 ----------- arch/arm64/include/asm/stat.h | 1 + arch/arm64/kernel/hw_breakpoint.c | 1 - arch/arm64/kernel/perf_regs.c | 2 +- arch/arm64/kernel/process.c | 1 - arch/mips/include/asm/compat.h | 11 ----------- arch/mips/kernel/signal32.c | 2 +- arch/parisc/include/asm/compat.h | 11 ----------- arch/powerpc/include/asm/compat.h | 11 ----------- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/oprofile/backtrace.c | 2 +- arch/s390/hypfs/hypfs_sprp.c | 1 - arch/s390/include/asm/compat.h | 11 ----------- arch/s390/include/asm/elf.h | 3 +-- arch/s390/kvm/priv.c | 1 - arch/s390/pci/pci_clp.c | 1 - arch/sparc/include/asm/compat.h | 11 ----------- arch/tile/include/asm/compat.h | 11 ----------- arch/x86/events/core.c | 2 +- arch/x86/include/asm/compat.h | 11 ----------- arch/x86/include/asm/ftrace.h | 2 +- arch/x86/include/asm/sys_ia32.h | 2 +- arch/x86/kernel/sys_x86_64.c | 2 +- drivers/s390/block/dasd_ioctl.c | 1 - drivers/s390/char/fs3270.c | 1 - drivers/s390/char/sclp_ctl.c | 1 - drivers/s390/char/vmcp.c | 1 - drivers/s390/cio/chsc_sch.c | 1 - drivers/s390/net/qeth_core_main.c | 2 +- drivers/staging/pi433/pi433_if.c | 2 +- include/linux/compat.h | 1 + include/linux/compat_time.h | 19 +++++++++++++++++++ 32 files changed, 32 insertions(+), 110 deletions(-) create mode 100644 include/linux/compat_time.h
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index a3c7f271ad4c..977b5064afc1 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -34,7 +34,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u16 __compat_uid_t; @@ -66,16 +65,6 @@ typedef u32 compat_ulong_t; typedef u64 compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { #ifdef __AARCH64EB__ short st_dev; diff --git a/arch/arm64/include/asm/stat.h b/arch/arm64/include/asm/stat.h index 15e35598ac40..eab738019707 100644 --- a/arch/arm64/include/asm/stat.h +++ b/arch/arm64/include/asm/stat.h @@ -20,6 +20,7 @@
#ifdef CONFIG_COMPAT
+#include <linux/compat_time.h> #include <asm/compat.h>
/* diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c index 749f81779420..bfa2b78cf0e3 100644 --- a/arch/arm64/kernel/hw_breakpoint.c +++ b/arch/arm64/kernel/hw_breakpoint.c @@ -29,7 +29,6 @@ #include <linux/ptrace.h> #include <linux/smp.h>
-#include <asm/compat.h> #include <asm/current.h> #include <asm/debug-monitors.h> #include <asm/hw_breakpoint.h> diff --git a/arch/arm64/kernel/perf_regs.c b/arch/arm64/kernel/perf_regs.c index 1d091d048d04..929fc369d0be 100644 --- a/arch/arm64/kernel/perf_regs.c +++ b/arch/arm64/kernel/perf_regs.c @@ -5,7 +5,7 @@ #include <linux/bug.h> #include <linux/sched/task_stack.h>
-#include <asm/compat.h> +#include <linux/compat.h> #include <asm/perf_regs.h> #include <asm/ptrace.h>
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index b2adcce7bc18..1acb3097d35b 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -52,7 +52,6 @@ #include <linux/thread_info.h>
#include <asm/alternative.h> -#include <asm/compat.h> #include <asm/cacheflush.h> #include <asm/exec.h> #include <asm/fpsimd.h> diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h index 49691331ada4..ccbf14e33282 100644 --- a/arch/mips/include/asm/compat.h +++ b/arch/mips/include/asm/compat.h @@ -14,7 +14,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_suseconds_t;
@@ -46,16 +45,6 @@ typedef u32 compat_ulong_t; typedef u64 compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; s32 st_pad1[3]; diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c index cf5c7c05e5a3..a6b04c70a8cb 100644 --- a/arch/mips/kernel/signal32.c +++ b/arch/mips/kernel/signal32.c @@ -14,7 +14,7 @@ #include <linux/signal.h> #include <linux/syscalls.h>
-#include <asm/compat.h> +#include <linux/compat.h> #include <asm/compat-signal.h> #include <linux/uaccess.h> #include <asm/unistd.h> diff --git a/arch/parisc/include/asm/compat.h b/arch/parisc/include/asm/compat.h index acf8aa07cbe0..90f844b16beb 100644 --- a/arch/parisc/include/asm/compat.h +++ b/arch/parisc/include/asm/compat.h @@ -13,7 +13,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u32 __compat_uid_t; @@ -40,16 +39,6 @@ typedef u32 compat_ulong_t; typedef u64 compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; /* dev_t is 32 bits on parisc */ compat_ino_t st_ino; /* 32 bits */ diff --git a/arch/powerpc/include/asm/compat.h b/arch/powerpc/include/asm/compat.h index 8a2aecfe9b02..517dbcfc2240 100644 --- a/arch/powerpc/include/asm/compat.h +++ b/arch/powerpc/include/asm/compat.h @@ -17,7 +17,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u32 __compat_uid_t; @@ -45,16 +44,6 @@ typedef u32 compat_ulong_t; typedef u64 compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; compat_ino_t st_ino; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 6b958414b4e0..a25cbe6482e2 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -42,7 +42,7 @@ #include <asm/paca.h> #include <asm/lppaca.h> #include <asm/cache.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/mmu.h> #include <asm/hvcall.h> #include <asm/xics.h> diff --git a/arch/powerpc/oprofile/backtrace.c b/arch/powerpc/oprofile/backtrace.c index ecc66d5f02c9..11ff763c03ad 100644 --- a/arch/powerpc/oprofile/backtrace.c +++ b/arch/powerpc/oprofile/backtrace.c @@ -11,7 +11,7 @@ #include <linux/sched.h> #include <asm/processor.h> #include <linux/uaccess.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/oprofile_impl.h>
#define STACK_SP(STACK) *(STACK) diff --git a/arch/s390/hypfs/hypfs_sprp.c b/arch/s390/hypfs/hypfs_sprp.c index ae0ed8dd5f1b..5d85a039391c 100644 --- a/arch/s390/hypfs/hypfs_sprp.c +++ b/arch/s390/hypfs/hypfs_sprp.c @@ -13,7 +13,6 @@ #include <linux/string.h> #include <linux/types.h> #include <linux/uaccess.h> -#include <asm/compat.h> #include <asm/diag.h> #include <asm/sclp.h> #include "hypfs.h" diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h index 5e6a63641a5f..7e587eb9fb58 100644 --- a/arch/s390/include/asm/compat.h +++ b/arch/s390/include/asm/compat.h @@ -53,7 +53,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u16 __compat_uid_t; @@ -97,16 +96,6 @@ typedef struct { u32 gprs_high[NUM_GPRS]; } s390_compat_regs_high;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; u16 __pad1; diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h index 1a61b1b997f2..3e15c77c7c9a 100644 --- a/arch/s390/include/asm/elf.h +++ b/arch/s390/include/asm/elf.h @@ -126,7 +126,7 @@ */
#include <asm/ptrace.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/syscall.h> #include <asm/user.h>
@@ -136,7 +136,6 @@ typedef s390_regs elf_gregset_t; typedef s390_fp_regs compat_elf_fpregset_t; typedef s390_compat_regs compat_elf_gregset_t;
-#include <linux/compat.h> #include <linux/sched/mm.h> /* for task_struct */ #include <asm/mmu_context.h>
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c index c954ac49eee4..07eebba4bd37 100644 --- a/arch/s390/kvm/priv.c +++ b/arch/s390/kvm/priv.c @@ -29,7 +29,6 @@ #include <asm/gmap.h> #include <asm/io.h> #include <asm/ptrace.h> -#include <asm/compat.h> #include <asm/sclp.h> #include "gaccess.h" #include "kvm-s390.h" diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c index 93cd0f1ca12b..19b2d2a9b43d 100644 --- a/arch/s390/pci/pci_clp.c +++ b/arch/s390/pci/pci_clp.c @@ -19,7 +19,6 @@ #include <linux/uaccess.h> #include <asm/pci_debug.h> #include <asm/pci_clp.h> -#include <asm/compat.h> #include <asm/clp.h> #include <uapi/asm/clp.h>
diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h index fa38c78de0f0..5b49b6a66cdb 100644 --- a/arch/sparc/include/asm/compat.h +++ b/arch/sparc/include/asm/compat.h @@ -11,7 +11,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u16 __compat_uid_t; @@ -39,16 +38,6 @@ typedef u32 compat_ulong_t; typedef u64 compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; compat_ino_t st_ino; diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h index 62a7b83025dd..21ab5b80f5c7 100644 --- a/arch/tile/include/asm/compat.h +++ b/arch/tile/include/asm/compat.h @@ -29,7 +29,6 @@ typedef u32 compat_ulong_t; typedef u32 compat_size_t; typedef s32 compat_ssize_t; typedef s32 compat_off_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef u32 compat_ino_t; typedef u32 compat_caddr_t; @@ -59,16 +58,6 @@ typedef unsigned long compat_elf_greg_t; #define COMPAT_ELF_NGREG (sizeof(struct pt_regs) / sizeof(compat_elf_greg_t)) typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - #define compat_stat stat #define compat_statfs statfs
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 140d33288e78..6b8961912781 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2391,7 +2391,7 @@ static unsigned long get_segment_base(unsigned int segment)
#ifdef CONFIG_IA32_EMULATION
-#include <asm/compat.h> +#include <linux/compat.h>
static inline int perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *entry) diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h index 2cbd75dd2fd3..160804ed875e 100644 --- a/arch/x86/include/asm/compat.h +++ b/arch/x86/include/asm/compat.h @@ -17,7 +17,6 @@
typedef u32 compat_size_t; typedef s32 compat_ssize_t; -typedef s32 compat_time_t; typedef s32 compat_clock_t; typedef s32 compat_pid_t; typedef u16 __compat_uid_t; @@ -46,16 +45,6 @@ typedef u32 compat_u32; typedef u64 __attribute__((aligned(4))) compat_u64; typedef u32 compat_uptr_t;
-struct compat_timespec { - compat_time_t tv_sec; - s32 tv_nsec; -}; - -struct compat_timeval { - compat_time_t tv_sec; - s32 tv_usec; -}; - struct compat_stat { compat_dev_t st_dev; u16 __pad1; diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h index 09ad88572746..db25aa15b705 100644 --- a/arch/x86/include/asm/ftrace.h +++ b/arch/x86/include/asm/ftrace.h @@ -49,7 +49,7 @@ int ftrace_int3_handler(struct pt_regs *regs); #if !defined(__ASSEMBLY__) && !defined(COMPILE_OFFSETS)
#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION) -#include <asm/compat.h> +#include <linux/compat.h>
/* * Because ia32 syscalls do not map to x86_64 syscall numbers diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index 82c34ee25a65..8527b26ad36f 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h @@ -16,7 +16,7 @@ #include <linux/linkage.h> #include <linux/types.h> #include <linux/signal.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/ia32.h>
/* ia32/sys_ia32.c */ diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 676774b9bb8d..9d8ea652e31c 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c @@ -19,7 +19,7 @@ #include <linux/elf.h>
#include <asm/elf.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/ia32.h> #include <asm/syscalls.h> #include <asm/mpx.h> diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 7bdc6aaa0ba3..2016e0ed5865 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -18,7 +18,6 @@ #include <linux/fs.h> #include <linux/blkpg.h> #include <linux/slab.h> -#include <asm/compat.h> #include <asm/ccwdev.h> #include <asm/schid.h> #include <asm/cmb.h> diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c index 61822480a2a0..16a4e8528bbc 100644 --- a/drivers/s390/char/fs3270.c +++ b/drivers/s390/char/fs3270.c @@ -19,7 +19,6 @@ #include <linux/slab.h> #include <linux/types.h>
-#include <asm/compat.h> #include <asm/ccwdev.h> #include <asm/cio.h> #include <asm/ebcdic.h> diff --git a/drivers/s390/char/sclp_ctl.c b/drivers/s390/char/sclp_ctl.c index a78cea0c3a09..248b5db3eaa8 100644 --- a/drivers/s390/char/sclp_ctl.c +++ b/drivers/s390/char/sclp_ctl.c @@ -14,7 +14,6 @@ #include <linux/init.h> #include <linux/ioctl.h> #include <linux/fs.h> -#include <asm/compat.h> #include <asm/sclp_ctl.h> #include <asm/sclp.h>
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c index 17e411c57576..948ce82a7725 100644 --- a/drivers/s390/char/vmcp.c +++ b/drivers/s390/char/vmcp.c @@ -23,7 +23,6 @@ #include <linux/mutex.h> #include <linux/cma.h> #include <linux/mm.h> -#include <asm/compat.h> #include <asm/cpcmd.h> #include <asm/debug.h> #include <asm/vmcp.h> diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c index 0015729d917d..8d9f36625ba5 100644 --- a/drivers/s390/cio/chsc_sch.c +++ b/drivers/s390/cio/chsc_sch.c @@ -16,7 +16,6 @@ #include <linux/miscdevice.h> #include <linux/kernel_stat.h>
-#include <asm/compat.h> #include <asm/cio.h> #include <asm/chsc.h> #include <asm/isc.h> diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c index 98a7f84540ab..a93591c6c9b0 100644 --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c @@ -27,7 +27,7 @@ #include <asm/chpid.h> #include <asm/io.h> #include <asm/sysinfo.h> -#include <asm/compat.h> +#include <linux/compat.h> #include <asm/diag.h> #include <asm/cio.h> #include <asm/ccwdev.h> diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c index 2a205c6173dc..473831ff8745 100644 --- a/drivers/staging/pi433/pi433_if.c +++ b/drivers/staging/pi433/pi433_if.c @@ -48,7 +48,7 @@ #include <linux/wait.h> #include <linux/spi/spi.h> #ifdef CONFIG_COMPAT -#include <asm/compat.h> +#include <linux/compat.h> #endif
#include "pi433_if.h" diff --git a/include/linux/compat.h b/include/linux/compat.h index b24aaf66feb4..2f79dac5ed65 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -7,6 +7,7 @@ */
#include <linux/types.h> +#include <linux/compat_time.h>
#include <linux/stat.h> #include <linux/param.h> /* for HZ */ diff --git a/include/linux/compat_time.h b/include/linux/compat_time.h new file mode 100644 index 000000000000..56a54a1e4355 --- /dev/null +++ b/include/linux/compat_time.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_COMPAT_TIME_H +#define _LINUX_COMPAT_TIME_H + +#include <linux/types.h> + +typedef s32 compat_time_t; + +struct compat_timespec { + compat_time_t tv_sec; + s32 tv_nsec; +}; + +struct compat_timeval { + compat_time_t tv_sec; + s32 tv_usec; +}; + +#endif /* _LINUX_COMPAT_TIME_H */
These functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/compat.h | 2 - include/linux/compat_time.h | 4 ++ kernel/Makefile | 2 +- kernel/compat.c | 92 +++++++++++++++++++++++---------------------- 4 files changed, 53 insertions(+), 47 deletions(-)
diff --git a/include/linux/compat.h b/include/linux/compat.h index 2f79dac5ed65..e06f11886000 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -168,8 +168,6 @@ extern int compat_get_timespec(struct timespec *, const void __user *); extern int compat_put_timespec(const struct timespec *, void __user *); extern int compat_get_timeval(struct timeval *, const void __user *); extern int compat_put_timeval(const struct timeval *, void __user *); -extern int compat_get_timespec64(struct timespec64 *, const void __user *); -extern int compat_put_timespec64(const struct timespec64 *, void __user *); extern int get_compat_itimerspec64(struct itimerspec64 *its, const struct compat_itimerspec __user *uits); extern int put_compat_itimerspec64(const struct itimerspec64 *its, diff --git a/include/linux/compat_time.h b/include/linux/compat_time.h index 56a54a1e4355..31f2774f1994 100644 --- a/include/linux/compat_time.h +++ b/include/linux/compat_time.h @@ -3,6 +3,7 @@ #define _LINUX_COMPAT_TIME_H
#include <linux/types.h> +#include <linux/time64.h>
typedef s32 compat_time_t;
@@ -16,4 +17,7 @@ struct compat_timeval { s32 tv_usec; };
+extern int compat_get_timespec64(struct timespec64 *, const void __user *); +extern int compat_put_timespec64(const struct timespec64 *, void __user *); + #endif /* _LINUX_COMPAT_TIME_H */ diff --git a/kernel/Makefile b/kernel/Makefile index 172d151d429c..2e3df3deee18 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -66,7 +66,7 @@ obj-$(CONFIG_KEXEC_CORE) += kexec_core.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o -obj-$(CONFIG_COMPAT) += compat.o +obj-y += compat.o obj-$(CONFIG_CGROUPS) += cgroup/ obj-$(CONFIG_UTS_NS) += utsname.o obj-$(CONFIG_USER_NS) += user_namespace.o diff --git a/kernel/compat.c b/kernel/compat.c index d1cee656a7ed..42653ac977c0 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -30,6 +30,52 @@
#include <linux/uaccess.h>
+static int __compat_get_timespec64(struct timespec64 *ts64, + const struct compat_timespec __user *cts) +{ + struct compat_timespec ts; + int ret; + + ret = copy_from_user(&ts, cts, sizeof(ts)); + if (ret) + return -EFAULT; + + ts64->tv_sec = ts.tv_sec; + ts64->tv_nsec = ts.tv_nsec; + + return 0; +} + +static int __compat_put_timespec64(const struct timespec64 *ts64, + struct compat_timespec __user *cts) +{ + struct compat_timespec ts = { + .tv_sec = ts64->tv_sec, + .tv_nsec = ts64->tv_nsec + }; + return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0; +} + +int compat_get_timespec64(struct timespec64 *ts, const void __user *uts) +{ + if (COMPAT_USE_64BIT_TIME) + return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0; + else + return __compat_get_timespec64(ts, uts); +} +EXPORT_SYMBOL_GPL(compat_get_timespec64); + +int compat_put_timespec64(const struct timespec64 *ts, void __user *uts) +{ + if (COMPAT_USE_64BIT_TIME) + return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0; + else + return __compat_put_timespec64(ts, uts); +} +EXPORT_SYMBOL_GPL(compat_put_timespec64); + +#ifdef CONFIG_COMPAT + int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp) { struct compat_timex tx32; @@ -120,50 +166,6 @@ static int __compat_put_timespec(const struct timespec *ts, struct compat_timesp __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; }
-static int __compat_get_timespec64(struct timespec64 *ts64, - const struct compat_timespec __user *cts) -{ - struct compat_timespec ts; - int ret; - - ret = copy_from_user(&ts, cts, sizeof(ts)); - if (ret) - return -EFAULT; - - ts64->tv_sec = ts.tv_sec; - ts64->tv_nsec = ts.tv_nsec; - - return 0; -} - -static int __compat_put_timespec64(const struct timespec64 *ts64, - struct compat_timespec __user *cts) -{ - struct compat_timespec ts = { - .tv_sec = ts64->tv_sec, - .tv_nsec = ts64->tv_nsec - }; - return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0; -} - -int compat_get_timespec64(struct timespec64 *ts, const void __user *uts) -{ - if (COMPAT_USE_64BIT_TIME) - return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0; - else - return __compat_get_timespec64(ts, uts); -} -EXPORT_SYMBOL_GPL(compat_get_timespec64); - -int compat_put_timespec64(const struct timespec64 *ts, void __user *uts) -{ - if (COMPAT_USE_64BIT_TIME) - return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0; - else - return __compat_put_timespec64(ts, uts); -} -EXPORT_SYMBOL_GPL(compat_put_timespec64); - int compat_get_timeval(struct timeval *tv, const void __user *utv) { if (COMPAT_USE_64BIT_TIME) @@ -582,3 +584,5 @@ void __user *compat_alloc_user_space(unsigned long len) return ptr; } EXPORT_SYMBOL_GPL(compat_alloc_user_space); + +#endif
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
These functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com
[...]
If I'm not mistaken, these functions will be needed only if CONFIG_COMPAT_32BIT_TIME is enabled. Should this be combined with patch #5?
Ben.
On Thu, Dec 14, 2017 at 3:27 PM, Ben Hutchings ben.hutchings@codethink.co.uk wrote:
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
These functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com
[...]
If I'm not mistaken, these functions will be needed only if CONFIG_COMPAT_32BIT_TIME is enabled. Should this be combined with patch #5?
This was purposely decided to be included unconditionally as the only argument against making them conditional is code size. But, these being very small functions it shouldn't matter all that much. I had left this open for discussion. Since I did not hear any preferences, I will make these conditional as Arnd and I discussed.
No, this should not be combined with patch 5. The purpose of that patch is not to include all the code that is conditional upon that config.
-Deepa
There are a total of 53 system calls (aside from ioctl) that pass a time_t or derived data structure as an argument, and in order to extend time_t to 64-bit, we have to replace them with new system calls and keep providing backwards compatibility.
To avoid adding completely new and untested code for this purpose, we introduce a new CONFIG_64BIT_TIME symbol. Every architecture that supports new 64 bit time_t syscalls enables this config via ARCH_HAS_64BIT_TIME.
After this is done for all architectures, the CONFIG_64BIT_TIME symbol will be deleted.
Signed-off-by: Arnd Bergmann arnd@arndb.de Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- arch/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/arch/Kconfig b/arch/Kconfig index 4f03534bfa6b..11810c29c1fa 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -873,6 +873,17 @@ config OLD_SIGACTION config COMPAT_OLD_SIGACTION bool
+config ARCH_HAS_64BIT_TIME + def_bool n + +config 64BIT_TIME + def_bool ARCH_HAS_64BIT_TIME + help + This should be selected by all architectures that need to support + new system calls with a 64-bit time_t. This is relevant on all 32-bit + architectures, and 64-bit architectures as part of compat syscall + handling. + config ARCH_NO_COHERENT_DMA_MMAP bool
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
There are a total of 53 system calls (aside from ioctl) that pass a time_t or derived data structure as an argument, and in order to extend time_t to 64-bit, we have to replace them with new system calls and keep providing backwards compatibility.
To avoid adding completely new and untested code for this purpose, we introduce a new CONFIG_64BIT_TIME symbol. Every architecture that supports new 64 bit time_t syscalls enables this config via ARCH_HAS_64BIT_TIME.
After this is done for all architectures, the CONFIG_64BIT_TIME symbol will be deleted.
Signed-off-by: Arnd Bergmann arnd@arndb.de Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com
arch/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/arch/Kconfig b/arch/Kconfig index 4f03534bfa6b..11810c29c1fa 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -873,6 +873,17 @@ config OLD_SIGACTION config COMPAT_OLD_SIGACTION
bool
+config ARCH_HAS_64BIT_TIME
- def_bool n
+config 64BIT_TIME
- def_bool ARCH_HAS_64BIT_TIME
- help
- This should be selected by all architectures that need to support
- new system calls with a 64-bit time_t. This is relevant on all 32-bit
- architectures, and 64-bit architectures as part of compat syscall
- handling.
Doesn't this text belong with ARCH_HAS_64BIT_TIME?
Ben.
config ARCH_NO_COHERENT_DMA_MMAP bool
Compat functions are now used to support 32 bit time_t in compat mode on 64 bit architectures and in native mode on 32 bit architectures.
Introduce COMPAT_32BIT_TIME to conditionally compile these functions.
Note that turning off 32 bit time_t support requires more changes on architecture side. For instance, architecure syscall tables need to be updated to drop support for 32 bit time_t syscalls.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- arch/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/Kconfig b/arch/Kconfig index 11810c29c1fa..e75c5239c885 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -884,6 +884,13 @@ config 64BIT_TIME architectures, and 64-bit architectures as part of compat syscall handling.
+config COMPAT_32BIT_TIME + def_bool (!64BIT && 64BIT_TIME) || COMPAT + help + This enables 32 bit time_t support in addition to 64 bit time_t support. + This is relevant on all 32-bit architectures, and 64-bit architectures + as part of compat syscall handling. + config ARCH_NO_COHERENT_DMA_MMAP bool
clock_gettime, clock_settime, clock_getres and clock_nanosleep compat syscalls are also repurposed to provide backward compatibility to support 32 bit time_t on 32 bit systems.
Note that nanosleep compat syscall will also be treated the same way as the above syscalls as it shares common handler functions with clock_nanosleep. But, there is no plan to provide y2038 safe solution for nanosleep.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- kernel/time/hrtimer.c | 2 +- kernel/time/posix-stubs.c | 2 ++ kernel/time/posix-timers.c | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index d32520840fde..bbd740171554 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1557,7 +1557,7 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp, return hrtimer_nanosleep(&tu, HRTIMER_MODE_REL, CLOCK_MONOTONIC); }
-#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, struct compat_timespec __user *, rmtp) diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index b258bee13b02..0645cfa93609 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -148,7 +148,9 @@ COMPAT_SYS_NI(timer_settime); COMPAT_SYS_NI(timer_gettime); COMPAT_SYS_NI(getitimer); COMPAT_SYS_NI(setitimer); +#endif
+#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, struct compat_timespec __user *, tp) { diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 13d6881f908b..67ed5966eccd 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1107,7 +1107,7 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, return error; }
-#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, struct compat_timespec __user *, tp) @@ -1142,6 +1142,10 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, return err; }
+#endif + +#ifdef CONFIG_COMPAT + COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, struct compat_timex __user *, utp) { @@ -1166,6 +1170,10 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, return err; }
+#endif + +#ifdef CONFIG_COMPAT_32BIT_TIME + COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, struct compat_timespec __user *, tp) { @@ -1221,7 +1229,8 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, return kc->nsleep(which_clock, flags, &t); }
-#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME + COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, struct compat_timespec __user *, rqtp, struct compat_timespec __user *, rmtp) @@ -1246,6 +1255,7 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
return kc->nsleep(which_clock, flags, &t); } + #endif
static const struct k_clock clock_realtime = {
The new struct __kernel_timespec is similar to current internal kernel struct timespec64 on 64 bit architecture. The compat structure however is similar to below on little endian systems (padding and tv_nsec are switched for big endian systems):
typedef s32 compat_long_t; typedef s64 compat_kernel_time64_t;
struct compat_kernel_timespec { compat_kernel_time64_t tv_sec; compat_long_t tv_nsec; compat_long_t padding; };
This allows for both the native and compat representations to be the same and syscalls using this type as part of their ABI can have a single entry point to both.
Note that the compat define is not included anywhere in the kernel explicitly to avoid confusion.
These types will be used by the new syscalls that will be introduced in the consequent patches. Most of the new syscalls are just an update to the existing native ones with this new type. Hence, put this new type under an ifdef so that the architectures can define CONFIG_64BIT_TIME when they are ready to handle this switch.
Cc: linux-arch@vger.kernel.org Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/time64.h | 10 +++++++++- include/uapi/asm-generic/posix_types.h | 1 + include/uapi/linux/time.h | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/linux/time64.h b/include/linux/time64.h index 93d39499838e..0d96887ba4e0 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -2,12 +2,20 @@ #ifndef _LINUX_TIME64_H #define _LINUX_TIME64_H
-#include <uapi/linux/time.h> #include <linux/math64.h>
typedef __s64 time64_t; typedef __u64 timeu64_t;
+/* CONFIG_64BIT_TIME enables new 64 bit time_t syscalls in the compat path + * and 32-bit emulation. + */ +#ifndef CONFIG_64BIT_TIME +#define __kernel_timespec timespec +#endif + +#include <uapi/linux/time.h> + #if __BITS_PER_LONG == 64 /* this trick allows us to optimize out timespec64_to_timespec */ # define timespec64 timespec diff --git a/include/uapi/asm-generic/posix_types.h b/include/uapi/asm-generic/posix_types.h index 5e6ea22bd525..f0733a26ebfc 100644 --- a/include/uapi/asm-generic/posix_types.h +++ b/include/uapi/asm-generic/posix_types.h @@ -87,6 +87,7 @@ typedef struct { typedef __kernel_long_t __kernel_off_t; typedef long long __kernel_loff_t; typedef __kernel_long_t __kernel_time_t; +typedef long long __kernel_time64_t; typedef __kernel_long_t __kernel_clock_t; typedef int __kernel_timer_t; typedef int __kernel_clockid_t; diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 53f8dd84beb5..0ad4510884b0 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -42,6 +42,13 @@ struct itimerval { struct timeval it_value; /* current value */ };
+#ifndef __kernel_timespec +struct __kernel_timespec { + __kernel_time64_t tv_sec; /* seconds */ + long long tv_nsec; /* nanoseconds */ +}; +#endif + /* * The IDs of the various system clocks (for POSIX.1b interval timers): */
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
The new struct __kernel_timespec is similar to current internal kernel struct timespec64 on 64 bit architecture. The compat structure however is similar to below on little endian systems (padding and tv_nsec are switched for big endian systems):
typedef s32 compat_long_t; typedef s64 compat_kernel_time64_t;
struct compat_kernel_timespec { compat_kernel_time64_t tv_sec; compat_long_t tv_nsec; compat_long_t padding; };
This allows for both the native and compat representations to be the same and syscalls using this type as part of their ABI can have a single entry point to both.
Note that the compat define is not included anywhere in the kernel explicitly to avoid confusion.
If I understand correctly, the intent here is that C libraries will be allowed to define struct timespec like that when appropriate feature macros are enabled. Could you spell that out in the commit message, and also the need to clear padding on the kernel side?
[...]
--- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -42,6 +42,13 @@ struct itimerval {
struct timeval it_value; /* current value */
}; +#ifndef __kernel_timespec +struct __kernel_timespec {
- __kernel_time64_t tv_sec; /* seconds */
- long long tv_nsec; /* nanoseconds */
+}; +#endif
I wonder if it makes sense to override the alignment of this structure? (64-bit types are aligned differently on 32-bit vs 64-bit x86, but not other compat cases.) It might reduce the need for conversions in compat code elsewhere later.
Ben.
/* * The IDs of the various system clocks (for POSIX.1b interval timers): */
On Fri, Dec 15, 2017 at 1:11 AM, Ben Hutchings ben.hutchings@codethink.co.uk wrote:
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
--- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -42,6 +42,13 @@ struct itimerval {
struct timeval it_value; /* current value */
};
+#ifndef __kernel_timespec +struct __kernel_timespec {
__kernel_time64_t tv_sec; /* seconds */
long long tv_nsec; /* nanoseconds */
+}; +#endif
I wonder if it makes sense to override the alignment of this structure? (64-bit types are aligned differently on 32-bit vs 64-bit x86, but not other compat cases.) It might reduce the need for conversions in compat code elsewhere later.
I think the alignment here should be agreed with glibc so they use the same alignment for their new timespec. I don't see a specific mention of this at https://sourceware.org/glibc/wiki/Y2038ProofnessDesign#struct___timespec64 so I'm adding Albert and libc-alpha to Cc for clarification.
I agree it would simplify things a bit to ensure that time64_t and __timespec64/__kernel_timespec have a 64-bit alignment even on x86-32, but I don't know if there is precedent for using gcc __attribute__((aligned(8)) on POSIX data types, of if that might cause problems e.g. for non-gnu compilers.
Arnd
get/put_timespec64() interfaces will eventually be used for conversions between the new y2038 safe struct __kernel_timespec and struct timespec64.
The new y2038 safe syscalls have a common entry for native and compat interfaces. On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not garuntee zeroing of these. If used without zeroing, kernel might be at risk of using timespec values incorrectly.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/time.h | 4 ++-- kernel/time/time.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/time.h b/include/linux/time.h index 4b62a2c0a661..aed74463592d 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -10,9 +10,9 @@ extern struct timezone sys_tz;
int get_timespec64(struct timespec64 *ts, - const struct timespec __user *uts); + const struct __kernel_timespec __user *uts); int put_timespec64(const struct timespec64 *ts, - struct timespec __user *uts); + struct __kernel_timespec __user *uts); int get_itimerspec64(struct itimerspec64 *it, const struct itimerspec __user *uit); int put_itimerspec64(const struct itimerspec64 *it, diff --git a/kernel/time/time.c b/kernel/time/time.c index bd4e6c7dd689..9de69f3e4f44 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -841,7 +841,7 @@ struct timespec64 timespec64_add_safe(const struct timespec64 lhs, }
int get_timespec64(struct timespec64 *ts, - const struct timespec __user *uts) + const struct __kernel_timespec __user *uts) { struct timespec kts; int ret; @@ -851,6 +851,11 @@ int get_timespec64(struct timespec64 *ts, return -EFAULT;
ts->tv_sec = kts.tv_sec; + + /* Zero out the padding for 32 bit systems or in compat mode */ + if (IS_ENABLED(CONFIG_64BIT_TIME) || !IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) + kts.tv_nsec &= 0xFFFFFFFFUL; + ts->tv_nsec = kts.tv_nsec;
return 0; @@ -858,12 +863,13 @@ int get_timespec64(struct timespec64 *ts, EXPORT_SYMBOL_GPL(get_timespec64);
int put_timespec64(const struct timespec64 *ts, - struct timespec __user *uts) + struct __kernel_timespec __user *uts) { struct timespec kts = { .tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec }; + return copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0; } EXPORT_SYMBOL_GPL(put_timespec64);
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
get/put_timespec64() interfaces will eventually be used for conversions between the new y2038 safe struct __kernel_timespec and struct timespec64.
The new y2038 safe syscalls have a common entry for native and compat interfaces. On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not garuntee zeroing of these. If used without
Spelling: "guarantee"
[...]
--- a/kernel/time/time.c +++ b/kernel/time/time.c
[...]
@@ -851,6 +851,11 @@ int get_timespec64(struct timespec64 *ts, return -EFAULT; ts->tv_sec = kts.tv_sec;
- /* Zero out the padding for 32 bit systems or in compat mode */
- if (IS_ENABLED(CONFIG_64BIT_TIME) || !IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
kts.tv_nsec &= 0xFFFFFFFFUL;
[...]
I don't understand the condition here. Suppose we're building for an architecture that enables the new syscalls and selects ARCH_64BIT_TIME, but we also enable 64BIT. Then the above condition ends up as: if (1 || 0 || in_compat_syscall()) so it's always true.
Should the condition be: if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) or is your intent that architectures only select ARCH_64BIT_TIME if 64BIT is not enabled?
Ben.
On Fri, Dec 15, 2017 at 1:21 AM, Ben Hutchings ben.hutchings@codethink.co.uk wrote:
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
get/put_timespec64() interfaces will eventually be used for conversions between the new y2038 safe struct __kernel_timespec and struct timespec64.
The new y2038 safe syscalls have a common entry for native and compat interfaces. On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not garuntee zeroing of these. If used without
Spelling: "guarantee"
[...]
--- a/kernel/time/time.c +++ b/kernel/time/time.c
[...]
@@ -851,6 +851,11 @@ int get_timespec64(struct timespec64 *ts, return -EFAULT;
ts->tv_sec = kts.tv_sec;
/* Zero out the padding for 32 bit systems or in compat mode */
if (IS_ENABLED(CONFIG_64BIT_TIME) || !IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
kts.tv_nsec &= 0xFFFFFFFFUL;
[...]
I don't understand the condition here. Suppose we're building for an architecture that enables the new syscalls and selects ARCH_64BIT_TIME, but we also enable 64BIT. Then the above condition ends up as: if (1 || 0 || in_compat_syscall()) so it's always true.
Should the condition be: if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) or is your intent that architectures only select ARCH_64BIT_TIME if 64BIT is not enabled?
My understanding was that we always enable CONFIG_64BIT_TIME when 64BIT is enabled.
For a 64-bit architecture, we must not clear the upper 32 bits of tv_nsec, but instead need later check them for being nonzero. I think the correct condition would be
if ((IS_ENABLED(CONFIG_64BIT_TIME) && !IS_ENABLED(CONFIG_64BIT)) || in_compat_syscall())
Two more thoughts:
- The temporary variable here is defined as 'struct timespec', this must be changed to __kernel_timespec for the function to work correctly once we switch a 32-bit architecture over. Doing it in this patch is probably the best time for that change.
- I had an idea to handle the copying of timespec/timeval with a one-size-fits-all function and multiple wrappers around it, such as
enum user_ts_type { USER_TS_TIMEVAL = 1, USER_TS_32 = 2, USER_TS_CLEARNSEC = 4, USER_TS_NOCHECK = 8, };
/* native handlers want to check on 64-bit but zero on 32-bit */ #define USER_TS_NATIVE (IS_ENABLED(CONFIG_64BIT) ? 0 : USER_TS_CLEARNSEC)
/* compat handlers accessing 64-bit time structs always want to clear the upper half */ #define USER_TS_COMPAT64 USER_TS_CLEARNSEC
/* on x32, we always use 64-bit time_t but want to clear the upper half */ #define USER_TS_COMPAT32 (COMPAT_USE_64BIT_TIME) ? USER_TS_CLEARNSEC : USER_TS_32)
int get_timestruct(struct timespec64 *ts, const void __user *uts, enum user_ts_type flags) { int ret;
if (flags & USER_TS_32) { struct compat_timespec ts32; ret = copy_from_user(&ts32, uts, sizeof(ts32)); if (ret) return -EFAULT; ts->tv_sec = ts32.tv_sec; ts->tv_nsec = ts32.tv_nsec; } else { ret = copy_from_user(&ts, uts, sizeof(*ts)); if (ret) return -EFAULT; if (flags & USER_TS_CLEARNSEC) ts->tv_nsec &= 0xFFFFFFFFUL; }
if (flags & USER_TS_TIMEVAL) { if (!(flags & USER_TS_NOCHECK) && ts->tv_nsec >= USEC_PER_SEC) return -EINVAL;
ts->tv_nsec *= NSEC_PER_USEC; } else { if (!(flags & USER_TS_NOCHECK) && ts->tv_nsec >= NSEC_PER_SEC) return -EINVAL; }
return 0; }
int get_timespec64(struct timespec64 *ts, const struct compat_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_NATIVE); }
int get_compat_timespec32(struct timespec64 *ts, const struct compat_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_COMPAT32); }
int get_compat_timespec64(struct timespec64 *ts, const struct __kernel_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_COMPAT64); }
While working on the driver patches I encountered lots of different combinations of those that might be interesting here, so we could have wrappers for the most common ones and call get_timestruct() and put_timestruct() directly for the less common variations. Am I taking it too far here, or would that make sense?
Arnd
On Fri, 2017-12-15 at 13:02 +0100, Arnd Bergmann wrote: [...]
- I had an idea to handle the copying of timespec/timeval with a
one-size-fits-all function and multiple wrappers around it, such as
enum user_ts_type { USER_TS_TIMEVAL = 1, USER_TS_32 = 2, USER_TS_CLEARNSEC = 4, USER_TS_NOCHECK = 8, };
[...]
While working on the driver patches I encountered lots of different combinations of those that might be interesting here, so we could have wrappers for the most common ones and call get_timestruct() and put_timestruct() directly for the less common variations. Am I taking it too far here, or would that make sense?
I don't think I've reviewed enough time-handling stuff to know, but I can certainly believe that this could be worth doing.
Ben.
On Fri, Dec 15, 2017 at 4:02 AM, Arnd Bergmann arnd@arndb.de wrote:
On Fri, Dec 15, 2017 at 1:21 AM, Ben Hutchings ben.hutchings@codethink.co.uk wrote:
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote:
get/put_timespec64() interfaces will eventually be used for conversions between the new y2038 safe struct __kernel_timespec and struct timespec64.
The new y2038 safe syscalls have a common entry for native and compat interfaces. On compat interfaces, the high order bits of nanoseconds should be zeroed out. This is because the application code or the libc do not garuntee zeroing of these. If used without
Spelling: "guarantee"
[...]
--- a/kernel/time/time.c +++ b/kernel/time/time.c
[...]
@@ -851,6 +851,11 @@ int get_timespec64(struct timespec64 *ts, return -EFAULT;
ts->tv_sec = kts.tv_sec;
/* Zero out the padding for 32 bit systems or in compat mode */
if (IS_ENABLED(CONFIG_64BIT_TIME) || !IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
kts.tv_nsec &= 0xFFFFFFFFUL;
[...]
I don't understand the condition here. Suppose we're building for an architecture that enables the new syscalls and selects ARCH_64BIT_TIME, but we also enable 64BIT. Then the above condition ends up as: if (1 || 0 || in_compat_syscall()) so it's always true.
Should the condition be: if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) or is your intent that architectures only select ARCH_64BIT_TIME if 64BIT is not enabled?
My understanding was that we always enable CONFIG_64BIT_TIME when 64BIT is enabled.
For a 64-bit architecture, we must not clear the upper 32 bits of tv_nsec, but instead need later check them for being nonzero. I think the correct condition would be
if ((IS_ENABLED(CONFIG_64BIT_TIME) && !IS_ENABLED(CONFIG_64BIT)) || in_compat_syscall())
I haven't enabled this by default on all 64 bit architectures. The reason I have the condition this way is that I haven't decided how I want to handle 64 bit time on x32, and x86 is the first architecture I plan to enable this for. At that time, this will be reworked based on whatever solution we agree on. I did not want to depend on COMPAT_USE_64BIT_TIME yet.
But, I did mean to do
if (IS_ENABLED(CONFIG_64BIT_TIME) && (!IS_ENABLED(CONFIG_64BIT)) || in_compat_syscall()))
I will update this.
Two more thoughts:
- The temporary variable here is defined as 'struct timespec', this must be changed to __kernel_timespec for the function to work correctly once we switch a 32-bit architecture over. Doing it in this patch is probably the best time for that change.
Thanks, will do. I will post an update.
- I had an idea to handle the copying of timespec/timeval with a
one-size-fits-all function and multiple wrappers around it, such as
enum user_ts_type { USER_TS_TIMEVAL = 1, USER_TS_32 = 2, USER_TS_CLEARNSEC = 4, USER_TS_NOCHECK = 8, };
/* native handlers want to check on 64-bit but zero on 32-bit */ #define USER_TS_NATIVE (IS_ENABLED(CONFIG_64BIT) ? 0 : USER_TS_CLEARNSEC)
/* compat handlers accessing 64-bit time structs always want to clear the upper half */ #define USER_TS_COMPAT64 USER_TS_CLEARNSEC
/* on x32, we always use 64-bit time_t but want to clear the upper half */ #define USER_TS_COMPAT32 (COMPAT_USE_64BIT_TIME) ? USER_TS_CLEARNSEC : USER_TS_32)
int get_timestruct(struct timespec64 *ts, const void __user *uts, enum user_ts_type flags) { int ret;
if (flags & USER_TS_32) { struct compat_timespec ts32; ret = copy_from_user(&ts32, uts, sizeof(ts32)); if (ret) return -EFAULT; ts->tv_sec = ts32.tv_sec; ts->tv_nsec = ts32.tv_nsec; } else { ret = copy_from_user(&ts, uts, sizeof(*ts)); if (ret) return -EFAULT; if (flags & USER_TS_CLEARNSEC) ts->tv_nsec &= 0xFFFFFFFFUL; } if (flags & USER_TS_TIMEVAL) { if (!(flags & USER_TS_NOCHECK) && ts->tv_nsec >= USEC_PER_SEC) return -EINVAL; ts->tv_nsec *= NSEC_PER_USEC; } else { if (!(flags & USER_TS_NOCHECK) && ts->tv_nsec >= NSEC_PER_SEC) return -EINVAL; } return 0;
}
int get_timespec64(struct timespec64 *ts, const struct compat_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_NATIVE); }
int get_compat_timespec32(struct timespec64 *ts, const struct compat_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_COMPAT32); }
int get_compat_timespec64(struct timespec64 *ts, const struct __kernel_timespec __user *uts) { return get_timestruct(ts. uts, USER_TS_COMPAT64); }
While working on the driver patches I encountered lots of different combinations of those that might be interesting here, so we could have wrappers for the most common ones and call get_timestruct() and put_timestruct() directly for the less common variations. Am I taking it too far here, or would that make sense?
I think this is a little confusing. nanosleep_copyout() uses a similar strategy. But, I think it makes sense in that case as it uses common functions for all versions of nanosleep and because of the union.
-Deepa
Change over clock_settime, clock_gettime and clock_getres syscalls to use __kernel_timespec times. This will enable changing over of these syscalls to use new y2038 safe syscalls when the architectures define the CONFIG_64BIT_TIME.
Cc: linux-api@vger.kernel.org Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/syscalls.h | 6 +++--- kernel/time/posix-stubs.c | 6 +++--- kernel/time/posix-timers.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a78186d826d7..7ac1bb9ea7da 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -309,13 +309,13 @@ asmlinkage long sys_timer_settime(timer_t timer_id, int flags, struct itimerspec __user *old_setting); asmlinkage long sys_timer_delete(timer_t timer_id); asmlinkage long sys_clock_settime(clockid_t which_clock, - const struct timespec __user *tp); + const struct __kernel_timespec __user *tp); asmlinkage long sys_clock_gettime(clockid_t which_clock, - struct timespec __user *tp); + struct __kernel_timespec __user *tp); asmlinkage long sys_clock_adjtime(clockid_t which_clock, struct timex __user *tx); asmlinkage long sys_clock_getres(clockid_t which_clock, - struct timespec __user *tp); + struct __kernel_timespec __user *tp); asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags, const struct timespec __user *rqtp, struct timespec __user *rmtp); diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 0645cfa93609..28c22f54d0f2 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -49,7 +49,7 @@ SYS_NI(alarm); */
SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, - const struct timespec __user *, tp) + const struct __kernel_timespec __user *, tp) { struct timespec64 new_tp;
@@ -80,7 +80,7 @@ int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp) return 0; } SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, - struct timespec __user *, tp) + struct __kernel_timespec __user *, tp) { int ret; struct timespec64 kernel_tp; @@ -94,7 +94,7 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, return 0; }
-SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) +SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct __kernel_timespec __user *, tp) { struct timespec64 rtn_tp = { .tv_sec = 0, diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 67ed5966eccd..d46ee8264fd3 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1034,7 +1034,7 @@ void exit_itimers(struct signal_struct *sig) }
SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, - const struct timespec __user *, tp) + const struct __kernel_timespec __user *, tp) { const struct k_clock *kc = clockid_to_kclock(which_clock); struct timespec64 new_tp; @@ -1049,7 +1049,7 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, }
SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, - struct timespec __user *,tp) + struct __kernel_timespec __user *, tp) { const struct k_clock *kc = clockid_to_kclock(which_clock); struct timespec64 kernel_tp; @@ -1090,7 +1090,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, }
SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, - struct timespec __user *, tp) + struct __kernel_timespec __user *, tp) { const struct k_clock *kc = clockid_to_kclock(which_clock); struct timespec64 rtn_tp;
Change over clock_nanosleep syscalls to use y2038 safe __kernel_timespec times. This will enable changing over of these syscalls to use new y2038 safe syscalls when the architectures define the CONFIG_64BIT_TIME.
Note that nanosleep syscall is deprecated and does not have a plan for making it y2038 safe. But, the syscall should work as before on 64 bit machines and on 32 bit machines, the syscall works correctly until y2038 as before using the existing compat syscall version. There is no new syscall for supporting 64 bit time_t on 32 bit architectures.
Cc: linux-api@vger.kernel.org Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/restart_block.h | 7 ++----- include/linux/syscalls.h | 6 +++--- kernel/time/hrtimer.c | 8 ++++++-- kernel/time/posix-stubs.c | 4 ++-- kernel/time/posix-timers.c | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/include/linux/restart_block.h b/include/linux/restart_block.h index bcfdb918cd81..5d83d0c1d06c 100644 --- a/include/linux/restart_block.h +++ b/include/linux/restart_block.h @@ -7,6 +7,7 @@
#include <linux/compiler.h> #include <linux/types.h> +#include <linux/time64.h>
struct timespec; struct compat_timespec; @@ -15,9 +16,7 @@ struct pollfd; enum timespec_type { TT_NONE = 0, TT_NATIVE = 1, -#ifdef CONFIG_COMPAT TT_COMPAT = 2, -#endif };
/* @@ -40,10 +39,8 @@ struct restart_block { clockid_t clockid; enum timespec_type type; union { - struct timespec __user *rmtp; -#ifdef CONFIG_COMPAT + struct __kernel_timespec __user *rmtp; struct compat_timespec __user *compat_rmtp; -#endif }; u64 expires; } nanosleep; diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 7ac1bb9ea7da..4df16a70b0d7 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -254,7 +254,7 @@ asmlinkage long sys_adjtimex(struct timex __user *txc_p); asmlinkage long sys_times(struct tms __user *tbuf);
asmlinkage long sys_gettid(void); -asmlinkage long sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp); +asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp, struct __kernel_timespec __user *rmtp); asmlinkage long sys_alarm(unsigned int seconds); asmlinkage long sys_getpid(void); asmlinkage long sys_getppid(void); @@ -317,8 +317,8 @@ asmlinkage long sys_clock_adjtime(clockid_t which_clock, asmlinkage long sys_clock_getres(clockid_t which_clock, struct __kernel_timespec __user *tp); asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags, - const struct timespec __user *rqtp, - struct timespec __user *rmtp); + const struct __kernel_timespec __user *rqtp, + struct __kernel_timespec __user *rmtp);
asmlinkage long sys_nice(int increment); asmlinkage long sys_sched_setscheduler(pid_t pid, int policy, diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index bbd740171554..6cb6e6632ecf 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1541,8 +1541,10 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp, return ret; }
-SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp, - struct timespec __user *, rmtp) +#if !defined(CONFIG_64BIT_TIME) || defined(CONFIG_64BIT) + +SYSCALL_DEFINE2(nanosleep, struct __kernel_timespec __user *, rqtp, + struct __kernel_timespec __user *, rmtp) { struct timespec64 tu;
@@ -1557,6 +1559,8 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp, return hrtimer_nanosleep(&tu, HRTIMER_MODE_REL, CLOCK_MONOTONIC); }
+#endif + #ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 28c22f54d0f2..f7e7a05e651d 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -114,8 +114,8 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct __kernel_time }
SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, - const struct timespec __user *, rqtp, - struct timespec __user *, rmtp) + const struct __kernel_timespec __user *, rqtp, + struct __kernel_timespec __user *, rmtp) { struct timespec64 t;
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index d46ee8264fd3..a6c4cb6de6a2 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1205,8 +1205,8 @@ static int common_nsleep(const clockid_t which_clock, int flags, }
SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, - const struct timespec __user *, rqtp, - struct timespec __user *, rmtp) + const struct __kernel_timespec __user *, rqtp, + struct __kernel_timespec __user *, rmtp) { const struct k_clock *kc = clockid_to_kclock(which_clock); struct timespec64 t;
On Mon, 2017-11-27 at 11:30 -0800, Deepa Dinamani wrote: [...]
@@ -15,9 +16,7 @@ struct pollfd; enum timespec_type { TT_NONE = 0, TT_NATIVE = 1, -#ifdef CONFIG_COMPAT TT_COMPAT = 2, -#endif }; /* @@ -40,10 +39,8 @@ struct restart_block { clockid_t clockid; enum timespec_type type; union {
struct timespec __user *rmtp;
-#ifdef CONFIG_COMPAT
struct __kernel_timespec __user *rmtp;
struct compat_timespec __user *compat_rmtp; -#endif }; u64 expires; } nanosleep;
[...]
The deletions of #ifdef and #endif here seem to belong in patch #6, as that's the one that changes the condition for the compat nanosleep implementation which uses the compat_rmtp field.
Ben.
On Mon, Nov 27, 2017 at 8:30 PM, Deepa Dinamani deepa.kernel@gmail.com wrote:
The series is a preparation series for individual architectures to use 64 bit time_t syscalls in compat and 32 bit emulation modes.
This is a follow up to the series Arnd Bergmann posted: https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html [1]
Big picture is as per the lwn article: https://lwn.net/Articles/643234/ [2]
The series is directed at converting posix clock syscalls: clock_gettime, clock_settime, clock_getres and clock_nanosleep to use a new data structure __kernel_timespec at syscall boundaries. __kernel_timespec maintains 64 bit time_t across all execution modes.
vdso will be handled as part of each architecture when they enable support for 64 bit time_t.
The compat syscalls are repurposed to provide backward compatibility by using them as native syscalls as well for 32 bit architectures. They will continue to use timespec at syscall boundaries.
CONFIG_64_BIT_TIME controls whether the syscalls use __kernel_timespec or timespec at syscall boundaries.
The series does the following:
- Enable compat syscalls on 32 bit architectures.
- Add a new __kernel_timespec type to be used as the data structure for all the new syscalls.
- Add new config CONFIG_64BIT_TIME(intead of the CONFIG_COMPAT_TIME in [1] and [2] to switch to new definition of __kernel_timespec. It is the same as struct timespec otherwise.
- Add new CONFIG_32BIT_TIME to conditionally compile compat syscalls.
- Changes since v1:
- Introduce CONFIG_32BIT_TIME
- Fixed zeroing out of higher order bits of tv_nsec
- Included Arnd's changes to fix up use of compat headers
Very nice. I think it would be good to get this into linux-next soon so we can build on top of this. I have submitted most other y2038 patches today that don't depend on either this or one of my other patches.
There is one patch that I want to do but haven't imlpemented yet, to merge get_timespec64() and compat_get_timespec() into one function that take a bunch of flags (check nanosecond, nano/microsecond, zero upper half of nanoseconds, 32-bit or 64-bit wide), since I found a few functions that need more than one of these, and they don't all need the same combinations. My patch will certainly conflict with yours, as your touch the same functions, but that's fine.
If you end up doing another version of the series though, it might be better to move the compat accessors into kernel/time/time.c along with the native functions, that should make it easier to consolidate them later.
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile legacy time syscalls such as sys_nanosleep because this will need to enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to exclusively mark legacy syscalls.
Do you mean we would need to do this separately for native and compat syscalls, and have yet another option, like LEGACY_TIME_SYSCALLS and LEGACY_TIME_COMPAT_SYSCALLS, to cover all cases? I would think that CONFIG_COMPAT_32BIT_TIME handles all the compat versions, while CONFIG_LEGACY_TIME_SYSCALLS handles all the native ones.
Arnd
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile legacy time syscalls such as sys_nanosleep because this will need to enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to exclusively mark legacy syscalls.
Do you mean we would need to do this separately for native and compat syscalls, and have yet another option, like LEGACY_TIME_SYSCALLS and LEGACY_TIME_COMPAT_SYSCALLS, to cover all cases? I would think that CONFIG_COMPAT_32BIT_TIME handles all the compat versions, while CONFIG_LEGACY_TIME_SYSCALLS handles all the native ones.
I meant sys_nanosleep would be covered by LEGACY_TIME_SYSCALLS, but compat_sys_nanosleep would be covered by CONFIG_COMPAT_32BIT_TIME along with other compat syscalls. So, if we define the LEGACY_TIME_SYSCALLS as
"This controls the compilation of the following system calls: time, stime, gettimeofday, settimeofday, adjtimex, nanosleep, alarm, getitimer, setitimer, select, utime, utimes, futimesat, and {old,new}{l,f,}stat{,64}. These all pass 32-bit time_t arguments on 32-bit architectures and are replaced by other interfaces (e.g. posix timers and clocks, statx). C libraries implementing 64-bit time_t in 32-bit architectures have to implement the handles by wrapping around the newer interfaces. New architectures should not explicitly enable this."
This would not be really true as compat interfaces have nothing to do with this config.
I was proposing that we could have LEGACY_TIME_SYSCALLS config, but then have all these "deprecated" syscalls be enclosed within this, compat or not. This will also mean that we will have to come up representing these syscalls in the syscall header files. This can be a separate patch and this series can be merged as is if everyone agrees.
-Deepa
On Mon, Nov 27, 2017 at 11:29 PM, Deepa Dinamani deepa.kernel@gmail.com wrote:
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile legacy time syscalls such as sys_nanosleep because this will need to enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to exclusively mark legacy syscalls.
Do you mean we would need to do this separately for native and compat syscalls, and have yet another option, like LEGACY_TIME_SYSCALLS and LEGACY_TIME_COMPAT_SYSCALLS, to cover all cases? I would think that CONFIG_COMPAT_32BIT_TIME handles all the compat versions, while CONFIG_LEGACY_TIME_SYSCALLS handles all the native ones.
I meant sys_nanosleep would be covered by LEGACY_TIME_SYSCALLS, but compat_sys_nanosleep would be covered by CONFIG_COMPAT_32BIT_TIME along with other compat syscalls. So, if we define the LEGACY_TIME_SYSCALLS as
"This controls the compilation of the following system calls: time, stime, gettimeofday, settimeofday, adjtimex, nanosleep,
alarm, getitimer, setitimer, select, utime, utimes, futimesat, and {old,new}{l,f,}stat{,64}. These all pass 32-bit time_t arguments on 32-bit architectures and are replaced by other interfaces (e.g. posix timers and clocks, statx). C libraries implementing 64-bit time_t in 32-bit architectures have to implement the handles by wrapping around the newer interfaces. New architectures should not explicitly enable this."
This would not be really true as compat interfaces have nothing to do with this config.
I was proposing that we could have LEGACY_TIME_SYSCALLS config, but then have all these "deprecated" syscalls be enclosed within this, compat or not. This will also mean that we will have to come up representing these syscalls in the syscall header files. This can be a separate patch and this series can be merged as is if everyone agrees.
I think doing this separately would be good, I don't see any interdependency with the other patches, we just need to decide what we want in the long run.
I agree my text that you cited doesn't capture the situation correctly, as this is really about the obsolete system calls that take 64-bit time_t arguments on architectures that are converted to allow 64-bit time_t for non-obsolete system calls.
Maybe it's better to just reword this to
"This controls the compilation of the following system calls: time, stime, gettimeofday, settimeofday, adjtimex, nanosleep, alarm, getitimer, setitimer, select, utime, utimes, futimesat, and {old,new}{l,f,}stat{,64}. These are all replaced by other interfaces (e.g. posix timers and clocks, statx) on architectures that got converted from 32-bit time_t to 64-bit time_t. C libraries implementing 64-bit time_t in 32-bit architectures have to implement the handles by wrapping around the newer interfaces. New architectures should not explicitly enable this."
That would clarify that it's not about the compat system calls, while also allowing the two options to be set independently.
Arnd
On Tue, Nov 28, 2017 at 6:17 AM, Arnd Bergmann arnd@arndb.de wrote:
On Mon, Nov 27, 2017 at 11:29 PM, Deepa Dinamani deepa.kernel@gmail.com wrote:
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile legacy time syscalls such as sys_nanosleep because this will need to enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to exclusively mark legacy syscalls.
Do you mean we would need to do this separately for native and compat syscalls, and have yet another option, like LEGACY_TIME_SYSCALLS and LEGACY_TIME_COMPAT_SYSCALLS, to cover all cases? I would think that CONFIG_COMPAT_32BIT_TIME handles all the compat versions, while CONFIG_LEGACY_TIME_SYSCALLS handles all the native ones.
I meant sys_nanosleep would be covered by LEGACY_TIME_SYSCALLS, but compat_sys_nanosleep would be covered by CONFIG_COMPAT_32BIT_TIME along with other compat syscalls. So, if we define the LEGACY_TIME_SYSCALLS as
"This controls the compilation of the following system calls: time, stime, gettimeofday, settimeofday, adjtimex, nanosleep,
alarm, getitimer, setitimer, select, utime, utimes, futimesat, and {old,new}{l,f,}stat{,64}. These all pass 32-bit time_t arguments on 32-bit architectures and are replaced by other interfaces (e.g. posix timers and clocks, statx). C libraries implementing 64-bit time_t in 32-bit architectures have to implement the handles by wrapping around the newer interfaces. New architectures should not explicitly enable this."
This would not be really true as compat interfaces have nothing to do with this config.
I was proposing that we could have LEGACY_TIME_SYSCALLS config, but then have all these "deprecated" syscalls be enclosed within this, compat or not. This will also mean that we will have to come up representing these syscalls in the syscall header files. This can be a separate patch and this series can be merged as is if everyone agrees.
I think doing this separately would be good, I don't see any interdependency with the other patches, we just need to decide what we want in the long run.
Right. There are three options:
1. Use two configs to identify which syscalls need not be supported by new architectures. In this case it makes sense to say LEGACY_TIME_SYSCALLS and COMPAT_32BIT_TIME both need to be disabled for new architectures. And, I can reword the config to what you mention below.
2. Make the LEGACY_TIME_SYSCALLS eliminate non y2038 safe syscalls mentioned below only. In this case only the native and compat functions of the below mentioned syscalls need to be identified by the config. I like this option as this clearly identifies which syscalls are deprecated and do not have a 64 bit counterpart. Not all architectures need to support turning this off.
3. If we don't need either 1 or 2, then we could stick with what we have today in the series as CONFIG_64BIT_TIME will be deleted and they only need #ifdef CONFIG_64BIT.
Let me know if anyone prefers something else.
I agree my text that you cited doesn't capture the situation correctly, as this is really about the obsolete system calls that take 64-bit time_t arguments on architectures that are converted to allow 64-bit time_t for non-obsolete system calls.
Maybe it's better to just reword this to
"This controls the compilation of the following system calls: time, stime, gettimeofday, settimeofday, adjtimex, nanosleep,
alarm, getitimer, setitimer, select, utime, utimes, futimesat, and {old,new}{l,f,}stat{,64}. These are all replaced by other interfaces (e.g. posix timers and clocks, statx) on architectures that got converted from 32-bit time_t to 64-bit time_t. C libraries implementing 64-bit time_t in 32-bit architectures have to implement the handles by wrapping around the newer interfaces. New architectures should not explicitly enable this."
That would clarify that it's not about the compat system calls, while also allowing the two options to be set independently.
-Deepa
On Wed, Nov 29, 2017 at 12:17 AM, Deepa Dinamani deepa.kernel@gmail.com wrote:
On Tue, Nov 28, 2017 at 6:17 AM, Arnd Bergmann arnd@arndb.de wrote:
On Mon, Nov 27, 2017 at 11:29 PM, Deepa Dinamani deepa.kernel@gmail.com wrote:
Right. There are three options:
- Use two configs to identify which syscalls need not be supported by
new architectures. In this case it makes sense to say LEGACY_TIME_SYSCALLS and COMPAT_32BIT_TIME both need to be disabled for new architectures. And, I can reword the config to what you mention below.
- Make the LEGACY_TIME_SYSCALLS eliminate non y2038 safe syscalls
mentioned below only. In this case only the native and compat functions of the below mentioned syscalls need to be identified by the config. I like this option as this clearly identifies which syscalls are deprecated and do not have a 64 bit counterpart. Not all architectures need to support turning this off.
- If we don't need either 1 or 2, then we could stick with what we
have today in the series as CONFIG_64BIT_TIME will be deleted and they only need #ifdef CONFIG_64BIT.
Let me know if anyone prefers something else.
I think I prefer to have both LEGACY_TIME_SYSCALLS to guard the native deprecated syscalls (disabled on 32-bit architectures after the conversion, and enabled on 64-bit architectures until we merge the next one), and COMPAT_32BIT_TIME to guard the compat versions of both the deprecated and the non-deprecated syscalls (enabled on all existing 32-bit architectures after the conversion, and on 64-bit architectures if they provide a compat mode for the former).
Those two are not symmetric, but I think those are the most common combinations, and the Kconfig symbol helps document what they are.
There is one more category for things like io_getevents() and rt_sigtimedwait that also need two separate compat versions, one for 32-bit time_t and one for 64-bit time_t, but it seems better to deal with those case-by-case rather than introducing another Kconfig symbol.
Arnd