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: Jiri Olsa <olsajiri@gmail.com>,
	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>,
	Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH] tracing: Refuse fprobe if RCU is not watching
Date: Wed, 12 Apr 2023 21:04:30 +0200	[thread overview]
Message-ID: <ZDcAvr0JuNE445FZ@krava> (raw)
In-Reply-To: <CALOAHbACzCwu-VeMczEJw8A4WFgkL-uQDS1NkcVR2pqEMZyAQQ@mail.gmail.com>

On Wed, Apr 12, 2023 at 10:37:07PM +0800, Yafang Shao wrote:
> On Tue, Apr 11, 2023 at 5:35 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > 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
> >
> 
> I think we can do it in two steps,
> 1. Fix this crash by adding preempt_count_{sub,add} into btf_id deny list.
>    The stable kernel may need this fix, so we'd better make it
> simpler, then it can be backported easily.
> 
> 2. Replace prog->active with the new
> test_recursion_try_{acquire,release} introduced by Steven
>    That's an improvement. We can do it in a separate patchset.
> 
> WDYT?

sounds good

> 
> BTW, maybe we need to add a new fentry test case to attach all
> available FUNCs parsed from /sys/kernel/btf/vmlinux.

that might be tricky because we don't have multi trampoline attach
support at the moment, so it will take forever

jirka

  reply	other threads:[~2023-04-12 19:05 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
2023-04-12 14:37                                   ` Yafang Shao
2023-04-12 19:04                                     ` Jiri Olsa [this message]
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=ZDcAvr0JuNE445FZ@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).