summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorIzik Eidus <izike@qumranet.com>2007-10-25 11:54:04 +0200
committerAvi Kivity <avi@qumranet.com>2008-01-30 17:52:55 +0200
commit80b14b5b32cb0a98234283daf9b5a6643e1a1ef3 (patch)
tree1abf719d18e5bcbb6ba7fd5b517bb70ebb8b1776 /drivers
parent5f43238d036fb30e73563e81e42d9c6f1de5551a (diff)
downloadlwn-80b14b5b32cb0a98234283daf9b5a6643e1a1ef3.tar.gz
lwn-80b14b5b32cb0a98234283daf9b5a6643e1a1ef3.zip
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')
-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 {
unsigned long *rmap;
unsigned long *dirty_bitmap;
unsigned long userspace_addr;
+ int user_alloc;
};
struct 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,
memset(new.rmap, 0, npages * sizeof(*new.rmap));
+ new.user_alloc = user_alloc;
if (user_alloc)
new.userspace_addr = mem->userspace_addr;
else {
@@ -727,6 +728,19 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
if (IS_ERR((void *)new.userspace_addr))
goto out_unlock;
}
+ } else {
+ if (!old.user_alloc && old.rmap) {
+ int ret;
+
+ down_write(&current->mm->mmap_sem);
+ ret = do_munmap(current->mm, old.userspace_addr,
+ old.npages * PAGE_SIZE);
+ up_write(&current->mm->mmap_sem);
+ if (ret < 0)
+ printk(KERN_WARNING
+ "kvm_vm_ioctl_set_memory_region: "
+ "failed to munmap memory\n");
+ }
}
/* Allocate page dirty bitmap if needed */