summaryrefslogtreecommitdiff
path: root/mm/memblock.c
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2021-08-11 10:55:18 +0200
committerMike Rapoport <rppt@linux.ibm.com>2021-08-11 14:50:50 +0300
commite888fa7bb882a1f305526d8f49d7016a7bc5f5ca (patch)
treebd8c423f250465b3ae2ebbda8f9a003ddd5cea35 /mm/memblock.c
parent00974b9a83cb233d9c8f9758f541d9aa2a80c5cd (diff)
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
Diffstat (limited to 'mm/memblock.c')
-rw-r--r--mm/memblock.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/mm/memblock.c b/mm/memblock.c
index 57a9849a5d82..e2ca8ddc8ebe 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1685,6 +1685,11 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
if (!size)
return;
+ if (memblock.memory.cnt <= 1) {
+ pr_warn("%s: No memory registered yet\n", __func__);
+ return;
+ }
+
ret = memblock_isolate_range(&memblock.memory, base, size,
&start_rgn, &end_rgn);
if (ret)