Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 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> |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 8 | #include <linux/hardirq.h> |
| 9 | #include <linux/kdebug.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/ptrace.h> |
| 12 | #include <linux/kexec.h> |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 13 | #include <linux/sysfs.h> |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 14 | #include <linux/bug.h> |
| 15 | #include <linux/nmi.h> |
| 16 | |
| 17 | #include <asm/stacktrace.h> |
| 18 | |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 19 | |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 20 | #define N_EXCEPTION_STACKS_END \ |
| 21 | (N_EXCEPTION_STACKS + DEBUG_STKSZ/EXCEPTION_STKSZ - 2) |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 22 | |
| 23 | static char x86_stack_ids[][8] = { |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 24 | [ DEBUG_STACK-1 ] = "#DB", |
| 25 | [ NMI_STACK-1 ] = "NMI", |
| 26 | [ DOUBLEFAULT_STACK-1 ] = "#DF", |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 27 | [ MCE_STACK-1 ] = "#MC", |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 28 | #if DEBUG_STKSZ > EXCEPTION_STKSZ |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 29 | [ N_EXCEPTION_STACKS ... |
| 30 | N_EXCEPTION_STACKS_END ] = "#DB[?]" |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 31 | #endif |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 32 | }; |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 33 | |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 34 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, |
Ingo Molnar | b803090 | 2009-11-26 08:17:31 +0100 | [diff] [blame] | 35 | unsigned *usedp, char **idp) |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 36 | { |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 37 | unsigned k; |
| 38 | |
| 39 | /* |
| 40 | * Iterate over all exception stacks, and figure out whether |
| 41 | * 'stack' is in one of them: |
| 42 | */ |
| 43 | for (k = 0; k < N_EXCEPTION_STACKS; k++) { |
| 44 | unsigned long end = per_cpu(orig_ist, cpu).ist[k]; |
| 45 | /* |
| 46 | * Is 'stack' above this exception frame's end? |
| 47 | * If yes then skip to the next frame. |
| 48 | */ |
| 49 | if (stack >= end) |
| 50 | continue; |
| 51 | /* |
| 52 | * Is 'stack' above this exception frame's start address? |
| 53 | * If yes then we found the right frame. |
| 54 | */ |
| 55 | if (stack >= end - EXCEPTION_STKSZ) { |
| 56 | /* |
| 57 | * Make sure we only iterate through an exception |
| 58 | * stack once. If it comes up for the second time |
| 59 | * then there's something wrong going on - just |
| 60 | * break out and return NULL: |
| 61 | */ |
| 62 | if (*usedp & (1U << k)) |
| 63 | break; |
| 64 | *usedp |= 1U << k; |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 65 | *idp = x86_stack_ids[k]; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 66 | return (unsigned long *)end; |
| 67 | } |
| 68 | /* |
| 69 | * If this is a debug stack, and if it has a larger size than |
| 70 | * the usual exception stacks, then 'stack' might still |
| 71 | * be within the lower portion of the debug stack: |
| 72 | */ |
| 73 | #if DEBUG_STKSZ > EXCEPTION_STKSZ |
| 74 | if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) { |
| 75 | unsigned j = N_EXCEPTION_STACKS - 1; |
| 76 | |
| 77 | /* |
| 78 | * Black magic. A large debug stack is composed of |
| 79 | * multiple exception stack entries, which we |
| 80 | * iterate through now. Dont look: |
| 81 | */ |
| 82 | do { |
| 83 | ++j; |
| 84 | end -= EXCEPTION_STKSZ; |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 85 | x86_stack_ids[j][4] = '1' + |
| 86 | (j - N_EXCEPTION_STACKS); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 87 | } while (stack < end - EXCEPTION_STKSZ); |
| 88 | if (*usedp & (1U << j)) |
| 89 | break; |
| 90 | *usedp |= 1U << j; |
Frederic Weisbecker | 0406ca6 | 2009-07-01 21:02:09 +0200 | [diff] [blame] | 91 | *idp = x86_stack_ids[j]; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 92 | return (unsigned long *)end; |
| 93 | } |
| 94 | #endif |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
Frederic Weisbecker | af2d828 | 2009-12-06 05:34:27 +0100 | [diff] [blame] | 99 | static inline int |
| 100 | in_irq_stack(unsigned long *stack, unsigned long *irq_stack, |
| 101 | unsigned long *irq_stack_end) |
| 102 | { |
| 103 | return (stack >= irq_stack && stack < irq_stack_end); |
| 104 | } |
| 105 | |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 106 | static const unsigned long irq_stack_size = |
| 107 | (IRQ_STACK_SIZE - 64) / sizeof(unsigned long); |
| 108 | |
| 109 | enum stack_type { |
| 110 | STACK_IS_UNKNOWN, |
| 111 | STACK_IS_NORMAL, |
| 112 | STACK_IS_EXCEPTION, |
| 113 | STACK_IS_IRQ, |
| 114 | }; |
| 115 | |
| 116 | static enum stack_type |
Steven Rostedt (Red Hat) | 1aabc59 | 2014-04-02 13:26:40 -0400 | [diff] [blame] | 117 | analyze_stack(int cpu, struct task_struct *task, unsigned long *stack, |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 118 | unsigned long **stack_end, unsigned long *irq_stack, |
| 119 | unsigned *used, char **id) |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 120 | { |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 121 | unsigned long addr; |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 122 | |
| 123 | addr = ((unsigned long)stack & (~(THREAD_SIZE - 1))); |
| 124 | if ((unsigned long)task_stack_page(task) == addr) |
| 125 | return STACK_IS_NORMAL; |
| 126 | |
| 127 | *stack_end = in_exception_stack(cpu, (unsigned long)stack, |
Steven Rostedt (Red Hat) | 1aabc59 | 2014-04-02 13:26:40 -0400 | [diff] [blame] | 128 | used, id); |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 129 | if (*stack_end) |
| 130 | return STACK_IS_EXCEPTION; |
| 131 | |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 132 | if (!irq_stack) |
| 133 | return STACK_IS_NORMAL; |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 134 | |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 135 | *stack_end = irq_stack; |
| 136 | irq_stack = irq_stack - irq_stack_size; |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 137 | |
| 138 | if (in_irq_stack(stack, irq_stack, *stack_end)) |
| 139 | return STACK_IS_IRQ; |
| 140 | |
| 141 | return STACK_IS_UNKNOWN; |
| 142 | } |
| 143 | |
Frederic Weisbecker | af2d828 | 2009-12-06 05:34:27 +0100 | [diff] [blame] | 144 | /* |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 145 | * x86-64 can have up to three kernel stacks: |
| 146 | * process stack |
| 147 | * interrupt stack |
| 148 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack |
| 149 | */ |
| 150 | |
Namhyung Kim | e8e999cf | 2011-03-18 11:40:06 +0900 | [diff] [blame] | 151 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
| 152 | unsigned long *stack, unsigned long bp, |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 153 | const struct stacktrace_ops *ops, void *data) |
| 154 | { |
| 155 | const unsigned cpu = get_cpu(); |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 156 | unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu); |
Jesper Juhl | 2e5aa68 | 2011-01-24 22:41:11 +0100 | [diff] [blame] | 157 | unsigned long dummy; |
Steven Rostedt (Red Hat) | 1aabc59 | 2014-04-02 13:26:40 -0400 | [diff] [blame] | 158 | unsigned used = 0; |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 159 | int graph = 0; |
| 160 | int done = 0; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 161 | |
| 162 | if (!task) |
| 163 | task = current; |
| 164 | |
| 165 | if (!stack) { |
Frederic Weisbecker | 47ce11a | 2011-06-30 19:04:56 +0200 | [diff] [blame] | 166 | if (regs) |
| 167 | stack = (unsigned long *)regs->sp; |
Dan Carpenter | d0caf292 | 2012-01-28 13:52:46 +0300 | [diff] [blame] | 168 | else if (task != current) |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 169 | stack = (unsigned long *)task->thread.sp; |
Frederic Weisbecker | 47ce11a | 2011-06-30 19:04:56 +0200 | [diff] [blame] | 170 | else |
| 171 | stack = &dummy; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Namhyung Kim | e8e999cf | 2011-03-18 11:40:06 +0900 | [diff] [blame] | 174 | if (!bp) |
| 175 | bp = stack_frame(task, regs); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 176 | /* |
| 177 | * Print function call entries in all stacks, starting at the |
| 178 | * current stack address. If the stacks consist of nested |
| 179 | * exceptions |
| 180 | */ |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 181 | while (!done) { |
| 182 | unsigned long *stack_end; |
| 183 | enum stack_type stype; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 184 | char *id; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 185 | |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 186 | stype = analyze_stack(cpu, task, stack, &stack_end, |
| 187 | irq_stack, &used, &id); |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 188 | |
| 189 | /* Default finish unless specified to continue */ |
| 190 | done = 1; |
| 191 | |
| 192 | switch (stype) { |
| 193 | |
| 194 | /* Break out early if we are on the thread stack */ |
| 195 | case STACK_IS_NORMAL: |
| 196 | break; |
| 197 | |
| 198 | case STACK_IS_EXCEPTION: |
| 199 | |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 200 | if (ops->stack(data, id) < 0) |
| 201 | break; |
| 202 | |
Linus Torvalds | da01e18 | 2016-06-23 12:20:01 -0700 | [diff] [blame] | 203 | bp = ops->walk_stack(task, stack, bp, ops, |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 204 | data, stack_end, &graph); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 205 | ops->stack(data, "<EOE>"); |
| 206 | /* |
| 207 | * We link to the next stack via the |
| 208 | * second-to-last pointer (index -2 to end) in the |
| 209 | * exception stack: |
| 210 | */ |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 211 | stack = (unsigned long *) stack_end[-2]; |
| 212 | done = 0; |
| 213 | break; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 214 | |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 215 | case STACK_IS_IRQ: |
| 216 | |
| 217 | if (ops->stack(data, "IRQ") < 0) |
| 218 | break; |
Linus Torvalds | da01e18 | 2016-06-23 12:20:01 -0700 | [diff] [blame] | 219 | bp = ops->walk_stack(task, stack, bp, |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 220 | ops, data, stack_end, &graph); |
| 221 | /* |
| 222 | * We link to the next stack (which would be |
| 223 | * the process stack normally) the last |
| 224 | * pointer (index -1 to end) in the IRQ stack: |
| 225 | */ |
| 226 | stack = (unsigned long *) (stack_end[-1]); |
Steven Rostedt (Red Hat) | 63c95654 | 2014-04-02 13:26:41 -0400 | [diff] [blame] | 227 | irq_stack = NULL; |
Steven Rostedt | 2223f6f | 2014-02-06 09:41:32 -0500 | [diff] [blame] | 228 | ops->stack(data, "EOI"); |
| 229 | done = 0; |
| 230 | break; |
| 231 | |
| 232 | case STACK_IS_UNKNOWN: |
| 233 | ops->stack(data, "UNK"); |
| 234 | break; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 235 | } |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* |
| 239 | * This handles the process stack: |
| 240 | */ |
Linus Torvalds | da01e18 | 2016-06-23 12:20:01 -0700 | [diff] [blame] | 241 | bp = ops->walk_stack(task, stack, bp, ops, data, NULL, &graph); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 242 | put_cpu(); |
| 243 | } |
| 244 | EXPORT_SYMBOL(dump_trace); |
| 245 | |
Neil Horman | 878719e | 2008-10-23 10:40:06 -0400 | [diff] [blame] | 246 | void |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 247 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
Namhyung Kim | e8e999cf | 2011-03-18 11:40:06 +0900 | [diff] [blame] | 248 | unsigned long *sp, unsigned long bp, char *log_lvl) |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 249 | { |
Ingo Molnar | 67f2de0 | 2009-11-26 08:29:10 +0100 | [diff] [blame] | 250 | unsigned long *irq_stack_end; |
| 251 | unsigned long *irq_stack; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 252 | unsigned long *stack; |
Ingo Molnar | 67f2de0 | 2009-11-26 08:29:10 +0100 | [diff] [blame] | 253 | int cpu; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 254 | int i; |
Ingo Molnar | 67f2de0 | 2009-11-26 08:29:10 +0100 | [diff] [blame] | 255 | |
| 256 | preempt_disable(); |
| 257 | cpu = smp_processor_id(); |
| 258 | |
| 259 | irq_stack_end = (unsigned long *)(per_cpu(irq_stack_ptr, cpu)); |
| 260 | irq_stack = (unsigned long *)(per_cpu(irq_stack_ptr, cpu) - IRQ_STACK_SIZE); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 261 | |
| 262 | /* |
Ingo Molnar | 67f2de0 | 2009-11-26 08:29:10 +0100 | [diff] [blame] | 263 | * Debugging aid: "show_stack(NULL, NULL);" prints the |
| 264 | * back trace for this cpu: |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 265 | */ |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 266 | if (sp == NULL) { |
| 267 | if (task) |
| 268 | sp = (unsigned long *)task->thread.sp; |
| 269 | else |
| 270 | sp = (unsigned long *)&sp; |
| 271 | } |
| 272 | |
| 273 | stack = sp; |
| 274 | for (i = 0; i < kstack_depth_to_print; i++) { |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 275 | if (stack >= irq_stack && stack <= irq_stack_end) { |
| 276 | if (stack == irq_stack_end) { |
| 277 | stack = (unsigned long *) (irq_stack_end[-1]); |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 278 | pr_cont(" <EOI> "); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 279 | } |
| 280 | } else { |
Adrien Schildknecht | 04769ae | 2015-02-22 16:23:58 +0100 | [diff] [blame] | 281 | if (kstack_end(stack)) |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 282 | break; |
| 283 | } |
Adrien Schildknecht | 1fc7f61 | 2015-02-20 03:34:21 +0100 | [diff] [blame] | 284 | if ((i % STACKSLOTS_PER_LINE) == 0) { |
| 285 | if (i != 0) |
| 286 | pr_cont("\n"); |
| 287 | printk("%s %016lx", log_lvl, *stack++); |
| 288 | } else |
| 289 | pr_cont(" %016lx", *stack++); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 290 | touch_nmi_watchdog(); |
| 291 | } |
Ingo Molnar | 67f2de0 | 2009-11-26 08:29:10 +0100 | [diff] [blame] | 292 | preempt_enable(); |
| 293 | |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 294 | pr_cont("\n"); |
Namhyung Kim | e8e999cf | 2011-03-18 11:40:06 +0900 | [diff] [blame] | 295 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Jan Beulich | 57da8b9 | 2012-05-09 08:47:37 +0100 | [diff] [blame] | 298 | void show_regs(struct pt_regs *regs) |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 299 | { |
| 300 | int i; |
| 301 | unsigned long sp; |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 302 | |
| 303 | sp = regs->sp; |
Tejun Heo | a43cb95 | 2013-04-30 15:27:17 -0700 | [diff] [blame] | 304 | show_regs_print_info(KERN_DEFAULT); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 305 | __show_regs(regs, 1); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 306 | |
| 307 | /* |
| 308 | * When in-kernel, we also print out the stack and code at the |
| 309 | * time of the fault.. |
| 310 | */ |
| 311 | if (!user_mode(regs)) { |
| 312 | unsigned int code_prologue = code_bytes * 43 / 64; |
| 313 | unsigned int code_len = code_bytes; |
| 314 | unsigned char c; |
| 315 | u8 *ip; |
| 316 | |
Prarit Bhargava | b0f4c4b | 2012-01-26 08:55:34 -0500 | [diff] [blame] | 317 | printk(KERN_DEFAULT "Stack:\n"); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 318 | show_stack_log_lvl(NULL, regs, (unsigned long *)sp, |
Prarit Bhargava | b0f4c4b | 2012-01-26 08:55:34 -0500 | [diff] [blame] | 319 | 0, KERN_DEFAULT); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 320 | |
Prarit Bhargava | b0f4c4b | 2012-01-26 08:55:34 -0500 | [diff] [blame] | 321 | printk(KERN_DEFAULT "Code: "); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 322 | |
| 323 | ip = (u8 *)regs->ip - code_prologue; |
| 324 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { |
Alexander van Heukelum | 8a54166 | 2008-10-04 23:12:46 +0200 | [diff] [blame] | 325 | /* try starting at IP */ |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 326 | ip = (u8 *)regs->ip; |
| 327 | code_len = code_len - code_prologue + 1; |
| 328 | } |
| 329 | for (i = 0; i < code_len; i++, ip++) { |
| 330 | if (ip < (u8 *)PAGE_OFFSET || |
| 331 | probe_kernel_address(ip, c)) { |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 332 | pr_cont(" Bad RIP value."); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 333 | break; |
| 334 | } |
| 335 | if (ip == (u8 *)regs->ip) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 336 | pr_cont("<%02x> ", c); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 337 | else |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 338 | pr_cont("%02x ", c); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 339 | } |
| 340 | } |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 341 | pr_cont("\n"); |
Alexander van Heukelum | 6fcbede | 2008-09-30 13:12:15 +0200 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | int is_valid_bugaddr(unsigned long ip) |
| 345 | { |
| 346 | unsigned short ud2; |
| 347 | |
| 348 | if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2))) |
| 349 | return 0; |
| 350 | |
| 351 | return ud2 == 0x0b0f; |
| 352 | } |