Merge git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt

* git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt:
hrtimer: don't modify restart_block->fn in restart functions
hrtimer: fix *rmtp/restarts handling in compat_sys_nanosleep()
hrtimer: fix *rmtp handling in hrtimer_nanosleep()
ntp: correct inconsistent interval/tick_length usage

+78 -52
+1 -1
include/linux/hrtimer.h
··· 316 316 317 317 /* Precise sleep: */ 318 318 extern long hrtimer_nanosleep(struct timespec *rqtp, 319 - struct timespec *rmtp, 319 + struct timespec __user *rmtp, 320 320 const enum hrtimer_mode mode, 321 321 const clockid_t clockid); 322 322 extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
+8 -1
include/linux/timex.h
··· 232 232 #else 233 233 #define NTP_INTERVAL_FREQ (HZ) 234 234 #endif 235 - #define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ) 235 + 236 + #define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE) 237 + #define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \ 238 + (s64)CLOCK_TICK_RATE) 239 + 240 + /* Because using NSEC_PER_SEC would be too easy */ 241 + #define NTP_INTERVAL_LENGTH ((((s64)TICK_USEC * NSEC_PER_USEC * USER_HZ) + \ 242 + CLOCK_TICK_ADJUST) / NTP_INTERVAL_FREQ) 236 243 237 244 /* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ 238 245 extern u64 current_tick_length(void);
+39 -4
kernel/compat.c
··· 40 40 __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; 41 41 } 42 42 43 + static long compat_nanosleep_restart(struct restart_block *restart) 44 + { 45 + struct compat_timespec __user *rmtp; 46 + struct timespec rmt; 47 + mm_segment_t oldfs; 48 + long ret; 49 + 50 + rmtp = (struct compat_timespec __user *)(restart->arg1); 51 + restart->arg1 = (unsigned long)&rmt; 52 + oldfs = get_fs(); 53 + set_fs(KERNEL_DS); 54 + ret = hrtimer_nanosleep_restart(restart); 55 + set_fs(oldfs); 56 + 57 + if (ret) { 58 + restart->arg1 = (unsigned long)rmtp; 59 + 60 + if (rmtp && put_compat_timespec(&rmt, rmtp)) 61 + return -EFAULT; 62 + } 63 + 64 + return ret; 65 + } 66 + 43 67 asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp, 44 68 struct compat_timespec __user *rmtp) 45 69 { 46 70 struct timespec tu, rmt; 71 + mm_segment_t oldfs; 47 72 long ret; 48 73 49 74 if (get_compat_timespec(&tu, rqtp)) ··· 77 52 if (!timespec_valid(&tu)) 78 53 return -EINVAL; 79 54 80 - ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL, 81 - CLOCK_MONOTONIC); 55 + oldfs = get_fs(); 56 + set_fs(KERNEL_DS); 57 + ret = hrtimer_nanosleep(&tu, 58 + rmtp ? (struct timespec __user *)&rmt : NULL, 59 + HRTIMER_MODE_REL, CLOCK_MONOTONIC); 60 + set_fs(oldfs); 82 61 83 - if (ret && rmtp) { 84 - if (put_compat_timespec(&rmt, rmtp)) 62 + if (ret) { 63 + struct restart_block *restart 64 + = &current_thread_info()->restart_block; 65 + 66 + restart->fn = compat_nanosleep_restart; 67 + restart->arg1 = (unsigned long)rmtp; 68 + 69 + if (rmtp && put_compat_timespec(&rmt, rmtp)) 85 70 return -EFAULT; 86 71 } 87 72
+27 -28
kernel/hrtimer.c
··· 1319 1319 return t->task == NULL; 1320 1320 } 1321 1321 1322 + static 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 + 1322 1338 long __sched hrtimer_nanosleep_restart(struct restart_block *restart) 1323 1339 { 1324 1340 struct hrtimer_sleeper t; 1325 - struct timespec *rmtp; 1326 - ktime_t time; 1327 - 1328 - restart->fn = do_no_restart_syscall; 1341 + struct timespec __user *rmtp; 1329 1342 1330 1343 hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS); 1331 1344 t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2; ··· 1346 1333 if (do_nanosleep(&t, HRTIMER_MODE_ABS)) 1347 1334 return 0; 1348 1335 1349 - rmtp = (struct timespec *)restart->arg1; 1336 + rmtp = (struct timespec __user *)restart->arg1; 1350 1337 if (rmtp) { 1351 - time = ktime_sub(t.timer.expires, t.timer.base->get_time()); 1352 - if (time.tv64 <= 0) 1353 - return 0; 1354 - *rmtp = ktime_to_timespec(time); 1338 + int ret = update_rmtp(&t.timer, rmtp); 1339 + if (ret <= 0) 1340 + return ret; 1355 1341 } 1356 - 1357 - restart->fn = hrtimer_nanosleep_restart; 1358 1342 1359 1343 /* The other values in restart are already filled in */ 1360 1344 return -ERESTART_RESTARTBLOCK; 1361 1345 } 1362 1346 1363 - long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp, 1347 + long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, 1364 1348 const enum hrtimer_mode mode, const clockid_t clockid) 1365 1349 { 1366 1350 struct restart_block *restart; 1367 1351 struct hrtimer_sleeper t; 1368 - ktime_t rem; 1369 1352 1370 1353 hrtimer_init(&t.timer, clockid, mode); 1371 1354 t.timer.expires = timespec_to_ktime(*rqtp); ··· 1373 1364 return -ERESTARTNOHAND; 1374 1365 1375 1366 if (rmtp) { 1376 - rem = ktime_sub(t.timer.expires, t.timer.base->get_time()); 1377 - if (rem.tv64 <= 0) 1378 - return 0; 1379 - *rmtp = ktime_to_timespec(rem); 1367 + int ret = update_rmtp(&t.timer, rmtp); 1368 + if (ret <= 0) 1369 + return ret; 1380 1370 } 1381 1371 1382 1372 restart = &current_thread_info()->restart_block; ··· 1391 1383 asmlinkage long 1392 1384 sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp) 1393 1385 { 1394 - struct timespec tu, rmt; 1395 - int ret; 1386 + struct timespec tu; 1396 1387 1397 1388 if (copy_from_user(&tu, rqtp, sizeof(tu))) 1398 1389 return -EFAULT; ··· 1399 1392 if (!timespec_valid(&tu)) 1400 1393 return -EINVAL; 1401 1394 1402 - ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL, 1403 - CLOCK_MONOTONIC); 1404 - 1405 - if (ret && rmtp) { 1406 - if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) 1407 - return -EFAULT; 1408 - } 1409 - 1410 - return ret; 1395 + return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC); 1411 1396 } 1412 1397 1413 1398 /*
+3 -14
kernel/posix-timers.c
··· 982 982 static int common_nsleep(const clockid_t which_clock, int flags, 983 983 struct timespec *tsave, struct timespec __user *rmtp) 984 984 { 985 - struct timespec rmt; 986 - int ret; 987 - 988 - ret = hrtimer_nanosleep(tsave, rmtp ? &rmt : NULL, 989 - flags & TIMER_ABSTIME ? 990 - HRTIMER_MODE_ABS : HRTIMER_MODE_REL, 991 - which_clock); 992 - 993 - if (ret && rmtp) { 994 - if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) 995 - return -EFAULT; 996 - } 997 - 998 - return ret; 985 + return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ? 986 + HRTIMER_MODE_ABS : HRTIMER_MODE_REL, 987 + which_clock); 999 988 } 1000 989 1001 990 asmlinkage long
-4
kernel/time/ntp.c
··· 43 43 static long time_reftime; /* time at last adjustment (s) */ 44 44 long time_adjust; 45 45 46 - #define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE) 47 - #define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \ 48 - (s64)CLOCK_TICK_RATE) 49 - 50 46 static void ntp_update_frequency(void) 51 47 { 52 48 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)