Skip to content

Commit 1e5823c

Browse files
Anshuman Khandualwilldeacon
authored andcommitted
arm64/mm: Ensure adequate HUGE_MAX_HSTATE
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>
1 parent a0e33f5 commit 1e5823c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/arm64/mm/hugetlbpage.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
519519

520520
static int __init hugetlbpage_init(void)
521521
{
522+
/*
523+
* HugeTLB pages are supported on maximum four page table
524+
* levels (PUD, CONT PMD, PMD, CONT PTE) for a given base
525+
* page size, corresponding to hugetlb_add_hstate() calls
526+
* here.
527+
*
528+
* HUGE_MAX_HSTATE should at least match maximum supported
529+
* HugeTLB page sizes on the platform. Any new addition to
530+
* supported HugeTLB page sizes will also require changing
531+
* HUGE_MAX_HSTATE as well.
532+
*/
533+
BUILD_BUG_ON(HUGE_MAX_HSTATE < 4);
522534
if (pud_sect_supported())
523535
hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
524536

0 commit comments

Comments
 (0)