asm_pointer_auth.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_ASM_POINTER_AUTH_H
  3. #define __ASM_ASM_POINTER_AUTH_H
  4. #include <asm/alternative.h>
  5. #include <asm/asm-offsets.h>
  6. #include <asm/cpufeature.h>
  7. #include <asm/sysreg.h>
  8. #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
  9. .macro __ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
  10. mov \tmp1, #THREAD_KEYS_KERNEL
  11. add \tmp1, \tsk, \tmp1
  12. ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APIA]
  13. msr_s SYS_APIAKEYLO_EL1, \tmp2
  14. msr_s SYS_APIAKEYHI_EL1, \tmp3
  15. .endm
  16. .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
  17. alternative_if ARM64_HAS_ADDRESS_AUTH
  18. __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
  19. alternative_else_nop_endif
  20. .endm
  21. .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3
  22. alternative_if ARM64_HAS_ADDRESS_AUTH
  23. __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
  24. isb
  25. alternative_else_nop_endif
  26. .endm
  27. #else /* CONFIG_ARM64_PTR_AUTH_KERNEL */
  28. .macro __ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
  29. .endm
  30. .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
  31. .endm
  32. .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3
  33. .endm
  34. #endif /* CONFIG_ARM64_PTR_AUTH_KERNEL */
  35. #ifdef CONFIG_ARM64_PTR_AUTH
  36. /*
  37. * thread.keys_user.ap* as offset exceeds the #imm offset range
  38. * so use the base value of ldp as thread.keys_user and offset as
  39. * thread.keys_user.ap*.
  40. */
  41. .macro __ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3
  42. mov \tmp1, #THREAD_KEYS_USER
  43. add \tmp1, \tsk, \tmp1
  44. ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APIA]
  45. msr_s SYS_APIAKEYLO_EL1, \tmp2
  46. msr_s SYS_APIAKEYHI_EL1, \tmp3
  47. .endm
  48. .macro __ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3
  49. mrs \tmp1, id_aa64isar1_el1
  50. ubfx \tmp1, \tmp1, #ID_AA64ISAR1_EL1_APA_SHIFT, #8
  51. mrs_s \tmp2, SYS_ID_AA64ISAR2_EL1
  52. ubfx \tmp2, \tmp2, #ID_AA64ISAR2_EL1_APA3_SHIFT, #4
  53. orr \tmp1, \tmp1, \tmp2
  54. cbz \tmp1, .Lno_addr_auth\@
  55. mov_q \tmp1, (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \
  56. SCTLR_ELx_ENDA | SCTLR_ELx_ENDB)
  57. mrs \tmp2, sctlr_el1
  58. orr \tmp2, \tmp2, \tmp1
  59. msr sctlr_el1, \tmp2
  60. __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
  61. isb
  62. .Lno_addr_auth\@:
  63. .endm
  64. .macro ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3
  65. alternative_if_not ARM64_HAS_ADDRESS_AUTH
  66. b .Lno_addr_auth\@
  67. alternative_else_nop_endif
  68. __ptrauth_keys_init_cpu \tsk, \tmp1, \tmp2, \tmp3
  69. .Lno_addr_auth\@:
  70. .endm
  71. #else /* !CONFIG_ARM64_PTR_AUTH */
  72. .macro ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3
  73. .endm
  74. #endif /* CONFIG_ARM64_PTR_AUTH */
  75. #endif /* __ASM_ASM_POINTER_AUTH_H */