Skip to content

Commit f8b46c4

Browse files
Anshuman Khandualwilldeacon
authored andcommitted
arm64/mm: Add pud_sect_supported()
Section mapping at PUD level is supported only on 4K pages and currently it gets verified with explicit #ifdef or IS_ENABLED() constructs. This adds a new helper pud_sect_supported() for this purpose, which particularly cleans up the HugeTLB code path. It updates relevant switch statements with checks for __PAGETABLE_PMD_FOLDED in order to avoid build failures caused with two identical switch case values in those code blocks. Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Suggested-by: Mark Rutland <[email protected]> Signed-off-by: Anshuman Khandual <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent e63cf61 commit f8b46c4

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,11 @@ static inline pgprot_t arch_filter_pgprot(pgprot_t prot)
10221022
return PAGE_READONLY_EXEC;
10231023
}
10241024

1025+
static inline bool pud_sect_supported(void)
1026+
{
1027+
return PAGE_SIZE == SZ_4K;
1028+
}
1029+
10251030

10261031
#endif /* !__ASSEMBLY__ */
10271032

arch/arm64/include/asm/vmalloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#define _ASM_ARM64_VMALLOC_H
33

44
#include <asm/page.h>
5+
#include <asm/pgtable.h>
56

67
#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
78

89
#define arch_vmap_pud_supported arch_vmap_pud_supported
910
static inline bool arch_vmap_pud_supported(pgprot_t prot)
1011
{
1112
/*
12-
* Only 4k granule supports level 1 block mappings.
1313
* SW table walks can't handle removal of intermediate entries.
1414
*/
15-
return IS_ENABLED(CONFIG_ARM64_4K_PAGES) &&
15+
return pud_sect_supported() &&
1616
!IS_ENABLED(CONFIG_PTDUMP_DEBUGFS);
1717
}
1818

arch/arm64/mm/hugetlbpage.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ void __init arm64_hugetlb_cma_reserve(void)
4040
{
4141
int order;
4242

43-
#ifdef CONFIG_ARM64_4K_PAGES
44-
order = PUD_SHIFT - PAGE_SHIFT;
45-
#else
46-
order = CONT_PMD_SHIFT + PMD_SHIFT - PAGE_SHIFT;
47-
#endif
43+
if (pud_sect_supported())
44+
order = PUD_SHIFT - PAGE_SHIFT;
45+
else
46+
order = CONT_PMD_SHIFT + PMD_SHIFT - PAGE_SHIFT;
4847
/*
4948
* HugeTLB CMA reservation is required for gigantic
5049
* huge pages which could not be allocated via the
@@ -62,8 +61,9 @@ bool arch_hugetlb_migration_supported(struct hstate *h)
6261
size_t pagesize = huge_page_size(h);
6362

6463
switch (pagesize) {
65-
#ifdef CONFIG_ARM64_4K_PAGES
64+
#ifndef __PAGETABLE_PMD_FOLDED
6665
case PUD_SIZE:
66+
return pud_sect_supported();
6767
#endif
6868
case PMD_SIZE:
6969
case CONT_PMD_SIZE:
@@ -126,8 +126,11 @@ static inline int num_contig_ptes(unsigned long size, size_t *pgsize)
126126
*pgsize = size;
127127

128128
switch (size) {
129-
#ifdef CONFIG_ARM64_4K_PAGES
129+
#ifndef __PAGETABLE_PMD_FOLDED
130130
case PUD_SIZE:
131+
if (pud_sect_supported())
132+
contig_ptes = 1;
133+
break;
131134
#endif
132135
case PMD_SIZE:
133136
contig_ptes = 1;
@@ -489,9 +492,9 @@ void huge_ptep_clear_flush(struct vm_area_struct *vma,
489492

490493
static int __init hugetlbpage_init(void)
491494
{
492-
#ifdef CONFIG_ARM64_4K_PAGES
493-
hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
494-
#endif
495+
if (pud_sect_supported())
496+
hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
497+
495498
hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
496499
hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
497500
hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
@@ -503,8 +506,9 @@ arch_initcall(hugetlbpage_init);
503506
bool __init arch_hugetlb_valid_size(unsigned long size)
504507
{
505508
switch (size) {
506-
#ifdef CONFIG_ARM64_4K_PAGES
509+
#ifndef __PAGETABLE_PMD_FOLDED
507510
case PUD_SIZE:
511+
return pud_sect_supported();
508512
#endif
509513
case CONT_PMD_SIZE:
510514
case PMD_SIZE:

0 commit comments

Comments
 (0)