Commit 0ffc70ea authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Add VM creation helper that "returns" vCPUs

Add a VM creator that "returns" the created vCPUs by filling the provided
array.  This will allow converting multi-vCPU tests away from hardcoded
vCPU IDs.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 0750388c
...@@ -563,10 +563,19 @@ struct kvm_vm *vm_create_default_with_vcpus(uint32_t nr_vcpus, uint64_t extra_me ...@@ -563,10 +563,19 @@ struct kvm_vm *vm_create_default_with_vcpus(uint32_t nr_vcpus, uint64_t extra_me
uint32_t vcpuids[]); uint32_t vcpuids[]);
/* Like vm_create_default_with_vcpus, but accepts mode and slot0 memory as a parameter */ /* Like vm_create_default_with_vcpus, but accepts mode and slot0 memory as a parameter */
struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, struct kvm_vm *__vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
uint64_t slot0_mem_pages, uint64_t extra_mem_pages, uint64_t slot0_mem_pages, uint64_t extra_mem_pages,
uint32_t num_percpu_pages, void *guest_code, uint32_t num_percpu_pages, void *guest_code,
uint32_t vcpuids[]); uint32_t vcpuids[], struct kvm_vcpu *vcpus[]);
static inline struct kvm_vm *vm_create_with_vcpus(uint32_t nr_vcpus,
void *guest_code,
struct kvm_vcpu *vcpus[])
{
return __vm_create_with_vcpus(VM_MODE_DEFAULT, nr_vcpus,
DEFAULT_GUEST_PHY_PAGES, 0, 0,
guest_code, NULL, vcpus);
}
/* /*
* Create a VM with a single vCPU with reasonable defaults and @extra_mem_pages * Create a VM with a single vCPU with reasonable defaults and @extra_mem_pages
......
...@@ -268,8 +268,8 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg) ...@@ -268,8 +268,8 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
/* Create a VM with enough guest pages */ /* Create a VM with enough guest pages */
guest_num_pages = test_mem_size / guest_page_size; guest_num_pages = test_mem_size / guest_page_size;
vm = vm_create_with_vcpus(mode, nr_vcpus, DEFAULT_GUEST_PHY_PAGES, vm = __vm_create_with_vcpus(mode, nr_vcpus, DEFAULT_GUEST_PHY_PAGES,
guest_num_pages, 0, guest_code, NULL); guest_num_pages, 0, guest_code, NULL, NULL);
/* Align down GPA of the testing memslot */ /* Align down GPA of the testing memslot */
if (!p->phys_offset) if (!p->phys_offset)
......
...@@ -296,12 +296,13 @@ struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t nr_pages) ...@@ -296,12 +296,13 @@ struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t nr_pages)
* extra_mem_pages is only used to calculate the maximum page table size, * extra_mem_pages is only used to calculate the maximum page table size,
* no real memory allocation for non-slot0 memory in this function. * no real memory allocation for non-slot0 memory in this function.
*/ */
struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, struct kvm_vm *__vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
uint64_t slot0_mem_pages, uint64_t extra_mem_pages, uint64_t slot0_mem_pages, uint64_t extra_mem_pages,
uint32_t num_percpu_pages, void *guest_code, uint32_t num_percpu_pages, void *guest_code,
uint32_t vcpuids[]) uint32_t vcpuids[], struct kvm_vcpu *vcpus[])
{ {
uint64_t vcpu_pages, extra_pg_pages, pages; uint64_t vcpu_pages, extra_pg_pages, pages;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
int i; int i;
...@@ -328,7 +329,9 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus, ...@@ -328,7 +329,9 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
for (i = 0; i < nr_vcpus; ++i) { for (i = 0; i < nr_vcpus; ++i) {
uint32_t vcpuid = vcpuids ? vcpuids[i] : i; uint32_t vcpuid = vcpuids ? vcpuids[i] : i;
vm_vcpu_add(vm, vcpuid, guest_code); vcpu = vm_vcpu_add(vm, vcpuid, guest_code);
if (vcpus)
vcpus[i] = vcpu;
} }
return vm; return vm;
...@@ -338,8 +341,8 @@ struct kvm_vm *vm_create_default_with_vcpus(uint32_t nr_vcpus, uint64_t extra_me ...@@ -338,8 +341,8 @@ struct kvm_vm *vm_create_default_with_vcpus(uint32_t nr_vcpus, uint64_t extra_me
uint32_t num_percpu_pages, void *guest_code, uint32_t num_percpu_pages, void *guest_code,
uint32_t vcpuids[]) uint32_t vcpuids[])
{ {
return vm_create_with_vcpus(VM_MODE_DEFAULT, nr_vcpus, DEFAULT_GUEST_PHY_PAGES, return __vm_create_with_vcpus(VM_MODE_DEFAULT, nr_vcpus, DEFAULT_GUEST_PHY_PAGES,
extra_mem_pages, num_percpu_pages, guest_code, vcpuids); extra_mem_pages, num_percpu_pages, guest_code, vcpuids, NULL);
} }
struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages, struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
......
...@@ -147,8 +147,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus, ...@@ -147,8 +147,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
* The memory is also added to memslot 0, but that's a benign side * The memory is also added to memslot 0, but that's a benign side
* effect as KVM allows aliasing HVAs in meslots. * effect as KVM allows aliasing HVAs in meslots.
*/ */
vm = vm_create_with_vcpus(mode, vcpus, slot0_pages, guest_num_pages, 0, vm = __vm_create_with_vcpus(mode, vcpus, DEFAULT_GUEST_PHY_PAGES,
perf_test_guest_code, NULL); slot0_pages + guest_num_pages, 0,
perf_test_guest_code, NULL, NULL);
pta->vm = vm; pta->vm = vm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment