BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v5 2/2] perf test: Add filtered event enabled time tests to event-times
Date: Thu, 03 Dec 2026 19:17:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-248480@kernel.org> (raw)
In-Reply-To: <77db7c446d31285aef889a726055489f8f1f2c10.1796323635.git.irogers@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] perf test: missing exclusive flag for pinned PMU event-times
  subtests
- [Low] perf test: uninitialized rt_child read on read_times() failure
- [Low] perf tools: zfree() may clobber errno before EINVAL check in
  affinity__setup()
- [Low] perf test: suite__event_times omits needs_mlock while mmapping
  perf fd
--

commit d7c83c2e6723a4a0fc8b63cdeef1ea6d8a997d9d
Author: Ian Rogers <irogers@google.com>

perf test: Add filtered event enabled time tests to event-times

This commit adds four filtered event enabled time subtests to the
event-times perf test suite and hardens tools/perf/util/affinity.{c,h} to
retry on EINVAL for large cpumasks, check CPU membership, and return an
error status from affinity__set().

> diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
> index 56dd37ca760ec..7068be72e3471 100644
> --- a/tools/perf/tests/event-times.c
> +++ b/tools/perf/tests/event-times.c

[ ... ]

> @@ -239,4 +252,842 @@ static int test__event_times(struct test_suite *test __maybe_unused, int subtest
>  	return ret;
>  }

[ ... ]

> +	if (read_times(fd, &rt_child) < 0 ||
> +	    rt_child.run <= rt_after.run || rt_child.ena != rt_child.run) {
> +		pr_debug("FAILED: inherited task+CPU mismatch: ena=%" PRIu64 " run=%" PRIu64 "\n",
> +			 rt_child.ena, rt_child.run);
> +		goto out;
> +	}

[Severity: Low]
Can pr_debug() read uninitialized stack memory here when read_times() fails?

rt_child is declared uninitialized on the stack in
test__event_times_task_and_cpu(), so if read_times(fd, &rt_child) returns -1
the short-circuit enters this block and prints uninitialized rt_child.ena
and rt_child.run.  Checking read_times() separately, as done earlier in the
same function, avoids the uninitialized read.

[ ... ]

> +static struct test_case tests__event_times[] = {
> +	TEST_CASE("Basic event times", event_times),
> +	TEST_CASE_REASON("Task and CPU filtered event times",
> +			 event_times_task_and_cpu,
> +			 "permissions or <2 allowed CPUs"),
> +	TEST_CASE_REASON("Hybrid PMU filtered event times",
> +			 event_times_hybrid,
> +			 "not hybrid or permissions"),
> +	TEST_CASE_REASON("Multiplexed and group filtered event times",
> +			 event_times_mux_migration,
> +			 "no hardware PMU or <2 allowed CPUs"),
> +	TEST_CASE_REASON("Pinned-blocked and group rollback event times",
> +			 event_times_pinned_rollback,
> +			 "no hardware PMU or <2 allowed CPUs"),
> +	{	.name = NULL, }
> +};

[Severity: Medium]
Should event_times_pinned_rollback and event_times_mux_migration use
TEST_CASE_REASON_EXCLUSIVE instead of TEST_CASE_REASON?

Default parallel perf test runs non-exclusive cases concurrently in pass 1
and only serializes exclusive ones in pass 2.
test_one_pmu_pinned_blocked_and_rollback() holds a pinned, exclusive PMU
event on cpu0 for 45 ms, setting cpc->exclusive and blocking other events.

Concurrent pass-1 hardware PMU tests can either be starved or compete with
pin_fd and force it into PERF_EVENT_STATE_ERROR, causing spurious TEST_FAIL
or TEST_SKIP results.  test_one_pmu_mux_migration() similarly opens 15
hardware PMU events on cpu0 while other pass-1 PMU tests are running.

> +
> +struct test_suite suite__event_times = {
> +	.desc = "Event times",
> +	.test_cases = tests__event_times,
> +};

[Severity: Low]
Does suite__event_times need .needs_mlock = true?

test__event_times_task_and_cpu() mmaps the perf event userpage for the
duration of the subtest, which charges one page against
current_user()->perf_mlock in perf_mmap_rb().  Without .needs_mlock = true,
it runs concurrently with needs_mlock suites holding mlock_budget->lock.

In an unprivileged parallel perf test run with no spare RLIMIT_MEMLOCK,
this can cause a concurrent needs_mlock test to fail with EPERM, or cause
mmap() here to return MAP_FAILED and silently skip the userpage check.

> diff --git a/tools/perf/util/affinity.c b/tools/perf/util/affinity.c
> index 6c64b5f69a4e0..e610eb959347d 100644
> --- a/tools/perf/util/affinity.c
> +++ b/tools/perf/util/affinity.c

[ ... ]

> @@ -10,73 +11,98 @@
>  #include "cpumap.h"
>  #include "affinity.h"

[ ... ]

>  int affinity__setup(struct affinity *a)
>  {
> -	int cpu_set_size = get_cpu_set_size();
> +	size_t bits = get_cpu_set_bits();
>  
> -	a->orig_cpus = bitmap_zalloc(cpu_set_size * 8);
> -	if (!a->orig_cpus)
> -		return -1;
> -	sched_getaffinity(0, cpu_set_size, (cpu_set_t *)a->orig_cpus);
> -	a->sched_cpus = bitmap_zalloc(cpu_set_size * 8);
> +	*a = (struct affinity){};
> +	for (;;) {
> +		unsigned long *orig = bitmap_zalloc(bits);
> +
> +		if (!orig)
> +			return -1;
> +		if (sched_getaffinity(0, bits / 8, (cpu_set_t *)orig) == 0) {
> +			a->orig_cpus = orig;
> +			break;
> +		}
> +		zfree(&orig);
> +		if (errno != EINVAL || bits >= (1U << 20))
> +			return -1;
> +		bits <<= 1;
> +	}

[Severity: Low]
Can zfree(&orig) clobber errno before the errno != EINVAL check?

zfree() calls free(), which is not guaranteed to preserve errno under
POSIX.1-2008 or older glibc.  If free() modifies errno on a large-cpumask
system, affinity__setup() returns -1 instead of retrying with a larger
buffer.  Saving errno before calling zfree(&orig) avoids this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/6e0c4ab555fda856605bd818854a6ef8ced4fcbd.1796323635.git.irogers@google.com?part=2

      reply	other threads:[~2026-12-03 19:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 18:53 [PATCH v5 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time Ian Rogers
2026-12-03 18:53 ` [PATCH v5 2/2] perf test: Add filtered event enabled time tests to event-times Ian Rogers
2026-12-03 19:17   ` 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-248480@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.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