From: Steven Rostedt <rostedt@goodmis.org>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: 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 06:30:46 -0400 [thread overview]
Message-ID: <20230410063046.391dd2bd@rorschach.local.home> (raw)
In-Reply-To: <CALOAHbC5UvoU2EUM+YzNSaJyNNq_OOXYZYcqXu6nUfB0AyX0bA@mail.gmail.com>
On Mon, 10 Apr 2023 13:36:32 +0800
Yafang Shao <laoar.shao@gmail.com> wrote:
> Many thanks for the detailed explanation.
> I think ftrace_test_recursion_trylock() can't apply to migreate_enable().
> If we change as follows to prevent migrate_enable() from recursing,
>
> bit = ftrace_test_recursion_trylock();
> if (bit < 0)
> return;
> migrate_enable();
> ftrace_test_recursion_unlock(bit);
>
> We have called migrate_disable() before, so if we don't call
> migrate_enable() it will cause other issues.
Right. Because you called migrate_disable() before (and protected it
with the ftrace_test_recursion_trylock(), the second call is guaranteed
to succeed!
[1] bit = ftrace_test_recursion_trylock();
if (bit < 0)
return;
migrate_disable();
ftrace_test_recursion_trylock(bit);
[..]
[2] ftrace_test_recursion_trylock();
migrate_enable();
ftrace_test_recursion_trylock(bit);
You don't even need to read the bit again, because it will be the same
as the first call [1]. That's because it returns the recursion level
you are in. A function will have the same recursion level through out
the function (as long as it always calls ftrace_test_recursion_unlock()
between them).
bpf_func()
bit = ftrace_test_recursion_trylock(); <-- OK
migrate_disable();
ftrace_test_recursion_unlock(bit);
[..]
ftrace_test_recursion_trylock(); <<-- guaranteed to be OK
migrate_enable() <<<-- gets traced
bpf_func()
bit = ftrace_test_recursion_trylock() <-- FAILED
if (bit < 0)
return;
ftrace_test_recursion_unlock(bit);
See, still works!
The migrate_enable() will never be called without the migrate_disable()
as the migrate_disable() only gets called when not being recursed.
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.
-- Steve
next prev parent reply other threads:[~2023-04-10 10:30 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 [this message]
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
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=20230410063046.391dd2bd@rorschach.local.home \
--to=rostedt@goodmis.org \
--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=olsajiri@gmail.com \
--cc=peterz@infradead.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