Info dump on Oops or panic()
PATCH 1/1 Info dump on Oops or panic()
From: Joshua Wise <[email protected]>
Background:
When managing a large number of servers, as Google does, it's sometimes useful to get an "at-a-glance" view of a machine when it crashes. When no other post-mortem is possible, it's often useful to know how long the machine has been powered on, which kernel it was running, and possibly other information that a driver may have logged. Up until now, there was no real way to do this other than to keep statistics outside to the machine.
Description:
This patch adds a call chain to be invoked when the system oopses or panics. Traps have been added to i386 and x86_64 kernels, but it should be trivial to add support for more architectures. Two sample notifiers have been added -- an uptime printer, and a utsname printer for showing various statistics about the running system.
Remaining issues:
* Is do_posix_clock_monotonic_gettime really the right API?
* Should this be on by default, or a disablable Kconfig entry?
Testing:
I accidentally built my testing kernel without the IDE drivers. It panic()ed immediately, and informed me that my uptime was 0.38 seconds.
Credits:
This code was mainly written by Mike Waychison <[email protected]> and Masoud Sharbiani <[email protected]>.
Patch:
This patch is against git 48d8d7ee5dd17c64833e0343ab4ae8ef01cc2648.
--
arch/i386/kernel/process.c +1 -0
@@ -325,6 +325,8 @@ void show_regs(struct pt_regs * regs) cr4 =read_cr4_safe ();printk ("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n" , cr0, cr2, cr3, cr4);show_trace (NULL , regs, ®s->esp); + +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }/*
arch/i386/kernel/traps.c +1 -0
@@ -341,6 +341,8 @@ void show_registers(struct pt_regs *regs } }printk ("\n" ); + +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }int is_valid_bugaddr (unsigned long eip)
arch/x86_64/kernel/process.c +1 -0
@@ -356,6 +356,7 @@ void show_regs(struct pt_regs *regs)printk ("CPU %d:" ,smp_processor_id ());__show_regs (regs);show_trace (NULL , regs, (void *)(regs +1 )); +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }/*
arch/x86_64/kernel/traps.c +1 -0
@@ -439,6 +439,8 @@ bad: } }printk ("\n" ); + +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }int is_valid_bugaddr (unsigned long rip)
include/linux/kernel.h +1 -0
@@ -104,6 +104,7 @@ #define abs(x) ({ \ })extern struct atomic_notifier_head panic_notifier_list; +extern struct atomic_notifier_head info_dumper_list;extern long (*panic_blink)(long time); NORET_TYPE void panic(const char * fmt, ...) __attribute__ ((NORET_AND format (printf, 1, 2)));
kernel/panic.c +1 -0
@@ -97,6 +97,7 @@ #ifdef CONFIG_SMP#endif atomic_notifier_call_chain (&panic_notifier_list,0 , buf); +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL );if (!panic_blink) panic_blink = no_blink;
kernel/sys.c +32 -0
@@ -98,6 +98,39 @@ struct pid *cad_pid;EXPORT_SYMBOL (cad_pid);/* +* Notifier list for kernel code which wants to printk hardware specific +* information at Oops or panic time. +*/ + +ATOMIC_NOTIFIER_HEAD (info_dumper_list); +EXPORT_SYMBOL (info_dumper_list); + +/* +* Dump out UTS info on oops / panic. +*/ + +static int dump_utsname(struct notifier_block *self, unsigned long v, void *p) +{ +printk ("%s %s %s %s %s %s\n" , +utsname ()->sysname, +utsname ()->nodename, +utsname ()->release, +utsname ()->version, +utsname ()->machine, +utsname ()->domainname); +return 0 ; +} + +static struct notifier_block utsname_notifier; + +static int __init register_utsname_dump (void ) { + utsname_notifier.notifier_call = dump_utsname; +atomic_notifier_chain_register (&info_dumper_list, &utsname_notifier); +return 0 ; +} +__initcall (register_utsname_dump); + +/* * Notifier list for kernel code which wants to be called * at shutdown. This is used to stop any idling DMA operations * and the like.
kernel/time.c +26 -0
@@ -31,6 +31,7 @@ #include <linux/module.h>#include <linux/timex.h> #include <linux/capability.h> #include <linux/errno.h> +#include <linux/notifier.h> #include <linux/syscalls.h> #include <linux/security.h> #include <linux/fs.h>
@@ -744,3 +745,33 @@ EXPORT_SYMBOL(get_jiffies_64);#endif EXPORT_SYMBOL (jiffies); + +/* +* Dump out uptime info on oops / panic. +* + * FIXME: Should I be just using get_jiffies64()? what if the lock there +* is damaged beyond any recognition? +*/ +static int dump_uptime (struct notifier_block *self,unsigned long v,void *p) +{ +struct timespec uptime; +/* The logic below is very much like how kernel + * prepares /proc/uptime. + */ +do_posix_clock_monotonic_gettime (&uptime); +printk ("Uptime(seconds): %lu.%02lu\n" , + (unsigned long ) uptime.tv_sec, + (uptime.tv_nsec / (NSEC_PER_SEC /100 ))); + +return 0 ; +} + +static struct notifier_block uptime_notifier; + +static int __init register_uptime_dump (void ) { + uptime_notifier.notifier_call = dump_uptime; +atomic_notifier_chain_register (&info_dumper_list, &uptime_notifier); +return 0 ; +} +__initcall (register_uptime_dump); +
arch/x86_64/kernel/process.c void show_regs(struct pt_regs *regs) · line 361
Quoted 9 lines · Joshua Wise
arch/x86_64/kernel/process.c +1
-0@@ -356,6 +356,7 @@ void show_regs(struct pt_regs *regs)printk ("CPU %d:" ,smp_processor_id ());__show_regs (regs);show_trace (NULL , regs, (void *)(regs +1 )); +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }
woah woah woah. This could push critical bits of the register dump or stacktrace off the screen... Barring any other problems with the patch, this should probably be dumped in the oops header, not trailing it where it could hide critical debugging info.
Regards,
Kyle M.
Joshua Wise
Acked-by Mike WaychisonQuoted 4 lines · Kyle McMartin
woah woah woah. This could push critical bits of the register dump or stacktrace off the screen... Barring any other problems with the patch, this should probably be dumped in the oops header, not trailing it where it could hide critical debugging info.
Okay, fair enough. Fixed version follows. I also fixed some checkpatch issues that I missed before.
However, please note that in general, the info dumped by this will consist of only a few lines. In our implementations, I believe that we only dump one line per notifier.
joshua
--
From: Joshua Wise <[email protected]>
Version: 2
Background:
When managing a large number of servers, as Google does, it's sometimes useful to get an "at-a-glance" view of a machine when it crashes. When no other post-mortem is possible, it's often useful to know how long the machine has been powered on, which kernel it was running, and possibly other information that a driver may have logged. Up until now, there was no real way to do this other than to keep statistics outside to the machine.
Description:
This patch adds a call chain to be invoked when the system oopses or panics. Traps have been added to i386 and x86_64 kernels, but it should be trivial to add support for more architectures. Two sample notifiers have been added -- an uptime printer, and a utsname printer for showing various statistics about the running system.
Remaining issues:
* Is do_posix_clock_monotonic_gettime really the right API?
* Should this be on by default, or a disablable Kconfig entry?
Testing:
I accidentally built my testing kernel without the IDE drivers. It panic()ed immediately, and informed me that my uptime was 0.38 seconds.
Credits:
This code was mainly written by Mike Waychison <[email protected]> and Masoud Sharbiani <[email protected]>.
Changelog:
v2 -- fixed some checkpatch issues. Moved dumping to before Oopses, as per the suggestion of Kyle McMartin <[email protected]>.
Patch:
This patch is against git 48d8d7ee5dd17c64833e0343ab4ae8ef01cc2648.
--
arch/i386/kernel/process.c +2 -0
@@ -301,6 +301,8 @@ void show_regs(struct pt_regs * regs) {unsigned long cr0 =0L , cr2 =0L , cr3 =0L , cr4 =0L ; +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); +printk ("\n" );printk ("Pid: %d, comm: %20s\n" , current->pid, current->comm);printk ("EIP: %04x:[<%08lx>] CPU: %d\n" ,0xffff & regs->xcs,regs->eip,smp_processor_id ());
arch/i386/kernel/traps.c +3 -0
@@ -289,6 +289,9 @@ void show_registers(struct pt_regs *regs ss = regs->xss &0xffff ; }print_modules (); + +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); + printk(KERN_EMERG "CPU: %d\n" KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n" KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n",
arch/x86_64/kernel/process.c +1 -0
@@ -353,6 +353,7 @@ void __show_regs(struct pt_regs * regs)void show_regs (struct pt_regs *regs) { +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL );printk ("CPU %d:" ,smp_processor_id ());__show_regs (regs);show_trace (NULL , regs, (void *)(regs +1 ));
arch/x86_64/kernel/traps.c +2 -0
@@ -410,6 +410,8 @@ void show_registers(struct pt_regs *regsconst int cpu =smp_processor_id ();struct task_struct *cur =cpu_pda (cpu)->pcurrent; +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); + rsp = regs->rsp;printk ("CPU %d " , cpu);__show_regs (regs);
include/asm-blackfin/macros.h deleted +0 -0
include/linux/kernel.h +1 -0
@@ -104,6 +104,7 @@ #define abs(x) ({ \ })extern struct atomic_notifier_head panic_notifier_list; +extern struct atomic_notifier_head info_dumper_list;extern long (*panic_blink)(long time); NORET_TYPE void panic(const char * fmt, ...) __attribute__ ((NORET_AND format (printf, 1, 2)));
kernel/panic.c +1 -0
@@ -97,6 +97,7 @@ #ifdef CONFIG_SMP#endif atomic_notifier_call_chain (&panic_notifier_list,0 , buf); +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL );if (!panic_blink) panic_blink = no_blink;
kernel/sys.c +33 -0
@@ -98,6 +98,39 @@ struct pid *cad_pid;EXPORT_SYMBOL (cad_pid);/* +* Notifier list for kernel code which wants to printk hardware specific +* information at Oops or panic time. +*/ + +ATOMIC_NOTIFIER_HEAD (info_dumper_list); +EXPORT_SYMBOL (info_dumper_list); + +/* +* Dump out UTS info on oops / panic. +*/ + +static int dump_utsname (struct notifier_block *self,unsigned long v,void *p) +{ +printk (KERN_EMERG "%s %s %s %s %s %s\n" , +utsname ()->sysname, +utsname ()->nodename, +utsname ()->release, +utsname ()->version, +utsname ()->machine, +utsname ()->domainname); +return 0 ; +} + +static struct notifier_block utsname_notifier; + +static int __init register_utsname_dump (void ) { + utsname_notifier.notifier_call = dump_utsname; +atomic_notifier_chain_register (&info_dumper_list, &utsname_notifier); +return 0 ; +} +__initcall (register_utsname_dump); + +/* * Notifier list for kernel code which wants to be called * at shutdown. This is used to stop any idling DMA operations * and the like.
kernel/time.c +32 -0
@@ -31,6 +31,7 @@ #include <linux/module.h>#include <linux/timex.h> #include <linux/capability.h> #include <linux/errno.h> +#include <linux/notifier.h> #include <linux/syscalls.h> #include <linux/security.h> #include <linux/fs.h>
@@ -744,3 +745,34 @@ EXPORT_SYMBOL(get_jiffies_64);#endif EXPORT_SYMBOL (jiffies); + +/* +* Dump out uptime info on oops / panic. +* +* FIXME: Should I be just using get_jiffies64()? what if the lock there +* is damaged beyond any recognition? +*/ + +static int dump_uptime (struct notifier_block *self,unsigned long v,void *p) +{ +struct timespec uptime; +/* The logic below is very much like how kernel +* prepares /proc/uptime. +*/ +do_posix_clock_monotonic_gettime (&uptime); +printk (KERN_EMERG "Uptime (seconds): %lu.%02lu\n" , + (unsigned long ) uptime.tv_sec, + (uptime.tv_nsec / (NSEC_PER_SEC /100 ))); + +return 0 ; +} + +static struct notifier_block uptime_notifier; + +static int __init register_uptime_dump (void ) { + uptime_notifier.notifier_call = dump_uptime; +atomic_notifier_chain_register (&info_dumper_list, &uptime_notifier); +return 0 ; +} +__initcall (register_uptime_dump); +
Quoted 38 lines · On Thu, 28 Jun 2007 16:12:23 -0700 (PDT) Joshua Wise <[email protected]> wrote:
Version: 2
Background:
When managing a large number of servers, as Google does, it's sometimes useful to get an "at-a-glance" view of a machine when it crashes. When no other post-mortem is possible, it's often useful to know how long the machine has been powered on, which kernel it was running, and possibly other information that a driver may have logged. Up until now, there was no real way to do this other than to keep statistics outside to the machine.Description:
This patch adds a call chain to be invoked when the system oopses or panics. Traps have been added to i386 andx86_64kernels, but it should be trivial to add support for more architectures. Two sample notifiers have been added -- an uptime printer, and a utsname printer for showing various statistics about the running system.Remaining issues:
* Isdo_posix_clock_monotonic_gettimereally the right API?
* Should this be on by default, or a disablableKconfigentry?Testing:
I accidentally built my testing kernel without the IDE drivers. It panic()ed immediately, and informed me that my uptime was 0.38 seconds.Credits:
This code was mainly written by Mike Waychison <[email protected]> and Masoud Sharbiani <[email protected]>.Changelog:
v2 -- fixed some checkpatch issues. Moved dumping to before Oopses, as per the suggestion of Kyle McMartin <[email protected]>.arch/i386/kernel/process.c +0
-0
arch/i386/kernel/process.c void show_regs(struct pt_regs * regs) · line 301
Quoted 1 line
arch/i386/kernel/process.c +0
-0@@ -301,6 +301,8 @@ void show_regs(struct pt_regs * regs) {
Your email client is doing space-stuffing. It's easy enough to fix at this end, but even easier if you fix it ;)
arch/i386/kernel/process.c void show_regs(struct pt_regs * regs) · line 305
Quoted 4 lines
arch/i386/kernel/process.c +2
-0unsigned long cr0 =0L , cr2 =0L , cr3 =0L , cr4 =0L ; +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); +
I worry a bit about doing _anything_ extra at oops-time. It just decreases the chances of the kernel generating the info which we want.
So... Please consider abandoning the notifier-chain and just go for a simple function call.
If people want to add extra goodies later on, well, they need to patch the kernel anyway so they can patch your newly-added function rather than hooking into the notifier chain.
arch/i386/kernel/process.c void show_regs(struct pt_regs * regs)
Quoted 9 lines
arch/i386/kernel/process.c +6
-0EXPORT_SYMBOL (cad_pid);/* +* Notifier list for kernel code which wants to printk hardware specific +* information at Oops or panic time. +*/ + +ATOMIC_NOTIFIER_HEAD (info_dumper_list); +EXPORT_SYMBOL (info_dumper_list);
That export isn't needed.
Quoted 5 lines
arch/i386/kernel/process.c +5
-0+/* +* Dump out UTS info on oops / panic. +*/ + +static int dump_utsname (struct notifier_block *self,unsigned long v,void *p)
arch/i386/kernel/process.c
Quoted 10 lines
arch/i386/kernel/process.c +10
-0+{ +printk (KERN_EMERG "%s %s %s %s %s %s\n" , +utsname ()->sysname, +utsname ()->nodename, +utsname ()->release, +utsname ()->version, +utsname ()->machine, +utsname ()->domainname); +return 0 ; +}
Again, a deref of current->nsproxy->uts_ns->name at oops-time has risks.
This string could be precalculated, no?
arch/i386/kernel/process.c
Quoted 3 lines
arch/i386/kernel/process.c +3
-0+static struct notifier_block utsname_notifier; + +static int __init register_utsname_dump (void ) {
<wishes that all nooglers got a copy of K&R>
arch/i386/kernel/process.c
Quoted 5 lines
arch/i386/kernel/process.c +5
-0+ utsname_notifier.notifier_call = dump_utsname; +atomic_notifier_chain_register (&info_dumper_list, &utsname_notifier); +return 0 ; +} +__initcall (register_utsname_dump);
module_init() is a bit more modern, but equivalent.
Quoted 10 lines
arch/i386/kernel/process.c +10
-0+/* +* Dump out uptime info on oops / panic. +* +* FIXME: Should I be just using get_jiffies64()? what if the lock there +* is damaged beyond any recognition? +*/ + +static int dump_uptime (struct notifier_block *self,unsigned long v,void *p) +{ +struct timespec uptime;
arch/i386/kernel/process.c
Quoted 10 lines
arch/i386/kernel/process.c +10
-0+/* The logic below is very much like how kernel +* prepares /proc/uptime. +*/ +do_posix_clock_monotonic_gettime (&uptime); +printk (KERN_EMERG "Uptime (seconds): %lu.%02lu\n" , + (unsigned long ) uptime.tv_sec, + (uptime.tv_nsec / (NSEC_PER_SEC /100 ))); + +return 0 ; +}
do_posix_clock_monotonic_gettime() takes xtime_lock. So if the kernel oopses while holding xtime_lock we don't get to see the oops. This is bad.
I don't know what to do here. It will be hard to find a read-the-time function which is a) lockless and b) available on all architectures and configs.
If you can find a way to use plain old jiffies, that'd be good.
arch/i386/kernel/process.c
Quoted 3 lines
arch/i386/kernel/process.c +3
-0+static struct notifier_block uptime_notifier; + +static int __init register_uptime_dump (void ) {
thwap
arch/i386/kernel/process.c
Quoted 5 lines
arch/i386/kernel/process.c +5
-0+ uptime_notifier.notifier_call = dump_uptime; +atomic_notifier_chain_register (&info_dumper_list, &uptime_notifier); +return 0 ; +} +__initcall (register_uptime_dump);
module_init()
Quoted 15 lines · Kyle McMartin
arch/x86_64/kernel/process.c void show_regs(struct pt_regs *regs) · line 361
Quoted 9 lines · Joshua Wise
arch/x86_64/kernel/process.c +1
-0@@ -356,6 +356,7 @@ void show_regs(struct pt_regs *regs)printk ("CPU %d:" ,smp_processor_id ());__show_regs (regs);show_trace (NULL , regs, (void *)(regs +1 )); +atomic_notifier_call_chain (&info_dumper_list,0 ,NULL ); }woah woah woah. This could push critical bits of the register dump or stacktrace off the screen... Barring any other problems with the patch, this should probably be dumped in the oops header, not trailing it where it could hide critical debugging info.
on the flip side, poorly written chained funcs could oops thus preventing the good info (like stacktrace) from being shown ... -mike
Joshua Wise <[email protected]> writes:
You are aware that oops screen estate is very precious on standard systems without serial console?
kernel/sys.c struct pid *cad_pid; · line 117
Quoted 11 lines
+/*
+ * Dump out UTS info on oops / panic.
+ */
+ +static intdump_utsname(struct notifier_block *self, unsigned long v, void *p)kernel/sys.c +6
-0+{ + printk ("%s %s %s %s %s %s\n", + utsname()->sysname, + utsname()->nodename, + utsname()->release, + utsname()->version,
release / version is already printed for oopses. I frankly don't see the point of the rest of the UTS information because that should be implicit in the log files (you surely know to which machine the log belongs)
Review
Quoted 9 lines
kernel/time.c +4
-0+static int dump_uptime (struct notifier_block *self,unsigned long v,void *p) +{ +struct timespec uptime; +/* The logic below is very much like how kernel + * prepares
/proc/uptime. + */(quoted diff) +4
-0+ do_posix_clock_monotonic_gettime(&uptime); + printk("Uptime(seconds): %lu.%02lu\n", + (unsigned long) uptime.tv_sec, + (uptime.tv_nsec / (NSEC_PER_SEC / 100)));
Wouldn't it be better to just print the time at boot up? If you have full log files you surely got the boot messages too and then you can get it from there. Ok it might be tricky if you don't know when the oops got logged, but surely that is a simple exercise in text processing to handle this on the console server?
It can be already done with CONFIG_PRINTK_TIME BTW which will event print it for every line.
-Andi
Quoted 2 lines · Joshua Wise
This patch adds a call chain to be invoked when the system oopses or panics.
That seems really fragile, processing a callchain when the system goes to panic is not guaranteed to work. Wouldn't simple function call have higher chances of survival?
Signature · 1 line
Jiri Kosina
Quoted 8 lines · On Fri, 29 Jun 2007 02:39:33 +0200 (CEST) Jiri Kosina <[email protected]> wrote:
Quoted 2 lines · Joshua Wise
This patch adds a call chain to be invoked when the system oopses or panics.
That seems really fragile, processing a callchain when the system goes to panic is not guaranteed to work. Wouldn't simple function call have higher chances of survival?
That was my complaint, but then we remembered die_chain, which is already doing that.
Joshua will take a look at using die_chain instead of adding another one.
Quoted 2 lines · Andrew Morton
Your email client is doing space-stuffing. It's easy enough to fix at this end, but even easier if you fix it ;)
Aw darn :( Stupid PINE. I'll fix it for the next patch.
Quoted 1 line
Quoted 1 line
(quoted diff) +1
-0+ atomic_notifier_call_chain(&info_dumper_list, 0, NULL);
[...]
Quoted 2 lines
So... Please consider abandoning the notifier-chain and just go for a simple function call.
As we discovered some minutes ago, there appears to be infrastructure for this already -- the die_chain. For thsoe of you who don't know, the die_chain gets called from notify_die. It exists on almost all architectures. On i386, it gets called from die() on arch/i386/kernel/traps.c:417 -- before registers are scrolled by. So, if we want our own specific output there, like utsname or uptime, then we can get it.
There exists a DIE_PANIC type on some architectures, but it's never actually ... used. So, I will probably write a patch to add it on all architectures, and use it in the panic routines.
Quoted 4 lines
kernel/sys.c struct pid *cad_pid; · line 106
Quoted 2 lines
kernel/sys.c +2
-0+ATOMIC_NOTIFIER_HEAD (info_dumper_list); +EXPORT_SYMBOL (info_dumper_list);That export isn't needed.
If I want someone else to access it, like a module, it is... But, I guess if I wanted to act as per canon, I should just do register functions, and export those. On the die_chain, those are EXPORT_SYMBOL_GPL, FWIW
Quoted 3 lines
Again, a deref of
current->nsproxy->uts_ns->nameat oops-time has risks.This string could be precalculated, no?
Yes, and will be.
Quoted 5 lines
I don't know what to do here. It will be hard to find a read-the-time function which is a) lockless and b) available on all architectures and configs.
If you can find a way to use plain old jiffies, that'd be good.
jiffies sounds good enough to me.
There seems to be some opposition to the utsname and uptime patches. I'll take a look at those here and see what I can do to make those a little more pleasing to non-Google users. Expect a patch for DIE_PANIC tomorrow...
joshua