diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index b3b4191ad..e8a76168b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -73,6 +73,12 @@ struct acrn_vm *get_vm_from_vmid(uint16_t vm_id) return &vm_array[vm_id]; } +/* return a pointer to the virtual machine structure of SOS VM */ +struct acrn_vm *get_sos_vm(void) +{ + return sos_vm_ptr; +} + /** * @pre vm_config != NULL */ diff --git a/hypervisor/common/io_req.c b/hypervisor/common/io_req.c index e4e10ae04..9776fe1e5 100644 --- a/hypervisor/common/io_req.c +++ b/hypervisor/common/io_req.c @@ -15,14 +15,15 @@ static void fire_vhm_interrupt(void) * use vLAPIC to inject vector to SOS vcpu 0 if vlapic is enabled * otherwise, send IPI hardcoded to BOOT_CPU_ID */ - struct acrn_vm *vm0; + struct acrn_vm *sos_vm; struct acrn_vcpu *vcpu; - vm0 = get_vm_from_vmid(0U); + sos_vm = get_sos_vm(); + if (sos_vm != NULL) { + vcpu = vcpu_from_vid(sos_vm, BOOT_CPU_ID); - vcpu = vcpu_from_vid(vm0, 0U); - - vlapic_set_intr(vcpu, acrn_vhm_vector, LAPIC_TRIG_EDGE); + vlapic_set_intr(vcpu, acrn_vhm_vector, LAPIC_TRIG_EDGE); + } } #if defined(HV_DEBUG) diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c index 51edd22be..4d17563d2 100644 --- a/hypervisor/debug/vuart.c +++ b/hypervisor/debug/vuart.c @@ -376,7 +376,7 @@ struct acrn_vuart *vuart_console_active(void) vm = get_vm_from_vmid(vuart_vmid); #else - struct acrn_vm *vm = get_vm_from_vmid(0U); + struct acrn_vm *vm = get_sos_vm(); #endif if (vm != NULL) { diff --git a/hypervisor/dm/vpci/sharing_mode.c b/hypervisor/dm/vpci/sharing_mode.c index 46e9d0b86..72a04d255 100644 --- a/hypervisor/dm/vpci/sharing_mode.c +++ b/hypervisor/dm/vpci/sharing_mode.c @@ -228,7 +228,7 @@ void vpci_reset_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf, } else { /* Return this PCI device to SOS */ if (vdev->vpci->vm == target_vm) { - vm = get_vm_from_vmid(0U); + vm = get_sos_vm(); if (vm != NULL) { vdev->vpci = &vm->vpci; diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index b162ff81c..6a6c597fe 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -314,6 +314,7 @@ extern struct acrn_vm_config vm_configs[]; bool is_sos_vm(const struct acrn_vm *vm); uint16_t find_free_vm_id(void); struct acrn_vm *get_vm_from_vmid(uint16_t vm_id); +struct acrn_vm *get_sos_vm(void); #ifdef CONFIG_PARTITION_MODE struct vm_config_arraies {