@@ -4671,38 +4671,23 @@ static int kvm_tdp_mmu_page_fault(struct kvm_vcpu *vcpu,
46714671}
46724672#endif
46734673
4674- bool __kvm_mmu_honors_guest_mtrrs ( bool vm_has_noncoherent_dma )
4674+ bool kvm_mmu_may_ignore_guest_pat ( void )
46754675{
46764676 /*
4677- * If host MTRRs are ignored (shadow_memtype_mask is non-zero), and the
4678- * VM has non-coherent DMA (DMA doesn't snoop CPU caches), KVM's ABI is
4679- * to honor the memtype from the guest's MTRRs so that guest accesses
4680- * to memory that is DMA'd aren't cached against the guest's wishes.
4681- *
4682- * Note, KVM may still ultimately ignore guest MTRRs for certain PFNs,
4683- * e.g. KVM will force UC memtype for host MMIO.
4677+ * When EPT is enabled (shadow_memtype_mask is non-zero), the CPU does
4678+ * not support self-snoop (or is affected by an erratum), and the VM
4679+ * has non-coherent DMA (DMA doesn't snoop CPU caches), KVM's ABI is to
4680+ * honor the memtype from the guest's PAT so that guest accesses to
4681+ * memory that is DMA'd aren't cached against the guest's wishes. As a
4682+ * result, KVM _may_ ignore guest PAT, whereas without non-coherent DMA,
4683+ * KVM _always_ ignores or honors guest PAT, i.e. doesn't toggle SPTE
4684+ * bits in response to non-coherent device (un)registration.
46844685 */
4685- return vm_has_noncoherent_dma && shadow_memtype_mask ;
4686+ return ! static_cpu_has ( X86_FEATURE_SELFSNOOP ) && shadow_memtype_mask ;
46864687}
46874688
46884689int kvm_tdp_page_fault (struct kvm_vcpu * vcpu , struct kvm_page_fault * fault )
46894690{
4690- /*
4691- * If the guest's MTRRs may be used to compute the "real" memtype,
4692- * restrict the mapping level to ensure KVM uses a consistent memtype
4693- * across the entire mapping.
4694- */
4695- if (kvm_mmu_honors_guest_mtrrs (vcpu -> kvm )) {
4696- for ( ; fault -> max_level > PG_LEVEL_4K ; -- fault -> max_level ) {
4697- int page_num = KVM_PAGES_PER_HPAGE (fault -> max_level );
4698- gfn_t base = gfn_round_for_level (fault -> gfn ,
4699- fault -> max_level );
4700-
4701- if (kvm_mtrr_check_gfn_range_consistency (vcpu , base , page_num ))
4702- break ;
4703- }
4704- }
4705-
47064691#ifdef CONFIG_X86_64
47074692 if (tdp_mmu_enabled )
47084693 return kvm_tdp_mmu_page_fault (vcpu , fault );
0 commit comments