From patchwork Mon Jan 4 14:16:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 59134 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp5383895lbb; Mon, 4 Jan 2016 06:18:26 -0800 (PST) X-Received: by 10.66.140.39 with SMTP id rd7mr126816628pab.86.1451917106717; Mon, 04 Jan 2016 06:18:26 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id um10si59271155pab.110.2016.01.04.06.18.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2016 06:18:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aG5ws-0000PK-Qq; Mon, 04 Jan 2016 14:17:26 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aG5wp-0000Ir-C7 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jan 2016 14:17:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6550549; Mon, 4 Jan 2016 06:16:29 -0800 (PST) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A9D6C3F246; Mon, 4 Jan 2016 06:17:00 -0800 (PST) Date: Mon, 4 Jan 2016 14:16:58 +0000 From: Will Deacon To: David Binderman Subject: Re: linux-4.4-rc8/arch/arm64/kernel/module.c:78: 32/64 bit problem ? Message-ID: <20160104141657.GC1616@arm.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160104_061723_519069_908B70E1 X-CRM114-Status: GOOD ( 10.13 ) X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.101.70 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On Mon, Jan 04, 2016 at 08:25:30AM +0000, David Binderman wrote: > Hello there, Hi David, > [linux-4.4-rc8/arch/arm64/kernel/module.c:78] -> > [linux-4.4-rc8/arch/arm64/kernel/module.c:88]: (warning) Shifting 32-bit > value by 64 bits is undefined behaviour. See condition at line 88. Curious, but how are you seeing this warning? GCC is silent for me... > Source code is > >     u64 imm_mask = (1 << len) - 1; >     s64 sval = do_reloc(op, place, val); > >     switch (len) { >     case 16: >         *(s16 *)place = sval; >         break; >     case 32: >         *(s32 *)place = sval; >         break; >     case 64: > > So it seems that len can be 64. Suggest new code > >     u64 imm_mask = (1UL << len) - 1; That still ends up shifting by the width of the type when len == 64, which is potentially still broken. We're better off using GENMASK. Will --->8 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index f4bc779e62e8..266e7490e85c 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -75,7 +75,7 @@ static u64 do_reloc(enum aarch64_reloc_op reloc_op, void *place, u64 val) static int reloc_data(enum aarch64_reloc_op op, void *place, u64 val, int len) { - u64 imm_mask = (1 << len) - 1; + u64 imm_mask = GENMASK(len - 1, 0); s64 sval = do_reloc(op, place, val); switch (len) {