diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 42434661e..d1747e243 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -444,16 +444,16 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ vpic_init(vm); } - /* Create virtual uart;*/ - init_vuart(vm, vm_config->vuart); - if (is_rt_vm(vm) || !is_postlaunched_vm(vm)) { vrtc_init(vm); } - vpci_init(vm); + init_vpci(vm); enable_iommu(); + /* Create virtual uart;*/ + init_vuart(vm, vm_config->vuart); + register_reset_port_handler(vm); /* vpic wire_mode default is INTR */ @@ -574,6 +574,20 @@ int32_t shutdown_vm(struct acrn_vm *vm) if (vm->state == VM_PAUSED) { vm->state = VM_POWERED_OFF; + vm_config = get_vm_config(vm->vm_id); + vm_config->guest_flags &= ~DM_OWNED_GUEST_FLAG_MASK; + + if (is_sos_vm(vm)) { + sbuf_reset(); + } + + deinit_vuart(vm); + + deinit_vpci(vm); + + /* Free EPT allocated resources assigned to VM */ + destroy_ept(vm); + mask = lapic_pt_enabled_pcpu_bitmap(vm); if (mask != 0UL) { ret = offline_lapic_pt_enabled_pcpus(vm, mask); @@ -582,25 +596,6 @@ int32_t shutdown_vm(struct acrn_vm *vm) foreach_vcpu(i, vm, vcpu) { offline_vcpu(vcpu); } - - vm_config = get_vm_config(vm->vm_id); - vm_config->guest_flags &= ~DM_OWNED_GUEST_FLAG_MASK; - - if (is_sos_vm(vm)) { - sbuf_reset(); - } - - vpci_cleanup(vm); - - deinit_vuart(vm); - - ptdev_release_all_entries(vm); - - /* Free iommu */ - destroy_iommu_domain(vm->iommu); - - /* Free EPT allocated resources assigned to VM */ - destroy_ept(vm); } else { ret = -EINVAL; } diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index d794259d3..e09f8caea 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -227,7 +228,7 @@ static int32_t vpci_mmio_cfg_access(struct io_request *io_req, void *private_dat * @pre vm != NULL * @pre vm->vm_id < CONFIG_MAX_VM_NUM */ -void vpci_init(struct acrn_vm *vm) +void init_vpci(struct acrn_vm *vm) { struct vm_io_range pci_cfgaddr_range = { .base = PCI_CONFIG_ADDR, @@ -270,7 +271,7 @@ void vpci_init(struct acrn_vm *vm) * @pre vm != NULL * @pre vm->vm_id < CONFIG_MAX_VM_NUM */ -void vpci_cleanup(struct acrn_vm *vm) +void deinit_vpci(struct acrn_vm *vm) { struct acrn_vm_config *vm_config; @@ -290,6 +291,11 @@ void vpci_cleanup(struct acrn_vm *vm) /* Unsupported VM type - Do nothing */ break; } + + ptdev_release_all_entries(vm); + + /* Free iommu */ + destroy_iommu_domain(vm->iommu); } /** diff --git a/hypervisor/include/dm/vpci.h b/hypervisor/include/dm/vpci.h index 13e76bb0b..e864a1dcb 100644 --- a/hypervisor/include/dm/vpci.h +++ b/hypervisor/include/dm/vpci.h @@ -149,8 +149,8 @@ struct acrn_vm; extern const struct pci_vdev_ops vhostbridge_ops; extern const struct pci_vdev_ops vpci_bridge_ops; -void vpci_init(struct acrn_vm *vm); -void vpci_cleanup(struct acrn_vm *vm); +void init_vpci(struct acrn_vm *vm); +void deinit_vpci(struct acrn_vm *vm); struct pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf); struct acrn_assign_pcidev; int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);