Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'sh/dwarf-unwinder'

Conflicts:
arch/sh/kernel/cpu/sh3/entry.S

+265 -130
+31
arch/sh/include/asm/bug.h
··· 2 2 #define __ASM_SH_BUG_H 3 3 4 4 #define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */ 5 + #define BUGFLAG_UNWINDER (1 << 1) 5 6 6 7 #ifdef CONFIG_GENERIC_BUG 7 8 #define HAVE_ARCH_BUG ··· 72 71 } \ 73 72 unlikely(__ret_warn_on); \ 74 73 }) 74 + 75 + #define UNWINDER_BUG() \ 76 + do { \ 77 + __asm__ __volatile__ ( \ 78 + "1:\t.short %O0\n" \ 79 + _EMIT_BUG_ENTRY \ 80 + : \ 81 + : "n" (TRAPA_BUG_OPCODE), \ 82 + "i" (__FILE__), \ 83 + "i" (__LINE__), \ 84 + "i" (BUGFLAG_UNWINDER), \ 85 + "i" (sizeof(struct bug_entry))); \ 86 + } while (0) 87 + 88 + #define UNWINDER_BUG_ON(x) ({ \ 89 + int __ret_unwinder_on = !!(x); \ 90 + if (__builtin_constant_p(__ret_unwinder_on)) { \ 91 + if (__ret_unwinder_on) \ 92 + UNWINDER_BUG(); \ 93 + } else { \ 94 + if (unlikely(__ret_unwinder_on)) \ 95 + UNWINDER_BUG(); \ 96 + } \ 97 + unlikely(__ret_unwinder_on); \ 98 + }) 99 + 100 + #else 101 + 102 + #define UNWINDER_BUG BUG 103 + #define UNWINDER_BUG_ON BUG_ON 75 104 76 105 #endif /* CONFIG_GENERIC_BUG */ 77 106
+10 -18
arch/sh/include/asm/dwarf.h
··· 265 265 266 266 unsigned long pc; 267 267 268 - struct dwarf_reg *regs; 269 - unsigned int num_regs; /* how many regs are allocated? */ 270 - 271 - unsigned int depth; /* what level are we in the callstack? */ 268 + struct list_head reg_list; 272 269 273 270 unsigned long cfa; 274 271 ··· 289 292 * @flags: Describes how to calculate the value of this register 290 293 */ 291 294 struct dwarf_reg { 295 + struct list_head link; 296 + 297 + unsigned int number; 298 + 292 299 unsigned long addr; 293 300 unsigned long flags; 294 301 #define DWARF_REG_OFFSET (1 << 0) 295 - }; 296 - 297 - /** 298 - * dwarf_stack - a DWARF stack contains a collection of DWARF frames 299 - * @depth: the number of frames in the stack 300 - * @level: an array of DWARF frames, indexed by stack level 301 - * 302 - */ 303 - struct dwarf_stack { 304 - unsigned int depth; 305 - struct dwarf_frame **level; 302 + #define DWARF_VAL_OFFSET (1 << 1) 303 + #define DWARF_UNDEFINED (1 << 2) 306 304 }; 307 305 308 306 /* ··· 362 370 #define DW_EXT_HI 0xffffffff 363 371 #define DW_EXT_DWARF64 DW_EXT_HI 364 372 365 - extern void dwarf_unwinder_init(void); 366 - 367 373 extern struct dwarf_frame *dwarf_unwind_stack(unsigned long, 368 374 struct dwarf_frame *); 369 - #endif /* __ASSEMBLY__ */ 375 + #endif /* !__ASSEMBLY__ */ 370 376 371 377 #define CFI_STARTPROC .cfi_startproc 372 378 #define CFI_ENDPROC .cfi_endproc 373 379 #define CFI_DEF_CFA .cfi_def_cfa 374 380 #define CFI_REGISTER .cfi_register 375 381 #define CFI_REL_OFFSET .cfi_rel_offset 382 + #define CFI_UNDEFINED .cfi_undefined 376 383 377 384 #else 378 385 ··· 385 394 #define CFI_DEF_CFA CFI_IGNORE 386 395 #define CFI_REGISTER CFI_IGNORE 387 396 #define CFI_REL_OFFSET CFI_IGNORE 397 + #define CFI_UNDEFINED CFI_IGNORE 388 398 389 399 #ifndef __ASSEMBLY__ 390 400 static inline void dwarf_unwinder_init(void)
+5
arch/sh/include/asm/system.h
··· 181 181 BUILD_TRAP_HANDLER(singlestep); 182 182 BUILD_TRAP_HANDLER(fpu_error); 183 183 BUILD_TRAP_HANDLER(fpu_state_restore); 184 + BUILD_TRAP_HANDLER(unwinder); 185 + 186 + #ifdef CONFIG_BUG 187 + extern void handle_BUG(struct pt_regs *); 188 + #endif 184 189 185 190 #define arch_align_stack(x) (x) 186 191
+6
arch/sh/include/asm/unwinder.h
··· 22 22 unsigned long *, const struct stacktrace_ops *, 23 23 void *); 24 24 25 + /* 26 + * Used by fault handling code to signal to the unwinder code that it 27 + * should switch to a different unwinder. 28 + */ 29 + extern int unwinder_faulted; 30 + 25 31 #endif /* _LINUX_UNWINDER_H */
+2
arch/sh/kernel/cpu/sh3/entry.S
··· 508 508 bsr save_regs ! needs original pr value in k3 509 509 mov #-1, k2 ! default vector kept in k2 510 510 511 + setup_frame_reg 512 + 511 513 stc sr, r0 ! get status register 512 514 shlr2 r0 513 515 and #0x3c, r0
+181 -97
arch/sh/kernel/dwarf.c
··· 11 11 * 12 12 * TODO: 13 13 * - DWARF64 doesn't work. 14 + * - Registers with DWARF_VAL_OFFSET rules aren't handled properly. 14 15 */ 15 16 16 17 /* #define DEBUG */ 17 18 #include <linux/kernel.h> 18 19 #include <linux/io.h> 19 20 #include <linux/list.h> 21 + #include <linux/mempool.h> 20 22 #include <linux/mm.h> 21 23 #include <asm/dwarf.h> 22 24 #include <asm/unwinder.h> ··· 27 25 #include <asm/dwarf.h> 28 26 #include <asm/stacktrace.h> 29 27 28 + /* Reserve enough memory for two stack frames */ 29 + #define DWARF_FRAME_MIN_REQ 2 30 + /* ... with 4 registers per frame. */ 31 + #define DWARF_REG_MIN_REQ (DWARF_FRAME_MIN_REQ * 4) 32 + 33 + static struct kmem_cache *dwarf_frame_cachep; 34 + static mempool_t *dwarf_frame_pool; 35 + 36 + static struct kmem_cache *dwarf_reg_cachep; 37 + static mempool_t *dwarf_reg_pool; 38 + 30 39 static LIST_HEAD(dwarf_cie_list); 31 - DEFINE_SPINLOCK(dwarf_cie_lock); 40 + static DEFINE_SPINLOCK(dwarf_cie_lock); 32 41 33 42 static LIST_HEAD(dwarf_fde_list); 34 - DEFINE_SPINLOCK(dwarf_fde_lock); 43 + static DEFINE_SPINLOCK(dwarf_fde_lock); 35 44 36 45 static struct dwarf_cie *cached_cie; 37 46 38 - /* 39 - * Figure out whether we need to allocate some dwarf registers. If dwarf 40 - * registers have already been allocated then we may need to realloc 41 - * them. "reg" is a register number that we need to be able to access 42 - * after this call. 47 + /** 48 + * dwarf_frame_alloc_reg - allocate memory for a DWARF register 49 + * @frame: the DWARF frame whose list of registers we insert on 50 + * @reg_num: the register number 43 51 * 44 - * Register numbers start at zero, therefore we need to allocate space 45 - * for "reg" + 1 registers. 52 + * Allocate space for, and initialise, a dwarf reg from 53 + * dwarf_reg_pool and insert it onto the (unsorted) linked-list of 54 + * dwarf registers for @frame. 55 + * 56 + * Return the initialised DWARF reg. 46 57 */ 47 - static void dwarf_frame_alloc_regs(struct dwarf_frame *frame, 48 - unsigned int reg) 58 + static struct dwarf_reg *dwarf_frame_alloc_reg(struct dwarf_frame *frame, 59 + unsigned int reg_num) 49 60 { 50 - struct dwarf_reg *regs; 51 - unsigned int num_regs = reg + 1; 52 - size_t new_size; 53 - size_t old_size; 61 + struct dwarf_reg *reg; 54 62 55 - new_size = num_regs * sizeof(*regs); 56 - old_size = frame->num_regs * sizeof(*regs); 57 - 58 - /* Fast path: don't allocate any regs if we've already got enough. */ 59 - if (frame->num_regs >= num_regs) 60 - return; 61 - 62 - regs = kzalloc(new_size, GFP_ATOMIC); 63 - if (!regs) { 64 - printk(KERN_WARNING "Unable to allocate DWARF registers\n"); 63 + reg = mempool_alloc(dwarf_reg_pool, GFP_ATOMIC); 64 + if (!reg) { 65 + printk(KERN_WARNING "Unable to allocate a DWARF register\n"); 65 66 /* 66 67 * Let's just bomb hard here, we have no way to 67 68 * gracefully recover. 68 69 */ 69 - BUG(); 70 + UNWINDER_BUG(); 70 71 } 71 72 72 - if (frame->regs) { 73 - memcpy(regs, frame->regs, old_size); 74 - kfree(frame->regs); 73 + reg->number = reg_num; 74 + reg->addr = 0; 75 + reg->flags = 0; 76 + 77 + list_add(&reg->link, &frame->reg_list); 78 + 79 + return reg; 80 + } 81 + 82 + static void dwarf_frame_free_regs(struct dwarf_frame *frame) 83 + { 84 + struct dwarf_reg *reg, *n; 85 + 86 + list_for_each_entry_safe(reg, n, &frame->reg_list, link) { 87 + list_del(&reg->link); 88 + mempool_free(reg, dwarf_reg_pool); 89 + } 90 + } 91 + 92 + /** 93 + * dwarf_frame_reg - return a DWARF register 94 + * @frame: the DWARF frame to search in for @reg_num 95 + * @reg_num: the register number to search for 96 + * 97 + * Lookup and return the dwarf reg @reg_num for this frame. Return 98 + * NULL if @reg_num is an register invalid number. 99 + */ 100 + static struct dwarf_reg *dwarf_frame_reg(struct dwarf_frame *frame, 101 + unsigned int reg_num) 102 + { 103 + struct dwarf_reg *reg; 104 + 105 + list_for_each_entry(reg, &frame->reg_list, link) { 106 + if (reg->number == reg_num) 107 + return reg; 75 108 } 76 109 77 - frame->regs = regs; 78 - frame->num_regs = num_regs; 110 + return NULL; 79 111 } 80 112 81 113 /** ··· 232 196 break; 233 197 default: 234 198 pr_debug("encoding=0x%x\n", (encoding & 0x70)); 235 - BUG(); 199 + UNWINDER_BUG(); 236 200 } 237 201 238 202 if ((encoding & 0x07) == 0x00) ··· 247 211 break; 248 212 default: 249 213 pr_debug("encoding=0x%x\n", encoding); 250 - BUG(); 214 + UNWINDER_BUG(); 251 215 } 252 216 253 217 return count; ··· 300 264 */ 301 265 static struct dwarf_cie *dwarf_lookup_cie(unsigned long cie_ptr) 302 266 { 303 - struct dwarf_cie *cie, *n; 267 + struct dwarf_cie *cie; 304 268 unsigned long flags; 305 269 306 270 spin_lock_irqsave(&dwarf_cie_lock, flags); ··· 314 278 goto out; 315 279 } 316 280 317 - list_for_each_entry_safe(cie, n, &dwarf_cie_list, link) { 281 + list_for_each_entry(cie, &dwarf_cie_list, link) { 318 282 if (cie->cie_pointer == cie_ptr) { 319 283 cached_cie = cie; 320 284 break; ··· 335 299 */ 336 300 struct dwarf_fde *dwarf_lookup_fde(unsigned long pc) 337 301 { 302 + struct dwarf_fde *fde; 338 303 unsigned long flags; 339 - struct dwarf_fde *fde, *n; 340 304 341 305 spin_lock_irqsave(&dwarf_fde_lock, flags); 342 - list_for_each_entry_safe(fde, n, &dwarf_fde_list, link) { 306 + 307 + list_for_each_entry(fde, &dwarf_fde_list, link) { 343 308 unsigned long start, end; 344 309 345 310 start = fde->initial_location; ··· 383 346 unsigned char insn; 384 347 unsigned char *current_insn; 385 348 unsigned int count, delta, reg, expr_len, offset; 349 + struct dwarf_reg *regp; 386 350 387 351 current_insn = insn_start; 388 352 ··· 406 368 count = dwarf_read_uleb128(current_insn, &offset); 407 369 current_insn += count; 408 370 offset *= cie->data_alignment_factor; 409 - dwarf_frame_alloc_regs(frame, reg); 410 - frame->regs[reg].addr = offset; 411 - frame->regs[reg].flags |= DWARF_REG_OFFSET; 371 + regp = dwarf_frame_alloc_reg(frame, reg); 372 + regp->addr = offset; 373 + regp->flags |= DWARF_REG_OFFSET; 412 374 continue; 413 375 /* NOTREACHED */ 414 376 case DW_CFA_restore: ··· 452 414 case DW_CFA_undefined: 453 415 count = dwarf_read_uleb128(current_insn, &reg); 454 416 current_insn += count; 417 + regp = dwarf_frame_alloc_reg(frame, reg); 418 + regp->flags |= DWARF_UNDEFINED; 455 419 break; 456 420 case DW_CFA_def_cfa: 457 421 count = dwarf_read_uleb128(current_insn, ··· 492 452 count = dwarf_read_leb128(current_insn, &offset); 493 453 current_insn += count; 494 454 offset *= cie->data_alignment_factor; 495 - dwarf_frame_alloc_regs(frame, reg); 496 - frame->regs[reg].flags |= DWARF_REG_OFFSET; 497 - frame->regs[reg].addr = offset; 455 + regp = dwarf_frame_alloc_reg(frame, reg); 456 + regp->flags |= DWARF_REG_OFFSET; 457 + regp->addr = offset; 498 458 break; 499 459 case DW_CFA_val_offset: 500 460 count = dwarf_read_uleb128(current_insn, &reg); 501 461 current_insn += count; 502 462 count = dwarf_read_leb128(current_insn, &offset); 503 463 offset *= cie->data_alignment_factor; 504 - frame->regs[reg].flags |= DWARF_REG_OFFSET; 505 - frame->regs[reg].addr = offset; 464 + regp = dwarf_frame_alloc_reg(frame, reg); 465 + regp->flags |= DWARF_VAL_OFFSET; 466 + regp->addr = offset; 506 467 break; 507 468 case DW_CFA_GNU_args_size: 508 469 count = dwarf_read_uleb128(current_insn, &offset); ··· 514 473 current_insn += count; 515 474 count = dwarf_read_uleb128(current_insn, &offset); 516 475 offset *= cie->data_alignment_factor; 517 - dwarf_frame_alloc_regs(frame, reg); 518 - frame->regs[reg].flags |= DWARF_REG_OFFSET; 519 - frame->regs[reg].addr = -offset; 476 + 477 + regp = dwarf_frame_alloc_reg(frame, reg); 478 + regp->flags |= DWARF_REG_OFFSET; 479 + regp->addr = -offset; 520 480 break; 521 481 default: 522 482 pr_debug("unhandled DWARF instruction 0x%x\n", insn); 483 + UNWINDER_BUG(); 523 484 break; 524 485 } 525 486 } ··· 538 495 * on the callstack. Each of the lower (older) stack frames are 539 496 * linked via the "prev" member. 540 497 */ 541 - struct dwarf_frame *dwarf_unwind_stack(unsigned long pc, 542 - struct dwarf_frame *prev) 498 + struct dwarf_frame * dwarf_unwind_stack(unsigned long pc, 499 + struct dwarf_frame *prev) 543 500 { 544 501 struct dwarf_frame *frame; 545 502 struct dwarf_cie *cie; 546 503 struct dwarf_fde *fde; 504 + struct dwarf_reg *reg; 547 505 unsigned long addr; 548 - int i, offset; 549 506 550 507 /* 551 508 * If this is the first invocation of this recursive function we ··· 558 515 if (!pc && !prev) 559 516 pc = (unsigned long)current_text_addr(); 560 517 561 - frame = kzalloc(sizeof(*frame), GFP_ATOMIC); 562 - if (!frame) 563 - return NULL; 518 + frame = mempool_alloc(dwarf_frame_pool, GFP_ATOMIC); 519 + if (!frame) { 520 + printk(KERN_ERR "Unable to allocate a dwarf frame\n"); 521 + UNWINDER_BUG(); 522 + } 564 523 524 + INIT_LIST_HEAD(&frame->reg_list); 525 + frame->flags = 0; 565 526 frame->prev = prev; 527 + frame->return_addr = 0; 566 528 567 529 fde = dwarf_lookup_fde(pc); 568 530 if (!fde) { ··· 587 539 * case above, which sucks because we could print a 588 540 * warning here. 589 541 */ 590 - return NULL; 542 + goto bail; 591 543 } 592 544 593 545 cie = dwarf_lookup_cie(fde->cie_pointer); ··· 607 559 switch (frame->flags) { 608 560 case DWARF_FRAME_CFA_REG_OFFSET: 609 561 if (prev) { 610 - BUG_ON(!prev->regs[frame->cfa_register].flags); 562 + reg = dwarf_frame_reg(prev, frame->cfa_register); 563 + UNWINDER_BUG_ON(!reg); 564 + UNWINDER_BUG_ON(reg->flags != DWARF_REG_OFFSET); 611 565 612 - addr = prev->cfa; 613 - addr += prev->regs[frame->cfa_register].addr; 566 + addr = prev->cfa + reg->addr; 614 567 frame->cfa = __raw_readl(addr); 615 568 616 569 } else { ··· 628 579 frame->cfa += frame->cfa_offset; 629 580 break; 630 581 default: 631 - BUG(); 582 + UNWINDER_BUG(); 632 583 } 633 584 634 - /* If we haven't seen the return address reg, we're screwed. */ 635 - BUG_ON(!frame->regs[DWARF_ARCH_RA_REG].flags); 585 + reg = dwarf_frame_reg(frame, DWARF_ARCH_RA_REG); 636 586 637 - for (i = 0; i <= frame->num_regs; i++) { 638 - struct dwarf_reg *reg = &frame->regs[i]; 587 + /* 588 + * If we haven't seen the return address register or the return 589 + * address column is undefined then we must assume that this is 590 + * the end of the callstack. 591 + */ 592 + if (!reg || reg->flags == DWARF_UNDEFINED) 593 + goto bail; 639 594 640 - if (!reg->flags) 641 - continue; 595 + UNWINDER_BUG_ON(reg->flags != DWARF_REG_OFFSET); 642 596 643 - offset = reg->addr; 644 - offset += frame->cfa; 645 - } 646 - 647 - addr = frame->cfa + frame->regs[DWARF_ARCH_RA_REG].addr; 597 + addr = frame->cfa + reg->addr; 648 598 frame->return_addr = __raw_readl(addr); 649 599 650 - frame->next = dwarf_unwind_stack(frame->return_addr, frame); 651 600 return frame; 601 + 602 + bail: 603 + dwarf_frame_free_regs(frame); 604 + mempool_free(frame, dwarf_frame_pool); 605 + return NULL; 652 606 } 653 607 654 608 static int dwarf_parse_cie(void *entry, void *p, unsigned long len, ··· 676 624 cie->cie_pointer = (unsigned long)entry; 677 625 678 626 cie->version = *(char *)p++; 679 - BUG_ON(cie->version != 1); 627 + UNWINDER_BUG_ON(cie->version != 1); 680 628 681 629 cie->augmentation = p; 682 630 p += strlen(cie->augmentation) + 1; ··· 706 654 count = dwarf_read_uleb128(p, &length); 707 655 p += count; 708 656 709 - BUG_ON((unsigned char *)p > end); 657 + UNWINDER_BUG_ON((unsigned char *)p > end); 710 658 711 659 cie->initial_instructions = p + length; 712 660 cie->augmentation++; ··· 734 682 * routine in the CIE 735 683 * augmentation. 736 684 */ 737 - BUG(); 685 + UNWINDER_BUG(); 738 686 } else if (*cie->augmentation == 'S') { 739 - BUG(); 687 + UNWINDER_BUG(); 740 688 } else { 741 689 /* 742 690 * Unknown augmentation. Assume 743 691 * 'z' augmentation. 744 692 */ 745 693 p = cie->initial_instructions; 746 - BUG_ON(!p); 694 + UNWINDER_BUG_ON(!p); 747 695 break; 748 696 } 749 697 } ··· 760 708 } 761 709 762 710 static int dwarf_parse_fde(void *entry, u32 entry_type, 763 - void *start, unsigned long len) 711 + void *start, unsigned long len, 712 + unsigned char *end) 764 713 { 765 714 struct dwarf_fde *fde; 766 715 struct dwarf_cie *cie; ··· 808 755 809 756 /* Call frame instructions. */ 810 757 fde->instructions = p; 811 - fde->end = start + len; 758 + fde->end = end; 812 759 813 760 /* Add to list. */ 814 761 spin_lock_irqsave(&dwarf_fde_lock, flags); ··· 818 765 return 0; 819 766 } 820 767 821 - static void dwarf_unwinder_dump(struct task_struct *task, struct pt_regs *regs, 768 + static void dwarf_unwinder_dump(struct task_struct *task, 769 + struct pt_regs *regs, 822 770 unsigned long *sp, 823 - const struct stacktrace_ops *ops, void *data) 771 + const struct stacktrace_ops *ops, 772 + void *data) 824 773 { 825 - struct dwarf_frame *frame; 774 + struct dwarf_frame *frame, *_frame; 775 + unsigned long return_addr; 826 776 827 - frame = dwarf_unwind_stack(0, NULL); 777 + _frame = NULL; 778 + return_addr = 0; 828 779 829 - while (frame && frame->return_addr) { 830 - ops->address(data, frame->return_addr, 1); 831 - frame = frame->next; 780 + while (1) { 781 + frame = dwarf_unwind_stack(return_addr, _frame); 782 + 783 + if (_frame) { 784 + dwarf_frame_free_regs(_frame); 785 + mempool_free(_frame, dwarf_frame_pool); 786 + } 787 + 788 + _frame = frame; 789 + 790 + if (!frame || !frame->return_addr) 791 + break; 792 + 793 + return_addr = frame->return_addr; 794 + ops->address(data, return_addr, 1); 832 795 } 833 796 } 834 797 ··· 856 787 857 788 static void dwarf_unwinder_cleanup(void) 858 789 { 859 - struct dwarf_cie *cie, *m; 860 - struct dwarf_fde *fde, *n; 861 - unsigned long flags; 790 + struct dwarf_cie *cie; 791 + struct dwarf_fde *fde; 862 792 863 793 /* 864 794 * Deallocate all the memory allocated for the DWARF unwinder. 865 795 * Traverse all the FDE/CIE lists and remove and free all the 866 796 * memory associated with those data structures. 867 797 */ 868 - spin_lock_irqsave(&dwarf_cie_lock, flags); 869 - list_for_each_entry_safe(cie, m, &dwarf_cie_list, link) 798 + list_for_each_entry(cie, &dwarf_cie_list, link) 870 799 kfree(cie); 871 - spin_unlock_irqrestore(&dwarf_cie_lock, flags); 872 800 873 - spin_lock_irqsave(&dwarf_fde_lock, flags); 874 - list_for_each_entry_safe(fde, n, &dwarf_fde_list, link) 801 + list_for_each_entry(fde, &dwarf_fde_list, link) 875 802 kfree(fde); 876 - spin_unlock_irqrestore(&dwarf_fde_lock, flags); 803 + 804 + kmem_cache_destroy(dwarf_reg_cachep); 805 + kmem_cache_destroy(dwarf_frame_cachep); 877 806 } 878 807 879 808 /** ··· 883 816 * easy to lookup the FDE for a given PC, so we build a list of FDE 884 817 * and CIE entries that make it easier. 885 818 */ 886 - void dwarf_unwinder_init(void) 819 + static int __init dwarf_unwinder_init(void) 887 820 { 888 821 u32 entry_type; 889 822 void *p, *entry; ··· 897 830 c_entries = 0; 898 831 f_entries = 0; 899 832 entry = &__start_eh_frame; 833 + 834 + dwarf_frame_cachep = kmem_cache_create("dwarf_frames", 835 + sizeof(struct dwarf_frame), 0, SLAB_PANIC, NULL); 836 + dwarf_reg_cachep = kmem_cache_create("dwarf_regs", 837 + sizeof(struct dwarf_reg), 0, SLAB_PANIC, NULL); 838 + 839 + dwarf_frame_pool = mempool_create(DWARF_FRAME_MIN_REQ, 840 + mempool_alloc_slab, 841 + mempool_free_slab, 842 + dwarf_frame_cachep); 843 + 844 + dwarf_reg_pool = mempool_create(DWARF_REG_MIN_REQ, 845 + mempool_alloc_slab, 846 + mempool_free_slab, 847 + dwarf_reg_cachep); 900 848 901 849 while ((char *)entry < __stop_eh_frame) { 902 850 p = entry; ··· 942 860 else 943 861 c_entries++; 944 862 } else { 945 - err = dwarf_parse_fde(entry, entry_type, p, len); 863 + err = dwarf_parse_fde(entry, entry_type, p, len, end); 946 864 if (err < 0) 947 865 goto out; 948 866 else ··· 959 877 if (err) 960 878 goto out; 961 879 962 - return; 880 + return 0; 963 881 964 882 out: 965 883 printk(KERN_ERR "Failed to initialise DWARF unwinder: %d\n", err); 966 884 dwarf_unwinder_cleanup(); 885 + return -EINVAL; 967 886 } 887 + early_initcall(dwarf_unwinder_init);
-4
arch/sh/kernel/irq.c
··· 14 14 #include <asm/processor.h> 15 15 #include <asm/machvec.h> 16 16 #include <asm/uaccess.h> 17 - #include <asm/dwarf.h> 18 17 #include <asm/thread_info.h> 19 18 #include <cpu/mmu_context.h> 20 19 ··· 261 262 sh_mv.mv_init_irq(); 262 263 263 264 irq_ctx_init(smp_processor_id()); 264 - 265 - /* This needs to be early, but not too early.. */ 266 - dwarf_unwinder_init(); 267 265 } 268 266 269 267 #ifdef CONFIG_SPARSE_IRQ
+20 -4
arch/sh/kernel/traps.c
··· 5 5 #include <linux/signal.h> 6 6 #include <linux/sched.h> 7 7 #include <linux/uaccess.h> 8 + #include <asm/unwinder.h> 8 9 #include <asm/system.h> 9 10 10 11 #ifdef CONFIG_BUG 11 - static void handle_BUG(struct pt_regs *regs) 12 + void handle_BUG(struct pt_regs *regs) 12 13 { 14 + const struct bug_entry *bug; 15 + unsigned long bugaddr = regs->pc; 13 16 enum bug_trap_type tt; 14 - tt = report_bug(regs->pc, regs); 17 + 18 + if (!is_valid_bugaddr(bugaddr)) 19 + goto invalid; 20 + 21 + bug = find_bug(bugaddr); 22 + 23 + /* Switch unwinders when unwind_stack() is called */ 24 + if (bug->flags & BUGFLAG_UNWINDER) 25 + unwinder_faulted = 1; 26 + 27 + tt = report_bug(bugaddr, regs); 15 28 if (tt == BUG_TRAP_TYPE_WARN) { 16 - regs->pc += instruction_size(regs->pc); 29 + regs->pc += instruction_size(bugaddr); 17 30 return; 18 31 } 19 32 33 + invalid: 20 34 die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff); 21 35 } 22 36 ··· 42 28 return 0; 43 29 if (probe_kernel_address((insn_size_t *)addr, opcode)) 44 30 return 0; 31 + if (opcode == TRAPA_BUG_OPCODE) 32 + return 1; 45 33 46 - return opcode == TRAPA_BUG_OPCODE; 34 + return 0; 47 35 } 48 36 #endif 49 37
+1
arch/sh/kernel/traps_32.c
··· 136 136 regs->pc = fixup->fixup; 137 137 return; 138 138 } 139 + 139 140 die(str, regs, err); 140 141 } 141 142 }
+9 -7
arch/sh/kernel/unwinder.c
··· 11 11 #include <linux/errno.h> 12 12 #include <linux/list.h> 13 13 #include <linux/spinlock.h> 14 + #include <linux/module.h> 14 15 #include <asm/unwinder.h> 15 16 #include <asm/atomic.h> 16 17 ··· 53 52 }; 54 53 55 54 static DEFINE_SPINLOCK(unwinder_lock); 56 - 57 - static atomic_t unwinder_running = ATOMIC_INIT(0); 58 55 59 56 /** 60 57 * select_unwinder - Select the best registered stack unwinder. ··· 121 122 return ret; 122 123 } 123 124 125 + int unwinder_faulted = 0; 126 + 124 127 /* 125 128 * Unwind the call stack and pass information to the stacktrace_ops 126 129 * functions. Also handle the case where we need to switch to a new ··· 145 144 * Hopefully this will give us a semi-reliable stacktrace so we 146 145 * can diagnose why curr_unwinder->dump() faulted. 147 146 */ 148 - if (atomic_inc_return(&unwinder_running) != 1) { 147 + if (unwinder_faulted) { 149 148 spin_lock_irqsave(&unwinder_lock, flags); 150 149 151 - if (!list_is_singular(&unwinder_list)) { 150 + /* Make sure no one beat us to changing the unwinder */ 151 + if (unwinder_faulted && !list_is_singular(&unwinder_list)) { 152 152 list_del(&curr_unwinder->list); 153 153 curr_unwinder = select_unwinder(); 154 + 155 + unwinder_faulted = 0; 154 156 } 155 157 156 158 spin_unlock_irqrestore(&unwinder_lock, flags); 157 - atomic_dec(&unwinder_running); 158 159 } 159 160 160 161 curr_unwinder->dump(task, regs, sp, ops, data); 161 - 162 - atomic_dec(&unwinder_running); 163 162 } 163 + EXPORT_SYMBOL_GPL(unwind_stack);