aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 */