Skip to content

Commit f953f14

Browse files
guilhermepiccolitorvalds
authored andcommitted
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/[email protected] Signed-off-by: Guilherme G. Piccoli <[email protected]> Acked-by: Baoquan He <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: Feng Tang <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8d470a4 commit f953f14

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,6 +3727,10 @@
37273727
bit 4: print ftrace buffer
37283728
bit 5: print all printk messages in buffer
37293729
bit 6: print all CPUs backtrace (if available in the arch)
3730+
*Be aware* that this option may print a _lot_ of lines,
3731+
so there are risks of losing older messages in the log.
3732+
Use this option carefully, maybe worth to setup a
3733+
bigger log buffer with "log_buf_len" along with this.
37303734

37313735
panic_on_taint= Bitmask for conditionally calling panic() in add_taint()
37323736
Format: <hex>[,nousertaint]

kernel/panic.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,13 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
148148
}
149149
EXPORT_SYMBOL(nmi_panic);
150150

151-
static void panic_print_sys_info(void)
151+
static void panic_print_sys_info(bool console_flush)
152152
{
153-
if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
154-
console_flush_on_panic(CONSOLE_REPLAY_ALL);
153+
if (console_flush) {
154+
if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
155+
console_flush_on_panic(CONSOLE_REPLAY_ALL);
156+
return;
157+
}
155158

156159
if (panic_print & PANIC_PRINT_ALL_CPU_BT)
157160
trigger_all_cpu_backtrace();
@@ -286,6 +289,8 @@ void panic(const char *fmt, ...)
286289
*/
287290
atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
288291

292+
panic_print_sys_info(false);
293+
289294
kmsg_dump(KMSG_DUMP_PANIC);
290295

291296
/*
@@ -316,7 +321,7 @@ void panic(const char *fmt, ...)
316321
debug_locks_off();
317322
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
318323

319-
panic_print_sys_info();
324+
panic_print_sys_info(true);
320325

321326
if (!panic_blink)
322327
panic_blink = no_blink;

0 commit comments

Comments
 (0)