posix_clocks: Prepare syscalls for 64 bit time_t conversion
Subsystems (22)
v5 cover posix_clocks: Prepare syscalls for 64 bit time_t conversion
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]
Thomas, Arnd, this seems ready to be merged now.
Can you help get this merged?
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 v4:
* Fixed up kbuild errors for arm64 and powerpc non compat configs
* Changes since v3:
* Updated include file ordering
* Changes since v2:
* Dropped the ARCH_HAS_64BIT_TIME config.
* Fixed zeroing out of higher order bits of tv_nsec for real.
* Addressed minor review comments from v1.
* 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 | 15 +++++++++ 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/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 | 1 + arch/s390/hypfs/hypfs_sprp.c | 1 - arch/s390/include/asm/compat.h | 11 ------- arch/s390/include/asm/elf.h | 4 +-- 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 +- 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/compat.c | 52 +++++------------------------- kernel/time/hrtimer.c | 10 ++++-- kernel/time/posix-stubs.c | 12 ++++--- kernel/time/posix-timers.c | 24 ++++++++++---- kernel/time/time.c | 58 +++++++++++++++++++++++++++++++--- 42 files changed, 177 insertions(+), 188 deletions(-) create mode 100644 include/linux/compat_time.h
base-commit: 61530b14b059d4838dcc2186e9de9d57e195ce55
Signature · 42 lines
2.14.1 Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
PATCH v5 2/10 include: Move compat_timespec/ timeval to compat_time.h
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"
--- 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/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 | 1 + arch/s390/hypfs/hypfs_sprp.c | 1 - arch/s390/include/asm/compat.h | 11 ----------- arch/s390/include/asm/elf.h | 4 ++-- 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 +- include/linux/compat.h | 1 + include/linux/compat_time.h | 19 +++++++++++++++++++ 30 files changed, 32 insertions(+), 107 deletions(-) create mode 100644 include/linux/compat_time.h
arch/arm64/include/asm/compat.h +0 -11
@@ -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;
arch/arm64/include/asm/stat.h +1 -0
@@ -20,6 +20,7 @@#ifdef CONFIG_COMPAT +#include <linux/compat_time.h> #include <asm/compat.h> /*
arch/arm64/kernel/hw_breakpoint.c +0 -1
@@ -30,7 +30,6 @@#include <linux/smp.h> #include <linux/uaccess.h> -#include <asm/compat.h> #include <asm/current.h> #include <asm/debug-monitors.h> #include <asm/hw_breakpoint.h>
arch/arm64/kernel/perf_regs.c +1 -1
@@ -1,11 +1,11 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/compat.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/perf_event.h> #include <linux/bug.h> #include <linux/sched/task_stack.h> -#include <asm/compat.h> #include <asm/perf_regs.h> #include <asm/ptrace.h>
arch/mips/include/asm/compat.h +0 -11
@@ -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 ];
arch/mips/kernel/signal32.c +1 -1
@@ -8,13 +8,13 @@* Copyright (C) 1999, 2000 Silicon Graphics, Inc. * Copyright (C) 2016, Imagination Technologies Ltd. */ +#include <linux/compat.h> #include <linux/compiler.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/signal.h> #include <linux/syscalls.h> -#include <asm/compat.h> #include <asm/compat-signal.h> #include <linux/uaccess.h> #include <asm/unistd.h>
arch/parisc/include/asm/compat.h +0 -11
@@ -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 */
arch/powerpc/include/asm/compat.h +0 -11
@@ -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;
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -13,6 +13,7 @@* 2 of the License, or (at your option) any later version. */ +#include <linux/compat.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/kernel.h>
@@ -42,7 +43,6 @@#include <asm/paca.h> #include <asm/lppaca.h> #include <asm/cache.h> -#include <asm/compat.h> #include <asm/mmu.h> #include <asm/hvcall.h> #include <asm/xics.h>
arch/powerpc/oprofile/backtrace.c +1 -0
@@ -7,6 +7,7 @@* 2 of the License, or (at your option) any later version. **/ +#include <linux/compat_time.h> #include <linux/oprofile.h> #include <linux/sched.h> #include <asm/processor.h>
arch/s390/hypfs/hypfs_sprp.c +0 -1
@@ -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"
arch/s390/include/asm/compat.h +0 -11
@@ -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;
arch/s390/include/asm/elf.h +2 -2
@@ -125,8 +125,9 @@* ELF register definitions.. */ +#include <linux/compat.h> +#include <asm/ptrace.h> -#include <asm/compat.h> #include <asm/syscall.h> #include <asm/user.h>
@@ -136,7 +137,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>
arch/s390/kvm/priv.c +0 -1
@@ -26,7 +26,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"
arch/s390/pci/pci_clp.c +0 -1
@@ -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>
arch/sparc/include/asm/compat.h +0 -11
@@ -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;
arch/tile/include/asm/compat.h +0 -11
@@ -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
arch/x86/events/core.c +1 -1
@@ -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)
arch/x86/include/asm/compat.h +0 -11
@@ -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;
arch/x86/include/asm/ftrace.h +1 -1
@@ -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
arch/x86/include/asm/sys_ia32.h +1 -1
@@ -12,11 +12,11 @@#ifdef CONFIG_COMPAT +#include <linux/compat.h> #include <linux/compiler.h> #include <linux/linkage.h> #include <linux/types.h> #include <linux/signal.h> -#include <asm/compat.h> #include <asm/ia32.h> /* ia32/sys_ia32.c */
arch/x86/kernel/sys_x86_64.c +1 -1
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/compat.h> #include <linux/errno.h> #include <linux/sched.h> #include <linux/sched/mm.h>
@@ -19,7 +20,6 @@#include <linux/elf.h> #include <asm/elf.h> -#include <asm/compat.h> #include <asm/ia32.h> #include <asm/syscalls.h> #include <asm/mpx.h>
drivers/s390/block/dasd_ioctl.c +0 -1
@@ -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>
drivers/s390/char/fs3270.c +0 -1
@@ -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>
drivers/s390/char/sclp_ctl.c +0 -1
@@ -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>
drivers/s390/char/vmcp.c +0 -1
@@ -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>
drivers/s390/cio/chsc_sch.c +0 -1
@@ -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>
drivers/s390/net/qeth_core_main.c +1 -1
@@ -10,6 +10,7 @@#define KMSG_COMPONENT "qeth"#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt +#include <linux/compat.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/string.h>
@@ -32,7 +33,6 @@#include <asm/chpid.h> #include <asm/io.h> #include <asm/sysinfo.h> -#include <asm/compat.h> #include <asm/diag.h> #include <asm/cio.h> #include <asm/ccwdev.h>
include/linux/compat.h +1 -0
@@ -7,6 +7,7 @@*/ #include <linux/types.h> +#include <linux/compat_time.h> #include <linux/stat.h> #include <linux/param.h> /* for HZ */
include/linux/compat_time.h new file +19 -0
@@ -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 */
Signature · 1 line
2.14.1
PATCH v5 7/10 include: Add new y2038 safe __kernel_timespec
In reply to Deepa DinamaniThe 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.
--- 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(-)
include/linux/time64.h +9 -1
@@ -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
include/uapi/asm-generic/posix_types.h +1 -0
@@ -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 ;
include/uapi/linux/time.h +7 -0
@@ -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): */
Signature · 1 line
2.14.1
PATCH v5 9/10 change time types to new y2038 safe __kernel_* types
In reply to Deepa DinamaniChange 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.
--- include/linux/syscalls.h | 6 +++--- kernel/time/posix-stubs.c | 6 +++--- kernel/time/posix-timers.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
include/linux/syscalls.h +3 -3
@@ -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);
kernel/time/posix-stubs.c +3 -3
@@ -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 ,
kernel/time/posix-timers.c +3 -3
@@ -1039,7 +1039,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;
@@ -1054,7 +1054,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;
@@ -1095,7 +1095,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;
Signature · 1 line
2.14.1
PATCH v5 10/10 nanosleep: change time types to safe __kernel_* types
In reply to Deepa DinamaniChange 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.
--- 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(-)
include/linux/restart_block.h +2 -5
@@ -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;
include/linux/syscalls.h +3 -3
@@ -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,
kernel/time/hrtimer.c +6 -2
@@ -1710,8 +1710,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;
@@ -1726,6 +1728,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,
kernel/time/posix-stubs.c +2 -2
@@ -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;
kernel/time/posix-timers.c +2 -2
@@ -1210,8 +1210,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;
Signature · 1 line
2.14.1
PATCH v5 1/10 compat: Make compat helpers independent of CONFIG_COMPAT
In reply to Deepa DinamaniMany 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.
--- include/linux/compat.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
include/linux/compat.h +6 -2
@@ -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>
@@ -20,9 +18,11 @@#include <linux/uaccess.h> #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
@@ -59,6 +59,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
@@ -891,7 +893,9 @@ static inline struct compat_timeval ns_to_compat_timeval(s64 nsec)#else /* !CONFIG_COMPAT */ #define is_compat_task () (0) +#ifndef in_compat_syscallstatic inline bool in_compat_syscall (void ) {return false; } +#endif #endif /* CONFIG_COMPAT */
Signature · 1 line
2.14.1
PATCH v5 3/10 compat: enable compat_get/put_timespec64 always
In reply to Deepa DinamaniThese functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems.
--- include/linux/compat.h | 2 -- include/linux/compat_time.h | 4 ++++ kernel/compat.c | 52 +++++++-------------------------------------- kernel/time/time.c | 44 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 46 deletions(-)
include/linux/compat.h +0 -2
@@ -267,8 +267,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,
include/linux/compat_time.h +4 -0
@@ -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 */
kernel/compat.c +8 -44
64 lines not on this page · raw message
kernel/time/time.c +44 -0
50 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH v5 4/10 arch: introduce CONFIG_64BIT_TIME
In reply to Deepa DinamaniThere 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.
After this is done for all architectures, the CONFIG_64BIT_TIME symbol will be deleted.
--- arch/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/Kconfig +8 -0
@@ -870,6 +870,14 @@ config OLD_SIGACTION config COMPAT_OLD_SIGACTION bool +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
Signature · 1 line
2.14.1
PATCH v5 6/10 posix-clocks: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME
In reply to Deepa Dinamaniclock_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.
--- kernel/time/hrtimer.c | 2 +- kernel/time/posix-stubs.c | 2 ++ kernel/time/posix-timers.c | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)
kernel/time/hrtimer.c +1 -1
@@ -1726,7 +1726,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)
kernel/time/posix-stubs.c +2 -0
@@ -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) {
kernel/time/posix-timers.c +12 -2
@@ -1112,7 +1112,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)
@@ -1147,6 +1147,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) {
@@ -1171,6 +1175,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) {
@@ -1226,7 +1234,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)
@@ -1251,6 +1260,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 = {
Signature · 1 line
2.14.1
PATCH v5 5/10 arch: Introduce CONFIG_COMPAT_32BIT_TIME
In reply to Deepa DinamaniCompat 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.
--- arch/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+)
arch/Kconfig +7 -0
@@ -878,6 +878,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
Signature · 1 line
2.14.1
PATCH v5 8/10 fix get_timespec64() for y2038 safe compat interfaces
In reply to Deepa Dinamaniget/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 guarantee zeroing of these. If used without zeroing, kernel might be at risk of using timespec values incorrectly.
Note that clearing of bits is dependent on CONFIG_64BIT_TIME for now. This is until COMPAT_USE_64BIT_TIME has been handled correctly. x86 will be the first architecture that will use the CONFIG_64BIT_TIME.
--- include/linux/time.h | 4 ++-- kernel/time/time.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-)
include/linux/time.h +2 -2
@@ -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,
kernel/time/time.c +10 -4
@@ -841,9 +841,9 @@ 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; +struct __kernel_timespec kts;int ret; ret =copy_from_user (&kts, uts,sizeof (kts));
@@ -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 = { +struct __kernel_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);
Signature · 1 line
2.14.1
Arnd Bergmann
maintainerQuoted 27 lines · Deepa Dinamani
The series is a preparation series for individual architectures to use 64 bit
time_tsyscalls 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]Thomas, Arnd, this seems ready to be merged now.
Can you help get this merged?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_getresandclock_nanosleepto use a new data structure__kernel_timespecat syscall boundaries.__kernel_timespecmaintains 64 bittime_tacross 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_TIMEcontrols whether the syscalls use__kernel_timespecor timespec at syscall boundaries.
Quoted 8 lines
The series does the following:
1. Enable compat syscalls on 32 bit architectures.
2. Add a new__kernel_timespectype to be used as the data structure for all the new syscalls.
3. Add new config CONFIG_64BIT_TIME(intead of theCONFIG_COMPAT_TIMEin
[1] and [2] to switch to new definition of__kernel_timespec. It is the same as struct timespec otherwise.
4. Add newCONFIG_32BIT_TIMEto conditionally compile compat syscalls.
I've applied all 10 patches to my y2038 git branch [1], which is part of linux-next,
to give it a little wider testing. If everything goes well, I'd send a pull request to
Thomas next week so he can integrate it into tip from there, or (if he prefers) send it directly to Linus in the merge window.
Thanks a lot for your persistence and your work on this!
Arnd
[1] git://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git#y2038