Skip to content

Commit 31062b6

Browse files
axiqiaopsiff
authored andcommitted
perf record: skip synthesize event when open evsel failed
[ Upstream commit 163e5f2 ] When using perf record with the `--overwrite` option, a segmentation fault occurs if an event fails to open. For example: perf record -e cycles-ct -F 1000 -a --overwrite Error: cycles-ct:H: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat' perf: Segmentation fault #0 0x6466b6 in dump_stack debug.c:366 #1 0x646729 in sighandler_dump_stack debug.c:378 #2 0x453fd1 in sigsegv_handler builtin-record.c:722 #3 0x7f8454e65090 in __restore_rt libc-2.32.so[54090] #4 0x6c5671 in __perf_event__synthesize_id_index synthetic-events.c:1862 deepin-community#5 0x6c5ac0 in perf_event__synthesize_id_index synthetic-events.c:1943 deepin-community#6 0x458090 in record__synthesize builtin-record.c:2075 deepin-community#7 0x45a85a in __cmd_record builtin-record.c:2888 deepin-community#8 0x45deb6 in cmd_record builtin-record.c:4374 deepin-community#9 0x4e5e33 in run_builtin perf.c:349 deepin-community#10 0x4e60bf in handle_internal_command perf.c:401 deepin-community#11 0x4e6215 in run_argv perf.c:448 deepin-community#12 0x4e653a in main perf.c:555 deepin-community#13 0x7f8454e4fa72 in __libc_start_main libc-2.32.so[3ea72] deepin-community#14 0x43a3ee in _start ??:0 The --overwrite option implies --tail-synthesize, which collects non-sample events reflecting the system status when recording finishes. However, when evsel opening fails (e.g., unsupported event 'cycles-ct'), session->evlist is not initialized and remains NULL. The code unconditionally calls record__synthesize() in the error path, which iterates through the NULL evlist pointer and causes a segfault. To fix it, move the record__synthesize() call inside the error check block, so it's only called when there was no error during recording, ensuring that evlist is properly initialized. Fixes: 4ea648a ("perf record: Add --tail-synthesize option") Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 3a3dff0a73ba27c7c2e285a83ee6a8df5012f6b4) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 8bee378 commit 31062b6

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tools/perf/builtin-record.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2832,11 +2832,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
28322832
rec->bytes_written += off_cpu_write(rec->session);
28332833

28342834
record__read_lost_samples(rec);
2835-
record__synthesize(rec, true);
28362835
/* this will be recalculated during process_buildids() */
28372836
rec->samples = 0;
28382837

28392838
if (!err) {
2839+
record__synthesize(rec, true);
28402840
if (!rec->timestamp_filename) {
28412841
record__finish_output(rec);
28422842
} else {

0 commit comments

Comments
 (0)