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>
7 #include <asm/sysreg.h>
8 #include <asm/assembler.h>
11 * User access enabling/disabling macros.
13 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
14 .macro __uaccess_ttbr0_disable, tmp1
15 mrs \tmp1, ttbr1_el1 // swapper_pg_dir
16 add \tmp1, \tmp1, #SWAPPER_DIR_SIZE // reserved_ttbr0 at the end of swapper_pg_dir
17 msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
21 .macro __uaccess_ttbr0_enable, tmp1
23 ldr \tmp1, [\tmp1, #TSK_TI_TTBR0] // load saved TTBR0_EL1
24 msr ttbr0_el1, \tmp1 // set the non-PAN TTBR0_EL1
28 .macro uaccess_ttbr0_disable, tmp1
29 alternative_if_not ARM64_HAS_PAN
30 __uaccess_ttbr0_disable \tmp1
31 alternative_else_nop_endif
34 .macro uaccess_ttbr0_enable, tmp1, tmp2
35 alternative_if_not ARM64_HAS_PAN
36 save_and_disable_irq \tmp2 // avoid preemption
37 __uaccess_ttbr0_enable \tmp1
39 alternative_else_nop_endif
42 .macro uaccess_ttbr0_disable, tmp1
45 .macro uaccess_ttbr0_enable, tmp1, tmp2
50 * These macros are no-ops when UAO is present.
52 .macro uaccess_disable_not_uao, tmp1
53 uaccess_ttbr0_disable \tmp1
54 alternative_if ARM64_ALT_PAN_NOT_UAO
56 alternative_else_nop_endif
59 .macro uaccess_enable_not_uao, tmp1, tmp2
60 uaccess_ttbr0_enable \tmp1, \tmp2
61 alternative_if ARM64_ALT_PAN_NOT_UAO
63 alternative_else_nop_endif
67 * Remove the address tag from a virtual address, if present.
69 .macro clear_address_tag, dst, addr
71 bic \dst, \addr, #(0xff << 56)
72 csel \dst, \dst, \addr, eq