diff options
author | neel <neel@FreeBSD.org> | 2014-08-14 05:00:45 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2014-08-14 05:00:45 +0000 |
commit | 53369652fd9c456d33338f450a0c02cfdc1db689 (patch) | |
tree | 5566cbafb79adbaf2f048d3a0f72a369e84fcaf1 /sys/amd64/vmm | |
parent | 844b1fe2e7077d4a5e1e680a1ee4fa970c07ab2b (diff) | |
download | FreeBSD-src-53369652fd9c456d33338f450a0c02cfdc1db689.zip FreeBSD-src-53369652fd9c456d33338f450a0c02cfdc1db689.tar.gz |
Use the max guest memory address when creating its iommu domain.
Also, assert that the GPA being mapped in the domain is less than its maxaddr.
Reviewed by: grehan
Pointed out by: Anish Gupta (akgupt3@gmail.com)
Diffstat (limited to 'sys/amd64/vmm')
-rw-r--r-- | sys/amd64/vmm/intel/vtd.c | 5 | ||||
-rw-r--r-- | sys/amd64/vmm/vmm.c | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/sys/amd64/vmm/intel/vtd.c b/sys/amd64/vmm/intel/vtd.c index afd7155..be57aff 100644 --- a/sys/amd64/vmm/intel/vtd.c +++ b/sys/amd64/vmm/intel/vtd.c @@ -448,6 +448,11 @@ vtd_update_mapping(void *arg, vm_paddr_t gpa, vm_paddr_t hpa, uint64_t len, ptpindex = 0; ptpshift = 0; + KASSERT(gpa + len > gpa, ("%s: invalid gpa range %#lx/%#lx", __func__, + gpa, len)); + KASSERT(gpa + len <= dom->maxaddr, ("%s: gpa range %#lx/%#lx beyond " + "domain maxaddr %#lx", __func__, gpa, len, dom->maxaddr)); + if (gpa & PAGE_MASK) panic("vtd_create_mapping: unaligned gpa 0x%0lx", gpa); diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index 397035a..ae67c58 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -572,6 +572,21 @@ vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len) return (0); } +static vm_paddr_t +vm_maxmem(struct vm *vm) +{ + int i; + vm_paddr_t gpa, maxmem; + + maxmem = 0; + for (i = 0; i < vm->num_mem_segs; i++) { + gpa = vm->mem_segs[i].gpa + vm->mem_segs[i].len; + if (gpa > maxmem) + maxmem = gpa; + } + return (maxmem); +} + static void vm_gpa_unwire(struct vm *vm) { @@ -709,7 +724,7 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int func) if (ppt_assigned_devices(vm) == 0) { KASSERT(vm->iommu == NULL, ("vm_assign_pptdev: iommu must be NULL")); - maxaddr = vmm_mem_maxaddr(); + maxaddr = vm_maxmem(vm); vm->iommu = iommu_create_domain(maxaddr); error = vm_gpa_wire(vm); |