From c4ea248bc97337d1470914d7604c11a340948c7c Mon Sep 17 00:00:00 2001 From: Haiwei Li Date: Thu, 11 Jul 2024 18:29:38 +0800 Subject: [PATCH] hv: remove Service VM delayed loading Now multiboot modules memory is already reserved from e820 in function `alloc_mods_memory()` and Service VM will not corrupt pre-launched VM modules. So remove the code of Service VM delayed loading. Tracked-On: #8652 Signed-off-by: Haiwei Li --- hypervisor/arch/x86/guest/vm.c | 37 +++++----------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index f3a21b0d9..bf60a558a 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -1087,7 +1087,6 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec) start_vm(vm); } -static uint8_t loaded_pre_vm_nr = 0U; /** * Prepare to create vm/vcpu for vm * @@ -1095,7 +1094,7 @@ static uint8_t loaded_pre_vm_nr = 0U; */ int32_t prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) { - int32_t err = 0; + int32_t err = -1; struct acrn_vm *vm = NULL; #ifdef CONFIG_SECURITY_VM_FIXUP @@ -1103,41 +1102,15 @@ int32_t prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) #endif if (get_vmid_by_name(vm_config->name) != vm_id) { pr_err("Invalid VM name: %s", vm_config->name); - err = -1; } else { /* Service VM and pre-launched VMs launch on all pCPUs defined in vm_config->cpu_affinity */ err = create_vm(vm_id, vm_config->cpu_affinity, vm_config, &vm); - } - - if (err == 0) { - if (is_prelaunched_vm(vm)) { - build_vrsdp(vm); - } - - if (is_service_vm(vm)) { - /* We need to ensure all modules of pre-launched VMs have been loaded already - * before loading Service VM modules, otherwise the module of pre-launched VMs could - * be corrupted because Service 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; - } + if (err == 0) { + if (is_prelaunched_vm(vm)) { + build_vrsdp(vm); } - } - err = prepare_os_image(vm); - - if (is_prelaunched_vm(vm)) { - loaded_pre_vm_nr++; + err = prepare_os_image(vm); } }