kvm: fix sorting of memslots with base_gfn == 0
authorPaolo Bonzini <[email protected]>
Sat, 27 Dec 2014 17:01:00 +0000 (18:01 +0100)
committerPaolo Bonzini <[email protected]>
Sun, 28 Dec 2014 09:01:17 +0000 (10:01 +0100)
commitefbeec7098eee2b3d2359d0cc24bbba0436e7f21
tree6b90f8b272f263d093b2f40a3aa471030616bbe1
parenta629df7eadffb03e6ce4a8616e62ea29fdf69b6b
kvm: fix sorting of memslots with base_gfn == 0

Before commit 0e60b0799fed (kvm: change memslot sorting rule from size
to GFN, 2014-12-01), the memslots' sorting key was npages, meaning
that a valid memslot couldn't have its sorting key equal to zero.
On the other hand, a valid memslot can have base_gfn == 0, and invalid
memslots are identified by base_gfn == npages == 0.

Because of this, commit 0e60b0799fed broke the invariant that invalid
memslots are at the end of the mslots array.  When a memslot with
base_gfn == 0 was created, any invalid memslot before it were left
in place.

This can be fixed by changing the insertion to use a ">=" comparison
instead of "<=", but some care is needed to avoid breaking the case
of deleting a memslot; see the comment in update_memslots.

Thanks to Tiejun Chen for posting an initial patch for this bug.

Reported-by: Jamie Heilman <[email protected]>
Reported-by: Andy Lutomirski <[email protected]>
Tested-by: Jamie Heilman <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
virt/kvm/kvm_main.c