summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--virt/kvm/kvm_main.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1cd693a76a51..3caf8162eb6b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -758,10 +758,15 @@ int __kvm_set_memory_region(struct kvm *kvm,
new.npages = npages;
new.flags = mem->flags;
- /* Disallow changing a memory slot's size. */
+ /*
+ * Disallow changing a memory slot's size or changing anything about
+ * zero sized slots that doesn't involve making them non-zero.
+ */
r = -EINVAL;
if (npages && old.npages && npages != old.npages)
goto out_free;
+ if (!npages && !old.npages)
+ goto out_free;
/* Check for overlaps */
r = -EEXIST;
@@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
r = -ENOMEM;
/* Allocate if a slot is being created */
- if (npages && !old.npages) {
+ if (!old.npages) {
new.user_alloc = user_alloc;
new.userspace_addr = mem->userspace_addr;