Skip to content

Commit

Permalink
kvm: x86: Suppress CR3_PCID_INVD bit only when PCIDs are enabled
Browse files Browse the repository at this point in the history
If the PCIDE bit is not set in CR4, then the MSb of CR3 is a reserved
bit. If the guest tries to set it, that should cause a #GP fault. So
mask out the bit only when the PCIDE bit is set.

Signed-off-by: Junaid Shahid <junaids@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Junaid Shahid authored and Paolo Bonzini committed May 11, 2018
1 parent bcb2b94 commit c19986f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,10 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
{
#ifdef CONFIG_X86_64
cr3 &= ~CR3_PCID_INVD;
bool pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);

if (pcid_enabled)
cr3 &= ~CR3_PCID_INVD;
#endif

if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
Expand Down

0 comments on commit c19986f

Please sign in to comment.