diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 0bb591c06..f5dec506d 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -457,6 +457,7 @@ int32_t shutdown_vm(struct acrn_vm *vm) { uint16_t i; struct acrn_vcpu *vcpu = NULL; + struct acrn_vm_config *vm_config = NULL; int32_t ret; pause_vm(vm); @@ -470,6 +471,9 @@ int32_t shutdown_vm(struct acrn_vm *vm) offline_vcpu(vcpu); } + vm_config = get_vm_config(vm->vm_id); + vm_config->guest_flags &= ~DM_OWNED_GUEST_FLAG_MASK; + ptdev_release_all_entries(vm); vpci_cleanup(vm); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 9d00c9f9b..7a949f311 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -157,7 +157,9 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param) if ((vm_id < CONFIG_MAX_VM_NUM) && (!is_valid_vm(get_vm_from_vmid(vm_id)))) { vm_config = get_vm_config(vm_id); - vm_config->guest_flags |= cv.vm_flag; + + /* Filter out the bits should not set by DM and then assign it to guest_flags */ + vm_config->guest_flags |= (cv.vm_flag & DM_OWNED_GUEST_FLAG_MASK); /* GUEST_FLAG_RT must be set if we have GUEST_FLAG_LAPIC_PASSTHROUGH set in guest_flags */ if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U) diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.h b/hypervisor/scenarios/logical_partition/vm_configurations.h index 6d9a4cd34..24b1c9309 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.h +++ b/hypervisor/scenarios/logical_partition/vm_configurations.h @@ -7,6 +7,9 @@ #ifndef VM_CONFIGURATIONS_H #define VM_CONFIGURATIONS_H +/* Bits mask of guest flags that can be programmed by device model. Other bits are set by hypervisor only */ +#define DM_OWNED_GUEST_FLAG_MASK 0UL + #define CONFIG_MAX_VM_NUM 2U /* The VM CONFIGs like: diff --git a/hypervisor/scenarios/sdc/vm_configurations.h b/hypervisor/scenarios/sdc/vm_configurations.h index 6c49865f9..bba9515e3 100644 --- a/hypervisor/scenarios/sdc/vm_configurations.h +++ b/hypervisor/scenarios/sdc/vm_configurations.h @@ -9,4 +9,9 @@ #define CONFIG_MAX_VM_NUM 2U +/* Bits mask of guest flags that can be programmed by device model. Other bits are set by hypervisor only */ +#define DM_OWNED_GUEST_FLAG_MASK (GUEST_FLAG_SECURE_WORLD_ENABLED | GUEST_FLAG_LAPIC_PASSTHROUGH | \ + GUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING) + + #endif /* VM_CONFIGURATIONS_H */