[PATCH] KVM: arm64: Read PMUVer as unsigned

James Clark posted 1 patch 1 month ago
There is a newer version of this series
arch/arm64/kvm/debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] KVM: arm64: Read PMUVer as unsigned
Posted by James Clark 1 month ago
ID_AA64DFR0_EL1.PMUVer is an unsigned field, so this skips
initialization of host_data_ptr(nr_event_counters) for PMUv3 for Armv8.8
onwards as they appear as negative values.

Fix it by reading it as unsigned.

Fixes: 2417218f2f23 ("KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts")
Signed-off-by: James Clark <james.clark@linaro.org>
---
 arch/arm64/kvm/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
index 3ad6b7c6e4ba..b8632edba9a3 100644
--- a/arch/arm64/kvm/debug.c
+++ b/arch/arm64/kvm/debug.c
@@ -76,7 +76,7 @@ void kvm_init_host_debug_data(void)
 {
 	u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
 
-	if (cpuid_feature_extract_signed_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
+	if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
 		*host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
 							      read_sysreg(pmcr_el0));
 

---
base-commit: c107785c7e8dbabd1c18301a1c362544b5786282
change-id: 20260305-james-kvm-pmuver-sign-fe830bdead2d

Best regards,
-- 
James Clark <james.clark@linaro.org>
Re: [PATCH] KVM: arm64: Read PMUVer as unsigned
Posted by Marc Zyngier 1 month ago
On Thu, 05 Mar 2026 11:50:01 +0000,
James Clark <james.clark@linaro.org> wrote:
> 
> ID_AA64DFR0_EL1.PMUVer is an unsigned field, so this skips
> initialization of host_data_ptr(nr_event_counters) for PMUv3 for Armv8.8
> onwards as they appear as negative values.
> 
> Fix it by reading it as unsigned.
> 
> Fixes: 2417218f2f23 ("KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts")
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
>  arch/arm64/kvm/debug.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
> index 3ad6b7c6e4ba..b8632edba9a3 100644
> --- a/arch/arm64/kvm/debug.c
> +++ b/arch/arm64/kvm/debug.c
> @@ -76,7 +76,7 @@ void kvm_init_host_debug_data(void)
>  {
>  	u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
>  
> -	if (cpuid_feature_extract_signed_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
> +	if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
>  		*host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
>  							      read_sysreg(pmcr_el0));
>  

How does this work on a system that advertises a non-architected PMU?

	M.

-- 
Without deviation from the norm, progress is not possible.
Re: [PATCH] KVM: arm64: Read PMUVer as unsigned
Posted by James Clark 1 month ago

On 05/03/2026 11:59 am, Marc Zyngier wrote:
> On Thu, 05 Mar 2026 11:50:01 +0000,
> James Clark <james.clark@linaro.org> wrote:
>>
>> ID_AA64DFR0_EL1.PMUVer is an unsigned field, so this skips
>> initialization of host_data_ptr(nr_event_counters) for PMUv3 for Armv8.8
>> onwards as they appear as negative values.
>>
>> Fix it by reading it as unsigned.
>>
>> Fixes: 2417218f2f23 ("KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts")
>> Signed-off-by: James Clark <james.clark@linaro.org>
>> ---
>>   arch/arm64/kvm/debug.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
>> index 3ad6b7c6e4ba..b8632edba9a3 100644
>> --- a/arch/arm64/kvm/debug.c
>> +++ b/arch/arm64/kvm/debug.c
>> @@ -76,7 +76,7 @@ void kvm_init_host_debug_data(void)
>>   {
>>   	u64 dfr0 = read_sysreg(id_aa64dfr0_el1);
>>   
>> -	if (cpuid_feature_extract_signed_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
>> +	if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_PMUVer_SHIFT) > 0)
>>   		*host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
>>   							      read_sysreg(pmcr_el0));
>>   
> 
> How does this work on a system that advertises a non-architected PMU?
> 
> 	M.
> 

Hmmm yeah I suppose it doesn't, there's actually already 
pmuv3_implemented() and has_pmuv3() which open code the same check 
again. Maybe I can try re-using something and tidying it up.