Skip to contentSkip to conversation

perf metrics: Fix segv with --for-each-cgroup

PATCH In review Ian Rogers 2 participants 2 messages May 5, 2023 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf metrics: Fix segv with --for-each-cgroup

Ensure the metric threshold is copied correctly or else a use of uninitialized memory happens.

Fixes d0a3052f6fae ("perf metric: Compute and print threshold values")
---
 tools/perf/util/metricgroup.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/metricgroup.c +1 -0
index 4b9a16291b96..c566c6859302 100644
@@ -1730,6 +1730,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
 				return -ENOMEM;
 
 			new_expr->metric_expr = old_expr->metric_expr;
+			new_expr->metric_threshold = old_expr->metric_threshold;
 			new_expr->metric_name = strdup(old_expr->metric_name);
 			if (!new_expr->metric_name)
 				return -ENOMEM;
Signature · 1 line
2.40.1.521.gf1e218fcd8-goog
maintainer Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ian Rogers

Ensure the metric threshold is copied correctly or else a use of uninitialized memory happens.

Fixes d0a3052f6fae ("perf metric: Compute and print threshold values")

Thanks for the fix. Now it runs ok

  $ sudo ./perf stat -a --bpf-counters \
Quoted 1 line

--for-each-cgroup user.slice,system.slice sleep 1

Thanks,
Namhyung

Quoted 19 lines
---
 tools/perf/util/metricgroup.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/metricgroup.c +1 -1
index 4b9a16291b96..c566c6859302 100644
@@ -1730,6 +1730,7 @@ int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
                                return -ENOMEM;
 
                        new_expr->metric_expr = old_expr->metric_expr;
+                       new_expr->metric_threshold = old_expr->metric_threshold;
                        new_expr->metric_name = strdup(old_expr->metric_name);
                        if (!new_expr->metric_name)
                                return -ENOMEM;
--

2.40.1.521.gf1e218fcd8-goog