lib/test_bitmap: increment failure counter properly
Subsystems (4)
Yury Norov
maintainerPATCH 1/2 lib/test_bitmap: increment failure counter properly
The tests that don't use expect_eq() macro to determine that a test is failured must increment failed_tests explicitly.
--- lib/test_bitmap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
lib/test_bitmap.c +15 -3
@@ -471,6 +471,7 @@ static void __init test_bitmap_parselist(void)if (err != ptest.errno) {pr_err ("parselist: %d: input is %s, errno is %d, expected %d\n" , i, ptest.in, err, ptest.errno); + failed_tests++;continue ; }
@@ -479,6 +480,7 @@ static void __init test_bitmap_parselist(void)pr_err ("parselist: %d: input is %s, result is 0x%lx, expected 0x%lx\n" , i, ptest.in, bmap[0 ], *ptest.expected); + failed_tests++;continue ; }
@@ -512,11 +514,13 @@ static void __init test_bitmap_printlist(void)if (ret != slen +1 ) {pr_err ("bitmap_print_to_pagebuf: result is %d, expected %d\n" , ret, slen); + failed_tests++; goto out; }if (strncmp (buf, expected, slen)) {pr_err ("bitmap_print_to_pagebuf: result is %s, expected %s\n" , buf, expected); + failed_tests++; goto out; }
@@ -584,6 +588,7 @@ static void __init test_bitmap_parse(void)if (err != test.errno) {pr_err ("parse: %d: input is %s, errno is %d, expected %d\n" , i, test.in, err, test.errno); + failed_tests++;continue ; }
@@ -592,6 +597,7 @@ static void __init test_bitmap_parse(void)pr_err ("parse: %d: input is %s, result is 0x%lx, expected 0x%lx\n" , i, test.in, bmap[0 ], *test.expected); + failed_tests++;continue ; }
@@ -616,10 +622,12 @@ static void __init test_bitmap_arr32(void) next_bit =find_next_bit (bmap2,round_up (nbits,BITS_PER_LONG ), nbits); -if (next_bit <round_up (nbits,BITS_PER_LONG )) +if (next_bit <round_up (nbits,BITS_PER_LONG )) {pr_err ("bitmap_copy_arr32(nbits == %d:" " tail is not safely cleared: %d\n" , nbits, next_bit); + failed_tests++; + }if (nbits <EXP1_IN_BITS -32 ) expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
@@ -642,15 +650,19 @@ static void __init test_bitmap_arr64(void)expect_eq_bitmap (bmap2, exp1, nbits); next_bit =find_next_bit (bmap2,round_up (nbits,BITS_PER_LONG ), nbits); -if (next_bit <round_up (nbits,BITS_PER_LONG )) +if (next_bit <round_up (nbits,BITS_PER_LONG )) {pr_err ("bitmap_copy_arr64(nbits == %d:" " tail is not safely cleared: %d\n" , nbits, next_bit); + failed_tests++; + }if ((nbits %64 ) && - (arr[(nbits -1 ) /64 ] & ~GENMASK_ULL ((nbits -1 ) %64 ,0 ))) + (arr[(nbits -1 ) /64 ] & ~GENMASK_ULL ((nbits -1 ) %64 ,0 ))) {pr_err ("bitmap_to_arr64(nbits == %d): tail is not safely cleared: 0x%016llx (must be 0x%016llx)\n" , nbits, arr[(nbits -1 ) /64 ],GENMASK_ULL ((nbits -1 ) %64 ,0 )); + failed_tests++; + }if (nbits <EXP1_IN_BITS -64 )expect_eq_uint (arr[DIV_ROUND_UP (nbits,64 )],0xa5a5a5a5 );
Signature · 1 line
2.34.1
Yury Norov
maintainerPATCH 2/2 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.
--- include/linux/bitmap.h | 8 +++----- lib/bitmap.c | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-)
include/linux/bitmap.h +3 -5
@@ -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
lib/bitmap.c +1 -1
@@ -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
Signature · 1 line
2.34.1
Re: [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64
From: Yury Norov <[email protected]>
Date: Mon, 27 Feb 2023 13:45:24 -0800
Quoted 52 lines
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 be0x0000000000000001)Fix it by removing bitmap_{from,to}_arr64() optimization for 32-bit LE arches.
Reported-by Guenter Roeck <[email protected]>Fixes 0a97953fd221 ("lib: add bitmap_{from,to}_arr64")Signed-off-by Yury Norov <[email protected]>Tested-by Guenter Roeck <[email protected]>--- include/linux/bitmap.h | 8 +++----- lib/bitmap.c | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-)include/linux/bitmap.h +3
-5@@ -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 lib/bitmap.c +0
-0
lib/bitmap.c void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits) · line 1501
Quoted 8 lines
lib/bitmap.c +1
-1@@ -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
For the series:
Thanks,
Olek
Quoted 2 lines · Yury Norov
The tests that don't use
expect_eq()macro to determine that a test is failured must incrementfailed_testsexplicitly.
...
lib/test_bitmap.c static void __init test_bitmap_arr32(void) · line 627
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err("bitmap_copy_arr32(nbits == %d:" " tail is not safely cleared: %d\n",
Usually we don't split string literals (since checkpatch doesn't complain on a looong lines with them at the end of the line),
...
lib/test_bitmap.c static void __init test_bitmap_arr64(void) · line 655
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err ("bitmap_copy_arr64(nbits == %d:" " tail is not safely cleared: %d\n" , nbits, next_bit);
Ditto.
P.S. Seems a material for another patch.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Yury Norov
maintainerQuoted 12 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
The tests that don't use
expect_eq()macro to determine that a test is failured must incrementfailed_testsexplicitly....
lib/test_bitmap.c static void __init test_bitmap_arr32(void) · line 627
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err("bitmap_copy_arr32(nbits == %d:" " tail is not safely cleared: %d\n",Usually we don't split string literals (since checkpatch doesn't complain on a looong lines with them at the end of the line),
Quoted 8 lines
...
lib/test_bitmap.c static void __init test_bitmap_arr64(void) · line 655
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err ("bitmap_copy_arr64(nbits == %d:" " tail is not safely cleared: %d\n" , nbits, next_bit);Ditto.
P.S. Seems a material for another patch.
If you're OK with this patch, can you give your review tag please?
Thanks,
Yury
Andy Shevchenko
Reviewed-byQuoted 15 lines · Yury Norov
Quoted 14 lines · Andy Shevchenko
Quoted 2 lines · Yury Norov
The tests that don't use
expect_eq()macro to determine that a test is failured must incrementfailed_testsexplicitly....
lib/test_bitmap.c static void __init test_bitmap_arr32(void) · line 627
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err("bitmap_copy_arr32(nbits == %d:" " tail is not safely cleared: %d\n",Usually we don't split string literals (since checkpatch doesn't complain on a looong lines with them at the end of the line),
...
Quoted 8 lines
Quoted 6 lines
lib/test_bitmap.c static void __init test_bitmap_arr64(void) · line 655
Quoted 2 lines
lib/test_bitmap.c +0
-0pr_err ("bitmap_copy_arr64(nbits == %d:" " tail is not safely cleared: %d\n" , nbits, next_bit);Ditto.
P.S. Seems a material for another patch.If you're OK with this patch, can you give your review tag please?
I'm fine with the series,
Signature · 2 lines
With Best Regards, Andy Shevchenko