In a follow-up patch, a new system feature will need to check for the presence of HW AF on each CPU individually. Signed-off-by: James Houghton --- arch/arm64/include/asm/cpufeature.h | 26 ++++++++++++++++++++------ arch/arm64/include/asm/pgtable.h | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index a57870fa96db..e818ad1b56e2 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -910,22 +910,36 @@ static inline u32 id_aa64mmfr0_parange_to_phys_shift(int parange) } /* Check whether hardware update of the Access flag is supported */ -static inline bool cpu_has_hw_af(void) +static inline bool supports_hw_af(int scope) { u64 mmfr1; if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM)) return false; - /* - * Use cached version to avoid emulated msr operation on KVM - * guests. - */ - mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); + if (scope == SCOPE_SYSTEM) { + /* + * Use cached version to avoid emulated msr operation on KVM + * guests. + */ + mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); + } else { + mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); + } return cpuid_feature_extract_unsigned_field(mmfr1, ID_AA64MMFR1_EL1_HAFDBS_SHIFT); } +static inline bool system_has_hw_af(void) +{ + return supports_hw_af(SCOPE_SYSTEM); +} + +static inline bool cpu_has_hw_af(void) +{ + return supports_hw_af(SCOPE_LOCAL_CPU); +} + static inline bool cpu_has_pan(void) { u64 mmfr1 = read_cpuid(ID_AA64MMFR1_EL1); diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 27689c62bd25..5f21d3a738ee 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1598,7 +1598,7 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf, * page after fork() + CoW for pfn mappings. We don't always have a * hardware-managed access flag on arm64. */ -#define arch_has_hw_pte_young cpu_has_hw_af +#define arch_has_hw_pte_young system_has_hw_af #ifdef CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG #define arch_has_hw_nonleaf_pmd_young system_supports_haft @@ -1608,7 +1608,7 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf, * Experimentally, it's cheap to set the access flag in hardware and we * benefit from prefaulting mappings as 'old' to start with. */ -#define arch_wants_old_prefaulted_pte cpu_has_hw_af +#define arch_wants_old_prefaulted_pte system_has_hw_af /* * Request exec memory is read into pagecache in at least 64K folios. This size -- 2.55.0.795.g602f6c329a-goog