From: Serge Semin <fancer.lancer@gmail.com>
To: Ralf Baechle <ralf@linux-mips.org>,
Paul Burton <paul.burton@mips.com>,
James Hogan <jhogan@kernel.org>,
Mike Rapoport <rppt@linux.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Thomas Bogendoerfer <tbogendoerfer@suse.de>,
Huacai Chen <chenhc@lemote.com>, Stefan Agner <stefan@agner.ch>,
Stephen Rothwell <sfr@canb.auug.org.au>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Juergen Gross <jgross@suse.com>
Cc: Serge Semin <Sergey.Semin@t-platforms.ru>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/5] mips: Make sure dt memory regions are valid
Date: Fri, 3 May 2019 20:50:40 +0300 [thread overview]
Message-ID: <20190503175041.7949-5-fancer.lancer@gmail.com> (raw)
In-Reply-To: <20190503175041.7949-1-fancer.lancer@gmail.com>
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 <fancer.lancer@gmail.com>
---
arch/mips/kernel/prom.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/prom.c b/arch/mips/kernel/prom.c
index 437a174e3ef9..28bf01961bb2 100644
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -41,7 +41,19 @@ char *mips_get_machine_name(void)
#ifdef CONFIG_USE_OF
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
{
- return add_memory_region(base, size, BOOT_MEM_RAM);
+ if (base >= PHYS_ADDR_MAX) {
+ pr_warn("Trying to add an invalid memory region, skipped\n");
+ return;
+ }
+
+ /* Truncate the passed memory region instead of type casting */
+ if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) {
+ pr_warn("Truncate memory region %llx @ %llx to size %llx\n",
+ size, base, PHYS_ADDR_MAX - base);
+ size = PHYS_ADDR_MAX - base;
+ }
+
+ add_memory_region(base, size, BOOT_MEM_RAM);
}
int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
--
2.21.0
next prev parent reply other threads:[~2019-05-03 17:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-03 17:50 [PATCH v2 0/5] mips: Post-bootmem-memblock transition fixes Serge Semin
2019-05-03 17:50 ` [PATCH v2 1/5] mips: Dump memblock regions for debugging Serge Semin
2019-05-06 19:11 ` Paul Burton
2019-05-03 17:50 ` [PATCH v2 2/5] mips: Perform early low memory test Serge Semin
2019-05-06 19:11 ` Paul Burton
2019-05-03 17:50 ` [PATCH v2 3/5] mips: Print the kernel virtual mem layout on debugging Serge Semin
2019-05-06 19:14 ` Paul Burton
2019-05-07 22:36 ` Serge Semin
2019-05-07 22:41 ` Paul Burton
2019-05-07 23:38 ` Serge Semin
2019-06-17 13:39 ` Serge Semin
2019-05-07 23:03 ` [PATCH v3] " Serge Semin
2019-05-03 17:50 ` Serge Semin [this message]
2019-05-06 19:12 ` [PATCH v2 4/5] mips: Make sure dt memory regions are valid Paul Burton
2019-05-03 17:50 ` [PATCH v2 5/5] mips: Manually call fdt_init_reserved_mem() method Serge Semin
2019-05-06 19:12 ` Paul Burton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190503175041.7949-5-fancer.lancer@gmail.com \
--to=fancer.lancer@gmail.com \
--cc=Sergey.Semin@t-platforms.ru \
--cc=akpm@linux-foundation.org \
--cc=alexandre.belloni@bootlin.com \
--cc=chenhc@lemote.com \
--cc=gregkh@linuxfoundation.org \
--cc=jgross@suse.com \
--cc=jhogan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=paul.burton@mips.com \
--cc=ralf@linux-mips.org \
--cc=rppt@linux.ibm.com \
--cc=sfr@canb.auug.org.au \
--cc=stefan@agner.ch \
--cc=tbogendoerfer@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).