* [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_interleave
@ 2026-09-02 9:02 Liu Jing
2026-09-02 14:04 ` Gregory Price
0 siblings, 1 reply; 2+ messages in thread
From: Liu Jing @ 2026-09-02 9:02 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 alloc_pages_bulk_interleave(), nodes_weight(pol->nodes) may return
0 if all nodes in the policy mask have been offlined at runtime. The
subsequent division "nr_pages / nodes" triggers a divide-by-zero
panic.
Add a zero check returning 0 (no pages allocated) when the nodemask
is empty, consistent with the guard in
alloc_pages_bulk_weighted_interleave().
Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
mm/mempolicy.c | 3 +++
1 file changed, 3 insertion(+), 0 deletion(-)
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2600,6 +2600,9 @@
unsigned long total_allocated = 0;
nodes = nodes_weight(pol->nodes);
+ if (!nodes)
+ return 0;
+
nr_pages_per_node = nr_pages / nodes;
delta = nr_pages - nodes * nr_pages_per_node;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_interleave
2026-09-02 9:02 [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_interleave Liu Jing
@ 2026-09-02 14:04 ` Gregory Price
0 siblings, 0 replies; 2+ messages in thread
From: Gregory Price @ 2026-09-02 14:04 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:02:45PM +0800, Liu Jing wrote:
> In alloc_pages_bulk_interleave(), nodes_weight(pol->nodes) may return
> 0 if all nodes in the policy mask have been offlined at runtime. The
> subsequent division "nr_pages / nodes" triggers a divide-by-zero
> panic.
>
now i'm positive this is LLM produced without understanding the
component.
A policy cannot have an empty nodemask, it can either
1) have no nodemask (default policy), or
2) be perceived as empty during a torn-read during a policy remap event
If you are running LLMs to search for surface level bugs and try to
hot-fix them without taking time to understand the underlying component,
please at least:
1) tell us that
2) generate reproducers
these "quick fixes" based on surface level observations are going to hide
real bugs and just degrade the overall state of the system.
> Add a zero check returning 0 (no pages allocated) when the nodemask
> is empty, consistent with the guard in
> alloc_pages_bulk_weighted_interleave().
>
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
> mm/mempolicy.c | 3 +++
> 1 file changed, 3 insertion(+), 0 deletion(-)
>
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -2600,6 +2600,9 @@
> unsigned long total_allocated = 0;
>
> nodes = nodes_weight(pol->nodes);
> + if (!nodes)
> + return 0;
> +
> nr_pages_per_node = nr_pages / nodes;
> delta = nr_pages - nodes * nr_pages_per_node;
>
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-02 14:05 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:02 [PATCH] mempolicy: fix div-by-zero in alloc_pages_bulk_interleave Liu Jing
2026-09-02 14:04 ` Gregory Price
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®