Skip to content

Commit e888fa7

Browse files
geerturppt
authored andcommitted
memblock: Check memory add/cap ordering
For memblock_cap_memory_range() to work properly, it should be called after memory is detected and added to memblock with memblock_add() or memblock_add_node(). If memblock_cap_memory_range() would be called before memory is registered, we may silently corrupt memory later because the crash kernel will see all memory as available. Print a warning and bail out if ordering is not satisfied. Suggested-by: Mike Rapoport <rppt@kernel.org> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Link: https://lore.kernel.org/r/aabc5bad008d49f07d542815c6c8d28ec90bb09e.1628672091.git.geert+renesas@glider.be
1 parent 00974b9 commit e888fa7

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

mm/memblock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,11 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
16851685
if (!size)
16861686
return;
16871687

1688+
if (memblock.memory.cnt <= 1) {
1689+
pr_warn("%s: No memory registered yet\n", __func__);
1690+
return;
1691+
}
1692+
16881693
ret = memblock_isolate_range(&memblock.memory, base, size,
16891694
&start_rgn, &end_rgn);
16901695
if (ret)

0 commit comments

Comments
 (0)