Skip to content

Commit ed1bdcb

Browse files
donshengacrnsi
authored andcommitted
HV: add uint64_t bar_base_mapped[PCI_BAR_COUNT] to struct pci_vdev
To remember the previously mapped/registered vbar base For the following reasons: register_mmio_emulation_handler() will throw an error if the the same addr_lo is alreayd registered before We are going to remove the base member from struct pci_bar, so we cannot use vdev->bar[idx].base in the code any more In subsequent commits, we will assume vdev_pt_remap_generic_mem_vbar() is called after a new vbar base is set, mainly because of 64-bit mmio bar handling, so we need a separate bar_base_mapped[] array to track the previously mapped vbar bases. Tracked-On: #3241 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com>
1 parent 65ca6ae commit ed1bdcb

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,12 @@ void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev)
245245
addr_lo = round_page_down(msix->mmio_gpa + msix->table_offset);
246246
}
247247

248-
register_mmio_emulation_handler(vdev->vpci->vm, vmsix_table_mmio_access_handler,
249-
addr_lo, addr_hi, vdev);
248+
if (vdev->bar_base_mapped[msix->table_bar] != addr_lo) {
249+
register_mmio_emulation_handler(vdev->vpci->vm, vmsix_table_mmio_access_handler,
250+
addr_lo, addr_hi, vdev);
251+
/* Remember the previously registered MMIO vbar base */
252+
vdev->bar_base_mapped[msix->table_bar] = addr_lo;
253+
}
250254
}
251255
}
252256

@@ -258,15 +262,16 @@ void vdev_pt_remap_msix_table_bar(struct pci_vdev *vdev)
258262
* @pre vdev->vpci != NULL
259263
* @pre vdev->vpci->vm != NULL
260264
*/
261-
static void vdev_pt_remap_generic_mem_vbar(const struct pci_vdev *vdev, uint32_t idx, uint32_t new_base)
265+
static void vdev_pt_remap_generic_mem_vbar(struct pci_vdev *vdev, uint32_t idx, uint32_t new_base)
262266
{
263267
struct acrn_vm *vm = vdev->vpci->vm;
264268

265269
/* If the old vbar is mapped before, unmap it first */
266-
if (vdev->bar[idx].base != 0UL) {
270+
if (vdev->bar_base_mapped[idx] != 0UL) {
267271
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
268-
vdev->bar[idx].base, /* GPA (old vbar) */
272+
vdev->bar_base_mapped[idx], /* GPA (old vbar) */
269273
vdev->bar[idx].size);
274+
vdev->bar_base_mapped[idx] = 0UL;
270275
}
271276

272277
if (new_base != 0U) {
@@ -278,6 +283,9 @@ static void vdev_pt_remap_generic_mem_vbar(const struct pci_vdev *vdev, uint32_t
278283
new_base, /*GPA*/
279284
vdev->bar[idx].size,
280285
EPT_WR | EPT_RD | EPT_UNCACHED);
286+
287+
/* Remember the previously mapped MMIO vbar */
288+
vdev->bar_base_mapped[idx] = (uint64_t)new_base;
281289
}
282290
}
283291

hypervisor/include/dm/vpci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ struct pci_vdev {
7777
uint32_t nr_bars; /* 6 for normal device, 2 for bridge, 1 for cardbus */
7878
struct pci_bar bar[PCI_BAR_COUNT];
7979

80+
/* Remember the previously mapped/registered vbar base for undo purpose */
81+
uint64_t bar_base_mapped[PCI_BAR_COUNT];
82+
8083
struct pci_msi msi;
8184
struct pci_msix msix;
8285

0 commit comments

Comments
 (0)