From: Borislav Petkov <bp@alien8.de>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Jiri Kosina <jkosina@suse.cz>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Vojtech Pavlik <vojtech@suse.cz>,
Seth Jennings <sjenning@redhat.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
"H. Peter Anvin" <hpa@linux.intel.com>
Subject: Re: [for-next][PATCH 2/4] ftrace/x86: Show trampoline call function in enabled_functions
Date: Wed, 5 Nov 2014 11:42:07 +0100 [thread overview]
Message-ID: <20141105104207.GB5245@pd.tnic> (raw)
In-Reply-To: <20141027182948.432689737@goodmis.org>
On Mon, Oct 27, 2014 at 02:27:04PM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
>
> The file /sys/kernel/debug/tracing/eneabled_functions is used to debug
> ftrace function hooks. Add to the output what function is being called
> by the trampoline if the arch supports it.
>
> Add support for this feature in x86_64.
>
> Cc: H. Peter Anvin <hpa@linux.intel.com>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
> arch/x86/kernel/ftrace.c | 98 ++++++++++++++++++++++++++++++++++++++++++------
> kernel/trace/ftrace.c | 22 ++++++++++-
> 2 files changed, 106 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
> index e4d48f6cad86..ca17c20a1010 100644
> --- a/arch/x86/kernel/ftrace.c
> +++ b/arch/x86/kernel/ftrace.c
> @@ -48,7 +48,7 @@ int ftrace_arch_code_modify_post_process(void)
> union ftrace_code_union {
> char code[MCOUNT_INSN_SIZE];
> struct {
> - char e8;
> + unsigned char e8;
u8?
"u8 e8;" looks supa dupa though :-)
> int offset;
> } __attribute__((packed));
> };
> @@ -797,12 +797,26 @@ static unsigned long create_trampoline(struct ftrace_ops *ops)
> return (unsigned long)trampoline;
> }
>
> +static unsigned long calc_trampoline_call_offset(bool save_regs)
> +{
> + unsigned long start_offset;
> + unsigned long call_offset;
> +
> + if (save_regs) {
> + start_offset = (unsigned long)ftrace_regs_caller;
> + call_offset = (unsigned long)ftrace_regs_call;
> + } else {
> + start_offset = (unsigned long)ftrace_caller;
> + call_offset = (unsigned long)ftrace_call;
> + }
> +
> + return call_offset - start_offset;
> +}
> +
> void arch_ftrace_update_trampoline(struct ftrace_ops *ops)
> {
> ftrace_func_t func;
> unsigned char *new;
> - unsigned long start_offset;
> - unsigned long call_offset;
> unsigned long offset;
> unsigned long ip;
> int ret;
> @@ -820,15 +834,7 @@ void arch_ftrace_update_trampoline(struct ftrace_ops *ops)
> return;
> }
>
> - if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {
> - start_offset = (unsigned long)ftrace_regs_caller;
> - call_offset = (unsigned long)ftrace_regs_call;
> - } else {
> - start_offset = (unsigned long)ftrace_caller;
> - call_offset = (unsigned long)ftrace_call;
> - }
> -
> - offset = call_offset - start_offset;
> + offset = calc_trampoline_call_offset(ops->flags & FTRACE_OPS_FL_SAVE_REGS);
> ip = ops->trampoline + offset;
>
> func = ftrace_ops_get_func(ops);
> @@ -840,6 +846,74 @@ void arch_ftrace_update_trampoline(struct ftrace_ops *ops)
> /* The update should never fail */
> WARN_ON(ret);
> }
> +
> +/* Return the address of the function the trampoline calls */
> +static void *addr_from_call(void *ptr)
> +{
> + union ftrace_code_union calc;
> + int ret;
> +
> + ret = probe_kernel_read(&calc, ptr, MCOUNT_INSN_SIZE);
> + if (WARN_ON_ONCE(ret < 0))
> + return NULL;
> +
> + /* Make sure this is a call */
> + if (WARN_ON_ONCE(calc.e8 != 0xe8)) {
> + pr_warn("Expected e8, got %x\n", calc.e8);
Simply WARN_ONCE gives you both.
> + return NULL;
> + }
> +
> + return ptr + MCOUNT_INSN_SIZE + calc.offset;
> +}
> +
> +void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
> + unsigned long frame_pointer);
> +
> +/*
> + * If the ops->trampoline was not allocated, then it probably
> + * has a static trampoline func, or is the ftrace caller itself.
> + */
> +static void *static_tramp_func(struct ftrace_ops *ops, struct dyn_ftrace *rec)
I guess you can merge this one into its only caller below - it is not
that huge... yet! :-)
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
next prev parent reply other threads:[~2014-11-05 10:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-27 18:27 [for-next][PATCH 0/4] ftrace: Add dynamic trampoline support Steven Rostedt
2014-10-27 18:27 ` [for-next][PATCH 1/4] ftrace/x86: Add dynamic allocated trampoline for ftrace_ops Steven Rostedt
2014-10-30 17:00 ` Steven Rostedt
2014-10-31 5:19 ` Masami Hiramatsu
2014-10-31 16:01 ` Steven Rostedt
2014-11-03 7:50 ` Masami Hiramatsu
2014-11-05 10:28 ` Borislav Petkov
2014-11-06 13:57 ` Steven Rostedt
2014-11-06 15:01 ` Borislav Petkov
2014-10-27 18:27 ` [for-next][PATCH 2/4] ftrace/x86: Show trampoline call function in enabled_functions Steven Rostedt
2014-10-30 17:00 ` Steven Rostedt
2014-11-05 10:42 ` Borislav Petkov [this message]
2014-11-06 14:01 ` Steven Rostedt
2014-10-27 18:27 ` [for-next][PATCH 3/4] ftrace/x86: Allow !CONFIG_PREEMPT dynamic ops to use allocated trampolines Steven Rostedt
2014-10-30 17:01 ` Steven Rostedt
2014-11-05 10:46 ` Borislav Petkov
2014-10-27 18:27 ` [for-next][PATCH 4/4] ftrace: Add more information to ftrace_bug() output Steven Rostedt
2014-10-30 17:02 ` Steven Rostedt
2014-11-05 10:49 ` Borislav Petkov
2014-10-29 16:27 ` [for-next][PATCH 0/4] ftrace: Add dynamic trampoline support Jiri Kosina
2014-10-30 16:56 ` Steven Rostedt
2014-10-30 17:08 ` Jiri Kosina
2014-10-31 10:04 ` Masami Hiramatsu
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=20141105104207.GB5245@pd.tnic \
--to=bp@alien8.de \
--cc=akpm@linux-foundation.org \
--cc=hpa@linux.intel.com \
--cc=jkosina@suse.cz \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rostedt@goodmis.org \
--cc=sjenning@redhat.com \
--cc=vojtech@suse.cz \
/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®