7.8 Context synchronization and ISB
DMB and DSB concern memory accesses. Context synchronization concerns context: system registers, PSTATE, and the translation and cache state that the PE uses to fetch and execute instructions. These are different axes. An ISB neither orders memory accesses (beyond the control+ISB idiom of 7.4) nor waits for anything to complete, and a DSB never makes a system-register write take effect. Most “barrier” bugs in early boot code mix up these two axes.
What counts as a context synchronization event
The Arm ARM defines a context synchronization event (CSE) as one of:
| Event | Condition |
|---|---|
Executing an ISB | always |
| Taking an exception | unless FEAT_ExS is implemented and SCTLR_ELx.EIS == 0, where ELx is the target Exception level |
Returning from an exception (ERET, ERETAA/ERETAB) | unless FEAT_ExS is implemented and SCTLR_ELx.EOS == 0, where ELx is the level the return is executed from |
| Exit from Debug state | always |
DCPS<n> or DRPS executed in Debug state | always |
Things that are not CSEs: DSB, DMB, branches (including BR to a freshly written address), WFI/WFE wake-up, and MSR itself.
FEAT_ExS (optional from v8.5, reported by ID_AA64MMFR0_EL1.EXS) adds SCTLR_ELx.EIS (bit 22) and SCTLR_ELx.EOS (bit 11). Without FEAT_ExS those bits are RES1, which is why the v8.0 RES1 masks for SCTLR_ELx include bits 22 and 11. With EIS/EOS cleared, exception entry or return no longer serialises the pipeline. That is cheaper for a hypervisor or EL3 that takes very frequent exceptions. The cost is that the handler must issue its own ISB wherever it depends on context written before the boundary. Formal studies of exception ordering (for example arXiv 2412.15140) treat the EIS/EOS = 0 configuration as rare and hard to program correctly. On a FEAT_ExS implementation the reset value of these bits is architecturally UNKNOWN, so boot code must set them explicitly.
Bring-up note: TF-A writes
SCTLR_EL3from a value that includes the architectural RES1 bits, soEIS=EOS= 1 by construction. If a firmware port computesSCTLR_EL3from scratch (mov x0, #(SCTLR_M | SCTLR_C | ...)), it clears bits 22 and 11. On aFEAT_ExScore this silently makes every SMC entry and everyERETnon-synchronizing. The resulting bugs are timing-dependent and appear only on that core.
What a CSE guarantees
For a context-changing operation (a direct write to a system register, a PSTATE change, a completed TLB or instruction cache invalidation) the rule is:
- Every instruction that appears in program order after the CSE is fetched, decoded and executed using the new context. None of them can have been observably fetched or executed early under the old one.
- Instructions between the context-changing operation and the CSE may observe either the old or the new context. Which one they see is not defined.
- The CSE does not wait for memory accesses or maintenance to complete. A
TLBIorIC IVAUbecomes a context change only once aDSBhas completed it. TheISBthen guarantees that later instructions see the result. - The guarantee is local to the PE that executes the CSE. Another PE needs its own CSE (see the cross-modifying-code rules in 8.6).
The second point explains why enabling the MMU needs an identity map. Between MSR SCTLR_EL3, x0 and the following ISB, instructions may be fetched with or without translation. Both views must therefore give the same address (9.3).
Direct and indirect reads and writes
The Arm ARM’s “Synchronization requirements for AArch64 System registers” are written in terms of four kinds of access:
- Direct read / direct write:
MRS/MSR(andSYS/SYSLforms) naming the register. - Indirect read: the hardware uses the register’s value as a side effect of executing some other instruction. Examples: the translation walk reading
TTBR0_EL1andTCR_EL1, the trap check for an FP instruction readingCPACR_EL1.FPEN, exception entry readingVBAR_EL3, and anERETreadingSPSR_EL3/ELR_EL3(a special case: a direct write to these is visible to a laterERETwithout a CSE). - Indirect write: the hardware updates the register as a side effect. Examples: exception entry writing
ESR_ELx/FAR_ELx/ELR_ELx, PMU counters counting, the counterCNTVCT_EL0advancing, and acknowledging an interrupt changing the GIC running priority.
The rules that matter:
- A direct read after a direct write to the same register, in program order, returns the written value. No synchronization is needed.
- Direct writes to the same register take effect in program order.
- An indirect read after a direct write needs a CSE between them. This is the common case. Writing
CPACR_EL1.FPENand then executingFMOVreadsFPENindirectly, so anISBis required. - A direct read is not ordered against the instruction stream around it without a CSE. That is why reading
CNTVCT_EL0or a PMU counter at a precise point needs anISBbefore theMRS(4.7, 16.5). - Memory-mapped registers (GIC Distributor/Redistributor,
CNTControlBase, SMMU, UART) are memory. They follow 7.9, and a CSE does nothing for them.
Some registers have extra rules stated in their own descriptions. Writes to PSTATE fields with MSR (immediate) (PAN, UAO, SSBS, DIT, TCO and the DAIF set/clear forms) are specified to affect subsequent instructions. That is why Linux toggles PAN without an ISB. When unmasking an interrupt with MSR DAIFClr, an ISB is what bounds the point by which a pending interrupt is taken. Check each register’s “Synchronization” or “Accessing” text in DDI0487 rather than generalising.
Which changes need one
| Change | Minimal sequence | Reason |
|---|---|---|
SCTLR_ELx.M, .C, .I | MSR; ISB | fetch and translation read these indirectly |
TTBRn_ELx, TCR_ELx, MAIR_ELx, TCR2_ELx, PIR_ELx | MSR…; ISB (plus TLB maintenance per 9.1) | walks are indirect reads |
TLBI | DSB ISH (completion); ISB | the DSB completes the invalidate; the ISB stops later instructions from having been fetched or translated with stale entries |
| new code in memory | DC CVAU; DSB ISH; IC IVAU; DSB ISH; ISB | 8.6 |
CPACR_EL1, CPTR_EL2, CPTR_EL3 (FP/SVE/SME enables) | MSR; ISB before the first FP/SIMD/SVE instruction | trap checks are indirect reads |
ZCR_ELx.LEN, SMCR_ELx | MSR; ISB | vector length is read indirectly |
VBAR_ELx | MSR; ISB before any exception that must use the new table | exception entry reads it indirectly |
SCR_EL3, HCR_EL2 routing and trap bits | MSR; ISB if they affect the current level; ERET suffices for the lower level | indirect reads at exception generation |
ICC_SRE_ELx | MSR; ISB before any other ICC_* access | required by the GICv3 spec (4.5) |
ICC_SGI1R_EL1 (sending an SGI) | DSB ISHST before, ISB after (Linux practice) | data visible before the IPI; force the write to issue |
PMCR_EL0, PMCNTENSET_EL0 around a measured region | MSR; ISB | prevents measured instructions from executing before the counters are enabled |
MDSCR_EL1, breakpoint/watchpoint registers | MSR; ISB | debug events are generated by indirect reads |
The world-switch case deserves a precise statement. In an EL3 exit path, restoring SCTLR_EL1, TTBR0_EL1, SCR_EL3.NS and so on, followed by ERET, needs no ISB: the ERET is the CSE, and nothing at EL3 depends on those values. Only a register that affects EL3’s own execution before the ERET needs an explicit ISB. Examples are CPTR_EL3 before EL3 saves FP state, or SCR_EL3.EA before EL3 unmasks SError.
// Enabling FP/SIMD at EL3, then saving the lower-EL FP context
mrs x0, cptr_el3
bic x0, x0, #(1 << 10) // CPTR_EL3.TFP = 0
msr cptr_el3, x0
isb // trap check is an indirect read
stp q0, q1, [x1], #32 // without the ISB this may trap (EC 0x07)
Validation note: Missing-
ISBbugs hide very well on models. QEMU TCG typically ends a translation block after a system-register write with side effects. The FVP executes instructions in order and with no visible speculation. Either way, the “new context” is effectively visible immediately. On silicon the same code may run with the old context for some instructions. Symptoms include an FP trap withESR_EL3.EC= 0x07 straight after enabling FP, exceptions vectoring to the oldVBAR, or a translation fault whoseFARpoints into the stale map. A directed test cannot prove theISBis needed, because either outcome is architecturally allowed. Treat this as a static review rule instead: for everyMSRto a register in the table, find the CSE before the first dependent instruction. A Tarmac trace from the FVP still helps confirm that theISBis present on the path that actually executes.
Security note: Exception return to a lower EL is the CSE that makes
SCR_EL3/HCR_EL2trap configuration and the lower EL’s translation registers take effect. If an EL3 handler changes those values and then returns along a path whereEOS= 0 on aFEAT_ExScore, the lower EL may run some instructions under the previous world’s context. KeepEOS= 1 at EL3.
Checkpoint
Q7.8.1 EL1 code updates TTBR0_EL1 to a new table, issues TLBI ASIDE1IS, and then executes DSB ISH. Which statement is correct?
- A. The sequence is complete.
DSBis a context synchronization event for TLB maintenance - B. An
ISBis still required before relying on the new translation for instructions on this PE, becauseDSBcompletes the invalidation but is not a CSE - C. An
ISBis required instead of theDSB, becauseISBwaits for the TLBI to complete - D. No barrier is needed, because the
MSR TTBR0_EL1is self-synchronizing
Answer
B. The two barriers do different jobs. DSB makes the TLBI complete (completion axis), and ISB makes later instructions fetch and translate using the new context (context axis). A is the common misconception. C reverses the roles, because an ISB waits for nothing.
Read more: Arm ARM (DDI0487), TLB maintenance requirements and the context synchronization event; Synchronization requirements for AArch64 System registers
Q7.8.2 EL3 restores a Non-secure EL1 context (SCTLR_EL1, TCR_EL1, TTBR0_EL1, VBAR_EL1), sets SCR_EL3.NS, and executes ERET. FEAT_ExS is not implemented. Where is an ISB needed?
- A. After every
MSR, because each system-register write must be synchronised individually - B. Immediately before the
ERET, becauseERETreadsSPSR_EL3indirectly - C. After the
ERET, at the first instruction of EL1 - D. Nowhere for these registers. The
ERETis itself a context synchronization event, and nothing at EL3 uses the restored values before it
Answer
D. Exception return is a CSE whenever FEAT_ExS is absent, or present with EOS = 1. The lower-EL registers are only read indirectly after the return. B is tempting, but direct writes to SPSR_EL3/ELR_EL3 are consumed by the ERET itself with no CSE required. With FEAT_ExS and SCTLR_EL3.EOS = 0 the answer would change.
Read more: Arm ARM (DDI0487), Context synchronization event; SCTLR_EL3 (EOS, EIS)
Q7.8.3 After writing the GIC Distributor’s GICD_CTLR (memory-mapped), firmware executes ISB and immediately enables interrupts, expecting the Distributor to be configured. Why is this reasoning wrong?
- A.
GICD_CTLRis a memory-mapped register, so its write is a Device memory access. It needs ordering or completion (DSB, and theRWPpoll the GIC defines), and a CSE does not provide that - B.
ISBis correct, but must come before the write - C. The
ISBis right, butDMB ISHis also needed because GIC registers are Inner Shareable - D. It is correct. Every register that configures the interrupt controller is synchronised by
ISB
Answer
A. A CSE applies to system registers and PSTATE. Memory-mapped registers follow Device memory ordering (7.9), and the GIC adds its own completion indicator (GICD_CTLR.RWP). C is wrong twice: Device memory is treated as Outer Shareable, and a DMB would only order the write, not complete it.
Read more: Arm ARM (DDI0487), Context synchronization event; GICv3 (IHI0069), GICD_CTLR.RWP