Skip to content

Commit ffced89

Browse files
committed
KVM: x86/mmu: Exempt nested EPT page tables from !USER, CR0.WP=0 logic
Exempt nested EPT shadow pages tables from the CR0.WP=0 handling of supervisor writes, as EPT doesn't have a U/S bit and isn't affected by CR0.WP (or CR4.SMEP in the exception to the exception). Opportunistically refresh the comment to explain what KVM is doing, as the only record of why KVM shoves in WRITE and drops USER is buried in years-old changelogs. Cc: Jon Kohler <jon@nutanix.com> Cc: Sergey Dyasli <sergey.dyasli@nutanix.com> Reviewed-by: Jon Kohler <jon@nutanix.com> Reviewed-by: Sergey Dyasli <sergey.dyasli@nutanix.com> Link: https://lore.kernel.org/r/20250602234851.54573-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 28224ef commit ffced89

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,12 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault
804804
if (r != RET_PF_CONTINUE)
805805
return r;
806806

807+
#if PTTYPE != PTTYPE_EPT
807808
/*
808-
* Do not change pte_access if the pfn is a mmio page, otherwise
809-
* we will cache the incorrect access into mmio spte.
809+
* Treat the guest PTE protections as writable, supervisor-only if this
810+
* is a supervisor write fault and CR0.WP=0 (supervisor accesses ignore
811+
* PTE.W if CR0.WP=0). Don't change the access type for emulated MMIO,
812+
* otherwise KVM will cache incorrect access information in the SPTE.
810813
*/
811814
if (fault->write && !(walker.pte_access & ACC_WRITE_MASK) &&
812815
!is_cr0_wp(vcpu->arch.mmu) && !fault->user && fault->slot) {
@@ -822,6 +825,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault
822825
if (is_cr4_smep(vcpu->arch.mmu))
823826
walker.pte_access &= ~ACC_EXEC_MASK;
824827
}
828+
#endif
825829

826830
r = RET_PF_RETRY;
827831
write_lock(&vcpu->kvm->mmu_lock);

0 commit comments

Comments
 (0)