mm: fix MAX_FOLIO_ORDER on powerpc configs with hugetlb
Subsystems (3)
David Hildenbrand (Red Hat)
maintainerPATCH v2 1/1 mm: fix MAX_FOLIO_ORDER on powerpc configs with hugetlb
In the past, CONFIG_ARCH_HAS_GIGANTIC_PAGE indicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.
In commit fae7d834c43c ("mm: add __dump_folio()") we started using CONFIG_ARCH_HAS_GIGANTIC_PAGE to decide MAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started using MAX_FOLIO_ORDER to detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.
In commit 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we used MAX_FOLIO_ORDER to detect inconsistencies, and in fact, we found some now.
Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set CONFIG_ARCH_HAS_GIGANTIC_PAGE and can exceed PUD_ORDER.
To fix it, let's make powerpc select CONFIG_ARCH_HAS_GIGANTIC_PAGE with hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting of CONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in __dump_folio() and inconsistencies around the expected largest folio in the system.
Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.
Add a new Kconfig option HAVE_GIGANTIC_FOLIOS to make both cases clearer. In particular, worry about ARCH_HAS_GIGANTIC_PAGE only with HUGETLB_PAGE.
Note: with enabling CONFIG_ARCH_HAS_GIGANTIC_PAGE on powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't seem critical enough to mark it as a fix.
---
v1 -> v2:
* Adjust patch description (typo, 16G vs 1G)
* Remove ARCH_HAS_GIGANTIC_PAGE from arch/powerpc/platforms/Kconfig.cputype
* Mention CONFIG_HAVE_GIGANTIC_FOLIOS in comment
* Use 1 GiB on 32bit to avoid unsigned-long capacity issues
I yet have to boot-test this on 32bit powerpc. Something for Monday.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/platforms/Kconfig.cputype | 1 - include/linux/mm.h | 13 ++++++++++--- mm/Kconfig | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKS
arch/powerpc/platforms/Kconfig.cputype +0 -1
@@ -423,7 +423,6 @@ config PPC_64S_HASH_MMU config PPC_RADIX_MMU bool "Radix MMU Support" depends on PPC_BOOK3S_64 - select ARCH_HAS_GIGANTIC_PAGE default y help Enable support for the Power ISA 3.0 Radix style MMU. Currently this
include/linux/mm.h +10 -3
@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections).
@@ -2087,10 +2087,17 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect +* no folios larger than 16 GiB on 64bit and 1 GiB on 32bit. +*/ +#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G) +#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif
mm/Kconfig +7 -0
@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE +# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) + # TODO: Allow to be enabled without THP config ARCH_SUPPORTS_HUGE_PFNMAP def_bool n
base-commit: 6146a0f1dfae5d37442a9ddcba012add260bceb0
Signature · 1 line
2.51.0
Le 14/11/2025 à 22:49, David Hildenbrand (Red Hat) a écrit :
Quoted 37 lines
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.
Quoted 8 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.
Tested on powerpc 8xx with CONFIG_ARCH_FORCE_MAX_ORDER=8 instead of 9. It is now possible to add hugepages with the following command:
echo 4 > /sys/kernel/mm/hugepages/hugepages-8192kB/nr_hugepages
But only if CONFIG_CMA is set.
Quoted 119 lines
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't seem critical enough to mark it as a fix.
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc Nathan Chancellor <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>---
v1 -> v2:
* Adjust patch description (typo, 16G vs 1G)
* RemoveARCH_HAS_GIGANTIC_PAGEfromarch/powerpc/platforms/Kconfig.cputype
* MentionCONFIG_HAVE_GIGANTIC_FOLIOSin comment
* Use 1 GiB on 32bit to avoid unsigned-long capacity issuesI yet have to boot-test this on 32bit powerpc. Something for Monday.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/platforms/Kconfig.cputype | 1 - include/linux/mm.h | 13 ++++++++++--- mm/Kconfig | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-)arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKSarch/powerpc/platforms/Kconfig.cputype +0
-1@@ -423,7 +423,6 @@ config PPC_64S_HASH_MMU config PPC_RADIX_MMU bool "Radix MMU Support" depends on PPC_BOOK3S_64 - select ARCH_HAS_GIGANTIC_PAGE default y help Enable support for the Power ISA 3.0 Radix style MMU. Currently thisinclude/linux/mm.h +10
-3@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections). @@ -2087,10 +2087,17 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect +* no folios larger than 16 GiB on 64bit and 1 GiB on 32bit. +*/ +#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G) +#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif mm/Kconfig +7
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE +# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) + # TODO: Allow to be enabled without THP config ARCH_SUPPORTS_HUGE_PFNMAP def_bool nbase-commit:
6146a0f1dfae5d37442a9ddcba012add260bceb0
Quoted 51 lines · Christophe Leroy
Le 14/11/2025 à 22:49, David Hildenbrand (Red Hat) a écrit :
Quoted 37 lines
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Quoted 8 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.Reviewed-by Christophe Leroy <[email protected]>
Quoted 9 lines
Tested on powerpc 8xx with
CONFIG_ARCH_FORCE_MAX_ORDER=8instead of 9. It is now possible to add hugepages with the following command:echo 4 >
/sys/kernel/mm/hugepages/hugepages-8192kB/nr_hugepagesBut only if
CONFIG_CMAis set.Tested-by Christophe Leroy <[email protected]>
Andrew,
can you please take this fix via mm tree
Maddy
Quoted 118 lines
Quoted 117 lines
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't seem critical enough to mark it as a fix.
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc Nathan Chancellor <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>---
v1 -> v2:
* Adjust patch description (typo, 16G vs 1G)
* RemoveARCH_HAS_GIGANTIC_PAGEfromarch/powerpc/platforms/Kconfig.cputype
* MentionCONFIG_HAVE_GIGANTIC_FOLIOSin comment
* Use 1 GiB on 32bit to avoid unsigned-long capacity issuesI yet have to boot-test this on 32bit powerpc. Something for Monday.
---
arch/powerpc/Kconfig | 1 +arch/powerpc/platforms/Kconfig.cputype| 1 - include/linux/mm.h | 13 ++++++++++--- mm/Kconfig | 7 +++++++4 files changed, 18 insertions(+), 4 deletions(-)arch/powerpc/Kconfig +0
-0@@ -137,6 +137,7 @@ config PPCselect ARCH_HAS_DMA_OPS if PPC64
selectARCH_HAS_FORTIFY_SOURCE
selectARCH_HAS_GCOV_PROFILE_ALL
+ select ARCH_HAS_GIGANTIC_PAGE ifARCH_SUPPORTS_HUGETLBFSselectARCH_HAS_KCOV
select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 &&PPC_FPUselectARCH_HAS_MEMBARRIER_CALLBACKSarch/powerpc/platforms/Kconfig.cputype +0
-0@@ -423,7 +423,6 @@ config PPC_64S_HASH_MMUconfig
PPC_RADIX_MMU
bool "Radix MMU Support"
depends onPPC_BOOK3S_64
- selectARCH_HAS_GIGANTIC_PAGE
default y
help
Enable support for the Power ISA 3.0 Radix style MMU. Currently thisinclude/linux/mm.h +10
-2@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio) return folio_large_nr_pages(folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS ) /** We don't expect any folios that exceed buddy sizes (and consequently * memory sections). @@ -2087,10 +2087,17 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE ) /** There is no real limit on the folio size. We limit them to the maximum we - * currently expect (e.g., hugetlb, dax). +* currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect +* no folios larger than 16 GiB on 64bit and 1 GiB on 32bit. +*/ +#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G) +#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER #endifmm/Kconfig +0
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNTconfig
PGTABLE_HAS_HUGE_LEAVES
def_boolTRANSPARENT_HUGEPAGE||HUGETLB_PAGE+#mm/Kconfig +6
-0+# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) +# TODO: Allow to be enabled without THP
configARCH_SUPPORTS_HUGE_PFNMAP
def_boolnbase-commit:
6146a0f1dfae5d37442a9ddcba012add260bceb0
Quoted 62 lines · David Hildenbrand (Red Hat)
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't seem critical enough to mark it as a fix.
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>
Quoted 8 lines
Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc Nathan Chancellor <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>
LGTM from a general point of view, obviously dependent on PPC guys confirming in general :) So:
Quoted 97 lines
---
v1 -> v2:
* Adjust patch description (typo, 16G vs 1G)
* RemoveARCH_HAS_GIGANTIC_PAGEfromarch/powerpc/platforms/Kconfig.cputype
* MentionCONFIG_HAVE_GIGANTIC_FOLIOSin comment
* Use 1 GiB on 32bit to avoid unsigned-long capacity issuesI yet have to boot-test this on 32bit powerpc. Something for Monday.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/platforms/Kconfig.cputype | 1 - include/linux/mm.h | 13 ++++++++++--- mm/Kconfig | 7 +++++++ 4 files changed, 18 insertions(+), 4 deletions(-)arch/powerpc/Kconfig +1
-0@@ -137,6 +137,7 @@ config PPC select ARCH_HAS_DMA_OPS if PPC64 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS select ARCH_HAS_KCOV select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU select ARCH_HAS_MEMBARRIER_CALLBACKSarch/powerpc/platforms/Kconfig.cputype +0
-1@@ -423,7 +423,6 @@ config PPC_64S_HASH_MMU config PPC_RADIX_MMU bool "Radix MMU Support" depends on PPC_BOOK3S_64 - select ARCH_HAS_GIGANTIC_PAGE default y help Enable support for the Power ISA 3.0 Radix style MMU. Currently thisinclude/linux/mm.h +10
-3@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)return folio_large_nr_pages (folio); } -#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE ) +#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS )/* * We don't expect any folios that exceed buddy sizes (and consequently * memory sections). @@ -2087,10 +2087,17 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)* pages are guaranteed to be contiguous. */ #define MAX_FOLIO_ORDER PFN_SECTION_SHIFT -#else +#elif defined(CONFIG_HUGETLB_PAGE )/* * There is no real limit on the folio size. We limit them to the maximum we -* currently expect (e.g., hugetlb, dax). +* currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect +* no folios larger than 16 GiB on 64bit and 1 GiB on 32bit. +*/ +#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G) +#else +/* +* Without hugetlb, gigantic folios that are bigger than a single PUD are +* currently impossible. */ #define MAX_FOLIO_ORDER PUD_ORDER#endif mm/Kconfig +7
-0@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT config PGTABLE_HAS_HUGE_LEAVES def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE +# +# We can end up creating gigantic folio. +# +config HAVE_GIGANTIC_FOLIOS + def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \ + (ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) + # TODO: Allow to be enabled without THP config ARCH_SUPPORTS_HUGE_PFNMAP def_bool nbase-commit:
6146a0f1dfae5d37442a9ddcba012add260bceb0--
2.51.0
David Hildenbrand (Red Hat)
maintainerQuoted 51 lines · Christophe Leroy
Le 14/11/2025 à 22:49, David Hildenbrand (Red Hat) a écrit :
Quoted 37 lines
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.Quoted 8 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs. I don't think this is a problem, but if it is we could handle it through__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.Reviewed-by Christophe Leroy <[email protected]>
Quoted 8 lines
Tested on powerpc 8xx with
CONFIG_ARCH_FORCE_MAX_ORDER=8instead of 9. It is now possible to add hugepages with the following command:echo 4 >
/sys/kernel/mm/hugepages/hugepages-8192kB/nr_hugepagesBut only if
CONFIG_CMAis set.Tested-by Christophe Leroy <[email protected]>
Thanks a lot for the review and test!
(thanks to the other reviewers obviously as well :) )
Signature · 3 lines
Cheers David
Ritesh Harjani (IBM)
reviewerQuoted 37 lines · David Hildenbrand (Red Hat)
In the past,
CONFIG_ARCH_HAS_GIGANTIC_PAGEindicated that we support runtime allocation of gigantic hugetlb folios. In the meantime it evolved into a generic way for the architecture to state that it supports gigantic hugetlb folios.In commit
fae7d834c43c("mm: add__dump_folio()") we started usingCONFIG_ARCH_HAS_GIGANTIC_PAGEto decideMAX_FOLIO_ORDER: whether we could have folios larger than what the buddy can handle. In the context of that commit, we started usingMAX_FOLIO_ORDERto detect page corruptions when dumping tail pages of folios. Before that commit, we assumed that we cannot have folios larger than the highest buddy order, which was obviously wrong.In commit
7b4f21f5e038("mm/hugetlb: check for unreasonable folio sizes when registering hstate"), we usedMAX_FOLIO_ORDERto detect inconsistencies, and in fact, we found some now.Powerpc allows for configs that can allocate gigantic folio during boot (not at runtime), that do not set
CONFIG_ARCH_HAS_GIGANTIC_PAGEand can exceedPUD_ORDER.To fix it, let's make powerpc select
CONFIG_ARCH_HAS_GIGANTIC_PAGEwith hugetlb on powerpc, and increase the maximum folio size with hugetlb to 16 GiB on 64bit (possible on arm64 and powerpc) and 1 GiB on 32 bit (powerpc). Note that on some powerpc configurations, whether we actually have gigantic pages depends on the setting ofCONFIG_ARCH_FORCE_MAX_ORDER, but there is nothing really problematic about setting it unconditionally: we just try to keep the value small so we can better detect problems in__dump_folio()and inconsistencies around the expected largest folio in the system.Ideally, we'd have a better way to obtain the maximum hugetlb folio size and detect ourselves whether we really end up with gigantic folios. Let's defer bigger changes and fix the warnings first.
While at it, handle gigantic DAX folios more clearly: DAX can only end up creating gigantic folios with
HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD.
Quoted 6 lines
Add a new
KconfigoptionHAVE_GIGANTIC_FOLIOSto make both cases clearer. In particular, worry aboutARCH_HAS_GIGANTIC_PAGEonly withHUGETLB_PAGE.Note: with enabling
CONFIG_ARCH_HAS_GIGANTIC_PAGEon powerpc, we will now also allow for runtime allocations of folios in some more powerpc configs.
So, book3s64 anyways always default to Radix which by default always select CONFIG_ARCH_HAS_GIGANTIC_PAGE. So even if during runtime Hash mmu gets selected, we anyways by default had this config enabled on book3s64.
Quoted 2 lines
I don't think this is a problem, but if it is we could handle it through
__HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED.
Exactly, I see we already have the above config knob at most places where this could be needed to prevent runtime gigantic pages.
Quoted 25 lines
While __dump_page()/__dump_folio was also problematic (not handling dumping of tail pages of such gigantic folios correctly), it doesn't seem critical enough to mark it as a fix.
Fixes 7b4f21f5e038 ("mm/hugetlb: check for unreasonable folio sizes when registering hstate")Reported-by Christophe Leroy <[email protected]>Reported-by Sourabh Jain <[email protected]>Cc Andrew Morton <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Donet Tom <[email protected]>Cc Michael Ellerman <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Christophe Leroy <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Liam R. Howlett" <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Michal Hocko <[email protected]>Cc Nathan Chancellor <[email protected]>Signed-off-by David Hildenbrand (Red Hat) <[email protected]>
Quoted 3 lines
---
v1 -> v2:
Sorry, this got delayed a bit as I wanted to run mm selftests and then update.
As I had updated in previous version, this patch also fixes the warning during boot when RADIX MMU config is kept disabled at build time (that means only Hash is selected) on book3s64.
No new tests failures were reported on running mm selftests with Hash mmu on book3s64. Also verified boot tests on few other ppc configs.
So even though I know this patch is already taken in rc6, but still -
Thanks again for providing a quick fix!
-ritesh