From 7bf9b1be2cd36094bc4846256fc34b5773398cbc Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Mon, 21 Jan 2019 15:36:31 +0800 Subject: [PATCH] HV: enable pcpu bitmap config for partition mode All the legacy cpu configration in vm_description.c are all cleaned up; Tracked-On: #2291 Signed-off-by: Victor Sun Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 33 ++++++++++++------- hypervisor/dm/vmptable.c | 14 ++++++-- hypervisor/include/arch/x86/guest/vm.h | 7 +--- hypervisor/partition/apl-mrb/vm_description.c | 20 ++--------- hypervisor/partition/dnv-cb2/vm_description.c | 20 ++--------- 5 files changed, 38 insertions(+), 56 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index c63c6838e..fbe866597 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -91,6 +91,26 @@ static inline uint16_t get_vm_bsp_pcpu_id(const struct acrn_vm_config *vm_config return (cpu_id < get_pcpu_nums()) ? cpu_id : INVALID_CPU_ID; } +#ifdef CONFIG_PARTITION_MODE +/** + * @pre vm_config != NULL + */ +uint16_t get_vm_pcpu_nums(struct acrn_vm_config *vm_config) +{ + uint16_t i, host_pcpu_num, pcpu_num = 0U; + uint64_t cpu_bitmap = vm_config->pcpu_bitmap; + + host_pcpu_num = get_pcpu_nums(); + + for (i = 0U; i < host_pcpu_num ; i++) { + if (bitmap_test(i, &cpu_bitmap)) { + pcpu_num++; + } + } + return pcpu_num; +} +#endif + /** * @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL */ @@ -395,13 +415,8 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) if (err == 0) { #ifdef CONFIG_PARTITION_MODE mptable_build(vm); +#endif - prepare_vcpu(vm, vm_config->vm_pcpu_ids[0]); - - /* Prepare the AP for vm */ - for (i = 1U; i < vm_config->vm_hw_num_cores; i++) - prepare_vcpu(vm, vm_config->vm_pcpu_ids[i]); -#else for (i = 0U; i < get_pcpu_nums(); i++) { if (bitmap_test(i, &vm_config->pcpu_bitmap)) { err = prepare_vcpu(vm, i); @@ -410,7 +425,7 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) } } } -#endif + } if (err == 0) { @@ -442,11 +457,7 @@ void launch_vms(uint16_t pcpu_id) sos_vm_ptr = &vm_array[vm_id]; } -#ifdef CONFIG_PARTITION_MODE - bsp_id = vm_config->vm_pcpu_ids[0]; -#else bsp_id = get_vm_bsp_pcpu_id(vm_config); -#endif if (pcpu_id == bsp_id) { prepare_vm(vm_id, vm_config); } diff --git a/hypervisor/dm/vmptable.c b/hypervisor/dm/vmptable.c index fba3a49ba..6690080e3 100644 --- a/hypervisor/dm/vmptable.c +++ b/hypervisor/dm/vmptable.c @@ -74,6 +74,9 @@ static uint8_t mpt_compute_checksum(void *base, size_t len) return (256U - sum); } +/** + * @pre vm_config != NULL + */ int32_t mptable_build(struct acrn_vm *vm) { char *startaddr; @@ -82,9 +85,14 @@ int32_t mptable_build(struct acrn_vm *vm) struct mpfps *mpfp; size_t mptable_length; uint16_t i; - uint16_t vcpu_num = vm->vm_config->vm_hw_num_cores; + uint16_t vcpu_num; + uint64_t pcpu_bitmap = 0U; struct mptable_info *mptable = &vm->mptable; + struct acrn_vm_config *vm_config; + vm_config = get_vm_config(vm->vm_id); + vcpu_num = get_vm_pcpu_nums(vm_config); + pcpu_bitmap = vm_config->pcpu_bitmap; (void *)memcpy_s((void *)mptable, sizeof(struct mptable_info), (const void *)&mptable_template, sizeof(struct mptable_info)); @@ -100,7 +108,7 @@ int32_t mptable_build(struct acrn_vm *vm) } for (i = 0U; i < vcpu_num; i++) { - uint16_t pcpu_id = *(vm->vm_config->vm_pcpu_ids + i); + uint16_t pcpu_id = ffs64(pcpu_bitmap); (void *)memcpy_s((void *)(mptable->proc_entry_array + i), sizeof(struct proc_entry), (const void *)&proc_entry_template, sizeof(struct proc_entry)); @@ -108,7 +116,7 @@ int32_t mptable_build(struct acrn_vm *vm) if (i == 0) { mptable->proc_entry_array[i].cpu_flags |= PROCENTRY_FLAG_BP; } - + bitmap_clear_lock(pcpu_id, &pcpu_bitmap); } /* Copy mptable info into guest memory */ diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 1d6c6e34d..ce6a469ae 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -216,13 +216,7 @@ struct acrn_vm_config { struct acrn_vm_pci_ptdev_config *pci_ptdevs; /* point to PCI PT devices BDF list */ struct acrn_vm_os_config os_config; /* OS information the VM */ - /* The physical CPU IDs associated with this VM - The first CPU listed - * will be the VM's BSP - */ - uint16_t *vm_pcpu_ids; - uint16_t vm_hw_num_cores; /* Number of virtual cores */ #ifdef CONFIG_PARTITION_MODE - uint8_t vm_id; uint64_t start_hpa; uint64_t mem_size; /* UOS memory size in hex */ bool vm_vuart; @@ -327,6 +321,7 @@ struct pcpu_vm_config_mapping { extern const struct pcpu_vm_config_mapping pcpu_vm_config_map[]; extern struct vm_config_arraies vm_config_partition; +uint16_t get_vm_pcpu_nums(struct acrn_vm_config *vm_config); void vrtc_init(struct acrn_vm *vm); #endif diff --git a/hypervisor/partition/apl-mrb/vm_description.c b/hypervisor/partition/apl-mrb/vm_description.c index da09e6c72..226b65579 100644 --- a/hypervisor/partition/apl-mrb/vm_description.c +++ b/hypervisor/partition/apl-mrb/vm_description.c @@ -7,18 +7,6 @@ #include #include -/* Number of CPUs in VM1 */ -#define VM1_NUM_CPUS 2U - -/* Logical CPU IDs assigned to this VM */ -uint16_t VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U}; - -/* Number of CPUs in VM2 */ -#define VM2_NUM_CPUS 2U - -/* Logical CPU IDs assigned with this VM */ -uint16_t VM2_CPUS[VM2_NUM_CPUS] = {3U, 1U}; - static struct vpci_vdev_array vpci_vdev_array1 = { .num_pci_vdev = 2, @@ -154,9 +142,7 @@ struct vm_config_arraies vm_config_partition = { .vm_config_array = { { .type = PRE_LAUNCHED_VM, - /* Internal variable, MUSTBE init to -1 */ - .vm_hw_num_cores = VM1_NUM_CPUS, - .vm_pcpu_ids = &VM1_CPUS[0], + .pcpu_bitmap = (PLUG_CPU(0) | PLUG_CPU(2)), .start_hpa = 0x100000000UL, .mem_size = 0x20000000UL, /* uses contiguous memory from host */ .vm_vuart = true, @@ -168,9 +154,7 @@ struct vm_config_arraies vm_config_partition = { { .type = PRE_LAUNCHED_VM, - /* Internal variable, MUSTBE init to -1 */ - .vm_hw_num_cores = VM2_NUM_CPUS, - .vm_pcpu_ids = &VM2_CPUS[0], + .pcpu_bitmap = (PLUG_CPU(1) | PLUG_CPU(3)), .start_hpa = 0x120000000UL, .mem_size = 0x20000000UL, /* uses contiguous memory from host */ .vm_vuart = true, diff --git a/hypervisor/partition/dnv-cb2/vm_description.c b/hypervisor/partition/dnv-cb2/vm_description.c index fc8d17601..82471ff32 100644 --- a/hypervisor/partition/dnv-cb2/vm_description.c +++ b/hypervisor/partition/dnv-cb2/vm_description.c @@ -7,18 +7,6 @@ #include #include -/* Number of CPUs in VM1*/ -#define VM1_NUM_CPUS 4U - -/* Logical CPU IDs assigned to this VM */ -uint16_t VM1_CPUS[VM1_NUM_CPUS] = {0U, 2U, 4U, 6U}; - -/* Number of CPUs in VM2*/ -#define VM2_NUM_CPUS 4U - -/* Logical CPU IDs assigned with this VM */ -uint16_t VM2_CPUS[VM2_NUM_CPUS] = {7U, 5U, 3U, 1U}; - static struct vpci_vdev_array vpci_vdev_array1 = { .num_pci_vdev = 3, .vpci_vdev_list = { @@ -188,9 +176,7 @@ struct vm_config_arraies vm_config_partition = { .vm_config_array = { { .type = PRE_LAUNCHED_VM, - /* Internal variable, MUSTBE init to -1 */ - .vm_hw_num_cores = VM1_NUM_CPUS, - .vm_pcpu_ids = &VM1_CPUS[0], + .pcpu_bitmap = (PLUG_CPU(0) | PLUG_CPU(2) | PLUG_CPU(4) | PLUG_CPU(6)), .start_hpa = 0x100000000UL, .mem_size = 0x80000000UL, /* uses contiguous memory from host */ .vm_vuart = true, @@ -203,9 +189,7 @@ struct vm_config_arraies vm_config_partition = { { .type = PRE_LAUNCHED_VM, - /* Internal variable, MUSTBE init to -1 */ - .vm_hw_num_cores = VM2_NUM_CPUS, - .vm_pcpu_ids = &VM2_CPUS[0], + .pcpu_bitmap = (PLUG_CPU(1) | PLUG_CPU(3) | PLUG_CPU(5) | PLUG_CPU(7)), .start_hpa = 0x180000000UL, .mem_size = 0x80000000UL, /* uses contiguous memory from host */ .vm_vuart = true,