From: Greg Bellows <greg.bellows@linaro.org>
To: qemu-devel@nongnu.org, serge.fdrv@gmail.com,
edgar.iglesias@gmail.com, aggelerf@ethz.ch,
peter.maydell@linaro.org
Cc: greg.bellows@linaro.org
Subject: [Qemu-devel] [PATCH v9 04/26] target-arm: add non-secure Translation Block flag
Date: Wed, 5 Nov 2014 17:22:51 -0600 [thread overview]
Message-ID: <1415229793-3278-5-git-send-email-greg.bellows@linaro.org> (raw)
In-Reply-To: <1415229793-3278-1-git-send-email-greg.bellows@linaro.org>
From: Sergey Fedorov <s.fedorov@samsung.com>
This patch is based on idea found in patch at
git://github.com/jowinter/qemu-trustzone.git
f3d955c6c0ed8c46bc0eb10b634201032a651dd2 by
Johannes Winter <johannes.winter@iaik.tugraz.at>.
The TBFLAG captures the SCR NS secure state at the time when a TB is created so
the correct bank is accessed on system register accesses.
Signed-off-by: Sergey Fedorov <s.fedorov@samsung.com>
Signed-off-by: Fabian Aggeler <aggelerf@ethz.ch>
Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
v7 -> v8
- Moved and renamed use_secure_reg() to this patch. New name is
access_secure_reg().
- Fixed function comment
v5 -> v6
- Removed 64-bit NS TBFLAG macros as they are not needed
- Added comment on DisasContext ns field
- Replaced use of USE_SECURE_REG with use_secure_reg
v4 -> v5
- Merge changes
- Fixed issue where TB secure state flag was incorrectly being set based on
secure state rather than NS setting. This caused an issue where monitor mode
MRC/MCR accesses were always secure rather than being based on NS bit
setting.
- Added separate 64/32 TB secure state flags
- Unconditionalized the setting of the DC ns bit
- Removed IS_NS macro and replaced with direct usage.
---
target-arm/cpu.h | 27 +++++++++++++++++++++++++++
target-arm/translate.c | 1 +
target-arm/translate.h | 1 +
3 files changed, 29 insertions(+)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 34fae40..8d3717d 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -817,6 +817,22 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el)
return arm_feature(env, ARM_FEATURE_AARCH64);
}
+/* Function for determing whether guest cp register reads and writes should
+ * access the secure or non-secure bank of a cp register. When EL3 is
+ * operating in AArch32 state, the NS-bit determines whether the secure
+ * instance of a cp register should be used. When EL3 is AArch64 (or if
+ * it doesn't exist at all) then there is no register banking, and all
+ * accesses are to the non-secure version.
+ */
+static inline bool access_secure_reg(CPUARMState *env)
+{
+ bool ret = (arm_feature(env, ARM_FEATURE_EL3) &&
+ !arm_el_is_aa64(env, 3) &&
+ !(env->cp15.scr_el3 & SCR_NS));
+
+ return ret;
+}
+
/* Macros for accessing a specified CP register bank */
#define A32_BANKED_REG_GET(_env, _regname, _secure) \
((_secure) ? (_env)->cp15._regname##_s : (_env)->cp15._regname##_ns)
@@ -1468,6 +1484,12 @@ static inline bool arm_singlestep_active(CPUARMState *env)
*/
#define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20
#define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT)
+/* Indicates whether cp register reads and writes by guest code should access
+ * the secure or nonsecure bank of banked registers; note that this is not
+ * the same thing as the current security state of the processor!
+ */
+#define ARM_TBFLAG_NS_SHIFT 22
+#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT)
/* Bit usage when in AArch64 state */
#define ARM_TBFLAG_AA64_EL_SHIFT 0
@@ -1512,6 +1534,8 @@ static inline bool arm_singlestep_active(CPUARMState *env)
(((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)
#define ARM_TBFLAG_AA64_PSTATE_SS(F) \
(((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT)
+#define ARM_TBFLAG_NS(F) \
+ (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT)
static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
target_ulong *cs_base, int *flags)
@@ -1561,6 +1585,9 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
if (privmode) {
*flags |= ARM_TBFLAG_PRIV_MASK;
}
+ if (!(access_secure_reg(env))) {
+ *flags |= ARM_TBFLAG_NS_MASK;
+ }
if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)
|| arm_el_is_aa64(env, 1)) {
*flags |= ARM_TBFLAG_VFPEN_MASK;
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 1d52e47..32eb7bb 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -11005,6 +11005,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
#if !defined(CONFIG_USER_ONLY)
dc->user = (ARM_TBFLAG_PRIV(tb->flags) == 0);
#endif
+ dc->ns = ARM_TBFLAG_NS(tb->flags);
dc->cpacr_fpen = ARM_TBFLAG_CPACR_FPEN(tb->flags);
dc->vfp_enabled = ARM_TBFLAG_VFPEN(tb->flags);
dc->vec_len = ARM_TBFLAG_VECLEN(tb->flags);
diff --git a/target-arm/translate.h b/target-arm/translate.h
index 41a9071..f6ee789 100644
--- a/target-arm/translate.h
+++ b/target-arm/translate.h
@@ -20,6 +20,7 @@ typedef struct DisasContext {
#if !defined(CONFIG_USER_ONLY)
int user;
#endif
+ bool ns; /* Use non-secure CPREG bank on access */
bool cpacr_fpen; /* FP enabled via CPACR.FPEN */
bool vfp_enabled; /* FP enabled via FPSCR.EN */
int vec_len;
--
1.8.3.2
next prev parent reply other threads:[~2014-11-05 23:23 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 23:22 [Qemu-devel] [PATCH v9 00/26] target-arm: add Security Extensions for CPUs Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 01/26] target-arm: extend async excp masking Greg Bellows
2014-11-05 23:37 ` Peter Maydell
2014-11-06 1:29 ` Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 02/26] target-arm: add async excp target_el function Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 03/26] target-arm: add banked register accessors Greg Bellows
2014-11-05 23:22 ` Greg Bellows [this message]
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 05/26] target-arm: add CPREG secure state support Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 06/26] target-arm: add secure state bit to CPREG hash Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 07/26] target-arm: insert AArch32 cpregs twice into hashtable Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 08/26] target-arm: move AArch32 SCR into security reglist Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 09/26] target-arm: implement IRQ/FIQ routing to Monitor mode Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 10/26] target-arm: add NSACR register Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 11/26] target-arm: add SDER definition Greg Bellows
2014-11-05 23:22 ` [Qemu-devel] [PATCH v9 12/26] target-arm: add MVBAR support Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 13/26] target-arm: add SCTLR_EL3 and make SCTLR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 14/26] target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 15/26] target-arm: make CSSELR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 16/26] target-arm: make TTBR0/1 banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 17/26] target-arm: make TTBCR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 18/26] target-arm: make DACR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 19/26] target-arm: make IFSR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 20/26] target-arm: make DFSR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 21/26] target-arm: make IFAR/DFAR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 22/26] target-arm: make PAR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 23/26] target-arm: make VBAR banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 24/26] target-arm: make c13 cp regs banked (FCSEIDR, ...) Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 25/26] target-arm: make MAIR0/1 banked Greg Bellows
2014-11-05 23:23 ` [Qemu-devel] [PATCH v9 26/26] target-arm: add cpu feature EL3 to CPUs with Security Extensions Greg Bellows
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=1415229793-3278-5-git-send-email-greg.bellows@linaro.org \
--to=greg.bellows@linaro.org \
--cc=aggelerf@ethz.ch \
--cc=edgar.iglesias@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=serge.fdrv@gmail.com \
/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).