Skip to contentSkip to conversation

Fix: trace sched switch start/stop refcount racy updates

PATCH New Mathieu Desnoyers 1 participant 1 message Aug 17, 2019 Tracing

lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

PATCH 1/1 Fix: trace sched switch start/stop refcount racy updates

Reading the sched_cmdline_ref and sched_tgid_ref initial state within tracing_start_sched_switch without holding the sched_register_mutex is racy against concurrent updates, which can lead to tracepoint probes being registered more than once (and thus trigger warnings within tracepoint.c).

[ Compile-tested only. I suspect it might fix the following syzbot
report:

[email protected] ]

CC Steven Rostedt (VMware) <[email protected]>
CC Joel Fernandes (Google) <[email protected]>
CC Peter Zijlstra <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Paul E. McKenney <[email protected]>
---
 kernel/trace/trace_sched_switch.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_sched_switch.c +3 -1
index e288168661e1..e304196d7c28 100644
@@ -89,8 +89,10 @@ static void tracing_sched_unregister(void)
 
 static void tracing_start_sched_switch(int ops)
 {
-	bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref);
+	bool sched_register;
+
 	mutex_lock(&sched_register_mutex);
+	sched_register = (!sched_cmdline_ref && !sched_tgid_ref);
 
 	switch (ops) {
 	case RECORD_CMDLINE:
Signature · 1 line
2.11.0