1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ASM_UACCESS_H
3 #define __ASM_ASM_UACCESS_H
5 #include <asm/alternative-macros.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
\tmp
1, ttbr1_el1
// swapper_pg_dir
17 bic
\tmp
1, \tmp
1, #TTBR_ASID_MASK
18 sub
\tmp
1, \tmp
1, #PAGE_SIZE // reserved_pg_dir just before swapper_pg_dir
19 msr ttbr0_el1
, \tmp
1 // set reserved TTBR0_EL1
21 add
\tmp
1, \tmp
1, #PAGE_SIZE
22 msr ttbr1_el1
, \tmp
1 // set reserved ASID
26 .macro __uaccess_ttbr0_enable
, tmp1
, tmp2
27 get_current_task
\tmp
1
28 ldr
\tmp
1, [\tmp
1, #TSK_TI_TTBR0] // load saved TTBR0_EL1
30 extr
\tmp
2, \tmp
2, \tmp
1, #48
32 msr ttbr1_el1
, \tmp
2 // set the active ASID
34 msr ttbr0_el1
, \tmp
1 // 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
\tmp
2 // avoid preemption
41 __uaccess_ttbr0_disable
\tmp
1
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
\tmp
3 // avoid preemption
49 __uaccess_ttbr0_enable
\tmp
1, \tmp
2
51 alternative_else_nop_endif
54 .macro uaccess_ttbr0_disable
, tmp1
, tmp2
57 .macro uaccess_ttbr0_enable
, tmp1
, tmp2
, tmp3
62 * Generate the assembly for LDTR/STTR with exception table entries.
63 * This is complicated as there is no post-increment or pair versions of the
64 * unprivileged instructions, and USER() only works for single instructions.
66 .macro user_ldp l
, reg1
, reg2
, addr
, post_inc
67 8888: ldtr
\reg
1, [\addr
];
68 8889: ldtr
\reg
2, [\addr
, #8];
69 add
\addr
, \addr
, \post_inc
;
71 _asm_extable
8888b
,\l
;
72 _asm_extable
8889b
,\l
;
75 .macro user_stp l
, reg1
, reg2
, addr
, post_inc
76 8888: sttr
\reg
1, [\addr
];
77 8889: sttr
\reg
2, [\addr
, #8];
78 add
\addr
, \addr
, \post_inc
;
80 _asm_extable
8888b
,\l
;
81 _asm_extable
8889b
,\l
;
84 .macro user_ldst l
, inst
, reg
, addr
, post_inc
85 8888: \inst
\reg
, [\addr
];
86 add
\addr
, \addr
, \post_inc
;
88 _asm_extable
8888b
,\l
;