summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunaid Shahid2018-05-04 20:37:13 +0200
committerPaolo Bonzini2018-05-11 11:21:12 +0200
commitc19986fea873f3c745122bf79013a872a190f212 (patch)
tree3d2dd64d5a9cd0d5ef154be7cce2ca944597a8c4
parentKVM: selftests: exit with 0 status code when tests cannot be run (diff)
downloadkernel-qcow2-linux-c19986fea873f3c745122bf79013a872a190f212.tar.gz
kernel-qcow2-linux-c19986fea873f3c745122bf79013a872a190f212.tar.xz
kernel-qcow2-linux-c19986fea873f3c745122bf79013a872a190f212.zip
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 <junaids@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 44bd4a23b59c..37dd9a9d050a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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)) {