From 7efe18a84b4a46e907d6e9dfbf80faabe7ae9b8c Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Wed, 7 Jul 2021 11:30:48 +0800 Subject: [PATCH] hv: Use new struct acrn_platform_info to adapt new HSM driver struct hc_platform_info -> struct acrn_platform_info MAX_PLATFORM_LAPIC_IDS -> ACRN_PLATFORM_LAPIC_IDS_MAX A layout change to the struct hc_platform_info is that move max_kata_containers to back of vm_config_size, uint16_t max_vcpus_per_vm; uint16_t max_vms; uint32_t vm_config_size; uint64_t max_kata_containers; Then, they are nature 64-bits aligned. Tracked-On: #6282 Signed-off-by: Shuo A Liu --- hypervisor/common/hypercall.c | 26 +++--- hypervisor/include/common/hypercall.h | 2 +- hypervisor/include/public/acrn_hv_defs.h | 100 +++++++++++------------ 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 29cde9c7c..99796b666 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -186,7 +186,7 @@ static void get_cache_shift(uint32_t *l2_shift, uint32_t *l3_shift) * for the current platform. * * @param vcpu Pointer to vCPU that initiates the hypercall. - * @param param1 GPA pointer to struct hc_platform_info. + * @param param1 GPA pointer to struct acrn_platform_info. * * @pre is_sos_vm(vcpu->vm) * @return 0 on success, non zero in case of error. @@ -195,7 +195,7 @@ int32_t hcall_get_platform_info(struct acrn_vcpu *vcpu, __unused struct acrn_vm uint64_t param1, __unused uint64_t param2) { struct acrn_vm *vm = vcpu->vm; - struct hc_platform_info pi = { 0 }; + struct acrn_platform_info pi = { 0 }; uint32_t entry_size = sizeof(struct acrn_vm_config); int32_t ret; @@ -205,22 +205,22 @@ int32_t hcall_get_platform_info(struct acrn_vcpu *vcpu, __unused struct acrn_vm uint16_t i; uint16_t pcpu_nums = get_pcpu_nums(); - get_cache_shift(&pi.l2_cat_shift, &pi.l3_cat_shift); + get_cache_shift(&pi.hw.l2_cat_shift, &pi.hw.l3_cat_shift); - for (i = 0U; i < min(pcpu_nums, MAX_PLATFORM_LAPIC_IDS); i++) { - pi.lapic_ids[i] = per_cpu(lapic_id, i); + for (i = 0U; i < min(pcpu_nums, ACRN_PLATFORM_LAPIC_IDS_MAX); i++) { + pi.hw.lapic_ids[i] = per_cpu(lapic_id, i); } - pi.cpu_num = pcpu_nums; - pi.version = 0x100; /* version 1.0; byte[1:0] = major:minor version */ - pi.max_vcpus_per_vm = MAX_VCPUS_PER_VM; - pi.max_kata_containers = CONFIG_MAX_KATA_VM_NUM; - pi.max_vms = CONFIG_MAX_VM_NUM; - pi.vm_config_entry_size = entry_size; + pi.hw.cpu_num = pcpu_nums; + pi.hw.version = 0x100; /* version 1.0; byte[1:0] = major:minor version */ + pi.sw.max_vcpus_per_vm = MAX_VCPUS_PER_VM; + pi.sw.max_kata_containers = CONFIG_MAX_KATA_VM_NUM; + pi.sw.max_vms = CONFIG_MAX_VM_NUM; + pi.sw.vm_config_size = entry_size; /* If it wants to get the vm_configs info */ - if (pi.vm_configs_addr != 0UL) { - ret = copy_to_gpa(vm, (void *)get_vm_config(0U), pi.vm_configs_addr, entry_size * pi.max_vms); + if (pi.sw.vm_configs_addr != 0UL) { + ret = copy_to_gpa(vm, (void *)get_vm_config(0U), pi.sw.vm_configs_addr, entry_size * pi.sw.max_vms); } if (ret == 0) { diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index be9683f91..953694dca 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -61,7 +61,7 @@ int32_t hcall_get_api_version(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, * * @param vcpu Pointer to vCPU that initiates the hypercall. * @param target_vm not used - * @param param1 GPA pointer to struct hc_platform_info. + * @param param1 GPA pointer to struct acrn_platform_info. * @param param2 not used * * @pre is_sos_vm(vcpu->vm) diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h index 1d6f89e36..4bab4be92 100644 --- a/hypervisor/include/public/acrn_hv_defs.h +++ b/hypervisor/include/public/acrn_hv_defs.h @@ -379,68 +379,66 @@ struct hc_api_version { uint32_t minor_version; } __aligned(8); +#define ACRN_PLATFORM_LAPIC_IDS_MAX 64 /** * Hypervisor API, return it for HC_GET_PLATFORM_INFO hypercall */ -struct hc_platform_info { +struct acrn_platform_info { /** Hardware Information */ - /** Physical CPU number */ - uint16_t cpu_num; + struct { + /** Physical CPU number */ + uint16_t cpu_num; + /** version of this structure */ + uint16_t version; - /** version of this structure */ - uint16_t version; + uint32_t l2_cat_shift; + uint32_t l3_cat_shift; - uint32_t l2_cat_shift; - uint32_t l3_cat_shift; + /** pLAPIC ID list */ + uint8_t lapic_ids[ACRN_PLATFORM_LAPIC_IDS_MAX]; - #define MAX_PLATFORM_LAPIC_IDS 64U - /** pLAPIC ID list */ - uint8_t lapic_ids[MAX_PLATFORM_LAPIC_IDS]; - - /** - * sizeof(uint8_t reserved0[]) + sizeof(l2_cat_shift) - * + sizeof(l3_cat_shift) + sizeof(uint8_t lapic_ids[]) = 124 - * - * Note: - * 1. DM needs to use the same logic as hypervisor to calculate vLAPIC IDs - * based on physical APIC IDs and CPU affinity setting. - * - * 2. Can only support at most 116 cores. And it assumes LAPIC ID is 8bits - * (X2APIC mode supports 32 bits) - */ - uint8_t reserved0[116U - MAX_PLATFORM_LAPIC_IDS]; + /** + * sizeof(uint8_t reserved0[]) + sizeof(l2_cat_shift) + * + sizeof(l3_cat_shift) + sizeof(uint8_t lapic_ids[]) = 124 + * + * Note: + * 1. DM needs to use the same logic as hypervisor to calculate vLAPIC IDs + * based on physical APIC IDs and CPU affinity setting. + * + * 2. Can only support at most 116 cores. And it assumes LAPIC ID is 8bits + * (X2APIC mode supports 32 bits) + */ + uint8_t reserved[52]; + } hw; /** Configuration Information */ - /** Maximum vCPU number for one VM. */ - uint16_t max_vcpus_per_vm; + struct { + /** Maximum vCPU number for one VM. */ + uint16_t max_vcpus_per_vm; + /** Number of configured VMs */ + uint16_t max_vms; + /** + * The size of acrn_vm_config is various on different platforms. + * This is the size of this struct which is used by the caller + * to parse the vm_configs array. + */ + uint32_t vm_config_size; - /** Maximum Kata container number in SOS VM */ - uint8_t max_kata_containers; + /** + * Address to an array of struct acrn_vm_config, containing all + * the configurations of all VMs. VHM treats it as an opague data + * structure. + * + * The size of one array element is vm_config_entry_size while + * the number of elements is max_vms. + */ + uint64_t vm_configs_addr; - uint8_t reserved1[7]; - - /** Number of configured VMs */ - uint16_t max_vms; - - /** - * The size of acrn_vm_config is various on different platforms. - * This is the size of this struct which is used by the caller - * to parse the vm_configs array. - */ - uint32_t vm_config_entry_size; - - /** - * Address to an array of struct acrn_vm_config, containing all - * the configurations of all VMs. VHM treats it as an opague data - * structure. - * - * The size of one array element is vm_config_entry_size while - * the number of elements is max_vms. - */ - uint64_t vm_configs_addr; - - /** Align the size of Configuration info to 128Bytes. */ - uint8_t reserved2[104]; + /** Maximum Kata container number in SOS VM */ + uint64_t max_kata_containers; + /** Align the size of Configuration info to 128Bytes. */ + uint8_t reserved[104]; + } sw; } __aligned(8); /**