From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sheng Yang Subject: [PATCH 3/4] KVM: x86: displace MMIO handling part Date: Tue, 23 Dec 2008 16:12:52 +0800 Message-ID: <1230019973-16833-4-git-send-email-sheng@linux.intel.com> References: <1230019973-16833-1-git-send-email-sheng@linux.intel.com> Cc: kvm@vger.kernel.org, Sheng Yang To: Avi Kivity Return-path: Received: from mga02.intel.com ([134.134.136.20]:22716 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752920AbYLWIMz (ORCPT ); Tue, 23 Dec 2008 03:12:55 -0500 In-Reply-To: <1230019973-16833-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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