traps.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Based on arch/arm/include/asm/traps.h
  4. *
  5. * Copyright (C) 2012 ARM Ltd.
  6. */
  7. #ifndef __ASM_TRAP_H
  8. #define __ASM_TRAP_H
  9. #include <linux/list.h>
  10. #include <asm/esr.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/sections.h>
  13. #ifdef CONFIG_ARMV8_DEPRECATED
  14. bool try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn);
  15. #else
  16. static inline bool
  17. try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn)
  18. {
  19. return false;
  20. }
  21. #endif /* CONFIG_ARMV8_DEPRECATED */
  22. void force_signal_inject(int signal, int code, unsigned long address, unsigned long err);
  23. void arm64_notify_segfault(unsigned long addr);
  24. void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str);
  25. void arm64_force_sig_fault_pkey(unsigned long far, const char *str, int pkey);
  26. void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str);
  27. void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str);
  28. int bug_brk_handler(struct pt_regs *regs, unsigned long esr);
  29. int cfi_brk_handler(struct pt_regs *regs, unsigned long esr);
  30. int reserved_fault_brk_handler(struct pt_regs *regs, unsigned long esr);
  31. int kasan_brk_handler(struct pt_regs *regs, unsigned long esr);
  32. int ubsan_brk_handler(struct pt_regs *regs, unsigned long esr);
  33. int early_brk64(unsigned long addr, unsigned long esr, struct pt_regs *regs);
  34. void dump_kernel_instr(unsigned long kaddr);
  35. /*
  36. * Move regs->pc to next instruction and do necessary setup before it
  37. * is executed.
  38. */
  39. void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
  40. static inline int __in_irqentry_text(unsigned long ptr)
  41. {
  42. return ptr >= (unsigned long)&__irqentry_text_start &&
  43. ptr < (unsigned long)&__irqentry_text_end;
  44. }
  45. static inline int in_entry_text(unsigned long ptr)
  46. {
  47. return ptr >= (unsigned long)&__entry_text_start &&
  48. ptr < (unsigned long)&__entry_text_end;
  49. }
  50. /*
  51. * CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
  52. * to indicate whether this ESR has a RAS encoding. CPUs without this feature
  53. * have a ISS-Valid bit in the same position.
  54. * If this bit is set, we know its not a RAS SError.
  55. * If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
  56. * errors share the same encoding as an all-zeros encoding from a CPU that
  57. * doesn't support RAS.
  58. */
  59. static inline bool arm64_is_ras_serror(unsigned long esr)
  60. {
  61. WARN_ON(preemptible());
  62. if (esr & ESR_ELx_IDS)
  63. return false;
  64. if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
  65. return true;
  66. else
  67. return false;
  68. }
  69. /*
  70. * Return the AET bits from a RAS SError's ESR.
  71. *
  72. * It is implementation defined whether Uncategorized errors are containable.
  73. * We treat them as Uncontainable.
  74. * Non-RAS SError's are reported as Uncontained/Uncategorized.
  75. */
  76. static inline unsigned long arm64_ras_serror_get_severity(unsigned long esr)
  77. {
  78. unsigned long aet = esr & ESR_ELx_AET;
  79. if (!arm64_is_ras_serror(esr)) {
  80. /* Not a RAS error, we can't interpret the ESR. */
  81. return ESR_ELx_AET_UC;
  82. }
  83. /*
  84. * AET is RES0 if 'the value returned in the DFSC field is not
  85. * [ESR_ELx_FSC_SERROR]'
  86. */
  87. if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
  88. /* No severity information : Uncategorized */
  89. return ESR_ELx_AET_UC;
  90. }
  91. return aet;
  92. }
  93. bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned long esr);
  94. void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr);
  95. static inline void arm64_mops_reset_regs(struct user_pt_regs *regs, unsigned long esr)
  96. {
  97. bool wrong_option = esr & ESR_ELx_MOPS_ISS_WRONG_OPTION;
  98. bool option_a = esr & ESR_ELx_MOPS_ISS_OPTION_A;
  99. int dstreg = ESR_ELx_MOPS_ISS_DESTREG(esr);
  100. int srcreg = ESR_ELx_MOPS_ISS_SRCREG(esr);
  101. int sizereg = ESR_ELx_MOPS_ISS_SIZEREG(esr);
  102. unsigned long dst, size;
  103. dst = regs->regs[dstreg];
  104. size = regs->regs[sizereg];
  105. /*
  106. * Put the registers back in the original format suitable for a
  107. * prologue instruction, using the generic return routine from the
  108. * Arm ARM (DDI 0487I.a) rules CNTMJ and MWFQH.
  109. */
  110. if (esr & ESR_ELx_MOPS_ISS_MEM_INST) {
  111. /* SET* instruction */
  112. if (option_a ^ wrong_option) {
  113. /* Format is from Option A; forward set */
  114. regs->regs[dstreg] = dst + size;
  115. regs->regs[sizereg] = -size;
  116. }
  117. } else {
  118. /* CPY* instruction */
  119. unsigned long src = regs->regs[srcreg];
  120. if (!(option_a ^ wrong_option)) {
  121. /* Format is from Option B */
  122. if (regs->pstate & PSR_N_BIT) {
  123. /* Backward copy */
  124. regs->regs[dstreg] = dst - size;
  125. regs->regs[srcreg] = src - size;
  126. }
  127. } else {
  128. /* Format is from Option A */
  129. if (size & BIT(63)) {
  130. /* Forward copy */
  131. regs->regs[dstreg] = dst + size;
  132. regs->regs[srcreg] = src + size;
  133. regs->regs[sizereg] = -size;
  134. }
  135. }
  136. }
  137. if (esr & ESR_ELx_MOPS_ISS_FROM_EPILOGUE)
  138. regs->pc -= 8;
  139. else
  140. regs->pc -= 4;
  141. }
  142. #endif