public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	zhiping zhong <xzhong86@163.com>,
	wu zhangjin <wuzhangjin@gmail.com>
Subject: [PATCH 11/15] ftrace/graph: Trace function entry before updating index
Date: Thu, 10 Mar 2011 10:58:11 -0500	[thread overview]
Message-ID: <20110310155911.781601308@goodmis.org> (raw)
In-Reply-To: 20110310155800.478792851@goodmis.org

[-- Attachment #1: 0011-ftrace-graph-Trace-function-entry-before-updating-in.patch --]
[-- Type: text/plain, Size: 2245 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Currently the index to the ret_stack is updated and the real return address
is saved in the ret_stack. Then we call the trace function. The trace
function could decide that it doesn't want to trace this function
(ex. set_graph_function does not match) and it will return 0 which means
not to trace this call.

The normal function graph tracer has this code:

	if (!(trace->depth || ftrace_graph_addr(trace->func)) ||
	      ftrace_graph_ignore_irqs())
		return 0;

What this states is, if the trace depth (which is curr_ret_stack)
is zero (top of nested functions) then test if we want to trace this
function. If this function is not to be traced, then return  0 and
the rest of the function graph tracer logic will not trace this function.

The problem arises when an interrupt comes in after we updated the
curr_ret_stack. The next function that gets called will have a trace->depth
of 1. Which fools this trace code into thinking that we are in a nested
function, and that we should trace. This causes interrupts to be traced
when they should not be.

The solution is to trace the function first and then update the ret_stack.

Reported-by: zhiping zhong <xzhong86@163.com>
Reported-by: wu zhangjin <wuzhangjin@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 arch/x86/kernel/ftrace.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 382eb29..a93742a 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -437,18 +437,19 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 		return;
 	}
 
-	if (ftrace_push_return_trace(old, self_addr, &trace.depth,
-		    frame_pointer) == -EBUSY) {
-		*parent = old;
-		return;
-	}
-
 	trace.func = self_addr;
+	trace.depth = current->curr_ret_stack + 1;
 
 	/* Only trace if the calling function expects to */
 	if (!ftrace_graph_entry(&trace)) {
-		current->curr_ret_stack--;
 		*parent = old;
+		return;
+	}
+
+	if (ftrace_push_return_trace(old, self_addr, &trace.depth,
+		    frame_pointer) == -EBUSY) {
+		*parent = old;
+		return;
 	}
 }
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
-- 
1.7.2.3



  parent reply	other threads:[~2011-03-10 15:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-10 15:58 [PATCH 00/15] [GIT PULL] tracing: updates for 2.6.39 Steven Rostedt
2011-03-10 15:58 ` [PATCH 01/15] tracing: Add an overwrite trace_option Steven Rostedt
2011-03-10 15:58 ` [PATCH 02/15] ring-buffer: Remove unused #include <linux/trace_irq.h> Steven Rostedt
2011-03-10 15:58 ` [PATCH 03/15] tracing: Remove lock_depth from event entry Steven Rostedt
2011-03-10 15:58 ` [PATCH 04/15] tracing: Fix event alignment: ftrace:context_switch and ftrace:wakeup Steven Rostedt
2011-03-10 15:58 ` [PATCH 05/15] tracing: Fix event alignment: module:module_request Steven Rostedt
2011-03-10 15:58 ` [PATCH 06/15] tracing: Fix event alignment: kvm:kvm_hv_hypercall Steven Rostedt
2011-03-10 15:58 ` [PATCH 07/15] tracing: Fix event alignment: mce:mce_record Steven Rostedt
2011-03-10 15:58 ` [PATCH 08/15] tracing: Fix event alignment: skb:kfree_skb Steven Rostedt
2011-03-10 15:58 ` [PATCH 09/15] tracing: Adjust conditional expression latency formatting Steven Rostedt
2011-03-10 15:58 ` [PATCH 10/15] ftrace: Add .ref.text as one of the safe areas to trace Steven Rostedt
2011-03-10 15:58 ` Steven Rostedt [this message]
2011-03-10 15:58 ` [PATCH 12/15] tracing: Explain about unstable clock on resume with ring buffer warning Steven Rostedt
2011-03-10 15:58 ` [PATCH 13/15] tracing: Export trace_set_clr_event() Steven Rostedt
2011-03-10 15:58 ` [PATCH 14/15] tracing: Align 4 byte ints together in struct tracer Steven Rostedt
2011-03-10 15:58 ` [PATCH 15/15] tracing: Fix irqoff selftest expanding max buffer Steven Rostedt
2011-03-11  8:27 ` [PATCH 00/15] [GIT PULL] tracing: updates for 2.6.39 Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110310155911.781601308@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=wuzhangjin@gmail.com \
    --cc=xzhong86@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox