blob: d8b2ce5765538d273bad2cd020e18cfb232c0c4a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Al Virob4b86642016-12-26 04:10:19 -05002#ifndef __ASM_ASM_UACCESS_H
3#define __ASM_ASM_UACCESS_H
4
5#include <asm/alternative.h>
6#include <asm/kernel-pgtable.h>
Will Deaconb5195382017-12-01 17:33:48 +00007#include <asm/mmu.h>
Al Virob4b86642016-12-26 04:10:19 -05008#include <asm/sysreg.h>
9#include <asm/assembler.h>
10
11/*
12 * User access enabling/disabling macros.
13 */
14#ifdef CONFIG_ARM64_SW_TTBR0_PAN
15 .macro __uaccess_ttbr0_disable, tmp1
Steve Capper9dfe4822018-01-11 10:11:57 +000016 mrs \tmp1, ttbr1_el1 // swapper_pg_dir
Catalin Marinas6b88a322018-01-10 13:18:30 +000017 bic \tmp1, \tmp1, #TTBR_ASID_MASK
Steve Capper9dfe4822018-01-11 10:11:57 +000018 sub \tmp1, \tmp1, #RESERVED_TTBR0_SIZE // reserved_ttbr0 just before swapper_pg_dir
19 msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
Al Virob4b86642016-12-26 04:10:19 -050020 isb
Steve Capper9dfe4822018-01-11 10:11:57 +000021 add \tmp1, \tmp1, #RESERVED_TTBR0_SIZE
Will Deacon27a921e2017-08-10 13:58:16 +010022 msr ttbr1_el1, \tmp1 // set reserved ASID
23 isb
Al Virob4b86642016-12-26 04:10:19 -050024 .endm
25
Will Deacon27a921e2017-08-10 13:58:16 +010026 .macro __uaccess_ttbr0_enable, tmp1, tmp2
Al Virob4b86642016-12-26 04:10:19 -050027 get_thread_info \tmp1
28 ldr \tmp1, [\tmp1, #TSK_TI_TTBR0] // load saved TTBR0_EL1
Will Deacon27a921e2017-08-10 13:58:16 +010029 mrs \tmp2, ttbr1_el1
30 extr \tmp2, \tmp2, \tmp1, #48
31 ror \tmp2, \tmp2, #16
32 msr ttbr1_el1, \tmp2 // set the active ASID
33 isb
Al Virob4b86642016-12-26 04:10:19 -050034 msr ttbr0_el1, \tmp1 // set the non-PAN TTBR0_EL1
35 isb
36 .endm
37
Catalin Marinas6b88a322018-01-10 13:18:30 +000038 .macro uaccess_ttbr0_disable, tmp1, tmp2
Al Virob4b86642016-12-26 04:10:19 -050039alternative_if_not ARM64_HAS_PAN
Catalin Marinas6b88a322018-01-10 13:18:30 +000040 save_and_disable_irq \tmp2 // avoid preemption
Al Virob4b86642016-12-26 04:10:19 -050041 __uaccess_ttbr0_disable \tmp1
Catalin Marinas6b88a322018-01-10 13:18:30 +000042 restore_irq \tmp2
Al Virob4b86642016-12-26 04:10:19 -050043alternative_else_nop_endif
44 .endm
45
Will Deacon27a921e2017-08-10 13:58:16 +010046 .macro uaccess_ttbr0_enable, tmp1, tmp2, tmp3
Al Virob4b86642016-12-26 04:10:19 -050047alternative_if_not ARM64_HAS_PAN
Will Deacon27a921e2017-08-10 13:58:16 +010048 save_and_disable_irq \tmp3 // avoid preemption
49 __uaccess_ttbr0_enable \tmp1, \tmp2
50 restore_irq \tmp3
Al Virob4b86642016-12-26 04:10:19 -050051alternative_else_nop_endif
52 .endm
53#else
Catalin Marinas6b88a322018-01-10 13:18:30 +000054 .macro uaccess_ttbr0_disable, tmp1, tmp2
Al Virob4b86642016-12-26 04:10:19 -050055 .endm
56
Will Deacon27a921e2017-08-10 13:58:16 +010057 .macro uaccess_ttbr0_enable, tmp1, tmp2, tmp3
Al Virob4b86642016-12-26 04:10:19 -050058 .endm
59#endif
60
61/*
62 * These macros are no-ops when UAO is present.
63 */
Catalin Marinas6b88a322018-01-10 13:18:30 +000064 .macro uaccess_disable_not_uao, tmp1, tmp2
65 uaccess_ttbr0_disable \tmp1, \tmp2
Al Virob4b86642016-12-26 04:10:19 -050066alternative_if ARM64_ALT_PAN_NOT_UAO
67 SET_PSTATE_PAN(1)
68alternative_else_nop_endif
69 .endm
70
Will Deacon27a921e2017-08-10 13:58:16 +010071 .macro uaccess_enable_not_uao, tmp1, tmp2, tmp3
72 uaccess_ttbr0_enable \tmp1, \tmp2, \tmp3
Al Virob4b86642016-12-26 04:10:19 -050073alternative_if ARM64_ALT_PAN_NOT_UAO
74 SET_PSTATE_PAN(0)
75alternative_else_nop_endif
76 .endm
77
Kristina Martsenko276e9322017-05-03 16:37:47 +010078/*
79 * Remove the address tag from a virtual address, if present.
80 */
Will Deacon2cf899d2019-10-15 21:04:18 -070081 .macro untagged_addr, dst, addr
82 sbfx \dst, \addr, #0, #56
83 and \dst, \dst, \addr
Kristina Martsenko276e9322017-05-03 16:37:47 +010084 .endm
85
Al Virob4b86642016-12-26 04:10:19 -050086#endif