Skip to content

Commit

Permalink
mm/page_alloc: fix freeing static percpu memory
Browse files Browse the repository at this point in the history
The size of struct per_cpu_zonestat can be 0 on !SMP && !NUMA.  In that
case, zone->per_cpu_zonestats will always equal to boot_zonestats.  But in
zone_pcp_reset(), zone->per_cpu_zonestats is freed via free_percpu()
directly without checking against boot_zonestats first.  boot_zonestats
will be released by free_percpu() unexpectedly.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 28f836b ("mm/page_alloc: split per cpu page lists and zone stats")
Signed-off-by: Miaohe Lin <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Oscar Salvador <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
MiaoheLin authored and akpm00 committed Oct 3, 2022
1 parent 5749fcc commit 022e7fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9513,9 +9513,11 @@ void zone_pcp_reset(struct zone *zone)
drain_zonestat(zone, pzstats);
}
free_percpu(zone->per_cpu_pageset);
free_percpu(zone->per_cpu_zonestats);
zone->per_cpu_pageset = &boot_pageset;
zone->per_cpu_zonestats = &boot_zonestats;
if (zone->per_cpu_zonestats != &boot_zonestats) {
free_percpu(zone->per_cpu_zonestats);
zone->per_cpu_zonestats = &boot_zonestats;
}
}
}

Expand Down

0 comments on commit 022e7fa

Please sign in to comment.