diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 7e2d44df9..c9ff1660b 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -29,6 +29,7 @@ static void init_vm(struct vm_description *vm_desc, struct vm *vm_handle) { /* Populate VM attributes from VM description */ +#ifdef CONFIG_VM0_DESC if (is_vm0(vm_handle)) { /* Allocate all cpus to vm0 at the beginning */ vm_handle->hw.num_vcpus = phys_cpu_num; @@ -37,6 +38,9 @@ static void init_vm(struct vm_description *vm_desc, vm_handle->hw.num_vcpus = vm_desc->vm_hw_num_cores; vm_handle->hw.exp_num_vcpus = vm_desc->vm_hw_num_cores; } +#else + vm_handle->hw.num_vcpus = vm_desc->vm_hw_num_cores; +#endif } /* return a pointer to the virtual machine structure associated with @@ -339,6 +343,10 @@ int prepare_vm0(void) struct vm *vm = NULL; struct vm_description *vm_desc = &vm0_desc; +#ifndef CONFIG_VM0_DESC + vm_desc->vm_hw_num_cores = phys_cpu_num; +#endif + err = create_vm(vm_desc, &vm); if (err != 0) { return err; @@ -360,6 +368,7 @@ int prepare_vm0(void) return err; } +#ifdef CONFIG_VM0_DESC static inline bool vcpu_in_vm_desc(struct vcpu *vcpu, struct vm_description *vm_desc) { @@ -404,3 +413,4 @@ void vm_fixup(struct vm *vm) vm->hw.num_vcpus = vm->hw.exp_num_vcpus; } } +#endif diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index bf7043c59..210b6fb2b 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -39,10 +39,12 @@ int vmcall_vmexit_handler(struct vcpu *vcpu) /* Dispatch the hypercall handler */ switch (hypcall_id) { case HC_GET_API_VERSION: +#ifdef CONFIG_VM0_DESC /* vm0 will call HC_GET_API_VERSION as first hypercall, fixup * vm0 vcpu here. */ vm_fixup(vm); +#endif ret = hcall_get_api_version(vm, param1); break; diff --git a/hypervisor/bsp/sbl/vm_description.c b/hypervisor/bsp/sbl/vm_description.c index 3dde99c23..c3db2cff2 100644 --- a/hypervisor/bsp/sbl/vm_description.c +++ b/hypervisor/bsp/sbl/vm_description.c @@ -6,6 +6,8 @@ #include +#ifdef CONFIG_VM0_DESC + /* Number of CPUs in VM0 */ #define VM0_NUM_CPUS 1 @@ -16,3 +18,9 @@ struct vm_description vm0_desc = { .vm_hw_num_cores = VM0_NUM_CPUS, .vm_pcpu_ids = &VM0_CPUS[0], }; + +#else + +struct vm_description vm0_desc; + +#endif // CONFIG_VM0_DESC diff --git a/hypervisor/bsp/uefi/vm_description.c b/hypervisor/bsp/uefi/vm_description.c index 3dde99c23..c3db2cff2 100644 --- a/hypervisor/bsp/uefi/vm_description.c +++ b/hypervisor/bsp/uefi/vm_description.c @@ -6,6 +6,8 @@ #include +#ifdef CONFIG_VM0_DESC + /* Number of CPUs in VM0 */ #define VM0_NUM_CPUS 1 @@ -16,3 +18,9 @@ struct vm_description vm0_desc = { .vm_hw_num_cores = VM0_NUM_CPUS, .vm_pcpu_ids = &VM0_CPUS[0], }; + +#else + +struct vm_description vm0_desc; + +#endif // CONFIG_VM0_DESC diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c index cd50e6620..0071c4f6c 100644 --- a/hypervisor/common/hv_main.c +++ b/hypervisor/common/hv_main.c @@ -104,7 +104,11 @@ void vcpu_thread(struct vcpu *vcpu) static bool is_vm0_bsp(uint16_t pcpu_id) { +#ifdef CONFIG_VM0_DESC return pcpu_id == vm0_desc.vm_pcpu_ids[0]; +#else + return pcpu_id == BOOT_CPU_ID; +#endif } int32_t hv_main(uint16_t pcpu_id) diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index a88d57bf8..955ed672b 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -175,7 +175,9 @@ void resume_vm_from_s3(struct vm *vm, uint32_t wakeup_vec); int start_vm(struct vm *vm); int create_vm(struct vm_description *vm_desc, struct vm **vm); int prepare_vm0(void); +#ifdef CONFIG_VM0_DESC void vm_fixup(struct vm *vm); +#endif struct vm *get_vm_from_vmid(uint16_t vm_id);