From: Peter Zijlstra <peterz@infradead.org>
To: Breno Leitao <leitao@debian.org>
Cc: 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>,
Ravi Bangoria <ravi.bangoria@amd.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
kuba@kernel.org, kernel-team@meta.com, stable@vger.kernel.org
Subject: Re: [PATCH] perf: Add RCU read lock protection to perf_iterate_ctx()
Date: Mon, 24 Feb 2025 13:30:16 +0100 [thread overview]
Message-ID: <20250224123016.GA17456@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250117-fix_perf_rcu-v1-1-13cb9210fc6a@debian.org>
On Fri, Jan 17, 2025 at 06:41:07AM -0800, Breno Leitao wrote:
> The perf_iterate_ctx() function performs RCU list traversal but
> currently lacks RCU read lock protection. This causes lockdep warnings
> when running perf probe with unshare(1) under CONFIG_PROVE_RCU_LIST=y:
>
> WARNING: suspicious RCU usage
> kernel/events/core.c:8168 RCU-list traversed in non-reader section!!
>
> Call Trace:
> lockdep_rcu_suspicious
> ? perf_event_addr_filters_apply
> perf_iterate_ctx
> perf_event_exec
> begin_new_exec
> ? load_elf_phdrs
> load_elf_binary
> ? lock_acquire
> ? find_held_lock
> ? bprm_execve
> bprm_execve
> do_execveat_common.isra.0
> __x64_sys_execve
> do_syscall_64
> entry_SYSCALL_64_after_hwframe
>
> This protection was previously present but was removed in commit
> bd2756811766 ("perf: Rewrite core context handling"). Add back the
> necessary rcu_read_lock()/rcu_read_unlock() pair around
> perf_iterate_ctx() call in perf_event_exec().
Hurm, I think it got ripped out because we no longer need to refer that
perf_event_ctxp[].
Anyway, please write it like so:
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0f8c55990783..b77f95089d62 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8320,7 +8320,8 @@ void perf_event_exec(void)
perf_event_enable_on_exec(ctx);
perf_event_remove_on_exec(ctx);
- perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL, true);
+ scoped_guard(rcu)
+ perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL, true);
perf_unpin_context(ctx);
put_ctx(ctx);
next prev parent reply other threads:[~2025-02-24 12:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 14:41 [PATCH] perf: Add RCU read lock protection to perf_iterate_ctx() Breno Leitao
2025-02-24 12:30 ` Peter Zijlstra [this message]
2025-02-24 18:36 ` [tip: perf/urgent] perf/core: " tip-bot2 for Breno Leitao
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=20250224123016.GA17456@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--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=ravi.bangoria@amd.com \
--cc=stable@vger.kernel.org \
/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