* that don't support NMI-based stack dumps.  The NMI-triggered stack
  * traces are more accurate because they are printed by the target CPU.
  */
-static void rcu_dump_cpu_stacks(void)
+static void rcu_dump_cpu_stacks(unsigned long gp_seq)
 {
        int cpu;
        unsigned long flags;
        struct rcu_node *rnp;
 
        rcu_for_each_leaf_node(rnp) {
+               if (gp_seq != data_race(rcu_state.gp_seq)) {
+                       pr_err("INFO: Stall ended during stack backtracing.\n");
+                       return;
+               }
                printk_deferred_enter();
                raw_spin_lock_irqsave_rcu_node(rnp, flags);
                for_each_leaf_node_possible_cpu(rnp, cpu)
               (long)rcu_seq_current(&rcu_state.gp_seq), totqlen,
               data_race(rcu_state.n_online_cpus)); // Diagnostic read
        if (ndetected) {
-               rcu_dump_cpu_stacks();
+               rcu_dump_cpu_stacks(gp_seq);
 
                /* Complain about tasks blocking the grace period. */
                rcu_for_each_leaf_node(rnp)
        rcu_force_quiescent_state();  /* Kick them all. */
 }
 
-static void print_cpu_stall(unsigned long gps)
+static void print_cpu_stall(unsigned long gp_seq, unsigned long gps)
 {
        int cpu;
        unsigned long flags;
        rcu_check_gp_kthread_expired_fqs_timer();
        rcu_check_gp_kthread_starvation();
 
-       rcu_dump_cpu_stacks();
+       rcu_dump_cpu_stacks(gp_seq);
 
        raw_spin_lock_irqsave_rcu_node(rnp, flags);
        /* Rewrite if needed in case of slow consoles. */
        gs2 = READ_ONCE(rcu_state.gp_seq);
        if (gs1 != gs2 ||
            ULONG_CMP_LT(j, js) ||
-           ULONG_CMP_GE(gps, js))
+           ULONG_CMP_GE(gps, js) ||
+           !rcu_seq_state(gs2))
                return; /* No stall or GP completed since entering function. */
        rnp = rdp->mynode;
        jn = jiffies + ULONG_MAX / 2;
                        pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);
                } else if (self_detected) {
                        /* We haven't checked in, so go dump stack. */
-                       print_cpu_stall(gps);
+                       print_cpu_stall(gs2, gps);
                } else {
                        /* They had a few time units to dump stack, so complain. */
                        print_other_cpu_stall(gs2, gps);