• Sean Christopherson's avatar
    KVM: x86/mmu: Move event re-injection unprotect+retry into common path · b299c273
    Sean Christopherson authored
    Move the event re-injection unprotect+retry logic into
    kvm_mmu_write_protect_fault(), i.e. unprotect and retry if and only if
    the #PF actually hit a write-protected gfn.  Note, there is a small
    possibility that the gfn was unprotected by a different tasking between
    hitting the #PF and acquiring mmu_lock, but in that case, KVM will resume
    the guest immediately anyways because KVM will treat the fault as spurious.
    
    As a bonus, unprotecting _after_ handling the page fault also addresses the
    case where the installing a SPTE to handle fault encounters a shadowed PTE,
    i.e. *creates* a read-only SPTE.
    
    Opportunstically add a comment explaining what on earth the intent of the
    code is, as based on the changelog from commit 577bdc49 ("KVM: Avoid
    instruction emulation when event delivery is pending").
    
    Link: https://lore.kernel.org/r/20240831001538.336683-15-seanjc@google.com
    
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    b299c273
mmu.c 216 KB