Skip to content

Commit b905039

Browse files
guilhermepiccoliakpm00
authored andcommitted
panic: fix the panic_print NMI backtrace setting
Commit 8d470a4 ("panic: add option to dump all CPUs backtraces in panic_print") introduced a setting for the "panic_print" kernel parameter to allow users to request a NMI backtrace on panic. Problem is that the panic_print handling happens after the secondary CPUs are already disabled, hence this option ended-up being kind of a no-op - kernel skips the NMI trace in idling CPUs, which is the case of offline CPUs. Fix it by checking the NMI backtrace bit in the panic_print prior to the CPU disabling function. Link: https://lkml.kernel.org/r/20230226160838.414257-1-gpiccoli@igalia.com Fixes: 8d470a4 ("panic: add option to dump all CPUs backtraces in panic_print") Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com> Cc: <stable@vger.kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: Dave Young <dyoung@redhat.com> Cc: Feng Tang <feng.tang@intel.com> Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> Cc: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com> Cc: Kees Cook <keescook@chromium.org> Cc: Michael Kelley <mikelley@microsoft.com> Cc: Petr Mladek <pmladek@suse.com> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 359d625 commit b905039

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

kernel/panic.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ static void panic_print_sys_info(bool console_flush)
212212
return;
213213
}
214214

215-
if (panic_print & PANIC_PRINT_ALL_CPU_BT)
216-
trigger_all_cpu_backtrace();
217-
218215
if (panic_print & PANIC_PRINT_TASK_INFO)
219216
show_state();
220217

@@ -244,6 +241,30 @@ void check_panic_on_warn(const char *origin)
244241
origin, limit);
245242
}
246243

244+
/*
245+
* Helper that triggers the NMI backtrace (if set in panic_print)
246+
* and then performs the secondary CPUs shutdown - we cannot have
247+
* the NMI backtrace after the CPUs are off!
248+
*/
249+
static void panic_other_cpus_shutdown(bool crash_kexec)
250+
{
251+
if (panic_print & PANIC_PRINT_ALL_CPU_BT)
252+
trigger_all_cpu_backtrace();
253+
254+
/*
255+
* Note that smp_send_stop() is the usual SMP shutdown function,
256+
* which unfortunately may not be hardened to work in a panic
257+
* situation. If we want to do crash dump after notifier calls
258+
* and kmsg_dump, we will need architecture dependent extra
259+
* bits in addition to stopping other CPUs, hence we rely on
260+
* crash_smp_send_stop() for that.
261+
*/
262+
if (!crash_kexec)
263+
smp_send_stop();
264+
else
265+
crash_smp_send_stop();
266+
}
267+
247268
/**
248269
* panic - halt the system
249270
* @fmt: The text string to print
@@ -334,23 +355,10 @@ void panic(const char *fmt, ...)
334355
*
335356
* Bypass the panic_cpu check and call __crash_kexec directly.
336357
*/
337-
if (!_crash_kexec_post_notifiers) {
358+
if (!_crash_kexec_post_notifiers)
338359
__crash_kexec(NULL);
339360

340-
/*
341-
* Note smp_send_stop is the usual smp shutdown function, which
342-
* unfortunately means it may not be hardened to work in a
343-
* panic situation.
344-
*/
345-
smp_send_stop();
346-
} else {
347-
/*
348-
* If we want to do crash dump after notifier calls and
349-
* kmsg_dump, we will need architecture dependent extra
350-
* works in addition to stopping other CPUs.
351-
*/
352-
crash_smp_send_stop();
353-
}
361+
panic_other_cpus_shutdown(_crash_kexec_post_notifiers);
354362

355363
/*
356364
* Run any panic handlers, including those that might need to

0 commit comments

Comments
 (0)