Linux Perf Users
 help / color / mirror / Atom feed
From: Sandipan Das <sandipan.das@amd.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf/x86/amd/uncore: Extend num_umc_pmc to fix UMC discovery
Date: Wed, 7 Oct 2026 21:33:51 +0530	[thread overview]
Message-ID: <38529f6b-448d-443b-bbc2-182a379cf590@amd.com> (raw)
In-Reply-To: <sashiko-outbox-163154@kernel.org>

On 07-10-2026 21:10, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] perf/x86/amd: OOB write on active_mask via unvalidated CPUID
> --
> 
> commit 00612d17a5d2f57d4e77167b7e9d6303f0e776ac
> Author: Sandipan Das <sandipan.das@amd.com>
> 
> perf/x86/amd/uncore: Extend num_umc_pmc to fix UMC discovery
> 
> The commit extends the width of the num_umc_pmc bitfield from six bits
> to eight bits to match Zen 5 documentation. This allows discovery of
> Unified Memory Controller (UMC) counters up to 64 in fully-populated
> Zen 6 configurations.
> 
>> diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
>> index 1eb13673e889f..d419b26086b22 100644
>> --- a/arch/x86/include/asm/perf_event.h
>> +++ b/arch/x86/include/asm/perf_event.h
>> @@ -293,7 +293,7 @@ union cpuid_0x80000022_ebx {
>>  		/* Number of Data Fabric Counters */
>>  		unsigned int	num_df_pmc:6;
>>  		/* Number of Unified Memory Controller Counters */
>> -		unsigned int	num_umc_pmc:6;
>> +		unsigned int	num_umc_pmc:8;
> 
> [Severity: High]
> Does this expansion allow values up to 255 from CPUID to propagate unchecked?
> 
> When the field was 6 bits, the natural boundary limited it to 63, which fit
> safely inside NUM_COUNTERS_MAX (64). With an 8-bit width, a hypervisor could
> supply a value greater than 64 in EBX.NumPerfCtrUmc.
> 

Uncore counters are generally not visible to guests.

> This value gets propagated down during initialization without validation:
> 
> arch/x86/events/amd/uncore.c:amd_uncore_umc_ctx_init() {
>     ...
>     pmu->num_counters = group_num_pmcs[gid] / group_num_pmus[gid];
>     ...
> }
> 
> If pmu->num_counters exceeds NUM_COUNTERS_MAX, can it cause an
> out-of-bounds write when starting the event?
> 

Not for real hardware since each UMC PMU has at most 4 PMCs.

> arch/x86/events/amd/uncore.c:amd_uncore_umc_start() {
>     ...
>     __set_bit(hwc->idx, ctx->active_mask);
>     ...
> }
> 
> Since ctx->active_mask is sized by BITS_TO_LONGS(NUM_COUNTERS_MAX), writing
> a bit greater than 63 might overflow into the adjacent nr_active and
> hrtimer fields in struct amd_uncore_ctx.
> 
> Should we cap pmu->num_counters against NUM_COUNTERS_MAX during
> initialization to prevent this regression?
> 
>>  	} split;
>>  	unsigned int		full;
>>  };
> 


      reply	other threads:[~2026-10-07 16:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 15:27 [PATCH] perf/x86/amd/uncore: Extend num_umc_pmc to fix UMC discovery Sandipan Das
2026-10-07 15:40 ` sashiko-bot
2026-10-07 16:03   ` Sandipan Das [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=38529f6b-448d-443b-bbc2-182a379cf590@amd.com \
    --to=sandipan.das@amd.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