From 8cd5c382bdbbae3bcef5b9efb427c04f030dbc4e Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sun, 5 Sep 2021 22:34:37 +0200
Subject: [PATCH] Remove the old vmm.

---
 Makefile_upgrade.inc                         |    5 +
 lib/libc/sys/Makefile.inc                    |    4 +-
 lib/libc/sys/Symbol.map                      |    6 -
 lib/libc/sys/vmm.2                           |   95 -
 share/man/man7/vkernel.7                     |    7 +-
 sys/conf/files                               |    1 -
 sys/kern/init_sysent.c                       |    4 +-
 sys/kern/kern_clock.c                        |    3 -
 sys/kern/kern_exit.c                         |    5 -
 sys/kern/kern_umtx.c                         |   14 -
 sys/kern/sys_vmm.c                           |  231 ---
 sys/kern/syscalls.c                          |    4 +-
 sys/kern/syscalls.master                     |    4 +-
 sys/platform/pc64/conf/files                 |   18 -
 sys/platform/pc64/include/vmm.h              |   48 -
 sys/platform/pc64/vmm/ept.c                  |  544 ------
 sys/platform/pc64/vmm/ept.h                  |  101 -
 sys/platform/pc64/vmm/svm.c                  |  171 --
 sys/platform/pc64/vmm/svm.h                  |   90 -
 sys/platform/pc64/vmm/vmm.c                  |  208 ---
 sys/platform/pc64/vmm/vmm.h                  |  101 -
 sys/platform/pc64/vmm/vmm_utils.c            |  173 --
 sys/platform/pc64/vmm/vmm_utils.h            |   52 -
 sys/platform/pc64/vmm/vmx.c                  | 1741 ------------------
 sys/platform/pc64/vmm/vmx.h                  |  335 ----
 sys/platform/pc64/vmm/vmx_genassym.c         |   72 -
 sys/platform/pc64/vmm/vmx_instr.h            |  164 --
 sys/platform/pc64/vmm/vmx_trap.s             |  200 --
 sys/platform/pc64/vmm/vmx_vmcs.h             |  215 ---
 sys/platform/pc64/x86_64/tls.c               |    5 -
 sys/platform/pc64/x86_64/vm_machdep.c        |   11 +-
 sys/platform/vkernel64/include/vmm.h         |   74 -
 sys/platform/vkernel64/platform/cothread.c   |   11 -
 sys/platform/vkernel64/platform/init.c       |  152 +-
 sys/platform/vkernel64/platform/pmap.c       |  102 +-
 sys/platform/vkernel64/platform/pmap_inval.c |  179 +-
 sys/platform/vkernel64/x86_64/mp.c           |   14 -
 sys/platform/vkernel64/x86_64/trap.c         |    6 +-
 sys/sys/param.h                              |    3 +-
 sys/sys/proc.h                               |    8 +-
 sys/sys/syscall.h                            |    4 +-
 sys/sys/syscall.mk                           |    2 -
 sys/sys/sysproto.h                           |   10 -
 sys/sys/sysunion.h                           |    2 -
 sys/sys/thread.h                             |    2 +-
 sys/sys/vmm.h                                |   61 -
 sys/vfs/procfs/procfs_mem.c                  |   13 -
 sys/vm/vm_glue.c                             |    8 -
 sys/vm/vm_vmspace.c                          |   82 +-
 test/vmm/Makefile                            |    5 -
 test/vmm/vmm_test.c                          |  111 --
 51 files changed, 72 insertions(+), 5409 deletions(-)
 delete mode 100644 lib/libc/sys/vmm.2
 delete mode 100644 sys/kern/sys_vmm.c
 delete mode 100644 sys/platform/pc64/include/vmm.h
 delete mode 100644 sys/platform/pc64/vmm/ept.c
 delete mode 100644 sys/platform/pc64/vmm/ept.h
 delete mode 100644 sys/platform/pc64/vmm/svm.c
 delete mode 100644 sys/platform/pc64/vmm/svm.h
 delete mode 100644 sys/platform/pc64/vmm/vmm.c
 delete mode 100644 sys/platform/pc64/vmm/vmm.h
 delete mode 100644 sys/platform/pc64/vmm/vmm_utils.c
 delete mode 100644 sys/platform/pc64/vmm/vmm_utils.h
 delete mode 100644 sys/platform/pc64/vmm/vmx.c
 delete mode 100644 sys/platform/pc64/vmm/vmx.h
 delete mode 100644 sys/platform/pc64/vmm/vmx_genassym.c
 delete mode 100644 sys/platform/pc64/vmm/vmx_instr.h
 delete mode 100644 sys/platform/pc64/vmm/vmx_trap.s
 delete mode 100644 sys/platform/pc64/vmm/vmx_vmcs.h
 delete mode 100644 sys/platform/vkernel64/include/vmm.h
 delete mode 100644 sys/sys/vmm.h
 delete mode 100644 test/vmm/Makefile
 delete mode 100644 test/vmm/vmm_test.c

diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc
index d634bb2584f..cc2203e905c 100644
--- a/Makefile_upgrade.inc
+++ b/Makefile_upgrade.inc
@@ -3914,6 +3914,11 @@ TO_REMOVE+=/usr/share/man/man8/ndisgen.8.gz
 TO_REMOVE+=/usr/share/misc/windrv_stub.c
 TO_REMOVE+=/usr/include/stand.h
 TO_REMOVE+=/usr/lib/libstand.a
+TO_REMOVE+=/usr/include/machine/vmm.h
+TO_REMOVE+=/usr/include/sys/vmm.h
+TO_REMOVE+=/usr/share/man/man2/vmm.2.gz
+TO_REMOVE+=/usr/share/man/man2/vmm_guest_ctl.2.gz
+TO_REMOVE+=/usr/share/man/man2/vmm_guest_sync_addr.2.gz
 
 .if !defined(WANT_INSTALLER)
 TO_REMOVE+=/usr/sbin/dfuibe_installer
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index c16757f61d5..ea41cbb2c2f 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -100,7 +100,7 @@ MAN+=	_exit.2 accept.2 access.2 acct.2 adjtime.2 bind.2 \
 	truncate.2 tls.2 umask.2 umtx.2 undelete.2 \
 	unlink.2 unlinkat.2 utimensat.2 utimes.2 utrace.2 usched_set.2 \
 	uuidgen.2 \
-	varsym.2 vfork.2 vmm.2 vquotactl.2 wait.2 write.2
+	varsym.2 vfork.2 vquotactl.2 wait.2 write.2
 
 MLINKS+=accept.2 accept4.2
 MLINKS+=access.2 eaccess.2 \
@@ -234,8 +234,6 @@ MLINKS+=utimes.2 futimes.2 \
 MLINKS+=varsym.2 varsym_get.2 \
 	varsym.2 varsym_list.2 \
 	varsym.2 varsym_set.2
