2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-11-28 04:24:34 +08:00

nanosleep: Use get_timespec64() and put_timespec64()

Usage of these apis and their compat versions makes
the syscalls: clock_nanosleep and nanosleep and
their compat implementations simpler.

This is a preparatory patch to isolate data conversions to
struct timespec64 at userspace boundaries. This helps contain
the changes needed to transition to new y2038 safe types.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Deepa Dinamani 2017-06-24 11:45:06 -07:00 committed by Al Viro
parent 5c4994102f
commit c0edd7c9ac
5 changed files with 26 additions and 38 deletions

View File

@ -453,7 +453,7 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer,
/* Precise sleep: */ /* Precise sleep: */
extern int nanosleep_copyout(struct restart_block *, struct timespec *); extern int nanosleep_copyout(struct restart_block *, struct timespec64 *);
extern long hrtimer_nanosleep(const struct timespec64 *rqtp, extern long hrtimer_nanosleep(const struct timespec64 *rqtp,
const enum hrtimer_mode mode, const enum hrtimer_mode mode,
const clockid_t clockid); const clockid_t clockid);

View File

@ -712,14 +712,14 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
alarmtimer_freezerset(absexp, type); alarmtimer_freezerset(absexp, type);
restart = &current->restart_block; restart = &current->restart_block;
if (restart->nanosleep.type != TT_NONE) { if (restart->nanosleep.type != TT_NONE) {
struct timespec rmt; struct timespec64 rmt;
ktime_t rem; ktime_t rem;
rem = ktime_sub(absexp, alarm_bases[type].gettime()); rem = ktime_sub(absexp, alarm_bases[type].gettime());
if (rem <= 0) if (rem <= 0)
return 0; return 0;
rmt = ktime_to_timespec(rem); rmt = ktime_to_timespec64(rem);
return nanosleep_copyout(restart, &rmt); return nanosleep_copyout(restart, &rmt);
} }

View File

