^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file contains the interface functions for the various time related
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * system calls: time, stime, gettimeofday, settimeofday, adjtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Modification history:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 1993-09-02 Philip Gladstone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Created file with time related functions from sched/core.c and adjtimex()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * 1993-10-08 Torsten Duwe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * adjtime interface update and CMOS clock write code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * 1995-08-13 Torsten Duwe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * kernel PLL updated to 1994-12-13 specs (rfc-1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * 1999-01-16 Ulrich Windl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Introduced error checking for many cases in adjtimex().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Updated NTP code according to technical memorandum Jan '96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * "A Kernel Model for Precision Timekeeping" by Dave Mills
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Allow time_constant larger than MAXTC(6) for NTP v4 (MAXTC == 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * (Even though the technical memorandum forbids it)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * 2004-07-14 Christoph Lameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Added getnstimeofday to allow the posix timer functions to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * with nanosecond accuracy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/timex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/timekeeper_internal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <generated/timeconst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "timekeeping.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * The timezone where the local system is located. Used as a default by some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * programs who obtain this value by using gettimeofday.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct timezone sys_tz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) EXPORT_SYMBOL(sys_tz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #ifdef __ARCH_WANT_SYS_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * sys_time() can be implemented in user-level using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * sys_gettimeofday(). Is this for backwards compatibility? If so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * why not move it into the appropriate arch directory (for those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * architectures that need it).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) SYSCALL_DEFINE1(time, __kernel_old_time_t __user *, tloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) __kernel_old_time_t i = (__kernel_old_time_t)ktime_get_real_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (tloc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (put_user(i,tloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) force_successful_syscall_return();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * sys_stime() can be implemented in user-level using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * sys_settimeofday(). Is this for backwards compatibility? If so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * why not move it into the appropriate arch directory (for those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * architectures that need it).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) SYSCALL_DEFINE1(stime, __kernel_old_time_t __user *, tptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct timespec64 tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (get_user(tv.tv_sec, tptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) tv.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) err = security_settime64(&tv, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) do_settimeofday64(&tv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif /* __ARCH_WANT_SYS_TIME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #ifdef CONFIG_COMPAT_32BIT_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef __ARCH_WANT_SYS_TIME32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* old_time32_t is a 32 bit "long" and needs to get converted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) SYSCALL_DEFINE1(time32, old_time32_t __user *, tloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) old_time32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) i = (old_time32_t)ktime_get_real_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (tloc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (put_user(i,tloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) force_successful_syscall_return();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) SYSCALL_DEFINE1(stime32, old_time32_t __user *, tptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct timespec64 tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (get_user(tv.tv_sec, tptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) tv.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) err = security_settime64(&tv, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) do_settimeofday64(&tv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif /* __ARCH_WANT_SYS_TIME32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) SYSCALL_DEFINE2(gettimeofday, struct __kernel_old_timeval __user *, tv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct timezone __user *, tz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (likely(tv != NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ktime_get_real_ts64(&ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (put_user(ts.tv_sec, &tv->tv_sec) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) put_user(ts.tv_nsec / 1000, &tv->tv_usec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (unlikely(tz != NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * In case for some reason the CMOS clock has not already been running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * in UTC, but in some local time: The first time we set the timezone,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * we will warp the clock so that it is ticking UTC time instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * local time. Presumably, if someone is setting the timezone then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * are running in an environment where the programs understand about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * timezones. This should be done at boot time in the /etc/rc script,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * as soon as possible, so that the clock can be set right. Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * various programs will get confused when the clock gets warped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int firsttime = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (tv && !timespec64_valid_settod(tv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) error = security_settime64(tv, tz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Verify we're within the +-15 hrs range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (tz->tz_minuteswest > 15*60 || tz->tz_minuteswest < -15*60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) sys_tz = *tz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) update_vsyscall_tz();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (firsttime) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) firsttime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!tv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) timekeeping_warp_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (tv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return do_settimeofday64(tv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) SYSCALL_DEFINE2(settimeofday, struct __kernel_old_timeval __user *, tv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct timezone __user *, tz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct timespec64 new_ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct timezone new_tz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (tv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (get_user(new_ts.tv_sec, &tv->tv_sec) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) get_user(new_ts.tv_nsec, &tv->tv_usec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (new_ts.tv_nsec > USEC_PER_SEC || new_ts.tv_nsec < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) new_ts.tv_nsec *= NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (copy_from_user(&new_tz, tz, sizeof(*tz)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) COMPAT_SYSCALL_DEFINE2(gettimeofday, struct old_timeval32 __user *, tv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct timezone __user *, tz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (tv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ktime_get_real_ts64(&ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (put_user(ts.tv_sec, &tv->tv_sec) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) put_user(ts.tv_nsec / 1000, &tv->tv_usec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) COMPAT_SYSCALL_DEFINE2(settimeofday, struct old_timeval32 __user *, tv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct timezone __user *, tz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct timespec64 new_ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct timezone new_tz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (tv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (get_user(new_ts.tv_sec, &tv->tv_sec) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) get_user(new_ts.tv_nsec, &tv->tv_usec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (new_ts.tv_nsec > USEC_PER_SEC || new_ts.tv_nsec < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) new_ts.tv_nsec *= NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (copy_from_user(&new_tz, tz, sizeof(*tz)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) SYSCALL_DEFINE1(adjtimex, struct __kernel_timex __user *, txc_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct __kernel_timex txc; /* Local copy of parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* Copy the user data space into the kernel copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * structure. But bear in mind that the structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * may change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (copy_from_user(&txc, txc_p, sizeof(struct __kernel_timex)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ret = do_adjtimex(&txc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return copy_to_user(txc_p, &txc, sizeof(struct __kernel_timex)) ? -EFAULT : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #ifdef CONFIG_COMPAT_32BIT_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int get_old_timex32(struct __kernel_timex *txc, const struct old_timex32 __user *utp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct old_timex32 tx32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) memset(txc, 0, sizeof(struct __kernel_timex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (copy_from_user(&tx32, utp, sizeof(struct old_timex32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) txc->modes = tx32.modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) txc->offset = tx32.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) txc->freq = tx32.freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) txc->maxerror = tx32.maxerror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) txc->esterror = tx32.esterror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) txc->status = tx32.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) txc->constant = tx32.constant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) txc->precision = tx32.precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) txc->tolerance = tx32.tolerance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) txc->time.tv_sec = tx32.time.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) txc->time.tv_usec = tx32.time.tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) txc->tick = tx32.tick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) txc->ppsfreq = tx32.ppsfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) txc->jitter = tx32.jitter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) txc->shift = tx32.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) txc->stabil = tx32.stabil;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) txc->jitcnt = tx32.jitcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) txc->calcnt = tx32.calcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) txc->errcnt = tx32.errcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) txc->stbcnt = tx32.stbcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int put_old_timex32(struct old_timex32 __user *utp, const struct __kernel_timex *txc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct old_timex32 tx32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) memset(&tx32, 0, sizeof(struct old_timex32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) tx32.modes = txc->modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) tx32.offset = txc->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) tx32.freq = txc->freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) tx32.maxerror = txc->maxerror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) tx32.esterror = txc->esterror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) tx32.status = txc->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) tx32.constant = txc->constant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) tx32.precision = txc->precision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) tx32.tolerance = txc->tolerance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) tx32.time.tv_sec = txc->time.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) tx32.time.tv_usec = txc->time.tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) tx32.tick = txc->tick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) tx32.ppsfreq = txc->ppsfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) tx32.jitter = txc->jitter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) tx32.shift = txc->shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) tx32.stabil = txc->stabil;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) tx32.jitcnt = txc->jitcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) tx32.calcnt = txc->calcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) tx32.errcnt = txc->errcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) tx32.stbcnt = txc->stbcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) tx32.tai = txc->tai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (copy_to_user(utp, &tx32, sizeof(struct old_timex32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) SYSCALL_DEFINE1(adjtimex_time32, struct old_timex32 __user *, utp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct __kernel_timex txc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int err, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) err = get_old_timex32(&txc, utp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ret = do_adjtimex(&txc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) err = put_old_timex32(utp, &txc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * Convert jiffies to milliseconds and back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * Avoid unnecessary multiplications/divisions in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * two most common HZ cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) unsigned int jiffies_to_msecs(const unsigned long j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return (MSEC_PER_SEC / HZ) * j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) # if BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return (HZ_TO_MSEC_MUL32 * j + (1ULL << HZ_TO_MSEC_SHR32) - 1) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) HZ_TO_MSEC_SHR32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return DIV_ROUND_UP(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) EXPORT_SYMBOL(jiffies_to_msecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) unsigned int jiffies_to_usecs(const unsigned long j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * Hz usually doesn't go much further MSEC_PER_SEC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * jiffies_to_usecs() and usecs_to_jiffies() depend on that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) BUILD_BUG_ON(HZ > USEC_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #if !(USEC_PER_SEC % HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return (USEC_PER_SEC / HZ) * j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) # if BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) EXPORT_SYMBOL(jiffies_to_usecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * mktime64 - Converts date to seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * Converts Gregorian date to seconds since 1970-01-01 00:00:00.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * [For the Julian calendar (which was used in Russia before 1917,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * Britain & colonies before 1752, anywhere else before 1582,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * and is still in use by some communities) leave out the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * -year/100+year/400 terms, and add 10.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * This algorithm was first published by Gauss (I think).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * A leap second can be indicated by calling this function with sec as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * 60 (allowable under ISO 8601). The leap second is treated the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * as the following second since they don't exist in UNIX time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * An encoding of midnight at the end of the day as 24:00:00 - ie. midnight
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * tomorrow - (allowable under ISO 8601) is supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) time64_t mktime64(const unsigned int year0, const unsigned int mon0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) const unsigned int day, const unsigned int hour,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) const unsigned int min, const unsigned int sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) unsigned int mon = mon0, year = year0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /* 1..12 -> 11,12,1..10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (0 >= (int) (mon -= 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) mon += 12; /* Puts Feb last since it has leap day */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) year -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return ((((time64_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) year*365 - 719499
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) )*24 + hour /* now have hours - midnight tomorrow handled here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) )*60 + min /* now have minutes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) )*60 + sec; /* finally seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) EXPORT_SYMBOL(mktime64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct timespec64 ts = ns_to_timespec64(nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct __kernel_old_timeval tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) tv.tv_sec = ts.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) tv.tv_usec = (suseconds_t)ts.tv_nsec / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) EXPORT_SYMBOL(ns_to_kernel_old_timeval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * set_normalized_timespec - set timespec sec and nsec parts and normalize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * @ts: pointer to timespec variable to be set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * @sec: seconds to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * @nsec: nanoseconds to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Set seconds and nanoseconds field of a timespec variable and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * normalize to the timespec storage format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * Note: The tv_nsec part is always in the range of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * 0 <= tv_nsec < NSEC_PER_SEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * For negative values only the tv_sec field is negative !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) while (nsec >= NSEC_PER_SEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * The following asm() prevents the compiler from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * optimising this loop into a modulo operation. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * also __iter_div_u64_rem() in include/linux/time.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) asm("" : "+rm"(nsec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) nsec -= NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ++sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) while (nsec < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) asm("" : "+rm"(nsec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) nsec += NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) --sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ts->tv_sec = sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ts->tv_nsec = nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) EXPORT_SYMBOL(set_normalized_timespec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * ns_to_timespec64 - Convert nanoseconds to timespec64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * @nsec: the nanoseconds value to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * Returns the timespec64 representation of the nsec parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct timespec64 ns_to_timespec64(const s64 nsec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct timespec64 ts = { 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) s32 rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (likely(nsec > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ts.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ts.tv_nsec = rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) } else if (nsec < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * With negative times, tv_sec points to the earlier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * second, and tv_nsec counts the nanoseconds since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * then, so tv_nsec is always a positive number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ts.tv_sec = -div_u64_rem(-nsec - 1, NSEC_PER_SEC, &rem) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ts.tv_nsec = NSEC_PER_SEC - rem - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) EXPORT_SYMBOL(ns_to_timespec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * msecs_to_jiffies: - convert milliseconds to jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * @m: time in milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * conversion is done as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * - negative values mean 'infinite timeout' (MAX_JIFFY_OFFSET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * - 'too large' values [that would result in larger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * MAX_JIFFY_OFFSET values] mean 'infinite timeout' too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * - all other values are converted to jiffies by either multiplying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * the input value by a factor or dividing it with a factor and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * handling any 32-bit overflows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * for the details see __msecs_to_jiffies()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * msecs_to_jiffies() checks for the passed in value being a constant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * via __builtin_constant_p() allowing gcc to eliminate most of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * code, __msecs_to_jiffies() is called if the value passed does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * allow constant folding and the actual conversion must be done at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * the _msecs_to_jiffies helpers are the HZ dependent conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * routines found in include/linux/jiffies.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) unsigned long __msecs_to_jiffies(const unsigned int m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Negative value, means infinite timeout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if ((int)m < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return MAX_JIFFY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return _msecs_to_jiffies(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) EXPORT_SYMBOL(__msecs_to_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned long __usecs_to_jiffies(const unsigned int u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return MAX_JIFFY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return _usecs_to_jiffies(u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) EXPORT_SYMBOL(__usecs_to_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * The TICK_NSEC - 1 rounds up the value to the next resolution. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * that a remainder subtract here would not do the right thing as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * resolution values don't fall on second boundries. I.e. the line:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * nsec -= nsec % TICK_NSEC; is NOT a correct resolution rounding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * Note that due to the small error in the multiplier here, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * rounding is incorrect for sufficiently large values of tv_nsec, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * well formed timespecs should have tv_nsec < NSEC_PER_SEC, so we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * Rather, we just shift the bits off the right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * value to a scaled second value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) timespec64_to_jiffies(const struct timespec64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) u64 sec = value->tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) long nsec = value->tv_nsec + TICK_NSEC - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (sec >= MAX_SEC_IN_JIFFIES){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) sec = MAX_SEC_IN_JIFFIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return ((sec * SEC_CONVERSION) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) (((u64)nsec * NSEC_CONVERSION) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) EXPORT_SYMBOL(timespec64_to_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * Convert jiffies to nanoseconds and separate with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * one divide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) u32 rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) NSEC_PER_SEC, &rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) value->tv_nsec = rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) EXPORT_SYMBOL(jiffies_to_timespec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * Convert jiffies/jiffies_64 to clock_t and back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) clock_t jiffies_to_clock_t(unsigned long x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) # if HZ < USER_HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return x * (USER_HZ / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return x / (HZ / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return div_u64((u64)x * TICK_NSEC, NSEC_PER_SEC / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) EXPORT_SYMBOL(jiffies_to_clock_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) unsigned long clock_t_to_jiffies(unsigned long x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) #if (HZ % USER_HZ)==0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (x >= ~0UL / (HZ / USER_HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return ~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) return x * (HZ / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /* Don't worry about loss of precision here .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (x >= ~0UL / HZ * USER_HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) return ~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* .. but do try to contain it here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) return div_u64((u64)x * HZ, USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) EXPORT_SYMBOL(clock_t_to_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) u64 jiffies_64_to_clock_t(u64 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) # if HZ < USER_HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) x = div_u64(x * USER_HZ, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) # elif HZ > USER_HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) x = div_u64(x, HZ / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * There are better ways that don't overflow early,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * but even this doesn't overflow in hundreds of years
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * in 64 bits, so..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) x = div_u64(x * TICK_NSEC, (NSEC_PER_SEC / USER_HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) return x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) EXPORT_SYMBOL(jiffies_64_to_clock_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) u64 nsec_to_clock_t(u64 x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #if (NSEC_PER_SEC % USER_HZ) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return div_u64(x, NSEC_PER_SEC / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) #elif (USER_HZ % 512) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) return div_u64(x * USER_HZ / 512, NSEC_PER_SEC / 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * overflow after 64.99 years.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return div_u64(x * 9, (9ull * NSEC_PER_SEC + (USER_HZ / 2)) / USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) EXPORT_SYMBOL_GPL(nsec_to_clock_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) u64 jiffies64_to_nsecs(u64 j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) #if !(NSEC_PER_SEC % HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return (NSEC_PER_SEC / HZ) * j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) # else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return div_u64(j * HZ_TO_NSEC_NUM, HZ_TO_NSEC_DEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) EXPORT_SYMBOL(jiffies64_to_nsecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) u64 jiffies64_to_msecs(const u64 j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return (MSEC_PER_SEC / HZ) * j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return div_u64(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) EXPORT_SYMBOL(jiffies64_to_msecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * @n: nsecs in u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * Unlike {m,u}secs_to_jiffies, type of input is not unsigned int but u64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * And this doesn't return MAX_JIFFY_OFFSET since this function is designed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * for scheduler, not for use in device drivers to calculate timeout value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) * NSEC_PER_SEC = 10^9 = (5^9 * 2^9) = (1953125 * 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * ULLONG_MAX ns = 18446744073.709551615 secs = about 584 years
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) u64 nsecs_to_jiffies64(u64 n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) #if (NSEC_PER_SEC % HZ) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /* Common case, HZ = 100, 128, 200, 250, 256, 500, 512, 1000 etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return div_u64(n, NSEC_PER_SEC / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) #elif (HZ % 512) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* overflow after 292 years if HZ = 1024 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return div_u64(n * HZ / 512, NSEC_PER_SEC / 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * Generic case - optimized for cases where HZ is a multiple of 3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * overflow after 64.99 years, exact for HZ = 60, 72, 90, 120 etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return div_u64(n * 9, (9ull * NSEC_PER_SEC + HZ / 2) / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) EXPORT_SYMBOL(nsecs_to_jiffies64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * nsecs_to_jiffies - Convert nsecs in u64 to jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * @n: nsecs in u64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * Unlike {m,u}secs_to_jiffies, type of input is not unsigned int but u64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * And this doesn't return MAX_JIFFY_OFFSET since this function is designed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * for scheduler, not for use in device drivers to calculate timeout value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * note:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * NSEC_PER_SEC = 10^9 = (5^9 * 2^9) = (1953125 * 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * ULLONG_MAX ns = 18446744073.709551615 secs = about 584 years
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) unsigned long nsecs_to_jiffies(u64 n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return (unsigned long)nsecs_to_jiffies64(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) EXPORT_SYMBOL_GPL(nsecs_to_jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) * Add two timespec64 values and do a safety check for overflow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * It's assumed that both values are valid (>= 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * And, each timespec64 is in normalized form.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct timespec64 timespec64_add_safe(const struct timespec64 lhs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) const struct timespec64 rhs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct timespec64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) set_normalized_timespec64(&res, (timeu64_t) lhs.tv_sec + rhs.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) lhs.tv_nsec + rhs.tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (unlikely(res.tv_sec < lhs.tv_sec || res.tv_sec < rhs.tv_sec)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) res.tv_sec = TIME64_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) res.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) int get_timespec64(struct timespec64 *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) const struct __kernel_timespec __user *uts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct __kernel_timespec kts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) ret = copy_from_user(&kts, uts, sizeof(kts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ts->tv_sec = kts.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) /* Zero out the padding in compat mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (in_compat_syscall())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) kts.tv_nsec &= 0xFFFFFFFFUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /* In 32-bit mode, this drops the padding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) ts->tv_nsec = kts.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) EXPORT_SYMBOL_GPL(get_timespec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) int put_timespec64(const struct timespec64 *ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct __kernel_timespec __user *uts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct __kernel_timespec kts = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) .tv_sec = ts->tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) .tv_nsec = ts->tv_nsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) EXPORT_SYMBOL_GPL(put_timespec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static int __get_old_timespec32(struct timespec64 *ts64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) const struct old_timespec32 __user *cts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct old_timespec32 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) ret = copy_from_user(&ts, cts, sizeof(ts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ts64->tv_sec = ts.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) ts64->tv_nsec = ts.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) static int __put_old_timespec32(const struct timespec64 *ts64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct old_timespec32 __user *cts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct old_timespec32 ts = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) .tv_sec = ts64->tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) .tv_nsec = ts64->tv_nsec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) int get_old_timespec32(struct timespec64 *ts, const void __user *uts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (COMPAT_USE_64BIT_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) return __get_old_timespec32(ts, uts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) EXPORT_SYMBOL_GPL(get_old_timespec32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) int put_old_timespec32(const struct timespec64 *ts, void __user *uts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (COMPAT_USE_64BIT_TIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return __put_old_timespec32(ts, uts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) EXPORT_SYMBOL_GPL(put_old_timespec32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) int get_itimerspec64(struct itimerspec64 *it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) const struct __kernel_itimerspec __user *uit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) ret = get_timespec64(&it->it_interval, &uit->it_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ret = get_timespec64(&it->it_value, &uit->it_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) EXPORT_SYMBOL_GPL(get_itimerspec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) int put_itimerspec64(const struct itimerspec64 *it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) struct __kernel_itimerspec __user *uit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) ret = put_timespec64(&it->it_interval, &uit->it_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ret = put_timespec64(&it->it_value, &uit->it_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) EXPORT_SYMBOL_GPL(put_itimerspec64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) int get_old_itimerspec32(struct itimerspec64 *its,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) const struct old_itimerspec32 __user *uits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (__get_old_timespec32(&its->it_interval, &uits->it_interval) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) __get_old_timespec32(&its->it_value, &uits->it_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) EXPORT_SYMBOL_GPL(get_old_itimerspec32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) int put_old_itimerspec32(const struct itimerspec64 *its,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct old_itimerspec32 __user *uits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (__put_old_timespec32(&its->it_interval, &uits->it_interval) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) __put_old_timespec32(&its->it_value, &uits->it_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) EXPORT_SYMBOL_GPL(put_old_itimerspec32);