diff mbox series

[V3,4/8] KVM: selftests: Split SEV VM creation logic

Message ID 20221223001352.3873203-5-vannapurve@google.com (mailing list archive)
State New
Headers show
Series KVM: selftests: SEV: selftests for fd-based private memory | expand

Commit Message

Vishal Annapurve Dec. 23, 2022, 12:13 a.m. UTC
Split SEV VM creation logic to allow additional modifications
to SEV VM configuration e.g. adding memslots.

Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
 .../selftests/kvm/include/x86_64/sev.h        |  4 ++++
 tools/testing/selftests/kvm/lib/x86_64/sev.c  | 20 ++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h
index 1148db928d0b..6bf2015fff7a 100644
--- a/tools/testing/selftests/kvm/include/x86_64/sev.h
+++ b/tools/testing/selftests/kvm/include/x86_64/sev.h
@@ -19,4 +19,8 @@  bool is_kvm_sev_supported(void);
 struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
 					   struct kvm_vcpu **cpu);
 
+struct kvm_vm *sev_vm_init_with_one_vcpu(uint32_t policy, void *guest_code,
+					   struct kvm_vcpu **cpu);
+
+void sev_vm_finalize(struct kvm_vm *vm, uint32_t policy);
 #endif /* SELFTEST_KVM_SEV_H */
diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c
index 49c62f25363e..96d3dbc2ba74 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/sev.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c
@@ -215,7 +215,7 @@  static void sev_vm_measure(struct kvm_vm *vm)
 	pr_debug("\n");
 }
 
-struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
+struct kvm_vm *sev_vm_init_with_one_vcpu(uint32_t policy, void *guest_code,
 					   struct kvm_vcpu **cpu)
 {
 	enum vm_guest_mode mode = VM_MODE_PXXV48_4K;
@@ -231,14 +231,28 @@  struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
 	*cpu = vm_vcpu_add(vm, 0, guest_code);
 	kvm_vm_elf_load(vm, program_invocation_name);
 
+	pr_info("SEV guest created, policy: 0x%x, size: %lu KB\n", policy,
+		nr_pages * vm->page_size / 1024);
+	return vm;
+}
+
+void sev_vm_finalize(struct kvm_vm *vm, uint32_t policy)
+{
 	sev_vm_launch(vm, policy);
 
 	sev_vm_measure(vm);
 
 	sev_vm_launch_finish(vm);
+}
 
-	pr_info("SEV guest created, policy: 0x%x, size: %lu KB\n", policy,
-		nr_pages * vm->page_size / 1024);
+struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
+					   struct kvm_vcpu **cpu)
+{
+	struct kvm_vm *vm;
+
+	vm = sev_vm_init_with_one_vcpu(policy, guest_code, cpu);
+
+	sev_vm_finalize(vm, policy);
 
 	return vm;
 }