Patch "perf stat: Fix and validate CPU map inputs in synthetic PERF_RECORD_STAT events" has been added to the 5.17-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    perf stat: Fix and validate CPU map inputs in synthetic PERF_RECORD_STAT events

to the 5.17-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     perf-stat-fix-and-validate-cpu-map-inputs-in-synthet.patch
and it can be found in the queue-5.17 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f473626d9825cb552ac80d519489a96c1040d552
Author: Ian Rogers <irogers@xxxxxxxxxx>
Date:   Wed May 18 20:20:01 2022 -0700

    perf stat: Fix and validate CPU map inputs in synthetic PERF_RECORD_STAT events
    
    [ Upstream commit 92d579ea3279aa87392b862df5810f0a7e30fcc6 ]
    
    Stat events can come from disk and so need a degree of validation. They
    contain a CPU which needs looking up via CPU map to access a counter.
    
    Add the CPU to index translation, alongside validity checking.
    
    Discussion thread:
    
      https://lore.kernel.org/linux-perf-users/CAP-5=fWQR=sCuiSMktvUtcbOLidEpUJLCybVF6=BRvORcDOq+g@xxxxxxxxxxxxxx/
    
    Fixes: 7ac0089d138f80dc ("perf evsel: Pass cpu not cpu map index to synthesize")
    Reported-by: Michael Petlan <mpetlan@xxxxxxxxxx>
    Suggested-by: Michael Petlan <mpetlan@xxxxxxxxxx>
    Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
    Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
    Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
    Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Cc: Dave Marchevsky <davemarchevsky@xxxxxx>
    Cc: Ian Rogers <irogers@xxxxxxxxxx>
    Cc: James Clark <james.clark@xxxxxxx>
    Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
    Cc: John Fastabend <john.fastabend@xxxxxxxxx>
    Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
    Cc: KP Singh <kpsingh@xxxxxxxxxx>
    Cc: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
    Cc: Mark Rutland <mark.rutland@xxxxxxx>
    Cc: Martin KaFai Lau <kafai@xxxxxx>
    Cc: Michael Petlan <mpetlan@xxxxxxxxxx>
    Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
    Cc: netdev@xxxxxxxxxxxxxxx
    Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
    Cc: Quentin Monnet <quentin@xxxxxxxxxxxxx>
    Cc: Song Liu <songliubraving@xxxxxx>
    Cc: Stephane Eranian <eranian@xxxxxxxxxx>
    Cc: Xing Zhengjun <zhengjun.xing@xxxxxxxxxxxxxxx>
    Cc: Yonghong Song <yhs@xxxxxx>
    Link: http://lore.kernel.org/lkml/20220519032005.1273691-2-irogers@xxxxxxxxxx
    Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index ee6f03481215..9c230b908b76 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -471,9 +471,10 @@ int perf_stat_process_counter(struct perf_stat_config *config,
 int perf_event__process_stat_event(struct perf_session *session,
 				   union perf_event *event)
 {
-	struct perf_counts_values count;
+	struct perf_counts_values count, *ptr;
 	struct perf_record_stat *st = &event->stat;
 	struct evsel *counter;
+	int cpu_map_idx;
 
 	count.val = st->val;
 	count.ena = st->ena;
@@ -484,8 +485,18 @@ int perf_event__process_stat_event(struct perf_session *session,
 		pr_err("Failed to resolve counter for stat event.\n");
 		return -EINVAL;
 	}
-
-	*perf_counts(counter->counts, st->cpu, st->thread) = count;
+	cpu_map_idx = perf_cpu_map__idx(evsel__cpus(counter), (struct perf_cpu){.cpu = st->cpu});
+	if (cpu_map_idx == -1) {
+		pr_err("Invalid CPU %d for event %s.\n", st->cpu, evsel__name(counter));
+		return -EINVAL;
+	}
+	ptr = perf_counts(counter->counts, cpu_map_idx, st->thread);
+	if (ptr == NULL) {
+		pr_err("Failed to find perf count for CPU %d thread %d on event %s.\n",
+			st->cpu, st->thread, evsel__name(counter));
+		return -EINVAL;
+	}
+	*ptr = count;
 	counter->supported = true;
 	return 0;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux