Skip to content

Commit bb0327e

Browse files
mingqiangchiwenlingz
authored andcommitted
hv: remove UUID
With current arch design the UUID is used to identify ACRN VMs, all VM configurations must be deployed with given UUIDs at build time. For post-launched VMs, end user must use UUID as acrn-dm parameter to launch specified user VM. This is not friendly for end users that they have to look up the pre-configured UUID before launching VM, and then can only launch the VM which its UUID in the pre-configured UUID list,otherwise the launch will fail.Another side, VM name is much straight forward for end user to identify VMs, whereas the VM name defined in launch script has not been passed to hypervisor VM configuration so it is not consistent with the VM name when user list VM in hypervisor shell, this would confuse user a lot. This patch will resolve these issues by removing UUID as VM identifier and use VM name instead: 1. Hypervisor will check the VM name duplication during VM creation time to make sure the VM name is unique. 2. If the VM name passed from acrn-dm matches one of pre-configured VM configurations, the corresponding VM will be launched, we call it static configured VM. If there is no matching found, hypervisor will try to allocate one unused VM configuration slot for this VM with given VM name and get it run if VM number does not reach CONFIG_MAX_VM_NUM, we will call it dynamic configured VM. 3. For dynamic configured VMs, we need a guest flag to identify them because the VM configuration need to be destroyed when it is shutdown or creation failed. v7->v8: -- rename is_static_vm_configured to is_static_configured_vm -- only set DM owned guest_flags in hcall_create_vm -- add check dynamic flag in get_unused_vmid v6->v7: -- refine get_vmid_by_name, return the first matching vm_id -- the GUEST_FLAG_STATIC_VM is added to identify the static or dynamic VM, the offline tool will set this flag for all the pre-defined VMs. -- only clear name field for dynamic VM instead of clear entire vm_config Tracked-On: #6685 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Victor Sun<victor.sun@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent ba9f339 commit bb0327e

File tree

12 files changed

+102
-114
lines changed

12 files changed

+102
-114
lines changed

hypervisor/arch/x86/configs/vm_config.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <asm/vm_config.h>
88
#include <util.h>
9+
#include <rtl.h>
910

1011
/*
1112
* @pre vm_id < CONFIG_MAX_VM_NUM
@@ -25,13 +26,13 @@ uint8_t get_vm_severity(uint16_t vm_id)
2526
}
2627

2728
/**
28-
* return true if the input uuid is configured in VM
29+
* return true if the input vm-name is configured in VM
2930
*
3031
* @pre vmid < CONFIG_MAX_VM_NUM
3132
*/
32-
bool vm_has_matched_uuid(uint16_t vmid, const uint8_t *uuid)
33+
bool vm_has_matched_name(uint16_t vmid, const char *name)
3334
{
3435
struct acrn_vm_config *vm_config = get_vm_config(vmid);
3536

36-
return (uuid_is_equal(vm_config->uuid, uuid));
37+
return (strncmp(vm_config->name, name, MAX_VM_NAME_LEN) == 0);
3738
}

