x86+Arm32: make find_next_{,zero_}bit() have well defined behavior
authorJan Beulich <jbeulich@suse.com>
Wed, 11 Dec 2019 13:06:18 +0000 (14:06 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 11 Dec 2019 13:06:18 +0000 (14:06 +0100)
commit7442006b9f0940fb36f1f8470a416ec836e0d2ce
treef84b1b257f4ded813ceb623243b241415f5a2c88
parent0b65f0a42894a796aff8f5c67ac2d156ff6c03af
x86+Arm32: make find_next_{,zero_}bit() have well defined behavior

These functions getting used with the 2nd and 3rd arguments being equal
wasn't well defined: Arm64 reliably returns the value of the 2nd
argument in this case, while on x86 for bitmaps up to 64 bits wide the
return value was undefined (due to the undefined behavior of a shift of
a value by the number of bits it's wide) when the incoming value was 64.
On Arm32 an actual out of bounds access would happen when the
size/offset value is a multiple of 32; if this access doesn't fault, the
return value would have been sufficiently correct afaict.

Make the functions consistently tolerate the last two arguments being
equal (and in fact the 3rd argument being greater or equal to the 2nd),
in favor of finding and fixing all the use sites that violate the
original more strict assumption.

This is XSA-307.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien@xen.org>
xen/arch/arm/arm32/lib/findbit.S
xen/include/asm-x86/bitops.h