]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - kernel/time/timer.c
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
[linux.git] / kernel / time / timer.c
index 74591ba9474f4dff4e0c3d7b7acedbe14b5d57a8..bbc5d1114583b21f1ab489cd40a98f3aa5ebd61d 100644 (file)
@@ -977,13 +977,29 @@ EXPORT_SYMBOL(add_timer);
  */
 void add_timer_on(struct timer_list *timer, int cpu)
 {
-       struct tvec_base *base = per_cpu_ptr(&tvec_bases, cpu);
+       struct tvec_base *new_base = per_cpu_ptr(&tvec_bases, cpu);
+       struct tvec_base *base;
        unsigned long flags;
 
        timer_stats_timer_set_start_info(timer);
        BUG_ON(timer_pending(timer) || !timer->function);
-       spin_lock_irqsave(&base->lock, flags);
-       timer->flags = (timer->flags & ~TIMER_BASEMASK) | cpu;
+
+       /*
+        * If @timer was on a different CPU, it should be migrated with the
+        * old base locked to prevent other operations proceeding with the
+        * wrong base locked.  See lock_timer_base().
+        */
+       base = lock_timer_base(timer, &flags);
+       if (base != new_base) {
+               timer->flags |= TIMER_MIGRATING;
+
+               spin_unlock(&base->lock);
+               base = new_base;
+               spin_lock(&base->lock);
+               WRITE_ONCE(timer->flags,
+                          (timer->flags & ~TIMER_BASEMASK) | cpu);
+       }
+
        debug_activate(timer, timer->expires);
        internal_add_timer(base, timer);
        spin_unlock_irqrestore(&base->lock, flags);