diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 7e2d259f7..74d2a775c 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -882,6 +882,7 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec) launch_vcpu(bsp); } +static uint8_t loaded_pre_vm_nr = 0U; /** * Prepare to create vm/vcpu for vm * @@ -900,7 +901,32 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) build_vrsdp(vm); } + if (is_sos_vm(vm)) { + /* We need to ensure all modules of pre-launched VMs have been loaded already + * before loading SOS VM modules, otherwise the module of pre-launched VMs could + * be corrupted because SOS VM kernel might pick any usable RAM to extract kernel + * when KASLR enabled. + * In case the pre-launched VMs aren't loaded successfuly that cause deadlock here, + * use a 10000ms timer to break the waiting loop. + */ + uint64_t start_tick = cpu_ticks(); + + while (loaded_pre_vm_nr != PRE_VM_NUM) { + uint64_t timeout = ticks_to_ms(cpu_ticks() - start_tick); + + if (timeout > 10000U) { + pr_err("Loading pre-launched VMs timeout!"); + break; + } + } + } + err = vm_sw_loader(vm); + + if (is_prelaunched_vm(vm)) { + loaded_pre_vm_nr++; + } + if (err == 0) { /* start vm BSP automatically */