From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: paulcacheux@gmail.com,
Paul Cacheux via B4 Relay
<devnull+paulcacheux.gmail.com@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] tracing: protect trace_probe_log with mutex
Date: Sat, 10 May 2025 08:57:44 +0900 [thread overview]
Message-ID: <20250510085744.3dab36f6e314c9e63a673d3e@kernel.org> (raw)
In-Reply-To: <20250510074456.805a16872b591e2971a4d221@kernel.org>
On Sat, 10 May 2025 07:44:56 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> On Fri, 02 May 2025 15:15:53 +0200
> Paul Cacheux via B4 Relay <devnull+paulcacheux.gmail.com@kernel.org> wrote:
>
> > From: Paul Cacheux <paulcacheux@gmail.com>
> >
> > The shared trace_probe_log variable can be accessed and modified
> > by multiple processes using tracefs at the same time, this new
> > mutex will guarantee it's always in a coherent state.
>
> Actually that's not happen. For the create part (and currently the
> event_log is used only in the creation), `dyn_event_ops_mutex` is already
> held in create_dyn_event(). Thus, it is already serialized.
Oops, if user writes some commands not directly from dynevent,
(e.g. tracefs/{kprobe_events,uprobe_events} )the mutex is not held.
Hmm, we need to make another patch.
>
> And even if there are multiple events are done in parallel, this
> is not enough because trace_probe_log::argc/argv can be changed
> before other user finishs to use the log.
But this is still valid. We need to reroute the creation to
dynamic_events.
Thank you,
>
> Thank you,
>
> >
> > There is no guarantee that multiple errors happening at the same
> > time will each have the correct error message, but at least this
> > won't crash.
> >
> > Fixes: ab105a4fb894 ("tracing: Use tracing error_log with probe events")
> >
> > Signed-off-by: Paul Cacheux <paulcacheux@gmail.com>
> > ---
> > kernel/trace/trace_probe.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> > index 2eeecb6c95eea55502b83af6775b7b6f0cc5ab94..14a7a0b59cd20a8bc43e3e7c653e986081f924c8 100644
> > --- a/kernel/trace/trace_probe.c
> > +++ b/kernel/trace/trace_probe.c
> > @@ -154,9 +154,11 @@ static const struct fetch_type *find_fetch_type(const char *type, unsigned long
> > }
> >
> > static struct trace_probe_log trace_probe_log;
> > +static DEFINE_MUTEX(trace_probe_log_lock);
> >
> > void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
> > {
> > + guard(mutex)(&trace_probe_log_lock);
> > trace_probe_log.subsystem = subsystem;
> > trace_probe_log.argc = argc;
> > trace_probe_log.argv = argv;
> > @@ -165,11 +167,13 @@ void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
> >
> > void trace_probe_log_clear(void)
> > {
> > + guard(mutex)(&trace_probe_log_lock);
> > memset(&trace_probe_log, 0, sizeof(trace_probe_log));
> > }
> >
> > void trace_probe_log_set_index(int index)
> > {
> > + guard(mutex)(&trace_probe_log_lock);
> > trace_probe_log.index = index;
> > }
> >
> > @@ -178,6 +182,8 @@ void __trace_probe_log_err(int offset, int err_type)
> > char *command, *p;
> > int i, len = 0, pos = 0;
> >
> > + guard(mutex)(&trace_probe_log_lock);
> > +
> > if (!trace_probe_log.argv)
> > return;
> >
> >
> > --
> > 2.49.0
> >
> >
>
>
> --
> Masami Hiramatsu (Google) <mhiramat@kernel.org>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
prev parent reply other threads:[~2025-05-09 23:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 13:15 [PATCH v2 0/2] tracing: fix race when creating trace probe log error message Paul Cacheux via B4 Relay
2025-05-02 13:15 ` [PATCH v2 1/2] tracing: add missing trace_probe_log_clear for eprobes Paul Cacheux via B4 Relay
2025-05-09 22:18 ` Masami Hiramatsu
2025-05-02 13:15 ` [PATCH v2 2/2] tracing: protect trace_probe_log with mutex Paul Cacheux via B4 Relay
2025-05-02 13:50 ` Steven Rostedt
2025-05-07 6:49 ` Paul Cacheux
2025-05-09 22:44 ` Masami Hiramatsu
2025-05-09 23:57 ` Masami Hiramatsu [this message]
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=20250510085744.3dab36f6e314c9e63a673d3e@kernel.org \
--to=mhiramat@kernel.org \
--cc=devnull+paulcacheux.gmail.com@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=namhyung@kernel.org \
--cc=paulcacheux@gmail.com \
--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
all inboxes | Powered by JetHome®