From: Steven Rostedt <rostedt@goodmis.org>
To: Wu Zhangjin <wuzhangjin@gmail.com>
Cc: linux-mips@linux-mips.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ralf Baechle <ralf@linux-mips.org>,
Nicholas Mc Guire <der.herr@hofr.at>,
Richard Sandiford <rdsandiford@googlemail.com>,
David Daney <ddaney@caviumnetworks.com>,
Adam Nemet <anemet@caviumnetworks.com>,
Patrik Kluba <kpajko79@gmail.com>
Subject: Re: [PATCH -v5 10/11] tracing: add function graph tracer support for MIPS
Date: Mon, 26 Oct 2009 11:13:21 -0400 [thread overview]
Message-ID: <1256570001.26028.298.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <ac9c325539cc056d9539c96a68743a425f9612ce.1256483735.git.wuzhangjin@gmail.com>
On Sun, 2009-10-25 at 23:17 +0800, Wu Zhangjin wrote:
> +
> +unsigned long ftrace_get_parent_addr(unsigned long self_addr,
> + unsigned long parent,
> + unsigned long parent_addr,
> + unsigned long fp)
> +{
> + unsigned long sp, ip, ra;
> + unsigned int code;
> +
> + /* move to the instruction "move ra, at" */
> + ip = self_addr - 8;
> +
> + /* search the text until finding the "move s8, sp" instruction or
> + * "s{d,w} ra, offset(sp)" instruction */
> + do {
> + ip -= 4;
> +
> + /* get the code at "ip" */
> + code = *(unsigned int *)ip;
Probably want to put the above in an asm with exception handling.
> +
> + /* If we hit the "move s8(fp), sp" instruction before finding
> + * where the ra is stored, then this is a leaf function and it
> + * does not store the ra on the stack. */
> + if ((code & MOV_FP_SP) == MOV_FP_SP)
> + return parent_addr;
> + } while (((code & S_RA) != S_RA));
Hmm, that condition also looks worrisome. Should we just always search
for s{d,w} R,X(sp)?
Since there should only be stores of registers into the sp above the
jump to mcount. The break out loop is a check for move. I think it would
be safer to have the break out loop is a check for non storing of a
register into SP.
> +
> + sp = fp + (code & STACK_OFFSET_MASK);
> + ra = *(unsigned long *)sp;
Also might want to make the above into a asm with exception handling.
> +
> + if (ra == parent)
> + return sp;
> +
> + ftrace_graph_stop();
> + WARN_ON(1);
> + return parent_addr;
Hmm, may need to do more than this. See below.
> +}
> +
> +/*
> + * Hook the return address and push it in the stack of return addrs
> + * in current thread info.
> + */
> +void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
> + unsigned long fp)
> +{
> + unsigned long old;
> + struct ftrace_graph_ent trace;
> + unsigned long return_hooker = (unsigned long)
> + &return_to_handler;
> +
> + if (unlikely(atomic_read(¤t->tracing_graph_pause)))
> + return;
> +
> + /* "parent" is the stack address saved the return address of the caller
> + * of _mcount, for a leaf function not save the return address in the
> + * stack address, so, we "emulate" one in _mcount's stack space, and
> + * hijack it directly, but for a non-leaf function, it will save the
> + * return address to the its stack space, so, we can not hijack the
> + * "parent" directly, but need to find the real stack address,
> + * ftrace_get_parent_addr() does it!
> + */
> +
> + old = *parent;
> +
> + parent = (unsigned long *)ftrace_get_parent_addr(self_addr, old,
> + (unsigned long)parent,
> + fp);
> +
> + *parent = return_hooker;
Although you may have turned off fgraph tracer in
ftrace_get_parent_addr, nothing stops the below from messing with the
stack. The return stack may get off sync and break later. If you fail
the above, you should not be calling the push function below.
-- Steve
> +
> + if (ftrace_push_return_trace(old, self_addr, &trace.depth, fp) ==
> + -EBUSY) {
> + *parent = old;
> + return;
> + }
> +
> + trace.func = self_addr;
> +
> + /* Only trace if the calling function expects to */
> + if (!ftrace_graph_entry(&trace)) {
> + current->curr_ret_stack--;
> + *parent = old;
> + }
> +}
> +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
next prev parent reply other threads:[~2009-10-26 15:13 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-25 15:16 [PATCH -v5 00/11] ftrace " Wu Zhangjin
2009-10-26 0:42 ` Frederic Weisbecker
[not found] ` <cover.1256483735.git.wuzhangjin@gmail.com>
2009-10-25 15:16 ` [PATCH -v5 01/11] tracing: convert trace_clock_local() as weak function Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 02/11] MIPS: add mips_timecounter_read() to get high precision timestamp Wu Zhangjin
2009-10-26 14:01 ` Steven Rostedt
2009-10-26 14:25 ` Wu Zhangjin
2009-10-26 14:34 ` Steven Rostedt
2009-10-26 14:42 ` Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 03/11] tracing: add MIPS specific trace_clock_local() Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 04/11] tracing: add static function tracer support for MIPS Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 05/11] tracing: enable HAVE_FUNCTION_TRACE_MCOUNT_TEST " Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 06/11] tracing: add an endian argument to scripts/recordmcount.pl Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 07/11] tracing: add dynamic function tracer support for MIPS Wu Zhangjin
2009-10-25 15:16 ` [PATCH -v5 08/11] tracing: not trace mips_timecounter_init() in MIPS Wu Zhangjin
2009-10-26 0:27 ` Frederic Weisbecker
2009-10-26 9:42 ` Wu Zhangjin
2009-11-02 21:43 ` Frederic Weisbecker
2009-11-03 1:34 ` Wu Zhangjin
2009-11-09 4:31 ` Wu Zhangjin
2009-11-09 11:53 ` Frederic Weisbecker
2009-11-09 12:08 ` Wu Zhangjin
2009-11-09 12:54 ` Steven Rostedt
2009-11-09 14:35 ` Wu Zhangjin
2009-10-25 15:17 ` [PATCH -v5 09/11] tracing: add IRQENTRY_EXIT for MIPS Wu Zhangjin
2009-10-26 0:36 ` Frederic Weisbecker
2009-10-26 7:26 ` Wu Zhangjin
2009-10-27 17:39 ` Frederic Weisbecker
2009-10-27 17:46 ` Frederic Weisbecker
2009-10-25 15:17 ` [PATCH -v5 10/11] tracing: add function graph tracer support " Wu Zhangjin
2009-10-26 15:13 ` Steven Rostedt [this message]
2009-10-26 16:11 ` Wu Zhangjin
2009-10-26 16:32 ` Steven Rostedt
2009-10-26 16:57 ` Wu Zhangjin
2009-10-26 17:11 ` Steven Rostedt
2009-10-25 15:17 ` [PATCH -v5 11/11] tracing: add dynamic function graph tracer " Wu Zhangjin
2009-10-26 1:13 ` [PATCH -v5 10/11] tracing: add function graph tracer support " Wu Zhangjin
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=1256570001.26028.298.camel@gandalf.stny.rr.com \
--to=rostedt@goodmis.org \
--cc=anemet@caviumnetworks.com \
--cc=ddaney@caviumnetworks.com \
--cc=der.herr@hofr.at \
--cc=kpajko79@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=rdsandiford@googlemail.com \
--cc=tglx@linutronix.de \
--cc=wuzhangjin@gmail.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
all inboxes | Powered by JetHome®