Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Christophe Leroy and committed by
Michael Ellerman
723f268f 5fb84fec

+44 -35
+27
arch/powerpc/include/asm/book3s/64/hugetlb.h
··· 107 107 108 108 void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr); 109 109 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 + 110 137 #endif
+5
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h
··· 36 36 (pshift == PAGE_SHIFT_8M ? _PMD_PAGE_8M : _PMD_PAGE_512K)); 37 37 } 38 38 39 + static inline int check_and_get_huge_psize(int shift) 40 + { 41 + return shift_to_mmu_psize(shift); 42 + } 43 + 39 44 #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */
+8
arch/powerpc/include/asm/nohash/hugetlb-book3e.h
··· 34 34 *hpdp = __hugepd(((unsigned long)new & ~PD_HUGE) | pshift); 35 35 } 36 36 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 + 37 45 #endif /* _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H */
+4 -35
arch/powerpc/mm/hugetlbpage.c
··· 549 549 return vma_kernel_pagesize(vma); 550 550 } 551 551 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 - 559 552 static int __init add_huge_page_size(unsigned long long size) 560 553 { 561 554 int shift = __ffs(size); ··· 556 563 557 564 /* Check that it is a page size supported by the hardware and 558 565 * that it fits within pagetable and slice limits. */ 559 - if (size <= PAGE_SIZE) 560 - return -EINVAL; 561 - #if defined(CONFIG_PPC_FSL_BOOK3E) 562 - if (!is_power_of_4(size)) 563 - return -EINVAL; 564 - #elif !defined(CONFIG_PPC_8xx) 565 - if (!is_power_of_2(size) || (shift > SLICE_HIGH_SHIFT)) 566 - return -EINVAL; 567 - #endif 568 - 569 - if ((mmu_psize = shift_to_mmu_psize(shift)) < 0) 566 + if (size <= PAGE_SIZE || !is_power_of_2(size)) 570 567 return -EINVAL; 571 568 572 - #ifdef CONFIG_PPC_BOOK3S_64 573 - /* 574 - * We need to make sure that for different page sizes reported by 575 - * firmware we only add hugetlb support for page sizes that can be 576 - * supported by linux page table layout. 577 - * For now we have 578 - * Radix: 2M and 1G 579 - * Hash: 16M and 16G 580 - */ 581 - if (radix_enabled()) { 582 - if (mmu_psize != MMU_PAGE_2M && mmu_psize != MMU_PAGE_1G) 583 - return -EINVAL; 584 - } else { 585 - if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G) 586 - return -EINVAL; 587 - } 588 - #endif 569 + mmu_psize = check_and_get_huge_psize(size); 570 + if (mmu_psize < 0) 571 + return -EINVAL; 589 572 590 573 BUG_ON(mmu_psize_defs[mmu_psize].shift != shift); 591 574