aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/hrtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r--kernel/hrtimer.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 668f3967eb39..3f4a57c7895d 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -1319,13 +1319,26 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
1319 return t->task == NULL; 1319 return t->task == NULL;
1320} 1320}
1321 1321
1322static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp)
1323{
1324 struct timespec rmt;
1325 ktime_t rem;
1326
1327 rem = ktime_sub(timer->expires, timer->base->get_time());
1328 if (rem.tv64 <= 0)
1329 return 0;
1330 rmt = ktime_to_timespec(rem);
1331
1332 if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
1333 return -EFAULT;
1334
1335 return 1;
1336}
1337
1322long __sched hrtimer_nanosleep_restart(struct restart_block *restart) 1338long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
1323{ 1339{
1324 struct hrtimer_sleeper t; 1340 struct hrtimer_sleeper t;
1325 struct timespec *rmtp; 1341 struct timespec __user *rmtp;
1326 ktime_t time;
1327
1328 restart->fn = do_no_restart_syscall;
1329 1342
1330 hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS); 1343 hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS);
1331 t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2; 1344 t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2;
@@ -1333,26 +1346,22 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
1333 if (do_nanosleep(&t, HRTIMER_MODE_ABS)) 1346 if (do_nanosleep(&t, HRTIMER_MODE_ABS))
1334 return 0; 1347 return 0;
1335 1348
1336 rmtp = (struct timespec *)restart->arg1; 1349 rmtp = (struct timespec __user *)restart->arg1;
1337 if (rmtp) { 1350 if (rmtp) {
1338 time = ktime_sub(t.timer.expires, t.timer.base->get_time()); 1351 int ret = update_rmtp(&t.timer, rmtp);
1339 if (time.tv64 <= 0) 1352 if (ret <= 0)
1340 return 0; 1353 return ret;
1341 *rmtp = ktime_to_timespec(time);
1342 } 1354 }
1343 1355
1344 restart->fn = hrtimer_nanosleep_restart;
1345
1346 /* The other values in restart are already filled in */ 1356 /* The other values in restart are already filled in */
1347 return -ERESTART_RESTARTBLOCK; 1357 return -ERESTART_RESTARTBLOCK;
1348} 1358}
1349 1359
1350long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp, 1360long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
1351 const enum hrtimer_mode mode, const clockid_t clockid) 1361 const enum hrtimer_mode mode, const clockid_t clockid)
1352{ 1362{
1353 struct restart_block *restart; 1363 struct restart_block *restart;
1354 struct hrtimer_sleeper t; 1364 struct hrtimer_sleeper t;
1355 ktime_t rem;
1356 1365
1357 hrtimer_init(&t.timer, clockid, mode); 1366 hrtimer_init(&t.timer, clockid, mode);
1358 t.timer.expires = timespec_to_ktime(*rqtp); 1367 t.timer.expires = timespec_to_ktime(*rqtp);
@@ -1364,10 +1373,9 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
1364 return -ERESTARTNOHAND; 1373 return -ERESTARTNOHAND;
1365 1374
1366 if (rmtp) { 1375 if (rmtp) {
1367 rem = ktime_sub(t.timer.expires, t.timer.base->get_time()); 1376 int ret = update_rmtp(&t.timer, rmtp);
1368 if (rem.tv64 <= 0) 1377 if (ret <= 0)
1369 return 0; 1378 return ret;
1370 *rmtp = ktime_to_timespec(rem);
1371 } 1379 }
1372 1380
1373 restart = &current_thread_info()->restart_block; 1381 restart = &current_thread_info()->restart_block;
@@ -1383,8 +1391,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
1383asmlinkage long 1391asmlinkage long
1384sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp) 1392sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
1385{ 1393{
1386 struct timespec tu, rmt; 1394 struct timespec tu;
1387 int ret;
1388 1395
1389 if (copy_from_user(&tu, rqtp, sizeof(tu))) 1396 if (copy_from_user(&tu, rqtp, sizeof(tu)))
1390 return -EFAULT; 1397 return -EFAULT;
@@ -1392,15 +1399,7 @@ sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
1392 if (!timespec_valid(&tu)) 1399 if (!timespec_valid(&tu))
1393 return -EINVAL; 1400 return -EINVAL;
1394 1401
1395 ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL, 1402 return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
1396 CLOCK_MONOTONIC);
1397
1398 if (ret && rmtp) {
1399 if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
1400 return -EFAULT;
1401 }
1402
1403 return ret;
1404} 1403}
1405 1404
1406/* 1405/*