Re: [PATCH v2 12/16] KVM: x86/pmu: Populate CPUID.0AH:ECX fixed-counter bitmap
From: Chen, Zide
Date: Wed Oct 28 2026 - 17:58:33 EST
On 10/28/2026 4:29 PM, Jim Mattson wrote:
> On Thu, Aug 27, 2026 at 3:48 PM Zide Chen <zide.chen@xxxxxxxxx> wrote:
>>
>> PerfMon v5 adds a fixed-counter support bitmap in CPUID.0AH:ECX.
>> This is the superset of EDX[4:0] which indicates the contiguous
>> counters starting from 0. For backward compatibility, it's recommended
>> to use the following to determine if a fixed counter is supported:
>>
>> FxCtr[i]_is_supported := ECX[i] || (EDX[4:0] > i);
>>
>> Originally-by: Yang Weijiang <weijiang.yang@xxxxxxxxx>
>> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
>> ---
>> arch/x86/kvm/cpuid.c | 5 ++++-
>> arch/x86/kvm/vmx/pmu_intel.c | 3 +++
>> 2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> index 106e719e7aee..63201d4ea4a1 100644
>> --- a/arch/x86/kvm/cpuid.c
>> +++ b/arch/x86/kvm/cpuid.c
>> @@ -1547,7 +1547,10 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
>>
>> entry->eax = eax.full;
>> entry->ebx = kvm_pmu_cap.events_mask;
>> - entry->ecx = 0;
>> + if (kvm_pmu_cap.version >= 5)
>> + entry->ecx &= (u32)kvm_pmu_cap.fixed_cntr_mask64;
>
> Is the '&' necessary?
You are right. kvm_pmu_cap.fixed_cntr_mask64 already reflects KVM's
supported fixed counters, so we can directly assign entry->ecx without
the & (matching how eax, ebx, and edx are populated). I will drop it in v3.