svn commit: r252866 - in projects/bhyve_npt_pmap/sys/amd64: include vmm vmm/amd vmm/intel
Neel Natu
neel at FreeBSD.org
Sat Jul 6 06:34:54 UTC 2013
Author: neel
Date: Sat Jul 6 06:34:53 2013
New Revision: 252866
URL: http://svnweb.freebsd.org/changeset/base/252866
Log:
Allocate guest vmspace at VM creation time and free it when the VM is
destroyed.
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/vmm.c
Modified: projects/bhyve_npt_pmap/sys/amd64/include/vmm.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/include/vmm.h Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/include/vmm.h Sat Jul 6 06:34:53 2013 (r252866)
@@ -39,6 +39,7 @@ struct seg_desc;
struct vm_exit;
struct vm_run;
struct vlapic;
+struct vmspace;
enum x2apic_state;
@@ -65,6 +66,8 @@ typedef int (*vmi_inject_event_t)(void *
uint32_t code, int code_valid);
typedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval);
typedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val);
+typedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max);
+typedef void (*vmi_vmspace_free)(struct vmspace *vmspace);
struct vmm_ops {
vmm_init_func_t init; /* module wide initialization */
@@ -82,6 +85,8 @@ struct vmm_ops {
vmi_inject_event_t vminject;
vmi_get_cap_t vmgetcap;
vmi_set_cap_t vmsetcap;
+ vmi_vmspace_alloc vmspace_alloc;
+ vmi_vmspace_free vmspace_free;
};
extern struct vmm_ops vmm_ops_intel;
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/amd/amdv.c Sat Jul 6 06:34:53 2013 (r252866)
@@ -151,6 +151,22 @@ amdv_setcap(void *arg, int vcpu, int typ
return (EINVAL);
}
+static struct vmspace *
+amdv_vmspace_alloc(vm_offset_t min, vm_offset_t max)
+{
+
+ printf("amdv_vmspace_alloc: not implemented\n");
+ return (NULL);
+}
+
+static void
+amdv_vmspace_free(struct vmspace *vmspace)
+{
+
+ printf("amdv_vmspace_free: not implemented\n");
+ return;
+}
+
struct vmm_ops vmm_ops_amd = {
amdv_init,
amdv_cleanup,
@@ -165,7 +181,9 @@ struct vmm_ops vmm_ops_amd = {
amdv_setdesc,
amdv_inject_event,
amdv_getcap,
- amdv_setcap
+ amdv_setcap,
+ amdv_vmspace_alloc,
+ amdv_vmspace_free,
};
static int
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.c Sat Jul 6 06:34:53 2013 (r252866)
@@ -37,6 +37,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/pmap.h>
+#include <vm/vm_map.h>
+#include <vm/vm_extern.h>
#include <machine/param.h>
#include <machine/cpufunc.h>
@@ -390,3 +392,31 @@ ept_invalidate_mappings(u_long pml4ept)
smp_rendezvous(NULL, invept_single_context, NULL, &invept_desc);
}
+
+struct vmspace *
+ept_vmspace_alloc(vm_offset_t min, vm_offset_t max)
+{
+ pmap_t pmap;
+ int success;
+ struct vmspace *vmspace;
+
+ vmspace = vmspace_alloc(min, max);
+ if (vmspace != NULL) {
+ /*
+ * Change the type of the pmap to PT_EPT.
+ */
+ pmap = vmspace_pmap(vmspace);
+ pmap_release(pmap);
+ success = pmap_pinit_type(pmap, PT_EPT);
+ if (!success)
+ panic("ept_vmspace_alloc: pmap_pinit_type() failed!");
+ }
+ return (vmspace);
+}
+
+void
+ept_vmspace_free(struct vmspace *vmspace)
+{
+
+ vmspace_free(vmspace);
+}
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/ept.h Sat Jul 6 06:34:53 2013 (r252866)
@@ -40,4 +40,6 @@ int ept_vmmmap_set(void *arg, vm_paddr_t
vm_paddr_t ept_vmmmap_get(void *arg, vm_paddr_t gpa);
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 Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/intel/vmx.c Sat Jul 6 06:34:53 2013 (r252866)
@@ -1867,5 +1867,7 @@ struct vmm_ops vmm_ops_intel = {
vmx_setdesc,
vmx_inject,
vmx_getcap,
- vmx_setcap
+ vmx_setcap,
+ ept_vmspace_alloc,
+ ept_vmspace_free,
};
Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c Sat Jul 6 06:24:19 2013 (r252865)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c Sat Jul 6 06:34:53 2013 (r252866)
@@ -44,11 +44,14 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <vm/vm.h>
+#include <vm/pmap.h>
#include <machine/vm.h>
#include <machine/pcb.h>
#include <machine/smp.h>
#include <x86/apicreg.h>
+#include <machine/pmap.h>
+#include <machine/vmparam.h>
#include <machine/vmm.h>
#include "vmm_host.h"
@@ -90,6 +93,7 @@ struct vcpu {
struct vm {
void *cookie; /* processor-specific data */
void *iommu; /* iommu-specific data */
+ struct vmspace *vmspace; /* guest's address space */
struct vcpu vcpu[VM_MAXCPU];
int num_mem_segs;
struct vm_memory_segment mem_segs[VM_MAX_MEMORY_SEGMENTS];
@@ -119,6 +123,10 @@ static struct vmm_ops *ops;
ENXIO)
#define VMMMAP_GET(vmi, gpa) \
(ops != NULL ? (*ops->vmmmap_get)(vmi, gpa) : ENXIO)
+#define VMSPACE_ALLOC(min, max) \
+ (ops != NULL ? (*ops->vmspace_alloc)(min, max) : NULL)
+#define VMSPACE_FREE(vmspace) \
+ (ops != NULL ? (*ops->vmspace_free)(vmspace) : ENXIO)
#define VMGETREG(vmi, vcpu, num, retval) \
(ops != NULL ? (*ops->vmgetreg)(vmi, vcpu, num, retval) : ENXIO)
#define VMSETREG(vmi, vcpu, num, val) \
@@ -259,6 +267,7 @@ vm_create(const char *name, struct vm **
{
int i;
struct vm *vm;
+ struct vmspace *vmspace;
vm_paddr_t maxaddr;
const int BSP = 0;
@@ -273,6 +282,10 @@ vm_create(const char *name, struct vm **
if (name == NULL || strlen(name) >= VM_MAX_NAMELEN)
return (EINVAL);
+ vmspace = VMSPACE_ALLOC(VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS);
+ if (vmspace == NULL)
+ return (ENOMEM);
+
vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO);
strcpy(vm->name, name);
vm->cookie = VMINIT(vm);
@@ -285,6 +298,7 @@ vm_create(const char *name, struct vm **
maxaddr = vmm_mem_maxaddr();
vm->iommu = iommu_create_domain(maxaddr);
vm_activate_cpu(vm, BSP);
+ vm->vmspace = vmspace;
*retvm = vm;
return (0);
@@ -345,6 +359,8 @@ vm_destroy(struct vm *vm)
iommu_destroy_domain(vm->iommu);
+ VMSPACE_FREE(vm->vmspace);
+
VMCLEANUP(vm->cookie);
free(vm, M_VM);
More information about the svn-src-projects
mailing list