From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 2/2] KVM: Fix kvm_free_physmem memory leak. Date: Sun, 26 Oct 2008 16:54:54 +0200 Message-ID: <490484BE.9050807@redhat.com> References: <6ad07c640810230629x1ed57744xf636d6b73c0e215a@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: =?ISO-8859-1?Q?Fran=E7ois_Diakhate?= Return-path: Received: from mx2.redhat.com ([66.187.237.31]:49860 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753403AbYJZOzD (ORCPT ); Sun, 26 Oct 2008 10:55:03 -0400 In-Reply-To: <6ad07c640810230629x1ed57744xf636d6b73c0e215a@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: =46ran=E7ois Diakhate wrote: > Make sure that kvm_free_physmem actually frees memory > when a memory slot is not user allocated. > > @@ -4195,7 +4195,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm, > memslot->userspace_addr =3D userspace_addr; > spin_unlock(&kvm->mmu_lock); > } else { > - if (!old.user_alloc && old.rmap) { > + if (!old.user_alloc && old.rmap && current->mm) { > int ret; > > =20 What's the purpose of this? > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index a87f45e..b0d7435 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -639,8 +639,17 @@ void kvm_free_physmem(struct kvm *kvm) > { > int i; > > - for (i =3D 0; i < kvm->nmemslots; ++i) > + for (i =3D 0; i < kvm->nmemslots; ++i) { > + struct kvm_userspace_memory_region mem =3D { > + .slot =3D i, > + .guest_phys_addr =3D kvm->memslots[i].base_gfn << PAGE_SHIFT, > + .memory_size =3D 0, > + .flags =3D 0, > + }; > + > + kvm_set_memory_region(kvm, &mem, kvm->memslots[i].user_alloc); > kvm_free_physmem_slot(&kvm->memslots[i], NULL); > + } > } > =20 Better to fix kvm_free_physmem_slot() if it doesn't handle=20 !user_allocated memory properly. --=20 error compiling committee.c: too many arguments to function