[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220311055056.57265-28-seanjc@google.com>
Date: Fri, 11 Mar 2022 05:49:38 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: Sean Christopherson <seanjc@...gle.com>
Subject: [RFC PATCH 027/105] KVM: selftests: Add vm_create_*() variants to
expose/return 'struct vcpu'
Signed-off-by: Sean Christopherson <seanjc@...gle.com>
---
.../selftests/kvm/include/kvm_util_base.h | 17 +++++++++++++++++
tools/testing/selftests/kvm/lib/kvm_util.c | 18 ++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
index 21020d6a4f01..e87988665607 100644
--- a/tools/testing/selftests/kvm/include/kvm_util_base.h
+++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
@@ -619,6 +619,23 @@ struct kvm_vm *vm_create_with_vcpus(enum vm_guest_mode mode, uint32_t nr_vcpus,
uint32_t num_percpu_pages, void *guest_code,
uint32_t vcpuids[]);
+
+/*
+ * 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)
*
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index ed7e2c5b0062..0c088454e600 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -365,6 +365,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
*
@@ -399,6 +409,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
*
--
2.35.1.723.g4982287a31-goog
Powered by blists - more mailing lists