public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tracing: Make sure RCU is watching before calling a stack trace
@ 2017-05-18 13:38 Steven Rostedt
  2017-05-18 13:48 ` Miroslav Benes
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Steven Rostedt @ 2017-05-18 13:38 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: LKML, Ingo Molnar, Thomas Gleixner


From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

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

Link: http://lkml.kernel.org/r/20170512172449.879684501@goodmis.org

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---

Changes since v1:

   My testing discovered that the stack trace can be called with
   interrupts enabled, which is a no no to have when calling
   rcu_irq_enter(). When interrupts are enabled, as with being in an
   NMI, RCU will also be watching.

kernel/trace/trace.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index fcc9a2d..34a98ba 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2568,7 +2568,31 @@ 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()
+	 * Also, RCU is always enabled when interrupts are.
+	 */
+	if (!irqs_disabled() || 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();
 }
 
 /**
-- 
2.9.3

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

end of thread, other threads:[~2017-05-18 19:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-18 13:38 [PATCH v2] tracing: Make sure RCU is watching before calling a stack trace Steven Rostedt
2017-05-18 13:48 ` Miroslav Benes
2017-05-18 14:04   ` Steven Rostedt
2017-05-18 18:18     ` Miroslav Benes
2017-05-18 14:50 ` Steven Rostedt
2017-05-18 15:47 ` Paul E. McKenney
2017-05-18 16:39   ` Steven Rostedt
2017-05-18 18:45     ` Paul E. McKenney
2017-05-18 19:30       ` Steven Rostedt
2017-05-18 19:50         ` Paul E. McKenney

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