memory: don't depend on guest_handle_subrange_okay() implementation details
authorJan Beulich <jbeulich@suse.com>
Thu, 6 Jun 2019 14:03:10 +0000 (16:03 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 6 Jun 2019 14:03:10 +0000 (16:03 +0200)
commit3b537c692361579b1c4e4108fc497dae8d0dcd86
tree087f217dfd28c46804c36febfcf35f26da857d7a
parent7177f589ba84433e1ca8bb97a5d074545133c49c
memory: don't depend on guest_handle_subrange_okay() implementation details

guest_handle_subrange_okay() takes inclusive first and last parameters,
i.e. checks that [first, last] is valid. Many callers, however, actually
need to see whether [first, limit) is valid (i.e., limit is non-
inclusive), and to do this they subtract 1 from the size. This is
normally correct, except in cases where first == limit, in which case
guest_handle_subrange_okay() will be passed a second parameter less than
its first.

As it happens, due to the way the math is implemented in x86's
guest_handle_subrange_okay(), the return value turns out to be correct;
but we shouldn\92t rely on this behavior.

Make sure all callers handle first == limit explicitly before calling
guest_handle_subrange_okay().

Note that the other uses (increase-reservation, populate-physmap, and
decrease-reservation) are already fine due to a suitable check in
do_memory_op().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
xen/common/memory.c