@ -1440,17 +1440,17 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
} }
EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
int nanosleep_copyout(struct restart_block *restart, struct timespec *ts) int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts)
{ {
switch(restart->nanosleep.type) { switch(restart->nanosleep.type) {
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
case TT_COMPAT: case TT_COMPAT:
if (compat_put_timespec(ts, restart->nanosleep.compat_rmtp)) if (compat_put_timespec64(ts, restart->nanosleep.compat_rmtp))
return -EFAULT; return -EFAULT;
break; break;
#endif #endif
case TT_NATIVE: case TT_NATIVE:
if (copy_to_user(restart->nanosleep.rmtp, ts, sizeof(struct timespec))) if (put_timespec64(ts, restart->nanosleep.rmtp))
return -EFAULT; return -EFAULT;
break; break;
default: default:
@ -1485,11 +1485,11 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
restart = &current->restart_block; restart = &current->restart_block;
if (restart->nanosleep.type != TT_NONE) { if (restart->nanosleep.type != TT_NONE) {
ktime_t rem = hrtimer_expires_remaining(&t->timer); ktime_t rem = hrtimer_expires_remaining(&t->timer);
struct timespec rmt; struct timespec64 rmt;
if (rem <= 0) if (rem <= 0)
return 0; return 0;
rmt = ktime_to_timespec(rem); rmt = ktime_to_timespec64(rem);
return nanosleep_copyout(restart, &rmt); return nanosleep_copyout(restart, &rmt);
} }
@ -1546,19 +1546,17 @@ out:
SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp, SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
struct timespec __user *, rmtp) struct timespec __user *, rmtp)
{ {
struct timespec64 tu64; struct timespec64 tu;
struct timespec tu;
if (copy_from_user(&tu, rqtp, sizeof(tu))) if (get_timespec64(&tu, rqtp))
return -EFAULT; return -EFAULT;
tu64 = timespec_to_timespec64(tu); if (!timespec64_valid(&tu))
if (!timespec64_valid(&tu64))
return -EINVAL; return -EINVAL;
current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
current->restart_block.nanosleep.rmtp = rmtp; current->restart_block.nanosleep.rmtp = rmtp;
return hrtimer_nanosleep(&tu64, HRTIMER_MODE_REL, CLOCK_MONOTONIC); return hrtimer_nanosleep(&tu, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
@ -1566,19 +1564,17 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
struct compat_timespec __user *, rmtp) struct compat_timespec __user *, rmtp)
{ {
struct timespec64 tu64; struct timespec64 tu;
struct timespec tu;
if (compat_get_timespec(&tu, rqtp)) if (compat_get_timespec64(&tu, rqtp))
return -EFAULT; return -EFAULT;
tu64 = timespec_to_timespec64(tu); if (!timespec64_valid(&tu))
if (!timespec64_valid(&tu64))
return -EINVAL; return -EINVAL;
current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
current->restart_block.nanosleep.compat_rmtp = rmtp; current->restart_block.nanosleep.compat_rmtp = rmtp;
return hrtimer_nanosleep(&tu64, HRTIMER_MODE_REL, CLOCK_MONOTONIC); return hrtimer_nanosleep(&tu, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
} }
#endif #endif

View File

@ -1314,12 +1314,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
*/ */
restart = &current->restart_block; restart = &current->restart_block;
restart->nanosleep.expires = expires; restart->nanosleep.expires = expires;
if (restart->nanosleep.type != TT_NONE) { if (restart->nanosleep.type != TT_NONE)
struct timespec ts; error = nanosleep_copyout(restart, &it.it_value);
ts = timespec64_to_timespec(it.it_value);
error = nanosleep_copyout(restart, &ts);
}
} }
return error; return error;

View File

@ -1213,26 +1213,24 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
struct timespec __user *, rmtp) struct timespec __user *, rmtp)
{ {
const struct k_clock *kc = clockid_to_kclock(which_clock); const struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec64 t64; struct timespec64 t;
struct timespec t;
if (!kc) if (!kc)
return -EINVAL; return -EINVAL;
if (!kc->nsleep) if (!kc->nsleep)
return -ENANOSLEEP_NOTSUP; return -ENANOSLEEP_NOTSUP;
if (copy_from_user(&t, rqtp, sizeof (struct timespec))) if (get_timespec64(&t, rqtp))
return -EFAULT; return -EFAULT;
t64 = timespec_to_timespec64(t); if (!timespec64_valid(&t))
if (!timespec64_valid(&t64))
return -EINVAL; return -EINVAL;
if (flags & TIMER_ABSTIME) if (flags & TIMER_ABSTIME)
rmtp = NULL; rmtp = NULL;
current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
current->restart_block.nanosleep.rmtp = rmtp; current->restart_block.nanosleep.rmtp = rmtp;
return kc->nsleep(which_clock, flags, &t64); return kc->nsleep(which_clock, flags, &t);
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
@ -1241,26 +1239,24 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
struct compat_timespec __user *, rmtp) struct compat_timespec __user *, rmtp)
{ {
const struct k_clock *kc = clockid_to_kclock(which_clock); const struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec64 t64; struct timespec64 t;
struct timespec t;
if (!kc) if (!kc)
return -EINVAL; return -EINVAL;
if (!kc->nsleep) if (!kc->nsleep)
return -ENANOSLEEP_NOTSUP; return -ENANOSLEEP_NOTSUP;
if (compat_get_timespec(&t, rqtp)) if (compat_get_timespec64(&t, rqtp))
return -EFAULT; return -EFAULT;
t64 = timespec_to_timespec64(t); if (!timespec64_valid(&t))
if (!timespec64_valid(&t64))
return -EINVAL; return -EINVAL;
if (flags & TIMER_ABSTIME) if (flags & TIMER_ABSTIME)
rmtp = NULL; rmtp = NULL;
current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
current->restart_block.nanosleep.compat_rmtp = rmtp; current->restart_block.nanosleep.compat_rmtp = rmtp;
return kc->nsleep(which_clock, flags, &t64); return kc->nsleep(which_clock, flags, &t);
} }
#endif #endif