]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
arm64/mm: Ensure adequate HUGE_MAX_HSTATE
authorAnshuman Khandual <anshuman.khandual@arm.com>
Mon, 2 Dec 2024 06:44:07 +0000 (12:14 +0530)
committerWill Deacon <will@kernel.org>
Tue, 10 Dec 2024 11:34:25 +0000 (11:34 +0000)
This asserts that HUGE_MAX_HSTATE is sufficient enough preventing potential
hugetlb_max_hstate runtime overflow in hugetlb_add_hstate() thus triggering
a BUG_ON() there after.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Link: https://lore.kernel.org/r/20241202064407.53807-1-anshuman.khandual@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/mm/hugetlbpage.c

index 3215adf48a1b6c7a68f48b61bd2dbc21cd917450..98a2a0e64e255864334302372ff4068bd5ec1f97 100644 (file)
@@ -519,6 +519,18 @@ pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 
 static int __init hugetlbpage_init(void)
 {
+       /*
+        * HugeTLB pages are supported on maximum four page table
+        * levels (PUD, CONT PMD, PMD, CONT PTE) for a given base
+        * page size, corresponding to hugetlb_add_hstate() calls
+        * here.
+        *
+        * HUGE_MAX_HSTATE should at least match maximum supported
+        * HugeTLB page sizes on the platform. Any new addition to
+        * supported HugeTLB page sizes will also require changing
+        * HUGE_MAX_HSTATE as well.
+        */
+       BUILD_BUG_ON(HUGE_MAX_HSTATE < 4);
        if (pud_sect_supported())
                hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);