From: Steven Rostedt <rostedt@goodmis.org>
To: Miroslav Benes <mbenes@suse.cz>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: A bug in ftrace - dynamic fops
Date: Thu, 11 Aug 2016 10:33:31 -0400 [thread overview]
Message-ID: <20160811103331.63c24695@gandalf.local.home> (raw)
In-Reply-To: <alpine.LNX.2.00.1608111606270.30416@pobox.suse.cz>
On Thu, 11 Aug 2016 16:08:58 +0200 (CEST)
Miroslav Benes <mbenes@suse.cz> wrote:
> /*
> * Dynamic ops may be freed, we must make sure that all
> * callers are done before leaving this function.
> * The same goes for freeing the per_cpu data of the per_cpu
> * ops.
> *
> * Again, normal synchronize_sched() is not good enough.
> * We need to do a hard force of sched synchronization.
> * This is because we use preempt_disable() to do RCU, but
> * the function tracers can be called where RCU is not watching
> * (like before user_exit()). We can not rely on the RCU
> * infrastructure to do the synchronization, thus we must do it
> * ourselves.
> */
> if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_PER_CPU)) {
> schedule_on_each_cpu(ftrace_sync);
>
> arch_ftrace_trampoline_free(ops);
>
> if (ops->flags & FTRACE_OPS_FL_PER_CPU)
> per_cpu_ops_free(ops);
> }
>
> I think the wording could be interpreted in a way that ftrace is
> responsible which is not true according to you.
OK, then I should update it to be a bit more clear, that it is only
worried about its own infrastructure and not what goes on within
ops->func().
I take feedback like yours seriously. If you are confused by it, then
others may be too.
Thus, I think there should be two points documented a bit better.
#1, ops->func() is special, and can be called from any context
including NMI. That means unless you take special care about exactly
what functions are going to be traced (via the filter hashes, which are
not even supported when DYNAMIC_FTRACE is not set), then the
ops->func() must be treated with the same care as an NMI handler would
be. (no locking, no sleeping, etc).
#2, the only synchronization that ftrace will take care of is its own.
That is, the dynamic trampolines have race conditions in the
implementation. The above comment is all about handling its own race
conditions, and doesn't care about what goes on within ops->func().
Although it does give a utility if ops->func() is not recursion safe,
but other than than, like all other function hooks, any synchronization
within the hooks must be taken care of by the caller to
(un)register_ftrace_function(). That includes hooks doing strange
things (like sleeping) and then freeing the ops after the registering.
Although, with #1, #2 may not be needed.
-- Steve
next prev parent reply other threads:[~2016-08-11 14:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-08 8:57 Miroslav Benes
2016-08-08 14:53 ` Steven Rostedt
2016-08-09 8:16 ` Miroslav Benes
2016-08-09 12:17 ` Steven Rostedt
2016-08-11 8:46 ` Miroslav Benes
2016-08-11 14:01 ` Steven Rostedt
2016-08-11 14:08 ` Miroslav Benes
2016-08-11 14:33 ` Steven Rostedt [this message]
2016-08-11 14:54 ` Miroslav Benes
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=20160811103331.63c24695@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@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®