Skip to contentSkip to conversation

memblock: fix crash when reserved memory is not added to memory

PATCH In review Yajun Deng 3 participants 3 messages Jan 18, 2024 – Jan 23, 2024

Subsystems (2)
lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH 1/1 memblock: fix crash when reserved memory is not added to memory

After commit 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()"), we set nid on all reserved pages based on memory region, but some reserved memory may not be added to memory on certain architectures. The nid is invalid.

Add the nid check, make sure the nid is valid by early_pfn_to_nid().

Fixes 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()")
---
 mm/memblock.c | 3 +++
 1 file changed, 3 insertions(+)
mm/memblock.c +3 -0
index abd92869874d..4dcb2ee35eca 100644
@@ -2176,6 +2176,9 @@ static void __init memmap_init_reserved_pages(void)
 			start = region->base;
 			end = start + region->size;
 
+			if (nid == NUMA_NO_NODE || nid >= MAX_NUMNODES)
+				nid = early_pfn_to_nid(PFN_DOWN(start));
+
 			reserve_bootmem_region(start, end, nid);
 		}
 	}
Signature · 1 line
2.25.1
maintainer
#1 lore raw

(adding Huang Pei to verify this fixes the crash on loongarch)

Quoted 30 lines · Yajun Deng

After commit 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()"), we set nid on all reserved pages based on memory region, but some reserved memory may not be added to memory on certain architectures. The nid is invalid.

Add the nid check, make sure the nid is valid by early_pfn_to_nid().

Fixes 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()")
---
 mm/memblock.c | 3 +++
 1 file changed, 3 insertions(+)
mm/memblock.c +3 -0
index abd92869874d..4dcb2ee35eca 100644
@@ -2176,6 +2176,9 @@ static void __init memmap_init_reserved_pages(void)
 			start = region->base;
 			end = start + region->size;
 
+			if (nid == NUMA_NO_NODE || nid >= MAX_NUMNODES)
+				nid = early_pfn_to_nid(PFN_DOWN(start));
+
 			reserve_bootmem_region(start, end, nid);
 		}
 	}
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw
Quoted 2 lines · Mike Rapoport

(adding Huang Pei to verify this fixes the crash on loongarch)

It fixed 61167ad5fecd on MIPS/loongson64, tested on 3b1500 with only this one;

My loongarch64 machine is not available now, I can not test it, sorry. It is already applied a arch-specific workaround in v6.5+

Quoted 35 lines · Yajun Deng
Quoted 30 lines

After commit 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()"), we set nid on all reserved pages based on memory region, but some reserved memory may not be added to memory on certain architectures. The nid is invalid.

Add the nid check, make sure the nid is valid by early_pfn_to_nid().

Fixes 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()")
---
 mm/memblock.c | 3 +++
 1 file changed, 3 insertions(+)
mm/memblock.c +3 -0
index abd92869874d..4dcb2ee35eca 100644
@@ -2176,6 +2176,9 @@ static void __init memmap_init_reserved_pages(void)
 			start = region->base;
 			end = start + region->size;
 
+			if (nid == NUMA_NO_NODE || nid >= MAX_NUMNODES)
+				nid = early_pfn_to_nid(PFN_DOWN(start));
+
 			reserve_bootmem_region(start, end, nid);
 		}
 	}
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.