mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-07 03:04:49 +00:00
hv: Remove vm_list
Loop the global vm_array[] instead of the vm_list. Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
b8e59e1638
commit
eff2ac7a90
@ -11,24 +11,11 @@
|
|||||||
|
|
||||||
/* Local variables */
|
/* Local variables */
|
||||||
|
|
||||||
/* VMs list */
|
|
||||||
struct list_head vm_list = {
|
|
||||||
.next = &vm_list,
|
|
||||||
.prev = &vm_list,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Lock for VMs list */
|
|
||||||
spinlock_t vm_list_lock = {
|
|
||||||
.head = 0U,
|
|
||||||
.tail = 0U
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct vm vm_array[CONFIG_MAX_VM_NUM] __aligned(CPU_PAGE_SIZE);
|
static struct vm vm_array[CONFIG_MAX_VM_NUM] __aligned(CPU_PAGE_SIZE);
|
||||||
|
|
||||||
#ifndef CONFIG_PARTITION_MODE
|
|
||||||
/* used for vmid allocation. And this means the max vm number is 64 */
|
|
||||||
static uint64_t vmid_bitmap;
|
static uint64_t vmid_bitmap;
|
||||||
|
|
||||||
|
/* used for vmid allocation. And this means the max vm number is 64 */
|
||||||
static inline uint16_t alloc_vm_id(void)
|
static inline uint16_t alloc_vm_id(void)
|
||||||
{
|
{
|
||||||
uint16_t id = ffz64(vmid_bitmap);
|
uint16_t id = ffz64(vmid_bitmap);
|
||||||
@ -47,7 +34,11 @@ static inline void free_vm_id(struct vm *vm)
|
|||||||
{
|
{
|
||||||
bitmap_clear_lock(vm->vm_id, &vmid_bitmap);
|
bitmap_clear_lock(vm->vm_id, &vmid_bitmap);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
static inline bool is_vm_valid(uint16_t vm_id)
|
||||||
|
{
|
||||||
|
return bitmap_test(vm_id, &vmid_bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
static void init_vm(struct vm_description *vm_desc,
|
static void init_vm(struct vm_description *vm_desc,
|
||||||
struct vm *vm_handle)
|
struct vm *vm_handle)
|
||||||
@ -75,20 +66,11 @@ static void init_vm(struct vm_description *vm_desc,
|
|||||||
*/
|
*/
|
||||||
struct vm *get_vm_from_vmid(uint16_t vm_id)
|
struct vm *get_vm_from_vmid(uint16_t vm_id)
|
||||||
{
|
{
|
||||||
struct vm *vm = NULL;
|
if (is_vm_valid(vm_id)) {
|
||||||
struct list_head *pos;
|
return &vm_array[vm_id];
|
||||||
|
} else {
|
||||||
spinlock_obtain(&vm_list_lock);
|
|
||||||
list_for_each(pos, &vm_list) {
|
|
||||||
vm = list_entry(pos, struct vm, list);
|
|
||||||
if (vm->vm_id == vm_id) {
|
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +84,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
|||||||
|
|
||||||
#ifdef CONFIG_PARTITION_MODE
|
#ifdef CONFIG_PARTITION_MODE
|
||||||
vm_id = vm_desc->vm_id;
|
vm_id = vm_desc->vm_id;
|
||||||
|
bitmap_set_lock(vm_id, &vmid_bitmap);
|
||||||
#else
|
#else
|
||||||
vm_id = alloc_vm_id();
|
vm_id = alloc_vm_id();
|
||||||
#endif
|
#endif
|
||||||
@ -176,11 +159,6 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_LIST_HEAD(&vm->list);
|
|
||||||
spinlock_obtain(&vm_list_lock);
|
|
||||||
list_add(&vm->list, &vm_list);
|
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
|
|
||||||
INIT_LIST_HEAD(&vm->softirq_dev_entry_list);
|
INIT_LIST_HEAD(&vm->softirq_dev_entry_list);
|
||||||
spinlock_init(&vm->softirq_dev_lock);
|
spinlock_init(&vm->softirq_dev_lock);
|
||||||
vm->intr_inject_delay_delta = 0UL;
|
vm->intr_inject_delay_delta = 0UL;
|
||||||
@ -270,10 +248,6 @@ int shutdown_vm(struct vm *vm)
|
|||||||
destroy_vcpu(vcpu);
|
destroy_vcpu(vcpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_obtain(&vm_list_lock);
|
|
||||||
list_del_init(&vm->list);
|
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
|
|
||||||
ptdev_release_all_entries(vm);
|
ptdev_release_all_entries(vm);
|
||||||
|
|
||||||
/* cleanup vioapic */
|
/* cleanup vioapic */
|
||||||
|
@ -525,17 +525,18 @@ static int shell_cmd_help(__unused int argc, __unused char **argv)
|
|||||||
static int shell_list_vm(__unused int argc, __unused char **argv)
|
static int shell_list_vm(__unused int argc, __unused char **argv)
|
||||||
{
|
{
|
||||||
char temp_str[MAX_STR_SIZE];
|
char temp_str[MAX_STR_SIZE];
|
||||||
struct list_head *pos;
|
|
||||||
struct vm *vm;
|
struct vm *vm;
|
||||||
|
uint16_t idx;
|
||||||
|
char state[32];
|
||||||
|
|
||||||
shell_puts("\r\nVM NAME VM ID VM STATE"
|
shell_puts("\r\nVM NAME VM ID VM STATE"
|
||||||
"\r\n======= ===== ========\r\n");
|
"\r\n======= ===== ========\r\n");
|
||||||
|
|
||||||
spinlock_obtain(&vm_list_lock);
|
for (idx = 0; idx < CONFIG_MAX_VM_NUM; idx++) {
|
||||||
list_for_each(pos, &vm_list) {
|
vm = get_vm_from_vmid(idx);
|
||||||
char state[32];
|
if (vm == NULL) {
|
||||||
|
continue;
|
||||||
vm = list_entry(pos, struct vm, list);
|
}
|
||||||
switch (vm->state) {
|
switch (vm->state) {
|
||||||
case VM_CREATED:
|
case VM_CREATED:
|
||||||
(void)strcpy_s(state, 32, "Created");
|
(void)strcpy_s(state, 32, "Created");
|
||||||
@ -559,7 +560,6 @@ static int shell_list_vm(__unused int argc, __unused char **argv)
|
|||||||
/* Output information for this task */
|
/* Output information for this task */
|
||||||
shell_puts(temp_str);
|
shell_puts(temp_str);
|
||||||
}
|
}
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -567,19 +567,20 @@ static int shell_list_vm(__unused int argc, __unused char **argv)
|
|||||||
static int shell_list_vcpu(__unused int argc, __unused char **argv)
|
static int shell_list_vcpu(__unused int argc, __unused char **argv)
|
||||||
{
|
{
|
||||||
char temp_str[MAX_STR_SIZE];
|
char temp_str[MAX_STR_SIZE];
|
||||||
struct list_head *pos;
|
|
||||||
struct vm *vm;
|
struct vm *vm;
|
||||||
struct vcpu *vcpu;
|
struct vcpu *vcpu;
|
||||||
|
char state[32];
|
||||||
|
uint16_t i;
|
||||||
|
uint16_t idx;
|
||||||
|
|
||||||
shell_puts("\r\nVM ID PCPU ID VCPU ID VCPU ROLE VCPU STATE"
|
shell_puts("\r\nVM ID PCPU ID VCPU ID VCPU ROLE VCPU STATE"
|
||||||
"\r\n===== ======= ======= ========= ==========\r\n");
|
"\r\n===== ======= ======= ========= ==========\r\n");
|
||||||
|
|
||||||
spinlock_obtain(&vm_list_lock);
|
for (idx = 0; idx < CONFIG_MAX_VM_NUM; idx++) {
|
||||||
list_for_each(pos, &vm_list) {
|
vm = get_vm_from_vmid(idx);
|
||||||
char state[32];
|
if (vm == NULL) {
|
||||||
uint16_t i;
|
continue;
|
||||||
|
}
|
||||||
vm = list_entry(pos, struct vm, list);
|
|
||||||
foreach_vcpu(i, vm, vcpu) {
|
foreach_vcpu(i, vm, vcpu) {
|
||||||
switch (vcpu->state) {
|
switch (vcpu->state) {
|
||||||
case VCPU_INIT:
|
case VCPU_INIT:
|
||||||
@ -612,7 +613,6 @@ static int shell_list_vcpu(__unused int argc, __unused char **argv)
|
|||||||
shell_puts(temp_str);
|
shell_puts(temp_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spinlock_release(&vm_list_lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,6 @@ struct vm {
|
|||||||
struct acrn_vuart vuart; /* Virtual UART */
|
struct acrn_vuart vuart; /* Virtual UART */
|
||||||
enum vpic_wire_mode wire_mode;
|
enum vpic_wire_mode wire_mode;
|
||||||
struct iommu_domain *iommu; /* iommu domain of this VM */
|
struct iommu_domain *iommu; /* iommu domain of this VM */
|
||||||
struct list_head list; /* list of VM */
|
|
||||||
spinlock_t spinlock; /* Spin-lock used to protect VM modifications */
|
spinlock_t spinlock; /* Spin-lock used to protect VM modifications */
|
||||||
|
|
||||||
struct list_head mmio_list; /* list for mmio. This list is not updated
|
struct list_head mmio_list; /* list for mmio. This list is not updated
|
||||||
@ -279,9 +278,6 @@ const struct vm_description_array *get_vm_desc_base(void);
|
|||||||
|
|
||||||
struct vm *get_vm_from_vmid(uint16_t vm_id);
|
struct vm *get_vm_from_vmid(uint16_t vm_id);
|
||||||
|
|
||||||
extern struct list_head vm_list;
|
|
||||||
extern spinlock_t vm_list_lock;
|
|
||||||
|
|
||||||
#ifdef CONFIG_PARTITION_MODE
|
#ifdef CONFIG_PARTITION_MODE
|
||||||
struct vm_description_array {
|
struct vm_description_array {
|
||||||
int num_vm_desc;
|
int num_vm_desc;
|
||||||
|
Loading…
Reference in New Issue
Block a user