]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-5.1/mips-make-sure-dt-memory-regions-are-valid.patch
4.19-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.1 / mips-make-sure-dt-memory-regions-are-valid.patch
CommitLineData
d50b8c78
SL
1From 965db14c2279a61b2a5cc3cc30c6cd84fd429f7e Mon Sep 17 00:00:00 2001
2From: Serge Semin <fancer.lancer@gmail.com>
3Date: Fri, 3 May 2019 20:50:40 +0300
4Subject: mips: Make sure dt memory regions are valid
5
6[ Upstream commit 93fa5b280761a4dbb14c5330f260380385ab2b49 ]
7
8There are situations when memory regions coming from dts may be
9too big for the platform physical address space. This especially
10concerns XPA-capable systems. Bootloader may determine more than 4GB
11memory available and pass it to the kernel over dts memory node, while
12kernel is built without XPA/64BIT support. In this case the region
13may either simply be truncated by add_memory_region() method
14or by u64->phys_addr_t type casting. But in worst case the method
15can even drop the memory region if it exceeds PHYS_ADDR_MAX size.
16So lets make sure the retrieved from dts memory regions are valid,
17and if some of them aren't, just manually truncate them with a warning
18printed out.
19
20Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
21Signed-off-by: Paul Burton <paul.burton@mips.com>
22Cc: Ralf Baechle <ralf@linux-mips.org>
23Cc: James Hogan <jhogan@kernel.org>
24Cc: Mike Rapoport <rppt@linux.ibm.com>
25Cc: Andrew Morton <akpm@linux-foundation.org>
26Cc: Michal Hocko <mhocko@suse.com>
27Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
29Cc: Huacai Chen <chenhc@lemote.com>
30Cc: Stefan Agner <stefan@agner.ch>
31Cc: Stephen Rothwell <sfr@canb.auug.org.au>
32Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
33Cc: Juergen Gross <jgross@suse.com>
34Cc: Serge Semin <Sergey.Semin@t-platforms.ru>
35Cc: linux-mips@vger.kernel.org
36Cc: linux-kernel@vger.kernel.org
37Signed-off-by: Sasha Levin <sashal@kernel.org>
38---
39 arch/mips/kernel/prom.c | 14 +++++++++++++-
40 1 file changed, 13 insertions(+), 1 deletion(-)
41
42diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
43index 93b8e0b4332f..b9d6c6ec4177 100644
44--- a/arch/mips/kernel/prom.c
45+++ b/arch/mips/kernel/prom.c
46@@ -41,7 +41,19 @@ char *mips_get_machine_name(void)
47 #ifdef CONFIG_USE_OF
48 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
49 {
50- return add_memory_region(base, size, BOOT_MEM_RAM);
51+ if (base >= PHYS_ADDR_MAX) {
52+ pr_warn("Trying to add an invalid memory region, skipped\n");
53+ return;
54+ }
55+
56+ /* Truncate the passed memory region instead of type casting */
57+ if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
58+ pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
59+ size, base, PHYS_ADDR_MAX - base);
60+ size = PHYS_ADDR_MAX - base;
61+ }
62+
63+ add_memory_region(base, size, BOOT_MEM_RAM);
64 }
65
66 int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
67--
682.20.1
69