]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Teach sev_*_test about revoking VM types
authorTycho Andersen <tycho@kernel.org>
Thu, 16 Apr 2026 23:23:29 +0000 (16:23 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 13 May 2026 16:55:54 +0000 (09:55 -0700)
Instead of using CPUID, use the VM type bit to determine support, since
those now reflect the correct status of support by the kernel and firmware
configurations.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
Tested-by: Tycho Andersen (AMD) <tycho@kernel.org>
Link: https://patch.msgid.link/20260416232329.3408497-8-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86/sev_init2_tests.c
tools/testing/selftests/kvm/x86/sev_migrate_tests.c
tools/testing/selftests/kvm/x86/sev_smoke_test.c

index 8eeba2327c7cd074a71fcd8605dd533af0a2ff87..8db88c355f1654525822700657b492ad025e2580 100644 (file)
@@ -136,16 +136,14 @@ int main(int argc, char *argv[])
                    kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_VM);
 
        TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_VM));
-       have_sev_es = kvm_cpu_has(X86_FEATURE_SEV_ES);
+       have_sev_es = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_ES_VM);
 
-       TEST_ASSERT(have_sev_es == !!(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_ES_VM)),
-                   "sev-es: KVM_CAP_VM_TYPES (%x) does not match cpuid (checking %x)",
-                   kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_ES_VM);
+       TEST_ASSERT(!have_sev_es || kvm_cpu_has(X86_FEATURE_SEV_ES),
+                   "sev-es: SEV_ES_VM supported without SEV_ES in CPUID");
 
-       have_snp = kvm_cpu_has(X86_FEATURE_SEV_SNP);
-       TEST_ASSERT(have_snp == !!(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM)),
-                   "sev-snp: KVM_CAP_VM_TYPES (%x) indicates SNP support (bit %d), but CPUID does not",
-                   kvm_check_cap(KVM_CAP_VM_TYPES), KVM_X86_SNP_VM);
+       have_snp = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM);
+       TEST_ASSERT(!have_snp || kvm_cpu_has(X86_FEATURE_SEV_SNP),
+                   "sev-snp: SNP_VM supported without SEV_SNP in CPUID");
 
        test_vm_types();
 
index 6b0928e69051d5087c8c5a0d6cb8629f5a88b5d2..42bc023d51937b853a3b4cde6e1e95eb80994467 100644 (file)
@@ -374,7 +374,7 @@ int main(int argc, char *argv[])
 
        TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV));
 
-       have_sev_es = kvm_cpu_has(X86_FEATURE_SEV_ES);
+       have_sev_es = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_ES_VM);
 
        if (kvm_has_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM)) {
                test_sev_migrate_from(/* es= */ false);
index 1a49ee3915864ebb1884d92ba0c6dcf8fee08025..6b2cbe2a90b7c559857f9c9b6d8fca9db79bbc2e 100644 (file)
@@ -249,10 +249,10 @@ int main(int argc, char *argv[])
 
        test_sev_smoke(guest_sev_code, KVM_X86_SEV_VM, 0);
 
-       if (kvm_cpu_has(X86_FEATURE_SEV_ES))
+       if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_ES_VM))
                test_sev_smoke(guest_sev_es_code, KVM_X86_SEV_ES_VM, SEV_POLICY_ES);
 
-       if (kvm_cpu_has(X86_FEATURE_SEV_SNP))
+       if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM))
                test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, snp_default_policy());
 
        return 0;