public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, Sheng Yang <sheng@linux.intel.com>
Subject: [PATCH 3/4] KVM: x86: displace MMIO handling part
Date: Tue, 23 Dec 2008 16:12:52 +0800	[thread overview]
Message-ID: <1230019973-16833-4-git-send-email-sheng@linux.intel.com> (raw)
In-Reply-To: <1230019973-16833-1-git-send-email-sheng@linux.intel.com>

Now we handling accessing guest memory first, then MMIO. But for intercepted
MMIO, the mapping to MMIO page is exist, so KVM would write to guest by mistake.
The patch move MMIO handling ahead of guest memory in emulating instruction.

(I am not confident on this modify, would it bring some side effect?)

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
 arch/x86/kvm/x86.c |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index aa4575c..6554966 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2022,17 +2022,6 @@ static int emulator_read_emulated(unsigned long addr,
 
 	gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, addr);
 
-	/* For APIC access vmexit */
-	if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
-		goto mmio;
-
-	if (emulator_read_std(addr, val, bytes, vcpu)
-			== X86EMUL_CONTINUE)
-		return X86EMUL_CONTINUE;
-	if (gpa == UNMAPPED_GVA)
-		return X86EMUL_PROPAGATE_FAULT;
-
-mmio:
 	/*
 	 * Is this MMIO handled locally?
 	 */
@@ -2045,6 +2034,12 @@ mmio:
 	}
 	mutex_unlock(&vcpu->kvm->lock);
 
+	if (emulator_read_std(addr, val, bytes, vcpu)
+			== X86EMUL_CONTINUE)
+		return X86EMUL_CONTINUE;
+	if (gpa == UNMAPPED_GVA)
+		return X86EMUL_PROPAGATE_FAULT;
+
 	vcpu->mmio_needed = 1;
 	vcpu->mmio_phys_addr = gpa;
 	vcpu->mmio_size = bytes;
@@ -2080,14 +2075,6 @@ static int emulator_write_emulated_onepage(unsigned long addr,
 		return X86EMUL_PROPAGATE_FAULT;
 	}
 
-	/* For APIC access vmexit */
-	if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
-		goto mmio;
-
-	if (emulator_write_phys(vcpu, gpa, val, bytes))
-		return X86EMUL_CONTINUE;
-
-mmio:
 	/*
 	 * Is this MMIO handled locally?
 	 */
@@ -2100,6 +2087,9 @@ mmio:
 	}
 	mutex_unlock(&vcpu->kvm->lock);
 
+	if (emulator_write_phys(vcpu, gpa, val, bytes))
+		return X86EMUL_CONTINUE;
+
 	vcpu->mmio_needed = 1;
 	vcpu->mmio_phys_addr = gpa;
 	vcpu->mmio_size = bytes;
-- 
1.5.4.5


  parent reply	other threads:[~2008-12-23  8:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-23  8:12 [PATCH 0/4] MSI-X Enabling Sheng Yang
2008-12-23  8:12 ` [PATCH 1/4] KVM: Using kfifo for irq recording Sheng Yang
2008-12-25 11:07   ` Avi Kivity
2008-12-25 11:27     ` Sheng Yang
2008-12-25 13:26       ` Avi Kivity
2008-12-26  1:53         ` Sheng Yang
2008-12-23  8:12 ` [PATCH 2/4] KVM: Add intercepted MMIO for KVM Sheng Yang
2008-12-23  8:12 ` Sheng Yang [this message]
2008-12-23  8:12 ` [PATCH 4/4] KVM: Enable MSI-X for KVM assigned device Sheng Yang
2008-12-23 20:19 ` [PATCH 0/4] MSI-X Enabling Marcelo Tosatti
2008-12-24  3:00   ` Sheng Yang

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=1230019973-16833-4-git-send-email-sheng@linux.intel.com \
    --to=sheng@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.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