Re: [PATCH 3/9] ftrace: Fix shutdown to disable calls properly

From: Jiri Olsa
Date: Tue Nov 29 2011 - 06:21:50 EST


On Mon, Nov 28, 2011 at 02:18:48PM -0500, Steven Rostedt wrote:
> On Sun, 2011-11-27 at 19:04 +0100, Jiri Olsa wrote:
> > Each ftrace_startup call increases the call record's flag,
> > so we need allways to decrease it when shutting down the
> > ftrace_ops.
>
> No, that's not how this works. I probably should comment this code
> better, because it caused me to reread it too ;)
>
> >
> > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> > ---
> > kernel/trace/ftrace.c | 3 +--
> > 1 files changed, 1 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index c6d0293..0ca0c0d 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -1744,8 +1744,7 @@ static void ftrace_shutdown(struct ftrace_ops *ops, int command)
> > if (ops != &global_ops || !global_start_up)
> > ops->flags &= ~FTRACE_OPS_FL_ENABLED;
> >
> > - if (!ftrace_start_up)
> > - command |= FTRACE_DISABLE_CALLS;
> > + command |= FTRACE_DISABLE_CALLS;
>
> FTRACE_DISABLE_CALLS will disable *all* functions for all tracers. If
> you are tracing with ftrace and perf, and one calls this with
> FTRACE_DISABLE_CALLS then both will no long be tracing anything.
>
> When you call unregister_ftrace_function() it will disable the functions
> that you have enabled by the ops.
>
> Nacked-by: Steven Rostedt <rostedt@xxxxxxxxxxxx

ops, should read/test more carefully.. however the problem stays, here's
one possible scenario of the issue:

- enable function trace like:
echo "mm_*" > ./set_ftrace_filter
echo function > ./current_tracer
- run:
./perf record -e ftrace:function cal
- this runs: register_ftrace_function/unregister_ftrace_function

- bad result: after perf is finished, function trace will have all the functions enabled

The reason is, that after the perf record calls unregister_ftrace_function,
only the functions' record flags (struct dyn_ftrace::flags) are changed, but
functions' mcount calls are not replaced accordingly.

In our case, when function trace becomes again the only tracer, it will be
plugged directly into the entry_BIT.S code, and thus getting all the functions
from previous perf ftrace_ops without any filtering.

I think we need to project the function record flags state into the
function call replacement during the unregister_ftrace_function.

jirka

>
> -- Steve
>
>
> >
> > if (saved_ftrace_func != ftrace_trace_function) {
> > saved_ftrace_func = ftrace_trace_function;
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/