Skip to content

Commit 2df354e

Browse files
committed
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: Yuan Yao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 41e6e36 commit 2df354e

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

arch/x86/kvm/x86.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8924,26 +8924,6 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
89248924
return !(emulation_type & EMULTYPE_WRITE_PF_TO_SP);
89258925
}
89268926

8927-
static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
8928-
gpa_t cr2_or_gpa, int emulation_type)
8929-
{
8930-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8931-
8932-
/*
8933-
* If the emulation is caused by #PF and it is non-page_table
8934-
* writing instruction, it means the VM-EXIT is caused by shadow
8935-
* page protected, we can zap the shadow page and retry this
8936-
* instruction directly.
8937-
*/
8938-
if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF))
8939-
return false;
8940-
8941-
if (x86_page_table_writing_insn(ctxt))
8942-
return false;
8943-
8944-
return kvm_mmu_unprotect_gfn_and_retry(vcpu, cr2_or_gpa);
8945-
}
8946-
89478927
static int complete_emulated_mmio(struct kvm_vcpu *vcpu);
89488928
static int complete_emulated_pio(struct kvm_vcpu *vcpu);
89498929

@@ -9223,7 +9203,15 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
92239203
return 1;
92249204
}
92259205

9226-
if (retry_instruction(ctxt, cr2_or_gpa, emulation_type))
9206+
/*
9207+
* If emulation was caused by a write-protection #PF on a non-page_table
9208+
* writing instruction, try to unprotect the gfn, i.e. zap shadow pages,
9209+
* and retry the instruction, as the vCPU is likely no longer using the
9210+
* gfn as a page table.
9211+
*/
9212+
if ((emulation_type & EMULTYPE_ALLOW_RETRY_PF) &&
9213+
!x86_page_table_writing_insn(ctxt) &&
9214+
kvm_mmu_unprotect_gfn_and_retry(vcpu, cr2_or_gpa))
92279215
return 1;
92289216

92299217
/* this is needed for vmware backdoor interface to work since it

0 commit comments

Comments
 (0)