Re: [PATCH] mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug
From: Gregory Price
Date: Wed Jul 01 2026 - 11:21:07 EST
On Wed, Jul 01, 2026 at 09:38:57AM +0300, Mike Rapoport wrote:
> On Tue, Jun 30, 2026 at 05:40:39PM -0400, Gregory Price wrote:
> > We miss a failed allocation check for pgdat->per_cpu_nodestats, which
> > results in a NULL deref when we offset into the per-cpu area.
> >
> > Propagate -ENOMEM up the stack and leave per_cpu_nodestats pointing
> > at boot_nodestats so a later online can retry the allocation.
> >
> > hotadd_init_pgdat() returns NULL on failure, which __try_online_node()
> > already maps to -ENOMEM.
> >
> > Assisted-by: Sashiko:unknown-model
>
> I suppose it's rather
>
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
I honestly wasn't sure here, Assisted-by is the tag for LLMs lol
i can change it
>
> > Fixes: 75ef71840539 ("mm, vmstat: add infrastructure for per-node vmstats")
> > Signed-off-by: Gregory Price <gourry@xxxxxxxxxx>
> > ---
> > include/linux/memory_hotplug.h | 2 +-
> > mm/memory_hotplug.c | 3 ++-
> > mm/mm_init.c | 14 +++++++++++---
> > 3 files changed, 14 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
> > index 7c9d66729c60..f04b915678db 100644
> > --- a/include/linux/memory_hotplug.h
> > +++ b/include/linux/memory_hotplug.h
> > @@ -289,7 +289,7 @@ static inline void __remove_memory(u64 start, u64 size) {}
> > /* Default online_type (MMOP_*) when new memory blocks are added. */
> > extern enum mmop mhp_get_default_online_type(void);
> > extern void mhp_set_default_online_type(enum mmop online_type);
> > -extern void __ref free_area_init_core_hotplug(struct pglist_data *pgdat);
> > +extern int __ref free_area_init_core_hotplug(struct pglist_data *pgdat);
>
> Nit: we are trying to get rid of 'extern's in the headers, even though it
> makes the declarations inconsistent.
> Can you please drop the extern since you anyway changing this?
yup no problem