public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* missing kvm smp tlb flush in invlpg
@ 2009-03-12 17:18 Andrea Arcangeli
  2009-03-15 10:35 ` Avi Kivity
  2009-03-15 19:23 ` Marcelo Tosatti
  0 siblings, 2 replies; 11+ messages in thread
From: Andrea Arcangeli @ 2009-03-12 17:18 UTC (permalink / raw)
  To: kvm; +Cc: Marcelo Tosatti

From: Andrea Arcangeli <aarcange@redhat.com>

While looking at invlpg out of sync code with Izik I think I noticed a
missing smp tlb flush here. 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.

Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---

diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index a0c11ea..855eb71 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -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)

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-03-16 18:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-12 17:18 missing kvm smp tlb flush in invlpg Andrea Arcangeli
2009-03-15 10:35 ` Avi Kivity
2009-03-15 16:16   ` Andrea Arcangeli
2009-03-15 16:19     ` Avi Kivity
2009-03-15 16:30       ` Andrea Arcangeli
2009-03-15 16:35         ` Avi Kivity
2009-03-15 17:05           ` Andrea Arcangeli
2009-03-16 10:16             ` Avi Kivity
2009-03-15 19:23 ` Marcelo Tosatti
2009-03-15 20:11   ` Izik Eidus
2009-03-16 18:22     ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox