aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBojan Novković <bnovkov@FreeBSD.org>2025-12-13 14:53:45 +0000
committerBojan Novković <bnovkov@FreeBSD.org>2025-12-15 15:41:57 +0000
commitf1809eab82a796845f126b703c01d4a31ccf2193 (patch)
treec121259eac63a36f0a3cde9a9879358bb9aceb99
parent43b07bdbc5d24febc7a904d16f05f921c478eaa7 (diff)
amd64/vmm.c: Fix an incorrect memory segment check in vm_iommu_{un}map
This change fixes two checks that conflated memory mapping and memory segment idenitifers. In both cases the code iterates over all memory mappings but passes the index to `vm_memseg_sysmem`, which is wrong. Fix this by passing the memory mapping's segment identifier instead. Differential Revision: https://reviews.freebsd.org/D54210 Reviewed by: markj Fixes: c76c2a19ae37 PR: 290920
-rw-r--r--sys/amd64/vmm/vmm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
index 2890e990633d..f3f9717129c9 100644
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -652,10 +652,10 @@ vm_iommu_map(struct vm *vm)
pmap = vmspace_pmap(vm_vmspace(vm));
for (i = 0; i < VM_MAX_MEMMAPS; i++) {
- if (!vm_memseg_sysmem(vm, i))
+ mm = &vm->mem.mem_maps[i];
+ if (!vm_memseg_sysmem(vm, mm->segid))
continue;
- mm = &vm->mem.mem_maps[i];
KASSERT((mm->flags & VM_MEMMAP_F_IOMMU) == 0,
("iommu map found invalid memmap %#lx/%#lx/%#x",
mm->gpa, mm->len, mm->flags));
@@ -700,10 +700,10 @@ vm_iommu_unmap(struct vm *vm)
sx_assert(&vm->mem.mem_segs_lock, SX_LOCKED);
for (i = 0; i < VM_MAX_MEMMAPS; i++) {
- if (!vm_memseg_sysmem(vm, i))
+ mm = &vm->mem.mem_maps[i];
+ if (!vm_memseg_sysmem(vm, mm->segid))
continue;
- mm = &vm->mem.mem_maps[i];
if ((mm->flags & VM_MEMMAP_F_IOMMU) == 0)
continue;
mm->flags &= ~VM_MEMMAP_F_IOMMU;