From: sashiko-bot@kernel.org
To: "Muchun Song" <songmuchun@bytedance.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Oscar Salvador" <osalvador@suse.de>
Cc: "Muchun Song" <muchun.song@linux.dev>,
"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, 03 Nov 2026 08:13:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-194806@kernel.org> (raw)
In-Reply-To: <20261103023831.1805473-1-songmuchun@bytedance.com>
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?
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
next prev parent reply other threads:[~2026-11-03 8:13 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 [this message]
2026-11-03 8:20 ` Muchun Song
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=sashiko-outbox-194806@kernel.org \
--to=sashiko-bot@kernel.org \
--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=muchun.song@linux.dev \
--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