Skip to content

Commit c1d2ba1

Browse files
committed
lib/bitmap: drop optimization of bitmap_{from,to}_arr64
bitmap_{from,to}_arr64() optimization is overly optimistic on 32-bit LE architectures when it's wired to bitmap_copy_clear_tail(). bitmap_copy_clear_tail() takes care of unused bits in the bitmap up to the next word boundary. But on 32-bit machines when copying bits from bitmap to array of 64-bit words, it's expected that the unused part of a recipient array must be cleared up to 64-bit boundary, so the last 4 bytes may stay untouched when nbits % 64 <= 32. While the copying part of the optimization works correct, that clear-tail trick makes corresponding tests reasonably fail: test_bitmap: bitmap_to_arr64(nbits == 1): tail is not safely cleared: 0xa5a5a5a500000001 (must be 0x0000000000000001) Fix it by removing bitmap_{from,to}_arr64() optimization for 32-bit LE arches. Reported-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 0a97953 ("lib: add bitmap_{from,to}_arr64") Signed-off-by: Yury Norov <[email protected]> Tested-by: Guenter Roeck <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Alexander Lobakin <[email protected]>
1 parent c4c14c2 commit c1d2ba1

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

include/linux/bitmap.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,10 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap,
302302
#endif
303303

304304
/*
305-
* On 64-bit systems bitmaps are represented as u64 arrays internally. On LE32
306-
* machines the order of hi and lo parts of numbers match the bitmap structure.
307-
* In both cases conversion is not needed when copying data from/to arrays of
308-
* u64.
305+
* On 64-bit systems bitmaps are represented as u64 arrays internally. So,
306+
* the conversion is not needed when copying data from/to arrays of u64.
309307
*/
310-
#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
308+
#if BITS_PER_LONG == 32
311309
void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits);
312310
void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits);
313311
#else

lib/bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
14951495
EXPORT_SYMBOL(bitmap_to_arr32);
14961496
#endif
14971497

1498-
#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
1498+
#if BITS_PER_LONG == 32
14991499
/**
15001500
* bitmap_from_arr64 - copy the contents of u64 array of bits to bitmap
15011501
* @bitmap: array of unsigned longs, the destination bitmap

0 commit comments

Comments
 (0)