Skip to content

Commit d999bd9

Browse files
ftang1torvalds
authored andcommitted
panic: add options to print system info when panic happens
Kernel panic issues are always painful to debug, partially because it's not easy to get enough information of the context when panic happens. And we have ramoops and kdump for that, while this commit tries to provide a easier way to show the system info by adding a cmdline parameter, referring some idea from sysrq handler. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Feng Tang <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: John Stultz <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d187715 commit d999bd9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,14 @@
30923092
timeout < 0: reboot immediately
30933093
Format: <timeout>
30943094

3095+
panic_print= Bitmask for printing system info when panic happens.
3096+
User can chose combination of the following bits:
3097+
bit 0: print all tasks info
3098+
bit 1: print system memory info
3099+
bit 2: print timer info
3100+
bit 3: print locks info if CONFIG_LOCKDEP is on
3101+
bit 4: print ftrace buffer
3102+
30953103
panic_on_warn panic() instead of WARN(). Useful to cause kdump
30963104
on a WARN().
30973105

kernel/panic.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ int panic_on_warn __read_mostly;
4646
int panic_timeout = CONFIG_PANIC_TIMEOUT;
4747
EXPORT_SYMBOL_GPL(panic_timeout);
4848

49+
#define PANIC_PRINT_TASK_INFO 0x00000001
50+
#define PANIC_PRINT_MEM_INFO 0x00000002
51+
#define PANIC_PRINT_TIMER_INFO 0x00000004
52+
#define PANIC_PRINT_LOCK_INFO 0x00000008
53+
#define PANIC_PRINT_FTRACE_INFO 0x00000010
54+
static unsigned long panic_print;
55+
4956
ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
5057

5158
EXPORT_SYMBOL(panic_notifier_list);
@@ -125,6 +132,24 @@ void nmi_panic(struct pt_regs *regs, const char *msg)
125132
}
126133
EXPORT_SYMBOL(nmi_panic);
127134

135+
static void panic_print_sys_info(void)
136+
{
137+
if (panic_print & PANIC_PRINT_TASK_INFO)
138+
show_state();
139+
140+
if (panic_print & PANIC_PRINT_MEM_INFO)
141+
show_mem(0, NULL);
142+
143+
if (panic_print & PANIC_PRINT_TIMER_INFO)
144+
sysrq_timer_list_show();
145+
146+
if (panic_print & PANIC_PRINT_LOCK_INFO)
147+
debug_show_all_locks();
148+
149+
if (panic_print & PANIC_PRINT_FTRACE_INFO)
150+
ftrace_dump(DUMP_ALL);
151+
}
152+
128153
/**
129154
* panic - halt the system
130155
* @fmt: The text string to print
@@ -254,6 +279,8 @@ void panic(const char *fmt, ...)
254279
debug_locks_off();
255280
console_flush_on_panic();
256281

282+
panic_print_sys_info();
283+
257284
if (!panic_blink)
258285
panic_blink = no_blink;
259286

@@ -658,6 +685,7 @@ void refcount_error_report(struct pt_regs *regs, const char *err)
658685
#endif
659686

660687
core_param(panic, panic_timeout, int, 0644);
688+
core_param(panic_print, panic_print, ulong, 0644);
661689
core_param(pause_on_oops, pause_on_oops, int, 0644);
662690
core_param(panic_on_warn, panic_on_warn, int, 0644);
663691
core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644);

0 commit comments

Comments
 (0)