[PATCH v2 1/2] arm64: Add support for FEAT_HAFT

Will Deacon will at kernel.org
Tue Aug 20 09:18:22 PDT 2024


On Wed, Aug 14, 2024 at 05:23:32PM +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong at hisilicon.com>
> 
> Armv8.9/v9.4 introduces the feature Hardware managed Access Flag
> for Table descriptors (FEAT_HAFT). The feature is indicated by
> ID_AA64MMFR1_EL1.HAFDBS == 0b0011 and can be enabled by
> TCR2_EL1.HAFT so it has a dependency on FEAT_TCR2.
> 
> This patch adds the Kconfig for FEAT_HAFT and support detecting
> and enabling the feature.
> 
> Signed-off-by: Yicong Yang <yangyicong at hisilicon.com>
> ---
>  arch/arm64/Kconfig             | 19 +++++++++++++++++++
>  arch/arm64/kernel/cpufeature.c | 26 ++++++++++++++++++++++++++
>  arch/arm64/tools/cpucaps       |  1 +
>  arch/arm64/tools/sysreg        |  1 +
>  4 files changed, 47 insertions(+)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index a2f8ff354ca6..869792458a23 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -2137,6 +2137,25 @@ config ARM64_EPAN
>  	  if the cpu does not implement the feature.
>  endmenu # "ARMv8.7 architectural features"
>  
> +menu "ARMv8.9 architectural features"
> +
> +config ARM64_HAFT
> +	bool "Support for Hardware managed Access Flag for Table Descriptor"
> +	depends on ARM64_HW_AFDBM
> +	default y
> +	help
> +	  The ARMv8.9/ARMv9.5 introduces the feature Hardware managed Access
> +	  Flag for Table descriptors. When enabled an architectural executed
> +	  memory access will update the Access Flag in each Table descriptor
> +	  which is accessed during the translation table walk and for which
> +	  the Access Flag is 0. The Access Flag of the Table descriptor use
> +	  the same bit of PTE_AF.
> +
> +	  The feature will only be enabled if all the CPUs in the system
> +	  support this feature. If unsure, say Y.
> +
> +endmenu # "ARMv8.9 architectural features"
> +
>  config ARM64_SVE
>  	bool "ARM Scalable Vector Extension support"
>  	default y
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 646ecd3069fd..ed4c968be935 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -2044,6 +2044,17 @@ static bool has_hw_dbm(const struct arm64_cpu_capabilities *cap,
>  
>  #endif
>  
> +#if CONFIG_ARM64_HAFT
> +
> +static void cpu_enable_haft(struct arm64_cpu_capabilities const *cap)
> +{
> +	sysreg_clear_set_s(SYS_TCR2_EL1, 0, TCR2_EL1x_HAFT);
> +	isb();
> +	local_flush_tlb_all();
> +}

As this isn't a per-TTBR enable, should we be initialising the kernel
table entries in TTBR1 as YOUNG to avoid potential races with the
hardware update? It looks like the bit is ignored on CPUs without HAFT,
so we can just do this unconditionally.

At the very least, we should be able to enable HAFT in __cpu_setup(),
like we do for HA.

> +#endif
> +
>  #ifdef CONFIG_ARM64_AMU_EXTN
>  
>  /*
> @@ -2580,6 +2591,21 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
>  		.cpus = &dbm_cpus,
>  		ARM64_CPUID_FIELDS(ID_AA64MMFR1_EL1, HAFDBS, DBM)
>  	},
> +#endif
> +#ifdef CONFIG_ARM64_HAFT
> +	{
> +		.desc = "Hardware managed Access Flag for Table Descriptor",
> +		/*
> +		 * Contrary to the page/block access flag, the table access flag
> +		 * cannot be emulated in software (no access fault will occur).
> +		 * Therefore mandate that all CPUs have FEAT_HAFT.
> +		 */

It's a bit of a pity that we can't handle this mismatch. After all,
access flag data is imprecise (unlike the dirty bit) and so you could
envisage a mechanism for falling back to leaf-level AF at runtime rather
than refusing to online a CPU.

Of course, it's hard to tell whether this really matters until we see
what people try to glue together.

Will



More information about the linux-arm-kernel mailing list