Skip to contentSkip to conversation

prepopulate guest pages after write-protecting

PATCH Applied Marcelo Tosatti 3 participants 3 messages Apr 4, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 prepopulate guest pages after write-protecting

Zdenek reported a bug where a looping "dmsetup status" eventually hangs on SMP guests.

The problem is that kvm_mmu_get_page() prepopulates the shadow MMU before write protecting the guest page tables. By doing so, it leaves a window open where the guest can mark a pte as present while the host has shadow cached such pte as "notrap". Accesses to such address will fault in the guest without the host having a chance to fix the situation.

Zdenek, can you confirm this fixes the problem?

arch/x86/kvm/mmu.c +1 -1
index 5c4c166..c89bf23 100644
@@ -852,9 +852,9 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
 	sp->gfn = gfn;
 	sp->role = role;
 	hlist_add_head(&sp->hash_link, bucket);
-	vcpu->arch.mmu.prefetch_page(vcpu, sp);
 	if (!metaphysical)
 		rmap_write_protect(vcpu->kvm, gfn);
+	vcpu->arch.mmu.prefetch_page(vcpu, sp);
 	return sp;
 }
 

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

#1 lore raw

2008/4/4, Marcelo Tosatti <[email protected]>:

Quoted 10 lines

Zdenek reported a bug where a looping "dmsetup status" eventually hangs on SMP guests.

The problem is that kvm_mmu_get_page() prepopulates the shadow MMU before write protecting the guest page tables. By doing so, it leaves a window open where the guest can mark a pte as present while the host has shadow cached such pte as "notrap". Accesses to such address will fault in the guest without the host having a chance to fix the situation.

Great - this looks like it has fixed my problems with busy looping processes - lets see if it will fix other weird behaviours I'm seeing with kvm :)

Zdenek

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

Applied
#2 lore raw
In reply to Marcelo Tosatti
Quoted 9 lines · Marcelo Tosatti

Zdenek reported a bug where a looping "dmsetup status" eventually hangs on SMP guests.

The problem is that kvm_mmu_get_page() prepopulates the shadow MMU before write protecting the guest page tables. By doing so, it leaves a window open where the guest can mark a pte as present while the host has shadow cached such pte as "notrap". Accesses to such address will fault in the guest without the host having a chance to fix the situation.

Applied, thanks. Impressive catch.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace