18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_ASM_POINTER_AUTH_H 38c2ecf20Sopenharmony_ci#define __ASM_ASM_POINTER_AUTH_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/alternative.h> 68c2ecf20Sopenharmony_ci#include <asm/asm-offsets.h> 78c2ecf20Sopenharmony_ci#include <asm/cpufeature.h> 88c2ecf20Sopenharmony_ci#include <asm/sysreg.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_PTR_AUTH 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * thread.keys_user.ap* as offset exceeds the #imm offset range 138c2ecf20Sopenharmony_ci * so use the base value of ldp as thread.keys_user and offset as 148c2ecf20Sopenharmony_ci * thread.keys_user.ap*. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3 178c2ecf20Sopenharmony_ci mov \tmp1, #THREAD_KEYS_USER 188c2ecf20Sopenharmony_ci add \tmp1, \tsk, \tmp1 198c2ecf20Sopenharmony_cialternative_if_not ARM64_HAS_ADDRESS_AUTH 208c2ecf20Sopenharmony_ci b .Laddr_auth_skip_\@ 218c2ecf20Sopenharmony_cialternative_else_nop_endif 228c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APIA] 238c2ecf20Sopenharmony_ci msr_s SYS_APIAKEYLO_EL1, \tmp2 248c2ecf20Sopenharmony_ci msr_s SYS_APIAKEYHI_EL1, \tmp3 258c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APIB] 268c2ecf20Sopenharmony_ci msr_s SYS_APIBKEYLO_EL1, \tmp2 278c2ecf20Sopenharmony_ci msr_s SYS_APIBKEYHI_EL1, \tmp3 288c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APDA] 298c2ecf20Sopenharmony_ci msr_s SYS_APDAKEYLO_EL1, \tmp2 308c2ecf20Sopenharmony_ci msr_s SYS_APDAKEYHI_EL1, \tmp3 318c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APDB] 328c2ecf20Sopenharmony_ci msr_s SYS_APDBKEYLO_EL1, \tmp2 338c2ecf20Sopenharmony_ci msr_s SYS_APDBKEYHI_EL1, \tmp3 348c2ecf20Sopenharmony_ci.Laddr_auth_skip_\@: 358c2ecf20Sopenharmony_cialternative_if ARM64_HAS_GENERIC_AUTH 368c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_USER_KEY_APGA] 378c2ecf20Sopenharmony_ci msr_s SYS_APGAKEYLO_EL1, \tmp2 388c2ecf20Sopenharmony_ci msr_s SYS_APGAKEYHI_EL1, \tmp3 398c2ecf20Sopenharmony_cialternative_else_nop_endif 408c2ecf20Sopenharmony_ci .endm 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci .macro __ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3 438c2ecf20Sopenharmony_ci mov \tmp1, #THREAD_KEYS_KERNEL 448c2ecf20Sopenharmony_ci add \tmp1, \tsk, \tmp1 458c2ecf20Sopenharmony_ci ldp \tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APIA] 468c2ecf20Sopenharmony_ci msr_s SYS_APIAKEYLO_EL1, \tmp2 478c2ecf20Sopenharmony_ci msr_s SYS_APIAKEYHI_EL1, \tmp3 488c2ecf20Sopenharmony_ci .endm 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3 518c2ecf20Sopenharmony_cialternative_if ARM64_HAS_ADDRESS_AUTH 528c2ecf20Sopenharmony_ci __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3 538c2ecf20Sopenharmony_cialternative_else_nop_endif 548c2ecf20Sopenharmony_ci .endm 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3 578c2ecf20Sopenharmony_cialternative_if ARM64_HAS_ADDRESS_AUTH 588c2ecf20Sopenharmony_ci __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3 598c2ecf20Sopenharmony_ci isb 608c2ecf20Sopenharmony_cialternative_else_nop_endif 618c2ecf20Sopenharmony_ci .endm 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci .macro __ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3 648c2ecf20Sopenharmony_ci mrs \tmp1, id_aa64isar1_el1 658c2ecf20Sopenharmony_ci ubfx \tmp1, \tmp1, #ID_AA64ISAR1_APA_SHIFT, #8 668c2ecf20Sopenharmony_ci cbz \tmp1, .Lno_addr_auth\@ 678c2ecf20Sopenharmony_ci mov_q \tmp1, (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \ 688c2ecf20Sopenharmony_ci SCTLR_ELx_ENDA | SCTLR_ELx_ENDB) 698c2ecf20Sopenharmony_ci mrs \tmp2, sctlr_el1 708c2ecf20Sopenharmony_ci orr \tmp2, \tmp2, \tmp1 718c2ecf20Sopenharmony_ci msr sctlr_el1, \tmp2 728c2ecf20Sopenharmony_ci __ptrauth_keys_install_kernel_nosync \tsk, \tmp1, \tmp2, \tmp3 738c2ecf20Sopenharmony_ci isb 748c2ecf20Sopenharmony_ci.Lno_addr_auth\@: 758c2ecf20Sopenharmony_ci .endm 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci .macro ptrauth_keys_init_cpu tsk, tmp1, tmp2, tmp3 788c2ecf20Sopenharmony_cialternative_if_not ARM64_HAS_ADDRESS_AUTH 798c2ecf20Sopenharmony_ci b .Lno_addr_auth\@ 808c2ecf20Sopenharmony_cialternative_else_nop_endif 818c2ecf20Sopenharmony_ci __ptrauth_keys_init_cpu \tsk, \tmp1, \tmp2, \tmp3 828c2ecf20Sopenharmony_ci.Lno_addr_auth\@: 838c2ecf20Sopenharmony_ci .endm 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#else /* CONFIG_ARM64_PTR_AUTH */ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_user tsk, tmp1, tmp2, tmp3 888c2ecf20Sopenharmony_ci .endm 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_kernel_nosync tsk, tmp1, tmp2, tmp3 918c2ecf20Sopenharmony_ci .endm 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci .macro ptrauth_keys_install_kernel tsk, tmp1, tmp2, tmp3 948c2ecf20Sopenharmony_ci .endm 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#endif /* CONFIG_ARM64_PTR_AUTH */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#endif /* __ASM_ASM_POINTER_AUTH_H */ 99