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

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:

Fixes: 7ac0089d138f80dc ("perf evsel: Pass cpu not cpu map index to synthesize")
Reported-by: Michael Petlan <>
Suggested-by: Michael Petlan <>
Signed-off-by: Ian Rogers <>
Cc: Alexander Shishkin <>
Cc: Alexei Starovoitov <>
Cc: Andrii Nakryiko <>
Cc: Daniel Borkmann <>
Cc: Dave Marchevsky <>
Cc: Ian Rogers <>
Cc: James Clark <>
Cc: Jiri Olsa <>
Cc: John Fastabend <>
Cc: Kan Liang <>
Cc: KP Singh <>
Cc: Lv Ruyi <>
Cc: Mark Rutland <>
Cc: Martin KaFai Lau <>
Cc: Michael Petlan <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Quentin Monnet <>
Cc: Song Liu <>
Cc: Stephane Eranian <>
Cc: Xing Zhengjun <>
Cc: Yonghong Song <>
Signed-off-by: Arnaldo Carvalho de Melo <>
1 file changed