Commit 2df354e3 authored by Sean Christopherson's avatar Sean Christopherson

KVM: x86: Fold retry_instruction() into x86_emulate_instruction()

Now that retry_instruction() is reasonably tiny, fold it into its sole
caller, x86_emulate_instruction().  In addition to getting rid of the
absurdly confusing retry_instruction() name, handling the retry in
x86_emulate_instruction() pairs it back up with the code that resets
last_retry_{eip,address}.

No functional change intended.
Reviewed-by: default avatarYuan Yao <yuan.yao@intel.com>
Link: https://lore.kernel.org/r/20240831001538.336683-12-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 41e6e367
......@@ -8924,26 +8924,6 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
return !(emulation_type & EMULTYPE_WRITE_PF_TO_SP);
}
static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
gpa_t cr2_or_gpa, int emulation_type)
{
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
/*
* If the emulation is caused by #PF and it is non-page_table
* writing instruction, it means the VM-EXIT is caused by shadow
* page protected, we can zap the shadow page and retry this
* instruction directly.
*/
if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF))
return false;
if (x86_page_table_writing_insn(ctxt))
return false;
return kvm_mmu_unprotect_gfn_and_retry(vcpu, cr2_or_gpa);
}
static int complete_emulated_mmio(struct kvm_vcpu *vcpu);
static int complete_emulated_pio(struct kvm_vcpu *vcpu);
......@@ -9223,7 +9203,15 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
return 1;
}
if (retry_instruction(ctxt, cr2_or_gpa, emulation_type))
/*
* If emulation was caused by a write-protection #PF on a non-page_table
* writing instruction, try to unprotect the gfn, i.e. zap shadow pages,
* and retry the instruction, as the vCPU is likely no longer using the
* gfn as a page table.
*/
if ((emulation_type & EMULTYPE_ALLOW_RETRY_PF) &&
!x86_page_table_writing_insn(ctxt) &&
kvm_mmu_unprotect_gfn_and_retry(vcpu, cr2_or_gpa))
return 1;
/* this is needed for vmware backdoor interface to work since it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment