dumpstack.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Stack dumping functions
  3. *
  4. * Copyright IBM Corp. 1999, 2013
  5. */
  6. #include <linux/kallsyms.h>
  7. #include <linux/hardirq.h>
  8. #include <linux/kprobes.h>
  9. #include <linux/utsname.h>
  10. #include <linux/export.h>
  11. #include <linux/kdebug.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/module.h>
  14. #include <linux/sched.h>
  15. #include <asm/processor.h>
  16. #include <asm/debug.h>
  17. #include <asm/dis.h>
  18. #include <asm/ipl.h>
  19. /*
  20. * For show_trace we have tree different stack to consider:
  21. * - the panic stack which is used if the kernel stack has overflown
  22. * - the asynchronous interrupt stack (cpu related)
  23. * - the synchronous kernel stack (process related)
  24. * The stack trace can start at any of the three stack and can potentially
  25. * touch all of them. The order is: panic stack, async stack, sync stack.
  26. */
  27. static unsigned long
  28. __show_trace(unsigned long sp, unsigned long low, unsigned long high)
  29. {
  30. struct stack_frame *sf;
  31. struct pt_regs *regs;
  32. unsigned long addr;
  33. while (1) {
  34. sp = sp & PSW_ADDR_INSN;
  35. if (sp < low || sp > high - sizeof(*sf))
  36. return sp;
  37. sf = (struct stack_frame *) sp;
  38. addr = sf->gprs[8] & PSW_ADDR_INSN;
  39. printk("([<%016lx>] %pSR)\n", addr, (void *)addr);
  40. /* Follow the backchain. */
  41. while (1) {
  42. low = sp;
  43. sp = sf->back_chain & PSW_ADDR_INSN;
  44. if (!sp)
  45. break;
  46. if (sp <= low || sp > high - sizeof(*sf))
  47. return sp;
  48. sf = (struct stack_frame *) sp;
  49. addr = sf->gprs[8] & PSW_ADDR_INSN;
  50. printk(" [<%016lx>] %pSR\n", addr, (void *)addr);
  51. }
  52. /* Zero backchain detected, check for interrupt frame. */
  53. sp = (unsigned long) (sf + 1);
  54. if (sp <= low || sp > high - sizeof(*regs))
  55. return sp;
  56. regs = (struct pt_regs *) sp;
  57. addr = regs->psw.addr & PSW_ADDR_INSN;
  58. printk(" [<%016lx>] %pSR\n", addr, (void *)addr);
  59. low = sp;
  60. sp = regs->gprs[15];
  61. }
  62. }
  63. static void show_trace(struct task_struct *task, unsigned long *stack)
  64. {
  65. const unsigned long frame_size =
  66. STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
  67. register unsigned long __r15 asm ("15");
  68. unsigned long sp;
  69. sp = (unsigned long) stack;
  70. if (!sp)
  71. sp = task ? task->thread.ksp : __r15;
  72. printk("Call Trace:\n");
  73. #ifdef CONFIG_CHECK_STACK
  74. sp = __show_trace(sp,
  75. S390_lowcore.panic_stack + frame_size - 4096,
  76. S390_lowcore.panic_stack + frame_size);
  77. #endif
  78. sp = __show_trace(sp,
  79. S390_lowcore.async_stack + frame_size - ASYNC_SIZE,
  80. S390_lowcore.async_stack + frame_size);
  81. if (task)
  82. __show_trace(sp, (unsigned long) task_stack_page(task),
  83. (unsigned long) task_stack_page(task) + THREAD_SIZE);
  84. else
  85. __show_trace(sp, S390_lowcore.thread_info,
  86. S390_lowcore.thread_info + THREAD_SIZE);
  87. if (!task)
  88. task = current;
  89. debug_show_held_locks(task);
  90. }
  91. void show_stack(struct task_struct *task, unsigned long *sp)
  92. {
  93. register unsigned long *__r15 asm ("15");
  94. unsigned long *stack;
  95. int i;
  96. if (!sp)
  97. stack = task ? (unsigned long *) task->thread.ksp : __r15;
  98. else
  99. stack = sp;
  100. for (i = 0; i < 20; i++) {
  101. if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
  102. break;
  103. if ((i * sizeof(long) % 32) == 0)
  104. printk("%s ", i == 0 ? "" : "\n");
  105. printk("%016lx ", *stack++);
  106. }
  107. printk("\n");
  108. show_trace(task, sp);
  109. }
  110. static void show_last_breaking_event(struct pt_regs *regs)
  111. {
  112. printk("Last Breaking-Event-Address:\n");
  113. printk(" [<%016lx>] %pSR\n", regs->args[0], (void *)regs->args[0]);
  114. }
  115. static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
  116. {
  117. return (regs->psw.mask & bits) / ((~bits + 1) & bits);
  118. }
  119. void show_registers(struct pt_regs *regs)
  120. {
  121. char *mode;
  122. mode = user_mode(regs) ? "User" : "Krnl";
  123. printk("%s PSW : %p %p", mode, (void *)regs->psw.mask, (void *)regs->psw.addr);
  124. if (!user_mode(regs))
  125. printk(" (%pSR)", (void *)regs->psw.addr);
  126. printk("\n");
  127. printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
  128. "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
  129. mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
  130. mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
  131. mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
  132. mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
  133. mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
  134. printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA));
  135. printk("\n%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
  136. regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
  137. printk(" %016lx %016lx %016lx %016lx\n",
  138. regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
  139. printk(" %016lx %016lx %016lx %016lx\n",
  140. regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
  141. printk(" %016lx %016lx %016lx %016lx\n",
  142. regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
  143. show_code(regs);
  144. }
  145. void show_regs(struct pt_regs *regs)
  146. {
  147. show_regs_print_info(KERN_DEFAULT);
  148. show_registers(regs);
  149. /* Show stack backtrace if pt_regs is from kernel mode */
  150. if (!user_mode(regs))
  151. show_trace(NULL, (unsigned long *) regs->gprs[15]);
  152. show_last_breaking_event(regs);
  153. }
  154. static DEFINE_SPINLOCK(die_lock);
  155. void die(struct pt_regs *regs, const char *str)
  156. {
  157. static int die_counter;
  158. oops_enter();
  159. lgr_info_log();
  160. debug_stop_all();
  161. console_verbose();
  162. spin_lock_irq(&die_lock);
  163. bust_spinlocks(1);
  164. printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff,
  165. regs->int_code >> 17, ++die_counter);
  166. #ifdef CONFIG_PREEMPT
  167. printk("PREEMPT ");
  168. #endif
  169. #ifdef CONFIG_SMP
  170. printk("SMP ");
  171. #endif
  172. #ifdef CONFIG_DEBUG_PAGEALLOC
  173. printk("DEBUG_PAGEALLOC");
  174. #endif
  175. printk("\n");
  176. notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
  177. print_modules();
  178. show_regs(regs);
  179. bust_spinlocks(0);
  180. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  181. spin_unlock_irq(&die_lock);
  182. if (in_interrupt())
  183. panic("Fatal exception in interrupt");
  184. if (panic_on_oops)
  185. panic("Fatal exception: panic_on_oops");
  186. oops_exit();
  187. do_exit(SIGSEGV);
  188. }