Module Name:    src
Committed By:   maxv
Date:           Tue Mar 17 17:18:49 UTC 2020

Modified Files:
        src/sys/arch/amd64/include: cpu.h param.h pcb.h types.h
        src/sys/arch/x86/x86: vm_machdep.c

Log Message:
Add a redzone between the pcb and the stack. Sent to port-amd64@.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/amd64/include/param.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/include/pcb.h
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/amd64/include/types.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/x86/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.67 src/sys/arch/amd64/include/cpu.h:1.68
--- src/sys/arch/amd64/include/cpu.h:1.67	Sun Dec  8 11:53:54 2019
+++ src/sys/arch/amd64/include/cpu.h	Tue Mar 17 17:18:49 2020
@@ -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 @@ x86_curlwp(void)
 #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__	*/

Index: src/sys/arch/amd64/include/param.h
diff -u src/sys/arch/amd64/include/param.h:1.36 src/sys/arch/amd64/include/param.h:1.37
--- src/sys/arch/amd64/include/param.h:1.36	Sat Feb  8 07:07:07 2020
+++ src/sys/arch/amd64/include/param.h	Tue Mar 17 17:18:49 2020
@@ -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)
-#define	UPAGES		5		/* pages of u-area (1 for redzone) */
 #else
-#define	UPAGES		4		/* pages of u-area */
+#define	UPAGES		5		/* pages of u-area (1 for redzone) */
 #endif
 #define	USPACE		(UPAGES * NBPG)	/* total size of u-area */
 

Index: src/sys/arch/amd64/include/pcb.h
diff -u src/sys/arch/amd64/include/pcb.h:1.31 src/sys/arch/amd64/include/pcb.h:1.32
--- src/sys/arch/amd64/include/pcb.h:1.31	Sat Oct 12 15:44:46 2019
+++ src/sys/arch/amd64/include/pcb.h	Tue Mar 17 17:18:49 2020
@@ -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

Index: src/sys/arch/amd64/include/types.h
diff -u src/sys/arch/amd64/include/types.h:1.64 src/sys/arch/amd64/include/types.h:1.65
--- src/sys/arch/amd64/include/types.h:1.64	Thu Nov 14 16:23:52 2019
+++ src/sys/arch/amd64/include/types.h	Tue Mar 17 17:18:49 2020
@@ -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 @@ typedef	unsigned char		__cpu_simple_lock
 #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

Index: src/sys/arch/x86/x86/vm_machdep.c
diff -u src/sys/arch/x86/x86/vm_machdep.c:1.41 src/sys/arch/x86/x86/vm_machdep.c:1.42
--- src/sys/arch/x86/x86/vm_machdep.c:1.41	Sat Jan 25 15:38:24 2020
+++ src/sys/arch/x86/x86/vm_machdep.c	Tue Mar 17 17:18:49 2020
@@ -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 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	/* 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 @@ vunmapbuf(struct buf *bp, vsize_t len)
 	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 */

Reply via email to