1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ASM_UACCESS_H
3 #define __ASM_ASM_UACCESS_H
5 #include <asm/alternative.h>
6 #include <asm/kernel-pgtable.h>
8 #include <asm/sysreg.h>
9 #include <asm/assembler.h>
12 * User access enabling/disabling macros.
14 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
15 .macro __uaccess_ttbr0_disable, tmp1
16 mrs \tmp1, ttbr1_el1 // swapper_pg_dir
17 bic \tmp1, \tmp1, #TTBR_ASID_MASK
18 add \tmp1, \tmp1, #SWAPPER_DIR_SIZE // reserved_ttbr0 at the end of swapper_pg_dir
19 msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
21 sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE
22 msr ttbr1_el1, \tmp1 // set reserved ASID
26 .macro __uaccess_ttbr0_enable, tmp1, tmp2
28 ldr \tmp1, [\tmp1, #TSK_TI_TTBR0] // load saved TTBR0_EL1
30 extr \tmp2, \tmp2, \tmp1, #48
32 msr ttbr1_el1, \tmp2 // set the active ASID
34 msr ttbr0_el1, \tmp1 // set the non-PAN TTBR0_EL1
38 .macro uaccess_ttbr0_disable, tmp1, tmp2
39 alternative_if_not ARM64_HAS_PAN
40 save_and_disable_irq \tmp2 // avoid preemption
41 __uaccess_ttbr0_disable \tmp1
43 alternative_else_nop_endif
46 .macro uaccess_ttbr0_enable, tmp1, tmp2, tmp3
47 alternative_if_not ARM64_HAS_PAN
48 save_and_disable_irq \tmp3 // avoid preemption
49 __uaccess_ttbr0_enable \tmp1, \tmp2
51 alternative_else_nop_endif
54 .macro uaccess_ttbr0_disable, tmp1, tmp2
57 .macro uaccess_ttbr0_enable, tmp1, tmp2, tmp3
62 * These macros are no-ops when UAO is present.
64 .macro uaccess_disable_not_uao, tmp1, tmp2
65 uaccess_ttbr0_disable \tmp1, \tmp2
66 alternative_if ARM64_ALT_PAN_NOT_UAO
68 alternative_else_nop_endif
71 .macro uaccess_enable_not_uao, tmp1, tmp2, tmp3
72 uaccess_ttbr0_enable \tmp1, \tmp2, \tmp3
73 alternative_if ARM64_ALT_PAN_NOT_UAO
75 alternative_else_nop_endif
79 * Remove the address tag from a virtual address, if present.
81 .macro clear_address_tag, dst, addr
83 bic \dst, \addr, #(0xff << 56)
84 csel \dst, \dst, \addr, eq