* [PATCH 1/2] lib/test_bitmap: increment failure counter properly
@ 2023-02-27 21:45 Yury Norov
2023-02-27 21:45 ` [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64 Yury Norov
2023-02-27 22:55 ` [PATCH 1/2] lib/test_bitmap: increment failure counter properly Andy Shevchenko
0 siblings, 2 replies; 6+ messages in thread
From: Yury Norov @ 2023-02-27 21:45 UTC (permalink / raw)
To: linux-kernel, Alexander Gordeev, Alexander Lobakin,
Andy Shevchenko, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Guenter Roeck, Heiko Carstens, Janosch Frank,
Rasmus Villemoes, Sven Schnelle, Vasily Gorbik, linux-s390, kvm
Cc: Yury Norov
The tests that don't use expect_eq() macro to determine that a test is
failured must increment failed_tests explicitly.
Reported-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/lkml/20230225184702.GA3587246@roeck-us.net/
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
lib/test_bitmap.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 8954610ec683..c4b90d145398 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64
2023-02-27 21:45 [PATCH 1/2] lib/test_bitmap: increment failure counter properly Yury Norov
@ 2023-02-27 21:45 ` Yury Norov
2023-02-28 10:45 ` Alexander Lobakin
2023-02-27 22:55 ` [PATCH 1/2] lib/test_bitmap: increment failure counter properly Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Yury Norov @ 2023-02-27 21:45 UTC (permalink / raw)
To: linux-kernel, Alexander Gordeev, Alexander Lobakin,
Andy Shevchenko, Christian Borntraeger, Claudio Imbrenda,
David Hildenbrand, Guenter Roeck, Heiko Carstens, Janosch Frank,
Rasmus Villemoes, Sven Schnelle, Vasily Gorbik, linux-s390, kvm
Cc: Yury Norov
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@roeck-us.net>
Link: https://lore.kernel.org/lkml/20230225184702.GA3587246@roeck-us.net/
Fixes: 0a97953fd221 ("lib: add bitmap_{from,to}_arr64")
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
---
include/linux/bitmap.h | 8 +++-----
lib/bitmap.c | 2 +-
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 40e53a2ecc0d..7d4c90eb3df4 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 1c81413c51f8..ddb31015e38a 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
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64
2023-02-27 21:45 ` [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64 Yury Norov
@ 2023-02-28 10:45 ` Alexander Lobakin
0 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2023-02-28 10:45 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, Alexander Gordeev, Andy Shevchenko,
Christian Borntraeger, Claudio Imbrenda, David Hildenbrand,
Guenter Roeck, Heiko Carstens, Janosch Frank, Rasmus Villemoes,
Sven Schnelle, Vasily Gorbik, linux-s390, kvm
From: Yury Norov <yury.norov@gmail.com>
Date: Mon, 27 Feb 2023 13:45:24 -0800
> 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@roeck-us.net>
> Link: https://lore.kernel.org/lkml/20230225184702.GA3587246@roeck-us.net/
> Fixes: 0a97953fd221 ("lib: add bitmap_{from,to}_arr64")
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> ---
> include/linux/bitmap.h | 8 +++-----
> lib/bitmap.c | 2 +-
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 40e53a2ecc0d..7d4c90eb3df4 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 1c81413c51f8..ddb31015e38a 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
For the series:
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Thanks,
Olek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] lib/test_bitmap: increment failure counter properly
2023-02-27 21:45 [PATCH 1/2] lib/test_bitmap: increment failure counter properly Yury Norov
2023-02-27 21:45 ` [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64 Yury Norov
@ 2023-02-27 22:55 ` Andy Shevchenko
2023-02-28 2:49 ` Yury Norov
1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2023-02-27 22:55 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, Alexander Gordeev, Alexander Lobakin,
Christian Borntraeger, Claudio Imbrenda, David Hildenbrand,
Guenter Roeck, Heiko Carstens, Janosch Frank, Rasmus Villemoes,
Sven Schnelle, Vasily Gorbik, linux-s390, kvm
On Mon, Feb 27, 2023 at 01:45:23PM -0800, Yury Norov wrote:
> The tests that don't use expect_eq() macro to determine that a test is
> failured must increment failed_tests explicitly.
...
> pr_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),
...
> pr_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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] lib/test_bitmap: increment failure counter properly
2023-02-27 22:55 ` [PATCH 1/2] lib/test_bitmap: increment failure counter properly Andy Shevchenko
@ 2023-02-28 2:49 ` Yury Norov
2023-03-01 15:11 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2023-02-28 2:49 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Alexander Gordeev, Alexander Lobakin,
Christian Borntraeger, Claudio Imbrenda, David Hildenbrand,
Guenter Roeck, Heiko Carstens, Janosch Frank, Rasmus Villemoes,
Sven Schnelle, Vasily Gorbik, linux-s390, kvm
On Tue, Feb 28, 2023 at 12:55:05AM +0200, Andy Shevchenko wrote:
> On Mon, Feb 27, 2023 at 01:45:23PM -0800, Yury Norov wrote:
> > The tests that don't use expect_eq() macro to determine that a test is
> > failured must increment failed_tests explicitly.
>
> ...
>
> > pr_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),
>
> ...
>
> > pr_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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] lib/test_bitmap: increment failure counter properly
2023-02-28 2:49 ` Yury Norov
@ 2023-03-01 15:11 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-03-01 15:11 UTC (permalink / raw)
To: Yury Norov
Cc: linux-kernel, Alexander Gordeev, Alexander Lobakin,
Christian Borntraeger, Claudio Imbrenda, David Hildenbrand,
Guenter Roeck, Heiko Carstens, Janosch Frank, Rasmus Villemoes,
Sven Schnelle, Vasily Gorbik, linux-s390, kvm
On Mon, Feb 27, 2023 at 06:49:29PM -0800, Yury Norov wrote:
> On Tue, Feb 28, 2023 at 12:55:05AM +0200, Andy Shevchenko wrote:
> > On Mon, Feb 27, 2023 at 01:45:23PM -0800, Yury Norov wrote:
> > > The tests that don't use expect_eq() macro to determine that a test is
> > > failured must increment failed_tests explicitly.
> >
> > ...
> >
> > > pr_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),
> >
> > ...
> >
> > > pr_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,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-01 15:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-27 21:45 [PATCH 1/2] lib/test_bitmap: increment failure counter properly Yury Norov
2023-02-27 21:45 ` [PATCH 2/2] lib/bitmap: drop optimization of bitmap_{from,to}_arr64 Yury Norov
2023-02-28 10:45 ` Alexander Lobakin
2023-02-27 22:55 ` [PATCH 1/2] lib/test_bitmap: increment failure counter properly Andy Shevchenko
2023-02-28 2:49 ` Yury Norov
2023-03-01 15:11 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox