dumpstack_32.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 1991, 1992 Linus Torvalds
  3. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  4. */
  5. #include <linux/sched/debug.h>
  6. #include <linux/kallsyms.h>
  7. #include <linux/kprobes.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/hardirq.h>
  10. #include <linux/kdebug.h>
  11. #include <linux/export.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/kexec.h>
  14. #include <linux/sysfs.h>
  15. #include <linux/bug.h>
  16. #include <linux/nmi.h>
  17. #include <asm/stacktrace.h>
  18. const char *stack_type_name(enum stack_type type)
  19. {
  20. if (type == STACK_TYPE_IRQ)
  21. return "IRQ";
  22. if (type == STACK_TYPE_SOFTIRQ)
  23. return "SOFTIRQ";
  24. return NULL;
  25. }
  26. static bool in_hardirq_stack(unsigned long *stack, struct stack_info *info)
  27. {
  28. unsigned long *begin = (unsigned long *)this_cpu_read(hardirq_stack);
  29. unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
  30. /*
  31. * This is a software stack, so 'end' can be a valid stack pointer.
  32. * It just means the stack is empty.
  33. */
  34. if (stack < begin || stack > end)
  35. return false;
  36. info->type = STACK_TYPE_IRQ;
  37. info->begin = begin;
  38. info->end = end;
  39. /*
  40. * See irq_32.c -- the next stack pointer is stored at the beginning of
  41. * the stack.
  42. */
  43. info->next_sp = (unsigned long *)*begin;
  44. return true;
  45. }
  46. static bool in_softirq_stack(unsigned long *stack, struct stack_info *info)
  47. {
  48. unsigned long *begin = (unsigned long *)this_cpu_read(softirq_stack);
  49. unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
  50. /*
  51. * This is a software stack, so 'end' can be a valid stack pointer.
  52. * It just means the stack is empty.
  53. */
  54. if (stack < begin || stack > end)
  55. return false;
  56. info->type = STACK_TYPE_SOFTIRQ;
  57. info->begin = begin;
  58. info->end = end;
  59. /*
  60. * The next stack pointer is stored at the beginning of the stack.
  61. * See irq_32.c.
  62. */
  63. info->next_sp = (unsigned long *)*begin;
  64. return true;
  65. }
  66. int get_stack_info(unsigned long *stack, struct task_struct *task,
  67. struct stack_info *info, unsigned long *visit_mask)
  68. {
  69. if (!stack)
  70. goto unknown;
  71. task = task ? : current;
  72. if (in_task_stack(stack, task, info))
  73. goto recursion_check;
  74. if (task != current)
  75. goto unknown;
  76. if (in_hardirq_stack(stack, info))
  77. goto recursion_check;
  78. if (in_softirq_stack(stack, info))
  79. goto recursion_check;
  80. goto unknown;
  81. recursion_check:
  82. /*
  83. * Make sure we don't iterate through any given stack more than once.
  84. * If it comes up a second time then there's something wrong going on:
  85. * just break out and report an unknown stack type.
  86. */
  87. if (visit_mask) {
  88. if (*visit_mask & (1UL << info->type)) {
  89. printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
  90. goto unknown;
  91. }
  92. *visit_mask |= 1UL << info->type;
  93. }
  94. return 0;
  95. unknown:
  96. info->type = STACK_TYPE_UNKNOWN;
  97. return -EINVAL;
  98. }
  99. void show_regs(struct pt_regs *regs)
  100. {
  101. int i;
  102. show_regs_print_info(KERN_EMERG);
  103. __show_regs(regs, !user_mode(regs));
  104. /*
  105. * When in-kernel, we also print out the stack and code at the
  106. * time of the fault..
  107. */
  108. if (!user_mode(regs)) {
  109. unsigned int code_prologue = code_bytes * 43 / 64;
  110. unsigned int code_len = code_bytes;
  111. unsigned char c;
  112. u8 *ip;
  113. show_trace_log_lvl(current, regs, NULL, KERN_EMERG);
  114. pr_emerg("Code:");
  115. ip = (u8 *)regs->ip - code_prologue;
  116. if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
  117. /* try starting at IP */
  118. ip = (u8 *)regs->ip;
  119. code_len = code_len - code_prologue + 1;
  120. }
  121. for (i = 0; i < code_len; i++, ip++) {
  122. if (ip < (u8 *)PAGE_OFFSET ||
  123. probe_kernel_address(ip, c)) {
  124. pr_cont(" Bad EIP value.");
  125. break;
  126. }
  127. if (ip == (u8 *)regs->ip)
  128. pr_cont(" <%02x>", c);
  129. else
  130. pr_cont(" %02x", c);
  131. }
  132. }
  133. pr_cont("\n");
  134. }