diff options
Diffstat (limited to 'arch/x86/kernel/dumpstack_64.c')
| -rw-r--r-- | arch/x86/kernel/dumpstack_64.c | 289 |
1 files changed, 6 insertions, 283 deletions
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c index 96a5db7da8a7..c302d0707048 100644 --- a/arch/x86/kernel/dumpstack_64.c +++ b/arch/x86/kernel/dumpstack_64.c | |||
| @@ -17,19 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | #include <asm/stacktrace.h> | 18 | #include <asm/stacktrace.h> |
| 19 | 19 | ||
| 20 | #define STACKSLOTS_PER_LINE 4 | 20 | #include "dumpstack.h" |
| 21 | #define get_bp(bp) asm("movq %%rbp, %0" : "=r" (bp) :) | ||
| 22 | |||
| 23 | int panic_on_unrecovered_nmi; | ||
| 24 | int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; | ||
| 25 | static unsigned int code_bytes = 64; | ||
| 26 | static int die_counter; | ||
| 27 | |||
| 28 | void printk_address(unsigned long address, int reliable) | ||
| 29 | { | ||
| 30 | printk(" [<%p>] %s%pS\n", (void *) address, | ||
| 31 | reliable ? "" : "? ", (void *) address); | ||
| 32 | } | ||
| 33 | 21 | ||
| 34 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | 22 | static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, |
| 35 | unsigned *usedp, char **idp) | 23 | unsigned *usedp, char **idp) |
| @@ -113,51 +101,6 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack, | |||
| 113 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack | 101 | * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack |
| 114 | */ | 102 | */ |
| 115 | 103 | ||
| 116 | static inline int valid_stack_ptr(struct thread_info *tinfo, | ||
| 117 | void *p, unsigned int size, void *end) | ||
| 118 | { | ||
| 119 | void *t = tinfo; | ||
| 120 | if (end) { | ||
| 121 | if (p < end && p >= (end-THREAD_SIZE)) | ||
| 122 | return 1; | ||
| 123 | else | ||
| 124 | return 0; | ||
| 125 | } | ||
| 126 | return p > t && p < t + THREAD_SIZE - size; | ||
| 127 | } | ||
| 128 | |||
| 129 | /* The form of the top of the frame on the stack */ | ||
| 130 | struct stack_frame { | ||
| 131 | struct stack_frame *next_frame; | ||
| 132 | unsigned long return_address; | ||
| 133 | }; | ||
| 134 | |||
| 135 | static inline unsigned long | ||
| 136 | print_context_stack(struct thread_info *tinfo, | ||
| 137 | unsigned long *stack, unsigned long bp, | ||
| 138 | const struct stacktrace_ops *ops, void *data, | ||
| 139 | unsigned long *end) | ||
| 140 | { | ||
| 141 | struct stack_frame *frame = (struct stack_frame *)bp; | ||
| 142 | |||
| 143 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) { | ||
| 144 | unsigned long addr; | ||
| 145 | |||
| 146 | addr = *stack; | ||
| 147 | if (__kernel_text_address(addr)) { | ||
| 148 | if ((unsigned long) stack == bp + sizeof(long)) { | ||
| 149 | ops->address(data, addr, 1); | ||
| 150 | frame = frame->next_frame; | ||
| 151 | bp = (unsigned long) frame; | ||
| 152 | } else { | ||
| 153 | ops->address(data, addr, bp == 0); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | stack++; | ||
| 157 | } | ||
| 158 | return bp; | ||
| 159 | } | ||
| 160 | |||
| 161 | void dump_trace(struct task_struct *task, struct pt_regs *regs, | 104 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
| 162 | unsigned long *stack, unsigned long bp, | 105 | unsigned long *stack, unsigned long bp, |
| 163 | const struct stacktrace_ops *ops, void *data) | 106 | const struct stacktrace_ops *ops, void *data) |
| @@ -166,6 +109,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
| 166 | unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr; | 109 | unsigned long *irqstack_end = (unsigned long *)cpu_pda(cpu)->irqstackptr; |
| 167 | unsigned used = 0; | 110 | unsigned used = 0; |
| 168 | struct thread_info *tinfo; | 111 | struct thread_info *tinfo; |
| 112 | int graph = 0; | ||
| 169 | 113 | ||
| 170 | if (!task) | 114 | if (!task) |
| 171 | task = current; | 115 | task = current; |
| @@ -206,7 +150,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
| 206 | break; | 150 | break; |
| 207 | 151 | ||
| 208 | bp = print_context_stack(tinfo, stack, bp, ops, | 152 | bp = print_context_stack(tinfo, stack, bp, ops, |
| 209 | data, estack_end); | 153 | data, estack_end, &graph); |
| 210 | ops->stack(data, "<EOE>"); | 154 | ops->stack(data, "<EOE>"); |
| 211 | /* | 155 | /* |
| 212 | * We link to the next stack via the | 156 | * We link to the next stack via the |
| @@ -225,7 +169,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
| 225 | if (ops->stack(data, "IRQ") < 0) | 169 | if (ops->stack(data, "IRQ") < 0) |
| 226 | break; | 170 | break; |
| 227 | bp = print_context_stack(tinfo, stack, bp, | 171 | bp = print_context_stack(tinfo, stack, bp, |
| 228 | ops, data, irqstack_end); | 172 | ops, data, irqstack_end, &graph); |
| 229 | /* | 173 | /* |
| 230 | * We link to the next stack (which would be | 174 | * We link to the next stack (which would be |
| 231 | * the process stack normally) the last | 175 | * the process stack normally) the last |
| @@ -243,62 +187,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, | |||
| 243 | /* | 187 | /* |
| 244 | * This handles the process stack: | 188 | * This handles the process stack: |
| 245 | */ | 189 | */ |
| 246 | bp = print_context_stack(tinfo, stack, bp, ops, data, NULL); | 190 | bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph); |
| 247 | put_cpu(); | 191 | put_cpu(); |
| 248 | } | 192 | } |
| 249 | EXPORT_SYMBOL(dump_trace); | 193 | EXPORT_SYMBOL(dump_trace); |
| 250 | 194 | ||
| 251 | static void | 195 | void |
| 252 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | ||
| 253 | { | ||
| 254 | printk(data); | ||
| 255 | print_symbol(msg, symbol); | ||
| 256 | printk("\n"); | ||
| 257 | } | ||
| 258 | |||
| 259 | static void print_trace_warning(void *data, char *msg) | ||
| 260 | { | ||
| 261 | printk("%s%s\n", (char *)data, msg); | ||
| 262 | } | ||
| 263 | |||
| 264 | static int print_trace_stack(void *data, char *name) | ||
| 265 | { | ||
| 266 | printk("%s <%s> ", (char *)data, name); | ||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | |||
| 270 | /* | ||
| 271 | * Print one address/symbol entries per line. | ||
| 272 | */ | ||
| 273 | static void print_trace_address(void *data, unsigned long addr, int reliable) | ||
| 274 | { | ||
| 275 | touch_nmi_watchdog(); | ||
| 276 | printk(data); | ||
| 277 | printk_address(addr, reliable); | ||
| 278 | } | ||
| 279 | |||
| 280 | static const struct stacktrace_ops print_trace_ops = { | ||
| 281 | .warning = print_trace_warning, | ||
| 282 | .warning_symbol = print_trace_warning_symbol, | ||
| 283 | .stack = print_trace_stack, | ||
| 284 | .address = print_trace_address, | ||
| 285 | }; | ||
| 286 | |||
| 287 | static void | ||
| 288 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | ||
| 289 | unsigned long *stack, unsigned long bp, char *log_lvl) | ||
| 290 | { | ||
| 291 | printk("%sCall Trace:\n", log_lvl); | ||
| 292 | dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl); | ||
| 293 | } | ||
| 294 | |||
| 295 | void show_trace(struct task_struct *task, struct pt_regs *regs, | ||
| 296 | unsigned long *stack, unsigned long bp) | ||
| 297 | { | ||
| 298 | show_trace_log_lvl(task, regs, stack, bp, ""); | ||
| 299 | } | ||
| 300 | |||
| 301 | static void | ||
| 302 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | 196 | show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
| 303 | unsigned long *sp, unsigned long bp, char *log_lvl) | 197 | unsigned long *sp, unsigned long bp, char *log_lvl) |
| 304 | { | 198 | { |
| @@ -342,33 +236,6 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, | |||
| 342 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); | 236 | show_trace_log_lvl(task, regs, sp, bp, log_lvl); |
| 343 | } | 237 | } |
| 344 | 238 | ||
| 345 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
| 346 | { | ||
| 347 | show_stack_log_lvl(task, NULL, sp, 0, ""); | ||
| 348 | } | ||
| 349 | |||
| 350 | /* | ||
| 351 | * The architecture-independent dump_stack generator | ||
| 352 | */ | ||
| 353 | void dump_stack(void) | ||
| 354 | { | ||
| 355 | unsigned long bp = 0; | ||
| 356 | unsigned long stack; | ||
| 357 | |||
| 358 | #ifdef CONFIG_FRAME_POINTER | ||
| 359 | if (!bp) | ||
| 360 | get_bp(bp); | ||
| 361 | #endif | ||
| 362 | |||
| 363 | printk("Pid: %d, comm: %.20s %s %s %.*s\n", | ||
| 364 | current->pid, current->comm, print_tainted(), | ||
| 365 | init_utsname()->release, | ||
| 366 | (int)strcspn(init_utsname()->version, " "), | ||
| 367 | init_utsname()->version); | ||
| 368 | show_trace(NULL, NULL, &stack, bp); | ||
| 369 | } | ||
| 370 | EXPORT_SYMBOL(dump_stack); | ||
| 371 | |||
| 372 | void show_registers(struct pt_regs *regs) | 239 | void show_registers(struct pt_regs *regs) |
| 373 | { | 240 | { |
| 374 | int i; | 241 | int i; |
| @@ -429,147 +296,3 @@ int is_valid_bugaddr(unsigned long ip) | |||
| 429 | return ud2 == 0x0b0f; | 296 | return ud2 == 0x0b0f; |
| 430 | } | 297 | } |
| 431 | 298 | ||
| 432 | static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED; | ||
| 433 | static int die_owner = -1; | ||
| 434 | static unsigned int die_nest_count; | ||
| 435 | |||
| 436 | unsigned __kprobes long oops_begin(void) | ||
| 437 | { | ||
| 438 | int cpu; | ||
| 439 | unsigned long flags; | ||
| 440 | |||
| 441 | oops_enter(); | ||
| 442 | |||
| 443 | /* racy, but better than risking deadlock. */ | ||
| 444 | raw_local_irq_save(flags); | ||
| 445 | cpu = smp_processor_id(); | ||
| 446 | if (!__raw_spin_trylock(&die_lock)) { | ||
| 447 | if (cpu == die_owner) | ||
| 448 | /* nested oops. should stop eventually */; | ||
| 449 | else | ||
| 450 | __raw_spin_lock(&die_lock); | ||
| 451 | } | ||
| 452 | die_nest_count++; | ||
| 453 | die_owner = cpu; | ||
| 454 | console_verbose(); | ||
| 455 | bust_spinlocks(1); | ||
| 456 | return flags; | ||
| 457 | } | ||
| 458 | |||
| 459 | void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr) | ||
| 460 | { | ||
| 461 | die_owner = -1; | ||
| 462 | bust_spinlocks(0); | ||
| 463 | die_nest_count--; | ||
| 464 | if (!die_nest_count) | ||
| 465 | /* Nest count reaches zero, release the lock. */ | ||
| 466 | __raw_spin_unlock(&die_lock); | ||
| 467 | raw_local_irq_restore(flags); | ||
| 468 | if (!regs) { | ||
| 469 | oops_exit(); | ||
| 470 | return; | ||
| 471 | } | ||
| 472 | if (in_interrupt()) | ||
| 473 | panic("Fatal exception in interrupt"); | ||
| 474 | if (panic_on_oops) | ||
| 475 | panic("Fatal exception"); | ||
| 476 | oops_exit(); | ||
| 477 | do_exit(signr); | ||
| 478 | } | ||
| 479 | |||
| 480 | int __kprobes __die(const char *str, struct pt_regs *regs, long err) | ||
| 481 | { | ||
| 482 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter); | ||
| 483 | #ifdef CONFIG_PREEMPT | ||
| 484 | printk("PREEMPT "); | ||
| 485 | #endif | ||
| 486 | #ifdef CONFIG_SMP | ||
| 487 | printk("SMP "); | ||
| 488 | #endif | ||
| 489 | #ifdef CONFIG_DEBUG_PAGEALLOC | ||
| 490 | printk("DEBUG_PAGEALLOC"); | ||
| 491 | #endif | ||
| 492 | printk("\n"); | ||
| 493 | sysfs_printk_last_file(); | ||
| 494 | if (notify_die(DIE_OOPS, str, regs, err, | ||
| 495 | current->thread.trap_no, SIGSEGV) == NOTIFY_STOP) | ||
| 496 | return 1; | ||
| 497 | |||
| 498 | show_registers(regs); | ||
| 499 | add_taint(TAINT_DIE); | ||
| 500 | /* Executive summary in case the oops scrolled away */ | ||
| 501 | printk(KERN_ALERT "RIP "); | ||
| 502 | printk_address(regs->ip, 1); | ||
| 503 | printk(" RSP <%016lx>\n", regs->sp); | ||
| 504 | if (kexec_should_crash(current)) | ||
| 505 | crash_kexec(regs); | ||
| 506 | return 0; | ||
| 507 | } | ||
| 508 | |||
| 509 | void die(const char *str, struct pt_regs *regs, long err) | ||
| 510 | { | ||
| 511 | unsigned long flags = oops_begin(); | ||
| 512 | |||
| 513 | if (!user_mode(regs)) | ||
| 514 | report_bug(regs->ip, regs); | ||
| 515 | |||
| 516 | if (__die(str, regs, err)) | ||
| 517 | regs = NULL; | ||
| 518 | oops_end(flags, regs, SIGSEGV); | ||
| 519 | } | ||
| 520 | |||
| 521 | notrace __kprobes void | ||
| 522 | die_nmi(char *str, struct pt_regs *regs, int do_panic) | ||
| 523 | { | ||
| 524 | unsigned long flags; | ||
| 525 | |||
| 526 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP) | ||
| 527 | return; | ||
| 528 | |||
| 529 | flags = oops_begin(); | ||
| 530 | /* | ||
| 531 | * We are in trouble anyway, lets at least try | ||
| 532 | * to get a message out. | ||
| 533 | */ | ||
| 534 | printk(KERN_EMERG "%s", str); | ||
| 535 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
| 536 | smp_processor_id(), regs->ip); | ||
| 537 | show_registers(regs); | ||
| 538 | if (kexec_should_crash(current)) | ||
| 539 | crash_kexec(regs); | ||
| 540 | if (do_panic || panic_on_oops) | ||
| 541 | panic("Non maskable interrupt"); | ||
| 542 | oops_end(flags, NULL, SIGBUS); | ||
| 543 | nmi_exit(); | ||
| 544 | local_irq_enable(); | ||
| 545 | do_exit(SIGBUS); | ||
| 546 | } | ||
| 547 | |||
| 548 | static int __init oops_setup(char *s) | ||
| 549 | { | ||
| 550 | if (!s) | ||
| 551 | return -EINVAL; | ||
| 552 | if (!strcmp(s, "panic")) | ||
| 553 | panic_on_oops = 1; | ||
| 554 | return 0; | ||
| 555 | } | ||
| 556 | early_param("oops", oops_setup); | ||
| 557 | |||
| 558 | static int __init kstack_setup(char *s) | ||
| 559 | { | ||
| 560 | if (!s) | ||
| 561 | return -EINVAL; | ||
| 562 | kstack_depth_to_print = simple_strtoul(s, NULL, 0); | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | early_param("kstack", kstack_setup); | ||
| 566 | |||
| 567 | static int __init code_bytes_setup(char *s) | ||
| 568 | { | ||
| 569 | code_bytes = simple_strtoul(s, NULL, 0); | ||
| 570 | if (code_bytes > 8192) | ||
| 571 | code_bytes = 8192; | ||
| 572 | |||
| 573 | return 1; | ||
| 574 | } | ||
| 575 | __setup("code_bytes=", code_bytes_setup); | ||
