Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2668602pxb; Tue, 19 Jan 2021 03:10:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYPrPVcEq3oC5HecJytS2XQ/zAccHWyNG1O2i2NEpMCpY4wlyb8hx5ZJA272j+nGj8U6Ly X-Received: by 2002:aa7:c7d8:: with SMTP id o24mr3055856eds.328.1611054643413; Tue, 19 Jan 2021 03:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611054643; cv=none; d=google.com; s=arc-20160816; b=f8AXRwyfDN9JnX5OnHHNvqmjEhYB/j3kT1IbzAQC0mK8n8kE1qCowKkiY1y+3VuQLk iOOGbWd/pkilt5/IqJdEWCVNfObjZvQi8w3W0TMxhOq0rDZQ0OoaeYz0vqQmThePycuz dA/Beh8ZbF6vdOCqszc9Y5HuMyOO4x4hcY229WkDT3MB9Q6/VkB9WBIL/zY+aD5tsj0e +F/EIvTi9wUhYePcQm3Q1BJHKvDpp9dx14s79N4YZShnDUcsBXkZO6g0KW4PHcoB1bJz f8ynP/NXbiSLMP0vIwFRzOIQ+7ZXkKwHtbO9SMXj+AUJoB2I7sTW1CQHQbgNT0FCx589 a7Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=aoKcbguBhDvejhBzEuAeYzZdvnyqPZRM84LhvPelp6M=; b=bA7rqfOq8yL/xP6G4NHeX33vTAx8Z6RAX7XiL6xM8e5HWClSprZy9LIxacJ/vf09q/ YWzAvyyEHTtUScLh4GPzhrBR0VsmCvgW7B5a6JbonC97YJO9SCc/cJRfN+PUtUHw1WEw 0qrJVkgXrVawYqHtuhjYBJFMyTSzXZOHmNbQoLt1eHow6L4pOCXcBdLvDmw7XWsPC8mI BGBwGuJlbcE7uLU2EiSjQfCujgyHKI+N1Xhb3vTPJf/Mw2Rd9lJMzfuKC1SlovjMlvHO /76nyexDg0VUOak7luHA42tobxxl0aBCBrQBHYREufmVPQRYNiOtIi28YjsttWJJ2DCV GXxA== 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 ks11si2107259ejb.186.2021.01.19.03.10.20; Tue, 19 Jan 2021 03:10:43 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390382AbhASKVN (ORCPT + 99 others); Tue, 19 Jan 2021 05:21:13 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:11417 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389653AbhASKJB (ORCPT ); Tue, 19 Jan 2021 05:09:01 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DKkq13K2Mzj8Y0; Tue, 19 Jan 2021 18:07:25 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Tue, 19 Jan 2021 18:08:08 +0800 From: John Garry To: , , , , , , , , CC: , , , John Garry Subject: [PATCH] perf metricgroup: Fix system PMU metrics Date: Tue, 19 Jan 2021 18:04:15 +0800 Message-ID: <1611050655-44020-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Joakim reports that getting "perf stat" for multiple system PMU metrics segfaults: ./perf stat -a -I 1000 -M imx8mm_ddr_write.all,imx8mm_ddr_write.all Segmentation fault While the same works without issue for a single metric. The logic in metricgroup__add_metric_sys_event_iter() is broken, in that add_metric() @m argument should be NULL for each new metric. Fix by not passing a holder for that, and rather make local in metricgroup__add_metric_sys_event_iter(). Fixes: be335ec28efa ("perf metricgroup: Support adding metrics for system PMUs") Reported-by: Joakim Zhang Signed-off-by: John Garry diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index ee94d3e8dd65..2e60ee170abc 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -766,7 +766,6 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused) struct metricgroup_add_iter_data { struct list_head *metric_list; const char *metric; - struct metric **m; struct expr_ids *ids; int *ret; bool *has_match; @@ -1058,12 +1057,13 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, void *data) { struct metricgroup_add_iter_data *d = data; + struct metric *m = NULL; int ret; if (!match_pe_metric(pe, d->metric)) return 0; - ret = add_metric(d->metric_list, pe, d->metric_no_group, d->m, NULL, d->ids); + ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids); if (ret) return ret; @@ -1114,7 +1114,6 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, .metric_list = &list, .metric = metric, .metric_no_group = metric_no_group, - .m = &m, .ids = &ids, .has_match = &has_match, .ret = &ret, -- 2.26.2