]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Add vm_create_*() variants to expose/return 'struct vcpu'
authorSean Christopherson <seanjc@google.com>
Tue, 15 Feb 2022 23:14:51 +0000 (15:14 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 11 Jun 2022 15:46:29 +0000 (11:46 -0400)
Add VM creation helpers to expose/return 'struct vcpu' so that tests
don't have to hardcode a VCPU_ID or make assumptions about what vCPU ID
is used by the framework just to retrieve a vCPU the test created.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/kvm_util_base.h
tools/testing/selftests/kvm/lib/kvm_util.c

index edbbbbe4cd5d5ab1e8b2bf3bd2a160004004bdae..c46c037500435478855a60fd718f0b790c8afb7d 100644 (file)
@@ -628,6 +628,22 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
 /* Create a default VM without any vcpus. */
 struct kvm_vm *vm_create_without_vcpus(enum vm_guest_mode mode, uint64_t pages);
 
+/*
+ * Create a VM with a single vCPU with reasonable defaults and @extra_mem_pages
+ * additional pages of guest memory.  Returns the VM and vCPU (via out param).
+ */
+struct kvm_vm *__vm_create_with_one_vcpu(struct vcpu **vcpu,
+                                        uint64_t extra_mem_pages,
+                                        void *guest_code);
+
+static inline struct kvm_vm *vm_create_with_one_vcpu(struct vcpu **vcpu,
+                                                    void *guest_code)
+{
+       return __vm_create_with_one_vcpu(vcpu, 0, guest_code);
+}
+
+struct vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm);
+
 /*
  * Adds a vCPU with reasonable defaults (e.g. a stack)
  *
index 8f670cef6faa1fa92ed0381ac78dc278b61dfd9a..1c5caf2ddca47afa3a2e4879ebea5d4e8bd69711 100644 (file)
@@ -369,6 +369,16 @@ struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages,
                                            (uint32_t []){ vcpuid });
 }
 
+struct kvm_vm *__vm_create_with_one_vcpu(struct vcpu **vcpu,
+                                        uint64_t extra_mem_pages,
+                                        void *guest_code)
+{
+       struct kvm_vm *vm = vm_create_default(0, extra_mem_pages, guest_code);
+
+       *vcpu = vcpu_get(vm, 0);
+       return vm;
+}
+
 /*
  * VM Restart
  *
@@ -403,6 +413,14 @@ void kvm_vm_restart(struct kvm_vm *vmp)
        }
 }
 
+struct vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm)
+{
+       kvm_vm_restart(vm);
+
+       vm_vcpu_add(vm, 0);
+       return vcpu_get(vm, 0);
+}
+
 /*
  * Userspace Memory Region Find
  *