From: sashiko-bot@kernel.org
To: "Fu Hao" <fuhao@open-hieco.net>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 4/7] perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h
Date: Mon, 15 Jun 2026 12:38:21 +0000 [thread overview]
Message-ID: <20260615123822.3B9311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <d387dd1497ac938b82ecc0c56505a64a61443c22.1781523812.git.fuhao@open-hieco.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Registered PMUs are not unregistered if `cpuhp_setup_state()` fails during module initialization, leading to a Use-After-Free.
--
commit 98d69c16b51701dce640f5ac92cee0daa35f2cfb
Author: Fu Hao <fuhao@open-hieco.net>
perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h
This patch adds L3 PMU support for the Hygon family 18h model 6h processor
by adjusting the slicemask and threadmask in the uncore driver.
> diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
> index 9293ce50574da..21f00edd3caa6 100644
> --- a/arch/x86/events/amd/uncore.c
> +++ b/arch/x86/events/amd/uncore.c
[ ... ]
> @@ -877,7 +910,8 @@ int amd_uncore_l3_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
> pmu->rdpmc_base = RDPMC_BASE_LLC;
> pmu->group = amd_uncore_ctx_gid(uncore, cpu);
>
> - if (boot_cpu_data.x86 >= 0x17) {
> + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
> + boot_cpu_data.x86 >= 0x17) {
> *l3_attr++ = &format_attr_event8.attr;
> *l3_attr++ = &format_attr_umask8.attr;
[ ... ]
> + if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON &&
> + boot_cpu_data.x86 == 0x18) {
> + *l3_attr++ = &format_attr_event8.attr;
> + *l3_attr++ = &format_attr_umask8.attr;
> + if (boot_cpu_data.x86_model >= 0x6 && boot_cpu_data.x86_model <= 0xf) {
> + *l3_attr++ = &format_attr_threadmask32.attr;
> + pmu->pmu.attr_update = hygon_uncore_l3_attr_update;
> + } else {
> + *l3_attr++ = &format_attr_threadmask8.attr;
> + }
> + }
> +
> if (perf_pmu_register(&pmu->pmu, pmu->pmu.name, -1)) {
> free_percpu(pmu->ctx);
> pmu->ctx = NULL;
[Severity: High]
This is a pre-existing issue, but registering the PMU here exposes a teardown
issue in the module initialization error path.
If cpuhp_setup_state() fails for the online state in amd_uncore_init(), the
error path jumps to fail_start and removes the hotplug states. This triggers
the amd_uncore_cpu_dead() teardown callback, which correctly frees the
per-CPU context by calling amd_uncore_ctx_free().
However, the error path does not unregister the PMU or free the uncore->pmus
array:
arch/x86/events/amd/uncore.c:amd_uncore_init() {
...
fail:
for (i = 0; i < UNCORE_TYPE_MAX; i++) {
uncore = &uncores[i];
if (uncore->info) {
free_percpu(uncore->info);
uncore->info = NULL;
}
}
return ret;
}
Since the initialization failed, the module will be unloaded, but the perf
subsystem retains references to the registered PMUs.
Could this lead to a use-after-free if the perf subsystem later accesses
these dangling PMUs (for instance, via perf stat) after the module memory
has been freed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1781523812.git.fuhao@open-hieco.net?part=4
prev parent reply other threads:[~2026-06-15 12:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1781523812.git.fuhao@open-hieco.net>
2026-06-15 12:20 ` [PATCH v3 4/7] perf/x86/uncore: Add L3 PMU support for Hygon family 18h model 6h Fu Hao
2026-06-15 12:38 ` 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=20260615123822.3B9311F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fuhao@open-hieco.net \
--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