.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Based on arch/arm/include/asm/processor.h |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 1995-1999 Russell King |
---|
5 | 6 | * Copyright (C) 2012 ARM Ltd. |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, |
---|
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | - * GNU General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License |
---|
17 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | 7 | */ |
---|
19 | 8 | #ifndef __ASM_PROCESSOR_H |
---|
20 | 9 | #define __ASM_PROCESSOR_H |
---|
21 | 10 | |
---|
22 | | -#define TASK_SIZE_64 (UL(1) << VA_BITS) |
---|
23 | | - |
---|
24 | | -#define KERNEL_DS UL(-1) |
---|
25 | | -#define USER_DS (TASK_SIZE_64 - 1) |
---|
26 | | - |
---|
27 | | -#ifndef __ASSEMBLY__ |
---|
| 11 | +#define KERNEL_DS UL(-1) |
---|
| 12 | +#define USER_DS ((UL(1) << VA_BITS) - 1) |
---|
28 | 13 | |
---|
29 | 14 | /* |
---|
30 | | - * Default implementation of macro that returns current |
---|
31 | | - * instruction pointer ("program counter"). |
---|
| 15 | + * On arm64 systems, unaligned accesses by the CPU are cheap, and so there is |
---|
| 16 | + * no point in shifting all network buffers by 2 bytes just to make some IP |
---|
| 17 | + * header fields appear aligned in memory, potentially sacrificing some DMA |
---|
| 18 | + * performance on some platforms. |
---|
32 | 19 | */ |
---|
33 | | -#define current_text_addr() ({ __label__ _l; _l: &&_l;}) |
---|
| 20 | +#define NET_IP_ALIGN 0 |
---|
34 | 21 | |
---|
35 | | -#ifdef __KERNEL__ |
---|
| 22 | +#define MTE_CTRL_GCR_USER_EXCL_SHIFT 0 |
---|
| 23 | +#define MTE_CTRL_GCR_USER_EXCL_MASK 0xffff |
---|
| 24 | + |
---|
| 25 | +#define MTE_CTRL_TCF_SYNC (1UL << 16) |
---|
| 26 | +#define MTE_CTRL_TCF_ASYNC (1UL << 17) |
---|
| 27 | + |
---|
| 28 | +#ifndef __ASSEMBLY__ |
---|
36 | 29 | |
---|
37 | 30 | #include <linux/build_bug.h> |
---|
38 | 31 | #include <linux/cache.h> |
---|
39 | 32 | #include <linux/init.h> |
---|
40 | 33 | #include <linux/stddef.h> |
---|
41 | 34 | #include <linux/string.h> |
---|
| 35 | +#include <linux/thread_info.h> |
---|
| 36 | +#include <linux/android_vendor.h> |
---|
42 | 37 | |
---|
43 | 38 | #include <vdso/processor.h> |
---|
44 | 39 | |
---|
45 | 40 | #include <asm/alternative.h> |
---|
46 | 41 | #include <asm/cpufeature.h> |
---|
47 | 42 | #include <asm/hw_breakpoint.h> |
---|
| 43 | +#include <asm/kasan.h> |
---|
48 | 44 | #include <asm/lse.h> |
---|
49 | 45 | #include <asm/pgtable-hwdef.h> |
---|
| 46 | +#include <asm/pointer_auth.h> |
---|
50 | 47 | #include <asm/ptrace.h> |
---|
| 48 | +#include <asm/spectre.h> |
---|
51 | 49 | #include <asm/types.h> |
---|
52 | 50 | |
---|
53 | 51 | /* |
---|
54 | 52 | * TASK_SIZE - the maximum size of a user space task. |
---|
55 | 53 | * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area. |
---|
56 | 54 | */ |
---|
| 55 | + |
---|
| 56 | +#define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS_MIN) |
---|
| 57 | +#define TASK_SIZE_64 (UL(1) << vabits_actual) |
---|
| 58 | + |
---|
57 | 59 | #ifdef CONFIG_COMPAT |
---|
58 | 60 | #if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS) |
---|
59 | 61 | /* |
---|
.. | .. |
---|
68 | 70 | TASK_SIZE_32 : TASK_SIZE_64) |
---|
69 | 71 | #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ |
---|
70 | 72 | TASK_SIZE_32 : TASK_SIZE_64) |
---|
| 73 | +#define DEFAULT_MAP_WINDOW (test_thread_flag(TIF_32BIT) ? \ |
---|
| 74 | + TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64) |
---|
71 | 75 | #else |
---|
72 | 76 | #define TASK_SIZE TASK_SIZE_64 |
---|
| 77 | +#define DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 |
---|
73 | 78 | #endif /* CONFIG_COMPAT */ |
---|
74 | 79 | |
---|
75 | | -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) |
---|
76 | | - |
---|
| 80 | +#ifdef CONFIG_ARM64_FORCE_52BIT |
---|
77 | 81 | #define STACK_TOP_MAX TASK_SIZE_64 |
---|
| 82 | +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) |
---|
| 83 | +#else |
---|
| 84 | +#define STACK_TOP_MAX DEFAULT_MAP_WINDOW_64 |
---|
| 85 | +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4)) |
---|
| 86 | +#endif /* CONFIG_ARM64_FORCE_52BIT */ |
---|
| 87 | + |
---|
78 | 88 | #ifdef CONFIG_COMPAT |
---|
79 | 89 | #define AARCH32_VECTORS_BASE 0xffff0000 |
---|
80 | 90 | #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ |
---|
.. | .. |
---|
82 | 92 | #else |
---|
83 | 93 | #define STACK_TOP STACK_TOP_MAX |
---|
84 | 94 | #endif /* CONFIG_COMPAT */ |
---|
| 95 | + |
---|
| 96 | +#ifndef CONFIG_ARM64_FORCE_52BIT |
---|
| 97 | +#define arch_get_mmap_end(addr) ((addr > DEFAULT_MAP_WINDOW) ? TASK_SIZE :\ |
---|
| 98 | + DEFAULT_MAP_WINDOW) |
---|
| 99 | + |
---|
| 100 | +#define arch_get_mmap_base(addr, base) ((addr > DEFAULT_MAP_WINDOW) ? \ |
---|
| 101 | + base + TASK_SIZE - DEFAULT_MAP_WINDOW :\ |
---|
| 102 | + base) |
---|
| 103 | +#endif /* CONFIG_ARM64_FORCE_52BIT */ |
---|
85 | 104 | |
---|
86 | 105 | extern phys_addr_t arm64_dma_phys_limit; |
---|
87 | 106 | #define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1) |
---|
.. | .. |
---|
129 | 148 | struct user_fpsimd_state fpsimd_state; |
---|
130 | 149 | } uw; |
---|
131 | 150 | |
---|
| 151 | + ANDROID_VENDOR_DATA(1); |
---|
| 152 | + |
---|
132 | 153 | unsigned int fpsimd_cpu; |
---|
133 | 154 | void *sve_state; /* SVE registers, if any */ |
---|
134 | 155 | unsigned int sve_vl; /* SVE vector length */ |
---|
.. | .. |
---|
136 | 157 | unsigned long fault_address; /* fault info */ |
---|
137 | 158 | unsigned long fault_code; /* ESR_EL1 value */ |
---|
138 | 159 | struct debug_info debug; /* debugging */ |
---|
| 160 | +#ifdef CONFIG_ARM64_PTR_AUTH |
---|
| 161 | + struct ptrauth_keys_user keys_user; |
---|
| 162 | + struct ptrauth_keys_kernel keys_kernel; |
---|
| 163 | +#endif |
---|
| 164 | +#ifdef CONFIG_ARM64_MTE |
---|
| 165 | + u64 mte_ctrl; |
---|
| 166 | +#endif |
---|
| 167 | + u64 sctlr_user; |
---|
139 | 168 | }; |
---|
| 169 | + |
---|
| 170 | +#define SCTLR_USER_MASK \ |
---|
| 171 | + (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | \ |
---|
| 172 | + SCTLR_EL1_TCF0_MASK) |
---|
140 | 173 | |
---|
141 | 174 | static inline void arch_thread_struct_whitelist(unsigned long *offset, |
---|
142 | 175 | unsigned long *size) |
---|
.. | .. |
---|
174 | 207 | |
---|
175 | 208 | static inline void start_thread_common(struct pt_regs *regs, unsigned long pc) |
---|
176 | 209 | { |
---|
| 210 | + s32 previous_syscall = regs->syscallno; |
---|
177 | 211 | memset(regs, 0, sizeof(*regs)); |
---|
178 | | - forget_syscall(regs); |
---|
| 212 | + regs->syscallno = previous_syscall; |
---|
179 | 213 | regs->pc = pc; |
---|
180 | | -} |
---|
181 | 214 | |
---|
182 | | -static inline void set_ssbs_bit(struct pt_regs *regs) |
---|
183 | | -{ |
---|
184 | | - regs->pstate |= PSR_SSBS_BIT; |
---|
185 | | -} |
---|
186 | | - |
---|
187 | | -static inline void set_compat_ssbs_bit(struct pt_regs *regs) |
---|
188 | | -{ |
---|
189 | | - regs->pstate |= PSR_AA32_SSBS_BIT; |
---|
| 215 | + if (system_uses_irq_prio_masking()) |
---|
| 216 | + regs->pmr_save = GIC_PRIO_IRQON; |
---|
190 | 217 | } |
---|
191 | 218 | |
---|
192 | 219 | static inline void start_thread(struct pt_regs *regs, unsigned long pc, |
---|
.. | .. |
---|
194 | 221 | { |
---|
195 | 222 | start_thread_common(regs, pc); |
---|
196 | 223 | regs->pstate = PSR_MODE_EL0t; |
---|
197 | | - |
---|
198 | | - if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) |
---|
199 | | - set_ssbs_bit(regs); |
---|
200 | | - |
---|
| 224 | + spectre_v4_enable_task_mitigation(current); |
---|
201 | 225 | regs->sp = sp; |
---|
202 | 226 | } |
---|
203 | 227 | |
---|
.. | .. |
---|
214 | 238 | regs->pstate |= PSR_AA32_E_BIT; |
---|
215 | 239 | #endif |
---|
216 | 240 | |
---|
217 | | - if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE) |
---|
218 | | - set_compat_ssbs_bit(regs); |
---|
219 | | - |
---|
| 241 | + spectre_v4_enable_task_mitigation(current); |
---|
220 | 242 | regs->compat_sp = sp; |
---|
221 | 243 | } |
---|
222 | 244 | #endif |
---|
| 245 | + |
---|
| 246 | +static inline bool is_ttbr0_addr(unsigned long addr) |
---|
| 247 | +{ |
---|
| 248 | + /* entry assembly clears tags for TTBR0 addrs */ |
---|
| 249 | + return addr < TASK_SIZE; |
---|
| 250 | +} |
---|
| 251 | + |
---|
| 252 | +static inline bool is_ttbr1_addr(unsigned long addr) |
---|
| 253 | +{ |
---|
| 254 | + /* TTBR1 addresses may have a tag if KASAN_SW_TAGS is in use */ |
---|
| 255 | + return arch_kasan_reset_tag(addr) >= PAGE_OFFSET; |
---|
| 256 | +} |
---|
223 | 257 | |
---|
224 | 258 | /* Forward declaration, a strange C thing */ |
---|
225 | 259 | struct task_struct; |
---|
.. | .. |
---|
228 | 262 | extern void release_thread(struct task_struct *); |
---|
229 | 263 | |
---|
230 | 264 | unsigned long get_wchan(struct task_struct *p); |
---|
| 265 | + |
---|
| 266 | +void update_sctlr_el1(u64 sctlr); |
---|
231 | 267 | |
---|
232 | 268 | /* Thread switching */ |
---|
233 | 269 | extern struct task_struct *cpu_switch_to(struct task_struct *prev, |
---|
.. | .. |
---|
262 | 298 | "nop") : : "p" (ptr)); |
---|
263 | 299 | } |
---|
264 | 300 | |
---|
265 | | -#define HAVE_ARCH_PICK_MMAP_LAYOUT |
---|
266 | | - |
---|
267 | | -#endif |
---|
268 | | - |
---|
269 | | -void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused); |
---|
270 | | -void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused); |
---|
271 | | -void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused); |
---|
272 | | - |
---|
273 | 301 | extern unsigned long __ro_after_init signal_minsigstksz; /* sigframe size */ |
---|
274 | 302 | extern void __init minsigstksz_setup(void); |
---|
275 | 303 | |
---|
.. | .. |
---|
288 | 316 | #define SVE_SET_VL(arg) sve_set_current_vl(arg) |
---|
289 | 317 | #define SVE_GET_VL() sve_get_current_vl() |
---|
290 | 318 | |
---|
| 319 | +/* PR_PAC_RESET_KEYS prctl */ |
---|
| 320 | +#define PAC_RESET_KEYS(tsk, arg) ptrauth_prctl_reset_keys(tsk, arg) |
---|
| 321 | + |
---|
| 322 | +/* PR_PAC_{SET,GET}_ENABLED_KEYS prctl */ |
---|
| 323 | +#define PAC_SET_ENABLED_KEYS(tsk, keys, enabled) \ |
---|
| 324 | + ptrauth_set_enabled_keys(tsk, keys, enabled) |
---|
| 325 | +#define PAC_GET_ENABLED_KEYS(tsk) ptrauth_get_enabled_keys(tsk) |
---|
| 326 | + |
---|
291 | 327 | #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI |
---|
292 | 328 | /* PR_{SET,GET}_TAGGED_ADDR_CTRL prctl */ |
---|
293 | | -long set_tagged_addr_ctrl(unsigned long arg); |
---|
294 | | -long get_tagged_addr_ctrl(void); |
---|
295 | | -#define SET_TAGGED_ADDR_CTRL(arg) set_tagged_addr_ctrl(arg) |
---|
296 | | -#define GET_TAGGED_ADDR_CTRL() get_tagged_addr_ctrl() |
---|
| 329 | +long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg); |
---|
| 330 | +long get_tagged_addr_ctrl(struct task_struct *task); |
---|
| 331 | +#define SET_TAGGED_ADDR_CTRL(arg) set_tagged_addr_ctrl(current, arg) |
---|
| 332 | +#define GET_TAGGED_ADDR_CTRL() get_tagged_addr_ctrl(current) |
---|
297 | 333 | #endif |
---|
298 | 334 | |
---|
299 | 335 | /* |
---|