lib: fix bitmap_parse() on 64-bit big endian archs
Subsystems (4)
Alexander Gordeev
maintainerPATCH v2 1/1 lib: fix bitmap_parse() on 64-bit big endian archs
Commit 2d6261583be0 ("lib: rework bitmap_parse()") does not take into account order of halfwords on 64-bit big endian architectures. As result (at least) Receive Packet Steering, IRQ affinity masks and runtime kernel test "test_bitmap" get broken on s390.
Fixes 2d6261583be0 ("lib: rework bitmap_parse()")
Cc Andrew Morton <[email protected]>
Cc Yury Norov <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Amritha Nambiar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Kees Cook <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Steffen Klassert <[email protected]>
Cc "Tobin C . Harding" <[email protected]>
Cc Vineet Gupta <[email protected]>
Cc Will Deacon <[email protected]>
Cc Willem de Bruijn <[email protected]>
Signed-off-by Alexander Gordeev <[email protected]>
--- lib/bitmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bitmap.c +7 -1
@@ -739,6 +739,7 @@ int bitmap_parse(const char *start, unsigned int buflen,const char *end =strnchrnul (start, buflen,'\n' ) -1 ;int chunks =BITS_TO_U32 (nmaskbits);u32 *bitmap = (u32 *)maskp; +int chunk =0 ;int unset_bit;while (1 ) {
@@ -749,9 +750,14 @@ int bitmap_parse(const char *start, unsigned int buflen,if (!chunks--)return -EOVERFLOW ; - end =bitmap_get_x32_reverse (start, end, bitmap++); +#if defined(CONFIG_64BIT ) && defined(__BIG_ENDIAN) + end =bitmap_get_x32_reverse (start, end, &bitmap[chunk ^1 ]); +#else + end =bitmap_get_x32_reverse (start, end, &bitmap[chunk]); +#endif if (IS_ERR (end))return PTR_ERR (end); + chunk++; } unset_bit = (BITS_TO_U32 (nmaskbits) - chunks) *32 ;
Signature · 1 line
2.23.0
Quoted 6 lines · Alexander Gordeev
Commit
2d6261583be0("lib: reworkbitmap_parse()") does not take into account order of halfwords on 64-bit big endian architectures. As result (at least) Receive Packet Steering, IRQ affinity masks and runtime kernel test "test_bitmap" get broken on s390.
LGTM (I would replace while loop, but it's style preference and one can consider worse than infinite loop)
Reviewed-by Andy Shevchenko <[email protected]>
Quoted 54 lines
Fixes 2d6261583be0 ("lib: rework bitmap_parse()")Cc Andrew Morton <[email protected]>Cc Yury Norov <[email protected]>Cc Andy Shevchenko <[email protected]>Cc Amritha Nambiar <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Chris Wilson <[email protected]>Cc Kees Cook <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Miklos Szeredi <[email protected]>Cc Rasmus Villemoes <[email protected]>Cc Steffen Klassert <[email protected]>Cc "Tobin C . Harding" <[email protected]>Cc Vineet Gupta <[email protected]>Cc Will Deacon <[email protected]>Cc Willem de Bruijn <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- lib/bitmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)lib/bitmap.c +7
-2@@ -739,6 +739,7 @@ int bitmap_parse(const char *start, unsigned int buflen,const char *end =strnchrnul (start, buflen,'\n' ) -1 ;int chunks =BITS_TO_U32 (nmaskbits);u32 *bitmap = (u32 *)maskp; +int chunk =0 ;int unset_bit;while (1 ) {@@ -749,9 +750,14 @@ int bitmap_parse(const char *start, unsigned int buflen,if (!chunks--)return -EOVERFLOW ; - end =bitmap_get_x32_reverse (start, end, bitmap++); +#if defined(CONFIG_64BIT ) && defined(__BIG_ENDIAN) + end =bitmap_get_x32_reverse (start, end, &bitmap[chunk ^1 ]); +#else + end =bitmap_get_x32_reverse (start, end, &bitmap[chunk]); +#endif if (IS_ERR (end))return PTR_ERR (end); + chunk++; } unset_bit = (BITS_TO_U32 (nmaskbits) - chunks) *32 ; --2.23.0
Signature · 2 lines
With Best Regards, Andy Shevchenko