Skip to contentSkip to conversation

nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()

PATCH In review Petr Mladek 3 participants 4 messages Oct 13 – Oct 14 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()

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.

---
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/[email protected]

---
 kernel/reboot.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/reboot.c +9 -0
index d177d89fcc33..5b9691f45f5f 100644
@@ -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);
Signature · 1 line
2.56.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

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.

Quoted 7 lines

Note that printk_trigger_flush() must be used instead of pr_flush() because the later is not safe in an atomic context.

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

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Petr Mladek
Quoted 11 lines · 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.

Quoted 7 lines

Note that printk_trigger_flush() must be used instead of pr_flush() because the later is not safe in an atomic context.

Thanks, Petr.

#3 lore raw
In reply to Petr Mladek
Quoted 11 lines · 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.

Quoted 7 lines

Note that printk_trigger_flush() must be used instead of pr_flush() because the later is not safe in an atomic context.

JFYI, the patch has been committed into printk/linux.git, branch for-7.3-hotfix.

I am going to give it a spin in linux-next and send a pull request on Friday unless any blocker appears in the meantime.

Best Regards,
Petr