kvm: warn on more invariant breakage
authorPaolo Bonzini <pbonzini@redhat.com>
Sat, 27 Dec 2014 20:08:16 +0000 (21:08 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 28 Dec 2014 09:01:25 +0000 (10:01 +0100)
Modifying a non-existent slot is not allowed.  Also check that the
first loop doesn't move a deleted slot beyond the used part of
the mslots array.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c

index 050974c051b5a9369a88926750885cd6f125a8f2..1cc6e2e199827093093e6c48eab72c6531136a13 100644 (file)
@@ -671,6 +671,7 @@ static void update_memslots(struct kvm_memslots *slots,
 
        WARN_ON(mslots[i].id != id);
        if (!new->npages) {
+               WARN_ON(!mslots[i].npages);
                new->base_gfn = 0;
                if (mslots[i].npages)
                        slots->used_slots--;
@@ -704,7 +705,8 @@ static void update_memslots(struct kvm_memslots *slots,
                        slots->id_to_index[mslots[i].id] = i;
                        i--;
                }
-       }
+       } else
+               WARN_ON_ONCE(i != slots->used_slots);
 
        mslots[i] = *new;
        slots->id_to_index[mslots[i].id] = i;