Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4263831ybg; Mon, 8 Jun 2020 03:28:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIvhz2lEYB77h+0yYs7znVvSFh0yWD1opZznGKjVMiGfjwp4zYs7YQ8VfPM3kcyBJ0IS79 X-Received: by 2002:a17:906:2f8d:: with SMTP id w13mr21131967eji.102.1591612127497; Mon, 08 Jun 2020 03:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591612127; cv=none; d=google.com; s=arc-20160816; b=xN8a6oVSSp/HLaKgxsq+AcXOgh3I0HqB9j9ktOZ8q91ERiSKXZnkmDzt8hGJAz5Wfr uc291q2g2dORKsCXwHA/xxV2fYbbPaPi1+zWx4Gtz9tY34KLhg/7kXJXSM8jUwmYx4Yv RK9bs2lR8BoDe0YVnVam6eooLxwrI3y+5KPgnzTT6v+plejSQIcS8fS1cJm65zPWgKeS Ont62eZru6OzjKL959xWJDyLApQATTAxJcvpr2JQ4apeAyymbzB5ZaIUYwBkPU5TiZxX gTimZB+/vsvaGIPEhZscgZM9ssu5z1dbKwBT4N/WWZVImGDN9nm4njUMXycajfWS03M/ NSfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=FIhLdzPVoHuoPUpnenTP74mwYgtsXxDtmZBpcYE2msc=; b=eIwPc0z7iOAQ4fV6v+51q8lKc7olDhbS3gPQlin5Pzv39GlUHKPw9zNzBbdRBfcgB4 gmKlribTDMEv+UYO5Fx1LbvaLZYVkGN9wpFW4G+rmk6gVf2oiE9HAGh7AQ3ZBo2rBO1j uvEb3uNFzr9+OE+iF1hmqDYxtKjJoQUo+aMQBYiw9P9bFa3sUydJHGa3q7FKh1P+7e1s vBvwUzL/N/vlwZKSCgVpodvECWIe7AnVuRWwGOEdJbT1mKGintPRax8pXr7KL3q216jY NSc0qoepH9yX25vSFjJmn7E5i2Mgi4RlDoHXxfiQXKBOo0QYrPwnYpViLokO21FPDZlx 5z4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si2167805ejb.677.2020.06.08.03.28.23; Mon, 08 Jun 2020 03:28:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbgFHKYX (ORCPT + 99 others); Mon, 8 Jun 2020 06:24:23 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:2220 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbgFHKYW (ORCPT ); Mon, 8 Jun 2020 06:24:22 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 058A2qJS184709; Mon, 8 Jun 2020 06:24:00 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31g7n7rhbm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jun 2020 06:23:59 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 058A3F09187332; Mon, 8 Jun 2020 06:23:59 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 31g7n7rhas-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jun 2020 06:23:59 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 058AK6eM006411; Mon, 8 Jun 2020 10:23:56 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma05fra.de.ibm.com with ESMTP id 31g2s7sgv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Jun 2020 10:23:56 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 058ANsgV57213166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Jun 2020 10:23:54 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12942A4060; Mon, 8 Jun 2020 10:23:54 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E92FA405B; Mon, 8 Jun 2020 10:23:53 +0000 (GMT) Received: from oc3871087118.ibm.com (unknown [9.145.56.93]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 8 Jun 2020 10:23:53 +0000 (GMT) From: Alexander Gordeev 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 Subject: [PATCH RESEND2] lib: fix bitmap_parse() on 64-bit big endian archs Date: Mon, 8 Jun 2020 12:23:49 +0200 Message-Id: <1591611829-23071-1-git-send-email-agordeev@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-08_07:2020-06-08,2020-06-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 impostorscore=0 phishscore=0 mlxlogscore=999 suspectscore=1 cotscore=-2147483648 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006080073 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 89260aa342d6..a725e4612984 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; -- 2.23.0