Re: [RFC PATCH v1] panic: Flush unsafe consoles before panic reboot
From: Breno Leitao
Date: Wed Oct 28 2026 - 07:24:36 EST
On Tue, Oct 27, 2026 at 07:07:30PM +0106, John Ogness wrote:
> On 2026-10-27, Breno Leitao <leitao@xxxxxxxxxx> wrote:
> > On Tue, Oct 27, 2026 at 09:12:09AM -0700, Breno Leitao wrote:
> Perhaps we need to begin by identifying all the sites where the current
> kernel is ending (whether reboot, shutdown, panic, kexec, hang).
Ack. This is what I have so far on the panic side:
1) panic() ending in the final loop (panic_timeout=0): flushed at the
end, including the unsafe consoles (d988d9a9b9d180, 5dde3b735413).
2) panic() ending in emergency_restart(): no unsafe flush (Ryan's RFC).
3) panic() ending in __crash_kexec(): the console_flush_on_panic() and
nbcon_atomic_flush_unsafe() calls all come later, with or without
crash_kexec_post_notifiers.
4) An oops ending in crash_kexec() straight from oops_end()/die(),
when kexec_should_crash() is true. panic() never runs.
5) Other crash_kexec() callers, such as s390 and hypervisors.
> > + /* Flush consoles with an unsafe write_atomic(), e.g. netconsole. */
> > + nbcon_atomic_flush_unsafe();
>
> I am guessing that the CPU is _always_ in emergency state here?
> Otherwise the flushing problem exists for all atomic consoles.
True. But for the unsafe consoles, the end of panic() already handles
this.
d988d9a9b9d180 ("panic: Flush kernel log buffer at the end") added
a final console_flush_on_panic(), and 5dde3b735413 ("printk: nbcon: Add
unsafe flushing on panic") added nbcon_atomic_flush_unsafe() after it,
to make sure the last messages get out.
That _only_ runs when panic() ends in the final loop, though. kdump never
gets there, and neither does reboot-on-panic or, possibly, some of the
other "kernel ending" sites you mentioned above.
The kdump case is the one I care about most. It is a regression for us
(Meta) in production, where kdump is always armed: netconsole has lost
these messages since it moved to nbcon.
So far we have identified two places that need the same unsafe flush
that 5dde3b735413 added to the final loop:
a) panic() ending in emergency_restart(). Petr's suggestion to flush
from console_flush_on_panic() covers this one.
b) __crash_kexec(), reached from panic() or straight from
oops_end()/die().