Commit b12a9124 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'y2038-for-4.21' of ssh://gitolite.kernel.org:/pub/scm/linux/kernel/git/arnd/playground

Pull y2038 updates from Arnd Bergmann:
 "More syscalls and cleanups

  This concludes the main part of the system call rework for 64-bit
  time_t, which has spread over most of year 2018, the last six system
  calls being

    - ppoll
    - pselect6
    - io_pgetevents
    - recvmmsg
    - futex
    - rt_sigtimedwait

  As before, nothing changes for 64-bit architectures, while 32-bit
  architectures gain another entry point that differs only in the layout
  of the timespec structure. Hopefully in the next release we can wire
  up all 22 of those system calls on all 32-bit architectures, which
  gives us a baseline version for glibc to start using them.

  This does not include the clock_adjtime, getrusage/waitid, and
  getitimer/setitimer system calls. I still plan to have new versions of
  those as well, but they are not required for correct operation of the
  C library since they can be emulated using the old 32-bit time_t based
  system calls.

  Aside from the system calls, there are also a few cleanups here,
  removing old kernel internal interfaces that have become unused after
  all references got removed. The arch/sh cleanups are part of this,
  there were posted several times over the past year without a reaction
  from the maintainers, while the corresponding changes made it into all
  other architectures"

* tag 'y2038-for-4.21' of ssh://gitolite.kernel.org:/pub/scm/linux/kernel/git/arnd/playground:
  timekeeping: remove obsolete time accessors
  vfs: replace current_kernel_time64 with ktime equivalent
  timekeeping: remove timespec_add/timespec_del
  timekeeping: remove unused {read,update}_persistent_clock
  sh: remove board_time_init() callback
  sh: remove unused rtc_sh_get/set_time infrastructure
  sh: sh03: rtc: push down rtc class ops into driver
  sh: dreamcast: rtc: push down rtc class ops into driver
  y2038: signal: Add compat_sys_rt_sigtimedwait_time64
  y2038: signal: Add sys_rt_sigtimedwait_time32
  y2038: socket: Add compat_sys_recvmmsg_time64
  y2038: futex: Add support for __kernel_timespec
  y2038: futex: Move compat implementation into futex.c
  io_pgetevents: use __kernel_timespec
  pselect6: use __kernel_timespec
  ppoll: use __kernel_timespec
  signal: Add restore_user_sigmask()
  signal: Add set_user_sigmask()
