reliable stack trace support
Subsystems (3)
PATCH 1/6 reliable stack trace support
These are the generic bits needed to enable reliable stack traces based on Dwarf2-like (.eh_frame) unwind information. Subsequent patches will enable x86-64 and i386 to make use of this.
Thanks to Andi Kleen and Ingo Molnar, who pointed out several possibilities for improvement.
Signed-off-by Jan Beulich <[email protected]>
include/linux/kernel.h +7 -0
@@ -29,6 +29,7 @@ extern const char linux_banner[];#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))#define ALIGN (x,a) (((x)+(a)-1)&~((a)-1)) +#define FIELD_SIZEOF (t, f) (sizeof(((t*)0)->f))#define KERN_EMERG "<0>"/* system is unusable */ #define KERN_ALERT "<1>"/* action must be taken immediately */
@@ -330,6 +331,12 @@ struct sysinfo {/* Force a compilation error if condition is true */ #define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2*!!(condition)])) +/* Force a compilation error if condition is true, but also produce a +result (of value 0 and type size_t), so the expression can be used +e.g. in a structure initializer (or where-ever else comma expressions +aren't permitted). */ +#define BUILD_BUG_ON_ZERO (e) (sizeof(char[1 - 2 * !!(e)]) - 1) +/* Trap pasters of __FUNCTION__ at compile-time */ #define __FUNCTION__ (__func__)
include/linux/module.h +3 -0
@@ -284,6 +284,9 @@ struct module/* The size of the executable code in each section. */ unsigned long init_text_size, core_text_size; +/* The handle returned from unwind_add_table. */ +void *unwind_info; +/* Arch-specific module values */ struct mod_arch_specific arch;
include/linux/unwind.h new file +118 -0
118 lines not on this page · raw message
init/main.c +2 -0
@@ -47,6 +47,7 @@#include <linux/rmap.h> #include <linux/mempolicy.h> #include <linux/key.h> +#include <linux/unwind.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -482,6 +483,7 @@ asmlinkage void __init start_kernel(void __stop___param - __start___param, &unknown_bootoption);sort_main_extable (); +unwind_init ();trap_init ();rcu_init ();init_IRQ ();
kernel/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_OBSOLETE_INTERMODULE) += intermodule.o obj-$(CONFIG_KALLSYMS) += kallsyms.o +obj-$(CONFIG_STACK_UNWIND) += unwind.o obj-$(CONFIG_PM) += power/ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o
kernel/module.c +15 -1
@@ -40,6 +40,7 @@#include <linux/string.h> #include <linux/sched.h> #include <linux/mutex.h> +#include <linux/unwind.h> #include <asm/uaccess.h> #include <asm/semaphore.h> #include <asm/cacheflush.h>
@@ -1051,6 +1052,8 @@ static void free_module(struct module *mremove_sect_attrs (mod);mod_kobject_remove (mod); +unwind_remove_table (mod->unwind_info,0 ); +/* Arch-specific cleanup. */ module_arch_cleanup (mod);
@@ -1412,7 +1415,7 @@ static struct module *load_module(void _unsigned int i, symindex =0 , strindex =0 , setupindex, exindex, exportindex, modindex, obsparmindex, infoindex, gplindex, crcindex, gplcrcindex, versindex, pcpuindex, gplfutureindex, - gplfuturecrcindex; + gplfuturecrcindex, unwindex =0 ;struct module *mod;long err =0 ;void *percpu =NULL , *ptr =NULL ;/* Stops spurious gcc warning */
@@ -1502,6 +1505,9 @@ static struct module *load_module(void _ versindex =find_sec (hdr, sechdrs, secstrings,"__versions" ); infoindex =find_sec (hdr, sechdrs, secstrings,".modinfo" ); pcpuindex =find_pcpusec (hdr, sechdrs, secstrings); +#ifdef ARCH_UNWIND_SECTION_NAME + unwindex =find_sec (hdr, sechdrs, secstrings,ARCH_UNWIND_SECTION_NAME ); +#endif /* Don't keep modinfo section */ sechdrs[infoindex].sh_flags &= ~(unsigned long )SHF_ALLOC ;
@@ -1510,6 +1516,8 @@ static struct module *load_module(void _ sechdrs[symindex].sh_flags |=SHF_ALLOC ; sechdrs[strindex].sh_flags |=SHF_ALLOC ;#endif +if (unwindex) + sechdrs[unwindex].sh_flags |=SHF_ALLOC ;/* Check module struct version now, before we try to use module. */ if (!check_modstruct_version (sechdrs, versindex, mod)) {
@@ -1738,6 +1746,11 @@ static struct module *load_module(void _ goto arch_cleanup;add_sect_attrs (mod, hdr->e_shnum, secstrings, sechdrs); +/* Size of section 0 is 0, so this works well if no unwind info. */ + mod->unwind_info =unwind_add_table (mod, + (void *)sechdrs[unwindex].sh_addr, + sechdrs[unwindex].sh_size); +/* Get rid of temporary copy */ vfree (hdr);
@@ -1836,6 +1849,7 @@ sys_init_module(void __user *umod, mod->state =MODULE_STATE_LIVE ;/* Drop initial reference. */ module_put (mod); +unwind_remove_table (mod->unwind_info,1 );module_free (mod, mod->module_init); mod->module_init =NULL ; mod->init_size =0 ;
kernel/unwind.c new file +915 -0
915 lines not on this page · raw message
lib/Kconfig.debug +9 -1
@@ -188,7 +188,7 @@ config FRAME_POINTER config UNWIND_INFO bool "Compile the kernel with frame unwind information" - depends on !IA64 + depends on !IA64 && !PARISC depends on !MODULES || !(MIPS || PARISC || PPC || SUPERH || SPARC64 || V850) help If you say Y here the resulting kernel image will be slightly larger
@@ -196,6 +196,14 @@ config UNWIND_INFO If you don't debug the kernel, you can say N, but we may not be able to solve problems without frame unwind information or frame pointers. +config STACK_UNWIND + bool "Stack unwind support" + depends on UNWIND_INFO + depends on n + help + This enables more precise stack traces, omitting all unrelated + occurrences of pointers into kernel code from the dump. + config FORCED_INLINING bool "Force gcc to inline functions marked 'inline'" depends on DEBUG_KERNEL