diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 28f312280..9ae0824be 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -308,6 +308,7 @@ static void prepare_sos_vm_memmap(struct acrn_vm *vm) /** * @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL + * @pre vm->state == VM_STATE_INVALID */ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_vm **rtn_vm) { diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index c4af39182..4cfb785d4 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -154,7 +154,8 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param) (void)memset((void *)&cv, 0U, sizeof(cv)); if (copy_from_gpa(vm, &cv, param, sizeof(cv)) == 0) { vm_id = get_vmid_by_uuid(&cv.uuid[0]); - if (vm_id < CONFIG_MAX_VM_NUM) { + 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;