public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: stable@kernel.org
Cc: linux-kernel@vger.kernel.org, kvm-devel@lists.sourceforge.net,
	Avi Kivity <avi@qumranet.com>
Subject: [PATCH 08/10] KVM: Skip pio instruction when it is emulated, not executed
Date: Sun,  2 Dec 2007 13:18:45 +0200	[thread overview]
Message-ID: <11965943273087-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1196594327338-git-send-email-avi@qumranet.com>

If we defer updating rip until pio instructions are executed, we have a
problem with reset:  a pio reset updates rip, and when the instruction
completes we skip the emulated instruction, pointing rip somewhere completely
unrelated.

Fix by updating rip when we see decode the instruction, not after emulation.

Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm_main.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 504e81d..b58fdf3 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1757,8 +1757,6 @@ static int complete_pio(struct kvm_vcpu *vcpu)
 	io->count -= io->cur_count;
 	io->cur_count = 0;
 
-	if (!io->count)
-		kvm_arch_ops->skip_emulated_instruction(vcpu);
 	return 0;
 }
 
@@ -1804,6 +1802,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 
 	pio_dev = vcpu_find_pio_dev(vcpu, port);
 	if (!string) {
+		kvm_arch_ops->skip_emulated_instruction(vcpu);
 		kvm_arch_ops->cache_regs(vcpu);
 		memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4);
 		kvm_arch_ops->decache_regs(vcpu);
@@ -1850,6 +1849,9 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 	vcpu->run->io.count = now;
 	vcpu->pio.cur_count = now;
 
+	if (now == count)
+		kvm_arch_ops->skip_emulated_instruction(vcpu);
+
 	for (i = 0; i < nr_pages; ++i) {
 		spin_lock(&vcpu->kvm->lock);
 		page = gva_to_page(vcpu, address + i * PAGE_SIZE);
-- 
1.5.3


      parent reply	other threads:[~2007-12-02 11:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-02 11:18 [PATCH 00/10]: KVM updates for 2.6.23.9 (-stable) Avi Kivity
2007-12-02 11:18 ` [PATCH 01/10] KVM: x86 emulator: implement 'movnti mem, reg' Avi Kivity
2007-12-02 11:18 ` [PATCH 02/10] KVM: x86 emulator: fix access registers for instructions with ModR/M byte and Mod = 3 Avi Kivity
2007-12-02 11:18 ` [PATCH 03/10] KVM: x86 emulator: invd instruction Avi Kivity
2007-12-02 11:18 ` [PATCH 04/10] KVM: SVM: Intercept the 'invd' and 'wbinvd' instructions Avi Kivity
2007-12-02 11:18 ` [PATCH 05/10] KVM: x86 emulator: Use emulator_write_emulated and not emulator_write_std Avi Kivity
     [not found] ` <1196594327338-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-02 11:18   ` [PATCH 06/10] KVM: Fix hang on uniprocessor Avi Kivity
2007-12-02 11:18   ` [PATCH 07/10] KVM: SVM: Fix FPU leak while emulating clts Avi Kivity
2007-12-02 11:18   ` [PATCH 09/10] KVM: VMX: Force vm86 mode if setting flags during real mode Avi Kivity
2007-12-02 11:18   ` [PATCH 10/10] KVM: VMX: Reset mmu context when entering " Avi Kivity
2007-12-02 19:08   ` [stable] [PATCH 00/10]: KVM updates for 2.6.23.9 (-stable) Greg KH
2007-12-03  9:23     ` [kvm-devel] " Avi Kivity
     [not found]       ` <4753CB07.7080807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-03 12:57         ` Greg KH
     [not found]           ` <20071203125739.GA12233-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2007-12-03 13:11             ` Avi Kivity
     [not found]               ` <47540067.7090905-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-03 13:31                 ` Greg KH
2007-12-02 11:18 ` Avi Kivity [this message]

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=11965943273087-git-send-email-avi@qumranet.com \
    --to=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@kernel.org \
    /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