Skip to content

Commit c19986f

Browse files
Junaid Shahidbonzini
authored andcommitted
kvm: x86: Suppress CR3_PCID_INVD bit only when PCIDs are enabled
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 <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent bcb2b94 commit c19986f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,10 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
843843
int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
844844
{
845845
#ifdef CONFIG_X86_64
846-
cr3 &= ~CR3_PCID_INVD;
846+
bool pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);
847+
848+
if (pcid_enabled)
849+
cr3 &= ~CR3_PCID_INVD;
847850
#endif
848851

849852
if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {

0 commit comments

Comments
 (0)