svn commit: r252911 - projects/bhyve_npt_pmap/sys/amd64/vmm

Neel Natu neel at FreeBSD.org
Sun Jul 7 04:16:33 UTC 2013


Author: neel
Date: Sun Jul  7 04:16:31 2013
New Revision: 252911
URL: http://svnweb.freebsd.org/changeset/base/252911

Log:
  Add mappings to guest's vm_map at the same time as creating the vm_object
  that backs those mappings.

Modified:
  projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c
  projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.c
  projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.h

Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c	Sun Jul  7 02:49:48 2013	(r252910)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/vmm.c	Sun Jul  7 04:16:31 2013	(r252911)
@@ -315,7 +315,7 @@ vm_free_mem_seg(struct vm *vm, struct me
 {
 
 	if (seg->object != NULL)
-		vmm_mem_free(seg->object);
+		vmm_mem_free(vm->vmspace, seg->gpa, seg->len);
 
 	bzero(seg, sizeof(*seg));
 }
@@ -430,7 +430,7 @@ vm_malloc(struct vm *vm, vm_paddr_t gpa,
 
 	seg = &vm->mem_segs[vm->num_mem_segs];
 
-	if ((object = vmm_mem_alloc(len)) == NULL)
+	if ((object = vmm_mem_alloc(vm->vmspace, gpa, len)) == NULL)
 		return (ENOMEM);
 
 	seg->gpa = gpa;

Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.c
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.c	Sun Jul  7 02:49:48 2013	(r252910)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.c	Sun Jul  7 04:16:31 2013	(r252911)
@@ -33,6 +33,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 
 #include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
+#include <vm/vm_map.h>
 #include <vm/vm_object.h>
 
 #include <machine/md_var.h>
@@ -47,22 +50,35 @@ vmm_mem_init(void)
 }
 
 vm_object_t
-vmm_mem_alloc(size_t size)
+vmm_mem_alloc(struct vmspace *vmspace, vm_paddr_t gpa, size_t len)
 {
+	int error;
 	vm_object_t obj;
 
-	if (size & PAGE_MASK)
-		panic("vmm_mem_alloc: invalid allocation size %lu", size);
+	if (gpa & PAGE_MASK)
+		panic("vmm_mem_alloc: invalid gpa %#lx", gpa);
+
+	if (len == 0 || (len & PAGE_MASK) != 0)
+		panic("vmm_mem_alloc: invalid allocation size %lu", len);
+
+	obj = vm_object_allocate(OBJT_DEFAULT, len >> PAGE_SHIFT);
+	if (obj != NULL) {
+		error = vm_map_find(&vmspace->vm_map, obj, 0, &gpa, len,
+				    VMFS_NO_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0);
+		if (error != KERN_SUCCESS) {
+			vm_object_deallocate(obj);
+			obj = NULL;
+		}
+	}
 
-	obj = vm_object_allocate(OBJT_DEFAULT, size >> PAGE_SHIFT);
 	return (obj);
 }
 
 void
-vmm_mem_free(vm_object_t obj)
+vmm_mem_free(struct vmspace *vmspace, vm_paddr_t gpa, size_t len)
 {
 
-	vm_object_deallocate(obj);
+	vm_map_remove(&vmspace->vm_map, gpa, gpa + len);
 }
 
 vm_paddr_t

Modified: projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.h
==============================================================================
--- projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.h	Sun Jul  7 02:49:48 2013	(r252910)
+++ projects/bhyve_npt_pmap/sys/amd64/vmm/vmm_mem.h	Sun Jul  7 04:16:31 2013	(r252911)
@@ -29,11 +29,12 @@
 #ifndef	_VMM_MEM_H_
 #define	_VMM_MEM_H_
 
+struct vmspace;
 struct vm_object;
 
 int		vmm_mem_init(void);
-struct vm_object *vmm_mem_alloc(size_t size);
-void		vmm_mem_free(struct vm_object *obj);
+struct vm_object *vmm_mem_alloc(struct vmspace *, vm_paddr_t gpa, size_t size);
+void		vmm_mem_free(struct vmspace *, vm_paddr_t gpa, size_t size);
 vm_paddr_t	vmm_mem_maxaddr(void);
 
 #endif


More information about the svn-src-projects mailing list