-MLINKS+=vmm.2 vmm_guest_ctl.2 \
-	vmm.2 vmm_guest_sync_addr.2
 MLINKS+=wait.2 wait3.2 \
 	wait.2 wait4.2 \
 	wait.2 wait6.2 \
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index a867b78364f..069a01d500d 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -290,8 +290,6 @@ DF404.0 {
     varsym_list;
     varsym_set;
     vfork;
-    vmm_guest_ctl;
-    vmm_guest_sync_addr;
     vmspace_create;
     vmspace_ctl;
     vmspace_destroy;
@@ -628,8 +626,6 @@ DFprivate_1.0 {
     __sys_varsym_list;
     __sys_varsym_set;
     __sys_vfork;
-    __sys_vmm_guest_ctl;
-    __sys_vmm_guest_sync_addr;
     __sys_vmspace_create;
     __sys_vmspace_ctl;
     __sys_vmspace_destroy;
@@ -933,8 +929,6 @@ DFprivate_1.0 {
     _varsym_list;
     _varsym_set;
     _vfork;
-    _vmm_guest_ctl;
-    _vmm_guest_sync_addr;
     _vmspace_create;
     _vmspace_ctl;
     _vmspace_destroy;
diff --git a/lib/libc/sys/vmm.2 b/lib/libc/sys/vmm.2
deleted file mode 100644
index b8d9f91d799..00000000000
--- a/lib/libc/sys/vmm.2
+++ /dev/null
@@ -1,95 +0,0 @@
-.\"
-.\" Copyright (c) 2015
-.\"	The DragonFly Project.  All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\"
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in
-.\"    the documentation and/or other materials provided with the
-.\"    distribution.
-.\" 3. Neither the name of The DragonFly Project nor the names of its
-.\"    contributors may be used to endorse or promote products derived
-.\"    from this software without specific, prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
-.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
-.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.Dd September 1, 2015
-.Dt VMM 2
-.Os
-.Sh NAME
-.Nm vmm_guest_ctl ,
-.Nm vmm_guest_sync_addr
-.Nd enter VMM mode / sync VMM threads
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/vmm.h
-.Ft int
-.Fn vmm_guest_ctl "int op" "struct vmm_guest_options *options"
-.Ft int
-.Fn vmm_guest_sync_addr "long *dstaddr" "long *srcaddr"
-.Sh DESCRIPTION
-In order to run a virtual machine on top of the host operating system, two
-sets of page tables are needed (one each for the host and guest).
-Older CPUs supports only one level of page tables and the second level had
-to be emulated in software.
-Modern CPUs have support for a second level of page table translations,
-such as
-.Tn Intel Ap s
-EPT
-or
-.Tn AMD Ap s
-RVI.
-The
-.Fn vmm_*
-functions bring the guest virtual machine into a state in which
-the hardware is able to walk two levels of page tables.
-.Pp
-The only
-.Fa op
-currently supported by
-.Fn vmm_guest_ctl
-is
-.Dv VMM_GUEST_RUN ,
-which bootstraps the calling process as a VMM process running with
-extended/nested page table support (two layers of page tables).
-The
-.Ft vmm_guest_options
-struct is defined in
-.In sys/vmm.h .
-.Pp
-The
-.Fn vmm_guest_sync_addr
-function copies the content of
-.Fa srcaddr
-to
-.Fa dstaddr ,
-synchronizing with all CPUs which are in VMM mode (i.e., all CPUs will see
-.Fa srcaddr Ap s
-value at
-.Fa dstaddr ) .
-.Sh HISTORY
-The
-.Fn vmm_guest_ctl
-and
-.Fn vmm_guest_sync_addr
-system calls were added in
-.Dx 3.5 .
-.Sh AUTHORS
-.An Mihai Carabas
diff --git a/share/man/man7/vkernel.7 b/share/man/man7/vkernel.7
index 2cc4cdf2003..342f6e5123c 100644
--- a/share/man/man7/vkernel.7
+++ b/share/man/man7/vkernel.7
@@ -29,7 +29,7 @@
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 5, 2019
+.Dd September 5, 2021
 .Dt VKERNEL 7
 .Os
 .Sh NAME
@@ -45,7 +45,7 @@
 .Cd "device vke"
 .Pp
 .Pa /var/vkernel/boot/kernel/kernel
-.Op Fl hdstUvz
+.Op Fl hstUvz
 .Op Fl c Ar file
 .Op Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ...
 .Op Fl i Ar file
@@ -82,9 +82,6 @@ or
 .Fl c
 option specified on the command line will be the boot disk.
 The CD9660 filesystem is assumed when booting from this media.
-.It Fl d
-Disables hardware pagetable for
-.Nm .
 .It Fl e Ar name Ns = Ns Li value : Ns Ar name Ns = Ns Li value : Ns ...
 Specify an environment to be used by the kernel.
 This option can be specified more than once.
diff --git a/sys/conf/files b/sys/conf/files
index 5303572285e..5a0e447a539 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1503,7 +1503,6 @@ kern/vfs_vfsops.c	standard
 kern/kern_threads.c	standard
 kern/vfs_aio.c		standard
 kern/subr_cpu_topology.c	standard
-kern/sys_vmm.c		standard
 vfs/deadfs/dead_vnops.c	standard
 vfs/fifofs/fifo_vnops.c	standard
 vfs/nullfs/null_vfsops.c	optional nullfs
diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c
index 2dc0b600834..da361b04514 100644
--- a/sys/kern/init_sysent.c
+++ b/sys/kern/init_sysent.c
@@ -548,8 +548,8 @@ struct sysent sysent[] = {
 	{ AS(linkat_args), (sy_call_t *)sys_linkat },	/* 531 = linkat */
 	{ AS(eaccess_args), (sy_call_t *)sys_eaccess },	/* 532 = eaccess */
 	{ AS(lpathconf_args), (sy_call_t *)sys_lpathconf },	/* 533 = lpathconf */
-	{ AS(vmm_guest_ctl_args), (sy_call_t *)sys_vmm_guest_ctl },	/* 534 = vmm_guest_ctl */
-	{ AS(vmm_guest_sync_addr_args), (sy_call_t *)sys_vmm_guest_sync_addr },	/* 535 = vmm_guest_sync_addr */
+	{ 0, (sy_call_t *)sys_nosys },			/* 534 = obsolete vmm_guest_ctl */
+	{ 0, (sy_call_t *)sys_nosys },			/* 535 = obsolete vmm_guest_sync_addr */
 	{ AS(procctl_args), (sy_call_t *)sys_procctl },	/* 536 = procctl */
 	{ AS(chflagsat_args), (sy_call_t *)sys_chflagsat },	/* 537 = chflagsat */
 	{ AS(pipe2_args), (sy_call_t *)sys_pipe2 },	/* 538 = pipe2 */
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index c6b7016a0ec..f98fdf78ae7 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -1003,9 +1003,6 @@ statclock(systimer_t info, int in_ipi, struct intrframe *frame)
 			 * The vkernel doesn't do a good job providing trap
 			 * frames that we can test.  If the GDF_VIRTUSER
 			 * flag is set we probably interrupted user mode.
-			 *
-			 * We also use this flag on the host when entering
-			 * VMM mode.
 			 */
 			td->td_uticks += bump;
 
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 13c63f74ae1..f26c8efc919 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -72,8 +72,6 @@
 #include <sys/refcount.h>
 #include <sys/spinlock2.h>
 
-#include <machine/vmm.h>
-
 static void reaplwps(void *context, int dummy);
 static void reaplwp(struct lwp *lp);
 static void killlwps(struct lwp *lp);
@@ -694,9 +692,6 @@ lwp_exit(int masterexit, void *waddr)
 	if (lp->lwp_vkernel)
 		vkernel_lwp_exit(lp);
 
-	if (td->td_vmm)
-		vmm_vmdestroy();
-
 	/*
 	 * Clean up select/poll support
 	 */
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 6eda83a54af..bd759e9825f 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -67,8 +67,6 @@
 
 #include <vm/vm_page2.h>
 
-#include <machine/vmm.h>
-
 /*
  * Improve umtx performance by polling for 4000nS before going to sleep.
  * This can avoid many IPIs in typical pthreads mutex situations.
@@ -125,12 +123,6 @@ sys_umtx_sleep(struct sysmsg *sysmsg, const struct umtx_sleep_args *uap)
 	return (EINVAL);
     td = curthread;
 
-    if (td->td_vmm) {
-	register_t gpa;
-	vmm_vm_get_gpa(td->td_proc, &gpa, (register_t)ptr);
-	ptr = (const int *)gpa;
-    }
-
     uptr = __DEQUALIFY(void *, ptr);
     if ((vm_offset_t)uptr & (sizeof(int) - 1))
 	return EFAULT;
@@ -268,12 +260,6 @@ sys_umtx_wakeup(struct sysmsg *sysmsg, const struct umtx_wakeup_args *uap)
 
     td = curthread;
 
-    if (td->td_vmm) {
-	register_t gpa;
-	vmm_vm_get_gpa(td->td_proc, &gpa, (register_t)ptr);
-	ptr = (const int *)gpa;
-    }
-
     /*
      * WARNING! We can only use vm_fault_page*() for reading data.  We
      *		cannot use it for writing data because there is no pmap
diff --git a/sys/kern/sys_vmm.c b/sys/kern/sys_vmm.c
deleted file mode 100644
index 31e49191ee4..00000000000
--- a/sys/kern/sys_vmm.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sysmsg.h>
-#include <sys/proc.h>
-#include <sys/wait.h>
-#include <sys/vmm.h>
-
-#include <sys/thread2.h>
-#include <sys/spinlock2.h>
-
-#include <machine/cpu.h>
-#include <machine/pmap.h>
-#include <machine/vmm.h>
-#include <machine/vmparam.h>
-
-#include <vm/vm_map.h>
-
-/*
- * vmm guest system call:
- * - init the calling thread structure
- * - prepare for running in non-root mode
- */
-int
-sys_vmm_guest_ctl(struct sysmsg *sysmsg,
-		  const struct vmm_guest_ctl_args *uap)
-{
-	int error = 0;
-	struct vmm_guest_options options;
-	struct trapframe *tf = sysmsg->sysmsg_frame;
-	unsigned long stack_limit = USRSTACK;
-	unsigned char stack_page[PAGE_SIZE];
-
-	clear_quickret();
-
-	switch (uap->op) {
-	case VMM_GUEST_RUN:
-		error = copyin(uap->options, &options,
-			       sizeof(struct vmm_guest_options));
-		if (error) {
-			kprintf("%s: error copyin vmm_guest_options\n",
-				__func__);
-			goto out;
-		}
-
-		while(stack_limit > tf->tf_sp) {
-			stack_limit -= PAGE_SIZE;
-			options.new_stack -= PAGE_SIZE;
-
-			error = copyin((const void *)stack_limit,
-				       (void *)stack_page, PAGE_SIZE);
-			if (error) {
-				kprintf("%s: error copyin stack\n",
-					__func__);
-				goto out;
-			}
-
-			error = copyout((const void *)stack_page,
-					(void *)options.new_stack, PAGE_SIZE);
-			if (error) {
-				kprintf("%s: error copyout stack\n",
-				    __func__);
-				goto out;
-			}
-		}
-
-		bcopy(tf, &options.tf, sizeof(struct trapframe));
-
-		error = vmm_vminit(&options);
-		if (error) {
-			if (error == ENODEV) {
-				kprintf("%s: vmm_vminit failed - "
-					"no VMM available \n", __func__);
-				goto out;
-			}
-			kprintf("%s: vmm_vminit failed\n", __func__);
-			goto out_exit;
-		}
-
-		generic_lwp_return(curthread->td_lwp, tf);
-
-		error = vmm_vmrun();
-
-		break;
-	default:
-		kprintf("%s: INVALID op\n", __func__);
-		error = EINVAL;
-		goto out;
-	}
-out_exit:
-	exit1(W_EXITCODE(error, 0));
-out:
-	return (error);
-}
-
-/*
- * The remote IPI will force the cpu out of any VMM mode it is
- * in.  When combined with bumping pm_invgen we can ensure that
- * INVEPT will be called when it returns.
- */
-static void
-vmm_exit_vmm(void *dummy __unused)
-{
-}
-
-/*
- * Swap the 64 bit value between *dstaddr and *srcaddr in a pmap-safe manner
- * and invalidate the tlb on all cpus the vkernel is running on.
- *
- * If dstaddr is NULL, just invalidate the tlb on the current cpu.
- *
- * v = *srcaddr
- * v = swap(dstaddr, v)
- * *dstaddr = v
- */
-int
-sys_vmm_guest_sync_addr(struct sysmsg *sysmsg,
-			const struct vmm_guest_sync_addr_args *uap)
-{
-	int error = 0;
-	cpulock_t olock;
-	cpulock_t nlock;
-	cpumask_t mask;
-	struct proc *p = curproc;
-	long v;
-
-	if (p->p_vmm == NULL)
-		return ENOSYS;
-	if (uap->dstaddr == NULL)
-		return 0;
-
-	crit_enter_id("vmm_inval");
-
-	/*
-	 * Acquire CPULOCK_EXCL, spin while we wait.  This will prevent
-	 * any other cpu trying to use related VMMs to wait for us.
-	 */
-	KKASSERT(CPUMASK_TESTMASK(p->p_vmm_cpumask, mycpu->gd_cpumask) == 0);
-	for (;;) {
-		olock = p->p_vmm_cpulock & ~CPULOCK_EXCL;
-		cpu_ccfence();
-		nlock = olock | CPULOCK_EXCL;
-		if (atomic_cmpset_int(&p->p_vmm_cpulock, olock, nlock))
-			break;
-		lwkt_process_ipiq();
-		cpu_pause();
-	}
-
-	/*
-	 * Wait for other cpu's to exit VMM mode (for this vkernel).  No
-	 * new cpus will enter VMM mode while we hold the lock.  New waiters
-	 * may turn-up though so the wakeup() later on has to be
-	 * unconditional.
-	 *
-	 * We must test on p_vmm_cpulock's counter, not the mask, because
-	 * VMM entries will set the mask bit unconditionally first
-	 * (interlocking our IPI below) and then conditionally bump the
-	 * counter.
-	 */
-	if (olock & CPULOCK_CNTMASK) {
-		mask = p->p_vmm_cpumask;
-		CPUMASK_ANDMASK(mask, mycpu->gd_other_cpus);
-		lwkt_send_ipiq_mask(mask, vmm_exit_vmm, NULL);
-		while (p->p_vmm_cpulock & CPULOCK_CNTMASK) {
-			lwkt_process_ipiq();
-			cpu_pause();
-		}
-	}
-
-#ifndef _KERNEL_VIRTUAL
-	/*
-	 * Ensure that any new entries into VMM mode using
-	 * vmm's managed under this process will issue a
-	 * INVEPT before resuming.
-	 */
-	atomic_add_64(&p->p_vmspace->vm_pmap.pm_invgen, 1);
-#endif
-
-	/*
-	 * Make the requested modification, wakeup any waiters.
-	 */
-	v = fuword64(uap->srcaddr);
-	v = swapu64(uap->dstaddr, v);
-	suword64(uap->srcaddr, v);
-
-	/*
-	 * VMMs on remote cpus will not be re-entered until we
-	 * clear the lock.
-	 */
-	atomic_clear_int(&p->p_vmm_cpulock, CPULOCK_EXCL);
-#if 0
-	wakeup(&p->p_vmm_cpulock);
-#endif
-
-	crit_exit_id("vmm_inval");
-
-	return error;
-}
diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c
index efbc838c96a..a240012e4fd 100644
--- a/sys/kern/syscalls.c
+++ b/sys/kern/syscalls.c
@@ -540,8 +540,8 @@ const char *syscallnames[] = {
 	"linkat",			/* 531 = linkat */
 	"eaccess",			/* 532 = eaccess */
 	"lpathconf",			/* 533 = lpathconf */
-	"vmm_guest_ctl",			/* 534 = vmm_guest_ctl */
-	"vmm_guest_sync_addr",			/* 535 = vmm_guest_sync_addr */
+	"obs_vmm_guest_ctl",			/* 534 = obsolete vmm_guest_ctl */
+	"obs_vmm_guest_sync_addr",			/* 535 = obsolete vmm_guest_sync_addr */
 	"procctl",			/* 536 = procctl */
 	"chflagsat",			/* 537 = chflagsat */
 	"pipe2",			/* 538 = pipe2 */
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index b1d6ec01eb1..42e9283a3b8 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -715,8 +715,8 @@
 				char *path2, int flags); }
 532	STD	{ int eaccess(char *path, int flags); }
 533	STD	{ int lpathconf(char *path, int name); }
-534	STD	{ int vmm_guest_ctl(int op, struct vmm_guest_options *options); }
-535	STD	{ int vmm_guest_sync_addr(long *dstaddr, long *srcaddr); }
+534	OBSOL	vmm_guest_ctl
+535	OBSOL	vmm_guest_sync_addr
 536	STD	{ int procctl(idtype_t idtype, id_t id, int cmd, void *data); }
 537	STD	{ int chflagsat(int fd, const char *path, u_long flags, int atflags);}
 538	STD	{ int pipe2(int *fildes, int flags); }
diff --git a/sys/platform/pc64/conf/files b/sys/platform/pc64/conf/files
index fdf20203f1c..46c9fb9715f 100644
--- a/sys/platform/pc64/conf/files
+++ b/sys/platform/pc64/conf/files
@@ -205,24 +205,6 @@ bus/isa/vga_isa.c			optional	vga
 platform/pc64/isa/clock.c		standard
 platform/pc64/isa/isa_intr.c		optional	isa
 platform/pc64/x86_64/spinlock.s		standard
-
-vmx_genassym.o				standard					\
-	dependency 	" $S/platform/$P/vmm/vmx_genassym.c ${FORWARD_HEADERS_COOKIE}"	\
-	compile-with	"${CC} ${CFLAGS:N-fno-common:N-flto} -fcommon ${WERROR} -c ${.IMPSRC}" \
-	no-obj no-implicit-rule								\
-	clean		"vmx_genassym.o"
-vmx_assym.h				standard					\
-	dependency 	"$S/kern/genassym.sh vmx_genassym.o"				\
-	compile-with	"sh $S/kern/genassym.sh vmx_genassym.o > ${.TARGET}"		\
-	no-obj no-implicit-rule before-depend						\
-	clean		"vmx_assym.h"
-platform/pc64/vmm/vmm.c			standard
-platform/pc64/vmm/vmm_utils.c		standard
-# platform/pc64/vmm/vmx.c		standard
-# platform/pc64/vmm/ept.c		standard
-# platform/pc64/vmm/vmx_trap.s		standard
-# platform/pc64/vmm/svm.c		standard
-
 dev/virtual/hyperv/hyperv.c		standard
 dev/virtual/hyperv/hyperv_busdma.c	standard
 dev/virtual/hyperv/x86_64/hyperv_machdep.c	standard
diff --git a/sys/platform/pc64/include/vmm.h b/sys/platform/pc64/include/vmm.h
deleted file mode 100644
index bb8365fe815..00000000000
--- a/sys/platform/pc64/include/vmm.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MACHINE_VMM_H_
-#define _MACHINE_VMM_H_
-
-#include <sys/vmm.h>
-
-int vmm_vminit(struct vmm_guest_options*);
-int vmm_vmdestroy(void);
-int vmm_vmrun(void);
-int vmm_vm_set_tls_area(void);
-void vmm_lwp_return(struct lwp *lp, struct trapframe *frame);
-void vmm_vm_set_guest_cr3(register_t guest_cr3);
-int vmm_vm_get_gpa(struct proc *p, register_t *gpa, register_t uaddr);
-
-#endif
diff --git a/sys/platform/pc64/vmm/ept.c b/sys/platform/pc64/vmm/ept.c
deleted file mode 100644
index e84dd1cdf3e..00000000000
--- a/sys/platform/pc64/vmm/ept.c
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/systm.h>
-#include <sys/sfbuf.h>
-#include <sys/proc.h>
-#include <sys/thread.h>
-
-#include <machine/pmap.h>
-#include <machine/specialreg.h>
-#include <machine/cpufunc.h>
-#include <machine/vmm.h>
-
-#include <vm/pmap.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-
-#include "vmx.h"
-#include "ept.h"
-#include "vmm_utils.h"
-#include "vmm.h"
-
-static int pmap_pm_flags_ept = 0;
-static int eptp_bits = 0;
-
-int
-vmx_ept_init(void)
-{
-	vmx_ept_vpid_cap = rdmsr(IA32_VMX_EPT_VPID_CAP);
-
-	if (!EPT_PWL4(vmx_ept_vpid_cap) ||
-	    !EPT_MEMORY_TYPE_WB(vmx_ept_vpid_cap)) {
-		return EINVAL;
-	}
-
-	eptp_bits |= EPTP_CACHE(PAT_WRITE_BACK) |
-	    EPTP_PWLEN(EPT_PWLEVELS - 1);
-
-	if (EPT_AD_BITS_SUPPORTED(vmx_ept_vpid_cap)) {
-		eptp_bits |= EPTP_AD_ENABLE;
-	} else {
-		pmap_pm_flags_ept |= PMAP_EMULATE_AD_BITS;
-	}
-
-	return 0;
-}
-
-/* Build the VMCS_EPTP pointer
- * - the ept_address
- * - the EPTP bits indicating optional features
- */
-uint64_t vmx_eptp(uint64_t ept_address)
-{
-	return (ept_address | eptp_bits);
-}
-
-/* Copyin from guest VMM */
-static int
-ept_copyin(const void *udaddr, void *kaddr, size_t len)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-
-	error = 0;
-
-	while (len) {
-		/* Get the GPA by manually walking the-GUEST page table*/
-		error = guest_phys_addr(vm, &gpa, guest_cr3,
-					(vm_offset_t)udaddr);
-		if (error) {
-			kprintf("%s: could not get guest_phys_addr\n",
-				__func__);
-			break;
-		}
-
-		m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-				  VM_PROT_READ, VM_FAULT_NORMAL,
-				  &error, NULL);
-		if (error) {
-			if (vmm_debug) {
-				kprintf("%s: could not fault in "
-					"vm map, gpa: %jx\n",
-					__func__,
-					(uintmax_t)gpa);
-			}
-			break;
-		}
-
-		n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
-		if (n > len)
-			n = len;
-
-		lwb = lwbuf_alloc(m, &lwb_cache);
-		bcopy((char *)lwbuf_kva(lwb) +
-		       ((vm_offset_t)udaddr & PAGE_MASK),
-		      kaddr, n);
-		len -= n;
-		udaddr = (const char *)udaddr + n;
-		kaddr = (char *)kaddr + n;
-		lwbuf_free(lwb);
-		vm_page_unhold(m);
-	}
-	if (error)
-		error = EFAULT;
-	return (error);
-}
-
-/* Copyout from guest VMM */
-static int
-ept_copyout(const void *kaddr, void *udaddr, size_t len)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-
-	error = 0;
-
-	while (len) {
-		int busy;
-
-		/* Get the GPA by manually walking the-GUEST page table*/
-		error = guest_phys_addr(vm, &gpa, guest_cr3,
-					(vm_offset_t)udaddr);
-		if (error) {
-			kprintf("%s: could not get guest_phys_addr\n",
-				__func__);
-			break;
-		}
-
-		m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-				  VM_PROT_READ | VM_PROT_WRITE,
-				  VM_FAULT_NORMAL,
-				  &error, &busy);
-		if (error) {
-			if (vmm_debug) {
-				kprintf("%s: could not fault in vm map, "
-					"gpa: 0x%jx\n",
-					__func__,
-					(uintmax_t)gpa);
-			}
-			break;
-		}
-
-		n = PAGE_SIZE - ((vm_offset_t)udaddr & PAGE_MASK);
-		if (n > len)
-			n = len;
-
-		lwb = lwbuf_alloc(m, &lwb_cache);
-		bcopy(kaddr, (char *)lwbuf_kva(lwb) +
-			     ((vm_offset_t)udaddr & PAGE_MASK), n);
-
-		len -= n;
-		udaddr = (char *)udaddr + n;
-		kaddr = (const char *)kaddr + n;
-		vm_page_dirty(m);
-#if 0
-		/* should not be needed */
-		cpu_invlpg((char *)lwbuf_kva(lwb) +
-			     ((vm_offset_t)udaddr & PAGE_MASK));
-#endif
-		lwbuf_free(lwb);
-		if (busy)
-			vm_page_wakeup(m);
-		else
-			vm_page_unhold(m);
-	}
-	if (error)
-		error = EFAULT;
-	return (error);
-}
-
-static int
-ept_copyinstr(const void *udaddr, void *kaddr, size_t len, size_t *res)
-{
-	int error;
-	size_t n;
-	const char *uptr = udaddr;
-	char *kptr = kaddr;
-
-	if (res)
-		*res = 0;
-	while (len) {
-		n = PAGE_SIZE - ((vm_offset_t)uptr & PAGE_MASK);
-		if (n > 32)
-			n = 32;
-		if (n > len)
-			n = len;
-		if ((error = ept_copyin(uptr, kptr, n)) != 0)
-			return(error);
-		while (n) {
-			if (res)
-				++*res;
-			if (*kptr == 0)
-				return(0);
-			++kptr;
-			++uptr;
-			--n;
-			--len;
-		}
-
-	}
-	return(ENAMETOOLONG);
-}
-
-
-static int
-ept_fubyte(const uint8_t *base)
-{
-	uint8_t c = 0;
-
-	if (ept_copyin(base, &c, 1) == 0)
-		return((int)c);
-	return(-1);
-}
-
-static int
-ept_subyte(uint8_t *base, uint8_t byte)
-{
-	unsigned char c = byte;
-
-	if (ept_copyout(&c, base, 1) == 0)
-		return(0);
-	return(-1);
-}
-
-static int32_t
-ept_fuword32(const uint32_t *base)
-{
-	uint32_t v;
-
-	if (ept_copyin(base, &v, sizeof(v)) == 0)
-		return(v);
-	return(-1);
-}
-
-static int64_t
-ept_fuword64(const uint64_t *base)
-{
-	uint64_t v;
-
-	if (ept_copyin(base, &v, sizeof(v)) == 0)
-		return(v);
-	return(-1);
-}
-
-static int
-ept_suword64(uint64_t *base, uint64_t word)
-{
-	if (ept_copyout(&word, base, sizeof(word)) == 0)
-		return(0);
-	return(-1);
-}
-
-static int
-ept_suword32(uint32_t *base, int word)
-{
-	if (ept_copyout(&word, base, sizeof(word)) == 0)
-		return(0);
-	return(-1);
-}
-
-static uint32_t
-ept_swapu32(volatile uint32_t *uaddr, uint32_t v)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-	volatile void *ptr;
-	int busy;
-
-	/* Get the GPA by manually walking the-GUEST page table*/
-	error = guest_phys_addr(vm, &gpa, guest_cr3, (vm_offset_t)uaddr);
-	if (error) {
-		kprintf("%s: could not get guest_phys_addr\n", __func__);
-		return EFAULT;
-	}
-	m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-			  VM_PROT_READ | VM_PROT_WRITE,
-			  VM_FAULT_NORMAL,
-			  &error, &busy);
-	if (error) {
-		if (vmm_debug) {
-			kprintf("%s: could not fault in vm map, gpa: %llx\n",
-				__func__, (unsigned long long) gpa);
-		}
-		return EFAULT;
-	}
-
-	n = PAGE_SIZE - ((vm_offset_t)uaddr & PAGE_MASK);
-	if (n < sizeof(uint32_t)) {
-		error = EFAULT;
-		v = (uint32_t)-error;
-		goto done;
-	}
-
-	lwb = lwbuf_alloc(m, &lwb_cache);
-	ptr = (void *)(lwbuf_kva(lwb) + ((vm_offset_t)uaddr & PAGE_MASK));
-	v = atomic_swap_int(ptr, v);
-
-	vm_page_dirty(m);
-	lwbuf_free(lwb);
-	error = 0;
-done:
-	if (busy)
-		vm_page_wakeup(m);
-	else
-		vm_page_unhold(m);
-	return v;
-}
-
-static uint64_t
-ept_swapu64(volatile uint64_t *uaddr, uint64_t v)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-	volatile void *ptr;
-	int busy;
-
-	/* Get the GPA by manually walking the-GUEST page table*/
-	error = guest_phys_addr(vm, &gpa, guest_cr3, (vm_offset_t)uaddr);
-	if (error) {
-		kprintf("%s: could not get guest_phys_addr\n", __func__);
-		return EFAULT;
-	}
-	m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-			  VM_PROT_READ | VM_PROT_WRITE,
-			  VM_FAULT_NORMAL,
-			  &error, &busy);
-	if (error) {
-		if (vmm_debug) {
-			kprintf("%s: could not fault in vm map, gpa: %llx\n",
-				__func__, (unsigned long long) gpa);
-		}
-		return EFAULT;
-	}
-
-	n = PAGE_SIZE - ((vm_offset_t)uaddr & PAGE_MASK);
-	if (n < sizeof(uint64_t)) {
-		error = EFAULT;
-		v = (uint64_t)-error;
-		goto done;
-	}
-
-	lwb = lwbuf_alloc(m, &lwb_cache);
-	ptr = (void *)(lwbuf_kva(lwb) + ((vm_offset_t)uaddr & PAGE_MASK));
-	v = atomic_swap_long(ptr, v);
-
-	vm_page_dirty(m);
-	lwbuf_free(lwb);
-	error = 0;
-done:
-	if (busy)
-		vm_page_wakeup(m);
-	else
-		vm_page_unhold(m);
-	return v;
-}
-
-static uint32_t
-ept_fuwordadd32(volatile uint32_t *uaddr, uint32_t v)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-	volatile void *ptr;
-	int busy;
-
-	/* Get the GPA by manually walking the-GUEST page table*/
-	error = guest_phys_addr(vm, &gpa, guest_cr3, (vm_offset_t)uaddr);
-	if (error) {
-		kprintf("%s: could not get guest_phys_addr\n", __func__);
-		return EFAULT;
-	}
-	m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-			  VM_PROT_READ | VM_PROT_WRITE,
-			  VM_FAULT_NORMAL,
-			  &error, &busy);
-	if (error) {
-		if (vmm_debug) {
-			kprintf("%s: could not fault in vm map, gpa: %llx\n",
-				__func__, (unsigned long long) gpa);
-		}
-		return EFAULT;
-	}
-
-	n = PAGE_SIZE - ((vm_offset_t)uaddr & PAGE_MASK);
-	if (n < sizeof(uint32_t)) {
-		error = EFAULT;
-		v = (uint32_t)-error;
-		goto done;
-	}
-
-	lwb = lwbuf_alloc(m, &lwb_cache);
-	ptr = (void *)(lwbuf_kva(lwb) + ((vm_offset_t)uaddr & PAGE_MASK));
-	v = atomic_fetchadd_int(ptr, v);
-
-	vm_page_dirty(m);
-	lwbuf_free(lwb);
-	error = 0;
-done:
-	if (busy)
-		vm_page_wakeup(m);
-	else
-		vm_page_unhold(m);
-	return v;
-}
-
-static uint64_t
-ept_fuwordadd64(volatile uint64_t *uaddr, uint64_t v)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	vm_page_t m;
-	register_t gpa;
-	size_t n;
-	int error;
-	struct vmspace *vm = curproc->p_vmspace;
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	register_t guest_cr3 = vti->guest_cr3;
-	volatile void *ptr;
-	int busy;
-
-	/* Get the GPA by manually walking the-GUEST page table*/
-	error = guest_phys_addr(vm, &gpa, guest_cr3, (vm_offset_t)uaddr);
-	if (error) {
-		kprintf("%s: could not get guest_phys_addr\n", __func__);
-		return EFAULT;
-	}
-	m = vm_fault_page(&vm->vm_map, trunc_page(gpa),
-			  VM_PROT_READ | VM_PROT_WRITE,
-			  VM_FAULT_NORMAL,
-			  &error, &busy);
-	if (error) {
-		if (vmm_debug) {
-			kprintf("%s: could not fault in vm map, gpa: %llx\n",
-				__func__, (unsigned long long) gpa);
-		}
-		return EFAULT;
-	}
-
-	n = PAGE_SIZE - ((vm_offset_t)uaddr & PAGE_MASK);
-	if (n < sizeof(uint64_t)) {
-		error = EFAULT;
-		v = (uint64_t)-error;
-		goto done;
-	}
-
-	lwb = lwbuf_alloc(m, &lwb_cache);
-	ptr = (void *)(lwbuf_kva(lwb) + ((vm_offset_t)uaddr & PAGE_MASK));
-	v = atomic_fetchadd_long(ptr, v);
-
-	vm_page_dirty(m);
-	lwbuf_free(lwb);
-	error = 0;
-done:
-	if (busy)
-		vm_page_wakeup(m);
-	else
-		vm_page_unhold(m);
-	return v;
-}
-
-void
-vmx_ept_pmap_pinit(pmap_t pmap)
-{
-	pmap_ept_transform(pmap, pmap_pm_flags_ept);
-
-	pmap->copyinstr = ept_copyinstr;
-	pmap->copyin = ept_copyin;
-	pmap->copyout = ept_copyout;
-	pmap->fubyte = ept_fubyte;
-	pmap->subyte = ept_subyte;
-	pmap->fuword32 = ept_fuword32;
-	pmap->fuword64 = ept_fuword64;
-	pmap->suword32 = ept_suword32;
-	pmap->suword64 = ept_suword64;
-	pmap->swapu32 = ept_swapu32;
-	pmap->swapu64 = ept_swapu64;
-	pmap->fuwordadd32 = ept_fuwordadd32;
-	pmap->fuwordadd64 = ept_fuwordadd64;
-}
diff --git a/sys/platform/pc64/vmm/ept.h b/sys/platform/pc64/vmm/ept.h
deleted file mode 100644
index 4a2a5d66c22..00000000000
--- a/sys/platform/pc64/vmm/ept.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_EPT_H_
-#define _VMM_EPT_H_
-
-#include <vm/vm.h>
-
-#include <machine/pmap.h>
-
-#define	EPT_PWL4(cap)			((cap) & (1ULL << 6))
-#define	EPT_MEMORY_TYPE_WB(cap)		((cap) & (1ULL << 14))
-#define	EPT_AD_BITS_SUPPORTED(cap)	((cap) & (1ULL << 21))
-#define	EPT_PWLEVELS			(4)	/* page walk levels */
-
-#define	EPTP_CACHE(x)			(x)
-#define	EPTP_PWLEN(x)			((x) << 3)
-#define	EPTP_AD_ENABLE			(0x1ULL << 6)
-
-#define	EPT_VIOLATION_READ		(1ULL << 0)
-#define	EPT_VIOLATION_WRITE		(1ULL << 1)
-#define	EPT_VIOLATION_INST_FETCH	(1ULL << 2)
-#define	EPT_VIOLATION_GPA_READABLE	(1ULL << 3)
-#define	EPT_VIOLATION_GPA_WRITEABLE	(1ULL << 4)
-#define	EPT_VIOLATION_GPA_EXECUTABLE	(1ULL << 5)
-
-#define	INVEPT_TYPE_SINGLE_CONTEXT	1UL
-#define	INVEPT_TYPE_ALL_CONTEXTS	2UL
-
-struct invept_desc {
-	uint64_t	eptp;
-	uint64_t	_res;
-};
-typedef struct invept_desc invept_desc_t;
-
-CTASSERT(sizeof(struct invept_desc) == 16);
-
-int vmx_ept_init(void);
-void vmx_ept_pmap_pinit(pmap_t pmap);
-uint64_t vmx_eptp(uint64_t ept_address);
-
-static __inline int
-vmx_ept_fault_type(uint64_t qualification)
-{
-	if (qualification & EPT_VIOLATION_WRITE)
-		return VM_PROT_WRITE;
-	else if (qualification & EPT_VIOLATION_INST_FETCH)
-		return VM_PROT_EXECUTE;
-	else
-		return VM_PROT_READ;
-}
-
-static __inline int
-vmx_ept_gpa_prot(uint64_t qualification)
-{
-	int prot = 0;
-
-	if (qualification & EPT_VIOLATION_GPA_READABLE)
-		prot |= VM_PROT_READ;
-
-	if (qualification & EPT_VIOLATION_GPA_WRITEABLE)
-		prot |= VM_PROT_WRITE;
-
-	if (qualification & EPT_VIOLATION_GPA_EXECUTABLE)
-		prot |= VM_PROT_EXECUTE;
-
-	return prot;
-}
-
-#endif
diff --git a/sys/platform/pc64/vmm/svm.c b/sys/platform/pc64/vmm/svm.c
deleted file mode 100644
index b07df63480d..00000000000
--- a/sys/platform/pc64/vmm/svm.c
+++ /dev/null
@@ -1,171 +0,0 @@
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/thread.h>
-#include <sys/vmm.h>
-
-#include <vm/pmap.h>
-
-#include <machine/cputypes.h>
-#include <machine/md_var.h>
-#include <machine/specialreg.h>
-
-#include "vmm.h"
-#include "svm.h"
-
-static int svm_available = 0;
-static int svm_enabled = 0;
-
-//static int svm_rvi_available = 0;
-//static int svm_vmcb_caching_available = 0;
-
-static vm_offset_t vm_hsave_va[MAXCPU];
-
-/*
- * svm_init() - Identify AMD SVM support.
- *
- *	Called in early boot. Detects AMD SVM support and extended features.
- */
-static int
-svm_init(void)
-{
-	uint64_t vm_cr;
-
-	/* Not fully implemented and will break vkernel64 bootstrap */
-	return (ENODEV);
-
-	/* SVM is identified by CPUID */
-	if ((amd_feature2 & AMDID2_SVM) == 0)
-		return (ENODEV);
-
-	/* Processor may support SVM, but it may be disabled. */
-	vm_cr = rdmsr(MSR_AMD_VM_CR);
-	if (vm_cr & VM_CR_SVMDIS)
-		return (ENODEV);
-
-	svm_available = 1;
-
-	return (0);
-}
-
-/*
- * svm_enable() - Called to enable SVM extensions on every processor.
- */
-static int
-svm_enable(void)
-{
-	uint64_t efer;
-	int origcpu;
-	int i;
-	vm_paddr_t vm_hsave_pa;
-
-	if (!svm_available)
-		return (ENODEV);
-
-	KKASSERT(svm_enabled == 0);
-
-	/* Set EFER.SVME and allocate a VM Host Save Area on every cpu */
-	origcpu = mycpuid;
-	for (i = 0; i < ncpus; i++) {
-		lwkt_migratecpu(i);
-
-		efer = rdmsr(MSR_EFER);
-		efer |= EFER_SVME;
-		wrmsr(MSR_EFER, efer);
-
-		vm_hsave_va[i] = (vm_offset_t) contigmalloc(4096, M_TEMP,
-							    M_WAITOK | M_ZERO,
-							    0, 0xffffffff,
-							    4096, 0);
-		vm_hsave_pa = vtophys(vm_hsave_va[i]);
-		wrmsr(MSR_AMD_VM_HSAVE_PA, vm_hsave_pa);
-	}
-	lwkt_migratecpu(origcpu);
-
-	svm_enabled = 1;
-
-	return (0);
-}
-
-/*
- * svm_disable() - Called to disable SVM extensions on every processor.
- */
-static int
-svm_disable(void)
-{
-	uint64_t efer;
-	int origcpu;
-	int i;
-
-	/* XXX Wait till no vmms are running? */
-
-	KKASSERT(svm_enabled == 1);
-
-	origcpu = mycpuid;
-	for (i = 0; i < ncpus; i++) {
-		lwkt_migratecpu(i);
-
-		wrmsr(MSR_AMD_VM_HSAVE_PA, 0);
-
-		contigfree((void *) vm_hsave_va[i], 4096, M_TEMP);
-		vm_hsave_va[i] = 0;
-
-		efer = rdmsr(MSR_EFER);
-		efer &= ~EFER_SVME;
-		wrmsr(MSR_EFER, efer);
-	}
-	lwkt_migratecpu(origcpu);
-
-	svm_enabled = 0;
-
-	return (0);
-}
-
-/*
- * svm_vminit() - Prepare current thread for VMRUN.
- *
- *	Allocates a VMCB for the current thread and flags the thread to return
- *	to usermode via svm_vmrun().
- */
-static int
-svm_vminit(struct vmm_guest_options *options)
-{
-	return (ENODEV);
-}
-
-/*
- * svm_vmdestroy() -
- */
-static int
-svm_vmdestroy(void)
-{
-	return (ENODEV);
-}
-
-/*
- * svm_vmrun() - Execute VMRUN on a prepared VMCB for a thread.
- *
- *	Called while a thread is returning to userspace, after being flagged as
- *	a VMM thread. svm_vmrun() continues in a loop around VMRUN/#VMEXIT
- *	handling until we are no longer a VMM thread.
- */
-static int
-svm_vmrun(void)
-{
-	return (ENODEV);
-}
-
-static struct vmm_ctl ctl_svm = {
-	.name = "SVM",
-	.init = svm_init,
-	.enable = svm_enable,
-	.disable = svm_disable,
-	.vminit = svm_vminit,
-	.vmdestroy = svm_vmdestroy,
-	.vmrun = svm_vmrun,
-};
-
-struct vmm_ctl *
-get_ctl_amd(void)
-{
-	return &ctl_svm;
-}
diff --git a/sys/platform/pc64/vmm/svm.h b/sys/platform/pc64/vmm/svm.h
deleted file mode 100644
index 0d61a099441..00000000000
--- a/sys/platform/pc64/vmm/svm.h
+++ /dev/null
@@ -1,90 +0,0 @@
-#ifndef _VMM_SVM_H_
-#define _VMM_SVM_H_
-
-struct vmcb {
-	/* Control Area */
-	uint16_t	vmcb_cr_read;
-	uint16_t	vmcb_cr_write;
-	uint16_t	vmcb_dr_read;
-	uint16_t	vmcb_dr_write;
-	uint32_t	vmcb_exception;
-	uint32_t	vmcb_ctrl1;
-	uint32_t	vmcb_ctrl2;
-	uint8_t		vmcb_unused1[40];
-	uint16_t	vmcb_pause_filter_threshold;
-	uint16_t	vmcb_pause_filter_count;
-	uint64_t	vmcb_iopm_base_pa;
-	uint64_t	vmcb_msrpm_base_pa;
-	uint64_t	vmcb_tsc_offset;
-	uint32_t	vmcb_asid;
-	uint8_t		vmcb_tlb_ctrl;
-	uint8_t		vmcb_unused2[3];
-	uint8_t		vmcb_v_tpr;
-	uint8_t		vmcb_v_irq;
-	/* ... */
-	uint8_t		vmcb_v_intr_vector;
-	uint8_t		vmcb_unused3[3];
-	uint64_t	vmcb_intr_shadow;
-	uint64_t	vmcb_exitcode;
-	uint64_t	vmcb_exitinfo1;
-	uint64_t	vmcb_exitinfo2;
-	uint64_t	vmcb_exitintinfo;
-	uint64_t	vmcb_np_enable;
-	uint8_t		vmcb_unused4[16];
-	uint64_t	vmcb_event_injection;
-	uint64_t	vmcb_n_cr3;
-
-	/* Saved Guest State */
-};
-
-/* SVM Intercept Codes (vmcb_exitcode) */
-#define VMEXIT_CR_READ(_cr)	(0 + (_cr))
-#define VMEXIT_CR_WRITE(_cr)	(16 + (_cr))
-#define VMEXIT_DR_READ(_dr)	(32 + (_dr))
-#define VMEXIT_DR_WRITE(_dr)	(48 + (_dr))
-#define VMEXIT_EXCP(_excp)	(64 + (_excp))
-#define VMEXIT_INTR		96
-#define VMEXIT_NMI		97
-#define VMEXIT_SMI		98
-#define VMEXIT_INIT		99
-#define VMEXIT_VINTR		100
-#define VMEXIT_CR0_SEL_WRITE	101
-#define VMEXIT_IDTR_READ	102
-#define VMEXIT_GDTR_READ	103
-#define VMEXIT_LDTR_READ	104
-#define VMEXIT_TR_READ		105
-#define VMEXIT_IDTR_WRITE	106
-#define VMEXIT_GDTR_WRITE	107
-#define VMEXIT_LDTR_WRITE	108
-#define VMEXIT_TR_WRITE		109
-#define VMEXIT_RDTSC		110
-#define VMEXIT_RDPMC		111
-#define VMEXIT_PUSHF		112
-#define VMEXIT_POPF		113
-#define VMEXIT_CPUID		114
-#define VMEXIT_RSM		115
-#define VMEXIT_IRET		116
-#define VMEXIT_SWINT		117
-#define VMEXIT_INVD		118
-#define VMEXIT_PAUSE		119
-#define VMEXIT_HLT		120
-#define VMEXIT_INVLPG		121
-#define VMEXIT_INVLPGA		122
-#define VMEXIT_IOIO		123
-#define VMEXIT_MSR		124
-#define VMEXIT_TASK_SWITCH	125
-#define VMEXIT_FERR_FREEZE	126
-#define VMEXIT_SHUTDOWN	127
-#define VMEXIT_VMRUN		128
-#define VMEXIT_VMMCALL		129
-#define VMEXIT_VMLOAD		130
-#define VMEXIT_VMSAVE		131
-#define VMEXIT_STGI		132
-#define VMEXIT_CLGI		133
-#define VMEXIT_SKINIT		134
-#define VMEXIT_RDTSCP		135
-#define VMEXIT_ICEBP		137
-#define VMEXIT_NPF		1024
-#define VMEXIT_INVALID		-1
-
-#endif  /* ndef _VMM_SVM_H_ */
diff --git a/sys/platform/pc64/vmm/vmm.c b/sys/platform/pc64/vmm/vmm.c
deleted file mode 100644
index 37f32a7a1bf..00000000000
--- a/sys/platform/pc64/vmm/vmm.c
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/systm.h>
-#include <sys/sysctl.h>
-#include <sys/eventhandler.h>
-#include <sys/proc.h>
-#include <sys/vkernel.h>
-
-#include <machine/vmm.h>
-#include <machine/cputypes.h>
-#include <machine/md_var.h>
-
-#include "vmm.h"
-
-static struct vmm_ctl *ctl = NULL;
-static struct sysctl_ctx_list vmm_sysctl_ctx;
-static int vmm_enabled;
-
-struct sysctl_oid *vmm_sysctl_tree;
-int vmm_debug;
-
-static int
-sysctl_vmm_enable(SYSCTL_HANDLER_ARGS)
-{
-	int error, new_val;
-
-	new_val = vmm_enabled;
-
-	error = sysctl_handle_int(oidp, &new_val, 0, req);
-        if (error != 0 || req->newptr == NULL)
-		return (error);
-
-	if (new_val != 0 && new_val != 1)
-		return (EINVAL);
-
-	if (vmm_enabled != new_val) {
-		if (new_val == 1) {
-			if (ctl->enable()) {
-				kprintf("VMM: vmm enable() failed\n");
-				return (EINVAL);
-			}
-		} else if (new_val == 0) {
-			if (ctl->disable()) {
-				kprintf("VMM: vmm disable() failed\n");
-				return (EINVAL);
-			}
-		}
-	} else {
-		return (EINVAL);
-	}
-
-	vmm_enabled = new_val;
-
-	return (0);
-}
-
-static void
-vmm_shutdown(void)
-{
-	if (vmm_enabled && panicstr == NULL)
-		ctl->disable();
-}
-
-static void
-vmm_init(void)
-{
-	sysctl_ctx_init(&vmm_sysctl_ctx);
-	vmm_sysctl_tree = SYSCTL_ADD_NODE(&vmm_sysctl_ctx,
-	    SYSCTL_STATIC_CHILDREN(_hw),
-	    OID_AUTO, "vmm",
-	    CTLFLAG_RD, 0, "VMM options");
-
-#if 0 /* Disable for now to avoid overload symbols confusing ddb/kgdb. */
-	if (cpu_vendor_id == CPU_VENDOR_INTEL) {
-		ctl = get_ctl_intel();
-	} else if (cpu_vendor_id == CPU_VENDOR_AMD) {
-		ctl = get_ctl_amd();
-	}
-#endif
-
-	if (ctl == NULL || ctl->init()) {
-		SYSCTL_ADD_INT(&vmm_sysctl_ctx,
-		    SYSCTL_CHILDREN(vmm_sysctl_tree),
-		    OID_AUTO, "enable", CTLFLAG_RD,
-		    &vmm_enabled, 0,
-		    "enable not supported");
-	} else {
-		SYSCTL_ADD_STRING(&vmm_sysctl_ctx,
-		    SYSCTL_CHILDREN(vmm_sysctl_tree),
-		    OID_AUTO, "type", CTLFLAG_RD,
-		    ctl->name, 0,
-		    "Type of the VMM");
-		SYSCTL_ADD_PROC(&vmm_sysctl_ctx,
-		    SYSCTL_CHILDREN(vmm_sysctl_tree),
-		    OID_AUTO, "enable", CTLTYPE_INT | CTLFLAG_WR,
-		    NULL, sizeof vmm_enabled, sysctl_vmm_enable, "I",
-		    "Control the state of the VMM");
-		SYSCTL_ADD_INT(&vmm_sysctl_ctx,
-		    SYSCTL_CHILDREN(vmm_sysctl_tree),
-		    OID_AUTO, "debug", CTLTYPE_INT | CTLFLAG_RW,
-		    &vmm_debug, 0,
-		    "vmm debugging");
-
-		/*
-		 * Normally enable VMM if it is supported.  But for now
-		 * lets not, because the vkernel is not stable with it
-		 * enabled.
-		 */
-		if (1) {
-			kprintf("VMM: available, disabled by default\n");
-		} else if (ctl->enable()) {
-			kprintf("VMM: vmm enable() failed\n");
-		} else {
-			vmm_enabled = 1;
-		}
-
-		EVENTHANDLER_REGISTER(shutdown_pre_sync, vmm_shutdown, NULL, SHUTDOWN_PRI_DEFAULT-1);
-	}
-}
-SYSINIT(vmm_init, SI_BOOT2_VMM, SI_ORDER_ANY, vmm_init, NULL);
-
-
-int
-vmm_vminit(struct vmm_guest_options *options)
-{
-	if (!vmm_enabled) {
-		return ENODEV;
-	}
-
-	return ctl->vminit(options);
-}
-
-int
-vmm_vmdestroy(void)
-{
-	if (!vmm_enabled) {
-		return ENODEV;
-	}
-	return ctl->vmdestroy();
-}
-
-int
-vmm_vmrun(void)
-{
-	if (!vmm_enabled) {
-		return ENODEV;
-	}
-	return ctl->vmrun();
-}
-
-int
-vmm_vm_set_tls_area(void)
-{
-	if (!vmm_enabled) {
-		return ENODEV;
-	}
-	return ctl->vm_set_tls_area();
-}
-
-void
-vmm_vm_set_guest_cr3(register_t guest_cr3)
-{
-	ctl->vm_set_guest_cr3(guest_cr3);
-}
-
-void
-vmm_lwp_return(struct lwp *lp, struct trapframe *frame)
-{
-	ctl->vm_lwp_return(lp, frame);
-}
-
-int
-vmm_vm_get_gpa(struct proc *p, register_t *gpa, register_t uaddr)
-{
-	return ctl->vm_get_gpa(p, gpa, uaddr);
-}
diff --git a/sys/platform/pc64/vmm/vmm.h b/sys/platform/pc64/vmm/vmm.h
deleted file mode 100644
index 41413d5cee1..00000000000
--- a/sys/platform/pc64/vmm/vmm.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_VMM_H_
-#define _VMM_VMM_H_
-
-#define MAX_NAME_LEN 256
-
-#include <sys/param.h>
-#include <sys/vmm.h>
-
-#define ERROR_IF(func)					\
-	do {						\
-	if ((err = (func))) {				\
-		kprintf("VMM: %s error at line: %d\n",	\
-		   __func__, __LINE__);			\
-		goto error;				\
-	}						\
-	} while(0)					\
-
-#define ERROR2_IF(func)					\
-	do {						\
-	if ((err = (func))) {				\
-		kprintf("VMM: %s error at line: %d\n",	\
-		   __func__, __LINE__);			\
-		goto error2;				\
-	}						\
-	} while(0)					\
-
-#ifdef VMM_DEBUG
-#define dkprintf(fmt, args...)		kprintf(fmt, ##args)
-#else
-#define dkprintf(fmt, args...)
-#endif
-
-#define INSTRUCTION_MAX_LENGTH		15
-
-struct vmm_ctl {
-	char name[MAX_NAME_LEN];
-	int (*init)(void);
-	int (*enable)(void);
-	int (*disable)(void);
-	int (*vminit)(struct vmm_guest_options *);
-	int (*vmdestroy)(void);
-	int (*vmrun)(void);
-	int (*vm_set_tls_area)(void);
-	void (*vm_lwp_return)(struct lwp *lp, struct trapframe *frame);
-	void (*vm_set_guest_cr3)(register_t);
-	int (*vm_get_gpa)(struct proc *, register_t *, register_t);
-
-
-};
-
-struct vmm_proc {
-	uint64_t	guest_cr3;
-	uint64_t	vmm_cr3;
-};
-
-struct vmm_ctl* get_ctl_intel(void);
-struct vmm_ctl* get_ctl_amd(void);
-
-#ifdef _KERNEL
-
-extern int vmm_debug;
-extern struct sysctl_oid *vmm_sysctl_tree;
-extern uint64_t vmx_ept_vpid_cap;
-
-#endif
-
-#endif
diff --git a/sys/platform/pc64/vmm/vmm_utils.c b/sys/platform/pc64/vmm/vmm_utils.c
deleted file mode 100644
index 9d61a5a84f7..00000000000
--- a/sys/platform/pc64/vmm/vmm_utils.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <cpu/lwbuf.h>
-#include <cpu/pmap.h>
-#include <vm/vm_page.h>
-#include <vm/vm_extern.h>
-
-#include "vmm_utils.h"
-
-#ifdef VMM_DEBUG
-int
-instr_check(struct instr_decode *instr, void *ip, uint8_t instr_length)
-{
-	uint8_t i;
-	uint8_t *instr_ip;
-	uint8_t *instr_opcode;
-
-	instr_ip = (uint8_t *) ip;
-	instr_opcode = (uint8_t *) &instr->opcode;
-
-	/*  Skip REX prefix if present */
-	if (*instr_ip >= 0x40 && *instr_ip <= 0x4F) {
-		instr_ip++;
-		instr_length--;
-	}
-
-	for (i = 0; i < instr->opcode_bytes; i++) {
-		if (i < instr_length) {
-			if (instr_ip[i] != instr_opcode[i]) {
-				return -1;
-			}
-		} else {
-			return -1;
-		}
-	}
-	return 0;
-}
-#endif
-
-static int
-get_pt_entry(struct vmspace *vm, pt_entry_t *pte, vm_offset_t addr, int index)
-{
-	struct lwbuf *lwb;
-	struct lwbuf lwb_cache;
-	pt_entry_t *pt;
-	int error;
-	vm_page_t m;
-
-	error = 0;
-	m = vm_fault_page(&vm->vm_map, trunc_page(addr),
-			  VM_PROT_READ, VM_FAULT_NORMAL,
-			  &error, NULL);
-	if (error) {
-		kprintf("%s: could not get addr %llx\n",
-		    __func__, (unsigned long long)addr);
-		*pte = 0;	/* avoid gcc warnings */
-		goto done;
-	}
-	lwb = lwbuf_alloc(m, &lwb_cache);
-	pt = (pt_entry_t *)lwbuf_kva(lwb) + ((vm_offset_t)addr & PAGE_MASK);
-
-	*pte = pt[index];
-	lwbuf_free(lwb);
-	vm_page_unhold(m);
-done:
-	return error;
-}
-
-int
-guest_phys_addr(struct vmspace *vm, register_t *gpa, register_t guest_cr3,
-		vm_offset_t uaddr)
-{
-	pt_entry_t pml4e;
-	pt_entry_t pdpe;
-	pt_entry_t pde;
-	pt_entry_t pte;
-	int err = 0;
-
-	err = get_pt_entry(vm, &pml4e, guest_cr3, uaddr >> PML4SHIFT);
-	if (err) {
-		kprintf("%s: could not get pml4e\n", __func__);
-		goto error;
-	}
-	if ((pml4e & kernel_pmap->pmap_bits[PG_V_IDX]) == 0) {
-		kprintf("%s: pml4e not valid\n", __func__);
-		err = EFAULT;
-		goto error;
-	}
-
-	err = get_pt_entry(vm, &pdpe, pml4e & PG_FRAME,
-			   (uaddr & PML4MASK) >> PDPSHIFT);
-	if (err) {
-		kprintf("%s: could not get pdpe\n", __func__);
-		goto error;
-	}
-	if ((pdpe & kernel_pmap->pmap_bits[PG_V_IDX]) == 0) {
-		kprintf("%s: pdpe not valid\n", __func__);
-		err = EFAULT;
-		goto error;
-	}
-	if (pdpe & kernel_pmap->pmap_bits[PG_PS_IDX]) {
-		*gpa = (pdpe & PG_FRAME) | (uaddr & PDPMASK);
-		return 0;
-	}
-
-	err = get_pt_entry(vm, &pde, pdpe & PG_FRAME,
-			   (uaddr & PDPMASK) >> PDRSHIFT);
-	if (err) {
-		kprintf("%s: could not get pdpe\n", __func__);
-		goto error;
-	}
-	if ((pde & kernel_pmap->pmap_bits[PG_V_IDX]) == 0) {
-		kprintf("%s: pde not valid\n", __func__);
-		err = EFAULT;
-		goto error;
-	}
-	if (pde & kernel_pmap->pmap_bits[PG_PS_IDX]) {
-		*gpa = (pde & PG_FRAME) | (uaddr & PDRMASK);
-		return 0;
-	}
-
-	err = get_pt_entry(vm, &pte, pde & PG_FRAME,
-			   (uaddr & PDRMASK) >> PAGE_SHIFT);
-	if (err) {
-		kprintf("%s: could not get pte\n", __func__);
-		goto error;
-	}
-	if ((pte & kernel_pmap->pmap_bits[PG_V_IDX]) == 0) {
-		kprintf("%s: pte not valid\n", __func__);
-		err = EFAULT;
-		goto error;
-	}
-	*gpa = (pte & PG_FRAME) | (uaddr & PAGE_MASK);
-	return 0;
-
-error:
-	return err;
-}
diff --git a/sys/platform/pc64/vmm/vmm_utils.h b/sys/platform/pc64/vmm/vmm_utils.h
deleted file mode 100644
index ab3e3fa1014..00000000000
--- a/sys/platform/pc64/vmm/vmm_utils.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_VMM_UTILS_H_
-#define _VMM_VMM_UTILS_H_
-
-#ifdef VMM_DEBUG
-struct instr_decode {
-	uint8_t opcode_bytes;
-	struct {
-		uint8_t byte1;
-		uint8_t byte2;
-		uint8_t byte3;
-	} opcode;
-};
-
-int instr_check(struct instr_decode *instr, void *ip, uint8_t instr_length);
-#endif
-
-int guest_phys_addr(struct vmspace *vm, register_t *gpa, register_t guest_cr3, vm_offset_t uaddr);
-#endif
diff --git a/sys/platform/pc64/vmm/vmx.c b/sys/platform/pc64/vmm/vmx.c
deleted file mode 100644
index 07b555b6269..00000000000
--- a/sys/platform/pc64/vmm/vmx.c
+++ /dev/null
@@ -1,1741 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- * by Matthew Dillon <dillon@backplane.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/malloc.h>
-#include <sys/systm.h>
-#include <sys/thread.h>
-#include <sys/thread2.h>
-#include <sys/sysctl.h>
-#include <sys/vmm.h>
-#include <sys/proc.h>
-#include <sys/syscall.h>
-#include <sys/wait.h>
-#include <sys/vkernel.h>
-#include <ddb/ddb.h>
-
-#include <cpu/cpu.h>
-
-#include <machine/cpufunc.h>
-#include <machine/cputypes.h>
-#include <machine/smp.h>
-#include <machine/globaldata.h>
-#include <machine/trap.h>
-#include <machine/pmap.h>
-#include <machine/md_var.h>
-
-#include <vm/vm_map.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_param.h>
-
-#include "vmm.h"
-#include "vmm_utils.h"
-
-#include "vmx.h"
-#include "vmx_instr.h"
-#include "vmx_vmcs.h"
-
-#include "ept.h"
-
-extern void trap(struct trapframe *frame);
-
-static int vmx_check_cpu_migration(void);
-static int execute_vmptrld(struct vmx_thread_info *vti);
-
-#ifdef VMM_DEBUG
-static struct instr_decode syscall_asm = {
-	.opcode_bytes = 2,
-	.opcode.byte1 = 0x0F,
-	.opcode.byte2 = 0x05,
-};
-#endif
-
-static struct vmx_ctl_info vmx_pinbased = {
-	.msr_addr = IA32_VMX_PINBASED_CTLS,
-	.msr_true_addr = IA32_VMX_TRUE_PINBASED_CTLS,
-};
-
-static struct vmx_ctl_info vmx_procbased = {
-	.msr_addr = IA32_VMX_PROCBASED_CTLS,
-	.msr_true_addr = IA32_VMX_TRUE_PROCBASED_CTLS,
-};
-
-static struct vmx_ctl_info vmx_procbased2 = {
-	.msr_addr = IA32_VMX_PROCBASED_CTLS2,
-	.msr_true_addr = IA32_VMX_PROCBASED_CTLS2,
-};
-
-static struct vmx_ctl_info vmx_exit = {
-	.msr_addr = IA32_VMX_EXIT_CTLS,
-	.msr_true_addr = IA32_VMX_TRUE_EXIT_CTLS,
-};
-
-static struct vmx_ctl_info vmx_entry = {
-	.msr_addr = IA32_VMX_ENTRY_CTLS,
-	.msr_true_addr = IA32_VMX_TRUE_ENTRY_CTLS,
-};
-
-/* SYSCTL tree and context */
-static struct sysctl_oid *vmx_sysctl_tree;
-static struct sysctl_ctx_list vmx_sysctl_ctx;
-
-/* Per cpu info */
-static struct vmx_pcpu_info *pcpu_info;
-
-/* VMX BASIC INFO */
-static uint32_t vmx_revision;
-static uint32_t vmx_region_size;
-static uint8_t vmx_width_addr;
-
-/* IA32_VMX_EPT_VPID_CAP */
-uint64_t vmx_ept_vpid_cap;
-
-/* VMX fixed bits */
-static uint64_t cr0_fixed_to_0;
-static uint64_t cr4_fixed_to_0;
-static uint64_t cr0_fixed_to_1;
-static uint64_t cr4_fixed_to_1;
-
-/* VMX status */
-static uint8_t vmx_enabled = 0;
-static uint8_t vmx_initialized = 0;
-
-/* VMX set control setting
- * Intel System Programming Guide, Part 3, Order Number 326019
- * 31.5.1 Algorithms for Determining VMX Capabilities
- * Implement Algorithm 3
- */
-static int
-vmx_set_ctl_setting(struct vmx_ctl_info *vmx_ctl, uint32_t bit_no, setting_t value) {
-	uint64_t vmx_basic;
-	uint64_t ctl_val;
-
-	/* Check if its branch b. or c. */
-	vmx_basic = rdmsr(IA32_VMX_BASIC);
-	if (IS_TRUE_CTL_AVAIL(vmx_basic))
-		ctl_val = rdmsr(vmx_ctl->msr_true_addr);
-	else
-		ctl_val = rdmsr(vmx_ctl->msr_addr);
-
-	/* Check if the value is known by VMM or set on DEFAULT */
-	switch(value) {
-	case DEFAULT:
-		/*
-		 * Both settings are allowd
-		 * - step b.iii)
-		 *   or
-		 * - c.iii), c.iv)
-		 */
-		if (IS_ZERO_SETTING_ALLOWED(ctl_val, bit_no) &&
-		    IS_ONE_SETTING_ALLOWED(ctl_val, bit_no)) {
-			/* For c.iii) and c.iv) */
-			if (IS_TRUE_CTL_AVAIL(vmx_basic))
-				ctl_val = rdmsr(vmx_ctl->msr_addr);
-
-			if (IS_ZERO_SETTING_ALLOWED(ctl_val, bit_no))
-				vmx_ctl->ctls &= ~BIT(bit_no);
-			else if (IS_ONE_SETTING_ALLOWED(ctl_val, bit_no))
-				vmx_ctl->ctls |= BIT(bit_no);
-		} else if (IS_ZERO_SETTING_ALLOWED(ctl_val, bit_no)) {
-			/* b.i), c.i) */
-			vmx_ctl->ctls &= ~BIT(bit_no);
-		} else if (IS_ONE_SETTING_ALLOWED(ctl_val, bit_no)) {
-			/* b.i), c.i) */
-			vmx_ctl->ctls |= BIT(bit_no);
-		} else {
-			return (EINVAL);
-		}
-		break;
-	case ZERO:
-		/* For b.ii) or c.ii) */
-		if (!IS_ZERO_SETTING_ALLOWED(ctl_val, bit_no))
-			return (EINVAL);
-		vmx_ctl->ctls &= ~BIT(bit_no);
-		break;
-	case ONE:
-		/* For b.ii) or c.ii) */
-		if (!IS_ONE_SETTING_ALLOWED(ctl_val, bit_no))
-			return (EINVAL);
-
-		vmx_ctl->ctls |= BIT(bit_no);
-
-		break;
-	}
-	return 0;
-}
-
-static void
-vmx_set_default_settings(struct vmx_ctl_info *vmx_ctl)
-{
-	int i;
-
-	for (i = 0; i < 32; i++) {
-		vmx_set_ctl_setting(vmx_ctl, i, DEFAULT);
-	}
-}
-
-static void
-alloc_vmxon_regions(void)
-{
-	int cpu;
-
-	pcpu_info = kmalloc(ncpus * sizeof(struct vmx_pcpu_info),
-			    M_TEMP, M_WAITOK | M_ZERO);
-
-	for (cpu = 0; cpu < ncpus; cpu++) {
-
-		/* The address must be aligned to 4K - alloc extra */
-		pcpu_info[cpu].vmxon_region_na = kmalloc(vmx_region_size + VMXON_REGION_ALIGN_SIZE,
-		    M_TEMP,
-		    M_WAITOK | M_ZERO);
-
-		/* Align address */
-		pcpu_info[cpu].vmxon_region = (unsigned char*) VMXON_REGION_ALIGN(pcpu_info[cpu].vmxon_region_na);
-
-		/* In the first 31 bits put the vmx revision*/
-		*((uint32_t *) pcpu_info[cpu].vmxon_region) = vmx_revision;
-	}
-}
-
-static void
-free_vmxon_regions(void)
-{
-	int i;
-
-	for (i = 0; i < ncpus; i++) {
-		pcpu_info[i].vmxon_region = NULL;
-
-		kfree(pcpu_info[i].vmxon_region_na, M_TEMP);
-	}
-
-	kfree(pcpu_info, M_TEMP);
-}
-
-static void
-build_vmx_sysctl(void)
-{
-	sysctl_ctx_init(&vmx_sysctl_ctx);
-	vmx_sysctl_tree = SYSCTL_ADD_NODE(&vmx_sysctl_ctx,
-		    SYSCTL_CHILDREN(vmm_sysctl_tree),
-		    OID_AUTO, "vmx",
-		    CTLFLAG_RD, 0, "VMX options");
-
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "revision", CTLFLAG_RD,
-	    &vmx_revision, 0,
-	    "VMX revision");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "region_size", CTLFLAG_RD,
-	    &vmx_region_size, 0,
-	    "VMX region size");
-	SYSCTL_ADD_INT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "width_addr", CTLFLAG_RD,
-	    &vmx_width_addr, 0,
-	    "VMX width address");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "pinbased_ctls", CTLFLAG_RD,
-	    &vmx_pinbased.ctls, 0,
-	    "VMX pin-based controls");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "procbased_ctls", CTLFLAG_RD,
-	    &vmx_procbased.ctls, 0,
-	    "VMX primary processor-based controls");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "procbased2_ctls", CTLFLAG_RD,
-	    &vmx_procbased2.ctls, 0,
-	    "VMX secondary processor-based controls");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "vmexit_ctls", CTLFLAG_RD,
-	    &vmx_exit.ctls, 0,
-	    "VMX exit controls");
-	SYSCTL_ADD_UINT(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "vmentry_ctls", CTLFLAG_RD,
-	    &vmx_entry.ctls, 0,
-	    "VMX entry controls");
-	SYSCTL_ADD_ULONG(&vmx_sysctl_ctx,
-	    SYSCTL_CHILDREN(vmx_sysctl_tree),
-	    OID_AUTO, "ept_vpid_cap", CTLFLAG_RD,
-	    &vmx_ept_vpid_cap,
-	    "VMX EPT VPID CAP");
-}
-
-
-
-static int
-vmx_init(void)
-{
-	uint64_t feature_control;
-	uint64_t vmx_basic_value;
-	uint64_t cr0_fixed_bits_to_1;
-	uint64_t cr0_fixed_bits_to_0;
-	uint64_t cr4_fixed_bits_to_0;
-	uint64_t cr4_fixed_bits_to_1;
-
-	int err;
-
-
-	/*
-	 * The ability of a processor to support VMX operation
-	 * and related instructions is indicated by:
-	 * CPUID.1:ECX.VMX[bit 5] = 1
-	 */
-	if (!(cpu_feature2 & CPUID2_VMX)) {
-		kprintf("VMM: VMX is not supported by this Intel CPU\n");
-		return (ENODEV);
-	}
-
-	vmx_set_default_settings(&vmx_pinbased);
-
-	vmx_set_default_settings(&vmx_procbased);
-	/* Enable second level for procbased */
-	err = vmx_set_ctl_setting(&vmx_procbased,
-	    PROCBASED_ACTIVATE_SECONDARY_CONTROLS,
-	    ONE);
-	if (err) {
-		kprintf("VMM: PROCBASED_ACTIVATE_SECONDARY_CONTROLS not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-	vmx_set_default_settings(&vmx_procbased2);
-
-	vmx_set_default_settings(&vmx_exit);
-	vmx_set_default_settings(&vmx_entry);
-
-	/* Enable external interrupts exiting */
-	err = vmx_set_ctl_setting(&vmx_pinbased,
-	    PINBASED_EXTERNAL_INTERRUPT_EXITING,
-	    ONE);
-	if (err) {
-		kprintf("VMM: PINBASED_EXTERNAL_INTERRUPT_EXITING not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Enable non-maskable interrupts exiting */
-	err = vmx_set_ctl_setting(&vmx_pinbased, PINBASED_NMI_EXITING, ONE);
-	if (err) {
-		kprintf("VMM: PINBASED_NMI_EXITING not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-
-	/* Set 64bits mode for GUEST */
-	err = vmx_set_ctl_setting(&vmx_entry, VMENTRY_IA32e_MODE_GUEST, ONE);
-	if (err) {
-		kprintf("VMM: VMENTRY_IA32e_MODE_GUEST not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Load MSR EFER on enry */
-	err = vmx_set_ctl_setting(&vmx_entry,
-				  VMENTRY_LOAD_IA32_EFER, ONE);
-	if (err) {
-		kprintf("VMM: VMENTRY_LOAD_IA32_EFER not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Set 64bits mode */
-	err = vmx_set_ctl_setting(&vmx_exit,
-				  VMEXIT_HOST_ADDRESS_SPACE_SIZE, ONE);
-	if (err) {
-		kprintf("VMM: VMEXIT_HOST_ADDRESS_SPACE_SIZE not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Save/Load Efer on exit */
-	err = vmx_set_ctl_setting(&vmx_exit,
-	    VMEXIT_SAVE_IA32_EFER,
-	    ONE);
-	if (err) {
-		kprintf("VMM: VMEXIT_SAVE_IA32_EFER not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Load Efer on exit */
-	err = vmx_set_ctl_setting(&vmx_exit,
-	    VMEXIT_LOAD_IA32_EFER,
-	    ONE);
-	if (err) {
-		kprintf("VMM: VMEXIT_LOAD_IA32_EFER not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	/* Enable EPT feature */
-	err = vmx_set_ctl_setting(&vmx_procbased2,
-	    PROCBASED2_ENABLE_EPT,
-	    ONE);
-	if (err) {
-		kprintf("VMM: PROCBASED2_ENABLE_EPT not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-
-	if (vmx_ept_init()) {
-		kprintf("VMM: vmx_ept_init failed\n");
-		return (ENODEV);
-	}
-#if 0
-	/* XXX - to implement in the feature */
-	/* Enable VPID feature */
-	err = vmx_set_ctl_setting(&vmx_procbased2,
-				  PROCBASED2_ENABLE_VPID,
-				  ONE);
-	if (err) {
-		kprintf("VMM: PROCBASED2_ENABLE_VPID not "
-			"supported by this CPU\n");
-		return (ENODEV);
-	}
-#endif
-
-	/* Check for the feature control status */
-	feature_control = rdmsr(IA32_FEATURE_CONTROL);
-	if (!(feature_control & BIT(FEATURE_CONTROL_LOCKED))) {
-		kprintf("VMM: IA32_FEATURE_CONTROL is not locked\n");
-		return (EINVAL);
-	}
-	if (!(feature_control & BIT(FEATURE_CONTROL_VMX_BIOS_ENABLED))) {
-		kprintf("VMM: VMX is disabled by the BIOS\n");
-		return (EINVAL);
-	}
-
-	vmx_basic_value = rdmsr(IA32_VMX_BASIC);
-	vmx_width_addr = (uint8_t) VMX_WIDTH_ADDR(vmx_basic_value);
-	vmx_region_size = (uint32_t) VMX_REGION_SIZE(vmx_basic_value);
-	vmx_revision = (uint32_t) VMX_REVISION(vmx_basic_value);
-
-	/* A.7 VMX-FIXED BITS IN CR0 */
-	cr0_fixed_bits_to_1 = rdmsr(IA32_VMX_CR0_FIXED0);
-	cr0_fixed_bits_to_0 = rdmsr(IA32_VMX_CR0_FIXED1);
-	cr0_fixed_to_1 = cr0_fixed_bits_to_1 & cr0_fixed_bits_to_0;
-	cr0_fixed_to_0 = ~cr0_fixed_bits_to_1 & ~cr0_fixed_bits_to_0;
-
-	/* A.8 VMX-FIXED BITS IN CR4 */
-	cr4_fixed_bits_to_1 = rdmsr(IA32_VMX_CR4_FIXED0);
-	cr4_fixed_bits_to_0 = rdmsr(IA32_VMX_CR4_FIXED1);
-	cr4_fixed_to_1 = cr4_fixed_bits_to_1 & cr4_fixed_bits_to_0;
-	cr4_fixed_to_0 = ~cr4_fixed_bits_to_1 & ~cr4_fixed_bits_to_0;
-
-	build_vmx_sysctl();
-
-	vmx_initialized = 1;
-	return 0;
-}
-
-static void
-execute_vmxon(void *perr)
-{
-	unsigned char *vmxon_region;
-	int *err = (int*) perr;
-
-	/* A.7 VMX-FIXED BITS IN CR0 */
-	load_cr0((rcr0() | cr0_fixed_to_1) & ~cr0_fixed_to_0);
-
-	/* A.8 VMX-FIXED BITS IN CR4 */
-	load_cr4((rcr4() | cr4_fixed_to_1) & ~cr4_fixed_to_0);
-
-	/* Enable VMX */
-	load_cr4(rcr4() | CR4_VMXE);
-
-	vmxon_region = pcpu_info[mycpuid].vmxon_region;
-	*err = vmxon(vmxon_region);
-	if (*err) {
-		kprintf("VMM: vmxon failed on cpu%d\n", mycpuid);
-	}
-}
-
-static void
-execute_vmxoff(void *dummy)
-{
-	invept_desc_t desc = { 0 };
-
-	if (invept(INVEPT_TYPE_ALL_CONTEXTS, (uint64_t*) &desc)) {
-		kprintf("VMM: execute_vmxoff: "
-			"invet failed on cpu%d\n", mycpu->gd_cpuid);
-	}
-
-	vmxoff();
-
-	/* Disable VMX */
-	load_cr4(rcr4() & ~CR4_VMXE);
-}
-
-static void
-execute_vmclear(void *data)
-{
-	struct vmx_thread_info *vti = data;
-	int err;
-	globaldata_t gd = mycpu;
-
-	/*
-	 * Must set vti->launched to zero after vmclear'ing to
-	 * force a vmlaunch the next time.
-	 *
-	 * Must not clear the loaded_vmx field until after we call
-	 * vmclear on the region.  This field triggers the interlocked
-	 * cpusync from another cpu trying to destroy or reuse
-	 * the vti.  If we clear the field first, the other cpu will
-	 * not interlock and may race our vmclear() on the underlying
-	 * memory.
-	 */
-	if (vti->last_cpu != -1) {
-		invept(INVEPT_TYPE_SINGLE_CONTEXT,
-		       (uint64_t*)&vti->invept_desc);
-		ERROR_IF(vmclear(vti->vmcs_region));
-	}
-error:
-	if (pcpu_info[gd->gd_cpuid].loaded_vmx == vti) {
-		pcpu_info[gd->gd_cpuid].loaded_vmx = NULL;
-	}
-	vti->launched = 0;
-	vti->last_cpu = -1;
-}
-
-static int
-execute_vmptrld(struct vmx_thread_info *vti)
-{
-	struct vmx_thread_info *loaded_vmx;
-	globaldata_t gd = mycpu;
-	int error;
-
-	/*
-	 * Make this the current VMCS.  Must set loaded_vmx field
-	 * before calling vmptrld() to avoid races against cpusync.
-	 *
-	 * Must set vti->launched to zero after the vmptrld to force
-	 * a vmlaunch.
-	 *
-	 * NOTE! We should NOT vmclear the previous vmx, the spec allows
-	 *	 it to remain active (just not current).  vmclear()ing
-	 *	 it would really mess up performance.
-	 */
-	loaded_vmx = pcpu_info[gd->gd_cpuid].loaded_vmx;
-	if (loaded_vmx != vti) {
-#if 0
-		/* this is not needed and messes up performance */
-		if (loaded_vmx)
-			execute_vmclear(loaded_vmx);
-#endif
-		/* current launched state does not change */
-		vti->last_cpu = gd->gd_cpuid;
-		error = vmptrld(vti->vmcs_region);
-		pcpu_info[gd->gd_cpuid].loaded_vmx = vti;
-	} else {
-		error = 0;
-	}
-	return error;
-}
-
-static int
-vmx_enable(void)
-{
-	int err;
-	int cpu;
-
-	if (!vmx_initialized) {
-		kprintf("VMM: vmx_enable - not allowed; vmx not initialized\n");
-		return (EINVAL);
-	}
-
-	if (vmx_enabled) {
-		kprintf("VMM: vmx_enable - already enabled\n");
-		return (EINVAL);
-	}
-
-	alloc_vmxon_regions();
-	for (cpu = 0; cpu < ncpus; cpu++) {
-		cpumask_t mask;
-
-		err = 0;
-		CPUMASK_ASSBIT(mask, cpu);
-		lwkt_cpusync_simple(mask, execute_vmxon, &err);
-		if(err) {
-			kprintf("VMM: vmx_enable error %d on cpu%d\n", err, cpu);
-			return err;
-		}
-	}
-	vmx_enabled = 1;
-	return 0;
-}
-
-static int
-vmx_disable(void)
-{
-	int cpu;
-
-	if (!vmx_enabled) {
-		kprintf("VMM: vmx_disable not allowed; vmx wasn't enabled\n");
-	}
-
-	for (cpu = 0; cpu < ncpus; cpu++) {
-		cpumask_t mask;
-
-		CPUMASK_ASSBIT(mask, cpu);
-		lwkt_cpusync_simple(mask, execute_vmxoff, NULL);
-	}
-
-	free_vmxon_regions();
-
-	vmx_enabled = 0;
-
-	return 0;
-}
-
-static int vmx_set_guest_descriptor(descriptor_t type,
-		uint16_t selector,
-		uint32_t rights,
-		uint64_t base,
-		uint32_t limit)
-{
-	int err;
-	int selector_enc;
-	int rights_enc;
-	int base_enc;
-	int limit_enc;
-
-
-	/*
-	 * Intel Manual Vol 3C. - page 60
-	 * If any bit in the limit field in the range 11:0 is 0, G must be 0.
-	 * If any bit in the limit field in the range 31:20 is 1, G must be 1.
-	 */
-	if ((~rights & VMCS_SEG_UNUSABLE) || (type == CS)) {
-		if ((limit & 0xfff) != 0xfff)
-			rights &= ~VMCS_G;
-		else if ((limit & 0xfff00000) != 0)
-			rights |= VMCS_G;
-	}
-
-	switch(type) {
-	case ES:
-		selector_enc = VMCS_GUEST_ES_SELECTOR;
-		rights_enc = VMCS_GUEST_ES_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_ES_BASE;
-		limit_enc = VMCS_GUEST_ES_LIMIT;
-		break;
-	case CS:
-		selector_enc = VMCS_GUEST_CS_SELECTOR;
-		rights_enc = VMCS_GUEST_CS_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_CS_BASE;
-		limit_enc = VMCS_GUEST_CS_LIMIT;
-		break;
-	case SS:
-		selector_enc = VMCS_GUEST_SS_SELECTOR;
-		rights_enc = VMCS_GUEST_SS_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_SS_BASE;
-		limit_enc = VMCS_GUEST_SS_LIMIT;
-		break;
-	case DS:
-		selector_enc = VMCS_GUEST_DS_SELECTOR;
-		rights_enc = VMCS_GUEST_DS_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_DS_BASE;
-		limit_enc = VMCS_GUEST_DS_LIMIT;
-		break;
-	case FS:
-		selector_enc = VMCS_GUEST_FS_SELECTOR;
-		rights_enc = VMCS_GUEST_FS_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_FS_BASE;
-		limit_enc = VMCS_GUEST_FS_LIMIT;
-		break;
-	case GS:
-		selector_enc = VMCS_GUEST_GS_SELECTOR;
-		rights_enc = VMCS_GUEST_GS_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_GS_BASE;
-		limit_enc = VMCS_GUEST_GS_LIMIT;
-		break;
-	case LDTR:
-		selector_enc = VMCS_GUEST_LDTR_SELECTOR;
-		rights_enc = VMCS_GUEST_LDTR_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_LDTR_BASE;
-		limit_enc = VMCS_GUEST_LDTR_LIMIT;
-		break;
-	case TR:
-		selector_enc = VMCS_GUEST_TR_SELECTOR;
-		rights_enc = VMCS_GUEST_TR_ACCESS_RIGHTS;
-		base_enc = VMCS_GUEST_TR_BASE;
-		limit_enc = VMCS_GUEST_TR_LIMIT;
-		break;
-	default:
-		kprintf("VMM: vmx_set_guest_descriptor: unknown descriptor\n");
-		err = -1;
-		goto error;
-		break;
-	}
-
-	ERROR_IF(vmwrite(selector_enc, selector));
-	ERROR_IF(vmwrite(rights_enc, rights));
-	ERROR_IF(vmwrite(base_enc, base));
-	ERROR_IF(vmwrite(limit_enc, limit));
-
-	return 0;
-error:
-	kprintf("VMM: vmx_set_guest_descriptor failed\n");
-	return err;
-}
-
-/*
- * Called by the first thread of the VMM process
- * - create a new vmspace
- * - init the vmspace with EPT PG_* bits and
- *   EPT copyin/copyout functions
- * - replace the vmspace of the current proc
- * - remove the old vmspace
- */
-static int
-vmx_vminit_master(struct vmm_guest_options *options)
-{
-	struct vmspace *oldvmspace;
-	struct vmspace *newvmspace;
-	struct proc *p = curthread->td_proc;
-	struct vmm_proc *p_vmm;
-
-	oldvmspace = curthread->td_lwp->lwp_vmspace;
-	newvmspace = vmspace_fork(oldvmspace, NULL, NULL);
-
-	vmx_ept_pmap_pinit(vmspace_pmap(newvmspace));
-	bzero(vmspace_pmap(newvmspace)->pm_pml4, PAGE_SIZE);
-
-	lwkt_gettoken(&oldvmspace->vm_map.token);
-	lwkt_gettoken(&newvmspace->vm_map.token);
-
-	pmap_pinit2(vmspace_pmap(newvmspace));
-	pmap_replacevm(curthread->td_proc, newvmspace, 0);
-
-	lwkt_reltoken(&newvmspace->vm_map.token);
-	lwkt_reltoken(&oldvmspace->vm_map.token);
-
-	vmspace_rel(oldvmspace);
-
-	options->vmm_cr3 = vtophys(vmspace_pmap(newvmspace)->pm_pml4);
-
-	p_vmm = kmalloc(sizeof(struct vmm_proc), M_TEMP, M_WAITOK | M_ZERO);
-	p_vmm->guest_cr3 = options->guest_cr3;
-	p_vmm->vmm_cr3 = options->vmm_cr3;
-	p->p_vmm = (void *)p_vmm;
-
-	if (p->p_vkernel) {
-		p->p_vkernel->vkernel_cr3 = options->guest_cr3;
-		dkprintf("PROCESS CR3 %016jx\n", (intmax_t)options->guest_cr3);
-	}
-
-	return 0;
-}
-
-static int
-vmx_vminit(struct vmm_guest_options *options)
-{
-	struct vmx_thread_info *vti;
-	struct vmx_thread_info *loaded_vmx;
-	struct tls_info guest_fs = curthread->td_tls.info[0];
-	struct tls_info guest_gs = curthread->td_tls.info[1];
-	globaldata_t gd;
-	int err;
-
-	vti = kmalloc(sizeof(*vti), M_TEMP, M_WAITOK | M_ZERO);
-	curthread->td_vmm = (void *)vti;
-
-	if (options->master) {
-		vmx_vminit_master(options);
-	}
-
-	bcopy(&options->tf, &vti->guest, sizeof(struct trapframe));
-
-	/*
-	 * Be sure we return success if the VMM hook enters
-	 */
-	vti->guest.tf_rax = 0;
-	vti->guest.tf_rflags &= ~PSL_C;
-
-	vti->vmcs_region_na = kmalloc(vmx_region_size + VMXON_REGION_ALIGN_SIZE,
-				      M_TEMP, M_WAITOK | M_ZERO);
-
-	/* Align address */
-	vti->vmcs_region = (unsigned char*)VMXON_REGION_ALIGN(vti->vmcs_region_na);
-	vti->last_cpu = -1;
-
-	vti->guest_cr3 = options->guest_cr3;
-	vti->vmm_cr3 = options->vmm_cr3;
-
-	/* In the first 31 bits put the vmx revision */
-	*((uint32_t *)vti->vmcs_region) = vmx_revision;
-
-	/*
-	 * Clear the currenetly loaded vmx, if any, so
-	 * we can initialize a new one right now.
-	 */
-	loaded_vmx = pcpu_info[mycpu->gd_cpuid].loaded_vmx;
-	if (loaded_vmx)
-		execute_vmclear(loaded_vmx);
-
-	/*
-	 * vmclear the vmcs to initialize it.
-	 */
-	crit_enter();
-
-	ERROR_IF(vmclear(vti->vmcs_region));
-	ERROR_IF(execute_vmptrld(vti));
-
-	/* Load the VMX controls */
-	ERROR_IF(vmwrite(VMCS_PINBASED_CTLS, vmx_pinbased.ctls));
-	ERROR_IF(vmwrite(VMCS_PROCBASED_CTLS, vmx_procbased.ctls));
-	ERROR_IF(vmwrite(VMCS_PROCBASED2_CTLS, vmx_procbased2.ctls));
-	ERROR_IF(vmwrite(VMCS_VMEXIT_CTLS, vmx_exit.ctls));
-	ERROR_IF(vmwrite(VMCS_VMENTRY_CTLS, vmx_entry.ctls));
-
-	/*
-	 * Load HOST CRs
-	 */
-	ERROR_IF(vmwrite(VMCS_HOST_CR0, rcr0() & ~CR0_TS));
-	ERROR_IF(vmwrite(VMCS_HOST_CR4, rcr4()));
-
-	/* Load HOST EFER and PAT */
-//	ERROR_IF(vmwrite(VMCS_HOST_IA32_PAT, rdmsr(MSR_PAT)));
-	ERROR_IF(vmwrite(VMCS_HOST_IA32_EFER, rdmsr(MSR_EFER)));
-
-	/* Load HOST selectors */
-	ERROR_IF(vmwrite(VMCS_HOST_ES_SELECTOR, GSEL(GDATA_SEL, SEL_KPL)));
-	ERROR_IF(vmwrite(VMCS_HOST_SS_SELECTOR, GSEL(GDATA_SEL, SEL_KPL)));
-	ERROR_IF(vmwrite(VMCS_HOST_FS_SELECTOR, GSEL(GDATA_SEL, SEL_KPL)));
-	ERROR_IF(vmwrite(VMCS_HOST_GS_SELECTOR, GSEL(GDATA_SEL, SEL_KPL)));
-	ERROR_IF(vmwrite(VMCS_HOST_CS_SELECTOR, GSEL(GCODE_SEL, SEL_KPL)));
-	ERROR_IF(vmwrite(VMCS_HOST_TR_SELECTOR, GSEL(GPROC0_SEL, SEL_KPL)));
-
-	/*
-	 * The BASE addresses are written on each VMRUN in case
-	 * the CPU changes because are per-CPU values
-	 */
-
-	/*
-	 * Call vmx_vmexit on VM_EXIT condition
-	 * The RSP will point to the vmx_thread_info
-	 */
-	ERROR_IF(vmwrite(VMCS_HOST_RIP, (uint64_t) vmx_vmexit));
-	ERROR_IF(vmwrite(VMCS_HOST_RSP, (uint64_t) vti));
-	ERROR_IF(vmwrite(VMCS_HOST_CR3, (uint64_t) KPML4phys));
-
-	/*
-	 * GUEST initialization
-	 * - set the descriptors according the conditions from Intel
-	 *   manual "26.3.1.2 Checks on Guest Segment Registers
-	 * - set the privilege to SEL_UPL (the vkernel will run
-	 *   in userspace context)
-	 */
-	ERROR_IF(vmx_set_guest_descriptor(ES, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    0, 0));
-
-	ERROR_IF(vmx_set_guest_descriptor(SS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    0, 0));
-
-	ERROR_IF(vmx_set_guest_descriptor(DS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    0, 0));
-
-	ERROR_IF(vmx_set_guest_descriptor(FS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    (uint64_t) guest_fs.base, (uint32_t) guest_fs.size));
-
-	ERROR_IF(vmx_set_guest_descriptor(GS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    (uint64_t) guest_gs.base, (uint32_t) guest_gs.size));
-
-	ERROR_IF(vmx_set_guest_descriptor(CS, GSEL(GUCODE_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(11) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P | VMCS_L,
-	    0, 0));
-
-	ERROR_IF(vmx_set_guest_descriptor(TR, GSEL(GPROC0_SEL, SEL_UPL),
-			VMCS_SEG_TYPE(11) | VMCS_P,
-			0, 0));
-
-	ERROR_IF(vmx_set_guest_descriptor(LDTR, 0, VMCS_SEG_UNUSABLE, 0, 0));
-
-	/* Set the CR0/CR4 registers, removing the unsupported bits */
-	vti->guest_cr0 = (CR0_PE | CR0_PG | cr0_fixed_to_1) & ~cr0_fixed_to_0;
-	ERROR_IF(vmwrite(VMCS_GUEST_CR0, vti->guest_cr0));
-	ERROR_IF(vmwrite(VMCS_GUEST_CR4, (CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT |
-	    CR4_OSXSAVE | cr4_fixed_to_1) & ~cr4_fixed_to_0));
-
-	/* Don't set EFER_SCE for catching "syscall" instructions */
-	ERROR_IF(vmwrite(VMCS_GUEST_IA32_EFER, (EFER_LME | EFER_LMA)));
-
-	vti->guest.tf_rflags = PSL_I | 0x02;
-	ERROR_IF(vmwrite(VMCS_GUEST_RFLAGS, vti->guest.tf_rflags));
-
-	/* The Guest CR3 indicating CR3 pagetable */
-	ERROR_IF(vmwrite(VMCS_GUEST_CR3, (uint64_t) vti->guest_cr3));
-
-	/* Throw all possible exceptions */
-	ERROR_IF(vmwrite(VMCS_EXCEPTION_BITMAP,(uint64_t) 0xFFFFFFFF));
-
-	/* Guest RIP and RSP */
-	ERROR_IF(vmwrite(VMCS_GUEST_RIP, options->tf.tf_rip));
-	ERROR_IF(vmwrite(VMCS_GUEST_RSP, options->tf.tf_rsp));
-
-	/*
-	 * This field is included for future expansion.
-	 * Software should set this field to FFFFFFFF_FFFFFFFFH
-	 * to avoid VM-entry failures (see Section 26.3.1.5).
-	 */
-	ERROR_IF(vmwrite(VMCS_LINK_POINTER, ~0ULL));
-
-	/*
-	 * The pointer to the EPT pagetable
-	 */
-	ERROR_IF(vmwrite(VMCS_EPTP, vmx_eptp(vti->vmm_cr3)));
-
-	/*
-	 * pcpu fields.  These change if the vti migrates between host
-	 * cpus.  Since we've already set vti->last_cpu, we must also
-	 * initialize the pcpu fields.
-	 */
-	gd = mycpu;
-	ERROR_IF(vmwrite(VMCS_HOST_GS_BASE, (uint64_t)gd));
-	ERROR_IF(vmwrite(VMCS_HOST_TR_BASE, (uint64_t)&gd->gd_prvspace->common_tss));
-
-	ERROR_IF(vmwrite(VMCS_HOST_GDTR_BASE, (uint64_t)&gdt[gd->gd_cpuid * NGDT]));
-	ERROR_IF(vmwrite(VMCS_HOST_IDTR_BASE, (uint64_t)r_idt_arr[gd->gd_cpuid].rd_base));
-
-	ERROR_IF(vmwrite(VMCS_GUEST_GDTR_BASE, (uint64_t)&gdt[gd->gd_cpuid * NGDT]));
-	ERROR_IF(vmwrite(VMCS_GUEST_GDTR_LIMIT, (uint64_t)(NGDT * sizeof(gdt[0]) - 1)));
-
-	/*
-	 * Finally, the ept descriptor.
-	 */
-	vti->invept_desc.eptp = vmx_eptp(vti->vmm_cr3);
-
-	crit_exit();
-
-	return 0;
-error:
-	crit_exit();
-
-	kprintf("VMM: vmx_vminit failed\n");
-	execute_vmclear(vti);
-
-	kfree(vti->vmcs_region_na, M_TEMP);
-	kfree(vti, M_TEMP);
-
-	return err;
-}
-
-/*
- * Destroy a context.  Make sure the context has been cleared and that
- * no TLB translations are stlil cached for its EPT.
- */
-static int
-vmx_vmdestroy(void)
-{
-	struct vmx_thread_info *vti = curthread->td_vmm;
-	struct proc *p = curproc;
-	int error = -1;
-
-	if (vti != NULL) {
-		vmx_check_cpu_migration();
-		execute_vmclear(vti);
-		invept(INVEPT_TYPE_SINGLE_CONTEXT,
-		       (uint64_t*)&vti->invept_desc);
-
-		if (vti->vmcs_region_na != NULL) {
-			kfree(vti->vmcs_region_na, M_TEMP);
-			error = 0;
-		}
-
-		curthread->td_vmm = NULL;
-		kfree(vti, M_TEMP);
-
-		lwkt_gettoken(&p->p_token);
-		if (p->p_nthreads == 1) {
-			kfree(p->p_vmm, M_TEMP);
-			p->p_vmm = NULL;
-		}
-		lwkt_reltoken(&p->p_token);
-	}
-	return error;
-}
-
-/*
- * Checks if we migrated to another cpu
- *
- * No locks are required
- */
-static int
-vmx_check_cpu_migration(void)
-{
-	struct vmx_thread_info *vti;
-	struct globaldata *gd;
-	cpumask_t mask;
-	int err;
-
-	gd = mycpu;
-	vti = (struct vmx_thread_info *)curthread->td_vmm;
-	ERROR_IF(vti == NULL);
-
-	if (vti->last_cpu != -1 && vti->last_cpu != gd->gd_cpuid) {
-		/*
-		 * Clear the context on the remote cpu if it is still
-		 * holding it (can race, we check again in the callback).
-		 */
-		CPUMASK_ASSBIT(mask, vti->last_cpu);
-		lwkt_cpusync_simple(mask, execute_vmclear, (void *)vti);
-
-		/*
-		 * Remote cpu may have raced us, we must make sure that
-		 * any reads were not reordered before the check.
-		 */
-		cpu_lfence();
-	}
-	return 0;
-error:
-	kprintf("VMM: vmx_check_cpu_migration failed\n");
-	return err;
-}
-
-/* Handle CPU migration
- *
- * We have to enter with interrupts disabled/critical section
- * to be sure that another VMCS won't steel our CPU.
- */
-static inline int
-vmx_handle_cpu_migration(void)
-{
-	struct vmx_thread_info *vti;
-	struct globaldata *gd;
-	int err;
-
-	gd = mycpu;
-	vti = (struct vmx_thread_info *)curthread->td_vmm;
-	ERROR_IF(vti == NULL);
-
-	if (vti->last_cpu != gd->gd_cpuid) {
-		/*
-		 * We need to synchronize the per-cpu fields after changing
-		 * cpus.  Also make sure there are no stale EPT translations
-		 * cached.
-		 */
-		dkprintf("VMM: vmx_handle_cpu_migration init per CPU data\n");
-
-		ERROR_IF(execute_vmptrld(vti));
-
-		invept(INVEPT_TYPE_SINGLE_CONTEXT,
-		       (uint64_t*)&vti->invept_desc);
-
-		/* Host related registers */
-		ERROR_IF(vmwrite(VMCS_HOST_GS_BASE, (uint64_t) gd)); /* mycpu points to %gs:0 */
-		ERROR_IF(vmwrite(VMCS_HOST_TR_BASE, (uint64_t) &gd->gd_prvspace->common_tss));
-
-		ERROR_IF(vmwrite(VMCS_HOST_GDTR_BASE, (uint64_t) &gdt[gd->gd_cpuid * NGDT]));
-		ERROR_IF(vmwrite(VMCS_HOST_IDTR_BASE, (uint64_t) r_idt_arr[gd->gd_cpuid].rd_base));
-
-		/* Guest related register */
-		ERROR_IF(vmwrite(VMCS_GUEST_GDTR_BASE, (uint64_t) &gdt[gd->gd_cpuid * NGDT]));
-		ERROR_IF(vmwrite(VMCS_GUEST_GDTR_LIMIT, (uint64_t) (NGDT * sizeof(gdt[0]) - 1)));
-	} else if (pcpu_info[gd->gd_cpuid].loaded_vmx != vti) {
-		/*
-		 * We only need to vmptrld
-		 */
-		dkprintf("VMM: vmx_handle_cpu_migration: vmcs is not loaded\n");
-
-		ERROR_IF(execute_vmptrld(vti));
-	} /* else we don't need to do anything */
-	return 0;
-error:
-	kprintf("VMM: vmx_handle_cpu_migration failed\n");
-	return err;
-}
-
-/*
- * Load information about VMexit
- *
- * We still are with interrupts disabled/critical secion
- * because we must operate with the VMCS on the CPU
- */
-static inline int
-vmx_vmexit_loadinfo(void)
-{
-	struct vmx_thread_info *vti;
-	int err;
-
-	vti = (struct vmx_thread_info *) curthread->td_vmm;
-	ERROR_IF(vti == NULL);
-
-	ERROR_IF(vmread(VMCS_VMEXIT_REASON, &vti->vmexit_reason));
-	ERROR_IF(vmread(VMCS_EXIT_QUALIFICATION, &vti->vmexit_qualification));
-	ERROR_IF(vmread(VMCS_VMEXIT_INTERRUPTION_INFO, &vti->vmexit_interruption_info));
-	ERROR_IF(vmread(VMCS_VMEXIT_INTERRUPTION_ERROR, &vti->vmexit_interruption_error));
-	ERROR_IF(vmread(VMCS_VMEXIT_INSTRUCTION_LENGTH, &vti->vmexit_instruction_length));
-	ERROR_IF(vmread(VMCS_GUEST_PHYSICAL_ADDRESS, &vti->guest_physical_address));
-	ERROR_IF(vmread(VMCS_GUEST_RIP, &vti->guest.tf_rip));
-	ERROR_IF(vmread(VMCS_GUEST_CS_SELECTOR, &vti->guest.tf_cs));
-	ERROR_IF(vmread(VMCS_GUEST_RFLAGS, &vti->guest.tf_rflags));
-	ERROR_IF(vmread(VMCS_GUEST_RSP, &vti->guest.tf_rsp));
-	ERROR_IF(vmread(VMCS_GUEST_SS_SELECTOR, &vti->guest.tf_ss));
-
-	return 0;
-error:
-	kprintf("VMM: vmx_vmexit_loadinfo failed\n");
-	return err;
-}
-
-
-static int
-vmx_set_tls_area(void)
-{
-	struct tls_info *guest_fs = &curthread->td_tls.info[0];
-	struct tls_info *guest_gs = &curthread->td_tls.info[1];
-
-	int err;
-
-	dkprintf("VMM: vmx_set_tls_area hook\n");
-
-	crit_enter();
-
-	ERROR_IF(vmx_check_cpu_migration());
-	ERROR_IF(vmx_handle_cpu_migration());
-
-	/* set %fs */
-	ERROR_IF(vmx_set_guest_descriptor(FS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    (uint64_t) guest_fs->base, (uint32_t) guest_fs->size));
-
-	/* set %gs */
-	ERROR_IF(vmx_set_guest_descriptor(GS, GSEL(GUDATA_SEL, SEL_UPL),
-	    VMCS_SEG_TYPE(3) | VMCS_S | VMCS_DPL(SEL_UPL) | VMCS_P,
-	    (uint64_t) guest_gs->base, (uint32_t) guest_gs->size));
-
-	crit_exit();
-	return 0;
-
-error:
-	crit_exit();
-	return err;
-}
-
-
-static int
-vmx_handle_vmexit(void)
-{
-	struct vmx_thread_info *vti;
-	int exit_reason;
-	int exception_type;
-	int exception_number;
-	int err;
-	int func, regs[4];
-	int rv;
-	int fault_type = VM_PROT_NONE;
-	int fault_flags = 0;
-	struct lwp *lp = curthread->td_lwp;
-
-	dkprintf("VMM: handle_vmx_vmexit\n");
-	vti = (struct vmx_thread_info *) curthread->td_vmm;
-	ERROR_IF(vti == NULL);
-
-	exit_reason = VMCS_BASIC_EXIT_REASON(vti->vmexit_reason);
-	switch (exit_reason) {
-	case EXIT_REASON_EXCEPTION:
-		dkprintf("VMM: handle_vmx_vmexit: "
-			 "EXIT_REASON_EXCEPTION with qualification "
-			 "%llx, interruption info %llx, "
-			 "interruption error %llx, instruction "
-			 "length %llx\n",
-			 (long long) vti->vmexit_qualification,
-			 (long long) vti->vmexit_interruption_info,
-			 (long long) vti->vmexit_interruption_error,
-			 (long long) vti->vmexit_instruction_length);
-
-		dkprintf("VMM: handle_vmx_vmexit: rax: %llx, rip: %llx, "
-			 "rsp: %llx,  rdi: %llx, "
-			 "rsi: %llx, %d, "
-			 "vti: %p, master: %p\n",
-			 (long long)vti->guest.tf_rax,
-			 (long long)vti->guest.tf_rip,
-			 (long long)vti->guest.tf_rsp,
-			 (long long)vti->guest.tf_rdi,
-			 (long long)vti->guest.tf_rsi,
-			 exit_reason, vti, curproc->p_vmm);
-
-		exception_type =
-			VMCS_EXCEPTION_TYPE(vti->vmexit_interruption_info);
-		exception_number =
-			VMCS_EXCEPTION_NUMBER(vti->vmexit_interruption_info);
-
-		if (exception_type == VMCS_EXCEPTION_HARDWARE) {
-			switch (exception_number) {
-			case IDT_UD:
-				/*
-				 * Disabled "syscall" instruction and
-				 * now we catch it for execution
-				 */
-				dkprintf("VMM: handle_vmx_vmexit: "
-					 "VMCS_EXCEPTION_HARDWARE IDT_UD\n");
-#ifdef VMM_DEBUG
-				/* Check to see if its syscall asm instuction */
-				uint8_t instr[INSTRUCTION_MAX_LENGTH];
-				if (copyin((const void *)vti->guest.tf_rip,
-					   instr,
-					   vti->vmexit_instruction_length) &&
-				    instr_check(&syscall_asm,(void *)instr,
-						(uint8_t)vti->vmexit_instruction_length)) {
-					kprintf("VMM: handle_vmx_vmexit: "
-						"UD different from syscall: ");
-					db_disasm((db_addr_t)instr, FALSE, NULL);
-				}
-#endif
-				/* Called to force a VMEXIT and invalidate TLB */
-				if (vti->guest.tf_rax == -1) {
-					vti->guest.tf_rip +=
-						vti->vmexit_instruction_length;
-					break;
-				}
-
-				vti->guest.tf_err = 2;
-				vti->guest.tf_trapno = T_FAST_SYSCALL;
-				vti->guest.tf_xflags = 0;
-
-				vti->guest.tf_rip +=
-					vti->vmexit_instruction_length;
-
-				syscall2(&vti->guest);
-				break;
-			case IDT_PF:
-				dkprintf("VMM: handle_vmx_vmexit: "
-					 "VMCS_EXCEPTION_HARDWARE IDT_PF "
-					 "at %llx\n",
-					 (long long) vti->guest.tf_rip);
-
-				vti->guest.tf_err =
-					vti->vmexit_interruption_error;
-				vti->guest.tf_addr =
-					vti->vmexit_qualification;
-				vti->guest.tf_xflags = 0;
-				vti->guest.tf_trapno = T_PAGEFLT;
-
-				/*
-				 * If we are a user process in the vkernel
-				 * pass the PF to the vkernel and will trigger
-				 * the user_trap()
-				 *
-				 * If we are the vkernel, send a SIGSEGV signal
-				 * to us that will trigger the execution of
-				 * kern_trap()
-				 *
-				 */
-				if (lp->lwp_vkernel && lp->lwp_vkernel->ve) {
-					vkernel_trap(lp, &vti->guest);
-				} else {
-					trapsignal(lp, SIGSEGV, SEGV_MAPERR);
-				}
-				break;
-			case IDT_NM:
-				vti->guest.tf_err =
-					vti->vmexit_interruption_error;
-				vti->guest.tf_addr =
-					vti->vmexit_qualification;
-				vti->guest.tf_xflags = 0;
-				vti->guest.tf_trapno = T_DNA;
-				if (lp->lwp_vkernel && lp->lwp_vkernel->ve) {
-					vkernel_trap(lp, &vti->guest);
-				} else {
-					/* XXX */
-				}
-				break;
-			default:
-				kprintf("VMM: handle_vmx_vmexit: "
-					"VMCS_EXCEPTION_HARDWARE unknown "
-					"number %d rip: %llx, rsp: %llx\n",
-					exception_number,
-					(long long)vti->guest.tf_rip,
-					(long long)vti->guest.tf_rsp);
-				err = -1;
-				goto error;
-			}
-		} else if (exception_type == VMCS_EXCEPTION_SOFTWARE) {
-			switch (exception_number) {
-			case 3:
-				dkprintf("VMM: handle_vmx_vmexit: "
-					 "VMCS_EXCEPTION_SOFTWARE "
-					 "number %d rip: %llx, rsp: %llx\n",
-					 exception_number,
-					 (long long)vti->guest.tf_rip,
-					 (long long)vti->guest.tf_rsp);
-
-				vti->guest.tf_trapno = T_BPTFLT;
-				vti->guest.tf_xflags = 0;
-				vti->guest.tf_err = 0;
-				vti->guest.tf_addr = 0;
-
-				vti->guest.tf_rip +=
-					vti->vmexit_instruction_length;
-
-				trap(&vti->guest);
-				break;
-			default:
-				kprintf("VMM: handle_vmx_vmexit: "
-					"VMCS_EXCEPTION_SOFTWARE unknown "
-					"number %d rip: %llx, rsp: %llx\n",
-					exception_number,
-					(long long)vti->guest.tf_rip,
-					(long long)vti->guest.tf_rsp);
-				err = -1;
-				goto error;
-			}
-		} else {
-			kprintf("VMM: handle_vmx_vmexit: "
-				"VMCS_EXCEPTION_ %d unknown\n",
-				exception_type);
-			err = -1;
-			goto error;
-		}
-		break;
-	case EXIT_REASON_EXT_INTR:
-		dkprintf("VMM: handle_vmx_vmexit: EXIT_REASON_EXT_INTR\n");
-		break;
-	case EXIT_REASON_CPUID:
-		dkprintf("VMM: handle_vmx_vmexit: EXIT_REASON_CPUID\n");
-
-		/*
-		 * Execute CPUID instruction and pass
-		 * the result to the vkernel
-		 */
-		func = vti->guest.tf_rax;
-		do_cpuid(func, regs);
-
-		vti->guest.tf_rax = regs[0];
-		vti->guest.tf_rbx = regs[1];
-		vti->guest.tf_rcx = regs[2];
-		vti->guest.tf_rdx = regs[3];
-
-		vti->guest.tf_rip += vti->vmexit_instruction_length;
-
-		break;
-	case EXIT_REASON_EPT_FAULT:
-		/*
-		 * EPT_FAULT are resolved like normal PFs. Nothing special
-		 * - get the fault type
-		 * - get the fault address (which is a GPA)
-		 * - execute vm_fault on the vm_map
-		 */
-		dkprintf("VMM: handle_vmx_vmexit: "
-			 "EXIT_REASON_EPT_FAULT with qualification %lld,"
-			 "GPA: %llx, fault_Type: %d\n",
-			 (long long)vti->vmexit_qualification,
-			 (unsigned long long)vti->guest_physical_address,
-			 fault_type);
-
-		fault_type = vmx_ept_fault_type(vti->vmexit_qualification);
-
-		if (fault_type & VM_PROT_WRITE)
-			fault_flags = VM_FAULT_DIRTY;
-		else
-			fault_flags = VM_FAULT_NORMAL;
-
-		rv = vm_fault(&curthread->td_lwp->lwp_vmspace->vm_map,
-			      trunc_page(vti->guest_physical_address),
-			      fault_type, fault_flags);
-
-		if (rv != KERN_SUCCESS) {
-			kprintf("VMM: handle_vmx_vmexit: "
-				"EXIT_REASON_EPT_FAULT couldn't resolve %jx\n",
-				(intmax_t)vti->guest_physical_address);
-			err = -1;
-			goto error;
-		}
-		break;
-	default:
-		kprintf("VMM: handle_vmx_vmexit: "
-			"unknown exit reason: %d with qualification %lld\n",
-			exit_reason,
-			(long long)vti->vmexit_qualification);
-		err = -1;
-		goto error;
-	}
-	return 0;
-error:
-	return err;
-}
-
-static int
-vmx_vmrun(void)
-{
-	struct vmx_thread_info *vti;
-	struct globaldata *gd;
-	int err;
-	int ret;
-	int sticks = 0;
-	uint64_t val;
-	cpulock_t olock;
-	cpulock_t nlock;
-	struct trapframe *save_frame;
-	thread_t td = curthread;
-
-	vti = (struct vmx_thread_info *)td->td_vmm;
-	save_frame = td->td_lwp->lwp_md.md_regs;
-	td->td_lwp->lwp_md.md_regs = &vti->guest;
-restart:
-	lwkt_user_yield();
-	crit_enter();
-
-	/*
-	 * The userexit can change the cpu we are running on.
-	 */
-	trap_handle_userexit(&vti->guest, sticks);
-	gd = mycpu;
-
-	ERROR2_IF(vmx_check_cpu_migration());
-	ERROR2_IF(vmx_handle_cpu_migration());
-
-	/*
-	 * Make the state safe to VMENTER
-	 * - disable interrupts and check if there were any pending
-	 * - check for ASTFLTs
-	 * - loop again until there are no ASTFLTs
-	 */
-	cpu_disable_intr();
-	if (gd->gd_reqflags & RQF_AST_MASK) {
-		atomic_clear_int(&gd->gd_reqflags, RQF_AST_SIGNAL);
-		cpu_enable_intr();
-		crit_exit();
-		vti->guest.tf_trapno = T_ASTFLT;
-		trap(&vti->guest);
-		/* CURRENT CPU CAN CHANGE */
-		goto restart;
-	}
-
-	/*
-	 * shouldn't be possible - REMOVE ME
-	 */
-	if (vti->last_cpu != gd->gd_cpuid) {
-		cpu_enable_intr();
-		crit_exit();
-		kprintf("VMM: vmx_vmrun: vti unexpectedly "
-			"changed cpus %d->%d\n",
-			gd->gd_cpuid, vti->last_cpu);
-		goto restart;
-	}
-
-	/*
-	 * Add us to the list of cpus running vkernel operations, interlock
-	 * against anyone trying to do an invalidation.
-	 *
-	 * We must set the cpumask first to ensure that we interlock another
-	 * cpu that may desire to IPI us after we have successfully
-	 * incremented the cpulock counter.
-	 */
-	ATOMIC_CPUMASK_ORBIT(td->td_proc->p_vmm_cpumask, gd->gd_cpuid);
-
-        for (;;) {
-		olock = td->td_proc->p_vmm_cpulock;
-		cpu_ccfence();
-		if ((olock & CPULOCK_EXCL) == 0) {
-			nlock = olock + CPULOCK_INCR;
-			if (atomic_cmpset_int(&td->td_proc->p_vmm_cpulock,
-					      olock, nlock)) {
-				/* fast path */
-				break;
-			}
-			/* cmpset race */
-			cpu_pause();
-			continue;
-		}
-
-		/*
-		 * More complex, another thread has locked the VMM
-		 * (probably to do an EPT invalidation).  We have to
-		 * sleep or busy-wait until it is no longer locked.
-		 *
-		 * NOTE: For now we busy wait.  Sleeping messes up
-		 *	 performance when the vkernel has to synchronize
-		 *	 multiple cpu threads.  The thread will still
-		 *	 be subject to its user process priority.
-		 */
-		ATOMIC_CPUMASK_NANDBIT(td->td_proc->p_vmm_cpumask,
-				       gd->gd_cpuid);
-		cpu_enable_intr();
-#if 0
-		tsleep_interlock(&td->td_proc->p_vmm_cpulock, 0);
-		if (td->td_proc->p_vmm_cpulock & CPULOCK_EXCL) {
-			tsleep(&td->td_proc->p_vmm_cpulock, PINTERLOCKED,
-			       "vmminvl", hz);
-		}
-#endif
-		crit_exit();
-		goto restart;
-	}
-
-	/*
-	 * Load specific Guest registers
-	 * GP registers will be loaded in vmx_launch/resume
-	 */
-	ERROR_IF(vmwrite(VMCS_GUEST_RIP, vti->guest.tf_rip));
-	ERROR_IF(vmwrite(VMCS_GUEST_CS_SELECTOR, vti->guest.tf_cs));
-	ERROR_IF(vmwrite(VMCS_GUEST_RFLAGS, vti->guest.tf_rflags));
-	ERROR_IF(vmwrite(VMCS_GUEST_RSP, vti->guest.tf_rsp));
-	ERROR_IF(vmwrite(VMCS_GUEST_SS_SELECTOR, vti->guest.tf_ss));
-	ERROR_IF(vmwrite(VMCS_GUEST_CR3, (uint64_t) vti->guest_cr3));
-
-	if (vti->guest.tf_xflags & PGEX_FPFAULT) {
-		if ((vti->guest_cr0 & CR0_TS) == 0) {
-			vti->guest_cr0 |= CR0_TS;
-			ERROR_IF(vmwrite(VMCS_GUEST_CR0,
-					 (uint64_t)vti->guest_cr0));
-		}
-	} else {
-		if (vti->guest_cr0 & CR0_TS) {
-			vti->guest_cr0 &= ~(long)CR0_TS;
-			ERROR_IF(vmwrite(VMCS_GUEST_CR0,
-					 (uint64_t)vti->guest_cr0));
-		}
-
-		/*
-		 * Make sure the correct FPU state is loaded for the guest.
-		 *
-		 * HOST_CR0 always clears CR0_TS so make sure this matches
-		 * regardless of the guest_cr0.
-		 */
-		if (mdcpu->gd_npxthread != td) {
-			if (mdcpu->gd_npxthread)
-				npxsave(mdcpu->gd_npxthread->td_savefpu);
-			npxdna();
-		}
-	}
-
-	/*
-	 * The kernel caches the MSR_FSBASE value in mdcpu->gd_user_fs.
-	 * A vmexit loads this unconditionally from the VMCS so make
-	 * sure it loads the correct value.
-	 */
-	ERROR_IF(vmwrite(VMCS_HOST_FS_BASE, mdcpu->gd_user_fs));
-
-	/*
-	 * EPT mappings can't be invalidated with normal invlpg/invltlb
-	 * instructions. We have to execute a special instruction that
-	 * invalidates all EPT cache ("invept").
-	 *
-	 * pm_invgen it's a generation number which is incremented in
-	 * pmap_inval_smp*(), before doing any invalidates.  This will
-	 * cause all CPUs thaat are using the EPT to VMEXIT and wait for
-	 * the interlock to complete.  When they VMENTER they will see that
-	 * the generation number had changed from their current and do a
-	 * invept.
-	 */
-	if (vti->eptgen != td->td_proc->p_vmspace->vm_pmap.pm_invgen) {
-		vti->eptgen = td->td_proc->p_vmspace->vm_pmap.pm_invgen;
-
-		ERROR_IF(invept(INVEPT_TYPE_SINGLE_CONTEXT,
-				(uint64_t*)&vti->invept_desc));
-	}
-
-	gd->gd_flags |= GDF_VIRTUSER;
-	if (vti->launched) {
-		/*
-		 * vmresume called from vmx_trap.s
-		 */
-		dkprintf("\n\nVMM: vmx_vmrun: vmx_resume\n");
-		ret = vmx_resume(vti);
-	} else {
-		/*
-		 * vmlaunch called from vmx_trap.s
-		 */
-		dkprintf("\n\nVMM: vmx_vmrun: vmx_launch\n");
-		vti->launched = 1;
-		ret = vmx_launch(vti);
-	}
-
-	/*
-	 * This is our return point from the vmlaunch/vmresume
-	 * There are two situations:
-	 *
-	 * - The vmlaunch/vmresume executed successfully and they
-	 *   would return through "vmx_vmexit" which will restore
-	 *   the state (registers) and return here with the ret
-	 *   set to VM_EXIT (ret is actually %rax)
-	 *
-	 * - The vmlaunch/vmresume failed to execute and will return
-	 *   immediately with ret set to the error code
-	 */
-	if (ret == VM_EXIT) {
-		ERROR_IF(vmx_vmexit_loadinfo());
-
-		ATOMIC_CPUMASK_NANDBIT(td->td_proc->p_vmm_cpumask,
-				       gd->gd_cpuid);
-		atomic_add_int(&td->td_proc->p_vmm_cpulock,
-			       -CPULOCK_INCR);
-		/* WARNING: don't adjust cpulock twice! */
-
-		cpu_enable_intr();
-		trap_handle_userenter(td);
-		sticks = td->td_sticks;
-
-		crit_exit();
-		/* processing pending before clearing VIRTUSER */
-		gd->gd_flags &= ~GDF_VIRTUSER;
-
-		/*
-		 * Handle the VMEXIT reason
-		 * - if not successful, we exit
-		 * - otherwise we loop up and VMENTER again
-		 *
-		 * NOTE: current cpu can change (e.g. vmexit reason is
-		 *	 syscall by vkernel kernel to run a vkernel user
-		 *	 thread).
-		 */
-		if (vmx_handle_vmexit())
-			goto done;
-
-		/*
-		 * We handled the VMEXIT reason and continue with
-		 * VM execution
-		 */
-		goto restart;
-	} else {
-		vti->launched = 0;
-
-		/*
-		 * Two types of error:
-		 * - VM_FAIL_VALID - the host state was ok,
-		 *   but probably the guest state was not
-		 * - VM_FAIL_INVALID - the parameters or the host state
-		 *   was not ok
-		 */
-		if (ret == VM_FAIL_VALID) {
-			vmread(VMCS_INSTR_ERR, &val);
-			err = (int) val;
-			kprintf("VMM: vmx_vmrun: vmenter failed with "
-				"VM_FAIL_VALID, error code %d\n",
-				err);
-		} else {
-			kprintf("VMM: vmx_vmrun: vmenter failed with "
-				"VM_FAIL_INVALID\n");
-		}
-		goto error;
-	}
-done:
-	kprintf("VMM: vmx_vmrun: returning with success\n");
-	return 0;
-	/* NOT REACHED */
-
-error:
-	ATOMIC_CPUMASK_NANDBIT(td->td_proc->p_vmm_cpumask, gd->gd_cpuid);
-	atomic_add_int(&td->td_proc->p_vmm_cpulock, -CPULOCK_INCR);
-	cpu_enable_intr();
-
-error2:
-	trap_handle_userenter(td);
-	td->td_lwp->lwp_md.md_regs = save_frame;
-	KKASSERT(CPUMASK_TESTMASK(td->td_proc->p_vmm_cpumask,
-				  gd->gd_cpumask) == 0);
-	/*atomic_clear_cpumask(&td->td_proc->p_vmm_cpumask, gd->gd_cpumask);*/
-
-	crit_exit();
-	/* processing pending before clearing VIRTUSER */
-	gd->gd_flags &= ~GDF_VIRTUSER;
-	kprintf("VMM: vmx_vmrun failed\n");
-
-	return err;
-}
-
-/*
- * Called when returning to user-space
- * after executing lwp_fork.
- */
-static void
-vmx_lwp_return(struct lwp *lp, struct trapframe *frame)
-{
-	struct vmm_guest_options options;
-	int vmrun_err;
-	struct vmm_proc *p_vmm = (struct vmm_proc *)curproc->p_vmm;
-
-	dkprintf("VMM: vmx_lwp_return \n");
-
-	bzero(&options, sizeof(struct vmm_guest_options));
-
-	bcopy(frame, &options.tf, sizeof(struct trapframe));
-
-	options.guest_cr3 = p_vmm->guest_cr3;
-	options.vmm_cr3 = p_vmm->vmm_cr3;
-
-	vmx_vminit(&options);
-	generic_lwp_return(lp, frame);
-
-	vmrun_err = vmx_vmrun();
-
-	exit1(W_EXITCODE(vmrun_err, 0));
-}
-
-static void
-vmx_set_guest_cr3(register_t guest_cr3)
-{
-	struct vmx_thread_info *vti = (struct vmx_thread_info *) curthread->td_vmm;
-	vti->guest_cr3 = guest_cr3;
-}
-
-static int
-vmx_vm_get_gpa(struct proc *p, register_t *gpa, register_t uaddr)
-{
-	return guest_phys_addr(p->p_vmspace, gpa, p->p_vkernel->vkernel_cr3, uaddr);
-}
-
-static struct vmm_ctl ctl_vmx = {
-	.name = "VMX from Intel",
-	.init = vmx_init,
-	.enable = vmx_enable,
-	.disable = vmx_disable,
-	.vminit = vmx_vminit,
-	.vmdestroy = vmx_vmdestroy,
-	.vmrun = vmx_vmrun,
-	.vm_set_tls_area = vmx_set_tls_area,
-	.vm_lwp_return = vmx_lwp_return,
-	.vm_set_guest_cr3 = vmx_set_guest_cr3,
-	.vm_get_gpa = vmx_vm_get_gpa,
-};
-
-struct vmm_ctl*
-get_ctl_intel(void)
-{
-	return &ctl_vmx;
-}
diff --git a/sys/platform/pc64/vmm/vmx.h b/sys/platform/pc64/vmm/vmx.h
deleted file mode 100644
index fc3200bed4a..00000000000
--- a/sys/platform/pc64/vmm/vmx.h
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_VMX_H_
-#define _VMM_VMX_H_
-
-#include <machine/pmap.h>
-
-#include "ept.h"
-
-#define BIT(x)	(1ULL << x)
-
-
-/* VMX info for a generic control */
-struct vmx_ctl_info {
-	uint32_t msr_addr;
-	uint32_t msr_true_addr;
-	uint32_t ctls;
-};
-
-/* The value of a setting */
-typedef enum {
-	ZERO,
-	ONE,
-	DEFAULT
-} setting_t;
-
-/* VMX per cpu info */
-struct vmx_pcpu_info {
-	unsigned char *vmxon_region_na;
-	unsigned char *vmxon_region;
-	struct vmx_thread_info *loaded_vmx;
-};
-
-struct vmx_thread_info {
-	unsigned char *vmcs_region_na;
-	unsigned char *vmcs_region;
-
-	int launched;	/* vmclear or vmptrld called, must use vmlaunch */
-	int last_cpu;	/* per-cpu info cached in VMCS for this cpu */
-
-	/* Guest unsaved registers in VMCS */
-	struct trapframe guest; /* put them directly in trapframe */
-	/*union savefpu	guest_fpu; FUTURE */
-	register_t	guest_cr2;
-
-	/* Host unsaved registers in VMCS */
-	register_t	host_rbx;
-	register_t	host_rbp;
-	register_t	host_r10;
-	register_t	host_r11;
-	register_t	host_r12;
-	register_t	host_r13;
-	register_t	host_r14;
-	register_t	host_r15;
-	register_t	host_rsp;
-	uint64_t	vmexit_reason;
-	uint64_t	vmexit_qualification;
-	uint64_t	vmexit_interruption_info;
-	uint64_t	vmexit_interruption_error;
-	uint64_t	vmexit_instruction_length;
-	uint64_t	guest_physical_address;
-
-	uint64_t	guest_cr0;
-	uint64_t	guest_cr3;
-	uint64_t	vmm_cr3;
-	invept_desc_t	invept_desc;
-	long		eptgen;
-};
-
-typedef enum {
-	ES,
-	CS,
-	SS,
-	DS,
-	FS,
-	GS,
-	LDTR,
-	TR
-} descriptor_t;
-
-int vmx_launch(struct vmx_thread_info *);
-int vmx_resume(struct vmx_thread_info *);
-void vmx_vmexit(void);
-
-
-
-/*
- * MSR register address
- */
-#define		IA32_FEATURE_CONTROL			0x3A
-#define		IA32_VMX_BASIC				0x480
-#define		IA32_VMX_PINBASED_CTLS			0x481
-#define		IA32_VMX_PROCBASED_CTLS			0x482
-#define		IA32_VMX_EXIT_CTLS			0x483
-#define		IA32_VMX_ENTRY_CTLS			0x484
-#define		IA32_VMX_CR0_FIXED0			0x486
-#define		IA32_VMX_CR0_FIXED1			0x487
-#define		IA32_VMX_CR4_FIXED0			0x488
-#define		IA32_VMX_CR4_FIXED1			0x489
-#define		IA32_VMX_EPT_VPID_CAP			0x48C
-#define		IA32_VMX_PROCBASED_CTLS2		0x48B
-#define		IA32_VMX_TRUE_PINBASED_CTLS		0x48D
-#define		IA32_VMX_TRUE_PROCBASED_CTLS		0x48E
-#define		IA32_VMX_TRUE_EXIT_CTLS			0x48F
-#define		IA32_VMX_TRUE_ENTRY_CTLS		0x490
-
-
-
-/*
- * IA32 FEATURE CONTROL bits
- */
-#define		FEATURE_CONTROL_LOCKED			0
-#define		FEATURE_CONTROL_VMX_BIOS_ENABLED	2
-
-
-
-/*
- * IA32_VMX_BASIC
- * A.1 BASIC VMX INFORMATION
- */
-#define		IS_TRUE_CTL_AVAIL(VMX_BASIC)	((VMX_BASIC) & (1ULL << (55)))
-#define		VMX_REVISION(reg_val)		(reg_val & 0x7fffffff) /* 0:30 */
-#define 	VMX_REGION_SIZE(reg_val)	((reg_val >> 32) & 0x01fff) /* 32:44 */
-#define 	VMX_WIDTH_ADDR(reg_val)		(reg_val >> 48 & 0x1) /* 48 */
-#define		VMXON_REGION_ALIGN_SIZE		4096ULL
-#define		VMXON_REGION_ALIGN(p)		rounddown2((unsigned long long)(p) + VMXON_REGION_ALIGN_SIZE, VMXON_REGION_ALIGN_SIZE)
-
-
-
-/*
- * Pin-Based VM-Execution Controls
- * Table 24-5. Definitions of Pin-Based Controls
- * */
-#define		PINBASED_EXTERNAL_INTERRUPT_EXITING	0
-#define		PINBASED_NMI_EXITING			3
-#define		PINBASED_VIRTUAL_NMIS			5
-#define		PINBASED_ACTIVATE_VMX_PREEMPTION_TIEMR	6
-#define		PINBASED_PROCESS_POSTED_INTERRUPTS	7
-
-
-
-/*
- * Processor-Based VM-Execution Controls
- * Table 24-6. Definitions of Primary Processor-Based Controls
- */
-#define		PROCBASED_INTERRUPT_WINDOW_EXITING	2
-#define		PROCBASED_USE_TSC_OFFSETING		3
-#define		PROCBASED_HLT_OFFSETING			7
-#define		PROCBASED_INVLPG_EXITING		9
-#define		PROCBASED_MWAIT_EXITING			10
-#define		PROCBASED_RDPMC_EXITING			11
-#define		PROCBASED_RDTSC_EXITING			12
-#define		PROCBASED_CR3_LOAD_EXITING		15
-#define		PROCBASED_CR3_STORE_EXITING		16
-#define		PROCBASED_CR8_LOAD_EXITING		19
-#define		PROCBASED_CR8_STORE_EXITING		20
-#define		PROCBASED_USE_TPR_SHADOW		21
-#define		PROCBASED_NMI_WINDOWS_EXITING		22
-#define		PROCBASED_MOV_DR_EXITING		23
-#define		PROCBASED_UNCOND_IO_EXITING		24
-#define		PROCBASED_USE_IO_BITMAPS		25
-#define		PROCBASED_MONITOR_TRAP_FLAG		27
-#define		PROCBASED_USE_MSR_BITMAPS		28
-#define		PROCBASED_MONITOR_EXITING		29
-#define		PROCBASED_PAUSE_EXITING			30
-#define		PROCBASED_ACTIVATE_SECONDARY_CONTROLS	31
-/* Table 24-7. Definitions of Secondary Processor-Based Controls */
-#define		PROCBASED2_VIRTUALIZE_APIC_ACCESSES	0
-#define		PROCBASED2_ENABLE_EPT			1
-#define		PROCBASED2_DESCRIPTOR_TABLE_EXITING	2
-#define		PROCBASED2_ENABLE_RDTSCP		3
-#define		PROCBASED2_VIRTUAL_x2APIC_MODE		4
-#define		PROCBASED2_ENABLE_VPID			5
-#define		PROCBASED2_WBINVD_EXITING		6
-#define		PROCBASED2_UNRESTRICTED_GUEST		7
-#define		PROCBASED2_APIC_REGISTER_VIRTULIZATION	8
-#define		PROCBASED2_VIRTUAL_INTERRUPT_DELIVERY	9
-#define		PROCBASED2_PAUSE_LOOP_EXITING		10
-#define		PROCBASED2_RDRAND_EXITING		11
-#define		PROCBASED2_ENABLE_INVPCID		12
-#define		PROCBASED2_ENABLE_VM_FUNCTIONS		13
-#define		PROCBASED2_VMCS_SHADOWING		14
-#define		PROCBASED2_EPT_VIOLATION_VE		18
-
-
-
-/*
- * VM-EXIT CONTROL FIELDS
- * Table 24-10. Definitions of VM-Exit Controls
- */
-#define		VMEXIT_SAVE_DEBUG_CONTROLS		2
-#define		VMEXIT_HOST_ADDRESS_SPACE_SIZE		9
-#define		VMEXIT_LOAD_IA32_PERF_GLOBAL_CTRL	12
-#define		VMEXIT_ACKNOWLEDGE_INTERRUPT_ON_EXIT	15
-#define		VMEXIT_SAVE_IA32_PAT			18
-#define		VMEXIT_LOAD_IA32_PAT			19
-#define		VMEXIT_SAVE_IA32_EFER			20
-#define		VMEXIT_LOAD_IA32_EFER			21
-#define		VMEXIT_SAVE_VMX_PREEMPTION_TIMER	22
-
-
-
-/*
- * VM-ENTRY CONTROL FIELDS
- * Table 24-12. Definitions of VM-Entry Controls
- */
-#define		VMENTRY_LOAD_DEBUG_CONTROLS		2
-#define		VMENTRY_IA32e_MODE_GUEST		9
-#define		VMENTRY_ENTRY_TO_SMM			10
-#define		VMENTRY_DEACTIVATE_DUAL_MONITOR		11
-#define		VMENTRY_LOAD_IA32_PERF_GLOBAL_CTRL	13
-#define		VMENTRY_LOAD_IA32_PAT			14
-#define		VMENTRY_LOAD_IA32_EFER			15
-
-
-
-#define IS_ONE_SETTING_ALLOWED(val, bit)	\
-    ((val) & (1ULL << (bit + 32)))
-
-#define IS_ZERO_SETTING_ALLOWED(val, bit)	\
-    (((val) & (1ULL << (bit))) == 0)
-
-
-
-/*
- * VMX Basic Exit Reasons
- */
-#define		EXIT_REASON_EXCEPTION		0
-#define		EXIT_REASON_EXT_INTR		1
-#define		EXIT_REASON_TRIPLE_FAULT	2
-#define		EXIT_REASON_INIT		3
-#define		EXIT_REASON_SIPI		4
-#define		EXIT_REASON_IO_SMI		5
-#define		EXIT_REASON_SMI			6
-#define		EXIT_REASON_INTR_WINDOW		7
-#define		EXIT_REASON_NMI_WINDOW		8
-#define		EXIT_REASON_TASK_SWITCH		9
-#define		EXIT_REASON_CPUID		10
-#define		EXIT_REASON_GETSEC		11
-#define		EXIT_REASON_HLT			12
-#define		EXIT_REASON_INVD		13
-#define		EXIT_REASON_INVLPG		14
-#define		EXIT_REASON_RDPMC		15
-#define		EXIT_REASON_RDTSC		16
-#define		EXIT_REASON_RSM			17
-#define		EXIT_REASON_VMCALL		18
-#define		EXIT_REASON_VMCLEAR		19
-#define		EXIT_REASON_VMLAUNCH		20
-#define		EXIT_REASON_VMPTRLD		21
-#define		EXIT_REASON_VMPTRST		22
-#define		EXIT_REASON_VMREAD		23
-#define		EXIT_REASON_VMRESUME		24
-#define		EXIT_REASON_VMWRITE		25
-#define		EXIT_REASON_VMXOFF		26
-#define		EXIT_REASON_VMXON		27
-#define		EXIT_REASON_CR_ACCESS		28
-#define		EXIT_REASON_DR_ACCESS		29
-#define		EXIT_REASON_INOUT		30
-#define		EXIT_REASON_RDMSR		31
-#define		EXIT_REASON_WRMSR		32
-#define		EXIT_REASON_INVAL_VMCS		33
-#define		EXIT_REASON_INVAL_MSR		34
-#define		EXIT_REASON_MWAIT		36
-#define		EXIT_REASON_MTF			37
-#define		EXIT_REASON_MONITOR		39
-#define		EXIT_REASON_PAUSE		40
-#define		EXIT_REASON_MCE			41
-#define		EXIT_REASON_TPR			43
-#define		EXIT_REASON_APIC		44
-#define		EXIT_REASON_GDTR_IDTR		46
-#define		EXIT_REASON_LDTR_TR		47
-#define		EXIT_REASON_EPT_FAULT		48
-#define		EXIT_REASON_EPT_MISCONFIG	49
-#define		EXIT_REASON_INVEPT		50
-#define		EXIT_REASON_RDTSCP		51
-#define		EXIT_REASON_VMX_PREEMPT		52
-#define		EXIT_REASON_INVVPID		53
-#define		EXIT_REASON_WBINVD		54
-#define		EXIT_REASON_XSETBV		55
-#define		EXIT_REASON_APIC_WRITE		56
-#define		EXIT_REASON_RDRAND		57
-#define		EXIT_REASON_INVPCID		58
-#define		EXIT_REASON_VMFUNC		59
-
-/* Table 24-2. Format of Access Rights */
-#define		VMCS_SEG_TYPE(x)	(x)
-#define		VMCS_S			(1 << 4)	/* Descriptor type - 0 = system; 1 = code or data */
-#define		VMCS_DPL(x)		(x << 5)	/* Descriptor Privilege Level */
-#define		VMCS_P			(1 << 7)	/* Segment present*/
-#define		VMCS_AVL		(1 << 12)	/* Available for use by system software */
-#define		VMCS_L			(1 << 13)	/* 64-bit mode active (for CS only) */
-#define		VMCS_OP_SIZE		(1 << 14)	/* Default operation size (0 = 16-bit segment; 1 = 32-bit segment) */
-#define		VMCS_G			(1 << 15)	/* Granularity */
-#define		VMCS_SEG_UNUSABLE	(1 << 16)	/* Segment unusable (0 = usable; 1 = unusable) */
-
-#define	VMCS_EXCEPTION_TYPE(x)			((x >> 8) & 0x7)
-#define	VMCS_EXCEPTION_EXTERNAL_INTERRUPT	0
-#define	VMCS_EXCEPTION_NMI			2
-#define	VMCS_EXCEPTION_HARDWARE			3
-#define	VMCS_EXCEPTION_SOFTWARE			6
-
-#define	VMCS_EXCEPTION_NUMBER(x)		(x & 0xFF)
-#endif
diff --git a/sys/platform/pc64/vmm/vmx_genassym.c b/sys/platform/pc64/vmm/vmx_genassym.c
deleted file mode 100644
index 274e19f57b5..00000000000
--- a/sys/platform/pc64/vmm/vmx_genassym.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/assym.h>
-
-#include "vmx.h"
-#include "vmx_instr.h"
-
-ASSYM(VTI_GUEST_RAX, offsetof(struct vmx_thread_info, guest.tf_rax));
-ASSYM(VTI_GUEST_RBX, offsetof(struct vmx_thread_info, guest.tf_rbx));
-ASSYM(VTI_GUEST_RCX, offsetof(struct vmx_thread_info, guest.tf_rcx));
-ASSYM(VTI_GUEST_RDX, offsetof(struct vmx_thread_info, guest.tf_rdx));
-ASSYM(VTI_GUEST_RSI, offsetof(struct vmx_thread_info, guest.tf_rsi));
-ASSYM(VTI_GUEST_RDI, offsetof(struct vmx_thread_info, guest.tf_rdi));
-ASSYM(VTI_GUEST_RBP, offsetof(struct vmx_thread_info, guest.tf_rbp));
-ASSYM(VTI_GUEST_R8, offsetof(struct vmx_thread_info, guest.tf_r8));
-ASSYM(VTI_GUEST_R9, offsetof(struct vmx_thread_info, guest.tf_r9));
-ASSYM(VTI_GUEST_R10, offsetof(struct vmx_thread_info, guest.tf_r10));
-ASSYM(VTI_GUEST_R11, offsetof(struct vmx_thread_info, guest.tf_r11));
-ASSYM(VTI_GUEST_R12, offsetof(struct vmx_thread_info, guest.tf_r12));
-ASSYM(VTI_GUEST_R13, offsetof(struct vmx_thread_info, guest.tf_r13));
-ASSYM(VTI_GUEST_R14, offsetof(struct vmx_thread_info, guest.tf_r14));
-ASSYM(VTI_GUEST_R15, offsetof(struct vmx_thread_info, guest.tf_r15));
-ASSYM(VTI_GUEST_CR2, offsetof(struct vmx_thread_info, guest_cr2));
-
-ASSYM(VTI_HOST_RBX, offsetof(struct vmx_thread_info, host_rbx));
-ASSYM(VTI_HOST_RBP, offsetof(struct vmx_thread_info, host_rbp));
-ASSYM(VTI_HOST_R10, offsetof(struct vmx_thread_info, host_r10));
-ASSYM(VTI_HOST_R11, offsetof(struct vmx_thread_info, host_r11));
-ASSYM(VTI_HOST_R12, offsetof(struct vmx_thread_info, host_r12));
-ASSYM(VTI_HOST_R13, offsetof(struct vmx_thread_info, host_r13));
-ASSYM(VTI_HOST_R14, offsetof(struct vmx_thread_info, host_r14));
-ASSYM(VTI_HOST_R15, offsetof(struct vmx_thread_info, host_r15));
-ASSYM(VTI_HOST_RSP, offsetof(struct vmx_thread_info, host_rsp));
-
-ASSYM(VM_SUCCEED, VM_SUCCEED);
-ASSYM(VM_FAIL_INVALID, VM_FAIL_INVALID);
-ASSYM(VM_FAIL_VALID, VM_FAIL_VALID);
-ASSYM(VM_EXIT, VM_EXIT);
diff --git a/sys/platform/pc64/vmm/vmx_instr.h b/sys/platform/pc64/vmm/vmx_instr.h
deleted file mode 100644
index 04d63ff7c98..00000000000
--- a/sys/platform/pc64/vmm/vmx_instr.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_VMX_INSTR_H_
-#define _VMM_VMX_INSTR_H_
-
-#include <vm/pmap.h>
-
-/*
- * Chapter 30 VMX Instruction Reference
- * Section 30.3 "Conventions"
- * from Intel Architecture Manual 3C.
- */
-#define	VM_SUCCEED		0
-#define	VM_FAIL_INVALID		1
-#define	VM_FAIL_VALID		2
-#define	VM_EXIT			3
-
-#define	GET_ERROR_CODE				\
-	"		jnc 1f;"		\
-	"		mov $1, %[err];"	\
-	"		jmp 4f;"		\
-	"1:		jnz 3f;"		\
-	"		mov $2, %[err];"	\
-	"		jmp 4f;"		\
-	"3:		mov $0, %[err];"	\
-	"4:"
-
-static inline int
-vmxon(char *vmx_region)
-{
-	int err;
-	uint64_t paddr;
-
-	paddr = vtophys(vmx_region);
-	__asm __volatile("vmxon %[paddr];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [paddr] "m" (paddr)
-			 : "memory");
-
-	return err;
-}
-
-static inline void
-vmxoff(void)
-{
-
-	__asm __volatile("vmxoff");
-}
-
-static inline int
-vmclear(char *vmcs_region)
-{
-	int err;
-	uint64_t paddr;
-
-	paddr = vtophys(vmcs_region);
-	__asm __volatile("vmclear %[paddr];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [paddr] "m" (paddr)
-			 : "memory");
-	return err;
-}
-
-static inline void
-vmptrst(uint64_t *addr)
-{
-
-	__asm __volatile("vmptrst %[addr]"
-			:
-			: [addr] "m" (*addr)
-			: "memory");
-}
-
-static inline int
-vmptrld(char *vmcs)
-{
-	int err;
-	uint64_t paddr;
-
-	paddr = vtophys(vmcs);
-	__asm __volatile("vmptrld %[paddr];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [paddr] "m" (paddr)
-			 : "memory");
-	return err;
-}
-
-static inline int
-vmwrite(uint64_t reg, uint64_t val)
-{
-	int err;
-
-	__asm __volatile("vmwrite %[val], %[reg];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [val] "r" (val), [reg] "r" (reg)
-			 : "memory");
-
-	return err;
-}
-
-static inline int
-vmread(uint64_t reg, uint64_t *addr)
-{
-	int err;
-
-	__asm __volatile("vmread %[reg], %[addr];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [reg] "r" (reg), [addr] "m" (*addr)
-			 : "memory");
-
-	return err;
-}
-
-static inline int
-invept(uint64_t type, uint64_t *desc_addr)
-{
-	int err;
-
-	__asm __volatile("invept %[desc_addr], %[type];"
-			 GET_ERROR_CODE
-			 : [err] "=r" (err)
-			 : [desc_addr] "m" (*desc_addr), [type] "r" (type)
-			 : "memory");
-	return err;
-}
-
-#endif
diff --git a/sys/platform/pc64/vmm/vmx_trap.s b/sys/platform/pc64/vmm/vmx_trap.s
deleted file mode 100644
index 164a10425e5..00000000000
--- a/sys/platform/pc64/vmm/vmx_trap.s
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asmacros.h>
-#include "vmx_assym.h"
-
-#define	VMX_RESTORE_GUEST(reg)			\
-	movq VTI_GUEST_CR2(reg),%rsi;		\
-	movq %rsi,%cr2;				\
-	movq VTI_GUEST_RAX(reg),%rax;		\
-	movq VTI_GUEST_RBX(reg),%rbx;		\
-	movq VTI_GUEST_RCX(reg),%rcx;		\
-	movq VTI_GUEST_RDX(reg),%rdx;		\
-	movq VTI_GUEST_RSI(reg),%rsi;		\
-	movq VTI_GUEST_RDI(reg),%rdi;		\
-	movq VTI_GUEST_RBP(reg),%rbp;		\
-	movq VTI_GUEST_R8(reg),%r8;		\
-	movq VTI_GUEST_R9(reg),%r9;		\
-	movq VTI_GUEST_R10(reg),%r10;		\
-	movq VTI_GUEST_R11(reg),%r11;		\
-	movq VTI_GUEST_R12(reg),%r12;		\
-	movq VTI_GUEST_R13(reg),%r13;		\
-	movq VTI_GUEST_R14(reg),%r14;		\
-	movq VTI_GUEST_R15(reg),%r15;		\
-
-#define	VMX_SAVE_GUEST(reg)			\
-	movq %rax,VTI_GUEST_RAX(reg);		\
-	movq %rbx,VTI_GUEST_RBX(reg);		\
-	movq %rcx,VTI_GUEST_RCX(reg);		\
-	movq %rdx,VTI_GUEST_RDX(reg);		\
-	movq %rsi,VTI_GUEST_RSI(reg);		\
-	movq %rdi,VTI_GUEST_RDI(reg);		\
-	movq %rbp,VTI_GUEST_RBP(reg);		\
-	movq %r8,VTI_GUEST_R8(reg);		\
-	movq %r9,VTI_GUEST_R9(reg);		\
-	movq %r10,VTI_GUEST_R10(reg);		\
-	movq %r11,VTI_GUEST_R11(reg);		\
-	movq %r12,VTI_GUEST_R12(reg);		\
-	movq %r13,VTI_GUEST_R13(reg);		\
-	movq %r14,VTI_GUEST_R14(reg);		\
-	movq %r15,VTI_GUEST_R15(reg);		\
-	movq %cr2, %rsi;			\
-	movq %rsi, VTI_GUEST_CR2(reg);		\
-
-#define	VMX_RUN_ERROR(dst_reg)			\
-	jnc 	1f;				\
-	movq 	$VM_FAIL_INVALID,dst_reg;	\
-	jmp 	3f;				\
-1:	jnz 	2f;				\
-	movq 	$VM_FAIL_VALID,dst_reg;		\
-	jmp 	3f;				\
-2:	movq 	$VM_SUCCEED,dst_reg;		\
-3:
-
-
-.text
-
-/*
- * Called by the HW VMM when doing a VMEXIT.
- * - restore the host context
- * - return to handle_vmx_vmexit() with
- *   ret=VM_EXIT, in vmx.c
- *
- * void vmx_exit(void)
- * %rsp = vmx_thread_info
- */
-ENTRY(vmx_vmexit)
-
-	VMX_SAVE_GUEST(%rsp)
-
-	movq	%rsp,%rdi
-
-	movq VTI_HOST_RBX(%rdi),%rbx
-	movq VTI_HOST_RBP(%rdi),%rbp
-	movq VTI_HOST_R12(%rdi),%r12
-	movq VTI_HOST_R13(%rdi),%r13
-	movq VTI_HOST_R14(%rdi),%r14
-	movq VTI_HOST_R15(%rdi),%r15
-	movq VTI_HOST_RSP(%rdi),%rsp
-
-	movq $VM_EXIT, %rax
-
-	ret
-END(vmx_vmexit)
-
-/*
- * Called first time when entering the VMM
- * - executing "vmlaunch" with success, doesn't
- *   return here. Starts execution from the RIP
- *   pointed in by VMCS_GUEST_CR3
- * - not executing "vmlaunch" with success, it
- *   returns immediately with the appropiate
- *   error code
- *
- * int vmx_launch(struct vmx_thread_info* vti)
- * %rdi = cti
- */
-ENTRY(vmx_launch)
-	movq %rbx,VTI_HOST_RBX(%rdi)
-	movq %rbp,VTI_HOST_RBP(%rdi)
-	movq %r12,VTI_HOST_R12(%rdi)
-	movq %r13,VTI_HOST_R13(%rdi)
-	movq %r14,VTI_HOST_R14(%rdi)
-	movq %r15,VTI_HOST_R15(%rdi)
-	movq %rsp,VTI_HOST_RSP(%rdi)
-
-	movq %rdi,%rsp
-
-	VMX_RESTORE_GUEST(%rsp)
-
-	vmlaunch
-
-	VMX_RUN_ERROR(%rax)
-
-	movq	%rsp,%rdi
-
-	movq VTI_HOST_RBX(%rdi),%rbx
-	movq VTI_HOST_RBP(%rdi),%rbp
-	movq VTI_HOST_R12(%rdi),%r12
-	movq VTI_HOST_R13(%rdi),%r13
-	movq VTI_HOST_R14(%rdi),%r14
-	movq VTI_HOST_R15(%rdi),%r15
-	movq VTI_HOST_RSP(%rdi),%rsp
-
-	ret
-END(vmx_launch)
-
-/*
- * Called every time when entering the VMM, but only
- * after vmlaunch was executed before it
- * - executing "vmresume" with success, doesn't
- *   return here. Starts execution from the RIP
- *   pointed in by VMCS_GUEST_CR3
- * - not executing "vmresume" with success, it
- *   returns immediately with the appropiate
- *   error code
- *
- * int vmx_resume(struct vmx_thread_info* vti)
- * %rdi = cti
- */
-ENTRY(vmx_resume)
-	movq %rbx,VTI_HOST_RBX(%rdi)
-	movq %rbp,VTI_HOST_RBP(%rdi)
-	movq %r12,VTI_HOST_R12(%rdi)
-	movq %r13,VTI_HOST_R13(%rdi)
-	movq %r14,VTI_HOST_R14(%rdi)
-	movq %r15,VTI_HOST_R15(%rdi)
-	movq %rsp,VTI_HOST_RSP(%rdi)
-
-	movq %rdi,%rsp
-
-	VMX_RESTORE_GUEST(%rsp)
-
-	vmresume
-
-	VMX_RUN_ERROR(%rax)
-
-	movq	%rsp,%rdi
-
-	movq VTI_HOST_RBX(%rdi),%rbx
-	movq VTI_HOST_RBP(%rdi),%rbp
-	movq VTI_HOST_R12(%rdi),%r12
-	movq VTI_HOST_R13(%rdi),%r13
-	movq VTI_HOST_R14(%rdi),%r14
-	movq VTI_HOST_R15(%rdi),%r15
-	movq VTI_HOST_RSP(%rdi),%rsp
-
-	ret
-END(vmx_resume)
diff --git a/sys/platform/pc64/vmm/vmx_vmcs.h b/sys/platform/pc64/vmm/vmx_vmcs.h
deleted file mode 100644
index 80478b4fdca..00000000000
--- a/sys/platform/pc64/vmm/vmx_vmcs.h
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _VMM_VMX_VMCS_H_
-#define _VMM_VMX_VMCS_H_
-
-/*
- * Appendix B: Field Enconding in VMCS
- * Intel Architecture Manual Vol3C - 326019
- */
-
-/* 16-Bit Control Fields */
-#define		VMCS_VPID			0x00000000
-#define		VMCS_PINV			0x00000002
-#define		VMCS_EPTP_INDEX			0x00000004
-
-/* 16-Bit Guest-State Fields */
-#define		VMCS_GUEST_ES_SELECTOR		0x00000800
-#define		VMCS_GUEST_CS_SELECTOR		0x00000802
-#define		VMCS_GUEST_SS_SELECTOR		0x00000804
-#define		VMCS_GUEST_DS_SELECTOR		0x00000806
-#define		VMCS_GUEST_FS_SELECTOR		0x00000808
-#define		VMCS_GUEST_GS_SELECTOR		0x0000080A
-#define		VMCS_GUEST_LDTR_SELECTOR	0x0000080C
-#define		VMCS_GUEST_TR_SELECTOR		0x0000080E
-#define		VMCS_GUEST_INTERRUPT_STATUS	0x00000810
-
-/* 16-Bit Host-State Fields */
-#define		VMCS_HOST_ES_SELECTOR		0x00000C00
-#define		VMCS_HOST_CS_SELECTOR		0x00000C02
-#define		VMCS_HOST_SS_SELECTOR		0x00000C04
-#define		VMCS_HOST_DS_SELECTOR		0x00000C06
-#define		VMCS_HOST_FS_SELECTOR		0x00000C08
-#define		VMCS_HOST_GS_SELECTOR		0x00000C0A
-#define		VMCS_HOST_TR_SELECTOR		0x00000C0C
-
-/* 64-Bit Control Fields */
-#define		VMCS_IO_BITMAP_A		0x00002000
-#define		VMCS_IO_BITMAP_B		0x00002002
-#define		VMCS_MSR_BITMAP			0x00002004
-#define		VMCS_VMEXIT_MSR_STORE		0x00002006
-#define		VMCS_VMEXIT_MSR_LOAD		0x00002008
-#define		VMCS_VMENTRY_MSR_LOAD		0x0000200A
-#define		VMCS_EXECUTIVE_VMCS		0x0000200C
-#define		VMCS_TSC_OFFSET			0x00002010
-#define		VMCS_VIRTUAL_APIC		0x00002012
-#define		VMCS_APIC_ACCESS		0x00002014
-#define		VMCS_POSTED_INTERRUPT_DESCR	0x00002016
-#define		VMCS_VMFUNCTION_CONTROLS	0x00002018
-#define		VMCS_EPTP			0x0000201A
-
-/* 64-Bit Read-Only Data Field */
-#define		VMCS_GUEST_PHYSICAL_ADDRESS	0x00002400
-
-/* 64-Bit Guest-State Fields */
-#define		VMCS_LINK_POINTER		0x00002800
-#define		VMCS_GUEST_IA32_DEBUGCTL	0x00002802
-#define		VMCS_GUEST_IA32_PAT		0x00002804
-#define		VMCS_GUEST_IA32_EFER		0x00002806
-#define		VMCS_GUEST_IA32_PERF_GLOBAL	0x00002808
-#define		VMCS_GUEST_PDPTE0		0x0000280A
-#define		VMCS_GUEST_PDPTE1		0x0000280C
-#define		VMCS_GUEST_PDPTE2		0x0000280E
-#define		VMCS_GUEST_PDPTE3		0x00002810
-
-/* 64-Bit Host-State Fields */
-#define		VMCS_HOST_IA32_PAT		0x00002C00
-#define		VMCS_HOST_IA32_EFER		0x00002C02
-#define		VMCS_HOST_IA32_PERF_GLOBAL_CTRL	0x00002C04
-
-/* 32-Bit Control Fields */
-#define		VMCS_PINBASED_CTLS		0x00004000
-#define		VMCS_PROCBASED_CTLS		0x00004002
-#define		VMCS_EXCEPTION_BITMAP		0x00004004
-#define		VMCS_PAGE_FAULT_ERR_MASK	0x00004006
-#define		VMCS_PAGE_FAULT_ERR_MATCH	0x00004008
-#define		VMCS_CR3_TARGET_COUNT		0x0000400A
-#define		VMCS_VMEXIT_CTLS		0x0000400C
-#define		VMCS_VMEXIT_MSR_STORE_COUNT	0x0000400E
-#define		VMCS_VMEXIT_MSR_LOAD_COUNT	0x00004010
-#define		VMCS_VMENTRY_CTLS		0x00004012
-#define		VMCS_VMENTRY_MSR_LOAD_COUNT	0x00004014
-#define		VMCS_VMENTRY_INTR_INFO		0x00004016
-#define		VMCS_VMENTRY_EXCEPTION_ERR	0x00004018
-#define		VMCS_VMENTRY_INSTR_LENGTH	0x0000401A
-#define		VMCS_TPR_THRESHOLD		0x0000401C
-#define		VMCS_PROCBASED2_CTLS		0x0000401E
-#define		VMCS_PLE_GAP			0x00004020
-#define		VMCS_PLE_WINDOW			0x00004022
-
-/* 32-Bit Read-Only Data Fields */
-#define		VMCS_INSTR_ERR			0x00004400
-#define		VMCS_VMEXIT_REASON		0x00004402
-#define		VMCS_BASIC_EXIT_REASON(val)	(val & 0xffff)
-#define		VMCS_VMEXIT_INTERRUPTION_INFO	0x00004404
-#define		VMCS_VMEXIT_INTERRUPTION_ERROR	0x00004406
-#define		VMCS_IDT_VECTORING_INFO		0x00004408
-#define		VMCS_IDT_VECTORING_ERR		0x0000440A
-#define		VMCS_VMEXIT_INSTRUCTION_LENGTH	0x0000440C
-#define		VMCS_VMEXIT_INSTRUCTION_INFO	0x0000440E
-
-/* 32-Bit Guest-State Fields */
-#define		VMCS_GUEST_ES_LIMIT		0x00004800
-#define		VMCS_GUEST_CS_LIMIT		0x00004802
-#define		VMCS_GUEST_SS_LIMIT		0x00004804
-#define		VMCS_GUEST_DS_LIMIT		0x00004806
-#define		VMCS_GUEST_FS_LIMIT		0x00004808
-#define		VMCS_GUEST_GS_LIMIT		0x0000480A
-#define		VMCS_GUEST_LDTR_LIMIT		0x0000480C
-#define		VMCS_GUEST_TR_LIMIT		0x0000480E
-#define		VMCS_GUEST_GDTR_LIMIT		0x00004810
-#define		VMCS_GUEST_IDTR_LIMIT		0x00004812
-#define		VMCS_GUEST_ES_ACCESS_RIGHTS	0x00004814
-#define		VMCS_GUEST_CS_ACCESS_RIGHTS	0x00004816
-#define		VMCS_GUEST_SS_ACCESS_RIGHTS	0x00004818
-#define		VMCS_GUEST_DS_ACCESS_RIGHTS	0x0000481A
-#define		VMCS_GUEST_FS_ACCESS_RIGHTS	0x0000481C
-#define		VMCS_GUEST_GS_ACCESS_RIGHTS	0x0000481E
-#define		VMCS_GUEST_LDTR_ACCESS_RIGHTS	0x00004820
-#define		VMCS_GUEST_TR_ACCESS_RIGHTS	0x00004822
-#define		VMCS_GUEST_INTERRUPTIBILITY	0x00004824
-#define		VMCS_GUEST_ACTIVITY		0x00004826
-#define		VMCS_GUEST_SMBASE		0x00004828
-#define		VMCS_GUEST_IA32_SYSENTER_CS	0x0000482A
-#define		VMCS_PREEMPTION_TIMER_VALUE	0x0000482E
-
-/* 32-Bit Host-State Field */
-#define		VMCS_HOST_IA32_SYSENTER_CS	0x00004C00
-
-/* Natural-Width Control Fields */
-#define		VMCS_CR0_MASK			0x00006000
-#define		VMCS_CR4_MASK			0x00006002
-#define		VMCS_CR0_SHADOW			0x00006004
-#define		VMCS_CR4_SHADOW			0x00006006
-#define		VMCS_CR3_TARGET_VALUE0		0x00006008
-#define		VMCS_CR3_TARGET_VALUE1		0x0000600A
-#define		VMCS_CR3_TARGET_VALUE2		0x0000600C
-#define		VMCS_CR3_TARGET_VALUE3		0x0000600E
-
-/* Natural-Width Read-Only Data Fields */
-#define		VMCS_EXIT_QUALIFICATION		0x00006400
-#define		VMCS_IO_RCX			0x00006402
-#define		VMCS_IO_RSI			0x00006404
-#define		VMCS_IO_RDI			0x00006406
-#define		VMCS_IO_RIP			0x00006408
-#define		VMCS_GUEST_LINEAR_ADDRESS	0x0000640A
-
-/* Natural-Width Guest-State Fields */
-#define		VMCS_GUEST_CR0			0x00006800
-#define		VMCS_GUEST_CR3			0x00006802
-#define		VMCS_GUEST_CR4			0x00006804
-#define		VMCS_GUEST_ES_BASE		0x00006806
-#define		VMCS_GUEST_CS_BASE		0x00006808
-#define		VMCS_GUEST_SS_BASE		0x0000680A
-#define		VMCS_GUEST_DS_BASE		0x0000680C
-#define		VMCS_GUEST_FS_BASE		0x0000680E
-#define		VMCS_GUEST_GS_BASE		0x00006810
-#define		VMCS_GUEST_LDTR_BASE		0x00006812
-#define		VMCS_GUEST_TR_BASE		0x00006814
-#define		VMCS_GUEST_GDTR_BASE		0x00006816
-#define		VMCS_GUEST_IDTR_BASE		0x00006818
-#define		VMCS_GUEST_DR7			0x0000681A
-#define		VMCS_GUEST_RSP			0x0000681C
-#define		VMCS_GUEST_RIP			0x0000681E
-#define		VMCS_GUEST_RFLAGS		0x00006820
-#define		VMCS_GUEST_PENDING_DBG_EXCEPT	0x00006822
-#define		VMCS_GUEST_IA32_SYSENTER_ESP	0x00006824
-#define		VMCS_GUEST_IA32_SYSENTER_EIP	0x00006826
-
-/* Natural-Width Host-State Fields */
-#define		VMCS_HOST_CR0			0x00006C00
-#define		VMCS_HOST_CR3			0x00006C02
-#define		VMCS_HOST_CR4			0x00006C04
-#define		VMCS_HOST_FS_BASE		0x00006C06
-#define		VMCS_HOST_GS_BASE		0x00006C08
-#define		VMCS_HOST_TR_BASE		0x00006C0A
-#define		VMCS_HOST_GDTR_BASE		0x00006C0C
-#define		VMCS_HOST_IDTR_BASE		0x00006C0E
-#define		VMCS_HOST_IA32_SYSENTER_ESP	0x00006C10
-#define		VMCS_HOST_IA32_SYSENTER_EIP	0x00006C12
-#define		VMCS_HOST_RSP			0x00006C14
-#define		VMCS_HOST_RIP			0x00006c16
-
-#endif
diff --git a/sys/platform/pc64/x86_64/tls.c b/sys/platform/pc64/x86_64/tls.c
index 813065a21d6..349034b9378 100644
--- a/sys/platform/pc64/x86_64/tls.c
+++ b/sys/platform/pc64/x86_64/tls.c
@@ -55,7 +55,6 @@
 #include <machine/smp.h>
 #include <machine/pcb.h>
 #include <machine/thread.h>
-#include <machine/vmm.h>
 
 /*
  * set a TLS descriptor.  For x86_64 descriptor 0 identifies %fs and
@@ -172,10 +171,6 @@ set_user_TLS(void)
 		wrmsr(MSR_KGSBASE, gd->gd_user_gs);
 	}
 
-	if (td->td_vmm) {
-		vmm_vm_set_tls_area();
-	}
-
 	clear_quickret();
 	crit_exit_quick(td);
 }
diff --git a/sys/platform/pc64/x86_64/vm_machdep.c b/sys/platform/pc64/x86_64/vm_machdep.c
index 0e07207d075..0b0e2ed6bfc 100644
--- a/sys/platform/pc64/x86_64/vm_machdep.c
+++ b/sys/platform/pc64/x86_64/vm_machdep.c
@@ -64,7 +64,6 @@
 #include <machine/segments.h>
 #include <machine/globaldata.h>	/* npxthread */
 #include <machine/specialreg.h>
-#include <machine/vmm.h>
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
@@ -263,14 +262,8 @@ cpu_prepare_lwp(struct lwp *lp, struct lwp_params *params)
 	if (error)
 		return (error);
 
-	if (lp->lwp_proc->p_vmm) {
-		lp->lwp_thread->td_pcb->pcb_cr3 = KPML4phys;
-		cpu_set_fork_handler(lp,
-		    (void (*)(void *, struct trapframe *))vmm_lwp_return, lp);
-	} else {
-		cpu_set_fork_handler(lp,
-		    (void (*)(void *, struct trapframe *))generic_lwp_return, lp);
-	}
+	cpu_set_fork_handler(lp,
+	    (void (*)(void *, struct trapframe *))generic_lwp_return, lp);
 	return (0);
 }
 
diff --git a/sys/platform/vkernel64/include/vmm.h b/sys/platform/vkernel64/include/vmm.h
deleted file mode 100644
index ef2a9b0669e..00000000000
--- a/sys/platform/vkernel64/include/vmm.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2003-2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MACHINE_VMM_H_
-#define _MACHINE_VMM_H_
-
-#include <sys/vmm.h>
-
-static __inline
-int vmm_vminit(struct vmm_guest_options* opts) {
-	return 0;
-}
-
-static __inline
-int vmm_vmdestroy(void) {
-	return 0;
-}
-
-static __inline
-int vmm_vmrun(void) {
-	return 0;
-}
-
-static __inline
-int vmm_vm_set_tls_area(void) {
-	return 0;
-}
-
-static __inline
-void vmm_lwp_return(struct lwp *lp, struct trapframe *frame) {
-}
-
-static __inline
-void vmm_vm_set_guest_cr3(register_t guest_cr3) {
-}
-
-static __inline
-int vmm_vm_get_gpa(struct proc *p, register_t *gpa, register_t uaddr) {
-	*gpa = 0;
-	return 0;
-}
-
-#endif
diff --git a/sys/platform/vkernel64/platform/cothread.c b/sys/platform/vkernel64/platform/cothread.c
index 1de97e81dfa..2b43758c7fb 100644
--- a/sys/platform/vkernel64/platform/cothread.c
+++ b/sys/platform/vkernel64/platform/cothread.c
@@ -69,7 +69,6 @@
 #include <stdio.h>
 
 static void cothread_thread(void *arg);
-extern int vmm_enabled;
 
 /*
  * Create a co-processor thread for a virtual kernel.  This thread operates
@@ -82,7 +81,6 @@ cothread_create(void (*thr_func)(cothread_t cotd),
 		void *arg, const char *name)
 {
 	cothread_t cotd;
-	void *stack;
 	pthread_attr_t attr;
 
 	cotd = kmalloc(sizeof(*cotd), M_DEVBUF, M_WAITOK|M_ZERO);
@@ -107,15 +105,6 @@ cothread_create(void (*thr_func)(cothread_t cotd),
 	 * our coprocessor thread taking any unix signals :-)
 	 */
 	pthread_attr_init(&attr);
-	if (vmm_enabled) {
-		stack = mmap(NULL, KERNEL_STACK_SIZE,
-			     PROT_READ|PROT_WRITE|PROT_EXEC,
-			     MAP_ANON, -1, 0);
-		if (stack == MAP_FAILED) {
-			panic("Unable to allocate stack for cothread\n");
-		}
-		pthread_attr_setstack(&attr, stack, KERNEL_STACK_SIZE);
-	}
 	crit_enter();
 	cpu_mask_all_signals();
 	pthread_create(&cotd->pthr, &attr, (void *)cothread_thread, cotd);
diff --git a/sys/platform/vkernel64/platform/init.c b/sys/platform/vkernel64/platform/init.c
index 80e68da5892..76f01225242 100644
--- a/sys/platform/vkernel64/platform/init.c
+++ b/sys/platform/vkernel64/platform/init.c
@@ -53,7 +53,6 @@
 #include <vm/vm_map.h>
 #include <sys/mplock2.h>
 #include <sys/wait.h>
-#include <sys/vmm.h>
 
 #include <machine/cpu.h>
 #include <machine/globaldata.h>
@@ -123,7 +122,6 @@ int real_ncpus;		/* number of real CPUs */
 int next_cpu;		/* next real CPU to lock a virtual CPU to */
 int vkernel_b_arg;	/* no of logical CPU bits - only SMP */
 int vkernel_B_arg;	/* no of core bits - only SMP */
-int vmm_enabled;	/* VMM HW assisted enable */
 int use_precise_timer = 0;	/* use a precise timer (more expensive) */
 struct privatespace *CPU_prvspace;
 
@@ -137,7 +135,6 @@ static void *proc0paddr;
 
 static void init_sys_memory(char *imageFile);
 static void init_kern_memory(void);
-static void init_kern_memory_vmm(void);
 static void init_globaldata(void);
 static void init_vkernel(void);
 static void init_disk(char **diskExp, int *diskFlags, int diskFileNum, enum vkdisk_type type);
@@ -182,7 +179,6 @@ main(int ac, char **av)
 	int isq;
 	int pos;
 	int eflag;
-	int dflag = 0;		/* disable vmm */
 	int real_vkernel_enable;
 	int supports_sse;
 	uint32_t mxcsr_mask;
@@ -268,11 +264,8 @@ main(int ac, char **av)
 	if (ac < 2)
 		usage_help(false);
 
-	while ((c = getopt(ac, av, "c:hsvztTl:m:n:r:R:e:i:p:I:Ud")) != -1) {
+	while ((c = getopt(ac, av, "c:hsvztTl:m:n:r:R:e:i:p:I:U")) != -1) {
 		switch(c) {
-		case 'd':
-			dflag = 1;
-			break;
 		case 'e':
 			/*
 			 * name=value:name=value:name=value...
@@ -446,24 +439,10 @@ main(int ac, char **av)
 		}
 	}
 
-	/*
-	 * Check VMM presence
-	 */
-	vsize = sizeof(vmm_enabled);
-	sysctlbyname("hw.vmm.enable", &vmm_enabled, &vsize, NULL, 0);
-	vmm_enabled = (vmm_enabled && !dflag);
-
 	writepid();
 	cpu_disable_intr();
-	if (vmm_enabled) {
-		/* use a MAP_ANON directly */
-		printf("VMM is available\n");
-		init_kern_memory_vmm();
-	} else {
-		printf("VMM is not available\n");
-		init_sys_memory(memImageFile);
-		init_kern_memory();
-	}
+	init_sys_memory(memImageFile);
+	init_kern_memory();
 	init_globaldata();
 	init_vkernel();
 	setrealcpu();
@@ -732,131 +711,6 @@ init_kern_memory(void)
 	virtual_start += PAGE_SIZE;
 }
 
-static
-void
-init_kern_memory_vmm(void)
-{
-	int i;
-	void *firstfree;
-	struct vmm_guest_options options;
-	void *dmap_address;
-
-	KvaStart = (vm_offset_t)KERNEL_KVA_START;
-	KvaSize = KERNEL_KVA_SIZE;
-	KvaEnd = KvaStart + KvaSize;
-
-	Maxmem = Maxmem_bytes >> PAGE_SHIFT;
-	physmem = Maxmem;
-
-	if (Maxmem_bytes < 64 * 1024 * 1024 || (Maxmem_bytes & SEG_MASK)) {
-		errx(1, "Bad maxmem specification: 64MB minimum, "
-		       "multiples of %dMB only",
-		       SEG_SIZE / 1024 / 1024);
-		/* NOT REACHED */
-	}
-
-	/* Call the vmspace_create to allocate the internal
-	 * vkernel structures. Won't do anything else (no new
-	 * vmspace)
-	 */
-	if (vmspace_create(NULL, 0, NULL) < 0)
-		panic("vmspace_create() failed");
-
-
-	/*
-	 * MAP_ANON the region of the VKERNEL phyisical memory
-	 * (known as GPA - Guest Physical Address
-	 */
-	dmap_address = mmap(NULL, Maxmem_bytes,
-			    PROT_READ|PROT_WRITE|PROT_EXEC,
-			    MAP_ANON|MAP_SHARED, -1, 0);
-	if (dmap_address == MAP_FAILED) {
-		err(1, "Unable to mmap() RAM region!");
-		/* NOT REACHED */
-	}
-	if (prezeromem)
-		bzero(dmap_address, Maxmem_bytes);
-
-	/* Alloc a new stack in the lowmem */
-	vkernel_stack = mmap(NULL, KERNEL_STACK_SIZE,
-			     PROT_READ|PROT_WRITE|PROT_EXEC,
-			     MAP_ANON, -1, 0);
-	if (vkernel_stack == MAP_FAILED) {
-		err(1, "Unable to allocate stack\n");
-	}
-
-	/*
-	 * Bootstrap the kernel_pmap
-	 */
-	firstfree = dmap_address;
-	dmap_min_address = NULL; /* VIRT == PHYS in the first 512G */
-	pmap_bootstrap((vm_paddr_t *)&firstfree, (uint64_t)KvaStart);
-
-	/*
-	 * Enter VMM mode
-	 */
-	bzero(&options, sizeof(options));
-	options.guest_cr3 = (register_t) KPML4phys;
-	options.new_stack = (uint64_t) vkernel_stack + KERNEL_STACK_SIZE;
-	options.master = 1;
-	if (vmm_guest_ctl(VMM_GUEST_RUN, &options)) {
-		err(1, "Unable to enter VMM mode.");
-	}
-
-	/*
-	 * phys_avail[] represents unallocated physical memory.  MI code
-	 * will use phys_avail[] to create the vm_page array.
-	 */
-	phys_avail[0].phys_beg = (vm_paddr_t)firstfree;
-	phys_avail[0].phys_beg = (phys_avail[0].phys_beg + PAGE_MASK) &
-				 ~(vm_paddr_t)PAGE_MASK;
-	phys_avail[0].phys_end = (vm_paddr_t)dmap_address + Maxmem_bytes;
-
-	/*
-	 * pmap_growkernel() will set the correct value.
-	 */
-	kernel_vm_end = 0;
-
-	/*
-	 * Allocate space for process 0's UAREA.
-	 */
-	proc0paddr = (void *)virtual_start;
-	for (i = 0; i < UPAGES; ++i) {
-		pmap_kenter_quick(virtual_start, phys_avail[0].phys_beg);
-		virtual_start += PAGE_SIZE;
-		phys_avail[0].phys_beg += PAGE_SIZE;
-	}
-
-	/*
-	 * crashdumpmap
-	 */
-	crashdumpmap = virtual_start;
-	virtual_start += MAXDUMPPGS * PAGE_SIZE;
-
-	/*
-	 * msgbufp maps the system message buffer
-	 */
-	assert((MSGBUF_SIZE & PAGE_MASK) == 0);
-	msgbufp = (void *)virtual_start;
-	for (i = 0; i < (MSGBUF_SIZE >> PAGE_SHIFT); ++i) {
-
-		pmap_kenter_quick(virtual_start, phys_avail[0].phys_beg);
-		virtual_start += PAGE_SIZE;
-		phys_avail[0].phys_beg += PAGE_SIZE;
-	}
-
-	msgbufinit(msgbufp, MSGBUF_SIZE);
-
-	/*
-	 * used by kern_memio for /dev/mem access
-	 */
-	ptvmmap = (caddr_t)virtual_start;
-	virtual_start += PAGE_SIZE;
-
-	printf("vmm: Hardware pagetable enabled for guest\n");
-}
-
-
 /*
  * Map the per-cpu globaldata for cpu #0.  Allocate the space using
  * virtual_start and phys_avail[0]
diff --git a/sys/platform/vkernel64/platform/pmap.c b/sys/platform/vkernel64/platform/pmap.c
index 9d1353bede7..8cc2093acb3 100644
--- a/sys/platform/vkernel64/platform/pmap.c
+++ b/sys/platform/vkernel64/platform/pmap.c
@@ -140,7 +140,6 @@ static uint64_t	KPDphys;	/* phys addr of kernel level 2 */
 uint64_t		KPDPphys;	/* phys addr of kernel level 3 */
 uint64_t		KPML4phys;	/* phys addr of kernel level 4 */
 
-extern int vmm_enabled;
 extern void *vkernel_stack;
 
 /*
@@ -384,83 +383,6 @@ allocpages(vm_paddr_t *firstaddr, int n)
 	return (ret);
 }
 
-static void
-create_dmap_vmm(vm_paddr_t *firstaddr)
-{
-	void *stack_addr;
-	int pml4_stack_index;
-	int pdp_stack_index;
-	int pd_stack_index;
-	long i,j;
-	int regs[4];
-	int amd_feature;
-
-	uint64_t KPDP_DMAP_phys = allocpages(firstaddr, NDMPML4E);
-	uint64_t KPDP_VSTACK_phys = allocpages(firstaddr, 1);
-	uint64_t KPD_VSTACK_phys = allocpages(firstaddr, 1);
-
-	pml4_entry_t *KPML4virt = (pml4_entry_t *)PHYS_TO_DMAP(KPML4phys);
-	pdp_entry_t *KPDP_DMAP_virt = (pdp_entry_t *)PHYS_TO_DMAP(KPDP_DMAP_phys);
-	pdp_entry_t *KPDP_VSTACK_virt = (pdp_entry_t *)PHYS_TO_DMAP(KPDP_VSTACK_phys);
-	pd_entry_t *KPD_VSTACK_virt = (pd_entry_t *)PHYS_TO_DMAP(KPD_VSTACK_phys);
-
-	bzero(KPDP_DMAP_virt, NDMPML4E * PAGE_SIZE);
-	bzero(KPDP_VSTACK_virt, 1 * PAGE_SIZE);
-	bzero(KPD_VSTACK_virt, 1 * PAGE_SIZE);
-
-	do_cpuid(0x80000001, regs);
-	amd_feature = regs[3];
-
-	/* Build the mappings for the first 512GB */
-	if (amd_feature & AMDID_PAGE1GB) {
-		/* In pages of 1 GB, if supported */
-		for (i = 0; i < NPDPEPG; i++) {
-			KPDP_DMAP_virt[i] = ((uint64_t)i << PDPSHIFT);
-			KPDP_DMAP_virt[i] |= VPTE_RW | VPTE_V | VPTE_PS | VPTE_U;
-		}
-	} else {
-		/* In page of 2MB, otherwise */
-		for (i = 0; i < NPDPEPG; i++) {
-			uint64_t KPD_DMAP_phys;
-			pd_entry_t *KPD_DMAP_virt;
-
-			KPD_DMAP_phys = allocpages(firstaddr, 1);
-			KPD_DMAP_virt =
-				(pd_entry_t *)PHYS_TO_DMAP(KPD_DMAP_phys);
-
-			bzero(KPD_DMAP_virt, PAGE_SIZE);
-
-			KPDP_DMAP_virt[i] = KPD_DMAP_phys;
-			KPDP_DMAP_virt[i] |= VPTE_RW | VPTE_V | VPTE_U;
-
-			/* For each PD, we have to allocate NPTEPG PT */
-			for (j = 0; j < NPTEPG; j++) {
-				KPD_DMAP_virt[j] = (i << PDPSHIFT) |
-						   (j << PDRSHIFT);
-				KPD_DMAP_virt[j] |= VPTE_RW | VPTE_V |
-						    VPTE_PS | VPTE_U;
-			}
-		}
-	}
-
-	/* DMAP for the first 512G */
-	KPML4virt[0] = KPDP_DMAP_phys;
-	KPML4virt[0] |= VPTE_RW | VPTE_V | VPTE_U;
-
-	/* create a 2 MB map of the new stack */
-	pml4_stack_index = (uint64_t)&stack_addr >> PML4SHIFT;
-	KPML4virt[pml4_stack_index] = KPDP_VSTACK_phys;
-	KPML4virt[pml4_stack_index] |= VPTE_RW | VPTE_V | VPTE_U;
-
-	pdp_stack_index = ((uint64_t)&stack_addr & PML4MASK) >> PDPSHIFT;
-	KPDP_VSTACK_virt[pdp_stack_index] = KPD_VSTACK_phys;
-	KPDP_VSTACK_virt[pdp_stack_index] |= VPTE_RW | VPTE_V | VPTE_U;
-
-	pd_stack_index = ((uint64_t)&stack_addr & PDPMASK) >> PDRSHIFT;
-	KPD_VSTACK_virt[pd_stack_index] = (uint64_t) vkernel_stack;
-	KPD_VSTACK_virt[pd_stack_index] |= VPTE_RW | VPTE_V | VPTE_U | VPTE_PS;
-}
-
 static void
 create_pagetables(vm_paddr_t *firstaddr, int64_t ptov_offset)
 {
@@ -551,11 +473,6 @@ pmap_bootstrap(vm_paddr_t *firstaddr, int64_t ptov_offset)
 	 */
 	create_pagetables(firstaddr, ptov_offset);
 
-	/* Create the DMAP for the VMM */
-	if (vmm_enabled) {
-		create_dmap_vmm(firstaddr);
-	}
-
 	virtual_start = KvaStart;
 	virtual_end = KvaEnd;
 
@@ -617,10 +534,7 @@ pmap_bootstrap(vm_paddr_t *firstaddr, int64_t ptov_offset)
 	virtual_start = va;
 
 	*CMAP1 = 0;
-	/* Not ready to do an invltlb yet for VMM*/
-	if (!vmm_enabled)
-		cpu_invltlb();
-
+	cpu_invltlb();
 }
 
 /*
@@ -1735,13 +1649,6 @@ cpu_vmspace_alloc(struct vmspace *vm)
 	void *rp;
 	vpte_t vpte;
 
-	/*
-	 * If VMM enable, don't do nothing, we
-	 * are able to use real page tables
-	 */
-	if (vmm_enabled)
-		return;
-
 #define USER_SIZE	(VM_MAX_USER_ADDRESS - VM_MIN_USER_ADDRESS)
 
 	if (vmspace_create(&vm->vm_pmap, 0, NULL) < 0)
@@ -1766,13 +1673,6 @@ cpu_vmspace_alloc(struct vmspace *vm)
 void
 cpu_vmspace_free(struct vmspace *vm)
 {
-	/*
-	 * If VMM enable, don't do nothing, we
-	 * are able to use real page tables
-	 */
-	if (vmm_enabled)
-		return;
-
 	if (vmspace_destroy(&vm->vm_pmap) < 0)
 		panic("vmspace_destroy() failed");
 }
diff --git a/sys/platform/vkernel64/platform/pmap_inval.c b/sys/platform/vkernel64/platform/pmap_inval.c
index 56883e6102c..01170625e0e 100644
--- a/sys/platform/vkernel64/platform/pmap_inval.c
+++ b/sys/platform/vkernel64/platform/pmap_inval.c
@@ -30,8 +30,6 @@
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- * $DragonFly: src/sys/platform/vkernel/platform/pmap_inval.c,v 1.4 2007/07/02 02:22:58 dillon Exp $
  */
 
 /*
@@ -59,7 +57,6 @@
 #include <sys/cdefs.h>
 #include <sys/mman.h>
 #include <sys/vmspace.h>
-#include <sys/vmm.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -77,42 +74,8 @@
 
 #include <vm/vm_page2.h>
 
-extern int vmm_enabled;
-
-/*
- * Invalidate the TLB on the current cpu
- *
- * (VMM enabled only)
- */
-static __inline
-void
-vmm_cpu_invltlb(void)
-{
-#if 0
-	/* not directly supported */
-	cpu_invltlb();
-#else
-	/* vmm_guest_sync_addr(NULL, NULL); */
-	/* For VMM mode forces vmmexit/resume */
-	uint64_t rax = -1;
-	__asm __volatile("syscall;"
-			:
-			: "a" (rax)
-			:);
-#endif
-}
-
-static __inline
-void
-vmm_cpu_invlpg(void *addr __unused)
-{
-	vmm_cpu_invltlb();
-}
-
 /*
  * Invalidate va in the TLB on the current cpu
- *
- * (VMM disabled only)
  */
 static __inline
 void
@@ -125,69 +88,6 @@ pmap_inval_cpu(struct pmap *pmap, vm_offset_t va, size_t bytes)
 	}
 }
 
-/*
- * This is a bit of a mess because we don't know what virtual cpus are
- * mapped to real cpus.  Basically try to optimize the degenerate cases
- * (primarily related to user processes with only one thread or only one
- * running thread), and shunt all the rest to the host cpu.  The host cpu
- * will invalidate all real cpu's the vkernel is running on.
- *
- * This can't optimize situations where a pmap is only mapped to some of
- * the virtual cpus, though shunting to the real host will still be faster
- * if the virtual kernel processes are running on fewer real-host cpus.
- * (And probably will be faster anyway since there's no round-trip signaling
- * overhead).
- *
- * NOTE: The critical section protects against preemption while the pmap
- *	 is locked, which could otherwise result in a deadlock.
- */
-static __inline
-void
-guest_sync_addr(struct pmap *pmap, volatile vpte_t *ptep, vpte_t *srcv)
-{
-	globaldata_t gd = mycpu;
-	cpulock_t olock;
-	cpulock_t nlock;
-
-	/*
-	 * Lock the pmap
-	 */
-	crit_enter();
-	for (;;) {
-		olock = pmap->pm_active_lock;
-		cpu_ccfence();
-		if ((olock & CPULOCK_EXCL) == 0) {
-			nlock = olock | CPULOCK_EXCL;
-			if (atomic_cmpset_int(&pmap->pm_active_lock,
-					      olock, nlock)) {
-				break;
-			}
-		}
-		cpu_pause();
-		lwkt_process_ipiq();
-		vkernel_yield();
-	}
-
-	/*
-	 * Update the pte and synchronize with other cpus.  If we can update
-	 * it trivially, do so.
-	 */
-	if (CPUMASK_TESTZERO(pmap->pm_active) ||
-	    CPUMASK_CMPMASKEQ(pmap->pm_active, gd->gd_cpumask)) {
-		if (ptep)
-			*srcv = atomic_swap_long(ptep, *srcv);
-		vmm_cpu_invltlb();
-	} else {
-		vmm_guest_sync_addr(__DEVOLATILE(void *, ptep), srcv);
-	}
-
-	/*
-	 * Unlock the pmap
-	 */
-	atomic_clear_int(&pmap->pm_active_lock, CPULOCK_EXCL);
-	crit_exit();
-}
-
 /*
  * Invalidate a pte in a pmap and synchronize with target cpus
  * as required.  Throw away the modified and access bits.  Use
@@ -202,15 +102,8 @@ guest_sync_addr(struct pmap *pmap, volatile vpte_t *ptep, vpte_t *srcv)
 void
 pmap_inval_pte(volatile vpte_t *ptep, struct pmap *pmap, vm_offset_t va)
 {
-	vpte_t pte;
-
-	if (vmm_enabled == 0) {
-		atomic_swap_long(ptep, 0);
-		pmap_inval_cpu(pmap, va, PAGE_SIZE);
-	} else {
-		pte = 0;
-		guest_sync_addr(pmap, ptep, &pte);
-	}
+	atomic_swap_long(ptep, 0);
+	pmap_inval_cpu(pmap, va, PAGE_SIZE);
 }
 
 /*
@@ -221,10 +114,7 @@ void
 pmap_inval_pte_quick(volatile vpte_t *ptep, struct pmap *pmap, vm_offset_t va)
 {
 	atomic_swap_long(ptep, 0);
-	if (vmm_enabled == 0)
-		pmap_inval_cpu(pmap, va, PAGE_SIZE);
-	else
-		vmm_cpu_invltlb();
+	pmap_inval_cpu(pmap, va, PAGE_SIZE);
 }
 
 /*
@@ -234,11 +124,7 @@ pmap_inval_pte_quick(volatile vpte_t *ptep, struct pmap *pmap, vm_offset_t va)
 void
 pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm_offset_t eva)
 {
-	if (vmm_enabled == 0) {
-		pmap_inval_cpu(pmap, sva, eva - sva);
-	} else {
-		guest_sync_addr(pmap, NULL, NULL);
-	}
+	pmap_inval_cpu(pmap, sva, eva - sva);
 }
 
 /*
@@ -249,19 +135,8 @@ pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm_offset_t eva)
 void
 pmap_inval_pde(volatile vpte_t *ptep, struct pmap *pmap, vm_offset_t va)
 {
-	vpte_t pte;
-
-	if (vmm_enabled == 0) {
-		atomic_swap_long(ptep, 0);
-		pmap_inval_cpu(pmap, va, SEG_SIZE);
-	} else if (CPUMASK_TESTMASK(pmap->pm_active,
-				    mycpu->gd_other_cpus) == 0) {
-		atomic_swap_long(ptep, 0);
-		vmm_cpu_invltlb();
-	} else {
-		pte = 0;
-		guest_sync_addr(pmap, ptep, &pte);
-	}
+	atomic_swap_long(ptep, 0);
+	pmap_inval_cpu(pmap, va, SEG_SIZE);
 }
 
 void
@@ -333,22 +208,15 @@ pmap_clean_pte(volatile vpte_t *ptep, struct pmap *pmap, vm_offset_t va,
 		break;
 	}
 
-	if (vmm_enabled == 0) {
-		for (;;) {
-			pte = *ptep;
-			cpu_ccfence();
-			if ((pte & VPTE_RW) == 0)
-				break;
-			if (atomic_cmpset_long(ptep,
-					       pte,
-					       pte & ~(VPTE_RW | VPTE_M))) {
-				pmap_inval_cpu(pmap, va, PAGE_SIZE);
-				break;
-			}
+	for (;;) {
+		pte = *ptep;
+		cpu_ccfence();
+		if ((pte & VPTE_RW) == 0)
+			break;
+		if (atomic_cmpset_long(ptep, pte, pte & ~(VPTE_RW | VPTE_M))) {
+			pmap_inval_cpu(pmap, va, PAGE_SIZE);
+			break;
 		}
-	} else {
-		pte = *ptep & ~(VPTE_RW | VPTE_M);
-		guest_sync_addr(pmap, ptep, &pte);
 	}
 
 	if (m) {
@@ -377,32 +245,21 @@ pmap_inval_loadandclear(volatile vpte_t *ptep, struct pmap *pmap,
 {
 	vpte_t pte;
 
-	if (vmm_enabled == 0) {
-		pte = atomic_swap_long(ptep, 0);
-		pmap_inval_cpu(pmap, va, PAGE_SIZE);
-	} else {
-		pte = 0;
-		guest_sync_addr(pmap, ptep, &pte);
-	}
+	pte = atomic_swap_long(ptep, 0);
+	pmap_inval_cpu(pmap, va, PAGE_SIZE);
 	return(pte);
 }
 
 void
 cpu_invlpg(void *addr)
 {
-	if (vmm_enabled)
-		vmm_cpu_invlpg(addr);
-	else
-		madvise(addr, PAGE_SIZE, MADV_INVAL);
+	madvise(addr, PAGE_SIZE, MADV_INVAL);
 }
 
 void
 cpu_invltlb(void)
 {
-	if (vmm_enabled)
-		vmm_cpu_invltlb(); /* For VMM mode forces vmmexit/resume */
-	else
-		madvise((void *)KvaStart, KvaEnd - KvaStart, MADV_INVAL);
+	madvise((void *)KvaStart, KvaEnd - KvaStart, MADV_INVAL);
 }
 
 /*
diff --git a/sys/platform/vkernel64/x86_64/mp.c b/sys/platform/vkernel64/x86_64/mp.c
index c5a38c1cf22..c571c2abec6 100644
--- a/sys/platform/vkernel64/x86_64/mp.c
+++ b/sys/platform/vkernel64/x86_64/mp.c
@@ -39,7 +39,6 @@
 #include <sys/memrange.h>
 #include <sys/tls.h>
 #include <sys/types.h>
-#include <sys/vmm.h>
 
 #include <vm/vm_extern.h>
 #include <vm/vm_kern.h>
@@ -65,8 +64,6 @@
 
 extern pt_entry_t *KPTphys;
 
-extern int vmm_enabled;
-
 volatile cpumask_t stopped_cpus;
 /* which cpus are ready for IPIs etc? */
 cpumask_t	smp_active_mask = CPUMASK_INITIALIZER_ONLYONE;
@@ -393,7 +390,6 @@ start_all_aps(u_int boot_addr)
 	struct privatespace *ps;
 	vm_page_t m;
 	vm_offset_t va;
-	void *stack;
 	pthread_attr_t attr;
 	size_t ipiq_size;
 #if 0
@@ -465,16 +461,6 @@ start_all_aps(u_int boot_addr)
 		 */
 		cpu_disable_intr();
 
-		if (vmm_enabled) {
-			stack = mmap(NULL, KERNEL_STACK_SIZE,
-				     PROT_READ|PROT_WRITE|PROT_EXEC,
-				     MAP_ANON, -1, 0);
-			if (stack == MAP_FAILED) {
-				panic("Unable to allocate stack for thread %d\n", x);
-			}
-			pthread_attr_setstack(&attr, stack, KERNEL_STACK_SIZE);
-		}
-
 		pthread_create(&ap_tids[x], &attr, start_ap, NULL);
 		cpu_enable_intr();
 
diff --git a/sys/platform/vkernel64/x86_64/trap.c b/sys/platform/vkernel64/x86_64/trap.c
index 9b7da3a193d..cc3b2fb112e 100644
--- a/sys/platform/vkernel64/x86_64/trap.c
+++ b/sys/platform/vkernel64/x86_64/trap.c
@@ -95,7 +95,6 @@ int (*pmath_emulate) (struct trapframe *);
 static int trap_pfault (struct trapframe *, int, vm_offset_t);
 static void trap_fatal (struct trapframe *, int, vm_offset_t);
 void dblfault_handler (void);
-extern int vmm_enabled;
 
 static struct krate segfltrate = { 1 };
 
@@ -1401,10 +1400,7 @@ go_user(struct intrframe *frame)
 		 * Set PGEX_U unconditionally, indicating a user frame (the
 		 * bit is normally set only by T_PAGEFLT).
 		 */
-		if (vmm_enabled)
-			id = (void *)vtophys(curproc->p_vmspace->vm_pmap.pm_pml4);
-		else
-			id = &curproc->p_vmspace->vm_pmap;
+		id = &curproc->p_vmspace->vm_pmap;
 
 		/*
 		 * The GDF_VIRTUSER hack helps statclock() figure out who
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 648788a89dd..f26229113d2 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -231,9 +231,10 @@
  * 600101 - kernel_{map,pmap,object} and {buffer,clean,pager}_map globals
  *          become pointers
  * 600102 - add nvmm(4) and libnvmm(3)
+ * 600103 - removal of the old vmm code
  */
 #undef __DragonFly_version
-#define __DragonFly_version 600102	/* propagated to newvers */
+#define __DragonFly_version 600103	/* propagated to newvers */
 
 #include <sys/_null.h>
 
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 2291f8a13f5..56a7519d6ce 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -306,9 +306,9 @@ struct	proc {
 	u_short		p_depth;	/* Used to downscale resource limits */
 
 	int		p_ionice;
-	void		*p_unused02;
+	void		*p_unused01;
 /* End area that is copied on creation. */
-#define	p_endcopy	p_unused02
+#define	p_endcopy	p_unused01
 	u_short		p_acflag;	/* Accounting flags. */
 
 	int		p_lock;		/* Prevent proc destruction */
@@ -330,9 +330,7 @@ struct	proc {
 	struct lwkt_token p_token;	/* Token for LWP access to proc */
 	struct sem_undo	*p_sem_undo;	/* Fast semaphore tracking lookup */
 	void		*p_drv_priv;	/* scp linkage (for syscons) */
-	void		*p_vmm;
-	cpulock_t	p_vmm_cpulock;	/* count cpus in and kickout lock */
-	cpumask_t	p_vmm_cpumask;	/* cpus entering or in vmm */
+	char		p_unused02[44];
 	struct sys_upmap *p_upmap;	/* user RW mappable per-process page */
 	forkid_t	p_forkid;	/* unique forkid */
 	struct sysreaper *p_reaper;	/* reaper control */
diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h
index 25851565f3e..58343c514c4 100644
--- a/sys/sys/syscall.h
+++ b/sys/sys/syscall.h
@@ -369,8 +369,8 @@
 #define	SYS_linkat	531
 #define	SYS_eaccess	532
 #define	SYS_lpathconf	533
-#define	SYS_vmm_guest_ctl	534
-#define	SYS_vmm_guest_sync_addr	535
+				/* 534 is obsolete vmm_guest_ctl */
+				/* 535 is obsolete vmm_guest_sync_addr */
 #define	SYS_procctl	536
 #define	SYS_chflagsat	537
 #define	SYS_pipe2	538
diff --git a/sys/sys/syscall.mk b/sys/sys/syscall.mk
index fb4ed95c666..fa64d039e99 100644
--- a/sys/sys/syscall.mk
+++ b/sys/sys/syscall.mk
@@ -297,8 +297,6 @@ MIASM =  \
 	linkat.o \
 	eaccess.o \
 	lpathconf.o \
-	vmm_guest_ctl.o \
-	vmm_guest_sync_addr.o \
 	procctl.o \
 	chflagsat.o \
 	pipe2.o \
diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h
index 6d97609fb94..0d0058dfbc8 100644
--- a/sys/sys/sysproto.h
+++ b/sys/sys/sysproto.h
@@ -1343,14 +1343,6 @@ struct	lpathconf_args {
 	char *	path;	char path_[PAD_(char *)];
 	int	name;	char name_[PAD_(int)];
 };
-struct	vmm_guest_ctl_args {
-	int	op;	char op_[PAD_(int)];
-	struct vmm_guest_options *	options;	char options_[PAD_(struct vmm_guest_options *)];
-};
-struct	vmm_guest_sync_addr_args {
-	long *	dstaddr;	char dstaddr_[PAD_(long *)];
-	long *	srcaddr;	char srcaddr_[PAD_(long *)];
-};
 struct	procctl_args {
 	idtype_t	idtype;	char idtype_[PAD_(idtype_t)];
 	id_t	id;	char id_[PAD_(id_t)];
@@ -1747,8 +1739,6 @@ int	sys_vquotactl (struct sysmsg *sysmsg, const struct vquotactl_args *);
 int	sys_linkat (struct sysmsg *sysmsg, const struct linkat_args *);
 int	sys_eaccess (struct sysmsg *sysmsg, const struct eaccess_args *);
 int	sys_lpathconf (struct sysmsg *sysmsg, const struct lpathconf_args *);
-int	sys_vmm_guest_ctl (struct sysmsg *sysmsg, const struct vmm_guest_ctl_args *);
-int	sys_vmm_guest_sync_addr (struct sysmsg *sysmsg, const struct vmm_guest_sync_addr_args *);
 int	sys_procctl (struct sysmsg *sysmsg, const struct procctl_args *);
 int	sys_chflagsat (struct sysmsg *sysmsg, const struct chflagsat_args *);
 int	sys_pipe2 (struct sysmsg *sysmsg, const struct pipe2_args *);
diff --git a/sys/sys/sysunion.h b/sys/sys/sysunion.h
index 55c15d9d64d..37c67f21973 100644
--- a/sys/sys/sysunion.h
+++ b/sys/sys/sysunion.h
@@ -303,8 +303,6 @@ union sysunion {
 	struct	linkat_args linkat;
 	struct	eaccess_args eaccess;
 	struct	lpathconf_args lpathconf;
-	struct	vmm_guest_ctl_args vmm_guest_ctl;
-	struct	vmm_guest_sync_addr_args vmm_guest_sync_addr;
 	struct	procctl_args procctl;
 	struct	chflagsat_args chflagsat;
 	struct	pipe2_args pipe2;
diff --git a/sys/sys/thread.h b/sys/sys/thread.h
index db32ce4305d..01bfdd8bb51 100644
--- a/sys/sys/thread.h
+++ b/sys/sys/thread.h
@@ -292,7 +292,7 @@ struct thread {
     char	td_comm[MAXCOMLEN+1]; /* typ 16+1 bytes */
     struct thread *td_preempted; /* we preempted this thread */
     struct ucred *td_ucred;	/* synchronized from proc->p_ucred */
-    void	 *td_vmm;	/* vmm private data */
+    void	*td_unused04;
     lwkt_tokref_t td_toks_have;		/* tokens we own */
     lwkt_tokref_t td_toks_stop;		/* tokens we want */
     struct lwkt_tokref td_toks_array[LWKT_MAXTOKENS];
diff --git a/sys/sys/vmm.h b/sys/sys/vmm.h
deleted file mode 100644
index 3f85440c2c1..00000000000
--- a/sys/sys/vmm.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2013 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Mihai Carabas <mihai.carabas@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef	_SYS_VMM_H_
-#define	_SYS_VMM_H_
-
-/*
- * Init the calling thread with a VM context
- * Run the calling thread in VM context
- * Destroy the VM context of the thread
- */
-
-#define	VMM_GUEST_RUN		1
-
-#include <sys/types.h>
-#include <machine/frame.h>
-
-struct vmm_guest_options {
-	register_t guest_cr3;
-	register_t vmm_cr3;
-	register_t new_stack;
-	struct trapframe tf;
-	uint8_t master;
-};
-
-
-int	vmm_guest_ctl(int, struct vmm_guest_options *);
-int	vmm_guest_sync_addr(long *, long *);
-
-#endif	/* !_SYS_VMM_H_ */
diff --git a/sys/vfs/procfs/procfs_mem.c b/sys/vfs/procfs/procfs_mem.c
index 1a168741438..6ffc1d78017 100644
--- a/sys/vfs/procfs/procfs_mem.c
+++ b/sys/vfs/procfs/procfs_mem.c
@@ -59,8 +59,6 @@
 #include <vm/vm_page.h>
 #include <sys/ptrace.h>
 
-#include <machine/vmm.h>
-
 static int	procfs_rwmem (struct proc *curp,
 				  struct proc *p, struct uio *uio);
 
@@ -121,17 +119,6 @@ procfs_rwmem(struct proc *curp, struct proc *p, struct uio *uio)
 		pageno = trunc_page(uva);
 		page_offset = uva - pageno;
 
-		/*
-		 * If the target process is running in VMM mode
-		 * translate the address into a GPA (Guest Physical
-		 * Address) via the EPT before doing the lookup.
-		 */
-		if (p->p_vmm) {
-			register_t gpa;
-			vmm_vm_get_gpa(p, &gpa, (register_t) pageno);
-			pageno = (vm_offset_t)gpa;
-		}
-
 		/*
 		 * How many bytes to copy
 		 */
diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c
index 6f615edac56..d3112a89c06 100644
--- a/sys/vm/vm_glue.c
+++ b/sys/vm/vm_glue.c
@@ -73,7 +73,6 @@
 #include <sys/unistd.h>
 
 #include <machine/limits.h>
-#include <machine/vmm.h>
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
@@ -147,18 +146,11 @@ useracc(c_caddr_t addr, int len, int rw)
 	vm_prot_t prot;
 	vm_map_t map;
 	vm_offset_t wrap;
-	vm_offset_t gpa;
 
 	KASSERT((rw & (~VM_PROT_ALL)) == 0,
 	    ("illegal ``rw'' argument to useracc (%x)", rw));
 	prot = rw;
 
-	if (curthread->td_vmm) {
-		if (vmm_vm_get_gpa(curproc, (register_t *)&gpa, (register_t) addr))
-			panic("%s: could not get GPA\n", __func__);
-		addr = (c_caddr_t) gpa;
-	}
-
 	/*
 	 * XXX - check separately to disallow access to user area and user
 	 * page tables - they are in the map.
diff --git a/sys/vm/vm_vmspace.c b/sys/vm/vm_vmspace.c
index 87ef43920d8..4702fab8c0c 100644
--- a/sys/vm/vm_vmspace.c
+++ b/sys/vm/vm_vmspace.c
@@ -51,7 +51,6 @@
 #include <vm/pmap.h>
 
 #include <machine/vmparam.h>
-#include <machine/vmm.h>
 
 static struct vmspace_entry *vkernel_find_vmspace(struct vkernel_proc *vkp,
 						  void *id, int havetoken);
@@ -108,9 +107,6 @@ sys_vmspace_create(struct sysmsg *sysmsg,
 		lwkt_reltoken(&p->p_token);
 	}
 
-	if (curthread->td_vmm)
-		return 0;
-
 	/*
 	 * Create a new VMSPACE, disallow conflicting ids
 	 */
@@ -196,16 +192,12 @@ sys_vmspace_ctl(struct sysmsg *sysmsg,
 		return (EINVAL);
 
 	/*
-	 * ve only matters when VMM is not used.
-	 *
 	 * NOTE: We have to copy *uap into ua because uap is an aliased
 	 *	 pointer into the sysframe, which we are replacing.
 	 */
-	if (curthread->td_vmm == NULL) {
-		if ((ve = vkernel_find_vmspace(vkp, ua.id, 0)) == NULL) {
-			error = ENOENT;
-			goto done;
-		}
+	if ((ve = vkernel_find_vmspace(vkp, ua.id, 0)) == NULL) {
+		error = ENOENT;
+		goto done;
 	}
 
 	switch(ua.cmd) {
@@ -249,20 +241,9 @@ sys_vmspace_ctl(struct sysmsg *sysmsg,
 			      sizeof(vklp->save_vextframe.vx_tls));
 			set_user_TLS();
 		} else {
-			/*
-			 * If it's a VMM thread just set the CR3. We also set
-			 * the vklp->ve to a key to be able to distinguish
-			 * when a vkernel user process runs and when not
-			 * (when it's NULL)
-			 */
-			if (curthread->td_vmm == NULL) {
-				vklp->ve = ve;
-				atomic_add_int(&ve->refs, 1);
-				pmap_setlwpvm(lp, ve->vmspace);
-			} else {
-				vklp->ve = ua.id;
-				vmm_vm_set_guest_cr3((register_t)ua.id);
-			}
+			vklp->ve = ve;
+			atomic_add_int(&ve->refs, 1);
+			pmap_setlwpvm(lp, ve->vmspace);
 			set_user_TLS();
 			set_vkernel_fp(sysmsg->sysmsg_frame);
 			error = EJUSTRETURN;
@@ -776,23 +757,16 @@ vkernel_lwp_exit(struct lwp *lp)
 	struct vmspace_entry *ve;
 
 	if ((vklp = lp->lwp_vkernel) != NULL) {
-		if (lp->lwp_thread->td_vmm == NULL) {
-			/*
-			 * vkernel thread
-			 */
-			if ((ve = vklp->ve) != NULL) {
-				kprintf("Warning, pid %d killed with "
-					"active VC!\n", lp->lwp_proc->p_pid);
-				pmap_setlwpvm(lp, lp->lwp_proc->p_vmspace);
-				vklp->ve = NULL;
-				KKASSERT(ve->refs > 0);
-				vmspace_entry_drop(ve);
-			}
-		} else {
-			/*
-			 * guest thread
-			 */
+		/*
+		 * vkernel thread
+		 */
+		if ((ve = vklp->ve) != NULL) {
+			kprintf("Warning, pid %d killed with "
+			    "active VC!\n", lp->lwp_proc->p_pid);
+			pmap_setlwpvm(lp, lp->lwp_proc->p_vmspace);
 			vklp->ve = NULL;
+			KKASSERT(ve->refs > 0);
+			vmspace_entry_drop(ve);
 		}
 		if ((ve = vklp->ve_cache) != NULL) {
 			vklp->ve_cache = NULL;
@@ -824,23 +798,17 @@ vkernel_trap(struct lwp *lp, struct trapframe *frame)
 	vklp = lp->lwp_vkernel;
 	KKASSERT(vklp);
 
-	/* If it's a VMM thread just set the vkernel CR3 back */
-	if (curthread->td_vmm == NULL) {
-		ve = vklp->ve;
-		KKASSERT(ve != NULL);
+	ve = vklp->ve;
+	KKASSERT(ve != NULL);
 
-		/*
-		 * Switch the LWP vmspace back to the virtual kernel's VM space.
-		 */
-		vklp->ve = NULL;
-		pmap_setlwpvm(lp, p->p_vmspace);
-		KKASSERT(ve->refs > 0);
-		vmspace_entry_drop(ve);
-		/* ve is invalid once we kill our ref */
-	} else {
-		vklp->ve = NULL;
-		vmm_vm_set_guest_cr3(p->p_vkernel->vkernel_cr3);
-	}
+	/*
+	 * Switch the LWP vmspace back to the virtual kernel's VM space.
+	 */
+	vklp->ve = NULL;
+	pmap_setlwpvm(lp, p->p_vmspace);
+	KKASSERT(ve->refs > 0);
+	vmspace_entry_drop(ve);
+	/* ve is invalid once we kill our ref */
 
 	/*
 	 * Copy the emulated process frame to the virtual kernel process.
diff --git a/test/vmm/Makefile b/test/vmm/Makefile
deleted file mode 100644
index 436802f4e87..00000000000
--- a/test/vmm/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-PROG=	vmm_test
-
-#CFLAGS+=-O -g -I/usr/src/sys
-
-.include <bsd.prog.mk>
diff --git a/test/vmm/vmm_test.c b/test/vmm/vmm_test.c
deleted file mode 100644
index fce7c604981..00000000000
--- a/test/vmm/vmm_test.c
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <sys/vmm_guest_ctl.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/vkernel.h>
-
-#include <cpu/cpufunc.h>
-#include <cpu/specialreg.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <err.h>
-#include <unistd.h>
-#include <strings.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#define vmm_printf(val, err, exp) \
-	printf("vmm_guest(%d): return %d, expected %d\n", val, err, exp);
-
-#define STACK_SIZE (512 * PAGE_SIZE)
-
-int
-vmm_boostrap(void)
-{
-	struct vmm_guest_options options;
-	uint64_t *ptr;
-	uint64_t stack_source;
-	uint64_t stack_size;
-	uint64_t stack_dest;
-	int pml4_stack_index;
-	int pdp_stack_index;
-	int pd_stack_index;
-	char tst[1024];
-	void *stack;
-	uint64_t i,j;
-	int regs[4];
-	int amd_feature;
-
-	stack = mmap(NULL, STACK_SIZE,
-	    PROT_READ|PROT_WRITE|PROT_EXEC,
-	    MAP_ANON, -1, 0);
-
-	if (stack == MAP_FAILED) {
-		printf("Error on allocating stack\n");
-		return -1;
-	}
-
-	posix_memalign((void **) &ptr, PAGE_SIZE, (512 + 4) * PAGE_SIZE);
-	bzero(ptr, (512 + 4) * PAGE_SIZE);
-
-	uint64_t *pml4 = ptr;
-	uint64_t *pdp = (uint64_t *)((uint64_t)ptr + PAGE_SIZE);
-	uint64_t *pdp_stack = (uint64_t *)((uint64_t)ptr + 2 * PAGE_SIZE);
-	uint64_t *pd_stack = (uint64_t *)((uint64_t)ptr + 3 * PAGE_SIZE);
-	uint64_t *pd_vec = (uint64_t *)((uint64_t)ptr + 4 * PAGE_SIZE);
-
-	pml4[0] = (uint64_t) pdp | VPTE_V | VPTE_RW| VPTE_U;
-
-	do_cpuid(0x80000001, regs);
-	amd_feature = regs[3];
-
-	if (amd_feature & AMDID_PAGE1GB) {
-		for (i = 0; i < VPTE_PAGE_ENTRIES; i++) {
-			pdp[i] = i << 30;
-			pdp[i] |=  VPTE_V | VPTE_RW | VPTE_U;
-		}
-	} else {
-		for (i = 0; i < VPTE_PAGE_ENTRIES; i++) {
-			uint64_t *pd = &pd_vec[i * VPTE_PAGE_ENTRIES];
-			pdp[i] = (uint64_t) pd;
-			pdp[i] |=  VPTE_V | VPTE_RW | VPTE_U;
-			for (j = 0; j < VPTE_PAGE_ENTRIES; j++) {
-				pd[j] = (i << 30) | (j << 21);
-				pd[j] |=  VPTE_V | VPTE_RW | VPTE_U | VPTE_PS;
-			}
-		}
-	}
-
-	void *stack_addr = NULL;
-
-	pml4_stack_index = (uint64_t)&stack_addr >> PML4SHIFT;
-	pml4[pml4_stack_index] = (uint64_t) pdp_stack;
-	pml4[pml4_stack_index] |= VPTE_V | VPTE_RW| VPTE_U;
-
-	pdp_stack_index = ((uint64_t)&stack_addr & PML4MASK) >> PDPSHIFT;
-	pdp_stack[pdp_stack_index] = (uint64_t) pd_stack;
-	pdp_stack[pdp_stack_index] |= VPTE_V | VPTE_RW| VPTE_U;
-
-	pd_stack_index = ((uint64_t)&stack_addr & PDPMASK) >> PDRSHIFT;
-	pd_stack[pd_stack_index] = (uint64_t) stack;
-	pd_stack[pd_stack_index] |= VPTE_V | VPTE_RW| VPTE_U | VPTE_PS;
-
-	options.new_stack = (uint64_t)stack + STACK_SIZE;
-	options.guest_cr3 = (register_t) pml4;
-	options.master = 1;
-	if(vmm_guest_ctl(VMM_GUEST_RUN, &options)) {
-		printf("Error: VMM enter failed\n");
-	}
-	printf("vmm_bootstrap: VMM bootstrap success\n");
-
-	return 0;
-}
-int
-main(void)
-{
-	vmm_boostrap();
-	printf("vmm_test: VMM bootstrap success\n");
-	return 0;
-}
-- 
2.32.0

