From: Steven Rostedt <rostedt@goodmis.org>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rt-users <linux-rt-users@vger.kernel.org>
Subject: Re: [PATCH 2/2] ring-buffer: Fix a race between readers and resize checks
Date: Mon, 27 May 2024 19:43:56 -0400 [thread overview]
Message-ID: <20240527194356.5078b56f@rorschach.local.home> (raw)
In-Reply-To: <2b920bab-23a2-4a8d-95c2-b69472d38373@suse.com>
On Mon, 27 May 2024 11:36:55 +0200
Petr Pavlu <petr.pavlu@suse.com> wrote:
> >> static void rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer)
> >> {
> >> @@ -2200,8 +2205,13 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
> >> */
> >> synchronize_rcu();
> >> for_each_buffer_cpu(buffer, cpu) {
> >> + unsigned long flags;
> >> +
> >> cpu_buffer = buffer->buffers[cpu];
> >> + raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> >> rb_check_pages(cpu_buffer);
> >> + raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock,
> >> + flags);
> >
> > Putting my RT hat on, I really don't like the above fix. The
> > rb_check_pages() iterates all subbuffers which makes the time interrupts
> > are disabled non-deterministic.
>
> I see, this applies also to the same rb_check_pages() validation invoked
> from ring_buffer_read_finish().
>
> >
> > Instead, I would rather have something where we disable readers while we do
> > the check, and re-enable them.
> >
> > raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> > cpu_buffer->read_disabled++;
> > raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> >
> > // Also, don't put flags on a new line. We are allow to go 100 characters now.
>
> Noted.
>
> >
> >
> > rb_check_pages(cpu_buffer);
> > raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> > cpu_buffer->read_disabled--;
> > raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> >
> > Or something like that. Yes, that also requires creating a new
> > "read_disabled" field in the ring_buffer_per_cpu code.
>
> I think this would work but I'm personally not immediately sold on this
> approach. If I understand the idea correctly, readers should then check
> whether cpu_buffer->read_disabled is set and bail out with some error if
> that is the case. The rb_check_pages() function is only a self-check
> code and as such, I feel it doesn't justify disrupting readers with
> a new error condition and adding more complex locking.
Honestly, this code was never made for more than one reader per
cpu_buffer. I'm perfectly fine if all check_pages() causes other
readers to the same per_cpu buffer to get -EBUSY.
Do you really see this being a problem? What use case is there for
hitting the check_pages() and reading the same cpu buffer at the same
time?
-- Steve
next prev parent reply other threads:[~2024-05-27 23:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240517134008.24529-1-petr.pavlu@suse.com>
[not found] ` <20240517134008.24529-3-petr.pavlu@suse.com>
2024-05-20 13:50 ` [PATCH 2/2] ring-buffer: Fix a race between readers and resize checks Steven Rostedt
2024-05-27 9:36 ` Petr Pavlu
2024-05-27 23:43 ` Steven Rostedt [this message]
2024-06-07 8:29 ` Petr Pavlu
2024-06-10 15:56 ` Steven Rostedt
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=20240527194356.5078b56f@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=petr.pavlu@suse.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