y2038: system calls, part 3
Subsystems (26)
Arnd Bergmann
maintainerv2 cover y2038: system calls, part 3
This is a mostly unchanged copy of a series I sent back in April for an initial review. All the earlier syscall patches that Deepa or I sent got merged now, and this is the largest chunk of remaining patches.
Changes this time are:
- This is actually tested with the LTP syscalls test suite, both before and after the CONFIG_64BIT_TIME change (which is not included here). I have created a patch series for musl libc to use 64-bit time_t and change all the system calls over to the new entry points for this. The only bugs I found during that testing were in later parts of the conversion that I have not posted yet.
- I rewrote the sys_io_getevents conversion after the introduction of sys_sys_io_getevents. We obviously don't need to have two of each, so we will only provide sys_io_pgetevents() with 64-bit time_t but not sys_io_getevents(), which the libc can implement on top of the former.
- While we have Deepa's POSIX timer conversion merged now, we still need to decide on how we want to do the replacement ABI for getitimer()/setitimer(). Like getrusage()/waitid() and clock_adjtime() and unlike the system calls I'm posting here, there is no one obvious ABI.
- For ppoll()/pselect6(), the ABI is fairly clear, but the implementation still needs to be done. I tested with a simple prototype based on the existing compat code, but we can probably improve that. This is something that Deepa still wants to work on.
- Finally, Christoph Hellwig objected to the idea of reusing the compat_ namespace for the 32-bit native case. Changing that would be a departure from our plans so far[2], and would make some things end up differently. Until we have decided on how this is to be done, I've decided to not change the code for this post. We can clearly rename all the symbols and I've implemented that in [3] for the current linux-next (not including the series here). This is something we can definitely do, but I'd need to know soon whether we can merge this series unchanged for 4.19 or if I should rebase it on top of that patch with the alternative naming.
Arnd
---
Previous cover letter announcement below, see [4] for the full series:
After the first timekeeping series from Deepa (merged into -tip now) and my follow-up for IPC system calls, this is a third set of system call conversions following the same principle.
Most of the changes are straightforward, so I'm grouping them into a larger series even though the system calls are mostly unrelated to one another. After this series, the remaining calls that need to be changed are getrusage()/waitid(), pselect6/ppoll(), timer{,fd}_{get,set}time() and getitimer()/setitimer(). Those will be sent separately, once they are matured enough.
To put the changes into perspective, a list of all system calls that require changes is available in a spreadsheet[5] and I have made another experimental patch that changes over x86[6] and arm[7] to actually use them.
Link [1] https://lore.kernel.org/lkml/[email protected]/
Link [2] https://lwn.net/Articles/643234/
Link [3] https://lore.kernel.org/lkml/[email protected]/
Link [4] https://lore.kernel.org/lkml/[email protected]/
Link [5] https://docs.google.com/spreadsheets/d/1HCYwHXxs48TsTb6IGUduNjQnmfRvMPzCN6T_0YiQwis
Link [6] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/commit/?h=y2038-4.18-rc5-next&id=2c995de3bdd5
Link [7] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/commit/?h=y2038-4.18-rc5-next&id=e73061da2f80
Arnd Bergmann (17):
y2038: compat: Move common compat types to asm-generic/compat.h
y2038: Remove newstat family from default syscall set
y2038: Remove stat64 family from default syscall set
asm-generic: Remove unneeded __ARCH_WANT_SYS_LLSEEK macro
asm-generic: Remove empty asm/unistd.h
y2038: Change sys_utimensat() to use __kernel_timespec
y2038: Compile utimes()/futimesat() conditionally
y2038: utimes: Rework #ifdef guards for compat syscalls
y2038: futex: Move compat implementation into futex.c
y2038: futex: Add support for __kernel_timespec
y2038: Prepare sched_rr_get_interval for __kernel_timespec
y2038: aio: Prepare sys_io_{p,}getevents for __kernel_timespec
y2038: socket: Convert recvmmsg to __kernel_timespec
y2038: socket: Add compat_sys_recvmmsg_time64
y2038: signal: Change rt_sigtimedwait to use __kernel_timespec
y2038: Make compat_sys_rt_sigtimedwait usable on 32-bit
y2038: signal: Add compat_sys_rt_sigtimedwait_time64
arch/alpha/include/asm/unistd.h | 2 + arch/arc/include/uapi/asm/unistd.h | 1 + arch/arm/include/asm/unistd.h | 4 +- arch/arm64/include/asm/compat.h | 20 +-- arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/uapi/asm/unistd.h | 1 + arch/c6x/include/uapi/asm/unistd.h | 1 + arch/h8300/include/uapi/asm/unistd.h | 1 + arch/hexagon/include/uapi/asm/unistd.h | 1 + arch/ia64/include/asm/unistd.h | 3 + arch/m68k/include/asm/unistd.h | 2 +- arch/microblaze/include/asm/unistd.h | 2 +- arch/mips/include/asm/compat.h | 22 +--- arch/mips/include/asm/unistd.h | 3 +- arch/nds32/include/uapi/asm/unistd.h | 1 + arch/nios2/include/uapi/asm/unistd.h | 1 + arch/openrisc/include/uapi/asm/unistd.h | 1 + arch/parisc/include/asm/compat.h | 18 +-- arch/parisc/include/asm/unistd.h | 3 +- arch/powerpc/include/asm/compat.h | 18 +-- arch/powerpc/include/asm/unistd.h | 3 +- arch/s390/include/asm/compat.h | 18 +-- arch/s390/include/asm/unistd.h | 3 +- arch/sh/include/asm/unistd.h | 2 +- arch/sparc/include/asm/compat.h | 19 +-- arch/sparc/include/asm/unistd.h | 3 +- arch/unicore32/include/uapi/asm/unistd.h | 1 + arch/x86/include/asm/compat.h | 19 +-- arch/x86/include/asm/unistd.h | 3 +- arch/xtensa/include/asm/unistd.h | 2 +- fs/aio.c | 77 ++++++++++-- fs/read_write.c | 2 +- fs/stat.c | 3 + fs/utimes.c | 59 +++++---- include/asm-generic/compat.h | 24 +++- include/asm-generic/unistd.h | 13 -- include/linux/compat.h | 12 +- include/linux/compat_time.h | 5 + include/linux/futex.h | 8 -- include/linux/socket.h | 19 ++- include/linux/syscalls.h | 25 ++-- include/uapi/asm-generic/unistd.h | 2 + kernel/Makefile | 3 - kernel/futex.c | 207 +++++++++++++++++++++++++++++-- kernel/futex_compat.c | 202 ------------------------------ kernel/sched/core.c | 4 +- kernel/signal.c | 68 ++++++++-- kernel/sys_ni.c | 1 + net/compat.c | 16 +-- net/socket.c | 55 ++++++-- 50 files changed, 524 insertions(+), 461 deletions(-) delete mode 100644 include/asm-generic/unistd.h delete mode 100644 kernel/futex_compat.c
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 1/17 y2038: compat: Move common compat types to asm-generic/compat.h
While converting compat system call handlers to work on 32-bit architectures, I found a number of types used in those handlers that are identical between all architectures.
Let's move all the identical ones into asm-generic/compat.h to avoid having to add even more identical definitions of those types.
For unknown reasons, mips defines __compat_gid32_t, __compat_uid32_t and compat_caddr_t as signed, while all others have them unsigned. This seems to be a mistake, but I'm leaving it alone here. The other types all differ by size or alignment on at least on architecture.
compat_aio_context_t is currently defined in linux/compat.h but also needed for compat_sys_io_getevents(), so let's move it into the same place.
While we still have not decided whether the 32-bit time handling will always use the compat syscalls, or in which form, I think this is a useful cleanup that we can merge regardless.
--- arch/arm64/include/asm/compat.h | 20 ++------------------ arch/mips/include/asm/compat.h | 22 ++-------------------- arch/parisc/include/asm/compat.h | 18 ++---------------- arch/powerpc/include/asm/compat.h | 18 ++---------------- arch/s390/include/asm/compat.h | 18 ++---------------- arch/sparc/include/asm/compat.h | 19 ++----------------- arch/x86/include/asm/compat.h | 19 ++----------------- include/asm-generic/compat.h | 24 +++++++++++++++++++++++- include/linux/compat.h | 2 -- 9 files changed, 37 insertions(+), 123 deletions(-)
arch/arm64/include/asm/compat.h +2 -18
@@ -25,6 +25,8 @@#include <linux/sched.h> #include <linux/sched/task_stack.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#ifdef __AARCH64EB__#define COMPAT_UTS_MACHINE "armv8b\0\0"
@@ -32,10 +34,6 @@#define COMPAT_UTS_MACHINE "armv8l\0\0"#endif -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u16 __compat_uid_t ;typedef u16 __compat_gid_t ;typedef u16 __compat_uid16_t ;
@@ -43,27 +41,13 @@ typedef u16 __compat_gid16_t;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u16 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u32 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef s32 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ;typedef __kernel_fsid_t compat_fsid_t ; -typedef s32 compat_key_t ; -typedef s32 compat_timer_t ; - -typedef s16 compat_short_t ; -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u16 compat_ushort_t ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ;struct compat_stat {#ifdef __AARCH64EB__
arch/mips/include/asm/compat.h +2 -20
@@ -9,43 +9,25 @@#include <asm/page.h> #include <asm/ptrace.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#define COMPAT_UTS_MACHINE "mips\0\0\0" -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_suseconds_t ; - -typedef s32 compat_pid_t ;typedef s32 __compat_uid_t ;typedef s32 __compat_gid_t ;typedef __compat_uid_t __compat_uid32_t ;typedef __compat_gid_t __compat_gid32_t ;typedef u32 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u32 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef u32 compat_nlink_t ;typedef s32 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef s32 compat_caddr_t ;typedef struct {s32 val[2 ]; }compat_fsid_t ; -typedef s32 compat_timer_t ; -typedef s32 compat_key_t ; - -typedef s16 compat_short_t ; -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u16 compat_ushort_t ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ;struct compat_stat {compat_dev_t st_dev;
arch/parisc/include/asm/compat.h +2 -16
@@ -8,36 +8,22 @@#include <linux/sched.h> #include <linux/thread_info.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#define COMPAT_UTS_MACHINE "parisc\0\0" -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u32 __compat_uid_t ;typedef u32 __compat_gid_t ;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u16 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u32 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef u16 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ; -typedef s32 compat_key_t ; -typedef s32 compat_timer_t ; - -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ;struct compat_stat {compat_dev_t st_dev;/* dev_t is 32 bits on parisc */
arch/powerpc/include/asm/compat.h +2 -16
@@ -8,6 +8,8 @@#include <linux/types.h> #include <linux/sched.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#ifdef __BIG_ENDIAN__#define COMPAT_UTS_MACHINE "ppc\0\0"
@@ -15,34 +17,18 @@#define COMPAT_UTS_MACHINE "ppcle\0\0"#endif -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u32 __compat_uid_t ;typedef u32 __compat_gid_t ;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u32 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u32 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef s16 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ;typedef __kernel_fsid_t compat_fsid_t ; -typedef s32 compat_key_t ; -typedef s32 compat_timer_t ; - -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ;struct compat_stat {compat_dev_t st_dev;
arch/s390/include/asm/compat.h +2 -16
@@ -9,6 +9,8 @@#include <linux/sched/task_stack.h> #include <linux/thread_info.h> +#include <asm-generic/compat.h> +#define __TYPE_IS_PTR (t) (!__builtin_types_compatible_p( \ typeof(0?(__force t)0:0ULL), u64))
@@ -51,34 +53,18 @@#define COMPAT_USER_HZ 100#define COMPAT_UTS_MACHINE "s390\0\0\0\0" -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u16 __compat_uid_t ;typedef u16 __compat_gid_t ;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u16 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u16 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef u16 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ;typedef __kernel_fsid_t compat_fsid_t ; -typedef s32 compat_key_t ; -typedef s32 compat_timer_t ; - -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ; typedef struct { u32 mask;
arch/sparc/include/asm/compat.h +2 -17
@@ -6,38 +6,23 @@*/ #include <linux/types.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#define COMPAT_UTS_MACHINE "sparc\0\0" -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u16 __compat_uid_t ;typedef u16 __compat_gid_t ;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u16 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u16 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef s16 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ;typedef __kernel_fsid_t compat_fsid_t ; -typedef s32 compat_key_t ; -typedef s32 compat_timer_t ; - -typedef s32 compat_int_t ; -typedef s32 compat_long_t ;typedef s64 compat_s64 ; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ;typedef u64 compat_u64 ; -typedef u32 compat_uptr_t ; -struct compat_stat {compat_dev_t st_dev;compat_ino_t st_ino;
arch/x86/include/asm/compat.h +2 -17
@@ -12,38 +12,23 @@#include <asm/user32.h> #include <asm/unistd.h> +#include <asm-generic/compat.h> +#define COMPAT_USER_HZ 100#define COMPAT_UTS_MACHINE "i686\0\0" -typedef u32 compat_size_t ; -typedef s32 compat_ssize_t ; -typedef s32 compat_clock_t ; -typedef s32 compat_pid_t ;typedef u16 __compat_uid_t ;typedef u16 __compat_gid_t ;typedef u32 __compat_uid32_t ;typedef u32 __compat_gid32_t ;typedef u16 compat_mode_t ; -typedef u32 compat_ino_t ;typedef u16 compat_dev_t ; -typedef s32 compat_off_t ; -typedef s64 compat_loff_t ;typedef u16 compat_nlink_t ;typedef u16 compat_ipc_pid_t ; -typedef s32 compat_daddr_t ;typedef u32 compat_caddr_t ;typedef __kernel_fsid_t compat_fsid_t ; -typedef s32 compat_timer_t ; -typedef s32 compat_key_t ; - -typedef s32 compat_int_t ; -typedef s32 compat_long_t ; typedef s64 __attribute__((aligned(4))) compat_s64; -typedef u32 compat_uint_t ; -typedef u32 compat_ulong_t ; -typedef u32 compat_u32 ; typedef u64 __attribute__((aligned(4))) compat_u64; -typedef u32 compat_uptr_t ;struct compat_stat {compat_dev_t st_dev;
include/asm-generic/compat.h +23 -1
@@ -1,3 +1,25 @@/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_GENERIC_COMPAT_H +#define __ASM_GENERIC_COMPAT_H -/* This is an empty stub for 32-bit-only architectures */ +/* These types are common across all compat ABIs */ +typedef u32 compat_size_t ; +typedef s32 compat_ssize_t ; +typedef s32 compat_clock_t ; +typedef s32 compat_pid_t ; +typedef u32 compat_ino_t ; +typedef s32 compat_off_t ; +typedef s64 compat_loff_t ; +typedef s32 compat_daddr_t ; +typedef s32 compat_timer_t ; +typedef s32 compat_key_t ; +typedef s16 compat_short_t ; +typedef s32 compat_int_t ; +typedef s32 compat_long_t ; +typedef u16 compat_ushort_t ; +typedef u32 compat_uint_t ; +typedef u32 compat_ulong_t ; +typedef u32 compat_uptr_t ; +typedef u32 compat_aio_context_t ; + +#endif
include/linux/compat.h +0 -2
@@ -110,8 +110,6 @@ typedef struct compat_sigaltstack {typedef __compat_uid32_t compat_uid_t ;typedef __compat_gid32_t compat_gid_t ; -typedef compat_ulong_t compat_aio_context_t ; -struct compat_sel_arg_struct ;struct rusage ;
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 2/17 y2038: Remove newstat family from default syscall set
In reply to Arnd BergmannWe have four generations of stat() syscalls:
- the oldstat syscalls that are only used on the older architectures
- the newstat family that is used on all 64-bit architectures but lacked support for large files on 32-bit architectures.
- the stat64 family that is used mostly on 32-bit architectures to replace newstat
- statx() to replace all of the above, adding 64-bit timestamps among other things.
We already compile stat64 only on those architectures that need it, but newstat is always built, including on those that don't reference it. This adds a new __ARCH_WANT_NEW_STAT symbol along the lines of __ARCH_WANT_OLD_STAT and __ARCH_WANT_STAT64 to control compilation of newstat. All architectures that need it use an explict define, the others now get a little bit smaller, and future architecture (including 64-bit targets) won't ever see it.
--- arch/alpha/include/asm/unistd.h | 1 + arch/arm/include/asm/unistd.h | 1 + arch/arm64/include/uapi/asm/unistd.h | 1 + arch/ia64/include/asm/unistd.h | 2 ++ arch/m68k/include/asm/unistd.h | 1 + arch/microblaze/include/asm/unistd.h | 1 + arch/mips/include/asm/unistd.h | 1 + arch/parisc/include/asm/unistd.h | 1 + arch/powerpc/include/asm/unistd.h | 1 + arch/s390/include/asm/unistd.h | 1 + arch/sh/include/asm/unistd.h | 1 + arch/sparc/include/asm/unistd.h | 1 + arch/x86/include/asm/unistd.h | 1 + arch/xtensa/include/asm/unistd.h | 1 + fs/stat.c | 3 +++ 15 files changed, 18 insertions(+)
arch/alpha/include/asm/unistd.h +1 -0
@@ -6,6 +6,7 @@#define NR_SYSCALLS 523 +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_GETHOSTNAME
arch/arm/include/asm/unistd.h +1 -0
@@ -16,6 +16,7 @@#include <uapi/asm/unistd.h> #include <asm/unistd-nr.h> +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_GETHOSTNAME#define __ARCH_WANT_SYS_PAUSE
arch/arm64/include/uapi/asm/unistd.h +1 -0
@@ -16,5 +16,6 @@*/ #define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_NEW_STAT#include <asm-generic/unistd.h>
arch/ia64/include/asm/unistd.h +2 -0
@@ -28,6 +28,8 @@#define __IGNORE_vfork/* clone() */ #define __IGNORE_umount2/* umount() */ +#define __ARCH_WANT_NEW_STAT +#if !defined(__ASSEMBLY__) && !defined(ASSEMBLER )#include <linux/types.h>
arch/m68k/include/asm/unistd.h +1 -0
@@ -7,6 +7,7 @@#define NR_syscalls 380 +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_OLD_STAT#define __ARCH_WANT_STAT64
arch/microblaze/include/asm/unistd.h +1 -0
@@ -15,6 +15,7 @@/* #define __ARCH_WANT_OLD_READDIR */ /* #define __ARCH_WANT_OLD_STAT */ +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_ALARM#define __ARCH_WANT_SYS_GETHOSTNAME
arch/mips/include/asm/unistd.h +1 -0
@@ -24,6 +24,7 @@#ifndef __ASSEMBLY__ +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_SYS_ALARM#define __ARCH_WANT_SYS_GETHOSTNAME
arch/parisc/include/asm/unistd.h +1 -0
@@ -141,6 +141,7 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \return K_INLINE_SYSCALL (name,5 , arg1, arg2, arg3, arg4, arg5); \ } +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_ALARM
arch/powerpc/include/asm/unistd.h +1 -0
@@ -22,6 +22,7 @@#include <linux/compiler.h> #include <linux/linkage.h> +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_ALARM
arch/s390/include/asm/unistd.h +1 -0
@@ -15,6 +15,7 @@#define __IGNORE_pkey_alloc#define __IGNORE_pkey_free +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_SYS_ALARM#define __ARCH_WANT_SYS_GETHOSTNAME
arch/sh/include/asm/unistd.h +1 -0
@@ -5,6 +5,7 @@# include <asm/unistd_64.h> # endif +# define __ARCH_WANT_NEW_STAT# define __ARCH_WANT_OLD_READDIR# define __ARCH_WANT_OLD_STAT# define __ARCH_WANT_STAT64
arch/sparc/include/asm/unistd.h +1 -0
@@ -21,6 +21,7 @@#else #define __NR_time 231/* Linux sparc32 */ #endif +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_ALARM
arch/x86/include/asm/unistd.h +1 -0
@@ -31,6 +31,7 @@# endif +# define __ARCH_WANT_NEW_STAT# define __ARCH_WANT_OLD_READDIR# define __ARCH_WANT_OLD_STAT# define __ARCH_WANT_SYS_ALARM
arch/xtensa/include/asm/unistd.h +1 -0
@@ -5,6 +5,7 @@#define __ARCH_WANT_SYS_CLONE#include <uapi/asm/unistd.h> +#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_UTIME#define __ARCH_WANT_SYS_LLSEEK
fs/stat.c +3 -0
@@ -280,6 +280,8 @@ SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, stat#endif /* __ARCH_WANT_OLD_STAT */ +#ifdef __ARCH_WANT_NEW_STAT +#if BITS_PER_LONG ==32 # define choose_32_64 (a,b) a#else
@@ -378,6 +380,7 @@ SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf) return error; } +#endif static int do_readlinkat (int dfd,const char __user *pathname,char __user *buf,int bufsiz)
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 3/17 y2038: Remove stat64 family from default syscall set
In reply to Arnd BergmannNew architectures should no longer need stat64, which is not y2038 safe and has been replaced by statx(). This removes the 'select __ARCH_WANT_STAT64' statement from asm-generic/unistd.h and instead moves it into the respective asm/unistd.h UAPI header files for each architecture that uses it today.
In the generic file, the system call number and entry points are now made conditional, so newly added architectures (e.g. riscv32 or csky) will never need to carry backwards compatiblity for it.
arm64 is the only 64-bit architecture using the asm-generic/unistd.h file, and it already sets __ARCH_WANT_NEW_STAT in its headers, and I use the same #ifdef here: future 64-bit architectures therefore won't see newstat or stat64 any more. They don't suffer from the y2038 time_t overflow, but for consistency it seems best to also let them use statx().
--- arch/arc/include/uapi/asm/unistd.h | 1 + arch/c6x/include/uapi/asm/unistd.h | 1 + arch/h8300/include/uapi/asm/unistd.h | 1 + arch/hexagon/include/uapi/asm/unistd.h | 1 + arch/nds32/include/uapi/asm/unistd.h | 1 + arch/nios2/include/uapi/asm/unistd.h | 1 + arch/openrisc/include/uapi/asm/unistd.h | 1 + arch/unicore32/include/uapi/asm/unistd.h | 1 + include/asm-generic/unistd.h | 1 - include/uapi/asm-generic/unistd.h | 2 ++ 10 files changed, 10 insertions(+), 1 deletion(-)
arch/arc/include/uapi/asm/unistd.h +1 -0
@@ -17,6 +17,7 @@#define _UAPI_ASM_ARC_UNISTD_H#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_EXECVE#define __ARCH_WANT_SYS_CLONE#define __ARCH_WANT_SYS_VFORK
arch/c6x/include/uapi/asm/unistd.h +1 -0
@@ -16,6 +16,7 @@*/ #define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_CLONE/* Use the standard ABI for syscalls. */
arch/h8300/include/uapi/asm/unistd.h +1 -0
@@ -1,5 +1,6 @@#define __ARCH_NOMMU#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64#include <asm-generic/unistd.h>
arch/hexagon/include/uapi/asm/unistd.h +1 -0
@@ -29,6 +29,7 @@#define sys_mmap2 sys_mmap_pgoff#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_EXECVE#define __ARCH_WANT_SYS_CLONE#define __ARCH_WANT_SYS_VFORK
arch/nds32/include/uapi/asm/unistd.h +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2005-2017 Andes Technology Corporation +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYNC_FILE_RANGE2/* Use the standard ABI for syscalls */
arch/nios2/include/uapi/asm/unistd.h +1 -0
@@ -19,6 +19,7 @@#define sys_mmap2 sys_mmap_pgoff#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64/* Use the standard ABI for syscalls */ #include <asm-generic/unistd.h>
arch/openrisc/include/uapi/asm/unistd.h +1 -0
@@ -20,6 +20,7 @@#define sys_mmap2 sys_mmap_pgoff#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_CLONE
arch/unicore32/include/uapi/asm/unistd.h +1 -0
@@ -15,4 +15,5 @@/* Use the standard ABI for syscalls. */ #include <asm-generic/unistd.h> +#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_CLONE
include/asm-generic/unistd.h +0 -1
@@ -8,6 +8,5 @@* be selected by default. */ #if __BITS_PER_LONG ==32 -#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_LLSEEK#endif
include/uapi/asm-generic/unistd.h +2 -0
@@ -242,10 +242,12 @@ __SYSCALL(__NR_tee, sys_tee)/* fs/stat.c */ #define __NR_readlinkat 78 __SYSCALL(__NR_readlinkat, sys_readlinkat) +#if defined(__ARCH_WANT_NEW_STAT) || defined(__ARCH_WANT_STAT64)#define __NR3264_fstatat 79 __SC_3264(__NR3264_fstatat, sys_fstatat64, sys_newfstatat)#define __NR3264_fstat 80 __SC_3264(__NR3264_fstat, sys_fstat64, sys_newfstat) +#endif /* fs/sync.c */ #define __NR_sync 81
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 4/17 asm-generic: Remove unneeded __ARCH_WANT_SYS_LLSEEK macro
In reply to Arnd BergmannThe sys_llseek sytem call is needed on all 32-bit architectures and none of the 64-bit ones, so we can remove the __ARCH_WANT_SYS_LLSEEK guard and simplify the include/asm-generic/unistd.h header further.
Since 32-bit tasks can run either natively or in compat mode on 64-bit architectures, we have to check for both !CONFIG_64BIT and CONFIG_COMPAT.
There are a few 64-bit architectures that also reference sys_llseek in their 64-bit ABI (e.g. sparc), but I verified that those all select CONFIG_COMPAT, so the #if check is still correct here. It's a bit odd to include it in the syscall table though, as it's the same as sys_lseek() on 64-bit, but with strange calling conventions.
--- arch/arm/include/asm/unistd.h | 1 - arch/arm64/include/asm/unistd.h | 1 - arch/m68k/include/asm/unistd.h | 1 - arch/microblaze/include/asm/unistd.h | 1 - arch/mips/include/asm/unistd.h | 1 - arch/parisc/include/asm/unistd.h | 1 - arch/powerpc/include/asm/unistd.h | 1 - arch/s390/include/asm/unistd.h | 1 - arch/sh/include/asm/unistd.h | 1 - arch/sparc/include/asm/unistd.h | 1 - arch/x86/include/asm/unistd.h | 1 - arch/xtensa/include/asm/unistd.h | 1 - fs/read_write.c | 2 +- include/asm-generic/unistd.h | 9 --------- 14 files changed, 1 insertion(+), 22 deletions(-)
arch/arm/include/asm/unistd.h +0 -1
@@ -21,7 +21,6 @@#define __ARCH_WANT_SYS_GETHOSTNAME#define __ARCH_WANT_SYS_PAUSE#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_SIGPENDING#define __ARCH_WANT_SYS_SIGPROCMASK
arch/arm64/include/asm/unistd.h +0 -1
@@ -18,7 +18,6 @@#define __ARCH_WANT_SYS_GETHOSTNAME#define __ARCH_WANT_SYS_PAUSE#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_SIGPENDING#define __ARCH_WANT_SYS_SIGPROCMASK
arch/m68k/include/asm/unistd.h +0 -1
@@ -22,7 +22,6 @@#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLD_GETRLIMIT#define __ARCH_WANT_SYS_OLD_MMAP
arch/microblaze/include/asm/unistd.h +0 -1
@@ -27,7 +27,6 @@#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE/* #define __ARCH_WANT_SYS_OLD_GETRLIMIT */ #define __ARCH_WANT_SYS_OLDUMOUNT
arch/mips/include/asm/unistd.h +0 -1
@@ -34,7 +34,6 @@#define __ARCH_WANT_SYS_WAITPID#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLD_UNAME#define __ARCH_WANT_SYS_OLDUMOUNT
arch/parisc/include/asm/unistd.h +0 -1
@@ -156,7 +156,6 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLDUMOUNT#define __ARCH_WANT_SYS_SIGPENDING
arch/powerpc/include/asm/unistd.h +0 -1
@@ -36,7 +36,6 @@#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLD_GETRLIMIT#define __ARCH_WANT_SYS_OLD_UNAME
arch/s390/include/asm/unistd.h +0 -1
@@ -26,7 +26,6 @@#define __ARCH_WANT_SYS_IPC#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLD_GETRLIMIT#define __ARCH_WANT_SYS_OLD_MMAP
arch/sh/include/asm/unistd.h +0 -1
@@ -20,7 +20,6 @@# define __ARCH_WANT_SYS_SOCKETCALL# define __ARCH_WANT_SYS_FADVISE64# define __ARCH_WANT_SYS_GETPGRP -# define __ARCH_WANT_SYS_LLSEEK# define __ARCH_WANT_SYS_NICE# define __ARCH_WANT_SYS_OLD_GETRLIMIT# define __ARCH_WANT_SYS_OLD_UNAME
arch/sparc/include/asm/unistd.h +0 -1
@@ -34,7 +34,6 @@#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_OLDUMOUNT#define __ARCH_WANT_SYS_SIGPENDING
arch/x86/include/asm/unistd.h +0 -1
@@ -38,7 +38,6 @@# define __ARCH_WANT_SYS_FADVISE64# define __ARCH_WANT_SYS_GETHOSTNAME# define __ARCH_WANT_SYS_GETPGRP -# define __ARCH_WANT_SYS_LLSEEK# define __ARCH_WANT_SYS_NICE# define __ARCH_WANT_SYS_OLDUMOUNT# define __ARCH_WANT_SYS_OLD_GETRLIMIT
arch/xtensa/include/asm/unistd.h +0 -1
@@ -8,7 +8,6 @@#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_STAT64#define __ARCH_WANT_SYS_UTIME -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_GETPGRP/*
fs/read_write.c +1 -1
@@ -331,7 +331,7 @@ COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset, unsigned i }#endif -#ifdef __ARCH_WANT_SYS_LLSEEK +#if !defined(CONFIG_64BIT ) || defined(CONFIG_COMPAT ) SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, unsigned long, offset_low, loff_t __user *, result, unsigned int, whence)
include/asm-generic/unistd.h +0 -9
@@ -1,12 +1,3 @@/* SPDX-License-Identifier: GPL-2.0 */ #include <uapi/asm-generic/unistd.h> #include <linux/export.h> - -/* -* These are required system calls, we should -* invert the logic eventually and let them -* be selected by default. -*/ -#if __BITS_PER_LONG ==32 -#define __ARCH_WANT_SYS_LLSEEK -#endif
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 5/17 asm-generic: Remove empty asm/unistd.h
In reply to Arnd BergmannNothing is left in asm/unistd.h except for the redirect to uapi/asm/unistd.h, so removing the file simply leads to that one being used directly. The linux/export.h inclusion is a leftover from commit e1b5bb6d1236 ("consolidate cond_syscall and SYSCALL_ALIAS declarations") and should not be used anyway.
--- include/asm-generic/unistd.h | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 include/asm-generic/unistd.h
include/asm-generic/unistd.h deleted +0 -3
@@ -1,3 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <uapi/asm-generic/unistd.h> -#include <linux/export.h>
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 6/17 y2038: Change sys_utimensat() to use __kernel_timespec
In reply to Arnd BergmannWhen 32-bit architectures get changed to support 64-bit time_t, utimensat() needs to use the new __kernel_timespec structure as its argument.
The older utime(), utimes() and futimesat() system calls don't need a corresponding change as they are no longer used on C libraries that have 64-bit time support.
As we do for the other syscalls that have timespec arguments, we reuse the 'compat' syscall entry points to implement the traditional four interfaces, and only leave the new utimensat() as a native handler, so that the same code gets used on both 32-bit and 64-bit kernels on each syscall.
--- fs/utimes.c | 2 +- include/linux/syscalls.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
fs/utimes.c +1 -1
@@ -166,7 +166,7 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, } SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename, - struct timespec __user *, utimes, int, flags) + struct __kernel_timespec __user *, utimes, int, flags) {struct timespec64 tstimes[2 ];
include/linux/syscalls.h +2 -1
@@ -513,7 +513,8 @@ asmlinkage long sys_timerfd_gettime(int ufd, struct __kernel_itimerspec __user */* fs/utimes.c */ asmlinkage long sys_utimensat (int dfd,const char __user *filename, -struct timespec __user *utimes,int flags); +struct __kernel_timespec __user *utimes, +int flags);/* kernel/acct.c */ asmlinkage long sys_acct (const char __user *name);
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 7/17 y2038: Compile utimes()/futimesat() conditionally
In reply to Arnd BergmannThere are four generations of utimes() syscalls: utime(), utimes(), futimesat() and utimensat(), each one being a superset of the previous one. For y2038 support, we have to add another one, which is the same as the existing utimensat() but always passes 64-bit times_t based timespec values.
There are currently 10 architectures that only use utimensat(), two that use utimes(), futimesat() and utimensat() but not utime(), and 11 architectures that have all four, and those define __ARCH_WANT_SYS_UTIME in order to get a sys_utime implementation. Since all the new architectures only want utimensat(), moving all the legacy entry points into a common __ARCH_WANT_SYS_UTIME guard simplifies the logic. Only alpha and ia64 grow a tiny bit as they now also get an unused sys_utime(), but it didn't seem worth the extra complexity of adding yet another ifdef for those.
--- arch/alpha/include/asm/unistd.h | 1 + arch/arm/include/asm/unistd.h | 2 +- arch/ia64/include/asm/unistd.h | 1 + fs/utimes.c | 51 ++++++++++++++++++----------------------- include/linux/syscalls.h | 10 ++++---- 5 files changed, 31 insertions(+), 34 deletions(-)
arch/alpha/include/asm/unistd.h +1 -0
@@ -14,6 +14,7 @@#define __ARCH_WANT_SYS_GETPGRP#define __ARCH_WANT_SYS_OLDUMOUNT#define __ARCH_WANT_SYS_SIGPENDING +#define __ARCH_WANT_SYS_UTIME#define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_VFORK#define __ARCH_WANT_SYS_CLONE
arch/arm/include/asm/unistd.h +1 -1
@@ -26,13 +26,13 @@#define __ARCH_WANT_SYS_SIGPROCMASK#define __ARCH_WANT_SYS_OLD_MMAP#define __ARCH_WANT_SYS_OLD_SELECT +#define __ARCH_WANT_SYS_UTIME#if !defined(CONFIG_AEABI ) || defined(CONFIG_OABI_COMPAT )#define __ARCH_WANT_SYS_TIME#define __ARCH_WANT_SYS_IPC#define __ARCH_WANT_SYS_OLDUMOUNT#define __ARCH_WANT_SYS_ALARM -#define __ARCH_WANT_SYS_UTIME#define __ARCH_WANT_SYS_OLD_GETRLIMIT#define __ARCH_WANT_OLD_READDIR#define __ARCH_WANT_SYS_SOCKETCALL
arch/ia64/include/asm/unistd.h +1 -0
@@ -29,6 +29,7 @@#define __IGNORE_umount2/* umount() */ #define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SYS_UTIME#if !defined(__ASSEMBLY__) && !defined(ASSEMBLER )
fs/utimes.c +22 -29
69 lines not on this page · raw message
include/linux/syscalls.h +6 -4
@@ -965,8 +965,6 @@ asmlinkage long sys_access(const char __user *filename, int mode);asmlinkage long sys_rename (const char __user *oldname,const char __user *newname);asmlinkage long sys_symlink (const char __user *old,const char __user *new); -asmlinkage long sys_utimes (char __user *filename, -struct timeval __user *utimes);#if defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_COMPAT_STAT64)asmlinkage long sys_stat64 (const char __user *filename,struct stat64 __user *statbuf);
@@ -996,14 +994,18 @@ asmlinkage long sys_alarm(unsigned int seconds);asmlinkage long sys_getpgrp (void );asmlinkage long sys_pause (void );asmlinkage long sys_time (time_t __user *tloc); +#ifdef __ARCH_WANT_SYS_UTIMEasmlinkage long sys_utime (char __user *filename,struct utimbuf __user *times); +asmlinkage long sys_utimes (char __user *filename, +struct timeval __user *utimes); +asmlinkage long sys_futimesat (int dfd,const char __user *filename, +struct timeval __user *utimes); +#endif asmlinkage long sys_creat (const char __user *pathname,umode_t mode);asmlinkage long sys_getdents (unsigned int fd,struct linux_dirent __user *dirent,unsigned int count); -asmlinkage long sys_futimesat (int dfd,const char __user *filename, -struct timeval __user *utimes);asmlinkage long sys_select (int n,fd_set __user *inp,fd_set __user *outp,fd_set __user *exp,struct timeval __user *tvp); asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 8/17 y2038: utimes: Rework #ifdef guards for compat syscalls
In reply to Arnd BergmannAfter changing over to 64-bit time_t syscalls, many architectures will want compat_sys_utimensat() but not respective handlers for utime(), utimes() and futimesat(). This adds a new __ARCH_WANT_COMPAT_SYS_UTIME to complement __ARCH_WANT_SYS_UTIME. For now, all 64-bit architectures that support CONFIG_COMPAT set it, but future 64-bit architectures will not (tile would not have needed it either, but got removed).
As older 32-bit architectures get converted to using CONFIG_64BIT_TIME, they will have to use __ARCH_WANT_COMPAT_SYS_UTIME instead of __ARCH_WANT_SYS_UTIME. Architectures using the generic syscall ABI don't need either of them as they never had a utime syscall.
Since the compat_utimbuf structure is now required outside of CONFIG_COMPAT, I'm moving it into compat_time.h.
---
If we proceed with Christoph's suggestion of renaming all the compat time handling to something that doesn't have compat in the name, the new macro here would have to get renamed as well.
--- arch/arm64/include/asm/unistd.h | 1 + arch/mips/include/asm/unistd.h | 1 + arch/parisc/include/asm/unistd.h | 1 + arch/powerpc/include/asm/unistd.h | 1 + arch/s390/include/asm/unistd.h | 1 + arch/sparc/include/asm/unistd.h | 1 + arch/x86/include/asm/unistd.h | 1 + fs/utimes.c | 6 +++++- include/linux/compat.h | 5 ----- include/linux/compat_time.h | 5 +++++ 10 files changed, 17 insertions(+), 6 deletions(-)
arch/arm64/include/asm/unistd.h +1 -0
@@ -22,6 +22,7 @@#define __ARCH_WANT_SYS_SIGPENDING#define __ARCH_WANT_SYS_SIGPROCMASK#define __ARCH_WANT_COMPAT_SYS_SENDFILE +#define __ARCH_WANT_COMPAT_SYS_UTIME#define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_VFORK
arch/mips/include/asm/unistd.h +1 -0
@@ -31,6 +31,7 @@#define __ARCH_WANT_SYS_IPC#define __ARCH_WANT_SYS_PAUSE#define __ARCH_WANT_SYS_UTIME +#define __ARCH_WANT_COMPAT_SYS_UTIME#define __ARCH_WANT_SYS_WAITPID#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_GETPGRP
arch/parisc/include/asm/unistd.h +1 -0
@@ -152,6 +152,7 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \#define __ARCH_WANT_COMPAT_SYS_TIME#define __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL#define __ARCH_WANT_SYS_UTIME +#define __ARCH_WANT_COMPAT_SYS_UTIME#define __ARCH_WANT_SYS_WAITPID#define __ARCH_WANT_SYS_SOCKETCALL#define __ARCH_WANT_SYS_FADVISE64
arch/powerpc/include/asm/unistd.h +1 -0
@@ -47,6 +47,7 @@#endif #ifdef CONFIG_PPC64 #define __ARCH_WANT_COMPAT_SYS_TIME +#define __ARCH_WANT_COMPAT_SYS_UTIME#define __ARCH_WANT_SYS_NEWFSTATAT#define __ARCH_WANT_COMPAT_SYS_SENDFILE#endif
arch/s390/include/asm/unistd.h +1 -0
@@ -34,6 +34,7 @@#define __ARCH_WANT_SYS_SIGPROCMASK# ifdef CONFIG_COMPAT # define __ARCH_WANT_COMPAT_SYS_TIME +# define __ARCH_WANT_COMPAT_SYS_UTIME# endif #define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_VFORK
arch/sparc/include/asm/unistd.h +1 -0
@@ -42,6 +42,7 @@#define __ARCH_WANT_SYS_IPC#else #define __ARCH_WANT_COMPAT_SYS_TIME +#define __ARCH_WANT_COMPAT_SYS_UTIME#define __ARCH_WANT_COMPAT_SYS_SENDFILE#endif
arch/x86/include/asm/unistd.h +1 -0
@@ -24,6 +24,7 @@# include <asm/unistd_64.h> # include <asm/unistd_64_x32.h> # define __ARCH_WANT_COMPAT_SYS_TIME +# define __ARCH_WANT_COMPAT_SYS_UTIME# define __ARCH_WANT_COMPAT_SYS_PREADV64# define __ARCH_WANT_COMPAT_SYS_PWRITEV64# define __ARCH_WANT_COMPAT_SYS_PREADV64V2
fs/utimes.c +5 -1
@@ -218,11 +218,12 @@ SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times) }#endif -#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME /* * Not all architectures have sys_utime, so implement this in terms * of sys_utimes. */ +#ifdef __ARCH_WANT_COMPAT_SYS_UTIME COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, struct compat_utimbuf __user *, t) {
@@ -237,6 +238,7 @@ COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, }return do_utimes (AT_FDCWD , filename, t ? tv :NULL ,0 ); } +#endif COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags) {
@@ -253,6 +255,7 @@ COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filenareturn do_utimes (dfd, filename, t ? tv :NULL , flags); } +#ifdef __ARCH_WANT_COMPAT_SYS_UTIMEstatic long do_compat_futimesat (unsigned int dfd,const char __user *filename,struct compat_timeval __user *t) {
@@ -285,3 +288,4 @@ COMPAT_SYSCALL_DEFINE2(utimes, const char __user *, filename, struct compat_timereturn do_compat_futimesat (AT_FDCWD , filename, t); }#endif +#endif
include/linux/compat.h +0 -5
@@ -113,11 +113,6 @@ typedef __compat_gid32_t compat_gid_t;struct compat_sel_arg_struct ;struct rusage ; -struct compat_utimbuf { -compat_time_t actime; -compat_time_t modtime; -}; -struct compat_itimerval {struct compat_timeval it_interval;struct compat_timeval it_value;
include/linux/compat_time.h +5 -0
@@ -22,6 +22,11 @@ struct compat_itimerspec {struct compat_timespec it_value; }; +struct compat_utimbuf { +compat_time_t actime; +compat_time_t modtime; +}; +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,
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 9/17 y2038: futex: Move compat implementation into futex.c
In reply to Arnd BergmannWe are going to share the compat_sys_futex() handler between 64-bit architectures and 32-bit architectures that need to deal with both 32-bit and 64-bit time_t, and this is easier if both entry points are in the same file.
In fact, most other system call handlers do the same thing these days, so let's follow the trend here and merge all of futex_compat.c into futex.c.
In the process, a few minor changes have to be done to make sure everything still makes sense: handle_futex_death() and futex_cmpxchg_enabled() become local symbol, and the compat version of the fetch_robust_entry() function gets renamed to compat_fetch_robust_entry() to avoid a symbol clash.
This is intended as a purely cosmetic patch, no behavior should change.
---
Regardless of whether we rename all compat time calls or not, moving the compat futex code into the main file helps us clean up the implementation.
--- include/linux/futex.h | 8 -- kernel/Makefile | 3 - kernel/futex.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++- kernel/futex_compat.c | 202 -------------------------------------------------- 4 files changed, 192 insertions(+), 216 deletions(-) delete mode 100644 kernel/futex_compat.c
include/linux/futex.h +0 -8
@@ -9,9 +9,6 @@ struct inode;struct mm_struct ;struct task_struct ; -extern int -handle_futex_death (u32 __user *uaddr,struct task_struct *curr,int pi); -/* * Futexes are matched on equal values of this key. * The key type depends on whether it's a shared or private mapping.
@@ -55,11 +52,6 @@ extern void exit_robust_list(struct task_struct *curr);long do_futex (u32 __user *uaddr,int op,u32 val,ktime_t *timeout,u32 __user *uaddr2,u32 val2,u32 val3); -#ifdef CONFIG_HAVE_FUTEX_CMPXCHG -#define futex_cmpxchg_enabled 1 -#else -extern int futex_cmpxchg_enabled; -#endif #else static inline void exit_robust_list (struct task_struct *curr) {
kernel/Makefile +0 -3
@@ -49,9 +49,6 @@ obj-$(CONFIG_PROFILING) += profile.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += time/ obj-$(CONFIG_FUTEX) += futex.o -ifeq ($(CONFIG_COMPAT),y) -obj-$(CONFIG_FUTEX) += futex_compat.o -endif obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += smp.o ifneq ($(CONFIG_SMP),y)
kernel/futex.c +192 -3
219 lines not on this page · raw message
kernel/futex_compat.c deleted +0 -202
202 lines not on this page · raw message
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 10/17 y2038: futex: Add support for __kernel_timespec
In reply to Arnd BergmannThis prepares sys_futex for y2038 safe calling: the native syscall is changed to receive a __kernel_timespec argument, which will be switched to 64-bit time_t in the future. All the internal time handling gets changed to timespec64, and the compat_sys_futex entry point is moved under the CONFIG_COMPAT_32BIT_TIME check to provide compatibility for existing 32-bit architectures.
--- include/linux/syscalls.h | 2 +- kernel/futex.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-)
include/linux/syscalls.h +1 -1
@@ -541,7 +541,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags);/* kernel/futex.c */ asmlinkage long sys_futex (u32 __user *uaddr,int op,u32 val, -struct timespec __user *utime,u32 __user *uaddr2, +struct __kernel_timespec __user *utime,u32 __user *uaddr2,u32 val3); asmlinkage long sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr,
kernel/futex.c +12 -10
@@ -3556,10 +3556,10 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, - struct timespec __user *, utime, u32 __user *, uaddr2, + struct __kernel_timespec __user *, utime, u32 __user *, uaddr2, u32, val3) { -struct timespec ts; +struct timespec64 ts;ktime_t t, *tp =NULL ;u32 val2 =0 ;int cmd = op &FUTEX_CMD_MASK ;
@@ -3569,12 +3569,12 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, cmd == FUTEX_WAIT_REQUEUE_PI)) {if (unlikely (should_fail_futex (!(op &FUTEX_PRIVATE_FLAG ))))return -EFAULT ; -if (copy_from_user (&ts, utime,sizeof (ts)) !=0 ) +if (get_timespec64 (&ts, utime))return -EFAULT ; -if (!timespec_valid (&ts)) +if (!timespec64_valid (&ts))return -EINVAL ; - t =timespec_to_ktime (ts); + t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); tp = &t;
@@ -3745,12 +3745,14 @@ COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid,return ret; } +#endif /* CONFIG_COMPAT */ +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, struct compat_timespec __user *, utime, u32 __user *, uaddr2, u32, val3) { -struct timespec ts; +struct timespec64 ts;ktime_t t, *tp =NULL ;int val2 =0 ;int cmd = op &FUTEX_CMD_MASK ;
@@ -3758,12 +3760,12 @@ COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,if (utime && (cmd ==FUTEX_WAIT || cmd ==FUTEX_LOCK_PI || cmd ==FUTEX_WAIT_BITSET || cmd ==FUTEX_WAIT_REQUEUE_PI )) { -if (compat_get_timespec (&ts, utime)) +if (compat_get_timespec64 (&ts, utime))return -EFAULT ; -if (!timespec_valid (&ts)) +if (!timespec64_valid (&ts))return -EINVAL ; - t =timespec_to_ktime (ts); + t =timespec64_to_ktime (ts);if (cmd ==FUTEX_WAIT ) t =ktime_add_safe (ktime_get (), t); tp = &t;
@@ -3774,7 +3776,7 @@ COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); } -#endif /* CONFIG_COMPAT */ +#endif /* CONFIG_COMPAT_32BIT_TIME */ static void __init futex_detect_cmpxchg (void ) {
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 11/17 y2038: Prepare sched_rr_get_interval for __kernel_timespec
In reply to Arnd BergmannThis is a preparation patch for converting sys_sched_rr_get_interval to work with 64-bit time_t on 32-bit architectures. The 'interval' argument is changed to struct __kernel_timespec, which will be redefined using 64-bit time_t in the future. The compat version of the system call in turn is enabled for compilation with CONFIG_COMPAT_32BIT_TIME so the individual 32-bit architectures can share the handling of the traditional argument with 64-bit architectures providing it for their compat mode.
--- include/linux/syscalls.h | 2 +- kernel/sched/core.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/syscalls.h +1 -1
@@ -614,7 +614,7 @@ asmlinkage long sys_sched_yield(void);asmlinkage long sys_sched_get_priority_max (int policy);asmlinkage long sys_sched_get_priority_min (int policy);asmlinkage long sys_sched_rr_get_interval (pid_t pid, -struct timespec __user *interval); +struct __kernel_timespec __user *interval);/* kernel/signal.c */ asmlinkage long sys_restart_syscall (void );
kernel/sched/core.c +2 -2
@@ -5265,7 +5265,7 @@ static int sched_rr_get_interval(pid_t pid, struct timespec64 *t)* an error code. */ SYSCALL_DEFINE2 (sched_rr_get_interval, pid_t, pid, - struct timespec __user *, interval) + struct __kernel_timespec __user *, interval) {struct timespec64 t;int retval =sched_rr_get_interval (pid, &t);
@@ -5276,7 +5276,7 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,return retval; } -#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE2 (sched_rr_get_interval, compat_pid_t, pid, struct compat_timespec __user *, interval)
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 12/17 y2038: aio: Prepare sys_io_{p,}getevents for __kernel_timespec
In reply to Arnd BergmannThis is a preparation patch for converting sys_io_pgetevents to work with 64-bit time_t on 32-bit architectures. The 'timeout' argument is changed to struct __kernel_timespec, which will be redefined using 64-bit time_t in the future. The compat version of the system call in turn is enabled for compilation with CONFIG_COMPAT_32BIT_TIME so the individual 32-bit architectures can share the handling of the traditional argument with 64-bit architectures providing it for their compat mode.
We now have five entry points into do_io_getevents(). Until we set CONFIG_64BIT_TIME, the arguments are
sys_io_getevents(): native aio_context_t, old-style timespecsys_io_pgetevents(): like sys_io_getevents(), but with added
aio_sigset argument
compat_sys_io_getevents(): 32-bit aio_context_t, 32-bit timespec compat_sys_io_pgetevents(): like compat_sys_io_getevents(), but with
added aio_sigset argumentcompat_sys_io_pgetevents_time64(): like compat_sys_io_pgetevents(),
but with 64-bit timespec
Once a 32-bit architecture sets CONFIG_64BIT_TIME, sys_io_getevents() is no longer available, and sys_io_pgetevents() takes a 64-bit timespec argument, whiel compat_sys_io_getevents() and compat_sys_io_pgetevents() implement the traditional behavior. compat_sys_io_pgetevents_time64() is only used on 64-bit architectures, to provide compatibility with the new 32-bit version of sys_io_pgetevents() taking a 64-bit timespec combined with a __compat_aio_sigset.
--- fs/aio.c | 77 +++++++++++++++++++++++++++++++++++++++++++----- include/linux/syscalls.h | 4 +-- 2 files changed, 71 insertions(+), 10 deletions(-)
fs/aio.c +69 -8
@@ -1869,7 +1869,7 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id, long, min_nr, long, nr, struct io_event __user *, events, - struct timespec __user *, timeout) + struct __kernel_timespec __user *, timeout) { struct timespec64 ts;int ret;
@@ -1888,7 +1888,7 @@ SYSCALL_DEFINE6(io_pgetevents, long, min_nr, long, nr, struct io_event __user *, events, - struct timespec __user *, timeout, + struct __kernel_timespec __user *, timeout, const struct __aio_sigset __user *, usig) { struct __aio_sigset ksig = { NULL, };
@@ -1929,6 +1929,73 @@ SYSCALL_DEFINE6(io_pgetevents, }#ifdef CONFIG_COMPAT +struct __compat_aio_sigset { +compat_sigset_t __user *sigmask; +compat_size_t sigsetsize; +}; + +COMPAT_SYSCALL_DEFINE6 (io_pgetevents_time64, + compat_aio_context_t, ctx_id, + compat_long_t, min_nr, + compat_long_t, nr, + struct io_event __user *, events, + struct __kernel_timespec __user *, timeout, + const struct __compat_aio_sigset __user *, usig) +{ +struct __compat_aio_sigset ksig = {NULL , }; +sigset_t ksigmask, sigsaved; +struct timespec64 t; +int ret; + +if (timeout &&get_timespec64 (&t, timeout)) +return -EFAULT ; + +if (usig &©_from_user (&ksig, usig,sizeof (ksig))) +return -EFAULT ; + +if (ksig.sigmask) { +if (ksig.sigsetsize !=sizeof (compat_sigset_t)) +return -EINVAL ; +if (get_compat_sigset (&ksigmask, ksig.sigmask)) +return -EFAULT ; +sigdelsetmask (&ksigmask,sigmask (SIGKILL ) |sigmask (SIGSTOP )); +sigprocmask (SIG_SETMASK , &ksigmask, &sigsaved); + } + + ret =do_io_getevents (ctx_id, min_nr, nr, events, timeout ? &t :NULL ); +if (signal_pending (current)) { +if (ksig.sigmask) { + current->saved_sigmask = sigsaved; +set_restore_sigmask (); + } +if (!ret) + ret = -ERESTARTNOHAND ; + }else { +if (ksig.sigmask) +sigprocmask (SIG_SETMASK , &sigsaved,NULL ); + } + +return ret; +} +#endif + +#ifdef CONFIG_COMPAT_32BIT_TIME +#ifndef CONFIG_COMPAT +#define compat_sigset_t sigset_t +struct __compat_aio_sigset { +compat_sigset_t __user *sigmask; +compat_size_t sigsetsize; +}; + +static inline int get_compat_sigset (sigset_t *set,const sigset_t __user *compat) +{ +if (copy_from_user (set, compat,sizeof *set)) +return -EFAULT ; + +return 0 ; +} +#endif + COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id, compat_long_t, min_nr, compat_long_t, nr,
@@ -1947,12 +2014,6 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,return ret; } - -struct __compat_aio_sigset { -compat_sigset_t __user *sigmask; -compat_size_t sigsetsize; -}; - COMPAT_SYSCALL_DEFINE6(io_pgetevents, compat_aio_context_t, ctx_id, compat_long_t, min_nr,
include/linux/syscalls.h +2 -2
@@ -296,12 +296,12 @@ asmlinkage long sys_io_getevents(aio_context_t ctx_id,long min_nr, long nr, struct io_event __user *events, - struct timespec __user *timeout); + struct __kernel_timespec __user *timeout);asmlinkage long sys_io_pgetevents (aio_context_t ctx_id,long min_nr,long nr,struct io_event __user *events, -struct timespec __user *timeout, +struct __kernel_timespec __user *timeout,const struct __aio_sigset *sig);/* fs/xattr.c */
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 13/17 y2038: socket: Convert recvmmsg to __kernel_timespec
In reply to Arnd BergmannThis converts the recvmmsg() system call in all its variations to use 'timespec64' internally for its timeout, and have a __kernel_timespec64 argument in the native entry point. This lets us change the type to use 64-bit time_t at a later point while using the 32-bit compat system call emulation for existing user space.
--- include/linux/socket.h | 4 ++-- include/linux/syscalls.h | 2 +- net/compat.c | 6 +++--- net/socket.c | 18 ++++++++---------- 4 files changed, 14 insertions(+), 16 deletions(-)
include/linux/socket.h +2 -2
@@ -348,7 +348,7 @@ struct ucred {extern int move_addr_to_kernel (void __user *uaddr,int ulen,struct sockaddr_storage *kaddr);extern int put_cmsg (struct msghdr *,int level,int type,int len,void *data); -struct timespec ; +struct timespec64 ;/* The __sys_...msg variants allow MSG_CMSG_COMPAT iff * forbid_cmsg_compat==false
@@ -358,7 +358,7 @@ extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg,extern long __sys_sendmsg (int fd,struct user_msghdr __user *msg,unsigned int flags,bool forbid_cmsg_compat);extern int __sys_recvmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen, -unsigned int flags,struct timespec *timeout); +unsigned int flags,struct timespec64 *timeout);extern int __sys_sendmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen,unsigned int flags,bool forbid_cmsg_compat);
include/linux/syscalls.h +1 -1
@@ -830,7 +830,7 @@ asmlinkage long sys_perf_event_open(asmlinkage long sys_accept4 (int ,struct sockaddr __user *,int __user *,int );asmlinkage long sys_recvmmsg (int fd,struct mmsghdr __user *msg,unsigned int vlen,unsigned flags, -struct timespec __user *timeout); +struct __kernel_timespec __user *timeout);asmlinkage long sys_wait4 (pid_t pid,int __user *stat_addr,int options,struct rusage __user *ru);
net/compat.c +3 -3
@@ -817,18 +817,18 @@ static int __compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, struct compat_timespec __user *timeout) {int datagrams; -struct timespec ktspec; +struct timespec64 ktspec;if (timeout ==NULL )return __sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, flags |MSG_CMSG_COMPAT ,NULL ); -if (compat_get_timespec (&ktspec, timeout)) +if (compat_get_timespec64 (&ktspec, timeout))return -EFAULT ; datagrams =__sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, flags |MSG_CMSG_COMPAT , &ktspec); -if (datagrams >0 &&compat_put_timespec (&ktspec, timeout)) +if (datagrams >0 &&compat_put_timespec64 (&ktspec, timeout)) datagrams = -EFAULT ;return datagrams;
net/socket.c +8 -10
@@ -2333,7 +2333,7 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg,*/ int __sys_recvmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen, -unsigned int flags,struct timespec *timeout) +unsigned int flags,struct timespec64 *timeout) {int fput_needed, err, datagrams;struct socket *sock;
@@ -2398,8 +2398,7 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,if (timeout) {ktime_get_ts64 (&timeout64); - *timeout =timespec64_to_timespec ( -timespec64_sub (end_time, timeout64)); + *timeout =timespec64_sub (end_time, timeout64);if (timeout->tv_sec <0 ) { timeout->tv_sec = timeout->tv_nsec =0 ;break ;
@@ -2445,10 +2444,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,static int do_sys_recvmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen,unsigned int flags, -struct timespec __user *timeout) +struct __kernel_timespec __user *timeout) {int datagrams; -struct timespec timeout_sys; +struct timespec64 timeout_sys;if (flags &MSG_CMSG_COMPAT )return -EINVAL ;
@@ -2456,13 +2455,12 @@ static int do_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg,if (!timeout)return __sys_recvmmsg (fd, mmsg, vlen, flags,NULL ); -if (copy_from_user (&timeout_sys, timeout,sizeof (timeout_sys))) +if (get_timespec64 (&timeout_sys, timeout))return -EFAULT ; datagrams =__sys_recvmmsg (fd, mmsg, vlen, flags, &timeout_sys); -if (datagrams >0 && -copy_to_user (timeout, &timeout_sys,sizeof (timeout_sys))) +if (datagrams >0 &&put_timespec64 (&timeout_sys, timeout)) datagrams = -EFAULT ;return datagrams;
@@ -2470,7 +2468,7 @@ static int do_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, - struct timespec __user *, timeout) + struct __kernel_timespec __user *, timeout) {return do_sys_recvmmsg (fd, mmsg, vlen, flags, timeout); }
@@ -2593,7 +2591,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)break ;case SYS_RECVMMSG : err =do_sys_recvmmsg (a0, (struct mmsghdr __user *)a1, a[2 ], - a[3 ], (struct timespec __user *)a[4 ]); + a[3 ], (struct __kernel_timespec __user *)a[4 ]);break ;case SYS_ACCEPT4 : err = __sys_accept4(a0, (struct sockaddr __user *)a1,
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 14/17 y2038: socket: Add compat_sys_recvmmsg_time64
In reply to Arnd Bergmannrecvmmsg() takes two arguments to pointers of structures that differ between 32-bit and 64-bit architectures: mmsghdr and timespec.
For y2038 compatbility, we are changing the native system call from timespec to __kernel_timespec with a 64-bit time_t (in another patch), and use the existing compat system call on both 32-bit and 64-bit architectures for compatibility with traditional 32-bit user space.
As we now have two variants of recvmmsg() for 32-bit tasks that are both different from the variant that we use on 64-bit tasks, this means we also require two compat system calls!
The solution I picked is to flip things around: The existing compat_sys_recvmmsg() call gets moved from net/compat.c into net/socket.c and now handles the case for old user space on all architectures that have set CONFIG_COMPAT_32BIT_TIME. A new compat_sys_recvmmsg_time64() call gets added in the old place for 64-bit architectures only, this one handles the case of a compat mmsghdr structure combined with __kernel_timespec.
In the indirect sys_socketcall(), we now need to call either do_sys_recvmmsg() or __compat_sys_recvmmsg(), depending on what kind of architecture we are on. For compat_sys_socketcall(), no such change is needed, we always call __compat_sys_recvmmsg().
I decided to not add a new SYS_RECVMMSG_TIME64 socketcall: Any libc implementation for 64-bit time_t will need significant changes including an updated asm/unistd.h, and it seems better to consistently use the separate syscalls that configuration, leaving the socketcall only for backward compatibility with 32-bit time_t based libc.
--- include/linux/compat.h | 5 ++++- include/linux/socket.h | 15 ++++++++++++++- kernel/sys_ni.c | 1 + net/compat.c | 14 +++++++------- net/socket.c | 39 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 63 insertions(+), 11 deletions(-)
include/linux/compat.h +4 -1
@@ -867,7 +867,10 @@ asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,asmlinkage long compat_sys_rt_tgsigqueueinfo (compat_pid_t tgid,compat_pid_t pid,int sig,struct compat_siginfo __user *uinfo); -asmlinkage long compat_sys_recvmmsg (int fd,struct compat_mmsghdr __user *mmsg, +asmlinkage long compat_sys_recvmmsg_time64 (int fd,struct compat_mmsghdr __user *mmsg, +unsigned vlen,unsigned int flags, +struct __kernel_timespec __user *timeout); +asmlinkage long compat_sys_recvmmsg (int fd,struct mmsghdr __user *mmsg,unsigned vlen,unsigned int flags,struct compat_timespec __user *timeout); asmlinkage long compat_sys_wait4(compat_pid_t pid,
include/linux/socket.h +14 -1
@@ -2,8 +2,8 @@#ifndef _LINUX_SOCKET_H#define _LINUX_SOCKET_H -#include <asm/socket.h> /* arch-dependent defines */ +#include <linux/errno.h> #include <linux/sockios.h> /* the SIOCxxx I/O controls */ #include <linux/uio.h> /* iovec support */ #include <linux/types.h> /* pid_t */
@@ -349,6 +349,7 @@ extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_stoextern int put_cmsg (struct msghdr *,int level,int type,int len,void *data);struct timespec64 ; +struct compat_timespec ;/* The __sys_...msg variants allow MSG_CMSG_COMPAT iff * forbid_cmsg_compat==false
@@ -359,6 +360,18 @@ extern long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned int flags, bool forbid_cmsg_compat);extern int __sys_recvmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen,unsigned int flags,struct timespec64 *timeout); +#ifdef CONFIG_COMPAT_32BIT_TIME +extern int __compat_sys_recvmmsg (int fd,struct mmsghdr __user *mmsg, +unsigned int vlen,unsigned int flags, +struct compat_timespec __user *timeout); +#else +static inline int __compat_sys_recvmmsg (int fd,struct mmsghdr __user *mmsg, +unsigned int vlen,unsigned int flags, +struct compat_timespec __user *timeout) +{ +return -EINVAL ; +} +#endif extern int __sys_sendmmsg (int fd,struct mmsghdr __user *mmsg,unsigned int vlen,unsigned int flags,bool forbid_cmsg_compat);
kernel/sys_ni.c +1 -0
@@ -285,6 +285,7 @@ COND_SYSCALL(perf_event_open);COND_SYSCALL (accept4);COND_SYSCALL (recvmmsg);COND_SYSCALL_COMPAT (recvmmsg); +COND_SYSCALL_COMPAT (recvmmsg_time64);/* * Architecture specific syscalls: see further below
net/compat.c +7 -7
@@ -812,9 +812,9 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, lenreturn __compat_sys_recvfrom (fd, buf, len, flags, addr, addrlen); } -static int __compat_sys_recvmmsg (int fd,struct compat_mmsghdr __user *mmsg, +static int __compat_sys_recvmmsg_time64 (int fd,struct compat_mmsghdr __user *mmsg,unsigned int vlen,unsigned int flags, -struct compat_timespec __user *timeout) +struct __kernel_timespec __user *timeout) {int datagrams;struct timespec64 ktspec;
@@ -823,22 +823,22 @@ static int __compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,return __sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, flags |MSG_CMSG_COMPAT ,NULL ); -if (compat_get_timespec64 (&ktspec, timeout)) +if (get_timespec64 (&ktspec, timeout))return -EFAULT ; datagrams =__sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, flags |MSG_CMSG_COMPAT , &ktspec); -if (datagrams >0 &&compat_put_timespec64 (&ktspec, timeout)) +if (datagrams >0 &&put_timespec64 (&ktspec, timeout)) datagrams = -EFAULT ;return datagrams; } -COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, +COMPAT_SYSCALL_DEFINE5(recvmmsg_time64, int, fd, struct compat_mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, - struct compat_timespec __user *, timeout) + struct __kernel_timespec __user *, timeout) { -return __compat_sys_recvmmsg (fd, mmsg, vlen, flags, timeout); +return __compat_sys_recvmmsg_time64 (fd, mmsg, vlen, flags, timeout); } COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
net/socket.c +37 -2
@@ -2473,6 +2473,37 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,return do_sys_recvmmsg (fd, mmsg, vlen, flags, timeout); } +#ifdef CONFIG_COMPAT_32BIT_TIME +int __compat_sys_recvmmsg (int fd,struct mmsghdr __user *mmsg, +unsigned int vlen,unsigned int flags, +struct compat_timespec __user *timeout) +{ +int datagrams; +struct timespec64 ktspec; + +if (timeout ==NULL ) +return __sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, + flags |MSG_CMSG_COMPAT ,NULL ); + +if (compat_get_timespec64 (&ktspec, timeout)) +return -EFAULT ; + + datagrams =__sys_recvmmsg (fd, (struct mmsghdr __user *)mmsg, vlen, + flags |MSG_CMSG_COMPAT , &ktspec); +if (datagrams >0 &&compat_put_timespec64 (&ktspec, timeout)) + datagrams = -EFAULT ; + +return datagrams; +} + +COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, + unsigned int, vlen, unsigned int, flags, + struct compat_timespec __user *, timeout) +{ +return __compat_sys_recvmmsg (fd, mmsg, vlen, flags, timeout); +} +#endif +#ifdef __ARCH_WANT_SYS_SOCKETCALL/* Argument list sizes for sys_socketcall */ #define AL (x) ((x) * sizeof(unsigned long))
@@ -2590,8 +2621,12 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) a[2], true);break ;case SYS_RECVMMSG : - err =do_sys_recvmmsg (a0, (struct mmsghdr __user *)a1, a[2 ], - a[3 ], (struct __kernel_timespec __user *)a[4 ]); +if (IS_ENABLED (CONFIG_64BIT ) || !IS_ENABLED (CONFIG_64BIT_TIME )) + err =do_sys_recvmmsg (a0, (struct mmsghdr __user *)a1, a[2 ], + a[3 ], (struct __kernel_timespec __user *)a[4 ]); +else + err =__compat_sys_recvmmsg (a0, (struct mmsghdr __user *)a1, a[2 ], + a[3 ], (struct compat_timespec __user *)a[4 ]);break ;case SYS_ACCEPT4 : err = __sys_accept4(a0, (struct sockaddr __user *)a1,
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 15/17 y2038: signal: Change rt_sigtimedwait to use __kernel_timespec
In reply to Arnd BergmannThis changes sys_rt_sigtimedwait() to use get_timespec64(), changing the timeout type to __kernel_timespec, which will be changed to use a 64-bit time_t in the future. Since the do_sigtimedwait() core function changes, we also have to modify the compat version of this system call in the same way.
--- include/linux/syscalls.h | 2 +- kernel/signal.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
include/linux/syscalls.h +1 -1
@@ -635,7 +635,7 @@ asmlinkage long sys_rt_sigprocmask(int how, sigset_t __user *set,asmlinkage long sys_rt_sigpending (sigset_t __user *set,size_t sigsetsize);asmlinkage long sys_rt_sigtimedwait (const sigset_t __user *uthese,siginfo_t __user *uinfo, -const struct timespec __user *uts, +const struct __kernel_timespec __user *uts,size_t sigsetsize);asmlinkage long sys_rt_sigqueueinfo (pid_t pid,int sig,siginfo_t __user *uinfo);
kernel/signal.c +9 -8
@@ -3036,7 +3036,7 @@ int copy_siginfo_from_user32(struct siginfo *to,* @ts: upper bound on process time suspension */ static int do_sigtimedwait (const sigset_t *which,siginfo_t *info, -const struct timespec *ts) +const struct timespec64 *ts) {ktime_t *to =NULL , timeout =KTIME_MAX ;struct task_struct *tsk = current;
@@ -3044,9 +3044,9 @@ static int do_sigtimedwait(const sigset_t *which, siginfo_t *info,int sig, ret =0 ;if (ts) { -if (!timespec_valid (ts)) +if (!timespec64_valid (ts))return -EINVAL ; - timeout =timespec_to_ktime (*ts); + timeout =timespec64_to_ktime (*ts); to = &timeout; }
@@ -3094,11 +3094,12 @@ static int do_sigtimedwait(const sigset_t *which, siginfo_t *info,* @sigsetsize: size of sigset_t type */ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, - siginfo_t __user *, uinfo, const struct timespec __user *, uts, + siginfo_t __user *, uinfo, + const struct __kernel_timespec __user *, uts, size_t, sigsetsize) {sigset_t these; -struct timespec ts; +struct timespec64 ts;siginfo_t info;int ret;
@@ -3110,7 +3111,7 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,return -EFAULT ;if (uts) { -if (copy_from_user (&ts, uts,sizeof (ts))) +if (get_timespec64 (&ts, uts))return -EFAULT ; }
@@ -3130,7 +3131,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, struct compat_timespec __user *, uts, compat_size_t, sigsetsize) { sigset_t s; -struct timespec t; +struct timespec64 t;siginfo_t info;long ret;
@@ -3141,7 +3142,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,return -EFAULT ;if (uts) { -if (compat_get_timespec (&t, uts)) +if (compat_get_timespec64 (&t, uts))return -EFAULT ; }
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 16/17 y2038: Make compat_sys_rt_sigtimedwait usable on 32-bit
In reply to Arnd BergmannOnce sys_rt_sigtimedwait() gets changed to a 64-bit time_t, we have to provide compatibility support for existing binaries. Using the compat_sys_rt_sigtimedwait() entry point is convenient because it allows to share the implementation with 64-bit architectures.
Unfortunately, the get_compat_sigset() and copy_siginfo_to_user32() functions are used in that function, but we can replace them with trivial helpers that do the same thing as before.
--- kernel/signal.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
kernel/signal.c +17 -2
@@ -3027,7 +3027,22 @@ int copy_siginfo_from_user32(struct siginfo *to, }return 0 ; } -#endif /* CONFIG_COMPAT */ + +#else /* !CONFIG_COMPAT */ + +/* 32-bit architectures only need to convert compat_time_t, not siginfo or sigset_t */ + +#define compat_siginfo siginfo +#define compat_sigset_t sigset_t +#define copy_siginfo_to_user32 copy_siginfo_to_user +static inline int get_compat_sigset (sigset_t *set,const sigset_t __user *compat) +{ +if (copy_from_user (set, compat,sizeof *set)) +return -EFAULT ; + +return 0 ; +} +#endif /* !CONFIG_COMPAT */ /** * do_sigtimedwait - wait for queued signals specified in @which
@@ -3125,7 +3140,7 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,return ret; } -#ifdef CONFIG_COMPAT +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, struct compat_siginfo __user *, uinfo, struct compat_timespec __user *, uts, compat_size_t, sigsetsize)
Signature · 1 line
2.9.0
Arnd Bergmann
maintainerPATCH v2 17/17 y2038: signal: Add compat_sys_rt_sigtimedwait_time64
In reply to Arnd BergmannNow that 32-bit architectures have two variants of sys_rt_sigtimedwaid() for 32-bit and 64-bit time_t, we also need to have a second compat system call entry point on the corresponding 64-bit architectures.
The traditional system call keeps getting handled by compat_sys_rt_sigtimedwait(), and this adds a new compat_sys_rt_sigtimedwait_time64() that differs only in the timeout argument type.
--- kernel/signal.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
kernel/signal.c +32 -0
@@ -3172,6 +3172,38 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, }#endif +#ifdef CONFIG_COMPAT +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese, + struct compat_siginfo __user *, uinfo, + struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize) +{ +sigset_t s; +struct timespec64 t; +siginfo_t info; +long ret; + +if (sigsetsize !=sizeof (sigset_t)) +return -EINVAL ; + +if (get_compat_sigset (&s, uthese)) +return -EFAULT ; + +if (uts) { +if (get_timespec64 (&t, uts)) +return -EFAULT ; + } + + ret =do_sigtimedwait (&s, &info, uts ? &t :NULL ); + +if (ret >0 && uinfo) { +if (copy_siginfo_to_user32 (uinfo, &info)) + ret = -EFAULT ; + } + +return ret; +} +#endif +/** * sys_kill - send a signal to a process * @pid: the PID of the process
Signature · 1 line
2.9.0
Re: [PATCH v2 01/17] y2038: compat: Move common compat types to asm-generic/compat.h
In reply to Arnd BergmannQuoted 12 lines · Arnd Bergmann
While converting compat system call handlers to work on 32-bit architectures, I found a number of types used in those handlers that are identical between all architectures.
Let's move all the identical ones into
asm-generic/compat.hto avoid having to add even more identical definitions of those types.For unknown reasons, mips defines
__compat_gid32_t,__compat_uid32_tandcompat_caddr_tas signed, while all others have them unsigned. This seems to be a mistake, but I'm leaving it alone here. The other types all differ by size or alignment on at least on architecture.
Quoted 7 lines
compat_aio_context_tis currently defined inlinux/compat.hbut also needed forcompat_sys_io_getevents(), so let's move it into the same place.While we still have not decided whether the 32-bit time handling will always use the compat syscalls, or in which form, I think this is a useful cleanup that we can merge regardless.
Looks good:
Re: [PATCH v2 02/17] y2038: Remove newstat family from default syscall set
In reply to Arnd BergmannQuoted 17 lines · Arnd Bergmann
We have four generations of
stat()syscalls:
- the oldstat syscalls that are only used on the older architectures
- the newstat family that is used on all 64-bit architectures but lacked support for large files on 32-bit architectures.
- the stat64 family that is used mostly on 32-bit architectures to replace newstat
-statx()to replace all of the above, adding 64-bit timestamps among other things.We already compile stat64 only on those architectures that need it, but newstat is always built, including on those that don't reference it. This adds a new
__ARCH_WANT_NEW_STATsymbol along the lines of__ARCH_WANT_OLD_STATand__ARCH_WANT_STAT64to control compilation of newstat. All architectures that need it use an explict define, the others now get a little bit smaller, and future architecture (including 64-bit targets) won't ever see it.
Quoted 2 lines
Signed-off-by Arnd Bergmann <[email protected]>
Do I read this right that you only want to provide statx by default? It is a little different from the traditional stat calls, so I'd like to know this is actually ok from libc folks first.
Re: [PATCH v2 04/17] asm-generic: Remove unneeded __ARCH_WANT_SYS_LLSEEK macro
In reply to Arnd BergmannQuoted 4 lines · Arnd Bergmann
The
sys_llseeksytem call is needed on all 32-bit architectures and none of the 64-bit ones, so we can remove the__ARCH_WANT_SYS_LLSEEKguard and simplify theinclude/asm-generic/unistd.hheader further.
Quoted 8 lines
Since 32-bit tasks can run either natively or in compat mode on 64-bit architectures, we have to check for both !CONFIG_64BIT and
CONFIG_COMPAT.There are a few 64-bit architectures that also reference
sys_llseekin their 64-bit ABI (e.g. sparc), but I verified that those all selectCONFIG_COMPAT, so the #if check is still correct here. It's a bit odd to include it in the syscall table though, as it's the same assys_lseek()on 64-bit, but with strange calling conventions.
Looks good,
Re: [PATCH v2 05/17] asm-generic: Remove empty asm/unistd.h
In reply to Arnd BergmannQuoted 5 lines · Arnd Bergmann
Nothing is left in
asm/unistd.hexcept for the redirect touapi/asm/unistd.h, so removing the file simply leads to that one being used directly. Thelinux/export.hinclusion is a leftover from commite1b5bb6d1236("consolidatecond_syscallandSYSCALL_ALIASdeclarations") and should not be used anyway.
Looks good,
Re: [PATCH v2 06/17] y2038: Change sys_utimensat() to use __kernel_timespec
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
When 32-bit architectures get changed to support 64-bit
time_t,utimensat()needs to use the new__kernel_timespecstructure as its argument.The older
utime(),utimes()andfutimesat()system calls don't need a corresponding change as they are no longer used on C libraries that have 64-bit time support.
Quoted 5 lines
As we do for the other syscalls that have timespec arguments, we reuse the 'compat' syscall entry points to implement the traditional four interfaces, and only leave the new
utimensat()as a native handler, so that the same code gets used on both 32-bit and 64-bit kernels on each syscall.
I wonder about the direction here: wouldn't it be easier to just leave th existing syscall names as-is and introduce a new utimesat64 which uses the new timespec? We can then drop the old legacy utimesat for new architectures added after the cutover.
Arnd Bergmann
maintainerRe: [PATCH v2 02/17] y2038: Remove newstat family from default syscall set
In reply to Christoph HellwigQuoted 18 lines · Christoph Hellwig
Quoted 17 lines · Arnd Bergmann
We have four generations of
stat()syscalls:
- the oldstat syscalls that are only used on the older architectures
- the newstat family that is used on all 64-bit architectures but lacked support for large files on 32-bit architectures.
- the stat64 family that is used mostly on 32-bit architectures to replace newstat
-statx()to replace all of the above, adding 64-bit timestamps among other things.We already compile stat64 only on those architectures that need it, but newstat is always built, including on those that don't reference it. This adds a new
__ARCH_WANT_NEW_STATsymbol along the lines of__ARCH_WANT_OLD_STATand__ARCH_WANT_STAT64to control compilation of newstat. All architectures that need it use an explict define, the others now get a little bit smaller, and future architecture (including 64-bit targets) won't ever see it.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Arnd Bergmann <[email protected]>Do I read this right that you only want to provide statx by default?
Yes, that is correct.
Quoted 2 lines
It is a little different from the traditional stat calls, so I'd like to know this is actually ok from libc folks first.
That would definitely help. See below for the stat implementation I did in my musl libc prototype based on statx(). It passes the LTP syscall tests, but that doesn't mean all the corner cases are correct.
Arnd
src/stat/fstat.c +5 -0
@@ -1,3 +1,4 @@ +#define _BSD_SOURCE#include <sys/stat.h> #include <errno.h> #include <fcntl.h>
@@ -8,6 +9,9 @@ void __procfdname(char *, unsigned);int fstat (int fd,struct stat *st) { +#ifdef __USE_TIME_BITS64 +return __statx (fd,"" , st,AT_EMPTY_PATH |AT_STATX_SYNC_AS_STAT ); +#else int ret =__syscall (SYS_fstat, fd, st);if (ret != -EBADF ||__syscall (SYS_fcntl, fd,F_GETFD ) <0 )return __syscall_ret (ret);
@@ -19,6 +23,7 @@ int fstat(int fd, struct stat *st)#else return syscall (SYS_fstatat,AT_FDCWD , buf, st,0 );#endif +#endif }LFS64 (fstat);
src/stat/fstatat.c +9 -0
@@ -1,10 +1,53 @@ +#define _BSD_SOURCE#include <sys/stat.h> +#include <statx.h> +#include <fcntl.h> +#include <errno.h> #include "syscall.h" #include "libc.h" +#ifdef __USE_TIME_BITS64 + +#define AT_FLAGS (AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH) + +int __statx(int fd, const char *restrict path, struct stat *restrict
buf, int flag)
+{
+ struct statx stx;
+ int ret;
+
+ ret = syscall(SYS_statx, fd, path, flag, STATX_BASIC_STATS, &stx);
+
+ buf->st_dev = (dev_t)stx.stx_dev_major << 32 | stx.stx_dev_minor; + buf->st_ino = stx.stx_ino; + buf->st_mode = stx.stx_mode; + buf->st_nlink = stx.stx_nlink; + buf->st_uid = stx.stx_uid; + buf->st_gid = stx.stx_gid; + buf->st_rdev = (dev_t)stx.stx_rdev_major << 32 | stx.stx_rdev_minor; + buf->st_size = stx.stx_size; + buf->st_blksize = stx.stx_blksize; + buf->st_blocks = stx.stx_blocks; + buf->st_atim.tv_sec = stx.stx_atime.tv_sec; + buf->st_mtim.tv_sec = stx.stx_atime.tv_sec; + buf->st_ctim.tv_sec = stx.stx_atime.tv_sec; + buf->st_atim.tv_nsec = stx.stx_atime.tv_nsec; + buf->st_mtim.tv_nsec = stx.stx_atime.tv_nsec; + buf->st_ctim.tv_nsec = stx.stx_atime.tv_nsec;
+
+ return ret;
+}
+#endif
+
int fstatat(int fd, const char *restrict path, struct stat *restrict
buf, int flag)
{
+#ifdef __USE_TIME_BITS64
+ if (flag & ~AT_FLAGS)
+ return __syscall_ret(-EINVAL);
+
+ return __statx(fd, path, buf, flag);
+#else
return syscall(SYS_fstatat, fd, path, buf, flag);
+#endif
}
LFS64(fstatat);
src/stat/lstat.c +3 -1
@@ -1,3 +1,4 @@ +#define _BSD_SOURCE#include <sys/stat.h> #include <fcntl.h> #include "syscall.h"
@@ -5,7 +6,9 @@int lstat (const char *restrict path,struct stat *restrict buf) { -#ifdef SYS_lstat +#ifdef __USE_TIME_BITS64 + return __statx(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW |
AT_STATX_SYNC_AS_STAT);
+#elif defined(SYS_lstat)
return syscall(SYS_lstat, path, buf);
#else
return syscall(SYS_fstatat, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);src/stat/stat.c +4 -1
@@ -1,3 +1,4 @@ +#define _BSD_SOURCE#include <sys/stat.h> #include <fcntl.h> #include "syscall.h"
@@ -5,7 +6,9 @@int stat (const char *restrict path,struct stat *restrict buf) { -#ifdef SYS_stat +#ifdef __USE_TIME_BITS64 +return __statx (AT_FDCWD , path, buf,AT_STATX_SYNC_AS_STAT ); +#elif defined(SYS_stat)return syscall (SYS_stat, path, buf);#else return syscall (SYS_fstatat,AT_FDCWD , path, buf,0 );
Arnd Bergmann
maintainerRe: [PATCH v2 06/17] y2038: Change sys_utimensat() to use __kernel_timespec
In reply to Christoph HellwigQuoted 15 lines · Christoph Hellwig
Quoted 8 lines · Arnd Bergmann
When 32-bit architectures get changed to support 64-bit
time_t,utimensat()needs to use the new__kernel_timespecstructure as its argument.The older
utime(),utimes()andfutimesat()system calls don't need a corresponding change as they are no longer used on C libraries that have 64-bit time support.Quoted 5 lines
As we do for the other syscalls that have timespec arguments, we reuse the 'compat' syscall entry points to implement the traditional four interfaces, and only leave the new
utimensat()as a native handler, so that the same code gets used on both 32-bit and 64-bit kernels on each syscall.
Quoted 4 lines
I wonder about the direction here: wouldn't it be easier to just leave th existing syscall names as-is and introduce a new utimesat64 which uses the new timespec? We can then drop the old legacy utimesat for new architectures added after the cutover.
We have debated both approaches over several years, but for most syscalls, we picked the approach described above, for multiple reasons:
- For any system call that takes a time_t derived argument, we already have two implementations (native and compat), so adding a third one requires duplicating some code.
- I want to avoid adding an implementation that is not well tested if possible, to make it less likely to introduce security holes or subtle bugs that we can't fix later without breaking the ABI. Using the same implementation for the new 32-bit case that we have for the existing 64-bit case means that this code is much better exercised, while reusing the compat code for the traditional native syscall means it gets exercised by all current user space, which makes it more likely to catch bugs early.
- Looking at the end result, I find it more logical to have each of the converted syscalls implement the same binary interface on both 32-bit and 64-bit architectures with the same code, and have the old 32-bit implementation be similarly shared. This is even more important once we add new architectures that don't even provide the 32-bit time_t interfaces and just leave out the old entry points.
Arnd
Re: [PATCH v2 02/17] y2038: Remove newstat family from default syscall set
In reply to Arnd BergmannQuoted 4 lines · Arnd Bergmann
That would definitely help. See below for the stat implementation I did in my musl libc prototype based on
statx(). It passes the LTP syscall tests, but that doesn't mean all the corner cases are correct.
Well, you definitely need explicit timestamp conversions on the result of statx to be usable in struct stat when userspace "long" is 64-bit, for BE because otherwise the integer nanoseconds will be in the wrong place for struct timespec, and for LE if the "__reserved is held in case we need a yet finer resolution." might start being returned as nonzero (for integer attoseconds, I suppose) in future.
Signature · 2 lines
Joseph S. Myers [email protected]
Arnd Bergmann
maintainerRe: [PATCH v2 02/17] y2038: Remove newstat family from default syscall set
Quoted 7 lines · Joseph Myers
Quoted 4 lines · Arnd Bergmann
That would definitely help. See below for the stat implementation I did in my musl libc prototype based on
statx(). It passes the LTP syscall tests, but that doesn't mean all the corner cases are correct.
Quoted 6 lines
Well, you definitely need explicit timestamp conversions on the result of statx to be usable in struct stat when userspace "long" is 64-bit, for BE because otherwise the integer nanoseconds will be in the wrong place for struct timespec, and for LE if the "
__reservedis held in case we need a yet finer resolution." might start being returned as nonzero (for integer attoseconds, I suppose) in future.
Right. The musl implementation I sent did that by simply copying each field we care about from the statx structure into the stat structure individually. This is the more or less the same thing that the kernel does to implement stat() as well.
Arnd