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