Skip to content

Commit 723f268

Browse files
chleroympe
authored andcommitted
powerpc/mm: cleanup ifdef mess in add_huge_page_size()
Introduce a subarch specific helper check_and_get_huge_psize() to check the huge page sizes and cleanup the ifdef mess in add_huge_page_size() Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 5fb84fe commit 723f268

File tree

4 files changed

+43
-34
lines changed

4 files changed

+43
-34
lines changed

arch/powerpc/include/asm/book3s/64/hugetlb.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,31 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi
107107

108108
void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
109109

110+
static inline int check_and_get_huge_psize(int shift)
111+
{
112+
int mmu_psize;
113+
114+
if (shift > SLICE_HIGH_SHIFT)
115+
return -EINVAL;
116+
117+
mmu_psize = shift_to_mmu_psize(shift);
118+
119+
/*
120+
* We need to make sure that for different page sizes reported by
121+
* firmware we only add hugetlb support for page sizes that can be
122+
* supported by linux page table layout.
123+
* For now we have
124+
* Radix: 2M and 1G
125+
* Hash: 16M and 16G
126+
*/
127+
if (radix_enabled()) {
128+
if (mmu_psize != MMU_PAGE_2M && mmu_psize != MMU_PAGE_1G)
129+
return -EINVAL;
130+
} else {
131+
if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G)
132+
return -EINVAL;
133+
}
134+
return mmu_psize;
135+
}
136+
110137
#endif

arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi
3636
(pshift == PAGE_SHIFT_8M ? _PMD_PAGE_8M : _PMD_PAGE_512K));
3737
}
3838

39+
static inline int check_and_get_huge_psize(int shift)
40+
{
41+
return shift_to_mmu_psize(shift);
42+
}
43+
3944
#endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */

arch/powerpc/include/asm/nohash/hugetlb-book3e.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshi
3434
*hpdp = __hugepd(((unsigned long)new & ~PD_HUGE) | pshift);
3535
}
3636

37+
static inline int check_and_get_huge_psize(int shift)
38+
{
39+
if (shift & 1) /* Not a power of 4 */
40+
return -EINVAL;
41+
42+
return shift_to_mmu_psize(shift);
43+
}
44+
3745
#endif /* _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H */

arch/powerpc/mm/hugetlbpage.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -549,51 +549,20 @@ unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
549549
return vma_kernel_pagesize(vma);
550550
}
551551

552-
static inline bool is_power_of_4(unsigned long x)
553-
{
554-
if (is_power_of_2(x))
555-
return (__ilog2(x) % 2) ? false : true;
556-
return false;
557-
}
558-
559552
static int __init add_huge_page_size(unsigned long long size)
560553
{
561554
int shift = __ffs(size);
562555
int mmu_psize;
563556

564557
/* Check that it is a page size supported by the hardware and
565558
* that it fits within pagetable and slice limits. */
566-
if (size <= PAGE_SIZE)
567-
return -EINVAL;
568-
#if defined(CONFIG_PPC_FSL_BOOK3E)
569-
if (!is_power_of_4(size))
559+
if (size <= PAGE_SIZE || !is_power_of_2(size))
570560
return -EINVAL;
571-
#elif !defined(CONFIG_PPC_8xx)
572-
if (!is_power_of_2(size) || (shift > SLICE_HIGH_SHIFT))
573-
return -EINVAL;
574-
#endif
575561

576-
if ((mmu_psize = shift_to_mmu_psize(shift)) < 0)
562+
mmu_psize = check_and_get_huge_psize(size);
563+
if (mmu_psize < 0)
577564
return -EINVAL;
578565

579-
#ifdef CONFIG_PPC_BOOK3S_64
580-
/*
581-
* We need to make sure that for different page sizes reported by
582-
* firmware we only add hugetlb support for page sizes that can be
583-
* supported by linux page table layout.
584-
* For now we have
585-
* Radix: 2M and 1G
586-
* Hash: 16M and 16G
587-
*/
588-
if (radix_enabled()) {
589-
if (mmu_psize != MMU_PAGE_2M && mmu_psize != MMU_PAGE_1G)
590-
return -EINVAL;
591-
} else {
592-
if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G)
593-
return -EINVAL;
594-
}
595-
#endif
596-
597566
BUG_ON(mmu_psize_defs[mmu_psize].shift != shift);
598567

599568
/* Return if huge page size has already been setup */

0 commit comments

Comments
 (0)