Commit b0f4c4b32c8e3aa0d44fc4dd6c40a9a9a8d66b63

Authored by Prarit Bhargava
Committed by Ingo Molnar
1 parent b64b223aed

bugs, x86: Fix printk levels for panic, softlockups and stack dumps

rsyslog will display KERN_EMERG messages on a connected
terminal.  However, these messages are useless/undecipherable
for a general user.

For example, after a softlockup we get:

 Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
 kernel:Stack:

 Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
 kernel:Call Trace:

 Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
 kernel:Code: ff ff a8 08 75 25 31 d2 48 8d 86 38 e0 ff ff 48 89
 d1 0f 01 c8 0f ae f0 48 8b 86 38 e0 ff ff a8 08 75 08 b1 01 4c 89 e0 0f 01 c9 <e8> ea 69 dd ff 4c 29 e8 48 89 c7 e8 0f bc da ff 49 89 c4 49 89

This happens because the printk levels for these messages are
incorrect. Only an informational message should be displayed on
a terminal.

I modified the printk levels for various messages in the kernel
and tested the output by using the drivers/misc/lkdtm.c kernel
modules (ie, softlockups, panics, hard lockups, etc.) and
confirmed that the console output was still the same and that
the output to the terminals was correct.

For example, in the case of a softlockup we now see the much
more informative:

 Message from syslogd@intel-s3e37-04 at Jan 25 10:18:06 ...
 BUG: soft lockup - CPU4 stuck for 60s!

instead of the above confusing messages.

AFAICT, the messages no longer have to be KERN_EMERG.  In the
most important case of a panic we set console_verbose().  As for
the other less severe cases the correct data is output to the
console and /var/log/messages.

Successfully tested by me using the drivers/misc/lkdtm.c module.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: dzickus@redhat.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/1327586134-11926-1-git-send-email-prarit@redhat.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 5 changed files with 9 additions and 8 deletions Side-by-side Diff

arch/x86/kernel/dumpstack.c
... ... @@ -252,7 +252,8 @@
252 252 unsigned short ss;
253 253 unsigned long sp;
254 254 #endif
255   - printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
  255 + printk(KERN_DEFAULT
  256 + "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
256 257 #ifdef CONFIG_PREEMPT
257 258 printk("PREEMPT ");
258 259 #endif
arch/x86/kernel/dumpstack_64.c
... ... @@ -269,11 +269,11 @@
269 269 unsigned char c;
270 270 u8 *ip;
271 271  
272   - printk(KERN_EMERG "Stack:\n");
  272 + printk(KERN_DEFAULT "Stack:\n");
273 273 show_stack_log_lvl(NULL, regs, (unsigned long *)sp,
274   - 0, KERN_EMERG);
  274 + 0, KERN_DEFAULT);
275 275  
276   - printk(KERN_EMERG "Code: ");
  276 + printk(KERN_DEFAULT "Code: ");
277 277  
278 278 ip = (u8 *)regs->ip - code_prologue;
279 279 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
... ... @@ -673,7 +673,7 @@
673 673  
674 674 stackend = end_of_stack(tsk);
675 675 if (tsk != &init_task && *stackend != STACK_END_MAGIC)
676   - printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
  676 + printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
677 677  
678 678 tsk->thread.cr2 = address;
679 679 tsk->thread.trap_no = 14;
... ... @@ -684,7 +684,7 @@
684 684 sig = 0;
685 685  
686 686 /* Executive summary in case the body of the oops scrolled away */
687   - printk(KERN_EMERG "CR2: %016lx\n", address);
  687 + printk(KERN_DEFAULT "CR2: %016lx\n", address);
688 688  
689 689 oops_end(flags, regs, sig);
690 690 }
... ... @@ -296,7 +296,7 @@
296 296 if (__this_cpu_read(soft_watchdog_warn) == true)
297 297 return HRTIMER_RESTART;
298 298  
299   - printk(KERN_ERR "BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n",
  299 + printk(KERN_EMERG "BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n",
300 300 smp_processor_id(), duration,
301 301 current->comm, task_pid_nr(current));
302 302 print_modules();
... ... @@ -169,7 +169,7 @@
169 169 return BUG_TRAP_TYPE_WARN;
170 170 }
171 171  
172   - printk(KERN_EMERG "------------[ cut here ]------------\n");
  172 + printk(KERN_DEFAULT "------------[ cut here ]------------\n");
173 173  
174 174 if (file)
175 175 printk(KERN_CRIT "kernel BUG at %s:%u!\n",