qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 v11 14/26] target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI
Date: Mon, 17 Nov 2014 10:47:46 -0600	[thread overview]
Message-ID: <1416242878-876-15-git-send-email-greg.bellows@linaro.org> (raw)
In-Reply-To: <1416242878-876-1-git-send-email-greg.bellows@linaro.org>

From: Fabian Aggeler <aggelerf@ethz.ch>

Add checks of SCR AW/FW bits when performing writes of CPSR.  These SCR bits
are used to control whether the CPSR masking bits can be adjusted from
non-secure state.

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>

---

v10 -> v11
- Moved cpsr_write() uncached_cpsr updated to before the mode setting.

v8 -> v9
- Move cpsr_write mask filtering above mode switch.
- Replace conditional checks removed in v8.

v7 -> v8
- Fixed incorrect use of env->uncached_cpsr A/I/F to use env->daif instead.
- Removed incorrect statement about SPSR to CPSR copies being affected by
  SCR.AW/FW.
- Fix typo in comment.
- Simpified cpsr_write logic

v3 -> v4
- Fixed up conditions for ignoring CPSR.A/F updates by isolating to v7 and
  checking for the existence of EL3 and non-existence of EL2.
---
 target-arm/helper.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 1148273..d555fe4 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -3644,6 +3644,8 @@ uint32_t cpsr_read(CPUARMState *env)
 
 void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
 {
+    uint32_t changed_daif;
+
     if (mask & CPSR_NZCV) {
         env->ZF = (~val) & CPSR_Z;
         env->NF = val;
@@ -3666,6 +3668,58 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
         env->GE = (val >> 16) & 0xf;
     }
 
+    /* In a V7 implementation that includes the security extensions but does
+     * not include Virtualization Extensions the SCR.FW and SCR.AW bits control
+     * whether non-secure software is allowed to change the CPSR_F and CPSR_A
+     * bits respectively.
+     *
+     * In a V8 implementation, it is permitted for privileged software to
+     * change the CPSR A/F bits regardless of the SCR.AW/FW bits.
+     */
+    if (!arm_feature(env, ARM_FEATURE_V8) &&
+        arm_feature(env, ARM_FEATURE_EL3) &&
+        !arm_feature(env, ARM_FEATURE_EL2) &&
+        !arm_is_secure(env)) {
+
+        changed_daif = (env->daif ^ val) & mask;
+
+        if (changed_daif & CPSR_A) {
+            /* Check to see if we are allowed to change the masking of async
+             * abort exceptions from a non-secure state.
+             */
+            if (!(env->cp15.scr_el3 & SCR_AW)) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "Ignoring attempt to switch CPSR_A flag from "
+                              "non-secure world with SCR.AW bit clear\n");
+                mask &= ~CPSR_A;
+            }
+        }
+
+        if (changed_daif & CPSR_F) {
+            /* Check to see if we are allowed to change the masking of FIQ
+             * exceptions from a non-secure state.
+             */
+            if (!(env->cp15.scr_el3 & SCR_FW)) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "Ignoring attempt to switch CPSR_F flag from "
+                              "non-secure world with SCR.FW bit clear\n");
+                mask &= ~CPSR_F;
+            }
+
+            /* Check whether non-maskable FIQ (NMFI) support is enabled.
+             * If this bit is set software is not allowed to mask
+             * FIQs, but is allowed to set CPSR_F to 0.
+             */
+            if ((A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_NMFI) &&
+                (val & CPSR_F)) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "Ignoring attempt to enable CPSR_F flag "
+                              "(non-maskable FIQ [NMFI] support enabled)\n");
+                mask &= ~CPSR_F;
+            }
+        }
+    }
+
     env->daif &= ~(CPSR_AIF & mask);
     env->daif |= val & CPSR_AIF & mask;
 
-- 
1.8.3.2

  parent reply	other threads:[~2014-11-17 16:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 16:47 [Qemu-devel] [PATCH v11 00/26] target-arm: add Security Extensions for CPUs Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 01/26] target-arm: extend async excp masking Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 02/26] target-arm: add async excp target_el function Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 03/26] target-arm: add banked register accessors Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 04/26] target-arm: add non-secure Translation Block flag Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 05/26] target-arm: add CPREG secure state support Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 06/26] target-arm: add secure state bit to CPREG hash Greg Bellows
2014-12-09 18:43   ` Peter Maydell
2014-12-09 19:00     ` Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 07/26] target-arm: insert AArch32 cpregs twice into hashtable Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 08/26] target-arm: move AArch32 SCR into security reglist Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 09/26] target-arm: implement IRQ/FIQ routing to Monitor mode Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 10/26] target-arm: add NSACR register Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 11/26] target-arm: add SDER definition Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 12/26] target-arm: add MVBAR support Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 13/26] target-arm: add SCTLR_EL3 and make SCTLR banked Greg Bellows
2014-11-17 16:47 ` Greg Bellows [this message]
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 15/26] target-arm: make CSSELR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 16/26] target-arm: make TTBR0/1 banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 17/26] target-arm: make TTBCR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 18/26] target-arm: make DACR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 19/26] target-arm: make IFSR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 20/26] target-arm: make DFSR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 21/26] target-arm: make IFAR/DFAR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 22/26] target-arm: make PAR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 23/26] target-arm: make VBAR banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 24/26] target-arm: make c13 cp regs banked (FCSEIDR, ...) Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 25/26] target-arm: make MAIR0/1 banked Greg Bellows
2014-11-17 16:47 ` [Qemu-devel] [PATCH v11 26/26] target-arm: add cpu feature EL3 to CPUs with Security Extensions Greg Bellows
2014-11-25 14:41 ` [Qemu-devel] [PATCH v11 00/26] target-arm: add Security Extensions for CPUs Peter Maydell

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=1416242878-876-15-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).