Skip to content

Commit c39ea0b

Browse files
ftang1torvalds
authored andcommitted
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.com Signed-off-by: Feng Tang <feng.tang@intel.com> Suggested-by: Petr Mladek <pmladek@suse.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Acked-by: Sergey 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e178a5b commit c39ea0b

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎drivers/tty/sysrq.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,12 @@ void __handle_sysrq(int key, bool check_mask)
527527
{
528528
struct sysrq_key_op *op_p;
529529
int orig_log_level;
530+
int orig_suppress_printk;
530531
int i;
531532

533+
orig_suppress_printk = suppress_printk;
534+
suppress_printk = 0;
535+
532536
rcu_sysrq_start();
533537
rcu_read_lock();
534538
/*
@@ -574,6 +578,8 @@ void __handle_sysrq(int key, bool check_mask)
574578
}
575579
rcu_read_unlock();
576580
rcu_sysrq_end();
581+
582+
suppress_printk = orig_suppress_printk;
577583
}
578584

579585
void handle_sysrq(int key)

‎include/linux/printk.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ static inline void console_verbose(void)
8282
extern char devkmsg_log_str[];
8383
struct ctl_table;
8484

85+
extern int suppress_printk;
86+
8587
struct va_format {
8688
const char *fmt;
8789
va_list *va;

‎kernel/panic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ void panic(const char *fmt, ...)
321321
disabled_wait();
322322
#endif
323323
pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
324+
325+
/* Do not scroll important messages printed above */
326+
suppress_printk = 1;
324327
local_irq_enable();
325328
for (i = 0; ; i += PANIC_TIMER_STEP) {
326329
touch_softlockup_watchdog();

‎kernel/printk/printk.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ static DEFINE_SEMAPHORE(console_sem);
8686
struct console *console_drivers;
8787
EXPORT_SYMBOL_GPL(console_drivers);
8888

89+
/*
90+
* System may need to suppress printk message under certain
91+
* circumstances, like after kernel panic happens.
92+
*/
93+
int __read_mostly suppress_printk;
94+
8995
#ifdef CONFIG_LOCKDEP
9096
static struct lockdep_map console_lock_dep_map = {
9197
.name = "console_lock"
@@ -1943,6 +1949,10 @@ asmlinkage int vprintk_emit(int facility, int level,
19431949
unsigned long flags;
19441950
u64 curr_log_seq;
19451951

1952+
/* Suppress unimportant messages after panic happens */
1953+
if (unlikely(suppress_printk))
1954+
return 0;
1955+
19461956
if (level == LOGLEVEL_SCHED) {
19471957
level = LOGLEVEL_DEFAULT;
19481958
in_sched = true;

0 commit comments

Comments
 (0)