diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2016-04-05 09:33:06 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2016-04-05 09:33:06 +0000 |
commit | 152cc94c85ff5023f1e216380e8a0a0793f546da (patch) | |
tree | 079911e610494bd5b263850c75f28ee3540e73b5 /usr.sbin/vmd | |
parent | 13e05f1e6413704a4ce8e037ad3138141fa54493 (diff) |
Support processors without unrestricted guest capability.
ok stefan
Diffstat (limited to 'usr.sbin/vmd')
-rw-r--r-- | usr.sbin/vmd/loadfile.h | 10 | ||||
-rw-r--r-- | usr.sbin/vmd/loadfile_elf.c | 39 | ||||
-rw-r--r-- | usr.sbin/vmd/vmm.c | 9 |
3 files changed, 49 insertions, 9 deletions
diff --git a/usr.sbin/vmd/loadfile.h b/usr.sbin/vmd/loadfile.h index 4b473425550..19534e09683 100644 --- a/usr.sbin/vmd/loadfile.h +++ b/usr.sbin/vmd/loadfile.h @@ -1,5 +1,5 @@ /* $NetBSD: loadfile.h,v 1.1 1999/04/28 09:08:50 christos Exp $ */ -/* $OpenBSD: loadfile.h,v 1.3 2016/03/13 13:11:47 stefan Exp $ */ +/* $OpenBSD: loadfile.h,v 1.4 2016/04/05 09:33:05 mlarkin Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -65,6 +65,14 @@ #define LOWMEM_KB 636 +#define BOOTARGS_PAGE 0x2000 +#define STACK_PAGE 0xF000 +#define GDT_PAGE 0x10000 +#define PML4_PAGE 0x11000 +#define PML3_PAGE 0x12000 +#define PML2_PAGE 0x13000 +#define NPTE_PG (PAGE_SIZE / sizeof(pt_entry_t)) + int loadelf_main(int, struct vm_create_params *, struct vcpu_init_state *); diff --git a/usr.sbin/vmd/loadfile_elf.c b/usr.sbin/vmd/loadfile_elf.c index 10a5ad80d83..8d2e68b25b0 100644 --- a/usr.sbin/vmd/loadfile_elf.c +++ b/usr.sbin/vmd/loadfile_elf.c @@ -1,5 +1,5 @@ /* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */ -/* $OpenBSD: loadfile_elf.c,v 1.12 2016/04/04 17:13:54 stefan Exp $ */ +/* $OpenBSD: loadfile_elf.c,v 1.13 2016/04/05 09:33:05 mlarkin Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -100,14 +100,11 @@ #include <machine/vmmvar.h> #include <machine/biosvar.h> #include <machine/segments.h> +#include <machine/pte.h> #include "loadfile.h" #include "vmd.h" -#define BOOTARGS_PAGE 0x2000 -#define GDT_PAGE 0x10000 -#define STACK_PAGE 0xF000 - union { Elf32_Ehdr elf32; Elf64_Ehdr elf64; @@ -195,6 +192,37 @@ push_gdt(void) } /* + * push_pt + * + * Create an identity-mapped page directory hierarchy mapping the first + * 1GB of physical memory. This is used during bootstrapping VMs on + * CPUs without unrestricted guest capability. + */ +static void +push_pt(void) +{ + pt_entry_t ptes[NPTE_PG]; + uint64_t i; + + /* PML3 [0] - first 1GB */ + memset(ptes, 0, sizeof(ptes)); + ptes[0] = PG_V | PML3_PAGE; + write_mem(PML4_PAGE, ptes, PAGE_SIZE); + + /* PML3 [0] - first 1GB */ + memset(ptes, 0, sizeof(ptes)); + ptes[0] = PG_V | PG_RW | PG_u | PML2_PAGE; + write_mem(PML3_PAGE, ptes, PAGE_SIZE); + + /* PML2 [0..511] - first 1GB (in 2MB pages) */ + memset(ptes, 0, sizeof(ptes)); + for (i = 0 ; i < NPTE_PG; i++) { + ptes[i] = PG_V | PG_RW | PG_u | PG_PS | (NBPD_L2 * i); + } + write_mem(PML2_PAGE, ptes, PAGE_SIZE); +} + +/* * loadelf_main * * Loads an ELF kernel to it's defined load address in the guest VM. @@ -234,6 +262,7 @@ loadelf_main(int fd, struct vm_create_params *vcp, struct vcpu_init_state *vis) return (r); push_gdt(); + push_pt(); n = create_bios_memmap(vcp, memmap); bootargsz = push_bootargs(memmap, n); stacksize = push_stack(bootargsz, marks[MARK_END]); diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 521a08beb7f..8c7eddf2df7 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.24 2016/04/04 17:13:54 stefan Exp $ */ +/* $OpenBSD: vmm.c,v 1.25 2016/04/05 09:33:05 mlarkin Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -161,13 +161,16 @@ static struct privsep_proc procs[] = { * * Specific bootloaders should clone this structure and override * those fields as needed. + * + * Note - CR3 and various bits in CR0 may be overridden by vmm(4) based on + * features of the CPU in use. */ static const struct vcpu_init_state vcpu_init_flat32 = { 0x2, /* RFLAGS */ 0x0, /* RIP */ 0x0, /* RSP */ - CR0_CD | CR0_NW | CR0_ET | CR0_PE, /* CR0 */ - 0x0, /* CR3 */ + CR0_CD | CR0_NW | CR0_ET | CR0_PE | CR0_PG, /* CR0 */ + PML4_PAGE, /* CR3 */ { 0x8, 0xFFFFFFFF, 0xC09F, 0x0}, /* CS */ { 0x10, 0xFFFFFFFF, 0xC093, 0x0}, /* DS */ { 0x10, 0xFFFFFFFF, 0xC093, 0x0}, /* ES */ |