[PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()
From: Petr Mladek
Date: Tue Oct 13 2026 - 14:04:34 EST
When the system is going down a normal way, the NBCON kthreads are
flushed and stopped properly via a syscore shutdown callback, see
printk_kthreads_shutdown().
One missing piece is emergency_restart() where the kthreads are not
stopped. It might be called from several non-panic code paths,
e.g. sysrq-o, kdb_reboot(), or some watchdogs.
Fix it by explicitly entering the emergency (atomic) mode and trying
to flush the consoles there.
Note that printk_trigger_flush() must be used instead of pr_flush()
because the later is not safe in an atomic context.
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/all/202608061008.48a1e76e-lkp@xxxxxxxxx/
Suggested-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
---
This is a 2nd attempt to make sure that NBCON consoles are flushed
during a shutdown.
Changes against [v1]
+ Handle only emergency_restart() where the syscore shutdown
callbacks are not called. [John]
+ Explicitly enter nbcon emergency mode instead of relying on
the system_state variable. [John]
+ Reworked the commit message completely.
[v1] https://lore.kernel.org/r/20261008150852.8286-1-pmladek@xxxxxxxx
---
kernel/reboot.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/reboot.c b/kernel/reboot.c
index d177d89fcc33..5b9691f45f5f 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -8,6 +8,7 @@
#define pr_fmt(fmt) "reboot: " fmt
#include <linux/atomic.h>
+#include <linux/console.h>
#include <linux/ctype.h>
#include <linux/export.h>
#include <linux/kexec.h>
@@ -94,6 +95,14 @@ void emergency_restart(void)
{
kmsg_dump(KMSG_DUMP_EMERG);
system_state = SYSTEM_RESTART;
+
+ /*
+ * NBCON kthreads won't be flushed and stopped properly in
+ * the emergency restart. Move them to the atomic mode.
+ */
+ nbcon_cpu_emergency_enter();
+ printk_trigger_flush();
+
machine_emergency_restart();
}
EXPORT_SYMBOL_GPL(emergency_restart);
--
2.56.0