]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf intel-tpebs: Avoid race when evlist is being deleted
authorIan Rogers <irogers@google.com>
Wed, 28 May 2025 03:26:34 +0000 (20:26 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 28 May 2025 13:12:47 +0000 (10:12 -0300)
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 <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>
tools/perf/util/intel-tpebs.c

index 4ad4bc118ea5f52ba61349fc702c3002fff45b01..3b92ebf5c1121889a6a8f95e802c57c8a65f6672 100644 (file)
@@ -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;