Commit ea424055 authored by Jan Beulich's avatar Jan Beulich Committed by Linus Torvalds

[PATCH] x86: Make backtracer fallback logic more bullet-proof

The unwinder fallback logic still had potential for falling through to
the legacy stack trace code without printing an indication (at once
serving as a separator) of this.

Further, the stack pointer retrieval for the fallback should be as
restrictive as possible (in order to avoid having the legacy stack
tracer try to access invalid memory). The patch tightens that, but
this could certainly be further improved.

Also making the call_trace command line option now conditional upon
CONFIG_STACK_UNWIND (as it's meaningless otherwise).
Signed-off-by: default avatarJan Beulich <jbeulich@novell.com>
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 61171b8d
...@@ -92,7 +92,11 @@ asmlinkage void spurious_interrupt_bug(void); ...@@ -92,7 +92,11 @@ asmlinkage void spurious_interrupt_bug(void);
asmlinkage void machine_check(void); asmlinkage void machine_check(void);
static int kstack_depth_to_print = 24; static int kstack_depth_to_print = 24;
#ifdef CONFIG_STACK_UNWIND
static int call_trace = 1; static int call_trace = 1;
#else
#define call_trace (-1)
#endif
ATOMIC_NOTIFIER_HEAD(i386die_chain); ATOMIC_NOTIFIER_HEAD(i386die_chain);
int register_die_notifier(struct notifier_block *nb) int register_die_notifier(struct notifier_block *nb)
...@@ -187,22 +191,21 @@ static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, ...@@ -187,22 +191,21 @@ static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
if (unwind_init_blocked(&info, task) == 0) if (unwind_init_blocked(&info, task) == 0)
unw_ret = show_trace_unwind(&info, log_lvl); unw_ret = show_trace_unwind(&info, log_lvl);
} }
if (unw_ret > 0 && !arch_unw_user_mode(&info)) { if (unw_ret > 0) {
#ifdef CONFIG_STACK_UNWIND if (call_trace == 1 && !arch_unw_user_mode(&info)) {
print_symbol("DWARF2 unwinder stuck at %s\n", print_symbol("DWARF2 unwinder stuck at %s\n",
UNW_PC(&info)); UNW_PC(&info));
if (call_trace == 1) { if (UNW_SP(&info) >= PAGE_OFFSET) {
printk("Leftover inexact backtrace:\n"); printk("Leftover inexact backtrace:\n");
if (UNW_SP(&info))
stack = (void *)UNW_SP(&info); stack = (void *)UNW_SP(&info);
} else if (call_trace > 1) } else
printk("Full inexact backtrace again:\n");
} else if (call_trace >= 1)
return; return;
else else
printk("Full inexact backtrace again:\n"); printk("Full inexact backtrace again:\n");
#else } else
printk("Inexact backtrace:\n"); printk("Inexact backtrace:\n");
#endif
}
} }
if (task == current) { if (task == current) {
...@@ -1241,6 +1244,7 @@ static int __init kstack_setup(char *s) ...@@ -1241,6 +1244,7 @@ static int __init kstack_setup(char *s)
} }
__setup("kstack=", kstack_setup); __setup("kstack=", kstack_setup);
#ifdef CONFIG_STACK_UNWIND
static int __init call_trace_setup(char *s) static int __init call_trace_setup(char *s)
{ {
if (strcmp(s, "old") == 0) if (strcmp(s, "old") == 0)
...@@ -1254,3 +1258,4 @@ static int __init call_trace_setup(char *s) ...@@ -1254,3 +1258,4 @@ static int __init call_trace_setup(char *s)
return 1; return 1;
} }
__setup("call_trace=", call_trace_setup); __setup("call_trace=", call_trace_setup);
#endif
...@@ -107,7 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) ...@@ -107,7 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
} }
static int kstack_depth_to_print = 12; static int kstack_depth_to_print = 12;
#ifdef CONFIG_STACK_UNWIND
static int call_trace = 1; static int call_trace = 1;
#else
#define call_trace (-1)
#endif
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
# include <linux/kallsyms.h> # include <linux/kallsyms.h>
...@@ -274,21 +278,21 @@ void show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long * s ...@@ -274,21 +278,21 @@ void show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long * s
if (unwind_init_blocked(&info, tsk) == 0) if (unwind_init_blocked(&info, tsk) == 0)
unw_ret = show_trace_unwind(&info, NULL); unw_ret = show_trace_unwind(&info, NULL);
} }
if (unw_ret > 0 && !arch_unw_user_mode(&info)) { if (unw_ret > 0) {
#ifdef CONFIG_STACK_UNWIND if (call_trace == 1 && !arch_unw_user_mode(&info)) {
unsigned long rip = info.regs.rip; print_symbol("DWARF2 unwinder stuck at %s\n",
print_symbol("DWARF2 unwinder stuck at %s\n", rip); UNW_PC(&info));
if (call_trace == 1) { if ((long)UNW_SP(&info) < 0) {
printk("Leftover inexact backtrace:\n"); printk("Leftover inexact backtrace:\n");
stack = (unsigned long *)info.regs.rsp; stack = (unsigned long *)UNW_SP(&info);
} else if (call_trace > 1) } else
printk("Full inexact backtrace again:\n");
} else if (call_trace >= 1)
return; return;
else else
printk("Full inexact backtrace again:\n"); printk("Full inexact backtrace again:\n");
#else } else
printk("Inexact backtrace:\n"); printk("Inexact backtrace:\n");
#endif
}
} }
/* /*
...@@ -1120,6 +1124,7 @@ static int __init kstack_setup(char *s) ...@@ -1120,6 +1124,7 @@ static int __init kstack_setup(char *s)
} }
__setup("kstack=", kstack_setup); __setup("kstack=", kstack_setup);
#ifdef CONFIG_STACK_UNWIND
static int __init call_trace_setup(char *s) static int __init call_trace_setup(char *s)
{ {
if (strcmp(s, "old") == 0) if (strcmp(s, "old") == 0)
...@@ -1133,3 +1138,4 @@ static int __init call_trace_setup(char *s) ...@@ -1133,3 +1138,4 @@ static int __init call_trace_setup(char *s)
return 1; return 1;
} }
__setup("call_trace=", call_trace_setup); __setup("call_trace=", call_trace_setup);
#endif
...@@ -87,6 +87,7 @@ static inline int arch_unw_user_mode(const struct unwind_frame_info *info) ...@@ -87,6 +87,7 @@ static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
#else #else
#define UNW_PC(frame) ((void)(frame), 0) #define UNW_PC(frame) ((void)(frame), 0)
#define UNW_SP(frame) ((void)(frame), 0)
static inline int arch_unw_user_mode(const void *info) static inline int arch_unw_user_mode(const void *info)
{ {
......
...@@ -95,6 +95,7 @@ static inline int arch_unw_user_mode(const struct unwind_frame_info *info) ...@@ -95,6 +95,7 @@ static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
#else #else
#define UNW_PC(frame) ((void)(frame), 0) #define UNW_PC(frame) ((void)(frame), 0)
#define UNW_SP(frame) ((void)(frame), 0)
static inline int arch_unw_user_mode(const void *info) static inline int arch_unw_user_mode(const void *info)
{ {
......
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