aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Honig <ahonig@google.com>2013-04-18 12:38:14 -0400
committerGleb Natapov <gleb@redhat.com>2013-04-22 04:02:38 -0400
commit27469d29b3caf889ddf81c7d89f0676e45eb551d (patch)
tree21692b39235a69d5605c1ce19460ac001bfec2fa
parentf1797359216c1daa145a354d07b8b2b7459668f4 (diff)
KVM: x86: Fix memory leak in vmx.c
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 free the memory. It's still possible for a user space process to leak memory if the last process to close the fd for the VM is not the process that created it. However, this is an unexpected case that's only caused by a user space process that's misbehaving. Signed-off-by: Andrew Honig <ahonig@google.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cbe16b4cad5c..e730a462ed05 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6859,6 +6859,23 @@ void kvm_arch_sync_events(struct kvm *kvm)
6859 6859
6860void kvm_arch_destroy_vm(struct kvm *kvm) 6860void kvm_arch_destroy_vm(struct kvm *kvm)
6861{ 6861{
6862 if (current->mm == kvm->mm) {
6863 /*
6864 * Free memory regions allocated on behalf of userspace,
6865 * unless the the memory map has changed due to process exit
6866 * or fd copying.
6867 */
6868 struct kvm_userspace_memory_region mem;
6869 memset(&mem, 0, sizeof(mem));
6870 mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
6871 kvm_set_memory_region(kvm, &mem);
6872
6873 mem.slot = IDENTITY_PAGETABLE_PRIVATE_MEMSLOT;
6874 kvm_set_memory_region(kvm, &mem);
6875
6876 mem.slot = TSS_PRIVATE_MEMSLOT;
6877 kvm_set_memory_region(kvm, &mem);
6878 }
6862 kvm_iommu_unmap_guest(kvm); 6879 kvm_iommu_unmap_guest(kvm);
6863 kfree(kvm->arch.vpic); 6880 kfree(kvm->arch.vpic);
6864 kfree(kvm->arch.vioapic); 6881 kfree(kvm->arch.vioapic);