kernel-ark/include
Jeremy Fitzhardinge 7664c5a1da [PATCH] Generic BUG implementation
This patch adds common handling for kernel BUGs, for use by architectures as
they wish.  The code is derived from arch/powerpc.

The advantages of having common BUG handling are:
 - consistent BUG reporting across architectures
 - shared implementation of out-of-line file/line data
 - implement CONFIG_DEBUG_BUGVERBOSE consistently

This means that in inline impact of BUG is just the illegal instruction
itself, which is an improvement for i386 and x86-64.

A BUG is represented in the instruction stream as an illegal instruction,
which has file/line information associated with it.  This extra information is
stored in the __bug_table section in the ELF file.

When the kernel gets an illegal instruction, it first confirms it might
possibly be from a BUG (ie, in kernel mode, the right illegal instruction).
It then calls report_bug().  This searches __bug_table for a matching
instruction pointer, and if found, prints the corresponding file/line
information.  If report_bug() determines that it wasn't a BUG which caused the
trap, it returns BUG_TRAP_TYPE_NONE.

Some architectures (powerpc) implement WARN using the same mechanism; if the
illegal instruction was the result of a WARN, then report_bug(Q) returns
CONFIG_DEBUG_BUGVERBOSE; otherwise it returns BUG_TRAP_TYPE_BUG.

lib/bug.c keeps a list of loaded modules which can be searched for __bug_table
entries.  The architecture must call
module_bug_finalize()/module_bug_cleanup() from its corresponding
module_finalize/cleanup functions.

Unsetting CONFIG_DEBUG_BUGVERBOSE will reduce the kernel size by some amount.
At the very least, filename and line information will not be recorded for each
but, but architectures may decide to store no extra information per BUG at
all.

Unfortunately, gcc doesn't have a general way to mark an asm() as noreturn, so
architectures will generally have to include an infinite loop (or similar) in
the BUG code, so that gcc knows execution won't continue beyond that point.
gcc does have a __builtin_trap() operator which may be useful to achieve the
same effect, unfortunately it cannot be used to actually implement the BUG
itself, because there's no way to get the instruction's address for use in
generating the __bug_table entry.

[randy.dunlap@oracle.com: Handle BUG=n, GENERIC_BUG=n to prevent build errors]
[bunk@stusta.de: include/linux/bug.h must always #include <linux/module.h]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@muc.de>
Cc: Hugh Dickens <hugh@veritas.com>
Cc: Michael Ellerman <michael@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 08:28:39 -08:00
..
acpi [PATCH] slab: remove kmem_cache_t 2006-12-07 08:39:25 -08:00
asm-alpha [PATCH] Pass struct dev pointer to dma_cache_sync() 2006-12-07 08:39:41 -08:00
asm-arm Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm 2006-12-07 15:40:39 -08:00
asm-arm26 [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-avr32 Merge branch 'for-linus' of master.kernel.org:/home/rmk/linux-2.6-arm 2006-12-07 15:40:39 -08:00
asm-cris [PATCH] include/asm-cris/: "extern inline" -> "static inline" 2006-12-07 08:39:45 -08:00
asm-frv [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-generic [PATCH] Generic BUG implementation 2006-12-08 08:28:39 -08:00
asm-h8300 [PATCH] include/asm-h8300/: "extern inline" -> "static inline" 2006-12-07 08:39:45 -08:00
asm-i386 Merge branch 'for-linus' of git://one.firstfloor.org/home/andi/git/linux-2.6 2006-12-07 08:59:11 -08:00
asm-ia64 Merge branch 'release' of master.kernel.org:/pub/scm/linux/kernel/git/aegl/linux-2.6 2006-12-07 15:39:22 -08:00
asm-m32r [PATCH] m32r: bootloader support for OPSPUT platform 2006-12-08 08:28:37 -08:00
asm-m68k [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-m68knommu [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-mips [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-parisc [PATCH] Pass struct dev pointer to dma_cache_sync() 2006-12-07 08:39:41 -08:00
asm-powerpc [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-ppc [PATCH] mm: pagefault_{disable,enable}() 2006-12-07 08:39:21 -08:00
asm-s390 [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-sh [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-sh64 [PATCH] cleanup asm/setup.h userspace visibility 2006-12-07 08:39:46 -08:00
asm-sparc [PATCH] remove kernel syscalls 2006-12-07 08:39:37 -08:00
asm-sparc64 [PATCH] Pass struct dev pointer to dma_cache_sync() 2006-12-07 08:39:41 -08:00
asm-um [PATCH] Pass struct dev pointer to dma_cache_sync() 2006-12-07 08:39:41 -08:00
asm-v850 [PATCH] remove kernel syscalls 2006-12-07 08:39:37 -08:00
asm-x86_64 Merge branch 'for-linus' of git://one.firstfloor.org/home/andi/git/linux-2.6 2006-12-07 08:59:11 -08:00
asm-xtensa [PATCH] Pass struct dev pointer to dma_cache_sync() 2006-12-07 08:39:41 -08:00
crypto [CRYPTO] lib: table driven multiplications in GF(2^128) 2006-12-06 18:38:55 -08:00
keys
linux [PATCH] Generic BUG implementation 2006-12-08 08:28:39 -08:00
math-emu
media
mtd
net Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6 2006-12-07 09:05:15 -08:00
pcmcia [PATCH] pcmcia: multifunction card handling fixes 2006-12-04 20:09:15 -05:00
rdma IB/cm: Fix automatic path migration support 2006-11-29 15:33:10 -08:00
rxrpc
scsi [PATCH] slab: remove kmem_cache_t 2006-12-07 08:39:25 -08:00
sound Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 2006-12-05 17:01:28 +00:00
video
Kbuild