]> rtime.felk.cvut.cz Git - can-eth-gw-linux.git/commitdiff
KVM: Fix user memslot overlap check
authorAlex Williamson <alex.williamson@redhat.com>
Thu, 29 Nov 2012 21:07:59 +0000 (14:07 -0700)
committerMarcelo Tosatti <mtosatti@redhat.com>
Fri, 30 Nov 2012 01:30:32 +0000 (23:30 -0200)
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>
virt/kvm/kvm_main.c

index e6cfd4344d28fdf927b689983d45439224558d1a..1cd693a76a510c34a2d563d9fe68072802d28620 100644 (file)
@@ -714,8 +714,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
        int r;
        gfn_t base_gfn;
        unsigned long npages;
-       unsigned long i;
-       struct kvm_memory_slot *memslot;
+       struct kvm_memory_slot *memslot, *slot;
        struct kvm_memory_slot old, new;
        struct kvm_memslots *slots, *old_memslots;
 
@@ -766,13 +765,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
        /* Check for overlaps */
        r = -EEXIST;
-       for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
-               struct kvm_memory_slot *s = &kvm->memslots->memslots[i];
-
-               if (s == memslot || !s->npages)
+       kvm_for_each_memslot(slot, kvm->memslots) {
+               if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot)
                        continue;
-               if (!((base_gfn + npages <= s->base_gfn) ||
-                     (base_gfn >= s->base_gfn + s->npages)))
+               if (!((base_gfn + npages <= slot->base_gfn) ||
+                     (base_gfn >= slot->base_gfn + slot->npages)))
                        goto out_free;
        }