Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1659541
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 04/16] move copyout to do_nanosleel() |
| Date | 2017-06-07 10:50 +0200 |
| Message-ID | <tPEP9-4gO-39@gated-at.bofh.it> (permalink) |
| References | <tPEP7-4gO-5@gated-at.bofh.it> <tPEP7-4gO-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
kernel/time/hrtimer.c | 62 +++++++++++++++++----------------------------------
1 file changed, 20 insertions(+), 42 deletions(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 4ae777f159de..baa7b846b6e3 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1441,6 +1441,7 @@ EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
{
+ struct timespec __user *rmtp;
hrtimer_init_sleeper(t, current);
do {
@@ -1457,48 +1458,33 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
__set_current_state(TASK_RUNNING);
- return t->task == NULL;
-}
-
-static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp)
-{
- struct timespec rmt;
- ktime_t rem;
-
- rem = hrtimer_expires_remaining(timer);
- if (rem <= 0)
+ if (!t->task)
return 0;
- rmt = ktime_to_timespec(rem);
- if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
- return -EFAULT;
-
- return 1;
+ rmtp = current->restart_block.nanosleep.rmtp;
+ if (rmtp) {
+ struct timespec rmt;
+ ktime_t rem = hrtimer_expires_remaining(&t->timer);
+ if (rem <= 0)
+ return 0;
+ rmt = ktime_to_timespec(rem);
+
+ if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
+ return -EFAULT;
+ }
+ return -ERESTART_RESTARTBLOCK;
}
long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
{
struct hrtimer_sleeper t;
- struct timespec __user *rmtp;
- int ret = 0;
+ int ret;
hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid,
HRTIMER_MODE_ABS);
hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
- if (do_nanosleep(&t, HRTIMER_MODE_ABS))
- goto out;
-
- rmtp = restart->nanosleep.rmtp;
- if (rmtp) {
- ret = update_rmtp(&t.timer, rmtp);
- if (ret <= 0)
- goto out;
- }
-
- /* The other values in restart are already filled in */
- ret = -ERESTART_RESTARTBLOCK;
-out:
+ ret = do_nanosleep(&t, HRTIMER_MODE_ABS);
destroy_hrtimer_on_stack(&t.timer);
return ret;
}
@@ -1506,8 +1492,7 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
long hrtimer_nanosleep(struct timespec64 *rqtp,
const enum hrtimer_mode mode, const clockid_t clockid)
{
- struct restart_block *restart = ¤t->restart_block;
- struct timespec __user *rmtp;
+ struct restart_block *restart;
struct hrtimer_sleeper t;
int ret = 0;
u64 slack;
@@ -1518,7 +1503,8 @@ long hrtimer_nanosleep(struct timespec64 *rqtp,
hrtimer_init_on_stack(&t.timer, clockid, mode);
hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack);
- if (do_nanosleep(&t, mode))
+ ret = do_nanosleep(&t, mode);
+ if (ret != -ERESTART_RESTARTBLOCK)
goto out;
/* Absolute timers do not update the rmtp value and restart: */
@@ -1527,18 +1513,10 @@ long hrtimer_nanosleep(struct timespec64 *rqtp,
goto out;
}
- rmtp = restart->nanosleep.rmtp;
- if (rmtp) {
- ret = update_rmtp(&t.timer, rmtp);
- if (ret <= 0)
- goto out;
- }
-
+ restart = ¤t->restart_block;
restart->fn = hrtimer_nanosleep_restart;
restart->nanosleep.clockid = t.timer.base->clockid;
restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
-
- ret = -ERESTART_RESTARTBLOCK;
out:
destroy_hrtimer_on_stack(&t.timer);
return ret;
--
2.11.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[PATCH 06/16] nanosleep/clock_nanosleep: teach to do compat copyouts Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
Re: [PATCH 06/16] nanosleep/clock_nanosleep: teach to do compat copyouts Peter Zijlstra <peterz@infradead.org> - 2017-06-07 12:10 +0200
[tip:timers/core] time/posix-timers: Move the compat copyouts to the nanosleep implementations tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 15/16] time()/stime(): move compat to native Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] time: Move compat_time()/stime() to native tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 12/16] move compat itimer syscalls to native ones Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] itimers: Move compat itimer syscalls to native ones tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 04/16] move copyout to do_nanosleel() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] hrtimer: Move copyout of remaining time to do_nanosleep() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
[PATCH 14/16] timer_create(): move compat to native, get rid of set_fs() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Move compat_timer_create() to native, get rid of set_fs() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 09/16] move adjtimex-related compat syscalls to native counterparts Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] ntp: Move adjtimex related compat syscalls to native counterparts tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 03/16] hrtimer_nanosleep(): pass rmtp in restart_block Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] hrtimer_nanosleep(): Pass rmtp in restart_block tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
[PATCH 08/16] kill ->nsleep_restart() Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Kill ->nsleep_restart() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
[PATCH 10/16] take compat timer_settime(2) to native one Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-07 10:50 +0200
[tip:timers/core] posix-timers: Take compat timer_settime(2) to native one tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:20 +0200
Re: [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Thomas Gleixner <tglx@linutronix.de> - 2017-06-13 01:10 +0200
Re: [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Thomas Gleixner <tglx@linutronix.de> - 2017-06-13 09:50 +0200
[tip:timers/core] posix-cpu-timers: Move copyout of timespec into do_cpu_nanosleep() tip-bot for Al Viro <tipbot@zytor.com> - 2017-06-14 00:10 +0200
csiph-web