diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 5d2718c97..6dc7c2256 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -98,14 +98,6 @@ bool is_created_vm(const struct acrn_vm *vm) return (vm->state == VM_CREATED); } -/** - * @pre vm != NULL - */ -bool is_paused_vm(const struct acrn_vm *vm) -{ - return (vm->state == VM_PAUSED); -} - bool is_service_vm(const struct acrn_vm *vm) { return (vm != NULL) && (get_vm_config(vm->vm_id)->load_order == SERVICE_VM); @@ -869,7 +861,7 @@ void arch_vm_prepare_bsp(struct acrn_vcpu *bsp) * @pre vm != NULL * @pre vm->state == VM_PAUSED */ -int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode) +int32_t arch_reset_vm(struct acrn_vm *vm) { uint16_t i; uint64_t mask; @@ -890,16 +882,11 @@ int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode) */ vm->arch_vm.vlapic_mode = VM_VLAPIC_XAPIC; - if ((mode == POWER_ON_RESET) && is_service_vm(vm)) { - (void)prepare_os_image(vm); - } - reset_vm_ioreqs(vm); reset_vioapics(vm); destroy_secure_world(vm, false); vm->arch_vm.sworld_control.flag.active = 0UL; vm->arch_vm.iwkey_backup_status = 0UL; - vm->state = VM_CREATED; return ret; } @@ -933,7 +920,7 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec) { struct acrn_vcpu *bsp = vcpu_from_vid(vm, BSP_CPU_ID); - reset_vm(vm, RESUME_FROM_S3); + reset_vm(vm); /* When Service VM resume from S3, it will return to real mode * with entry set to wakeup_vec. diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index ac8f034c6..5e84cf9fc 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -348,7 +348,7 @@ int32_t hcall_reset_vm(__unused struct acrn_vcpu *vcpu, struct acrn_vm *target_v if (is_paused_vm(target_vm)) { /* TODO: check target_vm guest_flags */ - ret = reset_vm(target_vm, COLD_RESET); + ret = reset_vm(target_vm); } return ret; } diff --git a/hypervisor/common/vm.c b/hypervisor/common/vm.c index 395cda4b9..cd357ef07 100644 --- a/hypervisor/common/vm.c +++ b/hypervisor/common/vm.c @@ -15,6 +15,14 @@ static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE); static struct acrn_vm *service_vm_ptr = NULL; +/** + * @pre vm != NULL + */ +bool is_paused_vm(const struct acrn_vm *vm) +{ + return (vm->state == VM_PAUSED); +} + /** * @pre vm_config != NULL */ @@ -243,3 +251,21 @@ int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *v return status; } + +/** + * "Warm" reset a VM. + * To "Cold" reset a VM, simply destroy and re-create. + * + * @pre vm->state == VM_PAUSED + */ +int32_t reset_vm(struct acrn_vm *vm) +{ + int32_t ret = -1; + + ret = arch_reset_vm(vm); + if (ret == 0) { + vm->state = VM_CREATED; + } + + return ret; +} diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index 09912bfa8..96a1227ef 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -131,7 +131,6 @@ void make_shutdown_vm_request(uint16_t pcpu_id); bool need_shutdown_vm(uint16_t pcpu_id); void poweroff_if_rt_vm(struct acrn_vm *vm); void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec); -int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode); bool is_created_vm(const struct acrn_vm *vm); bool is_service_vm(const struct acrn_vm *vm); bool is_postlaunched_vm(const struct acrn_vm *vm); diff --git a/hypervisor/include/common/vm.h b/hypervisor/include/common/vm.h index f868c99c6..ac7ced597 100644 --- a/hypervisor/include/common/vm.h +++ b/hypervisor/include/common/vm.h @@ -153,12 +153,14 @@ void arch_trigger_level_intr(__unused struct acrn_vm *vm, int32_t arch_init_vm(struct acrn_vm *vm, struct acrn_vm_config *vm_config); int32_t arch_deinit_vm(struct acrn_vm *vm); void arch_vm_prepare_bsp(struct acrn_vcpu *bsp); +int32_t arch_reset_vm(struct acrn_vm *vm); int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *vm_config, struct acrn_vm **rtn_vm); void launch_vms(uint16_t pcpu_id); void start_vm(struct acrn_vm *vm); void pause_vm(struct acrn_vm *vm); int32_t destroy_vm(struct acrn_vm *vm); +int32_t reset_vm(struct acrn_vm *vm); #endif /* !ASSEMBLER */