Linux-mm Archive on lore.kernel.org
 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

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

On Wed, Sep 02, 2026 at 05:03:46PM +0800, Liu Jing wrote:
> 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.
> 

weights can't be zero and we just fixed the rebind race

if you're actually seeing this then there's a different bug to fix

> 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