* [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing
@ 2026-11-06 7:23 Avi Weiss
0 siblings, 0 replies; only message in thread
From: Avi Weiss @ 2026-11-06 7:23 UTC (permalink / raw)
To: rppt; +Cc: akpm, rientjes, linux-mm, linux-kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-06 7:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 7:23 [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing Avi Weiss
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®