[PATCH] mm/mm_init: avoid overflow in percentage-based core sizing
From: Avi Weiss
Date: Fri Nov 06 2026 - 02:26:59 EST
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@xxxxxxxxx>
---
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