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: [PATCHv2 22/23] KVM: x86 emulator: move interruptibility state tracking out of emulator
Date: Wed, 28 Apr 2010 19:15:43 +0300	[thread overview]
Message-ID: <1272471344-7076-23-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1272471344-7076-1-git-send-email-gleb@redhat.com>

Emulator shouldn't access vcpu directly.

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

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 4cc8368..e2def3b 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1843,20 +1843,6 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
 	return X86EMUL_CONTINUE;
 }
 
-static void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask)
-{
-	u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask);
-	/*
-	 * an sti; sti; sequence only disable interrupts for the first
-	 * instruction. So, if the last instruction, be it emulated or
-	 * not, left the system with the INT_STI flag enabled, it
-	 * means that the last instruction is an sti. We should not
-	 * leave the flag on in this case. The same goes for mov ss
-	 */
-	if (!(int_shadow & mask))
-		ctxt->interruptibility = mask;
-}
-
 static inline void
 setup_syscalls_segments(struct x86_emulate_ctxt *ctxt,
 			struct x86_emulate_ops *ops, struct desc_struct *cs,
@@ -2516,7 +2502,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 	int rc = X86EMUL_CONTINUE;
 	int saved_dst_type = c->dst.type;
 
-	ctxt->interruptibility = 0;
 	ctxt->decode.mem_read.pos = 0;
 
 	if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) {
@@ -2789,7 +2774,7 @@ special_insn:
 		}
 
 		if (c->modrm_reg == VCPU_SREG_SS)
-			toggle_interruptibility(ctxt, KVM_X86_SHADOW_INT_MOV_SS);
+			ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS;
 
 		rc = load_segment_descriptor(ctxt, ops, sel, c->modrm_reg);
 
@@ -2958,7 +2943,7 @@ special_insn:
 		if (emulator_bad_iopl(ctxt, ops))
 			kvm_inject_gp(ctxt->vcpu, 0);
 		else {
-			toggle_interruptibility(ctxt, KVM_X86_SHADOW_INT_STI);
+			ctxt->interruptibility = KVM_X86_SHADOW_INT_STI;
 			ctxt->eflags |= X86_EFLAGS_IF;
 			c->dst.type = OP_NONE;	/* Disable writeback. */
 		}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5fda84e..f7e8732 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3776,12 +3776,26 @@ static void cache_all_regs(struct kvm_vcpu *vcpu)
 	vcpu->arch.regs_dirty = ~0;
 }
 
+static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)
+{
+	u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu, mask);
+	/*
+	 * an sti; sti; sequence only disable interrupts for the first
+	 * instruction. So, if the last instruction, be it emulated or
+	 * not, left the system with the INT_STI flag enabled, it
+	 * means that the last instruction is an sti. We should not
+	 * leave the flag on in this case. The same goes for mov ss
+	 */
+	if (!(int_shadow & mask))
+		kvm_x86_ops->set_interrupt_shadow(vcpu, mask);
+}
+
 int emulate_instruction(struct kvm_vcpu *vcpu,
 			unsigned long cr2,
 			u16 error_code,
 			int emulation_type)
 {
-	int r, shadow_mask;
+	int r;
 	struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
 
 	kvm_clear_exception_queue(vcpu);
@@ -3809,6 +3823,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 			? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
 		memset(c, 0, sizeof(struct decode_cache));
 		memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
+		vcpu->arch.emulate_ctxt.interruptibility = 0;
 
 		r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);
 		trace_kvm_emulate_insn_start(vcpu);
@@ -3876,8 +3891,7 @@ restart:
 		return EMULATE_FAIL;
 	}
 
-	shadow_mask = vcpu->arch.emulate_ctxt.interruptibility;
-	kvm_x86_ops->set_interrupt_shadow(vcpu, shadow_mask);
+	toggle_interruptibility(vcpu, vcpu->arch.emulate_ctxt.interruptibility);
 	kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
 	memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
 	kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
-- 
1.6.5


  parent reply	other threads:[~2010-04-28 16:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-28 16:15 [PATCHv2 00/23] next round of emulator cleanups Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 01/23] KVM: x86 emulator: introduce read cache Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 02/23] KVM: x86 emulator: fix Move r/m16 to segment register decoding Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 03/23] KVM: x86 emulator: cleanup xchg emulation Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 04/23] KVM: x86 emulator: cleanup nop emulation Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 05/23] KVM: x86 emulator: handle "far address" source operand Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 06/23] KVM: x86 emulator: add (set|get)_dr callbacks to x86_emulate_ops Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 07/23] KVM: x86 emulator: add (set|get)_msr " Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 08/23] KVM: x86 emulator: add get_cached_segment_base() callback " Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 09/23] KVM: x86 emulator: cleanup some direct calls into kvm to use existing callbacks Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 10/23] KVM: x86 emulator: make set_cr() callback return error if it fails Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 11/23] KVM: x86 emulator: make (get|set)_dr() " Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 12/23] KVM: x86 emulator: fix X86EMUL_RETRY_INSTR and X86EMUL_CMPXCHG_FAILED values Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 13/23] KVM: fill in run->mmio details in (read|write)_emulated function Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 14/23] KVM: x86 emulator: x86_emulate_insn() return -1 only in case of emulation failure Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 15/23] KVM: remove export of emulator_write_emulated() Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 16/23] KVM: do not inject #PF in (read|write)_emulated() callbacks Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 17/23] KVM: handle emulation failure case first Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 18/23] KVM: x86 emulator: advance RIP outside x86 emulator code Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 19/23] KVM: x86 emulator: set RFLAGS " Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 20/23] KVM: x86 emulator: use shadowed register in emulate_sysexit() Gleb Natapov
2010-04-28 16:15 ` [PATCHv2 21/23] KVM: x86 exmulator: handle shadowed registers outside emulator Gleb Natapov
2010-04-28 16:15 ` Gleb Natapov [this message]
2010-04-28 16:15 ` [PATCHv2 23/23] KVM: x86 emulator: do not inject exception directly into vcpu Gleb Natapov
     [not found]   ` <446597.86519.qm@web55502.mail.re4.yahoo.com>
2010-04-29 10:17     ` qemu-kvm.0.12.2 aborts on linux Gleb Natapov
     [not found]       ` <792291.45224.qm@web55507.mail.re4.yahoo.com>
2010-05-02  5:23         ` Gleb Natapov
     [not found]           ` <710443.70603.qm@web55504.mail.re4.yahoo.com>
2010-05-03  7:44             ` Gleb Natapov
2010-04-29  9:26 ` [PATCHv2 00/23] next round of emulator cleanups Avi Kivity
2010-05-05  7:57 ` Avi Kivity

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=1272471344-7076-23-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