From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4491C433E0 for ; Thu, 25 Feb 2021 16:46:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 786F564F19 for ; Thu, 25 Feb 2021 16:46:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 786F564F19 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UeNfIiEF2uOIiAok56itzD5J8cNk/b08BiMPh665HPA=; b=qpO8/5iAf4PNCwhNh4UotCydi Ms8yCKR1RYS3Cx+BPubg/8/FS0lymd0aayKi24DexMNoFtDo7OjW6F7qeTFPTc+4Hx2qK5D3he4N1 8JXfDBDkiw+Fyk4FHLpMikfC/Zi53sTxOJGe56cpvHHui+oKrBVluTDmNFem1jzWgjs+LNmtf5zZh K9ALuO4RhkLTR8y2S8XpgVmkzImQXfqlGrvmtftPidirUYZWvjVM53gPD3uWliDJLXcXzTdle4xtM 2Wt6Z10KTnzzrAnNB6S8fyhA1PLezgpIgxlf1Abz49vbpGnHdVAwtx3fBgw5EPWmKOOgAUXRSkxuR hTugTF+MA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFJlg-00075h-Sf; Thu, 25 Feb 2021 16:45:36 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFJlZ-00074k-2M for linux-arm-kernel@lists.infradead.org; Thu, 25 Feb 2021 16:45:30 +0000 Received: by mail-pl1-x630.google.com with SMTP id d11so3491414plo.8 for ; Thu, 25 Feb 2021 08:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/A3h88rm/bzKYDHwXmy10vJWFNAxrqRS/0m9On458gU=; b=aHUCEcGrUmuALlrW5N3AgOikup5aJsj9aZOTqbPycD+CdsOEPxmh6Kya2z0mJR5t8/ lIJa3GIp1QbkwFVHScQtErzxj9Q3OwZz6KcqjdCxfx4FGYDTD5U5YQaj0stiScxx0dNo V4sOdMMsmR6jJSrlUg3yLxssONi72uJgDT/2DsQihzM+2zpxCnpanor4Uiuu6+pYrQrR WpGICJobY8TfGWmMDR+uWe4EmxNwIYFRrV31pCkDS0dG8DReqJaGPVkzexm4ugMGuC9Y sLMcTtx0XCnTVybmPr2KuhMl/sCQKQB7wKYlzwNAQ0eZVq9K28lzNCVSd1/eexHwnXHA zo4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/A3h88rm/bzKYDHwXmy10vJWFNAxrqRS/0m9On458gU=; b=kpTkKrdX7BQ7xgTORFd5IXofOr2e+PODfXjqmJ73FtbE55NgABaBliJO939OqPZebg LwMNl/LVlV9w40Sf50UFiNRxquAvPhToTJY3LL/2MRtRwe5KfDcGiSSqL4BrjxofI8KA kbflZ2MEqD02cApTw4sMSseEUKxpVj7ESStbl0nfJEXsIYTr2q/lbkjVOrjtjeMJVSua WmVCsdtn8JT7LV9csm/oV0UISBvhnR4Qb3aJJqm6DozfW4YWnjH5Xvo/NOpVLw8NobmI P6ciXhzn96dJJAkxouc6fFPk0FWHcCZZtR6BuCH9esxOkkxNAClAoOxtdxtGX0fb7kZB LyCw== X-Gm-Message-State: AOAM531ZPzx3xKhfGK2MwCZKPp1rxqAGu2ywgOIJw0fy5FMh0xE5dPO+ Q9bl9XaCTi19JDEts9/AafIxlA== X-Google-Smtp-Source: ABdhPJzRSR4qjMRKOm8I7sIosVeGkGxfVF6vpPPpkiH9mbZ5oQ6Ew5AaJnhilG6ZMClo0nDq3Dmztw== X-Received: by 2002:a17:902:6949:b029:e3:1ee9:6bfd with SMTP id k9-20020a1709026949b02900e31ee96bfdmr3897370plt.66.1614271524938; Thu, 25 Feb 2021 08:45:24 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id s10sm6530952pgl.90.2021.02.25.08.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 08:45:24 -0800 (PST) Date: Thu, 25 Feb 2021 09:45:22 -0700 From: Mathieu Poirier To: Arnd Bergmann Subject: Re: [PATCH] coresight: etm4x: work around clang-12+ build failure Message-ID: <20210225164522.GA3554437@xps15> References: <20210225094324.3542511-1-arnd@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210225094324.3542511-1-arnd@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210225_114529_456613_E3B932DF X-CRM114-Status: GOOD ( 26.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sai Prakash Ranjan , Arnd Bergmann , Suzuki K Poulose , Alexander Shishkin , Greg Kroah-Hartman , coresight@lists.linaro.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Nathan Chancellor , clang-built-linux@googlegroups.com, Leo Yan , linux-arm-kernel@lists.infradead.org, Mike Leach Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Good morning, On Thu, Feb 25, 2021 at 10:42:58AM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > clang-12 fails to build the etm4x driver with -fsanitize=array-bounds: > > :1:7: error: expected constant expression in '.inst' directive > .inst (0xd5200000|((((2) << 19) | ((1) << 16) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 7) & 0x7)) << 12) | ((((((((((0x160 + (i * 4))))) >> 2))) & 0xf)) << 8) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 4) & 0x7)) << 5)))|(.L__reg_num_x8)) > ^ > drivers/hwtracing/coresight/coresight-etm4x-core.c:702:4: note: while in macro instantiation > etm4x_relaxed_read32(csa, TRCCNTVRn(i)); > ^ > drivers/hwtracing/coresight/coresight-etm4x.h:403:4: note: expanded from macro 'etm4x_relaxed_read32' > read_etm4x_sysreg_offset((offset), false))) > ^ > drivers/hwtracing/coresight/coresight-etm4x.h:383:12: note: expanded from macro 'read_etm4x_sysreg_offset' > __val = read_etm4x_sysreg_const_offset((offset)); \ > ^ > drivers/hwtracing/coresight/coresight-etm4x.h:149:2: note: expanded from macro 'read_etm4x_sysreg_const_offset' > READ_ETM4x_REG(ETM4x_OFFSET_TO_REG(offset)) > ^ > drivers/hwtracing/coresight/coresight-etm4x.h:144:2: note: expanded from macro 'READ_ETM4x_REG' > read_sysreg_s(ETM4x_REG_NUM_TO_SYSREG((reg))) > ^ > arch/arm64/include/asm/sysreg.h:1108:15: note: expanded from macro 'read_sysreg_s' > asm volatile(__mrs_s("%0", r) : "=r" (__val)); \ > ^ > arch/arm64/include/asm/sysreg.h:1074:2: note: expanded from macro '__mrs_s' > " mrs_s " v ", " __stringify(r) "\n" \ > ^ > > It appears that the __builin_constant_p() check in > read_etm4x_sysreg_offset() falsely returns 'true' here because clang > decides finds that an out-of-bounds access to config->cntr_val[] cannot > happen, and then it unrolls the loop with constant register numbers. Then > when actually emitting the output, it fails to figure out the value again. > > While this is incorrect behavior in clang, it is easy to work around > by avoiding the out-of-bounds array access. Do this by limiting the > loop counter to the actual dimension of the array. > > Link: https://github.com/ClangBuiltLinux/linux/issues/1310 > Signed-off-by: Arnd Bergmann > --- > drivers/hwtracing/coresight/coresight-etm4x-core.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c > index 15016f757828..4cccf874a602 100644 > --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c > @@ -691,13 +691,13 @@ static void etm4_disable_hw(void *info) > "timeout while waiting for PM stable Trace Status\n"); > > /* read the status of the single shot comparators */ > - for (i = 0; i < drvdata->nr_ss_cmp; i++) { > + for (i = 0; i < min_t(u32, drvdata->nr_ss_cmp, ETM_MAX_SS_CMP); i++) { > config->ss_status[i] = > etm4x_relaxed_read32(csa, TRCSSCSRn(i)); > } > > /* read back the current counter values */ > - for (i = 0; i < drvdata->nr_cntr; i++) { > + for (i = 0; i < min_t(u32, drvdata->nr_cntr, ETMv4_MAX_CNTR); i++) { This patch will work and I'd be happy to apply it if this was the only instance, but there are dozens of places in the coresight drivers where such patterns are used. Why are those not flagged as well? And shouldn't the real fix be with clang? Thanks, Mathieu > config->cntr_val[i] = > etm4x_relaxed_read32(csa, TRCCNTVRn(i)); > } > -- > 2.29.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel