From: Ian Rogers Date: Wed, 28 May 2025 03:26:34 +0000 (-0700) Subject: perf intel-tpebs: Avoid race when evlist is being deleted X-Git-Tag: v6.16-rc1~57^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=040a008d0e5006123ac1b6e96b9de615e587ab7e;p=thirdparty%2Fkernel%2Flinux.git 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: bcfab08db7fb38bf ("perf intel-tpebs: Filter non-workload samples") Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alex Gaynor Cc: Alice Ryhl Cc: Andi Kleen Cc: Andreas Hindborg Cc: Benno Lossin Cc: Björn Roy Baron Cc: Boqun Feng Cc: Danilo Krummrich Cc: Dmitriy Vyukov Cc: Gary Guo Cc: Howard Chu Cc: Ingo Molnar Cc: James Clark Cc: Jiapeng Chong Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Miguel Ojeda Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephen Brennan Cc: Trevor Gross Cc: Weilin Wang Link: https://lore.kernel.org/r/20250528032637.198960-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 4ad4bc118ea5f..3b92ebf5c1121 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -162,9 +162,17 @@ new_child: static bool should_ignore_sample(const struct perf_sample *sample, const struct tpebs_retire_lat *t) { - pid_t workload_pid = t->evsel->evlist->workload.pid; - pid_t sample_pid = sample->pid; + pid_t workload_pid, sample_pid = sample->pid; + /* + * During evlist__purge the evlist will be removed prior to the + * evsel__exit calling evsel__tpebs_close and taking the + * tpebs_mtx. Avoid a segfault by ignoring samples in this case. + */ + if (t->evsel->evlist == NULL) + return true; + + workload_pid = t->evsel->evlist->workload.pid; if (workload_pid < 0 || workload_pid == sample_pid) return false;