Re: [PATCH v4 1/2] arm64: errata: Factor out broken AMU const counter cap

From: Vladimir Murzin

Date: Thu Oct 01 2026 - 08:29:17 EST


On 10/1/26 10:00, Beata Michalska wrote:
> Move the workaround from the erratum 2457168-specific cpucap to a generic
> broken AMU constant-counter one. This keeps the existing Cortex-A510
> handling unchanged while allowing other errata with similar AMU constant
> counter issue to share the capability bit and call sites.
>
> Signed-off-by: Beata Michalska <beata.michalska@xxxxxxx>
> ---
> arch/arm64/Kconfig | 8 ++++++++
> arch/arm64/kernel/cpu_errata.c | 20 ++++++++++++++------
> arch/arm64/kernel/cpufeature.c | 2 +-
> arch/arm64/kernel/topology.c | 7 ++++---
> arch/arm64/tools/cpucaps | 2 +-
> 5 files changed, 28 insertions(+), 11 deletions(-)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index b5a51b0ef9440..3b6c052d46a18 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -1040,9 +1040,17 @@ config ARM64_ERRATUM_1902691
>
> If unsure, say Y.
>
> +config ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
> + bool
> + # Targeting errata affecting AMEVCNTR01, the AMU constant counter.
> + # On affected CPUs the counter may not increment at the expected rate,
> + # making it unreliable. As a result, AMU users should treat it as
> + # unavailable rather than relying on misleading counter values.
> +
> config ARM64_ERRATUM_2457168
> bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly"
> depends on ARM64_AMU_EXTN
> + select ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
> default y
> help
> This option adds the workaround for ARM Cortex-A510 erratum 2457168.
> diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
> index 5db8f0619e4bc..8ce559ac073c7 100644
> --- a/arch/arm64/kernel/cpu_errata.c
> +++ b/arch/arm64/kernel/cpu_errata.c
> @@ -381,6 +381,16 @@ static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = {
> };
> #endif
>
> +#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
> +static const struct midr_range workaround_amu_constcnt_list[] = {
> +#ifdef CONFIG_ARM64_ERRATUM_2457168
> + /* Cortex-A510 r0p0-r1p1 */
> + MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1),
> +#endif
> + {}
> +};
> +#endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT */
> +
> #ifdef CONFIG_CAVIUM_ERRATUM_23154
> static const struct midr_range cavium_erratum_23154_cpus[] = {
> MIDR_ALL_VERSIONS(MIDR_THUNDERX),
> @@ -916,14 +926,12 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
> ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A510, 0, 0, 2)
> },
> #endif
> -#ifdef CONFIG_ARM64_ERRATUM_2457168
> +#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
> {
> - .desc = "ARM erratum 2457168",
> - .capability = ARM64_WORKAROUND_2457168,
> + .desc = "Broken AMU AMEVCNTR01 (const counter)",
> + .capability = ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT,
> .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
> -
> - /* Cortex-A510 r0p0-r1p1 */
> - CAP_MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1)
> + CAP_MIDR_RANGE_LIST(workaround_amu_constcnt_list)
> },
> #endif
> #ifdef CONFIG_ARM64_ERRATUM_2038923
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 17b83a2518a8f..1569f84214763 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -2064,7 +2064,7 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap)
> cpumask_set_cpu(smp_processor_id(), &amu_cpus);
>
> /* 0 reference values signal broken/disabled counters */
> - if (!this_cpu_has_cap(ARM64_WORKAROUND_2457168))
> + if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT))
> update_freq_counters_refs();
> }
> }
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index d28438f8b83f1..64588554e7f76 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -402,7 +402,7 @@ static void cpu_read_constcnt(void *val)
> * the counter is disabled. A return value of 0 at counter read is
> * properly handled as an error case by the users of the counter.
> */
> - *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_2457168) ?
> + *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT) ?
> 0UL : read_constcnt();
> }
>
> @@ -463,8 +463,9 @@ static void amu_read_core_const_ctrs(void *val)
>
> /*
> * cpu_read_constcnt() incurs slight latency due to the
> - * ARM64_WORKAROUND_2457168 check. Read it first to minimize
> - * the sampling skew between the const and core counters.
> + * ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT check.
> + * Read it first to minimize the sampling skew between the const
> + * and core counters.
> */
> cpu_read_constcnt(&ctrs->constcnt);
> cpu_read_corecnt(&ctrs->corecnt);
> diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
> index 2775ba3359cfe..58b6c084f9f25 100644
> --- a/arch/arm64/tools/cpucaps
> +++ b/arch/arm64/tools/cpucaps
> @@ -105,7 +105,6 @@ WORKAROUND_1902691
> WORKAROUND_2038923
> WORKAROUND_2064142
> WORKAROUND_2077057
> -WORKAROUND_2457168
> WORKAROUND_2645198
> WORKAROUND_2658417
> WORKAROUND_4193714
> @@ -132,3 +131,4 @@ WORKAROUND_REPEAT_TLBI_SYNC
> WORKAROUND_SPECULATIVE_AT
> WORKAROUND_SPECULATIVE_SSBS
> WORKAROUND_SPECULATIVE_UNPRIV_LOAD
> +WORKAROUND_BROKEN_AMU_CONSTCNT
> -- 2.43.0
>

Reviewed-by: Vladimir Murzin <vladimir.murzin@xxxxxxx>

Thanks
Vladimir