Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kunwu Chan" <kunwu.chan@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/5] perf/core: add AUX ring accessors for kernel consumers
Date: Sun, 04 Oct 2026 17:45:25 +0000	[thread overview]
Message-ID: <20261004174526.4111B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004173458.837842-3-kunwu.chan@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf: misplaced smp_rmb() in perf_event_aux_tail_set()
--

commit bf06e748dd797d73b38eceb210cb85ac496712d0
Author: Kunwu Chan <kunwu.chan@gmail.com>

perf/core: add AUX ring accessors for kernel consumers

This commit adds kernel-consumer accessors for the published AUX producer head,
the consumer tail, and copying a possibly wrapped AUX interval. It introduces
these helpers to allow kernel consumers to own and drain the AUX buffer
without relying on the overflow path.

> diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
> index eae28e42346c7..2c6f260fcf91b 100644
> --- a/kernel/events/ring_buffer.c
> +++ b/kernel/events/ring_buffer.c
[ ... ]
> +int perf_event_aux_tail_set(struct perf_event *event, unsigned long tail)
> +{
> +	struct perf_buffer *rb = ring_buffer_get(event);
> +	unsigned long advance, aux_size, head, old_tail;
> +	int ret = -EINVAL;
> +
> +	if (!rb)
> +		return -ENOENT;
> +
> +	if (!rb_has_kernel_aux(rb)) {
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +
> +	aux_size = (unsigned long)rb->aux_nr_pages << PAGE_SHIFT;
> +	old_tail = READ_ONCE(rb->user_page->aux_tail);
> +	/*
> +	 * Pairs with the producer's AUX-data write barrier in
> +	 * perf_aux_output_end() before it publishes aux_head.
> +	 */
> +	smp_rmb();
> +	head = READ_ONCE(rb->user_page->aux_head);

[Severity: Low]
Is this smp_rmb() necessary here? Memory barriers order operations, they do not
accelerate visibility. Since perf_event_aux_tail_set() performs no payload data
reads, there is nothing for the smp_rmb() to order against the read of aux_head,
rendering the barrier functionally inert.

The comment claims it pairs with the producer's AUX-data write barrier, but
without trailing data reads, this pairing is meaningless. Does this result in
unnecessary code complexity and a negligible performance overhead, while
providing no structural safety risk since the subsequent smp_mb() correctly
orders space release?

> +	advance = tail - old_tail;
> +
> +	/* Modular distances keep the check valid when a cursor wraps. */
> +	if (head - old_tail <= aux_size && advance <= head - old_tail) {
> +		/* Order all prior AUX data reads before releasing the space. */
> +		smp_mb();
> +		WRITE_ONCE(rb->user_page->aux_tail, tail);
> +		ret = 0;
> +	}
> +
> +out:
> +	ring_buffer_put(rb);
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004173458.837842-1-kunwu.chan@gmail.com?part=2

  reply	other threads:[~2026-10-04 17:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 17:34 [PATCH 0/5] perf/core: add AUX buffer kernel-consumer API Kunwu Chan
2026-10-04 17:34 ` [PATCH 1/5] perf/core: add AUX buffer ownership for kernel events Kunwu Chan
2026-10-04 17:55   ` sashiko-bot
2026-10-04 17:34 ` [PATCH 2/5] perf/core: add AUX ring accessors for kernel consumers Kunwu Chan
2026-10-04 17:45   ` sashiko-bot [this message]
2026-10-04 17:34 ` [PATCH 3/5] perf/core: add KUnit tests for AUX kernel-consumer API Kunwu Chan
2026-10-04 17:45   ` sashiko-bot
2026-10-04 17:34 ` [PATCH 4/5] selftests/perf_events: add userspace AUX regression test Kunwu Chan
2026-10-04 17:43   ` sashiko-bot
2026-10-04 17:34 ` [PATCH 5/5] selftests/perf_events: add AUX kernel API selftest script Kunwu Chan
2026-10-04 17:45   ` sashiko-bot

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=20261004174526.4111B1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kunwu.chan@gmail.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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