Merge tag 'memblock-v7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock

Pull memblock updates from Mike Rapoport:
 "Non-urgent fixes:

   - Fix calculation of node_spanned_pages when running
     with 'kernelcore=mirror'

   - Properly handle failure to allocate per_cpu_nodestats
     in free_area_init_core_hotplug()

   - Fix deferred initialization of the memory map for
     configurations where node's RAM end is not aligned
     on PAGES_PER_SECTION

  Cleanups:

   - Remove redundant pageblock_align() call in free_unused_memmap()

   - Remove unnecessary invalid range checks in users of memblock
     iterators. Some users of for_each_mem_range() and
     for_each_mem_pfn_range() verify that start < end for each range.

     This is redundant because memblock iterators guarantee to never
     return an invalid range

   - Stop overlapping zones with 'kernelcore=mirror' and align behaviour
     of 'kernelcore=mirror' with other variants of kernelcore and
     movablecore

   - Remove redundant updates of numa_nodes_parsed mask in the callers
     of numa_add_memblk(), the latter always updates the mask anyway

   - Remove unnecessary initialization of pgdat->per_cpu_nodestats to
     NULL, the variable is reset to the actual value a few lines below"

* tag 'memblock-v7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock: (25 commits)
  mm/mm_init: deferred_grow_zone(): fix out-of-range first_deferred_pfn
  mm/mm_init: remove unnecessary initialization of pgdat->per_cpu_nodestats
  mm/mm_init: remove redundant memset in free_area_init()
  mm: numa_memblks: use numa_add_reserved_memblk() in numa_cleanup_meminfo()
  arch_numa: remove redundant node_possible_map assignment
  mm: numa_memblks: remove redundant numa_nodemask_from_meminfo()
  LoongArch: remove redundant numa_nodes_parsed node_set()
  arch_numa: remove redundant numa_nodes_parsed node_set()
  x86/numa: remove redundant numa_nodes_parsed node_set()
  of/numa: remove redundant numa_nodes_parsed node_set()
  ACPI: NUMA: remove redundant numa_nodes_parsed node_set()
  mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk()
  mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug
  mm/mm_init: drop overlap_memmap_init()
  mm/mm_init: don't overlap NORMAL and MOVABLE zones with kernelcore=mirror
  mm/hugetlb: remove unnecessary empty range check in hugetlb_bootmem_set_nodes()
  mm: remove unnecessary empty range check in early_calculate_totalpages()
  powerpc64/kasan: Remove unreachable invalid range check in kasan_init_phys_region()
  ARM: remove unreachable invalid range check in kasan_init()
  riscv: remove unreachable invalid range check in kasan_init()
  ...
This commit is contained in:
Linus Torvalds
2026-08-18 10:03:54 -07:00
18 changed files with 49 additions and 136 deletions

View File

@@ -262,12 +262,6 @@ void __init kasan_init(void)
&pa_start, &pa_end, &arm_lowmem_limit);
end = __va(arm_lowmem_limit);
}
if (start >= end) {
pr_info("Skipping invalid memory block %pa-%pa (virtual %p-%p)\n",
&pa_start, &pa_end, start, end);
continue;
}
create_mapping(start, end);
}

View File

@@ -353,9 +353,6 @@ static void __init kasan_init_shadow(void)
void *start = (void *)__phys_to_virt(pa_start);
void *end = (void *)__phys_to_virt(pa_end);
if (start >= end)
break;
kasan_map_populate((unsigned long)kasan_mem_to_shadow(start),
(unsigned long)kasan_mem_to_shadow(end),
early_pfn_to_nid(virt_to_pfn(start)));

View File

@@ -216,7 +216,6 @@ static int __init fake_numa_init(void)
phys_addr_t start = memblock_start_of_DRAM();
phys_addr_t end = memblock_end_of_DRAM() - 1;
node_set(0, numa_nodes_parsed);
pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
return numa_add_memblk(0, start, end + 1);

View File

@@ -305,9 +305,6 @@ void __init kasan_init(void)
void *start = (void *)phys_to_virt(pa_start);
void *end = (void *)phys_to_virt(pa_end);
if (start >= end)
break;
kasan_map_populate((unsigned long)mem_to_shadow(start),
(unsigned long)mem_to_shadow(end), NUMA_NO_NODE);
}

