linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib: fix bitmap_parse() on 64-bit big endian archs
@ 2020-05-12 15:21 Alexander Gordeev
  2020-05-12 15:58 ` Christian Borntraeger
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Gordeev @ 2020-05-12 15:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-s390, Alexander Gordeev, Yury Norov

Commit 2d626158 ("lib: rework bitmap_parse()") does
not take into account order of halfwords on 64-bit
big endian architectures.

Cc: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
 lib/bitmap.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 89260aa..a725e46 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -717,6 +717,19 @@ static const char *bitmap_get_x32_reverse(const char *start,
 	return end;
 }
 
+#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
+static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
+{
+	maskp += (chunk_idx / 2);
+	((u32 *)maskp)[(chunk_idx & 1) ^ 1] = chunk;
+}
+#else
+static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
+{
+	((u32 *)maskp)[chunk_idx] = chunk;
+}
+#endif
+
 /**
  * bitmap_parse - convert an ASCII hex string into a bitmap.
  * @start: pointer to buffer containing string.
@@ -738,7 +751,8 @@ 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_idx = 0;
+	u32 chunk;
 	int unset_bit;
 
 	while (1) {
@@ -749,9 +763,11 @@ int bitmap_parse(const char *start, unsigned int buflen,
 		if (!chunks--)
 			return -EOVERFLOW;
 
-		end = bitmap_get_x32_reverse(start, end, bitmap++);
+		end = bitmap_get_x32_reverse(start, end, &chunk);
 		if (IS_ERR(end))
 			return PTR_ERR(end);
+
+		save_x32_chunk(maskp, chunk, chunk_idx++);
 	}
 
 	unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: fix bitmap_parse() on 64-bit big endian archs
  2020-05-12 15:21 [PATCH] lib: fix bitmap_parse() on 64-bit big endian archs Alexander Gordeev
@ 2020-05-12 15:58 ` Christian Borntraeger
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Borntraeger @ 2020-05-12 15:58 UTC (permalink / raw)
  To: Alexander Gordeev, linux-kernel; +Cc: linux-s390, Yury Norov, Karsten Graul



On 12.05.20 17:21, Alexander Gordeev wrote:
> Commit 2d626158 ("lib: rework bitmap_parse()") does
> not take into account order of halfwords on 64-bit
> big endian architectures.

Karsten reported that this broke receive packet steering in 5.5 and later.
So we should add cc stable and a Fixes tag.
> 
> Cc: Yury Norov <yury.norov@gmail.com>
> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> ---
>  lib/bitmap.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bitmap.c b/lib/bitmap.c
> index 89260aa..a725e46 100644
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -717,6 +717,19 @@ static const char *bitmap_get_x32_reverse(const char *start,
>  	return end;
>  }
>  
> +#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
> +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
> +{
> +	maskp += (chunk_idx / 2);
> +	((u32 *)maskp)[(chunk_idx & 1) ^ 1] = chunk;
> +}
> +#else
> +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
> +{
> +	((u32 *)maskp)[chunk_idx] = chunk;
> +}
> +#endif
> +
>  /**
>   * bitmap_parse - convert an ASCII hex string into a bitmap.
>   * @start: pointer to buffer containing string.
> @@ -738,7 +751,8 @@ 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_idx = 0;
> +	u32 chunk;
>  	int unset_bit;
>  
>  	while (1) {
> @@ -749,9 +763,11 @@ int bitmap_parse(const char *start, unsigned int buflen,
>  		if (!chunks--)
>  			return -EOVERFLOW;
>  
> -		end = bitmap_get_x32_reverse(start, end, bitmap++);
> +		end = bitmap_get_x32_reverse(start, end, &chunk);
>  		if (IS_ERR(end))
>  			return PTR_ERR(end);
> +
> +		save_x32_chunk(maskp, chunk, chunk_idx++);
>  	}
>  
>  	unset_bit = (BITS_TO_U32(nmaskbits) - chunks) * 32;
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-12 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 15:21 [PATCH] lib: fix bitmap_parse() on 64-bit big endian archs Alexander Gordeev
2020-05-12 15:58 ` Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).