* [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
@ 2017-10-25 6:57 Paul Mackerras
2017-10-25 7:39 ` Matthew Wilcox
0 siblings, 1 reply; 8+ messages in thread
From: Paul Mackerras @ 2017-10-25 6:57 UTC (permalink / raw)
To: Matthew Wilcox, Linus Torvalds, lkml; +Cc: linuxppc-dev, linux-s390
Commit 2a98dc028f91 ("include/linux/bitmap.h: turn bitmap_set and
bitmap_clear into memset when possible", 2017-07-10) added an
optimization which effectively assumes that a contiguous set of
bits in a bitmap will be stored in a contiguous set of bytes of
the bitmap, in the case where the starting bit number and number of
bits are multiples of 8. This is true for a little-endian
representation, but not for a big-endian representation, because we
number the bits of a long from right to left for both little-endian
and big-endian representations.
The optimization can still be done for big-endian platforms, but
only if the starting bit number and number of bits are multiples
of BITS_PER_LONG. This adjusts the code to use 8 for little-endian
and BITS_PER_LONG for big-endian platforms.
Cc: stable@vger.kernel.org # v4.13
Fixes: 2a98dc028f91 ("include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible")
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
This was found by inspection.
I'm pretty sure commit 2c6deb01525a is wrong as well on big-endian
machines.
include/linux/bitmap.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 700cf5f..44e2eb4 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -174,8 +174,10 @@ extern unsigned int bitmap_to_u32array(u32 *buf,
unsigned int nbits);
#ifdef __BIG_ENDIAN
extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits);
+#define BITMAP_MIN_UNIT BITS_PER_LONG /* have to access as longs */
#else
#define bitmap_copy_le bitmap_copy
+#define BITMAP_MIN_UNIT 8 /* can access as bytes if desired */
#endif
extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits);
extern int bitmap_print_to_pagebuf(bool list, char *buf,
@@ -317,8 +319,10 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
{
if (__builtin_constant_p(nbits) && nbits == 1)
__set_bit(start, map);
- else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
- __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
+ else if (__builtin_constant_p(start & (BITMAP_MIN_UNIT-1)) &&
+ IS_ALIGNED(start, BITMAP_MIN_UNIT) &&
+ __builtin_constant_p(nbits & (BITMAP_MIN_UNIT-1)) &&
+ IS_ALIGNED(nbits, BITMAP_MIN_UNIT))
memset((char *)map + start / 8, 0xff, nbits / 8);
else
__bitmap_set(map, start, nbits);
@@ -329,8 +333,10 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
{
if (__builtin_constant_p(nbits) && nbits == 1)
__clear_bit(start, map);
- else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
- __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
+ else if (__builtin_constant_p(start & (BITMAP_MIN_UNIT-1)) &&
+ IS_ALIGNED(start, BITMAP_MIN_UNIT) &&
+ __builtin_constant_p(nbits & (BITMAP_MIN_UNIT-1)) &&
+ IS_ALIGNED(nbits, BITMAP_MIN_UNIT))
memset((char *)map + start / 8, 0, nbits / 8);
else
__bitmap_clear(map, start, nbits);
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
2017-10-25 6:57 [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines Paul Mackerras
@ 2017-10-25 7:39 ` Matthew Wilcox
2017-10-25 8:46 ` Paul Mackerras
0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2017-10-25 7:39 UTC (permalink / raw)
To: Paul Mackerras, Linus Torvalds, lkml; +Cc: linuxppc-dev, linux-s390
SGFuZyBvbiwgZG9uJ3QgdGVsbCBtZSB5b3UgZm91bmQgdGhpcyB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iaXRz
KTsNCj4gLS0NCj4gMi43LjQNCg0K
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
2017-10-25 7:39 ` Matthew Wilcox
@ 2017-10-25 8:46 ` Paul Mackerras
2017-10-25 9:11 ` Matthew Wilcox
2017-10-25 10:30 ` Michael Ellerman
0 siblings, 2 replies; 8+ messages in thread
From: Paul Mackerras @ 2017-10-25 8:46 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Linus Torvalds, linux-kernel, linuxppc-dev, linux-s390
On Wed, Oct 25, 2017 at 07:39:48AM +0000, Matthew Wilcox wrote:
> Hang on, don't tell me you found this by inspection. Are you not running the bitmap testcase, enabled by CONFIG_TEST_BITMAP? Either that should be producing an error, or there's a missing test case, or your inspection is wrong ...
I did find it by inspection. I was looking for a version of the
bitmap_* API that does little-endian style bitmaps on all systems, and
the inline bitmap_set() does that in the case where it calls memset,
but not in the case where it calls __bitmap_set.
I'll fire up a big-endian system tomorrow when I get to work to run
the test case. (PPC64 is almost entirely little-endian these days as
far as the IBM POWER systems are concerned.)
In any case, it's pretty clearly wrong as it is. On a big-endian
64-bit system, bitmap_set(p, 56, 16) should set bytes 0 and 15 to
0xff, and there's no way a single memset can do that.
Paul.
(and yes, I stuffed up the address for lkml)
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
2017-10-25 8:46 ` Paul Mackerras
@ 2017-10-25 9:11 ` Matthew Wilcox
2017-10-25 10:30 ` Michael Ellerman
1 sibling, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2017-10-25 9:11 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Linus Torvalds, linux-kernel, linuxppc-dev, linux-s390
From: Paul Mackerras [mailto:paulus@ozlabs.org]
> On Wed, Oct 25, 2017 at 07:39:48AM +0000, Matthew Wilcox wrote:
> > Hang on, don't tell me you found this by inspection. Are you not running the
> bitmap testcase, enabled by CONFIG_TEST_BITMAP? Either that should be
> producing an error, or there's a missing test case, or your inspection is wrong ...
>
> I did find it by inspection. I was looking for a version of the
> bitmap_* API that does little-endian style bitmaps on all systems, and
> the inline bitmap_set() does that in the case where it calls memset,
> but not in the case where it calls __bitmap_set.
I do believe that you noticed it by inspection, but you shouldn't've had to. I thought we had a comprehensive set of tests for exactly this, which means that either 01.org isn't running the right set of tests on a BE system or the tests are broken.
> I'll fire up a big-endian system tomorrow when I get to work to run
> the test case. (PPC64 is almost entirely little-endian these days as
> far as the IBM POWER systems are concerned.)
>
> In any case, it's pretty clearly wrong as it is. On a big-endian
> 64-bit system, bitmap_set(p, 56, 16) should set bytes 0 and 15 to
> 0xff, and there's no way a single memset can do that.
So ... this loop should include that case, right?
for (start = 0; start < 1024; start += 8) {
memset(bmap1, 0x5a, sizeof(bmap1));
memset(bmap2, 0x5a, sizeof(bmap2));
for (nbits = 0; nbits < 1024 - start; nbits += 8) {
bitmap_set(bmap1, start, nbits);
__bitmap_set(bmap2, start, nbits);
if (!bitmap_equal(bmap1, bmap2, 1024))
printk("set not equal %d %d\n", start, nbits);
if (!__bitmap_equal(bmap1, bmap2, 1024))
printk("set not __equal %d %d\n", start, nbits);
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
@ 2017-10-25 9:11 ` Matthew Wilcox
0 siblings, 0 replies; 8+ messages in thread
From: Matthew Wilcox @ 2017-10-25 9:11 UTC (permalink / raw)
To: Paul Mackerras; +Cc: Linus Torvalds, linux-kernel, linuxppc-dev, linux-s390
RnJvbTogUGF1bCBNYWNrZXJyYXMgW21haWx0bzpwYXVsdXNAb3psYWJzLm9yZ10NCj4gT24gV2Vk
LCBPY3QgMjUsIDIwMTcgYXQgMDc6Mzk6NDhBTSArMDAwMCwgTWF0dGhldyBXaWxjb3ggd3JvdGU6
DQo+ID4gSGFuZyBvbiwgZG9uJ3QgdGVsbCBtZSB5b3UgZ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GJtYXAyLCAxMDI0KSkNCiAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgcHJpbnRrKCJzZXQgbm90IGVxdWFsICVkICVkXG4iLCBzdGFydCwgbmJpdHMpOw0KICAg
ICAgICAgICAgICAgICAgICAgICAgaWYgKCFfX2JpdG1hcF9lcXVhbChibWFwMSwgYm1hcDIsIDEw
MjQpKQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwcmludGsoInNldCBub3QgX19l
cXVhbCAlZCAlZFxuIiwgc3RhcnQsIG5iaXRzKTsNCg0KDQo=
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
2017-10-25 8:46 ` Paul Mackerras
2017-10-25 9:11 ` Matthew Wilcox
@ 2017-10-25 10:30 ` Michael Ellerman
1 sibling, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2017-10-25 10:30 UTC (permalink / raw)
To: Paul Mackerras, Matthew Wilcox
Cc: linuxppc-dev, Linus Torvalds, linux-kernel, linux-s390
Paul Mackerras <paulus@ozlabs.org> writes:
> On Wed, Oct 25, 2017 at 07:39:48AM +0000, Matthew Wilcox wrote:
>> Hang on, don't tell me you found this by inspection. Are you not
>> running the bitmap testcase, enabled by CONFIG_TEST_BITMAP? Either
>> that should be producing an error, or there's a missing test case, or
>> your inspection is wrong ...
Oops.
[ 1.907533] test_bitmap: test 13: input is '0-2047:128/256' OK, Time: 1359
[ 1.907596] set not equal 0 8
[ 1.907640] set not __equal 0 8
[ 1.907684] clear not equal 0 8
[ 1.907728] clear not __equal 0 8
[ 1.907772] set not equal 0 16
[ 1.907816] set not __equal 0 16
[ 1.907861] clear not equal 0 16
[ 1.907905] clear not __equal 0 16
[ 1.907949] set not equal 0 24
[ 1.907993] set not __equal 0 24
[ 1.908038] clear not equal 0 24
[ 1.908082] clear not __equal 0 24
...
[ snip ~30,000 lines ]
...
[ 3.345729] set not equal 1008 8
[ 3.345773] set not __equal 1008 8
[ 3.345818] clear not equal 1008 8
[ 3.345863] clear not __equal 1008 8
[ 3.345909] test_bitmap: all 460506 tests passed
^^^^^^^^^^^^^^^^^^^^^^^
O_o
With the patch:
[ 1.904393] test_bitmap: test 13: input is '0-2047:128/256' OK, Time: 1359
[ 1.916270] test_bitmap: all 460506 tests passed
cheers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
2017-10-25 12:11 Matthew Wilcox
@ 2017-11-03 2:57 ` Michael Ellerman
0 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2017-11-03 2:57 UTC (permalink / raw)
To: Matthew Wilcox, Paul Mackerras, Matthew Wilcox, Linus Torvalds,
linux-kernel, linux-s390
Matthew Wilcox <willy@infradead.org> writes:
> (I don't think I can reliably send patches from outlook; sorry for
> breaking the threading)
>
> I see where we're not incrementing the failure count ... try this patch!
>
> --- 8< ---
>
> Subject: Fix bitmap optimisation tests to report errors correctly
> From: Matthew Wilcox <mawilcox@microsoft.com>
>
> I had neglected to increment the error counter when the tests failed,
> which made the tests noisy when they fail, but not actually return an
> error code.
>
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> Cc: stable@kernel.org
Thanks, that works for me.
test_bitmap: failed 31840 out of 460506 tests
cheers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines
@ 2017-10-25 12:11 Matthew Wilcox
2017-11-03 2:57 ` Michael Ellerman
0 siblings, 1 reply; 8+ messages in thread
From: Matthew Wilcox @ 2017-10-25 12:11 UTC (permalink / raw)
To: Michael Ellerman, Paul Mackerras, Matthew Wilcox, Linus Torvalds,
linux-kernel, linux-s390
(I don't think I can reliably send patches from outlook; sorry for
breaking the threading)
I see where we're not incrementing the failure count ... try this patch!
--- 8< ---
Subject: Fix bitmap optimisation tests to report errors correctly
From: Matthew Wilcox <mawilcox@microsoft.com>
I had neglected to increment the error counter when the tests failed,
which made the tests noisy when they fail, but not actually return an
error code.
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Cc: stable@kernel.org
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index aa1f2669bdd5..ae8a830e4e54 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -430,23 +430,32 @@ static void noinline __init test_mem_optimisations(void)
unsigned int start, nbits;
for (start = 0; start < 1024; start += 8) {
- memset(bmap1, 0x5a, sizeof(bmap1));
- memset(bmap2, 0x5a, sizeof(bmap2));
for (nbits = 0; nbits < 1024 - start; nbits += 8) {
+ memset(bmap1, 0x5a, sizeof(bmap1));
+ memset(bmap2, 0x5a, sizeof(bmap2));
+
bitmap_set(bmap1, start, nbits);
__bitmap_set(bmap2, start, nbits);
- if (!bitmap_equal(bmap1, bmap2, 1024))
+ if (!bitmap_equal(bmap1, bmap2, 1024)) {
printk("set not equal %d %d\n", start, nbits);
- if (!__bitmap_equal(bmap1, bmap2, 1024))
+ failed_tests++;
+ }
+ if (!__bitmap_equal(bmap1, bmap2, 1024)) {
printk("set not __equal %d %d\n", start, nbits);
+ failed_tests++;
+ }
bitmap_clear(bmap1, start, nbits);
__bitmap_clear(bmap2, start, nbits);
- if (!bitmap_equal(bmap1, bmap2, 1024))
+ if (!bitmap_equal(bmap1, bmap2, 1024)) {
printk("clear not equal %d %d\n", start, nbits);
- if (!__bitmap_equal(bmap1, bmap2, 1024))
+ failed_tests++;
+ }
+ if (!__bitmap_equal(bmap1, bmap2, 1024)) {
printk("clear not __equal %d %d\n", start,
nbits);
+ failed_tests++;
+ }
}
}
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-11-03 2:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-25 6:57 [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines Paul Mackerras
2017-10-25 7:39 ` Matthew Wilcox
2017-10-25 8:46 ` Paul Mackerras
2017-10-25 9:11 ` Matthew Wilcox
2017-10-25 9:11 ` Matthew Wilcox
2017-10-25 10:30 ` Michael Ellerman
2017-10-25 12:11 Matthew Wilcox
2017-11-03 2:57 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.