parents 1a80dade e4b92b10
...@@ -116,7 +116,6 @@ might look something like: ...@@ -116,7 +116,6 @@ might look something like:
* arch/sh/boards/vapor/setup.c - Setup code for imaginary board * arch/sh/boards/vapor/setup.c - Setup code for imaginary board
*/ */
#include <linux/init.h> #include <linux/init.h>
#include <asm/rtc.h> /* for board_time_init() */
const char *get_system_type(void) const char *get_system_type(void)
{ {
...@@ -132,13 +131,6 @@ int __init platform_setup(void) ...@@ -132,13 +131,6 @@ int __init platform_setup(void)
* this board. * this board.
*/ */
/*
* Presume all FooTech boards have the same broken timer,
* and also presume that we've defined foo_timer_init to
* do something useful.
*/
board_time_init = foo_timer_init;
/* Start-up imaginary PCI ... */ /* Start-up imaginary PCI ... */
/* And whatever else ... */ /* And whatever else ... */
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
# Makefile for the Sega Dreamcast specific parts of the kernel # Makefile for the Sega Dreamcast specific parts of the kernel
# #
obj-y := setup.o irq.o rtc.o obj-y := setup.o irq.o
obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
*/ */
#include <linux/time.h> #include <linux/time.h>
#include <asm/rtc.h> #include <linux/rtc.h>
#include <asm/io.h> #include <linux/io.h>
#include <linux/platform_device.h>
/* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in /* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in
seconds) to get the standard Unix Epoch when getting the time, and add seconds) to get the standard Unix Epoch when getting the time, and add
...@@ -26,13 +27,15 @@ ...@@ -26,13 +27,15 @@
/** /**
* aica_rtc_gettimeofday - Get the time from the AICA RTC * aica_rtc_gettimeofday - Get the time from the AICA RTC
* @ts: pointer to resulting timespec * @dev: the RTC device (ignored)
* @tm: pointer to resulting RTC time structure
* *
* Grabs the current RTC seconds counter and adjusts it to the Unix Epoch. * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch.
*/ */
static void aica_rtc_gettimeofday(struct timespec *ts) static int aica_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned long val1, val2; unsigned long val1, val2;
time64_t t;
do { do {
val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) | val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) |
...@@ -42,22 +45,26 @@ static void aica_rtc_gettimeofday(struct timespec *ts) ...@@ -42,22 +45,26 @@ static void aica_rtc_gettimeofday(struct timespec *ts)
(__raw_readl(AICA_RTC_SECS_L) & 0xffff); (__raw_readl(AICA_RTC_SECS_L) & 0xffff);
} while (val1 != val2); } while (val1 != val2);
ts->tv_sec = val1 - TWENTY_YEARS; /* normalize to 1970..2106 time range */
t = (u32)(val1 - TWENTY_YEARS);
/* Can't get nanoseconds with just a seconds counter. */ rtc_time64_to_tm(t, tm);
ts->tv_nsec = 0;
return 0;
} }
/** /**
* aica_rtc_settimeofday - Set the AICA RTC to the current time * aica_rtc_settimeofday - Set the AICA RTC to the current time
* @secs: contains the time_t to set * @dev: the RTC device (ignored)
* @tm: pointer to new RTC time structure
* *
* Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter. * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter.
*/ */
static int aica_rtc_settimeofday(const time_t secs) static int aica_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned long val1, val2; unsigned long val1, val2;
unsigned long adj = secs + TWENTY_YEARS; time64_t secs = rtc_tm_to_time64(tm);
u32 adj = secs + TWENTY_YEARS;
do { do {
__raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H); __raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H);
...@@ -73,9 +80,19 @@ static int aica_rtc_settimeofday(const time_t secs) ...@@ -73,9 +80,19 @@ static int aica_rtc_settimeofday(const time_t secs)
return 0; return 0;
} }
void aica_time_init(void) static const struct rtc_class_ops rtc_generic_ops = {
.read_time = aica_rtc_gettimeofday,
.set_time = aica_rtc_settimeofday,
};
static int __init aica_time_init(void)
{ {
rtc_sh_get_time = aica_rtc_gettimeofday; struct platform_device *pdev;
rtc_sh_set_time = aica_rtc_settimeofday;
} pdev = platform_device_register_data(NULL, "rtc-generic", -1,
&rtc_generic_ops,
sizeof(rtc_generic_ops));
return PTR_ERR_OR_ZERO(pdev);
}
arch_initcall(aica_time_init);
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
static void __init dreamcast_setup(char **cmdline_p) static void __init dreamcast_setup(char **cmdline_p)
{ {
board_time_init = aica_time_init;
} }
static struct sh_machine_vector mv_dreamcast __initmv = { static struct sh_machine_vector mv_dreamcast __initmv = {
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel # Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel
# #
obj-y := setup.o rtc.o obj-y := setup.o
obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/rtc.h> #include <linux/rtc.h>
#include <linux/platform_device.h>
#define RTC_BASE 0xb0000000 #define RTC_BASE 0xb0000000
#define RTC_SEC1 (RTC_BASE + 0) #define RTC_SEC1 (RTC_BASE + 0)
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
static DEFINE_SPINLOCK(sh03_rtc_lock); static DEFINE_SPINLOCK(sh03_rtc_lock);
unsigned long get_cmos_time(void) static int sh03_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned int year, mon, day, hour, min, sec; unsigned int year, mon, day, hour, min, sec;
...@@ -75,17 +76,18 @@ unsigned long get_cmos_time(void) ...@@ -75,17 +76,18 @@ unsigned long get_cmos_time(void)
} }
spin_unlock(&sh03_rtc_lock); spin_unlock(&sh03_rtc_lock);
return mktime(year, mon, day, hour, min, sec);
}
void sh03_rtc_gettimeofday(struct timespec *tv) tm->tm_sec = sec;
{ tm->tm_min = min;
tm->tm_hour = hour;
tm->tm_mday = day;
tm->tm_mon = mon;
tm->tm_year = year - 1900;
tv->tv_sec = get_cmos_time(); return 0;
tv->tv_nsec = 0;
} }
static int set_rtc_mmss(unsigned long nowtime) static int set_rtc_mmss(struct rtc_time *tm)
{ {
int retval = 0; int retval = 0;
int real_seconds, real_minutes, cmos_minutes; int real_seconds, real_minutes, cmos_minutes;
...@@ -97,8 +99,8 @@ static int set_rtc_mmss(unsigned long nowtime) ...@@ -97,8 +99,8 @@ static int set_rtc_mmss(unsigned long nowtime)
if (!(__raw_readb(RTC_CTL) & RTC_BUSY)) if (!(__raw_readb(RTC_CTL) & RTC_BUSY))
break; break;
cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10; cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10;
real_seconds = nowtime % 60; real_seconds = tm->tm_sec;
real_minutes = nowtime / 60; real_minutes = tm->tm_min;
if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
real_minutes += 30; /* correct for half hour time zone */ real_minutes += 30; /* correct for half hour time zone */
real_minutes %= 60; real_minutes %= 60;
...@@ -112,22 +114,31 @@ static int set_rtc_mmss(unsigned long nowtime) ...@@ -112,22 +114,31 @@ static int set_rtc_mmss(unsigned long nowtime)
printk_once(KERN_NOTICE printk_once(KERN_NOTICE
"set_rtc_mmss: can't update from %d to %d\n", "set_rtc_mmss: can't update from %d to %d\n",
cmos_minutes, real_minutes); cmos_minutes, real_minutes);
retval = -1; retval = -EINVAL;
} }
spin_unlock(&sh03_rtc_lock); spin_unlock(&sh03_rtc_lock);
return retval; return retval;
} }
int sh03_rtc_settimeofday(const time_t secs) int sh03_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned long nowtime = secs; return set_rtc_mmss(tm);
return set_rtc_mmss(nowtime);
} }
void sh03_time_init(void) static const struct rtc_class_ops rtc_generic_ops = {
.read_time = sh03_rtc_gettimeofday,
.set_time = sh03_rtc_settimeofday,
};
static int __init sh03_time_init(void)
{ {
rtc_sh_get_time = sh03_rtc_gettimeofday; struct platform_device *pdev;
rtc_sh_set_time = sh03_rtc_settimeofday;
pdev = platform_device_register_data(NULL, "rtc-generic", -1,
&rtc_generic_ops,
sizeof(rtc_generic_ops));
return PTR_ERR_OR_ZERO(pdev);
} }
arch_initcall(sh03_time_init);
...@@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void) ...@@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void)
plat_irq_setup_pins(IRQ_MODE_IRQ); plat_irq_setup_pins(IRQ_MODE_IRQ);
} }
/* arch/sh/boards/sh03/rtc.c */
void sh03_time_init(void);
static void __init sh03_setup(char **cmdline_p)
{
board_time_init = sh03_time_init;
}
static struct resource cf_ide_resources[] = { static struct resource cf_ide_resources[] = {
[0] = { [0] = {
.start = 0x1f0, .start = 0x1f0,
...@@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup); ...@@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup);
static struct sh_machine_vector mv_sh03 __initmv = { static struct sh_machine_vector mv_sh03 __initmv = {
.mv_name = "Interface (CTP/PCI-SH03)", .mv_name = "Interface (CTP/PCI-SH03)",
.mv_setup = sh03_setup,
.mv_init_irq = init_sh03_IRQ, .mv_init_irq = init_sh03_IRQ,
}; };
...@@ -117,18 +117,10 @@ static void __init sh_of_mem_reserve(void) ...@@ -117,18 +117,10 @@ static void __init sh_of_mem_reserve(void)
early_init_fdt_scan_reserved_mem(); early_init_fdt_scan_reserved_mem();
} }
static void __init sh_of_time_init(void)
{
pr_info("SH generic board support: scanning for clocksource devices\n");
timer_probe();
}
static void __init sh_of_setup(char **cmdline_p) static void __init sh_of_setup(char **cmdline_p)
{ {
struct device_node *root; struct device_node *root;
board_time_init = sh_of_time_init;
sh_mv.mv_name = "Unknown SH model"; sh_mv.mv_name = "Unknown SH model";
root = of_find_node_by_path("/"); root = of_find_node_by_path("/");
if (root) { if (root) {
......
...@@ -70,3 +70,5 @@ CONFIG_PROC_KCORE=y ...@@ -70,3 +70,5 @@ CONFIG_PROC_KCORE=y
CONFIG_TMPFS=y CONFIG_TMPFS=y
CONFIG_HUGETLBFS=y CONFIG_HUGETLBFS=y
# CONFIG_CRYPTO_ANSI_CPRNG is not set # CONFIG_CRYPTO_ANSI_CPRNG is not set
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_GENERIC=y
...@@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y ...@@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y
CONFIG_CRYPTO_DEFLATE=y CONFIG_CRYPTO_DEFLATE=y
# CONFIG_CRYPTO_ANSI_CPRNG is not set # CONFIG_CRYPTO_ANSI_CPRNG is not set
CONFIG_CRC_CCITT=y CONFIG_CRC_CCITT=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_GENERIC=y
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
#define _ASM_RTC_H #define _ASM_RTC_H
void time_init(void); void time_init(void);
extern void (*board_time_init)(void);
extern void (*rtc_sh_get_time)(struct timespec *);
extern int (*rtc_sh_set_time)(const time_t);
#define RTC_CAP_4_DIGIT_YEAR (1 << 0) #define RTC_CAP_4_DIGIT_YEAR (1 << 0)
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
/* arch/sh/boards/mach-dreamcast/irq.c */ /* arch/sh/boards/mach-dreamcast/irq.c */
extern int systemasic_irq_demux(int); extern int systemasic_irq_demux(int);
extern void systemasic_irq_init(void); extern void systemasic_irq_init(void);
extern void aica_time_init(void);
#endif /* __ASM_SH_DREAMCAST_SYSASIC_H */ #endif /* __ASM_SH_DREAMCAST_SYSASIC_H */
...@@ -22,77 +22,6 @@ ...@@ -22,77 +22,6 @@
#include <asm/clock.h> #include <asm/clock.h>
#include <asm/rtc.h> #include <asm/rtc.h>
/* Dummy RTC ops */
static void null_rtc_get_time(struct timespec *tv)
{
tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
tv->tv_nsec = 0;
}
static int null_rtc_set_time(const time_t secs)
{
return 0;
}
void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
void read_persistent_clock(struct timespec *ts)
{
rtc_sh_get_time(ts);
}
#ifdef CONFIG_GENERIC_CMOS_UPDATE
int update_persistent_clock(struct timespec now)
{
return rtc_sh_set_time(now.tv_sec);
}
#endif
static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm)
{
struct timespec tv;
rtc_sh_get_time(&tv);
rtc_time_to_tm(tv.tv_sec, tm);
return 0;
}
static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm)
{
unsigned long secs;
rtc_tm_to_time(tm, &secs);
if ((rtc_sh_set_time == null_rtc_set_time) ||
(rtc_sh_set_time(secs) < 0))
return -EOPNOTSUPP;
return 0;
}
static const struct rtc_class_ops rtc_generic_ops = {
.read_time = rtc_generic_get_time,
.set_time = rtc_generic_set_time,
};
static int __init rtc_generic_init(void)
{
struct platform_device *pdev;
if (rtc_sh_get_time == null_rtc_get_time)
return -ENODEV;
pdev = platform_device_register_data(NULL, "rtc-generic", -1,
&rtc_generic_ops,
sizeof(rtc_generic_ops));
return PTR_ERR_OR_ZERO(pdev);
}
device_initcall(rtc_generic_init);
void (*board_time_init)(void);
static void __init sh_late_time_init(void) static void __init sh_late_time_init(void)
{ {
/* /*
...@@ -110,8 +39,7 @@ static void __init sh_late_time_init(void) ...@@ -110,8 +39,7 @@ static void __init sh_late_time_init(void)
void __init time_init(void) void __init time_init(void)
{ {
if (board_time_init) timer_probe();
board_time_init();
clk_init(); clk_init();
......
...@@ -2065,11 +2065,13 @@ static long do_io_getevents(aio_context_t ctx_id, ...@@ -2065,11 +2065,13 @@ static long do_io_getevents(aio_context_t ctx_id,
* specifies an infinite timeout. Note that the timeout pointed to by * specifies an infinite timeout. Note that the timeout pointed to by
* timeout is relative. Will fail with -ENOSYS if not implemented. * timeout is relative. Will fail with -ENOSYS if not implemented.
*/ */
#if !defined(CONFIG_64BIT_TIME) || defined(CONFIG_64BIT)
SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id, SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
long, min_nr, long, min_nr,
long, nr, long, nr,
struct io_event __user *, events, struct io_event __user *, events,
struct timespec __user *, timeout) struct __kernel_timespec __user *, timeout)
{ {
struct timespec64 ts; struct timespec64 ts;
int ret; int ret;
...@@ -2083,6 +2085,8 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id, ...@@ -2083,6 +2085,8 @@ SYSCALL_DEFINE5(io_getevents, aio_context_t, ctx_id,
return ret; return ret;
} }
#endif
struct __aio_sigset { struct __aio_sigset {
const sigset_t __user *sigmask; const sigset_t __user *sigmask;
size_t sigsetsize; size_t sigsetsize;
...@@ -2093,7 +2097,7 @@ SYSCALL_DEFINE6(io_pgetevents, ...@@ -2093,7 +2097,7 @@ SYSCALL_DEFINE6(io_pgetevents,
long, min_nr, long, min_nr,
long, nr, long, nr,
struct io_event __user *, events, struct io_event __user *, events,
struct timespec __user *, timeout, struct __kernel_timespec __user *, timeout,
const struct __aio_sigset __user *, usig) const struct __aio_sigset __user *, usig)
{ {
struct __aio_sigset ksig = { NULL, }; struct __aio_sigset ksig = { NULL, };
...@@ -2107,33 +2111,56 @@ SYSCALL_DEFINE6(io_pgetevents, ...@@ -2107,33 +2111,56 @@ SYSCALL_DEFINE6(io_pgetevents,
if (usig && copy_from_user(&ksig, usig, sizeof(ksig))) if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
return -EFAULT; return -EFAULT;
if (ksig.sigmask) { ret = set_user_sigmask(ksig.sigmask, &ksigmask, &sigsaved, ksig.sigsetsize);
if (ksig.sigsetsize != sizeof(sigset_t)) if (ret)
return -EINVAL; return ret;
if (copy_from_user(&ksigmask, ksig.sigmask, sizeof(ksigmask)))
return -EFAULT;
sigdelsetmask(&ksigmask, sigmask(SIGKILL) | sigmask(SIGSTOP));
sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved);
}
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL); ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
if (signal_pending(current)) { restore_user_sigmask(ksig.sigmask, &sigsaved);
if (ksig.sigmask) { if (signal_pending(current) && !ret)
current->saved_sigmask = sigsaved; ret = -ERESTARTNOHAND;
set_restore_sigmask();
}
if (!ret) return ret;
}
#if defined(CONFIG_COMPAT_32BIT_TIME) && !defined(CONFIG_64BIT)
SYSCALL_DEFINE6(io_pgetevents_time32,
aio_context_t, ctx_id,
long, min_nr,
long, nr,
struct io_event __user *, events,
struct old_timespec32 __user *, timeout,
const struct __aio_sigset __user *, usig)
{
struct __aio_sigset ksig = { NULL, };
sigset_t ksigmask, sigsaved;
struct timespec64 ts;
int ret;
if (timeout && unlikely(get_old_timespec32(&ts, timeout)))
return -EFAULT;
if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
return -EFAULT;
ret = set_user_sigmask(ksig.sigmask, &ksigmask, &sigsaved, ksig.sigsetsize);
if (ret)
return ret;
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &ts : NULL);
restore_user_sigmask(ksig.sigmask, &sigsaved);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND; ret = -ERESTARTNOHAND;
} else {
if (ksig.sigmask)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
}
return ret; return ret;
} }
#ifdef CONFIG_COMPAT #endif
#if defined(CONFIG_COMPAT_32BIT_TIME)
COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id, COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
compat_long_t, min_nr, compat_long_t, min_nr,
compat_long_t, nr, compat_long_t, nr,
...@@ -2152,12 +2179,17 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id, ...@@ -2152,12 +2179,17 @@ COMPAT_SYSCALL_DEFINE5(io_getevents, compat_aio_context_t, ctx_id,
return ret; return ret;
} }
#endif
#ifdef CONFIG_COMPAT
struct __compat_aio_sigset { struct __compat_aio_sigset {
compat_sigset_t __user *sigmask; compat_sigset_t __user *sigmask;
compat_size_t sigsetsize; compat_size_t sigsetsize;
}; };
#if defined(CONFIG_COMPAT_32BIT_TIME)
COMPAT_SYSCALL_DEFINE6(io_pgetevents, COMPAT_SYSCALL_DEFINE6(io_pgetevents,
compat_aio_context_t, ctx_id, compat_aio_context_t, ctx_id,
compat_long_t, min_nr, compat_long_t, min_nr,
...@@ -2177,27 +2209,47 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents, ...@@ -2177,27 +2209,47 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,
if (usig && copy_from_user(&ksig, usig, sizeof(ksig))) if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
return -EFAULT; return -EFAULT;
if (ksig.sigmask) { ret = set_compat_user_sigmask(ksig.sigmask, &ksigmask, &sigsaved, ksig.sigsetsize);
if (ksig.sigsetsize != sizeof(compat_sigset_t)) if (ret)
return -EINVAL; return ret;
if (get_compat_sigset(&ksigmask, ksig.sigmask))
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
restore_user_sigmask(ksig.sigmask, &sigsaved);
if (signal_pending(current) && !ret)
ret = -ERESTARTNOHAND;
return ret;
}
#endif
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; return -EFAULT;
sigdelsetmask(&ksigmask, sigmask(SIGKILL) | sigmask(SIGSTOP));
sigprocmask(SIG_SETMASK, &ksigmask, &sigsaved); if (usig && copy_from_user(&ksig, usig, sizeof(ksig)))
} return -EFAULT;
ret = set_compat_user_sigmask(ksig.sigmask, &ksigmask, &sigsaved, ksig.sigsetsize);
if (ret)
return ret;
ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL); ret = do_io_getevents(ctx_id, min_nr, nr, events, timeout ? &t : NULL);
if (signal_pending(current)) { restore_user_sigmask(ksig.sigmask, &sigsaved);
if (ksig.sigmask) { if (signal_pending(current) && !ret)
current->saved_sigmask = sigsaved;
set_restore_sigmask();
}
if (!ret)
ret = -ERESTARTNOHAND; ret = -ERESTARTNOHAND;
} else {
if (ksig.sigmask)
sigprocmask(SIG_SETMASK, &sigsaved, NULL);
}
return ret; return ret;
} }
......
...@@ -2223,31 +2223,13 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events, ...@@ -2223,31 +2223,13 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
* If the caller wants a certain signal mask to be set during the wait, * If the caller wants a certain signal mask to be set during the wait,
* we apply it here. * we apply it here.
*/ */
if (sigmask) { error = set_user_sigmask(sigmask, &ksigmask, &sigsaved, sigsetsize);
if (sigsetsize != sizeof(sigset_t)) if (error)
return -EINVAL; return error;
if (copy_from_user(&ksigmask, sigmask, sizeof(ksigmask)))
return -EFAULT;
sigsaved = current->blocked;
set_current_blocked(&ksigmask);
}
error = do_epoll_wait(epfd, events, maxevents, timeout); error = do_epoll_wait(epfd, events, maxevents, timeout);
/* restore_user_sigmask(sigmask, &sigsaved);
* If we changed the signal mask, we need to restore the original one.
* In case we've got a signal while waiting, we do not restore the
* signal mask yet, and we allow do_signal() to deliver the signal on
* the way back to userspace, before the signal mask is restored.
*/
if (sigmask) {
if (error == -EINTR) {
memcpy(&current->saved_sigmask, &sigsaved,
sizeof(sigsaved));
set_restore_sigmask();
} else
set_current_blocked(&sigsaved);
}
return error; return error;
} }
...@@ -2266,31 +2248,13 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd, ...@@ -2266,31 +2248,13 @@ COMPAT_SYSCALL_DEFINE6(epoll_pwait, int, epfd,
* If the caller wants a certain signal mask to be set during the wait, * If the caller wants a certain signal mask to be set during the wait,
* we apply it here. * we apply it here.
*/ */
if (sigmask) { err = set_compat_user_sigmask(sigmask, &ksigmask, &sigsaved, sigsetsize);
if (sigsetsize != sizeof(compat_sigset_t)) if (err)
return -EINVAL; return err;
if (get_compat_sigset(&ksigmask, sigmask))
return -EFAULT;
sigsaved = current->blocked;
set_current_blocked(&ksigmask);
}
err = do_epoll_wait(epfd, events, maxevents, timeout); err = do_epoll_wait(epfd, events, maxevents, timeout);
/* restore_user_sigmask(sigmask, &sigsaved);
* If we changed the signal mask, we need to restore the original one.
* In case we've got a signal while waiting, we do not restore the
* signal mask yet, and we allow do_signal() to deliver the signal on
* the way back to userspace, before the signal mask is restored.
*/
if (sigmask) {
if (err == -EINTR) {
memcpy(&current->saved_sigmask, &sigsaved,
sizeof(sigsaved));
set_restore_sigmask();
} else
set_current_blocked(&sigsaved);
}
return err; return err;
} }
......
...@@ -2149,7 +2149,9 @@ EXPORT_SYMBOL(timespec64_trunc); ...@@ -2149,7 +2149,9 @@ EXPORT_SYMBOL(timespec64_trunc);
*/ */
struct timespec64 current_time(struct inode *inode) struct timespec64 current_time(struct inode *inode)
{ {
struct timespec64 now = current_kernel_time64(); struct timespec64 now;
ktime_get_coarse_real_ts64(&now);
if (unlikely(!inode->i_sb)) { if (unlikely(!inode->i_sb)) {
WARN(1, "current_time() called with uninitialized super_block in the inode"); WARN(1, "current_time() called with uninitialized super_block in the inode");
......
This diff is collapsed.
...@@ -169,6 +169,10 @@ typedef struct { ...@@ -169,6 +169,10 @@ typedef struct {
compat_sigset_word sig[_COMPAT_NSIG_WORDS]; compat_sigset_word sig[_COMPAT_NSIG_WORDS];
} compat_sigset_t; } compat_sigset_t;
int set_compat_user_sigmask(const compat_sigset_t __user *usigmask,
sigset_t *set, sigset_t *oldset,
size_t sigsetsize);
struct compat_sigaction { struct compat_sigaction {
#ifndef __ARCH_HAS_IRIX_SIGACTION #ifndef __ARCH_HAS_IRIX_SIGACTION
compat_uptr_t sa_handler; compat_uptr_t sa_handler;
...@@ -558,6 +562,12 @@ asmlinkage long compat_sys_io_pgetevents(compat_aio_context_t ctx_id, ...@@ -558,6 +562,12 @@ asmlinkage long compat_sys_io_pgetevents(compat_aio_context_t ctx_id,
struct io_event __user *events, struct io_event __user *events,
struct old_timespec32 __user *timeout, struct old_timespec32 __user *timeout,
const struct __compat_aio_sigset __user *usig); const struct __compat_aio_sigset __user *usig);
asmlinkage long compat_sys_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);
/* fs/cookies.c */ /* fs/cookies.c */
asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t); asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
...@@ -643,11 +653,21 @@ asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp, ...@@ -643,11 +653,21 @@ asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,
compat_ulong_t __user *exp, compat_ulong_t __user *exp,
struct old_timespec32 __user *tsp, struct old_timespec32 __user *tsp,
void __user *sig); void __user *sig);
asmlinkage long compat_sys_pselect6_time64(int n, compat_ulong_t __user *inp,
compat_ulong_t __user *outp,
compat_ulong_t __user *exp,
struct __kernel_timespec __user *tsp,
void __user *sig);
asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
unsigned int nfds, unsigned int nfds,
struct old_timespec32 __user *tsp, struct old_timespec32 __user *tsp,
const compat_sigset_t __user *sigmask, const compat_sigset_t __user *sigmask,
compat_size_t sigsetsize); compat_size_t sigsetsize);
asmlinkage long compat_sys_ppoll_time64(struct pollfd __user *ufds,
unsigned int nfds,
struct __kernel_timespec __user *tsp,
const compat_sigset_t __user *sigmask,
compat_size_t sigsetsize);
/* fs/signalfd.c */ /* fs/signalfd.c */
asmlinkage long compat_sys_signalfd4(int ufd, asmlinkage long compat_sys_signalfd4(int ufd,
...@@ -768,6 +788,9 @@ asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset, ...@@ -768,6 +788,9 @@ asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese, asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese,
struct compat_siginfo __user *uinfo, struct compat_siginfo __user *uinfo,
struct old_timespec32 __user *uts, compat_size_t sigsetsize); struct old_timespec32 __user *uts, compat_size_t sigsetsize);
asmlinkage long compat_sys_rt_sigtimedwait_time64(compat_sigset_t __user *uthese,
struct compat_siginfo __user *uinfo,
struct __kernel_timespec __user *uts, compat_size_t sigsetsize);
asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig, asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
struct compat_siginfo __user *uinfo); struct compat_siginfo __user *uinfo);
/* No generic prototype for rt_sigreturn */ /* No generic prototype for rt_sigreturn */
...@@ -873,6 +896,9 @@ asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages, ...@@ -873,6 +896,9 @@ asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages,
asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
compat_pid_t pid, int sig, compat_pid_t pid, int sig,
struct compat_siginfo __user *uinfo); struct compat_siginfo __user *uinfo);
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 compat_mmsghdr __user *mmsg, asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
unsigned vlen, unsigned int flags, unsigned vlen, unsigned int flags,
struct old_timespec32 __user *timeout); struct old_timespec32 __user *timeout);
......
...@@ -9,9 +9,6 @@ struct inode; ...@@ -9,9 +9,6 @@ struct inode;
struct mm_struct; struct mm_struct;
struct task_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. * Futexes are matched on equal values of this key.
* The key type depends on whether it's a shared or private mapping. * 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); ...@@ -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, long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
u32 __user *uaddr2, u32 val2, u32 val3); 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 #else
static inline void exit_robust_list(struct task_struct *curr) static inline void exit_robust_list(struct task_struct *curr)
{ {
......
...@@ -273,6 +273,10 @@ extern int group_send_sig_info(int sig, struct kernel_siginfo *info, ...@@ -273,6 +273,10 @@ extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
struct task_struct *p, enum pid_type type); struct task_struct *p, enum pid_type type);
extern int __group_send_sig_info(int, struct kernel_siginfo *, struct task_struct *); extern int __group_send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
extern int sigprocmask(int, sigset_t *, sigset_t *); extern int sigprocmask(int, sigset_t *, sigset_t *);
extern int set_user_sigmask(const sigset_t __user *usigmask, sigset_t *set,
sigset_t *oldset, size_t sigsetsize);
extern void restore_user_sigmask(const void __user *usigmask,
sigset_t *sigsaved);
extern void set_current_blocked(sigset_t *); extern void set_current_blocked(sigset_t *);
extern void __set_current_blocked(const sigset_t *); extern void __set_current_blocked(const sigset_t *);
extern int show_unhandled_signals; extern int show_unhandled_signals;
......
...@@ -349,7 +349,8 @@ struct ucred { ...@@ -349,7 +349,8 @@ struct ucred {
extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr); 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); extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
struct timespec64; struct __kernel_timespec;
struct old_timespec32;
/* The __sys_...msg variants allow MSG_CMSG_COMPAT iff /* The __sys_...msg variants allow MSG_CMSG_COMPAT iff
* forbid_cmsg_compat==false * forbid_cmsg_compat==false
...@@ -358,8 +359,10 @@ extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg, ...@@ -358,8 +359,10 @@ extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg,
unsigned int flags, bool forbid_cmsg_compat); unsigned int flags, bool forbid_cmsg_compat);
extern long __sys_sendmsg(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); unsigned int flags, bool forbid_cmsg_compat);
extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg,
unsigned int flags, struct timespec64 *timeout); unsigned int vlen, unsigned int flags,
struct __kernel_timespec __user *timeout,
struct old_timespec32 __user *timeout32);
extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
unsigned int vlen, unsigned int flags, unsigned int vlen, unsigned int flags,
bool forbid_cmsg_compat); bool forbid_cmsg_compat);
......
...@@ -296,12 +296,18 @@ asmlinkage long sys_io_getevents(aio_context_t ctx_id, ...@@ -296,12 +296,18 @@ asmlinkage long sys_io_getevents(aio_context_t ctx_id,
long min_nr, long min_nr,
long nr, long nr,
struct io_event __user *events, struct io_event __user *events,
struct timespec __user *timeout); struct __kernel_timespec __user *timeout);
asmlinkage long sys_io_pgetevents(aio_context_t ctx_id, asmlinkage long sys_io_pgetevents(aio_context_t ctx_id,
long min_nr, long min_nr,
long nr, long nr,
struct io_event __user *events, struct io_event __user *events,
struct timespec __user *timeout, struct __kernel_timespec __user *timeout,
const struct __aio_sigset *sig);
asmlinkage long sys_io_pgetevents_time32(aio_context_t ctx_id,
long min_nr,
long nr,
struct io_event __user *events,
struct old_timespec32 __user *timeout,
const struct __aio_sigset *sig); const struct __aio_sigset *sig);
/* fs/xattr.c */ /* fs/xattr.c */
...@@ -466,10 +472,16 @@ asmlinkage long sys_sendfile64(int out_fd, int in_fd, ...@@ -466,10 +472,16 @@ asmlinkage long sys_sendfile64(int out_fd, int in_fd,
/* fs/select.c */ /* fs/select.c */
asmlinkage long sys_pselect6(int, fd_set __user *, fd_set __user *, asmlinkage long sys_pselect6(int, fd_set __user *, fd_set __user *,
fd_set __user *, struct timespec __user *, fd_set __user *, struct __kernel_timespec __user *,
void __user *);
asmlinkage long sys_pselect6_time32(int, fd_set __user *, fd_set __user *,
fd_set __user *, struct old_timespec32 __user *,
void __user *); void __user *);
asmlinkage long sys_ppoll(struct pollfd __user *, unsigned int, asmlinkage long sys_ppoll(struct pollfd __user *, unsigned int,
struct timespec __user *, const sigset_t __user *, struct __kernel_timespec __user *, const sigset_t __user *,
size_t);
asmlinkage long sys_ppoll_time32(struct pollfd __user *, unsigned int,
struct old_timespec32 __user *, const sigset_t __user *,
size_t); size_t);
/* fs/signalfd.c */ /* fs/signalfd.c */
...@@ -541,7 +553,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags); ...@@ -541,7 +553,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags);
/* kernel/futex.c */ /* kernel/futex.c */
asmlinkage long sys_futex(u32 __user *uaddr, int op, u32 val, 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); u32 val3);
asmlinkage long sys_get_robust_list(int pid, asmlinkage long sys_get_robust_list(int pid,
struct robust_list_head __user * __user *head_ptr, struct robust_list_head __user * __user *head_ptr,
...@@ -637,6 +649,10 @@ asmlinkage long sys_rt_sigtimedwait(const sigset_t __user *uthese, ...@@ -637,6 +649,10 @@ asmlinkage long sys_rt_sigtimedwait(const sigset_t __user *uthese,
siginfo_t __user *uinfo, siginfo_t __user *uinfo,
const struct __kernel_timespec __user *uts, const struct __kernel_timespec __user *uts,
size_t sigsetsize); size_t sigsetsize);
asmlinkage long sys_rt_sigtimedwait_time32(const sigset_t __user *uthese,
siginfo_t __user *uinfo,
const struct old_timespec32 __user *uts,
size_t sigsetsize);
asmlinkage long sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo); asmlinkage long sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo);
/* kernel/sys.c */ /* kernel/sys.c */
...@@ -831,6 +847,9 @@ asmlinkage long sys_accept4(int, struct sockaddr __user *, int __user *, int); ...@@ -831,6 +847,9 @@ asmlinkage long sys_accept4(int, struct sockaddr __user *, int __user *, int);
asmlinkage long sys_recvmmsg(int fd, struct mmsghdr __user *msg, asmlinkage long sys_recvmmsg(int fd, struct mmsghdr __user *msg,
unsigned int vlen, unsigned flags, unsigned int vlen, unsigned flags,
struct __kernel_timespec __user *timeout); struct __kernel_timespec __user *timeout);
asmlinkage long sys_recvmmsg_time32(int fd, struct mmsghdr __user *msg,
unsigned int vlen, unsigned flags,
struct old_timespec32 __user *timeout);
asmlinkage long sys_wait4(pid_t pid, int __user *stat_addr, asmlinkage long sys_wait4(pid_t pid, int __user *stat_addr,
int options, struct rusage __user *ru); int options, struct rusage __user *ru);
......
...@@ -96,31 +96,6 @@ static inline int timespec_compare(const struct timespec *lhs, const struct time ...@@ -96,31 +96,6 @@ static inline int timespec_compare(const struct timespec *lhs, const struct time
return lhs->tv_nsec - rhs->tv_nsec; return lhs->tv_nsec - rhs->tv_nsec;
} }
extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec);
static inline struct timespec timespec_add(struct timespec lhs,
struct timespec rhs)
{
struct timespec ts_delta;
set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec,
lhs.tv_nsec + rhs.tv_nsec);
return ts_delta;
}
/*
* sub = lhs - rhs, in normalized form
*/
static inline struct timespec timespec_sub(struct timespec lhs,
struct timespec rhs)
{
struct timespec ts_delta;
set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec,
lhs.tv_nsec - rhs.tv_nsec);
return ts_delta;
}
/* /*
* Returns true if the timespec is norm, false if denorm: * Returns true if the timespec is norm, false if denorm:
*/ */
......
...@@ -262,18 +262,4 @@ void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock, ...@@ -262,18 +262,4 @@ void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock,
struct timespec64 *boot_offset); struct timespec64 *boot_offset);
extern int update_persistent_clock64(struct timespec64 now); extern int update_persistent_clock64(struct timespec64 now);
/*
* deprecated aliases, don't use in new code
*/
#define getnstimeofday64(ts) ktime_get_real_ts64(ts)
static inline struct timespec64 current_kernel_time64(void)
{
struct timespec64 ts;
ktime_get_coarse_real_ts64(&ts);
return ts;
}
#endif #endif
...@@ -6,15 +6,6 @@ ...@@ -6,15 +6,6 @@
* over time so we can remove the file here. * over time so we can remove the file here.
*/ */
static inline void do_gettimeofday(struct timeval *tv)
{
struct timespec64 now;
ktime_get_real_ts64(&now);
tv->tv_sec = now.tv_sec;
tv->tv_usec = now.tv_nsec/1000;
}
static inline unsigned long get_seconds(void) static inline unsigned long get_seconds(void)
{ {
return ktime_get_real_seconds(); return ktime_get_real_seconds();
...@@ -52,10 +43,4 @@ static inline void getboottime(struct timespec *ts) ...@@ -52,10 +43,4 @@ static inline void getboottime(struct timespec *ts)
*ts = timespec64_to_timespec(ts64); *ts = timespec64_to_timespec(ts64);
} }
/*
* Persistent clock related interfaces
*/
extern void read_persistent_clock(struct timespec *ts);
extern int update_persistent_clock(struct timespec now);
#endif #endif
...@@ -49,9 +49,6 @@ obj-$(CONFIG_PROFILING) += profile.o ...@@ -49,9 +49,6 @@ obj-$(CONFIG_PROFILING) += profile.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
obj-y += time/ obj-y += time/
obj-$(CONFIG_FUTEX) += futex.o 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_GENERIC_ISA_DMA) += dma.o
obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SMP) += smp.o
ifneq ($(CONFIG_SMP),y) ifneq ($(CONFIG_SMP),y)
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <linux/compat.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -173,8 +174,10 @@ ...@@ -173,8 +174,10 @@
* double_lock_hb() and double_unlock_hb(), respectively. * double_lock_hb() and double_unlock_hb(), respectively.
*/ */
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG #ifdef CONFIG_HAVE_FUTEX_CMPXCHG
int __read_mostly futex_cmpxchg_enabled; #define futex_cmpxchg_enabled 1
#else
static int __read_mostly futex_cmpxchg_enabled;
#endif #endif
/* /*
...@@ -3417,7 +3420,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pid, ...@@ -3417,7 +3420,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
* Process a futex-list entry, check whether it's owned by the * Process a futex-list entry, check whether it's owned by the
* dying task, and do notification if so: * dying task, and do notification if so:
*/ */
int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi) static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi)
{ {
u32 uval, uninitialized_var(nval), mval; u32 uval, uninitialized_var(nval), mval;
...@@ -3612,10 +3615,10 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, ...@@ -3612,10 +3615,10 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, 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) u32, val3)
{ {
struct timespec ts; struct timespec64 ts;
ktime_t t, *tp = NULL; ktime_t t, *tp = NULL;
u32 val2 = 0; u32 val2 = 0;
int cmd = op & FUTEX_CMD_MASK; int cmd = op & FUTEX_CMD_MASK;
...@@ -3625,12 +3628,12 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, ...@@ -3625,12 +3628,12 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
cmd == FUTEX_WAIT_REQUEUE_PI)) { cmd == FUTEX_WAIT_REQUEUE_PI)) {
if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG)))) if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG))))
return -EFAULT; return -EFAULT;
if (copy_from_user(&ts, utime, sizeof(ts)) != 0) if (get_timespec64(&ts, utime))
return -EFAULT; return -EFAULT;
if (!timespec_valid(&ts)) if (!timespec64_valid(&ts))
return -EINVAL; return -EINVAL;
t = timespec_to_ktime(ts); t = timespec64_to_ktime(ts);
if (cmd == FUTEX_WAIT) if (cmd == FUTEX_WAIT)
t = ktime_add_safe(ktime_get(), t); t = ktime_add_safe(ktime_get(), t);
tp = &t; tp = &t;
...@@ -3646,6 +3649,194 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, ...@@ -3646,6 +3649,194 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
} }
#ifdef CONFIG_COMPAT
/*
* Fetch a robust-list pointer. Bit 0 signals PI futexes:
*/
static inline int
compat_fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
compat_uptr_t __user *head, unsigned int *pi)
{
if (get_user(*uentry, head))
return -EFAULT;
*entry = compat_ptr((*uentry) & ~1);
*pi = (unsigned int)(*uentry) & 1;
return 0;
}
static void __user *futex_uaddr(struct robust_list __user *entry,
compat_long_t futex_offset)
{
compat_uptr_t base = ptr_to_compat(entry);
void __user *uaddr = compat_ptr(base + futex_offset);
return uaddr;
}
/*
* Walk curr->robust_list (very carefully, it's a userspace list!)
* and mark any locks found there dead, and notify any waiters.
*
* We silently return on any sign of list-walking problem.
*/
void compat_exit_robust_list(struct task_struct *curr)
{
struct compat_robust_list_head __user *head = curr->compat_robust_list;
struct robust_list __user *entry, *next_entry, *pending;
unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
unsigned int uninitialized_var(next_pi);
compat_uptr_t uentry, next_uentry, upending;
compat_long_t futex_offset;
int rc;
if (!futex_cmpxchg_enabled)
return;
/*
* Fetch the list head (which was registered earlier, via
* sys_set_robust_list()):
*/
if (compat_fetch_robust_entry(&uentry, &entry, &head->list.next, &pi))
return;
/*
* Fetch the relative futex offset:
*/
if (get_user(futex_offset, &head->futex_offset))
return;
/*
* Fetch any possibly pending lock-add first, and handle it
* if it exists:
*/
if (compat_fetch_robust_entry(&upending, &pending,
&head->list_op_pending, &pip))
return;
next_entry = NULL; /* avoid warning with gcc */
while (entry != (struct robust_list __user *) &head->list) {
/*
* Fetch the next entry in the list before calling
* handle_futex_death:
*/
rc = compat_fetch_robust_entry(&next_uentry, &next_entry,
(compat_uptr_t __user *)&entry->next, &next_pi);
/*
* A pending lock might already be on the list, so
* dont process it twice:
*/
if (entry != pending) {
void __user *uaddr = futex_uaddr(entry, futex_offset);
if (handle_futex_death(uaddr, curr, pi))
return;
}
if (rc)
return;
uentry = next_uentry;
entry = next_entry;
pi = next_pi;
/*
* Avoid excessively long or circular lists:
*/
if (!--limit)
break;
cond_resched();
}
if (pending) {
void __user *uaddr = futex_uaddr(pending, futex_offset);
handle_futex_death(uaddr, curr, pip);
}
}
COMPAT_SYSCALL_DEFINE2(set_robust_list,
struct compat_robust_list_head __user *, head,
compat_size_t, len)
{
if (!futex_cmpxchg_enabled)
return -ENOSYS;
if (unlikely(len != sizeof(*head)))
return -EINVAL;
current->compat_robust_list = head;
return 0;
}
COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid,
compat_uptr_t __user *, head_ptr,
compat_size_t __user *, len_ptr)
{
struct compat_robust_list_head __user *head;
unsigned long ret;
struct task_struct *p;
if (!futex_cmpxchg_enabled)
return -ENOSYS;
rcu_read_lock();
ret = -ESRCH;
if (!pid)
p = current;
else {
p = find_task_by_vpid(pid);
if (!p)
goto err_unlock;
}
ret = -EPERM;
if (!ptrace_may_access(p, PTRACE_MODE_READ_REALCREDS))
goto err_unlock;
head = p->compat_robust_list;
rcu_read_unlock();
if (put_user(sizeof(*head), len_ptr))
return -EFAULT;
return put_user(ptr_to_compat(head), head_ptr);
err_unlock:
rcu_read_unlock();
return ret;
}
#endif /* CONFIG_COMPAT */
#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
u32, val3)
{
struct timespec64 ts;
ktime_t t, *tp = NULL;
int val2 = 0;
int cmd = op & FUTEX_CMD_MASK;
if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
cmd == FUTEX_WAIT_BITSET ||
cmd == FUTEX_WAIT_REQUEUE_PI)) {
if (get_old_timespec32(&ts, utime))
return -EFAULT;
if (!timespec64_valid(&ts))
return -EINVAL;
t = timespec64_to_ktime(ts);
if (cmd == FUTEX_WAIT)
t = ktime_add_safe(ktime_get(), t);
tp = &t;
}
if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
val2 = (int) (unsigned long) utime;
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
}
#endif /* CONFIG_COMPAT_32BIT_TIME */
static void __init futex_detect_cmpxchg(void) static void __init futex_detect_cmpxchg(void)
{ {
#ifndef CONFIG_HAVE_FUTEX_CMPXCHG #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
......
// SPDX-License-Identifier: GPL-2.0
/*
* linux/kernel/futex_compat.c
*
* Futex compatibililty routines.
*
* Copyright 2006, Red Hat, Inc., Ingo Molnar
*/
#include <linux/linkage.h>
#include <linux/compat.h>
#include <linux/nsproxy.h>
#include <linux/futex.h>
#include <linux/ptrace.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
/*
* Fetch a robust-list pointer. Bit 0 signals PI futexes:
*/
static inline int
fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
compat_uptr_t __user *head, unsigned int *pi)
{
if (get_user(*uentry, head))
return -EFAULT;
*entry = compat_ptr((*uentry) & ~1);
*pi = (unsigned int)(*uentry) & 1;
return 0;
}
static void __user *futex_uaddr(struct robust_list __user *entry,
compat_long_t futex_offset)
{
compat_uptr_t base = ptr_to_compat(entry);
void __user *uaddr = compat_ptr(base + futex_offset);
return uaddr;
}
/*
* Walk curr->robust_list (very carefully, it's a userspace list!)
* and mark any locks found there dead, and notify any waiters.
*
* We silently return on any sign of list-walking problem.
*/
void compat_exit_robust_list(struct task_struct *curr)
{
struct compat_robust_list_head __user *head = curr->compat_robust_list;
struct robust_list __user *entry, *next_entry, *pending;
unsigned int limit = ROBUST_LIST_LIMIT, pi, pip;
unsigned int uninitialized_var(next_pi);
compat_uptr_t uentry, next_uentry, upending;
compat_long_t futex_offset;
int rc;
if (!futex_cmpxchg_enabled)
return;
/*
* Fetch the list head (which was registered earlier, via
* sys_set_robust_list()):
*/
if (fetch_robust_entry(&uentry, &entry, &head->list.next, &pi))
return;
/*
* Fetch the relative futex offset:
*/
if (get_user(futex_offset, &head->futex_offset))
return;
/*
* Fetch any possibly pending lock-add first, and handle it
* if it exists:
*/
if (fetch_robust_entry(&upending, &pending,
&head->list_op_pending, &pip))
return;
next_entry = NULL; /* avoid warning with gcc */
while (entry != (struct robust_list __user *) &head->list) {
/*
* Fetch the next entry in the list before calling
* handle_futex_death:
*/
rc = fetch_robust_entry(&next_uentry, &next_entry,
(compat_uptr_t __user *)&entry->next, &next_pi);
/*
* A pending lock might already be on the list, so
* dont process it twice:
*/
if (entry != pending) {
void __user *uaddr = futex_uaddr(entry, futex_offset);
if (handle_futex_death(uaddr, curr, pi))
return;
}
if (rc)
return;
uentry = next_uentry;
entry = next_entry;
pi = next_pi;
/*
* Avoid excessively long or circular lists:
*/
if (!--limit)
break;
cond_resched();
}
if (pending) {
void __user *uaddr = futex_uaddr(pending, futex_offset);
handle_futex_death(uaddr, curr, pip);
}
}
COMPAT_SYSCALL_DEFINE2(set_robust_list,
struct compat_robust_list_head __user *, head,
compat_size_t, len)
{
if (!futex_cmpxchg_enabled)
return -ENOSYS;
if (unlikely(len != sizeof(*head)))
return -EINVAL;
current->compat_robust_list = head;
return 0;
}
COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid,
compat_uptr_t __user *, head_ptr,
compat_size_t __user *, len_ptr)
{
struct compat_robust_list_head __user *head;
unsigned long ret;
struct task_struct *p;
if (!futex_cmpxchg_enabled)
return -ENOSYS;
rcu_read_lock();
ret = -ESRCH;
if (!pid)
p = current;
else {
p = find_task_by_vpid(pid);
if (!p)
goto err_unlock;
}
ret = -EPERM;
if (!ptrace_may_access(p, PTRACE_MODE_READ_REALCREDS))
goto err_unlock;
head = p->compat_robust_list;
rcu_read_unlock();
if (put_user(sizeof(*head), len_ptr))
return -EFAULT;
return put_user(ptr_to_compat(head), head_ptr);
err_unlock:
rcu_read_unlock();
return ret;
}
COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
u32, val3)
{
struct timespec ts;
ktime_t t, *tp = NULL;
int val2 = 0;
int cmd = op & FUTEX_CMD_MASK;
if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
cmd == FUTEX_WAIT_BITSET ||
cmd == FUTEX_WAIT_REQUEUE_PI)) {
if (compat_get_timespec(&ts, utime))
return -EFAULT;
if (!timespec_valid(&ts))
return -EINVAL;
t = timespec_to_ktime(ts);
if (cmd == FUTEX_WAIT)
t = ktime_add_safe(ktime_get(), t);
tp = &t;
}
if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
val2 = (int) (unsigned long) utime;
return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
}
...@@ -2735,6 +2735,84 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset) ...@@ -2735,6 +2735,84 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
} }
EXPORT_SYMBOL(sigprocmask); EXPORT_SYMBOL(sigprocmask);
/*
* The api helps set app-provided sigmasks.
*
* This is useful for syscalls such as ppoll, pselect, io_pgetevents and
* epoll_pwait where a new sigmask is passed from userland for the syscalls.
*/
int set_user_sigmask(const sigset_t __user *usigmask, sigset_t *set,
sigset_t *oldset, size_t sigsetsize)
{
if (!usigmask)
return 0;
if (sigsetsize != sizeof(sigset_t))
return -EINVAL;
if (copy_from_user(set, usigmask, sizeof(sigset_t)))
return -EFAULT;
*oldset = current->blocked;
set_current_blocked(set);
return 0;
}
EXPORT_SYMBOL(set_user_sigmask);
#ifdef CONFIG_COMPAT
int set_compat_user_sigmask(const compat_sigset_t __user *usigmask,
sigset_t *set, sigset_t *oldset,
size_t sigsetsize)
{
if (!usigmask)
return 0;
if (sigsetsize != sizeof(compat_sigset_t))
return -EINVAL;
if (get_compat_sigset(set, usigmask))
return -EFAULT;
*oldset = current->blocked;
set_current_blocked(set);
return 0;
}
EXPORT_SYMBOL(set_compat_user_sigmask);
#endif
/*
* restore_user_sigmask:
* usigmask: sigmask passed in from userland.
* sigsaved: saved sigmask when the syscall started and changed the sigmask to
* usigmask.
*
* This is useful for syscalls such as ppoll, pselect, io_pgetevents and
* epoll_pwait where a new sigmask is passed in from userland for the syscalls.
*/
void restore_user_sigmask(const void __user *usigmask, sigset_t *sigsaved)
{
if (!usigmask)
return;
/*
* When signals are pending, do not restore them here.
* Restoring sigmask here can lead to delivering signals that the above
* syscalls are intended to block because of the sigmask passed in.
*/
if (signal_pending(current)) {
current->saved_sigmask = *sigsaved;
set_restore_sigmask();
return;
}
/*
* This is needed because the fast syscall return path does not restore
* saved_sigmask when signals are not pending.
*/
set_current_blocked(sigsaved);
}
EXPORT_SYMBOL(restore_user_sigmask);
/** /**
* sys_rt_sigprocmask - change the list of currently blocked signals * sys_rt_sigprocmask - change the list of currently blocked signals
* @how: whether to add, remove, or set signals * @how: whether to add, remove, or set signals
...@@ -3254,7 +3332,71 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, ...@@ -3254,7 +3332,71 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
return ret; return ret;
} }
#ifdef CONFIG_COMPAT_32BIT_TIME
SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese,
siginfo_t __user *, uinfo,
const struct old_timespec32 __user *, uts,
size_t, sigsetsize)
{
sigset_t these;
struct timespec64 ts;
kernel_siginfo_t info;
int ret;
if (sigsetsize != sizeof(sigset_t))
return -EINVAL;
if (copy_from_user(&these, uthese, sizeof(these)))
return -EFAULT;
if (uts) {
if (get_old_timespec32(&ts, uts))
return -EFAULT;
}
ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL);
if (ret > 0 && uinfo) {
if (copy_siginfo_to_user(uinfo, &info))
ret = -EFAULT;
}
return ret;
}
#endif
#ifdef CONFIG_COMPAT #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;
kernel_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;
}
#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,
struct compat_siginfo __user *, uinfo, struct compat_siginfo __user *, uinfo,
struct old_timespec32 __user *, uts, compat_size_t, sigsetsize) struct old_timespec32 __user *, uts, compat_size_t, sigsetsize)
...@@ -3285,6 +3427,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, ...@@ -3285,6 +3427,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,
return ret; return ret;
} }
#endif #endif
#endif
/** /**
* sys_kill - send a signal to a process * sys_kill - send a signal to a process
......
...@@ -284,7 +284,9 @@ COND_SYSCALL_COMPAT(move_pages); ...@@ -284,7 +284,9 @@ COND_SYSCALL_COMPAT(move_pages);
COND_SYSCALL(perf_event_open); COND_SYSCALL(perf_event_open);
COND_SYSCALL(accept4); COND_SYSCALL(accept4);
COND_SYSCALL(recvmmsg); COND_SYSCALL(recvmmsg);
COND_SYSCALL(recvmmsg_time32);
COND_SYSCALL_COMPAT(recvmmsg); COND_SYSCALL_COMPAT(recvmmsg);
COND_SYSCALL_COMPAT(recvmmsg_time64);
/* /*
* Architecture specific syscalls: see further below * Architecture specific syscalls: see further below
......
...@@ -554,17 +554,9 @@ static void sync_rtc_clock(void) ...@@ -554,17 +554,9 @@ static void sync_rtc_clock(void)
} }
#ifdef CONFIG_GENERIC_CMOS_UPDATE #ifdef CONFIG_GENERIC_CMOS_UPDATE
int __weak update_persistent_clock(struct timespec now)
{
return -ENODEV;
}
int __weak update_persistent_clock64(struct timespec64 now64) int __weak update_persistent_clock64(struct timespec64 now64)
{ {
struct timespec now; return -ENODEV;
now = timespec64_to_timespec(now64);
return update_persistent_clock(now);
} }
#endif #endif
......
...@@ -383,42 +383,6 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0, ...@@ -383,42 +383,6 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0,
} }
EXPORT_SYMBOL(mktime64); EXPORT_SYMBOL(mktime64);
/**
* set_normalized_timespec - set timespec sec and nsec parts and normalize
*
* @ts: pointer to timespec variable to be set
* @sec: seconds to set
* @nsec: nanoseconds to set
*
* Set seconds and nanoseconds field of a timespec variable and
* normalize to the timespec storage format
*
* Note: The tv_nsec part is always in the range of
* 0 <= tv_nsec < NSEC_PER_SEC
* For negative values only the tv_sec field is negative !
*/
void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec)
{
while (nsec >= NSEC_PER_SEC) {
/*
* The following asm() prevents the compiler from
* optimising this loop into a modulo operation. See
* also __iter_div_u64_rem() in include/linux/time.h
*/
asm("" : "+rm"(nsec));
nsec -= NSEC_PER_SEC;
++sec;
}
while (nsec < 0) {
asm("" : "+rm"(nsec));
nsec += NSEC_PER_SEC;
--sec;
}
ts->tv_sec = sec;
ts->tv_nsec = nsec;
}
EXPORT_SYMBOL(set_normalized_timespec);
/** /**
* ns_to_timespec - Convert nanoseconds to timespec * ns_to_timespec - Convert nanoseconds to timespec
* @nsec: the nanoseconds value to be converted * @nsec: the nanoseconds value to be converted
......
...@@ -1464,7 +1464,7 @@ u64 timekeeping_max_deferment(void) ...@@ -1464,7 +1464,7 @@ u64 timekeeping_max_deferment(void)
} }
/** /**
* read_persistent_clock - Return time from the persistent clock. * read_persistent_clock64 - Return time from the persistent clock.
* *
* Weak dummy function for arches that do not yet support it. * Weak dummy function for arches that do not yet support it.
* Reads the time from the battery backed persistent clock. * Reads the time from the battery backed persistent clock.
...@@ -1472,20 +1472,12 @@ u64 timekeeping_max_deferment(void) ...@@ -1472,20 +1472,12 @@ u64 timekeeping_max_deferment(void)
* *
* XXX - Do be sure to remove it once all arches implement it. * XXX - Do be sure to remove it once all arches implement it.
*/ */
void __weak read_persistent_clock(struct timespec *ts) void __weak read_persistent_clock64(struct timespec64 *ts)
{ {
ts->tv_sec = 0; ts->tv_sec = 0;
ts->tv_nsec = 0; ts->tv_nsec = 0;
} }
void __weak read_persistent_clock64(struct timespec64 *ts64)
{
struct timespec ts;
read_persistent_clock(&ts);
*ts64 = timespec_to_timespec64(ts);
}
/** /**
* read_persistent_wall_and_boot_offset - Read persistent clock, and also offset * read_persistent_wall_and_boot_offset - Read persistent clock, and also offset
* from the boot. * from the boot.
......
...@@ -810,34 +810,23 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len ...@@ -810,34 +810,23 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len
return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen); return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen);
} }
static int __compat_sys_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, unsigned int, vlen, unsigned int, flags,
struct old_timespec32 __user *timeout) struct __kernel_timespec __user *, timeout)
{ {
int datagrams;
struct timespec64 ktspec;
if (timeout == NULL)
return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
flags | MSG_CMSG_COMPAT, NULL); flags | MSG_CMSG_COMPAT, timeout, 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;
} }
#ifdef CONFIG_COMPAT_32BIT_TIME
COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
unsigned int, vlen, unsigned int, flags, unsigned int, vlen, unsigned int, flags,
struct old_timespec32 __user *, timeout) struct old_timespec32 __user *, timeout)
{ {
return __compat_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
flags | MSG_CMSG_COMPAT, NULL, timeout);
} }
#endif
COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
{ {
...@@ -925,7 +914,8 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) ...@@ -925,7 +914,8 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
ret = __compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); ret = __compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
break; break;
case SYS_RECVMMSG: case SYS_RECVMMSG:
ret = __compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3], ret = __sys_recvmmsg(a0, compat_ptr(a1), a[2],
a[3] | MSG_CMSG_COMPAT, NULL,
compat_ptr(a[4])); compat_ptr(a[4]));
break; break;
case SYS_ACCEPT4: case SYS_ACCEPT4:
......
...@@ -2341,8 +2341,9 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg, ...@@ -2341,8 +2341,9 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg,
* Linux recvmmsg interface * Linux recvmmsg interface
*/ */
int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, static int do_recvmmsg(int fd, struct mmsghdr __user *mmsg,
unsigned int flags, struct timespec64 *timeout) unsigned int vlen, unsigned int flags,
struct timespec64 *timeout)
{ {
int fput_needed, err, datagrams; int fput_needed, err, datagrams;
struct socket *sock; struct socket *sock;
...@@ -2451,25 +2452,32 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, ...@@ -2451,25 +2452,32 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
return datagrams; return datagrams;
} }
static int do_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg,
unsigned int vlen, unsigned int flags, unsigned int vlen, unsigned int flags,
struct __kernel_timespec __user *timeout) struct __kernel_timespec __user *timeout,
struct old_timespec32 __user *timeout32)
{ {
int datagrams; int datagrams;
struct timespec64 timeout_sys; struct timespec64 timeout_sys;
if (flags & MSG_CMSG_COMPAT) if (timeout && get_timespec64(&timeout_sys, timeout))
return -EINVAL; return -EFAULT;
if (!timeout)
return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL);
if (get_timespec64(&timeout_sys, timeout)) if (timeout32 && get_old_timespec32(&timeout_sys, timeout32))
return -EFAULT; return -EFAULT;
datagrams = __sys_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys); if (!timeout && !timeout32)
return do_recvmmsg(fd, mmsg, vlen, flags, NULL);
datagrams = do_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys);
if (datagrams > 0 && put_timespec64(&timeout_sys, timeout)) if (datagrams <= 0)
return datagrams;
if (timeout && put_timespec64(&timeout_sys, timeout))
datagrams = -EFAULT;
if (timeout32 && put_old_timespec32(&timeout_sys, timeout32))
datagrams = -EFAULT; datagrams = -EFAULT;
return datagrams; return datagrams;
...@@ -2479,8 +2487,23 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, ...@@ -2479,8 +2487,23 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
unsigned int, vlen, unsigned int, flags, unsigned int, vlen, unsigned int, flags,
struct __kernel_timespec __user *, timeout) struct __kernel_timespec __user *, timeout)
{ {
return do_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); if (flags & MSG_CMSG_COMPAT)
return -EINVAL;
return __sys_recvmmsg(fd, mmsg, vlen, flags, timeout, NULL);
}
#ifdef CONFIG_COMPAT_32BIT_TIME
SYSCALL_DEFINE5(recvmmsg_time32, int, fd, struct mmsghdr __user *, mmsg,
unsigned int, vlen, unsigned int, flags,
struct old_timespec32 __user *, timeout)
{
if (flags & MSG_CMSG_COMPAT)
return -EINVAL;
return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL, timeout);
} }
#endif
#ifdef __ARCH_WANT_SYS_SOCKETCALL #ifdef __ARCH_WANT_SYS_SOCKETCALL
/* Argument list sizes for sys_socketcall */ /* Argument list sizes for sys_socketcall */
...@@ -2600,8 +2623,15 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) ...@@ -2600,8 +2623,15 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
a[2], true); a[2], true);
break; break;
case SYS_RECVMMSG: case SYS_RECVMMSG:
err = do_sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], if (IS_ENABLED(CONFIG_64BIT) || !IS_ENABLED(CONFIG_64BIT_TIME))
a[3], (struct __kernel_timespec __user *)a[4]); err = __sys_recvmmsg(a0, (struct mmsghdr __user *)a1,
a[2], a[3],
(struct __kernel_timespec __user *)a[4],
NULL);
else
err = __sys_recvmmsg(a0, (struct mmsghdr __user *)a1,
a[2], a[3], NULL,
(struct old_timespec32 __user *)a[4]);
break; break;
case SYS_ACCEPT4: case SYS_ACCEPT4:
err = __sys_accept4(a0, (struct sockaddr __user *)a1, err = __sys_accept4(a0, (struct sockaddr __user *)a1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment