From: tip-bot for Al Viro <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org,
viro@ZenIV.linux.org.uk, tglx@linutronix.de,
john.stultz@linaro.org, hpa@zytor.com, viro@ZenIV.linux.org.uk,
peterz@infradead.org
Subject: [tip:timers/core] alarmtimer: Move copyout and freeze handling into alarmtimer_do_nsleep()
Date: Tue, 13 Jun 2017 15:04:41 -0700 [thread overview]
Message-ID: <tip-15f27ce24cb613e6e01ce27c4094c55e55dde5d4@git.kernel.org> (raw)
In-Reply-To: <20170607084241.28657-2-viro@ZenIV.linux.org.uk>
Commit-ID: 15f27ce24cb613e6e01ce27c4094c55e55dde5d4
Gitweb: http://git.kernel.org/tip/15f27ce24cb613e6e01ce27c4094c55e55dde5d4
Author: Al Viro <viro@ZenIV.linux.org.uk>
AuthorDate: Wed, 7 Jun 2017 09:42:27 +0100
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 14 Jun 2017 00:00:40 +0200
alarmtimer: Move copyout and freeze handling into alarmtimer_do_nsleep()
The alarmtimer nanosleep() implementation can be simplified by moving the
copy out of the remaining time to alarmtimer_do_nsleep() which is shared
between the real nanosleep function and the restart function.
The pointer to the timespec64 which is updated has to be stored in the
restart block anyway. Instead of storing it only in the restart case, store
it before calling alarmtimer_do_nsleep() and copy the remaining time in the
signal exit path.
[ tglx: Added changelog ]
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170607084241.28657-2-viro@ZenIV.linux.org.uk
---
kernel/time/alarmtimer.c | 102 +++++++++++++++--------------------------------
1 file changed, 32 insertions(+), 70 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index d8a7a7e..ac6e9bc 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -688,8 +688,10 @@ static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm,
*
* Sets the alarm timer and sleeps until it is fired or interrupted.
*/
-static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp)
+static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
+ enum alarmtimer_type type)
{
+ struct timespec __user *rmtp;
alarm->data = (void *)current;
do {
set_current_state(TASK_INTERRUPTIBLE);
@@ -702,36 +704,26 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp)
__set_current_state(TASK_RUNNING);
- return (alarm->data == NULL);
-}
-
-
-/**
- * update_rmtp - Update remaining timespec value
- * @exp: expiration time
- * @type: timer type
- * @rmtp: user pointer to remaining timepsec value
- *
- * Helper function that fills in rmtp value with time between
- * now and the exp value
- */
-static int update_rmtp(ktime_t exp, enum alarmtimer_type type,
- struct timespec __user *rmtp)
-{
- struct timespec rmt;
- ktime_t rem;
-
- rem = ktime_sub(exp, alarm_bases[type].gettime());
-
- if (rem <= 0)
+ if (!alarm->data)
return 0;
- rmt = ktime_to_timespec(rem);
- if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
- return -EFAULT;
+ if (freezing(current))
+ alarmtimer_freezerset(absexp, type);
+ rmtp = current->restart_block.nanosleep.rmtp;
+ if (rmtp) {
+ struct timespec rmt;
+ ktime_t rem;
- return 1;
+ rem = ktime_sub(absexp, alarm_bases[type].gettime());
+ if (rem <= 0)
+ return 0;
+ rmt = ktime_to_timespec(rem);
+
+ if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
+ return -EFAULT;
+ }
+ return -ERESTART_RESTARTBLOCK;
}
/**
@@ -743,32 +735,12 @@ static int update_rmtp(ktime_t exp, enum alarmtimer_type type,
static long __sched alarm_timer_nsleep_restart(struct restart_block *restart)
{
enum alarmtimer_type type = restart->nanosleep.clockid;
- ktime_t exp;
- struct timespec __user *rmtp;
+ ktime_t exp = restart->nanosleep.expires;
struct alarm alarm;
- int ret = 0;
- exp = restart->nanosleep.expires;
alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
- if (alarmtimer_do_nsleep(&alarm, exp))
- goto out;
-
- if (freezing(current))
- alarmtimer_freezerset(exp, type);
-
- rmtp = restart->nanosleep.rmtp;
- if (rmtp) {
- ret = update_rmtp(exp, type, rmtp);
- if (ret <= 0)
- goto out;
- }
-
-
- /* The other values in restart are already filled in */
- ret = -ERESTART_RESTARTBLOCK;
-out:
- return ret;
+ return alarmtimer_do_nsleep(&alarm, exp, type);
}
/**
@@ -785,11 +757,16 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
struct timespec __user *rmtp)
{
enum alarmtimer_type type = clock2alarm(which_clock);
- struct restart_block *restart;
+ struct restart_block *restart = ¤t->restart_block;
struct alarm alarm;
ktime_t exp;
int ret = 0;
+ if (flags & TIMER_ABSTIME)
+ rmtp = NULL;
+
+ restart->nanosleep.rmtp = rmtp;
+
if (!alarmtimer_get_rtcdev())
return -ENOTSUPP;
@@ -808,32 +785,17 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
exp = ktime_add(now, exp);
}
- if (alarmtimer_do_nsleep(&alarm, exp))
- goto out;
-
- if (freezing(current))
- alarmtimer_freezerset(exp, type);
+ ret = alarmtimer_do_nsleep(&alarm, exp, type);
+ if (ret != -ERESTART_RESTARTBLOCK)
+ return ret;
/* abs timers don't set remaining time or restart */
- if (flags == TIMER_ABSTIME) {
- ret = -ERESTARTNOHAND;
- goto out;
- }
-
- if (rmtp) {
- ret = update_rmtp(exp, type, rmtp);
- if (ret <= 0)
- goto out;
- }
+ if (flags == TIMER_ABSTIME)
+ return -ERESTARTNOHAND;
- restart = ¤t->restart_block;
restart->fn = alarm_timer_nsleep_restart;
restart->nanosleep.clockid = type;
restart->nanosleep.expires = exp;
- restart->nanosleep.rmtp = rmtp;
- ret = -ERESTART_RESTARTBLOCK;
-
-out:
return ret;
}
next prev parent reply other threads:[~2017-06-13 22:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 8:41 [PATCHSET] sanitizing compat nanosleep and other timer-related syscalls Al Viro
2017-06-07 8:42 ` [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Al Viro
2017-06-07 8:42 ` [PATCH 02/16] move copyout and freeze handling into alarmtimer_do_nsleep() Al Viro
2017-06-13 22:04 ` tip-bot for Al Viro [this message]
2017-06-07 8:42 ` [PATCH 03/16] hrtimer_nanosleep(): pass rmtp in restart_block Al Viro
2017-06-13 22:05 ` [tip:timers/core] hrtimer_nanosleep(): Pass " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 04/16] move copyout to do_nanosleel() Al Viro
2017-06-13 22:05 ` [tip:timers/core] hrtimer: Move copyout of remaining time to do_nanosleep() tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 05/16] clock_nanosleep(): stash rmtp into restart_block Al Viro
2017-06-13 22:06 ` [tip:timers/core] posix-timers: Store rmtp into restart_block in sys_clock_nanosleep() tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 06/16] nanosleep/clock_nanosleep: teach to do compat copyouts Al Viro
2017-06-07 10:07 ` Peter Zijlstra
2017-06-13 22:06 ` [tip:timers/core] time/posix-timers: Move the compat copyouts to the nanosleep implementations tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 07/16] {clock_,}nanosleep(2): merge timespec copyout logics into a new helper Al Viro
2017-06-13 22:07 ` [tip:timers/core] hrtimers/posix-timers: Merge nanosleep " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 08/16] kill ->nsleep_restart() Al Viro
2017-06-13 22:08 ` [tip:timers/core] posix-timers: Kill ->nsleep_restart() tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 09/16] move adjtimex-related compat syscalls to native counterparts Al Viro
2017-06-13 22:08 ` [tip:timers/core] ntp: Move adjtimex related " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 10/16] take compat timer_settime(2) to native one Al Viro
2017-06-13 22:09 ` [tip:timers/core] posix-timers: Take " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 11/16] take compat timer_gettime(2) " Al Viro
2017-06-13 22:09 ` [tip:timers/core] posix-timers: Take " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 12/16] move compat itimer syscalls to native ones Al Viro
2017-06-13 22:10 ` [tip:timers/core] itimers: Move " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 13/16] clock_gettime/clock_settime/clock_getres: move to native syscalls Al Viro
2017-06-13 22:10 ` [tip:timers/core] posix-timers: Move compat versions of clock_gettime/settime/getres tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 14/16] timer_create(): move compat to native, get rid of set_fs() Al Viro
2017-06-13 22:11 ` [tip:timers/core] posix-timers: Move compat_timer_create() " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 15/16] time()/stime(): move compat to native Al Viro
2017-06-13 22:11 ` [tip:timers/core] time: Move compat_time()/stime() " tip-bot for Al Viro
2017-06-07 8:42 ` [PATCH 16/16] gettimeofday()/settimeofday(): move compat " Al Viro
2017-06-13 22:12 ` [tip:timers/core] time: Move compat_gettimeofday()/settimeofday() " tip-bot for Al Viro
2017-06-12 23:08 ` [PATCH 01/16] move copyout of timespec into do_cpu_nanosleep() Thomas Gleixner
2017-06-13 7:46 ` Thomas Gleixner
2017-06-13 22:04 ` [tip:timers/core] posix-cpu-timers: Move " tip-bot for Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-15f27ce24cb613e6e01ce27c4094c55e55dde5d4@git.kernel.org \
--to=tipbot@zytor.com \
--cc=hpa@zytor.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).