Commit f0736cf0 authored by Alex Williamson's avatar Alex Williamson Committed by Marcelo Tosatti

KVM: Restrict non-existing slot state transitions

The API documentation states:

	When changing an existing slot, it may be moved in the guest
	physical memory space, or its flags may be modified.

An "existing slot" requires a non-zero npages (memory_size).  The only
transition we should therefore allow for a non-existing slot should be
to create the slot, which includes setting a non-zero memory_size.  We
currently allow calls to modify non-existing slots, which is pointless,
confusing, and possibly wrong.

With this we know that the invalidation path of __kvm_set_memory_region
is always for a delete or move and never for adding a zero size slot.
Reviewed-by: default avatarGleb Natapov <gleb@redhat.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent f3200d00
...@@ -758,10 +758,15 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -758,10 +758,15 @@ int __kvm_set_memory_region(struct kvm *kvm,
new.npages = npages; new.npages = npages;
new.flags = mem->flags; 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; r = -EINVAL;
if (npages && old.npages && npages != old.npages) if (npages && old.npages && npages != old.npages)
goto out_free; goto out_free;
if (!npages && !old.npages)
goto out_free;
/* Check for overlaps */ /* Check for overlaps */
r = -EEXIST; r = -EEXIST;
...@@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
r = -ENOMEM; r = -ENOMEM;
/* Allocate if a slot is being created */ /* Allocate if a slot is being created */
if (npages && !old.npages) { if (!old.npages) {
new.user_alloc = user_alloc; new.user_alloc = user_alloc;
new.userspace_addr = mem->userspace_addr; new.userspace_addr = mem->userspace_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment