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 4/5] selftests/perf_events: add userspace AUX regression test
Date: Sun, 04 Oct 2026 17:43:48 +0000	[thread overview]
Message-ID: <20261004174349.285441F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004173458.837842-5-kunwu.chan@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Medium] selftests/perf_events: spurious failure on strict perf_event_paranoid
- [Medium] selftests/perf_events: reading aux_head before disable causes spurious SKIP
- [Medium] selftests/perf_events: inconsistent PMU config rejection handling
- [Low] selftests/perf_events: missing -latomic causes 32-bit build failure
--

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

selftests/perf_events: add userspace AUX regression test

This commit adds a C program to test the userspace AUX mmap protocol.
It verifies that the perf event AUX setup handles configuration, memory mapping,
and independent event buffers correctly without breaking user space.

> diff --git a/tools/testing/selftests/perf_events/Makefile b/tools/testing/selftests/perf_events/Makefile
> index 2e5d85770dfea..fbafbd43f097e 100644
> --- a/tools/testing/selftests/perf_events/Makefile
> +++ b/tools/testing/selftests/perf_events/Makefile
> @@ -3,4 +3,5 @@ CFLAGS += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES)
>  LDFLAGS += -lpthread

[Severity: Low]
Since the tests in aux_kernel_usermode.c use 64-bit atomic operations on
__u64 types, does the Makefile need the -latomic flag? Building on 32-bit
architectures usually requires linking libatomic to avoid build failures
on 64-bit atomic loads.

>  
>  TEST_GEN_PROGS := sigtrap_threads remove_on_exec watermark_signal mmap
> +TEST_GEN_PROGS += aux_kernel_usermode
>  include ../lib.mk

[ ... ]

> diff --git a/tools/testing/selftests/perf_events/aux_kernel_usermode.c b/tools/testing/selftests/perf_events/aux_kernel_usermode.c
> new file mode 100644
> index 0000000000000..5c2da4bac0740
> --- /dev/null
> +++ b/tools/testing/selftests/perf_events/aux_kernel_usermode.c
> @@ -0,0 +1,627 @@
[ ... ]
> +static int test_aux_mmap(int pmu_type)
> +{
> +	struct perf_event_attr attr = {};
> +	struct perf_event_mmap_page *mp;
> +	void *aux_base;
> +	unsigned long aux_size, aux_offset, mmap_size;
> +	int fd, ret;
> +
> +	attr.type = pmu_type;
> +	attr.size = sizeof(attr);
> +	attr.disabled = 1;
> +	attr.sample_period = 256;
> +
> +	/* ARM SPE requires period mode (freq=0) */
> +	attr.freq = 0;
> +
> +	fd = perf_event_open(&attr, 0, -1, -1, 0);
> +	if (fd < 0) {
> +		FAIL("AUX mmap: perf_event_open failed (%s)", strerror(errno));
> +		return 1;
> +	}

[Severity: Medium]
Could this cause a false positive failure if the PMU legitimately rejects
the zeroed configuration? Later in test_aux_head_monotonic, the same fd < 0
condition correctly uses SKIP to handle PMU rejection. Should this also skip
rather than failing entirely on systems with strict AUX PMUs?

[ ... ]

> +static int test_aux_head_monotonic(int pmu_type)
> +{
[ ... ]
> +	/* Read initial head */
> +	head_before = __atomic_load_n(&mp->aux_head, __ATOMIC_RELAXED);
> +
> +	usleep(100000); /* 100ms */
> +
> +	head_after = __atomic_load_n(&mp->aux_head, __ATOMIC_RELAXED);
> +
> +	ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);

[Severity: Medium]
Since head_after is read before the event is disabled, is there a chance
the hardware trace data hasn't been flushed to the ring buffer yet?
Hardware tracing PMUs typically only update the control page when explicitly
disabled or during an interrupt, which could cause a spurious SKIP here.
Would it be safer to disable the event before reading head_after?

[ ... ]

> +int main(void)
> +{
[ ... ]
> +	/* Test 6: Verify /proc/sys/kernel/perf_event_paranoid */
> +	printf("\n--- 6. Perf Event Paranoid ---\n");
> +	{
> +		FILE *f = fopen("/proc/sys/kernel/perf_event_paranoid", "r");
> +		int paranoid;
> +
> +		if (f) {
> +			if (fscanf(f, "%d", &paranoid) == 1) {
> +				printf("  perf_event_paranoid=%d\n", paranoid);
> +				if (paranoid > 2)
> +					FAIL("perf_event_paranoid=%d may block AUX",
> +					     paranoid);

[Severity: Medium]
Since the selftest enforces root execution at the beginning of main,
does this sysctl value actually restrict the test? A strict perf_event_paranoid
value greater than 2 typically doesn't block root users. Could this logic
incorrectly report a failure on systems with strict defaults?

> +				else
> +					PASS("perf_event_paranoid=%d (OK)", paranoid);
> +			}
> +			fclose(f);
> +		} else {
> +			printf("  [SKIP] Cannot read perf_event_paranoid\n");
> +		}
> +	}
> +
> +	printf("\n=== Result: %s ===\n", failed ? "FAIL" : "PASS");
> +	if (skipped)
> +		printf("=== Note: some tests were SKIPped (environment)\n");
> +	return failed ? 1 : 0;
> +}

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

  reply	other threads:[~2026-10-04 17:43 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
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 [this message]
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=20261004174349.285441F000FF@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