From 691008625e031cc3f742c183c6bd47a5b241ea41 Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Tue, 8 Nov 2022 09:13:15 -0800 Subject: [PATCH] Revert "FROMLIST: mm: x86, arm64: add arch_has_hw_pte_young()" This reverts commit 1ed19b562b1fd7862dca4db2d7978fb63cc61454. To be replaced with upstream version. Bug: 249601646 Change-Id: Ib992a9f199a9f30fbbf3f39537d87a8fb605c893 Signed-off-by: Kalesh Singh --- arch/arm64/include/asm/pgtable.h | 14 ++++++++++++-- arch/x86/include/asm/pgtable.h | 6 +++--- include/linux/pgtable.h | 13 ------------- mm/memory.c | 14 +++++++++++++- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index e4796c3ad19a..40321a57088d 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1011,13 +1011,23 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, * 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 +static inline bool arch_faults_on_old_pte(void) +{ + WARN_ON(preemptible()); + + return !cpu_has_hw_af(); +} +#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_prefaulted_pte cpu_has_hw_af +static inline bool arch_wants_old_prefaulted_pte(void) +{ + return !arch_faults_on_old_pte(); +} +#define arch_wants_old_prefaulted_pte arch_wants_old_prefaulted_pte #endif /* !__ASSEMBLY__ */ diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 7792a0624b64..87de9f2d71cf 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1452,10 +1452,10 @@ static inline bool arch_has_pfn_modify_check(void) return boot_cpu_has_bug(X86_BUG_L1TF); } -#define arch_has_hw_pte_young arch_has_hw_pte_young -static inline bool arch_has_hw_pte_young(void) +#define arch_faults_on_old_pte arch_faults_on_old_pte +static inline bool arch_faults_on_old_pte(void) { - return true; + return false; } #endif /* __ASSEMBLY__ */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 3f6deb434074..eb724505951f 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -241,19 +241,6 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif -#ifndef arch_has_hw_pte_young -/* - * Return whether the accessed bit is supported on the local CPU. - * - * This stub assumes accessing through an old PTE triggers a page fault. - * Architectures that automatically set the access bit should overwrite it. - */ -static inline bool arch_has_hw_pte_young(void) -{ - return false; -} -#endif - #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long address, diff --git a/mm/memory.c b/mm/memory.c index e9bb4af8e09d..a58fa97404e0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -126,6 +126,18 @@ int randomize_va_space __read_mostly = 2; #endif +#ifndef arch_faults_on_old_pte +static inline bool arch_faults_on_old_pte(void) +{ + /* + * Those arches which don't have hw access flag feature need to + * implement their own helper. By default, "true" means pagefault + * will be hit on old pte. + */ + return true; +} +#endif + #ifndef arch_wants_old_prefaulted_pte static inline bool arch_wants_old_prefaulted_pte(void) { @@ -2871,7 +2883,7 @@ static inline bool cow_user_page(struct page *dst, struct page *src, * On architectures with software "accessed" bits, we would * take a double page fault, so mark it accessed here. */ - if (!arch_has_hw_pte_young() && !pte_young(vmf->orig_pte)) { + if (arch_faults_on_old_pte() && !pte_young(vmf->orig_pte)) { pte_t entry; vmf->pte = pte_offset_map_lock(mm, vmf->pmd, addr, &vmf->ptl);