Skip to content

Commit 2299926

Browse files
yonghuahlijinxia
authored andcommitted
HV: Refine 'hv_main()' function usage
'hv_main()' wraps several logic which has no dependencies each other(enable VMX, prepare to create service os VM..), in this case, split this function to make code logic clear. remove 'is_vm0_bsp()' & 'hv_main()' Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 9d9c97d commit 2299926

File tree

5 files changed

+11
-57
lines changed

5 files changed

+11
-57
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,11 @@ static void bsp_boot_post(void)
546546

547547
console_setup_timer();
548548

549-
/* Start initializing the VM for this CPU */
550-
if (hv_main(BOOT_CPU_ID) != 0) {
551-
panic("failed to start VM for bsp\n");
552-
}
549+
exec_vmxon_instr(BOOT_CPU_ID);
550+
551+
prepare_vm0();
552+
553+
default_idle();
553554

554555
/* Control should not come here */
555556
cpu_dead(BOOT_CPU_ID);
@@ -621,13 +622,12 @@ static void cpu_secondary_post(void)
621622
/* Wait for boot processor to signal all secondary cores to continue */
622623
pcpu_sync_sleep(&pcpu_sync, 0UL);
623624

624-
ret = hv_main(get_cpu_id());
625-
if (ret != 0) {
626-
panic("hv_main ret = %d\n", ret);
627-
}
625+
exec_vmxon_instr(get_cpu_id());
626+
627+
default_idle();
628628

629-
/* Control will only come here for secondary CPUs not configured for
630-
* use or if an error occurs in hv_main
629+
/* Control will only come here for secondary
630+
* CPUs not configured for use.
631631
*/
632632
cpu_dead(get_cpu_id());
633633
}

hypervisor/arch/x86/idt.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ external_interrupt_save_frame:
393393

394394
/*
395395
* We disable softirq path from interrupt IRET, since right now all IRQ
396-
* are for Guest, and we can execute softirq in hv_main() loop
396+
* are for Guest.
397397
*/
398398

399399
popq %rax

hypervisor/common/hv_main.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -107,48 +107,6 @@ void vcpu_thread(struct vcpu *vcpu)
107107
} while (1);
108108
}
109109

110-
static bool is_vm0_bsp(uint16_t pcpu_id)
111-
{
112-
#ifdef CONFIG_VM0_DESC
113-
return pcpu_id == vm0_desc.vm_pcpu_ids[0];
114-
#else
115-
return pcpu_id == BOOT_CPU_ID;
116-
#endif
117-
}
118-
119-
int32_t hv_main(uint16_t pcpu_id)
120-
{
121-
int32_t ret;
122-
123-
pr_info("%s, Starting common entry point for CPU %hu",
124-
__func__, pcpu_id);
125-
126-
if (pcpu_id != get_cpu_id()) {
127-
pr_err("%s, cpu_id %hu mismatch\n", __func__, pcpu_id);
128-
return -EINVAL;
129-
}
130-
131-
/* Enable virtualization extensions */
132-
ret = exec_vmxon_instr(pcpu_id);
133-
if (ret != 0) {
134-
return ret;
135-
}
136-
137-
/* X2APIC mode is disabled by default. */
138-
x2apic_enabled = false;
139-
140-
if (is_vm0_bsp(pcpu_id)) {
141-
ret = prepare_vm0();
142-
if (ret != 0) {
143-
return ret;
144-
}
145-
}
146-
147-
default_idle();
148-
149-
return 0;
150-
}
151-
152110
#ifdef HV_DEBUG
153111
void get_vmexit_profile(char *str_arg, int str_max)
154112
{

hypervisor/common/hypercall.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ int32_t hcall_create_vm(struct vm *vm, uint64_t param)
161161
{
162162
int32_t ret = 0;
163163
struct vm *target_vm = NULL;
164-
/* VM are created from hv_main() directly
165-
* Here we just return the vmid for DM
166-
*/
167164
struct acrn_create_vm cv;
168165
struct vm_description vm_desc;
169166

hypervisor/include/arch/x86/cpu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ extern struct cpuinfo_x86 boot_cpu_data;
261261
/* Function prototypes */
262262
void cpu_dead(uint16_t pcpu_id);
263263
void trampoline_start16(void);
264-
int32_t hv_main(uint16_t cpu_id);
265264
bool is_vapic_supported(void);
266265
bool is_vapic_intr_delivery_supported(void);
267266
bool is_vapic_virt_reg_supported(void);

0 commit comments

Comments
 (0)