HID: usbhid: add quirk HID_QUIRK_NOGET to TPV optical touchscreen
[firefly-linux-kernel-4.4.55.git] / kernel / rcutree.c
index 6194402ec853b6cf4dbd25a85bb704b004b8073a..4fb2376ddf0660575970a29db0637ac4c70c2020 100644 (file)
@@ -134,13 +134,12 @@ static int rcu_scheduler_fully_active __read_mostly;
  */
 static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
 DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
-DEFINE_PER_CPU(int, rcu_cpu_kthread_cpu);
 DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
 DEFINE_PER_CPU(char, rcu_cpu_has_work);
 
 #endif /* #ifdef CONFIG_RCU_BOOST */
 
-static void rcu_node_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
+static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu);
 static void invoke_rcu_core(void);
 static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
 
@@ -207,6 +206,9 @@ EXPORT_SYMBOL_GPL(rcu_note_context_switch);
 DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
        .dynticks_nesting = DYNTICK_TASK_EXIT_IDLE,
        .dynticks = ATOMIC_INIT(1),
+#if defined(CONFIG_RCU_USER_QS) && !defined(CONFIG_RCU_USER_QS_FORCE)
+       .ignore_user_qs = true,
+#endif
 };
 
 static int blimit = 10;                /* Maximum callbacks per rcu_do_batch. */
@@ -323,45 +325,17 @@ static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
 }
 
 /*
- * If the specified CPU is offline, tell the caller that it is in
- * a quiescent state.  Otherwise, whack it with a reschedule IPI.
- * Grace periods can end up waiting on an offline CPU when that
- * CPU is in the process of coming online -- it will be added to the
- * rcu_node bitmasks before it actually makes it online.  The same thing
- * can happen while a CPU is in the process of coming online.  Because this
- * race is quite rare, we check for it after detecting that the grace
- * period has been delayed rather than checking each and every CPU
- * each and every time we start a new grace period.
- */
-static int rcu_implicit_offline_qs(struct rcu_data *rdp)
-{
-       /*
-        * If the CPU is offline for more than a jiffy, it is in a quiescent
-        * state.  We can trust its state not to change because interrupts
-        * are disabled.  The reason for the jiffy's worth of slack is to
-        * handle CPUs initializing on the way up and finding their way
-        * to the idle loop on the way down.
-        */
-       if (cpu_is_offline(rdp->cpu) &&
-           ULONG_CMP_LT(rdp->rsp->gp_start + 2, jiffies)) {
-               trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "ofl");
-               rdp->offline_fqs++;
-               return 1;
-       }
-       return 0;
-}
-
-/*
- * rcu_idle_enter_common - inform RCU that current CPU is moving towards idle
+ * rcu_eqs_enter_common - current CPU is moving towards extended quiescent state
  *
  * If the new value of the ->dynticks_nesting counter now is zero,
  * we really have entered idle, and must do the appropriate accounting.
  * The caller must have disabled interrupts.
  */
