Skip to content

Commit 37aa782

Browse files
sergey-senozhatskyakpm00
authored andcommitted
panic: remove redundant panic-cpu backtrace
Backtraces from all CPUs are printed during panic() when SYS_INFO_ALL_CPU_BT is set. It shows the backtrace for the panic-CPU even when it has already been explicitly printed before. Do not change the legacy code which prints the backtrace in various contexts, for example, as part of Oops report, right after panic message. It will always be visible in the crash dump. Instead, remember when the backtrace was printed, and skip it when dumping the optional backtraces on all CPUs. [akpm@linux-foundation.org: make panic_this_cpu_backtrace_printed static] Closes: https://lore.kernel.org/oe-kbuild-all/202509050048.FMpVvh1u-lkp@intel.com/ [pmladek@suse.com: Handle situations when the backtrace was not printed for the panic CPU] Link: https://lkml.kernel.org/r/20250903100418.410026-1-pmladek@suse.com Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Link: https://lore.kernel.org/r/20250731030314.3818040-1-senozhatsky@chromium.org Signed-off-by: Petr Mladek <pmladek@suse.com> Tested-by: Feng Tang <feng.tang@linux.alibaba.com> Reviewed-by: John Ogness <john.ogness@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 652ab7c commit 37aa782

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

kernel/panic.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static unsigned int warn_limit __read_mostly;
6767
static bool panic_console_replay;
6868

6969
bool panic_triggering_all_cpu_backtrace;
70+
static bool panic_this_cpu_backtrace_printed;
7071

7172
int panic_timeout = CONFIG_PANIC_TIMEOUT;
7273
EXPORT_SYMBOL_GPL(panic_timeout);
@@ -380,19 +381,28 @@ void check_panic_on_warn(const char *origin)
380381
origin, limit);
381382
}
382383

384+
static void panic_trigger_all_cpu_backtrace(void)
385+
{
386+
/* Temporary allow non-panic CPUs to write their backtraces. */
387+
panic_triggering_all_cpu_backtrace = true;
388+
389+
if (panic_this_cpu_backtrace_printed)
390+
trigger_allbutcpu_cpu_backtrace(raw_smp_processor_id());
391+
else
392+
trigger_all_cpu_backtrace();
393+
394+
panic_triggering_all_cpu_backtrace = false;
395+
}
396+
383397
/*
384398
* Helper that triggers the NMI backtrace (if set in panic_print)
385399
* and then performs the secondary CPUs shutdown - we cannot have
386400
* the NMI backtrace after the CPUs are off!
387401
*/
388402
static void panic_other_cpus_shutdown(bool crash_kexec)
389403
{
390-
if (panic_print & SYS_INFO_ALL_CPU_BT) {
391-
/* Temporary allow non-panic CPUs to write their backtraces. */
392-
panic_triggering_all_cpu_backtrace = true;
393-
trigger_all_cpu_backtrace();
394-
panic_triggering_all_cpu_backtrace = false;
395-
}
404+
if (panic_print & SYS_INFO_ALL_CPU_BT)
405+
panic_trigger_all_cpu_backtrace();
396406

397407
/*
398408
* Note that smp_send_stop() is the usual SMP shutdown function,
@@ -470,13 +480,15 @@ void vpanic(const char *fmt, va_list args)
470480
buf[len - 1] = '\0';
471481

472482
pr_emerg("Kernel panic - not syncing: %s\n", buf);
473-
#ifdef CONFIG_DEBUG_BUGVERBOSE
474483
/*
475484
* Avoid nested stack-dumping if a panic occurs during oops processing
476485
*/
477-
if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
486+
if (test_taint(TAINT_DIE) || oops_in_progress > 1) {
487+
panic_this_cpu_backtrace_printed = true;
488+
} else if (IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) {
478489
dump_stack();
479-
#endif
490+
panic_this_cpu_backtrace_printed = true;
491+
}
480492

481493
/*
482494
* If kgdb is enabled, give it a chance to run before we stop all

0 commit comments

Comments
 (0)