From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
bpf@vger.kernel.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH] rethook: Reject getting a rethook if RCU is not watching
Date: Fri, 27 May 2022 01:14:34 +0900 [thread overview]
Message-ID: <20220527011434.9e8c47d1b40f549baf2cf52a@kernel.org> (raw)
In-Reply-To: <Yo+TWcfpyHy55Il5@krava>
On Thu, 26 May 2022 16:49:26 +0200
Jiri Olsa <olsajiri@gmail.com> wrote:
> On Thu, May 26, 2022 at 11:25:30PM +0900, Masami Hiramatsu wrote:
> > On Tue, 24 May 2022 19:23:01 -0400
> > Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > > On Sat, 7 May 2022 13:46:52 +0900
> > > Masami Hiramatsu <mhiramat@kernel.org> wrote:
> > >
> > > Is this expected to go through the BPF tree?
> > >
> >
> > Yes, since rethook (fprobe) is currently used only from eBPF.
> > Jiri, can you check this is good for your test case?
>
> sure I'll test it.. can't see the original email,
> perhaps I wasn't cc-ed.. but I'll find it
Here it is. I Cc-ed your @kernel.org address.
https://lore.kernel.org/all/165189881197.175864.14757002789194211860.stgit@devnote2/T/#u
>
> is this also related to tracing 'idle' functions,
> as discussed in here?
> https://lore.kernel.org/bpf/20220515203653.4039075-1-jolsa@kernel.org/
Ah, yes. So this may not happen with the above patch, but for the
hardening (ensuring it is always safe), I would like to add this.
>
> because that's the one I can reproduce.. but I can
> certainly try that with your change as well
Thank you!
>
> jirka
>
> >
> > Thank you,
> >
> >
> > > -- Steve
> > >
> > >
> > > > Since the rethook_recycle() will involve the call_rcu() for reclaiming
> > > > the rethook_instance, the rethook must be set up at the RCU available
> > > > context (non idle). This rethook_recycle() in the rethook trampoline
> > > > handler is inevitable, thus the RCU available check must be done before
> > > > setting the rethook trampoline.
> > > >
> > > > This adds a rcu_is_watching() check in the rethook_try_get() so that
> > > > it will return NULL if it is called when !rcu_is_watching().
> > > >
> > > > Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
> > > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > > > ---
> > > > kernel/trace/rethook.c | 9 +++++++++
> > > > 1 file changed, 9 insertions(+)
> > > >
> > > > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> > > > index b56833700d23..c69d82273ce7 100644
> > > > --- a/kernel/trace/rethook.c
> > > > +++ b/kernel/trace/rethook.c
> > > > @@ -154,6 +154,15 @@ struct rethook_node *rethook_try_get(struct rethook *rh)
> > > > if (unlikely(!handler))
> > > > return NULL;
> > > >
> > > > + /*
> > > > + * This expects the caller will set up a rethook on a function entry.
> > > > + * When the function returns, the rethook will eventually be reclaimed
> > > > + * or released in the rethook_recycle() with call_rcu().
> > > > + * This means the caller must be run in the RCU-availabe context.
> > > > + */
> > > > + if (unlikely(!rcu_is_watching()))
> > > > + return NULL;
> > > > +
> > > > fn = freelist_try_get(&rh->pool);
> > > > if (!fn)
> > > > return NULL;
> > >
> >
> >
> > --
> > Masami Hiramatsu (Google) <mhiramat@kernel.org>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2022-05-26 16:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-07 4:46 [PATCH] rethook: Reject getting a rethook if RCU is not watching Masami Hiramatsu
2022-05-24 23:23 ` Steven Rostedt
2022-05-26 14:25 ` Masami Hiramatsu
2022-05-26 14:49 ` Jiri Olsa
2022-05-26 16:14 ` Masami Hiramatsu [this message]
2022-05-27 22:10 ` Jiri Olsa
2022-05-28 1:19 ` Masami Hiramatsu
2022-06-03 19:21 ` Andrii Nakryiko
2022-06-06 16:02 ` Masami Hiramatsu
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=20220527011434.9e8c47d1b40f549baf2cf52a@kernel.org \
--to=mhiramat@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olsajiri@gmail.com \
--cc=paulmck@kernel.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).