traps.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/sections.h>
  12. struct pt_regs;
  13. struct undef_hook {
  14. struct list_head node;
  15. u32 instr_mask;
  16. u32 instr_val;
  17. u64 pstate_mask;
  18. u64 pstate_val;
  19. int (*fn)(struct pt_regs *regs, u32 instr);
  20. };
  21. void register_undef_hook(struct undef_hook *hook);
  22. void unregister_undef_hook(struct undef_hook *hook);
  23. void force_signal_inject(int signal, int code, unsigned long address, unsigned long err);
  24. void arm64_notify_segfault(unsigned long addr);
  25. void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str);
  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. /*
  29. * Move regs->pc to next instruction and do necessary setup before it
  30. * is executed.
  31. */
  32. void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
  33. static inline int __in_irqentry_text(unsigned long ptr)
  34. {
  35. return ptr >= (unsigned long)&__irqentry_text_start &&
  36. ptr < (unsigned long)&__irqentry_text_end;
  37. }
  38. static inline int in_entry_text(unsigned long ptr)
  39. {
  40. return ptr >= (unsigned long)&__entry_text_start &&
  41. ptr < (unsigned long)&__entry_text_end;
  42. }
  43. /*
  44. * CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
  45. * to indicate whether this ESR has a RAS encoding. CPUs without this feature
  46. * have a ISS-Valid bit in the same position.
  47. * If this bit is set, we know its not a RAS SError.
  48. * If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
  49. * errors share the same encoding as an all-zeros encoding from a CPU that
  50. * doesn't support RAS.
  51. */
  52. static inline bool arm64_is_ras_serror(unsigned long esr)
  53. {
  54. WARN_ON(preemptible());
  55. if (esr & ESR_ELx_IDS)
  56. return false;
  57. if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
  58. return true;
  59. else
  60. return false;
  61. }
  62. /*
  63. * Return the AET bits from a RAS SError's ESR.
  64. *
  65. * It is implementation defined whether Uncategorized errors are containable.
  66. * We treat them as Uncontainable.
  67. * Non-RAS SError's are reported as Uncontained/Uncategorized.
  68. */
  69. static inline unsigned long arm64_ras_serror_get_severity(unsigned long esr)
  70. {
  71. unsigned long aet = esr & ESR_ELx_AET;
  72. if (!arm64_is_ras_serror(esr)) {
  73. /* Not a RAS error, we can't interpret the ESR. */
  74. return ESR_ELx_AET_UC;
  75. }
  76. /*
  77. * AET is RES0 if 'the value returned in the DFSC field is not
  78. * [ESR_ELx_FSC_SERROR]'
  79. */
  80. if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
  81. /* No severity information : Uncategorized */
  82. return ESR_ELx_AET_UC;
  83. }
  84. return aet;
  85. }
  86. bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned long esr);
  87. void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr);
  88. #endif