View File

@@ -68,9 +68,6 @@ static void __init kasan_init_phys_region(void *start, void *end)
unsigned long k_start, k_end, k_cur;
void *va;
if (start >= end)
return;
k_start = ALIGN_DOWN((unsigned long)kasan_mem_to_shadow(start), PAGE_SIZE);
k_end = ALIGN((unsigned long)kasan_mem_to_shadow(end), PAGE_SIZE);

View File

@@ -24,9 +24,6 @@ static void __init kasan_init_phys_region(void *start, void *end)
unsigned long k_start, k_end, k_cur;
void *va;
if (start >= end)
return;
k_start = ALIGN_DOWN((unsigned long)kasan_mem_to_shadow(start), PAGE_SIZE);
k_end = ALIGN((unsigned long)kasan_mem_to_shadow(end), PAGE_SIZE);

View File

@@ -1239,8 +1239,6 @@ static void __init create_linear_mapping_page_table(void)
/* Map all memory banks in the linear mapping */
for_each_mem_range(i, &start, &end) {
if (start >= end)
break;
if (start <= __pa(PAGE_OFFSET) &&
__pa(PAGE_OFFSET) < end)
start = __pa(PAGE_OFFSET);

View File

@@ -512,9 +512,6 @@ void __init kasan_init(void)
void *start = (void *)__va(p_start);
void *end = (void *)__va(p_end);
if (start >= end)
break;
kasan_populate(kasan_mem_to_shadow(start), kasan_mem_to_shadow(end));
}

View File

@@ -150,7 +150,6 @@ int __init amd_numa_init(void)
prevbase = base;
numa_add_memblk(nodeid, base, limit);
node_set(nodeid, numa_nodes_parsed);
}
if (nodes_empty(numa_nodes_parsed))

View File

@@ -216,7 +216,6 @@ static int __init dummy_numa_init(void)
printk(KERN_INFO "Faking a node at [mem %#018Lx-%#018Lx]\n",
0LLU, PFN_PHYS(max_pfn) - 1);
node_set(0, numa_nodes_parsed);
node_set(0, numa_phys_nodes_parsed);
numa_add_memblk(0, 0, PFN_PHYS(max_pfn));

View File

@@ -221,9 +221,6 @@ static int __init numa_register_nodes(void)
node_set_online(nid);
}
/* Setup online nodes to actual nodes*/
node_possible_map = numa_nodes_parsed;
return 0;
}
@@ -283,7 +280,6 @@ static int __init dummy_numa_init(void)
pr_err("NUMA init failed\n");
return ret;
}
node_set(0, numa_nodes_parsed);
numa_off = true;
return 0;

View File

@@ -59,11 +59,8 @@ static int __init of_numa_parse_memory_nodes(void)
r = -EINVAL;
}
for (i = 0; !r && !of_address_to_resource(np, i, &rsrc); i++) {
for (i = 0; !r && !of_address_to_resource(np, i, &rsrc); i++)
r = numa_add_memblk(nid, rsrc.start, rsrc.end + 1);
if (!r)
node_set(nid, numa_nodes_parsed);
}
if (!i || r) {
of_node_put(np);

View File

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

View File

@@ -4444,15 +4444,12 @@ hugetlb_early_param("default_hugepagesz", default_hugepagesz_setup);
void __init hugetlb_bootmem_set_nodes(void)
{
int i, nid;
unsigned long start_pfn, end_pfn;
if (!nodes_empty(hugetlb_bootmem_nodes))
return;
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
if (end_pfn > start_pfn)
node_set(nid, hugetlb_bootmem_nodes);
}
for_each_mem_pfn_range(i, MAX_NUMNODES, NULL, NULL, &nid)
node_set(nid, hugetlb_bootmem_nodes);
}
void __init hugetlb_bootmem_alloc(void)

View File

@@ -2224,10 +2224,8 @@ static void __init free_unused_memmap(void)
}
#ifdef CONFIG_SPARSEMEM
if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) {
prev_end = pageblock_align(end);
if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
}
#endif
}

View File

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

View File

