]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: x86: fix use of L1 MMIO areas in nested guests
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Aug 2017 16:36:58 +0000 (18:36 +0200)
committerRadim Krčmář <rkrcmar@redhat.com>
Fri, 18 Aug 2017 12:37:49 +0000 (14:37 +0200)
There is currently some confusion between nested and L1 GPAs.  The
assignment to "direct" in kvm_mmu_page_fault tries to fix that, but
it is not enough.  What this patch does is fence off the MMIO cache
completely when using shadow nested page tables, since we have neither
a GVA nor an L1 GPA to put in the cache.  This also allows some
simplifications in kvm_mmu_page_fault and FNAME(page_fault).

The EPT misconfig likewise does not have an L1 GPA to pass to
kvm_io_bus_write, so that must be skipped for guest mode.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
[Changed comment to say "GPAs" instead of "L1's physical addresses", as
 per David's review. - Radim]
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/mmu.c
arch/x86/kvm/paging_tmpl.h
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.h

index a2c592b1461779a985d8256ea14bf79a9c1c32c0..2dafd36368cca5d7328cb77661a736a1c8121408 100644 (file)
@@ -3596,6 +3596,13 @@ static bool is_shadow_zero_bits_set(struct kvm_mmu *mmu, u64 spte, int level)
 
 static bool mmio_info_in_cache(struct kvm_vcpu *vcpu, u64 addr, bool direct)
 {
+       /*
+        * A nested guest cannot use the MMIO cache if it is using nested
+        * page tables, because cr2 is a nGPA while the cache stores GPAs.
+        */
+       if (mmu_is_nested(vcpu))
+               return false;
+
        if (direct)
                return vcpu_match_mmio_gpa(vcpu, addr);
 
@@ -4841,7 +4848,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
 {
        int r, emulation_type = EMULTYPE_RETRY;
        enum emulation_result er;
-       bool direct = vcpu->arch.mmu.direct_map || mmu_is_nested(vcpu);
+       bool direct = vcpu->arch.mmu.direct_map;
 
        /* With shadow page tables, fault_address contains a GVA or nGPA.  */
        if (vcpu->arch.mmu.direct_map) {
index 3bb90ceeb52dd9a3d4289c3d2f8684ca84fe4175..86b68dc5a6493152b9032f1fda970b31ca8d755a 100644 (file)
@@ -790,8 +790,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code,
                         &map_writable))
                return 0;
 
-       if (handle_abnormal_pfn(vcpu, mmu_is_nested(vcpu) ? 0 : addr,
-                               walker.gfn, pfn, walker.pte_access, &r))
+       if (handle_abnormal_pfn(vcpu, addr, walker.gfn, pfn, walker.pte_access, &r))
                return r;
 
        /*
index e2c8b33c35d139560cc303f2233afb32952eb221..61389ad784e4294f189c774f0ab8789cc31c18b9 100644 (file)
@@ -6402,8 +6402,13 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
        int ret;
        gpa_t gpa;
 
+       /*
+        * A nested guest cannot optimize MMIO vmexits, because we have an
+        * nGPA here instead of the required GPA.
+        */
        gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
-       if (!kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
+       if (!is_guest_mode(vcpu) &&
+           !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
                trace_kvm_fast_mmio(gpa);
                return kvm_skip_emulated_instruction(vcpu);
        }
index 6120670749055ddb43174c606d3d5eceaf41ecd6..113460370a7f6692fd0a10c79f1d419e866a0f36 100644 (file)
@@ -90,7 +90,11 @@ static inline u32 bit(int bitno)
 static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
                                        gva_t gva, gfn_t gfn, unsigned access)
 {
-       vcpu->arch.mmio_gva = gva & PAGE_MASK;
+       /*
+        * If this is a shadow nested page table, the "GVA" is
+        * actually a nGPA.
+        */
+       vcpu->arch.mmio_gva = mmu_is_nested(vcpu) ? 0 : gva & PAGE_MASK;
        vcpu->arch.access = access;
        vcpu->arch.mmio_gfn = gfn;
        vcpu->arch.mmio_gen = kvm_memslots(vcpu->kvm)->generation;