svn commit: r252910 - in projects/bhyve_npt_pmap/sys/amd64: include vmm vmm/amd vmm/intel
Neel Natu
neel at FreeBSD.org
Sun Jul 7 02:49:50 UTC 2013
Author: neel
Date: Sun Jul 7 02:49:48 2013
New Revision: 252910
URL: http://svnweb.freebsd.org/changeset/base/252910
Log:
The nested page tables are now maintained by the VM subsystem.
Remove the redundant 'pml4ept[]' and point the EPT to the physical address
of 'pm_pml4' instead.
Also get rid of the 'ept_vmcleanup()' function since this is now done by
'pmap_release()'.
Modified:
projects/bhyve_npt_pmap/sys/amd64/include/vmm.h
projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c
projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c
projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h
projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.c
projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.h
projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c
Modified: projects/bhyve_npt_pmap/sys/amd64/include/vmm.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/include/vmm.h Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/include/vmm.h Sun Jul 7 02:49:48 2013 (r252910)
@@ -41,12 +41,13 @@ struct vm_run;
struct vlapic;
struct vmspace;
struct vm_object;
+struct pmap;
enum x2apic_state;
typedef int (*vmm_init_func_t)(void);
typedef int (*vmm_cleanup_func_t)(void);
-typedef void * (*vmi_init_func_t)(struct vm *vm); /* instance specific apis */
+typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip);
typedef void (*vmi_cleanup_func_t)(void *vmi);
typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c Sun Jul 7 02:49:48 2013 (r252910)
@@ -54,7 +54,7 @@ amdv_cleanup(void)
}
static void *
-amdv_vminit(struct vm *vm)
+amdv_vminit(struct vm *vm, struct pmap *pmap)
{
printf("amdv_vminit: not implemented\n");
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sun Jul 7 02:49:48 2013 (r252910)
@@ -152,79 +152,6 @@ ept_dump(uint64_t *ptp, int nlevels)
#endif
static void
-ept_free_pt_entry(pt_entry_t pte)
-{
- if (pte == 0)
- return;
-
- /* sanity check */
- if ((pte & EPT_PG_SUPERPAGE) != 0)
- panic("ept_free_pt_entry: pte cannot have superpage bit");
-
- return;
-}
-
-static void
-ept_free_pd_entry(pd_entry_t pde)
-{
- pt_entry_t *pt;
- int i;
-
- if (pde == 0)
- return;
-
- if ((pde & EPT_PG_SUPERPAGE) == 0) {
- pt = (pt_entry_t *)PHYS_TO_DMAP(pde & EPT_ADDR_MASK);
- for (i = 0; i < NPTEPG; i++)
- ept_free_pt_entry(pt[i]);
- free(pt, M_VMX); /* free the page table page */
- }
-}
-
-static void
-ept_free_pdp_entry(pdp_entry_t pdpe)
-{
- pd_entry_t *pd;
- int i;
-
- if (pdpe == 0)
- return;
-
- if ((pdpe & EPT_PG_SUPERPAGE) == 0) {
- pd = (pd_entry_t *)PHYS_TO_DMAP(pdpe & EPT_ADDR_MASK);
- for (i = 0; i < NPDEPG; i++)
- ept_free_pd_entry(pd[i]);
- free(pd, M_VMX); /* free the page directory page */
- }
-}
-
-static void
-ept_free_pml4_entry(pml4_entry_t pml4e)
-{
- pdp_entry_t *pdp;
- int i;
-
- if (pml4e == 0)
- return;
-
- if ((pml4e & EPT_PG_SUPERPAGE) == 0) {
- pdp = (pdp_entry_t *)PHYS_TO_DMAP(pml4e & EPT_ADDR_MASK);
- for (i = 0; i < NPDPEPG; i++)
- ept_free_pdp_entry(pdp[i]);
- free(pdp, M_VMX); /* free the page directory ptr page */
- }
-}
-
-void
-ept_vmcleanup(struct vmx *vmx)
-{
- int i;
-
- for (i = 0; i < NPML4EPG; i++)
- ept_free_pml4_entry(vmx->pml4ept[i]);
-}
-
-static void
invept_single_context(void *arg)
{
struct invept_desc desc = *(struct invept_desc *)arg;
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h Sun Jul 7 02:49:48 2013 (r252910)
@@ -36,7 +36,6 @@ struct vmx;
int ept_init(void);
void ept_invalidate_mappings(u_long ept_pml4);
-void ept_vmcleanup(struct vmx *vmx);
struct vmspace *ept_vmspace_alloc(vm_offset_t min, vm_offset_t max);
void ept_vmspace_free(struct vmspace *vmspace);
#endif
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.c Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.c Sun Jul 7 02:49:48 2013 (r252910)
@@ -681,7 +681,7 @@ vmx_setup_cr_shadow(int which, struct vm
#define vmx_setup_cr4_shadow(vmcs) vmx_setup_cr_shadow(4, (vmcs))
static void *
-vmx_vminit(struct vm *vm)
+vmx_vminit(struct vm *vm, pmap_t pmap)
{
uint16_t vpid;
int i, error, guest_msr_count;
@@ -694,6 +694,8 @@ vmx_vminit(struct vm *vm)
}
vmx->vm = vm;
+ vmx->eptphys = vtophys((vm_offset_t)pmap->pm_pml4);
+
/*
* Clean up EPTP-tagged guest physical and combined mappings
*
@@ -703,7 +705,7 @@ vmx_vminit(struct vm *vm)
*
* Combined mappings for this EP4TA are also invalidated for all VPIDs.
*/
- ept_invalidate_mappings(vtophys(vmx->pml4ept));
+ ept_invalidate_mappings(vmx->eptphys);
msr_bitmap_initialize(vmx->msr_bitmap);
@@ -759,7 +761,7 @@ vmx_vminit(struct vm *vm)
error = vmcs_set_defaults(&vmx->vmcs[i],
(u_long)vmx_longjmp,
(u_long)&vmx->ctx[i],
- vtophys(vmx->pml4ept),
+ vmx->eptphys,
pinbased_ctls,
procbased_ctls,
procbased_ctls2,
@@ -1543,7 +1545,6 @@ vmx_vmcleanup(void *arg)
if (error != 0)
panic("vmx_vmcleanup: vmclear error %d on vcpu 0", error);
- ept_vmcleanup(vmx);
free(vmx, M_VMX);
return;
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.h Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.h Sun Jul 7 02:49:48 2013 (r252910)
@@ -82,16 +82,15 @@ struct vmxstate {
/* virtual machine softc */
struct vmx {
- pml4_entry_t pml4ept[NPML4EPG];
struct vmcs vmcs[VM_MAXCPU]; /* one vmcs per virtual cpu */
char msr_bitmap[PAGE_SIZE];
struct msr_entry guest_msrs[VM_MAXCPU][GUEST_MSR_MAX_ENTRIES];
struct vmxctx ctx[VM_MAXCPU];
struct vmxcap cap[VM_MAXCPU];
struct vmxstate state[VM_MAXCPU];
+ vm_paddr_t eptphys;
struct vm *vm;
};
-CTASSERT((offsetof(struct vmx, pml4ept) & PAGE_MASK) == 0);
CTASSERT((offsetof(struct vmx, vmcs) & PAGE_MASK) == 0);
CTASSERT((offsetof(struct vmx, msr_bitmap) & PAGE_MASK) == 0);
CTASSERT((offsetof(struct vmx, guest_msrs) & 15) == 0);
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c Sun Jul 7 02:17:49 2013 (r252909)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c Sun Jul 7 02:49:48 2013 (r252910)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/pmap.h>
+#include <vm/vm_map.h>
#include <machine/vm.h>
#include <machine/pcb.h>
@@ -121,7 +122,7 @@ static struct vmm_ops *ops;
#define VMM_INIT() (ops != NULL ? (*ops->init)() : 0)
#define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0)
-#define VMINIT(vm) (ops != NULL ? (*ops->vminit)(vm): NULL)
+#define VMINIT(vm, pmap) (ops != NULL ? (*ops->vminit)(vm, pmap): NULL)
#define VMRUN(vmi, vcpu, rip) \
(ops != NULL ? (*ops->vmrun)(vmi, vcpu, rip) : ENXIO)
#define VMCLEANUP(vmi) (ops != NULL ? (*ops->vmcleanup)(vmi) : NULL)
@@ -290,7 +291,7 @@ vm_create(const char *name, struct vm **
vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO);
strcpy(vm->name, name);
- vm->cookie = VMINIT(vm);
+ vm->cookie = VMINIT(vm, vmspace_pmap(vmspace));
for (i = 0; i < VM_MAXCPU; i++) {
vcpu_init(vm, i);
More information about the svn-src-projects
mailing list