stacktrace.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 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. #if defined(CONFIG_ARM_SDE_INTERFACE)
  60. DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
  61. DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
  62. static inline struct stack_info stackinfo_get_sdei_normal(void)
  63. {
  64. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
  65. unsigned long high = low + SDEI_STACK_SIZE;
  66. return (struct stack_info) {
  67. .low = low,
  68. .high = high,
  69. };
  70. }
  71. static inline struct stack_info stackinfo_get_sdei_critical(void)
  72. {
  73. unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
  74. unsigned long high = low + SDEI_STACK_SIZE;
  75. return (struct stack_info) {
  76. .low = low,
  77. .high = high,
  78. };
  79. }
  80. #else
  81. #define stackinfo_get_sdei_normal() stackinfo_get_unknown()
  82. #define stackinfo_get_sdei_critical() stackinfo_get_unknown()
  83. #endif
  84. #ifdef CONFIG_EFI
  85. extern u64 *efi_rt_stack_top;
  86. static inline struct stack_info stackinfo_get_efi(void)
  87. {
  88. unsigned long high = (u64)efi_rt_stack_top;
  89. unsigned long low = high - THREAD_SIZE;
  90. return (struct stack_info) {
  91. .low = low,
  92. .high = high,
  93. };
  94. }
  95. #endif
  96. #endif /* __ASM_STACKTRACE_H */