aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-09-14 13:26:06 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-09-14 16:59:55 -0400
commit22d95b1282810f5af599ee292b3fc443aefbdad0 (patch)
treedafe050aef12ea4bbac4ffb77070d8ec416a0838 /drivers/kvm/mmu.c
parent44e3ff32ac229a10a30b7b840f092f5b32a5f72a (diff)
KVM: MMU: Fix rare oops on guest context switch
A guest context switch to an uncached cr3 can require allocation of shadow pages, but we only recycle shadow pages in kvm_mmu_page_fault(). Move shadow page recycling to mmu_topup_memory_caches(), which is called from both the page fault handler and from guest cr3 reload. Signed-off-by: Avi Kivity <avi@qumranet.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r--drivers/kvm/mmu.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 1a87ba9d5156..23965aa5ee78 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -273,12 +273,14 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
273 int r; 273 int r;
274 274
275 r = __mmu_topup_memory_caches(vcpu, GFP_NOWAIT); 275 r = __mmu_topup_memory_caches(vcpu, GFP_NOWAIT);
276 kvm_mmu_free_some_pages(vcpu);
276 if (r < 0) { 277 if (r < 0) {
277 spin_unlock(&vcpu->kvm->lock); 278 spin_unlock(&vcpu->kvm->lock);
278 kvm_arch_ops->vcpu_put(vcpu); 279 kvm_arch_ops->vcpu_put(vcpu);
279 r = __mmu_topup_memory_caches(vcpu, GFP_KERNEL); 280 r = __mmu_topup_memory_caches(vcpu, GFP_KERNEL);
280 kvm_arch_ops->vcpu_load(vcpu); 281 kvm_arch_ops->vcpu_load(vcpu);
281 spin_lock(&vcpu->kvm->lock); 282 spin_lock(&vcpu->kvm->lock);
283 kvm_mmu_free_some_pages(vcpu);
282 } 284 }
283 return r; 285 return r;
284} 286}
@@ -1208,7 +1210,7 @@ int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
1208 return kvm_mmu_unprotect_page(vcpu, gpa >> PAGE_SHIFT); 1210 return kvm_mmu_unprotect_page(vcpu, gpa >> PAGE_SHIFT);
1209} 1211}
1210 1212
1211void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu) 1213void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
1212{ 1214{
1213 while (vcpu->kvm->n_free_mmu_pages < KVM_REFILL_PAGES) { 1215 while (vcpu->kvm->n_free_mmu_pages < KVM_REFILL_PAGES) {
1214 struct kvm_mmu_page *page; 1216 struct kvm_mmu_page *page;
@@ -1218,7 +1220,6 @@ void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
1218 kvm_mmu_zap_page(vcpu->kvm, page); 1220 kvm_mmu_zap_page(vcpu->kvm, page);
1219 } 1221 }
1220} 1222}
1221EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages);
1222 1223
1223static void free_mmu_pages(struct kvm_vcpu *vcpu) 1224static void free_mmu_pages(struct kvm_vcpu *vcpu)
1224{ 1225{