@@ -332,8 +332,7 @@ static unsigned long __init early_calculate_totalpages(void)
unsigned long pages = end_pfn - start_pfn;
totalpages += pages;
if (pages)
node_set_state(nid, N_MEMORY);
node_set_state(nid, N_MEMORY);
}
return totalpages;
}
@@ -799,28 +798,6 @@ void __meminit init_deferred_page(unsigned long pfn, int nid)
__init_deferred_page(pfn, nid);
}
/* If zone is ZONE_MOVABLE but memory is mirrored, it is an overlapped init */
static bool __meminit
overlap_memmap_init(unsigned long zone, unsigned long *pfn)
{
static struct memblock_region *r __meminitdata;
if (mirrored_kernelcore && zone == ZONE_MOVABLE) {
if (!r || *pfn >= memblock_region_memory_end_pfn(r)) {
for_each_mem_region(r) {
if (*pfn < memblock_region_memory_end_pfn(r))
break;
}
}
if (*pfn >= memblock_region_memory_base_pfn(r) &&
memblock_is_mirror(r)) {
*pfn = memblock_region_memory_end_pfn(r);
return true;
}
}
return false;
}
/*
* Only struct pages that correspond to ranges defined by memblock.memory
* are zeroed and initialized by going through __init_single_page() during
@@ -907,8 +884,6 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone
* function. They do not exist on hotplugged memory.
*/
if (context == MEMINIT_EARLY) {
if (overlap_memmap_init(zone, &pfn))
continue;
if (defer_init(nid, pfn, zone_end_pfn)) {
deferred_struct_pages = true;
break;
@@ -1174,9 +1149,8 @@ static void __init adjust_zone_range_for_zone_movable(int nid,
arch_zone_highest_possible_pfn[movable_zone]);
/* Adjust for ZONE_MOVABLE starting within this range */
} else if (!mirrored_kernelcore &&
*zone_start_pfn < zone_movable_pfn[nid] &&
*zone_end_pfn > zone_movable_pfn[nid]) {
} else if (*zone_start_pfn < zone_movable_pfn[nid] &&
*zone_end_pfn > zone_movable_pfn[nid]) {
*zone_end_pfn = zone_movable_pfn[nid];
/* Check if this whole range is within ZONE_MOVABLE */
@@ -1224,40 +1198,11 @@ static unsigned long __init zone_absent_pages_in_node(int nid,
unsigned long zone_start_pfn,
unsigned long zone_end_pfn)
{
unsigned long nr_absent;
/* zone is empty, we don't have any absent pages */
if (zone_start_pfn == zone_end_pfn)
return 0;
nr_absent = __absent_pages_in_range(nid, zone_start_pfn, zone_end_pfn);
/*
* ZONE_MOVABLE handling.
* Treat pages to be ZONE_MOVABLE in ZONE_NORMAL as absent pages
* and vice versa.
*/
if (mirrored_kernelcore && zone_movable_pfn[nid]) {
unsigned long start_pfn, end_pfn;
struct memblock_region *r;
for_each_mem_region(r) {
start_pfn = clamp(memblock_region_memory_base_pfn(r),
zone_start_pfn, zone_end_pfn);
end_pfn = clamp(memblock_region_memory_end_pfn(r),
zone_start_pfn, zone_end_pfn);
if (zone_type == ZONE_MOVABLE &&
memblock_is_mirror(r))
nr_absent += end_pfn - start_pfn;
if (zone_type == ZONE_NORMAL &&
!memblock_is_mirror(r))
nr_absent += end_pfn - start_pfn;
}
}
return nr_absent;
return __absent_pages_in_range(nid, zone_start_pfn, zone_end_pfn);
}
/*
@@ -1338,7 +1283,7 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
unsigned long node_start_pfn,
unsigned long node_end_pfn)
{
unsigned long realtotalpages = 0, totalpages = 0;
unsigned long realtotalpages = 0;
enum zone_type i;
for (i = 0; i < MAX_NR_ZONES; i++) {
@@ -1368,11 +1313,10 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
zone->present_early_pages = real_size;
#endif
totalpages += spanned;
realtotalpages += real_size;
}
pgdat->node_spanned_pages = totalpages;
pgdat->node_spanned_pages = node_end_pfn - node_start_pfn;
pgdat->node_present_pages = realtotalpages;
pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages);
}
@@ -1536,7 +1480,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;
@@ -1544,8 +1488,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.
@@ -1583,6 +1533,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
@@ -1720,7 +1672,6 @@ static void __init free_area_init_node(int nid)
pgdat->node_id = nid;
pgdat->node_start_pfn = start_pfn;
pgdat->per_cpu_nodestats = NULL;
if (start_pfn != end_pfn) {
pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
@@ -1843,7 +1794,6 @@ static void __init free_area_init(void)
}
/* Find the PFNs that ZONE_MOVABLE begins at in each node */
memset(zone_movable_pfn, 0, sizeof(zone_movable_pfn));
find_zone_movable_pfns_for_nodes();
/* Print out the zone ranges */
@@ -2214,10 +2164,13 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order)
}
/*
* There were no pages to initialize and free which means the zone's
* memory map is completely initialized.
* The loop only tests spfn before entering an iteration, so on exit it
* may point up to a section past the end of the zone. When it does,
* the rest of the zone has already been handed to
* deferred_init_memmap_chunk() and nothing is left to initialize.
*/
pgdat->first_deferred_pfn = nr_pages ? spfn : ULONG_MAX;
pgdat->first_deferred_pfn =
spfn < zone_end_pfn(zone) ? spfn : ULONG_MAX;
pgdat_resize_unlock(pgdat, &flags);

