Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Fix crash on synthesizing the unit

Adam reported a record command crash for simple session like:

$ perf record -e cpu-clock ls

with following backtrace:

Program received signal SIGSEGV, Segmentation fault.
3543 ev = event_update_event__new(size + 1, PERF_EVENT_UPDATE__UNIT, evsel->id[0]);
(gdb) bt
#0 perf_event__synthesize_event_update_unit
#1 0x000000000051e469 in perf_event__synthesize_extra_attr
#2 0x00000000004445cb in record__synthesize
#3 0x0000000000444bc5 in __cmd_record
...

We synthesize an update event that needs to touch the evsel id array,
which is not defined at that time. Fix this by forcing the id allocation
for events with their unit defined.

Reflecting possible read_format ID bit in the attr tests.

Reported-by: Yongxin Liu <yongxin.liu@outlook.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adam Lee <leeadamrobert@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201477
Fixes: bfd8f72c2778 ("perf record: Synthesize unit/scale/... in event update")
Link: http://lkml.kernel.org/r/20181112130012.5424-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
fb50c09e 4d47d640

+2 -2
+1 -1
tools/perf/tests/attr/base-record
··· 9 9 config=0 10 10 sample_period=* 11 11 sample_type=263 12 - read_format=0 12 + read_format=0|4 13 13 disabled=1 14 14 inherit=1 15 15 pinned=0
+1 -1
tools/perf/util/evsel.c
··· 1092 1092 attr->exclude_user = 1; 1093 1093 } 1094 1094 1095 - if (evsel->own_cpus) 1095 + if (evsel->own_cpus || evsel->unit) 1096 1096 evsel->attr.read_format |= PERF_FORMAT_ID; 1097 1097 1098 1098 /*