[PATCH v8 1/5] HV: Clear DM set guest_flags when shutdown vm


Kaige Fu
 

Currently, the previous configurations about guest_flags set by DM will
not be cleared when shutdown the vm. Then it might bring issue for the
next dm-launched vm.

For example, if we create one vm with LAPIC_PASSTHROUGH flag and shutdown it.
Then the next dm-launched vm will has the LAPIC_PASSTHROUGH flag set no matter
whether we set it in DM.

This patch clears all the DM set flags when shtudown vm.

Signed-off-by: Kaige Fu <kaige.fu@...>
Acked-by: Eddie Dong <eddie.dong@...>
---
hypervisor/arch/x86/guest/vm.c | 4 ++++
hypervisor/common/hypercall.c | 4 +++-
hypervisor/scenarios/sdc/vm_configurations.h | 5 +++++
3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c
index 28f31228..cebbc9cc 100644
--- a/hypervisor/arch/x86/guest/vm.c
+++ b/hypervisor/arch/x86/guest/vm.c
@@ -447,6 +447,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);
@@ -460,6 +461,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 d26ace3a..e8dbf63a 100644
--- a/hypervisor/common/hypercall.c
+++ b/hypervisor/common/hypercall.c
@@ -156,7 +156,9 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param)
vm_id = get_vmid_by_uuid(&cv.uuid[0]);
if (vm_id < CONFIG_MAX_VM_NUM) {
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/sdc/vm_configurations.h b/hypervisor/scenarios/sdc/vm_configurations.h
index 6c49865f..bba9515e 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 */
--
2.20.0

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.