summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2024-04-23 09:53:28 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2024-05-07 13:07:35 -0400
commit40269c03fdbff2171af246795a4c639cb0cf1ed5 (patch)
treedb270e67bb76d1666a68498dcfa6e9e21a173307
parent555485bd86e344b20f3a6582fdbeeab207d08757 (diff)
downloadlinux-stable-40269c03fdbff2171af246795a4c639cb0cf1ed5.tar.gz
linux-stable-40269c03fdbff2171af246795a4c639cb0cf1ed5.tar.bz2
linux-stable-40269c03fdbff2171af246795a4c639cb0cf1ed5.zip
KVM: x86: Explicitly zero kvm_caps during vendor module load
Zero out all of kvm_caps when loading a new vendor module to ensure that KVM can't inadvertently rely on global initialization of a field, and add a comment above the definition of kvm_caps to call out that all fields needs to be explicitly computed during vendor module load. Signed-off-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Message-ID: <20240423165328.2853870-4-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 44ce187bad89..8f3979d5fc80 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -92,6 +92,11 @@
#define MAX_IO_MSRS 256
#define KVM_MAX_MCE_BANKS 32
+/*
+ * Note, kvm_caps fields should *never* have default values, all fields must be
+ * recomputed from scratch during vendor module load, e.g. to account for a
+ * vendor module being reloaded with different module parameters.
+ */
struct kvm_caps kvm_caps __read_mostly;
EXPORT_SYMBOL_GPL(kvm_caps);
@@ -9755,6 +9760,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
return -EIO;
}
+ memset(&kvm_caps, 0, sizeof(kvm_caps));
+
x86_emulator_cache = kvm_alloc_emulator_cache();
if (!x86_emulator_cache) {
pr_err("failed to allocate cache for x86 emulator\n");