aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorIzik Eidus <izike@qumranet.com>2007-10-25 05:54:04 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:55 -0500
commit80b14b5b32cb0a98234283daf9b5a6643e1a1ef3 (patch)
tree1abf719d18e5bcbb6ba7fd5b517bb70ebb8b1776 /drivers/kvm/kvm_main.c
parent5f43238d036fb30e73563e81e42d9c6f1de5551a (diff)
KVM: Unmap kernel-allocated memory on slot destruction
kvm_vm_ioctl_set_memory_region() is able to remove memory in addition to adding it. Therefore when using kernel swapping support for old userspaces, we need to munmap the memory if the user request to remove it Signed-off-by: Izik Eidus <izike@qumranet.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 453e98e251da..ab2c77c9ecef 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -713,6 +713,7 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
713 713
714 memset(new.rmap, 0, npages * sizeof(*new.rmap)); 714 memset(new.rmap, 0, npages * sizeof(*new.rmap));
715 715
716 new.user_alloc = user_alloc;
716 if (user_alloc) 717 if (user_alloc)
717 new.userspace_addr = mem->userspace_addr; 718 new.userspace_addr = mem->userspace_addr;
718 else { 719 else {
@@ -727,6 +728,19 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
727 if (IS_ERR((void *)new.userspace_addr)) 728 if (IS_ERR((void *)new.userspace_addr))
728 goto out_unlock; 729 goto out_unlock;
729 } 730 }
731 } else {
732 if (!old.user_alloc && old.rmap) {
733 int ret;
734
735 down_write(&current->mm->mmap_sem);
736 ret = do_munmap(current->mm, old.userspace_addr,
737 old.npages * PAGE_SIZE);
738 up_write(&current->mm->mmap_sem);
739 if (ret < 0)
740 printk(KERN_WARNING
741 "kvm_vm_ioctl_set_memory_region: "
742 "failed to munmap memory\n");
743 }
730 } 744 }
731 745
732 /* Allocate page dirty bitmap if needed */ 746 /* Allocate page dirty bitmap if needed */