Skip to contentSkip to conversation

of: fdt: Scan /memreserve/ last

PATCH Applied Lucas Tanure 2 participants 2 messages Apr 24, 2023 – Apr 27, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 of: fdt: Scan /memreserve/ last

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.

---
Previous Threads:
#regzbot link: https://lore.kernel.org/linux-arm-kernel/[email protected]/#regzbot
#regzbot link: https://lore.kernel.org/all/CAJX_Q+1Tjc+-TjZ6JW9X0NxEdFe=82a9626yL63j7uVD4LpxEA@mail.gmail.com/

V1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/linux-mm/[email protected]/T/

Change from V3:
- Drop cover letter
- Add more information into the patch

Change from V2:
- Remove region overlap and reserved checks

Change from V1:
- Instead of allowing to mark nomap a region already reserved, give
precedence to /reserved-memory node scan.

---
 drivers/of/fdt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/of/fdt.c +3 -2
index d14735a81301..bf502ba8da95 100644
@@ -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);
@@ -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();
 }
 
Signature · 1 line
2.40.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Lucas Tanure

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.

Quoted 8 lines

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

---
Previous Threads:
#regzbot link: https://lore.kernel.org/linux-arm-kernel/[email protected]/#regzbot
#regzbot link: https://lore.kernel.org/all/CAJX_Q+1Tjc+-TjZ6JW9X0NxEdFe=82a9626yL63j7uVD4LpxEA@mail.gmail.com/

Note that this should have been a 'Link:' entry in the commit message for regzbot. I added it.

Quoted 12 lines

V1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/linux-mm/[email protected]/T/

Change from V3:
- Drop cover letter
- Add more information into the patch

Change from V2:
- Remove region overlap and reserved checks

Quoted 7 lines

Change from V1:
- Instead of allowing to mark nomap a region already reserved, give
precedence to /reserved-memory node scan.

---
 drivers/of/fdt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied, thanks!

Going to let this sit in linux-next for a bit. I also didn't tag for stable kernels. I want it to get some exposure in mainline at least for a few -rc releases rather than getting backported right away. Please help ensure that happens if you see stable review emails. I'm going to be offline most of the next month.

Rob