Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1451622ybz; Thu, 16 Apr 2020 09:23:19 -0700 (PDT) X-Google-Smtp-Source: APiQypJ68598AdwbaoS4J0AxM8kuvwqTsKxpzN1+T4cBiTbaOu14olxH8PXtmb6cE9hgj+UDOVyA X-Received: by 2002:aa7:cd6a:: with SMTP id ca10mr1994867edb.332.1587054199111; Thu, 16 Apr 2020 09:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587054199; cv=none; d=google.com; s=arc-20160816; b=j0ndp0Spc/bk6j5SvQ4i6s8PCVjpOxKItcB4tpZewtj6WAAq7JLDA2JF9Hv0HvMTU+ x7/+Ihx+Grn9azPcYnJs8r5I2ZOPaGGNtNTLMC/Q+PXPrMGcTaH6HF2fwxs7uDF02FzN QNfXXfzvQxhA+1znflWnIkJp6iNZcJEmisBk9jIbjkodYlvKSjZSC3i/Vs/mOhFMvUaS 41vqq+q3BMOmWWVndc+daqb3cCf4EFThWKkQpZptytnVcrd0IHwN8AnrfnRWbAb+bI/K /lmG+c8R71OceKzkyaNskcuI4FMa0J7B/K/QrX2wQFioY7FaTecOxF5/EHp/kterSE9f rtBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=xZJzR8aUM+SZbK48EYF5Ty1B6fxD7fSCQJj/dlS5WPs=; b=JOH6EvcsoXaMaCrM+41C3dJhft61GmBkmZ5BmEIr5G4a0jZqO7gacluRf5flhY9/Cs i4NIEM575OAC0v8IPnTvB456M1NeEza1gu3/BxPVh9JLci09lFBUhmxh1SXNeBwKYT0J VdbgekkID0B4ehxUvIArQDZWJZ+Hr2n62C3V2NYDNRWTfRMyX4VqKiwGCdXr0BXRgWwZ tpx/rhgR0sLNhSOs2P41uSz0qjqKHSpF6OcSSxQKehLzt5xwlZSKXXO672ePETXbwM5j np2+b4zq/1CBielQ7D/3RRNPQYJKXSes/rbe4hBAlxVJYAqlc4oqxLTe6WrJK4pM55H8 3rog== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b89si3963641edf.345.2020.04.16.09.22.55; Thu, 16 Apr 2020 09:23:19 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389899AbgDPQVj (ORCPT + 99 others); Thu, 16 Apr 2020 12:21:39 -0400 Received: from mga17.intel.com ([192.55.52.151]:24257 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405707AbgDPQVa (ORCPT ); Thu, 16 Apr 2020 12:21:30 -0400 IronPort-SDR: cx837X40+qVtFt2KbdS4sifpGIp2faYRbVnEscVncFFntOrBkB1Zk8vXvvXc5xv64LZhVcloVm Aw3sgkphw7/Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2020 09:21:29 -0700 IronPort-SDR: MUpfP6odjF0JmE7yBQEnKYqWp82J/1I5DsHVtGe9n3He3T/wGVi+0+UwRr1IN3OuEuXhHv2/A3 OoBv5VZQjNIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,391,1580803200"; d="scan'208";a="253915577" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.21]) by orsmga003.jf.intel.com with ESMTP; 16 Apr 2020 09:21:29 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id 5FC583018C4; Thu, 16 Apr 2020 09:21:29 -0700 (PDT) From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH v1] perf parse: Avoid false uncore matches Date: Thu, 16 Apr 2020 09:21:19 -0700 Message-Id: <20200416162119.619956-1-andi@firstfloor.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen The PMU matching adds an implicit '*' to match multiple instances of PMUs. But this causes problems when the user specified an explicit number, in this case longer numbers with the same prefix could be matched too, which is not intended. Check for the number case and avoid the extra wildcard. Also this fixes a memory leak with the pattern match. We would not free the allocated pattern. Before: $ perf stat --no-merge -e cha_1// -a sleep 1 Performance counter stats for 'system wide': 698,393,431 uncore_cha_1// 698,395,491 uncore_cha_14// 698,393,873 uncore_cha_12// 698,392,975 uncore_cha_10// 698,391,167 uncore_cha_17// 698,390,371 uncore_cha_15// 698,389,007 uncore_cha_13// 698,388,069 uncore_cha_11// 698,386,991 uncore_cha_16// 1.001343184 seconds time elapsed After $ ./perf stat --no-merge -e cha_1// -a sleep 1 Performance counter stats for 'system wide': 741,490,611 uncore_cha_1// 1.000847326 seconds time elapsed $ Signed-off-by: Andi Kleen --- tools/perf/util/parse-events.y | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 94f8bcd83582..f38c90756476 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -286,7 +286,8 @@ PE_NAME opt_pmu_config parse_events_terms__delete(orig_terms); \ free(list); \ free($1); \ - free(pattern); \ + if ($1 != pattern) \ + free(pattern); \ YYABORT; \ } while(0) @@ -303,7 +304,9 @@ PE_NAME opt_pmu_config struct perf_pmu *pmu = NULL; int ok = 0; - if (asprintf(&pattern, "%s*", $1) < 0) + if ($1[0] && isdigit($1[strlen($1) - 1])) + pattern = $1; + else if (asprintf(&pattern, "%s*", $1) < 0) CLEANUP_YYABORT; while ((pmu = perf_pmu__scan(pmu)) != NULL) { @@ -320,6 +323,8 @@ PE_NAME opt_pmu_config parse_events_terms__delete(terms); } } + if ($1 != pattern) + free(pattern); if (!ok) CLEANUP_YYABORT; -- 2.24.1