Skip to contentSkip to conversation

tracing: Make sure RCU is watching before calling a stack trace

PATCH Superseded Steven Rostedt 2 participants 2 messages May 18, 2017 Tracing

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Make sure RCU is watching before calling a stack trace

From: "Steven Rostedt (VMware)" <[email protected]>

As stack tracing now requires "rcu watching", force RCU to be watching when recording a stack trace.

---
 kernel/trace/trace.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
kernel/trace/trace.c +22 -1
index fcc9a2d..a1b45b4 100644
@@ -2568,7 +2568,28 @@ static inline void ftrace_trace_stack(struct trace_array *tr,
 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
 		   int pc)
 {
-	__ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL);
+	struct ring_buffer *buffer = tr->trace_buffer.buffer;
+
+	/* When an NMI triggers, RCU is enabled via rcu_nmi_enter() */
+	if (in_nmi()) {
+		__ftrace_trace_stack(buffer, flags, skip, pc, NULL);
+		return;
+	}
+
+	/*
+	 * It is possible that a function is being traced in a
+	 * location that RCU is not watching. A call to
+	 * rcu_irq_enter() will make sure that it is, but there's
+	 * a few internal rcu functions that could be traced
+	 * where that wont work either. In those cases, we just
+	 * do nothing.
+	 */
+	if (unlikely(rcu_irq_enter_disabled()))
+		return;
+
+	rcu_irq_enter();
+	__ftrace_trace_stack(buffer, flags, skip, pc, NULL);
+	rcu_irq_exit();
 }
 
 /**
Signature · 1 line
2.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

As stack tracing now requires "rcu watching", force RCU to be watching when recording a stack trace.

Looks correct to me.

Quoted 41 lines
---
 kernel/trace/trace.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
kernel/trace/trace.c +22 -1
index fcc9a2d..a1b45b4 100644
@@ -2568,7 +2568,28 @@ static inline void ftrace_trace_stack(struct trace_array *tr,
 void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
 		   int pc)
 {
-	__ftrace_trace_stack(tr->trace_buffer.buffer, flags, skip, pc, NULL);
+	struct ring_buffer *buffer = tr->trace_buffer.buffer;
+
+	/* When an NMI triggers, RCU is enabled via rcu_nmi_enter() */
+	if (in_nmi()) {
+		__ftrace_trace_stack(buffer, flags, skip, pc, NULL);
+		return;
+	}
+
+	/*
+	 * It is possible that a function is being traced in a
+	 * location that RCU is not watching. A call to
+	 * rcu_irq_enter() will make sure that it is, but there's
+	 * a few internal rcu functions that could be traced
+	 * where that wont work either. In those cases, we just
+	 * do nothing.
+	 */
+	if (unlikely(rcu_irq_enter_disabled()))
+		return;
+
+	rcu_irq_enter();
+	__ftrace_trace_stack(buffer, flags, skip, pc, NULL);
+	rcu_irq_exit();
 }
 
 /**
Signature · 1 line
2.9.3