Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp640800rwr; Thu, 4 May 2023 07:51:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mXStLTDM1Jxw0bK8Wm3cDtLz+A3/q39ucgsjJwAaN+rFaIdqGQWyuFC22MfsB9r+O4ICy X-Received: by 2002:a05:6a00:1805:b0:63c:56f5:5053 with SMTP id y5-20020a056a00180500b0063c56f55053mr3329327pfa.13.1683211899600; Thu, 04 May 2023 07:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683211899; cv=none; d=google.com; s=arc-20160816; b=T9Kuq1ZngqomxRBFLBJbbwsRjl2EflIs63osZxRcIlaCZ2925nMljHSCGYrBWRkM6e 5oYIbvThTs55GhPWUrfyVXAejBodQD9FaMRh/DYvW0WYMMNF8tJFBMIgMuaEyBNvDZwG 1sWRYlmvo8th1tf6ud5kwzkLzqoUE8GOF5W593h+MVh/U1gu0eGpurw1kNmzBFd5xh4r 0t1OjnlfcWkvQoJ/KxclS+KJjUMXue9PZnv67bWypvjy2g6eK3prM8s1qT111x17Nn2P fFelx8lmUB8oYlvVczhxSGt0QHq1C3XM42STyIR+uNpAJFppISq2uREPwisyxfrwxOxx lmuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uRsk4pOCv02JM3zLhIa97BSa53Fc8Xy1lN9JG2JlVfM=; b=a4dnTSPB2sMfT/G9iKxXkOHn+io9ki8ecSAI/+McEQwgkH09wudeQyZiMK8qYpU+UX SOvd9NjRqhx1kA4JqZPof4whDngji39ftIH6gHUWJMEUI8RgeQPgbY/fuvjIAdKUXii+ isKxVooN8rNnHOzNSvgSjUEEOS2DjJJEQ9veN3ANPZCboCOc+qbOypUAGUPXw40PTvNc UPIWnlQsYHuhRmVawyirUzUjopeIxAZy6YOP5Kjymp0WoIhNl03a1bPm884IRlj8+yA9 PyNKWwlp0ThdzZE+cUKVdQnICiYS7V2LWjyMr/2gjo9vIidYW9FB5BlPTx2ydDGFed8W sBXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020aa7990a000000b0062d7d3c6cadsi36385304pff.333.2023.05.04.07.51.28; Thu, 04 May 2023 07:51:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231197AbjEDOtM (ORCPT + 99 others); Thu, 4 May 2023 10:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbjEDOtL (ORCPT ); Thu, 4 May 2023 10:49:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B4FDCF; Thu, 4 May 2023 07:49:09 -0700 (PDT) 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 6E8F22F4; Thu, 4 May 2023 07:49:53 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 915C23F5A1; Thu, 4 May 2023 07:49:06 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org Cc: James Clark , Leo Yan , Mathieu Poirier , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf cs-etm: Fix contextid validation Date: Thu, 4 May 2023 15:48:22 +0100 Message-Id: <20230504144822.1938717-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pre 5.11 kernels don't support 'contextid1' and 'contextid2' so validation would be skipped. By adding an additional check for 'contextid', old kernels will still have validation done even though contextid would either be contextid1 or contextid2. Additionally now that it's possible to override options, an existing bug in the validation is revealed. 'val' is overwritten by the contextid1 validation, and re-used for contextid2 validation causing it to always fail. '!val || val != 0x4' is the same as 'val != 0x4' because 0 is also != 4, so that expression can be simplified and the temp variable not overwritten. Fixes: 35c51f83dd1e ("perf cs-etm: Validate options after applying them") Reviewed-by: Leo Yan Link: https://lore.kernel.org/all/20230501073452.GA4660@leoy-yangtze.lan Signed-off-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 77cb03e6ff87..9ca040bfb1aa 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -78,9 +78,9 @@ static int cs_etm_validate_context_id(struct auxtrace_record *itr, char path[PATH_MAX]; int err; u32 val; - u64 contextid = - evsel->core.attr.config & - (perf_pmu__format_bits(&cs_etm_pmu->format, "contextid1") | + u64 contextid = evsel->core.attr.config & + (perf_pmu__format_bits(&cs_etm_pmu->format, "contextid") | + perf_pmu__format_bits(&cs_etm_pmu->format, "contextid1") | perf_pmu__format_bits(&cs_etm_pmu->format, "contextid2")); if (!contextid) @@ -114,8 +114,7 @@ static int cs_etm_validate_context_id(struct auxtrace_record *itr, * 0b00100 Maximum of 32-bit Context ID size. * All other values are reserved. */ - val = BMVAL(val, 5, 9); - if (!val || val != 0x4) { + if (BMVAL(val, 5, 9) != 0x4) { pr_err("%s: CONTEXTIDR_EL1 isn't supported, disable with %s/contextid1=0/\n", CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL; -- 2.34.1