dumpstack.c 6.0 KB

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