From 7345677bbb300b95b71282f5a189dfd83fac4051 Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Fri, 3 Aug 2018 15:43:25 +0800 Subject: [PATCH] hv:cleanup vmid related code Remove structure vm_attr Wrap two APIs alloc_vm_id and free_vm_id Signed-off-by: Mingqiang Chi Acked-by: Eddie Dong --- hypervisor/arch/x86/assign.c | 30 +++++++++---------- hypervisor/arch/x86/ept.c | 4 +-- hypervisor/arch/x86/guest/guest.c | 2 +- hypervisor/arch/x86/guest/pm.c | 2 +- hypervisor/arch/x86/guest/vcpu.c | 8 ++--- hypervisor/arch/x86/guest/vlapic.c | 6 ++-- hypervisor/arch/x86/guest/vm.c | 41 ++++++++++++++++---------- hypervisor/arch/x86/guest/vmcall.c | 2 +- hypervisor/arch/x86/guest/vpic.c | 2 +- hypervisor/arch/x86/mtrr.c | 2 +- hypervisor/arch/x86/trusty2.c | 2 +- hypervisor/common/hypercall.c | 14 ++++----- hypervisor/common/io_request.c | 2 +- hypervisor/common/vm_load.c | 4 +-- hypervisor/debug/dump.c | 2 +- hypervisor/debug/shell.c | 8 ++--- hypervisor/include/arch/x86/guest/vm.h | 7 ++--- 17 files changed, 73 insertions(+), 65 deletions(-) diff --git a/hypervisor/arch/x86/assign.c b/hypervisor/arch/x86/assign.c index cd413528b..0cef4d6de 100644 --- a/hypervisor/arch/x86/assign.c +++ b/hypervisor/arch/x86/assign.c @@ -329,10 +329,10 @@ add_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, " not able to add into vm%d with vbdf%x", entry->phys_bdf, entry->ptdev_intr_info.msi.msix_entry_index, - entry->vm->attr.id, - entry->virt_bdf, vm->attr.id, virt_bdf); + entry->vm->vm_id, + entry->virt_bdf, vm->vm_id, virt_bdf); ASSERT(false, "msix entry pbdf%x idx%d already in vm%d", - phys_bdf, msix_entry_index, entry->vm->attr.id); + phys_bdf, msix_entry_index, entry->vm->vm_id); spinlock_release(&ptdev_lock); return &invalid_entry; @@ -345,7 +345,7 @@ add_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, dev_dbg(ACRN_DBG_IRQ, "VM%d MSIX add vector mapping vbdf%x:pbdf%x idx=%d", - entry->vm->attr.id, virt_bdf, phys_bdf, msix_entry_index); + entry->vm->vm_id, virt_bdf, phys_bdf, msix_entry_index); return entry; } @@ -369,7 +369,7 @@ remove_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint32_t msix_entry_inde dev_dbg(ACRN_DBG_IRQ, "VM%d MSIX remove vector mapping vbdf-pbdf:0x%x-0x%x idx=%d", - entry->vm->attr.id, + entry->vm->vm_id, entry->virt_bdf, entry->phys_bdf, msix_entry_index); release_entry(entry); @@ -413,11 +413,11 @@ add_intx_remapping(struct vm *vm, uint8_t virt_pin, pr_err("INTX pin%d already in vm%d with vpin%d," " not able to add into vm%d with vpin%d", entry->ptdev_intr_info.intx.phys_pin, - entry->vm->attr.id, + entry->vm->vm_id, entry->ptdev_intr_info.intx.virt_pin, - vm->attr.id, virt_pin); + vm->vm_id, virt_pin); ASSERT(false, "intx entry pin%d already vm%d", - phys_pin, entry->vm->attr.id); + phys_pin, entry->vm->vm_id); spinlock_release(&ptdev_lock); return &invalid_entry; @@ -431,7 +431,7 @@ add_intx_remapping(struct vm *vm, uint8_t virt_pin, dev_dbg(ACRN_DBG_IRQ, "VM%d INTX add pin mapping vpin%d:ppin%d", - entry->vm->attr.id, virt_pin, phys_pin); + entry->vm->vm_id, virt_pin, phys_pin); return entry; } @@ -466,7 +466,7 @@ static void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin) "vPIC" : "vIOAPIC", entry->ptdev_intr_info.intx.phys_pin, phys_irq); dev_dbg(ACRN_DBG_IRQ, "from vm%d vpin=%d\n", - entry->vm->attr.id, + entry->vm->vm_id, entry->ptdev_intr_info.intx.virt_pin); } @@ -677,7 +677,7 @@ int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf, entry->ptdev_intr_info.msi.msix_entry_index, entry->ptdev_intr_info.msi.virt_vector, entry->ptdev_intr_info.msi.phys_vector, - entry->vm->attr.id); + entry->vm->vm_id); END: return 0; } @@ -831,7 +831,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info) (entry->ptdev_intr_info.intx.vpin_src != 0)? "vIOPIC" : "vPIC", info->virt_pin, - entry->vm->attr.id); + entry->vm->vm_id); intx->vpin_src = info->vpin_src; intx->virt_pin = info->virt_pin; } @@ -848,7 +848,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info) "IOAPIC pin=%hhu pirq=%u deassigned ", phys_pin, phys_irq); dev_dbg(ACRN_DBG_IRQ, "from vm%d vIOAPIC vpin=%d", - entry->vm->attr.id, + entry->vm->vm_id, intx->virt_pin); goto END; } else { @@ -869,7 +869,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info) dev_dbg(ACRN_DBG_IRQ, "IOAPIC pin=%hhu pirq=%u assigned to vm%d %s vpin=%d", - phys_pin, phys_irq, entry->vm->attr.id, + phys_pin, phys_irq, entry->vm->vm_id, intx->vpin_src == PTDEV_VPIN_PIC ? "vPIC" : "vIOAPIC", intx->virt_pin); @@ -1037,7 +1037,7 @@ void get_ptdev_info(char *str_arg, int str_max) &bdf, &vbdf); len = snprintf(str, size, "\r\n%d\t%s\t%d\t0x%X\t0x%X", - entry->vm->attr.id, type, + entry->vm->vm_id, type, irq, vector, dest); size -= len; str += len; diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 26e4b52a0..33e10f130 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -129,7 +129,7 @@ uint64_t local_gpa2hpa(struct vm *vm, uint64_t gpa, uint32_t *size) pr_dbg("GPA2HPA: 0x%llx->0x%llx", gpa, hpa); } else { pr_err("VM %d GPA2HPA: failed for gpa 0x%llx", - vm->attr.boot_idx, gpa); + vm->vm_id, gpa); } if (size != NULL) { @@ -153,7 +153,7 @@ uint64_t hpa2gpa(struct vm *vm, uint64_t hpa) hpa, &pg_size, PTT_EPT); if (pgentry == NULL) { pr_err("VM %d hpa2gpa: failed for hpa 0x%llx", - vm->attr.boot_idx, hpa); + vm->vm_id, hpa); ASSERT(false, "hpa2gpa not found"); } return ((*pgentry & (~(pg_size - 1UL))) diff --git a/hypervisor/arch/x86/guest/guest.c b/hypervisor/arch/x86/guest/guest.c index fd1e73cc4..fe48af056 100644 --- a/hypervisor/arch/x86/guest/guest.c +++ b/hypervisor/arch/x86/guest/guest.c @@ -32,7 +32,7 @@ struct page_walk_info { inline bool is_vm0(struct vm *vm) { - return (vm->attr.boot_idx & 0x7FU) == 0U; + return (vm->vm_id) == 0U; } inline struct vcpu *vcpu_from_vid(struct vm *vm, uint16_t vcpu_id) diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c index 1eea13e8b..e3058e76e 100644 --- a/hypervisor/arch/x86/guest/pm.c +++ b/hypervisor/arch/x86/guest/pm.c @@ -210,7 +210,7 @@ register_gas_io_handler(struct vm *vm, struct acpi_generic_address *gas) &pm1ab_io_read, &pm1ab_io_write); pr_dbg("Enable PM1A trap for VM %d, port 0x%x, size %d\n", - vm->attr.id, gas_io.base, gas_io.len); + vm->vm_id, gas_io.base, gas_io.len); } void register_pm1ab_handler(struct vm *vm) diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index e801ce7bb..69742630d 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -75,7 +75,7 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle) per_cpu(vcpu, pcpu_id) = vcpu; pr_info("PCPU%d is working as VM%d VCPU%d, Role: %s", - vcpu->pcpu_id, vcpu->vm->attr.id, vcpu->vcpu_id, + vcpu->pcpu_id, vcpu->vm->vm_id, vcpu->vcpu_id, is_vcpu_bsp(vcpu) ? "PRIMARY" : "SECONDARY"); #ifdef CONFIG_START_VM0_BSP_64BIT @@ -84,7 +84,7 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle) /* Set up temporary guest page tables */ vm->arch_vm.guest_init_pml4 = create_guest_initial_paging(vm); pr_info("VM %d VCPU %hu CR3: 0x%016llx ", - vm->attr.id, vcpu->vcpu_id, + vm->vm_id, vcpu->vcpu_id, vm->arch_vm.guest_init_pml4); } #endif @@ -156,7 +156,7 @@ int start_vcpu(struct vcpu *vcpu) /* If this VCPU is not already launched, launch it */ if (!vcpu->launched) { pr_info("VM %d Starting VCPU %hu", - vcpu->vm->attr.id, vcpu->vcpu_id); + vcpu->vm->vm_id, vcpu->vcpu_id); if (vcpu->arch_vcpu.vpid) exec_vmwrite16(VMX_VPID, vcpu->arch_vcpu.vpid); @@ -185,7 +185,7 @@ int start_vcpu(struct vcpu *vcpu) if (status == 0) { if (is_vcpu_bsp(vcpu)) { pr_info("VM %d VCPU %hu successfully launched", - vcpu->vm->attr.id, vcpu->vcpu_id); + vcpu->vm->vm_id, vcpu->vcpu_id); } } } else { diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index 5cb7200c4..f1b782761 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -105,7 +105,7 @@ vm_lapic_from_vcpu_id(struct vm *vm, uint16_t vcpu_id) struct vcpu *vcpu; vcpu = vcpu_from_vid(vm, vcpu_id); - ASSERT(vcpu != NULL, "vm%d, vcpu%hu", vm->attr.id, vcpu_id); + ASSERT(vcpu != NULL, "vm%d, vcpu%hu", vm->vm_id, vcpu_id); return vcpu->arch_vcpu.vlapic; } @@ -116,7 +116,7 @@ vm_lapic_from_pcpuid(struct vm *vm, uint16_t pcpu_id) struct vcpu *vcpu; vcpu = vcpu_from_pid(vm, pcpu_id); - ASSERT(vcpu != NULL, "vm%d, pcpu%hu", vm->attr.id, pcpu_id); + ASSERT(vcpu != NULL, "vm%d, pcpu%hu", vm->vm_id, pcpu_id); return vcpu->arch_vcpu.vlapic; } @@ -1173,7 +1173,7 @@ vlapic_icrlo_write_handler(struct acrn_vlapic *vlapic) target_vcpu->arch_vcpu.sipi_vector = vec; pr_err("Start Secondary VCPU%hu for VM[%d]...", target_vcpu->vcpu_id, - target_vcpu->vm->attr.id); + target_vcpu->vm->vm_id); schedule_vcpu(target_vcpu); } else { pr_err("Unhandled icrlo write with mode %u\n", mode); diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index e4e615e16..620835548 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -25,6 +25,25 @@ spinlock_t vm_list_lock = { /* used for vmid allocation. And this means the max vm number is 64 */ static uint64_t vmid_bitmap; +static inline uint16_t alloc_vm_id(void) +{ + uint16_t id = ffz64(vmid_bitmap); + + while (id < (size_t)(sizeof(vmid_bitmap) * 8U)) { + if (!bitmap_test_and_set_lock(id, &vmid_bitmap)) { + return id; + } + id = ffz64(vmid_bitmap); + } + + return INVALID_VM_ID; +} + +static inline void free_vm_id(struct vm *vm) +{ + bitmap_clear_lock(vm->vm_id, &vmid_bitmap); +} + static void init_vm(struct vm_description *vm_desc, struct vm *vm_handle) { @@ -54,7 +73,7 @@ struct vm *get_vm_from_vmid(uint16_t vm_id) spinlock_obtain(&vm_list_lock); list_for_each(pos, &vm_list) { vm = list_entry(pos, struct vm, list); - if (vm->attr.id == vm_id) { + if (vm->vm_id == vm_id) { spinlock_release(&vm_list_lock); return vm; } @@ -66,7 +85,6 @@ struct vm *get_vm_from_vmid(uint16_t vm_id) int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm) { - uint16_t id; struct vm *vm; int status; @@ -102,21 +120,13 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm) goto err; } - for (id = 0U; id < (size_t)(sizeof(vmid_bitmap) * 8U); id++) { - if (!bitmap_test_and_set_lock(id, &vmid_bitmap)) { - break; - } - } - - if (id >= (size_t)(sizeof(vmid_bitmap) * 8U)) { + vm->vm_id = alloc_vm_id(); + if (vm->vm_id == INVALID_VM_ID) { pr_err("%s, no more VMs can be supported\n", __func__); - status = -EINVAL; + status = -ENODEV; goto err; } - vm->attr.id = id; - vm->attr.boot_idx = id; - atomic_store16(&vm->hw.created_vcpus, 0U); /* gpa_lowtop are used for system start up */ @@ -273,7 +283,8 @@ int shutdown_vm(struct vm *vm) destroy_iommu_domain(vm->iommu); } - bitmap_clear_lock(vm->attr.id, &vmid_bitmap); + /* Free vm id */ + free_vm_id(vm); if (vm->vpic != NULL) { vpic_cleanup(vm); @@ -300,7 +311,7 @@ int start_vm(struct vm *vm) /* Only start BSP (vid = 0) and let BSP start other APs */ vcpu = vcpu_from_vid(vm, 0U); - ASSERT(vcpu != NULL, "vm%d, vcpu0", vm->attr.id); + ASSERT(vcpu != NULL, "vm%d, vcpu0", vm->vm_id); schedule_vcpu(vcpu); return 0; diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index 0556e6ccd..5e30b2696 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -181,7 +181,7 @@ int vmcall_vmexit_handler(struct vcpu *vcpu) out: cur_context->guest_cpu_regs.regs.rax = (uint64_t)ret; - TRACE_2L(TRACE_VMEXIT_VMCALL, vm->attr.id, hypcall_id); + TRACE_2L(TRACE_VMEXIT_VMCALL, vm->vm_id, hypcall_id); return 0; } diff --git a/hypervisor/arch/x86/guest/vpic.c b/hypervisor/arch/x86/guest/vpic.c index 2c6a84e02..c0a74110c 100644 --- a/hypervisor/arch/x86/guest/vpic.c +++ b/hypervisor/arch/x86/guest/vpic.c @@ -234,7 +234,7 @@ static void vpic_notify_intr(struct acrn_vpic *vpic) if (vpic->vm->wire_mode == VPIC_WIRE_INTR) { struct vcpu *vcpu = vcpu_from_vid(vpic->vm, 0U); - ASSERT(vcpu != NULL, "vm%d, vcpu0", vpic->vm->attr.id); + ASSERT(vcpu != NULL, "vm%d, vcpu0", vpic->vm->vm_id); vcpu_inject_extint(vcpu); } else { vlapic_set_local_intr(vpic->vm, BROADCAST_CPU_ID, APIC_LVT_LINT0); diff --git a/hypervisor/arch/x86/mtrr.c b/hypervisor/arch/x86/mtrr.c index 4811d6ee3..32e4eb340 100644 --- a/hypervisor/arch/x86/mtrr.c +++ b/hypervisor/arch/x86/mtrr.c @@ -117,7 +117,7 @@ void init_mtrr(struct vcpu *vcpu) } pr_dbg("vm%d vcpu%hu fixed-range MTRR[%u]: %16llx", - vcpu->vm->attr.id, vcpu->vcpu_id, i, + vcpu->vm->vm_id, vcpu->vcpu_id, i, vcpu->mtrr.fixed_range[i].value); } } diff --git a/hypervisor/arch/x86/trusty2.c b/hypervisor/arch/x86/trusty2.c index 877cd1fa6..3bfe0012d 100644 --- a/hypervisor/arch/x86/trusty2.c +++ b/hypervisor/arch/x86/trusty2.c @@ -25,7 +25,7 @@ uint64_t gpa2hpa_for_trusty(struct vm *vm, uint64_t gpa) pr_dbg("GPA2HPA: 0x%llx->0x%llx", gpa, hpa); } else { pr_err("VM %d GPA2HPA: failed for gpa 0x%llx", - vm->attr.boot_idx, gpa); + vm->vm_id, gpa); } return hpa; diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index fd32386b0..280bfd0b1 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -181,7 +181,7 @@ int32_t hcall_create_vm(struct vm *vm, uint64_t param) cv.vmid = ACRN_INVALID_VMID; ret = -1; } else { - cv.vmid = target_vm->attr.id; + cv.vmid = target_vm->vm_id; ret = 0; } @@ -393,7 +393,7 @@ int32_t hcall_notify_ioreq_finish(uint16_t vmid, uint16_t vcpu_id) vcpu = vcpu_from_vid(target_vm, vcpu_id); if (vcpu == NULL) { pr_err("%s, failed to get VCPU %d context from VM %d\n", - __func__, vcpu_id, target_vm->attr.id); + __func__, vcpu_id, target_vm->vm_id); return -EINVAL; } @@ -410,13 +410,13 @@ static int32_t local_set_vm_memory_region(struct vm *vm, if ((region->size & (CPU_PAGE_SIZE - 1UL)) != 0UL) { pr_err("%s: [vm%d] map size 0x%x is not page aligned", - __func__, target_vm->attr.id, region->size); + __func__, target_vm->vm_id, region->size); return -EINVAL; } hpa = gpa2hpa(vm, region->vm0_gpa); dev_dbg(ACRN_DBG_HYCALL, "[vm%d] gpa=0x%x hpa=0x%x size=0x%x", - target_vm->attr.id, region->gpa, hpa, region->size); + target_vm->vm_id, region->gpa, hpa, region->size); base_paddr = get_hv_image_base(); if (((hpa <= base_paddr) && @@ -540,7 +540,7 @@ static int32_t write_protect_page(struct vm *vm, struct wp_data *wp) hpa = gpa2hpa(vm, wp->gpa); dev_dbg(ACRN_DBG_HYCALL, "[vm%d] gpa=0x%x hpa=0x%x", - vm->attr.id, wp->gpa, hpa); + vm->vm_id, wp->gpa, hpa); base_paddr = get_hv_image_base(); if (((hpa <= base_paddr) && (hpa + CPU_PAGE_SIZE > base_paddr)) || @@ -665,7 +665,7 @@ int32_t hcall_assign_ptdev(struct vm *vm, uint16_t vmid, uint64_t param) if (copy_from_gpa(vm, &bdf, param, sizeof(bdf)) != 0) { pr_err("%s: Unable copy param from vm %d\n", - __func__, vm->attr.id); + __func__, vm->vm_id); return -EIO; } @@ -673,7 +673,7 @@ int32_t hcall_assign_ptdev(struct vm *vm, uint16_t vmid, uint64_t param) if (target_vm->iommu == NULL) { if (target_vm->arch_vm.nworld_eptp == NULL) { pr_err("%s, EPT of VM not set!\n", - __func__, target_vm->attr.id); + __func__, target_vm->vm_id); return -EPERM; } /* TODO: how to get vm's address width? */ diff --git a/hypervisor/common/io_request.c b/hypervisor/common/io_request.c index 2d617920f..7897d6c43 100644 --- a/hypervisor/common/io_request.c +++ b/hypervisor/common/io_request.c @@ -188,7 +188,7 @@ void get_req_info(char *str_arg, int str_max) state, dir, &addr, &val); len = snprintf(str, size, "\r\n%d\t%d\t%d\t%s\t%s\t%s", - vm->attr.id, i, client_id, type, + vm->vm_id, i, client_id, type, state, dir); size -= len; str += len; diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index afb7e9006..15e7c600f 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -137,7 +137,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) /* Set VCPU entry point to kernel entry */ vcpu->entry_addr = sw_kernel->kernel_entry_addr; pr_info("%s, VM *d VCPU %hu Entry: 0x%016llx ", - __func__, vm->attr.id, vcpu->vcpu_id, vcpu->entry_addr); + __func__, vm->vm_id, vcpu->vcpu_id, vcpu->entry_addr); } /* Calculate the host-physical address where the guest will be loaded */ @@ -220,7 +220,7 @@ int general_sw_loader(struct vm *vm, struct vcpu *vcpu) cur_context->guest_cpu_regs.regs.rsi = create_zero_page(vm); pr_info("%s, RSI pointing to zero page for VM %d at GPA %X", - __func__, vm->attr.id, + __func__, vm->vm_id, cur_context->guest_cpu_regs.regs.rsi); } else { diff --git a/hypervisor/debug/dump.c b/hypervisor/debug/dump.c index 03b89daa0..6911b99f7 100644 --- a/hypervisor/debug/dump.c +++ b/hypervisor/debug/dump.c @@ -57,7 +57,7 @@ static void dump_guest_reg(struct vcpu *vcpu) printf("Guest Registers:\r\n"); printf("= VM ID %d ==== vCPU ID %hu === pCPU ID %d ====" "world %d =============\r\n", - vcpu->vm->attr.id, vcpu->vcpu_id, vcpu->pcpu_id, + vcpu->vm->vm_id, vcpu->vcpu_id, vcpu->pcpu_id, vcpu->arch_vcpu.cur_context); printf("= RIP=0x%016llx RSP=0x%016llx " "RFLAGS=0x%016llx\r\n", diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index 7ba66e2cc..cc19b3d9f 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -517,8 +517,8 @@ int shell_list_vm(__unused int argc, __unused char **argv) /* Create output string consisting of VM name and VM id */ snprintf(temp_str, MAX_STR_SIZE, - "vm_%-24d %-16d %-8s\r\n", vm->attr.id, - vm->attr.id, state); + "vm_%-24d %-16d %-8s\r\n", vm->vm_id, + vm->vm_id, state); /* Output information for this task */ shell_puts(temp_str); @@ -562,7 +562,7 @@ int shell_list_vcpu(__unused int argc, __unused char **argv) */ snprintf(temp_str, MAX_STR_SIZE, " %-9d %-10d %-7hu %-12s %-16s\r\n", - vm->attr.id, + vm->vm_id, vcpu->pcpu_id, vcpu->vcpu_id, is_vcpu_bsp(vcpu) ? @@ -627,7 +627,7 @@ int shell_vcpu_dumpreg(int argc, char **argv) snprintf(temp_str, MAX_STR_SIZE, "= VM ID %d ==== CPU ID %hu========================\r\n", - vm->attr.id, vcpu->vcpu_id); + vm->vm_id, vcpu->vcpu_id); shell_puts(temp_str); snprintf(temp_str, MAX_STR_SIZE, "= RIP=0x%016llx RSP=0x%016llx " "RFLAGS=0x%016llx\r\n", cur_context->rip, diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 43e2307d5..35dcec3f6 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -18,10 +18,7 @@ enum vm_privilege_level { }; #define MAX_VM_NAME_LEN 16 -struct vm_attr { - uint16_t id; /* Virtual machine identifier */ - uint16_t boot_idx; /* Index indicating the boot sequence for this VM */ -}; +#define INVALID_VM_ID 0xffffU struct vm_hw_info { uint16_t num_vcpus; /* Number of total virtual cores */ @@ -129,7 +126,7 @@ struct vcpuid_entry { struct acrn_vpic; struct vm { - struct vm_attr attr; /* Reference to this VM's attributes */ + uint16_t vm_id; /* Virtual machine identifier */ struct vm_hw_info hw; /* Reference to this VM's HW information */ struct vm_sw_info sw; /* Reference to SW associated with this VM */ struct vm_pm_info pm; /* Reference to this VM's arch information */