Skip to content

Commit fe4484f

Browse files
lifeixlijinxia
authored andcommitted
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 <fei1.li@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
1 parent 574bdc3 commit fe4484f

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ static void get_cpu_name(void)
367367

368368
void bsp_boot_init(void)
369369
{
370+
int ret;
370371
uint64_t start_tsc = rdtsc();
371372

372373
/* Clear BSS */
@@ -541,14 +542,17 @@ void bsp_boot_init(void)
541542
console_setup_timer();
542543

543544
/* Start initializing the VM for this CPU */
544-
hv_main(CPU_BOOT_ID);
545+
ret = hv_main(CPU_BOOT_ID);
546+
if (ret != 0)
547+
panic("failed to start VM for bsp\n");
545548

546549
/* Control should not come here */
547550
cpu_dead(CPU_BOOT_ID);
548551
}
549552

550553
void cpu_secondary_init(void)
551554
{
555+
int ret;
552556
/* NOTE: Use of local / stack variables in this function is problematic
553557
* since the stack is switched in the middle of the function. For this
554558
* reason, the logical id is only temporarily stored in a static
@@ -605,7 +609,9 @@ void cpu_secondary_init(void)
605609
/* Wait for boot processor to signal all secondary cores to continue */
606610
pcpu_sync_sleep(&pcpu_sync, 0);
607611

608-
hv_main(get_cpu_id());
612+
ret = hv_main(get_cpu_id());
613+
if (ret != 0)
614+
panic("hv_main ret = %d\n", ret);
609615

610616
/* Control will only come here for secondary CPUs not configured for
611617
* use or if an error occurs in hv_main

hypervisor/common/hv_main.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,28 @@ static bool is_vm0_bsp(int pcpu_id)
138138

139139
int hv_main(int cpu_id)
140140
{
141-
int ret = 0;
141+
int ret;
142142

143143
pr_info("%s, Starting common entry point for CPU %d",
144144
__func__, cpu_id);
145-
ASSERT(cpu_id < phy_cpu_num, "cpu_id out of range");
146145

147-
ASSERT((uint64_t) cpu_id == get_cpu_id(),
148-
"cpu_id/tsc_aux mismatch");
146+
if (cpu_id >= phy_cpu_num) {
147+
pr_err("%s, cpu_id %d out of range %d\n",
148+
__func__, cpu_id, phy_cpu_num);
149+
return -EINVAL;
150+
}
151+
152+
if ((uint32_t) cpu_id != get_cpu_id()) {
153+
pr_err("%s, cpu_id %d mismatch\n", __func__, cpu_id);
154+
return -EINVAL;
155+
}
149156

150157
/* Enable virtualization extensions */
151158
ret = exec_vmxon_instr();
152-
ASSERT(ret == 0, "Unable to enable VMX!");
159+
if (ret != 0) {
160+
pr_err("%s, Unable to enable VMX!\n", __func__);
161+
return ret;
162+
}
153163

154164
/* X2APIC mode is disabled by default. */
155165
x2apic_enabled = false;
@@ -159,7 +169,7 @@ int hv_main(int cpu_id)
159169

160170
default_idle();
161171

162-
return ret;
172+
return 0;
163173
}
164174

165175
int get_vmexit_profile(char *str, int str_max)

0 commit comments

Comments
 (0)