Skip to content

Commit 93fa5b2

Browse files
fancerpaulburton
authored andcommitted
mips: Make sure dt memory regions are valid
There are situations when memory regions coming from dts may be too big for the platform physical address space. This especially concerns XPA-capable systems. Bootloader may determine more than 4GB memory available and pass it to the kernel over dts memory node, while kernel is built without XPA/64BIT support. In this case the region may either simply be truncated by add_memory_region() method or by u64->phys_addr_t type casting. But in worst case the method can even drop the memory region if it exceeds PHYS_ADDR_MAX size. So lets make sure the retrieved from dts memory regions are valid, and if some of them aren't, just manually truncate them with a warning printed out. Signed-off-by: Serge Semin <[email protected]> Signed-off-by: Paul Burton <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: James Hogan <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Stefan Agner <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Alexandre Belloni <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Serge Semin <[email protected]> Cc: [email protected] Cc: [email protected]
1 parent 2f5bd03 commit 93fa5b2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arch/mips/kernel/prom.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ char *mips_get_machine_name(void)
4141
#ifdef CONFIG_USE_OF
4242
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
4343
{
44-
return add_memory_region(base, size, BOOT_MEM_RAM);
44+
if (base >= PHYS_ADDR_MAX) {
45+
pr_warn("Trying to add an invalid memory region, skipped\n");
46+
return;
47+
}
48+
49+
/* Truncate the passed memory region instead of type casting */
50+
if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
51+
pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
52+
size, base, PHYS_ADDR_MAX - base);
53+
size = PHYS_ADDR_MAX - base;
54+
}
55+
56+
add_memory_region(base, size, BOOT_MEM_RAM);
4557
}
4658

4759
int __init early_init_dt_reserve_memory_arch(phys_addr_t base,

0 commit comments

Comments
 (0)