Skip to content

Commit 26627bd

Browse files
fyin1wenlingz
authored andcommitted
hv: add function to set AP entry
With reset_vcpu_regs as pre-condition, we only need to set cs_selector and cs_base for AP. We call set_ap_entry in two places: 1. When emulation AP SIPI 2. When sos BSP resume from S3. The BSP is resumed to real mode with entry set to wakeup_vec. We call set_ap_entry API here with entry twisted from wakeup_vec. Tracked-On: #1231 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent f7b11c8 commit 26627bd

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ void reset_vcpu_regs(struct vcpu *vcpu)
252252
set_vcpu_regs(vcpu, &realmode_init_regs);
253253
}
254254

255+
void set_ap_entry(struct vcpu *vcpu, uint64_t entry)
256+
{
257+
struct ext_context *ectx;
258+
259+
ectx = &(vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].ext_ctx);
260+
ectx->cs.selector = (uint16_t)((entry >> 4UL) & 0xFFFFU);
261+
ectx->cs.base = ectx->cs.selector << 4UL;
262+
263+
vcpu_set_rip(vcpu, 0UL);
264+
}
265+
255266
/***********************************************************************
256267
*
257268
* @pre vm != NULL && rtn_vcpu_handle != NULL

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,11 @@ vlapic_icrlo_write_handler(struct acrn_vlapic *vlapic)
12071207
continue;
12081208
}
12091209

1210-
target_vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
1211-
target_vcpu->arch_vcpu.sipi_vector = vec;
12121210
pr_err("Start Secondary VCPU%hu for VM[%d]...",
12131211
target_vcpu->vcpu_id,
12141212
target_vcpu->vm->vm_id);
1213+
target_vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
1214+
set_ap_entry(target_vcpu, vec << 12U);
12151215
schedule_vcpu(target_vcpu);
12161216
} else if (mode == APIC_DELMODE_SMI) {
12171217
pr_info("vlapic: SMI IPI do not support\n");

hypervisor/arch/x86/guest/vm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,14 @@ void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec)
374374
vm->state = VM_STARTED;
375375

376376
reset_vcpu(bsp);
377-
bsp->entry_addr = (void *)(uint64_t)wakeup_vec;
377+
378+
/* When SOS resume from S3, it will return to real mode
379+
* with entry set to wakeup_vec.
380+
*/
378381
bsp->arch_vcpu.cpu_mode = CPU_MODE_REAL;
379-
init_vmcs(bsp);
382+
set_ap_entry(bsp, wakeup_vec);
380383

384+
init_vmcs(bsp);
381385
schedule_vcpu(bsp);
382386
}
383387

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ uint64_t vcpu_get_pat_ext(struct vcpu *vcpu);
287287
void vcpu_set_pat_ext(struct vcpu *vcpu, uint64_t val);
288288
void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs);
289289
void reset_vcpu_regs(struct vcpu *vcpu);
290+
void set_ap_entry(struct vcpu *vcpu, uint64_t entry);
290291

291292
static inline bool is_long_mode(struct vcpu *vcpu)
292293
{

0 commit comments

Comments
 (0)