aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2012-11-29 16:07:59 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2012-11-29 20:30:32 -0500
commit5419369ed6bd4cf711fdda5e52a5999b940413f5 (patch)
tree723920e638aa5adadf5252121b7126e1ad125a44 /virt
parent5a560f8b5ed361c7be783d5a671ea26ca4d6fa01 (diff)
KVM: Fix user memslot overlap check
Prior to memory slot sorting this loop compared all of the user memory slots for overlap with new entries. With memory slot sorting, we're just checking some number of entries in the array that may or may not be user slots. Instead, walk all the slots with kvm_for_each_memslot, which has the added benefit of terminating early when we hit the first empty slot, and skip comparison to private slots. Cc: stable@vger.kernel.org Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e6cfd4344d28..1cd693a76a51 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -714,8 +714,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
714 int r; 714 int r;
715 gfn_t base_gfn; 715 gfn_t base_gfn;
716 unsigned long npages; 716 unsigned long npages;
717 unsigned long i; 717 struct kvm_memory_slot *memslot, *slot;
718 struct kvm_memory_slot *memslot;
719 struct kvm_memory_slot old, new; 718 struct kvm_memory_slot old, new;
720 struct kvm_memslots *slots, *old_memslots; 719 struct kvm_memslots *slots, *old_memslots;
721 720
@@ -766,13 +765,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
766 765
767 /* Check for overlaps */ 766 /* Check for overlaps */
768 r = -EEXIST; 767 r = -EEXIST;
769 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { 768 kvm_for_each_memslot(slot, kvm->memslots) {
770 struct kvm_memory_slot *s = &kvm->memslots->memslots[i]; 769 if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot)
771
772 if (s == memslot || !s->npages)
773 continue; 770 continue;
774 if (!((base_gfn + npages <= s->base_gfn) || 771 if (!((base_gfn + npages <= slot->base_gfn) ||
775 (base_gfn >= s->base_gfn + s->npages))) 772 (base_gfn >= slot->base_gfn + slot->npages)))
776 goto out_free; 773 goto out_free;
777 } 774 }
778 775