mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-19 18:02:06 +00:00
hv: create vm failed don't panic system
Just return error number to the caller. Signed-off-by: Li, Fei1 <fei1.li@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
This commit is contained in:
parent
6c8fc0a4df
commit
e0c329e4e9
@ -90,15 +90,19 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
||||
{
|
||||
unsigned int id;
|
||||
struct vm *vm;
|
||||
int status = 0;
|
||||
int status;
|
||||
|
||||
if ((vm_desc == NULL) || (rtn_vm == NULL))
|
||||
status = -EINVAL;
|
||||
if ((vm_desc == NULL) || (rtn_vm == NULL)) {
|
||||
pr_err("%s, invalid paramater\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (status == 0) {
|
||||
/* Allocate memory for virtual machine */
|
||||
vm = calloc(1, sizeof(struct vm));
|
||||
ASSERT(vm != NULL, "vm allocation failed");
|
||||
if (vm == NULL) {
|
||||
pr_err("%s, vm allocation failed\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Map Virtual Machine to its VM Description
|
||||
@ -114,8 +118,11 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
||||
|
||||
vm->hw.vcpu_array =
|
||||
calloc(1, sizeof(struct vcpu *) * vm->hw.num_vcpus);
|
||||
ASSERT(vm->hw.vcpu_array != NULL,
|
||||
"vcpu_array allocation failed");
|
||||
if (vm->hw.vcpu_array == NULL) {
|
||||
pr_err("%s, vcpu_array allocation failed\n", __func__);
|
||||
status = -ENOMEM;
|
||||
goto err1;
|
||||
}
|
||||
|
||||
for (id = 0; id < sizeof(long) * 8; id++)
|
||||
if (bitmap_test_and_set(id, &vmid_bitmap) == 0)
|
||||
@ -131,9 +138,13 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
||||
/* Only for SOS: Configure VM software information */
|
||||
/* For UOS: This VM software information is configure in DM */
|
||||
if (is_vm0(vm)) {
|
||||
prepare_vm0_memmap_and_e820(vm);
|
||||
status = prepare_vm0_memmap_and_e820(vm);
|
||||
if (status != 0)
|
||||
goto err2;
|
||||
#ifndef CONFIG_EFI_STUB
|
||||
status = init_vm0_boot_info(vm);
|
||||
if (status != 0)
|
||||
goto err2;
|
||||
#endif
|
||||
} else {
|
||||
/* populate UOS vm fields according to vm_desc */
|
||||
@ -149,9 +160,6 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
||||
list_add(&vm->list, &vm_list);
|
||||
spinlock_release(&vm_list_lock);
|
||||
|
||||
/* Ensure VM software information obtained */
|
||||
if (status == 0) {
|
||||
|
||||
/* Set up IO bit-mask such that VM exit occurs on
|
||||
* selected IO ranges
|
||||
*/
|
||||
@ -170,19 +178,31 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
||||
|
||||
/* Allocate full emulated vIOAPIC instance */
|
||||
vm->arch_vm.virt_ioapic = vioapic_init(vm);
|
||||
if (vm->arch_vm.virt_ioapic == NULL) {
|
||||
status = -ENODEV;
|
||||
goto err3;
|
||||
}
|
||||
|
||||
/* Populate return VM handle */
|
||||
*rtn_vm = vm;
|
||||
vm->sw.io_shared_page = NULL;
|
||||
|
||||
status = set_vcpuid_entries(vm);
|
||||
if (status)
|
||||
if (status != 0)
|
||||
goto err4;
|
||||
|
||||
vm->state = VM_CREATED;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
/* Return status to caller */
|
||||
err4:
|
||||
vioapic_cleanup(vm->arch_vm.virt_ioapic);
|
||||
err3:
|
||||
vpic_cleanup(vm);
|
||||
err2:
|
||||
free(vm->hw.vcpu_array);
|
||||
err1:
|
||||
free(vm);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -300,7 +320,8 @@ int prepare_vm0(void)
|
||||
struct vm_description *vm_desc = &vm0_desc;
|
||||
|
||||
ret = create_vm(vm_desc, &vm);
|
||||
ASSERT(ret == 0, "VM creation failed!");
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Allocate all cpus to vm0 at the beginning */
|
||||
for (i = 0; i < phy_cpu_num; i++)
|
||||
|
@ -159,8 +159,11 @@ int hv_main(int cpu_id)
|
||||
/* X2APIC mode is disabled by default. */
|
||||
x2apic_enabled = false;
|
||||
|
||||
if (is_vm0_bsp(cpu_id))
|
||||
prepare_vm0();
|
||||
if (is_vm0_bsp(cpu_id)) {
|
||||
ret = prepare_vm0();
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
default_idle();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user