All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Andrew Honig <ahonig@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCHv2] KVM: x86: Fix memory leak in vmx.c
Date: Thu, 18 Apr 2013 13:21:53 +0300	[thread overview]
Message-ID: <20130418102153.GB8911@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1304171052550.2545@ahonig-virtual-machine>

On Wed, Apr 17, 2013 at 10:54:32AM -0700, Andrew Honig wrote:
> 
> If userspace creates and destroys multiple VMs within the same process
> we leak 20k of memory in the userspace process context per VM.  This
> patch frees the memory in kvm_arch_destroy_vm.  If the process exits
> without closing the VM file descriptor or the file descriptor has been
> shared with another process then we don't need to free the memory.
> 
> Signed-off-by: Andrew Honig <ahonig@google.com>
> ---
>  arch/x86/kvm/x86.c |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index e172132..e93e16b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6811,6 +6811,23 @@ void kvm_arch_sync_events(struct kvm *kvm)
>  
>  void kvm_arch_destroy_vm(struct kvm *kvm)
>  {
> +	if (current->mm == kvm->mm) {
> +		/*
> +		 * Free memory regions allocated on behalf of userspace,
> +		 * unless the the memory map has changed due to process exit
> +		 * or fd copying.
> +		 */
> +		struct kvm_userspace_memory_region mem;
> +		memset(&mem, 0, sizeof(mem));
> +		mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
> +		kvm_set_memory_region(kvm, &mem, 0);
> +
> +		mem.slot = IDENTITY_PAGETABLE_PRIVATE_MEMSLOT;
> +		kvm_set_memory_region(kvm, &mem, 0);
> +
> +		mem.slot = TSS_PRIVATE_MEMSLOT;
> +		kvm_set_memory_region(kvm, &mem, 0);
You should code it against next branch. kvm_set_memory_region() has only
two parameters there.

> +	}
>  	kvm_iommu_unmap_guest(kvm);
>  	kfree(kvm->arch.vpic);
>  	kfree(kvm->arch.vioapic);
> -- 
> 1.7.10.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
			Gleb.

      parent reply	other threads:[~2013-04-18 10:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-17 17:54 [PATCHv2] KVM: x86: Fix memory leak in vmx.c Andrew Honig
2013-04-17 20:37 ` Eric Northup
2013-04-17 21:55 ` Paolo Bonzini
2013-04-17 23:03   ` Andrew Honig
2013-04-18  8:20     ` Paolo Bonzini
2013-04-18  8:50       ` Gleb Natapov
2013-04-18 10:21 ` Gleb Natapov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130418102153.GB8911@redhat.com \
    --to=gleb@redhat.com \
    --cc=ahonig@google.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.