@@ -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 */
@@ -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;
}
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(-)