aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcu/tree.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2017-08-15 04:08:51 -0400
committerIngo Molnar <mingo@kernel.org>2017-08-15 04:08:51 -0400
commitd5da6457bfadf64ff78f1816ae8329dbbba19513 (patch)
tree3f4e1ab3a4de182e3938394b40d16c57df63f7a0 /kernel/rcu/tree.c
parentef954844c7ace62f773f4f23e28d2d915adc419f (diff)
parenta58163d8ca2c8d288ee9f95989712f98473a5ac2 (diff)
Merge branch 'for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into core/rcu
Pull RCU fix from Paul McKenney: " This pull request is for an RCU change that permits waiting for grace periods started by CPUs late in the process of going offline. Lack of this capability is causing failures: http://lkml.kernel.org/r/db9c91f6-1b17-6136-84f0-03c3c2581ab4@codeaurora.org" Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/rcu/tree.c')
-rw-r--r--kernel/rcu/tree.c209
1 files changed, 113 insertions, 96 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 51d4c3acf32d..9bb5dff50815 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2563,85 +2563,6 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
2563} 2563}
2564 2564
2565/* 2565/*
2566 * Send the specified CPU's RCU callbacks to the orphanage. The
2567 * specified CPU must be offline, and the caller must hold the
2568 * ->orphan_lock.
2569 */
2570static void
2571rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
2572 struct rcu_node *rnp, struct rcu_data *rdp)
2573{
2574 lockdep_assert_held(&rsp->orphan_lock);
2575
2576 /* No-CBs CPUs do not have orphanable callbacks. */
2577 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) || rcu_is_nocb_cpu(rdp->cpu))
2578 return;
2579
2580 /*
2581 * Orphan the callbacks. First adjust the counts. This is safe
2582 * because _rcu_barrier() excludes CPU-hotplug operations, so it
2583 * cannot be running now. Thus no memory barrier is required.
2584 */
2585 rdp->n_cbs_orphaned += rcu_segcblist_n_cbs(&rdp->cblist);
2586 rcu_segcblist_extract_count(&rdp->cblist, &rsp->orphan_done);
2587
2588 /*
2589 * Next, move those callbacks still needing a grace period to
2590 * the orphanage, where some other CPU will pick them up.
2591 * Some of the callbacks might have gone partway through a grace
2592 * period, but that is too bad. They get to start over because we
2593 * cannot assume that grace periods are synchronized across CPUs.
2594 */
2595 rcu_segcblist_extract_pend_cbs(&rdp->cblist, &rsp->orphan_pend);
2596
2597 /*
2598 * Then move the ready-to-invoke callbacks to the orphanage,
2599 * where some other CPU will pick them up. These will not be
2600 * required to pass though another grace period: They are done.
2601 */
2602 rcu_segcblist_extract_done_cbs(&rdp->cblist, &rsp->orphan_done);
2603
2604 /* Finally, disallow further callbacks on this CPU. */
2605 rcu_segcblist_disable(&rdp->cblist);
2606}
2607
2608/*
2609 * Adopt the RCU callbacks from the specified rcu_state structure's
2610 * orphanage. The caller must hold the ->orphan_lock.
2611 */
2612static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)
2613{
2614 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
2615
2616 lockdep_assert_held(&rsp->orphan_lock);
2617
2618 /* No-CBs CPUs are handled specially. */
2619 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) ||
2620 rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags))
2621 return;
2622
2623 /* Do the accounting first. */
2624 rdp->n_cbs_adopted += rsp->orphan_done.len;
2625 if (rsp->orphan_done.len_lazy != rsp->orphan_done.len)
2626 rcu_idle_count_callbacks_posted();
2627 rcu_segcblist_insert_count(&rdp->cblist, &rsp->orphan_done);
2628
2629 /*
2630 * We do not need a memory barrier here because the only way we
2631 * can get here if there is an rcu_barrier() in flight is if
2632 * we are the task doing the rcu_barrier().
2633 */
2634
2635 /* First adopt the ready-to-invoke callbacks, then the done ones. */
2636 rcu_segcblist_insert_done_cbs(&rdp->cblist, &rsp->orphan_done);
2637 WARN_ON_ONCE(rsp->orphan_done.head);
2638 rcu_segcblist_insert_pend_cbs(&rdp->cblist, &rsp->orphan_pend);
2639 WARN_ON_ONCE(rsp->orphan_pend.head);
2640 WARN_ON_ONCE(rcu_segcblist_empty(&rdp->cblist) !=
2641 !rcu_segcblist_n_cbs(&rdp->cblist));
2642}
2643
2644/*
2645 * Trace the fact that this CPU is going offline. 2566 * Trace the fact that this CPU is going offline.
2646 */ 2567 */
2647static void rcu_cleanup_dying_cpu(struct rcu_state *rsp) 2568static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
@@ -2704,14 +2625,12 @@ static void rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
2704 2625
2705/* 2626/*
2706 * The CPU has been completely removed, and some other CPU is reporting 2627 * The CPU has been completely removed, and some other CPU is reporting
2707 * this fact from process context. Do the remainder of the cleanup, 2628 * this fact from process context. Do the remainder of the cleanup.
2708 * including orphaning the outgoing CPU's RCU callbacks, and also 2629 * There can only be one CPU hotplug operation at a time, so no need for
2709 * adopting them. There can only be one CPU hotplug operation at a time, 2630 * explicit locking.
2710 * so no other CPU can be attempting to update rcu_cpu_kthread_task.
2711 */ 2631 */
2712static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp) 2632static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2713{ 2633{
2714 unsigned long flags;
2715 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); 2634 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2716 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */ 2635 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
2717 2636
@@ -2720,18 +2639,6 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2720 2639
2721 /* Adjust any no-longer-needed kthreads. */ 2640 /* Adjust any no-longer-needed kthreads. */
2722 rcu_boost_kthread_setaffinity(rnp, -1); 2641 rcu_boost_kthread_setaffinity(rnp, -1);
2723
2724 /* Orphan the dead CPU's callbacks, and adopt them if appropriate. */
2725 raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
2726 rcu_send_cbs_to_orphanage(cpu, rsp, rnp, rdp);
2727 rcu_adopt_orphan_cbs(rsp, flags);
2728 raw_spin_unlock_irqrestore(&rsp->orphan_lock, flags);
2729
2730 WARN_ONCE(rcu_segcblist_n_cbs(&rdp->cblist) != 0 ||
2731 !rcu_segcblist_empty(&rdp->cblist),
2732 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, 1stCB=%p\n",
2733 cpu, rcu_segcblist_n_cbs(&rdp->cblist),
2734 rcu_segcblist_first_cb(&rdp->cblist));
2735} 2642}
2736 2643
2737/* 2644/*
@@ -3937,6 +3844,116 @@ void rcu_report_dead(unsigned int cpu)
3937 for_each_rcu_flavor(rsp) 3844 for_each_rcu_flavor(rsp)
3938 rcu_cleanup_dying_idle_cpu(cpu, rsp); 3845 rcu_cleanup_dying_idle_cpu(cpu, rsp);
3939} 3846}
3847
3848/*
3849 * Send the specified CPU's RCU callbacks to the orphanage. The
3850 * specified CPU must be offline, and the caller must hold the
3851 * ->orphan_lock.
3852 */
3853static void
3854rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
3855 struct rcu_node *rnp, struct rcu_data *rdp)
3856{
3857 lockdep_assert_held(&rsp->orphan_lock);
3858
3859 /* No-CBs CPUs do not have orphanable callbacks. */
3860 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) || rcu_is_nocb_cpu(rdp->cpu))
3861 return;
3862
3863 /*
3864 * Orphan the callbacks. First adjust the counts. This is safe
3865 * because _rcu_barrier() excludes CPU-hotplug operations, so it
3866 * cannot be running now. Thus no memory barrier is required.
3867 */
3868 rdp->n_cbs_orphaned += rcu_segcblist_n_cbs(&rdp->cblist);
3869 rcu_segcblist_extract_count(&rdp->cblist, &rsp->orphan_done);
3870
3871 /*
3872 * Next, move those callbacks still needing a grace period to
3873 * the orphanage, where some other CPU will pick them up.
3874 * Some of the callbacks might have gone partway through a grace
3875 * period, but that is too bad. They get to start over because we
3876 * cannot assume that grace periods are synchronized across CPUs.
3877 */
3878 rcu_segcblist_extract_pend_cbs(&rdp->cblist, &rsp->orphan_pend);
3879
3880 /*
3881 * Then move the ready-to-invoke callbacks to the orphanage,
3882 * where some other CPU will pick them up. These will not be
3883 * required to pass though another grace period: They are done.
3884 */
3885 rcu_segcblist_extract_done_cbs(&rdp->cblist, &rsp->orphan_done);
3886
3887 /* Finally, disallow further callbacks on this CPU. */
3888 rcu_segcblist_disable(&rdp->cblist);
3889}
3890
3891/*
3892 * Adopt the RCU callbacks from the specified rcu_state structure's
3893 * orphanage. The caller must hold the ->orphan_lock.
3894 */
3895static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)
3896{
3897 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
3898
3899 lockdep_assert_held(&rsp->orphan_lock);
3900
3901 /* No-CBs CPUs are handled specially. */
3902 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) ||
3903 rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags))
3904 return;
3905
3906 /* Do the accounting first. */
3907 rdp->n_cbs_adopted += rsp->orphan_done.len;
3908 if (rsp->orphan_done.len_lazy != rsp->orphan_done.len)
3909 rcu_idle_count_callbacks_posted();
3910 rcu_segcblist_insert_count(&rdp->cblist, &rsp->orphan_done);
3911
3912 /*
3913 * We do not need a memory barrier here because the only way we
3914 * can get here if there is an rcu_barrier() in flight is if
3915 * we are the task doing the rcu_barrier().
3916 */
3917
3918 /* First adopt the ready-to-invoke callbacks, then the done ones. */
3919 rcu_segcblist_insert_done_cbs(&rdp->cblist, &rsp->orphan_done);
3920 WARN_ON_ONCE(rsp->orphan_done.head);
3921 rcu_segcblist_insert_pend_cbs(&rdp->cblist, &rsp->orphan_pend);
3922 WARN_ON_ONCE(rsp->orphan_pend.head);
3923 WARN_ON_ONCE(rcu_segcblist_empty(&rdp->cblist) !=
3924 !rcu_segcblist_n_cbs(&rdp->cblist));
3925}
3926
3927/* Orphan the dead CPU's callbacks, and then adopt them. */
3928static void rcu_migrate_callbacks(int cpu, struct rcu_state *rsp)
3929{
3930 unsigned long flags;
3931 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
3932 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
3933
3934 raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
3935 rcu_send_cbs_to_orphanage(cpu, rsp, rnp, rdp);
3936 rcu_adopt_orphan_cbs(rsp, flags);
3937 raw_spin_unlock_irqrestore(&rsp->orphan_lock, flags);
3938 WARN_ONCE(rcu_segcblist_n_cbs(&rdp->cblist) != 0 ||
3939 !rcu_segcblist_empty(&rdp->cblist),
3940 "rcu_cleanup_dead_cpu: Callbacks on offline CPU %d: qlen=%lu, 1stCB=%p\n",
3941 cpu, rcu_segcblist_n_cbs(&rdp->cblist),
3942 rcu_segcblist_first_cb(&rdp->cblist));
3943}
3944
3945/*
3946 * The outgoing CPU has just passed through the dying-idle state,
3947 * and we are being invoked from the CPU that was IPIed to continue the
3948 * offline operation. We need to migrate the outgoing CPU's callbacks.
3949 */
3950void rcutree_migrate_callbacks(int cpu)
3951{
3952 struct rcu_state *rsp;
3953
3954 for_each_rcu_flavor(rsp)
3955 rcu_migrate_callbacks(cpu, rsp);
3956}
3940#endif 3957#endif
3941 3958
3942/* 3959/*