Skip to content

Commit f85106d

Browse files
Shuo A Liuacrnsi
authored andcommitted
hv: Do not reset vcpu thread's stack when reset_vcpu
vcpu thread's stack shouldn't follow reset_vcpu to reset. There is also a bug here: while vcpu B thread set vcpu->running to false, other vcpu A thread will treat the vcpu B is paused while it has not been switch out completely, then reset_vcpu will reset the vcpu B thread's stack and corrupt its running context. This patch will remove the vcpu thread's stack reset from reset_vcpu. With the change, we need do init_vmcs between vcpu startup address be settled and scheduled in. And switch_to_idle() is not needed anymore as S3 thread's stack will not be reset. Tracked-On: #3813 Signed-off-by: Fengwei Yin <fengwei.yin@intel.com> Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
1 parent 3072b6f commit f85106d

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ void reset_vcpu(struct acrn_vcpu *vcpu)
639639
vcpu->arch.exception_info.exception = VECTOR_INVALID;
640640
vcpu->arch.cur_context = NORMAL_WORLD;
641641
vcpu->arch.irq_window_enabled = false;
642-
vcpu->thread_obj.host_sp = build_stack_frame(vcpu);
643642
(void)memset((void *)vcpu->arch.vmcs, 0U, PAGE_SIZE);
644643

645644
for (i = 0; i < NR_WORLD; i++) {

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,8 @@ vlapic_process_init_sipi(struct acrn_vcpu* target_vcpu, uint32_t mode, uint32_t
11701170
target_vcpu->vcpu_id,
11711171
target_vcpu->vm->vm_id);
11721172
set_vcpu_startup_entry(target_vcpu, (icr_low & APIC_VECTOR_MASK) << 12U);
1173+
/* init vmcs after set_vcpu_startup_entry */
1174+
init_vmcs(target_vcpu);
11731175
schedule_vcpu(target_vcpu);
11741176
}
11751177
}

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ void start_vm(struct acrn_vm *vm)
647647

648648
/* Only start BSP (vid = 0) and let BSP start other APs */
649649
bsp = vcpu_from_vid(vm, BOOT_CPU_ID);
650+
init_vmcs(bsp);
650651
schedule_vcpu(bsp);
651652
}
652653

@@ -772,7 +773,6 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec)
772773

773774
init_vmcs(bsp);
774775
schedule_vcpu(bsp);
775-
switch_to_idle(default_idle);
776776
}
777777

778778
/**

hypervisor/arch/x86/guest/vmcs.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,7 @@ static void init_exit_ctrl(const struct acrn_vcpu *vcpu)
496496
exec_vmwrite64(VMX_EXIT_MSR_LOAD_ADDR_FULL, hva2hpa((void *)vcpu->arch.msr_area.host));
497497
}
498498

499-
/**
500-
* @pre vcpu != NULL
501-
*/
502-
void init_vmcs(struct acrn_vcpu *vcpu)
499+
static void do_init_vmcs(struct acrn_vcpu *vcpu)
503500
{
504501
uint64_t vmx_rev_id;
505502
uint64_t vmcs_pa;
@@ -532,6 +529,20 @@ void init_vmcs(struct acrn_vcpu *vcpu)
532529
init_exit_ctrl(vcpu);
533530
}
534531

532+
/**
533+
* @pre vcpu != NULL
534+
*/
535+
void init_vmcs(struct acrn_vcpu *vcpu)
536+
{
537+
uint16_t pcpu_id = vcpu->pcpu_id;
538+
539+
if (pcpu_id == get_pcpu_id()) {
540+
do_init_vmcs(vcpu);
541+
} else {
542+
smp_call_function((1UL << pcpu_id), (smp_call_func_t)do_init_vmcs, vcpu);
543+
}
544+
}
545+
535546
void switch_apicv_mode_x2apic(struct acrn_vcpu *vcpu)
536547
{
537548
uint32_t value32;

hypervisor/common/hv_main.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ void vcpu_thread(struct thread_object *obj)
2121
int32_t ret = 0;
2222

2323
do {
24-
/* If vcpu is not launched, we need to do init_vmcs first */
25-
if (!vcpu->launched) {
26-
init_vmcs(vcpu);
27-
}
28-
2924
if (!is_lapic_pt_enabled(vcpu)) {
3025
CPU_IRQ_DISABLE();
3126
}

0 commit comments

Comments
 (0)