public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org
Subject: [PATCH 17/23] KVM: x86 emulator: advance RIP outside x86 emulator code
Date: Tue, 27 Apr 2010 15:15:18 +0300	[thread overview]
Message-ID: <1272370524-1295-18-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1272370524-1295-1-git-send-email-gleb@redhat.com>

Return new RIP as part of instruction emulation result instead of
updating KVM's RIP from x86 emulator code.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 arch/x86/kvm/emulate.c |    7 ++++---
 arch/x86/kvm/x86.c     |    4 +++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c8acc1d..ef4a3ab 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2525,8 +2525,9 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
 
 	if (rc == X86EMUL_CONTINUE) {
 		memcpy(ctxt->vcpu->arch.regs, c->regs, sizeof c->regs);
-		kvm_rip_write(ctxt->vcpu, c->eip);
 		rc = writeback(ctxt, ops);
+		if (rc == X86EMUL_CONTINUE)
+			ctxt->eip = c->eip;
 	}
 
 	return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
@@ -2583,7 +2584,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 		if (address_mask(c, c->regs[VCPU_REGS_RCX]) == 0) {
 		string_done:
 			ctxt->restart = false;
-			kvm_rip_write(ctxt->vcpu, c->eip);
+			ctxt->eip = c->eip;
 			goto done;
 		}
 		/* The second termination condition only applies for REPE
@@ -3061,7 +3062,7 @@ writeback:
 	ctxt->decode.mem_read.end = 0;
 	/* Commit shadow register state. */
 	memcpy(ctxt->vcpu->arch.regs, c->regs, sizeof c->regs);
-	kvm_rip_write(ctxt->vcpu, c->eip);
+	ctxt->eip = c->eip;
 	ops->set_rflags(ctxt->vcpu, ctxt->eflags);
 
 done:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f1ebeed..f0b12f4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3874,6 +3874,7 @@ restart:
 
 	shadow_mask = vcpu->arch.emulate_ctxt.interruptibility;
 	kvm_x86_ops->set_interrupt_shadow(vcpu, shadow_mask);
+	kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
 
 	if (vcpu->arch.pio.count) {
 		if (!vcpu->arch.pio.in)
@@ -4877,7 +4878,8 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason,
 
 	if (ret)
 		return EMULATE_FAIL;
-
+	
+	kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
 	kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
 	return EMULATE_DONE;
 }
-- 
1.6.5


  parent reply	other threads:[~2010-04-27 12:15 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-27 12:15 [PATCH 00/23] next round of emulator cleanups Gleb Natapov
2010-04-27 12:15 ` [PATCH 01/23] KVM: x86 emulator: introduce read cache Gleb Natapov
2010-04-27 12:15 ` [PATCH 02/23] KVM: x86 emulator: fix Move r/m16 to segment register decoding Gleb Natapov
2010-04-27 12:15 ` [PATCH 03/23] KVM: x86 emulator: cleanup xchg emulation Gleb Natapov
2010-04-27 12:15 ` [PATCH 04/23] KVM: x86 emulator: cleanup nop emulation Gleb Natapov
2010-04-27 12:15 ` [PATCH 05/23] KVM: x86 emulator: handle "far address" source operand Gleb Natapov
2010-04-27 12:15 ` [PATCH 06/23] KVM: x86 emulator: add (set|get)_dr callbacks to x86_emulate_ops Gleb Natapov
2010-04-27 12:15 ` [PATCH 07/23] KVM: x86 emulator: add (set|get)_msr " Gleb Natapov
2010-04-27 12:15 ` [PATCH 08/23] KVM: x86 emulator: cleanup some direct calls into kvm to use existing callbacks Gleb Natapov
2010-04-28  8:59   ` Avi Kivity
2010-04-28  9:33     ` Gleb Natapov
2010-04-28 12:56       ` Avi Kivity
2010-04-27 12:15 ` [PATCH 09/23] KVM: x86 emulator: make set_cr() callback return error if it fails Gleb Natapov
2010-04-28  9:01   ` Avi Kivity
2010-04-27 12:15 ` [PATCH 10/23] KVM: x86 emulator: make (get|set)_dr() " Gleb Natapov
2010-04-27 12:15 ` [PATCH 11/23] KVM: x86 emulator: fix X86EMUL_RETRY_INSTR and X86EMUL_CMPXCHG_FAILED values Gleb Natapov
2010-04-27 12:15 ` [PATCH 12/23] KVM: fill in run->mmio details in (read|write)_emulated function Gleb Natapov
2010-04-27 12:15 ` [PATCH 13/23] KVM: x86 emulator: x86_emulate_insn() return -1 only in case of emulation failure Gleb Natapov
2010-04-27 12:15 ` [PATCH 14/23] KVM: remove export of emulator_write_emulated() Gleb Natapov
2010-04-27 12:15 ` [PATCH 15/23] KVM: do not inject #PF in (read|write)_emulated() callbacks Gleb Natapov
2010-04-28  9:11   ` Avi Kivity
2010-04-28  9:21     ` Gleb Natapov
2010-04-29  9:23       ` Avi Kivity
2010-04-27 12:15 ` [PATCH 16/23] KVM: handle emulation failure case first Gleb Natapov
2010-04-27 12:15 ` Gleb Natapov [this message]
2010-04-27 12:15 ` [PATCH 18/23] KVM: x86 emulator: set RFLAGS outside x86 emulator code Gleb Natapov
2010-04-27 12:15 ` [PATCH 19/23] KVM: x86 emulator: use shadowed register in emulate_sysexit() Gleb Natapov
2010-04-27 12:15 ` [PATCH 20/23] KVM: x86 exmulator: handle shadowed registers outside emulator Gleb Natapov
2010-04-27 12:15 ` [PATCH 21/23] KVM: x86 emulator: move interruptibility state tracking out of emulator Gleb Natapov
2010-04-27 12:15 ` [PATCH 22/23] KVM: remove unneeded initialization Gleb Natapov
2010-04-28  9:17   ` Avi Kivity
2010-04-27 12:15 ` [PATCH 23/23] KVM: x86 emulator: do not inject exception directly into vcpu Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1272370524-1295-18-git-send-email-gleb@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox