Re: [RFC] ftrace: Add support to keep some functions out of ftrace

Alexei Starovoitov
2022-07-22T16:53:47Z

On Fri, Jul 22, 2022 at 9:25 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri, 22 Jul 2022 12:08:54 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > On Fri, 22 Jul 2022 09:04:29 -0700
> > Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> >
> > > ftrace must not peek into bpf specific functions.
> > > Currently ftrace is causing the kernel to crash.
> > > What Jiri is proposing is to fix ftrace bug.
> > > And you're saying nack? let ftrace be broken ?
>
> Sounds like a BPF bug to me. Ftrace did nothing to cause this breakage. It
> was something BPF must have done. What exactly is BPF doing to ftrace
> locations anyway?

ftrace location?
fentry != ftrace.
nop5 in the beginning of the function or in the middle of it
doesn't mean that it's safe for ftrace to attach there.
In some cases bpf has custom calling convention
like it preserves %rax.
In other cases there will be multiple nop5 locations
through the function where special care needs to be taken
to attach.

> > >
> > > If you don't like Jiri's approach please propose something else.
> >
> > So, why not mark it as notrace? That will prevent ftrace from looking at it.
> >
>
> And if for some strange reason you need the mcount/fentry on some internal
> BPF infrastructure, the work around is to register two ftrace_ops() that
> have filters to that function. In which case ftrace will force the call to
> the ftrace iterator loop, and any more ops attached will simply be added to
> that loop, and ftrace will no longer touch that location.
>
> Then you can do whatever you want to it without fear of racing with ftrace.

Jiri,
that sounds like a workable solution.
wdyt?

> But other than that, we don't need infrastructure to hide any mcount/fentry
> locations from ftrace. Those were add *for* ftrace.

fentry != ftrace.