Re: [PATCH] nbcon/reboot: Flush nbcon consoles synchronously on reboot
From: John Ogness
Date: Mon Oct 12 2026 - 09:35:24 EST
On 2026-10-08, Petr Mladek <pmladek@xxxxxxxx> wrote:
> 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.
We are already using the syscore.ops.shutdown notifier for this.
> Let's default to NBCON_PRIO_EMERGENCY for the post-running states.
> printk() will automatically try flushing the consoles synchronously.
Switching to emergency state can cause ugly output and is best
effort. For emergencies it is acceptable, but I am against this in the
general case. A normal shutdown/reboot is not an emergency. I prefer we
mark the appropriate emergency situations.
> 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;
> +
Too general. The vast majority of cases do not need this.
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index d177d89fcc33..776784a82499 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -94,6 +95,7 @@ void emergency_restart(void)
> {
> kmsg_dump(KMSG_DUMP_EMERG);
> system_state = SYSTEM_RESTART;
> + printk_trigger_flush();
This is clearly an emergency. Similar to what we did for MIPS, I would
add:
nbcon_cpu_emergency_enter();
before triggering the flush.
> @@ -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();
This is not necessary. This is handled by the syscore notifier.
> 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();
Ditto.
John