Patch "lib/bitmap: drop optimization of bitmap_{from,to}_arr64" has been added to the 6.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    lib/bitmap: drop optimization of bitmap_{from,to}_arr64

to the 6.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     lib-bitmap-drop-optimization-of-bitmap_-from-to-_arr.patch
and it can be found in the queue-6.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 652c15b135e8e0e0922f7097ec5eebbed6966040
Author: Yury Norov <yury.norov@xxxxxxxxx>
Date:   Mon Feb 27 11:24:36 2023 -0800

    lib/bitmap: drop optimization of bitmap_{from,to}_arr64
    
    [ Upstream commit c1d2ba10f594046831d14b03f194e8d05e78abad ]
    
    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 <linux@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/lkml/20230225184702.GA3587246@xxxxxxxxxxxx/
    Fixes: 0a97953fd221 ("lib: add bitmap_{from,to}_arr64")
    Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
    Tested-by: Guenter Roeck <linux@xxxxxxxxxxxx>
    Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
    Reviewed-by: Alexander Lobakin <aleksander.lobakin@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 7d6d73b781472..03644237e1efb 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -302,12 +302,10 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap,
 #endif
 
 /*
- * On 64-bit systems bitmaps are represented as u64 arrays internally. On LE32
- * machines the order of hi and lo parts of numbers match the bitmap structure.
- * In both cases conversion is not needed when copying data from/to arrays of
- * u64.
+ * On 64-bit systems bitmaps are represented as u64 arrays internally. So,
+ * the conversion is not needed when copying data from/to arrays of u64.
  */
-#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
+#if BITS_PER_LONG == 32
 void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits);
 void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits);
 #else
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 1c81413c51f86..ddb31015e38ae 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1495,7 +1495,7 @@ void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits)
 EXPORT_SYMBOL(bitmap_to_arr32);
 #endif
 
-#if (BITS_PER_LONG == 32) && defined(__BIG_ENDIAN)
+#if BITS_PER_LONG == 32
 /**
  * bitmap_from_arr64 - copy the contents of u64 array of bits to bitmap
  *	@bitmap: array of unsigned longs, the destination bitmap



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux