Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] ring-buffer: Annotate the speculative iterator event copy
@ 2026-11-11  8:42 Zhu Jun
  2026-11-11  9:10 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-11  8:42 UTC (permalink / raw)
  To: rostedt
  Cc: vdonnefort, mhiramat, mathieu.desnoyers, linux-trace-kernel,
	linux-kernel, syzbot+530af6f1e5c230588975, Zhu Jun

A non-consuming iterator can copy an event while the writer overwrites
its page. The reader lock only excludes other readers, so KCSAN reports
the memcpy() racing with event reservation.

The iterator already checks the page stamp and committed size after the
copy and retries if the writer entered the page. Mark the speculative
copy as an intentional race; only the validated private copy is used.

Fixes: 785888c544e0 ("ring-buffer: Have rb_iter_head_event() handle concurrent writer")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 kernel/trace/ring_buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 18f023cf1d6f..197015ff715a 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3566,7 +3566,8 @@ rb_iter_head_event(struct ring_buffer_iter *iter)
 		/* Writer corrupted the read? */
 		goto reset;
 
-	memcpy(iter->event, event, length);
+	/* The page stamp below detects a concurrent overwrite of this copy. */
+	data_race(memcpy(iter->event, event, length));
 	/*
 	 * If the page stamp is still the same after this rmb() then the
 	 * event was safely copied without the writer entering the page.
-- 
2.51.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-11  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  8:42 [PATCH] ring-buffer: Annotate the speculative iterator event copy Zhu Jun
2026-11-11  9:10 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox