1 Subject: DWARF2 EH-frame based stack unwinding
2 From: jbeulich@novell.com
5 Automatically created from "patches.suse/stack-unwind" by xen-port-patches.py
7 --- sle11-2009-05-14.orig/arch/x86/kernel/entry_32-xen.S 2009-05-14 11:20:49.000000000 +0200
8 +++ sle11-2009-05-14/arch/x86/kernel/entry_32-xen.S 2009-05-14 11:29:34.000000000 +0200
9 @@ -1290,6 +1290,38 @@ ENTRY(fixup_4gb_segment)
11 END(spurious_interrupt_bug)
13 +#ifdef CONFIG_STACK_UNWIND
14 +ENTRY(arch_unwind_init_running)
19 + movl %ebx, PT_EBX(%edx)
21 + movl %ebx, PT_ECX(%edx)
22 + movl %ebx, PT_EDX(%edx)
23 + movl %esi, PT_ESI(%edx)
24 + movl %edi, PT_EDI(%edx)
25 + movl %ebp, PT_EBP(%edx)
26 + movl %ebx, PT_EAX(%edx)
27 + movl $__USER_DS, PT_DS(%edx)
28 + movl $__USER_DS, PT_ES(%edx)
29 + movl $__KERNEL_PERCPU, PT_FS(%edx)
30 + movl %ebx, PT_ORIG_EAX(%edx)
31 + movl %ecx, PT_EIP(%edx)
33 + movl $__KERNEL_CS, PT_CS(%edx)
34 + movl %ebx, PT_EFLAGS(%edx)
35 + movl %eax, PT_OLDESP(%edx)
38 + movl PT_EBX(%edx), %ebx
39 + movl $__KERNEL_DS, PT_OLDSS(%edx)
42 +ENDPROC(arch_unwind_init_running)
45 ENTRY(kernel_thread_helper)
46 pushl $0 # fake return address for unwinder
48 --- sle11-2009-05-14.orig/arch/x86/kernel/entry_64-xen.S 2009-03-16 16:38:16.000000000 +0100
49 +++ sle11-2009-05-14/arch/x86/kernel/entry_64-xen.S 2008-11-25 13:17:09.000000000 +0100
50 @@ -1419,3 +1419,36 @@ KPROBE_ENTRY(ignore_sysret)
53 ENDPROC(ignore_sysret)
55 +#ifdef CONFIG_STACK_UNWIND
56 +ENTRY(arch_unwind_init_running)
58 + movq %r15, R15(%rdi)
59 + movq %r14, R14(%rdi)
61 + movq %r13, R13(%rdi)
62 + movq %r12, R12(%rdi)
64 + movq %rbp, RBP(%rdi)
65 + movq %rbx, RBX(%rdi)
67 + movq %rax, R11(%rdi)
68 + movq %rax, R10(%rdi)
71 + movq %rax, RAX(%rdi)
72 + movq %rax, RCX(%rdi)
73 + movq %rax, RDX(%rdi)
74 + movq %rax, RSI(%rdi)
75 + movq %rax, RDI(%rdi)
76 + movq %rax, ORIG_RAX(%rdi)
77 + movq %rcx, RIP(%rdi)
79 + movq $__KERNEL_CS, CS(%rdi)
80 + movq %rax, EFLAGS(%rdi)
81 + movq %rcx, RSP(%rdi)
82 + movq $__KERNEL_DS, SS(%rdi)
85 +ENDPROC(arch_unwind_init_running)
87 --- sle11-2009-05-14.orig/arch/x86/kernel/traps_32-xen.c 2008-11-25 13:17:06.000000000 +0100
88 +++ sle11-2009-05-14/arch/x86/kernel/traps_32-xen.c 2008-11-25 13:17:09.000000000 +0100
89 @@ -86,6 +86,11 @@ int panic_on_unrecovered_nmi;
91 int kstack_depth_to_print = 24;
92 static unsigned int code_bytes = 64;
93 +#ifdef CONFIG_STACK_UNWIND
94 +static int call_trace = 1;
96 +#define call_trace (-1)
98 static int ignore_nmis;
99 static int die_counter;
101 @@ -156,6 +161,33 @@ print_context_stack(struct thread_info *
105 +struct ops_and_data {
106 + const struct stacktrace_ops *ops;
110 +static asmlinkage int
111 +dump_trace_unwind(struct unwind_frame_info *info, void *data)
113 + struct ops_and_data *oad = (struct ops_and_data *)data;
115 + unsigned long sp = UNW_SP(info);
117 + if (arch_unw_user_mode(info))
119 + while (unwind(info) == 0 && UNW_PC(info)) {
121 + oad->ops->address(oad->data, UNW_PC(info), 1);
122 + if (arch_unw_user_mode(info))
124 + if ((sp & ~(PAGE_SIZE - 1)) == (UNW_SP(info) & ~(PAGE_SIZE - 1))
125 + && sp > UNW_SP(info))
132 void dump_trace(struct task_struct *task, struct pt_regs *regs,
133 unsigned long *stack, unsigned long bp,
134 const struct stacktrace_ops *ops, void *data)
135 @@ -163,6 +195,40 @@ void dump_trace(struct task_struct *task
139 + if (call_trace >= 0) {
141 + struct unwind_frame_info info;
142 + struct ops_and_data oad = { .ops = ops, .data = data };
145 + if (unwind_init_frame_info(&info, task, regs) == 0)
146 + unw_ret = dump_trace_unwind(&info, &oad);
147 + } else if (task == current)
148 + unw_ret = unwind_init_running(&info, dump_trace_unwind, &oad);
150 + if (unwind_init_blocked(&info, task) == 0)
151 + unw_ret = dump_trace_unwind(&info, &oad);
154 + if (call_trace == 1 && !arch_unw_user_mode(&info)) {
155 + ops->warning_symbol(data, "DWARF2 unwinder stuck at %s\n",
157 + if (UNW_SP(&info) >= PAGE_OFFSET) {
158 + ops->warning(data, "Leftover inexact backtrace:\n");
159 + stack = (void *)UNW_SP(&info);
162 + bp = UNW_FP(&info);
164 + ops->warning(data, "Full inexact backtrace again:\n");
165 + } else if (call_trace >= 1)
168 + ops->warning(data, "Full inexact backtrace again:\n");
170 + ops->warning(data, "Inexact backtrace:\n");
176 @@ -1226,3 +1292,19 @@ static int __init code_bytes_setup(char
179 __setup("code_bytes=", code_bytes_setup);
181 +#ifdef CONFIG_STACK_UNWIND
182 +static int __init call_trace_setup(char *s)
184 + if (strcmp(s, "old") == 0)
186 + else if (strcmp(s, "both") == 0)
188 + else if (strcmp(s, "newfallback") == 0)
190 + else if (strcmp(s, "new") == 2)
194 +__setup("call_trace=", call_trace_setup);
196 --- sle11-2009-05-14.orig/arch/x86/kernel/traps_64-xen.c 2008-11-25 13:17:06.000000000 +0100
197 +++ sle11-2009-05-14/arch/x86/kernel/traps_64-xen.c 2008-11-25 13:17:09.000000000 +0100
198 @@ -59,6 +59,11 @@ int panic_on_unrecovered_nmi;
200 int kstack_depth_to_print = 12;
201 static unsigned int code_bytes = 64;
202 +#ifdef CONFIG_STACK_UNWIND
203 +static int call_trace = 1;
205 +#define call_trace (-1)
207 static int ignore_nmis;
208 static int die_counter;
210 @@ -165,6 +170,32 @@ static unsigned long *in_exception_stack
214 +struct ops_and_data {
215 + const struct stacktrace_ops *ops;
219 +static int dump_trace_unwind(struct unwind_frame_info *info, void *context)
221 + struct ops_and_data *oad = (struct ops_and_data *)context;
223 + unsigned long sp = UNW_SP(info);
225 + if (arch_unw_user_mode(info))
227 + while (unwind(info) == 0 && UNW_PC(info)) {
229 + oad->ops->address(oad->data, UNW_PC(info), 1);
230 + if (arch_unw_user_mode(info))
232 + if ((sp & ~(PAGE_SIZE - 1)) == (UNW_SP(info) & ~(PAGE_SIZE - 1))
233 + && sp > UNW_SP(info))
241 * x86-64 can have up to three kernel stacks:
243 @@ -229,6 +260,42 @@ void dump_trace(struct task_struct *task
247 + if (call_trace >= 0) {
249 + struct unwind_frame_info info;
250 + struct ops_and_data oad = { .ops = ops, .data = data };
253 + if (unwind_init_frame_info(&info, task, regs) == 0)
254 + unw_ret = dump_trace_unwind(&info, &oad);
255 + } else if (task == current)
256 + unw_ret = unwind_init_running(&info, dump_trace_unwind, &oad);
258 + if (unwind_init_blocked(&info, task) == 0)
259 + unw_ret = dump_trace_unwind(&info, &oad);
262 + if (call_trace == 1 && !arch_unw_user_mode(&info)) {
263 + ops->warning_symbol(data, "DWARF2 unwinder stuck at %s\n",
265 + if ((long)UNW_SP(&info) < 0) {
266 + ops->warning(data, "Leftover inexact backtrace:\n");
267 + stack = (unsigned long *)UNW_SP(&info);
273 + ops->warning(data, "Full inexact backtrace again:\n");
274 + } else if (call_trace >= 1) {
278 + ops->warning(data, "Full inexact backtrace again:\n");
280 + ops->warning(data, "Inexact backtrace:\n");
286 @@ -1242,3 +1309,21 @@ static int __init code_bytes_setup(char
289 __setup("code_bytes=", code_bytes_setup);
291 +#ifdef CONFIG_STACK_UNWIND
292 +static int __init call_trace_setup(char *s)
296 + if (strcmp(s, "old") == 0)
298 + else if (strcmp(s, "both") == 0)
300 + else if (strcmp(s, "newfallback") == 0)
302 + else if (strcmp(s, "new") == 0)
306 +early_param("call_trace", call_trace_setup);