KVM: SVM: Invert handling of SEV and SEV_ES feature flags
authorSean Christopherson <seanjc@google.com>
Thu, 4 Apr 2024 12:13:11 +0000 (08:13 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 11 Apr 2024 17:08:21 +0000 (13:08 -0400)
Leave SEV and SEV_ES '0' in kvm_cpu_caps by default, and instead set them
in sev_set_cpu_caps() if SEV and SEV-ES support are fully enabled.  Aside
from the fact that sev_set_cpu_caps() is wildly misleading when it *clears*
capabilities, this will allow compiling out sev.c without falsely
advertising SEV/SEV-ES support in KVM_GET_SUPPORTED_CPUID.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20240404121327.3107131-2-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/cpuid.c
arch/x86/kvm/svm/sev.c

index bfc0bfcb2bc60dd2860fa4617f3dc92dea1f3a97..51bd2197feed1c928b16d30845317b47cd158a86 100644 (file)
@@ -771,7 +771,7 @@ void kvm_set_cpu_caps(void)
        kvm_cpu_cap_mask(CPUID_8000_000A_EDX, 0);
 
        kvm_cpu_cap_mask(CPUID_8000_001F_EAX,
-               0 /* SME */ | F(SEV) | 0 /* VM_PAGE_FLUSH */ | F(SEV_ES) |
+               0 /* SME */ | 0 /* SEV */ | 0 /* VM_PAGE_FLUSH */ | 0 /* SEV_ES */ |
                F(SME_COHERENT));
 
        kvm_cpu_cap_mask(CPUID_8000_0021_EAX,
index e5a4d9b0e79fd23e2dfc8224aa7a89d3b243c103..382c745b8ba9b225be0d367310d65ea7e5d6fcb4 100644 (file)
@@ -2186,10 +2186,10 @@ void sev_vm_destroy(struct kvm *kvm)
 
 void __init sev_set_cpu_caps(void)
 {
-       if (!sev_enabled)
-               kvm_cpu_cap_clear(X86_FEATURE_SEV);
-       if (!sev_es_enabled)
-               kvm_cpu_cap_clear(X86_FEATURE_SEV_ES);
+       if (sev_enabled)
+               kvm_cpu_cap_set(X86_FEATURE_SEV);
+       if (sev_es_enabled)
+               kvm_cpu_cap_set(X86_FEATURE_SEV_ES);
 }
 
 void __init sev_hardware_setup(void)