-static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
+static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
+                               bool user)
 {
        trace_rcu_dyntick("Start", oldval, 0);
-       if (!is_idle_task(current)) {
+       if (!user && !is_idle_task(current)) {
                struct task_struct *idle = idle_task(smp_processor_id());
 
                trace_rcu_dyntick("Error on entry: not idle task", oldval, 0);
@@ -378,7 +352,7 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
        WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
 
        /*
-        * The idle task is not permitted to enter the idle loop while
+        * It is illegal to enter an extended quiescent state while
         * in an RCU read-side critical section.
         */
        rcu_lockdep_assert(!lock_is_held(&rcu_lock_map),
@@ -389,6 +363,25 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
                           "Illegal idle entry in RCU-sched read-side critical section.");
 }
 
+/*
+ * Enter an RCU extended quiescent state, which can be either the
+ * idle loop or adaptive-tickless usermode execution.
+ */
+static void rcu_eqs_enter(bool user)
+{
+       long long oldval;
+       struct rcu_dynticks *rdtp;
+
+       rdtp = &__get_cpu_var(rcu_dynticks);
+       oldval = rdtp->dynticks_nesting;
+       WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
+       if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE)
+               rdtp->dynticks_nesting = 0;
+       else
+               rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
+       rcu_eqs_enter_common(rdtp, oldval, user);
+}
+
 /**
  * rcu_idle_enter - inform RCU that current CPU is entering idle
  *
@@ -404,21 +397,70 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
 void rcu_idle_enter(void)
 {
        unsigned long flags;
-       long long oldval;
+
+       local_irq_save(flags);
+       rcu_eqs_enter(false);
+       local_irq_restore(flags);
+}
+EXPORT_SYMBOL_GPL(rcu_idle_enter);
+
+#ifdef CONFIG_RCU_USER_QS
+/**
+ * rcu_user_enter - inform RCU that we are resuming userspace.
+ *
+ * Enter RCU idle mode right before resuming userspace.  No use of RCU
+ * is permitted between this call and rcu_user_exit(). This way the
+ * CPU doesn't need to maintain the tick for RCU maintenance purposes
+ * when the CPU runs in userspace.
+ */
+void rcu_user_enter(void)
+{
+       unsigned long flags;
        struct rcu_dynticks *rdtp;
 
+       /*
+        * Some contexts may involve an exception occuring in an irq,
+        * leading to that nesting:
+        * rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
+        * This would mess up the dyntick_nesting count though. And rcu_irq_*()
+        * helpers are enough to protect RCU uses inside the exception. So
+        * just return immediately if we detect we are in an IRQ.
+        */
+       if (in_interrupt())
+               return;
+
+       WARN_ON_ONCE(!current->mm);
+
        local_irq_save(flags);
        rdtp = &__get_cpu_var(rcu_dynticks);
-       oldval = rdtp->dynticks_nesting;
-       WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0);
-       if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE)
-               rdtp->dynticks_nesting = 0;
-       else
-               rdtp->dynticks_nesting -= DYNTICK_TASK_NEST_VALUE;
-       rcu_idle_enter_common(rdtp, oldval);
+       if (!rdtp->ignore_user_qs && !rdtp->in_user) {
+               rdtp->in_user = true;
+               rcu_eqs_enter(true);
+       }
        local_irq_restore(flags);
 }
-EXPORT_SYMBOL_GPL(rcu_idle_enter);
+
+/**
+ * rcu_user_enter_after_irq - inform RCU that we are going to resume userspace
+ * after the current irq returns.
+ *
+ * This is similar to rcu_user_enter() but in the context of a non-nesting
+ * irq. After this call, RCU enters into idle mode when the interrupt
+ * returns.
+ */
+void rcu_user_enter_after_irq(void)
+{
+       unsigned long flags;
+       struct rcu_dynticks *rdtp;
+
+       local_irq_save(flags);
+       rdtp = &__get_cpu_var(rcu_dynticks);
+       /* Ensure this irq is interrupting a non-idle RCU state.  */
+       WARN_ON_ONCE(!(rdtp->dynticks_nesting & DYNTICK_TASK_MASK));
+       rdtp->dynticks_nesting = 1;
+       local_irq_restore(flags);
+}
+#endif /* CONFIG_RCU_USER_QS */
 
 /**
  * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
@@ -450,18 +492,19 @@ void rcu_irq_exit(void)
        if (rdtp->dynticks_nesting)
                trace_rcu_dyntick("--=", oldval, rdtp->dynticks_nesting);
        else
-               rcu_idle_enter_common(rdtp, oldval);
+               rcu_eqs_enter_common(rdtp, oldval, true);
        local_irq_restore(flags);
 }
 
 /*
- * rcu_idle_exit_common - inform RCU that current CPU is moving away from idle
+ * rcu_eqs_exit_common - current CPU moving away from extended quiescent state
  *
  * If the new value of the ->dynticks_nesting counter was previously zero,
  * we really have exited idle, and must do the appropriate accounting.
  * The caller must have disabled interrupts.
  */
