1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ASM_POINTER_AUTH_H
3 #define __ASM_ASM_POINTER_AUTH_H
5 #include <asm/alternative.h>
6 #include <asm/asm-offsets.h>
7 #include <asm/cpufeature.h>
8 #include <asm/sysreg.h>
10 #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
12 .macro __ptrauth_keys_install_kernel_nosync tsk
, tmp1
, tmp2
, tmp3
13 mov
\tmp
1, #THREAD_KEYS_KERNEL
14 add
\tmp
1, \tsk
, \tmp
1
15 ldp
\tmp
2, \tmp
3, [\tmp
1, #PTRAUTH_KERNEL_KEY_APIA]
16 msr_s SYS_APIAKEYLO_EL1
, \tmp
2
17 msr_s SYS_APIAKEYHI_EL1
, \tmp
3
20 .macro ptrauth_keys_install_kernel_nosync tsk
, tmp1
, tmp2
, tmp3
21 alternative_if ARM64_HAS_ADDRESS_AUTH
22 __ptrauth_keys_install_kernel_nosync
\tsk
, \tmp
1, \tmp
2, \tmp
3
23 alternative_else_nop_endif
26 .macro ptrauth_keys_install_kernel tsk
, tmp1
, tmp2
, tmp3
27 alternative_if ARM64_HAS_ADDRESS_AUTH
28 __ptrauth_keys_install_kernel_nosync
\tsk
, \tmp
1, \tmp
2, \tmp
3
30 alternative_else_nop_endif
33 #else /* CONFIG_ARM64_PTR_AUTH_KERNEL */
35 .macro __ptrauth_keys_install_kernel_nosync tsk
, tmp1
, tmp2
, tmp3
38 .macro ptrauth_keys_install_kernel_nosync tsk
, tmp1
, tmp2
, tmp3
41 .macro ptrauth_keys_install_kernel tsk
, tmp1
, tmp2
, tmp3
44 #endif /* CONFIG_ARM64_PTR_AUTH_KERNEL */
46 #ifdef CONFIG_ARM64_PTR_AUTH
48 * thread.keys_user.ap* as offset exceeds the #imm offset range
49 * so use the base value of ldp as thread.keys_user and offset as
50 * thread.keys_user.ap*.
52 .macro __ptrauth_keys_install_user tsk
, tmp1
, tmp2
, tmp3
53 mov
\tmp
1, #THREAD_KEYS_USER
54 add
\tmp
1, \tsk
, \tmp
1
55 ldp
\tmp
2, \tmp
3, [\tmp
1, #PTRAUTH_USER_KEY_APIA]
56 msr_s SYS_APIAKEYLO_EL1
, \tmp
2
57 msr_s SYS_APIAKEYHI_EL1
, \tmp
3
60 .macro __ptrauth_keys_init_cpu tsk
, tmp1
, tmp2
, tmp3
61 mrs
\tmp
1, id_aa64isar1_el1
62 ubfx
\tmp
1, \tmp
1, #ID_AA64ISAR1_EL1_APA_SHIFT, #8
63 mrs_s
\tmp
2, SYS_ID_AA64ISAR2_EL1
64 ubfx
\tmp
2, \tmp
2, #ID_AA64ISAR2_EL1_APA3_SHIFT, #4
65 orr
\tmp
1, \tmp
1, \tmp
2
66 cbz
\tmp
1, .Lno_addr_auth\@
67 mov_q
\tmp
1, (SCTLR_ELx_ENIA
| SCTLR_ELx_ENIB
| \
68 SCTLR_ELx_ENDA
| SCTLR_ELx_ENDB
)
70 orr
\tmp
2, \tmp
2, \tmp
1
72 __ptrauth_keys_install_kernel_nosync
\tsk
, \tmp
1, \tmp
2, \tmp
3
77 .macro ptrauth_keys_init_cpu tsk
, tmp1
, tmp2
, tmp3
78 alternative_if_not ARM64_HAS_ADDRESS_AUTH
80 alternative_else_nop_endif
81 __ptrauth_keys_init_cpu
\tsk
, \tmp
1, \tmp
2, \tmp
3
85 #else /* !CONFIG_ARM64_PTR_AUTH */
87 .macro ptrauth_keys_install_user tsk
, tmp1
, tmp2
, tmp3
90 #endif /* CONFIG_ARM64_PTR_AUTH */
92 #endif /* __ASM_ASM_POINTER_AUTH_H */