mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nbcon/reboot: Flush nbcon consoles synchronously on reboot
@ 2026-10-08 15:08 Petr Mladek
  2026-10-08 15:19 ` Bradley Morgan
  2026-10-09  6:51 ` Sebastian Andrzej Siewior
  0 siblings, 2 replies; 9+ messages in thread
From: Petr Mladek @ 2026-10-08 15:08 UTC (permalink / raw)
  To: John Ogness
  Cc: Sergey Senozhatsky, Steven Rostedt, Pavel Tikhomirov,
	Oleg Nesterov, Christian Brauner, Sebastian Andrzej Siewior,
	oe-lkp, lkp, linux-serial, oliver.sang, linux-kernel,
	Petr Mladek

NBCON consoles emit messages in a dedicated kthreads when the system
is working properly. printk() tries to flush them synchronously in
explicitly marked emergency context and in panic().

Another situation where printk() could not rely on kthreads are the various
reboot and halt code paths. They can be detected by the `system_state`
variable.

Let's default to NBCON_PRIO_EMERGENCY for the post-running states.
printk() will automatically try flushing the consoles synchronously.
Also do not rely on printk() and explicitly flush the consoles
after these states are set.

Note that suspend code paths have already been handled, see
console_suspend_all() and console_suspend().

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/all/202608061008.48a1e76e-lkp@intel.com/
Suggested-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
Hi,

ah, this somehow fallen through cracks.
I am sending it as a proper patch finally.

I am sorry I have been somehow too busy before
the Plumbers conference.

Best Regards,
Petr
---
 kernel/printk/nbcon.c | 4 ++++
 kernel/reboot.c       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index fb1b37741952..d8f8ec836eea 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1446,6 +1446,10 @@ enum nbcon_prio nbcon_get_default_prio(void)
 	if (panic_on_this_cpu())
 		return NBCON_PRIO_PANIC;
 
+	/* Do not rely on kthreads when the system is going down. */
+	if (system_state > SYSTEM_RUNNING)
+		return NBCON_PRIO_EMERGENCY;
+
 	cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting();
 	if (*cpu_emergency_nesting)
 		return NBCON_PRIO_EMERGENCY;
diff --git a/kernel/reboot.c b/kernel/reboot.c
index d177d89fcc33..776784a82499 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,7 @@ void emergency_restart(void)
 {
 	kmsg_dump(KMSG_DUMP_EMERG);
 	system_state = SYSTEM_RESTART;
+	printk_trigger_flush();
 	machine_emergency_restart();
 }
 EXPORT_SYMBOL_GPL(emergency_restart);
@@ -102,6 +104,7 @@ void kernel_restart_prepare(char *cmd)
 {
 	blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
 	system_state = SYSTEM_RESTART;
+	printk_trigger_flush();
 	usermodehelper_disable();
 	device_shutdown();
 }
@@ -305,6 +308,7 @@ static void kernel_shutdown_prepare(enum system_states state)
 	blocking_notifier_call_chain(&reboot_notifier_list,
 		(state == SYSTEM_HALT) ? SYS_HALT : SYS_POWER_OFF, NULL);
 	system_state = state;
+	printk_trigger_flush();
 	usermodehelper_disable();
 	device_shutdown();
 }
-- 
2.55.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-10-09 15:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 15:08 [PATCH] nbcon/reboot: Flush nbcon consoles synchronously on reboot Petr Mladek
2026-10-08 15:19 ` Bradley Morgan
2026-10-09  9:16   ` Petr Mladek
2026-10-09 10:52     ` Sebastian Andrzej Siewior
2026-10-09  6:51 ` Sebastian Andrzej Siewior
2026-10-09  9:08   ` Petr Mladek
2026-10-09 12:59     ` Sebastian Andrzej Siewior
2026-10-09 13:28     ` John Ogness
2026-10-09 15:27       ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®