public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* KVM: MMU: rmap_write_protect() hugepage iteration bug
@ 2008-06-08  0:27 Marcelo Tosatti
  2008-06-08  1:54 ` Andrea Arcangeli
  0 siblings, 1 reply; 11+ messages in thread
From: Marcelo Tosatti @ 2008-06-08  0:27 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel


rmap_next() expects the "spte" argument to be NULL whenever there's only
one remaining entry in the descriptor. That is, it was not designed to
handle changes in the chain while iterating.

This bug cripples rmap_write_protect() so that it won't nuke all
writable large mappings to a particular gfn.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index aaccc40..e11ff17 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -632,17 +632,19 @@ static void rmap_write_protect(struct kvm *kvm, u64 gfn)
 	rmapp = gfn_to_rmap(kvm, gfn, 1);
 	spte = rmap_next(kvm, rmapp, NULL);
 	while (spte) {
+		u64 *next_spte;
 		BUG_ON(!spte);
 		BUG_ON(!(*spte & PT_PRESENT_MASK));
 		BUG_ON((*spte & (PT_PAGE_SIZE_MASK|PT_PRESENT_MASK)) != (PT_PAGE_SIZE_MASK|PT_PRESENT_MASK));
 		pgprintk("rmap_write_protect(large): spte %p %llx %lld\n", spte, *spte, gfn);
+		next_spte = rmap_next(kvm, rmapp, spte);
 		if (is_writeble_pte(*spte)) {
 			rmap_remove(kvm, spte);
 			--kvm->stat.lpages;
 			set_shadow_pte(spte, shadow_trap_nonpresent_pte);
 			write_protected = 1;
 		}
-		spte = rmap_next(kvm, rmapp, spte);
+		spte = next_spte;
 	}
 
 	if (write_protected)

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

end of thread, other threads:[~2008-06-09  0:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-08  0:27 KVM: MMU: rmap_write_protect() hugepage iteration bug Marcelo Tosatti
2008-06-08  1:54 ` Andrea Arcangeli
2008-06-08  4:48   ` Marcelo Tosatti
2008-06-08  7:30     ` Avi Kivity
2008-06-08  8:03       ` Avi Kivity
2008-06-08  8:04         ` Avi Kivity
2008-06-08 18:31     ` Andrea Arcangeli
2008-06-08 19:52       ` Marcelo Tosatti
2008-06-08 20:30         ` Andrea Arcangeli
2008-06-09  0:20           ` Marcelo Tosatti
2008-06-09  0:55             ` Andrea Arcangeli

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