Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhu Jun" <zhujun2@cmss.chinamobile.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] ring-buffer: Annotate the speculative iterator event copy
Date: Wed, 11 Nov 2026 09:10:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-208667@kernel.org> (raw)
In-Reply-To: <20261111084201.80984-1-zhujun2@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ring-buffer: unannotated speculative reads in
  rb_iter_head_event()
--

commit a821b9e5782f64ce12600813e637e78c35dbbee8
Author: Zhu Jun <zhujun2@cmss.chinamobile.com>

ring-buffer: Annotate the speculative iterator event copy

This commit wraps the speculative memcpy() in rb_iter_head_event() with
data_race() to silence KCSAN warnings when a concurrent writer overwrites
the page being read by a non-consuming iterator.

> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index e760d2fe386fb..6e51a7a75d6b1 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -3562,7 +3562,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));

[Severity: Low]
Can KCSAN still trigger on the adjacent speculative reads of event and
iter_head_page->page->time_stamp in rb_iter_head_event()?

kernel/trace/ring_buffer.c:rb_iter_head_event() {
    ...
	event = __rb_page_index(iter_head_page, iter->head);
	length = rb_event_length(event);
    ...
	data_race(memcpy(iter->event, event, length));
	smp_rmb();

	/* Make sure the page didn't change since we read this */
	if (iter->page_stamp != iter_head_page->page->time_stamp ||
    ...
}

Before the annotated memcpy(), rb_event_length(event) reads
event->type_len, event->time_delta, and event->array[0] from the same
shared page while a concurrent writer updates the header in
rb_update_event(). Because rb_event_length() and rb_event_data_length()
read the event->type_len bitfield via plain loads across multiple checks,
the compiler can also reload inconsistent values if a writer modifies the
header mid-evaluation. Likewise, the plain loads of
iter_head_page->page->time_stamp in the validation check and reset path
race with the writer updating tail_page->page->time_stamp in
__rb_reserve_next().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111084201.80984-1-zhujun2@cmss.chinamobile.com?part=1

      reply	other threads:[~2026-11-11  9:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  8:42 [PATCH] ring-buffer: Annotate the speculative iterator event copy Zhu Jun
2026-11-11  9:10 ` sashiko-bot [this message]

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=sashiko-outbox-208667@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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