-static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
+static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
+                              int user)
 {
        smp_mb__before_atomic_inc();  /* Force ordering w/previous sojourn. */
        atomic_inc(&rdtp->dynticks);
@@ -470,7 +513,7 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
        WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
        rcu_cleanup_after_idle(smp_processor_id());
        trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
-       if (!is_idle_task(current)) {
+       if (!user && !is_idle_task(current)) {
                struct task_struct *idle = idle_task(smp_processor_id());
 
                trace_rcu_dyntick("Error on exit: not idle task",
@@ -482,6 +525,25 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
        }
 }
 
+/*
+ * Exit an RCU extended quiescent state, which can be either the
+ * idle loop or adaptive-tickless usermode execution.
+ */
+static void rcu_eqs_exit(bool user)
+{
+       struct rcu_dynticks *rdtp;
+       long long oldval;
+
+       rdtp = &__get_cpu_var(rcu_dynticks);
+       oldval = rdtp->dynticks_nesting;
+       WARN_ON_ONCE(oldval < 0);
+       if (oldval & DYNTICK_TASK_NEST_MASK)
+               rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
+       else
+               rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
+       rcu_eqs_exit_common(rdtp, oldval, user);
+}
+
 /**
  * rcu_idle_exit - inform RCU that current CPU is leaving idle
  *
@@ -494,23 +556,69 @@ static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
  * now starting.
  */
 void rcu_idle_exit(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       rcu_eqs_exit(false);
+       local_irq_restore(flags);
+}
+EXPORT_SYMBOL_GPL(rcu_idle_exit);
+
+#ifdef CONFIG_RCU_USER_QS
+/**
+ * rcu_user_exit - inform RCU that we are exiting userspace.
+ *
+ * Exit RCU idle mode while entering the kernel because it can
+ * run a RCU read side critical section anytime.
+ */
+void rcu_user_exit(void)
 {
        unsigned long flags;
        struct rcu_dynticks *rdtp;
-       long long oldval;
+
+       /*
+        * Some contexts may involve an exception occuring in an irq,
+        * leading to that nesting:
+        * rcu_irq_enter() rcu_user_exit() rcu_user_exit() rcu_irq_exit()
+        * This would mess up the dyntick_nesting count though. And rcu_irq_*()
+        * helpers are enough to protect RCU uses inside the exception. So
+        * just return immediately if we detect we are in an IRQ.
+        */
+       if (in_interrupt())
+               return;
 
        local_irq_save(flags);
        rdtp = &__get_cpu_var(rcu_dynticks);
-       oldval = rdtp->dynticks_nesting;
-       WARN_ON_ONCE(oldval < 0);
-       if (oldval & DYNTICK_TASK_NEST_MASK)
-               rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
-       else
-               rdtp->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
-       rcu_idle_exit_common(rdtp, oldval);
+       if (rdtp->in_user) {
+               rdtp->in_user = false;
+               rcu_eqs_exit(true);
+       }
        local_irq_restore(flags);
 }
-EXPORT_SYMBOL_GPL(rcu_idle_exit);
+
+/**
+ * rcu_user_exit_after_irq - inform RCU that we won't resume to userspace
+ * idle mode after the current non-nesting irq returns.
+ *
+ * This is similar to rcu_user_exit() but in the context of an irq.
+ * This is called when the irq has interrupted a userspace RCU idle mode
+ * context. When the current non-nesting interrupt returns after this call,
+ * the CPU won't restore the RCU idle mode.
+ */
+void rcu_user_exit_after_irq(void)
+{
+       unsigned long flags;
+       struct rcu_dynticks *rdtp;
+
+       local_irq_save(flags);
+       rdtp = &__get_cpu_var(rcu_dynticks);
+       /* Ensure we are interrupting an RCU idle mode. */
+       WARN_ON_ONCE(rdtp->dynticks_nesting & DYNTICK_TASK_NEST_MASK);
+       rdtp->dynticks_nesting += DYNTICK_TASK_EXIT_IDLE;
+       local_irq_restore(flags);
+}
+#endif /* CONFIG_RCU_USER_QS */
 
 /**
  * rcu_irq_enter - inform RCU that current CPU is entering irq away from idle
@@ -545,7 +653,7 @@ void rcu_irq_enter(void)
        if (oldval)
                trace_rcu_dyntick("++=", oldval, rdtp->dynticks_nesting);
        else
-               rcu_idle_exit_common(rdtp, oldval);
+               rcu_eqs_exit_common(rdtp, oldval, true);
        local_irq_restore(flags);
 }
 
@@ -609,6 +717,21 @@ int rcu_is_cpu_idle(void)
 }
 EXPORT_SYMBOL(rcu_is_cpu_idle);
 
+#ifdef CONFIG_RCU_USER_QS
+void rcu_user_hooks_switch(struct task_struct *prev,
+                          struct task_struct *next)
+{
+       struct rcu_dynticks *rdtp;
+
+       /* Interrupts are disabled in context switch */
+       rdtp = &__get_cpu_var(rcu_dynticks);
+       if (!rdtp->ignore_user_qs) {
+               clear_tsk_thread_flag(prev, TIF_NOHZ);
+               set_tsk_thread_flag(next, TIF_NOHZ);
+       }
+}
+#endif /* #ifdef CONFIG_RCU_USER_QS */
+
 #if defined(CONFIG_PROVE_RCU) && defined(CONFIG_HOTPLUG_CPU)
 
 /*
@@ -679,7 +802,7 @@ static int dyntick_save_progress_counter(struct rcu_data *rdp)
  * Return true if the specified CPU has passed through a quiescent
  * state by virtue of being in or having passed through an dynticks
  * idle state since the last call to dyntick_save_progress_counter()
- * for this same CPU.
+ * for this same CPU, or by virtue of having been offline.
  */
 static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
 {
@@ -703,8 +826,26 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
                return 1;
        }
 
-       /* Go check for the CPU being offline. */
-       return rcu_implicit_offline_qs(rdp);
+       /*
+        * Check for the CPU being offline, but only if the grace period
+        * is old enough.  We don't need to worry about the CPU changing
+        * state: If we see it offline even once, it has been through a
+        * quiescent state.
+        *
+        * The reason for insisting that the grace period be at least
+        * one jiffy old is that CPUs that are not quite online and that
+        * have just gone offline can still execute RCU read-side critical
+        * sections.
+        */
+       if (ULONG_CMP_GE(rdp->rsp->gp_start + 2, jiffies))
+               return 0;  /* Grace period is not old enough. */
+       barrier();
+       if (cpu_is_offline(rdp->cpu)) {
+               trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, "ofl");
+               rdp->offline_fqs++;
+               return 1;
+       }
+       return 0;
 }
 
 static int jiffies_till_stall_check(void)
