Return-Path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:14124 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730571AbgFHQln (ORCPT ); Mon, 8 Jun 2020 12:41:43 -0400 From: Alexander Gordeev Subject: [PATCH v2] lib: fix bitmap_parse() on 64-bit big endian archs Date: Mon, 8 Jun 2020 18:41:11 +0200 Message-Id: <1591634471-17647-1-git-send-email-agordeev@linux.ibm.com> Sender: linux-s390-owner@vger.kernel.org List-ID: To: linux-kernel@vger.kernel.org Cc: linux-s390@vger.kernel.org, Alexander Gordeev , stable@vger.kernel.org, Andrew Morton , Yury Norov , Andy Shevchenko , Amritha Nambiar , Arnaldo Carvalho de Melo , Chris Wilson , Kees Cook , Matthew Wilcox , Miklos Szeredi , Rasmus Villemoes , Steffen Klassert , "Tobin C . Harding" , Vineet Gupta , Will Deacon , Willem de Bruijn 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: stable@vger.kernel.org Cc: Andrew Morton Cc: Yury Norov Cc: Andy Shevchenko Cc: Amritha Nambiar Cc: Arnaldo Carvalho de Melo Cc: Chris Wilson Cc: Kees Cook Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Rasmus Villemoes Cc: Steffen Klassert Cc: "Tobin C . Harding" Cc: Vineet Gupta Cc: Will Deacon Cc: Willem de Bruijn Signed-off-by: Alexander Gordeev --- lib/bitmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 89260aa342d6..80d26b183248 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -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