[Y2038] [PATCH 21/23] y2038: itimer: change implementation to timespec64

2019-11-08 Thread Arnd Bergmann
There is no 64-bit version of getitimer/setitimer since that is not actually needed. However, the implementation is built around the deprecated 'struct timeval' type. Change the code to use timespec64 internally to reduce the dependencies on timeval and associated helper functions. Minor

[Y2038] [PATCH 22/23] [RFC] y2038: itimer: use ktime_t internally

2019-11-08 Thread Arnd Bergmann
Avoid the intermediate step going from timeval to timespec64 to ktime_t and back by using ktime_t throughout the code. I was going back and forth between the two implementations. This patch is optional: if we want it, it could be folded into the patch converting to itimerspec64. On an arm32

[Y2038] [PATCH 4/8] ipmi: kill off 'timespec' usage again

2019-11-08 Thread Arnd Bergmann
'struct timespec' is getting removed from the kernel. The usage in ipmi was fixed before in commit 48862ea2ce86 ("ipmi: Update timespec usage to timespec64"), but unfortunately it crept back in. The busy looping code can better use ktime_t anyway, so use that there to simplify the implementation.

[Y2038] [PATCH 7/8] ppdev: fix PPGETTIME/PPSETTIME ioctls

2019-11-08 Thread Arnd Bergmann
Going through the uses of timeval in the user space API, I noticed two bugs in ppdev that were introduced in the y2038 conversion: * The range check was accidentally moved from ppsettime to ppgettime * On sparc64, the microseconds are in the other half of the 64-bit word. Fix both, and mark

[Y2038] [PATCH 8/8] Input: input_event: fix struct padding on sparc64

2019-11-08 Thread Arnd Bergmann
Going through all uses of timeval, I noticed that we screwed up input_event in the previous attempts to fix it: The time fields now match between kernel and user space, but all following fields are in the wrong place. Add the required padding that is implied by the glibc timeval definition to

[Y2038] [PATCH 18/23] y2038: itimer: compat handling to itimer.c

2019-11-08 Thread Arnd Bergmann
The structure is only used in one place, moving it there simplifies the interface and helps with later changes to this code. Rename it to match the other time32 structures in the process. Signed-off-by: Arnd Bergmann --- include/linux/compat.h | 15 --- kernel/compat.c| 24

[Y2038] [PATCH 19/23] y2038: use compat_{get,set}_itimer on alpha

2019-11-08 Thread Arnd Bergmann
The itimer handling for the old alpha osf_setitimer/osf_getitimer system calls is identical to the compat version of getitimer/setitimer, so just use those directly. Signed-off-by: Arnd Bergmann --- arch/alpha/kernel/osf_sys.c| 65 --

[Y2038] [PATCH 17/23] y2038: time: avoid timespec usage in settimeofday()

2019-11-08 Thread Arnd Bergmann
The compat_get_timeval() and timeval_valid() interfaces are deprecated and getting removed along with the definition of struct timeval itself. Change the two implementations of the settimeofday() system call to open-code these helpers and completely avoid references to timeval. Signed-off-by:

[Y2038] [PATCH 16/23] y2038: timerfd: Use timespec64 internally

2019-11-08 Thread Arnd Bergmann
timerfd_show() uses a 'struct itimerspec' internally, but that is deprecated because of the time_t overflow and a conflict with the glibc type of the same name that is now incompatible in user space. Use a pair of timespec64 variables instead as a simple replacement. As this removes the last use

[Y2038] [PATCH 10/23] y2038: uapi: change __kernel_time_t to __kernel_old_time_t

2019-11-08 Thread Arnd Bergmann
This is mainly a patch for clarification, and to let us remove the time_t definition from the kernel to prevent new users from creeping in that might not be y2038-safe. All remaining uses of 'time_t' or '__kernel_time_t' are part of the user API that cannot be changed by that either have a

[Y2038] [PATCH 2/8] timekeeping: optimize ns_to_timespec64

2019-11-08 Thread Arnd Bergmann
I noticed that ns_to_timespec64() calls div_s64_rem(), which is a rather slow function on 32-bit architectures, as it cannot take advantage of the do_div() optimizations for constant arguments. This open-codes the div_s64_rem() function here, so we can pass a constant divider into the optimized

[Y2038] [PATCH 1/8] y2038: timex: remove incorrect time_t truncation

