3.3 Routing and masking
Two separate questions
For every asynchronous exception the PE answers two questions, in this order:
- Routing: which EL is the target? The answer comes from
SCR_EL3andHCR_EL2, never from PSTATE. - Masking: given the target and the current EL, is the exception taken now, held pending, or subject to
PSTATE.{A,I,F}?
Most masking surprises come from treating DAIF as a “global interrupt disable”. It is not one. DAIF masks only exceptions whose target is the current EL, or EL1 when executing at EL0, plus one VHE case described below.
The routing controls
| Register.bit | Routes | Effect when 1 |
|---|---|---|
SCR_EL3.IRQ (bit 1) | physical IRQ | taken to EL3 from any EL |
SCR_EL3.FIQ (bit 2) | physical FIQ | taken to EL3 from any EL |
SCR_EL3.EA (bit 3) | physical SError and synchronous External aborts | taken to EL3 from any EL |
HCR_EL2.IMO (bit 4) | physical IRQ from EL0/EL1 | taken to EL2. Also enables virtual IRQ (HCR_EL2.VI, GIC list registers) at EL1/EL0 |
HCR_EL2.FMO (bit 3) | physical FIQ from EL0/EL1 | taken to EL2. Also enables virtual FIQ |
HCR_EL2.AMO (bit 5) | physical SError from EL0/EL1 | taken to EL2. Also enables virtual SError (HCR_EL2.VSE) |
HCR_EL2.TGE (bit 27) | everything from EL0 | IMO/FMO/AMO behave as 1 for all purposes except a direct read. Synchronous exceptions from EL0 go to EL2 |
HCR_EL2.TEA (bit 37, FEAT_RAS) | synchronous External aborts from EL0/EL1 | taken to EL2 |
SCR_EL3 routing wins over HCR_EL2. The HCR_EL2 bits apply only when EL2 is enabled in the current Security state. In Secure state that requires SCR_EL3.EEL2 == 1 (FEAT_SEL2), otherwise the HCR_EL2 bits are treated as 0 and Secure EL0/EL1 exceptions target EL1. Which GIC interrupts arrive as IRQ and which as FIQ depends on the group, the current Security state and EL. That is the GIC’s side of routing, covered in 4.3. Virtual interrupt delivery is in 11.4.
The physical IRQ routing table
The table below is for physical IRQ, with EL2 enabled in the current Security state. Replace SCR_EL3.IRQ/HCR_EL2.IMO/PSTATE.I with FIQ/FMO/F or EA/AMO/A to get the FIQ and SError tables. Entries mean:
- ELn, masked: taken to ELn when
PSTATE.I == 0, otherwise held pending; - ELn: taken to ELn regardless of PSTATE;
- pending: not taken at this EL.
SCR_EL3.IRQ | TGE | E2H | IMO | at EL0 | at EL1 | at EL2 | at EL3 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | x | 0 | EL1, masked | EL1, masked | pending | pending |
| 0 | 0 | x | 1 | EL2 | EL2 | EL2, masked | pending |
| 0 | 1 | 0 | x | EL2 | n/a | EL2, masked | pending |
| 0 | 1 | 1 | x | EL2, masked | n/a | EL2, masked | pending |
| 1 | x | x | x | EL3 | EL3 | EL3 | EL3, masked |
When EL2 is not enabled, use the first row with “EL2” read as “n/a”. n/a marks EL1, which is not in use when TGE == 1: an ERET to EL1 is an illegal return (3.2).
These rules follow from the table:
- To a higher EL: not maskable. A Non-secure kernel with
PSTATE.Iset cannot block an IRQ routed to EL2 byIMO, and a Secure-EL1 TEE withPSTATE.Fset cannot block a Group 0 FIQ routed to EL3 bySCR_EL3.FIQ. TF-A’s interrupt-management framework relies on this. - To a lower EL: held pending. At EL2 with
IMO == 0, an IRQ meant for EL1 waits until theERETto EL1. At EL3 withSCR_EL3.IRQ == 0, no IRQ is ever taken, whatever DAIF says, so masking DAIF at EL3 has no effect on IRQs that are not routed there. - The VHE exception. With
{E2H,TGE} == {1,1}, EL0 is part of the EL2&0 regime and behaves like EL0 under an EL1 kernel, soPSTATE.Iat EL0 masks interrupts that target EL2. WithE2H == 0, EL0 cannot mask EL2-routed interrupts. PSTATEat EL0. An EL0 attempt to write DAIF is trapped unlessSCTLR_EL1.UMA == 1. Even then, it can only mask exceptions targeting EL1 (or EL2 under VHE).
Synchronous External aborts
Synchronous External aborts are synchronous, so DAIF never masks them. They are routed like this: to EL3 if SCR_EL3.EA == 1; otherwise from EL0/EL1 to EL2 if HCR_EL2.TEA == 1 (or TGE == 1 for EL0); otherwise to the current EL, or EL1 for EL0. At EL3 with EA == 0, they are still taken to EL3, because no lower target exists.
When DAIF does not mask: a checklist
- The target is a higher EL (the table above).
- The exception is synchronous. This includes synchronous External aborts and every trap.
PSTATE.Daffects only debug exceptions, and only those targeting the current EL (16.1). - The PE is in
WFI/WFE. By the WFI wake-up event rules, a pending physical interrupt (or SError) wakesWFIeven when PSTATE masks it. The PE then resumes after theWFIwithout taking the exception. Code that spins “WFI with interrupts masked, then check” depends on this. - FEAT_NMI superpriority. With
SCTLR_ELx.NMI == 1, an interrupt with superpriority is not masked byPSTATE.I. It is masked byPSTATE.ALLINT, and also, whenSCTLR_ELx.SPINTMASK == 1, whilePSTATE.SP == 1. See 4.3. - The FEAT_DoubleFault controls below.
Double faults: errors while PSTATE.A is set
Every exception entry sets PSTATE.A. Without further controls, firmware-first RAS at EL3 has two problems:
- Masked errors. An SError raised while any EL3 handler runs, for example during an SMC, is held pending until EL3 unmasks or returns. By then the error may be reported against the wrong context.
- Two entry points. Synchronous External aborts arrive on the synchronous vector, which also dispatches SMCs and traps, while SErrors arrive on the SError vector. Error handling is split across two paths with different state-saving conventions, and a nested error re-enters at the same EL and overwrites
ELR_EL3,SPSR_EL3andESR_EL3unless the handler saved them first.
FEAT_DoubleFault (permitted from v8.4) addresses both:
| Control | Bit | Effect |
|---|---|---|
SCR_EL3.NMEA | 20 | Non-maskable External Aborts. When 1, SErrors are taken at EL3 regardless of PSTATE.A. Ignored (treated as 0) when SCR_EL3.EA == 0, unless FEAT_DoubleFault2 is implemented |
SCR_EL3.EASE | 19 | External Aborts to SError vector. When 1, synchronous External aborts taken to EL3 use the SError vector offset of VBAR_EL3 instead of the synchronous one |
Together, these let EL3 put all error handling behind a single SError entry that can be reached even from inside another handler. That entry must be written to expect nesting, for example by saving ELR_EL3/SPSR_EL3/ESR_EL3 first and detecting re-entry with a per-CPU flag. When NMEA is effectively 1, the effective value of SCTLR_EL3.IESB is also 1, so errors are synchronized at the exception boundary (3.4).
FEAT_DoubleFault2, an OPTIONAL feature from the 2022 extensions (Armv8.9/Armv9.4; check its exact permitted and mandatory levels in DDI0487 A2), extends the idea to the lower ELs and adds traps for masked errors:
| Control | Effect |
|---|---|
SCTLR2_EL1.NMEA (bit 2), SCTLR2_EL2.NMEA | PSTATE.A does not mask physical SErrors taken to EL1/EL2 |
SCTLR2_EL1.EASE (bit 5), SCTLR2_EL2.EASE | synchronous External aborts taken to EL1/EL2 use the SError vector offset |
HCRX_EL2.TMEA (bit 19) | below EL2, with EL2 enabled: synchronous External aborts with PSTATE.A == 1, and masked physical (and delegated) SErrors, at EL1/EL0 are taken to EL2, unless routed to EL3 |
SCR_EL3.TMEA (bit 51) | below EL3: synchronous External aborts with PSTATE.A == 1, and masked physical SErrors, are taken to EL3, unless routed to EL2 by another control |
SCTLR2_ELx must itself be enabled from above (SCR_EL3.SCTLR2En, HCRX_EL2.SCTLR2En), which is the pattern described in 2.6 and 17.3. Their interaction with virtual SErrors and with the delegated SErrors of FEAT_E3DSE (SCR_EL3.DSE, bit 57, and SCR_EL3.EnDSE, bit 58) is defined field by field: for example HCRX_EL2.TMEA explicitly covers delegated SErrors. Check the register descriptions rather than assuming either way.
Security note: with
SCR_EL3.EA == 1, a lower EL already cannot hide a physical SError from EL3, because an exception targeting a higher EL is not masked byPSTATE.A.SCR_EL3.TMEAmatters for the kernel-first configuration,SCR_EL3.EA == 0: errors normally go to the lower EL’s own handler, but an error the lower EL cannot take safely (a physical SError it is masking, or a synchronous External abort that arrives whilePSTATE.Ais set, typically inside its own exception handler) is diverted to EL3 instead of being held pending indefinitely or overwriting the lower EL’sELR/SPSR/ESR.
Bring-up note: “IRQs never arrive at EL1” and “SErrors land in EL3 instead of the kernel” (or the reverse) often trace back to the same register: an
SCR_EL3built withIRQ/FIQ/EAcopied from another platform’s TF-A configuration. DumpSCR_EL3andHCR_EL2before you start on the GIC checklist in 4.5.
Checkpoint
Q3.3.1 Non-secure EL2 runs with HCR_EL2.{E2H,TGE,IMO} == {0,0,0} and PSTATE.I == 0. SCR_EL3.IRQ == 0. A physical IRQ becomes pending. What happens?
- A. It is taken to EL2, because PSTATE.I is clear at EL2
- B. It is taken to EL1, because IMO is 0
- C. It stays pending until the PE executes at EL1 (or EL0), where it targets EL1 and is subject to PSTATE.I there
- D. It is taken to EL3, because no lower EL can accept it
Answer
C. With IMO == 0 and TGE == 0, the target is EL1. Exceptions are never taken to a lower EL, so at EL2 the IRQ is held pending, whatever DAIF says. A reads DAIF as global, but PSTATE.I only matters when the target is the current EL. Asynchronous exceptions are never “promoted” to EL3 (D).
Read more: Arm ARM (DDI0487), Asynchronous exception routing; Asynchronous exception masking
Q3.3.2 OP-TEE at Secure EL1 runs with PSTATE.{I,F} == {1,1}. SCR_EL3.FIQ == 1, SCR_EL3.EEL2 == 0, and a Group 0 interrupt is signalled as FIQ. What happens?
- A. It stays pending until OP-TEE clears
PSTATE.F - B. It is taken to EL3 at
VBAR_EL3 + 0x500, because an exception targeting a higher EL is not masked by PSTATE - C. It is taken to Secure EL1, because Secure EL2 is disabled
- D. It is taken to EL3 only if
SCR_EL3.NMEA == 1
Answer
B. SCR_EL3.FIQ routes the FIQ to EL3, which is above the current EL, so PSTATE.F at S-EL1 is irrelevant. The vector is “lower EL, AArch64”, FIQ. A assumes DAIF is global. NMEA concerns SErrors at EL3, not FIQs (D).
Read more: Arm ARM (DDI0487), SCR_EL3.FIQ; Asynchronous exception masking
Q3.3.3 A firmware-first RAS design has EL3 handling all errors. The core implements FEAT_DoubleFault but not FEAT_DoubleFault2. Which SCR_EL3 configuration makes SErrors interrupt EL3 handlers that run with PSTATE.A == 1, and sends synchronous External aborts taken to EL3 to the same entry point as SErrors?
- A.
SCR_EL3.EA = 1,NMEA = 0,EASE = 0 - B.
SCR_EL3.EA = 0,NMEA = 1,EASE = 1 - C.
SCR_EL3.EA = 1,NMEA = 0,EASE = 1 - D.
SCR_EL3.EA = 1,NMEA = 1,EASE = 1
Answer
D. EA routes errors to EL3. NMEA makes SErrors untouched by PSTATE.A at EL3, and it is ignored when EA == 0 without FEAT_DoubleFault2, which rules out B. EASE sends synchronous External aborts to the SError vector so that one handler deals with both. C leaves SErrors masked inside EL3 handlers.
Read more: Arm ARM (DDI0487), SCR_EL3.NMEA; SCR_EL3.EASE; FEAT_DoubleFault