Skip to content

Commit 9d70f3f

Browse files
committed
Revert "KVM: VMX: Always honor guest PAT on CPUs that support self-snoop"
This reverts commit 377b2f3. This caused a regression with the bochsdrm driver, which used ioremap() instead of ioremap_wc() to map the video RAM. After the commit, the WB memory type is used without the IGNORE_PAT, resulting in the slower UC memory type. In fact, UC is slow enough to basically cause guests to not boot... but only on new processors such as Sapphire Rapids and Cascade Lake. Coffee Lake for example works properly, though that might also be an effect of being on a larger, more NUMA system. The driver has been fixed but that does not help older guests. Until we figure out whether Cascade Lake and newer processors are working as intended, revert the commit. Long term we might add a quirk, but the details depend on whether the processors are working as intended: for example if they are, the quirk might reference bochs-compatible devices, e.g. in the name and documentation, so that userspace can disable the quirk by default and only leave it enabled if such a device is being exposed to the guest. If instead this is actually a bug in CLX+, then the actions we need to take are different and depend on the actual cause of the bug. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 59cbd4e commit 9d70f3f

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,16 +4674,14 @@ static int kvm_tdp_mmu_page_fault(struct kvm_vcpu *vcpu,
46744674
bool kvm_mmu_may_ignore_guest_pat(void)
46754675
{
46764676
/*
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
4677+
* When EPT is enabled (shadow_memtype_mask is non-zero), and the VM
46794678
* has non-coherent DMA (DMA doesn't snoop CPU caches), KVM's ABI is to
46804679
* honor the memtype from the guest's PAT so that guest accesses to
46814680
* memory that is DMA'd aren't cached against the guest's wishes. As a
46824681
* 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.
4682+
* KVM _always_ ignores guest PAT (when EPT is enabled).
46854683
*/
4686-
return !static_cpu_has(X86_FEATURE_SELFSNOOP) && shadow_memtype_mask;
4684+
return shadow_memtype_mask;
46874685
}
46884686

46894687
int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)

arch/x86/kvm/vmx/vmx.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7659,13 +7659,11 @@ u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
76597659

76607660
/*
76617661
* Force WB and ignore guest PAT if the VM does NOT have a non-coherent
7662-
* device attached and the CPU doesn't support self-snoop. Letting the
7663-
* guest control memory types on Intel CPUs without self-snoop may
7664-
* result in unexpected behavior, and so KVM's (historical) ABI is to
7665-
* trust the guest to behave only as a last resort.
7662+
* device attached. Letting the guest control memory types on Intel
7663+
* CPUs may result in unexpected behavior, and so KVM's ABI is to trust
7664+
* the guest to behave only as a last resort.
76667665
*/
7667-
if (!static_cpu_has(X86_FEATURE_SELFSNOOP) &&
7668-
!kvm_arch_has_noncoherent_dma(vcpu->kvm))
7666+
if (!kvm_arch_has_noncoherent_dma(vcpu->kvm))
76697667
return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT;
76707668

76717669
return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT);

0 commit comments

Comments
 (0)