stacktrace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_STACKTRACE_H
  6. #define __ASM_STACKTRACE_H
  7. #include <linux/percpu.h>
  8. #include <linux/sched.h>
  9. #include <linux/sched/task_stack.h>
  10. #include <linux/llist.h>
  11. #include <asm/memory.h>
  12. #include <asm/pointer_auth.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/sdei.h>
  15. #include <asm/stacktrace/common.h>
  16. extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
  17. const char *loglvl);
  18. DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
  19. static inline struct stack_info stackinfo_get_irq(void)
  20. {
  21. unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
  22. unsigned long high = low + IRQ_STACK_SIZE;
  23. return (struct stack_info) {
  24. .low = low,
  25. .high = high,
  26. };
  27. }
  28. static inline bool on_irq_stack(unsigned long sp, unsigned long size)
  29. {
  30. struct stack_info info = stackinfo_get_irq();
  31. return stackinfo_on_stack(&info, sp, size);
  32. }
  33. static inline struct stack_info stackinfo_get_task(const struct task_struct *tsk)
  34. {
  35. unsigned long low = (unsigned long)task_stack_page(tsk);
  36. unsigned long high = low + THREAD_SIZE;
  37. return (struct stack_info) {
  38. .low = low,
  39. .high = high,
  40. };
  41. }
  42. static inline bool on_task_stack(const struct task_struct *tsk,
  43. unsigned long sp, unsigned long size)
  44. {
  45. struct stack_info info = stackinfo_get_task(tsk);
  46. return stackinfo_on_stack(&info, sp, size);
  47. }
  48. #define on_thread_stack() (on_task_stack(current, current_stack_pointer, 1))
  49. #ifdef CONFIG_VMAP_STACK
  50. DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack);
  51. static inline struct stack_info stackinfo_get_overflow(void)
  52. {
  53. unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
  54. unsigned long high = low + OVERFLOW_STACK_SIZE;
  55. return (struct stack_info) {
  56. .low = low,
  57. .high = high,
  58. };
  59. }
  60. #else
  61. #define stackinfo_get_overflow() stackinfo_get_unknown()
  62. #endif
  63. #if defined(CONFIG_ARM_SDE_INTERFACE) && defined(CONFIG_VMAP_STACK)
  64. DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
  65. DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
  66. static inline struct stack_info stackinfo_get_sdei_normal(void)
  67. {
  68. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
  69. unsigned long high = low + SDEI_STACK_SIZE;
  70. return (struct stack_info) {
  71. .low = low,
  72. .high = high,
  73. };
  74. }
  75. static inline struct stack_info stackinfo_get_sdei_critical(void)
  76. {
  77. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
  78. unsigned long high = low + SDEI_STACK_SIZE;
  79. return (struct stack_info) {
  80. .low = low,
  81. .high = high,
  82. };
  83. }
  84. #else
  85. #define stackinfo_get_sdei_normal() stackinfo_get_unknown()
  86. #define stackinfo_get_sdei_critical() stackinfo_get_unknown()
  87. #endif
  88. #ifdef CONFIG_EFI
  89. extern u64 *efi_rt_stack_top;
  90. static inline struct stack_info stackinfo_get_efi(void)
  91. {
  92. unsigned long high = (u64)efi_rt_stack_top;
  93. unsigned long low = high - THREAD_SIZE;
  94. return (struct stack_info) {
  95. .low = low,
  96. .high = high,
  97. };
  98. }
  99. #endif
  100. #endif /* __ASM_STACKTRACE_H */