2019-11-08 Thread Arnd Bergmann
A cast to 'time_t' was accidentally left in place during the conversion of __do_adjtimex() to 64-bit timestamps, so the resulting value is incorrectly truncated. Remove the cast so the 64-bit time gets propagated correctly. Cc: sta...@vger.kernel.org Fixes: ead25417f82e ("timex: use

[Y2038] [PATCH 00/23] y2038 cleanups

2019-11-08 Thread Arnd Bergmann
This is a series of cleanups for the y2038 work, mostly intended for namespace cleaning: the kernel defines the traditional time_t, timeval and timespec types that often lead to y2038-unsafe code. Even though the unsafe usage is mostly gone from the kernel, having the types and associated

[Y2038] [PATCH 01/23] y2038: remove CONFIG_64BIT_TIME

2019-11-08 Thread Arnd Bergmann
The CONFIG_64BIT_TIME option is defined on all architectures, and can be removed for simplicity now. Signed-off-by: Arnd Bergmann --- arch/Kconfig | 8 fs/aio.c | 2 +- ipc/syscall.c | 2 +- kernel/time/hrtimer.c | 2 +- kernel/time/time.c| 4 ++--

[Y2038] [PATCH 02/23] y2038: add __kernel_old_timespec and __kernel_old_time_t

2019-11-08 Thread Arnd Bergmann
The 'struct timespec' definition can no longer be part of the uapi headers because it conflicts with a a now incompatible libc definition. Also, we really want to remove it in order to prevent new uses from creeping in. The same namespace conflict exists with time_t, which should also be removed.

[Y2038] [PATCH 04/23] y2038: vdso: change timespec to __kernel_old_timespec

2019-11-08 Thread Arnd Bergmann
In order to remove 'timespec' completely from the kernel, all internal uses should be converted to a y2038-safe type, while those that are only for compatibity with existing user space should be marked appropriately. Change vdso to use __kernel_old_timespec in order to avoid the deprecated type

[Y2038] [PATCH 06/23] y2038: vdso: nds32: open-code timespec_add_ns()

2019-11-08 Thread Arnd Bergmann
The nds32 vdso is now the last user of the deprecated timespec_add_ns(). Change it to an open-coded version like the one it already uses in do_realtime(). What we should really do though is to use the generic vdso implementation that is now used in x86. arm and mips. Signed-off-by: Arnd Bergmann

[Y2038] [PATCH 03/23] y2038: vdso: change timeval to __kernel_old_timeval

2019-11-08 Thread Arnd Bergmann
The gettimeofday() function in vdso uses the traditional 'timeval' structure layout, which will be incompatible with future versions of glibc on 32-bit architectures that use a 64-bit time_t. This interface is problematic for y2038, when time_t overflows on 32-bit architectures, but the plan so

[Y2038] [PATCH 07/23] y2038: vdso: powerpc: avoid timespec references

2019-11-08 Thread Arnd Bergmann
As a preparation to stop using 'struct timespec' in the kernel, change the powerpc vdso implementation: - split up the vdso data definition to have equivalent members for seconds and nanoseconds instead of an xtime structure - use timespec64 as an intermediate for the xtime update - change

[Y2038] [PATCH 6/8] lp: fix sparc64 LPSETTIMEOUT ioctl

2019-11-08 Thread Arnd Bergmann
The layout of struct timeval is different on sparc64 from anything else, and the patch I did long ago failed to take this into account. Change it now to handle sparc64 user space correctly again. Quite likely nobody cares about parallel ports on sparc64, but there is no reason not to fix it.

[Y2038] [PATCH 12/23] y2038: syscalls: change remaining timeval to __kernel_old_timeval

2019-11-08 Thread Arnd Bergmann
All of the remaining syscalls that pass a timeval (gettimeofday, utime, futimesat) can trivially be changed to pass a __kernel_old_timeval instead, which has a compatible layout, but avoids ambiguity with the timeval type in user space. Signed-off-by: Arnd Bergmann ---

[Y2038] [PATCH 13/23] y2038: socket: remove timespec reference in timestamping

2019-11-08 Thread Arnd Bergmann
In order to remove the 'struct timespec' definition and the timespec64_to_timespec() helper function, change over the in-kernel definition of 'struct scm_timestamping' to use the __kernel_old_timespec replacement and open-code the assignment. Signed-off-by: Arnd Bergmann ---

[Y2038] [PATCH 15/23] y2038: elfcore: Use __kernel_old_timeval for process times

2019-11-08 Thread Arnd Bergmann
We store elapsed time for a crashed process in struct elf_prstatus using 'timeval' structures. Once glibc starts using 64-bit time_t, this becomes incompatible with the kernel's idea of timeval since the structure layout no longer matches on 32-bit architectures. This changes the definition of

[Y2038] [PATCH 11/23] y2038: rusage: use __kernel_old_timeval

2019-11-08 Thread Arnd Bergmann
There are two 'struct timeval' fields in 'struct rusage'. Unfortunately the definition of timeval is now ambiguous when used in user space with a libc that has a 64-bit time_t, and this also changes the 'rusage' definition in user space in a way that is incompatible with the system call

[Y2038] [PATCH 14/23] y2038: make ns_to_compat_timeval use __kernel_old_timeval

2019-11-08 Thread Arnd Bergmann
This gets us one step closer to removing 'struct timeval' from the kernel. We still keep __kernel_old_timeval for interfaces that we cannot fix otherwise, and ns_to_compat_timeval() is provably safe for interfaces that are legitimate users of __kernel_old_timeval on native kernels, so this is an

[Y2038] [PATCH 13/16] hfs/hfsplus: use 64-bit inode timestamps

2019-11-08 Thread Arnd Bergmann
The interpretation of on-disk timestamps in HFS and HFS+ differs between 32-bit and 64-bit kernels at the moment. Use 64-bit timestamps consistently so apply the current 64-bit behavior everyhere. According to the official documentation for HFS+ [1], inode timestamps are supposed to cover the

[Y2038] [PATCH 12/16] hostfs: pass 64-bit timestamps to/from user space

2019-11-08 Thread Arnd Bergmann
The use of 'struct timespec' is deprecated in the kernel, so we want to avoid the conversions from/to the proper timespec64 structure. On the user space side, we have a 'struct timespec' that is defined by the C library and that will be incompatible with the kernel's view on 32-bit architectures

[Y2038] [PATCH 05/16] xtensa: ISS: avoid struct timeval

2019-11-08 Thread Arnd Bergmann
'struct timeval' will get removed from the kernel, change the one user in arch/xtensa to avoid referencing it, by using a fixed-length array instead. Signed-off-by: Arnd Bergmann --- arch/xtensa/platforms/iss/include/platform/simcall.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)

