Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

generic bug: use show_regs() instead of dump_stack()

The current generic bug implementation has a call to dump_stack() in case a
WARN_ON(whatever) gets hit. Since report_bug(), which calls dump_stack(),
gets called from an exception handler we can do better: just pass the
pt_regs structure to report_bug() and pass it to show_regs() in case of a
warning. This will give more debug informations like register contents,
etc... In addition this avoids some pointless lines that dump_stack()
emits, since it includes a stack backtrace of the exception handler which
is of no interest in case of a warning. E.g. on s390 the following lines
are currently always present in a stack backtrace if dump_stack() gets
called from report_bug():

[<000000000001517a>] show_trace+0x92/0xe8)
[<0000000000015270>] show_stack+0xa0/0xd0
[<00000000000152ce>] dump_stack+0x2e/0x3c
[<0000000000195450>] report_bug+0x98/0xf8
[<0000000000016cc8>] illegal_op+0x1fc/0x21c
[<00000000000227d6>] sysc_return+0x0/0x10

Acked-by: Jeremy Fitzhardinge <jeremy@goop.org>
Acked-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Kyle McMartin <kyle@parisc-linux.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Heiko Carstens and committed by
Linus Torvalds
608e2619 94bed2a9

+16 -12
+1 -1
arch/avr32/kernel/traps.c
··· 184 184 if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) { 185 185 enum bug_trap_type type; 186 186 187 - type = report_bug(regs->pc); 187 + type = report_bug(regs->pc, regs); 188 188 switch (type) { 189 189 case BUG_TRAP_TYPE_NONE: 190 190 break;
+1 -1
arch/i386/kernel/traps.c
··· 390 390 unsigned long esp; 391 391 unsigned short ss; 392 392 393 - report_bug(regs->eip); 393 + report_bug(regs->eip, regs); 394 394 395 395 printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); 396 396 #ifdef CONFIG_PREEMPT
+1 -1
arch/parisc/kernel/traps.c
··· 302 302 if (unlikely(iir == PARISC_BUG_BREAK_INSN && !user_mode(regs))) { 303 303 /* check if a BUG() or WARN() trapped here. */ 304 304 enum bug_trap_type tt; 305 - tt = report_bug(regs->iaoq[0] & ~3); 305 + tt = report_bug(regs->iaoq[0] & ~3, regs); 306 306 if (tt == BUG_TRAP_TYPE_WARN) { 307 307 regs->iaoq[0] += 4; 308 308 regs->iaoq[1] += 4;
+1 -1
arch/powerpc/kernel/traps.c
··· 777 777 return; 778 778 779 779 if (!(regs->msr & MSR_PR) && /* not user-mode */ 780 - report_bug(regs->nip) == BUG_TRAP_TYPE_WARN) { 780 + report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 781 781 regs->nip += 4; 782 782 return; 783 783 }
+1 -1
arch/ppc/kernel/traps.c
··· 619 619 return; 620 620 621 621 if (!(regs->msr & MSR_PR) && /* not user-mode */ 622 - report_bug(regs->nip) == BUG_TRAP_TYPE_WARN) { 622 + report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { 623 623 regs->nip += 4; 624 624 return; 625 625 }
+1 -1
arch/s390/kernel/traps.c
··· 319 319 else { 320 320 enum bug_trap_type btt; 321 321 322 - btt = report_bug(regs->psw.addr & PSW_ADDR_INSN); 322 + btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs); 323 323 if (btt == BUG_TRAP_TYPE_WARN) 324 324 return; 325 325 die(str, regs, interruption_code);
+1 -1
arch/sh/kernel/traps.c
··· 874 874 void handle_BUG(struct pt_regs *regs) 875 875 { 876 876 enum bug_trap_type tt; 877 - tt = report_bug(regs->pc); 877 + tt = report_bug(regs->pc, regs); 878 878 if (tt == BUG_TRAP_TYPE_WARN) { 879 879 regs->pc += 2; 880 880 return;
+1 -1
arch/x86_64/kernel/traps.c
··· 531 531 unsigned long flags = oops_begin(); 532 532 533 533 if (!user_mode(regs)) 534 - report_bug(regs->rip); 534 + report_bug(regs->rip, regs); 535 535 536 536 __die(str, regs, err); 537 537 oops_end(flags);
+5 -2
include/linux/bug.h
··· 10 10 BUG_TRAP_TYPE_BUG = 2, 11 11 }; 12 12 13 + struct pt_regs; 14 + 13 15 #ifdef CONFIG_GENERIC_BUG 14 16 #include <asm-generic/bug.h> 15 17 ··· 22 20 23 21 const struct bug_entry *find_bug(unsigned long bugaddr); 24 22 25 - enum bug_trap_type report_bug(unsigned long bug_addr); 23 + enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs); 26 24 27 25 int module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, 28 26 struct module *); ··· 33 31 34 32 #else /* !CONFIG_GENERIC_BUG */ 35 33 36 - static inline enum bug_trap_type report_bug(unsigned long bug_addr) 34 + static inline enum bug_trap_type report_bug(unsigned long bug_addr, 35 + struct pt_regs *regs) 37 36 { 38 37 return BUG_TRAP_TYPE_BUG; 39 38 }
+3 -2
lib/bug.c
··· 38 38 #include <linux/list.h> 39 39 #include <linux/module.h> 40 40 #include <linux/bug.h> 41 + #include <linux/sched.h> 41 42 42 43 extern const struct bug_entry __start___bug_table[], __stop___bug_table[]; 43 44 ··· 113 112 return module_find_bug(bugaddr); 114 113 } 115 114 116 - enum bug_trap_type report_bug(unsigned long bugaddr) 115 + enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) 117 116 { 118 117 const struct bug_entry *bug; 119 118 const char *file; ··· 148 147 "[verbose debug info unavailable]\n", 149 148 (void *)bugaddr); 150 149 151 - dump_stack(); 150 + show_regs(regs); 152 151 return BUG_TRAP_TYPE_WARN; 153 152 } 154 153