svn commit: r241148 - projects/bhyve/sys/amd64/vmm

Neel Natu neel at FreeBSD.org
Wed Oct 3 01:18:52 UTC 2012


Author: neel
Date: Wed Oct  3 01:18:51 2012
New Revision: 241148
URL: http://svn.freebsd.org/changeset/base/241148

Log:
  Get rid of assumptions in the hypervisor that the host physical memory
  associated with guest physical memory is contiguous.
  
  Add check to vm_gpa2hpa() that the range indicated by [gpa,gpa+len) is all
  contained within a single 4KB page.

Modified:
  projects/bhyve/sys/amd64/vmm/vmm.c
  projects/bhyve/sys/amd64/vmm/vmm_instruction_emul.c

Modified: projects/bhyve/sys/amd64/vmm/vmm.c
==============================================================================
--- projects/bhyve/sys/amd64/vmm/vmm.c	Wed Oct  3 00:46:30 2012	(r241147)
+++ projects/bhyve/sys/amd64/vmm/vmm.c	Wed Oct  3 01:18:51 2012	(r241148)
@@ -404,6 +404,11 @@ vm_malloc(struct vm *vm, vm_paddr_t gpa,
 vm_paddr_t
 vm_gpa2hpa(struct vm *vm, vm_paddr_t gpa, size_t len)
 {
+	vm_paddr_t nextpage;
+
+	nextpage = rounddown(gpa + PAGE_SIZE, PAGE_SIZE);
+	if (len > nextpage - gpa)
+		panic("vm_gpa2hpa: invalid gpa/len: 0x%016lx/%lu", gpa, len);
 
 	return (VMMMAP_GET(vm->cookie, gpa));
 }

Modified: projects/bhyve/sys/amd64/vmm/vmm_instruction_emul.c
==============================================================================
--- projects/bhyve/sys/amd64/vmm/vmm_instruction_emul.c	Wed Oct  3 00:46:30 2012	(r241147)
+++ projects/bhyve/sys/amd64/vmm/vmm_instruction_emul.c	Wed Oct  3 01:18:51 2012	(r241148)
@@ -133,7 +133,7 @@ vmm_fetch_instruction(struct vm *vm, uin
 		      uint64_t cr3, struct vie *vie)
 {
 	int n, err;
-	uint64_t hpa, gpa, gpaend;
+	uint64_t hpa, gpa, gpaend, off;
 
 	/*
 	 * XXX cache previously fetched instructions using 'rip' as the tag
@@ -150,7 +150,8 @@ vmm_fetch_instruction(struct vm *vm, uin
 		if (err)
 			break;
 
-		n = min(inst_length - vie->num_valid, gpaend - gpa);
+		off = gpa & PAGE_MASK;
+		n = min(inst_length - vie->num_valid, PAGE_SIZE - off);
 
 		hpa = vm_gpa2hpa(vm, gpa, n);
 		if (hpa == -1)


More information about the svn-src-projects mailing list