From 2096c43e5c94844d057e1f5f0e77faca81ede274 Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Wed, 22 May 2019 15:09:34 +0800 Subject: [PATCH] hv: create all VCPUs for guest when create VM To enable static configuration of different scenarios, we configure VMs in HV code and prepare all nesserary resources for this VM in create VM hypercall. It means when we create one VM through hypercall, HV will read all its configuration and run it automatically. Tracked-On: #3663 Signed-off-by: Jason Chen CJ Signed-off-by: Yu Wang Signed-off-by: Shuo A Liu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index ccc25681d..a48381e22 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -421,6 +421,8 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ struct acrn_vm *vm = NULL; int32_t status = 0; bool need_cleanup = false; + uint32_t i; + uint16_t pcpu_id; /* Allocate memory for virtual machine */ vm = &vm_array[vm_id]; @@ -536,6 +538,21 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ (void)memset(vm->arch_vm.nworld_eptp, 0U, PAGE_SIZE); } } + + if (status == 0) { + /* We have assumptions: + * 1) vcpus used by SOS has been offlined by DM before UOS re-use it. + * 2) vcpu_affinity[] passed sanitization is OK for vcpu creating. + */ + for (i = 0U; i < vm_config->vcpu_num; i++) { + pcpu_id = ffs64(vm_config->vcpu_affinity[i]); + status = prepare_vcpu(vm, pcpu_id); + if (status != 0) { + break; + } + } + } + return status; } @@ -724,21 +741,10 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec) void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) { int32_t err = 0; - uint16_t i, pcpu_id; struct acrn_vm *vm = NULL; err = create_vm(vm_id, vm_config, &vm); - if (err == 0) { - for (i = 0U; i < vm_config->vcpu_num; i++) { - pcpu_id = ffs64(vm_config->vcpu_affinity[i]); - err = prepare_vcpu(vm, pcpu_id); - if (err != 0) { - break; - } - } - } - if (err == 0) { if (is_prelaunched_vm(vm)) { build_vacpi(vm);