hv: provide vm_config information in get_platform_info hypercall

Hypervisor reports VM configuration information to SOS which can be used to
dynamically allocate VCPU affinity.

Servise OS can get the vm_configs in this order:

1. call platform_info HC (set vm_configs_addr with 0) to get max_vms and
   vm_config_entry_size.
2. allocate memory for acrn_vm_config array based on the number of VMs
   and entry size that just got in step 1.
3. call platform_info HC again to collect VM configurations.

Tracked-On: #4616
Signed-off-by: Zide Chen <zide.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Zide Chen 2020-03-23 14:03:51 -07:00 committed by wenlingz
parent b9583f42e9
commit 5420b34a26
2 changed files with 50 additions and 7 deletions

View File

@ -108,13 +108,31 @@ int32_t hcall_get_api_version(struct acrn_vm *vm, uint64_t param)
*/
int32_t hcall_get_platform_info(struct acrn_vm *vm, uint64_t param)
{
struct hc_platform_info platform_info;
struct hc_platform_info pi = { 0 };
uint32_t entry_size = sizeof(struct acrn_vm_config);
int32_t ret;
platform_info.cpu_num = get_pcpu_nums();
platform_info.max_vcpus_per_vm = MAX_VCPUS_PER_VM;
platform_info.max_kata_containers = CONFIG_MAX_KATA_VM_NUM;
/* to get the vm_config_info pointer */
ret = copy_from_gpa(vm, &pi, param, sizeof(pi));
if (ret == 0) {
pi.cpu_num = get_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;
return copy_to_gpa(vm, &platform_info, param, sizeof(platform_info));
/* 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 (ret == 0) {
ret = copy_to_gpa(vm, &pi, param, sizeof(pi));
}
}
return ret;
}
/**

View File

@ -319,8 +319,11 @@ struct hc_platform_info {
/** Physical CPU number */
uint16_t cpu_num;
/** version of this structure */
uint16_t version;
/** Align the size of version & hardware info to 128Bytes. */
uint8_t reserved0[126];
uint8_t reserved0[124];
/** Configuration Information */
/** Maximum vCPU number for one VM. */
@ -329,8 +332,30 @@ struct hc_platform_info {
/** Maximum Kata container number in SOS VM */
uint8_t max_kata_containers;
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 reserved1[125];
uint8_t reserved2[104];
} __aligned(8);
/**