Skip to content

Commit 4a4e1e8

Browse files
pratiksampatsean-jc
authored andcommitted
KVM: selftests: Introduce SEV VM type check
In preparation for SNP, declutter the vm type check by introducing a SEV-SNP VM type check as well as a transitive set of helper functions. The SNP VM type is the subset of SEV-ES. Similarly, the SEV-ES and SNP types are subset of the SEV VM type check. Signed-off-by: Pratik R. Sampat <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: make the helpers static inlines] Signed-off-by: Sean Christopherson <[email protected]>
1 parent f694f30 commit 4a4e1e8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ enum sev_guest_state {
2727

2828
#define GHCB_MSR_TERM_REQ 0x100
2929

30+
static inline bool is_sev_snp_vm(struct kvm_vm *vm)
31+
{
32+
return vm->type == KVM_X86_SNP_VM;
33+
}
34+
35+
static inline bool is_sev_es_vm(struct kvm_vm *vm)
36+
{
37+
return is_sev_snp_vm(vm) || vm->type == KVM_X86_SEV_ES_VM;
38+
}
39+
40+
static inline bool is_sev_vm(struct kvm_vm *vm)
41+
{
42+
return is_sev_es_vm(vm) || vm->type == KVM_X86_SEV_VM;
43+
}
44+
3045
void sev_vm_launch(struct kvm_vm *vm, uint32_t policy);
3146
void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement);
3247
void sev_vm_launch_finish(struct kvm_vm *vm);

tools/testing/selftests/kvm/lib/x86/processor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm)
639639
sync_global_to_guest(vm, host_cpu_is_amd);
640640
sync_global_to_guest(vm, is_forced_emulation_enabled);
641641

642-
if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
642+
if (is_sev_vm(vm)) {
643643
struct kvm_sev_init init = { 0 };
644644

645645
vm_sev_ioctl(vm, KVM_SEV_INIT2, &init);
@@ -1156,7 +1156,7 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
11561156

11571157
void kvm_init_vm_address_properties(struct kvm_vm *vm)
11581158
{
1159-
if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
1159+
if (is_sev_vm(vm)) {
11601160
vm->arch.sev_fd = open_sev_dev_path_or_exit();
11611161
vm->arch.c_bit = BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT));
11621162
vm->gpa_tag_mask = vm->arch.c_bit;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void test_sev(void *guest_code, uint64_t policy)
124124
for (;;) {
125125
vcpu_run(vcpu);
126126

127-
if (policy & SEV_POLICY_ES) {
127+
if (is_sev_es_vm(vm)) {
128128
TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_SYSTEM_EVENT,
129129
"Wanted SYSTEM_EVENT, got %s",
130130
exit_reason_str(vcpu->run->exit_reason));

0 commit comments

Comments
 (0)