View File

@@ -17,20 +17,6 @@ nodemask_t numa_nodes_parsed __initdata;
static struct numa_meminfo numa_meminfo __initdata_or_meminfo;
static struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
/*
* Set nodes, which have memory in @mi, in *@nodemask.
*/
static void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
const struct numa_meminfo *mi)
{
int i;
for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
if (mi->blk[i].start != mi->blk[i].end &&
mi->blk[i].nid != NUMA_NO_NODE)
node_set(mi->blk[i].nid, *nodemask);
}
/**
* numa_reset_distance - Reset NUMA distance table
*
@@ -56,7 +42,6 @@ static int __init numa_alloc_distance(void)
/* size the new table and allocate it */
nodes_parsed = numa_nodes_parsed;
numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo);
for_each_node_mask(i, nodes_parsed)
cnt = i;
@@ -135,13 +120,20 @@ EXPORT_SYMBOL(__node_distance);
static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
struct numa_meminfo *mi)
{
/* whine about and ignore invalid nid */
if (nid < 0 || nid >= MAX_NUMNODES) {
pr_warn("Warning: invalid memblk node id %d [mem %#010Lx-%#010Lx]\n",
nid, start, end - 1);
return -EINVAL;
}
/* ignore zero length blks */
if (start == end)
return 0;
/* whine about and ignore invalid blks */
if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
/* whine about and ignore invalid ranges */
if (start > end) {
pr_warn("Warning: invalid memblk range for node %d [mem %#010Lx-%#010Lx]\n",
nid, start, end - 1);
return 0;
}
@@ -193,13 +185,20 @@ static void __init numa_move_tail_memblk(struct numa_meminfo *dst, int idx,
* @end: End address of the new memblk
*
* Add a new memblk to the default numa_meminfo.
* On success @nid is also set in numa_nodes_parsed.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int __init numa_add_memblk(int nid, u64 start, u64 end)
{
return numa_add_memblk_to(nid, start, end, &numa_meminfo);
int ret;
ret = numa_add_memblk_to(nid, start, end, &numa_meminfo);
if (!ret)
node_set(nid, numa_nodes_parsed);
return ret;
}
/**
@@ -256,8 +255,7 @@ int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
/* preserve info for non-RAM areas above 'max_pfn': */
if (bi->end > high) {
numa_add_memblk_to(bi->nid, high, bi->end,
&numa_reserved_meminfo);
numa_add_reserved_memblk(bi->nid, high, bi->end);
bi->end = high;
}
@@ -401,7 +399,6 @@ static int __init numa_register_meminfo(struct numa_meminfo *mi)
/* Account for nodes with cpus and no memory */
node_possible_map = numa_nodes_parsed;
numa_nodemask_from_meminfo(&node_possible_map, mi);
if (WARN_ON(nodes_empty(node_possible_map)))
return -EINVAL;