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

This commit is contained in:
maxv 2018-08-12 10:50:35 +00:00
parent 0262a62fe4
commit 9c9be108fe
5 changed files with 22 additions and 37 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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, pd_entry_t *src)
}
#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);
/*