hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/arm64/include/asm/processor.h
....@@ -1,59 +1,61 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Based on arch/arm/include/asm/processor.h
34 *
45 * Copyright (C) 1995-1999 Russell King
56 * 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/>.
187 */
198 #ifndef __ASM_PROCESSOR_H
209 #define __ASM_PROCESSOR_H
2110
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)
2813
2914 /*
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.
3219 */
33
-#define current_text_addr() ({ __label__ _l; _l: &&_l;})
20
+#define NET_IP_ALIGN 0
3421
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__
3629
3730 #include <linux/build_bug.h>
3831 #include <linux/cache.h>
3932 #include <linux/init.h>
4033 #include <linux/stddef.h>
4134 #include <linux/string.h>
35
+#include <linux/thread_info.h>
36
+#include <linux/android_vendor.h>
4237
4338 #include <vdso/processor.h>
4439
4540 #include <asm/alternative.h>
4641 #include <asm/cpufeature.h>
4742 #include <asm/hw_breakpoint.h>
43
+#include <asm/kasan.h>
4844 #include <asm/lse.h>
4945 #include <asm/pgtable-hwdef.h>
46
+#include <asm/pointer_auth.h>
5047 #include <asm/ptrace.h>
48
+#include <asm/spectre.h>
5149 #include <asm/types.h>
5250
5351 /*
5452 * TASK_SIZE - the maximum size of a user space task.
5553 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
5654 */
55
+
56
+#define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS_MIN)
57
+#define TASK_SIZE_64 (UL(1) << vabits_actual)
58
+
5759 #ifdef CONFIG_COMPAT
5860 #if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS)
5961 /*
....@@ -68,13 +70,21 @@
6870 TASK_SIZE_32 : TASK_SIZE_64)
6971 #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
7072 TASK_SIZE_32 : TASK_SIZE_64)
73
+#define DEFAULT_MAP_WINDOW (test_thread_flag(TIF_32BIT) ? \
74
+ TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64)
7175 #else
7276 #define TASK_SIZE TASK_SIZE_64
77
+#define DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64
7378 #endif /* CONFIG_COMPAT */
7479
75
-#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4))
76
-
80
+#ifdef CONFIG_ARM64_FORCE_52BIT
7781 #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
+
7888 #ifdef CONFIG_COMPAT
7989 #define AARCH32_VECTORS_BASE 0xffff0000
8090 #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
....@@ -82,6 +92,15 @@
8292 #else
8393 #define STACK_TOP STACK_TOP_MAX
8494 #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 */
85104
86105 extern phys_addr_t arm64_dma_phys_limit;
87106 #define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1)
....@@ -129,6 +148,8 @@
129148 struct user_fpsimd_state fpsimd_state;
130149 } uw;
131150
151
+ ANDROID_VENDOR_DATA(1);
152
+
132153 unsigned int fpsimd_cpu;
133154 void *sve_state; /* SVE registers, if any */
134155 unsigned int sve_vl; /* SVE vector length */
....@@ -136,7 +157,19 @@
136157 unsigned long fault_address; /* fault info */
137158 unsigned long fault_code; /* ESR_EL1 value */
138159 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;
139168 };
169
+
170
+#define SCTLR_USER_MASK \
171
+ (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | \
172
+ SCTLR_EL1_TCF0_MASK)
140173
141174 static inline void arch_thread_struct_whitelist(unsigned long *offset,
142175 unsigned long *size)
....@@ -174,19 +207,13 @@
174207
175208 static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
176209 {
210
+ s32 previous_syscall = regs->syscallno;
177211 memset(regs, 0, sizeof(*regs));
178
- forget_syscall(regs);
212
+ regs->syscallno = previous_syscall;
179213 regs->pc = pc;
180
-}
181214
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;
190217 }
191218
192219 static inline void start_thread(struct pt_regs *regs, unsigned long pc,
....@@ -194,10 +221,7 @@
194221 {
195222 start_thread_common(regs, pc);
196223 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);
201225 regs->sp = sp;
202226 }
203227
....@@ -214,12 +238,22 @@
214238 regs->pstate |= PSR_AA32_E_BIT;
215239 #endif
216240
217
- if (arm64_get_ssbd_state() != ARM64_SSBD_FORCE_ENABLE)
218
- set_compat_ssbs_bit(regs);
219
-
241
+ spectre_v4_enable_task_mitigation(current);
220242 regs->compat_sp = sp;
221243 }
222244 #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
+}
223257
224258 /* Forward declaration, a strange C thing */
225259 struct task_struct;
....@@ -228,6 +262,8 @@
228262 extern void release_thread(struct task_struct *);
229263
230264 unsigned long get_wchan(struct task_struct *p);
265
+
266
+void update_sctlr_el1(u64 sctlr);
231267
232268 /* Thread switching */
233269 extern struct task_struct *cpu_switch_to(struct task_struct *prev,
....@@ -262,14 +298,6 @@
262298 "nop") : : "p" (ptr));
263299 }
264300
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
-
273301 extern unsigned long __ro_after_init signal_minsigstksz; /* sigframe size */
274302 extern void __init minsigstksz_setup(void);
275303
....@@ -288,12 +316,20 @@
288316 #define SVE_SET_VL(arg) sve_set_current_vl(arg)
289317 #define SVE_GET_VL() sve_get_current_vl()
290318
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
+
291327 #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI
292328 /* 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)
297333 #endif
298334
299335 /*