Skip to contentSkip to conversation

arm64/mm: Ensure adequate HUGE_MAX_HSTATE

PATCH Applied Anshuman Khandual 4 participants 4 messages Dec 2, 2024 – Dec 10, 2024 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Mark Rutland <[email protected]>

---
This patch applies on v6.13-rc1

 arch/arm64/mm/hugetlbpage.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/mm/hugetlbpage.c +12 -0
index 3215adf48a1b..98a2a0e64e25 100644
@@ -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);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Anshuman Khandual

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 <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Mark Rutland <[email protected]>

---
This patch applies on v6.13-rc1

 arch/arm64/mm/hugetlbpage.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/mm/hugetlbpage.c +2 -0
index 3215adf48a1b..98a2a0e64e25 100644
@@ -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

arch/arm64/mm/hugetlbpage.c pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, · line 533

Quoted 10 lines
arch/arm64/mm/hugetlbpage.c +10 -0
+	 * 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);

I guess we only technically need 3 if pud_sect_supported() == false ? Although for simplicity (and to reduce my rebasing effort for boot-time page size :) ), agree we should always just compare to 4.

Quoted 3 lines
arch/arm64/mm/hugetlbpage.c +0 -0
 	if (pud_sect_supported())
 		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Anshuman Khandual
Quoted 12 lines · Anshuman Khandual

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 <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Mark Rutland <[email protected]>
Quoted 6 lines

---
This patch applies on v6.13-rc1

  arch/arm64/mm/hugetlbpage.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
maintainer Applied
#3 lore raw
In reply to Anshuman Khandual
Quoted 5 lines · Anshuman Khandual

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.

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64/mm: Ensure adequate HUGE_MAX_HSTATE

      https://git.kernel.org/arm64/c/1e5823c8e86d

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev