Commit bc850d6b authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Ingo Molnar

x86: add the capability to print fuzzy backtraces

For enhancing the 32 bit EBP based backtracer, I need the capability
for the backtracer to tell it's customer that an entry is either
reliable or unreliable, and the backtrace printing code then needs to
print the unreliable ones slightly different.

This patch adds the basic capability, the next patch will add a user
of this capability.
Signed-off-by: default avatarArjan van de Ven <arjan@linux.intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 3d1f7cae
...@@ -167,7 +167,7 @@ static void dump_leak(void) ...@@ -167,7 +167,7 @@ static void dump_leak(void)
iommu_leak_pages); iommu_leak_pages);
for (i = 0; i < iommu_leak_pages; i += 2) { for (i = 0; i < iommu_leak_pages; i += 2) {
printk(KERN_DEBUG "%lu: ", iommu_pages-i); printk(KERN_DEBUG "%lu: ", iommu_pages-i);
printk_address((unsigned long) iommu_leak_tab[iommu_pages-i]); printk_address((unsigned long) iommu_leak_tab[iommu_pages-i], 0);
printk(KERN_CONT "%c", (i+1)%2 == 0 ? '\n' : ' '); printk(KERN_CONT "%c", (i+1)%2 == 0 ? '\n' : ' ');
} }
printk(KERN_DEBUG "\n"); printk(KERN_DEBUG "\n");
......
...@@ -329,7 +329,7 @@ void __show_regs(struct pt_regs * regs) ...@@ -329,7 +329,7 @@ void __show_regs(struct pt_regs * regs)
(int)strcspn(init_utsname()->version, " "), (int)strcspn(init_utsname()->version, " "),
init_utsname()->version); init_utsname()->version);
printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip); printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
printk_address(regs->ip); printk_address(regs->ip, regs->bp);
printk("RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->sp, printk("RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->sp,
regs->flags); regs->flags);
printk("RAX: %016lx RBX: %016lx RCX: %016lx\n", printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
...@@ -377,7 +377,7 @@ void show_regs(struct pt_regs *regs) ...@@ -377,7 +377,7 @@ void show_regs(struct pt_regs *regs)
{ {
printk("CPU %d:", smp_processor_id()); printk("CPU %d:", smp_processor_id());
__show_regs(regs); __show_regs(regs);
show_trace(NULL, regs, (void *)(regs + 1)); show_trace(NULL, regs, (void *)(regs + 1), regs->bp);
} }
/* /*
......
...@@ -22,7 +22,7 @@ static int save_stack_stack(void *data, char *name) ...@@ -22,7 +22,7 @@ static int save_stack_stack(void *data, char *name)
return -1; return -1;
} }
static void save_stack_address(void *data, unsigned long addr) static void save_stack_address(void *data, unsigned long addr, int reliable)
{ {
struct stack_trace *trace = (struct stack_trace *)data; struct stack_trace *trace = (struct stack_trace *)data;
if (trace->skip > 0) { if (trace->skip > 0) {
......
...@@ -126,7 +126,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo, ...@@ -126,7 +126,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
addr = frame->return_address; addr = frame->return_address;
if (__kernel_text_address(addr)) if (__kernel_text_address(addr))
ops->address(data, addr); ops->address(data, addr, 1);
/* /*
* break out of recursive entries (such as * break out of recursive entries (such as
* end_of_stack_stop_unwind_function). Also, * end_of_stack_stop_unwind_function). Also,
...@@ -145,7 +145,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo, ...@@ -145,7 +145,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
addr = *stack++; addr = *stack++;
if (__kernel_text_address(addr)) if (__kernel_text_address(addr))
ops->address(data, addr); ops->address(data, addr, 1);
} }
#endif #endif
return bp; return bp;
...@@ -220,9 +220,11 @@ static int print_trace_stack(void *data, char *name) ...@@ -220,9 +220,11 @@ static int print_trace_stack(void *data, char *name)
/* /*
* Print one address/symbol entries per line. * Print one address/symbol entries per line.
*/ */
static void print_trace_address(void *data, unsigned long addr) static void print_trace_address(void *data, unsigned long addr, int reliable)
{ {
printk("%s [<%08lx>] ", (char *)data, addr); printk("%s [<%08lx>] ", (char *)data, addr);
if (!reliable)
printk("? ");
print_symbol("%s\n", addr); print_symbol("%s\n", addr);
touch_nmi_watchdog(); touch_nmi_watchdog();
} }
......
...@@ -99,13 +99,14 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) ...@@ -99,13 +99,14 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
int kstack_depth_to_print = 12; int kstack_depth_to_print = 12;
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
void printk_address(unsigned long address) void printk_address(unsigned long address, int reliable)
{ {
unsigned long offset = 0, symsize; unsigned long offset = 0, symsize;
const char *symname; const char *symname;
char *modname; char *modname;
char *delim = ":"; char *delim = ":";
char namebuf[128]; char namebuf[128];
char reliab[4] = "";;
symname = kallsyms_lookup(address, &symsize, &offset, symname = kallsyms_lookup(address, &symsize, &offset,
&modname, namebuf); &modname, namebuf);
...@@ -113,13 +114,16 @@ void printk_address(unsigned long address) ...@@ -113,13 +114,16 @@ void printk_address(unsigned long address)
printk(" [<%016lx>]\n", address); printk(" [<%016lx>]\n", address);
return; return;
} }
if (!reliable)
strcpy(reliab, "? ");
if (!modname) if (!modname)
modname = delim = ""; modname = delim = "";
printk(" [<%016lx>] %s%s%s%s+0x%lx/0x%lx\n", printk(" [<%016lx>] %s%s%s%s%s+0x%lx/0x%lx\n",
address, delim, modname, delim, symname, offset, symsize); address, reliab, delim, modname, delim, symname, offset, symsize);
} }
#else #else
void printk_address(unsigned long address) void printk_address(unsigned long address, int reliable)
{ {
printk(" [<%016lx>]\n", address); printk(" [<%016lx>]\n", address);
} }
...@@ -215,7 +219,7 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p) ...@@ -215,7 +219,7 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
} }
void dump_trace(struct task_struct *tsk, struct pt_regs *regs, void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
unsigned long *stack, unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data) const struct stacktrace_ops *ops, void *data)
{ {
const unsigned cpu = get_cpu(); const unsigned cpu = get_cpu();
...@@ -252,7 +256,7 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs, ...@@ -252,7 +256,7 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
* down the cause of the crash will be able to figure \ * down the cause of the crash will be able to figure \
* out the call path that was taken. \ * out the call path that was taken. \
*/ \ */ \
ops->address(data, addr); \ ops->address(data, addr, 1); \
} \ } \
} while (0) } while (0)
...@@ -331,10 +335,10 @@ static int print_trace_stack(void *data, char *name) ...@@ -331,10 +335,10 @@ static int print_trace_stack(void *data, char *name)
return 0; return 0;
} }
static void print_trace_address(void *data, unsigned long addr) static void print_trace_address(void *data, unsigned long addr, int reliable)
{ {
touch_nmi_watchdog(); touch_nmi_watchdog();
printk_address(addr); printk_address(addr, reliable);
} }
static const struct stacktrace_ops print_trace_ops = { static const struct stacktrace_ops print_trace_ops = {
...@@ -345,15 +349,17 @@ static const struct stacktrace_ops print_trace_ops = { ...@@ -345,15 +349,17 @@ static const struct stacktrace_ops print_trace_ops = {
}; };
void void
show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long *stack) show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long *stack,
unsigned long bp)
{ {
printk("\nCall Trace:\n"); printk("\nCall Trace:\n");
dump_trace(tsk, regs, stack, &print_trace_ops, NULL); dump_trace(tsk, regs, stack, bp, &print_trace_ops, NULL);
printk("\n"); printk("\n");
} }
static void static void
_show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp) _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp,
unsigned long bp)
{ {
unsigned long *stack; unsigned long *stack;
int i; int i;
...@@ -387,12 +393,12 @@ _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp) ...@@ -387,12 +393,12 @@ _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp)
printk(" %016lx", *stack++); printk(" %016lx", *stack++);
touch_nmi_watchdog(); touch_nmi_watchdog();
} }
show_trace(tsk, regs, sp); show_trace(tsk, regs, sp, bp);
} }
void show_stack(struct task_struct *tsk, unsigned long * sp) void show_stack(struct task_struct *tsk, unsigned long * sp)
{ {
_show_stack(tsk, NULL, sp); _show_stack(tsk, NULL, sp, 0);
} }
/* /*
...@@ -401,13 +407,14 @@ void show_stack(struct task_struct *tsk, unsigned long * sp) ...@@ -401,13 +407,14 @@ void show_stack(struct task_struct *tsk, unsigned long * sp)
void dump_stack(void) void dump_stack(void)
{ {
unsigned long dummy; unsigned long dummy;
unsigned long bp = 0;
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,
(int)strcspn(init_utsname()->version, " "), (int)strcspn(init_utsname()->version, " "),
init_utsname()->version); init_utsname()->version);
show_trace(NULL, NULL, &dummy); show_trace(NULL, NULL, &dummy, bp);
} }
EXPORT_SYMBOL(dump_stack); EXPORT_SYMBOL(dump_stack);
...@@ -432,7 +439,7 @@ void show_registers(struct pt_regs *regs) ...@@ -432,7 +439,7 @@ void show_registers(struct pt_regs *regs)
*/ */
if (in_kernel) { if (in_kernel) {
printk("Stack: "); printk("Stack: ");
_show_stack(NULL, regs, (unsigned long*)sp); _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
printk("\nCode: "); printk("\nCode: ");
if (regs->ip < PAGE_OFFSET) if (regs->ip < PAGE_OFFSET)
...@@ -527,7 +534,7 @@ int __kprobes __die(const char * str, struct pt_regs * regs, long err) ...@@ -527,7 +534,7 @@ int __kprobes __die(const char * str, struct pt_regs * regs, long err)
add_taint(TAINT_DIE); add_taint(TAINT_DIE);
/* Executive summary in case the oops scrolled away */ /* Executive summary in case the oops scrolled away */
printk(KERN_ALERT "RIP "); printk(KERN_ALERT "RIP ");
printk_address(regs->ip); printk_address(regs->ip, regs->bp);
printk(" RSP <%016lx>\n", regs->sp); printk(" RSP <%016lx>\n", regs->sp);
if (kexec_should_crash(current)) if (kexec_should_crash(current))
crash_kexec(regs); crash_kexec(regs);
......
...@@ -578,7 +578,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -578,7 +578,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
else else
printk(KERN_ALERT "Unable to handle kernel paging request"); printk(KERN_ALERT "Unable to handle kernel paging request");
printk(" at %016lx RIP: \n" KERN_ALERT, address); printk(" at %016lx RIP: \n" KERN_ALERT, address);
printk_address(regs->ip); printk_address(regs->ip, regs->bp);
dump_pagetable(address); dump_pagetable(address);
tsk->thread.cr2 = address; tsk->thread.cr2 = address;
tsk->thread.trap_no = 14; tsk->thread.trap_no = 14;
......
...@@ -32,7 +32,7 @@ static int backtrace_stack(void *data, char *name) ...@@ -32,7 +32,7 @@ static int backtrace_stack(void *data, char *name)
return 0; return 0;
} }
static void backtrace_address(void *data, unsigned long addr) static void backtrace_address(void *data, unsigned long addr, int reliable)
{ {
unsigned int *depth = data; unsigned int *depth = data;
......
...@@ -22,12 +22,13 @@ enum die_val { ...@@ -22,12 +22,13 @@ enum die_val {
DIE_PAGE_FAULT, DIE_PAGE_FAULT,
}; };
extern void printk_address(unsigned long address); extern void printk_address(unsigned long address, int reliable);
extern void die(const char *,struct pt_regs *,long); extern void die(const char *,struct pt_regs *,long);
extern int __must_check __die(const char *, struct pt_regs *, long); extern int __must_check __die(const char *, struct pt_regs *, long);
extern void show_registers(struct pt_regs *regs); extern void show_registers(struct pt_regs *regs);
extern void __show_registers(struct pt_regs *, int all); extern void __show_registers(struct pt_regs *, int all);
extern void show_trace(struct task_struct *, struct pt_regs *, unsigned long *); extern void show_trace(struct task_struct *t, struct pt_regs *regs,
unsigned long *sp, unsigned long bp);
extern void __show_regs(struct pt_regs *regs); extern void __show_regs(struct pt_regs *regs);
extern void show_regs(struct pt_regs *regs); extern void show_regs(struct pt_regs *regs);
extern void dump_pagetable(unsigned long); extern void dump_pagetable(unsigned long);
......
...@@ -9,12 +9,13 @@ struct stacktrace_ops { ...@@ -9,12 +9,13 @@ struct stacktrace_ops {
void (*warning)(void *data, char *msg); void (*warning)(void *data, char *msg);
/* msg must contain %s for the symbol */ /* msg must contain %s for the symbol */
void (*warning_symbol)(void *data, char *msg, unsigned long symbol); void (*warning_symbol)(void *data, char *msg, unsigned long symbol);
void (*address)(void *data, unsigned long address); void (*address)(void *data, unsigned long address, int reliable);
/* On negative return stop dumping */ /* On negative return stop dumping */
int (*stack)(void *data, char *name); int (*stack)(void *data, char *name);
}; };
void dump_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long *stack, void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data); const struct stacktrace_ops *ops, void *data);
#endif #endif
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