hypervisor/arch/x86/guest/trusty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static bool setup_trusty_info(struct acrn_vcpu *vcpu, uint32_t mem_size, uint64_
279279
/* Derive dvseed from dseed for Trusty */
280280
if (derive_virtual_seed(&key_info.dseed_list[0U], &key_info.num_seeds,
281281
NULL, 0U,
282-
vcpu->vm->uuid, sizeof(vcpu->vm->uuid))) {
282+
(uint8_t *)vcpu->vm->name, strnlen_s(vcpu->vm->name, MAX_VM_NAME_LEN))) {
283283
/* Derive encryption key of attestation keybox from dseed */
284284
if (derive_attkb_enc_key(key_info.attkb_enc_key)) {
285285
/* Prepare trusty startup param */

hypervisor/arch/x86/guest/vm.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,30 @@ void *get_sworld_memory_base(void)
5858
return post_user_vm_sworld_memory;
5959
}
6060

61-
uint16_t get_vmid_by_uuid(const uint8_t *uuid)
61+
uint16_t get_unused_vmid(void)
6262
{
63-
uint16_t vm_id = 0U;
63+
uint16_t vm_id;
64+
struct acrn_vm_config *vm_config;
65+
66+
for (vm_id = 0; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
67+
vm_config = get_vm_config(vm_id);
68+
if ((vm_config->name[0] == '\0') && ((vm_config->guest_flags & GUEST_FLAG_STATIC_VM) == 0U)) {
69+
break;
70+
}
71+
}
72+
return (vm_id < CONFIG_MAX_VM_NUM) ? (vm_id) : (ACRN_INVALID_VMID);
73+
}
74+
75+
uint16_t get_vmid_by_name(const char *name)
76+
{
77+
uint16_t vm_id;
6478

65-
while (!vm_has_matched_uuid(vm_id, uuid)) {
66-
vm_id++;
67-
if (vm_id == CONFIG_MAX_VM_NUM) {
79+
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
80+
if ((*name != '\0') && vm_has_matched_name(vm_id, name)) {
6881
break;
6982
}
7083
}
71-
return vm_id;
84+
return (vm_id < CONFIG_MAX_VM_NUM) ? (vm_id) : (ACRN_INVALID_VMID);
7285
}
7386

7487
/**
@@ -162,6 +175,16 @@ bool is_vcat_configured(const struct acrn_vm *vm)
162175
return ((vm_config->guest_flags & GUEST_FLAG_VCAT_ENABLED) != 0U);
163176
}
164177

178+
/**
179+
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
180+
*/
181+
bool is_static_configured_vm(const struct acrn_vm *vm)
182+
{
183+
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
184+
185+
return ((vm_config->guest_flags & GUEST_FLAG_STATIC_VM) != 0U);
186+
}
187+
165188
/**
166189
* @brief VT-d PI posted mode can possibly be used for PTDEVs assigned
167190
* to this VM if platform supports VT-d PI AND lapic passthru is not configured
@@ -546,8 +569,7 @@ int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *v
546569
init_ept_pgtable(&vm->arch_vm.ept_pgtable, vm->vm_id);
547570
vm->arch_vm.nworld_eptp = pgtable_create_root(&vm->arch_vm.ept_pgtable);
548571

549-
(void)memcpy_s(&vm->uuid[0], sizeof(vm->uuid),
550-
&vm_config->uuid[0], sizeof(vm_config->uuid));
572+
(void)memcpy_s(&vm->name[0], MAX_VM_NAME_LEN, &vm_config->name[0], MAX_VM_NAME_LEN);
551573

552574
if (is_service_vm(vm)) {
553575
/* Only for Service VM */
@@ -792,6 +814,9 @@ int32_t shutdown_vm(struct acrn_vm *vm)
792814
/* after guest_flags not used, then clear it */
793815
vm_config = get_vm_config(vm->vm_id);
794816
vm_config->guest_flags &= ~DM_OWNED_GUEST_FLAG_MASK;
817+
if (!is_static_configured_vm(vm)) {
818+
memset(vm_config->name, 0U, MAX_VM_NAME_LEN);
819+
}
795820

796821
if (is_ready_for_system_shutdown()) {
797822
/* If no any guest running, shutdown system */
@@ -932,8 +957,13 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
932957
#ifdef CONFIG_SECURITY_VM_FIXUP
933958
security_vm_fixup(vm_id);
934959
#endif
935-
/* Service VM and pre-launched VMs launch on all pCPUs defined in vm_config->cpu_affinity */
936-
err = create_vm(vm_id, vm_config->cpu_affinity, vm_config, &vm);
960+
if (get_vmid_by_name(vm_config->name) != vm_id) {
961+
pr_err("Invalid VM name: %s", vm_config->name);
962+
err = -1;
963+
} else {
964+
/* Service VM and pre-launched VMs launch on all pCPUs defined in vm_config->cpu_affinity */
965+
err = create_vm(vm_id, vm_config->cpu_affinity, vm_config, &vm);
966+
}
937967

938968
if (err == 0) {
939969
if (is_prelaunched_vm(vm)) {

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <trace.h>
1616
#include <logmsg.h>
1717

18+
static spinlock_t vm_id_lock = { .head = 0U, .tail = 0U };
1819
struct hc_dispatch {
1920
int32_t (*handler)(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, uint64_t param1, uint64_t param2);
2021

@@ -105,6 +106,22 @@ static const struct hc_dispatch hc_dispatch_table[] = {
105106
.permission_flags = GUEST_FLAG_SECURE_WORLD_ENABLED},
106107
};
107108

109+
uint16_t allocate_dynamical_vmid(struct acrn_vm_creation *cv)
110+
{
111+
uint16_t vm_id;
112+
struct acrn_vm_config *vm_config;
113+
114+
spinlock_obtain(&vm_id_lock);
115+
vm_id = get_unused_vmid();
116+
if (vm_id != ACRN_INVALID_VMID) {
117+
vm_config = get_vm_config(vm_id);
118+
memcpy_s(vm_config->name, MAX_VM_NAME_LEN, cv->name, MAX_VM_NAME_LEN);
119+
vm_config->cpu_affinity = cv->cpu_affinity;
120+
}
121+
spinlock_release(&vm_id_lock);
122+
return vm_id;
123+
}
124+
108125
#define GUEST_FLAGS_ALLOWING_HYPERCALLS GUEST_FLAG_SECURE_WORLD_ENABLED
109126

110127
struct acrn_vm *parse_target_vm(struct acrn_vm *service_vm, uint64_t hcall_id, uint64_t param1, __unused uint64_t param2)
@@ -118,7 +135,19 @@ struct acrn_vm *parse_target_vm(struct acrn_vm *service_vm, uint64_t hcall_id, u
118135
switch (hcall_id) {
119136
case HC_CREATE_VM:
120137
if (copy_from_gpa(service_vm, &cv, param1, sizeof(cv)) == 0) {
121-
vm_id = get_vmid_by_uuid(&cv.uuid[0]);
138+
vm_id = get_vmid_by_name((char *)cv.name);
139+
/* if the vm-name is not found, it indicates that it is not in pre-defined vm_list.
140+
* So try to allocate one free slot to start one vm based on user-requirement
141+
*/
142+
if (vm_id == ACRN_INVALID_VMID) {
143+
vm_id = allocate_dynamical_vmid(&cv);
144+
/* it doesn't find the available vm_slot for the given vm_name.
145+
* Maybe the CONFIG_MAX_VM_NUM is too small to start the VM.
146+
*/
147+
if (vm_id == ACRN_INVALID_VMID) {
148+
pr_err("The VM name provided (%s) is invalid, cannot create VM", cv.name);
149+
}
150+
}
122151
}
123152
break;
124153

hypervisor/common/hypercall.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,13 @@ int32_t hcall_create_vm(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, uint6
254254
int32_t ret = -1;
255255
struct acrn_vm *tgt_vm = NULL;
256256
struct acrn_vm_creation cv;
257-
struct acrn_vm_config* vm_config = NULL;
257+
struct acrn_vm_config *vm_config = get_vm_config(vmid);
258258

259259
if (copy_from_gpa(vm, &cv, param1, sizeof(cv)) == 0) {
260260
if (is_poweroff_vm(get_vm_from_vmid(vmid))) {
261261

262-
vm_config = get_vm_config(vmid);
263-
264262
/* Filter out the bits should not set by DM and then assign it to guest_flags */
263+
vm_config->guest_flags &= ~DM_OWNED_GUEST_FLAG_MASK;
265264
vm_config->guest_flags |= (cv.vm_flag & DM_OWNED_GUEST_FLAG_MASK);
266265

267266
/* post-launched VM is allowed to choose pCPUs from vm_config->cpu_affinity only */
@@ -301,6 +300,10 @@ int32_t hcall_create_vm(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm, uint6
301300

302301
}
303302

303+
if (((ret != 0) || (cv.vmid == ACRN_INVALID_VMID)) && (!is_static_configured_vm(target_vm))) {
304+
memset(vm_config->name, 0U, MAX_VM_NAME_LEN);
305+
}
306+
304307
return ret;
305308
}
306309

hypervisor/debug/profiling.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,6 @@ int32_t profiling_vm_list_info(struct acrn_vm *vm, uint64_t addr)
875875
vm_idx++;
876876

877877
vm_info_list.vm_list[vm_idx].vm_id_num = tmp_vm->vm_id;
878-
(void)memcpy_s((void *)vm_info_list.vm_list[vm_idx].uuid,
879-
16U, tmp_vm->uuid, 16U);
880878
snprintf(vm_info_list.vm_list[vm_idx].vm_name, 16U, "vm_%d",
881879
tmp_vm->vm_id, 16U);
882880
vm_info_list.vm_list[vm_idx].num_vcpus = 0;

hypervisor/debug/shell.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv)
590590
uint16_t vm_id;
591591
char state[32];
592592

593-
shell_puts("\r\nVM_UUID VM_ID VM_NAME VM_STATE"
594-
"\r\n================================ ===== ================================ ========\r\n");
593+
shell_puts("\r\nVM_ID VM_NAME VM_STATE"
594+
"\r\n===== ================================ ========\r\n");
595595

596596
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
597597
vm = get_vm_from_vmid(vm_id);
@@ -614,12 +614,7 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv)
614614
}
615615
vm_config = get_vm_config(vm_id);
616616
if (!is_poweroff_vm(vm)) {
617-
int8_t i;
618-
619-
for (i = 0; i < 16; i++) {
620-
snprintf(temp_str + 2 * i, 3U, "%02x", vm->uuid[i]);
621-
}
622-
snprintf(temp_str + 32, MAX_STR_SIZE - 32U, " %-3d %-32s %-8s\r\n",
617+
snprintf(temp_str, MAX_STR_SIZE, " %-3d %-32s %-8s\r\n",
623618
vm_id, vm_config->name, state);
624619

625620
/* Output information for this task */

hypervisor/include/arch/x86/asm/guest/vm.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct acrn_vm {
156156

157157
struct vm_io_handler_desc emul_pio[EMUL_PIO_IDX_MAX];
158158

159-
uint8_t uuid[16];
159+
char name[MAX_VM_NAME_LEN];
160160
struct secure_world_control sworld_control;
161161

162162
/* Secure World's snapshot
@@ -241,7 +241,7 @@ bool is_paused_vm(const struct acrn_vm *vm);
241241
bool is_service_vm(const struct acrn_vm *vm);
242242
bool is_postlaunched_vm(const struct acrn_vm *vm);
243243
bool is_prelaunched_vm(const struct acrn_vm *vm);
244-
uint16_t get_vmid_by_uuid(const uint8_t *uuid);
244+
uint16_t get_vmid_by_name(const char *name);
245245
struct acrn_vm *get_vm_from_vmid(uint16_t vm_id);
246246
struct acrn_vm *get_service_vm(void);
247247

@@ -257,6 +257,8 @@ bool is_lapic_pt_configured(const struct acrn_vm *vm);
257257
bool is_rt_vm(const struct acrn_vm *vm);
258258
bool is_nvmx_configured(const struct acrn_vm *vm);
259259
bool is_vcat_configured(const struct acrn_vm *vm);
260+
bool is_static_configured_vm(const struct acrn_vm *vm);
261+
uint16_t get_unused_vmid(void);
260262
bool is_pi_capable(const struct acrn_vm *vm);
261263
bool has_rt_vm(void);
262264
struct acrn_vm *get_highest_severity_vm(bool runtime);

hypervisor/include/arch/x86/asm/vm_config.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
#include <board_info.h>
1313
#include <boot.h>
1414
#include <acrn_common.h>
15-
#include <vm_uuids.h>
1615
#include <vm_configurations.h>
1716
#include <asm/sgx.h>
1817
#include <acrn_hv_defs.h>
1918

20-
#define CONFIG_MAX_VM_NUM (PRE_VM_NUM + SERVICE_VM_NUM + MAX_POST_VM_NUM)
21-
2219
#define AFFINITY_CPU(n) (1UL << (n))
2320
#define MAX_VCPUS_PER_VM MAX_PCPU_NUM
2421
#define MAX_VUART_NUM_PER_VM 8U
@@ -38,31 +35,24 @@
3835
#define MAX_MMIO_DEV_NUM 2U
3936

4037
#define CONFIG_SERVICE_VM .load_order = SERVICE_VM, \
41-
.uuid = SERVICE_VM_UUID, \
4238
.severity = SEVERITY_SERVICE_VM
4339

44-
#define CONFIG_SAFETY_VM(idx) .load_order = PRE_LAUNCHED_VM, \
45-
.uuid = SAFETY_VM_UUID##idx, \
40+
#define CONFIG_SAFETY_VM .load_order = PRE_LAUNCHED_VM, \
4641
.severity = SEVERITY_SAFETY_VM
4742

48-
#define CONFIG_PRE_STD_VM(idx) .load_order = PRE_LAUNCHED_VM, \
49-
.uuid = PRE_STANDARD_VM_UUID##idx, \
43+
#define CONFIG_PRE_STD_VM .load_order = PRE_LAUNCHED_VM, \
5044
.severity = SEVERITY_STANDARD_VM
5145

52-
#define CONFIG_PRE_RT_VM(idx) .load_order = PRE_LAUNCHED_VM, \
53-
.uuid = PRE_RTVM_UUID##idx, \
46+
#define CONFIG_PRE_RT_VM .load_order = PRE_LAUNCHED_VM, \
5447
.severity = SEVERITY_RTVM
5548

56-
#define CONFIG_POST_STD_VM(idx) .load_order = POST_LAUNCHED_VM, \
57-
.uuid = POST_STANDARD_VM_UUID##idx, \
49+
#define CONFIG_POST_STD_VM .load_order = POST_LAUNCHED_VM, \
5850
.severity = SEVERITY_STANDARD_VM
5951

60-
#define CONFIG_POST_RT_VM(idx) .load_order = POST_LAUNCHED_VM, \
61-
.uuid = POST_RTVM_UUID##idx, \
52+
#define CONFIG_POST_RT_VM .load_order = POST_LAUNCHED_VM, \
6253
.severity = SEVERITY_RTVM
6354

64-
#define CONFIG_KATA_VM(idx) .load_order = POST_LAUNCHED_VM, \
65-
.uuid = KATA_VM_UUID##idx, \
55+
#define CONFIG_KATA_VM .load_order = POST_LAUNCHED_VM, \
6656
.severity = SEVERITY_STANDARD_VM
6757

6858
/* ACRN guest severity */
@@ -154,8 +144,7 @@ struct pt_intx_config {
154144

155145
struct acrn_vm_config {
156146
enum acrn_vm_load_order load_order; /* specify the load order of VM */
157-
char name[MAX_VM_OS_NAME_LEN]; /* VM name identifier, useful for debug. */
158-
const uint8_t uuid[16]; /* UUID of the VM */
147+
char name[MAX_VM_NAME_LEN]; /* VM name identifier */
159148
uint8_t reserved[2]; /* Temporarily reserve it so that don't need to update
160149
* the users of get_platform_info frequently.
161150
*/
@@ -214,7 +203,7 @@ struct acrn_vm_config {
214203

215204
struct acrn_vm_config *get_vm_config(uint16_t vm_id);
216205
uint8_t get_vm_severity(uint16_t vm_id);
217-
bool vm_has_matched_uuid(uint16_t vmid, const uint8_t *uuid);
206+
bool vm_has_matched_name(uint16_t vmid, const char *name);
218207

219208
extern struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM];
220209

hypervisor/include/common/vm_uuids.h

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)