Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Linus Torvalds committed Feb 10, 2008
2 parents 712a30e + c289b07 commit 58a14ee
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 52 deletions.
2 changes: 1 addition & 1 deletion include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer,

/* Precise sleep: */
extern long hrtimer_nanosleep(struct timespec *rqtp,
struct timespec *rmtp,
struct timespec __user *rmtp,
const enum hrtimer_mode mode,
const clockid_t clockid);
extern long hrtimer_nanosleep_restart(struct restart_block *restart_block);
Expand Down
9 changes: 8 additions & 1 deletion include/linux/timex.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,14 @@ static inline int ntp_synced(void)
#else
#define NTP_INTERVAL_FREQ (HZ)
#endif
#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)

#define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE)
#define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \
(s64)CLOCK_TICK_RATE)

/* Because using NSEC_PER_SEC would be too easy */
#define NTP_INTERVAL_LENGTH ((((s64)TICK_USEC * NSEC_PER_USEC * USER_HZ) + \
CLOCK_TICK_ADJUST) / NTP_INTERVAL_FREQ)

/* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */
extern u64 current_tick_length(void);
Expand Down
43 changes: 39 additions & 4 deletions kernel/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,35 @@ int put_compat_timespec(const struct timespec *ts, struct compat_timespec __user
__put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
}

static long compat_nanosleep_restart(struct restart_block *restart)
{
struct compat_timespec __user *rmtp;
struct timespec rmt;
mm_segment_t oldfs;
long ret;

rmtp = (struct compat_timespec __user *)(restart->arg1);
restart->arg1 = (unsigned long)&rmt;
oldfs = get_fs();
set_fs(KERNEL_DS);
ret = hrtimer_nanosleep_restart(restart);
set_fs(oldfs);

if (ret) {
restart->arg1 = (unsigned long)rmtp;

if (rmtp && put_compat_timespec(&rmt, rmtp))
return -EFAULT;
}

return ret;
}

asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
struct compat_timespec __user *rmtp)
{
struct timespec tu, rmt;
mm_segment_t oldfs;
long ret;

if (get_compat_timespec(&tu, rqtp))
Expand All @@ -52,11 +77,21 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
if (!timespec_valid(&tu))
return -EINVAL;

ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL,
CLOCK_MONOTONIC);
oldfs = get_fs();
set_fs(KERNEL_DS);
ret = hrtimer_nanosleep(&tu,
rmtp ? (struct timespec __user *)&rmt : NULL,
HRTIMER_MODE_REL, CLOCK_MONOTONIC);
set_fs(oldfs);

if (ret) {
struct restart_block *restart
= &current_thread_info()->restart_block;

restart->fn = compat_nanosleep_restart;
restart->arg1 = (unsigned long)rmtp;

if (ret && rmtp) {
if (put_compat_timespec(&rmt, rmtp))
if (rmtp && put_compat_timespec(&rmt, rmtp))
return -EFAULT;
}

Expand Down
55 changes: 27 additions & 28 deletions kernel/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,40 +1319,49 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
return t->task == NULL;
}

static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp)
{
struct timespec rmt;
ktime_t rem;

rem = ktime_sub(timer->expires, timer->base->get_time());
if (rem.tv64 <= 0)
return 0;
rmt = ktime_to_timespec(rem);

if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
return -EFAULT;

return 1;
}

long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
{
struct hrtimer_sleeper t;
struct timespec *rmtp;
ktime_t time;

restart->fn = do_no_restart_syscall;
struct timespec __user *rmtp;

hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS);
t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2;

if (do_nanosleep(&t, HRTIMER_MODE_ABS))
return 0;

rmtp = (struct timespec *)restart->arg1;
rmtp = (struct timespec __user *)restart->arg1;
if (rmtp) {
time = ktime_sub(t.timer.expires, t.timer.base->get_time());
if (time.tv64 <= 0)
return 0;
*rmtp = ktime_to_timespec(time);
int ret = update_rmtp(&t.timer, rmtp);
if (ret <= 0)
return ret;
}

restart->fn = hrtimer_nanosleep_restart;

/* The other values in restart are already filled in */
return -ERESTART_RESTARTBLOCK;
}

long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
const enum hrtimer_mode mode, const clockid_t clockid)
{
struct restart_block *restart;
struct hrtimer_sleeper t;
ktime_t rem;

hrtimer_init(&t.timer, clockid, mode);
t.timer.expires = timespec_to_ktime(*rqtp);
Expand All @@ -1364,10 +1373,9 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
return -ERESTARTNOHAND;

if (rmtp) {
rem = ktime_sub(t.timer.expires, t.timer.base->get_time());
if (rem.tv64 <= 0)
return 0;
*rmtp = ktime_to_timespec(rem);
int ret = update_rmtp(&t.timer, rmtp);
if (ret <= 0)
return ret;
}

restart = &current_thread_info()->restart_block;
Expand All @@ -1383,24 +1391,15 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec *rmtp,
asmlinkage long
sys_nanosleep(struct timespec __user *rqtp, struct timespec __user *rmtp)
{
struct timespec tu, rmt;
int ret;
struct timespec tu;

if (copy_from_user(&tu, rqtp, sizeof(tu)))
return -EFAULT;

if (!timespec_valid(&tu))
return -EINVAL;

ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL,
CLOCK_MONOTONIC);

if (ret && rmtp) {
if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
return -EFAULT;
}

return ret;
return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
}

/*
Expand Down
17 changes: 3 additions & 14 deletions kernel/posix-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,20 +982,9 @@ sys_clock_getres(const clockid_t which_clock, struct timespec __user *tp)
static int common_nsleep(const clockid_t which_clock, int flags,
struct timespec *tsave, struct timespec __user *rmtp)
{
struct timespec rmt;
int ret;

ret = hrtimer_nanosleep(tsave, rmtp ? &rmt : NULL,
flags & TIMER_ABSTIME ?
HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
which_clock);

if (ret && rmtp) {
if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
return -EFAULT;
}

return ret;
return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ?
HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
which_clock);
}

asmlinkage long
Expand Down
4 changes: 0 additions & 4 deletions kernel/time/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ long time_freq; /* frequency offset (scaled ppm)*/
static long time_reftime; /* time at last adjustment (s) */
long time_adjust;

#define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE)
#define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \
(s64)CLOCK_TICK_RATE)

static void ntp_update_frequency(void)
{
u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
Expand Down

0 comments on commit 58a14ee

Please sign in to comment.