KVM: x86: Fully re-initialize supported_vm_types on vendor module load
authorSean Christopherson <seanjc@google.com>
Tue, 23 Apr 2024 16:53:26 +0000 (09:53 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 May 2024 17:07:34 +0000 (13:07 -0400)
Recompute the entire set of supported VM types when a vendor module is
loaded, as preserving supported_vm_types across vendor module unload and
reload can result in VM types being incorrectly treated as supported.

E.g. if a vendor module is loaded with TDP enabled, unloaded, and then
reloaded with TDP disabled, KVM_X86_SW_PROTECTED_VM will be incorrectly
retained.  Ditto for SEV_VM and SEV_ES_VM and their respective module
params in kvm-amd.ko.

Fixes: 2a955c4db1dd ("KVM: x86: Add supported_vm_types to kvm_caps")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Message-ID: <20240423165328.2853870-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 2d2619d3eee47349d6aa34cc5a16f7ccefe3adee..a65a1012d8781e0f3bee3807ed9e1ed17741a284 100644 (file)
@@ -94,7 +94,6 @@
 
 struct kvm_caps kvm_caps __read_mostly = {
        .supported_mce_cap = MCG_CTL_P | MCG_SER_P,
-       .supported_vm_types = BIT(KVM_X86_DEFAULT_VM),
 };
 EXPORT_SYMBOL_GPL(kvm_caps);
 
@@ -9776,6 +9775,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
        if (r)
                goto out_free_percpu;
 
+       kvm_caps.supported_vm_types = BIT(KVM_X86_DEFAULT_VM);
+
        if (boot_cpu_has(X86_FEATURE_XSAVE)) {
                host_xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);
                kvm_caps.supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0;