[for-next][PATCH 3/3] ring-buffer: Annotate the speculative iterator event copy
From: Steven Rostedt
Date: Wed Dec 02 2026 - 03:11:22 EST
From: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
A non-consuming iterator speculatively copies an event while a writer
may overwrite its page. The reader lock excludes other readers, but not
writers, so KCSAN reports the concurrent memcpy() and event reservation
accesses.
The iterator already validates the page stamp and committed size after
the copy and retries if the page changed. This makes the race intentional
and the KCSAN report a false positive. Mark the speculative copy with
data_race() to document the allowed access and suppress the report.
Link: https://patch.msgid.link/20261113083446.177306-1-zhujun2@xxxxxxxxxxxxxxxxxxxx
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
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 5c08a755d29d..f4090e25b910 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3575,7 +3575,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.53.0