[PATCH 24/45] KVM: MMU: prepopulate guest pages after write-protecting

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Avi Kivity
Date: Thursday, April 17, 2008 - 2:10 am

From: 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.

Fix by moving the write protection before the pte prefetch.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 arch/x86/kvm/mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

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;
 }
 
-- 
1.5.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 01/45] s390: fixup for kvm, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 07/45] KVM: s390: sie intercept handling, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 12/45] KVM: s390: add kvm to kconfig on s390, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 13/45] KVM: s390: API documentation, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 14/45] KVM: s390: update maintainers, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 17/45] KVM: VMX: Enable MSR Bitmap feature, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 18/45] KVM: MMU: unify slots_lock usage, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 22/45] KVM: add vm refcounting, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 24/45] KVM: MMU: prepopulate guest pages after writ ..., Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 25/45] KVM: s390: Fix incorrect return value, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 26/45] KVM: s390: rename stfl to kvm_stfl, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 27/45] KVM: s390: Improve pgste accesses, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 34/45] KVM: ia64: VMM module interfaces, Avi Kivity, (Thu Apr 17, 2:10 am)
[PATCH 44/45] KVM: ia64: Enable kvm build for ia64, Avi Kivity, (Thu Apr 17, 2:10 am)
Re: [PATCH 13/45] KVM: s390: API documentation, Randy Dunlap, (Thu Apr 17, 8:11 am)
Re: [PATCH 13/45] KVM: s390: API documentation, Carsten Otte, (Thu Apr 17, 8:42 am)