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 <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andreas Hindborg <a.hindborg@kernel.org> Cc: Benno Lossin <benno.lossin@proton.me> Cc: Björn Roy Baron <bjorn3_gh@protonmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Gary Guo <gary@garyguo.net> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Trevor Gross <tmgross@umich.edu> Cc: Weilin Wang <weilin.wang@intel.com> Link: https://lore.kernel.org/r/20250528032637.198960-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
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)