Skip to content

Commit c1edcc4

Browse files
committed
KVM: x86: Retry to-be-emulated insn in "slow" unprotect path iff sp is zapped
Resume the guest and thus skip emulation of a non-PTE-writing instruction if and only if unprotecting the gfn actually zapped at least one shadow page. If the gfn is write-protected for some reason other than shadow paging, attempting to unprotect the gfn will effectively fail, and thus retrying the instruction is all but guaranteed to be pointless. This bug has existed for a long time, but was effectively fudged around by the retry RIP+address anti-loop detection. Reviewed-by: Yuan Yao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 2fb2b78 commit c1edcc4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8965,14 +8965,14 @@ static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
89658965
if (ctxt->eip == last_retry_eip && last_retry_addr == cr2_or_gpa)
89668966
return false;
89678967

8968-
vcpu->arch.last_retry_eip = ctxt->eip;
8969-
vcpu->arch.last_retry_addr = cr2_or_gpa;
8970-
89718968
if (!vcpu->arch.mmu->root_role.direct)
89728969
gpa = kvm_mmu_gva_to_gpa_write(vcpu, cr2_or_gpa, NULL);
89738970

8974-
kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(gpa));
8971+
if (!kvm_mmu_unprotect_page(vcpu->kvm, gpa_to_gfn(gpa)))
8972+
return false;
89758973

8974+
vcpu->arch.last_retry_eip = ctxt->eip;
8975+
vcpu->arch.last_retry_addr = cr2_or_gpa;
89768976
return true;
89778977
}
89788978

0 commit comments

Comments
 (0)