mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-25 23:13:26 +00:00
hv: vm: refine the devices unregistration sequence of vm shutdown
Conceptually, the devices unregistration sequence of the shutdown process should be opposite to create. Tracked-On: #4550 Signed-off-by: Li Fei1 <fei1.li@intel.com>
This commit is contained in:
parent
3a326056fd
commit
572f755037
@ -444,16 +444,16 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
|
|||||||
vpic_init(vm);
|
vpic_init(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create virtual uart;*/
|
|
||||||
init_vuart(vm, vm_config->vuart);
|
|
||||||
|
|
||||||
if (is_rt_vm(vm) || !is_postlaunched_vm(vm)) {
|
if (is_rt_vm(vm) || !is_postlaunched_vm(vm)) {
|
||||||
vrtc_init(vm);
|
vrtc_init(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
vpci_init(vm);
|
init_vpci(vm);
|
||||||
enable_iommu();
|
enable_iommu();
|
||||||
|
|
||||||
|
/* Create virtual uart;*/
|
||||||
|
init_vuart(vm, vm_config->vuart);
|
||||||
|
|
||||||
register_reset_port_handler(vm);
|
register_reset_port_handler(vm);
|
||||||
|
|
||||||
/* vpic wire_mode default is INTR */
|
/* vpic wire_mode default is INTR */
|
||||||
@ -574,6 +574,20 @@ int32_t shutdown_vm(struct acrn_vm *vm)
|
|||||||
if (vm->state == VM_PAUSED) {
|
if (vm->state == VM_PAUSED) {
|
||||||
vm->state = VM_POWERED_OFF;
|
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);
|
mask = lapic_pt_enabled_pcpu_bitmap(vm);
|
||||||
if (mask != 0UL) {
|
if (mask != 0UL) {
|
||||||
ret = offline_lapic_pt_enabled_pcpus(vm, mask);
|
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) {
|
foreach_vcpu(i, vm, vcpu) {
|
||||||
offline_vcpu(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 {
|
} else {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <ptdev.h>
|
||||||
#include <vm.h>
|
#include <vm.h>
|
||||||
#include <vtd.h>
|
#include <vtd.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
@ -227,7 +228,7 @@ static int32_t vpci_mmio_cfg_access(struct io_request *io_req, void *private_dat
|
|||||||
* @pre vm != NULL
|
* @pre vm != NULL
|
||||||
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
|
* @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 = {
|
struct vm_io_range pci_cfgaddr_range = {
|
||||||
.base = PCI_CONFIG_ADDR,
|
.base = PCI_CONFIG_ADDR,
|
||||||
@ -270,7 +271,7 @@ void vpci_init(struct acrn_vm *vm)
|
|||||||
* @pre vm != NULL
|
* @pre vm != NULL
|
||||||
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
|
* @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;
|
struct acrn_vm_config *vm_config;
|
||||||
|
|
||||||
@ -290,6 +291,11 @@ void vpci_cleanup(struct acrn_vm *vm)
|
|||||||
/* Unsupported VM type - Do nothing */
|
/* Unsupported VM type - Do nothing */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptdev_release_all_entries(vm);
|
||||||
|
|
||||||
|
/* Free iommu */
|
||||||
|
destroy_iommu_domain(vm->iommu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,8 +149,8 @@ struct acrn_vm;
|
|||||||
|
|
||||||
extern const struct pci_vdev_ops vhostbridge_ops;
|
extern const struct pci_vdev_ops vhostbridge_ops;
|
||||||
extern const struct pci_vdev_ops vpci_bridge_ops;
|
extern const struct pci_vdev_ops vpci_bridge_ops;
|
||||||
void vpci_init(struct acrn_vm *vm);
|
void init_vpci(struct acrn_vm *vm);
|
||||||
void vpci_cleanup(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 pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf);
|
||||||
struct acrn_assign_pcidev;
|
struct acrn_assign_pcidev;
|
||||||
int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);
|
int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);
|
||||||
|
Loading…
Reference in New Issue
Block a user