From 09a63560f4dedf45791beb8cd907b90eaaad26ea Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Wed, 3 Jul 2019 00:00:46 +0800 Subject: [PATCH] hv: vm_manage: minor fix about triple_fault_shutdown_vm The current implement will trigger shutdown vm request on the BSP VCPU on the VM, not the VCPU will trap out because triple fault. However, if the BSP VCPU on the VM is handling another IO emulation, it may overwrite the triple fault IO request on the vhm_request_buffer in function acrn_insert_request. The atomic operation of get_vhm_req_state can't guarantee the vhm_request_buffer will not access by another IO request if it is not running on the corresponding VCPU. So it should trigger triple fault shutdown VM IO request on the VCPU which trap out because of triple fault exception. Besides, rt_vm_pm1a_io_write will do the right thing which we shouldn't do it in triple_fault_shutdown_vm. Tracked-On: #1842 Signed-off-by: Li, Fei1 --- hypervisor/acpi_parser/acpi_ext.c | 1 + hypervisor/arch/x86/guest/vm_reset.c | 17 +++-------------- hypervisor/arch/x86/guest/vmexit.c | 2 +- hypervisor/include/arch/x86/guest/vm_reset.h | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/hypervisor/acpi_parser/acpi_ext.c b/hypervisor/acpi_parser/acpi_ext.c index e139101f2..4cda879e4 100644 --- a/hypervisor/acpi_parser/acpi_ext.c +++ b/hypervisor/acpi_parser/acpi_ext.c @@ -34,6 +34,7 @@ #include #include #include +#include #include /* Per ACPI spec: diff --git a/hypervisor/arch/x86/guest/vm_reset.c b/hypervisor/arch/x86/guest/vm_reset.c index ba4929855..936892afd 100644 --- a/hypervisor/arch/x86/guest/vm_reset.c +++ b/hypervisor/arch/x86/guest/vm_reset.c @@ -32,21 +32,13 @@ struct acpi_reset_reg *get_host_reset_reg_data(void) /** * @pre vm != NULL */ -void triple_fault_shutdown_vm(struct acrn_vm *vm) +void triple_fault_shutdown_vm(struct acrn_vcpu *vcpu) { - struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID); + struct acrn_vm *vm = vcpu->vm; if (is_postlaunched_vm(vm)) { struct io_request *io_req = &vcpu->req; - /* - * Hypervisor sets VM_POWERING_OFF to authenticate that the reboot request is - * actually from the guest itself, not from external entities. (for example acrn-dm) - */ - if (is_rt_vm(vm)) { - vm->state = VM_POWERING_OFF; - } - /* Device model emulates PM1A for post-launched VMs */ io_req->io_type = REQ_PORTIO; io_req->reqs.pio.direction = REQUEST_WRITE; @@ -258,9 +250,6 @@ void register_reset_port_handler(struct acrn_vm *vm) void shutdown_vm_from_idle(uint16_t pcpu_id) { struct acrn_vm *vm = get_vm_from_vmid(per_cpu(shutdown_vm_id, pcpu_id)); - const struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID); - if (vcpu->pcpu_id == pcpu_id) { - (void)shutdown_vm(vm); - } + (void)shutdown_vm(vm); } diff --git a/hypervisor/arch/x86/guest/vmexit.c b/hypervisor/arch/x86/guest/vmexit.c index a6d209f0c..698430b8b 100644 --- a/hypervisor/arch/x86/guest/vmexit.c +++ b/hypervisor/arch/x86/guest/vmexit.c @@ -255,7 +255,7 @@ static int32_t triple_fault_vmexit_handler(struct acrn_vcpu *vcpu) { pr_fatal("VM%d: triple fault @ guest RIP 0x%016llx, exit qualification: 0x%016llx", vcpu->vm->vm_id, exec_vmread(VMX_GUEST_RIP), exec_vmread(VMX_EXIT_QUALIFICATION)); - triple_fault_shutdown_vm(vcpu->vm); + triple_fault_shutdown_vm(vcpu); return 0; } diff --git a/hypervisor/include/arch/x86/guest/vm_reset.h b/hypervisor/include/arch/x86/guest/vm_reset.h index a10db6668..e0b05a772 100644 --- a/hypervisor/include/arch/x86/guest/vm_reset.h +++ b/hypervisor/include/arch/x86/guest/vm_reset.h @@ -16,7 +16,7 @@ struct acpi_reset_reg { void register_reset_port_handler(struct acrn_vm *vm); void shutdown_vm_from_idle(uint16_t pcpu_id); -void triple_fault_shutdown_vm(struct acrn_vm *vm); +void triple_fault_shutdown_vm(struct acrn_vcpu *vcpu); struct acpi_reset_reg *get_host_reset_reg_data(void); #endif /* VM_RESET_H_ */