diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 447144728..abea419e0 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -156,6 +156,22 @@ bool is_rt_vm(const struct acrn_vm *vm) return ((vm_config->guest_flags & GUEST_FLAG_RT) != 0U); } +/** + * @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM + * + * Stateful VM refers to VM that has its own state (such as internal file cache), + * and will experience state loss (file system corruption) if force powered down. + */ +bool is_stateful_vm(const struct acrn_vm *vm) +{ + struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id); + + /* TEE VM doesn't has its own state. The TAs will do the content + * flush by themselves, HV and OS doesn't need to care about the state. + */ + return ((vm_config->guest_flags & GUEST_FLAG_TEE) == 0U); +} + /** * @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM */ @@ -751,7 +767,7 @@ static bool is_ready_for_system_shutdown(void) for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) { vm = get_vm_from_vmid(vm_id); /* TODO: Update code to cover hybrid mode */ - if (!is_poweroff_vm(vm)) { + if (!is_poweroff_vm(vm) && is_stateful_vm(vm)) { ret = false; break; } diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index b01bfac8e..aa22fc783 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -256,6 +256,7 @@ void vrtc_init(struct acrn_vm *vm); bool is_lapic_pt_configured(const struct acrn_vm *vm); bool is_rt_vm(const struct acrn_vm *vm); +bool is_stateful_vm(const struct acrn_vm *vm); bool is_nvmx_configured(const struct acrn_vm *vm); bool is_vcat_configured(const struct acrn_vm *vm); bool is_static_configured_vm(const struct acrn_vm *vm);