From: cov@codeaurora.org (Christopher Covington)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC] arm: Handle starting up in secure mode
Date: Tue, 16 Sep 2014 17:09:16 -0400 [thread overview]
Message-ID: <1410901756-20694-1-git-send-email-cov@codeaurora.org> (raw)
ARM Linux currently has the most features available to it in hypervisor
(HYP) mode, so switch to it when possible. This can also ensure proper
reset of newer registers such as CNTVOFF.
The permissions on the Non-Secure Access Control Register (NSACR) are
used to probe what the security setting currently is when in supervisor
(SVC) mode.
Signed-off-by: Christopher Covington <cov@codeaurora.org>
---
arch/arm/kernel/head.S | 1 +
arch/arm/kernel/hyp-stub.S | 71 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
index 664eee8..6fe2387 100644
--- a/arch/arm/kernel/head.S
+++ b/arch/arm/kernel/head.S
@@ -85,6 +85,7 @@ ENTRY(stext)
THUMB( .thumb ) @ switch to Thumb now.
THUMB(1: )
+ bl __mon_stub_install
#ifdef CONFIG_ARM_VIRT_EXT
bl __hyp_stub_install
#endif
diff --git a/arch/arm/kernel/hyp-stub.S b/arch/arm/kernel/hyp-stub.S
index 2a55373..36d1a9c 100644
--- a/arch/arm/kernel/hyp-stub.S
+++ b/arch/arm/kernel/hyp-stub.S
@@ -20,6 +20,7 @@
#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/virt.h>
+#include <asm/opcodes-sec.h>
#ifndef ZIMAGE
/*
@@ -76,6 +77,64 @@ ENTRY(__boot_cpu_mode)
#endif /* ZIMAGE */
/*
+ * Detect whether the system is in secure supervisor mode, and if it is,
+ * switch to hypervisor mode by way of secure monitor mode.
+ */
+ENTRY(__mon_stub_install)
+ mrs r4, cpsr
+ and r4, r4, #MODE_MASK
+ cmp r4, #SVC_MODE
+ movne pc, lr
+
+ /*
+ * Set things up so that if an NSACR access causes an undefined
+ * instruction exception, we return. safe_svcmode_maskall called
+ * just after this will get us back into supervisor mode.
+ */
+ adr r4, __mon_stub_vectors
+ mcr p15, 0, r4, c12, c0, 0 @ set vector base address (VBAR)
+ mov r4, lr
+
+ /*
+ * Writing the NSACR will only succeed if we're in a secure mode.
+ */
+ mrc p15, 0, r5, c1, c1, 2 @ get non-secure access control (NSACR)
+ mcr p15, 0, r5, c1, c1, 2 @ set non-secure access control (NSACR)
+
+ /*
+ * If we get here, we know we're in secure supervisor mode, so make the
+ * switch to secure monitor mode.
+ *
+ * TODO: make sure this doesn't trap to A64 EL3.
+ */
+ adr r4, __mon_stub_vectors
+ mcr p15, 0, r4, c12, c0, 1 @ set monitor vector base (MVBAR)
+ adr r4, mon_settings
+ __SMC(0)
+
+ /*
+ * Now, from non-secure supervisor mode, transition to hypervisor mode
+ * and return via the exception vector.
+ */
+ mov r4, lr
+ __HVC(0)
+ENDPROC(__mon_stub_install)
+
+ENTRY(mon_settings)
+ /*
+ * Prepare for hypervisor mode by setting the HCE and NS bits.
+ */
+ mrc p15, 0, r4, c1, c1, 0 @ get secure configuration (SCR)
+ orr r4, r4, #0x100
+ orr r4, r4, #1
+ mcr p15, 0, r4, c1, c1, 0 @ set secure configuration (SCR)
+
+ adr r4, __mon_stub_vectors
+ mcr p15, 4, r4, c12, c0, 0 @ set hypervisor vectors (HVBAR)
+ __ERET
+ENDPROC(mon_settings)
+
+/*
* Hypervisor stub installation functions.
*
* These must be called with the MMU and D-cache off.
@@ -209,6 +268,18 @@ ENDPROC(__hyp_set_vectors)
#endif
.align 5
+__mon_stub_vectors:
+__mon_stub_reset: W(b) .
+__mon_stub_und: mov pc, r4
+__mon_stub_call: mov pc, r4
+__mon_stub_pabort: W(b) .
+__mon_stub_dabort: W(b) .
+__mon_stub_trap: mov pc, r4
+__mon_stub_irq: W(b) .
+__mon_stub_fiq: W(b) .
+ENDPROC(__hyp_stub_vectors)
+
+.align 5
__hyp_stub_vectors:
__hyp_stub_reset: W(b) .
__hyp_stub_und: W(b) .
--
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by the Linux Foundation.
next reply other threads:[~2014-09-16 21:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 21:09 Christopher Covington [this message]
2014-09-16 21:24 ` [RFC] arm: Handle starting up in secure mode Christopher Covington
2014-09-17 13:25 ` Christopher Covington
2014-09-17 20:55 ` Sonny Rao
2014-09-19 5:56 ` Peter Maydell
2014-09-19 13:22 ` Christopher Covington
2014-09-19 13:30 ` Catalin Marinas
2014-09-19 13:58 ` Christopher Covington
2014-09-19 16:52 ` Sonny Rao
2014-09-18 17:23 ` Catalin Marinas
2014-09-19 14:02 ` Christopher Covington
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=1410901756-20694-1-git-send-email-cov@codeaurora.org \
--to=cov@codeaurora.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).