From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Jiri Olsa <jolsa@redhat.com>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Jiri Kosina <jikos@kernel.org>
Subject: Re: [RFC][PATCH 0/3 v3] ftrace: Add access to function arguments for all callbacks
Date: Thu, 29 Oct 2020 22:29:18 +0900 [thread overview]
Message-ID: <20201029222918.7d0625ec4ca47e6f1d64c75b@kernel.org> (raw)
In-Reply-To: <20201029000816.272878754@goodmis.org>
On Wed, 28 Oct 2020 20:08:16 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> This is something I wanted to implement a long time ago, but held off until
> there was a good reason to do so. Now it appears that having access to the
> arguments of the function by default is very useful. As a bonus, because
> arguments must be saved regardless before calling a callback, because they
> need to be restored before returning back to the start of the traced
> function, there's not much work to do to have them always be there for
> normal function callbacks.
>
> The basic idea is that if CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is set, then
> all callbacks registered to ftrace can use the regs parameter for the stack
> and arguments (kernel_stack_pointer(regs), regs_get_kernel_argument(regs, n)),
> without the need to set REGS that causes overhead by saving all registers as
> REGS simulates a breakpoint.
>
> This could be extended to move the REGS portion to kprobes itself, and
> remove the SAVE_REGS flag completely, but for now, kprobes still uses the
> full SAVE_REGS support.
Yeah, I would like to keep using the SAVE_REGS support until SAVE_ARGS
implemented on all arch. But in parallel, I will prepare generic
kprobe-on-ftrace handler.
> The last patch extends the WITH_ARGS to allow default function tracing to
> modify the instruction pointer, where livepatching for x86 no longer needs
> to save all registers.
>
> The idea of this approach is to give enough information to a callback that
> it could retrieve all arguments, which includes the stack pointer and
> instruction pointer.
>
> This can also be extended to modify the function graph tracer to use the
> function tracer instead of having a separate trampoline.
Anyway, this series (3 patches) looks good to me.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thank you!
>
> Changes since v2:
>
> - Change all callback args to use struct ftrace_regs, and if something
> requires the full regs, it must use the ftrace_get_regs() helper macro,
> which will return NULL if the regs isn't full (FL_SAVE_REGS set).
> This addresses a concern by both Peter Zijlsta and Thomas Gleixner that
> a partially filled pt_regs may be used inappropriately.
>
> - No test patch in this version.
>
> - Use case using livepatching is added. This passes the test_livepatch.sh
> selftest.
>
> Steven Rostedt (VMware) (3):
> ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs
> ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default
> livepatching: Use the default ftrace_ops instead of REGS when ARGS is available
>
> ----
> arch/powerpc/include/asm/livepatch.h | 4 +++-
> arch/s390/include/asm/livepatch.h | 5 ++++-
> arch/x86/Kconfig | 1 +
> arch/x86/include/asm/ftrace.h | 18 ++++++++++++++++++
> arch/x86/include/asm/livepatch.h | 4 ++--
> arch/x86/kernel/ftrace_64.S | 15 +++++++++++++--
> arch/x86/kernel/kprobes/ftrace.c | 3 ++-
> include/linux/ftrace.h | 28 ++++++++++++++++++++++++++--
> include/linux/kprobes.h | 2 +-
> kernel/livepatch/patch.c | 10 ++++++----
> kernel/trace/Kconfig | 9 +++++++++
> kernel/trace/ftrace.c | 27 +++++++++++++++------------
> kernel/trace/trace_event_perf.c | 2 +-
> kernel/trace/trace_functions.c | 9 ++++-----
> kernel/trace/trace_irqsoff.c | 2 +-
> kernel/trace/trace_sched_wakeup.c | 2 +-
> kernel/trace/trace_selftest.c | 20 +++++++++++---------
> kernel/trace/trace_stack.c | 2 +-
> 18 files changed, 119 insertions(+), 44 deletions(-)
--
Masami Hiramatsu <mhiramat@kernel.org>
prev parent reply other threads:[~2020-10-29 13:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 0:08 [RFC][PATCH 0/3 v3] ftrace: Add access to function arguments for all callbacks Steven Rostedt
2020-10-29 0:08 ` [RFC][PATCH 1/3 v3] ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs Steven Rostedt
2020-10-29 0:08 ` [RFC][PATCH 2/3 v3] ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default Steven Rostedt
2020-10-29 0:08 ` [RFC][PATCH 3/3 v3] livepatching: Use the default ftrace_ops instead of REGS when ARGS is available Steven Rostedt
2020-10-30 13:07 ` Miroslav Benes
2020-10-29 13:29 ` Masami Hiramatsu [this message]
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=20201029222918.7d0625ec4ca47e6f1d64c75b@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexei.starovoitov@gmail.com \
--cc=jikos@kernel.org \
--cc=jolsa@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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