mm/page_alloc: Ensure that HUGETLB_PAGE_ORDER is less than MAX_ORDER
Subsystems (2)
PATCH 1/1 mm/page_alloc: Ensure that HUGETLB_PAGE_ORDER is less than MAX_ORDER
pageblock_order must always be less than MAX_ORDER, otherwise it might lead to an warning during boot. A similar problem got fixed on arm64 platform with the commit 79cc2ed5a716 ("arm64/mm: Drop THP conditionality from FORCE_MAX_ZONEORDER"). Assert the above condition before HUGETLB_PAGE_ORDER gets assigned as pageblock_order. This will help detect the problem earlier on platforms where HUGETLB_PAGE_SIZE_VARIABLE is enabled.
--- mm/page_alloc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/page_alloc.c +9 -2
@@ -7068,10 +7068,17 @@ void __init set_pageblock_order(void)if (pageblock_order)return ; -if (HPAGE_SHIFT >PAGE_SHIFT ) +if (HPAGE_SHIFT >PAGE_SHIFT ) { +/* +* pageblock_order must always be less than +* MAX_ORDER. So does HUGETLB_PAGE_ORDER if +* that is being assigned here. +*/ +WARN_ON (HUGETLB_PAGE_ORDER >=MAX_ORDER ); order =HUGETLB_PAGE_ORDER ; -else + }else { order =MAX_ORDER -1 ; + }/* * Assume the largest contiguous order of interest is a huge page.
Signature · 1 line
2.20.1
Quoted 21 lines · Anshuman Khandual
pageblock_ordermust always be less thanMAX_ORDER, otherwise it might lead to an warning during boot. A similar problem got fixed on arm64 platform with the commit79cc2ed5a716("arm64/mm: Drop THP conditionality fromFORCE_MAX_ZONEORDER"). Assert the above condition beforeHUGETLB_PAGE_ORDERgets assigned aspageblock_order. This will help detect the problem earlier on platforms whereHUGETLB_PAGE_SIZE_VARIABLEis enabled.Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>--- mm/page_alloc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)mm/page_alloc.c +0
-0@@ -7068,10 +7068,17 @@ void __init set_pageblock_order(void)if (pageblock_order)
mm/page_alloc.c void __init set_pageblock_order(void) · line 7077
Quoted 10 lines
mm/page_alloc.c +7
-1return ; -if (HPAGE_SHIFT >PAGE_SHIFT ) +if (HPAGE_SHIFT >PAGE_SHIFT ) { +/* +* pageblock_order must always be less than +* MAX_ORDER. So does HUGETLB_PAGE_ORDER if +* that is being assigned here. +*/ +WARN_ON (HUGETLB_PAGE_ORDER >=MAX_ORDER );
Can't that be a BUILD_BUG_ON() ?
Quoted 9 lines
mm/page_alloc.c +2
-1order =HUGETLB_PAGE_ORDER ; - else + }else { order =MAX_ORDER -1 ; + }/* * Assume the largest contiguous order of interest is a huge page.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 25 lines · David Hildenbrand
Quoted 24 lines · Anshuman Khandual
pageblock_ordermust always be less thanMAX_ORDER, otherwise it might lead to an warning during boot. A similar problem got fixed on arm64 platform with the commit79cc2ed5a716("arm64/mm: Drop THP conditionality fromFORCE_MAX_ZONEORDER"). Assert the above condition beforeHUGETLB_PAGE_ORDERgets assigned aspageblock_order. This will help detect the problem earlier on platforms whereHUGETLB_PAGE_SIZE_VARIABLEis enabled.Cc Andrew Morton <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>---
mm/page_alloc.c| 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)mm/page_alloc.c +1
-0@@ -7068,10 +7068,17 @@ void __init set_pageblock_order(void) if (pageblock_order) return; - if (HPAGE_SHIFT > PAGE_SHIFT) + if (HPAGE_SHIFT > PAGE_SHIFT) {
Quoted 8 lines
mm/page_alloc.c void __init set_pageblock_order(void) · line 7077
Quoted 6 lines
mm/page_alloc.c +6
-0+ /* + * pageblock_order must always be less than + * MAX_ORDER. So does HUGETLB_PAGE_ORDER if + * that is being assigned here. + */ + WARN_ON(HUGETLB_PAGE_ORDER >= MAX_ORDER);Can't that be a
BUILD_BUG_ON()?
Yes, it can be. Probably might be appropriate as well, given that both the arguments here are compile time constants. Okay, will change.
Quoted 11 lines
Quoted 9 lines
mm/page_alloc.c +2
-1order = HUGETLB_PAGE_ORDER; - else + } else { order = MAX_ORDER - 1; + } /** Assume the largest contiguous order of interest is a huge page.