Skip to content

Commit 41e6e36

Browse files
committed
KVM: x86: Move EMULTYPE_ALLOW_RETRY_PF to x86_emulate_instruction()
Move the sanity checks for EMULTYPE_ALLOW_RETRY_PF to the top of x86_emulate_instruction(). In addition to deduplicating a small amount of code, this makes the connection between EMULTYPE_ALLOW_RETRY_PF and EMULTYPE_PF even more explicit, and will allow dropping retry_instruction() entirely. Reviewed-by: Yuan Yao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent dfaae84 commit 41e6e36

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8870,10 +8870,6 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
88708870
if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF))
88718871
return false;
88728872

8873-
if (WARN_ON_ONCE(is_guest_mode(vcpu)) ||
8874-
WARN_ON_ONCE(!(emulation_type & EMULTYPE_PF)))
8875-
return false;
8876-
88778873
if (!vcpu->arch.mmu->root_role.direct) {
88788874
/*
88798875
* Write permission should be allowed since only
@@ -8942,10 +8938,6 @@ static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
89428938
if (!(emulation_type & EMULTYPE_ALLOW_RETRY_PF))
89438939
return false;
89448940

8945-
if (WARN_ON_ONCE(is_guest_mode(vcpu)) ||
8946-
WARN_ON_ONCE(!(emulation_type & EMULTYPE_PF)))
8947-
return false;
8948-
89498941
if (x86_page_table_writing_insn(ctxt))
89508942
return false;
89518943

@@ -9148,6 +9140,11 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
91489140
struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
91499141
bool writeback = true;
91509142

9143+
if ((emulation_type & EMULTYPE_ALLOW_RETRY_PF) &&
9144+
(WARN_ON_ONCE(is_guest_mode(vcpu)) ||
9145+
WARN_ON_ONCE(!(emulation_type & EMULTYPE_PF))))
9146+
emulation_type &= ~EMULTYPE_ALLOW_RETRY_PF;
9147+
91519148
r = kvm_check_emulate_insn(vcpu, emulation_type, insn, insn_len);
91529149
if (r != X86EMUL_CONTINUE) {
91539150
if (r == X86EMUL_RETRY_INSTR || r == X86EMUL_PROPAGATE_FAULT)

0 commit comments

Comments
 (0)