Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5181000rwr; Mon, 1 May 2023 01:09:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vvBz9Xjq6SHRSNmkkj1xrECHST5OFqmtkT9Zx0QTyDuoXfYjONfGSELZmbe4vmUaloX/+ X-Received: by 2002:a05:6a00:238e:b0:634:10a8:538c with SMTP id f14-20020a056a00238e00b0063410a8538cmr15340039pfc.12.1682928540316; Mon, 01 May 2023 01:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682928540; cv=none; d=google.com; s=arc-20160816; b=UpEGNcboRlqvHXTM2Xu9F+JA6cxj/JUczAr/Jb7xfh+8177/5Nuewv5exMgC5ZbYyf 4ITAvuqMRsGl9vIPsaTcSEtQ13POOIfpjpMz6xZL+S9eGNufpvQ0BqSBp7XzcAf0xlZQ 0yCHor69dole5TqCgL5/2gVI9mNz/iYHvl1RbJtQnBYezOeunmV5nKnA9aKbdgCt2+q/ anyEC8cGfP3173NT8au/9cv4edfnzXuFZmpR+5foIquAGcgeELDiQur3IDznuFOY29fi c8QVlKIHCb+FSFomaz+mHYwvL5jnZG39mYI9ixKAyfwd0pomWcsAwFtY7CKL5ZLuySKj o1pw== 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=1wQrzKEZuX3/5Eef7KYCRXhJKEAjq0AaAjZ6GxmmUQA=; b=tNPwoOMGN1T7RX65spNx6sS96briv9qa90wS6TaAOE/XtHeTCujoPpexb5Alu6knF0 102A44M12AU9SCzHpXigs8/aVrrD3xz6yKSpV9wmVlVV61OijQpGWqL5dIwtW61SiBEy 3xY8mMTKESsQ2NDBUIhaVXdmfImI+bGU6s34JrQXhUxdTTzGfM5IiUY6na/V1KRt6OBD ggF/cGKqzVowlTJEVMOvV9CjYJ+WA/oiL7bg2NWnQfhRAWELU5Chhtm3bGOzjYev4YDY KLdP0Kn69y55HhWZLJR/ihNJ1TmFts2w6gAGptoN6sHN1qlUSVeIN8MBsg3P3Nl0RNJQ GWAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pz6OmxP6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 80-20020a621953000000b0063b630df528si23161960pfz.272.2023.05.01.01.08.46; Mon, 01 May 2023 01:09:00 -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; dkim=pass header.i=@linaro.org header.s=google header.b=pz6OmxP6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjEAHfH (ORCPT + 99 others); Mon, 1 May 2023 03:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjEAHfF (ORCPT ); Mon, 1 May 2023 03:35:05 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A28B10C1 for ; Mon, 1 May 2023 00:35:04 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-24ded4b33d7so781009a91.3 for ; Mon, 01 May 2023 00:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682926504; x=1685518504; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1wQrzKEZuX3/5Eef7KYCRXhJKEAjq0AaAjZ6GxmmUQA=; b=pz6OmxP6Fg7Vb4oJk0JZFeQ+MTDUHyPTrS/XaaO/HIdZRNFns/MsY2sRHWMXintVHn t+M3tkRSn55imwLUUniv4dxD9C5df5uptXLGHHknGuyGPyqnMHkX6Ws9QBlEwU+rV2Wl p8RSHV9DpzPkzAqVjEIp8WJbPrTlBCuNI7gU/RMvw9VkWuBxmQxZFg16NYgJ4TGTxJ00 DbDh2d1OH2GrvL0uEa+VoeXxKImM4LwPVv3CFiRmPO6Naii89aEQYJNWlMX13BQjVonl WUg1jYj7mdR3gcelvz+B7MddNbvBwS9JSCcXca2RiPTE9PfwimO2Waq52C1RjGAeVH54 ZBRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682926504; x=1685518504; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1wQrzKEZuX3/5Eef7KYCRXhJKEAjq0AaAjZ6GxmmUQA=; b=KT1aXHRN5YT7T0Ar4wBt/twhvZtin50D1c0BzD1HKnEYXFee7g0eo50O0kq3D9NKKn Wzqkrn9nSbnVKx/lv8kmm49b49Ni+qPgvNqWPafUvQWeFX3YputE/0JaVOJxcu6rP9Wv ij532+rorbJ8s+XEQSn/9PD8dNS66iP4kpx5tjsvkou1pcq2TzHtnJmp20DI+pXoW0sm fG2nf/dLDWqsGURU8OE5qcIbN1SnG2rmn1VORSbU8lDx+gCu5YiMUtpIF8eGEGm16mX4 fExtkm/o9KFwsOl0pXOUXgmsKEysLYMX7wNK6SyHMNcrUMX/xtemDJs7ph/NMP1mjRBJ RTEA== X-Gm-Message-State: AC+VfDxVh2VkFMQhdk2JUBY6PZfoN4W9zH5pFQcbTV/Dn127fCiFwCib ON8aHEqNUQFWTyll2LkQdn15ww== X-Received: by 2002:a17:90b:954:b0:24d:fb2c:1ae0 with SMTP id dw20-20020a17090b095400b0024dfb2c1ae0mr2722814pjb.17.1682926503957; Mon, 01 May 2023 00:35:03 -0700 (PDT) Received: from leoy-yangtze.lan ([107.151.177.135]) by smtp.gmail.com with ESMTPSA id h24-20020a17090adb9800b0024df0e14479sm2013816pjv.5.2023.05.01.00.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 00:35:03 -0700 (PDT) Date: Mon, 1 May 2023 15:34:52 +0800 From: Leo Yan To: James Clark Cc: linux-perf-users@vger.kernel.org, coresight@lists.linaro.org, shy828301@gmail.com, denik@google.com, 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 , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/7] perf: cs-etm: Validate options after applying themperf_pmu__format_bits Message-ID: <20230501073452.GA4660@leoy-yangtze.lan> References: <20230424134748.228137-1-james.clark@arm.com> <20230424134748.228137-5-james.clark@arm.com> <20230427151228.GA152865@leoy-huanghe> <20230427221047.GA174797@leoy-huanghe> <15217b55-8a80-fbe9-7b7f-997939f42d0d@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15217b55-8a80-fbe9-7b7f-997939f42d0d@arm.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 On Fri, Apr 28, 2023 at 01:33:16PM +0100, James Clark wrote: [...] > > ETMv4 uses 'contextid' as well, since the user space needs to know which > > exception level's PID should be traced, e.g. when CPU runs in EL2 > > 'contextid' is set as ETM_OPT_CTXTID2, the perf tool will set 'contextid2' > > to tell driver to trace CONTEXTIDR_EL2. > > > > That's still working because it reads the config term in the setup > function rather than setting any one bit manually: > > if (!perf_cpu_map__empty(cpus)) { > evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, > "timestamp", 1); > evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, > "contextid", 1); > } Okay, yeah, this change can set CTXTID or CTXTID2 bit if user doesn't set anything. > > We can only verify 'contextid', and set 'contextid1' or 'contextid2' based > > on CPU running exception level, finally driver knows how to trace PID. > > > > Thanks, > > Leo > > > > I'm not 100% sure what you mean by this. But previously the validation > was looking at both contextid1 and contextid2 options and checking if > either were supported if either were set. > > I have the following change in mind, it fixes the backwards > compatibility issue. And the validation should be exactly the same as it > was before. Except for one bug that I found when both bits are requested > which I've also fixed here: > > From f1b9f56df29dfb4f2a7be25f009c79c86335587a Mon Sep 17 00:00:00 2001 > From: James Clark > Date: Fri, 28 Apr 2023 10:29:52 +0100 > Subject: [PATCH] perf cs-etm: Fix contextid validation > > 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") > Signed-off-by: James Clark LGTM: Reviewed-by: Leo Yan --- > 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