powerpc/mm/hugetlb: Filter out hugepage size not supported by page table layout
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Tue, 21 Mar 2017 17:29:56 +0000 (22:59 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 31 Mar 2017 12:09:50 +0000 (23:09 +1100)
Without this if firmware reports 1MB page size support we will crash
trying to use 1MB as hugetlb page size.

echo 300 > /sys/kernel/mm/hugepages/hugepages-1024kB/nr_hugepages

kernel BUG at ./arch/powerpc/include/asm/hugetlb.h:19!
.....
....
[c0000000e2c27b30c00000000029dae8 .hugetlb_fault+0x638/0xda0
[c0000000e2c27c30c00000000026fb64 .handle_mm_fault+0x844/0x1d70
[c0000000e2c27d70c00000000004805c .do_page_fault+0x3dc/0x7c0
[c0000000e2c27e30c00000000000ac98 handle_page_fault+0x10/0x30

With fix, we don't enable 1MB as hugepage size.

bash-4.2# cd /sys/kernel/mm/hugepages/
bash-4.2# ls
hugepages-16384kB  hugepages-16777216kB

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/hugetlbpage.c

index 8c3389cbcd12216ef7b71884163322255f76ea68..a4f33de4008eeed9829eb1ceef01e72d7cedfd8f 100644 (file)
@@ -753,6 +753,24 @@ static int __init add_huge_page_size(unsigned long long size)
        if ((mmu_psize = shift_to_mmu_psize(shift)) < 0)
                return -EINVAL;
 
+#ifdef CONFIG_PPC_BOOK3S_64
+       /*
+        * We need to make sure that for different page sizes reported by
+        * firmware we only add hugetlb support for page sizes that can be
+        * supported by linux page table layout.
+        * For now we have
+        * Radix: 2M
+        * Hash: 16M and 16G
+        */
+       if (radix_enabled()) {
+               if (mmu_psize != MMU_PAGE_2M)
+                       return -EINVAL;
+       } else {
+               if (mmu_psize != MMU_PAGE_16M && mmu_psize != MMU_PAGE_16G)
+                       return -EINVAL;
+       }
+#endif
+
        BUG_ON(mmu_psize_defs[mmu_psize].shift != shift);
 
        /* Return if huge page size has already been setup */