From 0d59577fe436cb263c0338399054f6676cd3445e Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Tue, 30 Nov 2021 04:42:13 +0000 Subject: [PATCH] hv: Add stateful VM check before system shutdown This patch introduces stateful VM which represents a VM that has its own internal state such as a file cache, and adds a check before system shutdown to make sure that stateless VM does not block system shutdown. Tracked-On: #6571 Signed-off-by: Wang Yu Signed-off-by: Yifan Liu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 18 +++++++++++++++++- hypervisor/include/arch/x86/asm/guest/vm.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) 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);