From b3890c0f96f3f0eadaa954069949ac3ef8f3bbbe Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Mon, 7 Nov 2022 16:05:00 -0800 Subject: [PATCH] Revert "FROMLIST: mm: x86, arm64: add arch_has_hw_pte_young()" This reverts commit 1861f17391a871ecf944fd504cbb906fc6121261. 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 d1b19eaf9479..e2a304ef1fea 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1008,13 +1008,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 3908780fc408..448cd01eb3ec 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1397,10 +1397,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 2f1188980baf..d468efcf48f4 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -259,19 +259,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 84a45b664c48..dbeff9cf9604 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -122,6 +122,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) { @@ -2904,7 +2916,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);