Re: [PATCH] mempolicy: fix mod-by-zero in weighted_interleave_nid

From: Gregory Price

Date: Wed Sep 02 2026 - 10:06:32 EST


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@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
>
>