diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 897aa8b8e..49410024b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -589,9 +589,7 @@ int32_t shutdown_vm(struct acrn_vm *vm) ptdev_release_all_entries(vm); /* Free iommu */ - if (vm->iommu != NULL) { - destroy_iommu_domain(vm->iommu); - } + destroy_iommu_domain(vm->iommu); /* Free EPT allocated resources assigned to VM */ destroy_ept(vm); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 453537275..84ef55e3c 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -874,7 +874,6 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param) uint16_t bdf; struct acrn_vm *target_vm = get_vm_from_vmid(vmid); bool bdf_valid = true; - bool iommu_valid = true; if (!is_poweroff_vm(target_vm) && is_postlaunched_vm(target_vm)) { if (param < 0x10000UL) { @@ -888,24 +887,7 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param) } } - /* create a iommu domain for target VM if not created */ - if (bdf_valid && (target_vm->iommu == NULL)) { - if (target_vm->arch_vm.nworld_eptp == NULL) { - pr_err("%s, EPT of VM not set!\n", - __func__, target_vm->vm_id); - iommu_valid = false; - ret = -EPERM; - } else { - /* TODO: how to get vm's address width? */ - target_vm->iommu = create_iommu_domain(vmid, - hva2hpa(target_vm->arch_vm.nworld_eptp), 48U); - if (target_vm->iommu == NULL) { - iommu_valid = false; - ret = -ENODEV; - } - } - } - if (bdf_valid && iommu_valid) { + if (bdf_valid) { ret = move_pt_device(vm->iommu, target_vm->iommu, (uint8_t)(bdf >> 8U), (uint8_t)(bdf & 0xffU)); } diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index b9ff255c1..d77ab50aa 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -186,8 +186,6 @@ static bool pci_cfgdata_io_write(struct acrn_vm *vm, uint16_t addr, size_t bytes */ void vpci_init(struct acrn_vm *vm) { - int32_t ret = -EINVAL; - struct vm_io_range pci_cfgaddr_range = { .flags = IO_ATTR_RW, .base = PCI_CONFIG_ADDR, @@ -203,23 +201,14 @@ void vpci_init(struct acrn_vm *vm) struct acrn_vm_config *vm_config; vm->vpci.vm = vm; + vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U); + /* Build up vdev list for vm */ + vpci_init_vdevs(vm); vm_config = get_vm_config(vm->vm_id); switch (vm_config->load_order) { case PRE_LAUNCHED_VM: case SOS_VM: - vm->iommu = create_iommu_domain(vm->vm_id, hva2hpa(vm->arch_vm.nworld_eptp), 48U); - /* Build up vdev list for vm */ - vpci_init_vdevs(vm); - ret = 0; - break; - - default: - /* Nothing to do for other vm types */ - break; - } - - if (ret == 0) { /* * SOS: intercept port CF8 only. * UOS or pre-launched VM: register handler for CF8 only and I/O requests to CF9/CFA/CFB are @@ -231,6 +220,11 @@ void vpci_init(struct acrn_vm *vm) /* Intercept and handle I/O ports CFC -- CFF */ register_pio_emulation_handler(vm, PCI_CFGDATA_PIO_IDX, &pci_cfgdata_range, pci_cfgdata_io_read, pci_cfgdata_io_write); + break; + + default: + /* Nothing to do for other vm types */ + break; } }