From e7d0c20709d6811dbe3fd0aac14ca36d4cbf8467 Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Thu, 16 Jul 2020 14:45:41 +0800 Subject: [PATCH] HV: init vcpu affinity of SOS VM when launch VMs Previously the initialization of SOS vCPUs is done by sanitize_vm_config() before call launch_vms(), once sanitize_vm_config() is moved to pre-build, we need to do the initialization in launch_vms(); Tracked-On: #5077 Signed-off-by: Victor Sun Reviewed-by: Jason Chen CJ Acked-by: Eddie Dong --- hypervisor/arch/x86/configs/vm_config.c | 4 +--- hypervisor/arch/x86/guest/vm.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hypervisor/arch/x86/configs/vm_config.c b/hypervisor/arch/x86/configs/vm_config.c index 1f63ef449..0657aac3b 100644 --- a/hypervisor/arch/x86/configs/vm_config.c +++ b/hypervisor/arch/x86/configs/vm_config.c @@ -155,9 +155,7 @@ bool sanitize_vm_config(void) } break; case SOS_VM: - /* Deduct pcpus of PRE_LAUNCHED_VMs */ - vm_config->cpu_affinity = ALL_CPUS_MASK ^ pre_launch_pcpu_bitmap; - if ((vm_config->cpu_affinity == 0UL) || (vm_config->severity != (uint8_t)SEVERITY_SOS) || + if ((vm_config->severity != (uint8_t)SEVERITY_SOS) || ((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)) { ret = false; } diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index aaa4b9e05..1a3f6f5d2 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -766,12 +766,22 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) void launch_vms(uint16_t pcpu_id) { uint16_t vm_id; + uint64_t pre_vm_cpu_affinity = 0UL; struct acrn_vm_config *vm_config; for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) { vm_config = get_vm_config(vm_id); if ((vm_config->load_order == SOS_VM) || (vm_config->load_order == PRE_LAUNCHED_VM)) { - if (vm_config->load_order == SOS_VM) { + if (vm_config->load_order == PRE_LAUNCHED_VM) { + pre_vm_cpu_affinity |= vm_config->cpu_affinity; + } else if (vm_config->load_order == SOS_VM) { + /* Deduct pcpus of PRE_LAUNCHED_VMs */ + vm_config->cpu_affinity = ALL_CPUS_MASK ^ pre_vm_cpu_affinity; + if (vm_config->cpu_affinity == 0UL) { + /* in case physical cores are not all up as expected */ + pr_err("no vCPUs for SOS VM (vm id: %d)", vm_id); + break; + } sos_vm_ptr = &vm_array[vm_id]; }