Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
37aa782d 652ab7c8

+21 -9
+21 -9
kernel/panic.c
··· 67 67 static bool panic_console_replay; 68 68 69 69 bool panic_triggering_all_cpu_backtrace; 70 + static bool panic_this_cpu_backtrace_printed; 70 71 71 72 int panic_timeout = CONFIG_PANIC_TIMEOUT; 72 73 EXPORT_SYMBOL_GPL(panic_timeout); ··· 381 380 origin, limit); 382 381 } 383 382 383 + static void panic_trigger_all_cpu_backtrace(void) 384 + { 385 + /* Temporary allow non-panic CPUs to write their backtraces. */ 386 + panic_triggering_all_cpu_backtrace = true; 387 + 388 + if (panic_this_cpu_backtrace_printed) 389 + trigger_allbutcpu_cpu_backtrace(raw_smp_processor_id()); 390 + else 391 + trigger_all_cpu_backtrace(); 392 + 393 + panic_triggering_all_cpu_backtrace = false; 394 + } 395 + 384 396 /* 385 397 * Helper that triggers the NMI backtrace (if set in panic_print) 386 398 * and then performs the secondary CPUs shutdown - we cannot have ··· 401 387 */ 402 388 static void panic_other_cpus_shutdown(bool crash_kexec) 403 389 { 404 - if (panic_print & SYS_INFO_ALL_CPU_BT) { 405 - /* Temporary allow non-panic CPUs to write their backtraces. */ 406 - panic_triggering_all_cpu_backtrace = true; 407 - trigger_all_cpu_backtrace(); 408 - panic_triggering_all_cpu_backtrace = false; 409 - } 390 + if (panic_print & SYS_INFO_ALL_CPU_BT) 391 + panic_trigger_all_cpu_backtrace(); 410 392 411 393 /* 412 394 * Note that smp_send_stop() is the usual SMP shutdown function, ··· 480 470 buf[len - 1] = '\0'; 481 471 482 472 pr_emerg("Kernel panic - not syncing: %s\n", buf); 483 - #ifdef CONFIG_DEBUG_BUGVERBOSE 484 473 /* 485 474 * Avoid nested stack-dumping if a panic occurs during oops processing 486 475 */ 487 - if (!test_taint(TAINT_DIE) && oops_in_progress <= 1) 476 + if (test_taint(TAINT_DIE) || oops_in_progress > 1) { 477 + panic_this_cpu_backtrace_printed = true; 478 + } else if (IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE)) { 488 479 dump_stack(); 489 - #endif 480 + panic_this_cpu_backtrace_printed = true; 481 + } 490 482 491 483 /* 492 484 * If kgdb is enabled, give it a chance to run before we stop all