RE: [PATCH] bitmap: Fix optimization of bitmap_set/clear for big-endian machines

From: Matthew Wilcox
Date: Wed Oct 25 2017 - 05:11:41 EST


From: Paul Mackerras [mailto:paulus@xxxxxxxxxx]
> 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);