From: John Ogness <john.ogness@linutronix.de>
Date: Mon, 11 Sep 2023 15:53:39 +0000
Subject: [PATCH 31/48] rcu: Mark emergency sections in rcu stalls

Mark emergency sections wherever multiple lines of
rcu stall information are generated. In an emergency
section the CPU will not perform console output for the
printk() calls. Instead, a flushing of the console
output is triggered when exiting the emergency section.
This allows the full message block to be stored as
quickly as possible in the ringbuffer.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/rcu/tree_exp.h   |    7 +++++++
 kernel/rcu/tree_stall.h |    9 +++++++++
 2 files changed, 16 insertions(+)

Index: linux-6.8.2-rt10/kernel/rcu/tree_exp.h
===================================================================
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:10 @
  * Authors: Paul E. McKenney <paulmck@linux.ibm.com>
  */
 
+#include <linux/console.h>
 #include <linux/lockdep.h>
 
 static void rcu_exp_handler(void *unused);
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:640 @ static void synchronize_rcu_expedited_wa
 			return;
 		if (rcu_stall_is_suppressed())
 			continue;
+
+		nbcon_cpu_emergency_enter();
+
 		j = jiffies;
 		rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_EXP, (void *)(j - jiffies_start));
 		trace_rcu_stall_warning(rcu_state.name, TPS("ExpeditedStall"));
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:696 @ static void synchronize_rcu_expedited_wa
 			rcu_exp_print_detail_task_stall_rnp(rnp);
 		}
 		jiffies_stall = 3 * rcu_exp_jiffies_till_stall_check() + 3;
+
+		nbcon_cpu_emergency_exit();
+
 		panic_on_rcu_stall();
 	}
 }
Index: linux-6.8.2-rt10/kernel/rcu/tree_stall.h
===================================================================
--- linux-6.8.2-rt10.orig/kernel/rcu/tree_stall.h
+++ linux-6.8.2-rt10/kernel/rcu/tree_stall.h
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:10 @
  * Author: Paul E. McKenney <paulmck@linux.ibm.com>
  */
 
+#include <linux/console.h>
 #include <linux/kvm_para.h>
 #include <linux/rcu_notifier.h>
 
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:608 @ static void print_other_cpu_stall(unsign
 	if (rcu_stall_is_suppressed())
 		return;
 
+	nbcon_cpu_emergency_enter();
+
 	/*
 	 * OK, time to rat on our buddy...
 	 * See Documentation/RCU/stallwarn.rst for info on how to debug
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:661 @ static void print_other_cpu_stall(unsign
 	rcu_check_gp_kthread_expired_fqs_timer();
 	rcu_check_gp_kthread_starvation();
 
+	nbcon_cpu_emergency_exit();
+
 	panic_on_rcu_stall();
 
 	rcu_force_quiescent_state();  /* Kick them all. */
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:683 @ static void print_cpu_stall(unsigned lon
 	if (rcu_stall_is_suppressed())
 		return;
 
+	nbcon_cpu_emergency_enter();
+
 	/*
 	 * OK, time to rat on ourselves...
 	 * See Documentation/RCU/stallwarn.rst for info on how to debug
@ linux-6.8.2-rt10/kernel/rcu/tree_exp.h:713 @ static void print_cpu_stall(unsigned lon
 			   jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 
+	nbcon_cpu_emergency_exit();
+
 	panic_on_rcu_stall();
 
 	/*