^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __ASM_COMPILER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __ASM_COMPILER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #ifdef ARM64_ASM_ARCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define ARM64_ASM_PREAMBLE ".arch " ARM64_ASM_ARCH "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define ARM64_ASM_PREAMBLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * The EL0/EL1 pointer bits used by a pointer authentication code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This is dependent on TBI0/TBI1 being enabled, or bits 63:56 would also apply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define ptrauth_user_pac_mask() GENMASK_ULL(54, vabits_actual)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ptrauth_kernel_pac_mask() GENMASK_ULL(63, vabits_actual)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Valid for EL0 TTBR0 and EL1 TTBR1 instruction pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ptrauth_clear_pac(ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ((ptr & BIT_ULL(55)) ? (ptr | ptrauth_kernel_pac_mask()) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) (ptr & ~ptrauth_user_pac_mask()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define __builtin_return_address(val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) (void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #endif /* __ASM_COMPILER_H */