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 01/26] target-arm: extend async excp masking
Date: Wed, 5 Nov 2014 17:22:48 -0600 [thread overview]
Message-ID: <1415229793-3278-2-git-send-email-greg.bellows@linaro.org> (raw)
In-Reply-To: <1415229793-3278-1-git-send-email-greg.bellows@linaro.org>
This patch extends arm_excp_unmasked() to use lookup tables for determining
whether IRQ and FIQ exceptions are masked. The lookup tables are based on the
ARMv8 and ARMv7 specification physical interrupt masking tables.
If EL3 is using AArch64 IRQ/FIQ masking is ignored in all exception levels
other than EL3 if SCR.{FIQ|IRQ} is set to 1 (routed to EL3).
Signed-off-by: Greg Bellows <greg.bellows@linaro.org>
---
v8 -> v9
- Undo the use of tables for exception masking and instead go with simplified
logic based on the target EL lookup.
- Remove the masking tables
v7 -> v8
- Add IRQ and FIQ exeception masking lookup tables.
- Rewrite patch to use lookup tables for determining whether an excpetion is
masked or not.
v5 -> v6
- Globally change Aarch# to AArch#
- Fixed comment termination
v4 -> v5
- Merge with v4 patch 10
---
target-arm/cpu.h | 79 +++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 53 insertions(+), 26 deletions(-)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index cb6ec5c..0ea8602 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -1247,39 +1247,51 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
CPUARMState *env = cs->env_ptr;
unsigned int cur_el = arm_current_el(env);
unsigned int target_el = arm_excp_target_el(cs, excp_idx);
- /* FIXME: Use actual secure state. */
- bool secure = false;
- /* If in EL1/0, Physical IRQ routing to EL2 only happens from NS state. */
- bool irq_can_hyp = !secure && cur_el < 2 && target_el == 2;
- /* ARMv7-M interrupt return works by loading a magic value
- * into the PC. On real hardware the load causes the
- * return to occur. The qemu implementation performs the
- * jump normally, then does the exception return when the
- * CPU tries to execute code at the magic address.
- * This will cause the magic PC value to be pushed to
- * the stack if an interrupt occurred at the wrong time.
- * We avoid this by disabling interrupts when
- * pc contains a magic address.
+ bool secure = arm_is_secure(env);
+ uint32_t scr;
+ uint32_t hcr;
+ bool pstate_unmasked;
+ int8_t unmasked = 0;
+ bool is_aa64 = arm_el_is_aa64(env, 3);
+
+ /* Don't take exceptions if they target a lower EL.
+ * This check should catch any exceptions that would not be taken but left
+ * pending.
*/
- bool irq_unmasked = !(env->daif & PSTATE_I)
- && (!IS_M(env) || env->regs[15] < 0xfffffff0);
-
- /* Don't take exceptions if they target a lower EL. */
if (cur_el > target_el) {
return false;
}
switch (excp_idx) {
case EXCP_FIQ:
- if (irq_can_hyp && (env->cp15.hcr_el2 & HCR_FMO)) {
- return true;
- }
- return !(env->daif & PSTATE_F);
+ /* If FIQs are routed to EL3 or EL2 then there are cases where we
+ * override the CPSR.F in determining if the exception is masked or
+ * not. If neither of these are set then we fall back to the CPSR.F
+ * setting otherwise we further assess the state below.
+ */
+ hcr = (env->cp15.hcr_el2 & HCR_FMO);
+ scr = (env->cp15.scr_el3 & SCR_FIQ);
+
+ /* When EL3 is 32-bit, the SCR.FW bit controls whether the CPSR.F bit
+ * masks FIQ interrupts when taken in non-secure state. If SCR.FW is
+ * set then FIQs can be masked by CPSR.F when non-secure but only
+ * when FIQs are only routed to EL3.
+ */
+ scr &= is_aa64 || !((env->cp15.scr_el3 & SCR_FW) && !hcr);
+ pstate_unmasked = !(env->daif & PSTATE_F);
+ break;
+
case EXCP_IRQ:
- if (irq_can_hyp && (env->cp15.hcr_el2 & HCR_IMO)) {
- return true;
- }
- return irq_unmasked;
+ /* When EL3 execution state is 32-bit, if HCR.IMO is set then we may
+ * override the CPSR.I masking when in non-secure state. The SCR.IRQ
+ * setting has already been taken into consideration when setting the
+ * target EL, so it does not have a further affect here.
+ */
+ hcr = is_aa64 || (env->cp15.hcr_el2 & HCR_IMO);
+ scr = false;
+ pstate_unmasked = !(env->daif & PSTATE_I);
+ break;
+
case EXCP_VFIQ:
if (!secure && !(env->cp15.hcr_el2 & HCR_FMO)) {
/* VFIQs are only taken when hypervized and non-secure. */
@@ -1291,10 +1303,25 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
/* VIRQs are only taken when hypervized and non-secure. */
return false;
}
- return irq_unmasked;
+ return !(env->daif & PSTATE_I) &&
+ (!IS_M(env) || env->regs[15] < 0xfffffff0);
default:
g_assert_not_reached();
}
+
+ /* Use the target EL, current execution state and SCR/HCR settings to
+ * determine whether the corresponding CPSR bit is used to mask the
+ * interrupt.
+ */
+ if ((target_el > cur_el) && (target_el != 1) && (scr || hcr) &&
+ (is_aa64 || !secure)) {
+ unmasked = 1;
+ }
+
+ /* The PSTATE bits only mask the interrupt if we have not overriden the
+ * ability above.
+ */
+ return unmasked || pstate_unmasked;
}
static inline CPUARMState *cpu_init(const char *cpu_model)
--
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 ` Greg Bellows [this message]
2014-11-05 23:37 ` [Qemu-devel] [PATCH v9 01/26] target-arm: extend async excp masking 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 ` [Qemu-devel] [PATCH v9 04/26] target-arm: add non-secure Translation Block flag Greg Bellows
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-2-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).