Merge tag 'edac_for_4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp
[sfrench/cifs-2.6.git] / arch / arm64 / include / asm / asm-uaccess.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ASM_UACCESS_H
3 #define __ASM_ASM_UACCESS_H
4
5 #include <asm/alternative.h>
6 #include <asm/kernel-pgtable.h>
7 #include <asm/sysreg.h>
8 #include <asm/assembler.h>
9
10 /*
11  * User access enabling/disabling macros.
12  */
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
18         isb
19         .endm
20
21         .macro  __uaccess_ttbr0_enable, tmp1
22         get_thread_info \tmp1
23         ldr     \tmp1, [\tmp1, #TSK_TI_TTBR0]   // load saved TTBR0_EL1
24         msr     ttbr0_el1, \tmp1                // set the non-PAN TTBR0_EL1
25         isb
26         .endm
27
28         .macro  uaccess_ttbr0_disable, tmp1
29 alternative_if_not ARM64_HAS_PAN
30         __uaccess_ttbr0_disable \tmp1
31 alternative_else_nop_endif
32         .endm
33
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
38         restore_irq \tmp2
39 alternative_else_nop_endif
40         .endm
41 #else
42         .macro  uaccess_ttbr0_disable, tmp1
43         .endm
44
45         .macro  uaccess_ttbr0_enable, tmp1, tmp2
46         .endm
47 #endif
48
49 /*
50  * These macros are no-ops when UAO is present.
51  */
52         .macro  uaccess_disable_not_uao, tmp1
53         uaccess_ttbr0_disable \tmp1
54 alternative_if ARM64_ALT_PAN_NOT_UAO
55         SET_PSTATE_PAN(1)
56 alternative_else_nop_endif
57         .endm
58
59         .macro  uaccess_enable_not_uao, tmp1, tmp2
60         uaccess_ttbr0_enable \tmp1, \tmp2
61 alternative_if ARM64_ALT_PAN_NOT_UAO
62         SET_PSTATE_PAN(0)
63 alternative_else_nop_endif
64         .endm
65
66 /*
67  * Remove the address tag from a virtual address, if present.
68  */
69         .macro  clear_address_tag, dst, addr
70         tst     \addr, #(1 << 55)
71         bic     \dst, \addr, #(0xff << 56)
72         csel    \dst, \dst, \addr, eq
73         .endm
74
75 #endif