[RFC PATCH v2 4/5] printk, tracing: Support console flush suppression and tail pinning
Petr Mladek
pmladek at suse.com
Mon Nov 16 09:08:26 PST 2026
On Mon 2026-11-02 21:44:52, Aaron Tomlin wrote:
> When collecting high-volume diagnostic output into the printk ring
> buffer during a kernel crash prior to kexec, synchronous console
> emission can stall the panicking CPU for tens of seconds on slow serial
> or IPMI Serial-over-LAN links, risking external hardware watchdog
> resets. At the same time, uninhibited ring buffer rotation can wrap and
> overwrite the initial Oops, faulting registers, and primary call trace.
>
> Introduce two scoped mechanisms for in-memory crash telemetry
> collection:
>
> 1. Console flush suppression
Nit: We already use the word "suppress" for filtering less important
messages on the console, see suppress_message_printing().
I would prefer to use another name to avoid confusion.
We basically want to "block" or "pause" consoles here.
>
> Provide printk_suppress_console_flush(bool) to clear the console
> flush mask in printk_get_console_flush_type(), guard legacy
> record emission and kthread wakeups, and suppress
> wake_up_klogd() in vprintk_emit(). Records written via
> vprintk_store() are stored in the in-memory ring buffer while
> bypassing synchronous hardware console emission and kthread
> wakeups.
We already have similar infrastructure for suspend, see
console_suspend_all().
We should not use a completely different aproach to achieve
the same. It would just complicate the code and design.
I suggest to add CON_PAUSED flag and handle it similar
way as CON_SUSPENDED flag. It should be enough to:
+ update console_is_usable().
+ add console_pause_all_in_panic()
, where the console_pause_all_in_panic() would do similar
things as console_suspend_all() with the following differences:
+ no flush
+ take console_srcu_read_lock() instead of console_list_lock()
+ no synchronize_srcu()
And I think that it will be only a one-way operation. We do not
need a resume part.
> 2. Ring buffer tail pinning
>
> Provide printk_mark_panic_start(), printk_clear_panic_start(),
> printk_freeze_tail(bool), and printk_is_tail_full(). Recording
> the next reserved sequence number at the start of a crash (or
> clamping to prb_first_valid_seq(prb) if the crash output itself
> already wrapped the buffer) allows data_make_reusable() and
> desc_push_tail() to continue recycling older pre-crash records
> while refusing to advance the tail past the pinned crash
> sequence number. Once the watermark is reached, prb_reserve(),
> prb_reserve_in_last(), and ftrace_dump_one() finalize the last
> record and stop reserving descriptors or consuming trace entries
> so the primary crash context and remaining trace buffer remain
> intact.
>
> --- a/kernel/printk/printk_ringbuffer.c
> +++ b/kernel/printk/printk_ringbuffer.c
> @@ -377,6 +377,90 @@ static struct prb_data_block *to_block(struct prb_data_ring *data_ring,
> return (void *)&data_ring->data[DATA_INDEX(data_ring, begin_lpos)];
> }
>
> +static atomic64_t printk_panic_seq = ATOMIC64_INIT(U64_MAX);
> +static bool printk_tail_frozen;
> +static bool printk_tail_full;
> +
> +/**
> + * printk_mark_panic_start - record the ring buffer sequence at crash start
> + *
> + * Pin the next reserved sequence number at the beginning of a top-level Oops,
> + * fatal warning, or panic so subsequent tail freezing can recycle older
> + * pre-crash records without overwriting the primary crash output.
>
> + * Context: Any context.
> + * Return: true if this call newly pinned the crash start sequence from
> + * U64_MAX, false if a crash start sequence was already active.
> + */
> +bool printk_mark_panic_start(void)
> +{
> + s64 panic_seq = atomic64_read(&printk_panic_seq);
> + u64 first_seq, next_seq;
> + bool pinned;
> +
> + do {
> + first_seq = prb_first_valid_seq(prb);
> + if ((u64)panic_seq == U64_MAX) {
> + next_seq = prb_next_reserve_seq(prb);
> + pinned = true;
> + } else if ((u64)panic_seq < first_seq) {
> + next_seq = first_seq;
> + pinned = false;
What scenario does this handle, please?
Why do we need to move the "pin" when there are concurrent callers?
What happens when the original caller clears the pin and
the other racy caller continues with panic()?
> + } else {
> + return false;
> + }
> + } while (!atomic64_try_cmpxchg(&printk_panic_seq, &panic_seq, next_seq));
Are the atomic64 operations safe in NMI? I would expect that they use
some locking.
I am afraid that we might need another approach.
IMHO, it would be much easier when the caller knows whether it will
panic() or not. And the panicing caller would just freeze buffer so
that the next_seq will always stay there.
Finally, please split the console pausing and ring buffer freezing
into separate patches.
Best Regards,
Petr
More information about the kexec
mailing list