Skip to content

Commit 0f9d964

Browse files
fyin1NanlinXie
authored andcommitted
hv: add function to return to VM0
Emulate VM0 resume from S3 state: - reset BSP of VM0 - set the BSP entry to saved VM0 wakeup vec and set BSP to real mode - start BSP To match trampoline_spinlock release on ACRN Sx resume path, acquire trampoline_spinlock if ACRN Sx enter fails. Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 02d8191 commit 0f9d964

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,28 @@ void resume_vm(struct vm *vm)
285285
vm->state = VM_STARTED;
286286
}
287287

288+
/* Resume vm from S3 state
289+
*
290+
* To resume vm after guest enter S3 state:
291+
* - reset BSP
292+
* - BSP will be put to real mode with entry set as wakeup_vec
293+
* - init_vmcs BSP. We could call init_vmcs here because we know current
294+
* pcpu is mapped to BSP of vm.
295+
*/
296+
void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec)
297+
{
298+
struct vcpu *bsp = vcpu_from_vid(vm, 0);
299+
300+
vm->state = VM_STARTED;
301+
302+
reset_vcpu(bsp);
303+
bsp->entry_addr = (void *)(uint64_t)wakeup_vec;
304+
bsp->arch_vcpu.cpu_mode = CPU_MODE_REAL;
305+
init_vmcs(bsp);
306+
307+
schedule_vcpu(bsp);
308+
}
309+
288310
/* Create vm/vcpu for vm0 */
289311
int prepare_vm0(void)
290312
{

hypervisor/arch/x86/pm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int enter_s3(struct vm *vm, uint32_t pm1a_cnt_val,
7272
{
7373
uint32_t pcpu_id;
7474
uint64_t pmain_entry_saved;
75+
uint32_t guest_wakeup_vec32;
7576
uint64_t *pmain_entry;
7677

7778
if (vm->pm.sx_state_data == NULL) {
@@ -83,6 +84,15 @@ int enter_s3(struct vm *vm, uint32_t pm1a_cnt_val,
8384

8485
pcpu_id = get_cpu_id();
8586

87+
/* Save the wakeup vec set by guest. Will return to guest
88+
* with this wakeup vec as entry.
89+
*/
90+
guest_wakeup_vec32 = *vm->pm.sx_state_data->wake_vector_32;
91+
92+
/* set ACRN wakeup vec instead */
93+
*vm->pm.sx_state_data->wake_vector_32 =
94+
(uint32_t) trampoline_start16_paddr;
95+
8696
/* offline all APs */
8797
stop_cpus();
8898

@@ -128,5 +138,8 @@ int enter_s3(struct vm *vm, uint32_t pm1a_cnt_val,
128138
/* online all APs again */
129139
start_cpus();
130140

141+
/* jump back to vm */
142+
resume_vm_from_s3(vm, guest_wakeup_vec32);
143+
131144
return 0;
132145
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ struct vm_description {
172172
int shutdown_vm(struct vm *vm);
173173
void pause_vm(struct vm *vm);
174174
void resume_vm(struct vm *vm);
175+
void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec);
175176
int start_vm(struct vm *vm);
176177
int create_vm(struct vm_description *vm_desc, struct vm **vm);
177178
int prepare_vm0(void);

0 commit comments

Comments
 (0)