public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] prepopulate guest pages after write-protecting
@ 2008-04-04 17:56 Marcelo Tosatti
  2008-04-04 19:08 ` Zdenek Kabelac
  2008-04-04 21:06 ` Avi Kivity
  0 siblings, 2 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2008-04-04 17:56 UTC (permalink / raw)
  To: Zdenek Kabelac, Avi Kivity; +Cc: kvm-devel


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.

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


Zdenek, can you confirm this fixes the problem?


diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 5c4c166..c89bf23 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -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

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

* Re: [PATCH] prepopulate guest pages after write-protecting
  2008-04-04 17:56 [PATCH] prepopulate guest pages after write-protecting Marcelo Tosatti
@ 2008-04-04 19:08 ` Zdenek Kabelac
  2008-04-04 21:06 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Zdenek Kabelac @ 2008-04-04 19:08 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm-devel, Avi Kivity

2008/4/4, Marcelo Tosatti <mtosatti@redhat.com>:
>
>  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

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

* Re: [PATCH] prepopulate guest pages after write-protecting
  2008-04-04 17:56 [PATCH] prepopulate guest pages after write-protecting Marcelo Tosatti
  2008-04-04 19:08 ` Zdenek Kabelac
@ 2008-04-04 21:06 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2008-04-04 21:06 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm-devel, Zdenek Kabelac

Marcelo Tosatti wrote:
> 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.

-- 
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

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

end of thread, other threads:[~2008-04-04 21:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-04 17:56 [PATCH] prepopulate guest pages after write-protecting Marcelo Tosatti
2008-04-04 19:08 ` Zdenek Kabelac
2008-04-04 21:06 ` Avi Kivity

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