Skip to content

Commit 40ae32f

Browse files
ZideChen0wenlingz
authored andcommitted
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>
1 parent 42c4399 commit 40ae32f

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

hypervisor/common/hypercall.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,31 @@ int32_t hcall_get_api_version(struct acrn_vm *vm, uint64_t param)
108108
*/
109109
int32_t hcall_get_platform_info(struct acrn_vm *vm, uint64_t param)
110110
{
111-
struct hc_platform_info platform_info;
111+
struct hc_platform_info pi = { 0 };
112+
uint32_t entry_size = sizeof(struct acrn_vm_config);
113+
int32_t ret;
114+
115+
/* to get the vm_config_info pointer */
116+
ret = copy_from_gpa(vm, &pi, param, sizeof(pi));
117+
if (ret == 0) {
118+
pi.cpu_num = get_pcpu_nums();
119+
pi.version = 0x100; /* version 1.0; byte[1:0] = major:minor version */
120+
pi.max_vcpus_per_vm = MAX_VCPUS_PER_VM;
121+
pi.max_kata_containers = CONFIG_MAX_KATA_VM_NUM;
122+
pi.max_vms = CONFIG_MAX_VM_NUM;
123+
pi.vm_config_entry_size = entry_size;
124+
125+
/* If it wants to get the vm_configs info */
126+
if (pi.vm_configs_addr != 0UL) {
127+
ret = copy_to_gpa(vm, (void *)get_vm_config(0U), pi.vm_configs_addr, entry_size * pi.max_vms);
128+
}
112129

113-
platform_info.cpu_num = get_pcpu_nums();
114-
platform_info.max_vcpus_per_vm = MAX_VCPUS_PER_VM;
115-
platform_info.max_kata_containers = CONFIG_MAX_KATA_VM_NUM;
130+
if (ret == 0) {
131+
ret = copy_to_gpa(vm, &pi, param, sizeof(pi));
132+
}
133+
}
116134

117-
return copy_to_gpa(vm, &platform_info, param, sizeof(platform_info));
135+
return ret;
118136
}
119137

120138
/**

hypervisor/include/public/acrn_hv_defs.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,11 @@ struct hc_platform_info {
318318
/** Physical CPU number */
319319
uint16_t cpu_num;
320320

321+
/** version of this structure */
322+
uint16_t version;
323+
321324
/** Align the size of version & hardware info to 128Bytes. */
322-
uint8_t reserved0[126];
325+
uint8_t reserved0[124];
323326

324327
/** Configuration Information */
325328
/** Maximum vCPU number for one VM. */
@@ -328,8 +331,30 @@ struct hc_platform_info {
328331
/** Maximum Kata container number in SOS VM */
329332
uint8_t max_kata_containers;
330333

334+
uint8_t reserved1[7];
335+
336+
/** Number of configured VMs */
337+
uint16_t max_vms;
338+
339+
/**
340+
* The size of acrn_vm_config is various on different platforms.
341+
* This is the size of this struct which is used by the caller
342+
* to parse the vm_configs array.
343+
*/
344+
uint32_t vm_config_entry_size;
345+
346+
/**
347+
* Address to an array of struct acrn_vm_config, containing all
348+
* the configurations of all VMs. VHM treats it as an opague data
349+
* structure.
350+
*
351+
* The size of one array element is vm_config_entry_size while
352+
* the number of elements is max_vms.
353+
*/
354+
uint64_t vm_configs_addr;
355+
331356
/** Align the size of Configuration info to 128Bytes. */
332-
uint8_t reserved1[125];
357+
uint8_t reserved2[104];
333358
} __aligned(8);
334359

335360
/**

0 commit comments

Comments
 (0)