linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	alexei.starovoitov@gmail.com, linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org, Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Jiri Olsa <olsajiri@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH] tracing: Refuse fprobe if RCU is not watching
Date: Mon, 10 Apr 2023 23:35:11 +0200	[thread overview]
Message-ID: <ZDSBD6UvUdA73TSv@krava> (raw)
In-Reply-To: <CALOAHbBQgPqhBhOVukWG9FNL23m3EOFm1QN6+pi5SN8cP2ztBw@mail.gmail.com>

On Mon, Apr 10, 2023 at 10:20:31PM +0800, Yafang Shao wrote:
> On Mon, Apr 10, 2023 at 10:12 PM Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > On Mon, 10 Apr 2023 21:56:16 +0800
> > Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > > Thanks for your explanation again.
> > > BPF trampoline is a little special. It includes three parts, as follows,
> > >
> > >     ret = __bpf_prog_enter();
> > >     if (ret)
> > >         prog->bpf_func();
> > >      __bpf_prog_exit();
> > >
> > > migrate_disable() is called in __bpf_prog_enter() and migrate_enable()
> > > in __bpf_prog_exit():
> > >
> > >     ret = __bpf_prog_enter();
> > >                 migrate_disable();
> > >     if (ret)
> > >         prog->bpf_func();
> > >      __bpf_prog_exit();
> > >           migrate_enable();
> > >
> > > That said, if we haven't executed migrate_disable() in
> > > __bpf_prog_enter(), we shouldn't execute migrate_enable() in
> > > __bpf_prog_exit().
> > > Can ftrace_test_recursion_trylock() be applied to this pattern ?
> >
> > Yes, it can! And in this you would need to not call migrate_enable()
> > because if the trace_recursion_trylock() failed, it would prevent
> > migrate_disable() from being called (and should not let the bpf_func() from
> > being called either. And then the migrate_enable in __bpf_prog_exit() would
> > need to know not to call migrate_enable() which checking the return value
> > of ftrace_test_recursion_trylock() would give the same value as what the
> > one before migrate_disable() had.
> >
> 
> That needs some changes in invoke_bpf_prog() in files
> arch/${ARCH}/net/bpf_jit_comp.c.
> But I will have a try. We can then remove the bpf_prog->active, that
> will be a good cleanup as well.

I was wondering if it's worth the effort to do that just to be able to attach
bpf prog to preempt_count_add/sub and was going to suggest to add them to
btf_id_deny as Steven pointed out earlier as possible solution

but if that might turn out as alternative to prog->active, that'd be great

jirka

> 
> >
> > >
> > > > Note, the ftrace_test_recursion_*() code needs to be updated because it
> > > > currently does disable preemption, which it doesn't have to. And that
> > > > can cause migrate_disable() to do something different. It only disabled
> > > > preemption, as there was a time that it needed to, but now it doesn't.
> > > > But the users of it will need to be audited to make sure that they
> > > > don't need the side effect of it disabling preemption.
> > > >
> > >
> > > disabling preemption is not expected by bpf prog, so I think we should
> > > change it.
> >
> > The disabling of preemption was just done because every place that used it
> > happened to also disable preemption. So it was just a clean up, not a
> > requirement. Although the documentation said it did disable preemption :-/
> >
> >  See ce5e48036c9e7 ("ftrace: disable preemption when recursion locked")
> >
> > I think I can add a ftrace_test_recursion_try_aquire() and release() that
> > is does the same thing without preemption. That way, we don't need to
> > revert that patch, and use that instead.
> >
> > -- Steve
> 
> 
> 
> -- 
> Regards
> Yafang

  reply	other threads:[~2023-04-10 21:35 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  2:01 [PATCH] tracing: Refuse fprobe if RCU is not watching Yafang Shao
2023-03-21 14:12 ` Masami Hiramatsu
2023-03-21 14:17 ` Steven Rostedt
2023-03-21 15:50   ` Peter Zijlstra
2023-03-23  5:59   ` Yafang Shao
2023-03-23 12:39     ` Steven Rostedt
2023-03-24  2:51       ` Yafang Shao
2023-03-24  3:01         ` Steven Rostedt
2023-04-09  5:32           ` Yafang Shao
2023-04-09 11:55             ` Steven Rostedt
2023-04-09 12:45               ` Yafang Shao
2023-04-09 13:54                 ` Masami Hiramatsu
2023-04-09 14:44                   ` Yafang Shao
2023-04-10  2:02                     ` Steven Rostedt
2023-04-10  5:36                       ` Yafang Shao
2023-04-10 10:30                         ` Steven Rostedt
2023-04-10 13:56                           ` Yafang Shao
2023-04-10 14:12                             ` Steven Rostedt
2023-04-10 14:20                               ` Yafang Shao
2023-04-10 21:35                                 ` Jiri Olsa [this message]
2023-04-12 14:37                                   ` Yafang Shao
2023-04-12 19:04                                     ` Jiri Olsa
2023-04-10 14:31                               ` Steven Rostedt
2023-04-12 14:30                                 ` Yafang Shao
2023-04-09 17:25                 ` Steven Rostedt
2023-04-10  4:28                   ` Yafang Shao
2023-03-21 14:43 ` Jiri Olsa

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=ZDSBD6UvUdA73TSv@krava \
    --to=olsajiri@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=peterz@infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).