Module Name:    src
Committed By:   maxv
Date:           Sun Aug 12 10:50:35 UTC 2018

Modified Files:
        src/sys/arch/amd64/amd64: machdep.c
        src/sys/arch/amd64/include: pmap.h vmparam.h
        src/sys/arch/x86/include: pmap.h
        src/sys/arch/x86/x86: pmap.c

Log Message:
Randomize the main memory on Xen, same as native. Tested on amd64-dom0.


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/amd64/include/vmparam.h
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.297 -r1.298 src/sys/arch/x86/x86/pmap.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/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.311 src/sys/arch/amd64/amd64/machdep.c:1.312
--- src/sys/arch/amd64/amd64/machdep.c:1.311	Sun Aug 12 09:05:52 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Aug 12 10:50:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.311 2018/08/12 09:05:52 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.312 2018/08/12 10:50:35 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.311 2018/08/12 09:05:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.312 2018/08/12 10:50:35 maxv Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -1592,6 +1592,9 @@ init_bootspace(void)
 void
 init_slotspace(void)
 {
+	vaddr_t slotspace_rand(int, size_t, size_t);
+	vaddr_t va;
+
 	memset(&slotspace, 0, sizeof(slotspace));
 
 	/* User. */
@@ -1608,15 +1611,6 @@ init_slotspace(void)
 	slotspace.area[SLAREA_PTE].active = true;
 	slotspace.area[SLAREA_PTE].dropmax = false;
 
-#ifdef XEN
-	/* Main. */
-	slotspace.area[SLAREA_MAIN].sslot = PDIR_SLOT_KERN;
-	slotspace.area[SLAREA_MAIN].mslot = NKL4_MAX_ENTRIES;
-	slotspace.area[SLAREA_MAIN].nslot = 0 /* variable */;
-	slotspace.area[SLAREA_MAIN].active = true;
-	slotspace.area[SLAREA_MAIN].dropmax = false;
-#endif
-
 #ifdef __HAVE_PCPU_AREA
 	/* Per-CPU. */
 	slotspace.area[SLAREA_PCPU].sslot = PDIR_SLOT_PCPU;
@@ -1638,8 +1632,8 @@ init_slotspace(void)
 #ifdef XEN
 	/* Hypervisor. */
 	slotspace.area[SLAREA_HYPV].sslot = 256;
-	slotspace.area[SLAREA_HYPV].mslot = 16;
-	slotspace.area[SLAREA_HYPV].nslot = 16;
+	slotspace.area[SLAREA_HYPV].mslot = 17;
+	slotspace.area[SLAREA_HYPV].nslot = 17;
 	slotspace.area[SLAREA_HYPV].active = true;
 	slotspace.area[SLAREA_HYPV].dropmax = false;
 #endif
@@ -1651,19 +1645,13 @@ init_slotspace(void)
 	slotspace.area[SLAREA_KERN].active = true;
 	slotspace.area[SLAREA_KERN].dropmax = false;
 
-#ifndef XEN
-	vaddr_t slotspace_rand(int, size_t, size_t);
-	vaddr_t va;
-
 	/* Main. */
 	slotspace.area[SLAREA_MAIN].mslot = NKL4_MAX_ENTRIES+1;
 	slotspace.area[SLAREA_MAIN].dropmax = false;
 	va = slotspace_rand(SLAREA_MAIN, NKL4_MAX_ENTRIES * NBPD_L4,
 	    NBPD_L4);
-
 	vm_min_kernel_address = va;
 	vm_max_kernel_address = va + NKL4_MAX_ENTRIES * NBPD_L4;
-#endif
 }
 
 void

Index: src/sys/arch/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.49 src/sys/arch/amd64/include/pmap.h:1.50
--- src/sys/arch/amd64/include/pmap.h:1.49	Sun Aug 12 08:17:50 2018
+++ src/sys/arch/amd64/include/pmap.h	Sun Aug 12 10:50:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.49 2018/08/12 08:17:50 maxv Exp $	*/
+/*	$NetBSD: pmap.h,v 1.50 2018/08/12 10:50:35 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -138,12 +138,7 @@
 #define VA_SIGN_POS(va)		((va) & ~VA_SIGN_MASK)
 
 #define L4_SLOT_PTE		255
-#ifndef XEN
 #define L4_SLOT_KERN		slotspace.area[SLAREA_MAIN].sslot
-#else
-/* Xen use slots 256-272, let's move farther */
-#define L4_SLOT_KERN		320 /* pl4_i(VM_MIN_KERNEL_ADDRESS) */
-#endif
 #define L4_SLOT_KERNBASE	511 /* pl4_i(KERNBASE) */
 
 #define PDIR_SLOT_KERN	L4_SLOT_KERN

