Skip to content

Commit

Permalink
of: fdt: Scan /memreserve/ last
Browse files Browse the repository at this point in the history
Change the scanning /memreserve/ and /reserved-memory node order to fix
Kernel panic on Khadas Vim3 Board.

If /memreserve/ goes first, the memory is reserved, but nomap can't be
applied to the region. So the memory won't be used by Linux, but it is
still present in the linear map as normal memory, which allows
speculation. Legitimate access to adjacent pages will cause the CPU
to end up prefetching into them leading to Kernel panic.

So /reserved-memory node should go first, as it has a more updated
description of the memory regions and can apply flags, like nomap.

Link: https://lore.kernel.org/all/CAJX_Q+1Tjc+-TjZ6JW9X0NxEdFe=82a9626yL63j7uVD4LpxEA@mail.gmail.com/
Signed-off-by: Lucas Tanure <tanure@linux.com>
Link: https://lore.kernel.org/r/20230424113846.46382-1-tanure@linux.com
Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
Lucas Tanure authored and Rob Herring committed Apr 27, 2023
1 parent 6e0c2bf commit b413281
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ void __init early_init_fdt_scan_reserved_mem(void)
if (!initial_boot_params)
return;

fdt_scan_reserved_mem();
fdt_reserve_elfcorehdr();

/* Process header /memreserve/ fields */
for (n = 0; ; n++) {
fdt_get_mem_rsv(initial_boot_params, n, &base, &size);
Expand All @@ -643,8 +646,6 @@ void __init early_init_fdt_scan_reserved_mem(void)
memblock_reserve(base, size);
}

fdt_scan_reserved_mem();
fdt_reserve_elfcorehdr();
fdt_init_reserved_mem();
}

Expand Down

0 comments on commit b413281

Please sign in to comment.