Skip to content

Commit 040a008

Browse files
captain5050acmel
authored andcommitted
perf intel-tpebs: Avoid race when evlist is being deleted
Reading through the evsel->evlist may seg fault if a sample arrives when the evlist is being deleted. Detect this case and ignore samples arriving when the evlist is being deleted. Fixes: bcfab08 ("perf intel-tpebs: Filter non-workload samples") Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: Alice Ryhl <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Benno Lossin <[email protected]> Cc: Björn Roy Baron <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Dmitriy Vyukov <[email protected]> Cc: Gary Guo <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiapeng Chong <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephen Brennan <[email protected]> Cc: Trevor Gross <[email protected]> Cc: Weilin Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 07f2b12 commit 040a008

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/perf/util/intel-tpebs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,17 @@ static bool is_child_pid(pid_t parent, pid_t child)
162162

163163
static bool should_ignore_sample(const struct perf_sample *sample, const struct tpebs_retire_lat *t)
164164
{
165-
pid_t workload_pid = t->evsel->evlist->workload.pid;
166-
pid_t sample_pid = sample->pid;
165+
pid_t workload_pid, sample_pid = sample->pid;
167166

167+
/*
168+
* During evlist__purge the evlist will be removed prior to the
169+
* evsel__exit calling evsel__tpebs_close and taking the
170+
* tpebs_mtx. Avoid a segfault by ignoring samples in this case.
171+
*/
172+
if (t->evsel->evlist == NULL)
173+
return true;
174+
175+
workload_pid = t->evsel->evlist->workload.pid;
168176
if (workload_pid < 0 || workload_pid == sample_pid)
169177
return false;
170178

0 commit comments

Comments
 (0)