linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Kan Liang" <kan.liang@linux.intel.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Jiapeng Chong" <jiapeng.chong@linux.alibaba.com>,
	"James Clark" <james.clark@linaro.org>,
	"Howard Chu" <howardchu95@gmail.com>,
	"Weilin Wang" <weilin.wang@intel.com>,
	"Stephen Brennan" <stephen.s.brennan@oracle.com>,
	"Andi Kleen" <ak@linux.intel.com>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/7] perf intel-tpebs: Avoid race when evlist is being deleted
Date: Tue, 27 May 2025 20:26:34 -0700	[thread overview]
Message-ID: <20250528032637.198960-5-irogers@google.com> (raw)
In-Reply-To: <20250528032637.198960-1-irogers@google.com>

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: bcfab08db7fb ("perf intel-tpebs: Filter non-workload samples")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/intel-tpebs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c
index 4ad4bc118ea5..3b92ebf5c112 100644
--- a/tools/perf/util/intel-tpebs.c
+++ b/tools/perf/util/intel-tpebs.c
@@ -162,9 +162,17 @@ static bool is_child_pid(pid_t parent, pid_t 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;
 
-- 
2.49.0.1238.gf8c92423fb-goog


  parent reply	other threads:[~2025-05-28  3:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28  3:26 [PATCH v2 0/7] Various asan and test fixes Ian Rogers
2025-05-28  3:26 ` [PATCH v2 1/7] perf symbol: Fix use-after-free in filename__read_build_id Ian Rogers
2025-05-28  3:26 ` [PATCH v2 2/7] perf test demangle-java: Don't segv if demangling fails Ian Rogers
2025-05-28  3:26 ` [PATCH v2 3/7] perf symbol: Move demangling code out of symbol-elf.c Ian Rogers
2025-05-28  3:26 ` Ian Rogers [this message]
2025-05-28 17:53   ` [PATCH v2 4/7] perf intel-tpebs: Avoid race when evlist is being deleted Namhyung Kim
2025-05-28 18:02     ` Ian Rogers
2025-05-28 20:13       ` Namhyung Kim
2025-05-28 20:44         ` Ian Rogers
2025-05-28 22:23           ` Namhyung Kim
2025-05-28  3:26 ` [PATCH v2 5/7] perf test intel-pt: Skip jitdump test if no libelf Ian Rogers
2025-05-28  3:26 ` [PATCH v2 6/7] perf test trace_summary: Skip --bpf-summary tests if no libbpf Ian Rogers
2025-05-28  4:17   ` Howard Chu
2025-05-28 12:56     ` Arnaldo Carvalho de Melo
2025-05-28  3:26 ` [PATCH v2 7/7] perf thread: Avoid recursively taking thread__comm_lock Ian Rogers
2025-05-28 18:02 ` [PATCH v2 0/7] Various asan and test fixes Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250528032637.198960-5-irogers@google.com \
    --to=irogers@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alex.gaynor@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dvyukov@google.com \
    --cc=gary@garyguo.net \
    --cc=howardchu95@gmail.com \
    --cc=james.clark@linaro.org \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stephen.s.brennan@oracle.com \
    --cc=tmgross@umich.edu \
    --cc=weilin.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).