mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-27 22:13:55 -04:00
mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug
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.
On failure nothing needs to be unwound:
- the node is never marked online
- per_cpu_nodestats is left pointing at boot_nodestats
- __add_memory_resource() cleans up pending memblock resources
- later online attempts retry the per_cpu_nodestats allocation
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260627202243.758289-1-gourry%40gourry.net
Fixes: 75ef718405 ("mm, vmstat: add infrastructure for per-node vmstats")
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Link: https://patch.msgid.link/20260701221613.2818148-1-gourry@gourry.net
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
This commit is contained in:
committed by
Mike Rapoport (Microsoft)
parent
7783dcd79a
commit
2ebce860bd
@@ -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);
|
||||
int __ref free_area_init_core_hotplug(struct pglist_data *pgdat);
|
||||
extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
|
||||
extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
|
||||
extern int add_memory_resource(int nid, struct resource *resource,
|
||||
|
||||
@@ -1263,7 +1263,8 @@ static pg_data_t *hotadd_init_pgdat(int nid)
|
||||
pgdat = NODE_DATA(nid);
|
||||
|
||||
/* init node's zones as empty zones, we don't have any present pages.*/
|
||||
free_area_init_core_hotplug(pgdat);
|
||||
if (free_area_init_core_hotplug(pgdat))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* The node we allocated has no zone fallback lists. For avoiding
|
||||
|
||||
14
mm/mm_init.c
14
mm/mm_init.c
@@ -1535,7 +1535,7 @@ void __init set_pageblock_order(void)
|
||||
* NOTE: this function is only called during memory hotplug
|
||||
*/
|
||||
#ifdef CONFIG_MEMORY_HOTPLUG
|
||||
void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
|
||||
int __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
|
||||
{
|
||||
int nid = pgdat->node_id;
|
||||
enum zone_type z;
|
||||
@@ -1543,8 +1543,14 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
|
||||
|
||||
pgdat_init_internals(pgdat);
|
||||
|
||||
if (pgdat->per_cpu_nodestats == &boot_nodestats)
|
||||
pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat);
|
||||
if (pgdat->per_cpu_nodestats == &boot_nodestats) {
|
||||
struct per_cpu_nodestat __percpu *p;
|
||||
|
||||
p = alloc_percpu(struct per_cpu_nodestat);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
pgdat->per_cpu_nodestats = p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset the nr_zones, order and highest_zoneidx before reuse.
|
||||
@@ -1575,6 +1581,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
|
||||
zone->present_pages = 0;
|
||||
zone_init_internals(zone, z, nid, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user