From fe4484f5a92707fbf519955b6866c6976d8c5f7d Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Mon, 28 May 2018 10:23:04 +0800 Subject: [PATCH] hv: move panic out of hv_main We cleanup ASSERT. This serial try to only panic when create SOS failed. Signed-off-by: Li, Fei1 Reviewed-by: Kevin Tian --- hypervisor/arch/x86/cpu.c | 10 ++++++++-- hypervisor/common/hv_main.c | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index c6bb36fad..bb7ba0614 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -367,6 +367,7 @@ static void get_cpu_name(void) void bsp_boot_init(void) { + int ret; uint64_t start_tsc = rdtsc(); /* Clear BSS */ @@ -541,7 +542,9 @@ void bsp_boot_init(void) console_setup_timer(); /* Start initializing the VM for this CPU */ - hv_main(CPU_BOOT_ID); + ret = hv_main(CPU_BOOT_ID); + if (ret != 0) + panic("failed to start VM for bsp\n"); /* Control should not come here */ cpu_dead(CPU_BOOT_ID); @@ -549,6 +552,7 @@ void bsp_boot_init(void) void cpu_secondary_init(void) { + int ret; /* NOTE: Use of local / stack variables in this function is problematic * since the stack is switched in the middle of the function. For this * reason, the logical id is only temporarily stored in a static @@ -605,7 +609,9 @@ void cpu_secondary_init(void) /* Wait for boot processor to signal all secondary cores to continue */ pcpu_sync_sleep(&pcpu_sync, 0); - hv_main(get_cpu_id()); + ret = hv_main(get_cpu_id()); + if (ret != 0) + panic("hv_main ret = %d\n", ret); /* Control will only come here for secondary CPUs not configured for * use or if an error occurs in hv_main diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index 176074100..d20c51f8d 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -138,18 +138,28 @@ static bool is_vm0_bsp(int pcpu_id) int hv_main(int cpu_id) { - int ret = 0; + int ret; pr_info("%s, Starting common entry point for CPU %d", __func__, cpu_id); - ASSERT(cpu_id < phy_cpu_num, "cpu_id out of range"); - ASSERT((uint64_t) cpu_id == get_cpu_id(), - "cpu_id/tsc_aux mismatch"); + if (cpu_id >= phy_cpu_num) { + pr_err("%s, cpu_id %d out of range %d\n", + __func__, cpu_id, phy_cpu_num); + return -EINVAL; + } + + if ((uint32_t) cpu_id != get_cpu_id()) { + pr_err("%s, cpu_id %d mismatch\n", __func__, cpu_id); + return -EINVAL; + } /* Enable virtualization extensions */ ret = exec_vmxon_instr(); - ASSERT(ret == 0, "Unable to enable VMX!"); + if (ret != 0) { + pr_err("%s, Unable to enable VMX!\n", __func__); + return ret; + } /* X2APIC mode is disabled by default. */ x2apic_enabled = false; @@ -159,7 +169,7 @@ int hv_main(int cpu_id) default_idle(); - return ret; + return 0; } int get_vmexit_profile(char *str, int str_max)