提交 80b51f31 编写于 作者: A Arjan van de Ven 提交者: Ingo Molnar

x86: use the stack frames to get exact stack-traces for CONFIG_FRAMEPOINTER on x86-64

x86 32 bit already has this feature: This patch uses the stack frames with
frame pointer into an exact stack trace, by following the frame pointer.
This only affects kernels built with the CONFIG_FRAME_POINTER config option
enabled, and greatly reduces the amount of noise in oopses.

This code uses the traditional method of doing backtraces, but if it
finds a valid frame pointer chain, will use that to show which parts
of the backtrace are reliable and which parts are not

Due to the fragility and importance of the backtrace code, this needs to
be well reviewed and well tested before merging into mainlne.
Signed-off-by: NArjan van de Ven <arjan@linux.intel.com>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 e4a94568
...@@ -225,31 +225,34 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, ...@@ -225,31 +225,34 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
return p > t && p < t + THREAD_SIZE - size; return p > t && p < t + THREAD_SIZE - size;
} }
/* The form of the top of the frame on the stack */
struct stack_frame {
struct stack_frame *next_frame;
unsigned long return_address;
};
static inline unsigned long print_context_stack(struct thread_info *tinfo, static inline unsigned long print_context_stack(struct thread_info *tinfo,
unsigned long *stack, unsigned long bp, unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data, const struct stacktrace_ops *ops, void *data,
unsigned long *end) unsigned long *end)
{ {
/* struct stack_frame *frame = (struct stack_frame *)bp;
* Print function call entries within a stack. 'cond' is the
* "end of stackframe" condition, that the 'stack++' while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
* iteration will eventually trigger. unsigned long addr;
*/
while (valid_stack_ptr(tinfo, stack, 3, end)) { addr = *stack;
unsigned long addr = *stack++;
/* Use unlocked access here because except for NMIs
we should be already protected against module unloads */
if (__kernel_text_address(addr)) { if (__kernel_text_address(addr)) {
/* if ((unsigned long) stack == bp + 8) {
* If the address is either in the text segment of the ops->address(data, addr, 1);
* kernel, or in the region which contains vmalloc'ed frame = frame->next_frame;
* memory, it *may* be the address of a calling bp = (unsigned long) frame;
* routine; if so, print it so that someone tracing } else {
* down the cause of the crash will be able to figure ops->address(data, addr, bp == 0);
* out the call path that was taken. }
*/
ops->address(data, addr, 1);
} }
stack++;
} }
return bp; return bp;
} }
...@@ -274,6 +277,19 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs, ...@@ -274,6 +277,19 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
stack = (unsigned long *)tsk->thread.sp; stack = (unsigned long *)tsk->thread.sp;
} }
#ifdef CONFIG_FRAME_POINTER
if (!bp) {
if (tsk == current) {
/* Grab bp right from our regs */
asm("movq %%rbp, %0" : "=r" (bp):);
} else {
/* bp is the last reg pushed by switch_to */
bp = *(unsigned long *) tsk->thread.sp;
}
}
#endif
/* /*
* Print function call entries in all stacks, starting at the * Print function call entries in all stacks, starting at the
...@@ -290,8 +306,8 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs, ...@@ -290,8 +306,8 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
if (ops->stack(data, id) < 0) if (ops->stack(data, id) < 0)
break; break;
print_context_stack(tinfo, stack, 0, ops, bp = print_context_stack(tinfo, stack, bp, ops,
data, estack_end); data, estack_end);
ops->stack(data, "<EOE>"); ops->stack(data, "<EOE>");
/* /*
* We link to the next stack via the * We link to the next stack via the
...@@ -309,8 +325,8 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs, ...@@ -309,8 +325,8 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
if (stack >= irqstack && stack < irqstack_end) { if (stack >= irqstack && stack < irqstack_end) {
if (ops->stack(data, "IRQ") < 0) if (ops->stack(data, "IRQ") < 0)
break; break;
print_context_stack(tinfo, stack, 0, ops, bp = print_context_stack(tinfo, stack, bp,
data, irqstack_end); ops, data, irqstack_end);
/* /*
* We link to the next stack (which would be * We link to the next stack (which would be
* the process stack normally) the last * the process stack normally) the last
...@@ -328,7 +344,7 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs, ...@@ -328,7 +344,7 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
/* /*
* This handles the process stack: * This handles the process stack:
*/ */
print_context_stack(tinfo, stack, 0, ops, data, NULL); bp = print_context_stack(tinfo, stack, bp, ops, data, NULL);
put_cpu(); put_cpu();
} }
EXPORT_SYMBOL(dump_trace); EXPORT_SYMBOL(dump_trace);
...@@ -425,6 +441,11 @@ void dump_stack(void) ...@@ -425,6 +441,11 @@ void dump_stack(void)
unsigned long dummy; unsigned long dummy;
unsigned long bp = 0; unsigned long bp = 0;
#ifdef CONFIG_FRAME_POINTER
if (!bp)
asm("movq %%rbp, %0" : "=r" (bp):);
#endif
printk("Pid: %d, comm: %.20s %s %s %.*s\n", printk("Pid: %d, comm: %.20s %s %s %.*s\n",
current->pid, current->comm, print_tainted(), current->pid, current->comm, print_tainted(),
init_utsname()->release, init_utsname()->release,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册