diff --git a/hypervisor/arch/x86/configs/vm_config.c b/hypervisor/arch/x86/configs/vm_config.c index 52e827260..37da27c2b 100644 --- a/hypervisor/arch/x86/configs/vm_config.c +++ b/hypervisor/arch/x86/configs/vm_config.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include #include @@ -103,6 +104,7 @@ bool sanitize_vm_config(void) ret = false; } else { vm_config->pcpu_bitmap = sos_pcpu_bitmap; + vm_config->vcpu_num = bitmap_weight(sos_pcpu_bitmap); } break; case POST_LAUNCHED_VM: diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index 99d470af6..f9e65a2a8 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -175,10 +175,11 @@ int32_t hcall_create_vm(struct acrn_vm *vm, uint64_t param) } else { /* return a relative vm_id from SOS view */ cv.vmid = vmid_2_rel_vmid(vm->vm_id, vm_id); + cv.vcpu_num = vm_config->vcpu_num; ret = 0; } - if (copy_to_gpa(vm, &cv.vmid, param, sizeof(cv.vmid)) != 0) { + if (copy_to_gpa(vm, &cv, param, sizeof(cv)) != 0) { pr_err("%s: Unable copy param to vm\n", __func__); ret = -1; } diff --git a/hypervisor/include/arch/x86/vm_config.h b/hypervisor/include/arch/x86/vm_config.h index 1e073ebd6..ab4dd8e71 100644 --- a/hypervisor/include/arch/x86/vm_config.h +++ b/hypervisor/include/arch/x86/vm_config.h @@ -96,6 +96,7 @@ struct acrn_vm_config { char name[MAX_VM_OS_NAME_LEN]; /* VM name identifier, useful for debug. */ const uint8_t uuid[16]; /* UUID of the VM */ uint64_t pcpu_bitmap; /* from pcpu bitmap, we could know VM core number */ + uint16_t vcpu_num; /* Number of vCPUs for the VM */ uint64_t guest_flags; /* VM flags that we want to configure for guest * Now we have two flags: * GUEST_FLAG_SECURE_WORLD_ENABLED diff --git a/hypervisor/scenarios/hybrid/vm_configurations.c b/hypervisor/scenarios/hybrid/vm_configurations.c index b040e1b93..af5a9ce71 100644 --- a/hypervisor/scenarios/hybrid/vm_configurations.c +++ b/hypervisor/scenarios/hybrid/vm_configurations.c @@ -17,6 +17,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { /* fc836901-8685-4bc0-8b71-6e31dc36fa47 */ .guest_flags = GUEST_FLAG_HIGHEST_SEVERITY, .pcpu_bitmap = VM0_CONFIG_PCPU_BITMAP, + .vcpu_num = 1U, .clos = 0U, .memory = { .start_hpa = VM0_CONFIG_MEM_START_HPA, @@ -82,6 +83,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0xd2U, 0x79U, 0x54U, 0x38U, 0x25U, 0xd6U, 0x11U, 0xe8U, \ 0x86U, 0x4eU, 0xcbU, 0x7aU, 0x18U, 0xb3U, 0x46U, 0x43U}, /* d2795438-25d6-11e8-864e-cb7a18b34643 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = COM1_BASE, diff --git a/hypervisor/scenarios/industry/vm_configurations.c b/hypervisor/scenarios/industry/vm_configurations.c index f50b5aa41..780efe69f 100644 --- a/hypervisor/scenarios/industry/vm_configurations.c +++ b/hypervisor/scenarios/industry/vm_configurations.c @@ -47,6 +47,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0xd2U, 0x79U, 0x54U, 0x38U, 0x25U, 0xd6U, 0x11U, 0xe8U, \ 0x86U, 0x4eU, 0xcbU, 0x7aU, 0x18U, 0xb3U, 0x46U, 0x43U}, /* d2795438-25d6-11e8-864e-cb7a18b34643 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = COM1_BASE, @@ -66,6 +67,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { /* The hard RTVM must be launched as VM2 */ .guest_flags = GUEST_FLAG_HIGHEST_SEVERITY, + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = COM1_BASE, @@ -84,6 +86,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0x38U, 0x15U, 0x88U, 0x21U, 0x52U, 0x08U, 0x40U, 0x05U, \ 0xb7U, 0x2aU, 0x8aU, 0x60U, 0x9eU, 0x41U, 0x90U, 0xd0U}, /* 38158821-5208-4005-b72a-8a609e4190d0 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = COM1_BASE, diff --git a/hypervisor/scenarios/logical_partition/vm_configurations.c b/hypervisor/scenarios/logical_partition/vm_configurations.c index d5729a152..8d1106cc7 100644 --- a/hypervisor/scenarios/logical_partition/vm_configurations.c +++ b/hypervisor/scenarios/logical_partition/vm_configurations.c @@ -18,6 +18,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { 0x81U, 0x09U, 0xf2U, 0x01U, 0xebU, 0xd6U, 0x1aU, 0x5eU}, /* 26c5e0d8-8f8a-47d8-8109-f201ebd61a5e */ .pcpu_bitmap = VM0_CONFIG_PCPU_BITMAP, + .vcpu_num = 2U, .clos = 0U, .memory = { .start_hpa = VM0_CONFIG_MEM_START_HPA, @@ -56,6 +57,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { 0xbcU, 0x58U, 0x76U, 0x05U, 0x83U, 0x7fU, 0x93U, 0x5eU}, /* dd87ce08-66f9-473d-bc58-7605837f935e */ .pcpu_bitmap = VM1_CONFIG_PCPU_BITMAP, + .vcpu_num = 2U, .guest_flags = (GUEST_FLAG_RT | GUEST_FLAG_LAPIC_PASSTHROUGH), .clos = 0U, .memory = { diff --git a/hypervisor/scenarios/sdc/vm_configurations.c b/hypervisor/scenarios/sdc/vm_configurations.c index d1c1e8ec4..dbb41229d 100644 --- a/hypervisor/scenarios/sdc/vm_configurations.c +++ b/hypervisor/scenarios/sdc/vm_configurations.c @@ -46,6 +46,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0xd2U, 0x79U, 0x54U, 0x38U, 0x25U, 0xd6U, 0x11U, 0xe8U, \ 0x86U, 0x4eU, 0xcbU, 0x7aU, 0x18U, 0xb3U, 0x46U, 0x43U}, /* d2795438-25d6-11e8-864e-cb7a18b34643 */ + .vcpu_num = CONFIG_MAX_PCPU_NUM - CONFIG_MAX_KATA_VM_NUM - 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, @@ -62,6 +63,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0xa7U, 0xadU, 0xa5U, 0x06U, 0x1aU, 0xb0U, 0x4bU, 0x6bU, \ 0xa0U, 0xdaU, 0xe5U, 0x13U, 0xcaU, 0x9bU, 0x8cU, 0x2fU}, /* a7ada506-1ab0-4b6b-a0da-e513ca9b8c2f */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, diff --git a/hypervisor/scenarios/sdc2/vm_configurations.c b/hypervisor/scenarios/sdc2/vm_configurations.c index c370c8712..634640a14 100644 --- a/hypervisor/scenarios/sdc2/vm_configurations.c +++ b/hypervisor/scenarios/sdc2/vm_configurations.c @@ -46,6 +46,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0xd2U, 0x79U, 0x54U, 0x38U, 0x25U, 0xd6U, 0x11U, 0xe8U, \ 0x86U, 0x4eU, 0xcbU, 0x7aU, 0x18U, 0xb3U, 0x46U, 0x43U}, /* d2795438-25d6-11e8-864e-cb7a18b34643 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, @@ -61,6 +62,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0x49U, 0x5aU, 0xe2U, 0xe5U, 0x26U, 0x03U, 0x4dU, 0x64U, \ 0xafU, 0x76U, 0xd4U, 0xbcU, 0x5aU, 0x8eU, 0xc0U, 0xe5U}, /* 495ae2e5-2603-4d64-af76-d4bc5a8ec0e5 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE, @@ -76,6 +78,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { .uuid = {0x38U, 0x15U, 0x88U, 0x21U, 0x52U, 0x08U, 0x40U, 0x05U, \ 0xb7U, 0x2aU, 0x8aU, 0x60U, 0x9eU, 0x41U, 0x90U, 0xd0U}, /* 38158821-5208-4005-b72a-8a609e4190d0 */ + .vcpu_num = 1U, .vuart[0] = { .type = VUART_LEGACY_PIO, .addr.port_base = INVALID_COM_BASE,