Skip to content

Commit 5a8703f

Browse files
donshengacrnsi
authored andcommitted
HV: need to unmap existing EPT mapping for a vbar base (gpa)
Only do the EPT mapping if vbar base (gpa) is not mapped to the same pbar (hpa) before. Need to unmap the existing mapping for a vbar base (gpa), otherwise, hv will throw an error. Tracked-On: #3241 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 0247c0b commit 5a8703f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,27 @@ static void vdev_pt_remap_generic_mem_vbar(struct pci_vdev *vdev, uint32_t idx)
281281

282282
/* If a new vbar is set (nonzero), set the EPT mapping accordingly */
283283
if (vbar_base != 0UL) {
284+
uint64_t hpa = gpa2hpa(vdev->vpci->vm, vbar_base);
284285
uint64_t pbar_base = get_pbar_base(vdev->pdev, idx); /* pbar (hpa) */
285286

286-
/* Map the physical BAR in the guest MMIO space */
287-
ept_add_mr(vm, (uint64_t *)(vm->arch_vm.nworld_eptp),
288-
pbar_base, /* HPA (pbar) */
289-
vbar_base, /* GPA (new vbar) */
290-
vbar->size,
291-
EPT_WR | EPT_RD | EPT_UNCACHED);
287+
if (hpa != pbar_base) {
288+
/* Unmap the existing mapping for new vbar */
289+
if (hpa != INVALID_HPA) {
290+
ept_del_mr(vm, (uint64_t *)(vm->arch_vm.nworld_eptp),
291+
vbar_base, /* GPA (new vbar) */
292+
vbar->size);
293+
}
294+
295+
/* Map the physical BAR in the guest MMIO space */
296+
ept_add_mr(vm, (uint64_t *)(vm->arch_vm.nworld_eptp),
297+
pbar_base, /* HPA (pbar) */
298+
vbar_base, /* GPA (new vbar) */
299+
vbar->size,
300+
EPT_WR | EPT_RD | EPT_UNCACHED);
292301

293-
/* Remember the previously mapped MMIO vbar */
294-
vdev->bar_base_mapped[idx] = vbar_base;
302+
/* Remember the previously mapped MMIO vbar */
303+
vdev->bar_base_mapped[idx] = vbar_base;
304+
}
295305
}
296306
}
297307

0 commit comments

Comments
 (0)