]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: sanity-check maximum folio size in folio_set_order()
authorDavid Hildenbrand <david@redhat.com>
Mon, 1 Sep 2025 15:03:31 +0000 (17:03 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:25:31 +0000 (17:25 -0700)
Let's sanity-check in folio_set_order() whether we would be trying to
create a folio with an order that would make it exceed MAX_FOLIO_ORDER.

This will enable the check whenever a folio/compound page is initialized
through prepare_compound_head() / prepare_compound_page() with
CONFIG_DEBUG_VM set.

Link: https://lkml.kernel.org/r/20250901150359.867252-11-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.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/internal.h

index 45da9ff5694f628db18f740718f0a7a06c4548f0..9b0129531d004ff0e9cec9cd84ca866fd8ef1585 100644 (file)
@@ -755,6 +755,7 @@ static inline void folio_set_order(struct folio *folio, unsigned int order)
 {
        if (WARN_ON_ONCE(!order || !folio_test_large(folio)))
                return;
+       VM_WARN_ON_ONCE(order > MAX_FOLIO_ORDER);
 
        folio->_flags_1 = (folio->_flags_1 & ~0xffUL) | order;
 #ifdef NR_PAGES_IN_LARGE_FOLIO