Skip to contentSkip to conversation

lib/test_bitmap: Correct test data offsets for 32-bit

PATCH Superseded Andy Shevchenko 2 participants 6 messages Jan 8, 2020 – Jan 9, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/test_bitmap: Correct test data offsets for 32-bit

On 32-bit platform the size of long is only 32 bits which makes wrong offset in the array of 64 bit size.

Calculate offset based on BITS_PER_LONG.

Fixes 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
---
 lib/test_bitmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/test_bitmap.c +5 -4
index 5cb35a734462..af522577a76e 100644
@@ -275,22 +275,23 @@ static void __init test_copy(void)
 static void __init test_replace(void)
 {
 	unsigned int nbits = 64;
+	unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);
 	DECLARE_BITMAP(bmap, 1024);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_1_0, nbits);
 
 	bitmap_fill(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);
 
 	bitmap_fill(bmap, 1024);
-	bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_1_0, nbits);
 }
 
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/2 lib/test_bitmap: Fix address space when test user buffer

Force address space to avoid the following warning:

lib/test_bitmap.c:461:53: warning: incorrect type in argument 1 (different address spaces)
lib/test_bitmap.c:461:53: expected char const [noderef] <asn:1> *ubuf
lib/test_bitmap.c:461:53: got char const *in

---
 lib/test_bitmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/test_bitmap.c +2 -1
index af522577a76e..8d3154457ff8 100644
@@ -458,7 +458,8 @@ static void __init __test_bitmap_parse(int is_user)
 
 			set_fs(KERNEL_DS);
 			time = ktime_get();
-			err = bitmap_parse_user(test.in, len, bmap, test.nbits);
+			err = bitmap_parse_user((__force const char __user *)test.in, len,
+						bmap, test.nbits);
 			time = ktime_get() - time;
 			set_fs(orig_fs);
 		} else {
Signature · 1 line
2.24.1
maintainer
#2 lore raw
In reply to Andy Shevchenko
Quoted 17 lines · Andy Shevchenko

On 32-bit platform the size of long is only 32 bits which makes wrong offset in the array of 64 bit size.

Calculate offset based on BITS_PER_LONG.

Fixes 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
---
 lib/test_bitmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/test_bitmap.c +0 -0
index 5cb35a734462..af522577a76e 100644

lib/test_bitmap.c static void __init test_copy(void) · line 278

Quoted 4 lines
lib/test_bitmap.c +1 -0
@@ -275,22 +275,23 @@ static void __init test_copy(void)
 static void __init test_replace(void)
 {
 	unsigned int nbits = 64;
+	unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);

Step is already defined in this file:

        #define step (sizeof(u64) / sizeof(unsigned long))

to avoid the same problem in other test cases. Introducing another variant of it looks messy.

lib/test_bitmap.c static void __init test_copy(void) · line 283

Quoted 6 lines
lib/test_bitmap.c +1 -1
 	DECLARE_BITMAP(bmap, 1024);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);

If nbits is always 64, why don't you pass 64 directly?

Yury

Quoted 18 lines
lib/test_bitmap.c +3 -3
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_1_0, nbits);
 
 	bitmap_fill(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);
 
 	bitmap_fill(bmap, 1024);
-	bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_1_0, nbits);
 }
 
Signature · 1 line
2.24.1
#3 lore raw
Quoted 10 lines · Yury Norov
Quoted 8 lines · Andy Shevchenko

On 32-bit platform the size of long is only 32 bits which makes wrong offset in the array of 64 bit size.

Calculate offset based on BITS_PER_LONG.

Fixes 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
Quoted 5 lines

lib/test_bitmap.c static void __init test_copy(void) · line 278

Quoted 2 lines
lib/test_bitmap.c +1 -0
 	unsigned int nbits = 64;
+	unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);

Step is already defined in this file:

        #define step (sizeof(u64) / sizeof(unsigned long))

...and later undefined.

Quoted 2 lines

to avoid the same problem in other test cases. Introducing another variant of it looks messy.

I don't see any problem.

Quoted 9 lines

lib/test_bitmap.c static void __init test_copy(void) · line 283

Quoted 7 lines
lib/test_bitmap.c +1 -1
 	DECLARE_BITMAP(bmap, 1024);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);

If nbits is always 64, why don't you pass 64 directly?

We may use any setting. For now it's 64, but nothing prevents us to extend to, let's say, 75.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 17 lines · Andy Shevchenko
Quoted 10 lines · Yury Norov
Quoted 8 lines · Andy Shevchenko

On 32-bit platform the size of long is only 32 bits which makes wrong offset in the array of 64 bit size.

Calculate offset based on BITS_PER_LONG.

Fixes 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
Quoted 5 lines

lib/test_bitmap.c static void __init test_copy(void) · line 278

Quoted 2 lines
lib/test_bitmap.c +1 -0
 	unsigned int nbits = 64;
+	unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);

Step is already defined in this file:

        #define step (sizeof(u64) / sizeof(unsigned long))
Quoted 6 lines

...and later undefined.

Quoted 2 lines

to avoid the same problem in other test cases. Introducing another variant of it looks messy.

I don't see any problem.

The problem is that you reimplement the functionality instead of reuse.

Quoted 16 lines
Quoted 8 lines

lib/test_bitmap.c static void __init test_copy(void) · line 283

Quoted 6 lines
lib/test_bitmap.c +1 -1
 	DECLARE_BITMAP(bmap, 1024);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);

If nbits is always 64, why don't you pass 64 directly?

We may use any setting. For now it's 64, but nothing prevents us to extend to, let's say, 75.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 20 lines · Yury Norov
Quoted 19 lines · Andy Shevchenko
Quoted 10 lines · Yury Norov
Quoted 8 lines · Andy Shevchenko

On 32-bit platform the size of long is only 32 bits which makes wrong offset in the array of 64 bit size.

Calculate offset based on BITS_PER_LONG.

Fixes 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
Quoted 5 lines

lib/test_bitmap.c static void __init test_copy(void) · line 278

Quoted 2 lines
lib/test_bitmap.c +1 -0
 	unsigned int nbits = 64;
+	unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);

Step is already defined in this file:

        #define step (sizeof(u64) / sizeof(unsigned long))

...and later undefined.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

to avoid the same problem in other test cases. Introducing another variant of it looks messy.

I don't see any problem.

The problem is that you reimplement the functionality instead of reuse.

I may not reuse by the reason I mentioned above. The definition of step works only for 64 bits, we may modify test case for any amount of bits to be tested.

I'll rename the variable to something else to reduce confusion.

Quoted 17 lines
Quoted 17 lines
Quoted 9 lines

lib/test_bitmap.c static void __init test_copy(void) · line 283

Quoted 7 lines
lib/test_bitmap.c +1 -1
 	DECLARE_BITMAP(bmap, 1024);
 
 	bitmap_zero(bmap, 1024);
-	bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+	bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_0_1, nbits);

If nbits is always 64, why don't you pass 64 directly?

We may use any setting. For now it's 64, but nothing prevents us to extend to, let's say, 75.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
With Best Regards,
Andy Shevchenko