From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Arnd Bergmann <arnd@arndb.de>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Linus Walleij <linus.walleij@linaro.org>,
Russell King - ARM Linux <linux@armlinux.org.uk>,
Alexander Sverdlin <alexander.sverdlin@nokia.com>,
Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 1/2] ARM: take memreserve FDT entries into account when discovering base of RAM
Date: Mon, 11 Jan 2021 11:30:19 +0100 [thread overview]
Message-ID: <20210111103020.32372-2-ardb@kernel.org> (raw)
In-Reply-To: <20210111103020.32372-1-ardb@kernel.org>
As an enhancement to the newly added logic to cross-reference the base
of DRAM calculated by rounding the decompressor load address against the
memory nodes in the DT, take /memreserve/ entries into account as well.
This ensures that DT platforms that currently rely on TEXT_OFFSET to be
increased in order to stay clear of memory reservations no longer need
this hack in the future.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm/boot/compressed/Makefile | 2 ++
arch/arm/boot/compressed/fdt_check_mem_start.c | 35 +++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index fd94e27ba4fa..cf8cfe3f286c 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -96,6 +96,8 @@ endif
$(foreach o, $(libfdt_objs) atags_to_fdt.o fdt_check_mem_start.o, \
$(eval CFLAGS_$(o) := -I $(srctree)/scripts/dtc/libfdt -fno-stack-protector))
+CFLAGS_fdt_check_mem_start.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
+
# These were previously generated C files. When you are building the kernel
# with O=, make sure to remove the stale files in the output tree. Otherwise,
# the build system wrongly compiles the stale ones.
diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
index 62450d824c3c..f81ed6ae9776 100644
--- a/arch/arm/boot/compressed/fdt_check_mem_start.c
+++ b/arch/arm/boot/compressed/fdt_check_mem_start.c
@@ -4,6 +4,19 @@
#include <linux/libfdt.h>
#include <linux/sizes.h>
+/*
+ * The ARM kernel only uses part of the 32 KiB TEXT_OFFSET window at the start
+ * of the uncompressed image, and some platforms rely on this, and have placed
+ * reserved regions right before it. This means we should only consider an
+ * overlap to be a collision if the reserved region covers the area that we
+ * actually use for page tables.
+ */
+#ifdef CONFIG_ARM_LPAE
+#define TEXT_OFFSET_FREE (TEXT_OFFSET - 0x5000)
+#else
+#define TEXT_OFFSET_FREE (TEXT_OFFSET - 0x4000)
+#endif
+
static const void *get_prop(const void *fdt, const char *node_path,
const char *property, int minlen)
{
@@ -44,6 +57,24 @@ static uint64_t get_val(const fdt32_t *cells, uint32_t ncells)
return r;
}
+static void clip_reserved_regions(const void *fdt, uint32_t *base, uint64_t *end)
+{
+ int i;
+
+ for (i = 0; i < fdt_num_mem_rsv(fdt); i++) {
+ uint64_t address, size;
+
+ if (fdt_get_mem_rsv(fdt, i, &address, &size))
+ return;
+
+ if (*base >= address && *base < (address + size))
+ *base = address + size;
+
+ if (*end >= address && *end < (address + size))
+ *end = address;
+ }
+}
+
/*
* Check the start of physical memory
*
@@ -107,7 +138,9 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
base = fdt32_ld(reg + addr_cells - 1);
end = base + size;
- if (mem_start >= base && mem_start < end) {
+ clip_reserved_regions(fdt, &base, &end);
+ if (mem_start + TEXT_OFFSET_FREE >= base &&
+ mem_start < end) {
/* Calculated address is valid, use it */
return mem_start;
}
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-01-11 10:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 10:30 [PATCH 0/2] ARM: remove TEXT_OFFSET override for Axxia Ard Biesheuvel
2021-01-11 10:30 ` Ard Biesheuvel [this message]
2021-01-11 10:30 ` [PATCH 2/2] ARM: axxia: remove TEXT_OFFSET override hack Ard Biesheuvel
2021-01-12 10:34 ` Alexander Sverdlin
2021-01-12 10:40 ` Ard Biesheuvel
2021-01-12 11:22 ` Alexander Sverdlin
2021-01-12 13:55 ` Alexander Sverdlin
2021-01-12 14:05 ` Ard Biesheuvel
2021-01-12 14:21 ` Alexander Sverdlin
2021-01-13 17:49 ` Ard Biesheuvel
2021-01-13 21:26 ` Russell King - ARM Linux admin
2021-01-13 22:43 ` Ard Biesheuvel
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=20210111103020.32372-2-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=alexander.sverdlin@nokia.com \
--cc=arnd@arndb.de \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux@armlinux.org.uk \
/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).