Skip to content

Commit 39231e8

Browse files
David Hildenbrand (Red Hat)akpm00
authored andcommitted
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 fae7d83 ("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 7b4f21f ("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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 7b4f21f ("mm/hugetlb: check for unreasonable folio sizes when registering hstate") Reported-by: Christophe Leroy <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Reported-by: Sourabh Jain <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: David Hildenbrand (Red Hat) <[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: Andrew Morton <[email protected]>
1 parent b05addf commit 39231e8

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ config PPC
137137
select ARCH_HAS_DMA_OPS if PPC64
138138
select ARCH_HAS_FORTIFY_SOURCE
139139
select ARCH_HAS_GCOV_PROFILE_ALL
140+
select ARCH_HAS_GIGANTIC_PAGE if ARCH_SUPPORTS_HUGETLBFS
140141
select ARCH_HAS_KCOV
141142
select ARCH_HAS_KERNEL_FPU_SUPPORT if PPC64 && PPC_FPU
142143
select ARCH_HAS_MEMBARRIER_CALLBACKS

arch/powerpc/platforms/Kconfig.cputype

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ config PPC_64S_HASH_MMU
423423
config PPC_RADIX_MMU
424424
bool "Radix MMU Support"
425425
depends on PPC_BOOK3S_64
426-
select ARCH_HAS_GIGANTIC_PAGE
427426
default y
428427
help
429428
Enable support for the Power ISA 3.0 Radix style MMU. Currently this

include/linux/mm.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)
20742074
return folio_large_nr_pages(folio);
20752075
}
20762076

2077-
#if !defined(CONFIG_ARCH_HAS_GIGANTIC_PAGE)
2077+
#if !defined(CONFIG_HAVE_GIGANTIC_FOLIOS)
20782078
/*
20792079
* We don't expect any folios that exceed buddy sizes (and consequently
20802080
* memory sections).
@@ -2087,10 +2087,17 @@ static inline unsigned long folio_nr_pages(const struct folio *folio)
20872087
* pages are guaranteed to be contiguous.
20882088
*/
20892089
#define MAX_FOLIO_ORDER PFN_SECTION_SHIFT
2090-
#else
2090+
#elif defined(CONFIG_HUGETLB_PAGE)
20912091
/*
20922092
* There is no real limit on the folio size. We limit them to the maximum we
2093-
* currently expect (e.g., hugetlb, dax).
2093+
* currently expect (see CONFIG_HAVE_GIGANTIC_FOLIOS): with hugetlb, we expect
2094+
* no folios larger than 16 GiB on 64bit and 1 GiB on 32bit.
2095+
*/
2096+
#define MAX_FOLIO_ORDER get_order(IS_ENABLED(CONFIG_64BIT) ? SZ_16G : SZ_1G)
2097+
#else
2098+
/*
2099+
* Without hugetlb, gigantic folios that are bigger than a single PUD are
2100+
* currently impossible.
20942101
*/
20952102
#define MAX_FOLIO_ORDER PUD_ORDER
20962103
#endif

mm/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,13 @@ config PAGE_MAPCOUNT
908908
config PGTABLE_HAS_HUGE_LEAVES
909909
def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE
910910

911+
#
912+
# We can end up creating gigantic folio.
913+
#
914+
config HAVE_GIGANTIC_FOLIOS
915+
def_bool (HUGETLB_PAGE && ARCH_HAS_GIGANTIC_PAGE) || \
916+
(ZONE_DEVICE && HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
917+
911918
# TODO: Allow to be enabled without THP
912919
config ARCH_SUPPORTS_HUGE_PFNMAP
913920
def_bool n

0 commit comments

Comments
 (0)