Skip to content

Commit 5c64aba

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Drop exec/NX check from "page fault can be fast"
Tweak the "page fault can be fast" logic to explicitly check for !PRESENT faults in the access tracking case, and drop the exec/NX check that becomes redundant as a result. No sane hardware will generate an access that is both an instruct fetch and a write, i.e. it's a waste of cycles. If hardware goes off the rails, or KVM runs under a misguided hypervisor, spuriously running throught fast path is benign (KVM has been uknowingly being doing exactly that for years). Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20220423034752.1161007-6-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 54275f7 commit 5c64aba

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

arch/x86/kvm/mmu/mmu.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,16 +3044,14 @@ static bool handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa
30443044
static bool page_fault_can_be_fast(struct kvm_page_fault *fault)
30453045
{
30463046
/*
3047-
* Do not fix the mmio spte with invalid generation number which
3048-
* need to be updated by slow page fault path.
3047+
* Page faults with reserved bits set, i.e. faults on MMIO SPTEs, only
3048+
* reach the common page fault handler if the SPTE has an invalid MMIO
3049+
* generation number. Refreshing the MMIO generation needs to go down
3050+
* the slow path. Note, EPT Misconfigs do NOT set the PRESENT flag!
30493051
*/
30503052
if (fault->rsvd)
30513053
return false;
30523054

3053-
/* See if the page fault is due to an NX violation */
3054-
if (unlikely(fault->exec && fault->present))
3055-
return false;
3056-
30573055
/*
30583056
* #PF can be fast if:
30593057
*
@@ -3069,7 +3067,14 @@ static bool page_fault_can_be_fast(struct kvm_page_fault *fault)
30693067
* SPTE is MMU-writable (determined later), the fault can be fixed
30703068
* by setting the Writable bit, which can be done out of mmu_lock.
30713069
*/
3072-
return !kvm_ad_enabled() || (fault->write && fault->present);
3070+
if (!fault->present)
3071+
return !kvm_ad_enabled();
3072+
3073+
/*
3074+
* Note, instruction fetches and writes are mutually exclusive, ignore
3075+
* the "exec" flag.
3076+
*/
3077+
return fault->write;
30733078
}
30743079

30753080
/*

0 commit comments

Comments
 (0)