aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcu/tree.c
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2018-04-21 23:44:11 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2018-07-12 17:24:42 -0400
commit26d950a9451336a6b5abc1c8ca6c21df58e8d89f (patch)
treef68a88af62c5dda366ccc760afd57b223f8d5b1a /kernel/rcu/tree.c
parent8c42b1f39fdf9fde7cfc4024397255f31a860db6 (diff)
rcu: Diagnostics for grace-period startup hangs
This commit causes a splat if RCU is idle and a request for a new grace period is ignored for more than one second. This splat normally indicates that some code path asked for a new grace period, but failed to wake up the RCU grace-period kthread. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> [ paulmck: Fix bug located by Dan Carpenter and his static checker. ] [ paulmck: Fix self-deadlock bug located 0day test robot. ] [ paulmck: Disable unless CONFIG_PROVE_RCU=y. ]
Diffstat (limited to 'kernel/rcu/tree.c')
-rw-r--r--kernel/rcu/tree.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index b1fffa21b9e4..6ce82c009195 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1681,6 +1681,7 @@ static bool rcu_start_this_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1681 } 1681 }
1682 trace_rcu_this_gp(rnp_root, rdp, c, TPS("Startedroot")); 1682 trace_rcu_this_gp(rnp_root, rdp, c, TPS("Startedroot"));
1683 WRITE_ONCE(rsp->gp_flags, rsp->gp_flags | RCU_GP_FLAG_INIT); 1683 WRITE_ONCE(rsp->gp_flags, rsp->gp_flags | RCU_GP_FLAG_INIT);
1684 rsp->gp_req_activity = jiffies;
1684 if (!rsp->gp_kthread) { 1685 if (!rsp->gp_kthread) {
1685 trace_rcu_this_gp(rnp_root, rdp, c, TPS("NoGPkthread")); 1686 trace_rcu_this_gp(rnp_root, rdp, c, TPS("NoGPkthread"));
1686 goto unlock_out; 1687 goto unlock_out;
@@ -2113,6 +2114,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
2113 /* Advance CBs to reduce false positives below. */ 2114 /* Advance CBs to reduce false positives below. */
2114 if (!rcu_accelerate_cbs(rsp, rnp, rdp) && needgp) { 2115 if (!rcu_accelerate_cbs(rsp, rnp, rdp) && needgp) {
2115 WRITE_ONCE(rsp->gp_flags, RCU_GP_FLAG_INIT); 2116 WRITE_ONCE(rsp->gp_flags, RCU_GP_FLAG_INIT);
2117 rsp->gp_req_activity = jiffies;
2116 trace_rcu_grace_period(rsp->name, READ_ONCE(rsp->gpnum), 2118 trace_rcu_grace_period(rsp->name, READ_ONCE(rsp->gpnum),
2117 TPS("newreq")); 2119 TPS("newreq"));
2118 } 2120 }
@@ -2745,6 +2747,65 @@ static void force_quiescent_state(struct rcu_state *rsp)
2745} 2747}
2746 2748
2747/* 2749/*
2750 * This function checks for grace-period requests that fail to motivate
2751 * RCU to come out of its idle mode.
2752 */
2753static void
2754rcu_check_gp_start_stall(struct rcu_state *rsp, struct rcu_node *rnp,
2755 struct rcu_data *rdp)
2756{
2757 unsigned long flags;
2758 unsigned long j;
2759 struct rcu_node *rnp_root = rcu_get_root(rsp);
2760 static atomic_t warned = ATOMIC_INIT(0);
2761
2762 if (!IS_ENABLED(CONFIG_PROVE_RCU) ||
2763 rcu_gp_in_progress(rsp) || !need_any_future_gp(rcu_get_root(rsp)))
2764 return;
2765 j = jiffies; /* Expensive access, and in common case don't get here. */
2766 if (time_before(j, READ_ONCE(rsp->gp_req_activity) + HZ) ||
2767 time_before(j, READ_ONCE(rsp->gp_activity) + HZ) ||
2768 atomic_read(&warned))
2769 return;
2770
2771 raw_spin_lock_irqsave_rcu_node(rnp, flags);
2772 j = jiffies;
2773 if (rcu_gp_in_progress(rsp) || !need_any_future_gp(rcu_get_root(rsp)) ||
2774 time_before(j, READ_ONCE(rsp->gp_req_activity) + HZ) ||
2775 time_before(j, READ_ONCE(rsp->gp_activity) + HZ) ||
2776 atomic_read(&warned)) {
2777 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
2778 return;
2779 }
2780 /* Hold onto the leaf lock to make others see warned==1. */
2781
2782 if (rnp_root != rnp)
2783 raw_spin_lock_rcu_node(rnp_root); /* irqs already disabled. */
2784 j = jiffies;
2785 if (rcu_gp_in_progress(rsp) || !need_any_future_gp(rcu_get_root(rsp)) ||
2786 time_before(j, rsp->gp_req_activity + HZ) ||
2787 time_before(j, rsp->gp_activity + HZ) ||
2788 atomic_xchg(&warned, 1)) {
2789 raw_spin_unlock_rcu_node(rnp_root); /* irqs remain disabled. */
2790 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
2791 return;
2792 }
2793 pr_alert("%s: g%lu %d%d%d%d gar:%lu ga:%lu f%#x %s->state:%#lx\n",
2794 __func__, READ_ONCE(rsp->gpnum),
2795 need_future_gp_element(rcu_get_root(rsp), 0),
2796 need_future_gp_element(rcu_get_root(rsp), 1),
2797 need_future_gp_element(rcu_get_root(rsp), 2),
2798 need_future_gp_element(rcu_get_root(rsp), 3),
2799 j - rsp->gp_req_activity, j - rsp->gp_activity,
2800 rsp->gp_flags, rsp->name,
2801 rsp->gp_kthread ? rsp->gp_kthread->state : 0x1ffffL);
2802 WARN_ON(1);
2803 if (rnp_root != rnp)
2804 raw_spin_unlock_rcu_node(rnp_root);
2805 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
2806}
2807
2808/*
2748 * This does the RCU core processing work for the specified rcu_state 2809 * This does the RCU core processing work for the specified rcu_state
2749 * and rcu_data structures. This may be called only from the CPU to 2810 * and rcu_data structures. This may be called only from the CPU to
2750 * whom the rdp belongs. 2811 * whom the rdp belongs.
@@ -2755,7 +2816,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
2755 unsigned long flags; 2816 unsigned long flags;
2756 bool needwake; 2817 bool needwake;
2757 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda); 2818 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
2758 struct rcu_node *rnp; 2819 struct rcu_node *rnp = rdp->mynode;
2759 2820
2760 WARN_ON_ONCE(!rdp->beenonline); 2821 WARN_ON_ONCE(!rdp->beenonline);
2761 2822
@@ -2769,7 +2830,6 @@ __rcu_process_callbacks(struct rcu_state *rsp)
2769 if (rcu_segcblist_restempty(&rdp->cblist, RCU_NEXT_READY_TAIL)) { 2830 if (rcu_segcblist_restempty(&rdp->cblist, RCU_NEXT_READY_TAIL)) {
2770 local_irq_restore(flags); 2831 local_irq_restore(flags);
2771 } else { 2832 } else {
2772 rnp = rdp->mynode;
2773 raw_spin_lock_rcu_node(rnp); /* irqs disabled. */ 2833 raw_spin_lock_rcu_node(rnp); /* irqs disabled. */
2774 needwake = rcu_accelerate_cbs(rsp, rnp, rdp); 2834 needwake = rcu_accelerate_cbs(rsp, rnp, rdp);
2775 raw_spin_unlock_irqrestore_rcu_node(rnp, flags); 2835 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
@@ -2778,6 +2838,8 @@ __rcu_process_callbacks(struct rcu_state *rsp)
2778 } 2838 }
2779 } 2839 }
2780 2840
2841 rcu_check_gp_start_stall(rsp, rnp, rdp);
2842
2781 /* If there are callbacks ready, invoke them. */ 2843 /* If there are callbacks ready, invoke them. */
2782 if (rcu_segcblist_ready_cbs(&rdp->cblist)) 2844 if (rcu_segcblist_ready_cbs(&rdp->cblist))
2783 invoke_rcu_callbacks(rsp, rdp); 2845 invoke_rcu_callbacks(rsp, rdp);