aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm
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
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')
-rw-r--r--drivers/kvm/kvm.h1
-rw-r--r--drivers/kvm/kvm_main.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index f7181a407be1..12de42c789a2 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -353,6 +353,7 @@ struct kvm_memory_slot {
353 unsigned long *rmap; 353 unsigned long *rmap;
354 unsigned long *dirty_bitmap; 354 unsigned long *dirty_bitmap;
355 unsigned long userspace_addr; 355 unsigned long userspace_addr;
356 int user_alloc;
356}; 357};
357 358
358struct kvm { 359struct kvm {
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 */