mm/hugetlb: Add some new generic fallbacks
Subsystems (13)
v2 cover mm/hugetlb: Add some new generic fallbacks
This series adds the following new generic fallbacks. Before that it drops __HAVE_ARCH_HUGE_PTEP_GET from arm64 platform.
1. is_hugepage_only_range()
2. arch_clear_hugepage_flags()
This has been boot tested on arm64 and x86 platforms but built tested on some more platforms including the changed ones here. This series applies on v5.7-rc4. After this arm (32 bit) remains the sole platform defining it's own huge_ptep_get() via __HAVE_ARCH_HUGE_PTEP_GET.
Changes in V2:
- Adopted "#ifndef func" method (adding a single symbol to namespace) per Andrew
- Updated the commit messages in [PATCH 2/3] and [PATCH 3/3] as required
Changes in V1: (https://patchwork.kernel.org/project/linux-mm/list/?series=270677)
Anshuman Khandual (3):
arm64/mm: Drop __HAVE_ARCH_HUGE_PTEP_GET
mm/hugetlb: Define a generic fallback for is_hugepage_only_range() mm/hugetlb: Define a generic fallback for arch_clear_hugepage_flags()
arch/arm/include/asm/hugetlb.h | 7 +------ arch/arm64/include/asm/hugetlb.h | 13 +------------ arch/ia64/include/asm/hugetlb.h | 5 +---- arch/mips/include/asm/hugetlb.h | 11 ----------- arch/parisc/include/asm/hugetlb.h | 10 ---------- arch/powerpc/include/asm/hugetlb.h | 5 +---- arch/riscv/include/asm/hugetlb.h | 10 ---------- arch/s390/include/asm/hugetlb.h | 8 +------- arch/sh/include/asm/hugetlb.h | 7 +------ arch/sparc/include/asm/hugetlb.h | 10 ---------- arch/x86/include/asm/hugetlb.h | 10 ---------- include/linux/hugetlb.h | 14 ++++++++++++++ 12 files changed, 20 insertions(+), 90 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/3 arm64/mm: Drop __HAVE_ARCH_HUGE_PTEP_GET
Platform specific huge_ptep_get() is required only when fetching the huge PTE involves more than just dereferencing the page table pointer. This is not the case on arm64 platform. Hence huge_ptep_pte() can be dropped along with it's __HAVE_ARCH_HUGE_PTEP_GET subscription.
--- arch/arm64/include/asm/hugetlb.h | 6 ------ 1 file changed, 6 deletions(-)
arch/arm64/include/asm/hugetlb.h +0 -6
@@ -17,12 +17,6 @@extern bool arch_hugetlb_migration_supported (struct hstate *h);#endif -#define __HAVE_ARCH_HUGE_PTEP_GET -static inline pte_t huge_ptep_get (pte_t *ptep) -{ -return READ_ONCE (*ptep); -} -static inline int is_hugepage_only_range (struct mm_struct *mm,unsigned long addr,unsigned long len) {
Signature · 1 line
2.20.1
Will Deacon
maintainerRe: [PATCH V2 1/3] arm64/mm: Drop __HAVE_ARCH_HUGE_PTEP_GET
Quoted 21 lines · Anshuman Khandual
Platform specific
huge_ptep_get()is required only when fetching the huge PTE involves more than just dereferencing the page table pointer. This is not the case on arm64 platform. Hencehuge_ptep_pte()can be dropped along with it's__HAVE_ARCH_HUGE_PTEP_GETsubscription.Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>--- arch/arm64/include/asm/hugetlb.h | 6 ------ 1 file changed, 6 deletions(-)arch/arm64/include/asm/hugetlb.h +0
-0
arch/arm64/include/asm/hugetlb.h line 24
Quoted 8 lines
arch/arm64/include/asm/hugetlb.h +0
-5@@ -17,12 +17,6 @@extern bool arch_hugetlb_migration_supported (struct hstate *h);#endif -#define __HAVE_ARCH_HUGE_PTEP_GET -static inline pte_t huge_ptep_get (pte_t *ptep) -{ -return READ_ONCE (*ptep); -}
Hmm, I'm nervous about dropping the READ_ONCE() here. We added them after running into page-table issues with THP [1] and it's really important to use them consistently to avoid hitting that again.
If the generic code used READ_ONCE(), I'd be happy to switch to it.
Will
Re: [PATCH V2 1/3] arm64/mm: Drop __HAVE_ARCH_HUGE_PTEP_GET
Quoted 35 lines · Will Deacon
Quoted 21 lines · Anshuman Khandual
Platform specific
huge_ptep_get()is required only when fetching the huge PTE involves more than just dereferencing the page table pointer. This is not the case on arm64 platform. Hencehuge_ptep_pte()can be dropped along with it's__HAVE_ARCH_HUGE_PTEP_GETsubscription.Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>--- arch/arm64/include/asm/hugetlb.h | 6 ------ 1 file changed, 6 deletions(-)arch/arm64/include/asm/hugetlb.h +0
-0arch/arm64/include/asm/hugetlb.h line 24
Quoted 8 lines
arch/arm64/include/asm/hugetlb.h +0
-5@@ -17,12 +17,6 @@extern bool arch_hugetlb_migration_supported (struct hstate *h);#endif -#define __HAVE_ARCH_HUGE_PTEP_GET -static inline pte_t huge_ptep_get (pte_t *ptep) -{ -return READ_ONCE (*ptep); -}Hmm, I'm nervous about dropping the
READ_ONCE()here. We added them after running into page-table issues with THP [1] and it's really important to use them consistently to avoid hitting that again.
Quoted 1 line
If the generic code used
READ_ONCE(), I'd be happy to switch to it.
Sure, will add READ_ONCE() in the generic huge_ptep_get(). AFAICS it should not cause any problem for other platforms (but let me know otherwise).
Quoted 5 lines
Will
PATCH v2 2/3 mm/hugetlb: Define a generic fallback for is_hugepage_only_range()
In reply to Anshuman KhandualThere are multiple similar definitions for is_hugepage_only_range() on various platforms. Lets just add it's generic fallback definition for platforms that do not override. This help reduce code duplication.
--- arch/arm/include/asm/hugetlb.h | 6 ------ arch/arm64/include/asm/hugetlb.h | 6 ------ arch/ia64/include/asm/hugetlb.h | 1 + arch/mips/include/asm/hugetlb.h | 7 ------- arch/parisc/include/asm/hugetlb.h | 6 ------ arch/powerpc/include/asm/hugetlb.h | 1 + arch/riscv/include/asm/hugetlb.h | 6 ------ arch/s390/include/asm/hugetlb.h | 7 ------- arch/sh/include/asm/hugetlb.h | 6 ------ arch/sparc/include/asm/hugetlb.h | 6 ------ arch/x86/include/asm/hugetlb.h | 6 ------ include/linux/hugetlb.h | 9 +++++++++ 12 files changed, 11 insertions(+), 56 deletions(-)
arch/arm/include/asm/hugetlb.h +0 -6
@@ -14,12 +14,6 @@#include <asm/hugetlb-3level.h> #include <asm-generic/hugetlb.h> -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr,unsigned long len) -{ -return 0 ; -} -static inline void arch_clear_hugepage_flags (struct page *page) {clear_bit (PG_dcache_clean, &page->flags);
arch/arm64/include/asm/hugetlb.h +0 -6
@@ -17,12 +17,6 @@extern bool arch_hugetlb_migration_supported (struct hstate *h);#endif -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr,unsigned long len) -{ -return 0 ; -} -static inline void arch_clear_hugepage_flags (struct page *page) {clear_bit (PG_dcache_clean, &page->flags);
arch/ia64/include/asm/hugetlb.h +1 -0
@@ -20,6 +20,7 @@ static inline int is_hugepage_only_range(struct mm_struct *mm,return (REGION_NUMBER (addr) ==RGN_HPAGE ||REGION_NUMBER ((addr)+(len)-1 ) ==RGN_HPAGE ); } +#define is_hugepage_only_range is_hugepage_only_range#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/mips/include/asm/hugetlb.h +0 -7
@@ -11,13 +11,6 @@#include <asm/page.h> -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) -{ -return 0 ; -} -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE static inline int prepare_hugepage_range(struct file *file, unsigned long addr,
arch/parisc/include/asm/hugetlb.h +0 -6
@@ -12,12 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,pte_t huge_ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep); -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) { -return 0 ; -} -/* * If the arch doesn't supply something else, assume that hugepage * size aligned regions are ok without further preparation.
arch/powerpc/include/asm/hugetlb.h +1 -0
@@ -30,6 +30,7 @@ static inline int is_hugepage_only_range(struct mm_struct *mm,return slice_is_hugepage_only_range (mm, addr, len);return 0 ; } +#define is_hugepage_only_range is_hugepage_only_range#define __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
arch/riscv/include/asm/hugetlb.h +0 -6
@@ -5,12 +5,6 @@#include <asm-generic/hugetlb.h> #include <asm/page.h> -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) { -return 0 ; -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/s390/include/asm/hugetlb.h +0 -7
@@ -21,13 +21,6 @@ pte_t huge_ptep_get(pte_t *ptep);pte_t huge_ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep); -static inline bool is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) -{ -return false; -} -/* * If the arch doesn't supply something else, assume that hugepage * size aligned regions are ok without further preparation.
arch/sh/include/asm/hugetlb.h +0 -6
@@ -5,12 +5,6 @@#include <asm/cacheflush.h> #include <asm/page.h> -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) { -return 0 ; -} -/* * If the arch doesn't supply something else, assume that hugepage * size aligned regions are ok without further preparation.
arch/sparc/include/asm/hugetlb.h +0 -6
@@ -20,12 +20,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,pte_t huge_ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep); -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) { -return 0 ; -} -#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSHstatic inline void huge_ptep_clear_flush (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep)
arch/x86/include/asm/hugetlb.h +0 -6
@@ -7,12 +7,6 @@#define hugepages_supported () boot_cpu_has(X86_FEATURE_PSE) -static inline int is_hugepage_only_range (struct mm_struct *mm, -unsigned long addr, -unsigned long len) { -return 0 ; -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
include/linux/hugetlb.h +9 -0
@@ -591,6 +591,15 @@ static inline unsigned int blocks_per_huge_page(struct hstate *h)#include <asm/hugetlb.h> +#ifndef is_hugepage_only_range +static inline int is_hugepage_only_range (struct mm_struct *mm, +unsigned long addr,unsigned long len) +{ +return 0 ; +} +#define is_hugepage_only_range is_hugepage_only_range +#endif +#ifndef arch_make_huge_ptestatic inline pte_t arch_make_huge_pte (pte_t entry,struct vm_area_struct *vma,struct page *page,int writable)
Signature · 1 line
2.20.1
PATCH v2 3/3 mm/hugetlb: Define a generic fallback for arch_clear_hugepage_flags()
In reply to Anshuman KhandualThere are multiple similar definitions for arch_clear_hugepage_flags() on various platforms. Lets just add it's generic fallback definition for platforms that do not override. This help reduce code duplication.
--- arch/arm/include/asm/hugetlb.h | 1 + arch/arm64/include/asm/hugetlb.h | 1 + arch/ia64/include/asm/hugetlb.h | 4 ---- arch/mips/include/asm/hugetlb.h | 4 ---- arch/parisc/include/asm/hugetlb.h | 4 ---- arch/powerpc/include/asm/hugetlb.h | 4 ---- arch/riscv/include/asm/hugetlb.h | 4 ---- arch/s390/include/asm/hugetlb.h | 1 + arch/sh/include/asm/hugetlb.h | 1 + arch/sparc/include/asm/hugetlb.h | 4 ---- arch/x86/include/asm/hugetlb.h | 4 ---- include/linux/hugetlb.h | 5 +++++ 12 files changed, 9 insertions(+), 28 deletions(-)
arch/arm/include/asm/hugetlb.h +1 -0
@@ -18,5 +18,6 @@ static inline void arch_clear_hugepage_flags(struct page *page) {clear_bit (PG_dcache_clean, &page->flags); } +#define arch_clear_hugepage_flags arch_clear_hugepage_flags#endif /* _ASM_ARM_HUGETLB_H */
arch/arm64/include/asm/hugetlb.h +1 -0
@@ -21,6 +21,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) {clear_bit (PG_dcache_clean, &page->flags); } +#define arch_clear_hugepage_flags arch_clear_hugepage_flagsextern pte_t arch_make_huge_pte (pte_t entry,struct vm_area_struct *vma,struct page *page,int writable);
arch/ia64/include/asm/hugetlb.h +0 -4
@@ -28,10 +28,6 @@ static inline void huge_ptep_clear_flush(struct vm_area_struct *vma, { } -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#include <asm-generic/hugetlb.h> #endif /* _ASM_IA64_HUGETLB_H */
arch/mips/include/asm/hugetlb.h +0 -4
@@ -75,10 +75,6 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, return changed; } -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#include <asm-generic/hugetlb.h> #endif /* __ASM_HUGETLB_H */
arch/parisc/include/asm/hugetlb.h +0 -4
@@ -42,10 +42,6 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty); -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#include <asm-generic/hugetlb.h> #endif /* _ASM_PARISC64_HUGETLB_H */
arch/powerpc/include/asm/hugetlb.h +0 -4
@@ -61,10 +61,6 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty); -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#include <asm-generic/hugetlb.h> #else /* ! CONFIG_HUGETLB_PAGE */
arch/riscv/include/asm/hugetlb.h +0 -4
@@ -5,8 +5,4 @@#include <asm-generic/hugetlb.h> #include <asm/page.h> -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#endif /* _ASM_RISCV_HUGETLB_H */
arch/s390/include/asm/hugetlb.h +1 -0
@@ -39,6 +39,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) {clear_bit (PG_arch_1, &page->flags); } +#define arch_clear_hugepage_flags arch_clear_hugepage_flagsstatic inline void huge_pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep,unsigned long sz)
arch/sh/include/asm/hugetlb.h +1 -0
@@ -30,6 +30,7 @@ static inline void arch_clear_hugepage_flags(struct page *page) {clear_bit (PG_dcache_clean, &page->flags); } +#define arch_clear_hugepage_flags arch_clear_hugepage_flags#include <asm-generic/hugetlb.h>
arch/sparc/include/asm/hugetlb.h +0 -4
@@ -47,10 +47,6 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,return changed; } -static inline void arch_clear_hugepage_flags (struct page *page) -{ -} -#define __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, unsigned long floor,
arch/x86/include/asm/hugetlb.h +0 -3
@@ -7,8 +7,4 @@#define hugepages_supported () boot_cpu_has(X86_FEATURE_PSE) -static inline void arch_clear_hugepage_flags (struct page *page) -{ -}