From: Steven Rostedt <rostedt@goodmis.org>
To: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Jiri Kosina <jkosina@suse.cz>,
Seth Jennings <sjenning@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Petr Mladek <pmladek@suse.cz>, Vojtech Pavlik <vojtech@suse.cz>,
Namhyung Kim <namhyung@kernel.org>,
Miroslav Benes <mbenes@suse.cz>, Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH ftrace/core v6 4/5] kprobes: Set IPMODIFY flag only if the probe can change regs->ip
Date: Fri, 21 Nov 2014 15:15:48 -0500 [thread overview]
Message-ID: <20141121151548.7bd8bcd9@gandalf.local.home> (raw)
In-Reply-To: <20141121102530.11844.41626.stgit@localhost.localdomain>
On Fri, 21 Nov 2014 05:25:30 -0500
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> wrote:
> Set FTRACE_OPS_FL_IPMODIFY flag only for the probes which can change
> regs->ip, which has kprobe->break_handler.
> Currently we can not put jprobe and another ftrace handler which
> changes regs->ip on the same function because all kprobes have
> FTRACE_OPS_FL_IPMODIFY flag. This removes FTRACE_OPS_FL_IPMODIFY
> flag from kprobes and only when the user uses jprobe (or the
> kprobe.break_handler != NULL) we add additinal ftrace_ops with
> FTRACE_OPS_FL_IPMODIFY on target function.
>
> Note about the implementation: This uses a dummy ftrace_ops to
> reserve IPMODIFY flag on the given ftrace address, for the case
> that we have a enabled kprobe on a function entry and a jprobe
> is added on the same point. In that case, we already have a
> ftrace_ops without IPMODIFY flag on the entry, and we have to
> add another ftrace_ops with IPMODIFY on the same address.
> If we put a same handler on both ftrace_ops, the handler can
> be called twice on that entry until the first one is removed.
> This means that the kprobe and the jprobe are called twice too,
> and that will not what kprobes expected.
> Thus I added a dummy ftrace_ops just for reserving IPMODIFY flag.
>
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> ---
> Changes in v4:
> - Increment refcounter after succeeded to register ftrace_ops.
>
> Changes in v3:
> - Update __ftrace_add/remove_filter_ip() according to
> Namhyng's comments (thanks!)
> - Split out regs->ip recovering code from this patch.
> ---
> Documentation/kprobes.txt | 12 ++--
> kernel/kprobes.c | 125 +++++++++++++++++++++++++++++++++++++++------
> 2 files changed, 114 insertions(+), 23 deletions(-)
>
> diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
> index 4227ec2..eb03efc 100644
> --- a/Documentation/kprobes.txt
> +++ b/Documentation/kprobes.txt
> @@ -264,15 +264,13 @@ stop-machine method that ksplice uses for supporting a CONFIG_PREEMPT=y
> kernel.
>
> NOTE for geeks:
> -The jump optimization changes the kprobe's pre_handler behavior.
> -Without optimization, the pre_handler can change the kernel's execution
> +The jump optimization (and ftrace-based kprobes) changes the kprobe's
> +pre_handler behavior.
> +Without optimizations, the pre_handler can change the kernel's execution
> path by changing regs->ip and returning 1. However, when the probe
> is optimized, that modification is ignored. Thus, if you want to
> -tweak the kernel's execution path, you need to suppress optimization,
> -using one of the following techniques:
> -- Specify an empty function for the kprobe's post_handler or break_handler.
> - or
> -- Execute 'sysctl -w debug.kprobes_optimization=n'
> +tweak the kernel's execution path, you need to suppress optimization or
> +notify your handler will modify regs->ip by setting p->break_handler.
>
> 1.5 Blacklist
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 831978c..4b4b7c5 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -915,10 +915,93 @@ static struct kprobe *alloc_aggr_kprobe(struct kprobe *p)
> #ifdef CONFIG_KPROBES_ON_FTRACE
> static struct ftrace_ops kprobe_ftrace_ops __read_mostly = {
> .func = kprobe_ftrace_handler,
> - .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY,
> + .flags = FTRACE_OPS_FL_SAVE_REGS,
> };
> static int kprobe_ftrace_enabled;
>
> +static void kprobe_ftrace_stub(unsigned long a0, unsigned long a1,
> + struct ftrace_ops *op, struct pt_regs *regs)
> +{
> + /* Do nothing. This is just a dummy handler */
> +}
Feel free to just use ftrace_stub instead. That's what it's there for.
> +
> +/* This is only for checking conflict with other ftrace users */
> +static struct ftrace_ops kprobe_ipmod_ftrace_ops __read_mostly = {
> + .func = kprobe_ftrace_stub,
> + .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY,
> +};
> +static int kprobe_ipmod_ftrace_enabled;
> +
> +static int __ftrace_add_filter_ip(struct ftrace_ops *ops, unsigned long ip,
> + int *ref)
> +{
> + int ret;
> +
> + /* Try to set given ip to filter */
> + ret = ftrace_set_filter_ip(ops, ip, 0, 0);
> + if (ret < 0)
> + return ret;
> +
> + if (*ref == 0) {
> + ret = register_ftrace_function(ops);
> + if (ret < 0) {
> + /* Rollback the filter */
> + ftrace_set_filter_ip(ops, ip, 1, 0);
> + goto out;
Why the goto out, and not just return ret?
> + }
> + }
> + (*ref)++;
> +
> +out:
> + return ret;
Probably could just return 0 here.
Rest looks fine.
-- Steve
> +}
> +
> +static int __ftrace_remove_filter_ip(struct ftrace_ops *ops, unsigned long ip,
> + int *ref)
> +{
> + int ret;
> +
> + if (*ref == 1) {
> + ret = unregister_ftrace_function(ops);
> + if (ret < 0)
> + return ret;
> + /*Ignore failure, because it is already unregistered */
> + ftrace_set_filter_ip(ops, ip, 1, 0);
> + } else {
> + /* Try to remove given ip to filter */
> + ret = ftrace_set_filter_ip(ops, ip, 1, 0);
> + if (ret < 0)
> + return ret;
> + }
> +
> + (*ref)--;
> +
> + return 0;
> +}
> +
next prev parent reply other threads:[~2014-11-21 20:16 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-21 10:25 [PATCH ftrace/core v6 0/5] ftrace, kprobes: Introduce IPMODIFY flag for ftrace_ops to detect conflicts Masami Hiramatsu
2014-11-21 10:25 ` [PATCH ftrace/core v6 1/5] kprobes/ftrace: Recover original IP if pre_handler doesn't change it Masami Hiramatsu
2014-11-21 10:25 ` [PATCH ftrace/core v6 2/5] ftrace, kprobes: Support IPMODIFY flag to find IP modify conflict Masami Hiramatsu
2014-11-21 18:05 ` Steven Rostedt
2014-11-21 19:43 ` Steven Rostedt
2014-11-24 2:12 ` Masami Hiramatsu
2014-11-24 2:06 ` Masami Hiramatsu
2014-11-21 10:25 ` [PATCH ftrace/core v6 3/5] kprobes: Add IPMODIFY flag to kprobe_ftrace_ops Masami Hiramatsu
2014-11-21 10:25 ` [PATCH ftrace/core v6 4/5] kprobes: Set IPMODIFY flag only if the probe can change regs->ip Masami Hiramatsu
2014-11-21 20:15 ` Steven Rostedt [this message]
2014-11-24 2:43 ` Masami Hiramatsu
2015-01-26 16:14 ` Petr Mladek
2015-02-24 7:38 ` Masami Hiramatsu
2015-02-24 8:52 ` Petr Mladek
2015-02-24 11:47 ` Masami Hiramatsu
2015-02-24 13:10 ` Petr Mladek
2014-11-21 10:25 ` [PATCH ftrace/core v6 5/5] kselftest, ftrace: Add ftrace IPMODIFY flag test Masami Hiramatsu
2014-11-21 21:03 ` Steven Rostedt
2014-11-24 2:50 ` Masami Hiramatsu
2014-11-24 4:29 ` Steven Rostedt
2014-11-24 14:11 ` Masami Hiramatsu
2014-11-24 15:07 ` Steven Rostedt
2014-11-24 15:18 ` Steven Rostedt
2014-11-24 15:19 ` Steven Rostedt
2014-11-25 1:51 ` Masami Hiramatsu
2014-11-24 16:18 ` Shuah Khan
2014-11-25 1:23 ` Masami Hiramatsu
2014-11-25 14:42 ` Shuah Khan
2014-11-25 14:44 ` Shuah Khan
2014-11-26 7:20 ` Masami Hiramatsu
2014-11-26 18:40 ` Shuah Khan
2014-11-27 4:56 ` Masami Hiramatsu
2014-11-26 14:31 ` Steven Rostedt
2014-11-27 0:55 ` 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=20141121151548.7bd8bcd9@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=ananth@in.ibm.com \
--cc=jkosina@suse.cz \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mbenes@suse.cz \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=pmladek@suse.cz \
--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®