Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp702322pxb; Thu, 25 Feb 2021 12:51:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUuURN0b12a/xkx+drxlSpYG3ktRcRsMjeo07IOFovxVXCzqF71wwk4TyPfgVVAZNU8BpP X-Received: by 2002:a17:906:72d1:: with SMTP id m17mr3036030ejl.118.1614286286251; Thu, 25 Feb 2021 12:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614286286; cv=none; d=google.com; s=arc-20160816; b=MklUHLFdbjMjM8qPSE5cl0efraTUcT8QGcq0DKJfzXDvE1Cmv2MiM2bbJtU42FvD94 KH4u3pTW3bg4TArXkTPwNahCmixL6vuN7M4LLt3hcWJ/4dslrxqHenvl2OkVQy3DZgSO AJ3JDoN4WLIj0lJZuR4e3KISRnBnCoOzjRQsqD1xwlPziym+HdlNt1f+yqXDwFyvcsVx 7XBx67jU3RasLFQSdq2QJ/1k2XtlrEInyp4JwOEnJKMKRaP9cnVRmr7CNqjbwwzbnYfk TlbARYCSZULhLju8XuA203qV9fvY127u22IjZgbVlz6gZpaxGdrZG65x4ipcz9vnvZZs E0MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=FrrGfd1EdZQPPUGwleXpAq9NNkW8aJFy98CwizL+8Gg=; b=BIntu59f6yL95ep/5GkqjNb/LRQoj8nWShRX3hixzXqDwAmfPQTvhJigo3NrtNeZme EqGxM+uFAOnoBf1NwOGKiN+1warwfju9dwHbBT3Drlf5/sP7H8nZHE88kWh5oDIu38pS RkLbT5HYvnVSO52rVGDKuOqJqYaUVP4mcCLrTIqkGFsABIu/TE6q/o1E9geEtMrtAS/p z54gRFu6DGR2uTh6/1/Y0Nb/GBmEhyTLscnBmXE24iv57YJaqYAdw58iR8bqS/rkDTYR sJNEu/2ydhZqpzi+A8Bp2Fy9IzpSIWHqbLggCnw5J3W5C0s1U7hidRX/U/KD1+gPTe3M oj4A== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s7si3973100edw.490.2021.02.25.12.51.00; Thu, 25 Feb 2021 12:51:26 -0800 (PST) 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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232644AbhBYRV6 (ORCPT + 99 others); Thu, 25 Feb 2021 12:21:58 -0500 Received: from foss.arm.com ([217.140.110.172]:42116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232033AbhBYRV4 (ORCPT ); Thu, 25 Feb 2021 12:21:56 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 810F8101E; Thu, 25 Feb 2021 09:21:08 -0800 (PST) Received: from [10.57.49.35] (unknown [10.57.49.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9339C3F73D; Thu, 25 Feb 2021 09:21:04 -0800 (PST) Subject: Re: [PATCH] coresight: etm4x: work around clang-12+ build failure To: Arnd Bergmann , Mathieu Poirier , Alexander Shishkin , Nathan Chancellor , Nick Desaulniers Cc: Arnd Bergmann , Mike Leach , Leo Yan , Greg Kroah-Hartman , Sai Prakash Ranjan , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20210225094324.3542511-1-arnd@kernel.org> From: Suzuki K Poulose Message-ID: <19c9eba2-c5cd-301f-4dfa-a31c971728f9@arm.com> Date: Thu, 25 Feb 2021 17:20:57 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210225094324.3542511-1-arnd@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/25/21 9:42 AM, 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 s/decides finds/decides/ ? > 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)); > } > There are more places where we do this. So I believe you need the similar change elsewhere too in the driver. So, that becomes cumbersome for circumventing the compiler issue. Suzuki