KVM: x86 emulator: restart string instruction without going back to a guest.
Currently when string instruction is only partially complete we go back to a guest mode, guest tries to reexecute instruction and exits again and at this point emulation continues. Avoid all of this by restarting instruction without going back to a guest mode, but return to a guest mode each 1024 iterations to allow interrupt injection. Pending exception causes immediate guest entry too. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
This commit is contained in:
@@ -3755,6 +3755,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
|
||||
return EMULATE_DONE;
|
||||
}
|
||||
|
||||
restart:
|
||||
r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);
|
||||
shadow_mask = vcpu->arch.emulate_ctxt.interruptibility;
|
||||
|
||||
@@ -3777,7 +3778,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
|
||||
|
||||
if (r) {
|
||||
if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
|
||||
return EMULATE_DONE;
|
||||
goto done;
|
||||
if (!vcpu->mmio_needed) {
|
||||
kvm_report_emulation_failure(vcpu, "mmio");
|
||||
return EMULATE_FAIL;
|
||||
@@ -3792,6 +3793,13 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
|
||||
return EMULATE_DO_MMIO;
|
||||
}
|
||||
|
||||
done:
|
||||
if (vcpu->arch.exception.pending)
|
||||
vcpu->arch.emulate_ctxt.restart = false;
|
||||
|
||||
if (vcpu->arch.emulate_ctxt.restart)
|
||||
goto restart;
|
||||
|
||||
return EMULATE_DONE;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(emulate_instruction);
|
||||
@@ -4560,6 +4568,15 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (vcpu->arch.emulate_ctxt.restart) {
|
||||
vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
|
||||
r = emulate_instruction(vcpu, 0, 0, EMULTYPE_NO_DECODE);
|
||||
srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
|
||||
if (r == EMULATE_DO_MMIO) {
|
||||
r = 0;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL)
|
||||
kvm_register_write(vcpu, VCPU_REGS_RAX,
|
||||
kvm_run->hypercall.ret);
|
||||
|
Reference in New Issue
Block a user