Skip to content

Commit 4c180a5

Browse files
committed
selftests: kvm: split "launch" phase of SEV VM creation
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>
1 parent d18c864 commit 4c180a5

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

tools/testing/selftests/kvm/include/x86_64/sev.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ void sev_vm_launch(struct kvm_vm *vm, uint32_t policy);
3131
void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement);
3232
void sev_vm_launch_finish(struct kvm_vm *vm);
3333

34-
struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
34+
struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code,
3535
struct kvm_vcpu **cpu);
36+
void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement);
3637

3738
kvm_static_assert(SEV_RET_SUCCESS == 0);
3839

tools/testing/selftests/kvm/lib/x86_64/sev.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,30 @@ void sev_vm_launch_finish(struct kvm_vm *vm)
113113
TEST_ASSERT_EQ(status.state, SEV_GUEST_STATE_RUNNING);
114114
}
115115

116-
struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code,
116+
struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t type, void *guest_code,
117117
struct kvm_vcpu **cpu)
118118
{
119119
struct vm_shape shape = {
120120
.mode = VM_MODE_DEFAULT,
121-
.type = policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM,
121+
.type = type,
122122
};
123123
struct kvm_vm *vm;
124124
struct kvm_vcpu *cpus[1];
125-
uint8_t measurement[512];
126125

127126
vm = __vm_create_with_vcpus(shape, 1, 0, guest_code, cpus);
128127
*cpu = cpus[0];
129128

129+
return vm;
130+
}
131+
132+
void vm_sev_launch(struct kvm_vm *vm, uint32_t policy, uint8_t *measurement)
133+
{
130134
sev_vm_launch(vm, policy);
131135

132-
/* TODO: Validate the measurement is as expected. */
136+
if (!measurement)
137+
measurement = alloca(256);
138+
133139
sev_vm_launch_measure(vm, measurement);
134140

135141
sev_vm_launch_finish(vm);
136-
137-
return vm;
138142
}

tools/testing/selftests/kvm/x86_64/sev_smoke_test.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ static void test_sev(void *guest_code, uint64_t policy)
4141
struct kvm_vm *vm;
4242
struct ucall uc;
4343

44-
vm = vm_sev_create_with_one_vcpu(policy, guest_code, &vcpu);
44+
uint32_t type = policy & SEV_POLICY_ES ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM;
45+
46+
vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu);
47+
48+
/* TODO: Validate the measurement is as expected. */
49+
vm_sev_launch(vm, policy, NULL);
4550

4651
for (;;) {
4752
vcpu_run(vcpu);

0 commit comments

Comments
 (0)