Commit 0a658002 authored by Andi Kleen's avatar Andi Kleen Committed by Linus Torvalds

[PATCH] x86_64: Rewrite exception stack backtracing

Exceptions and hardware interrupts can, to a certain degree, nest, so when
attempting to follow the sequence of stacks used in order to dump their
contents this has to be accounted for.  Also, IST stacks have their tops
stored in the TSS, so there's no need to add the stack size to get to their
ends.

Minor changes from AK.
Signed-off-by: default avatarJan Beulich <jbeulich@novell.com>
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 63518644
...@@ -120,95 +120,106 @@ int printk_address(unsigned long address) ...@@ -120,95 +120,106 @@ int printk_address(unsigned long address)
} }
#endif #endif
unsigned long *in_exception_stack(int cpu, unsigned long stack) static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
{ unsigned *usedp, const char **idp)
int k; {
static const char ids[N_EXCEPTION_STACKS][8] = {
[DEBUG_STACK - 1] = "#DB",
[NMI_STACK - 1] = "NMI",
[DOUBLEFAULT_STACK - 1] = "#DF",
[STACKFAULT_STACK - 1] = "#SS",
[MCE_STACK - 1] = "#MC",
};
unsigned k;
for (k = 0; k < N_EXCEPTION_STACKS; k++) { for (k = 0; k < N_EXCEPTION_STACKS; k++) {
struct tss_struct *tss = &per_cpu(init_tss, cpu); unsigned long end;
unsigned long start = tss->ist[k] - EXCEPTION_STKSZ;
if (stack >= start && stack < tss->ist[k]) end = per_cpu(init_tss, cpu).ist[k];
return (unsigned long *)tss->ist[k]; if (stack >= end)
continue;
if (stack >= end - EXCEPTION_STKSZ) {
if (*usedp & (1U << k))
break;
*usedp |= 1U << k;
*idp = ids[k];
return (unsigned long *)end;
}
} }
return NULL; return NULL;
} }
/* /*
* x86-64 can have upto three kernel stacks: * x86-64 can have upto three kernel stacks:
* process stack * process stack
* interrupt stack * interrupt stack
* severe exception (double fault, nmi, stack fault) hardware stack * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
* Check and process them in order.
*/ */
void show_trace(unsigned long *stack) void show_trace(unsigned long *stack)
{ {
unsigned long addr; unsigned long addr;
unsigned long *irqstack, *irqstack_end, *estack_end; const unsigned cpu = safe_smp_processor_id();
const int cpu = safe_smp_processor_id(); unsigned long *irqstack_end = (unsigned long *)cpu_pda[cpu].irqstackptr;
int i; int i;
unsigned used = 0;
printk("\nCall Trace:"); printk("\nCall Trace:");
i = 0;
#define HANDLE_STACK(cond) \
estack_end = in_exception_stack(cpu, (unsigned long)stack); do while (cond) { \
if (estack_end) { addr = *stack++; \
while (stack < estack_end) { if (kernel_text_address(addr)) { \
addr = *stack++; /* \
if (__kernel_text_address(addr)) { * If the address is either in the text segment of the \
i += printk_address(addr); * kernel, or in the region which contains vmalloc'ed \
i += printk(" "); * memory, it *may* be the address of a calling \
if (i > 50) { * routine; if so, print it so that someone tracing \
printk("\n"); * down the cause of the crash will be able to figure \
i = 0; * out the call path that was taken. \
} */ \
} i += printk_address(addr); \
if (i > 50) { \
printk("\n "); \
i = 0; \
} \
else \
i += printk(" "); \
} \
} while (0)
for(i = 0; ; ) {
const char *id;
unsigned long *estack_end;
estack_end = in_exception_stack(cpu, (unsigned long)stack,
&used, &id);
if (estack_end) {
i += printk(" <%s> ", id);
HANDLE_STACK (stack < estack_end);
i += printk(" <EOE> ");
stack = (unsigned long *) estack_end[-2];
continue;
} }
i += printk(" <EOE> "); if (irqstack_end) {
i += 7; unsigned long *irqstack;
stack = (unsigned long *) estack_end[-2]; irqstack = irqstack_end -
} (IRQSTACKSIZE - 64) / sizeof(*irqstack);
irqstack_end = (unsigned long *) (cpu_pda[cpu].irqstackptr); if (stack >= irqstack && stack < irqstack_end) {
irqstack = (unsigned long *) (cpu_pda[cpu].irqstackptr - IRQSTACKSIZE + 64); i += printk(" <IRQ> ");
HANDLE_STACK (stack < irqstack_end);
if (stack >= irqstack && stack < irqstack_end) { stack = (unsigned long *) (irqstack_end[-1]);
printk("<IRQ> "); irqstack_end = NULL;
while (stack < irqstack_end) { i += printk(" <EOI> ");
addr = *stack++; continue;
/*
* If the address is either in the text segment of the
* kernel, or in the region which contains vmalloc'ed
* memory, it *may* be the address of a calling
* routine; if so, print it so that someone tracing
* down the cause of the crash will be able to figure
* out the call path that was taken.
*/
if (__kernel_text_address(addr)) {
i += printk_address(addr);
i += printk(" ");
if (i > 50) {
printk("\n ");
i = 0;
}
} }
}
stack = (unsigned long *) (irqstack_end[-1]);
printk(" <EOI> ");
i += 7;
}
while (((long) stack & (THREAD_SIZE-1)) != 0) {
addr = *stack++;
if (__kernel_text_address(addr)) {
i += printk_address(addr);
i += printk(" ");
if (i > 50) {
printk("\n ");
i = 0;
}
} }
break;
} }
HANDLE_STACK (((long) stack & (THREAD_SIZE-1)) != 0);
#undef HANDLE_STACK
printk("\n"); printk("\n");
} }
......
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