Re: [patch] kvm: make cr3 loading more robust

Ingo Molnar
2007-01-03T12:32:53Z

* Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:

> Right not the list is not LRU, so a zap can kill your parent page
> table. I'm also worried about preserving invariants, as the page
> tables are linked through a variety of data structures. Calling
> zap_page() while another operation is in progress could cause
> corruption if zap_page() kills one of your parents or children.

ok. How about the patch below then? This only addresses the OOM
scenario, not the !memslot case.

Ingo

Signed-off-by: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>

Index: linux/drivers/kvm/mmu.c
===================================================================
--- linux.orig/drivers/kvm/mmu.c
+++ linux/drivers/kvm/mmu.c
@@ -903,6 +903,8 @@ static void paging_new_cr3(struct kvm_vc
{
pgprintk("%s: cr3 %lx\n", __FUNCTION__, vcpu->cr3);
mmu_free_roots(vcpu);
+ if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
+ kvm_mmu_free_some_pages(vcpu);
mmu_alloc_roots(vcpu);
kvm_mmu_flush_tlb(vcpu);
kvm_arch_ops->set_cr3(vcpu, vcpu->mmu.root_hpa);