Re: [PATCH 2/2] ftrace: prevent preemption in perf_ftrace_function_call()

From
Peter Zijlstra <peterz@infradead.org>
Date
2021-10-12 11:21:54
Also in
linux-riscv, live-patching, lkml
Reply to
王贇, 2021-10-12
On Tue, Oct 12, 2021 at 01:40:31PM +0800, 王贇 wrote:
quoted hunk ↗ jump to hunk
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 6aed10e..33c2f76 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -441,12 +441,19 @@ void perf_trace_buf_update(void *record, u16 type)
 	if (!rcu_is_watching())
 		return;

+	/*
+	 * Prevent CPU changing from now on. rcu must
+	 * be in watching if the task was migrated and
+	 * scheduled.
+	 */
+	preempt_disable_notrace();
+
 	if ((unsigned long)ops->private != smp_processor_id())
-		return;
+		goto out;

 	bit = ftrace_test_recursion_trylock(ip, parent_ip);
 	if (bit < 0)
-		return;
+		goto out;

 	event = container_of(ops, struct perf_event, ftrace_ops);
This seems rather daft, wouldn't it be easier to just put that check
under the recursion thing?
Thread (24 messages) 24 messages, 5 authors, last reply 2021-10-26
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help