@@ -761,14 +902,15 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
        rcu_for_each_leaf_node(rsp, rnp) {
                raw_spin_lock_irqsave(&rnp->lock, flags);
                ndetected += rcu_print_task_stall(rnp);
+               if (rnp->qsmask != 0) {
+                       for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
+                               if (rnp->qsmask & (1UL << cpu)) {
+                                       print_cpu_stall_info(rsp,
+                                                            rnp->grplo + cpu);
+                                       ndetected++;
+                               }
+               }
                raw_spin_unlock_irqrestore(&rnp->lock, flags);
-               if (rnp->qsmask == 0)
-                       continue;
-               for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
-                       if (rnp->qsmask & (1UL << cpu)) {
-                               print_cpu_stall_info(rsp, rnp->grplo + cpu);
-                               ndetected++;
-                       }
        }
 
        /*
@@ -833,7 +975,8 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
        j = ACCESS_ONCE(jiffies);
        js = ACCESS_ONCE(rsp->jiffies_stall);
        rnp = rdp->mynode;
-       if ((ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) {
+       if (rcu_gp_in_progress(rsp) &&
+           (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask) && ULONG_CMP_GE(j, js)) {
 
                /* We haven't checked in, so go dump stack. */
                print_cpu_stall(rsp);
@@ -1486,17 +1629,6 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
        int i;
        struct rcu_data *rdp = __this_cpu_ptr(rsp->rda);
 
-       /*
-        * If there is an rcu_barrier() operation in progress, then
-        * only the task doing that operation is permitted to adopt
-        * callbacks.  To do otherwise breaks rcu_barrier() and friends
-        * by causing them to fail to wait for the callbacks in the
-        * orphanage.
-        */
-       if (rsp->rcu_barrier_in_progress &&
-           rsp->rcu_barrier_in_progress != current)
-               return;
-
        /* Do the accounting first. */
        rdp->qlen_lazy += rsp->qlen_lazy;
        rdp->qlen += rsp->qlen;
@@ -1551,9 +1683,8 @@ static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
  * The CPU has been completely removed, and some other CPU is reporting
  * this fact from process context.  Do the remainder of the cleanup,
  * including orphaning the outgoing CPU's RCU callbacks, and also
