From c9c0d2167b3f6a2e22c818e39592a5ccdb0d9480 Mon Sep 17 00:00:00 2001 From: Zhang Chen Date: Tue, 27 Jun 2023 09:38:51 +0800 Subject: [PATCH] hypervisor/ivshmem: Fix ivshmem ivposition loss issue ACRN sets the ivposition to the VM_ID in ivshmem_server_bind_peer(). This value should be saved in the ivshmem_device until unbind. It is wrong to clear ivs_dev->mmio in the ivshmem_vbar_map(), Instead, it should clear the ivshmem_device structure in the create_ivshmem_device to ensure the same initial states after VM reboot case. Tracked-On: #8485 Signed-off-by: Zhang Chen Reviewed-by: Junjie Mao --- hypervisor/dm/vpci/ivshmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hypervisor/dm/vpci/ivshmem.c b/hypervisor/dm/vpci/ivshmem.c index 9390a20f7..6efac61b4 100644 --- a/hypervisor/dm/vpci/ivshmem.c +++ b/hypervisor/dm/vpci/ivshmem.c @@ -180,6 +180,11 @@ static void create_ivshmem_device(struct pci_vdev *vdev) } spinlock_release(&ivshmem_dev_lock); ASSERT((i < IVSHMEM_DEV_NUM), "failed to find and set ivshmem device"); + /* + * Clear ivshmem_device mmio to ensure the same initial + * states after VM reboot. + */ + memset(&ivshmem_dev[i].mmio, 0U, sizeof(uint32_t) * 4); } /* @@ -248,13 +253,11 @@ static void ivshmem_vbar_map(struct pci_vdev *vdev, uint32_t idx) { struct acrn_vm *vm = vpci2vm(vdev->vpci); struct pci_vbar *vbar = &vdev->vbars[idx]; - struct ivshmem_device *ivs_dev = (struct ivshmem_device *) vdev->priv_data; if ((idx == IVSHMEM_SHM_BAR) && (vbar->base_hpa != INVALID_HPA) && (vbar->base_gpa != 0UL)) { ept_add_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, vbar->base_hpa, vbar->base_gpa, vbar->size, EPT_RD | EPT_WR | EPT_WB | EPT_IGNORE_PAT); } else if ((idx == IVSHMEM_MMIO_BAR) && (vbar->base_gpa != 0UL)) { - (void)memset(&ivs_dev->mmio, 0U, sizeof(ivs_dev->mmio)); register_mmio_emulation_handler(vm, ivshmem_mmio_handler, vbar->base_gpa, (vbar->base_gpa + vbar->size), vdev, false); ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, vbar->base_gpa, round_page_up(vbar->size));