]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/mips-make-sure-dt-memory-regions-are-valid.patch
Linux 5.1.10
[thirdparty/kernel/stable-queue.git] / queue-4.19 / mips-make-sure-dt-memory-regions-are-valid.patch
1 From 8e6fcbe5380fd4cf83249c060bf0ef93f2a7ff05 Mon Sep 17 00:00:00 2001
2 From: Serge Semin <fancer.lancer@gmail.com>
3 Date: Fri, 3 May 2019 20:50:40 +0300
4 Subject: mips: Make sure dt memory regions are valid
5
6 [ Upstream commit 93fa5b280761a4dbb14c5330f260380385ab2b49 ]
7
8 There are situations when memory regions coming from dts may be
9 too big for the platform physical address space. This especially
10 concerns XPA-capable systems. Bootloader may determine more than 4GB
11 memory available and pass it to the kernel over dts memory node, while
12 kernel is built without XPA/64BIT support. In this case the region
13 may either simply be truncated by add_memory_region() method
14 or by u64->phys_addr_t type casting. But in worst case the method
15 can even drop the memory region if it exceeds PHYS_ADDR_MAX size.
16 So lets make sure the retrieved from dts memory regions are valid,
17 and if some of them aren't, just manually truncate them with a warning
18 printed out.
19
20 Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
21 Signed-off-by: Paul Burton <paul.burton@mips.com>
22 Cc: Ralf Baechle <ralf@linux-mips.org>
23 Cc: James Hogan <jhogan@kernel.org>
24 Cc: Mike Rapoport <rppt@linux.ibm.com>
25 Cc: Andrew Morton <akpm@linux-foundation.org>
26 Cc: Michal Hocko <mhocko@suse.com>
27 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
29 Cc: Huacai Chen <chenhc@lemote.com>
30 Cc: Stefan Agner <stefan@agner.ch>
31 Cc: Stephen Rothwell <sfr@canb.auug.org.au>
32 Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
33 Cc: Juergen Gross <jgross@suse.com>
34 Cc: Serge Semin <Sergey.Semin@t-platforms.ru>
35 Cc: linux-mips@vger.kernel.org
36 Cc: linux-kernel@vger.kernel.org
37 Signed-off-by: Sasha Levin <sashal@kernel.org>
38 ---
39 arch/mips/kernel/prom.c | 14 +++++++++++++-
40 1 file changed, 13 insertions(+), 1 deletion(-)
41
42 diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
43 index 89950b7bf536..bdaf3536241a 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 --
68 2.20.1
69