Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp546298pxb; Thu, 25 Feb 2021 08:52:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKmG2z5J0RysicOCKsGWulefDdRAF7WackZCjNw/JN4fTbe8m3AGlReUxJnm1qyS6+Fb4C X-Received: by 2002:a05:6402:1155:: with SMTP id g21mr3911029edw.279.1614271966359; Thu, 25 Feb 2021 08:52:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614271966; cv=none; d=google.com; s=arc-20160816; b=iIvGB/0GYY6v8CGdGZR1qz4mTNplWg1Ah0AkHA2ElZwTSNrc216D5OkzkL8GO3F2ih vRg4EQx0Av2w2BlED1pmWUHicc7PDFOs5DziHT5TPRA8nFSpsAqrcHeLm/K4jXFJ24S3 ERPfYpUjT/UkZFaVFZ0W5lhGyljBaEWnUQ+G0wEDF4dYaPCwdlJ8j/xzgDzUzp1anB40 FK+Pkkzkk2W8BuTADgvBJ1DHQUBBl7fabA8j4XQWWccKCR814jq6k8uTZkbMre5X1Qwv ljzKU6VjSuxUhIr32Jay7rkXUe7byMXepYJi2wV2wuuCdWUmz8bczAF679Iamxk+7UBu s3Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/A3h88rm/bzKYDHwXmy10vJWFNAxrqRS/0m9On458gU=; b=V5qAKPRZf6dhNcIPbyCHwEjJT/jqzU1riGj9ysCM9KgjA1GH2jFu2pP14sxZssnTfb xm9E7M8QAlR4bwZ9dgymCTod2og9DzRNvR3yKPLliCiGC03hxHfOY0/FiRiyjjvwWtTK 5sVzQmtunTkDOa5Cv9Bc05VuICl1sWQVD0WHoZkwAJGe/mZ4YBt/lr9bnK1RXUzejPT2 z7YQ9yyDqtW+M5Ej/hCoUuC9iysaLEUI6c0sLbd1YytA/DjCGB/O42XPjWY5E0tUo587 CCClH/KQuAkqSgsI1gUC1Fs8ji0gCtBu99xsKcFkSd+wG5DDXxBzNZ6v0a1OsnH0hKtJ WGQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aHUCEcGr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qo25si3704508ejb.288.2021.02.25.08.52.23; Thu, 25 Feb 2021 08:52:46 -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; dkim=pass header.i=@linaro.org header.s=google header.b=aHUCEcGr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234044AbhBYQtQ (ORCPT + 99 others); Thu, 25 Feb 2021 11:49:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbhBYQqI (ORCPT ); Thu, 25 Feb 2021 11:46:08 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EFE4C061756 for ; Thu, 25 Feb 2021 08:45:25 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id s16so3488728plr.9 for ; Thu, 25 Feb 2021 08:45:25 -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=ozYr1E8OYHtKyMSE6Af8oVUfU0dY5ArMHKdkJVK10OTxKQEhNpGlBnWw+gn9LVgXXP TQV73Io2Q2Upd8GSFqDvksHi1NHCjciRks1E8aEgyjxVbYouk29OEiPXyn5t9Ru2+4k7 woBopH7ma2Bu2wEleDkXiSZvaAAjLYrZ8vM3YLkEErdr7FDPwZfcLkEgTdKfrYauGzWk QfyVIy9a2T98czz0s3/kI/IDrIabkZuxofGeTmw1EPr/8SujWLNcwFbVAzHpSztyKKMb y2sgsHCDWfDN2tCRU4HnqPs1hfoAh1VvnyvGzc3N0EAhvBhj32IDzuz4kigbiAT2CTE8 sEqg== X-Gm-Message-State: AOAM533Wk5s0zN6rutuBwznrahUPKXR1AxN3FR5NUMBBo2NAWCANlzB6 nTbVTHvTBHQ1gPW9M0+u8wXP2A== 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 Cc: Suzuki K Poulose , Alexander Shishkin , Nathan Chancellor , Nick Desaulniers , 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 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210225094324.3542511-1-arnd@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >