From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796348191; b=HAPx5YLNPNy3MfkO72c14qXmKcEwVYOJG4rMyRXutfDzH6r93YGPpiJ43zGJpwzmGuN/ 9IgdTF/xaAeGEJrTi6hTVFa83eT11k2JVz/c/swp0CoqqTQK8IHSgG2eujbEEIR8KL/0I vDYLq6Ebb6r3V58FgC+GIyNdeEMaNJwe28Y071iC4odk0AQA5xvrsGGxgbLS/dB5e52gh O41GhB/TWhR+eBchRu5PyLpyHs2ogGey/sTXvBk89Gmd4aWaljA7+GxOatMTyzGfiOJVJ L1LWwwgZJ5NUDO0j5hhRBaUHyyLWWYNTWjDMv1vcaJRKhVcfUFFHFQ/8xdk+etH74vQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796348191; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=YwTRvi+OE1OPdqolr8r/uJDBk/ezIKKKGUTLTO7OFCg=; b=jhpYROGU3XM6by+JbrQZep9FtdrEX7wxWF37UprQoibbrhI/EyhJYtE5gz8ef8RL9EAb cHNINz+qj0FWMMnqSSnMfCRSmqiYbbKNnL2FktUt40b9NYOmUOXQCJUwBLSe3hVvhEEGI bt5Ho/M1Z8nQUpHxs/O4kTo0+00r1iqwIwEVfFw3ew8k2QHlUvX9ozuwKhI3672aukC2e 8Qnh71kmG2SRb9ppZJoe1KpFNhnyJsNxH6PKHJFqZlNzeEEtRrSXena+1AU0arw5ZGvLh JStncGQgBc7WVI8Ge9PklWGOjMt1PcFtBtuRAfKU1Du33UEluZPBR/WX56tYW1xh9UQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Wwnrz1jB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B518606A322 for ; Fri, 4 Dec 2026 01:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Wwnrz1jB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C9331F000C2; Fri, 4 Dec 2026 01:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796348191; bh=YwTRvi+OE1OPdqolr8r/uJDBk/ezIKKKGUTLTO7OFCg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Wwnrz1jBEhs2wpP7KWfX16AQKhZTcLIzx6zx6rOmjed4CMnP6IRLJRWSo5btQLxXa HvQNdw+cfqVmGSF7s3ozVgAIyDZO9rZbIuBkbhOIlF45cu4z3K7LqtJOxFyy1lgfcY pAbRoEXCAq89omxfKzJhaXOG3ROueCAEwyykCHKJZRnNHzDC6IBmQTbKVaBEJoZFHq hsHxqKCq6OZN2m4L/Mu8kjLqSIGbUJyOP17B8as7ge4N4mU4oJVOa9uiyJr7tW4FvH +KlVf6Clc17O8QZ6l31+uBJoY4PQpj047Yb9SV4bYYyvVBABsxeUiuHSxAhCtd2h0v JZNbwpi/mwZqw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 08/11] perf list, jevents: Add --export-dir and --output-dir sysfs-style exporters Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261204011029.1946921-9-irogers@google.com> References: <20261204011029.1946921-1-irogers@google.com> <20261204011029.1946921-9-irogers@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:36:30 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [Medium] perf jevents: broken RISC-V SiFive mimpid expansion in _expand_cpuid_pattern() - [Medium] perf jevents: regex Compat skipped in _is_literal_compat(), breaking ARM CMN - [Low] perf jevents: default starting_dir in main() omits build-generated JSON files - [Low] perf list: missing explicit assert.h include for new assert() calls - [Low] perf list: unchecked strlist__new() and strdup() in cmd_list() --export-dir - [Low] perf pmu-layer: errno clobber and zero-write loop in export_write_str_at() - [Low] perf pmu-layer: export_constraint_str() drops GROUP_EVENTS overrides - [Low] perf list: O((E+M)*P) PMU rescans and missing DRM/HWMON early exit - [Low] perf jevents: truthiness check in _export_event_files() drops 0 latencies -- commit b8344fa746e0c1d020b1e268db8e70477584fd3d Author: Ian Rogers perf list, jevents: Add --export-dir and --output-dir sysfs-style exporters This commit adds two sysfs-style directory exporters for pmu-events.dir layering: perf list --export-dir to materialize active host PMU events, metrics, and metricgroups on disk, and jevents.py --output-dir to export architecture JSON trees with CPUID and sysfs compat symlinks. > diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c > index 53e1834233c87..85de0bd73e324 100644 > --- a/tools/perf/builtin-list.c > +++ b/tools/perf/builtin-list.c > @@ -25,9 +26,11 @@ > #include > #include > #include > +#include > #include > #include > #include > +#include [Severity: Low] Should be included explicitly here for the new assert() calls in cmd_list()? Relying on transitive inclusion can break builds across glibc and musl if an indirect header stops pulling it in. [ ... ] > + export_ps.visited_groups =3D strlist__new(NULL, NULL); > + assert(export_ps.visited_groups); > + ps->visited_metrics =3D strlist__new(NULL, NULL); > + assert(ps->visited_metrics); > + if (unit_name) > + ps->pmu_glob =3D strdup(unit_name); > + else if (cputype) { > + const struct perf_pmu *pmu =3D perf_pmus__pmu_for_pmu_filter(cputype); > + > + if (!pmu) { > + pr_err("ERROR: cputype is not supported!\n"); > + ret =3D -1; > + goto out; > + } > + ps->pmu_glob =3D strdup(pmu->name); > + } [Severity: Low] What happens if strlist__new() or strdup() fails here? Under -DNDEBUG, the assert() calls compile out and a NULL strlist reaches export_dir_print_metric(), causing a NULL pointer dereference in strlist__has_entry() or strlist__add(). Similarly, an unchecked strdup() leaves ps->pmu_glob NULL on allocation failure, which silently disables the --unit or --cputype filter and exports all PMUs instead of returning an error. > diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jev= ents.py > index fdd984c420874..ed9b2f90535a1 100755 > --- a/tools/perf/pmu-events/jevents.py > +++ b/tools/perf/pmu-events/jevents.py [ ... ] > + if event.retirement_latency_mean: > + _write_text_file(base + '.retire-lat-mean', str(event.retirement_lat= ency_mean)) > + if event.retirement_latency_min: > + _write_text_file(base + '.retire-lat-min', str(event.retirement_late= ncy_min)) > + if event.retirement_latency_max: > + _write_text_file(base + '.retire-lat-max', str(event.retirement_late= ncy_max)) [Severity: Low] Can these truthiness checks drop valid zero retirement latency values? JsonEvent.__init__() stores numeric JSON values directly, so a value of 0 (such as RetirementLatencyMin on 24 Intel Granite Rapids events) evaluates as false and omits the .retire-lat-* file. Unlike pmu_layer__export_event(), which writes the sidecar whenever has_retire_lat_min is set, omitting the file leaves the attribute missing on disk and lets a non-zero value from a lower pmu-events.dir layer leak through. Checking "is not None" would preserve explicit zeros. [ ... ] > +def _expand_cpuid_pattern(arch: str, pattern: str) -> Sequence[str]: > + """Expand a mapfile.csv CPUID pattern into literal directory names.""" > + if arch =3D=3D 's390': > + m =3D re.match(r'^\^IBM\.([^.*]+)\.\*.*$', pattern) > + if m: > + return ['IBM,' + x for x in _expand_regex_fragment(m.group(1))] > + return [] > + > + if arch =3D=3D 'powerpc': > + return _expand_regex_fragment(pattern.replace('[[:xdigit:]]{4}', '00= 00')) > + > + xdigit_cls =3D '[0-9A-F]' if arch =3D=3D 'x86' else '[0-9a-f]' > + pat =3D pattern > + if pat.endswith('-[[:xdigit:]]+'): > + pat =3D pat[:-len('-[[:xdigit:]]+')] > + elif pat.endswith('-0x[[:xdigit:]]+'): > + pat =3D pat[:-len('-0x[[:xdigit:]]+')] > + elif pat.endswith('[[:xdigit:]]+'): > + pat =3D pat[:-len('[[:xdigit:]]+')] + f'({xdigit_cls}|)' > + pat =3D pat.replace('[[:xdigit:]]', xdigit_cls) > + return [c for c in _expand_regex_fragment(pat) if '/' not in c] [Severity: Medium] Does replacing a trailing [[:xdigit:]]+ with ({xdigit_cls}|) break RISC-V SiFive CPUID resolution? In tools/perf/pmu-events/arch/riscv/mapfile.csv, entries like sifive/bullet-07 use patterns with a fixed leading nibble followed by [[:xdigit:]]+ (such as 0x489-0x8000000000000[1-9a-e]07-0x[78ac][[:xdigit:]]+). Because [[:xdigit:]]+ requires one or more hex digits, replacing it with zero or one digit emits invalid 1-hex-digit mimpid symlinks (such as -0x7) and only covers 1- and 2-digit mimpids. Real SiFive cores report multi-nibble 32-bit mimpid values, and build_cpuid_candidates() in pmu-layer.c only probes the full mvendorid-marchid-mimpid string and the mvendorid-marchid prefix, so none of those symlinks will match at runtime. > +def _is_literal_compat(compat: str) -> bool: > + """Return True if compat is a plain PMU identifier without regex opera= tors.""" > + return bool(compat) and '/' not in compat and not any( > + ch in compat for ch in '*+?[]()|^$\\' > + ) [Severity: Medium] Will skipping regex Compat strings make exported ARM CMN definitions unreachable at runtime? In tools/perf/pmu-events/arch/arm64/arm/cmn/sys/cmn.json, Compat is "(434|436|43c|43a).*", which _is_literal_compat() rejects, so no sys/ symlink is created for the exported arm_cmn files. Since dir_for_each_scope() in pmu-layer.c only does a literal openat() under sys/ for pmu->id, those exported ARM CMN events and metrics can never be loaded. This also contradicts the commit message example showing sys/43401 -> ../models/arm64/arm/cmn (and for literal sys Compat entries, target_root includes the trailing /sys component). [ ... ] > + default_arch_dir =3D os.path.join( > + os.path.dirname(os.path.abspath(__file__)), 'arch' > + ) [Severity: Low] Does defaulting starting_dir to the clean source arch/ directory silently omit build-generated JSON definitions? tools/perf/pmu-events/Build generates legacy-cache.json and the Intel, AMD Zen, and ARM64 extra-metrics.json and extra-metricgroups.json files under $(OUTPUT)pmu-events/arch/ rather than the source tree. Running the documented command "jevents.py --output-dir /opt/pmu-events x86 all" without a pre-built starting_dir therefore produces an overlay tree missing all Python-generated metrics, metricgroup descriptions, and legacy cache events. > diff --git a/tools/perf/util/pmu-layer.c b/tools/perf/util/pmu-layer.c > index 7ab72c8adf9cc..5e28002b0bb49 100644 > --- a/tools/perf/util/pmu-layer.c > +++ b/tools/perf/util/pmu-layer.c [ ... ] > + while (off < len) { > + ssize_t n =3D write(fd, content + off, len - off); > + > + if (n < 0) { > + if (errno =3D=3D EINTR) > + continue; > + close(fd); > + return -errno; > + } > + off +=3D (size_t)n; > + } > + for (;;) { > + ssize_t n =3D write(fd, "\n", 1); > + > + if (n < 0 && errno =3D=3D EINTR) > + continue; > + if (n !=3D 1) { > + int err =3D errno ? -errno : -EIO; > + > + close(fd); > + return err; > + } > + break; > + } [Severity: Low] Can close(fd) clobber errno before returning -errno on a failed write()? Saving errno into a local variable before close(fd), as done in the loop below, would preserve the original write() error. Also, the first loop spins indefinitely if write() returns 0 while off < len, and the trailing newline loop consults errno even when n =3D=3D = 0, which can return a stale errno (such as EEXIST from pmu_layer__mkdir_p()) instead of -EIO. [ ... ] > +static struct perf_pmu_alias *export_find_pmu_and_alias(const char *pmu_= name, > + const char *event_name, > + struct perf_pmu **out_pmu) > +{ > + struct perf_pmu *pmu =3D perf_pmus__find(pmu_name); > + struct perf_pmu *fallback_pmu =3D NULL; > + struct perf_pmu_alias *fallback_alias =3D NULL; > + struct perf_pmu_alias *alias; > + > + if (pmu) { > + enum pmu_kind kind =3D perf_pmu__kind(pmu); > + > + if (kind !=3D PERF_PMU_KIND_DRM && kind !=3D PERF_PMU_KIND_HWMON) { [ ... ] > + } > + pmu =3D NULL; > + } > + > + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { [Severity: Low] Can this cause O((E + M) * P) PMU rescans during perf list --export-dir on servers with many uncore, hwmon, and DRM PMUs? For JSON uncore events where pmu_name is the generic unit name (e.g., uncore_cha), perf_pmus__find() misses and falls through to a full perf_pmus__scan() on every event; likewise, when perf_pmus__find() hits a DRM or HWMON PMU, it falls through to perf_pmus__scan() instead of returning NULL. export_find_pmu_metric() and export_pmu_glob_matches_metric() similarly scan all PMUs per metric, and pmu_layer__export_event() and pmu_layer__export_metric() repeat pmu_layer__mkdir_p() and open()/close() on the same target directory for every individual event and metric. [ ... ] > +static const char *export_constraint_str(enum metric_event_groups groupi= ng) > +{ > + switch (grouping) { > + case MetricNoGroupEvents: > + return "NO_GROUP_EVENTS"; > + case MetricNoGroupEventsNmi: > + return "NO_GROUP_EVENTS_NMI"; > + case MetricNoGroupEventsSmt: > + return "NO_GROUP_EVENTS_SMT"; > + case MetricNoGroupEventsThresholdAndNmi: > + return "NO_THRESHOLD_AND_NMI"; > + case MetricGroupEvents: > + default: > + return NULL; > + } > +} [Severity: Low] Does returning NULL for MetricGroupEvents drop explicit GROUP_EVENTS overrides on export? parse_constraint_str() accepts GROUP_EVENTS (or 0) to set has_event_grouping =3D true with MetricGroupEvents, and pmu_layer__export_metric() only calls export_constraint_str() when has_event_grouping is true. Omitting the .constraint sidecar here means a lower layer's NO_GROUP_EVENTS* constraint will take effect again when the exported directory is re-layered. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204011029.1946= 921-1-irogers@google.com?part=3D8