Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] perf: Add RCU read lock protection to perf_iterate_ctx()
@ 2025-01-17 14:41 Breno Leitao
  2025-02-24 12:30 ` Peter Zijlstra
  2025-02-24 18:36 ` [tip: perf/urgent] perf/core: " tip-bot2 for Breno Leitao
  0 siblings, 2 replies; 3+ messages in thread
From: Breno Leitao @ 2025-01-17 14:41 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Ravi Bangoria
  Cc: linux-perf-users, linux-kernel, kuba, kernel-team, stable,
	Breno Leitao

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().

CC: stable@vger.kernel.org
Fixes: bd2756811766 ("perf: Rewrite core context handling")
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 kernel/events/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 065f9188b44a0d8ee66cc76314ae247dbe45cb57..e2adb06f8d81307b2762375474bee1c9e8a74598 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8277,7 +8277,9 @@ void perf_event_exec(void)
 
 	perf_event_enable_on_exec(ctx);
 	perf_event_remove_on_exec(ctx);
+	rcu_read_lock();
 	perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL, true);
+	rcu_read_unlock();
 
 	perf_unpin_context(ctx);
 	put_ctx(ctx);

---
base-commit: dbb0aea70ce4b85915a52d7adf9af57bd80f330a
change-id: 20250117-fix_perf_rcu-2ff93190950a

Best regards,
-- 
Breno Leitao <leitao@debian.org>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-24 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-02-24 18:36 ` [tip: perf/urgent] perf/core: " tip-bot2 for Breno Leitao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox