stacktrace.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifdef CONFIG_VMAP_STACK
  49. DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack);
  50. static inline struct stack_info stackinfo_get_overflow(void)
  51. {
  52. unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
  53. unsigned long high = low + OVERFLOW_STACK_SIZE;
  54. return (struct stack_info) {
  55. .low = low,
  56. .high = high,
  57. };
  58. }
  59. #else
  60. #define stackinfo_get_overflow() stackinfo_get_unknown()
  61. #endif
  62. #if defined(CONFIG_ARM_SDE_INTERFACE) && defined(CONFIG_VMAP_STACK)
  63. DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
  64. DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
  65. static inline struct stack_info stackinfo_get_sdei_normal(void)
  66. {
  67. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
  68. unsigned long high = low + SDEI_STACK_SIZE;
  69. return (struct stack_info) {
  70. .low = low,
  71. .high = high,
  72. };
  73. }
  74. static inline struct stack_info stackinfo_get_sdei_critical(void)
  75. {
  76. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
  77. unsigned long high = low + SDEI_STACK_SIZE;
  78. return (struct stack_info) {
  79. .low = low,
  80. .high = high,
  81. };
  82. }
  83. #else
  84. #define stackinfo_get_sdei_normal() stackinfo_get_unknown()
  85. #define stackinfo_get_sdei_critical() stackinfo_get_unknown()
  86. #endif
  87. #ifdef CONFIG_EFI
  88. extern u64 *efi_rt_stack_top;
  89. static inline struct stack_info stackinfo_get_efi(void)
  90. {
  91. unsigned long high = (u64)efi_rt_stack_top;
  92. unsigned long low = high - THREAD_SIZE;
  93. return (struct stack_info) {
  94. .low = low,
  95. .high = high,
  96. };
  97. }
  98. #endif
  99. #endif /* __ASM_STACKTRACE_H */