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