From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 25/30] perf pmus: Add perf_pmus__read_from_env()
Date: Fri, 13 Nov 2026 21:05:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-213689@kernel.org> (raw)
In-Reply-To: <20261113195335.2865725-26-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf pmus: empty core_pmus in perf_pmus__read_from_env()
without cpu caps
- [Medium] perf pmus: broken event config name lookup in
env_pmu_find_or_add()
--
commit 62379d346fd8a3e273dd7df18d358ca721a7bc84
Author: Ian Rogers <irogers@google.com>
perf pmus: Add perf_pmus__read_from_env()
This commit adds perf_pmus__read_from_env() and perf_pmu__add_cap() to
reconstruct core and other PMU lists and capabilities from perf.data
header metadata, and lazily populates env->pmus in perf_env__pmus().
> diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
> index 6d68371107aa1..b924ff6180e41 100644
> --- a/tools/perf/util/pmus.c
> +++ b/tools/perf/util/pmus.c
[ ... ]
> @@ -981,3 +984,234 @@ struct perf_pmu *perf_pmus__fake_pmu(void)
>
> return &fake;
> }
[ ... ]
> + pmu->pmus = pmus;
> + pmu->sysfs_aliases_loaded = true;
> + pmu->caps_initialized = true;
> + pmu->max_precise = -1;
> + pmu->is_core = env_is_pmu_core(name, env);
> + pmu->auxtrace = !strcmp(name, "intel_pt") ||
> + !strcmp(name, "intel_bts") ||
> + !strcmp(name, "cs_etm") ||
> + strstarts(name, "arm_spe") ||
> + strstarts(name, "hisi_ptt");
> + pmu->is_uncore = !pmu->is_core && !pmu->auxtrace &&
> + !perf_pmu__is_software(pmu) &&
> + (perf_pmu__kind(pmu) == PERF_PMU_KIND_PE ||
> + pmu->type == PERF_PMU_TYPE_FAKE);
> +
> + if (!strcmp(name, "software") || !strcmp(name, "tool"))
> + pmu->events_table = perf_pmu__default_core_events_table();
> + else if (core_table && (pmu->is_core || pmu->is_uncore))
> + pmu->events_table = core_table;
[Severity: Medium]
Does setting pmu->events_table on an env-backed PMU while leaving
pmu->format empty break perf_pmu__name_from_config() and leak help_msg?
When print_event_desc() or evsel__fprintf() calls
perf_event_attr__fprintf() with perf_env__pmus(env),
perf_pmu__for_each_name_from_config() loads the JSON aliases from
pmu->events_table via pmu_add_cpu_aliases() and calls
perf_pmu__parse_terms_to_attr() -> pmu_config_term() with err == NULL on
each alias. Because pmu->format is empty, pmu_find_format() returns NULL
for every format term (such as event= or umask=):
tools/perf/util/pmu.c:pmu_config_term() {
...
format = pmu_find_format(&pmu->format, term->config);
if (!format) {
char *pmu_term = pmu_formats_string(&pmu->format);
char *unknown_term;
char *help_msg;
...
help_msg = parse_events_formats_error_string(pmu_term);
if (err) {
parse_events_error__handle(err, term->err_term,
unknown_term,
help_msg);
} else {
pr_debug("%s (%s)\n", unknown_term, help_msg);
free(unknown_term);
}
free(pmu_term);
return -EINVAL;
}
...
}
As a result, perf_pmu__name_from_config() fails to resolve format-based
event names, and every alias iteration leaks help_msg in the !err branch.
[ ... ]
> +int perf_pmus__read_from_env(struct perf_pmus *pmus, struct perf_env *env)
> +{
> + const struct pmu_events_table *core_table = NULL;
> + struct perf_pmu *pmu;
> +
> + if (!pmus || !env)
> + return -EINVAL;
> +
> + perf_pmus__exit(pmus);
> + pmus->read_pmu_types = PERF_TOOL_PMU_TYPE_ALL_MASK;
[ ... ]
> + if (env->nr_cpu_pmu_caps > 0 && env->cpu_pmu_caps) {
> + pmu = pmu_find(pmus, "cpu");
> + if (!pmu && !list_empty(&pmus->core_pmus)) {
> + /* Match the writer's perf_pmus__find_core_pmu() order. */
> + list_sort(NULL, &pmus->core_pmus, pmus_cmp);
> + pmu = list_first_entry(&pmus->core_pmus, struct perf_pmu, list);
> + if (pmu->nr_caps > 0)
> + pmu = NULL;
> + } else if (!pmu) {
> + pmu = env_pmu_find_or_add(pmus, "cpu", PERF_TYPE_RAW,
> + env, core_table);
> + }
> + if (pmu)
> + env_pmu_add_caps_strings(pmu, env->nr_cpu_pmu_caps, env->cpu_pmu_caps);
> + }
[Severity: Medium]
Can perf_pmus__read_from_env() leave pmus->core_pmus empty when
env->nr_cpu_pmu_caps is 0?
Unlike pmu_read_sysfs(), which always creates a placeholder core PMU when
pmus->core_pmus is empty, the fallback env_pmu_find_or_add(pmus, "cpu",
PERF_TYPE_RAW, ...) here only runs when env->nr_cpu_pmu_caps > 0. If a
perf.data file has HEADER_PMU_MAPPINGS or HEADER_PMU_CAPS without CPU PMU
capabilities and no PMU name matches env_is_pmu_core() (for example, a VM
recording with only software and tracepoint PMUs), pmus->core_pmus stays
empty while pmus->read_pmu_types is set to PERF_TOOL_PMU_TYPE_ALL_MASK,
preventing pmu_read_sysfs() from creating the placeholder.
perf_pmus__find_core_pmu() and evsel__find_pmu() then return NULL for
PERF_TYPE_HARDWARE, PERF_TYPE_HW_CACHE, and PERF_TYPE_RAW events.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261113195335.2865725-1-irogers@google.com?part=25
next prev parent reply other threads:[~2026-11-13 21:05 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:53 [PATCH v2 00/30] perf: Per-env PMUs, metric event sharing, and recorded event metrics Ian Rogers
2026-11-13 19:53 ` [PATCH v2 01/30] perf pmus: Don't skip core PMUs as duplicates Ian Rogers
2026-11-13 20:04 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 02/30] perf script: Fix metrics computed from samples Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 03/30] perf script: Don't drop metric samples for CPUs missing from the evsel Ian Rogers
2026-11-13 20:02 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 04/30] perf metricgroup: Don't prefer tool events for displaying a metric Ian Rogers
2026-11-13 19:59 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 05/30] perf env: Make lazy perf_env initialization thread-safe Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 06/30] perf env: Add host_env() singleton Ian Rogers
2026-11-13 20:47 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 07/30] perf pmu: Add from_env parameter to perf_pmu__init() Ian Rogers
2026-11-13 20:10 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 08/30] perf pmus: Introduce struct perf_pmus and perf_env__pmus() Ian Rogers
2026-11-13 20:36 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 09/30] perf pmus: Pass struct perf_pmus to find helpers Ian Rogers
2026-11-13 20:11 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 10/30] perf pmus: Pass struct perf_pmus to scan helpers Ian Rogers
2026-11-13 20:06 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 11/30] perf pmu-events: Add e_machine to struct pmu_events_map Ian Rogers
2026-11-13 20:12 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 12/30] perf pmu-events: Pass e_machine to find_core_*_table() Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 13/30] perf header: Pass e_machine to strcmp_cpuid_str() Ian Rogers
2026-11-13 20:01 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 14/30] perf header: Support CPUID matching across all architectures Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 15/30] perf test: Make the CPUID matching test architecture independent Ian Rogers
2026-11-13 20:02 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 16/30] perf test: Add CPUID matching tests for other architectures Ian Rogers
2026-11-13 20:03 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 17/30] perf dwarf-regs: Add e_machine__same_arch() Ian Rogers
2026-11-13 20:00 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 18/30] perf metricgroup: Pass struct perf_pmus to metricgroup__for_each_metric() Ian Rogers
2026-11-13 20:37 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 19/30] perf metricgroup: Move matching of metrics to recorded events from perf script Ian Rogers
2026-11-13 20:59 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 20/30] perf parse-events: Decode metric-id terms when adding events Ian Rogers
2026-11-13 20:33 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 21/30] perf evsel: Generalize metric_id to a set of metric_ids Ian Rogers
2026-11-13 20:31 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 22/30] perf pmu: Add perf_pmu__for_each_name_from_config() Ian Rogers
2026-11-13 20:13 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 23/30] perf metricgroup: Share metric events by their counter encoding Ian Rogers
2026-11-13 20:59 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 24/30] perf stat: Share events between metrics and command line events Ian Rogers
2026-11-13 20:14 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 25/30] perf pmus: Add perf_pmus__read_from_env() Ian Rogers
2026-11-13 21:05 ` sashiko-bot [this message]
2026-11-13 19:53 ` [PATCH v2 26/30] perf metricgroup: Improve matching of metrics to recorded events Ian Rogers
2026-11-13 20:37 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 27/30] perf metricgroup: Add metricgroup__add_recorded_metrics() Ian Rogers
2026-11-13 20:42 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 28/30] perf stat report: Display metrics for recorded events Ian Rogers
2026-11-13 20:44 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 29/30] perf script: Display metrics for perf stat record data Ian Rogers
2026-11-13 20:47 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 30/30] perf test: Add stat record metrics test Ian Rogers
2026-11-13 20:14 ` 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=sashiko-outbox-213689@kernel.org \
--to=sashiko-bot@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 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.