]> git.ipfire.org Git - thirdparty/linux.git/commit
mm/hugetlb: check for unreasonable folio sizes when registering hstate
authorDavid Hildenbrand <david@redhat.com>
Mon, 1 Sep 2025 15:03:29 +0000 (17:03 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Sep 2025 21:22:02 +0000 (14:22 -0700)
commit7b4f21f5e0386dfe02c68c009294d8f26e3c1bad
treec9615e761586836dc9f6bd963f86cf871078cbfd
parent646b67d575897dc656b07446e23e756d54e49828
mm/hugetlb: check for unreasonable folio sizes when registering hstate

Let's check that no hstate that corresponds to an unreasonable folio size
is registered by an architecture.  If we were to succeed registering, we
could later try allocating an unsupported gigantic folio size.

Further, let's add a BUILD_BUG_ON() for checking that HUGETLB_PAGE_ORDER
is sane at build time.  As HUGETLB_PAGE_ORDER is dynamic on powerpc, we
have to use a BUILD_BUG_ON_INVALID() to make it compile.

No existing kernel configuration should be able to trigger this check:
either SPARSEMEM without SPARSEMEM_VMEMMAP cannot be configured or
gigantic folios will not exceed a memory section (the case on sparse).

Link: https://lkml.kernel.org/r/20250901150359.867252-9-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/hugetlb.c