From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Vincent Donnefort <vdonnefort@google.com>,
Zhu Jun <zhujun2@cmss.chinamobile.com>
Subject: [for-next][PATCH 2/3] ring-buffer: Mark concurrent accesses to waiter flags
Date: Wed, 02 Dec 2026 03:10:40 -0500 [thread overview]
Message-ID: <20261202081110.582906299@kernel.org> (raw)
In-Reply-To: 20261202081038.604861818@kernel.org
From: Zhu Jun <zhujun2@cmss.chinamobile.com>
Poll and wait paths set the pending waiter flags while ring buffer
writers test and clear them without a common lock. The irq_work callback
also accesses the full-buffer wakeup flags concurrently. These plain
accesses cause KCSAN reports.
Use READ_ONCE() and WRITE_ONCE() for the shared waiter and wakeup flags.
Keep the existing barriers and irq_work wakeup protocol unchanged.
Link: https://patch.msgid.link/20261111084137.80941-1-zhujun2@cmss.chinamobile.com
Fixes: 15693458c4bc ("tracing/ring-buffer: Move poll wake ups into ring buffer code")
Fixes: 1e0d6714aceb ("ring-buffer: Do not wake up a splice waiter when page is not full")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ring_buffer.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 0377868a12c2..5c08a755d29d 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -904,14 +904,14 @@ static void rb_wake_up_waiters(struct irq_work *work)
(void)atomic_fetch_inc_release(&rbwork->seq);
wake_up_all(&rbwork->waiters);
- if (rbwork->full_waiters_pending || rbwork->wakeup_full) {
+ if (READ_ONCE(rbwork->full_waiters_pending) || READ_ONCE(rbwork->wakeup_full)) {
/* Only cpu_buffer sets the above flags */
struct ring_buffer_per_cpu *cpu_buffer =
container_of(rbwork, struct ring_buffer_per_cpu, irq_work);
scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) {
- rbwork->wakeup_full = false;
- rbwork->full_waiters_pending = false;
+ WRITE_ONCE(rbwork->wakeup_full, false);
+ WRITE_ONCE(rbwork->full_waiters_pending, false);
/* Waking up all waiters, they will reset the shortest full */
cpu_buffer->shortest_full = 0;
@@ -1023,9 +1023,9 @@ rb_wait_cond(struct rb_irq_work *rbwork, struct trace_buffer *buffer,
* a task has been queued. It's OK for spurious wake ups.
*/
if (full)
- rbwork->full_waiters_pending = true;
+ WRITE_ONCE(rbwork->full_waiters_pending, true);
else
- rbwork->waiters_pending = true;
+ WRITE_ONCE(rbwork->waiters_pending, true);
return false;
}
@@ -1153,12 +1153,12 @@ __poll_t ring_buffer_poll_wait(struct trace_buffer *buffer, int cpu,
* full_waiters_pending doesn't leak up into the above.
*/
smp_mb();
- rbwork->full_waiters_pending = true;
+ WRITE_ONCE(rbwork->full_waiters_pending, true);
return 0;
}
poll_wait(filp, &rbwork->waiters, poll_table);
- rbwork->waiters_pending = true;
+ WRITE_ONCE(rbwork->waiters_pending, true);
/*
* There's a tight race between setting the waiters_pending and
@@ -4387,14 +4387,14 @@ rb_irq_work_queue(struct rb_irq_work *irq_work)
static __always_inline void
rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
{
- if (buffer->irq_work.waiters_pending) {
- buffer->irq_work.waiters_pending = false;
+ if (READ_ONCE(buffer->irq_work.waiters_pending)) {
+ WRITE_ONCE(buffer->irq_work.waiters_pending, false);
/* irq_work_queue() supplies it's own memory barriers */
rb_irq_work_queue(&buffer->irq_work);
}
- if (cpu_buffer->irq_work.waiters_pending) {
- cpu_buffer->irq_work.waiters_pending = false;
+ if (READ_ONCE(cpu_buffer->irq_work.waiters_pending)) {
+ WRITE_ONCE(cpu_buffer->irq_work.waiters_pending, false);
/* irq_work_queue() supplies it's own memory barriers */
rb_irq_work_queue(&cpu_buffer->irq_work);
}
@@ -4405,7 +4405,7 @@ rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
if (cpu_buffer->reader_page == cpu_buffer->commit_page)
return;
- if (!cpu_buffer->irq_work.full_waiters_pending)
+ if (!READ_ONCE(cpu_buffer->irq_work.full_waiters_pending))
return;
cpu_buffer->last_pages_touch = local_read(&cpu_buffer->pages_touched);
@@ -4413,8 +4413,8 @@ rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
if (!full_hit(buffer, cpu_buffer->cpu, cpu_buffer->shortest_full))
return;
- cpu_buffer->irq_work.wakeup_full = true;
- cpu_buffer->irq_work.full_waiters_pending = false;
+ WRITE_ONCE(cpu_buffer->irq_work.wakeup_full, true);
+ WRITE_ONCE(cpu_buffer->irq_work.full_waiters_pending, false);
/* irq_work_queue() supplies it's own memory barriers */
rb_irq_work_queue(&cpu_buffer->irq_work);
}
--
2.53.0
next prev parent reply other threads:[~2026-12-02 8:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:10 [for-next][PATCH 0/3] ring-buffer: Updates for v7.5 Steven Rostedt
2026-12-02 8:10 ` [for-next][PATCH 1/3] ring-buffer: Use is_user_task() in __rb_allocate_pages() Steven Rostedt
2026-12-02 8:10 ` Steven Rostedt [this message]
2026-12-02 8:10 ` [for-next][PATCH 3/3] ring-buffer: Annotate the speculative iterator event copy 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=20261202081110.582906299@kernel.org \
--to=rostedt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=vdonnefort@google.com \
--cc=zhujun2@cmss.chinamobile.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