4.3 Groups, security and priority
Three groups
Each SGI, PPI and SPI is assigned to a group by two bits, one in GICD_IGROUPR<n> (or GICR_IGROUPR0) and one in GICD_IGRPMODR<n> (or GICR_IGRPMODR0). These registers are accessible only from Secure state when GICD_CTLR.DS == 0.
IGRPMODR | IGROUPR | Group | Intended owner |
|---|---|---|---|
| 0 | 0 | Group 0 | EL3 firmware |
| 0 | 1 | Non-secure Group 1 | Normal world (Linux, hypervisor) |
| 1 | 0 | Secure Group 1 | Secure EL1/EL2 (OP-TEE, SPMC) |
| 1 | 1 | Reserved (behaves as Non-secure Group 1) | — |
LPIs are always Non-secure Group 1.
Each group has a Distributor enable (GICD_CTLR.EnableGrp0, EnableGrp1NS, EnableGrp1S) and a CPU-interface enable (ICC_IGRPEN0_EL1, ICC_IGRPEN1_EL1 banked by Security state, and ICC_IGRPEN1_EL3 for EL3 control of both Group 1 enables). An interrupt is forwarded only if both of its enables are set.
GICD_CTLR.DS (Disable Security) set to 1 removes the distinction: there is one Security state, Group 0 and Group 1, and Non-secure software can configure everything. It is meant for systems without EL3 or without a Secure world. On any system with a TEE, DS must be 0 and should be locked if the implementation allows.
Group to FIQ or IRQ
A group does not map to a fixed exception type. Which of FIQ or IRQ it raises depends on the PE’s current Exception level and Security state:
| Group | EL3 | Secure EL1/EL2 | Non-secure EL1/EL2 |
|---|---|---|---|
| Group 0 | FIQ | FIQ | FIQ |
| Secure Group 1 | FIQ | IRQ | FIQ |
| Non-secure Group 1 | FIQ | FIQ | IRQ |
The rule: an interrupt that belongs to the Security state the PE is currently in, at an EL below 3, is an IRQ. Anything else, meaning Group 0 or the other world’s Group 1, is an FIQ. The FIQ is then routed by SCR_EL3.FIQ/HCR_EL2.FMO (3.3), which is how “the other world’s interrupt” reaches EL3 or stays at the current EL by configuration. The table assumes AArch64 at EL3. For how the PE behaves in Realm state, see 12.4 and IHI0069.
How TF-A and OP-TEE use them
TF-A’s interrupt management framework names three types: INTR_TYPE_EL3 (Group 0), INTR_TYPE_S_EL1 (Secure Group 1) and INTR_TYPE_NS (Non-secure Group 1). A Secure Payload Dispatcher (SPD) registers a routing model for each type and Security state. That model sets SCR_EL3.FIQ and SCR_EL3.IRQ per world, and EL3 restores them on every world switch as part of each world’s saved SCR_EL3 (register_interrupt_type_handler() and set_routing_model() in TF-A’s interrupt_mgmt.c).
With OP-TEE (opteed SPD, GICv3, CFG_ARM_GICV3=y):
- OP-TEE native interrupts are Secure Group 1. While OP-TEE runs at S-EL1 they arrive as IRQ and are handled in place. While the Normal world runs they arrive as FIQ, are routed to EL3 (
SCR_EL3.FIQ = 1in Non-secure state), and opteed enters OP-TEE’s FIQ vector entry to handle them. - Foreign interrupts are Non-secure Group 1 interrupts that arrive while OP-TEE runs. They arrive at S-EL1 as FIQ. OP-TEE saves the thread and returns to the Normal world with an RPC (
OPTEE_SMC_RETURN_RPC_FOREIGN_INTR). There the interrupt is still pending and is taken as an IRQ. OP-TEE never acknowledges a Normal-world interrupt. - This is the opposite of GICv2 OP-TEE (Group 0 = FIQ = native), and a recurring source of confusion in ports.
- Group 0 interrupts (for example an EL3 watchdog or a RAS error interrupt with firmware-first handling) are always FIQ and routed to EL3. The EL3 handler reads
ICC_IAR0_EL1. A return of 1020 or 1021 tells it that the FIQ was really a Group 1 interrupt to be handed on (4.2).
With an S-EL2 SPMC (Hafnium), Secure Group 1 interrupts are owned by the SPMC, which virtualises them to secure partitions. Non-secure interrupts taken during secure execution are handled according to each partition’s FF-A “NS-interrupt action” (managed exit, signalled, or queued). See 12.3.
Priority, mask and running priority
Priority is 8 bits, and a lower value means higher priority. Only the top ICC_CTLR_EL1.PRIbits + 1 bits are implemented, and the rest read as zero. An implementation with two Security states implements at least 32 levels (5 bits). Priorities live in GICD_IPRIORITYR<n> / GICR_IPRIORITYR<n> (one byte per INTID) and in the LPI property table.
The CPU interface signals the highest-priority pending interrupt (HPPI) only if all of these hold:
- It is enabled, and its group is enabled at both the Distributor and the CPU interface.
- Its priority is strictly higher (numerically lower) than
ICC_PMR_EL1. A PMR of 0x00 masks everything. 0xFF lets everything through except priority 0xFF, which can never be signalled. - Its group priority is strictly higher than the running priority,
ICC_RPR_EL1. RPR is the priority of the highest-priority active interrupt on this PE, and 0xFF when none is active.
Condition 3 is preemption. The binary point register splits the priority into a group priority, used for preemption, and a subpriority, used only to choose between pending interrupts of the same group priority:
ICC_BPR0_EL1 value | Group priority bits | Subpriority bits |
|---|---|---|
| 0 | [7:1] | [0] |
| 1 | [7:2] | [1:0] |
| 2 | [7:3] | [2:0] |
| … | … | … |
| 7 | none (no preemption) | [7:0] |
ICC_BPR1_EL1 applies the same split shifted by one (value n gives group priority [7:n]), unless ICC_CTLR_ELx.CBPR makes Group 1 use BPR0. Each set bit in ICC_AP0Rn_EL1/ICC_AP1Rn_EL1 records one active group priority. That is why there can be as many nested active interrupts as there are group-priority levels, and why priority drops must happen in last-in, first-out order.
Secure and Non-secure views of priority
With DS == 0, priorities are shared between the worlds but not equally. When Non-secure software writes the priority of a Non-secure Group 1 interrupt, the value is stored as (v >> 1) | 0x80, and reads apply the reverse shift. Seen from the Secure view:
Secure view: 0x00 ............ 0x7F | 0x80 ............ 0xFF
only Secure/Group 0 | Non-secure writes land here
As a result Secure software can always pick a priority that the Normal world cannot outrank, and Non-secure software loses one bit of priority resolution. TF-A’s convention (GIC_HIGHEST_SEC_PRIORITY, PLAT_RAS_PRI, and so on) puts all Secure and Group 0 interrupts in the bottom half.
Whether the CPU interface applies the corresponding transform to Non-secure accesses of ICC_PMR_EL1 and ICC_RPR_EL1 depends on SCR_EL3.FIQ. With SCR_EL3.FIQ == 1, Non-secure PMR writes land in the 0x80–0xFF range of the Secure view, so the Normal world can never mask Secure-range priorities, and while PMR holds a Secure-range value, Non-secure writes to it are ignored. With SCR_EL3.FIQ == 0, Non-secure PMR and RPR accesses are not transformed: they see the Secure view directly, so the values Linux writes do not line up with the shifted priorities it programmed in the Distributor. Linux has to detect this case (gic_nonsecure_priorities) for its PMR-based pseudo-NMIs. See IHI0069, “Software accesses of interrupt priority”, for the full table.
Security note: In TF-A reviews, check that every Secure and Group 0 interrupt priority is below 0x80, and that
GICD_CTLR.DSis 0 and stays 0. An EL3-critical interrupt (watchdog, RAS) placed at, say, 0xA0 can be starved by a Normal-world handler that stays active at a higher Non-secure priority, or by a Non-secure PMR value.
FEAT_NMI, ALLINT and GICv3.3 superpriority
Before v8.8, a “non-maskable” interrupt for Linux was emulated: PSTATE.I stayed clear and masking was done with ICC_PMR_EL1 (irqchip.gicv3_pseudo_nmi=1). FEAT_NMI (added in Armv8.8 / v9.3; see DDI0487 A2 for its status) and FEAT_GICv3_NMI (GICv3.3) make it architectural.
GIC side (GICv3.3): an interrupt can be given the NMI property (GICD_INMIR<n> for SPIs, GICR_INMIR0 for SGIs and PPIs; support is reported by GICD_TYPER.NMI). Such an interrupt has superpriority, higher than any priority value. A Group 1 NMI must be acknowledged with ICC_NMIAR1_EL1. With NMIs enabled, ICC_IAR1_EL1 returns 1022 for it, so an ordinary IRQ path cannot accidentally consume an NMI. ICC_RPR_EL1 reports an active NMI separately from the 8-bit running priority.
PE side (FEAT_NMI), enabled per EL with SCTLR_ELx.NMI:
- An IRQ or FIQ with superpriority is not masked by
PSTATE.I/PSTATE.F. PSTATE.ALLINT, written withMSR ALLINT, #immor through theALLINTspecial register, masks all IRQs and FIQs taken to the current EL, superpriority included.SCTLR_ELx.SPINTMASK = 1gives an alternative model: superpriority interrupts are masked while the PE runs at ELx usingSP_ELx(PSTATE.SP == 1). Code onSP_EL0can take NMIs, and the exception entry and exit paths, which run onSP_ELx, are protected without explicitALLINTmanipulation.- On exception entry to ELx,
PSTATE.ALLINTis set toNOT SCTLR_ELx.SPINTMASK, so withSPINTMASK == 0the handler starts with all interrupts masked and must clearALLINTwhen it can accept an NMI.ALLINTis saved in and restored fromSPSR_ELx.HCRX_EL2.TALLINTlets EL2 trap EL1 writes toALLINT.
Bring-up note: Enabling
SCTLR_EL1.NMIwithout NMI-aware code is a silent hazard. Every region that was protected only byPSTATE.I/Fcan now be preempted by a superpriority interrupt, and an NMI that preempts the window between exception entry and savingELR_EL1/SPSR_EL1(for example becauseALLINTwas cleared too early) corrupts the return state. Either keepSPINTMASK = 0and clearALLINTonly after state is saved, or useSPINTMASK = 1withSP_EL0-based kernel code. QEMU (since 9.1) and the FVP model FEAT_NMI and the GICv3.3 NMI registers, so test there before silicon.
Checkpoint
Q4.3.1 OP-TEE (GICv3 build) is running at S-EL1 with SCR_EL3.FIQ = 0 in Secure state. A Non-secure Group 1 SPI targeted at this core becomes pending. What happens?
- A. An IRQ is taken at S-EL1, and OP-TEE acknowledges it with
ICC_IAR1_EL1and forwards the INTID to Linux - B. Nothing until OP-TEE returns, because Non-secure Group 1 interrupts are not signalled in Secure state
- C. An FIQ is taken at S-EL1. OP-TEE treats it as a foreign interrupt and exits to the Normal world, where the still-pending interrupt is taken as an IRQ
- D. An FIQ is taken to EL3, which acknowledges it and injects it into Linux
Answer
C. In Secure state, the other world’s Group 1 is signalled as FIQ. With SCR_EL3.FIQ = 0, the FIQ is taken at S-EL1. OP-TEE does not acknowledge it: it saves the thread and returns with a foreign-interrupt RPC. In Non-secure state the same interrupt is signalled as IRQ. A is wrong because acknowledging from S-EL1 would consume a Normal-world interrupt, and the IAR1 accessed from Secure state is the Secure Group 1 one anyway. D would need SCR_EL3.FIQ = 1 and is not opteed’s model for foreign interrupts.
Read more: GIC Architecture Specification (IHI0069), Interrupt grouping and interrupt signaling; OP-TEE documentation, Core architecture, “Native and foreign interrupts”
Q4.3.2 ICC_BPR0_EL1 = 2, PMR = 0xF0, and a Group 0 interrupt with priority 0x40 is active. Which newly pending Group 0 interrupt preempts it, and why?
- A. Priority 0x42, because a different subpriority counts as a different preemption level
- B. Priority 0x38, because its group priority (bits [7:3], 0x38) is higher than that of 0x40
- C. Priority 0x44, because any priority that passes the PMR check preempts an active interrupt
- D. None, because with BPR0 = 2 preemption is disabled
Answer
B. With BPR0 = 2, the group priority is bits [7:3]. Both 0x42 and 0x44 have group priority 0x40, equal to the active one, so they wait. Subpriority only orders pending interrupts of the same group, which rules out A. Passing the PMR is necessary but not sufficient: the group priority must also beat the running priority, which rules out C. D confuses value 2 with value 7, the only setting with no group-priority bits.
Read more: GIC Architecture Specification (IHI0069), Preemption; ICC_BPR0_EL1
Q4.3.3 An EL1 kernel sets SCTLR_EL1.NMI = 1 and SCTLR_EL1.SPINTMASK = 0. An IRQ exception (non-NMI) is taken to EL1. Which statement about the handler’s first instructions is correct?
- A.
PSTATE.ALLINTis 1 on entry, so even a superpriority interrupt cannot preempt until the handler clearsALLINT - B.
PSTATE.Iis set on entry, which also masks superpriority interrupts - C. Superpriority interrupts can preempt immediately, because only
SPINTMASK = 1protects the entry path - D.
ALLINTis not affected by exception entry and keeps its value from the interrupted context
Answer
A. On entry, PSTATE.ALLINT is set to NOT SCTLR_EL1.SPINTMASK, which is 1 here. That protects the window before ELR_EL1/SPSR_EL1 are saved. B is the tempting wrong answer: with SCTLR_EL1.NMI = 1, PSTATE.I deliberately does not mask superpriority interrupts. C and D misstate the entry behavior.
Read more: Arm ARM (DDI0487), FEAT_NMI; PSTATE.ALLINT; SCTLR_EL1.SPINTMASK; GIC Architecture Specification (IHI0069), NMIs