All of lore.kernel.org
 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 3/5] perf/core: add KUnit tests for AUX kernel-consumer API
Date: Sun, 04 Oct 2026 17:45:20 +0000	[thread overview]
Message-ID: <20261004174520.8BE771F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004173458.837842-4-kunwu.chan@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf: double free of perf_event in aux_test_create_event()
- [Medium] perf: memory leak of AUX pages on KUnit assertion failure
--

commit 5c8a187a6ddc0c41bba18676f8fced4749f18392
Author: Lian Wang <lianux.mm@gmail.com>

perf/core: add KUnit tests for AUX kernel-consumer API

This commit adds a KUnit test suite for the perf AUX kernel-consumer API.
It registers a self-contained dummy AUX PMU and includes 39 test cases to 
cover the setup, release, and data copying lifecycle.

> diff --git a/kernel/events/aux_kernel_test.c b/kernel/events/aux_kernel_test.c
> new file mode 100644
> --- /dev/null
> +++ b/kernel/events/aux_kernel_test.c

[ ... ]

> +static struct perf_event *aux_test_create_event(struct kunit *test)
> +{
> +	struct perf_event_attr attr = {};
> +	struct perf_event *event;
> +
> +	attr.type = dummy_aux_pmu_type;
> +	attr.size = sizeof(attr);
> +	attr.disabled = 1;
> +
> +	event = perf_event_create_kernel_counter(&attr, raw_smp_processor_id(),
> +						 NULL, NULL, NULL);
> +	if (IS_ERR(event))
> +		return event;
> +
> +	if (kunit_add_action_or_reset(test, aux_test_event_release, event)) {
> +		perf_event_release_kernel(event);

[Severity: Medium]
Will this cause a double free of the event object?

If kunit_add_action_or_reset() fails, it automatically executes the cleanup 
action, which in this case is aux_test_event_release(). That callback 
already invokes perf_event_release_kernel() on the event. Calling it a 
second time explicitly in this error path appears to trigger a double free.

> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	return event;
> +}

[ ... ]

> +static void test_user_kernel_coexistence(struct kunit *test)
> +{
> +	struct perf_event *ev_a = aux_test_create_event(test);
> +	struct perf_event *ev_b = aux_test_create_event(test);
> +	struct perf_output_handle handle_a, handle_b;
> +	unsigned long a_head_before, b_head_before;
> +	void *addr;
> +	int ret;

[ ... ]

> +	/* Simulate userspace ownership: swap refcounts on B's rb.
> +	 * perf_mmap() would set aux_mmap_count=1 for a userspace event.
> +	 */
> +	refcount_set(&ev_b->rb->aux_mmap_count, 1);
> +	refcount_set(&ev_b->rb->aux_kernel_count, 0);
> +
> +	/* Produce on A — B's head stays 0 */
> +	addr = perf_aux_output_begin(&handle_a, ev_a);
> +	KUNIT_ASSERT_NOT_NULL(test, addr);

[Severity: Medium]
Does this leak the AUX pages if the assertion fails?

If this assertion or subsequent assertions fail while aux_kernel_count is
set to 0, the test will immediately abort and skip the manual refcount
restoration at the end of the function.

When KUnit runs the deferred cleanup action aux_test_event_release() on 
abort, perf_event_release_aux() observes that aux_kernel_count is 0 and 
returns early without tearing down the buffer, leaving the memory 
permanently leaked.

> +	perf_aux_output_end(&handle_a, 512);

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

  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
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 [this message]
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=20261004174520.8BE771F000FF@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.