Skip to content

Commit 64f18d2

Browse files
yaowenbinacmel
authored andcommitted
perf top: Fix TUI exit screen refresh race condition
When the following command is executed several times, a coredump file is generated. $ timeout -k 9 5 perf top -e task-clock ******* ******* ******* 0.01% [kernel] [k] __do_softirq 0.01% libpthread-2.28.so [.] __pthread_mutex_lock 0.01% [kernel] [k] __ll_sc_atomic64_sub_return double free or corruption (!prev) perf top --sort comm,dso timeout: the monitored command dumped core When we terminate "perf top" using sending signal method, SLsmg_reset_smg() called. SLsmg_reset_smg() resets the SLsmg screen management routines by freeing all memory allocated while it was active. However SLsmg_reinit_smg() maybe be called by another thread. SLsmg_reinit_smg() will free the same memory accessed by SLsmg_reset_smg(), thus it results in a double free. SLsmg_reinit_smg() is called already protected by ui__lock, so we fix the problem by adding pthread_mutex_trylock of ui__lock when calling SLsmg_reset_smg(). Signed-off-by: Wenyu Liu <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Hewenliang <[email protected]> Signed-off-by: yaowenbin <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e0257a0 commit 64f18d2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/perf/ui/tui/setup.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ void ui__exit(bool wait_for_ok)
170170
"Press any key...", 0);
171171

172172
SLtt_set_cursor_visibility(1);
173-
SLsmg_refresh();
174-
SLsmg_reset_smg();
173+
if (!pthread_mutex_trylock(&ui__lock)) {
174+
SLsmg_refresh();
175+
SLsmg_reset_smg();
176+
pthread_mutex_unlock(&ui__lock);
177+
}
175178
SLang_reset_tty();
176-
177179
perf_error__unregister(&perf_tui_eops);
178180
}

0 commit comments

Comments
 (0)