Skip to content

Commit

Permalink
kvm: warn on more invariant breakage
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bonzini committed Dec 28, 2014
1 parent efbeec7 commit dbaff30
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dbaff30

Please sign in to comment.