Commit 73c9ceab authored by Jeremy Fitzhardinge's avatar Jeremy Fitzhardinge Committed by Paul Mackerras

[POWERPC] Generic BUG for powerpc

This makes powerpc use the generic BUG machinery.  The biggest reports the
function name, since it is redundant with kallsyms, and not needed in general.

There is an overall reduction of code, since module_32/64 duplicated several
functions.

Unfortunately there's no way to tell gcc that BUG won't return, so the BUG
macro includes a goto loop.  This will generate a real jmp instruction, which
is never used.

[akpm@osdl.org: build fix]
[paulus@samba.org: remove infinite loop in BUG_ON]
Signed-off-by: default avatarJeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 973c1fab
...@@ -99,6 +99,11 @@ config AUDIT_ARCH ...@@ -99,6 +99,11 @@ config AUDIT_ARCH
bool bool
default y default y
config GENERIC_BUG
bool
default y
depends on BUG
config DEFAULT_UIMAGE config DEFAULT_UIMAGE
bool bool
help help
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/bug.h>
#include "setup.h" #include "setup.h"
...@@ -290,23 +291,11 @@ int module_finalize(const Elf_Ehdr *hdr, ...@@ -290,23 +291,11 @@ int module_finalize(const Elf_Ehdr *hdr,
struct module *me) struct module *me)
{ {
const Elf_Shdr *sect; const Elf_Shdr *sect;
int err;
me->arch.bug_table = NULL; err = module_bug_finalize(hdr, sechdrs, me);
me->arch.num_bugs = 0; if (err) /* never true, currently */
return err;
/* Find the __bug_table section, if present */
sect = find_section(hdr, sechdrs, "__bug_table");
if (sect != NULL) {
me->arch.bug_table = (void *) sect->sh_addr;
me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
}
/*
* Strictly speaking this should have a spinlock to protect against
* traversals, but since we only traverse on BUG()s, a spinlock
* could potentially lead to deadlock and thus be counter-productive.
*/
list_add(&me->arch.bug_list, &module_bug_list);
/* Apply feature fixups */ /* Apply feature fixups */
sect = find_section(hdr, sechdrs, "__ftr_fixup"); sect = find_section(hdr, sechdrs, "__ftr_fixup");
...@@ -320,7 +309,7 @@ int module_finalize(const Elf_Ehdr *hdr, ...@@ -320,7 +309,7 @@ int module_finalize(const Elf_Ehdr *hdr,
void module_arch_cleanup(struct module *mod) void module_arch_cleanup(struct module *mod)
{ {
list_del(&mod->arch.bug_list); module_bug_cleanup(mod);
} }
struct bug_entry *module_find_bug(unsigned long bugaddr) struct bug_entry *module_find_bug(unsigned long bugaddr)
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/moduleloader.h> #include <linux/moduleloader.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/bug.h>
#include <asm/module.h> #include <asm/module.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/firmware.h> #include <asm/firmware.h>
...@@ -439,23 +440,11 @@ int module_finalize(const Elf_Ehdr *hdr, ...@@ -439,23 +440,11 @@ int module_finalize(const Elf_Ehdr *hdr,
const Elf_Shdr *sechdrs, struct module *me) const Elf_Shdr *sechdrs, struct module *me)
{ {
const Elf_Shdr *sect; const Elf_Shdr *sect;
int err;
me->arch.bug_table = NULL; err = module_bug_finalize(hdr, sechdrs, me);
me->arch.num_bugs = 0; if (err)
return err;
/* Find the __bug_table section, if present */
sect = find_section(hdr, sechdrs, "__bug_table");
if (sect != NULL) {
me->arch.bug_table = (void *) sect->sh_addr;
me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
}
/*
* Strictly speaking this should have a spinlock to protect against
* traversals, but since we only traverse on BUG()s, a spinlock
* could potentially lead to deadlock and thus be counter-productive.
*/
list_add(&me->arch.bug_list, &module_bug_list);
/* Apply feature fixups */ /* Apply feature fixups */
sect = find_section(hdr, sechdrs, "__ftr_fixup"); sect = find_section(hdr, sechdrs, "__ftr_fixup");
...@@ -475,7 +464,7 @@ int module_finalize(const Elf_Ehdr *hdr, ...@@ -475,7 +464,7 @@ int module_finalize(const Elf_Ehdr *hdr,
void module_arch_cleanup(struct module *mod) void module_arch_cleanup(struct module *mod)
{ {
list_del(&mod->arch.bug_list); module_bug_cleanup(mod);
} }
struct bug_entry *module_find_bug(unsigned long bugaddr) struct bug_entry *module_find_bug(unsigned long bugaddr)
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/kexec.h> #include <linux/kexec.h>
#include <linux/backlight.h> #include <linux/backlight.h>
#include <linux/bug.h>
#include <asm/kdebug.h> #include <asm/kdebug.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
...@@ -727,54 +728,9 @@ static int emulate_instruction(struct pt_regs *regs) ...@@ -727,54 +728,9 @@ static int emulate_instruction(struct pt_regs *regs)
return -EINVAL; return -EINVAL;
} }
/* int is_valid_bugaddr(unsigned long addr)
* Look through the list of trap instructions that are used for BUG(),
* BUG_ON() and WARN_ON() and see if we hit one. At this point we know
* that the exception was caused by a trap instruction of some kind.
* Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
* otherwise.
*/
extern struct bug_entry __start___bug_table[], __stop___bug_table[];
#ifndef CONFIG_MODULES
#define module_find_bug(x) NULL
#endif
struct bug_entry *find_bug(unsigned long bugaddr)
{ {
struct bug_entry *bug; return is_kernel_addr(addr);
for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
if (bugaddr == bug->bug_addr)
return bug;
return module_find_bug(bugaddr);
}
static int check_bug_trap(struct pt_regs *regs)
{
struct bug_entry *bug;
unsigned long addr;
if (regs->msr & MSR_PR)
return 0; /* not in kernel */
addr = regs->nip; /* address of trap instruction */
if (addr < PAGE_OFFSET)
return 0;
bug = find_bug(regs->nip);
if (bug == NULL)
return 0;
if (bug->line & BUG_WARNING_TRAP) {
/* this is a WARN_ON rather than BUG/BUG_ON */
printk(KERN_ERR "Badness in %s at %s:%ld\n",
bug->function, bug->file,
bug->line & ~BUG_WARNING_TRAP);
dump_stack();
return 1;
}
printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
bug->function, bug->file, bug->line);
return 0;
} }
void __kprobes program_check_exception(struct pt_regs *regs) void __kprobes program_check_exception(struct pt_regs *regs)
...@@ -810,7 +766,9 @@ void __kprobes program_check_exception(struct pt_regs *regs) ...@@ -810,7 +766,9 @@ void __kprobes program_check_exception(struct pt_regs *regs)
return; return;
if (debugger_bpt(regs)) if (debugger_bpt(regs))
return; return;
if (check_bug_trap(regs)) {
if (!(regs->msr & MSR_PR) && /* not user-mode */
report_bug(regs->nip) == BUG_TRAP_TYPE_WARN) {
regs->nip += 4; regs->nip += 4;
return; return;
} }
......
...@@ -62,11 +62,7 @@ SECTIONS ...@@ -62,11 +62,7 @@ SECTIONS
__stop___ex_table = .; __stop___ex_table = .;
} }
__bug_table : { BUG_TABLE
__start___bug_table = .;
*(__bug_table)
__stop___bug_table = .;
}
/* /*
* Init sections discarded at runtime * Init sections discarded at runtime
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/sysrq.h> #include <linux/sysrq.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/bug.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include <asm/string.h> #include <asm/string.h>
...@@ -35,7 +36,6 @@ ...@@ -35,7 +36,6 @@
#include <asm/cputable.h> #include <asm/cputable.h>
#include <asm/rtas.h> #include <asm/rtas.h>
#include <asm/sstep.h> #include <asm/sstep.h>
#include <asm/bug.h>
#include <asm/irq_regs.h> #include <asm/irq_regs.h>
#include <asm/spu.h> #include <asm/spu.h>
#include <asm/spu_priv1.h> #include <asm/spu_priv1.h>
...@@ -1346,7 +1346,7 @@ static void backtrace(struct pt_regs *excp) ...@@ -1346,7 +1346,7 @@ static void backtrace(struct pt_regs *excp)
static void print_bug_trap(struct pt_regs *regs) static void print_bug_trap(struct pt_regs *regs)
{ {
struct bug_entry *bug; const struct bug_entry *bug;
unsigned long addr; unsigned long addr;
if (regs->msr & MSR_PR) if (regs->msr & MSR_PR)
...@@ -1357,11 +1357,11 @@ static void print_bug_trap(struct pt_regs *regs) ...@@ -1357,11 +1357,11 @@ static void print_bug_trap(struct pt_regs *regs)
bug = find_bug(regs->nip); bug = find_bug(regs->nip);
if (bug == NULL) if (bug == NULL)
return; return;
if (bug->line & BUG_WARNING_TRAP) if (is_warning_bug(bug))
return; return;
printf("kernel BUG in %s at %s:%d!\n", printf("kernel BUG at %s:%u!\n",
bug->function, bug->file, (unsigned int)bug->line); bug->file, bug->line);
} }
void excprint(struct pt_regs *fp) void excprint(struct pt_regs *fp)
......
...@@ -13,36 +13,39 @@ ...@@ -13,36 +13,39 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
struct bug_entry {
unsigned long bug_addr;
long line;
const char *file;
const char *function;
};
struct bug_entry *find_bug(unsigned long bugaddr);
/*
* If this bit is set in the line number it means that the trap
* is for WARN_ON rather than BUG or BUG_ON.
*/
#define BUG_WARNING_TRAP 0x1000000
#ifdef CONFIG_BUG #ifdef CONFIG_BUG
/* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
sizeof(struct bug_entry), respectively */
#ifdef CONFIG_DEBUG_BUGVERBOSE
#define _EMIT_BUG_ENTRY \
".section __bug_table,\"a\"\n" \
"2:\t" PPC_LONG "1b, %0\n" \
"\t.short %1, %2\n" \
".org 2b+%3\n" \
".previous\n"
#else
#define _EMIT_BUG_ENTRY \
".section __bug_table,\"a\"\n" \
"2:\t" PPC_LONG "1b\n" \
"\t.short %2\n" \
".org 2b+%3\n" \
".previous\n"
#endif
/* /*
* BUG_ON() and WARN_ON() do their best to cooperate with compile-time * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
* optimisations. However depending on the complexity of the condition * optimisations. However depending on the complexity of the condition
* some compiler versions may not produce optimal results. * some compiler versions may not produce optimal results.
*/ */
#define BUG() do { \ #define BUG() do { \
__asm__ __volatile__( \ __asm__ __volatile__( \
"1: twi 31,0,0\n" \ "1: twi 31,0,0\n" \
".section __bug_table,\"a\"\n" \ _EMIT_BUG_ENTRY \
"\t"PPC_LONG" 1b,%0,%1,%2\n" \ : : "i" (__FILE__), "i" (__LINE__), \
".previous" \ "i" (0), "i" (sizeof(struct bug_entry))); \
: : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \ for(;;) ; \
} while (0) } while (0)
#define BUG_ON(x) do { \ #define BUG_ON(x) do { \
...@@ -51,23 +54,21 @@ struct bug_entry *find_bug(unsigned long bugaddr); ...@@ -51,23 +54,21 @@ struct bug_entry *find_bug(unsigned long bugaddr);
BUG(); \ BUG(); \
} else { \ } else { \
__asm__ __volatile__( \ __asm__ __volatile__( \
"1: "PPC_TLNEI" %0,0\n" \ "1: "PPC_TLNEI" %4,0\n" \
".section __bug_table,\"a\"\n" \ _EMIT_BUG_ENTRY \
"\t"PPC_LONG" 1b,%1,%2,%3\n" \ : : "i" (__FILE__), "i" (__LINE__), "i" (0), \
".previous" \ "i" (sizeof(struct bug_entry)), \
: : "r" ((long)(x)), "i" (__LINE__), \ "r" ((long)(x))); \
"i" (__FILE__), "i" (__FUNCTION__)); \
} \ } \
} while (0) } while (0)
#define __WARN() do { \ #define __WARN() do { \
__asm__ __volatile__( \ __asm__ __volatile__( \
"1: twi 31,0,0\n" \ "1: twi 31,0,0\n" \
".section __bug_table,\"a\"\n" \ _EMIT_BUG_ENTRY \
"\t"PPC_LONG" 1b,%0,%1,%2\n" \ : : "i" (__FILE__), "i" (__LINE__), \
".previous" \ "i" (BUGFLAG_WARNING), \
: : "i" (__LINE__ + BUG_WARNING_TRAP), \ "i" (sizeof(struct bug_entry))); \
"i" (__FILE__), "i" (__FUNCTION__)); \
} while (0) } while (0)
#define WARN_ON(x) ({ \ #define WARN_ON(x) ({ \
...@@ -77,13 +78,12 @@ struct bug_entry *find_bug(unsigned long bugaddr); ...@@ -77,13 +78,12 @@ struct bug_entry *find_bug(unsigned long bugaddr);
__WARN(); \ __WARN(); \
} else { \ } else { \
__asm__ __volatile__( \ __asm__ __volatile__( \
"1: "PPC_TLNEI" %0,0\n" \ "1: "PPC_TLNEI" %4,0\n" \
".section __bug_table,\"a\"\n" \ _EMIT_BUG_ENTRY \
"\t"PPC_LONG" 1b,%1,%2,%3\n" \ : : "i" (__FILE__), "i" (__LINE__), \
".previous" \ "i" (BUGFLAG_WARNING), \
: : "r" (__ret_warn_on), \ "i" (sizeof(struct bug_entry)), \
"i" (__LINE__ + BUG_WARNING_TRAP), \ "r" (__ret_warn_on)); \
"i" (__FILE__), "i" (__FUNCTION__)); \
} \ } \
unlikely(__ret_warn_on); \ unlikely(__ret_warn_on); \
}) })
......
...@@ -46,8 +46,6 @@ struct mod_arch_specific { ...@@ -46,8 +46,6 @@ struct mod_arch_specific {
unsigned int num_bugs; unsigned int num_bugs;
}; };
extern struct bug_entry *module_find_bug(unsigned long bugaddr);
/* /*
* Select ELF headers. * Select ELF headers.
* Make empty section for module_frob_arch_sections to expand. * Make empty section for module_frob_arch_sections to expand.
......
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