From: sashiko-bot@kernel.org
To: "Qi Liu" <liuqi@hygon.cn>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/3] perf/x86/amd/uncore: Convert AMD driver to common PMU helpers
Date: Wed, 01 Jul 2026 04:00:39 +0000 [thread overview]
Message-ID: <20260701040039.A047D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260701034413.718872-3-liuqi@hygon.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Context migration logic incorrectly alters the designated PMU CPU when a non-designated sibling CPU goes offline, permanently breaking PMU hrtimers and event polling.
- [High] Module initialization failure during CPU hotplug setup leaks previously registered PMUs and their allocated structures, leading to a dangling pointer in the kernel's PMU list.
--
commit 9535e3c8779a5fdb3921bce37f7ad4c941fd34c9
Author: Qi Liu <liuqi@hygon.cn>
perf/x86/amd/uncore: Convert AMD driver to common PMU helpers
Use the common uncore PMU helpers for AMD uncore event handling and
per-CPU context management.
> diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
> index dbc00b6dd69ee..9cb8b0d1afe7a 100644
> --- a/arch/x86/events/amd/uncore.c
> +++ b/arch/x86/events/amd/uncore.c
[ ... ]
> @@ -1087,41 +654,40 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
[ ... ]
> -static struct amd_uncore uncores[UNCORE_TYPE_MAX] = {
> +static struct uncore_common uncores[UNCORE_TYPE_MAX] = {
> /* UNCORE_TYPE_DF */
> {
> .scan = amd_uncore_df_ctx_scan,
> .init = amd_uncore_df_ctx_init,
> - .move = amd_uncore_ctx_move,
> - .free = amd_uncore_ctx_free,
> + .move = uncore_common_ctx_move,
> + .free = uncore_common_ctx_free,
> },
[Severity: High]
This isn't a bug introduced by this patch, but while moving the context
migration logic to uncore_common_ctx_move(), I noticed a potential issue
when a sibling CPU is taken offline.
In the migration loop, if the offline CPU is not the currently designated CPU,
will the loop pick the first online sibling CPU and forcibly update next->cpu
to it without checking if the offline CPU was the active one?
If this happens, the hrtimer would never start on the newly designated CPU
because no events were actually migrated. When the existing hrtimer fires
on the originally designated CPU, it evaluates this check in
uncore_common_hrtimer():
if (!ctx->nr_active || ctx->cpu != smp_processor_id())
return HRTIMER_NORESTART;
Would this mismatched CPU cause the pinned hrtimer to permanently return
HRTIMER_NORESTART, stopping the PMU event polling?
[ ... ]
> @@ -1138,7 +706,7 @@ static int __init amd_uncore_init(void)
> BUG_ON(!uncore->move);
> BUG_ON(!uncore->free);
>
> - uncore->info = alloc_percpu(union amd_uncore_info);
> + uncore->info = alloc_percpu(union uncore_common_info);
> if (!uncore->info) {
> ret = -ENOMEM;
> goto fail;
> }
[Severity: High]
This is a pre-existing issue, but I noticed a potential leak in the module
initialization error path, such as at this goto fail or if cpuhp_setup_state()
fails later in amd_uncore_init().
If setup fails for CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE, it jumps to the error
handling labels (e.g., fail_start). However, the error path doesn't seem to
unregister successfully registered PMUs or free uncore->pmus.
Unlike amd_uncore_exit() which correctly cleans up the PMUs:
perf_pmu_unregister(&pmu->pmu);
free_percpu(pmu->ctx);
...
kfree(uncore->pmus);
Will failing during initialization leave dangling pointers in the global pmus
list and leak the allocated context memory, potentially causing a crash
during subsequent PMU accesses?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260701034413.718872-1-liuqi@hygon.cn?part=2
next prev parent reply other threads:[~2026-07-01 4:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 3:44 [PATCH 0/3] perf/x86/amd/uncore: Add common helpers and Hygon support Qi Liu
2026-07-01 3:44 ` [PATCH 1/3] perf/x86/amd/uncore: Add common PMU helper functions Qi Liu
2026-07-01 4:04 ` sashiko-bot
2026-07-01 7:00 ` Peter Zijlstra
2026-07-01 7:50 ` 答复: " Qi Liu
2026-07-01 7:51 ` Peter Zijlstra
2026-07-01 7:55 ` 答复: " Qi Liu
2026-07-01 3:44 ` [PATCH 2/3] perf/x86/amd/uncore: Convert AMD driver to common PMU helpers Qi Liu
2026-07-01 4:00 ` sashiko-bot [this message]
2026-07-01 3:44 ` [PATCH 3/3] perf/x86/amd/uncore: Add Hygon uncore PMU support Qi Liu
2026-07-01 3:56 ` 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=20260701040039.A047D1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=liuqi@hygon.cn \
--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