[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250528032637.198960-8-irogers@google.com>
Date: Tue, 27 May 2025 20:26:37 -0700
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
"Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>, James Clark <james.clark@...aro.org>,
Howard Chu <howardchu95@...il.com>, Weilin Wang <weilin.wang@...el.com>,
Stephen Brennan <stephen.s.brennan@...cle.com>, Andi Kleen <ak@...ux.intel.com>,
Dmitry Vyukov <dvyukov@...gle.com>, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 7/7] perf thread: Avoid recursively taking thread__comm_lock
Fix cases where functions that take thread_comm_lcok were called
holding thread__comm_lock. This created some buggy behavior in perf
top when built with sanitizers. Ensure -Wthread-safety warnings for
clang work.
Fixes: 8f454c95817d ("perf thread: Ensure comm_lock held for comm_list")
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
tools/perf/util/thread.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index c202b98b36c2..f4ad15e1e314 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -201,13 +201,21 @@ int thread__set_namespaces(struct thread *thread, u64 timestamp,
return ret;
}
+static struct comm *__thread__comm(struct thread *thread)
+ SHARED_LOCKS_REQUIRED(thread__comm_lock(thread))
+{
+ if (list_empty(thread__comm_list(thread)))
+ return NULL;
+
+ return list_first_entry(thread__comm_list(thread), struct comm, list);
+}
+
struct comm *thread__comm(struct thread *thread)
{
struct comm *res = NULL;
down_read(thread__comm_lock(thread));
- if (!list_empty(thread__comm_list(thread)))
- res = list_first_entry(thread__comm_list(thread), struct comm, list);
+ res = __thread__comm(thread);
up_read(thread__comm_lock(thread));
return res;
}
@@ -243,7 +251,7 @@ static int ____thread__set_comm(struct thread *thread, const char *str,
u64 timestamp, bool exec)
EXCLUSIVE_LOCKS_REQUIRED(thread__comm_lock(thread))
{
- struct comm *new, *curr = thread__comm(thread);
+ struct comm *new, *curr = __thread__comm(thread);
/* Override the default :tid entry */
if (!thread__comm_set(thread)) {
@@ -294,8 +302,9 @@ int thread__set_comm_from_proc(struct thread *thread)
}
static const char *__thread__comm_str(struct thread *thread)
+ SHARED_LOCKS_REQUIRED(thread__comm_lock(thread))
{
- const struct comm *comm = thread__comm(thread);
+ const struct comm *comm = __thread__comm(thread);
if (!comm)
return NULL;
--
2.49.0.1238.gf8c92423fb-goog
Powered by blists - more mailing lists