Re: ftrace module init race/bug

From: Alexei Starovoitov
Date: Mon Nov 07 2016 - 16:39:04 EST


On Mon, Nov 07, 2016 at 03:08:41PM -0500, Steven Rostedt wrote:
> On Mon, 7 Nov 2016 11:46:24 -0800
> Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote:
>
> > Hi Steven,
> >
> > I'm debugging the following spew:
> >
> > [ 7139.111213] WARNING: CPU: 8 PID: 856649 at kernel/trace/ftrace.c:2747 ftrace_shutdown+0x263/0x270
>
> What kernel version is this, as that line number doesn't line up to
> nay warning on 4.9 on 4.9-rc1.

it's our 4.6 with backports. It's line 2766 in 4.9 and as far as I can tell
the ftrace logic is the same, so pretty sure it's applicable, but...
no reproducer available. Only this spew.

> > do you think the following diff is enough to silence the warning
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index b1870fbd2b67..edb00bf70d84 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -2744,7 +2744,7 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
> > struct dyn_ftrace *rec;
> >
> > do_for_each_ftrace_rec(pg, rec) {
> > - if (FTRACE_WARN_ON_ONCE(rec->flags))
> > + if (FTRACE_WARN_ON_ONCE(rec->flags & ~FTRACE_FL_DISABLED))
> > pr_warn(" %pS flags:%lx\n",
> > (void *)rec->ip, rec->flags);
> > } while_for_each_ftrace_rec();
> >
> > or it's a tip of an iceberg and less hacky fix is needed?
>
> Actually, this may be correct. I need to audit the other
> do_for_each_ftrace_rec() loops.

yep, the __ftrace_hash_rec_update() has !FTRACE_FL_DISABLED check,
so I thought ftrace_shutdown() may need it too.
Should I send the above patch with proper sob?