[Y2038] [PATCH 03/16] net: sock: use __kernel_old_timespec instead of timespec

2019-11-08 Thread Arnd Bergmann
The 'timespec' type definition and helpers like ktime_to_timespec() or timespec64_to_timespec() should no longer be used in the kernel so we can remove them and avoid introducing y2038 issues in new code. Change the socket code that needs to pass a timespec to user space for backward

[Y2038] [PATCH 04/16] dlm: use SO_SNDTIMEO_NEW instead of SO_SNDTIMEO_OLD

2019-11-08 Thread Arnd Bergmann
Eliminate one more use of 'struct timeval' from the kernel so we can eventually remove the definition as well. The kernel supports the new format with a 64-bit time_t version of timeval here, so use that instead of the old timeval. Signed-off-by: Arnd Bergmann --- fs/dlm/lowcomms.c | 6 +++---

Re: [Y2038] [PATCH 15/16] drm/etnaviv: use ktime_t for timeouts

2019-11-08 Thread Lucas Stach
Am Freitag, den 08.11.2019, 22:32 +0100 schrieb Arnd Bergmann: > struct timespec is being removed from the kernel because it often leads > to code that is not y2038-safe. > > In the etnaviv driver, monotonic timestamps are used, which do not suffer > from overflow, but using ktime_t still leads

[Y2038] [PATCH 06/16] um: ubd: use 64-bit time_t where possible

2019-11-08 Thread Arnd Bergmann
The ubd code suffers from a possible y2038 overflow on 32-bit architectures, both for the cow header and the os_file_modtime() function. Replace time_t with time64_t to extend the ubd_kern side as much as possible. Whether this makes a difference for the user side depends on the host libc

[Y2038] [PATCH 14/16] drm/msm: avoid using 'timespec'

2019-11-08 Thread Arnd Bergmann
The timespec structure and associated interfaces are deprecated and will be removed in the future because of the y2038 overflow. The use of ktime_to_timespec() in timeout_to_jiffies() does not suffer from that overflow, but is easy to avoid by just converting the ktime_t into jiffies directly.

[Y2038] [PATCH 08/16] tsacct: add 64-bit btime field

2019-11-08 Thread Arnd Bergmann
As there is only a 32-bit ac_btime field in taskstat and we should handle dates after the overflow, add a new field with the same information but 64-bit width that can hold a full time64_t. Signed-off-by: Arnd Bergmann --- include/uapi/linux/taskstats.h | 5 - kernel/tsacct.c

