Skip to content

Commit f305a01

Browse files
author
Maxim Levitsky
committed
KVM: x86: remove shadow_memtype_mask
JIRA: https://issues.redhat.com/browse/RHEL-47242 commit 3fee483 Author: Paolo Bonzini <pbonzini@redhat.com> Date: Mon Mar 3 11:31:50 2025 -0500 KVM: x86: remove shadow_memtype_mask The IGNORE_GUEST_PAT quirk is inapplicable, and thus always-disabled, if shadow_memtype_mask is zero. As long as vmx_get_mt_mask is not called for the shadow paging case, there is no need to consult shadow_memtype_mask and it can be removed altogether. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
1 parent 8f032ec commit f305a01

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,21 +4836,6 @@ static int kvm_tdp_mmu_page_fault(struct kvm_vcpu *vcpu,
48364836
}
48374837
#endif
48384838

4839-
bool kvm_mmu_may_ignore_guest_pat(struct kvm *kvm)
4840-
{
4841-
/*
4842-
* When EPT is enabled (shadow_memtype_mask is non-zero), and the VM
4843-
* has non-coherent DMA (DMA doesn't snoop CPU caches), KVM's ABI is to
4844-
* honor the memtype from the guest's PAT so that guest accesses to
4845-
* memory that is DMA'd aren't cached against the guest's wishes. As a
4846-
* result, KVM _may_ ignore guest PAT, whereas without non-coherent DMA.
4847-
* KVM _always_ ignores guest PAT, when EPT is enabled and when quirk
4848-
* KVM_X86_QUIRK_IGNORE_GUEST_PAT is enabled or the CPU lacks the
4849-
* ability to safely honor guest PAT.
4850-
*/
4851-
return kvm_check_has_quirk(kvm, KVM_X86_QUIRK_IGNORE_GUEST_PAT);
4852-
}
4853-
48544839
int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
48554840
{
48564841
#ifdef CONFIG_X86_64

arch/x86/kvm/mmu/spte.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ u64 __read_mostly shadow_mmio_value;
3737
u64 __read_mostly shadow_mmio_mask;
3838
u64 __read_mostly shadow_mmio_access_mask;
3939
u64 __read_mostly shadow_present_mask;
40-
u64 __read_mostly shadow_memtype_mask;
4140
u64 __read_mostly shadow_me_value;
4241
u64 __read_mostly shadow_me_mask;
4342
u64 __read_mostly shadow_acc_track_mask;
@@ -210,9 +209,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
210209
if (level > PG_LEVEL_4K)
211210
spte |= PT_PAGE_SIZE_MASK;
212211

213-
if (shadow_memtype_mask)
214-
spte |= kvm_x86_call(get_mt_mask)(vcpu, gfn,
215-
kvm_is_mmio_pfn(pfn));
212+
spte |= kvm_x86_call(get_mt_mask)(vcpu, gfn, kvm_is_mmio_pfn(pfn));
216213
if (host_writable)
217214
spte |= shadow_host_writable_mask;
218215
else
@@ -467,13 +464,7 @@ void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only)
467464
/* VMX_EPT_SUPPRESS_VE_BIT is needed for W or X violation. */
468465
shadow_present_mask =
469466
(has_exec_only ? 0ull : VMX_EPT_READABLE_MASK) | VMX_EPT_SUPPRESS_VE_BIT;
470-
/*
471-
* EPT overrides the host MTRRs, and so KVM must program the desired
472-
* memtype directly into the SPTEs. Note, this mask is just the mask
473-
* of all bits that factor into the memtype, the actual memtype must be
474-
* dynamically calculated, e.g. to ensure host MMIO is mapped UC.
475-
*/
476-
shadow_memtype_mask = VMX_EPT_MT_MASK | VMX_EPT_IPAT_BIT;
467+
477468
shadow_acc_track_mask = VMX_EPT_RWX_MASK;
478469
shadow_host_writable_mask = EPT_SPTE_HOST_WRITABLE;
479470
shadow_mmu_writable_mask = EPT_SPTE_MMU_WRITABLE;
@@ -525,12 +516,6 @@ void kvm_mmu_reset_all_pte_masks(void)
525516
shadow_x_mask = 0;
526517
shadow_present_mask = PT_PRESENT_MASK;
527518

528-
/*
529-
* For shadow paging and NPT, KVM uses PAT entry '0' to encode WB
530-
* memtype in the SPTEs, i.e. relies on host MTRRs to provide the
531-
* correct memtype (WB is the "weakest" memtype).
532-
*/
533-
shadow_memtype_mask = 0;
534519
shadow_acc_track_mask = 0;
535520
shadow_me_mask = 0;
536521
shadow_me_value = 0;

arch/x86/kvm/mmu/spte.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ extern u64 __read_mostly shadow_mmio_value;
187187
extern u64 __read_mostly shadow_mmio_mask;
188188
extern u64 __read_mostly shadow_mmio_access_mask;
189189
extern u64 __read_mostly shadow_present_mask;
190-
extern u64 __read_mostly shadow_memtype_mask;
191190
extern u64 __read_mostly shadow_me_value;
192191
extern u64 __read_mostly shadow_me_mask;
193192

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8527,6 +8527,8 @@ __init int vmx_hardware_setup(void)
85278527
if (enable_ept)
85288528
kvm_mmu_set_ept_masks(enable_ept_ad_bits,
85298529
cpu_has_vmx_ept_execute_only());
8530+
else
8531+
vt_x86_ops.get_mt_mask = NULL;
85308532

85318533
/*
85328534
* Setup shadow_me_value/shadow_me_mask to include MKTME KeyID

arch/x86/kvm/x86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13566,8 +13566,10 @@ static void kvm_noncoherent_dma_assignment_start_or_stop(struct kvm *kvm)
1356613566
* due to toggling the "ignore PAT" bit. Zap all SPTEs when the first
1356713567
* (or last) non-coherent device is (un)registered to so that new SPTEs
1356813568
* with the correct "ignore guest PAT" setting are created.
13569+
*
13570+
* If KVM always honors guest PAT, however, there is nothing to do.
1356913571
*/
13570-
if (kvm_mmu_may_ignore_guest_pat(kvm))
13572+
if (kvm_check_has_quirk(kvm, KVM_X86_QUIRK_IGNORE_GUEST_PAT))
1357113573
kvm_zap_gfn_range(kvm, gpa_to_gfn(0), gpa_to_gfn(~0ULL));
1357213574
}
1357313575

0 commit comments

Comments
 (0)