[PATCH] mempolicy: fix mod-by-zero in weighted_interleave_nid
From: Liu Jing
Date: Wed Sep 02 2026 - 05:20:46 EST
In weighted_interleave_nid(), if the iw_table contains all-zero
weights for every node in the policy nodemask, weight_total sums to
zero. The subsequent "ilx % weight_total" triggers a divide-by-zero
panic.
Add a zero check returning the current NUMA node id when the total
weight is zero, consistent with the existing !nr_nodes guard.
Signed-off-by: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
---
mm/mempolicy.c | 4 ++++
1 file changed, 4 insertion(+), 0 deletion(-)
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2218,6 +2218,10 @@
/* calculate the total weight */
for_each_node_mask(nid, nodemask)
weight_total += table ? table[nid] : 1;
+
+
+ if (!weight_total)
+ return numa_node_id();
/* Calculate the node offset based on totals */
target = ilx % weight_total;
--
2.43.0