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 <[email protected]> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
