diff options
author | Junaid Shahid <junaids@google.com> | 2018-06-27 14:59:13 -0700 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-08-06 17:58:56 +0200 |
commit | c9470a2e28479e97eb44d926ea7bbb5709ad9d6b (patch) | |
tree | 482d62fb205c50c77ddfe5603f2a6abcd2dc5e8b | |
parent | afe828d1de4047d26eb0cd0c0154f5ac3722bf63 (diff) | |
download | linux-c9470a2e28479e97eb44d926ea7bbb5709ad9d6b.tar.gz linux-c9470a2e28479e97eb44d926ea7bbb5709ad9d6b.tar.bz2 linux-c9470a2e28479e97eb44d926ea7bbb5709ad9d6b.zip |
kvm: x86: Propagate guest PCIDs to host PCIDs
When using shadow paging mode, propagate the guest's PCID value to
the shadow CR3 in the host instead of always using PCID 0.
Signed-off-by: Junaid Shahid <junaids@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | arch/x86/kvm/mmu.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 6a2a97d8015b..1fab69c0b2f3 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -86,10 +86,25 @@ static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu) return kvm_mmu_load(vcpu); } +static inline unsigned long kvm_get_pcid(struct kvm_vcpu *vcpu, gpa_t cr3) +{ + BUILD_BUG_ON((X86_CR3_PCID_MASK & PAGE_MASK) != 0); + + return kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE) + ? cr3 & X86_CR3_PCID_MASK + : 0; +} + +static inline unsigned long kvm_get_active_pcid(struct kvm_vcpu *vcpu) +{ + return kvm_get_pcid(vcpu, kvm_read_cr3(vcpu)); +} + static inline void kvm_mmu_load_cr3(struct kvm_vcpu *vcpu) { if (VALID_PAGE(vcpu->arch.mmu.root_hpa)) - vcpu->arch.mmu.set_cr3(vcpu, vcpu->arch.mmu.root_hpa); + vcpu->arch.mmu.set_cr3(vcpu, vcpu->arch.mmu.root_hpa | + kvm_get_active_pcid(vcpu)); } /* |