History

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.

Feng Tang committed 7 years ago

Commit c39ea0b1 parent e178a5b4 files · +21 −0Browse files

Unified · Split

4 files
  1. drivers/tty/sysrq.c +6 −0
  2. include/linux/printk.h +2 −0
  3. kernel/panic.c +3 −0
  4. kernel/printk/printk.c +10 −0
drivers/tty/sysrq.c+6−0
@@ -527,8 +527,12 @@ void __handle_sysrq(int key, bool check_mask) · 526 unmodified lines
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) · 39 unmodified lines
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+2−0
@@ -82,6 +82,8 @@ static inline void console_verbose(void) · 81 unmodified lines
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+3−0
@@ -321,6 +321,9 @@ void panic(const char *fmt, ...) · 320 unmodified lines
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+10−0
@@ -86,6 +86,12 @@ static DEFINE_SEMAPHORE(console_sem); · 85 unmodified lines
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, · 1851 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t