dm: Remove hardcode vm_config size from vm_get_config()

vm_config size can be calced by platform_info.sw.max_vms *
platform_info.sw.vm_config_size.

Change vm_get_config() to call IOCTL ACRN_IOCTL_GET_PLATFORM_INFO
twice, first to get platform_info, second to get the vm_configs
content.

Tracked-On: #6282
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
Shuo A Liu 2021-04-23 17:30:44 +08:00 committed by wenlingz
parent d170336e90
commit b218544872
1 changed files with 13 additions and 6 deletions

View File

@ -673,29 +673,36 @@ vm_irqfd(struct vmctx *ctx, struct acrn_irqfd *args)
int
vm_get_config(struct vmctx *ctx, struct acrn_vm_config_header *vm_cfg, struct acrn_platform_info *plat_info)
{
#define VM_CFG_BUFF_SIZE 0x8000
int i, err = 0;
uint8_t *configs_buff;
int configs_size;
uint8_t *configs_buff = NULL;
struct acrn_vm_config_header *pcfg;
struct acrn_platform_info platform_info;
if ((ctx == NULL) || (vm_cfg == NULL))
return -1;
configs_buff = calloc(1, VM_CFG_BUFF_SIZE);
/* The first IOCTL to get max_vm and vm_config size of a VM */
bzero(&platform_info, sizeof(platform_info));
err = ioctl(ctx->fd, ACRN_IOCTL_GET_PLATFORM_INFO, &platform_info);
if (err) {
pr_err("%s: IOCTL first time failed!\n", __func__);
goto exit;
}
configs_size = platform_info.sw.max_vms * platform_info.sw.vm_config_size;
configs_buff = calloc(1, configs_size);
if (configs_buff == NULL) {
pr_err("%s, Allocate memory fail.\n", __func__);
return -1;
}
bzero(&platform_info, sizeof(platform_info));
platform_info.sw.vm_configs_addr = configs_buff;
err = ioctl(ctx->fd, ACRN_IOCTL_GET_PLATFORM_INFO, &platform_info);
if (err) {
pr_err("%s, failed: get platform info.\n", __func__);
pr_err("%s: IOCTL second time failed!\n", __func__);
goto exit;
}
assert(VM_CFG_BUFF_SIZE > (platform_info.sw.max_vms * platform_info.sw.vm_config_size));
for (i = 0; i < platform_info.sw.max_vms; i++) {
pcfg = (struct acrn_vm_config_header *)(configs_buff + (i * platform_info.sw.vm_config_size));