]> www.infradead.org Git - users/hch/block.git/commitdiff
selftests: kvm: split "launch" phase of SEV VM creation
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 4 Apr 2024 12:13:26 +0000 (08:13 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 11 Apr 2024 17:08:27 +0000 (13:08 -0400)
Allow the caller to set the initial state of the VM.  Doing this
before sev_vm_launch() matters for SEV-ES, since that is the
place where the VMSA is updated and after which the guest state
becomes sealed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20240404121327.3107131-17-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/x86_64/sev.h
tools/testing/selftests/kvm/lib/x86_64/sev.c
tools/testing/selftests/kvm/x86_64/sev_smoke_test.c

index 0719f083351ad8a1b99cf48364ee02082f63bedf..82c11c81a956323d54ea1b27d8b88dbc5eb6db6e 100644 (file)
@@ -31,8 +31,9 @@ void sev_vm_launch(struct kvm_vm *vm, uint32_t policy);
 void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement);
 void sev_vm_launch_finish(struct kvm_vm *vm);
 
-struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
+struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code,
                                           struct kvm_vcpu **cpu);
+void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement);
 
 kvm_static_assert(SEV_RET_SUCCESS == 0);
 
index 597994fa4f416b7da20b7d6f40d26e49f495f9e5..d482029b60040067cdbe489022f789a560e554dd 100644 (file)
@@ -113,26 +113,30 @@ void sev_vm_launch_finish(struct kvm_vm *vm)
        TEST_ASSERT_EQ(status.state, SEV_GUEST_STATE_RUNNING);
 }
 
-struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
+struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code,
                                           struct kvm_vcpu **cpu)
 {
        struct vm_shape shape = {
                .mode = VM_MODE_DEFAULT,
-               .type = policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM,
+               .type = type,
        };
        struct kvm_vm *vm;
        struct kvm_vcpu *cpus[1];
-       uint8_t measurement[512];
 
        vm = __vm_create_with_vcpus(shape, 1, 0, guest_code, cpus);
        *cpu = cpus[0];
 
+       return vm;
+}
+
+void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement)
+{
        sev_vm_launch(vm, policy);
 
-       /* TODO: Validate the measurement is as expected. */
+       if (!measurement)
+               measurement = alloca(256);
+
        sev_vm_launch_measure(vm, measurement);
 
        sev_vm_launch_finish(vm);
-
-       return vm;
 }
index 026779f3ed06dec85838bfbaa2d3bf8730169418..234c80dd344df9d1d354cae8c17ac04ed6989aa8 100644 (file)
@@ -41,7 +41,12 @@ static void test_sev(void *guest_code, uint64_t policy)
        struct kvm_vm *vm;
        struct ucall uc;
 
-       vm = vm_sev_create_with_one_vcpu(policy, guest_code, &vcpu);
+       uint32_t type = policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM;
+
+       vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu);
+
+       /* TODO: Validate the measurement is as expected. */
+       vm_sev_launch(vm, policy, NULL);
 
        for (;;) {
                vcpu_run(vcpu);