From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
g@google.com, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, kernel-team@android.com
Subject: Re: [PATCH v13 2/6] ring-buffer: Introducing ring-buffer mapping functions
Date: Sat, 3 Feb 2024 19:54:30 -0500 [thread overview]
Message-ID: <20240203195430.51171d85@rorschach.local.home> (raw)
In-Reply-To: <ZbkiLjUKmgg6oXR5@google.com>
On Tue, 30 Jan 2024 16:22:06 +0000
Vincent Donnefort <vdonnefort@google.com> wrote:
> > > +static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
> > > +{
> > > + struct trace_buffer_meta *meta = cpu_buffer->meta_page;
> > > +
> > > + WRITE_ONCE(meta->reader.read, cpu_buffer->reader_page->read);
> > > + WRITE_ONCE(meta->reader.id, cpu_buffer->reader_page->id);
> > > + WRITE_ONCE(meta->reader.lost_events, cpu_buffer->lost_events);
> > > +
> > > + WRITE_ONCE(meta->entries, local_read(&cpu_buffer->entries));
> > > + WRITE_ONCE(meta->overrun, local_read(&cpu_buffer->overrun));
> > > + WRITE_ONCE(meta->read, cpu_buffer->read);
> > > +}
> > > +
> > > static void
> > > rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
> > > {
> > > @@ -5204,6 +5225,9 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
> > > cpu_buffer->lost_events = 0;
> > > cpu_buffer->last_overrun = 0;
> > >
> > > + if (cpu_buffer->mapped)
> >
> > There are some cpu_buffer->mapped are accessed via WRITE_ONCE/READ_ONCE()
> > but others are not. What makes those different?
>
> The cpu_buffer->mapped is READ_ONCE for the section where it is not protected
> with a lock. That is (in this version) only ring_buffer_swap_cpu().
>
> That said...
>
> a. This is not enough protection at this level, Ideally the _map should also
> call synchronize_rcu() to make sure the _swap does see the ->mapped > 0.
>
> b. With refcount for the snapshot in trace/trace.c, it is not possible for those
> functions to race. trace_arm_snapshot() and tracing_buffers_mmap() are mutually
> exclusive and already stabilized with the trace mutex.
>
> So how about I completely remove those WRITE_ONCE/READ_ONCE and just rely on the
> protection given in trace/trace.c instead of duplicating it in
> trace/ring_buffer.c?
I would add a comment and replace the READ_ONCE with WARN_ON_ONCE():
/* It is up to the callers to not swap mapped buffers */
if (WARN_ON_ONCE(cpu_buffer_a->mapped || cpu_buffer_b->mapped)) {
ret = -EBUSY;
goto out;
}
-- Steve
next prev parent reply other threads:[~2024-02-04 0:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 14:27 [PATCH v13 0/6] Introducing trace buffer mapping by user-space Vincent Donnefort
2024-01-29 14:27 ` [PATCH v13 1/6] ring-buffer: Zero ring-buffer sub-buffers Vincent Donnefort
2024-01-29 14:27 ` [PATCH v13 2/6] ring-buffer: Introducing ring-buffer mapping functions Vincent Donnefort
2024-01-30 14:55 ` Masami Hiramatsu
2024-01-30 16:22 ` Vincent Donnefort
2024-02-04 0:54 ` Steven Rostedt [this message]
2024-02-04 0:33 ` Steven Rostedt
2024-02-05 9:43 ` Vincent Donnefort
2024-01-29 14:27 ` [PATCH v13 3/6] tracing: Add snapshot refcount Vincent Donnefort
2024-01-30 9:30 ` kernel test robot
2024-01-30 10:32 ` Vincent Donnefort
2024-02-05 10:25 ` Steven Rostedt
2024-01-29 14:28 ` [PATCH v13 4/6] tracing: Allow user-space mapping of the ring-buffer Vincent Donnefort
2024-01-29 14:28 ` [PATCH v13 5/6] Documentation: tracing: Add ring-buffer mapping Vincent Donnefort
2024-01-29 14:28 ` [PATCH v13 6/6] ring-buffer/selftest: Add ring-buffer mapping test Vincent Donnefort
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=20240203195430.51171d85@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=g@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=vdonnefort@google.com \
/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®