- * adopting them, if there is no _rcu_barrier() instance running.
- * There can only be one CPU hotplug operation at a time, so no other
- * CPU can be attempting to update rcu_cpu_kthread_task.
+ * adopting them.  There can only be one CPU hotplug operation at a time,
+ * so no other CPU can be attempting to update rcu_cpu_kthread_task.
  */
 static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
 {
@@ -1564,8 +1695,7 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
        struct rcu_node *rnp = rdp->mynode;  /* Outgoing CPU's rdp & rnp. */
 
        /* Adjust any no-longer-needed kthreads. */
-       rcu_stop_cpu_kthread(cpu);
-       rcu_node_kthread_setaffinity(rnp, -1);
+       rcu_boost_kthread_setaffinity(rnp, -1);
 
        /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
 
@@ -1611,14 +1741,13 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
        WARN_ONCE(rdp->qlen != 0 || rdp->nxtlist != NULL,
                  "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, nxtlist=%p\n",
                  cpu, rdp->qlen, rdp->nxtlist);
+       init_callback_list(rdp);
+       /* Disallow further callbacks on this CPU. */
+       rdp->nxttail[RCU_NEXT_TAIL] = NULL;
 }
 
 #else /* #ifdef CONFIG_HOTPLUG_CPU */
 
-static void rcu_adopt_orphan_cbs(struct rcu_state *rsp)
-{
-}
-
 static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
 {
 }
@@ -1987,8 +2116,6 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
        head->func = func;
        head->next = NULL;
 
-       smp_mb(); /* Ensure RCU update seen before callback registry. */
-
        /*
         * Opportunistically note grace-period endings and beginnings.
         * Note that we might see a beginning right after we see an
@@ -1999,6 +2126,12 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
        rdp = this_cpu_ptr(rsp->rda);
 
        /* Add the callback to our list. */
+       if (unlikely(rdp->nxttail[RCU_NEXT_TAIL] == NULL)) {
+               /* _call_rcu() is illegal on offline CPU; leak the callback. */
+               WARN_ON_ONCE(1);
+               local_irq_restore(flags);
+               return;
+       }
        ACCESS_ONCE(rdp->qlen)++;
        if (lazy)
                rdp->qlen_lazy++;
@@ -2367,13 +2500,10 @@ static void rcu_barrier_func(void *type)
 static void _rcu_barrier(struct rcu_state *rsp)
 {
        int cpu;
-       unsigned long flags;
        struct rcu_data *rdp;
-       struct rcu_data rd;
        unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done);
        unsigned long snap_done;
 
-       init_rcu_head_on_stack(&rd.barrier_head);
        _rcu_barrier_trace(rsp, "Begin", -1, snap);
 
        /* Take mutex to serialize concurrent rcu_barrier() requests. */
@@ -2413,70 +2543,30 @@ static void _rcu_barrier(struct rcu_state *rsp)
        /*
         * Initialize the count to one rather than to zero in order to
         * avoid a too-soon return to zero in case of a short grace period
-        * (or preemption of this task).  Also flag this task as doing
-        * an rcu_barrier().  This will prevent anyone else from adopting
-        * orphaned callbacks, which could cause otherwise failure if a
-        * CPU went offline and quickly came back online.  To see this,
-        * consider the following sequence of events:
-        *
-        * 1.   We cause CPU 0 to post an rcu_barrier_callback() callback.
-        * 2.   CPU 1 goes offline, orphaning its callbacks.
-        * 3.   CPU 0 adopts CPU 1's orphaned callbacks.
-        * 4.   CPU 1 comes back online.
-        * 5.   We cause CPU 1 to post an rcu_barrier_callback() callback.
-        * 6.   Both rcu_barrier_callback() callbacks are invoked, awakening
-        *      us -- but before CPU 1's orphaned callbacks are invoked!!!
+        * (or preemption of this task).  Exclude CPU-hotplug operations
+        * to ensure that no offline CPU has callbacks queued.
         */
        init_completion(&rsp->barrier_completion);
        atomic_set(&rsp->barrier_cpu_count, 1);
-       raw_spin_lock_irqsave(&rsp->onofflock, flags);
-       rsp->rcu_barrier_in_progress = current;
-       raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
+       get_online_cpus();
 
        /*
-        * Force every CPU with callbacks to register a new callback
-        * that will tell us when all the preceding callbacks have
-        * been invoked.  If an offline CPU has callbacks, wait for
-        * it to either come back online or to finish orphaning those
-        * callbacks.
+        * Force each CPU with callbacks to register a new callback.
+        * When that callback is invoked, we will know that all of the
+        * corresponding CPU's preceding callbacks have been invoked.
         */
