]>
Commit | Line | Data |
---|---|---|
2bc5f927 AH |
1 | /* |
2 | * Copyright (C) 1991, 1992 Linus Torvalds | |
3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs | |
4 | */ | |
5 | #include <linux/kallsyms.h> | |
6 | #include <linux/kprobes.h> | |
7 | #include <linux/uaccess.h> | |
2bc5f927 AH |
8 | #include <linux/hardirq.h> |
9 | #include <linux/kdebug.h> | |
186f4360 | 10 | #include <linux/export.h> |
2bc5f927 AH |
11 | #include <linux/ptrace.h> |
12 | #include <linux/kexec.h> | |
b8030906 | 13 | #include <linux/sysfs.h> |
2bc5f927 AH |
14 | #include <linux/bug.h> |
15 | #include <linux/nmi.h> | |
16 | ||
17 | #include <asm/stacktrace.h> | |
18 | ||
198d208d SR |
19 | static void *is_irq_stack(void *p, void *irq) |
20 | { | |
21 | if (p < irq || p >= (irq + THREAD_SIZE)) | |
22 | return NULL; | |
23 | return irq + THREAD_SIZE; | |
24 | } | |
25 | ||
26 | ||
cfeeed27 | 27 | static void *is_hardirq_stack(unsigned long *stack) |
198d208d | 28 | { |
cfeeed27 | 29 | void *irq = this_cpu_read(hardirq_stack); |
198d208d SR |
30 | |
31 | return is_irq_stack(stack, irq); | |
32 | } | |
33 | ||
cfeeed27 | 34 | static void *is_softirq_stack(unsigned long *stack) |
198d208d | 35 | { |
cfeeed27 | 36 | void *irq = this_cpu_read(softirq_stack); |
198d208d SR |
37 | |
38 | return is_irq_stack(stack, irq); | |
39 | } | |
0406ca6d | 40 | |
e8e999cf NK |
41 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
42 | unsigned long *stack, unsigned long bp, | |
2bc5f927 AH |
43 | const struct stacktrace_ops *ops, void *data) |
44 | { | |
7ee991fb | 45 | int graph = 0; |
0788aa6a | 46 | u32 *prev_esp; |
7ee991fb | 47 | |
4b8afafb JP |
48 | task = task ? : current; |
49 | stack = stack ? : get_stack_pointer(task, regs); | |
50 | bp = bp ? : (unsigned long)get_frame_pointer(task, regs); | |
e8e999cf | 51 | |
2bc5f927 | 52 | for (;;) { |
198d208d SR |
53 | void *end_stack; |
54 | ||
cfeeed27 | 55 | end_stack = is_hardirq_stack(stack); |
198d208d | 56 | if (!end_stack) |
cfeeed27 | 57 | end_stack = is_softirq_stack(stack); |
2bc5f927 | 58 | |
da01e18a | 59 | bp = ops->walk_stack(task, stack, bp, ops, data, |
198d208d | 60 | end_stack, &graph); |
2ac53721 | 61 | |
0788aa6a | 62 | /* Stop if not on irq stack */ |
198d208d | 63 | if (!end_stack) |
0788aa6a SR |
64 | break; |
65 | ||
198d208d SR |
66 | /* The previous esp is saved on the bottom of the stack */ |
67 | prev_esp = (u32 *)(end_stack - THREAD_SIZE); | |
0788aa6a | 68 | stack = (unsigned long *)*prev_esp; |
2bc5f927 AH |
69 | if (!stack) |
70 | break; | |
0788aa6a | 71 | |
2ac53721 AH |
72 | if (ops->stack(data, "IRQ") < 0) |
73 | break; | |
2bc5f927 AH |
74 | touch_nmi_watchdog(); |
75 | } | |
76 | } | |
77 | EXPORT_SYMBOL(dump_trace); | |
78 | ||
878719e8 | 79 | void |
2bc5f927 | 80 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
e8e999cf | 81 | unsigned long *sp, unsigned long bp, char *log_lvl) |
2bc5f927 AH |
82 | { |
83 | unsigned long *stack; | |
84 | int i; | |
85 | ||
4b8afafb | 86 | sp = sp ? : get_stack_pointer(task, regs); |
2bc5f927 AH |
87 | |
88 | stack = sp; | |
89 | for (i = 0; i < kstack_depth_to_print; i++) { | |
90 | if (kstack_end(stack)) | |
91 | break; | |
1fc7f61c AS |
92 | if ((i % STACKSLOTS_PER_LINE) == 0) { |
93 | if (i != 0) | |
94 | pr_cont("\n"); | |
95 | printk("%s %08lx", log_lvl, *stack++); | |
96 | } else | |
97 | pr_cont(" %08lx", *stack++); | |
ca0a8164 | 98 | touch_nmi_watchdog(); |
2bc5f927 | 99 | } |
c767a54b | 100 | pr_cont("\n"); |
e8e999cf | 101 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
2bc5f927 AH |
102 | } |
103 | ||
2bc5f927 | 104 | |
57da8b96 | 105 | void show_regs(struct pt_regs *regs) |
2bc5f927 AH |
106 | { |
107 | int i; | |
108 | ||
a43cb95d | 109 | show_regs_print_info(KERN_EMERG); |
f39b6f0e | 110 | __show_regs(regs, !user_mode(regs)); |
2bc5f927 | 111 | |
2bc5f927 AH |
112 | /* |
113 | * When in-kernel, we also print out the stack and code at the | |
114 | * time of the fault.. | |
115 | */ | |
f39b6f0e | 116 | if (!user_mode(regs)) { |
2bc5f927 AH |
117 | unsigned int code_prologue = code_bytes * 43 / 64; |
118 | unsigned int code_len = code_bytes; | |
119 | unsigned char c; | |
120 | u8 *ip; | |
121 | ||
c767a54b | 122 | pr_emerg("Stack:\n"); |
5a8ff54c | 123 | show_stack_log_lvl(NULL, regs, NULL, 0, KERN_EMERG); |
2bc5f927 | 124 | |
c767a54b | 125 | pr_emerg("Code:"); |
2bc5f927 AH |
126 | |
127 | ip = (u8 *)regs->ip - code_prologue; | |
128 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | |
8a541665 | 129 | /* try starting at IP */ |
2bc5f927 AH |
130 | ip = (u8 *)regs->ip; |
131 | code_len = code_len - code_prologue + 1; | |
132 | } | |
133 | for (i = 0; i < code_len; i++, ip++) { | |
134 | if (ip < (u8 *)PAGE_OFFSET || | |
135 | probe_kernel_address(ip, c)) { | |
c767a54b | 136 | pr_cont(" Bad EIP value."); |
2bc5f927 AH |
137 | break; |
138 | } | |
139 | if (ip == (u8 *)regs->ip) | |
c767a54b | 140 | pr_cont(" <%02x>", c); |
2bc5f927 | 141 | else |
c767a54b | 142 | pr_cont(" %02x", c); |
2bc5f927 AH |
143 | } |
144 | } | |
c767a54b | 145 | pr_cont("\n"); |
2bc5f927 AH |
146 | } |
147 | ||
148 | int is_valid_bugaddr(unsigned long ip) | |
149 | { | |
150 | unsigned short ud2; | |
151 | ||
152 | if (ip < PAGE_OFFSET) | |
153 | return 0; | |
154 | if (probe_kernel_address((unsigned short *)ip, ud2)) | |
155 | return 0; | |
156 | ||
157 | return ud2 == 0x0b0f; | |
158 | } |