linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 4/4] arm64: prevent __va() translations before memstart_addr is assigned
Date: Fri, 12 Feb 2016 15:57:26 +0100	[thread overview]
Message-ID: <1455289046-21321-5-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1455289046-21321-1-git-send-email-ard.biesheuvel@linaro.org>

Since memstart_addr is assigned relatively late in the boot code,
after generic code like DT parsing and memblock manipulation has
already occurred, we need to ensure that no __va() translation occur
until memstart_addr has been set to a meaningful value.

So initialize memstart_addr to a value that cannot represent a valid
physical address, and BUG() if memstart_addr is referenced while it
still holds this value. Note that the > comparison against LLONG_MAX
(not ULLONG_MAX) resolves to a single tbnz instruction that performs
a conditional jump to a brk instruction that is emitted out of line.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/include/asm/memory.h | 4 +++-
 arch/arm64/mm/init.c            | 8 +++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index c900883a3119..ae398919fb5f 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -24,6 +24,7 @@
 #include <linux/compiler.h>
 #include <linux/const.h>
 #include <linux/types.h>
+#include <asm/bug.h>
 #include <asm/sizes.h>
 
 /*
@@ -133,7 +134,8 @@
 
 extern phys_addr_t		memstart_addr;
 /* PHYS_OFFSET - the physical address of the start of memory. */
-#define PHYS_OFFSET		({ memstart_addr; })
+#define PHYS_OFFSET		\
+	({ BUG_ON(memstart_addr > LLONG_MAX); memstart_addr; })
 
 /* the virtual base of the kernel image (minus TEXT_OFFSET) */
 extern u64			kimage_vaddr;
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index ed85778b32e5..023c41f22b5b 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -48,7 +48,13 @@
 
 #include "mm.h"
 
-phys_addr_t memstart_addr __read_mostly = 0;
+/*
+ * We need to be able to catch inadvertent references to memstart_addr
+ * that occur (potentially in generic code) before arm64_memblock_init()
+ * executes, which assigns it its actual value. So use a default value
+ * that cannot be mistaken for a real physical address.
+ */
+phys_addr_t memstart_addr __read_mostly = ULLONG_MAX;
 phys_addr_t arm64_dma_phys_limit __read_mostly;
 
 #ifdef CONFIG_BLK_DEV_INITRD
-- 
2.5.0

  parent reply	other threads:[~2016-02-12 14:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 14:57 [PATCH v3 0/4] arm64: avoid early __va translations Ard Biesheuvel
2016-02-12 14:57 ` [PATCH v3 1/4] of/fdt: factor out assignment of initrd_start/initrd_end Ard Biesheuvel
2016-02-22 16:49   ` Will Deacon
2016-02-22 16:56     ` Ard Biesheuvel
2016-02-22 17:09       ` Will Deacon
2016-02-22 17:16         ` Ard Biesheuvel
2016-02-12 14:57 ` [PATCH v3 2/4] arm64: defer __va translation of initrd_start and initrd_end Ard Biesheuvel
2016-02-12 14:57 ` [PATCH v3 3/4] arm64: prevent potential circular header dependencies in asm/bug.h Ard Biesheuvel
2016-02-22 18:00   ` Will Deacon
2016-02-12 14:57 ` Ard Biesheuvel [this message]
2016-02-22 16:52   ` [PATCH v3 4/4] arm64: prevent __va() translations before memstart_addr is assigned Will Deacon
2016-02-22 17:17     ` Ard Biesheuvel
2016-02-22 17:41       ` Catalin Marinas
2016-02-22 17:55         ` Ard Biesheuvel
2016-02-22 17:26     ` Catalin Marinas
2016-02-22 17:38       ` Ard Biesheuvel
2016-02-15 10:42 ` [PATCH v3 0/4] arm64: avoid early __va translations Laurentiu Tudor

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=1455289046-21321-5-git-send-email-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).