dumpstack_32.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  5. */
  6. #include <linux/sched/debug.h>
  7. #include <linux/kallsyms.h>
  8. #include <linux/kprobes.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/hardirq.h>
  11. #include <linux/kdebug.h>
  12. #include <linux/export.h>
  13. #include <linux/ptrace.h>
  14. #include <linux/kexec.h>
  15. #include <linux/sysfs.h>
  16. #include <linux/bug.h>
  17. #include <linux/nmi.h>
  18. #include <asm/stacktrace.h>
  19. const char *stack_type_name(enum stack_type type)
  20. {
  21. if (type == STACK_TYPE_IRQ)
  22. return "IRQ";
  23. if (type == STACK_TYPE_SOFTIRQ)
  24. return "SOFTIRQ";
  25. if (type == STACK_TYPE_ENTRY)
  26. return "ENTRY_TRAMPOLINE";
  27. return NULL;
  28. }
  29. static bool in_hardirq_stack(unsigned long *stack, struct stack_info *info)
  30. {
  31. unsigned long *begin = (unsigned long *)this_cpu_read(hardirq_stack);
  32. unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
  33. /*
  34. * This is a software stack, so 'end' can be a valid stack pointer.
  35. * It just means the stack is empty.
  36. */
  37. if (stack <= begin || stack > end)
  38. return false;
  39. info->type = STACK_TYPE_IRQ;
  40. info->begin = begin;
  41. info->end = end;
  42. /*
  43. * See irq_32.c -- the next stack pointer is stored at the beginning of
  44. * the stack.
  45. */
  46. info->next_sp = (unsigned long *)*begin;
  47. return true;
  48. }
  49. static bool in_softirq_stack(unsigned long *stack, struct stack_info *info)
  50. {
  51. unsigned long *begin = (unsigned long *)this_cpu_read(softirq_stack);
  52. unsigned long *end = begin + (THREAD_SIZE / sizeof(long));
  53. /*
  54. * This is a software stack, so 'end' can be a valid stack pointer.
  55. * It just means the stack is empty.
  56. */
  57. if (stack <= begin || stack > end)
  58. return false;
  59. info->type = STACK_TYPE_SOFTIRQ;
  60. info->begin = begin;
  61. info->end = end;
  62. /*
  63. * The next stack pointer is stored at the beginning of the stack.
  64. * See irq_32.c.
  65. */
  66. info->next_sp = (unsigned long *)*begin;
  67. return true;
  68. }
  69. int get_stack_info(unsigned long *stack, struct task_struct *task,
  70. struct stack_info *info, unsigned long *visit_mask)
  71. {
  72. if (!stack)
  73. goto unknown;
  74. task = task ? : current;
  75. if (in_task_stack(stack, task, info))
  76. goto recursion_check;
  77. if (task != current)
  78. goto unknown;
  79. if (in_entry_stack(stack, info))
  80. goto recursion_check;
  81. if (in_hardirq_stack(stack, info))
  82. goto recursion_check;
  83. if (in_softirq_stack(stack, info))
  84. goto recursion_check;
  85. goto unknown;
  86. recursion_check:
  87. /*
  88. * Make sure we don't iterate through any given stack more than once.
  89. * If it comes up a second time then there's something wrong going on:
  90. * just break out and report an unknown stack type.
  91. */
  92. if (visit_mask) {
  93. if (*visit_mask & (1UL << info->type)) {
  94. printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
  95. goto unknown;
  96. }
  97. *visit_mask |= 1UL << info->type;
  98. }
  99. return 0;
  100. unknown:
  101. info->type = STACK_TYPE_UNKNOWN;
  102. return -EINVAL;
  103. }