Skip to content

Commit 40269c0

Browse files
sean-jcbonzini
authored andcommitted
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 <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 555485b commit 40269c0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kvm/x86.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
#define MAX_IO_MSRS 256
9393
#define KVM_MAX_MCE_BANKS 32
9494

95+
/*
96+
* Note, kvm_caps fields should *never* have default values, all fields must be
97+
* recomputed from scratch during vendor module load, e.g. to account for a
98+
* vendor module being reloaded with different module parameters.
99+
*/
95100
struct kvm_caps kvm_caps __read_mostly;
96101
EXPORT_SYMBOL_GPL(kvm_caps);
97102

@@ -9755,6 +9760,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
97559760
return -EIO;
97569761
}
97579762

9763+
memset(&kvm_caps, 0, sizeof(kvm_caps));
9764+
97589765
x86_emulator_cache = kvm_alloc_emulator_cache();
97599766
if (!x86_emulator_cache) {
97609767
pr_err("failed to allocate cache for x86 emulator\n");

0 commit comments

Comments
 (0)