Commit c39ea0b9 authored by Feng Tang's avatar Feng Tang Committed by Linus Torvalds

panic: avoid the extra noise dmesg

When kernel panic happens, it will first print the panic call stack,
then the ending msg like:

[   35.743249] ---[ end Kernel panic - not syncing: Fatal exception
[   35.749975] ------------[ cut here ]------------

The above message are very useful for debugging.

But if system is configured to not reboot on panic, say the
"panic_timeout" parameter equals 0, it will likely print out many noisy
message like WARN() call stack for each and every CPU except the panic
one, messages like below:

	WARNING: CPU: 1 PID: 280 at kernel/sched/core.c:1198 set_task_cpu+0x183/0x190
	Call Trace:
	<IRQ>
	try_to_wake_up
	default_wake_function
	autoremove_wake_function
	__wake_up_common
	__wake_up_common_lock
	__wake_up
	wake_up_klogd_work_func
	irq_work_run_list
	irq_work_tick
	update_process_times
	tick_sched_timer
	__hrtimer_run_queues
	hrtimer_interrupt
	smp_apic_timer_interrupt
	apic_timer_interrupt

For people working in console mode, the screen will first show the panic
call stack, but immediately overridden by these noisy extra messages,
which makes debugging much more difficult, as the original context gets
lost on screen.

Also these noisy messages will confuse some users, as I have seen many bug
reporters posted the noisy message into bugzilla, instead of the real
panic call stack and context.

Adding a flag "suppress_printk" which gets set in panic() to avoid those
noisy messages, without changing current kernel behavior that both panic
blinking and sysrq magic key can work as is, suggested by Petr Mladek.

To verify this, make sure kernel is not configured to reboot on panic and
in console
 # echo c > /proc/sysrq-trigger
to see if console only prints out the panic call stack.

Link: http://lkml.kernel.org/r/1551430186-24169-1-git-send-email-feng.tang@intel.comSigned-off-by: default avatarFeng Tang <feng.tang@intel.com>
Suggested-by: default avatarPetr Mladek <pmladek@suse.com>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@suse.de>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Sasha Levin <sashal@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e178a5be
...@@ -527,8 +527,12 @@ void __handle_sysrq(int key, bool check_mask) ...@@ -527,8 +527,12 @@ void __handle_sysrq(int key, bool check_mask)
{ {
struct sysrq_key_op *op_p; struct sysrq_key_op *op_p;
int orig_log_level; int orig_log_level;
int orig_suppress_printk;
int i; int i;
orig_suppress_printk = suppress_printk;
suppress_printk = 0;
rcu_sysrq_start(); rcu_sysrq_start();
rcu_read_lock(); rcu_read_lock();
/* /*
...@@ -574,6 +578,8 @@ void __handle_sysrq(int key, bool check_mask) ...@@ -574,6 +578,8 @@ void __handle_sysrq(int key, bool check_mask)
} }
rcu_read_unlock(); rcu_read_unlock();
rcu_sysrq_end(); rcu_sysrq_end();
suppress_printk = orig_suppress_printk;
} }
void handle_sysrq(int key) void handle_sysrq(int key)
......
...@@ -82,6 +82,8 @@ static inline void console_verbose(void) ...@@ -82,6 +82,8 @@ static inline void console_verbose(void)
extern char devkmsg_log_str[]; extern char devkmsg_log_str[];
struct ctl_table; struct ctl_table;
extern int suppress_printk;
struct va_format { struct va_format {
const char *fmt; const char *fmt;
va_list *va; va_list *va;
......
...@@ -321,6 +321,9 @@ void panic(const char *fmt, ...) ...@@ -321,6 +321,9 @@ void panic(const char *fmt, ...)
disabled_wait(); disabled_wait();
#endif #endif
pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf); pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
/* Do not scroll important messages printed above */
suppress_printk = 1;
local_irq_enable(); local_irq_enable();
for (i = 0; ; i += PANIC_TIMER_STEP) { for (i = 0; ; i += PANIC_TIMER_STEP) {
touch_softlockup_watchdog(); touch_softlockup_watchdog();
......
...@@ -86,6 +86,12 @@ static DEFINE_SEMAPHORE(console_sem); ...@@ -86,6 +86,12 @@ static DEFINE_SEMAPHORE(console_sem);
struct console *console_drivers; struct console *console_drivers;
EXPORT_SYMBOL_GPL(console_drivers); EXPORT_SYMBOL_GPL(console_drivers);
/*
* System may need to suppress printk message under certain
* circumstances, like after kernel panic happens.
*/
int __read_mostly suppress_printk;
#ifdef CONFIG_LOCKDEP #ifdef CONFIG_LOCKDEP
static struct lockdep_map console_lock_dep_map = { static struct lockdep_map console_lock_dep_map = {
.name = "console_lock" .name = "console_lock"
...@@ -1943,6 +1949,10 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1943,6 +1949,10 @@ asmlinkage int vprintk_emit(int facility, int level,
unsigned long flags; unsigned long flags;
u64 curr_log_seq; u64 curr_log_seq;
/* Suppress unimportant messages after panic happens */
if (unlikely(suppress_printk))
return 0;
if (level == LOGLEVEL_SCHED) { if (level == LOGLEVEL_SCHED) {
level = LOGLEVEL_DEFAULT; level = LOGLEVEL_DEFAULT;
in_sched = true; in_sched = true;
......
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