Skip to content

Commit 6205257

Browse files
committed
KVM: x86: Remove manual pfn lookup when retrying #PF after failed emulation
Drop the manual pfn look when retrying an instruction that KVM failed to emulation in response to a #PF due to a write-protected gfn. Now that KVM sets EMULTYPE_ALLOW_RETRY_PF if and only if the page fault hit a write- protected gfn, i.e. if and only if there's a writable memslot, there's no need to redo the lookup to avoid retrying an instruction that failed on emulated MMIO (no slot, or a write to a read-only slot). I.e. KVM will never attempt to retry an instruction that failed on emulated MMIO, whereas that was not the case prior to the introduction of RET_PF_WRITE_PROTECTED. Reviewed-by: Yuan Yao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent b299c27 commit 6205257

File tree

1 file changed

+0
-18
lines changed

1 file changed

+0
-18
lines changed

arch/x86/kvm/x86.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8865,7 +8865,6 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
88658865
int emulation_type)
88668866
{
88678867
gpa_t gpa = cr2_or_gpa;
8868-
kvm_pfn_t pfn;
88698868

88708869
if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF))
88718870
return false;
@@ -8885,23 +8884,6 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
88858884
return true;
88868885
}
88878886

8888-
/*
8889-
* Do not retry the unhandleable instruction if it faults on the
8890-
* readonly host memory, otherwise it will goto a infinite loop:
8891-
* retry instruction -> write #PF -> emulation fail -> retry
8892-
* instruction -> ...
8893-
*/
8894-
pfn = gfn_to_pfn(vcpu->kvm, gpa_to_gfn(gpa));
8895-
8896-
/*
8897-
* If the instruction failed on the error pfn, it can not be fixed,
8898-
* report the error to userspace.
8899-
*/
8900-
if (is_error_noslot_pfn(pfn))
8901-
return false;
8902-
8903-
kvm_release_pfn_clean(pfn);
8904-
89058887
/*
89068888
* If emulation may have been triggered by a write to a shadowed page
89078889
* table, unprotect the gfn (zap any relevant SPTEs) and re-enter the

0 commit comments

Comments
 (0)