diff mbox series

[2/2] arm64: mm: Implement arch_wants_old_faultaround_pte()

Message ID 20201209163950.8494-3-will@kernel.org (mailing list archive)
State New, archived
Headers show
Series Create 'old' ptes for faultaround mappings on arm64 with hardware access flag | expand

Commit Message

Will Deacon Dec. 9, 2020, 4:39 p.m. UTC
On CPUs with hardware AF/DBM, initialising prefaulted PTEs as 'old'
improves vmscan behaviour and does not appear to introduce any overhead.

Implement arch_wants_old_faultaround_pte() to return 'true' if we detect
hardware access flag support at runtime. This can be extended in future
based on MIDR matching if necessary.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/cpufeature.h | 12 ++++++++++++
 arch/arm64/include/asm/pgtable.h    |  8 +++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

Catalin Marinas Dec. 9, 2020, 6:35 p.m. UTC | #1
On Wed, Dec 09, 2020 at 04:39:50PM +0000, Will Deacon wrote:
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index da250e4741bd..3424f5881390 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -764,6 +764,18 @@ static inline bool cpu_has_hw_af(void)
>  						ID_AA64MMFR1_HADBS_SHIFT);
>  }
>  
> +static inline bool system_has_hw_af(void)
> +{
> +	u64 mmfr1;
> +
> +	if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM))
> +		return false;
> +
> +	mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
> +	return cpuid_feature_extract_unsigned_field(mmfr1,
> +						ID_AA64MMFR1_HADBS_SHIFT);
> +}

Could we not add a new system-wide cpu feature that checks for hardware
AF? This read_sanitised_ftr_reg() does a binary search on each
invocation.
Will Deacon Dec. 9, 2020, 6:46 p.m. UTC | #2
On Wed, Dec 09, 2020 at 06:35:09PM +0000, Catalin Marinas wrote:
> On Wed, Dec 09, 2020 at 04:39:50PM +0000, Will Deacon wrote:
> > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> > index da250e4741bd..3424f5881390 100644
> > --- a/arch/arm64/include/asm/cpufeature.h
> > +++ b/arch/arm64/include/asm/cpufeature.h
> > @@ -764,6 +764,18 @@ static inline bool cpu_has_hw_af(void)
> >  						ID_AA64MMFR1_HADBS_SHIFT);
> >  }
> >  
> > +static inline bool system_has_hw_af(void)
> > +{
> > +	u64 mmfr1;
> > +
> > +	if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM))
> > +		return false;
> > +
> > +	mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
> > +	return cpuid_feature_extract_unsigned_field(mmfr1,
> > +						ID_AA64MMFR1_HADBS_SHIFT);
> > +}
> 
> Could we not add a new system-wide cpu feature that checks for hardware
> AF? This read_sanitised_ftr_reg() does a binary search on each
> invocation.

I posted a diff [1] which would allow removing the binary search for cases
where we can pass the register coding as a constant (like this), but
honestly, it's not like we have many ID registers so I doubt it really
matters in the grand scheme of things.

That said, I'm spinning a v2 anyway so I can include it for comments
since I haven't posted it as a proper patch before.

Will

[1] https://lore.kernel.org/r/20201202172727.GC29813@willie-the-truck
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index da250e4741bd..3424f5881390 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -764,6 +764,18 @@  static inline bool cpu_has_hw_af(void)
 						ID_AA64MMFR1_HADBS_SHIFT);
 }
 
+static inline bool system_has_hw_af(void)
+{
+	u64 mmfr1;
+
+	if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM))
+		return false;
+
+	mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
+	return cpuid_feature_extract_unsigned_field(mmfr1,
+						ID_AA64MMFR1_HADBS_SHIFT);
+}
+
 #ifdef CONFIG_ARM64_AMU_EXTN
 /* Check whether the cpu supports the Activity Monitors Unit (AMU) */
 extern bool cpu_has_amu_feat(int cpu);
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 5628289b9d5e..d5c2a7625e9a 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -974,7 +974,13 @@  static inline bool arch_faults_on_old_pte(void)
 
 	return !cpu_has_hw_af();
 }
-#define arch_faults_on_old_pte arch_faults_on_old_pte
+#define arch_faults_on_old_pte		arch_faults_on_old_pte
+
+/*
+ * 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_faultaround_pte	system_has_hw_af
 
 #endif /* !__ASSEMBLY__ */