From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Honig Subject: Memory leak in vmx.c Date: Fri, 7 Dec 2012 14:51:38 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 To: kvm@vger.kernel.org Return-path: Received: from mail-ia0-f173.google.com ([209.85.210.173]:35536 "EHLO mail-ia0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750971Ab2LGT76 (ORCPT ); Fri, 7 Dec 2012 14:59:58 -0500 Received: by mail-ia0-f173.google.com with SMTP id w21so1449492iac.32 for ; Fri, 07 Dec 2012 11:59:57 -0800 (PST) Sender: kvm-owner@vger.kernel.org List-ID: I've noticed a memory leak that occurs in vmx.c. In alloc_apic_access_page, it calls __kvm_set_memory_region(kvm, &kvm_userspace_mem, 0). __kvm_set_memory_region calls kvm_arch_prepare_memory_region, which because the user_alloc parameter is 0 will allocate memory for the page with vm_mmap. This memory never gets freed. In kvm_arch_destroy_vm it calls put_page(kvm->arch.apic_access_page), but that only unpins the memory (necessary due to an earlier call to gfn_to_page), it never actually frees the memory. The memory is allocated in the current process context so it's cleaned up when the process exits, but if a process creates and destroys multiple VMs then this leak starts to become a problem. Similar leaks occur in alloc_identity_pagetable and vmx_set_tss_addr for a total of 5 pages of memory leak for a VM. The vmx_set_tss_addr actually leaks each time vmx_set_tss_addr is called so this could also become a problem if a program had occasion to set the tss addr several times. thanks, Andy