nbcon/reboot: Switch NBCON consoles into the emergency mode in emergency_restart()
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
@@ -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
[email protected]
AI reviewSashiko 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 ofpr_flush()because the later is not safe in an atomic context.Reported-by kernel test robot <[email protected]>Suggested-by John Ogness <[email protected]>Signed-off-by Petr Mladek <[email protected]>
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
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 ofpr_flush()because the later is not safe in an atomic context.Reported-by kernel test robot <[email protected]>Suggested-by John Ogness <[email protected]>Signed-off-by Petr Mladek <[email protected]>
Thanks, Petr.
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 ofpr_flush()because the later is not safe in an atomic context.Reported-by kernel test robot <[email protected]>Suggested-by John Ogness <[email protected]>Signed-off-by Petr Mladek <[email protected]>
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