From: Peter Zijlstra <peterz@infradead.org>
To: Kunwu Chan <kunwu.chan@gmail.com>
Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
sj@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
rdunlap@infradead.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, akpm@linux-foundation.org,
lianux.mm@gmail.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 1/5] perf/core: add AUX buffer ownership for kernel events
Date: Mon, 12 Oct 2026 12:42:08 +0200 [thread overview]
Message-ID: <20261012104208.GQ4121339@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20261009160010.1829642-2-kunwu.chan@gmail.com>
On Fri, Oct 09, 2026 at 11:59:48PM +0800, Kunwu Chan wrote:
> Add an in-kernel AUX owner reference and setup/release helpers for
> kernel-created perf events that need an AUX buffer without a userspace
> mmap. The setup path validates that the event is a kernel event with
> no parent, rejects non-power-of-two page counts and negative watermark
> values, allocates the perf buffer and AUX pages, records the kernel
> owner, and attaches the buffer under the same lock.
>
> perf_event_release_aux() stops AUX writers, frees AUX storage, and
> detaches the buffer, in that order, matching the AUX teardown ordering
> of perf_mmap_close(): perf_pmu_output_stop() walks event->rb->event_list
> and rb_free_aux() must run while the buffer is still referenced by the
> event. The single event->rb reference is dropped by
> ring_buffer_attach(event, NULL) itself, so the release path does not
> put it again.
>
> Both functions run under event->mmap_mutex, the lock that already
> serialises ring-buffer attach/detach transitions for an event:
> perf_mmap(), perf_mmap_close(), _perf_event_set_output() and
> _free_event() all hold it around ring_buffer_attach(). Concurrent
> perf_event_release_aux() callers therefore go through the same
> serialisation point, and a second release call, or a release of a
> buffer this API does not own, is a no-op.
>
> Keep aux_mmap_count dedicated to userspace mappings.
> perf_aux_output_begin() accepts a writer while either a userspace or kernel
> owner remains, preserving the existing teardown ordering.
>
> diff --git a/kernel/events/internal.h b/kernel/events/internal.h
> index c03c4f2eea57..760b7659ad87 100644
> --- a/kernel/events/internal.h
> +++ b/kernel/events/internal.h
> @@ -48,6 +48,12 @@ struct perf_buffer {
> int aux_nr_pages;
> int aux_overwrite;
> refcount_t aux_mmap_count;
> + /*
> + * In-kernel AUX owner reference, set by perf_event_setup_aux():
> + * admits writers and ties the AUX teardown to
> + * perf_event_release_aux() when no userspace mmap holds the buffer.
> + */
> + refcount_t aux_kernel_count;
> unsigned long aux_mmap_locked;
> void (*free_aux)(void *);
> refcount_t aux_refcount;
This doesn't make sense to me. If the even is a kernel event, then there
cannot be mmap users, so adding another refcount is just for giggles?
next prev parent reply other threads:[~2026-10-12 10:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:59 [PATCH v2 0/5] perf/core: add AUX buffer kernel-consumer API Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 1/5] perf/core: add AUX buffer ownership for kernel events Kunwu Chan
2026-10-12 10:42 ` Peter Zijlstra [this message]
2026-10-09 15:59 ` [PATCH v2 2/5] perf/core: add AUX ring accessors for kernel consumers Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 3/5] perf/core: add KUnit tests for AUX kernel-consumer API Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 4/5] selftests/perf_events: add userspace AUX regression test Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 5/5] selftests/perf_events: add AUX kernel API selftest script Kunwu Chan
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=20261012104208.GQ4121339@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=corbet@lwn.net \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kunwu.chan@gmail.com \
--cc=lianux.mm@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=rdunlap@infradead.org \
--cc=sj@kernel.org \
--cc=skhan@linuxfoundation.org \
/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
all inboxes | Powered by JetHome®