From: Muchun Song <muchun.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: Muchun Song <songmuchun@bytedance.com>,
Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Kiryl Shutsemau <kas@kernel.org>, Mike Rapoport <rppt@kernel.org>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
linux-mm@kvack.org
Subject: Re: [PATCH] mm/hugetlb: fix validation of unsupported HugeTLB orders
Date: Tue, 3 Nov 2026 16:20:08 +0800 [thread overview]
Message-ID: <CDC3B454-CBB4-428D-A97F-B3B8414BBC07@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-194806@kernel.org>
> On Nov 3, 2026, at 16:13, sashiko-bot@kernel.org wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm/hugetlb: boot BUG_ON() in hugetlb_init() when HPAGE_SHIFT is 0 on powerpc
> --
>
> commit 83959b12982c256d20ca0de51021b3beae201569
> Author: Muchun Song <muchun.song@linux.dev>
>
> mm/hugetlb: fix validation of unsupported HugeTLB orders
>
> This commit replaces BUILD_BUG_ON_INVALID() with MAYBE_BUILD_BUG_ON() in
> hugetlb_init() so that configurations where HUGETLB_PAGE_ORDER exceeds
> MAX_FOLIO_ORDER are rejected at build time when constant or via BUG_ON() at
> runtime otherwise.
>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index ff9dbfbc7a961..e21ac667694bd 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -4181,7 +4181,7 @@ static int __init hugetlb_init(void)
>>
>> BUILD_BUG_ON(sizeof_field(struct page, private) * BITS_PER_BYTE <
>> __NR_HPAGEFLAGS);
>> - BUILD_BUG_ON_INVALID(HUGETLB_PAGE_ORDER > MAX_FOLIO_ORDER);
>> + MAYBE_BUILD_BUG_ON(HUGETLB_PAGE_ORDER > MAX_FOLIO_ORDER);
>
> [Severity: High]
> Will placing MAYBE_BUILD_BUG_ON() before the hugepages_supported() check in
> hugetlb_init() trigger a boot BUG_ON() on architectures like PowerPC
> Book3S-64 when huge pages are unsupported at runtime?
Yeah, it's easy to fix, but I'll wait another day before updating it—just
in case others have feedback.
Thanks,
Muchun
>
> On CONFIG_PPC_BOOK3S_64, arch/powerpc/include/asm/page.h defines HPAGE_SHIFT
> as a runtime unsigned int variable:
>
> extern unsigned int hpage_shift;
> #define HPAGE_SHIFT hpage_shift
> ...
> #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
>
> Because hpage_shift is not a compile-time constant, MAYBE_BUILD_BUG_ON()
> expands to a runtime BUG_ON(HUGETLB_PAGE_ORDER > MAX_FOLIO_ORDER).
>
> When huge pages are not supported by the platform or are disabled at boot
> (for example, when hugetlbpage_init_defaultsize() in
> arch/powerpc/mm/book3s64/hugetlbpage.c finds no supported huge page sizes),
> hpage_shift remains 0, which hugepages_supported() checks:
>
> static inline bool hugepages_supported(void)
> {
> if (hugetlb_disabled)
> return false;
>
> return HPAGE_SHIFT != 0;
> }
>
> Evaluating HUGETLB_PAGE_ORDER before checking hugepages_supported() computes
> (0U - PAGE_SHIFT) in unsigned int arithmetic, wrapping around to a large
> unsigned value that exceeds MAX_FOLIO_ORDER and hits BUG_ON().
>
> Should MAYBE_BUILD_BUG_ON(HUGETLB_PAGE_ORDER > MAX_FOLIO_ORDER) be moved
> after the if (!hugepages_supported()) block in hugetlb_init(), similar to how
> hugepage_init() in mm/huge_memory.c checks has_transparent_hugepage() before
> evaluating MAYBE_BUILD_BUG_ON(HPAGE_PMD_ORDER > MAX_PAGE_ORDER)?
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261103023831.1805473-1-songmuchun@bytedance.com?part=1
prev parent reply other threads:[~2026-11-03 8:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 2:38 [PATCH] mm/hugetlb: fix validation of unsupported HugeTLB orders Muchun Song
2026-11-03 8:13 ` sashiko-bot
2026-11-03 8:20 ` Muchun Song [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CDC3B454-CBB4-428D-A97F-B3B8414BBC07@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chenhuacai@kernel.org \
--cc=david@kernel.org \
--cc=kas@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox