From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
Jessica Yu <jeyu@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"David S . Miller" <davem@davemloft.net>,
Ingo Molnar <mingo@kernel.org>, Petr Mladek <pmladek@suse.com>,
Joe Lawrence <joe.lawrence@redhat.com>,
Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] kprobes: propagate error from arm_kprobe_ftrace()
Date: Sat, 4 Nov 2017 05:35:20 +0900 [thread overview]
Message-ID: <20171104053520.f45d3febb1f414fb08dd76c2@kernel.org> (raw)
In-Reply-To: <20171103133312.1a0646e2@vmware.local.home>
On Fri, 3 Nov 2017 13:33:12 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 3 Nov 2017 09:53:37 -0500
> Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> > > > -static void arm_kprobe_ftrace(struct kprobe *p)
> > > > +static int arm_kprobe_ftrace(struct kprobe *p)
> > > > {
> > > > - int ret;
> > > > + int ret = 0;
> > > >
> > > > ret = ftrace_set_filter_ip(&kprobe_ftrace_ops,
> > > > (unsigned long)p->addr, 0, 0);
> > > > - WARN(ret < 0, "Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret);
> > > > - kprobe_ftrace_enabled++;
> > > > - if (kprobe_ftrace_enabled == 1) {
> > > > + if (WARN(ret < 0, "Failed to arm kprobe-ftrace at %p (%d)\n", p->addr, ret))
> > > > + return ret;
> > > > +
> > > > + if (kprobe_ftrace_enabled == 0) {
> > > > ret = register_ftrace_function(&kprobe_ftrace_ops);
> > > > - WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret);
> > > > + if (WARN(ret < 0, "Failed to init kprobe-ftrace (%d)\n", ret))
> > > > + goto err_ftrace;
> > > > }
> > > > +
> > > > + kprobe_ftrace_enabled++;
> > > > + return ret;
> > > > +
> > > > +err_ftrace:
> > > > + ftrace_set_filter_ip(&kprobe_ftrace_ops, (unsigned long)p->addr, 1, 0);
> > >
> > > Hmm, this could have a very nasty side effect. If you remove a function
> > > from the ops, and it was the last function, an empty ops means to trace
> > > *all* functions.
> >
> > But this error path only runs when register_ftrace_function() fails, in
> > which case the ops aren't live anyway, right?
>
> I was thinking that if there was more than one function that is going
> to be registered, that only this one would be black listed. But yeah,
> if there was only one function in the hash, then it probably wouldn't
> matter if it was cleared, because it failed. But I'm paranoid about
> things like this, and prefer to be more robust than to depend on the
> design to enforce correctness than to have each individual function
> being contained and do what is expected of it.
So, what coding will be better? I can only think of this;
ret = ftrace_set_filter_ip(&kprobe_ftrace_ops,
(unsigned long)p->addr, 0, !kprobe_ftrace_enabled);
And do not remove ip from filter in error case of register_ftrace_function.
BTW, ftrace_set_filter_ip(..., 1, 0); is not easy to read (and @reset
is meaningless in removing)
ftrace_new_filter_ip(ops, addr);
ftrace_append_filter_ip(ops, addr);
ftrace_remove_filter_ip(ops, addr);
wrappers will be more useful.
Thank you,
>
> -- Steve
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-11-03 20:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-02 16:33 [PATCH v2 0/2] kprobes: improve error handling when arming/disarming kprobes Jessica Yu
2017-11-02 16:33 ` [PATCH v2 1/2] kprobes: propagate error from arm_kprobe_ftrace() Jessica Yu
2017-11-03 14:03 ` Steven Rostedt
2017-11-03 14:53 ` Josh Poimboeuf
2017-11-03 17:33 ` Steven Rostedt
2017-11-03 20:35 ` Masami Hiramatsu [this message]
2017-11-07 17:14 ` Jessica Yu
2017-11-09 0:35 ` Masami Hiramatsu
2017-11-21 14:47 ` Jessica Yu
2017-11-03 21:49 ` [PATCH v2 1/2] " Masami Hiramatsu
2017-11-02 16:33 ` [PATCH v2 2/2] kprobes: propagate error from disarm_kprobe_ftrace() Jessica Yu
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=20171104053520.f45d3febb1f414fb08dd76c2@kernel.org \
--to=mhiramat@kernel.org \
--cc=ananth@linux.vnet.ibm.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=jeyu@kernel.org \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mingo@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.