-       for_each_possible_cpu(cpu) {
-               preempt_disable();
+       for_each_online_cpu(cpu) {
                rdp = per_cpu_ptr(rsp->rda, cpu);
-               if (cpu_is_offline(cpu)) {
-                       _rcu_barrier_trace(rsp, "Offline", cpu,
-                                          rsp->n_barrier_done);
-                       preempt_enable();
-                       while (cpu_is_offline(cpu) && ACCESS_ONCE(rdp->qlen))
-                               schedule_timeout_interruptible(1);
-               } else if (ACCESS_ONCE(rdp->qlen)) {
+               if (ACCESS_ONCE(rdp->qlen)) {
                        _rcu_barrier_trace(rsp, "OnlineQ", cpu,
                                           rsp->n_barrier_done);
                        smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
-                       preempt_enable();
                } else {
                        _rcu_barrier_trace(rsp, "OnlineNQ", cpu,
                                           rsp->n_barrier_done);
-                       preempt_enable();
                }
        }
-
-       /*
-        * Now that all online CPUs have rcu_barrier_callback() callbacks
-        * posted, we can adopt all of the orphaned callbacks and place
-        * an rcu_barrier_callback() callback after them.  When that is done,
-        * we are guaranteed to have an rcu_barrier_callback() callback
-        * following every callback that could possibly have been
-        * registered before _rcu_barrier() was called.
-        */
-       raw_spin_lock_irqsave(&rsp->onofflock, flags);
-       rcu_adopt_orphan_cbs(rsp);
-       rsp->rcu_barrier_in_progress = NULL;
-       raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
-       atomic_inc(&rsp->barrier_cpu_count);
-       smp_mb__after_atomic_inc(); /* Ensure atomic_inc() before callback. */
-       rd.rsp = rsp;
-       rsp->call(&rd.barrier_head, rcu_barrier_callback);
+       put_online_cpus();
 
        /*
         * Now that we have an rcu_barrier_callback() callback on each
@@ -2497,8 +2587,6 @@ static void _rcu_barrier(struct rcu_state *rsp)
 
        /* Other rcu_barrier() invocations can now safely proceed. */
        mutex_unlock(&rsp->barrier_mutex);
-
-       destroy_rcu_head_on_stack(&rd.barrier_head);
 }
 
 /**
@@ -2538,6 +2626,9 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
        rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
        WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
        WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
+#ifdef CONFIG_RCU_USER_QS
+       WARN_ON_ONCE(rdp->dynticks->in_user);
+#endif
        rdp->cpu = cpu;
        rdp->rsp = rsp;
        raw_spin_unlock_irqrestore(&rnp->lock, flags);
@@ -2564,6 +2655,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
        rdp->qlen_last_fqs_check = 0;
        rdp->n_force_qs_snap = rsp->n_force_qs;
        rdp->blimit = blimit;
+       init_callback_list(rdp);  /* Re-enable callbacks on this CPU. */
        rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
        atomic_set(&rdp->dynticks->dynticks,
                   (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
@@ -2634,12 +2726,10 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
                break;
        case CPU_ONLINE:
        case CPU_DOWN_FAILED:
-               rcu_node_kthread_setaffinity(rnp, -1);
-               rcu_cpu_kthread_setrt(cpu, 1);
+               rcu_boost_kthread_setaffinity(rnp, -1);
                break;
        case CPU_DOWN_PREPARE:
-               rcu_node_kthread_setaffinity(rnp, cpu);
-               rcu_cpu_kthread_setrt(cpu, 0);
+               rcu_boost_kthread_setaffinity(rnp, cpu);
                break;
        case CPU_DYING:
        case CPU_DYING_FROZEN:
@@ -2723,7 +2813,7 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp)
        int cprv;
        int i;
 
-       cprv = NR_CPUS;
+       cprv = nr_cpu_ids;
        for (i = rcu_num_lvls - 1; i >= 0; i--) {
                ccur = rsp->levelcnt[i];
                rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
@@ -2821,7 +2911,8 @@ static void __init rcu_init_geometry(void)
        int rcu_capacity[MAX_RCU_LVLS + 1];
 
        /* If the compile-time values are accurate, just leave. */
-       if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF)
+       if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF &&
+           nr_cpu_ids == NR_CPUS)
                return;
 
        /*