Skip to content

Commit 7c83d09

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Mark CR4.TSD as being possibly owned by the guest
Mark CR4.TSD as being possibly owned by the guest as that is indeed the case on VMX. Without TSD being tagged as possibly owned by the guest, a targeted read of CR4 to get TSD could observe a stale value. This bug is benign in the current code base as the sole consumer of TSD is the emulator (for RDTSC) and the emulator always "reads" the entirety of CR4 when grabbing bits. Add a build-time assertion in to ensure VMX doesn't hand over more CR4 bits without also updating x86. Fixes: 52ce3c2 ("x86,kvm,vmx: Don't trap writes to CR4.TSD") Cc: [email protected] Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d74fcfc commit 7c83d09

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

arch/x86/kvm/kvm_cache_regs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS
88
#define KVM_POSSIBLE_CR4_GUEST_BITS \
99
(X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \
10-
| X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_PGE)
10+
| X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_PGE | X86_CR4_TSD)
1111

1212
#define BUILD_KVM_GPR_ACCESSORS(lname, uname) \
1313
static __always_inline unsigned long kvm_##lname##_read(struct kvm_vcpu *vcpu)\

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
40344034

40354035
void set_cr4_guest_host_mask(struct vcpu_vmx *vmx)
40364036
{
4037+
BUILD_BUG_ON(KVM_CR4_GUEST_OWNED_BITS & ~KVM_POSSIBLE_CR4_GUEST_BITS);
4038+
40374039
vmx->vcpu.arch.cr4_guest_owned_bits = KVM_CR4_GUEST_OWNED_BITS;
40384040
if (enable_ept)
40394041
vmx->vcpu.arch.cr4_guest_owned_bits |= X86_CR4_PGE;

0 commit comments

Comments
 (0)