From: Avi Weiss <thnkslprpt@gmail.com>
To: rppt@kernel.org
Cc: akpm@linux-foundation.org, rientjes@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing
Date: Fri, 6 Nov 2026 09:23:55 +0200 [thread overview]
Message-ID: <20261106072354.2234189-2-thnkslprpt@gmail.com> (raw)
The kernelcore= and movablecore= percentage calculations multiply the
total number of pages before dividing. On 32-bit kernels, the
intermediate unsigned long product can overflow, producing incorrect
memory zone boundaries. With 2 GiB of RAM and kernelcore=100%, a
32-bit HIGHMEM kernel incorrectly creates ZONE_MOVABLE.
Use mult_frac() to calculate both percentages without overflowing
the intermediate product.
Fixes: a5c6d6509342 ("mm, page_alloc: extend kernelcore and movablecore for percent")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
mm/mm_init.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 2a0e782a151d..27a50ecd5c20 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -7,6 +7,7 @@
*
*/
#include <linux/kernel.h>
+#include <linux/math.h>
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/export.h>
@@ -448,11 +449,9 @@ static void __init find_zone_movable_pfns_for_nodes(void)
* amount of necessary memory.
*/
if (required_kernelcore_percent)
- required_kernelcore = (totalpages * 100 * required_kernelcore_percent) /
- 10000UL;
+ required_kernelcore = mult_frac(totalpages, required_kernelcore_percent, 100);
if (required_movablecore_percent)
- required_movablecore = (totalpages * 100 * required_movablecore_percent) /
- 10000UL;
+ required_movablecore = mult_frac(totalpages, required_movablecore_percent, 100);
/*
* If movablecore= was specified, calculate what size of
base-commit: 36aad21d50d1af3f6954bb0c988257a908202477
--
2.43.0
next reply other threads:[~2026-11-06 7:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 7:23 Avi Weiss [this message]
2026-11-07 10:57 ` Mike Rapoport
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=20261106072354.2234189-2-thnkslprpt@gmail.com \
--to=thnkslprpt@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
/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
all inboxes | Powered by JetHome®