Skip to contentSkip to conversation

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

PATCH In review Andy Shevchenko 4 participants 6 messages Jan 9, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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")

---
v2: rename step -> nlongs to avoid confusion with a macro (Yury)

 lib/test_bitmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/test_bitmap.c +5 -4
index 5cb35a734462..707b0389db35 100644
@@ -275,22 +275,23 @@ static void __init test_copy(void)
 static void __init test_replace(void)
 {
 	unsigned int nbits = 64;
+	unsigned int nlongs = 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 * nlongs], &exp2[1 * nlongs], 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 * nlongs], &exp2[0 * nlongs], 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 * nlongs], &exp2[1 * nlongs], 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 * nlongs], &exp2[0 * nlongs], exp2_to_exp3_mask, nbits);
 	expect_eq_bitmap(bmap, exp3_1_0, nbits);
 }
 
Signature · 1 line
2.24.1
#1 lore raw

PATCH v2 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

---
v2: no changes

 lib/test_bitmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/test_bitmap.c +2 -1
index 707b0389db35..61ed71c1daba 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

Re: [PATCH v2 2/2] lib/test_bitmap: Fix address space when test user buffer

Quoted 5 lines · On Thu, 9 Jan 2020 12:36:01 +0200 Andy Shevchenko…

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

We did this in

commit 17b6753ff08bc47f50da09f5185849172c598315

Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed Dec 4 16:53:06 2019 -0800
Commit:     Linus Torvalds <[email protected]>
CommitDate: Wed Dec 4 19:44:14 2019 -0800

lib/test_bitmap: force argument of bitmap_parselist_user() to proper address space

lib/test_bitmap.c static void __init __test_bitmap_parse(int is_user) · line 465

Quoted 12 lines
lib/test_bitmap.c +2 -1
@@ -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 {

Except your tree has test' where mainline has ptest'. I'm not sure what has happened here?

#3 lore raw

Re: [PATCH v2 2/2] lib/test_bitmap: Fix address space when test user buffer

Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Thu, 9 Jan 2020 12:36:01 +0200 Andy Shevchenko…

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

We did this in

Quoted 7 lines

commit 17b6753ff08bc47f50da09f5185849172c598315

Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed Dec 4 16:53:06 2019 -0800
Commit:     Linus Torvalds <[email protected]>
CommitDate: Wed Dec 4 19:44:14 2019 -0800

lib/test_bitmap: force argument of bitmap_parselist_user() to proper address space

This is for "parseLIST", while new patch for "parse".

Quoted 17 lines

lib/test_bitmap.c static void __init __test_bitmap_parse(int is_user) · line 465

Quoted 13 lines
lib/test_bitmap.c +2 -1
@@ -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 {

Except your tree has test' where mainline has ptest'. I'm not sure what has happened here?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw

Re: [PATCH v2 2/2] lib/test_bitmap: Fix address space when test user buffer

Quoted 18 lines · On Thu, 9 Jan 2020 23:04:59 +0200 Andy Shevchenko <[email protected]>…
Quoted 17 lines · Andrew Morton
Quoted 5 lines · On Thu, 9 Jan 2020 12:36:01 +0200 Andy Shevchenko…

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

We did this in

commit 17b6753ff08bc47f50da09f5185849172c598315

Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed Dec 4 16:53:06 2019 -0800
Commit:     Linus Torvalds <[email protected]>
CommitDate: Wed Dec 4 19:44:14 2019 -0800
Quoted 3 lines
Quoted 1 line

lib/test_bitmap: force argument of bitmap_parselist_user() to proper address space

This is for "parseLIST", while new patch for "parse".

Oh. This is a fix against the mm patch lib-add-test-for-bitmap_parse.patch. Please tell us such things!

But [patch 1/2] is applicable to current mainline, yes?

#5 lore raw

Re: [PATCH v2 2/2] lib/test_bitmap: Fix address space when test user buffer

Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 9 Jan 2020 23:04:59 +0200 Andy Shevchenko <[email protected]>…
Quoted 17 lines · Andrew Morton
Quoted 5 lines · On Thu, 9 Jan 2020 12:36:01 +0200 Andy Shevchenko…

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

We did this in

commit 17b6753ff08bc47f50da09f5185849172c598315

Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed Dec 4 16:53:06 2019 -0800
Commit:     Linus Torvalds <[email protected]>
CommitDate: Wed Dec 4 19:44:14 2019 -0800
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

lib/test_bitmap: force argument of bitmap_parselist_user() to proper address space

This is for "parseLIST", while new patch for "parse".

Oh. This is a fix against the mm patch lib-add-test-for-bitmap_parse.patch. Please tell us such things!

But [patch 1/2] is applicable to current mainline, yes?

Yes

Guenter