Re: [PATCH] do not free active mmu pages in free_mmu_pages()

Gleb Natapov
2009-03-16T20:37:48Z

On Mon, Mar 16, 2009 at 05:15:33PM -0300, Marcelo Tosatti wrote:
> On Wed, Mar 11, 2009 at 12:07:55PM +0200, Gleb Natapov wrote:
> > free_mmu_pages() should only undo what alloc_mmu_pages() does.
> >
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> > index 2a36f7f..b625ed4 100644
> > --- a/arch/x86/kvm/mmu.c
> > +++ b/arch/x86/kvm/mmu.c
> > @@ -2638,14 +2638,6 @@ EXPORT_SYMBOL_GPL(kvm_disable_tdp);
> >
> > static void free_mmu_pages(struct kvm_vcpu *vcpu)
> > {
> > - struct kvm_mmu_page *sp;
> > -
> > - while (!list_empty(&vcpu->kvm->arch.active_mmu_pages)) {
> > - sp = container_of(vcpu->kvm->arch.active_mmu_pages.next,
> > - struct kvm_mmu_page, link);
> > - kvm_mmu_zap_page(vcpu->kvm, sp);
> > - cond_resched();
> > - }
> > free_page((unsigned long)vcpu->arch.mmu.pae_root);
> > }
>
> Doesnt the vm shutdown path rely on the while loop you removed to free
> all shadow pages before freeing the mmu kmem caches, if mmu notifiers
> is disabled?
>
Shouldn't mmu_free_roots() on all vcpus clear all mmu pages?

> And how harmful is that loop? Zaps the entire cache on cpu hotunplug?
>
KVM doesn't support vcpu destruction, but destruction is called anyway
on various error conditions. The one that easy to trigger is to create
vcpu with the same id simultaneously from two threads. The result is
OOPs in random places.

--
Gleb.