* [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing
@ 2026-11-06 7:23 Avi Weiss
2026-11-07 10:57 ` Mike Rapoport
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread* Re: [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing
2026-11-06 7:23 [PATCH] mm/mm_init: avoid overflow in percentage-based core sizing Avi Weiss
@ 2026-11-07 10:57 ` Mike Rapoport
0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2026-11-07 10:57 UTC (permalink / raw)
To: Avi Weiss; +Cc: Mike Rapoport, akpm, rientjes, linux-mm, linux-kernel
From: Mike Rapoport (Microsoft) <rppt@kernel.org>
On Fri, 06 Nov 2026 09:23:55 +0200, Avi Weiss wrote:
> 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.
>
> [...]
Applied to for-next branch of memblock.git tree, thanks!
[1/1] mm/mm_init: avoid overflow in percentage-based core sizing
commit: 36557d74a757a4bb71bb1492449680177687f5a1
tree: https://git.kernel.org/pub/scm/linux/kernel/git/mm/memblock
branch: for-next
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-07 10:58 UTC | newest]
Thread overview: 2+ messages (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
2026-11-07 10:57 ` Mike Rapoport
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®