]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: Fix missing smp tlb flush in invlpg
authorAndrea Arcangeli <aarcange@redhat.com>
Thu, 12 Mar 2009 17:18:43 +0000 (18:18 +0100)
committerAvi Kivity <avi@redhat.com>
Mon, 16 Mar 2009 10:16:42 +0000 (12:16 +0200)
When kvm emulates an invlpg instruction, it can drop a shadow pte, but
leaves the guest tlbs intact.  This can cause memory corruption when
swapping out.

Without this the other cpu can still write to a freed host physical page.
tlb smp flush must happen if rmap_remove is called always before mmu_lock
is released because the VM will take the mmu_lock before it can finally add
the page to the freelist after swapout. mmu notifier makes it safe to flush
the tlb after freeing the page (otherwise it would never be safe) so we can do
a single flush for multiple sptes invalidated.

Cc: stable@kernel.org
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/paging_tmpl.h

index a0c11ead723956c667172a9f3fb6787684fe7ff5..855eb71110490fe269216163605f4eda95d6e19d 100644 (file)
@@ -445,6 +445,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
        gpa_t pte_gpa = -1;
        int level;
        u64 *sptep;
+       int need_flush = 0;
 
        spin_lock(&vcpu->kvm->mmu_lock);
 
@@ -464,6 +465,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
                                rmap_remove(vcpu->kvm, sptep);
                                if (is_large_pte(*sptep))
                                        --vcpu->kvm->stat.lpages;
+                               need_flush = 1;
                        }
                        set_shadow_pte(sptep, shadow_trap_nonpresent_pte);
                        break;
@@ -473,6 +475,8 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
                        break;
        }
 
+       if (need_flush)
+               kvm_flush_remote_tlbs(vcpu->kvm);
        spin_unlock(&vcpu->kvm->mmu_lock);
 
        if (pte_gpa == -1)