Fix user namespace exiting OOPs
[safe/jmp/linux-2.6] / kernel / hrtimer.c
index 5e7122d..c21ca6b 100644 (file)
@@ -59,6 +59,7 @@ ktime_t ktime_get(void)
 
        return timespec_to_ktime(now);
 }
+EXPORT_SYMBOL_GPL(ktime_get);
 
 /**
  * ktime_get_real - get the real (wall-) time in ktime_t format
@@ -135,20 +136,17 @@ EXPORT_SYMBOL_GPL(ktime_get_ts);
 static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
 {
        ktime_t xtim, tomono;
-       struct timespec xts;
+       struct timespec xts, tom;
        unsigned long seq;
 
        do {
                seq = read_seqbegin(&xtime_lock);
-#ifdef CONFIG_NO_HZ
-               getnstimeofday(&xts);
-#else
-               xts = xtime;
-#endif
+               xts = current_kernel_time();
+               tom = wall_to_monotonic;
        } while (read_seqretry(&xtime_lock, seq));
 
        xtim = timespec_to_ktime(xts);
-       tomono = timespec_to_ktime(wall_to_monotonic);
+       tomono = timespec_to_ktime(tom);
        base->clock_base[CLOCK_REALTIME].softirq_time = xtim;
        base->clock_base[CLOCK_MONOTONIC].softirq_time =
                ktime_add(xtim, tomono);
@@ -277,6 +275,8 @@ ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
 
        return ktime_add(kt, tmp);
 }
+
+EXPORT_SYMBOL_GPL(ktime_add_ns);
 # endif /* !CONFIG_KTIME_SCALAR */
 
 /*
@@ -458,6 +458,18 @@ void clock_was_set(void)
 }
 
 /*
+ * During resume we might have to reprogram the high resolution timer
+ * interrupt (on the local CPU):
+ */
+void hres_timers_resume(void)
+{
+       WARN_ON_ONCE(num_online_cpus() > 1);
+
+       /* Retrigger the CPU local events: */
+       retrigger_next_event(NULL);
+}
+
+/*
  * Check, whether the timer is on the callback pending list
  */
 static inline int hrtimer_cb_pending(const struct hrtimer *timer)
@@ -542,7 +554,8 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  */
 static int hrtimer_switch_to_hres(void)
 {
-       struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
+       int cpu = smp_processor_id();
+       struct hrtimer_cpu_base *base = &per_cpu(hrtimer_bases, cpu);
        unsigned long flags;
 
        if (base->hres_active)
@@ -552,6 +565,8 @@ static int hrtimer_switch_to_hres(void)
 
        if (tick_init_highres()) {
                local_irq_restore(flags);
+               printk(KERN_WARNING "Could not switch to high resolution "
+                                   "mode on CPU %d\n", cpu);
                return 0;
        }
        base->hres_active = 1;
@@ -653,6 +668,7 @@ hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
 
        return orun;
 }
+EXPORT_SYMBOL_GPL(hrtimer_forward);
 
 /*
  * enqueue_hrtimer - internal function to (re)start a timer
@@ -666,6 +682,7 @@ static void enqueue_hrtimer(struct hrtimer *timer,
        struct rb_node **link = &base->active.rb_node;
        struct rb_node *parent = NULL;
        struct hrtimer *entry;
+       int leftmost = 1;
 
        /*
         * Find the right place in the rbtree:
@@ -677,18 +694,19 @@ static void enqueue_hrtimer(struct hrtimer *timer,
                 * We dont care about collisions. Nodes with
                 * the same expiry time stay together.
                 */
-               if (timer->expires.tv64 < entry->expires.tv64)
+               if (timer->expires.tv64 < entry->expires.tv64) {
                        link = &(*link)->rb_left;
-               else
+               } else {
                        link = &(*link)->rb_right;
+                       leftmost = 0;
+               }
        }
 
        /*
         * Insert the timer to the rbtree and check whether it
         * replaces the first pending timer
         */
-       if (!base->first || timer->expires.tv64 <
-           rb_entry(base->first, struct hrtimer, node)->expires.tv64) {
+       if (leftmost) {
                /*
                 * Reprogram the clock event device. When the timer is already
                 * expired hrtimer_enqueue_reprogram has either called the
@@ -813,7 +831,12 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
 
        timer_stats_hrtimer_set_start_info(timer);
 
-       enqueue_hrtimer(timer, new_base, base == new_base);
+       /*
+        * Only allow reprogramming if the new base is on this CPU.
+        * (it might still be on another CPU if the timer was pending)
+        */
+       enqueue_hrtimer(timer, new_base,
+                       new_base->cpu_base == &__get_cpu_var(hrtimer_bases));
 
        unlock_hrtimer_base(timer, &flags);
 
@@ -1384,16 +1407,18 @@ static void migrate_hrtimers(int cpu)
 static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
                                        unsigned long action, void *hcpu)
 {
-       long cpu = (long)hcpu;
+       unsigned int cpu = (long)hcpu;
 
        switch (action) {
 
        case CPU_UP_PREPARE:
+       case CPU_UP_PREPARE_FROZEN:
                init_hrtimers_cpu(cpu);
                break;
 
 #ifdef CONFIG_HOTPLUG_CPU
        case CPU_DEAD:
+       case CPU_DEAD_FROZEN:
                clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &cpu);
                migrate_hrtimers(cpu);
                break;