Re: [RFC PATCH v2 1/5] panic, sys_info: Fix duplicate and dropped all-CPU backtraces in panic

From: Petr Mladek

Date: Mon Nov 16 2026 - 10:30:55 EST


On Mon 2026-11-02 21:44:49, Aaron Tomlin wrote:
> When sys_info() was factored out of kernel/panic.c by
> commit b76e89e50fc3 ("panic: generalize panic_print's function to show
> sys info"), __sys_info() gained an unconditional call to
> trigger_all_cpu_backtrace() when SYS_INFO_ALL_BT is set, while
> panic_other_cpus_shutdown() retained its own call to
> panic_trigger_all_cpu_backtrace().
>
> This causes two problems during a kernel panic:
>
> 1. vpanic() invokes panic_trigger_all_cpu_backtrace() inside
> panic_other_cpus_shutdown() before stopping secondary CPUs, and
> then invokes trigger_all_cpu_backtrace() a second time inside
> sys_info(panic_print) after secondary CPUs have already been
> shut down, stalling for up to 10 seconds waiting for offline
> CPUs to respond to NMIs. Furthermore, if SYS_INFO_ALL_BT is
> configured via the kernel.kernel_sys_info sysctl rather than
> panic_print, panic_other_cpus_shutdown() misses it prior to CPU
> shutdown.
>
> 2. If sys_info(SYS_INFO_ALL_BT) is invoked on the panicking CPU
> prior to panic_other_cpus_shutdown(), calling
> trigger_all_cpu_backtrace() directly bypasses
> panic_trigger_all_cpu_backtrace() and leaves
> panic_triggering_all_cpu_backtrace unset. Because panic_cpu is
> already active, vprintk_emit() silently drops all NMI backtrace
> messages originating from non-panic CPUs.
>
> Export panic_trigger_all_cpu_backtrace() with a panic_on_this_cpu() and
> one-shot guard so all-CPU backtraces are only emitted once before
> secondary CPUs are stopped, consult sys_info_get_mask(panic_print) in
> panic_other_cpus_shutdown(), record prior Oops stack dumps in
> panic_try_start(), and route SYS_INFO_ALL_BT in __sys_info()
> through panic_trigger_all_cpu_backtrace() on the panicking CPU.
>
> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -451,13 +452,21 @@ bool panic_try_start(void)
> old_cpu = PANIC_CPU_INVALID;
> this_cpu = raw_smp_processor_id();
>
> - return atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu);
> + if (!atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu))
> + return false;
> +
> + if (atomic_read(&panic_redirect_cpu) == PANIC_CPU_INVALID &&
> + (test_taint(TAINT_DIE) || oops_in_progress))
> + panic_this_cpu_backtrace_printed = true;

This would be pretty hard to maintain. The complexity of the check
shows how many code paths affect the decision. I can't imagine how
to synchonize all the pieces this way.

We need another approach. I remember that I have already proposed
something some time ago.

The idea was to enhance sys_info() API to remember what has already
been printed. trigger_all_cpu_backtrace() and frieds should
not longer be called directly. They should be called only via
sys_info() API.

See https://lore.kernel.org/all/aj5tFiwhRqPkAkqU@xxxxxxxxxxxxxxx/
for more details.

I think that this would be a better way to go.
What do you think, please?

Best Regards,
Petr