0001
0002 #ifndef __ASM_ASM_POINTER_AUTH_H
0003 #define __ASM_ASM_POINTER_AUTH_H
0004
0005 #include <asm/alternative.h>
0006 #include <asm/asm-offsets.h>
0007 #include <asm/cpufeature.h>
0008 #include <asm/sysreg.h>
0009
0010 #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
0011
0012 .macro __ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
0013 mov \tmp1, #THREAD_KEYS_KERNEL
0014 add \tmp1, \tsk, \tmp1
0015 ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APIA]
0016 msr_s SYS_APIAKEYLO_EL1, \tmp2
0017 msr_s SYS_APIAKEYHI_EL1, \tmp3
0018 .endm
0019
0020 .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
0021 alternative_if ARM64_HAS_ADDRESS_AUTH
0022 __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
0023 alternative_else_nop_endif
0024 .endm
0025
0026 .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3
0027 alternative_if ARM64_HAS_ADDRESS_AUTH
0028 __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
0029 isb
0030 alternative_else_nop_endif
0031 .endm
0032
0033 #else
0034
0035 .macro __ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
0036 .endm
0037
0038 .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3
0039 .endm
0040
0041 .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3
0042 .endm
0043
0044 #endif
0045
0046 #ifdef CONFIG_ARM64_PTR_AUTH
0047
0048
0049
0050
0051
0052 .macro __ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3
0053 mov \tmp1, #THREAD_KEYS_USER
0054 add \tmp1, \tsk, \tmp1
0055 ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APIA]
0056 msr_s SYS_APIAKEYLO_EL1, \tmp2
0057 msr_s SYS_APIAKEYHI_EL1, \tmp3
0058 .endm
0059
0060 .macro __ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3
0061 mrs \tmp1, id_aa64isar1_el1
0062 ubfx \tmp1, \tmp1, #ID_AA64ISAR1_EL1_APA_SHIFT, #8
0063 mrs_s \tmp2, SYS_ID_AA64ISAR2_EL1
0064 ubfx \tmp2, \tmp2, #ID_AA64ISAR2_EL1_APA3_SHIFT, #4
0065 orr \tmp1, \tmp1, \tmp2
0066 cbz \tmp1, .Lno_addr_auth\@
0067 mov_q \tmp1, (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \
0068 SCTLR_ELx_ENDA | SCTLR_ELx_ENDB)
0069 mrs \tmp2, sctlr_el1
0070 orr \tmp2, \tmp2, \tmp1
0071 msr sctlr_el1, \tmp2
0072 __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3
0073 isb
0074 .Lno_addr_auth\@:
0075 .endm
0076
0077 .macro ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3
0078 alternative_if_not ARM64_HAS_ADDRESS_AUTH
0079 b .Lno_addr_auth\@
0080 alternative_else_nop_endif
0081 __ptrauth_keys_init_cpu \tsk, \tmp1, \tmp2, \tmp3
0082 .Lno_addr_auth\@:
0083 .endm
0084
0085 #else
0086
0087 .macro ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3
0088 .endm
0089
0090 #endif
0091
0092 #endif