dumpstack.c 5.7 KB

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