Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add a redzone between the pcb and the stack. Sent t...
details: https://anonhg.NetBSD.org/src/rev/06ad75229773
branches: trunk
changeset: 970242:06ad75229773
user: maxv <maxv%NetBSD.org@localhost>
date: Tue Mar 17 17:18:49 2020 +0000
description:
Add a redzone between the pcb and the stack. Sent to port-amd64@.
diffstat:
sys/arch/amd64/include/cpu.h | 5 ++++-
sys/arch/amd64/include/param.h | 6 ++----
sys/arch/amd64/include/pcb.h | 6 +++++-
sys/arch/amd64/include/types.h | 3 ++-
sys/arch/x86/x86/vm_machdep.c | 38 ++++++++++++++++++++++++++++++--------
5 files changed, 43 insertions(+), 15 deletions(-)
diffs (140 lines):
diff -r 253b6f8d0ba9 -r 06ad75229773 sys/arch/amd64/include/cpu.h
--- a/sys/arch/amd64/include/cpu.h Tue Mar 17 17:16:26 2020 +0000
+++ b/sys/arch/amd64/include/cpu.h Tue Mar 17 17:18:49 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.67 2019/12/08 11:53:54 maxv Exp $ */
+/* $NetBSD: cpu.h,v 1.68 2020/03/17 17:18:49 maxv Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -84,6 +84,9 @@
#define CLKF_INTR(frame) (curcpu()->ci_idepth > 0)
#define LWP_PC(l) ((l)->l_md.md_regs->tf_rip)
+void *cpu_uarea_alloc(bool);
+bool cpu_uarea_free(void *);
+
#endif /* _KERNEL */
#else /* __x86_64__ */
diff -r 253b6f8d0ba9 -r 06ad75229773 sys/arch/amd64/include/param.h
--- a/sys/arch/amd64/include/param.h Tue Mar 17 17:16:26 2020 +0000
+++ b/sys/arch/amd64/include/param.h Tue Mar 17 17:18:49 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.36 2020/02/08 07:07:07 maxv Exp $ */
+/* $NetBSD: param.h,v 1.37 2020/03/17 17:18:49 maxv Exp $ */
#ifdef __x86_64__
@@ -69,10 +69,8 @@
#if defined(KASAN) || defined(KMSAN)
#define UPAGES 8
-#elif defined(DIAGNOSTIC)
+#else
#define UPAGES 5 /* pages of u-area (1 for redzone) */
-#else
-#define UPAGES 4 /* pages of u-area */
#endif
#define USPACE (UPAGES * NBPG) /* total size of u-area */
diff -r 253b6f8d0ba9 -r 06ad75229773 sys/arch/amd64/include/pcb.h
--- a/sys/arch/amd64/include/pcb.h Tue Mar 17 17:16:26 2020 +0000
+++ b/sys/arch/amd64/include/pcb.h Tue Mar 17 17:18:49 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcb.h,v 1.31 2019/10/12 15:44:46 christos Exp $ */
+/* $NetBSD: pcb.h,v 1.32 2020/03/17 17:18:49 maxv Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -77,6 +77,10 @@
#define NIOPORTS 1024 /* # of ports we allow to be mapped */
+/*
+ * IMPORTANT NOTE: this structure, including the variable-sized FPU state at
+ * the end, must fit within one page.
+ */
struct pcb {
int pcb_flags;
#define PCB_COMPAT32 0x01
diff -r 253b6f8d0ba9 -r 06ad75229773 sys/arch/amd64/include/types.h
--- a/sys/arch/amd64/include/types.h Tue Mar 17 17:16:26 2020 +0000
+++ b/sys/arch/amd64/include/types.h Tue Mar 17 17:18:49 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.64 2019/11/14 16:23:52 maxv Exp $ */
+/* $NetBSD: types.h,v 1.65 2020/03/17 17:18:49 maxv Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -116,6 +116,7 @@
#define __HAVE_PCPU_AREA 1
#define __HAVE_DIRECT_MAP 1
#endif
+#define __HAVE_CPU_UAREA_ROUTINES 1
#if !defined(NO_PCI_MSI_MSIX)
#define __HAVE_PCI_MSI_MSIX
#endif
diff -r 253b6f8d0ba9 -r 06ad75229773 sys/arch/x86/x86/vm_machdep.c
--- a/sys/arch/x86/x86/vm_machdep.c Tue Mar 17 17:16:26 2020 +0000
+++ b/sys/arch/x86/x86/vm_machdep.c Tue Mar 17 17:18:49 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.41 2020/01/25 15:38:24 ad Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.42 2020/03/17 17:18:49 maxv Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.41 2020/01/25 15:38:24 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.42 2020/03/17 17:18:49 maxv Exp $");
#include "opt_mtrr.h"
@@ -194,12 +194,6 @@
/* Child LWP might get aston() before returning to userspace. */
tf->tf_trapno = T_ASTFLT;
-#if 0 /* DIAGNOSTIC */
- /* Set a red zone in the kernel stack after the uarea. */
- pmap_kremove(uv, PAGE_SIZE);
- pmap_update(pmap_kernel());
-#endif
-
/* If specified, set a different user stack for a child. */
if (stack != NULL) {
#ifdef __x86_64__
@@ -353,3 +347,31 @@
bp->b_data = bp->b_saveaddr;
bp->b_saveaddr = 0;
}
+
+#ifdef __HAVE_CPU_UAREA_ROUTINES
+void *
+cpu_uarea_alloc(bool system)
+{
+ vaddr_t va;
+
+ va = uvm_km_alloc(kernel_map, USPACE, 0, UVM_KMF_WIRED|UVM_KMF_WAITVA);
+ if (va == 0)
+ return NULL;
+
+ /*
+ * The second page is unmapped, and acts as a guard page between the
+ * PCB (first page) and the stack (rest of the pages).
+ */
+ pmap_kremove(va + PAGE_SIZE, PAGE_SIZE);
+ pmap_update(pmap_kernel());
+
+ return (void *)va;
+}
+
+bool
+cpu_uarea_free(void *addr)
+{
+ uvm_km_free(kernel_map, (vaddr_t)addr, USPACE, UVM_KMF_WIRED);
+ return true;
+}
+#endif /* __HAVE_CPU_UAREA_ROUTINES */
Home |
Main Index |
Thread Index |
Old Index