Commit 3d6e79ee authored by John Garry's avatar John Garry Committed by Arnaldo Carvalho de Melo

perf metricgroup: Fix system PMU metrics

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: be335ec2 ("perf metricgroup: Support adding metrics for system PMUs")
Reported-by: default avatarJoakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linuxarm@openeuler.org
Link: https://lore.kernel.org/r/1611050655-44020-1-git-send-email-john.garry@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9c880c24
...@@ -773,7 +773,6 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused) ...@@ -773,7 +773,6 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
struct metricgroup_add_iter_data { struct metricgroup_add_iter_data {
struct list_head *metric_list; struct list_head *metric_list;
const char *metric; const char *metric;
struct metric **m;
struct expr_ids *ids; struct expr_ids *ids;
int *ret; int *ret;
bool *has_match; bool *has_match;
...@@ -1065,12 +1064,13 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, ...@@ -1065,12 +1064,13 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
void *data) void *data)
{ {
struct metricgroup_add_iter_data *d = data; struct metricgroup_add_iter_data *d = data;
struct metric *m = NULL;
int ret; int ret;
if (!match_pe_metric(pe, d->metric)) if (!match_pe_metric(pe, d->metric))
return 0; 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) if (ret)
return ret; return ret;
...@@ -1121,7 +1121,6 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, ...@@ -1121,7 +1121,6 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
.metric_list = &list, .metric_list = &list,
.metric = metric, .metric = metric,
.metric_no_group = metric_no_group, .metric_no_group = metric_no_group,
.m = &m,
.ids = &ids, .ids = &ids,
.has_match = &has_match, .has_match = &has_match,
.ret = &ret, .ret = &ret,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment