Commit f953f140 authored by Guilherme G. Piccoli's avatar Guilherme G. Piccoli Committed by Linus Torvalds

panic: move panic_print before kmsg dumpers

The panic_print setting allows users to collect more information in a
panic event, like memory stats, tasks, CPUs backtraces, etc.  This is an
interesting debug mechanism, but currently the print event happens *after*
kmsg_dump(), meaning that pstore, for example, cannot collect a dmesg with
the panic_print extra information.

This patch changes that in 2 steps:

(a) The panic_print setting allows to replay the existing kernel log
    buffer to the console (bit 5), besides the extra information dump.
    This functionality makes sense only at the end of the panic()
    function.  So, we hereby allow to distinguish the two situations by a
    new boolean parameter in the function panic_print_sys_info().

(b) With the above change, we can safely call panic_print_sys_info()
    before kmsg_dump(), allowing to dump the extra information when using
    pstore or other kmsg dumpers.

The additional messages from panic_print could overwrite the oldest
messages when the buffer is full.  The only reasonable solution is to use
a large enough log buffer, hence we added an advice into the kernel
parameters documentation about that.

Link: https://lkml.kernel.org/r/20220214141308.841525-1-gpiccoli@igalia.comSigned-off-by: default avatarGuilherme G. Piccoli <gpiccoli@igalia.com>
Acked-by: default avatarBaoquan He <bhe@redhat.com>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Reviewed-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Cc: Feng Tang <feng.tang@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8d470a45
...@@ -3727,6 +3727,10 @@ ...@@ -3727,6 +3727,10 @@
bit 4: print ftrace buffer bit 4: print ftrace buffer
bit 5: print all printk messages in buffer bit 5: print all printk messages in buffer
bit 6: print all CPUs backtrace (if available in the arch) bit 6: print all CPUs backtrace (if available in the arch)
*Be aware* that this option may print a _lot_ of lines,
so there are risks of losing older messages in the log.
Use this option carefully, maybe worth to setup a
bigger log buffer with "log_buf_len" along with this.
panic_on_taint= Bitmask for conditionally calling panic() in add_taint() panic_on_taint= Bitmask for conditionally calling panic() in add_taint()
Format: <hex>[,nousertaint] Format: <hex>[,nousertaint]
......
...@@ -148,10 +148,13 @@ void nmi_panic(struct pt_regs *regs, const char *msg) ...@@ -148,10 +148,13 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
} }
EXPORT_SYMBOL(nmi_panic); EXPORT_SYMBOL(nmi_panic);
static void panic_print_sys_info(void) static void panic_print_sys_info(bool console_flush)
{ {
if (console_flush) {
if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
console_flush_on_panic(CONSOLE_REPLAY_ALL); console_flush_on_panic(CONSOLE_REPLAY_ALL);
return;
}
if (panic_print & PANIC_PRINT_ALL_CPU_BT) if (panic_print & PANIC_PRINT_ALL_CPU_BT)
trigger_all_cpu_backtrace(); trigger_all_cpu_backtrace();
...@@ -286,6 +289,8 @@ void panic(const char *fmt, ...) ...@@ -286,6 +289,8 @@ void panic(const char *fmt, ...)
*/ */
atomic_notifier_call_chain(&panic_notifier_list, 0, buf); atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
panic_print_sys_info(false);
kmsg_dump(KMSG_DUMP_PANIC); kmsg_dump(KMSG_DUMP_PANIC);
/* /*
...@@ -316,7 +321,7 @@ void panic(const char *fmt, ...) ...@@ -316,7 +321,7 @@ void panic(const char *fmt, ...)
debug_locks_off(); debug_locks_off();
console_flush_on_panic(CONSOLE_FLUSH_PENDING); console_flush_on_panic(CONSOLE_FLUSH_PENDING);
panic_print_sys_info(); panic_print_sys_info(true);
if (!panic_blink) if (!panic_blink)
panic_blink = no_blink; panic_blink = no_blink;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment