Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Randomize the main memory on Xen, same as native. T...



details:   https://anonhg.NetBSD.org/src/rev/6c4e84df4aa8
branches:  trunk
changeset: 834404:6c4e84df4aa8
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sun Aug 12 10:50:35 2018 +0000

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

diffstat:

 sys/arch/amd64/amd64/machdep.c   |  26 +++++++-------------------
 sys/arch/amd64/include/pmap.h    |   7 +------
 sys/arch/amd64/include/vmparam.h |  13 ++++++-------
 sys/arch/x86/include/pmap.h      |   4 +++-
 sys/arch/x86/x86/pmap.c          |   9 +++++----
 5 files changed, 22 insertions(+), 37 deletions(-)

diffs (183 lines):

diff -r 7250b40708d2 -r 6c4e84df4aa8 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sun Aug 12 10:45:27 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sun Aug 12 10:50:35 2018 +0000
@@ -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 @@
 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 @@
        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 @@
 #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 @@
        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
diff -r 7250b40708d2 -r 6c4e84df4aa8 sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h     Sun Aug 12 10:45:27 2018 +0000
+++ b/sys/arch/amd64/include/pmap.h     Sun Aug 12 10:50:35 2018 +0000
@@ -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
diff -r 7250b40708d2 -r 6c4e84df4aa8 sys/arch/amd64/include/vmparam.h
--- a/sys/arch/amd64/include/vmparam.h  Sun Aug 12 10:45:27 2018 +0000
+++ b/sys/arch/amd64/include/vmparam.h  Sun Aug 12 10:50:35 2018 +0000
@@ -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,16 +128,15 @@
 #ifndef XEN
 #define VM_MIN_KERNEL_ADDRESS_DEFAULT  0xffff800000000000
 #define VM_MAX_KERNEL_ADDRESS_DEFAULT  0xffffa00000000000
+#else
+#define VM_MIN_KERNEL_ADDRESS_DEFAULT  0xffffa00000000000
+#define VM_MAX_KERNEL_ADDRESS_DEFAULT  0xffffc00000000000
+#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
-#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
 
 /*
  * The address to which unspecified mapping requests default
diff -r 7250b40708d2 -r 6c4e84df4aa8 sys/arch/x86/include/pmap.h
--- a/sys/arch/x86/include/pmap.h       Sun Aug 12 10:45:27 2018 +0000
+++ b/sys/arch/x86/include/pmap.h       Sun Aug 12 10:50:35 2018 +0000
@@ -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 @@
        } area[SLSPACE_NAREAS];
 };
 
+extern struct slotspace slotspace;
+
 #ifndef MAXGDTSIZ
 #define MAXGDTSIZ 65536 /* XXX */
 #endif
diff -r 7250b40708d2 -r 6c4e84df4aa8 sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Sun Aug 12 10:45:27 2018 +0000
+++ b/sys/arch/x86/x86/pmap.c   Sun Aug 12 10:50:35 2018 +0000
@@ -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 @@
 }
 #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 @@
 }
 #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);
 
 /*



Home | Main Index | Thread Index | Old Index