diff options
author | Alex Williamson <alex.williamson@redhat.com> | 2012-12-10 12:32:45 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2012-12-13 20:21:50 -0500 |
commit | f0736cf0550b349a5d5a374d65ca0488cc2eee40 (patch) | |
tree | d72fbc1acd03c5047961bcfb5d4063137a392384 /virt/kvm/kvm_main.c | |
parent | f3200d00ea42e485772ff92d6d649aa8eeb640c0 (diff) |
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: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 9 |
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, | |||
758 | new.npages = npages; | 758 | new.npages = npages; |
759 | new.flags = mem->flags; | 759 | new.flags = mem->flags; |
760 | 760 | ||
761 | /* Disallow changing a memory slot's size. */ | 761 | /* |
762 | * Disallow changing a memory slot's size or changing anything about | ||
763 | * zero sized slots that doesn't involve making them non-zero. | ||
764 | */ | ||
762 | r = -EINVAL; | 765 | r = -EINVAL; |
763 | if (npages && old.npages && npages != old.npages) | 766 | if (npages && old.npages && npages != old.npages) |
764 | goto out_free; | 767 | goto out_free; |
768 | if (!npages && !old.npages) | ||
769 | goto out_free; | ||
765 | 770 | ||
766 | /* Check for overlaps */ | 771 | /* Check for overlaps */ |
767 | r = -EEXIST; | 772 | r = -EEXIST; |
@@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
780 | r = -ENOMEM; | 785 | r = -ENOMEM; |
781 | 786 | ||
782 | /* Allocate if a slot is being created */ | 787 | /* Allocate if a slot is being created */ |
783 | if (npages && !old.npages) { | 788 | if (!old.npages) { |
784 | new.user_alloc = user_alloc; | 789 | new.user_alloc = user_alloc; |
785 | new.userspace_addr = mem->userspace_addr; | 790 | new.userspace_addr = mem->userspace_addr; |
786 | 791 | ||