Index: src/sys/arch/amd64/include/vmparam.h
diff -u src/sys/arch/amd64/include/vmparam.h:1.46 src/sys/arch/amd64/include/vmparam.h:1.47
--- src/sys/arch/amd64/include/vmparam.h:1.46	Sun Aug 12 08:17:50 2018
+++ src/sys/arch/amd64/include/vmparam.h	Sun Aug 12 10:50:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.46 2018/08/12 08:17:50 maxv Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.47 2018/08/12 10:50:35 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -128,17 +128,16 @@
 #ifndef XEN
 #define VM_MIN_KERNEL_ADDRESS_DEFAULT	0xffff800000000000
 #define VM_MAX_KERNEL_ADDRESS_DEFAULT	0xffffa00000000000
-extern vaddr_t vm_min_kernel_address;
-extern vaddr_t vm_max_kernel_address;
-#define VM_MIN_KERNEL_ADDRESS	vm_min_kernel_address
-#define VM_MAX_KERNEL_ADDRESS	vm_max_kernel_address
 #else
 #define VM_MIN_KERNEL_ADDRESS_DEFAULT	0xffffa00000000000
 #define VM_MAX_KERNEL_ADDRESS_DEFAULT	0xffffc00000000000
-#define VM_MIN_KERNEL_ADDRESS	VM_MIN_KERNEL_ADDRESS_DEFAULT
-#define VM_MAX_KERNEL_ADDRESS	VM_MAX_KERNEL_ADDRESS_DEFAULT
 #endif
 
+extern vaddr_t vm_min_kernel_address;
+extern vaddr_t vm_max_kernel_address;
+#define VM_MIN_KERNEL_ADDRESS	vm_min_kernel_address
+#define VM_MAX_KERNEL_ADDRESS	vm_max_kernel_address
+
 /*
  * The address to which unspecified mapping requests default
  */

Index: src/sys/arch/x86/include/pmap.h
diff -u src/sys/arch/x86/include/pmap.h:1.82 src/sys/arch/x86/include/pmap.h:1.83
--- src/sys/arch/x86/include/pmap.h:1.82	Sun Aug 12 09:05:52 2018
+++ src/sys/arch/x86/include/pmap.h	Sun Aug 12 10:50:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.82 2018/08/12 09:05:52 maxv Exp $	*/
+/*	$NetBSD: pmap.h,v 1.83 2018/08/12 10:50:35 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -174,6 +174,8 @@ struct slotspace {
 	} area[SLSPACE_NAREAS];
 };
 
+extern struct slotspace slotspace;
+
 #ifndef MAXGDTSIZ
 #define MAXGDTSIZ 65536 /* XXX */
 #endif

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.297 src/sys/arch/x86/x86/pmap.c:1.298
--- src/sys/arch/x86/x86/pmap.c:1.297	Sun Aug 12 10:45:27 2018
+++ src/sys/arch/x86/x86/pmap.c	Sun Aug 12 10:50:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.297 2018/08/12 10:45:27 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.298 2018/08/12 10:50:35 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -157,7 +157,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.297 2018/08/12 10:45:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.298 2018/08/12 10:50:35 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1371,7 +1371,8 @@ pmap_init_lapic(void)
 }
 #endif
 
-#if defined(__HAVE_PCPU_AREA) || defined(__HAVE_DIRECT_MAP)
+#if defined(__HAVE_PCPU_AREA) || defined(__HAVE_DIRECT_MAP) || \
+    (defined(XEN) && defined(__x86_64__))
 static size_t
 pmap_pagetree_nentries_range(vaddr_t startva, vaddr_t endva, size_t pgsz)
 {
@@ -1393,7 +1394,7 @@ slotspace_copy(int type, pd_entry_t *dst
 }
 #endif
 
-#if defined(__HAVE_DIRECT_MAP)
+#if defined(__HAVE_DIRECT_MAP) || (defined(XEN) && defined(__x86_64__))
 vaddr_t slotspace_rand(int, size_t, size_t);
 
 /*

Reply via email to