linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mempolicy: fix mod-by-zero in weighted_interleave_nid
@ 2026-09-02  9:03 Liu Jing
  2026-09-02 13:58 ` Gregory Price
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Jing @ 2026-09-02  9:03 UTC (permalink / raw)
  To: akpm
  Cc: david, ziy, matthew.brost, joshua.hahnjy, rakie.kim, byungchul,
	gourry, ying.huang, apopple, linux-mm, linux-kernel, Liu Jing

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@cmss.chinamobile.com>
---
 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-02 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  9:03 [PATCH] mempolicy: fix mod-by-zero in weighted_interleave_nid Liu Jing
2026-09-02 13:58 ` Gregory Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).