huge vmalloc mappings
Subsystems (12)
Nicholas Piggin
reviewerv13 cover huge vmalloc mappings
Important compound page fix thanks to Ding Tianhong.
Thanks,
Nick
Since v12:
- Use compound pages so it works with remap_vmalloc_range [noticed by Ding]
- Fix debug_vm_pgtable.c compile error.
Since v11:
- ARM compile fix (patch 1)
- debug_vm_pgtable compile fix
Since v10:
- Fixed code style, most > 80 colums, tweak patch titles, etc [thanks Christoph]
- Made huge vmalloc code and data structure compile away if unselected [Christoph]
- Archs only have to provide arch_vmap_p?d_supported for levels they implement [Christoph]
Since v9:
- Fixed intermediate build breakage on x86-32 !PAE [thanks Ding]
- Fixed small page fallback case vm_struct double-free [thanks Ding]
Since v8:
- Fixed nommu compile.
- Added Kconfig option help text
- Added VM_NOHUGE which should help archs implement it [suggested by Rick]
Since v7:
- Rebase, added some acks, compile fix
- Removed "order=" from vmallocinfo, it's a bit confusing (nr_pages is in small page size for compatibility).
- Added arch_vmap_pmd_supported() test before starting to allocate the large page, rather than only testing it when doing the map, to avoid unsupported configs trying to allocate huge pages for no reason.
Since v6:
- Fixed a false positive warning introduced in patch 2, found by kbuild test robot.
Since v5:
- Split arch changes out better and make the constant folding work
- Avoid most of the 80 column wrap, fix a reference to lib/ioremap.c
- Fix compile error on some archs
*** BLURB HERE ***
Nicholas Piggin (14):
ARM: mm: add missing pud_page define to 2-level page tables mm/vmalloc: fix HUGE_VMAP regression by enabling huge pages in
vmalloc_to_page
mm: apply_to_pte_range warn and fail if a large pte is encountered mm/vmalloc: rename vmap_*_range vmap_pages_*_range mm/ioremap: rename ioremap_*_range to vmap_*_range
mm: HUGE_VMAP arch support cleanup
powerpc: inline huge vmap supported functions
arm64: inline huge vmap supported functions
x86: inline huge vmap supported functions
mm/vmalloc: provide fallback arch huge vmap support functions
mm: Move vmap_range from mm/ioremap.c to mm/vmalloc.c mm/vmalloc: add vmap_range_noflush variant
mm/vmalloc: Hugepage vmalloc mappings powerpc/64s/radix: Enable huge vmalloc mappings
.../admin-guide/kernel-parameters.txt | 2 + arch/Kconfig | 11 + arch/arm/include/asm/pgtable-3level.h | 2 - arch/arm/include/asm/pgtable.h | 3 + arch/arm64/include/asm/vmalloc.h | 24 + arch/arm64/mm/mmu.c | 26 - arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/vmalloc.h | 20 + arch/powerpc/kernel/module.c | 22 +- arch/powerpc/mm/book3s64/radix_pgtable.c | 21 - arch/x86/include/asm/vmalloc.h | 20 + arch/x86/mm/ioremap.c | 19 - arch/x86/mm/pgtable.c | 13 - include/linux/io.h | 9 - include/linux/vmalloc.h | 46 ++ init/main.c | 1 - mm/debug_vm_pgtable.c | 4 +- mm/ioremap.c | 225 +------- mm/memory.c | 66 ++- mm/page_alloc.c | 5 +- mm/vmalloc.c | 485 +++++++++++++++--- 21 files changed, 621 insertions(+), 404 deletions(-)
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 1/14 ARM: mm: add missing pud_page define to 2-level page tables
ARM uses its own PMD folding scheme which is missing pud_page which should just pass through to pmd_page. Move this from the 3-level page table to common header.
--- arch/arm/include/asm/pgtable-3level.h | 2 -- arch/arm/include/asm/pgtable.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/include/asm/pgtable-3level.h +0 -2
@@ -186,8 +186,6 @@ static inline pte_t pte_mkspecial(pte_t pte)#define pmd_write (pmd) (pmd_isclear((pmd), L_PMD_SECT_RDONLY))#define pmd_dirty (pmd) (pmd_isset((pmd), L_PMD_SECT_DIRTY)) -#define pud_page (pud) pmd_page(__pmd(pud_val(pud))) -#define pud_write (pud) pmd_write(__pmd(pud_val(pud)))#define pmd_hugewillfault (pmd) (!pmd_young(pmd) || !pmd_write(pmd))#define pmd_thp_or_huge (pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd))
arch/arm/include/asm/pgtable.h +3 -0
@@ -166,6 +166,9 @@ extern struct page *empty_zero_page;extern pgd_t swapper_pg_dir[PTRS_PER_PGD ]; +#define pud_page (pud) pmd_page(__pmd(pud_val(pud))) +#define pud_write (pud) pmd_write(__pmd(pud_val(pud))) +#define pmd_none (pmd) (!pmd_val(pmd))static inline pte_t *pmd_page_vaddr (pmd_t pmd)
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 2/14 mm/vmalloc: fix HUGE_VMAP regression by enabling huge pages in vmalloc_to_page
In reply to Nicholas Pigginvmalloc_to_page returns NULL for addresses mapped by larger pages[*]. Whether or not a vmap is huge depends on the architecture details, alignments, boot options, etc., which the caller can not be expected to know. Therefore HUGE_VMAP is a regression for vmalloc_to_page.
This change teaches vmalloc_to_page about larger pages, and returns the struct page that corresponds to the offset within the large page. This makes the API agnostic to mapping implementation details.
[*] As explained by commit 029c54b095995 ("mm/vmalloc.c: huge-vmap:
fail gracefully on unexpected huge vmap mappings")
--- mm/vmalloc.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-)
mm/vmalloc.c +26 -15
@@ -34,7 +34,7 @@#include <linux/bitops.h> #include <linux/rbtree_augmented.h> #include <linux/overflow.h> - +#include <linux/pgtable.h> #include <linux/uaccess.h> #include <asm/tlbflush.h> #include <asm/shmparam.h>
@@ -343,7 +343,9 @@ int is_vmalloc_or_module_addr(const void *x) }/* -* Walk a vmap address to the struct page it maps. +* Walk a vmap address to the struct page it maps. Huge vmap mappings will +* return the tail page that corresponds to the base page address, which +* matches small vmap mappings. */ struct page *vmalloc_to_page (const void *vmalloc_addr) {
@@ -363,25 +365,33 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)if (pgd_none (*pgd))return NULL ; +if (WARN_ON_ONCE (pgd_leaf (*pgd))) +return NULL ;/* XXX: no allowance for huge pgd */ +if (WARN_ON_ONCE (pgd_bad (*pgd))) +return NULL ; + p4d =p4d_offset (pgd, addr);if (p4d_none (*p4d))return NULL ; - pud =pud_offset (p4d, addr); +if (p4d_leaf (*p4d)) +return p4d_page (*p4d) + ((addr & ~P4D_MASK ) >>PAGE_SHIFT ); +if (WARN_ON_ONCE (p4d_bad (*p4d))) +return NULL ; -/* -* Don't dereference bad PUD or PMD (below) entries. This will also -* identify huge mappings, which we may encounter on architectures -* that define CONFIG_HAVE_ARCH_HUGE_VMAP=y. Such regions will be -* identified as vmalloc addresses by is_vmalloc_addr(), but are -* not [unambiguously] associated with a struct page, so there is -* no correct value to return for them. -*/ -WARN_ON_ONCE (pud_bad (*pud)); -if (pud_none (*pud) ||pud_bad (*pud)) + pud =pud_offset (p4d, addr); +if (pud_none (*pud)) +return NULL ; +if (pud_leaf (*pud)) +return pud_page (*pud) + ((addr & ~PUD_MASK ) >>PAGE_SHIFT ); +if (WARN_ON_ONCE (pud_bad (*pud)))return NULL ; + pmd =pmd_offset (pud, addr); -WARN_ON_ONCE (pmd_bad (*pmd)); -if (pmd_none (*pmd) ||pmd_bad (*pmd)) +if (pmd_none (*pmd)) +return NULL ; +if (pmd_leaf (*pmd)) +return pmd_page (*pmd) + ((addr & ~PMD_MASK ) >>PAGE_SHIFT ); +if (WARN_ON_ONCE (pmd_bad (*pmd)))return NULL ; ptep =pte_offset_map (pmd, addr);
@@ -389,6 +399,7 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)if (pte_present (pte)) page =pte_page (pte);pte_unmap (ptep); +return page; }EXPORT_SYMBOL (vmalloc_to_page);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 3/14 mm: apply_to_pte_range warn and fail if a large pte is encountered
In reply to Nicholas Pigginapply_to_pte_range might mistake a large pte for bad, or treat it as a page table, resulting in a crash or corruption. Add a test to warn and return error if large entries are found.
--- mm/memory.c | 66 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-)
mm/memory.c +49 -17
@@ -2446,13 +2446,21 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, }do { next =pmd_addr_end (addr, end); -if (create || !pmd_none_or_clear_bad (pmd)) { - err =apply_to_pte_range (mm, pmd, addr, next, fn, data, - create, mask); -if (err) -break ; +if (pmd_none (*pmd) && !create) +continue ; +if (WARN_ON_ONCE (pmd_leaf (*pmd))) +return -EINVAL ; +if (!pmd_none (*pmd) &&WARN_ON_ONCE (pmd_bad (*pmd))) { +if (!create) +continue ; +pmd_clear_bad (pmd); } + err =apply_to_pte_range (mm, pmd, addr, next, + fn, data, create, mask); +if (err) +break ; }while (pmd++, addr = next, addr != end); +return err; }
@@ -2474,13 +2482,21 @@ static int apply_to_pud_range(struct mm_struct *mm, p4d_t *p4d, }do { next =pud_addr_end (addr, end); -if (create || !pud_none_or_clear_bad (pud)) { - err =apply_to_pmd_range (mm, pud, addr, next, fn, data, - create, mask); -if (err) -break ; +if (pud_none (*pud) && !create) +continue ; +if (WARN_ON_ONCE (pud_leaf (*pud))) +return -EINVAL ; +if (!pud_none (*pud) &&WARN_ON_ONCE (pud_bad (*pud))) { +if (!create) +continue ; +pud_clear_bad (pud); } + err =apply_to_pmd_range (mm, pud, addr, next, + fn, data, create, mask); +if (err) +break ; }while (pud++, addr = next, addr != end); +return err; }
@@ -2502,13 +2518,21 @@ static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, }do { next =p4d_addr_end (addr, end); -if (create || !p4d_none_or_clear_bad (p4d)) { - err =apply_to_pud_range (mm, p4d, addr, next, fn, data, - create, mask); -if (err) -break ; +if (p4d_none (*p4d) && !create) +continue ; +if (WARN_ON_ONCE (p4d_leaf (*p4d))) +return -EINVAL ; +if (!p4d_none (*p4d) &&WARN_ON_ONCE (p4d_bad (*p4d))) { +if (!create) +continue ; +p4d_clear_bad (p4d); } + err =apply_to_pud_range (mm, p4d, addr, next, + fn, data, create, mask); +if (err) +break ; }while (p4d++, addr = next, addr != end); +return err; }
@@ -2528,9 +2552,17 @@ static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, pgd =pgd_offset (mm, addr);do { next =pgd_addr_end (addr, end); -if (!create &&pgd_none_or_clear_bad (pgd)) +if (pgd_none (*pgd) && !create)continue ; - err =apply_to_p4d_range (mm, pgd, addr, next, fn, data, create, &mask); +if (WARN_ON_ONCE (pgd_leaf (*pgd))) +return -EINVAL ; +if (!pgd_none (*pgd) &&WARN_ON_ONCE (pgd_bad (*pgd))) { +if (!create) +continue ; +pgd_clear_bad (pgd); + } + err =apply_to_p4d_range (mm, pgd, addr, next, + fn, data, create, &mask);if (err)break ; }while (pgd++, addr = next, addr != end);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 4/14 mm/vmalloc: rename vmap_*_range vmap_pages_*_range
In reply to Nicholas PigginThe vmalloc mapper operates on a struct page * array rather than a linear physical address, re-name it to make this distinction clear.
--- mm/vmalloc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
mm/vmalloc.c +8 -8
@@ -189,7 +189,7 @@ void unmap_kernel_range_noflush(unsigned long start, unsigned long size)arch_sync_kernel_mappings (start, end); } -static int vmap_pte_range (pmd_t *pmd,unsigned long addr, +static int vmap_pages_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -217,7 +217,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,return 0 ; } -static int vmap_pmd_range (pud_t *pud,unsigned long addr, +static int vmap_pages_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -229,13 +229,13 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,return -ENOMEM ;do { next =pmd_addr_end (addr, end); -if (vmap_pte_range (pmd, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pte_range (pmd, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (pmd++, addr = next, addr != end);return 0 ; } -static int vmap_pud_range (p4d_t *p4d,unsigned long addr, +static int vmap_pages_pud_range (p4d_t *p4d,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -247,13 +247,13 @@ static int vmap_pud_range(p4d_t *p4d, unsigned long addr,return -ENOMEM ;do { next =pud_addr_end (addr, end); -if (vmap_pmd_range (pud, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pmd_range (pud, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (pud++, addr = next, addr != end);return 0 ; } -static int vmap_p4d_range (pgd_t *pgd,unsigned long addr, +static int vmap_pages_p4d_range (pgd_t *pgd,unsigned long addr,unsigned long end,pgprot_t prot,struct page **pages,int *nr,pgtbl_mod_mask *mask) {
@@ -265,7 +265,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr,return -ENOMEM ;do { next =p4d_addr_end (addr, end); -if (vmap_pud_range (p4d, addr, next, prot, pages, nr, mask)) +if (vmap_pages_pud_range (p4d, addr, next, prot, pages, nr, mask))return -ENOMEM ; }while (p4d++, addr = next, addr != end);return 0 ;
@@ -306,7 +306,7 @@ int map_kernel_range_noflush(unsigned long addr, unsigned long size, next =pgd_addr_end (addr, end);if (pgd_bad (*pgd)) mask |=PGTBL_PGD_MODIFIED ; - err =vmap_p4d_range (pgd, addr, next, prot, pages, &nr, &mask); + err =vmap_pages_p4d_range (pgd, addr, next, prot, pages, &nr, &mask);if (err)return err; }while (pgd++, addr = next, addr != end);
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 5/14 mm/ioremap: rename ioremap_*_range to vmap_*_range
In reply to Nicholas PigginThis will be used as a generic kernel virtual mapping function, so re-name it in preparation.
--- mm/ioremap.c | 64 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 31 deletions(-)
mm/ioremap.c +33 -31
@@ -61,9 +61,9 @@ static inline int ioremap_pud_enabled(void) { return 0; }static inline int ioremap_pmd_enabled (void ) {return 0 ; }#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ -static int ioremap_pte_range (pmd_t *pmd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pte_t *pte;u64 pfn;
@@ -81,9 +81,8 @@ static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,return 0 ; } -static int ioremap_try_huge_pmd (pmd_t *pmd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_pmd (pmd_t *pmd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_pmd_enabled ())return 0 ;
@@ -103,9 +102,9 @@ static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long addr,return pmd_set_huge (pmd, phys_addr, prot); } -static inline int ioremap_pmd_range (pud_t *pud,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pmd_range (pud_t *pud,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pmd_t *pmd;unsigned long next;
@@ -116,20 +115,19 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,do { next =pmd_addr_end (addr, end); -if (ioremap_try_huge_pmd (pmd, addr, next, phys_addr, prot)) { +if (vmap_try_huge_pmd (pmd, addr, next, phys_addr, prot)) { *mask |=PGTBL_PMD_MODIFIED ;continue ; } -if (ioremap_pte_range (pmd, addr, next, phys_addr, prot, mask)) +if (vmap_pte_range (pmd, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (pmd++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -static int ioremap_try_huge_pud (pud_t *pud,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_pud (pud_t *pud,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_pud_enabled ())return 0 ;
@@ -149,9 +147,9 @@ static int ioremap_try_huge_pud(pud_t *pud, unsigned long addr,return pud_set_huge (pud, phys_addr, prot); } -static inline int ioremap_pud_range (p4d_t *p4d,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_pud_range (p4d_t *p4d,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {pud_t *pud;unsigned long next;
@@ -162,20 +160,19 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr,do { next =pud_addr_end (addr, end); -if (ioremap_try_huge_pud (pud, addr, next, phys_addr, prot)) { +if (vmap_try_huge_pud (pud, addr, next, phys_addr, prot)) { *mask |=PGTBL_PUD_MODIFIED ;continue ; } -if (ioremap_pmd_range (pud, addr, next, phys_addr, prot, mask)) +if (vmap_pmd_range (pud, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (pud++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -static int ioremap_try_huge_p4d (p4d_t *p4d,unsigned long addr, -unsigned long end,phys_addr_t phys_addr, -pgprot_t prot) +static int vmap_try_huge_p4d (p4d_t *p4d,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {if (!ioremap_p4d_enabled ())return 0 ;
@@ -195,9 +192,9 @@ static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr,return p4d_set_huge (p4d, phys_addr, prot); } -static inline int ioremap_p4d_range (pgd_t *pgd,unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot, -pgtbl_mod_mask *mask) +static int vmap_p4d_range (pgd_t *pgd,unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +pgtbl_mod_mask *mask) {p4d_t *p4d;unsigned long next;
@@ -208,19 +205,19 @@ static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,do { next =p4d_addr_end (addr, end); -if (ioremap_try_huge_p4d (p4d, addr, next, phys_addr, prot)) { +if (vmap_try_huge_p4d (p4d, addr, next, phys_addr, prot)) { *mask |=PGTBL_P4D_MODIFIED ;continue ; } -if (ioremap_pud_range (p4d, addr, next, phys_addr, prot, mask)) +if (vmap_pud_range (p4d, addr, next, phys_addr, prot, mask))return -ENOMEM ; }while (p4d++, phys_addr += (next - addr), addr = next, addr != end);return 0 ; } -int ioremap_page_range (unsigned long addr, -unsigned long end,phys_addr_t phys_addr,pgprot_t prot) +static int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot) {pgd_t *pgd;unsigned long start;
@@ -235,8 +232,7 @@ int ioremap_page_range(unsigned long addr, pgd =pgd_offset_k (addr);do { next =pgd_addr_end (addr, end); - err =ioremap_p4d_range (pgd, addr, next, phys_addr, prot, - &mask); + err =vmap_p4d_range (pgd, addr, next, phys_addr, prot, &mask);if (err)break ; }while (pgd++, phys_addr += (next - addr), addr = next, addr != end);
@@ -249,6 +245,12 @@ int ioremap_page_range(unsigned long addr,return err; } +int ioremap_page_range (unsigned long addr, +unsigned long end,phys_addr_t phys_addr,pgprot_t prot) +{ +return vmap_range (addr, end, phys_addr, prot); +} +#ifdef CONFIG_GENERIC_IOREMAP void __iomem *ioremap_prot (phys_addr_t addr,size_t size,unsigned long prot) {
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 6/14 mm: HUGE_VMAP arch support cleanup
In reply to Nicholas PigginThis changes the awkward approach where architectures provide init functions to determine which levels they can provide large mappings for, to one where the arch is queried for each call.
This removes code and indirection, and allows constant-folding of dead code for unsupported levels.
This also adds a prot argument to the arch query. This is unused currently but could help with some architectures (e.g., some powerpc processors can't map uncacheable memory with large pages).
--- arch/arm64/include/asm/vmalloc.h | 8 ++ arch/arm64/mm/mmu.c | 10 +-- arch/powerpc/include/asm/vmalloc.h | 8 ++ arch/powerpc/mm/book3s64/radix_pgtable.c | 8 +- arch/x86/include/asm/vmalloc.h | 7 ++ arch/x86/mm/ioremap.c | 12 +-- include/linux/io.h | 9 --- include/linux/vmalloc.h | 6 ++ init/main.c | 1 - mm/debug_vm_pgtable.c | 4 +- mm/ioremap.c | 94 ++++++++++-------------- 11 files changed, 87 insertions(+), 80 deletions(-)
arch/arm64/include/asm/vmalloc.h +8 -0
@@ -1,4 +1,12 @@#ifndef _ASM_ARM64_VMALLOC_H#define _ASM_ARM64_VMALLOC_H +#include <asm/page.h> + +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_ARM64_VMALLOC_H */
arch/arm64/mm/mmu.c +5 -5
@@ -1316,12 +1316,12 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)return dt_virt; } -int __init arch_ioremap_p4d_supported (void ) +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {/* * Only 4k granule supports level 1 block mappings.
@@ -1331,9 +1331,9 @@ int __init arch_ioremap_pud_supported(void) !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) { -/* See arch_ioremap_pud_supported() */ +/* See arch_vmap_pud_supported() */ return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); }
arch/powerpc/include/asm/vmalloc.h +8 -0
@@ -1,4 +1,12 @@#ifndef _ASM_POWERPC_VMALLOC_H#define _ASM_POWERPC_VMALLOC_H +#include <asm/page.h> + +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_POWERPC_VMALLOC_H */
arch/powerpc/mm/book3s64/radix_pgtable.c +4 -4
@@ -1082,13 +1082,13 @@ void radix__ptep_modify_prot_commit(struct vm_area_struct *vma,set_pte_at (mm, addr, ptep, pte); } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {/* HPT does not cope with large pages in the vmalloc area */ return radix_enabled (); } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) {return radix_enabled (); }
@@ -1182,7 +1182,7 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)return 1 ; } -int __init arch_ioremap_p4d_supported (void ) +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; }
arch/x86/include/asm/vmalloc.h +7 -0
@@ -1,6 +1,13 @@#ifndef _ASM_X86_VMALLOC_H#define _ASM_X86_VMALLOC_H +#include <asm/page.h> #include <asm/pgtable_areas.h> +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot); +bool arch_vmap_pud_supported (pgprot_t prot); +bool arch_vmap_pmd_supported (pgprot_t prot); +#endif +#endif /* _ASM_X86_VMALLOC_H */
arch/x86/mm/ioremap.c +7 -5
@@ -481,24 +481,26 @@ void iounmap(volatile void __iomem *addr) }EXPORT_SYMBOL (iounmap); -int __init arch_ioremap_p4d_supported (void ) +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP +bool arch_vmap_p4d_supported (pgprot_t prot) { -return 0 ; +return false; } -int __init arch_ioremap_pud_supported (void ) +bool arch_vmap_pud_supported (pgprot_t prot) {#ifdef CONFIG_X86_64 return boot_cpu_has (X86_FEATURE_GBPAGES );#else -return 0 ; +return false;#endif } -int __init arch_ioremap_pmd_supported (void ) +bool arch_vmap_pmd_supported (pgprot_t prot) {return boot_cpu_has (X86_FEATURE_PSE ); } +#endif /* * Convert a physical pointer to a virtual kernel pointer for /dev/mem
include/linux/io.h +0 -9
@@ -31,15 +31,6 @@ static inline int ioremap_page_range(unsigned long addr, unsigned long end, }#endif -#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -void __init ioremap_huge_init (void ); -int arch_ioremap_p4d_supported (void ); -int arch_ioremap_pud_supported (void ); -int arch_ioremap_pmd_supported (void ); -#else -static inline void ioremap_huge_init (void ) { } -#endif -/* * Managed iomap interface */
include/linux/vmalloc.h +6 -0
@@ -78,6 +78,12 @@ struct vmap_area { }; }; +#ifndef CONFIG_HAVE_ARCH_HUGE_VMAP +static inline bool arch_vmap_p4d_supported (pgprot_t prot) {return false; } +static inline bool arch_vmap_pud_supported (pgprot_t prot) {return false; } +static inline bool arch_vmap_pmd_supported (pgprot_t prot) {return false; } +#endif +/* * Highlevel APIs for driver use */
init/main.c +0 -1
@@ -837,7 +837,6 @@ static void __init mm_init(void)pgtable_init ();debug_objects_mem_init ();vmalloc_init (); -ioremap_huge_init ();/* Should be run before the first non-init thread is created */ init_espfix_bsp ();/* Should be run after espfix64 is set up. */
mm/debug_vm_pgtable.c +2 -2
@@ -247,7 +247,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) {pmd_t pmd; -if (!arch_ioremap_pmd_supported ()) +if (!arch_vmap_pmd_supported (prot))return ;pr_debug ("Validating PMD huge\n" );
@@ -385,7 +385,7 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) {pud_t pud; -if (!arch_ioremap_pud_supported ()) +if (!arch_vmap_pud_supported (prot))return ;pr_debug ("Validating PUD huge\n" );
mm/ioremap.c +40 -54
189 lines not on this page · raw message
Signature · 1 line
2.23.0
Re: [PATCH v13 06/14] mm: HUGE_VMAP arch support cleanup
Le 17/03/2021 à 07:23, Nicholas Piggin a écrit :
Quoted 43 lines
This changes the awkward approach where architectures provide init functions to determine which levels they can provide large mappings for, to one where the arch is queried for each call.
This removes code and indirection, and allows constant-folding of dead code for unsupported levels.
This also adds a prot argument to the arch query. This is unused currently but could help with some architectures (e.g., some powerpc processors can't map uncacheable memory with large pages).
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Reviewed-by Ding Tianhong <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>--- arch/arm64/include/asm/vmalloc.h | 8 ++ arch/arm64/mm/mmu.c | 10 +-- arch/powerpc/include/asm/vmalloc.h | 8 ++ arch/powerpc/mm/book3s64/radix_pgtable.c | 8 +- arch/x86/include/asm/vmalloc.h | 7 ++ arch/x86/mm/ioremap.c | 12 +-- include/linux/io.h | 9 --- include/linux/vmalloc.h | 6 ++ init/main.c | 1 - mm/debug_vm_pgtable.c | 4 +- mm/ioremap.c | 94 ++++++++++-------------- 11 files changed, 87 insertions(+), 80 deletions(-)mm/ioremap.c +0
-0
mm/ioremap.c line 19
Quoted 8 lines
mm/ioremap.c +1
-4@@ -16,49 +16,16 @@#include "pgalloc-track.h" #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static int __read_mostly ioremap_p4d_capable; -static int __read_mostly ioremap_pud_capable; -static int __read_mostly ioremap_pmd_capable; -static int __read_mostly ioremap_huge_disabled; +static bool __ro_after_init iomap_max_page_shift =PAGE_SHIFT ;
Must be an int, not a bool.
Quoted 35 lines
mm/ioremap.c +1
-28static int __init set_nohugeiomap (char *str) { - ioremap_huge_disabled =1 ; + iomap_max_page_shift =P4D_SHIFT ;return 0 ; }early_param ("nohugeiomap" , set_nohugeiomap); - -void __init ioremap_huge_init (void ) -{ -if (!ioremap_huge_disabled) { -if (arch_ioremap_p4d_supported ()) - ioremap_p4d_capable =1 ; -if (arch_ioremap_pud_supported ()) - ioremap_pud_capable =1 ; -if (arch_ioremap_pmd_supported ()) - ioremap_pmd_capable =1 ; - } -} - -static inline int ioremap_p4d_enabled (void ) -{ -return ioremap_p4d_capable; -} - -static inline int ioremap_pud_enabled (void ) -{ -return ioremap_pud_capable; -} - -static inline int ioremap_pmd_enabled (void ) -{ -return ioremap_pmd_capable; -}
mm/ioremap.c line 31
Quoted 10 lines
mm/ioremap.c +2
-5- -#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ -static inline int ioremap_p4d_enabled (void ) {return 0 ; } -static inline int ioremap_pud_enabled (void ) {return 0 ; } -static inline int ioremap_pmd_enabled (void ) {return 0 ; } +#else /* CONFIG_HAVE_ARCH_HUGE_VMAP */ +static const bool iomap_max_page_shift =PAGE_SHIFT ;#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
Christophe
Re: [PATCH v13 06/14] mm: HUGE_VMAP arch support cleanup
Le 28/04/2021 à 10:32, Christophe Leroy a écrit :
Quoted 41 lines
Le 17/03/2021 à 07:23, Nicholas Piggin a écrit :
Quoted 37 lines
This changes the awkward approach where architectures provide init functions to determine which levels they can provide large mappings for, to one where the arch is queried for each call.
This removes code and indirection, and allows constant-folding of dead code for unsupported levels.
This also adds a prot argument to the arch query. This is unused currently but could help with some architectures (e.g., some powerpc processors can't map uncacheable memory with large pages).
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Reviewed-by Ding Tianhong <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>---
arch/arm64/include/asm/vmalloc.h | 8 ++ arch/arm64/mm/mmu.c | 10 +-- arch/powerpc/include/asm/vmalloc.h | 8 ++arch/powerpc/mm/book3s64/radix_pgtable.c| 8 +- arch/x86/include/asm/vmalloc.h | 7 ++ arch/x86/mm/ioremap.c | 12 +-- include/linux/io.h | 9 --- include/linux/vmalloc.h | 6 ++ init/main.c | 1 - mm/debug_vm_pgtable.c | 4 +- mm/ioremap.c | 94 ++++++++++--------------11 files changed, 87 insertions(+), 80 deletions(-)
Quoted 14 lines
mm/ioremap.c line 18
Quoted 12 lines
mm/ioremap.c +1
-4@@ -16,49 +16,16 @@ #include "pgalloc-track.h" #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static int __read_mostly ioremap_p4d_capable; -static int __read_mostly ioremap_pud_capable; -static int __read_mostly ioremap_pmd_capable; -static int __read_mostly ioremap_huge_disabled; +static bool __ro_after_init iomap_max_page_shift =PAGE_SHIFT ;Must be an int, not a bool.
And the initial value seems wrong. Should be P4D_SHIFT ?
Quoted 5 lines
mm/ioremap.c line 23
Quoted 5 lines
mm/ioremap.c +1
-1static int __init set_nohugeiomap(char *str) { - ioremap_huge_disabled = 1; + iomap_max_page_shift = P4D_SHIFT;
And PAGE_SHIFT here when NO hugeiomap ?
Quoted 3 lines
mm/ioremap.c line 26
Quoted 3 lines
mm/ioremap.c +0
-0return 0; } early_param("nohugeiomap", set_nohugeiomap);
Christophe
Nicholas Piggin
reviewerPATCH v13 7/14 powerpc: inline huge vmap supported functions
In reply to Nicholas PigginThis allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
--- arch/powerpc/include/asm/vmalloc.h | 19 ++++++++++++++++--- arch/powerpc/mm/book3s64/radix_pgtable.c | 21 --------------------- 2 files changed, 16 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/vmalloc.h +16 -3
@@ -1,12 +1,25 @@#ifndef _ASM_POWERPC_VMALLOC_H#define _ASM_POWERPC_VMALLOC_H +#include <asm/mmu.h> #include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +/* HPT does not cope with large pages in the vmalloc area */ +return radix_enabled (); +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return radix_enabled (); +}#endif #endif /* _ASM_POWERPC_VMALLOC_H */
arch/powerpc/mm/book3s64/radix_pgtable.c +0 -21
@@ -1082,22 +1082,6 @@ void radix__ptep_modify_prot_commit(struct vm_area_struct *vma,set_pte_at (mm, addr, ptep, pte); } -bool arch_vmap_pud_supported (pgprot_t prot) -{ -/* HPT does not cope with large pages in the vmalloc area */ -return radix_enabled (); -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -return radix_enabled (); -} - -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ; -} -int pud_set_huge (pud_t *pud,phys_addr_t addr,pgprot_t prot) {pte_t *ptep = (pte_t *)pud;
@@ -1181,8 +1165,3 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)return 1 ; } - -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -}
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 8/14 arm64: inline huge vmap supported functions
In reply to Nicholas PigginThis allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
--- arch/arm64/include/asm/vmalloc.h | 23 ++++++++++++++++++++--- arch/arm64/mm/mmu.c | 26 -------------------------- 2 files changed, 20 insertions(+), 29 deletions(-)
arch/arm64/include/asm/vmalloc.h +20 -3
@@ -4,9 +4,26 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +/* +* Only 4k granule supports level 1 block mappings. +* SW table walks can't handle removal of intermediate entries. +*/ +return IS_ENABLED (CONFIG_ARM64_4K_PAGES ) && + !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +/* See arch_vmap_pud_supported() */ +return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); +}#endif #endif /* _ASM_ARM64_VMALLOC_H */
arch/arm64/mm/mmu.c +0 -26
@@ -1316,27 +1316,6 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)return dt_virt; } -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} - -bool arch_vmap_pud_supported (pgprot_t prot) -{ -/* -* Only 4k granule supports level 1 block mappings. -* SW table walks can't handle removal of intermediate entries. -*/ -return IS_ENABLED (CONFIG_ARM64_4K_PAGES ) && - !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -/* See arch_vmap_pud_supported() */ -return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); -} -int pud_set_huge (pud_t *pudp,phys_addr_t phys,pgprot_t prot) {pud_t new_pud =pfn_pud (__phys_to_pfn (phys),mk_pud_sect_prot (prot));
@@ -1428,11 +1407,6 @@ int pud_free_pmd_page(pud_t *pudp, unsigned long addr)return 1 ; } -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ;/* Don't attempt a block mapping */ -} -#ifdef CONFIG_MEMORY_HOTPLUG static void __remove_pgd_mapping (pgd_t *pgdir,unsigned long start,u64 size) {
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 9/14 x86: inline huge vmap supported functions
In reply to Nicholas PigginThis allows unsupported levels to be constant folded away, and so p4d_free_pud_page can be removed because it's no longer linked to.
--- arch/x86/include/asm/vmalloc.h | 22 +++++++++++++++++++--- arch/x86/mm/ioremap.c | 21 --------------------- arch/x86/mm/pgtable.c | 13 ------------- 3 files changed, 19 insertions(+), 37 deletions(-)
arch/x86/include/asm/vmalloc.h +19 -3
@@ -1,13 +1,29 @@#ifndef _ASM_X86_VMALLOC_H#define _ASM_X86_VMALLOC_H +#include <asm/cpufeature.h> #include <asm/page.h> #include <asm/pgtable_areas.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot); -bool arch_vmap_pud_supported (pgprot_t prot); -bool arch_vmap_pmd_supported (pgprot_t prot); +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} + +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +#ifdef CONFIG_X86_64 +return boot_cpu_has (X86_FEATURE_GBPAGES ); +#else +return false; +#endif +} + +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return boot_cpu_has (X86_FEATURE_PSE ); +}#endif #endif /* _ASM_X86_VMALLOC_H */
arch/x86/mm/ioremap.c +0 -21
@@ -481,27 +481,6 @@ void iounmap(volatile void __iomem *addr) }EXPORT_SYMBOL (iounmap); -#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} - -bool arch_vmap_pud_supported (pgprot_t prot) -{ -#ifdef CONFIG_X86_64 -return boot_cpu_has (X86_FEATURE_GBPAGES ); -#else -return false; -#endif -} - -bool arch_vmap_pmd_supported (pgprot_t prot) -{ -return boot_cpu_has (X86_FEATURE_PSE ); -} -#endif -/* * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access
arch/x86/mm/pgtable.c +0 -13
@@ -780,14 +780,6 @@ int pmd_clear_huge(pmd_t *pmd)return 0 ; } -/* -* Until we support 512GB pages, skip them in the vmap area. -*/ -int p4d_free_pud_page (p4d_t *p4d,unsigned long addr) -{ -return 0 ; -} -#ifdef CONFIG_X86_64 /** * pud_free_pmd_page - Clear pud entry and free pmd page.
@@ -861,11 +853,6 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)#else /* !CONFIG_X86_64 */ -int pud_free_pmd_page (pud_t *pud,unsigned long addr) -{ -return pud_none (*pud); -} -/* * Disable free page handling on x86-PAE. This assures that ioremap() * does not update sync'd pmd entries. See vmalloc_sync_one().
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 10/14 mm/vmalloc: provide fallback arch huge vmap support functions
In reply to Nicholas PigginIf an architecture doesn't support a particular page table level as a huge vmap page size then allow it to skip defining the support query function.
--- arch/arm64/include/asm/vmalloc.h | 7 +++---- arch/powerpc/include/asm/vmalloc.h | 7 +++---- arch/x86/include/asm/vmalloc.h | 13 +++++-------- include/linux/vmalloc.h | 24 ++++++++++++++++++++---- 4 files changed, 31 insertions(+), 20 deletions(-)
arch/arm64/include/asm/vmalloc.h +3 -4
@@ -4,11 +4,8 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) {/*
@@ -19,11 +16,13 @@ static inline bool arch_vmap_pud_supported(pgprot_t prot) !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {/* See arch_vmap_pud_supported() */ return !IS_ENABLED (CONFIG_PTDUMP_DEBUGFS ); } +#endif #endif /* _ASM_ARM64_VMALLOC_H */
arch/powerpc/include/asm/vmalloc.h +3 -4
@@ -5,21 +5,20 @@#include <asm/page.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) {/* HPT does not cope with large pages in the vmalloc area */ return radix_enabled (); } +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {return radix_enabled (); } +#endif #endif /* _ASM_POWERPC_VMALLOC_H */
arch/x86/include/asm/vmalloc.h +5 -8
@@ -6,24 +6,21 @@#include <asm/pgtable_areas.h> #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) -{ -return false; -} +#ifdef CONFIG_X86_64 +#define arch_vmap_pud_supported arch_vmap_pud_supportedstatic inline bool arch_vmap_pud_supported (pgprot_t prot) { -#ifdef CONFIG_X86_64 return boot_cpu_has (X86_FEATURE_GBPAGES ); -#else -return false; -#endif } +#endif +#define arch_vmap_pmd_supported arch_vmap_pmd_supportedstatic inline bool arch_vmap_pmd_supported (pgprot_t prot) {return boot_cpu_has (X86_FEATURE_PSE ); } +#endif #endif /* _ASM_X86_VMALLOC_H */
include/linux/vmalloc.h +20 -4
@@ -78,10 +78,26 @@ struct vmap_area { }; }; -#ifndef CONFIG_HAVE_ARCH_HUGE_VMAP -static inline bool arch_vmap_p4d_supported (pgprot_t prot) {return false; } -static inline bool arch_vmap_pud_supported (pgprot_t prot) {return false; } -static inline bool arch_vmap_pmd_supported (pgprot_t prot) {return false; } +/* archs that select HAVE_ARCH_HUGE_VMAP should override one or more of these */ +#ifndef arch_vmap_p4d_supported +static inline bool arch_vmap_p4d_supported (pgprot_t prot) +{ +return false; +} +#endif + +#ifndef arch_vmap_pud_supported +static inline bool arch_vmap_pud_supported (pgprot_t prot) +{ +return false; +} +#endif + +#ifndef arch_vmap_pmd_supported +static inline bool arch_vmap_pmd_supported (pgprot_t prot) +{ +return false; +}#endif /*
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 11/14 mm: Move vmap_range from mm/ioremap.c to mm/vmalloc.c
In reply to Nicholas PigginThis is a generic kernel virtual memory mapper, not specific to ioremap.
Code is unchanged other than making vmap_range non-static.
--- include/linux/vmalloc.h | 3 + mm/ioremap.c | 203 ---------------------------------------- mm/vmalloc.c | 202 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 203 deletions(-)
include/linux/vmalloc.h +3 -0
@@ -189,6 +189,9 @@ extern struct vm_struct *remove_vm_area(const void *addr);extern struct vm_struct *find_vm_area (const void *addr);#ifdef CONFIG_MMU +int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +unsigned int max_page_shift);extern int map_kernel_range_noflush (unsigned long start,unsigned long size,pgprot_t prot,struct page **pages); int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,
mm/ioremap.c +0 -203
209 lines not on this page · raw message
mm/vmalloc.c +202 -0
208 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 12/14 mm/vmalloc: add vmap_range_noflush variant
In reply to Nicholas PigginAs a side-effect, the order of flush_cache_vmap() and arch_sync_kernel_mappings() calls are switched, but that now matches the other callers in this file.
--- mm/vmalloc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/vmalloc.c +13 -3
@@ -240,7 +240,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,return 0 ; } -int vmap_range (unsigned long addr,unsigned long end, +static int vmap_range_noflush (unsigned long addr,unsigned long end,phys_addr_t phys_addr,pgprot_t prot,unsigned int max_page_shift) {
@@ -263,14 +263,24 @@ int vmap_range(unsigned long addr, unsigned long end,break ; }while (pgd++, phys_addr += (next - addr), addr = next, addr != end); -flush_cache_vmap (start, end); -if (mask &ARCH_PAGE_TABLE_SYNC_MASK )arch_sync_kernel_mappings (start, end);return err; } +int vmap_range (unsigned long addr,unsigned long end, +phys_addr_t phys_addr,pgprot_t prot, +unsigned int max_page_shift) +{ +int err; + + err =vmap_range_noflush (addr, end, phys_addr, prot, max_page_shift); +flush_cache_vmap (addr, end); + +return err; +} +static void vunmap_pte_range (pmd_t *pmd,unsigned long addr,unsigned long end,pgtbl_mod_mask *mask) {
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 13/14 mm/vmalloc: Hugepage vmalloc mappings
In reply to Nicholas PigginSupport huge page vmalloc mappings. Config option HAVE_ARCH_HUGE_VMALLOC enables support on architectures that define HAVE_ARCH_HUGE_VMAP and supports PMD sized vmap mappings.
vmalloc will attempt to allocate PMD-sized pages if allocating PMD size or larger, and fall back to small pages if that was unsuccessful.
Architectures must ensure that any arch specific vmalloc allocations that require PAGE_SIZE mappings (e.g., module allocations vs strict module rwx) use the VM_NOHUGE flag to inhibit larger mappings.
This can result in more internal fragmentation and memory overhead for a given allocation, an option nohugevmalloc is added to disable at boot.
--- arch/Kconfig | 11 ++ include/linux/vmalloc.h | 21 ++++ mm/page_alloc.c | 5 +- mm/vmalloc.c | 216 +++++++++++++++++++++++++++++++--------- 4 files changed, 206 insertions(+), 47 deletions(-)
arch/Kconfig +11 -0
@@ -785,6 +785,17 @@ config HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD config HAVE_ARCH_HUGE_VMAP bool +# +# Archs that select this would be capable of PMD-sized vmaps (i.e., +# arch_vmap_pmd_supported() returns true), and they must make no assumptions +# that vmalloc memory is mapped with PAGE_SIZE ptes. The VM_NO_HUGE_VMAP flag +# can be used to prohibit arch-specific allocations from using hugepages to +# help with this (e.g., modules may require it). +# +config HAVE_ARCH_HUGE_VMALLOC + depends on HAVE_ARCH_HUGE_VMAP + bool + config ARCH_WANT_HUGE_PMD_SHARE bool
include/linux/vmalloc.h +21 -0
@@ -26,6 +26,7 @@ struct notifier_block; /* in notifier.h */#define VM_KASAN 0x00000080/* has allocated kasan shadow memory */ #define VM_FLUSH_RESET_PERMS 0x00000100/* reset direct map and flush TLB on unmap, can't be freed in atomic context */ #define VM_MAP_PUT_PAGES 0x00000200/* put pages and free array in vfree */ +#define VM_NO_HUGE_VMAP 0x00000400/* force PAGE_SIZE pte mapping */ /* * VM_KASAN is used slighly differently depending on CONFIG_KASAN_VMALLOC.
@@ -54,6 +55,9 @@ struct vm_struct {unsigned long size;unsigned long flags;struct page **pages; +#ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC +unsigned int page_order; +#endif unsigned int nr_pages;phys_addr_t phys_addr;const void *caller;
@@ -188,6 +192,22 @@ void free_vm_area(struct vm_struct *area);extern struct vm_struct *remove_vm_area (const void *addr);extern struct vm_struct *find_vm_area (const void *addr); +static inline bool is_vm_area_hugepages (const void *addr) +{ +/* +* This may not 100% tell if the area is mapped with > PAGE_SIZE +* page table entries, if for some reason the architecture indicates +* larger sizes are available but decides not to use them, nothing +* prevents that. This only indicates the size of the physical page +* allocated in the vmalloc layer. +*/ +#ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC +return find_vm_area (addr)->page_order >0 ; +#else +return false; +#endif +} +#ifdef CONFIG_MMU int vmap_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
@@ -205,6 +225,7 @@ static inline void set_vm_flush_reset_perms(void *addr)if (vm) vm->flags |=VM_FLUSH_RESET_PERMS ; } +#else static inline int map_kernel_range_noflush(unsigned long start, unsigned long size,
mm/page_alloc.c +4 -1
@@ -72,6 +72,7 @@#include <linux/padata.h> #include <linux/khugepaged.h> #include <linux/buffer_head.h> +#include <linux/vmalloc.h> #include <asm/sections.h> #include <asm/tlbflush.h>
@@ -8222,6 +8223,7 @@ void *__init alloc_large_system_hash(const char *tablename,void *table =NULL ;gfp_t gfp_flags;bool virt; +bool huge;/* allow the kernel cmdline to have a say */ if (!numentries) {
@@ -8289,6 +8291,7 @@ void *__init alloc_large_system_hash(const char *tablename, }else if (get_order (size) >=MAX_ORDER || hashdist) { table =__vmalloc (size, gfp_flags); virt = true; + huge =is_vm_area_hugepages (table); }else {/* * If bucketsize is not a power-of-two, we may free
@@ -8305,7 +8308,7 @@ void *__init alloc_large_system_hash(const char *tablename,pr_info ("%s hash table entries: %ld (order: %d, %lu bytes, %s)\n" , tablename,1UL << log2qty,ilog2 (size) -PAGE_SHIFT , size, - virt ?"vmalloc" :"linear" ); + virt ? (huge ?"vmalloc hugepage" :"vmalloc" ) :"linear" );if (_hash_shift) *_hash_shift = log2qty;
mm/vmalloc.c +170 -46
334 lines not on this page · raw message
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v13 14/14 powerpc/64s/radix: Enable huge vmalloc mappings
In reply to Nicholas PigginThis reduces TLB misses by nearly 30x on a git diff workload on a 2-node POWER9 (59,800 -> 2,100) and reduces CPU cycles by 0.54%, due to vfs hashes being allocated with 2MB pages.
--- .../admin-guide/kernel-parameters.txt | 2 ++ arch/powerpc/Kconfig | 1 + arch/powerpc/kernel/module.c | 22 +++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -0
@@ -3243,6 +3243,8 @@ nohugeiomap [KNL,X86,PPC,ARM64] Disable kernel huge I/O mappings. + nohugevmalloc [PPC] Disable kernel huge vmalloc mappings. + nosmt [KNL,S390] Disable symmetric multithreading (SMT). Equivalent to smt=1.
arch/powerpc/Kconfig +1 -0
@@ -181,6 +181,7 @@ config PPC select GENERIC_GETTIMEOFDAY select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU + select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KASAN if PPC32 && PPC_PAGE_SHIFT <= 14 select HAVE_ARCH_KASAN_VMALLOC if PPC32 && PPC_PAGE_SHIFT <= 14
arch/powerpc/kernel/module.c +18 -4
@@ -8,6 +8,7 @@#include <linux/moduleloader.h> #include <linux/err.h> #include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/bug.h> #include <asm/module.h> #include <linux/uaccess.h>
@@ -87,13 +88,26 @@ int module_finalize(const Elf_Ehdr *hdr,return 0 ; } -#ifdef MODULES_VADDR void *module_alloc (unsigned long size) { +unsigned long start =VMALLOC_START ; +unsigned long end =VMALLOC_END ; + +#ifdef MODULES_VADDR BUILD_BUG_ON (TASK_SIZE >MODULES_VADDR ); + start =MODULES_VADDR ; + end =MODULES_END ; +#endif + +/* +* Don't do huge page allocations for modules yet until more testing +* is done. STRICT_MODULE_RWX may require extra work to support this +* too. +*/ -return __vmalloc_node_range (size,1 ,MODULES_VADDR ,MODULES_END ,GFP_KERNEL , -PAGE_KERNEL_EXEC ,VM_FLUSH_RESET_PERMS ,NUMA_NO_NODE , +return __vmalloc_node_range (size,1 , start, end,GFP_KERNEL , +PAGE_KERNEL_EXEC , +VM_NO_HUGE_VMAP |VM_FLUSH_RESET_PERMS , +NUMA_NO_NODE ,__builtin_return_address (0 )); } -#endif
Signature · 1 line
2.23.0
Re: [PATCH v13 14/14] powerpc/64s/radix: Enable huge vmalloc mappings
Hi Nick,
Le 17/03/2021 à 07:24, Nicholas Piggin a écrit :
Quoted 37 lines
This reduces TLB misses by nearly 30x on a
git diffworkload on a 2-node POWER9 (59,800 -> 2,100) and reduces CPU cycles by 0.54%, due to vfs hashes being allocated with 2MB pages.Acked-by Michael Ellerman <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>--- .../admin-guide/kernel-parameters.txt | 2 ++ arch/powerpc/Kconfig | 1 + arch/powerpc/kernel/module.c | 22 +++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-)arch/powerpc/kernel/module.c +7
-1@@ -8,6 +8,7 @@#include <linux/moduleloader.h> #include <linux/err.h> #include <linux/vmalloc.h> +#include <linux/mm.h> #include <linux/bug.h> #include <asm/module.h> #include <linux/uaccess.h> @@ -87,13 +88,26 @@ int module_finalize(const Elf_Ehdr *hdr,return 0 ; } -#ifdef MODULES_VADDR void *module_alloc (unsigned long size) { +unsigned long start =VMALLOC_START ; +unsigned long end =VMALLOC_END ; + +#ifdef MODULES_VADDR BUILD_BUG_ON (TASK_SIZE >MODULES_VADDR ); + start =MODULES_VADDR ; + end =MODULES_END ;
arch/powerpc/kernel/module.c int module_finalize(const Elf_Ehdr *hdr, · line 96
Quoted 10 lines
arch/powerpc/kernel/module.c +7
-2+#endif + +/* +* Don't do huge page allocations for modules yet until more testing +* is done. STRICT_MODULE_RWX may require extra work to support this +* too. +*/ - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, - PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,
I think you should add the following in <asm/pgtable.h>
#ifndef MODULES_VADDR
#define MODULES_VADDR VMALLOC_START
#define MODULES_END VMALLOC_END
#endif
And leave module_alloc() as is (just removing the enclosing #ifdef MODULES_VADDR and adding the VM_NO_HUGE_VMAP flag)
This would minimise the conflits with the changes I did in powerpc/next reported by Stephen R.
Quoted 8 lines
arch/powerpc/kernel/module.c +4
-1+return __vmalloc_node_range (size,1 , start, end,GFP_KERNEL , +PAGE_KERNEL_EXEC , +VM_NO_HUGE_VMAP |VM_FLUSH_RESET_PERMS , +NUMA_NO_NODE ,__builtin_return_address (0 )); } -#endif
Andrew Morton
maintainerRe: [PATCH v13 14/14] powerpc/64s/radix: Enable huge vmalloc mappings
Quoted 15 lines · On Thu, 15 Apr 2021 12:23:55 +0200 Christophe Leroy…
arch/powerpc/kernel/module.c int module_finalize(const Elf_Ehdr *hdr, · line 96
Quoted 6 lines
arch/powerpc/kernel/module.c +3
-2+* is done. STRICT_MODULE_RWX may require extra work to support this +* too. +*/ - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, - PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,I think you should add the following in <
asm/pgtable.h>#ifndef
MODULES_VADDR
#defineMODULES_VADDRVMALLOC_START
#defineMODULES_ENDVMALLOC_END
#endif
Quoted 5 lines
And leave
module_alloc()as is (just removing the enclosing #ifdefMODULES_VADDRand adding theVM_NO_HUGE_VMAPflag)This would minimise the conflits with the changes I did in powerpc/next reported by Stephen R.
I'll drop powerpc-64s-radix-enable-huge-vmalloc-mappings.patch for now, make life simpler.
Nick, a redo on top of Christophe's changes in linux-next would be best please.
Re: [PATCH v13 14/14] powerpc/64s/radix: Enable huge vmalloc mappings
Hi all,
Quoted 17 lines · On Thu, 15 Apr 2021 11:55:29 -0700 Andrew Morton <[email protected]>…
Quoted 15 lines · On Thu, 15 Apr 2021 12:23:55 +0200 Christophe Leroy…
arch/powerpc/kernel/module.c int module_finalize(const Elf_Ehdr *hdr, · line 96
Quoted 6 lines
arch/powerpc/kernel/module.c +3
-2+* is done. STRICT_MODULE_RWX may require extra work to support this +* too. +*/ - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, - PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,I think you should add the following in <
asm/pgtable.h>#ifndef
MODULES_VADDR
#defineMODULES_VADDRVMALLOC_START
#defineMODULES_ENDVMALLOC_END
#endif
Quoted 8 lines
Quoted 5 lines
And leave
module_alloc()as is (just removing the enclosing #ifdefMODULES_VADDRand adding theVM_NO_HUGE_VMAPflag)This would minimise the conflits with the changes I did in powerpc/next reported by Stephen R.
I'll drop powerpc-64s-radix-enable-huge-vmalloc-mappings.patch for now, make life simpler.
I have dropped that patch from linux-next.
Signature · 2 lines
Cheers, Stephen Rothwell
Nicholas Piggin
reviewerRe: [PATCH v13 14/14] powerpc/64s/radix: Enable huge vmalloc mappings
In reply to Andrew MortonExcerpts from Andrew Morton's message of April 16, 2021 4:55 am:
Quoted 16 lines · On Thu, 15 Apr 2021 12:23:55 +0200 Christophe Leroy…
Quoted 15 lines
arch/powerpc/kernel/module.c int module_finalize(const Elf_Ehdr *hdr, · line 96
Quoted 6 lines
arch/powerpc/kernel/module.c +3
-2+* is done. STRICT_MODULE_RWX may require extra work to support this +* too. +*/ - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, - PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,I think you should add the following in <
asm/pgtable.h>#ifndef
MODULES_VADDR
#defineMODULES_VADDRVMALLOC_START
#defineMODULES_ENDVMALLOC_END
#endif
Quoted 8 lines
Quoted 5 lines
And leave
module_alloc()as is (just removing the enclosing #ifdefMODULES_VADDRand adding theVM_NO_HUGE_VMAPflag)This would minimise the conflits with the changes I did in powerpc/next reported by Stephen R.
I'll drop powerpc-64s-radix-enable-huge-vmalloc-mappings.patch for now, make life simpler.
Yeah that's fine.
Quoted 2 lines
Nick, a redo on top of Christophe's changes in linux-next would be best please.
Will do.
Thanks,
Nick
Andrew Morton
maintainerQuoted 3 lines · On Wed, 17 Mar 2021 16:23:48 +1000 Nicholas Piggin <[email protected]> wrote:
*** BLURB HERE ***
That's really not what it means ;)
Could we please get a nice description for the [0/n]? What's it all about, what's the benefit, what are potential downsides.
And performance testing results! Because if it ain't faster, there's no point in merging it?
Nicholas Piggin
reviewerExcerpts from Andrew Morton's message of March 18, 2021 8:58 am:
Quoted 7 lines · On Wed, 17 Mar 2021 16:23:48 +1000 Nicholas Piggin <[email protected]> wrote:
Quoted 4 lines
*** BLURB HERE ***
That's really not what it means ;)
Sigh, wasn't having a good yesterday.
Quoted 6 lines
Could we please get a nice description for the [0/n]? What's it all about, what's the benefit, what are potential downsides.
And performance testing results! Because if it ain't faster, there's no point in merging it?
It's supposed to have a bit of description in patch 13, and has some performance reuslts in patch 14. Is it better to put a bigger writeup in 0? I thought that tends to get lost.
I'll write something here to discuss for now, and can fit it into the appropriate place in the series after that.
The kernel virtual mapping layer grew support for mapping memory with > PAGE_SIZE ptes with 0ddab1d2ed664 ("lib/ioremap.c: add huge I/O map capability interfaces"), and implemented support for using those huge page mappings with ioremap.
According to the submission, the use-case is mapping very large non-volatile memory devices, which could be GB or TB.
https://lore.kernel.org/lkml/[email protected]/
The benefit is said to be in the overhead of maintaining the mapping, perhaps both in memory overhead and setup / teardown time. Memory overhead for the mapping with a 4kB page and 8 byte page table is 2GB per TB of mapping, down to 4MB / TB with 2MB pages.
The same huge page vmap infrastructure can be quite easily adapted and used for mapping vmalloc memory pages without more complexity for arch or core vmap code. However unlike ioremap, vmalloc page table overhead is not a real problem, so the advantage to justify this is performance.
Several of the most structures in the kernel (e.g., vfs and network hash tables) are allocated with vmalloc on NUMA machines, in order to distribute access bandwidth over the machine. Mapping these with larger pages can improve TLB usage significantly, for example this reduces TLB misses by nearly 30x on a git diff workload on a 2-node POWER9 (59,800 -> 2,100) and reduces CPU cycles by 0.54%, due to vfs hashes being allocated with 2MB pages.
[ Other numbers?
- The difference is even larger in a guest due to more costly TLB misses.
- Eric Dumazet was keen on the network hash performance possibilities.
- Other archs? Ding was doing x86 testing. ]
The kernel module allocator also uses vmalloc to map module images even on non-NUMA, which can result in high iTLB pressure on highly modular distro type of kernels. This series does not implement huge mappings for modules yet, but it's a step along the way. Rick Edgecombe was looking at that IIRC.
The per-cpu allocator similarly might be able to take advantage of this. Also on the todo list.
The disadvantages of this I can see are:
* Memory fragmentation can waste some physical memory because it will attempt to allocate larger pages to fit the required size, rounding up (once the requested size is >= 2MB).
- I don't see it being a big problem in practice unless some user crops up that allocates thousands of 2.5MB ranges. We can tewak heuristics a bit there if needed to reduce peak waste.
* Less granular mappings can make the NUMA distribution less balanced.
- Similar to the above.
- Could also allocate all major system hashes with one allocation up-front and spread them all across the one block, which should help overall NUMA distribution and reduce fragmentation waste.
* Callers might expect something about the underlying allocated pages.
- Tried to keep the apperance of base PAGE_SIZE pages throughout the APIs and exposed data structures.
- Added a VM_NO_HUGE_VMAP flag to hammer troublesome cases with.
- Finally, added a nohugevmalloc boot option to turn it off (independent of nohugeiomap).
Is that helpful?
Thanks,
Nick