[Y2038] [PATCH 10/16] packet: clarify timestamp overflow

2019-11-08 Thread Arnd Bergmann
The memory mapped packet socket data structure in version 1 through 3 all contain 32-bit second values for the packet time stamps, which makes them suffer from the overflow of time_t in y2038 or y2106 (depending on whether user space interprets the value as signed or unsigned). The implementation

[Y2038] [PATCH 16/16] firewire: ohci: stop using get_seconds() for BUS_TIME

2019-11-08 Thread Arnd Bergmann
The ohci driver uses the get_seconds() function to implement the 32-bit CSR_BUS_TIME register. This was added in 2010 commit a48777e03ad5 ("firewire: add CSR BUS_TIME support"). As get_seconds() returns a 32-bit value (on 32-bit architectures), it seems like a good fit for that register, but it

[Y2038] [PATCH 11/16] quota: avoid time_t in v1_disk_dqblk definition

2019-11-08 Thread Arnd Bergmann
The time_t type is part of the user interface and not always the same, with the move to 64-bit timestamps and the difference between architectures. Make the quota format definition independent of this type and use a basic type of the same length. Make it unsigned in the process to keep the v1

[Y2038] [PATCH 15/16] drm/etnaviv: use ktime_t for timeouts

2019-11-08 Thread Arnd Bergmann
struct timespec is being removed from the kernel because it often leads to code that is not y2038-safe. In the etnaviv driver, monotonic timestamps are used, which do not suffer from overflow, but using ktime_t still leads to better code overall. The conversion is straightforward for the most

Re: [Y2038] [PATCH 05/16] xtensa: ISS: avoid struct timeval

2019-11-08 Thread Max Filippov
On Fri, Nov 8, 2019 at 1:34 PM Arnd Bergmann wrote: > > 'struct timeval' will get removed from the kernel, change the one > user in arch/xtensa to avoid referencing it, by using a fixed-length > array instead. > > Signed-off-by: Arnd Bergmann > --- >

[Y2038] [PATCH 02/16] fat: use prandom_u32() for i_generation

2019-11-08 Thread Arnd Bergmann
Similar to commit 46c9a946d766 ("shmem: use monotonic time for i_generation") we should not use the deprecated get_seconds() interface for i_generation. prandom_u32() is the replacement used in other file systems. Signed-off-by: Arnd Bergmann --- fs/fat/inode.c | 3 ++- 1 file changed, 2

[Y2038] [PATCH 01/16] staging: exfat: use prandom_u32() for i_generation

2019-11-08 Thread Arnd Bergmann
Similar to commit 46c9a946d766 ("shmem: use monotonic time for i_generation") we should not use the deprecated get_seconds() interface for i_generation. prandom_u32() is the replacement used in other file systems. Signed-off-by: Arnd Bergmann --- drivers/staging/exfat/exfat_super.c | 4 ++-- 1

[Y2038] [PATCH 07/16] acct: stop using get_seconds()

2019-11-08 Thread Arnd Bergmann
In 'struct acct', 'struct acct_v3', and 'struct taskstats' we have a 32-bit 'ac_btime' field containing an absolute time value, which will overflow in year 2106. There are two possible ways to deal with it: a) let it overflow and have user space code deal with reconstructing the data based on

[Y2038] [PATCH 00/16] drivers: y2038 updates

2019-11-08 Thread Arnd Bergmann
These are updates to devidce drivers and file systems that for some reason or another were not included in the kernel in the previous y2038 series. I've gone through all users of time_t again to make sure the kernel is in a long-term maintainable state. Posting these as a series for better

[Y2038] [PATCH 09/16] netfilter: nft_meta: use 64-bit time arithmetic

2019-11-08 Thread Arnd Bergmann
On 32-bit architectures, get_seconds() returns an unsigned 32-bit time value, which also matches the type used in the nft_meta code. This will not overflow in year 2038 as a time_t would, but it still suffers from the overflow problem later on in year 2106. Change this instance to use the

Re: [Y2038] [PATCH 4/8] ipmi: kill off 'timespec' usage again

2019-11-08 Thread Corey Minyard
On Fri, Nov 08, 2019 at 09:34:27PM +0100, Arnd Bergmann wrote: > 'struct timespec' is getting removed from the kernel. The usage in ipmi > was fixed before in commit 48862ea2ce86 ("ipmi: Update timespec usage > to timespec64"), but unfortunately it crept back in. > > The busy looping code can