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:
Mingqiang Chi
2018-09-27 14:15:32 +08:00
committed by wenlingz
parent b8e59e1638
commit eff2ac7a90
3 changed files with 26 additions and 56 deletions

View File

@@ -11,24 +11,11 @@
/* 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);
#ifndef CONFIG_PARTITION_MODE
/* used for vmid allocation. And this means the max vm number is 64 */
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)
{
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);
}
#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,
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 *vm = NULL;
struct list_head *pos;
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;
}
if (is_vm_valid(vm_id)) {
return &vm_array[vm_id];
} else {
return NULL;
}
spinlock_release(&vm_list_lock);
return NULL;
}
/**
@@ -102,6 +84,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
#ifdef CONFIG_PARTITION_MODE
vm_id = vm_desc->vm_id;
bitmap_set_lock(vm_id, &vmid_bitmap);
#else
vm_id = alloc_vm_id();
#endif
@@ -176,11 +159,6 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
#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);
spinlock_init(&vm->softirq_dev_lock);
vm->intr_inject_delay_delta = 0UL;
@@ -270,10 +248,6 @@ int shutdown_vm(struct vm *vm)
destroy_vcpu(vcpu);
}
spinlock_obtain(&vm_list_lock);
list_del_init(&vm->list);
spinlock_release(&vm_list_lock);
ptdev_release_all_entries(vm);
/* cleanup vioapic */