All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()
@ 2026-10-13 15:41 Petr Mladek
  2026-10-13 15:54 ` sashiko-bot
  2026-10-13 16:09 ` John Ogness
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Mladek @ 2026-10-13 15:41 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, linux-kernel, Petr Mladek

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@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>
---
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@suse.com
---
 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


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

* Re: [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()
  2026-10-13 15:41 [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart() Petr Mladek
@ 2026-10-13 15:54 ` sashiko-bot
  2026-10-13 16:09 ` John Ogness
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-13 15:54 UTC (permalink / raw)
  To: Petr Mladek; +Cc: linux-serial

> 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@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>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013154141.94016-1-pmladek@suse.com?part=1


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

* Re: [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()
  2026-10-13 15:41 [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart() Petr Mladek
  2026-10-13 15:54 ` sashiko-bot
@ 2026-10-13 16:09 ` John Ogness
  1 sibling, 0 replies; 3+ messages in thread
From: John Ogness @ 2026-10-13 16:09 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Steven Rostedt, Pavel Tikhomirov,
	Oleg Nesterov, Christian Brauner, Sebastian Andrzej Siewior,
	oe-lkp, lkp, linux-serial, linux-kernel, Petr Mladek

On 2026-10-13, Petr Mladek <pmladek@suse.com> wrote:
> 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@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>

Reviewed-by: John Ogness <john.ogness@linutronix.de>

Thanks, Petr.

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 15:41 [PATCH v2] nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart() Petr Mladek
2026-10-13 15:54 ` sashiko-bot
2026-10-13 16:09 ` John Ogness

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.