Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

This book covers the Arm A-profile architecture, Armv8-A and Armv9-A in AArch64 state, starting from the Arm Architecture Reference Manual (Arm DDI0487, “the Arm ARM”). Its aim is to get you from “I use this” to “I can reason about this from the Arm ARM”. That means precise semantics, register-level detail, the reasons behind each rule, and how each rule shows up when you bring up a new SoC or try to show that one is correct.

Status: draft. The text was drafted with AI assistance and checked by separate AI review passes. It has not yet been reviewed against DDI0487 by a human. Treat each claim as something to confirm in the Arm ARM or the relevant companion specification before you rely on it, and report any errors you find.

Who it is for

The reader we have in mind is a systems software engineer with several years of TEE and device-security work: OP-TEE, EL3 code review, and kernel hardening such as PAN, shadow call stacks, KASLR and KASAN. That engineer now works on firmware bring-up (TF-A, an RTOS such as FreeRTOS, pre-silicon platforms, multi-chiplet SoCs) and may move into silicon validation. The book assumes:

  • You already know the exception model, interrupt handling with the GIC, and TrustZone-A with an EL3 monitor. The parts on these topics are marked Review part and are kept concise and register-precise.
  • Your weak spots are the memory system and speculation. The book spends most of its depth on these: what DMB, DSB and ISB actually guarantee, what “observed” and “complete” mean, coherency and the Points of Coherency and Unification, cache and TLB maintenance, Spectre-class attacks and their mitigations, and MTE. These are the deep-dive parts.
  • You are not primarily an embedded-Linux engineer. Firmware (TF-A, bare-metal tests, RTOS ports) is the main idiom. Linux arm64 code appears as a reference mapping (“this is where Linux does it”), not as the thing being taught.

If you are a validation or verification engineer who already knows the memory system well, the silicon-validation reading path skips the introductory material.

What it covers

PartsTopicCharacter
1–2Versions, FEAT_ names and discovery; the AArch64 programmer’s model, system registers and the trap-control mapFoundation
3–4Exceptions, SError, GICv3/v4 and the Generic TimerReview parts
5Translation regimes, descriptors, permissions, faults (ends with a lab)Core
6–10Memory types, the ordering model, caches and coherency, TLB maintenance and break-before-make, atomics (Parts 7 and 8 end with labs and exercises)Deep dive
11EL2, VHE, nested virtualization, stage 2, the SMMUCore
12TrustZone-A, secure boot, PSCI/SMCCC/FF-A, RME and CCA, MECReview part
13PAC, BTI, GCS, translation hardening, the upper address bits, MTECore
14How speculation is modelled, Spectre v1/v2/v4, BHB, Meltdown-class leaks, world-switch isolation (ends with exercises)Deep dive
15Advanced SIMD and FP, SVE/SVE2, SME, and what firmware must do about themCore
16Self-hosted and external debug, CoreSight, PMUv3, AMU, SPE and trace, RASCore
17–18Reset to OS handoff, multi-chiplet bring-up, crash and hang triage, pre-silicon environments, directed tests, BSA/SBSA conformanceApplied

The front matter tells you how to use the book, including four reading paths, how to read the Arm ARM itself, and how to set up the labs on QEMU, the Arm FVP and herdtools7.

Not covered: the AArch32 instruction sets and AArch32 system programming, except where AArch32 state affects AArch64 firmware (for example SCR_EL3.RW or HCR_EL2.RW). Also not covered: the microarchitecture of particular cores, except as clearly labelled examples, and SoC IP that Arm does not specify architecturally. Interconnect protocols (AMBA CHI, ACE) appear only as far as they explain what a maintenance instruction or barrier becomes on the bus.

Architecture versions and the issue of DDI0487 it tracks

The book covers Armv8.0-A to Armv8.9-A (the v8 line ends at v8.9) and Armv9.0-A to Armv9.6-A and later. Up to v9.4, each Armv9.n-A extension pairs with Armv8.(n+5)-A. From v9.5 onward there is no v8 counterpart (1.1).

Every version claim is phrased as “permitted from vX.Y” (the earliest version in which an implementation may include the feature) and, where relevant, “mandatory from vX.Y” (the version from which an implementation that claims compliance must include it). These come from the feature descriptions in DDI0487 chapter A2, not from compiler -march tables. The two often disagree, because a toolchain’s -march=armv8.5-a describes what the compiler may emit, not what the architecture requires. Where a section was not sure of a version, it says “see DDI0487 A2” rather than guessing.

The text tracks DDI0487 issue M.a and the Arm ARM Known Issues document published against it (Arm document 102105). Sections that depend on a Known Issues entry say so (see 7.5). Check the title page of your copy. If yours is a later issue, assume that anything touched by a newer Known Issues entry or a newer extension may have changed. For features newer than the tracked issue, the authoritative sources are Arm’s A-profile architecture extensions pages and the per-release register (DDI0601) and A64 instruction set (DDI0602) documentation (Reading the Arm ARM).

The companion book: Armv8-M for A-profile Engineers

A sibling book, Armv8-M for A-profile Engineers (the armv8m-intro-mdbook directory next to this one), covers the M-profile: the programmer’s model, the NVIC and exception stacking, PMSAv8 and the MPU, M-profile barriers and caches, and TrustZone for Armv8-M with TF-M. It is written the other way round from this book. It starts from A-profile knowledge and explains each M-profile mechanism by contrast.

The two books meet in the same SoC. A modern A-profile system usually contains M-profile cores as well: a system control processor that sequences power and clocks, a manageability controller, and often a root-of-trust or runtime security engine that runs before the first A-profile instruction. In bring-up, the A-profile boot chain in Part 17 usually depends on those cores. Read the M-profile book if you have to port, debug or review that firmware. Read this one for everything that runs on the application cores. The two profiles share instruction names and much vocabulary, but the memory models, exception models and security models behind them differ. Do not carry an intuition about, say, DSB or a Security state from one profile to the other without checking it in that profile’s manual (DDI0553 for Armv8-M).

Typographic conventions

  • Registers, fields, instructions and code are in code font: SCTLR_EL3.M, TLBI VAE1IS, ID_AA64MMFR1_EL1.HAFDBS. Bit ranges are written [n:m].
  • The architecture’s defined terms are used exactly: PE (processing element) rather than “core” when the statement is architectural, observer, complete, Point of Coherency (PoC), context synchronization event. Capitalised terms such as IMPLEMENTATION DEFINED, UNKNOWN and CONSTRAINED UNPREDICTABLE have the meanings given in Reading the Arm ARM.
  • FEAT_ names (FEAT_LSE, FEAT_RME) identify features. Version numbers say only when a feature became permitted or mandatory.
  • Section numbers such as “7.8” refer to this book. References to the Arm ARM use chapter or section titles and register names rather than DDI0487 section numbers, because those numbers move between issues. The one exception is chapter A2, the list of architecture extensions, which is cited by number.

How to use this book

The book is meant to be read selectively. Each part says at its top what it assumes and what you can skip, and the four reading paths below give explicit section lists for the four reasons you are most likely to be reading it.

What a section looks like

Each section is a 5–10 minute read (labs, exercise sets and some deep-dive sections run longer), and covers one topic at register level. A section usually contains:

  • The rule, stated in the Arm ARM’s terms, followed by the reason for it. For the memory model, the reason is usually an observable outcome that the rule permits or forbids.
  • Register and field tables for the controls involved, with bit positions where they are stable across issues.
  • A short example. A64 code is written in GNU assembler syntax, firmware code in C, and Arm pseudocode (ASL) or layout diagrams in plain text blocks. Examples are kept minimal and are meant to be correct as written, not illustrative pseudo-assembly.
  • Callouts (below) where the topic has a direct bring-up, security or validation consequence.
  • A Checkpoint of 2–3 questions at the end.

Each part opens with a three-line block:

  • Prerequisites: the sections the part assumes, as links.
  • If you already know: what you can skim or skip, and which subsections not to skip even if the topic is familiar.
  • Why this matters for bring-up/validation: one sentence on why the part is worth your time.

Parts 3, 4 and 12 are marked Review part. They cover the reader’s strong areas and are concise and register-precise rather than introductory. Parts 6–10 and 14 are the deep-dive parts. They go slowly, define each term before using it, and use litmus tests and worked sequences to show why a rule exists.

Callouts

Three kinds of callout are used, and only where they add something:

Bring-up note: A consequence for early firmware or first silicon. Typical content: a reset value that is UNKNOWN and must be written, an enable bit that EL3 must set before a lower EL can use a feature, or a sequence that works on a model but not on hardware.

Security note: A consequence for isolation between Exception levels, Security states or worlds. Typical content: state that leaks across a world switch if it is not saved, cleared or invalidated, or a trap that must be enabled for a guarantee to hold.

Validation note: How to test the rule. It says what to run, what a failure looks like (a hang, a stale value, a fault syndrome, a litmus outcome that should be impossible) and which register or PMU event confirms the result. Parts 5–10, 14 and 16 each contain at least one.

Checkpoint quizzes

Each section ends with a Checkpoint of 2–3 multiple-choice questions, numbered Q<part>.<section>.<n>. Each has exactly one defensible answer, and the wrong options are chosen to be plausible misconceptions. The questions test reasoning about sequences and outcomes rather than recall.

  • Click an option (or focus it with Tab and press Enter or Space). The book marks your choice right or wrong, shows the correct option and opens the explanation. The explanation ends with a Read more pointer into the Arm ARM or a companion specification.
  • Your answer is saved only in your browser, in local storage, keyed by page and question. Nothing is sent anywhere. Returning to the page shows your earlier answer. Clearing site data, using a private window, or switching browsers or machines starts you afresh.
  • Try again appears under an answered question. It clears the saved answer for that question and lets you choose again.
  • Without JavaScript, the questions render as plain lists, and the Answer disclosure under each one holds the answer and its explanation.

A wrong answer is useful information. Most distractors are a rule that holds on some other architecture, in some other context, or on most implementations without being guaranteed. Reread the explanation of why the tempting option is wrong.

Labs

Parts 5, 7 and 8 end with a runnable lab:

LabRuns onWhat it does
5.9 Debugging translation with AT and PAR_EL1QEMU virt or FVP, bare-metal at EL3Builds translation tables with deliberate faults and decodes each with AT S1E1R and PAR_EL1
7.11 Litmus testing from model to siliconherd7, then litmus7 on QEMU, FVP and a boardComputes what the memory model allows, then measures what implementations do
8.10 Validating coherency and cache maintenanceQEMU, FVP with cache-state modelling, and a boardTests with checkers and PMU fingerprints, each run again with the maintenance removed

Lab setup covers installation, a minimal bare-metal EL3 image that the labs build on, and the labs/partNN/ directory layout. Each lab says when a step needs real hardware. Read 18.4 before trusting a model result: QEMU does not model caches or a weak memory order, and the FVP models cache state only when asked and never reorders memory accesses.

Exercises

7.11, 8.10 and 14.8 contain applied exercises. Most take the form “here is a sequence from firmware or a driver: which barrier, maintenance operation or mitigation is missing, and why?” Each answer is collapsed under an Answer disclosure. Write your answer down before you open it, because the value is in having to state the reason. The answers name the minimum sufficient sequence and explain why stronger but common alternatives are unnecessary or still insufficient.

How the parts depend on each other

Read the diagram from the top. A part assumes every part above it on its own line of descent, and A --> B means that B assumes A. A note such as (+7.8) lists further prerequisites that the lines do not show. Only the main dependencies appear. Each part’s opener lists the exact prerequisite sections.

[1] Landscape: versions, FEAT_, ID registers
 |
[2] AArch64 programmer's model
 |
[3] Exception model (review) --------------> [15] SIMD, FP, SVE, SME (+7.8)
 |
 +---------------------------+
 |                           |
[4] GIC and timers (review) [5] VM I: translation ------> [11] Virtualization (+4)
 |                           |
 |                          [6] Memory types and attributes
 |                           |
 |                          [7] Memory ordering model
 |                           |
 |                          [8] Caches and coherency --+--> [10] Atomics
 |                           |                         +--> [13] Hardening, MTE
 |                           |                         +--> [16] Debug, trace, PMU, RAS
 |                          [9] VM II: TLBs, BBM, MMU on
 |                           |
 |                           +--> [14] Speculation
 |                           +--> [18] Debugging, validation, compliance (+16)
 |                           |
 +------------------------> [12] Secure world, firmware, RME
                             |
                            [17] Boot and bring-up

The same graph as a table, for searching:

PartAssumes
1nothing (start here on every path)
21
32
42, 3
52, 3
65
73, 6
86, 7
95, 6, 7, 8
106, 7, 8
112, 3, 4, 5
122, 3, 4, 5, 8, 9
132, 3, 5, 6, 8
143, 6, 7, 9
152, 3, 7.8
162, 3, 7.8, 8
173, 4, 8, 9, 12 (17.1–17.3 can be read straight after Part 5)
183, 5, 9, 16

Reading paths

Four paths, each an explicit, ordered list of sections. They overlap. A section on more than one path is written to serve all of them. Every path assumes you have read this page and Reading the Arm ARM. Lab setup is needed only for the labs on that path.

B: bring-up

For bringing up firmware on a new SoC or a new core: from reset to a booted OS, and debugging what goes wrong along the way. 17.1–17.3 come directly after Part 5. They use forward references into Parts 8 and 9, which you can follow or leave for later.

Foundations

  1. 1.1 Versions, FEAT_ names and discovery
  2. 1.3 Implementations and errata
  3. 2.5 System registers
  4. 2.6 The trap-control map
  5. 3.2 Entry and return
  6. 3.3 Routing and masking
  7. 3.4 SError, architecturally

Interrupts and timers

  1. 4.1 GICv3 architecture
  2. 4.2 Interrupt types and lifecycle
  3. 4.3 Groups, security and priority
  4. 4.4 LPIs and the ITS
  5. 4.5 GIC bring-up and the interrupt-never-arrives checklist
  6. 4.6 The Generic Timer
  7. 4.7 Reading time correctly

Translation, then early boot

  1. 5.1 Translation regimes and stages
  2. 5.2 TCR_ELx and TCR2_ELx
  3. 5.3 Descriptors and walk mechanics
  4. 5.8 MMU faults and how to decode them
  5. 5.9 Lab: debugging translation with AT and PAR_EL1
  6. 17.1 Reset
  7. 17.2 Initialising EL3
  8. 17.3 The EL3 feature-enable checklist

The memory system as firmware sees it

  1. 6.1 A hardware mental model (non-architectural)
  2. 6.5 MAIR_ELx and AttrIndx
  3. 7.5 DMB
  4. 7.6 DSB
  5. 7.7 Acquire/release as one-way barriers
  6. 7.8 Context synchronization and ISB
  7. 7.9 Device memory ordering
  8. 7.10 Ordering patterns
  9. 8.4 Points of coherency and beyond
  10. 8.5 Data cache maintenance
  11. 8.6 Instruction cache maintenance and cross-modifying code
  12. 8.7 DMA and non-coherent masters
  13. 8.8 Caches at power transitions
  14. 9.1 TLBs and TLB maintenance
  15. 9.2 Break-before-make and FEAT_BBM
  16. 9.3 Turning the MMU and caches on
  17. 10.4 Waiting and locking

Firmware interfaces, debug access and the rest of boot

  1. 12.2 The architectural contract of a secure boot chain
  2. 12.3 Firmware interfaces
  3. 16.2 External debug and CoreSight
  4. 17.4 Secondary cores and CPU power states
  5. 17.5 Multi-chiplet bring-up
  6. 17.6 Handing off to the OS

When it breaks

  1. 18.1 Decoding a crash end to end
  2. 18.2 Triage of a hung core
  3. 18.3 Bring-up failure signatures

M: memory system

For the reader whose weak spot is the memory system: Parts 6–10 in order, then speculation’s effect on the memory system, then the parts of MTE and address tagging that depend on it. This path assumes you can read a translation table descriptor. If you cannot yet, read 5.1–5.3 first.

  1. 6.1 A hardware mental model (non-architectural)
  2. 6.2 Normal and Device memory
  3. 6.3 Cacheability
  4. 6.4 Shareability
  5. 6.5 MAIR_ELx and AttrIndx
  6. 6.6 Mismatched attributes and aliases
  7. 7.1 Observers, “observed by” and “completes”
  8. 7.2 Single-copy and multi-copy atomicity
  9. 7.3 Litmus tests
  10. 7.4 Dependencies
  11. 7.5 DMB
  12. 7.6 DSB
  13. 7.7 Acquire/release as one-way barriers
  14. 7.8 Context synchronization and ISB
  15. 7.9 Device memory ordering
  16. 7.10 Ordering patterns
  17. 7.11 Lab and exercises: litmus testing from model to silicon
  18. 8.1 Cache organisation
  19. 8.2 Hardware coherency concepts
  20. 8.3 Coherency at system scale: instructions to transactions
  21. 8.4 Points of coherency and beyond
  22. 8.5 Data cache maintenance
  23. 8.6 Instruction cache maintenance and cross-modifying code
  24. 8.7 DMA and non-coherent masters
  25. 8.8 Caches at power transitions
  26. 8.9 MPAM: resource partitioning and monitoring
  27. 8.10 Lab and exercises: validating coherency and cache maintenance
  28. 9.1 TLBs and TLB maintenance
  29. 9.2 Break-before-make and FEAT_BBM
  30. 9.3 Turning the MMU and caches on
  31. 10.1 Exclusives
  32. 10.2 LSE atomics (FEAT_LSE)
  33. 10.3 Wide and unaligned accesses
  34. 10.4 Waiting and locking
  35. 14.1 How speculation is modelled and what it attacks
  36. 14.2 Speculation and the memory system
  37. 13.3 Who owns the upper address bits
  38. 13.4 MTE architecture
  39. 13.5 MTE tag checking
  40. 13.6 MTE in a system

S: security

For TEE, hypervisor and platform-security work: isolation boundaries, the secure-world and Realm architecture, hardening features and speculation. This path assumes the exception model from Part 3, which this reader is expected to know already.

  1. 2.1 Exception levels, Security states and execution states
  2. 5.5 Access permissions
  3. 11.5 The SMMU (SMMUv3)
  4. 12.1 TrustZone-A recap, precisely
  5. 12.2 The architectural contract of a secure boot chain
  6. 12.3 Firmware interfaces
  7. 12.4 RME and Arm CCA
  8. 12.5 Memory Encryption Contexts (FEAT_MEC)
  9. 13.1 Pointer Authentication and BTI
  10. 13.2 Guarded Control Stack and Translation Hardening
  11. 13.3 Who owns the upper address bits
  12. 13.4 MTE architecture
  13. 13.5 MTE tag checking
  14. 13.6 MTE in a system
  15. 14.1 How speculation is modelled and what it attacks
  16. 14.2 Speculation and the memory system
  17. 14.3 Spectre v1 (bounds check bypass)
  18. 14.4 Spectre v2 and BHB
  19. 14.5 Spectre v4 (speculative store bypass)
  20. 14.6 Meltdown-class leaks
  21. 14.7 Prediction isolation on a world switch
  22. 14.8 Exercises: auditing for missing mitigations
  23. 17.3 The EL3 feature-enable checklist

V: silicon validation

For pre-silicon and post-silicon validation: what the architecture permits (so you know what counts as a bug), how coherency becomes transactions, the instruments (PMU, AMU, trace, RAS), and how to write tests that can fail. This path assumes the ordering and coherency vocabulary of Parts 6–8. If those are new to you, take the M path through Part 8 first.

  1. 1.1 Versions, FEAT_ names and discovery
  2. 1.2 What Armv9-A actually changed
  3. 1.3 Implementations and errata
  4. 6.1 A hardware mental model (non-architectural)
  5. 7.1 Observers, “observed by” and “completes”
  6. 7.2 Single-copy and multi-copy atomicity
  7. 7.3 Litmus tests
  8. 7.11 Lab and exercises: litmus testing from model to silicon
  9. 8.2 Hardware coherency concepts
  10. 8.3 Coherency at system scale: instructions to transactions
  11. 8.9 MPAM: resource partitioning and monitoring
  12. 8.10 Lab and exercises: validating coherency and cache maintenance
  13. 9.1 TLBs and TLB maintenance
  14. 16.2 External debug and CoreSight
  15. 16.3 PMUv3
  16. 16.4 Activity Monitors (AMU)
  17. 16.5 The PMU as a validation instrument
  18. 16.6 Profiling and trace
  19. 16.7 RAS architecture
  20. 16.8 RAS handling and error injection
  21. 17.5 Multi-chiplet bring-up
  22. 18.1 Decoding a crash end to end
  23. 18.2 Triage of a hung core
  24. 18.3 Bring-up failure signatures
  25. 18.4 Pre-silicon environments and their blind spots
  26. 18.5 Writing directed architectural tests
  27. 18.6 Conformance and platform standards

Which parts each path uses

“all” means the whole part. An empty cell means the path does not use the part.

No path covers Part 15 or most of Part 11. Read 15.3 if you write EL3 or EL2 code on a core with SVE or SME, and Part 11 when you work on a hypervisor or need the stage 2 and SMMU material in full.

Other conventions

  • Search with the magnifying glass or by pressing s or /. Register names are searchable: HCR_EL2, TCR2_EL1.
  • Linux and TF-A references name a function or file, such as TF-A’s el3_entrypoint_common macro or Linux’s arch/arm64/include/asm/tlbflush.h, so you can find it in any recent tree. They are mappings, not specifications. When the code and the Arm ARM disagree, the Arm ARM wins, and the difference is usually a deliberate implementation choice or a workaround for an erratum.
  • Appendices (feature timeline, register cheat sheet, barrier and maintenance recipes, ESR decode card, bring-up checklists, glossary, references) collect lookup material that the parts link to.

Reading the Arm ARM

The Arm Architecture Reference Manual for A-profile architecture (Arm DDI0487) runs to more than 10,000 pages. Nobody reads it front to back. This page explains how it is organised, which companion documents fill the gaps it leaves, how to read its pseudocode, and the precise meaning of the capitalised words that decide what you may rely on.

How DDI0487 is organised

The manual is divided into lettered parts. Chapter numbers inside a part move between issues as material is added, so this book cites chapter and section titles, not numbers. The one exception is chapter A2, the list of architecture extensions, which is cited by number.

PartContentsWhen you go there
AIntroduction and architecture overview. Chapter A2 lists the architecture extensions and every FEAT_ name, with the version in which each feature is permitted and the version from which it is mandatory, plus the dependencies between features.“Is this feature in v9.2?”, “What does FEAT_X require?”
BThe AArch64 application-level architecture: the application programmer’s model and the AArch64 application-level memory model, which covers memory types and attributes, ordering, observability and completion, barriers, atomicity, and caches as software at EL0 sees themEverything in Parts 6, 7 and 10 of this book
CThe A64 instruction set: encoding overview, encoding index, and an alphabetical description of each instruction (base, SIMD and FP and, in recent issues, SVE and SME), each with its decode and operation pseudocode“What exactly does LDAPR / DC CIVAC / TLBI RVAE1IS do?”
DThe AArch64 system-level architecture: the system programmer’s model, exceptions, the virtual memory system architecture (VMSA, translation and TLB maintenance), the Generic Timer, self-hosted debug, the PMU, the AMU, MTE, RME and other system features, and the AArch64 system register descriptionsMost of Parts 2–5, 8, 9 and 11–17
E, F, GAArch32: the application level, the A32 and T32 instruction sets, and the system levelOnly when AArch32 state affects your AArch64 code (EL0 compatibility, SPSR encodings, SCR_EL3.RW)
HExternal debug: the debug state, halting, the external debug interface and its registers16.2, 18.2
IMemory-mapped system register descriptions: the memory-mapped Generic Timer frames (CNTControlBase, CNTCTLBase, CNTBaseN), the external debug, CTI, PMU and AMU register frames4.6, 16.2
JThe architectural pseudocode library: the shared functions used by every instruction and register description (translation, exception entry, permission checks, the memory model’s access functions)When prose is ambiguous
KAppendices, including the architectural constraints on UNPREDICTABLE behaviors and the barrier litmus tests, which also give the recommended barrier and maintenance sequences for common cases7.3, 7.10, 8.5

A glossary closes the manual. The terms the Arm ARM sets in small capitals, such as IMPLEMENTATION DEFINED and UNKNOWN, are defined there, and the glossary entry is the definition that counts.

Two practical habits help:

  • Use the PDF’s bookmarks and full-text search, not the page numbers. Search for the register name with its suffix (TCR2_EL1), or for a quoted phrase from the rule you want (“context synchronization event”).
  • Read the rule’s conditions, not just the rule. Most statements are scoped by Exception level, Security state, feature presence (“When FEAT_X is implemented”) or memory type. A rule quoted without its conditions is usually wrong somewhere.

Errata to the manual

Arm publishes a Known Issues document for each DDI0487 issue (Arm document 102105). The entries are corrections and clarifications, some of which change behaviour that software relies on. 7.5 describes an example: the redefinition of the DMB shareability argument. When this book cites a Known Issues entry, it gives the entry identifier and the issue it was raised against.

Registers and instructions outside the PDF

The register and instruction descriptions are also published per architecture release, as HTML and in machine-readable form:

  • Arm A-profile Architecture Registers (DDI0601) has one page per system register. Each page gives the field layout, the conditions for each field, the reset behaviour, and an Accessing section containing the pseudocode for each MRS/MSR encoding, including every trap. That section answers questions such as “which EL does this access trap to, and with what EC?”
  • A64 Instruction Set Architecture (DDI0602) is the instruction descriptions in the same form.
  • The machine-readable specification. Arm publishes the register and instruction data as XML and as JSON (the Arm Architecture Machine Readable Specification). Tools that generate register headers, disassemblers and test generators consume it. When the HTML and a header file disagree, check the release each was generated from.

These releases are named by date and often appear before the corresponding DDI0487 issue. For a brand-new extension they are the only description. Code that uses them should record which release it was written against.

Reference mappings that are useful but not authoritative: TF-A’s include/arch/aarch64/arch.h (field and bit definitions used by EL3 code), and Linux’s arch/arm64/tools/sysreg (from which the kernel generates its register definitions).

Companion specifications

DDI0487 specifies the PE. The rest of the system is specified elsewhere:

DocumentSpecifiesUsed in
IHI0069, GIC architecture (GICv3 and GICv4)Distributor, Redistributors, ITS, the CPU interface and its ICC_* registers, and the virtual CPU interfacePart 4, 11.4
IHI0070, SMMU architecture (SMMUv3)Stream tables, context descriptors, the command and event queues, and SMMU translation11.5
DDI0587, RAS supplementThe error record registers (ERRnSTATUS and the rest), error injection, and the RAS model at system level16.7, 16.8
DEN0129, RME system architectureWhat a system needs beyond the PE for RME: physical address space (PAS) tagging of every transaction, granule protection checks for requesters other than the PE (such as the SMMU), PAS filtering at completers, and the requirements on memory encryption and the system Root of Trust12.4, 12.5
DEN0094, BSA, and DEN0029, SBSAThe base and server system architectures: minimum hardware a compliant OS can rely on (timers, watchdogs, GIC, SMMU, PCIe and so on)18.6
DEN0022 PSCI, DEN0028 SMCCC, DEN0077 FF-AFirmware interfaces (not architecture, but every EL3 and EL2 component implements them)12.3, 17.4

Core-specific documents fill in what the architecture leaves IMPLEMENTATION DEFINED: the core’s Technical Reference Manual (TRM) and its Software Developer Errata Notice (SDEN). See 1.3.

Reading the pseudocode

The Arm ARM describes instruction behaviour, register accesses and most system mechanisms in ASL (Arm Architecture Specification Language). The pseudocode is normative unless the text around it says otherwise, and it resolves ambiguity in the prose more often than any other source. Its main features:

  • Types. bits(N) is a bitvector of width N, integer is unbounded, and boolean is TRUE/FALSE. Bit literals are quoted: '1', '0101'. Slicing is x<7:4> and concatenation is a:b.
  • Layout. Blocks are delimited by indentation, as in Python. Fields are named as in the register descriptions: SCTLR_EL1.M, PSTATE.EL, HCR_EL2.TGE.
  • Feature checks. Recent issues write IsFeatureImplemented(FEAT_X). Older issues use one function per feature, HaveXExt(). Either way, a feature check is a static property of the implementation, not a run-time enable.
  • Non-determinism. UNKNOWN values, IMPLEMENTATION_DEFINED "name" choices, and ConstrainUnpredictable(Unpredictable_...) calls mark the places where the architecture allows several behaviours. Search for these when you need to know what an implementation is permitted to do.

A register access function has a typical shape. The fragment below is simplified and illustrative, not quoted: the real function also handles fine-grained traps, nested virtualization and more ELs.

// Shape of the MSR SCTLR_EL1, <Xt> access pseudocode (simplified)
if PSTATE.EL == EL0 then
    UNDEFINED;
elsif PSTATE.EL == EL1 then
    if EL2Enabled() && HCR_EL2.TVM == '1' then
        AArch64.SystemAccessTrap(EL2, 0x18);   // EC 0x18: MSR/MRS/system instruction trap
    else
        SCTLR_EL1 = X[t, 64];
elsif PSTATE.EL == EL2 then
    ...

Read such a function from the top. The first branch that matches decides the outcome, so the order of the checks is the priority of the traps. That ordering is often what a validation test needs, and the prose rarely states it.

The library functions you will meet most often are AArch64.TakeException() (exception entry), AArch64.ExceptionReturn(), the translation functions (from AArch64.FullTranslate() down in recent issues), and the memory access and barrier functions behind the memory model. Their names vary slightly between issues, so search for them rather than relying on memory.

The pseudocode is a specification, not a model of hardware. In particular it is sequential: it describes one PE executing one instruction at a time. The memory model is specified separately, as axioms over executions, in the application-level memory model chapter of Part B, with litmus tests in Part K. herd7’s aarch64.cat is the formal model that matches it (7.3). Pseudocode that performs Mem[] accesses in program order does not mean the accesses are observed in program order.

The words that carry weight

These terms are defined in the glossary. The definitions decide what firmware may assume and what a validation test may flag as a bug.

TermMeaningConsequence
IMPLEMENTATION DEFINEDThe architecture allows a choice, and the implementation must document the choice it makes, for example in the TRM. “IMPLEMENTATION DEFINED, with constraints” limits the choice to a set.Portable code reads an ID register or treats the choice as a platform parameter. A test checks behaviour against the TRM, not against the Arm ARM alone.
UNKNOWNA value that software must not rely on. It can differ between implementations, between resets and between reads. An UNKNOWN value must not reveal information that the current Exception level could not otherwise access.Most system register fields reset to UNKNOWN unless the description says otherwise. Firmware must write every field it depends on, and must not build a value by read-modify-write of a reset value (17.1).
UNPREDICTABLEBehaviour that software must not rely on. It must not be a security hole: it may not do anything that code at the same or a lower privilege could not do by other means, and it must not halt or hang the PE or the system.Rare in AArch64, where most such cases are CONSTRAINED. A test that triggers UNPREDICTABLE behaviour cannot have an expected result, only security checks.
CONSTRAINED UNPREDICTABLEBehaviour that software must not rely on, but limited to a listed set of permitted behaviours. The Part K appendix on architectural constraints on UNPREDICTABLE behaviors lists the sets. In pseudocode it appears as ConstrainUnpredictable().A test of a CONSTRAINED UNPREDICTABLE case must accept every permitted behaviour, and only those. A model and silicon may legitimately differ.
UNDEFINEDExecuting the instruction generates an Undefined Instruction exception. This is a defined behaviour, not a vague one.An unimplemented instruction or register encoding is UNDEFINED and is reported with ESR_ELx.EC 0x00 (unknown reason). A feature that is implemented but disabled by a trap control usually reports its own EC instead (3.2).
RES0Reserved, should be zero. The bit might be used by a future extension, or by a feature this implementation lacks. Hardware may implement it as read-as-zero, write-ignored, or as a stored bit. Software must not rely on it reading as 0. When writing a register, software writes 0 or writes back a value it previously read from the same register (the SBZP rule).Writing 1 to a RES0 bit is how a field that is later allocated gets enabled by accident. Write 0 unless you know the feature exists.
RES1The same with 1: software must write 1, or preserve a value it read.SCTLR_ELx has several RES1 bits. A firmware constant that leaves them 0 may work on one model and change behaviour on another.
RAZ/WI, RAO/WIRead-as-zero (or one), writes ignored. Unlike RES0, this is a statement about hardware behaviour, not a reservation.Safe to test for.

Two related habits: “is permitted to” means the behaviour may occur and software must cope with it. “Is required to” and “must” mean a validation test may flag its absence as a bug. Wording such as “it is expected that” or “Arm recommends” introduces non-normative guidance, which an implementation may ignore.

Looking things up

A register or a field. Start from its DDI0601 page or its entry in the Part D system register descriptions:

  1. Check the purpose and the configuration notes (“This register is present only when FEAT_X is implemented”).
  2. For each field, read the conditions (“When FEAT_Y is implemented … Otherwise, RES0”) and the reset behaviour (Warm reset, Cold reset, “architecturally UNKNOWN”).
  3. Read the Accessing pseudocode for each encoding you use. It shows every trap, the EL it goes to, and the priority order between traps.

If all you have is a disassembly, a system register appears as an encoding. For example, mrs x0, S3_0_C1_C0_0 is op0=3, op1=0, CRn=1, CRm=0, op2=0, which is SCTLR_EL1. The register index by encoding in DDI0601, or the encoding table in Part D, maps it back to a name (2.5).

A feature. Find FEAT_X in chapter A2. That gives the versions in which it is permitted and mandatory, the features it requires, and the ID register field that reports it. Then read the field’s description: whether it is signed or unsigned, and what each value means (1.1). Finally, search Part D for “When FEAT_X is implemented” to find every control the feature adds. That list is your enable checklist (17.3).

An instruction. Use its page in Part C or DDI0602. Read the decode pseudocode first, because it holds the UNDEFINED and CONSTRAINED UNPREDICTABLE cases, and the operation pseudocode second. For barriers and maintenance instructions, the operation pseudocode is thin: the semantics live in the memory model prose in Part B and in the VMSA chapter of Part D.

A rule you half-remember. Search for its key phrase in quotation marks, then read the whole paragraph and its conditions. If the rule concerns ordering, check it against a litmus test in herd7 before relying on it (7.11).

Lab setup

The labs in 5.9, 7.11 and 8.10 use four tools. Each answers a different question, and none of them answers all of them:

ToolWhat it isGood forCannot show
QEMU virt (TCG)Fast functional emulator with a gdbstubEL3 bare-metal code, exception and translation flow, quick iterationCaches (CMOs are no-ops), weak memory ordering, timing
Arm FVP FVP_Base_RevC-2xAEMvAArm’s Architecture Envelope Model of the Base platform, configurable per featureFeatures QEMU lacks or approximates, TF-A as on real platforms, Tarmac instruction traces, optional cache-state modellingReordering (each PE executes in order), timing
herd7Executes litmus tests against the formal AArch64 memory model (aarch64.cat)What the architecture allowsWhat any implementation does
litmus7Generates C test harnesses that run a litmus test millions of times on LinuxWhat an implementation doesAnything about the architecture as such

A step that needs a real board says so. See 18.4 for what each environment hides.

Host packages

On a Debian or Ubuntu x86-64 host:

sudo apt install build-essential git make device-tree-compiler libssl-dev \
    gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu gdb-multiarch \
    qemu-system-arm opam

qemu-system-arm provides qemu-system-aarch64. The distribution’s QEMU is fine if it is recent. Check that qemu-system-aarch64 -cpu help lists max. For the newest FEAT_ support, build QEMU from source.

For bare-metal code, use the Arm GNU Toolchain aarch64-none-elf target, downloaded from Arm’s developer site (search for “Arm GNU Toolchain downloads”):

mkdir -p "$HOME/opt"
tar xf arm-gnu-toolchain-*-x86_64-aarch64-none-elf.tar.xz -C "$HOME/opt"
export PATH="$(echo "$HOME"/opt/arm-gnu-toolchain-*-aarch64-none-elf/bin):$PATH"
aarch64-none-elf-gcc --version

The Makefile below also works with the distribution’s aarch64-linux-gnu-gcc (make CROSS=aarch64-linux-gnu-), because it passes -ffreestanding -nostdlib and disables PIE and the stack protector, which some distributions enable by default. aarch64-linux-gnu-gcc is required for litmus7 harnesses, which are Linux user programs.

Repository layout

The labs assume one working directory:

armv8-labs/
├── labs/
│   ├── common/          minimal EL3 image from this page: start.S vectors.S uart.c main.c link.ld Makefile
│   ├── part05/          5.9: self-contained start.S, lab.c, link.ld (see 5.9)
│   ├── part07/          7.11: tests/ (litmus files), run-qemu/, run-board/, model.txt
│   └── part08/          8.10: test sources, build/lab8.elf, build/lab8.bin
├── tf-a/                Trusted Firmware-A clone, for FVP runs that boot through BL1/BL31 (8.10)
└── guest/               Linux kernel Image and rootfs.ext4 for litmus7 runs (7.11)

Commands in the labs are given relative to armv8-labs/ unless the lab says cd first. Each lab directory holds its build output under build/, so a stale binary from another lab is never picked up.

A minimal bare-metal EL3 image

The image in labs/common/ is the smallest useful starting point. It parks every PE except the one with affinity 0.0.0, sets SCTLR_EL3 to a known value, installs an EL3 vector table, clears .bss, initialises the PL011 UART, prints a few ID registers, and takes a deliberate exception to prove that the vectors work. It runs unchanged on QEMU virt (with secure=on) and on the FVP. Only the UART base and the load address differ between the two.

link.ld

ENTRY(_start)
SECTIONS {
  . = LOAD_ADDR;
  .text : {
    *(.text.boot)
    . = ALIGN(2048);  *(.text.vectors)      /* VBAR_EL3 needs 2KB alignment */
    *(.text*)
  }
  .rodata : { *(.rodata*) }
  .data   : { *(.data*) }
  .bss    : ALIGN(16) { __bss_start = .; *(.bss*) *(COMMON) . = ALIGN(16); __bss_end = .; }
  . = ALIGN(16); . += 0x4000; __stack_top = .;
}

start.S

    .section .text.boot, "ax"
    .global _start
_start:
    mrs     x0, mpidr_el1
    and     x0, x0, #0xffffff       // Aff2:Aff1:Aff0
    cbz     x0, primary
park:                               // secondaries: QEMU (secure=on) and FVP may start them here too
    wfe
    b       park

primary:
    ldr     x0, =0x30c50830         // SCTLR_EL3 base value (see below); M=0 C=0 I=0 A=0 EE=0
    msr     sctlr_el3, x0
    ldr     x0, =el3_vectors
    msr     vbar_el3, x0
    isb                             // new SCTLR_EL3 and VBAR_EL3 in effect before anything can fault

    ldr     x0, =__bss_start
    ldr     x1, =__bss_end
1:  cmp     x0, x1
    b.hs    2f
    str     xzr, [x0], #8
    b       1b
2:  ldr     x0, =__stack_top
    mov     sp, x0                  // PSTATE.SP is 1 at reset, so this is SP_EL3
    bl      main
3:  wfe
    b       3b

Most SCTLR_EL3 fields reset to UNKNOWN values, so the code writes the whole register. 0x30c50830 sets bits 29, 28, 23, 22, 18, 16, 11, 5 and 4, which is TF-A’s SCTLR_EL3 base value. They are RES1, except that bits 22 and 11 are EIS and EOS when FEAT_ExS is implemented, and 1 is the setting that keeps exception entry and exit context-synchronizing. With M = 0, EL3 data accesses are Device-nGnRnE, so every access must be aligned. That is why the Makefile passes -mstrict-align (6.5).

vectors.S

    .macro  ventry id
    .balign 0x80
    mov     x0, #\id
    b       el3_unhandled
    .endm

    .section .text.vectors, "ax"
    .balign 0x800
    .global el3_vectors
el3_vectors:
    ventry 0    // Current EL, SP_EL0: Synchronous
    ventry 1    //                     IRQ
    ventry 2    //                     FIQ
    ventry 3    //                     SError
    ventry 4    // Current EL, SP_ELx: Synchronous
    ventry 5    //                     IRQ
    ventry 6    //                     FIQ
    ventry 7    //                     SError
    ventry 8    // Lower EL, AArch64:  Synchronous
    ventry 9    //                     IRQ
    ventry 10   //                     FIQ
    ventry 11   //                     SError
    ventry 12   // Lower EL, AArch32:  Synchronous
    ventry 13   //                     IRQ
    ventry 14   //                     FIQ
    ventry 15   //                     SError

Each entry is 0x80 bytes and the table is 0x800 bytes, aligned to 2KB (3.1). The handler never returns, so it does not save registers.

uart.c (PL011; register offsets from the PL011 TRM)

#include <stdint.h>

#ifdef PLAT_FVP
#define UART_BASE 0x1c090000UL          /* FVP Base: UART0 */
#else
#define UART_BASE 0x09000000UL          /* QEMU virt: UART0 */
#endif

#define REG(off)   (*(volatile uint32_t *)(UART_BASE + (off)))
#define UARTDR     REG(0x000)
#define UARTFR     REG(0x018)
#define UARTIBRD   REG(0x024)
#define UARTFBRD   REG(0x028)
#define UARTLCR_H  REG(0x02c)
#define UARTCR     REG(0x030)
#define FR_BUSY    (1u << 3)
#define FR_TXFF    (1u << 5)

void uart_init(void)
{
    UARTCR = 0;                         /* disable while configuring */
    while (UARTFR & FR_BUSY)
        ;
    UARTIBRD = 13;                      /* 115200 baud from a 24 MHz UARTCLK */
    UARTFBRD = 1;
    UARTLCR_H = (3u << 5) | (1u << 4);  /* 8 data bits, FIFOs on; also latches IBRD/FBRD */
    UARTCR = (1u << 9) | (1u << 8) | 1u;/* RXE, TXE, UARTEN */
}

void uart_putc(char c)
{
    if (c == '\n')
        uart_putc('\r');
    while (UARTFR & FR_TXFF)
        ;
    UARTDR = (uint32_t)c;
}

void uart_puts(const char *s) { while (*s) uart_putc(*s++); }

void uart_hex(uint64_t v)
{
    uart_puts("0x");
    for (int i = 60; i >= 0; i -= 4)
        uart_putc("0123456789abcdef"[(v >> i) & 0xf]);
}

Neither model needs the baud-rate setup to produce output, but real PL011s do, and recent QEMU logs a guest error (-d guest_errors) if you write to a UART whose UARTEN or TXE bit is clear. The divisor assumes the 24 MHz UART clock of the FVP Base platform. Check your board’s clock.

main.c

#include <stdint.h>

void uart_init(void);
void uart_puts(const char *s);
void uart_hex(uint64_t v);

#define READ_SYSREG(r) ({ uint64_t _v; __asm__ volatile("mrs %0, " #r : "=r"(_v)); _v; })

static void show(const char *name, uint64_t v) { uart_puts(name); uart_hex(v); uart_puts("\n"); }

void el3_unhandled(uint64_t slot)
{
    show("\nunhandled exception, vector slot ", slot);
    show("  ESR_EL3  ", READ_SYSREG(esr_el3));
    show("  ELR_EL3  ", READ_SYSREG(elr_el3));
    show("  FAR_EL3  ", READ_SYSREG(far_el3));
    show("  SPSR_EL3 ", READ_SYSREG(spsr_el3));
    for (;;)
        __asm__ volatile("wfe");
}

int main(void)
{
    uart_init();
    show("CurrentEL        ", READ_SYSREG(CurrentEL) >> 2);
    show("MIDR_EL1         ", READ_SYSREG(midr_el1));
    show("MPIDR_EL1        ", READ_SYSREG(mpidr_el1));
    show("ID_AA64PFR0_EL1  ", READ_SYSREG(id_aa64pfr0_el1));
    show("ID_AA64MMFR0_EL1 ", READ_SYSREG(id_aa64mmfr0_el1));
    uart_puts("taking BRK #0x42 at EL3...\n");
    __asm__ volatile("brk #0x42");
    return 0;
}

Makefile (recipe lines start with a tab)

PLAT    ?= qemu
CROSS   ?= aarch64-none-elf-
CC       = $(CROSS)gcc
OBJCOPY  = $(CROSS)objcopy
CFLAGS   = -O1 -g -Wall -ffreestanding -nostdlib -fno-pie -fno-stack-protector \
           -mstrict-align -mgeneral-regs-only -fno-tree-loop-distribute-patterns
ifeq ($(PLAT),fvp)
CFLAGS  += -DPLAT_FVP
LOAD     = 0x80000000
else
LOAD     = 0x40080000
endif
OUT      = build/$(PLAT)
SRCS     = start.S vectors.S uart.c main.c

$(OUT)/el3.elf: $(SRCS) link.ld | $(OUT)
	$(CC) $(CFLAGS) -no-pie -static -Wl,--defsym=LOAD_ADDR=$(LOAD) -T link.ld $(SRCS) -o $@
	$(OBJCOPY) -O binary $@ $(OUT)/el3.bin

$(OUT):
	mkdir -p $@

clean:
	rm -rf build
.PHONY: clean

-mgeneral-regs-only keeps the compiler from using FP/SIMD registers. Their use would trap if CPTR_EL3.TFP, which is UNKNOWN after reset, happened to be 1 (15.3). -fno-tree-loop-distribute-patterns stops GCC from turning the loops into calls to memset, which does not exist here. QEMU loads the image at 0x40080000 rather than at the base of RAM, because for a bare-metal ELF it places the device tree blob at the start of RAM.

Expected output (values vary with the model and its configuration):

CurrentEL        0x0000000000000003
MIDR_EL1         0x...
MPIDR_EL1        0x...
ID_AA64PFR0_EL1  0x...
ID_AA64MMFR0_EL1 0x...
taking BRK #0x42 at EL3...

unhandled exception, vector slot 0x0000000000000004
  ESR_EL3  0x00000000f2000042
  ELR_EL3  0x...                      (address of the BRK)
  FAR_EL3  0x...                      (UNKNOWN for this exception)
  SPSR_EL3 0x...

The exception arrives in slot 4 (current EL with SP_ELx, Synchronous). ESR_EL3 = 0xf2000042 decodes as EC 0x3C (BRK instruction execution in AArch64 state), IL = 1, ISS = the immediate 0x42. A BRK is taken to the current Exception level when that level is EL2 or EL3. If the output stops before the BRK line, the UART base or load address is wrong. If it stops at the BRK line, VBAR_EL3 or the table alignment is wrong.

Running on QEMU

cd labs/common && make PLAT=qemu
qemu-system-aarch64 -M virt,secure=on,virtualization=on -cpu max -smp 1 -m 1G \
    -nographic -kernel build/qemu/el3.elf \
    -d int,mmu,guest_errors,unimp -D qemu.log      # exit QEMU: Ctrl-A then x
  • secure=on gives the CPU EL3 and adds the Secure-only memory and devices. virtualization=on gives it EL2. With both set, an ELF that is not a Linux kernel image starts at EL3, at its ELF entry point. With -smp greater than 1, whether the secondary CPUs also start at the entry point or are held powered off depends on the QEMU version and machine options, so start.S parks any PE whose affinity is not 0.0.0.
  • -cpu max enables every feature the QEMU build supports. Individual features can be switched off (-cpu max,sve=off, -cpu max,pauth=off) to test discovery code. -M virt,...,mte=on adds MTE tag storage. -cpu max,x-rme=on enables QEMU’s experimental RME support. Check the result in the ID registers rather than trusting the command line.
  • -d int logs every exception taken, with its ESR, FAR and ELR. This is the fastest way to find a fault loop. mmu logs MMU-related events, guest_errors logs accesses that real hardware would reject or that are probably bugs (unmapped MMIO, a disabled UART), and unimp logs accesses to devices or registers QEMU does not implement. -D sends the log to a file. qemu-system-aarch64 -d help lists all items.
  • gdbstub. Add -s -S to listen on TCP port 1234 and hold the CPU at reset:
qemu-system-aarch64 ... -s -S &
gdb-multiarch build/qemu/el3.elf \
    -ex 'target remote :1234' -ex 'break main' -ex 'continue'

QEMU exposes the system registers to gdb by their architectural names, so p/x $SCTLR_EL3 and p/x $VBAR_EL3 work, and info all-registers lists them all. The aarch64-none-elf-gdb from the Arm GNU Toolchain works too, if your toolchain package includes it.

Running on the Arm FVP

Download the Armv-A Base RevC AEM FVP (FVP_Base_RevC-2xAEMvA) from Arm’s Ecosystem FVP downloads page (free, Linux x86-64 and AArch64 hosts). It unpacks to a Base_RevC_AEMvA_pkg/ directory. The executable is under models/Linux64_GCC-*/ and the plugins are under plugins/Linux64_GCC-*/. The GCC version in the directory name changes between releases.

export FVP_DIR=$HOME/opt/Base_RevC_AEMvA_pkg
export PATH="$(echo "$FVP_DIR"/models/Linux64_GCC-*):$PATH"
cd labs/common && make PLAT=fvp
FVP_Base_RevC-2xAEMvA \
    -C cluster0.NUM_CORES=1 -C bp.secure_memory=0 \
    -C bp.pl011_uart0.out_file=- -C bp.pl011_uart0.unbuffered_output=1 \
    -C bp.terminal_0.start_telnet=0 -C bp.vis.disable_visualisation=1 \
    -a cluster0.cpu0=build/fvp/el3.elf \
    --plugin "$(echo "$FVP_DIR"/plugins/Linux64_GCC-*/TarmacTrace.so)" \
    -C TRACE.TarmacTrace.trace-file=el3.tarmac
  • -a cluster0.cpu0=FILE loads the ELF and sets that PE’s start address to its entry point. If your FVP version does not, set the reset address with -C cluster0.cpu0.RVBAR=0x80000000.
  • bp.secure_memory=0 turns off the platform’s TrustZone memory filtering, so EL3 can run from DRAM at 0x80000000 without programming the TZC first. TF-A’s documented FVP runs set bp.secure_memory=1, so that the filtering TF-A programs is enforced.
  • UART. out_file=- sends UART0 to stdout, and start_telnet=0 stops the model opening a terminal window.
  • Tarmac records every executed instruction, register write, memory access and exception. Grep it for ESR_EL3 or for an exception record instead of single-stepping. The trace options vary by FVP release. List them with --plugin .../TarmacTrace.so --list-params | grep TRACE.TarmacTrace.
  • Parameters in general. FVP_Base_RevC-2xAEMvA --list-params prints every parameter with its default. Pipe it to grep -i when a lab names a parameter your version does not recognise. Parameter names do change between releases.
  • Debugging. -I starts the Iris debug server, which Arm Development Studio connects to. Recent FVP packages also ship a GDBRemoteConnection.so plugin for gdb. It prints its port when the model starts, and its parameters appear in --list-params when it is loaded.

Selecting architecture features

The AEM model implements whatever the parameters say. These are the ones the book uses. Set each one for cluster1 as well if that cluster has cores.

ParameterEffect
cluster0.has_arm_v9-2=1 (or v8-7, v9-4, …)Selects the architecture version and its mandatory features
cluster0.memory_tagging_support_level=2 plus bp.dram_metadata.is_enabled=1FEAT_MTE2. Use 3 for FEAT_MTE3. Without the DRAM metadata parameter, tags are not stored, and the model does not warn you.
cluster0.rme_support_level=2 plus bp.has_rme=1FEAT_RME in the PE, plus the platform-side RME support. TF-A must be built with ENABLE_RME=1. The TF-A RME documentation gives the complete parameter list.
cluster0.has_sve=1, cluster0.sve.has_sme=1, cluster0.sve.has_sme2=1SVE, SME and SME2
cluster0.has_branch_target_exception=1FEAT_BTI
cluster0.max_32bit_el=-1No AArch32 at any EL
cluster0.PA_SIZE=48Physical address size, reported in ID_AA64MMFR0_EL1.PARange
cache_state_modelled=1Model cache contents, so that missing maintenance can produce wrong data (8.10). Slower.

Booting through TF-A

8.10 runs its test at EL2 or EL1 as a BL33 image, with TF-A providing BL1, BL2, BL31 and PSCI:

git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git tf-a
make -C tf-a CROSS_COMPILE=aarch64-none-elf- PLAT=fvp DEBUG=0 \
    BL33=$PWD/labs/part08/build/lab8.bin all fip
# outputs: tf-a/build/fvp/release/bl1.bin and fip.bin
FVP_Base_RevC-2xAEMvA \
    -C pctl.startup=0.0.0.0 -C bp.secure_memory=1 -C cache_state_modelled=1 \
    -C bp.secureflashloader.fname=tf-a/build/fvp/release/bl1.bin \
    -C bp.flashloader0.fname=tf-a/build/fvp/release/fip.bin \
    -C bp.pl011_uart0.out_file=- -C bp.terminal_0.start_telnet=0 \
    -C bp.vis.disable_visualisation=1 -C bp.ve_sysregs.exit_on_shutdown=1

The pctl.startup, secure_memory and cache_state_modelled settings follow TF-A’s documented FVP runs. Drop cache_state_modelled=1 for faster runs when you are not testing maintenance. DEBUG=1 puts the output in build/fvp/debug/ and makes BL1 and BL31 log much more. TF-A’s FVP build needs dtc (device-tree-compiler), and its host tools need OpenSSL headers. Arm’s Shrinkwrap tool packages complete FVP configurations (firmware, kernel and the matching model parameters) if you want a full software stack without assembling it yourself.

herdtools7: herd7 and litmus7

Install through opam, OCaml’s package manager:

opam init -y && eval "$(opam env)"
opam install herdtools7               # herd7, litmus7, diy7, mcompare7 and friends
herd7 -version

To build from source instead, clone https://github.com/herd/herdtools7, install the dependencies with opam install . --deps-only, then make all and make PREFIX=$HOME/.local install. The default PREFIX is $HOME.

Smoke test: message passing with DMB on both sides, whose relaxed outcome the model forbids.

AArch64 MP+dmb.sys
{
0:X1=x; 0:X3=y;
1:X1=y; 1:X3=x;
}
 P0          | P1          ;
 MOV W0,#1   | LDR W0,[X1] ;
 STR W0,[X1] | DMB SY      ;
 DMB SY      | LDR W2,[X3] ;
 MOV W2,#1   |             ;
 STR W2,[X3] |             ;
exists (1:X0=1 /\ 1:X2=0)
mkdir -p labs/part07/tests && cd labs/part07
# save the test above as tests/MP+dmb.sys.litmus
herd7 -model aarch64.cat tests/MP+dmb.sys.litmus

The output lists three reachable final states and ends with Observation MP+dmb.sys Never 0 3: the exists clause is satisfied in none of them. Delete both DMB SY lines and the result becomes Sometimes. Recent herd7 versions may also print a flag about the shareability argument of DMB (7.5). That flag does not change the verdict.

A Linux guest for litmus7

litmus7 harnesses are Linux user programs, so the QEMU and FVP runs in 7.11 need a kernel and a root filesystem. Buildroot builds both:

git clone https://gitlab.com/buildroot.org/buildroot.git guest/buildroot
make -C guest/buildroot qemu_aarch64_virt_defconfig
make -C guest/buildroot -j"$(nproc)"
cp guest/buildroot/output/images/Image guest/buildroot/output/images/rootfs.ext4 guest/

The guest has no compiler, so build the harness on the host and copy the binaries in. Generate it with the 7.11 options (-gcc aarch64-linux-gnu-gcc -linkopt -static). Pass -o run-qemu to get a directory rather than an archive, or unpack the archive into run-qemu/. Then:

cd labs/part07
make -C run-qemu                      # cross-compiles with aarch64-linux-gnu-gcc
mkdir -p mnt && sudo mount -o loop ../../guest/rootfs.ext4 mnt
sudo cp -r run-qemu mnt/root/ && sudo umount mnt
cd ../..
qemu-system-aarch64 -M virt -cpu max -smp 4 -m 2G -accel tcg,thread=multi -nographic \
    -kernel guest/Image -append "rootwait root=/dev/vda console=ttyAMA0" \
    -drive file=guest/rootfs.ext4,if=none,format=raw,id=hd0 \
    -device virtio-blk-device,drive=hd0
# log in as root, then:  cd run-qemu && sh run.sh > qemu.txt

On a board running Linux, build natively, or cross-build the same way and copy the directory over. Only board runs can show relaxed outcomes that QEMU on an x86 host and the FVP never produce (7.11).

Checklist

Before starting the labs, confirm that:

  • the EL3 image prints CurrentEL 0x...03 and the BRK report on both QEMU and the FVP;
  • qemu.log shows the BRK exception when run with -d int;
  • the FVP Tarmac file contains the brk instruction and the exception entry that follows it;
  • herd7 reports Never for MP+dmb.sys and Sometimes for the version without barriers;
  • the Linux guest boots in QEMU and runs a litmus7 harness built on the host.

Part 1: The architecture landscape

Prerequisites: none beyond Reading the Arm ARM; this part is the entry point for every reading path. If you already know: how to read A2 and decode ID registers with signed fields, skim 1.1. If you have shipped TF-A errata flags for a production core, skip to the REVIDR_EL1 and Errata ABI parts of 1.3. Why this matters for bring-up/validation: every enable bit, workaround and test in the rest of the book depends on knowing exactly which features and which errata the silicon in front of you has, and none of that can be read from a version number.

An “Armv9.2 core” is a claim about a set of features, not a description of the hardware. This part separates three layers that are easily confused. The architecture is a list of FEAT_ names, each permitted from one version and possibly mandatory from a later one, and each discovered at run time through a 4-bit ID register field with its own signedness rules. The v9 baseline is a short list of rules added on top of v8.5. The implementation is a specific core, revision and integration, with its own IMPLEMENTATION DEFINED registers and errata.

1.1 covers versions and discovery: the v9.n = v8.(n+5) pairing, the ID register families, the field rules, FEAT_IDST and trapping, and how TF-A and Linux deal with cores that disagree. 1.2 states precisely what Armv9-A changed and what it left optional. 1.3 moves from architecture to silicon: the core families and the DSU, what a TRM adds, how to read an errata notice against MIDR_EL1/REVIDR_EL1, and how TF-A applies workarounds on every reset and reports them to lower ELs.

1.1 Versions, FEAT_ names and discovery

Versions are sets of features

The A-profile architecture is versioned Armv8.0 to Armv8.9 and Armv9.0 onward. Since Armv8.5 (2018) Arm has published one set of extensions a year. Each set added one v8.x and, from 2021, a matching v9.x, until the v8 line stopped:

Armv9 versionEquivalent Armv8 baseExtensions year
v9.0v8.5v8.5 in 2018; v9.0 announced 2021
v9.1v8.62019
v9.2v8.72020
v9.3v8.82021
v9.4v8.92022
v9.5none2023
v9.6none2024
v9.7, v9.8, …none2025 onward

The pairing rule is v9.n = v8.(n+5) plus the v9 baseline, up to v9.4/v8.9. An Armv9.n implementation must also be a compliant Armv8.(n+5) implementation. The v8 line ends at v8.9: there is no v8.10, so v9.5 and later have no v8 counterpart. 1.2 covers what the v9 baseline adds.

A version number is shorthand for a set of features, each named FEAT_xxx (for example FEAT_LSE, FEAT_PAuth, FEAT_MTE2, FEAT_RME). Each feature has two version attributes in DDI0487 section A2, “Armv8-A and Armv9-A architecture extensions”:

  • Permitted from vX (the Arm ARM says “OPTIONAL from”): an implementation claiming vX or later may include it.
  • Mandatory from vY: an implementation claiming vY or later must include it. Many features never become mandatory.

Examples:

FeaturePermitted fromMandatory from
FEAT_RASv8.0v8.2
FEAT_SBv8.0v8.5
FEAT_CLRBHBv8.0v8.9
FEAT_MTE / FEAT_MTE2v8.5never
FEAT_SVEv8.2see 1.2

Two more rules from A2 govern the edges. First, an Armv8.x implementation is permitted to include any subset of the features of Armv8.(x+1), so a “v8.2” core with a few v8.3 features is architecturally legal. Second, claiming vY means implementing every feature mandatory at vY and below. Some features also have dependencies: one feature may be permitted only if another is implemented, or two may be required together. A2 lists these per feature.

Bring-up note: Never derive a feature from a version string, compiler -march flag, or marketing name. Compiler tables enable what the PCS/ABI wants at that -march, not what A2 makes mandatory (they disagree on SVE2 for v9.0, for example). The core TRM lists the implemented features, and the ID registers report them at run time. Treat both as the ground truth, and check the TRM against the ID registers on first silicon.

No register tells you the version

MIDR_EL1.Architecture (bits [19:16]) reads 0b1111, meaning “defined by the ID registers”. No architected register encodes “v8.7” or “v9.2”. Software discovers each feature separately, through 4-bit fields in the ID registers.

The AArch64 ID register families

These are all in the “feature ID space” (op0=3, op1=0, CRn=0, CRm=0..7) and are readable at EL1 and above:

Register(s)What it describes
ID_AA64PFR0_EL1EL0–EL3 AArch64/AArch32 support, FP, AdvSIMD, GIC system-register interface, RAS, SVE, SEL2, MPAM, AMU, DIT, RME, CSV2, CSV3
ID_AA64PFR1_EL1, ID_AA64PFR2_EL1BTI, SSBS, MTE, SME, NMI, GCS, the _frac refinements; PFR2 holds newer MTE refinements and FPMR
ID_AA64ISAR0_EL1 – ID_AA64ISAR3_EL1Instruction-set features: crypto, atomics, CRC, RNDR, TLBI range/outer-shareable, PAuth algorithms, LRCPC, BF16/I8MM, SB, SPECRES, MOPS, CLRBHB, WFxT, SYSREG_128, and more
ID_AA64MMFR0_EL1 – ID_AA64MMFR4_EL1Memory system: PARange, ASID bits, granule support, ECV, FGT, VHE, PAN, HAFDBS, BBM, E0PD, TCR2/SCTLR2, S1PIE/S1POE, MEC, E2H0
ID_AA64DFR0_EL1, ID_AA64DFR1_EL1Debug and monitoring: Debug version, breakpoint/watchpoint counts, PMUVer, SPE, TraceVer/TraceBuffer, BRBE, DoubleLock, MTPMU
ID_AA64ZFR0_EL1SVE sub-features (SVEver, AES, BitPerm, …), only meaningful if SVE or SME is present
ID_AA64SMFR0_EL1SME sub-features and SME version
ID_AA64FPFR0_EL1FP8 formats and operations (FEAT_FP8 and related)

Three identification registers sit beside them:

  • MIDR_EL1: Implementer [31:24] (0x41 is Arm Ltd), Variant [23:20], Architecture [19:16], PartNum [15:4], Revision [3:0]. Variant and Revision are the rVpR that errata notices use (1.3).
  • REVIDR_EL1: IMPLEMENTATION DEFINED. Cores typically use bits here to report ECO fixes within a revision, so that software can tell that a specific erratum is fixed even though MIDR_EL1 is unchanged. The core TRM defines the bits.
  • MPIDR_EL1: affinity Aff3 [39:32], Aff2 [23:16], Aff1 [15:8], Aff0 [7:0], plus U [30] (uniprocessor) and MT [24] (the lowest affinity level is numbered as if it held multithreaded logical PEs). DynamIQ cores set MT=1 even when they have no SMT, with Aff0=0 and the core number in Aff1. MPIDR is a logical ID: it says nothing about core type, and its mapping onto physical topology is a platform decision (see 17.5).

When EL2 is implemented and enabled, EL1 reads of MIDR_EL1 and MPIDR_EL1 return VPIDR_EL2 and VMPIDR_EL2. A hypervisor uses these to present virtual identities.

The field-level tables for these registers are in Appendix B. The rules below matter more than memorising them.

The field rules

DDI0487 “Principles of the ID scheme for fields in ID registers” sets the conventions:

  1. Fields are 4 bits, and a larger value means more functionality. A value of N implies everything that values below N indicated. Correct tests are therefore field >= X, never field == X. A test with == breaks on the next core, when 0b0010 arrives with a superset feature.
  2. Most fields are unsigned. A few are signed, and in those 0b1111 (−1) means “not implemented” while 0b0000 means “implemented”. Examples are ID_AA64PFR0_EL1.FP and .AdvSIMD (0b0000 = present, 0b0001 = present with half-precision, 0b1111 = absent), ID_AA64MMFR0_EL1.TGran4 and .TGran64, and ID_AA64DFR0_EL1.DoubleLock. Reading a signed field as unsigned turns “absent” into “the best possible value”.
  3. Exceptions are documented per field. ID_AA64DFR0_EL1.PMUVer == 0b1111 means an IMPLEMENTATION DEFINED PMU, not PMUv3 at its highest version. ID_AA64MMFR0_EL1.TGran16 is unsigned with 0b0000 = not supported, the opposite polarity to TGran4. Always read the field description, not just the encoding pattern.
  4. Reserved and unallocated encodings in the feature ID space read as zero. A feature that a core predates therefore reads as “not implemented”. Software can read ID_AA64ISAR3_EL1 (encoded S3_0_C0_C6_3) on an old core and get 0. Use the generic S3_... name if the assembler does not know the register.
/* Signed vs unsigned extraction: the one helper you need. */
static inline unsigned idfield_u(uint64_t reg, unsigned shift)
{ return (reg >> shift) & 0xf; }

static inline int idfield_s(uint64_t reg, unsigned shift)
{ return ((int64_t)(reg << (60 - shift))) >> 60; }   /* sign-extend 4 bits */

/* FP present?  ID_AA64PFR0_EL1.FP is signed, bits [19:16] */
bool has_fp = idfield_s(read_id_aa64pfr0_el1(), 16) >= 0;

Trapping ID registers: HCR_EL2.TID3 and FEAT_IDST

The ID registers cannot be written, but a hypervisor can choose what a guest sees. HCR_EL2.TID3 traps EL1 (and EL0 where applicable) reads of the “ID group 3” registers to EL2: the ID_AA64*, the AArch32 ID_* and MVFRn registers, and the unallocated encodings of the feature ID space. These traps report with EC = 0x18 (trapped MSR/MRS/system instruction), with the full op0/op1/CRn/CRm/op2 and Rt in the ISS, so KVM or another hypervisor can return sanitised values. TID1 covers REVIDR_EL1 and AIDR_EL1, and TID2 covers CTR_EL0, CCSIDR_EL1, CLIDR_EL1 and CSSELR_EL1. Fine-grained traps (HFGRTR_EL2, FEAT_FGT) allow per-register control; see 11.1.

FEAT_IDST (Armv8.4, reported in ID_AA64MMFR2_EL1.IDS) changes the syndrome for exceptions caused by reads in the feature ID space (op0=3, op1={0,1,3}, CRn=0, CRm=0..7). Without it, an access that is UNDEFINED, such as an EL0 MRS of an ID_AA64* register or a read of GMID_EL1 on a core without FEAT_MTE2, reports EC = 0x00 (unknown reason). The handler then has to fetch and decode the instruction to emulate it. With FEAT_IDST, the same exception reports EC = 0x18 with a decoded ISS. Linux uses either path to emulate EL0 reads of the ID registers with sanitised values, which HWCAP_CPUID advertises.

Security note: ID registers are an information channel and a policy input. A guest or lower EL that sees a feature bit will use the feature. If the higher EL has not enabled it, the result is an UNDEF or an unexpected trap. If the higher EL has enabled it but does not context-switch its state, the result is a cross-world leak. Hiding a feature from a guest with TID3 only works if EL2 also traps or disables the feature itself (2.6).

Heterogeneous cores: whose ID registers?

Each PE has its own ID registers. On a system with different core types (big.LITTLE/DynamIQ with mixed cores, or a multi-chiplet SoC that mixes core revisions), the values can differ between cores. The architecture says nothing about system-wide consistency, so each firmware layer handles it differently.

TF-A enables features per core. Each ENABLE_FEAT_xxx build flag takes 0 (compiled out), 1 (assumed present and enabled unconditionally) or 2 (compiled in, checked at run time by is_feat_xxx_supported(), which reads the local ID register). With FEATURE_DETECTION=1, a debug build checks that the flags match the running core and reports mismatches. This is the tool to use at bring-up when the RTL configuration or FVP parameters may not match the build. TF-A does not compute a system-wide intersection. With flag value 2 on a mixed system, each core enables what it has, and a core-type asymmetry is passed straight up to the OS. 17.3 covers the enable side.

Linux cpufeature (arch/arm64/kernel/cpufeature.c) builds a sanitised system-wide view. Each ID register field is described by ARM64_FTR_BITS(visible, strict, type, shift, width, safe_val), where type gives the safe direction: FTR_LOWER_SAFE for most features (take the minimum across CPUs), FTR_HIGHER_SAFE for some cache-geometry-style fields, and FTR_EXACT (fall back to safe_val if CPUs disagree). Signed fields use the S_ARM64_FTR_BITS variant, which applies rule 2 above. Per-CPU values are folded into the system value as CPUs come up. A “strict” mismatch prints SANITY CHECK: Unexpected variation in SYS_... and taints the kernel. Once system capabilities are finalised, a late CPU that lacks a capability already in use is refused: verify_local_cpu_capabilities() fails and the CPU is not brought online (cpu_die_early()). The sanitised values are what EL0 sees through MRS emulation, and what KVM bases guest ID registers on.

Validation note: On a new SoC, dump every ID register on every core and every cluster type, and diff the results against the TRM and against each other. Expected differences between core types should match the TRM. Any difference between cores of the same type indicates a configuration-pin, RTL-configuration or fuse problem. Under Linux, dmesg | grep -i "SANITY CHECK\|CPU features" and /sys/devices/system/cpu/cpu*/regs/identification/midr_el1 give a first view, and a bare-metal loop over all PEs that prints MIDR/REVIDR/ID_AA64* is the authoritative one.

Checkpoint

Q1.1.1 Firmware tests for half-precision FP support with if (((pfr0 >> 16) & 0xf) >= 1), where bits [19:16] are ID_AA64PFR0_EL1.FP. On a core with no floating-point unit at all, what happens?

  • A. The test is correct: FP absent reads as 0, which fails >= 1
  • B. The test is correct, because the reserved value 0b1111 is never used for FP
  • C. The test wrongly passes, because FP is a signed field and 0b1111 (−1, not implemented) read as unsigned is 15
  • D. The read itself UNDEFs on a core without FP, so the test never runs
Answer

C. ID_AA64PFR0_EL1.FP is one of the signed fields. 0b0000 means FP is implemented, 0b0001 adds half-precision, and 0b1111 means not implemented. Sign-extend the field and test >= 1 (or >= 0 for “any FP”). Option A describes the polarity of an unsigned field, which is how most fields behave, and that is why the bug is easy to write. The ID register read itself is always permitted at EL1.

Read more: Arm ARM (DDI0487), “Principles of the ID scheme for fields in ID registers”; ID_AA64PFR0_EL1

Q1.1.2 A core’s TRM says “Armv8.2-A, with FEAT_LRCPC (Armv8.3) and FEAT_DotProd”. Boot firmware wants to use pointer authentication, which is mandatory from Armv8.3. What may it assume?

  • A. PAuth is present: implementing one v8.3 feature makes the core a v8.3 implementation, so every v8.3 mandatory feature follows
  • B. Only the v8.2 mandatory set and the listed extras are guaranteed. PAuth must be checked in ID_AA64ISAR1_EL1 (APA/API/GPA/GPI, and ID_AA64ISAR2_EL1 for APA3/GPA3)
  • C. The TRM describes an illegal configuration, because a v8.2 core may not contain v8.3 features
  • D. MIDR_EL1.Architecture reports the effective version, so firmware should read it to decide
Answer

B. A2 lets an Armv8.x implementation include any subset of the features of Armv8.(x+1), and some features are permitted well below the version where they become mandatory. The claimed version guarantees only that version’s mandatory set. A is the common mistake: a v8.3 feature in a v8.2 core does not make the other v8.3 mandatory features present. C is wrong for the same reason. MIDR_EL1.Architecture reads 0b1111, meaning “see the ID registers”, and carries no version.

Read more: Arm ARM (DDI0487), A2 “Armv8-A and Armv9-A architecture extensions”; ID_AA64ISAR1_EL1; MIDR_EL1

Q1.1.3 A Linux EL0 process executes MRS x0, ID_AA64ISAR0_EL1 on a core with FEAT_IDST. Which describes the exception the kernel receives?

  • A. None. EL0 can read the ID registers directly and gets the raw hardware value
  • B. EC = 0x00, and the kernel must decode the faulting instruction to find the register
  • C. It is trapped to EL2 with EC = 0x18 because HCR_EL2.TID3 is always set under Linux
  • D. EC = 0x18 taken to EL1, with the register encoding and Rt in the ISS, so the kernel can emulate a sanitised value
Answer

D. EL0 accesses to the ID_AA64* registers are UNDEFINED. FEAT_IDST makes exceptions from reads in the feature ID space report EC = 0x18 with a decoded ISS, instead of EC = 0x00. B describes a core without FEAT_IDST: the kernel still emulates, but has to decode the instruction itself. C confuses the hypervisor trap with the EL0 case: TID3 traps EL1 reads to EL2, and an EL0 UNDEF goes to EL1 regardless.

Read more: Arm ARM (DDI0487), FEAT_IDST in A2; ESR_ELx EC 0x18; HCR_EL2.TID3

1.2 What Armv9-A actually changed

v9.0 is v8.5 with a short list of extra rules

Armv9-A did not add a new execution state, a new exception model or a new translation scheme. AArch64 at v9.0 runs the same instruction set, page tables, exception levels and memory model as Armv8.5. Architecturally, Armv9.0 means:

  1. Every Armv8.5 mandatory feature. An Armv9.0 implementation must be a compliant Armv8.5 implementation (1.1). That brings in, among others, FEAT_LSE, FEAT_PAN, FEAT_RAS, FEAT_PAuth, FEAT_BTI, FEAT_SB, FEAT_CSV2 and FEAT_DIT.
  2. SVE2. Arm announced v9 with SVE2 as its headline feature, and every v9 application core so far implements it. Look at the precise wording, though. Current DDI0487 issues list FEAT_SVE2 as OPTIONAL from Armv9.0, and require it for Armv9-A systems that support standard operating systems with rich application environments. Toolchains still treat SVE2 as part of -march=armv9-a (LLVM cites the AAPCS64 for this). For a deeply embedded or real-time PE, or an accelerator control core that claims v9, the ID register is the only authority: check ID_AA64PFR0_EL1.SVE and ID_AA64ZFR0_EL1.SVEver. See DDI0487 A2 for the current text.
  3. AArch32 at EL0 only. In Armv8-A, AArch32 is permitted at any EL, subject to the rule that an EL using AArch32 forces every lower EL to AArch32 as well. In Armv9-A, EL1, EL2 and EL3 are AArch64 only, and AArch32 support at EL0 is optional. Several later cores (for example Cortex-X2 and Cortex-A715) are AArch64-only at every EL. Check ID_AA64PFR0_EL1.EL0 (0b0010 = AArch64 and AArch32). 2.1 covers the execution-state rules in detail.
  4. Trace, if present, is ETE. Armv9 does not require a trace unit. If a PE trace unit is implemented, it must be the Embedded Trace Extension (FEAT_ETE; confirm the exact wording in DDI0487 A2), the v9 successor to ETMv4, programmed through TRC* system registers. The Trace Buffer Extension (FEAT_TRBE), which writes trace to memory through a per-PE buffer (TRBBASER_EL1, TRBPTR_EL1, TRBLIMITR_EL1), is optional. Discover them through ID_AA64DFR0_EL1.TraceVer and .TraceBuffer. See 16.6.
  5. A few removals. For example, the OS Double Lock (FEAT_DoubleLock) is not permitted in v9 (16.1). Check A2 for the complete list of features that are optional in v8 but not permitted in v9.

That is the whole difference at v9.0. Most features associated with “v9” in marketing, such as MTE, RME, SME and BRBE, are optional, and several of them are also permitted in v8.x implementations.

Bring-up note: “We moved to a v9 core” changes the EL3 checklist in practice, even though the architectural delta is small. SVE2 means CPTR_EL3.EZ and ZCR_EL3, plus per-world Z/P/FFR context if any world uses SVE (15.3). ETE/TRBE mean MDCR_EL3 trace-buffer and trace-filter controls (17.3). Losing AArch32 means SCR_EL3.RW and HCR_EL2.RW must be 1, and that any AArch32 BL32 or BL33 legacy payload will not run.

The optional v9.x features

After v9.0, each v9.n release equals the matching v8.(n+5) plus features that exist only on the v9 line. The table groups the significant v9-line optional features by the year Arm published them. The exact “permitted from” version of each is in A2. Do not infer it from the year, because some features are permitted one version earlier than the release that introduced them.

Extensions yearVersionNotable v9-only optional featuresShared with v8 (permitted in v8.x too)
2019v9.1 / v8.6none of noteFEAT_FGT, FEAT_ECV, FEAT_BF16, FEAT_I8MM, FEAT_AMUv1p1, FEAT_TWED, FEAT_MTPMU
2020v9.2 / v8.7FEAT_RME (Realm Management Extension, Arm CCA), FEAT_SME, FEAT_BRBE, FEAT_MEC (an RME extension added to the Arm ARM later; see A2 for its version)FEAT_HCX, FEAT_WFxT, FEAT_XS, FEAT_LS64, FEAT_MTE3, FEAT_PMUv3p7, FEAT_SPEv1p2, FEAT_AFP
2021v9.3 / v8.8none of noteFEAT_MOPS, FEAT_NMI, FEAT_HBC, FEAT_TIDCP1, FEAT_CMOW, FEAT_PMUv3p8
2022v9.4 / v8.9FEAT_SME2 (A2 permits it from v9.2), FEAT_GCS, FEAT_D128/FEAT_SYSREG128, FEAT_LSE128, FEAT_SVE2p1/FEAT_SME2p1FEAT_THE, FEAT_S1PIE/FEAT_S2PIE, FEAT_S1POE/FEAT_S2POE, FEAT_TCR2, FEAT_SCTLR2, FEAT_CSSC, FEAT_RASv2, FEAT_ECBHB, FEAT_SPEv1p4, FEAT_PMUv3p9, MTE refinements (FEAT_MTE4 and related)
2023v9.5FEAT_FP8 and FPMR, FEAT_CPA, FEAT_PAuth_LR, FEAT_HDBSS/FEAT_HACDBS, RME GPT updates (FEAT_RME_GPC2), EL3 write traps (FEAT_FGWTE3), SError delegation, breakpoint mismatch/range updatesnone: no v8 counterpart exists
2024v9.6FEAT_LSUI, FEAT_CMPBR, FEAT_OCCMO, FEAT_UINJ, FEAT_SVE2p2/FEAT_SME2p2, SME quarter-tile and structured-sparsity ops, MPAM domains, FEAT_RME_GPC3, bitwise locking of EL1 system registers, producer-consumer hintsnone
2025 onwardv9.7+for example TLBI domains and MPAMv2; see Arm’s A-profile Architecture Extensions pagenone

A few points this table hides:

  • RME and SME have no v8 form. They exist only on the v9 line and are optional even at v9.6. A v9.2 core may implement neither.
  • Security features are spread across both lines. PAuth (v8.3), BTI and MTE (v8.5), and the 2022 permission indirection, overlays and THE are all v8-line features that v9 inherited. “Armv9 security” is mostly a v8 story. RME is the exception (Part 12, Part 13).
  • Mandatory-from dates still advance on the v9 line. Features such as FEAT_CLRBHB (mandatory from v8.9, and so from v9.4) become mandatory on both lines together.

Why “a v9 core” tells you little

Consider what is guaranteed by “v9.0” versus “v9.2” versus a particular core:

ClaimWhat you may assume
“Armv9.0”The v8.5 mandatory set, AArch64 at EL1–EL3, SVE2 in any rich-OS system, ETE if there is trace
“Armv9.2”Also the v8.7 mandatory set (for example FEAT_HCX; read the A2 list rather than recalling it). Not RME, not SME, not BRBE, not MTE
“Cortex-X / Neoverse V, v9.2”Nothing beyond the claimed version until you read its TRM: SVE vector length, MTE, RME, SME, AArch32 EL0, and SPE/TRBE/BRBE presence all vary by core and sometimes by configuration

Configurable options make this worse. Licensees choose options at integration time: crypto extensions (export rules), sometimes cache sizes, and the presence of particular trace or RAS components. Two SoCs with the same core and revision can report different ID_AA64ISAR0_EL1 crypto fields. And SVE predates v9: Neoverse V1, an Armv8.4 core, implements SVE with 256-bit vectors, while v9.0 cores such as Neoverse N2 have SVE2 with 128-bit vectors.

The working rule for firmware is the one from 1.1: detect each feature, then enable it. TF-A’s ENABLE_FEAT_*=2 and Linux’s capability framework exist because architecture versions are not a reliable proxy.

Validation note: A “v9.x compliance” claim cannot be checked as a single item. Build a per-feature matrix: for each FEAT_ in the claimed version’s mandatory set, check (a) the ID field matches the TRM, (b) the feature works (execute its instructions, access its registers), and (c) the higher-EL enable and trap bits behave, so that an untrapped access executes and a trapped one reports the expected ESR_ELx.EC. A missing mandatory feature, or an ID field that claims a feature the RTL does not have, is the kind of bug the Arm ACS suites catch late. Catching it early is cheap (18.6).

Checkpoint

Q1.2.1 A vendor states that their new SoC’s application cores are “Armv9.2-A”. A platform team plans to rely on Realm support (Arm CCA) for a confidential-VM product. What is the correct conclusion?

  • A. Realm support is guaranteed, because RME is a v9.2 feature
  • B. Realm support is guaranteed if SVE2 is present, because both come with the v9 baseline
  • C. Realm support cannot exist, because RME requires Armv9.4
  • D. Nothing yet. RME is optional at every v9.x, so check ID_AA64PFR0_EL1.RME on the cores and confirm the system-level pieces (GPT-capable SMMU, PAS-aware interconnect and memory protection)
Answer

D. FEAT_RME is permitted from v9.2 but never mandatory, and a CCA system needs system-architecture support beyond the PE (DEN0129). Option A confuses “introduced in” with “mandatory from”, which is the central mistake this section warns about. SVE2 has nothing to do with RME.

Read more: Arm ARM (DDI0487), A2 entry for FEAT_RME; ID_AA64PFR0_EL1.RME; Arm CCA system architecture (DEN0129)

Q1.2.2 A legacy platform has an AArch32 Secure-EL1 trusted OS that boots on an Armv8.2 core. The team ports it unchanged to an Armv9.0 core. What happens, and why?

  • A. It works, if SCR_EL3.RW is cleared so that the lower EL runs AArch32
  • B. It cannot run. Armv9 permits AArch32 only at EL0, so EL1 is AArch64-only
  • C. It works only in Non-secure state, because Armv9 removed AArch32 from Secure state only
  • D. It works if the core implements FEAT_AA32EL1, which every v9.0 core implements
Answer

B. In Armv9-A, EL1 and above are AArch64-only, and AArch32 is at most an EL0 option. On some later cores it is absent entirely. Option A is how this was done on v8 cores that supported AArch32 at EL1. On a core where ID_AA64PFR0_EL1.EL1 reads 0b0001 (AArch64 only), the RW control cannot select AArch32. The trusted OS must be ported to AArch64 (or run as an EL0 AArch32 component under an AArch64 S-EL1).

Read more: Arm ARM (DDI0487), A2 Armv9-A requirements; ID_AA64PFR0_EL1.EL1; SCR_EL3.RW

Q1.2.3 Which statement about Armv9.0 and SVE2 matches current DDI0487 wording most precisely?

  • A. FEAT_SVE2 is OPTIONAL from Armv9.0, but Armv9-A systems supporting standard rich operating systems must provide it. Software should still check ID_AA64PFR0_EL1.SVE and ID_AA64ZFR0_EL1.SVEver
  • B. FEAT_SVE2 is mandatory in every Armv9.0 PE without exception, so its ID fields can be ignored
  • C. FEAT_SVE2 is permitted only from Armv9.2, together with SME
  • D. FEAT_SVE2 is an Armv8.5 mandatory feature, inherited unchanged by v9.0
Answer

A. Arm launched v9 with SVE2 as a headline feature, and compilers enable it for -march=armv9-a. The Arm ARM, however, words the requirement through the rich-OS system condition, not as an unconditional PE requirement. B is the popular simplification, and it is still dangerous for firmware on unusual PEs. SVE and SVE2 are not mandatory at any v8.x.

Read more: Arm ARM (DDI0487), A2 entry for FEAT_SVE2; ID_AA64ZFR0_EL1

1.3 Implementations and errata

The Arm core families

The Arm ARM defines what a PE must do. A core is one implementation of it, documented in its own Technical Reference Manual (TRM). Arm’s own A-profile cores fall into a few lines:

LinePurposeExamples (MIDR PartNum)
Cortex-A, “big”Performance per watt in mobile and clientCortex-A72 (0xD08), A76 (0xD0B), A78 (0xD41), A710, A715, A720
Cortex-A, “LITTLE”EfficiencyCortex-A53 (0xD03), A55 (0xD05), A510, A520
Cortex-XPeak single-thread performanceX1, X2, X3, X4, X925
Neoverse NInfrastructure, balancedN1 (0xD0C), N2, N3
Neoverse VInfrastructure, maximum performance (wide SVE on V1)V1, V2, V3
Neoverse EThroughput and data plane, SMTE1

Since Cortex-A55/A75 (2017), Arm cores are built into DynamIQ clusters around a DynamIQ Shared Unit (DSU): DSU, DSU-AE, DSU-110, DSU-120. The DSU is not a PE. It holds the shared L3, the snoop control and snoop filter, the cluster’s bus interface (ACE or CHI) and ACP, and the cluster power-management logic. It has its own IMPLEMENTATION DEFINED registers, accessed from the cores: CLUSTERCFR_EL1, CLUSTERIDR_EL1 (DSU variant and revision), CLUSTERACTLR_EL1, CLUSTERPWRCTLR_EL1 and others. It also has its own TRM and its own errata notice. A DSU erratum is therefore matched against CLUSTERIDR_EL1, not against the core’s MIDR_EL1.

Neoverse cores also appear in Arm’s Compute Subsystem (CSS) and reference designs with a CMN mesh interconnect. Their errata can involve interactions with the interconnect, which is a separate product with its own errata notice.

What a core TRM adds to the Arm ARM

The TRM is where IMPLEMENTATION DEFINED becomes defined. Firmware engineers rely on these parts of it:

  • The feature list and configuration options, such as crypto present or absent, cache sizes, and number of cores. These fix the expected values of the ID registers (1.1).
  • IMPLEMENTATION DEFINED system registers. These are in the encoding space the architecture reserves for them (op0=3, CRn=11 or CRn=15), and are written S3_<op1>_C15_<CRm>_<op2> in assembly:
    • CPUACTLR_EL1 (and CPUACTLR2/3/..._EL1): auxiliary control, the “chicken bits” that disable a predictor, a prefetcher or a fast path. Most errata workarounds set a bit here. Arm documents many of these bits only through errata notices.
    • CPUECTLR_EL1: extended control. On pre-DynamIQ cores (A53/A57/A72) it holds SMPEN (bit 6), which must be set before caches and MMU are enabled for the core to take part in coherency. DynamIQ cores have no such bit (17.4).
    • CPUPWRCTLR_EL1 (DynamIQ): CORE_PWRDN_EN and retention controls, set before the final WFI of a power-down.
    • Encodings move between generations. Cortex-A53 has CPUACTLR_EL1 at S3_1_C15_C2_0, while Neoverse N1 has it at S3_0_C15_C1_0. Always take the encoding from the specific TRM.
  • Access control for those registers. On many Arm cores, IMPLEMENTATION DEFINED bits in ACTLR_EL3 and ACTLR_EL2 decide whether lower ELs may access them. Firmware normally leaves lower-EL write access disabled.
  • The REVIDR_EL1 bit map: which ECO fixes a given part reports.
  • Reset values, power domains, and the PMU event list, including IMPLEMENTATION DEFINED events (16.3).

Security note: Chicken bits change microarchitectural behaviour that the architecture does not describe, including speculation. Several Spectre-class mitigations (Part 14) are IMP DEF control bits that EL3 sets at reset. Lower-EL write access to CPUACTLR_EL1 lets a compromised kernel undo them. Review ACTLR_EL3 as carefully as SCR_EL3.

Reading an SDEN

Arm publishes a Software Developer Errata Notice (SDEN) for each core and for the DSU. Licensees integrating the core receive further detail under NDA. Each SDEN contains a summary table and one entry per erratum with:

  • ID: a number such as 1688305, used in TF-A build flags and Linux Kconfig names.
  • Category: A (critical, no acceptable workaround), B (significant, or critical with an acceptable workaround), C (minor). “A (rare)” and “B (rare)” mark conditions that are unlikely to occur in practice.
  • Status: “Present in: r0p0, r1p0. Fixed in: r1p1.” Sometimes also “Fixed in r1p0 parts with REVIDR_EL1[n] set”.
  • Description, configurations affected, conditions and implications. The conditions are the precise microarchitectural trigger sequence. Read them, because they often show that your software can never trigger the erratum.
  • Workaround: what software must do, and at which EL.

Match an erratum to a part with MIDR_EL1: Variant [23:20] is the r and Revision [3:0] is the p. Compare (Variant << 4) | Revision as one number, which is what TF-A’s cpu_get_rev_var returns and what CPU_REV(r, p) builds. Then apply the REVIDR_EL1 exception if the SDEN gives one.

MIDR_EL1 = 0x411FD410   Implementer 0x41 (Arm), Variant 1, Arch 0xF, PartNum 0xD41, Revision 0
         -> Cortex-A78 r1p0, rev_var = 0x10
"Present in r0p0, r1p0; fixed in r1p1"   ->  affected if rev_var <= 0x10   (check_erratum_ls ..., CPU_REV(1,0))

Validation note: On multi-die or multi-cluster parts, read MIDR_EL1, REVIDR_EL1 and CLUSTERIDR_EL1 on every core during first silicon bring-up and log them. Mixed revisions within one product do happen, especially across chiplets taped out at different times. A workaround applied only where the boot core’s revision says so leaves the other dies exposed. The TF-A errata report at boot (below) is a cheap per-core cross-check.

Workaround types

TypeExampleWho applies it
IMP DEF control bitSet a CPUACTLR2_EL1 bit to disable a fast pathEL3 at reset, usually because lower-EL access is disabled
Instruction sequenceAdd a DSB or ISB, repeat a TLBI, add a branch-predictor flush loop on exception entryWhatever EL executes the affected code: EL3 vectors, the kernel, KVM
Software avoidanceNever generate the triggering pattern. Cortex-A53 843419 (ADRP at specific page offsets) and 835769 (multiply-accumulate after a memory op) are handled by the linker (--fix-cortex-a53-843419) and compiler (-mfix-cortex-a53-835769)The toolchain, for every image that runs on the core
SplitEL3 sets a control bit and the OS must also add a sequenceBoth, and the OS needs to be told

Some workarounds cost performance or power. The SDEN says so, and that is why TF-A makes each one a build option instead of enabling all of them.

Apply at reset and on every warm boot

IMP DEF control registers are in the core’s power domain. When a core is powered off (CPU_OFF, or CPU_SUSPEND to a power-down state), they lose their values, and on power-up they come back at their reset values. A chicken bit set only on the cold-boot path therefore disappears after the first deep idle. The rules:

  1. Apply reset-type workarounds in the per-core reset handler, which runs on cold boot and on every warm entry. Apply them before the core enables its caches and MMU, joins coherency or enables branch prediction, unless the SDEN says otherwise. Some bits are only safe to change before these are enabled.
  2. Apply runtime workarounds at the point the SDEN names: power-down sequence, context switch, or exception entry.
  3. Check every core, with each core reading its own MIDR_EL1. Never cache the boot core’s result.

TF-A’s errata framework: the worked example

TF-A keeps per-core code in lib/cpus/aarch64/<core>.S. Each erratum is a pair of macros: one applies the workaround, the other checks the revision.

cpu_reset_prologue cortex_a78

workaround_reset_start cortex_a78, ERRATUM(1688305), ERRATA_A78_1688305
	sysreg_bit_set CORTEX_A78_ACTLR2_EL1, CORTEX_A78_ACTLR2_EL1_BIT_1
workaround_reset_end cortex_a78, ERRATUM(1688305)

check_erratum_ls cortex_a78, ERRATUM(1688305), CPU_REV(1, 0)
  • workaround_reset_start/end adds the code to cortex_a78_reset_func, guarded by the check function, when the build flag ERRATA_A78_1688305=1. It also records an entry in the core’s errata list.
  • check_erratum_ls (revision ≤), check_erratum_hs (≥) and check_erratum_range generate the revision test against cpu_get_rev_var.
  • workaround_runtime_start plus apply_erratum place a workaround elsewhere, for example in cortex_a78_core_pwr_dwn, next to the CPUPWRCTLR_EL1.CORE_PWRDN_EN write.
  • CVE mitigations use the same machinery with CVE(2022, 23960) and WORKAROUND_CVE_2022_23960.
  • declare_cpu_ops cortex_a78, CORTEX_A78_MIDR, cortex_a78_reset_func, cortex_a78_core_pwr_dwn registers the core. At reset, el3_entrypoint_common runs call_reset_handler, which calls plat_reset_handler, finds the cpu_ops entry matching MIDR_EL1 with get_cpu_ops_ptr, and calls its reset function. bl31_warm_entrypoint uses the same macro, so every warm boot re-applies the workarounds.
  • DSU errata are ERRATA_DSU_<id> flags, checked against CLUSTERIDR_EL1.
  • With REPORT_ERRATA=1, each core logs one line per erratum that applies to its revision. An enabled workaround prints BL31: cortex_a78: CPU workaround for erratum 1688305 was applied at INFO level, so it appears only with LOG_LEVEL 40 or higher. If the erratum applies but its flag is off, the line ends in missing! and is printed as a WARN. Review this output on first silicon, on every core type.

The authoritative flag list is docs/design/cpu-specific-build-macros.rst.

Telling lower ELs: SMCCC_ARCH_WORKAROUND_* and the Errata ABI

Some mitigations need cooperation between EL3 and the OS. SMCCC (12.3) defines Arm-architecture calls that the OS discovers with SMCCC_ARCH_FEATURES (0x80000001). A return of 0 means the call is implemented and needed. Where the spec defines it, 1 means this PE is not affected. A negative value means not supported.

CallIDIssueDetail
SMCCC_ARCH_WORKAROUND_10x80008000CVE-2017-5715 (Spectre v2, branch target injection)14.4
SMCCC_ARCH_WORKAROUND_20x80007FFFCVE-2018-3639 (Spectre v4, SSB)14.5
SMCCC_ARCH_WORKAROUND_30x80003FFFCVE-2022-23960 (Spectre-BHB), also covers WA_114.4
SMCCC_ARCH_WORKAROUND_40x80000004CVE-2024-7881 (data memory-dependent prefetcher). Discovery only: firmware applies the fix at boot. Linux enables KPTI on affected cores if the call is absent14.6

For errata in general, Arm defines the Errata Management Firmware Interface (DEN0100), the “Errata ABI”. EM_VERSION (0x840000F0), EM_FEATURES (0x840000F1) and EM_CPU_ERRATUM_FEATURES (0x840000F2, arguments: erratum ID and a forward flag that a hypervisor sets when forwarding a guest query). The answer is per PE:

ReturnMeaning for the caller
HIGHER_EL_MITIGATION (3)Affected, and fully mitigated above you. Do nothing
NOT_AFFECTED (2)This PE, revision and system are not affected
AFFECTED (1)Affected and not fully mitigated above you. Apply your part of the workaround
UNKNOWN_ERRATUM (−3)Firmware has no information. Fall back to MIDR/REVIDR matching

The ABI exists because MIDR/REVIDR matching cannot tell the OS two things: whether firmware already set the chicken bit, and whether a non-Arm interconnect makes a core erratum reachable. TF-A implements it with ERRATA_ABI_SUPPORT=1. It answers from the same errata list (a split workaround reports AFFECTED even when the EL3 half is applied), and ERRATA_NON_ARM_INTERCONNECT adds platform-specific entries. OS support varies, so do not assume the ABI is queried.

Checkpoint

Q1.3.1 A workaround that sets a CPUACTLR_EL1 bit is applied by EL3 firmware in its cold-boot platform setup. Tests pass after boot, but the erratum’s failure signature appears hours later under a workload with deep idle. What is the most likely cause?

  • A. The OS kernel cleared the bit, since CPUACTLR_EL1 is writable from EL1 by default on all Arm cores
  • B. The write needed a DSB after it, and without one the bit only took effect on some cores
  • C. The core lost the bit when it powered down for idle, and warm-boot entry did not re-run the workaround because it was not in the per-core reset handler
  • D. Deep idle changes MIDR_EL1.Revision, so the revision check then fails
Answer

C. IMP DEF control registers are in the core power domain and return to their reset values on every power-up. Workarounds belong in the per-core reset function, which TF-A runs on both cold and warm entry. A is possible only if ACTLR_EL3/ACTLR_EL2 grant lower-EL write access, which is IMP DEF and normally disabled, and it would not explain the link to idle. B: synchronisation of a system register write needs an ISB at most and has nothing to do with idle. MIDR_EL1 is fixed.

Read more: core TRM, CPUACTLR_EL1 and power domains; TF-A lib/cpus reset handler and bl31_warm_entrypoint

Q1.3.2 A core reports MIDR_EL1 = 0x412FD0C0. An erratum is listed as “Present in r0p0–r2p0, fixed in r3p0; also fixed in r2p0 parts with REVIDR_EL1[4] set”. REVIDR_EL1 reads 0x10. What is the right decision?

  • A. Not affected. The part is r2p0 (Variant 2, Revision 0), which is in the affected range, but REVIDR_EL1 bit 4 is set, so the ECO fix is present
  • B. Affected, because REVIDR_EL1 is IMPLEMENTATION DEFINED and can never override MIDR
  • C. Not affected, because the Revision field is 0 and the fix is listed under r3p0, whose Revision is also 0
  • D. Affected, because Variant 2 is r0p2, inside r0p0–r2p0
Answer

A. Variant [23:20] = 2 and Revision [3:0] = 0 give r2p0, which falls in the affected range. 0x10 sets bit 4, which the SDEN names as the ECO marker. REVIDR_EL1 is IMP DEF in the Arm ARM, but the core’s TRM and SDEN define it, and that is exactly how fixes within a revision are reported. C compares only Revision and ignores Variant. D swaps r and p.

Read more: Arm ARM (DDI0487), MIDR_EL1, REVIDR_EL1; the core’s SDEN errata status fields

Q1.3.3 TF-A is built with the workaround for erratum N enabled, and with ERRATA_ABI_SUPPORT=1. On an affected core, the kernel’s EM_CPU_ERRATUM_FEATURES(N) call returns AFFECTED (1). What does this imply?

  • A. A firmware bug, because an enabled workaround must always report NOT_AFFECTED
  • B. The erratum has a split workaround. EL3 applied its part, but the caller must still apply its own part (for example an instruction sequence)
  • C. The forward flag was set from EL1, so the result is invalid
  • D. The core has an ECO fix in REVIDR_EL1, so the workaround was skipped
Answer

B. If the PE is affected and firmware mitigates it completely, the answer is HIGHER_EL_MITIGATION (3). AFFECTED with the workaround enabled is how TF-A reports a split workaround, where only part of the mitigation can be done above the caller. A misreads the meaning of NOT_AFFECTED, which describes the PE, not the mitigation. A forward flag set from EL1 returns INVALID_PARAMETERS (−2), not 1. D cannot produce this result either: TF-A’s check functions mostly test MIDR_EL1 only, and where a check does account for an ECO fix, the answer is NOT_AFFECTED, not AFFECTED.

Read more: Arm Errata Management Firmware Interface (DEN0100); TF-A services/std_svc/errata_abi

Part 2: AArch64 programmer’s model

Prerequisites: 1.1 Versions, FEAT_ names and discovery (ID registers and the “permitted from / mandatory from” vocabulary). If you already know: AAPCS64 and A64 assembly from TF-A or kernel work, skim 2.2 and the first half of 2.3; do not skip 2.4–2.6, which carry the v8.8+ state that later parts assume. Why this matters for bring-up/validation: almost every “the core hangs, takes an UNDEF or traps to EL3 on a new feature” failure traces back to the execution-state, PSTATE, system-register encoding or trap-control facts in this part.

This part fixes the vocabulary the rest of the book uses for “where code runs” and “what state it runs with”. 2.1 separates three independent axes that are often blurred: the Exception level, the Security state (including RME’s Realm and Root), and the execution state (AArch64 or AArch32), and states exactly when each can change. 2.2 and 2.3 cover the register file, AAPCS64, and enough of the A64 encoding space that you can read a firmware disassembly and see why new features (BTI, PAC, MOPS, 128-bit system registers) are encoded where they are.

The second half is about control state. 2.4 lists every PSTATE field up to v9.6 together with the one access path each permits, 2.5 explains the system-register encoding space that MRS, MSR, SYS and the new MRRS/MSRR all index, and 2.6 gives a one-page map of which register at which EL traps or enables which class of functionality. It ends with the rule that drives most of Part 17: a new feature is disabled or trapped until a higher EL turns it on.

2.1 Exception levels, Security states and execution states

At any moment a PE is described by three separate properties:

AxisValuesChanges at
Exception levelEL0, EL1, EL2, EL3exception entry, exception return (and reset)
Security stateSecure, Non-secure, Realm (RME), Root (RME)exception entry to or return from EL3, or a change of SCR_EL3.{NSE,NS} followed by an exception return
Execution stateAArch64, AArch32exception entry and exception return only (and reset)

Keeping these apart prevents most of the common confusion. “Secure EL1” is one point in this space. “EL3” is not a Security state. Being in AArch32 says nothing about which EL you are at.

Exception levels

The EL sets the privilege of the current software and which system registers it can reach. A register suffixed _ELn is accessible at ELn and above, with the exceptions covered in 2.5.

  • EL0: unprivileged applications. Always implemented.
  • EL1: OS kernel or a Secure OS such as OP-TEE. Always implemented.
  • EL2: hypervisor. Optional. Present in the Secure state only with FEAT_SEL2 (permitted from v8.4) and SCR_EL3.EEL2 = 1.
  • EL3: the monitor. Optional architecturally, but every practical TrustZone or RME system has it.

Exceptions are taken to the same or a higher EL, and exception returns go to the same or a lower EL. There is no instruction that changes the EL except by these two routes. CurrentEL (bits [3:2]) reports the EL, and reading it from EL0 is UNDEFINED.

Security states and which combinations exist

Without FEAT_RME there are two Security states. EL3 is always Secure, and SCR_EL3.NS selects the state of EL2/EL1/EL0. With FEAT_RME (permitted from v9.2) there are four. EL3 runs in Root, and the pair SCR_EL3.{NSE,NS} selects the state of the lower ELs:

SCR_EL3.{NSE,NS}Lower-EL Security state
0,0Secure
0,1Non-secure
1,0Reserved
1,1Realm

The resulting combinations:

ELNon-secureSecureRealmRoot
EL3noyes (only without RME)noyes (only with RME)
EL2yeswith FEAT_SEL2 and SCR_EL3.EEL2=1yesno
EL1yesyesyesno
EL0yesyesyesno

SCR_EL3.{NSE,NS} takes effect for the lower ELs on the next exception return from EL3. While the PE is executing at EL3 they do not change the state EL3 itself runs in, but they do select which lower-EL translation regime EL3’s AT and TLBI operations target, and which Secure or Non-secure copy of the banked GICv3 CPU-interface registers (such as ICC_IGRPEN1_EL1) EL3 accesses. 12.1 and 12.4 cover the memory side: PA spaces, the TZASC and the GPT.

Security note: The Security state determines which physical address space the PE’s accesses are made to. The Exception level does not. Secure EL0 can reach Secure PA space that Non-secure EL2 cannot. Reviews that treat “higher EL” as “more trusted” go wrong for Realm vs Non-secure EL2 in particular: Non-secure EL2 cannot access the Realm PA space at all, while Realm EL0 can access Realm PA space and, where its stage 2 maps it, Non-secure PA space.

Execution states

AArch64 and AArch32 are execution states. They are not modes. The execution state of an EL is fixed while that EL runs, and it can change only:

  • on exception entry, to the state of the target EL, which is never AArch32 if any lower EL is AArch64;
  • on exception return, to the state encoded in SPSR_ELx.M[4] (0 for AArch64, 1 for AArch32), subject to the controls below;
  • at reset, to the state the implementation resets into (for EL3, see RMR_EL3 and the core’s IMP DEF reset configuration).

The rule that ties the ELs together is that if an EL uses AArch32, all lower ELs use AArch32. Equivalently, an AArch64 EL is never below an AArch32 EL. Moving between execution states when an exception crosses ELs is called interprocessing. An ERET that requests AArch32 at a level that cannot use it, or AArch64 under an AArch32 level, is an illegal exception return: PSTATE.IL is set and the next instruction takes an Illegal Execution state exception (see 3.2).

Who decides the state of the next lower EL

ControlDecidesNotes
SCR_EL3.RWState of the EL directly below EL3: EL2 if EL2 is implemented and enabled in the target Security state, otherwise EL11 = AArch64. RAO/WI if the lower EL cannot use AArch32
HCR_EL2.RWState of EL1 when EL2 is enabled1 = AArch64. RAO/WI if EL1 cannot use AArch32. Not used when HCR_EL2.{E2H,TGE} = {1,1}, because then there is no EL1 guest
SPSR_EL1.M[4] / SPSR_EL2.M[4] on ERET to EL0State of EL0EL0 has no RW bit. Its state is chosen on every return, so an AArch64 kernel can run AArch32 and AArch64 processes side by side

SCR_EL3.RW is the most common bring-up bug in this group. Several SCR_EL3 fields reset to architecturally UNKNOWN values, so EL3 firmware must write the whole register, RW included, before the first ERET to an AArch64 BL33 or hypervisor. TF-A’s context-management library (lib/el3_runtime/aarch64/context_mgmt.c) derives it from the next image’s entry-point information (SPSR and security attributes).

What the architecture versions permit

  • Armv8-A permits AArch32 at any EL, subject to the “lower ELs follow” rule. Examples include AArch32 EL0 under an AArch64 kernel, a whole AArch32 Non-secure world under an AArch64 EL3, and even AArch32-only cores such as Cortex-A32. Support at each EL is IMPLEMENTATION DEFINED, and ID registers report it.
  • Armv9-A permits AArch32 at EL0 only. EL1, EL2 and EL3 are AArch64-only. AArch32 at EL0 is still optional (see 1.2).
  • Implementations have gone further and dropped AArch32 entirely. Cortex-X2 has no AArch32 support at any EL, and Cortex-A715 and later big and mid cores (and Cortex-A520 among the little cores) are AArch64-only. Cortex-A710 and Cortex-A510 still provide AArch32 at EL0. A DynamIQ cluster that mixes them is therefore asymmetric. Linux handles this with the opt-in allow_mismatched_32bit_el0 mode, which restricts 32-bit tasks to capable CPUs. Firmware is not affected, since it has no AArch32 code.

Treat the core list as an example. The authority for a given part is its TRM and its ID registers.

Discovering support: ID_AA64PFR0_EL1.EL0–EL3

FieldBits0b00000b00010b0010
EL0[3:0](not used)AArch64 onlyAArch64 and AArch32
EL1[7:4](not used)AArch64 onlyAArch64 and AArch32
EL2[11:8]EL2 not implementedAArch64 onlyAArch64 and AArch32
EL3[15:12]EL3 not implementedAArch64 onlyAArch64 and AArch32

Other relevant fields are ID_AA64PFR0_EL1.SEL2 (Secure EL2) and ID_AA64PFR0_EL1.RME. For heterogeneous clusters, the system-wide value is the minimum across cores, which is what Linux’s cpufeature code computes (see 1.1). The AArch32 views of the same state (ID_PFR0/1 and the AArch32 register mappings) are tabulated in Appendix B.

    // Can EL1 run AArch32? (EL1 field, bits [7:4])
    mrs     x0, id_aa64pfr0_el1
    ubfx    x1, x0, #4, #4
    cmp     x1, #2
    b.eq    el1_has_aa32
    // otherwise: SCR_EL3.RW / HCR_EL2.RW are RAO/WI for EL1

Bring-up note: If a pre-silicon model or an early FPGA image reports ID_AA64PFR0_EL1.EL2 = 0 or EL3 = 0 unexpectedly, check the model’s configuration parameters before debugging firmware. On FVP and in RTL testbenches, whether EL2/EL3 is implemented, and which ELs have AArch32, are configuration options, and a mismatch shows up only as an UNDEF on the first msr hcr_el2 or a SCR_EL3 write that never sticks.

Checkpoint

Q2.1.1 On a core with ID_AA64PFR0_EL1.EL0 = 0b0001, an AArch64 guest kernel (SCR_EL3.RW = 1, HCR_EL2.RW = 1) tries to start a 32-bit process by executing ERET with SPSR_EL1.M[4] = 1 and a valid AArch32 User mode in M[3:0]. What happens?

  • A. The process starts in AArch32, because EL0’s execution state is chosen only by SPSR_EL1.M[4]
  • B. The ERET completes to EL0 in AArch64, with M[4] ignored because it is RES0 on this core
  • C. It is an illegal exception return: the PE stays at EL1 with PSTATE.IL = 1, and the next instruction takes an Illegal Execution state exception to EL1
  • D. The ERET traps to EL2, because HCR_EL2.RW controls EL0’s state as well
Answer

C. A return to an execution state the target EL does not support is one of the listed illegal exception return cases. PSTATE.EL, nRW and SP are left unchanged, PSTATE.IL is set, and execution resumes at ELR_EL1 in EL1, where the first instruction takes the Illegal Execution state exception (EC 0x0E). A is tempting: M[4] does select EL0’s state, but only within what the implementation and the level above permit. HCR_EL2.RW controls EL1, not EL0, and there is no ERET trap here, so D is wrong.

Read more: Arm ARM (DDI0487), “Illegal return events from AArch64 state”; “Interprocessing”; ID_AA64PFR0_EL1

Q2.1.2 On an RME system, EL3 sets SCR_EL3.{NSE,NS} = {1,1} and then, still at EL3, writes SCTLR_EL1. Which statement is correct?

  • A. EL3 is still in Root state. The values take effect for the lower ELs on the next ERET, which enters Realm state
  • B. EL3 is now in Realm state, so its own memory accesses go to the Realm PA space
  • C. The write is illegal: {NSE,NS} may only be changed with the MMU off
  • D. {1,1} is the reserved encoding, so the next ERET is an illegal exception return
Answer

A. EL3 always runs in Root when RME is implemented. {NSE,NS} selects the Security state of the lower ELs, which is entered on exception return, so EL3 typically programs the target world’s EL1/EL2 context and then ERETs. B confuses the “lower-EL state” field with EL3’s own state. {1,0} is the reserved encoding, not {1,1}, so D is wrong.

Read more: Arm ARM (DDI0487), SCR_EL3.NSE and SCR_EL3.NS; “Security states” in the AArch64 exception model; RME system architecture (DEN0129)

Q2.1.3 Linux on a big.LITTLE phone reports that only some CPUs can run a 32-bit app. Which ID-register observation explains this?

  • A. ID_AA64PFR0_EL1.EL1 = 0b0001 on all CPUs
  • B. ID_AA64PFR0_EL1.EL3 = 0b0000 on the big CPUs
  • C. ID_AA64PFR0_EL1.EL0 = 0b0010 on all CPUs, but HCR_EL2.RW = 1
  • D. ID_AA64PFR0_EL1.EL0 = 0b0010 on some CPUs and 0b0001 on others
Answer

D. The EL0 field reports per-CPU AArch32 support at EL0. A mix such as Cortex-A710 (AArch32 EL0) and Cortex-X2 (AArch64 only) gives an asymmetric system, so the sanitised system-wide value is “AArch64 only” unless the kernel opts into mismatched 32-bit EL0. C is tempting, but HCR_EL2.RW controls EL1’s state, not EL0’s, and setting it to 1 does not stop AArch32 EL0.

Read more: Arm ARM (DDI0487), ID_AA64PFR0_EL1; Linux Documentation/arch/arm64/asymmetric-32bit.rst

2.2 Registers and the calling convention

The general-purpose register file

AArch64 has 31 general-purpose registers, X0–X30, each 64 bits wide. W0–W30 name their low 32 bits. Two rules matter in practice:

  • A write to a Wn register zero-extends into Xn. mov w0, #-1 leaves x0 = 0x00000000_ffffffff. Firmware that builds a 64-bit address in a W register silently loses the top half, and a 32-bit ldr w1, [x0] result is never sign-extended unless you use ldrsw.
  • Register number 31 is not a register. Depending on the instruction it means the stack pointer (SP/WSP, for example as the base of a load or in add sp, sp, #16) or the zero register (XZR/WZR, which reads as zero and ignores writes, for example str xzr, [x0] or cmp x0, #0 = subs xzr, x0, #0). Each encoding fixes which one, so mov x0, sp and mov x0, xzr are different instructions (add x0, sp, #0 and orr x0, xzr, xzr).

There is no banking of X0–X30 by EL or Security state. An exception to EL3 arrives with the lower EL’s registers live, which is why the first instructions of any EL3 vector save registers to a per-CPU context before using them. TF-A’s cpu_context_t holds exactly this state.

The program counter

The PC is not a general-purpose register. No data-processing instruction can read or write it directly, and there is no mov x0, pc. It is read only implicitly: by PC-relative instructions (ADR, ADRP, literal LDR, branches), by BL/BLR, which write the return address to X30, and by the exception-entry logic, which writes ELR_ELx. It is written only by branches, exception entry and ERET. Instructions are 4-byte aligned. A branch to a misaligned target takes a PC alignment fault (EC 0x22) when the misaligned PC is used, not at the branch.

Stack pointers and SPSel

Each implemented EL has its own stack pointer: SP_EL0, SP_EL1, SP_EL2, SP_EL3. At EL0 the PE always uses SP_EL0. At EL1 and above, PSTATE.SP (written through the SPSel special register) chooses:

PSTATE.SPSP used at ELx (x ≥ 1)Vector table group used for exceptions taken from the current EL
0SP_EL0 (“ELxt”)“Current EL with SP0”
1SP_ELx (“ELxh”)“Current EL with SPx”

Exception entry always sets PSTATE.SP = 1, so a handler starts on its own EL’s dedicated stack, whatever the interrupted code was using. SP_EL0 can be accessed from EL1 and above as a system register (mrs x0, sp_el0) when not currently selected. SP_ELx for the current EL cannot be accessed that way, and SP_EL1 is accessible from EL2 and EL3.

    msr     spsel, #0           // switch to SP_EL0 at the current EL
    mov     sp, x1              // initialise it
    msr     spsel, #1           // back to SP_ELx

TF-A uses the split deliberately. At EL3, SP_EL3 holds a pointer to the current CPU’s cpu_context_t, and the C runtime stack is SP_EL0. On entry from a lower EL, the handler saves the lower world’s GPRs through SP_EL3, then executes msr spsel, #MODE_SP_EL0 and calls C. Linux uses SP_EL0 at EL1 differently: while running in the kernel, sp_el0 holds the current task pointer.

SP alignment checking. When SCTLR_ELx.SA (bit [3]) is set, a load or store that uses SP as its base register at ELx with SP not 16-byte aligned takes an SP alignment fault (EC 0x26). SCTLR_EL1.SA0 (bit [4]) is the same check for EL0. The check is on the base register value at the time of the access, not on every arithmetic update of SP.

Bring-up note: TF-A sets SCTLR_EL3.SA very early in el3_entrypoint_common. If a hand-written assembly path pushes a single 8-byte register with str x0, [sp, #-8]!, the next SP-based access faults. In a bare vector table with no handler yet installed, this shows up as a recursive exception loop at VBAR_EL3 + 0x200. Always push and pop in 16-byte pairs (stp/ldp).

AAPCS64 register roles

The Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64, part of Arm’s ABI set) defines how compiled code uses the registers. The architecture itself gives no register a special role except X30 (written by BL/BLR, used by RET by default) and register 31.

RegisterAAPCS64 rolePreserved across a call?
X0–X7Arguments and resultsNo
X8Indirect result location (address of a large returned struct)No
X9–X15TemporariesNo
X16, X17 (IP0, IP1)Intra-procedure-call scratch: veneers and PLT stubs may clobber themNo
X18Platform register (see below)Platform-defined
X19–X28Callee-savedYes
X29 (FP)Frame pointerYes
X30 (LR)Link registerSaved by any non-leaf function
SPStack pointer, 16-byte aligned at any public interfaceYes
V8–V15Only the low 64 bits (D8–D15) are callee-savedPartially
other V, Z, PCaller-saved. The SVE and SME extensions to the PCS are in 15.2No

Points that matter in firmware:

  • X16/X17 and veneers. A linker can insert a veneer between a BL and a far target that uses X16/X17. Assembly that keeps live values in them across a call to another object file can break at link time. They are also the registers through which BR reaches a BTI c landing pad from a PLT. Details are in 13.1.
  • No red zone in AAPCS64. Code may not use memory below SP. An exception taken to the same EL while that EL runs on SP_ELx starts its handler on the same stack and would overwrite it. Some platform ABIs (Apple’s) define one, but neither firmware nor Linux does.
  • SMCCC is not AAPCS64. The SMC calling convention passes up to X0–X17 as arguments and results. SMCCC v1.0 left X4–X17 unpredictable on return, v1.1 mandates their preservation, and v1.2 allows them to carry results (and otherwise still preserves them). X18–X30 and the stack pointers are always callee-preserved. A C wrapper around smc #0 therefore has to declare its clobbers explicitly. See 12.3.
  • FP/SIMD in firmware. TF-A and most RTOS kernels build with -mgeneral-regs-only, so they never touch V registers. EL3 then has to save the lower world’s FP state only when a world switch can expose it (TF-A’s CTX_INCLUDE_FPREGS). See 15.3.

X18, the platform register

AAPCS64 leaves X18 to the platform. A platform either reserves it for a fixed purpose or declares it an ordinary temporary. Known uses:

  • Linux kernel with Shadow Call Stack (CONFIG_SHADOW_CALL_STACK): X18 holds the shadow-stack pointer, and the kernel is compiled with -ffixed-x18.
  • Windows on Arm: X18 points to the TEB in user mode.
  • Apple platforms: reserved, and must not be used.
  • Most bare-metal and firmware builds: an ordinary temporary.

Security note: The danger is at boundaries. A kernel that relies on SCS trusts X18 on return from any call. If firmware or a Secure partition clobbers X18 across an SMC and the kernel’s SMC wrapper does not save it, the kernel loses its shadow-stack pointer. SMCCC requires the callee to preserve X18 (with X19–X30) across calls, which is why EL3 must restore the full GPR context on every return to the Normal world, and why the reverse direction (OP-TEE or an SP calling into a hosted service) needs the same care.

Frame records

When a function establishes a frame, AAPCS64 asks it to store a frame record of two 64-bit words, the caller’s X29 followed by X30, and to point X29 at that record. The records form a linked list through the stack:

  X29 ──► +0x00  previous X29  ──► (caller's frame record) ──► ... ──► 0
          +0x08  saved X30 (return address into caller)
func:
    stp     x29, x30, [sp, #-32]!   // push frame record (+16 bytes of locals)
    mov     x29, sp                 // FP points at the record
    ...
    ldp     x29, x30, [sp], #32
    ret

A crash handler can walk the list from the faulting X29 to produce a backtrace without unwind tables. This is usually the only backtrace available in early firmware. Three caveats apply. Leaf functions and code built with -fomit-frame-pointer do not push records. The chain should end with a zero X29, so set x29 = 0 before the first C call at reset. With PAC-RET (-mbranch-protection=pac-ret), the saved X30 is signed, so the backtracer must strip the PAC (XPACI, or XPACLRI on X30) before symbolising it (13.1). Decoding a crash end to end, including ELR and FAR, is in 18.1.

Checkpoint

Q2.2.1 An EL1 kernel runs with PSTATE.SP = 0 (on SP_EL0) inside a critical section, and an IRQ is taken to EL1. Which vector-table entry is used, and which stack does the handler start on?

  • A. “Current EL with SP0”, running on SP_EL0
  • B. “Current EL with SP0”, running on SP_EL1
  • C. “Current EL with SPx”, running on SP_EL1
  • D. “Lower EL using AArch64”, running on SP_EL1
Answer

B. The vector group records the SP selection that was in use when the exception was taken, so it is “Current EL with SP0”. Exception entry then sets PSTATE.SP = 1, so the handler runs on SP_EL1. Option A assumes the handler inherits the interrupted SP selection. Option C names the right stack but the wrong vector group. The interrupted code was at EL1, not a lower EL, so D is wrong.

Read more: Arm ARM (DDI0487), “Exception vectors” and SPSel; see also 3.1

Q2.2.2 A Normal-world kernel built with Shadow Call Stack starts crashing on return from one particular SMC. The Secure-side handler is C code compiled as an ordinary bare-metal build. What is the most likely cause?

  • A. The SMC handler did not preserve X29, which breaks the frame-record chain
  • B. X16/X17 were clobbered by a linker veneer inside the Secure image
  • C. The handler left SP misaligned, so SCTLR_EL1.SA faulted after return
  • D. X18 was used as a temporary on the Secure side, and EL3 returned without restoring the Normal world’s X18
Answer

D. SCS keeps the shadow-stack pointer in X18, and in an ordinary bare-metal build X18 is a temporary. Registers are not banked by Security state, so unless EL3 restores the Normal world’s saved GPRs (SMCCC requires X18 to be preserved), the kernel resumes with a corrupted shadow-stack pointer and faults on its next shadow-stack pop. X29 would also need preserving, but losing it breaks backtraces, not returns. Veneers inside the Secure image cannot affect the Normal world’s registers once EL3 restores the context.

Read more: Arm SMC Calling Convention (DEN0028), register preservation; AAPCS64, “General-purpose registers”

Q2.2.3 Early boot code does mov w0, #0x80000000 and movk x0, #0x1, lsl #32, then ldr w1, [x0]. Which statement about the registers is correct?

  • A. x0 = 0x1_8000_0000 and the upper 32 bits of x1 are zero after the load
  • B. x0 = 0x1_8000_0000 and x1 holds the loaded word sign-extended, because bit 31 of the address is set
  • C. x0 = 0x8000_0000, because writes to w0 lock out the upper half until the next X write
  • D. x0 = 0xffff_ffff_8000_0000, because mov w0 sign-extends into x0
Answer

A. A write to w0 zero-extends, giving 0x0000_0000_8000_0000. MOVK then replaces bits [47:32] only and keeps the rest. ldr w1 also writes w1 and zero-extends into x1. Only ldrsw sign-extends, and it does so based on the loaded data, not the address, so B mixes up two things. D is the common belief that 32-bit writes sign-extend, and they never do.

Read more: Arm ARM (DDI0487), “Registers in AArch64 state” and the MOVK/LDRSW instruction descriptions

2.3 A64 instruction set essentials

This section is not an instruction reference. It covers the parts of the A64 design that explain what you see in a firmware disassembly, and why new architecture features are encoded where they are.

Fixed 32-bit encoding and the top-level groups

Every A64 instruction is 32 bits, little-endian in memory regardless of data endianness, and 4-byte aligned. Bits [28:25] (called op1 in the Arm ARM’s top-level table) select the main encoding group:

bits [28:25]Group
0000Reserved (includes UDF #imm16). With bit [31] = 1: SME encodings
0010SVE encodings
100xData processing, immediate
101xBranches, exception generation, and system instructions
x1x0Loads and stores
x101Data processing, register
x111Data processing, scalar FP and Advanced SIMD
0001, 0011Unallocated

Two consequences follow. First, an immediate operand has to fit inside 32 bits alongside the opcode. That is why MOV of an arbitrary 64-bit constant becomes a MOVZ/MOVK sequence (TF-A’s mov_imm macro), and why logical immediates use the compact “bitmask immediate” encoding, which cannot express every value. Second, the all-zero word 0x00000000 decodes as UDF #0. A branch into zero-filled memory therefore takes an Undefined Instruction exception (EC 0x00) at the first instruction, which is much easier to diagnose than running off into garbage.

Loads and stores

A64 is a load/store architecture. Only load and store instructions access memory, plus the atomics in 10.2 and the MOPS instructions below. The addressing modes:

ModeSyntaxEffective addressBase written back
Unsigned offsetldr x0, [x1, #16]x1 + 16 (scaled, 12-bit)no
Unscaled offsetldur x0, [x1, #-3]x1 - 3 (signed 9-bit)no
Pre-indexldr x0, [x1, #16]!x1 + 16yes, before the access
Post-indexldr x0, [x1], #16x1yes, x1 + 16 after
Register offsetldr x0, [x1, x2, lsl #3] / [x1, w2, sxtw]x1 + (x2 << 3)no
Literalldr x0, label / ldr x0, =constPC + simm19*4 (±1 MiB)n/a
Pairldp x0, x1, [sp], #16 / stp x29, x30, [sp, #-16]!as above, two registersper form

LDP/STP are the workhorses of save/restore code. The assembler pseudo-instruction ldr x0, =const places the constant in a nearby literal pool and emits a PC-relative literal load. That is fine in firmware, provided the literal pool is in the same position-independent image.

Conditional execution without IT

A64 has no general predication and no IT blocks. Instead, a small set of instructions read the flags:

  • B.cond, CBZ/CBNZ, TBZ/TBNZ for branches. CB* and TB* test a register directly and leave the flags unchanged.
  • CSEL, CSINC, CSINV, CSNEG for branchless selects. CSET/CINC are aliases: cset w0, eq = csinc w0, wzr, wzr, ne.
  • CCMP/CCMN for compare chains: if the condition holds, compare; otherwise set NZCV to an immediate.
    // x0 = (a == 1 && b == 2) ? 1 : 0, no branches
    cmp     x1, #1
    ccmp    x2, #2, #0b0000, eq   // if a==1, compare b; else NZCV=0000 (=> "ne")
    cset    x0, eq

Branchless selects matter for speculation. CSEL on a bounds check is the basis of the Spectre-v1 masking pattern together with CSDB (14.3).

ADR, ADRP and position-independent firmware

  • ADR Xd, label gives PC + simm21, a range of ±1 MiB.
  • ADRP Xd, label gives (PC & ~0xFFF) + simm21 << 12, the 4 KiB page of label within ±4 GiB. Paired with add Xd, Xd, :lo12:label or a load with a :lo12: offset, it reaches any address in that range.

Both are PC-relative, so code built from them runs correctly at any load address with no relocation, as long as the code and data keep their relative offset. TF-A’s ENABLE_PIE build and the “relocate yourself” prologue of many bootloaders depend on this. Absolute addresses still enter through ldr x0, =sym literals and through C data containing pointers. A PIE image fixes those up at runtime from its .rela.dyn entries before turning the MMU on. Branches (B/BL, ±128 MiB) are PC-relative too.

The HINT space and NOP compatibility

HINT #imm (imm = CRm:op2, 7 bits) occupies a region of the system-instruction space that every Armv8.0 implementation executes as NOP when it does not recognise the hint. Arm places new instructions there when they must be safe to run on older cores:

HINT #InstructionFeatureOn a core without the feature
0NOPbase—
1YIELDbaseNOP
2, 3WFE, WFIbase(always implemented; architecturally permitted to complete immediately)
4, 5SEV, SEVLbase—
16ESBFEAT_RASNOP
17PSB CSYNCFEAT_SPENOP
18TSB CSYNCFEAT_TRFNOP
20CSDBbase (v8.0, later defined)NOP
25PACIASPFEAT_PAuthNOP
29AUTIASPFEAT_PAuthNOP
32, 34, 36, 38BTI, BTI c, BTI j, BTI jcFEAT_BTINOP
40CHKFEAT X16FEAT_CHKNOP (X16 unchanged)

This is how a distribution can ship one binary built with -mbranch-protection=standard that runs on a v8.0 core. PACIASP and BTI c cost nothing there and protect on a v8.5+ core. CHKFEAT was designed around the same property: software loads a mask into X16, and a core that does not know the hint leaves X16 untouched, which reads as “not enabled”. The non-hint PAC forms (PACIA Xd, Xn, RETAA, LDRAA) are not in HINT space and are UNDEFINED on cores without FEAT_PAuth. So are WFET/WFIT (FEAT_WFxT), which is why they need a feature check.

SYS, SYSL and SYSP: maintenance and translation operations

Cache, TLB and address-translation operations are not memory instructions. They are system instructions: SYS #op1, Cn, Cm, #op2, Xt with op0 = 1, and the assembler provides aliases:

AliasUnderlying formExample
DCSYS with CRn = 7dc civac, x0 = sys #3, c7, c14, #1, x0
ICSYS with CRn = 7ic ivau, x0 = sys #3, c7, c5, #1, x0
ATSYS with CRn = 7at s1e1r, x0
TLBISYS with CRn = 8 (and 9 for some newer variants)tlbi vae1is, x0

SYSL is the read form (L = 1) and has few architected users. SYSP (FEAT_SYSINSTR128) is the 128-bit pair form behind TLBIP, used when descriptors are 128-bit (FEAT_D128). The encoding is shared with MRS/MSR, as 2.5 explains. That is why the same op1 field decides which EL may execute DC CIVAC (op1 = 3, permitted at EL0 if SCTLR_EL1.UCI = 1) versus DC CISW (op1 = 0, EL1 and above). The semantics of the operations are in 8.5, 9.1 and 5.9.

Optional instruction groups

  • Cryptographic extension: FEAT_AES and FEAT_PMULL, FEAT_SHA1, FEAT_SHA256, FEAT_SHA512, FEAT_SHA3, FEAT_SM3 and FEAT_SM4 (Advanced SIMD instructions). Always optional, because some configurations are excluded for export-control reasons. Check ID_AA64ISAR0_EL1 per field. A “v9 core” may lack them.
  • FEAT_RNG (permitted from v8.5): RNDR and RNDRRS are system registers read with MRS, not new opcodes. A read returns 64 random bits with NZCV = 0000, or returns 0 with NZCV = 0100 (Z set) if no entropy is available in a reasonable time. RNDRRS reseeds first. Code must loop on the flags. With FEAT_RNG_TRAP, SCR_EL3.TRNDR lets EL3 trap them and emulate them, for example from a platform TRNG.
  • FEAT_CSSC (mandatory from v8.9): scalar ABS, CNT, CTZ (register forms) and SMAX/SMIN/UMAX/UMIN (register and immediate forms). They are pure data processing and need no enable.
1:  mrs     x0, rndr
    b.eq    1b              // Z set: no entropy yet, retry (bound this in real code)

FEAT_MOPS: architected memcpy and memset

FEAT_MOPS (an Armv8.8/v9.3 feature; see DDI0487 A2 for its mandatory status) adds CPYP/CPYM/CPYE (memmove semantics; CPYF* is the forward-only memcpy variant) and SETP/SETM/SETE (memset; SETG* also sets MTE tags). Each operation is three instructions that must appear consecutively, with the same registers:

    // memmove(x0 = dst, x1 = src, x2 = n)
    cpyp    [x0]!, [x1]!, x2!     // prologue: validate, choose direction, may copy a little
    cpym    [x0]!, [x1]!, x2!     // main: bulk of the copy, interruptible
    cpye    [x0]!, [x1]!, x2!     // epilogue: the tail

All three update the destination, source and size registers as they make progress, so the operation can be interrupted and resumed after any instruction. The architecture permits two algorithms, and which one a core uses is IMPLEMENTATION DEFINED. The prologue records the choice in PSTATE.C:

Option A (C = 0)Option B (C = 1)
Forward copy, after CPYPXd, Xs point past the end. Xn holds minus the bytes remaining. NZCV = 0000Xd, Xs point at the next byte to copy. Xn holds the bytes remaining. NZCV = 0010
Backward copy, after CPYPXd, Xs unchanged. Xn = bytes remaining. NZCV = 0000Xd, Xs point one past the highest byte still to copy. NZCV = 1010 (N = 1)

Software never interprets these values. It only has to run the three instructions in order. The design has two architectural consequences.

The Memory Copy/Set exception (EC 0x27). If CPYM or CPYE finds register or PSTATE state that its own implementation would not have produced, it takes an exception instead of guessing. This happens most commonly because a thread was migrated between cores with different options (big and little cores in a cluster can differ) between CPYP and CPYM. Executing a main or epilogue instruction out of sequence has the same effect. The ESR ISS tells the handler which of the CPY/SET instructions faulted, whether it was the epilogue, the registers involved, and whether the cause was the option. The handler rewinds the registers into the form the current core expects and restarts from the prologue. Linux does this in arm64_mops_reset_regs(). Any EL that can migrate a context must handle EC 0x27, and that includes a hypervisor moving vCPUs.

Enables. MOPS at EL0/EL1 is UNDEFINED unless enabled:

  • SCTLR_EL1.MSCEn (bit [33]) enables the instructions at EL0. Its effective value is 1 when HCR_EL2.{E2H,TGE} = {1,1}, in which case SCTLR_EL2.MSCEn governs EL0.
  • HCRX_EL2.MSCEn (bit [11]) enables them at EL1 and EL0 when EL2 is enabled. HCRX_EL2.MCE2 (bit [10]) routes EL1’s Memory Copy/Set exceptions to EL2.
  • HCRX_EL2 only has an effect if EL3 sets SCR_EL3.HXEn. With EL2 enabled and HXEn = 0, the effective value of HCRX_EL2.MSCEn is 0, and MOPS is UNDEFINED at EL1 and EL0.

That chain (EL3 enables HCRX, EL2 enables MOPS, EL1 enables EL0) is the pattern in 2.6. Linux’s boot requirements state it explicitly.

Bring-up note: reading an objdump of BL31 entry code

Bring-up note: The listing below was assembled with GNU as and disassembled with aarch64-linux-gnu-objdump -d (binutils 2.44). It is a condensed paraphrase of TF-A’s bl31_entrypoint and el3_entrypoint_common, not a verbatim build. In a real tree, run aarch64-none-elf-objdump -d build/<plat>/<mode>/bl31/bl31.elf | less and search for bl31_entrypoint.

0000000000000000 <bl31_entrypoint>:
   0:  d503245f   bti     c                       // HINT #34: NOP on pre-v8.5 cores
   4:  aa0003f4   mov     x20, x0                 // save BL2's arguments in callee-saved regs
   8:  aa0103f5   mov     x21, x1
   c:  d2810600   mov     x0, #0x830              // mov_imm: MOVZ + MOVK build
  10:  f2a618a0   movk    x0, #0x30c5, lsl #16    //   0x30c50830 = SCTLR_EL3 RES1 bits
  14:  d51e1000   msr     sctlr_el3, x0           // MMU, caches, alignment checks off
  18:  d5033fdf   isb                             // make the SCTLR write take effect
  1c:  10003f20   adr     x0, 800 <runtime_exceptions>
  20:  d51ec000   msr     vbar_el3, x0            // vectors: 2 KiB-aligned, PC-relative
  24:  d5033fdf   isb
  28:  940001f7   bl      804 <reset_handler>     // per-CPU errata and IMP DEF setup
  2c:  d53e1000   mrs     x0, sctlr_el3
  30:  d2820141   mov     x1, #0x100a             // I | SA | A
  34:  aa010000   orr     x0, x0, x1
  38:  d51e1000   msr     sctlr_el3, x0
  3c:  d5033fdf   isb
  40:  d50344ff   msr     daifclr, #0x4           // unmask SError (A) at EL3
  44:  d538f180   mrs     x0, s3_0_c15_c1_4       // IMP DEF register: objdump has no name
  48:  d5380401   mrs     x1, id_aa64pfr0_el1
  4c:  d3482c21   ubfx    x1, x1, #8, #4          // EL2 field
  50:  90000000   adrp    x0, 0 <...>             // + relocation: page of __BSS_START__
  54:  91000000   add     x0, x0, #0x0            //   :lo12: part
  58:  58003d82   ldr     x2, 808 <...>           // literal-pool load (ldr x2, =const)
  5c:  d503233f   paciasp
  60:  d503251f   chkfeat x16                     // HINT #40
  64:  d503403f   msr     ssbs, #0x0              // PSTATE immediate form (op0 = 0), see 2.4
  68:  d50b7520   ic      ivau, x0                // SYS #3, C7, C5, #1 shown by its alias

How to read it:

  • Encodings tell you the group. d5xxxxxx words are system instructions: MSR/MRS, hints, barriers, SYS. d503201f is NOP, and anything d503 2xxx with Rt = 31 is a HINT. d5033fdf is ISB.
  • Unnamed system registers print as s3_<op1>_c<n>_c<m>_<op2>. op0 = 3 with CRn = 15 (or 11) is the IMPLEMENTATION DEFINED space. Look the register up in the core TRM. This one is CPUECTLR_EL1 on many Cortex cores (1.3). An older binutils prints even architected v9 registers this way, so decode them with 2.5 before assuming they are IMP DEF.
  • Hints print as their newest name. An older objdump shows hint #0x22 where this one shows bti c, and hint #0x28 where this one shows chkfeat x16. Both are the same instruction.
  • adrp + add :lo12: in a .o shows zero offsets plus a relocation. Use objdump -dr to see the symbol, or disassemble the linked ELF.
  • ISB after each MSR SCTLR_EL3/VBAR_EL3 is the context-synchronization requirement, explained in 7.8.

Checkpoint

Q2.3.1 A Linux distribution builds its kernel with -mbranch-protection=pac-ret+bti. On a v8.2 core without FEAT_PAuth or FEAT_BTI, which instruction in the generated code would take an Undefined Instruction exception if it appeared?

  • A. paciasp at a function entry
  • B. bti c at a function entry
  • C. retaa at a function return
  • D. autiasp before ret
Answer

C. PACIASP, AUTIASP and BTI are all allocated in the HINT space, so cores that lack the feature execute them as NOP. RETAA is a combined authenticate-and-return instruction encoded outside HINT space. It is UNDEFINED without FEAT_PAuth, which is why compilers emit it only when targeting v8.3+ explicitly. The most tempting wrong answer, A, assumes every PAC instruction is new opcode space.

Read more: Arm ARM (DDI0487), “Hint instructions” in the A64 system instruction class; RETAA, RETAB

Q2.3.2 A user-space memmove using CPYP/CPYM/CPYE is preempted between CPYP and CPYM and resumed on a different core. The new core takes an exception with EC 0x27 on CPYM. What does this most likely mean, and what should the kernel do?

  • A. The destination buffer is unmapped. Deliver SIGSEGV
  • B. The two cores implement different MOPS options. Rewrite the registers into a form the current core accepts and restart from CPYP
  • C. SCTLR_EL1.MSCEn is 0 on the new core. Set it and retry CPYM
  • D. The PE detected a torn copy. Fall back to a software memmove at the faulting PC
Answer

B. EC 0x27 is the Memory Copy and Memory Set exception. It is raised when the main or epilogue instruction sees register or PSTATE.C state inconsistent with its own algorithm, which is typical after migration between option-A and option-B implementations. The ISS gives enough information to reconstruct the registers so execution can restart at the prologue (Linux: arm64_mops_reset_regs). An unmapped buffer gives a Data Abort (EC 0x24/0x25), and a disabled MSCEn gives an Undefined Instruction exception (EC 0x00), not EC 0x27.

Read more: Arm ARM (DDI0487), “Memory Copy and Memory Set exceptions”; CPYP, CPYM, CPYE; Linux Documentation/arch/arm64/mops.rst

Q2.3.3 A hypervisor sets HCRX_EL2.MSCEn = 1 and a guest kernel sets SCTLR_EL1.MSCEn = 1, but MOPS instructions in the guest’s user space are still UNDEFINED. ID_AA64ISAR2_EL1 reports FEAT_MOPS. What is the most likely cause?

  • A. HCRX_EL2.MCE2 must also be set
  • B. MOPS must also be enabled in CPACR_EL1, like FP
  • C. The guest needs an ISB after SCTLR_EL1 only on a core that uses option B
  • D. EL3 left SCR_EL3.HXEn = 0, so HCRX_EL2 has no effect and MSCEn is effectively 0
Answer

D. With EL2 enabled and SCR_EL3.HXEn = 0, HCRX_EL2.MSCEn has an effective value of 0, which makes MOPS UNDEFINED at EL1 and EL0 whatever the stored value. With HXEn = 0, the hypervisor’s MSR HCRX_EL2 itself traps to EL3 (EC 0x18). If EL3 treats that trap as write-ignored instead of reporting it, the hypervisor believes the write succeeded, which matches the symptom. MCE2 only routes EC 0x27 exceptions, and CPACR_EL1 has no MOPS control.

Read more: Arm ARM (DDI0487), HCRX_EL2.MSCEn and SCR_EL3.HXEn; Linux Documentation/arch/arm64/booting.rst

2.4 PSTATE

PSTATE (“process state”) is not a register. In AArch64 there is no CPSR that you can read or write as a whole. PSTATE is an architectural collection of independent fields. Some have their own access instructions, some can be reached only through SPSR_ELx, and two (SM, ZA) are not saved in SPSR at all. On exception entry, the PE copies the AArch64 PSTATE fields into SPSR_ELx of the target EL, and ERET restores them from it. The exact entry-time changes to each field are listed in 3.2.

The fields

The bit positions are the positions in SPSR_ELx for an exception taken from AArch64. PSTATE itself has no bit layout.

FieldSPSR bitsFeatureMeaning
N,Z,C,V[31:28]baseCondition flags
D,A,I,F[9:6]baseMask debug exceptions, SError, IRQ, FIQ, each for exceptions targeting the current EL (what “masked” means when the target is a higher EL is in 3.3)
ELM[3:2]baseCurrent Exception level. Read as CurrentEL
SPM[0]baseStack-pointer select at EL1+ (2.2)
nRWM[4]baseExecution state: 0 = AArch64. Only meaningful in SPSR
SS[21]baseSoftware step state (16.1)
IL[20]baseIllegal Execution state (3.2)
PAN[22]FEAT_PAN (v8.1)Privileged accesses to EL0-accessible memory fault (5.5)
UAO[23]FEAT_UAO (v8.2)LDTR/STTR at EL1/EL2 use the current EL’s permissions, not EL0’s
DIT[24]FEAT_DIT (v8.4)Data-independent timing for the instructions the Arm ARM lists
TCO[25]FEAT_MTE (v8.5)Tag Check Override: suppress MTE tag checks (13.5)
SSBS[12]FEAT_SSBS0 = hardware may not speculatively let a load bypass an earlier store to the same address (14.5)
BTYPE[11:10]FEAT_BTI (v8.5)Type of the last indirect branch, checked at the next instruction (13.1)
ALLINT[13]FEAT_NMI (v8.8)Masks all IRQ and FIQ, including those with Superpriority (4.3)
SM, ZAnot in SPSRFEAT_SME (v9.2)Streaming SVE mode, and ZA storage enabled (15.2)
PM[32]FEAT_EBEPMasks the PMU exception used for exception-based event profiling (16.3)
EXLOCK[34]FEAT_GCS (v9.4)Exception-return state lock: while set, the current EL’s changes to its own exception-return state (ELR, SPSR, GCS pointer) are restricted (13.2)
UINJ[36]FEAT_UINJ (v9.6, 2024 extensions)Undefined-instruction injection: set by a higher EL in SPSR, so that after the return the target takes an Undefined Instruction exception

SPSR bit [35] is PACM (FEAT_PAuth_LR), another SPSR-only bit. The SPSR layout grows upward from bit 32. SPSR_ELx has been a 64-bit register since v8.0, and save/restore code that keeps only the low 32 bits (str w1, [...] of a mrs x1, spsr_el3) silently drops PM, EXLOCK, PACM and UINJ on newer cores.

Access methods

Each field is reached in one or more of four ways:

  1. MSR (immediate), the op0 = 0 “PSTATE field” form msr <field>, #imm. It needs no scratch register and is the canonical way to flip a single bit.
  2. MRS/MSR (register) using a special-purpose register name (NZCV, DAIF, PAN, …). The value is presented at the field’s SPSR bit position.
  3. Via SVCR, for the SME bits only.
  4. SPSR only: no direct access, so the field can be changed only by an exception return.
FieldMSR immediateMRS/MSR registerLowest EL with direct accessNotes
NZCV—NZCVEL0Also written by flag-setting instructions
D,A,I,FDAIFSet, DAIFClrDAIFEL1 (EL0 if SCTLR_EL1.UMA = 1)
EL—CurrentEL (read-only)EL1UNDEFINED at EL0
SPSPSelSPSelEL1
PANPANPANEL1
UAOUAOUAOEL1
DITDITDITEL0
SSBSSSBSSSBSEL0Direct access needs FEAT_SSBS2. With FEAT_SSBS only, the field is SPSR-only plus the SCTLR_ELx.DSSBS entry default
TCOTCOTCOEL0
ALLINTALLINTALLINTEL1HCRX_EL2.TALLINT traps EL1’s MSR ALLINT, #1 to EL2
PMPMPMEL1
SM, ZASVCRSM, SVCRZA, SVCRSMZA (= SMSTART/SMSTOP)SVCREL0Subject to the SME enables in CPACR_EL1/CPTR_ELx/SMCR_ELx
nRW, SS, IL, BTYPE, EXLOCK, UINJ, PACM———SPSR only. BTYPE is also set implicitly by BR/BLR
    msr     pan, #1              // immediate form: no register needed
    mrs     x0, daif             // read all four masks (bits [9:6])
    msr     daifset, #0b0011     // set I and F (bit order D A I F = 8 4 2 1)
    mrs     x1, currentel
    lsr     x1, x1, #2           // x1 = EL number
    smstart sm                   // = msr svcrsm, #1

Visibility of a write. The Arm ARM guarantees that the side effects of a PSTATE write by MSR are visible to later instructions in program order and invisible to earlier ones, with no ISB needed. This is unlike most system-register writes (2.5). The guarantee covers the PE’s own interpretation, such as PAN checks on the next load. It does not make a newly unmasked pending interrupt arrive at a particular instruction boundary. That is the interrupt-taking model in 3.3, and the GIC’s PMR is a separate register with its own synchronization rules.

Fields that need particular care

SM and ZA are not saved on exception entry. They live in SVCR, are not copied into SPSR, and exception entry does not change them. A handler at a higher EL that may be entered in Streaming mode therefore runs with PSTATE.SM = 1. It must either avoid FP/SIMD entirely, rely on the SME traps to catch it, or execute SMSTOP and restore the state later. This is why EL3 context management must save and restore SVCR explicitly across worlds (15.3).

SPSR-only fields are policy in the hands of the higher EL. BTYPE and IL carry in-flight state across an exception: the interrupted code’s pending BTI check, or its illegal-state flag. An EL that fabricates an SPSR (for a first entry into a lower EL, or a signal frame) must set them deliberately, normally to 0. UINJ turns this into an explicit tool: rather than synthesising an Undefined Instruction exception into the lower EL by hand (writing the lower EL’s ESR, ELR and SPSR and redirecting to its vector), firmware sets SPSR_EL3.UINJ and returns.

SSBS has two kinds of default. SCTLR_ELx.DSSBS sets the value PSTATE.SSBS takes on exception entry to ELx. EL0 can change its own value only with FEAT_SSBS2. A kernel that wants the speculative-store-bypass mitigation everywhere sets DSSBS = 0 and sanitises SPSR.SSBS on return.

Security note: PAN, UAO, TCO and DIT have security meaning, and all four are saved and restored through SPSR on every exception. An EL1 kernel that runs with PAN = 1 relies on its own exception entry, controlled by SCTLR_EL1.SPAN, and on every ERET restoring the intended value. A higher EL that builds a return SPSR for EL1 by hand (a hypervisor injecting an exception, or EL3 resuming a world) must preserve these bits from the saved context rather than zeroing them. A zeroed PAN or DIT is a silent hardening loss that no test catches by crashing.

Bring-up note: When decoding an SPSR from a crash dump, decode at least bits [36:0]. A value like 0x4_0000_03c5 on a GCS-enabled system is “EL1h, all of DAIF masked, EXLOCK set”. That is not an exotic corruption, only a field older tools don’t print.

Checkpoint

Q2.4.1 A hypervisor runs at EL2 with Streaming SVE mode active (PSTATE.SM = 1) and takes an SMC to EL3. EL3’s handler is built with -mgeneral-regs-only. Which statement is correct?

  • A. The handler runs with PSTATE.SM = 1, because SM is not saved in SPSR_EL3 or changed on exception entry. Whether that matters depends on EL3’s SME traps and whether the handler touches FP/SIMD state
  • B. Exception entry clears SM, and SPSR_EL3 records the old value so ERET restores it
  • C. The SMC is UNDEFINED while PSTATE.SM = 1
  • D. Exception entry clears both SM and ZA, so ZA contents are lost
Answer

A. SM and ZA are held in SVCR. They are neither copied to SPSR nor modified by exception entry. A general-regs-only handler is unaffected in practice, but any EL3 code that does use FP/SIMD, or a world switch, must handle SVCR explicitly. B is the natural assumption from how every other PSTATE bit behaves.

Read more: Arm ARM (DDI0487), SVCR, and “Process state, PSTATE” in the AArch64 exception model; SME supplement chapters

Q2.4.2 Which pair of PSTATE fields can be changed only by an exception return, with no MSR or MRS form?

  • A. PAN and UAO
  • B. SSBS and TCO
  • C. BTYPE and IL
  • D. ALLINT and PM
Answer

C. BTYPE is written implicitly by indirect branches, and IL by illegal returns. Neither has a direct access instruction, so software can set them only through SPSR on ERET. All the others have MSR immediate and MRS/MSR register forms, although SSBS gets them only with FEAT_SSBS2, which makes B tempting on an SSBS-only core.

Read more: Arm ARM (DDI0487), “Process state, PSTATE” and SPSR_EL1

Q2.4.3 An EL1 kernel executes msr pan, #1 and on the very next instruction performs an ldr from a user page. Which statement is correct?

  • A. An ISB is required between them, or the load may still be checked with PAN = 0
  • B. No ISB is needed: a PSTATE write by MSR is architecturally visible to all later instructions
  • C. A DSB ISH is required to make the PAN change visible to the MMU
  • D. The write only takes effect at the next exception return
Answer

B. Writes to PSTATE fields are guaranteed to affect later instructions and not earlier ones, without a context synchronization event. This differs from writes to a system register such as SCTLR_EL1, which generally do need an ISB (7.8). Option A applies that system-register rule to PSTATE.

Read more: Arm ARM (DDI0487), “Process state, PSTATE” (writes to PSTATE fields); PAN

2.5 System registers

AArch64 has no coprocessor interface and no memory-mapped core control block. All PE control and identification state is reached through one encoding space, addressed by five fields. The same space is used by MRS/MSR (registers), MSR-immediate (PSTATE fields), and SYS (operations such as DC, TLBI, AT).

The encoding: op0, op1, CRn, CRm, op2

MRS Xt, <reg> and MSR <reg>, Xt encode the register as follows:

 31            22  21  20 19  18  16  15  12  11   8  7   5  4    0
 1 1 0 1 0 1 0 1 0 0 | L | op0 |  op1  |  CRn  |  CRm  |  op2 |  Rt
                       L=1: MRS (read)  L=0: MSR (write)

The generic name S<op0>_<op1>_C<CRn>_C<CRm>_<op2> is accepted by GNU as and LLVM for any encoding, which is how you write a register your toolchain does not yet know. The disassembler prints the same form for registers it cannot name (see the objdump in 2.3).

RegisterGeneric nameWord
SCTLR_EL1S3_0_C1_C0_0d5381000 (mrs x0, …)
SCTLR_EL2S3_4_C1_C0_0d53c1000
SCTLR_EL12S3_5_C1_C0_0d53d1000
SCTLR_EL3S3_6_C1_C0_0d53e1000
ID_AA64PFR0_EL1S3_0_C0_C4_0d5380400
MDSCR_EL1S2_0_C0_C2_2d5300240

How op0 partitions the space

op0Contents
0Not registers: hints, barriers (DMB/DSB/ISB/SB), CLREX, and the PSTATE-field MSR-immediate forms (2.4)
1System instructions: SYS/SYSL (DC, IC, AT, TLBI, prediction-restriction CFP/CPP/DVP, …)
2Debug and legacy trace registers (MDSCR_EL1, DBGBCR<n>_EL1, OSLAR_EL1, …)
3Everything else. CRn = 11 and CRn = 15 are reserved for IMPLEMENTATION DEFINED registers

op1 hints at the owning EL

By convention, op1 indicates the lowest EL that normally owns the register. This is a naming convention, not an access rule: the authoritative access conditions are each register’s accessibility pseudocode.

op1Typical ownerExamples
0EL1SCTLR_EL1, TCR_EL1, VBAR_EL1, ID registers
1, 2EL1 (cache identification)CCSIDR_EL1, CLIDR_EL1 (1), CSSELR_EL1 (2)
3EL0CTR_EL0, TPIDR_EL0, CNTVCT_EL0, DCZID_EL0
4EL2HCR_EL2, SCTLR_EL2, VTTBR_EL2
5EL2 aliases of EL1/EL0 registersSCTLR_EL12, CNTP_CTL_EL02
6EL3SCR_EL3, SCTLR_EL3, MDCR_EL3

The ID space is forward-compatible. Encodings S3_0_C0_C<m>_<op2> with CRm = 1 to 7 are the ID-register block. Unallocated encodings in it are RAZ, not UNDEFINED. Software can therefore probe a newer ID register, for example ID_AA64ISAR3_EL1, on an older core and read 0, meaning “nothing implemented”. FEAT_IDST makes EL0 accesses to this space trap as EC 0x18 instead of being UNDEFINED (1.1).

Access rules and what failure looks like

Every register access is checked in a fixed order, which the System Register XML expresses as accessibility pseudocode. The result is one of four outcomes: the access proceeds, it is UNDEFINED (Undefined Instruction exception, EC 0x00), it traps to a higher EL (usually EC 0x18), or, under FEAT_NV2, it is converted into a memory access. As an example, the pseudocode for MRS Xt, SCTLR_EL12 in the Arm XML reads, in outline:

if PSTATE.EL == EL0 then UNDEFINED
elsif PSTATE.EL == EL1 then
    if EffectiveHCR_EL2_NVx() == '101' then X[t] = NVMem(0x110)  // NV2: memory access
    elsif EffectiveHCR_EL2_NVx() IN {'xx1'} then trap to EL2, EC 0x18
    else UNDEFINED
elsif PSTATE.EL == EL2 then
    if ELIsInHost(EL2) then X[t] = SCTLR_EL1 else UNDEFINED
elsif PSTATE.EL == EL3 then
    if ELIsInHost(EL2) then X[t] = SCTLR_EL1 else UNDEFINED

A trap with EC 0x18 carries the encoding in its ISS, so the handler can decode exactly which register was accessed:

ISS bits[21:20][19:17][16:14][13:10][9:5][4:1][0]
FieldOp0Op2Op1CRnRtCRmDirection (1 = read)

The fields are not in instruction order. Decoders that extract them in op0/op1/CRn/CRm/op2 order produce plausible but wrong register names. The full decode card is in Appendix D.

The _EL12 and _EL02 aliases (FEAT_VHE)

With FEAT_VHE (mandatory from v8.1) and HCR_EL2.E2H = 1, EL2 is a “host” EL that runs an unmodified OS kernel. That needs two mechanisms:

  1. Redirection. At EL2 with E2H = 1, the EL1 encodings of registers that have EL2 counterparts access the EL2 register. mrs x0, sctlr_el1 reads SCTLR_EL2, and msr ttbr1_el1, x0 writes TTBR1_EL2. The kernel’s EL1 code therefore runs at EL2 unchanged.
  2. Aliases to reach the real EL1/EL0 registers. Because the plain EL1 names are redirected, the host uses _EL12 names (SCTLR_EL12, TCR_EL12, VBAR_EL12, CNTKCTL_EL12, …) to access a guest’s EL1 state, and _EL02 names (CNTP_CTL_EL02, CNTV_CVAL_EL02, …) for its EL0 timer registers. All of them sit at op1 = 5.

As the pseudocode shows, _EL12 is UNDEFINED at EL2 and EL3 unless EL2 is in host mode, and at EL1 it exists only to be trapped or transformed by nested virtualization (11.2). EL3 firmware saving a Non-secure EL1 context must therefore use the plain _EL1 names (at EL3 there is no redirection) and must not use _EL12 unless it has checked E2H.

SYS: operations in the same space

SYS #op1, Cn, Cm, #op2{, Xt} is the op0 = 1 member of the same format, with L = 0. DC, IC, AT and TLBI are aliases, and their op1 follows the same EL convention: DC CVAC (EL0-capable) is op1 = 3, and TLBI ALLE2 is op1 = 4. Traps on them are also reported with EC 0x18, and HCR_EL2.TPCP/TPU/TTLB and the fine-grained trap registers apply (11.1).

128-bit system registers: MRRS and MSRR (FEAT_SYSREG128)

FEAT_D128 (an Armv9.4 extension) introduces 128-bit translation table descriptors, and with them some system registers become 128 bits wide: TTBR0_EL1, TTBR1_EL1, TTBR0_EL2, TTBR1_EL2, VTTBR_EL2, PAR_EL1, and the RCWMASK_EL1/RCWSMASK_EL1 masks. FEAT_SYSREG128 provides the access instructions:

    mrrs    x0, x1, ttbr0_el1     // x0 = bits[63:0], x1 = bits[127:64]
    msrr    ttbr0_el1, x2, x3     // write all 128 bits in one access
  • The pair must start at an even register (Xt, Xt+1). GNU as rejects mrrs x1, x2, ....
  • The encoding is the MRS/MSR format with bit [22] set (mrrs x0, x1, ttbr0_el1 = d5782000). There is also SYSP (FEAT_SYSINSTR128) for 128-bit system instructions such as TLBIP.
  • Plain MRS/MSR still work on these registers but transfer only bits [63:0]. Check the register’s description for what a 64-bit write does to the upper half before mixing the two forms.
  • Traps: SCR_EL3.D128En = 0 makes MRRS/MSRR at EL1 and EL2 trap to EL3, and HCRX_EL2.D128En = 0 traps them at EL1 to EL2. Both are reported with EC 0x14, not 0x18.

Bring-up note: A kernel or hypervisor built for D128 that dies on its very first msrr ttbr0_el1 with an exception to EL3 (EC 0x14) is not hitting a broken MMU. EL3 has not set SCR_EL3.D128En. This is the “new features arrive trapped” pattern in 2.6 and 17.3. Note also that HCRX_EL2.D128En behaves as 0 when EL2 is enabled and SCR_EL3.HXEn = 0.

When does a write take effect? (pointer)

A direct write to a system register is not, in general, guaranteed to affect subsequent instructions until a context synchronization event (such as ISB, exception entry, or ERET) occurs. Direct reads of the same register by the same PE observe the write in program order, and writes that affect translation or cache maintenance carry additional TLB or barrier requirements. The exact rules (which effects need an ISB, which need a DSB first, and the exceptions that FEAT_ExS makes possible on entry and return) are the subject of 7.8. The working rule for firmware is: MSR to control state, then ISB, before relying on the change. The objdump of BL31’s entry code in 2.3 does exactly that.

Checkpoint

Q2.5.1 EL3 firmware saves a Non-secure context. The Normal-world hypervisor runs with HCR_EL2.E2H = 1. EL3 reads SCTLR_EL1 using the plain encoding S3_0_C1_C0_0. What does it get?

  • A. SCTLR_EL2, because E2H redirection applies to every EL above EL1
  • B. An Undefined Instruction exception, because with E2H = 1 only SCTLR_EL12 is valid
  • C. A trap to EL2, because the access targets a VHE-managed register
  • D. SCTLR_EL1, because redirection applies only to accesses executed at EL2
Answer

D. Redirection of EL1 encodings to EL2 registers is a property of execution at EL2 in host mode. At EL3 the plain encoding names the EL1 register. SCTLR_EL12 would also be valid at EL3 when EL2 is in host mode, but it is not required. Option A generalises redirection to EL3, which is the usual mistake. A trap from EL3 to EL2 is impossible, so C is wrong.

Read more: Arm ARM (DDI0487), SCTLR_EL1 accessibility pseudocode; “Virtualization Host Extensions”

Q2.5.2 A hypervisor’s trap handler receives EC 0x18 with ISS = 0x340420. Which access trapped?

  • A. MSR CPACR_EL1, X1
  • B. MRS X1, CPACR_EL1
  • C. MSR SCTLR_EL1, X1
  • D. MSR S3_0_C1_C2_0, X1
Answer

A. Decode with the ISS layout, which is not instruction order: Op0[21:20] = 3, Op2[19:17] = 2, Op1[16:14] = 0, CRn[13:10] = 1, Rt[9:5] = 1, CRm[4:1] = 0, Direction[0] = 0 (write). That is S3_0_C1_C0_2, which is CPACR_EL1, written from X1. B inverts the direction bit (1 means read). C drops Op2, which sits between Op0 and Op1 in the ISS and is easy to miss. D is what you get if you take the fields in instruction order from the wrong bit positions.

Read more: Arm ARM (DDI0487), ESR_EL2, ISS encoding for an exception from MSR, MRS, or System instruction execution in AArch64 state; CPACR_EL1

Q2.5.3 Boot code on a pre-v8.4 core wants to detect FEAT_SEL2 by reading ID_AA64PFR0_EL1, and also probes ID_AA64MMFR4_EL1, a register newer than the core. What happens on the probe?

  • A. Undefined Instruction exception, so the probe must be guarded by a version check
  • B. A trap to EL3 with EC 0x18
  • C. The read returns 0, because unallocated encodings in the ID-register block are RAZ
  • D. The value is UNKNOWN, so the result must be masked with the fields known on that core
Answer

C. Unallocated encodings in S3_0_C0_C<1-7>_<op2> are reserved as RAZ precisely so that software can probe future ID registers on older cores and read “not implemented”. A is what happens for unallocated encodings outside the ID block. FEAT_IDST changes this only for EL0 accesses.

Read more: Arm ARM (DDI0487), “Reserved encodings in the ID register space” / System register encoding space for ID registers; FEAT_IDST

2.6 The trap-control map

Every EL above EL0 owns a small set of registers that decide what the ELs below it may do. The rules are spread across hundreds of fields. This section is the orientation map: which register to open when something at a lower EL is UNDEFINED or traps unexpectedly. Field-by-field programming for bring-up is in 17.3. Fine-grained traps (HFGRTR_EL2 and the related registers) are in 11.1.

The map

AreaEL3 controls (affect EL2, EL1, EL0)EL2 controls (affect EL1, EL0)EL1 controls (affect EL0)
World, routing, execution stateSCR_EL3: NS/NSE, RW, EEL2, IRQ/FIQ/EA routingHCR_EL2: RW, TGE, E2H, IMO/FMO/AMO, VM—
Calls and waitsSCR_EL3: SMD (SMC disable), HCE (HVC enable), TWI/TWEHCR_EL2: TSC (trap SMC), TWI/TWESCTLR_EL1: nTWI/nTWE
FP / SIMD, SVE, SMECPTR_EL3: TFP, EZ, ESMCPTR_EL2: TFP, TZ, TSM (or FPEN, ZEN, SMEN when E2H = 1)CPACR_EL1: FPEN, ZEN, SMEN
Trapping the trap registersCPTR_EL3.TCPAC (EL2/EL1 accesses to CPTR_EL2/CPACR_EL1)CPTR_EL2.TCPAC (CPACR_EL1)—
Debug, PMU, trace, SPEMDCR_EL3: TDA, TDOSA, TPM, SDD, SPD32, NSPB (SPE owner), NSTB (TRBE owner), TTRF, SCCD/MCCD; CPTR_EL3.TTA, TAMMDCR_EL2: TDE, TDA, TDRA, TDOSA, TPM, TPMCR, HPMN, HPMD, E2PB, TPMS, TTRF; CPTR_EL2.TTA, TAMMDSCR_EL1, PMUSERENR_EL0, CPACR_EL1.TTA
Virtual memory and IDSCR_EL3: TID3, TID5 (FEAT_IDTE3, a recent addition); otherwise ID-register traps are at EL2 or in the FGT registersHCR_EL2: TVM/TRVM, TTLB*, TPCP, TPU, TSW, TACR, TIDCP, TID0–TID5, TDZSCTLR_EL1: UCI, UCT, DZE, UMA
Security extensionsSCR_EL3: APK/API (PAuth), ATA (MTE tags), GCSEn, PIEn, EnSCXTHCR_EL2: APK/API, ATA, EnSCXT; HCRX_EL2.GCSEnSCTLR_EL1: EnIA/EnIB/EnDA/EnDB, ATA0, TSCXT
Extension-register gatesSCR_EL3: HXEn, TCR2En, SCTLR2En, FGTEn, D128En, ECVEnHCRX_EL2: TCR2En, SCTLR2En, D128En—
Newer instructionsSCR_EL3: TRNDR (RNDR), EnTP2 (SME TPIDR2), ADEn/EnAS0 (LS64), AMVOFFENHCRX_EL2: MSCEn/MCE2 (MOPS), EnALS/EnASR/EnAS0 (LS64), TALLINT, EnFPMSCTLR_EL1: MSCEn, EnALS/EnASR/EnAS0, EnTP2

Some cells name fields that exist only with a particular feature, and the list is not exhaustive. Its purpose is to tell you which register’s description to read. The register descriptions in the System Register XML are the authority.

Reading the map: three rules

1. Polarity varies, so read each field. Arm has mixed “trap” and “enable” fields since v8.0, and the newer the field, the more likely it is an enable:

FieldValue that permits the featureKind
CPTR_EL3.TFP0trap
CPTR_EL3.EZ, CPTR_EL3.ESM1enable
SCR_EL3.SMD0disable
SCR_EL3.HCE1enable
SCR_EL3.APK, SCR_EL3.API1“do not trap”
SCR_EL3.TRNDR0trap
CPACR_EL1.FPEN0b11two-bit enable (EL0 and EL1 separately)

Many of these fields reset to UNKNOWN values. Firmware must write every field of SCR_EL3, CPTR_EL3 and MDCR_EL3 deliberately, which is why TF-A builds them from explicit per-feature values instead of read-modify-write.

2. The same register can change shape. CPTR_EL2 has two layouts. With HCR_EL2.E2H = 0 it uses TFP/TZ/TSM trap bits. With E2H = 1 it uses the CPACR_EL1-style FPEN/ZEN/SMEN fields, so that a VHE host kernel can program it like CPACR_EL1. Code that sets CPTR_EL2 before deciding E2H programs the wrong layout.

3. Every trap at every EL applies. A lower-EL access is permitted only if no control at any higher EL traps or disables it. When several apply, the Arm ARM defines a priority, normally favouring the trap to the lowest target EL. The authoritative order is each register’s or instruction’s accessibility pseudocode (2.5). The exception class tells you which family fired:

Symptom (ESR EC)Typical cause
0x00UNDEFINED: feature absent, or an enable such as MSCEn is effectively 0
0x07FP/SIMD trapped (FPEN, TFP)
0x14128-bit MRRS/MSRR trapped (D128En)
0x16 / 0x17HVC / SMC routed, or trapped by HCR_EL2.TSC (0x17)
0x18MSR/MRS/SYS trapped: by SCR_EL3.*En, HCR_EL2.T*, MDCR_ELx.T*, or FGT
0x19SVE trapped (ZEN, TZ, EZ)
0x1DSME trapped (SMEN, TSM, ESM)

Extension registers: HCRX_EL2, TCR2_ELx, SCTLR2_ELx

HCR_EL2, TCR_ELx and SCTLR_ELx ran out of free bits, so Arm added companion registers rather than reusing RES0 fields with new meanings:

  • HCRX_EL2 (FEAT_HCX, mandatory from v8.7; see DDI0487 A2 for the earliest version that permits it) holds the EL2 controls for newer features: MOPS, LS64, NMI (TALLINT, VINMI/VFNMI), the XS attribute (FnXS), CMOW, GCSEn, D128En, TCR2En/SCTLR2En, and others.
  • TCR2_ELx (FEAT_TCR2) extends translation control: PIE (permission indirection), POE/E0POE (permission overlays), D128, AIE, HAFT, and others. See 5.2.
  • SCTLR2_ELx (FEAT_SCTLR2) extends system control with fields such as NMEA, EASE, EnADERR/EnANERR for the newer RAS and abort behaviours, and the PAC-related EnPACM. See 3.3.

Each extension register is itself gated by the EL above it. Until EL3 sets SCR_EL3.HXEn, EL2’s accesses to HCRX_EL2 trap to EL3, and (with EL2 enabled) its fields take effective values that mostly disable the features. Until EL3 sets SCR_EL3.TCR2En and SCR_EL3.SCTLR2En, and EL2 sets HCRX_EL2.TCR2En and HCRX_EL2.SCTLR2En, the lower ELs’ accesses to TCR2_EL1/SCTLR2_EL1 trap. When EL2 is not implemented or not enabled, the HCRX_EL2 gates for TCR2En, SCTLR2En and D128En behave as 1, so a system without a hypervisor needs only the EL3 enables.

The pattern: features arrive disabled or trapped

Almost every feature added since v8.3 that adds architectural state or a new privilege-sensitive operation follows the same rule:

On a system where higher-EL software predates the feature, the feature is invisible or inert to lower ELs. It becomes usable only when each higher EL, in turn, opts in.

That is what keeps a v8.0-era EL3 or hypervisor safe on a newer core. Firmware that does not know about MTE tags, PAuth keys, SME’s ZA or GCS cannot fail to context-switch state it has never enabled. The corresponding bring-up consequence is that every new feature needs work at every EL above the one that uses it. For a Linux kernel at EL1 to use TCR2_EL1.PIE under KVM, EL3 must set SCR_EL3.HXEn, SCR_EL3.TCR2En and SCR_EL3.PIEn, EL2 must set HCRX_EL2.TCR2En (and the FGT or PIEn-related controls must not trap), and only then can EL1 program TCR2_EL1. Where a feature adds state, as SVE, SME, MTE tags, PAuth keys and GCS pointers do, the EL that enables it also takes on the obligation to save and restore that state across every world or VM switch it performs.

Security note: Enabling a feature at EL3 is a security decision, not just plumbing. Setting CPTR_EL3.EZ without saving and restoring ZCR_EL2/Z state on world switches leaks Secure vector state to the Normal world, or the reverse. Setting SCR_EL3.APK without per-world key management lets Normal-world code observe or influence the keys the Secure world uses. TF-A ties each ENABLE_FEAT_* build option to both the enable bit and the matching context-management code for this reason.

Bring-up note: When a newly enabled kernel feature dies at its first use with an exception at EL3 (EC 0x18 or 0x14 in ESR_EL3), decode the ISS to get the register (2.5), then find which SCR_EL3/CPTR_EL3/MDCR_EL3 field gates it. In TF-A, that usually means a missing ENABLE_FEAT_<X>=1 (or =2, which enables the feature at runtime only if the ID register reports it) in the platform makefile. If the exception lands at EL2 instead, apply the same method to HCR_EL2/HCRX_EL2/CPTR_EL2/MDCR_EL2 and the FGT registers.

Checkpoint

Q2.6.1 On a system with no EL2, EL3 firmware sets SCR_EL3.TCR2En = 1 but never sets SCR_EL3.HXEn. Can the EL1 kernel access TCR2_EL1?

  • A. No: HCRX_EL2.TCR2En is also required, and it is inaccessible while HXEn = 0
  • B. Yes: when EL2 is not implemented or not enabled, the HCRX_EL2.TCR2En gate behaves as 1, so only the EL3 enable matters
  • C. No: TCR2_EL1 exists only when FEAT_VHE is in use
  • D. Yes, but only after the kernel also sets SCTLR2_EL1.TCR2En
Answer

B. HCRX_EL2.TCR2En has an effective value of 1 when EL2 is not implemented or not enabled in the current Security state, so the EL2 gate disappears and SCR_EL3.TCR2En alone decides. A is the right answer for a system with an enabled EL2, where HXEn = 0 makes the HCRX gates effectively 0. There is no SCTLR2_EL1.TCR2En field, so D is wrong.

Read more: Arm ARM (DDI0487), HCRX_EL2.TCR2En and SCR_EL3.TCR2En; TCR2_EL1 accessibility

Q2.6.2 A hypervisor running with HCR_EL2.E2H = 1 writes CPTR_EL2 with the value it used when it ran non-VHE (TFP = 0, TZ = 0, everything else 0). Guests now take FP traps to EL2. Why?

  • A. CPTR_EL3.TFP is set, and EL3 traps are reported at EL2
  • B. With E2H = 1, FP traps from EL1 are always taken to EL2
  • C. CPACR_EL1.FPEN must be 0b11 in the guest as well, and it reset to 0
  • D. With E2H = 1, CPTR_EL2 uses the FPEN/ZEN layout, so writing 0 there sets FPEN = 0b00, which traps FP
Answer

D. The CPTR_EL2 layout depends on E2H. In the VHE layout, FPEN is an enable field at bits [21:20], and 0 means “trap”. The non-VHE value of all-zeros therefore enables trapping. A is wrong because EL3 traps are taken to EL3. C could cause FP traps, but those would be taken to EL1, not EL2.

Read more: Arm ARM (DDI0487), CPTR_EL2 (both layouts); “Virtualization Host Extensions”

Q2.6.3 Why does the architecture make new features such as GCS or permission indirection disabled at lower ELs until each higher EL enables them, rather than enabled by default?

  • A. To save power: disabled features are clock-gated
  • B. Because ID registers cannot report a feature until it is enabled
  • C. So that higher-EL software that predates the feature cannot be undermined by lower-EL state or behaviour it does not know to save, restore or virtualise
  • D. Because the reset values of the enable fields are fixed by the Arm ARM as 0 on cold reset
Answer

C. A pre-GCS hypervisor does not context-switch GCSPR_EL1. If guests could enable GCS without it, state would leak or be corrupted between VMs. Opt-in at every level lets new cores run old firmware safely. B is wrong, since ID registers report implemented features independently of enables. D is wrong as a general claim: many enable fields reset to UNKNOWN, which is why firmware must program them explicitly.

Read more: Arm ARM (DDI0487), SCR_EL3, HCRX_EL2; Arm “Learn the architecture: AArch64 exception model”

Part 3: The exception model

Review part: concise and register-precise, for readers who already know this material.

Prerequisites: 2.1 Exception levels, Security states and execution states, 2.4 PSTATE, 2.6 The trap-control map.

If you already know: how a TF-A or OP-TEE vector table is laid out and how SCR_EL3.{IRQ,FIQ} steer interrupts to EL3, skim 3.1 and 3.3. Read the FEAT_ExS and illegal-return parts of 3.2, the FEAT_DoubleFault material at the end of 3.3, and all of 3.4.

Why this matters for bring-up/validation: the first sign of almost every bring-up failure is an exception, and you can only read ESR_ELx, ELR_ELx and FAR_ELx correctly if you know exactly what the architecture promises about them.

This part restates the AArch64 exception model in the vocabulary of the Arm ARM. 3.1 classifies exceptions (synchronous, IRQ, FIQ, SError), defines “precise” and “taken to ELx”, and pins down how the 16-entry vector table at VBAR_ELx is indexed. 3.2 gives the exact architectural state changes on entry and on ERET: ELR_ELx, SPSR_ELx, the ESR_ELx EC/IL/ISS layout, when FAR_ELx is valid, the PSTATE fields the hardware sets on entry, what makes an exception return illegal, and how FEAT_ExS can remove the context synchronization that entry and return normally provide.

3.3 covers the routing controls in SCR_EL3 and HCR_EL2, the asynchronous routing tables, and the cases where PSTATE.{A,I,F} do not mask an exception, including the FEAT_DoubleFault and FEAT_DoubleFault2 controls for errors that arrive while PSTATE.A is set. 3.4 treats SError on its own terms: asynchronous external aborts, error synchronization with ESB and IESB, deferred errors in DISR_EL1/VDISR_EL2, the SError ISS, and when an SError can be attributed to a specific instruction. Crash triage is in 18.3, and the RAS error-record architecture is in 16.7.

3.1 Exception types and the vector table

The four exception classes

Every AArch64 exception has a type, which selects one of four vector offsets inside a vector-table quadrant:

ClassGenerated byExamples
SynchronousExecution or attempted execution of an instruction, or an instruction fetchSVC/HVC/SMC, traps (EC 0x18 and others), instruction and data aborts, PC and SP alignment faults, BRK, breakpoints, watchpoints, software step, Illegal Execution state, synchronous External aborts
IRQA physical or virtual IRQ signalGIC interrupt signalled as IRQ, HCR_EL2.VI
FIQA physical or virtual FIQ signalGIC Group 0 (or “other Security state” Group 1) interrupt signalled as FIQ, HCR_EL2.VF
SErrorA physical or virtual System Errorasynchronous External abort, RAS error reported asynchronously, HCR_EL2.VSE

IRQ, FIQ and SError are asynchronous: they are not generated by the instruction stream, and the architecture only requires them to be taken “in finite time” once pending and unmasked. Synchronous External aborts are reported through the synchronous vector with a Data or Instruction Abort EC. They are not SErrors, even though both come from the memory system. Debug exceptions are synchronous, and PSTATE.D controls whether most of them are taken (see 16.1).

Precise and imprecise

The Arm ARM defines an exception as precise when the PE state presented to the handler is consistent with every instruction before the preferred return address having executed and none at or after it having executed. (For some synchronous exceptions, such as an abort on a multi-register load or store, the architecture permits the faulting instruction to have partially updated registers or memory; DDI0487 lists which.)

  • Synchronous exceptions are precise. The preferred return address is the faulting instruction for aborts and traps. For SVC, HVC and SMC it is the next instruction. A trapped SMC (for example via HCR_EL2.TSC, EC 0x17) is reported with the SMC itself as the preferred return address, because it did not execute.
  • Physical and virtual IRQ and FIQ are taken precisely at an instruction boundary. ELR_ELx is the first instruction that did not execute.
  • An SError can be imprecise. It is taken at some instruction boundary, but the error that caused it may come from a store retired many instructions earlier, or from no instruction at all (a line eviction, a prefetch, a poison detected by a scrubber). Without RAS information the handler cannot say which architectural state was affected. With FEAT_RAS, ESR_ELx.AET classifies how much state is recoverable. 3.4 covers this, including when an SError is attributable.

ESR_ELx.IL has nothing to do with precision. It gives the instruction length (32-bit, or 16-bit T32) and is 1 for exceptions not associated with a specific instruction, such as SError.

“Taken to ELx”

The target Exception level is decided by routing controls (3.3), never by the handler. The rules that never change are these:

  • An exception is never taken to EL0.
  • An exception is never taken to an EL lower than the current EL. An asynchronous exception routed to a lower EL stays pending until the PE drops to an EL where it can be taken.
  • A synchronous exception generated at ELx is taken to ELx or higher. EL0 exceptions go to EL1 by default, or to EL2 when HCR_EL2.TGE == 1 or another EL2 control routes them there.
  • The target EL’s Execution state is fixed. If the target is AArch64, the handler runs in AArch64 using VBAR_ELx of the target EL.

“Taken from the current EL” means the target EL equals the EL that was executing. “Taken from a lower EL” means the target EL is higher than the EL that was executing.

VBAR_ELx and the 16-entry layout

VBAR_EL1, VBAR_EL2 and VBAR_EL3 hold the table base. Bits [10:0] are RES0, so the table is 2 KB aligned. It is divided into four 512-byte quadrants of four 128-byte (32-instruction) entries:

OffsetTaken fromSynchronousIRQFIQSError
0x000Current EL, SP_EL0 (PSTATE.SP == 0)0x0000x0800x1000x180
0x200Current EL, SP_ELx (PSTATE.SP == 1)0x2000x2800x3000x380
0x400Lower EL, AArch640x4000x4800x5000x580
0x600Lower EL, AArch320x6000x6800x7000x780

Two selection rules are easy to misremember.

Current EL, SP0 vs SPx depends on PSTATE.SP at the moment the exception was taken, not on the SP the handler will use. Exception entry always sets PSTATE.SP = 1, so every handler starts on SP_ELx. The SP0 quadrant exists for software that runs its main code on SP_EL0 at an elevated EL. BL31 in TF-A does this: its C runtime runs at EL3 with SPSel == 0, while SP_EL3 points to the per-CPU cpu_context_t. An exception raised by BL31 itself therefore lands in the 0x000 quadrant. TF-A treats those entries as fatal (“unhandled exception at EL3”), which is a useful first fact when you decode an EL3 crash.

Lower EL AArch64 vs AArch32 is determined by the Execution state of the Exception level immediately below the target EL, not by the state of the EL where the exception occurred. Take an exception from AArch32 EL0 to EL2 when EL1 is AArch64 and HCR_EL2.{E2H,TGE} != {1,1}. It uses the 0x400 (AArch64) quadrant of VBAR_EL2, because EL1 is the “next lower” level. The AArch64.TakeException() pseudocode has two refinements: for a target of EL3, the “next lower” level is EL2 if EL2 is enabled in the current Security state and EL1 otherwise; and for an exception from EL0 to EL2 with {E2H,TGE} == {1,1} (VHE host), it is EL0 itself, so an AArch32 EL0 task under a VHE host uses VBAR_EL2 + 0x600. On Armv9-A cores that implement AArch32 only at EL0 (or not at all), the 0x600 quadrant of VBAR_EL3 can never be selected, and that of VBAR_EL2 only in the VHE-host case. See 2.1.

There is no vector for “taken to the same EL from a different Security state”. A Secure EL1 exception routed to EL3 and a Non-secure EL1 exception routed to EL3 both use VBAR_EL3 + 0x400. The handler reads SCR_EL3.NS (and SCR_EL3.NSE with RME) to find out which world it came from.

    .section .vectors, "ax"
    .balign 2048                    // VBAR_ELx[10:0] are RES0
vectors:
    .irp q, cur_sp0, cur_spx, low64, low32
    .irp t, sync, irq, fiq, serror
    .balign 128                     // 32 instructions per entry
    b   \q\()_\t
    .endr
    .endr

    // install
    adr x0, vectors
    msr VBAR_EL3, x0
    isb                              // see 7.8: a VBAR write needs context synchronization

An entry is 32 instructions, which is enough for a short save sequence before branching out. TF-A and Linux use the space in place for Spectre-BHB mitigation sequences at the 0x400/0x600 entries. See 14.4.

Bring-up note: VBAR_EL3 resets to an UNKNOWN value. An exception taken before the first MSR VBAR_EL3 (for example a synchronous External abort from a not-yet-enabled DRAM controller) branches to an UNKNOWN address. That usually shows up as a core that “hangs” with no UART output. Program VBAR_EL3 with a minimal “log ESR_EL3/ELR_EL3 and spin” table as the first few instructions after reset. A table whose base is not 2 KB aligned does not fault: the low bits are RES0 and are ignored, so the entries are silently misindexed, and a recursive exception at VBAR + 0x200 is the classic symptom (18.3).

Security note: with SCR_EL3.FIQ == 1 and a Secure EL1 TEE masking PSTATE.F, a Group 0 FIQ still reaches EL3 at VBAR_EL3 + 0x500 (lower EL, AArch64), because PSTATE masking does not apply to an exception targeting a higher EL (the only exception is the VHE-host EL0 case in 3.3). An EL3 dispatcher that assumes “FIQ means from Non-secure” without checking SCR_EL3.NS has a confused-deputy bug.

Checkpoint

Q3.1.1 EL1 is AArch64 and EL0 runs an AArch32 application. HCR_EL2.TGE == 0. The application executes an instruction trapped to EL2 by an HCR_EL2 control. Which VBAR_EL2 offset is used?

  • A. 0x600, because the instruction that trapped was executing in AArch32
  • B. 0x200, because the exception is taken to EL2 using SP_EL2
  • C. 0x400, because the quadrant is selected by the Execution state of the EL immediately below the target, which is AArch64 EL1
  • D. 0x000, because EL0 uses SP_EL0
Answer

C. For exceptions from a lower EL, the vector quadrant depends on the Execution state of the next lower EL than the target, here EL1, which is AArch64. A is the tempting misreading (“the state where it happened”), and it is only true when EL1 is also AArch32. B and D are current-EL quadrants, and this exception comes from a lower EL.

Read more: Arm ARM (DDI0487), Exception vectors, “Vector offsets from vector table base address”

Q3.1.2 BL31 runs its C code at EL3 with SPSel == 0. A NULL-pointer dereference in that C code causes a Data Abort. Where does the PE branch, and which stack pointer is in use at the first instruction of the handler?

  • A. VBAR_EL3 + 0x000, running on SP_EL3
  • B. VBAR_EL3 + 0x200, running on SP_EL3
  • C. VBAR_EL3 + 0x000, running on SP_EL0
  • D. VBAR_EL3 + 0x400, running on SP_EL3
Answer

A. The quadrant reflects PSTATE.SP at the time of the exception (0, so “current EL with SP0”), but exception entry always sets PSTATE.SP to 1, so the handler starts on SP_EL3. C confuses the selector with the handler’s stack. D would apply only if the abort came from a lower EL.

Read more: Arm ARM (DDI0487), Exception entry; SPSel; VBAR_EL3

Q3.1.3 A handler for an SError cannot reconstruct which store caused it, while a handler for an IRQ always sees a clean instruction boundary. Which statement captures the architectural distinction?

  • A. SErrors have ESR_ELx.IL == 1, which marks them imprecise
  • B. IRQs are synchronous to the instruction stream, SErrors are asynchronous
  • C. SErrors are always taken at the instruction after the faulting store
  • D. Both are asynchronous, but an SError may be imprecise: the state at ELR_ELx need not reflect the instruction that caused the error
Answer

D. IRQ, FIQ and SError are all asynchronous. Interrupts are taken precisely at an instruction boundary, but an SError can be imprecise because the error may come from an earlier retired access or from no instruction at all. IL gives the instruction length (A is wrong), and B misclassifies IRQ.

Read more: Arm ARM (DDI0487), Synchronous and asynchronous exceptions; precise and imprecise exceptions; SError exceptions

3.2 Entry and return

What the PE writes on entry to AArch64 ELx

When an exception is taken to an AArch64 target ELx, the PE performs these steps, all as one atomic architectural action:

  1. SPSR_ELx ← PSTATE of the interrupted context (the AArch64 or AArch32 format, depending on where it came from).
  2. ELR_ELx ← preferred return address (3.1). If the exception came from AArch32, bits [63:32] are zero.
  3. ESR_ELx ← syndrome, for synchronous exceptions and SError. IRQ and FIQ report no syndrome, so ESR_ELx holds nothing meaningful for them. It is not guaranteed to be “unchanged” either: the register description makes ESR_ELx UNKNOWN on any exception return from ELx.
  4. FAR_ELx ← faulting virtual address, only for the exception types listed below. Otherwise FAR_ELx becomes UNKNOWN.
  5. PSTATE updated as in the table below, and the PC is set to the vector address.

Exception entry does not save or modify the general-purpose registers, and saving them is the handler’s job. On entry from AArch32, do not rely on the upper 32 bits of the X registers that held AArch32 state. The Arm ARM constrains what they may contain (see the AArch32-to-AArch64 register mapping rules), but software should treat them as not meaningful.

PSTATE on entry

FieldValue after entry to ELxNote
ELtarget EL
nRW0 (AArch64)
SP1 (use SP_ELx)
D, A, I, Fall set to 1regardless of which class was taken
SS0software step state, see 16.1
IL0
BTYPE0FEAT_BTI
PANset to 1 if SCTLR_ELx.SPAN == 0, otherwise unchangedFEAT_PAN. Applies to entry to EL1, and to EL2 when HCR_EL2.{E2H,TGE} == {1,1}
UAO0FEAT_UAO
SSBSSCTLR_ELx.DSSBSFEAT_SSBS
TCO1FEAT_MTE. Tag checks are suppressed until software clears TCO
ALLINTNOT SCTLR_ELx.SPINTMASK (applied whenever FEAT_NMI is implemented, even if SCTLR_ELx.NMI == 0)FEAT_NMI, see 4.3
EXLOCKper GCSCR_ELx.EXLOCKENFEAT_GCS, see 13.2
DIT, NZCV, SM, ZAunchangedSME streaming mode survives exception entry

For the newer fields (PM, UINJ and the like), see 2.4 and the Arm ARM pseudocode for AArch64.TakeException(), which is the authoritative list.

SPSR_ELx (AArch64 format)

BitsFieldBitsField
[3:0]M[3:0]: EL and SP (0b0000 EL0t, 0b0100 EL1t, 0b0101 EL1h, 0b1000 EL2t, 0b1001 EL2h, 0b1100 EL3t, 0b1101 EL3h)[20]IL
[4]M[4]: 0 = AArch64[21]SS
[9:6]D A I F[22]PAN
[11:10]BTYPE[23]UAO
[12]SSBS[24]DIT
[13]ALLINT[25]TCO
[31:28]N Z C V[63:32]newer fields (PM, EXLOCK, …), see DDI0487

ESR_ELx: EC, IL, ISS

 63      56 55          32 31    26 25  24                     0
+----------+--------------+--------+---+------------------------+
|   RES0   |     ISS2     |   EC   |IL |          ISS           |
+----------+--------------+--------+---+------------------------+
  • EC [31:26] is the exception class. It decides how to parse ISS.
  • IL [25] is the instruction length: 1 = 32-bit. It is 0 only for a 16-bit T32 instruction trap. It is also 1 for SError, Instruction Aborts, PC and SP alignment faults, Data Aborts with ISV == 0, Illegal Execution state, debug exceptions other than BRK/BKPT, and EC 0x00.
  • ISS [24:0] is class-specific. For Data Aborts, ISS[24] is ISV (the SAS/SRT/… instruction-syndrome fields are valid). For many trap classes it is CV, which only says that the COND field (for a conditional AArch32 instruction) is valid.
  • ISS2 [55:32] is used by FEAT_LS64 (Xs), FEAT_GCS, FEAT_THE and FEAT_S1POE/S2POE fault reporting, among others.

EC summary

ECMeaningECMeaning
0x00Unknown reason (UNDEFINED instruction)0x1FIMPLEMENTATION DEFINED, to EL3
0x01Trapped WFI/WFE/WFIT/WFET0x20Instruction Abort, lower EL
0x07Trapped SVE/SIMD/FP access (CPACR/CPTR)0x21Instruction Abort, same EL
0x09Trapped PAuth instruction (HCR_EL2.API/SCR_EL3.API)0x22PC alignment fault
0x0DBranch Target exception (BTI)0x24Data Abort, lower EL
0x0EIllegal Execution state0x25Data Abort, same EL
0x15SVC (AArch64)0x26SP alignment fault
0x16HVC (AArch64)0x27Memory Operation exception (FEAT_MOPS)
0x17SMC (AArch64)0x2CTrapped floating-point exception (AArch64)
0x18Trapped MSR/MRS/system instruction0x2DGCS exception
0x19Trapped SVE access0x2FSError
0x1CPAC authentication failure (FEAT_FPAC)0x30/0x31Breakpoint, lower/same EL
0x1DTrapped SME access0x32/0x33Software step, lower/same EL
0x1EGranule Protection Check (FEAT_RME)0x34/0x35Watchpoint, lower/same EL
0x11/0x12/0x13SVC/HVC/SMC from AArch320x3CBRK (AArch64)

The full table, with the ISS layout of each class and the DFSC/IFSC values, is Appendix D. Abort ISS fields (WnR, S1PTW, CM, FnV, ISV/SAS/SRT) are in 5.8.

FAR_ELx validity

FAR_ELx is written only on:

  • Instruction Abort and Data Abort (EC 0x20, 0x21, 0x24, 0x25);
  • PC alignment fault (0x22);
  • Watchpoint (0x34, 0x35), where the recorded address is within the watched range but which byte is recorded is constrained, not exact;
  • Granule Protection Check exceptions on an instruction fetch or data access;
  • SError with FEAT_RASv2, but only when ISS.VFV == 1 (3.4).

For every other exception, FAR_ELx is UNKNOWN. That means it is not even guaranteed to keep its old value. Even for aborts, three rules apply:

  • For a synchronous External abort that is not on a translation table walk, ISS.FnV == 1 means FAR_ELx is UNKNOWN.
  • When the address was tagged (TBI), the top byte of the reported address can be UNKNOWN for some fault types. Treat FAR[63:56] as reliable only where DDI0487 says so for the implemented features (FEAT_MTE changes this).
  • FAR_ELx holds a VA. For a stage-2 fault the IPA is in HPFAR_EL2, and with FEAT_PFAR a PA can be in PFAR_ELx. See 5.8.

ERET and exception return

ERET (and ERETAA/ERETAB with PAuth) at ELx restores PC ← ELR_ELx and PSTATE ← SPSR_ELx, subject to a legality check. It is UNDEFINED at EL0. A return is an illegal exception return if SPSR_ELx asks for any of the following:

  • an EL higher than the current EL;
  • an EL that is not implemented, or an M[3:0] encoding that is reserved (for example 0b0001, EL0 with SP_ELx);
  • EL2 when EL2 is not enabled in the current Security state (for example Secure EL2 with SCR_EL3.EEL2 == 0);
  • EL1 when EL2 is enabled and HCR_EL2.TGE == 1 (EL1 is not in use);
  • AArch32 (M[4] == 1) at a level that SCR_EL3.RW/HCR_EL2.RW define as AArch64, or AArch64 at a level defined as AArch32, or AArch32 where AArch32 is not implemented.

On an illegal return, PSTATE.EL, PSTATE.nRW and PSTATE.SP are unchanged, PSTATE.IL is set to 1, the other PSTATE fields are restored from SPSR, and the PC is restored from ELR_ELx. The return itself does not fault. The next instruction the PE attempts to execute takes an Illegal Execution state exception (EC 0x0E) to the current EL, with ELR pointing at that instruction (unless a higher-priority synchronous exception on that instruction, such as a PC alignment fault or an Instruction Abort, is taken first). This design guarantees that software never runs at an EL or Execution state it could not legally reach. A mis-built SPSR therefore shows up as an EC 0x0E exception at the same EL as the ERET, at the address you were trying to return to.

A return to AArch64 with ELR[1:0] != 0 is not illegal. It produces a PC alignment fault at the target when the first instruction is fetched.

    // EL3 -> Non-secure EL2h, AArch64, DAIF masked
    mov  x0, #(0b1001)              // M = EL2h
    orr  x0, x0, #(0xF << 6)        // D A I F
    msr  SPSR_EL3, x0
    adr  x1, ns_el2_entry
    msr  ELR_EL3, x1
    // SCR_EL3.NS=1, RW=1, HCE=1 already programmed (see 17.2)
    eret

Context synchronization, and FEAT_ExS

By default, exception entry and exception return are context synchronization events. System register writes made before them are visible to instructions after them, without an ISB. That is why “write SCTLR_EL1 at EL2, then ERET” works.

FEAT_ExS (permitted from v8.5) makes this configurable per EL:

ControlBit01
SCTLR_ELx.EIS22Exception entry to ELx is not a context synchronization eventEntry is a context synchronization event
SCTLR_ELx.EOS11ERET from ELx is not a context synchronization eventERET is a context synchronization event

Without FEAT_ExS these bits are RES1. With FEAT_ExS they reset to an architecturally UNKNOWN value, so software must write them to 1 explicitly: firmware that writes the whole register with the v8.0 RES1 pattern (for example TF-A’s SCTLR_EL3 reset value) keeps the synchronizing behaviour, but code that only read-modify-writes SCTLR_ELx from reset does not get it guaranteed. Clearing them is an optimization for hypervisors and kernels with hot entry paths. Clearing them also means that any system register write whose effect the next context depends on, such as TTBR, TCR or SCTLR before an ERET, needs an explicit ISB. The PSTATE values that entry itself writes still apply to the handler. What is lost is the synchronization of earlier context-changing operations, such as system-register writes not yet followed by an ISB. See 7.8 for the full context-synchronization rules, and note that neither entry nor return is a DSB: outstanding memory accesses are not waited for.

Bring-up note: when you see EC 0x0E immediately after a hand-off ERET, decode SPSR_ELx.M against SCR_EL3.{RW,NS,EEL2} and HCR_EL2.{RW,E2H,TGE} before anything else. ELR will equal the entry point you returned to, which makes the bug look like “the next image crashed on its first instruction”.

Checkpoint

Q3.2.1 On a core that implements AArch32 at EL1, EL3 firmware writes SPSR_EL3 = 0x3C5 (EL1h, DAIF set) and ERETs to a Non-secure kernel, but SCR_EL3.RW == 0. What happens?

  • A. The ERET itself takes a synchronous exception to EL3 with EC 0x0E
  • B. The return is illegal: the PE stays at EL3 with PSTATE.IL == 1, the PC becomes ELR_EL3, and the first instruction there takes an EC 0x0E exception to EL3
  • C. The PE enters Non-secure EL1 in AArch32 state, because SCR_EL3.RW overrides SPSR.M[4]
  • D. Behaviour is UNPREDICTABLE
Answer

B. SPSR.M[4] == 0 requests AArch64, which conflicts with SCR_EL3.RW == 0, so this is an illegal exception return. EL, nRW and SP are kept, IL is set, and the PC is loaded from ELR. The Illegal Execution state exception is taken when the next instruction is executed, not by the ERET (A). The architecture defines this behaviour exactly, so it is neither “silently fixed up” (C) nor UNPREDICTABLE (D).

Read more: Arm ARM (DDI0487), Illegal return events from AArch64 state; The Illegal Execution state exception

Q3.2.2 A hypervisor on a core with FEAT_ExS sets SCTLR_EL2.EOS = 0. Before ERET to a guest it writes VTTBR_EL2 and HCR_EL2. Which statement is correct?

  • A. No change is needed, because ERET always synchronizes system-register writes made at the same EL
  • B. A DSB SY before ERET is sufficient
  • C. Only the HCR_EL2 write needs an ISB, because VTTBR_EL2 is only used by the walker
  • D. An ISB is required before ERET, because with EOS == 0 the return is no longer a context synchronization event
Answer

D. EOS == 0 removes the guarantee that the ERET synchronizes earlier context-changing writes, so the guest’s first instructions could run under the old HCR_EL2 or stage-2 base. An ISB restores the guarantee. A DSB waits for memory accesses, not for system-register context (B). The walker is part of the context that must be synchronized too (C).

Read more: Arm ARM (DDI0487), SCTLR_EL2.EOS; Context synchronization event

Q3.2.3 An IRQ handler at EL1 logs ESR_EL1 and FAR_EL1, and both contain plausible values from a page fault handled earlier. What can you conclude?

  • A. Nothing: an IRQ writes no syndrome or address, and both registers are UNKNOWN by then, so stale-looking values carry no information
  • B. The IRQ was raised by the earlier page fault
  • C. The hardware preserved them, which is guaranteed for asynchronous exceptions
  • D. ESR_EL1.IL == 0 would distinguish the two cases
Answer

A. The syndrome registers are written only for exception types that report a syndrome or address. IRQ and FIQ write neither, FAR_EL1 is UNKNOWN for any exception other than the listed abort, alignment and watchpoint types, and both registers are made UNKNOWN by every exception return from EL1, including the one that ended the earlier page-fault handler. An implementation may happen to leave the old value, but software must not rely on it (C). Logging them in an IRQ path, or comparing them, is a frequent source of misleading crash reports.

Read more: Arm ARM (DDI0487), ESR_EL1; FAR_EL1; Exception entry

3.3 Routing and masking

Two separate questions

For every asynchronous exception the PE answers two questions, in this order:

  1. Routing: which EL is the target? The answer comes from SCR_EL3 and HCR_EL2, never from PSTATE.
  2. 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.bitRoutesEffect when 1
SCR_EL3.IRQ (bit 1)physical IRQtaken to EL3 from any EL
SCR_EL3.FIQ (bit 2)physical FIQtaken to EL3 from any EL
SCR_EL3.EA (bit 3)physical SError and synchronous External abortstaken to EL3 from any EL
HCR_EL2.IMO (bit 4)physical IRQ from EL0/EL1taken to EL2. Also enables virtual IRQ (HCR_EL2.VI, GIC list registers) at EL1/EL0
HCR_EL2.FMO (bit 3)physical FIQ from EL0/EL1taken to EL2. Also enables virtual FIQ
HCR_EL2.AMO (bit 5)physical SError from EL0/EL1taken to EL2. Also enables virtual SError (HCR_EL2.VSE)
HCR_EL2.TGE (bit 27)everything from EL0IMO/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/EL1taken 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.IRQTGEE2HIMOat EL0at EL1at EL2at EL3
00x0EL1, maskedEL1, maskedpendingpending
00x1EL2EL2EL2, maskedpending
010xEL2n/aEL2, maskedpending
011xEL2, maskedn/aEL2, maskedpending
1xxxEL3EL3EL3EL3, 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.I set cannot block an IRQ routed to EL2 by IMO, and a Secure-EL1 TEE with PSTATE.F set cannot block a Group 0 FIQ routed to EL3 by SCR_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 the ERET to EL1. At EL3 with SCR_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, so PSTATE.I at EL0 masks interrupts that target EL2. With E2H == 0, EL0 cannot mask EL2-routed interrupts.
  • PSTATE at EL0. An EL0 attempt to write DAIF is trapped unless SCTLR_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

  1. The target is a higher EL (the table above).
  2. The exception is synchronous. This includes synchronous External aborts and every trap. PSTATE.D affects only debug exceptions, and only those targeting the current EL (16.1).
  3. The PE is in WFI/WFE. By the WFI wake-up event rules, a pending physical interrupt (or SError) wakes WFI even when PSTATE masks it. The PE then resumes after the WFI without taking the exception. Code that spins “WFI with interrupts masked, then check” depends on this.
  4. FEAT_NMI superpriority. With SCTLR_ELx.NMI == 1, an interrupt with superpriority is not masked by PSTATE.I. It is masked by PSTATE.ALLINT, and also, when SCTLR_ELx.SPINTMASK == 1, while PSTATE.SP == 1. See 4.3.
  5. 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_EL3 and ESR_EL3 unless the handler saved them first.

FEAT_DoubleFault (permitted from v8.4) addresses both:

ControlBitEffect
SCR_EL3.NMEA20Non-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.EASE19External 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:

ControlEffect
SCTLR2_EL1.NMEA (bit 2), SCTLR2_EL2.NMEAPSTATE.A does not mask physical SErrors taken to EL1/EL2
SCTLR2_EL1.EASE (bit 5), SCTLR2_EL2.EASEsynchronous 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 by PSTATE.A. SCR_EL3.TMEA matters 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 while PSTATE.A is set, typically inside its own exception handler) is diverted to EL3 instead of being held pending indefinitely or overwriting the lower EL’s ELR/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_EL3 built with IRQ/FIQ/EA copied from another platform’s TF-A configuration. Dump SCR_EL3 and HCR_EL2 before 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

3.4 SError, architecturally

What an SError is

An SError is the asynchronous member of the exception classes (3.1), and the architecture’s channel for errors that cannot be, or were not, reported synchronously. Physical sources include:

  • Asynchronous External aborts. A memory access completes with an error response from the interconnect or the slave (for example a decode error for a posted write to a hole in the map, or a slave error from a powered-down peripheral) after the instruction that issued it has retired. Writes are the classic case, because a store can retire before its response returns.
  • RAS errors reported asynchronously. These include an uncorrectable ECC error found on a cache eviction or by a scrubber, poison that was deferred rather than consumed, and errors in structures not tied to any instruction. Error nodes are described in 16.7.
  • IMPLEMENTATION DEFINED sources, such as a core-internal parity error.

There are also virtual SErrors, pended by HCR_EL2.VSE with syndrome from VSESR_EL2 (11.4), and, with FEAT_E3DSE, delegated SErrors that EL3 pends for EL2/EL1/EL0 through SCR_EL3.DSE (enabled by SCR_EL3.EnDSE).

Whether a particular bus error is reported synchronously (as an Abort EC) or as an SError is IMPLEMENTATION DEFINED in general. Loads are usually synchronous, posted stores are usually asynchronous, and the system interconnect has a say as well.

Routing is by SCR_EL3.EA and HCR_EL2.AMO, and masking is by PSTATE.A, with the FEAT_DoubleFault/DoubleFault2 refinements covered in 3.3. Remember that SCR_EL3.EA == 0 means that at EL3 SErrors are not taken at all.

Syndrome: the SError ISS (EC 0x2F)

Before FEAT_RAS, the SError ISS was IMPLEMENTATION DEFINED. FEAT_RAS (mandatory from v8.2) defines the architected layout used when IDS == 0:

BitsFieldMeaning
[24]IDS1 = bits [23:0] are IMPLEMENTATION DEFINED. Nothing below is valid
[18]ELSFEAT_RASv2: 1 = a synchronous exception triggered by the instruction at ELR_ELx
[17:16]WUFEAT_RASv2: whether a store that generated the abort updated the location
[15]VFVFEAT_RASv2: FAR_ELx holds a valid VA for the error
[14]PFVFEAT_PFAR: PFAR_ELx is valid
[13]IESBFEAT_IESB: synchronized by an implicit ESB and taken immediately
[12:10]AETAsynchronous Error Type (below)
[9]EAIMPLEMENTATION DEFINED classification of External aborts
[7:6]WnRV, WnRFEAT_RASv2: Write-not-Read information
[5:0]DFSC0b000000 Uncategorized, 0b010001 Asynchronous SError. Other values reserved

AET, EA, IESB and the RASv2/PFAR fields are defined only when DFSC == 0b010001, and are RES0 otherwise. With DFSC == 0b000000, the error is “uncategorized” and the handler knows nothing about its containment.

AETNameState of the PE after the error
0b000UC, Uncontainablethe error may have spread arbitrarily. Isolate or reset the system
0b001UEU, Unrecoverablecontained, but the PE state is corrupted. The interrupted context cannot continue
0b010UEO, Restartablethe PE state is not corrupted. Execution can resume from ELR_ELx
0b011UER, Recoverablethe error is contained and was synchronized by an error synchronization event. Execution cannot simply resume, but software can recover by isolating the affected context (for example by terminating the thread that consumed the data)
0b110CE, Correctedinformational

The precise definitions are in the RAS specification (DDI0587). Linux’s arm64_is_fatal_ras_serror() is a useful reference mapping. It treats IDS == 1, an uncategorized DFSC, UC, UEU and UER as fatal, and only CE and UEO as survivable. That is a policy choice for this path (the kernel does not attempt UER recovery from an SError), not an architectural rule.

ESB and deferred errors

ESB (Error Synchronization Barrier, HINT #16, a NOP without FEAT_RAS) is the explicit error synchronization event. After an ESB, any physical SError that the error-synchronization rules require to be synchronized is pending. What happens next depends on masking:

  • SError can be taken (unmasked, or targeting a higher EL): it is taken, at the ESB boundary.
  • SError is masked (by PSTATE.A at its target EL, or because its target is a lower EL than the current one): the ESB defers it. The pending SError is cleared, and its syndrome is written to DISR_EL1 with DISR_EL1.A (bit 31) set. DISR_EL1 uses the same IDS/AET/EA/DFSC layout as the ISS.

DISR_EL1 is the deferral register for EL1, EL2 and EL3, and access to it from lower ELs is redirected:

Access fromConditionAccess goes to
EL1EL2 enabled and HCR_EL2.AMO == 1 (or the FEAT_DoubleFault2 TMEA condition)VDISR_EL2
EL1, EL2FEAT_E3DSE and effective SCR_EL3.EnDSE == 1 (checked after the EL1 row above)VDISR_EL3
EL1, EL2otherwise, SCR_EL3.EA == 1RAZ/WI
EL3alwaysDISR_EL1

At EL1 under a hypervisor with AMO == 1, physical SErrors target EL2, so an EL1 ESB can only defer a virtual SError. It records the syndrome (from VSESR_EL2) in VDISR_EL2 and clears HCR_EL2.VSE. The guest reads its DISR_EL1 and transparently gets VDISR_EL2.

The idiom, used by KVM on every guest exit, consumes errors without an unmask/remask window:

    // at EL2, PSTATE.A == 1 after exception entry
    esb                         // synchronize errors from the guest's instructions
    mrs   x1, DISR_EL1
    tbnz  x1, #31, guest_serror // A set: the error belongs to the guest, not to EL2
    // guest_serror must clear DISR_EL1 (msr DISR_EL1, xzr); reading it does not clear A

IESB: implicit error synchronization

FEAT_IESB (permitted from v8.2) adds SCTLR_ELx.IESB (bit 21). When it is set, an implicit error synchronization event is inserted at every exception entry to ELx and every exception return from ELx. Errors caused by code before the boundary are therefore synchronized at the boundary, so they cannot leak into the next context and be blamed on it.

  • If the synchronized SError can be taken immediately, it is taken, and ESR_ELx.IESB == 1 tells the handler that it belongs to the code before the boundary. An example is an ERET from EL1 with SCR_EL3.EA == 1, where the target is EL3 and the error is unmasked.
  • If it is masked, which is the normal case on entry because entry sets PSTATE.A, it stays pending, and the handler’s first explicit ESB defers it into DISR_EL1 as above. The implicit event itself does not defer anything and does not write DISR_EL1: only the ESB instruction does.

When SCR_EL3.NMEA is effectively 1, SCTLR_EL3.IESB is treated as 1 (3.3).

When can an SError be attributed to an instruction?

Ranked from most to least precise:

  1. It is not an SError. A synchronous External abort (EC 0x24/0x25/0x20/0x21 with DFSC 0b010000, or the walk variants) is precise and belongs to the instruction at ELR_ELx. FnV says whether FAR_ELx is valid. Consumed poison should take this path (16.7).
  2. FEAT_RASv2 with ISS.ELS == 1: the SError is architecturally reported as triggered by the instruction at ELR_ELx, and VFV/WU/WnR add detail.
  3. Synchronized at a barrier (ESB, or IESB with ISS.IESB == 1): attributable to a region, meaning the context before the barrier, but not to an instruction. This is enough to decide “guest or host”, “EL1 or EL3”, or “this thread”.
  4. Otherwise: imprecise. ELR_ELx is just where the PE happened to be. The error could come from a store hundreds of instructions earlier, a speculative or prefetch access, or another agent’s transaction. The ERR<n> error records and the interconnect’s error logs are the only evidence (18.3).

Bring-up note: an SError that appears to come from “random” code shortly after DRAM or a new peripheral is first touched is usually case 4: a posted write to an address that the interconnect rejects. To bisect it, put DSB SY followed by ESB (with PSTATE.A masked) after each suspect store and check DISR_EL1.A. If the implementation treats that error as synchronizable by an error synchronization event (which errors are is IMPLEMENTATION DEFINED, and a decode error returned after the write has completed may not be), this converts the imprecise SError into a region-attributed one without changing the routing. If the SError targets a higher EL, the ESB cannot defer it, but it is still taken at the ESB, which gives the same attribution.

Validation note: to test the IESB and ESB paths, inject an error with the RAS pseudo-fault generation registers (ERR<n>PFGCTL, see 16.8) so that it is signalled by an access issued just before an ERET (how an injected fault binds to an access is IMPLEMENTATION DEFINED per error node, so check the core TRM). With SCTLR_ELx.IESB == 1 the SError must be reported with ESR_ELx.IESB == 1 (or deferred into DISR_EL1 if masked), and must never be taken after the first instruction of the new context. A report against the new context’s code means the implicit barrier is missing or IESB is not effective.

Checkpoint

Q3.4.1 A Non-secure kernel at EL1 executes ESB with PSTATE.A == 1. HCR_EL2.AMO == 1, SCR_EL3.EA == 0, and a physical SError caused by the kernel’s earlier store becomes pending. What happens?

  • A. The ESB defers it into DISR_EL1, which the kernel then reads
  • B. The SError targets EL2, which is above the current EL, so it is not masked by PSTATE.A and is taken to EL2 at the ESB
  • C. The ESB defers it into VDISR_EL2
  • D. It stays pending until the kernel clears PSTATE.A
Answer

B. Deferral happens only for an SError that is masked at the current EL. With AMO == 1, physical SErrors from EL1 target EL2 and cannot be masked by EL1’s PSTATE.A. C is the tempting answer, but VDISR_EL2 records deferred virtual SErrors. A is wrong too: an EL1 read of DISR_EL1 would return VDISR_EL2 here.

Read more: Arm ARM (DDI0487), ESB; DISR_EL1; VDISR_EL2; Asynchronous exception masking

Q3.4.2 An EL3 handler receives an SError with ESR_EL3.IDS == 0, DFSC == 0b010001, AET == 0b010 and IESB == 0, on a core without FEAT_RASv2. Which conclusion is justified?

  • A. The error was caused by the instruction at ELR_EL3
  • B. The interrupted context must be terminated, because its state is corrupted
  • C. The PE state is not corrupted, so execution may resume at ELR_EL3, but the error cannot be attributed to a particular instruction
  • D. FAR_EL3 holds the address of the failing access
Answer

C. AET 0b010 is UEO (Restartable). The PE state is intact, but nothing in the syndrome ties the error to ELR_EL3 (A): that would need RASv2 ELS, or at least a barrier-synchronized report. B describes UEU. FAR is not valid for an SError without RASv2 VFV == 1 (D).

Read more: Arm ARM (DDI0487), ISS encoding for an SError exception; RAS specification (DDI0587), error types

Q3.4.3 A hypervisor wants every SError caused by guest code to be identified as the guest’s, even when the error response arrives after the guest has trapped to EL2. Which mechanism provides this architecturally?

  • A. SCTLR_EL2.IESB == 1, plus an ESB and a DISR_EL1.A check early in the EL2 exit path
  • B. A DSB SY as the first instruction of the EL2 vector
  • C. HCR_EL2.AMO == 1, which ensures that SErrors are taken in guest context
  • D. SCR_EL3.NMEA == 1
Answer

A. The implicit error synchronization event at entry to EL2 makes the guest’s errors pending at the boundary. Because entry masked PSTATE.A, the first ESB defers them into DISR_EL1, attributed to the code before the boundary, which is the guest. A DSB (B) waits for accesses to complete, but it is not an error synchronization event and does not defer anything. AMO only routes SErrors (C). NMEA concerns EL3 masking (D).

Read more: Arm ARM (DDI0487), SCTLR_EL2.IESB; Error synchronization event; ESB

Part 4: Interrupts and timers

Review part: concise and register-precise, for readers who already know this material.

Prerequisites: 3.1 Exception types and the vector table, 3.3 Routing and masking, 2.1 Exception levels, Security states and execution states

If you already know: the GICv3 programming model from writing a TF-A platform port or an OP-TEE GIC driver, skim 4.1–4.3 for the register tables and read 4.4, 4.5 and 4.7 properly.

Why this matters for bring-up/validation: on a new SoC the first interrupt and the first timer tick are where a wrong Redistributor stride, a sleeping Redistributor, a group/FIQ mix-up or an unsynchronised counter first shows up, usually as silence rather than a fault.

Part 3 ended at the PE boundary: an IRQ or FIQ is asserted, routed by SCR_EL3 and HCR_EL2, and masked by PSTATE. This part covers what sits behind that signal. Sections 4.1 to 4.4 cover the GICv3 model. 4.1 introduces the components (Distributor, Redistributors, the ICC_* system-register CPU interface) and affinity routing. 4.2 follows one interrupt through its state machine: acknowledge, priority drop and deactivation. 4.3 explains how interrupt groups map to FIQ and IRQ in each Security state, and how priority, preemption and the v8.8 NMI extension interact. 4.4 covers the memory-resident side: LPIs, their tables, and the ITS that turns a device’s MSI write into an LPI. 4.5 turns all of this into a bring-up checklist for the interrupt that never arrives, including multi-chip GICs.

The last two sections cover the Generic Timer. 4.6 covers the system counter, the per-EL and per-Security-state timers, and the memory-mapped counter frames. 4.7 covers reading time correctly: counter reads are not ordered the way most people assume, and multi-chiplet systems must keep one consistent count across dies. GICv4 virtual interrupt injection is deliberately left to 11.4.

4.1 GICv3 architecture

The GICv3 architecture is specified in IHI0069, not in the Arm ARM. The Arm ARM defines only the PE side: the IRQ, FIQ and SError exceptions, PSTATE masking, the routing controls covered in 3.3, and the existence of a “GIC CPU interface” whose registers are ICC_* System registers. Everything else is in the GIC specification: the components, the state machine and the memory-mapped frames. This section maps out those components and how affinity routing ties them to MPIDR_EL1.

The four components

           wired SPIs                    MSI writes (DeviceID, EventID)
               |                                   |
        +--------------+                     +-----------+
        | Distributor  |  SPI routing,       |    ITS    |  translation tables in memory
        |  (GICD_*)    |  SPI config         | (GITS_*)  |  -> LPI INTID + target collection
        +--------------+                     +-----------+
               |  (IMPLEMENTATION DEFINED interconnect: AXI-Stream / on-chip fabric)
   +-----------+-----------+------------------- ... ---------+
   |                       |                                 |
+------------------+  +------------------+              +------------------+
| Redistributor 0  |  | Redistributor 1  |              | Redistributor N  |  SGI/PPI config,
| (GICR_*)         |  | (GICR_*)         |              | (GICR_*)         |  LPI tables, power
+------------------+  +------------------+              +------------------+
   | GIC Stream protocol / IMPLEMENTATION DEFINED
+------------------+
| CPU interface    |  ICC_* System registers, inside or beside the PE
+------------------+
   | IRQ / FIQ (and vIRQ/vFIQ)
   PE
ComponentScopeOwnsAccessed by
DistributorOne per GIC (per chip in multi-chip configurations, see 4.5)SPIs (and extended SPIs): enable, group, priority, trigger, routing; global enables GICD_CTLRMMIO, GICD_*
RedistributorOne per PESGIs and PPIs (config in the SGI_base frame), LPI property/pending table pointers, PE power handshake (GICR_WAKER)MMIO, GICR_*
CPU interfaceOne per PEAcknowledge, EOI, deactivate, priority mask, running priority, binary point, SGI generationSystem registers ICC_* (virtual: ICV_*, control: ICH_*)
ITSZero or moreTranslation of MSIs to LPIsMMIO, GITS_*, plus a command queue in memory (4.4)

The split between Redistributor and CPU interface matters to firmware. The Redistributor is in the GIC’s power and clock domain and survives a PE power-down. The CPU interface is usually built into the core. Arm cores implement it there, and it talks to the Redistributor over the GIC Stream protocol (AXI4-Stream in Arm’s GIC-600/700 IP). That interface is IMPLEMENTATION DEFINED as far as the architecture is concerned. It is also why the GICR_WAKER handshake exists: the Redistributor must be told that its PE’s interface is quiescent before power is removed, and must be woken before the PE takes interrupts again.

Redistributor frames and discovery

Each Redistributor occupies contiguous 64KB frames:

FrameOffsetContents
RD_base0x00000GICR_CTLR, GICR_IIDR, GICR_TYPER (0x8), GICR_WAKER (0x14), GICR_PROPBASER (0x70), GICR_PENDBASER (0x78)
SGI_base0x10000GICR_IGROUPR0, GICR_ISENABLER0, …, GICR_IPRIORITYR<n>, GICR_ICFGR0/1, GICR_IGRPMODR0, GICR_NSACR
VLPI_base + reserved0x20000, 0x30000GICv4 only (see 11.4)

A GICv3 Redistributor therefore has a 128KB stride and a GICv4 Redistributor a 256KB stride. Software never assumes which: it walks the region and reads GICR_TYPER in each frame. GICR_TYPER.Affinity_Value (bits [63:32]) holds the Aff3.Aff2.Aff1.Aff0 of the PE served by that Redistributor, GICR_TYPER.Last (bit 4) marks the last Redistributor in a contiguous region, and GICR_TYPER.VLPIS shows whether the larger GICv4 stride applies. TF-A’s gicv3_rdistif_probe() and Linux’s gic_iterate_rdists() both do exactly this walk, matching the affinity value against the PE’s own MPIDR_EL1.

Bring-up note: A device tree or platform #define that gives the wrong Redistributor region size or stride is one of the most common first-interrupt failures. The walk either stops early, so a PE finds no Redistributor and TF-A panics or Linux leaves that CPU without a GIC, or it reads garbage GICR_TYPER values from unpopulated space. Dump GICR_TYPER at every 64KB step once before trusting the platform constants.

The CPU interface as System registers

GICv3 moved the CPU interface from MMIO (the GICv2 GICC_* frame) to System registers. This was more than a speed-up. It makes the interface per-PE without needing banked addresses, lets EL2 trap or virtualise it cleanly (ICH_HCR_EL2, ICV_*), and lets accesses be ordered by the PE’s own context-synchronization rules.

RegisterPurpose
ICC_SRE_EL1/EL2/EL3System Register Enable: SRE (bit 0) selects the System-register interface; DFB/DIB disable FIQ/IRQ bypass; Enable (EL2/EL3 only) allows lower ELs to use ICC_SRE_EL1
ICC_IAR0_EL1, ICC_IAR1_EL1Acknowledge the highest-priority pending Group 0 / Group 1 interrupt
ICC_EOIR0_EL1, ICC_EOIR1_EL1, ICC_DIR_EL1Priority drop, and deactivation (4.2)
ICC_HPPIR0_EL1, ICC_HPPIR1_EL1Peek at the highest-priority pending interrupt without acknowledging it
ICC_PMR_EL1, ICC_RPR_EL1Priority mask; running priority (4.3)
ICC_BPR0_EL1, ICC_BPR1_EL1Binary point (preemption granularity)
ICC_AP0R<n>_EL1, ICC_AP1R<n>_EL1Active-priority bitmaps; save/restore only
ICC_IGRPEN0_EL1, ICC_IGRPEN1_EL1, ICC_IGRPEN1_EL3Per-PE group enables at the CPU interface
ICC_CTLR_EL1, ICC_CTLR_EL3EOImode, CBPR, and read-only capability fields (PRIbits, IDbits, SEIS, A3V, RSS, ExtRange)
ICC_SGI0R_EL1, ICC_SGI1R_EL1, ICC_ASGI1R_EL1Generate SGIs (Group 0; Group 1 of the current Security state; Group 1 of the other Security state)
ICC_NMIAR1_EL1Acknowledge a Group 1 NMI (GICv3.3 with FEAT_NMI, see 4.3)

Writes to these registers are not self-synchronising in general. A write to ICC_PMR_EL1, ICC_IGRPENn_EL1, ICC_EOIRn_EL1 or ICC_SGI1R_EL1 is only guaranteed to have taken effect after a context synchronization event, which is why Linux puts an ISB after its EOI and SGI writes (see 7.8). Leaving the System-register interface disabled (ICC_SRE_ELx.SRE == 0) selects the legacy memory-mapped interface. Support for that is optional, and most modern implementations make SRE RAO/WI. The enable order across EL3, EL2 and EL1 belongs to 4.5.

Affinity routing

With affinity routing enabled (GICD_CTLR.ARE_S and GICD_CTLR.ARE_NS; just ARE when GICD_CTLR.DS == 1), every target is named by an affinity value in the same format as MPIDR_EL1. That gives a hierarchical name of up to 2^32 PEs, where GICv2 had an 8-bit target mask. In practice affinity routing is always on. GICv3 legacy (non-ARE) operation is optional and only exists for GICv2-era software.

SPI routing uses one 64-bit GICD_IROUTER<n> per SPI, at GICD_base + 0x6000 + 8n:

FieldBitsMeaning
Aff0, Aff1, Aff2[7:0], [15:8], [23:16]Target PE affinity
Interrupt_Routing_Mode (IRM)310: route to the named PE. 1: “1 of N”, deliver to any participating PE
Aff3[39:32]Target PE affinity, level 3

In 1-of-N mode the GIC picks a PE from those whose Redistributor has not opted out with GICR_CTLR.DPG0/DPG1NS/DPG1S, and whose CPU interface has the group enabled. Support for 1-of-N is optional (GICD_TYPER.No1N), and its selection policy is IMPLEMENTATION DEFINED. Firmware that needs determinism, such as a Secure SPI that must reach the core running the SPMC, names a PE explicitly.

SGIs are targeted through ICC_SGI1R_EL1 (and its siblings), whose layout encodes a cluster and a 16-bit target list within it:

FieldBitsMeaning
TargetList[15:0]Bit n targets the PE with Aff0 = n (+16×RS) in the named cluster
Aff1[23:16]Cluster affinity
INTID[27:24]SGI number 0–15
Aff2[39:32]
IRM401: all PEs except self (TargetList ignored)
RS[47:44]Range selector, for Aff0 values above 15 (if ICC_CTLR_EL1.RSS == 1)
Aff3[55:48]

So one write reaches at most 16 PEs that share Aff3.Aff2.Aff1. A broadcast to a large multi-cluster system is several writes, or one IRM = 1 write. Note what this means for DynamIQ parts, where each core usually has a distinct Aff1 and Aff0 = 0: each SGI write reaches exactly one core unless IRM is used.

Versions in brief

VersionAdds (summary; IHI0069 is authoritative)
GICv3.0Affinity routing, System-register CPU interface, LPIs and ITS, Secure Group 1
GICv3.1Extended SPI (INTIDs 4096–5119) and extended PPI (1056–1119) ranges, Secure EL2 support
GICv3.3NMIs (“superpriority”), for use with FEAT_NMI
GICv4.0 / 4.1Direct injection of vLPIs; v4.1 adds direct vSGIs (11.4)

Read GICD_PIDR2.ArchRev and GICD_TYPER (ESPI, NMI, LPIS, MBIS, DVIS, RSS) rather than assuming a version from the IP name.

GICv5 and what it means for firmware ports

GICv5 (Arm document AES0070, first published in 2025) is not a compatible extension of GICv3. Its main changes:

  • The Distributor and Redistributors are replaced by an Interrupt Routing Service (IRS). The IRS holds the configuration and state of SPIs and LPIs, mostly in memory-resident tables, instead of banks of globally synchronised MMIO registers. An ITS still translates MSIs, and an Interrupt Wire Bridge (IWB) converts wired interrupts into messages.
  • The CPU interface is driven by new GIC system instructions (the GIC / GICR instruction space, for example GIC CDEN to enable and GICR CDIA to acknowledge), discovered through ID_AA64PFR2_EL1 as FEAT_GCIE. ICC_* System registers still exist but have a different set and layout.
  • The model is LPI-centric. There are only PPIs, SPIs and LPIs, and there is no SGI type: inter-processor interrupts are LPIs.
  • Virtualization is designed in. Virtual interrupts can be delivered to a running vPE without a list-register round trip through the hypervisor, and guest IPIs and interrupt configuration are meant not to need EL2 traps (check AES0070 for exactly which interrupt types and operations this covers).
  • Interrupts belong to interrupt domains (EL3, Secure, Non-secure, Realm) instead of to GICv3 “groups”.

For a firmware port this is a rewrite, not a driver tweak. TF-A’s GICv3 driver, the group-to-FIQ/IRQ reasoning in 4.3, the GICR_WAKER power handshake and the ITS command sequences in 4.4 all change. The PE-side concepts carry over unchanged: exception routing, PSTATE masking, and the need for context synchronization after control writes. Treat the GICv5 statements above as a summary of the published specification, and check AES0070 before relying on them.

Checkpoint

Q4.1.1 A platform port computes each CPU’s Redistributor as GICR_base + cpu_index * 128KB and then checks that GICR_TYPER.Affinity_Value matches the CPU’s MPIDR_EL1. On the real GIC (GICv4.1-capable IP), CPU 0 boots fine but CPUs 1–3 report “no Redistributor found”. What is the most likely cause?

  • A. The Redistributors of CPUs 1–3 are still asleep (GICR_WAKER.ProcessorSleep == 1), so GICR_TYPER reads as zero
  • B. Affinity routing is disabled, so GICR_TYPER.Affinity_Value is not populated
  • C. Each Redistributor is 256KB (GICR_TYPER.VLPIS == 1), so CPUs 1 and 3 land in VLPI_base frames and CPU 2 lands on Redistributor 1, and none of those holds a matching affinity
  • D. ICC_SRE_EL1.SRE is 0 on CPUs 1–3, so they cannot read Redistributor registers
Answer

C. With GICv4 the Redistributor has four 64KB frames. CPU 0 matches at offset 0. CPU 1’s address (0x20000) is Redistributor 0’s VLPI_base frame, where offset 0x8 is not GICR_TYPER. CPU 2’s address (0x40000) is Redistributor 1, which holds CPU 1’s affinity. CPU 3 lands in Redistributor 1’s VLPI_base. A walk that steps by 128KB and stops at GICR_TYPER.Last fails in a different way, which is why software reads VLPIS in each frame rather than using a constant. Option A is tempting, but GICR_TYPER is readable whatever the GICR_WAKER state: the wake handshake controls interrupt forwarding, not discovery. ICC_SRE controls the CPU interface, not MMIO access to GICR_*.

Read more: GIC Architecture Specification (IHI0069), Redistributor register map; GICR_TYPER

Q4.1.2 A system has 4 clusters with Aff1 = 0..3 and 8 cores each with Aff0 = 0..7. Firmware wants to send SGI 5 to core 2 in every cluster. What is the minimum number of ICC_SGI1R_EL1 writes, and why?

  • A. Four, because one write names a single Aff3.Aff2.Aff1 cluster and a TargetList within it
  • B. One, with TargetList = 0x0004 and Aff1 left as 0, since TargetList applies to all clusters
  • C. One, with IRM = 1, because IRM broadcasts to the set named in TargetList across all clusters
  • D. Two, because RS lets one write cover 16 clusters at a time
Answer

A. TargetList selects Aff0 values within the one cluster named by the Aff3/Aff2/Aff1 fields of that write. IRM = 1 means “all PEs except self” and ignores TargetList, so it would hit 31 cores, not the 4 wanted. RS extends the Aff0 range in steps of 16 (for clusters with more than 16 PEs). It does not select clusters.

Read more: GIC Architecture Specification (IHI0069), ICC_SGI1R_EL1

Q4.1.3 Which statement correctly says why GICv3 split the Redistributor from the CPU interface, and what that means for power management?

  • A. The Redistributor holds the PE’s acknowledge state, so it must be saved and restored by firmware on every power-down
  • B. The CPU interface is in the GIC power domain, so ICC_* registers keep their values across a core power-down
  • C. The split only exists to support legacy GICv2 software, and has no effect on power sequencing
  • D. The Redistributor stays in the GIC’s power domain and keeps SGI/PPI/LPI configuration while the PE is off, so the PE must quiesce its interface with the GICR_WAKER handshake before power is removed
Answer

D. The Redistributor is the GIC’s per-PE agent and can stay powered when the core is off. That is what allows wake-up on an interrupt targeting an off core. The CPU interface usually lives in the core, so its ICC_* state (PMR, group enables, active priorities) is lost and must be restored. B has the domains reversed. A puts the acknowledge and active-priority state on the wrong side.

Read more: GIC Architecture Specification (IHI0069), Power management, GICR_WAKER

4.2 Interrupt types and lifecycle

INTID space

TypeINTID rangeScopeConfig lives inTriggerActive state
SGI0–15Per PE, generated by software (ICC_SGI*R_EL1)Redistributor SGI_baseEdge (fixed)Yes
PPI16–31; extended PPI 1056–1119 (GICv3.1)Per PE (timers, PMU overflow, GIC maintenance, TRBE, …)Redistributor SGI_baseLevel or edge (GICR_ICFGR1)Yes
SPI32–1019; extended SPI 4096–5119 (GICv3.1)Shared, routed by GICD_IROUTER<n>DistributorLevel or edge (GICD_ICFGR<n>)Yes
Special1020–1023Returned by acknowledge reads, never configured———
LPI8192 and up (limited by GICD_TYPER.IDbits, GICR_PROPBASER.IDbits)Per target Redistributor, Non-secure Group 1 onlyMemory tables (4.4)Edge (message)No

The special INTIDs tell software what an acknowledge or HPPIR read found:

INTIDMeaning
1020(EL3, Group 0 read) highest pending is Secure Group 1
1021(EL3, Group 0 read) highest pending is Non-secure Group 1
1022Highest pending interrupt is an NMI, ICC_IAR1_EL1 was used and SCTLR_ELx.NMI == 1. With FEAT_NMI, NMIs must be acknowledged with ICC_NMIAR1_EL1 (4.3)
1023Spurious: nothing pending that this read is allowed to acknowledge, or it cannot preempt

1020 and 1021 are what let an EL3 FIQ handler find out that a Group 1 interrupt caused the FIQ, and hand it to S-EL1 or the Normal world without acknowledging it. TF-A’s plat_ic_get_pending_interrupt_type() is built on this. Sizes are discovered at run time: GICD_TYPER.ITLinesNumber (N) gives the maximum SPI INTID as 32×(N+1) − 1, so up to 32×N SPIs, GICD_TYPER.ESPI_range gives the extended SPIs, and GICR_TYPER.PPInum gives the extended PPIs.

The state machine

Every SGI, PPI and SPI has four states. They are visible and writable through the set/clear register pairs (GICD/GICR_ISPENDR/ICPENDR, ISACTIVER/ICACTIVER):

           assert / set-pending                    acknowledge (IARn read)
 Inactive ------------------------> Pending ----------------------------> Active
    ^                                                                      |   ^
    |                                       re-assert (edge) or            |   |
    |                                       still asserted (level)         v   |
    +-- deactivate (EOImode=0 EOI, or DIR) -------------------- Active and pending
         from Active -> Inactive,  from Active and pending -> Pending

The trigger type decides how the line maps onto this:

  • Level-sensitive: the pending state follows the input. If the peripheral still asserts the line when the interrupt is acknowledged, it goes to active and pending, and it becomes pending again after deactivation. That is why a handler must clear the source before EOI, and why the clear must have completed, not merely been issued (see 7.9). Otherwise the interrupt is taken again straight away.
  • Edge-triggered: each rising edge (or message, such as GICD_SETSPI_NSR or an ITS write) sets pending. Edges that arrive while the interrupt is pending merge into one. An edge that arrives while it is active gives active and pending, so it is not lost.

While an interrupt is active it is not signalled again. A second instance can only arrive once it has been deactivated. This is the mechanism that serialises one INTID across all PEs.

Acknowledge, priority drop, deactivation

Handling an interrupt involves three distinct architectural events:

  1. Acknowledge: a read of ICC_IAR0_EL1 (Group 0) or ICC_IAR1_EL1 (Group 1) returns the INTID of the highest-priority pending interrupt of that group. That interrupt must be enabled, its group must be enabled, its priority must be higher than ICC_PMR_EL1, and its group priority must be higher than the running priority. The read moves the interrupt from pending to active, sets the bit for its group priority in ICC_AP0Rn/ICC_AP1Rn, and so raises the running priority (ICC_RPR_EL1). The acknowledge is itself a side-effecting System-register read. That is one reason Linux follows ICC_IAR1_EL1 with a DSB SY (gic_read_iar()).
  2. Priority drop: a write of the INTID to ICC_EOIR0_EL1/ICC_EOIR1_EL1 clears the highest set active-priority bit, which lowers the running priority so that lower-priority interrupts can preempt again. Priority drops must be done in the reverse order of acknowledges, and the EOIR group must match the IAR group used.
  3. Deactivation: the interrupt moves from active to inactive (or from active and pending to pending), so the GIC can signal that INTID again.

ICC_CTLR_EL1.EOImode (with the EL3 copies ICC_CTLR_EL3.EOImode_EL3, EOImode_EL1S and EOImode_EL1NS) decides whether steps 2 and 3 are combined:

EOImodeICC_EOIRn_EL1 writeICC_DIR_EL1 write
0Priority drop and deactivationMust not be used (behavior is not useful; see IHI0069 ICC_DIR_EL1)
1Priority drop onlyDeactivation

EOImode = 1 has two main uses:

  • Forwarding to a guest. A hypervisor acknowledges and drops priority on a physical interrupt but leaves it active. It then puts it in a list register with the HW bit set, so that the guest’s virtual EOI deactivates the physical interrupt directly. KVM runs the host with EOImode = 1 when it owns EL2 for this reason (11.4).
  • Deferred handling of a level interrupt. The handler drops priority so other interrupts can run, and keeps the INTID active (so not re-signalled) until a thread has quietened the device. Then it writes ICC_DIR_EL1.

The minimal EOImode = 0 handler at EL1:

irq_el1:
    mrs   x0, ICC_IAR1_EL1          // acknowledge: pending -> active, RPR raised
    and   w1, w0, #0xffffff         // INTID field
    sub   w2, w1, #1020
    cmp   w2, #3
    b.ls  1f                        // 1020-1023: special, nothing to EOI (LPIs are >= 8192)
    dsb   sy                        // as Linux does after IAR
    bl    dispatch                  // must quiesce the source (and complete the write)
    msr   ICC_EOIR1_EL1, x0         // priority drop + deactivate (EOImode == 0)
    isb                             // redundant before ERET (itself a context synchronization event
                                    // unless SCTLR_EL1.EOS == 0); needed if unmasking in place
1:  eret                            // (register save/restore omitted)

A spurious 1023 must not be written to EOIR. Its usual cause is a race: the interrupt was withdrawn, or a higher-priority one was taken elsewhere, between signalling and acknowledge.

Type-specific details

  • SGIs in GICv3 with affinity routing have no per-source state. The GICv2 “which CPU sent it” field in IAR is gone. An SGI that is sent again while still pending on the same target merges into one. Non-secure code can generate a Secure SGI only where GICR_NSACR permits. To make normal-memory data visible to the target’s handler before the SGI arrives, the sender needs a DSB before the ICC_SGI1R_EL1 write, because a DMB does not order against a System-register write. It also needs an ISB after the write to ensure the SGI is issued promptly. Linux’s gic_ipi_send_mask() uses dsb(ishst) … write … isb().
  • PPIs are private to one PE: they are routed only to the PE they belong to, and must be configured through that PE’s Redistributor. Neither the GIC spec nor the Arm ARM fixes which PPI a source uses. BSA gives the recommended assignments, for example the EL1 physical timer (INTID 30), the EL1 virtual timer (27), the Non-secure EL2 physical timer (26) and the PMU (23); the platform’s firmware tables give the real ones.
  • LPIs have no active state. Acknowledging an LPI makes it inactive straight away. The EOI is still needed for the priority drop, and ICC_DIR_EL1 for an LPI has no effect. A new MSI can set it pending again while the handler is still running, so LPI handlers must tolerate re-entry or the device must not re-signal. LPI configuration is cached, so a change to the property table needs an explicit invalidate (4.4).

Security note: The set-pending and set-active registers let a privileged agent fabricate an interrupt. Secure-group interrupts are RAZ/WI to Non-secure accesses in the Distributor and Redistributor (when GICD_CTLR.DS == 0), which is what stops the Normal world injecting a Secure interrupt. If a platform ships with DS == 1, that protection is gone, and the boot chain should treat it as a configuration error on any system with a TEE.

Checkpoint

Q4.2.1 A level-sensitive SPI handler running with EOImode = 0 writes ICC_EOIR1_EL1 and then clears the device’s status register with a store to Device-nGnRE memory. The interrupt is taken a second time with nothing to do. What explains this?

  • A. EOImode = 0 does not deactivate SPIs, so the interrupt stays active and is re-signalled
  • B. The EOI deactivated the interrupt while the line was still asserted, so it went to pending (it was active and pending) and was signalled again before the device clear took effect
  • C. Level-sensitive SPIs must be acknowledged twice, once for assertion and once for deassertion
  • D. The running priority was not dropped, so the same interrupt preempted itself
Answer

B. For a level interrupt the pending state follows the input. Deactivating while the input is still high leaves it pending, and since the priority has dropped it is signalled again. The source must be quietened first, and that store must have completed (a DSB, or a read-back if the peripheral needs it) before the EOI. D cannot be right: an interrupt cannot preempt at its own running priority, and an EOI with EOImode = 0 does drop the priority.

Read more: GIC Architecture Specification (IHI0069), Interrupt handling state machine; level-sensitive and edge-triggered behavior

Q4.2.2 A hypervisor runs with EOImode = 1 at EL2. It acknowledges a physical SPI, writes ICC_EOIR1_EL1, and forwards the SPI to a guest through a list register with the HW bit set. What is the state of the physical SPI while the guest handles it?

  • A. Inactive: EOIR deactivated it, and the HW bit only affects the virtual interrupt
  • B. Pending: priority drop returns it to pending until the guest acknowledges
  • C. Active, with the running priority of the PE still raised until the guest’s EOI
  • D. Active, with the PE’s running priority already dropped, so it will be deactivated when the guest’s virtual EOI propagates through the HW bit
Answer

D. With EOImode = 1, the EOIR write only drops priority, so the PE can take other interrupts, including the maintenance and other physical interrupts the hypervisor needs. The physical SPI stays active, so it is not re-signalled. When the guest deactivates the virtual interrupt, the HW link deactivates the physical INTID. C is wrong because the priority drop has already happened. A would be the EOImode = 0 behavior.

Read more: GIC Architecture Specification (IHI0069), Priority drop and interrupt deactivation; ICC_CTLR_EL1.EOImode; ICH_LR<n>_EL2.HW

Q4.2.3 A core stores a message to a Normal-memory mailbox, executes DMB ISH, and then writes ICC_SGI1R_EL1 to signal another core. Occasionally the receiving handler reads the old message. Why?

  • A. DMB orders memory accesses only against other memory accesses. The System-register write that generates the SGI is not a memory access, so it needs a DSB before it
  • B. SGIs are delivered speculatively before the sender’s store, and only an ISB on the receiver fixes it
  • C. DMB ISH does not cover the receiving core; DMB OSH is required
  • D. The mailbox must be Device memory for any barrier to order it against an SGI
Answer

A. The SGI write is a System-register access with side effects outside the memory model’s ordering of explicit accesses. DMB does not order it after earlier stores, but DSB waits for those stores to complete before later instructions, including the MSR, execute. Both cores are in the same Inner Shareable domain, so C misidentifies the problem. Linux uses dsb(ishst) before the SGI write.

Read more: Arm ARM (DDI0487), Memory barriers, DSB; GIC Architecture Specification (IHI0069), ICC_SGI1R_EL1

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.

IGRPMODRIGROUPRGroupIntended owner
00Group 0EL3 firmware
01Non-secure Group 1Normal world (Linux, hypervisor)
10Secure Group 1Secure EL1/EL2 (OP-TEE, SPMC)
11Reserved (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:

GroupEL3Secure EL1/EL2Non-secure EL1/EL2
Group 0FIQFIQFIQ
Secure Group 1FIQIRQFIQ
Non-secure Group 1FIQFIQIRQ

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 = 1 in 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:

  1. It is enabled, and its group is enabled at both the Distributor and the CPU interface.
  2. 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.
  3. 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 valueGroup priority bitsSubpriority bits
0[7:1][0]
1[7:2][1:0]
2[7:3][2:0]
………
7none (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.DS is 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 with MSR ALLINT, #imm or through the ALLINT special register, masks all IRQs and FIQs taken to the current EL, superpriority included.
  • SCTLR_ELx.SPINTMASK = 1 gives an alternative model: superpriority interrupts are masked while the PE runs at ELx using SP_ELx (PSTATE.SP == 1). Code on SP_EL0 can take NMIs, and the exception entry and exit paths, which run on SP_ELx, are protected without explicit ALLINT manipulation.
  • On exception entry to ELx, PSTATE.ALLINT is set to NOT SCTLR_ELx.SPINTMASK, so with SPINTMASK == 0 the handler starts with all interrupts masked and must clear ALLINT when it can accept an NMI. ALLINT is saved in and restored from SPSR_ELx. HCRX_EL2.TALLINT lets EL2 trap EL1 writes to ALLINT.

Bring-up note: Enabling SCTLR_EL1.NMI without NMI-aware code is a silent hazard. Every region that was protected only by PSTATE.I/F can now be preempted by a superpriority interrupt, and an NMI that preempts the window between exception entry and saving ELR_EL1/SPSR_EL1 (for example because ALLINT was cleared too early) corrupts the return state. Either keep SPINTMASK = 0 and clear ALLINT only after state is saved, or use SPINTMASK = 1 with SP_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_EL1 and 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.ALLINT is 1 on entry, so even a superpriority interrupt cannot preempt until the handler clears ALLINT
  • B. PSTATE.I is set on entry, which also masks superpriority interrupts
  • C. Superpriority interrupts can preempt immediately, because only SPINTMASK = 1 protects the entry path
  • D. ALLINT is 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

4.4 LPIs and the ITS

SPIs do not scale. Each one needs a wire, a set of Distributor register bits, and a globally synchronised MMIO configuration. PCIe and other modern devices signal interrupts by writing to an address (MSI/MSI-X). GICv3’s answer has two layers. LPIs are message-based interrupts whose configuration and pending state live in normal memory. The Interrupt Translation Service (ITS) turns a device’s write into an LPI on a chosen Redistributor. This section covers the physical model. GICv4’s vLPIs and the vPE tables are in 11.4.

LPI properties

  • INTIDs from 8192 upwards. The maximum is set by GICD_TYPER.IDbits (the hardware maximum) and by GICR_PROPBASER.IDbits (what software provides tables for).
  • Always Non-secure Group 1, always edge-triggered (message-based), and with no active state (4.2).
  • LPIs are supported if GICD_TYPER.LPIS == 1 and, per Redistributor, if GICR_TYPER.PLPIS == 1.
  • They can be generated by an ITS, or directly by writing GICR_SETLPIR if GICR_TYPER.DirectLPI == 1. Direct LPIs are rare in Arm IP.

The two Redistributor tables

GICR_PROPBASER --> LPI Configuration table (1 byte per LPI, indexed by INTID - 8192)
                     bit [7:2] priority (top 6 bits; bits [1:0] of priority are 0)
                     bit [1]   RES1
                     bit [0]   Enable
GICR_PENDBASER --> LPI Pending table (1 bit per INTID, including 0..8191; per Redistributor)
                     first 1KB (INTIDs 0..8191): IMPLEMENTATION DEFINED use, must start zeroed
RegisterKey fieldsNotes
GICR_PROPBASERPhysical_Address, IDbits (supported INTID bits = IDbits+1), InnerCache, OuterCache, ShareabilityTable size is 2^(IDbits+1) − 8192 bytes. Normally the same table for all Redistributors; GICR_TYPER.CommonLPIAff says which Redistributors must share one
GICR_PENDBASERPhysical_Address (64KB aligned), PTZ (Pending Table Zero), cache and shareability attributesOne table per Redistributor, 2^(IDbits+1) bits. PTZ = 1 tells the GIC the table is all zeros, so it can skip reading it
GICR_CTLR.EnableLPIs—Writing either BASER while EnableLPIs == 1 is UNPREDICTABLE. It is IMPLEMENTATION DEFINED whether EnableLPIs can be cleared once set

These tables are owned by the GIC once LPIs are enabled. Software never writes the pending table. Software does write the configuration table, but the Redistributor may cache entries, so an update (enable, disable, priority change) must be followed by an invalidate. That is the ITS INV/INVALL command, or GICR_INVLPIR/GICR_INVALLR where implemented (GICv4.1, or DirectLPI).

Bring-up note: Because EnableLPIs can be one-way, firmware that enables LPIs in a Redistributor (for example a BL33 doing PCIe boot) leaves the next stage unable to move the tables. Linux has a whole mechanism for kexec and firmware handover (it reuses the pre-programmed tables and marks them reserved, see its_cpu_init_lpis() and the RDIST_FLAGS_RD_TABLES_PREALLOCATED logic). Hand over with LPIs disabled, or record in the handoff where the tables are.

The ITS: three tables and a command queue

An ITS translates a pair (DeviceID, EventID) into an (LPI INTID, target Redistributor) pair. The device supplies only the EventID, as the data of a 32-bit write to GITS_TRANSLATER. The interconnect supplies the DeviceID as sideband information: the PCIe Requester ID mapped through the root complex, or the SMMU StreamID. Firmware describes that mapping in ACPI IORT or in device-tree msi-map/msi-parent.

MSI write: data = EventID  -->  GITS_TRANSLATER (ITS_base + 0x10040), DeviceID from sideband
    |
    v
Device table [DeviceID]     -> ITT base address, number of EventID bits      (GITS_BASER<n>, Type = Devices)
    |
    v
ITT of that device [EventID] -> pINTID (LPI), ICID                           (memory, allocated per device)
    |
    v
Collection table [ICID]     -> RDbase (target Redistributor)                 (GITS_BASER<n>, Type = Collections,
    |                                                                         or held in the ITS: GITS_TYPER.HCC)
    v
Target Redistributor sets pINTID pending, reads its Configuration entry (Enable, priority), forwards to the CPU interface

A collection is one level of indirection between interrupts and PEs. Moving every LPI of a collection to another PE (CPU hotplug, affinity change) is one MOVALL (plus remapping the collection with MAPC), not one command per interrupt. Linux uses one collection per CPU.

Discovery and table setup

GITS_TYPER describes the ITS:

FieldMeaning
ITT_entry_sizeBytes per ITT entry minus 1 (software allocates ITTs with this)
ID_bitsEventID bits minus 1 supported
DevbitsDeviceID bits minus 1 supported
PTATarget address format: 1 = RDbase is the Redistributor’s physical address, 0 = it is GICR_TYPER.Processor_Number
HCCNumber of collections held in the ITS without a memory table
Physical, VirtualPhysical LPIs supported; GICv4 vLPIs supported

Each GITS_BASER<n> (n = 0–7) has a read-only Type (0 unimplemented, 1 Devices, 2 vPEs, 4 Collections) and Entry_Size. Software must probe them rather than assume an order. Software chooses Physical_Address, Page_Size (4K, 16K or 64K), Size (in pages), the cache and shareability attributes, and Indirect. Indirect (two-level) tables use a first level of 8-byte pointers to pages, which matters when Devbits is large but DeviceIDs are sparse, as with PCIe bus/device/function. Then Valid is set.

The command queue

GITS_CBASER describes a ring buffer in memory (base address, Size in 4KB pages, attributes, Valid). Each command is 32 bytes. Software writes commands at GITS_CWRITER and advances it. The ITS consumes them and advances GITS_CREADR. The queue is empty when the two are equal, and full when advancing CWRITER would make it equal CREADR.

CommandCodeEffect
MAPD0x08Map DeviceID to an ITT (address, EventID size), or unmap if V = 0
MAPC0x09Map ICID to a target RDbase, or unmap
MAPTI0x0AMap (DeviceID, EventID) to (pINTID, ICID)
MAPI0x0BMAPTI with pINTID = EventID
MOVI0x01Move one (DeviceID, EventID) to another collection
DISCARD0x0FRemove the mapping and clear any pending state
INV0x0CRe-read the configuration entry for the LPI that (DeviceID, EventID) maps to
INVALL0x0DRe-read all configuration for a collection
INT / CLEAR0x03 / 0x04Set / clear pending, as if the device had written (useful for testing)
MOVALL0x0EMove all pending LPIs from one Redistributor to another
SYNC0x05Wait until all earlier commands’ effects for a Redistributor are globally visible

The ITS processes commands in order, but completion of their effects at the Redistributors is only guaranteed after a SYNC for that target (or VSYNC for GICv4) has itself been consumed, meaning GITS_CREADR has moved past it. Watching CREADR advance past a MAPTI does not mean an MSI will already be delivered.

A minimal bring-up sequence for one device with one MSI:

/* once per Redistributor (with GICR_CTLR.EnableLPIs == 0): */
/* GICR_PROPBASER, GICR_PENDBASER (zeroed table), then set GICR_CTLR.EnableLPIs */

/* once per ITS */
alloc_and_program(GITS_BASER_n /* Type == Devices */);
alloc_and_program(GITS_BASER_m /* Type == Collections, unless HCC covers it */);
write64(GITS_CBASER, cmdq_pa | size_pages_minus_1 | attrs | VALID);
write64(GITS_CWRITER, 0);
write32(GITS_CTLR, GITS_CTLR_ENABLED);
its_cmd(MAPC, .icid = cpu, .rdbase = PTA ? gicr_pa(cpu) : proc_num(cpu), .v = 1);
its_cmd(SYNC, .rdbase = ...);

/* per device: DeviceID 0x100, EventID 0 -> LPI 8192 on CPU 0 */
prop_table[8192 - 8192] = (prio & 0xfc) | 0x2 /*RES1*/ | 0x1 /*Enable*/;
clean_dcache_to_poc_if_noncoherent(&prop_table[0], 1);
its_cmd(MAPD,  .devid = 0x100, .itt = itt_pa, .size = event_bits - 1, .v = 1);
its_cmd(MAPTI, .devid = 0x100, .eventid = 0, .pintid = 8192, .icid = 0);
its_cmd(INV,   .devid = 0x100, .eventid = 0);
its_cmd(SYNC,  .rdbase = ...);
/* now program the device's MSI address = GITS_TRANSLATER PA, data = 0 */

its_cmd() writes 32 bytes to the queue slot, makes them visible to the ITS (a DSB for coherent ITS, or a clean to PoC first for a non-coherent one), advances GITS_CWRITER, and for SYNC polls GITS_CREADR.

Bring-up note: Write Shareability/InnerCache in GITS_BASER<n>, GITS_CBASER, GICR_PROPBASER and GICR_PENDBASER, then read them back. An ITS or Redistributor that cannot snoop the PE caches reports Non-shareable or non-cacheable. Software must then use Non-cacheable mappings for these tables, or clean to the Point of Coherency before every command or table update (8.5, 8.7). Linux does this (GITS_FLAGS_CMDQ_NEEDS_FLUSHING). Forgetting it produces commands the ITS reads as stale zeros.

Bring-up note: If a command is malformed or out of range (DeviceID above Devbits, an unmapped collection), the ITS may stall: GITS_CREADR.Stalled = 1 and CREADR stops. How the error is reported is IMPLEMENTATION DEFINED. After fixing the command, software can restart processing with GITS_CWRITER.Retry where the stall model supports it. A queue that never drains is the first thing to check when MSIs never arrive.

Security and isolation

The ITS and LPIs are Non-secure only. Isolation between devices rests on the DeviceID being unforgeable. A device can only choose an EventID, which indexes its own ITT. Firmware must therefore make sure DeviceIDs are generated by hardware (the root complex or SMMU), not by the device, and that the ITS tables, ITTs and command queue are not reachable by device DMA. They are normally kept outside any SMMU mapping given to a device (11.5). GITS_TRANSLATER itself must be mapped for the devices that send MSIs.

Checkpoint

Q4.4.1 A driver disables an LPI by clearing bit 0 of its configuration-table byte and executes DSB SY. The LPI keeps being delivered. What is missing?

  • A. An ISB, so that the CPU interface sees the new configuration
  • B. Nothing in software. LPIs cannot be disabled once mapped, so a DISCARD is the only way
  • C. An invalidation (INV for that DeviceID/EventID followed by SYNC, or GICR_INVLPIR where supported), because the Redistributor may have cached the old configuration
  • D. A write to GICR_PENDBASER to clear the pending bit
Answer

C. The configuration table is memory that the Redistributor may cache. The DSB makes the store visible at the PE’s side, but the GIC need not re-read it until told to with an invalidate. A misplaces the problem: the cached state is in the GIC, not the PE’s context. D is wrong twice over: software never writes the pending table, and rewriting GICR_PENDBASER with LPIs enabled is UNPREDICTABLE.

Read more: GIC Architecture Specification (IHI0069), LPI Configuration tables; ITS commands INV, SYNC

Q4.4.2 After MAPD, MAPTI and INV, the driver sees GITS_CREADR pass the INV and immediately triggers the device. The first MSI is sometimes lost, but later ones work. What is the most defensible fix?

  • A. Insert DSB SY; ISB after observing GITS_CREADR
  • B. Issue a SYNC targeting the collection’s Redistributor and wait for GITS_CREADR to pass it before enabling the device
  • C. Replace MAPTI with MAPI, which completes synchronously
  • D. Set GICR_PENDBASER.PTZ, so the Redistributor does not need to read the pending table
Answer

B. CREADR advancing only means the ITS has consumed a command. A SYNC is what guarantees that the effects of earlier commands on that Redistributor are complete. PE barriers (A) cannot order the ITS’s internal work. MAPI differs only in using pINTID = EventID. PTZ is a one-time initialisation hint and is unrelated.

Read more: GIC Architecture Specification (IHI0069), The ITS command queue; SYNC

Q4.4.3 A malicious PCIe endpoint wants to raise an LPI that belongs to another device. Which property of the architecture prevents it, and what must the platform get right for that to hold?

  • A. LPIs are Secure-only, so endpoints cannot raise them without TrustZone permission
  • B. The ITS checks the EventID against an allow-list in GITS_CTLR
  • C. Each LPI’s configuration byte records the owning DeviceID, and the Redistributor checks it
  • D. Translation is indexed by a DeviceID supplied as sideband by the root complex or SMMU, so the device can only select EventIDs within its own ITT. The platform must generate DeviceIDs in hardware and keep ITS tables and ITTs out of device-reachable memory
Answer

D. The DeviceID selects which ITT is used, and the device controls only the EventID. If a device could choose its DeviceID, or overwrite an ITT by DMA, isolation would be lost. A is wrong because LPIs are Non-secure Group 1 only. The configuration table holds just priority and enable, which rules out C.

Read more: GIC Architecture Specification (IHI0069), The ITS, DeviceID and EventID; Arm IORT specification (DEN0049)

4.5 GIC bring-up and the interrupt-never-arrives checklist

An interrupt that never arrives has no fault, syndrome or log. It is a state somewhere along the Distributor, Redistributor and CPU interface path that stops propagation. This section gives the initialisation order that removes those states, then a checklist that walks the same path backwards when something is still silent. The architecture is in 4.1, lifecycle in 4.2, groups and priority views in 4.3, and LPIs in 4.4.

The bring-up order

GICv3 initialisation splits into global work, done once by the boot PE, and per-PE work, done by every PE as it comes up (in TF-A, gicv3_distif_init() and then gicv3_rdistif_init() / gicv3_cpuif_enable() per core).

StepWhoRegistersWhy
1Each PE, EL3 then EL2 then EL1ICC_SRE_EL3, ICC_SRE_EL2, ICC_SRE_EL1Select the system-register CPU interface
2Boot PE, SecureGICD_CTLR.ARE_S, ARE_NS, DS; wait on RWPTurn on affinity routing (and decide the security model)
3Boot PEGICD_IGROUPR<n>, GICD_IGRPMODR<n>, GICD_IPRIORITYR<n>, GICD_ICFGR<n>, GICD_IROUTER<n>Configure each SPI before enabling it
4Boot PEGICD_CTLR.EnableGrp0/EnableGrp1NS/EnableGrp1S; wait on RWPLet the Distributor forward
5Each PE, SecureGICR_WAKER.ProcessorSleep = 0, poll ChildrenAsleep == 0Wake the Redistributor-to-CPU-interface link
6Each PESGI_base frame: GICR_IGROUPR0, GICR_IGRPMODR0, GICR_IPRIORITYR<n>, GICR_ICFGR1, GICR_ISENABLER0Configure SGIs and PPIs (timer, PMU, maintenance)
7Each PEICC_PMR_EL1, ICC_BPR*, ICC_CTLR_EL1/EL3, ICC_IGRPEN0_EL1, ICC_IGRPEN1_EL1 / ICC_IGRPEN1_EL3Unmask and enable groups at the CPU interface
8Each PESCR_EL3.IRQ/FIQ, HCR_EL2.IMO/FMO, PSTATE.{I,F}Exception routing and masking (3.3)

The order matters at two points. Group and routing configuration for an SPI should be written while the interrupt is disabled, because the GIC architecture does not guarantee when, or whether, a change to an enabled interrupt’s group, priority or routing takes effect for an instance that is already pending. And GICD_CTLR.ARE_* should be set while the Distributor group enables are still clear: changing ARE with groups enabled is not something the architecture makes predictable (see the GICD_CTLR description in IHI0069).

ICC_SRE_ELx: making the system registers reachable

ICC_SRE_ELx has SRE (bit 0), DFB (bit 1), DIB (bit 2) and, at EL3 and EL2 only, Enable (bit 3).

  • SRE = 1 selects the system-register interface for that EL. With SRE = 0, the EL uses the legacy memory-mapped GICC interface (if the implementation supports it at all; many GIC-600-class systems do not), and ICC_* accesses at that EL are UNDEFINED or trapped.
  • ICC_SRE_EL3.Enable = 1 lets EL2 access ICC_SRE_EL2; ICC_SRE_EL2.Enable = 1 lets EL1 access ICC_SRE_EL1. If the higher EL leaves Enable = 0, the lower EL’s access to its own ICC_SRE traps upward.
  • Write from the top down, with an ISB after each write. A write to ICC_SRE_ELx is a system-register write that later instructions only see after a context synchronization event (7.8); reading back SRE after the ISB confirms that the bit is not RAO/WI or RAZ/WI on this implementation.
    // EL3, per PE
    mrs     x0, ICC_SRE_EL3
    orr     x0, x0, #0xf          // Enable | DIB | DFB | SRE
    msr     ICC_SRE_EL3, x0
    isb
    mrs     x0, ICC_SRE_EL3
    tbz     x0, #0, sre_failed    // SRE stuck at 0: no system-register interface

Older assemblers need the encoded name (S3_6_C12_C12_5 for ICC_SRE_EL3). Linux’s boot protocol requires firmware to set ICC_SRE_EL3.SRE and ICC_SRE_EL3.Enable, and, if the kernel is entered at EL1, ICC_SRE_EL2.SRE and ICC_SRE_EL2.Enable too (a kernel entered at EL2 programs ICC_SRE_EL2 itself). If firmware skips this, the kernel traps or dies in early GIC probe.

GICD_CTLR: ARE and DS

The Secure view of GICD_CTLR holds EnableGrp0 (bit 0), EnableGrp1NS (bit 1), EnableGrp1S (bit 2), ARE_S (bit 4), ARE_NS (bit 5), DS (bit 6) and RWP (bit 31). The Non-secure view shows EnableGrp1 and EnableGrp1A in bits 0–1 and ARE_NS in bit 4.

  • ARE_S / ARE_NS. With affinity routing off, GICD_IROUTER<n> is unused and the legacy 8-target GICD_ITARGETSR model applies, which cannot address more than 8 PEs and does not exist at all for LPIs. A modern system sets both bits. Some implementations make them RAO/WI.
  • DS (Disable Security). With DS = 0 the GIC has two Security states: Secure-only registers and bits are RAZ/WI to Non-secure accesses, and Non-secure priority writes use the shifted view (4.3). With DS = 1 there is one Security state, all registers are accessible to any access, and Secure Group 1 does not exist. Once DS is 1 it can only be cleared by a hardware reset, and setting it while any group is enabled is UNPREDICTABLE. A system running TF-A with a Secure world must leave DS = 0.
  • RWP. Writes to GICD_CTLR and to GICD_ICENABLER<n> do not take effect immediately. Poll GICD_CTLR.RWP until it is 0 before relying on the new state; the per-Redistributor equivalent is GICR_CTLR.RWP for GICR_ICENABLER0 and GICR_CTLR.EnableLPIs.

GICR_WAKER: the per-PE gate

Every Redistributor powers up “asleep”. GICR_WAKER.ProcessorSleep (bit 1) is set at reset, and ChildrenAsleep (bit 2) reads 1 while the interface to the PE is quiescent. While ProcessorSleep = 1, the Redistributor does not forward interrupts to the CPU interface. If an interrupt targeting that PE becomes pending, the GIC asserts a wake request towards the power controller instead (the signal and what the power controller does with it are IMPLEMENTATION DEFINED).

Bring-up must clear ProcessorSleep and then poll until ChildrenAsleep reads 0. Clearing the bit only starts the handshake: until ChildrenAsleep = 0 the link is not guaranteed to be up, and interrupts can be held back. On power-down, the reverse sequence (set ProcessorSleep, poll ChildrenAsleep = 1) runs before the core is turned off (17.4). GIC-600 and later also have an IMPLEMENTATION DEFINED GICR_PWRR that must power up the Redistributor before GICR_WAKER responds at all; TF-A’s gic600 driver handles this.

When GICD_CTLR.DS = 0, GICR_WAKER is accessible only to Secure accesses. In a TF-A system the wake-up is therefore EL3’s job, in the PSCI CPU_ON and warm-boot path. A Non-secure OS that writes it sees no effect.

To find the right Redistributor, walk the frames from GICR_BASE and compare GICR_TYPER[63:32] (Affinity_Value, Aff3.Aff2.Aff1.Aff0) against MPIDR_EL1. Each frame is 128 KB (RD_base and SGI_base) in GICv3, and 256 KB if GICR_TYPER.VLPIS is set (GICv4). GICR_TYPER.Last (bit 4) marks the end of a contiguous region.

Group, enable, priority and PMR

For an interrupt to be signalled, every one of these must hold:

  1. Group. IGROUPR and IGRPMODR together select the group: (0,0) Group 0, (0,1) Secure Group 1, (1,0) Non-secure Group 1. The group decides whether the PE sees IRQ or FIQ in the current state (4.3). Getting it wrong does not lose the interrupt: it usually shows up as an FIQ taken to EL3 instead of an IRQ at EL1.
  2. Distributor group enable for that group in GICD_CTLR. This is not an SPI-only gate: with affinity routing, the group enables also govern forwarding of SGIs and PPIs held in the Redistributors, and EnableGrp1NS controls whether LPIs are forwarded.
  3. Interrupt enable: GICD_ISENABLER<n> for SPIs, GICR_ISENABLER0 for SGIs and PPIs, the LPI property table entry for LPIs.
  4. CPU interface group enable: ICC_IGRPEN0_EL1 or ICC_IGRPEN1_EL1 (with ICC_IGRPEN1_EL3.EnableGrp1NS/EnableGrp1S controlling both Security states from EL3).
  5. Priority higher than the mask. The interrupt is signalled only if its priority value is numerically lower than ICC_PMR_EL1 and higher than the running priority (ICC_RPR_EL1). ICC_PMR_EL1 resets to 0, which masks everything. An interrupt with priority 0xFF can never be signalled, whatever PMR is. Remember the Non-secure view: with DS = 0, a Non-secure write of 0xA0 to a priority register stores 0xD0.
  6. Exception masking and routing: PSTATE.I/F, and the SCR_EL3 / HCR_EL2 routing bits.

Configuration matters too. A level-sensitive SPI that is configured as edge (GICD_ICFGR) latches one pending edge and then never fires again if the line stays high across the acknowledge.

IROUTER, and an SPI routed to a powered-off core

GICD_IROUTER<n> (64-bit, at GICD_BASE + 0x6000 + 8n, valid for n ≥ 32) holds Aff3 [39:32], Aff2 [23:16], Aff1 [15:8], Aff0 [7:0] and Interrupt_Routing_Mode (bit 31).

  • IRM = 0 (targeted). The SPI goes only to the PE whose affinity matches exactly. If no Redistributor matches, because of a typo in the affinity or an MPIDR layout that differs from what the code assumed (for example MT = 1 cores, where Aff0 is the thread), the interrupt stays pending in the Distributor indefinitely.
  • IRM = 1 (1-of-N). The Distributor chooses any participating PE. Participation per group is controlled by GICR_CTLR.DPG0/DPG1NS/DPG1S, and GICD_TYPER.No1N = 1 means 1-of-N is not supported. Which PE is chosen is IMPLEMENTATION DEFINED.

A targeted SPI is not rerouted when its target is powered off. It stays pending. If that core went down through CPU_OFF with ProcessorSleep = 1, the GIC may raise a wake request. Whether the power controller acts on it for a core in the OFF state (as opposed to retention or suspend) is platform policy, and in many systems it does not. The interrupt then waits until the core comes back. Operating systems migrate SPI affinity away from a core before hot-unplug for this reason. In firmware-only stacks (FreeRTOS on one core, a secure partition on another), this is a common cause of interrupts that work until the first power transition.

Multi-chip GICs

The GICv3 architecture describes one logical GIC. A multi-chip or multi-chiplet system keeps that illusion with an IMPLEMENTATION DEFINED multichip scheme. On Arm’s GIC-600 and GIC-700 it is driven by GICD_CHIPSR, GICD_DCHIPR and GICD_CHIPR<n> at GICD_BASE + 0xC000, 0xC004 and 0xC008 + 8n. TF-A’s gic600_multichip_init() shows the required sequence:

  1. On the routing-table owner chip, check that the Distributor group enables and RWP are all clear, and that GICD_CHIPSR.RTS reports the disconnected state. Multichip configuration must come before any Distributor enable.
  2. Write the owner chip number into GICD_DCHIPR, polling GICD_DCHIPR.PUP (update in progress) before and after the write.
  3. For the owner first and then each other chip, write GICD_CHIPR<n> with that chip’s chip-to-chip address, the range of SPI blocks (blocks of 32 SPIs) it owns, and the socket-state bit that brings it online. Poll PUP around each write, read the register back, and check that RTS reports the consistent state.

The consequences for routing:

  • SPIs are owned by the chip whose block range contains them. The owning Distributor fragment holds their state, and delivering one to a PE on another chip is a chip-to-chip message. Overlapping or missing SPI ranges show up as SPIs that are pending on one chip and invisible on another.
  • SGIs and LPIs go to the target Redistributor through the same links. An ITS on chip 0 that translates an MSI for a collection whose target is a Redistributor on chip 1 sends the LPI across. The target is a physical address or a processor number, depending on GITS_TYPER.PTA (4.4), so the Redistributor map must already be consistent.
  • Affinity is not topology. IROUTER uses MPIDR affinity, and the mapping from affinity to die is a platform decision (17.5).

If a remote chip’s link is down or not yet configured, interrupts addressed there simply do not arrive. GIC-600/700 report this through IMPLEMENTATION DEFINED error records, not through anything in the GICv3 programmer’s model.

Checking state: walk backwards from the PE

When an interrupt does not arrive, check state in this order:

QuestionWhere to look
Is it pending at all?SPI: GICD_ISPENDR<n>. SGI/PPI: GICR_ISPENDR0 (SGI_base + 0x200) of the target PE. LPI: pending table bit (in memory, IMPLEMENTATION DEFINED caching)
Is it stuck active?GICD_ISACTIVER<n> / GICR_ISACTIVER0. An active interrupt with no EOI or deactivate blocks itself (4.2)
Is it enabled and in the right group?ISENABLER, IGROUPR, IGRPMODR
Is it routed to a live PE?GICD_IROUTER<n> vs MPIDR_EL1 of the target; that PE’s GICR_WAKER
Does the CPU interface see it?On the target PE: ICC_HPPIR0_EL1 / ICC_HPPIR1_EL1; a special INTID (1023, or 1020/1021 at EL3) means the highest-priority pending interrupt at this interface is not of that group, or nothing is pending
Is it masked?ICC_PMR_EL1, ICC_RPR_EL1, ICC_IGRPEN*, PSTATE.DAIF
Is it routed to another EL?SCR_EL3.IRQ/FIQ, HCR_EL2.IMO/FMO/TGE

Two active tests separate the source from the GIC. Writing the INTID’s bit in GICD_ISPENDR<n> (or GICR_ISPENDR0) makes it pending without the device: if that delivers, the GIC path is fine and the device or wire is at fault. For an SGI, ICC_SGI1R_EL1 from another PE tests Redistributor wake-up and the CPU interface without depending on any SPI configuration (the Distributor group enable still applies, and in GIC-600-class implementations the SGI message itself passes through the Distributor).

Bring-up note: In pre-silicon models, check the GIC configuration parameters (number of SPIs in GICD_TYPER.ITLinesNumber, Redistributor count, GICR_TYPER.Last) against the RTL. A Redistributor walk that runs off the end because Last is never set looks like a hang in early boot, not like an interrupt problem.

Validation note: For each interrupt source, test with a forced pending write (ISPENDR) and with a real device assertion. Then repeat both after a CPU_SUSPEND/CPU_OFF cycle of the target PE and, on multi-chip parts, with the target on each die. The usual failure is that an interrupt is delivered once and then never again. GICD_ISACTIVER shows a stuck-active interrupt (missing deactivate with EOImode = 1), and GICD_ISPENDR with an unchanged IROUTER points to a sleeping or offline target.

Checkpoint

Q4.5.1 In a TF-A + Linux system, a device SPI is enabled, Non-secure Group 1, priority 0xA0, and GICD_ISPENDR<n> shows it pending. Its GICD_IROUTER<n> (IRM = 0) names a core that Linux took offline with PSCI CPU_OFF a minute ago. What happens to the interrupt?

  • A. The Distributor reroutes it to another participating PE, because the target’s GICR_WAKER.ProcessorSleep is 1
  • B. It is discarded when the target Redistributor is powered off, so it needs to be retriggered
  • C. It stays pending in the Distributor. The GIC may request a wake-up for the target, and it is delivered only if and when that core is woken or the routing is changed
  • D. It is delivered to the boot PE, since affinity 0.0.0.0 is the default target for unroutable SPIs
Answer

C. With Interrupt_Routing_Mode = 0, the SPI is targeted at one affinity, and the GIC does not reroute it. Pending state is held in the Distributor regardless of the target’s power state. A wake request is raised towards the power controller, but whether an OFF core is woken by it is a platform decision. Option A describes 1-of-N routing (IRM = 1), which only chooses among participating PEs and is not a fallback for targeted SPIs. There is no default target (D), and pending state is not lost (B).

Read more: GICv3/4 (IHI0069), GICD_IROUTER<n> and power management (GICR_WAKER)

Q4.5.2 Warm-boot code in BL31 clears GICR_WAKER.ProcessorSleep and immediately enables ICC_IGRPEN1_EL3. On silicon, a PPI pending at that moment is sometimes delivered late, while on the FVP it never is. What is the most likely fix?

  • A. Poll GICR_WAKER.ChildrenAsleep until it reads 0 after clearing ProcessorSleep, and only then rely on delivery
  • B. Add a DSB SY after the GICR_WAKER write; the write was still buffered
  • C. Set GICD_CTLR.DS = 1 so that the Non-secure world can wake the Redistributor itself
  • D. Write ICC_PMR_EL1 before ICC_SRE_EL3
Answer

A. Clearing ProcessorSleep only starts the quiescence handshake between the Redistributor and the CPU interface, and ChildrenAsleep = 0 is the architectural signal that it has finished. Models often complete it instantly, which hides the missing poll. A DSB (B) makes the store complete at the Redistributor but does not wait for the handshake it starts, so the window remains. DS = 1 (C) removes the Security model and does not change the handshake. D is a misordering, because ICC_PMR_EL1 is not accessible through the system-register interface until SRE is set.

Read more: GICv3/4 (IHI0069), GICR_WAKER; TF-A gicv3_rdistif_mark_core_awake()

Q4.5.3 A new driver’s SPI never reaches its Linux handler, but EL3 starts logging unexpected FIQs at the same rate as the device’s interrupts. SCR_EL3.FIQ = 1. Which configuration error best explains this?

  • A. ICC_PMR_EL1 is 0 on the target core
  • B. GICD_CTLR.ARE_NS is 0, so the SPI uses legacy targeting
  • C. The SPI is configured edge-triggered while the device is level-sensitive
  • D. GICD_IGROUPR<n> and GICD_IGRPMODR<n> bits are both 0 for that INTID, so it is Group 0
Answer

D. Group 0 interrupts are always signalled as FIQ. With SCR_EL3.FIQ = 1 they are taken to EL3 whatever EL the PE is running at, which matches what EL3 sees. SPIs commonly reset to Group 0 in a GIC with two Security states (the reset value is implementation-specific, so check), and firmware that never sets the group bit for a new INTID produces exactly this. A PMR of 0 (A) would mask the interrupt completely, not move it to EL3. B and C affect whether and how often it is delivered, not which exception type it becomes.

Read more: GICv3/4 (IHI0069), interrupt grouping and GICD_IGROUPR<n>/GICD_IGRPMODR<n>; Arm ARM (DDI0487), SCR_EL3.FIQ

4.6 The Generic Timer

The Generic Timer has two halves: one system counter, a free-running count of system time that lives in an always-on domain outside the PEs, and per-PE timers, comparators built into each PE that read that count and raise a PPI. A system can also expose memory-mapped timer frames that raise SPIs and keep working while PEs are off. This section covers the programmer’s model. How to read the count without being caught by speculation, and the v8.6 changes, are in 4.7. Virtualizing the timer for guests is in 11.4.

The counter views

RegisterValueNotes
CNTPCT_EL0Physical countThe system count as broadcast to this PE (minus CNTPOFF_EL2 at EL0/EL1 when FEAT_ECV’s physical offset is enabled, see 4.7)
CNTVCT_EL0Physical count − CNTVOFF_EL2The offset applies to reads from EL1 and EL3, from EL0 unless HCR_EL2.{E2H,TGE} = {1,1}, and from EL2 only when E2H = 0. When EL2 is not implemented the offset is zero
CNTFRQ_EL0Counter frequency in HzInformational only; see below

The counter is at least 56 bits wide, with a roll-over time of no less than 40 years at its frequency. From Armv8.6 it is 64 bits and counts at 1 GHz (4.7). It must count monotonically and give a uniform view of time across all PEs. That requirement is easy on one die and much harder across chiplets.

CNTFRQ_EL0 does not set the frequency. It is a register that firmware writes so that software can read the frequency. Only the highest implemented EL can write it (EL3 in a TF-A system), and its reset value is architecturally UNKNOWN. Firmware takes the real value from the platform (the frequency of the entry in the CNTFID<n> table that it selected, see below) and writes it on every PE, including on warm boot if the register is not retained. A wrong CNTFRQ_EL0 does not stop timers. It makes every derived time value wrong by a constant factor: delays too short or too long, and a Linux clocksource with the wrong rate.

The per-PE timers

Each timer has the same three registers: CVAL (64-bit compare value), TVAL (32-bit signed down-counter view) and CTL.

TimerRegistersCounter comparedPresentTypical INTID (BSA)
EL1 physicalCNTP_CTL_EL0, CNTP_CVAL_EL0, CNTP_TVAL_EL0physicalalways30
EL1 virtualCNTV_*_EL0virtualalways27
Secure physical (EL3 / Secure EL1)CNTPS_*_EL1physicalwith EL329
Non-secure EL2 physicalCNTHP_*_EL2physicalwith EL226
Non-secure EL2 virtualCNTHV_*_EL2virtualFEAT_VHE28
Secure EL2 physicalCNTHPS_*_EL2physicalFEAT_SEL2see BSA
Secure EL2 virtualCNTHVS_*_EL2virtualFEAT_SEL2see BSA

The INTIDs are the Arm BSA recommendations, not architecture. Read them from the device tree or the ACPI GTDT rather than hard-coding them. The architecture defines each timer’s output as a PPI towards its own PE, so each PE has a private instance of every timer. With RME, the EL2 timers in Realm state and their naming are given in DDI0487’s Generic Timer chapter.

With HCR_EL2.E2H = 1, EL2 accesses to CNTP_*_EL0 and CNTV_*_EL0 are redirected to the EL2 timers (CNTHP_*, CNTHV_*). EL2 reaches the EL1 timers through the *_EL02 aliases. Code that runs at both EL1 and EL2 must allow for this.

CTL, CVAL and TVAL

CNTx_CTL holds ENABLE (bit 0), IMASK (bit 1) and ISTATUS (bit 2, read-only).

  • The timer condition is met when CVAL ≤ count, an unsigned 64-bit comparison against the counter the timer uses (physical or virtual).
  • ISTATUS reflects the condition while ENABLE = 1. The interrupt output is asserted while ENABLE = 1, ISTATUS = 1 and IMASK = 0.
  • Writing TVAL sets CVAL = count + SignExtend(TVAL). Reading TVAL returns (CVAL − count)[31:0], which goes negative after the deadline passes. Because TVAL is 32 bits, a 1 GHz counter cannot be programmed more than about 2.1 s ahead through TVAL. Program CVAL directly instead (Linux switched to CVAL for this reason).

The output is level-sensitive. Acknowledging and EOIing the PPI does not clear it, because the condition is still true. The handler must move CVAL forward, set IMASK, or clear ENABLE before EOI, or it re-enters immediately. Configure the PPI as level in GICR_ICFGR1 if that bit is programmable (4.5).

    // Arm the EL1 physical timer to fire 'x1' ticks from now, using CVAL
    mrs     x0, CNTPCT_EL0          // see 4.7 for the ordering needed here
    add     x0, x0, x1
    msr     CNTP_CVAL_EL0, x0
    mov     x0, #1                  // ENABLE=1, IMASK=0
    msr     CNTP_CTL_EL0, x0
    isb                             // make the new timer state take effect before continuing

Who may access what

ControlEffect
CNTKCTL_EL1.EL0PCTEN (bit 0) / EL0VCTEN (bit 1)EL0 reads of CNTPCT_EL0 / CNTVCT_EL0 (and CNTFRQ_EL0)
CNTKCTL_EL1.EL0VTEN (bit 8) / EL0PTEN (bit 9)EL0 access to the virtual / physical timer registers
CNTHCTL_EL2.EL1PCTEN / EL1PCEN (bits 0/1 when E2H = 0; bits 10/11 as EL1PCTEN/EL1PTEN when E2H = 1)EL1 and EL0 access to the physical counter and physical timer. A hypervisor clears these so guests use the virtual timer
SCR_EL3.ST (bit 11)When 0, Secure EL1 accesses to CNTPS_*_EL1 trap to EL3. When Secure EL2 is enabled, it behaves as 1

FEAT_ECV adds more CNTHCTL_EL2 traps (EL1TVT, EL1TVCT, EL1NVPCT, EL1NVVCT), covered in 4.7.

Security note: CNTPS is the Secure world’s own timer, so its existence or behaviour cannot be influenced by Non-secure software. OP-TEE and Secure Partitions that need a timeout should use it (or a Secure memory-mapped frame), not the Non-secure physical timer, which the normal world can reprogram. Leaving SCR_EL3.ST = 1 hands the Secure physical timer to Secure EL1. That is a deliberate TF-A choice, and the timer must still be configured as Group 0 or Secure Group 1 in the GIC.

CNTVOFF_EL2

CNTVOFF_EL2 is a 64-bit offset subtracted to form the virtual count. It is per PE: each PE has its own CNTVOFF_EL2, and a hypervisor must keep them identical for one VM, or a vCPU that migrates sees time jump. If EL2 is implemented but firmware enters EL1 directly, CNTVOFF_EL2 resets to an UNKNOWN value. EL3 must write it, normally to 0, before dropping to a Non-secure EL1 that uses the virtual counter. TF-A writes it to 0 as part of setting up an unused EL2 before the first exit to Non-secure EL1. Missing this gives a Linux kernel with a random but internally consistent clock on each core, and different values across cores.

The event stream

Each PE can generate a periodic event that sets its event register and so wakes WFE:

  • CNTKCTL_EL1.EVNTEN (bit 2), EVNTDIR (bit 3) and EVNTI (bits [7:4]) generate an event from the virtual count. EVNTI = n selects counter bit n, and EVNTDIR chooses whether a 0→1 or a 1→0 transition of that bit triggers it. An event is produced every 2^(n+1) counts.
  • CNTHCTL_EL2 has the same fields, applied to the physical count, for EL2’s use.
  • FEAT_ECV’s EVNTIS selects counter bits [23:8] instead of [15:0], which is needed at 1 GHz (4.7).

The event stream bounds the time any WFE can sleep. Linux enables it (about 10 kHz) so that WFE-based polling loops cannot hang if the expected SEV or exclusive-monitor clear never happens. Firmware spin-locks or hold pens that wait with WFE should not rely on the event stream unless they enable it themselves; they should rely on an explicit SEV (17.4).

The memory-mapped frames

The system counter and system-level timers are controlled through memory-mapped frames (DDI0487 part I). Base addresses are platform-defined.

CNTControlBase, the counter control frame. In a system with two Security states it is accessible only through the Secure physical address space.

OffsetRegisterPurpose
0x000CNTCREN (bit 0) counter enable, HDBG (bit 1) halt on debug, SCEN (bit 2) scaling enable with FEAT_CNTSC, FCREQ [17:8] selects the frequency-table entry
0x004CNTSRStatus, including FCACK (the acknowledged frequency entry) and DBGH
0x008CNTCVThe 64-bit count value; writable to set the initial count
0x010CNTSCRScale value (FEAT_CNTSC, 4.7)
0x020+CNTFID<n>Frequency modes table; CNTFID0 is the base frequency, the list ends with a zero entry

CNTReadBase gives a read-only view of CNTCV for the Non-secure world.

CNTCTLBase, the timer control frame, has CNTFRQ (the frequency value, Secure write), CNTNSAR (which frames Non-secure software can use), CNTTIDR (which frames exist and have a virtual timer), CNTACR<n> (per-frame access controls) and CNTVOFF<n> (virtual offset for frame n).

CNTBaseN and optionally CNTEL0BaseN are the timer frames. Each has its own CNTPCT, CNTVCT, CNTFRQ, CNTP_CVAL/TVAL/CTL and CNTV_*, with the same semantics as the system-register timers, but each signals an SPI and is shared by the whole system. They serve as wake-up timers for cores whose local timers are powered off (the Linux “broadcast” timer, and the BSA requirement for a system wake-up timer).

CNTCR.EN: the timer that never ticks

CNTCR.EN resets to 0. With it clear, the system counter does not count, CNTPCT_EL0 returns the same value on every read, and no timer condition ever changes. Reads still succeed, so nothing faults. On many SoCs the boot ROM or TF-A platform code enables it, typically with FCREQ = 0 (select CNTFID0). A new platform port that forgets it (18.3) hangs in the first udelay() or never takes a scheduler tick.

/* TF-A style: enable the system counter at the base frequency */
#define CNTCR_OFF    0x000
#define CNTCR_EN     (1U << 0)
#define CNTCR_FCREQ(x) ((uint32_t)(x) << 8)

mmio_write_32(PLAT_CNTCONTROL_BASE + CNTCR_OFF, CNTCR_FCREQ(0) | CNTCR_EN);
write_cntfrq_el0(mmio_read_32(PLAT_CNTCONTROL_BASE + 0x020)); /* CNTFID0 */

Bring-up note: Check four things in order: two reads of CNTPCT_EL0 differ (CNTCR.EN), CNTFRQ_EL0 matches the frequency of the clock that actually feeds the counter (measure against a wall clock or a known UART baud), CNTVOFF_EL2 is 0 on all cores if no hypervisor is running, and the timer PPI is Group 1 NS, enabled, level, and not masked by PMR on each core.

Checkpoint

Q4.6.1 A bare-metal EL1 timer handler acknowledges INTID 30 through ICC_IAR1_EL1, toggles an LED, writes ICC_EOIR1_EL1 and returns. The handler runs back-to-back forever after the first tick. What is wrong?

  • A. The PPI is configured as edge-triggered, so a new edge is latched at every EOI
  • B. The timer output is level-sensitive and stays asserted while ISTATUS = 1 and IMASK = 0. The handler must advance CVAL (or mask or disable the timer) before EOI
  • C. ICC_EOIR1_EL1 only drops priority; with EOImode = 0 a separate write to ICC_DIR_EL1 is needed
  • D. CNTKCTL_EL1.EVNTEN is set, so the event stream retriggers the interrupt
Answer

B. The timer condition CVAL ≤ count remains true after the deadline, so the PE’s timer keeps asserting its interrupt signal, and the GIC makes it pending again as soon as it is deactivated. Moving CVAL forward clears ISTATUS. An edge configuration (A) would give the opposite symptom, a single tick. With EOImode = 0 (C), ICC_EOIR1_EL1 performs both priority drop and deactivation. The event stream (D) generates WFE wake-up events, not interrupts.

Read more: Arm ARM (DDI0487), The Generic Timer: Operation of the timer, CNTP_CTL_EL0

Q4.6.2 TF-A boots Linux directly at Non-secure EL1 on a core that implements EL2. On each core, CNTPCT_EL0 values agree to within a few ticks, but CNTVCT_EL0 differs by large, apparently random amounts between cores, and Linux reports clock jumps on migration. Which firmware omission explains this?

  • A. CNTFRQ_EL0 was not written on the secondary cores
  • B. CNTKCTL_EL1.EL0VCTEN is 0
  • C. CNTCR.EN was set after the secondaries came up
  • D. CNTVOFF_EL2 was never initialised, so each PE subtracts its own UNKNOWN reset value
Answer

D. The virtual count is the physical count minus the per-PE CNTVOFF_EL2. When EL2 exists but is unused, EL3 must write it (normally 0) on every PE, or each core has its own arbitrary offset. A missing CNTFRQ_EL0 (A) misreports the rate but does not change the count. A late CNTCR.EN (C) would delay counting for all PEs equally, because they share one system counter. B only affects EL0 access.

Read more: Arm ARM (DDI0487), CNTVOFF_EL2 and CNTVCT_EL0

Q4.6.3 A platform wants a timeout to fire while every core in a cluster is powered off. Which timer can do this, and why?

  • A. A timer in a memory-mapped CNTBaseN frame, because it is in the system’s always-on domain and signals an SPI that can wake a core through the GIC
  • B. CNTPS_*_EL1, because the Secure physical timer is kept powered through CPU_OFF
  • C. CNTHP_*_EL2, because EL2 timer state is saved in the Redistributor
  • D. Any per-PE timer, as long as CNTKCTL_EL1.EVNTEN is set so the event stream keeps the core alive
Answer

A. All CNTP/CNTV/CNTPS/CNTHP-class timers are part of the PE and lose their state when the PE’s power domain is off. The memory-mapped timer frames are system components that compare against the always-on system counter and raise SPIs, which the GIC can turn into a wake request. B is the most tempting wrong answer, but the Secure world does not change which power domain the timer is in. The event stream (D) is also part of the PE and only generates WFE events.

Read more: Arm ARM (DDI0487), The Generic Timer memory-mapped components (CNTBaseN, CNTCTLBase); Arm BSA, system wake-up timer

4.7 Reading time correctly

MRS x0, CNTVCT_EL0 looks like the simplest instruction in the book. It is not a memory access, though, so none of the memory-ordering machinery of Part 7 applies to it. The PE is free to execute it early, late or speculatively unless you constrain it. This section covers the ordering rules, the FEAT_ECV registers that relax them, the Armv8.6 frequency change, counter scaling, and keeping one notion of time across chiplets. Register basics are in 4.6.

Why a counter read floats

DDI0487’s Generic Timer chapter states that reads of CNTPCT_EL0 (and CNTVCT_EL0) can occur speculatively and out of order relative to other instructions executed on the same PE. Two consequences follow:

  1. Barriers do not order it. DMB orders memory accesses against memory accesses (7.5). A counter read is a system-register read, so a DMB between a load and an MRS CNTVCT_EL0 constrains nothing. Acquire and release semantics (7.7) also only order memory accesses.
  2. The value can predate the code around it. An out-of-order core can sample the counter before older loads have returned, or before an older branch has resolved. A timestamp “after” an event can then hold a time before it.

Current issues of DDI0487 do guarantee that reads of CNTVCT_EL0 and CNTVCTSS_EL0 occur in program order relative to each other, so two back-to-back reads on one PE do not go backwards. They give no ordering against anything else.

Ordering a read after earlier instructions: ISB

The Arm ARM’s own example is the fix. If a load from memory obtains a signal that the counter must now be read, an ISB between the two makes the counter read occur after the signal has been read. The ISB is a context synchronization event (7.8): instructions after it are fetched and executed only after it completes, so the MRS cannot be hoisted above it.

1:  ldar    w0, [x1]            // observe "start" flag from another PE
    cbz     w0, 1b
    isb                         // counter read cannot be performed before this point
    mrs     x2, CNTVCT_EL0

ISB does not wait for earlier stores to complete. If you want the time at which an MMIO write has completed (for example, timing a device’s response), you need DSB to wait for completion (7.6), then ISB, then the read:

    str     w3, [x4]            // doorbell to Device memory
    dsb     sy                  // store has completed
    isb
    mrs     x5, CNTPCT_EL0

Ordering a read before later loads: the Linux dependency trick

The other direction is harder. In a seqlock reader, such as the Linux vDSO clock_gettime(), the counter must be read inside the critical section. That means before the re-read of the sequence count that validates it. A later load can be satisfied before the counter read has executed, and no barrier instruction orders a system-register read before a later load. Linux therefore turns the counter value into an address dependency:

/* arch/arm64/include/asm/arch_timer.h (abridged) */
#define arch_counter_enforce_ordering(val) do {         \
        u64 tmp, _val = (val);                          \
        asm volatile(                                   \
        "       eor     %0, %1, %1\n"   /* tmp = 0, but depends on val */ \
        "       add     %0, sp, %0\n"                   \
        "       ldr     xzr, [%0]"      /* dummy load from the stack */   \
        : "=r" (tmp) : "r" (_val));                     \
} while (0)

static __always_inline u64 __arch_counter_get_cntvct(void)
{
        u64 cnt;
        asm volatile(ALTERNATIVE("isb\n mrs %0, cntvct_el0",
                                 "nop\n" __mrs_s("%0", SYS_CNTVCTSS_EL0),
                                 ARM64_HAS_ECV) : "=r" (cnt));
        arch_counter_enforce_ordering(cnt);
        return cnt;
}

The dummy LDR cannot be issued until the counter value exists, because its address depends on it. The seqlock’s smp_rmb() (a DMB ISHLD) then orders the dummy load before the sequence re-read. Together they order the counter read before the re-read. The construction relies on the dependency rules of 7.4: a register data dependency through EOR x, v, v still counts, even though the result is always zero. A second ISB after the read would also work, at a higher cost on every clock_gettime().

NeedSequence
Read after an earlier load or branchISB ; MRS
Read after an earlier store has completedDSB ; ISB ; MRS
Read before a later loadMRS ; address dependency into the load (or ISB)
Timer write takes effect before continuingMSR CNTx_CVAL/CTL ; ISB
Elapsed-time measurement of a code regionISB ; MRS t0 ; ... ; ISB ; MRS t1 (add DSB before the second ISB if memory side effects must be included)

Bring-up note: A missing ISB rarely shows up on in-order cores or functional models such as QEMU, which treat system registers as self-synchronizing. It shows up on wide out-of-order cores as occasional negative deltas, or as time that runs backwards across a seqlock retry. Test timing code on the real core or on a cycle-accurate model.

FEAT_ECV

FEAT_ECV (Enhanced Counter Virtualization) is mandatory from Armv8.6: ID_AA64MMFR0_EL1.ECV = 0b0000 is not permitted from v8.6. The field has two levels: 0b0001 gives the self-synchronized registers, the extra traps and EVNTIS, and 0b0010 adds CNTPOFF_EL2, CNTHCTL_EL2.ECV and SCR_EL3.ECVEn. Recent DDI0487 issues name the second level FEAT_ECV_POFF; see A2 for its permitted/mandatory status.

CNTPCTSS_EL0 and CNTVCTSS_EL0

These are self-synchronized views of the physical and virtual counts. A read returns a value consistent with the counter not having been read until the MRS was known to be non-speculative, and the read appears to occur in program order relative to other instructions, without an ISB. This replaces the leading ISB, which is why Linux patches the isb to nop when FEAT_ECV is present.

The ordering against later loads is a separate problem, and the self-synchronized read does not solve it. A younger load may still be satisfied early. Linux keeps arch_counter_enforce_ordering() after CNTVCTSS_EL0 for that reason. EL0 can test for the register through the HWCAP2_ECV bit, and EL0 access is controlled by the same CNTKCTL_EL1.EL0VCTEN/EL0PCTEN bits as the plain registers.

CNTPOFF_EL2

CNTPOFF_EL2 is a physical offset, the physical counterpart of CNTVOFF_EL2. When SCR_EL3.ECVEn = 1 and CNTHCTL_EL2.ECV = 1, the physical count seen by EL0 and EL1 (both CNTPCT_EL0 reads and the EL1 physical timer’s comparison) is reduced by CNTPOFF_EL2. It is not applied at EL2 or EL3, or at EL0 when HCR_EL2.{E2H,TGE} = {1,1}. A hypervisor can then give a guest a consistent physical and virtual view of time after migration, instead of trapping every physical counter access.

EL3 controls access: with SCR_EL3.ECVEn (bit 28) = 0, EL2 accesses to CNTPOFF_EL2 trap to EL3 and the offset is treated as zero for everything except direct accesses from EL3. In TF-A this is ENABLE_FEAT_ECV (17.3).

The extra CNTHCTL_EL2 traps

CNTHCTL_EL2.EL1TVT (bit 13) traps EL0 and EL1 accesses to the EL1 virtual timer registers, EL1TVCT (bit 14) traps EL0 and EL1 accesses to CNTVCT_EL0/CNTVCTSS_EL0 (neither applies when HCR_EL2.{E2H,TGE} = {1,1}), and EL1NVPCT/EL1NVVCT serve nested virtualization. All are described in 11.2 and 11.4.

EVNTIS

CNTKCTL_EL1.EVNTIS and CNTHCTL_EL2.EVNTIS (bit 17 in both) make EVNTI select a bit from counter bits [23:8] instead of [15:0]. At 1 GHz, bit 15 gives one event every 2^16 ns ≈ 65.5 µs at most, which is shorter than the 100 µs Linux targets. With EVNTIS, periods up to about 16.8 ms are possible.

The 1 GHz counter from v8.6 / v9.1

From Armv8.6 (and so Armv9.1), the system counter is required to be 64 bits wide and to count at 1 GHz. CNTFRQ_EL0 should therefore read 1,000,000,000 on any such system. This is architecturally the effective frequency. The physical implementation can update at a lower rate and increment by more than 1 per update. Several consequences follow:

  • Resolution is not 1 ns. Two reads a few nanoseconds apart can return the same value, and deltas come in multiples of the update increment. Do not treat CNTVCT deltas as cycle-accurate. Use the PMU cycle counter for that (16.3).
  • Wrap-around maths changes. Software that assumes the minimum 56-bit width reaches its wrap point after about 2.3 years at 1 GHz (2^56 ns), well within a product’s uptime, and Linux had to fix its clocksource masking for high-frequency counters. A full 64-bit count at 1 GHz wraps after about 584 years.
  • TVAL reaches only about 2.1 s ahead, so use CVAL (4.6).
  • Pre-v8.6 cores in the same system (for example a v8.2 management core beside v9 application cores) must see the same counter, so the system counter must run at 1 GHz for everyone. Check old firmware that hard-codes 24, 50 or 100 MHz.

FEAT_CNTSC: counter scaling

The cheap way to produce an effective 1 GHz count from a lower-frequency reference (say, a 50 MHz crystal) is to add a scaled increment per tick. FEAT_CNTSC provides this in the system counter:

  • CNTID.CNTSC = 0b0001 indicates support. CNTSCR sits at CNTControlBase + 0x010 (Secure only).
  • CNTSCR.ScaleVal is an unsigned fixed-point value with 8 integer and 24 fractional bits. With CNTCR.SCEN = 1, the counter adds ScaleVal on every tick. With SCEN = 0 it adds 0x1.000000, which is 1.
  • ScaleVal and SCEN can only be changed while CNTCR.EN = 0. Changing either while enabled makes the count UNKNOWN, and it stays UNKNOWN on later ticks.

For 50 MHz → 1 GHz, ScaleVal = 20.0 = 0x14000000, which is exact. For a 26 MHz reference, 1e9/26e6 = 38.4615… is not exactly representable in 2^-24 steps, and the rounding error drifts the count by parts per billion. That is negligible against crystal tolerance, but every die must use the identical ScaleVal, or their counters diverge steadily. The architecture version that FEAT_CNTSC is permitted from is listed in DDI0487 A2.

Keeping counters synchronized across chiplets

The architecture requires the system counter to provide a uniform view of system time to all PEs. Software relies on a stronger, practical property: if PE A reads time t1 and passes it to PE B, and B, ordered after observing it, reads t2, then t2 ≥ t1. The Linux scheduler, clock_gettime() across thread migration, and trace timestamps all assume it.

On one die this is achieved by distributing a single counter’s value to all PEs. Across dies there are two common schemes, both IMPLEMENTATION DEFINED:

SchemeHowBring-up obligations
One counter, distributedA master die’s counter value (often Gray-coded or interpolated, as with CoreSight timestamp distribution) is sent over the die-to-die linkLink latency must be compensated. The link must be up before any die reads time
One counter per die, synchronizedShared reference clock; each die’s CNTCV written with the same value and CNTCR.EN set by a simultaneous hardware triggerSame CNTFID/FCREQ and ScaleVal everywhere. A die that is reset or power-cycled alone must be resynchronized, not just re-enabled

Writing CNTCV and then setting EN from software on each die in turn leaves a skew equal to the software’s latency between the dies. That can be microseconds, which is far more than the cross-die message latency, so the monotonicity property above breaks. Skew only has to stay below the minimum one-way communication latency between PEs. The test for it is therefore a communication test, not a comparison of counter values. Frequency changes (FCREQ) must also be coordinated across dies. See 17.5 for where this fits in the bring-up order.

Validation note: Run a cross-die ping-pong. PE A executes ISB; MRS CNTVCT_EL0 and publishes the value with STLR. PE B waits with LDAR, then ISB; MRS CNTVCT_EL0, and checks t2 ≥ t1. Then swap roles. Run it for hours, across every die pair, across die-level power transitions and frequency mode changes. A failure with correct barriers means counter skew. A failure that disappears when you add the ISBs means the test itself was wrong. Also log t2 − t1 both ways: an asymmetric minimum shows the skew directly.

Checkpoint

Q4.7.1 A latency test on PE B does ldar w0, [flag] in a loop until it is non-zero, then immediately mrs x1, CNTVCT_EL0. PE A wrote the flag with stlr after recording its own timestamp t1. Occasionally x1 < t1, even on a single die. What is the correct fix?

  • A. Replace LDAR with LDR followed by DMB ISH, so the counter read is ordered after the flag load
  • B. Nothing is wrong in the code, because a single die’s counter is always consistent, so this must be a hardware erratum
  • C. Insert an ISB between the LDAR loop and the MRS, because acquire semantics only order later memory accesses, and a counter read is not one
  • D. Insert a DSB ISH after PE A’s STLR
Answer

C. Counter reads can be performed speculatively and out of order relative to other instructions. LDAR orders later memory accesses after it, so the MRS can execute speculatively before the loop has exited. The Arm ARM gives exactly this pattern (a signal read from memory, then ISB, then the counter read). DMB (A) also orders only memory accesses. A DSB on PE A (D) does not constrain when PE B samples the counter. B blames hardware for a software ordering bug.

Read more: Arm ARM (DDI0487), The Generic Timer, reading CNTPCT_EL0 and CNTVCT_EL0 (speculation and ordering)

Q4.7.2 On FEAT_ECV hardware, Linux reads CNTVCTSS_EL0 without a leading ISB but still executes the eor/add/ldr xzr sequence after it. Why is the trailing sequence still needed?

  • A. CNTVCTSS_EL0 is only self-synchronizing at EL1, so the vDSO at EL0 needs extra ordering
  • B. Self-synchronization constrains when the counter is sampled relative to earlier instructions, but a later load (the seqlock re-read) can still be satisfied before the counter read; the address dependency plus smp_rmb() prevents that
  • C. The dummy load flushes the counter value from the PE’s register cache to memory
  • D. Without it, CNTVCTSS_EL0 reads may return values that go backwards relative to an earlier CNTVCTSS_EL0 read on the same PE
Answer

B. The self-synchronized view removes the need for the ISB before the read. Linux uses the dependency to order the read against later loads, which no barrier can do for a system-register read. The dummy load’s address depends on the counter value, and DMB ISHLD orders that load before the sequence re-read. D is tempting, but reads of CNTVCT_EL0/CNTVCTSS_EL0 are already in program order relative to each other. A and C are not architectural behaviours.

Read more: Arm ARM (DDI0487), CNTVCTSS_EL0; Linux arch/arm64/include/asm/arch_timer.h

Q4.7.3 A two-die SoC passes the cross-die ping-pong test from die 1 to die 0, but from die 0 to die 1 about 0.1% of iterations have t2 < t1 by roughly 300 ns. The test uses STLR/LDAR and an ISB before each counter read. Firmware enables each die’s counter by writing CNTCV then CNTCR.EN from the boot PE, die 0 first. What does the result indicate?

  • A. Die 0’s counter is ahead of die 1’s by more than the die 0 → die 1 message latency, a skew introduced by the sequential software enable. The fix is a synchronized hardware start (or distribution from one counter), not more barriers
  • B. The test is missing a DSB before each counter read
  • C. Die 0’s CNTFRQ_EL0 is programmed differently from die 1’s
  • D. The ISB cannot order a counter read after an LDAR, so PE B still samples the counter before it sees the flag
Answer

A. A one-directional failure is the signature of a constant offset. A message from the die that is ahead to the die that is behind can arrive at an earlier counter value whenever the skew exceeds the one-way latency, while the reverse direction always passes. Die 0 was enabled first, so it has been counting longer and is ahead by roughly the software latency between the two enables. Barriers cannot remove a skew between two counters (B). The test’s barriers are already sufficient: the Arm ARM’s own pattern for ordering a counter read after a memory read is ISB (D). CNTFRQ_EL0 (C) is only informational and does not change the count.

Read more: Arm ARM (DDI0487), The Generic Timer: the system counter; platform system counter integration documentation

Part 5: Virtual memory I: translation structure

Prerequisites: 2.1 Exception levels, Security states and execution states and 2.5 System registers; 3.2 Entry and return for ESR/FAR before reading 5.8. If you already know: how to walk a 4K table by hand and decode a Data Abort ESR, skim 5.1–5.4, and read 5.5 onward for PIE/POE, hardware AF/dirty management, LPA2/D128 and the AT-based debugging lab. Why this matters for bring-up/validation: the first instruction after SCTLR_ELx.M = 1 is where a firmware image most often dies silently, and every one of those failures is a mismatch between the registers in this part and the tables in memory.

This part covers the static side of address translation: what a translation regime is, how TCR_ELx and TCR2_ELx shape it, what the descriptors contain, how the walker steps through them, and what the permission and access-flag bits mean. It starts with regimes and stages (5.1), because “which tables did this access actually use?” is the first question in any translation bug. Then come the controls (5.2), the descriptor formats, starting levels, contiguous runs and stage-2 concatenation (5.3), and a full walk worked by hand, including a fault (5.4).

The second half adds the layers on top of the basic format. 5.5 covers direct and hierarchical permissions, PAN/EPAN, permission indirection and overlays. 5.6 covers hardware Access flag and dirty-state management and how those updates interact with the memory model. 5.7 covers 52- and 56-bit addressing, including the 128-bit descriptors. The part closes with fault decoding (5.8) and a lab that uses AT and PAR_EL1 to debug translation on QEMU and the FVP (5.9). Changing live translations (TLB maintenance, break-before-make, turning the MMU on) is Part 9, and memory attributes are Part 6.

5.1 Translation regimes and stages

A translation regime is the complete set of controls that maps an address issued by a PE to a physical address: one or two stages, the registers that configure each stage, the TLB tagging (ASID, VMID) and the ELs whose accesses use it. You debug a translation problem by first naming the regime the faulting access used. Most “the MMU is broken” reports turn out to be “the access used a different regime from the one I programmed”.

Stages and address spaces

  • Stage 1 maps a virtual address (VA) to an output address. If no stage 2 applies, the output is a physical address (PA). Otherwise it is an intermediate physical address (IPA).
  • Stage 2 maps an IPA to a PA. It is owned by EL2 and exists only in the EL1&0 regime, and only while EL2 is enabled in the current Security state and HCR_EL2.VM is 1. Stage 2 is covered in depth in 11.3.

Stage 1 can also be disabled (SCTLR_ELx.M == 0). The VA then maps flat to the output address, with the fixed memory attributes described in 6.5. A disabled stage still checks address size. A VA above the implemented PA size gives an Address size fault, not a wrap.

Every stage 1 table-walk access is itself an IPA when stage 2 is active, so the walker translates each descriptor address through stage 2. If a stage 2 fault hits on one of those accesses, ESR_EL2.ISS.S1PTW is 1 (decode in 5.8). In the worst case, 4 stage-1 levels nested in 4 stage-2 levels take (4+1)×(4+1)−1 = 24 memory accesses for one TLB miss.

The regimes

RegimeUsed byStagesVA rangesStage-1 registersTLB tag
EL1&0EL1, and EL0 when not (E2H==1 && TGE==1)1, plus stage 2 if EL2 is enabled and HCR_EL2.VM==1Two: TTBR0_EL1 (low), TTBR1_EL1 (high)SCTLR_EL1, TCR_EL1, TCR2_EL1, MAIR_EL1ASID (+ VMID when EL2 is enabled)
EL2EL2 with HCR_EL2.E2H==01One: TTBR0_EL2SCTLR_EL2, TCR_EL2, TCR2_EL2, MAIR_EL2None: entries are global
EL2&0 (FEAT_VHE, v8.1)EL2 with E2H==1; EL0 with E2H==1 && TGE==11Two: TTBR0_EL2, TTBR1_EL2SCTLR_EL2, TCR_EL2 (VHE layout), TCR2_EL2, MAIR_EL2ASID
EL3EL31One: TTBR0_EL3SCTLR_EL3, TCR_EL3, MAIR_EL3None
Stage 2 of EL1&0(applies to EL1&0)2One IPA spaceVTTBR_EL2, VTCR_EL2; Secure: VSTTBR_EL2, VSTCR_EL2 (FEAT_SEL2, v8.4)VMID

Each regime exists separately in each Security state where its ELs exist. The Arm ARM names them that way: “Secure EL1&0”, “Non-secure EL2&0”, “Realm EL1&0” and so on. With FEAT_RME, EL3 runs in Root state and its regime is the only Root regime. Realm EL1&0 uses VTTBR_EL2/VTCR_EL2 for its stage 2, like Non-secure (Realm EL2 itself has only stage 1). The physical address space an output address lands in (Secure, Non-secure, Root, Realm) is chosen by the regime’s Security state together with the descriptor NS/NSTable bits, and with RME also NSE. That mechanism is in 12.1 and 12.4.

The two-range regimes split the VA space. Addresses with the top bits all 0 use TTBR0, and addresses with the top bits all 1 use TTBR1. The size of each range is set by T0SZ/T1SZ (5.2). An address in the hole between the two ranges takes a Translation fault without any table walk (5.8 covers the level it reports). The single-range regimes (EL2 without VHE, EL3) have only the low range. Any VA whose top bits are not 0 faults, after any top-byte-ignore (13.3).

Which regime does an access use?

The regime is chosen by the EL the access is made for, not always the current EL. Use this decision procedure:

access at EL3                          -> EL3 regime
access at EL2:   HCR_EL2.E2H == 1      -> EL2&0 regime
                 HCR_EL2.E2H == 0      -> EL2 regime
access at EL1                          -> EL1&0 regime (+ stage 2 if EL2 enabled and VM==1)
access at EL0:   E2H == 1 && TGE == 1  -> EL2&0 regime
                 otherwise             -> EL1&0 regime

Some details change which regime applies, or how it applies:

  • HCR_EL2.TGE == 1 with E2H == 0. EL0 still uses EL1&0, but stage 1 behaves as if SCTLR_EL1.M were 0 (for every purpose except reading it back). With HCR_EL2.VM == 0 as well, EL0 addresses map flat to PAs. This lets a non-VHE EL2 kernel run EL0 code, but only without a stage 1 of its own, which is why the configuration is rarely useful. (Non-VHE KVM does not use it: its host kernel runs at EL1 with TGE == 0.) VHE (E2H=1, TGE=1) exists so that host EL0 gets a real stage 1 in the EL2&0 regime. See 11.2.
  • Unprivileged loads and stores (LDTR*/STTR*, and the unprivileged CPY*/SET* forms of FEAT_MOPS) at EL1 use the EL1&0 regime with EL0 permissions. At EL2 with E2H==1 && TGE==1, they use the EL2&0 regime with EL0 permissions. At EL3, and at EL2 otherwise, they behave like ordinary accesses. Permission details are in 5.5.
  • Address translation instructions name their regime explicitly: AT S1E1R walks EL1&0 stage 1, AT S12E1R walks both EL1&0 stages, and AT S1E3R walks EL3. EL3 firmware can therefore probe a lower regime without switching to it. See the lab in 5.9.
  • Instruction fetches and data accesses use the same regime. Separate permission bits apply (5.5), but there are no separate tables.
  • E2H may be fixed. On implementations that do not support HCR_EL2.E2H == 0, E2H is RES1 and the EL2 (non-VHE) regime never exists. Discovery is through ID_AA64MMFR4_EL1.E2H0 (FEAT_E2H0; for the version, see DDI0487 A2). Firmware that assumes it can run EL2 code with E2H=0 breaks on such cores.
  • Non-PE masters (DMA engines, GPUs) do not use any PE translation regime. Their translation goes through the SMMU, which has its own stage 1/stage 2 configuration that mirrors these formats (11.5).

Bring-up note: A TF-A BL31 image runs in the EL3 regime with TTBR0_EL3 only. The BL33/UEFI it hands off to starts in EL2 (or EL1), with SCTLR_EL2.M == 0, so it has no translation at all. When BL31 later handles an SMC from the normal world, a pointer the caller passes in is a normal-world VA. EL3 cannot dereference it through its own regime. It must either be given a PA, or translate it with AT S12E1R/AT S1E2R and then check the PA space (5.9).

Registers per regime: what is shared and what is not

MAIR_ELx, TCR_ELx, TCR2_ELx and SCTLR_ELx are per regime, not per VA range. Both halves of the EL1&0 regime share one MAIR_EL1 and one SCTLR_EL1. TCR_EL1 holds separate fields for the two halves (T0SZ/T1SZ, TG0/TG1, EPD0/EPD1 and so on). With VHE, TCR_EL2 changes layout to match TCR_EL1, and the _EL12/_EL02 aliases let EL2 reach the real EL1&0 registers while E2H==1 redirects plain _EL1 names to their EL2 counterparts (2.5).

TLB entries are tagged by regime. Changing HCR_EL2.TGE does not invalidate anything. Entries from one regime are not used for lookups in another, but they remain until invalidated. (E2H is in practice set once at boot and not toggled at run time; KVM flips TGE, never E2H. Firmware that does change E2H should invalidate the EL2 entries.) and TLBI operations also name their regime (TLBI VAE1, VAE2, VAE3; VAE2 targets EL2 or EL2&0 according to the current E2H). Invalidation is in 9.1.

Validation note: Regime selection is a good place to look for RTL bugs, because the selection depends on several dynamic inputs (current EL, E2H, TGE, VM, Security state). A directed test programs disjoint tables for EL1&0 and EL2&0 so that the same VA maps to different PAs, then runs the same EL0 load with each combination of {E2H, TGE} and checks which PA was read. On the FVP, the Tarmac trace shows the physical address each load used. In QEMU, -d mmu does not log VMSA walks (it logs only PMSA/MPU lookups), so check the value read, or use gva2gpa in the monitor and AT in the test. On silicon, the PMU events DTLB_WALK (0x0034) and L1D_TLB_REFILL (0x0005) confirm that a walk happened, and the value read identifies the regime used.

Checkpoint

Q5.1.1 A hypervisor runs with HCR_EL2.E2H == 1, HCR_EL2.TGE == 0. A guest EL0 application executes LDR x0, [x1]. Which translation applies?

  • A. EL2&0 stage 1 only, because E2H is set
  • B. EL1&0 stage 1 only, because stage 2 is disabled while E2H == 1
  • C. EL1&0 stage 1, then stage 2 if HCR_EL2.VM == 1
  • D. EL2&0 stage 1, then stage 2
Answer

C. EL0 uses the EL2&0 regime only when both E2H and TGE are 1. With TGE == 0, this is a guest EL0, which uses EL1&0, with stage 2 controlled by HCR_EL2.VM. Option A is the tempting mistake: E2H alone changes the regime used by EL2 itself, not by EL0.

Read more: Arm ARM (DDI0487), “Translation regimes” in the AArch64 Virtual Memory System Architecture chapter; HCR_EL2.E2H, HCR_EL2.TGE

Q5.1.2 EL3 firmware receives an SMC whose argument is a Non-secure EL1 VA. Which approach is architecturally sound for EL3 to find the corresponding PA?

  • A. Execute AT S12E1R with the VA (with the lower EL’s translation registers still live), ISB, then read PAR_EL1
  • B. Dereference the VA directly, because EL3 can always access lower-EL mappings
  • C. Execute AT S1E3R with the VA, because EL3 regime tables include all lower-EL mappings
  • D. Temporarily write TTBR0_EL3 with the value of TTBR0_EL1 and dereference the VA
Answer

A. AT S12E1R walks both stages of the EL1&0 regime using that regime’s current registers, and leaves the result in PAR_EL1 after a context synchronization event. From EL3, the Security state walked is the one selected by SCR_EL3.NS (and NSE with RME), so NS must be 1 to probe the Non-secure regime. Option D looks clever but is wrong: EL3 descriptors use the single-range format, TCR_EL3 differs from TCR_EL1, the VA may be in the TTBR1 range, and stage 2 would be skipped. Option C uses EL3’s own tables, which know nothing of the caller’s mappings.

Read more: Arm ARM (DDI0487), “Address translation instructions”; PAR_EL1

Q5.1.3 Software clears HCR_EL2.TGE while running at EL2 with E2H == 1, then immediately ERETs to a guest EL1 without any TLB invalidation. What do the TLB entries left over from host EL0 mean for the guest?

  • A. The guest may hit them, because host EL0 and guest EL0 share ASIDs
  • B. The change of TGE invalidates all EL2&0 entries automatically
  • C. It is CONSTRAINED UNPREDICTABLE which regime’s entries are used
  • D. They are tagged as EL2&0 regime entries and cannot be used for EL1&0 lookups, although they stay in the TLB
Answer

D. TLB entries are associated with a translation regime (and with ASID/VMID within it), and a lookup for one regime never matches entries of another. Nothing is invalidated automatically (so B is wrong), but stale entries do no harm across regimes. Option A confuses ASID tagging inside one regime with tagging across regimes.

Read more: Arm ARM (DDI0487), “Translation Lookaside Buffers (TLBs)”, “TLB maintenance”

5.2 TCR_ELx and TCR2_ELx

TCR_ELx sets the shape of a regime’s translation: how large each VA range is, which granule each range uses, how large the output addresses may be, and with what memory attributes the walker reads descriptors. TCR2_ELx (FEAT_TCR2) is the extension register that newer translation features are enabled from. The descriptors themselves are in 5.3.

Layouts

TCR_EL1 and the VHE form of TCR_EL2 (E2H == 1) have two sets of fields, one per VA range. TCR_EL3 and the non-VHE TCR_EL2 have one set and a different layout:

FieldTCR_EL1 bitsTCR_EL3 / TCR_EL2 (E2H=0) bitsMeaning
T0SZ[5:0][5:0]Size offset of the low (TTBR0) range: VA size = 64 − T0SZ
EPD0[7]–Disable walks for TTBR0 on a TLB miss
IRGN0/ORGN0/SH0[9:8]/[11:10]/[13:12]sameWalk attributes for TTBR0 walks
TG0[15:14][15:14]TTBR0 granule: 00=4K, 01=64K, 10=16K
T1SZ[21:16]–Size offset of the high (TTBR1) range
A1[22]–ASID comes from TTBR1_EL1 (1) or TTBR0_EL1 (0)
EPD1[23]RES1 at [23]Disable walks for TTBR1
IRGN1/ORGN1/SH1[25:24]/[27:26]/[29:28]–Walk attributes for TTBR1 walks
TG1[31:30]RES1 at [31]TTBR1 granule: 01=16K, 10=4K, 11=64K (different encoding!)
IPS / PSIPS [34:32]PS [18:16]Output address size
AS[36]–16-bit ASIDs (if ID_AA64MMFR0_EL1.ASIDBits allows)
TBI0/TBI1[37]/[38]TBI [20]Top byte ignored (13.3)
HA/HD[39]/[40][21]/[22]Hardware AF/dirty update (5.6)
HPD0/HPD1[41]/[42]HPD [24]Disable hierarchical permissions (FEAT_HPDS, v8.1)
HWU*[50:43][28:25]Descriptor bits 59–62 usable by hardware, IMPLEMENTATION DEFINED (FEAT_HPDS2)
TBID0/TBID1[51]/[52]TBID [29]TBI for data accesses only (FEAT_PAuth)
NFD0/NFD1[53]/[54]–SVE non-fault accesses fault without a walk
E0PD0/E0PD1[55]/[56]–EL0 access to the range faults without a walk (FEAT_E0PD, v8.5)
TCMA0/TCMA1[57]/[58]TCMA [30]MTE match-all tag (13.5)
DS[59][32]52-bit with 4K/16K (FEAT_LPA2, 5.7)

Note the RES1 bits. TCR_EL3 and non-VHE TCR_EL2 have bits [31] and [23] RES1, and TF-A defines TCR_EL3_RES1 for them. Note also that TG0 and TG1 use different encodings for the same granule. Copying a TG0 value into TG1 gives the wrong granule or a reserved value (4K 00 becomes reserved, 64K 01 becomes 16K, 16K 10 becomes 4K). This is a classic bring-up bug: TG1 = 00 is reserved, and a reserved value is treated as an IMPLEMENTATION DEFINED choice among the implemented granules, so the behaviour differs between a model and silicon.

T0SZ, T1SZ: the input address size

The low range covers VAs 0 to 2^(64−T0SZ) − 1. The high range covers 2^64 − 2^(64−T1SZ) to 2^64 − 1. T0SZ = 16 gives the familiar 48-bit range. The size, together with the granule, fixes the starting level of the walk and the size of the first table (5.3). Programming T0SZ and the table layout from different assumptions is the commonest root cause of a level-0 Translation fault right after SCTLR_ELx.M is set.

Limits:

  • The minimum TxSZ is 16 (48-bit), or 12 (52-bit) with FEAT_LVA for 64K, or with DS == 1 (FEAT_LPA2) for 4K/16K (5.7).
  • The maximum is 39, or up to 48 (47 for 64K) with FEAT_TTST (v8.4, small translation tables).
  • Values outside the supported range are CONSTRAINED UNPREDICTABLE in their effect. Do not rely on any behaviour.

The TTBR covering a range must point to a table aligned to that table’s size, with a 64-byte minimum. A 48-bit 64K configuration, for example, starts at level 1 with only 64 entries (512 bytes).

TG0/TG1: granules

The granule is the page size and the size of every translation table at that granule (4KB, 16KB or 64KB). It also sets the bits resolved per level (9, 11 and 13 respectively) and the available block sizes. Support is discoverable, and the fields have different signedness:

ID_AA64MMFR0_EL1 fieldBitsEncoding
TGran4[31:28]0000 supported, 0001 supported with 52-bit, 1111 not supported (signed)
TGran64[27:24]0000 supported, 1111 not supported (signed)
TGran16[23:20]0000 not supported, 0001 supported, 0010 with 52-bit (unsigned)
TGran4_2/TGran64_2/TGran16_2[43:40]/[39:36]/[35:32]Stage 2 support; 0000 means “as the stage 1 field”

The two ranges of one regime may use different granules, and stage 1 and stage 2 may differ too.

IPS and PS: output address size

Value000001010011100101110111
Bits32364042444852 (FEAT_LPA/LPA2)56 (FEAT_D128)

If IPS or PS is larger than ID_AA64MMFR0_EL1.PARange, the implemented size is used instead. An output address above the configured size is an Address size fault. This covers the TTBR base address, a next-level table address and the final output address. If IPS is too small for your DRAM, the walk faults with an Address size fault, not a Translation fault. That difference tells you which of the two is misprogrammed. In the EL1&0 regime with stage 2 active, IPS bounds the IPA. The PA bound is VTCR_EL2.PS.

EPD0/EPD1

EPDn = 1 makes a TLB miss in that range a Translation fault instead of a walk. It does not disable TLB hits, so cached entries for that range keep working until they are invalidated. Typical uses:

  • an EL1 environment that has no user half (EPD0=1) or no kernel half (EPD1=1, as in many bare-metal or RTOS ports that use TTBR0 only);
  • a temporary state during a TTBR switch.

Keep TG1 a valid encoding and T1SZ in range anyway: the fields still exist, some behaviour still depends on them (the TTBR0/TTBR1 range split, TLBI range operations), and a later clear of EPD1 uses them immediately. Point TTBR1_EL1 at something harmless for the same reason.

HPD0/HPD1

With FEAT_HPDS (v8.1), HPDn = 1 makes the walk ignore the hierarchical permission bits in table descriptors (APTable, UXNTable/XNTable, PXNTable). With FEAT_HPDS2 (v8.2), those freed bits, together with the HWU enables, can carry IMPLEMENTATION DEFINED hardware attributes (PBHA). NSTable is not affected by HPD. Permissions are in 5.5.

Walk attributes: IRGN, ORGN, SH

IRGNn/ORGNn give the inner/outer cacheability of the walker’s descriptor reads (00 Non-cacheable, 01 WB read/write-allocate, 10 WT read-allocate, 11 WB read-allocate no write-allocate), and SHn their shareability (00 Non-shareable, 10 Outer, 11 Inner). They must agree with how software writes the tables, or the walker can read stale data: see Part 6 (6.3, 6.6).

TCR2_ELx (FEAT_TCR2)

TCR_EL1 was nearly full, so FEAT_TCR2 (an Armv8.9/v9.4 extension; for the permitted-from version, see DDI0487 A2) adds TCR2_EL1 and TCR2_EL2 as the enable registers for newer translation features. TCR2_EL1 fields:

BitFieldFeatureEnables
0PnCHFEAT_THEProtected attribute in descriptor bit 52 (13.2)
1PIEFEAT_S1PIEIndirect permission scheme (5.5)
2E0POEFEAT_S1POEPermission overlays for EL0 accesses (POR_EL0)
3POEFEAT_S1POEPermission overlays for EL1 accesses (POR_EL1)
4AIEFEAT_AIEAttribute index extension (MAIR2_EL1)
5D128FEAT_D128128-bit descriptor format (5.7)
10PTTWIFEAT_THEPermitted translation table write inhibit
11HAFTFEAT_HAFTHardware Access flag in table descriptors (5.6)
14/15DisCH0/DisCH1FEAT_D128Disable the contiguous hint per range
16–18A2, FNG0, FNG1FEAT_ASID2Two concurrent ASIDs

TCR2_EL1 is gated twice. If SCR_EL3.TCR2En == 0, EL1 and EL2 accesses to it trap to EL3 or are UNDEFINED. If EL2 is enabled and HCRX_EL2.TCR2En == 0, EL1 accesses trap to EL2. In either case, all TCR2_EL1 fields are treated as 0. A kernel that enables PIE while firmware leaves SCR_EL3.TCR2En clear does not get partial PIE: it takes an exception on the MSR. EL3 has no TCR2_EL3. The equivalent EL3 enables are fields of TCR_EL3 itself (for example TCR_EL3.PIE and TCR_EL3.POE). The enable sequencing is in 17.3.

Write ordering

All of these fields may be cached in TLBs. Change them only when no walk can use the old values (normally with the MMU off, or with a TLB invalidate afterwards), and follow the write with an ISB before relying on it (7.8). The enable sequence is in 9.3.

    // EL1, TTBR0 only: 48-bit VA, 4K, 40-bit IPS, inner-shareable WBWA walks
    // T0SZ=16, IRGN0=ORGN0=WBWA, SH0=Inner, TG0=4K, T1SZ=16 and TG1=4K (valid, unused), EPD1=1, IPS=40-bit
    .equ    TCR_VAL, (16 << 0) | (1 << 8) | (1 << 10) | (3 << 12) | (0 << 14) | (16 << 16) | (1 << 23) | (2 << 30) | (2 << 32)
    ldr     x0, =TCR_VAL            // = 0x2_8090_3510
    msr     tcr_el1, x0
    isb

Checkpoint

Q5.2.1 A port copies TCR_EL1.TG0 = 0b00 (4K) into TG1 and sets T1SZ = 16 for a kernel in the high range. The tables are built for 4K. What is the most likely outcome?

  • A. It works, because 00 means 4K in both fields
  • B. TG1 = 00 is reserved, so the walk uses an IMPLEMENTATION DEFINED implemented granule and may not match the tables, which can make it work on one platform and fault on another
  • C. The MSR to TCR_EL1 is UNDEFINED
  • D. The TTBR1 range is disabled as if EPD1 were set
Answer

B. TG1 encodes 16K/4K/64K as 01/10/11, and 00 is reserved. Reserved granule values are treated as an IMPLEMENTATION DEFINED implemented granule, so the result depends on the implementation, which is the worst kind of bug to find late. Option A is the assumption that causes the bug.

Read more: Arm ARM (DDI0487), TCR_EL1.TG1

Q5.2.2 DRAM sits at PA 0x80_0000_0000 (bit 39 set). With TCR_EL1.IPS = 0b001 (36 bits), the first access after enabling the MMU faults. Which DFSC class do you expect, and why?

  • A. Translation fault level 0, because the VA is out of range
  • B. Permission fault, because the walk was Non-cacheable
  • C. Translation fault at the level of the first invalid descriptor
  • D. Address size fault, because the TTBR base or a descriptor’s output address exceeds the 36-bit output size
Answer

D. Output addresses (including TTBR and table addresses) are checked against IPS. Bits above it that are non-zero give an Address size fault. Option A is tempting because “level 0” is common at MMU enable, but it concerns the input range (T0SZ), not the output range.

Read more: Arm ARM (DDI0487), “Address size configuration”, TCR_EL1.IPS

Q5.2.3 Linux enables FEAT_S1PIE on a platform whose EL3 firmware does not set SCR_EL3.TCR2En. What happens when the kernel executes MSR TCR2_EL1, x0?

  • A. The access traps to EL3 (or is UNDEFINED), and the TCR2_EL1 fields are treated as 0 regardless
  • B. The write succeeds, and PIE is enabled at EL1 but not at EL0
  • C. The write is ignored silently, so MRS reads back 0
  • D. PIE is enabled, but POE is not
Answer

A. With SCR_EL3.TCR2En == 0, lower-EL accesses to TCR2_EL1 trap to EL3 or are UNDEFINED, and the register’s fields are treated as zero for all purposes. Option C describes a write-ignore, which is not what the architecture specifies. It is the “silent failure” that people expect from RAZ/WI controls.

Read more: Arm ARM (DDI0487), TCR2_EL1, SCR_EL3.TCR2En, HCRX_EL2.TCR2En

5.3 Descriptors and walk mechanics

This section describes the VMSAv8-64 descriptor format (64-bit descriptors) for a 48-bit output address. The 52-bit and 128-bit variants change the address fields and add levels, and are in 5.7. Permission bits are named here and explained in 5.5. AF and DBM are in 5.6.

How a walk proceeds

A table walk starts from TTBRn_ELx.BADDR at the starting level. At each level it takes a group of VA bits as an index, reads the 64-bit descriptor at table_base + index × 8, and acts on the descriptor type:

  • invalid: the walk stops with a Translation fault at that level;
  • table: the walk continues at the next level using the address in the descriptor;
  • block or page: the walk ends, and the output address is the descriptor address field concatenated with the remaining low VA bits.

Every table occupies exactly one granule: 512 entries for 4K, 2048 for 16K, 8192 for 64K. The only exceptions are a smaller first table, when the VA size does not fill the top level, and concatenated first tables at stage 2.

Architecturally, each descriptor read is a single-copy atomic 64-bit read (128-bit with FEAT_D128). Its endianness is set by SCTLR_ELx.EE for the regime, so a big-endian EE reads your little-endian tables byte-swapped. The walker uses the cacheability and shareability from TCR_ELx.{IRGN,ORGN,SH} (5.2). Walks are permitted to be speculative and to be cached, both as final TLB entries and as intermediate walk cache entries. That is why a descriptor update needs the maintenance sequence in 9.1.

Descriptor types by bits[1:0]

bits[1:0]Levels 0–2Level 3
x0Invalid (bits[63:1] ignored, so software may use them)Invalid
01Block (where a block is permitted at that level), otherwise invalidReserved: treated as invalid
11TablePage

So the same 0b11 means “table” at level 2 and “page” at level 3. A page descriptor written one level too high is silently read as a table pointer to your data page. The walk then continues through data as if it were descriptors.

Block sizes by granule (48-bit OA, DS == 0):

GranuleLevel 1 blockLevel 2 blockLevel 3 page
4K1GB2MB4KB
16K– (64GB only with DS == 1)32MB16KB
64K– (4TB only with FEAT_LPA)512MB64KB

Level 0 holds only table descriptors in the 48-bit formats.

Field layouts (stage 1, 4K granule)

Table descriptor (levels 0-2):
 63      62:61     60        59        58:51    50:48  47:12              11:2    1 0
+-------+---------+---------+---------+--------+------+------------------+-------+---+
|NSTable|APTable  |UXNTable/|PXNTable |ignored |RES0  | next-level table |ignored|1 1|
|       |         |XNTable  |         |        |      | address [47:12]  |       |   |
+-------+---------+---------+---------+--------+------+------------------+-------+---+

Block (L1/L2, type 01) and page (L3, type 11) descriptors:
 63   62:59   58:55  54      53   52   51   50  49:48  47:n   n-1:12  11  10  9:8 7:6     5  4:2      1 0
+----+-------+------+-------+----+----+----+---+-----+------+-------+---+---+---+-------+--+--------+---+
|ign |PBHA/  |SW    |UXN/XN |PXN |Cont|DBM |GP |RES0 | OA   | RES0  |nG |AF |SH |AP[2:1]|NS|AttrIndx|t t|
|    |ign    |use   |       |    |    |    |   |     |      |(block)|   |   |   |       |  |        |   |
+----+-------+------+-------+----+----+----+---+-----+------+-------+---+---+---+-------+--+--------+---+
 n = 30 for a 1GB block, 21 for a 2MB block, 12 for a page

The lower attributes (bits [11:2]) are:

  • AttrIndx[2:0], an index into MAIR_ELx (6.5);
  • NS (meaningful only for a Secure regime);
  • AP[2:1];
  • SH (shareability for Normal memory, 6.4);
  • AF;
  • nG, which makes the entry ASID-tagged (only in regimes with ASIDs).

The upper attributes are:

  • GP (BTI guarded page, 13.1);
  • DBM;
  • Contiguous;
  • PXN and UXN (in single-range regimes, bit 54 is XN and bit 53 is RES0);
  • four bits for software use;
  • bits [62:59], which are ignored unless FEAT_HPDS2 PBHA is enabled, or POE claims [62:60] as POIndex.

With FEAT_BBM, bit 16 of a block descriptor is nT (9.2).

With 16K and 64K granules, the address fields start at bits 14 and 16 respectively. For 64K with FEAT_LPA, bits [15:12] carry OA[51:48] (5.7).

Stage 2 descriptors keep the same type encodings and address fields, but the attributes differ:

  • MemAttr[3:0] in bits [5:2] is a direct encoding, not an index;
  • S2AP[1:0] in bits [7:6];
  • XN[1:0] in bits [54:53] (with FEAT_XNX).

Details are in 11.3.

Bits shown as RES0 inside the OA field of a block (for example bits [20:12] of a 2MB block) must be zero. A block whose address is not aligned to the block size is a programming error, and the architecture does not guarantee the resulting translation. 5.9 lists it among the five commonest mistakes.

The starting level

Each level resolves g − 3 VA bits, where 2^g is the granule size, because a granule holds 2^(g−3) eight-byte entries. With VAbits = 64 − T0SZ:

levels_needed = ceil((VAbits - g) / (g - 3))
start_level   = 4 - levels_needed        // levels are numbered so the last is level 3
first_table_entries = 2 ^ ((VAbits - g) - (levels_needed - 1) * (g - 3))
GranuleStart L0Start L1Start L2Start L3
4K (g=12, 9 bits/level)VA 40–48 bits (T0SZ 16–24)31–39 (25–33)22–30 (34–42)≤21 (43–48)
16K (g=14, 11 bits/level)48 (16), with 2 entries37–47 (17–27)26–36 (28–38)≤25 (39–48)
64K (g=16, 13 bits/level)–43–48 (16–21), with 64 entries at 48 bits30–42 (22–34)≤29 (35–47)

T0SZ values above 39 need FEAT_TTST (v8.4), so a level-3 start is only reachable with it for 4K, and with it for most of the 16K/64K level-3 range. The 52-bit cases (T0SZ below 16) are in 5.7.

For stage 1, the starting level is implied by TxSZ and the granule. Software cannot choose it, so the table tree it builds must start at exactly that level. A common bring-up error is to build a 3-level tree (L1 → L2 → L3) for a 39-bit VA and then program T0SZ = 16. The walker treats the L1 table as L0. Every VA below 512GB uses entry 0 of it, which is interpreted as a level-0 descriptor pointing to a “level 1” table that is really your level 2.

The contiguous bit

Contiguous (bit 52) is a hint. It tells the implementation that a naturally aligned run of adjacent entries in the same table holds consistent attributes and permissions and maps a contiguous, equally aligned output range, so the whole run may be cached as one TLB entry:

GranuleLevel 3 runLevel 2 runLevel 1 run
4K16 × 4KB = 64KB16 × 2MB = 32MB16 × 1GB = 16GB
16K128 × 16KB = 2MB32 × 32MB = 1GB–
64K32 × 64KB = 2MB32 × 512MB = 16GB–

An implementation may ignore the bit. If software sets it on a run that is not consistent (one entry differs, the run is misaligned, or one entry is invalid), the result is CONSTRAINED UNPREDICTABLE. The permitted outcomes include a TLB conflict abort, or a translation that uses another entry of the run for an address it was not meant to cover. Changing one page inside a contiguous run therefore needs break-before-make on the whole run (9.2).

Stage-2 concatenated tables

At stage 2, the starting level is explicit: VTCR_EL2.SL0, with SL2 for level −1 under LPA2. For 4K, SL0 = 00 means level 2, 01 level 1 and 10 level 0. For 16K/64K, 00 means level 3, 01 level 2 and 10 level 1. Because the starting level is programmable, stage 2 may start one level later (one level number higher) than the IPA size alone would imply, with up to 16 concatenated tables at the initial level. The concatenated block is one contiguous region, aligned to its total size, and the extra top IPA bits select which table to use.

Example (4K, 40-bit IPA, T0SZ = 24): stage 1 logic would start at level 0 with only 2 entries used. Stage 2 can instead start at level 1 (SL0 = 01) with 2 concatenated 4KB tables (8KB, 8KB-aligned), and IPA bit 39 selects the table. This saves one walk level for every stage-1 descriptor fetch and every final access, which matters because stage 2 lookups multiply (5.1). KVM uses this for its default IPA sizes.

4K granule, IPA sizeStart L0Start L1 (concatenated)Start L2 (concatenated)
40 bits2 entries2 tables– (would need 1024)
42 bits8 entries8 tables–
44 bits32 entriesnot allowed (32 > 16)–
34 bits–16 entries16 tables (the maximum)

Configurations whose T0SZ/SL0 combination is inconsistent (it would need more than 16 tables, or the start level is too low for the IPA size) generate a stage 2 Translation fault. Stage 1 never concatenates.

Validation note: Test the contiguous hint for correctness, not speed, because the architecture never requires it to make anything faster. Map a 64KB contiguous run (4K granule) with a distinct data pattern per page, access all 16 pages in random order from several PEs, and check every value. Then repeat with one deliberately inconsistent entry and check that the outcome is one the architecture permits for a misprogrammed Contiguous bit, as listed in the Arm ARM (for example a TLB conflict abort, reported as DFSC 0b110000, or a translation derived from one of the entries in the run). Note that a translation derived from the “wrong” entry can produce a PA that no single entry maps, so the checker must accept the permitted outcomes rather than only the intended PAs. DTLB_WALK (PMU event 0x0034) counts dropping with the hint set are evidence that the implementation uses it, but the event is not a pass criterion.

Bring-up note: When you build tables with a host-side script for a pre-silicon image, also emit the computed starting level and first-table size, and assert them against the T0SZ/TG0 you will program. Two numbers in a log are cheaper than a hang at the first instruction after SCTLR_ELx.M = 1.

Checkpoint

Q5.3.1 A level-3 table contains an entry with bits[1:0] = 0b01. What does the walker do for a VA that indexes it?

  • A. It maps a 4KB block, because 01 is the block encoding
  • B. It treats the entry as a table pointer, because level 3 has no blocks
  • C. It takes a Translation fault at level 3, because 01 is reserved at level 3 and treated as invalid
  • D. The result is CONSTRAINED UNPREDICTABLE, and the entry may be used as a page
Answer

C. At level 3, only 0b11 (page) is valid. 0b01 is reserved and behaves as an invalid descriptor, which gives a Translation fault at level 3. Option A carries the level 0–2 meaning of 01 into level 3.

Read more: Arm ARM (DDI0487), “Translation table descriptor formats”, VMSAv8-64 level 3 descriptor format

Q5.3.2 With a 4K granule, software builds L1 → L2 → L3 tables for a 39-bit VA space but programs T0SZ = 16. The kernel image lives at VA 0x4000_0000. What happens on the first fetch after the MMU is enabled?

  • A. It works, because unused high bits of the VA are zero
  • B. The walker starts at level 0, treats the L1 table as L0, and follows entry 0 as a table descriptor, so the walk goes one level off and normally faults or translates wrongly
  • C. The walker detects the short tree and starts at level 1
  • D. The MSR SCTLR_EL1 that sets M is UNDEFINED, because T0SZ mismatches the tables
Answer

B. The starting level is implied by T0SZ and the granule, and the walker cannot see your intended structure. VA bits [47:39] index the “L0” table, which here is your L1 table. Entry 0, if it is a block, is invalid at level 0 (fault). If it is a table, the walk continues through a wrongly levelled tree. Option C assumes the walker checks the tree’s shape, and it does not.

Read more: Arm ARM (DDI0487), “Translation table walks”, “Selection between TTBR0 and TTBR1” and the initial lookup level tables

Q5.3.3 A hypervisor wants a 4K-granule stage 2 for a 40-bit IPA starting at level 1. What must the initial table be?

  • A. One 4KB table, 4KB-aligned, with IPA bit 39 ignored
  • B. A level-0 table with 2 entries, because concatenation is only for 64K granules
  • C. 16 concatenated tables, the architectural fixed count
  • D. Two concatenated 4KB tables in one 8KB-aligned 8KB region, with IPA bit 39 selecting the table
Answer

D. A 40-bit IPA at level 1 needs 2^(40−30) = 1024 entries, which is 2 tables. Concatenated tables must be contiguous and aligned to their total size. Sixteen is the maximum number of concatenated tables, not a fixed count (so C is wrong). Option A is wrong because, with T0SZ = 24 and SL0 = 01, the walker always uses IPA bit 39 to index an 8KB region. With only one 4KB table allocated, IPAs with bit 39 set index whatever memory follows that table.

Read more: Arm ARM (DDI0487), “Concatenated translation tables for the initial stage 2 lookup”, VTCR_EL2.SL0

5.4 Worked example: a 4K-granule walk by hand

This section walks three VAs through one set of EL1&0 stage 1 tables by hand: a 4KB page, a 2MB block, and a Translation fault. Do it once on paper. After that, a hex dump of a page table (from a debugger, a crash log or a Tarmac trace) reads like a sentence. The format rules are in 5.3, and the fault decode is in 5.8.

The configuration

RegisterValueMeaning
TCR_EL10x0000_0002_8090_3510T0SZ=16 (48-bit), TG0=4K, IRGN0=ORGN0=01, SH0=11, T1SZ=16, EPD1=1, TG1=4K, IPS=010 (40-bit)
TTBR0_EL10x0000_0000_8000_0000ASID 0, L0 table at PA 0x8000_0000
MAIR_EL10x0000_0000_0000_FF00Attr0 = 0x00 (Device-nGnRnE), Attr1 = 0xFF (Normal, inner/outer WB RW-allocate)
SCTLR_EL1M=1, C=1, I=1, EE=0MMU and caches on, little-endian walks

With a 4K granule and a 48-bit VA, the walk starts at level 0 and uses four 9-bit indexes:

 VA:  63..48 | 47..39 | 38..30 | 29..21 | 20..12 | 11..0
       zero  |  L0    |  L1    |  L2    |  L3    | offset

Tables in memory (PA), each 4KB:

TablePA
L00x8000_0000
L10x8000_1000
L20x8000_2000
L30x8000_3000

Walk 1: a 4KB page

VA = 0x0000_0081_4061_AABC.

Split it. Bit 39 is the lowest bit of the L0 index: 0x81_4061_AABC >> 39 = 1. The index steps:

L0 index = VA[47:39] = 0x001  (1)
L1 index = VA[38:30] = 0x005  (5)
L2 index = VA[29:21] = 0x003  (3)
L3 index = VA[20:12] = 0x01A  (26)
offset   = VA[11:0]  = 0xABC

Level 0. The descriptor address is 0x8000_0000 + 1×8 = 0x8000_0008.

[0x8000_0008] = 0x0000_0000_8000_1003
  bits[1:0] = 11       -> table (level 0)
  [63:59]   = 0        -> NSTable/APTable/XNTable/PXNTable impose nothing
  [47:12]   = 0x80001  -> next table at PA 0x8000_1000 (within 40-bit IPS: no Address size fault)

Level 1. The descriptor address is 0x8000_1000 + 5×8 = 0x8000_1028.

[0x8000_1028] = 0x0000_0000_8000_2003   -> table, next at 0x8000_2000

Level 2. The descriptor address is 0x8000_2000 + 3×8 = 0x8000_2018.

[0x8000_2018] = 0x0000_0000_8000_3003   -> table, next at 0x8000_3000

Level 3. The descriptor address is 0x8000_3000 + 26×8 = 0x8000_30D0.

[0x8000_30D0] = 0x0060_0000_9ABC_D707
  bits[1:0]  = 11        -> page (at level 3)
  AttrIndx   = [4:2]  = 001  -> MAIR Attr1: Normal WB
  NS         = [5]    = 0    (ignored: Non-secure regime)
  AP[2:1]    = [7:6]  = 00   -> EL1 RW, EL0 no access
  SH         = [9:8]  = 11   -> Inner Shareable
  AF         = [10]   = 1
  nG         = [11]   = 0    -> global
  OA         = [47:12] = 0x9ABCD
  PXN        = [53]   = 1, UXN = [54] = 1  -> not executable at EL1 or EL0

Result: PA = 0x9ABC_D000 | 0xABC = 0x0000_0000_9ABC_DABC, Normal WB, Inner Shareable, kernel read/write data. The walk made four descriptor reads, one per level, and the TLB now holds a 4KB entry (and possibly walk-cache entries for the L0–L2 steps).

How to construct the page descriptor value:

  0x0000_0000_9ABC_D000   OA
| 0x0040_0000_0000_0000   UXN  (bit 54)
| 0x0020_0000_0000_0000   PXN  (bit 53)
| 0x0000_0000_0000_0400   AF   (bit 10)
| 0x0000_0000_0000_0300   SH = 11
| 0x0000_0000_0000_0004   AttrIndx = 1
| 0x0000_0000_0000_0003   page
= 0x0060_0000_9ABC_D707

Walk 2: a 2MB block

VA = 0x0000_0081_4081_2345.

L0 = 1, L1 = 5, L2 = VA[29:21] = 4, remainder VA[20:0] = 0x01_2345

Levels 0 and 1 are the same as in Walk 1, and both are likely to be walk-cache hits on a real core. At level 2 the descriptor address is 0x8000_2000 + 4×8 = 0x8000_2020.

[0x8000_2020] = 0x0060_0000_A000_0705
  bits[1:0] = 01           -> block (valid at level 2 with 4K: 2MB)
  OA[47:21] = 0xA000_0000 >> 21 = 0x500;  bits[20:12] = 0  (aligned: correct)
  attributes as Walk 1 (AttrIndx 1, SH 11, AF 1, AP 00, PXN=UXN=1)

Result: PA = 0xA000_0000 | 0x01_2345 = 0x0000_0000_A001_2345. The walk took three reads and stopped at level 2. The VA bits [20:0] pass straight through.

The value differs from the page descriptor in only two ways: bits[1:0] are 01 and not 11, and the low 9 address bits must be zero. If you had written 0x...A000_0707 (type 11) into the L2 slot, the walker would read PA 0xA000_0000 as an L3 table. The 512 “descriptors” it found there would be whatever data lives in that memory.

Walk 3: a Translation fault

An EL1 load of VA = 0x0000_0081_40A0_0678:

L0 = 1, L1 = 5, L2 = VA[29:21] = 5
[0x8000_2028] = 0x0000_0000_0000_0000   -> bit[0] = 0: invalid

The walk stops at level 2. The exception is a Data Abort taken to EL1 from EL1:

ESR_EL1 = 0x9600_0006
  EC   [31:26] = 0x25     Data Abort, same EL
  IL   [25]    = 1        32-bit instruction
  WnR  [6]     = 0        read
  DFSC [5:0]   = 0b000110 Translation fault, level 2
FAR_EL1 = 0x0000_0081_40A0_0678   (valid for this fault)

A store to the same VA would give 0x9600_0046 (WnR = 1). The instruction-syndrome bits (ISV and the fields it validates) are shown clear here. The rules for when they are set are in 5.8.

The level number is the diagnostic. “Level 2” says levels 0 and 1 are fine and the L2 table is reachable, but the slot for VA[29:21] = 5 is empty. The fix is in the L2 table at 0x8000_2028, not in TTBR0_EL1 or TCR_EL1. By contrast, the following point at the configuration:

  • A level 0 Translation fault on every access after the MMU is enabled points at TTBR0_EL1, T0SZ or EPD0, or at a VA outside the range. Suppose the VA here had been 0xFFFF_0081_4061_AABC with EPD1 = 1. It is in the TTBR1 range, walks for that range are disabled, and it faults without reading anything.
  • An Address size fault (DFSC 0b0000LL) would mean a table or output address above the 40-bit IPS. For example, [0x8000_0008] holding 0x0000_0100_8000_1003 (bit 40 set) faults at level 0.

Checking your arithmetic on a model

Two checks confirm a hand walk against the real walker. First, read the descriptors yourself by physical address through the QEMU gdbstub (-s -S). QEMU’s PhyMemMode packet makes gdb memory reads physical:

(gdb) maintenance packet Qqemu.PhyMemMode:1
(gdb) x/gx 0x80000008        # L0[1]
(gdb) x/gx 0x80001028        # L1[5]
(gdb) x/gx 0x80002028        # L2[5] -> 0 for Walk 3
(gdb) maintenance packet Qqemu.PhyMemMode:0

Second, ask the hardware walker:

    // EL1 (or EL3 for the EL1&0 regime): ask the hardware
    ldr     x0, =0x0000008140A00678
    at      s1e1r, x0
    isb
    mrs     x1, par_el1      // PAR_EL1.F=1, FST=0b000110 for Walk 3

The full AT/PAR procedure is the lab in 5.9.

Validation note: Hand walks like these make cheap golden vectors for a pre-silicon MMU test. Generate tables from a script, record the expected PA (or fault level and DFSC) for each VA, and run AT S1E1R + PAR_EL1 comparisons alongside real loads. A mismatch between the AT result and the load result for the same VA is itself a bug signature, because both use the same walk. Count DTLB_WALK (0x0034) to check that cold accesses really walked rather than hit a stale entry from a previous test.

Checkpoint

Q5.4.1 Using the tables above, a load from VA 0x0000_0081_4061_B000 runs at EL1. What determines whether it faults?

  • A. Only the L3 entry at 0x8000_30D8 (index 27), because L0–L2 are the same as in Walk 1
  • B. The L2 entry at 0x8000_2020, because 0xB000 crosses into the next 2MB region
  • C. Nothing: VAs within 64KB of a mapped page share its TLB entry
  • D. The L3 entry at 0x8000_30D0, because the offset field absorbs the difference
Answer

A. 0x...61_B000 differs from Walk 1’s VA in bits [20:12] (0x1B = 27 instead of 26), so L0–L2 are the same, and the L3 index moves to 27, at 0x8000_3000 + 27×8 = 0x8000_30D8. Option D forgets that only bits [11:0] are the offset. Option C would need the contiguous bit and a consistent run of 16 entries.

Read more: Arm ARM (DDI0487), “Translation table walks” for the 4KB granule

Q5.4.2 An EL1 store to some VA gives ESR_EL1 = 0x9600_0045. What does this tell you about the walk?

  • A. A Permission fault on a write at level 1
  • B. A Translation fault on a read at level 1, from a load
  • C. A Translation fault at level 1 on a write. The L0 descriptor was a valid table, and the L1 entry indexed by the VA is invalid
  • D. An Address size fault at level 1
Answer

C. EC 0x25 is a Data Abort from the same EL, WnR (bit 6) = 1, and DFSC 0b000101 is a Translation fault at level 1. To reach level 1, the L0 descriptor must have been a valid table. Option A confuses Permission faults (0b0011LL) with Translation faults (0b0001LL).

Read more: Arm ARM (DDI0487), ESR_EL1, ISS encoding for an exception from a Data Abort

Q5.4.3 Someone writes 0x0060_0000_A010_0705 into L2 entry 4 instead of 0x0060_0000_A000_0705. Which statement is correct?

  • A. The block is simply shifted by 1MB, and translations are well defined
  • B. Bits [20:12] of a level-2 block descriptor must be zero. With bit 20 set, the descriptor is misprogrammed, and the architecture does not guarantee the resulting PA
  • C. The walker treats the entry as a table, because a non-aligned address implies a table
  • D. The walker rounds the address down and always produces 0xA000_0000 + offset
Answer

B. For a 2MB block, OA comes from bits [47:21]. Bits [20:12] are RES0, and writing them non-zero is a programming error with no guaranteed outcome. Option A assumes block addresses are byte-granular, and option D assumes the hardware masks the bits, which you must not rely on even if a given core does.

Read more: Arm ARM (DDI0487), VMSAv8-64 block descriptor format

5.5 Access permissions

Stage 1 permissions are built in layers. Conceptually they compose as follows (the Arm ARM pseudocode interleaves some steps, for example WXN is evaluated together with the overlay, but every layer after the first can only remove permission):

  1. The base permission comes from the descriptor. It is either direct (the AP/XN bits) or indirect (an index into PIR_ELx, with FEAT_S1PIE).
  2. Hierarchical restrictions from table descriptors are applied, unless they are disabled.
  3. Global modifiers are applied: WXN, the implicit “EL0-writable is never EL1-executable” rule, PAN/EPAN, and the unprivileged-access rules.
  4. A permission overlay (FEAT_S1POE) can only remove permissions.
  5. If stage 2 is active, its permissions are intersected with the result (11.3).

A failure at any step is a Permission fault (DFSC 0b0011LL, where LL is the level of the final descriptor). Decode is in 5.8.

Direct permissions: AP[2:1], UXN, PXN

AP[2:1] (descriptor bits [7:6]) in a two-range regime (EL1&0, EL2&0):

AP[2:1]Privileged (EL1 or EL2)Unprivileged (EL0)
00Read/writeNone
01Read/writeRead/write
10Read-onlyNone
11Read-onlyRead-only

AP[2] selects read-only, and AP[1] grants EL0 access. In the single-range regimes (EL2 with E2H=0, EL3), there is no EL0, so AP[1] is RES1 (TF-A sets it as AP_ONE_VA_RANGE_RES1) and only AP[2] matters.

Execute permission is separate from read permission. In two-range regimes, UXN (bit 54) forbids execution at EL0 and PXN (bit 53) at the privileged EL. In single-range regimes, bit 54 is XN and bit 53 is RES0. Two architectural rules add to these bits:

  • EL0-writable memory is never privileged-executable. In the EL1&0 regime, any location with AP[2:1] = 01 is treated as PXN for EL1, whatever bit 53 says. The EL2&0 regime has the same rule for EL2. Kernel code cannot be planted through a user-writable mapping.
  • SCTLR_ELx.WXN = 1 treats every writable location as execute-never for the regime (under direct permissions; with PIE, WXN affects only the PIR encoding 0110, see below). WXN is permitted to be cached in TLB entries, so changing it needs a TLB invalidate for the regime, not just an ISB.

Security note: At EL3, also set SCR_EL3.SIF. It makes a Secure-state instruction fetch from a Non-secure PA a Permission fault, even when the EL3 or S-EL1 tables mark the page executable. A stray EL3 table entry that maps normal-world memory as executable then cannot be turned into code execution.

Hierarchical permissions: APTable, XNTable, PXNTable

Table descriptors can restrict everything below them:

FieldBitsEffect on all subsequent levels
APTable[1:0][62:61]x1: no EL0 access; 1x: no write access at any EL (APTable[0] RES0 in single-range regimes)
UXNTable (XNTable)[60]Execute-never at EL0 (at all ELs in single-range regimes)
PXNTable[59]Execute-never at the privileged EL

They can only remove permission, never grant it. TCR_ELx.HPD0/HPD1 (FEAT_HPDS, v8.1; TCR_EL3.HPD, TCR_EL2.HPD) makes the walk ignore them, which frees the bits for PBHA (FEAT_HPDS2). When stage 1 permission indirection is enabled, hierarchical permissions are disabled as if HPD were 1, because the PIE model has no table-level counterpart. The same happens when a stage 1 permission overlay (TCR2_ELx.POE or E0POE) is enabled. Firmware that relies on APTable to make a whole subtree read-only loses that protection silently when PIE or POE is switched on.

PAN, EPAN, UAO and unprivileged accesses

PAN (FEAT_PAN, v8.1). When PSTATE.PAN = 1, a privileged data access (at EL1, or at EL2 in the EL2&0 regime) to a location that EL0 can access (AP[1] = 1) takes a Permission fault. Instruction fetches are not affected. SCTLR_EL1.SPAN = 0 makes the PE set PSTATE.PAN automatically on exception entry to EL1 (SCTLR_EL2.SPAN does the same for EL2 with E2H=1), so a kernel does not have a window between taking an exception and setting PAN. Software flips PAN cheaply with MSR PAN, #imm.

FEAT_PAN2 (v8.2) adds AT S1E1RP and AT S1E1WP, which translate with the current PSTATE.PAN applied. Plain AT S1E1R/W ignore PAN.

EPAN (FEAT_PAN3, v8.7). PAN keys off AP[1], so an execute-only user mapping (AP = 00, UXN = 0: EL0 may only execute, and EL1 has RW) was not covered. A kernel could be tricked into reading user code through it. With SCTLR_ELx.EPAN = 1, PAN also faults privileged data accesses to locations that are executable at EL0.

Unprivileged loads and stores (LDTR*, STTR*, and the unprivileged FEAT_MOPS forms) executed at EL1 are checked against EL0 permissions. The same holds at EL2 with E2H = TGE = 1. PAN does not fault them, because they are not privileged accesses. That is the intended way for a kernel to copy to and from user memory: PAN stays on, and the access is checked as if EL0 had made it.

UAO (FEAT_UAO, v8.2). With PSTATE.UAO = 1, LDTR*/STTR* at EL1 (and at EL2 in EL2&0) use the privileged permissions instead. Linux once used it to run the same copy_*_user code on kernel addresses (set_fs(KERNEL_DS)), and has since removed it. New code has no reason to set UAO.

Permission indirection (FEAT_S1PIE, FEAT_S2PIE)

With TCR2_EL1.PIE = 1 (or TCR2_EL2.PIE, or TCR_EL3.PIE), the stage 1 permission bits no longer encode permissions directly. Four descriptor bits form a 4-bit PIIndex:

PIIndex bit3210
Descriptor bit54 (UXN)53 (PXN)51 (DBM)6 (AP[1])

The index selects a 4-bit field in two registers: PIR_ELx for privileged accesses and PIRE0_ELx for EL0 accesses in two-range regimes. The EL3 regime has PIR_EL3 only. Selected Perm encodings:

EncodingPermissionOverlay
0000No accessApplied
0001ReadApplied
0010Execute onlyApplied
0011Read, executeApplied
0101Read, writeApplied
0110Read, write, execute; execute is removed when SCTLR_ELx.WXN = 1Applied
0111Read, write, executeApplied
1000ReadNot applied
1001Read, plus GCS read/write (13.2)Not applied
1010Read, executeNot applied
1100Read, writeNot applied
1110Read, write, executeNot applied

The remaining encodings (0100, 1011, 1101, 1111) are reserved and give no access. See the PIR_EL1 register description. 0110 is the only encoding that WXN affects under PIE. The implicit “EL0-writable is never privileged-executable” rule also survives, in a stronger form: if the selected PIR entry grants privileged execute and the PIRE0 entry grants EL0 write, the location gives no access at all. Three properties matter:

  • Permissions become a table that software designs. The OS picks up to 16 page “types” (kernel text, user execute-only, GCS stack and so on), and the descriptor carries only the type number. A true EL0 execute-only page with no EL1 access, which direct permissions cannot express, is one PIR/PIRE0 pair of entries.
  • PIR contents may be cached in TLBs. Changing PIR_ELx after enabling therefore needs TLB maintenance. Treat the registers as boot-time constants.
  • PIE is required by FEAT_D128. With TCR2_EL1.D128 = 1, the indirect scheme is always in effect, because the 128-bit format has no direct-permission encoding (5.7).

The stage 2 counterpart (FEAT_S2PIE) is enabled by VTCR_EL2.S2PIE and uses S2PIR_EL2. Its index is formed from the stage 2 permission bits. See 11.3.

Permission overlays (FEAT_S1POE, FEAT_S2POE)

An overlay is a second, per-thread permission layer. With POE enabled, descriptor bits [62:60] are a 3-bit POIndex, which selects a 4-bit field in a Permission Overlay Register:

  • POR_EL0 for EL0 accesses (enabled by TCR2_EL1.E0POE);
  • POR_EL1 for EL1 accesses (enabled by TCR2_EL1.POE);
  • POR_EL2/POR_EL3 for those regimes (TCR2_EL2.POE, TCR_EL3.POE).
POR field00000001001000110100010101100111
PermitsnoneRXRXWRWWXRWX

Values 1xxx are reserved and give no access.

The effective permission is base ∩ overlay. The overlay can only restrict. With PIE enabled, it applies only where the selected PIR encoding says “overlay applied”. Under direct permissions, it applies to every access of the enabled kind (privileged for POE, EL0 for E0POE). When the overlay is in use and WXN = 1, an overlay value that grants execute has its write permission removed instead. The bits [62:60] overlap the PBHA bits, so a platform cannot use both for the same descriptors.

The TCR2 enable bits are not permitted to be cached in TLBs. The overlay registers are system registers that a thread can switch with an MSR + ISB, without touching page tables or TLBs. That is the point of the feature: the page tables stay shared, and each thread holds its own view of them. An overlay violation is reported as a Permission fault with ESR_ELx.ISS2.Overlay set, which distinguishes it from a base-permission fault. Stage 2 overlays (FEAT_S2POE, enabled by VTCR_EL2.S2POE, indexed by bits of the stage 2 descriptor) apply the same idea to stage 2. Their register, S2POR_EL1, is an EL1-accessible register (trappable through the EL2 fine-grained traps), so it can be switched as part of a guest’s context while the stage 2 tables stay shared (11.3).

FEAT_S1PIE, S2PIE, S1POE, S2POE and TCR2 are Armv8.9/v9.4 (2022) extensions. For their permitted-from versions, see DDI0487 A2. Before EL1 can use them, EL3 must enable access: SCR_EL3.TCR2En and SCR_EL3.PIEn (which covers the PIR/POR registers). Under EL2, HCRX_EL2.TCR2En and the fine-grained trap controls for those registers must also allow EL1 access. The checklist is in 17.3.

Security note: POR_EL0 is user-controlled protection keys, the Arm equivalent of x86 PKU, and Linux exposes it through pkey_alloc()/pkey_mprotect(). A process can tag its secret-holding pages with key k and give itself access only around the code that needs them:

    // grant RW for key 1 only for this window
    mrs     x9, por_el0
    bfi     x9, x10, #4, #4      // x10 = 0b0101 (RW) into Perm1
    msr     por_el0, x9
    isb
    ldr     x0, [x1]             // access the protected page
    ...

This is an isolation and bug-containment tool, not a security boundary against code that already executes in the process. Any attacker who reaches an MSR POR_EL0 gadget can rewrite the register. Make it robust with control-flow integrity, so that such gadgets cannot be reached: BTI and PAC (13.1) and GCS (13.2). Also make sure that signal delivery saves POR_EL0 and sets a known value for the handler (Linux does this), so a handler does not inherit a window that happened to be open. Because the kernel’s POR_EL1 is separate, user keys never weaken kernel accesses. A kernel copying to user memory with STTR is checked against POR_EL0, which is the correct behaviour.

Validation note: Build a permission matrix test. For each PIIndex (0–15) × {EL0, EL1} × {read, write, execute} × {PAN 0/1} × {overlay on/off}, predict the outcome from the PIR/PIRE0/POR values, perform the access, and compare against the result and the ESR (DFSC level and ISS2.Overlay). Run every cell with both AT S1E1R/W/AT S1E0R/W and a real access: an AT/access disagreement is a walker bug. Cover the TCR2En = 0 case: the MSR must trap, and the walker must behave as if every TCR2_EL1 field were 0 (no PIE, no overlay), whatever value was previously written.

Checkpoint

Q5.5.1 A kernel maps a user page with AP[2:1] = 01 and PXN = 0, and then jumps to it at EL1. What happens?

  • A. It executes, because PXN is clear and PAN does not apply to instruction fetches
  • B. It takes a Permission fault, because memory writable at EL0 is always treated as PXN at EL1
  • C. It executes only if SCTLR_EL1.WXN = 0
  • D. It faults only when PSTATE.PAN = 1
Answer

B. In the EL1&0 regime, locations that EL0 can write are treated as privileged execute-never, independent of the PXN bit, WXN and PAN. Option A correctly says PAN ignores fetches, but misses this separate implicit rule.

Read more: Arm ARM (DDI0487), “Instruction execution permissions”, “Access permissions for instruction execution”

Q5.5.2 With PSTATE.PAN = 1 and SCTLR_EL1.EPAN = 0, a user mapping has AP[2:1] = 00, UXN = 0 (execute-only for EL0). Which EL1 access succeeds, and why does EPAN exist?

  • A. None. PAN blocks all EL1 accesses to user pages
  • B. LDTR succeeds, and EPAN exists to block LDTR
  • C. A plain LDR faults, because PAN checks UXN
  • D. A plain LDR succeeds, because PAN only checks AP[1], which is 0 here. EPAN extends PAN to EL0-executable locations to close this gap
Answer

D. AP = 00 means EL1 RW and EL0 no data access, so PAN (which tests EL0 data accessibility) does not fire, and the kernel can read user code. FEAT_PAN3/EPAN adds “executable at EL0” to the PAN condition. Option B is wrong because LDTR is checked against EL0 permissions, and EL0 has no read access here, so LDTR would fault.

Read more: Arm ARM (DDI0487), SCTLR_EL1.EPAN, “PSTATE.PAN”

Q5.5.3 A hypervisor-free EL1 OS enables TCR2_EL1.PIE. Its tables mark a whole kernel-data subtree read-only through APTable = 0b10 in an L1 table descriptor. After enabling PIE, a store to that subtree succeeds. Why?

  • A. With permission indirection enabled, hierarchical permissions are disabled, so APTable is ignored
  • B. APTable only affects EL0
  • C. PIR_EL1 caching made the old permissions stale, and a TLBI would fix it
  • D. APTable = 0b10 is reserved under PIE and grants write access
Answer

A. Enabling stage 1 PIE disables hierarchical permission controls, as if HPD were set. The protection must move into the PIIndex of each leaf descriptor. Option C is a real concern for later changes to PIR_EL1, but it does not explain a write being allowed through a table that is meant to forbid it.

Read more: Arm ARM (DDI0487), “Hierarchical permissions”, “Stage 1 indirect permissions”; TCR2_EL1.PIE

5.6 Access flag and dirty state

An OS that pages, reclaims or migrates memory needs two facts per page: has it been accessed since it was last aged, and has it been written since it was last cleaned? VMSAv8-64 records the first in the Access flag (AF) and the second in the dirty state. Both can be maintained by software through faults, or by hardware (FEAT_HAFDBS) that writes the descriptor itself. Once hardware writes descriptors, the walker is a writer of shared data, and software updates to page tables become a concurrency problem.

The Access flag

AF is bit [10] of every block and page descriptor, at both stages. Its meaning depends on whether hardware management is enabled for the regime:

ConfigurationAccess to a descriptor with AF == 0
TCR_ELx.HA == 0 (or FEAT_HAFDBS not implemented)Access flag fault, DFSC 0b0010LL (LL = level)
TCR_ELx.HA == 1Hardware sets AF = 1 in memory with an atomic update, and the access proceeds

HA is TCR_EL1[39] (and the VHE form of TCR_EL2), TCR_EL2[21]/TCR_EL3[21] in the single-range layouts, and VTCR_EL2[21] for stage 2. See the layout table in 5.2.

The software-managed scheme is simple. The OS clears AF when it ages a page, takes the Access flag fault on the next access, sets AF = 1, and returns. No TLB invalidation is needed on that path, because the architecture does not allow a TLB to cache a translation that generates an Access flag fault (the same rule applies to Translation and Address size faults). The new descriptor only has to be visible to the walker before the faulting instruction runs again: a store, a DSB, then the exception return. 9.1 gives the exact rules, including FEAT_ETS2.

Aging works the other way round. Clearing AF on a valid, possibly-cached entry has no effect until the TLB entry is gone, because a cached entry with AF == 1 keeps translating without a walk. If you need the next access to be detected, you need a TLBI. Linux accepts imprecise aging and skips the invalidation in some paths. Firmware that uses AF to detect accesses (rare) cannot.

Bring-up note: TF-A’s xlat_tables_v2 sets AF = 1 in every descriptor it creates, and EL3 does not enable HA. An Access flag fault in early firmware almost always means a hand-built descriptor that leaves bit 10 clear. It shows as DFSC 0x0B (level 3) or 0x09/0x0A for blocks. This is one of the five common mistakes in 5.9.

Dirty state and DBM

Armv8.0 has no dirty bit. Software uses write permission as a proxy: it maps a page read-only, takes a Permission fault on the first write, records the page as dirty, and makes the page writable. FEAT_HAFDBS adds a Dirty Bit Modifier (DBM, bit [51]) that lets hardware make that transition instead:

Stage“Writable-clean” encodingWhat hardware does on a write (HD=1)“Writable-dirty” encoding
Stage 1DBM = 1, AP[2] = 1 (read-only)clears AP[2] to 0DBM = 1, AP[2] = 0
Stage 2DBM = 1, S2AP[1] = 0 (no write)sets S2AP[1] to 1DBM = 1, S2AP[1] = 1

So the “dirty bit” is not a separate bit. It is the write-permission bit, and DBM says “hardware may grant write permission on demand”. A descriptor with DBM = 0 and AP[2] = 1 is still truly read-only and gives a Permission fault. The enable is TCR_ELx.HD (TCR_EL1[40], VTCR_EL2[22]). HD has effect only when HA is also 1. With FEAT_S1PIE, the stage 1 dirty state moves to an explicit descriptor bit, and a permission fault caused by the dirty state is flagged by ESR_ELx.ISS2.DirtyBit. The PIE encodings are in 5.5.

To clean a page (after writeback, or at the start of a migration pass), software sets AP[2] = 1 again (or clears S2AP[1]). That is a permission downgrade. Cached writable entries keep allowing silent writes until they are invalidated, so the clean is a descriptor update followed by TLBI and DSB, not a store alone. Upgrading a page in the software scheme (read-only to writable after a fault) also needs a TLBI, unlike the AF case, because a TLB is permitted to cache an entry that generates a Permission fault. Linux’s ptep_set_access_flags() invalidates the page when it sets the dirty state for this reason.

Discovery and enables

ID_AA64MMFR1_EL1.HAFDBS (bits [3:0]) is cumulative:

ValueMeaning
0b0000No hardware updates
0b0001Hardware Access flag only
0b0010Access flag and dirty state (DBM)
0b0011As 0b0010, plus FEAT_HAFT (Access flag in table descriptors)
0b0100As 0b0011, plus FEAT_HDBSS

FEAT_HAFDBS was introduced by the Armv8.1 extension and is OPTIONAL from Armv8.0. It has never become mandatory, so an Armv9 core may still report 0b0000 or 0b0001. HA/HD are per-regime, and on a heterogeneous system they can differ per core. Linux treats hardware DBM as a per-CPU capability for this reason, and disables it on cores with errata such as Cortex-A55 erratum 1024718.

Hardware updates and the memory model

A hardware AF or dirty-state update is an atomic read-modify-write of the descriptor, performed by the walker as part of translating an access. Several consequences follow.

1. The update is atomic with respect to software’s accesses, but software’s plain stores are not atomic with respect to it. If software reads a descriptor, computes a new value and stores it with an ordinary STR, hardware can set the dirty state between the read and the store, and the store silently discards it. For migration that is data corruption: the page is copied as clean while it holds a new write. Any software update of a descriptor that hardware may be updating concurrently must itself be an atomic RMW (LDXR/STXR or an LSE CAS, see 10.1 and 10.2), and must retry if the descriptor changed:

/* Write-protect (clean) a stage 1 PTE without losing a concurrent hardware dirty update. */
static inline uint64_t pte_wrprotect_atomic(volatile uint64_t *ptep)
{
    uint64_t old = *ptep, new;
    do {
        new = old | PTE_RDONLY;            /* AP[2] = 1: writable-clean if DBM = 1 */
        /* if hardware cleared AP[2] since we read 'old', the CAS fails and we retry,
           and the caller sees that the page was dirty */
    } while (!__atomic_compare_exchange_n(ptep, &old, new, false,
                                          __ATOMIC_RELAXED, __ATOMIC_RELAXED));
    return old;                             /* old & PTE_RDONLY == 0  =>  was dirty */
}
/* then: DSB ISHST; TLBI VAE1IS; DSB ISH  (9.1) */

Linux’s __ptep_set_wrprotect() and ptep_test_and_clear_young() are this loop with cmpxchg_relaxed().

2. The hardware side also detects races. If the descriptor changes between the walk’s read and the update, the hardware does not write a value computed from the stale read. DDI0487 requires the update to be retried against the new value, or the translation restarted. This is why the CAS loop above is sufficient: whichever writer goes second sees the other’s change.

3. The memory holding the tables must support atomic updates from the walker. If the walker’s RMW cannot be performed atomically on that memory, for example because the tables are Non-cacheable and the interconnect does not support far atomics to that target, the access takes an Unsupported atomic hardware update fault (DFSC 0x31). Whether a given memory type and location supports it is IMPLEMENTATION DEFINED. Keep tables in Normal Inner Write-Back Inner Shareable memory, and match the walk attributes in TCR_ELx.IRGN/ORGN/SH (5.2).

4. The AF is a hint. The dirty state is what migration depends on. The AF can be set by walks for accesses that are never architecturally executed, including speculative ones, so “AF set” means “probably accessed”, never “certainly accessed”. The dirty state is tied to a write being performed. Software relies on the rule that a write cannot become visible while its descriptor still reads as writable-clean. The exact statement of when the update becomes observable relative to the access, and the effect of DSB on outstanding hardware updates, is in DDI0487 “Hardware management of the dirty state” and the translation-table ordering rules. Read it before you write a lock-free page-table walker.

5. Ordering of the walker against your own loads still follows Part 9. A hardware update is not a program-order access of the PE that triggered it, so a plain load of the descriptor right after an access is not guaranteed to see the update. Software that reads AF or dirty state for decisions does so with atomics, and after the TLBI/DSB sequence when exactness matters.

Validation note: Test HAFDBS with a two-agent race: core A writes in a tight loop to a writable-clean page, while core B repeatedly cleans the page with a CAS loop plus TLBI VAE1IS and DSB ISH, and records whether old was dirty. Every write that A completes after B’s DSB must be followed by B seeing the page dirty in a later iteration. A lost update shows up as a pass with a written value but “clean” status, which shows that the dirty update was not observed before the write was. Count walks with the PMU (DTLB_WALK, event 0x0034) to confirm that the cleaning TLBIs are really forcing new walks. Also run with tables in Non-cacheable memory to check that the platform either supports the RMW or reports DFSC 0x31 cleanly instead of corrupting the descriptor.

FEAT_HAFT: Access flag in table descriptors

FEAT_HAFT (introduced by the Armv8.9 extension, OPTIONAL from Armv8.7, ID_AA64MMFR1_EL1.HAFDBS >= 0b0011) gives table descriptors an Access flag at bit [10], which was previously ignored there. With TCR2_ELx.HAFT (bit 11) or VTCR_EL2.HAFT (bit 44) set, the walker sets the table descriptor’s AF when it uses that table during a walk. An OS can then age memory hierarchically. If a level-1 table descriptor’s AF is still clear, nothing in the 1GB it covers has been walked since it was cleared, and the whole subtree can be skipped without visiting 262,144 PTEs. As with the leaf AF, clearing a table AF only has an effect once cached walk entries (including intermediate “walk cache” entries) have been invalidated. FEAT_HAFT requires FEAT_HAFDBS and FEAT_TCR2.

FEAT_HDBSS and FEAT_HACDBS: dirty tracking for live migration (overview)

Live migration of a VM is a stage 2 dirty-tracking loop: write-protect all of guest memory, let it run, find the dirty pages, copy them, and repeat. With plain HAFDBS the hypervisor has to scan stage 2 descriptors to find the dirty ones and clean each one with a CAS and a TLBI. Both are O(guest size) per pass. Two Armv9.5 extensions (OPTIONAL from Armv9.4) offload the work:

  • FEAT_HDBSS (Hardware Dirty state tracking Structure). When VTCR_EL2.HDBSS (bit 45) is set, each time hardware moves a stage 2 descriptor from writable-clean to writable-dirty it also appends a record of the IPA to a buffer in memory. HDBSSBR_EL2 holds the buffer base and size (SZ, 4KB to 2MB). HDBSSPROD_EL2 holds the producer INDEX and an FSC for faults on the buffer write itself. A full buffer or a failed record write is reported to EL2 (ESR_ELx.ISS2.HDBSSF), so the hypervisor reads a list of dirty IPAs instead of scanning.
  • FEAT_HACDBS (Hardware Accelerator for Cleaning Dirty State). The hypervisor supplies a list of IPAs in memory (HACDBSBR_EL2, with progress tracked in HACDBSCONS_EL2), and hardware moves each named stage 2 descriptor from writable-dirty back to writable-clean. Discovery is ID_AA64MMFR4_EL1.HACDBS, and FEAT_HACDBS requires FEAT_HDBSS.

Both apply to stage 2 only and matter to hypervisor authors. For firmware, the job is to leave the EL2 controls alone and pass the ID fields through. Stage 2 itself is in 11.3.

Checkpoint

Q5.6.1 With TCR_EL1.HA == 1 and HD == 1, a kernel cleans a page by reading its PTE, ORing in AP[2], and writing it back with STR, then issues DSB ISHST; TLBI VAE1IS; DSB ISH. Under heavy writes from another core, the migration occasionally copies stale data. Why?

  • A. The TLBI should be TLBI VMALLE1IS, because a VA-based invalidate misses walk-cache entries
  • B. DSB ISHST is too weak before the TLBI, so it must be DSB ISH
  • C. Hardware can clear AP[2] (mark the page dirty) between the kernel’s load and its STR, and the plain store overwrites that update, so the page is recorded as clean although it was written
  • D. Hardware dirty updates are not coherent with data caches, so the kernel must clean the PTE’s cache line first
Answer

C. The hardware update is an atomic RMW, but the kernel’s load/modify/store is not, so a concurrent hardware update is lost. The update must be a CAS (or LDXR/STXR) loop that fails if the descriptor changed. The barrier sequence (B) is the standard one from 9.1 and is not the problem. A TLBI VAE1IS (A) also invalidates the walk-cache entries for that VA. D is wrong: walker updates are coherent in the shareability domain given by the walk attributes.

Read more: Arm ARM (DDI0487), “Hardware management of the dirty state”; Linux __ptep_set_wrprotect()

Q5.6.2 In a purely software-managed scheme (HA == 0), which pair of fault fixes is correct?

  • A. After an Access flag fault: set AF, DSB, return, with no TLBI. After a write Permission fault used for dirty tracking: make the page writable and invalidate the page’s TLB entry
  • B. Both fixes need a TLBI, because any descriptor change requires invalidation
  • C. Neither needs a TLBI, because the faulting entry is never cached
  • D. The Access flag fix needs a TLBI; the permission upgrade does not, because permission faults are re-checked on every access
Answer

A. A TLB is not permitted to cache a translation that generates an Access flag fault, so a walk after the fix sees the new descriptor. A TLB is permitted to cache an entry that generates a Permission fault, so an upgrade without invalidation can fault again. Option C is the tempting overgeneralisation of the AF rule.

Read more: Arm ARM (DDI0487), “TLB maintenance requirements” / caching of translation table entries that generate faults

Q5.6.3 A bring-up team enables TCR_EL1.HA on a new SoC whose early page tables sit in an SRAM mapped Non-cacheable. The first access to a page with AF == 0 reports DFSC 0x31. What does this tell you?

  • A. The descriptor is malformed, so the walk returned a Translation fault encoded at level 1
  • B. HA is ignored unless HD is also set
  • C. The SRAM has ECC, and the walk’s read took a synchronous parity error
  • D. The walker’s atomic update of the descriptor is not supported for that memory, so the tables must move to memory that supports it (normally Normal Write-Back cacheable) or HA must stay off
Answer

D. 0x31 is the Unsupported atomic hardware update fault. Whether a memory type and target support the walker’s RMW is IMPLEMENTATION DEFINED, and Non-cacheable SRAM behind a simple slave often does not. B reverses the dependency: HD requires HA, not the other way round. C would be 0x1C–0x1F (or SEA codes with RAS).

Read more: Arm ARM (DDI0487), ESR_ELx.DFSC and “Hardware management of the Access flag”

5.7 Large addresses

The baseline VMSAv8-64 format gives 48-bit VAs and 48-bit PAs. Four extensions raise those limits, each by finding spare descriptor bits or by adding a level: FEAT_LVA and FEAT_LPA (52 bits, 64K granule only), FEAT_LPA2 (52 bits for 4K and 16K), and FEAT_D128 with FEAT_LVA3 (128-bit descriptors, 56-bit PA and VA). The walk mechanics they modify are in 5.3, and the TxSZ/IPS fields in 5.2.

Version summary

DDI0487 A2 lists each feature under the extension that introduced it and states an earlier “OPTIONAL from” version. Arm’s Feature names in A-profile architecture (109697) reproduces those statements:

FeatureIntroduced byPermitted (OPTIONAL) fromDiscovery
FEAT_LVA (52-bit VA)Armv8.2Armv8.1ID_AA64MMFR2_EL1.VARange == 0b0001
FEAT_LPA (52-bit PA/IPA, 64K)Armv8.2Armv8.1ID_AA64MMFR0_EL1.PARange == 0b0110
FEAT_LPA2 (52-bit, 4K/16K)Armv8.7Armv8.6TGran4 == 0b0001, TGran16 == 0b0010, TGran4_2/TGran16_2 == 0b0011
FEAT_D128 (VMSAv9-128, 56-bit PA)Armv9.4Armv9.3ID_AA64MMFR3_EL1.D128 (and D128_2 for stage 2)
FEAT_SYSREG128Armv9.4Armv9.3ID_AA64ISAR2_EL1.SYSREG_128
FEAT_LVA3 (56-bit VA)Armv9.4Armv9.3ID_AA64MMFR2_EL1.VARange

None of them is mandatory. Secondary sources disagree on whether D128 is “v9.3” or “v9.4”. Both are right in their own sense: the feature is part of the Armv9.4 extension, and an Armv9.3 implementation is permitted to include it. FEAT_LPA2 requires FEAT_LVA. FEAT_LVA3 requires FEAT_D128 and FEAT_LVA. Note that PARange == 0b0110 alone does not tell you that 4K/16K can use 52 bits. That needs the LPA2 values of TGran4/TGran16.

FEAT_LVA and FEAT_LPA: 52 bits with the 64K granule

The 64K granule resolves 13 bits per level, so a 48-bit VA uses a level 1 table with only 64 entries (bits [47:42]). FEAT_LVA lets TxSZ go down to 12. The level 1 table then indexes bits [51:42] and grows to 1024 entries (8KB, still a single walk start at level 1). No descriptor format changes.

FEAT_LPA needs four more output-address bits. The 64K page and block descriptors have spare bits because the OA field starts at bit 16, so:

64K granule, 52-bit OA (FEAT_LPA), block/page/table descriptor:
  bits [47:16]  OA[47:16]        (block: only the bits above the block size)
  bits [15:12]  OA[51:48]        (were RES0)
TTBRn_ELx with a 52-bit table address:
  bits [47:6]   BADDR[47:6]
  bits [5:2]    BADDR[51:48]

Two consequences matter for bring-up. First, a table pointed to by a TTBR with a 52-bit base must be at least 64-byte aligned, because TTBR bits [5:2] are no longer address bits [5:2]. Second, a 64K level 1 block now covers 4TB if PARange is 52 bits. IPS/PS (or VTCR_EL2.PS) must be 0b110 to emit these addresses. An output address with bits above the configured size set gives an Address size fault.

FEAT_LPA2: 52 bits with 4K and 16K

With 4K and 16K pages the descriptor OA field starts at bit 12 or 14, so there is no room below it. FEAT_LPA2 is enabled per regime by TCR_ELx.DS (TCR_EL1[59], TCR_EL2[32]/TCR_EL3[32] in the single-range layout, VTCR_EL2[32]). It takes the room from the shareability field:

4K/16K granule with DS == 1, block/page/table descriptor:
  bits [49:12]  OA[49:12]   (4K)      bits [49:14] OA[49:14] (16K)
  bits [9:8]    OA[51:50]   (were SH[1:0])
Shareability of every mapping in the range:
  stage 1: TCR_ELx.SH0 / SH1      stage 2: VTCR_EL2.SH0

So with DS == 1 you lose per-page shareability. Every mapping through a given TTBR uses the walk’s SH value. For most OSes that is Inner Shareable anyway. Firmware that maps some regions Non-shareable or Outer Shareable through descriptor SH must reconsider. Non-cacheable and Device mappings are treated as Outer Shareable regardless, see 6.4.

DS == 1 also:

  • allows TxSZ down to 12 (52-bit VA) for 4K and 16K;
  • adds block sizes: a level 0 block of 512GB with 4K, and a level 1 block of 64GB with 16K, when 52-bit PA is implemented;
  • changes the address operand format of the TLBI range operations, whose base address is then expressed in 64KB units. See 9.1.

DS is only meaningful for 4K and 16K. For 64K, 52-bit support is FEAT_LVA/LPA as above.

The level −1 walk

With 4K and DS == 1, a VA larger than 48 bits needs a lookup above level 0:

GranuleVA bitsLevelsTop table
4K48 (T0SZ = 16)0, 1, 2, 3L0: 512 entries, VA[47:39]
4K, DS=152 (T0SZ = 12)−1, 0, 1, 2, 3L−1: 16 entries, VA[51:48]
16K, DS=1520, 1, 2, 3L0: 32 entries, VA[51:47]
64K, LVA521, 2, 3L1: 1024 entries, VA[51:42]

Level −1 exists only for the 4K granule (the other granules fit 52 bits in their existing levels). For T0SZ 12–15, the walk starts at level −1. Faults at that level have their own encodings because LL cannot express −1: Translation fault level −1 is DFSC 0x2B, Address size fault level −1 is 0x29, and synchronous External abort on the walk at level −1 is 0x13 (5.8). For stage 2, VTCR_EL2.SL2 (bit 33) together with SL0 selects a level −1 start.

Bring-up note: Linux supports 52-bit VA kernels that fall back to 48 bits at boot when the CPU lacks the feature. With LPA2 that is not just a T1SZ change: an extra level appears or disappears, so the early page-table builder has to handle a variable number of levels. If you bring up a 52-bit-capable core on a 48-bit model (or the reverse), check ID_AA64MMFR0_EL1.TGran4 on every core before blaming the kernel. A mixed system where one cluster lacks LPA2 cannot run a DS == 1 kernel at all.

FEAT_D128: the 128-bit descriptor format (VMSAv9-128)

FEAT_D128 introduces a second translation table format, VMSAv9-128, with 128-bit descriptors. It is enabled per regime: TCR2_EL1.D128 / TCR2_EL2.D128 (bit 5) for stage 1, and VTCR_EL2.D128 (bit 38) for stage 2. The format provides:

  • 56-bit output addresses (PARange == 0b0111, IPS/PS == 0b111);
  • 52-bit VA at every granule with FEAT_LVA, and 56-bit VA with FEAT_LVA3;
  • room for a 4-bit AttrIndx (FEAT_AIE, MAIR2_ELx), a 4-bit permission overlay index, and the permission-indirection index;
  • mandatory permission indirection: there is no AP[2:1] encoding in a VMSAv9-128 leaf. FEAT_D128 requires FEAT_S1PIE (and FEAT_S2PIE when EL2 is implemented), and enabling D128 makes the PIE enable RES1, so PIR_ELx/PIRE0_ELx must be programmed before the first walk (5.5);
  • TLBIP forms of the VA- and IPA-based TLB invalidations (TLBIP VA*, RVA*, IPA*, RIPA*), which take 128-bit operands. They are part of FEAT_D128 and are encoded in the SYSP space that FEAT_SYSINSTR128 provides (FEAT_D128 requires FEAT_SYSINSTR128, FEAT_SYSREG128, FEAT_LSE128, FEAT_AIE and FEAT_TCR2).

Table geometry

A 16-byte descriptor halves the entries in a granule-sized table: 256 for 4K, 1024 for 16K and 4096 for 64K. Each level therefore resolves one bit fewer (8, 10 and 12 bits). With 4K pages a 48-bit VA now needs five lookups (starting at level −1), and a 56-bit VA needs six (starting at level −2, which has its own DFSC codes). To win those lookups back, VMSAv9-128 adds skip-level fields (SKL) in the TTBRs and in table descriptors. They let a walk skip initial levels, using a correspondingly larger table. The exact starting-level rules, the block sizes per level and the descriptor bit layout are long and have changed between DDI0487 issues. Take them from the current issue’s “VMSAv9-128” chapters, not from memory.

128-bit registers (FEAT_SYSREG128)

The base registers grow too: TTBR0_EL1, TTBR1_EL1, TTBR0_EL2, TTBR1_EL2 and VTTBR_EL2, together with PAR_EL1 and the FEAT_THE RCWMASK_EL1/RCWSMASK_EL1, have 128-bit forms. They are accessed with MRRS/MSRR (a pair of X registers) and gated by SCR_EL3.D128En (2.5, 17.3):

    // Install a 128-bit TTBR0_EL1 value held in x0 (low) / x1 (high).
    // MSRR requires an even/odd consecutive register pair.
    msrr    ttbr0_el1, x0, x1
    isb
    // Read back a 128-bit PAR after AT (see 5.9)
    mrrs    x2, x3, par_el1         // x3 bit 0 = PAR_EL1[64] = D128 format indicator

PAR_EL1 uses the 128-bit layout when PAR_EL1.D128 (bit [64]) is 1. In that layout a successful result carries PA (OA[55:12]) in bits [119:76], with ATTR, SH, NS and NSE where the 64-bit format has them. Software that only executes MRS x0, PAR_EL1 cannot see bit 64. In a D128 regime it must use MRRS. The decoding is in 5.9.

What D128 costs

  • Twice the memory per table entry, and one or two extra lookups unless SKL is used.
  • The whole translation stack needs a second implementation: descriptor builders, the walkers in your debugger scripts, TLBI wrappers (TLBIP), AT decoding, and context switching of 128-bit registers in EL3/EL2.
  • 56-bit VA reshapes the upper address bits that TBI, PAC and MTE share (13.3).

D128 is aimed at very large memory systems (CXL-attached or multi-chiplet servers). A bring-up engineer is most likely to meet it as an ID-register field that must be passed through correctly and an SCR_EL3 bit that must be set when an OS wants it.

Validation note: For each large-address feature, a directed test should drive the boundary values. Map a page whose OA has bit 51 (LPA/LPA2) or bit 55 (D128) set, and confirm the access reaches the expected PA, either through a debug memory read of the target or with AT plus PAR_EL1.PA. Then set the address one bit above the configured IPS and confirm an Address size fault at the right level. For LPA2, also check that changing descriptor bits [9:8] moves the PA and does not change shareability: a model that still decodes them as SH passes ordinary 48-bit tests and fails only here. Use the level −1 fault codes (0x29, 0x2B) as the oracle for T0SZ 12–15.

Checkpoint

Q5.7.1 A 4K-granule kernel sets TCR_EL1.DS = 1 and T1SZ = 12. Its old page-table code wrote descriptor SH = 0b11 (Inner Shareable) in bits [9:8] of every leaf. What happens to the mappings?

  • A. Nothing changes, because DS only affects TLBI operand formats
  • B. Bits [9:8] are now OA[51:50], so every mapping points 3 × 2^50 bytes above the intended PA (an Address size fault if IPS is below 52 bits), and shareability comes from TCR_EL1.SH1
  • C. The walk ignores bits [9:8] and the mappings are Non-shareable
  • D. T1SZ = 12 is invalid with 4K, so DS is ignored
Answer

B. With DS == 1, descriptor bits [9:8] are output-address bits [51:50], and shareability for the range is taken from TCR_EL1.SH0/SH1. Writing the old SH value turns into setting OA bits. If IPS is 52 bits that silently aliases a wrong PA. Otherwise it gives an Address size fault. D is wrong because LPA2 is precisely what makes TxSZ = 12 valid for 4K.

Read more: Arm ARM (DDI0487), “Translation table descriptor formats” with TCR_ELx.DS; FEAT_LPA2

Q5.7.2 A crash log shows DFSC 0x2B on a kernel that uses 4K pages. Which configuration does this point to?

  • A. A 64K-granule kernel with 52-bit VA, because only 64K has more than four levels
  • B. An Address size fault on the TTBR base address
  • C. A Translation fault at level 3 in a D128 regime
  • D. A Translation fault at level −1, which is only possible with TCR_ELx.DS == 1 and TxSZ below 16 (or in a VMSAv9-128 regime)
Answer

D. 0x2B is “Translation fault, level −1”. With VMSAv8-64 that level exists only for 4K with LPA2 and a 52-bit VA. With 64K, 52-bit VAs start at level 1 (A is backwards). An Address size fault on the TTBR is the level 0 encoding 0x00, or 0x29 for level −1.

Read more: Arm ARM (DDI0487), ESR_ELx.DFSC encodings

Q5.7.3 An OS enables TCR2_EL1.D128 but leaves PIR_EL1 at its reset value, since it “only wanted 56-bit PA”. What is the right expectation?

  • A. VMSAv9-128 leaf descriptors have no AP[2:1] encoding and permission indirection is in force, so permissions come from PIR_EL1/PIRE0_EL1 and an unprogrammed PIR gives wrong permissions or faults on the first access
  • B. Permissions fall back to the VMSAv8-64 AP bits until TCR2_EL1.PIE is set
  • C. D128 is ignored unless IPS == 0b111
  • D. The MSR to TCR2_EL1 is UNDEFINED unless PIR_EL1 is non-zero
Answer

A. FEAT_D128 depends on FEAT_S1PIE. In the 128-bit format the leaf carries a permission index, not AP bits, and enabling D128 makes PIE RES1. B describes a fallback that does not exist. C confuses the output size with the format selection.

Read more: Arm ARM (DDI0487), VMSAv9-128 descriptor formats; TCR2_EL1.D128, PIR_EL1

5.8 MMU faults and how to decode them

An MMU fault arrives as an Instruction Abort (EC 0x20 from a lower EL, 0x21 from the same EL) or a Data Abort (EC 0x24/0x25). The exception entry mechanics and the EC table are in 3.2, and the one-page card is Appendix D. This section covers the abort ISS, which tells you what kind of translation failure happened, at which level, at which stage, and whether FAR_ELx can be trusted.

The fault status code (DFSC/IFSC)

ISS[5:0] is the DFSC (data) or IFSC (instruction). Most classes encode the walk level in the low two bits (LL). Levels −1 and −2 cannot be expressed that way, so they have separate codes.

DFSCFaultLevelsTypical meaning
0x00–0x03Address size0–3An OA (TTBR base, table address, or output) exceeds IPS/PS or PARange. Level 0 means the TTBR itself
0x29 / 0x2CAddress size−1 / −2Same, for LPA2 / D128 walks (5.7)
0x04–0x07Translation0–3Invalid descriptor, VA outside the TxSZ range, or EPDn/E0PDn set
0x2B / 0x2ATranslation−1 / −2Same, for LPA2 / D128 walks
0x08–0x0BAccess flag0–3AF == 0 with hardware AF disabled (5.6)
0x0C–0x0FPermission0–3AP/PIE/POE/XN/PAN check failed (5.5)
0x10Synchronous External abort, not on a walk–The access itself got an error response (3.4, 16.7)
0x11Synchronous Tag Check Fault–MTE (13.5)
0x12, 0x13, 0x14–0x17Synchronous External abort on a walk−2, −1, 0–3The descriptor read (or hardware update) got an error
0x18, 0x1B, 0x1C–0x1FSynchronous parity/ECC error (not on / on a walk)–, −1, 0–3Only when FEAT_RAS is not implemented. With RAS these are reserved, and errors are reported as SEA
0x21Alignment–Unaligned access to Device memory, SCTLR_ELx.A, or an exclusive/atomic alignment rule
0x23, 0x24–0x27Granule Protection Fault on a walk−1, 0–3RME: the descriptor’s PA is not accessible in this PAS (12.4)
0x28Granule Protection Fault, not on a walk–RME: the output PA is not accessible in this PAS
0x30TLB conflict abort–Overlapping TLB entries, usually a break-before-make violation (9.2)
0x31Unsupported atomic hardware update–The walker’s AF/dirty RMW is not supported on the table memory
0x34, 0x35IMPLEMENTATION DEFINED (lockdown; unsupported exclusive or atomic)–0x35 usually means an exclusive or atomic to memory whose type or target cannot support it (10.1)

Two distinctions carry most of the diagnostic value:

  • Translation vs Address size. A Translation fault means the walk found nothing valid. An Address size fault means it found something but the address is too wide for the configuration. The first points to the tables, the second to IPS/PS, the TTBR value or the physical memory map.
  • External abort on a walk vs not on a walk. 0x14–0x17 say the walker’s read of the table failed: tables in memory that does not respond, is not yet initialised, or is blocked by a TZC/firewall for the walk’s security attribute. 0x10 says the translation succeeded and the target access failed.

The other ISS fields

Data Abort ISS (EC 0x24/0x25); the Instruction Abort ISS is the subset marked †:

BitsFieldMeaning
[24]ISVBits [23:14] hold a valid instruction syndrome
[23:22]SASAccess size: byte, halfword, word, doubleword
[21]SSEThe load sign-extends
[20:16]SRTTransfer register number
[15]SF64-bit register transfer
[14]ARAcquire/release semantics
[13]VNCRFault on an FEAT_NV2 access through VNCR_EL2 (11.2)
[12:11]SET†With FEAT_RAS, the error state of a synchronous External abort (recoverable, uncontainable, restartable)
[10]FnV†FAR is not valid (meaningful only for External aborts)
[9]EA†IMPLEMENTATION DEFINED classification of an External abort
[8]CMFault on a cache maintenance instruction, or on an AT instruction’s stage 2 walk
[7]S1PTW†Stage 2 fault on a stage 1 table walk
[6]WnRWrite (1) or read (0)
[5:0]DFSC/IFSC†Fault status, above

ISS2 (ESR_ELx[55:32]) adds bits for newer features, for example DirtyBit [5] (a PIE dirty-state permission fault), Overlay [6] (a POE overlay fault), GCS [8], TagAccess [9], TnD [10] and HDBSSF [11]. A permission fault that you cannot explain from AP/XN alone usually has one of these set.

Reading the fields correctly

  • WnR with CM or S1PTW. Faults on cache maintenance instructions report WnR = 1 whatever the instruction. With S1PTW = 1, WnR describes the walker’s access to the stage 1 table (which may be a hardware AF/dirty write), not the instruction’s access. Linux’s esr_dabt_iswrite() carries the comment “Always check for S1PTW before using this”.
  • ISV and emulation. A hypervisor emulating MMIO decodes the access from SAS/SSE/SRT/SF/AR without fetching the guest instruction. The architecture provides a valid syndrome only for a qualifying single-register load or store (no writeback, not a pair, not SIMD/FP, not an exclusive) that faults at stage 2. For anything else ISV = 0, and the hypervisor must decode the instruction or refuse, as KVM does when a guest uses LDP or a post-indexed store to a device. Do not rely on ISV for faults taken to EL1 or EL3.
  • VNCR = 1 means the fault was taken on a memory access that FEAT_NV2 generated by redirecting a guest hypervisor’s system register access to the page at VNCR_EL2. It was not a fault on the instruction’s operand.

Which address registers are valid

RegisterHoldsValid when
FAR_ELxFaulting VAInstruction and Data Aborts, PC alignment, watchpoints. Not valid if FnV = 1 (some External aborts). Not written for SError
HPFAR_EL2Faulting IPA (FIPA, bits [47:4] = IPA[55:12]; NS [63])Stage 2 faults taken to EL2: Translation, Access flag and Address size faults, and any fault with S1PTW = 1. For a stage 2 Permission fault that is not on a stage 1 walk, HPFAR_EL2 may be UNKNOWN
PFAR_ELx (FEAT_PFAR)Faulting PA, with NS/NSESynchronous External aborts and SErrors, when the syndrome’s PFV indication says it is valid. The address may be anywhere within an IMPLEMENTATION DEFINED naturally aligned granule

Notes on each:

  • FAR_ELx gives the VA only to page granularity in some cases. For accesses that span pages (unaligned, LDP, DC ZVA, SVE contiguous loads), it can hold an address inside the access other than its start. The FAR_ELx description in DDI0487 gives the exact rules. With TBI enabled, a Data Abort’s FAR includes the address tag. The exception is a synchronous MTE Tag Check fault, for which bits [63:60] are UNKNOWN unless FEAT_MTE_TAGGED_FAR is implemented (13.3).
  • HPFAR_EL2.FIPA holds only IPA[N:12]. The page offset comes from FAR_EL2[11:0]. When HPFAR_EL2 may be UNKNOWN (a stage 2 Permission fault), KVM recomputes the IPA by running AT S1E1R on FAR_EL2 (5.9). Some older cores had errata that made even the “valid” cases unreliable, for example Cortex-A57 erratum 834220, which KVM works around the same way.
  • FEAT_PFAR is an Armv8.9 extension, OPTIONAL from Armv8.8 (ID_AA64PFR1_EL1.PFAR). It provides PFAR_EL1, PFAR_EL2 and the PFAR_EL12 alias. Its main use is RAS: correlating a synchronous External abort with the memory controller’s error record without walking tables in the handler. Access from lower ELs is controlled by fine-grained traps (FEAT_FGT2).

Worked decode

ESR_EL1 = 0x0000_0000_9600_0045   FAR_EL1 = 0xffff_8000_1234_5678
  EC  [31:26] = 0x25   Data Abort, same EL
  IL  [25]    = 1      32-bit instruction
  ISV [24]    = 0      no syndrome (normal at EL1)
  WnR [6]     = 1      write
  DFSC[5:0]   = 0x05   Translation fault, level 1
=> a store to a TTBR1 address whose level 1 descriptor is invalid (bit[0] == 0, or a block
   encoding where the granule does not permit level 1 blocks). Read TTBR1_EL1 and walk: L0 index = VA[47:39], L1 index = VA[38:30].

ESR_EL3 = 0x8600_000F   FAR_EL3 = 0x0000_0000_0400_1000
  EC = 0x21 Instruction Abort, same EL;  IFSC = 0x0F  Permission fault, level 3
=> fetching from a page mapped XN at EL3 (or writable with SCTLR_EL3.WXN = 1).

Bring-up triage table

SymptomFirst suspectsConfirm with
Instruction Abort, IFSC 0x04–0x07, FAR = the instruction after MSR SCTLR_ELxThe code that enables the MMU is not identity-mapped. Or TTBR0 points at the wrong table, or T0SZ implies a different start level than the tables were built forWalk by hand from TTBRn using T0SZ (5.4). Before setting M, dry-run the same tables in the EL1&0 regime with AT S1E1R on the PC. AT S1E3R with SCTLR_EL3.M == 0 only reports the flat MMU-off mapping (5.9)
Data Abort, level 0 Translation fault right after MMU onTTBR0 vs TTBR1 range confusion, EPD0 = 1, or tables written with caches off but walked as cacheable, so the walker read stale linesTCR_ELx, TTBR values. Clean the tables to PoC or match the walk attributes (9.3)
Address size fault, level 0 (0x00)TTBR base above IPS/PS, or PS left at its reset valueTCR_ELx.PS/IPS against the DRAM base
Access flag fault (0x09–0x0B)Hand-built descriptor without bit 10Dump the leaf descriptor
Alignment fault (0x21) in early CData accesses with the MMU off are Device-nGnRnE; compiler-generated unaligned access or memcpy (build with -mstrict-align). Or DRAM mapped through a Device AttrIndxSCTLR_ELx.M/C, MAIR_ELx slot (6.5)
SEA on walk (0x14–0x17)Tables in DRAM before the controller is trained, or in memory a TZC/firewall blocks for the walk’s NS attributeInterconnect error logs. Move the tables to SRAM
Permission fault on a fetch at EL1/EL2PXN, WXN, the implicit PXN on EL0-writable pages, or the GCS/BTI page attributesISS2 bits, descriptor PXN/UXN, SCTLR_ELx.WXN
0x30 TLB conflictChanging block ↔ table, or the output address, without break-before-make9.2
0x35 on a spinlock before the MMU is onExclusive to Device or Non-cacheable memoryUse locks that do not need exclusives early (TF-A’s bakery lock, 10.4)
0x24–0x28 GPFGPT marks the PA for another PAS, or the GPT is not yet enabled correctlyGPCCR_EL3, GPTBR_EL3, the GPT entry for the PA
Guest stage 2 fault with S1PTW = 1The guest’s page tables live at an IPA that stage 2 does not mapHPFAR_EL2 gives the table’s IPA

More end-to-end examples are in 18.1, and the “dead after SCTLR.M = 1” playbook is in 18.3.

Validation note: Build a fault-matrix test. For each DFSC class you can provoke (Translation and Access flag at each level, Address size at level 0 via TTBR and at the leaf via OA, Permission with and without PAN, Alignment, TLB conflict by deliberately skipping BBM), make the vector handler log ESR, FAR, HPFAR/PFAR when relevant, and ELR, and compare them against an expected table. Pre-silicon, the common failures are a wrong level in LL (the model reports the level where it detected the fault, not the level of the invalid descriptor), S1PTW not set on stage 2 faults during a stage 1 walk, and FnV or FAR mismatches on External aborts. The harness pattern is in 18.5.

Checkpoint

Q5.8.1 BL31 sets SCTLR_EL3.M = 1. The next exception has ESR_EL3.EC = 0x21, IFSC 0x06, and FAR_EL3 equal to the address of the instruction after the MSR. What does this tell you first?

  • A. The ISB after the MSR is missing, so the old translation regime is still in use
  • B. The tables are fine, but MAIR_EL3 maps the code as Device, so it cannot be fetched
  • C. The instruction fetch after the enable found no valid descriptor at level 2: the running code is not mapped (usually not identity-mapped) in the new tables
  • D. The page is mapped but marked XN
Answer

C. EC 0x21 is an Instruction Abort at the same EL, and IFSC 0x06 is a Translation fault at level 2. The fetch of the next instruction, now translated, found an invalid level 2 descriptor. A is backwards: a fault on translation shows that the new regime is in use. D would be a Permission fault (0x0C–0x0F). B: fetching from Device memory that is not marked execute-never is CONSTRAINED UNPREDICTABLE, and the permitted outcomes do not include a Translation fault at the level where a valid descriptor exists.

Read more: Arm ARM (DDI0487), ESR_ELx ISS encoding for an exception from an Instruction Abort

Q5.8.2 A hypervisor gets a stage 2 Data Abort with S1PTW = 1, WnR = 1, DFSC 0x07. The guest executed a load. How should the hypervisor interpret this?

  • A. The guest’s stage 1 walk (possibly a hardware AF/dirty update to the guest table) touched an IPA with no valid stage 2 level 3 entry. HPFAR_EL2 gives that table’s IPA, and WnR describes the walker’s access, not the load
  • B. The load is to an MMIO region, so the hypervisor should emulate it using SRT
  • C. WnR = 1 with a load means that the syndrome is corrupt
  • D. It is a stage 1 fault and should be reinjected into the guest
Answer

A. S1PTW = 1 means that the stage 2 fault happened on the stage 1 walk, so the faulting IPA is a guest table address, reported in HPFAR_EL2. WnR reflects the walk access, which can be a write when the guest’s hardware AF/dirty management updates its descriptor. B would require the fault to be on the data access itself, with ISV = 1.

Read more: Arm ARM (DDI0487), ESR_EL2.ISS.S1PTW, HPFAR_EL2

Q5.8.3 Early firmware takes DFSC 0x15 on its first access to a DRAM-backed variable after turning on the MMU, with tables placed in DRAM. Which is the best first hypothesis?

  • A. The variable’s page is missing, so the fault is a Translation fault at level 1
  • B. The walker’s read of the level 1 table got an External abort: the DRAM holding the tables (or the path to it, such as a TZC region or an untrained controller) is not usable for that access
  • C. The leaf descriptor has AF = 0
  • D. IPS is too small for the DRAM address
Answer

B. 0x15 is a synchronous External abort on a translation table walk at level 1. The descriptor read failed, which says nothing about the descriptor’s contents. A Translation fault at level 1 would be 0x05, and an Address size fault would be 0x01. Check the memory controller and TZC configuration, or move the tables to SRAM to bisect.

Read more: Arm ARM (DDI0487), ESR_ELx.DFSC; 16.7

5.9 Lab: debugging translation with AT and PAR_EL1

The address translation (AT) instructions ask the MMU “what would happen if this regime accessed this VA now?” The answer is written to PAR_EL1 instead of being delivered as a fault. They are the most precise tool for translation bugs, because they report what the hardware does, including its TLB contents and walk attributes, rather than what your table dump claims. This lab uses them from EL3 to dry-run page tables, and reproduces the five commonest descriptor mistakes.

The AT operations

All of them take a VA in Xt, write PAR_EL1, and are encoded as SYS instructions.

InstructionLowest ELRegime and stagesPermissions checked as
AT S1E0R, AT S1E0WEL1EL1&0 stage 1an EL0 read/write
AT S1E1R, AT S1E1WEL1EL1&0 stage 1an EL1 read/write, ignoring PSTATE.PAN
AT S1E1RP, AT S1E1WPEL1EL1&0 stage 1an EL1 read/write, honouring PSTATE.PAN (FEAT_PAN2: OPTIONAL from v8.1, mandatory from v8.2)
AT S1E2R, AT S1E2WEL2EL2 or EL2&0 stage 1an EL2 read/write
AT S12E0R, AT S12E0WEL2EL1&0 stage 1 and stage 2EL0
AT S12E1R, AT S12E1WEL2EL1&0 stage 1 and stage 2EL1
AT S1E3R, AT S1E3WEL3EL3 stage 1EL3
AT S1E1A, AT S1E2A, AT S1E3AEL1/EL2/EL3stage 1 of that regimeno permission check (FEAT_ATS1A, Armv8.9 extension, OPTIONAL from v8.8, ID_AA64ISAR2_EL1.ATS1A)

Behaviours that matter when you read the result:

  • Stage 1 only versus stage 1+2. S1E0/S1E1 in a regime with stage 2 enabled return the IPA. S12E0/S12E1 return the final PA with combined attributes. If stage 2 is disabled, S12 behaves like S1.
  • Stage 2 faults during a stage 1-only AT. The stage 1 walk’s own table reads still go through stage 2. When AT S1E1R executed at EL1 hits a stage 2 fault on a table read, that fault is taken to EL2 as a Data Abort with S1PTW = 1 and CM = 1, not recorded in PAR_EL1. When executed at EL2 or EL3, it is recorded in PAR with S = 1.
  • From EL3, the Security state comes from SCR_EL3. AT S1E1*/S12E1* at EL3 translate in the EL1&0 regime of the state selected by SCR_EL3.NS (and NSE with RME), using the EL1/EL2 system registers as they currently hold. They are only meaningful while those registers contain that world’s context.
  • AT reflects TLB state. An AT may be satisfied from cached TLB entries, so after a descriptor change without the TLBI it can return the old translation, just as a real access would. If AT disagrees with your manual walk of memory, suspect missing maintenance (9.1). Some models always walk memory, so they cannot show this.
  • AT is not a load. It does not raise stage 1 faults, but it can raise synchronous External aborts on walk reads. With hardware AF management enabled it may set AF.

FEAT_ATS1A exists because a debugger or hypervisor often needs the PA of a mapping it has no permission to access, for example an execute-only page or a page behind a POE overlay. Before it, software had to try R, then W, then reason about why both failed.

PAR_EL1 formats

PAR_EL1.F (bit 0) selects the layout. The 64-bit format:

BitsF = 0 (success)F = 1 (fault)
[63:56]ATTR: resulting memory attributes in MAIR encodingIMPLEMENTATION DEFINED
[55:52]RES0IMPLEMENTATION DEFINED
[51:12]PA[51:12] (bits [51:48] with FEAT_LPA/LPA2)RES0
[15] / [14] / [13] / [12](part of PA)DirtyBit (PIE) / Overlay (POE) / TopLevel / AssuredOnly (FEAT_THE)
[11]NSE (RME)RES1
[10]IMPLEMENTATION DEFINEDRES0
[9]NSS: fault was at stage 2
[8:7]SH: resulting shareability[8] PTW: stage 2 fault on a stage 1 walk
[6:1]RES0FST: fault status, same encoding as DFSC (5.8)
[0]F = 0F = 1

PA is page-granular. Add VA[11:0] (for 4K) yourself. NS (and NSE) report the output physical address space for regimes where that is defined, and are UNKNOWN in some others (for example NS for a Non-secure regime). With FEAT_D128 the register is 128 bits wide. When PAR_EL1.D128 (bit [64]) is 1, a successful result holds PA = OA[55:12] in bits [119:76], with ATTR, SH, NS and NSE where the 64-bit format has them. A fault result keeps the 64-bit fault layout in bits [63:0]. Read it with MRRS (5.7).

The ISB before reading PAR

AT writes PAR_EL1 as a side effect. That is an indirect write of a system register, and a direct read (MRS) is only guaranteed to observe it after a context synchronization event. So the sequence is always:

    at      s1e1r, x0
    isb                     // without this, MRS may return the previous PAR value
    mrs     x0, par_el1

The ISB rules are in 7.8. An ISB is also needed before the AT if you have just written TTBR/TCR/MAIR/SCTLR, so that the AT uses the new values. Some cores add errata on top. Linux’s read_sysreg_par() inserts a DMB SY around the PAR read for Cortex-A77 erratum 1508412.

Security note: PAR_EL1 belongs to the EL1 context. TF-A saves and restores it per world for this reason. EL3 debug or RAS code that runs AT and then returns to the same world without a context restore has overwritten that world’s PAR_EL1. That breaks any in-flight AT/MRS sequence in the lower EL, and in the other direction it can expose a translation result across worlds. Save PAR_EL1 before using AT at EL3 and restore it afterwards.

Using AT from a debugger

An external debugger can execute AT in Debug state through the ITR (EDITR) and then read PAR_EL1. Arm Development Studio’s MMU view and most JTAG tools use this, or a walk of the tables in memory, or both. Know which one your tool uses. A table-reading walk shows memory contents. An AT shows what the MMU does, including stale TLB entries and the walk’s cacheability. When they disagree, the difference is the bug.

QEMU’s gdbstub cannot execute instructions for you, but the HMP monitor (reachable from gdb as monitor <cmd>) provides:

  • monitor gva2gpa <va>, which translates using the current CPU’s current regime (stage 1 and 2);
  • monitor xp /4gx <pa>, which dumps descriptors by physical address;
  • -d int on the command line, which prints ESR, FAR and ELR for every exception taken.

QEMU has no info tlb or info mmu monitor command for Arm targets (those are x86/PPC/SPARC-only), and -d mmu only logs PMSA (M- and R-profile MPU) lookups, not VMSA walks. On A-profile, use gva2gpa, xp, and AT in your own code.

Lab

Everything runs at EL3 on QEMU virt or FVP Base RevC. The trick is to dry-run the tables in the Secure EL1&0 regime. start.S first sets SCR_EL3.RW = 1. Without it EL1 is AArch32, and AT S1E1R from EL3 would translate with the AArch32 regime’s formats. EL3 then writes TTBR0_EL1, TCR_EL1, MAIR_EL1 and SCTLR_EL1.M = 1 (nothing runs at EL1) and probes with AT S1E1R. A broken table produces a PAR value, not a dead EL3. The same technique validates real firmware tables before the MSR SCTLR_EL3 that would make the mistake fatal.

Files are in labs/part05/ (see Lab setup for toolchains).

start.S

    .section .text.boot, "ax"
    .global _start
_start:
    mov     x0, #0x430          // SCR_EL3: RW=1 (EL1 is AArch64), RES1 [5:4], NS=0 (Secure)
    msr     scr_el3, x0
    msr     hcr_el2, xzr        // matters only for extension 1 (NS=1); reset value may be UNKNOWN
    isb
    ldr     x0, =__stack_top
    mov     sp, x0
    bl      main
1:  wfe
    b       1b

    .text
    .global at_s1e1r
at_s1e1r:                       // uint64_t at_s1e1r(uint64_t va)
    at      s1e1r, x0
    isb
    mrs     x0, par_el1
    ret

    .global el1_regime_install  // (ttbr0, tcr, mair)
el1_regime_install:
    msr     mair_el1, x2
    msr     tcr_el1, x1
    msr     ttbr0_el1, x0
    ldr     x3, =0x30d00801     // SCTLR_EL1: RES1 bits + M=1 (C=0, I=0)
    msr     sctlr_el1, x3
    dsb     ish                 // descriptor stores visible to the walker
    tlbi    alle1               // drop any cached EL1&0 entries (SCR_EL3.NS selects the state)
    dsb     ish
    isb                         // new EL1 regime visible to subsequent AT
    ret

lab.c

#include <stdint.h>

#ifdef PLAT_FVP
#define UART_BASE 0x1c090000UL
#define DRAM_BASE 0x80000000UL
#else                                   /* QEMU virt */
#define UART_BASE 0x09000000UL
#define DRAM_BASE 0x40000000UL
#endif

#define BLK     0x1ULL                  /* block descriptor, bits[1:0] = 01 */
#define TBL     0x3ULL                  /* table descriptor, bits[1:0] = 11 */
#define AF      (1ULL << 10)
#define SH_IS   (3ULL << 8)
#define IDX(n)  ((uint64_t)(n) << 2)
enum { MT_NORMAL = 0, MT_DEVICE = 1 };
#define MAIR    0x00000000000000ffULL   /* Attr0 = 0xFF Normal WB, Attr1 = 0x00 Device-nGnRnE */
/* T0SZ=32 (4GB, start level 1), IRGN0/ORGN0=WBWA, SH0=IS, TG0=4K, EPD1=1, TG1=4K, IPS=40-bit */
#define TCR     0x280803520ULL

static uint64_t l1[512] __attribute__((aligned(4096)));
static uint64_t l2[512] __attribute__((aligned(4096)));
extern uint64_t at_s1e1r(uint64_t va);
extern void el1_regime_install(uint64_t ttbr, uint64_t tcr, uint64_t mair);

/* -nostdlib: GCC may still emit calls to these for aggregate initialisers such as c[] below */
void *memcpy(void *d, const void *s, __SIZE_TYPE__ n) { char *p = d; const char *q = s; while (n--) *p++ = *q++; return d; }
void *memset(void *d, int v, __SIZE_TYPE__ n) { char *p = d; while (n--) *p++ = (char)v; return d; }

static void putc_(char c) { *(volatile uint32_t *)UART_BASE = c; }
static void puts_(const char *s) { while (*s) putc_(*s++); }
static void hex(uint64_t v) { puts_("0x"); for (int i = 60; i >= 0; i -= 4) putc_("0123456789abcdef"[(v >> i) & 0xf]); }

static void probe(const char *what, uint64_t va)
{
    uint64_t par = at_s1e1r(va);
    puts_(what); puts_(" va="); hex(va);
    if (par & 1) {
        puts_("  FAULT fst="); hex((par >> 1) & 0x3f);
        puts_(" ptw="); putc_('0' + ((par >> 8) & 1));
        puts_(" s="); putc_('0' + ((par >> 9) & 1));
    } else {
        puts_("  pa="); hex((par & 0x000ffffffffff000ULL) | (va & 0xfff));
        puts_(" attr="); hex(par >> 56);
        puts_(" sh="); putc_('0' + ((par >> 7) & 3));
    }
    puts_("\n");
}

int main(void)
{
    const uint64_t probe_va = DRAM_BASE + 0x20000000;        /* level 2 index 256 */
    const uint64_t good = probe_va | BLK | IDX(MT_NORMAL) | SH_IS | AF;
    struct { const char *name; uint64_t l2e; uint64_t tcr; } c[] = {
        { "good        ", good,                                   TCR },
        { "1 AttrIndx  ", (good & ~IDX(7)) | IDX(MT_DEVICE),      TCR },
        { "2 no AF     ", good & ~AF,                             TCR },
        { "3 misaligned", good | 0x100000,                        TCR },
        { "4 SH=NSH    ", good & ~SH_IS,                          TCR },
        { "5 T0SZ=16   ", good,                       (TCR & ~0x3fULL) | 16 },
    };

    for (int i = 0; i < 512; i++) { l1[i] = 0; l2[i] = 0; }
    l1[0] = 0x0 | BLK | IDX(MT_DEVICE) | AF;                  /* first GB: MMIO */
    l1[DRAM_BASE >> 30] = (uint64_t)(uintptr_t)l2 | TBL;
    for (int i = 0; i < 512; i++)
        l2[i] = (DRAM_BASE + ((uint64_t)i << 21)) | BLK | IDX(MT_NORMAL) | SH_IS | AF;

    for (unsigned k = 0; k < sizeof c / sizeof c[0]; k++) {
        l2[256] = c[k].l2e;
        el1_regime_install((uint64_t)(uintptr_t)l1, c[k].tcr, MAIR);
        probe(c[k].name, probe_va + 0x1234);
    }
    el1_regime_install((uint64_t)(uintptr_t)l1, TCR, MAIR);
    probe("unmapped GB ", 0xc0000000);                        /* l1[3] == 0 on QEMU */
    probe("beyond T0SZ ", 0x100000000ULL);                    /* VA[63:32] != 0 */
    return 0;
}

link.ld (set LOAD_ADDR to 0x40080000 for QEMU or 0x80080000 for FVP):

ENTRY(_start)
SECTIONS {
  . = LOAD_ADDR;
  .text   : { *(.text.boot) *(.text*) }
  .rodata : { *(.rodata*) }
  .data   : { *(.data*) }
  .bss    : ALIGN(4096) { *(.bss*) *(COMMON) }
  . = ALIGN(16); . += 0x4000; __stack_top = .;
}

Build and run on QEMU:

CFLAGS="-O1 -ffreestanding -nostdlib -mstrict-align -mgeneral-regs-only -fno-tree-loop-distribute-patterns"
aarch64-none-elf-gcc $CFLAGS -Wl,--defsym=LOAD_ADDR=0x40080000 -T link.ld start.S lab.c -o lab.elf
qemu-system-aarch64 -M virt,secure=on,virtualization=on -cpu max -m 2G -nographic \
    -kernel lab.elf -d int,guest_errors -D qemu.log        # exit: Ctrl-A x

A bare-metal ELF on virt with secure=on starts at EL3 at its entry point. -mstrict-align is not optional here: with SCTLR_EL3.M = 0, EL3’s own data accesses (stack included) are Device-nGnRnE, and an unaligned compiler-generated access would be an Alignment fault (6.5).

On FVP (needs the Arm FVP download; paths vary by version):

aarch64-none-elf-gcc $CFLAGS -DPLAT_FVP -Wl,--defsym=LOAD_ADDR=0x80080000 -T link.ld start.S lab.c -o lab_fvp.elf
FVP_Base_RevC-2xAEMvA -C cluster0.NUM_CORES=1 \
    -C bp.secure_memory=0 -C bp.pl011_uart0.out_file=- -C bp.vis.disable_visualisation=1 \
    -a cluster0.cpu0=lab_fvp.elf \
    --plugin "$PVLIB_HOME"/plugins/Linux64_GCC-*/TarmacTrace.so \
    -C TRACE.TarmacTrace.trace-file=lab.tarmac

If your model version does not start at the ELF entry, set the reset address (--list-params | grep -i rvbar). To find the Tarmac switches for translation-walk and TLB records in your version, run --plugin .../TarmacTrace.so --list-params | grep -i -E 'mmu|tlb|walk'. The parameter names have changed between releases. Even without walk records, the trace shows each AT instruction followed by the PAR_EL1 register write, which is enough to check results. Remember that FVP does not model cache contents by default, so it cannot show stale-table bugs (18.4).

What you should see, and why

CaseExpected PAR_EL1What it means
goodF=0, pa = DRAM_BASE+0x2000_1234, attr = 0xff, sh = 3Baseline
1 wrong AttrIndxF=0, attr = 0x00, sh = 2 (Device memory is always reported as Outer Shareable)The translation succeeds, so nothing faults until much later: alignment faults on unaligned accesses, DC ZVA faults, exclusives that never succeed, and very slow memcpy. Always check ATTR, not just F
2 missing AFF=1, fst = 0x0a (Access flag, level 2)The level in FST is the level of the leaf. With TCR_EL1.HA = 1 the AT may instead set AF and succeed (5.6)
3 block misalignmentUsually F=0 with pa still DRAM_BASE+0x2000_1234Bits [20:12] of a level 2 block OA are RES0. Writing them gives no reliable result, and most implementations ignore them, so the mapping silently points somewhere other than the code intended. Compare pa with the intended PA, not with the descriptor
4 SH mismatchF=0, sh = 0Fine on a single core. On silicon, other cores that map the same PA as Inner Shareable lose coherency with this one (6.4, 6.6). With DS == 1, shareability comes from TCR, not the descriptor (5.7)
5 T0SZ/start-level mismatchF=1, fst = 0x04 (Translation, level 0)T0SZ = 16 starts the walk at level 0, so l1 is read as a level 0 table. Its entry 0 is a block descriptor, which is invalid at level 0 for 4K without LPA2. The reverse mistake (tables built from level 0, T0SZ implying level 1) makes the walker use a table descriptor as if it were one level lower, and usually ends in a fault or a wildly wrong pa
unmapped GBF=1, fst = 0x05Invalid level 1 descriptor
beyond T0SZF=1, fst = 0x04A VA outside the TxSZ range is reported as a level 0 Translation fault whatever the start level

DDI0487 permits PAR_EL1.ATTR and SH to report the attributes the implementation actually uses rather than the ones the descriptor and MAIR asked for. A core may therefore show a different Normal encoding than 0xff in the good case. Compare the class (Normal Write-Back, Non-cacheable or Device), not the exact byte.

Note the starting-level boundaries for 4K: T0SZ 16–24 start at level 0, 25–33 at level 1, and 34–39 at level 2 (5.3). Changing T0SZ from 32 to 25 would not break these tables. Changing it to 24 would.

Extensions:

  1. Set SCR_EL3.NS = 1 before el1_regime_install and rerun. You are now probing the Non-secure EL1&0 regime. Then set descriptor bit 5 (NS) in the Secure case and watch PAR.NS.
  2. Remove the tlbi alle1 and change l2[256] between two probes. On QEMU the AT still sees the new descriptor, because it walks memory every time. On silicon it may not, and that difference is the reason the TLBI is in the sequence.
  3. If ID_AA64ISAR2_EL1.ATS1A and ID_AA64MMFR3_EL1.S1PIE are non-zero, enable PIE (TCR2_EL1.PIE, which needs SCR_EL3.TCR2En and SCR_EL3.PIEn). Program a PIR_EL1 entry that gives EL1 no read access (for example execute-only), point the probe page at it, and compare AT S1E1R (Permission fault, fst = 0x0e) with AT S1E1A (success). This needs an assembler that knows FEAT_ATS1A, for example via -march=armv8.9-a. The PIE encodings are in 5.5.

Validation note: AT is also a target of validation, not just a tool. A directed test should check that AT agrees with real accesses for every fault class (provoke the same VA with a load, compare ESR.DFSC with PAR.FST), that S1E1RP honours PSTATE.PAN while S1E1R does not, that PAR.ATTR/SH equal the combined stage 1 and stage 2 attributes for S12E1R, and that a missing ISB is the only way to see a stale PAR. Disagreement between AT and a real access usually points to the walker’s two code paths (the one that serves AT and the one that serves loads) having diverged in the RTL or the model.

Checkpoint

Q5.9.1 EL3 firmware builds tables for its own regime and, before setting SCTLR_EL3.M, runs AT S1E3R on the PC to check them. PAR_EL1 reports success with PA == VA, even for an address the tables do not map. Why?

  • A. AT S1E3R ignores the tables and always returns a flat mapping
  • B. The ISB between AT and MRS is missing, so PAR holds a stale value
  • C. TTBR0_EL3 is not used by AT until a TLBI ALLE3
  • D. With SCTLR_EL3.M == 0, stage 1 of the EL3 regime is disabled, so AT reports the flat MMU-off translation. To dry-run tables, probe them in a regime that has its MMU enabled (for example by installing them in the EL1&0 regime and using AT S1E1R from EL3)
Answer

D. AT reports what the regime currently does, and with M == 0 that is the identity mapping with MMU-off attributes. B is a real hazard, but a stale PAR would not systematically show PA == VA for every probe. A is the overgeneralisation: AT uses the tables once stage 1 is enabled.

Read more: Arm ARM (DDI0487), AT S1E3R; “The effects of disabling address translation stages on VMSAv8-64 behavior”

Q5.9.2 A KVM-style hypervisor takes a stage 2 Permission fault with S1PTW == 0 and needs the faulting IPA. Why does it run AT S1E1R on FAR_EL2 instead of reading HPFAR_EL2, and what must the sequence contain?

  • A. HPFAR_EL2 only holds PAs, so AT is needed to get an IPA; no barrier is needed
  • B. For that fault type HPFAR_EL2 may be UNKNOWN. AT S1E1R (with the guest’s EL1 context live) returns the IPA in PAR_EL1, and an ISB is needed between the AT and the MRS PAR_EL1
  • C. HPFAR_EL2 is valid, but AT S12E1R is faster; a DSB is needed before the MRS
  • D. FAR_EL2 already holds the IPA, so the AT is only a consistency check
Answer

B. The architecture does not guarantee HPFAR_EL2 for a stage 2 Permission fault that is not on a stage 1 walk (and some errata widen that). AT S1E1R gives the stage 1 output, which is the IPA. The PAR update is an indirect write, so it needs a context synchronization event before a direct read. DSB (C) is not one. FAR_EL2 holds the VA (D).

Read more: Arm ARM (DDI0487), HPFAR_EL2, PAR_EL1; Linux __translate_far_to_hpfar()

Q5.9.3 AT S1E1R on a kernel VA returns F = 0, ATTR = 0x00, while the kernel intended Normal Write-Back memory. Which conclusion is justified?

  • A. The mapping is fine, because AT succeeded, and ATTR is IMPLEMENTATION DEFINED on success
  • B. MAIR_EL1 is irrelevant, because ATTR reports the raw AttrIndx
  • C. The leaf’s AttrIndx selects a MAIR_EL1 slot that holds Device-nGnRnE (or MAIR_EL1 itself is wrong). Expect alignment faults, DC ZVA faults and failing exclusives later, not at the access
  • D. Stage 2 has forced the memory to Device, so stage 1 cannot be at fault
Answer

C. On success, PAR_EL1.ATTR is the resulting attribute in MAIR encoding, and 0x00 is Device-nGnRnE. Either the AttrIndx is wrong or the MAIR slot is wrong, and the two are told apart by reading MAIR_EL1. D is possible only for S12E1R with stage 2 active. A stage 1-only S1E1R reports stage 1 attributes.

Read more: Arm ARM (DDI0487), PAR_EL1.ATTR; 6.5

Part 6: Memory types and attributes

Prerequisites: 5.1, 5.2 and 5.3 (translation regimes, TCR_ELx walk attributes, and where AttrIndx and SH sit in a descriptor).

If you already know: the Device G/R/E types and the MAIR encodings, skim 6.2, 6.3 and the encoding tables in 6.5. Do not skip 6.1, the “always Outer Shareable” rule in 6.4, the MMU-off consequences in 6.5, or 6.6, because Parts 7, 8, 9 and 14 build directly on them.

Why this matters for bring-up/validation: most “works on the model, fails on silicon” memory bugs in early firmware come from an attribute that permits more than the code assumed: speculation, merging, a narrower shareability domain, or a stale line created under different attributes.

Part 6 is the first of the deep-dive memory-system parts. It answers a question that Part 5 left open: once a translation succeeds, what is the PE allowed to do with the access?

6.1 starts with an explicitly non-architectural picture of a core and its interconnect: pipelines, store buffers, line-fill buffers, write buffers and home nodes. With that picture you can see where an access is “in flight”, and later parts refer back to it whenever an architectural rule needs an intuition. 6.2 to 6.4 then define the attributes precisely:

  • the Normal and Device memory types, and what each permits in speculation, merging, reordering and repetition;
  • Inner and Outer cacheability, with its allocation and transience hints;
  • the three shareability domains, including the rule that Device and Normal Non-cacheable accesses are always Outer Shareable, and what that rule means for DMB ISH versus DMB OSH around MMIO.

The last two sections are where bring-up bugs live. 6.5 covers MAIR_ELx and the fixed memory types that apply while the MMU or the D-cache is off. These defaults explain the classic early-boot faults: alignment faults, DC ZVA faults, unreliable exclusives, and why TF-A builds with -mstrict-align. 6.6 covers mismatched attributes and aliases. It explains what DDI0487 guarantees and what it does not, the rules Linux follows, and a case study of the cache maintenance needed when data crosses between caches-off and caches-on code, or between a non-coherent master and a PE. The full treatment of ordering is in Part 7, of caches and maintenance in Part 8, and of the stage 1/stage 2 attribute combination in 11.3.

6.1 A hardware mental model (non-architectural)

Everything in this section is non-architectural. DDI0487 does not describe pipelines, store buffers or line-fill buffers. It is deliberately abstract, and it defines only which outcomes are permitted, using observers, “observed by” and “complete” (7.1). A real core is one way of producing a subset of those outcomes.

So why build a hardware model at all? The abstract rules are hard to remember without one. Once you can picture where an access physically is at a given moment, most of Parts 7, 8 and 14 become predictable:

  • why the SB (store buffering) litmus outcome is allowed;
  • why a DMB is cheap and a DSB is not;
  • why a speculative load can leave a line in the cache.

The rule for using the model is simple. Use it to generate hypotheses, and use the architecture to decide correctness. If the model says “this can’t happen on my core” but the architecture allows it, the code is still wrong. The next core, or the next stepping, may do it.

The pipeline and speculation

A typical out-of-order A-profile core (for example Cortex-A7x, Cortex-X or Neoverse N/V) looks roughly like this:

 fetch ──► decode ──► rename ──► issue queues ──► execute ──► reorder buffer ──► commit (retire)
   ▲   branch predictors                          │                                │
   │   (BTB, history, return stack)              ▼                                ▼
 L1 I-cache / ITLB                        load/store unit ◄──── store buffer (post-commit)
                                                 │
                                          L1 D-cache, DTLB, line-fill buffers
                                                 │
                                          L2 (private) ─► DSU/L3 or interconnect
  • Front end. The predictors guess the next fetch address long before any branch resolves, so instruction fetch is speculative almost all the time. When the MMU is off, those fetches are treated as Normal memory (6.5). DDI0487 then limits speculative fetches to memory close to the code being executed (roughly the same or the next translation-granule-sized block), but anything in that window, such as MMIO placed right after the image, can still be fetched.
  • Out-of-order back end. Instructions execute when their operands are ready. The reorder buffer (ROB) commits them in program order. Anything that has not yet committed is speculative: it can be squashed after a mispredict, a fault on an older instruction, or an interrupt.
  • The squash is incomplete. On a squash the core restores architectural state (registers, PSTATE, memory as other observers see it). It does not restore microarchitectural state: cache lines filled by squashed loads, TLB entries, prefetcher training and predictor history. That gap is the whole of Part 14 (14.1).
  • In-order cores are not exempt. In-order cores such as Cortex-A53 and Cortex-A55 still predict branches, have non-blocking caches and buffer stores. They reorder memory accesses less, but the architecture gives them the same permissions.

The load path

  1. An address-generation unit (AGU) computes the VA. The DTLB (or a table walk, itself a sequence of memory reads) supplies the PA and the attributes.
  2. On an L1 D-cache hit, the value returns within a few cycles. On a miss, the core allocates a line-fill buffer (LFB, also called an MSHR) and sends a read request outward. Younger loads can hit under that miss, so loads return values out of program order.
  3. If the store buffer holds an older store to the same bytes, the load takes its value from the store buffer (store-to-load forwarding). The PE therefore sees its own store before any other observer can.
  4. The core tracks loads that executed early. If a snoop invalidates a line that an early load read, before that load commits, the core may replay the load. This is roughly how it enforces the ordering the architecture does require, such as same-address read-read coherence, and orderings created by barriers and acquire.

From the architecture’s point of view, a read is globally observed when its value can no longer be changed by a write to the same location from any observer. In the model, that moment is when the value is bound and the core no longer tracks the load against snoops.

The store path

A store has two buffering stages, and the difference between them matters:

StageCommitted?Visible to other PEs?What can remove it
Store queue (pre-commit)NoNeverSquash: the store simply vanishes
Store buffer (post-commit)YesNot yetNothing; it will drain
L1 D-cache line in a unique (writable) stateYesYes, through coherenceEviction or snoop moves it, but the value stays
  • Speculative stores never leave the core. Arm cores keep uncommitted stores in the store queue, and the architecture forbids speculative writes from becoming observable. Squashed stores leave no trace in memory. They can still affect timing, for example through forwarding, which is the basis of Spectre v4 (14.5).
  • Committed but not visible. A committed store waits in the store buffer until the core owns the line in a writable state. For a WB-cacheable line, this means a ReadUnique or MakeUnique transaction on CHI (8.3). Later loads to other addresses execute meanwhile. This is the store→load reordering that the SB litmus test exposes (7.3).
  • Merging. Adjacent stores can merge in the store buffer or in a write-combining buffer. For Normal Non-cacheable and Device-G* memory, that merging is the “Gathering” the attribute permits (6.2).
  • Evictions. A dirty line evicted from L1 or L2 goes through a write-back or eviction buffer. It is now “in the memory system”, but it has not necessarily reached DRAM. Data can sit in a system-level cache, or in a buffer at a home node, indefinitely.

Beyond the core: the interconnect

Outside the core, an access becomes one or more transactions: a request, possibly snoops to other caches, and a response.

  • In a DynamIQ cluster, the DSU (with an optional L3) is the first shared level.
  • In a server or AI SoC, a CMN-style mesh carries the transactions to a home node (HN-F). The home node holds the system-level cache slice and the snoop filter, and it serialises the accesses to each address.
  • Beyond the home node sit the memory controller and DRAM, or, for an MMIO address, an HN-I or bridge and then the peripheral.

The completion response for a write can come from different places:

  • Early acknowledgement. A buffer in the interconnect accepts the write and returns the response itself. This is what the “E” attribute permits.
  • Endpoint acknowledgement. The response comes from the peripheral itself, or from the point that guarantees visibility to it. nE asks for this.

The core cannot tell where a response came from. It only knows that the response has arrived.

Where is an access “in flight”?

The table below is the most useful part of this section. Keep it in mind when reading 7.5–7.9.

Location of the accessArchitecturally, roughlyWhich instruction waits for it
Uncommitted in the ROB or store queueSpeculative; not yet an architectural accessNothing needed; a squash removes it (stores only)
Post-commit store bufferExecuted; not yet observed by other PEsDMB orders later accesses behind it; DSB waits for it
L1/L2 in a coherent stateObserved by the observers in the coherence domainAlready visible to those observers
Interconnect buffer, pre-responseVisible at some point, but not completeDSB waits for the response
Endpoint (DRAM, peripheral)Complete; for nE, from the endpoint’s viewNothing further from the PE

The barrier intuitions follow from the table. They are intuitions, not definitions:

  • DMB. It stops later accesses from becoming observable before earlier ones, typically by holding or tagging them in the load/store unit and the store buffer. It does not have to wait for the buffers to drain (7.5).
  • DSB. It stalls execution until earlier accesses, and earlier cache, TLB and branch-predictor maintenance, are complete. That means waiting for responses from the far end of the interconnect, which is why a DSB can cost hundreds or thousands of cycles on a large mesh (7.6).
  • ISB. It flushes the pipeline so that later instructions are refetched under the current context. It says nothing about the memory buffers (7.8).

Bring-up note: On pre-silicon platforms the “in flight” window can be far longer or far shorter than on silicon. FVP executes each PE’s instructions in order and models no store buffer, and QEMU TCG shows at most the reorderings of its host, so both are close to sequentially consistent in practice. Emulators and FPGAs often have extreme interconnect latency ratios. A missing barrier that “works” on FVP proves nothing. A litmus run on emulation or silicon is the first real test (7.11).

Validation note: To show that the store buffer is real on a given core, run the SB litmus test (each thread does a store, then a load of the other thread’s location) without barriers. The relaxed outcome (both loads read 0) should appear within a few million iterations under litmus7 stress. If it never appears on an out-of-order core, suspect the test harness (threads not actually concurrent, or same-core affinity), not the hardware. On the PMU, L1D_CACHE_REFILL (0x0003) and BUS_ACCESS (0x0019) confirm that the lines are really ping-ponging between cores. Their absence means the test is not contending.

What this model does not cover

  • Prefetchers. Hardware prefetchers allocate lines that no instruction, speculative or otherwise, asked for. The architecture covers them under the general rule that a cacheable location can be allocated into a cache at any time (6.3).
  • Multi-copy atomicity. Whether a store becomes visible to all other observers at the same time. Armv8 is other-multi-copy atomic. In this model, that corresponds to a store buffer that is private to one PE and is not shared with siblings, whereas some POWER designs share it between SMT threads (7.2).
  • Coherence protocol details. MOESI states, snoop filters and directories are in 8.2. The mapping onto CHI transactions is in 8.3.

Checkpoint

Q6.1.1 Two cores run STR W1,[X0]; LDR W2,[X3] and STR W1,[X3]; LDR W2,[X0] respectively (both locations initially 0, W1=1). Both loads return 0. In the hardware model, what most directly explains this outcome?

  • A. Speculative execution of the loads before the branch predictor resolved
  • B. A non-coherent L1 D-cache that hid each store from the other core
  • C. Each committed store waiting in its core’s store buffer while the younger load to a different address read the coherent cache
  • D. The interconnect reordering the two stores at the home node
Answer

C. This is the SB litmus test. The architecture permits the outcome because store→load order to different addresses is not preserved without a barrier. Microarchitecturally, a post-commit store buffer causes it. B is tempting but wrong: the caches are coherent, and the stores simply have not reached them yet. There are no branches, so A does not apply.

Read more: Arm ARM (DDI0487), The AArch64 Application Level Memory Model, “Ordering relations”; herdtools aarch64.cat

Q6.1.2 A load executes speculatively down a mispredicted path, misses in L1 and allocates a line. The core then squashes it. Which statement is correct?

  • A. No architectural register or memory value changes, but the line may remain allocated in the cache
  • B. The core must evict the line on squash, or the architecture is violated
  • C. The line is allocated only if the location is Device memory
  • D. The load was never issued to the memory system, because loads are issued only at commit
Answer

A. A squash restores architectural state only. Cache allocation is microarchitectural, and the architecture permits allocating cacheable locations at any time. That is exactly the cache-timing channel behind Spectre. D describes a hypothetical “issue at commit” design, which would be far too slow; real cores issue loads early. C is backwards: Device memory is never accessed speculatively by data loads.

Read more: Arm ARM (DDI0487), “Speculative accesses” and “Cache behavior”; Arm Cache Speculation Side-channels whitepaper

Q6.1.3 A test passes on FVP and QEMU TCG but fails intermittently on an emulation platform. The failure goes away when a DMB is added between a data store and a flag store. What is the best conclusion?

  • A. The emulation platform has a coherency bug, because FVP is the Arm reference model
  • B. The DMB hides a timing difference, so the code was correct without it
  • C. FVP is wrong, because it should model the store buffer
  • D. The code depended on store→store order that the architecture does not guarantee; FVP and TCG simply never reorder those stores
Answer

D. FVP and TCG are architecturally conformant without exhibiting the reorderings the architecture permits. Passing on them is no evidence of correct ordering. A treats “the reference model never did it” as if it meant “it is forbidden”, which it does not. C is wrong because a model is not required to show every permitted behaviour.

Read more: Arm ARM (DDI0487), “Ordering requirements”; Fast Models documentation (FVP memory model limitations)

6.2 Normal and Device memory

Every data and instruction access in AArch64 has a memory type, either Normal or Device, plus further attributes.

  • Where the type comes from. The type belongs to the access, not to the physical address. With stage 1 enabled, it comes from MAIR_ELx through the descriptor’s AttrIndx (6.5). It is then possibly combined with stage 2 (11.3). With stage 1 disabled, fixed defaults apply (6.5).
  • One PA, two types. Nothing stops two VAs from giving the same PA different types. What that costs you is in 6.6.

The two types differ in one thing: what the PE and the memory system may do that the program did not literally ask for.

Normal memory

Normal memory is for locations with no side effects: reading a location twice returns the same value, as long as no one writes it in between, and reading has no effect on the location. The architecture therefore permits the PE and the memory system to:

  • read speculatively. The PE can perform loads (and instruction fetches, if the region is executable) that the program never architecturally executes, and it can read lines that no instruction asked for (prefetch).
  • allocate into caches at any time, if the location is cacheable (6.3). This includes speculative allocation.
  • merge and split accesses. Adjacent stores can be combined into one transaction. An access that is not single-copy atomic can be performed as several smaller accesses. One cache-line read can satisfy several loads.
  • reorder accesses, subject only to the ordering model of Part 7: dependencies, barriers, acquire/release and same-address coherence.
  • perform unaligned accesses. Most loads and stores may be unaligned when SCTLR_ELx.A is 0. Exclusives, acquire/release and atomics have stricter rules (10.3).

None of these freedoms changes the architectural result of a single-threaded program. They are visible only to other observers, and the ordering model governs what those observers may see.

Two things are not permitted, even for Normal memory:

  • a speculative write becoming observable;
  • a spurious write of a value the program did not write. Merging combines bytes the program did write. It does not write the bytes in between.

Device memory

Device memory is for locations where an access has side effects or where reads are not idempotent, such as FIFO pops, clear-on-read status registers and doorbells. Compared with Normal memory, Device memory adds these guarantees:

  • No speculative data access. A load or store to Device memory is performed only when the instruction is architecturally executed. This is the property that makes it safe to map a FIFO.
  • No caching. Device memory is never allocated into a cache, and there is no “cacheable Device” type.
  • Unaligned accesses always fault. An unaligned access to any Device type generates an Alignment fault, whatever SCTLR_ELx.A says: DFSC 0b100001 in ESR_ELx (5.8). DC ZVA to Device memory also generates an Alignment fault.
  • Restricted exclusives and atomics. Whether Load-Exclusive/Store-Exclusive and atomic instructions work on Device memory is IMPLEMENTATION DEFINED. They can fail, or fault with “Unsupported Exclusive or Atomic access” (6.5, 10.1).
  • Shareability is fixed. Device memory is always treated as Outer Shareable, whatever the descriptor’s SH field says (6.4).

Two caveats people get wrong

Instruction fetch. “No speculation” covers data accesses. If a Device region is executable, the PE can speculatively fetch instructions from it, and that is a read with side effects on a read-sensitive peripheral. The only architectural protection is to make every Device mapping execute-never (UXN/PXN, or XN at EL2/EL3). TF-A’s xlat library does this unconditionally for MT_DEVICE regions, and it is a common review item. With the MMU off, instruction fetches are Normal memory and there is no XN at all. The only protection is the architectural limit on how far speculative fetches may run ahead of the executed code (see 6.5), so keep read-sensitive peripherals away from boot code (14.2).

Repeated accesses. An instruction that makes several accesses, such as LDP/STP or a multi-register SIMD load or store, can be interrupted by an exception after some of its accesses have been made. It is then re-executed from the start when the exception returns, which repeats the accesses already made. On a clear-on-read or FIFO register, the repeat is a real second access. Use single-register accesses of the register’s natural width (LDR W/STR W for a 32-bit register) for anything with side effects. This is also why readl/writel-style accessors are written in inline assembly rather than left to the compiler.

The G, R and E attributes

Device memory is divided by three attributes. Each is either permitted (the letter) or forbidden (“n” plus the letter).

AttributeIf permittedIf forbidden (nX)
G: GatheringMultiple accesses (to the same or adjacent locations) may be merged into one transaction, and one load may satisfy anotherThe number and size of accesses are exactly those the program specified
R: ReorderingAccesses to the same peripheral may arrive out of program order (barriers still apply)Accesses from one PE to the same peripheral arrive in program order. “Same peripheral” is an IMPLEMENTATION DEFINED block of address space
E: Early write acknowledgementAn intermediate buffer may return the write responseThe response should come from the endpoint

The architecture defines four combinations, ordered from most to least restrictive:

TypeMAIR encodingTypical use
Device-nGnRnE0x00Strongly ordered registers. This is also the data memory type when stage 1 is off. TF-A maps all MT_DEVICE as nGnRnE
Device-nGnRE0x04General MMIO. Linux ioremap()
Device-nGRE0x08Peripherals that tolerate reordering but not merging. Rare
Device-GRE0x0CWrite-only bulk regions, such as some frame buffers or accelerator command windows, that tolerate merging but not speculation

Notes on the precise meaning:

  • nR orders by peripheral, not against Normal memory. It orders accesses to the same peripheral block by one PE. It does not order Device accesses against Normal memory, nor accesses to two different peripherals. Those need barriers (7.9). Since the block size is IMPLEMENTATION DEFINED, do not rely on nR between two register blocks that happen to be close in the address map.
  • E is a hint. DDI0487 describes the early-write-acknowledgement attribute as a hint, so an interconnect may still acknowledge a write early even when the attribute is nE. Arm recommends nE where the programmer needs a write response that reflects the endpoint. The PCIe configuration space, whose writes are non-posted, is the standard example. Even with nE, STR followed by DSB guarantees only that the write’s response has been received. It does not guarantee that the peripheral has finished acting on the write, for example by deasserting an interrupt line (7.9).
  • G applies to accesses the program actually makes. Gathering never adds speculative accesses. Device-GRE is still non-speculative. That is the difference between Device-GRE and Normal Non-cacheable, which also merges and reorders but can be read speculatively.

Normal Non-cacheable vs Device-GRE

People often choose between these two for write-combining buffers (Linux ioremap_wc() uses Normal Non-cacheable).

PropertyNormal NC (0x44)Device-GRE (0x0C)
Speculative readsPermittedNot permitted
Gathering / reorderingPermittedPermitted
Unaligned accessPermitted (if SCTLR_ELx.A=0)Alignment fault
DC ZVAPermittedAlignment fault
ShareabilityTreated as Outer ShareableTreated as Outer Shareable
ExclusivesRequires global monitor support (IMPLEMENTATION DEFINED)IMPLEMENTATION DEFINED

Use Normal NC for memory that is genuinely RAM but must bypass caches, such as DMA buffers for a non-coherent master (8.7). Use a Device type for anything where an unrequested read could be harmful.

The XS attribute (brief)

With FEAT_XS (v8.7), each access also carries an XS attribute, which marks memory that may be slow to respond. It matters for TLBI ... nXS and DSB ... nXS, which do not wait for XS=1 accesses to complete (9.1).

  • Defaults. Under the original MAIR encodings, Device, Normal Non-cacheable and Normal Write-Through memory have XS=1, and Inner and Outer Write-Back memory has XS=0. The extra encodings below exist to give exactly those XS=1 types an XS=0 variant. For mixed Inner/Outer cacheability, see the MAIR_ELx description.
  • Extra encodings. FEAT_XS adds MAIR encodings with XS=0 for Device memory and for some Normal types (6.5).

Security note: A Normal mapping of a peripheral is a covert “read anything at any time” licence for the PE’s speculation. If a Secure peripheral, or a TZASC-protected carve-out, is mapped Normal in the Non-secure world’s linear map, speculative reads can reach it. The access is blocked, but blocked transactions may be reported as asynchronous SErrors that are very hard to attribute. Map peripherals as Device and XN, and keep protected carve-outs out of other worlds’ tables entirely.

Validation note: Two directed tests are worth having for every new interconnect or peripheral bridge.

  1. Device speculation. Map a read-sensitive register (a counter that increments on read, or a FIFO) as Device-nGnRE behind a mispredicted branch, and check that the counter does not move. Repeat with a Normal NC mapping to prove that the test can detect speculation.
  2. Gathering. Issue two adjacent STRH to an nG mapping and check on a bus monitor, ELA trace or RTL waveform that there are two transactions, not one merged 32-bit write.

An unexpected Alignment fault (DFSC 0b100001) on an apparently aligned access usually means the region is mapped Device when it was meant to be Normal, or that the MMU is off.

Checkpoint

Q6.2.1 A UART’s receive FIFO register pops a byte on every read. It is mapped Device-nGnRE with PXN=0 at EL1, and the code never branches to that address. Bytes are occasionally lost. What is the most plausible architectural explanation?

  • A. Device-nGnRE permits gathering, so two reads were merged into one
  • B. The region is executable, so the PE can speculatively fetch instructions from it, which pops the FIFO
  • C. nGnRE allows speculative data reads; nGnRnE is needed to forbid them
  • D. The early write acknowledgement attribute allows reads to be repeated
Answer

B. Device memory forbids speculative data accesses, but not speculative instruction fetch from an executable region. Device mappings must be XN. C is the tempting error: no Device type, including nGnRE, is ever speculatively read for data. The G/R/E attributes concern merging, ordering and write responses, not speculation. A is wrong because “nG” forbids gathering.

Read more: Arm ARM (DDI0487), “Device memory” and “Execute-never controls”

Q6.2.2 A driver does STR W1, [X0] (Device-nGnRnE) to clear an interrupt status bit, then DSB SY, then exception return. The interrupt still re-fires once. Which statement is correct?

  • A. nGnRnE guarantees the peripheral has acted on the write before the STR retires, so the GIC must be at fault
  • B. The DSB was unnecessary, because nE already makes the store complete before the next instruction
  • C. Using nGnRE instead would fix it, because early acknowledgement is faster
  • D. The DSB guarantees only that the write’s response was received; the peripheral may not have deasserted its line yet, so a read-back of the device (or a status poll) is needed
Answer

D. Completion means the write response was received. With nE, that response should come from the endpoint, but E is a hint, and the peripheral’s side effect (deasserting the interrupt) can still lag. B confuses a memory attribute with a barrier: nothing makes the PE wait for a store except a DSB, or a dependent read. A overstates what nE promises.

Read more: Arm ARM (DDI0487), “Early Write Acknowledgement” and “Completion of memory accesses”

Q6.2.3 A firmware routine copies a structure to a peripheral’s register window with memcpy(). It works at -O0 and takes an exception at -O2. ESR shows an Alignment fault. Why?

  • A. At -O2, the compiler emitted LDP/STP or unaligned wide accesses, and any unaligned access to Device memory faults whatever SCTLR_ELx.A says
  • B. Device memory forbids STP entirely
  • C. The window must be mapped Device-GRE to permit memcpy()
  • D. -O2 enabled speculation, which Device memory forbids
Answer

A. An optimised memcpy uses wide, possibly unaligned accesses, and possibly DC ZVA in memset. Any unaligned access to Device memory generates an Alignment fault. Even when the accesses are aligned, LDP/STP can repeat accesses after an interrupt and may not match the register widths. B overstates the rule: an aligned STP to Device memory is legal. Use explicit accessors of the register width.

Read more: Arm ARM (DDI0487), “Alignment of data accesses” and “Device memory”

6.3 Cacheability

Cacheability is an attribute of Normal memory only, since Device memory is never cached (6.2). Every Normal access carries two cacheability attributes, an Inner and an Outer one. Each says Write-Back, Write-Through or Non-cacheable, and the cacheable cases also carry allocation and transience hints. This section covers what those attributes mean and the rule that matters most for bring-up: a cacheable line may be allocated, or written back, at any time.

Inner and Outer

The architecture divides the caches in a system into an inner set and an outer set.

  • Inner attributes control the inner caches and Outer attributes control the outer caches.
  • Where the boundary sits is IMPLEMENTATION DEFINED. In a typical Arm system, the PE’s L1 and L2 and the cluster’s DSU L3 are inner. Whether a system-level cache (an SLC in the CMN home nodes) counts as “outer”, or ignores the attributes, is a property of the SoC.
  • Many cores export the attributes to the interconnect, as AXI AxCACHE or CHI MemAttr. A system cache, or a downstream bridge, then decides what to do with them.

Practical consequences:

  • Use the same attributes for both. For ordinary RAM, set Inner and Outer to Write-Back Read/Write-Allocate Non-transient (MAIR 0xFF). Inner WB with Outer NC is legal, but you are then relying on a system-specific meaning for “outer”.
  • “Outer Non-cacheable” does not mean “reaches DRAM”. The memory system may still buffer the write. The guarantee you need for a non-coherent observer comes from cache maintenance to the Point of Coherency and from DSB completion, not from outer attributes (8.4).

Write-Back, Write-Through and Non-cacheable

TypeReadsWritesNotes
Write-Back (WB)May allocate and hit in the cacheMay update only the cache. Memory is updated on eviction or cleanThe default for RAM. Lines can be dirty
Write-Through (WT)May allocate and hitUpdate the cache (if present) and also the next levelLines are never dirty in that cache level. Rarely used. Some implementations treat WT as Non-cacheable (check the TRM)
Non-cacheable (NC)Not allocatedNot allocatedStill Normal memory, with speculation and gathering permitted. Always treated as Outer Shareable when both Inner and Outer are NC (6.4)

“Cacheable” has a precise architectural meaning: the location may be held in a cache. The architecture never promises that a cacheable location is cached, or that it is not. It promises that the cache is transparent to software, within the location’s shareability domain, provided all accesses use the same attributes. The exceptions are maintenance, and observers that are not coherent with the cache.

Allocation hints and transience

Each cacheable nibble in MAIR_ELx has the form 0b00RW/0b01RW (WT/WB Transient, RW not 00) or 0b10RW/0b11RW (WT/WB Non-transient) (6.5):

  • R (Read-Allocate) and W (Write-Allocate) are hints. They suggest whether a miss on a read or a write should allocate a line.
  • Transient (encodings 0b00RW/0b01RW) is a hint that the data is likely to be used only briefly. An implementation might allocate the line with low retention priority, or into a limited set of ways, or it may ignore the hint.

These are hints, so:

  • “No allocate” does not mean “never in the cache”. A line can still get into the cache through another access, a prefetcher, speculation or another alias. The only reliable way to keep a location out of a cache is to make every mapping of it Non-cacheable, and to clean and invalidate any lines that already exist (6.6).
  • Allocation hints never change coherence or correctness. Only performance changes.
  • They are not LDNP/STNP. The non-temporal load/store pair instructions carry a per-access non-temporal hint. That hint is separate from the transient attribute in MAIR, although an implementation may treat them in a similar way.

The rule that drives Parts 8 and 9

A location with a cacheable attribute can be allocated into a cache at any time, and a line can be evicted, and if dirty written back, at any time.

Speculative loads, prefetchers and instruction fetches allocate lines whenever they like. Eviction depends on replacement policy and on other cores’ traffic. The architecture lets you rely on neither. Three things follow:

  1. Invalidation is never permanent. After DC IVAC, the line can be re-allocated before your next instruction runs. So cache maintenance is a statement about a moment, not about a state. It gives guarantees only together with an ordering argument: no one writes the location through a cacheable alias between the maintenance and the use (8.5).
  2. A dirty line is a time bomb. If memory is updated behind the cache’s back, for example by a non-coherent DMA master, a debugger, or the PE itself with caches off, a dirty line covering it can later be written back over the new data. This is why “invalidate before read” can lose data (8.7).
  3. Turning caches off does not empty them. With SCTLR_ELx.C=0, data accesses to Normal memory are treated as Non-cacheable, and the lines that are already present just stop being looked up by those accesses. If those lines are dirty, they will be written back eventually (8.8).

Controls that override the attributes

ControlEffect
SCTLR_ELx.C = 0Data accesses to Normal memory in that translation regime are treated as Non-cacheable. Stage 1 translation table walks are also treated as Non-cacheable
SCTLR_ELx.I = 0Instruction fetches are treated as Non-cacheable
SCTLR_ELx.M = 0Stage 1 disabled: data accesses become Device-nGnRnE, and instruction fetches become Normal (6.5)
HCR_EL2.CD/ID, HCR_EL2.DCStage 2 overrides for the EL1&0 regime (11.3)
TCR_ELx.IRGNn/ORGNnThe cacheability of stage 1 table walks: 00 NC, 01 WB RA WA, 10 WT RA nWA, 11 WB RA nWA (5.2)

The walk attributes are separate from the data attributes. If tables are written through a WB alias while IRGN says NC, the walker may read stale memory. This is a classic table-setup mistake; 5.9 shows how to catch it.

Cacheability and the other features

  • Exclusives. Load-Exclusive/Store-Exclusive are architecturally guaranteed to work on Write-Back cacheable, shareable memory. For Non-cacheable or Device memory, support depends on an IMPLEMENTATION DEFINED global monitor (10.1).
  • LSE atomics. On Non-cacheable memory, LSE atomics may be performed as far atomics in the interconnect, or may not be supported at all (10.2).
  • MTE. Allocation tags exist only for the Tagged Normal type, which must be Inner and Outer WB RAWA Non-transient (0xF0) (6.5, 13.4).
  • Hardware coherency. Hardware coherency keeps cacheable data coherent among the observers in its shareability domain (6.4). Non-coherent observers are handled by maintenance (8.2).

Bring-up note: On first silicon or emulation, check that the core’s exported attributes survive the interconnect. A common integration bug is a bridge that ties AxCACHE to a constant. Then the system cache allocates NC traffic, or ignores WB traffic, and DMA “coherency” or performance silently changes. Compare CHI MemAttr, or AXI AxCACHE, in a waveform for one access to each MAIR index you use.

Validation note: To confirm that a region is really treated as Non-cacheable, run a loop of loads over a buffer larger than L1 with PMEVTYPER set to L1D_CACHE_REFILL (0x0003) and MEM_ACCESS (0x0013). On a WB mapping the refill count tracks about one per cache line. On an NC mapping it should stay at zero. A non-zero count on NC means the attribute is not reaching the cache: wrong AttrIndx, MAIR_ELx written but not synchronized, or a stage 2 override. Use AT S1E1R and PAR_EL1.ATTR to see the attributes the walk actually produced (5.9).

Checkpoint

Q6.3.1 Firmware maps a buffer as Normal Inner/Outer Write-Back No-Read-Allocate, No-Write-Allocate (“so it never enters the cache”). The buffer is then given to a non-coherent DMA master without any cache maintenance. Is this safe?

  • A. No: allocation attributes are hints; the location is still cacheable and can be allocated (by speculation, prefetch or another access) and hold dirty data
  • B. Yes: No-Allocate on both read and write is architecturally equivalent to Non-cacheable
  • C. Yes, if the buffer is also marked Transient
  • D. No, but only because Outer No-Allocate is ignored; Inner No-Allocate is honoured
Answer

A. R and W are allocation hints, so the location remains Write-Back cacheable. Architecturally it may be in a cache, possibly dirty. You need either an NC mapping (with prior clean+invalidate) or the maintenance sequences of 8.7. B is the misconception the question targets. Transient is also just a hint, so C is wrong too.

Read more: Arm ARM (DDI0487), “Cacheability, cache allocation hints, and cache transient hints”

Q6.3.2 Code clears SCTLR_EL3.C and then writes a mailbox structure in DRAM that another, coherent PE will read with its caches enabled. The other PE sometimes reads stale data. What is the most likely reason?

  • A. With C=0, stores go to Device-nGnRnE memory, which is not coherent
  • B. The other PE needs SCTLR.C=0 too, because coherency requires identical SCTLR settings
  • C. The writer’s stores are now Non-cacheable while the reader’s mapping is cacheable, so a stale line in a cache can satisfy the reader; this is a mismatched-attribute alias that needs maintenance
  • D. SCTLR.C affects only instruction fetches, so the stale data must come from a missing DMB
Answer

C. With C=0 and the MMU on, data accesses to Normal memory are treated as Non-cacheable. The same PA is then accessed Non-cacheable by one PE and Write-Back by another, which is a mismatch: hardware coherency between the two is not guaranteed (6.6). A confuses C=0 with M=0. Only stage 1 disabled makes data accesses Device-nGnRnE.

Read more: Arm ARM (DDI0487), SCTLR_EL3.C; “Mismatched memory attributes”

6.4 Shareability

Cacheability says whether a location may be held in a cache. Shareability says for which observers hardware must keep that location coherent. The same concept, the shareability domain, also parameterises barriers (DMB ISH), broadcast TLB maintenance (TLBI ...IS) and the reach of cache maintenance by VA. Getting it wrong rarely fails on a single cluster and often fails on a multi-chiplet system.

The three domains

A shareability domain is a set of observers. For a location in a given domain, the architecture guarantees that all observers in that domain see the location coherently, without software maintenance.

DomainDescriptor SH[1:0]Typical membership
Non-shareable00The PE itself. Hardware is not required to keep the location coherent with any other observer
Inner Shareable11The PEs controlled by one OS or hypervisor. In practice, all application PEs in the system
Outer Shareable10The Inner Shareable domain plus other agents, for example IO-coherent masters such as a GPU, an accelerator, or a PCIe root complex behind an SMMU
(Full system)n/aAll observers. Used as a barrier domain (SY), not as a memory attribute

SH=01 is reserved. It gives CONSTRAINED UNPREDICTABLE behaviour.

The domains nest: Non-shareable ⊆ Inner ⊆ Outer ⊆ Full system. Which agents are in which domain is a property of the system design, not of the PE. DDI0487 sets the expectation that PEs under the same OS or hypervisor share an Inner Shareable domain. Platform specifications such as BSA build on that.

The SH field is in bits[9:8] of stage 1 block and page descriptors. There is one exception. With FEAT_LPA2 and TCR_ELx.DS=1, those bits hold output-address bits, and the shareability of block and page mappings comes from TCR_ELx.SH0 (TTBR0 half) or TCR_ELx.SH1 (TTBR1 half), the same fields that give the walk shareability (5.7). The shareability of the table walks themselves comes from TCR_ELx.SH0/SH1 (5.2). With stage 2, the stage 1 and stage 2 shareability combine, and the more shareable of the two wins (11.3).

Device and Normal Non-cacheable are always Outer Shareable

Data accesses to Device memory, and to Normal memory that is Inner Non-cacheable and Outer Non-cacheable, are treated as Outer Shareable, whatever the SH field says.

Why does this rule exist? With no cache involved, there is nothing to keep coherent: every access goes to the memory system, so every observer sees the same location. TF-A’s xlat library says so in a comment, and it sets OSH on Device descriptors anyway for tidiness.

Two consequences follow, and the second is the one that matters.

1. SH on such mappings is meaningless. Writing ISH or NSH on a Device or NC mapping is harmless and has no effect.

2. Barriers that must order MMIO, or NC DMA buffers, against an outside observer need an Outer Shareable or full-system domain. A barrier’s domain names the observers for which the ordering is guaranteed. Consider the classic doorbell:

    // Descriptor in Normal memory (WB if the DMA master is IO-coherent, NC otherwise)
    str     w1, [x2, #DESC_LEN]
    str     x3, [x2, #DESC_ADDR]
    dmb     oshst               // order the descriptor writes before the doorbell, for the device
    str     w4, [x5, #DOORBELL] // Device-nGnRE MMIO

The DMA engine is an observer outside the Inner Shareable domain. It is usually in the Outer Shareable domain, or merely in the full system. DMB ISHST guarantees ordering only as seen by observers in the Inner Shareable domain, so architecturally it is not enough here. DMB OSHST, DMB ST, or a DSB with the same or a larger domain is enough. This is why Linux defines dma_wmb() as dmb(oshst) and dma_rmb() as dmb(oshld), and why writel() places a dma_wmb() before the store.

A few precise caveats:

  • Same peripheral, no barrier needed. Two accesses from one PE to the same Device-nR peripheral are kept in order by the nR attribute alone (6.2).
  • Different peripherals, or a Device access against Normal memory, need barriers (7.9).
  • The full rules for reading barrier domains against shareability are in 7.5.
  • Many implementations treat ISH, OSH and SY identically. That is IMPLEMENTATION DEFINED. Code that uses ISH for MMIO ordering may pass on one core and fail on another core, or on another interconnect.

Where shareability is used besides coherence

  • DMB/DSB domains. As described above, and in 7.5–7.6.
  • Broadcast TLB maintenance. TLBI ...IS affects the TLBs of all PEs in the Inner Shareable domain. TLBI ...OS (FEAT_TLBIOS) affects the Outer Shareable domain. The DSB that follows must cover at least the same domain (9.1).
  • Data cache maintenance by VA. DC CVAC/CIVAC/IVAC act on the caches of all observers in the shareability domain of the location. For a Non-shareable mapping, the operation need only affect the caches of the issuing PE. If another core has a dirty copy of a line that you mapped NSH, your clean will not reach it (8.5).
  • Exclusives. For Non-shareable locations, the local monitor can satisfy a Store-Exclusive. For shareable locations, the global monitor or the coherence protocol is involved (10.1).
  • Instruction cache invalidation to PoU. IC IALLUIS is broadcast to the Inner Shareable domain, and IC IALLU is local (8.6).

Non-shareable: a bug that hides

Mapping shared data as Non-shareable is a latent bug. It works on many cores because the hardware keeps all WB lines coherent anyway, but that behaviour is IMPLEMENTATION DEFINED. Common ways it happens:

  • Copied tables. A per-CPU table template is copied, and someone later maps a shared region through it with SH=00.
  • Defaults. An SH=00 default in a hand-written table generator.
  • Walk attributes. Translation table walks set NSH in TCR_ELx.SH0 while the tables are shared and updated by another PE.

The symptom on a stricter implementation is stale data or a lost update that appears only across clusters or chiplets. TF-A maps all its Normal memory Inner Shareable. Linux uses ISH for all Normal mappings (PTE_SHARED).

Shareability domains in a real SoC

StructureTypical place in the domains
PEs in a DynamIQ cluster (DSU, L3)Inner Shareable, kept coherent by the DSU snoop control
Several clusters on a CMN meshInner Shareable, kept coherent by snoop filters in the HN-F home nodes
Chiplets joined by CHI C2C (or a proprietary coherent link)Normally one Inner Shareable domain spanning all chiplets, since one OS image runs on all PEs. Snoops and DVM messages cross the link (8.3, 17.5)
IO-coherent masters (ACE-Lite or CHI RN-I, CXL.cache devices)Snoop the PE caches. Inside the Outer Shareable domain, or inside the Inner Shareable domain, depending on integration
Non-coherent masters (simple DMA engines, debug MEM-AP, many accelerators)Outside every shareability domain for cacheable data. Reached only through maintenance to a point of coherency

Shareability answers “who must see this location coherently?”. A point of coherency answers “where must the data reach for a given observer to see it?”. The two are separate:

  • A non-coherent DMA master is outside every domain. What matters for it is the PoC, through DC CVAC.
  • Instruction fetch on the same PE is inside the domain, yet it needs maintenance to the PoU.

8.4 develops this comparison.

Bring-up note: On a multi-chiplet SoC, the Inner Shareable domain exists only once the coherent link is up, and once each chiplet’s snoop filters and DVM targets include the other chiplets. Before then, a secondary chiplet’s PEs are effectively in a different domain. TLBI ...IS, IC IALLUIS and DC by VA issued on one chiplet will not reach the other. Firmware must not release secondaries into shared memory until the link reports that coherency is enabled (17.5).

Validation note: To validate shareability end to end, check that the core exports it.

  • Snoopability. Each CHI request has a SnpAttr (snoopable) bit derived from cacheability and shareability. Check it in a waveform for an ISH WB access, and check that it is 0 for Device accesses (CHI requires Device to be non-snoopable; for Normal NC the value is implementation-specific, so check the core’s TRM).
  • Coherence across chiplets. Run a cross-chiplet message-passing litmus test with the data mapped ISH WB.
  • Broadcast maintenance across chiplets. Run a DC CIVAC test in which chiplet A writes a line, chiplet B cleans it to PoC, and a non-coherent observer reads DRAM.

A failure that disappears when the data is mapped NC points at snoop-filter or DVM routing configuration rather than at the PE.

Checkpoint

Q6.4.1 A descriptor maps a peripheral as Device-nGnRE with SH=00 (Non-shareable). What shareability do the accesses have, and why?

  • A. Non-shareable, so only the issuing PE is guaranteed to observe the writes
  • B. CONSTRAINED UNPREDICTABLE, because Device memory requires SH=10
  • C. Inner Shareable, the default for all Device memory
  • D. Outer Shareable, because Device memory is always treated as Outer Shareable whatever SH says
Answer

D. Device data accesses, like Normal Inner-NC/Outer-NC accesses, are uncached, so hardware treats them as Outer Shareable and ignores SH. A is the tempting reading of the field. B confuses this with the reserved encoding SH=01, which is the only one that is CONSTRAINED UNPREDICTABLE.

Read more: Arm ARM (DDI0487), “Shareable Normal memory” and “Device memory”; stage 1 SH field

Q6.4.2 Firmware writes a DMA descriptor into Normal NC memory, executes DMB ISHST, then writes a Device-nGnRE doorbell. The (non-coherent) DMA engine occasionally reads a stale descriptor. Which change is architecturally sufficient?

  • A. Change the doorbell mapping to Device-nGnRnE
  • B. Use DMB OSHST (or DMB ST), because the DMA engine is outside the Inner Shareable domain
  • C. Change the descriptor memory to SH=11 (Inner Shareable)
  • D. Add ISB after the DMB
Answer

B. Both accesses are Outer Shareable (NC and Device), and the observer that needs to see the order is outside the Inner Shareable domain. ISH guarantees ordering only for observers inside the Inner Shareable domain. C has no effect, because SH is ignored for Normal Inner-NC/Outer-NC memory. A removes early acknowledgement but does not order the descriptor writes before the doorbell, as seen by the device.

Read more: Arm ARM (DDI0487), DMB, “Shareability domains”; Linux arch/arm64/include/asm/barrier.h

Q6.4.3 A buffer shared between two PEs on different chiplets was mapped Non-shareable WB by mistake. PE B fills the first half, signals PE A, and PE A fills the second half and executes DC CVAC over the whole buffer (to PoC) and DSB SY. A non-coherent accelerator then reads stale data from DRAM. Why can this happen?

  • A. DC CVAC cleans only to the PoU, not the PoC
  • B. DSB SY does not wait for cache maintenance to complete
  • C. For a Non-shareable location, the clean is required to affect only PE A’s caches; the dirty lines PE B wrote need not be cleaned
  • D. Non-shareable memory is never written back to DRAM
Answer

C. Data cache maintenance by VA acts within the shareability domain of the location. Non-shareable means “this PE only”, so B’s dirty line is outside the scope of A’s clean. A is false, because DC CVAC cleans to the PoC. B is false too: a DSB does wait for earlier maintenance to complete. The fix is to map the buffer ISH and keep a single writer per handover.

Read more: Arm ARM (DDI0487), “Data cache maintenance instructions”, “Effects of instructions that operate by VA to the Point of Coherency”

6.5 MAIR_ELx and AttrIndx

Stage 1 descriptors do not encode the memory type directly. A block or page descriptor carries a 3-bit AttrIndx in bits[4:2]. That index selects one of eight 8-bit Attr fields in MAIR_ELx (Memory Attribute Indirection Register) of the translation regime. There are three of these registers:

  • MAIR_EL1 for EL1&0;
  • MAIR_EL2 for EL2, or for EL2&0 with VHE;
  • MAIR_EL3.

Shareability is not in MAIR. It comes from the descriptor’s SH field (6.4). Stage 2 does not use indirection: its descriptors carry MemAttr[3:0] directly, and the combination rules (including FEAT_S2FWB) are in 11.3.

The Attr encoding

Each Attr field (8 bits, written Attr<n> in DDI0487) is decoded as follows.

Attr[7:4]Attr[3:0]Meaning
0000dd00Device memory. dd: 00 nGnRnE, 01 nGnRE, 10 nGRE, 11 GRE
0000dd01With FEAT_XS: Device memory with XS=0. Otherwise UNPREDICTABLE
0000dd1xUNPREDICTABLE
oooo ≠ 0000iiii ≠ 0000Normal memory. oooo = Outer, iiii = Inner, per the table below
01000000With FEAT_XS: Normal Inner/Outer Non-cacheable, XS=0
10100000With FEAT_XS: Normal Inner/Outer WT RA nWA Non-transient, XS=0
11110000With FEAT_MTE2: Tagged Normal, Inner/Outer WB RA WA Non-transient
other0000UNPREDICTABLE

The Inner and Outer nibbles of a Normal type use the same encoding:

NibbleMeaning
00RW (RW ≠ 00)Write-Through Transient
0100Non-cacheable
01RW (RW ≠ 00)Write-Back Transient
10RWWrite-Through Non-transient
11RWWrite-Back Non-transient

Here R and W are the read-allocate and write-allocate hints (1 = allocate) (6.3).

The working set of values is small:

ValueTypeTF-A indexLinux index
0xFFNormal WB RAWA Non-transient (Inner and Outer)0 (ATTR_IWBWA_OWBWA_NTR)0 (MT_NORMAL)
0xF0Tagged Normal (MTE)n/a1 (MT_NORMAL_TAGGED)
0x44Normal Non-cacheable2 (ATTR_NON_CACHEABLE)2 (MT_NORMAL_NC)
0x00Device-nGnRnE1 (ATTR_DEVICE)3 (MT_DEVICE_nGnRnE)
0x04Device-nGnREn/a4 (MT_DEVICE_nGnRE)
    // MAIR_EL3: idx0 = Normal WB, idx1 = Device-nGnRnE, idx2 = Normal NC
    mov     x0, #0xff                 // Attr0
    mov     x1, #0x440000             // Attr1 = 0x00 (bits[15:8]), Attr2 = 0x44 (bits[23:16])
    orr     x0, x0, x1
    msr     mair_el3, x0
    isb                               // before any walk that uses the new values

Tagged Normal (0xF0)

0xF0 is the only Tagged type, and it must be Inner and Outer WB RAWA Non-transient.

  • Tag checking and tag accesses take place only for Tagged memory. Instructions such as LDG and STG operate on allocation tags only there; on Untagged memory their tag accesses are RAZ/WI (13.4).
  • Without FEAT_MTE2, 0xF0 is UNPREDICTABLE. It is not “plain WB”.
  • Linux defers the switch. Linux boots with MAIR_EL1.Attr1 = 0xFF and switches it to 0xF0 only once MTE support has been detected. mte_cpu_setup() writes MAIR_EL1 and then calls local_flush_tlb_all(), because TLB entries may hold attributes derived from the old MAIR value.

That last step generalises. Changing an Attr field that live mappings use changes the attributes of every one of those mappings, and TLBs may cache the old attributes. Treat it like a change to the descriptors: change the field only when no mapping uses it, or follow the write with ISB and TLB invalidation, and deal with any aliasing it creates (6.6).

FEAT_AIE (brief)

FEAT_AIE is a 2022 extension; for its permitted-from version, see DDI0487 A2. It extends the indirection to 16 entries:

  • TCR2_ELx.AIE=1 enables an extra AttrIndx bit in the descriptor.
  • Indices 8–15 select fields in MAIR2_ELx.
  • When 128-bit descriptors are enabled (TCR2_ELx.D128=1, FEAT_D128), TCR2_ELx.AIE is RES1 (5.7).

Memory types when the MMU or the D-cache is off

When stage 1 translation of a regime is disabled (SCTLR_ELx.M=0), the PE does not consult MAIR at all. The VA is used directly as the PA, and fixed attributes apply.

AccessAttributes with SCTLR_ELx.M=0
DataDevice-nGnRnE, whatever SCTLR_ELx.C says
Instruction fetch, SCTLR_ELx.I=1Normal, Outer Shareable, Inner/Outer Write-Through RA nWA
Instruction fetch, SCTLR_ELx.I=0Normal, Outer Shareable, Inner/Outer Non-cacheable

Special cases:

  • EL1&0 under a hypervisor. For the EL1&0 regime, HCR_EL2.DC=1 overrides the data default to Normal Non-shareable, Inner/Outer Write-Back RAWA, and the PE behaves as if HCR_EL2.VM were 1, so stage 2 translation applies (11.3).
  • MMU on, D-cache off. With M=1 and C=0, MAIR is used, but every Normal data access is treated as Non-cacheable. Device mappings stay Device.

The asymmetry between data and instruction fetch is deliberate. Data stays safe for MMIO, and instruction fetch stays fast. The fetch side is still speculative. With all stages of translation disabled, DDI0487 limits speculative instruction fetches to locations near the code being executed (roughly the same or the next translation-granule-sized block; see “Behavior of instruction fetches when all associated stages of translation are disabled”). Within that window nothing is execute-never, so an unmapped hole or a read-sensitive peripheral placed directly after the boot image can be fetched. With stage 2 enabled (EL1 with its MMU off under a hypervisor), this limit does not apply, because not all stages are disabled (14.2).

The consequences of running with data as Device-nGnRnE

Early boot code (BL1, BL31’s cold-boot entry, and the PSCI warm-boot paths before the MMU is enabled) runs with all data in Device-nGnRnE memory, including its stack. Four consequences follow.

  1. Every unaligned data access faults, whatever SCTLR_ELx.A says (DFSC 0b100001). Compilers generate unaligned accesses freely on AArch64: for packed structs, for inlined memcpy, and for merged adjacent stores. TF-A therefore builds all AArch64 code with -mstrict-align (make_helpers/cflags.mk), so the compiler never emits an access it does not know to be aligned. TF-A also sets SCTLR_EL3.A=1 at entry, so alignment checking stays on after the MMU is enabled. The flag is therefore needed in both phases. It does not cover hand-written assembly or prebuilt libraries.
  2. DC ZVA faults. DC ZVA to Device memory generates an Alignment fault, so an optimised memset cannot be used before the MMU is on. TF-A has two helpers: zeromem uses plain stores and is safe with the MMU off, while zero_normalmem uses DC ZVA and requires Normal memory.
  3. Exclusives and atomics are not guaranteed. Load-Exclusive/Store-Exclusive and LSE atomics are architecturally guaranteed only on Normal shareable WB memory. On Device memory, support is IMPLEMENTATION DEFINED: a STXR might never succeed, or the access might fault with “Unsupported Exclusive or Atomic access” (DFSC 0b110101). This is why TF-A uses bakery locks, which need only ordinary loads and stores, on paths where participating PEs may have their data caches off. Spinlocks built on exclusives are used only where every participant is coherent (10.4).
  4. Everything is slow and nothing is speculative. Every load waits for a non-gathered, non-reordered round trip. On emulation, that can make the pre-MMU phase dominate boot time. That is a reason to enable the MMU early, not to “optimise” pre-MMU code.

Bring-up note: “Works on FVP, Alignment fault on silicon or emulation right after reset” is almost always consequence 1 or 2. Look for a new C file built without -mstrict-align, a vendor library linked into BL1 or BL2, or a memset that resolves to an optimised libc version. ESR shows EC 0x25 (Data Abort, same EL) with DFSC 0b100001, and FAR_ELx gives an address that is not naturally aligned, or that is the target of a DC ZVA (5.8).

Validation note: To check that every MAIR index your firmware uses produces the attributes you meant, use AT S1E3R (or S1E1R) on one address per index, then ISB, then read PAR_EL1. PAR_EL1.ATTR (bits[63:56]) returns the resulting attributes in MAIR format, and PAR_EL1.SH returns the shareability (5.9). In RTL or emulation, also check the bus attributes of one real access per index. A mismatch between PAR_EL1.ATTR and the bus means an integration problem, not a table problem.

Checkpoint

Q6.5.1 BL31 code that runs before the MMU is enabled calls a C helper that zeroes a struct with memset, and takes an Alignment fault at a 64-byte-aligned address. What is the most likely cause?

  • A. The struct is not aligned to 16 bytes
  • B. SCTLR_EL3.A is 1; clearing it would fix the fault
  • C. The memset uses DC ZVA, which faults on Device memory, and with the MMU off all data accesses are Device-nGnRnE
  • D. DC ZVA is UNDEFINED at EL3
Answer

C. With stage 1 disabled, data accesses are Device-nGnRnE, and DC ZVA to Device memory generates an Alignment fault, even at an aligned address. B is the tempting fix, but Device-memory alignment faults do not depend on SCTLR_ELx.A. The fix is a plain-store zeroing routine (TF-A’s zeromem) until the MMU is on.

Read more: Arm ARM (DDI0487), DC ZVA; “Behavior when stage 1 address translation is disabled”

Q6.5.2 With SCTLR_EL3.M=0 and SCTLR_EL3.I=1, which statement about instruction fetch is correct?

  • A. Fetches are Normal, Write-Through cacheable and Outer Shareable, so the PE may speculatively fetch beyond the executed code, within an architecturally limited window, and nothing in that window is execute-never
  • B. Fetches are Device-nGnRnE like data accesses, so no speculative fetch occurs
  • C. Fetches are Normal Write-Back, so IC IALLU is not needed after loading code
  • D. Instruction fetch is disabled until the MMU is enabled
Answer

A. With stage 1 off, instruction fetches are Normal, Outer Shareable, and WT-cacheable when I=1. Nothing marks any region execute-never. DDI0487 limits speculative fetches in this state to locations near the code being executed, but MMIO or a hole directly after the boot image is inside that window, which is how early-boot SErrors from speculative fetches arise. B is the common assumption that “MMU off means everything is Device”, which holds only for data. C is wrong because the I-cache can still hold stale lines.

Read more: Arm ARM (DDI0487), “Behavior when stage 1 address translation is disabled”; SCTLR_EL3.I

Q6.5.3 Why does TF-A build with -mstrict-align even though most of BL31 runs with the MMU and caches enabled?

  • A. Because -mstrict-align makes generated code faster on Normal memory
  • B. Because code runs with data as Device-nGnRnE before the MMU is on, and because TF-A sets SCTLR_EL3.A=1 so alignment checking also applies after the MMU is enabled
  • C. Because Normal memory forbids unaligned accesses at EL3
  • D. Because exclusives require aligned addresses, and -mstrict-align also aligns all exclusive accesses
Answer

B. Both phases fault on unaligned accesses: Device memory always, and Normal memory once SCTLR_EL3.A=1. The flag stops the compiler from introducing such accesses. C is false, because Normal memory permits unaligned accesses unless SCTLR_ELx.A is set. D misstates the flag: it affects the compiler’s choice of ordinary loads and stores, while exclusive alignment is an architectural rule that the code must meet anyway.

Read more: Arm ARM (DDI0487), “Alignment support”; TF-A make_helpers/cflags.mk, el3_common_macros.S

6.6 Mismatched attributes and aliases

A physical location is accessed with mismatched attributes when two accesses to it differ in memory type, cacheability or shareability. This can happen through two VAs (an alias), through two translation regimes, or through two observers. Bring-up code creates such mismatches all the time, mostly without noticing:

  • the MMU-off to MMU-on transition, in which the same PA is accessed first as Device-nGnRnE and then as Normal WB;
  • SCTLR_ELx.C=0 phases, in which data accesses to Normal memory are Non-cacheable;
  • a non-coherent DMA master or a debugger writing memory that a PE then reads through its caches.

This section covers what DDI0487 says about mismatches, what it does not promise, the rules Linux follows, and the maintenance each bring-up transition needs. The maintenance instructions themselves are in 8.5, and power transitions are treated in depth in 8.8.

Aliases that are not mismatches

Two VAs that map the same PA with identical attributes are harmless for data. AArch64 data and unified caches behave as PIPT, so both VAs hit the same line, and coherence and ordering hold exactly as for one VA.

One caveat remains, and it does not concern attributes: the instruction cache may be VIPT, so instruction-side aliases need care (8.1).

What the architecture says about mismatches

DDI0487’s section “Mismatched memory attributes” takes a damage-limitation approach. It does not make mismatched aliases UNPREDICTABLE. Instead, it lists what software may lose. The losses fall into three groups:

  • Uniprocessor semantics. A read through alias B, after a write through alias A by the same PE, may not return the value written. For example, the write sits in a cache line that the NC read does not look up.
  • Coherency. Different observers may disagree about the value of the location. For example, one sees DRAM and another sees a dirty line.
  • Memory-type guarantees. Properties promised by one alias’s type may not hold when another alias has a weaker type. A Normal alias of a Device location permits speculative reads of the device and merged writes to it, which defeats the Device alias’s “no speculation” and nG guarantees.

DDI0487 also gives a recovery guarantee for the common case. If the mismatch is only in cacheability (and shareability) for Normal memory, software can restore coherence at defined handover points with cache maintenance by VA to the Point of Coherency, completed by DSB:

  • Before accessing through the less-cached alias (or before another agent reads memory), clean the location’s lines through the cacheable alias, so that no dirty data stays hidden in a cache.
  • Before accessing through the cacheable alias after memory was updated another way, invalidate the location’s lines, so that no stale line hides the new data.

Perform the maintenance through a mapping whose shareability covers every PE that may hold the line. Maintenance by VA acts within the location’s shareability domain (6.4).

Several things are not guaranteed:

  • Any steady state. A cacheable alias that stays mapped can have lines allocated speculatively at any moment after your invalidate (6.3). Maintenance gives guarantees at a handover point, provided nothing accesses the location through the other alias until the next handover.
  • Recovery for Device/Normal mismatches. No maintenance sequence makes a Normal alias of a read-sensitive device safe, because the damage (a speculative read with a side effect) has already happened.
  • That a Non-cacheable access does or does not look up the cache. Whether an NC access can hit a line allocated through a cacheable alias is not something to rely on in either direction.
MismatchWhat can go wrongRemedy
Normal WB vs Normal NC (same PE or different PEs)Stale or lost data in either directionClean (or clean+invalidate) to PoC before the NC/external side reads; invalidate before the WB side reads
Normal WB ISH vs WB NSHCoherency with other PEs not guaranteed. Maintenance by VA through the NSH alias may stay localDo not do this. Map all shared memory with one shareability
Normal (any) vs DeviceSpeculative or merged access to the device, which may have side effects. Device ordering guarantees lostDo not do this. Keep devices out of every Normal mapping
Device type A vs Device type B (for example nGnRnE vs nGnRE)The stronger alias’s G/R/E guarantees may not holdUse one Device type per peripheral
Tagged vs Untagged NormalTag checks and tag storage behaviour differ per aliasSee 13.6
Stage 1 vs stage 2 combined attributesGuest NC vs host WB is a mismatch at the PAFEAT_S2FWB, or host maintenance (11.3)

The rules Linux follows

Linux is a useful reference because it has to live with aliases. The kernel’s linear map covers all RAM as Normal WB Inner Shareable. Its rules:

  1. Never map RAM as Device. On arm64, ioremap_prot() refuses any PFN that is in the linear map, with a WARN_ON(pfn_is_map_memory(...)) and a NULL return. memremap(..., MEMREMAP_WB) of RAM returns the linear-map address instead of creating a second mapping.
  2. Keep memory that must not be accessed out of the linear map. Device-tree reserved-memory nodes with no-map (for example Secure or firmware carve-outs) are never mapped, so speculative accesses cannot reach them. Without no-map, a TZASC-protected region is in the linear map, and speculation can generate errors from it (14.2).
  3. Tolerate exactly one kind of mismatch: an NC alias with a cacheable linear alias, for non-coherent DMA. dma_alloc_coherent() for a non-coherent device cleans the buffer to the PoC (arch_dma_prep_coherent()), then maps it a second time as Normal NC and XN (pgprot_dmacoherent()). The linear alias stays cacheable but is never accessed. This relies on the handover rule above: any line speculatively allocated through the linear alias is clean, and software never reads through that alias. For streaming DMA, Linux avoids the second alias and uses maintenance on the cacheable mapping instead (8.7).
  4. Leave virtualised guests to FEAT_S2FWB. When FEAT_S2FWB is present, KVM uses stage 2 to force guest RAM to Normal WB, whatever the guest’s stage 1 attributes say. Otherwise it performs maintenance when it maps pages for the guest (11.3).

TF-A follows the same spirit with simpler means. Each region in the xlat tables has a single memory type. Device regions are always XN. Caches are flushed at the points where the MMU or cache state changes, as the case study below shows.

Bring-up case study

Case A: data written with SCTLR.C=0, read after enabling caches

Suppose BL2 (or a ROM) writes a parameter block or a loaded image while it runs with the MMU off (data accesses Device-nGnRnE) or with C=0 (Normal NC). The writes go towards memory. After BL31 enables its MMU and caches, it reads the same PA through a Normal WB mapping. Two things can be in the caches already:

  • A stale clean line for that PA. It may come from an earlier boot stage that ran with caches on, from a coherent PE, or from a system cache that keeps its contents across the boot stages. The read hits it and returns old data.
  • A stale dirty line. It is evicted later and overwrites the new data in memory. TF-A’s entry code names this exact hazard: “possible corruption of this memory by dirty cache lines in a system cache as a result of use by an earlier boot loader stage”.

Whether caches are invalidated by hardware at reset is IMPLEMENTATION DEFINED (9.3, 17.1). Even when they are, a system cache shared across stages is not reset with the PE.

The remedy is to invalidate the region by VA to the PoC, with caches off, after the last non-cacheable write and before the first cacheable access. TF-A’s BL2 and BL31 entry code does this for their own RW regions, before zeroing .bss:

    // Invalidate own RW image range before using it (caches still off)
    adr     x0, __RW_START__
    adr     x1, __RW_END__
    sub     x1, x1, x0
    bl      inv_dcache_range        // DC IVAC per line, then DSB SY

The reverse transition is just as common. Data written with caches on, and then read by a party with caches off, needs a clean to the PoC first. Examples are the next boot stage with its MMU off, a PE in warm boot, or a non-coherent master. TF-A’s image loader does flush_dcache_range() (clean+invalidate to PoC) on every loaded image, “so that it can be executed later by any CPU, regardless of cache and MMU state”. The power-down form of the same rule is in 8.8.

Case B: an image loaded by a non-coherent master, then executed

Suppose a DMA engine copies BL33 from flash into DRAM, or a debugger writes it through a MEM-AP. Neither agent snoops the PE caches. The PE then verifies the image and branches to it. There are four hazards:

  1. Dirty D-cache lines covering the destination, for example from its previous use as a heap or a buffer. They are evicted after the DMA and overwrite parts of the image.
  2. Stale clean D-cache lines. The PE’s verification reads (hash, signature) hit them and check old data. The data the PE checks is then not the data it executes.
  3. Stale lines in the I-cache, or in a unified L2/L3, which the instruction fetch hits.
  4. Lines allocated speculatively during the transfer through the cacheable mapping, for example by a prefetcher running ahead of the PE’s own accesses to adjacent memory.

The sequence that handles all four:

    // x0 = dest, x1 = size; caches and MMU on, dest mapped Normal WB ISH
    bl      flush_dcache_range      // 1. DC CIVAC to PoC: no dirty lines can be written back later
                                    //    (ends with DSB SY)
    // ... program DMA, start, wait for completion (poll a Device status reg) ...
    dsb     sy                      //    the completion read is complete before the maintenance
    bl      inv_dcache_range        // 2. DC IVAC to PoC: drop lines allocated during the transfer
                                    //    (ends with DSB SY)
    // ... verify image (reads now come from memory) ...
    ic      iallu                   // 3. invalidate the I-cache (IC IALLUIS if other PEs will run it)
    dsb     sy
    isb                             // 4. refetch the code that follows under the new I-cache state
    br      x0

Why both steps 1 and 2?

  • Step 1 removes dirty lines. It must happen before the DMA writes, because cleaning a dirty line afterwards would write it over the new data.
  • Step 2 removes clean lines that may have arrived during the transfer.

Using only “invalidate after” fails in two ways. A dirty line may be evicted during the transfer and overwrite the new data. And in some configurations DC IVAC is performed as a clean and invalidate (for example at EL1 with stage 2 enabled; see the DC IVAC description in DDI0487), which would write the dirty line back over the image. Using only “clean before” leaves the stale-hit hazard open. This is the general rule of 8.7.

Do not rely on CTR_EL0.IDC/DIC to skip step 3 for code written by a non-coherent agent. This is a conservative reading rather than a quoted rule. The bits are defined in terms of data-to-instruction coherence for this PE’s caches, and the architecture does not clearly extend them to memory changed behind the caches by a non-coherent agent. Treat step 3 as mandatory here (8.6).

Debuggers fall into two cases:

  • Through the PE. A debugger that loads through the PE (the PE halted in Debug state, executing stores) uses the PE’s data-side caches. It is coherent for data, but it still needs the I-cache step.
  • Through a MEM-AP. A debugger that writes through a MEM-AP is non-coherent, unless the AP is set up to issue cacheable, shareable transactions. The AXI-AP’s CSW has cache and domain fields for this, and their support is IMPLEMENTATION DEFINED.

Many debugger “download” commands perform the maintenance for you. Check that yours does before blaming the image.

Summary of transitions

TransitionMaintenance (by VA, to PoC unless stated)Hazard it removes
Caches on → caches off (same PE, or next stage starts with MMU off)Clean+invalidate the data that will be read, then DSBDirty data hidden from NC/Device reads
Caches off writes → caches on readsInvalidate after the writes and before enabling (or before the first cacheable read), then DSBStale clean or dirty lines from earlier stages or system caches
PE writes → non-coherent master readsClean, then DSB, then start the masterData not yet at the PoC
Non-coherent master writes → PE readsClean+invalidate before the transfer, invalidate after it, DSBDirty-line write-back over new data; stale hits
Any of the above, followed by executing the dataPlus IC IALLU/IALLUIS (or IC IVAU), DSB, ISBStale instructions

Security note: Case B hazard 2 is a time-of-check/time-of-use bug in secure boot. If the verifier hashes the image through cache lines that no longer match memory, it authenticates bytes that will not be executed. Always invalidate after the load and before measuring. Then measure and execute through the same mapping, with no writer outside the verifier between the two.

Validation note: Do not wait for a bad image to expose these hazards. Provoke them in a directed test.

  1. Plant dirty lines. Fill the destination through a WB mapping with a marker pattern, so it is in the cache and dirty. Skip step 1, DMA the real image, then force eviction by streaming a buffer larger than the LLC. Read memory through an NC alias, or a MEM-AP. Marker bytes in the image prove the write-back hazard.
  2. Count the write-backs. L1D_CACHE_WB (0x0015) and L2D_CACHE_WB (0x0018) count them during the eviction loop.
  3. Repeat with step 1 restored. The markers must disappear.

A debugger memory view that differs between “via core” and “via AP” for the same address shows that a line is dirty or stale in the PE’s caches.

Checkpoint

Q6.6.1 A non-coherent DMA engine writes an image into DRAM. Before the transfer, software executed no maintenance. After the transfer, it executes DC IVAC over the range, then DSB, and reads the image through a WB mapping. Occasionally a few cache lines of the image contain old buffer contents. What is the most likely mechanism?

  • A. The DSB after DC IVAC should have been an ISB
  • B. DC IVAC acts only on the PoU, so the system cache was not invalidated
  • C. The NC accesses of the DMA engine bypassed the shareability domain, so maintenance cannot help
  • D. A dirty line covering the destination was evicted (written back) during the transfer, after the DMA had written that memory; invalidating afterwards cannot undo a write-back that has already happened
Answer

D. Lines can be evicted at any time. A dirty line written back during or after the DMA writes overwrites the new data in memory, and the later invalidate only removes the cached copy. The fix is to clean (or clean+invalidate) before the transfer. B is wrong because DC IVAC operates to the PoC. A is wrong because a DSB is what completes the maintenance, while an ISB does not wait for it.

Read more: Arm ARM (DDI0487), “Mismatched memory attributes”, “Data cache maintenance instructions”

Q6.6.2 Why does TF-A’s BL31 invalidate its RW range (inv_dcache_range) at entry, while its caches are still disabled?

  • A. Because caches are always full of random data at reset, as the architecture requires
  • B. Because an earlier boot stage may have left lines, possibly dirty, in a cache that is not reset with the PE, such as a system cache; these could later hit, or be written back over BL31’s data once caches are enabled
  • C. Because DC IVAC is needed to enable the MMU
  • D. Because zeroing .bss with the MMU off would otherwise fault
Answer

B. This is the mismatch between “written with caches off” and “read with caches on”. Stale clean lines cause wrong reads, and stale dirty lines cause later corruption. The source comment cites dirty lines in a system cache left by an earlier stage. A overstates the case: reset invalidation is IMPLEMENTATION DEFINED, and the problem is lines left by earlier stages, not random contents. D confuses this with the DC ZVA and alignment rules for Device memory.

Read more: TF-A el3_common_macros.S / bl2_entrypoint.S; Arm ARM (DDI0487), “Mismatched memory attributes”

Q6.6.3 A platform maps a Secure-only DRAM carve-out as Normal WB in the Non-secure kernel’s linear map but never accesses it. The kernel occasionally takes SErrors that point at no particular instruction. What is the best explanation and fix?

  • A. The Normal mapping permits speculative and prefetch reads into the carve-out, which the TZASC rejects; remove it from the linear map (no-map)
  • B. The mapping is harmless because it is never architecturally accessed; the SErrors must come from a peripheral
  • C. Change the mapping to Device-nGnRnE, which makes it safe to leave mapped
  • D. Add DC CIVAC over the carve-out at boot to make the alias coherent
Answer

A. Any Normal mapping licenses speculative access. The TZASC (or GPC under RME) rejects the access, and the error can arrive as an asynchronous SError. Not mapping the region is the only robust fix. C removes data speculation but still permits speculative instruction fetch, unless the region is XN as well, and it still leaves a mapping to protected memory in the NS world. D misunderstands the problem: this is an access-permission issue, not a coherence one.

Read more: Arm ARM (DDI0487), “Speculative accesses” and “Mismatched memory attributes”; Linux Documentation/devicetree/bindings/reserved-memory

Part 7: The memory ordering model

Prerequisites: 6.1 A hardware mental model, 6.2 Normal and Device memory, 6.4 Shareability; 3.2 Entry and return for 7.8.

If you already know: if you can derive MP/SB/WRC/IRIW outcomes from aarch64.cat without looking, skim 7.1–7.3 and start at 7.4. Do not skip 7.5 and 7.6 even if barriers are familiar: they cover the recent redefinition of the barrier domain argument. If you already know C11 atomics, 7.7 mostly gives you the mapping table.

Why this matters for bring-up/validation: most “works on the model, fails on silicon” firmware bugs, and many silicon interconnect bugs, are ordering bugs, and you can only tell which kind you have if you can state what the architecture allows.

This part replaces “add barriers until it works” with the reasoning DDI0487 uses. It starts with the vocabulary: observers, observed, complete (7.1). Then it covers the two kinds of atomicity, including the 2017 move to an other-multi-copy-atomic model that makes older texts misleading (7.2). With those, the five canonical litmus tests can be decided by looking for a cycle in the “ordered-before” relation (7.3). The following sections take each source of ordering in turn, cheapest first: dependencies, DMB, DSB, acquire/release, and context synchronization with ISB (7.4–7.8). Each one says exactly what it orders, what it waits for, and what it does not do.

The last three sections apply the model. 7.9 covers Device memory and the eternal question “does the DSB mean the peripheral saw it?”. 7.10 gives the bare-metal patterns: doorbells, descriptor rings, cross-chiplet mailboxes and seqlocks. 7.11 takes litmus tests from herd7 to litmus7 on QEMU, FVP and silicon. There you learn to tell an allowed-but-unobserved outcome from a forbidden-but-observed one, which may be a silicon bug or a test bug. The Linux barrier API mapping is in Appendix C.

7.1 Observers, “observed by” and “completes”

DDI0487 specifies the memory model, and every barrier, in terms of a small set of defined words: observer, observed, globally observed, complete, Coherence order, Reads-from. Pipeline vocabulary such as “drained”, “retired”, “flushed” or “hit the bus” appears nowhere in the normative text. Before reading a barrier rule, translate it into these terms. This section defines them and ties each one to the non-architectural hardware picture in 6.1. That picture explains why a rule exists. It is never a substitute for the rule.

Observers

An observer is any agent that can issue reads or writes to memory: a PE, a DMA engine, a GPU, an accelerator, or a debugger acting through a memory access port. A shareability domain (6.4) is just a named set of observers. Every barrier with a domain option (ISH, OSH, NSH, SY) is a statement about the observers in that set.

A single PE generates more than one stream of memory effects, and the model treats them differently:

StreamModel termOrdered by DMB/DSB like loads and stores?
LDR/STR/atomics/LDAR etc.Explicit accesses (Exp in aarch64.cat)Yes
Instruction fetchImplicit, instruction-fetch effectsNo; needs IC maintenance and ISB (8.6)
Translation table walksImplicit, TTD reads (and hardware AF/DBM writes)Only through specific rules (DSB, CSE, FEAT_ETS2) (9.1)
MTE allocation-tag readsImplicit tag effectsThrough specific rules (13.4)

The consequence is easy to miss. “The PE has written the descriptor” and “the PE’s own table walker will see the descriptor” are two different claims. The walker is, for ordering purposes, close to a separate observer. That is why the TLB update sequence needs a DSB and why the instruction stream needs an ISB.

Program order, Coherence order, Reads-from

Three base relations underpin every definition.

  • Program order (po): the order of instructions in one PE’s execution, as the ISA sequential semantics define it. It is a per-PE order and says nothing about what other observers see.
  • Coherence order (co): for each location, a single total order over all writes to that location, agreed by all observers. Coherence is per location. It is the only ordering you get “for free” across observers, and only for that one location.
  • Reads-from (rf): links each read to the write whose value it returns (or to the initial value).

The model combines these into derived relations. The ones that cross observers are the external versions: rfe (read from a write by another observer), coe (a write coherence-after another observer’s write) and fre (“from-reads”: a read that returns a value coherence-before another observer’s write).

“Observed by”

DDI0487 gives “observed” two framings. Learn both, because older text (and most Arm application notes) uses the first, while the formal model in B2 uses the second.

Operational definitions. A write to a location is observed by an observer when:

  • a later read of that location by that observer returns the value written, or the value of a write coherence-after it; or
  • a later write to that location by that observer is coherence-after it.

A read of a location is observed by an observer when a later write to that location by that observer can no longer affect the value the read returns.

A read or write is globally observed for a shareability domain when it is observed by every observer in that domain.

Axiomatic definition. In the formal model (aarch64.cat, and the “Definition of the Arm memory model” in DDI0487 B2), an effect E1 is Observed-by E2 when E1 and E2 come from different observers and E2 reads from E1, or E2 is coherence-after E1, or E1 reads a value coherence-before E2. In relational form this is obs = rfe | coe | fre. Every outcome the architecture forbids comes from a cycle that the model rules out, which consists of obs edges joined by the per-PE “ordered-before” edges that dependencies, barriers and acquire/release provide (7.3).

The two framings say the same thing. Observation is about values: an observer has observed a write only once it can no longer read anything older from that location. Nothing in the definition mentions caches or buses.

“Complete”

Completion is the stronger notion, and it is what DSB waits for (7.6). DDI0487 defines it per kind of operation:

OperationComplete for a shareability domain when…
Read or writeit is globally observed for that domain, and any translation table walks associated with it are complete for that domain
TLB maintenance (TLBI)every memory access that used the invalidated entries has been observed to the extent its attributes require, and no new access using those entries can be observed
Cache maintenance by VA (DC/IC)its effects are complete for that domain, and any walks it caused are complete

Two consequences matter for firmware.

  1. Completion is relative to a domain. A store can be complete for the Inner Shareable domain while an observer outside that domain, such as a non-coherent DMA master, still sees stale memory. That is a cacheability and Point of Coherency problem (8.4), not an ordering one.
  2. For Device memory, “complete” means the write has been acknowledged, not that its side effect has happened. With the Early Write Acknowledgement attribute (E, as in nGnRE), an intermediate buffer may give that acknowledgement. Even with nE the architecture does not promise that the peripheral has acted on the write. 7.9 works this through.

The hardware picture, mapped

The mapping to the 6.1 model is approximate and non-architectural, but it builds the right intuition:

Where the store is (6.1 model)Architectural status
Executed, still speculativeNot an effect yet. No observer may see it (stores are never speculatively visible)
Retired, sitting in the store bufferThe writing PE may read it (store-to-load forwarding). No other observer has observed it
Written into a coherent L1/L2 line held uniqueObserved by all observers in the coherent domain, which is why Armv8 is other-multi-copy atomic (7.2)
Non-cacheable or Device write accepted by an interconnect bufferComplete, if that buffer is allowed to acknowledge it
Device write accepted by the peripheralComplete (nE). The side effect may still be pending

For loads: a load is complete once the value it returns is fixed and no write by any observer in the domain can change it. A load that hits in a line which can still be snooped away and replayed is, in this picture, not yet complete. This is why “loads complete” is a meaningful thing for DSB to wait for.

Validation note: Architecturally, you can only test observation through reads. A litmus test observes a write by reading it back on another PE (7.11). For completion to an endpoint, you need evidence from the device side, such as a peripheral status register, a bus trace or a CMN/interconnect PMU count. A test that “proves” a DSB made a peripheral see a write by reading the same register back from the PE proves less than it appears to: the read-back is ordered after the write by Device ordering rules, and that is a different property.

Ordering, completion and context

Every barrier rule falls into one of three bins. Keep them apart:

PropertyQuestion it answersMechanism
Ordering“Will every observer in domain D see A before B?”DMB, dependencies, LDAR/STLR, Device nR (7.4, 7.5, 7.7)
Completion“Has A finished for domain D before anything after this point executes?”DSB (7.6)
Context synchronization“Will later instructions be fetched and executed with the effects of A (a system-register write, a completed TLBI)?”ISB, exception entry/return (7.8)

A common bug is to use a property from one bin to get a result from another. A DMB cannot make a TLBI finish. A DSB does not make the PE refetch instructions. An ISB does not wait for stores.

Checkpoint

Q7.1.1 PE0 executes STR w1, [x0] to Inner Shareable, Write-Back memory and then reads the same location back with LDR w2, [x0], getting the new value. What does that read prove about observation by PE1, which is in the same Inner Shareable domain?

  • A. PE1 has observed the write, because Coherence order is the same for all observers
  • B. PE1 has observed the write, because the store must have left the store buffer for the load to return its value
  • C. Nothing: PE0 may read its own write by forwarding before any other observer has observed it
  • D. PE1 has observed the write only if the location is in a cache line PE0 holds unique
Answer

C. The model lets a PE see its own write before it is visible to others. That is the “other” in other-multi-copy atomicity. Option A confuses agreement on the order of writes with when each observer sees them. Option B assumes no store-to-load forwarding, which the architecture explicitly allows.

Read more: Arm ARM (DDI0487), B2 “Definitions” (Observer, Observed, Multi-copy atomicity)

Q7.1.2 Firmware writes a Device-nGnRE register and executes DSB SY. Which statement does the architecture actually guarantee once the DSB completes?

  • A. The write has been acknowledged as complete, possibly by an intermediate buffer, but the peripheral may not yet have acted on it
  • B. The peripheral has performed the side effect of the write
  • C. The write has reached the peripheral, because Device memory is never buffered
  • D. Nothing about the write, because DSB only orders Normal memory accesses
Answer

A. Completion for Device memory means the write has been acknowledged. With E (Early Write Acknowledgement permitted), a buffer on the path may give that acknowledgement. Even nE only moves the acknowledgement to the endpoint, and it still does not guarantee the side effect. Option C ignores the E attribute. Option D is wrong: DSB covers all explicit accesses of the required types, whatever the memory type.

Read more: Arm ARM (DDI0487), B2 “Completion and endpoint ordering”; Device memory attributes (Early Write Acknowledgement)

Q7.1.3 Why does the model treat a PE’s translation table walks as effects that ordinary load/store ordering rules do not cover?

  • A. Because walks always use Non-cacheable memory types
  • B. Because walks happen only after a TLBI, so ordering is implicit
  • C. Because walks are performed by the SMMU, not the PE
  • D. Because the walker reads descriptors independently of program order, so a store to a descriptor is not guaranteed visible to the PE’s own walks without the specific DSB/CSE rules
Answer

D. Walks are implicit accesses. They can happen speculatively and at any time, not at a program-order point. The model only orders them through particular rules (for example DSB before relying on a new descriptor, or FEAT_ETS2 in some cases). Option A is wrong: walk cacheability comes from TCR_ELx.IRGN/ORGN, and is often Write-Back.

Read more: Arm ARM (DDI0487), B2 “Definition of the Arm memory model” (implicit effects); the AArch64 VMSA chapter, ordering of translation table walks

7.2 Single-copy and multi-copy atomicity

“Atomic” has two independent meanings in DDI0487, and loose speech mixes them up:

  • Single-copy atomicity is about tearing: is one access seen as a whole by every observer, or can someone see half of it?
  • Multi-copy atomicity is about propagation: when a write becomes visible to one other observer, does it become visible to all of them?

Neither one is “atomic read-modify-write”. That is exclusives and LSE (10.1, 10.2).

Single-copy atomicity: the definition

DDI0487 defines a read or write as single-copy atomic when both of these hold:

  1. Stores: if two single-copy atomic stores overlap, then for every overlapping byte, all the writes of one store come before all the writes of the other in that byte’s Coherence order. Bytes from the two stores are never interleaved.
  2. Loads: if a single-copy atomic load overlaps a single-copy atomic store, then for the overlapping bytes the load returns either all of that store’s data or none of it. It cannot take some bytes from that store and some from a coherence-earlier write.

Note what this does not say. It says nothing about when the access becomes visible, and nothing about ordering with other locations.

Which accesses are single-copy atomic (Armv8.0 baseline)

AccessSingle-copy atomicity
LDRB/STRB, and any access at byte granularityByte
LDRH/STRH, LDR/STR (W or X) aligned to the access sizeWhole access (16, 32 or 64 bits)
Unaligned scalar access (where permitted)Each byte only, before FEAT_LSE2
LDP/STP of W registers aligned to 4Two separate 32-bit single-copy atomic accesses
LDP/STP of X registers aligned to 8Two separate 64-bit single-copy atomic accesses, not one 128-bit access (before FEAT_LSE2)
SIMD&FP load/store of ≤64 bits aligned to its sizeWhole access
SIMD&FP 128-bit (LDR q0) aligned to 8A pair of 64-bit single-copy atomic accesses
LD1/ST1 and other element/structure formsEach element, if aligned to the element size
LDXP/STXP of X registers128-bit single-copy atomic only when the STXP succeeds
LSE atomics, CAS, SWP, LDADD… alignedWhole access (CASP, from v8.1, covers 128 bits)
Translation table walk descriptor reads64-bit for the VMSAv8-64 descriptor format

The wider and unaligned cases are the subject of 10.3. These are: FEAT_LSE2 (v8.4), which makes 16-byte-aligned LDP/STP single-copy atomic and gives atomicity to unaligned accesses that do not cross a 16-byte boundary; FEAT_LSE128 (v9.4); FEAT_LRCPC3 (v8.9); 128-bit descriptors with FEAT_D128; and 64-byte LD64B/ST64B (FEAT_LS64). This page uses only the baseline.

Why firmware cares

  • Descriptor writes. A 64-bit translation table descriptor must be written with a single aligned STR Xn, never as two STR Wn halves. The walker reads 64 bits single-copy atomically. If you write two halves, the walker can read a descriptor with the new low half (valid bit set) and the stale high half (old UXN/PXN, old output address bits). In C that means a volatile uint64_t store or the project’s WRITE_ONCE. A plain assignment lets the compiler split or merge the store.
  • 128-bit values without LSE2. A 16-byte mailbox written with STP x0, x1 can be torn for a reader that does LDP x2, x3: the reader can see the new first doubleword and the old second one. Either use LDXP/STXP or CASP, or arrange for one 64-bit field (a sequence number or a valid flag) to carry the protocol, and order the rest against it (7.10).
  • MMU off. With the MMU off, data accesses are Device-nGnRnE (6.5), and unaligned accesses fault. That is one reason TF-A builds with -mstrict-align. Single-copy atomicity is then a non-issue only because the unaligned case cannot happen at all.

Multi-copy atomicity: three strengths

Take one write W to location x by observer P0:

PropertyDefinitionExample architectures
Multi-copy atomicW becomes visible to all observers, including P0, at the same momentSequential consistency; no mainstream CPU architecture
Other-multi-copy atomicIf W is observed by any observer other than P0, it is observed by all other observers. P0 may see W early (forwarding)Armv8-A and Armv9-A; x86-TSO is also other-MCA, because of its store buffer
Non-multi-copy atomicDifferent observers may see W at different times, and may disagree on the order of writes to different locationsIBM POWER, ARMv7, and the original Armv8 text

All three include coherence: every observer agrees on the per-location Coherence order. That never weakens. What changes is whether observers can disagree across locations about when writes became visible.

In DDI0487 terms, the Arm memory model is other-multi-copy atomic. In the axiomatic model this property is what lets obs = rfe | coe | fre (external edges only) go straight into the single global “ordered-before” relation, with no extra propagation relation. Same-PE reads-from (rfi) is deliberately left out of obs. That gap is exactly the “other” in the name.

The 2017 revision, and why older material is weaker

The first Armv8 issues of DDI0487 described the memory model in prose inherited from ARMv7. That text was non-multi-copy atomic, like POWER: it allowed a write to reach some PEs before others. In 2017 Arm revised the Armv8 model and replaced the prose with an axiomatic definition that is other-multi-copy atomic. The revision was applied to Armv8.0 itself, not as a new feature. Arm’s position was that no Armv8 implementation had exhibited non-MCA behaviour, so the stronger model constrained no shipping core. The formalisation, and its proof of equivalence to an operational model, is Pulte, Flur, Deacon, French, Sarkar and Sewell, “Simplifying ARM Concurrency”, POPL 2018. The aarch64.cat file in herdtools7 is the executable form you will use in 7.11.

You will meet the older, weaker model in:

  • the ARMv7-A/R ARM, and AArch32-era application notes, including the original “Barrier Litmus Tests and Cookbook”;
  • early Armv8 training material written before 2017;
  • Linux’s memory-barriers.txt, which deliberately targets the weakest supported architecture (historically including non-MCA machines) and therefore insists on barrier cumulativity and on “transitivity” cases that Armv8 gives for free;
  • academic papers that discuss “ARM” as if it were POWER-like (the Flowing and POP models).

The practical difference is in tests like WRC and IRIW. Under a non-MCA model, WRC with address dependencies on both reading threads is allowed. A cumulative barrier on the middle thread is needed to forbid it. Under the revised Armv8 model, WRC+addrs and IRIW+addrs are forbidden. 7.3 derives this.

Security note: Code reviewed against the old model is not wrong under the new one, since the new model is strictly stronger. But “we can drop this barrier because Armv8 is MCA” is a valid argument only for the Armv8 profile. Shared code that also runs on AArch32 ARMv7 cores (some system control processors, or older companion cores), or that is ported to other non-MCA architectures, keeps the old requirement.

Multi-copy atomicity is not sequential consistency

Other-MCA forbids observers from disagreeing about the visibility order of writes. It does not stop a PE from reading its own write early, and it does not stop reordering of independent accesses within a PE. Store buffering (SB) is still allowed, as are reordered loads (MP without barriers) and load buffering (LB). Those need dependencies, barriers or acquire/release (7.4–7.7).

Multi-chiplet and system scale

Other-multi-copy atomicity is a promise the whole system must keep for every observer the model covers, not just the core. A coherent interconnect breaks it if, for example, it lets a write become readable by PEs on the local chiplet while a remote chiplet can still return the old value for the same line after it has already observed some later write. A typical cause is a broken invalidation handshake between a local snoop filter and a remote home node. Only the interaction between the two shows the bug. Neither chiplet is wrong on its own.

Validation note: Run IRIW+addrs and WRC+addrs (7.11) with the writer and reader threads pinned to different clusters and chiplets. Any observation of the forbidden outcome is a coherence or interconnect bug, not a software bug, provided the test is correct. Same-cluster runs rarely stress the path, because the shared L2/L3 serialises everything. While the test runs, interconnect PMU snoop and retry counters (CMN or CCIX/CXL link counters) show whether the cross-chiplet path is actually being exercised.

Checkpoint

Q7.2.1 On a core without FEAT_LSE2, EL3 writes a 16-byte shared structure with STP x0, x1, [x2] (x2 16-byte aligned). Another PE reads it with LDP x3, x4, [x2]. What may the reader observe?

  • A. Only the old 16 bytes or the new 16 bytes, because the STP address is 16-byte aligned
  • B. A mix such as new x3 with old x4, because each half is a separate 64-bit single-copy atomic access
  • C. A mix at byte granularity within each doubleword, because LDP is never single-copy atomic
  • D. Only the new value, because other-multi-copy atomicity makes the whole STP visible at once
Answer

B. Without LSE2, an X-register LDP/STP aligned to 8 is two 64-bit single-copy atomic accesses, so it can tear between the doublewords but not inside one. Option A describes FEAT_LSE2 behaviour. Option D confuses multi-copy atomicity, which is per write, with single-copy atomicity across the two halves.

Read more: Arm ARM (DDI0487), B2 “Single-copy atomicity”

Q7.2.2 A 2014 training deck says that on Armv8, WRC (P0 writes x; P1 reads x then writes y; P2 reads y then x) with address dependencies on P1 and P2 can still show P2 reading x == 0. What is the best explanation?

  • A. The deck is right, because address dependencies never order a load before a later store
  • B. The deck is right for Inner Shareable memory but wrong for Outer Shareable memory
  • C. The deck is wrong in every version, because WRC is forbidden even without dependencies
  • D. The deck predates the 2017 revision to other-multi-copy atomicity, under which WRC+addrs is forbidden
Answer

D. The earlier, non-MCA text allowed a write to propagate to P1 before P2, which permits this outcome without a cumulative barrier. The revised model forbids it. Option C overreaches: WRC with no dependencies is still allowed, because P1’s and P2’s accesses can be reordered.

Read more: Arm ARM (DDI0487), B2 “Multi-copy atomicity”; Pulte et al., POPL 2018

Q7.2.3 Why must firmware update a valid 64-bit stage 1 descriptor with a single STR Xn rather than two STR Wn?

  • A. The walker reads the descriptor 64-bit single-copy atomically and can see a mix of new and old halves if the store is split
  • B. Two W stores are not ordered with respect to each other without a DMB
  • C. Two W stores to the same doubleword are always merged into one by the store buffer
  • D. Descriptors must be written with Device memory attributes
Answer

A. A split store gives the walker a window in which half of the descriptor is old and half is new. Even with perfect ordering of the two halves (B), the intermediate state is still observable. Merging (C) is permitted but never guaranteed, so you cannot rely on it. In any case, changing a valid descriptor needs break-before-make (9.2).

Read more: Arm ARM (DDI0487), B2 “Single-copy atomicity”; the AArch64 VMSA chapter, translation table descriptor atomicity

7.3 Litmus tests

A litmus test is a tiny multi-threaded program plus a final condition on registers and memory. The question it asks is always the same: does the architecture allow this outcome? The five shapes on this page (MP, SB, LB, WRC, IRIW) cover almost every ordering bug you will meet in firmware. Each one is a pattern you can recognise in real code, and each has a minimal fix and a typical wrong fix. 7.11 runs them with herd7 and litmus7. Here we derive the answers from the axiomatic model.

The model in one screen

DDI0487 B2 defines the Arm memory model axiomatically. A candidate execution (a choice of rf and co, see 7.1) is allowed only if it satisfies three checks. This is an abridged rendering for explicit accesses only, in the style of the 2017 aarch64.cat:

obs = rfe | coe | fre                               (* Observed-by: external edges *)

dob = addr | data                                   (* Dependency-ordered-before *)
    | ctrl; [W]
    | (ctrl | addr; po); [ISB]; po; [R]
    | addr; po; [W]
    | (addr | data); rfi

aob = rmw | [range(rmw)]; rfi; [A | Q]              (* Atomic-ordered-before *)

bob = po; [dmb.full]; po                            (* Barrier-ordered-before *)
    | [R]; po; [dmb.ld]; po
    | [W]; po; [dmb.st]; po; [W]
    | [A | Q]; po                                   (* acquire / acquirePC *)
    | po; [L]                                       (* release *)
    | [L]; po; [A]                                  (* STLR then LDAR: RCsc *)

ob  = (obs | dob | aob | bob)+                      (* Ordered-before *)

acyclic  po-loc | rf | co | fr     as internal      (* per-location coherence *)
irreflexive ob                     as external      (* no cycle in ob *)
empty    rmw & (fre; coe)          as atomic        (* RMWs really are atomic *)

A is LDAR-class acquire, Q is LDAPR-class acquirePC, L is STLR-class release, dmb.full is DMB SY/ISH/OSH/NSH. The current herdtools7 aarch64.cat is much larger. It separates explicit and implicit effects (instruction fetch, translation table walks, MTE tags), adds TLBI, DSB and DC CVAU ordering, adds “pick” dependencies through conditional selects, and generalises the ISB clause. For the five tests below the abridged form gives the same answers.

The method is always the same. Write the cycle that the forbidden-looking outcome would need. If every edge in the cycle is in ob, the outcome is forbidden. If even one edge is plain po that no rule promotes, it is allowed. Other-multi-copy atomicity (7.2) is what lets the external rfe/fre/coe edges go straight into ob.

MP: message passing

P0                    | P1
STR  w1, [x_data]     | LDR  w2, [x_flag]     // r2 = 1 ?
STR  w1, [x_flag]     | LDR  w3, [x_data]     // r3 = 0 ?

Outcome r2=1, r3=0: P1 sees the flag but stale data.

Candidate cycle: Wdata -po-> Wflag -rfe-> Rflag -po-> Rdata -fre-> Wdata. Both po edges are plain, so the outcome is allowed, and it is commonly observed on out-of-order cores.

VariantResultWhy
DMB ISHST on P0, address dependency on P1ForbiddenP0 edge in bob (dmb.st, W→W), P1 edge in dob (addr)
DMB ISHST on P0, DMB ISHLD on P1Forbiddendmb.ld orders R→anything
STLR flag on P0, LDAR (or LDAPR) flag on P1Forbiddenpo; [L] and `[A
DMB ISHST on P0, control dependency on P1Allowedctrl orders only to writes. The data load may be satisfied speculatively before the branch resolves
DMB ISHST on P0, control dependency + ISB on P1Forbiddenctrl; [ISB]; po; [R]
DMB ISHLD on P0Alloweddmb.ld orders earlier reads. P0 has only writes

MP is the descriptor-plus-doorbell pattern, the mailbox, and every “write payload then set valid bit” protocol (7.10).

SB: store buffering

P0                    | P1
STR  w1, [x_a]        | STR  w1, [x_b]
LDR  w2, [x_b]        | LDR  w3, [x_a]        // r2 = 0 && r3 = 0 ?

Cycle: Wa -po-> Rb -fre-> Wb -po-> Ra -fre-> Wa. Plain: allowed. Each store can sit in its own PE’s store buffer while the load runs. This is the one reordering that even x86 allows.

The fix needs a W→R edge on both sides. Only these provide it:

  • a full DMB ISH (or SY), which is in bob via dmb.full;
  • STLR followed by LDAR, which is in bob via [L]; po; [A].

DMB ISHST does not work, because it is W→W only. DMB ISHLD does not work, because it orders from earlier reads. STLR + LDAPR does not work, because [L]; po; [Q] is deliberately not in bob (see 7.7). Dekker-style mutual exclusion, and “set my flag, then check yours” handshakes between EL3 and a secure partition or between a PE and an SCP, are all SB. A missing full barrier here is a classic bug in hand-rolled firmware locks (10.4).

LB: load buffering

P0                    | P1
LDR  w2, [x_a]        | LDR  w3, [x_b]        // r2 = 1 && r3 = 1 ?
STR  w1, [x_b]        | STR  w1, [x_a]

Cycle: Ra -po-> Wb -rfe-> Rb -po-> Wa -rfe-> Ra. Plain: allowed by the architecture. In the 6.1 picture, a store may be made visible once the earlier load is known not to fault, before the load’s data has actually returned. Many implementations never show it, but the model does not forbid it.

Any dependency from the load to the store forbids it: data and addr directly, and ctrl; [W] because stores are never made visible speculatively. So LB+datas, LB+addrs and LB+ctrls are all forbidden. LB is the shape behind “can my load return a value written by a store that comes after it in my own program order?”. Architecturally the answer is yes unless a dependency or barrier rules it out.

WRC: write-to-read causality

P0              | P1                    | P2
STR w1, [x_x]   | LDR w2, [x_x]  // =1  | LDR w4, [x_y]  // =1
                | <dep>                 | <dep>
                | STR w1, [x_y]         | LDR w5, [x_x]  // =0 ?

Cycle: Wx -rfe-> R1x -po-> Wy -rfe-> R2y -po-> R2x -fre-> Wx.

  • Plain: allowed, because the reorderings on P1 and P2 break the chain.
  • WRC+addrs (address dependency on P1 to the store, which is addr; po; [W] or a direct addr/data, and on P2 to the second load): forbidden. Every edge is in ob.

The interesting edge is the first rfe. P1 has seen P0’s write. Other-multi-copy atomicity says that if any observer other than P0 has seen it, all have. So P2, having seen P1’s later write through a dependency chain, must see x=1. Under the pre-2017 non-MCA model this was allowed unless P1 used a cumulative barrier (7.2). WRC is the shape of “core A publishes, core B forwards a pointer, core C consumes”.

IRIW: independent reads of independent writes

P0            | P1            | P2                   | P3
STR w1,[x_x]  | STR w1,[x_y]  | LDR w2,[x_x] // =1   | LDR w4,[x_y] // =1
              |               | LDR w3,[x_y] // =0   | LDR w5,[x_x] // =0 ?

The outcome means P2 thinks x was written first and P3 thinks y was written first. Cycle: Wx -rfe-> P2:Rx -po-> P2:Ry -fre-> Wy -rfe-> P3:Ry -po-> P3:Rx -fre-> Wx.

  • Plain: allowed, because each reader’s two loads can be reordered.
  • IRIW+addrs or IRIW+dmb.lds (ordering on both readers only): forbidden, with no barrier at all on the writers. This is the cleanest demonstration that Armv8 is other-MCA. On POWER, IRIW+addrs is allowed and needs sync.

Summary

TestPlainMinimal sufficient fixTypical insufficient fix
MPAllowedDMB ST writer + addr dep / DMB LD / LDAR readerControl dependency alone on the reader
SBAllowedFull DMB both sides, or STLR→LDARDMB ST, DMB LD, STLR→LDAPR
LBAllowedAny dependency (data/addr/ctrl) both sidesnone common
WRCAllowedDependencies (or DMB LD) on both readersBarrier on P0 only
IRIWAllowedDependencies or DMB LD on both readersBarriers on the writers

Coherence is free, and only per location

The internal check covers the single-location cases (CoRR, CoWR, CoRW, CoWW). On one PE, two reads of the same location never see values going backwards in Coherence order. A read never returns a value older than the PE’s own earlier write. None of this needs a barrier. Do not use these tests to argue about two different locations, even ones in the same cache line. The model has no notion of cache lines.

Validation note: “Allowed” is not “will be observed”. LB and some MP variants may never appear on an in-order core such as Cortex-A53, even after billions of iterations. Conversely, observing a forbidden outcome under litmus7 means either a silicon/interconnect bug or a test bug, such as a missing dependency in the generated code or the wrong memory type. Before you file a hardware bug, confirm the test against herd7 first (7.11).

Checkpoint

Q7.3.1 A reader polls a flag and then reads a payload. The writer uses DMB ISHST between payload and flag. The reader code is LDR w0, [flag]; CBZ w0, retry; LDR w1, [payload]. Is flag=1, payload=old allowed?

  • A. No, because the conditional branch creates a control dependency that orders the two loads
  • B. No, because DMB ISHST on the writer is cumulative and orders the reader too
  • C. Yes, because a control dependency orders only later stores; the payload load can be satisfied speculatively before the branch resolves
  • D. Yes, but only if the payload and the flag are in different cache lines
Answer

C. In the model, ctrl contributes only ctrl; [W] and ctrl; [ISB]; po; [R]. Adding ISB after the branch, an address dependency, DMB ISHLD, or LDAR on the flag would forbid the outcome. Option A is the common misconception. Option D is irrelevant, because the model has no cache lines.

Read more: Arm ARM (DDI0487), B2 “Dependency-ordered-before”; the “Barrier Litmus Tests” appendix

Q7.3.2 Two PEs each do STR to their own flag then LDR the other’s flag (SB), and both read 0. A developer adds STLR for the store and LDAPR for the load. Is the both-zero outcome now forbidden?

  • A. Yes, because release followed by any acquire is ordered
  • B. No, because [L]; po; [Q] is not in Barrier-ordered-before; only LDAR after STLR gives the W→R edge
  • C. Yes, because LDAPR orders all later accesses after it
  • D. No, because SB can only be fixed with DSB
Answer

B. RCpc acquire (LDAPR) is allowed to be satisfied before an earlier STLR to a different address is observed. That is the whole difference from LDAR. A full DMB ISH between the store and the load, or LDAR, fixes it. A DSB is sufficient but not necessary (D).

Read more: Arm ARM (DDI0487), B2 “Barrier-ordered-before”; LDAPR

Q7.3.3 In IRIW, the two readers each use DMB ISHLD between their loads, and the writers have no barriers. Which statement is right?

  • A. The disagreeing outcome is forbidden, because other-multi-copy atomicity puts the external edges in ob and the readers’ DMB LD closes the cycle
  • B. The outcome is still allowed, because the writers also need DMB ISHST
  • C. The outcome is forbidden only if all four PEs are in the same cluster
  • D. The outcome is allowed, because DMB LD does not order a load before a later load
Answer

A. Each writer issues one store, so there is nothing on the writer side to order. The cycle consists of rfe, reader bob, fre, rfe, reader bob, fre, all in ob. Option B is the reflex from non-MCA models. Option D is false: DMB LD orders earlier loads against all later accesses.

Read more: Arm ARM (DDI0487), B2 “Multi-copy atomicity”; herdtools7 aarch64.cat

7.4 Dependencies

A dependency is the cheapest ordering on Arm: no barrier, no acquire, just a register that carries a loaded value into a later instruction. The architecture honours dependencies syntactically. A dependency exists because of which registers an instruction reads, not because of whether the value actually influences the result. That makes dependencies a precise tool in assembly and a fragile one in C. This section defines the three kinds, says exactly what each one orders, and lists the cases where something that looks like a dependency orders nothing.

Definitions

DDI0487 B2 builds everything from a register data dependency: a chain from the destination register of a read effect, through any number of register-to-register instructions, to a source register of a later instruction in program order. The chain is broken where an instruction overwrites the carrying register with a value that does not depend on it. Instructions that read and write other registers do not affect it.

KindThe chain ends in…Example
Address dependencythe address of a later memory accessLDR x1, [x0] → LDR x2, [x1, #8]
Data dependencythe data register of a later storeLDR x1, [x0] → STR x1, [x3]
Control dependencythe condition of a conditional branch (B.cond via NZCV, CBZ/CBNZ, TBZ/TBNZ), with the dependent effect after the branch in program orderLDR w1, [x0] → CBZ w1, 1f → STR ...

A dependency is a syntactic property. This sequence has a real address dependency, although the offset is always zero:

    ldr     x1, [x_flag]
    eor     x2, x1, x1          // x2 = 0, but depends on x1
    ldr     x3, [x_data, x2]    // address-dependent on the flag load

The hardware must not satisfy the second load until the first one has returned its value. A design that uses value prediction still has to behave as though it waited. This “fake dependency” idiom is legal and common in hand-written code. Linux uses the same eor trick after an MRS of the counter, but there the source is a system-register read rather than a memory read, which is a different case (item 4 below and 4.7).

What each dependency orders

From the Dependency-ordered-before (dob) relation (7.3):

Source → targetOrdered?dob clause
Read → address-dependent read or writeYesaddr
Read → data-dependent writeYesdata
Read → any write after an address-dependent accessYesaddr; po; [W]
Read → write after a control-dependent branchYesctrl; [W]
Read → read after a control-dependent branchNo(none)
Read → read after a control dependency and an ISBYesctrl; [ISB]; po; [R]
Read → read after an address-dependent access and an ISBYesaddr; po; [ISB]; po; [R]
Read → later read of a store it fed (forwarding)Yes(addr | data); rfi

Why the asymmetry: stores are never speculatively visible

The rule behind the table is that no write may become visible to another observer while it is still speculative. A store after a branch that depends on a load cannot be released until the branch resolves, and the branch cannot resolve until the load has its value. The same applies to a store after an address-dependent access: until the address is known, the PE cannot rule out that the earlier access faults, so the later store stays speculative.

Loads have no such restriction. A PE may predict the branch, execute the load on the predicted path, and keep the value if the prediction was right. Architecturally that is indistinguishable from a load performed early. So ctrl gives no R→R order. In MP, a control-dependent read of the payload can return stale data (7.3).

Control + ISB

An ISB after the branch forbids that. Instructions after an ISB are fetched and executed only after the ISB completes, and the ISB cannot complete while it is itself on an unresolved speculative path. This works, but it is a pipeline flush on every pass. Prefer an address dependency, DMB ISHLD, or LDAR/LDAPR on the flag (7.7). The ctrl+ISB form matters mostly when the “read” you need ordered is not an ordinary load, for example an MRS of a counter or a system register (7.8).

Dependencies that do not create ordering

  1. Control to a later load. This is the case above, and the most common mistake.

  2. Dependencies that the compiler removes. C has no notion of a hardware dependency. Given r = *flag; x = data[r - r];, a compiler will fold r - r to zero and drop the dependency. Given if (p == &known) use(known.field), it may substitute the address it already knows. C11 memory_order_consume was meant to preserve such chains, but in practice compilers implement it as acquire. Firmware that relies on a dependency must create it where the compiler cannot see through it: in assembly, in inline asm with the dependent load inside, or by using an acquire load. Linux’s READ_ONCE plus address dependency relies on compiler behaviour and documented restrictions that bare-metal toolchains do not promise.

  3. Dependencies through the condition of a conditional select. CSEL x3, x4, x5, EQ, where the flags come from a loaded value, is not an ordinary register data dependency in the current model. Recent DDI0487 issues and herdtools7 aarch64.cat describe it with separate “pick” dependency relations. These still order later writes (pick-addr-dep; [W], pick-ctrl-dep; [W]), and an ISB can be added for reads. They do not order a later load whose address is chosen by the select. Branchless code (CSEL instead of CBZ) can therefore weaken ordering that the branching version had for stores: ctrl; [W] orders every later store after the branch, but a pick dependency orders only stores that consume the selected value. Neither version orders a later load without an ISB. A dependency through the selected data operand of CSEL is an ordinary data dependency.

  4. Reads that are not memory reads. The model covers memory effects. An MRS of CNTVCT_EL0 or of a system register is not a read effect in dob, so a register chain from it to a load orders nothing in model terms. 4.7 and 7.8 cover what is guaranteed.

  5. The wrong direction. A dependency orders its source read before the target. It does nothing for earlier accesses. In SB, an address dependency from P0’s load to some later access does not stop P0’s earlier store from being overtaken by that load (7.3). A dependency also orders nothing for accesses by other observers on its own. The cross-PE guarantee comes from combining it with obs edges.

  6. Implicit accesses. Dependencies order explicit accesses. They do not make your PE’s translation table walker or instruction fetch see a store (7.1).

One case that looks broken is in fact fine: dependencies through memory on the same PE. If a compiler spills the loaded value to the stack and reloads it, the chain is R1 -data-> Wstack -rfi-> Rstack -addr-> R2. (addr | data); rfi puts R1 before Rstack, so the order survives the spill.

Where dependencies earn their place in firmware

  • Pointer publication, consumer side. If the producer writes a structure and then publishes a pointer to it with STLR or after DMB ISHST, the consumer needs only an address dependency, LDR x1, [x_ptr]; LDR x2, [x1, #off], written in assembly. This is the cheapest correct consumer.
  • Descriptor rings. A dependency from the ring index you read to the descriptor address you compute orders the descriptor read, if the compiler keeps it.
  • LB-style safety. Any “load, decide, store” sequence is already ordered R→W by its control dependency. No barrier is needed for that direction.

Security note: The fact that ctrl gives no R→R ordering in the memory model is closely related to Spectre v1 (14.3): loads after an unresolved bounds check execute speculatively. In the memory model the speculative load is harmless because its value is discarded on misprediction. Its cache footprint is not. The memory model tells you about values, not about microarchitectural side effects. CSDB is the speculation barrier for that purpose, and it is not a memory-ordering barrier.

Validation note: MP+dmb.st+ctrl is allowed, and an aggressive out-of-order core should show it under litmus7 stress. If it never appears, the test is simply not stressing hard enough. MP+dmb.st+addr and MP+dmb.st+ctrlisb are forbidden, so any observation of those is a bug. Check the generated assembly before blaming silicon: a C-generated litmus harness that lost the eor dependency is a test bug (7.11). On cores with value prediction, the address-dependency variants are the ones to run longest.

Checkpoint

Q7.4.1 Which reader sequence is sufficient, without any barrier instruction, to forbid flag=1, data=old in MP when the writer uses DMB ISHST?

  • A. LDR w0,[flag]; CBZ w0, retry; LDR w1,[data]
  • B. LDR w0,[flag]; CMP w0,#0; CSEL x2, x_data, x_dummy, NE; LDR w1,[x2]
  • C. LDR w0,[flag]; MOV x2, x_data; LDR w1,[x2]
  • D. LDR w0,[flag]; AND x2, x0, xzr; LDR w1,[x_data, x2]
Answer

D. AND x2, x0, xzr reads x0, so it creates a syntactic address dependency even though the result is always zero. A is control only, which does not order R→R. B makes the address depend on the condition flags of a CSEL, a “pick” dependency that does not order a later load. C has no dependency on w0 at all.

Read more: Arm ARM (DDI0487), B2 “Dependency definitions” (Address dependency, Register data dependency)

Q7.4.2 Why does a control dependency order a later store but not a later load?

  • A. Stores may not become visible while speculative, but a load may be satisfied speculatively and its value kept if the branch prediction was correct
  • B. Branch predictors are disabled for branches whose condition comes from a load
  • C. Stores always drain in program order through the store buffer
  • D. The architecture forbids any load from executing before an older branch resolves
Answer

A. This is the reason for the asymmetry in dob. Option C is false: stores to different locations need DMB ST to be ordered. Option D is false, and it is exactly what Spectre exploits.

Read more: Arm ARM (DDI0487), B2 “Dependency-ordered-before”; speculation rules for writes

Q7.4.3 A C consumer is written p = *(volatile uintptr_t *)&head; v = ((struct d *)p)->val; and relies on the address dependency for ordering. Under which change is this most likely to stop being correct?

  • A. Compiling for an Armv9 core instead of Armv8
  • B. Moving head and the structure into the same cache line
  • C. A compiler optimisation that proves p equals a known address and loads val from that address directly
  • D. Running the code at EL3 instead of EL1
Answer

C. The hardware honours syntactic dependencies, but the compiler can replace a loaded pointer with an equal constant, and then no dependency remains. Use assembly or an acquire load if the ordering must be guaranteed. Cache-line placement (B) and Exception level (D) do not affect the model.

Read more: Arm ARM (DDI0487), B2 “Dependency definitions”; C11 memory_order_consume (ISO/IEC 9899:2011, 7.17.3)

7.5 DMB

DMB (Data Memory Barrier) orders memory effects. It does not wait for anything to complete, does not stall unrelated instructions, and does not synchronize context. A DMB says: “the accesses of type T before me are observed by every observer before the accesses of type T′ after me.” The access-type field of the instruction is what selects T and T′. The domain field once mattered too, but under the current definition it no longer has any functional effect (see below).

Encoding and options

DMB <option> encodes the option in CRm. The domain is in CRm[3:2] and the access types are in CRm[1:0]. The “Domain” column gives the historical meaning, which is now deprecated for DMB:

CRmOptionDomainOrders (before → after)
0b1111SYFull systemR/W → R/W
0b1110STFull systemW → W
0b1101LDFull systemR → R/W
0b1011ISHInner ShareableR/W → R/W
0b1010ISHSTInner ShareableW → W
0b1001ISHLDInner ShareableR → R/W
0b0111NSHNon-shareableR/W → R/W
0b0110NSHSTNon-shareableW → W
0b0101NSHLDNon-shareableR → R/W
0b0011OSHOuter ShareableR/W → R/W
0b0010OSHSTOuter ShareableW → W
0b0001OSHLDOuter ShareableR → R/W

The LD forms are new in Armv8. ARMv7 had only full and ST forms. Other CRm values are reserved. DDI0487 says that unsupported and reserved options execute as a full system barrier, but that software must not rely on this. Do not confuse DMB with DSB, which uses the same option names and some of whose CRm values mean SSBB/PSSBB (7.6).

What “ordering” means precisely

In the axiomatic model (7.3) a DMB contributes these Barrier-ordered-before edges:

po; [dmb.full]; po                (* every access before → every access after *)
[R]; po; [dmb.ld]; po             (* every read before   → every access after *)
[W]; po; [dmb.st]; po; [W]        (* every write before  → every write after  *)

These edges join with Observed-by edges into ob, and ob must be acyclic. Operationally: if access A precedes the DMB and B follows it, with matching types, then no observer can observe B and afterwards observe a state that does not yet include A.

Because the model is other-multi-copy atomic (7.2), the edges compose with other PEs’ writes that this PE has read. If P1 reads P0’s write and then executes DMB ISH and its own store, every observer that sees P1’s store also sees P0’s write (rfe; bob). This is the property older text calls cumulativity. In Armv8 you do not have to request it.

What a DMB does not do:

  • It does not make anything complete. A store before a DMB may still be in a buffer long after the DMB has retired. Only its order relative to later stores is fixed.
  • It does not order instruction fetch, translation table walks, or the effect of a system-register write. Those need DSB and/or ISB (7.8).
  • It does not wait for TLBI or IC completion. It does order data cache maintenance by VA (DC CVAC, DC CIVAC…) against explicit accesses (using a barrier whose access types include both loads and stores), but it does not wait for that maintenance to finish (8.5).
  • It does not stop non-memory instructions after it from executing early.

The domain argument: what it meant, and what it means now

The domain field (NSH/ISH/OSH/SY) is where most of the folklore about DMB lives. Its status has changed recently, so read older code and older text with that in mind.

The classical reading. Until recently, DDI0487 defined a DMB’s guarantee as holding for “the observers in the required shareability domain”. The guidance that followed was to choose the domain by asking who must see these accesses in this order. The usual answers were: ISH for other PEs sharing Inner Shareable Write-Back memory, and OSH for a DMA master reading Normal Non-cacheable buffers or for Device memory, because NC and Device memory are treated as Outer Shareable whatever SH says (6.4). That is why Linux defines dma_wmb() as DMB OSHST on arm64 (Appendix C), and why a lot of firmware review comments say “ISHST is not enough before a DMA doorbell”.

The current position. Arm has since recognised that, in an other-multi-copy-atomic model (7.2), a domain-limited ordering guarantee has no observable meaning. Once a write is observed by any other observer, it is observed by all of them. The DDI0487 Known Issues entry AARCH-24234 (raised against issue M.a) therefore redefines the DMB shareability argument as having no functional effect and deprecates it. DMB NSH, DMB ISH, DMB OSH and DMB SY give the same ordering, and likewise for the LD and ST forms. Arm’s barrier guide (102336, v1.1) says the same: “barriers with this argument behave the same as if the shareability option is not given”. herdtools7 adopted this in March 2026 and now flags Shareability-argument-for-DMB-is-deprecated instead of assuming a common Inner Shareable domain.

Arm presents this as a consequence of the model that has applied since Armv8.0, not as a new hardware requirement. In practice:

QuestionAnswer under the current model
Is existing DMB ISH / DMB ISHST code wrong?No. It gives full or W→W ordering, which is what it always had to give in an MCA system
Is DMB ISHST before a DMA doorbell now sufficient for ordering?Yes. The access type (ST) is what matters
Should new code drop the qualifier?Spell it DMB SY/DMB ST/DMB LD (or follow your codebase’s convention). Do not churn working code just for spelling
Does the domain still matter anywhere?For DSB, yes: it is now called the maintenance scope and governs TLBI and IC completion (7.6)

What the change does not remove is the coherency question. A DMB orders this PE’s accesses. It cannot make a non-coherent DMA master see data that is still in this PE’s cache. That needs the right memory type, or cache maintenance to the Point of Coherency (8.7). Many of the “ISH vs OSH” bugs in older bring-up war stories were really missing-CMO bugs, which a stronger barrier on a particular core happened to hide.

Bring-up note: Older code may contain domain choices justified as “OSH because the GPU is outside the Inner Shareable domain”. When you review it, check the access type and the memory attributes rather than the domain. If a port of such a routine fails on a new chiplet design, look for missing cache maintenance or a wrong memory type, not for the wrong DMB domain. Also check whether the target’s documentation pins an older DDI0487 issue: this book follows the AARCH-24234 position, so cite it when you justify a change.

The LD and ST variants

ST and LD are partial barriers. They are cheaper on some cores, but they are not interchangeable with the full form:

  • DMB ST: W→W only. It is enough for the writer side of MP (payload, then flag). It is not enough as a release: a critical section’s loads may still be satisfied after the unlocking store. This lock release is broken:
    // critical section: loads and stores to shared data
    ldr     w2, [x_shared]
    dmb     ishst               // WRONG: W->W only
    str     wzr, [x_lock]       // unlock

Another PE can take the lock, write x_shared, and this PE’s ldr can still return the new value. That is an R→W reordering across the unlock. Use STLR wzr, [x_lock] or DMB ISH.

  • DMB LD: R→R/W. After reading a flag, it orders every later access after that read, which makes it an acquire fence. It is enough for the reader side of MP and for the readers in WRC/IRIW. It does nothing for earlier stores.

  • DMB LD + DMB ST ≠ DMB full. Together they give R→R, R→W and W→W, but never W→R. Store buffering (SB) and any “publish my flag, then check yours” handshake need the full barrier, or STLR followed by LDAR (7.3).

NeedMinimal DMB
Payload stores before flag storeDMB ISHST (ST in any spelling, device or PE consumer alike)
Flag load before payload loadsDMB ISHLD, or a dependency/LDAR
Critical-section accesses before unlock storeDMB ISH (or STLR)
My store before my load of another locationDMB ISH (full)

Cost

DDI0487 imposes no cost model. In the 6.1 picture, a DMB is often implemented by tagging the store buffer and the load queue so that later accesses of the ordered type cannot perform before the earlier ones. Independent arithmetic keeps flowing. A full DMB that must order a buffered store before a later load does stall that load until the store is observed by other observers. That is the W→R case, and why SB fixes are expensive. Measure the cost on your target with PMU cycle counts rather than assuming one. 7.6 compares DMB with DSB.

Validation note: Use herd7 (7.11) to check access-type choices (LD, ST or full). It treats every domain the same and flags deprecated qualifiers. On hardware, test DMA-facing protocols with a real non-PE observer, for example a DMA engine that copies the ring and checks a sequence number in each descriptor. Stale descriptors seen by the device, but never by another core, almost always mean missing cache maintenance or a cacheable mapping, not a barrier-domain problem. Confirm with the device’s own error or status counters and, where available, interconnect PMU read counts against the ring address.

Checkpoint

Q7.5.1 Firmware fills a DMA descriptor in a Normal Non-cacheable ring, then writes a Device doorbell register with DMB ISHST between the two stores. A reviewer, citing “NC and Device are Outer Shareable”, insists on DMB OSHST. Under the current DDI0487 position (Known Issues entry AARCH-24234), which statement is right?

  • A. The reviewer is right, because the DMA master is outside the Inner Shareable domain, so ISHST gives it no ordering
  • B. Both give the same ordering. The DMB shareability argument has no functional effect in an other-multi-copy-atomic model, and what matters is the ST access type
  • C. Neither is enough. A DSB OSHST is required, because the doorbell is Device memory
  • D. DMB ISHST is enough only if the descriptor was also cleaned to the Point of Coherency
Answer

B. AARCH-24234 deprecates the DMB shareability argument and redefines it as having no functional meaning, so ISHST, OSHST and ST give the same W→W ordering. A is the classical reasoning that the Known Issue retires. C confuses ordering with completion: the device only needs the descriptor write to be observed before the doorbell write, which is an ordering requirement. D adds a CMO that an NC ring does not need. A CMO would be needed if the ring were cacheable and the master non-coherent, and it would then be a separate requirement, not a barrier-domain one.

Read more: Arm ARM (DDI0487), DMB; DDI0487 Known Issues, AARCH-24234; Arm “Learn the architecture: Memory Systems, Ordering, and Barriers” (102336)

Q7.5.2 A spinlock release is coded as DMB ISHST; STR wzr, [lock]. What can go wrong?

  • A. Nothing, because the critical section’s stores are ordered before the unlock
  • B. The unlock store may never become visible without a DSB
  • C. Stores from the critical section may become visible after the unlock
  • D. Loads in the critical section may be satisfied after the unlock is observed, and so return data another lock holder has already written
Answer

D. DMB ST orders W→W only, so a critical-section load can be reordered after the unlock store. C is exactly what DMB ST does prevent. B confuses ordering with completion: the store becomes visible eventually without any barrier. The fix is STLR or a full DMB ISH.

Read more: Arm ARM (DDI0487), DMB (access types); B2 “Barrier-ordered-before”

Q7.5.3 A developer replaces a full DMB ISH with DMB ISHLD followed by DMB ISHST, reasoning that this covers loads and stores. Which ordering is lost?

  • A. A load before the barriers, against a later store
  • B. A store before the barriers, against a later store
  • C. A store before the barriers, against a later load
  • D. A load before the barriers, against a later load
Answer

C. LD gives R→R/W and ST gives W→W, so no combination gives W→R. Any store-buffering (SB) protocol breaks. A and D are covered by DMB ISHLD, and B by DMB ISHST.

Read more: Arm ARM (DDI0487), DMB; Arm ARM “Barrier Litmus Tests” appendix (SB)

7.6 DSB

DSB (Data Synchronization Barrier) is about completion. A DMB fixes the order in which observers see accesses. A DSB waits until earlier operations are complete in the sense of 7.1, and holds back every later instruction until then. It is the only barrier that can tell you a TLBI or a DC has finished, and the one you need before WFI, before a power transition, and before an ISB that has to see the result of maintenance.

Encoding and options

DSB <option> uses the same CRm encodings as DMB (7.5) for SY, ST, LD, ISH, ISHST, ISHLD, NSH, NSHST, NSHLD, OSH, OSHST and OSHLD. Two CRm values whose access-type bits (CRm[1:0]) are 0b00 do not encode a DSB at all and are reused:

EncodingInstructionPurpose
DSB with CRm = 0b0000SSBBSpeculative Store Bypass Barrier (14.5)
DSB with CRm = 0b0100PSSBBPhysical Speculative Store Bypass Barrier (14.5)
DSB <option>nXS (separate encoding, FEAT_XS)DSB SYnXS, ISHnXS, OSHnXS, NSHnXSNeed not wait for accesses to memory with the XS attribute (9.1)

SSBB and PSSBB are not memory barriers in the ordering sense. Do not write DSB #0 expecting a weak DSB.

The completion rule

From the DSB definition in DDI0487, restated:

  1. All explicit memory accesses of the required access types that appear in program order before the DSB are complete for the required domain.
  2. If the required access types are reads and writes (no LD/ST qualifier), all cache maintenance and TLB maintenance instructions issued by this PE before the DSB are complete for the required domain.
  3. No instruction after the DSB in program order can change any state of the system, or perform any part of its function, until the DSB completes. Being fetched and decoded is allowed, and so are a small number of side-effect-free operations that DDI0487 lists.

Rule 2 is the one that bites. DSB ISHST or DSB ST does not wait for a TLBI or a DC to complete. Only a full DSB does. In the TLB update sequence (9.1), the DSB ISHST before the TLBI makes the descriptor store complete. The DSB ISH after it waits for the invalidation. Swapping them, or using ST for both, is a real bug.

Rule 3 is what makes DSB expensive. It is not just “later memory accesses wait”. Later arithmetic also waits, as do system-register writes, WFI, everything except fetch and decode.

Everything a DMB with the same access types orders, the DSB orders too. A DSB is strictly stronger.

What “complete” means for each kind of operation

Operation before the DSBComplete when…Typical consequence
LoadIts value is returned and no write by any observer can change itLater instructions see a fixed value
Store to Normal memoryGlobally observed (coherent observers)No coherent observer can read the old value
Store to Device memory, EAcknowledged, possibly by an intermediate bufferThe peripheral may not have received it yet
Store to Device memory, nEAcknowledged by the endpointReceived, but the side effect is not guaranteed to have happened (7.9)
TLBI (local or broadcast)No observer can make a new access using the invalidated entries, and earlier accesses that used them are completeSafe to free or reuse the old page, after an ISB for this PE’s own instruction stream
DC CVAC/CIVAC/CVAU/IVAC/...The clean/invalidate has taken effect to the named point (PoC, PoU, PoP…)A non-coherent master can read it, or the instruction side can fetch it (8.5)
IC IVAU/IALLUIS/...The invalidation has taken effect in all instruction caches in scopeStill needs an ISB before this PE executes the new code (8.6)

A DSB never resynchronizes the instruction stream. After TLBI ...; DSB ISH, instructions already fetched under the old translation may still be in the pipeline. That is why the sequence ends in ISB (7.8).

The domain is now a “maintenance scope”

The same DDI0487 Known Issues entry that deprecates the DMB shareability argument (AARCH-24234, raised against issue M.a, see 7.5) also redefines the DSB argument:

  • Because the model is other-multi-copy atomic, completion of explicit loads and stores does not depend on the domain. The argument is renamed the maintenance scope, and it matters only for the completion of TLBI and IC effects.
  • DSB ISH therefore means “wait for my maintenance to complete across the Inner Shareable scope”. It is the natural partner of TLBI ...IS and IC IALLUIS. DSB NSH is enough after purely local maintenance (TLBI VAE1, IC IALLU) when nothing else needs to observe it. DSB SY behaves as DSB OSH.
  • The scope qualifiers on the LD and ST forms (DSB ISHST, DSB NSHLD…) are deprecated. Those forms do not wait for maintenance, so a scope means nothing for them. Existing DSB ISHST behaves exactly as DSB ST.

Older code and older text (including the classic TLB sequence written with DSB ISHST) is still correct. Only its spelling is deprecated. herdtools7 now flags Maintenance-scope-for-DSB-ST-is-deprecated for it (and Maintenance-scope-for-DSB-LD-is-deprecated for the LD forms).

The DSB-before-WFI rule

WFI is a hint that may put the PE into a low-power state. The architecture does not require WFI to wait for earlier memory accesses or maintenance to complete. Two failures follow from that:

  1. Power-down. If the PE (or its cluster) loses power after WFI, outstanding stores and CMOs can be lost or left half-done. Every power-down path ends with completion first:
    // TF-A style: psci_power_down_wfi
    dsb     sy          // all earlier stores and maintenance complete
1:  wfi
    b       1b          // not expected to return when powering down
  1. Handshakes. If the PE writes a “going to sleep” flag, clears a peripheral interrupt or releases a mailbox and then executes WFI, the write may still be buffered while the PE sleeps. Another agent that waits for the write, and would then send the wake-up, may wait forever. Some implementations drain buffers on WFI anyway, which is IMPLEMENTATION DEFINED behaviour and exactly why the bug survives on one core and appears on the next.

The same reasoning applies before any operation with an effect outside the memory model that must follow earlier accesses: writing a reset controller register, handing off to a power controller over a doorbell, or SMC-ing to EL3 for a power state change. 7.10 has the recipes, and the CPU power-state flow is in 17.4.

DSB vs DMB cost

AspectDMBDSB
Waits forNothing (constrains order only)Completion of the selected accesses and, for the full form, maintenance
Blocks later non-memory instructionsNoYes
Device nE store before itLater accesses ordered behind itRound trip to the endpoint
Broadcast TLBI/IC before itNot waited forAll PEs in scope must acknowledge. On AMBA CHI this is a DVM Sync and its responses (8.3)

In the 6.1 picture, a DMB can usually be satisfied inside the PE’s load/store unit, while a DSB drains it and may wait on the farthest agent in the system. After a broadcast TLBI on a large mesh or across chiplets, a DSB can take microseconds. Use DSB only where completion is the property you need: before WFI/power-down, after maintenance, before an ISB that must see completed maintenance, and before signalling an agent outside the memory model. Everywhere else, use DMB, acquire/release or a dependency.

Bring-up note: “The core is stuck with the PC on a DSB” is a classic first-silicon or new-platform symptom. It means something before the DSB never completed. The usual suspects are a Device write to an unclocked or unpowered peripheral that never returns a response, and a broadcast TLBI/IC whose DVM messages the interconnect is not configured to handle (a DVM or snoop domain not enabled for the cluster, or a chiplet link not yet up). Look at the instruction before the DSB, then at the interconnect’s DVM and snoop configuration. 18.2 has the full triage.

Validation note: Time TLBI VAE1IS; DSB ISH with PMCCNTR_EL0 for three placements: all PEs on one cluster, across clusters, and across chiplets. A latency that does not grow with scope suggests the TLBI was not actually broadcast (check TLBI vs TLBI ...IS in the binary and the interconnect DVM counters). A large step across chiplets is expected, and it feeds the TLB shootdown budget. For CMOs, confirm completion functionally: clean a buffer, DSB SY, have a non-coherent DMA master read it, and compare. Run the same test with the DSB removed. The failure rate without it is your evidence that the test exercises the path (8.10).

Checkpoint

Q7.6.1 EL2 code unmaps a stage 2 page with STR xzr, [desc]; DSB ISHST; TLBI IPAS2E1IS, x0; DSB ISHST; TLBI VMALLE1IS; DSB ISHST; ISB and then frees the page. What is wrong?

  • A. Nothing, because each DSB ISHST orders the TLBIs behind the descriptor store
  • B. The first DSB ISHST should be a DMB ISHST
  • C. The DSBs after the TLBIs must be full (DSB ISH). A ST-only DSB does not wait for TLB maintenance to complete, so the page can be freed while other PEs still hold translations to it
  • D. The final ISB should come before the last DSB
Answer

C. Only a DSB whose required access types are reads and writes waits for TLB and cache maintenance. The first DSB ISHST is right: it only needs the descriptor store to complete before the walkers can be asked to re-walk. B would weaken it to ordering only, and a DMB does not order the descriptor store against the later TLBI: a TLBI is not an explicit memory access.

Read more: Arm ARM (DDI0487), DSB; the AArch64 VMSA chapter, “TLB maintenance instructions” and the ordering and completion of TLB maintenance

Q7.6.2 A CPU_OFF path cleans the PE’s data cache to the PoC, writes a “core off” flag to Normal Non-cacheable memory for the power controller, and executes WFI. On one SoC it works. On another, the power controller occasionally waits forever for the flag. What is the most likely missing step?

  • A. A DSB SY before WFI, because WFI does not wait for the flag store or the cache clean to complete
  • B. An ISB before WFI, so that the flag store is executed
  • C. A DMB ST between the clean and the flag store
  • D. Making the flag memory Device-nGnRnE, so the store cannot be buffered
Answer

A. Without a DSB, the flag store (and the clean) may still be in flight when the PE stops. Whether WFI drains buffers is IMPLEMENTATION DEFINED, which explains the difference between the SoCs. B does nothing for completion. C orders the store after the clean but does not make either one complete. D changes where the acknowledgement comes from, but still nothing waits for it.

Read more: Arm ARM (DDI0487), WFI (“Wait For Interrupt”) and DSB; TF-A psci_power_down_wfi

Q7.6.3 Under the redefinition in Known Issues entry AARCH-24234, which use of the DSB argument still changes behaviour?

  • A. DSB ISHST vs DSB OSHST before a DMA doorbell
  • B. DSB ISHLD vs DSB LD after reading a mailbox
  • C. DSB ISH vs DSB SY for ordering two Device stores
  • D. DSB NSH vs DSB ISH after a broadcast TLBI VAE1IS
Answer

D. The argument is now a maintenance scope that matters only for TLBI and IC completion. After a broadcast TLBI, NSH scope is not enough to wait for the other PEs, and ISH is needed. For explicit accesses (A, B, C) completion does not depend on the domain, and the qualifiers on the LD/ST forms are deprecated.

Read more: Arm ARM (DDI0487), DSB; DDI0487 Known Issues, AARCH-24234

7.7 Acquire/release as one-way barriers

A DMB (7.5) is a two-way fence. It orders a class of accesses before it against a class of accesses after it. Acquire and release instructions attach the ordering to one access, and only in one direction. The result is usually cheaper and often closer to what the algorithm needs. These instructions do not give completion, so they never replace a DSB (7.6).

The three ordering rules

The Arm ARM states the Load-Acquire, Load-AcquirePC and Store-Release rules as clauses of barrier-ordered-before (bob) in the axiomatic model of 7.3. The relevant lines of aarch64.cat, abridged:

let bob = po; [dmb.full]; po
        | [L]; po; [A]        (* Store-Release then Load-Acquire  *)
        | [A | Q]; po         (* Load-Acquire(PC) before everything later *)
        | po; [L]             (* everything earlier before Store-Release *)
        | ...

Here A is a Load-Acquire (LDAR, LDAXR, the A forms of CAS/SWP/LDADD…), Q is a Load-AcquirePC (LDAPR, LDAPUR), and L is a Store-Release (STLR, STLXR, the L forms of the atomics).

RuleOrderedNot ordered
Acquire (LDAR, LDAPR)the acquire read before every program-order-later load and storeearlier accesses may still be performed after the acquire
Release (STLR)every program-order-earlier load and store before the release writelater accesses may be performed before the release
RCsc (STLR then LDAR)the release write is observed before the later LDAR is satisfiedSTLR then LDAPR: no ordering

So acquire is a fence that stops later accesses from moving up above it, and release is a fence that stops earlier accesses from moving down below it. A critical section bracketed by an acquire and a release can absorb surrounding accesses (“roach motel”), but nothing can leak out of it.

Some consequences that are easy to get wrong:

  • STLR orders earlier loads as well as earlier stores. A release is therefore not equivalent to DMB ISHST; STR. The nearest two-way equivalent is DMB ISH; STR, which is strictly stronger because it also orders the earlier accesses against everything after the STR.
  • LDAR is not equivalent to LDR; DMB ISHLD. The DMB ISHLD form also orders every earlier load against later accesses, which is stronger in one way. It does not give the [L]; po; [A] ordering against an earlier STLR, which is weaker in another.
  • The ordering applies to all memory types, Device included (7.9), and to the acquire/release forms of the exclusives and LSE atomics (10.1, 10.2).
  • Nothing here concerns completion. STLR does not wait for its write, or for any earlier write, to become visible before execution continues. It only constrains the order in which observers can see them. Anything with a non-memory side effect still needs a DSB: before WFI/WFE/SEV, after TLBI or cache maintenance, or before relying on a peripheral having seen a write.

Message passing with acquire/release

// P0: producer                 // P1: consumer
    str   w1, [x0]      // data     1:  ldar  w2, [x3]      // flag
    mov   w4, #1                        cbz   w2, 1b
    stlr  w4, [x3]      // flag         ldr   w5, [x0]      // data

The outcome “P1 sees flag = 1 and data = 0” is forbidden. po; [L] orders the data write before the flag write. The flag write is read by P1 (rfe), and [A]; po orders the flag read before the data read. That is an ordered cycle in the model of 7.3. On the consumer side, an address dependency would also work (7.4), and so would LDR; DMB ISHLD. LDAR (or LDAPR) states the intent and does not depend on the compiler preserving a dependency.

Since the 2017 revision Armv8 is other-multi-copy atomic for all stores (7.2). Older texts describe STLR as “multi-copy atomic” in contrast to plain stores. That distinction no longer exists. What remains special about STLR is the ordering it imposes, not how its write propagates.

RCsc vs RCpc: why LDAPR exists

LDAR is RCsc (release consistency, sequentially consistent). A Store-Release followed by a Load-Acquire to a different address cannot be reordered, so the store-buffering test with STLR/LDAR on both sides forbids the 0/0 outcome:

// SB+rel-acq       P0                    P1
                    stlr w1, [x0]  // x   stlr w1, [x2]  // y
                    ldar w3, [x2]  // y   ldar w3, [x0]  // x
// exists (0:X3=0 /\ 1:X3=0): forbidden with LDAR, allowed with LDAPR

That property costs hardware something real. An LDAR cannot be satisfied while an earlier STLR is still waiting in the store buffer, so a release followed by an acquire tends to drain the store buffer. C11/C++11 memory_order_acquire and memory_order_release only require RCpc (“processor consistent”): an acquire load does not have to be ordered after an unrelated earlier release store. Only memory_order_seq_cst needs the RCsc pairing.

LDAPR (Load-AcquirePC) is LDAR without the [L]; po; [A] clause. It keeps [Q]; po: every later access is still ordered after it. It just no longer waits for an earlier STLR.

FeatureInstructionsAvailability
base v8.0LDAR, LDARB, LDARH, STLR, STLRB, STLRH, LDAXR/STLXR and pair formsmandatory in v8.0
FEAT_LRCPCLDAPR, LDAPRB, LDAPRH (base register only)permitted from v8.2, mandatory from v8.3
FEAT_LRCPC2LDAPUR, LDAPURB/H/SB/SH/SW, STLUR, STLURB, STLURH: signed 9-bit unscaled immediate offsetmandatory from v8.4
FEAT_LRCPC3LDIAPP/STILP, writeback forms, SIMD&FP LDAP1/STL1see 10.3

Discovery is through ID_AA64ISAR1_EL1.LRCPC: 0b0001 means FEAT_LRCPC, 0b0010 adds FEAT_LRCPC2, and 0b0011 adds FEAT_LRCPC3. STLUR is an ordinary Store-Release with an offset. The “PC” only weakens the load side, so a separate “release-PC” store does not exist.

The offset forms matter more than they look. Before LRCPC2, an acquire or release of a structure field needed an ADD to form the address, because LDAR/STLR accept only [Xn]. Compilers emit LDAPUR/STLUR for atomic_load_explicit(&s->f, memory_order_acquire) when the target allows it.

The C11/C++11 mapping

This is the mapping GCC and LLVM use for AArch64 (the “Cambridge mapping”, with the RCpc refinement):

C/C++ operationA64 (without LSE / LRCPC)A64 with FEAT_LSE, FEAT_LRCPC
load relaxedLDRLDR
load acquire (and consume, which compilers promote to acquire)LDARLDAPR / LDAPUR
load seq_cstLDARLDAR (must stay RCsc)
store relaxedSTRSTR
store release / seq_cstSTLRSTLR / STLUR
RMW relaxedLDXR/STXR loopLDADD, SWP, CAS
RMW acquireLDAXR/STXRLDADDA, SWPA, CASA
RMW releaseLDXR/STLXRLDADDL, SWPL, CASL
RMW acq_rel / seq_cstLDAXR/STLXRLDADDAL, SWPAL, CASAL
atomic_thread_fence(acquire)DMB ISHLDDMB ISHLD
atomic_thread_fence(release / acq_rel / seq_cst)DMB ISHDMB ISH

Three points in this table are deliberate:

  1. seq_cst loads and stores need no fence. STLR followed by LDAR already has the RCsc ordering, so the classic “seq_cst store then seq_cst load” (Dekker) works with no DMB. For that reason a seq_cst load can never be lowered to LDAPR.
  2. A release fence is DMB ISH, not DMB ISHST. A release fence must order earlier loads against later stores, and DMB ISHST orders only store against store.
  3. Everything uses ISH. The C11 model’s threads are assumed to be PEs in one Inner Shareable domain. If the other side is a DMA master, an SCP/MCP outside the Inner Shareable domain, or memory that is Device or Normal Non-cacheable (always Outer Shareable, 6.4), stdatomic.h is not the right tool. Write explicit DMB OSH* or DSB sequences (7.10).

Bring-up note: In TF-A-style C, __atomic_load_n(p, __ATOMIC_ACQUIRE) on a v8.2 build without +rcpc compiles to LDAR. Building for -march=armv8.3-a or later, or adding +rcpc, changes it to LDAPR. A core that does not implement FEAT_LRCPC then takes an UNDEFINED exception. Pin -march to what ID_AA64ISAR1_EL1 actually reports on the slowest core in the system, not to the newest core on the SoC (1.1).

Security note: A release store publishing a pointer, together with an acquire load consuming it, is the minimum that stops a reader from seeing an initialised pointer to uninitialised contents. A reader using plain LDR with no dependency can see stale memory behind a fresh pointer, for example an attacker-controlled previous allocation. That is a publication bug: each individual access is single-copy atomic, yet the reader still uses stale data.

Checkpoint

Q7.7.1 Two PEs each run STLR W1, [own_flag] followed by an acquire load of the other PE’s flag. The final condition “both loads read 0” must be forbidden. Which load instruction choice achieves that, and why?

  • A. LDAPR on both sides, because every access after an acquire is ordered after it
  • B. LDR on both sides, because Armv8 is other-multi-copy atomic
  • C. LDAR on both sides, because a Store-Release is ordered before a program-order-later Load-Acquire (RCsc)
  • D. Either LDAR or LDAPR, because the release already orders all earlier accesses
Answer

C. This is SB. Forbidding 0/0 needs each PE’s store ordered before its later load, which is exactly the [L]; po; [A] clause of bob that LDAR carries and LDAPR drops. Option D is the tempting wrong answer: a release orders earlier accesses before itself and says nothing about later loads. Multi-copy atomicity (B) does not stop store buffering.

Read more: Arm ARM (DDI0487), Load-Acquire, Load-AcquirePC, and Store-Release; the definition of Barrier-ordered-before

Q7.7.2 A compiler lowers atomic_thread_fence(memory_order_release) to DMB ISH instead of the cheaper DMB ISHST. Why is DMB ISHST insufficient?

  • A. A release fence must also order earlier loads before later stores, and DMB ISHST orders only stores against stores
  • B. DMB ISHST does not order accesses to Normal Cacheable memory
  • C. DMB ISHST waits for completion, which is too slow and gives no extra ordering
  • D. DMB ISHST orders only the Inner Shareable domain, and release requires Outer Shareable
Answer

A. Release semantics forbid an earlier read from being satisfied after the releasing store becomes visible. Otherwise a reader that acquires could overwrite data that the releasing thread is still about to read (the load-buffering shape). DMB ISHST only orders write against write. Option D is wrong: compilers use ISH for every C11 fence. C is wrong because no DMB waits for completion.

Read more: Arm ARM (DDI0487), Data Memory Barrier; C/C++ to AArch64 mappings in the herdtools/Cambridge papers

Q7.7.3 Firmware posts a command for a PE by writing the command buffer and then doing STLR on a flag in Normal Cacheable memory. The other PE is in WFE. The producer executes SEV immediately after the STLR. Occasionally the consumer wakes, reads the old flag, and goes back to sleep forever. What is missing?

  • A. Nothing. STLR guarantees the flag is visible before any later instruction executes
  • B. An ISB between STLR and SEV
  • C. Replace STLR with DMB ISH; STR
  • D. A DSB ISH between the STLR and the SEV, because release orders memory effects but does not make the store complete before the non-memory event
Answer

D. SEV is not a memory access, so neither release semantics nor a DMB orders it. Only a DSB makes the flag write complete before the event is sent. Option A confuses ordering with completion. C has the same flaw in a different form. B synchronises the instruction context, not memory.

Read more: Arm ARM (DDI0487), Data Synchronization Barrier; Wait for Event mechanism and Send event

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:

EventCondition
Executing an ISBalways
Taking an exceptionunless 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 statealways
DCPS<n> or DRPS executed in Debug statealways

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_EL3 from a value that includes the architectural RES1 bits, so EIS = EOS = 1 by construction. If a firmware port computes SCTLR_EL3 from scratch (mov x0, #(SCTLR_M | SCTLR_C | ...)), it clears bits 22 and 11. On a FEAT_ExS core this silently makes every SMC entry and every ERET non-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 TLBI or IC IVAU becomes a context change only once a DSB has completed it. The ISB then 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 (and SYS/SYSL forms) 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_EL1 and TCR_EL1, the trap check for an FP instruction reading CPACR_EL1.FPEN, exception entry reading VBAR_EL3, and an ERET reading SPSR_EL3/ELR_EL3 (a special case: a direct write to these is visible to a later ERET without 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 counter CNTVCT_EL0 advancing, and acknowledging an interrupt changing the GIC running priority.

The rules that matter:

  1. A direct read after a direct write to the same register, in program order, returns the written value. No synchronization is needed.
  2. Direct writes to the same register take effect in program order.
  3. An indirect read after a direct write needs a CSE between them. This is the common case. Writing CPACR_EL1.FPEN and then executing FMOV reads FPEN indirectly, so an ISB is required.
  4. A direct read is not ordered against the instruction stream around it without a CSE. That is why reading CNTVCT_EL0 or a PMU counter at a precise point needs an ISB before the MRS (4.7, 16.5).
  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

ChangeMinimal sequenceReason
SCTLR_ELx.M, .C, .IMSR; ISBfetch and translation read these indirectly
TTBRn_ELx, TCR_ELx, MAIR_ELx, TCR2_ELx, PIR_ELxMSR…; ISB (plus TLB maintenance per 9.1)walks are indirect reads
TLBIDSB ISH (completion); ISBthe DSB completes the invalidate; the ISB stops later instructions from having been fetched or translated with stale entries
new code in memoryDC CVAU; DSB ISH; IC IVAU; DSB ISH; ISB8.6
CPACR_EL1, CPTR_EL2, CPTR_EL3 (FP/SVE/SME enables)MSR; ISB before the first FP/SIMD/SVE instructiontrap checks are indirect reads
ZCR_ELx.LEN, SMCR_ELxMSR; ISBvector length is read indirectly
VBAR_ELxMSR; ISB before any exception that must use the new tableexception entry reads it indirectly
SCR_EL3, HCR_EL2 routing and trap bitsMSR; ISB if they affect the current level; ERET suffices for the lower levelindirect reads at exception generation
ICC_SRE_ELxMSR; ISB before any other ICC_* accessrequired 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 regionMSR; ISBprevents measured instructions from executing before the counters are enabled
MDSCR_EL1, breakpoint/watchpoint registersMSR; ISBdebug 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-ISB bugs 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 with ESR_EL3.EC = 0x07 straight after enabling FP, exceptions vectoring to the old VBAR, or a translation fault whose FAR points into the stale map. A directed test cannot prove the ISB is needed, because either outcome is architecturally allowed. Treat this as a static review rule instead: for every MSR to a register in the table, find the CSE before the first dependent instruction. A Tarmac trace from the FVP still helps confirm that the ISB is present on the path that actually executes.

Security note: Exception return to a lower EL is the CSE that makes SCR_EL3/HCR_EL2 trap configuration and the lower EL’s translation registers take effect. If an EL3 handler changes those values and then returns along a path where EOS = 0 on a FEAT_ExS core, the lower EL may run some instructions under the previous world’s context. Keep EOS = 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. DSB is a context synchronization event for TLB maintenance
  • B. An ISB is still required before relying on the new translation for instructions on this PE, because DSB completes the invalidation but is not a CSE
  • C. An ISB is required instead of the DSB, because ISB waits for the TLBI to complete
  • D. No barrier is needed, because the MSR TTBR0_EL1 is 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, because ERET reads SPSR_EL3 indirectly
  • C. After the ERET, at the first instruction of EL1
  • D. Nowhere for these registers. The ERET is 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_CTLR is a memory-mapped register, so its write is a Device memory access. It needs ordering or completion (DSB, and the RWP poll the GIC defines), and a CSE does not provide that
  • B. ISB is correct, but must come before the write
  • C. The ISB is right, but DMB ISH is 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

7.9 Device memory ordering

6.2 defines the Device types and the G/R/E attributes. This section covers what those attributes do for ordering, what they do not do, and the bring-up question that matters most: when can software assume a peripheral has acted on a write?

What Device-nR orders, and what it leaves alone

The Non-Reordering attribute gives a guarantee that Normal memory never gets: for Device-nR memory, accesses to the same peripheral arrive at that peripheral in program order. This is an arrival-order guarantee at the endpoint, which is stronger than the observability order a DMB provides. The size of “the same peripheral” (the block over which nR applies) is IMPLEMENTATION DEFINED. Do not assume it covers two different IP blocks that happen to sit in adjacent 4 KB pages.

Both types used for MMIO in practice, Device-nGnRnE and Device-nGnRE, are nR. Program-ordered STRs to one UART or one timer frame therefore arrive in order with no barrier. Everything else needs an explicit barrier:

Earlier accessLater accessOrdered without a barrier?Barrier that orders it
Device-nR, peripheral PDevice-nR, same Pyes (arrival order)n/a
Device, peripheral PDevice, peripheral QnoDMB OSH (observation); DSB if Q’s side effect depends on P’s having happened
Normal (DMA buffer, descriptor)Device (doorbell)noDMB OSHST (or STLR to the doorbell)
Device (status/index read)Normal (buffer read)noDMB OSHLD (or LDAR for the status read)
Device writesystem-register write (ICC_EOIR1_EL1, MSR to a timer)no; a DMB does not order system-register writesDSB
Device writeWFI, power-down, resetnoDSB (7.6)

The domain is OSH for a reason. Device and Normal Non-cacheable memory are always treated as Outer Shareable, whatever SH says (6.4), and a peripheral or DMA master may sit outside the Inner Shareable domain. DMB ISH architecturally orders accesses only with respect to observers in the Inner Shareable domain. On many SoCs it happens to work, which is how the bug survives until a chiplet or an IO-coherent bridge changes the topology. DMB SY is also correct. TF-A and Linux use OSH because it is the minimum that is sufficient.

Acquire/release semantics apply to Device accesses as they do to Normal ones (7.7). STLR to a doorbell is therefore a valid single-instruction replacement for DMB OSHST; STR. It also orders earlier loads, which is stronger than needed but rarely costly. Device locations are never read speculatively and accesses are never repeated or merged beyond what G permits, so the only reordering left to control is between distinct endpoints and memory types.

nGnRnE vs nGnRE in practice

The only difference is E, Early write acknowledgement. It says who may send the write response:

  • nE: the response must come from the endpoint.
  • E: any point on the path may respond, such as an interconnect write buffer or a bridge. On AMBA this roughly corresponds to the transaction being marked bufferable.

E does not change the architectural order in which observers see the writes. It changes completion, and therefore what a DSB waits for. It also changes error attribution. An early responder cannot return the endpoint’s SLVERR/DECERR on that response, so a failing write to an E location surfaces later, if at all, as an asynchronous SError (3.4), far from the faulting STR.

Typical choices:

WhoMappingAttribute (MAIR encoding)
MMU or D-side translation offall data accessesDevice-nGnRnE (6.5)
TF-A MT_DEVICEall MMIODevice-nGnRE (0x04)
Linux ioremap()ordinary MMIODevice-nGnRE
Linux ioremap_np(), PCI config spacenon-posted requirementDevice-nGnRnE (0x00)

Whether nE is honoured end to end is a platform property, not something the PE can enforce. A bridge that converts to a protocol with posted writes, such as a PCIe root port, acknowledges early regardless of the attribute. Some interconnects treat all Device writes as bufferable. On many cores the attribute also affects how many writes may be outstanding at once, which is IMPLEMENTATION DEFINED and visible only as performance.

“Does a DSB ensure the peripheral saw it?”

Answer in layers:

  1. For an nE location: the write reached the endpoint. The Arm ARM states that a DSB executed by the PE that performed a write to a No Early write acknowledgement location completes only after that write has reached its endpoint in the memory system. This assumes the platform honours nE.
  2. For an E location: no. The DSB may complete when an intermediate buffer accepts the write. The write is ordered and will arrive, but it may not have arrived yet.
  3. Even for nE, “reached the endpoint” is not “took effect”. The peripheral may synchronise the write into another clock domain. An interrupt line it deasserts takes cycles to reach the GIC. A reset or clock controller starts a sequence that finishes later. The architecture can say nothing about any of that.

So the robust idioms, in order of strength, are:

  • Read back from the same peripheral. Because of nR, the read arrives at the peripheral after the write. When its data returns, the write has arrived, whatever E says. For PCIe, a read also flushes posted writes on the same path. Then use the read value or a DSB to order anything that follows.
  • Poll the peripheral’s own completion indication, for example GICD_CTLR.RWP, GICR_CTLR.RWP, or a power controller’s status register. Only the peripheral knows when its side effect has finished.
// ISR tail: clear the source, then EOI, without a spurious re-entry
    mov   w1, #IRQ_BIT
    str   w1, [x0, #UART_ICR]       // Device-nGnRE: may be acknowledged early
    ldr   w2, [x0, #UART_RIS]       // read-back, same peripheral, arrives after the clear
    dsb   sy                        // read complete before the system-register write
    msr   icc_eoir1_el1, x3         // EOI (and deactivate, if EOImode == 0)

With only DSB SY and no read-back, the code is architecturally correct for an nE mapping on a platform that honours nE. It is still exposed to rule 3, because the line deassertion may not yet have reached the GIC. That is why drivers add the read-back even when “the DSB should be enough”.

Validation note: Two cheap checks tell you whether the platform honours nE. (1) Time a STR + DSB SY pair to a distant peripheral mapped nGnRnE and then nGnRE, using CNTVCT_EL0 with ISB before each read (4.7), or the PMU cycle counter. If the latency is identical and short for both, something on the path acknowledges early regardless. (2) Write to an unmapped hole behind the same bridge with nGnRnE. On a platform that honours nE, the error arrives close to the STR (an SError right after the DSB, with ESR_ELx.ISS.AET/DFSC per 3.4). An error that arrives much later, or never, means the response was early. In pre-silicon, confirm the bufferable bit (AWCACHE[0] on AXI, or the EWA bit of the CHI MemAttr field) on the bus trace.

Bring-up note: Configuring one block and then starting another is the classic cross-peripheral case. Examples: program a clock divider and then release a reset, or set up an SMMU stream table and then enable a DMA master. nR does not cover two peripherals, and a DMB only orders observation. Use the first block’s completion status, or a read-back followed by DSB SY, before the second write.

Checkpoint

Q7.9.1 A driver writes a DMA descriptor to Normal, Inner Shareable, Write-Back memory that a hardware-coherent DMA engine reads. It then writes the engine’s doorbell, which is mapped Device-nGnRE. Which barrier between the two stores is the minimum sufficient one architecturally?

  • A. None. Device-nR keeps the two stores in order
  • B. DMB ISHST, because the descriptor is Inner Shareable
  • C. DMB OSHST, because the doorbell is Device (treated as Outer Shareable) and the DMA engine may be outside the Inner Shareable domain
  • D. DSB SY, because only completion guarantees the engine sees the descriptor
Answer

C. The order needed is store→store observation by the DMA engine, so a DMB of the ST type is enough, and the domain must include the engine. A is wrong because nR covers only accesses to the same peripheral, not Normal→Device. B often works in practice but is not architecturally sufficient. D works but is stronger than necessary for a coherent master. For a non-coherent master the maintenance itself needs a DSB (8.7).

Read more: Arm ARM (DDI0487), Device memory and Data Memory Barrier; shareability of Device memory

Q7.9.2 A store to a peripheral mapped Device-nGnRnE is followed by DSB SY. What does the architecture guarantee when the DSB completes, assuming the platform honours nE?

  • A. The peripheral has finished acting on the write, including any interrupt line deassertion
  • B. The write has reached its endpoint, but nothing is said about when the peripheral’s side effects finish
  • C. Only that the write is ordered before later Device accesses; completion is never architected for Device memory
  • D. That every other PE has executed a CSE and sees the new peripheral state
Answer

B. For a No Early write acknowledgement location, DSB completion means the write reached the endpoint. What the peripheral then does internally is outside the architecture, which is why read-back and status polling exist. A is the tempting overstatement. C describes a DMB.

Read more: Arm ARM (DDI0487), Early Write Acknowledgement; Data Synchronization Barrier

Q7.9.3 An ISR clears a peripheral’s interrupt status with a store (Device-nGnRE) and then writes ICC_EOIR1_EL1. The interrupt is occasionally re-taken at once. Which change addresses both the architectural gap and the platform gap?

  • A. Insert DMB OSH between the store and the MSR
  • B. Remap the peripheral as Device-nGnRnE, with no other change
  • C. Insert ISB between the store and the MSR
  • D. Read back a register of the same peripheral after the store, then DSB SY, then write ICC_EOIR1_EL1
Answer

D. The read-back relies on nR arrival order to prove that the clear reached the peripheral, regardless of E. The DSB orders that against the system-register write, which a DMB cannot do (A). B on its own still has no barrier against the MSR. C synchronises context, not memory.

Read more: Arm ARM (DDI0487), Device memory attributes (nR, nE); GICv3 (IHI0069), interrupt end of interrupt

7.10 Ordering patterns

This section assembles 7.5–7.9 into the sequences firmware actually writes. The idiom is bare-metal and TF-A style: explicit barriers, and MMIO accessors that do not contain barriers. The Linux barrier API (wmb, dma_wmb, smp_store_release, writel vs writel_relaxed…) and its A64 lowering are tabulated in Appendix C.

Bring-up note: TF-A’s mmio_write_32()/mmio_read_32() are plain volatile accesses with no barrier, so they behave like Linux’s writel_relaxed/readl_relaxed, not like writel/readl. Code ported from a Linux driver that relied on writel ordering a preceding DMA-buffer store must add the barrier explicitly. FreeRTOS ports are the same.

1. Doorbell after a descriptor (to-device, coherent master)

/* desc[] in Normal WB memory; the DMA engine is IO-coherent (snoops CPU caches) */
desc[tail].addr  = buf_pa;
desc[tail].len   = len;
desc[tail].flags = DESC_OWN_HW;      /* ownership last */
tail = (tail + 1) % RING_SZ;

dmboshst();                          /* dmb oshst: descriptor stores before doorbell */
mmio_write_32(DMA_BASE + TAIL_REG, tail);
  • ST is enough because the ordering needed is store→store.
  • OSH is needed because the doorbell is Device (Outer Shareable) and the engine is not guaranteed to be in the Inner Shareable domain (7.9).
  • The alternative is STLR on the doorbell: stlr w1, [x0].
  • If the engine is not coherent, the descriptor and buffer must be cleaned to the PoC first (DC CVAC…). Cache maintenance is completed by a DSB, not ordered by a DMB, so the sequence becomes DC CVAC loop; DSB OSH (TF-A’s clean_dcache_range ends with dsb sy); doorbell (8.7). After a DSB, no further DMB is required.

2. Consuming completions (from-device)

The device writes completion entries and then advances a producer index. The index may be in memory or in a Device register.

// x0 = &ring, x1 = DMA_BASE, w2 = my consumer index
    ldr   w3, [x1, #PROD_REG]      // Device read of producer index
    dmb   oshld                    // index read before entry reads (and before later stores)
1:  cmp   w2, w3
    b.eq  2f
    ldr   x4, [x0, x2, lsl #4]     // read entry w2
    // ... process ...
    add   w2, w2, #1
    and   w2, w2, #(RING_SZ - 1)
    b     1b
2:  // entry reads before handing slots back
    dmb   oshld                    // LD orders earlier loads against later loads AND stores
    str   w2, [x1, #CONS_REG]      // give slots back

Two non-obvious points:

  • DMB OSHLD is sufficient before the consumer-index store. The LD variant orders earlier loads against later loads and stores. That covers load→store, which is exactly “do not let the device overwrite an entry I have not read yet”.
  • If the index lives in coherent memory instead of a register, LDAR on the index replaces the first DMB. For a non-coherent master, entries must be invalidated (DC IVAC; DSB) before they are read, and the buffer must not be dirty in the CPU cache while the device writes it (8.7).

When completion is signalled by an interrupt, entering the handler is a context synchronization event (7.8). The handler’s loads are therefore not performed before the interrupt is taken. The device and interconnect must still make the data visible before the interrupt is delivered. With PCIe MSIs, the PCIe ordering rules take care of this. For a wired interrupt it is a property of the device and its integration. A polled loop gets no such help and needs the barrier shown above.

3. DSB before WFI, power-down and reset

SituationSequenceWhy
Idle (vPortSuppressTicksAndSleep, TF-A psci_power_down_wfi)DSB SY; WFIoutstanding accesses complete before the core may lose clocks; WFI itself does not wait for earlier accesses to complete (7.6)
CPU_OFF / cluster power-downclean to PoC, exit coherency, DSB SY, ISB, WFI8.8, 17.4
System reset via an SoC reset registerclean any data that must survive to PoC; DSB SY; reset STR; DSB SY; WFI loopthe reset write must leave the PE, and the PE must not run on into code that assumes it did not
Warm reset via RMR_EL3.RRDSB SY; ISB; MSR RMR_EL3, x0; ISB; WFI loopsequence given in core TRMs; on those cores the reset is acted on once the PE enters WFI, which is IMPLEMENTATION DEFINED rather than architectural

The “clean before reset” step is easy to miss. Boot flags, crash records and “reason for reset” words written with the caches on are lost if they are still dirty in a cache that the reset invalidates.

4. Inter-core mailbox (same Inner Shareable domain)

// Producer (PE0)                          // Consumer (PE1)
    stp   x2, x3, [x0]        // payload       sevl
    mov   w4, #1                          1:  wfe
    stlr  w4, [x1]            // flag          ldar  w5, [x1]      // flag
    dsb   ish                 // flag done     cbz   w5, 1b
    sev                                        ldp   x2, x3, [x0]  // payload
  • STLR/LDAR (or DMB ISH on each side) provides message passing (7.7).
  • DSB ISH before SEV is required because SEV is not a memory access. Without it, PE1 can wake, still see flag == 0, and sleep with no further event coming. That is a lost wake-up.
  • The consumer can avoid SEV entirely: load the flag with LDAXR, so that the producer’s store clears the exclusive monitor and generates the wake-up event (10.4).
  • If the doorbell is an SGI rather than an event, the sequence is: payload stores; DSB ISHST; MSR ICC_SGI1R_EL1, x0; ISB. A DMB cannot order a system-register write.
  • Put the request and response mailboxes on separate cache lines (use CTR_EL0.CWG as the safe granule). Otherwise the two directions ping-pong one line.

5. Inter-chiplet mailboxes

Nothing in the architecture mentions chiplets. What matters is which shareability domain and which coherency the two ends share.

Both ends in the same coherent Inner Shareable domain (for example, CHI C2C extending one coherent system across dies, 8.3). The pattern is identical to §4. Only the timing changes: cross-die line migration costs several times more than on-die. Windows that were nanoseconds wide become wide enough to hit, so a missing barrier that “never failed” on a monolithic die shows up here first.

Ends that are not mutually coherent (a management controller on another die, separate OS islands, or an accelerator’s control CPU). Then:

  1. Map the shared buffer Normal Non-cacheable on both sides, with identical attributes. A Cacheable mapping on one side and a Non-cacheable mapping on the other is the mismatched-alias case of 6.6.
  2. Producer: payload stores; DSB SY; doorbell store to the receiver’s MHU-style Device register. A DMB OSHST orders observation only for observers in the producer’s Outer Shareable domain. Whether the far die is in that domain is a platform property. A DSB makes the payload stores complete before the doorbell is issued, which does not depend on that answer.
  3. Receiver: take the doorbell interrupt (a CSE) or poll the doorbell status, then DMB OSHLD if polling, then read the payload.
  4. Send the acknowledgement the same way in the opposite direction, through its own buffer and doorbell.

Validation note: Stress each mailbox pattern with the endpoints placed on every pair of dies, not only on die 0. Use a sequence number plus a payload checksum: the receiver checks checksum(payload) == expected(seq). A stale payload with a fresh sequence number is the signature of a missing barrier or a mismatched attribute. Count failures over 107–109 iterations. On the interconnect side, CMN PMU events for cross-die (CCG/C2C) traffic confirm that the test really crossed the link (16.5).

6. Seqlocks

A seqlock lets readers run without writing shared state. They retry if a writer was active.

// Writer (writers already serialised by a lock)
    ldr   w0, [x9]            // seq
    add   w0, w0, #1          // odd: write in progress
    str   w0, [x9]
    dmb   ishst               // seq(odd) before data stores
    stp   x1, x2, [x10]       // data
    add   w0, w0, #1          // even: stable
    stlr  w0, [x9]            // release: data stores before seq(even)

// Reader
1:  ldar  w3, [x9]            // acquire: data loads after seq
    tbnz  w3, #0, 1b          // writer active
    ldp   x4, x5, [x10]       // data (possibly torn)
    dmb   ishld               // data loads before re-reading seq
    ldr   w6, [x9]
    cmp   w3, w6
    b.ne  1b                  // retry; only now are x4/x5 valid

The asymmetry is the point of the example:

  • The writer’s first increment cannot be an STLR. Release orders earlier accesses before the store, so the data stores could still become visible before seq turns odd. The writer needs the store→store DMB ISHST after it.
  • The reader’s second seq read cannot simply be LDAR. Acquire orders later accesses, and the issue here is the earlier data loads being satisfied after the seq re-read. That needs DMB ISHLD before the re-read.
  • In C, the data must be read with relaxed atomics (or volatile in firmware code), and the reader fence is atomic_thread_fence(memory_order_acquire), which is DMB ISHLD (7.7). Otherwise the compiler may cache or tear the data loads in ways the hardware barrier cannot repair.

Security note: Data read inside a seqlock retry loop is untrusted until the final comparison succeeds. Using a torn field as an index or length before the retry check is a functional bug. It is also a speculation gadget, because the comparison is a conditional branch (14.3). Validate first, and mask indices if they cross a privilege boundary.

Checkpoint

Q7.10.1 A consumer reads completion entries written by a coherent DMA engine and then writes the consumer index to a Device register, freeing those slots. Which barrier between the last entry read and the index write is the minimum sufficient?

  • A. DMB OSHST, because the operation to order is the index store
  • B. DMB OSHLD, because the LD variant orders earlier loads against later loads and stores
  • C. DSB SY, because a Device store cannot be ordered by a DMB
  • D. None, because the Device-nR attribute orders the store after earlier loads
Answer

B. The hazard is load→store: the device must not refill a slot before the CPU has read it. DMB LD covers earlier loads against later loads and stores. A is the tempting wrong answer, because DMB ST orders only stores against stores. C is wrong because a DMB does order Device accesses. D is wrong because nR covers only accesses to the same peripheral.

Read more: Arm ARM (DDI0487), Data Memory Barrier (the LD, ST and full variants)

Q7.10.2 In the seqlock reader, replacing DMB ISHLD; LDR seq with a single LDAR seq for the re-read is wrong. Why?

  • A. LDAR orders only later accesses after itself. The earlier data loads may still be satisfied after the re-read, so a torn read could pass the check
  • B. LDAR cannot be used on a location that another PE writes with STLR
  • C. LDAR is RCsc, so it deadlocks against the writer’s STLR
  • D. It is not wrong. LDAR is strictly stronger than DMB ISHLD
Answer

A. Acquire is one-way: it stops later accesses moving above it, not earlier ones moving below it. The second read needs every earlier data load ordered before it, which is exactly what DMB ISHLD provides. D is the misconception this question targets.

Read more: Arm ARM (DDI0487), Load-Acquire and barrier-ordered-before

Q7.10.3 A mailbox between two dies that are not mutually coherent uses a Normal Non-cacheable buffer and a Device doorbell register on the receiving die. Why does the producer use DSB SY rather than DMB OSHST between the payload stores and the doorbell store?

  • A. DMB does not order accesses to Normal Non-cacheable memory
  • B. DSB SY makes the payload coherent with the receiver’s caches
  • C. Whether the remote die is an observer in the producer’s Outer Shareable domain is platform-defined. DSB makes the payload stores complete before the doorbell is issued, regardless of that
  • D. The doorbell is a system register, so only a DSB can order it
Answer

C. DMB ordering is defined relative to the observers in its shareability domain. DSB SY waits for the payload stores to complete for the full system, a guarantee that does not depend on how the platform draws the Outer Shareable domain. B is wrong because a barrier performs no cache maintenance, and the buffer is Non-cacheable anyway. D is wrong because the doorbell here is memory-mapped.

Read more: Arm ARM (DDI0487), Data Synchronization Barrier and shareability domains

7.11 Lab and exercises: litmus testing from model to silicon

The lab has three parts. You compute what the architecture allows with herd7, observe what an implementation does with litmus7, and then reason about the gap between the two. The tests are the shapes from 7.3, with the barriers and dependencies of 7.4–7.5. Files go in labs/part07/ (Lab setup).

Step 0: tools

opam install herdtools7            # provides herd7, litmus7, diy7, mcompare7
herd7 -version
mkdir -p labs/part07/{tests,run-qemu,run-board}

herd7 ships the AArch64 model as aarch64.cat in its library directory and uses it by default for AArch64 tests. Passing -model aarch64.cat makes the choice explicit in your logs.

Step 1: write the tests

tests/MP+dmb.st+addr.litmus. The address dependency is the classic EOR-to-zero trick from 7.4:

AArch64 MP+dmb.st+addr
{
0:X1=x; 0:X3=y;
1:X1=y; 1:X3=x;
}
 P0          | P1                  ;
 MOV W0,#1   | LDR W0,[X1]         ;
 STR W0,[X1] | EOR W2,W0,W0        ;
 DMB ST      | LDR W4,[X3,W2,SXTW] ;
 MOV W2,#1   |                     ;
 STR W2,[X3] |                     ;
exists (1:X0=1 /\ 1:X4=0)

tests/SB+dmb.sys.litmus:

AArch64 SB+dmb.sys
{
0:X1=x; 0:X3=y;
1:X1=y; 1:X3=x;
}
 P0          | P1          ;
 MOV W0,#1   | MOV W0,#1   ;
 STR W0,[X1] | STR W0,[X1] ;
 DMB SY      | DMB SY      ;
 LDR W2,[X3] | LDR W2,[X3] ;
exists (0:X2=0 /\ 1:X2=0)

tests/WRC+addr+addr.litmus is three threads. It tests other-multi-copy atomicity (7.2):

AArch64 WRC+addr+addr
{
0:X1=x;
1:X1=x; 1:X4=y;
2:X1=y; 2:X4=x;
}
 P0          | P1                  | P2                  ;
 MOV W0,#1   | LDR W0,[X1]         | LDR W0,[X1]         ;
 STR W0,[X1] | EOR W2,W0,W0        | EOR W2,W0,W0        ;
             | MOV W3,#1           | LDR W3,[X4,W2,SXTW] ;
             | STR W3,[X4,W2,SXTW] |                     ;
exists (1:X0=1 /\ 2:X0=1 /\ 2:X3=0)

Also make the unfenced baselines MP, SB and WRC, by deleting the barriers and replacing each dependent access with a plain one. List all six in tests/@all.

Step 2: what the model says

cd labs/part07
herd7 -model aarch64.cat tests/@all > model.txt
herd7 -model aarch64.cat -show prop -graph columns -o dot tests/MP.litmus   # witness graph
dot -Tsvg dot/MP.dot > MP.svg

Expected verdicts:

Testherd7 ObservationWhy
MPSometimesnothing orders either side
MP+dmb.st+addrNeverDMB ST orders W→W; the address dependency is in dob
SBSometimesstore buffering is allowed
SB+dmb.sysNeverfull DMB orders W→R
WRCSometimesno ordering on P1 or P2
WRC+addr+addrNeverdependencies plus other-multi-copy atomicity

A Never line is the claim that the architecture forbids the outcome. The -show prop graph for MP shows the cycle that is allowed: po (P0), rfe, po (P1), fre. Neither po edge is in ob, so nothing closes it into a forbidden ordered cycle.

Step 3: run on QEMU TCG

litmus7 turns each test into a C harness with inline assembly. The harness runs as a Linux user program, so the guest needs Linux (Lab setup). Cross-compile a static archive:

litmus7 -a 4 -s 100k -r 20 -affinity incr1 -mem direct \
        -gcc aarch64-linux-gnu-gcc -linkopt -static \
        -o run-qemu.tar tests/@all
qemu-system-aarch64 -M virt -cpu max -smp 4 -m 2G -accel tcg,thread=multi \
        -kernel Image -append "console=ttyAMA0 root=/dev/vda rw" \
        -drive file=rootfs.ext4,format=raw,if=virtio -nographic
# in the guest:  tar xf run-qemu.tar && make && sh run.sh > qemu.txt

Typical result on an x86 host: MTTCG maps guest loads and stores onto the host’s TSO memory order. SB shows the relaxed outcome, but MP and WRC usually report Never although the architecture allows them. QEMU is a functional model, not a weak-memory model. It tells you that your harness and expected-outcome files work. It tells you almost nothing about Arm hardware.

Step 4: run on the FVP, then on a board

FVP Base RevC AEM. The model interleaves PEs in quanta and executes each PE in order, so every relaxed outcome comes out Never. The FVP is useful in two cases: bring-up of the harness on your exact software stack, and experiments with features that QEMU lacks. Run Linux on it with small -s/-r, because it is slow. Smaller quanta (see --help for the quantum option) increase interleaving but never create reordering. Cache-state modelling (--list-params | grep -i cache_state) changes timing, not the memory model.

Board (needs real hardware). Build natively with the same options, then run:

litmus7 -a 4 -s 1M -r 100 -affinity incr1 -mem direct -o run-board tests/@all
cd run-board && make -j && sh run.sh > board.txt
mcompare7 ../model.txt board.txt     # side-by-side model vs hardware

Step 5: read the histograms

Test MP Allowed
Histogram (4 states)
5005214 :>1:X0=0; 1:X4=0;
37    *>1:X0=1; 1:X4=0;
11523 :>1:X0=0; 1:X4=1;
4983226 :>1:X0=1; 1:X4=1;
Ok
Witnesses
Positive: 37, Negative: 9999963
Condition exists (1:X0=1 /\ 1:X4=0) is validated
Observation MP Sometimes 37 9999963

The line marked *> is the final condition. Read the result as a two-by-two matrix:

observed (Sometimes)not observed (Never)
model allowsnormalallowed-but-never-observed
model forbidsforbidden-but-observednormal

Allowed-but-never-observed is not a bug. Common causes: the microarchitecture never reorders that way (load buffering, LB, is rarely seen), the stress is too weak, or the platform is an in-order model. Software must still not rely on the outcome being absent, because the next core may produce it. Record the result as “allowed, unseen at N iterations” and try harder stress before you conclude anything.

Forbidden-but-observed is always a finding. Triage it in this order:

  1. Test bug. Check the initial-state lines, which register the condition names, and whether the dependency survives. A hand-written C harness can have its EOR optimised away. litmus7 copies the assembly verbatim, but your own tests may not. Also check memory type: litmus7 uses Normal WB memory, while a bare-metal port might use Device or Non-cacheable memory.
  2. Model mismatch. Check the herdtools7 version and the aarch64.cat revision. Pre-2017 material describes a non-MCA model (7.2).
  3. Environment. Check for a hypervisor underneath, a QEMU bug, or a missing isb in your own harness changes.
  4. Silicon. Record MIDR_EL1/REVIDR_EL1, check the published errata (1.3), and reduce the test to a minimum. Sweep -s and the affinity to find the conditions that trigger it. A well-known Armv7-era precedent is the Cortex-A9 read-after-read ordering erratum, exposed by exactly this kind of testing.

Step 6: stress

KnobHowWhat it exposes
Affinity-affinity incr1 vs incr2, or an explicit -p 0,8,16,24 from lscpu -e / /sys/devices/system/cpu/cpu*/topologysame cluster vs cross-cluster vs cross-die paths
Cache-line placement-mem direct/indirect, -stride <n>, -preload randomx and y in one line vs different lines and home nodes
Contention-a larger than the thread count (several instances run concurrently), plus stress-ng --cache N pinned to other coressnoop-filter and home-node pressure; longer store-buffer residency
Chipletspin P0 and P1 on different dies (NUMA nodes)C2C latency widens windows; a forbidden outcome here points at the cross-die coherence protocol
Volume-s 1M -r 1000, overnightrare outcomes (single digits per 109)

Validation note: For a new SoC, run the full diy7-generated AArch64 suite, not just these six tests. Run it at least once on each topology class: intra-cluster, inter-cluster and inter-die. Any forbidden-but-observed result is a release blocker. While the test runs, read the PMU events MEM_ACCESS and BUS_ACCESS and, on the interconnect, the CMN cross-die (CCG) counters (16.5). They confirm that the shared lines really moved between dies. A forbidden-outcome-free run in which the lines never left the local die proves nothing about C2C.

Exercises: fix the barrier

Assume Normal WB Inner Shareable memory, coherent PEs, and Device-nGnRE MMIO unless stated otherwise.

E1. Sending an SGI with a payload.

    str   x2, [x0]                 // payload for target CPU
    msr   icc_sgi1r_el1, x1        // send SGI
Answer

Insert dsb ishst before the MSR, and isb after it if the code depends on the SGI having been issued. A DMB cannot order a system-register write. Without the DSB, the target can take the SGI and read the old payload. See 7.10 §4.

E2. Releasing a secondary from a holding pen (TF-A-style). The secondary is still running with its D-cache and MMU off.

hold_entry[cpu] = ep;              /* primary, caches on */
hold_state[cpu] = HOLD_GO;
sev();
/* secondary: while (hold_state[me] != HOLD_GO) wfe();  jump(hold_entry[me]); */
Answer

There are three problems.

  1. Visibility. With the MMU off, the secondary’s data accesses are Device-nGnRnE (6.5). It reads memory directly and does not see lines that are dirty in the primary’s cache. The primary must clean both words to the PoC (DC CVAC, as TF-A’s flush_dcache_range does).
  2. Producer ordering and completion. The secondary may wake spuriously from WFE and poll at any time, so hold_state must not reach memory before hold_entry. Write hold_entry, clean it, DSB SY; then write hold_state, clean it, DSB SY; then SEV. The final DSB is also what makes the state visible before the event.
  3. Consumer side. Do not rely on nR between two loads to DRAM, because “same peripheral” is IMPLEMENTATION DEFINED. After the wait loop sees HOLD_GO, put dmb sy (or make the hold_state load an LDAR) before loading hold_entry. This protects against a stale entry left over from a previous power cycle.

E3. Installing vectors and unmasking SError.

    adr   x0, el3_vectors
    msr   vbar_el3, x0
    msr   daifclr, #4              // unmask SError
Answer

Add isb after the MSR VBAR_EL3. Exception entry reads VBAR_EL3 indirectly, so a direct write needs a CSE before it is guaranteed to be used (7.8). Without it, a pending SError taken right after the unmask can vector through the old (or reset UNKNOWN) table.

E4. Starting a non-coherent DMA engine.

1:  dc    cvac, x0                 // clean buffer, line by line
    add   x0, x0, x3
    cmp   x0, x1
    b.lo  1b
    dmb   osh
    str   w2, [x4, #DMA_START]
Answer

Replace dmb osh with dsb osh (or dsb sy). The master does not snoop, so it needs the cleans to have completed to the PoC. Only a DSB waits for cache maintenance to complete, and a DMB does not order DC CVAC against a later Device store in the sense required here. Also derive x3 from CTR_EL0.DminLine, not from a hard-coded 64 (8.5).

E5. FreeRTOS tickless idle.

mmio_write_32(PWRCTL_BASE + CORE_RET_EN, 1);   /* allow retention */
__asm__ volatile("wfi");
Answer

Use dsb sy between the two. The Device write must complete before the PE stops, and WFI itself does not wait for outstanding accesses to complete (7.6). If the controller samples the enable asynchronously, read the register back first (7.9).

E6. Seqlock writer.

    ldr   w0, [x9]
    add   w0, w0, #1
    stlr  w0, [x9]                 // seq odd
    stp   x1, x2, [x10]            // data
    add   w0, w0, #1
    stlr  w0, [x9]                 // seq even
Answer

The first STLR does not stop the later data stores from becoming visible before it. Replace it with str followed by dmb ishst. The second STLR is correct (7.10 §6).

Checkpoint

Q7.11.1 MP (no barriers) reports Never on QEMU TCG on an x86 host over 108 iterations. herd7 says Sometimes. What is the correct conclusion?

  • A. QEMU has a bug, because it must exhibit every allowed outcome
  • B. The herd model is too weak for this test
  • C. The outcome is allowed but not exhibited by this platform. Software must still not rely on its absence
  • D. MP is forbidden in practice on Armv8 since the 2017 multi-copy-atomicity revision
Answer

C. An implementation may be stronger than the architecture, and QEMU on a TSO host usually is. A is wrong because no implementation has to exhibit allowed outcomes. D confuses other-multi-copy atomicity (which forbids WRC-style outcomes with dependencies) with forbidding MP, which stays allowed without barriers.

Read more: Arm ARM (DDI0487), the AArch64 memory model; herdtools7 documentation, litmus7

Q7.11.2 On a two-die prototype, WRC+addr+addr reports Sometimes 3 in 109 runs, but only when P0 is on the other die from P1 and P2. The harness reproduces Never on single-die runs. What is the best next step?

  • A. Accept it, because rare outcomes are within architectural tolerance
  • B. Treat it as a likely ordering or coherence bug on the cross-die path. Confirm the test (dependencies intact, Normal WB memory), then minimise and file with MIDR_EL1/REVIDR_EL1, topology and counters
  • C. Add DMB SY to every thread until the outcome disappears, then close the issue
  • D. Rerun on the FVP to confirm
Answer

B. The model forbids the outcome, so any observation is a finding, and topology dependence points at the C2C path. C hides the symptom and loses the evidence. D cannot help because the FVP never reorders. A misreads “forbidden” as “rare”.

Read more: Arm ARM (DDI0487), multi-copy atomicity; herdtools7 documentation

Part 8: Caches and coherency

Prerequisites: 6.1 A hardware mental model, 6.3 Cacheability, 6.4 Shareability, 7.1 Observers, “observed by” and “completes”, 7.6 DSB

If you already know: how to read CTR_EL0/CLIDR_EL1/CCSIDR_EL1 and the difference between PoU and PoC, skim 8.1 and the first half of 8.4. If you have written CHI or ACE RTL or verification, skim 8.2 and use 8.3 as a lookup table.

Why this matters for bring-up/validation: most “it works with caches off” and “DMA data is occasionally stale” bugs, and most power-down hangs, come down to a missing or wrong-scope cache maintenance operation, or to an agent that was never made part of the coherency domain.

The architecture says very little about how caches are built. It tells software what it can discover (line sizes, levels, the Level of Coherency and Level of Unification), which observers the hardware keeps coherent, and a set of points in the memory system (PoU, PoC, PoP and the newer ones) that cache maintenance operations (CMOs) are defined against. This part starts from those architectural facts (8.1) and then looks under them. 8.2 covers the hardware coherency machinery (line states, snoop filters, inclusivity, system-level caches) so it is clear why most CMOs are only needed for non-coherent observers. 8.3 follows individual A64 instructions onto the interconnect as ACE/CHI transactions, across DSU, CMN and chip-to-chip links.

With that model in place, 8.4 defines every architectural point and contrasts “where data must reach” with the “who must see it” of shareability. 8.5–8.7 cover the data and instruction CMOs and the DMA sequences built from them. 8.8 is the single home for cache handling at power transitions. 8.9 covers MPAM, which partitions the same caches and bandwidth. 8.10 turns the part into tests you can run.

8.1 Cache organisation

The Arm ARM does not describe a cache hierarchy. It describes the behaviour of caches as software sees it, and a small set of ID registers. Those registers give software what it needs to write correct maintenance code: line sizes for by-VA loops, the levels to walk for set/way loops, and the levels at which the PoU and PoC lie. This section covers those registers and the guarantees behind them. The points themselves are defined in 8.4.

What the architecture guarantees about cache structure

  • Data and unified caches behave as PIPT. Whatever the real indexing scheme, software never sees VA aliasing in data caches: two VAs mapping the same PA with the same attributes always see the same data. Aliasing between attributes is a different problem (see 6.6).
  • Instruction caches can have a different policy, reported in CTR_EL0.L1Ip. They are not required to be coherent with data caches or with memory. That is why code modification needs explicit maintenance (8.6).
  • Allocation is unpredictable. Any location that is mapped with a cacheable Normal attribute and is accessible under the current translation regime can be allocated into a cache at any time, including speculatively, and without any program-order access to it. It can also be evicted at any time. Every DMA and power-down rule in 8.7 and 8.8 follows from this.
  • Cache sizes and line counts are not architectural. The ID registers below say how to manage the caches, not how big they really are. Recent DDI0487 issues say explicitly that CCSIDR_EL1 is intended for set/way management and need not describe the physical cache. Some implementations report a reduced or synthetic geometry.

CTR_EL0: the by-VA maintenance parameters

CTR_EL0 is the register that by-VA CMO loops depend on. EL0 can read it when SCTLR_EL1.UCT == 1. It is trapped to EL2 by HCR_EL2.TID2, and with FEAT_FGT also by a fine-grained trap.

FieldBitsMeaning
IminLine[3:0]log2(words) of the smallest I-cache line of all instruction caches controlled by the PE
L1Ip[15:14]L1 instruction cache policy (see below)
DminLine[19:16]log2(words) of the smallest data/unified cache line of all levels controlled by the PE
ERG[23:20]Exclusives Reservation Granule, log2(words). 0 means “not reported”: assume 512 words (2 KB)
CWG[27:24]Cache Writeback Granule, log2(words). 0 means “not reported”: assume 2 KB, or derive it from the largest CCSIDR_EL1.LineSize
IDC[28]D-cache clean to PoU is not required for I/D coherence (8.6)
DIC[29]I-cache invalidation to PoU is not required for I/D coherence (8.6)
TminLine[37:32]FEAT_MTE2: log2(tag granules) of the smallest tag-cache line

A “word” is 4 bytes, so the line size in bytes is 4 << DminLine. A value of 4 means 64 bytes.

    mrs   x1, ctr_el0
    ubfx  x1, x1, #16, #4      // DminLine
    mov   x2, #4
    lsl   x2, x2, x1           // x2 = D-cache line size in bytes (stride for DC by VA)
    sub   x3, x2, #1
    bic   x0, x0, x3           // align start address down to a line

DminLine is the minimum across levels because a loop with a smaller stride is always correct: it just issues some redundant operations. A stride larger than the smallest line would skip lines.

CWG is the granule of memory that a cache writeback may overwrite when one modified line is evicted. It is the number that matters for DMA buffer alignment (8.7). If a buffer the device writes shares a CWG-sized block with CPU-written data, an eviction of the CPU’s dirty data can overwrite what the device wrote. ERG bounds the region an exclusive monitor may track (10.1). Two lock words inside one ERG can clear each other’s reservations.

Bring-up note: on heterogeneous systems (big.LITTLE, DynamIQ with mixed cores) CTR_EL0 can differ between cores. Code that reads it once on the boot core and caches the stride is wrong if another core has a smaller line. Linux computes a system-wide “safe” value (the minimum DminLine/IminLine, IDC/DIC only if every core has them). If cores disagree, it clears SCTLR_EL1.UCT and emulates EL0 reads. TF-A reads CTR_EL0 on every call to its cache helpers, which avoids the problem.

L1Ip: instruction cache policy

L1IpPolicyStatus
0b00VPIPT (VMID-aware PIPT)Added in a later Armv8 issue of DDI0487 (no FEAT_ name). Since removed from the architecture (now reserved). No implementation is known, and Linux dropped support in 2023
0b01AIVIVT (ASID-tagged VIVT)Listed in early DDI0487 issues; now reserved, and no Armv8 implementation used it
0b10VIPTPermitted
0b11PIPTPermitted

With PIPT, an IC IVAU by any VA that maps the PA invalidates the line. With VIPT, the index can contain VA bits above the page offset when a way is larger than the page size. The same PA can then sit in the I-cache under different index bits for different VAs, and maintenance by one VA is not a reliable way to remove entries created through another alias. This is why Linux falls back to IC IALLU/IC IALLUIS when it makes a new user page executable on a VIPT I-cache. VPIPT was PIPT with VMID-tagged entries, where IC maintenance at EL1 affected only the current VMID. Hypervisors had to invalidate on VMID reuse. Code that still checks for 0b00 should treat it as reserved.

CLIDR_EL1: which levels exist, and where the PoU and PoC lie

FieldBitsMeaning
Ctype1–Ctype7[20:0], 3 bits each0b000 none, 0b001 I only, 0b010 D only, 0b011 separate I and D, 0b100 unified
LoUIS[23:21]Level of Unification, Inner Shareable
LoC[26:24]Level of Coherence
LoUU[29:27]Level of Unification, Uniprocessor
ICB[32:30]Inner cache boundary: the last level that holds Inner-cacheable attributes (0 = not disclosed)
Ttype1–Ttype7[46:33]FEAT_MTE2: tag-cache type per level

The three “Level of” fields are counts. LoC = 3 means that levels 1 and 2 must be cleaned or invalidated to make data coherent at the PoC, and level 3 and beyond need not be. They are the bounds of a set/way loop. LoC = 0 means no cache needs maintenance to reach the PoC. On some systems that is literally true. On others the caches below the PoC are hardware-coherent with every master. A LoUU of 1 on a core whose L1 I- and D-caches are unified at L2 means DC CVAU only needs to push data out of L1D. A LoUU of 0 is possible when the L1 I-cache snoops the D-cache. CTR_EL0.IDC is the by-VA equivalent statement.

The architecture places a level of caching relative to a point, not to physical blocks. A DSU L3 or a CMN system-level cache may or may not count as a “level” in CLIDR_EL1. A system cache that lies beyond the PoC is invisible to CLIDR_EL1 (see 8.2). Do not infer the SoC topology from CLIDR_EL1.

CSSELR_EL1 and CCSIDR_EL1: per-level geometry

To read the geometry of one cache, select it with CSSELR_EL1 and read CCSIDR_EL1. The select is a system-register write whose effect on a later MRS is only guaranteed after an ISB (7.8).

    // x0 = level (0-based) ; select data/unified cache at that level
    lsl   x1, x0, #1           // CSSELR_EL1.Level is bits [3:1]; InD [0] = 0
    msr   csselr_el1, x1
    isb                        // CSSELR write must be synchronized before reading CCSIDR
    mrs   x2, ccsidr_el1

CSSELR_EL1 fields: InD [0] (1 = instruction cache), Level [3:1], and TnD [4] (FEAT_MTE2: separate allocation-tag cache).

CCSIDR_EL1 has two layouts, chosen by ID_AA64MMFR2_EL1.CCIDX (FEAT_CCIDX, OPTIONAL from v8.2):

FieldWithout FEAT_CCIDX (32-bit)With FEAT_CCIDX (64-bit)
LineSize = log2(bytes) − 4[2:0][2:0]
Associativity = ways − 1[12:3][23:3]
NumSets = sets − 1[27:13][55:32]

In AArch32 the wider NumSets does not fit, so FEAT_CCIDX adds CCSIDR2 (and the AArch64 CCSIDR2_EL1), which holds NumSets separately. Code that hard-codes the 32-bit layout reads garbage on a FEAT_CCIDX core. A set/way loop that uses those values can then miss most of the cache. TF-A and Linux both check CCIDX before decoding.

LineSize here is the real line length for that level, used as the set index shift in set/way operands (8.5). It is not CTR_EL0.DminLine, which is a minimum across levels. HCR_EL2.TID2 traps CTR_EL0, CCSIDR_EL1, CCSIDR2_EL1, CLIDR_EL1 and CSSELR_EL1. With FEAT_EVT, HCR_EL2.TID4 traps the latter four without CTR_EL0. KVM uses these traps to present a fixed, migratable geometry to guests.

Putting it together

ID register     answers                                      used by
-----------     -------                                      -------
CTR_EL0         by-VA stride (DminLine/IminLine), I-policy,  DC/IC by VA loops, DMA alignment,
                IDC/DIC, CWG, ERG                            JIT, exclusives layout
CLIDR_EL1       which levels exist; LoUU/LoUIS/LoC           bounds of set/way loops
CSSELR_EL1 +    sets, ways, line length of one level         set/way operand encoding
CCSIDR_EL1

Validation note: silicon validation should check that the ID registers agree with the RTL configuration and with each other. Check that CTR_EL0.DminLine is not larger than the smallest CCSIDR_EL1.LineSize, that LoC/LoUU/LoUIS match the documented hierarchy, and that IDC/DIC are set only when the coherence they promise is real. Test the last one by writing an instruction through the D-side, skipping the operations IDC/DIC say are unnecessary, and executing it in a loop, as in 8.10. A wrong DIC = 1 shows up as stale-instruction execution that only appears under cache pressure.

Checkpoint

Q8.1.1 A boot-time routine on a big.LITTLE system reads CTR_EL0 on the boot core (DminLine = 4) and stores the 64-byte stride in a global variable. A secondary core of the other type has a 32-byte L1D line. What is the consequence for DC CIVAC loops run on that secondary core?

  • A. None, because DC CIVAC operates on whole cache lines of whatever size the executing core has
  • B. None, because DminLine is defined as the system-wide minimum
  • C. Every other 32-byte line of the range may be left unmaintained on that core, so dirty data can survive the “clean”
  • D. The loop faults with an alignment fault because the addresses are not 32-byte aligned
Answer

C. DminLine is the minimum over the caches controlled by that PE, not over the system. A 64-byte stride on a core with 32-byte lines maintains only the line containing each address it issues, so alternate lines are skipped. A is the tempting option: each operation does maintain a whole line, but only the line that contains its address. DC by VA operations are not alignment-checked, so D is wrong.

Read more: Arm ARM (DDI0487), CTR_EL0 (DminLine); Linux arm64 read_sanitised_ftr_reg(SYS_CTR_EL0)

Q8.1.2 On a core with FEAT_CCIDX, legacy firmware decodes CCSIDR_EL1 as NumSets = bits[27:13], Associativity = bits[12:3]. What is the most likely visible result?

  • A. Its set/way clean loop issues the wrong set and way counts, so dirty lines stay in the cache and the data is lost at power-down
  • B. Nothing, because FEAT_CCIDX only changes the AArch32 view
  • C. An UNDEFINED exception when CCSIDR_EL1 is read
  • D. Nothing on single-cluster systems, because CCSIDR_EL1 is only consulted for L3
Answer

A. With FEAT_CCIDX, CCSIDR_EL1 is 64-bit: Associativity is [23:3] and NumSets is [55:32]. Decoding the old layout yields nonsense counts. Usually the counts are too small, so most sets or ways are never cleaned, and the failure only shows up when a power-down drops dirty data. B is wrong: the AArch64 register layout itself changes, and CCSIDR2 exists because AArch32 cannot hold the wider field.

Read more: Arm ARM (DDI0487), CCSIDR_EL1, CCSIDR2_EL1, ID_AA64MMFR2_EL1.CCIDX

Q8.1.3 CLIDR_EL1 reports Ctype1 = 0b011, Ctype2 = 0b100, LoUU = 1, LoC = 2. The SoC also has a 16 MB system-level cache in the interconnect. What can you conclude?

  • A. The system cache is a third level that CLIDR_EL1 failed to report, which is an erratum
  • B. To publish new code to instruction fetch on this PE, both L1 and L2 must be cleaned
  • C. A set/way loop must cover levels 1, 2 and the system cache to reach the PoC
  • D. Only L1 and L2 need maintenance to reach the PoC, and the system cache sits beyond the PoC or is otherwise transparent to all observers
Answer

D. LoC = 2 means levels 1 and 2 are the only ones that need maintenance to reach the PoC. A system cache beyond the PoC (or one every master goes through coherently) is architecturally invisible and needs no CPU maintenance. LoUU = 1 means only L1 needs cleaning for I/D unification, so B is wrong. A is the tempting option, but CLIDR_EL1 reports the levels that matter for maintenance, not every SRAM in the SoC.

Read more: Arm ARM (DDI0487), CLIDR_EL1 (LoC, LoUU, Ctypen)

8.2 Hardware coherency concepts

Most of the material in this section is not architectural. The Arm ARM does not mention MOESI, snoop filters or inclusivity. It states the outcomes hardware coherency must provide and leaves the mechanism to the implementation and to the AMBA protocols (ACE, CHI). The mechanism still matters for this reader for two reasons. It explains which observers need cache maintenance operations at all. It is also where validation finds bugs that the architectural model only describes as “forbidden outcome observed”.

Coherence vs ordering

Coherence is a per-location property. For each location, all writes appear in a single total order (the coherence order of DDI0487 B2), and every observer that reads the location sees values consistent with it. The ordering model of Part 7 is about the relation between locations, and is built on top of coherence. A cache-coherent system can still produce the MP outcome of 7.3 when the barriers are missing, and a coherence bug can break even a correctly fenced program. Validation needs to keep the two failure classes apart: a CoRR or CoWW violation on one address is a coherence bug and always a hardware bug, while a missing-barrier outcome is usually a software bug.

Line states: MOESI as ACE and CHI name them

Hardware keeps one invariant per line: at any instant there is either one writer or many readers (single-writer/multiple-reader), and at most one cache is responsible for the dirty data. AMBA names the states on two axes, Unique/Shared and Clean/Dirty:

MOESIACE/CHIMeaning
MUniqueDirty (UD)Only copy, modified; this cache must write it back
OSharedDirty (SD)Other copies may exist; this cache owns the dirty data
EUniqueClean (UC)Only copy, matches memory; can be written without a transaction
SSharedClean (SC)Other copies may exist; not responsible for writeback
IInvalid (I)—
—CHI: UniqueCleanEmpty (UCE), UniqueDirtyPartial (UDP)Ownership held with no or partial valid data (for full-line writes without a read)

A store to a line in a Shared state must first gain uniqueness (CHI CleanUnique or ReadUnique). That transaction invalidates the other copies, which is where the cost of true and false sharing comes from (8.10). A load miss on a line that is UniqueDirty in another cache is satisfied by a snoop: the owner forwards the data and either keeps ownership (SD) or passes the dirty data on. The exact transitions belong to the protocol and the implementation. 8.3 maps instructions onto them.

Finding the copies: snooping, directories, snoop filters

  • Broadcast snooping. Every coherent miss snoops every other coherent cache. The CCI-400 generation (Cortex-A53/A57/A72 clusters with ACE ports) worked this way. It is simple, but snoop traffic grows with the number of agents.
  • Directory / snoop filter. A structure at the home of each address records which caches may hold the line, so only those caches are snooped. In a CMN mesh, each HN-F keeps a snoop filter for its address slice. A DSU also tracks its cores’ L1/L2 contents, so it can answer snoops for the cluster.
  • Snoop filter capacity. A snoop filter is a finite cache of tracking entries. When it must evict an entry, it has to back-invalidate the line from every cache that may hold it. A core can therefore lose a line it is actively using because of activity elsewhere. This is architecturally invisible, because the line is just refetched, but it costs performance. It also stresses coherence corner cases (an eviction racing with a store or with an exclusive), which makes it a validation target.

Inclusivity

PolicyOuter level holds…Consequence
Inclusiveeverything in the inner levelsThe outer tags double as a snoop filter, but evicting an outer line forces back-invalidation of inner copies
Exclusivelines not in the inner levelsMaximum capacity. Lines move between levels on fill and eviction
Non-inclusive, non-exclusive (NINE)eitherTypical modern choice. Tracking is done by a separate snoop filter

Inclusivity is IMPLEMENTATION DEFINED and can differ per level and per core; check the TRM. Software must never depend on it. The architectural CMOs are defined so that they work whatever the policy: a by-VA clean to PoC must find the line wherever it is in the hierarchy up to the PoC. Set/way operations, in contrast, act on one level of one PE’s local hierarchy. With exclusive or NINE caches a line can migrate between levels, or to another PE, while a set/way loop runs. This is one reason set/way cannot be used for coherency (8.5).

The system-level cache

A system-level cache (SLC) lives in the interconnect, for example in each CMN HN-F, rather than in a cluster. Two properties matter:

  1. It is usually memory-side. Every coherent and IO-coherent agent reaches memory through the home node, so the SLC is transparent to all of them. In architectural terms it is at or beyond the PoC. CLIDR_EL1 does not report it, and no CPU maintenance is needed for it.
  2. “Usually” is the catch. An agent that reaches DRAM by a path that bypasses the home node sees memory without the SLC’s contents, for example a debug or test master wired directly to the memory controller, or a second die whose accesses are not homed in this die’s HN-F. For such an agent the PoC is not where the system designer thinks it is; strictly, such a system does not meet the PoC definition. Because “clean to PoC” is defined by observers, not by a physical place, the 2024 extensions add more precise targets in both directions: outer-cache CMOs (FEAT_OCCMO, DC CVAOC/DC CIVAOC) that push data only as far as an outer cache such as an SLC, when that is all the consumer needs, and a Point of Physical Storage (FEAT_PoPS, DC CIVAPS) for when the physical storage itself must hold the data (8.4).

Which observers hardware keeps coherent

The architectural statement: for Normal memory that is Inner and Outer Write-Back cacheable and Inner Shareable, hardware keeps the data coherent for all observers in the Inner Shareable domain that access it with the same attributes. No CMO is needed between PEs, ever. The attribute conditions are what matter in practice:

ObserverCoherent with PE data caches?Maintenance needed
Other PEs, same Inner Shareable domain, same cacheable attributesYes (snooped)None. Barriers only (Part 7)
Fully coherent agent (CHI RN-F accelerator, CXL.cache device)Yes, both waysNone
IO-coherent master (ACE-Lite or CHI RN-I/RN-D issuing snoopable transactions, typically through an SMMU with cacheable shareable attributes)Its reads snoop PE caches, and its writes invalidate PE copies. It has no snooped cache of its ownNone, provided the transactions really are marked snoopable (8.7, 11.5)
Non-coherent master (plain AXI, or non-snoopable attributes)NoClean to PoC before it reads; invalidate before the CPU reads what it wrote (8.7)
The PE’s own instruction fetchNot requiredDC CVAU + IC IVAU unless IDC/DIC say otherwise (8.6)
Translation table walksCoherent if the walk attributes (TCR_ELx.IRGNn/ORGNn/SHn) are cacheable and match the data mappingIf walks are Non-cacheable, clean table updates to PoC
The same PE through a mismatched alias (for example a Non-cacheable mapping of cacheable data)NoSee 6.6
Agents beyond a PA-space or encryption boundaryDefined by RME/MECPoPA/PoE operations (8.4, 12.4)

The table is the main point of this section. Most CMOs exist only for the rows that say “No” or “Not required”. In a well-built server SoC, nearly all DMA is IO-coherent and the CPU never issues a data CMO in steady state. In a cost-reduced embedded SoC, or in pre-silicon models where the interconnect is a stub, every DMA path may be non-coherent. Bring-up firmware has to know which kind it is running on, per master.

Bring-up note: “IO-coherent” is a property of a whole path, not of a device. The device must emit snoopable transactions, or the SMMU must override its attributes (STE/CD memory attributes, the SMMU_CR1 table-walk attributes for its own fetches). The interconnect port must be configured to accept snoops (ACE-Lite port enabled, or RN-I configured). The memory must be mapped Inner and Outer Write-Back shareable on the CPU side. Any one of these missing gives a path that is silently non-coherent and works “most of the time”.

Validation note: to confirm that a path is actually coherent, have the CPU write a pattern to a cacheable line and leave it dirty (no CMO), then have the master read it. A coherent path returns the new pattern. On the interconnect PMU, an HN-F snoop event should increment (Linux arm-cmn exposes, for example, hnf_snp_sent, hnf_dir_snoops_sent and hnf_sf_hit; CMN S3 HN-S nodes use the hns_ prefix), and the CPU-side writeback or snoop-related counters should move (which events count snoop-caused writebacks is core-specific; check the TRM). Then reverse the direction: the master writes, and the CPU reads a line it previously held. A stale value means the master’s write did not invalidate the CPU’s copy. To provoke snoop-filter back-invalidation, run a footprint larger than the snoop filter’s coverage on other cores and repeat; hnf_sf_evictions and hnf_sfbi_dir_snp_sent/hnf_sfbi_brd_snp_sent confirm that it happened.

Checkpoint

Q8.2.1 A DMA engine sits behind an SMMU on an ACE-Lite port. The CPU maps the buffer Normal Inner/Outer Write-Back Inner Shareable. The SMMU STE leaves the device’s own AxCACHE attributes, which mark accesses Non-cacheable non-snoopable, unchanged. The CPU writes a descriptor and rings the doorbell with the correct DMB. What is the risk?

  • A. None, because an ACE-Lite port makes all accesses from the device IO-coherent
  • B. The device can read stale data from DRAM while the descriptor is still dirty in a CPU cache, because its transactions are not snooped
  • C. None, because DMB OSH before the doorbell forces the dirty line out to memory
  • D. The SMMU reports a permission fault because the attributes mismatch
Answer

B. Coherency depends on the transaction attributes. A non-snoopable read goes to memory without looking in the CPU caches. C is the tempting option, but a barrier orders and completes accesses. It never moves data out of a cache, so only a CMO (clean to PoC) or a snoopable path would help. A is wrong because an ACE-Lite port only allows snoopable transactions.

Read more: Arm ARM (DDI0487), shareability and coherency of Normal memory; SMMUv3 (IHI0070), STE memory attribute overrides

Q8.2.2 On a two-core system, a test observes core 1 read x = 2 and then a later read of x by the same core return 1, where core 0 performed x = 1; x = 2 with no barriers. What does this imply?

  • A. Expected behaviour: the test needs a DMB between core 0’s stores
  • B. Expected behaviour: core 1 needs a DMB LD between its two loads
  • C. A software bug, because x should have been declared atomic
  • D. A coherence violation (CoRR), which is forbidden without any barrier and points to a hardware or model bug
Answer

D. Two reads of the same location by one observer must not go backwards in that location’s coherence order, whatever barriers are present (read-read coherence). Barriers order accesses to different locations. A and B apply the ordering-model tools to a per-location property. This is exactly the separation a validation triage needs.

Read more: Arm ARM (DDI0487), the AArch64 application-level memory model, coherence order and the internal visibility requirement

Q8.2.3 A test master is wired directly to the DRAM controller, bypassing the CMN HN-Fs that contain the system-level cache. Firmware cleans a buffer with DC CVAC before the master reads it. The master still sometimes sees old data. Which explanation is most plausible?

  • A. The clean to PoC left the data in the SLC, which is beyond the architectural PoC for HN-routed agents but not for an agent that bypasses it
  • B. DC CVAC only cleans L1, so DC CIVAC is required
  • C. The master needs a DSB SY executed on its side
  • D. CLIDR_EL1.LoC is misreported and the set/way loop missed a level
Answer

A. The PoC is defined by the observers the system designer included. An agent that bypasses the home node is effectively outside that definition, so for it the SLC is a non-coherent cache. Fix it in the system design (route the master through an HN, or have the SLC treat its accesses correctly), or with operations that target further out where the architecture provides them. B is wrong: DC CVAC cleans every level up to the PoC.

Read more: Arm ARM (DDI0487), Point of Coherency definition; Terminology for Clean, Invalidate, and Clean and Invalidate instructions (PoPS)

8.3 Coherency at system scale: instructions to transactions

This section follows A64 instructions out of the PE and onto the interconnect. It covers what goes on the wire, who answers, and what a DSB waits for. Nothing here is architectural. The mapping from instructions to AMBA transactions is chosen by each core and interconnect implementation, and the tables give the typical mapping, not a guarantee. The architecture constrains only the outcomes. The point of having this model is that bring-up hangs, CMO bugs and silicon-validation failures all show up at transaction level.

The topology

  core  core  core  core          (L1I/L1D, private L2)
    \    |     |    /
     DSU: L3 + snoop filter, cluster coherency       ---- CHI (or ACE on older DSUs)
         |
   +-----XP------XP------XP------+    CMN mesh of crosspoints (XP)
   |   RN-F     HN-F    HN-F      |    RN-F  = fully coherent requester (a DSU / cluster)
   |   RN-I     HN-F    MN        |    RN-I/RN-D = IO requester (PCIe RC, SMMU TBUs, DMA)
   |   HN-I     SN-F    CCG       |    HN-F  = home node: PoS, SLC slice, snoop filter
   +-----------------------|------+    HN-I  = home for IO/Device address ranges
                           |           SN-F  = memory controller port
                       chip-to-chip    MN    = misc node: DVM broadcast/sync (DN)
                       (CML/CCIX/CXL,  CCG   = CXL/CCIX gateway to another die
                        CHI C2C)

The important rule is one home per address. Physical addresses are hashed across HN-Fs (an HN-S in CMN S3). The home is the Point of Serialization for its addresses: requests to the same line are ordered there, it consults the snoop filter, sends snoops, returns data and, in the end, sends the Comp (completion) response. The architecture’s “complete” (7.1) corresponds, roughly, to the requester having received the response that guarantees the access is globally observable for the required domain. A DSB waits for exactly those responses.

Loads, stores and evictions

Instruction / eventTypical ACETypical CHIWho answers
Cacheable load missReadShared / ReadCleanReadNotSharedDirty, ReadShared, ReadCleanHN-F: from SLC, a snooped owner, or SN-F
Cacheable store, line absentReadUniqueReadUniqueHN-F, after invalidating other copies
Store to a line held SharedCleanUniqueCleanUnique (or MakeReadUnique)HN-F invalidates the other sharers
Full-line write (streaming, DC ZVA)MakeUniqueMakeUnique (CHI-E also has write-zero forms)HN-F, no data read
Dirty evictionWriteBackWriteBackFull / WriteBackPtl, WriteEvictFullHN-F (may allocate in SLC)
Clean evictionEvict (optional)Evict, or silentsnoop filter update only
Non-cacheable / Device accessReadNoSnoop / WriteNoSnoopReadNoSnp / WriteNoSnpHN-I (Device) or HN-F (Normal NC)

In CHI, Device-nGnRE and nGnRnE map onto the EWA (early write acknowledge) and ordering attributes of WriteNoSnp. An HN-I may return Comp for an EWA = 1 write before the endpoint has it. This is the transaction-level reason why a DSB after a Device-nGnRE store does not prove that the peripheral received the store (7.9).

Exclusives and atomics

  • LDXR/STXR on cacheable shareable memory are normally resolved in the core’s cache. STXR succeeds if the line is still held Unique and the local monitor is set. If the line is only Shared, the core sends a CleanUnique with the CHI Excl attribute, and the home tells it whether it kept the line or lost it to another requester. A snoop that invalidates the line clears the local monitor. The coherence protocol acts as the “global monitor” for this memory (10.1).
  • Exclusives on Non-cacheable or Device memory become ReadNoSnp/WriteNoSnp with Excl = 1. They work only if some node (HN-I, HN-F or SN) implements an exclusive monitor for that range. That is why the architecture leaves the behaviour IMPLEMENTATION DEFINED.
  • LSE atomics (10.2) are executed either near, in the core’s L1 after obtaining the line Unique, or far, sent as CHI AtomicStore, AtomicLoad, AtomicSwap or AtomicCompare to the home node, which performs the operation in its SLC or at memory. The choice is IMPLEMENTATION DEFINED. Some cores make it depend on contention or expose a control in an IMPLEMENTATION DEFINED register. Far atomics avoid moving a contended line back and forth between cores. They require that every node on the path supports atomics, which is a frequent pre-silicon gap.

Cache maintenance operations

InstructionTypical transactionEffect at the home
DC CVACCleanSharedWrite any dirty copy back to (at least) the PoC; copies may remain
DC CIVACCleanInvalidWrite back dirty data, invalidate all cached copies
DC IVACMakeInvalid (or CleanInvalid when the core or EL2 upgrades it)Invalidate everywhere; dirty data may be discarded
DC CVAP (FEAT_DPB)CleanSharedPersistClean to the Point of Persistence
DC CVADP (FEAT_DPB2)a CleanSharedPersist-family request marked for deep persistence (protocol-revision dependent; check IHI0050)Clean to the Point of Deep Persistence
DC CVAUoften nothing on the interconnectThe PoU is usually inside the core or cluster

A by-VA CMO is broadcast across the shareability domain by the home, not by the issuing core. The core does its own local part (writing back a dirty line from its own caches) and sends the CMO request to the line’s home. The home snoops the other holders and forwards the operation downstream if it has to. A CMO is complete when the home returns Comp, and DSB waits for that. Set/way operations generate no interconnect CMO. They are local operations that may cause ordinary writebacks (8.5).

TLBI and IC broadcast: DVM

TLB and instruction-cache invalidations that must reach other PEs travel as Distributed Virtual Memory (DVM) messages:

    str   x1, [x0]            // descriptor update: an ordinary coherent write
    dsb   ishst               // wait for its Comp: the write is visible to walkers
    tlbi  vae1is, x2          // DVMOp (CHI: request to MN; MN sends SnpDVMOp to every RN-F
                              //        in the DVM domain, including SMMU TCUs on the mesh)
    dsb   ish                 // DVM Sync: completes only when every recipient has
                              //           finished all earlier DVMOps from this requester
    isb

IC IVAU and IC IALLUIS use the same mechanism. DVM Sync is the transaction form of the rule that a TLBI is not complete until a later DSB completes (7.6, 9.1). Its cost grows with the number of recipients and with the slowest one. A recipient that never responds (a powered-down cluster still listed in the DVM domain, or an SMMU with a stuck TCU) hangs the issuing PE in the DSB. This is one of the commonest multi-cluster bring-up hangs.

DMB and DSB themselves are not transactions on CHI. A barrier is a requester-side rule about when it may issue later requests and when it may retire, based on the responses it holds. ACE defined barrier transactions. Later AMBA revisions deprecated them, and CHI has none.

Across chiplets: CHI C2C, CML and CXL

When a coherent domain spans dies, addresses homed on the other die are reached through a gateway (CMN’s CCG, using CCIX/CXL-based links, or a link defined by the AMBA CHI chip-to-chip specification). The protocol is still CHI-like at both ends. Four things change:

  1. Latency. A remote-homed miss crosses the link twice, and a snoop of a remote cache adds more round trips. Expect remote accesses to cost several times the on-die latency. The exact figure depends on the implementation.
  2. Snoop filtering per die. Each die’s home tracks remote caching coarsely. Sharing patterns that are cheap on one die (such as a contended lock) can be pathological when the line’s home is remote. Place hot synchronisation data deliberately (7.10, 17.5).
  3. DVM and barriers. A DVM Sync must be acknowledged by every PE and SMMU on every die. TLBI+DSB and IC IALLUIS + DSB cost much more, and a cross-die TLB shootdown is a different performance class from an on-die one.
  4. Architectural ordering does not weaken. The model of Part 7 still holds: the interconnect must give the same guarantees, at a higher cost. Two things do get looser: what early acknowledgement means for Device writes (a gateway may acknowledge), and where the effective PoC lies when each die has its own SLC.

CXL, for completeness: CXL.mem memory (HDM) is homed by the host and is coherent with CPU caches like local DRAM. CXL.cache lets a device cache host memory as a snooped peer. CXL.io is PCIe, and DMA over it follows the IO-coherent or non-coherent rules of 8.2.

What firmware must configure

None of the following is done by the architecture. It is SoC firmware (often SCP/MCP firmware, sometimes BL1/BL2) and it must complete before the first coherent access (17.5):

  • Address map. CMN discovery, then the RN SAM in each requester, which hashes addresses across HN-Fs and routes IO ranges to HN-Is. Then each HN-F’s SAM to SN-Fs, and for chiplets the remote ranges behind each CCG. A wrong SAM sends requests to a non-existent node, and the requester hangs or takes an SError.
  • Home-node features. SLC and snoop-filter enable and power state, and exclusive-monitor and atomic support on HN-I/SN where needed.
  • Coherency and DVM domain entry. With CCI-400/500 ACE systems, enable snoop and DVM requests per slave interface (TF-A cci_enable_snoop_dvm_reqs()). On CCN, use TF-A ccn_enter_snoop_dvm_domain(). With CHI, the requester and interconnect perform a SYSCOREQ/SYSCOACK handshake. The core side is covered in 8.8 and 17.4.
  • IO coherency. RN-I/RN-D settings and SMMU attribute overrides, so that DMA that is meant to be coherent actually emits snoopable transactions.
  • Partitioning and QoS. MPAM controls in the MSCs (8.9).

Validation note: to confirm that an instruction produced the transaction you expect, count it on both sides. On the PE, BUS_ACCESS and the L2/L3 refill and writeback events should move for coherent misses and evictions. On the CMN PMU (Linux arm-cmn driver, or the CMN debug-trace controller pre-silicon), count HN-F requests and snoops for CMOs, and DVM-node events (arm-cmn dn_rxreq_dvmop, dn_rxreq_dvmsync) for TLBI and IC broadcast. Two failures look different. A DC CVAC that produces no HN-F activity on a line that is known to be dirty means the CMO was dropped. A DSB that never retires after a TLBI, with an MN DVM Sync outstanding, means one recipient is not responding: identify it from the MN’s per-target state or by removing agents from the DVM domain one at a time.

Checkpoint

Q8.3.1 After a cluster is powered off without leaving the DVM domain, another cluster executes TLBI VMALLE1IS; DSB ISH; ISB, and that core hangs. At transaction level, which step is waiting?

  • A. The TLBI, because DVMOp requests are blocking
  • B. The ISB that follows, because it waits for the instruction stream to refill
  • C. The DSB’s DVM Sync, which cannot complete until every member of the DVM domain, including the powered-off one, responds
  • D. A snoop-filter back-invalidation triggered by the TLBI
Answer

C. DVMOps can be issued and buffered, and completion is collected by the DVM Sync that the DSB generates. A domain member that cannot respond stalls it forever. A is the tempting option, because the TLBI is where the cause lies, but the stall shows up at the DSB. The fix is to leave the DVM domain before power-off (8.8).

Read more: Arm ARM (DDI0487), completion of TLB maintenance instructions; AMBA CHI specification (IHI0050), DVM operations

Q8.3.2 A heavily contended counter is updated with LDADD on a 4-die system. Profiling shows the counter’s line rarely moving between core caches, yet throughput is limited by link bandwidth to one die. What is the most likely explanation?

  • A. The implementation executes the atomics far, at the line’s home node on the remote die, so every update is a link round trip, but the line is not moved between cores
  • B. LDADD is implemented as LDXR/STXR loops on this core, which moves the line every time
  • C. The counter is in Device memory, which forces every access to the HN-I
  • D. The snoop filter is full
Answer

A. Far atomics (CHI AtomicLoad and friends) are performed at the home, so cores do not move the line between their caches. When the home is on another die, every update crosses the link. Placing the counter’s home locally, or sharding the counter, helps. B would show the line moving between cores, which contradicts the observation.

Read more: Arm ARM (DDI0487), FEAT_LSE atomic instructions; AMBA CHI specification (IHI0050), atomic transactions

Q8.3.3 Why can firmware not rely on DMB or DSB to appear as a transaction it can trace on a CHI interconnect?

  • A. Barriers are transported but filtered out by the CMN debug trace controller
  • B. On CHI, barriers are a requester-side rule about issuing and retiring based on the responses it has received, and no barrier transaction exists
  • C. Barriers are only sent when the domain is SY
  • D. Barriers become DVM Sync messages, which are not traceable
Answer

B. CHI has no barrier transaction. A DSB waits for Comp responses (and for DVM Sync completion if DVMOps are outstanding), and a DMB constrains issue order. D is the tempting option, but only a DSB that follows outstanding DVMOps generates a DVM Sync, and that message is about TLBI/IC completion, not a general barrier.

Read more: AMBA CHI specification (IHI0050), ordering and DVM Sync; Arm ARM (DDI0487), DSB

8.4 Points of coherency and beyond

Every by-VA and by-PA cache maintenance operation names a point: the place in the memory system that the operation must push data to, or invalidate stale copies down to. The architecture defines each point by the set of observers that are guaranteed to agree once data has reached it, not by a physical location. The same SoC can therefore have its PoC in DRAM for one design and at a system cache for another. Software only needs to know which observers it must satisfy.

The points

Point of Unification (PoU)

  • PoU for a PE: the point by which that PE’s instruction cache, data cache and translation table walks are guaranteed to see the same copy of a location. Data written by stores and then fetched as instructions must reach this point. (Cacheable translation table walks are coherent with the data caches without maintenance. Walks made with Non-cacheable attributes read from the PoC instead (8.2).) CLIDR_EL1.LoUU gives the number of levels before it.
  • PoU for the Inner Shareable domain: the point by which the instruction caches, data caches and translation table walks of all PEs in the Inner Shareable domain see the same copy. CLIDR_EL1.LoUIS gives the levels before it.

DC CVAU and IC IVAU target the PoU. Because data caches in the Inner Shareable domain are coherent, a DC CVAU affects the line in whichever cache of that domain holds it. IC IVAU is broadcast to all instruction caches in the domain. The invalidate-all forms are IC IALLU (local: this PE’s instruction caches, to its PoU) and IC IALLUIS (all PEs in the Inner Shareable domain).

Point of Coherency (PoC)

The point by which all agents that can access memory (all PEs, DMA masters, anything else that reads or writes memory) are guaranteed to see the same copy. In practice this is usually DRAM, or a memory-side system cache that every agent goes through (8.2). CLIDR_EL1.LoC gives the number of levels before it. DC CVAC, DC CIVAC and DC IVAC target the PoC.

The definition has an important corollary: the PoC is only as good as the system designer’s list of “agents that can access memory”. An agent that bypasses the path the designer had in mind is outside the guarantee.

Point of Persistence (PoP) and Point of Deep Persistence (PoDP)

  • PoP, introduced with FEAT_DPB (DC CVAP, OPTIONAL from v8.1, mandatory from v8.2): a point at or beyond the PoC where a write is preserved across loss of system power and reliably recovered when power returns. It exists only if the system has persistent memory (NVDIMM, battery-backed or flush-on-fail DRAM).
  • PoDP, introduced with FEAT_DPB2 (DC CVADP, OPTIONAL from v8.1, mandatory from v8.5; FEAT_DPB2 also redefines the PoP, which changes the scope of DC CVAP): a stronger persistence point, intended for data that must survive failure modes the PoP itself does not cover (for example a failure of the flush-on-fail energy reserve). Its exact guarantee is system-defined. Check the platform documentation before relying on any difference between the PoP and the PoDP.

If the system has no persistence point, DC CVAP behaves as DC CVAC. Software can use it unconditionally where FEAT_DPB is implemented.

Point of Physical Aliasing (PoPA): FEAT_RME

With RME the same physical address exists in up to four PA spaces (Secure, Non-secure, Realm, Root). Before the PoPA, caches treat {PAS, PA} as the address, so a Non-secure line and a Realm line with the same PA are different locations. The PoPA is the point at which accesses to the same PA from different PA spaces refer to the same storage. When firmware moves a granule between PA spaces (12.4), it must make sure no cached copy tagged with the old PAS can later be written back over data written in the new one. DC CIPAPA (clean and invalidate by PA to PoPA, EL3 only) does this. Its operand carries the PA and, in Xt.NS/Xt.NSE, the PA space whose copies are to be pushed past the PoPA. It is not subject to translation or granule protection checks, it affects all caches in the Outer Shareable domain, and it acts on all copies irrespective of MECID. DC CIGDPAPA also covers MTE allocation tags. These operations are by PA because the granule may no longer be mapped by any VA the caller can use, and because the caller must name a PA space other than its own.

Point of Encryption (PoE): FEAT_MEC

With Memory Encryption Contexts (12.5), cache entries before the PoE hold plaintext tagged with a MECID. The memory is encrypted at or beyond the PoE. When a MECID’s key changes or a granule is reassigned to a different encryption context, the old-context copies must be pushed through the PoE or removed. That is what DC CIPAE (and the tag variant DC CIGDPAE) do, by PA, irrespective of MECID.

Point of Physical Storage (PoPS): FEAT_PoPS

FEAT_PoPS is part of the 2024 extensions (OPTIONAL from v9.5, identified by ID_AA64MMFR4_EL1.PoPS). It defines the Point of Physical Storage and adds DC CIVAPS, a clean and invalidate by VA to the PoPS, with a tag-and-data form DC CIGDVAPS when MTE is implemented. HCR_EL2.TPCP traps them along with the PoC and PoP operations. Informally, the PoPS is where the data is held by the physical storage itself, which can be further out than a memory-side cache that the PoC definition still allows. It is for cases where “every agent sees the same copy” (the PoC) is not enough, because what matters is that the storage behind the address holds the data. Like the PoPA/PoE operations, DC CIVAPS acts on all copies irrespective of MECID. This is new and few documents cover it. Take the normative definition from the current DDI0487 (“Terminology for Clean, Invalidate, and Clean and Invalidate instructions”) rather than from this summary. FEAT_OCCMO (OPTIONAL from v9.3, mandatory from v9.6) goes the other way. Its outer-cache CMOs (DC CVAOC, DC CIVAOC and MTE GD forms) can go less far than the PoC. They publish data to an outer cache, such as an SLC that the consuming device reads through, without the cost of pushing it to DRAM.

Summary table

PointObservers that agree once data reaches itInstructionsFeature
PoU (PE)this PE’s I-cache, D-cache, walksDC CVAU, IC IVAU, IC IALLUv8.0
PoU (IS)I/D/walks of all PEs in the Inner Shareable domainIC IALLUIS, broadcast IC IVAUv8.0
PoCall agents that can access memoryDC CVAC, DC CIVAC, DC IVACv8.0
PoPPoC observers, and survives power lossDC CVAPFEAT_DPB (v8.1 optional, v8.2 mandatory)
PoDPas PoP, with the stronger persistence guaranteeDC CVADPFEAT_DPB2 (v8.1 optional, v8.5 mandatory)
PoPAall PA spacesDC CIPAPA, DC CIGDPAPAFEAT_RME
PoEall encryption contexts (MECIDs)DC CIPAE, DC CIGDPAEFEAT_MEC
PoPSthe physical storage itselfDC CIVAPS, DC CIGDVAPSFEAT_PoPS (v9.5 optional)

PoU ≤ PoC ≤ PoP ≤ PoDP is architectural. Where the PoPA and the PoE sit relative to the PoC is constrained by DDI0487 and DEN0129, but in typical systems both are on the memory side, next to the memory controller’s PAS filtering and encryption, at or beyond the PoC. Do not assume that a clean to PoC also reaches the PoPA or the PoE. Use the dedicated operations.

Shareability vs points: “who must see it” vs “where it must reach”

These two concepts are easily confused because both describe a set of observers. They answer different questions.

Shareability domain (6.4)Point (this section)
Question answeredWho must observe my accesses in order, and which agents does hardware keep coherent?Where must data be pushed (or stale copies removed) so that a given set of observers agrees?
Expressed bySH bits of the mapping; barrier domain (DMB ISH, DSB OSH); ...IS/...OS TLBI formsThe CMO name (...VAU, ...VAC, ...VAP, ...PAPA)
MechanismHardware snooping and orderingWriteback and invalidation through cache levels
Needed for coherent observers?Yes: barriers are always needed for orderingNo: coherent observers see the data without a CMO
Needed for non-coherent observers?Not sufficient on its ownYes: the CMO is what makes data reach them

A DSB OSH waits until earlier accesses are complete for all observers in the Outer Shareable domain. It does not move a dirty line out of a cache. A DC CVAC moves the line to the PoC, but other observers are only guaranteed to see it after a DSB, because the CMO is complete only then (7.6). Correct code for a non-coherent observer always needs both: the CMO picks where, and the barrier waits until it has got there before the observer is told to look.

Worked example 1: DMA from a non-coherent master

The CPU fills a buffer in Normal Write-Back memory. A non-coherent DMA engine will read it from DRAM.

    // x0 = buffer start, x1 = end, x2 = line size from CTR_EL0.DminLine
1:  dc    cvac, x0            // where: PoC, which this master is guaranteed to read from
    add   x0, x0, x2
    cmp   x0, x1
    b.lo  1b
    dsb   osh                 // when: wait for the cleans to complete. Device memory and
                              // the master are in the Outer Shareable domain (6.4)
    str   w3, [x4]            // doorbell (Device memory): start the DMA

A DMB OSH before the doorbell is not enough here. It would order the doorbell after the CMOs in the ordering model, but the CMOs are only guaranteed complete, and their effects visible to a non-PE observer, after a DSB. Use DSB. The full to-device and from-device sequences, including buffer alignment to CTR_EL0.CWG, are in 8.7.

Worked example 2: code written as data, then executed

A loader copies code into memory. Instruction fetch on this PE, and on other PEs, must see it.

    dc    cvau, x0            // where: PoU, so the I-side can find the new data
    dsb   ish                 // the clean is complete for all Inner Shareable observers
    ic    ivau, x0            // remove stale instructions (broadcast in the IS domain)
    dsb   ish                 // the invalidation is complete
    isb                       // this PE refetches; other PEs need their own ISB (8.6)

PoU, not PoC, is the right target. The observer is instruction fetch, and the PoU is defined as the point where it agrees with the D-side. Cleaning to PoC also works, but it is slower and has no extra benefit. CTR_EL0.IDC/DIC may let you omit steps (8.6).

Bring-up note: pre-silicon models often blur these points. An FVP run without cache modelling has no caches at all, so every point coincides with memory, and a missing DC CVAC before DMA can never fail. An emulator with a stubbed interconnect may make every master coherent. A test that passes there proves only that the sequence has no ordering bugs. Rerun cache-sensitive tests with FVP cache modelling enabled, as in 8.10, and on the first silicon, before treating them as proven.

Checkpoint

Q8.4.1 A driver for a non-coherent master cleans its buffer with DC CVAC in a loop, then executes DMB OSH, then writes the doorbell. Occasionally the master reads stale data. Why?

  • A. DC CVAC only reaches the PoU, so DC CIVAC is needed
  • B. The barrier domain is wrong: DMB ISH is needed because the buffer is Inner Shareable
  • C. The doorbell should be written with STLR
  • D. A DMB does not wait for the cleans to complete. A DSB is needed before the doorbell so that the data has reached the PoC before the master is told to read it
Answer

D. A CMO’s effect is only guaranteed visible to other observers once it has completed, and only DSB waits for completion. B is the tempting option, but the domain must cover the master, which is in the Outer Shareable domain, and ISH is narrower. Even with the right domain, a DMB is the wrong barrier type. A is wrong: DC CVAC targets the PoC.

Read more: Arm ARM (DDI0487), ordering and completion of data and instruction cache instructions; DSB

Q8.4.2 EL3 firmware transitions a granule from the Non-secure PA space to the Realm PA space. Why does it use DC CIPAPA rather than DC CIVAC?

  • A. DC CIVAC would only affect the local PE
  • B. The cached copies to remove are tagged with the old PA space. An operation by PA to the PoPA can name that PA space explicitly and needs no mapping through which to reach it
  • C. DC CIVAC is UNDEFINED at EL3
  • D. DC CIPAPA is faster because it does not write back dirty data
Answer

B. Before the PoPA, {PAS, PA} pairs are distinct locations. A VA-based CMO acts on the location that the VA translates to, in the PA space of that translation. DC CIPAPA takes the PA and names the old PA space explicitly in Xt.NS/Xt.NSE. It is not subject to translation or granule protection checks, and it pushes those copies to the point where the spaces alias. D is wrong: it is a clean and invalidate. A is wrong because DC CIVAC is broadcast, but that does not fix the PAS problem.

Read more: Arm ARM (DDI0487), DC CIPAPA; RME system architecture (DEN0129), cache maintenance

Q8.4.3 Which statement about shareability domains and points of coherency is correct?

  • A. Marking a buffer Outer Shareable makes it coherent with a non-coherent DMA master, so no CMO is needed
  • B. DSB SY after a store is equivalent to DC CVAC followed by DSB SY for a non-coherent observer
  • C. Shareability and barrier domains say which observers must see accesses in order. A point says where data must be pushed for observers that hardware does not keep coherent
  • D. The PoC is always the Outer Shareable boundary
Answer

C. They are independent axes. A is the tempting option: shareability defines which agents hardware promises coherence with, and an agent that does not snoop is not covered by it. B is wrong because a barrier never moves data out of a cache. D confuses an ordering domain with a physical point that is defined by observers.

Read more: Arm ARM (DDI0487), shareability domains; Point of Coherency and Point of Unification definitions

8.5 Data cache maintenance

Data cache maintenance instructions are SYS instructions, written DC <op>, Xt. They fall into three groups: by VA (the everyday ones, broadcast, defined against a point from 8.4), by set/way (local, for power management and initialisation only), and DC ZVA and its MTE relatives, which write memory rather than maintain caches. The instruction-side and DMA sequences built from these are in 8.6 and 8.7. By-PA operations to PoPA/PoE are covered in 8.4 and 12.4.

The by-VA operations

InstructionOperationPointEL0 (when enabled)FeatureEL2 trap
DC IVACInvalidatePoCneverv8.0HCR_EL2.TPCP
DC CVACCleanPoCSCTLR_EL1.UCIv8.0HCR_EL2.TPCP
DC CIVACClean and invalidatePoCSCTLR_EL1.UCIv8.0HCR_EL2.TPCP
DC CVAUCleanPoUSCTLR_EL1.UCIv8.0HCR_EL2.TPU
DC CVAPCleanPoPSCTLR_EL1.UCIFEAT_DPB (mandatory v8.2)HCR_EL2.TPCP
DC CVADPCleanPoDPSCTLR_EL1.UCIFEAT_DPB2 (mandatory v8.5)HCR_EL2.TPCP
DC ZVAZero a block(a store)SCTLR_EL1.DZEv8.0HCR_EL2.TDZ

(HCR_EL2.TPCP was called TPC before FEAT_DPB extended it to cover the PoP. FEAT_FGT adds per-instruction traps in HFGITR_EL2.)

Semantics common to all by-VA operations:

  • Whole line. The operation acts on the line containing the address. There is no alignment requirement, and loops step by CTR_EL0.DminLine (8.1).
  • Broadcast. The operation affects every cache, up to the named point, that can hold the location for the shareability domain of the VA’s mapping. For normal Inner Shareable memory that means other PEs’ caches too. No IPI is needed.
  • Translated and checked. The VA is translated by the current regime and can take a translation or access-flag fault, reported as a Data Abort with ESR_ELx.ISS.CM = 1 (5.8). DC IVAC is permission-checked as a write, because it can destroy data. The clean operations are generally permitted on read-only mappings. See the per-instruction pages in DDI0487 for the exact permission and EL0 rules.
  • Attribute-independent. The operation acts on cached copies of the PA regardless of the cacheability of the mapping used to name it. This is what lets software clean the cacheable alias of a buffer through a Non-cacheable mapping (6.6). With the MMU off, the VA is the PA and the operations still work.
  • Ordering and completion. A by-VA DC operation is ordered after earlier loads and stores by the same PE to the same cache line without a barrier, when those accesses are to Normal Write-Back memory. For accesses through Device or Non-cacheable mappings, a DMB is needed between them. Linux’s dcache_clean_poc loop starts with no barrier for this reason. Relative to accesses to other addresses, a DMB orders it. It is only guaranteed to have taken effect for other observers once a later DSB has completed, so every sequence that hands data to an observer ends with a DSB of the right domain (7.6).
// Clean [x0, x1) to PoC. Clobbers x2, x3. (Same shape as TF-A's flush_dcache_range.)
clean_dcache_range_poc:
    mrs   x3, ctr_el0
    ubfx  x3, x3, #16, #4
    mov   x2, #4
    lsl   x2, x2, x3              // line size
    sub   x3, x2, #1
    bic   x0, x0, x3              // align down
1:  dc    cvac, x0
    add   x0, x0, x2
    cmp   x0, x1
    b.lo  1b
    dsb   sy                      // completion; use the narrowest domain covering the observer
    ret

DC IVAC is the dangerous one

Invalidate discards a dirty line. Any data in the same line that the CPU wrote and has not yet cleaned is lost, including data outside the buffer you meant to invalidate. Three consequences follow:

  1. EL0 can never use it. Otherwise it would be a way to roll memory back to an older value that EL0 could not otherwise write.
  2. With EL2 enabled and HCR_EL2.VM == 1, DC IVAC executed at EL1 is performed as DC CIVAC. A guest cannot use it to discard data it does not own at the physical level. Some implementations always perform an invalidate as clean+invalidate, which is permitted.
  3. It is only safe on whole lines that are owned exclusively by the device side. This is the “invalidate before read” problem worked through in 8.7. Most code should use DC CIVAC.

DC CVAP and DC CVADP

These give persistence. Use them after writing a persistent-memory region and before a DSB that tells software the record is durable. If the system has no PoP, DC CVAP behaves as DC CVAC. If it has no PoDP, DC CVADP behaves as DC CVAP. Software can therefore use the strongest operation it needs wherever the feature is implemented.

DC ZVA and DCZID_EL0

DC ZVA writes zeros to an aligned block of memory. The block size is reported in DCZID_EL0:

DCZID_EL0 fieldBitsMeaning
BS[3:0]log2(words) of the block size: 4 means 64 bytes. The architectural maximum is 2 KB
DZP[4]1 = DC ZVA (and DC GVA/DC GZVA) prohibited at this EL. The value reflects SCTLR_EL1.DZE at EL0 and HCR_EL2.TDZ

Properties:

  • The address is aligned down to the block size, so DC ZVA on an unaligned pointer zeroes bytes before it. memset implementations use it only for the aligned middle of a range.
  • It behaves as a set of stores for permissions, watchpoints, ordering and coherency. It is not a cache maintenance operation and does not need any CMO.
  • It is permitted to avoid reading the line from memory (CHI MakeUnique or a write-zero transaction, 8.3). That is why it is fast.
  • On Device memory it generates an Alignment fault. With the MMU or D-cache off, data accesses are Device-nGnRnE, so an optimised memset that uses DC ZVA faults in early boot code. This is one reason bare-metal firmware must not link a generic libc memset before the MMU is on (6.5).
  • BS can differ between core types. Read DCZID_EL0 per use, or take the system-wide value as Linux does.

The MTE tag variants (brief)

With FEAT_MTE2 the allocation tags have their own storage and may be cached separately (13.4). The DC family therefore gains tag-only (G) and tag-and-data (GD) forms:

Data-onlyTags onlyTags and data
DC ZVADC GVA (set tags of a block)DC GZVA (zero data and set tags)
DC CVACDC CGVACDC CGDVAC
DC CIVACDC CIGVACDC CIGDVAC
DC IVACDC IGVACDC IGDVAC
DC CVAP / DC CVADPDC CGVAP / DC CGVADPDC CGDVAP / DC CGDVADP
DC ISW / CSW / CISWDC IGSW / CGSW / CIGSWDC IGDSW / CGDSW / CIGDSW

The rule for a DMA or power-down sequence on tagged memory is simple: if tags must survive or be seen by another agent, use the GD form wherever you would have used the data form.

Set/way operations, and why they are unsafe for coherency

DC ISW, DC CSW and DC CISW name a cache line by level, set and way rather than by address. The operand is built from CCSIDR_EL1 (8.1): Level in [3:1], the set index shifted left by log2(line length in bytes), and the way index in the top bits of the low 32 bits, shifted left by 32 − ⌈log2(ways)⌉.

// Clean+invalidate one cache level by set/way. x0 = level << 1 (CSSELR format).
    msr   csselr_el1, x0
    isb
    mrs   x1, ccsidr_el1              // assumes no FEAT_CCIDX; check ID_AA64MMFR2_EL1.CCIDX
    and   x2, x1, #7
    add   x2, x2, #4                  // x2 = log2(line bytes) = set shift
    ubfx  x3, x1, #3, #10             // x3 = ways - 1
    clz   w4, w3                      // w4 = way shift = 32 - ceil(log2(ways))
    ubfx  x5, x1, #13, #15            // x5 = sets - 1
1:  mov   x6, x3                      // way loop counter
2:  lsl   w7, w6, w4
    orr   w7, w0, w7                  // level | way
    lsl   w8, w5, w2
    orr   w7, w7, w8                  // | set
    dc    cisw, x7
    subs  x6, x6, #1
    b.ge  2b
    subs  x5, x5, #1
    b.ge  1b
    dsb   sy

(For a direct-mapped cache clz returns 32, which is harmless here because the way index is always 0. TF-A’s dcsw_op_all/dcsw_op_level* are the production versions and iterate the levels from 1 to LoC or LoUIS.)

Set/way operations are architecturally restricted to cache initialisation and power-down of the local hierarchy. Using them for coherency, for example “clean the whole cache before DMA”, is wrong for structural reasons:

  1. Local only. They act on the caches of the executing PE’s own hierarchy and are not broadcast. A dirty copy in another PE’s L1, or in a cluster cache the walk does not cover, is untouched.
  2. Not atomic with respect to allocation. While the loop runs, lines keep arriving through speculation, prefetch and coherent fills from other PEs. With exclusive or NINE caches (8.2), a line can also move from a level not yet processed to one already processed. The loop’s final state guarantees nothing about any given address.
  3. No defined relation to a point. They operate on the levels you choose to walk. A system cache beyond the levels reported by CLIDR_EL1 is not covered, and you only reach a point if your loop bounds match LoC/LoUU/LoUIS.
  4. Invisible to virtualization. A guest’s set/way operations act on whatever physical lines happen to sit at that set and way, which is meaningless to the guest. Hypervisors trap them with HCR_EL2.TSW (and, with HCR_EL2.VM == 1 or HCR_EL2.SWIO == 1, DC ISW at EL1 is performed as DC CISW). KVM emulates them with by-VA cleaning of the guest’s memory.

The power-down use is safe because the preconditions remove problems 1 and 2. The local caches are no longer allocating (the C bit is cleared, or the core has left coherency so that no snoops refill it), and other PEs no longer hold coherent copies that matter. The exact order is in 8.8. DC ISW at reset is only needed on cores that do not invalidate their caches in hardware. Most current cores do, which is IMPLEMENTATION DEFINED (9.3).

Security note: DC IVAC at EL1 on a buffer shared with a more privileged world is a rollback primitive against any write from that world that is still cached. This is why EL0 can never use it, why EL2 upgrades it, and why secure firmware that shares memory with Non-secure software must not rely on the Non-secure side’s maintenance for integrity. RME closes the cross-PAS variant with the PoPA rules (8.4).

Validation note: each by-VA CMO has a PMU fingerprint. Make a line dirty, then execute DC CVAC. L1D_CACHE_WB (and the L2/L3 writeback events if the line was there) should increment by one, and a following load should hit, because the line is clean but still present. After DC CIVAC the following load should refill (L1D_CACHE_REFILL). A CMO that leaves the counters unchanged on a known-dirty line is a finding: the dirty data never left. If the load after a DC CVAC refills, that is not an architectural violation, because a line may be evicted at any time. It does mean the implementation invalidates on clean, which matters for performance and should match the TRM. For DC ZVA, sweep DCZID_EL0.BS alignment edges and check that exactly one block is zeroed, and that Device mappings fault.

Checkpoint

Q8.5.1 Before handing a buffer to a non-coherent DMA engine on a 4-core cluster, firmware runs a DC CISW loop over all levels up to LoC on core 0. Another core wrote half of the buffer a moment earlier. What is the problem?

  • A. Set/way operations are local and not atomic with respect to allocation, so dirty lines in other cores’ caches (and lines refilled during the loop) are not guaranteed to reach the PoC
  • B. None, provided the loop runs to LoC
  • C. DC CISW is UNDEFINED at EL3
  • D. None, provided a DSB SY follows the loop
Answer

A. Set/way acts on the executing PE’s hierarchy only and gives no per-address guarantee. A by-VA DC CVAC loop, which is broadcast and address-precise, followed by a DSB, is the correct sequence. B and D are tempting because the loop does cover every level up to the PoC on this core. The barrier only waits for the operations that were issued, and none of them touched the other cores’ caches.

Read more: Arm ARM (DDI0487), data cache maintenance by set/way; the restrictions on set/way operations

Q8.5.2 Early BL2 code, running with SCTLR_EL3.M = 0, calls an optimised memset and takes an Alignment fault on a DC ZVA with a 64-byte-aligned address. Why?

  • A. DCZID_EL0.DZP is always 1 at EL3
  • B. DC ZVA needs the address aligned to the cache size, not the block size
  • C. With the MMU off, data accesses are treated as Device-nGnRnE, and DC ZVA to Device memory generates an Alignment fault regardless of address alignment
  • D. DC ZVA requires FEAT_MTE
Answer

C. The fault comes from the memory type, not the address. B is the tempting option because the fault is an “alignment” fault, but the address is suitably aligned. The fix is a plain-store memset until the MMU and caches are on, or building with -mstrict-align and not using DC ZVA early.

Read more: Arm ARM (DDI0487), DC ZVA; behaviour of data accesses when stage 1 translation is disabled

Q8.5.3 A guest kernel at EL1 executes DC IVAC on a buffer while HCR_EL2.VM = 1. What does the architecture require?

  • A. The invalidate is performed as written, so dirty data is discarded
  • B. The operation is performed as a clean and invalidate (DC CIVAC), so dirty data is written back, not discarded
  • C. It always traps to EL2
  • D. It is UNDEFINED at EL1 when stage 2 is enabled
Answer

B. With stage 2 enabled, an EL1 invalidate by VA is upgraded to clean and invalidate. Otherwise a guest could discard data at the physical level, including data belonging to lines it shares with other owners. C is tempting, but trapping is separately controlled by HCR_EL2.TPCP and is not implied by VM.

Read more: Arm ARM (DDI0487), DC IVAC; effects of HCR_EL2.VM on data cache invalidate instructions

8.6 Instruction cache maintenance and cross-modifying code

Data stores and instruction fetches are not coherent with each other by default. A store goes into the data side of the hierarchy (store buffer, L1D, possibly further out). Instruction fetch reads from the L1I, which may hold a stale copy, and it may have read from memory at any time since the last context synchronization event on that PE. The Arm ARM states the second point explicitly: the PE may have fetched instructions “at any time since the last Context synchronization event”. To make newly written instructions executable, three things must happen:

  1. The new data must reach a point where instruction fetch can see it. That point is the Point of Unification (PoU) (8.4).
  2. Any stale copy in instruction caches must be removed.
  3. Every PE that will execute the new code must discard instructions it has already fetched. That requires a context synchronization event on that PE (7.8).

The canonical sequence

For a single location, with the code written through a Normal, Inner Shareable, cacheable mapping:

    str     w1, [x0]          // write the new instruction
    dc      cvau, x0          // clean data cache by VA to PoU
    dsb     ish               // wait for the clean to complete
    ic      ivau, x0          // invalidate instruction cache by VA to PoU
    dsb     ish               // wait for the invalidate to complete
    isb                       // discard fetched instructions on this PE

Each step has a reason:

StepWhy
DC CVAUPushes the dirty line from the data cache out to the PoU, where the I-side fetch path meets the D-side. Without it, the I-cache refills from a level that still holds the old bytes.
first DSB ISHIC IVAU is not ordered after DC CVAU by default. If the invalidate runs first, a refetch (including a speculative one) can pull the old bytes back into the L1I before the clean lands.
IC IVAURemoves stale copies from instruction caches. For a location in Inner Shareable memory (normal coherent memory), the by-VA operation is broadcast to the instruction caches of all PEs in the Inner Shareable domain, so one PE can do this for everyone.
second DSB ISHWaits for the invalidate to complete on all PEs it is broadcast to. Before that, a refetch can still hit a stale line.
ISBA context synchronization event. Instructions fetched before it, possibly from the old line, are discarded and refetched. It only affects the PE that executes it.

For a range, loop the DC CVAU over the range in CTR_EL0.DminLine steps, then one DSB ISH, then loop IC IVAU in CTR_EL0.IminLine steps, then DSB ISH; ISB. The line sizes come from CTR_EL0 (8.1). Always read them from the register: big.LITTLE systems have had cores with different I-line sizes, and Linux uses the system-wide minimum for this reason.

IC IALLU (local, to PoU) and IC IALLUIS (Inner Shareable) invalidate all instruction caches without needing a VA. They are the right tool after loading a large image, or when no VA is mapped. The cost is that every hot code path on every PE refetches.

What CTR_EL0.IDC and DIC let you omit

CTR_EL0 advertises two IMPLEMENTATION DEFINED properties:

FieldBitMeaning when 1Omittable step
IDC28Data cache clean to PoU is not required for instruction-to-data coherenceDC CVAU
DIC29Instruction cache invalidation to PoU is not required for data-to-instruction coherenceIC IVAU

The effective value of IDC is also 1 when CLIDR_EL1.LoC == 0, or when both LoUIS and LoUU are 0, because then no data cache lies inside the PoU. If DIC is 1, IDC must also read 1. All PEs in the same Inner Shareable domain must agree on both values.

The reduced sequences are:

// IDC == 1, DIC == 0
    str     w1, [x0]
    dsb     ish               // still needed: the store must be visible
    ic      ivau, x0          //   before the invalidate is performed
    dsb     ish
    isb

// IDC == 1, DIC == 1
    str     w1, [x0]
    dsb     ish               // store complete for all IS observers
    isb                       // local PE refetches; remote PEs need their own

The DSB and the ISB are never optional. DIC says the instruction cache does not need invalidating. It does not say instructions that are already fetched are thrown away. The pipeline still holds them until a context synchronization event.

Bring-up note: Some implementations have errata where CTR_EL0.DIC reads 1 but the I-side can still see stale data. Neoverse N1 erratum 1542419 is the best-known case: Linux traps EL0 reads of CTR_EL0 and reports DIC = 0, so that user space performs the IC IVAU, and the workaround has a firmware counterpart in TF-A. If you rely on DIC in firmware, check the core’s SDEN first (1.3).

Who sees the new code: the cross-PE sequence

The modifying PE’s DC/IC operations are broadcast, so it can clean and invalidate for the whole Inner Shareable domain. It cannot run an ISB on another PE. The architecture therefore requires a split sequence for code that another PE will execute:

// Modifying PE (P0)
    str     w1, [x0]          // new instruction(s)
    dc      cvau, x0
    dsb     ish
    ic      ivau, x0
    dsb     ish               // invalidate complete on all IS PEs
    mov     w3, #1
    str     w3, [x2]          // publish "code ready" flag (STLR is also fine)

// Each executing PE (P1..Pn)
1:  ldr     w3, [x2]          // or LDAR
    cbz     w3, 1b
    isb                       // P1's own context synchronization event
    br      x0                // now guaranteed to execute the new code

The flag store must be ordered after the second DSB. A DSB orders all later instructions, so a plain STR is enough. The executing PE needs no DC or IC of its own, but it does need the ISB after it has observed the flag. Instead of an ISB, any other context synchronization event works: taking an exception (unless SCTLR_ELx.EIS == 0 under FEAT_ExS) or returning from one (unless SCTLR_ELx.EOS == 0 under FEAT_ExS). This is why Linux’s kick_all_cpus_sync() (an IPI to every CPU) is a valid cross-PE synchronisation: the IRQ entry on each CPU is its context synchronization event.

CMODX: modifying code that may be executing right now

The sequence above assumes no PE is executing the location while it changes. Concurrent modification and execution of instructions (CMODX) is the case where P1 may fetch the location while P0 overwrites it, and P1 has done no synchronisation. Live patching, tracepoints and JIT back-patching all work this way.

The architecture gives a guarantee only for a small set of instructions. If both the old and the new instruction are in that set, P1 executes either the old or the new instruction, nothing else. The set is:

  • B, BL (immediate branches)
  • NOP
  • BRK, SVC, HVC, SMC
  • ISB

For conditional branches, concurrent modification is allowed, but the PE may combine the old condition with the new target or the new condition with the old target. Patch the condition and the target as separate steps, or avoid patching conditional branches at all. The current DDI0487 issue words this precisely; read it before you extend the set.

If either the old or the new instruction is outside the set, the behaviour is CONSTRAINED UNPREDICTABLE. It can be any behaviour achievable by executing any sequence of instructions at the same Exception level. That bound is why CMODX is not a privilege-escalation risk, but it is no correctness guarantee at all. A torn fetch of a half-written MOVZ/MOVK pair, for example, is permitted.

The concurrent store must also be single-copy atomic for the instruction: one aligned 32-bit STR. Rewriting an instruction with two 16-bit stores gives P1 a chance to fetch a mixed encoding, even if both endpoints are in the set.

Even within the set, “old or new” holds only until P1 next synchronises. Before that, P1 may keep executing the old instruction indefinitely (it may still be in its L1I or pipeline). The full cache-maintenance sequence is still needed, and P1 must take a context synchronization event, before you can rely on P1 executing the new instruction.

The standard live-patching recipe follows from this:

  1. Overwrite the first instruction of the site with a BRK or a B to a trampoline (both in the CMODX set), then run the maintenance sequence and synchronise all PEs.
  2. Rewrite the rest of the site; no PE can be executing it now.
  3. Replace the first instruction with the final one, again via the set, or synchronise all PEs first.

Linux’s aarch64_insn_patch_text() avoids the problem differently. It uses stop_machine() so that no other CPU is executing kernel text during the write.

Security note: In a CMODX window, an instruction outside the set can execute as anything reachable at the current EL. For EL3 or S-EL1 code patched at runtime (for example a debug hook in BL31), that means arbitrary EL3 behaviour. Don’t patch EL3 text while secondaries run; park them, or only patch through the CMODX set.

FEAT_CMOW: cache maintenance needs write permission

EL0 can execute IC IVAU and DC CIVAC when SCTLR_EL1.UCI == 1, which Linux sets for JITs. Before FEAT_CMOW, read permission was enough. EL0 could invalidate lines of read-only pages it shares with others, such as shared libraries or the vDSO. That gives an attacker a Flush+Reload-style flush primitive on memory it could never write. FEAT_CMOW (mandatory from v8.8) adds two controls:

ControlEffect when 1
SCTLR_EL1.CMOW (bit 32)IC IVAU, DC CIVAC, DC CIGDVAC and DC CIGVAC at EL0, on a location with stage 1 read but not write permission, generate a stage 1 Permission fault.
HCRX_EL2.CMOW (bit 9)The same instructions at EL1 or EL0 on a location without stage 2 write permission generate a stage 2 Permission fault. The effective value is 0 unless SCR_EL3.HXEn == 1.

For stage 1, “write permission” here means AP[2] == 0 or DBM == 1, with APTable[1] == 0 at every level. The bits only affect execution at EL0 or EL1. With HCR_EL2.{E2H,TGE} == {1,1}, SCTLR_EL1.CMOW has no effect.

A JIT that uses W^X with two aliases (writable and executable) must run its IC IVAU on the writable alias once CMOW is set, or it takes a Permission fault. By-VA invalidation acts on the physical line, so either alias is correct for coherence.

JITs, loaders and firmware

  • Loaders (BL2 loading BL31, a bootloader loading an OS). If the image was written with the MMU and caches on, clean it to PoU (to PoC if the next stage starts with caches off; see 8.7 and 9.3), invalidate the I-cache, DSB, then ISB or the exception return into the new image. TF-A’s flush_dcache_range plus the ERET into the next image follows this pattern. An image written by DMA or by a debugger through the external debug interface bypasses the PE’s D-cache, but stale lines in the I-cache still need IC IALLU.
  • JITs. Generate code, run the range sequence once per batch, and publish the entry pointer with release semantics. Every thread that calls into the new code needs a context synchronization event after it observes the pointer. In practice this comes from an ISB in the call stub, or from an exception, such as the mprotect syscall or the first-touch page fault. A thread that already has the old target in flight is a CMODX case.
  • EL0 access controls. SCTLR_EL1.UCT lets EL0 read CTR_EL0. SCTLR_EL1.UCI lets EL0 execute DC CVAU, DC CIVAC, DC CVAC, IC IVAU and related instructions; if it is 0, they trap to EL1.

Validation note: Test with a P0/P1 pair. P0 rewrites a MOV w0, #1; RET stub to MOV w0, #2; RET, runs the full sequence and sets a flag. P1 spins on the flag, then calls the stub with or without the ISB. Without the ISB, an old result after the flag is allowed. If P1 still returns the old value with the ISB, the bug is real: a broken IC broadcast, a wrong DIC, or the maintenance not reaching the PoU. On cores that count them, the PMU events L1I_CACHE_REFILL (0x01) and L1I_TLB_REFILL confirm whether P1 really refetched. FVP’s cache models (with cache state modelling enabled) are needed to see the stale-I-cache failure at all, because QEMU TCG has no instruction cache to go stale (8.10).

Checkpoint

Q8.6.1 A system reports CTR_EL0.IDC == 1 and CTR_EL0.DIC == 1. P0 writes a new function, executes DSB ISH, and stores a pointer to it. P1 loads the pointer with LDAR and branches to it straight away. What is guaranteed?

  • A. P1 executes the new code, because DIC means no instruction cache maintenance is needed
  • B. P1 executes the new code, because LDAR orders the instruction fetch after the load
  • C. Nothing: P1 may execute stale instructions it fetched earlier, because it has had no context synchronization event after observing the pointer
  • D. P1 takes a CONSTRAINED UNPREDICTABLE exception
Answer

C. DIC removes the need for IC IVAU, not for a context synchronization event on each executing PE. Instruction fetch is not a memory read ordered by acquire semantics. P1 may have fetched (or speculatively prefetched) from that address at any time since its last CSE. An ISB on P1 after the LDAR, or an exception entry or return, is required. Option A is the tempting misreading of DIC.

Read more: Arm ARM (DDI0487), Concurrent modification and execution of instructions; CTR_EL0

Q8.6.2 A live-patching tool replaces an ADD x0, x0, #1 with ADD x0, x0, #2 in kernel text, using one aligned 32-bit store while other CPUs may be executing it, followed by the full DC/IC/DSB sequence and an IPI to all CPUs. What does the architecture say about another CPU that fetches the instruction during the window?

  • A. Its behaviour is CONSTRAINED UNPREDICTABLE, because ADD is not in the set of instructions that may be concurrently modified
  • B. It executes either the old or the new ADD, because the store is single-copy atomic
  • C. It always executes the old ADD until its IPI arrives
  • D. It takes an Instruction Abort, because the line is being invalidated
Answer

A. The “old or new” guarantee holds only when both instructions are in the CMODX set (B, BL, NOP, BRK, SVC, HVC, SMC, ISB). Single-copy atomicity of the store (option B) is necessary but not sufficient. The safe approach is to route through the set (for example, patch in a BRK or a branch first) or to stop the other CPUs during the write.

Read more: Arm ARM (DDI0487), Concurrent modification and execution of instructions

Q8.6.3 On a v8.8 system, Linux sets SCTLR_EL1.UCI = 1 and SCTLR_EL1.CMOW = 1. A JIT maps its code buffer twice: RW at VA1 and RX at VA2. After writing code through VA1, it executes IC IVAU on VA2 from EL0. What happens?

  • A. The invalidate works, because IC IVAU needs only read or execute permission
  • B. It traps to EL1 as a system instruction trap, because UCI does not cover IC IVAU
  • C. It completes but has no effect, because an instruction cache invalidate on an alias is ignored
  • D. It generates a stage 1 Permission fault, because VA2 has no write permission and CMOW requires it
Answer

D. With CMOW == 1, IC IVAU (and DC CIVAC and the tag variants) at EL0 on a location that is readable but not writable at stage 1 generates a Permission fault. The JIT should run the maintenance on the RW alias VA1. That is architecturally correct, because by-VA maintenance acts on the physical line. Option B is wrong: UCI is exactly the control that lets EL0 execute IC IVAU.

Read more: Arm ARM (DDI0487), SCTLR_EL1.CMOW; HCRX_EL2.CMOW; FEAT_CMOW

8.7 DMA and non-coherent masters

A DMA master is non-coherent when its accesses do not snoop the PE caches, and the PE caches are not invalidated by its writes. Typical cases are a device on an ACE-Lite or AXI port without I/O coherency, a debug or trace sink, a power-management controller, or a pre-silicon accelerator model that writes DRAM directly. For such a master, the data it needs, or the data it produced, must reach the Point of Coherency (8.4), because the PoC is the only place both sides are guaranteed to see the same copy. Hardware keeps coherent masters coherent, so the sequences here are unnecessary for them (8.2). Doing them anyway is safe but slow.

Shareability does not help on its own. Mapping a buffer Outer Shareable on the PE says which PE-side observers must agree. It does not make a master that does not snoop see the PE’s dirty lines.

To-device: the PE writes, the device reads

// x0 = buffer start, x1 = buffer end; buffer written by the PE through a WB mapping
    mrs     x3, ctr_el0
    ubfx    x3, x3, #16, #4        // DminLine: log2(words)
    mov     x2, #4
    lsl     x2, x2, x3             // line size in bytes
    sub     x3, x2, #1
    bic     x0, x0, x3             // align start down
1:  dc      cvac, x0               // clean to PoC
    add     x0, x0, x2
    cmp     x0, x1
    b.lo    1b
    dsb     sy                     // cleans complete at PoC
    str     w4, [x5]               // doorbell: Device-nGnRE register
  • DC CVAC (clean, not invalidate) is enough. The PE keeps its copy, and the line just becomes clean.
  • The DSB must come before the doorbell. A DMB would order the doorbell store after the clean as seen by PE-side observers. The device, though, reads DRAM, not the PE’s view of the clean. The architecture only guarantees the clean has completed to the PoC after a DSB. Use DSB SY, or DSB OSH if the master is known to be inside the Outer Shareable domain. Linux’s dcache_clean_poc ends in dsb sy.
  • The doorbell is the same pattern as 7.10, with the clean replacing the plain ordering step.

From-device: the device writes, the PE reads

This direction needs maintenance on both sides of the transfer:

Before starting the DMA (buffer ownership -> device):
    DC CIVAC (or DC CVAC) over the buffer   // no dirty line may be evicted later
    DSB SY
    start DMA (doorbell)

After the DMA completes (interrupt or status read, ownership -> PE):
    DC IVAC over the buffer                  // drop lines fetched during the DMA
    DSB SY
    read the buffer

Each half fixes a different failure:

Missing stepFailure
Clean before the DMAA dirty line for the buffer, left from earlier PE use, is evicted during or after the DMA and overwrites the device’s data in DRAM. Corruption is intermittent and line-sized.
Invalidate after the DMAThe PE reads a stale line. It could be one that was never invalidated, or one the PE speculatively or prefetch-allocated during the transfer. A cacheable Normal mapping lets the PE allocate the line at any time (14.2). An invalidate before the DMA alone does not prevent this.

The post-DMA invalidate is not optional even when the pre-DMA step was a clean+invalidate. Without it, nothing stops the line from being refilled while the device writes. Linux’s arm64 DMA layer does this: arch_sync_dma_for_device() cleans the buffer for every direction, and arch_sync_dma_for_cpu() invalidates it for DMA_FROM_DEVICE and DMA_BIDIRECTIONAL.

Why “invalidate before read” can lose data

DC IVAC discards a line, including any dirty data in it. That is correct only if every byte of the line belongs to the device’s buffer and the PE has no unwritten data there. Three common ways it goes wrong:

  1. Partial lines at the buffer edges. If the buffer does not start and end on a cache-line boundary (and, to be safe, a CTR_EL0.CWG boundary, since a writeback may be that large), the first and last lines also hold neighbouring data. Examples are a struct field, a stack slot, or another buffer’s header. Invalidating them discards the PE’s recent writes to that data. The fixes, in order of preference: allocate DMA buffers aligned and padded to CWG; or use DC CIVAC for the partial edge lines. The second is what Linux’s dcache_inval_poc does. It keeps the neighbour’s data but writes the PE’s stale copy of the buffer’s edge bytes back over the device’s data if the device has already written them. So edge lines must not be touched by both sides at once, whatever the instruction.
  2. Invalidate instead of clean before the DMA. Using DC IVAC in the pre-DMA step, to “save the writeback”, loses any PE writes to the buffer that were still dirty. That is harmless only if the PE really never wrote it.
  3. Virtualized guests. A guest’s DC IVAC is not guaranteed to discard data. With EL2 enabled and stage 2 active, the AArch64.DC pseudocode performs an EL1 DC IVAC as a clean and invalidate. This stops a guest from discarding data the hypervisor or another guest wrote to the same PA. A guest driver that relies on the invalidate to drop data is broken under a hypervisor.

DC IVAC is also the only data-cache maintenance by VA whose correct use depends on who owns each byte of the line. That ownership is a software contract, and the hardware cannot check it.

Security note: Invalidating lines you do not own is a data-integrity primitive: it rolls memory back to the DRAM copy. This is why DC IVAC is not available at EL0 and why the stage 2 upgrade exists. For the same reason, Secure firmware sharing a buffer with the Normal world must not DC IVAC across the buffer boundary into Secure data.

The alternative: Non-cacheable buffers

Mapping the DMA buffer Normal Non-cacheable on the PE avoids CMOs but has costs:

  • Every PE access goes to memory. That is fine for descriptors, but slow for bulk data the PE processes.
  • Any other cacheable alias of the same PA, such as a firmware flat map or the Linux linear map, can still allocate lines through speculation. That is a mismatched-attribute alias (6.6). Remove or unmap the cacheable alias, or clean+invalidate after changing the attributes.
  • Ordering still needs barriers. Non-cacheable stores can sit in a write buffer, so a DSB or an ordered doorbell sequence is still required (7.9).

A common split is Non-cacheable for descriptor rings and cacheable plus CMOs for payload buffers.

The SMMU’s coherency attributes

When a master sits behind an SMMUv3 (11.5), the SMMU decides what memory attributes its transactions have downstream. Two separate questions arise.

1. Are the device’s own DMA transactions coherent? With translation enabled, the output attributes come from the translation tables. Stage 1 uses the CD’s MAIR-indexed attributes; stage 2 uses the STE’s stage 2 attributes. The two are combined as for the PE, or the stage 2 attributes override them when STE.S2FWB is set and SMMU_IDR3.FWB reports support. For bypass or stage-1-bypass cases, the STE fields MTCFG/MemAttr, SHCFG and ALLOCCFG override or supply the attributes. A transaction marked Inner/Outer Write-Back Shareable is snooped only if the path from the SMMU to the interconnect is I/O-coherent, for example an ACE-Lite or CHI RN-I port into the home nodes. Marking a device mapping cacheable on a non-coherent path does not make it coherent. The firmware description has to match the hardware: IORT’s memory access properties (CCA) in ACPI, or the dma-coherent property in device tree.

2. Are the SMMU’s own accesses coherent? These are its stream table, CD and translation table walks, and its command, event and PRI queues. SMMU_IDR0.COHACC says whether the SMMU can make coherent accesses at all. If it can, SMMU_CR1 sets the cacheability and shareability of table and queue accesses (TABLE_IC/OC/SH, QUEUE_IC/OC/SH). CD.IR0/OR0/SH0 and STE.S2IR0/S2OR0/S2SH0 set the attributes of stage 1 and stage 2 table walks. If COHACC == 0, or the attributes are set to Non-cacheable, the software that writes STEs, CDs, page tables and commands must clean them to the PoC before telling the SMMU (before CMD_CFGI_STE or the SMMU_CMDQ_PROD update). Without that, the SMMU reads stale configuration, and the bug shows up as wrong translations or C_BAD_STE events that disappear when you add a debug print.

Bring-up note: If a device “works with caches off” or “works after a DC CIVAC of the whole buffer”, check the coherency description before adding CMOs. Find out whether the port is actually I/O-coherent in this SoC configuration, whether the IORT or DT says so, and whether the SMMU’s attributes for that stream are WB-Shareable. A mismatch in either direction is a bug. Declaring coherency the path lacks causes stale data. Declaring non-coherency when the path is coherent costs performance, and the CMOs on cacheable aliases are still correct.

Validation note: A minimal DMA round-trip test fills a buffer with a known pattern on the PE, cleans it, DMAs it to a second buffer, invalidates the second buffer, and compares. Run it under several perturbations: misalign the buffers by 8 to 56 bytes, have a second PE prefetch-read the destination during the transfer, and remove each CMO in turn. Every removal should produce a detectable failure on a cache-modelling FVP or on silicon. A test that still passes with a CMO removed shows the master is coherent, the cache model is off, or the buffer never gets cached, not that the code is right. PMU L1D_CACHE_WB (0x15) and BUS_ACCESS (0x19) show whether the clean caused writebacks. Interconnect counters, such as CMN HN-F snoop events, show whether the device’s reads snooped. See 8.10.

Checkpoint

Q8.7.1 A driver for a non-coherent device does DC IVAC over the receive buffer, then starts the DMA, then reads the buffer when the completion interrupt arrives. Occasionally it reads old data. Which change is necessary and sufficient, assuming the buffer is line-aligned and the PE never writes it?

  • A. Replace the DC IVAC with DC CIVAC before the DMA
  • B. Add a DC IVAC and DSB SY over the buffer after the completion, before reading
  • C. Add a DMB SY between the interrupt acknowledgement and the first load
  • D. Map the buffer Outer Shareable instead of Inner Shareable
Answer

B. While the DMA ran, the PE could speculatively or prefetch-allocate lines of the buffer from DRAM. Those lines hold pre-DMA data, and the pre-DMA invalidate cannot prevent that. An invalidate after completion removes them. Option A guards against dirty lines being evicted onto the DMA data, but the PE never wrote the buffer, so that cannot cause stale reads. Shareability (option D) does not make a master that does not snoop coherent.

Read more: Arm ARM (DDI0487), Data cache maintenance instructions; Speculative accesses to Normal memory

Q8.7.2 A receive buffer starts 16 bytes into a 64-byte cache line. The first 16 bytes are a lock word that another PE is actively using. The driver does DC IVAC on every line of the buffer after the DMA. What can happen?

  • A. Nothing, because DC IVAC affects only the bytes of the buffer
  • B. The DC IVAC is UNDEFINED on a misaligned VA
  • C. The lock word is cleaned to DRAM first, because DC IVAC always cleans dirty data
  • D. A recent update to the lock word that is still dirty in a cache is discarded, so the lock is rolled back to its DRAM value
Answer

D. Cache maintenance works on whole lines. DC IVAC invalidates the entire line containing the VA, including dirty bytes outside the buffer. The VA needs no alignment (so B is wrong). DC IVAC does not clean (so C is wrong), except when the implementation or a stage 2 regime upgrades it to clean and invalidate, which you cannot rely on at EL3 or EL2. Align and pad DMA buffers to CWG, or use DC CIVAC on edge lines.

Read more: Arm ARM (DDI0487), DC IVAC; CTR_EL0.CWG

Q8.7.3 An SMMUv3 reports SMMU_IDR0.COHACC == 0. Software writes a new STE with normal cacheable stores, issues CMD_CFGI_STE and CMD_SYNC, and the device then faults with a bad-STE event. What is the most likely missing step?

  • A. Cleaning the STE (and any CD or tables it points to) to the PoC, followed by a DSB, before issuing the command
  • B. A TLBI VMALLE1IS before CMD_CFGI_STE
  • C. Setting SMMU_CR1.TABLE_SH to Inner Shareable
  • D. An ISB after writing the STE
Answer

A. With COHACC == 0, the SMMU’s table and queue reads do not snoop PE caches, so the STE must be in memory at the PoC before the SMMU is told to fetch it. Setting SMMU_CR1 attributes (option C) cannot create coherency the SMMU does not support. The command queue entries themselves must also be visible, by the same reasoning. A PE TLBI does not affect SMMU configuration caches. An ISB has nothing to do with memory visibility to another master.

Read more: SMMUv3 (IHI0070), SMMU_IDR0.COHACC; SMMU_CR1; Structure and queue coherency

8.8 Caches at power transitions

This is the book’s one deep treatment of what happens to caches when a PE, a cluster or the system loses power. PSCI mechanics (CPU_ON, CPU_SUSPEND, the warm-boot entry point) are in 17.4. The MMU-on sequence and the invalidate-at-reset rules are in 9.3. This section covers the data in the caches, and why the order of the steps decides whether it survives.

The problem has two parts. When a cache loses power, its dirty lines are lost unless they were written back. And while a PE is leaving or entering coherency, there is a window where it holds lines that the rest of the system cannot snoop, or where it can see stale lines it was never told to drop.

Cache enable and disable, architecturally

  • SCTLR_ELx.C controls data and unified cacheability for the translation regime. With C == 0, data accesses to Normal memory in that regime are treated as Non-cacheable. With the MMU off (SCTLR_ELx.M == 0), data accesses are Device-nGnRnE regardless. SCTLR_ELx.I controls instruction cacheability in the same way.
  • Clearing C stops new allocations by that regime’s accesses. It does not clean, invalidate or disable the cache. Lines already there stay, dirty lines stay dirty, and the cache keeps answering snoops from coherent observers. A Non-cacheable access to a location that still has a line in the cache is a mismatched-attribute case. Don’t rely on it either hitting or missing (6.6).
  • Speculative accesses through other regimes, or through cacheable translations still in the TLB, can still allocate. Clearing C at EL3 does not stop EL1&0 allocation, though at the point where EL3 powers down the core nothing else runs.

The consequence: “turn the cache off, then clean it” is the only order that leaves a cache with no dirty lines. “Clean, then turn it off” leaves a window in which new writes, including the cleaning routine’s own stack spills, allocate new dirty lines.

Clean to PoC before power-off

Data that must survive the PE’s power-off must be at the PoC, or at least past any cache that loses power:

  • This PE’s private caches (L1, and L2 on most cores) are lost when the core powers down. Every dirty line must be written back.
  • Data that the warm-boot path reads with caches off. On pre-DynamIQ TF-A builds, the warm-boot entry runs with SCTLR_EL3.C == 0 until the MMU is re-enabled. Any variable it reads before then must be clean to PoC: the per-CPU PSCI state, the entry point and context ID, the platform’s power-state target. TF-A cleans these explicitly with flush_dcache_range() (look for psci_flush_cpu_data). With HW_ASSISTED_COHERENCY and WARMBOOT_ENABLE_DCACHE_EARLY, the design changes so caches can come on early in the warm-boot path.
  • The cluster’s shared cache (DSU L3 or a pre-DynamIQ cluster L2) is lost only when the last core of the cluster goes down and the cluster power domain turns off. That core cleans or flushes the shared level, or hardware does it.
  • A system-level cache in the interconnect (for example a CMN HN-F SLC) is below every PE’s set/way reach. It is flushed through IMPLEMENTATION DEFINED means, usually by the SCP or power controller, as part of system suspend.

Set/way: only for the local hierarchy, only here

8.5 explains why DC CISW and friends are unsafe as coherency tools: they act on this PE’s view of one cache level, lines can migrate between ways while you iterate, and other PEs’ caches are untouched. Power-down is the one place they are the right tool, because all of the following are true here:

  1. The PE has stopped allocating, since SCTLR_ELx.C is clear.
  2. Other PEs may still snoop this cache. A line they take while you iterate is simply no longer your problem, as long as you leave coherency after the loop.
  3. The goal is “empty this physical cache before it loses power”, not “make address X visible”. Set/way is exactly that operation, and by-VA maintenance would need a mapping for every PA that might be cached.

Use set/way only for the levels that lose power with this PE or cluster: up to CLIDR_EL1.LoUIS for a core, and the cluster’s shared level for the last core. TF-A’s dcsw_op_louis and dcsw_op_all take the level range from CLIDR_EL1 (8.1) and iterate sets and ways using CCSIDR_EL1. The cache-level limits come from CLIDR; never hard-code them.

Leaving coherency: pre-DynamIQ cores

On Cortex-A53, A57, A72 (and A35, A73 and similar), each core’s participation in cluster coherency is controlled by CPUECTLR_EL1.SMPEN. This is an IMPLEMENTATION DEFINED register (S3_1_C15_C2_1), bit 6 on these cores. While SMPEN == 1, the core’s L1D receives coherency requests from the SCU/L2. When it is 0, it does not. Software must set it before enabling caches and the MMU, and clear it only when the L1 is empty.

TF-A’s cortex_a53_core_pwr_dwn and cortex_a53_cluster_pwr_dwn show the order:

// Core power-down on a Cortex-A53-class core, at EL3 (sketch of TF-A's sequence)
    mrs     x0, sctlr_el3
    bic     x0, x0, #(1 << 2)     // SCTLR_EL3.C = 0: stop allocating
    msr     sctlr_el3, x0
    isb
    // (A57/A72: also disable L2 prefetch via CPUECTLR_EL1 and wait, per TRM)
    mov     x0, #DCCISW
    bl      dcsw_op_level1        // clean+invalidate L1 by set/way
    // last core in cluster only: bl dcsw_op_level2 (clean+invalidate L2)
    mrs     x0, S3_1_C15_C2_1     // CPUECTLR_EL1
    bic     x0, x0, #(1 << 6)     // SMPEN = 0: leave coherency
    msr     S3_1_C15_C2_1, x0
    isb
    dsb     sy
    // program the power controller, then:
    wfi

Each ordering constraint has a reason:

If you……this breaks
clean before clearing CStack spills and the routine’s own stores allocate new dirty lines after the clean; they are lost at power-off.
clear SMPEN before the cleanThe core is outside coherency but holds dirty lines. Other cores’ reads of those addresses get the stale DRAM copy, and the dirty lines vanish at power-off. Their writes no longer invalidate this core’s copies either, but those copies are about to be discarded anyway.
do any cacheable access after SMPEN = 0It may allocate a line the system cannot see or invalidate.
omit the final DSB before WFIThe writebacks and the power-controller register write may still be in flight when the core asks to power down.

The reverse on wake-up: SMPEN must be set before the D-cache and MMU are enabled. That is why TF-A’s Cortex-A53/A57/A72 reset handlers set it in reset_func early in BL31 entry.

Leaving coherency: DynamIQ cores

DynamIQ cores (Cortex-A55, A75, A76 and later, Neoverse N1 and later, with a DSU) have no SMPEN. Coherency entry and exit and the private-cache flush are done by hardware, under the control of the core’s Power Policy Unit (PPU). Software’s job shrinks to:

// Core power-down on a DynamIQ core (TF-A cortex_a76_core_pwr_dwn)
    mrs     x0, S3_0_C15_C2_7     // CPUPWRCTLR_EL1
    orr     x0, x0, #1            // CORE_PWRDN_EN: next WFI requests power-down
    msr     S3_0_C15_C2_7, x0
    isb
    // PSCI layer: program the power controller (often via SCP), dsb sy, wfi

With CPUPWRCTLR_EL1.CORE_PWRDN_EN == 1, the core’s next WFI becomes a power-down request. Once the PPU accepts it, the core cleans and invalidates its L1 and L2, leaves coherency with the DSU, and powers off. TF-A platforms built only from such cores can set HW_ASSISTED_COHERENCY=1, which removes the software set/way flush from the PSCI power-down path. The software rule “don’t allocate dirty data you need after the request” still applies to data the warm-boot path reads before caches come back. With WARMBOOT_ENABLE_DCACHE_EARLY that data is cache-coherent anyway.

For the cluster, the DSU’s IMPLEMENTATION DEFINED registers give the power controller hints:

  • CLUSTERPWRDN_EL1 (S3_0_C15_C3_6). Bit 0 tells the power controller whether cluster power is still required when all cores are down. Bit 1 (memory retention) requests that the L3 RAMs be kept in retention instead of being flushed and powered off. These are advisory: the cluster PPU and the SCP decide, and the DSU flushes the L3 itself before a full cluster power-off.
  • CLUSTERPWRCTLR_EL1 (S3_0_C15_C3_5) controls L3 cache-portion power-down (powering off some L3 ways at run time) and functional-retention behaviour.

Check the field layouts for your DSU revision in the DSU TRM. TF-A’s drivers/arm/dsu code programs these from platform data.

Bring-up note: Cache maintenance has a long errata history, and power-down and CMO sequences are where it shows up. Cortex-A53 has several errata in which a clean by VA may not be honoured: 819472, 824069, 826319 and 827319 are grouped under Linux’s ARM64_WORKAROUND_CLEAN_CACHE, which upgrades DC CVAC/DC CVAU to DC CIVAC. Cortex-A53 erratum 855873 (“an eviction might overtake a cache clean operation”) is handled in TF-A on r0p3 and later by setting CPUACTLR_EL1.ENDCCASCI (bit 44), which makes hardware perform cleans as clean+invalidate. For any new core, read the SDEN’s cache, CMO and power-down categories before trusting the TRM sequence, and enable the matching ERRATA_* build flags in TF-A (1.3). A missing errata workaround in this area typically shows up as corruption only after many thousands of suspend cycles.

Why the order matters at system scale

On a multi-cluster or multi-chiplet system, the same reasoning repeats one level up. Before a cluster’s CHI port is taken out of the snoop domain, for example by removing it from the HN-F snoop filter or DVM domain through the interconnect’s IMPLEMENTATION DEFINED controls, everything the cluster held must already be written back. After the cluster leaves, no DVM messages or snoops are sent to it. TLBI broadcasts from other clusters therefore don’t reach it, which is why a cluster coming back up must invalidate its TLBs and caches as if from reset (8.3, 17.5).

Validation note: The core test is a suspend-resume stress with checker patterns. Before each CPU_SUSPEND (power-down state) or CPU_OFF/CPU_ON cycle, the target core writes a unique pattern to a few hundred lines, including lines on the stack the power-down path uses. After it resumes, another core and the resumed core both verify the patterns. Add a variant where another core continuously reads and writes lines the target holds dirty during its power-down sequence. That variant catches the clear-SMPEN-too-early bug. On FVP, enable cache state modelling (-C cache_state_modelled=1); without it, the model has no dirty lines to lose and every sequence “passes”. On silicon, PMU L1D_CACHE_WB (0x15) on the target before WFI confirms the flush happened. Interconnect counters confirm that snoops stopped arriving after the core left coherency.

Checkpoint

Q8.8.1 On a Cortex-A53, a vendor power-down routine does: DC CISW loop over L1; clear SCTLR_EL3.C; ISB; clear CPUECTLR_EL1.SMPEN; DSB SY; WFI. Corruption appears after many suspend cycles. Which change fixes the ordering bug?

  • A. Clear SMPEN before the DC CISW loop, so the loop is not disturbed by snoops
  • B. Replace the DC CISW loop with DC CIVAC over all of DRAM
  • C. Clear SCTLR_EL3.C (and ISB) before the DC CISW loop
  • D. Add an IC IALLU after clearing SMPEN
Answer

C. With C still set during the loop, the routine’s own stores and stack spills (and any other cacheable writes) can allocate dirty lines after the set/way pass has already visited their sets. Those lines are lost at power-off. Option A is the classic opposite mistake: leaving coherency while holding dirty lines makes other cores read stale data. Option B is impractical, and it still leaves the allocation window.

Read more: Arm ARM (DDI0487), SCTLR_EL3.C; data cache maintenance by set/way; Cortex-A53 TRM, CPUECTLR_EL1

Q8.8.2 A TF-A port for a DynamIQ core uses HW_ASSISTED_COHERENCY=1. The core’s power-down path sets CPUPWRCTLR_EL1.CORE_PWRDN_EN and executes WFI, with no software cache flush. Which statement is correct?

  • A. This is a bug: the L1 and L2 must be cleaned by set/way before the WFI
  • B. This is the intended design: once the power-down request is accepted, the core’s hardware sequence cleans its private caches and exits coherency
  • C. This works only if the DSU’s CLUSTERPWRDN_EL1 is also written
  • D. This works only because DynamIQ caches are write-through
Answer

B. On DynamIQ cores the private-cache clean and coherency exit are part of the hardware power-down sequence, triggered by WFI with CORE_PWRDN_EN == 1, under control of the PPU. CLUSTERPWRDN_EL1 is an advisory hint for cluster power, not a requirement for a core power-down. The caches are write-back.

Read more: Cortex-A76 TRM (or your core’s TRM), CPUPWRCTLR_EL1 and core power-down; TF-A cortex_a76_core_pwr_dwn

Q8.8.3 The warm-boot entry point on a pre-DynamIQ platform reads a per-CPU “target power state” variable before enabling the MMU and D-cache. The variable was written by the core itself, with caches on, just before suspending. Sometimes the resumed core reads an old value. Why?

  • A. The write reached only the core’s cache. The warm-boot path reads with caches off, so it reads DRAM, and the variable was not cleaned to PoC after it was written
  • B. The read needs a DMB because Device-nGnRnE reads are not ordered
  • C. The core’s L1 retained the value but SCTLR_EL3.C == 0 disables cache hits
  • D. The TLB still held the old translation from before suspend
Answer

A. With the MMU off, the read is Device-nGnRnE, which goes to memory. Any data the caches-off path consumes must be cleaned to PoC by the writer. TF-A does this with explicit flush_dcache_range() calls on PSCI per-CPU data. Option C is tempting but misses the point: after a power-down the L1 contents are gone anyway, and the only question is whether DRAM was updated before that.

Read more: Arm ARM (DDI0487), Behavior of caches when the MMU is disabled; TF-A PSCI library design, cache maintenance on power-down

8.9 MPAM: resource partitioning and monitoring

Shared caches and memory bandwidth are the main source of interference between workloads on a large SoC. A noisy VM evicts a latency-critical one from the SLC, or a DMA-heavy accelerator saturates a memory controller. MPAM (Memory System Resource Partitioning and Monitoring, FEAT_MPAM) addresses this in two halves:

  • The PE side is architectural and in DDI0487. Every memory request the PE issues is tagged with a label.
  • The memory-system side is specified in the separate MPAM architecture supplement. Memory System Components (MSCs) such as caches, interconnects and memory controllers read the label and apply per-label controls and monitors. The MSCs are programmed through MMIO.

The label carries no access control. MPAM decides how much of a resource a request may use, never whether it may access memory.

Versions: ID_AA64PFR0_EL1.MPAM (bits [43:40]) gives the major version and ID_AA64PFR1_EL1.MPAM_frac (bits [19:16]) the minor, giving v0.1, v1.0 or v1.1. FEAT_MPAM is usually described as a v8.4 feature, but DDI0487 also lists it as permitted in v8.2 implementations, and FEAT_MPAMv0p1 exists for such parts. See DDI0487 A2 for the exact permitted-from rules of each minor version.

The label: PARTID, PMG and the PARTID space

Label partWidth (field)Meaning
PARTIDup to 16 bits; max is MPAMIDR_EL1.PARTID_MAXPartition ID. MSCs index their control settings by it.
PMGup to 8 bits; max is MPAMIDR_EL1.PMG_MAXPerformance Monitoring Group: a sub-label within a PARTID, used only by monitors to split usage further. Controls ignore it.
PARTID spaceMPAM_NS, plus Root/Realm with RMESelects which of the MSC’s independent PARTID namespaces the request belongs to. Secure PARTID 5 and Non-secure PARTID 5 are different partitions.

Instruction fetches and data accesses carry separate labels: PARTID_I/PMG_I and PARTID_D/PMG_D in each register. So code and data of one workload can be given different cache shares.

PE registers

The PE generates the label from the register for the current Exception level:

RegisterUsed when executing atNotable fields
MPAM0_EL1EL0PARTID_I/D [15:0]/[31:16], PMG_I/D [39:32]/[47:40]
MPAM1_EL1 (MPAM1_EL12 under VHE)EL1 (and EL0 with GSTAPP_PLK)the same, plus MPAMEN (read-only mirror)
MPAM2_EL2EL2TRAPMPAM0EL1, TRAPMPAM1EL1, EnMPAMSM (SME), TIDR, ALTSP controls
MPAM3_EL3EL3MPAMEN (bit 63), TRAPLOWER (bit 62), SDEFLT, FORCE_NS, ALTSP controls

MPAM3_EL3.MPAMEN is the master enable. In MPAM2_EL2 and MPAM1_EL1, bit 63 is a read-only view of it. While MPAMEN == 0, every request carries the default PARTID and PMG (0) in its PARTID space, so the MSCs see a single partition.

MPAMIDR_EL1 describes the PE’s implementation:

FieldBitsMeaning
PARTID_MAX[15:0]Largest PARTID the PE can generate
HAS_HCR17Virtualization support: MPAMHCR_EL2, MPAMVPMV_EL2, MPAMVPM<n>_EL2
VPMR_MAX[20:18]Highest n for the MPAMVPM<n>_EL2 mapping registers
PMG_MAX[39:32]Largest PMG
HAS_ALTSP57Alternative PARTID spaces (RME)
HAS_TIDR58MPAM2_EL2.TIDR implemented
SP459Four PARTID spaces (Secure, Non-secure, Root, Realm) rather than two
HAS_FORCE_NS60MPAM3_EL3.FORCE_NS implemented
HAS_SDEFLT61MPAM3_EL3.SDEFLT implemented

The PE’s PARTID_MAX and each MSC’s MPAMF_IDR.PARTID_MAX are independent. Software must use the smallest common range. A PARTID larger than an MSC supports is an error at that MSC (reported through MPAMF_ESR and the MSC’s error interrupt), not a silent wrap.

Virtual PARTIDs

A hypervisor should not let a guest choose physical PARTIDs, and it should not need to trap every guest write of MPAM1_EL1. With MPAMIDR_EL1.HAS_HCR == 1:

  • MPAMHCR_EL2.EL1_VPMEN (bit 1) and EL0_VPMEN (bit 0) mark MPAM1_EL1 and MPAM0_EL1 PARTIDs as virtual.
  • A virtual PARTID indexes the MPAMVPM0_EL2–MPAMVPM7_EL2 registers. Each holds four 16-bit physical PARTIDs, so there are up to 32 virtual PARTIDs. MPAMVPMV_EL2 holds one valid bit per entry. A virtual PARTID with no valid mapping falls back to a default physical PARTID rather than leaking the guest’s value; the exact rule is in the MPAMVPMV_EL2 description in DDI0487.
  • MPAMHCR_EL2.GSTAPP_PLK (bit 8) makes guest EL0 use the guest’s MPAM1_EL1 labels. This keeps a guest OS’s applications from choosing their own partition.
  • MPAMHCR_EL2.TRAP_MPAMIDR_EL1 (bit 31) and MPAM2_EL2.TIDR trap guest reads of MPAMIDR_EL1, so the hypervisor can present a reduced PARTID_MAX.

MPAM2_EL2.TRAPMPAM1EL1/TRAPMPAM0EL1 trap guest accesses to the MPAM registers for full emulation instead.

Secure, Root and Realm PARTID spaces

Each MSC has one MMIO configuration frame per PARTID space: _s (Secure), _ns (Non-secure) and, with four spaces, _rt (Root) and _rl (Realm). Each frame is reachable only by accesses in the matching physical address space. The Non-secure OS therefore cannot reconfigure the cache share of Secure PARTIDs. It also cannot monitor Secure usage through its own frame, which closes an obvious side channel.

On the PE:

  • MPAM3_EL3.SDEFLT forces Secure-state requests to PARTID 0 and PMG 0, useful when the Secure world has no MPAM-aware software.
  • MPAM3_EL3.FORCE_NS makes Secure-state requests use the Non-secure PARTID space (MPAM_NS = 1). This lets the Normal-world resource manager control Secure traffic too.
  • With FEAT_RME and HAS_ALTSP, the alternative PARTID space controls (MPAM3_EL3.ALTSP_HEN, ALTSP_HFC, ALTSP_EL3, RT_ALTSP_NS; MPAM2_EL2.ALTSP_HFC, ALTSP_EL2) let a Security state label requests in an alternative space instead of its primary one. For example, Realm or Root traffic can be labelled in a space the Non-secure host’s MPAM driver controls, so the host can budget its Realms without being able to touch Realm-space configuration. Which space the RMM uses is a CCA platform policy decision (12.4).

Security note: MPAM monitors are a measurement channel. A CSU monitor shows how many bytes of the cache a PARTID occupies, which an attacker can use as a coarse occupancy side channel. Don’t share a PARTID+PMG between mutually distrusting tenants if monitors are exposed to either. Make sure Secure/Realm traffic is labelled in a space whose monitors the Normal world cannot read, unless that is intended.

EL3 duties

MPAM3_EL3 resets with MPAMEN = 0 and TRAPLOWER = 1. Until EL3 changes it, any access to an MPAM System register from EL2 or EL1 traps to EL3 (EC 0x18). On a TF-A system:

  1. If ID_AA64PFR0_EL1.MPAM/MPAM_frac is non-zero, write MPAM3_EL3 with MPAMEN = 1 and TRAPLOWER = 0 for the worlds allowed to use MPAM. TF-A does this under ENABLE_FEAT_MPAM. Recent versions keep the setting per world, so Secure/Realm can stay trapped.
  2. Initialise MPAM2_EL2 (clear trap bits, PARTID 0) and MPAMHCR_EL2 before dropping to a hypervisor, since most of their fields reset to UNKNOWN values.
  3. Program the Secure (and Root/Realm) frames of every MSC that EL3 owns: at minimum, a sensible configuration for PARTID 0 in each space. MSC reset values are IMPLEMENTATION DEFINED, and the MPAM supplement does not promise that they leave the full resource available.
  4. Describe the MSCs to the OS: the ACPI MPAM table (MSC base, interrupts, the resource each controls and its location such as cache ID or memory proximity domain), or device tree.

Bring-up note: A kernel or hypervisor that probes MPAM on a platform where EL3 left TRAPLOWER = 1 takes an unexpected exception to EL3 on its first MRS MPAMIDR_EL1 or MPAM2_EL2 access. On TF-A this typically ends in a “unhandled exception” panic in BL31 with ESR_EL3.EC == 0x18. Either enable MPAM at EL3 or make sure the ID registers the OS sees (through an ID_AA64PFR* override or a firmware table) say it is absent.

MSCs and their MMIO interface

Each MSC exposes a feature page with ID registers, and the configuration and monitor registers behind a selector:

Discovery    MPAMF_IDR            PARTID_MAX, PMG_MAX, HAS_CPOR_PART, HAS_CCAP_PART,
                                  HAS_MBW_PART, HAS_PRI_PART, HAS_MSMON, HAS_RIS,
                                  HAS_PARTID_NRW, EXT, SP4 ...
             MPAMF_CPOR_IDR       CPBM_WD: cache-portion bitmap width
             MPAMF_CCAP_IDR       cache-capacity control resolution
             MPAMF_MBW_IDR        bandwidth control types and resolution
             MPAMF_MSMON_IDR      MSMON_CSU, MSMON_MBWU present
Configure    MPAMCFG_PART_SEL     PARTID_SEL [15:0], INTERNAL [16], RIS [27:24]
             MPAMCFG_CPBM<n>      cache-portion bitmap: which portions PARTID may allocate in
             MPAMCFG_CMAX         maximum fraction of cache capacity
             MPAMCFG_MBW_MIN/MAX  minimum / maximum bandwidth fractions
             MPAMCFG_MBW_PBM      bandwidth-portion bitmap
             MPAMCFG_PRI          internal / downstream priority
Monitor      MSMON_CFG_MON_SEL    select monitor instance (and RIS)
             MSMON_CFG_CSU_FLT/CTL   PARTID/PMG filter, match enables, EN
             MSMON_CSU            NRDY [31], VALUE [30:0] in bytes
             MSMON_CFG_MBWU_FLT/CTL, MSMON_MBWU(_L)   bandwidth usage in bytes
Errors       MPAMF_ESR, MPAMF_ECR   PARTID/PMG out of range, monitor errors

The programming model: write MPAMCFG_PART_SEL.PARTID_SEL, then write that PARTID’s control registers. HAS_RIS MSCs contain several resources (for example a cache and its memory port) chosen by RIS. With PARTID narrowing (HAS_PARTID_NRW), the MSC has fewer internal PARTIDs than request PARTIDs, and MPAMCFG_INTPARTID maps request PARTIDs onto them. Monitors report NRDY while their value is not yet meaningful, for example right after configuration or a cache power transition. Software must not treat an NRDY read as zero.

Controls are policies, and their effect is partly IMPLEMENTATION DEFINED. A cache-portion bitmap restricts where a PARTID may allocate, not what it may hit. Lines already resident stay until evicted, so a new partitioning takes effect gradually. Bandwidth limits are enforced over an implementation-defined window (MPAMCFG_MBW_WINWD where implemented) and are approximate.

Where MSCs sit in a CMN mesh

The label must travel with the request to every MSC. On CHI, requests carry MPAM fields (PartID, PerfMonGroup and the NS/space indication) from the RN-F through the mesh. Typical MSC placement in a CMN-based SoC:

  • DSU L3 (where the DSU implements MPAM): partitioning of the cluster-shared cache.
  • HN-F / SLC slices: each HN-F slice is usually a separate MSC, or one resource instance (RIS) of a combined MSC, with portion or capacity control and CSU monitors. To partition the SLC, every slice must be programmed identically, because addresses hash across all of them.
  • Memory controllers (behind SN-F): bandwidth controls and MBWU monitors.
  • I/O and accelerators: requests that enter through an RN-I or the SMMU get labels from the SMMU (STE/CD MPAM fields, with SMMU MPAM support) or from fixed per-port defaults.
  • Across chiplets: CHI C2C or CXL links must carry the label. If the bridge drops it, all remote traffic arrives as PARTID 0, and partitioning of the remote die’s SLC and DRAM silently stops working (8.3).

The exact CHI field set depends on the CHI issue and the CMN product. Check the interconnect TRM for which HN-F and SN components implement MPAM controls versus monitors only.

Validation note: Confirming that partitioning takes effect needs a three-part test, because register read-back proves only that the MMIO write landed.

  1. Label check. Run a workload with a known PARTID+PMG, configure a CSU monitor at the target MSC to match exactly that PARTID+PMG, and confirm MSMON_CSU.VALUE rises from zero. If it stays at zero, the label is not arriving. Look for a wrong PARTID space (MPAM_NS, FORCE_NS, ALTSP), MPAMEN still 0, virtual PARTID mapping, or a bridge dropping the field.
  2. Control check. Run a cache-thrashing aggressor in PARTID A and a pointer-chasing victim in PARTID B sized to fit the SLC. Measure the victim’s latency, or its LL_CACHE_MISS_RD (0x37) / L3D_CACHE_REFILL (0x2A) PMU counts where implemented, with a shared bitmap and then with disjoint MPAMCFG_CPBM bitmaps. Expect the victim’s miss rate to fall to near its solo value. CSU for A should plateau at its share of capacity.
  3. Bandwidth check. Set MPAMCFG_MBW_MAX for a streaming PARTID and compare MBWU or memory-controller counters against the configured fraction. Expect approximate enforcement over the window, not exact.

Run all three for every MSC instance (every HN-F slice, every memory channel, every chiplet), and repeat after a cluster power cycle. MSC state may be in a power domain that loses its configuration.

Checkpoint

Q8.9.1 A Normal-world kernel programs disjoint cache-portion bitmaps in the SLC MSCs’ Non-secure frames for PARTIDs 1 and 2. CSU monitors in the Non-secure frame matching PARTID 1 read zero while the workload runs, even though MPAM1_EL1 reads PARTID 1. EL3 set MPAMEN = 1. Which explanation is most consistent?

  • A. CSU monitors only count instruction fetches, so PARTID_D traffic is invisible
  • B. The cache-portion bitmap has stopped PARTID 1 from hitting in the cache
  • C. The requests are not arriving in the Non-secure PARTID space with PARTID 1. For example, a hypervisor enabled EL1_VPMEN and the virtual PARTID maps to another physical PARTID
  • D. CSU monitors need PMG_MAX == 0
Answer

C. A monitor that stays at zero means no requests match its filter at that MSC. The usual causes are a label problem: virtual-to-physical PARTID mapping, the wrong PARTID space, a bridge dropping the label, or a PMG mismatch in the monitor filter. Option B misunderstands bitmaps: they limit where a PARTID can allocate, not whether it hits, and a restricted PARTID still occupies the portions it is allowed.

Read more: Arm ARM (DDI0487), MPAMHCR_EL2, MPAMVPMn_EL2, MPAMVPMV_EL2; MPAM architecture supplement, CSU monitors

Q8.9.2 A TF-A port for an MPAM-capable SoC does not set ENABLE_FEAT_MPAM. Linux boots, detects MPAM from ID_AA64PFR0_EL1, and reads MPAMIDR_EL1. What happens?

  • A. The access traps to EL3, because MPAM3_EL3.TRAPLOWER resets to 1, and BL31 has no handler for it
  • B. The read returns zeros, because MPAM is disabled
  • C. The read is UNDEFINED at EL1 and Linux gets an Undefined Instruction exception
  • D. It works, because TRAPLOWER only affects MPAM3_EL3 itself
Answer

A. TRAPLOWER resets to 1 and traps all MPAM System register accesses from ELs lower than EL3. EL3 firmware must clear it, or hide MPAM from the OS. MPAMEN == 0 affects only the labels on requests, not register accessibility (so B is wrong). The registers exist because FEAT_MPAM is implemented, so the access is not UNDEFINED.

Read more: Arm ARM (DDI0487), MPAM3_EL3.TRAPLOWER; TF-A build option ENABLE_FEAT_MPAM

Q8.9.3 An SoC has 16 HN-F slices, each an SLC MSC. A tester programs MPAMCFG_CPBM for PARTID 3 on slice 0 only, limiting it to a quarter of the portions, and sees almost no change in PARTID 3’s total SLC occupancy. Why?

  • A. Cache-portion partitioning only takes effect after a DC CISW on every PE
  • B. Physical addresses are hashed across all slices, so only about 1/16 of PARTID 3’s lines are in slice 0. The other 15 slices are still unrestricted
  • C. PARTID 3 exceeds MPAMF_IDR.PARTID_MAX, so the write was ignored
  • D. CPBM only applies to the Secure PARTID space
Answer

B. An SLC distributed across HN-F slices is partitioned only when every slice gets the same control settings. MPAM controls are per-MSC. Option A is wrong because bitmaps limit future allocation and need no CMO, although existing lines drain gradually. Option C would show up as an MSC error (MPAMF_ESR), and nothing suggests it here.

Read more: MPAM architecture supplement, cache portion partitioning; your CMN TRM, HN-F MPAM support

8.10 Lab and exercises: validating coherency and cache maintenance

This lab turns Part 8 into tests that can fail. Each test has a checker, a value that is wrong if and only if coherency or maintenance is broken. It also has a fingerprint, the PMU counts that show the test exercised what it claims to. A test with no failing variant proves nothing, so every test here is run with its maintenance or atomicity removed as well. Expect that variant to fail.

Setup

Use the bare-metal image and the labs/part08/ layout from Lab setup. The test binary runs at EL2 or EL1 Non-secure with the MMU and caches on. It brings secondaries up with PSCI CPU_ON, maps a few test regions with selectable attributes, and prints over the PL011.

# QEMU virt: built-in PSCI (conduit is hvc; smc if virtualization=on), 8 CPUs, no caches modelled
qemu-system-aarch64 -M virt,gic-version=3 -cpu max -smp 8 -m 1G \
    -nographic -kernel build/lab8.elf

# FVP Base RevC, TF-A as firmware, lab8.bin as BL33; two 4-core clusters
FVP_Base_RevC-2xAEMvA \
    -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 \
    -C cache_state_modelled=1 \
    -C bp.secureflashloader.fname=tf-a/build/fvp/release/bl1.bin \
    -C bp.flashloader0.fname=tf-a/build/fvp/release/fip.bin \
    -C bp.pl011_uart0.out_file=uart0.log
# build the FIP with: make PLAT=fvp BL33=../labs/part08/build/lab8.bin all fip

Rerun every FVP test with -C cache_state_modelled=0. The comparison matters more than either run:

EnvironmentModelsA CMO-removal test there…
QEMU TCGTLBs, atomicity (host atomics), no cachesalways passes: CMOs are no-ops and memory is always coherent
FVP, cache_state_modelled=0TLBs, no cache statealways passes, same reason
FVP, cache_state_modelled=1cache contents, dirty lines, coherency protocol; no timingmust fail when a CMO is removed; PMU cache events may not match silicon, and timing is meaningless
Silicon or emulator with the real RTLeverything, including timing and PMUmust fail; timing and PMU fingerprints are meaningful (needs a real board or emulator)

Validation note: Record, for every test, which environment can fail it. A green run on an environment that cannot fail the test is not coverage. Reporting it as coverage is the most common pre-silicon validation mistake in this area (18.4).

PMU harness

Program counters at the EL the test runs at. EL3 and EL2 must not trap or disable them: MDCR_EL3, and MDCR_EL2.HPMN must cover the counters. Details are in 16.3.

#define NSH (1UL << 27)   /* PMEVTYPERn_EL0.NSH: also count at EL2 */

static inline void pmu_setup(void) {
    write_sysreg(NSH | 0x03, pmevtyper0_el0);   /* L1D_CACHE_REFILL */
    write_sysreg(NSH | 0x04, pmevtyper1_el0);   /* L1D_CACHE */
    write_sysreg(NSH | 0x15, pmevtyper2_el0);   /* L1D_CACHE_WB */
    write_sysreg(NSH | 0x19, pmevtyper3_el0);   /* BUS_ACCESS */
    write_sysreg(NSH, pmccfiltr_el0);           /* cycle counter: same filter */
    write_sysreg(0xF | (1UL << 31), pmcntenset_el0); /* counters 0-3 + cycle */
    write_sysreg(read_sysreg(pmcr_el0) | 0x7, pmcr_el0); /* E, P, C: enable+reset */
    isb();
}

With NSH == 0 (the value a bare event number gives), events at EL2 are not counted, so a test running at EL2 would read zeros. The event numbers are the common architectural events. A core may not implement all of them, so check PMCEID0_EL0 (for events 0x00 to 0x1F, bit n set means event n is implemented; PMCEID1_EL0 covers 0x20 to 0x3F). Interconnect events, such as snoops sent, snoop-filter hits and back-invalidations at the HN-F, or DVM operations, come from the CMN or DSU PMU. Their encodings are IMPLEMENTATION DEFINED, so take them from that product’s TRM.

Test 1: false sharing vs true sharing

Two cores each increment their own counter 10⁶ times with plain LDR/ADD/STR.

  • Variant F (false sharing): the counters are in one 64-byte line.
  • Variant P (padded): the counters are CTR_EL0.CWG-aligned and in separate lines.

Checker: each final counter equals 10⁶. False sharing is a performance effect, never a correctness one. Any difference is a coherency bug.

Fingerprint, on silicon: in F, L1D_CACHE_REFILL approaches one per increment on each core, because every store must regain unique ownership, and cycles per iteration rise by 10–100×. In P, refills are near zero after warm-up. Put the two cores on different clusters, then on different chiplets. The refill count stays the same but the cycles per refill grow, which measures the snoop path (8.3). If F and P have the same refill rate, look for a wrong line-size assumption, or an allocation that is not the size you think.

True sharing: both cores increment one counter. Now the checker is the lost-update test.

Test 2: lost-update detection, exclusives vs LSE

N cores (one per cluster and chiplet at least) each add 1 to a shared counter M times. Three implementations:

// (a) plain: expected to lose updates
1:  ldr     x1, [x0]
    add     x1, x1, #1
    str     x1, [x0]
// (b) exclusives
2:  ldxr    x1, [x0]
    add     x1, x1, #1
    stxr    w2, x1, [x0]
    cbnz    w2, 2b
// (c) LSE (FEAT_LSE)
    mov     x1, #1
    stadd   x1, [x0]

Checker: the total equals N×M for (b) and (c). For (a), the architecture permits lost updates but does not require them; under real contention the total comes out below N×M in practice, and the test design relies on that. If (a) never loses an update, the test is not creating contention: the cores are not actually running at the same time, or the model serialises them. Fix the test before trusting (b) and (c).

Fingerprint: for (b), count STXR failures in software (the cbnz taken count). It should be non-zero under contention and must not grow without bound (livelock). For (c), on CHI systems that execute far atomics, L1D_CACHE_REFILL on the counter line can stay near zero while HN-F atomic counters rise. Whether STADD goes near or far is IMPLEMENTATION DEFINED, and on some cores it is configurable. Run the test on Write-Back memory and on Non-cacheable memory, where exclusives depend on a global monitor. The memory-type matrix and the near/far details are in 10.1 and 10.2.

Test 3: CMO-plus-DMA round trips

Use a real non-coherent DMA engine on a board. On FVP with cache modelling, a Non-cacheable alias of the buffer stands in for the non-coherent master, because its accesses bypass the modelled caches. This is a deliberate mismatched-attribute trick for testing only (6.6), and it emulates the data path of a master that does not snoop, not its timing.

Checker pattern: every 64-bit word holds addr ^ seed ^ iteration. It is unique per word and per pass, so a stale line shows up as the previous iteration’s value at a known address, not as random garbage.

for (it = 0; it < ITERS; it++) {
    fill(src, len, seed, it);              /* PE writes via WB mapping */
    memset(dst, 0xA5, len);                /* PE dirties dst, so T2 matters */
    dc_cvac_range(src, len); dsb_sy();     /* to-device: clean      [T1] */
    dc_civac_range(dst, len); dsb_sy();    /* from-device: pre-clean [T2] */
    dma_copy(dst, src, len);               /* or NC-alias memcpy on FVP */
    dma_wait();
    dc_ivac_range(dst, len); dsb_sy();     /* from-device: invalidate [T3] */
    check(dst, len, seed, it);             /* report first bad addr + value */
}

Run the matrix: remove T1, T2, T3 one at a time. Misalign dst by 8–56 bytes with live neighbour data. Add a second core that read-streams dst during the copy, to provoke speculative and prefetch refills. The expected outcomes on a cache-modelling environment are: no T1 gives old data at the destination; no T2 corrupts the destination (with 0xA5 bytes) when a dirty line from the memset is evicted during or after the copy; no T3 gives stale reads, more often with the prefetching core; misalignment damages the neighbour data. Each failure should be reproducible within a bounded number of iterations. A failure that never appears means that environment cannot see it. The sequences themselves are in 8.7.

Test 4: TLBI shootdown across clusters and chiplets

One page VA V is mapped to PA1 (filled with tag 0x11) and readable by every core. Readers loop: read flag F with LDAR, read [V], record any (F == 1, value == 0x11) pair. The writer remaps with break-before-make (9.2):

    // x_pte, x_va, x_new, x_flag are symbolic; substitute real registers
    str     xzr, [x_pte]              // invalidate descriptor
    dsb     ishst
    tlbi    vale1is, x_va             // broadcast; x_va = VA[55:12] (and ASID)
    dsb     ish                       // complete on every PE in the IS domain
    str     x_new, [x_pte]            // descriptor for PA2 (tag 0x22)
    dsb     ishst
    mov     w9, #1
    stlr    w9, [x_flag]

Checker: no reader may observe F == 1 and then read 0x11. That combination means some PE kept a translation through a completed broadcast TLBI: a DVM message did not reach its cluster or chiplet, or a DVM Sync completed early. Readers may legitimately fault while the descriptor is invalid. Make the fault handler retry. Place readers on every cluster and every chiplet; a chiplet whose DVM forwarding is misconfigured is the target (17.5). Then drop IS (use TLBI VALE1) and confirm the checker fires on remote readers. On QEMU it may not fire, because TCG’s cross-CPU flush is often stronger than the architecture requires. The full sequence rationale is in 9.1.

Fingerprint: the CMN or DSU DVM counters increment once per TLBI ...IS plus one sync per DSB. A reader core’s L1D_TLB_REFILL (0x05) rises once after each remap.

Exercises: find the missing CMO

Each snippet is from firmware for a platform with the stated properties. Say what is missing, why it fails, and when it would show up.

E1. BL2 running at EL3 (as in a RESET_TO_BL2 build), with MMU and D-cache on, copies BL31 into SRAM with memcpy, then ERETs to BL31’s entry, which runs with SCTLR_EL3.{M,C,I} = 0.

Answer

BL31’s image may still be dirty in BL2’s D-cache. BL31 fetches and reads with caches off, so from memory, and it can get stale bytes. Clean the image to PoC (DC CVAC loop, DSB SY) before the ERET. Invalidate the I-cache (IC IALLU) if BL31’s address range may have been executed before. TF-A’s image loader does this with flush_dcache_range(). On FVP this fails only with cache_state_modelled=1, and typically as a hang in BL31’s early C code.

E2. A non-coherent NIC transmit path:

desc->addr = buf_pa; desc->len = len; desc->own = 1;
dmb(st);
writel(TX_DOORBELL, tail);
Answer

Both the payload buf and the descriptor must be cleaned to PoC (DC CVAC over each), and a DSB must separate the cleans from the doorbell. DMB ST orders the stores as PE-side observers see them, but the NIC reads DRAM and never snoops, so it can fetch an old descriptor or payload. The symptom is intermittently corrupt frames, or a descriptor the NIC reports as not owned. It is worse when the buffer was recently written and still sits in L1.

E3. The receive path does DC CIVAC over the buffer and DSB SY, starts the DMA, and on the completion IRQ parses the buffer directly.

Answer

The invalidate after completion is missing. During the transfer the PE can speculatively or prefetch-allocate lines of the buffer, holding pre-DMA data. Add DC IVAC (or DC CIVAC on non-line-aligned edges) plus DSB SY before parsing. It shows up rarely, and more often when other code touches adjacent memory or the hardware prefetcher is aggressive.

E4. The primary core writes the secondary’s entry point and stack pointer to a mailbox in DRAM with caches on, then releases the secondary with an SEV. The secondary starts with MMU and caches off and spins reading the mailbox.

Answer

The mailbox must be cleaned to PoC (DC CVAC, DSB SY) before the SEV. The secondary’s reads are Device-nGnRnE (MMU off) and go to memory. They cannot see the primary’s dirty line in any architecturally guaranteed way. The DSB before SEV is also needed so that the clean completes before the event is sent. The symptom is a secondary that never leaves its spin loop, or jumps to address 0. It often “goes away” with debug prints, because those evict the line.

E5. A JIT on core A:

    // code written via x0..x1
    dc   cvau, x0          // looped over range
    ic   ivau, x0          // looped over range
    dsb  ish
    isb
    stlr x0, [x_fnptr]

Core B loads fnptr with LDAR and calls it. CTR_EL0.IDC == DIC == 0.

Answer

Two things are missing. First, a DSB ISH between the DC CVAU loop and the IC IVAU loop; without it, the invalidate can complete before the clean, and a refill can bring the old bytes back into the I-cache. Second, core B needs a context synchronization event (an ISB) after its LDAR and before the call; A’s ISB affects only A. See 8.6. The second bug shows up as B occasionally executing the previous contents of a reused code buffer.

E6. On a Cortex-A53 cluster, the PSCI power-down path for the last core in the cluster clears SCTLR_EL3.C, cleans and invalidates by set/way up to LoUIS, clears SMPEN, and requests cluster power-off.

Answer

LoUIS covers only the L1 on Cortex-A53. The cluster’s shared L2 also loses power, so the last core must also clean and invalidate L2 by set/way (TF-A’s cortex_a53_cluster_pwr_dwn calls dcsw_op_level2, or uses dcsw_op_all) before leaving coherency. Dirty lines that lived only in L2 are lost. That data is often other cores’ data, such as kernel state written just before those cores went offline. It appears after cluster-level suspend, not core-level suspend. See 8.8.

Checkpoint

Q8.10.1 A pre-silicon team reports that the DMA round-trip test passes with every combination of CMOs removed, on both QEMU and FVP. What is the correct conclusion?

  • A. The SoC’s DMA path is I/O-coherent, so the driver’s CMOs can be dropped
  • B. The CMOs are correct, because the test passed with them in place
  • C. The checker pattern is too weak and should use random data
  • D. Neither environment can fail this test as run. The result gives no coverage until it is rerun on FVP with cache_state_modelled=1 (or on RTL or silicon) and the removal variants fail
Answer

D. QEMU models no caches, and the FVP run evidently has cache-state modelling off, or the “device” bypasses nothing. A test whose failing variants pass has not shown it can detect the bug. Option A confuses a model artefact with a hardware property: I/O coherency must come from the SoC’s design and its firmware description (IORT/DT), not from a green test.

Read more: Arm Fast Models / FVP Reference Guide, cache state modelling; Arm ARM (DDI0487), data cache maintenance instructions

Q8.10.2 In the TLBI shootdown test, a reader on chiplet 1 records F == 1 followed by a read of the old page’s tag. Readers on chiplet 0 never do. The writer’s sequence is exactly as shown in Test 4. What is the most likely cause?

  • A. The reader is missing an ISB after its LDAR
  • B. The broadcast TLBI or its DVM Sync is not reaching, or not being completed by, chiplet 1. For example, the chiplet link’s DVM forwarding is not enabled
  • C. TLBI VALE1IS only invalidates last-level entries, so the reader’s walk cache kept the old leaf
  • D. The reader’s load is speculative and therefore allowed to use stale translations
Answer

B. After the writer’s DSB ISH completes, no PE in the Inner Shareable domain may still use the old translation. A failure confined to one chiplet points at DVM propagation or sync completion across the link. Option A: an ISB is not needed for data accesses to use a new translation once the TLBI has completed, and the acquire orders the data read after the flag. Option C: VALE1 removes the leaf entry, which is exactly the one that changed.

Read more: Arm ARM (DDI0487), TLB maintenance instructions and completion by DSB; CHI specification, DVM operations

Q8.10.3 In the lost-update test, variant (a) (plain LDR/ADD/STR) never loses an update over 10⁹ iterations on 8 cores in a model, and variants (b) and (c) also total exactly N×M. What should you conclude?

  • A. Variant (a) is accidentally atomic because the counter is 64-bit aligned
  • B. The environment provides sequential consistency, so the atomics are correct
  • C. The test is not producing real contention in that environment, so the (b) and (c) results are not evidence of atomicity
  • D. The exclusive monitor is working, so (a) also benefits from it
Answer

C. The architecture does not forbid a plain read-modify-write from losing updates, and under real concurrency over 10⁹ iterations it does so in practice. If it never does, the cores are being serialised, for example by a model’s quantum scheduling, or they are not running at the same time. Then the atomic variants are not being tested either. Fix the test (raise the iterations, shrink the model’s quantum, or confirm the cores overlap) before drawing conclusions. Option A misreads single-copy atomicity: each access is atomic, but the read-modify-write sequence is not.

Read more: Arm ARM (DDI0487), single-copy atomicity; Load-Exclusive and Store-Exclusive instructions

Part 9: Virtual memory II: maintaining translations

Prerequisites: 5.1–5.3, 5.6, 6.5, 7.6, 7.8, 8.4

If you already know: If you can justify every barrier in Linux’s __flush_tlb_page() and in TF-A’s enable_mmu_direct_el3, skim 9.1 for FEAT_ETS2 and FEAT_XS, and 9.2 for the BBM levels.

Why this matters for bring-up/validation: Most “dead after SCTLR.M=1”, stale-mapping and sporadic translation-fault bugs are a missing DSB, ISB, TLBI or break step, and a TLB shootdown is one of the first multi-PE coherency paths silicon validation must prove.

Part 5 described translation tables as static structures. This part covers what happens when they change while the hardware is using them. TLBs and walk caches may hold any valid translation they have walked, for as long as they like. Software keeps them correct with tags (ASID, VMID, nG), TLBI operations of the right scope and shareability domain, and a fixed sequence of barriers whose individual steps exist for specific reasons. The sequence has stage 2, FEAT_ETS2 and FEAT_XS variants. Some changes cannot be made in place at all: changing the output address, the memory type or the block size of a live mapping requires break-before-make. FEAT_BBM relaxes this only for block-size changes, and it still leaves TLB conflict aborts to handle.

The part ends with the first transition every boot stage makes: turning the MMU and caches on. That transition combines everything before it. It needs reset-state assumptions about caches and TLBs, the context-synchronization rules for MAIR, TCR, TTBR and SCTLR, an identity-mapped trampoline, cache maintenance for tables written with the MMU off, and a memory map that gives speculation nothing dangerous to touch.

9.1 TLBs and TLB maintenance

The architecture puts few limits on what a TLB caches or when. It may cache any valid translation it has walked, at any time (speculative walks included), hold it for as long as it likes, and combine stage 1 and stage 2 results into one entry. It may also cache intermediate walk results (“walk caches”). There is one useful negative rule: a TLB never caches a translation that would fault with a Translation, Address size or Access flag fault. Everything else in this section follows from those rules. Software must assume that a valid descriptor, once written, may be cached somewhere until an explicit TLBI that covers it completes.

Tags: ASID, VMID, nG

A TLB entry is tagged with the translation regime it belongs to, and within a regime with these labels:

TagSourceWidthNotes
ASIDTTBR0_EL1 or TTBR1_EL1, bits [63:48], chosen by TCR_EL1.A1 (also EL2&0 with HCR_EL2.E2H=1)8 or 16 bits (TCR_ELx.AS; supported size in ID_AA64MMFR0_EL1.ASIDBits)Only regimes with two VA ranges have ASIDs
VMIDVTTBR_EL2.VMID8 bits, or 16 with FEAT_VMID16 (v8.1) and VTCR_EL2.VS=1Tags EL1&0 entries, both stage 1 and combined, while stage 2 is in use or EL2 is enabled
Global / non-globaldescriptor nG (bit 11 of a block/page descriptor)1 bitnG=0 entries match any ASID; nG=1 entries match only the ASID they were walked with

Kernel mappings are global, so an ASID switch never has to flush them. User mappings are non-global. EL3 and non-VHE EL2 have one VA range and no ASIDs. A TLBI by VA in those regimes matches on VA alone.

Two related controls appear in bring-up:

  • TTBRn_ELx.CnP (FEAT_TTCNP, v8.2) states that this TTBR value points to tables shared by all PEs in the Inner Shareable domain that use the same ASID/VMID. An implementation may then share TLB entries between those PEs. Set it only when that is true on every PE. If one PE’s tables differ, that PE may use a translation another PE walked, and the architecture does not define which one wins.
  • HCR_EL2.FB forces TLBI (and some other maintenance) executed at EL1 to be broadcast across the Inner Shareable domain. A hypervisor sets it so that a vCPU migrated between physical PEs cannot leave stale local entries behind.

TLBI scopes

The operation name is TLBI <type><level>{IS|OS}{, Xt}. The type sets what is matched, the level sets which regime, and the suffix sets which PEs are affected.

TypeMatchesTypical forms
VAOne VA, for the given ASID, plus global entries for that VAVAE1, VAE2, VAE3
VAAOne VA, any ASIDVAAE1
VAL / VAALSame as VA/VAA, but only last-level (leaf) entries; walk-cache entries may surviveVALE1, VAALE1, VALE3
ASIDAll non-global entries for one ASIDASIDE1
VMALLAll EL1&0 entries for the current VMID (stage 1 only, or combined)VMALLE1
VMALLS12All stage 1 and stage 2 entries for the current VMID (EL2 only)VMALLS12E1
IPAStage 2 entries for one IPA, current VMID (EL2 only)IPAS2E1, IPAS2LE1
ALLEverything for the regimeALLE1 (all VMIDs), ALLE2, ALLE3

The Xt operand of a by-VA operation carries VA[55:12] in bits [43:0] and the ASID in bits [63:48]. With FEAT_TTL (v8.4), bits [47:44] carry a TTL hint giving the granule and the level of the leaf. A wrong TTL hint makes the invalidation imprecise, which is permitted to leave the real entry in place, so set it only when you know the level.

Domain suffix. With no suffix the operation affects only the executing PE, except that HCR_EL2.FB upgrades it at EL1. IS affects every PE in the Inner Shareable domain. OS (FEAT_TLBIOS, v8.4) affects the Outer Shareable domain. The OS forms matter on systems where several clusters or chiplets share an Outer but not an Inner Shareable domain. A broadcast TLBI becomes a DVM operation on the interconnect, and its completion becomes a DVM Sync issued by the DSB (see 8.3). Masters that take part in DVM, such as an SMMU, are invalidated too (11.5).

Range forms (FEAT_TLBIRANGE, v8.4). TLBI RVAE1IS, RVAAE1IS, RVALE1IS, RIPAS2E1IS and the related forms invalidate a range encoded as BaseADDR, TG (granule), SCALE, NUM and TTL. The range is (NUM+1) × 2^(5×SCALE+1) pages starting at BaseADDR. This replaces loops of hundreds of single-VA TLBIs, each of which is a separate DVM message, with one operation. Linux’s __flush_tlb_range() falls back to a full ASID flush above a threshold. Firmware rarely needs ranges, but a hypervisor unmapping stage 2 benefits a lot.

The full update sequence

To change or remove a live valid descriptor (a remap that needs break-before-make is covered in 9.2):

    // x1 = descriptor address, x2 = new descriptor value
    // x0 = (VA >> 12) | (ASID << 48)
    str     x2, [x1]          // 1. write the descriptor
    dsb     ishst             // 2. make the store visible to all walkers
    tlbi    vae1is, x0        // 3. invalidate cached copies on all PEs
    dsb     ish               // 4. wait for the invalidation to complete everywhere
    isb                       // 5. resynchronise this PE's own context

Each step has a reason:

  1. Store. Use a single 64-bit store, so that a walker sees either the old descriptor or the new one (7.2). If the descriptor may be updated by hardware (FEAT_HAFDBS), use an atomic read-modify-write instead (5.6).
  2. DSB ISHST. A TLBI is not ordered after earlier stores by a DMB. Only a DSB orders it. Without this DSB the invalidation can finish on another PE before that PE’s walker can observe the new descriptor. The other PE then walks again, reads the old descriptor, and caches it again after the invalidation. The ST variant is enough because only the preceding stores matter. This step assumes the walks are cacheable and coherent (TCR_ELx.IRGN/ORGN/SH match how the tables are mapped). If the walks are Non-cacheable, the store must also be cleaned to the PoC (DC CVAC) before the DSB.
  3. TLBI ...IS. This removes the entry from every TLB in the domain, including walk caches for a non-L form.
  4. DSB ISH. A TLBI completes only when a following DSB completes (7.6). For a broadcast TLBI, that means every targeted PE has removed the entry and every memory access those PEs made using the old translation has completed. The second part is the expensive one, and it is the reason for FEAT_XS (below). For OS forms use DSB OSH.
  5. ISB. The local PE may already have fetched, and translated, the instructions that follow, using the old entry. The ISB is a context synchronization event (7.8), and it makes later instructions be fetched and translated afresh. Other PEs do not need an ISB of their own for data accesses, because the DSB on the initiator already guarantees their old-translation accesses are complete. Instruction fetch on another PE is the cross-modifying-code problem of 8.6.

Invalid → valid needs no TLBI. Faulting translations are never cached, so there is no stale entry to remove. The sequence is store, DSB ISHST, ISB. The DSB makes the store visible to walks. Without FEAT_ETS2 the ISB is still needed, because an instruction already in the pipeline may have walked (and faulted) speculatively before the DSB. Linux’s __set_pte does exactly this for kernel mappings, and it also tolerates the window for user mappings by treating a spurious fault as “retry”.

FEAT_ETS2: when a DSB alone suffices

FEAT_ETS2 (ID_AA64MMFR1_EL1.ETS = 0b0010) tightens the ordering between explicit accesses and translation table walks. The original FEAT_ETS (ETS = 0b0001) has been retired from the Arm ARM and now gives no extra guarantee, so test for value 2 or higher. Its guarantees:

  • The VA of a load or store that is after a DSB in program order is not translated until the DSB completes. A new valid descriptor that was made visible before that DSB therefore cannot produce a spurious Translation, Access flag or Address size fault for a later data access, with no ISB needed.
  • A TLBI that affects only translations without execute permission is complete, for later data accesses, when the following DSB completes.
  • The ordering rules also cover walks that generate those faults, which closes the hole in the memory model behind the base-architecture ISB requirement.

None of this covers instruction fetch: anything that changes an executable mapping still needs the ISB. For the versions in which FEAT_ETS2 is permitted and mandatory, see DDI0487 section A2. Code that must run on older cores keeps the ISB unconditionally. It is cheap compared with the DSB.

Stage 2: the IPA pair

A hypervisor that changes a stage 2 descriptor must remove two kinds of entry: stage 2-only entries (IPA→PA) and combined entries (VA→PA, tagged with the VMID). Combined entries cannot be found by IPA, so:

    // at EL2, with VTTBR_EL2.VMID = target VMID; x0 = IPA >> 12
    str     x2, [x1]
    dsb     ishst
    tlbi    ipas2e1is, x0     // stage 2 entries for this IPA
    dsb     ish               // must complete before the next TLBI
    tlbi    vmalle1is         // combined/stage 1 entries for this VMID
    dsb     ish
    isb

The middle DSB matters. Without it, a walk on another PE that starts after VMALLE1IS has removed the combined entries could still use the stage 2 entry that is not yet invalidated, and create a fresh combined entry from the old IPA mapping. TLBI VMALLS12E1IS does both at once but discards the whole VMID’s stage 1 entries. Both IPA and VMALL operations act on the current VMID in VTTBR_EL2. Before invalidating for a guest that is not running, a hypervisor must load that guest’s VMID (and, under VHE, leave the HCR_EL2.{E2H,TGE}={1,1} context, because with TGE set an EL1 TLBI targets the EL2&0 regime). See 11.3.

FEAT_XS: memory that is slow to complete

Step 4 above is unbounded in principle. The DSB cannot complete until every access made with the old translation has completed. If one of those accesses is a Device read across a PCIe or CXL link, or to a slow peripheral, every TLB shootdown in the system waits for it. FEAT_XS (v8.7) adds an XS attribute that marks accesses which may take a long time to complete, together with ways to skip waiting for them:

  • The attribute. With FEAT_XS, Device memory (MAIR 0b0000dd00) has XS=1, and new encodings 0b0000dd01 give Device with XS=0. Normal Inner and Outer Write-Back memory has XS=0. 0b01000000 (Normal Non-cacheable) and 0b10100000 (Normal Write-Through) gain an XS=0 meaning that is UNPREDICTABLE without the feature. See the MAIR_ELx encoding table and 6.5.
  • TLBI ...nXS (for example TLBI VAE1ISNXS). It behaves as the normal form except that its completion does not wait for accesses with XS=1.
  • DSB <option>nXS (for example DSB ISHNXS). A DSB that does not wait for XS=1 accesses, so pairing it with a TLBI nXS keeps the whole sequence free of the slow traffic.
  • HCRX_EL2.FnXS (bit 3, requires FEAT_HCX). When 1, ordinary TLBI at EL1 behaves as the nXS form, and DSB at EL1 and EL0 behaves as DSB nXS. A hypervisor uses it to give an unmodified guest the faster behaviour when it knows that waiting for the guest’s XS accesses buys nothing. HCRX_EL2.FGTnXS (bit 4) decides whether the HFGITR_EL2 TLBI traps also apply to the nXS forms.

Using nXS is a correctness claim. You are asserting that nothing after the sequence depends on XS=1 accesses made through the old mapping having finished. For a device mapping being torn down, that is usually false.

Validation note: Test shootdown by having N PEs on different clusters (and chiplets) spin reading a canary VA while one PE remaps it from PA1 to PA2 with the sequence above, then writes a flag. Any read of PA1’s pattern after the initiator’s final DSB ISH is a failure: either DVM delivery or completion is broken, or the sequence is wrong. Run negative controls by deleting step 2 or the middle stage 2 DSB, and confirm the test can detect stale data. On the observers, L1D_TLB_REFILL (0x05) and DTLB_WALK (0x34) should rise after each shootdown. If they do not, the entry was never invalidated. Measure the initiator’s DSB latency across dies to obtain the DVM Sync cost that 17.5 budgets for.

Bring-up note: Some cores have TLBI errata in which the architected sequence is not sufficient (for example Cortex-A76 erratum 1286807, where a translation change can lead to a read-after-read ordering violation; Linux’s ARM64_WORKAROUND_REPEAT_TLBI works around it by issuing the TLBI, a DSB ISH, and the TLBI again). Check the errata notice of every core and of the interconnect before signing off a shootdown test (1.3).

Checkpoint

Q9.1.1 A kernel unmaps a page with str xzr, [x1]; tlbi vae1is, x0; dsb ish; isb. Occasionally another PE still reads the old physical page long after the unmap returned. What is the most direct architectural explanation?

  • A. The final ISB only synchronises the local PE, and the other PE needed its own ISB
  • B. VAE1IS misses global entries, so VAAE1IS was required
  • C. Without a DSB between the store and the TLBI, the invalidation can complete on the other PE before its walker sees the zeroed descriptor, so it walks again and re-caches the old translation
  • D. The TLBI needs the OS suffix because the store went to Outer Shareable memory
Answer

C. TLBI is ordered after earlier stores only by a DSB. Without DSB ISHST the old descriptor can still be what walkers read after their entries are removed. Option A is tempting, but the initiator’s DSB ISH already guarantees that the other PE has finished using the old translation for data accesses, and no remote ISB is needed for that. VAE1IS does match global entries for the VA, and the TLBI domain is not chosen by the descriptor’s memory attributes.

Read more: Arm ARM (DDI0487), TLB maintenance requirements and the ordering of TLB maintenance instructions

Q9.1.2 A hypervisor changes a stage 2 descriptor and issues TLBI IPAS2E1IS; TLBI VMALLE1IS; DSB ISH; ISB, with no DSB between the two TLBIs. What can go wrong?

  • A. A walk on another PE after the VMALLE1IS can still hit the not-yet-invalidated stage 2 entry and build a new combined entry from the old IPA→PA mapping
  • B. Nothing: the final DSB completes both TLBIs, so their order does not matter
  • C. VMALLE1IS also invalidates stage 2 entries, which makes the IPA TLBI redundant, so only performance is lost
  • D. The IPA operation is UNDEFINED unless it is followed directly by a DSB
Answer

A. The final DSB guarantees both operations complete, but not that the IPA invalidation completes before the combined entries are removed. In the gap a fresh combined entry can be created from the stale stage 2 entry, and it survives. VMALLE1IS affects stage 1 and combined entries, not stage 2-only entries. That is why the IPA form exists.

Read more: Arm ARM (DDI0487), TLBI IPAS2E1IS and the stage 2 maintenance sequence

Q9.1.3 Firmware on a core without FEAT_ETS2 writes a new valid descriptor for a previously unmapped VA, executes DSB ISHST, and then immediately loads from that VA. It occasionally takes a Translation fault. What is the minimal correct fix?

  • A. Add TLBI VAE1 after the DSB to evict the cached invalid entry
  • B. Replace DSB ISHST with DMB ISH
  • C. Clean the descriptor to PoC with DC CVAC, whatever the walk attributes
  • D. Add an ISB after the DSB
Answer

D. Faulting translations are never cached, so there is nothing to invalidate. Without ETS2, the load can be translated (and fault) speculatively before the DSB completes, and only a context synchronization event forces it to be retranslated afterwards. With FEAT_ETS2 the DSB alone would suffice for a data access. A DMB does not order walks, and a clean to PoC is needed only if walks are Non-cacheable.

Read more: Arm ARM (DDI0487), FEAT_ETS2 and the ordering of translation table walks

9.2 Break-before-make and FEAT_BBM

9.1 showed how to remove a stale TLB entry after a descriptor changes. Removal on its own is not enough when the old and new descriptors are both valid and differ in certain ways. Between the store and the end of the TLBI, a PE can hold the old entry and also walk the new descriptor, and so hold two different valid translations for the same VA. The architecture does not define which one is used, or whether both are. Break-before-make (BBM) closes that window: there is always an invalid state between the old valid entry and the new one.

What can go wrong without it

If more than one TLB entry matches an access, DDI0487 permits these outcomes (it classes them as CONSTRAINED UNPREDICTABLE):

  • A TLB conflict abort. This is a synchronous Data or Instruction Abort with fault status 0b110000. It is the best outcome because you can see it.
  • Use of either translation, possibly a different one for each access. A store may go to the old PA and the following load come from the new PA.
  • An amalgam of the two entries, for example the OA of one with the attributes of the other. Mismatched memory types or cacheability on one PA is then the mismatched-attribute case of 6.6, with possible loss of coherency.

Hardware AF/DBM updates make this worse. A PE writing the dirty state back into the old descriptor can overwrite the new one (5.6).

Which changes need BBM

The Arm ARM requires break-before-make when a valid descriptor is replaced by another valid descriptor and any of these change:

ChangeWhy
Output addressTwo PAs for one VA
Memory type, cacheability or shareabilityMismatched attributes for one PA, or two
Block size: block ↔ table, a different level, or the Contiguous bit set or cleared on live entriesOverlapping entries of different sizes, the classic source of TLB conflict aborts
Non-global → global (nG 1→0), which can create a global entry that overlaps non-global entries in some TLBLinux’s pgattr_change_is_safe() treats nG 0→1 as safe and refuses nG 1→0 on a live entry

The following can be changed live with only the 9.1 update sequence: access permissions (AP, UXN/PXN), AF set by software, DBM/dirty state, and software-defined bits. The architecture guarantees that the old and new entries are then equivalent apart from permissions, so whichever entry a PE uses, the result is still one of the two. Linux encodes this list in pgattr_change_is_safe(). TF-A’s xlat_change_mem_attributes() changes only permissions and execute-never, on page-granular regions, for the same reason.

The sequence

    // Replace live descriptor at [x1] (covering VA range [x3, x4)) with x2
    str     xzr, [x1]          // break: write an invalid descriptor
    dsb     ishst
    // invalidate every VA the old entry covered (see below)
    tlbi    vae1is, x0         // repeat for the range, or use TLBI RVAE1IS
    dsb     ish                // no PE can still hold or use the old entry
    str     x2, [x1]           // make
    dsb     ishst
    isb                        // see 9.1 for when FEAT_ETS2 lets you drop it

Points that matter:

  • Use a non-leaf TLBI (VAE1, not VALE1) when the entry being broken is a table descriptor. Walk-cache entries that point to the old next-level table must also go.
  • Cover the whole range of a block. By-VA invalidation of one address in a block removes the block entry, but cores may cache a block entry as smaller (“splintered”) TLB entries. Invalidating every page-sized step, a range TLBI, or a whole-ASID or VMID flush is the conservative choice. Linux flushes the full PMD or PUD range when it splits a huge page for this reason.
  • Use an atomic swap for the break if hardware updates dirty state (SWP or LDXR/STXR writing zero). The old value returned is the final AF and dirty state, which otherwise is lost.
  • Plan for the window. Any PE that touches the VA between break and make takes a Translation fault. A kernel’s fault handler retries. Firmware usually has no such handler, so the rule is: do not break a mapping that another PE (or this PE’s own instruction fetch, stack or exception vectors) may be using. If you must, park the other PEs, or switch to a separate set of tables via a trampoline (Linux’s __cpu_replace_ttbr1 runs from the idmap for exactly this reason).

Splitting and merging blocks

Split (block → table), level 0 BBM. First build the next-level table so that it reproduces the block’s OA and attributes exactly, and publish it with DSB ISHST. Then break the block descriptor, invalidate the block’s whole range, DSB ISH, write the table descriptor, DSB ISHST, ISB. After the split you can change individual pages with the 9.1 sequence. Linux needs this for rodata=full and for memory hot-remove, and the requirement is why it historically mapped the linear map at page granularity.

Merge (table → block). Break the table descriptor. Invalidate every VA in the range with a non-leaf TLBI (or a full ASID or VMID flush) so that both the leaf entries and any walk-cache entry pointing at the old table are removed. DSB ISH, then write the block descriptor, DSB ISHST, ISB. Free the old table page only after that DSB. The Contiguous bit follows the same rules. Setting or clearing it on 16 live entries (for the 4K granule) is a block-size change, so break all 16, invalidate, and rewrite them.

Security note: Freeing a translation table page before the TLBI that removes walk-cache references to it has completed is a use-after-free in hardware. A walker can still fetch “descriptors” from the reused page, whose contents may be attacker-controlled, and the result is an arbitrary mapping. This is why Linux defers page-table freeing (tlb_remove_table) and why a hypervisor’s stage 2 teardown must complete TLBI IPAS2E1IS/VMALLS12E1IS before reusing table pages.

FEAT_BBM levels

FEAT_BBM (v8.4) relaxes the rules for block-size changes only. Changes to OA, memory type and shareability always need BBM. The level is in ID_AA64MMFR2_EL1.BBM, bits [55:52]:

BBMMeaning
0 (level 0)Full break-before-make is required for every block-size change
1 (level 1)Adds the nT bit (bit 16 of block descriptors). Software uses an nT=1 block during a size change so that the change can be made without a fully invalid window. TLB conflict aborts remain possible. The required sequence is in DDI0487 under the support levels for changing block size
2 (level 2)A block-size change, with the OA, attributes and permissions unchanged, can be made directly (block ↔ table) without breaking coherency, ordering or uniprocessor semantics. nT is ignored. TLB conflict aborts may still be generated
3 (level 3, recent issues)As level 2, but the implementation does not generate TLB conflict aborts for such changes. Check the current DDI0487 issue for the exact definition

With level 2 or higher, the split above becomes: write the table descriptor (equivalent mapping) straight over the block, DSB ISHST, invalidate the block range, DSB ISH, ISB. You still need the TLBI. Level 2 only promises that the overlap between old and new entries is harmless, not that the old entry goes away by itself.

Handling a TLB conflict abort at level 1 or 2. The abort is routed to EL2 when stage 2 is enabled and the conflict comes from a block-size or Contiguous-bit change. Otherwise it goes to the EL that owns the stage 1 regime. The fix is a local invalidation, which removes the duplicate entries without a broadcast, followed by a retry:

conflict_abort:                 // ESR_EL1.DFSC == 0b110000
    tlbi    vmalle1             // or a local TLBI by the faulting VA
    dsb     nsh
    isb
    eret                        // retry the access

Linux took a stricter line. It relaxes BBM for kernel mappings only on CPUs known never to raise conflict aborts. At first this was “BBML2_NOABORT”, an MIDR allow-list, because some cores did not advertise their level correctly in the ID register. In 2026 patches it is being reframed as detection of BBM level 3 or higher from ID_AA64MMFR2_EL1.BBM, with an allow-list kept for cores that implement the behaviour but do not advertise it.

Bring-up note: In early firmware, the usual BBM bug is an mmap_add_dynamic_region()-style remap, or a “change this 2 MB block to Device” helper, run while a secondary core is already executing from, or accessing, the same block. It usually shows up as a sporadic Translation fault on the secondary core (the break window), or, on cores that detect the overlap, a fault-status 0b110000 abort. If you see a TLB conflict abort on a core whose BBM field reads 0, a block-size change was done without BBM.

Checkpoint

Q9.2.1 Firmware must change a live 4 KB page from Normal Write-Back to Device-nGnRE (same PA) while other cores may access it. Which approach is architecturally correct?

  • A. Overwrite the descriptor with the new AttrIndx, then DSB ISHST; TLBI VAE3IS; DSB ISH; ISB, because the PA is unchanged
  • B. Break the mapping, invalidate and complete, write the new descriptor, and ensure no other core accesses the page during the window (plus the cache maintenance that the memory-type change needs)
  • C. Overwrite it directly if ID_AA64MMFR2_EL1.BBM reads 2
  • D. Set nT=1 in the new descriptor and overwrite it directly
Answer

B. A memory-type change always needs break-before-make. FEAT_BBM levels relax only block-size changes, so C and D do not apply. Option A is the tempting one: the PA is the same, but two live entries with different memory types for one PA are a mismatched-attribute alias. Dirty lines from the Write-Back mapping must also be cleaned and invalidated to the PoC before Device accesses rely on memory (see 6.6).

Read more: Arm ARM (DDI0487), Using break-before-make when updating translation table entries

Q9.2.2 A kernel merges 512 page mappings into one 2 MB block. It breaks the table descriptor, issues TLBI VALE1IS for each page, DSB ISH, writes the block descriptor, and frees the old level 3 table. What is wrong?

  • A. Nothing. Every page was invalidated before the block was written
  • B. It should have used TLBI VAAE1IS, because block entries are always global
  • C. The block descriptor must be written before the table is broken, so that the range is never unmapped
  • D. VALE1IS invalidates only leaf entries, so a walk-cache entry that points to the freed table may survive and be used for a later walk
Answer

D. The broken entry was a table descriptor, and walk caches may hold that pointer. Last-level invalidation does not remove it, so a walker can later read the freed page as a level 3 table. Use VAE1IS (or a range or ASID flush), and free the page only after the DSB. Option C describes “make before break”, which is exactly what creates conflicting entries.

Read more: Arm ARM (DDI0487), TLB maintenance instructions, leaf-only (*L*) forms and translation table walk caching

Q9.2.3 On a core with ID_AA64MMFR2_EL1.BBM = 2, a guest kernel splits a block into a table without an invalid step, and occasionally takes a fault with status 0b110000. What does this indicate?

  • A. Expected level 2 behaviour. Conflict aborts remain permitted, and the handler should do a local TLBI and retry (if stage 2 is enabled, the abort may be routed to EL2)
  • B. A hardware bug, because level 2 forbids TLB conflict aborts
  • C. The table descriptor had different attributes from the block. Level 2 rejects these with a conflict abort, and it does not report conflicts for equivalent mappings
  • D. The guest forgot the nT bit, which level 2 requires on the new table descriptor
Answer

A. Level 2 guarantees that the overlap does not break coherency, ordering or uniprocessor semantics, but it still permits conflict aborts. That is why Linux additionally requires “no-abort” behaviour (BBM level 3, or an allow-list) before relaxing BBM. nT is ignored at level 2. Changing attributes during a split is not covered by level 2 at all, so its outcome is not a defined “rejection”.

Read more: Arm ARM (DDI0487), Support levels for changing block size; ID_AA64MMFR2_EL1.BBM

9.3 Turning the MMU and caches on

Enabling the MMU is one write to SCTLR_ELx, but that write switches how the next instruction is fetched and how every data access is typed, and it starts a walker that reads memory written while the caches were off. Most “dead after SCTLR.M=1” failures (18.3) come down to a short list of rules in this section.

What reset gives you

  • SCTLR_ELx.{M,C,I}. These reset to 0 at the highest EL on a cold reset, and many other fields are UNKNOWN. Write the whole register early, not just the bits you care about (17.1, 17.2).
  • Caches. Whether reset invalidates the caches is IMPLEMENTATION DEFINED. Arm’s Armv8-A cores invalidate their caches in hardware at reset, so firmware for them does no set/way invalidation at cold boot (some Armv7 cores did need it). Read the TRM of your core, and of any system cache, rather than assuming. If software invalidation is needed, it is a set/way loop over the local levels only, before any cacheable access (8.8).
  • TLBs. Hardware invalidation at reset is also implementation-specific. Even when it happens, a later boot stage inherits TLB entries from an earlier stage that ran with the MMU on, or from before a warm reset. Always issue a local TLBI ALLE3 (or ALLE2/VMALLE1) before enabling. It is cheap.
  • Memory types with the MMU off. Data accesses are Device-nGnRnE, and instruction fetches are Normal (cacheable if SCTLR.I=1). This is why early C code faults on unaligned accesses and DC ZVA (6.5).

Register write order, and the two ISBs

    // Tables already built and visible; x0=MAIR, x1=TCR, x2=TTBR0
    tlbi    alle3
    msr     mair_el3, x0
    msr     tcr_el3, x1
    msr     ttbr0_el3, x2
    dsb     ish                 // table stores and the TLBI complete
    isb                         // MAIR/TCR/TTBR visible to the MMU
    mrs     x3, sctlr_el3
    orr     x3, x3, #(1 << 0)   // M
    orr     x3, x3, #(1 << 2)   // C
    orr     x3, x3, #(1 << 12)  // I
    msr     sctlr_el3, x3
    isb                         // later instructions fetched and executed translated

MAIR, TCR and TTBR are not ordered among themselves. The MMU reads them indirectly, and an indirect read is guaranteed to see a direct write only after a context synchronization event (7.8). Because one ISB makes all three visible together, the order in which they are written does not matter. What matters is that the ISB comes between them and the SCTLR write.

ISB before SCTLR.M. The write to SCTLR is a direct write to a different register, and it is not ordered with the earlier TCR/TTBR writes as the MMU sees them. Without the ISB, the PE may start translating with the old (reset, UNKNOWN) TCR or TTBR values. The DSB ISH before it makes sure the walker can see the translation tables and that the TLBI has completed, because a TLBI is complete only after a DSB.

ISB after SCTLR.M. Instructions after the MSR may already have been fetched, and possibly executed speculatively, under the old context. After the ISB every instruction is fetched through the new translation and the new memory types. Without it, a few instructions run in an undefined mixture of contexts. That is harmless only by luck.

Compare TF-A’s enable_mmu_direct_el3 (in lib/xlat_tables_v2/aarch64/enable_mmu.S), the worked example for this section. It asserts that SCTLR.M is still 0, issues TLBI ALLE3, loads MAIR, TCR and TTBR0 from mmu_cfg_params, and then runs dsb ish; isb. Next it sets SCTLR.{WXN,C,M}, clearing C again if the caller passed DISABLE_DCACHE, and finishes with isb. The I-cache is enabled separately, earlier, in el3_entrypoint_common. Because the TLBI is local, any DSB domain would complete it. ISH is there for the table stores, which matters if another PE built or will share the tables.

Identity-mapping the trampoline

The instruction after the second ISB is fetched at PC+4 as a VA. So the code that enables the MMU must be mapped at VA == PA, or at least the page that contains it must be. At EL3, TF-A simply maps all of its images flat, so the issue never arises. If you want the image to run at a different VA:

  1. Map the enable routine’s page both at its PA (the identity, or “idmap”) and at the target VA.
  2. Enable the MMU in the idmap page, then branch absolutely to the target VA (ldr x0, =target; br x0).
  3. Optionally remove the idmap afterwards, with the 9.1 sequence.

Linux does exactly this with .idmap.text, using TTBR0 for the idmap and TTBR1 for the kernel. At EL3 and in non-VHE EL2 there is only TTBR0, so both mappings must live in one table. Keep the stack and the exception vectors (VBAR_ELx) mapped across the switch as well. Recursive exceptions at VBAR immediately after enabling (18.3) usually mean the vector table is not mapped, or is mapped XN.

The classic failures

SymptomCauseCheck
Level 0 (or starting-level) Translation fault on the first fetch after M=1Wrong T0SZ/TG0, so the walk starts at a different level from the one the tables were built for, or TTBR0 points to the wrong pageRemember that the TG0 and TG1 encodings differ (TG0: 00 = 4K, 01 = 64K, 10 = 16K; TG1: 01 = 16K, 10 = 4K, 11 = 64K), and recompute the starting level (5.3)
Address size faultTCR.PS/IPS smaller than the table or output addressesID_AA64MMFR0_EL1.PARange vs PS
Garbage walks or random faults with the caches on, correct on FVPTables written with the MMU off (Non-cacheable stores) while stale lines for the same addresses, left by an earlier stage or a previous run, sit in the cache. The walk, which is cacheable per TCR.IRGN0/ORGN0, hits the stale lineInvalidate the table region to the PoC (DC IVAC) before building it, so that no stale dirty line is evicted over the new entries, and again after, to drop any line allocated (speculatively, say) in between. Alternatively the previous stage cleans and invalidates the region before handing over. Linux’s head.S invalidates the page tables it built with the MMU off
Data written before enabling the cache “disappears” afterwardsThe same stale-line effect, for data (6.6)Invalidate (not clean) the region by VA to the PoC (DC IVAC) before enabling the cache. A clean would write a stale dirty line back over the new data
Works with a debugger single-stepping, fails at speedA missing ISB, before or after the SCTLR writeRead the sequence above against the disassembly. A compiler-generated MSR in C needs explicit isb()
Permission fault on the first fetchSCTLR.WXN=1 with writable code pages, or code mapped XNBefore enabling, decode the leaf descriptors by hand: with SCTLR.M=0 an AT instruction reports the flat MMU-off mapping and does not walk your tables. After enabling (from a mapped page), AT S1E3R and PAR_EL1 show the translation, though AT does not check execute permission (5.9)

The stale-line case is the one FVP hides, because cache state is not modelled by default (18.4). Turn on cache modelling, or test on RTL or silicon, before you trust a boot path that writes tables with the MMU off.

Bring-up note: Once the MMU is on, the PE may speculatively fetch and prefetch from any address mapped as Normal and executable, and may speculatively read or prefetch anything mapped as Normal. These accesses are not limited to what the code actually touches. A large flat block (say 1 GB of “DRAM”) that also covers a PA hole, untrained DDR, a Secure-only carve-out or an unclocked memory can produce asynchronous SErrors or bus hangs with no instruction to blame. Map only what exists and is ready. Map MMIO as Device, which data accesses never read speculatively, and XN, so that instruction fetch cannot touch it either. Leave holes unmapped, and remap DDR as Normal only after training. The MMU-off case, where instruction fetch is Normal everywhere, and the speculation details are covered in 14.2.

Validation note: A minimal MMU-on directed test: build tables with the MMU off, fill the table region’s cache lines with a poison pattern beforehand (cacheable alias, no clean), then enable. A correct boot path survives, and one that omits the invalidate faults or walks garbage. Check the outcome with PAR_EL1 from AT S1E3R on a few VAs, and with DTLB_WALK (0x34) counts, which show whether the walks happen at all. Run it on silicon or with FVP cache modelling on.

Turning it off again

Disabling is the reverse transition, and it reintroduces the stale-line problem in the other direction: the next stage, running with caches off, must find its data at the PoC, and no new dirty lines may be created after the last clean. The usual order is to clear M and C together, ISB, and then clean and invalidate to the PoC the data the next stage relies on (a clean done before clearing C is undone by any later cacheable write, including stack pushes). The code doing it must be identity-mapped. Power-down ordering and set/way usage are covered once, in 8.8.

Checkpoint

Q9.3.1 An engineer removes the isb between msr ttbr0_el3, x2 and the msr sctlr_el3 that sets M, reasoning that “MSRs to system registers execute in order”. Why is that reasoning wrong?

  • A. MSR instructions can be reordered by the assembler unless separated by an ISB
  • B. The ISB is needed to complete the earlier TLBI ALLE3
  • C. The MMU reads TCR and TTBR indirectly, and those reads are guaranteed to see the new values only after a context synchronization event, so translation could start with the old values
  • D. The ISB makes the translation table stores visible to the walker
Answer

C. Program order of direct writes says nothing about when the walker, an indirect reader, sees them. An ISB is the context synchronization event that guarantees it. Option B is tempting, but TLBI completion and table-store visibility (D) come from the DSB, not the ISB. The sequence needs both.

Read more: Arm ARM (DDI0487), Synchronization requirements for AArch64 System registers; context synchronization event

Q9.3.2 BL2 builds its translation tables with the MMU and D-cache off, then enables both. It works on FVP but walks garbage on silicon after a warm reset. Which fix addresses the root cause?

  • A. Add an extra ISB after setting SCTLR.M
  • B. Invalidate the table region to the PoC by VA before and after building the tables, so that cacheable walks cannot hit stale lines left from before the reset
  • C. Mark the walks Inner Shareable in TCR.SH0
  • D. Replace TLBI ALLE3 with TLBI ALLE3IS
Answer

B. The stores went to memory (Non-cacheable with the MMU off), but older cache lines for the same addresses survived the warm reset, and the cacheable walk hits them. FVP does not model cache contents by default, which is why it passed. The invalidate before building stops a stale dirty line from being evicted over the new entries. The TLB is not the problem, so D does nothing, and an ISB orders context, not data.

Read more: Arm ARM (DDI0487), Behavior of caches at reset; translation table walk cacheability and TCR_ELx.IRGN0/ORGN0

Q9.3.3 Firmware maps 0x8000_0000–0xFFFF_FFFF as one 2 GB range of Normal Write-Back, executable memory. Only the first 1 GB is DRAM, and the rest is a PA hole. Shortly after the MMU is turned on, an SError is taken and no faulting instruction can be found. What is the most likely cause?

  • A. Speculative instruction fetch or prefetch into the mapped hole, which returns a bus error reported asynchronously
  • B. The ISB after SCTLR.M was missing
  • C. A TLB conflict abort between two block entries
  • D. A missing DSB before the SCTLR write
Answer

A. Normal executable mappings permit speculative accesses that the program never makes. A hole that returns an error response produces an SError with no precise instruction. Map only real memory, and use Device/XN for MMIO. A TLB conflict abort is synchronous and has its own fault status, and missing barriers give synchronous translation symptoms, not an SError.

Read more: Arm ARM (DDI0487), Normal memory and speculative accesses; see also 14.2

Part 10: Atomics and synchronization

Prerequisites: 6.2 Normal and Device memory, 6.5 MAIR_ELx and AttrIndx, 7.2 Single-copy and multi-copy atomicity, 7.7 Acquire/release as one-way barriers, 8.3 Coherency at system scale.

If you already know: how LDAXR/STLXR loops and CASAL are built and ordered, skim 10.1 and 10.2 for the monitor-clearing and near/far rules, and read 10.3 and 10.4 in full.

Why this matters for bring-up/validation: the first lock in firmware runs before the MMU and caches are on, across chiplets and next to non-coherent controllers, so it is the first place where the architecture’s “IMPLEMENTATION DEFINED” fine print about atomics turns into a hang.

Part 7 says what ordering an access gets. This part is about indivisibility: which read-modify-write operations the architecture makes atomic, where that guarantee comes from in hardware, and what it depends on. Exclusives (10.1) get their atomicity from a monitor that watches a reservation granule. That is why the memory type and the master matter, and why an exclusive on Device or Non-cacheable memory is a system question rather than a CPU question. LSE atomics (10.2) move the operation into the memory system: it is performed in the local cache (“near”) or at the interconnect’s home node (“far”), with the same architectural ordering either way.

10.3 covers the 128-bit and 64-byte forms (LDXP/STXP, CASP, LSE2, LSE128, LRCPC3, LS64) and the alignment-fault rules that decide whether an access is atomic or faults. 10.4 puts it all together: the event register and WFE, how locks are built from these primitives, why TF-A falls back to a bakery lock when caches are off, and how to synchronise with SCP/MCP/RSE controllers that have no coherent atomics at all.

10.1 Exclusives

An exclusive pair (LDXR … STXR) does not lock anything. It is an optimistic protocol: the load marks an address, the store succeeds only if nothing could have written the marked location in between, and software retries on failure. All the guarantees come from exclusive monitors, which are small state machines with two states, Open Access and Exclusive Access. Everything that is IMPLEMENTATION DEFINED about exclusives comes down to where these monitors live and what they can see.

The instructions

InstructionEffectOrdering
LDXR{B,H}, LDXR Wt/XtLoad, and mark the address (local and, if shareable, global monitor)none
LDAXR…Same, with acquire (RCsc)acquire
STXR Ws, Wt, [Xn]Store if the monitors permit; Ws = 0 on success, 1 on failurenone
STLXR…Same, with releaserelease
LDXP/STXP, LDAXP/STLXPPair forms, see 10.3as above
CLREXClear the local monitor to Open Accessnone

A canonical atomic increment looks like this:

// x0 = address of a 64-bit counter
1:  ldaxr   x1, [x0]        // load and mark, acquire
    add     x1, x1, #1
    stlxr   w2, x1, [x0]    // try store, release; w2 = status
    cbnz    w2, 1b          // lost the reservation, retry

The status register Ws must not be the same register as Xt or Xn. Those combinations are CONSTRAINED UNPREDICTABLE. A store-exclusive always clears the local monitor, whether it succeeds or fails, so a failed STXR must go back to the LDXR, not to itself.

The architecture does not guarantee that a successful STXR means “no other agent wrote the location”. It guarantees the reverse: if another observer wrote the marked granule after the LDXR, the STXR fails. Spurious failures are always permitted. That is why every exclusive sequence is a loop, and why forward progress is a separate question (below).

Local and global monitors

  • The local monitor belongs to one PE. It tracks that PE’s own LDXR and is enough for locations that are Non-shareable. It may be tag-based (an address is recorded) or just a single flag.
  • The global monitor tracks marked addresses on behalf of all PEs for Shareable locations. A store by any observer to a granule marked for PE n moves PE n’s global monitor to Open Access.

For Shareable locations a STXR succeeds only if both the local and the global monitor are in Exclusive Access for that address.

In a modern coherent system the “global monitor” for Normal Inner/Outer Write-Back Shareable memory is usually not a separate block. It is built from cache coherency. The PE holds the line in a Unique state between LDXR and STXR. If a snoop takes the line away (another master wants to write it), the monitor is cleared. This is non-architectural, but it is the right mental model for why exclusives on cacheable memory “just work” and scale with the coherency protocol. On CHI, the Exclusive flag on ReadShared/CleanUnique lets the home node act as a point-of-serialisation monitor when the line is not held Unique (see 8.3).

Bring-up note: on a multi-chiplet SoC, check that the chiplet-to-chiplet link (CHI C2C or a proprietary bridge) carries the Exclusive attribute and the snoops that clear monitors. If it does not, STXR from cores on different dies can both succeed on the same lock. That shows up as a mutual-exclusion failure only under cross-die contention, never in single-die testing.

The exclusives reservation granule

The monitors do not track bytes. They track an Exclusives Reservation Granule (ERG), an aligned block whose size is IMPLEMENTATION DEFINED. CTR_EL0.ERG (bits [23:20]) reports log2 of the maximum granule size in words. Valid values range from 4 words (16 bytes) to 512 words (2 KB). The value 0 means “no information” (deprecated in current issues), and software must then assume 2 KB.

Consequences:

  • A store by another PE anywhere in the granule may clear your reservation, even if it does not touch your bytes. Two hot lock words in one granule cause livelock-like retry storms. Pad locks to at least the ERG. Padding to the cache line size is the common practice, and is sufficient when ERG ≤ line size, which is true on mainstream cores but not guaranteed. Read CTR_EL0 to be sure.
  • A STXR to a different address in the same granule as the LDXR, or of a different size, is CONSTRAINED UNPREDICTABLE in whether it succeeds. Always pair the load and store to the same address and size.

What clears a monitor

EventEffect
STXR/STLXR by the same PE (pass or fail)Clears the local monitor
CLREXClears the local monitor
Store by another observer to the marked granule (Shareable)Clears that PE’s global monitor
Exception return (AArch64)Clears the local monitor
Taking an exceptionDo not rely on the monitor state afterwards. Software must assume it may be lost
Eviction of the marked line, in cache-based implementationsMay clear the monitor (IMPLEMENTATION DEFINED)
Non-exclusive store by the same PE to the marked granuleNot guaranteed to clear the local monitor
Cache maintenance, TLBI, a translation-table change affecting the addressMay clear the monitor

Two practical rules follow from this table. First, a context switch does not need CLREX in AArch64, because the exception return already clears the local monitor. A preempted LDXR therefore cannot pair with a STXR in another thread. Second, because non-exclusive stores by the same PE are not guaranteed to clear the monitor, CLREX is still the tool when software abandons a sequence and does something else that relies on the monitor being open. An example is an emulator or a hypervisor that has emulated a store.

Security note: a reservation cannot leak across an exception boundary, because exception return clears the local monitor. The global monitor is per PE, not per world, so a Secure and a Non-secure thread on the same PE are separated by the ERET, not by the monitor. Lock words shared across worlds must still be in memory that both worlds map with the same attributes (see 6.6).

Forward progress

The architecture guarantees that an exclusive loop eventually succeeds only if software follows the usage restrictions in DDI0487, Load-Exclusive and Store-Exclusive instruction usage restrictions. In summary:

  • no explicit memory accesses, cache maintenance or TLBI, DC ZVA, or system-register writes between the LDXR and the STXR;
  • no exceptions taken in between (as far as software can control this);
  • the code between them is short, and the LDXR/STXR access the same address and size.

Break these rules and the loop may never terminate. The classic case is a debugger single-stepping through the sequence: each step takes a debug exception, the return clears the monitor, and the STXR fails forever. Debuggers work around it by stepping over the whole sequence as a unit (GDB does this for AArch64), and Linux kprobes refuse to place probes inside one. LSE atomics (10.2) avoid the problem entirely.

Which memory types and masters

This is where the “it works on my FVP” bugs come from.

  • Normal, Inner and Outer Write-Back, Inner or Outer Shareable: exclusives are architecturally supported between PEs in the same shareability domain. The coherency protocol provides the global monitor.
  • Normal Non-cacheable, and Device: the global monitor must be an actual piece of hardware in the interconnect or the memory controller (an “exclusive access monitor”, like the AXI exclusive monitor in a DMC or an SRAM controller). Whether one exists for a given address range is a property of the system, so the architecture makes support IMPLEMENTATION DEFINED. If the target does not support exclusives, the behaviour is also IMPLEMENTATION DEFINED. Permitted outcomes include a Data Abort (for example DFSC 0b110101, Unsupported Exclusive or Atomic access, or an External abort), or STXR reporting failure. Some interconnects report “OKAY” instead of “EXOKAY” and the store always fails, so a lock loop spins forever.
  • Device memory exclusives are a further special case. Many systems simply do not support them, and portable firmware never relies on them.
  • Other masters: the global monitor only sees writes that pass through the point it monitors. A DMA master or an SCP writing through a non-coherent path to the same SRAM may not clear a PE’s reservation at all. For cacheable memory, a non-coherent master’s write is invisible to the cache-based monitor by definition. Exclusives are a mechanism for coherent PEs, not a cross-agent lock (see 10.4).

The reason the architecture cannot make Non-cacheable or Device exclusives mandatory is that the PE is not where the protection happens. For cacheable memory the PE’s own cache plus coherency enforce atomicity. For anything else, the request goes out on the bus and the target must implement the monitor. The architecture cannot require a property of an IP block it does not specify.

That is why “MMU off” matters: with SCTLR_EL3.M == 0, data accesses are Device-nGnRnE (6.5). An exclusive-based spinlock in early boot code is therefore relying on a system-level monitor that may not exist, which is why TF-A uses a different lock on its cache-off paths (10.4).

Validation note: for each memory region that firmware intends to lock in (DRAM, on-chip SRAM, a mailbox SRAM), run a directed test with the region mapped as Normal Write-Back, Normal Non-cacheable and Device. In each case, run an LDXR/STXR increment from two PEs and check the final count. Expected failure signatures are: a count lower than the number of increments (the monitor is missing, so both stores succeeded), a hang (the store always fails), or a synchronous Data Abort whose ESR_ELx.ISS.DFSC is 0b110101 or an external-abort code. On CMN-based systems, the interconnect PMU’s exclusive-access events confirm whether the transactions reached the home node with the Exclusive flag set.

Checkpoint

Q10.1.1 Two lock words, lockA at 0x8000_0000 and lockB at 0x8000_0020, are each taken with an LDAXR/STXR loop by different PEs. CTR_EL0.ERG reads 0b0100. Under heavy contention on both locks, throughput collapses even though the locks are independent. What is the best explanation?

  • A. LDAXR has acquire semantics and serialises all loads to the same cache line
  • B. The ERG is 16 bytes, so the two locks are in different granules and the problem must be elsewhere
  • C. The ERG is 16 words (64 bytes), so both locks share one reservation granule, and each PE’s stores clear the other’s reservation
  • D. The global monitor only tracks one address per system, so every exclusive in the system competes
Answer

C. ERG is log2 of the size in words: 0b0100 gives 16 words, which is 64 bytes. Both addresses fall in the same 64-byte aligned granule, so a STXR to one lock clears the reservation for the other, causing retry storms. B misreads the field as bytes. The global monitor is per PE, not one per system, so D is wrong.

Read more: Arm ARM (DDI0487), CTR_EL0.ERG; Exclusive access instructions and Shareable memory locations

Q10.1.2 BL31 warm-boot code runs with SCTLR_EL3.M == 0 and uses an LDAXR/STXR spinlock in on-chip SRAM. On silicon, one core spins forever in the loop while no other core holds the lock. The same code passes on the FVP. Which explanation is most consistent with the architecture?

  • A. With the MMU off the accesses are Device-nGnRnE, and the SRAM path has no exclusive monitor, so the store never gets an exclusive-OK response and STXR always reports failure
  • B. The missing DSB after STXR keeps the store from completing, so the status register stays 1
  • C. The local monitor is disabled while the MMU is off, so LDAXR always marks Open Access
  • D. STXR needs a preceding CLREX on warm boot, because reset leaves the monitor in an UNKNOWN state
Answer

A. Exclusives on Device or Non-cacheable memory depend on a monitor at the target, and whether one exists is IMPLEMENTATION DEFINED (a system property). An always-failing STXR is a permitted outcome. The FVP models a monitor that the real SRAM controller may lack. B is wrong because the status register reports the monitor check, not completion. There is no architectural rule that disables the local monitor with the MMU off. A CLREX would only force failure, never fix it.

Read more: Arm ARM (DDI0487), Load-Exclusive and Store-Exclusive instruction usage restrictions; behaviour of exclusives on memory types other than Normal Write-Back

Q10.1.3 A kernel developer adds CLREX to the AArch64 context-switch path “so that thread B’s STXR cannot succeed using thread A’s reservation”. Why is this unnecessary on AArch64 for the case where the switch goes through an exception?

  • A. STXR checks the thread ID stored in TPIDR_EL0 against the reservation
  • B. Taking any exception always clears both the local and global monitors
  • C. The global monitor is cleared by TLBI on the ASID change
  • D. The exception return that resumes thread B clears the local monitor, so B’s STXR without its own LDXR fails
Answer

D. In AArch64, an exception return clears the local monitor, so a reservation cannot survive into the resumed context. B overstates the rule: software must not rely on what taking an exception does to the monitor, and the architecture does not make exception entry clear the global monitor, which is cleared by stores to the granule and the owner’s own exclusive operations (and possibly by IMPLEMENTATION DEFINED events such as eviction). Monitors know nothing about TPIDR_EL0 or ASIDs.

Read more: Arm ARM (DDI0487), Clearing the local monitor; exception return behaviour

10.2 LSE atomics (FEAT_LSE)

FEAT_LSE (Large System Extensions) adds single-instruction read-modify-write operations. It is mandatory from v8.1: ID_AA64ISAR0_EL1.Atomic (bits [23:20]) must read 0b0010 (LSE) or 0b0011 (LSE plus LSE128). The motivation is in the name. On a large system, an LDXR/STXR loop must pull the line into the requester’s cache in a Unique state, and under contention the line moves between cores while most STXRs fail. A single atomic instruction can instead be sent to the data. It is performed once, at a point where the line is already serialised, and it cannot fail and retry.

The instruction families

FamilyOperation (old = value in memory)Returns
CAS Ws, Wt, [Xn]if old == Ws then write Wt; Ws := oldold value in Ws
CASP2×32 or 2×64-bit compare-and-swap of a register pair (10.3)old pair
SWP Ws, Wt, [Xn]write Ws; Wt := oldold value
LDADD Ws, Wt, [Xn]write old + Ws; Wt := oldold value
LDCLRold AND NOT Ws (bit clear)old value
LDEORold XOR Wsold value
LDSETold OR Wsold value
LDSMAX/LDSMINsigned max/minold value
LDUMAX/LDUMINunsigned max/minold value

Every form except CASP has B and H (byte, halfword) variants, and all have 32/64-bit register forms. There is no LDSUB (use LDADD with a negated operand) and no LDAND (use LDCLR with an inverted mask).

ST<op> (STADD, STCLR, STSET, …) are aliases, not separate instructions. They are LD<op> with Rt = XZR/WZR and no acquire (A == 0). The disassembler prints STADD only when both conditions hold. The point of the alias is to tell hardware that the old value is not needed, so the operation can be posted like a store (“fire and forget”). This matters for far atomics, below.

Ordering variants

Each instruction has four ordering forms, written as a suffix before the size letter: none, A (acquire), L (release), AL (acquire and release), for example LDADDAL, CASAH, SWPLB. The acquire is RCsc acquire, the same as LDAR, and the release is the same as STLR (7.7).

Two rules are easy to get wrong:

  1. Acquire disappears with a zero-register destination. DDI0487 states that “if the destination register is not one of WZR or XZR, LDADDA and LDADDAL load from memory with acquire semantics”. It is the same for CASA/CASAL when Rs is the zero register. LDADDAL wzr-style code therefore has release semantics only. If you need a full barrier around a value-discarding atomic, use a real destination register or add a DMB.
  2. A failed CAS need not write. If the comparison fails, the architecture permits the old value to be written back but does not require it. Do not reason about CASL’s release ordering on the failure path, because there may be no store to which it attaches. The acquire on the read of a CASA/CASAL applies whether or not the compare succeeds, which is what lets a failed CASA in a lock loop see the critical-section writes of the previous owner.

When the operation is performed, the read and the write are a single atomic access. No other write to the location can come between them in the coherence order. For a CAS, this holds only when the write is performed. A CAS whose Rs and Rt are the same register can never change memory.

Atomics are explicit memory accesses. A DMB orders them like the loads and stores they contain. For a value-returning atomic, the read part creates address, data and control dependencies through the destination register in the usual way (7.4). An ST<op> returns nothing, so it cannot head a dependency chain.

Alignment and memory types

LSE atomics must be naturally aligned. Without FEAT_LSE2, a misaligned atomic always takes an Alignment fault, regardless of SCTLR_ELx.A. With FEAT_LSE2, an access that stays inside an aligned 16-byte quantity is allowed (10.3).

Memory-type support has the same shape as for exclusives (10.1):

  • Normal Inner/Outer Write-Back Shareable is supported.
  • Non-cacheable and Device are IMPLEMENTATION DEFINED, because the target (interconnect home node, memory controller or peripheral) must perform the atomic. An unsupported target may produce a Data Abort with DFSC 0b110101 (Unsupported Exclusive or Atomic access) or an External abort.

With the MMU off, data accesses are Device-nGnRnE (6.5), so a CASA-based lock in early boot is just as non-portable as an exclusive one.

Near and far atomics

Architecturally, an atomic is just an atomic. Where it is executed is an implementation choice, and the choice is invisible except in performance and in which faults or errors are possible.

  • Near atomic. The PE obtains the line in a Unique state in its own L1 or L2, performs the ALU operation locally, and leaves the line dirty in its cache. This is the same traffic as a successful exclusive pair, without the failure window. It is the right choice when the same core will touch the location again soon.
  • Far atomic. The PE sends the operation to the interconnect as an atomic transaction. In AMBA CHI these are AtomicStore (no return, which is what ST<op> maps to), AtomicLoad (LD<op>), AtomicSwap (SWP) and AtomicCompare (CAS). The home node (HN-F, the point of coherency and serialisation for that address, usually alongside the system-level cache slice) performs the operation, after snooping out any cached copies. Alternatively, it forwards the operation to the subordinate (memory controller or device) if that is where the data lives. This is the right choice for a highly contended counter or lock, because the line stops moving between cores.

Which one a given core uses is IMPLEMENTATION DEFINED. Typical policies are: near if the line already hits Unique or Exclusive in L1, far otherwise. Some cores offer an IMPLEMENTATION DEFINED control (an IMP_CPUECTLR_EL1-style field) to force near or far, or to choose by memory type. Check the core TRM, and check that the interconnect supports far atomics at all. A CHI requester connected to an interconnect or bridge without atomic support must be configured to execute atomics near, or atomics to Non-cacheable memory will fault.

Ordering of far atomics

A far atomic gets exactly the same architectural ordering as a near one. The PE is responsible for this, not the interconnect:

  • For LD<op>A/CASA, later accesses cannot be performed before the returned value is available, which for a far atomic means a round trip to the home node.
  • For L forms, the PE must ensure that all earlier accesses are observed before the atomic is issued.
  • A plain STADD (an AtomicStore) can be posted. A later DMB orders it against later accesses, as for an ordinary store. A DSB waits for it to complete, which for a far atomic means the home node has performed it and responded.

The point to internalise is that “far” does not weaken anything. It only moves the point of serialisation. What changes in practice is latency: an LDADDAL performed far on a cross-chiplet address may take hundreds of nanoseconds, because the acquire waits for the round trip across CHI C2C (8.3).

Bring-up note: far atomics introduce a failure mode that exclusives do not have. The home node, or a CXL/C2C bridge behind it, must implement every atomic opcode, and an unsupported one comes back as a transaction error (an External abort, often an asynchronous SError for STADD). If a statistics counter in Non-cacheable shared memory starts producing SErrors only after the interconnect is reconfigured, check the near/far policy and the bridge’s atomic-support parameters first.

LSE versus exclusives

ExclusivesLSE
Can fail and retryyes (spuriously, too)no (CAS can fail the compare, but is still a single access)
Arbitrary operationyes (any code between)fixed ALU ops, or CAS-loop
Contended scalingpoor (line moves, retries)good, especially far
Debugger single-stepcan livelockfine
Can head a WFE waityes (LDXR arms the monitor)no, combine with LDXR (10.4)

Toolchains choose at build time (-march=armv8.1-a or +lse), or at run time with outline atomics (GCC -moutline-atomics, the default for AArch64 Linux targets since GCC 10.1), which tests HWCAP_ATOMICS. Firmware built with -march=armv8-a silently uses exclusives everywhere.

Validation note: a lost-update test is the most direct check of atomic correctness across the coherency fabric. N cores, each on a different cluster or chiplet, perform M LDADDALs each on one shared counter, then compare the total with N×M. Run it three ways: on a Write-Back line, on a Non-cacheable line, and with the near/far policy forced each way, if the core allows. A short count means the home node or a bridge broke atomicity. An SError or a DFSC 0b110101 abort means an unsupported target. Use the core PMU’s atomic or MEM_ACCESS events and the CMN PMU’s per-opcode request counters to confirm that the expected Atomic* transactions arrived at the HN-F (see 8.10).

Checkpoint

Q10.2.1 A developer replaces LDADDAL x1, x2, [x0] with STADDL x1, [x0] because the old value is unused. The atomic increment marks the end of a producer’s critical section, which must be ordered before later reads in the producer. What changed?

  • A. Nothing: STADDL is an alias of LDADDAL with XZR as destination
  • B. The acquire semantics are lost, so later loads may now be performed before the atomic. STADDL is LDADDL with XZR, which only has release semantics
  • C. The release semantics are lost, so earlier critical-section stores may be reordered after the atomic
  • D. The operation becomes non-atomic, because ST<op> forms are performed as a separate read and write
Answer

B. ST<op> aliases only exist for A == 0, so STADDL is LDADDL with a zero destination. It keeps the release, so C is wrong, but it never had acquire. Even LDADDAL with a zero destination loses its acquire. The operation is still a single atomic access, so D is wrong. If later reads must not pass it, keep a real destination register or add DMB ISH.

Read more: Arm ARM (DDI0487), LDADD, LDADDA, LDADDAL, LDADDL (STADD alias conditions)

Q10.2.2 On a CHI system, core 0 executes LDADDA w1, w2, [x0] and the core chooses to perform it far, at the home node. Which statement about its ordering is correct?

  • A. Far atomics are performed outside the PE, so acquire semantics only apply between PEs on the same home node
  • B. A far atomic is ordered only by a following DSB, because a DMB cannot observe interconnect-level operations
  • C. Later loads by core 0 cannot be performed until the old value returns from the home node, just as for a near atomic
  • D. Far atomics are only single-copy atomic with respect to other far atomics, not to ordinary stores from other cores
Answer

C. Where the atomic is performed is IMPLEMENTATION DEFINED and invisible to the memory model. The PE must provide the same acquire, which here means waiting for the response. The home node serialises all accesses to the line, including ordinary stores, which it handles by snooping, so D is wrong. DMB orders far atomics like any explicit access, so B is wrong. B confuses ordering with completion.

Read more: Arm ARM (DDI0487), Atomic memory operation instructions and the definition of Ordered-before; AMBA CHI (IHI0050), Atomic transactions

Q10.2.3 A lock-acquire loop is 1: mov w1, wzr; casa w1, w2, [x0]; cbnz w1, 1b. A reviewer argues that when the CASA fails the compare, it “performs no access, so it can’t synchronise with the previous owner’s STLR”. What is the correct response?

  • A. The read of a failed CASA still has acquire semantics, so once a CASA succeeds or reads the released value, the previous owner’s critical-section writes are visible. A failed compare also guarantees nothing is written in a way software can rely on
  • B. The reviewer is right, and a DMB ISH is needed after every failed CASA
  • C. The reviewer is right for CASA but not for CASAL, whose release covers the failure path
  • D. The reviewer is wrong because a failed CAS always writes the old value back, creating a store that orders the sequence
Answer

A. A CAS always reads, and the acquire applies to that read when Rs is not the zero register (here the destination is w1). The loop only exits on a successful CASA, which is an acquire read of the lock word written by the owner’s release. D states as mandatory something that is only permitted. C is backwards: release attaches to the write, and on failure there may be no write.

Read more: Arm ARM (DDI0487), CAS, CASA, CASAL, CASL

10.3 Wide and unaligned accesses

7.2 gives the baseline: an aligned access of up to 64 bits is single-copy atomic, and everything else is a sequence of smaller atomic accesses. This section covers the instructions that go beyond that baseline (128-bit and 64-byte accesses), the rules that let an unaligned access still be atomic, and the alignment-fault rules that decide which of these you get and which fault.

128 bits before LSE2: LDXP/STXP and CASP

LDXP/STXP (v8.0) load and store a register pair exclusively. With 64-bit registers, the pair must be 16-byte aligned. The atomicity guarantee is asymmetric, and it is the one people miss:

  • A STXP that succeeds writes the 128 bits as a single-copy atomic access.
  • An LDXP on its own is not guaranteed to read 128 bits atomically. The two halves may be read at different times. The read is only known to be atomic if a following STXP to the same address succeeds, which proves no write intervened.

A 128-bit atomic load in v8.0 is therefore a read-modify-write:

// x0 = 16-byte aligned address; returns the 128-bit value in x2:x3
1:  ldaxp   x2, x3, [x0]
    stxp    w4, x2, x3, [x0]    // write back the same value
    cbnz    w4, 1b

This writes, so it faults on read-only mappings and causes coherence traffic on every read.

CASP (v8.1, part of FEAT_LSE) compares and swaps a pair: CASP Xs, Xs+1, Xt, Xt+1, [Xn], with A/L/AL variants. Xs and Xt must be even-numbered registers. The 64-bit form needs 16-byte alignment and is a single 128-bit single-copy atomic access when it writes. It has the same “failed compare need not write” rule as CAS (10.2). Like the LDXP/STXP read idiom, it needs write permission: CASP is treated as a write for permission checks even when the compare fails, so it cannot serve as a load from read-only memory.

FEAT_LSE2 (v8.4)

FEAT_LSE2 is mandatory from v8.4 (ID_AA64MMFR2_EL1.AT, bits [35:32], = 0b0001). It changes two things.

1. 16-byte LDP/STP atomicity. An LDP, LDNP or STP of two 64-bit registers is single-copy atomic as a whole if the access is 16-byte aligned and is to Normal Inner Write-Back, Outer Write-Back memory. The exact conditions are in DDI0487, Changes to single-copy atomicity in Armv8.4. This finally gives a pure 128-bit atomic load (LDP) and store (STP). GCC’s libatomic, for example, uses this when HWCAP_USCAT is set.

2. Unaligned accesses within 16 bytes. A load or store, including an atomic, exclusive or acquire/release access, whose bytes all fall within one aligned 16-byte quantity is single-copy atomic even if it is not naturally aligned. Recent DDI0487 issues add CTR_EL0.LSE2Size (bits [43:40]), which lets an implementation advertise a larger quantity. Its minimum encoding, 0b0000, means 16 bytes, which is the only portable assumption.

It also relaxes alignment faults:

  • Exclusives and LSE atomics do not fault if they stay within the aligned 16-byte quantity. They still fault if they cross it.
  • Load-acquire/store-release (LDAR, LDAPR, LDAPUR, STLR, STLUR and relatives, the list in SCTLR_ELx.nAA) do not fault within the 16-byte quantity. For an access that crosses it, SCTLR_ELx.nAA (bit 6) decides: 0 gives an Alignment fault, and 1 performs the access without a fault but without single-copy atomicity.

The fault behaviour, as DDI0487’s AArch64.UnalignedAccessFaults() pseudocode expresses it, is:

if exclusive or atomic:   fault = !LSE2 || !AllInAlignedQuantity(addr, size, 16)
if acquire/release:       fault = !LSE2 || (SCTLR_ELx.nAA == '0' && !AllInAlignedQuantity(addr, size, 16))

Setting nAA = 1 does not make anything atomic. It only stops the fault that tells you atomicity was lost. Leave it at 0 unless you are running legacy code that you know tolerates torn acquire/release accesses.

Alignment-fault rules by memory type and SCTLR_ELx.A

AccessNormal memory, SCTLR_ELx.A = 0Normal memory, A = 1Device memory (any A)
Ordinary load/store, LDP/STP, SIMDunaligned permitted (not single-copy atomic as a whole unless LSE2 applies)Alignment fault if not aligned to the element/access sizeAlignment fault if unaligned
Exclusives, LSE atomicsfault unless aligned (LSE2: unless within 16 bytes)Alignment fault if not naturally aligned (the LSE2 relaxation does not apply)fault if unaligned, and memory-type support is IMPLEMENTATION DEFINED (10.1)
Acquire/releasefault unless aligned (LSE2: within 16 bytes, or per nAA)Alignment fault if not naturally aligned (LSE2 and nAA do not apply)fault if unaligned
DC ZVApermittedpermittedAlignment fault
LD64B/ST64B*must be 64-byte alignedsamemust be 64-byte aligned

Two rows are where firmware gets hurt. With the MMU off, data accesses are Device-nGnRnE (with the MMU on but SCTLR_ELx.C == 0, Normal memory becomes Non-cacheable instead, which does not fault on unaligned access) (6.5). Any unaligned access then faults, including a compiler-generated unaligned LDR from memcpy or a packed struct, and DC ZVA faults. This is why TF-A builds with -mstrict-align. The fault is reported as a synchronous Data Abort with DFSC 0b100001 (Alignment fault). See 5.8.

FEAT_LSE128 (v9.4)

FEAT_LSE128 (ID_AA64ISAR0_EL1.Atomic = 0b0011) adds 128-bit forms of three LSE operations. Each takes the operand in a register pair and returns the old value in the same pair:

InstructionOperation
SWPP{A,L,AL} Xt1, Xt2, [Xn]swap 128 bits
LDSETP{A,L,AL}128-bit OR
LDCLRP{A,L,AL}128-bit AND-NOT

The address must be 16-byte aligned. There is no 128-bit add: the set is bitwise and swap operations, which suits flag words and descriptors rather than arithmetic. The main architectural customer is FEAT_D128 (128-bit translation table descriptors). Software sets and clears descriptor bits atomically with LDSETP/LDCLRP and exchanges a descriptor with SWPP, against hardware access-flag and dirty-state updates (5.6, 5.7). The version rules are in DDI0487 A2; it is optional.

FEAT_LRCPC3 (v8.9)

FEAT_LRCPC3 (ID_AA64ISAR1_EL1.LRCPC = 0b0011, optional) extends the RCpc acquire/release family:

  • LDIAPP (Load-Acquire RCpc ordered Pair) and STILP (Store-Release ordered Pair), with 32- and 64-bit register forms and writeback variants. DDI0487 defines an order between the two halves. For LDIAPP, the memory effects of Xt1 are Ordered-before those of Xt2. This is what makes a “load flag, then the payload next to it” pair safe in one instruction.
  • post-index LDAPR, pre-index STLR, and SIMD&FP LDAPUR/STLUR/LDAP1/STL1.

The 128-bit use: with LSE2, a 16-byte-aligned LDIAPP Xt1, Xt2 is a 128-bit acquire load that does not write, which neither LDXP/STXP nor CASP can provide. For single-copy atomicity of the pair, DDI0487 points to Requirements for single-copy atomicity. Treat the pair as atomic only under the same alignment and memory-type conditions as LSE2 LDP.

FEAT_LS64, LS64_V, LS64_ACCDATA (v8.7)

These add 64-byte single-copy atomic loads and stores, intended for accelerator and device work queues, where a 64-byte descriptor must arrive as one transaction, never as eight. All are optional. ID_AA64ISAR1_EL1.LS64 (bits [63:60]) reports the level.

ValueFeatureAdds
0b0001FEAT_LS64LD64B, ST64B
0b0010FEAT_LS64_VST64BV Xs, Xt, [Xn]: store, with a 64-bit status returned in Xs
0b0011FEAT_LS64_ACCDATAST64BV0 Xs, Xt, [Xn]: as ST64BV, but bits [31:0] of the first doubleword come from ACCDATA_EL1[31:0]
0b0100FEAT_LS64WBLD64B/ST64B (and 32-byte SIMD&FP pair accesses) to Write-Back Cacheable, Shareable memory

The data is eight consecutive registers starting at Xt. The address must be 64-byte aligned.

Memory-type restrictions. Which locations support these instructions is IMPLEMENTATION DEFINED. In practice, without FEAT_LS64WB the targets are Device or Normal Non-cacheable memory with a target that accepts 64-byte transactions. A location that supports ST64BV0 also supports ST64BV. For an unsupported location:

  • ST64BV/ST64BV0 return 0xFFFF_FFFF_FFFF_FFFF in Xs, and the memory contents are UNKNOWN.
  • LD64B/ST64B can generate a Data Abort with DFSC 0b110101 (Unsupported Exclusive or Atomic access). The architecture also allows IMPLEMENTATION DEFINED behaviour here, so a test must accept either outcome.

Any other status value is defined by the target device. A typical meaning is “accepted” or “retry, queue full”.

Enables (all default to trapping when 0):

ControlBitTrapsTo
SCTLR_EL1.EnALS56EL0 LD64B/ST64BEL1
SCTLR_EL1.EnAS055EL0 ST64BV0EL1
SCTLR_EL1.EnASR54EL0 ST64BVEL1
HCRX_EL2.EnAS0 / EnALS / EnASR0 / 1 / 2EL0 and EL1 use (EL0 only if not already trapped to EL1)EL2
SCR_EL3.EnAS036ST64BV0 at EL0–EL2EL3
SCR_EL3.ADEn37EL1/EL2 access to ACCDATA_EL1EL3

Traps are reported with EC 0x0A, and the ISS identifies the instruction. A trap at EL2 is a common surprise. If SCR_EL3.HXEn == 0, the effective value of HCRX_EL2 is 0, so all three HCRX traps are active even though EL2 never set them. EL3 must set SCR_EL3.HXEn (and usually the HCRX enables in its EL2 hand-off) for a kernel to use LS64 (17.3).

Bring-up note: 64-byte atomic accelerator doorbells. A typical shared work queue exposes a “portal” page per queue. A submitter builds a 64-byte descriptor in x0–x7 and issues ST64BV0 x8, x0, [portal]. The device receives the whole descriptor in one write, with the low 32 bits replaced by ACCDATA_EL1. The kernel or hypervisor loads that register per process or per VM, typically with a PASID-like context ID, so user space cannot forge it. x8 returns accept or retry. The bring-up checks are:

  1. the portal is mapped Device-nGnRE (or Non-cacheable), never cacheable unless FEAT_LS64WB is present;
  2. every hop (core, CHI deferrable-write support such as WriteNoSnpDef in CHI issue E and later, C2C bridge, PCIe Deferrable Memory Write if the device is behind a root port) preserves the 64-byte write as one transaction with a response. A bridge that splits it gives torn descriptors, and one that cannot return status turns every ST64BV into 0xFFFF… or an abort;
  3. the EL3 and EL2 enables above are set;
  4. ACCDATA_EL1 is context-switched.

A torn-write test is to submit descriptors whose eight doublewords carry the same sequence number, and have the device or a bus monitor check that they all match.

Checkpoint

Q10.3.1 On a v8.0 core without LSE2, code needs to read a 16-byte aligned 128-bit value from a page mapped read-only at EL1. Another core updates it with STXP. Which approach gives a single-copy atomic read?

  • A. LDXP x2, x3, [x0] alone, because an exclusive pair load is single-copy atomic
  • B. LDP x2, x3, [x0], because the address is 16-byte aligned
  • C. CASP x2, x3, x2, x3, [x0] with equal compare and new values, because it never changes memory
  • D. None of these. The v8.0 atomic-read idiom is LDXP plus a successful STXP of the same value, which needs write permission. The data must be made writable or read with a separate protocol such as a seqlock
Answer

D. LDXP alone is not guaranteed atomic, and atomicity is only established by a successful STXP. Aligned LDP atomicity is a FEAT_LSE2 property. CASP, even one that cannot change memory, is treated as a write for permission checks and faults on a read-only page. With LSE2 (mandatory from v8.4), B becomes correct for Write-Back memory.

Read more: Arm ARM (DDI0487), Requirements for single-copy atomicity; LDXP, STXP; CASP

Q10.3.2 On a v8.4 core, SCTLR_EL1.nAA == 0. Code executes LDAR x1, [x0] with x0 = 0x1008, and then with x0 = 0x100C. What happens?

  • A. Both take Alignment faults, because acquire loads must be naturally aligned
  • B. 0x1008 is in one aligned 16-byte quantity and does not fault. 0x100C crosses into the next quantity and faults
  • C. Neither faults, because LSE2 removes alignment checks for acquire loads
  • D. Both succeed, but only 0x1008 is single-copy atomic. nAA == 0 suppresses the fault
Answer

B. With LSE2, an acquire/release access faults only if it is not wholly within an aligned 16-byte quantity and nAA == 0. Bytes 0x1008–0x100F stay inside 0x1000–0x100F, while 0x100C–0x1013 cross the boundary. C and D describe nAA == 1, which would let 0x100C complete without a fault and without atomicity.

Read more: Arm ARM (DDI0487), SCTLR_EL1.nAA; Changes to single-copy atomicity in Armv8.4

Q10.3.3 An EL1 driver’s first ST64BV to an accelerator portal traps to EL2 with EC 0x0A, although the hypervisor never writes HCRX_EL2. SCTLR_EL1.EnASR is 1. What is the most likely cause?

  • A. The portal is mapped as Normal Write-Back, and LS64 instructions trap on cacheable memory
  • B. ST64BV always traps to EL2 the first time so that the hypervisor can validate the device
  • C. SCR_EL3.HXEn is 0, so the effective value of HCRX_EL2 is 0 and HCRX_EL2.EnASR traps EL1 use to EL2
  • D. SCR_EL3.EnAS0 is 0, which traps all LS64 stores to EL3, reported at EL2
Answer

C. When EL2 is enabled and SCR_EL3.HXEn == 0, HCRX_EL2 behaves as all zeros, so every HCRX enable is effectively off, and its traps are on. A wrong memory type gives a Data Abort or a 0xFFFF… status, not an EC 0x0A trap. SCR_EL3.EnAS0 only covers ST64BV0, and it traps to EL3.

Read more: Arm ARM (DDI0487), HCRX_EL2 (EnASR), SCR_EL3 (HXEn, EnAS0), ST64BV

10.4 Waiting and locking

The earlier sections in this part give you atomic operations. A lock also needs a way to wait that does not burn power or flood the interconnect. Firmware also has to lock in conditions where those atomics are not guaranteed: before the caches are on, and against agents that are not coherent at all.

The event register, WFE, SEV and SEVL

Each PE has a one-bit event register. Software cannot read it directly. It is set by:

  • SEV executed by any PE in the system (a broadcast);
  • SEVL executed by this PE (local only);
  • an exception return;
  • the clearing of this PE’s global monitor (the global-monitor event, below);
  • an event from the Generic Timer event stream (CNTKCTL_EL1.EVNTEN/EVNTI, and CNTHCTL_EL2 for EL2. See 4.6);
  • IMPLEMENTATION DEFINED sources, such as an external event input.

WFE then behaves as follows. If the event register is set, WFE clears it and completes immediately. Otherwise the PE may enter a low-power state until a WFE wake-up event occurs. Wake-up events are the event-register sources above, plus pending interrupts and SErrors and certain debug events, as listed in DDI0487 Wait for Event. WFE is a hint. An implementation may treat it as a NOP, and it may wake for no visible reason, so every WFE is inside a loop that re-checks the condition.

SEVL exists to prime that loop. It lets the first WFE fall straight through, so the loop can be written “wait, then check” without a special first iteration. TF-A’s exclusive spinlock is the textbook use:

// TF-A lib/locks/exclusive/aarch64/spinlock.S (non-CAS build)
spin_lock:
    mov     w2, #1
    sevl
l1: wfe
l2: ldaxr   w1, [x0]        // load-acquire and arm the global monitor
    cbnz    w1, l1          // held: sleep until the monitor is cleared
    stxr    w1, w2, [x0]
    cbnz    w1, l2
    ret
spin_unlock:
    stlr    wzr, [x0]       // the store clears waiters' monitors, so no SEV needed
    ret

Traps on WFE: SCTLR_EL1.nTWE (EL0 to EL1), HCR_EL2.TWE (to EL2) and SCR_EL3.TWE (bit 13, to EL3), all reported as EC 0x01. FEAT_TWED adds a configurable delay before the trap is taken (SCR_EL3.TWEDEn/TWEDEL and the EL2 equivalents). Hypervisors trap WFE to deschedule a vCPU that is spinning on a lock held by a preempted vCPU.

The global-monitor event

The unlock above has no SEV, yet waiters wake. The waiter’s LDAXR marks the lock’s granule in its global monitor. When the owner’s STLR writes that granule, the waiter’s global monitor goes from Exclusive Access to Open Access, and that transition generates an event for the waiter. The protocol is race-free by construction. If the unlock lands between the waiter’s LDAXR and its WFE, the monitor is already cleared, so the event register is already set and the WFE falls through.

The event only exists where a global monitor exists. On Normal Write-Back Shareable memory, the cache-based monitor’s loss of the line provides it (10.1). On Non-cacheable or Device memory without a system monitor, a store from the owner generates no event. A waiter then sleeps until some unrelated SEV, interrupt or event-stream tick. LSE locks combine both mechanisms. TF-A’s USE_SPINLOCK_CAS build takes the lock with CASA, and when it sees the lock held it does LDXR only to arm the monitor before WFE. Its bit_lock does the same with LDSETAB and LDXRB.

The event stream is the safety net. With EVNTEN set, every waiter wakes at a bounded period (Linux sets about 10 kHz). A missing event costs latency instead of a hang. Firmware that relies on WFE in memory of uncertain type should either enable the event stream or send SEV explicitly in its unlock path.

WFET and WFIT (FEAT_WFxT)

FEAT_WFxT (mandatory from v8.7, ID_AA64ISAR2_EL1.WFxT = 0b0010) adds WFET Xt and WFIT Xt. They behave like WFE/WFI, but also complete when the virtual count CNTVCT_EL0 reaches the value in Xt. The value is an absolute deadline, not a duration:

    mrs     x1, cntvct_el0
    add     x1, x1, x2          // x2 = timeout in counter ticks
1:  ldaxr   w3, [x0]
    cbz     w3, 2f              // condition met
    wfet    x1                  // sleep until event, wake-up or deadline
    mrs     x4, cntvct_el0
    cmp     x4, x1
    b.lo    1b
    // timed out
2:

Because the deadline is in virtual time, CNTVOFF_EL2 applies. EL2 code that uses physical time must convert. The same trap controls cover them: nTWE/TWE cover WFET, and nTWI/TWI cover WFIT. On a trap, ESR reports the register number, which is what 0b0010 in the ID field means. A timed wait no longer has to depend on the event stream.

Ticket locks, qspinlock and MCS (brief)

A test-and-set lock (above) is unfair: whichever core wins the race after an unlock gets the lock. A ticket lock is FIFO. It has two 16-bit halves, next and owner:

// lock word: [31:16] next, [15:0] owner
    mov     w2, #0x10000
    ldadda  w2, w1, [x0]        // take a ticket: old value in w1
    eor     w2, w1, w1, ror #16 // owner == my ticket?
    cbz     w2, 3f
    sevl
2:  wfe
    ldaxrh  w3, [x0]            // owner half; arms monitor
    eor     w2, w3, w1, lsr #16
    cbnz    w2, 2b
3:  // locked
// unlock: owner++ with release
    ldrh    w1, [x0]
    add     w1, w1, #1
    stlrh   w1, [x0]

The problem at scale is that every waiter spins on the same line. Each unlock invalidates it in all N waiting caches, and N re-reads follow. Handover cost grows with the number of waiters, and on a multi-chiplet system each re-read may cross the die-to-die link. MCS locks give each waiter its own queue node and spin location, so a handover touches one remote line. Linux’s qspinlock packs an MCS queue into a 32-bit word with a fast path for the uncontended case. arm64 Linux moved from its own ticket lock to qspinlock in 2018. For firmware with a handful of cores, a ticket or test-and-set lock is fine. For runtime services entered concurrently by hundreds of cores, it is not.

Locks before the MMU and caches are on: TF-A’s bakery lock

PSCI power-down and warm-boot paths run while some cores have the D-cache disabled. Their data accesses are then Device-nGnRnE (MMU off) or Non-cacheable, while other cores access the same lock with caches on. Exclusives are not guaranteed on those memory types (10.1), and the mismatched attributes break coherency (6.6). TF-A’s design document says it directly: BL31 touches PSCI state “before the data cache is enabled in the warm boot path”, so it “uses locks based on Lamport’s Bakery algorithm instead.”

The bakery algorithm needs no read-modify-write at all. Each CPU writes only its own entry, a choosing bit plus a ticket number, and reads everyone else’s. It relies only on aligned 16-bit loads and stores being single-copy atomic, which the architecture guarantees whatever the translation state. bakery_lock_get() takes max(all tickets) + 1, waits for each other CPU that is choosing, waits (with wfe) on any CPU with a lower (ticket, CPU index) pair, and ends with dmbish(). bakery_lock_release() does dmbish(), clears its entry, then dsb(); sev();. The SEV is required because no global-monitor event exists here.

TF-A has two variants:

BuildLock storageCoherency handling
USE_COHERENT_MEM=1 (bakery_lock_coherent.c).bakery_lock inside .coherent_ram, mapped Device/Non-cacheable at EL3All CPUs see the same attributes whatever their cache state
USE_COHERENT_MEM=0 (bakery_lock_normal.c)Normal cacheable memory, one cache-line-aligned block per CPU (PLAT_PERCPU_BAKERY_LOCK_SIZE must be a multiple of CACHE_WRITEBACK_GRANULE)Explicit maintenance: after writing, DC CVAC (cache on) or DC IVAC (cache off), then DSB ISH; before reading, DC CIVAC (cache on only) then DMB ISH

The per-CPU line split in the second variant is essential. If two CPUs’ entries shared a line, a cache-off CPU’s DC IVAC would discard a cache-on CPU’s dirty update to its own entry.

With HW_ASSISTED_COHERENCY=1, which is for cores that stay coherent through power transitions (DSU-based designs), PSCI uses ordinary spinlocks instead (lib/psci/psci_private.h). Bakery locks cost O(N) reads per acquisition, so on a many-core, multi-chiplet SoC this option is worth a lot. See 8.8 and 17.4.

Synchronising with non-coherent agents (SCP, MCP, RSE)

System control, management and security processors (SCP, MCP, RSE) are usually Cortex-M or R class. They are not in the application cores’ coherency domain and cannot take part in their atomics. No lock is shared. Instead, the protocol is single-writer ownership plus a doorbell. SCMI’s shared-memory transport (DEN0056) is the standard example. Its channel header has a channel status word whose bit 0 means “channel free” and bit 1 means “channel error”:

  1. The agent (AP, EL3) waits for free == 1. Only the side that owns the channel writes it.
  2. The agent writes the message header and payload, then clears free, which hands ownership to the platform.
  3. Barrier: a DSB (at least DMB OSH; see 7.9) so that the payload and status stores are observed before the doorbell.
  4. The agent writes the doorbell, typically an MHU register (Device-nGnRE).
  5. The platform processes the message, writes the response, sets free, and raises a completion interrupt, or the agent polls free.
  6. The agent reads the response only after it observes free == 1. That load is the acquire point, so use LDAR, or a load followed by DMB, before reading the payload.

Memory attributes must match what the other side can see. Map the shared area Non-cacheable or Device on the AP. If it must be cacheable, use DC CVAC before the doorbell and DC IVAC before reading the response, to the point the agent reads from (8.7). Never use LDXR/STXR or LSE atomics on this memory to “lock” it against the SCP, because the SCP’s writes will not clear your monitor. The same pattern covers the RSE communication channel used for measured boot and the cross-chiplet mailboxes in 17.5.

Validation note: a core found spinning in a WFE loop is the most common lock symptom in bring-up triage (18.2). Sample its PC non-intrusively (PMPCSR/EDPCSR) and read the lock word over the debug port. If the lock is free but the core still sleeps, a wake-up was lost: the lock is in memory with no global-monitor event and the unlock has no SEV, or the event stream is off (CNTKCTL_EL1.EVNTEN == 0). Confirm by enabling the event stream: the hang should become a slow but correct path. If the lock word reads as held by a CPU that has powered down, suspect a bakery entry lost through a DC IVAC on a shared line, or an exclusive STXR that “succeeded” without a monitor. For a lost-update stress test of the lock itself, see 8.10.

Checkpoint

Q10.4.1 In the TF-A non-CAS spin_lock, why can the waiter safely execute WFE after seeing the lock held, even if the owner’s STLR to release it happens just before the WFE executes?

  • A. STLR always broadcasts an SEV to all PEs, so the event register is set whenever a lock is released
  • B. The waiter’s LDAXR armed its global monitor. The owner’s store clears it and sets the waiter’s event register, so the later WFE completes immediately
  • C. WFE re-executes the preceding LDAXR when it wakes, so it observes the new value
  • D. The SEVL at the top of the function keeps the event register permanently set during the loop
Answer

B. The event comes from the global monitor’s transition to Open Access, and the event register latches it until the next WFE, so the race is closed. A store-release has no SEV side effect, so A is wrong. That is why the global-monitor mechanism matters. SEVL sets the register once and the first WFE consumes it, so D is wrong. WFE does not replay instructions.

Read more: Arm ARM (DDI0487), Wait for Event mechanism and Send event; Use of Wait for Event and Send Event with exclusive monitors

Q10.4.2 A firmware lock in Normal Non-cacheable SRAM is taken with CASA and waited for with LDXR plus WFE, and released with a plain STLR. On silicon, waiters sometimes stall for up to 100 µs after a release, but never hang. What best explains this?

  • A. CASA on Non-cacheable memory is performed far, which adds 100 µs of latency
  • B. STLR on Non-cacheable memory is buffered until the next DSB
  • C. The release has no acquire, so the waiter must wait for the store to propagate
  • D. The SRAM path has no global monitor, so the release generates no event. Waiters wake only at the next event-stream tick, and the stall is bounded by that period
Answer

D. The global-monitor event exists only where a global monitor tracks the location. Without one, the WFE is woken by the next event-stream event, interrupt or unrelated SEV, so the stall is bounded and recurring. Adding DSB; SEV to the unlock path, or moving the lock to Write-Back memory, fixes it. A far atomic costs hundreds of nanoseconds, not 100 µs. Stores do not wait indefinitely for a DSB.

Read more: Arm ARM (DDI0487), Wait for Event; CNTKCTL_EL1 (EVNTEN, EVNTI)

Q10.4.3 A platform builds TF-A with USE_COHERENT_MEM=0, and a porting engineer sets CACHE_WRITEBACK_SHIFT to 5 and PLAT_PERCPU_BAKERY_LOCK_SIZE to 32 bytes to save memory, on a core whose CTR_EL0.CWG reports a 64-byte writeback granule. The build-time size check passes. Under PSCI stress, CPU_ON and CPU_SUSPEND occasionally corrupt power-domain state. Why?

  • A. Two CPUs’ bakery entries share a cache line. A CPU with its cache off does DC IVAC on its entry and discards another CPU’s dirty update to its entry in the same line
  • B. The bakery algorithm requires 64-bit tickets, and 32 bytes truncates them
  • C. DC IVAC is not permitted with the MMU off, so the invalidate is ignored
  • D. Bakery locks require exclusives, and the smaller size breaks the ERG
Answer

A. The normal-memory variant is only correct if each CPU’s entry occupies its own writeback granule, which is why TF-A asserts that the size is a multiple of CACHE_WRITEBACK_GRANULE. That check is only as good as the granule the platform declares: with 32 declared on 64-byte hardware, two CPUs’ entries share a line. A per-CPU block split across a line lets cache maintenance by one CPU destroy another CPU’s data. Bakery locks use no exclusives at all, so D is wrong. Cache maintenance by VA works with the MMU off, using a flat mapping, so C is wrong.

Read more: TF-A firmware design, Bakery lock data; Arm ARM (DDI0487), DC IVAC and CTR_EL0.CWG

Part 11: Virtualization

Prerequisites: 2.6 The trap-control map, 3.3 Routing and masking, 4.1 GICv3 architecture, 4.4 LPIs and the ITS, 4.6 The Generic Timer, 5.1 Translation regimes and stages, 5.8 MMU faults and how to decode them, 9.1 TLBs and TLB maintenance. If you already know: how KVM’s world switch, VHE and the vGIC work, skim 11.1–11.2 and 11.4. Read 11.3 (attribute combination and FWB) and 11.5 (SMMUv3) anyway, because they carry most of the memory-system and bring-up content. Why this matters for bring-up/validation: EL2 and the SMMU decide what every guest and every DMA master can reach, and firmware leaves the trap, timer-offset, GIC and SMMU state that the hypervisor and the IOMMU driver depend on.

EL2 is a trap-and-translate layer. A hypervisor gets control in three ways: by trapping guest instructions and register accesses (HCR_EL2, HCRX_EL2 and the fine-grained trap registers), by translating every guest physical address through stage 2, and by owning physical interrupts and presenting virtual ones. Part 11 covers these in that order. 11.1 covers the trap controls and what a hypervisor must trap. 11.2 covers VHE, which lets a host kernel run at EL2, and the nested-virtualization extensions built on it. 11.3 covers stage 2 itself: its configuration, its faults, and how its attributes and permissions combine with stage 1, which is where FEAT_S2FWB and the cache-coherency problems of virtual machines arise. 11.4 covers virtual exceptions, the GICv3 list registers, GICv4/4.1 direct injection, and the virtual timer.

11.5 applies the same ideas to DMA masters. The SMMUv3 is a separately specified translation unit (IHI0070). It uses stage 1 and stage 2 tables in the same formats as the PE, but it has its own stream and context tables, command and event queues, and its own coherency attributes. Most SMMU bring-up bugs are in the StreamID mapping, the invalidation protocol and coherency, not in translation itself, so 11.5 closes with those mistakes.

11.1 EL2 basics and trapping

A hypervisor at EL2 controls a guest in three ways. It traps instructions and system-register accesses that the guest must not perform directly. It translates every guest physical address (an IPA) through stage 2. And it virtualizes exceptions and interrupts (11.4). This section covers the first two at the control-register level. The register-by-register map of who traps what is in 2.6; here the question is what a hypervisor has to set, and why.

HCR_EL2: the main control register

HCR_EL2 applies when EL2 is implemented and enabled in the current Security state (SCR_EL3.NS=1, or SCR_EL3.EEL2=1 for Secure EL2). The bits that matter fall into a few groups:

GroupBitsEffect
Stage 2VM (bit 0), PTW, DC, CD, ID, FWBEnable the EL1&0 stage 2 and control its attributes (11.3)
RoutingFMO (3), IMO (4), AMO (5), TGE (27), TEA (37)Route physical FIQ/IRQ/SError (and, with TEA, synchronous External aborts) to EL2 and enable the virtual interrupts (11.4, 3.3)
Virtual exceptionsVF (6), VI (7), VSE (8)Assert a virtual FIQ, IRQ or SError to EL1
Instruction trapsTWI (13), TWE (14), TSC (19), TSW (22), TPCP, TPU, TTLB, TTLBIS, TTLBOS, TICAB, TOCUTrap WFI, WFE, SMC, set/way CMOs, PoC/PoU CMOs, TLBI and IC maintenance
Register trapsTID0–TID5, TID3 (18), TACR, TIDCP, TVM (26), TRVM, TLOR, TERRTrap ID, auxiliary, IMPLEMENTATION DEFINED, MMU-control writes and reads, LORegion and RAS registers
Feature gatesAPI, APK, ATA, EnSCXT, FIENInverted-sense enables: 0 traps or disables PAuth, MTE tag access, SCXTNUM, RAS fault injection
Execution stateRW (31)EL1 is AArch64 (1) or AArch32 (0)
Host and nestingE2H (34), TGE, NV, NV1, NV2VHE and nested virtualization (11.2)

Two conventions are worth fixing in mind. Most trap bits trap when set to 1, so a zero-initialised HCR_EL2 traps nothing and leaves stage 2 off. A few feature bits (API, APK, ATA) are the reverse, so the same zeroed register does trap PAuth instructions and key-register accesses, and traps the MTE tag-control registers while disabling Allocation Tag access at EL1/EL0. A guest that suddenly takes EC 0x09 (PAuth trap) at EL2 usually points to a hypervisor that has not set HCR_EL2.API/APK.

Every trapped access arrives at EL2 with an ESR syndrome. The common ones are EC 0x01 (WFx), 0x16 (HVC), 0x17 (SMC trapped by TSC), 0x18 (MSR/MRS/system instruction, with Op0/Op1/CRn/CRm/Op2, Rt and direction in the ISS), 0x1A (ERET, under NV or FGT), and 0x20/0x24 (stage-2 instruction and data aborts). See Appendix D.

HCRX_EL2 (FEAT_HCX)

HCR_EL2 ran out of bits, so FEAT_HCX (v8.7, see DDI0487 A2) adds HCRX_EL2. Newer controls live there. Examples are EnALS/EnAS0/EnASR (the LS64 instructions, 10.3), FnXS/FGTnXS (FEAT_XS TLBI behaviour), TALLINT/VINMI/VFNMI (FEAT_NMI), TCR2En, SCTLR2En, GCSEn, D128En and MSCEn. The pattern is the one described in 2.6: EL3 must set SCR_EL3.HXEn or EL2’s own accesses to HCRX_EL2 trap to EL3, and while HXEn=0 the register behaves as if every field were 0. Many HCRX_EL2 bits are enables, so an EL2 that clears the register disables the feature for EL1 rather than allowing it. EL3 sequencing is in 17.3.

Stage 2 and the VMID

With HCR_EL2.VM=1, every EL1&0 access is translated twice: VA to IPA by the guest’s stage 1, then IPA to PA by stage 2. Stage 2 is configured by VTCR_EL2 and based at VTTBR_EL2 (11.3). VTTBR_EL2 also carries the VMID in bits [55:48] (8-bit), or bits [63:48] when VTCR_EL2.VS=1 and 16-bit VMIDs are implemented (ID_AA64MMFR1_EL1.VMIDBits).

The VMID tags every TLB entry of the EL1&0 regime, stage-1-only and combined entries alike. That lets the hypervisor switch guests by writing VTTBR_EL2, without invalidating anything. So the VMID is part of the isolation boundary. Two guests that share a VMID can hit each other’s TLB entries, and the stage-2 invalidation sequence (TLBI IPAS2E1IS followed by TLBI VMALLE1IS, 9.1) operates on the current VMID. A hypervisor that invalidates on behalf of a guest that is not running must first load that guest’s VTTBR_EL2, with an ISB.

Security note: VMID reuse needs a full invalidation (TLBI VMALLS12E1IS for that VMID, or a global flush on roll-over) before a new VM gets the number. Prediction resources may also be tagged by VMID, and their isolation guarantees (FEAT_CSV2 and related) are covered in 14.7.

What a hypervisor must trap

Trapping everything is slow, so the useful question is which resources a guest cannot be allowed to touch, and why.

  • Physical time and timers. CNTHCTL_EL2.EL1PCTEN/EL1PCEN trap EL1 access to the physical counter and timer, so the guest uses the virtual timer, offset by CNTVOFF_EL2 (11.4).
  • Set/way cache maintenance (TSW). DC ISW/CSW/CISW act on the physical cache geometry of the PE the guest happens to run on. They cannot be made correct across vCPU migration, and they can discard other guests’ dirty lines. KVM traps them and converts them into by-VA maintenance or a full flush of the guest’s memory (8.5).
  • SMC (TSC). Guest PSCI calls must reach the hypervisor, not EL3, or a guest could power off a physical core. Guests normally use HVC conduit; TSC closes the SMC path.
  • ID registers (TID3 and friends, plus TID2 for cache ID). These let the hypervisor present one consistent CPU model across heterogeneous cores and across migration, and hide features it does not context-switch.
  • IMPLEMENTATION DEFINED and auxiliary registers (TIDCP, TACR). Their effects are not architecturally scoped to a VM.
  • Debug and PMU (MDCR_EL2: TDA, TDE, TPM, TPMCR, HPMN). These partition the PMU counters and keep the guest out of debug state.
  • FP/SIMD/SVE/SME (CPTR_EL2). Trapping allows lazy context switching, and is required for any state the hypervisor does not save.
  • MMU-control writes (TVM/TRVM), conditionally. Historically KVM trapped them to learn when a guest turned its caches on, which mattered for coherency before FEAT_S2FWB (11.3).
  • WFI/WFE (TWI/TWE), as policy. Trapping them lets the hypervisor deschedule an idle or spinning vCPU. Not trapping them gives lower latency on dedicated cores.

TLB maintenance (TTLB) is normally not trapped. A guest’s TLBI is automatically scoped to its VMID by hardware, so it cannot affect other VMs. It is trapped only for nested virtualization or for errata workarounds.

Fine-grained traps: FEAT_FGT and FEAT_FGT2

The coarse traps are blunt. TID3, for example, traps the whole ID-register group, and TVM traps all of the MMU-control registers. FEAT_FGT (a v8.6 feature, see DDI0487 A2) adds per-register and per-instruction trap bits:

RegisterTraps
HFGRTR_EL2MRS reads of individual EL1/EL0 system registers (SCTLR_EL1, TCR_EL1, TPIDR_EL0, ERX*, LOR*, and so on)
HFGWTR_EL2MSR writes of the same registers, with the same bit layout where a register is writable
HFGITR_EL2Individual instructions: TLBI groups, AT, DC/IC groups, ERET, SVC_EL0/SVC_EL1 and more
HDFGRTR_EL2, HDFGWTR_EL2Debug, PMU, SPE, TRBE and BRBE registers
HAFGRTR_EL2Activity Monitor registers (present only with FEAT_AMUv1 as well as FEAT_FGT)

FEAT_FGT2 (introduced with the v8.9/v9.4 extensions, see DDI0487 A2) adds HFGRTR2_EL2, HFGWTR2_EL2, HFGITR2_EL2, HDFGRTR2_EL2 and HDFGWTR2_EL2 for registers added after the first set filled up.

The rules:

  • FGT traps apply to accesses from EL1 and EL0 when EL2 is enabled. They do not apply to the EL2&0 host when HCR_EL2.{E2H,TGE}={1,1}.
  • EL3 gating. SCR_EL3.FGTEn (bit 27) and SCR_EL3.FGTEn2 (bit 59) must be 1. Otherwise EL2’s accesses to the FGT registers trap to EL3 (EC 0x18), and the fine-grained traps behave as if all bits were 0. Linux’s arm64 boot protocol requires EL3 to set both when the corresponding feature is present.
  • Polarity. Most bits trap when 1. Bits named n<REG>, such as nTPIDR2_EL0, nSMPRI_EL1, nPIR_EL1, nPOR_EL1 and nGCS_EL1, trap when 0. These bits cover registers added after FGT was defined. An older hypervisor that zero-fills the FGT registers therefore traps access to state it does not know how to context-switch, which is the safe default.
  • The FGT registers’ fields reset to architecturally UNKNOWN values, so EL2 must write every FGT register it has (including the FGT2 ones) rather than relying on reset values.
    // EL2: trap guest writes to SCTLR_EL1 only (not TCR/TTBR as TVM would).
    // HFGWTR_EL2_SCTLR_EL1 is a mask generated from the System Register XML.
    mrs     x0, HFGWTR_EL2
    ldr     x1, =HFGWTR_EL2_SCTLR_EL1
    orr     x0, x0, x1
    msr     HFGWTR_EL2, x0
    isb

Take FGT field positions from the System Register XML (as Linux does with its generated sysreg definitions), never from memory: the registers are dense and the n bits are interleaved with ordinary ones.

Bring-up note: a kernel entered at EL2 that faults at its first MSR HFGRTR_EL2 or MSR HCRX_EL2 with an exception taken to EL3 (EC 0x18 in ESR_EL3) is the classic symptom of firmware that did not set SCR_EL3.FGTEn/FGTEn2/HXEn on a core that implements the feature. The fix is in TF-A (ENABLE_FEAT_FGT, ENABLE_FEAT_FGT2, ENABLE_FEAT_HCX), not in the kernel.

Validation note: for each trap bit you claim to support, run a directed test: guest EL1 performs the access, and EL2’s handler checks ESR_EL2.EC, the ISS encoding of the register, and ELR_EL2. Then clear the bit and confirm the access completes with no exception. A trap with the wrong priority, such as an FGT trap reported where an UNDEFINED is required for an unimplemented register, shows up only in such negative tests (18.5).

Checkpoint

Q11.1.1 A hypervisor wants to stop guests from discarding each other’s dirty data through cache maintenance, and also wants guest cache maintenance to be correct when a vCPU migrates between physical cores. Which guest instructions must it trap, and why?

  • A. DC CIVAC and DC IVAC with TPCP, because by-VA maintenance to the PoC can reach other VMs’ memory
  • B. TLBI VMALLE1IS with TTLB, because broadcast TLB maintenance affects all VMIDs
  • C. DC ISW/CSW/CISW with TSW, because set/way operations act on physical cache locations, not on the guest’s addresses, and cannot follow a vCPU across cores
  • D. Nothing, because stage 2 confines all cache maintenance to the guest’s IPA space
Answer

C. By-VA maintenance is translated through stage 1 and stage 2, so it only reaches memory the guest maps, and an invalidate is upgraded to clean+invalidate under stage 2 where needed. Set/way operations name cache lines by set and way on the local PE. They are not translated, they can drop other owners’ dirty lines, and they say nothing about the caches of a core the vCPU ran on earlier. Guest TLBIs (B) are tagged with the current VMID and so do not cross VMs. D is wrong because set/way operations bypass translation entirely.

Read more: Arm ARM (DDI0487), HCR_EL2.TSW; “Data cache maintenance instructions” (set/way and virtualization)

Q11.1.2 An old hypervisor zero-initialises every FGT register it finds. It then runs on a newer core where HFGRTR_EL2 has an nPOR_EL1 bit, and a guest reads POR_EL1. What happens, and why was the bit defined this way?

  • A. The read traps to EL2, because n-prefixed bits trap when 0, so state the hypervisor does not context-switch is protected by default
  • B. The read completes, because a zero FGT register disables all fine-grained traps
  • C. The read is UNDEFINED at EL1, because the hypervisor has not enabled the feature in HCRX_EL2
  • D. The read traps to EL3, because SCR_EL3.FGTEn controls the trap destination
Answer

A. Bits for registers added after FGT was introduced use negative polarity, so the value 0, which is what an unaware hypervisor writes, means “trap”. The guest therefore cannot use or leak POR_EL1 state that the hypervisor would fail to save on a switch. B would be true for ordinary positive-polarity bits only. SCR_EL3.FGTEn gates whether the FGT registers are effective and accessible from EL2. It does not redirect guest traps to EL3 (D).

Read more: Arm ARM (DDI0487), HFGRTR_EL2 field descriptions; SCR_EL3.FGTEn

Q11.1.3 KVM handles a stage-2 fault for VM 7 and wants to invalidate a stale IPA mapping while VM 3 is the guest loaded on this PE. Which sequence is correct?

  • A. TLBI IPAS2E1IS with VM 7’s IPA, because the IPA uniquely identifies the entry
  • B. TLBI VAE1IS with the guest VA, because combined entries are tagged by VA
  • C. TLBI ALLE1IS, the only instruction that can reach another VMID
  • D. Write VM 7’s VTTBR_EL2, ISB, then TLBI IPAS2E1IS, DSB ISH, TLBI VMALLE1IS, DSB ISH, then restore VM 3’s VTTBR_EL2
Answer

D. (The descriptor update itself is assumed to be already followed by DSB ISHST.) Stage-2 and EL1&0 TLBIs operate on the VMID currently in VTTBR_EL2, so the hypervisor must switch VMIDs, with an ISB so that the new VMID is used, before invalidating. The stage-1+2 combined entries are not invalidated by IPAS2E1IS alone, hence the VMALLE1IS. A would invalidate VM 3’s entries for that IPA. ALLE1IS (C) works, but it is a sledgehammer that flushes every VM. It is not the only option.

Read more: Arm ARM (DDI0487), TLBI IPAS2E1IS; “TLB maintenance requirements and the TLB maintenance instructions”

11.2 VHE and nested virtualization

The original Armv8.0 EL2 was designed for a type-1 hypervisor: a small program at EL2 with its own single-range translation regime, which shares nothing with EL1. A hosted hypervisor such as KVM does not fit that design. Its scheduler, memory manager and drivers are an ordinary OS kernel. FEAT_VHE (v8.1) changes EL2 so that an OS kernel can run there unmodified. FEAT_NV and FEAT_NV2 (v8.3 and v8.4) then let a guest believe it owns EL2, so that it can run its own guests.

HCR_EL2.E2H: what changes at EL2

Setting HCR_EL2.E2H=1 changes EL2 in three ways.

  1. A two-range translation regime. EL2 stops using the single-range EL2 regime and uses the EL2&0 regime instead. That regime has TTBR0_EL2 and TTBR1_EL2, ASIDs in the TTBRs, a TCR_EL2 with the TCR_EL1 layout (T0SZ/T1SZ, A1, EPD0/1, and so on), and global/non-global entries. It has the same shape as EL1&0, so a kernel’s page-table code works unchanged (5.1).
  2. Register layouts change. Several EL2 registers take on their EL1 counterpart’s format. CPTR_EL2 gets the CPACR_EL1 layout (FPEN, ZEN, SMEN) instead of the trap-bit layout (TFP, TZ). CNTHCTL_EL2 gets a CNTKCTL_EL1-like layout, with EL0PCTEN/EL0VCTEN and the EL1 controls moved to other bit positions. Code that programs these registers must know which layout is active.
  3. Register redirection. At EL2 with E2H=1, an MRS or MSR that names an EL1 register accesses the corresponding EL2 register.
Name used at EL2Register actually accessed
SCTLR_EL1, TCR_EL1, TTBR0_EL1, TTBR1_EL1, MAIR_EL1, AMAIR_EL1SCTLR_EL2, TCR_EL2, TTBR0_EL2, TTBR1_EL2, MAIR_EL2, AMAIR_EL2
VBAR_EL1, ESR_EL1, FAR_EL1, AFSR0/1_EL1, ELR_EL1, SPSR_EL1the _EL2 registers
CPACR_EL1, CONTEXTIDR_EL1, CNTKCTL_EL1, ZCR_EL1CPTR_EL2, CONTEXTIDR_EL2, CNTHCTL_EL2, ZCR_EL2
CNTP_CTL_EL0/CVAL/TVAL, CNTV_CTL_EL0/CVAL/TVALCNTHP_*_EL2, CNTHV_*_EL2 (the EL2 physical and virtual timers)

To reach the real EL1 registers, which belong to the guest, EL2 uses new encodings with the suffixes _EL12 (SCTLR_EL12, TTBR0_EL12, VBAR_EL12, ELR_EL12, SPSR_EL12, CNTKCTL_EL12, and so on) and _EL02 (CNTP_CTL_EL02, CNTV_CVAL_EL02, …). These encodings are UNDEFINED when E2H=0, and at EL1 they are UNDEFINED or trapped (see NV below).

Not every register is redirected. Registers with no EL2 meaning, or with a separate EL2 copy that the kernel uses directly, are left alone. TPIDR_EL1, MDSCR_EL1, PAR_EL1 and SP_EL1 are examples. Linux under VHE keeps its per-CPU offset in TPIDR_EL2 for this reason. The System Register XML lists, for each register, its behaviour “when HCR_EL2.E2H == 1”.

HCR_EL2.TGE: hosting EL0

E2H makes EL2 look like EL1. TGE (trap general exceptions) makes EL0 belong to EL2. With {E2H,TGE}={1,1}:

  • EL0 runs in the EL2&0 regime, so host user processes share the host kernel’s ASID-tagged regime.
  • Exceptions from EL0, including SVC, go to EL2. EL1 is not used.
  • HCR_EL2.VM and most of the other EL1-directed stage-2 and trap controls are treated as 0 for all purposes other than direct reads, so host EL0 has no stage 2. FMO/IMO/AMO are treated as 1, so physical interrupts go to EL2.
  • Fine-grained traps (11.1) do not apply, and the virtual counter offset CNTVOFF_EL2 is treated as zero for host EL0 reads, as it is for EL2 reads with E2H=1 (11.4).

With {E2H,TGE}={1,0} the same EL2 runs a guest: EL1 and EL0 belong to the VM again, under stage 2. Switching a single bit, TGE, between the host and guest configurations is what makes the VHE world switch cheap.

Why KVM runs Linux at EL2

Without VHE (KVM’s “nVHE” mode), the host kernel runs at EL1 and a small hypervisor (KVM’s nVHE hyp code, arch/arm64/kvm/hyp/nvhe/) runs at EL2. Every guest exit then needs: an exception to EL2, saving the guest’s EL1 context, restoring the host’s EL1 context, an ERET to host EL1 so that the kernel can handle the exit, and the whole sequence reversed to re-enter the guest. The EL1 system-register file is swapped twice per exit.

With VHE the host kernel is already at EL2. A guest exit is just an exception to the kernel. Guest EL1 state is saved through the _EL12 aliases only when the vCPU is descheduled, not on every exit. Timer and interrupt handling for the host also happen without a world switch. KVM selects VHE at boot when the kernel is entered at EL2 and FEAT_VHE is present.

    // VHE: enter a guest (sketch; KVM does far more)
    msr     VTTBR_EL2, x1          // guest VMID and stage-2 base
    msr     SCTLR_EL12, x2         // guest's real SCTLR_EL1
    msr     VBAR_EL12, x3
    mrs     x0, HCR_EL2
    bic     x0, x0, #(1 << 27)     // TGE = 0: EL1/EL0 now belong to the guest
    orr     x0, x0, #1             // VM = 1: stage 2 on
    msr     HCR_EL2, x0
    isb
    msr     ELR_EL2, x4            // guest PC
    msr     SPSR_EL2, x5           // guest PSTATE, M = EL1h
    eret

Some implementations do not support E2H=0 at all, and HCR_EL2.E2H is then RES1. FEAT_E2H0 names the ability to run with E2H=0; its absence is reported by a non-zero (negative) value of ID_AA64MMFR4_EL1.E2H0. Firmware and boot code must therefore not assume that EL2 can be run in the original non-VHE mode, and they must not program CPTR_EL2 or CNTHCTL_EL2 with the non-VHE layout without checking which layout is in effect.

Security note: VHE puts the whole host kernel, with its drivers and attack surface, at the hypervisor’s privilege level. A host kernel bug is a hypervisor compromise, and guests must trust the host. Android’s protected KVM (pKVM) deliberately does the opposite: the host runs at EL1 under its own stage 2, and only a small hypervisor runs at EL2 (in nVHE form, or as “hVHE”, which uses E2H=1 for the hypervisor’s own regime but never hosts a kernel there). For EL3 reviewers, the trust question is not “is EL2 used” but “what code runs at EL2”.

Bring-up note: the Linux arm64 boot protocol asks to be entered at EL2 whenever virtualization is wanted, and the kernel itself decides between VHE and nVHE. Firmware that drops to EL1 silently disables KVM. Firmware that leaves stale HCR_EL2 bits, such as TGE or E2H with an HCR_EL2 written for another layout, produces early kernel faults that look like translation bugs.

Nested virtualization: FEAT_NV and FEAT_NV2 (in brief)

Nested virtualization runs a guest hypervisor (L1) at EL1 under the real hypervisor (L0). L1 must believe it is at EL2.

FEAT_NV (v8.3) provides the traps that make this possible. With HCR_EL2.NV=1:

  • CurrentEL read at EL1 returns EL2, so L1’s “am I at EL2” checks succeed.
  • EL1 accesses to EL2 registers (HCR_EL2, VTTBR_EL2, ESR_EL2, …) and to the _EL12/_EL02 aliases trap to L0 (EC 0x18) instead of being UNDEFINED.
  • ERET, ERETAA and ERETAB at EL1 trap to L0 (EC 0x1A), so L0 can emulate L1’s “return to its guest”.
  • EL2 TLBI and AT instructions trap.

HCR_EL2.NV1 adds the behaviour needed for an L1 that is a non-VHE hypervisor. It traps further EL1 registers that such a hypervisor uses as its “EL2” ones, and it changes some stage-1 descriptor interpretation. A VHE guest hypervisor runs with NV=1, NV1=0.

FEAT_NV alone is functional but slow, because an L1 hypervisor touches EL2 registers on every world switch, and each access is a trap to L0.

FEAT_NV2 (v8.4) removes most of those traps. With HCR_EL2.{NV,NV2}=1, EL1 accesses to many EL2 registers, and to EL1 registers that L1 uses on behalf of its own guest, become loads and stores to memory. The memory page is the one at VNCR_EL2.BADDR, and each register has an architecturally fixed offset in it. L0 reads that page when it needs L1’s view of a register, for example when emulating L1’s ERET into L2. Some other EL2 registers, such as ELR_EL2 and SPSR_EL2, are instead redirected to their EL1 counterparts, which L1 can use directly because L0 owns the real EL2 copies. Registers with immediate side effects still trap. A fault on one of these redirected accesses is reported as a data abort with ESR_ELx.ISS.VNCR=1 (5.8).

L0 also has to merge stage 2: L1’s stage 2 for L2 (IPA_L2 to IPA_L1) composed with L0’s own (IPA_L1 to PA) into a “shadow” stage 2 that the hardware walks, and it has to keep that shadow coherent with L1’s TLBIs. This is a software problem, and it is why NV support in KVM has taken years. The architecture provides the traps and VNCR, not the shadow tables.

Checkpoint

Q11.2.1 A VHE host kernel at EL2 executes MSR VBAR_EL1, x0 and then MSR VBAR_EL12, x1. Which registers are written?

  • A. VBAR_EL1, then VBAR_EL1 again, because the _EL12 alias is only a second name
  • B. VBAR_EL2 (redirected), then the real VBAR_EL1, which is the guest’s vector base
  • C. The real VBAR_EL1, then VBAR_EL2
  • D. VBAR_EL2, then an UNDEFINED exception, because _EL12 names exist only under FEAT_NV
Answer

B. With E2H=1, EL1 register names used at EL2 are redirected to the EL2 registers, so the unmodified kernel’s VBAR_EL1 write sets its own vector table. _EL12 names are the VHE way to reach the real EL1 registers, which belong to the guest. They are defined by FEAT_VHE and are UNDEFINED only when E2H=0 (D confuses them with the NV trap behaviour).

Read more: Arm ARM (DDI0487), “Virtualization Host Extensions”, VBAR_EL12

Q11.2.2 Why is a VHE guest exit cheaper than an nVHE one in KVM?

  • A. VHE disables stage 2 during exits, so no TLB maintenance is needed
  • B. VHE implementations save EL1 state to memory in hardware
  • C. With VHE the guest runs at EL2 too, so no exception is taken
  • D. The host kernel already runs at EL2, so an exit does not need a round trip to host EL1 with two swaps of the EL1 register file. Guest EL1 state can stay loaded until the vCPU is descheduled
Answer

D. In nVHE mode the host is at EL1, so handling any exit in the kernel requires swapping the guest’s EL1 context out and the host’s in, then the reverse. Under VHE the kernel handles the exit directly at EL2. B describes FEAT_NV2’s VNCR memory redirection, which is a different feature for a different problem, and is still software-managed. The guest never runs at EL2 (C).

Read more: Arm ARM (DDI0487), HCR_EL2.E2H and HCR_EL2.TGE; Arm, “AArch64 Virtualization” guide

Q11.2.3 An L1 guest hypervisor runs under L0 with HCR_EL2.{NV,NV2}=1. L1 executes MSR HCR_EL2, x0 while preparing to run its own guest. What typically happens?

  • A. The write becomes a store to L1’s VNCR page at a fixed offset, with no trap. L0 consumes the value when it emulates L1’s ERET into L2
  • B. The write traps to L0 with EC 0x18, as it would under FEAT_NV alone
  • C. The write updates the real HCR_EL2, because NV2 grants L1 direct access
  • D. The write is UNDEFINED because L1 is at EL1
Answer

A. NV2 converts accesses to registers like HCR_EL2 into memory accesses relative to VNCR_EL2.BADDR, which avoids a trap per access. B is FEAT_NV without NV2. L1 never writes the real EL2 registers (C). L0 merges L1’s values with its own when it runs L2. D would be true without FEAT_NV.

Read more: Arm ARM (DDI0487), VNCR_EL2; “Enhanced support for nested virtualization” (FEAT_NV2)

11.3 Stage 2 in detail

Stage 2 translates an intermediate physical address (IPA) to a PA for every EL1&0 access while HCR_EL2.VM=1. That includes the guest’s own stage-1 table walks, because the guest’s TTBRn_EL1 and its table descriptors hold IPAs. The descriptor formats and the walk mechanics are the same as stage 1 (5.3). This section covers what is different: the configuration register, the attribute and permission fields, how stage 1 and stage 2 results combine, and the controls that override that combination.

VTCR_EL2 and the IPA size

FieldBitsMeaning
T0SZ[5:0]IPA size = 64 − T0SZ bits
SL0[7:6]Starting level of the walk (encoding depends on TG0)
IRGN0, ORGN0, SH0[9:8], [11:10], [13:12]Cacheability and shareability of stage-2 table walks
TG0[15:14]Granule: 0b00 4KB, 0b01 64KB, 0b10 16KB
PS[18:16]Output (physical) address size: 0b000 32 bits … 0b101 48, 0b110 52
VS[19]16-bit VMID
HA, HD[21], [22]Hardware Access-flag and dirty-state update for stage 2 (FEAT_HAFDBS)
NSW, NSA[29], [30]For Secure EL2: PA space of Secure stage-2 walks and output
DS[32]52-bit addressing with 4KB/16KB granules (FEAT_LPA2)
SL2[33]With DS=1 and 4KB granule, start at level −1

There is only one range (no T1SZ), and the IPA space starts at 0. Stage 2 has one feature stage 1 does not: concatenated tables at the starting level. Up to 16 adjacent tables can form the first level, which adds up to four bits of IPA without adding a walk level. KVM’s default 40-bit IPA with a 4KB granule uses T0SZ=24, SL0=0b01 (start at level 1) and two concatenated level-1 tables, which needs 8KB contiguous and 8KB-aligned, instead of a four-level walk. The T0SZ/SL0 combination must be consistent with the granule. An inconsistent pair is not a valid configuration. The VTCR_EL2.SL0 description says how it is reported (a stage-2 Translation fault in the pseudocode), so check it before relying on the exact behaviour.

Two size checks apply and are often confused:

  • An IPA above 2^(64−T0SZ) gives a stage-2 Translation fault. This is how a hypervisor bounds guest physical address space.
  • An output address above the PS size, or above the implemented ID_AA64MMFR0_EL1.PARange, gives an Address size fault. Program PS no higher than PARange (a larger value is treated as the implemented size, so it buys nothing). On heterogeneous systems, use the smallest PARange of all cores (the sanitised value).

Bring-up note: KVM sizes each VM’s IPA space from the VMM’s request, bounded by the sanitised PARange. On SoCs that put DRAM or device apertures above 2^40, a 40-bit default IPA leaves no room for a device passthrough at its native address. VMMs then relocate it, or ask for a larger IPA, which needs a deeper walk or more concatenation.

Stage-2 descriptor fields

The upper and lower attributes differ from stage 1 in three ways. Stage 2 has no AttrIndx or MAIR, no user/privileged split in its permissions, and no nG bit.

FieldBitsMeaning
MemAttr[3:0][5:2]Memory type, encoded directly (no MAIR indirection)
S2AP[1:0][7:6]00 no access, 01 read-only, 10 write-only, 11 read/write
SH[1:0][9:8]Shareability
AF[10]Access flag
DBM[51]Dirty bit modifier (hardware dirty tracking)
XN[1:0][54:53]Execute-never. With FEAT_XNX, the two bits give separate EL1 and EL0 control

With HCR_EL2.FWB=0, MemAttr is interpreted like this. MemAttr[3:2]=00 means Device, with MemAttr[1:0] giving nGnRnE/nGnRE/nGRE/GRE. Otherwise MemAttr[3:2] is the Outer and MemAttr[1:0] the Inner cacheability: 01 Non-cacheable, 10 Write-Through, 11 Write-Back. Stage 2 carries no allocation or transient hints. Those come from stage 1. FEAT_S2PIE and FEAT_S2POE (permission indirection and overlays for stage 2, v8.9) let S2PIR_EL2 reinterpret the permission bits. They are not covered further here.

How stage 1 and stage 2 combine

This is the single place in the book where combination is defined (6.5 points here). With FWB=0 the rule is the more restrictive of the two, for each attribute:

AttributeCombined result
Memory typeIf either stage says Device, the result is Device, of the stronger type: nGnRnE > nGnRE > nGRE > GRE
Cacheability (Inner and Outer separately)The weaker: Non-cacheable < Write-Through < Write-Back
Allocation and transient hintsFrom stage 1
ShareabilityIf the result is Device or Inner+Outer Non-cacheable, Outer Shareable. Otherwise the more shareable of the two: OSH > ISH > NSH
Data permissionsBoth must permit. Stage 1 faults are taken to EL1, stage 2 faults to EL2
ExecuteExecute-never if either stage says so

Two consequences matter in practice.

A guest can always make memory less cacheable, never more. The hypervisor maps guest RAM as stage-2 Normal WB. The guest still gets Device-nGnRnE for data when its MMU is off (6.5), and Non-cacheable if it maps a buffer that way. Meanwhile the host may have written the guest’s kernel image through its own cacheable alias. The guest’s non-cacheable reads then go past dirty lines in the cache to stale DRAM, which is the classic “guest crashes at boot with garbage instructions” bug. Before FWB, KVM handled this by cleaning every page to the PoC before mapping it at stage 2, and by trapping set/way operations and (via TVM) MMU-enable writes so that it could flush when the guest switched its caches on (8.5, 6.6).

The hypervisor’s Device mapping always wins. Mapping emulated MMIO as stage-2 Device, or leaving it unmapped so that accesses fault and are emulated, guarantees Device semantics whatever the guest’s stage 1 says. HCR_EL2.PTW=1 additionally makes a guest stage-1 walk that lands on stage-2 Device memory a stage-2 Permission fault, rather than a walk of MMIO.

FEAT_S2FWB: stage 2 forced write-back

FEAT_S2FWB (v8.4) changes the meaning of MemAttr when HCR_EL2.FWB=1, so that stage 2 can force an attribute instead of only restricting it. MemAttr[2] selects the interpretation:

MemAttr[2:0]Result
0b0xxDevice, of the type in MemAttr[1:0]. FWB does not change how a stage-2 Device type combines with stage 1, so a stronger stage-1 Device type still wins
0b101Normal Non-cacheable, unless stage 1 is Device, in which case the stage-1 Device type
0b110Normal Write-Back, regardless of stage 1 (allocation hints from stage 1 if it is Normal cacheable)
0b111The stage-1 attributes, unchanged

MemAttr[3] is RES0 unless FEAT_MTE_PERM uses it (13.6). With guest RAM mapped 0b110, every guest access to RAM is Write-Back cacheable even while the guest’s MMU is off. There are no mismatched aliases with the host, and KVM skips the clean-to-PoC on stage-2 mapping. The cost is that a guest can no longer obtain a genuinely Non-cacheable view of RAM, for example for a non-coherent passthrough device’s buffers. Such regions must be mapped with 0b101 or 0b111 deliberately. Instruction-side maintenance (I-cache invalidation to the PoU, 8.6) is unaffected by FWB.

HCR_EL2.CD, ID and DC

These are older, global overrides.

  • HCR_EL2.CD (bit 32): stage 2 is treated as Normal Non-cacheable for all EL1&0 data accesses and stage-1 walks.
  • HCR_EL2.ID (bit 33): the same for instruction fetches.

These make the whole guest uncacheable without touching stage-2 tables. They are useful as a debugging lever (“does the bug go away if the guest is uncached?”) and not otherwise used by KVM. How CD and ID interact with FWB=1 encodings is spelled out in the HCR_EL2.CD/ID field descriptions. Check them rather than assuming that one override beats the other.

  • HCR_EL2.DC (bit 12, “default cacheable”): the PE behaves as if SCTLR_EL1.M were 0 whatever the guest writes (stage 1 forced off), the default stage-1 attributes become Normal Inner/Outer Write-Back Non-shareable instead of Device-nGnRnE, and HCR_EL2.VM behaves as 1. It suits only a guest that never enables its own MMU, so it was never a general answer to the MMU-off coherency problem. FWB is.

Stage-2 faults

A stage-2 fault is taken to EL2 as an instruction or data abort from a lower EL (EC 0x20/0x24). Decoding is in 5.8. The points specific to stage 2:

  • ESR_EL2.ISS.S1PTW=1 means the fault happened on the guest’s stage-1 walk: the IPA of a guest table descriptor was unmapped or not readable at stage 2. A hypervisor that reports this to the guest as a guest page fault is wrong. It is the hypervisor’s own mapping problem.
  • FAR_EL2 holds the guest VA, and HPFAR_EL2.FIPA holds the faulting IPA bits [51:12] (or [47:12]). HPFAR is valid for stage-2 Translation and Access flag faults and for faults on stage-1 walks. For a stage-2 Permission fault not on a walk, Linux treats HPFAR as possibly invalid and recomputes the IPA with AT S1E1R on the guest VA.
  • MMIO emulation relies on ISS.ISV=1 with SAS, SSE, SRT, SF and WnR. Syndrome is provided only for single general-purpose-register loads and stores without writeback. A guest that touches MMIO with LDP or a post-indexed load gives ISV=0, and the hypervisor must decode the instruction or kill the guest. Guest drivers should use simple LDR/STR for MMIO.

Validation note: the combination table is directly testable. From EL2, run AT S12E1R (or S12E1W) on a guest VA with a chosen stage-1 MAIR attribute and stage-2 MemAttr. PAR_EL1.ATTR and PAR_EL1.SH then report the combined result in MAIR format (the PAR_EL1 description allows the reported attributes to differ from an IMPLEMENTATION DEFINED downgrade the core actually applies, such as WT treated as NC, so treat AT as checking the architectural rule). Sweep the 4×4 matrix of {Device-nGnRnE, NC, WT, WB} for both FWB=0 and FWB=1 and compare with the tables above. A mismatch in a real access path, as opposed to AT, shows up as unexpected L1D refills (L1D_CACHE_REFILL) on a region that should be non-cacheable, or none on one that should be cacheable (16.5).

Checkpoint

Q11.3.1 With HCR_EL2.FWB=0, the guest’s stage 1 maps a buffer as Normal Inner/Outer Write-Back Inner Shareable, and the hypervisor’s stage 2 maps it as Normal Outer Write-Back, Inner Non-cacheable. What is the combined attribute?

  • A. Normal Inner/Outer Write-Back, Inner Shareable, because stage 1 controls cacheability and stage 2 only controls permissions
  • B. Normal Inner/Outer Non-cacheable, Outer Shareable, because any non-cacheable component makes the whole access non-cacheable
  • C. Normal Inner Non-cacheable, Outer Write-Back, with shareability the more shareable of the two descriptors’ SH fields
  • D. Device-nGnRE, because mismatched cacheability is CONSTRAINED UNPREDICTABLE
Answer

C. Inner and outer cacheability are combined separately, each taking the weaker value. Shareability is the more shareable of the two, and forced Outer Shareable only when the result is Device or Non-cacheable at both levels. B wrongly collapses inner and outer. A ignores that stage 2 restricts attributes as well as permissions.

Read more: Arm ARM (DDI0487), “Combining the stage 1 and stage 2 attributes”

Q11.3.2 A hypervisor on a core without FEAT_S2FWB copies a guest kernel into guest RAM through its own Write-Back mapping, maps the RAM at stage 2 as Normal WB, and starts the guest with its MMU off. The guest executes garbage. Which fix is architecturally sufficient?

  • A. Map the guest RAM at stage 2 as Device-nGnRnE so the guest’s accesses are ordered
  • B. Clean the copied range to the PoC (and invalidate the I-cache to the PoU) before running the guest, because the guest’s MMU-off accesses are non-cacheable and bypass the dirty lines
  • C. Set HCR_EL2.CD=1 so that the hypervisor’s own writes become non-cacheable
  • D. Nothing at the hypervisor; the guest must invalidate its caches before turning the MMU on
Answer

B. The combined attribute is the more restrictive one. With the guest’s stage 1 off, data is Device-nGnRnE, so reads go to memory past the host’s dirty lines. Cleaning to the PoC makes memory up to date. The I-cache invalidation is needed because, once the guest enables its I-cache, it could otherwise hit stale instruction lines held for those PAs from earlier use. C affects guest EL1&0 accesses, not the hypervisor’s EL2 writes. D fails because the guest reads its image with the MMU off before it can run any maintenance, so it has already fetched stale DRAM contents. With FWB, mapping 0b110 removes the problem.

Read more: Arm ARM (DDI0487), HCR_EL2.FWB; “Behavior of caches at reset and when caches are disabled”

Q11.3.3 A data abort reaches EL2 with ESR_EL2.ISS.S1PTW=1 and a stage-2 Translation fault DFSC. What does it mean, and what should the hypervisor do?

  • A. The guest’s own page tables have an invalid entry; inject a data abort into the guest
  • B. The guest accessed MMIO; emulate the access using the SRT field
  • C. The fault address in FAR_EL2 is an IPA; map it and retry
  • D. The guest’s stage-1 walk read a descriptor at an IPA that stage 2 does not map; fix or populate the stage-2 mapping of that IPA (from HPFAR_EL2) and retry
Answer

D. S1PTW marks a stage-2 fault during the stage-1 table walk. The faulting IPA is the descriptor’s address, reported in HPFAR_EL2, and the cause lies in the hypervisor’s stage 2, not the guest’s tables (A). FAR_EL2 holds the guest VA of the original access, not an IPA (C). MMIO emulation (B) does not apply to walks.

Read more: Arm ARM (DDI0487), ESR_EL2 ISS encoding for Data Abort (S1PTW); HPFAR_EL2

11.4 Virtualizing exceptions and interrupts

A guest expects to receive IRQs, FIQs and SErrors and to program a GIC CPU interface and a timer. The hypervisor must own the physical versions of all of these. The architecture solves this in three layers: virtual exceptions in the PE (HCR_EL2.VI/VF/VSE), a virtual CPU interface in the GIC driven by list registers (GICv3), and direct injection of virtual LPIs and SGIs by the GIC itself (GICv4/4.1). The virtual timer and CNTVOFF_EL2 complete the picture. GICv3 itself is covered in 4.1–4.4, and routing in 3.3.

Virtual IRQ, FIQ and SError

With HCR_EL2.IMO=1 (FMO, AMO likewise), two things happen: physical IRQs are routed to EL2, and virtual IRQs are enabled for EL1/EL0. A virtual IRQ is pending when HCR_EL2.VI=1 or the GIC’s virtual CPU interface asserts its virtual IRQ signal. The two sources are ORed. The same holds for VF and FIQs.

Virtual exceptions follow these rules:

  • They are taken only at EL1 or EL0, to EL1, through the guest’s VBAR_EL1. They are masked by the guest’s PSTATE.I/F/A. They are never taken at EL2, and they are not taken when HCR_EL2.TGE=1.
  • HCR_EL2.VI and VF are levels. The hypervisor clears them when the guest has dealt with the source. Clearing VI does not “un-take” an exception already taken.
  • Virtual SError (HCR_EL2.VSE, enabled by AMO) is the hypervisor’s way to report an asynchronous abort to a guest, for example a RAS error in guest memory (16.8). With FEAT_RAS, VSESR_EL2 supplies the syndrome that the guest sees in ESR_EL1. VSE is cleared by hardware when the virtual SError is taken. An ESB in the guest can defer it into VDISR_EL2.
  • Superpriority under FEAT_NMI has virtual counterparts in HCRX_EL2.VINMI/VFNMI.

A hypervisor that drives everything through HCR_EL2.VI must emulate a whole interrupt controller, and every guest acknowledge and EOI traps. That is how virtualization worked before GIC virtualization support and on GICs without it. The GIC’s virtual CPU interface removes most of those traps.

GICv3 virtualization: ICV registers and list registers

When HCR_EL2.IMO/FMO=1, guest EL1 accesses to the CPU-interface registers ICC_IAR1_EL1, ICC_EOIR1_EL1, ICC_PMR_EL1, ICC_CTLR_EL1 and so on are redirected to the ICV_* registers, the virtual CPU interface, with no trap. The guest acknowledges, prioritises and EOIs virtual interrupts at full speed. The exceptions are the SGI-generation registers (ICC_SGI1R_EL1, ICC_ASGI1R_EL1, ICC_SGI0R_EL1). They have no virtual counterpart and trap to EL2, because sending an SGI to another vCPU needs the hypervisor to find where that vCPU runs.

The hypervisor feeds the virtual interface through list registers ICH_LR<n>_EL2. There are up to 16, and the implemented count is ICH_VTR_EL2.ListRegs+1.

ICH_LR<n>_EL2 fieldBitsMeaning
vINTID[31:0]The INTID the guest will read from ICV_IAR
pINTID[44:32]With HW=1, the physical INTID linked to this virtual one. With HW=0, bit 41 is EOI (request a maintenance interrupt on deactivation)
Priority[55:48]Virtual priority
Group[60]Virtual Group 0 (vFIQ) or Group 1 (vIRQ)
HW[61]Hardware-linked: guest deactivation also deactivates pINTID
State[63:62]00 invalid, 01 pending, 10 active, 11 pending and active

The flow for a passthrough or hardware-linked interrupt such as the virtual timer:

  1. The physical interrupt fires and is taken at EL2. The hypervisor acknowledges it but does not deactivate it. With ICC_CTLR_EL1.EOImode=1 at EL2, priority drop and deactivation are split.
  2. It writes a list register: vINTID, pINTID, HW=1, State=pending.
  3. On guest entry the virtual CPU interface signals a vIRQ. The guest reads ICV_IAR1_EL1, handles the interrupt, and writes ICV_EOIR1_EL1 (and ICV_DIR_EL1 if it uses EOImode=1).
  4. Because HW=1, the guest’s deactivation also deactivates the physical interrupt. No trap is needed, and the physical interrupt cannot fire again before the guest has handled it.

The other ICH_* registers:

  • ICH_HCR_EL2: En (enable the virtual interface), maintenance-interrupt enables (UIE, LRENPIE, NPIE, VGrp0EIE/VGrp0DIE/VGrp1EIE/VGrp1DIE), trap controls (TC, TALL0, TALL1, TDIR), and EOIcount.
  • ICH_VMCR_EL2: the guest’s view of its PMR, BPR and group enables, saved and restored on vCPU switch.
  • ICH_AP0R<n>_EL2/ICH_AP1R<n>_EL2: active-priority bits, also part of vCPU state.
  • ICH_ELRSR_EL2 (empty LRs), ICH_EISR_EL2 (LRs with an EOI maintenance request), ICH_MISR_EL2 (why a maintenance interrupt fired).

Maintenance interrupts are a PPI (INTID 25 by BSA convention) raised by the virtual interface to tell the hypervisor that its list registers need attention. Typical causes: an LR with EOI=1 was deactivated (a level-triggered emulated interrupt, so the hypervisor can resample the line); the LRs are nearly empty (UIE, underflow), so more pending interrupts can be loaded; or the guest EOIed an interrupt that was not in any LR (LRENPIE, counted in EOIcount), which means it overflowed the LRs. They are what lets the hypervisor run with more pending virtual interrupts than there are list registers.

Validation note: test the HW=1 path explicitly. Inject the physical virtual-timer PPI through an LR with HW=1, let the guest EOI it, and check with GICR_ISACTIVER0 that the physical PPI’s active state cleared without an EL2 trap. A GIC or model that fails to propagate the deactivation leaves the PPI active forever, and the guest’s timer “fires once and never again”. That is a common pre-silicon GIC integration bug, and it is easy to misdiagnose as a timer problem.

GICv4 and GICv4.1: direct injection

List registers still need the hypervisor on every interrupt delivery. For a passthrough device’s MSIs, GICv4 lets the ITS (4.4) deliver virtual LPIs directly to a vPE with no hypervisor involvement.

  • The hypervisor creates a vPE (VPEID) per vCPU. VMAPP maps it to a target Redistributor and a virtual pending table. VMAPTI/VMAPI map a device’s EventID to a vINTID on that vPE. VMOVP and VMOVI move vPEs and individual interrupts, and VINVALL/VSYNC synchronise.
  • On scheduling a vCPU, the hypervisor makes its vPE resident on the physical Redistributor by writing GICR_VPENDBASER (with Valid=1) and, in v4.0, GICR_VPROPBASER. Virtual LPIs for a resident vPE are presented through the virtual CPU interface like LR-delivered interrupts, without using an LR.
  • A vLPI for a non-resident vPE is recorded in its virtual pending table. A doorbell, a physical LPI to the hypervisor, can then wake the vCPU. In GICv4.0 the doorbell is per vLPI. In GICv4.1 it is per vPE (a default doorbell), which is cheaper to manage.

GICv4.1 also restructures the residency interface. Redistributors share a vPE configuration table described through GICR_VPROPBASER (with a v4.1 layout), and GICR_VPENDBASER selects the vPE by ID. The hypervisor must poll the Dirty bit after making a vPE resident. The other major addition is direct injection of vSGIs. The sender’s ICC_SGI1R_EL1 write still traps to EL2, but the hypervisor then writes GITS_SGIR (VPEID and vINTID) and the GIC delivers the vSGI to the target vPE directly, whether or not it is resident, with no LR management on the receive side. The price is that such vSGIs have no Active state. Support is advertised by GICD_TYPER2.nASSGIcap, and the guest requests active-less SGIs through its emulated GICD_CTLR.nASSGIreq.

Bring-up note: GICv4 support needs the ITS, the Redistributors’ VLPI support (GICR_TYPER.VLPIS, plus the v4.1 bits), memory for vPE and virtual pending tables, and coherent ITS table walks. On a multi-chip GIC, VMOVP must reach every ITS that maps the vPE. Linux’s KVM keeps GICv4 direct injection disabled unless asked (kvm-arm.vgic_v4_enable), so “MSIs work in the guest” does not show that direct injection works. Check the doorbell and residency paths separately.

The virtual timer and CNTVOFF_EL2

The guest’s natural timer is the EL1 virtual timer (CNTV_CTL_EL0, CNTV_CVAL_EL0, PPI 27). Its counter is:

CNTVCT_EL0 = CNTPCT_EL0 - CNTVOFF_EL2

The hypervisor sets CNTVOFF_EL2 per VM so that guest time starts near zero and stays continuous across save/restore or migration. It also traps the physical counter and timer (CNTHCTL_EL2.EL1PCTEN/EL1PCEN, with the E2H-dependent layout from 11.2) so that guests cannot see or program physical time. FEAT_ECV (v8.6) adds CNTPOFF_EL2, a physical-counter offset enabled by CNTHCTL_EL2.ECV (with SCR_EL3.ECVEn). It lets the guest use the EL1 physical timer too, which nested virtualization needs (4.6).

Offset rules under VHE: CNTVOFF_EL2 is not applied to CNTVCT_EL0 reads at EL2 when HCR_EL2.E2H=1, or at EL0 when {E2H,TGE}={1,1}. The host sees the virtual counter equal to the physical one, and the offset applies only to the guest. The host’s own timers are the EL2 physical and virtual timers (CNTHP_*, PPI 26; CNTHV_*, PPI 28), reached through the redirected CNTP_*/CNTV_* names (11.2).

On a vCPU switch the hypervisor saves CNTV_CTL/CNTV_CVAL through the _EL02 aliases under VHE. If the guest timer is armed, it sets a host software timer for the same deadline to wake the vCPU. While the guest runs, the virtual timer PPI fires to EL2 and is injected through an LR with HW=1, as above.

Checkpoint

Q11.4.1 A hypervisor takes the physical virtual-timer PPI at EL2, acknowledges and deactivates it straight away (EOImode=0), and injects vINTID 27 through a list register with HW=0. The guest is never scheduled again, because EL2 is flooded with the same PPI. Why, and what is the architectural fix?

  • A. The timer PPI is level-sensitive and its condition stays true until the guest reprograms CNTV_CVAL/CTL, so it reasserts as soon as it is deactivated. Keep the physical interrupt active (EOImode=1, priority drop only) and inject with HW=1, so that the guest’s deactivation deactivates it
  • B. The virtual timer cannot be injected through list registers; it must use HCR_EL2.VI
  • C. CNTVOFF_EL2 was not set, so the timer comparison is always true
  • D. The LR priority is lower than the guest’s ICV_PMR_EL1, so the interrupt stays pending and retriggers
Answer

A. A level-sensitive interrupt that is deactivated while its line is still asserted becomes pending again at once. The line drops only when the guest handles the timer. With HW=1 the physical interrupt stays active until the guest deactivates the virtual one, so it cannot retrigger at EL2 meanwhile. KVM does this, or masks the physical timer while the interrupt is in flight. D would hold the virtual interrupt pending in the LR, but it would not re-interrupt EL2. C changes when the timer fires, not whether a handled interrupt retriggers.

Read more: GICv3/4 architecture specification (IHI0069), ICH_LR<n>_EL2 and hardware-linked virtual interrupts

Q11.4.2 In a GICv4.0 system, a passthrough NIC raises an MSI for a vCPU that is currently descheduled. What happens?

  • A. The ITS drops the vLPI, because the vPE is not resident
  • B. The vLPI is delivered to whichever physical PE last ran the vCPU, as a physical LPI
  • C. The vLPI is set pending in the vPE’s virtual pending table, and if a doorbell is configured, a physical doorbell LPI tells the hypervisor to schedule the vCPU
  • D. The ITS stalls the write until the vPE becomes resident
Answer

C. Virtual pending state lives in memory, in the virtual pending table, and is not lost. The doorbell is the mechanism that wakes a non-resident vCPU. In v4.1 the doorbell is per vPE instead of per vLPI. Nothing is delivered as a physical interrupt to the guest’s old CPU (B), and the ITS does not stall the device (D).

Read more: GICv3/4 architecture specification (IHI0069), “Direct injection of virtual LPIs” and “Doorbell interrupts”

Q11.4.3 A VHE host reads CNTVCT_EL0 at EL2 while CNTVOFF_EL2 holds a guest’s large offset. What value does it see, and why?

  • A. CNTPCT_EL0 - CNTVOFF_EL2, because the virtual counter always includes the offset
  • B. The physical count, because with E2H=1 the offset is not applied to EL2 reads, so the host is not skewed by the guest’s offset
  • C. An UNKNOWN value, because CNTVOFF_EL2 must be zero while E2H=1
  • D. The access traps, because CNTHCTL_EL2.EL1PCTEN=0
Answer

B. Under VHE, the virtual offset is ignored at EL2, and at EL0 with TGE=1, so the hypervisor can leave a guest’s CNTVOFF_EL2 loaded while the host runs. A is the rule for the guest at EL1/EL0 with TGE=0. EL1PCTEN controls EL1 access to the physical counter, not EL2 reads of the virtual one (D).

Read more: Arm ARM (DDI0487), CNTVCT_EL0 and CNTVOFF_EL2; “The Generic Timer in AArch64 state”

11.5 The SMMU (SMMUv3)

The SMMU is the I/O MMU of an Arm system. It applies stage 1 and/or stage 2 translation, permissions and attributes to transactions from DMA masters, using page tables in the same formats as the PE. It is specified separately in IHI0070 (SMMUv3.x), not in DDI0487, and it is a memory-mapped device programmed through registers, in-memory tables and queues, not through system registers. For an EL3/TEE reviewer, the SMMU is what makes “the device can only reach its buffers” true. For bring-up, it is where most “DMA works with the SMMU in bypass but not in translate” bugs live.

Identifying a transaction: StreamID and SubstreamID

Every transaction that enters the SMMU carries:

  • a StreamID (SID), which identifies the master. For PCIe it is derived from the Requester ID (bus/device/function), for other masters from interconnect sideband signals. How SIDs are allocated is a system integration decision, described to software by the ACPI IORT ID mappings or the device tree iommus/iommu-map properties.
  • optionally a SubstreamID (SSID), which identifies an address space within the master. It is the PCIe PASID, used for shared virtual addressing.
  • a Security indication (SEC_SID). Secure streams use a separate Secure programming interface (SMMU_S_*) and Secure stream table. With RME, Realm and granule-protection checks apply as well (12.4).

Stream table and context descriptors

SMMU_STRTAB_BASE and SMMU_STRTAB_BASE_CFG (FMT, LOG2SIZE, SPLIT) locate the stream table. It is either linear, an array of 64-byte Stream Table Entries indexed by SID, or two-level, with a level-1 array of descriptors pointing to level-2 STE arrays, so that sparse 16-bit or larger SID spaces do not need megabytes of STEs. SMMU_IDR0.ST_LEVEL and SMMU_IDR1.SIDSIZE say what is supported.

An STE says what happens to the stream:

STE fieldPurpose
VValid. An invalid STE makes the stream’s transactions abort with a C_BAD_STE event
Config0b000 abort, 0b100 bypass, 0b101 stage 1 only, 0b110 stage 2 only, 0b111 nested (stage 1 then stage 2)
S1ContextPtr, S1Fmt, S1CDMaxBase of the context-descriptor table (an IPA if stage 2 is also enabled), its format, and the number of SSIDs
S2VMID, S2TTB, S2T0SZ, S2SL0, S2TG, S2PS, S2AA64, S2R, S2SStage-2 configuration, mirroring VTCR_EL2/VTTBR_EL2, plus record and stall fault behaviour
EATSWhether ATS translation requests are allowed (see below)
STRWWhich translation regime stage 1 belongs to (EL1, EL2, EL2-E2H), and hence which TLBI commands invalidate it
SHCFG, MTCFG/MemAttr, ALLOCCFG, INSTCFG, PRIVCFGOverrides for the incoming transaction’s shareability, memory type, allocation, instruction/data and privilege attributes

A Context Descriptor (CD, 64 bytes) describes one stage-1 address space and is indexed by SSID. It holds TTB0/TTB1, T0SZ/T1SZ, TG0/TG1, IPS, EPD0/1, ASID, MAIR, the walk attributes, AA64, HA/HD, and the fault controls R (record) and S (stall). A CD can point at the same page tables as a CPU process, which is how shared virtual addressing works. CD tables are linear or two-level too, as S1Fmt selects.

  SID ──► Stream table ──► STE ──Config=0b111──► CD table[SSID] ──► CD ──► stage-1 tables (IPA)
                              │                                                  │
                              └──────────► S2TTB, S2VMID ──► stage-2 tables ◄───┘ (walks also translated)

Nested mode (0b111) is how a guest gets a virtual IOMMU. The guest owns the CD and stage-1 tables at IPAs, the hypervisor owns the STE and stage 2, and the CD-table fetches and stage-1 walks are themselves translated by stage 2, exactly as on the PE (11.3).

Queues, invalidation and faults

Software never writes the SMMU’s internal caches directly. It talks to the SMMU through circular queues in memory, each with PROD/CONS index registers:

  • Command queue (SMMU_CMDQ_BASE, SMMU_CMDQ_PROD/CONS). Configuration-cache invalidation (CMD_CFGI_STE, CMD_CFGI_CD, CMD_CFGI_ALL), TLB invalidation (CMD_TLBI_NH_VA, CMD_TLBI_NH_ASID, CMD_TLBI_S2_IPA, CMD_TLBI_S12_VMALL, CMD_TLBI_EL2_*, CMD_TLBI_NSNH_ALL), CMD_ATC_INV, CMD_PRI_RESP, CMD_RESUME, and CMD_SYNC. The SMMU may process commands in any order up to a CMD_SYNC. A CMD_SYNC completes only when all earlier commands have completed and their effects are visible. Completion is signalled by MSI write, by SEV, or by polling CONS. “Wrote a CMD_TLBI” is therefore not “the TLB is clean”. “CMD_SYNC completed” is.
  • Event queue (SMMU_EVENTQ_BASE). Faults and configuration errors: C_BAD_STREAMID (SID beyond the table), F_STE_FETCH, C_BAD_STE, F_STREAM_DISABLED, C_BAD_SUBSTREAMID, F_CD_FETCH, C_BAD_CD, F_WALK_EABT, F_TRANSLATION, F_ADDR_SIZE, F_ACCESS, F_PERMISSION, F_TLB_CONFLICT. Each record carries the SID, SSID, input address and, for stage 2, the IPA.
  • PRI queue, for PCIe Page Request Interface requests (below).
  • SMMU_GERROR with SMMU_GERRORN reports global errors such as a command-queue error (SMMU_CMDQ_CONS.ERR gives the reason) or an abort on an event-queue or MSI write. Event-queue overflow is not a global error: it is flagged by SMMU_EVENTQ_PROD.OVFLG.

The update protocol is the I/O analogue of break-before-make (9.2). Write the STE, CD or page-table entry; make it visible to the SMMU’s table walker (a DSB if the SMMU is coherent, a clean to the PoC first if not); issue the CFGI or TLBI command; then CMD_SYNC and wait for it. An STE with live traffic must be changed so that the SMMU never sees a torn 64-byte entry. Linux’s driver writes the non-V words first, or goes through an abort STE.

Control is in SMMU_CR0 (SMMUEN, EVTQEN, CMDQEN, PRIQEN, ATSCHK, VMW), with each change acknowledged in SMMU_CR0ACK, which software must poll. SMMU_CR1 sets the cacheability and shareability of table walks and queue accesses. SMMU_CR2 has E2H, RECINVSID and PTM. While SMMUEN=0, all traffic either bypasses or aborts according to SMMU_GBPA.ABORT.

ATS and PRI

ATS (PCIe Address Translation Services) lets an endpoint cache translations in its own Address Translation Cache (ATC). The endpoint sends a translation request, which the SMMU answers if STE.EATS allows it, and then issues transactions marked translated. Those transactions carry PAs, and the SMMU passes them without a walk. With split-stage ATS (STE.EATS=0b10), they carry IPAs and still go through stage 2. Two consequences follow:

  • Invalidation reaches into the device. After unmapping, software must issue CMD_ATC_INV to send an ATS invalidation to the endpoint, then CMD_SYNC, which waits for the endpoint’s completion. A buggy endpoint ATC turns into a use-after-unmap DMA.
  • Trust. A device that is allowed ATS can claim any address is “translated”. SMMU_CR0.ATSCHK (where implemented) and stage-2-checked EATS modes reduce what a malicious endpoint can reach, but a device with ATS enabled is part of the trusted computing base. Confidential-computing device assignment adds TDISP/IDE for this reason.

PRI (Page Request Interface) lets an ATS-capable endpoint ask for a page that is not mapped, instead of faulting. Requests arrive on the PRI queue. Software maps the page and answers with CMD_PRI_RESP. Non-PCIe masters can get a similar effect with the stall model: a faulting transaction is held (CD.S/STE.S2S), reported in the event queue, and resumed or terminated with CMD_RESUME. The master must tolerate arbitrarily long stalls, which few do. SMMU_IDR0.STALL_MODEL says what the implementation supports.

Coherency attributes

The SMMU accesses memory in two roles, and each has its own attributes.

  1. Its own structures: the stream table, CDs, page tables and queues. If SMMU_IDR0.COHACC=1 and the system integrates the SMMU as an I/O-coherent agent, these accesses can be Inner Shareable Write-Back (SMMU_CR1, CD/STE walk attributes), and software only needs a DSB before issuing commands. Otherwise software must clean every updated structure to the PoC (8.7). Firmware describes this with the IORT COHACC override or the DT dma-coherent property. A description that claims coherency the interconnect does not provide gives stale STEs and page tables, and the failures are intermittent.
  2. The translated DMA. Its output attributes combine the page-table attributes with the incoming transaction’s attributes. The STE MTCFG/SHCFG/ALLOCCFG fields can override incoming attributes before combination. A master that issues non-coherent transactions can be made coherent this way, but only if the interconnect path behind the SMMU actually snoops.

Broadcast TLB maintenance (BTM). If SMMU_IDR0.BTM=1 and the SMMU is in the DVM domain, CPU TLBI ...IS instructions also invalidate matching SMMU TLB entries (by ASID/VMID), so shared CPU/SMMU page tables need no command-queue TLBI. SMMU_CR2.PTM=1 opts out. If the platform does not wire DVM to the SMMU, the driver must use commands even when BTM is advertised.

Bring-up mistakes that matter

SymptomUsual causeFirst check
All DMA aborts at boot, before any driver loadsSMMU_GBPA.ABORT=1 from reset or firmware, SMMUEN=0SMMU_GBPA, and whether early boot relies on bypass
C_BAD_STREAMID or C_BAD_STE for one deviceIORT/DT SID mapping wrong, or SID beyond LOG2SIZEEvent record SID vs the table and the integration spec
Device works only after something else flushes cachesNon-coherent SMMU described as coherent, so structures not cleanedSMMU_IDR0.COHACC, IORT/DT coherency, SMMU_CR1 attributes
Stale translations after unmapMissing CMD_SYNC, or CMD_ATC_INV omitted with ATSCommand-queue sequence; ATS enabled?
Commands stop, SMMU_GERROR.CMDQ_ERRMalformed command, or command-queue memory not reachable or coherentSMMU_CMDQ_CONS.ERR
PCIe MSIs never arrive once translatedITS doorbell (GITS_TRANSLATER) not mapped in the device’s address spaceIOVA mapping for the MSI page (4.4)
Firmware-era DMA continues into the OSFirmware left Config=bypass STEs or SMMUEN=0 with GBPA bypassSecurity review: what the handoff state allows

A clean initialisation from firmware or the driver follows a fixed order. Program the queue and table bases with SMMUEN=0. Enable the queues (CMDQEN, EVTQEN) and poll CR0ACK. Issue CMD_CFGI_ALL, CMD_TLBI_NSNH_ALL and CMD_TLBI_EL2_ALL, then CMD_SYNC, because cached configuration at reset is not guaranteed empty. Only then set SMMUEN. The TCU/TBU split of implementations such as Arm’s MMU-600/700, with distributed TBUs next to masters and a central TCU that walks, is IMPLEMENTATION DEFINED. It matters for placement and for DVM connectivity, not for the programming model.

Security note: at the firmware-to-OS handoff, any stream left in bypass is a DMA path around everything the TEE assumed. TF-A and secure firmware should leave the Non-secure SMMU either disabled with GBPA.ABORT=1 or configured with only the streams that firmware itself needs, and they should configure the Secure SMMU interface for any Secure masters. Review the STE Config of each stream, not only SMMUEN.

Validation note: drive each StreamID with a directed DMA to an unmapped IOVA and check that the event queue records F_TRANSLATION with the expected SID and input address. That single test validates SID routing, STE lookup and fault reporting. Use the SMMU’s PMCG (performance monitor counter groups) to confirm that TLB misses and walks occur where expected (16.5).

Checkpoint

Q11.5.1 A driver unmaps a DMA buffer by clearing the page-table entry, issues CMD_TLBI_NH_VA for the IOVA, and immediately frees the page. Occasionally the device writes to the freed page. The SMMU is coherent and ATS is not used. What is missing?

  • A. A DSB SY after writing the command to the queue
  • B. A CMD_SYNC after the TLBI, waiting for its completion, before freeing the page, because commands complete asynchronously
  • C. A CMD_CFGI_STE, because TLB entries are cached in the STE
  • D. Nothing; the SMMU completes each TLBI before consuming the next command
Answer

B. Writing PROD only queues the command. The SMMU may still hold the old translation, and in-flight transactions that used it may still be outstanding, until a later CMD_SYNC completes. The driver does need a barrier between writing the queue entry and updating PROD, but that does not wait for the SMMU. The STE is configuration, not a TLB, so C does not help. D is false: the specification allows commands before a CMD_SYNC to be processed and complete in any order.

Read more: SMMUv3 specification (IHI0070), “CMD_SYNC” and “Command queue”

Q11.5.2 A platform’s IORT marks the SMMU as coherent (COHACC), but the interconnect does not route its table walks through the coherent path. Which failure fits best?

  • A. Every transaction aborts with C_BAD_STREAMID
  • B. SMMU_CR0ACK never acknowledges SMMUEN
  • C. DMA is permanently slow because walks miss in the CPU caches
  • D. Intermittent use of stale STEs, CDs or PTEs. The driver skips cleaning to the PoC, so the SMMU reads old memory contents while new ones sit in CPU caches
Answer

D. When software believes the SMMU is coherent, it only issues a DSB after updating structures. A non-snooping walker reads DRAM and sees whatever was last written back. The result depends on cache eviction timing, so it is intermittent. A would need a wrong SID or table size. B concerns register handshakes, not memory coherency.

Read more: SMMUv3 specification (IHI0070), SMMU_IDR0.COHACC and SMMU_CR1; Arm DEN0049 (IORT), SMMUv3 node flags

Q11.5.3 A hypervisor gives a guest a virtual IOMMU using STE Config=0b111. The guest writes a CD whose TTB0 is an IPA. Who translates the address the SMMU uses to fetch the guest’s stage-1 descriptors?

  • A. Nobody; the SMMU treats TTB0 as a PA in nested mode
  • B. The guest’s stage 1, recursively
  • C. The STE’s stage 2, because in nested mode CD fetches and stage-1 walks are themselves IPAs translated by stage 2
  • D. The CPU’s VTTBR_EL2, through broadcast TLB maintenance
Answer

C. Nested translation in the SMMU follows the PE: the guest’s CD pointer, TTB0 and table descriptors are IPAs, and the SMMU translates them through the stage 2 named by S2TTB/S2VMID. A fault there is reported as a stage-2 fault on a stage-1 walk. The SMMU does not use the CPU’s system registers (D). BTM affects invalidation, not which tables are walked.

Read more: SMMUv3 specification (IHI0070), “Stage 1 and stage 2 translation” and STE.Config

Part 12: Secure world, firmware and RME

Review part: concise and register-precise, for readers who already know this material.

Prerequisites: 2.1, 3.3, 4.3, 5.1, 8.4, 9.1

If you already know: OP-TEE, TF-A BL31 and SMCCC from TEE work, skim 12.1–12.3 for the register-level precision and the FF-A material, then read 12.4 and 12.5 in full.

Why this matters for bring-up/validation: every boot stage, every SMC and every granule transition is a contract between privilege levels, and when a contract is broken you get the faults that are hardest to triage: a hang at the first ERET, a GPF at EL3, or silently corrupted Realm memory.

Part 12 starts from the security model you already work in and makes it exact. It first restates TrustZone-A at register level: what SCR_EL3.NS and SCR_EL3.NSE select, what is architectural and what belongs to the system (TZASC), and what Secure EL2 adds. It then sets out the state each boot stage must hand to the next, using TF-A’s BL1/BL2/BL31/BL32/BL33 chain as the worked example. After that it covers the firmware interfaces that carry calls across the boundaries: SMCCC, PSCI and FF-A.

The second half covers what Armv9 adds. RME turns the two-world model into four physical address spaces, enforced by a Granule Protection Table that EL3 owns. Changing which world owns a granule then becomes a cache, TLB and barrier problem, which is where the memory-system material of Parts 7–9 comes back. FEAT_MEC goes further and splits the Realm PAS into many encryption contexts, which adds the Point of Encryption and a new set of cache-maintenance rules.

12.1 TrustZone-A recap, precisely

TrustZone-A is two separate mechanisms that usually get described as one. The first is the Security state of the PE, which decides which system registers, translation regimes and exception routing are in force. The second is the physical address space (PAS) that each access targets, which is an extra address bit carried through caches, TLBs and the interconnect. The PE architecture defines both. Which physical memory a given PAS can actually reach is a system property, outside the Arm ARM.

Security state: SCR_EL3.NS and SCR_EL3.NSE

EL3 is always Secure (Root, when RME is implemented). The Security state of EL2, EL1 and EL0 comes from SCR_EL3:

SCR_EL3.NSE (bit 62)SCR_EL3.NS (bit 0)Lower-EL Security state
00Secure
01Non-secure
10Reserved
11Realm (FEAT_RME only)

Without FEAT_RME, NSE is RES0 and only NS matters. The value that counts is the one in force at the ERET (or other exception return) that leaves EL3. Changing SCR_EL3.NS while you stay at EL3 does not change EL3’s own state. It does change which copy of banked state EL3’s own accesses reach: for example, which ICC_* Group 1 registers MSR reaches, and the Security state used by AT S12E1R-style operations issued from EL3. Treat SCR_EL3 writes as context-changing: an ISB is needed before EL3 code that relies on the new value (7.8).

The other world-relevant SCR_EL3 controls you already know:

FieldBitEffect
IRQ, FIQ, EA1, 2, 3Route physical IRQ/FIQ/SError and External aborts to EL3
SMD7SMC is UNDEFINED at EL1, EL2 and EL3 (an HCR_EL2.TSC trap from EL1 takes priority)
HCE8HVC enabled
SIF9Secure state cannot fetch instructions from the Non-secure PAS
RW10Next-lower EL is AArch64
ST11Secure EL1 may access CNTPS_*_EL1 (otherwise trapped to EL3)
EEL218Secure EL2 enabled (FEAT_SEL2)
GPF48GPFs from EL0–EL2 taken to EL3 (FEAT_RME, see 12.4)

Most system registers below EL3 are not banked by Security state in AArch64. There is one SCTLR_EL1, one TTBR0_EL1, one VBAR_EL2. EL3 firmware must save and restore them on every world switch. This is the job of TF-A’s cm_el1_sysregs_context_save/restore(), and of the EL2 equivalents when CTX_INCLUDE_EL2_REGS is set (as it is when an SPMC runs at S-EL2 or the RMM at R-EL2). The real banking is in the GIC CPU interface (some ICC_* state, such as ICC_IGRPEN1_EL1, ICC_BPR1_EL1 and ICC_CTLR_EL1, has Secure and Non-secure copies). The Secure timers (CNTPS_*, and with FEAT_SEL2 CNTHPS_*/CNTHVS_*) are separate registers, not banked copies. This differs from AArch32, where many CP15 registers are banked, and it is why “forgot to switch register X” is a classic EL3 review finding.

The PAS: NS as an address bit

Every physical access carries a PAS identifier. In a two-world system that is the NS bit. Secure state may target either PAS: stage 1 descriptors in a Secure translation regime have an NS bit (bit 5 in block and page descriptors), and NSTable in table descriptors forces NS on everything below. Non-secure state can only target the Non-secure PAS, and the descriptor NS bit is ignored.

The rule that matters for the memory system: Secure PA 0x8000_0000 and Non-secure PA 0x8000_0000 are different locations as far as caches and TLBs are concerned. Cache lines and TLB entries are tagged with the PAS, so there is no architectural coherency between the two aliases, even if the system maps both to the same DRAM byte. Mapping a buffer Secure in one world and Non-secure in another is therefore an aliasing bug of the kind 6.6 describes. Shared buffers must be Non-secure in both worlds: OP-TEE maps its NS shared memory with NS=1.

TLB entries are also tagged with the translation regime and Security state, so a Secure EL1&0 entry is never used for a Non-secure EL1&0 lookup. TLBI instructions affect only the Security state of the regime they target: a TLBI VMALLE1IS issued at Secure EL1 does not touch Non-secure entries.

Security note: SCR_EL3.SIF is cheap insurance. If an S-EL1 mapping is accidentally NS and executable, the Normal world can plant code that Secure state will run. With SIF=1 such a fetch takes a Permission fault instead. It complements, and does not replace, SCTLR_EL1.WXN and a correct NS bit.

Secure memory: the TZASC is not architectural

The Arm ARM defines the two PASes. It says nothing about which DRAM is reachable through which PAS. That is the job of the system:

  • A TrustZone Address Space Controller (TZASC; Arm’s TZC-400 is the common example) sits in front of each DRAM port and checks every transaction’s NS attribute (AxPROT[1] on AXI, where 1 means Non-secure, or the CHI NS field) against per-region rules. It can also check a per-master ID (NSAID on TZC-400). A failed check typically returns a bus error (SLVERR/DECERR), which reaches the PE as an External abort or SError (3.4), or the read returns zeros, depending on how the TZC is configured.
  • A TrustZone Protection Controller (TZPC) or equivalent gates peripherals.
  • Non-PE masters drive NS themselves, or have it set by the SMMU’s stream configuration (11.5).

So “this region is Secure” means three settings agree: the TZASC region is configured, the Secure-world mappings use NS=0, and no Non-secure mapping reaches it with a PAS the TZASC lets through. Firmware (TF-A BL2 or BL31 platform code) programs the TZASC early and locks it if it can. RME replaces this with the PE-side Granule Protection Check, which works at granule size and can change at run time (12.4).

Bring-up note: a TZASC configured too late or too tightly looks like a memory-system bug. BL2 loads BL32 into DRAM and then BL31’s first access takes an SError. Before you suspect DDR training, check the TZC’s fault status registers (on TZC-400, INT_STATUS and the per-filter FAIL_ADDRESS_LOW/FAIL_ADDRESS_HIGH/FAIL_CONTROL/FAIL_ID) and its ACTION setting.

Secure EL2 (FEAT_SEL2)

FEAT_SEL2 (permitted from v8.4) adds EL2 to Secure state, enabled by SCR_EL3.EEL2. When EEL2=0, Secure state has only EL1 and EL0 (plus EL3), and Secure EL1&0 has no stage 2.

With EEL2=1, the Secure EL1&0 regime gets a stage 2 translation, and that stage 2 has two IPA spaces:

  • The Secure stage 1 descriptor NS bit now selects the IPA space (Secure IPA or Non-secure IPA), not the PA space directly.
  • Secure IPA space is translated through VSTTBR_EL2/VSTCR_EL2. Non-secure IPA space is translated through VTTBR_EL2/VTCR_EL2, the same registers the Non-secure hypervisor uses, so EL3 must context-switch them.
  • The output PAS is controlled by VSTCR_EL2.SW/SA for Secure IPA space and VTCR_EL2.NSW/NSA for Non-secure IPA space: *W covers the stage 2 walks, *A the final accesses.

All the usual EL2 machinery (HCR_EL2, VBAR_EL2, the GIC virtual interface) also exists in Secure state. Because the registers are shared, EL3 context-switches the whole EL2 register set when it switches between Secure EL2 and Non-secure EL2.

The secure partition model

Secure EL2 exists to stop the Secure world being one large trusted blob. Instead of a single Trusted OS at S-EL1 with authority over all Secure memory, an SPMC (Secure Partition Manager Core) runs at S-EL2 and isolates secure partitions (SPs) at S-EL1 and S-EL0, each confined by its own stage 2. The Arm reference is Hafnium. OP-TEE becomes one SP among several. The EL3 component that forwards calls between worlds is the SPMD, a dispatcher in BL31. The messaging, memory-sharing and partition-ID rules come from FF-A and are covered in 12.3. Without FEAT_SEL2 there are two fallbacks: an SPMC at S-EL1 (OP-TEE can act as one) or one at EL3 (TF-A’s EL3 SPMC hosting S-EL0 partitions such as StandaloneMM). Either gives weaker isolation.

For interrupts, the secure partition model rests on the GICv3 group split described in 4.3. Group 0 and Secure Group 1 are signalled as FIQ while Non-secure state runs, and SCR_EL3.FIQ=1 brings them to EL3 so the SPMD can hand them to the SPMC.

Checkpoint

Q12.1.1 OP-TEE at S-EL1 maps a 4 KB buffer with NS=0. The Linux driver maps the same DRAM address with its normal Non-secure mapping, and the TZASC lets Non-secure accesses through. Both sides read and write the buffer with caches enabled. What does the architecture guarantee?

  • A. Coherency, because both mappings are Inner Shareable Write-Back and refer to the same PA
  • B. Coherency, as long as both sides use DMB ISH around their accesses
  • C. Nothing: Secure PA X and Non-secure PA X are different physical locations to the caches, so the two views can diverge until explicit maintenance (and even then only through IMPLEMENTATION DEFINED aliasing in the system)
  • D. A synchronous External abort on the Non-secure access, because the PE detects the alias
Answer

C. The PAS is part of the physical address. Cache lines tagged Secure and Non-secure for the same numeric PA are unrelated locations, so the coherency protocol never connects them. A barrier orders accesses but cannot make two different locations coherent (B). The PE does not detect aliases (D). The correct design maps the shared buffer NS=1 from the Secure side as well.

Read more: Arm ARM (DDI0487), Security state and physical address spaces; Mismatched memory attributes

Q12.1.2 On a FEAT_SEL2 system with SCR_EL3.EEL2=1, an S-EL1 partition’s stage 1 descriptor has NS=1. What happens to the access?

  • A. It produces a Non-secure IPA, which is translated by the stage 2 tables at VTTBR_EL2, with the output PAS controlled by VTCR_EL2.NSA
  • B. It goes directly to the Non-secure PAS, bypassing stage 2, as it would without Secure EL2
  • C. It is translated by VSTTBR_EL2, and NS=1 is ignored because Secure stage 2 always outputs Secure PAs
  • D. It takes a stage 1 Permission fault because S-EL1 may not generate Non-secure addresses under an SPMC
Answer

A. With Secure EL2 enabled, the stage 1 NS bit selects the IPA space. Non-secure IPA space uses VTTBR_EL2/VTCR_EL2, with NSW/NSA selecting the output PAS for walks and accesses. B describes the EEL2=0 behaviour. This is also why EL3 must context-switch VTTBR_EL2: the Secure and Non-secure worlds both use it.

Read more: Arm ARM (DDI0487), VSTCR_EL2, VTCR_EL2, Secure EL2 and the Secure EL1&0 translation regime

Q12.1.3 An EL3 world-switch routine saves and restores SCTLR_EL1, TTBR0/1_EL1, TCR_EL1, MAIR_EL1, VBAR_EL1, SP_EL1, ELR_EL1 and SPSR_EL1, but not CONTEXTIDR_EL1 or TPIDR_EL1. Secure EL2 is not implemented. Which statement is correct?

  • A. This is fine: those two registers are banked by Security state in AArch64
  • B. This is fine: TLB entries are tagged by Security state, so a stale CONTEXTIDR_EL1 cannot cause harm
  • C. It is only a problem if the Secure world also uses ASIDs
  • D. It is a bug: neither register is banked, so one world’s value leaks into, and can be overwritten by, the other world
Answer

D. AArch64 EL1 system registers have a single copy shared by both Security states, so EL3 must switch everything either world uses. TPIDR_EL1 holds a per-CPU pointer in both Linux and OP-TEE, so the result is an information leak plus corruption. TLB tagging (B) protects translations, not register contents, and CONTEXTIDR_EL1 is also read by trace and debug.

Read more: Arm ARM (DDI0487), AArch64 system register descriptions (banking by Security state); TF-A cm_el1_sysregs_context_save

12.2 The architectural contract of a secure boot chain

A boot chain is a series of handovers. At each one, the outgoing stage hands over control of the PE with some state defined and the rest UNKNOWN. The incoming stage may assume only what was agreed. Most “it worked on FVP and hangs on silicon” bugs are a broken handover: the next stage relied on state nobody set, or the previous stage left state that matters (dirty lines, stale TLB entries, an enabled interrupt) that nobody cleaned up. This section lists what the architecture makes you specify at each boundary, and then walks through TF-A’s chain as the concrete instance. The reset path itself is in 17.1, EL3 initialisation in 17.2, and the multi-chiplet reset and boot-core election in 17.5.

The handover checklist

Every boundary has to settle each of these items, either by setting it or by stating that the next stage does:

ItemWhat must be agreedWhy the architecture makes it your problem
Target EL and Security stateSPSR_ELx.M[3:0] for the ERET, SCR_EL3.{NSE,NS}, SCR_EL3.RW, HCR_EL2.RWDetermines which regime and which register copies the next stage uses
PSTATEDAIF masked (normally all four), SPSR_ELx.SP selection (ELnh)An unmasked SError or IRQ before the next stage installs VBAR_ELx ends up at an UNKNOWN vector
Entry point and argumentsELR_ELx, X0–X3 (or more)Plain software convention, but it must be written down
MMU and caches of the next stageTarget SCTLR_ELx written to a known value: M=0, C=0, RES1 bits set, EE as requiredSCTLR_EL1/SCTLR_EL2 are UNKNOWN out of reset, and a stale M=1 jumps into the previous stage’s tables
Memory image coherencyNext-stage image cleaned to the PoC (and the I-cache invalidated to the PoU if the next stage fetches with SCTLR.I=1)With M=0, data accesses are Device-nGnRnE and do not look up the cache, so the image must already be in memory. See 8.5 and 9.3
TLBsInvalidated for any regime the outgoing stage used and the incoming stage will reuseStale entries survive SCTLR.M going 1→0→1
Lower-EL controlsCPTR_ELx, MDCR_ELx, HCR_EL2, CNTHCTL_EL2, CNTVOFF_EL2, VTTBR_EL2, … set to non-trapping safe valuesMany are UNKNOWN at reset, and an UNKNOWN trap bit gives an unexplained EC 0x18 or 0x07 trap
TimersCNTFRQ_EL0 written (only possible at the highest implemented EL), system counter enabled (CNTCR.EN)The OS cannot set the frequency and will compute time incorrectly (4.6)
GICDistributor and Redistributor security configured (GICD_CTLR.ARE_S/ARE_NS, groups, GICR_WAKER), ICC_SRE_EL3.SRE/Enable=1 so lower ELs can set ICC_SRE_EL2/EL1.SREOnly Secure software can configure groups. The Normal world can only enable its own Group 1 (4.5)
Feature enablesSCR_EL3/CPTR_EL3/MDCR_EL3 bits for every FEAT_ the next stage will useMissing ones trap to EL3, see 17.3
Memory protectionTZASC/GPT configured before any lower world runsOnce Non-secure code runs, it can touch anything left unprotected

A minimal, self-contained drop from EL3 to Non-secure EL2 that honours this contract looks like this (constants written out for clarity):

    // Next stage: AArch64 Non-secure EL2h, MMU off, DAIF masked
    ldr   x0, =0x30C50830          // SCTLR_EL2: RES1 bits, M=C=I=0, EE=0
    msr   sctlr_el2, x0
    msr   hcr_el2, xzr             // BL33 owns HCR_EL2; start with no traps
    msr   cntvoff_el2, xzr         // UNKNOWN at reset
    mov   x0, #0x531               // SCR_EL3: RW(10) | HCE(8) | RES1(5:4) | NS(0)
    msr   scr_el3, x0
    mov   x0, #0x3C9               // SPSR_EL3: D,A,I,F masked, M = EL2h
    msr   spsr_el3, x0
    adr   x0, bl33_entry
    msr   elr_el3, x0
    isb
    mov   x0, x20                  // e.g. DTB address for the next stage
    eret

The ISB before the ERET is not strictly needed for the ERET itself, because ERET is a context synchronization event. It is there so that any EL3 code between the writes and the ERET sees the new SCR_EL3. Real firmware also writes CPTR_EL2 (which has RES1 bits when HCR_EL2.E2H=0), MDCR_EL2 and the FEAT_ enables. The example shows the shape of the handover, not a complete production sequence.

TF-A as the worked example

TF-A’s generic chain without RME:

StageRuns atLoaded byHands over toMechanism
BL1 (AP Trusted ROM)EL3, from ROM, MMU on with a small mapreset (RVBAR)BL2ERET to S-EL1
BL2 (Trusted Boot Firmware)S-EL1 (or EL3 with RESET_TO_BL2, or when RME is enabled)BL1BL31SMC BL1_SMC_RUN_IMAGE back to BL1, which jumps to BL31 at EL3
BL31 (EL3 Runtime Firmware)EL3, residentBL2BL32 (init), then BL33ERET using per-world contexts
BL32 (Secure payload: OP-TEE, or an SPMC such as Hafnium)S-EL1 or S-EL2BL2back to BL31SMC “init done” to its SPD/SPMD
BL33 (Non-trusted firmware: UEFI, U-Boot)NS-EL2 (or NS-EL1)BL2OSLinux boot protocol, 17.6

Where TF-A meets each contract item:

  • BL1 → BL2. BL1 is the first trusted code. It does the EL3 architectural setup (SCTLR_EL3, SCR_EL3, CPTR_EL3, MDCR_EL3, CNTFRQ_EL0) and enables the interconnect’s coherency on Arm platforms. It authenticates BL2, then ERETs to S-EL1 with x1 holding a meminfo_t describing the memory BL2 may use. On FVP, x0 carries the address of the firmware configuration (FW_CONFIG). The S-EL1 SCTLR_EL1 is written to a clean MMU-off value as part of the context setup.
  • BL2 → BL31. BL2 loads, authenticates and cleans to the PoC every image it places (flush_dcache_range() after load), because each is entered with the MMU off. At S-EL1 it cannot jump to EL3, so it issues BL1_SMC_RUN_IMAGE. TF-A’s firmware-design document then describes BL1 doing exactly what the table requires: it clears SCTLR_EL3.M/I/C, cleans the data cache to the PoC, invalidates the TLBs and jumps to BL31 at EL3. x0 points to the bl_params list (an entry_point_info_t per image: PC, SPSR, security attribute, args). x1/x2 carry platform configuration such as SOC_FW_CONFIG and HW_CONFIG.
  • BL31 → BL32. BL31 repeats the EL3 setup (BL1 is in ROM and cannot be patched, so BL31 overrides it). It initialises the GIC Distributor and Redistributors as their Secure owner, and builds a cpu_context_t per world. The SPD (opteed) or SPMD then ERETs into BL32 for initialisation, and BL32 returns via an SMC with a fixed function ID that means “boot done”. Only then does BL31 enter BL33.
  • BL31 → BL33. cm_prepare_el3_exit() builds SCR_EL3 for the Non-secure world (NS, RW, HCE, plus FEAT_ enables). For BL33 at EL2 it writes SCTLR_EL2 to its RES1 value with the correct EE. When EL2 is implemented but BL33 runs at EL1, init_nonsecure_el2_unused() neutralises EL2: HCR_EL2 with only RW set, CPTR_EL2 non-trapping, CNTHCTL_EL2 allowing EL1 physical timer and counter access, CNTVOFF_EL2=0, VTTBR_EL2=0, MDCR_EL2 and ICC_SRE_EL2 set up. The ERET carries the SPSR and args that BL2 recorded for BL33.

With RME enabled, BL2 runs at EL3 (BL1 still loads it) and also loads the RMM image into the Realm PAS. The GPT is built before any lower world runs. After initialising BL32, BL31 initialises the RMM by an ERET to R-EL2, and the RMM answers with RMM_BOOT_COMPLETE before BL31 enters BL33 (12.4).

Bring-up note: when the next stage hangs immediately after the ERET, read ESR_EL3/ELR_EL3 in the debugger before anything else. An ELR_EL3 pointing at an instruction in the next stage with EC 0x18 means a lower-EL system register access trapped: the next stage touched something CPTR_EL3/MDCR_EL3/SCR_EL3 still traps. A PC that ends up at an offset such as +0x200 or +0x380 from an address the next stage never set up means it took an exception before installing VBAR_EL2/VBAR_EL1, which are UNKNOWN out of reset. Check SPSR_EL3.DAIF in the handover, and whether the image was cleaned to the PoC.

Image authentication, in brief

The authentication contract comes from Arm’s TBBR (Trusted Board Boot Requirements, DEN0006), implemented by TF-A’s Trusted Board Boot:

  • The root of trust is a hash of the Root-of-Trust Public Key (ROTPK) held in OTP or fuses, plus BL1 in ROM. Everything else is verified against it.
  • A chain of X.509v3 certificates travels in the FIP: a Trusted Key certificate signed by the ROTPK, key certificates for the Trusted World and Non-trusted World keys, then content certificates holding image hashes for BL2, BL31, BL32, BL33 and the RMM.
  • Anti-rollback: certificates carry NV counters (Trusted and Non-trusted) that are checked against monotonic hardware counters.
  • Measured boot is a separate property from verified boot: each stage extends a measurement into an event log or a hardware root of trust (for example an RSE or a TPM) for later attestation. On CCA systems the platform attestation token is rooted in those measurements (12.4).

The architecture’s part is small but non-negotiable. Verification must happen on the copy that will execute, after it is in memory the verifier controls. The image must then be cleaned to the PoC before the jump, so that what runs is what was hashed.

Security note: a classic time-of-check/time-of-use gap is verifying an image in a Non-secure-accessible buffer (or one a DMA master can still write) and then executing it in place. The TZASC or GPT protection must cover the image before hashing starts, not after.

Checkpoint

Q12.2.1 BL2, running with its MMU and D-cache on, copies BL31 into SRAM and verifies its hash. BL31 is entered at EL3 with SCTLR_EL3.M=0, C=0. BL31 sometimes executes garbage. Which handover step is most likely missing?

  • A. A DSB SY after the copy, so the stores complete before the jump
  • B. A clean of the BL31 range to the PoC: with the MMU off, data accesses are Device-nGnRnE and the I-fetch is Non-cacheable if SCTLR_EL3.I=0, so the dirty lines in BL2’s cache are not seen
  • C. An ISB at BL31’s entry point
  • D. TLBI ALLE3, because BL1’s EL3 tables are still cached
Answer

B. The copy sits in dirty cache lines. A DSB (A) makes the stores complete, but for a cacheable store that does not imply the data has left the cache. Only a clean pushes it to the PoC, where a non-cacheable access looks. TF-A cleans every loaded image to the PoC for exactly this reason. Stale TLB entries (D) matter only once BL31 turns its MMU on.

Read more: Arm ARM (DDI0487), Behavior when stage 1 address translation is disabled; Data cache maintenance instructions; TF-A firmware design, “BL2 image load”

Q12.2.2 BL31 ERETs to BL33 at Non-secure EL1 on a core that implements EL2, without ever writing EL2 registers. Linux then fails intermittently, most visibly in timekeeping. What did the handover miss?

  • A. Nothing: EL2 registers are ignored when SCR_EL3.HCE=0
  • B. SCR_EL3.RW, which must be 0 when skipping EL2
  • C. ICC_SRE_EL3.Enable, without which EL1 cannot use the GIC system registers
  • D. Neutralising EL2: registers such as HCR_EL2, CNTHCTL_EL2 and CNTVOFF_EL2 still affect Non-secure EL1&0 when EL2 is implemented, even if nothing runs there, and their reset values are UNKNOWN
Answer

D. When EL2 is implemented and enabled for the Security state, its controls apply to EL1&0 whether or not software runs at EL2. An UNKNOWN CNTVOFF_EL2 offsets the virtual counter, and an UNKNOWN CNTHCTL_EL2 can trap physical timer access. HCE (A) only enables the HVC instruction. TF-A’s init_nonsecure_el2_unused() exists for exactly this case.

Read more: Arm ARM (DDI0487), HCR_EL2, CNTHCTL_EL2, CNTVOFF_EL2 reset values; TF-A init_nonsecure_el2_unused

Q12.2.3 Why does TF-A, without RME, have BL2 call back into BL1 with BL1_SMC_RUN_IMAGE instead of jumping to BL31 directly?

  • A. BL2 runs at S-EL1, and the only way to enter EL3 code from a lower EL is an exception to EL3. BL1’s SMC handler owns EL3 at that point, disables its MMU and caches, cleans to the PoC and enters BL31 at EL3
  • B. BL31’s entry point is in ROM, which only BL1 can map
  • C. The SMC is a context synchronization event, which is needed for the new VBAR_EL3
  • D. BL1 must authenticate BL31, because BL2 is not trusted to verify EL3 images
Answer

A. A lower EL cannot branch into a higher EL. It must take an exception that the higher EL handles. With RESET_TO_BL2 or RME, BL2 already runs at EL3 and jumps directly. Authentication of BL31 (D) is done by BL2 in TF-A’s Trusted Board Boot. BL31 is in trusted SRAM, not ROM (B).

Read more: TF-A firmware design, “BL1” and “Running BL2 at EL3 execution level”; Arm ARM (DDI0487), Exception entry

12.3 Firmware interfaces

Three Arm specifications define almost every call that crosses a privilege boundary on an A-profile system. SMCCC (DEN0028) defines the register-level calling convention and the function ID space. PSCI (DEN0022) is the power-management API built on SMCCC. FF-A (DEN0077) is the partition-messaging and memory-sharing API built on SMCCC. This section covers the interfaces. The firmware sequences behind PSCI (cache flushing, coherency exit, the GIC wake-up path) are in 17.4 and 8.8.

SMCCC: conduits and the function ID

The conduit is SMC #0 (to EL3, or trapped to EL2 by HCR_EL2.TSC) or HVC #0 (to EL2). The immediate is ignored by convention, and the function ID travels in W0. Its layout:

BitsFieldValues
31Call type1 = Fast call (atomic with respect to the caller’s PE: runs to completion, cannot be preempted by the Normal world), 0 = Yielding call (may be interrupted and resumed)
30Convention0 = SMC32/HVC32, 1 = SMC64/HVC64
29:24Owning entity number (OEN)0 Arm Architecture, 1 CPU service, 2 SiP, 3 OEM, 4 Standard Secure service, 5 Standard Hypervisor, 6 Vendor Hypervisor, 7 Vendor EL3 Monitor, 48–49 Trusted Applications, 50–63 Trusted OS
23:17ReservedMust be zero for Fast calls
16SVE hint (SMCCC v1.3)1 = the caller has no live SVE state beyond the FP/SIMD view, so the callee need not preserve Z/P/FFR upper bits
15:0Function numberWithin the OEN

So 0x84000000 is a Fast, SMC32, Standard Secure service call, function 0 (PSCI_VERSION), and 0xC4000003 is the SMC64 form of function 3 (CPU_ON). PSCI, SDEI, TRNG, FF-A and the CCA RMI all live in OEN 4. Arm architecture calls (OEN 0) include SMCCC_VERSION (0x80000000), SMCCC_ARCH_FEATURES (0x80000001), SMCCC_ARCH_SOC_ID (0x80000002) and the Spectre workarounds SMCCC_ARCH_WORKAROUND_1/2/3 (0x80008000, 0x80007FFF, 0x80003FFF; see 14.4). An unknown function ID must return SMC_UNK (−1, 0xFFFFFFFF in W0).

Register usage for SMC64/HVC64:

  • Arguments in X1–X17 and results in X0–X17 (the full range from v1.2; earlier versions used X1–X6 for arguments, with W7 carrying an optional hypervisor client ID, and X0–X3 for results).
  • The callee must preserve X18–X30, SP_EL0 and SP_ELx. From v1.1, it must also preserve the argument/result registers that a given function does not use (X4–X17 for a classic four-result call). That is why Linux’s arm_smccc_1_1_smc() clobbers only X0–X3.
  • SMC32 uses only the W views, and the upper halves are not part of the contract.
  • FP/SIMD/SVE/SME state is preserved by the callee, subject to the SVE hint.

Discovery is layered: check that SMCCC_VERSION exists with PSCI_FEATURES (if it does not, assume v1.0), call it, then SMCCC_ARCH_FEATURES(fid) for each optional call. The conduit itself is chosen by the OS from the device tree (/psci method = "smc" or "hvc") or from the ACPI FADT PSCI_USE_HVC flag.

Security note: an EL3 SMC handler must treat every argument as hostile. Pointers from the Normal world must be range-checked against NS memory, and copied in once before validation (no double fetch). It must never dereference a pointer without checking which PAS it names: on RME systems a forged pointer into Realm memory takes a GPF at EL3 (12.4). Fast calls run with interrupts masked at EL3, so a long fast call is also a denial-of-service and latency problem.

PSCI: the interface and its coordination rules

The calls you will use in bring-up (SMC64 IDs; the SMC32 form replaces 0xC4 with 0x84):

CallIDContract
CPU_ON(target_mpidr, entry, context_id)0xC4000003Powers on the target. It starts at entry, in the caller’s EL and execution state (Non-secure EL2 or EL1), with X0 = context_id, MMU and D-cache off. Errors: ALREADY_ON, ON_PENDING, INVALID_PARAMETERS, INVALID_ADDRESS
CPU_OFF()0x84000002Called by the core itself. Does not return on success. The caller must already have migrated its interrupts and work away
CPU_SUSPEND(power_state, entry, context_id)0xC4000001Retention (standby) states return to the caller. Power-down states resume at entry like a warm boot, with the caller’s context lost
AFFINITY_INFO(mpidr, level)0xC4000004Returns ON (0), OFF (1) or ON_PENDING (2). This is how an OS learns that a CPU_OFF really finished
SYSTEM_OFF / SYSTEM_RESET0x84000008 / 0x84000009Do not return. SYSTEM_RESET is a cold reset
SYSTEM_RESET2(type, cookie)0xC4000012PSCI 1.1. Type 0 = warm reset. Bit 31 set = vendor-specific reset
PSCI_FEATURES(fid)0x8400000AIs a call implemented? For CPU_SUSPEND it also reports the power_state format and whether OS-initiated mode is supported

The power_state parameter comes in two formats:

FormatStateIDStateType (0 = standby/retention, 1 = power-down)PowerLevel
Originalbits [15:0]bit 16bits [25:24]
Extended (PSCI 1.0+)bits [27:0]bit 30encoded in StateID by the platform

Coordination is about deciding when a cluster or system may power down when several cores vote. PSCI defines two modes:

  • Platform-coordinated (the default, required): each core requests its preferred state for every level of its hierarchy. The firmware puts a node into the shallowest state that all its cores have requested, so a node powers down only when the last core asks for it. The OS never has to know who is last.
  • OS-initiated (OSI, PSCI 1.0, optional, selected with PSCI_SET_SUSPEND_MODE): the OS decides. The last core in a node requests the composite state for the node. Firmware checks that the request is consistent with what it knows (for example, that every other core in the node is really idle or off) and returns DENIED if it is not. OSI moves the race condition into the OS, and in exchange the OS’s knowledge of wake-up latency is used.

Both modes follow one rule: a core that has asked to power down must not count as off until firmware has completed its power-down sequence. That is why AFFINITY_INFO exists, and why a CPU_ON aimed at a core still in its CPU_OFF sequence returns ALREADY_ON instead of racing the power-down. (ON_PENDING is different: it means an earlier CPU_ON for that core has not completed yet.)

Validation note: test PSCI as a state machine, not call by call. Useful cases: CPU_ON on a core that is still in its CPU_OFF sequence (must return ALREADY_ON or eventually succeed, never hang); concurrent CPU_SUSPEND power-down requests from every core in a cluster while one core is woken by an SGI (the cluster must not be powered down under a running core); and SYSTEM_SUSPEND with a pending wake-up interrupt. Confirm each with AFFINITY_INFO, with PSCI_STAT_RESIDENCY/PSCI_STAT_COUNT where implemented, and with the power controller’s status registers. TF-A’s TFTF has a PSCI suite that covers most of these.

FF-A: partitions, messaging and memory sharing

FF-A (v1.0 in 2020, then 1.1, 1.2 and 1.3) standardises how endpoints (VMs, the OS, secure partitions) talk to each other through partition managers. Function IDs are in OEN 4, function numbers 0x60 upward (FFA_ERROR = 0x84000060, FFA_SUCCESS = 0x84000061, FFA_VERSION = 0x84000063).

Components. In the Normal world, the hypervisor (if any) is the NS partition manager. In the Secure world, the SPMC manages SPs. The SPMD in BL31 relays FF-A calls between the worlds and saves and restores world context. SPMC placements:

SPMC atExampleIsolation between SPs
S-EL2 (FEAT_SEL2)HafniumStage 2 per SP. SPs at S-EL1 (OP-TEE as an SP) or S-EL0
S-EL1OP-TEE as SPMCStage 1 only. S-EL0 SPs (OP-TEE TAs, or FF-A S-EL0 SPs)
EL3TF-A EL3 SPMCS-EL0 SPs such as StandaloneMM

Each endpoint has a 16-bit ID. In TF-A and Hafnium, secure endpoints have bit 15 set and ID 0 is the Normal world (hypervisor or OS). Discovery uses FFA_VERSION, FFA_FEATURES, FFA_ID_GET and FFA_PARTITION_INFO_GET. SP properties (UUID, EL, execution contexts, memory regions, interrupts) come from partition manifests (device tree) that the SPMC reads at boot.

Messaging.

  • Direct messaging: FFA_MSG_SEND_DIRECT_REQ/RESP (and the REQ2/RESP2 forms from v1.2 that carry more registers and a UUID). This is a synchronous, register-only RPC into a specific SP execution context. It is the path OP-TEE’s Linux driver uses under FF-A.
  • Indirect messaging: FFA_MSG_SEND2 (v1.1) copies the message through the RX/TX buffer pair that each endpoint registers with FFA_RXTX_MAP.
  • Scheduling: FFA_RUN (give CPU time to an SP), FFA_MSG_WAIT (an SP idles), FFA_YIELD, and FFA_INTERRUPT when a secure interrupt preempts. Notifications (v1.1) are the asynchronous, doorbell-like path.

Memory sharing. A lender describes a region (a list of PA ranges, permissions, attributes and receivers) in its TX buffer and calls one of the following:

CallAfter it completes
FFA_MEM_SHARELender and borrower(s) both have access
FFA_MEM_LENDBorrower has access, lender loses it until reclaim
FFA_MEM_DONATEOwnership moves permanently

The partition manager returns a 64-bit handle. The borrower maps the region with FFA_MEM_RETRIEVE_REQ and gives it back with FFA_MEM_RELINQUISH. The lender then recovers it with FFA_MEM_RECLAIM. The SPMC enforces each transfer by editing the stage 2 tables of the parties involved. When a lender loses access, the PM must remove the mapping, broadcast the TLBI and complete it before the call returns: lend is not secure if the lender keeps a stale TLB entry. Lending from the Normal world without a hypervisor is the weak case. Nothing in the Secure world controls the OS’s stage 1, so exclusivity can be enforced only if the SPMC also changes the memory’s PAS (through the TZASC, or the GPT on RME systems). Otherwise the region stays Non-secure and the SP must map it Non-secure, because mapping it NS=0 would create a Secure alias of a Non-secure location (12.1).

Bring-up note: most FF-A bring-up failures are manifest mismatches, not protocol bugs: an SP UUID in the Linux driver that differs from the manifest, an SP’s memory region that overlaps another one, or an interrupt claimed in a manifest but left configured as Non-secure Group 1. Hafnium and the SPMD print the parsed manifest at boot, so compare that log first.

Checkpoint

Q12.3.1 A vendor adds an SMC that copies a 64-byte record into a buffer whose address is passed in X1, and returns status in X0 and a length in X1. Linux calls it with arm_smccc_1_1_smc() and keeps a live value in X5 across the call. EL3’s handler is written in C and uses X5 as scratch, without restoring it before the ERET. Who is wrong?

  • A. Linux: SMCCC lets the callee corrupt X4–X17
  • B. Nobody: X5 is caller-saved under AAPCS64, so Linux should have spilled it
  • C. The EL3 handler: from SMCCC v1.1, registers that a function does not use for results must be preserved, and AAPCS64 caller-saved rules do not apply across the SMC boundary
  • D. Linux: it should have used an SMC32 call, for which only W0–W3 are defined
Answer

C. SMCCC is its own contract, not AAPCS64. From v1.1 the callee must return unused registers unchanged, and Linux’s 1.1 helpers rely on this by clobbering only X0–X3. A was the v1.0 rule. In TF-A this bug cannot arise from C code: the EL3 entry path saves the full GP register context and restores it on exit, so only a hand-written assembly handler could leak X5 this way.

Read more: SMC Calling Convention (DEN0028), register use in AArch64 SMC and HVC calls

Q12.3.2 In platform-coordinated mode, core 0 of a two-core cluster calls CPU_SUSPEND asking for core power-down and cluster power-down. Core 1 is running. What must the firmware do?

  • A. Return DENIED, because a cluster state was requested while another core in the cluster is running
  • B. Power down core 0 only, record its vote for the cluster, and power the cluster down only once core 1 also requests a cluster power-down state
  • C. Power down the whole cluster, because the request came from the last core to ask
  • D. Put core 0 into retention instead, because platform-coordinated mode does not allow power-down
Answer

B. In platform-coordinated mode, each core’s request is a vote and the node enters the shallowest state its cores agree on. DENIED for an inconsistent composite request (A) is OS-initiated mode behaviour. That rule exists because in OSI the OS claims to be the last core.

Read more: Arm PSCI (DEN0022), power state coordination: platform-coordinated and OS-initiated modes

Q12.3.3 Under a Hafnium SPMC at S-EL2, S-EL1 partition SP1 uses FFA_MEM_LEND to give a buffer from its own Secure memory to SP2. Which property must the SPMC enforce before it reports success to SP1?

  • A. None beyond bookkeeping: SP1 is expected to have removed its own stage 1 mapping before the call
  • B. The buffer is cleaned and invalidated to the PoC on every PE, so that SP1’s cached copy cannot be read
  • C. The buffer is moved to the Non-secure PAS, so that both partitions can address it through the same IPA space
  • D. SP1’s stage 2 mapping is removed and the TLB invalidation has completed (TLBI then DSB), so SP1 cannot reach the buffer even through a cached translation
Answer

D. Lend means exclusive access for the borrower. The SPMC owns both partitions’ stage 2 tables, so it enforces this there, and a removal counts only once the TLBI has completed. Relying on the lender’s own stage 1 (A) is not isolation, because the lender is the party being restricted. Cache maintenance (B) does not remove access rights, and moving the buffer to the Non-secure PAS (C) would expose it to the Normal world.

Read more: Arm FF-A (DEN0077), memory management: lend, share and donate transactions; Arm ARM (DDI0487), TLB maintenance requirements

12.4 RME and Arm CCA

FEAT_RME (permitted from v9.2) does two things to the TrustZone model of 12.1. It adds two Security states, Realm and Root, giving four. And it moves the “which world may touch this memory” decision from a static, system-level TZASC into a PE-side check against an in-memory table that EL3 owns and can change at run time: the Granule Protection Table (GPT). Arm CCA (Confidential Compute Architecture) is the system and software architecture built on top: the RMM at R-EL2, the RMI/RSI interfaces and attestation. The system-level requirements (which requesters must be checked, the PoPA, memory encryption) are in DEN0129.

Four PASes and who may access them

Security stateELsSCR_EL3.{NSE,NS}PASes it may access
RootEL3 onlyn/aRoot, Secure, Non-secure, Realm
SecureS-EL0–S-EL2{0,0}Secure, Non-secure
Non-secureNS-EL0–NS-EL2{0,1}Non-secure
RealmR-EL0–R-EL2{1,1}Realm, Non-secure

At EL3, the stage 1 descriptor selects the output PAS with NS (bit 5) plus NSE (bit 11, which is not otherwise used at EL3). PA-based maintenance operands select it with bits [63:62] = {NS, NSE}: Secure {0,0}, Root {0,1}, Non-secure {1,0}, Realm {1,1}. Note that this ordering differs from SCR_EL3, where NSE is bit 62 and NS is bit 0. Getting the two encodings confused is a common source of “the CMO did nothing” bugs.

The table says which PAS a state may name. Whether the access then succeeds is decided by the Granule Protection Check (GPC): after translation, every access, including translation table walks, is checked against the GPT entry for its PA. Each entry holds a 4-bit GPI (Granule Protection Information):

GPIMeaningNotes
0b0000No accessUsed as the intermediate state while a granule changes owner
0b1000Secure only
0b1001Non-secure only
0b1010Root onlyGPT itself and EL3 memory
0b1011Realm only
0b1101NSO (Non-secure Only), a more restricted form of Non-secure accessFEAT_RME_GPC2, enabled by GPCCR_EL3.NSO, otherwise reserved. See the GPI encodings in DDI0487 for the exact access rule
0b1111Any accessTypical for device MMIO that every world may reach
0b0100–0b0111Further encodings (SA, NSP, NA6, NA7)Later extensions (FEAT_RME_GDI), each enabled by its own GPCCR_EL3 bit, otherwise reserved

An access passes only if its PAS matches the GPI, or the GPI is “any”.

GPCCR_EL3, GPTBR_EL3 and the walk

GPTBR_EL3.BADDR holds the level 0 table’s PA, from bit 12 upwards. GPCCR_EL3 configures the check:

FieldBitsMeaning
PPS[2:0] (plus PPS3 at [3] with GPC3)Protected Physical Address Size: the PA range the GPT covers
IRGN, ORGN, SH[9:8], [11:10], [13:12]Cacheability and shareability of GPT walks
PGS[15:14]Physical granule size: 00 4 KB, 10 16 KB, 01 64 KB
GPC[16]Enables granule protection checks
GPCP[17]GPC fault priority for stage 2 table walks (may be RES0)
L0GPTSZ[23:20]Read-only, IMPLEMENTATION DEFINED: PA bits covered by each level 0 entry, encoded 0 = 30 bits (1 GB) up to 9 = 39 bits (512 GB)
NSO, SPAD/NSPAD/RLPAD, APPSAA[19], [7]/[6]/[5], [24]FEAT_RME_GPC2: NSO encoding enable, per-PAS “access disable”, and how Secure/Realm/Root accesses above PPS are treated
GPCBW[29]FEAT_RME_GPC3: enables the GPC bypass windows defined in GPCBW_EL3

The walk has at most two levels, indexed by PA:

 PA[PPS-1 : L0GPTSZ]  -> level 0 entry (64-bit), at GPTBR_EL3 base
     bits[3:0] = 0b0001  Block descriptor:  GPI in [7:4] for the whole L0 region (e.g. 1 GB)
     bits[3:0] = 0b0011  Table descriptor:  L1 table address
     otherwise           invalid -> GPT walk fault
 PA[L0GPTSZ-1 : granule_shift+4] -> level 1 entry (64-bit)
     Granules descriptor:   16 x 4-bit GPIs, one per granule (64 KB of PA per entry at PGS=4 KB)
     Contiguous descriptor: bits[3:0]=0b0001, GPI in [7:4], Contig in [9:8]
                            (2 MB / 32 MB / 512 MB), replicated in every entry of the block

The contiguous form lets the TLB cache one GPT result for a large block. Software must keep every replicated entry identical. Breaking a contiguous region back into granules needs a TLBI RPALOS over the old block, whereas merging needs no TLB maintenance (Arm’s example flows, document 109839). FEAT_RME_GPC3’s bypass windows (GPCBW_EL3: a base, a size from 1 GB to 64 GB, and an optional stride) let large regions skip the walk entirely and use a fixed default result instead. They are intended for huge flat regions where a walk per TLB miss is wasted.

GPT information may be cached in TLBs and combined with translation entries. That is why TLBI is part of every GPT change.

Granule protection faults

There are two classes:

  • GPF: the walk succeeded but the GPI forbids the access. For accesses at EL0–EL2, SCR_EL3.GPF=1 takes them to EL3 as a Granule Protection Check exception, EC 0x1E. With GPF=0, they are reported as an ordinary Instruction or Data Abort to the EL the abort would normally go to, with xFSC 0b101000 (GPF not on a translation table walk) or 0b100011–0b100111 (GPF on a translation table walk, levels −1 to 3). A GPF on a stage 2 walk is what a hypervisor sees when the guest’s tables sit in a granule that has been delegated away. A GPF on an EL3 access is a normal current-EL Data Abort with DFSC 0b101000. TF-A’s rme_gpf_safe_read()/rme_gpf_safe_write() rely on that to copy from lower-EL buffers without crashing.
  • GPT walk/configuration faults (invalid GPT descriptor, GPT address size fault): these mean EL3’s own table is broken, and they are reported to EL3 as EC 0x1E.

MFAR_EL3 reports the faulting PA and its PAS for GPC exceptions, because FAR_EL3 holds a VA. Linux treats a GPF on a walk as a kernel bug (oops) and a GPF outside a walk as SIGBUS, since user space may legitimately touch a page the host has just delegated.

Changing a granule’s PA space safely

This is the core RME memory-system sequence. The rules are the ones from Parts 7–9 applied to a new address bit. Arm’s Granule Transition Flow (109839) and TF-A’s gpt_delegate_pas()/gpt_undelegate_pas() implement these steps:

Delegate (NS -> Realm or Secure), executed at EL3 with caches on, under a GPT lock:
  1. DC CIPAPA  each line of the granule, operand = PA | target PAS   // drop speculative fills tagged target-PAS
     DSB OSH
  2. write GPI = target in the L1 entry
     DSB OSHST                                                        // GPT write visible to GPT walkers
  3. TLBI RPALOS, PA (size = granule)                                 // remove cached GPT info everywhere
     DSB OSH
  4. DC CIPAPA  each line, operand = PA | NS                          // NS-tagged lines must not be written back later
     DSB OSH

Undelegate (Realm or Secure -> NS), the owner has already scrubbed the granule:
  1. GPI = No access ; DSB OSHST ; TLBI RPALOS ; DSB OSH               // previous owner loses access first
  2. DC CIPAPA (old PAS) ; DSB OSH                                    // scrubbed data pushed past the PoPA
  3. DC CIPAPA (NS) ; DSB OSH                                          // drop stale speculative NS fills
  4. GPI = NS ; DSB OSHST ; TLBI RPALOS ; DSB OSH

(TF-A first shatters a contiguous GPT block that covers the granule, with its
own TLBI RPALOS, and may fuse the block again afterwards.)

Why each piece is there:

  • To the PoPA, not the PoC. The Point of Physical Aliasing is where the PAS stops being part of the address and all four PAS aliases of a PA reach the same storage. A line tagged with the old PAS that is still dirty anywhere before the PoPA could later be written back over the new owner’s data, or serve stale data. DC CIPAPA (clean and invalidate by PA to PoPA, EL3 only) is the only CMO that reaches that point by PA and PAS. With FEAT_MTE2, use DC CIGDPAPA so that allocation tags are cleaned as well.
  • TLBI RPAOS / RPALOS / PAALLOS. These invalidate cached GPT information by PA range (RPA*), by PA range for last-level entries only (RPAL*), or entirely (PAALLOS, used after enabling or rebuilding the GPT). They are Outer Shareable, so every PE and every SMMU that caches GPT results must be in the DVM domain that receives them.
  • OSH barriers. GPT consumers include other PEs and SMMUs, so Inner Shareable is not enough.
  • No access first on undelegate. Until the GPI says “no access”, the old owner can still write. Revoking access first guarantees that nothing written later becomes observable.

Validation note: the GTF is a good target for directed tests on FVP and on RTL. Delegate a granule while another core keeps writing to it through an NS mapping, and check that the writer takes a GPF after the TLBI completes and that no NS write lands after the transition (read the granule back through a Realm mapping). Then repeat with the step 4 CMO removed, using FVP with cache_state_modelled=1: without it the bug is invisible (18.4). On silicon, a skipped TLBI RPALOS typically shows up as a GPF that “should not happen” on another core. MFAR_EL3 and the ESR GPCSC field show whether it was a walk fault or a GPI mismatch.

SMMU granule protection checks

Every requester that is not a PE must be checked too, or a DMA master would bypass the GPT. With RME, an SMMUv3 implementation performs the GPC on device accesses (including its own table walks) using the same GPT. It is configured through its Root register page (SMMU_ROOT_*): the GPT base and configuration, which should mirror GPTBR_EL3/GPCCR_EL3, a GPC enable in SMMU_ROOT_CR0, and GPF fault address registers. Requesters that sit behind no SMMU need a completer-side PAS filter, which DEN0129 requires. EL3 firmware owns all of this: enabling the PE’s GPC while leaving the SMMU’s off is a hole, and so is an SMMU that does not receive the TLBI PA broadcasts. Details are in IHI0070’s RME chapter.

What changes for EL3 firmware

  • EL3 is the Root world. Its code, data, stacks and the GPT itself must be GPI Root, and the GPT must be valid before GPCCR_EL3.GPC=1. In TF-A, BL2 runs at EL3 when RME is enabled, builds the GPT early, and loads the RMM into Realm PAS.
  • There are three lower-world contexts to switch (Secure, Non-secure, Realm), each with full EL2 state, using SCR_EL3.NSE on the ERET.
  • The RMMD in BL31 forwards RMI calls (SMC64, OEN 4, function numbers 0x150–0x18F) from the Normal-world host to the RMM. It also serves the RMM-EL3 interface: RMM_GTSI_DELEGATE/UNDELEGATE (the GTF above), RMM_ATTEST_GET_REALM_KEY, RMM_ATTEST_GET_PLAT_TOKEN, and RMM_BOOT_COMPLETE.
  • Any EL3 access to a lower-world buffer must be GPF-tolerant, because the buffer’s owner may have changed since the pointer was validated.

RMM, RMI and RSI in brief. The RMM (TF-RMM is the reference) runs at R-EL2 and is the only component that can map Realm memory into Realms. The host (KVM) asks it, through RMI, to delegate granules, create a Realm descriptor (RD), Realm Execution Contexts (RECs) and Realm Translation Tables (RTTs), populate measured data (RMI_DATA_CREATE) and run a REC (RMI_REC_ENTER). The host chooses which memory, and the RMM guarantees how that memory is used. A Realm calls the RMM through RSI (SMC from R-EL1, function numbers starting at 0x190) for attestation tokens, measurement extension and IPA-state changes (RSI_IPA_STATE_SET marks a range as RAM or as shared with the host).

Attestation in brief. A CCA attestation token has two parts. The platform token is signed by the platform’s root of trust (for example an RSE) and covers firmware measurements and the security lifecycle state. The Realm token is signed by the RMM’s Realm Attestation Key, which the platform token binds, and covers the Realm Initial Measurement (RIM), the Realm Extensible Measurements (REMs) and a challenge from the verifier.

Checkpoint

Q12.4.1 In a delegate sequence, firmware writes the GPI to Realm and issues TLBI RPALOS and DSB OSH, but skips the final DC CIPAPA with the Non-secure PAS. What can go wrong?

  • A. A dirty NS-tagged line for that PA, left by the host before the delegate, can later be evicted and written back past the PoPA, overwriting data the Realm has since stored
  • B. Nothing: the GPC blocks the NS writeback because the granule is now Realm
  • C. The host takes a GPF on its next read, which is the intended outcome, so the CMO is only a performance optimisation
  • D. The RMM’s later reads return zeros, because the line is still tagged NS
Answer

A. Caches before the PoPA hold the line as an NS location, which is a different location from the Realm alias. A writeback is the eviction of an access that already passed its GPC, so B is the tempting but wrong answer. Cleaning and invalidating the NS alias to the PoPA removes it before it can corrupt the Realm’s view.

Read more: Arm ARM (DDI0487), DC CIPAPA and the Point of Physical Aliasing; Arm RME and MEC example software flows (109839), Granule Transition Flow

Q12.4.2 EL3 copies a structure from a pointer the Normal world passed in an SMC. The page was delegated to Realm on another core after EL3 validated the pointer. What does EL3 observe, and how does TF-A deal with it?

  • A. EC 0x1E with SCR_EL3.GPF set, and BL31 panics
  • B. Stale NS data, because EL3 accesses bypass the GPC
  • C. A Data Abort from the current EL with DFSC “Granule Protection Fault not on translation table walk”. TF-A’s GPF-tolerant copy helpers have a fixup table that resumes at a recovery PC and return a short count
  • D. A GPT walk fault, because Root cannot address Realm PAS through an NS-attributed mapping
Answer

C. EL3 accesses are subject to the GPC, so B is wrong. A GPF on an EL3 access is reported as a normal current-EL abort (SCR_EL3.GPF concerns EL0–EL2 only), which is why A is wrong. TF-A’s rme_gpf_safe_read() checks for DFSC 0b101000 in its EL3 handler. The access is a GPF, not a walk fault (D): the walk succeeded, and the GPI simply does not allow NS.

Read more: Arm ARM (DDI0487), Granule protection checks and GPC exceptions; TF-A lib/gpt_rme, rme_helpers.S

Q12.4.3 A platform enables GPCCR_EL3.GPC on the PEs but leaves the SMMU’s Root GPC disabled, intending to “do it later in the kernel”. Which statement is correct?

  • A. This is acceptable, because the SMMU’s stage 2 for the device already prevents access to Realm memory
  • B. It is a hole: device DMA is then not checked against the GPT, so a Non-secure device (or the host programming its stage 2) can reach Realm and Root memory. Only Root firmware can enable the SMMU GPC, so it must be enabled before any lower world runs
  • C. It is acceptable as long as the SMMU is in the DVM domain, because TLBI RPALOS also blocks its accesses
  • D. The PE GPC catches DMA writes when the lines are next read by a PE, so integrity is preserved
Answer

B. The host controls the SMMU’s Non-secure stage 2, so that stage 2 is not a protection against the host (A). TLBI only invalidates cached GPT information. It does not enforce a check that is turned off (C). A PE-side check on a later read does not undo a write that has already reached memory (D).

Read more: Arm SMMUv3 (IHI0070), Realm Management Extension: granule protection checks; RME system architecture (DEN0129), requester checks

12.5 Memory Encryption Contexts (FEAT_MEC)

RME’s GPC (12.4) separates the worlds. It does not separate one Realm from another: every Realm granule is in the same Realm PAS, so isolation between Realms rests entirely on the RMM’s stage 2 tables. Against physical attacks (bus probing, cold boot, DRAM interposers), a system can encrypt each PAS with its own key, but without MEC all of Realm PAS shares one key. FEAT_MEC (permitted from v9.2, requires FEAT_RME; detected with ID_AA64MMFR3_EL1.MEC) splits the Realm PAS into many Memory Encryption Contexts. Each memory access carries a MECID that selects the encryption context (key or key tweak) used at the memory encryption engine. Accesses to the Non-secure, Secure and Root PASes always use the default MECID 0. Realm PAS accesses use whatever MECID the translation regime and descriptor select.

The architecture defines how a MECID is attached to an access and what software must do to avoid mixing contexts. It does not define the cipher, the key store or the engine. Those are system components (DEN0129 calls the engine a Memory Protection Engine), driven by IMPLEMENTATION DEFINED EL3 firmware.

The registers

RegisterSelects the MECID forNotes
MECIDR_EL2— (ID register)MECIDWidthm1 [3:0]: MECID width is MECIDWidthm1 + 1 bits, up to 16
MECID_P0_EL2Realm EL2 / EL2&0 accesses translated by TTBR0_EL2 (primary)
MECID_A0_EL2The same, via descriptors with AMEC=1 (alternate)Enabled by TCR2_EL2.AMEC0 [12]
MECID_P1_EL2Realm EL2&0 accesses translated by TTBR1_EL2 (primary, E2H=1)
MECID_A1_EL2The same, via descriptors with AMEC=1Enabled by TCR2_EL2.AMEC1 [13]
VMECID_P_EL2Realm EL1&0 stage 2 (primary): the Realm VM’s own memory
VMECID_A_EL2Realm EL1&0 stage 2 (alternate), via stage 2 descriptors with AMEC=1One alternate context per Realm VM
MECID_RL_A_EL3EL3 accesses to Realm PAS (descriptor {NSE,NS}={1,1})Used when SCTLR2_EL3.EMEC [1] = 1

The enables around them:

  • SCR_EL3.MECEn (bit 49) lets Realm EL2 access the MECID registers; otherwise they trap to EL3. TF-A gates this behind ENABLE_FEAT_MEC, which also needs FEAT_TCR2 and FEAT_SCTLR2.
  • SCTLR2_EL2.EMEC turns MEC on for Realm EL2’s regimes. While it is 0, the AMEC descriptor bit position is RES0 and no alternate MECIDs are used.
  • TCR2_EL2.AMEC0/AMEC1: when 0, using a block or page descriptor with AMEC=1 causes a Translation fault. Both bits may be cached in a TLB only when they are 1.
  • MEC applies only to Realm PAS accesses, so these registers and enables have no effect on Secure, Non-secure or Root PAS accesses (the access rules from other Security states are in each register’s description). They reset to UNKNOWN values on a Warm reset, so the RMM’s warm-boot path must reprogram them.

Device traffic is tagged as well: with MEC, SMMU-originated accesses to Realm memory also carry a MECID from the stream’s configuration (IHI0070).

How the RMM uses them

Arm’s MEC use-model guidance (document 109839) and TF-RMM follow the same pattern:

  • Per-Realm private MECID. When a Realm is created, the RMM gives it a MECID, either chosen by the host in the Realm parameters (RMM v1.1) or the default. The RMM sets VMECID_P_EL2 to that value when it runs the Realm’s RECs, so the Realm’s code, data, stage 1 tables and stage 2 tables are all encrypted in its own context.
  • RMM accessing Realm state. The RMM runs with E2H=1, so it has two VA halves, each with its own primary and alternate MECID register. Its own image stays in the RMM’s own context, and the mappings it uses for the Realm it is serving (in TF-RMM, the per-CPU slot buffer in the TTBR1_EL2 half) carry that Realm’s MECID, so it reads and writes the Realm’s RTTs, metadata and REC contexts in the Realm’s context. Which half and which register (primary or alternate) carry which context is a software choice; check the TF-RMM source for the current assignment.
  • Alternate contexts. VMECID_A_EL2/MECID_A0_EL2 give each Realm one extra context, intended for memory shared between Realms or with the RMM. The RMM specification exposes this as a shared MECID state (RMI_MEC_SET_SHARED / RMI_MEC_SET_PRIVATE in RMM v1.1). TF-RMM tracks one shared MECID and how many Realms use it, and refuses to make it private again while any Realm still does. Arm’s guidance notes that this does not make inter-Realm data sharing part of the CCA security model.
  • EL3. MECID_RL_A_EL3 usually holds the RMM’s MECID, so that EL3 can load the RMM image into Realm PAS at boot and write attestation material for it.
  • Key refresh. Reusing a MECID for a new Realm requires a new key or tweak for that MECID, otherwise the new Realm could read the old one’s ciphertext as plaintext. In TF-A’s RMM-EL3 interface this is RMM_MEC_REFRESH (0xC40001B6, from interface v0.8). It takes the MECID and a reason bit (Realm creation or destruction). How EL3 reprograms the engine is IMPLEMENTATION DEFINED. Refreshing a tweak destroys every byte still associated with the old value.

The Point of Encryption and the maintenance rules

The Point of Encryption (PoE) is the point in the memory system where accesses are encrypted and decrypted using their MECID. Caches before it hold plaintext. A cache line holds data for a PA. If it is filled under one MECID and later used or written back under another, the result is a mismatched-MECID access, and Arm states that such accesses corrupt memory within the Realm PAS. This is not a fault the PE detects. It is silent corruption, or plaintext from one context reaching another, which is a confidentiality break. Software must make it impossible.

Arm’s rules (109839, “Mismatched MECID avoidance”):

  1. All active translations to a granule use the same MECID. Two live mappings of one PA with different MECIDs (for example a primary and an alternate mapping) can produce a mismatch through ordinary or speculative accesses. A mapping counts as active until its TLB invalidation has completed.
  2. Do not change a MECID register while any granule is reachable through a translation that uses it.
  3. Clean and invalidate to the PoE before any change of a granule’s associated MECID or MECID state.

The instructions are FEAT_MEC’s DC CIPAE (clean and invalidate by PA to PoE, with the PAS selected in bits [63:62] as for DC CIPAPA) and DC CIGDPAE (the same, including MTE allocation tags). They can be executed at EL3, and at EL2 in Realm state. Realm EL2 software can therefore do its own MEC maintenance without an SMC.

The resulting flows for the RMM:

RemoveGranule(pa):                          // a granule leaves a Realm but stays in Realm PAS
    unmap from the Realm's stage 2   ; TLBI IPAS2E1IS ; DSB ISH ; TLBI VMALLE1IS ; DSB ISH   // see 9.1
    unmap any R-EL2 stage 1 alias    ; TLBI VAE2IS ; DSB
    for each line: DC CIPAE, pa | REALM
    DSB OSH

AddGranule(pa, ipa):                         // a granule joins a Realm
    if the previous MECID is still live:
        map temporarily at R-EL2 with the new Realm's MECID; scrub (DC ZVA or random data); unmap
    map pa at ipa in the Realm's stage 2

Points to note:

  • The GTF already covers PAS changes. A granule that leaves Realm PAS through the EL3 granule transition flow needs no extra DC CIPAE, because the GTF’s clean and invalidate to the PoPA already pushes it past the PoE. The PoE matters for granules that move within Realm PAS between MECIDs. TF-RMM therefore flushes to the PoE when a granule returns to the RMM’s DELEGATED state, since a delegated granule can be reused by another Realm without an undelegate.
  • Changing AMEC in a descriptor is destructive to the granule’s contents. Treat it as a break-before-make change (9.2) with a RemoveGranule-style flush in the middle.
  • Primary MECID registers can safely be changed by a higher EL while the lower regime is not running. That is the normal case for VMECID_P_EL2 on a REC switch, because the Realm’s mappings are not active while the RMM runs. Realm EL2 may turn on SCTLR2_EL2.EMEC itself only if MECID_P0_EL2 and MECID_P1_EL2 are 0, matching the MECID it was already using.
  • Alternate MECID registers can be changed only when no valid translation uses them and TLB entries with AMEC=1 have been invalidated. Clearing TCR2_EL2.AMEC0/1 first guarantees that no new AMEC=1 translation can be created while the register changes.

Security note: MEC defends against physical attackers and makes reused memory safe. It does not replace stage 2 isolation. MEC does not reliably catch a bug in the RMM’s RTT handling that maps Realm A’s page into Realm B. If the data is only in memory, B’s MECID decrypts it to garbage. If lines filled under A’s MECID are still cached, B may read A’s plaintext. If the bug also reuses A’s MECID, B reads the plaintext directly. Review MECID assignment code as carefully as RTT code.

Validation note: QEMU’s FEAT_MEC support models the registers (and, in recent versions, MECID selection) but does no encryption. On FVP, MEC is enabled with a model parameter, and TF-RMM reports whether it found FEAT_MEC. Neither environment will show the silent corruption a missing DC CIPAE causes on silicon. To test the maintenance rules pre-silicon, use an RTL or emulation build with the real memory protection engine. Write a pattern under MECID a, remap the granule under MECID b with the PoE flush deliberately omitted, and check that the corruption appears. Then confirm it disappears when the flush is restored.

Checkpoint

Q12.5.1 The RMM destroys Realm A and immediately gives one of its granules to a new Realm B, which has a different private MECID. The granule stays in Realm PAS the whole time. Which step is required for correctness, beyond unmapping and TLB invalidation?

  • A. An undelegate and re-delegate round trip through EL3, because Realm EL2 has no cache maintenance instruction that reaches past the PoC
  • B. DC CIVAC to the PoC through A’s old mapping before it is removed
  • C. Nothing, because B’s MECID selects a different key and A’s data becomes unreadable automatically
  • D. DC CIPAE on every line of the granule (to the PoE), then DSB, before B can access it, so that no line filled under A’s MECID survives in a cache to be hit or written back under B’s
Answer

D. Caches before the PoE hold plaintext, and the architecture gives no guarantee that a hit respects the MECID, so a line left over from A is a mismatched-MECID hazard. C is the tempting misconception: the key change protects only data that has already reached memory. A rests on a false premise: DC CIPAE is executable at Realm EL2 precisely so that the RMM can do this flush without an SMC, and the granule never needs to leave Realm PAS. B is the wrong point and relies on a mapping that should already be gone.

Read more: Arm ARM (DDI0487), FEAT_MEC and DC CIPAE; Arm RME and MEC example software flows (109839), Mismatched MECID avoidance

Q12.5.2 Realm EL2 software wants to change MECID_A0_EL2 while the system is running. Which approach is safe?

  • A. Write the register and issue an ISB, because MECID registers are not cached in TLBs
  • B. Clear TCR2_EL2.AMEC0 so no new AMEC=1 translations can be used, remove or invalidate every AMEC=1 mapping and its TLB entries, clean and invalidate the affected granules to the PoE, then write the register and re-enable
  • C. Clear SCTLR2_EL2.EMEC, write the register, then set EMEC again
  • D. Ask EL3 to issue RMM_MEC_REFRESH for the new value, which makes the change atomic
Answer

B. Alternate MECID registers may change only when no valid translation is associated with them and the AMEC=1 TLB entries are gone. AMEC0 exists to stop new ones being created during the change. Toggling EMEC (C) changes the MECID of every active Realm EL2 access, and that is itself a mismatch hazard. RMM_MEC_REFRESH (D) changes a MECID’s key, not which MECID a register selects.

Read more: Arm ARM (DDI0487), MECID_A0_EL2 and TCR2_EL2.AMEC0; Arm RME and MEC example software flows (109839), Update Alternate MECID register

Q12.5.3 Which statement about EL3’s use of MEC is correct?

  • A. EL3 always uses MECID 0, so it cannot access Realm memory once MEC is enabled
  • B. EL3 inherits MECID_P0_EL2, so it sees whatever Realm the RMM last ran
  • C. EL3 accesses to Secure, Non-secure and Root PAS use MECID 0. Accesses to Realm PAS use MECID_RL_A_EL3 when SCTLR2_EL3.EMEC=1, which is typically set to the RMM’s MECID so EL3 can load and serve the RMM
  • D. EL3 selects a MECID per access through the AMEC bit of its own descriptors
Answer

C. MEC contexts exist only in the Realm PAS, and EL3 has a single Realm-PAS MECID register of its own. A contradicts the RMM boot flow, in which EL3 populates Realm memory. B would couple EL3 to whatever state EL2 left behind. D describes Realm EL2’s alternate mechanism, not EL3’s.

Read more: Arm ARM (DDI0487), MECID_RL_A_EL3 and SCTLR2_EL3.EMEC; Arm RME and MEC example software flows (109839), EL3 translation regime

Part 13: Hardening features

Prerequisites: 2.4, 3.2, 5.2, 5.5, 6.5, 8.5

If you already know: If you have shipped -mbranch-protection=standard in TF-A or a kernel, skim 13.1 for FPAC and FEAT_PAuth_LR only. Do not skip 13.3: the PAC, TBI and MTE interactions are where configurations quietly go wrong.

Why this matters for bring-up/validation: Every feature here arrives trapped or disabled until EL3 and EL2 enable it and context-switch its state. MTE in particular depends on memory-controller tag storage that firmware must reserve, protect and describe, so its failures are platform failures as much as CPU ones.

This part covers the architectural defences against memory-corruption exploits, in the order an attacker meets them. Pointer Authentication and BTI (13.1) constrain control flow probabilistically: a signed return address, and a landing pad for every indirect branch. The Guarded Control Stack makes return addresses unforgeable, and the Translation Hardening Extension gives the kernel a checked update path for its own page tables (13.2). The recurring firmware lesson is that these features share state across Exception levels (one set of PAuth keys, one GCR_EL1), so each layer that uses them must install and restore its own state.

The second half is the Memory Tagging Extension. 13.3 first settles who owns the upper pointer bits (TTBR select, TBI, MTE tag, PAC) and what FAR reports. 13.4 and 13.5 cover the data model, instructions and checking modes, and 13.6 widens the view to the SoC: the enable chain, tag-storage carve-outs, stage 2, devices, the 2022 MTE extensions, the security limits including speculative tag leakage, and how to validate MTE before silicon.

13.1 Pointer Authentication and BTI

Pointer Authentication (PAuth) and Branch Target Identification (BTI) are the two halves of Arm’s control-flow integrity story. PAuth protects backward edges, such as return addresses, and any other pointer that software chooses to sign. BTI constrains forward edges, meaning indirect branch targets. Both arrive in the HINT space wherever possible, so a binary built with -mbranch-protection=standard still runs on a v8.0 core: there, PACIASP, AUTIASP and BTI c execute as NOPs.

Keys, enables and traps

FEAT_PAuth is mandatory from v8.3, and therefore present in every Armv9-A PE. DDI0487 A2 gives the earliest version that permits it. It defines five 128-bit keys, each split into a Hi/Lo pair of system registers:

KeyRegistersUsed by
Instruction AAPIAKeyHi_EL1, APIAKeyLo_EL1PACIA*, AUTIA*, RETAA, BRAA, BLRAA, ERETAA
Instruction BAPIBKey{Hi,Lo}_EL1PACIB*, AUTIB*, … *AB forms
Data AAPDAKey{Hi,Lo}_EL1PACDA, AUTDA, LDRAA
Data BAPDBKey{Hi,Lo}_EL1PACDB, AUTDB, LDRAB
GenericAPGAKey{Hi,Lo}_EL1PACGA (a 32-bit MAC into the top half of Xd)

The keys are not banked by Exception level. There are no _EL2 or _EL3 key registers. EL2 and EL3 sign with whatever is in the _EL1 registers. This one fact drives all of the firmware work below.

Each regime enables each key separately: SCTLR_ELx.EnIA [31], EnIB [30], EnDA [27] and EnDB [13]. In SCTLR_EL1 they apply to both EL1 and EL0. When a key is disabled, the corresponding PAC and AUT instructions leave the pointer unchanged. That is how the HINT-space forms stay harmless. PACGA has no enable bit.

A higher EL can also trap the instructions and the key registers:

ControlEffect when 0EC
HCR_EL2.API [41]PAuth instructions at EL0/EL1 trap to EL20x09
HCR_EL2.APK [40]EL1 accesses to the key registers trap to EL20x18
SCR_EL3.API [17]PAuth instructions at EL0–EL2 trap to EL30x09
SCR_EL3.APK [16]Key register accesses at EL1/EL2 trap to EL30x18

The reset values are UNKNOWN, so EL3 has to write them. A forgotten SCR_EL3.API shows up as Linux dying on its first PACIASP with an EC 0x09 trap landing in BL31 (17.3). Writes to a key register, and to SCTLR_ELx.En*, are direct writes to system registers that later PAC/AUT instructions read indirectly. A context synchronization event is therefore needed between the write and the first use (7.8).

PAC and AUT

PACIA Xd, Xn computes a MAC, the PAC, over three inputs: the pointer in Xd, a 64-bit modifier in Xn, and key A. It then inserts the PAC into the pointer’s unused upper bits. Which bits are unused depends on TnSZ, TBI and bit 55. 13.3 works out the width: with a 48-bit VA it is 7 bits when TBI is on and 15 bits when TBI is off. AUTIA Xd, Xn recomputes the PAC, and if it matches it restores the canonical pointer. XPACI/XPACD strip a PAC without checking it.

The modifier is what stops a signed pointer being replayed in a different context:

FormPointerModifierTypical use
PACIASP / AUTIASPX30SPReturn address in a non-leaf function
PACIAZ / AUTIAZX30zeroLeaf functions or no-stack contexts (weaker)
PACIA1716 / AUTIA1716X17X16Signing in trampolines and PLTs
PACIA Xd, XnXdXnArbitrary: C++ vtables, function pointers with a type discriminator
RETAA, ERETAA / BRAA Xn, Xm, BLRAA Xn, XmX30, ELR_ELx / XnSP / XmCombined authenticate-and-branch
LDRAA Xt, [Xn, #imm]!Xn (DA key)zeroAuthenticated load

The problem with the SP modifier is well known. Two call sites at the same stack depth sign their return addresses with identical modifiers, so the signed LR from one can be substituted into the other. FEAT_PAuth_LR, below, addresses that.

The standard prologue and epilogue look like this:

func:
    paciasp                 // sign LR with SP; also an implicit BTI c landing pad
    stp     x29, x30, [sp, #-16]!
    mov     x29, sp
    bl      callee
    ldp     x29, x30, [sp], #16
    autiasp                 // or: retaa
    ret

What an authentication failure does

The failure behaviour changed across versions. The ID_AA64ISAR1_EL1.APA/API (and ID_AA64ISAR2_EL1.APA3) field value tells you which behaviour you have:

Field valueFeatureOn AUT failure
0b0001FEAT_PAuthAn error code is written into the PAC field’s upper bits, making the pointer non-canonical. The fault comes later, on use, as a translation fault
0b0010FEAT_EPACAUT failure as above. The change is in PAC*: signing a pointer whose extension bits are not canonical writes a PAC of zero instead of a PAC with one bit flipped
0b0011FEAT_PAuth2PAC XORs the MAC into the field instead of replacing it, and AUT XORs it back, so a failure leaves a deterministically corrupted pointer. Mandatory from v8.6
0b0100FEAT_FPACAUT* failure generates a synchronous exception, EC 0x1C, at the instruction itself
0b0101FEAT_FPACCOMBINEThe combined forms (RETAA, BRAA, LDRAA, …) also fault with EC 0x1C
0b0110FEAT_PAuth_LRAs FPACCOMBINE, plus the PC-modifier instructions

The algorithm is reported separately. APA means QARMA5, APA3 in ID_AA64ISAR2_EL1 means QARMA3 (FEAT_PACQARMA3), and API means an IMPLEMENTATION DEFINED algorithm. GPA/GPA3/GPI report the same for PACGA. QARMA3 is cheaper in latency. The choice of algorithm does not change software, but it does change the PAC values, so a test vector that passes on the FVP’s QARMA5 configuration will not match a core using an IMPLEMENTATION DEFINED algorithm.

Without FPAC, the failure point is the next dereference or RET. That surfaces as an instruction abort with a translation fault on a weird-looking address whose top bits are wrong. On a crash dump, a FAR with garbage in bits [54:48] after a RET is the signature (18.1). With FPAC, ESR_ELx.EC = 0x1C and the ISS says which key type failed. The exception is taken to the EL that would handle a synchronous exception from the current EL. An FPAC at EL1 therefore goes to EL1, not to EL3.

Security note: Without FPAC an attacker gets an oracle. A failed AUT that does not immediately fault produces a pointer the attacker may be able to observe or reuse. Combined with a speculative branch on the result, the PACMAN attack (2022) brute-forced PACs speculatively on Apple M1. PAuth is a deterministic MAC; it is not a speculation barrier. FPAC narrows the architectural oracle but not the speculative one (Part 14).

Key management at exception entry

Because keys are shared across ELs, every software layer that uses PAuth for itself must install its own keys on entry and restore the lower layer’s keys on exit:

  • Linux (EL1) gives each user task its own APIA/APIB/APDA/APDB/APGA keys and uses a separate kernel APIA key. It swaps in the kernel key on entry from EL0 (ptrauth_keys_install_kernel) and restores the task’s keys on return.
  • KVM saves the host keys and loads the guest’s on vcpu entry. Alternatively it traps the guest’s first PAuth use through HCR_EL2.API/APK = 0 and switches keys lazily.
  • TF-A BL31, when built with BRANCH_PROTECTION ≠ 0, saves all five keys of the interrupted world in the save_gp_pmcr_pauth_regs macro (lib/el3_runtime/aarch64/context.S) and loads its own APIA key from cpu_data. On exit, restore_gp_pmcr_pauth_regs restores the saved keys. The saved keys also belong to the per-world context, so the Secure world never sees Normal-world keys and vice versa.

The required ordering is: key write, then a context synchronization event, then the first PACIASP. In practice the entry path is assembly that does not itself sign anything until the keys are installed. Note also that ERET is a context synchronization event, so restored keys are in effect for the lower EL’s first instruction.

Bring-up note: Mixed-IP systems are the trap. If a little core implements an IMPLEMENTATION DEFINED algorithm and a big core implements QARMA5, a pointer signed on one core will not authenticate after migration to the other. Linux treats PAuth as a system-wide feature only if the algorithm matches on all CPUs (cpufeature sanitises APA/API/APA3 as “exact”). Check this on any heterogeneous cluster before turning it on.

FEAT_PAuth_LR

FEAT_PAuth_LR is a 2023 extension. Arm presents it with v9.5, although TF-A’s build documentation describes it as optional from v9.4, so check DDI0487 A2. It is reported by the value 0b0110 in whichever of ID_AA64ISAR1_EL1.APA/API or ID_AA64ISAR2_EL1.APA3 is non-zero. It adds the address of the signing instruction as a second modifier, which makes a signed LR bound to its function, not merely to a stack depth:

  • PACIASPPC / PACIBSPPC sign X30 with SP and the PC of the instruction itself.
  • AUTIASPPC <label> and RETAASPPC <label> authenticate with SP and a PC computed from a PC-relative immediate that points back at the signing instruction. The ...SPPCR Xm forms take that address in a register.
  • PACNBIASPPC is the variant without the implicit BTI.
  • PACIA171615 / AUTIA171615 take the pointer in X17 and two modifiers in X16 and X15.
  • PACM (HINT #39) sets PSTATE.PACM. While PACM is 1, the existing PACIASP and PACIA1716 take a second modifier (PC and X15 respectively), so a single hint retrofits old sequences. ID_AA64ISAR3_EL1.PACM reports whether this PACM behaviour is fully implemented or only trivially (see DDI0487 for what the trivial form guarantees).

The PSTATE.PACM behaviour is gated by SCTLR2_ELx.EnPACM/EnPACM0 and HCRX_EL2.PACMEn. TF-A sets SCTLR2_EL3.EnPACM and SCTLR2_EL1.EnPACM when ENABLE_FEAT_PAUTH_LR is set. SPSR_ELx has a PACM bit (bit 35 in TF-A’s definitions), so the state survives exceptions.

BTI

FEAT_BTI is permitted from v8.4, mandatory from v8.5, and reported in ID_AA64PFR1_EL1.BT. A page is guarded when its stage 1 Block or Page descriptor has the GP bit [50] set (stage 2 has no GP). In a guarded page, the first instruction executed after an indirect branch must be a compatible landing pad, or a Branch Target exception (EC 0x0D) is taken.

The mechanism is PSTATE.BTYPE, a 2-bit value that every branch sets and that the next instruction checks:

BranchBTYPE set
BR Xn / BRAA etc. from a guarded page, n = 16 or 170b01
BR Xn from a guarded page, any other register0b11
BR from a non-guarded page, any register0b01
BLR / BLRAA etc.0b10
Direct branches, RET, sequential execution0b00
Landing padAccepts BTYPE
BTI c01, 10 (call targets)
BTI j01, 11 (jump targets)
BTI jc01, 10, 11
BTI (no operand)none, so it is not a landing pad
PACIASP / PACIBSP01, 10, and 11 only when SCTLR_ELx.BT0/BT1 = 0

The X16/X17 rule exists so that linker veneers and PLT stubs, which branch with BR X16/X17, can land on a BTI c function entry. SCTLR_EL1.BT0 [35] and BT1 [36] make PACIxSP stricter for EL0 and EL1 respectively. BTYPE is saved in SPSR_ELx on exception entry and restored by ERET. An exception handler that returns to the same instruction (for example after a page fault on the landing pad) therefore preserves the check. Software that emulates a branch has to set SPSR.BTYPE itself.

Bring-up note: BTI is per page, not per image. TF-A builds its images with BTI landing pads and sets GP only on its own code regions. If a platform maps a ROM or a third-party blob as guarded and that blob was not built with -mbranch-protection, the first indirect call into it takes EC 0x0D. In the other direction, a Linux module built without BTI fails the same way only once the kernel maps it with PTE_GP.

Checkpoint

Q13.1.1 BL31 is built with BRANCH_PROTECTION=1 and runs on a FEAT_PAuth2 core without FPAC. On an SMC from Linux, BL31’s C code signs and authenticates its own return addresses. Which statement explains why BL31 must save Linux’s APIA key on entry?

  • A. SCR_EL3.APK = 1 makes EL3 use a banked copy of the key, which must be synchronised with the EL1 copy
  • B. The key must be saved only if Linux uses the B key, because EL3 cannot read the A key of a lower EL
  • C. There is a single set of _EL1 key registers shared by all ELs, so BL31 overwriting APIAKey would break every return address Linux signed before the SMC
  • D. It does not need to; ERET automatically restores the lower EL’s keys from SPSR_EL3
Answer

C. The PAuth keys are not banked by Exception level. EL3 signs with the same APIAKey{Hi,Lo}_EL1 registers that Linux uses. If BL31 installs its own key and does not restore Linux’s, then Linux’s next AUTIASP on a return address signed before the SMC fails. A is wrong because there are no banked EL3 keys; APK only controls trapping of key-register accesses. D is wrong because SPSR_EL3 holds PSTATE, not keys.

Read more: Arm ARM (DDI0487), Pointer authentication; APIAKeyHi_EL1; TF-A save_gp_pmcr_pauth_regs

Q13.1.2 A guarded page contains a function whose first instruction is BTI j. A C call through a function pointer (BLR X8) reaches it. What happens?

  • A. A Branch Target exception (EC 0x0D), because BLR sets BTYPE = 0b10 and BTI j accepts only 0b01 and 0b11
  • B. Nothing; BTI j accepts every BTYPE except 0b00
  • C. An exception only if SCTLR_EL1.BT1 = 1
  • D. A Branch Target exception only if X8 was not X16 or X17
Answer

A. BLR always sets BTYPE 0b10, a call. BTI j is a jump-only landing pad, so the check fails. The X16/X17 rule (D) applies to BR, not to BLR, and gives BTYPE 0b01 rather than avoiding the check. SCTLR_ELx.BTn (C) only affects whether PACIxSP accepts BTYPE 0b11.

Read more: Arm ARM (DDI0487), PSTATE.BTYPE; BTI instruction; Branch Target exception

Q13.1.3 Two functions, f and g, both called from main at the same stack depth, use PACIASP/AUTIASP. An attacker with a stack write primitive copies the signed LR saved by f into g’s frame. Which feature makes g’s AUTIASP-equivalent authentication fail?

  • A. FEAT_FPAC, because it adds the function’s address to the modifier
  • B. FEAT_EPAC, because it removes the error code that let the attacker detect failure
  • C. BTI, because the return lands in main without a landing pad
  • D. FEAT_PAuth_LR (PACIASPPC/RETAASPPC), because the signing instruction’s PC becomes a second modifier, so f’s signature does not verify in g
Answer

D. With SP as the only modifier, identical SP values make the two signed LRs interchangeable. FEAT_PAuth_LR adds the address of the signing instruction, which differs between f and g. FPAC (A) only changes how a failure is reported (an immediate EC 0x1C); it does not change the modifier. BTI (C) does not check RET targets.

Read more: Arm ARM (DDI0487), FEAT_PAuth_LR; PACIASPPC; RETAASPPC

13.2 Guarded Control Stack and Translation Hardening

PAuth makes a corrupted return address detectable with high probability, but it is probabilistic and it is vulnerable to signing gadgets. The Guarded Control Stack (GCS) makes return addresses unforgeable by keeping a second copy in memory that ordinary stores cannot write. The Translation Hardening Extension (THE) applies a similar idea to the translation tables themselves: it gives software a checked update path for descriptors, so that a kernel write primitive is not automatically a page-table write primitive.

FEAT_GCS: versions and enables

GCS was announced as part of Arm’s 2022 extensions and is an Armv9-A feature. Arm material places it as OPTIONAL from v9.3, while some vendor and TF-A commit text says v9.4, so take the version from DDI0487 A2 and the ID register, not from -march. It is reported by ID_AA64PFR1_EL1.GCS [47:44]. GCS memory is identified through stage 1 permission indirection, so in practice it needs FEAT_S1PIE (5.5).

GCS is gated in the usual pattern (17.3): SCR_EL3.GCSEn [39] for EL2 and below, HCRX_EL2.GCSEn [22] for EL1 and EL0. If these are clear, the GCS registers trap and GCS is not active at the lower ELs. TF-A sets SCR_EL3.GCSEn and context-switches the EL2 GCS registers with ENABLE_FEAT_GCS.

Registers

RegisterContent
GCSPR_EL0..GCSPR_EL3GCS pointer, PTR [63:3]. 8-byte aligned, grows down. EL0 can read GCSPR_EL0 only when GCSCRE0_EL1.nTR = 1, and can update it only through GCS instructions
GCSCR_EL1/EL2/EL3Per-EL control for the EL itself
GCSCRE0_EL1Control for EL0

The GCSCR_ELx fields are:

FieldBitMeaning
PCRSEL0Procedure call/return enable: BL/BLR push and RET pop through the GCS
RVCHKEN5Return value check: RET compares the popped value with the target in LR
EXLOCKEN6Exception-return lock (not in GCSCRE0_EL1)
PUSHMEn8Permit GCSPUSHM explicit pushes
STREn9Permit GCSSTR/GCSSTTR explicit stores to GCS memory
nTR10GCSCRE0_EL1 only. When 0, EL0 reads of GCSPR_EL0 trap; Linux always sets it to 1

How it works

When PCRSEL is set, every BL or BLR also pushes the return address: GCSPR_ELx -= 8, then a GCS store of LR at the new pointer. RET (and RETAA and friends) performs a GCS load from GCSPR_ELx, then increments the pointer. If RVCHKEN is set and the loaded value differs from the branch target, a GCS exception is taken: EC 0x2D, with ISS.ExType = 0 (data check) and ISS.IT identifying the instruction (RET, RETAA, GCSPOPM, GCSSS1, …).

GCS memory is a distinct permission. In stage 1 permission indirection there is a GCS encoding (Linux uses PIE_GCS = 0x9) under which:

  • ordinary STR, STP and atomics from any EL fault as a permission fault;
  • GCS stores (implicit pushes, GCSPUSHM, GCSSTR when STREn permits) succeed;
  • ordinary loads are allowed, which is how debuggers and unwinders read the stack.

A fault caused by a GCS access is a normal data abort, marked by ISS2.GCS (bit 8 of ISS2) in ESR_ELx. Linux reports GCS data-check failures (EC 0x2D) as SIGSEGV with SEGV_CPERR.

The remaining instructions are:

InstructionPurpose
GCSPUSHM Xt / GCSPOPM XtPush or pop an arbitrary entry (used by setjmp/longjmp unwinders)
GCSSS1 Xt / GCSSS2 XtTwo-step stack switch. The target stack must hold a valid cap token (address in [63:12] and token 0x1). Switching writes an in-progress token (0x5) to the old stack, so neither stack can be used twice
GCSSTR / GCSSTTRExplicit stores to GCS memory, gated by STREn
GCSPUSHX / GCSPOPX / GCSPOPCXPush or pop an exception return record (EL1 and above), letting a kernel protect its own nested exception returns
GCSB DSYNCGCS barrier (HINT; NOP without GCS)
CHKFEAT X16FEAT_CHK: clears bit 0 of X16 if GCS is enabled at the current EL

Exception entry does not push anything onto the GCS. The interrupted context’s GCSPR_ELx simply stays where it was, and the handler at the higher EL uses its own GCSPR.

GCSB DSYNC

GCS stores are not ordinary explicit stores, so a plain DMB does not order them. GCSB DSYNC orders the GCS memory effects of earlier instructions before later memory accesses that are ordered by a barrier or by release semantics. In the other direction, it orders acquire accesses before later GCS effects. Linux issues it on context switch whenever the previous or next task has GCS enabled. The reason given in gcs_thread_switch() is that a migrated thread’s GCS pushes must be visible to the PE that runs it next. It is also issued before reading or modifying another thread’s GCS, for example in signal delivery. Without it, a task migrated between PEs can pop a stale value and take a spurious EC 0x2D, which is a classic intermittent failure (7.5, 7.10).

PSTATE.EXLOCK

EXLOCK protects the handler’s own return state. When GCSCR_ELx.EXLOCKEN = 1, an exception taken from the same EL sets PSTATE.EXLOCK to 1. An exception from a lower EL clears it. While EXLOCK is 1, writes to ELR_ELx and SPSR_ELx at that EL generate a GCS exception with ExType = EXLOCK. An ERET that returns to the same EL with EXLOCK = 0 while EXLOCKEN = 1 is an illegal exception return. The effect is that a nested handler cannot be tricked into rewriting the return state of the frame below it unless it goes through the GCS exception-return record instructions. EXLOCK is saved in SPSR_ELx like the other PSTATE bits (2.4).

FEAT_CHK

CHKFEAT (HINT #40) exists so that runtime code can ask “is GCS on right now?” without reading a system register that might trap:

    mov     x16, #1
    chkfeat x16             // NOP on old cores: x16 stays 1
    cbz     x16, gcs_on     // bit 0 cleared => GCS enabled at this EL

Because it is a HINT, it is safe on every core. On a core without GCS the answer is always “off”. QEMU implements FEAT_CHK with GCS as its only defined bit, which reflects the current architecture.

Bring-up note: Enabling GCS for EL1 itself (a kernel shadow stack) needs a GCS region mapped with the GCS permission before GCSCR_EL1.PCRSEL is set. Otherwise the very next BL takes a permission fault on the push, and the fault handler’s own BL faults again. Set GCSPR_EL1 and the mapping first, then set PCRSEL and synchronise with an ISB. Expect the first return after enabling to fail, because that return address was never pushed. Linux documents the user-space equivalent: you cannot return from the function that enabled GCS.

FEAT_THE: Translation Hardening

FEAT_THE is a 2022 extension, the same wave as GCS. TF-A describes it as optional from v8.8, so check DDI0487 A2 for the version. It is reported by ID_AA64PFR1_EL1.THE [51:48]. The threat it addresses is an attacker with an arbitrary-write primitive in EL1 who flips descriptor bits (AP, UXN/PXN, the output address) to gain execute or write access. THE adds three things.

1. The Protected attribute. When TCR2_EL1.PnCH [0] = 1, bit [52] of stage 1 descriptors for the TTBRn_EL1 regime is reinterpreted as Protected and stops being the Contiguous bit. In the 128-bit D128 format the Protected bit is always present, at [114], independent of PnCH (sources differ on whether PnCH reads as RES0 or RES1 when TCR2_EL1.D128 = 1; see the register description) (5.7).

2. Read-Check-Write instructions. These are atomic read-modify-write instructions for descriptors, modelled on the LSE atomics (10.2):

Family64-bit128-bit pair
Compare and swapRCWCAS{A,L,AL}RCWCASP*
Bit set / clearRCWSET*, RCWCLR*RCWSETP*, RCWCLRP*
SwapRCWSWP*RCWSWPP*
“Soft” variantsRCWSCAS*, RCWSSET*, RCWSCLR*, RCWSSWP*...P forms

Each one loads the descriptor and computes the new value. It then stores the new value only if the RCW checks pass, or, for the RCWS* forms, if the RCW and RCWS checks both pass. The outcome is reported in NZCV, so software can branch on a refused update. The 64-bit forms are UNDEFINED when D128 is enabled for the regime. The architecture says these instructions are for translation-table updates, not for general use.

3. Mask registers.

  • RCWMASK_EL1 holds the bit-fields of a descriptor that an RCW instruction may change in a Protected descriptor.
  • RCWSMASK_EL1 is a software mask that the RCWS* forms also apply.

Lower-EL access to both is trapped to EL3 unless SCR_EL3.RCWMASKEn [42] = 1. TF-A sets this bit and context-switches the registers when ENABLE_FEAT_THE is set.

TCR2_EL1.PTTWI [10] (with HCRX_EL2.PTTWI) lets RCWS writes carry the Reduced Coherence property, in which the write need not be coherent with translation table walks until the usual TLB-maintenance sequence completes. It is a performance option and does not change the barrier recipe in 9.1.

The masks limit which bits change through the checked path. On their own they do not stop a plain STR to a table page. The full threat model therefore needs a component above EL1 that also:

  • keeps the table pages unwritable by ordinary stores. Stage 2 permission indirection provides “MostlyRO” (MRO, MRO-TL0/TL1) permissions in S2PIR_EL2 intended for this; see DDI0487 for the exact rules on which writes they admit (11.3);
  • prevents EL1 from widening the masks after boot, for example with fine-grained write traps on RCWMASK_EL1, or the register-mask features.

Read THE as the EL1 half of a hypervisor-assisted kernel-integrity design, not as a stand-alone defence.

Security note: In-process isolation, keeping one library’s data away from another’s within the same address space, is the job of permission overlays (FEAT_S1POE, POR_EL0) described in 5.5. POE is complementary to GCS. GCS protects control flow; POE protects data domains, with keys that user space can switch without a system call.

Checkpoint

Q13.2.1 A thread with GCS enabled is preempted on PE0, after which the kernel migrates it to PE1. Occasionally its first RET on PE1 takes an EC 0x2D data-check failure even though no attacker is present. Which missing step is the most likely cause?

  • A. An ISB after writing GCSPR_EL0 on PE1
  • B. A GCSB DSYNC on PE0’s context switch, so that the thread’s earlier GCS pushes are ordered before the release that publishes the thread to the run queue
  • C. A DSB ISH on PE1 before the ERET, because GCS loads bypass the cache
  • D. Setting GCSCR_EL1.EXLOCKEN so that the return state is locked
Answer

B. GCS stores are not ordered by a plain barrier or by the release in the scheduler’s lock. GCSB DSYNC orders the GCS memory effects before subsequent release or barrier-ordered accesses, which is what Linux’s gcs_thread_switch() does. Without it, PE1 can observe an old GCS entry. A (an ISB) handles context synchronization of the register write, not memory ordering of the pushes. C is wrong because GCS accesses are coherent memory accesses; the problem is ordering, not caching.

Read more: Arm ARM (DDI0487), The Guarded Control Stack; GCSB DSYNC

Q13.2.2 With FEAT_THE and TCR2_EL1.PnCH = 1, which statement about a stage 1 descriptor in the TTBR1_EL1 tables is correct?

  • A. Bit [52] is still the Contiguous hint, and Protected is carried in a software-reserved bit
  • B. A Protected descriptor cannot be modified by any write from EL1
  • C. RCWCAS on a Protected descriptor always succeeds; only RCWSCAS is checked
  • D. Bit [52] is the Protected bit, so these mappings cannot use the Contiguous hint, and an RCW update that would change a bit outside the permitted mask is refused, with the result reported in NZCV
Answer

D. PnCH repurposes bit [52] as Protected for the TTBRn_EL1 regime, which removes the Contiguous hint for those mappings. RCW instructions perform a conditional store and report the result in the condition flags. B overstates the mechanism: the architecture checks the RCW path, and blocking ordinary stores to table pages needs stage 2 permissions on top. C is wrong because the RCW checks apply to the non-S forms as well; RCWS adds the soft-mask check.

Read more: Arm ARM (DDI0487), TCR2_EL1.PnCH; RCWCAS; RCWMASK_EL1

Q13.2.3 A run-time library needs to know whether GCS is active for the current thread, and it must run unchanged on v8.2 cores. Which approach is architecturally safe?

  • A. mov x16, #1; chkfeat x16 and test bit 0 of X16
  • B. mrs x0, GCSCRE0_EL1 and test PCRSEL
  • C. Read ID_AA64PFR1_EL1.GCS through the kernel’s MRS emulation
  • D. mrs x0, GCSPR_EL0 and treat a non-zero value as “enabled”
Answer

A. CHKFEAT is in the HINT space, so it is a NOP on cores without FEAT_CHK, which leaves X16 = 1 (“not enabled”). Where FEAT_CHK is implemented it clears bit 0 when GCS is enabled at the current EL. B is an EL1 register, so it is UNDEFINED at EL0. C reports only that the feature is implemented, not that it is enabled for this thread. D is UNDEFINED on pre-GCS cores, and a non-zero pointer does not prove PCRSEL is set.

Read more: Arm ARM (DDI0487), CHKFEAT; FEAT_CHK

13.3 Who owns the upper address bits

A 64-bit pointer on a 48-bit VA system has 16 bits that translation does not use. Four parties compete for them: the TTBR select bit, Top Byte Ignore (TBI) software tags, the MTE logical tag, and the PAC. Large-VA features shrink the pool further. This section is the bookkeeping that tells you, for a given TCR_ELx, exactly which bits belong to whom. Get it wrong and you see PACs that never authenticate, MTE checks that silently never happen, or faults with FAR values that look impossible.

The fixed points

  • Bit 55 selects the VA range in two-range regimes (EL1&0, and EL2&0 with HCR_EL2.E2H = 1): 0 means TTBR0, 1 means TTBR1. TBI does not change this. Bit 55 is never part of a PAC or a tag, and it is preserved by every PAC/AUT/XPAC operation.
  • Bits [VA−1:0] are the address, where VA = 64 − TnSZ (5.2).
  • Bits [54:VA], and [63:56] when TBI is off, must equal bit 55 for translation. Otherwise the access takes a translation fault at level 0 (or at the starting level).

In the one-range regimes (EL2 with E2H = 0, and EL3) the upper bits must be zero rather than a copy of bit 55, and TCR_EL2/TCR_EL3 have a single TBI [20] and TBID [29].

TBI and TBID

TCR_EL1.TBI0 [37] and TBI1 [38] make the address translation ignore bits [63:56] for the TTBR0 and TTBR1 halves respectively. The top byte becomes an address tag that hardware carries through loads and stores but does not translate.

TBI originally applied to instruction addresses as well. FEAT_PAuth added TBID0 [51] and TBID1 [52]. When TBIDn = 1, TBI applies to data accesses only:

TBInTBIDnData address top byteInstruction address top byte
0xSignificantSignificant
10IgnoredIgnored (the PC is written with bits [63:56] as copies of bit 55)
11IgnoredSignificant, so a branch to a tagged address is a non-canonical target and faults

The architecture never holds a tagged PC. When TBI applies to instruction addresses, a branch or an ERET to a tagged address writes the PC with the top byte replaced by a sign extension of bit 55. TBID exists for PAC, not for safety: instruction pointers do not need a software tag byte, so freeing that byte gives code pointers a wider PAC (below). Linux sets TBI0 for user space, plus TBI1 | TBID1 when KASAN or MTE is in use for the kernel half.

The PAC field

The PAC is inserted into whatever is left after the address, bit 55 and (if TBI applies) the top byte. The DDI0487 pseudocode computes this in AddPAC from the bottom PAC bit (64 − TnSZ) and a top bit that is 55 when TBI applies to that kind of pointer, or 63 when it does not. The “kind” is the crucial part. For the instruction keys (PACIA, PACIB, …), the effective TBI is TBI && !TBID; for the data keys it is plain TBI.

VA size (TnSZ)TBI appliesPAC bitsWidth
39 (25)no[63:56], [54:39]24
39 (25)yes[54:39]16
48 (16)no[63:56], [54:48]15
48 (16)yes[54:48]7
52 (12, LPA2/LVA)no[63:56], [54:52]11
52 (12)yes[54:52]3

A typical Linux configuration has a 48-bit VA, user TBI0 = 1 and TBID0 = 0. That gives 7-bit PACs for both code and data pointers in user space. Setting TBID0 would give instruction pointers 15 bits while keeping the tag byte for data. The cost of a 3-bit PAC at 52-bit VA is real: a one-in-eight guess rate makes PAuth close to decorative without FPAC to turn every wrong guess into a crash (13.1).

Note that the PAC width for a pointer depends on the TnSZ of the range that bit 55 of that pointer selects. TTBR0 and TTBR1 pointers can therefore have different PAC widths in the same process.

The MTE logical tag

MTE (13.4) defines the logical tag as bits [59:56], inside the TBI byte. In the base MTE architecture, a load or store can be tag-checked only if TBI applies to its address. A pointer in a range with TBIn = 0 is an unchecked access no matter what MAIR says. Bits [63:60] stay free for software, and HWASan-style schemes or allocator metadata use them.

MTE also costs the PAC nothing extra, because the PAC already avoids the TBI byte. A data pointer with TBI on carries the MTE tag in [59:56], 4 spare bits in [63:60] and a 7-bit PAC in [54:48]. All three can coexist.

TCMA: match-all tags

TCR_EL1.TCMA0 [57] and TCMA1 [58] (FEAT_MTE2) make a particular logical tag value unchecked:

  • TTBR0 range (bit 55 = 0): logical tag 0b0000 is treated as unchecked when TCMA0 = 1.
  • TTBR1 range (bit 55 = 1): logical tag 0b1111 is treated as unchecked when TCMA1 = 1.

These are the values that a canonical, never-tagged pointer has. With TCMA1 = 1, a kernel can enable MTE checking for EL1 and still dereference untagged 0xffff... pointers produced by code that knows nothing about tags (early boot, per-CPU offsets, phys_to_virt). Linux’s TCR_MTE_FLAGS sets exactly TCMA1 | TBI1 | TBID1. The consequence for security is that the canonical tag becomes a hole: an allocator must never hand out 0b1111 (kernel) or 0b0000 (user, if TCMA0 is set) as a real tag. Linux excludes them through GCR_EL1.Exclude (13.5).

Large VAs and D128

The 52-bit VA configurations (5.7) use the same rules. FEAT_LVA (64K granule) and FEAT_LPA2 (4K/16K granules with TCR_ELx.DS = 1) both allow TnSZ down to 12. The address then consumes bits [51:0], the TBI byte and bit 55 are unchanged, and the PAC is squeezed to bits [54:52]. MTE is unaffected, because its tag lives in the TBI byte. A kernel that switches to 52-bit VA for capacity reasons should be honest that it is trading PAuth strength for address space.

FEAT_LVA3 with the D128 translation format allows a 56-bit VA, using bits [55:0] with bit 55 doubling as the range select. Here [54:VA] is empty, so with TBI on, no bits are left for a PAC at all. With TBI off, only the top byte is available, and MTE cannot use it. Take the exact PAC-field rules for D128 and LVA3 configurations from the AddPAC/CalculateBottomPACBit pseudocode in the DDI0487 issue you target, not from this derivation. The MTE4 controls TCR_ELx.MTX0/MTX1 [60]/[61] (13.6) change the accounting again, because they decouple MTE checking from TBI.

What FAR_ELx reports

Faults expose the upper bits, and a crash-dump reader needs to know which bits to trust:

FaultFAR_ELx[63:56]
Data abort or watchpoint on a tagged addressThe tag byte as used by the access (Linux strips it from si_addr unless the handler set SA_EXPOSE_TAGBITS)
Instruction abortThe faulting PC. If TBI applied to instruction addresses, the branch already replaced the top byte with a sign extension of bit 55; if not (TBI off, or TBIDn = 1), the non-canonical top byte the branch target carried
Synchronous MTE tag check fault, without FEAT_MTE_TAGGED_FAR[59:56] = the logical tag; [63:60] UNKNOWN
Synchronous MTE tag check fault, with FEAT_MTE_TAGGED_FARAll of [63:56] valid
Asynchronous tag check faultNo FAR at all; only a TFSR_ELx flag
RET after a failed AUT without FPACA corrupted PAC field or error code, so the “address” has garbage in [54:48] or the top byte

FEAT_MTE_TAGGED_FAR is a 2022 MTE extension (Linux calls it Armv8.9), reported in ID_AA64PFR2_EL1.MTEFAR [11:8] and exposed to user space as HWCAP3_MTE_FAR. Without it, Linux overwrites FAR[63:60] with bits from the untagged address before reporting, so user space does not see UNKNOWN garbage.

Bring-up note: When a level-0 translation fault arrives at a “valid” address, compare FAR bits [63:56] and [54:VA] with bit 55 before suspecting the tables. A pointer that was tagged by code expecting TBI = 1, but used in a regime with TBI = 0 (EL3, or EL2 with E2H = 0 and TCR_EL2.TBI = 0), faults exactly like an unmapped address. Firmware that inherits an allocator or a library from a TBI-assuming environment hits this first.

Checkpoint

Q13.3.1 A user process runs with T0SZ = 16, TBI0 = 1 and TBID0 = 1. How wide are the PACs produced by PACIA (code pointer) and PACDA (data pointer) for TTBR0 addresses?

  • A. Both 7 bits
  • B. Both 15 bits
  • C. PACIA 15 bits ([63:56] and [54:48]); PACDA 7 bits ([54:48])
  • D. PACIA 7 bits; PACDA 15 bits
Answer

C. With TBID0 = 1, TBI applies only to data addresses. The instruction keys therefore see TBI as off and may use the top byte, giving 8 + 7 = 15 bits. The data keys see TBI on and use only [54:48]. D reverses the roles: TBID frees the top byte of instruction pointers, which is its whole purpose.

Read more: Arm ARM (DDI0487), Pointer authentication, the PAC field; TCR_EL1.TBID0

Q13.3.2 A kernel enables MTE checking at EL1 with TCR_EL1.TCMA1 = 1. A kernel pointer 0xffff_8000_1234_0000 (never tagged) is dereferenced into Tagged memory whose allocation tag is 0x3. What happens, and why?

  • A. No fault. The logical tag is 0xF and bit 55 = 1, so TCMA1 makes the access unchecked
  • B. A synchronous tag check fault, because 0xF ≠ 0x3
  • C. No fault, because the TTBR1 range is never tag-checked
  • D. A translation fault, because bits [63:56] are not ignored at EL1
Answer

A. Bits [59:56] of the pointer are 0xF. With bit 55 = 1 and TCMA1 = 1, tag 0b1111 is a match-all value and the access is unchecked. This is why allocators must exclude 0xF as a real kernel tag. Without TCMA1 the result would be B. C is wrong because TTBR1 accesses are checked whenever TBI1 is set, TCF is not NONE and the memory is Tagged.

Read more: Arm ARM (DDI0487), TCR_EL1.TCMA1; Allocation Tag checking

Q13.3.3 Linux moves from 48-bit to 52-bit user VA (FEAT_LPA2, T0SZ = 12) with TBI0 = 1. What happens to user-space PAuth and MTE?

  • A. Both are unaffected; the extra address bits come from the TBI byte
  • B. The MTE logical tag is unaffected, but the user PAC shrinks from 7 bits to 3 bits
  • C. MTE must be disabled because bits [59:56] become address bits
  • D. PAuth stops working because no PAC bits remain
Answer

B. The four extra address bits [51:48] are taken from the PAC field [54:48], leaving [54:52]. The TBI byte, and therefore the MTE tag in [59:56], is untouched. D would be true only if the VA reached bit 55, as in the 56-bit LVA3 configuration with TBI on.

Read more: Arm ARM (DDI0487), FEAT_LPA2; Pointer authentication, the PAC field

13.4 MTE architecture

The Memory Tagging Extension (MTE) attaches a small “colour” to every 16 bytes of memory and to every pointer, then has the hardware compare the two on each checked access. It is a lock-and-key scheme. The allocator chooses the colours, and the hardware catches use-after-free and buffer overflows when a pointer of one colour touches memory of another. This section covers the data model and the instructions. 13.5 covers when checks happen and how failures are reported, and 13.6 covers what the platform must provide.

Feature levels

ID_AA64PFR1_EL1.MTE [11:8] reports one of four levels:

ValueFeatureWhat you get
0b0000—Nothing
0b0001FEAT_MTE (v8.5)Instructions only at EL0: IRG, ADDG, SUBP and so on manipulate pointer tags, but no allocation tags are stored. Tag loads read as zero and tag stores are ignored
0b0010FEAT_MTE2Full MTE: allocation-tag storage, tag checking, the EL1 bulk instructions, the tag cache-maintenance operations
0b0011FEAT_MTE3MTE2 plus asymmetric checking (13.5)

All the features are optional, including in Armv9-A. ID_AA64PFR1_EL1.MTEX and ID_AA64PFR2_EL1 report the later extensions (MTE4, MTE_PERM, MTE_TAGGED_FAR, MTE_STORE_ONLY), which 13.6 covers. In practice “supports MTE” means MTE2 or higher. FEAT_MTE alone exists so that a binary using the instructions runs without faulting on a core that has no tag storage.

Allocation tags and logical tags

  • A logical tag (or address tag) is 4 bits held in bits [59:56] of a virtual address. It is carried in the TBI byte, so it costs no translation (13.3).
  • An allocation tag is 4 bits held in memory, one per 16-byte, 16-byte-aligned granule of physical memory. The tag belongs to the physical granule, not to the VA. Two VAs that alias the same PA share its allocation tags.

Allocation tags exist only for memory whose final memory attribute is Tagged Normal. At stage 1 that is the MAIR encoding 0xF0, Inner and Outer Write-Back, Read-Allocate, Write-Allocate, Non-transient, plus tagging (6.5). Stage 2 and system controls can withdraw it (13.6). For any other memory type, tag reads return zero, tag writes are ignored, and accesses are unchecked.

Tag storage costs 4 bits per 128 bits, or 1/32 (3.125%) of the tagged memory. Where the tags live is not architectural. The usual implementation is a carve-out of DRAM that the memory controller manages. In the cache hierarchy, tags may travel with their data lines or in separate tag caches, and that is IMPLEMENTATION DEFINED. Software sees only the instructions below.

Access control: who may touch allocation tags

The instructions that read or write allocation tags work only when allocation tag access is enabled for the current EL:

  • SCTLR_EL1.ATA [43] for EL1 and ATA0 [42] for EL0 (and the equivalent bits in SCTLR_EL2/EL3);
  • and, from above, HCR_EL2.ATA [56] and SCR_EL3.ATA [26] (13.6).

When access is disabled, LDG reads a tag of 0 and STG-class stores update only data (or nothing). Pointer-only instructions such as IRG and ADDG still work. This is separate from checking: ATA controls whether software may access tags, while TCF controls whether loads and stores are checked against them.

The instructions

Pointer manipulation (no memory access)

InstructionEffect
IRG Xd|SP, Xn|SP{, Xm}Insert Random taG: copies Xn to Xd with a random logical tag, excluding the tags in GCR_EL1.Exclude OR’d with Xm[15:0]
GMI Xd, Xn|SP, XmTag Mask Insert: Xd = Xm | (1 << tag(Xn)), which builds an exclusion set (“not the neighbour’s tag”)
ADDG Xd|SP, Xn|SP, #uimm6, #uimm4Adds uimm6 × 16 to the address and uimm4 to the tag, skipping excluded tags
SUBG ...The same with subtraction
SUBP Xd, Xn|SP, Xm|SP / SUBPS / CMPP56-bit pointer difference or compare that ignores the tags

ADDG exists because the compiler tags each stack slot differently. It steps both the address and the colour in one instruction, staying clear of colours the allocator excludes.

Tag stores

InstructionWrites
STG Xt|SP, [Xn|SP{, #simm}]The allocation tag of one granule := the logical tag of Xt. The address comes from Xn. Pre- and post-index forms exist
STZGSame, and zeroes the 16 data bytes
ST2G / STZ2GTwo consecutive granules (32 bytes)
STGP Xt1, Xt2, [Xn|SP{, #simm}]16 bytes of data and the tag taken from the address register
DC GVA, XtTags of a whole DCZID_EL0 block, set from the tag in Xt
DC GZVA, XtZeroes the block’s data and sets its tags: the tagging form of DC ZVA

The Xt versus Xn distinction in STG matters. stg x0, [x0] (the common form) colours the granule with the pointer’s own tag. stg x1, [x0] colours the granule that x0 points to with x1’s tag, which is how a free routine retags memory to a “poison” colour through the old pointer.

Tag loads

InstructionReads
LDG Xt, [Xn|SP{, #simm}]Puts the allocation tag of the addressed granule into Xt[59:56] and leaves the other bits of Xt unchanged. ldg x0, [x0] therefore “re-colours” an untagged pointer correctly

Bulk forms (EL1 and above only)

STGM Xt, [Xn], STZGM Xt, [Xn] and LDGM Xt, [Xn] move the tags of a whole block of granules to or from a register in packed 4-bit form. The block size is 4 << GMID_EL1.BS bytes, and GMID_EL1 exists for exactly this. These forms are UNDEFINED at EL0 and are the kernel’s tool for clearing, saving and restoring a page’s tags (swap, migration, hibernation). Linux’s mte_clear_page_tags is simply:

    mrs     x1, gmid_el1
    ubfx    x1, x1, #0, #4
    mov     x2, #4
    lsl     x1, x2, x1          // bytes per STGM
1:  stgm    xzr, [x0]           // tag := 0 for the whole block
    add     x0, x0, x1
    tst     x0, #(PAGE_SIZE - 1)
    b.ne    1b

An allocator tagging a fresh 64-byte object looks like this:

    irg     x0, x0              // random tag, honouring GCR_EL1.Exclude
    mov     x1, x0
    add     x2, x0, #64
1:  st2g    x1, [x1], #32       // colour two granules, post-increment
    cmp     x1, x2
    b.ne    1b                  // x0 = tagged pointer returned to the caller

All tag stores are not checked. Writing tags is a privileged operation for the allocator (controlled by ATA), not an access to the data itself.

Tag cache maintenance

Because tags can be cached, possibly in different structures from the data, MTE2 adds tag variants of the data cache maintenance operations (8.5). The naming pattern is G for “tags only” and GD for “tags and data”:

OperationEffectPoint
DC CGVAC / DC CGDVACClean tags / tags and dataPoC
DC CIGVAC / DC CIGDVACClean and invalidate tags / tags and dataPoC
DC IGVAC / DC IGDVACInvalidate tags / tags and data (EL1 and above)PoC
DC CGVAP / DC CGDVAPClean to the Point of PersistencePoP
DC CGVADP / DC CGDVADPClean to the Point of Deep PersistencePoDP
DC IGSW, IGDSW, CGSW, CGDSW, CIGSW, CIGDSWSet/way forms, local only—

A data-only operation (DC CIVAC) is not required to maintain the allocation tags. Code that hands Tagged memory to an observer that bypasses the PE’s caches must therefore use the GD form. Examples are a non-coherent agent that copies pages with their tags, a memory-controller tag scrubber, or a power-down path that turns caches off (8.8). The set/way variants share every set/way caveat from 8.5. They exist for power-down and boot, not for coherency.

Bring-up note: DC GZVA is gated by the same DCZID_EL0.DZP bit as DC ZVA (prohibited when DZP = 1). Linux falls back to STZ2G loops in that case. Firmware that zeroes Tagged memory with DC ZVA leaves its old tags in place. The first reuse of that memory with a new tag then faults if the old tags were non-zero.

Checkpoint

Q13.4.1 x0 holds a pointer with logical tag 0x5, and x1 holds the same address with logical tag 0xA. After stg x1, [x0], what is the allocation tag of the granule?

  • A. 0x5, because the address register’s tag is stored
  • B. 0xA, because STG stores the logical tag of the data register Xt at the address in Xn
  • C. 0x5 ⊕ 0xA
  • D. Unchanged, because STG is checked and the tags of x0 and the granule may not match
Answer

B. STG Xt, [Xn] takes the tag from Xt and the address from Xn. This is what lets a free routine re-colour memory through the old pointer. A describes STGP, which takes the tag from the address register. D is wrong because tag stores are not tag-checked.

Read more: Arm ARM (DDI0487), STG; Allocation Tag access

Q13.4.2 An EL1 driver hands a 4 KB Tagged page to a non-coherent DMA engine that copies pages including their allocation tags through the memory controller’s tag interface. Which maintenance before starting the DMA is sufficient?

  • A. DC CVAC over the page, then DSB SY
  • B. DC CGVAC over the page, then DSB SY
  • C. DC CIVAC over the page; tags are always written back with their data line
  • D. DC CGDVAC over the page, then DSB SY, so that both the dirty data and the dirty tags reach the PoC before the DMA reads them
Answer

D. The engine reads both data and tags from beyond the caches, so both must be clean to the PoC. CGDVAC covers both, and the DSB ensures completion. A and C are data-only operations, and the architecture does not require them to maintain tags; whether tags share a line with data is IMPLEMENTATION DEFINED. B cleans only the tags, so dirty data stays in the cache.

Read more: Arm ARM (DDI0487), DC CGDVAC; Memory Tagging Extension, cache maintenance

Q13.4.3 On a core reporting ID_AA64PFR1_EL1.MTE = 0b0001, a user program executes irg x0, x0; stg x0, [x0]; ldr x1, [x0] on a mapping with MAIR attribute 0xF0. What is observed?

  • A. IRG is UNDEFINED
  • B. The LDR takes a tag check fault on the first mismatch
  • C. All three execute. The STG stores no tag, and the LDR is not checked, because FEAT_MTE without MTE2 has no tag storage or checking
  • D. STG takes a permission fault because tag storage is not mapped
Answer

C. FEAT_MTE alone is the instructions-only level: the EL0 tag instructions execute, but allocation tags are not stored and accesses are not checked, so tagged binaries run unprotected but without faults. Checking (B) needs FEAT_MTE2 together with the enables described in 13.5 and 13.6.

Read more: Arm ARM (DDI0487), ID_AA64PFR1_EL1.MTE; FEAT_MTE and FEAT_MTE2

13.5 MTE tag checking

Storing tags (13.4) does nothing by itself. Protection comes from tag checking: on a checked load or store, the PE compares the pointer’s logical tag with the allocation tag of every granule the access touches. This section covers which accesses are checked, the three reporting modes, how random tags are generated, and the escape hatch PSTATE.TCO.

Is this access checked?

An access is Tag Checked only if every condition below holds. This is the order in which to debug “why didn’t it fault?”:

  1. FEAT_MTE2 or higher is implemented, and allocation tag access is enabled for the EL: SCR_EL3.ATA, HCR_EL2.ATA where applicable, and SCTLR_ELx.ATA/ATA0 (13.6).
  2. The memory’s final attribute is Tagged Normal (MAIR 0xF0, not withdrawn by stage 2).
  3. TBI applies to the address (13.3). The MTE4 MTX controls relax this.
  4. The tag check fault mode for the EL is not NONE: SCTLR_ELx.TCF, or SCTLR_EL1.TCF0 for EL0 and for unprivileged LDTR/STTR at EL1.
  5. PSTATE.TCO = 0.
  6. The logical tag is not a match-all value under TCMA0/TCMA1.
  7. The instruction form is a checked form. Loads and stores whose base register is SP with an immediate offset (or none) are Unchecked, because the compiler is assumed to be accessing its own frame safely. PC-relative literal loads, instruction fetches, translation table walks and the tag instructions themselves are also unchecked.

The SP rule is the one that surprises people. A stack buffer overflow through x0 = sp + 16 is checked, but str x1, [sp, #16] is not. This is how compilers keep tagged stack slots cheap.

Fault modes: TCF and TCF0

FieldBitsControls
SCTLR_EL1.TCF[41:40]Accesses at EL1
SCTLR_EL1.TCF0[39:38]Accesses at EL0
SCTLR_EL2.TCF / SCTLR_EL3.TCF—EL2 and EL3 respectively (with E2H = 1, SCTLR_EL2.TCF0 covers EL0 of the EL2&0 regime)
ValueModeOn mismatch
0b00NONENothing; not checked
0b01SynchronousSynchronous Data Abort, precise, access not performed
0b10AsynchronousThe access is performed, and a flag is set in TFSR_ELx/TFSRE0_EL1
0b11Asymmetric (FEAT_MTE3)Reads synchronous, writes asynchronous

Synchronous

A synchronous tag check fault is a Data Abort (EC 0x24 from a lower EL, or 0x25 from the current EL) with DFSC = 0b010001 (0x11), “Synchronous Tag Check Fault”. It is taken before the access has any architectural effect, ELR_ELx points at the faulting instruction, and FAR_ELx holds the faulting address. That address includes the logical tag in [59:56], while bits [63:60] are UNKNOWN without FEAT_MTE_TAGGED_FAR (13.3). For a multi-granule access (an LDP crossing granules, a SIMD load), take the exact rule for which address within the access FAR reports from DDI0487 rather than assuming it is the first byte. Linux delivers SIGSEGV/SEGV_MTESERR, and KASAN HW_TAGS prints a report with the allocation and free stacks.

Synchronous mode is precise and debuggable but costs the most, because the load cannot retire until the tag compare is resolved.

Asynchronous

In asynchronous mode the faulting access completes: a store has written memory and a load has returned data. The PE then sets a sticky bit:

RegisterRecords faults from
TFSRE0_EL1EL0 accesses
TFSR_EL1EL1 accesses
TFSR_EL2, TFSR_EL3EL2 and EL3 accesses

Each register has TF0 [0] and TF1 [1]. TF0 is set for an address with bit 55 = 0 (the TTBR0 range) and TF1 for bit 55 = 1. No address, no PC and no exception are recorded. Software must poll the register, so detection is coarse-grained: “something in this task, since the last check”.

Asynchronous faults reach TFSR with no defined latency, so software must synchronise before reading:

  • With SCTLR_ELx.ITFSB [37] = 1, exception entry to ELx implicitly synchronises outstanding asynchronous faults into TFSR_ELx/TFSRE0_EL1. Linux sets this, and its kernel entry path can therefore read TFSRE0_EL1.TF0 directly (check_mte_async_tcf in entry.S) and raise SIGSEGV/SEGV_MTEAERR on the next return to the task.
  • Without an exception, a DSB is required. Before reading TFSR_EL1 on the way out of the kernel, Linux does dsb(nsh); isb();. Before clearing TFSRE0_EL1 when a task execs a new image (mte_thread_init_user), it does dsb ish.
    // kernel exit: catch async faults from this kernel section
    dsb     nsh                     // make prior async tag faults visible in TFSR_EL1
    isb
    mrs     x0, tfsr_el1
    tbnz    x0, #1, report_kasan    // TF1: fault on a TTBR1 (kernel) address

The asynchronous mode is cheap, with a cost close to running MTE off on most microarchitectures, which is why it is Linux’s default per-CPU preferred mode. Its security value is detection after the fact: the corrupting store has already landed.

Asymmetric (MTE3)

Asymmetric mode makes loads synchronous and stores asynchronous. Its rationale is that tag-mismatched reads are the information-disclosure path and are cheap to check precisely, while stores are where synchronous checking hurts the store buffer. ID_AA64PFR1_EL1.MTE = 0b0011 indicates support. Linux’s per-CPU mte_tcf_preferred sysfs knob accepts asymm. A task’s prctl may request several modes at once, and the kernel then picks the CPU’s preferred mode among them.

Bring-up note: Async faults from EL3 or a secure partition land in TFSR_EL3 or TFSR_EL1 and are never examined by anyone unless the firmware is written to check. Enabling TCF = async in firmware without a polling point gives you the cost and none of the benefit. Conversely, Normal-world TFSR_EL1 and TFSRE0_EL1 contents are per-world state that EL3 must context-switch if both worlds use MTE.

Generating tags: GCR_EL1 and RGSR_EL1

IRG is the only random-tag source, and it is controlled by two registers:

RegisterFieldMeaning
GCR_EL1Exclude [15:0]Bitmap of tags IRG (and ADDG/SUBG) must not produce
RRND [16]0: use the architected pseudo-random generator seeded by RGSR_EL1. 1: use an IMPLEMENTATION DEFINED random source
RGSR_EL1SEED [23:8]Generator state
TAG [3:0]Last tag generated

GCR_EL1 is used for IRG at both EL1 and EL0, but the kernel and user space want different exclusion sets. When KASAN HW_TAGS is enabled, Linux therefore rewrites GCR_EL1 on every kernel entry (mte_set_kernel_gcr) and on return to user (mte_set_user_gcr, which takes the task’s include mask from prctl(PR_SET_TAGGED_ADDR_CTRL)). Without KASAN it simply loads the task’s user value on context switch. RRND = 1 in both cases. The kernel’s exclusion keeps 0xF (its match-all tag under TCMA1) out of the random set.

RGSR_EL1 is UNKNOWN out of reset. Linux seeds it from CNTVCT_EL0 and forces a non-zero seed, because an implementation may treat RRND = 1 like RRND = 0, and a zero seed would make IRG return a constant. If Exclude excludes every tag, IRG returns tag 0.

Security note: An LFSR seeded from a counter is not a CSPRNG, and 4 bits are 4 bits: a blind guess succeeds with probability 1/15 or 1/16. MTE’s random tagging is a probabilistic defence that is strong against bugs and fuzzers but weaker against a patient attacker who can retry. Deterministic schemes, such as alternating odd and even tags for adjacent allocations, give guaranteed detection of linear overflows into the neighbour, which is why allocators combine both (13.6).

PSTATE.TCO

PSTATE.TCO (Tag Check Override, FEAT_MTE) disables tag checking for all accesses at the current EL while leaving tag access and the instructions working. It is written with MSR TCO, #imm and read with MRS Xt, TCO, and it is saved in SPSR_ELx (2.4).

Two behaviours matter:

  • Exception entry sets PSTATE.TCO to 1. A handler therefore starts with checking off until it explicitly clears TCO. Linux re-enables checking early in C entry (mte_disable_tco_entry) only if the kernel or the task uses checking, because toggling TCO is expensive on some microarchitectures.
  • Typical users of TCO are code that legitimately touches memory with a “wrong” tag: Linux’s uaccess_enable() path (exclusives on user memory execute at EL1 and would otherwise be checked against TCF rather than TCF0), load_unaligned_zeropad, stack unwinders, and allocators walking metadata.
    msr     tco, #1          // suspend checks
    ldr     x1, [x0]         // may cross into a differently-coloured granule
    msr     tco, #0          // resume

TCO is a context-local override and needs no barrier: an MSR immediate to PSTATE takes effect for following instructions in program order.

Checkpoint

Q13.5.1 A user program has TCF0 = async. An out-of-bounds store with a mismatched tag executes, then the program issues a write() system call. On the SVC entry, Linux reads TFSRE0_EL1 without a DSB first. Why is that sufficient?

  • A. SCTLR_EL1.ITFSB = 1, so taking the exception implicitly synchronises pending asynchronous tag check faults into TFSRE0_EL1
  • B. Asynchronous faults are written to TFSRE0_EL1 before the faulting store retires
  • C. SVC is a DSB-equivalent for all memory effects
  • D. It is not sufficient; Linux misses the fault until the next context switch
Answer

A. ITFSB makes exception entry a synchronisation point for asynchronous tag check faults. Without it, a DSB would be needed, which is what Linux does on kernel exit. B is wrong because asynchronous recording has no defined latency, which is the whole reason synchronisation exists. C is wrong because an exception entry is a context synchronization event, not a DSB.

Read more: Arm ARM (DDI0487), SCTLR_EL1.ITFSB; TFSRE0_EL1

Q13.5.2 With TCF = sync at EL1, Tagged memory, TBI1 = 1 and TCMA1 = 0, which of these kernel accesses can take a synchronous tag check fault?

  • A. ldr x1, [sp, #32], where the stack slot has a different tag from SP
  • B. An instruction fetch from a Tagged page
  • C. ldr x1, [x2, #32], where x2 = sp with a different logical tag from the granule at sp + 32
  • D. stg x2, [x3], where the tags of x3 and the granule differ
Answer

C. Only C is a checked access. A uses SP as the base with an immediate offset, which is architecturally Unchecked even though the value is the same as in C. B is an instruction fetch, which is never tag-checked. D is a tag store, which writes the allocation tag and is not checked.

Read more: Arm ARM (DDI0487), Tag Checked and Unchecked accesses

Q13.5.3 A secure partition enables MTE with TCF = sync, but its IRQ handler never faults on an obvious use-after-free, while the same bug faults in thread context. What is the most likely explanation?

  • A. Asynchronous faults are always used in exception handlers
  • B. Exception entry set PSTATE.TCO = 1, and the handler never cleared it, so its accesses are not checked
  • C. GCR_EL1.Exclude differs between handler and thread
  • D. SPSR_EL1.TCO must be set to 0 before the handler runs
Answer

B. Taking an exception sets PSTATE.TCO, which suppresses checking until software clears it with MSR TCO, #0. A is wrong because the TCF mode does not change on exception entry. C affects only which tags IRG generates. D confuses the saved state of the interrupted context (restored on ERET) with the handler’s current PSTATE.

Read more: Arm ARM (DDI0487), PSTATE.TCO; exception entry

13.6 MTE in a system

MTE is not only a CPU feature. Tags need physical storage that a memory controller manages, firmware has to reserve and protect that storage, hypervisors have to decide what guests may tag, and devices that write memory know nothing about tags. This section covers what each layer of the platform must do, the 2022 MTE extensions, how Linux uses MTE, where MTE’s guarantees end, and how to validate it before silicon.

The enable chain: SCR_EL3.ATA and HCR_EL2.ATA

Allocation tag access is gated top-down, in the pattern described in 17.3:

ControlWhen 0
SCR_EL3.ATA [26]Allocation tag access is disabled at EL2, EL1 and EL0. MSR/MRS of GCR_EL1, RGSR_EL1, TFSR_EL1, TFSR_EL2 and TFSRE0_EL1 from those ELs traps to EL3 (EC 0x18)
HCR_EL2.ATA [56]The same for EL1 and EL0, trapping to EL2
SCTLR_ELx.ATA/ATA0Tag access disabled for that EL, with no trap (13.4)

HCR_EL2.DCT [57] covers the case where HCR_EL2.DC = 1 forces a guest’s stage 1 to Normal Write-Back while its MMU is off: DCT makes that default attribute Tagged.

TF-A sets SCR_EL3.ATA in both the Secure and Non-secure contexts whenever FEAT_MTE2 is present (context_mgmt.c), and ENABLE_FEAT_MTE2 makes it context-switch the MTE system registers. If both worlds use MTE, the per-world GCR_EL1, RGSR_EL1, TFSR_EL1 and TFSRE0_EL1 must be saved and restored on every world switch, exactly as for any other EL1 state. A missing SCR_EL3.ATA typically shows up as Linux dying in mte_cpu_setup() on the GCR_EL1 write, with BL31 reporting an unhandled EC 0x18.

Tag storage: carve-outs and the memory controller

The architecture says only that each Tagged granule has an allocation tag. It says nothing about where the tag lives. In real systems:

  • The memory controller (or the interconnect’s home node) implements tag storage, usually as a dedicated region of DRAM holding 4 bits per 16 bytes, 1/32 of the covered range. On each Tagged access it fetches or updates the tag alongside the data, and it may cache tags. The PA-to-tag-address mapping, the tag cache and the tag error-handling behaviour are all IMPLEMENTATION DEFINED.
  • Firmware reserves the carve-out, normally in the stage that trains DRAM (TF-A BL2 or a platform-specific DDR initialisation). It programs the memory controller’s tag-region base and size registers, and it removes the carve-out from the memory map it hands on (the device tree /memory and /reserved-memory, or the UEFI memory map). Some products make this a boot-time choice: the bootloader reserves tag storage only when MTE is requested, which is why some phones need a reboot to turn MTE on.
  • The OS has no standard way to learn which ranges are taggable. Linux assumes that if every CPU supports MTE then all memory that it maps as Normal is taggable. A Linux RFC (2023–2024) proposed a device-tree description of tag storage so that the kernel could reuse unused tag memory for data. It was not merged. Consequently, firmware must not report DRAM that lacks tag storage as ordinary memory on an MTE-enabled system. What a Tagged access to tag-less memory does is IMPLEMENTATION DEFINED, and on some systems it can be an external abort.

Security note: The tag carve-out is a security asset. If the Normal world can write it through a PA alias or a DMA master, it can recolour Secure or Realm memory, which defeats MTE in that world. If it can read it, it learns another world’s tags. The carve-out must be covered by the same TZASC or GPT protection as the memory it describes (12.1, 12.4), and it should not be reachable by ordinary PA accesses at all.

Stage 2: what a guest may tag

A guest’s Tagged stage 1 mapping yields Tagged memory only if stage 2 allows it. Stage 2 must not degrade the memory below Normal Inner and Outer Write-Back, and DDI0487’s attribute-combining rules decide the final result (11.3, including the FEAT_S2FWB encodings). If stage 2 makes the page Non-cacheable or Device, the guest’s tags silently vanish: tag reads return zero, and nothing is checked.

Before FEAT_MTE_PERM, a hypervisor had no way to allow Normal WB access to a page while denying tag access to it. That matters because the hypervisor must be able to back the tags, by saving them on swap and copying them on migration. KVM therefore requires a VMM to opt in (KVM_CAP_ARM_MTE), and it refuses to map memory into an MTE guest unless the host VMA is VM_MTE_ALLOWED, which means anonymous or shmem memory. File-backed and device-backed memory is excluded.

FEAT_MTE_PERM (ID_AA64PFR2_EL1.MTEPERM [3:0]) adds a stage 2 NoTagAccess attribute. Linux’s stage 2 AT emulation treats MemAttr[3] in the FWB encoding as selecting the NoTagAccess variants; take the exact encodings, including the non-FWB case, from DDI0487. A guest access to the allocation tags of such a page (LDG/STG, or a checked access) takes a stage 2 permission fault to EL2, with ISS2.TagAccess (bit 9 of ISS2) set. The hypervisor can then allow ordinary data access to memory it cannot tag and either emulate or refuse the tag access.

Devices, DMA and the SMMU

DMA masters do not perform tag checks. In general they also cannot write tags, unless the device and the memory system implement a tag-aware path, which is rare and IMPLEMENTATION DEFINED. Three consequences follow:

  1. A device write into Tagged memory is never checked. A buggy or malicious device, or a driver that hands the device a stale buffer, corrupts memory without detection, whatever TCF says. The SMMU (11.5) still provides the address protection; MTE adds nothing on the device side.
  2. A device write leaves the allocation tags unchanged, or, on some memory systems, sets them to a defined value. CPU code reading the buffer afterwards must use a pointer whose tag matches whatever tags are there. Kernels usually avoid the issue by mapping DMA buffers untagged, or by accessing them with match-all pointers (TCMA1).
  3. Non-coherent DMA of Tagged memory follows 8.7, and it needs the tag-and-data maintenance forms if anything beyond the PE consumes the tags (13.4).

The 2022 MTE extensions (FEAT_MTE4 and friends)

Arm added a group of MTE extensions in 2022 (the v8.9/v9.4 wave; see DDI0487 A2 for exactly which are mandatory with FEAT_MTE4). They are discovered individually:

FeatureDiscoveryWhat it does
FEAT_MTE_CANONICAL_TAGSID_AA64PFR1_EL1.MTEXWith TCR_ELx.MTX0/MTX1 [60]/[61] set (a single MTX bit in the one-range TCR_EL2/TCR_EL3), memory that is not Tagged is treated as canonically tagged: an access to it with a non-canonical logical tag (not 0b0000 for bit 55 = 0, not 0b1111 for bit 55 = 1) is a tag check fault. This catches a tagged heap pointer straying into untagged memory
FEAT_MTE_NO_ADDRESS_TAGSID_AA64PFR1_EL1.MTEXMakes tag checking under MTX independent of TBI, so a regime can use MTE without making the whole top byte ignored (13.3)
FEAT_MTE_STORE_ONLYID_AA64PFR2_EL1.MTESTOREONLY [7:4]SCTLR_ELx.TCSO [59] / TCSO0 [58]: check only stores. This is cheaper and keeps write-corruption detection. Linux exposes it as PR_MTE_STORE_ONLY
FEAT_MTE_TAGGED_FARID_AA64PFR2_EL1.MTEFAR [11:8]FAR[63:60] valid on a synchronous tag check fault (13.3)
FEAT_MTE_PERMID_AA64PFR2_EL1.MTEPERM [3:0]Stage 2 NoTagAccess (above)

Linux integration in brief

  • User space. mmap/mprotect with PROT_MTE (anonymous and shmem only) selects the Tagged MAIR index. prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC | (incl_mask << PR_MTE_TAG_SHIFT)) selects the modes and the tag include set, which the kernel turns into GCR_EL1.Exclude on return to user. Page tags are zeroed lazily the first time a page is mapped PROT_MTE (PG_mte_tagged), saved on swap-out, and copied on CoW and migration. Allocators that use it include Scudo (Android) and glibc (GLIBC_TUNABLES=glibc.mem.tagging=1). The selftests are in tools/testing/selftests/arm64/mte/.
  • Kernel. KASAN HW_TAGS (kasan=on kasan.mode=sync|async|asymm) tags slab and page allocations with random top-byte tags from 0xF0 upward, uses 0xFE for freed memory, and uses 0xFF for native pointers, which stay valid because of TCMA1. In async mode it checks TFSR_EL1 on kernel exit (13.5).

Security limits

  • 4 bits. A random guess matches with probability 1/16, or 1/15 with one tag excluded. An attacker who can retry, or who can crash a worker process without consequence, will eventually win. Deterministic colouring (adjacent allocations always differ) guarantees detection of linear overflow into the neighbour but not of arbitrary writes.
  • Granularity. Tags are per 16 bytes, so an overflow within a granule (into allocator padding or into a neighbouring field of the same object) is invisible. Intra-object overflows are invisible as well.
  • Asynchronous mode is detection, not prevention. The corrupting store lands, and the report arrives at the next kernel entry or exit.
  • Unchecked paths. SP-relative accesses, TCO windows, match-all tags, DMA and untagged aliases of the same PA all bypass checking.
  • Speculative tag-check bypass. Tag checks gate architectural access, but a mismatched speculative load can still bring data into the cache, and whether a speculative access faulted can itself leak. The 2024 TikTag work (on Pixel 8 class devices and Linux) and StickyTags showed gadgets that leak tag-check outcomes through cache timing, which let an attacker discover the tags and then make a correctly tagged architectural access. Treat allocation tags as not secret in the speculation threat model, and keep the usual Spectre mitigations in place (14.1, 14.3).

Validation note: validating MTE on pre-silicon.

Model setup. On FVP Base RevC AEM, set -C cluster0.memory_tagging_support_level=2 (or 3 for MTE3), mirror it for every cluster, and set -C bp.dram_metadata.is_enabled=1. Without the last parameter the model has no tag storage, and it does not warn about it. The MTE ID fields still look right, so tests pass or fail for the wrong reason. Build TF-A with ENABLE_FEAT_MTE2=1. On QEMU, -M virt,mte=on -cpu max (TCG) models tag memory as a separate address space.

Directed tests (18.5):

  1. STG and LDG round trip through two VA aliases of one PA, which shows the tag follows the PA.
  2. A negative test: a deliberate mismatch must produce EC 0x25 with DFSC 0x11 and FAR[59:56] equal to the pointer tag.
  3. Async: a mismatch sets TFSR_EL1.TF1, and is visible after DSB or after exception entry with ITFSB.
  4. TCMA1 match-all, the SP-relative unchecked rule, and PSTATE.TCO being set on exception entry.
  5. IRG never returns an excluded tag over many iterations, and a non-zero RGSR_EL1.SEED gives a non-constant sequence.
  6. Tag coherency: PE0 does STG, then a release; PE1 does an acquire, then a checked load, which must see the new tag (7.10).
  7. Tags survive DC CIGDVAC, the caches-off transition, and a cluster power-down with retention.
  8. DMA into Tagged memory leaves the tags as the SoC specification promises.

Confirming that checks really ran. The PMU common events MEM_ACCESS_CHECKED (0x4024), MEM_ACCESS_CHECKED_RD (0x4025) and MEM_ACCESS_CHECKED_WR (0x4026) count tag-checked accesses. If they read zero during a “passing” run, nothing was checked, typically because of ATA, TCF, TBI, MAIR or the model parameter.

Silicon-level. In emulation or RTL, inspect the memory controller’s tag region through a backdoor to confirm the PA-to-tag mapping, and inject tag-storage ECC errors to check the RAS reporting path (16.8). Finally, run the Linux MTE kselftests under the real firmware, which exercises SCR_EL3.ATA and the context switching end to end.

Checkpoint

Q13.6.1 On an FVP with MTE2 and DRAM metadata enabled, a directed test colours a buffer with STG and reads the tags back correctly with LDG. Yet a deliberately mismatched load never faults, with TCF = sync, and MEM_ACCESS_CHECKED stays at zero. The test code sets sp to the buffer’s (tagged) address and loads with ldr x1, [sp, #48]. What is the cause?

  • A. bp.dram_metadata.is_enabled is not set, so no tags are stored
  • B. SCR_EL3.ATA = 0
  • C. Loads that use SP as the base register with an immediate offset are architecturally Unchecked, so no check runs
  • D. The MAIR attribute is not Tagged Normal (0xF0)
Answer

C. The correct LDG read-back proves that tag storage exists (ruling out A), that allocation tag access is enabled (ruling out B, because with ATA disabled LDG reads zero), and that the memory is Tagged (ruling out D, because tags of untagged memory read as zero). What remains is a reason why the load is not checked, and the zero PMU count confirms it was not. The SP-relative immediate form is Unchecked by definition.

Read more: Arm ARM (DDI0487), Tag Checked and Unchecked accesses; PMU common event MEM_ACCESS_CHECKED

Q13.6.2 A hypervisor wants to give a guest Normal Write-Back access to a region of memory that the host cannot back with tag storage, while preventing the guest from relying on tags there. Which mechanism does this architecturally?

  • A. Clear HCR_EL2.ATA for the guest
  • B. FEAT_MTE_PERM: map the region with the stage 2 NoTagAccess attribute, so guest tag accesses there take a stage 2 permission fault to EL2
  • C. Map the region at stage 2 as Normal Non-cacheable
  • D. Set TCR_EL1.TCMA0 on the guest’s behalf
Answer

B. NoTagAccess is a per-page stage 2 control that leaves data access as Normal WB. A turns off tag access for the whole guest. C changes the data memory type and can create attribute mismatches with the guest’s mappings. D is guest-controlled state and only affects match-all tags.

Read more: Arm ARM (DDI0487), FEAT_MTE_PERM; stage 2 memory attributes; ESR_ELx ISS2.TagAccess

Q13.6.3 Linux runs with MTE in sync mode for a user process. A peripheral, via the SMMU, writes past the end of a DMA buffer into a neighbouring Tagged object. What does MTE detect?

  • A. Nothing at the time of the write, because device accesses are not tag-checked. Only the SMMU’s address permissions limit the device
  • B. A synchronous tag check fault reported to the process
  • C. An asynchronous fault recorded in TFSRE0_EL1
  • D. An SMMU event, because the SMMU checks the stream’s tags
Answer

A. Tag checking is performed by the PE for its own checked accesses. DMA masters, including those behind an SMMU, do not check tags, and SMMUv3 has no MTE checking. A later CPU access to the corrupted object may still fault if the device changed the tags, but the overflow itself is not caught. B and C would require a PE access.

Read more: Arm ARM (DDI0487), Memory Tagging Extension; SMMUv3 (IHI0070)

Part 14: Speculation and side channels

Prerequisites: 6.1 A hardware mental model (non-architectural), 6.2 Normal and Device memory, 7.4 Dependencies, 7.8 Context synchronization and ISB, 3.1 Exception types and the vector table, 9.1 TLBs and TLB maintenance, 1.3 Implementations and errata. If you already know: the Spectre and Meltdown variants and the Linux or TF-A mitigations for them, skim 14.1, 14.3 and 14.6. Read 14.2 (speculation as a bring-up hazard), 14.4 (the BHB ladder and TF-A’s vector wiring) and 14.7 (SPECRES on a world switch) anyway, and do the 14.8 exercises. Why this matters for bring-up/validation: speculative and prefetch accesses are real transactions that cause SErrors and hangs no instruction explains, and every EL3 vector and SMC handler you ship must carry the right per-core mitigation, which you can only verify by reading ID registers, MIDR and errata notices together.

The architecture says very little about speculation. It permits speculative reads and cache allocation for Normal memory, it forbids speculative data accesses to Device memory and speculative writes that other observers can see, and since 2018 it adds a small set of feature-advertised restrictions (CSV2, CSV3, SSBS, ECBHB) and speculation barriers (CSDB, SB, SSBB/PSSBB, CLRBHB, the SPECRES instructions). Everything else is microarchitecture. 14.1 draws that line precisely and maps each predictor structure to the variant that abuses it. 14.2 turns to what speculation does to the memory system: the cache side channel, but also stray speculative fetches and prefetches into PA holes, untrained DRAM and Secure carve-outs, the speculative-AT errata behind TF-A’s and KVM’s unusual SCTLR_EL1/TCR_EL1 handling, and the places where TF-A puts speculation barriers.

14.3 to 14.6 take the variants one at a time, each with its architectural feature, its software fallback and the firmware interface: Spectre v1 with CSDB, SB and masking; v2 and BHB with CSV2, ECBHB, CLRBHB, the k-iteration loop and SMCCC_ARCH_WORKAROUND_1/3; v4 with SSBS and SMCCC_ARCH_WORKAROUND_2; and the Meltdown class with CSV3, E0PD and KPTI. 14.7 covers prediction isolation across a world switch: SCXTNUM_ELx, the FEAT_SPECRES prediction-restriction instructions, and how to read which mitigations a core needs. 14.8 is the audit exercise, applied to an EL3 vector, an SMC handler and short gadget snippets.

14.1 How speculation is modelled and what it attacks

Every speculation side channel has the same three ingredients:

  1. a predictor that a less-privileged or different context can train;
  2. a transient window, in which the PE executes instructions it will later squash;
  3. a covert channel, which is microarchitectural state that the squash does not roll back and that the attacker can measure. In practice this is almost always cache residency.

The architecture describes none of the hardware involved. Predictors, reorder buffers and line-fill buffers are not in DDI0487. What the Arm ARM does define is a set of permissions and, since 2018, a short list of restrictions and barriers. This section separates the two and maps each predictor to the variant that abuses it. The hardware picture is in 6.1. Read that first if “post-commit store buffer” or “squash” are not yet concrete for you.

What the architecture says about speculation

The memory model (7.1) is defined over architecturally executed instructions, the ones that would run in a simple sequential execution of the program. Speculative execution is everything else: instructions that the PE starts and then discards. The architecture constrains speculation in a few places only.

RuleStatusWhere it matters
Reads of Normal memory can be made speculatively, at any time, to any location mapped as Normal and readable in the current translation regimePermittedThe whole cache side channel (14.2)
Caches can allocate a line for any Normal Cacheable location at any time, for a speculative access or a prefetchPermittedCovert channel, and the stale-line bugs of 8.7
Translation table walks and TLB allocation can be speculativePermittedSpeculative-AT errata (14.2), break-before-make (9.2)
Speculative data accesses to any Device memory typeNot permittedMMIO safety; instruction fetch is a separate case (6.2)
Speculative writes becoming visible to any other observerNot permittedSquashed stores leave memory unchanged; they can still affect timing (v4)
Instruction fetch from any location that is not execute-neverPermitted, including speculativelyDevice regions must be XN

Everything else about speculation is microarchitecture. In particular, the architecture says nothing about what state a squash restores beyond architectural state. That gap is the attack surface.

After Spectre, Arm added two kinds of architectural text:

  • Restrictions on the effects of speculation. These are feature-gated promises about what speculation will not do, each advertised by an ID register field. Examples are FEAT_CSV2 (branch targets trained in one hardware-described context cannot control speculation in another), FEAT_CSV3 (data loaded speculatively from a location that would fault cannot be used to form a cache-timing channel, see 14.6) and FEAT_SSBS (a controllable store-bypass restriction, 14.5). The Arm ARM collects the general statements under “Restrictions on the effects of speculation” in the AArch64 application-level memory model chapter.
  • Speculation barriers. These are instructions with defined semantics for speculative execution: CSDB (a HINT, so it is a NOP on older cores), SB (FEAT_SB), SSBB and PSSBB (DSB encodings), CLRBHB (FEAT_CLRBHB, a HINT, 14.4), and the prediction-restriction instructions of FEAT_SPECRES. Ordinary barriers have no speculation semantics. A DMB orders observation and says nothing about whether a younger load executes. DSB followed by ISB happens to stop speculation on all known cores, and Arm documents it as the pre-SB fallback. That is guidance, not a property of DSB or ISB.

The practical rule: any mitigation must reduce to an ID-register-advertised restriction, an architectural speculation barrier, or core-specific behaviour documented by the core vendor (a TRM statement, an erratum notice or a Security Center advisory). If it is none of these, it is a guess.

Hardware-described context

The CSV2, CSV3 and SPECRES text depends on the term hardware-described context: roughly the combination of Security state, Exception level, VMID (when EL2 is enabled for that state), ASID (for regimes that use one), and, with FEAT_CSV2_2, the value of SCXTNUM_ELx. The restrictions apply between such contexts. Two consequences follow.

  • The restrictions do not apply within a context. A JavaScript engine and the sandboxed script it runs share one hardware context, so CSV2 does nothing for them. That is what SCXTNUM_ELx is for (14.7).
  • EL3 is its own context. On a CSV2 core, Non-secure EL1 cannot train branch targets that EL3 then uses. On a pre-CSV2 core it can, and EL3 firmware must remove the trained state on entry (14.4).

Predictor structures and the variants that abuse them

The structures below are non-architectural. Their sizes, indexing and tagging vary by core and are rarely documented in full. The mapping from structure to variant is stable across cores, though.

StructureWhat it predictsTypical index and tagVariantCVESection
Conditional (direction) predictorTaken or not taken for B.cond, CBZ, TBZPC bits, often hashed with global historyv1, bounds check bypassCVE-2017-575314.3
Branch target buffer (BTB) and indirect predictorTarget of BR, BLR, and on some cores RETPC bits (VA), partial tag; pre-CSV2 often no context tagv2, branch target injectionCVE-2017-571514.4
Branch history buffer (BHB)Recent taken-branch history used to select an indirect targetGlobal, shared across exception entry on affected coresSpectre-BHB / BHICVE-2022-2396014.4
Return stackTarget of RETPush on BL/BLR, pop on RET; on underflow, some cores fall back to the BTBReturn-stack attacks. Exposure is core-specific; Arm advisories treat it as part of the v2 analysis—14.4
Memory disambiguation (store-to-load forwarding prediction)Whether a load may execute before an older store with an unresolved addressLoad PCv4, speculative store bypassCVE-2018-363914.5
Fault deferral in the load pipelineNot a predictor: a permission or translation fault is raised at commit, not when data returns—v3 (Meltdown), v3a (rogue system register read)CVE-2017-5754, CVE-2018-364014.6
Sequential fetch past unconditional control flowThat RET, BR, ERET, SVC and so on fall through—Straight-line speculation (SLS)CVE-2020-1384414.2

Read the table as a set of questions for a code review:

  • Can the attacker steer a branch direction? (v1)
  • Can the attacker choose a target, either directly or through history? (v2, BHB)
  • Can a load run ahead of a store that should have overwritten its source? (v4)
  • Does a faulting load forward data before the fault is taken? (v3, v3a)

Different questions need different fixes, and a fix for one does nothing for another. CSDB does not touch the BTB, and CLRBHB does not stop store bypass.

The covert channel: why the cache

A transient instruction can only leave measurable traces in shared microarchitectural state. The usual channel is L1D or LLC residency:

/* the transient gadget: two dependent loads */
uint8_t secret = *(volatile uint8_t *)victim_ptr;   /* transient read */
(void)probe[secret * 64];                            /* transient fill of one line */

/* the attacker, afterwards, architecturally */
for (int i = 0; i < 256; i++)
    t[i] = time_load(&probe[i * 64]);                /* the fast one reveals 'secret' */

The first load reads the secret. The second turns it into an address, and the cache fill for that address survives the squash. The attacker then times loads to find which line is now resident:

  • Flush+Reload, when the attacker and victim share memory. On AArch64, EL0 can flush by VA with DC CIVAC when SCTLR_EL1.UCI=1, which Linux sets.
  • Prime+Probe, when they do not. The attacker fills a cache set and watches for evictions.

Other channels exist: TLB state, prefetcher training, port contention and DRAM row buffers. They are slower and noisier, and the mitigations in this part do not depend on which one is used. Taking away the timer does not help either. CNTVCT_EL0 can be trapped or coarsened, but a counting thread on another core works as a timer.

So the gadget a reviewer looks for is a load whose address depends on data obtained speculatively, reachable in a transient window. One load alone leaks nothing through the cache. The data has to reach a second address-forming operation. That is why the masking patterns in 14.3 work: they break the dependency, not the load.

Security note: “Transient” includes the window after a mispredicted exception return path, after an SVC or SMC that the front end did not recognise as a control-flow change, and after an ERET (SLS). EL3 code that does ERET and then has data-dependent loads in the following bytes, for example a literal pool or the next function, has a gadget even though those bytes are never architecturally executed. TF-A follows every ERET with a speculation barrier for this reason (14.2).

How the variants map onto a TEE threat model

For EL3 and S-EL1/S-EL2 firmware, the attacker is normally Non-secure EL1 (a compromised kernel) or EL0 calling through it. The secrets are Secure-world keys and memory.

VariantAttacker trainsVictim runsFirmware role
v1Branch directions, through repeated in-bounds SMC argumentsBounds-checked table lookups in an SMC or TA handlerMask indices in handlers (14.3)
v2 / BHBBTB or BHB from NS-EL1EL3 or S-EL1 indirect branches (handler tables, function pointers)Vector-entry mitigation, SMCCC_ARCH_WORKAROUND_1/3 (14.4)
v4Not a training attack: the bypass happens in the victim’s own codeStore-then-load sequences on attacker-influenced dataSSBS or chicken bits, SMCCC_ARCH_WORKAROUND_2 (14.5)
v3 / v3aNothing: the attacker reads directly—Firmware mostly unaffected; KPTI is an OS problem (14.6)
Cross-world prediction residuePredictors shared across a world switchThe other worldFEAT_SPECRES on context switch (14.7)

Validation note: Mitigations are validated by disabling them and checking that the attack signal appears, then enabling them and checking that it disappears. A test that passes with the mitigation enabled but never showed a signal without it proves nothing. Measure the signal on silicon or cycle-accurate RTL, because FVP and QEMU do not model predictors or cache timing. The PMU gives a lower-noise oracle than raw timing. Count BR_MIS_PRED (0x10) and BR_PRED (0x12) to confirm that training actually happened, INST_SPEC (0x1B) against INST_RETIRED (0x08) to confirm that a transient window opened, and L1D_CACHE_REFILL (0x03) on the probe array to see the fill without timing noise (16.5). Event availability beyond the common set is IMPLEMENTATION DEFINED; check PMCEID0_EL0/PMCEID1_EL0.

Checkpoint

Q14.1.1 A reviewer argues: “This EL3 handler has a bounds-checked load, then DMB ISH, then a second load that uses the first value as an index. The DMB orders the loads, so there is no Spectre v1 gadget.” What is wrong with the argument?

  • A. Nothing. A DMB prevents younger loads from being issued until older loads complete.
  • B. The DMB needs to be a DMB SY. An Inner Shareable barrier does not cover EL3.
  • C. A DMB constrains the order in which architecturally executed accesses are observed. It has no defined effect on whether younger instructions execute speculatively, so both loads can still run in the transient window.
  • D. The argument is right only for Device memory, where the DMB also prevents speculative reads.
Answer

C. Ordinary barriers are defined in terms of observation order between architecturally executed accesses. They carry no speculation semantics. A core can execute the younger load speculatively and later make the outcome appear ordered, while the cache fill survives the squash. Only CSDB, SB, SSBB/PSSBB, CLRBHB and the SPECRES instructions have defined speculation effects, and DSB+ISB is a documented fallback rather than an architectural guarantee. A is the common misconception that DMB stalls issue. D confuses the Device-memory no-speculation rule, which is a property of the memory type, with a property of the barrier.

Read more: Arm ARM (DDI0487), Restrictions on the effects of speculation; Data Memory Barrier (DMB)

Q14.1.2 A core reports ID_AA64PFR0_EL1.CSV2 = 1. A browser JIT at EL0 runs untrusted script and its own trusted runtime in the same process. Is the runtime protected from branch-target injection by the script?

  • A. No. CSV2 restricts branch-target training only between hardware-described contexts, and the script and runtime share EL, Security state, ASID and VMID. Separating them needs SCXTNUM_EL0 with FEAT_CSV2_2, or a software mitigation.
  • B. Yes. CSV2 means the BTB is tagged with the full VA, so aliasing between script and runtime is impossible.
  • C. Yes, as long as the runtime is mapped with PXN.
  • D. No, because CSV2 applies only to EL1 and above.
Answer

A. CSV2 is a restriction between hardware-described contexts. Within one context, branch-target training is still allowed to influence speculation. FEAT_CSV2_2 adds SCXTNUM_ELx to the context, so software can create sub-contexts (14.7). B describes a possible implementation, but the architecture promises nothing about tagging. D is wrong because CSV2 covers EL0 contexts too, distinguished by ASID.

Read more: Arm ARM (DDI0487), ID_AA64PFR0_EL1.CSV2; SCXTNUM_EL0

Q14.1.3 Which code fragment is the minimal cache-channel Spectre gadget, assuming x1 is attacker-controlled and the code runs inside a transient window?

  • A. ldr x2, [x0, x1] alone
  • B. ldr x2, [x0, x1] followed by str x2, [sp]
  • C. ldr x2, [x0, x1] followed by cmp x2, #0
  • D. ldrb w2, [x0, x1] followed by ldr x3, [x4, x2, lsl #6]
Answer

D. The leak needs the speculatively read value to form a second address, so that the line filled by the second load encodes the secret. A brings the secret into a register, but the only line touched is the one at an attacker-chosen address, which the attacker already knows. B’s store never leaves the core speculatively. C can leak through branch timing only if a dependent branch follows, which is a different and weaker channel.

Read more: Arm whitepaper “Cache Speculation Side-channels”; Arm ARM (DDI0487), Restrictions on the effects of speculation

14.2 Speculation and the memory system

Speculation reaches the memory system in two ways. The first is the side channel of 14.1: transient loads change cache state. The second matters more in bring-up. Speculative and prefetch accesses are real transactions on the interconnect. They can hit a PA hole, a DRAM controller that is not trained yet, or a TZASC-protected region. The error responses that come back surface as SErrors or hangs, and no instruction caused them. This section covers both, along with the speculative-walk errata that make TF-A and KVM save SCTLR and TCR in unusual places.

Speculative cache fills

For any location mapped as Normal Cacheable and readable in the current regime, the architecture allows the PE to read it speculatively and allocate it into a cache at any time (6.3). Three consequences follow.

  • Side channel. A transient load leaves a resident line, and a transient dependent load leaves a line whose address encodes data. This is the covert channel used by every variant in this part.
  • Coherency hazards. A line can come back into a cache after you invalidated it, even if no instruction touched it, as long as the VA mapping stays Normal Cacheable. This is why the DMA receive recipe invalidates after the transfer (8.7), and why mismatched aliases are dangerous (6.6).
  • Reach. The PE can only speculate into what the current translation regime maps. A mapping that exists only in another regime, or a PA the tables do not map at all, is unreachable for data speculation. “Not mapped” is the only complete defence against speculative data access. Permission bits do not help on cores that have the Meltdown problem (14.6).

Device memory and the MMU-off defaults

Speculative data accesses to any Device memory type (nGnRnE through GRE) are not permitted. This is architectural, and it is why MMIO is safe as long as it is mapped Device. Two caveats apply.

  1. Instruction fetch is not covered. The PE may speculatively fetch instructions from any location that is not execute-never, Device included. Every Device mapping must therefore be UXN/PXN (or XN in the EL2 and EL3 regimes). A speculative fetch from a read-sensitive register, such as a FIFO or a clear-on-read status register, is a real read with side effects (6.2).
  2. With stage 1 disabled, data and instruction accesses get different defaults (6.5). Data accesses are Device-nGnRnE, so there is no speculative data access at all. Instruction fetches are Normal, with cacheability from SCTLR_ELx.I, and no XN exists to stop them.

How far can MMU-off instruction fetch reach?

The Arm ARM bounds instruction fetch when all associated stages of translation for the regime are disabled (see “Behavior of instruction fetches when all associated stages of translation are disabled”). As quoted in core errata notices (Cortex-A53 843819, Falkor E1041), fetches are limited to the same or the next translation granule (4KB) as an instruction that has been or will be executed. The Arm ARM text also lists a small number of further allowances tied to branch targets on the program’s actual path; read the exact list there rather than relying on this paraphrase. What it does not permit is fetching from an arbitrary PA, for example a stale predicted target left over from MMU-on execution. That rule has two sharp edges:

  • The next 4KB counts. Code that ends near the top of an SRAM, with a PA hole or an unclocked block directly above it, can generate sequential prefetches into that hole. Leave at least a 4KB pad, or place code so that the following granule is backed by real memory.
  • Errata break it. Some cores have published errata where MMU-off fetches escape the window, especially around the transition from SCTLR_ELx.M=1 to 0 or when HCR_EL2.VM is set. Two examples are Linux’s QCOM_FALKOR_ERRATUM_E1041, worked around with an ISB before clearing M, and Cortex-A53 erratum 843819. Treat the 4KB window as the architectural bound and the errata list in the core’s SDEN as the reason not to rely on it (1.3).

Once the MMU is on, the bound is the mapping. Any Normal mapping can be read speculatively, and any Normal mapping that is not XN can be fetched speculatively (9.3).

Prefetchers

Hardware data and instruction prefetchers are IMPLEMENTATION DEFINED. The architecture treats a prefetch as a speculative access, so it is permitted only where speculative reads are permitted: Normal memory that the current regime maps. In practice, prefetchers work on physical addresses and usually stop at a page boundary, because they do not have the next page’s translation. Some cores also cross the boundary using TLB information, so check the TRM. Many cores expose control bits in IMPLEMENTATION DEFINED registers (CPUECTLR_EL1 and similar) to tune or disable prefetching. Interconnects add their own system-level-cache prefetchers.

The architecture also reserves prefetch hints (PRFM, PRFUM). These never fault, and a translation fault on a PRFM is suppressed. On some cores a PRFM to a mapped but broken PA still issues a real transaction, so a stray PRFM in memcpy can reach whatever the mapping allows.

Where the stray transactions go, and how they surface

TargetTypical responseHow it shows up on the PE
Unmapped hole in the interconnect address mapDECERR or SLVERR from a default slaveAsynchronous SError, or a RAS record in the cluster or interconnect (16.7)
DRAM controller before training, or a channel not yet initialisedNo response, or an error response, depending on the controllerCore hang (outstanding transaction never completes), or SError
TZASC or TZC-protected carve-out accessed with NS=1Error response or RAZ/WI, per the TZC ACTION configuration, often with an interruptSError, or silent zeros in the cache that later look like data corruption
RME: a PA whose GPT entry does not allow the access PASGranule protection check, which applies to speculative accesses tooA failing speculative access is not made, and no fault is reported
Powered-down or unclocked IPBus hangCore or cluster hang, often with the debugger unable to halt

How a PE reports an error response to a speculative or prefetch access is IMPLEMENTATION DEFINED. It may discard the response, poison the line, log it in a RAS error record, or raise an SError interrupt. A synchronous External abort is only taken for an access that is architecturally executed. For speculative ones, the common outcome on Arm cores is an SError whose ESR_ELx gives only an IMPLEMENTATION DEFINED or uncategorised syndrome, and whose ELR_ELx points at unrelated code (3.4). The fingerprint is an SError that moves when you add or remove unrelated code, because that changes the predicted paths and the prefetch streams.

Prevention

  1. Map only what exists and is ready. Build the address map from the SoC memory map, not from “1GB blocks covering DRAM”. A hole inside a block mapping is a speculative target.
  2. Holes: no descriptor at all. Marking a hole XN stops instruction fetch but not speculative data reads of a Normal mapping. Marking it Device stops data speculation but still reaches the bus for architectural stray accesses. Invalid descriptors stop both.
  3. MMIO: Device and XN. TF-A’s xlat library applies execute-never to every MT_DEVICE region. Hand-built tables need the same.
  4. DRAM: Normal only after training. Until the DDR PHY and controller are trained, either leave DRAM unmapped or map it Device-nGnRnE for the training code’s own accesses. Switching to Normal Cacheable means a remap with break-before-make (9.2).
  5. Prefetchers: enable last. If the core or interconnect prefetchers are programmable, keep them disabled, or at their conservative reset setting, until every Normal mapping is backed by working memory. This is an IMPLEMENTATION DEFINED step. Find it in the TRM and the SoC integration guide.
  6. Secure carve-outs: not in the NS linear map. Device-tree reserved-memory with no-map keeps Linux from mapping them (6.6). A TZASC that answers NS accesses with RAZ/WI hides the bug instead of reporting it, so prefer an error response during bring-up.

Bring-up note: A multi-chiplet system often has PA windows that point at a remote die whose links are not trained yet. Map remote-die memory only after the link-up handshake (17.5). Otherwise a prefetch or a speculative read of a Normal mapping to the remote window can hang the local interconnect, and the debugger will not tell you why.

Speculative walks and the speculative-AT errata

Translation table walks may be speculative, and a speculative walk may allocate TLB entries (9.1). Architecturally, any such entry must be one that the regime’s configuration could have produced. Several cores violate this during a context switch of the EL1&0 regime done from a higher EL:

CoreErratumTF-A build flag
Cortex-A531530924ERRATA_A53_1530924
Cortex-A551530923ERRATA_A55_1530923
Cortex-A571319537ERRATA_A57_1319537
Cortex-A721319367ERRATA_A72_1319367
Cortex-A761165522ERRATA_A76_1165522

While EL3 or EL2 restores a new world’s SCTLR_EL1, TCR_EL1, TTBRn_EL1 and VTTBR_EL2 one register at a time, a speculative AT or a speculative EL1&0 walk can combine old and new values. It can then allocate a TLB entry, tagged with the new ASID and VMID, that corresponds to neither world. The fix is to make an EL1&0 stage-1 walk impossible while the registers are inconsistent:

  • Set TCR_EL1.EPD0 and EPD1, so a TTBR walk faults instead of reading memory.
  • Keep SCTLR_EL1.M=1, because with M=0 the regime would produce a flat mapping that allocates without any walk.
  • Restore SCTLR_EL1 first and TCR_EL1 last, each followed by an ISB.

TF-A implements this as apply_at_speculative_wa on every lower-EL vector entry and restore_ptw_el1_sys_regs in el3_exit, enabled by ERRATA_SPECULATIVE_AT whenever any of the flags above is set:

// lib/el3_runtime/aarch64/context.S (abridged): on entry to EL3
    mrs   x29, tcr_el1
    str   x29, [sp, #(CTX_ERRATA_SPEC_AT_OFFSET + CTX_ERRATA_SPEC_AT_TCR_EL1)]
    orr   x29, x29, #(TCR_EPD0_BIT | TCR_EPD1_BIT)
    msr   tcr_el1, x29
    isb
    mrs   x29, sctlr_el1
    orr   x29, x29, #SCTLR_M_BIT
    msr   sctlr_el1, x29
    isb
// ... on exit, after all other EL1 registers are restored:
//     isb; msr sctlr_el1, <saved>; isb; msr tcr_el1, <saved>

KVM does the same in nVHE mode under ARM64_WORKAROUND_SPECULATIVE_AT. It writes the guest’s TCR_EL1 with EPD0|EPD1 set until stage 2 is configured, and it restores the host’s SCTLR_EL1, then ISB, then TCR_EL1. It also sets the EPD bits around the guest-VMID TLB invalidation in __tlb_switch_to_guest(). The TF-A build documentation notes that if EL3 enables the workaround, EL2 software must implement it too.

TF-A’s speculation barrier points

LocationBarrierWhy
exception_return macro (every EL3 ERET)SB if ENABLE_FEAT_SB, else DSB NSH; ISBStraight-line speculation past ERET into whatever bytes follow
BHB loop on lower-EL vector entryspeculation_barrier (SB, or DSB SY; ISB) after the loopThe loop must finish overwriting history before any indirect branch (14.4)
Lower-EL vector entries on speculative-AT coresapply_at_speculative_wa (EPD and M with ISB)Prevent inconsistent EL1&0 walks during the world switch
WA1 vectors on Cortex-A57/A72SCTLR_EL3.M toggle with ISBCore-specific BTB invalidation on pre-CSV2 cores (14.4)
Compiled C, when HARDEN_SLS=1-mharden-sls=all: speculation barriers after RET and BR, BLR via thunksSLS in C code, not only in assembly

ENABLE_FEAT_SB defaults to on for platforms built for v8.5 or later, where FEAT_SB is mandatory. On earlier cores the fallback costs a full DSB on every exception return.

Validation note: To validate the “map only what exists” rule, run a directed test with an intentionally bad mapping. Map a 2MB Normal executable block that covers a known PA hole, run a tight loop with a predictable indirect branch near the end of the valid range, and count SErrors (in a RAS record or in ISR_EL1.A) over a long run. Repeat with the hole unmapped. The pass criterion is zero SErrors with the correct map and a non-zero count with the bad one. A zero count on both shows that the test cannot see the problem, not that the core is safe. Look at the interconnect’s error logs and the TZC FAIL_ADDRESS registers, or their equivalents, to confirm which PA was hit. This needs RTL with a realistic interconnect model, or silicon: FVP does not speculate.

Checkpoint

Q14.2.1 BL2 maps all of DRAM as one Normal Cacheable, executable 4GB region before the DDR controller is trained. It then calls the DDR training code, which runs from SRAM. Occasionally the system hangs during training. What is the most plausible mechanism, and the fix?

  • A. The training code’s stack is in DRAM. Move the stack to SRAM.
  • B. Speculative reads, instruction fetches or prefetches to the Normal DRAM mapping reach an untrained controller that never responds. Leave DRAM unmapped (or Device for the training accesses) until training completes, then remap as Normal with break-before-make.
  • C. The DRAM mapping lacks PXN. Setting PXN on it fixes the hang.
  • D. The training code needs a DSB SY after each DRAM register write.
Answer

B. Any Normal mapping is a legitimate target for speculative data reads and prefetches, and any Normal executable mapping is a target for speculative fetch, whether or not code touches it. An untrained controller may not answer, so the outstanding transaction hangs the core. C is the tempting wrong answer: PXN stops instruction fetch but not speculative data reads or prefetch from a Normal mapping. A would fail deterministically, not occasionally.

Read more: Arm ARM (DDI0487), speculative accesses to Normal memory; Memory types and attributes

Q14.2.2 On a core with erratum 1319367, EL3 switches from Secure to Non-secure EL1 state. Why does TF-A restore TCR_EL1 after SCTLR_EL1, with an ISB between them?

  • A. SCTLR_EL1 writes are ignored while TCR_EL1.EPDx is set.
  • B. The architecture requires TCR_EL1 to be written last in any context switch.
  • C. The ISB makes the TLB invalidation complete.
  • D. While TCR_EL1.EPD0/1=1 and SCTLR_EL1.M=1, no EL1&0 stage-1 walk can occur. Restoring TCR_EL1 last, after a context synchronization event makes every other EL1 register take effect, ensures that the first possible speculative walk sees a fully consistent new context.
Answer

D. The workaround keeps EL1&0 stage-1 walks impossible until all other EL1 registers have been restored and synchronized. Re-enabling walks by clearing the EPD bits through the TCR_EL1 write is the last step. M must stay 1 throughout, because M=0 would give a flat mapping that can allocate without a walk. B is wrong because there is no general architectural rule about write order. The order only matters because of the erratum.

Read more: TF-A docs, build options, ERRATA_SPECULATIVE_AT; Arm Cortex-A72 Software Developer Errata Notice, erratum 1319367

Q14.2.3 BL1 runs from ROM at 0x0000_0000–0x0000_FFFF with the MMU off. The address range 0x0001_0000–0x0001_FFFF is a hole that returns DECERR. BL1’s last function, which is executed, ends 64 bytes below 0x0001_0000. Which statement is correct?

  • A. The Arm ARM allows speculative instruction fetch from the next 4KB granule after sequentially fetched code, so a sequential prefetch into the hole is permitted and can produce an SError. Pad the ROM image, or put code elsewhere.
  • B. With the MMU off, instruction fetches are Device-nGnRnE, so no speculative fetch can occur.
  • C. The hole is safe because speculative instruction fetches never cross a 64KB boundary.
  • D. Only a mispredicted branch could reach the hole, and branch prediction is disabled when the MMU is off.
Answer

A. With all stages disabled, instruction fetches are Normal, and fetches may reach the same or the next 4KB granule as an instruction that has been or will be executed. The hole sits in that window. B confuses the data default (Device-nGnRnE) with the instruction default (Normal). D is wrong because branch prediction is not architecturally disabled when the MMU is off, and the sequential case alone is enough.

Read more: Arm ARM (DDI0487), Behavior of instruction fetches when all associated stages of translation are disabled

14.3 Spectre v1 (bounds check bypass)

Spectre v1 (CVE-2017-5753) abuses the conditional branch predictor. The attacker calls the victim many times with an in-bounds index, which trains the bounds check to predict “in range”. Then it passes an out-of-bounds index. The PE predicts the check, runs the protected loads in the transient window, and leaves a cache footprint that encodes data from outside the array. Nothing at the architectural level goes wrong: the branch resolves, the loads are squashed, and the handler returns an error.

/* SMC handler at EL3. x1 (idx) comes from Non-secure EL1. */
if (idx < table_len) {              /* B.HS predicted not taken          */
    uint8_t v = table[idx];         /* transient: reads beyond the table */
    ret = lut[v * 64];              /* transient: fill encodes v          */
}

The architecture does not order these loads behind the branch. A control dependency orders a later store behind the branch’s operands, but it does not order loads (7.4). Even if it did, the memory model only constrains architecturally executed accesses. A fix has to force the protected loads to use a value that is safe even when the branch is mispredicted. There are three tools for this: CSDB with a conditional select, SB, and masking that is safe by construction.

CSDB: Consumption of Speculative Data Barrier

CSDB is HINT #20. It is part of the base architecture from v8.0. Arm defined it retroactively in 2018 and placed it in the hint space so that older cores execute it as a NOP. That is correct for them, because Arm’s guidance is that a conditional select followed by CSDB is enough on every Arm implementation. The guarantee, paraphrasing DDI0487:

No instruction other than a branch, appearing in program order after the CSDB, can be speculatively executed using the results of any data value prediction, or of any PSTATE.{N,Z,C,V} prediction of an instruction other than a conditional branch, where that instruction appears in program order before the CSDB and has not been architecturally resolved.

Three points in that definition are easy to miss.

  1. It is about predicted data and flags, not predicted control flow. CSDB does not stop the PE from speculating down the wrong side of the B.HS. It only stops later instructions from consuming a value that was computed from a predicted flag. A bare CSDB after the branch, with no conditional select, does nothing useful.
  2. The conditional select is what makes it work. CSEL x1, x1, xzr, LO produces a result from the flags. If those flags were predicted instead of computed, the result is the “result of a PSTATE prediction”, and CSDB stops any later instruction from using it until the flags resolve. Once the flags resolve, the CSEL result is correct (zero for an out-of-bounds index) even on the mispredicted path.
  3. Branches are excluded on the consumer side. Later conditional branches can still be predicted. Only data consumption is constrained.

The canonical sequence:

// x0 = table, x1 = idx (untrusted), x2 = table_len
    cmp     x1, x2
    b.hs    1f                    // architectural bounds check
    csel    x1, x1, xzr, lo       // idx if in bounds, else 0: depends on real flags
    csdb                          // nothing after this uses a predicted-flags result
    ldrb    w3, [x0, x1]          // safe: x1 is in bounds or 0 on every path
    ldr     x4, [x5, x3, lsl #6]
1:

Linux uses a branchless mask form, array_index_mask_nospec() in arch/arm64/include/asm/barrier.h:

    cmp     x1, x2                // idx - sz: C = 1 when idx >= sz
    sbc     x6, xzr, xzr          // x6 = 0 - 0 - !C = ~0 if idx < sz, else 0
    csdb
    and     x1, x1, x6            // array_index_nospec(): idx or 0

SBC consumes the carry flag in the same way CSEL does, so the CSDB rule covers it. OP-TEE provides the same pattern as confine_array_index() in lib/libutils/ext/include/confine_array_index.h, using CMP; CSEL ..., LO; HINT #20, and uses it in its SCMI server and drivers on IDs that come from the Normal world.

Clamping to 0 is a convention. Any index that is in bounds works. What matters is that the clamped value is architecturally correct on the good path and harmless on the bad one. Index 0 must not itself be secret, which is normally true for a dispatch table.

SB: Speculation Barrier

SB (FEAT_SB, ID_AA64ISAR1_EL1.SB, bits [39:36]) is permitted from v8.0 and mandatory from v8.5. It is a full stop for speculation. Paraphrasing DDI0487: until the SB completes, no instruction after it in program order can be executed speculatively to the extent that the speculation can be observed through side channels as a result of control-flow or data-value speculation. An SB cannot itself be executed speculatively as a result of control-flow or data-value speculation. It can be executed speculatively on the prediction that an earlier instruction does not take an exception, so it does not replace the fault-deferral defences of 14.6.

CSDBSB
EncodingHINT #20 (NOP if not understood)Dedicated system encoding; UNDEFINED without FEAT_SB
AvailabilityEvery v8.0+ coreFEAT_SB; mandatory from v8.5
StopsUse of predicted data values and predicted flags by later non-branch instructionsAll speculative execution past the barrier
Needs a select or mask in frontYesNo
CostUsually a few cyclesA pipeline drain, but no wait for memory completion
Fallback when absent—DSB SY; ISB (TF-A) or DSB NSH; ISB (Linux). Documented by Arm as working, but not architecturally defined as a speculation barrier

Use SB where masking is impractical:

  • after an ERET or a RET (straight-line speculation, 14.2);
  • after a bounds check that guards a long block with many uses of the index;
  • after an untrusted pointer that is dereferenced in many places;
  • at the end of the BHB loop (14.4).

Use CSEL+CSDB on hot paths, because it costs a few cycles instead of a drain. Code that must run on both v8.0 and v8.5 parts needs to detect the feature at runtime or through build configuration. TF-A’s speculation_barrier macro uses ENABLE_FEAT_SB, and Linux patches the barrier at boot with alternatives.

Masking patterns that need no barrier

Some code is safe by construction. The rule is: if the index or pointer is forced into range by unconditional arithmetic, with no flag involved, no prediction can produce an out-of-range value.

PatternExampleWhy it is safe
Power-of-two table indexed by a bit fieldTF-A’s SMC dispatcher: two ubfx and an orr combine the 6-bit OEN with the call-type bit, giving a 7-bit index into rt_svc_descs_indices[128] (MAX_RT_SVCS)Every value the ubfx can produce is inside the array
AND with size−1table[idx & (N - 1)] for N a power of twoRange forced without flags
Address-space bit clearingLinux __uaccess_mask_ptr(): BIC ptr, ptr, #(1 << 55)A user pointer can never select the TTBR1 (kernel) half, even speculatively
Branchless minCMP + CSEL to the boundNeeds CSDB, because CSEL reads flags

Watch the second stage in the TF-A example. The byte read from rt_svc_descs_indices is checked with tbnz w15, #7, smc_unknown before it scales into the descriptor array, and that check is a branch. Whether a mispredicted tbnz is a gadget depends on what an out-of-range descriptor load can reach and on the fact that the result is used as an indirect branch target. This is exactly the kind of judgement an audit has to make (14.8).

Compiler support

  • Builtins. GCC provides __builtin_speculation_safe_value(val, failval). On AArch64 it lowers to a conditional select plus CSDB when speculation tracking is available, and to a heavier barrier otherwise. Linux and OP-TEE use their own inline assembly, which makes the instruction sequence explicit.
  • Whole-program hardening. Clang’s speculative load hardening (-mspeculative-load-hardening) supports AArch64. It tracks misprediction in a register using CSEL and CSDB, and masks loaded values or addresses. Its cost is high, so firmware rarely uses it.
  • The compiler can undo you. A C-level if (i < n) i &= mask; can be turned back into a branch, or have the mask hoisted. Write the mask in asm volatile, as Linux and OP-TEE do, or use the builtin.

Variant 1.1 and other relatives

Bounds check bypass store (v1.1, CVE-2018-3693) uses the same mispredicted bounds check to guard a store. Speculative stores never leave the core, but the transient store can be forwarded to younger transient loads. A transient store that overwrites a saved return address on the stack gives a transient RET to an attacker-chosen target. The fixes are the same: mask the index before the store, or put an SB after the check.

v1 gadgets in a TEE are found wherever Normal-world input selects memory. Look for:

  • SMC arguments x1–x7;
  • FF-A partition IDs and memory-handle indices;
  • SCMI domain and clock IDs;
  • OP-TEE syscall and pseudo-TA command IDs;
  • lengths that bound a loop over a Secure buffer.

The two-load shape (an index into table A, whose value indexes table B) is the classic gadget. An index into a table of function pointers is just as bad, because it combines v1 with an indirect branch.

Security note: The bounds check and the mask must use the same, already-copied value. If an SMC handler reads idx from shared Normal-world memory, checks it, and then reads it again to use it, the result is a TOCTOU bug whether or not speculation is involved. A speculative-only fix such as CSDB on the second read does not address it. Copy untrusted values into registers or Secure memory once, then check and mask the copy.

Checkpoint

Q14.3.1 A developer hardens a bounds check by adding CSDB directly after b.hs 1f, with no CSEL, and leaves ldrb w3, [x0, x1] using the unmodified x1. Is the gadget closed?

  • A. Yes. CSDB prevents speculative execution past it until the preceding branch resolves.
  • B. Yes, on v8.5 cores, where CSDB is upgraded to SB semantics.
  • C. No. CSDB only stops later instructions from consuming results derived from predicted flags or predicted data values. x1 was never derived from the flags, so the load can still use the out-of-range value on the mispredicted path.
  • D. No, because CSDB must come before the CMP to take effect.
Answer

C. CSDB is not a control-flow barrier. It is effective only together with an instruction such as CSEL or SBC that turns the real flags into a data value. Then, on the wrong path, the value used after the CSDB is the clamped one. A describes SB, not CSDB. B is false: CSDB’s semantics do not change with the architecture version.

Read more: Arm ARM (DDI0487), CSDB; Arm whitepaper “Cache Speculation Side-channels”, Software mitigation

Q14.3.2 Which of these index sanitisations is safe against Spectre v1 without any speculation barrier?

  • A. cmp x1, x2; csel x1, x1, xzr, lo
  • B. and x1, x1, #0x3f for a 64-entry table
  • C. cmp x1, x2; b.hs fail with the load placed after the branch
  • D. cmp x1, x2; sbc x6, xzr, xzr; and x1, x1, x6
Answer

B. The AND forces the index into 0–63 without reading any flag, so no prediction can produce an out-of-range value. A and D both derive the mask from flags, which may be predicted, so they need a CSDB after the flag-consuming instruction. That is exactly why Linux’s array_index_mask_nospec() ends with csdb(). C is the unmitigated gadget.

Read more: Arm ARM (DDI0487), CSDB; Linux arch/arm64/include/asm/barrier.h, array_index_mask_nospec()

Q14.3.3 TF-A is built with ENABLE_FEAT_SB=1 by mistake for a v8.2 core that lacks FEAT_SB and uses the BHB loop mitigation on its lower-EL vectors. FEATURE_DETECTION is left at its default of 0. What happens?

  • A. Every ERET from EL3 is followed by an Undefined Instruction exception, because the SB in exception_return is UNDEFINED.
  • B. Nothing. SB is in the hint space and executes as a NOP on cores that lack it.
  • C. ERET paths work, because the SB after an ERET is never architecturally executed. The first exception from a lower EL runs the BHB loop’s speculation_barrier architecturally, and that SB takes an Undefined Instruction exception (EC 0x00) at EL3.
  • D. The core silently falls back to DSB NSH; ISB for every SB.
Answer

C. Unlike CSDB, SB has a dedicated encoding outside the hint space, and it is UNDEFINED without FEAT_SB. An SB placed after ERET is only ever reached speculatively, so it never faults, and on this core it also gives no protection. The barrier at the end of the BHB loop is in the normal flow of the vector entry, so it is executed and faults. A misses that difference. B confuses SB with CSDB. D describes a build-time choice in TF-A’s macros, not a hardware fallback.

Read more: Arm ARM (DDI0487), SB; ID_AA64ISAR1_EL1.SB; TF-A docs, build options, ENABLE_FEAT_SB

14.4 Spectre v2 and BHB

Spectre v2 (CVE-2017-5715, branch target injection) and Spectre-BHB (CVE-2022-23960, branch history injection) both make a victim’s indirect branch speculatively jump to a gadget the attacker chose. The difference is which predictor state the attacker controls:

  • v2 poisons the target stored in the BTB or the indirect predictor. Code in one context trains an entry that aliases a victim branch in another context.
  • BHB poisons the history that selects among targets. The targets the victim branch uses may all have been trained by the victim itself. The attacker shapes the global branch history just before the context switch, so the victim’s lookup picks a victim-trained target that happens to be a useful gadget.

That difference explains why CSV2, the architectural fix for v2, did not fix BHB, and why the BHB mitigations live at exception entry, where history crosses from one context to the next.

CSV2: the architectural fix for v2

ID_AA64PFR0_EL1.CSV2, bits [59:56], advertises restrictions on branch-target speculation between hardware-described contexts (Security state, EL, VMID, ASID, and with CSV2_2 also SCXTNUM_ELx; see 14.1).

CSV2FeatureGuarantee
0b0000—No statement. Assume cross-context target injection is possible, and check the core’s advisory
0b0001FEAT_CSV2Branch targets trained in one hardware-described context cannot exploitatively control speculative execution in another. SCXTNUM_ELx is not part of the context. ID_AA64PFR1_EL1.CSV2_frac (bits [35:32]) refines this value: 0b0001 is CSV2_1p1 and 0b0010 is CSV2_1p2, which differ in whether SCXTNUM_ELx is accessible at all (14.7)
0b0010FEAT_CSV2_2As above, with SCXTNUM_ELx implemented and part of the context
0b0011FEAT_CSV2_3As CSV2_2, plus the same restriction for branch history: history created in one context cannot exploitatively control indirect branches in another. A CSV2_3 core is not affected by Spectre-BHB

FEAT_CSV2 is permitted from v8.0 and mandatory from v8.5. For CSV2_2 and CSV2_3, see DDI0487 A2. Several earlier cores implement CSV2 from a particular revision onwards. Cortex-A72 reports CSV2 from r1p0, for example, and TF-A’s check_erratum_custom for CVE-2017-5715 on A72 reads the field at runtime instead of assuming.

Security note: “Exploitatively control” is the precise wording, and it is narrower than “isolate”. Under CSV2 a cross-context BTB hit can still happen. What is restricted is a cross-context entry steering the victim to an attacker-useful target. CSV2 also says nothing about timing side effects of predictor sharing, and it does not separate code that shares one hardware context.

SMCCC_ARCH_WORKAROUND_1: firmware help on pre-CSV2 cores

On a core without CSV2, a lower EL can train BTB entries that EL3 will use. A higher-privileged OS or hypervisor can also be attacked by its own lower EL. The architecture has no instruction that invalidates the branch predictor in AArch64, so the fix is core-specific and lives in EL3:

CoreWhat TF-A does on entry from a lower ELVector table
Cortex-A57, Cortex-A72 (before CSV2)Toggles SCTLR_EL3.M off and on. On these cores this invalidates the branch predictor, which is core-specific behaviour, not architecturalwa_cve_2017_5715_mmu_vbar
Cortex-A73, Cortex-A75Drops into AArch32 S-EL1 to execute the AArch32 BPIALL, then returns by SMCwa_cve_2017_5715_bpiall_vbar

The SMCCC call SMCCC_ARCH_WORKAROUND_1 (0x80008000, SMCCC v1.1 or later) lets a lower EL ask for the same invalidation at points where it is the victim. Examples are Linux on a switch between user processes, or KVM on guest exit. Discovery is by SMCCC_ARCH_FEATURES (0x80000001) with w1 = 0x80008000:

Return valueMeaning
0Implemented, and this PE needs it
1Implemented, but this PE does not need it (Linux: SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED)
−1 (NOT_SUPPORTED)Not implemented. The caller must assume it is vulnerable unless it can prove otherwise from CSV2

The answer is per PE. On a big.LITTLE system, each core type must be asked separately, and the OS must treat the system as affected if any core is.

BHB: the mitigation ladder

Spectre-BHB affects many cores that do have CSV2: Cortex-A57/A72 through A78, X1/X2, A710, Neoverse N1/N2/V1 and later parts (see Arm’s Spectre-BHB advisory for the authoritative list). The mitigation must run on exception entry from a less-privileged EL, before the first indirect branch in the more-privileged code. Choose the first mechanism the core supports, in this order. Linux’s spectre_bhb_enable_mitigation() in arch/arm64/kernel/proton-pack.c uses the same order.

#MechanismDiscoveryCost at entry
0CSV2_3: not affectedID_AA64PFR0_EL1.CSV2 = 0b0011None
1FEAT_ECBHB: an exception to a higher EL prevents earlier branch history from exploitatively controlling indirect branches after the exception. v8.9; see DDI0487 A2ID_AA64MMFR1_EL1.ECBHB, bits [63:60]None: hardware
2FEAT_CLRBHB: the CLRBHB instruction (HINT #22) clears history for the current context. Permitted from v8.0, mandatory from v8.9ID_AA64ISAR2_EL1.CLRBHB, bits [31:28]CLRBHB; ISB
3Branch loop: execute k taken branches to overwrite the history, then a speculation barrierMIDR lookup: the value of k is per core and comes from Arm’s advisoryk taken branches plus SB or DSB; ISB
4SMCCC_ARCH_WORKAROUND_3 (0x80003FFF): firmware does a core-specific predictor invalidation that also covers WA_1SMCCC_ARCH_FEATURESOne SMC round trip

Because CLRBHB is in the hint space, it executes as a NOP on a core that does not implement it, so shared code can carry it without faulting (but also without protection). Linux still selects the CLRBHB vector slot only on CPUs that advertise ID_AA64ISAR2_EL1.CLRBHB, and patches the KVM hyp copy to NOPs when no CPU uses it. The loop and the SMC are only used when the instruction is absent.

The loop, as TF-A writes it (lib/cpus/aarch64/wa_cve_2022_23960_bhb.S):

    .macro apply_cve_2022_23960_bhb_wa _bhb_loop_count
    str   x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
    mov   x2, \_bhb_loop_count
1:  b     2f                     // a taken branch: shifts one entry into the BHB
2:  subs  x2, x2, #1
    bne   1b                     // a second taken branch per iteration
    speculation_barrier          // SB, or DSB SY; ISB
    ldr   x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
    .endm

Linux’s __mitigate_spectre_bhb_loop uses b . + 4 in the same place, and patches the immediate at boot to the largest k among the system’s cores.

kCores (from TF-A *_BHB_LOOP_COUNT)
8Cortex-A72 (Linux also uses 8 for Cortex-A57; TF-A has no A57 count and uses the WA_1 MMU-toggle vectors there instead)
24Cortex-A76, A76AE, A77, Neoverse N1
32Cortex-A78, A78AE, A78C, X1, X2, A710, Neoverse N2, V1
38Cortex-A715
132Cortex-A720, X3, X4, Neoverse V2, V3

These are the values in the TF-A tree as of 2025. Take them from the current TF-A source and Arm’s advisory, not from this table. Linux 6.6’s list stops at 32, plus 11 for Ampere-1. Later kernels added the larger counts, so an old kernel on a newer core may be under-mitigated while reporting that it is mitigated. Cortex-A73 and A75 cannot be fixed with a loop, and they use WA_3.

Bring-up note: In a heterogeneous system, the mitigation is per core type, but the vector code at a given EL is usually shared. TF-A solves this per core: each CPU’s reset function installs its own VBAR_EL3 (for example wa_cve_vbar_cortex_a710), with that core’s k built in. Linux patches a single loop count, the system-wide maximum. If you add a new core type to a TF-A port, check that its cpu_ops reset function runs on every core, including warm boot. A core that comes back from power-down through a path that skips the override runs with the generic, unmitigated vectors.

How TF-A wires it into the EL3 vectors

  1. Per-core vector tables. wa_cve_2022_23960_bhb_vector_table _count, _cpu (in wa_cve_2022_23960_bhb_vector.S) builds a full 2KB table. The current-EL entries (0x000–0x3FF) just branch to the generic handlers. The lower-EL AArch64 and AArch32 entries (0x400–0x7FF) run apply_cve_2022_23960_bhb_wa and then branch to the generic handler. Only lower-EL entries are mitigated, because those are the only ones where the history came from less-privileged code.
  2. Installation. The core’s reset function, under WORKAROUND_CVE_2022_23960 (default 1), uses override_vector_table or writes VBAR_EL3 directly. On A57/A72 before CSV2, the WA_1 MMU-toggle table is installed instead, and it covers both. On A76, one table (cortex_a76_wa_cve_vbar) combines the BHB loop with the CVE-2018-3639 dynamic workaround (14.5).
  3. The WA_1/WA_3 fast path. In wa_cve_2017_5715_mmu.S, the synchronous lower-EL entry checks w0 == WA_1 || w0 == WA_3 and ESR_EL3 == SMC #0 with a CMP/CCMP/CCMP chain, and returns with exception_return immediately. The predictor invalidation has already happened on vector entry, so there is nothing left to do. On cores without a fast path, the SMC reaches arm_arch_svc_smc_handler(), which returns SMC_RET0, because “the workaround has already been applied on affected PEs during entry to EL3”.
  4. Discovery. arm_arch_svc_setup.c answers SMCCC_ARCH_FEATURES for WA_1 and WA_3 from each core’s check_erratum_* functions. WA_3 reports “not required” only if neither CVE-2022-23960 nor CVE-2017-5715 applies, because a caller may use WA_3 in place of WA_1.

The same pattern applies at EL2 and EL1: KVM and Linux install mitigated vector slots (EL1_VECTOR_BHB_LOOP, EL1_VECTOR_BHB_CLEAR_INSN, EL1_VECTOR_BHB_FW) and choose among them per CPU at boot.

Validation note: For each core type, check three things. (1) Discovery is consistent. Compare ID_AA64PFR0_EL1.CSV2, ID_AA64MMFR1_EL1.ECBHB and ID_AA64ISAR2_EL1.CLRBHB with the core’s TRM, and compare the SMCCC_ARCH_FEATURES answers for WA_1 and WA_3 with the advisory. A WA_3 answer of 1 on an affected core is a firmware bug. (2) The vector is installed. On every core, after cold boot and after a CPU_SUSPEND power-down resume, read VBAR_EL3 with a debugger and compare it with the symbol of the per-core table. (3) The loop runs. Count BR_RETIRED (0x21) or BR_IMMED_RETIRED (0x0D) across an SMC from Non-secure EL1, with EL3 counting enabled (by default MDCR_EL3.SPME=0 prohibits counting at EL3, so the loop is invisible). It should rise by about 2·k relative to a build without the workaround. On Linux, /sys/devices/system/cpu/vulnerabilities/spectre_v2 reports the BHB state the kernel believes it has, which is only as good as its MIDR tables.

Checkpoint

Q14.4.1 A core reports CSV2 = 0b0010, ECBHB = 0 and CLRBHB = 1. A developer argues that because the core has CSV2_2, no Spectre-BHB mitigation is needed on EL3 entry. Which response is correct?

  • A. Correct. CSV2_2 covers all branch predictor state, including history.
  • B. Incorrect. CSV2 and CSV2_2 restrict cross-context use of branch targets. Only CSV2_3 or ECBHB covers branch history. Put CLRBHB; ISB on the lower-EL vector entries, before the first indirect branch.
  • C. Incorrect. The core needs the k-iteration loop, because CLRBHB is only a hint and might be a NOP.
  • D. Incorrect. Lower ELs must call SMCCC_ARCH_WORKAROUND_3 before every SMC.
Answer

B. BHB attacks use victim-trained targets selected by attacker-shaped history, which is outside CSV2_2’s guarantee. With ID_AA64ISAR2_EL1.CLRBHB = 1, the instruction is implemented and is the preferred software mitigation, ahead of the loop and the firmware call. C misreads the hint encoding: being a hint means the instruction is a NOP only on cores that do not advertise it. D puts the burden on the attacker’s side of the boundary, which the victim cannot rely on.

Read more: Arm ARM (DDI0487), ID_AA64PFR0_EL1.CSV2, ID_AA64ISAR2_EL1.CLRBHB, CLRBHB; Arm Spectre-BHB security advisory

Q14.4.2 In TF-A’s BHB vector table, why do the current-EL entries (0x000–0x3FF) skip the loop while the lower-EL entries (0x400–0x7FF) run it?

  • A. The current-EL entries are only 32 instructions long, so there is no room for the loop.
  • B. EL3 never takes exceptions from EL3.
  • C. The loop would corrupt SP_EL0 in the current-EL, SP_EL0 entries.
  • D. BHB injection needs the branch history to have been shaped by less-privileged code. On a current-EL exception, the history was produced by EL3 itself, so there is no attacker-controlled history to clear.
Answer

D. The threat is history crossing from a less-privileged context into a more-privileged one, and that crossing only happens on lower-EL entries. A is false because every entry has the same 32-instruction size. B is false because EL3 can take synchronous exceptions and SErrors while running.

Read more: TF-A source, lib/cpus/aarch64/wa_cve_2022_23960_bhb_vector.S; Arm Spectre-BHB security advisory

Q14.4.3 A DynamIQ cluster mixes Cortex-A55 and Cortex-A78 cores. Linux runs on all of them. The A55 cores are not affected by Spectre-BHB. Which statement about Linux’s loop mitigation is correct?

  • A. Linux uses a single patched loop count, the maximum k across all affected cores (32 here). Only the A78 cores have the loop vectors installed. The A55 cores are not affected and keep the default vectors.
  • B. Linux disables the mitigation, because the system is heterogeneous.
  • C. Linux uses k = 8 on every core, because that is the smallest safe value.
  • D. Linux asks firmware for SMCCC_ARCH_WORKAROUND_3 on every core, because loop counts cannot be mixed.
Answer

A. spectre_bhb_loop_affected() records the maximum k across the cores it has seen, and that value is patched into the shared loop. Each affected CPU then selects the loop vector with this_cpu_set_vectors(). Unaffected CPUs return early. C has the logic backwards: a loop count below a core’s k leaves that core’s history only partly overwritten. The firmware call is only chosen when no instruction or loop mitigation exists for the core.

Read more: Linux arch/arm64/kernel/proton-pack.c, spectre_bhb_loop_affected(), spectre_bhb_enable_mitigation()

14.5 Spectre v4 (speculative store bypass)

Spectre v4 (CVE-2018-3639, “speculative store bypass”, SSB) uses the memory-disambiguation predictor from 14.1. A younger load is allowed to execute before an older store whose address is not yet known. If the predictor guesses “no alias” and the addresses turn out to match, the load has transiently read the stale value, the one in the location before the store. The load is replayed and the architectural result is correct. Any address formed from the stale value in the meantime has already left a cache fill.

Unlike v1 and v2, the attacker does not train anything across a context boundary. The bypass happens inside the victim’s own instruction stream. The attacker’s part is to arrange that the stale value is one it chose.

The gadget shape

/* victim, e.g. an SMC handler copying a caller-supplied index into a context */
ctx->idx = untrusted_idx;           /* (1) attacker-chosen value lands in memory    */
...
ctx->idx = untrusted_idx & MASK;    /* (2) sanitising store; its address is slow     */
v = table[ctx->idx];                /* (3) load may bypass (2) and read (1)          */
w = probe[v * 64];                  /* (4) dependent load: the cache channel         */

What makes (3) bypass (2) is that the store’s address resolves late. Typical causes are a base pointer that missed in the cache, or a pointer chain. The store’s data being late does not matter, because a core that knows the addresses match will forward or wait. Compilers create this shape without being asked: a register spilled to the stack and reloaded, or a struct field that is checked and then rewritten. Masking patterns from 14.3 do not help if the masked value is stored and then reloaded, because the reload is exactly the load that bypasses.

For firmware, the classic place is EL3 or S-EL1 code that saves the caller’s x0–x7 into a context structure, sanitises some of them in place, and later reloads them.

What the architecture provides

MechanismFeature / ID fieldScopeCost
PSTATE.SSBSFEAT_SSBS, ID_AA64PFR1_EL1.SSBS ≥ 0b0001Every load while the bit is 0Ongoing, core-dependent
SCTLR_ELx.DSSBS (bit 44)FEAT_SSBSThe value PSTATE.SSBS takes on exception entry to ELxNone by itself
MSR SSBS, #immFEAT_SSBSDirect write of the bit, usable at EL0Cheap toggle
MRS/MSR with the SSBS system registerFEAT_SSBS2, ID_AA64PFR1_EL1.SSBS = 0b0010Read the bit, or write it from a registerCheap
SSBBDefined for all Armv8.0 implementationsPoint fix: same virtual addressOne barrier
PSSBBDefined for all Armv8.0 implementationsPoint fix: same physical address, any VAOne barrier

FEAT_SSBS is permitted from v8.0. Some secondary sources say it is mandatory from v8.5, but the ID_AA64PFR1_EL1.SSBS field description carries no “From Armv8.x, the value 0b0000 is not permitted” statement (unlike CSV2, CSV3 or SB), so probe ID_AA64PFR1_EL1.SSBS and do not infer it from a version claim.

PSTATE.SSBS: read the name carefully

SSBS stands for Speculative Store Bypass Safe. The polarity is the reverse of what a “mitigation enable” bit usually looks like:

  • PSTATE.SSBS = 0: the code is not declared safe. Hardware is not permitted to let loads speculatively bypass older stores in a way that could be exploited through a timing side channel. Mitigation on.
  • PSTATE.SSBS = 1: the code is declared safe, so the bypass is allowed. Mitigation off, full performance.

PSTATE.SSBS is held in SPSR_ELx bit 12 for an AArch64 context and bit 23 for an AArch32 context (where it also sits in CPSR). Like every PSTATE bit it is restored by ERET (2.4).

DSSBS: the entry default

On exception entry to ELx, PSTATE.SSBS is set to SCTLR_ELx.DSSBS. This lets a more privileged level start with the mitigation on, whatever the interrupted context had. With DSSBS = 0, an EL0 process that set SSBS=1 for its own speed cannot leave the kernel running unmitigated. TF-A clears SCTLR_EL3.DSSBS in el3_entrypoint_common, so EL3 always runs with SSBS=0. Its SPSR_64() macro also clears the SSBS bit, so a lower EL that TF-A enters for the first time starts mitigated as well.

With FEAT_SSBS, software can change the bit three ways: exception entry (via DSSBS), ERET (via SPSR), and MSR SSBS, #imm, whose decode is gated on FEAT_SSBS, not FEAT_SSBS2. Linux uses the immediate form for its own EL1 state on any FEAT_SSBS core, and edits the saved SPSR_EL1.SSBS of a task that opted in or out. FEAT_SSBS2 adds only the MRS/MSR register forms (MRS Xt, SSBS / MSR SSBS, Xt), so software can also read the bit:

    msr     ssbs, #0          // mitigation on (FEAT_SSBS)
    sb                        // see the erratum note below; dsb nsh; isb without FEAT_SB
    ...                       // sensitive store/reload sequence
    msr     ssbs, #1          // mitigation off

GNU as needs -march=...+ssbs for these mnemonics. MSR SSBS is permitted at EL0. That is by design: v4 is a self-protection problem, and a JIT or sandbox runtime is entitled to choose for itself. It also means a privileged level must never assume that the SSBS value it set before ERET is still in force when that context traps back. It must rely on DSSBS on entry.

Bring-up note: An MSR SSBS, #imm is architecturally self-synchronising, but many Arm cores have an erratum in which MSR SSBS, #0 may not affect younger speculative instructions. Linux tracks it as ARM64_ERRATUM_3194386. It covers Cortex-A76/A77/A78/A78C/A710/A715/A720/A725, Cortex-X1/X1C/X2/X3/X4/X925 and Neoverse N1/N2/N3/V1/V2/V3, each under its own erratum number. The workaround is an SB (or ISB) after every privileged write to SSBS. Linux also hides the ID_AA64PFR1_EL1.SSBS field, and so HWCAP_SSBS, from EL0 on affected cores. Check the SDEN for the cores you ship (1.3).

SSBB and PSSBB: point barriers

These are DSB encodings with CRm = 0b0000 and CRm = 0b0100 respectively (7.6). Despite the encoding, their architectural meaning is not a DSB completion guarantee. What they define is a speculation restriction:

  • SSBB: a load after the barrier does not speculatively read an entry earlier in the coherence order than the one written by the latest older store, before the barrier, to the same location using the same virtual address. Symmetrically, a load before the barrier does not speculatively read data from a store after it.
  • PSSBB: the same, but for stores to the same physical location, whatever VA they used. Use it when the store and the reload may go through different aliases, for example a buffer mapped twice or a kernel writing through the linear map and reading through a vmalloc alias.

These encodings were reserved DSB options before Spectre, and the Arm ARM requires reserved DSB options to execute as a full-system DSB. A core older than the definition therefore runs them as DSB SY. That is safe but slow, so the Arm ARM’s statement that they exist in all v8.0 implementations is not a promise of cheapness. Place them between the sanitising store and the reload:

    str     x1, [x0, #CTX_IDX]    // attacker value saved earlier...
    and     x1, x1, #0xff
    str     x1, [x0, #CTX_IDX]    // ...overwritten with the sanitised one
    ssbb                          // reload below cannot see the older value
    ldr     x2, [x0, #CTX_IDX]
    ldrb    w3, [x4, x2]

For C, there is no compiler intrinsic that places SSBB reliably, because the compiler chooses where reloads go. Code that needs v4 protection runs with SSBS=0 rather than with hand-placed barriers.

Cores without SSBS: chicken bits and SMCCC_ARCH_WORKAROUND_2

Cores affected by v4 that predate SSBS have an IMPLEMENTATION DEFINED “disable load pass store” control in an CPUACTLR*_EL1 register. Only EL3 can write it, or a lower EL if EL3 grants access through ACTLR_EL3, which production firmware should not do. TF-A’s advisory TFV-7 lists them:

CoreControlTF-A approach
Cortex-A57, A72CPUACTLR_EL1 bit 55Static: set at every reset, never cleared
Cortex-A73bit 3 of S3_0_C15_C0_0 (undocumented in TRM)Static
Cortex-A75CPUACTLR_EL1 bit 35Static
Cortex-A76CPUACTLR2_EL1 bit 16Dynamic (DYNAMIC_WORKAROUND_CVE_2018_3639)

The register encodings and bit numbers are core-specific. Take them from the TRM or advisory for your exact core and revision, never from this table.

Static mitigation sets the bit once per reset (cold and warm). The whole stack is mitigated and nobody else has to do anything. Dynamic mitigation lets a lower EL ask EL3 to switch the bit for its own context with SMCCC_ARCH_WORKAROUND_2 (function ID 0x80007FFF, SMCCC v1.1+):

  • w1 = 1: enable the mitigation for the caller; w1 = 0: disable it.
  • Discovery is SMCCC_ARCH_FEATURES(0x80007FFF). TF-A returns 0 when this PE needs dynamic mitigation and the call must be made. It returns 1 when the call is not needed on this PE, either because the PE is unaffected or because it implements SSBS, so the caller should use PSTATE.SSBS. It returns NOT_REQUIRED (-2) when firmware has mitigated permanently and the call has no effect. NOT_SUPPORTED (-1) means firmware says nothing, so a careful caller treats the PE as possibly vulnerable, as Linux does.

TF-A’s Cortex-A76 implementation shows the shape. On every entry to EL3 from a lower EL, its private vector table sets the chicken bit, so EL3 itself always runs mitigated. A fast path in the sync vector recognises SMC #0 with w0 = 0x80007FFF, sets or clears the bit according to w1, records whether the bit should be cleared again on the next el3_exit, and executes ERET without entering the C runtime. The call is therefore cheap enough for an OS to make on every context switch. Linux’s default policy (ssbd=kernel) keeps the kernel mitigated and leaves user tasks unmitigated unless they opt in with prctl(PR_SET_SPECULATION_CTRL) or seccomp. That is why it either edits SPSR.SSBS or calls WORKAROUND_2 at the kernel/user boundary.

Security note: The v4 threat for Secure firmware is narrow but real: a Non-secure caller chooses register values that EL3 or the SPMC spills and reloads. Firmware should not take the Non-secure world’s SSBS choice into the Secure world. With SSBS, that is guaranteed by SCTLR_EL3.DSSBS = 0 and an S-EL1 SCTLR_EL1.DSSBS = 0 saved and restored per world. Without SSBS, use the static chicken bit, or the dynamic scheme’s “always on in EL3” entry path. A dynamic implementation that only switches the bit when asked, and not on every EL3 entry, leaves EL3 running with whatever the Non-secure kernel last requested.

Validation note: The architecture gives no PMU event for “store bypassed”. Validate with a timing or throughput microbenchmark: a store whose address hangs off a cache-missing load, followed by a load to the same address. With bypass allowed, the load issues early and is replayed. Look for a rise in a pipeline-flush or replay event (IMPLEMENTATION DEFINED, check the TRM’s PMU chapter) and a change in cycles per iteration between SSBS=1 and SSBS=0, or chicken bit off and on. Confirm the entry default architecturally: on a FEAT_SSBS2 core, MRS x0, SSBS as the first instruction of the EL3 sync handler must read 0. Run the test on every core type in a heterogeneous cluster, because SSBS support and the chicken bit can differ per core (1.1).

Checkpoint

Q14.5.1 An EL1 kernel on a FEAT_SSBS core (no SSBS2) sets SCTLR_EL1.DSSBS = 1 for performance and relies on clearing SPSR_EL1.SSBS before returning to tasks that requested the mitigation. Which statement is correct?

  • A. The kernel is mitigated, because the task’s SSBS=0 is restored into PSTATE on every exception entry
  • B. The kernel cannot change SSBS at all without FEAT_SSBS2, so the configuration is impossible
  • C. Opted-in tasks are mitigated at EL0, but every kernel entry starts with SSBS=1, so kernel code runs without the v4 mitigation
  • D. DSSBS only affects AArch32 contexts, so the configuration has no effect on AArch64
Answer

C. On exception entry, PSTATE.SSBS is loaded from SCTLR_ELx.DSSBS of the target EL, not from the interrupted context. DSSBS = 1 therefore means the kernel always starts with the bypass allowed. A has the direction wrong: the task’s value is saved into SPSR, not kept. B is wrong because SPSR editing works with plain FEAT_SSBS, and so does MSR SSBS, #imm; SSBS2 adds only the register-form MRS/MSR.

Read more: Arm ARM (DDI0487), SCTLR_EL1.DSSBS; PSTATE.SSBS

Q14.5.2 A Secure partition writes a sanitised length into a shared structure through its own mapping. A helper then reloads it through a second VA alias of the same page, and uses it as an index. Which barrier, placed between the store and the reload, prevents a speculative read of the old value?

  • A. PSSBB, because the store and the reload use different VAs for the same physical location
  • B. SSBB, because it covers every store before it regardless of address
  • C. CSDB, because it stops speculative use of the loaded value
  • D. DMB ISHLD, because it orders the load after the store
Answer

A. SSBB covers only stores to the same location using the same virtual address, so it is the tempting but insufficient choice when aliases are involved. PSSBB extends the restriction to the same physical location. CSDB concerns values produced under conditional-select misprediction (v1). A DMB orders observation, not speculative execution.

Read more: Arm ARM (DDI0487), SSBB and PSSBB instruction descriptions

Q14.5.3 On a Cortex-A76 platform built with DYNAMIC_WORKAROUND_CVE_2018_3639, the Non-secure kernel calls SMCCC_ARCH_WORKAROUND_2 with w1 = 0 for a task. What is the state of the “disable load pass store” bit while EL3 runs the next unrelated SMC from that task?

  • A. Clear, because the call disabled the mitigation for the whole PE until re-enabled
  • B. Clear, but only for SMCs routed to the Secure world
  • C. Set only if the SMC function ID is in the Arm Architecture range
  • D. Set, because the EL3 entry path re-enables it on every lower-EL entry and clears it again only on exit to the caller
Answer

D. The dynamic scheme is per context: EL3 forces the mitigation on at entry and restores the caller’s requested state on el3_exit. Without this, EL3 would inherit the Non-secure world’s choice, which is the trap described by A. The function ID and the destination world do not affect the entry path.

Read more: Arm, Firmware interfaces for mitigating cache speculation vulnerabilities (SMCCC_ARCH_WORKAROUND_2); TF-A security advisory TFV-7

14.6 Meltdown-class leaks

Spectre variants make the victim run code it should not. Meltdown-class leaks are different: the attacker’s own instruction reads something it has no right to read, and the core forwards the value to younger instructions before it raises the fault. Nothing needs training. The required hardware behaviour is fault deferral, the last structure row in the table in 14.1. Among Arm-designed cores the exposure is small and well bounded, and that is the main point of this section: know exactly which cores and which boundaries are affected, so firmware neither ignores the problem nor copies OS-level mitigations it does not need.

Variant 3: rogue data cache load (CVE-2017-5754)

    // EL0, kernel VA in x1 (mapped in TTBR1_EL1, AP = privileged-only)
    ldrb    w2, [x1]            // permission fault, but only at commit
    lsl     x2, x2, #6
    ldrb    w3, [x9, x2]        // transient: probe line indexed by the secret

The attack needs the victim data to be mapped in the attacker’s current translation regime, with only the permission check standing in the way. In the EL1&0 regime the kernel is mapped (TTBR1) while EL0 runs, so EL0 can attack EL1. Among Arm’s own cores, the Arm security bulletin lists Cortex-A75 as the only one affected by variant 3. Other implementers’ cores are a separate question; Linux keeps a MIDR safe-list and otherwise defers to CSV3.

What variant 3 cannot do on any core:

  • Reach EL3 or Secure memory from the Non-secure world. EL3 has its own regime, and Secure PAs are not mapped in any Non-secure translation. TF-A’s advisory says plainly that variant 3 “is not applicable” to TF-A for this reason.
  • Cross from EL1 to EL2. EL2 uses a separate regime, apart from the EL2&0 regime under VHE, where the same EL0-vs-EL2 problem reappears.

Security note: The Secure world has its own EL0/EL1 boundary. A trusted application at S-EL0 on a Cortex-A75 can read S-EL1 (Trusted OS) memory exactly as Non-secure EL0 can read the kernel. TF-A explicitly leaves that to the Secure Payload. OP-TEE’s answer is CFG_CORE_UNMAP_CORE_AT_EL0, the S-EL1 equivalent of KPTI. If you review a Trusted OS for an A75-based SoC, check that this, or an equivalent, is on.

Variant 3a: rogue system register read (CVE-2018-3640)

Here the “load” is an MRS of a system register that the current EL is not allowed to read. On affected cores the value is forwarded speculatively before the trap or UNDEFINED exception is taken. Among Arm cores, Cortex-A57 and Cortex-A72 are affected in AArch64 (Cortex-A15 in AArch32).

The leak is register contents, not memory. Few system registers hold secrets, but several hold layout: VBAR_EL1, VBAR_EL2, TTBRx_ELy. That makes 3a a KASLR or hypervisor-layout leak. Linux’s response (ARM64_SPECTRE_V3A, matched by MIDR on A57/A72) is to run KVM’s hypervisor vectors from a separate, randomised mapping, so that VBAR_EL2 no longer reveals where EL2 code lives. TF-A’s position is that software mitigation is generally not believed necessary.

Bring-up note: Do not keep secrets in system registers that are readable, under 3a, from a less privileged EL on A57/A72. Two examples are a key parked in an IMPLEMENTATION DEFINED scratch register, and a pointer to secret data in TPIDR_EL1 used as a “hidden” location. The architectural trap does not protect the value from a speculative read on these cores.

KPTI: the OS-level fix

Kernel page-table isolation removes the kernel from the EL1&0 regime while EL0 runs, so a variant 3 load finds no mapping at all. On arm64 Linux:

  • While EL0 runs, TTBR1_EL1 points at a trampoline page table that maps only the trampoline vectors (tramp_vectors) and the minimum needed to switch.
  • The trampoline vector entry writes TTBR1_EL1 to the real kernel table, issues an ISB, and branches into the normal vectors. Exit does the reverse.
  • Kernel mappings are made nG, and each process gets an ASID pair (user and kernel ASIDs differ in bit 0). Switching tables then needs no TLBI: TCR_EL1.A1 selects the ASID from TTBR1_EL1, and the trampoline flips the ASID together with the base address (9.1).

The cost is two TTBR writes and two ISBs per kernel crossing, plus TLB pressure from nG kernel mappings. Linux decides per system (unmap_kernel_at_el0() in cpufeature.c, with kaslr_requires_kpti()) as follows:

ConditionKPTI?
Every core has ID_AA64PFR0_EL1.CSV3 = 1 or is on the MIDR safe-list (A35/A53/A55/A57/A72/A73 and others)Not needed for Meltdown
KASLR enabled and the core lacks FEAT_E0PDOn anyway, to protect KASLR from timing attacks
A core is affected by CVE-2024-7881 and firmware does not advertise SMCCC_ARCH_WORKAROUND_4On, but only in kernels carrying the January 2025 patch series that proposed this (queued on an arm64 topic branch; not in every mainline or vendor kernel, so check yours)
kpti= on the command lineForced either way

KPTI is a kernel matter. EL3 firmware has nothing to do for it except to avoid breaking its assumptions, for example by not mapping firmware-shared buffers into the trampoline view.

FEAT_CSV3: the architectural “not affected”

ID_AA64PFR0_EL1.CSV3 (bits [63:60]) = 0b0001 means, in current issues of the register description: data loaded or read from a register under speculation, where the load or register read would not be permitted architecturally, cannot be used by newer instructions in a manner that allows the value of the inaccessible data to be recovered by code architecturally executed. Older issues worded it more narrowly, as data loaded with a permission or domain fault that cannot be used to form an address, generate condition codes or SVE predicate values, or affect the timing of other instructions. 0b0000 means the PE does not disclose. It does not mean “vulnerable”.

  • Permitted from v8.0. From v8.5 the value 0b0000 is not permitted, so CSV3 is effectively mandatory from v8.5.
  • It is what lets an OS drop KPTI. The current wording also names register reads, so on a core that reports CSV3 = 1 against that wording, variant 3a is covered too. Older issues spoke only of faulting loads, so check which wording your DDI0487 issue and the core’s TRM use before relying on CSV3 for 3a. Linux identifies 3a by MIDR (A57/A72, which report 0), not by CSV3. For an older core reporting 0, the security bulletin and the TRM are the authority (14.7).

FEAT_E0PD: faulting EL0 accesses to the kernel half

FEAT_E0PD is permitted from v8.4 and mandatory from v8.5 (ID_AA64MMFR2_EL1.E0PD, bits [63:60]). It adds TCR_EL1.E0PD0 (bit 55) and TCR_EL1.E0PD1 (bit 56), and the same fields in TCR_EL2 for the EL2&0 regime. With E0PD1 = 1, any EL0 access to an address translated through TTBR1_EL1 takes a level 0 Translation fault, whether or not the address is mapped. The point is that the fault should take the same time to generate whether or not the address is in the TLB (the register description words this as a “should”, not a “must”), so its timing does not reveal whether a translation exists or is cached. These faults are also not counted as TLB misses by the PMU. DDI0487 describes this under TCR_EL1.E0PDx.

E0PD is aimed at the other Meltdown-adjacent leak, which is probing the kernel layout by timing faulting accesses or prefetches, the classic KASLR break. It is not a variant 3 fix on its own. The ID register text, however, ties it to one: if FEAT_E0PD is implemented, FEAT_CSV3 must be implemented. A core with E0PD is therefore not variant-3 vulnerable, and E0PD replaces the remaining reason for KPTI (KASLR robustness) at no per-crossing cost.

    // EL1 init on a v8.5+ core: fault EL0 accesses to the TTBR1 half
    mrs     x0, tcr_el1
    orr     x0, x0, #(1 << 56)      // TCR_EL1.E0PD1
    msr     tcr_el1, x0
    isb

CVE-2024-7881: a leak with no speculation

TF-A advisory TFV-13 describes a newer issue in the same class. On some cores (Cortex-X3, X4, X925 and Neoverse V2, V3, V3AE), an unprivileged context can make the data memory-dependent prefetcher fetch a privileged location and then use the contents as an address that it also dereferences. The fill reveals the value. No instruction executes transiently at all. The mitigation is an IMPLEMENTATION DEFINED disable applied by EL3 at reset (on Neoverse V2, TF-A sets CPUACTLR6_EL1 bit 41). SMCCC_ARCH_WORKAROUND_4 (0x80000004) exists for discovery only: in TF-A, SMCCC_ARCH_FEATURES returns 0 on an affected PE where the firmware mitigation is in place and NOT_SUPPORTED (-1) on an unaffected PE, and calling the function does nothing. A 2025 Linux patch series makes the kernel fall back to KPTI on affected cores when discovery does not return 0. Whether your kernel carries it is a per-tree question; it is not in every mainline release.

Validation note: For each Meltdown-class item, the deliverable is a table, per core type and revision, with three columns: the ID field (CSV3, E0PD), the bulletin status, and what the firmware or OS does. Test it from both ends. From EL1, check that SMCCC_ARCH_FEATURES(0x80000004) returns 0 on affected cores and that Linux reports /sys/devices/system/cpu/vulnerabilities/meltdown as expected. On silicon, run a Flush+Reload variant 3 test from EL0 against a privileged-only kernel page with KPTI forced off. On a CSV3 core it must give no signal. On A75 with KPTI off it should give a signal, which proves the test works. For E0PD, check that an EL0 access to a TTBR1 address reports a level 0 Translation fault (ESR_EL1.ISS.DFSC = 0b000100) whether or not the page is mapped.

Not a speculation mitigation: PSTATE.DIT

This topic is unrelated to Meltdown and is kept here only because reviewers often confuse it with one. Data-independent timing is a promise about architecturally executed instructions. With PSTATE.DIT = 1, the architecture requires two things. The timing of every load and store is insensitive to the data value loaded or stored, though not to the address. For certain data-processing instructions, the time taken is independent of the values in their registers and of NZCV. Which instructions are covered is stated in each instruction’s “Operational information” in DDI0487, and the list is collected under “About PSTATE.DIT”. Check it before relying on a particular instruction, rather than assuming that all of integer, SIMD or crypto is covered. It is what constant-time cryptography assumes, and on a core that does early-out multiplies it is otherwise false.

  • FEAT_DIT, ID_AA64PFR0_EL1.DIT (bits [51:48]). The value 0b0000 is not permitted from v8.4, so it is mandatory from v8.4. PSTATE.DIT is SPSR bit 24.
  • Accessed with MSR DIT, #imm and MRS/MSR DIT, permitted at EL0.
  • Exception entry does not change it. The handler keeps the interrupted context’s value until it sets its own. TF-A therefore sets DIT = 1 on every EL3 entry (ENABLE_FEAT_DIT), and Linux does the same on kernel entry.

What DIT does not do: it does nothing for timing that depends on addresses (table lookups indexed by a secret), on branches on secrets, or on anything transient. Constant-time code still needs constant-time algorithms. DIT only removes the hidden data-dependent latency of individual instructions.

Checkpoint

Q14.6.1 A Cortex-A75 SoC runs TF-A at EL3, OP-TEE at S-EL1 with TAs at S-EL0, and Linux with KPTI enabled. Which boundary is still exposed to variant 3 if nothing else is done?

  • A. Non-secure EL0 reading EL3 memory, because EL3 does not use KPTI
  • B. S-EL0 trusted applications reading S-EL1 (OP-TEE core) memory
  • C. Non-secure EL1 reading Secure memory through a speculative walk
  • D. None, because KPTI in Linux protects the whole system
Answer

B. Variant 3 needs the target mapped in the attacker’s own regime, guarded only by a permission check. The Secure EL1&0 regime has that shape when OP-TEE’s core is mapped while TAs run, so OP-TEE needs CFG_CORE_UNMAP_CORE_AT_EL0. EL3 memory and Secure PAs are not mapped in any Non-secure regime, so A and C do not apply. D is wrong because Linux’s KPTI only changes the Non-secure EL1&0 tables.

Read more: Arm ARM (DDI0487), FEAT_CSV3; TF-A security advisory TFV-6 (variant 3)

Q14.6.2 On a v8.5 core with FEAT_E0PD, Linux disables KPTI even with KASLR on. What justifies dropping both reasons for KPTI?

  • A. E0PD prevents speculative loads from reading kernel data at EL0
  • B. E0PD unmaps the kernel from TTBR1_EL1 while EL0 runs
  • C. E0PD makes TTBR1_EL1 inaccessible to EL0 MRS, which closes variant 3a
  • D. E0PD makes every EL0 access to the TTBR1 half fault, with the fault intended to take the same time whether or not the address is mapped, which protects KASLR, and implementing E0PD requires CSV3, which covers variant 3
Answer

D. E0PD by itself addresses fault-timing layout probes. The Meltdown guarantee comes from the architectural rule that E0PD implies CSV3. A is the tempting option, but it attributes CSV3’s property to E0PD. B describes KPTI, and C is unrelated (TTBR1_EL1 was never EL0-readable architecturally).

Read more: Arm ARM (DDI0487), ID_AA64MMFR2_EL1.E0PD; TCR_EL1.E0PD1

Q14.6.3 An EL3 crypto service sets PSTATE.DIT = 1 once in its cold-boot path and assumes it stays set. What goes wrong?

  • A. Each later EL3 entry keeps the lower EL’s DIT value, which is restored from SPSR on every ERET, so the service may run with DIT=0
  • B. Nothing; DIT is a global control, so setting it once at EL3 covers all ELs
  • C. Exception entry always clears DIT, so the service always runs with DIT=0
  • D. DIT is RES0 at EL3
Answer

A. DIT is a PSTATE bit, saved to SPSR and restored by ERET. Exception entry leaves it unchanged, so EL3 inherits whatever the Non-secure caller had. That is why TF-A sets it on every entry. C is the tempting option, but entry does not clear it either. Assuming either fixed value is wrong.

Read more: Arm ARM (DDI0487), About PSTATE.DIT; AArch64.TakeException()

14.7 Prediction isolation on a world switch

A “world switch” here is any point where one piece of software hands the PE to another it does not trust. Examples are EL3 switching Non-secure and Secure (or Realm), a hypervisor switching VMs, an SPMC switching partitions, a Trusted OS switching TAs, and an OS switching processes. The question for each is the same: can prediction state left by the outgoing software steer speculation in the incoming software? The architecture answers it in three layers:

  1. Automatic isolation between hardware-described contexts, promised by FEAT_CSV2/CSV2_2/CSV2_3 (branch prediction) and FEAT_CSV3 (faulting loads, 14.6).
  2. Software-defined sub-contexts with SCXTNUM_ELx, for isolation the hardware context cannot express.
  3. Explicit restriction instructions in FEAT_SPECRES/SPECRES2, for cases where a context identity is reused or where a predictor is not covered by layer 1.

Vector-entry mitigations for cores that lack layer 1 (BHB loops, SMCCC_ARCH_WORKAROUND_1/3) are in 14.4.

Layer 1: what CSV2 already gives you

The hardware-described context (14.1) is made of the Security state, the Exception level, the VMID where stage 2 applies, the ASID where the regime uses one, and, with FEAT_CSV2_2, SCXTNUM_ELx. On a CSV2 core, branch targets trained in one such context cannot exploitatively control speculation in another. Consequences:

  • Non-secure ↔ Secure through EL3 is isolated for branch targets, because the Security state and EL differ. EL3 does not need to flush anything for branch-target prediction on a CSV2 core.
  • Two VMs with different VMIDs are isolated, and so are two processes with different ASIDs.
  • Two partitions or TAs that end up with the same VMID or ASID are not isolated, and neither is an ASID or VMID number reused for a new tenant after roll-over. As far as the hardware context is concerned, they are the same context. That is the gap layer 3 fills.
  • CSV2 speaks about branch target prediction. Branch history is CSV2_3’s concern (14.4). Data value prediction and cache prefetch prediction are named separately by SPECRES.

Layer 2: SCXTNUM_ELx

SCXTNUM_EL0, SCXTNUM_EL1, SCXTNUM_EL2 and SCXTNUM_EL3 are 64-bit “software context number” registers. Software writes a value, and with FEAT_CSV2_2 (ID_AA64PFR0_EL1.CSV2 = 0b0010 or higher) the value becomes part of the hardware-described context for that EL. Two sandboxes in one process, such as a browser’s site-isolated JIT compartments, can then be separated without separate ASIDs.

ID_AA64PFR0_EL1.CSV2ID_AA64PFR1_EL1.CSV2_fracSCXTNUM_ELx present?Part of the context?
0b00010b0000 or 0b0001 (CSV2_1p1)No—
0b00010b0010 (CSV2_1p2)YesNo: the registers exist but give no isolation
0b0010 (CSV2_2) or 0b0011 (CSV2_3)—YesYes

The CSV2_1p2 row is a trap. Software that writes SCXTNUM_EL0 there gets a working register and no protection. Decide from CSV2, not from whether the MSR succeeds.

Access controls follow the usual pattern of arriving trapped (2.6):

ControlEffect when it blocks
SCR_EL3.EnSCXT (bit 25) = 0EL0–EL2 accesses trap to EL3 (or are UNDEFINED where the register’s accessibility pseudocode selects that, via EL3SDDUndef())
HCR_EL2.EnSCXT (bit 53) = 0EL1 and EL0 accesses trap to EL2 (when EL2 is enabled)
SCTLR_ELx.TSCXT (bit 20) = 1EL0 accesses to SCXTNUM_EL0 trap
HFGRTR_EL2/HFGWTR_EL2.SCXTNUM_EL0/SCXTNUM_EL1 (FEAT_FGT)Fine-grained traps to EL2

Bring-up note: Once EL3 sets SCR_EL3.EnSCXT, SCXTNUM_EL0/EL1/EL2 become per-world state, and EL3 must save and restore them on every world switch, like any other EL1/EL2 system register. Otherwise the Secure world inherits, and can read, the Non-secure world’s values, and the reverse. TF-A sets EnSCXT only when is_feat_csv2_2_supported(), and saves and restores all three in its EL1/EL2 context code. A port that enables EnSCXT in a hand-rolled SCR value without extending the context is a cross-world leak of software state, and also of the isolation it was meant to provide. Their reset value is UNKNOWN, so initialise them before first entry to each world.

Few production stacks use SCXTNUM today. Linux does not program it for user space, and KVM traps guest access. For firmware the main obligations are therefore not to break it, by context-switching it, and not to rely on it for isolation that VMIDs, ASIDs or Security states already give.

Layer 3: FEAT_SPECRES restriction instructions

FEAT_SPECRES (ID_AA64ISAR1_EL1.SPECRES, bits [43:40], 0b0001) adds three SYS-space instructions. FEAT_SPECRES2 (SPECRES = 0b0010) adds a fourth. FEAT_SPECRES is permitted from v8.0 and mandatory from v8.5. FEAT_SPECRES2 is permitted from v8.0 and mandatory from v8.9/v9.4. The ID_AA64ISAR1_EL1.SPECRES description states both directly: from Armv8.5 the value 0b0000 is not permitted, and from Armv8.9 the value 0b0001 is not permitted. Cross-check against DDI0487 A2 for the issue you target.

InstructionRestricts
CFP RCTX, XtControl-flow prediction (branch targets, history, return prediction)
DVP RCTX, XtData value prediction
CPP RCTX, XtCache prefetch prediction
COSP RCTX, Xt (SPECRES2)Other speculative prediction, meaning anything not covered by the three above

GNU as needs +predres (and +predres2 for COSP).

The guarantee (paraphrasing the CFP description, the others are analogous): predictions determined by the actions of code in the target context before the instruction cannot be used to exploitatively control speculative execution after the instruction is complete and synchronized. Note what the descriptor names. It names the context whose learned state is to be neutralised, not the context to be protected. Whatever ran under that context identity earlier can no longer steer what runs afterwards, including a new owner of the same identity. That is exactly the identity-reuse gap left by layer 1. The implementation may invalidate entries, retag them or ignore them; the architecture does not say which.

The RCTX descriptor in Xt

BitsFieldMeaning
[63:49]RES0
[48]GVMID1 = all VMIDs (EL0/EL1 targets)
[47:32]VMIDTarget VMID when GVMID = 0 and the target is EL1, or EL0 outside the EL2&0 host regime
[31:28]RES0
[27]NSEWith FEAT_RME, selects the Security state together with NS
[26]NSWithout RME: 0 = Secure, 1 = Non-secure
[25:24]ELTarget EL: 0b00 EL0 … 0b11 EL3
[23:17]RES0
[16]GASID1 = all ASIDs (EL0 target)
[15:0]ASIDTarget ASID when GASID = 0

Rules that matter in practice:

  • Completion is local and needs a sequence. The effect is guaranteed only after a DSB covering reads and writes on the PE that executed it, followed by a context synchronization event. There is no broadcast form. A hypervisor recycling a VMID has to run the sequence on every PE that may have run the old tenant, typically lazily, on each PE’s next use of the new VMID generation, the same way a VMID roll-over TLB flush is handled.
  • A lower EL cannot target a higher one. Executed at an EL below the target EL, or for an unimplemented EL and Security state combination, the instruction is a NOP. There are further NOP cases for NS/NSE at EL3. EL1 can therefore clean up for its own EL0/EL1 contexts, but not for EL2 or EL3.
  • Traps: at EL0, with SCTLR_EL1.EnRCTX (bit 10) = 0 they trap to EL1 (or to EL2 when HCR_EL2.TGE = 1) with EC 0x18, not UNDEFINED; in the EL2&0 host regime, SCTLR_EL2.EnRCTX = 0 traps them to EL2. At EL1 they trap to EL2 under nested virtualization (HCR_EL2.NV) and through HFGITR_EL2.CFPRCTX/DVPRCTX/CPPRCTX with FEAT_FGT.
  • They are meant to be rare. Arm expects use “on the roll-over of an ASID or VMID”, not on every context switch.
    // EL2: VMID generation roll-over, run on each PE before first use of the
    // new generation. Target: all VMIDs, EL1, Non-secure.
    mov     x0, #(1 << 48)                    // GVMID = 1
    orr     x0, x0, #(1 << 26)                // NS = 1
    orr     x0, x0, #(0b01 << 24)             // EL = EL1
    cfp     rctx, x0
    dvp     rctx, x0
    cpp     rctx, x0
    orr     x1, x0, #(1 << 16)                // same, EL0 with GASID = 1
    and     x1, x1, #~(0b11 << 24)            // EL = EL0
    cfp     rctx, x1
    dvp     rctx, x1
    cpp     rctx, x1
    dsb     sy
    isb

When EL3 or a hypervisor must issue them

SituationWhoNeeded?
NS ↔ Secure (or Realm) world switch on a CSV2 core, contexts persistentEL3No. The Security state already separates the contexts
Same, on a pre-CSV2 coreEL3Such cores are pre-v8.5 and usually lack SPECRES too, so use the 14.4 vector mitigations. Where SPECRES is present, EL3 could in principle target the Non-secure EL1/EL0 contexts on entry, but Arm says RCTX “should not be used on every context switch”
VMID roll-over or reuse for a different VMEL2 (KVM, Hafnium-style SPMC at S-EL2, RMM at R-EL2 for Realm VMIDs)Yes, all four (COSP with SPECRES2), on every PE, before the new tenant runs
ASID roll-over or reuse for a different process or TAEL1 OS or Trusted OSYes, with GASID = 1 or the reused ASID
A Secure partition or payload replaced in place (new image, same S-EL1 context, same VMID or no EL2)EL3 or SPMCYes, for the reused context, since it is the same identity with a new owner
Live firmware activation that replaces the EL3 imageEL3Not mandated anywhere, but by the same reasoning it is identity reuse for EL3 itself. Issue with EL = 0b11 from the new image
Sandboxes within one processUser runtimeNot RCTX. Use distinct SCXTNUM_EL0 values on CSV2_2 cores

Security note: “Isolated by the Security state” is only as good as the identifiers below it. In the Secure world, OP-TEE or an SPMC that gives every TA or partition a distinct ASID or VMID gets layer 1 isolation between them for free. One that runs several partitions with the same VMID, or recycles ASIDs, needs RCTX on reuse. If you review an SPMC, ask how VMIDs are allocated and what happens when a partition is restarted.

Reading which mitigations a core needs

No single register gives the answer. Combine four sources, in this order:

  1. ID registers, the architectural promises. Probe these on every core type; never assume them from a version number (1.1).
FieldValue meansMitigation you can drop or must use
ID_AA64PFR0_EL1.CSV2 [59:56]≥1 branch targets isolated; 2 adds SCXTNUM; 3 adds history≥1: no BTB flush on entry; 3: no BHB loop (14.4)
ID_AA64PFR1_EL1.CSV2_frac [35:32]1p1/1p2 refinements1p2: SCXTNUM present but not isolating
ID_AA64PFR0_EL1.CSV3 [63:60]1 = Meltdown-safeNo KPTI or S-EL0 unmapping for variant 3 (14.6)
ID_AA64PFR1_EL1.SSBS [7:4]1 SSBS, 2 SSBS2Use DSSBS/PSTATE.SSBS instead of chicken bits (14.5)
ID_AA64ISAR1_EL1.SB [39:36]SB instructionSB instead of DSB+ISB (14.3)
ID_AA64ISAR1_EL1.SPECRES [43:40]1 CFP/DVP/CPP, 2 adds COSPRCTX available for identity reuse
ID_AA64MMFR1_EL1.ECBHB [63:60]Restrictions on branch-history speculation around exceptionsNo BHB sequence on entry (14.4)
ID_AA64ISAR2_EL1.CLRBHB [31:28]CLRBHB instructionSingle-instruction BHB clear (14.4)
ID_AA64MMFR2_EL1.E0PD [63:60]E0PD, and CSV3 impliedKPTI for KASLR not needed

A value of 0 in CSV2 or CSV3 means not disclosed, not vulnerable. That is where the other sources come in.

  1. Arm’s security bulletins, the Speculative Processor Vulnerability list for each CVE, indexed by core. They are the authority for older cores that report 0.
  2. The TRM and SDEN for the exact MIDR variant and revision. These give the IMPLEMENTATION DEFINED parts: the BHB loop count k, chicken bits for v4, the CVE-2024-7881 prefetcher disable, and errata in the mitigations themselves, such as the SSBS self-synchronisation erratum in 14.5 (1.3).
  3. The firmware contract: SMCCC_ARCH_FEATURES for SMCCC_ARCH_WORKAROUND_1/2/3/4, which tells a lower EL what EL3 has already done, plus the TF-A CPU library’s WORKAROUND_CVE_* build flags, which show what EL3 will do (12.3).

Validation note: Build the four-source table once per SoC and check it against the running system in both directions. Dump the ID fields above on every core type from EL3 at boot, and compare them with the sanitised values Linux reports (/sys/devices/system/cpu/vulnerabilities/*, plus CPU features and SSBS/SB hwcaps). A mismatch usually means a heterogeneous cluster where one core lacks a feature the boot core has. For SCXTNUM, write distinct values in the Secure and Non-secure worlds and check that each world reads back its own value after a round trip through EL3. A failure means the context code is missing them. For RCTX, an architectural test can only check that the instructions execute without trapping at the intended EL, trap with EC 0x18 from EL0 when SCTLR_EL1.EnRCTX = 0, and are NOPs when the target EL is above the executing EL. Their effect is visible only in a predictor-training test on silicon or RTL. In that test, the BR_MIS_PRED (0x10) count for a victim branch should return to its untrained level after CFP RCTX and the DSB/ISB (16.5).

Checkpoint

Q14.7.1 On a FEAT_CSV2_2 core, an SPMC at S-EL2 restarts a crashed Secure partition by reloading its image into the same memory and reusing its VMID. Which action restores prediction isolation between the old and new instance?

  • A. None. The Security state already separates them
  • B. TLBI VMALLS12E1 for that VMID, because TLB invalidation also invalidates branch predictors
  • C. CFP/DVP/CPP RCTX (and COSP with SPECRES2) targeting that VMID at EL1 and EL0, then DSB and ISB, on each PE that may have run the old instance
  • D. Write a new value to SCXTNUM_EL3
Answer

C. The old and new instances share every element of the hardware-described context, so CSV2 does not separate them. RCTX stops predictions learned in the named context before the instruction from steering later execution. It completes only locally, after a DSB, and takes effect after a context synchronization event. A is the tempting answer, but the Security state is the same for both instances. TLB maintenance has no architectural effect on predictors. SCXTNUM_EL3 affects only EL3’s own context.

Read more: Arm ARM (DDI0487), CFP RCTX; Restrictions on the effects of speculation

Q14.7.2 A core reports ID_AA64PFR0_EL1.CSV2 = 0b0001 and ID_AA64PFR1_EL1.CSV2_frac = 0b0010. A JIT runtime writes a different SCXTNUM_EL0 per sandbox, and the MSRs succeed. What isolation does it get between sandboxes?

  • A. Full branch-target isolation, because the registers are implemented
  • B. None from SCXTNUM. On CSV2_1p2 the registers exist but are not part of the hardware-described context
  • C. Isolation for branch history, but not for branch targets
  • D. Isolation only if SCTLR_EL1.TSCXT is 1
Answer

B. Only FEAT_CSV2_2 and later make SCXTNUM_ELx part of the context. CSV2_1p2 provides the registers alone. A is the tempting answer, because the register works and the protection silently does not. TSCXT = 1 would trap EL0 accesses, not enable isolation.

Read more: Arm ARM (DDI0487), ID_AA64PFR1_EL1.CSV2_frac; SCXTNUM_EL0

Q14.7.3 A Non-secure EL1 kernel executes CFP RCTX with EL = 0b11 (EL3) after a firmware update, intending to clear EL3’s predictions. What happens?

  • A. EL3’s control-flow predictions are restricted on this PE after DSB+ISB
  • B. The instruction traps to EL3, which performs it on the kernel’s behalf
  • C. EL3’s predictions are restricted on all PEs in the Inner Shareable domain
  • D. It executes as a NOP, because a lower EL cannot target a higher EL’s context
Answer

D. RCTX executed at an EL below the target EL is treated as a NOP. Only EL3 can clean up for EL3, for example as part of its own activation sequence. A is what the kernel intended. C is wrong twice: there is no broadcast form, and the instruction would not target EL3 from EL1 in any case.

Read more: Arm ARM (DDI0487), CFP RCTX, Control Flow Prediction Restriction by Context

14.8 Exercises: auditing for missing mitigations

These exercises practise the review questions from 14.1 on code you are likely to meet in EL3 and Secure-world firmware. For each one, decide what the attacker controls, which variant applies, what the fix is, and how you would show that the fix matters. Answers are collapsed. Try each before opening it.

Use this checklist for all of them:

QuestionVariantWhere the fix lives
Is there an indirect branch reachable from a lower-EL entry before any prediction mitigation?v2, BHB14.4
Is an attacker-supplied value bounds-checked by a branch and then used to form an address?v114.3
Is a sanitised value written over an attacker value in memory and then reloaded?v414.5
Can code fall through an ERET, RET or BR into bytes that load?SLS14.2
Is a context identity (ASID, VMID, image slot) reused for a new owner?Prediction residue14.7
Does secret-dependent work rely on a PSTATE bit (SSBS, DIT) that someone else could have left in the wrong state?v4 / timing14.5, 14.6

Exercise 1: an EL3 vector

The platform’s core reports CSV2 = 1, CSV3 = 1, SSBS = 0 (not implemented), ECBHB = 0 and CLRBHB = 0. Its security bulletin lists it as affected by Spectre-BHB, with a branch-loop count k given in the TRM, and by Spectre v4, with an IMPLEMENTATION DEFINED “disable load pass store” bit that the platform uses dynamically. Audit this lower-EL AArch64 synchronous vector and the exit path:

    .balign 0x80
lower_el_sync_a64:                         // VBAR_EL3 + 0x400
    stp     x29, x30, [sp, #CTX_X29]
    mrs     x30, esr_el3
    ubfx    x30, x30, #26, #6              // EC
    cmp     x30, #0x17                     // SMC from AArch64?
    b.ne    1f
    ldr     x30, =smc_dispatch
    br      x30
1:  b       handle_other_sync

    // ...

el3_exit:
    bl      restore_gp_regs                // x0-x30 from context
    eret
    .ltorg                                 // literal pool follows

And in the reset code:

    mov_imm x0, (SCTLR_EL3_RES1 | SCTLR_I_BIT | SCTLR_SA_BIT | SCTLR_DSSBS_BIT)
    msr     sctlr_el3, x0
Answer

There are four problems, plus one non-problem.

  1. Indirect branch before BHB mitigation (Spectre-BHB). br x30 is the first indirect branch after entry from Non-secure EL1. On an affected core without ECBHB, the branch history built up by the Non-secure world selects its predicted target. CSV2 = 1 does not help, because CSV2 covers branch targets trained in another context, while BHB attacks steer selection by history. That is why CSV2_3 exists. Fixes: put the k-iteration branch loop (or CLRBHB where implemented, or rely on ECBHB) at the very top of every lower-EL vector entry, before any indirect branch. Better still, remove the indirect branch: b smc_dispatch reaches the same place, because the target is a link-time constant. The ldr =/br pair exists only for range, and a direct B covers ±128 MB.
  2. No v4 mitigation on entry. With dynamic WORKAROUND_2, the “disable load pass store” bit must be set on every lower-EL entry and restored to the caller’s requested state on exit (14.5). This vector does neither. EL3 runs with whatever the Non-secure kernel last asked for, and its context save (spill and reload of attacker-chosen x0–x7) is the shape of a v4 gadget.
  3. SLS after ERET. The literal pool follows the ERET directly. If the front end speculates straight past the ERET, it decodes pool constants as instructions, possibly including loads. Add sb (FEAT_SB) or dsb nsh; isb straight after the ERET, as TF-A’s exception_return macro does.
  4. No BHB mitigation on the path used by SMCCC_ARCH_WORKAROUND_3 discovery. If firmware answers SMCCC_ARCH_FEATURES(WORKAROUND_3) with 0 but the vectors do not actually run the loop, Linux trusts the answer and drops its own mitigation for calls into EL3. Check that the discovery answer and the vector code come from the same build flag (TF-A: WORKAROUND_CVE_2022_23960).

Non-problem: SCTLR_DSSBS_BIT in the SCTLR_EL3 value. On a core without FEAT_SSBS, SCTLR_EL3.DSSBS is RES0, so the bit does nothing. It is still a latent bug: the same code on a later core with SSBS would make EL3 run with SSBS=1, mitigation off. Clear it, as TF-A does.

How to show the fixes matter: on silicon, train the BHB from Non-secure EL1 with a branch pattern that ends in a call to a chosen gadget address, issue SMC, and look for a probe-array fill. Repeat with the loop enabled. PMU events BR_MIS_PRED and L1D_CACHE_REFILL counted around the SMC make the before/after difference visible without fine-grained timing.

Exercise 2: an SMC handler in C

typedef uint64_t (*svc_fn)(uint64_t, uint64_t);
static const svc_fn svc_table[NUM_SVCS];        /* NUM_SVCS = 11 */
static const uint8_t key[32];                   /* Secure */
static const uint8_t sbox[256];

uint64_t smc_handler(uint32_t fid, uint64_t x1, uint64_t x2)
{
    uint32_t idx = fid & 0xffff;
    if (idx >= NUM_SVCS)
        return SMC_UNK;
    return svc_table[idx](x1, x2);
}

static uint64_t svc_key_check(uint64_t i, uint64_t guess)
{
    if (i >= sizeof(key))
        return SMC_INVALID_PARAM;
    return sbox[key[i] ^ (uint8_t)guess] == 0;
}
Answer
  1. svc_table[idx] is v1 feeding an indirect call. The Non-secure caller trains idx >= NUM_SVCS as not taken with valid FIDs, then passes idx = 1000. The CPU speculatively loads a “function pointer” from svc_table + 8000, which is whatever EL3 data sits there, and branches to it speculatively with attacker-chosen x1/x2. This is worse than a plain v1 leak, because it gives the attacker a speculative jump to a location determined by EL3 memory contents. Fix: clamp the index without a branch the CPU can predict.
static inline uint64_t index_nospec(uint64_t idx, uint64_t size)
{
    uint64_t safe;
    asm volatile("cmp   %1, %2\n"
                 "csel  %0, %1, xzr, lo\n"
                 "csdb\n"
                 : "=r"(safe) : "r"(idx), "r"(size) : "cc");
    return safe;
}
    ...
    idx = index_nospec(idx, NUM_SVCS);

An alternative is to make the table size a power of two (16, padding the extra entries with an “unknown” handler) and use idx & 15. Then there is no bounds check to bypass, and TF-A’s runtime-service lookup uses the same idea (14.3).

  1. svc_key_check has the same v1 shape, key[i] followed by sbox[...], so it needs the same clamp on i. But it also leaks without any speculation. sbox[key[i] ^ guess] is an architecturally executed, secret-indexed load. Its cache footprint reveals key[i] ^ guess, so an attacker who can run Prime+Probe on a shared cache recovers the key byte by byte. Neither CSDB nor PSTATE.DIT fixes this. DIT makes the data timing of individual instructions constant; it does not make an address constant (14.6). The fix is algorithmic: compare in constant time without a table, or touch every table entry.

  2. Not a problem: fid & 0xffff is not a mitigation, but it is not a bug either. It just narrows the range before the check.

Exercise 3: spot the gadget

For each snippet, say whether there is an exploitable speculation or timing issue. If there is, name it and give the minimal fix. Assume Secure EL1 or EL3 code, with x0–x3 controlled by the Non-secure caller unless stated otherwise.

Snippet A

    cmp     x1, #64
    b.hs    out
    ldrb    w2, [x10, x1]          // x10: Secure buffer
    ldrb    w3, [x11, x2, lsl #6]  // x11: any buffer

Snippet B

    cmp     x1, #64
    csel    x1, x1, xzr, lo
    ldrb    w2, [x10, x1]
    ldrb    w3, [x11, x2, lsl #6]

Snippet C

    ubfx    x1, x0, #24, #4        // 4-bit field
    adr     x9, handlers           // 16 entries, all valid
    ldr     x9, [x9, x1, lsl #3]
    blr     x9

Snippet D

/* Secure partition manager, per-call */
ctx->arg_len = regs->x2;                    /* raw, saved for tracing   */
ctx->arg_len = MIN(regs->x2, MAX_LEN);      /* sanitised, same field    */
memcpy_from_ns(buf, regs->x1, ctx->arg_len);
val = lookup[buf[ctx->arg_len - 1]];        /* reload of arg_len        */

Snippet E

/* SPMC: restart a crashed partition */
void sp_restart(struct sp *sp)
{
    load_image(sp);                 /* same memory, same VMID */
    tlbi_vmalls12e1_for(sp->vmid);  /* TLBI VMALLS12E1IS; DSB ISH */
    sp_enter(sp);
}

Snippet F

el3_cold_boot:
    mov     x0, #DIT_BIT
    msr     dit, x0                // "constant-time crypto from here on"
    ...
lower_el_sync_a64:
    // ... save context, no DIT write ...
    bl      ecdsa_sign_with_hw_key
Answer

A: Spectre v1. This is the textbook shape: a predicted-not-taken b.hs, then a load indexed by x1 followed by a load indexed by the result. Fix: csel x1, x1, xzr, lo followed by csdb before the first load, or an SB after the branch where its cost is acceptable.

B: still v1, because the CSDB is missing. The CSEL looks like a mask, but without CSDB the architecture lets the PE use a predicted NZCV value (or a predicted data value) for the CSEL result. Speculatively, x1 can still be 1000. The guarantee comes from CSDB: later instructions, other than branches, cannot use unresolved NZCV or data-value predictions from before it. Add csdb after the CSEL. On a core that does not predict flags it costs nothing, and on one that does it is the fix.

C: no gadget. The index is bounded by construction (ubfx gives 0–15), every entry is a valid handler, and no conditional branch exists to mispredict. The blr is an indirect branch, so v2 and BHB still apply at the vector level (Exercise 1), but there is no v1 here. The lesson is to recognise this pattern as safe rather than adding CSDB everywhere.

D: Spectre v4. The raw x2 is stored, then overwritten with the clamped value at the same address, then reloaded. If the sanitising store’s address resolves late (for example ctx came from a cache-missing load), the reload can bypass it and transiently see the raw length. buf[len - 1] then indexes far outside buf, and lookup[...] turns the byte into a cache fill. Fixes, best first: keep the sanitised value in a register and do not reload it, or store the raw value in a different field. If the reload must stay, put ssbb between store and reload, or run the partition manager with PSTATE.SSBS = 0 (or the static chicken bit on pre-SSBS cores). The memcpy_from_ns also needs the clamp itself to be CSDB-safe if MIN compiles to a branch.

E: prediction residue on identity reuse. The new instance has the same Security state, EL and VMID as the old one, so CSV2 sees one context, and predictions the crashed (possibly compromised) instance trained remain usable. TLB maintenance has no effect on predictors. Fix: on each PE that ran the old instance, CFP/DVP/CPP RCTX (and COSP with SPECRES2) with the VMID, EL = EL1 and EL0, NS = 0, then DSB and ISB. Alternatively, give the restarted instance a fresh VMID and retire the old one until the next roll-over cleanup (14.7).

F: not speculation, but a real timing bug. PSTATE.DIT is a PSTATE bit. It is saved to SPSR_EL3 and restored by every ERET, and exception entry does not change it. After the first return to the Non-secure world, each SMC enters EL3 with the caller’s DIT value, typically 0, so the signing code runs without the data-independent-timing guarantee. Fix: msr dit, #1 on every EL3 entry, before any secret-dependent work, as TF-A’s ENABLE_FEAT_DIT entry code does (14.6).

Validation note: An audit finding becomes a validated finding only when you can show the signal with the mitigation removed. For each fix above, keep a directed test with a build switch that disables it. The test must give a probe-array signal (or, for D, a replay-count increase) with the switch off, and none with the switch on. Count INST_SPEC against INST_RETIRED to show the transient window opened, BR_MIS_PRED to show the training took effect, and L1D_CACHE_REFILL on the probe array (16.5). Run on silicon or cycle-accurate RTL, because FVP and QEMU model none of this. For E and F, an architectural test is enough to prove the precondition. For F, read MRS x0, DIT in the EL3 handler after entry from an EL1 that cleared DIT. For E, check that the restart path executes the RCTX instructions on every PE (a Tarmac trace on FVP shows them).

Checkpoint

Q14.8.1 A reviewer proposes adding CSDB after every indirect branch in EL3 “to stop Spectre”. Which statement best explains why this is the wrong fix?

  • A. CSDB is a NOP on all cores and has no effect anywhere
  • B. CSDB restricts the use of predicted NZCV and data values by later non-branch instructions. It does not constrain where an indirect branch is predicted to go, which is the v2/BHB problem
  • C. CSDB only works at EL0
  • D. CSDB must be placed before the branch, not after
Answer

B. Each variant has its own fix. Branch-target and history injection are handled by CSV2/CSV2_3, by vector-entry BHB sequences and WORKAROUND_1/3, or by removing the indirect branch. CSDB is a v1 tool used with CSEL masks. A is the tempting answer, because CSDB is a HINT that older cores treat as a NOP, but on cores with flag or data-value prediction it has defined semantics.

Read more: Arm ARM (DDI0487), CSDB; Restrictions on the effects of speculation

Q14.8.2 Firmware answers SMCCC_ARCH_FEATURES(SMCCC_ARCH_WORKAROUND_3) with 0, but a build-flag mismatch left the BHB loop out of the EL3 vectors. What is the consequence for a Linux kernel on an affected core?

  • A. None. Linux always runs its own BHB loop before an SMC
  • B. Linux detects the mismatch through ID_AA64MMFR1_EL1.ECBHB and falls back
  • C. Linux treats firmware as mitigated and may rely on the WORKAROUND_3 call for its own entry. EL3 entries are then unprotected, and Linux’s mitigation may also be incomplete
  • D. The SMC is rejected with NOT_SUPPORTED at run time
Answer

C. Discovery is a promise that the lower EL takes at face value. Nothing in the architecture checks it. ECBHB describes the hardware, not the firmware, so it cannot detect the gap. That is why the audit must tie the discovery answer and the vector code to one build flag, and why validation must test with the mitigation compiled out.

Read more: Arm, Firmware interfaces for mitigating cache speculation vulnerabilities (SMCCC_ARCH_WORKAROUND_3)

Q14.8.3 Of the following EL3 sequences, which one needs no additional speculation mitigation for v1, given that x0 is attacker-controlled?

  • A. and x1, x0, #7 then ldr x2, [x9, x1, lsl #3] into an 8-entry table, then ldrb w3, [x10, x2]
  • B. cmp x0, #8; b.hs 1f; ldr x2, [x9, x0, lsl #3]; ldrb w3, [x10, x2]
  • C. cmp x0, #8; csel x1, x0, xzr, lo; ldr x2, [x9, x1, lsl #3]; ldrb w3, [x10, x2]
  • D. cmp x0, #8; b.hs 1f; dmb ish; ldr x2, [x9, x0, lsl #3]; ldrb w3, [x10, x2]
Answer

A. The AND bounds the index by data dependency, with no prediction involved, so every speculative value is in range. B is the plain gadget. C is the tempting answer, but it lacks the CSDB that stops a predicted NZCV from feeding the CSEL. In D, a DMB orders observation and has no speculation semantics.

Read more: Arm ARM (DDI0487), CSDB; Arm, Cache Speculation Side-channels whitepaper

Part 15: SIMD, FP, SVE and SME

Prerequisites: 2.4 PSTATE, 2.6 The trap-control map, 3.2 Entry and return, 7.8 Context synchronization and ISB. If you already know: how Neon/FP context switching and CPACR_EL1.FPEN work, skim 15.1 but read its Security note. If you know SVE as a programming model, skip to the ZCR_ELx and SME parts of 15.2. Read 15.3 in full whatever you know. Why this matters for bring-up/validation: every vector feature is trapped by EL3 until it is enabled, and one register file is shared by all worlds, so a missing enable bit or a narrow save policy shows up as boot-time traps to EL3 or as silently corrupted state in another world.

The storyline runs from small state to large state. 15.1 covers the base case: 32 128-bit V registers, FPCR/FPSR, and the CPACR_EL1/CPTR_ELx traps that let an OS or hypervisor switch FP state lazily, together with the cross-world hazard that lazy switching creates. 15.2 widens the registers. SVE makes the vector length an implementation choice capped by ZCR_ELx. SME adds Streaming SVE mode with its own vector length, the ZA matrix array and SME2’s ZT0, and SVCR changes have side effects that zero registers. TPIDR2_EL0 supports a lazy ZA-save ABI, and FP8 adds the FPMR register. Each of these brings new state and a new enable bit.

15.3 is the firmware view. It covers what EL3 and an unused EL2 must program, in what order (CPTR_EL3.EZ/ESM before ZCR_EL3/SMCR_EL3; SCR_EL3.EnTP2/EnFPM per world), and how TF-A splits per-world state from per-CPU state. It also covers which build options decide who saves what, why PSTATE.SM and ZA cross a world switch unchanged, and what each missing bit looks like in a crash dump.

15.1 Advanced SIMD and FP

In AArch64, floating-point and Advanced SIMD (Neon) are one register file, one pair of control/status registers and one set of trap controls. The architecture lets ID_AA64PFR0_EL1 report them as absent, but they are implemented together or not at all, and every Arm-designed A-profile core and every OS ABI for general-purpose software assumes them. Firmware cares about three things here: where the state lives, what controls its behaviour, and how the trap controls let software (an OS, a hypervisor or EL3) defer saving it.

The register file

There are 32 registers, V0–V31, each 128 bits wide. The register name chooses how many low-order bits an instruction accesses:

NameWidthTypical use
Bn8Scalar byte (SIMD scalar ops)
Hn16Half-precision (FEAT_FP16) or BFloat16 scalar
Sn32Single precision
Dn64Double precision, or a 64-bit vector (Vn.8B, Vn.4H, Vn.2S)
Qn128Full 128-bit vector (Vn.16B, Vn.8H, Vn.4S, Vn.2D)

A write to a scalar view zeroes the rest of the 128-bit register: FMOV S0, W1 clears bits [127:32] of V0. It does not merge with them, as AArch32 did with S0/S1 packed in D0. When SVE is implemented, Vn is the low 128 bits of Zn, and an Advanced SIMD or FP write zeroes the bits of Zn above bit 127 as well (15.2). That zeroing is what makes FP context handling and SVE context handling inseparable.

The minimum context for a thread or world is therefore 32 × 16 = 512 bytes of vector state plus FPCR and FPSR. For an AArch32 EL1 or EL0, add FPEXC32_EL2. TF-A’s simd_regs_t (in include/lib/el3_runtime/simd_ctx.h) has that layout when CTX_INCLUDE_FPREGS=1 and SVE context is not included, with FPSR and FPCR each in an 8-byte slot (528 bytes before the AArch32 extras).

Under AAPCS64, the low 64 bits of V8–V15 are callee-saved and everything else is caller-saved (2.2). Exception entry saves no FP state. If any code between the vector and the ERET may touch the registers, the handler must save them itself, or arrange for that code never to touch them.

FPCR: control

FPCR is accessed with MRS/MSR FPCR and is readable and writable at EL0. Its main fields:

FieldBitsMeaning
AHP26Alternative half-precision format (no infinities or NaNs) for FP16 conversions
DN25Default NaN: NaN results are the default NaN instead of propagating the input payload
FZ24Flush denormal inputs and outputs to zero (single and double precision)
RMode23:22Rounding: 00 RN (nearest), 01 RP (towards +inf), 10 RM (towards -inf), 11 RZ
FZ1619Flush-to-zero for half precision (FEAT_FP16)
IDE, IXE, UFE, OFE, DZE, IOE15, 12–8Trap enables for input-denormal, inexact, underflow, overflow, divide-by-zero, invalid
EBF13Extended BFloat16 behaviour (FEAT_EBF16)
NEP, AH, FIZ2, 1, 0FEAT_AFP: output element preservation for scalar ops, alternate (x86-compatible) handling, flush inputs to zero

Bits [21:20] and [18:16] (Stride, Len) exist only for AArch32 compatibility. Two points are commonly misremembered:

  • Floating-point exception trapping is optional. Whether the trap-enable bits are implemented is IMPLEMENTATION DEFINED. If they are not, they are RAZ/WI, and software has to write a 1 and read the bit back to find out. When they are implemented and enabled, an FP exception is taken as a synchronous exception with EC 0x2C (AArch64) or 0x28 (AArch32). Most Cortex and Neoverse cores do not implement it, so the cumulative flags in FPSR are the only reporting mechanism.
  • FPCR is part of the thread context. An exception handler that changes the rounding mode or FZ and does not restore them silently changes the numerics of the interrupted code.

FPSR: status

FPSR holds the cumulative (sticky) exception flags: IOC (bit 0), DZC (1), OFC (2), UFC (3), IXC (4), IDC (7), and QC (bit 27), the Advanced SIMD saturation flag. Bits [31:28] (N, Z, C, V) are used only by AArch32 VMRS APSR_nzcv. In AArch64, FP compares write PSTATE.NZCV directly. The flags are sticky: hardware sets them and only software clears them. They therefore show whether anything since the last clear raised the condition, which makes them useful as cheap test oracles.

Discovery

ID_AA64PFR0_EL1.FP (bits [19:16]) and .AdvSIMD (bits [23:20]) are signed fields: 0b0000 means implemented, 0b0001 means implemented with half-precision arithmetic (FEAT_FP16, permitted from v8.2), and 0b1111 means not implemented. The many optional extensions to the instruction set (FEAT_DotProd, FEAT_FHM, FEAT_FCMA, FEAT_JSCVT, FEAT_BF16, FEAT_I8MM, FEAT_FRINTTS, FEAT_AFP, FEAT_RPRES and others) are reported in ID_AA64ISAR0_EL1/ISAR1_EL1. None of them adds architectural state except FEAT_AFP and FEAT_EBF16, which add the FPCR bits above. Their version information is in Appendix A.

The trap controls

Each Exception level above EL0 can trap FP/SIMD use at the levels below it, and in some cases at its own level:

ControlTrapsEncoding
CPACR_EL1.FPEN [21:20]EL0 and EL1 to EL1 (no effect when HCR_EL2.{E2H,TGE}={1,1}; CPTR_EL2.FPEN then controls EL0)0b00/0b10: trap EL0 and EL1; 0b01: trap EL0 only; 0b11: no trap
CPTR_EL2.TFP bit 10 (E2H=0)EL0, EL1 and EL2 to EL21 traps
CPTR_EL2.FPEN [21:20] (E2H=1)EL0, EL1 and EL2 to EL20b00/0b10: trap EL0, EL1 and EL2; 0b01: trap EL0 only when HCR_EL2.TGE=1, otherwise no trap; 0b11: no trap
CPTR_EL3.TFP bit 10All ELs to EL31 traps

A trapped instruction, or a trapped access to FPCR/FPSR, is reported with EC 0x07. For a trap at EL2 or EL1 the ISS gives no further detail in AArch64. At EL3 a trapped FP access appears to the monitor as an exception from whatever world was running, and TF-A’s default handling of an unexpected EC 0x07 is a panic.

The register-by-register overview is in 2.6. EL3 programming is in 15.3.

Bring-up note: CPACR_EL1 and CPTR_ELx are system registers. After an MSR that removes a trap, the change is only guaranteed to affect later instructions after a context synchronization event, so an ISB must come before the first FP instruction (7.8). Compilers also emit FP/SIMD instructions for plain C, such as memcpy/memset expansion, struct copies and vectorised loops. Firmware that runs with FP trapped must be built with -mgeneral-regs-only (TF-A does this). If an early-boot C function suddenly takes EC 0x07, the most likely cause is a new compiler or a missing flag, not the hardware.

Lazy context switching

FP state is large compared with the integer context and many threads never touch it. The traps above let a kernel or hypervisor defer the save and restore:

  1. On a context switch, leave the outgoing thread’s FP state in the registers and record that the registers hold thread A’s state. Set the trap (FPEN = 0b01 or 0b00).
  2. If thread B executes an FP instruction, it takes EC 0x07. The handler saves the registers into A’s context, loads B’s context, records B as the owner, clears the trap and returns to re-execute the faulting instruction. Because the exception is synchronous and precise, no partial state exists.
  3. If B never touches FP, nothing is saved or restored, and A finds its state intact if it is scheduled again on the same CPU.

The bookkeeping that matters is “which context currently owns this CPU’s registers” (per CPU) and “is this context’s state live in some CPU’s registers” (per context). Migration of a thread to another CPU, and power-down of a CPU (8.8, 17.4), must force the save first, because the registers are lost.

Real systems use variants of this scheme:

  • Linux arm64 now restores FP state lazily on the return to user space (a per-task “foreign FP state” flag), not on a trap. It uses trap-on-first-use only to detect when a task first uses SVE or SME, so that the larger buffers are allocated on demand.
  • KVM keeps the guest’s FP/SIMD trapped on entry and switches host and guest state on the first guest FP trap. This is the classic trap-based form, because many exits never touch FP.
  • TF-A does not switch lazily. With CTX_INCLUDE_FPREGS=1 it saves and restores eagerly on world switch. By default it saves nothing and relies on the secure world not touching the registers (15.3).

Security note: Lazy switching leaves another context’s values in the registers. That is safe only while the trap reliably fires before any read. Two classes of bug recur. The first is a trap window: code at a higher EL, or a different world, uses FP without saving first. Neither CPACR_EL1 nor the lower EL’s lazy state machine traps EL3, so an EL3 or S-EL1 service that uses Neon for crypto leaks or corrupts the Normal-world state unless it saves and restores. The second is speculative reads of trapped state. That issue was disclosed for another architecture in 2018 as “Lazy FP state restore” (CVE-2018-3665). Check the core’s security advisories before relying on lazy switching across a trust boundary. For a cross-world boundary, eager save/restore or zeroing is the defensible default.

Checkpoint

Q15.1.1 An OS uses trap-based lazy FP switching with CPACR_EL1.FPEN=0b01 for user threads. A secure-world service at S-EL1 called through EL3 uses Neon for AES and does not save the registers. TF-A is built with CTX_INCLUDE_FPREGS=0. What happens to a Normal-world user thread whose FP state was live in the registers?

  • A. Nothing, because the S-EL1 FP instructions take an EC 0x07 trap to the Normal-world kernel, which saves the state first
  • B. Nothing, because CPACR_EL1 is banked per Security state and the Secure copy traps the access to EL3
  • C. Its FP state is silently corrupted, because no Normal-world trap applies to S-EL1 execution and nobody saved the registers
  • D. The S-EL1 access faults with EC 0x07 to S-EL1, because FPEN=0b01 traps EL0 and EL1
Answer

C. The register file is shared by all worlds. The Normal-world CPACR_EL1 value does not apply while S-EL1 runs: EL3 switches the EL1 system registers, so S-EL1 runs with its own CPACR_EL1 value. No trap returns control to the Normal-world kernel. Unless EL3 saves FP state per world, or the S-EL1 code saves what it overwrites, the Normal-world values are lost. A is the tempting answer, but a trap is always taken to the controlling EL of the regime that is executing, never to another world’s kernel. D misreads 0b01, which traps EL0 only.

Read more: Arm ARM (DDI0487), CPACR_EL1, CPTR_EL3; TF-A build options, CTX_INCLUDE_FPREGS

Q15.1.2 A test writes 1 to FPCR.IOE, executes FDIV of 0.0 by 0.0, and expects an EC 0x2C exception. None is taken, but FPSR.IOC reads 1. What is the most likely explanation?

  • A. The implementation does not support FP exception trapping, so IOE is RAZ/WI; reading FPCR back would show 0
  • B. An ISB was missing between the MSR FPCR and the FDIV, so the old trap-enable value was used
  • C. EC 0x2C traps are taken only when CPTR_EL3.TFP=1
  • D. 0.0/0.0 raises divide-by-zero, not invalid operation, so DZE should have been set
Answer

A. Support for FP exception trapping is IMPLEMENTATION DEFINED, and most Arm-designed cores do not implement it. The enable bits then read as zero and writes are ignored, so only the sticky FPSR flag records the event. Reading the register back is the standard detection method. D is wrong because 0/0 is an invalid operation (it yields a NaN); DZC is for a finite non-zero value divided by zero. C confuses the access trap (EC 0x07) with the FP exception trap. B is wrong because FPCR is a special-purpose register, not a System register that needs an ISB: an MSR FPCR affects the following instructions directly.

Read more: Arm ARM (DDI0487), FPCR, FPSR, Floating-point exceptions and exception traps

Q15.1.3 SVE is implemented with a 256-bit vector length. A Normal-world thread holds live data in Z0[255:128]. A secure service, allowed to use FP but not SVE, executes MOV V0.16B, V1.16B and then restores the low 128 bits of V0 exactly. What does the Normal-world thread observe?

  • A. All 256 bits intact, because the restore puts V0 back
  • B. All bits intact, because SVE state is banked between Security states
  • C. An EC 0x19 trap when the secure service executes the Advanced SIMD instruction, because SVE is disabled for it
  • D. Z0[255:128] reads as zero, because an Advanced SIMD write zeroes the bits of Z0 above bit 127
Answer

D. V0 is the low 128 bits of Z0, and any Advanced SIMD or FP write zeroes the higher bits. Saving and restoring only the 128-bit view does not preserve SVE state. This is why TF-A requires CTX_INCLUDE_SVE_REGS when CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS are both set. C is wrong because Advanced SIMD instructions are governed by the FP controls, not the SVE ones, even when SVE is trapped.

Read more: Arm ARM (DDI0487), The Scalable Vector Extension, SVE registers (relationship of Z and V registers); TF-A build options, CTX_INCLUDE_SVE_REGS

15.2 SVE, SVE2 and SME

For firmware, what SVE and SME change most is the size and shape of the register state, and the number of controls that must be set before any of it is usable. This section gives the state and the controls precisely. The instruction-set content is covered only as far as it affects state. EL3 programming is in 15.3.

SVE state

RegisterCountSizeNotes
Z0–Z3132VL bitsVn is the low 128 bits of Zn
P0–P1516VL/8 bitsOne bit per byte of a Z register
FFR1VL/8 bitsFirst-fault register, written by first-fault and non-fault loads (LDFF1*, LDNF1*)

The vector length (VL) is chosen by the implementation. The current ARM ARM permits any power of two from 128 to 2048 bits, and an implementation may support only a subset of those lengths. Early issues allowed any multiple of 128. Arm later restricted the rule, so old documents and old asserts (TF-A still checks SVE_VECTOR_LEN % 128) reflect the looser wording.

At the maximum VL, the non-streaming SVE context is 32 × 256 + 17 × 32 = 8736 bytes, against just over 512 bytes for FP/SIMD alone.

Vector-length agnosticism. Code does not hard-code VL. It reads VL with RDVL/CNTB/CNTW and drives loops with predicates, so the same binary runs on any VL:

// x0 = dst, x1 = src, x2 = n (number of 32-bit elements)
    mov     x3, #0
    whilelo p0.s, x3, x2            // p0 = lanes with x3+i < n
1:  ld1w    {z0.s}, p0/z, [x1, x3, lsl #2]
    add     z0.s, z0.s, #1
    st1w    {z0.s}, p0, [x0, x3, lsl #2]
    incw    x3                      // x3 += number of 32-bit lanes in VL
    whilelo p0.s, x3, x2
    b.first 1b                      // loop while the first lane is active

The tail is handled by the predicate, so the loop needs no scalar epilogue. Software that saves state must also be VL-agnostic: a context buffer sized at build time for 128-bit vectors is overrun on a 256-bit part.

Controlling VL: ZCR_ELx. ZCR_EL1, ZCR_EL2 and ZCR_EL3 each have a LEN field in bits [3:0] that requests VL = (LEN+1) × 128 bits. The effective VL at an Exception level is limited by the ZCR of that level and of every higher implemented and enabled level. The PE then uses the largest supported length that does not exceed the result. So ZCR_EL3 caps everything, and EL2 caps its guests. When the effective VL shrinks and later grows again, the ARM ARM does not guarantee that the bits that became inaccessible were preserved (see the ZCR_EL1 description). This matters to any code that changes LEN while live state is held at the old length.

Discovery and versions. ID_AA64PFR0_EL1.SVE (bits [35:32]) reports SVE. ID_AA64ZFR0_EL1.SVEver (bits [3:0]) distinguishes SVE (0b0000), SVE2 (0b0001), SVE2.1 (0b0010) and SVE2.2 (0b0011). The rest of ID_AA64ZFR0_EL1 reports the optional instruction groups. FEAT_SVE is permitted from v8.2. Current DDI0487 issues list FEAT_SVE2 as OPTIONAL from v9.0, even though toolchains treat it as part of -march=armv9-a; only SVEver is authoritative (1.2).

Traps. SVE instructions, and accesses to ZCR_ELx, are controlled by CPACR_EL1.ZEN [17:16] (same encoding as FPEN), CPTR_EL2.TZ bit 8 (or ZEN when E2H=1), and CPTR_EL3.EZ bit 8. EZ is an enable, so 0 traps. An SVE access trap is reported with EC 0x19. SVE instructions are also subject to the FP controls. The ARM ARM pseudocode for the SVE enable check tests the controls from the lowest Exception level upwards, and at each level tests the SVE control before the FP one. A guest with both traps set at EL1 therefore takes EC 0x19, not 0x07.

SME: Streaming SVE mode and ZA

SME adds two independent pieces of state, each with its own enable in PSTATE:

  • PSTATE.SM, Streaming SVE mode. SVE instructions execute at the streaming vector length (SVL), set by SMCR_ELx.LEN, which may differ from the non-streaming VL. The Z and P registers (and FFR, which is accessible only when FA64 is enabled) take the SVL in this mode. Streaming mode is designed for a separate, wide matrix unit that may be shared between cores. Many instructions that suit a latency-oriented core are therefore illegal in streaming mode: most Advanced SIMD vector instructions, SVE gather/scatter, and the first-fault loads that use FFR. Executing one is reported with EC 0x1D, ISS.SMTC=1, unless FEAT_SME_FA64 is implemented (ID_AA64SMFR0_EL1.FA64, bit 63) and enabled by SMCR_ELx.FA64.
  • PSTATE.ZA, the ZA array. ZA is a two-dimensional SVL/8 × SVL/8-byte array, accessed as tiles (ZA0.S–ZA3.S, and so on) or as horizontal and vertical slices. It is the accumulator for outer-product instructions such as FMOPA. At SVL = 512 bits it is 4 KiB; at SVL = 2048 bits it is 64 KiB.

Both live in SVCR (SM is bit 0, ZA is bit 1). They are changed by MSR SVCRSM, #imm, MSR SVCRZA, #imm and MSR SVCRSMZA, #imm, whose preferred aliases are SMSTART/SMSTOP with an optional SM or ZA operand. The architectural side effects are the part firmware must know:

EventEffect
PSTATE.SM changes (either direction)All implemented bits of Z0–Z31, P0–P15 and FFR are set to zero. FPMR is set to zero. FPSR is set to 0x0800_009F (all cumulative flags set). ZA and ZT0 are not affected.
PSTATE.ZA 0 → 1ZA (and ZT0) are set to zero
PSTATE.ZA 1 → 0ZA contents are lost
Exception entry or returnNo change. SM and ZA are not in SPSR, so a handler runs in whatever mode the interrupted code was in.

The last row has consequences at every EL. An EL1 or EL3 handler entered from streaming code that executes an Advanced SIMD instruction, for example in a context-save routine, takes an illegal-in-streaming-mode trap. A save routine running in streaming mode sees Z and P at the SVL, not the VL. Any code that saves vector state must read SVCR first and act on it, or execute SMSTOP SM, which destroys the Z state unless it has been saved first.

SME controls. SMCR_EL1/SMCR_EL2/SMCR_EL3 contain LEN [3:0] (SVL request, capped by higher ELs as for ZCR), FA64 (bit 31) and EZT0 (bit 30, SME2). Traps are CPACR_EL1.SMEN [25:24], CPTR_EL2.TSM bit 12 (or SMEN when E2H=1), and CPTR_EL3.ESM bit 12 (an enable). SVE instructions executed in streaming mode are controlled by these SME controls, not by ZEN/TZ/EZ. The FP controls still apply. The trap codes in ESR_ELx.ISS.SMTC for EC 0x1D are:

SMTCCause
0Trapped by SMEN/TSM/ESM
1Instruction illegal in Streaming SVE mode
2Instruction requires PSTATE.SM=1 and it is 0
3Instruction accesses ZA and PSTATE.ZA=0
4Instruction accesses ZT0 and the applicable SMCR_ELx.EZT0=0

Discovery is ID_AA64PFR1_EL1.SME (bits [27:24]: 0b0001 SME, 0b0010 SME2) and ID_AA64SMFR0_EL1, whose SMEver field (bits [59:56]) distinguishes SME, SME2, SME2.1 and SME2.2 and whose other fields list the supported data types. Both FEAT_SME and FEAT_SME2 are optional from v9.2 (see DDI0487 A2).

TPIDR2_EL0 and the lazy ZA save ABI

ZA can be tens of kilobytes, so the procedure-call standard avoids saving it on every call. TPIDR2_EL0 is an EL0-accessible register reserved for this protocol. In the AAPCS64 SME support, ZA is in one of three states:

  • off: PSTATE.ZA=0;
  • active: PSTATE.ZA=1 and TPIDR2_EL0 is null; the current function owns the contents;
  • dormant: PSTATE.ZA=1 and TPIDR2_EL0 points to a 16-byte TPIDR2 block (za_save_buffer pointer, a 16-bit num_za_save_slices, reserved bytes). The contents belong to a caller and have not yet been saved.

A caller with live ZA that calls a function which does not share ZA sets up the block and makes ZA dormant. A callee that wants ZA checks TPIDR2_EL0. If it is non-null, the callee calls __arm_tpidr2_save, which stores ZA into the caller’s buffer, and then sets TPIDR2_EL0 to null itself (the support routine does not clear it). The callee then owns ZA. After the call, the caller turns ZA back on if necessary and checks TPIDR2_EL0. If it is null, a save happened, and the caller calls __arm_tpidr2_restore. If the callee never used ZA, no save or restore happens at all.

For system software TPIDR2_EL0 is per-thread state, like TPIDR_EL0. EL0 access is enabled by SCTLR_EL1.EnTP2 (bit 60), or SCTLR_EL2.EnTP2 in the EL2&0 regime, and lower-EL access by SCR_EL3.EnTP2 (bit 41). When these are clear, accesses trap with EC 0x18. An OS must save and restore TPIDR2_EL0 on context switch, and it has to define what signal handlers see. Linux saves the SME state in the signal frame and enters the handler with Streaming SVE mode and ZA disabled. Its treatment of TPIDR2_EL0 at signal entry has changed between kernel versions, so check Documentation/arch/arm64/sme.rst for the version you run.

SME2, ZT0 and SME without SVE

SME2 adds multi-vector instructions that operate on groups of two or four consecutive Z registers. ZA can also be addressed as groups of vectors, which allows multi-vector accumulation into ZA without outer products. SME2 adds predicate-as-counter encodings (PN8–PN15, a compact way to express “the first n lanes” across several vectors) and one new register, ZT0: 512 bits, used as a lookup table by LUTI2/LUTI4. ZT0 follows PSTATE.ZA, so it is zeroed and discarded with ZA. Access is gated by SMCR_ELx.EZT0 at each level. For context purposes SME2 adds only ZT0, 64 bytes.

SME without full SVE. FEAT_SME does not require FEAT_SVE. On such an implementation, Z, P and FFR (if FA64 is present) exist only in Streaming SVE mode. Outside streaming mode only the 128-bit V registers are accessible, and ZCR_ELx does not exist. An SVE instruction executed with PSTATE.SM=0 traps with EC 0x1D, SMTC 2: the enable check for SVE instructions becomes the streaming-SVE check. Apple’s M4 is a well-known example of this shape. Firmware and kernels must not infer “SVE present” from “SME present”, and a context-save routine must not use ZCR_ELx or RDVL outside streaming mode on such a part. Use RDSVL for the streaming length.

SVE2.1 and SME2.1 deltas

  • SVE2.1 (FEAT_SVE2p1) brings a large part of the SME2 multi-vector and predicate-as-counter model to non-streaming mode: multi-vector contiguous loads and stores governed by PN registers, WHILE* forms producing predicate pairs or counters, PEXT, and some formerly SME-only instructions such as SCLAMP/UCLAMP and REVD. It also adds operations on 128-bit segments (“quadword” reductions and permutes such as ADDQV, DUPQ, EXTQ, TBLQ) and 128-bit-element gather/scatter (LD1Q/ST1Q).
  • SME2.1 (FEAT_SME2p1) adds MOVAZ (move ZA slices to Z and zero the source, which is useful for draining an accumulator), ZERO forms that clear groups of ZA vectors, and related refinements. The new half-precision and BFloat16 SME arithmetic groups are separate features (FEAT_SME_F16F16, FEAT_SVE_B16B16, FEAT_SME_B16B16).
  • In an Armv9.4 implementation, SVE2 implies SVE2.1 and SME2 implies SME2.1. Neither adds architectural state beyond what SVE2 and SME2 have, so no context-switch code changes.

FPMR and FP8

FEAT_FP8 adds 8-bit floating-point formats: E5M2 and E4M3. The instruction encoding has no room for format and scaling selection, so it moves into a new EL0-accessible register, FPMR (FEAT_FPMR), which FP8 instructions read implicitly:

FieldBitsMeaning
F8S1, F8S22:0, 5:3Format of the first and second FP8 source operand (0b000 E5M2, 0b001 E4M3)
F8D8:6Format of an FP8 destination
OSM, OSC14, 15Overflow saturation for multiplication and for conversion
LSCALE, NSCALE, LSCALE222:16, 31:24, 37:32Scaling exponents applied by the conversions

The arithmetic groups are separate features (FEAT_FP8FMA, FEAT_FP8DOT4, FEAT_FP8DOT2, and streaming and SME forms such as FEAT_SSVE_FP8FMA and FEAT_SME_F8F32). ID_AA64PFR2_EL1.FPMR (bits [35:32]) reports the register.

FPMR is new architectural state with its own enables: SCR_EL3.EnFPM (bit 50), HCRX_EL2.EnFPM (bit 23), and SCTLR_EL1.EnFPM/SCTLR_EL2.EnFPM (bit 34) for EL0. A disabled direct access traps with EC 0x18. A disabled implicit read by an FP8 instruction is reported with EC 0x00, the “unknown reason” syndrome, which is easy to mistake for a genuinely UNDEFINED encoding. FPMR is a per-thread value, it belongs to the FP context, and it is zeroed when PSTATE.SM changes. FEAT_FPMR and FP8 arrived with the 2023 architecture extensions. TF-A documents FEAT_FPMR as optional from v9.2. Confirm the base version in DDI0487 A2.

Validation note: The SVCR side-effect rules are cheap to test directly, and early models and RTL often get them wrong. With PSTATE.SM=0, write known patterns to Z0, P0, FPSR and FPMR, execute SMSTART SM, and read them back: expect zeros and FPSR=0x0800009F. Repeat for SMSTOP SM, then check that a ZA pattern survives an SM change but not SMSTOP ZA followed by SMSTART ZA. Take an exception from streaming mode and check that SVCR is unchanged in the handler. A wrong result usually shows up later as corrupted vector state after a context switch, which is far harder to attribute.

Checkpoint

Q15.2.1 An EL1 kernel’s context-switch code saves Z registers with STR Zn, [x0, #k, MUL VL] into a buffer sized from RDVL at boot. A user thread was interrupted while in Streaming SVE mode on a core with VL = 128 and SVL = 512. What goes wrong?

  • A. Nothing, because exception entry clears PSTATE.SM, so the save runs at the non-streaming VL
  • B. The stores run at SVL = 512 because exceptions do not change PSTATE.SM, so they overrun a buffer sized for 128-bit vectors
  • C. The STR instructions take EC 0x1D with SMTC 1, because SVE stores are illegal in streaming mode
  • D. The saved data is zero, because entering the exception zeroed the Z registers
Answer

B. PSTATE.SM and PSTATE.ZA are not changed by exception entry or return, so the handler executes SVE instructions at the streaming vector length. The save must check SVCR and size the save for SVL. A is the common misconception. C is wrong because contiguous STR/ST1 stores are legal in streaming mode; gathers, scatters, FFR access and most Advanced SIMD vector instructions are the illegal ones. D confuses exception entry with an SM change, which is the event that zeroes the registers.

Read more: Arm ARM (DDI0487), SVCR; The Scalable Matrix Extension, Streaming SVE mode

Q15.2.2 A function holds live data in ZA and calls a function that may itself use ZA, following the lazy-save ABI. The callee never touches ZA. After the call returns, what is the state, and what work was done?

  • A. ZA was saved to the caller’s buffer at the call and restored at return, because the ABI saves at every call to a non-sharing function
  • B. ZA is zero, because the callee entered with ZA dormant and dormant ZA is discarded at return
  • C. TPIDR2_EL0 is null, so the caller must call __arm_tpidr2_restore
  • D. ZA still holds the caller’s data, TPIDR2_EL0 still points to the caller’s block, and no save or restore happened
Answer

D. The caller made ZA dormant by pointing TPIDR2_EL0 at its TPIDR2 block. Only a callee that wants to use ZA performs the save and clears TPIDR2_EL0. When none did, the caller finds TPIDR2_EL0 non-null and skips the restore. The protocol exists so that this, the common case, costs nothing. C describes the outcome when a callee did use ZA.

Read more: Arm ARM (DDI0487), TPIDR2_EL0; Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64), SME support, ZA lazy saving scheme

Q15.2.3 On a part with FP8 support, Linux user code executes an FP8 FCVTN and takes a synchronous exception with EC 0x00. A direct MRS x0, FPMR in the same process takes EC 0x18. What is the most likely cause?

  • A. An EnFPM enable is clear at some level (SCTLR_EL1, HCRX_EL2 or SCR_EL3), so the implicit FPMR read by the FP8 instruction and the direct access both trap
  • B. The core does not implement FEAT_FP8, so the encoding is UNDEFINED
  • C. The process is in Streaming SVE mode, and FP8 conversions are illegal in streaming mode
  • D. CPACR_EL1.FPEN traps EL0, and FP8 instructions report that trap with EC 0x00
Answer

A. A disabled implicit FPMR read by an FP8 instruction is reported with EC 0x00, and a disabled direct access with EC 0x18. Seeing both together points to an FPMR enable, often EL3 or EL2 firmware that predates FEAT_FPMR. B fits the EC 0x00 alone, but an unimplemented FPMR register access would also be UNDEFINED (EC 0x00), not EC 0x18. D is wrong because an FPEN trap always uses EC 0x07.

Read more: Arm ARM (DDI0487), FPMR, SCTLR_EL1.EnFPM, HCRX_EL2.EnFPM, SCR_EL3.EnFPM

15.3 Firmware responsibilities

FP, SVE and SME follow the rule set out in 2.6: the feature arrives trapped or disabled, and each higher Exception level must enable it for the levels below. EL3 is at the top of that chain. Its registers reset to UNKNOWN values, so nothing works until EL3 writes them. EL3 also owns the hard part, because all worlds share one register file and only EL3 sees every world switch. This section covers what EL3 and EL2 must program, how TF-A organises the per-world state, and what a missing bit looks like. 17.3 has the full FEAT_-to-enable-bit table; only the FP/SVE/SME rows are covered here.

The EL3 controls

FeaturePresent ifEL3 enableAlso programTrap when missing
FP/Advanced SIMDID_AA64PFR0_EL1.FP/AdvSIMD ≠ 0b1111CPTR_EL3.TFP=0 (bit 10)EC 0x07 to EL3
SVEID_AA64PFR0_EL1.SVE ≠ 0CPTR_EL3.EZ=1 (bit 8)ZCR_EL3.LEN (VL cap)EC 0x19 to EL3
SMEID_AA64PFR1_EL1.SME ≠ 0CPTR_EL3.ESM=1 (bit 12)SMCR_EL3.LEN, .FA64EC 0x1D, SMTC 0, to EL3
SME2 (ZT0)ID_AA64PFR1_EL1.SME ≥ 2SMCR_EL3.EZT0=1 (bit 30)EC 0x1D, SMTC 4, to EL3
TPIDR2_EL0SMESCR_EL3.EnTP2=1 (bit 41)EC 0x18 to EL3
FPMRID_AA64PFR2_EL1.FPMR ≠ 0SCR_EL3.EnFPM=1 (bit 50)EC 0x18 to EL3 (direct access); an FP8 instruction is UNDEFINED instead (EC 0x00, taken to the current EL, or EL1/EL2 from EL0)

Several details in this table are commonly got wrong:

  • Opposite polarities. TFP traps when 1. EZ and ESM enable when 1. A zeroed CPTR_EL3 therefore enables FP but traps SVE and SME.
  • The traps also apply to EL3 itself. The pseudocode for these checks tests CPTR_EL3 whatever the current EL is. With EZ=0, an MSR ZCR_EL3 or an SVE instruction executed at EL3 traps to EL3. So the order is: write CPTR_EL3, then ISB, then program ZCR_EL3/SMCR_EL3. The same applies to ESM and SMCR_EL3.
  • ZCR_EL3.LEN and SMCR_EL3.LEN cap every lower EL. EL3 should normally set the maximum value, 0xF, and leave lower ELs to restrict further. A lower cap at EL3 is a platform decision: TF-A exposes it as SVE_VECTOR_LEN. One reason to use it is a system whose cores support different VLs, because Linux requires every CPU to support the vector lengths it has already committed to and rejects a late CPU that does not.
  • SVE implies FP. SVE instructions are checked against the FP controls as well (15.2), so EZ=1 with TFP=1 still traps SVE, with EC 0x07.
  • FA64 is a policy choice, not a fix. Setting it where FEAT_SME_FA64 is implemented lets streaming code use the full A64 ISA. Where it is not implemented the bit is RES0, so firmware must check ID_AA64SMFR0_EL1.FA64 rather than set it blindly.

A minimal cold- and warm-boot sequence, before any lower EL runs, looks like this:

    mrs     x0, id_aa64pfr0_el1
    mrs     x1, id_aa64pfr1_el1
    mov     x2, #0                      // CPTR_EL3 resets UNKNOWN: build it from zero
                                        // TFP = 0: FP/SIMD not trapped
                                        // (TAM/TTA/TCPAC policy: see 17.2)
    ubfx    x3, x0, #32, #4             // ID_AA64PFR0_EL1.SVE
    cbz     x3, 1f
    orr     x2, x2, #(1 << 8)           // EZ = 1
1:  ubfx    x4, x1, #24, #4             // ID_AA64PFR1_EL1.SME
    cbz     x4, 2f
    orr     x2, x2, #(1 << 12)          // ESM = 1
2:  msr     cptr_el3, x2
    isb                                 // CPTR_EL3 write visible before ZCR/SMCR access
    cbz     x3, 3f
    mov     x5, #0xf
    msr     S3_6_C1_C2_0, x5            // ZCR_EL3.LEN = max
3:  cbz     x4, 4f
    mov     x5, #0xf                    // SMCR_EL3.LEN = max
    mrs     x6, S3_0_C0_C4_5            // ID_AA64SMFR0_EL1
    tbz     x6, #63, 5f                 // FA64 implemented?
    orr     x5, x5, #(1 << 31)          // FA64 = 1 (policy choice)
5:  cmp     x4, #2                      // SME2 or later?
    b.lo    6f
    orr     x5, x5, #(1 << 30)          // EZT0 = 1
6:  msr     S3_6_C1_C2_6, x5            // SMCR_EL3
4:  isb

SCR_EL3.EnTP2 and EnFPM are per-world values. They belong in the SCR_EL3 that EL3 installs before each ERET, not in a one-off write at boot. Both CPTR_EL3 and these SCR_EL3 bits must be reprogrammed on every warm boot, because they are lost when the core powers down (17.4).

EL2: present or unused

When a hypervisor runs at EL2, it owns CPTR_EL2, ZCR_EL2, SMCR_EL2 and HCRX_EL2.EnFPM, and it typically uses them for lazy switching of guest state (15.1). EL3’s only job is to leave EL2 able to use them. When EL2 is implemented but no EL2 software will run, and the Normal world enters at EL1, EL3 must program EL2 itself, because the EL2 controls still apply to EL1 and EL0 and they reset to UNKNOWN values. TF-A does this under INIT_UNUSED_NS_EL2.

Bring-up note: With HCR_EL2.E2H=0, CPTR_EL2 bits [9:0] and 12–13 are RES1 except where a feature gives them a meaning: bit 8 is TZ when SVE is implemented and bit 12 is TSM when SME is implemented. Firmware that writes “the RES1 mask” from the register description therefore sets TZ=1 and TSM=1, and traps SVE and SME. TF-A writes that mask and then clears TZ explicitly in sve_init_el2_unused(). If an EL1 kernel takes EC 0x19 or 0x1D to an EL2 that nobody installed, look here first.

Per-world context in TF-A

TF-A splits EL3-owned state into two kinds. Per-world values are identical on every CPU for a given world and live in per_world_context[] (lib/el3_runtime/aarch64/context_mgmt.c). They are currently ctx_cptr_el3 and ctx_mpam3_el3. Per-CPU, per-world values live in each cpu_context_t. They include the SCR_EL3 image that carries EnTP2 and EnFPM. While EL3 itself runs, TF-A installs a separate root context: CPTR_EL3 has TFP=1, so stray FP use in EL3 C code traps, and EZ=1/ESM=1, so EL3 can still access ZCR_EL3/SMCR_EL3. On exit, TF-A writes the target world’s ctx_cptr_el3 before the ERET.

The feature modules set the per-world values:

FunctionEffect
sve_init_el3()ZCR_EL3.LEN from SVE_VECTOR_LEN
sve_enable_per_world() / sve_disable_per_world()set / clear CPTR_EL3.EZ for a world
sme_init_el3()SMCR_EL3.LEN = max, FA64 and EZT0 if implemented
sme_enable_per_world() / sme_disable_per_world()set ESM / clear ESM and EZ
sme_enable(ctx) / sme_disable(ctx)set / clear SCR_EL3.EnTP2 in a CPU context

The build options choose the policy:

OptionMeaning
ENABLE_SVE_FOR_NS, ENABLE_SME_FOR_NS, ENABLE_SME2_FOR_NSEnable the feature for the Normal world (SME requires SVE). Values 0/1/2 follow the FEATURE_DETECTION convention: 2 means “check the ID register at runtime”.
ENABLE_SVE_FOR_SWD, ENABLE_SME_FOR_SWDAlso enable it for the Secure world. The SPMC or Secure OS must then manage the state.
ENABLE_FEAT_FPMRSet SCR_EL3.EnFPM
CTX_INCLUDE_FPREGSEL3 saves and restores V0–V31, FPSR, FPCR on world switch
CTX_INCLUDE_SVE_REGSEL3 saves Z, P and FFR at SVE_VECTOR_LEN. Requires ENABLE_SVE_FOR_SWD, and is mandatory when CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS are both set
SVE_VECTOR_LENThe ZCR_EL3 cap, default 2048

The default Secure-world policy is worth reading closely. With ENABLE_SVE_FOR_SWD=0, TF-A clears EZ (and ESM) for the Secure world but leaves TFP=0. Secure code can still execute FP/Advanced SIMD instructions, and each such write zeroes the upper bits of the Normal world’s Z registers (15.1). The policy is safe only if the Secure world never touches FP, or saves it at the full SVE width (which needs SVE enabled for it, ENABLE_SVE_FOR_SWD=1), or EL3 does (CTX_INCLUDE_SVE_REGS, which also requires ENABLE_SVE_FOR_SWD=1). TF-A’s documentation recommends doing the save in the lower EL, because the EL3 buffers are large: at a VL of 2048 bits, each world needs about 8.7 KB per CPU for SVE alone.

When the SPMD sits between the worlds, a cheaper option exists. SMCCC v1.3 defines bit 16 of the function ID as the SVE live-state hint. A caller that sets it declares that no SVE state above the 128-bit V registers, and no P or FFR state, needs preserving across the call. The SPMD reads the hint (is_sve_hint_set()), passes it to the SPMC, and uses it to skip the wide part of the save. For Realms, TF-A enables SVE and SME in the Realm world’s CPTR_EL3, and the RMM saves and restores whatever Normal-world state it overwrites (12.4).

SME across a world switch

TF-A’s SIMD context (simd_regs_t) covers V/Z, P, FFR, FPSR, FPCR and, for AArch32, FPEXC32. It does not cover SVCR, ZA, ZT0 or FPMR. The SME state is left to the lower-EL managers. This has three consequences for anyone porting a Secure OS or SPMC to an SME part:

  • An SMC can arrive with PSTATE.SM=1 and/or PSTATE.ZA=1, because exceptions do not change them (15.2). The Secure world then starts in streaming mode. Its first Advanced SIMD vector instruction traps (SMTC 1, unless FA64 is enabled), and a Z-register save runs at SVL instead of VL.
  • A Secure-world SMSTOP that leaves streaming mode zeroes the Normal world’s Z, P, FFR and FPMR and rewrites its FPSR. A Secure-world SMSTOP ZA discards the Normal world’s ZA. Either must be preceded by a save, at SVL, of everything the Normal world could own.
  • TPIDR2_EL0 is an EL0 register that EL3 does not switch. A Secure world that runs S-EL0 code using SME must save and restore it, or the Normal world’s lazy-save chain is corrupted.

The simplest correct policy for most products is the default: Secure and Realm code that does not need SME does not get it (ESM=0 for that world), and whichever manager first uses FP state in another world saves the Normal world’s state at the widest length currently in effect.

What a missing bit looks like

SymptomLikely cause
Normal-world kernel hangs or panics at EL3 during early boot, with an unhandled EC 0x19 in the EL3 crash dumpCPTR_EL3.EZ=0 while Linux probes SVE: it reads ZCR_EL1 and executes RDVL at boot if the ID registers report SVE
EC 0x1D with SMTC 0 at EL3CPTR_EL3.ESM=0 with ID_AA64PFR1_EL1.SME reporting SME
EC 0x18 at EL3 with the TPIDR2_EL0 or FPMR encoding in the ISSSCR_EL3.EnTP2 or EnFPM missing from that world’s SCR_EL3
Works on cold boot, fails after CPU_SUSPEND or hotplugEnable bits written once at boot, not restored on the warm-boot path
Normal-world SVE data randomly loses its high bitsA Secure or Realm service uses FP with no SVE-width save anywhere
Linux reports a smaller VL than the core supportsZCR_EL3.LEN/SVE_VECTOR_LEN or SMCR_EL3.LEN capped at EL3, or a hypervisor cap in ZCR_EL2

Linux sanitises the ID registers (1.1), but it trusts them. If the ID register reports SVE and EL3 traps it, the kernel does not degrade gracefully: it takes the trap at the first probe. A hypervisor can hide the feature from a guest by trapping and emulating ID_AA64PFR0_EL1 (HCR_EL2.TID3). EL3 cannot hide a feature from EL2 that way unless FEAT_IDTE3 is implemented (17.3). The practical rule is therefore: enable every feature that the ID registers advertise, or make the platform’s ID values match what you enable.

Validation note: For each world, run a directed test at the lowest EL that executes one FP instruction, one SVE instruction (RDVL), SMSTART/SMSTOP, one ZT0 access, an MRS of TPIDR2_EL0 and an MRS of FPMR. Expect either success or the documented trap for that world’s policy, never a trap to EL3. Repeat after CPU_SUSPEND to power-down and after CPU_OFF/CPU_ON. Then test cross-world integrity. Fill Z0–Z31 with patterns in the Normal world at the maximum VL, call an SMC handled by a Secure service that executes Advanced SIMD instructions, and compare. A mismatch above bit 127 shows that the save policy is broken, not the hardware.

Checkpoint

Q15.3.1 EL3 boot code executes MOV x0, #0xF; MSR ZCR_EL3, x0 and only afterwards sets CPTR_EL3.EZ=1. On the first boot of an SVE part it takes an exception straight away. Why?

  • A. ZCR_EL3 is write-once after reset and was already written by the boot ROM
  • B. CPTR_EL3.EZ=0 traps accesses to ZCR_EL3 even from EL3, so the write traps to EL3 (EC 0x19) before EZ is set
  • C. The ISB between the two writes is missing, so the ZCR_EL3 write is UNPREDICTABLE
  • D. ZCR_EL3.LEN=0xF requests 2048 bits, which is larger than the implementation supports, and an unsupported length faults
Answer

B. The SVE enable check tests CPTR_EL3.EZ regardless of the current EL, and the CPTR_EL3 reset value is UNKNOWN, so it may well be 0. EL3 must set EZ first, then ISB, then write ZCR_EL3. D is wrong because LEN is a request: the PE uses the largest supported length that does not exceed it, and setting the maximum is the recommended EL3 value.

Read more: Arm ARM (DDI0487), CPTR_EL3, ZCR_EL3, CheckSVEEnabled() pseudocode

Q15.3.2 TF-A is built with ENABLE_SVE_FOR_NS=1, ENABLE_SVE_FOR_SWD=0, CTX_INCLUDE_FPREGS=0. OP-TEE at S-EL1 uses Neon for a hash. A Normal-world SVE application occasionally sees corrupted vectors. Which change actually fixes the problem?

  • A. Set CTX_INCLUDE_FPREGS=1, so that EL3 saves V0–V31 around the Secure call
  • B. Set ENABLE_SVE_FOR_SWD=1, so that OP-TEE’s Neon instructions trap
  • C. Make Normal-world Z, P and FFR state survive at full width: either OP-TEE saves and restores it before using Neon (it then needs SVE access, ENABLE_SVE_FOR_SWD=1), or EL3 does (CTX_INCLUDE_SVE_REGS=1, which requires ENABLE_SVE_FOR_SWD=1)
  • D. Set SVE_VECTOR_LEN=128, so that Z and V are the same size
Answer

C. With SVE disabled for the Secure world, TF-A clears only EZ, and Advanced SIMD remains usable. Each Neon write zeroes the bits of the Normal world’s Z registers above bit 127. A saves only the 128-bit view, which is exactly the combination TF-A forbids without CTX_INCLUDE_SVE_REGS. B gets the effect backwards: enabling SVE for the Secure world removes a trap, it does not add one, and Neon is governed by TFP in any case. D hides the problem by throwing away the SVE width for everyone, at a large performance cost, so it is not a fix.

Read more: TF-A build options, ENABLE_SVE_FOR_SWD, CTX_INCLUDE_SVE_REGS; Arm ARM (DDI0487), SVE registers

Q15.3.3 A product enables SME for the Normal world only. A Normal-world thread in Streaming SVE mode, with ZA active, makes an FF-A call. The SPMC at S-EL2 uses Advanced SIMD vector instructions in its message-copy path. What happens first, and why?

  • A. The SPMC’s first Advanced SIMD vector instruction traps with EC 0x1D, SMTC 1, unless FA64 is enabled, because PSTATE.SM is still 1 after the exception and the world switch
  • B. Nothing goes wrong, because EL3 clears PSTATE.SM and PSTATE.ZA on every world switch
  • C. The SPMC’s instruction traps with EC 0x1D, SMTC 0, because ESM=0 for the Secure world, and that check takes priority over everything
  • D. The SMC itself is rejected, because SMC is illegal in Streaming SVE mode
Answer

A. Exception entry, ERET and EL3’s world switch leave SVCR unchanged, and TF-A does not save or restore it. The Secure world therefore runs in streaming mode, where most Advanced SIMD vector instructions are illegal. C is tempting, but ESM is checked only for SVE and SME instructions and SME register accesses. The pseudocode checks an Advanced SIMD instruction against the FP controls (FPEN/TFP, which allow it here) and then for legality in Streaming SVE mode, and that second check raises SMTC 1 at the current EL. A Secure-world SVE instruction would instead trap to EL3 with SMTC 0. Either way, the Secure-world code must handle entry with SM=1. B is false for TF-A. D is false: SMC is legal in streaming mode.

Read more: Arm ARM (DDI0487), SVCR, Streaming SVE mode instruction legality; TF-A simd_ctx.h

Part 16: Debug, trace, PMU and RAS

Prerequisites: 2.6 The trap-control map, 3.2 Entry and return, 3.4 SError, architecturally, 7.8 Context synchronization and ISB, 8.7 DMA and non-coherent masters.

If you already know: how a JTAG probe halts a core and how perf programs counters, skim 16.1 and the register tables in 16.3. Read the OS Lock and DoubleLock material in 16.1, the CTI, authentication and power-down parts of 16.2, the PMUv3p5–p9 extensions in 16.3, and all of 16.4 to 16.8.

Why this matters for bring-up/validation: these blocks are the instruments you observe the silicon with. When they are misconfigured or misunderstood, you see nothing, or you see the wrong thing and trust it.

This part covers the observation and error-reporting machinery of the PE. 16.1 and 16.2 are the two halves of debug. Self-hosted debug turns breakpoints, watchpoints and single-step into exceptions taken to EL1 or EL2, gated by MDSCR_EL1, PSTATE.D and the OS Lock. External debug halts the PE in Debug state through the CoreSight fabric (DP, APs, ROM tables), with CTIs to cross-halt every core, the authentication signals to decide who may halt what, and power-request handshakes to keep a core reachable across power-down. 16.2 also covers the two ways a debugger can read memory, through the halted PE or through a MEM-AP, and what each one does and does not see.

The remaining sections turn from control to measurement and errors. 16.3 covers the PMUv3 programming model, including EL and Security-state filtering, EL3 prohibition and the p5–p9 extensions (64-bit counters, freeze, thresholds, the fixed instruction counter and snapshots). 16.4 covers the AMU, the always-on accounting counters that firmware owns and must save across power-down. 16.5 uses PMU events as a test oracle for memory attributes, TLB maintenance and speculation, and 16.6 covers SPE, ETE/TRBE and BRBE, and what EL3 has to enable for each. 16.7 and 16.8 cover RAS: error records and nodes, the error classes and poison, then firmware-first handling and fault injection as a test matrix.

16.1 Self-hosted debug

In self-hosted debug, software running on the PE is its own debugger. Debug events become debug exceptions that are taken to an EL1 or EL2 handler, as in GDB under Linux or a debug monitor in firmware. External (halting) debug, where events stop the PE in Debug state, is the subject of 16.2. The two share the same breakpoint and watchpoint hardware, and EDSCR.HDE and the authentication interface decide which model an event uses.

The debug exceptions and their syndromes

ExceptionGenerated byEC (lower EL / same EL)Gate
Breakpoint InstructionBRK #imm160x3C (one value)always generated, even when debug is otherwise disabled
BreakpointDBGBCR<n>_EL1/DBGBVR<n>_EL1 match0x30 / 0x31MDSCR_EL1.MDE
WatchpointDBGWCR<n>_EL1/DBGWVR<n>_EL1 match0x34 / 0x35MDSCR_EL1.MDE
Software StepMDSCR_EL1.SS plus PSTATE.SS0x32 / 0x33MDSCR_EL1.SS
Vector CatchAArch32 EL1 only0x3AMDSCR_EL1.MDE

BRK is a synchronous exception like SVC. It is not subject to the enable rules below, and the imm16 comment field appears in the ISS. Every other debug exception is generated only if debug exceptions are enabled from the current Exception level and Security state. The ASL function that decides this is AArch64.GenerateDebugExceptionsFrom(). In outline:

  1. The debug target Exception level, ELd, is EL2 if EL2 is enabled in the current Security state and either MDCR_EL2.TDE or HCR_EL2.TGE is 1. Otherwise ELd is EL1. In AArch64, debug exceptions other than BRK are never taken to EL3, and none are generated while executing at EL3.
  2. If the OS Lock is locked, or the OS Double Lock is in effect (DoubleLockStatus()), or the PE is halted, nothing is generated.
  3. In Secure state, MDCR_EL3.SDD == 1 disables them at every Secure EL.
  4. From an EL lower than ELd, they are enabled. From ELd itself, they are enabled only if MDSCR_EL1.KDE == 1 and PSTATE.D == 0. From an EL higher than ELd, they are never enabled.

This rule is why a kernel can debug its own EL1 code only with KDE set and PSTATE.D cleared. It is also why a hypervisor that sets MDCR_EL2.TDE takes over every guest debug event, and why EL3 firmware cannot be debugged self-hosted at all. PSTATE.D is set on every exception entry, so a handler for a debug exception cannot recurse into itself by default.

MDSCR_EL1 fields that matter here (bit positions from the System Register XML):

BitFieldMeaning
15MDEenables Breakpoint, Watchpoint and Vector Catch exceptions
14HDEthe self-hosted view of EDSCR.HDE (halting debug enable)
13KDEenables debug exceptions at ELd
12TDCCtraps EL0 access to the DCC registers
0SSSoftware Step enable

Breakpoints

ID_AA64DFR0_EL1.BRPs is the number of breakpoints minus one, and CTX_CMPs is the number that are context-aware, also minus one. The context-aware breakpoints are the highest-numbered ones. Before FEAT_Debugv8p9 there are at most 16 of each. FEAT_Debugv8p9 allows up to 64 and exposes them in banks of 16 through MDSELR_EL1.BANK, with the counts in ID_AA64DFR1_EL1.{BRPs,WRPs,CTX_CMPs}.

DBGBCR<n>_EL1 fields:

  • E (bit 0): enable.
  • PMC, HMC, SSC (with SSCE under RME): select the Exception levels and Security states in which the breakpoint matches. In the common cases, with HMC=0 and SSC=0b00, PMC=0b01 matches EL1 only, 0b10 matches EL0 only and 0b11 matches both. These are the values Linux’s hw_breakpoint uses. For the full table, see the Arm ARM section “Execution conditions for which a breakpoint generates Breakpoint exceptions”.
  • BAS [8:5]: byte-address select, which exists to select halfwords for T32. For an A64 instruction address match, program it to 0b1111. For what other values do, see the DBGBCR<n>_EL1.BAS description. Linux always writes 0xF here.
  • BT: the breakpoint type. 0b0000 is an unlinked address match and 0b0001 is a linked address match. Further types match on Context ID (CONTEXTIDR_EL1), VMID, or CONTEXTIDR_EL2, and are available only on context-aware breakpoints.
  • LBN: for a linked breakpoint, the context-aware breakpoint it is linked to. An address match fires only if the linked context also matches. This is how a debugger sets “break at VA X only in process Y”.

DBGBVR<n>_EL1 holds the word-aligned instruction VA. The upper bits follow the sign-extension rules for the implemented VA size. On a Breakpoint exception, ELR_ELx holds the address of the breakpointed instruction. That instruction has not executed, and the handler must disable the breakpoint or step over it before returning.

Watchpoints

DBGWCR<n>_EL1/DBGWVR<n>_EL1 match data accesses:

  • LSC: 0b01 loads, 0b10 stores, 0b11 both.
  • BAS: a byte mask over the doubleword-aligned (DBGWVR[2:0] == 0) address. 0xFF watches all 8 bytes.
  • MASK: when non-zero, watches a naturally aligned 2^MASK-byte region (the minimum is 8 bytes). It is mutually exclusive with a partial BAS.
  • WT, LBN: link the watchpoint to a context-aware breakpoint for context-qualified watching.
  • PAC, HMC, SSC: the same EL and Security filtering as for breakpoints.

A Watchpoint exception is synchronous and precise with respect to the accessing instruction. ELR_ELx points at the load or store, which has not completed architecturally. For a single-access store, the watched memory has not been updated, so the handler can inspect the old value. For instructions that make several accesses, such as STP or DC ZVA, check “Watchpoint exceptions” in the Arm ARM for whether the other accesses may already have been performed before relying on this. ESR_ELx.ISS.WnR gives the direction, and FAR_ELx holds an address from the access, not necessarily the watched address. A DC ZVA or an LDP that only partly overlaps the watched bytes still triggers, and FAR_ELx can point anywhere in the accessed range that the architecture allows. Some cache maintenance instructions, DC IVAC among them, can also trigger a store watchpoint. For which instructions do and which are only permitted to, see “Watchpoint exceptions” in the Arm ARM.

Bring-up note: DBGWVR/DBGBVR compare virtual addresses in the translation regime of the matching EL. If you set a watchpoint before SCTLR_EL1.M is set and then enable the MMU with a non-identity mapping, the watchpoint now watches a different physical location. Watchpoints do match with the MMU off (VA == PA), which is handy for catching stray writes into a page-table pool during early boot.

Software step

Software step is a small state machine on MDSCR_EL1.SS and PSTATE.SS:

inactive          MDSCR_EL1.SS == 0, or debug exceptions disabled from the current EL
active-not-pending  MDSCR_EL1.SS == 1 and PSTATE.SS == 1: the PE executes ONE instruction
active-pending    MDSCR_EL1.SS == 1 and PSTATE.SS == 0: Software Step exception is taken
                  before the next instruction

The debugger’s handler (at ELd) sets SPSR_ELx.SS = 1 (bit 21) and executes ERET to the debuggee. The PE then executes one instruction, PSTATE.SS becomes 0, and the step exception is taken with ELR_ELx pointing to the next instruction. Things to know:

  • If the stepped instruction itself causes an exception to ELd, the handler is not stepped, because it runs at ELd with PSTATE.D == 1. The step state travels in SPSR_ELx.SS. After an exception-generating instruction such as SVC, which counts as stepped, the saved SS is 0, so the step exception is taken right after the handler’s ERET. After a fault, where the instruction did not complete, the instruction is stepped again when it re-executes. For the exact rules, see “Software Step exceptions” in the Arm ARM. ESR_ELx.ISS.ISV qualifies the EX bit described next.
  • ESR_ELx.ISS.EX reports that the stepped instruction was a Load-Exclusive. Stepping through an LDXR/STXR loop can livelock, because the step exception clears the exclusive monitor (an exception return is permitted to clear it). Debuggers step over the whole loop with a breakpoint after it. This is one reason to prefer LSE atomics (10.2).
  • With KDE = 1, a kernel can single-step itself at EL1 (EC 0x33). This is how kprobes or kgdb step.

The OS Lock

The OS Lock exists so that an OS can save and restore the debug registers across a core power-down without an external debugger changing them underneath it.

  • OSLAR_EL1.OSLK (WO, bit 0): write 1 to lock and 0 to unlock.
  • OSLSR_EL1.OSLK (bit 1) reads the state. OSLSR_EL1.OSLM (bits [3,0]) reads 0b10 (“implemented”), the only permitted value in Armv8.

While the lock is set:

  • Breakpoint, Watchpoint, Software Step and Vector Catch exceptions are not generated. BRK still is.
  • External debugger accesses to most debug registers return an error response, including EDSCR, EDITR and DBGBCR<n>_EL1 through the external interface. Software at EL1 or above can still read and write them through system register accesses in order to save and restore them.
  • A debugger can arm EDECR.OSUCE (OS Unlock Catch) to halt the PE as soon as software unlocks.

The OS Lock is set on Cold reset (OSLSR_EL1.OSLK resets to 1). Linux clears it on every CPU during early CPU setup, including on the resume path (older kernels did this in clear_os_lock() in debug-monitors.c; recent kernels do it in the early boot/resume code). A bare-metal or RTOS image that never writes OSLAR_EL1 keeps self-hosted debug disabled, and an external debugger sees error responses on the core’s debug registers until it writes OSLAR_EL1 itself through the external interface at offset 0x300.

Traps: MDCR_EL3.TDOSA and MDCR_EL2.TDOSA trap OSLAR_EL1, OSLSR_EL1, OSDLR_EL1 and DBGPRCR_EL1 (EC 0x18). MDCR_ELx.TDA traps the breakpoint, watchpoint and MDSCR_EL1 accesses. These let a hypervisor virtualise guest debug.

The OS Double Lock (FEAT_DoubleLock)

OSDLR_EL1.DLK (bit 0) is the “really powering down now” lock. ASL defines:

DoubleLockStatus() = OSDLR_EL1.DLK == 1 && DBGPRCR_EL1.CORENPDRQ == 0 && !Halted()

When it is in effect, no debug events are generated and external debug accesses to most of the core’s debug registers (including EDSCR and the breakpoint registers) return an error. This is meant to be the last step before the power controller removes Core power, so that no debug APB transaction is caught in flight across the power boundary. DBGPRCR_EL1.CORENPDRQ (Core No Power-Down Request, driven by a debugger through EDPRCR) overrides it. In that case the power controller emulates the power-down, which is how a debugger keeps a core alive across CPU_SUSPEND.

Version status: ID_AA64DFR0_EL1.DoubleLock (bits [39:36], a signed field) is 0b0000 (implemented) or 0b1111 (not implemented, with OSDLR_EL1 RAZ/WI).

  • In Armv8.0 the double lock is mandatory.
  • With FEAT_Debugv8p2 it becomes optional.
  • With FEAT_DoPD (Debug over Powerdown, which moves all external debug registers into the Core power domain) it is not permitted.
  • Following DDI0487 A2, Armv9-A implementations do not implement FEAT_DoubleLock.

Code that executes MSR OSDLR_EL1, x therefore has to check the ID field. On a part without the feature the write is ignored, so do not rely on the lock for power-down safety there.

Security note: self-hosted debug exceptions in Secure state are a way to observe Secure execution. TF-A sets MDCR_EL3.SDD = 1 (Secure self-hosted debug disabled, except BRK) and, for AArch32 Secure EL1, SPD32 = 0b10. When you review a secure-world image, check that no path clears SDD in production builds, and that MDCR_EL3.TDA/TDOSA handling does not let the Normal world reprogram a breakpoint that matches in Secure state. With SSC/HMC a breakpoint can be configured to match Secure EL1, and SDD is what stops it from firing.

Validation note: a minimal self-hosted debug test at EL1 sets MDSCR_EL1.{MDE,KDE}, clears PSTATE.D (msr daifclr, #8), programs DBGBVR0_EL1 with a function address and DBGBCR0_EL1 = (0xF << 5) | (0b01 << 1) | 1 (BAS = 0b1111, EL1, enabled), executes ISB, and calls the function. Expect EC 0x31 with ELR_EL1 equal to the function address. The same test with OSLAR_EL1 = 1 must take no exception, and the same test with KDE = 0 must take none either. Without the ISB after programming, the breakpoint is permitted to fire but is not guaranteed to. If it never fires even with the ISB, the usual cause is an OS Lock that was never cleared.

Checkpoint

Q16.1.1 EL1 code sets MDSCR_EL1.MDE = 1, programs and enables a breakpoint that matches at EL1, executes ISB, and calls the target. HCR_EL2.TGE == 0, MDCR_EL2.TDE == 0, and the OS Lock is unlocked. No exception is taken. Which explanation is consistent with the architecture?

  • A. Breakpoints are only generated for EL0 code, so EL1 must use BRK instead
  • B. The ISB is not enough. A DSB SY is required for a DBGBCR write to take effect
  • C. MDSCR_EL1.KDE is 0 or PSTATE.D is 1, so debug exceptions are disabled at the debug target EL itself
  • D. Breakpoint exceptions are always routed to EL3, which ignores them
Answer

C. ELd is EL1 here, and debug exceptions from ELd require both KDE == 1 and PSTATE.D == 0. Option B is tempting because barrier questions usually have that shape, but writes to debug system registers are made visible to subsequent instructions by a context synchronization event, and ISB is one. DSB adds nothing here. EL1 breakpoints exist, which rules out A, and AArch64 never takes non-BRK debug exceptions to EL3, which rules out D.

Read more: Arm ARM (DDI0487), “Enabling debug exceptions from the current Exception level and Security state”, MDSCR_EL1

Q16.1.2 A bring-up team’s RTOS image boots on a new core. The external debugger connects over the DAP but reports errors whenever it tries to program a hardware breakpoint, even though authentication signals permit invasive debug. What is the most likely cause?

  • A. The OS Lock is still set from Cold reset, so external accesses to the breakpoint registers return an error response
  • B. The OS Double Lock is set from Cold reset and blocks all external access
  • C. MDSCR_EL1.MDE is 0, which makes the breakpoint registers read-only externally
  • D. The breakpoint registers can only be written by software running at EL1
Answer

A. OSLSR_EL1.OSLK resets to 1 on Cold reset, and while it is set, external accesses to DBGBCR<n>_EL1 and similar registers generate an error response. Linux clears it, but a bare-metal image often does not. The debugger can clear it through the external OSLAR_EL1. B is wrong because OSDLR_EL1.DLK resets to 0, and on Armv9 parts the double lock is not implemented at all. MDE controls only self-hosted exception generation, which rules out C.

Read more: Arm ARM (DDI0487), OSLSR_EL1, OSLAR_EL1, “The OS Lock”

Q16.1.3 A debugger single-steps EL0 code under Linux and reaches an LDXR/STXR retry loop. Each step completes, yet the loop never exits. Why?

  • A. Software step is not permitted on Load-Exclusive instructions and silently skips them
  • B. PSTATE.SS is cleared by STXR, so the step exception never arrives
  • C. The step exception is taken at EL1, which is above ELd, so it is ignored
  • D. Taking the step exception and returning between LDXR and STXR is permitted to clear the local exclusive monitor, so STXR keeps failing
Answer

D. Each step exception is an exception entry and return between the LDXR and the STXR, and an exception return is permitted to clear the exclusive monitor, so the store-exclusive fails every time. This is why ESR_ELx.ISS.EX flags a stepped Load-Exclusive: it lets the debugger switch to a breakpoint after the loop. Option A is wrong because the instruction is stepped normally. Option C misreads the routing: the exception is taken to EL1 (ELd) from EL0, which is the normal case.

Read more: Arm ARM (DDI0487), “Software Step exceptions”, “Stepping a Load-Exclusive instruction”

16.2 External debug and CoreSight

External debug means an agent outside the PE controls it: a JTAG probe, a Trace32 or DS-5 session, or a validation script driving the DAP. Debug events halt the PE in Debug state rather than raising an exception. The Arm ARM defines the PE side, meaning the external debug registers, Debug state and the authentication rules. The CoreSight architecture and ADIv5/ADIv6 define the fabric that gets the probe to those registers. A bring-up engineer needs both, because “the debugger can’t connect” is usually a fabric, power or authentication problem rather than a core problem.

Topology: probe to register

 probe ──JTAG/SWD──> DP (JTAG-DP / SW-DP / SWJ-DP)
                      │  DP CTRL/STAT: CDBGPWRUPREQ/ACK, CSYSPWRUPREQ/ACK
                      ├── APB-AP ──> debug APB ──> ROM table
                      │                           ├─ core0: debug | CTI | PMU | ETE/ETM  (4KB frames)
                      │                           ├─ core1: ...
                      │                           └─ CTM, funnels, TMC/ETR, STM ...
                      └── AXI-AP / AHB-AP (MEM-AP) ──> system interconnect ──> DRAM, peripherals
  • The DP (Debug Port) terminates the wire protocol. Before anything behind it responds, the debugger sets CDBGPWRUPREQ (debug power domain) and CSYSPWRUPREQ (system power) in DP CTRL/STAT and waits for the matching ACK bits. A board that never returns CDBGPWRUPACK has a power-controller or reset-sequencing problem, not a core problem.
  • APs (Access Ports) are bus masters. A MEM-AP issues memory transactions, with attributes taken from its CSW register. The APB-AP masters the debug APB. In ADIv6, APs are themselves found through ROM tables and can sit behind other APs.
  • The ROM table lists components by offset. Every CoreSight component has 4KB of registers with CIDR/PIDR identification at the top and DEVARCH/DEVTYPE describing it. For an A-profile PE, the Arm ARM fixes the layout of the debug frame (EDSCR at 0x088, EDITR at 0x084, DBGBCR<n>_EL1 at 0x408 + 16n, OSLAR_EL1 at 0x300, and so on), and separately the PMU, CTI and trace frames.
  • Software-lock registers (EDLAR, CTILAR, key 0xC5ACCE55) apply only to accesses from the system side (that is, from software on a core). Accesses through the APB-AP are external and bypass them. The software lock is optional and Arm deprecates it, so many current implementations leave it out.

Bring-up note: on a multi-chiplet SoC, each chiplet usually has its own DP or a nested AP/ROM-table subtree, and the die-to-die link must be up and its debug bridge configured before the remote ROM table is visible. Ask the SoC team for the actual ROM-table walk, with base addresses, before blaming the probe. A useful first test is to read each core’s EDDEVARCH (offset 0xFBC) and EDPRSR.

Halting debug state

EDSCR is the external view of debug status and control:

FieldMeaning
STATUS[5:0]0b000010 Non-debug, 0b000001 restarting, 0b010011 external debug request, 0b000111 breakpoint, 0b101011 watchpoint, 0b011011 halting step, 0b101111 HLT, 0b100111 Reset Catch, 0b100011 OS Unlock Catch, 0b110111 Exception Catch
HDEhalting debug enable: breakpoints, watchpoints and HLT halt instead of taking exceptions
ITEthe instruction written to EDITR has completed
ERRcumulative error flag, cleared by writing EDRCR.CSE
MAmemory access mode (below)
TXfull/RXfullDebug Communications Channel (DCC) handshake
EL, NS, NSE, RWthe Exception level, Security state and register width while halted

Halting events are: External Debug Request (a CTI output, below), breakpoints and watchpoints with HDE == 1, HLT #imm, halting step (EDECR.SS), and the catch events EDECR.RCE (Reset Catch) and EDECR.OSUCE (OS Unlock Catch). EDESR records pending ones. Reset Catch is the bring-up workhorse: it halts the core on the first instruction after reset, before any firmware runs.

In Debug state the PE does not fetch. The debugger writes A64 instructions to EDITR, which the PE executes one at a time, and moves data through DBGDTRRX_EL0/DBGDTRTX_EL0. Reading a system register looks like this:

EDITR <- MRS X0, VBAR_EL3        // only if halted at EL3, or after DCPS3
EDITR <- MSR DBGDTR_EL0, X0      // X0 -> DTR (both halves)
read DBGDTRTX (low word), DBGDTRRX (high word)

DCPS1/2/3 change EL while halted (DCPS3 subject to authentication), and DRPS lowers the EL as an ERET would (from SPSR_ELx) but does not branch. The PSTATE saved on entry to Debug state is in DSPSR_EL0, with the resume address in DLR_EL0, and both are restored on exit. Leaving Debug state is only possible through a CTI restart trigger (below). No register write exits it directly.

EDPRSR is the first register to read on any core you cannot talk to, because it is designed to stay readable while the core is powered down. It reports PU (core powered up), SPD (sticky power-down: the core lost power since the last read, so debug register state was lost), R/SR (in reset / sticky reset), HALTED, OSLK (OS Lock, which 16.1 says blocks most debug-frame accesses), DLK (double lock), and the RME and Debugv8p4 “access disabled” status bits (EDAD, SDAD, EPMAD, SPMAD, …).

CTI and CTM: halting everything at once

Each PE has a CTI (Cross-Trigger Interface). Trigger inputs come from PE events and trigger outputs drive PE actions. The CTIs exchange events over a small number of broadcast channels on the CTM (Cross-Trigger Matrix). The architected PE connections are:

CTI triggerDirectionMeaning
input 0PE → CTIcross-halt trigger: the PE entered Debug state
input 1PE → CTIPMU overflow
inputs 4–7trace → CTItrace unit external outputs (when present)
output 0CTI → PEDebug request: the halting event
output 1CTI → PERestart request: exit Debug state
output 2CTI → GICgeneric CTI interrupt
outputs 4–7CTI → tracetrace unit external inputs

A cross-halt setup, done on every core’s CTI:

CTICONTROL.GLBEN = 1
CTIINEN0  = 1<<0      // input trigger 0 (I halted) -> channel 0
CTIOUTEN0 = 1<<0      // channel 0 -> output trigger 0 (debug request)
CTIOUTEN1 = 1<<1      // channel 1 -> output trigger 1 (restart)
CTIGATE   = 0b11      // let channels 0,1 propagate to/from the CTM

To halt everything, write CTIAPPPULSE = 1<<0 on any CTI, or let any core hit a breakpoint. Its cross-halt input fires channel 0, and every core receives a debug request. To restart:

  1. On each core, write CTIINTACK = 1<<0. The debug request output is latched until acknowledged. If you restart without acking, the core halts again at once.
  2. Poll CTITRIGOUTSTATUS bit 0 until it reads 0.
  3. Write CTIAPPPULSE = 1<<1 (channel 1). Every core leaves Debug state, and EDSCR.STATUS passes through 0b000001 to 0b000010.

Cross-halting is not simultaneous. The CTM is usually asynchronous across clock domains, so cores stop at different times, with an implementation-dependent spread that can be many cycles. Do not treat a cross-halt snapshot as a coherent point in time for memory-ordering analysis (7.1).

Authentication: who may halt what

The authentication interface consists of signals driven by the SoC (fuses, life-cycle state, a security controller), and the PE evaluates them through ASL functions:

SignalASL predicatePermits
DBGENExternalInvasiveDebugEnabled()halting and invasive access in Non-secure state
SPIDEN (with DBGEN)ExternalSecureInvasiveDebugEnabled()the same in Secure state
NIDEN, SPNIDENExternal[Secure]NoninvasiveDebugEnabled()trace and PMU counting, before FEAT_Debugv8p4
RLPIDEN (RME)ExternalRealmInvasiveDebugEnabled()Realm state
RTPIDEN (RME)ExternalRootInvasiveDebugEnabled()Root state (EL3 under RME)

With FEAT_Debugv8p4, the separate non-invasive signals are gone in effect: Non-secure non-invasive debug is always permitted (DBGAUTHSTATUS_EL1.NSNID can only read “enabled”), and Secure non-invasive debug follows Secure invasive debug (SNID == SID). DBGAUTHSTATUS_EL1 reports the evaluated result per state (NSID, SID, RLID, RTID, …). It is the register to read when a debugger “can see the core but cannot halt it”. For how the RME signals combine with DBGEN and SPIDEN, see the ASL definitions of these predicates rather than relying on the signal names.

A halting event that is not allowed in the current state does not halt and is not lost if it is a level-held request. External Debug Request stays asserted until acknowledged, so a core running EL3 code with SPIDEN = 0 halts at the first instruction after it enters a state where halting is allowed. Breakpoints, watchpoints and HLT that are not allowed behave as if HDE == 0.

EL3 software has additional controls over register access by an external debugger: MDCR_EL3.EDAD/EDADE (breakpoint, watchpoint and OSLAR_EL1 access per Security state), MDCR_EL3.EPMAD/EPMADE (PMU frame), and ETAD/ETADE (trace). The E...E “extended” bits exist with RME to add Realm to the set. These do not stop halting. They stop a debugger from reprogramming hardware the Secure or Realm world depends on.

Security note: debug authentication is the gate that turns a production device into a development device. For review, the questions are: which life-cycle states drive DBGEN/SPIDEN/RTPIDEN high; whether the signals can change at runtime (an authenticated debug unlock, and what the CPU sees during the transition); whether MEM-APs into Secure or Root memory are gated by the same policy, since an AXI-AP that can issue Secure transactions bypasses the PE’s authentication entirely; and whether MDCR_EL3.EDAD/EPMAD are set when SPIDEN is low.

Debugging across power-down

Pre-DoPD Armv8 splits the external debug registers between a Debug power domain (kept on while debugging, holding for example EDPRSR, EDPRCR.COREPURQ, the EDECR Reset Catch and OS Unlock Catch controls, and the ID registers. The per-field domain is given in each register description) and the Core power domain (everything else, lost on power-down). Using the debug-domain registers:

  • EDPRCR.CORENPDRQ (also visible as DBGPRCR_EL1.CORENPDRQ) asks the power controller to emulate power-down: the core goes through CPU_SUSPEND/CPU_OFF, but its registers survive.
  • EDPRCR.COREPURQ asks for Core power-up so that the debugger can reach a core that is off.
  • EDPRSR.SPD and SR tell the debugger that state was lost and that breakpoints must be reprogrammed.

With FEAT_DoPD, all external debug registers live in the Core power domain. Accesses to a powered-down core return an error, COREPURQ is gone, and power-up requests go through an IMPLEMENTATION DEFINED mechanism, typically a CoreSight Granular Power Requester or the system power controller. CORENPDRQ remains. The OS Double Lock is not permitted with DoPD (16.1).

Touching memory and system registers without side effects

There are two paths, with opposite trade-offs:

  1. Through the halted PE. Use EDITR loads and stores, or memory access mode (EDSCR.MA = 1), where each read of DBGDTRTX executes an implicit LDR W1, [X0], #4 and each write of DBGDTRRX executes an implicit STR. Accesses use the PE’s current translation regime, attributes and caches, so they are coherent with what software sees. They can also allocate cache lines, fill TLBs and move PMU event counts. Breakpoints and watchpoints do not fire, because debug events are not generated in Debug state. They can fault: EDSCR.ERR is set and the fault syndrome appears in the halted context’s ESR/FAR.
  2. Through a MEM-AP. This does not disturb the PE at all. What it sees depends on where the AP sits and on CSW attributes. A non-coherent AXI-AP reading DRAM sees stale data for lines that are dirty in a core’s cache. A debug master on an I/O-coherent (ACE-Lite or CHI RN-I) port that issues cacheable shareable reads snoops the caches and sees current data. Writes through a non-coherent AP can also be overwritten later by a dirty-line eviction (8.7).

Practical rule: for software-visible truth, read through the PE, or clean to PoC first by issuing DC CVAC through EDITR. To inspect memory without changing cache or TLB state, use a coherent MEM-AP. To inspect the caches themselves, use the IMPLEMENTATION DEFINED RAM-index system instructions that many Arm cores provide in Debug state (see the core TRM). These are core-specific, not architectural.

Validation note: test cross-halt and authentication as properties, not as demos.

  • (1) With all CTIs programmed, pulse channel 0 and check that EDPRSR.HALTED == 1 and EDSCR.STATUS == 0b010011 on every core. Measure the spread using timestamps from each core’s trace, or from CNTVCT_EL0 read in Debug state.
  • (2) Restart without CTIINTACK and expect an immediate re-halt. That proves the latch behaviour.
  • (3) With SPIDEN = 0, assert a debug request while a core spins in Secure EL1. It must not halt until it returns to Non-secure, and DBGAUTHSTATUS_EL1.SID must read 0b10.
  • (4) Power a core down with CORENPDRQ = 0 and confirm that EDPRSR.PU = 0 and SPD = 1, and that core-domain accesses return errors rather than hanging the DAP.

Checkpoint

Q16.2.1 A debugger halts all cores through the CTI, then pulses the restart channel. Every core leaves Debug state and immediately halts again with EDSCR.STATUS == 0b010011. What was missed?

  • A. EDRCR.CSE was not written, so the sticky error flag forced a re-halt
  • B. The debug request trigger output was not acknowledged with CTIINTACK, so it was still asserted
  • C. EDSCR.HDE must be cleared before restarting
  • D. Restart must be requested through EDPRCR, not the CTI
Answer

B. CTI output trigger 0 (debug request) stays asserted until it is acknowledged through CTIINTACK. Restarting with it still high is an External Debug Request again, which is exactly STATUS 0b010011. EDRCR.CSE clears EDSCR.ERR, and a sticky error causes no halt, which rules out A. Exit from Debug state is architecturally only through the CTI restart trigger, so D is backwards.

Read more: Arm ARM (DDI0487), “Cross-triggers” chapter, CTIINTACK, EDSCR

Q16.2.2 On a halted core, a debugger reads a buffer through a non-coherent AXI-AP and through the PE in memory access mode, and gets different data. Software on the core had just written the buffer through a Write-Back mapping. Which statement is correct?

  • A. The AP is correct. Memory access mode reads through a separate debug cache
  • B. The difference shows a coherency bug in the interconnect
  • C. The PE path is software-visible truth. The AP read DRAM while the new data was still dirty in the core’s cache
  • D. Both are UNKNOWN until the core is restarted
Answer

C. Memory access mode executes ordinary loads in the PE’s translation regime, so it hits the dirty lines. A non-coherent AP issues transactions that do not snoop the CPU caches, so it sees memory below the cache. That is expected behaviour, not a bug: the AP is not part of the coherent domain, which rules out B. Issue DC CVAC through EDITR first if you need the AP view to agree.

Read more: Arm ARM (DDI0487), “Memory access mode”, EDSCR.MA. ADIv6, “MEM-AP” CSW

Q16.2.3 On a production-fused part, DBGEN = 1 and SPIDEN = 0. A core executing BL31 at EL3 receives an External Debug Request. What happens?

  • A. The request stays pending. The core halts once it is executing in a state where halting is allowed, for example after ERET to Non-secure EL1 or EL2
  • B. The core halts at EL3, but EDITR instructions are ignored
  • C. The request is dropped and the debugger must re-issue it
  • D. The core takes a Debug exception to EL3 instead
Answer

A. Halting is not allowed in Secure state (EL3 without RME) when ExternalSecureInvasiveDebugEnabled() is FALSE. External Debug Request is a level held by the CTI output until it is acknowledged, so it takes effect at the first point where halting is allowed. It is not dropped, which rules out C. Halting events never turn into exceptions, which rules out D.

Read more: Arm ARM (DDI0487), “Halting allowed and halting prohibited”, DBGAUTHSTATUS_EL1

16.3 PMUv3

The Performance Monitors Extension (FEAT_PMUv3) is the per-PE event counting block. It is optional in the architecture but present on effectively every A-profile core. This section covers its programming model: counters, filtering, prohibition and the extensions up to PMUv3p9. Using the counts as a validation oracle is the subject of 16.5. The version is in ID_AA64DFR0_EL1.PMUVer (0b0001 PMUv3, 0b0100 p1, 0b0101 p4, 0b0110 p5, 0b0111 p7, 0b1000 p8, 0b1001 p9; 0b1111 means an IMPLEMENTATION DEFINED non-PMUv3 PMU). This field uses the PMU’s alternative ID scheme, not the signed/unsigned rule of 1.1.

Registers

RegisterRole
PMCR_EL0global control and N (number of event counters, up to 31)
PMEVCNTR<n>_EL0, PMEVTYPER<n>_EL0event counter n and its event/filter selection
PMCCNTR_EL0, PMCCFILTR_EL064-bit cycle counter and its filter
PMCNTENSET/CLR_EL0per-counter enable (bit 31 = cycle counter, bit 32 = instruction counter, p9)
PMOVSSET/CLR_EL0overflow status
PMINTENSET/CLR_EL1overflow interrupt enable
PMSELR_EL0 + PMXEVTYPER/PMXEVCNTR_EL0indirect access by index
PMCEID0/1_EL0which common events are implemented
PMUSERENR_EL0EL0 access (EN, SW, CR, ER, and from p9 UEN, IR, TID)
PMSWINC_EL0software increment (event 0x00)

PMCR_EL0 bits: E [0] enable all, P [1] reset event counters, C [2] reset cycle counter, D [3] divide cycle counter by 64 (deprecated in AArch64), X [4] export events to trace, DP [5] disable the cycle counter where event counting is prohibited, LC [6] cycle counter overflows at 64 bits, LP [7] event counters overflow at 64 bits (p5), FZO [9] freeze on overflow (p7), N [15:11], IDCODE [23:16], IMP [31:24], FZS [32] freeze on an SPE buffer event.

A counter counts only when PMCR_EL0.E, its PMCNTENSET bit, its filter and the prohibition rules below all allow it. Event numbers 0x0000–0x003F and 0x4000–0x403F are the common architectural and microarchitectural events, reported in PMCEID0/1_EL0. PMUv3p8 extends the common space to 0x0040–0x00BF and 0x4040–0x40BF, and removes the CONSTRAINED UNPREDICTABLE behaviour of selecting an unimplemented event. Everything else is IMPLEMENTATION DEFINED per core.

Filtering by Exception level and Security state

PMEVTYPER<n>_EL0 (and PMCCFILTR_EL0, with evtCount RES0) filter with a scheme that confuses everyone once:

BitFieldRule
31P1: do not count at EL1
30U1: do not count at EL0
29NSKNon-secure EL1 is counted only if NSK == P
28NSUNon-secure EL0 is counted only if NSU == U
27NSH1: count at (Non-secure) EL2
26MEL3 is counted only if M == P
25MTFEAT_MTPMU: count events from all threads of the core
24SHSecure EL2 is counted only if SH != NSH
22:20RLK, RLU, RLHRME: Realm EL1 is counted only if RLK == P, Realm EL0 only if RLU == U, and Realm EL2 only if RLH != NSH (the SH rule)
15:0evtCountevent number (16 bits from p1)

P and U set a baseline, and the per-state bits flip it. So P=0, M=0 counts EL1 and EL3, and to count “EL1 but not EL3” you must set M=1. EL2 is excluded by default (NSH=0).

Above the filter sit the prohibition controls. These are owned by higher ELs and the filter cannot override them:

  • MDCR_EL3.SPME [17]: 0 prohibits counting in Secure state (and, with p7 and MPMX == 0, at EL3). It resets to 0, so out of reset the Secure world is invisible to the PMU. Before FEAT_Debugv8p2 the decision also involved the SPNIDEN authentication signal (16.2).
  • MDCR_EL3.SCCD [23] (p5): prohibits the cycle counter in Secure state and at EL3.
  • MDCR_EL3.MPMX [35] and MCCD [34] (p7): MPMX = 1 prohibits counting at EL3, independently of the rest of the Secure state, and MCCD = 1 stops PMCCNTR_EL0 at EL3. TF-A sets SPME = 0, SCCD = 1, MCCD = 1 and MPMX = 0. Firmware cycles are therefore never attributed to Normal-world measurements, but they are lost from the timeline.
  • MDCR_EL2.HPMD [17] (p1) prohibits counting at EL2, and HCCD [23] (p5) does the same for the cycle counter.
  • MDCR_EL2.HPMN [4:0] splits the counters into a first range [0, HPMN), owned by EL1/EL0, and a second range [HPMN, N), owned by EL2. At EL1, PMCR_EL0.N reads as HPMN. MDCR_EL2.HPME enables the second range, and HLP (p5) sets its overflow width.
  • PMCR_EL0.DP: when 1, the cycle counter obeys the same prohibitions as the event counters. When 0, many of the controls above leave PMCCNTR_EL0 running.

Traps: MDCR_EL3.TPM [6] and MDCR_EL2.TPM [6]/TPMCR [5] trap PMU accesses. PMUSERENR_EL0 gates EL0.

Security note: a cycle or event counter that runs across a world switch is a timing side channel into the Secure or Realm world. Keep SPME = 0, set SCCD/MCCD and keep PMCR_EL0.DP = 1. When the Secure world wants its own profiling, context-switch the PMU in the SPMC rather than relaxing SPME globally. See 14.7 for the wider world-switch hygiene.

A minimal counting sequence

    // EL1: count INST_RETIRED (0x08) at EL0+EL1 only, plus cycles, 64-bit cycle counter
    mov     x0, #0x08
    orr     x0, x0, #(1 << 26)        // M=1 != P=0  -> exclude EL3
    msr     pmevtyper0_el0, x0        // NSH=0 -> exclude EL2
    mov     x0, #(1 << 26)
    msr     pmccfiltr_el0, x0
    mov     x0, #1                    // counter 0
    orr     x0, x0, #(1 << 31)        // cycle counter
    msr     pmcntenset_el0, x0
    mrs     x0, pmcr_el0
    orr     x0, x0, #(1 << 6)         // LC
    orr     x0, x0, #0x7              // E | P | C (reset both, enable)
    msr     pmcr_el0, x0
    isb                               // counting is not guaranteed to start before this
    // ... measured code ...
    isb
    mrs     x1, pmevcntr0_el0
    mrs     x2, pmccntr_el0

PMU register writes are ordinary system-register writes. A context synchronization event (ISB) is what guarantees that the enable takes effect for following instructions. Without the second ISB, the MRS can execute out of order with the code under measurement. Counts of speculative events (INST_SPEC, cache refills) include work from mis-speculated paths, and even INST_RETIRED is attributed at a boundary the architecture does not make cycle-exact.

Multi-core counting pitfalls

  • Counters are per PE. No architectural “start all cores” exists: each core sets its own PMCR_EL0.E, so start skew is the IPI latency. There is no architected CTI output that starts or stops PMU counting. The CTI can only broadcast a PMU overflow (CTI input 1) to other cores, for example to cross-halt them (16.2), and with FEAT_PMUv3_SS a capture event takes a snapshot (below). The practical approach is to read CNTVCT_EL0 next to every sample and align the samples afterwards.
  • Heterogeneous clusters have different PMCEID sets and different IMPLEMENTATION DEFINED event numbers. The same raw event number can mean different things on a big core and a LITTLE core, which is why Linux registers one PMU instance per core type.
  • Migration: an OS that moves a thread between cores mid-measurement mixes counters unless it virtualises them (perf does, a bare-metal harness usually does not).
  • SMT/MT: with FEAT_MTPMU, the MT bit decides whether events from sibling threads are included. Since v8.6 an IMPLEMENTATION DEFINED alternative is no longer permitted.
  • Low-power states: whether CPU_CYCLES and PMCCNTR_EL0 advance in WFI depends on the clocking and is effectively IMPLEMENTATION DEFINED. The counters are in the Core power domain and are lost on power-down unless firmware or the OS saves them.
  • Overflow interrupt: a PPI, INTID 23 by BSA/SBSA convention, so it is per-PE by construction. Its interaction with PMCR_EL0.FZO is covered below.

The extensions

FeatureVersionAdds
FEAT_PMUv3p1v8.116-bit evtCount, MDCR_EL2.HPMD
FEAT_PMUv3p4v8.4PMMIR_EL1 (used in 16.5)
FEAT_PMUv3p5v8.564-bit event counters (PMCR_EL0.LP, MDCR_EL2.HLP), MDCR_EL3.SCCD, MDCR_EL2.HCCD
FEAT_PMUv3p7v8.7PMCR_EL0.FZO, MDCR_EL2.HPMFZO (freeze on overflow), MDCR_EL3.MPMX/MCCD
FEAT_PMUv3p8v8.8wider common event space, defined behaviour for unimplemented events
FEAT_PMUv3_THv8.8threshold counting: PMEVTYPER<n>_EL0.TH [43:32] and TC [63:61], width in PMMIR_EL1.THWIDTH
FEAT_PMUv3p9v8.9PMUSERENR_EL0.UEN with PMUACR_EL1, EDECR.PME
FEAT_PMUv3_ICNTRv8.9fixed instruction counter PMICNTR_EL0 + PMICFILTR_EL0
FEAT_PMUv3_SSv8.9snapshots: PMSSCR_EL1, PMEVCNTSVR<n>_EL1, PMCCNTSVR_EL1, PMICNTSVR_EL1
FEAT_PMUv3_EXT64v8.964-bit external (memory-mapped) PMU interface

The pN versions are cumulative, and each one requires the previous. A PE of architecture version v8.x that implements FEAT_PMUv3 must report at least the highest pN at or below x. For example, a v8.7 PE with a PMU cannot report p5. The _TH, _ICNTR, _SS, _EDGE and _EXT64 features remain optional. For the exact rules, see the PMUVer field description and DDI0487 A2.

Freeze on overflow (p7). With PMCR_EL0.FZO = 1, the first-range counters (and the cycle counter if DP = 1, and the instruction counter) stop while any first-range overflow flag in PMOVSCLR_EL0 is set. Without it, counters keep running in the window between the overflow and the interrupt handler reading them, which skews ratios computed in the handler. MDCR_EL2.HPMFZO does the same for the second range.

Thresholding (FEAT_PMUv3_TH). For events that can increment by more than 1 per cycle (for example “operations retired” on a wide core, or occupancy-style events), TC selects a comparison of the per-cycle increment against TH: not-equal, equal, greater-or-equal or less-than. Each has a variant that adds the increment and a “count” variant that adds 1 per qualifying cycle. “Cycles with at least 4 retirements” becomes a single counter, TC=0b101, TH=4. FEAT_PMUv3_EDGE adds edge detection (count transitions), and FEAT_PMUv3_TH2 can chain the even/odd counter pair.

EL0 access (p9). The legacy PMUSERENR_EL0.{EN,ER,CR,SW} is all-or-nothing. With UEN = 1, EL0 can access only the counters whose bits are set in PMUACR_EL1 (P[30:0] event counters, C [31] cycle, F0 [32] instruction counter), while PMCR_EL0 stays trapped. IR makes the instruction counter read-only at EL0. This lets a kernel give a user-space JIT or profiler direct MRS access to its own counters.

Fixed instruction counter (FEAT_PMUv3_ICNTR). PMICNTR_EL0 counts INST_RETIRED without using an event counter. It is filtered by PMICFILTR_EL0 with the same P/U/NSK/... scheme and controlled at bit 32 (F0) of PMCNTENSET, PMOVSSET and related registers.

Snapshots (FEAT_PMUv3_SS). Writing PMSSCR_EL1.SS = 1, or an external capture event, copies all counters into the shadow ...SVR registers at one instant. SS reads 1 until the capture completes, and NC = 0 reports that a capture has happened. This answers “read 8 counters coherently” without stopping counting. It is gated by MDCR_EL3.EnPMSS and MDCR_EL2.PMSSE.

EXT64. The external (memory-mapped) PMU interface supports 64-bit accesses and maps the upper halves of registers such as PMCR_EL0 and PMEVTYPER<n>_EL0, so an external agent can read a 64-bit counter in one access. With a 32-bit-only interface, the agent must read high, low and high again, and retry if the high word changed.

Bring-up note: TF-A programs the PMU security controls in lib/extensions/pmuv3/, and enables EL2-owned controls such as MDCR_EL2.HPMN = N when EL2 is unused. If Linux reports fewer counters than the TRM promises, check MDCR_EL2.HPMN (EL1 sees PMCR_EL0.N == HPMN) before suspecting the silicon. If Secure-world benchmarks read zero, SPME = 0 is doing its job.

Validation note: filter correctness is a cheap and high-value test. Count INST_RETIRED with {P,U,NSK,NSU,M,NSH} swept over all combinations while running a known instruction count at each EL (an SMC round-trip covers EL3, an HVC covers EL2). Every combination has a closed-form expected result, and a mismatch is an RTL or model bug in filter decode. Repeat with MDCR_EL3.SPME, MPMX and PMCR_EL0.DP toggled to check the prohibition priority, and with FZO = 1 and a counter preloaded to 0xFFFF_FFFF (LP = 0) to check that counting freezes on the overflow cycle.

Checkpoint

Q16.3.1 Firmware with EL3 implemented sets PMEVTYPER0_EL0 = 0x08 (INST_RETIRED, all filter bits zero), and MDCR_EL3.SPME = 1. Normal-world software reads a count that is noticeably larger than the instruction count of its loop, which contains SMC calls. Why?

  • A. INST_RETIRED counts speculatively executed instructions
  • B. NSK = 0 with P = 0 excludes Non-secure EL1, so the count comes only from EL3
  • C. The counter is 32-bit and wrapped
  • D. M == P == 0, so EL3 is counted, and with SPME = 1 so is Secure state, which includes the firmware run by each SMC
Answer

D. EL3 is counted when M == P, and with SPME=1 nothing prohibits Secure counting. Excluding EL3 needs M = 1, and excluding Secure EL1 and EL0 relies on keeping SPME = 0. Option A is wrong because INST_RETIRED counts architecturally executed instructions (INST_SPEC is the speculative one). Option B inverts the rule: Non-secure EL1 is counted when NSK == P.

Read more: Arm ARM (DDI0487), PMEVTYPER<n>_EL0, MDCR_EL3.SPME, “Prohibiting event and cycle counting”

Q16.3.2 An overflow handler computes IPC from two counters that were configured to overflow together. The ratios are noisy. Which PMUv3 extension addresses the skew most directly?

  • A. FEAT_PMUv3p5 64-bit counters, because overflow becomes rarer
  • B. FEAT_PMUv3p7 PMCR_EL0.FZO, which stops the affected counters while an overflow flag is set, so the handler reads values frozen at the overflow
  • C. FEAT_PMUv3_TH thresholding
  • D. PMUACR_EL1, so EL0 can read the counters faster
Answer

B. Without freeze, both counters keep counting until the handler’s MRS, including the handler’s own instructions. FZO freezes the counters at the overflow. Option A reduces how often the problem occurs but not the skew when it does. FEAT_PMUv3_SS snapshots would also help, but they are not offered here.

Read more: Arm ARM (DDI0487), PMCR_EL0.FZO, MDCR_EL2.HPMFZO

Q16.3.3 A Linux guest under KVM sees PMCR_EL0.N == 4 on a core whose TRM documents 6 event counters. Which is the most likely explanation?

  • A. MDCR_EL2.HPMN == 4. EL1 sees only the first range, and counters 4–5 are reserved to EL2
  • B. MDCR_EL3.SPME == 0 hides counters from the Normal world
  • C. The core implements PMUv3p1 only, which caps N at 4
  • D. PMUSERENR_EL0.EN == 0 reduces N as seen from EL1
Answer

A. PMCR_EL0.N reads as HPMN from EL1 and EL0 when EL2 is implemented and enabled. That is how a hypervisor partitions the counters. SPME prohibits counting in Secure state and does not change N, which rules out B. PMUSERENR_EL0 controls only EL0 access, which rules out D.

Read more: Arm ARM (DDI0487), MDCR_EL2.HPMN, PMCR_EL0.N

16.4 Activity Monitors (AMU)

The Activity Monitors Extension is a second, separate set of per-PE counters. It is built for always-on activity accounting by firmware and power-management software (frequency invariance, power and thermal control, MPMM-style throttling), not for profiling. FEAT_AMUv1 is optional from v8.4, and FEAT_AMUv1p1 (virtual offsets and auxiliary-counter restriction) is optional from v8.6. Both are reported by ID_AA64PFR0_EL1.AMU (0b0001 v1, 0b0010 v1p1). An external, memory-mapped view (FEAT_AMU_EXT32/EXT64) can exist next to the system registers.

Counter groups

Group 0: architected counters. Their events are fixed by the architecture, and AMEVTYPER0<n>_EL0 is read-only:

CounterevtCountEvent
AMEVCNTR00_EL00x0011processor frequency cycles (CPU_CYCLES)
AMEVCNTR01_EL00x4004constant frequency cycles (CNT_CYCLES), at the System Counter rate
AMEVCNTR02_EL00x0008instructions retired (INST_RETIRED)
AMEVCNTR03_EL00x4005memory stall cycles (STALL_BACKEND_MEM)

Group 1: auxiliary counters. There are up to 16, AMEVCNTR1<n>_EL0, whose events in AMEVTYPER1<n>_EL0 are IMPLEMENTATION DEFINED. An event may be fixed in hardware, in which case the type register is read-only. With v1p1, AMCG1IDR_EL0 reports which auxiliary counters exist (bits [15:0]) and which have a virtual offset register (bits [31:16]), because the implemented set need not be contiguous.

All counters are 64 bits wide (AMCFGR_EL0.SIZE == 0b111111). They have no overflow interrupt: at gigahertz rates, 64 bits do not wrap within the lifetime of the part.

Configuration and identification registers

  • AMCFGR_EL0: N [7:0] is the total number of counters minus one, SIZE [13:8] the counter width minus one, HDBG [24] reports that AMCR_EL0.HDBG is supported, and NCG [31:28] is the number of groups minus one.
  • AMCGCR_EL0: CG0NC [7:0] and CG1NC [15:8] give the number of counters in group 0 (4 in AMUv1) and in group 1.
  • AMCR_EL0: HDBG [10] stops counting while the PE is halted in Debug state (16.2). CG1RZ [17] (v1p1) makes system-register reads of the group 1 counters return zero at every EL except the highest implemented one.
  • AMCNTENSET0/CLR0_EL0 and AMCNTENSET1/CLR1_EL0: per-counter enables.

Who controls what

The AMU is controlled only from the highest implemented EL, which on most systems is EL3. MSR to AMCNTENSET0_EL0 and AMEVCNTR0<n>_EL0 is UNDEFINED below that EL, and so are the other enable, control and counter writes. Lower ELs can only read, subject to these traps:

ControlEffect
CPTR_EL3.TAM [30]1: EL2, EL1 and EL0 accesses to all AMU registers trap to EL3 (EC 0x18). Must be cleared for Linux to use the AMU
CPTR_EL2.TAM [30]1: EL1/EL0 accesses trap to EL2
AMUSERENR_EL0.EN [0]0: EL0 accesses trap to EL1 (or to EL2 if HCR_EL2.TGE == 1)
HAFGRTR_EL2 (FEAT_FGT)per-counter fine-grained read traps to EL2

Counter writes have one more trap: writing a counter while it is enabled has UNPREDICTABLE results. The architected counters reset to 0 on an AMU reset, which the architecture does not tie to a PE Warm reset. Firmware therefore cannot assume that the counters are zero, or even disabled, when it starts.

AMUv1p1 virtual offsets

A guest that reads the AMU to compute its own frequency or utilisation should see counts relative to its timeline. FEAT_AMUv1p1 adds AMEVCNTVOFF0<n>_EL2 (for n = 0, 2, 3) and AMEVCNTVOFF1<n>_EL2. When

  • SCR_EL3.AMVOFFEN [35] == 1, and
  • HCR_EL2.AMVOFFEN == 1, and
  • EL2 is enabled in the current Security state and HCR_EL2.{E2H,TGE} is not {1,1},

a read from EL1 or EL0 returns physical count − offset. Reads at EL2 and EL3 always return the physical count. Counter 1 has no offset register of its own: the constant-frequency counter uses CNTVOFF_EL2, keeping it in step with the guest’s virtual counter (4.7). With SCR_EL3.AMVOFFEN == 0, EL2 accesses to the offset registers trap to EL3 and the offsets read as zero for the subtraction. That is the safe default when EL3 does not context-switch them.

TF-A: enabling, restricting and saving

TF-A’s AMU support is in lib/extensions/amu/aarch64/amu.c, built with ENABLE_FEAT_AMU, ENABLE_FEAT_AMUv1p1, ENABLE_AMU_AUXILIARY_COUNTERS and AMU_RESTRICT_COUNTERS (default 1). The current code does the following (structure as of recent TF-A releases):

  • Per world: it clears CPTR_EL3.TAM, so that lower ELs can read the counters.
  • Per CPU context: on v1p1 parts it sets SCR_EL3.AMVOFFEN in the context’s saved SCR_EL3, so that EL2 accesses to the offset registers do not trap and a hypervisor can own the offsets.
  • Per CPU at EL3 init: it enables all four architected counters (AMCNTENSET0_EL0). If auxiliary counters are configured, it enables the platform-specified ones. On v1p1 parts with AMU_RESTRICT_COUNTERS, it sets AMCR_EL0.CG1RZ, so that IMPLEMENTATION DEFINED auxiliary events read as zero outside EL3. It leaves HDBG at 0.
  • When EL2 is unused: it clears CPTR_EL2.TAM and, on v1p1 parts, HCR_EL2.AMVOFFEN, so that no virtual offset is applied.
  • Across power-down: the counters are in the Core power domain and are lost on power-down. TF-A subscribes to the PSCI psci_suspend_pwrdown_start and psci_suspend_pwrdown_finish events. On the way down, it disables the counters first (followed by an ISB), so that the saved values form one consistent snapshot, and then saves group 0 and the implemented group 1 counters. On the way up, it disables the counters if the AMU was not reset, writes the saved values, and re-enables the counters.
  • Across world switches: the instructions-retired and memory-stall counters (AMEVCNTR02/03_EL0) are saved and restored per Security state by the context-management code. Normal-world software therefore does not see instructions retired by Secure-world firmware, while the two cycle counters stay global.

Bring-up note: Linux’s frequency-invariance code (arch/arm64/kernel/topology.c) samples counters 0 and 1 on each scheduler tick and assumes they are monotonic across idle. When AMU save/restore is missing or broken, counter 0 restarts from an UNKNOWN value after the first CPU_SUSPEND power-down, and the frequency scale factor jumps. If EL3 leaves CPTR_EL3.TAM = 1, the kernel’s first AMU read traps to EL3 as an unexpected system-register trap. Depending on the TF-A version and configuration this ends in a panic or an exception injected back to the kernel, so check TAM first when an early AMU read hangs.

AMU versus PMU

PMU (16.3)AMU
Purposeprofiling and debugalways-on activity accounting
Owner of configurationEL0–EL3, with prohibition by higher ELshighest EL only. Lower ELs can only read
Event choiceany of dozens of common events plus IMPLEMENTATION DEFINED events, per counterfixed group 0, IMPLEMENTATION DEFINED group 1
EL/Security filteringPMEVTYPER filter bits and MDCR_EL3.SPMEnone in the counter. Firmware swaps counter values per world
Width / overflow32 or 64-bit, overflow interrupt64-bit, no interrupt
Freeze in Debug stateno dedicated control bit (see the PMU chapter of DDI0487 for Debug-state counting rules)AMCR_EL0.HDBG
VirtualisationMDCR_EL2.HPMN partition, trap-and-emulatev1p1 offsets subtracted in hardware
Typical consumerperf, validationcpufreq/schedutil, SCMI power agents, TF-A MPMM

The most important difference is that the AMU counts everything the PE does, whatever the Exception level or Security state, because there is no filter. That is what makes it trustworthy for power management, and also what makes it a side-channel concern. TF-A therefore restricts group 1 by default and per-world-swaps the instruction and stall counts.

Security note: group 0 INST_RETIRED and STALL_BACKEND_MEM counted across an SMC reveal how much work, and how much memory stall, the Secure world performed for a given request, and a cache-timing attacker can use that. Auxiliary events can be finer-grained still. In review, check that AMU_RESTRICT_COUNTERS stays enabled, that the per-world swap of counters 2 and 3 is in place for every world, including Realm under RME, and that no Secure Partition is given AMU access it does not need.

Validation note: five properties are worth automating.

  • (1) Monotonicity across CPU_SUSPEND power-down: read AMEVCNTR00/01_EL0 before and after and require after ≥ before. A failure is missing or misordered save/restore.
  • (2) Ratio sanity: over a fixed interval, ΔAMEVCNTR01 / ΔCNTPCT_EL0 must equal 1 while the core is running. Any drift means counter 1 is not on the System Counter clock.
  • (3) ΔAMEVCNTR00 / ΔAMEVCNTR01 must match the configured DVFS ratio.
  • (4) With CG1RZ = 1, group 1 reads at EL1 must return 0 while the memory-mapped view still counts.
  • (5) With v1p1, a write to AMEVCNTVOFF00_EL2 must shift EL1 reads by exactly the offset and leave EL2 reads unchanged.

Checkpoint

Q16.4.1 After a CPU_SUSPEND power-down and resume, Linux’s frequency-invariance code sees AMEVCNTR00_EL0 go backwards. TF-A’s AMU save/restore is enabled. Which ordering bug in a platform’s own port is most consistent with this?

  • A. The restore wrote the counters after ISB rather than before
  • B. AMCR_EL0.HDBG was left at 0
  • C. The save path read the counters without disabling them first, or the restore path wrote them while they were enabled. Either makes the written value UNPREDICTABLE or inconsistent
  • D. SCR_EL3.AMVOFFEN was 0, so EL1 reads subtracted a stale offset
Answer

C. Writes to an enabled AMU counter are UNPREDICTABLE, and the AMU may not have been reset with the PE, so its enable state at resume cannot be assumed. TF-A disables the counters before saving and before restoring for exactly this reason. Option D is backwards: with AMVOFFEN == 0 the offsets are treated as zero, so no subtraction happens. HDBG matters only in halting Debug state, which rules out B.

Read more: Arm ARM (DDI0487), AMEVCNTR0<n>_EL0, AMCNTENSET0_EL0; TF-A lib/extensions/amu/aarch64/amu.c

Q16.4.2 A hypervisor at EL2 wants a guest’s reads of AMEVCNTR01_EL0 to exclude time when the guest was descheduled. Which register does it adjust?

  • A. AMEVCNTVOFF01_EL2
  • B. CNTVOFF_EL2, because the constant-frequency counter’s virtual offset is the generic timer virtual offset
  • C. AMEVTYPER01_EL0, to change the event to a guest-only event
  • D. None: the AMU cannot be virtualised, so the read must be trapped with CPTR_EL2.TAM and emulated
Answer

B. AMEVCNTVOFF0<n>_EL2 exists only for n = 0, 2 and 3, and accessing n = 1 is UNDEFINED, which rules out A. The constant-frequency counter is defined to use CNTVOFF_EL2, so it stays consistent with CNTVCT_EL0. Trap-and-emulate (D) works, but it is unnecessary with FEAT_AMUv1p1. Group 0 event types are read-only, which rules out C.

Read more: Arm ARM (DDI0487), AMEVCNTVOFF0<n>_EL2, SCR_EL3.AMVOFFEN, HCR_EL2.AMVOFFEN

Q16.4.3 A team proposes using the AMU instead of the PMU to measure the instruction count of a Normal-world benchmark “because the AMU cannot be disabled by the OS”. What is the main flaw in that reasoning?

  • A. AMU counters have no EL or Security filter, so the raw count includes EL2/EL3/Secure work, and firmware may swap counters 2 and 3 per world, so the result depends on firmware policy rather than on the benchmark
  • B. The AMU’s INST_RETIRED counts speculative instructions
  • C. EL1 can reprogram AMEVTYPER02_EL0 to a different event
  • D. AMU counters are only 32 bits wide and wrap during long benchmarks
Answer

A. The AMU counts everything the PE does. Whether Normal-world reads include Secure-world instructions depends on what EL3 context-switches, and current TF-A swaps counters 2 and 3 per world. It is an accounting tool, not a filtered profiler. Group 0 types are architecturally fixed, which rules out C, and the counters are 64-bit, which rules out D.

Read more: Arm ARM (DDI0487), “The Activity Monitors Extension”, AMEVTYPER0<n>_EL0

16.5 The PMU as a validation instrument

16.3 covers how to program PMUv3. This section is about using the counts as evidence. Many memory-system properties have no architecturally visible result: a mis-programmed MAIR_EL1 that makes a buffer Write-Back instead of Non-cacheable still returns the right data. A TLBI that misses its target still “works” until the stale entry is used, and a speculation barrier that does nothing looks identical to one that works. Event counts turn these invisible properties into numbers that a directed test can check.

Ground rules for counting as an oracle

The architecture defines event numbers and their intent, but leaves exactly what is counted largely to the implementation:

  • Architectural events (INST_RETIRED 0x08, EXC_TAKEN 0x09, BR_RETIRED 0x21, LD_RETIRED/ST_RETIRED 0x06/0x07 where implemented) count things defined by the instruction stream. They are the stable reference.
  • Microarchitectural events (L1D_CACHE_REFILL 0x03, L1D_TLB_REFILL 0x05, INST_SPEC 0x1B, BUS_ACCESS 0x19, DTLB_WALK 0x34 and so on) have common numbers, but whether a given access counts (a prefetch, a speculative access, a walk that hits a walk cache) is IMPLEMENTATION DEFINED. Check the core’s TRM.
  • Presence is discoverable: PMCEID0_EL0/PMCEID1_EL0 (and the upper halves for 0x4000+ events) report which common events are implemented. A test must skip, not fail, when an event is absent.
  • Accuracy: the Arm ARM does not require exact counts in general. Counting near a boundary such as an exception entry, a filter change or an ISB may be off by a small number of events. Design tests so that the expected outcomes differ by orders of magnitude (“≈0 vs ≈N”), not by a few counts.

Bracket the region of interest with context synchronization, so that the counter enable and the read are not reordered with the code under test:

    // x0 = event number, counter 0. Assumes PMCR_EL0.E = 1 and filtering set (16.3)
    msr   PMEVTYPER0_EL0, x0
    msr   PMEVCNTR0_EL0, xzr
    mov   x1, #1
    msr   PMCNTENSET_EL0, x1
    isb                         // counter enabled before the test region starts
    bl    test_body
    isb                         // test region's instructions have executed
    mrs   x2, PMEVCNTR0_EL0

The ISB bounds the instruction stream. Memory accesses still outstanding (a posted store, or a refill in flight) may be counted after the read. If the event concerns memory traffic, put a DSB before the final ISB (7.6). Filter by EL (PMEVTYPER<n>_EL0.P/U/NSK/NSH/M) so that an interrupt handler running during the test does not contaminate the count. Better still, mask interrupts and confirm that EXC_TAKEN is 0 over the region.

Oracle 1: memory attributes

A cacheability bug never produces wrong data on a single PE. It only changes performance, or, with a non-coherent agent, breaks a DMA protocol later (8.7). The PMU makes it visible directly:

TestMappingExpected L1D_CACHE_REFILL per passExpected BUS_ACCESS
Stream reads over a buffer 4× L1D size, twiceNormal WB, Inner Shareable≈ size / line size on each pass≈ refills × (line / bus width)
Same bufferNormal Non-cacheable≈ 0≈ size / access size, or less if the core gathers accesses
Same buffer, fits in L1DNormal WB≈ size / line on pass 1, ≈ 0 on pass 2≈ 0 on pass 2
Same bufferDevice-nGnRE≈ 0≈ one per access, with no gathering

Interpreting failures:

  • NC mapping but refills ≈ size/line. The effective attribute is Cacheable. Look for a wrong AttrIndx or MAIR slot (6.5), stage 2 combining (with HCR_EL2.FWB stage 2 can force Write-Back: 11.3), or a different alias of the same PA (6.6).
  • WB mapping but refills ≈ 0 and BUS_ACCESS high. Caching is not happening. Check SCTLR_ELx.C, the HCR_EL2.CD/DC bits, and TCR_ELx.IRGN/ORGN for walks.
  • Second pass still refills on a fitting buffer. Either something is cleaning and invalidating (a stray set/way loop), or the lines are being evicted by another agent’s snoops.

Hardware prefetchers make Cacheable refill counts noisy, though not NC ones. Non-cacheable accesses can be speculative, but they do not allocate. Use PMMIR_EL1.BUS_WIDTH (below) to convert BUS_ACCESS into bytes instead of guessing the bus width.

Oracle 2: TLB maintenance effectiveness

The full sequence in 9.1 (store descriptor; DSB ISHST; TLBI; DSB ISH; ISB) can be checked functionally by remapping a page and reading a signature. But that only proves the final translation is right. It cannot tell “the TLBI worked” apart from “the entry was never cached”. Counting can:

  1. Touch N distinct pages (N below the L1 DTLB capacity) twice. On the second pass L1D_TLB_REFILL ≈ 0, which proves the entries are cached.
  2. Issue the maintenance under test: TLBI VAE1IS per page, TLBI ASIDE1IS, or a range TLBI RVAE1IS.
  3. Touch the pages again. DTLB_WALK should be ≈ N, and L1D_TLB_REFILL ≈ N.
Observation after step 3Likely cause
DTLB_WALK ≈ NThe invalidation reached this PE’s TLBs
DTLB_WALK ≈ 0The TLBI targeted the wrong ASID/VMID/regime, the wrong VA (for example a missing >> 12 in the operand), or TTL/range fields excluded the entries
≈ N for the issuing PE, ≈ 0 on a remote PE that also cached themBroadcast failed. Check shareability (an IS vs non-IS op), whether the remote PE has joined the DVM domain (17.5), and interconnect DVM routing
L1 refills ≈ N but DTLB_WALK ≈ 0Only the L1 micro-TLB was invalidated, and the L2 TLB still held the entries. A TLBI must remove matching entries from every level of TLB that caches them, so unless the L2 TLB was legitimately refilled in between (descriptors left valid allow speculative walks to re-cache them, and whether such walks are counted is IMPLEMENTATION DEFINED), this is a candidate core or interconnect bug

For the remote-PE case, run the counter on the other PE, have that PE re-touch the pages after a flag handshake, and read its own count. DTLB_WALK counts data TLB accesses that needed at least one translation table walk access. Walk caches typically hold only table (non-leaf) entries, so a walk after a leaf invalidation still fetches the leaf descriptor and is counted; whether a walk fully satisfied from internal structures counts is IMPLEMENTATION DEFINED. L2D_TLB_REFILL (0x2D) helps separate the levels.

Validation note: pair the TLBI oracle with an interconnect counter. On a CMN-based system the DVM node counts DVM operations and syncs. A broadcast TLBI ...IS that is not visible as a DVM op at the interconnect, while the local PE does re-walk, means the PE treated it as local. That points at a shareability bug in the maintenance code, or at a PE that is outside the DVM domain because of the DSU/cluster configuration. Confirm with the remote DTLB_WALK count described above.

Oracle 3: speculation

INST_SPEC (0x1B) counts operations speculatively executed, and INST_RETIRED (0x08) counts instructions architecturally executed. Their difference, together with BR_MIS_PRED (0x10) and BR_MIS_PRED_RETIRED (0x22), gives a coarse view of work thrown away. The units differ: INST_SPEC may count micro-operations, so the ratio is only meaningful relative to a baseline on the same core.

Uses in validation:

  • Barrier effectiveness. Train a branch, then mispredict into a region that would issue loads. With SB (or CSDB plus masking, 14.3) placed after the branch, the speculatively executed loads should disappear. The useful counters are an L1D access or refill count on a probe buffer, read only as a performance signal. The architectural proof that a gadget is closed is still a timing-channel test, and the PMU only supports the claim.
  • Predictor invalidation on a world switch. After CFP RCTX/CPP RCTX or a BHB clear (14.4, 14.7), a previously well-trained indirect branch should show a burst of BR_MIS_PRED. If it does not, the restriction did not affect the predictor that the test trained, which is IMPLEMENTATION DEFINED. Report it, but do not treat it alone as an architectural violation.
  • Event filtering leakage. With PMEVTYPER<n>_EL0 filtering out EL3 (and MDCR_EL3.SPME == 0), the counts must not include EL3 work. An SMC-heavy loop is a cheap test that the prohibition works (16.3).

Oracle 4: barrier and maintenance cost

Bring-up questions such as “how long does a DSB ISH take on this die”, “is a DC CIVAC over 1 MB going to the SLC or to DRAM” and “what does a TLBI VMALLE1IS cost across four chiplets” are answered with CPU_CYCLES (or PMCCNTR_EL0) around a loop, as a mean over many iterations:

/* cycles per DSB ISH with k outstanding stores; run on an otherwise idle system */
for (i = 0; i < ITER; i++) {
    for (j = 0; j < k; j++)
        buf[j * 16] = i;            /* separate lines */
    asm volatile("dsb ish" ::: "memory");
}

Sweep k, the memory type of buf and the cluster/die location of the line’s home node. A DSB’s cost is dominated by what has to complete. A flat curve means the stores complete quickly (for example into a nearby SLC). A step at a die boundary shows cross-die completion latency, which also bounds the latency of TLBI broadcast. Most cores also provide the Arm-recommended IMPLEMENTATION DEFINED events ISB_SPEC, DSB_SPEC and DMB_SPEC (commonly 0x7C–0x7E, check the TRM), plus STALL_BACKEND/STALL_BACKEND_MEM to attribute the stall cycles.

PMMIR_EL1: machine description

PMMIR_EL1 (FEAT_PMUv3p4) describes the PMU’s own scaling so that a tool does not hard-code it:

FieldMeaning
SLOTS [7:0]Largest increment of STALL_SLOT per cycle, that is the pipeline width used for top-down analysis: STALL_SLOT / (SLOTS × CPU_CYCLES) is the fraction of slots lost
BUS_SLOTS [15:8]Largest increment of BUS_ACCESS per BUS_CYCLES cycle
BUS_WIDTH [19:16]Bytes per BUS_ACCESS, encoded as a power of two (0 = not specified)
THWIDTH [23:20]Width of the PMEVTYPER<n>_EL0.TH threshold field (FEAT_PMUv3_TH, 16.3)
EDGE [27:24]Edge-detection support (FEAT_PMUv3_EDGE)

Read it once in the test harness and log it with the results. A mismatch between PMMIR_EL1 and the TRM is itself a finding.

System PMUs: counting beyond the PE

The PE PMU sees only the PE’s side of a transaction. To prove where a transaction went, use the system PMUs:

  • CMN interconnect PMU. Each crosspoint has a Debug/Trace Monitor (DTM) with a few local counters and flit watchpoints, aggregated into global counters in the Debug/Trace Controller (DTC). Node-specific events include HN-F SLC hits and misses, snoop-filter activity and PoC queue occupancy, and DVM node operations. Typical checks: whether a DC CVAC loop actually generates CleanShared requests at the HN-F (8.3), whether a “Non-shareable” buffer is generating snoops, and how traffic splits across per-die SLCs. The event list is product-specific (CMN-600/650/700/S3 differ). Linux arm-cmn exposes it, but on pre-silicon you program the PMU registers through MMIO directly.
  • SMMU PMCG (Performance Monitor Counter Group, defined in SMMUv3, IHI0070). Each TCU/TBU may have one. The architected events are cycles (0), transactions (1), TLB misses (2), configuration cache misses (3), translation table walk accesses (4), configuration structure accesses (5), and PCIe ATS translation requests received (6) and ATS-translated transactions passed through (7). Counters can be filtered by StreamID through SMMU_PMCG_SMR<n> with a span option. Use it to check that a device’s DMA really goes through translation (transactions > 0 for its StreamID), and that invalidating with CMD_TLBI_* causes walks (11.5). In ACPI, PMCGs are IORT nodes.
  • CoreSight PMU architecture (IHI0091) PMUs in memory controllers, PCIe root complexes, caches and other devices. With ACPI these are described by the APMT (Arm Performance Monitoring Unit Table, DEN0117). Each node gives the PMU’s base address, interrupt, node type (memory controller, SMMU, PCIe root complex, ACPI device, CPU cache) and processor affinity. Linux’s arm_cspmu driver consumes it. Table details are in 18.6.
  • FEAT_SPMU (permitted from v8.8) gives System PMUs a System-register interface (SPMCR_EL0, SPMSELR_EL0 and so on), so some cluster-level PMUs are reachable without MMIO.
  • MPAM monitors (memory-bandwidth and cache-storage usage per PARTID/PMG) are a related family, covered in 8.9.

Bring-up note: system PMUs are often clock- or power-gated, Secure-only by default, or locked behind an IMPLEMENTATION DEFINED “secure access” bit. If every counter reads 0, check the PMU’s own enable and the security configuration of its register frame before suspecting the event. A PMCG or CMN PMU that the firmware leaves Secure-only is a common reason why the OS driver probes but counts nothing.

Checkpoint

Q16.5.1 A test maps a 1 MB buffer as Normal Non-cacheable at stage 1 and streams reads over it twice from EL1 under a hypervisor. L1D_CACHE_REFILL is about 16 K on each pass (64-byte lines). What is the most useful first hypothesis?

  • A. The core’s prefetcher is refilling Non-cacheable lines, which the architecture permits
  • B. The PMU counts Non-cacheable accesses as refills, so the test is invalid
  • C. The effective memory type is Cacheable, for example because stage 2 with HCR_EL2.FWB == 1 forces Write-Back, or because a Cacheable alias is in use
  • D. The TLB is missing on every line, and each miss is counted as a refill
Answer

C. A refill count of ≈ size/line, repeated on the second pass, is the signature of Cacheable lines being allocated and evicted. Non-cacheable accesses do not allocate in the cache, so A describes something that cannot produce refills. B is a possible IMPLEMENTATION DEFINED quirk, but it is the least likely explanation and is checked last, against the TRM. D confuses L1D_CACHE_REFILL with L1D_TLB_REFILL, and 1 MB in 4 KB pages would give ≈ 256 walks, not 16 K.

Read more: Arm ARM (DDI0487), Combining stage 1 and stage 2 memory type attributes; HCR_EL2.FWB; PMU common event L1D_CACHE_REFILL

Q16.5.2 PE0 caches 32 pages in its TLB, then PE1 issues TLBI VAE1IS for each page followed by DSB ISH. PE0 then re-touches the pages and its DTLB_WALK count increases by 0. PE1 re-touching its own copies shows 32 walks. Which conclusion is best supported?

  • A. The invalidation did not reach PE0. Suspect the broadcast path or PE0’s DVM-domain membership before suspecting the maintenance code’s operands
  • B. PE0’s walk cache satisfied the walks, so DTLB_WALK did not count them
  • C. The test is invalid because DTLB_WALK only counts walks caused by instruction fetches
  • D. PE1 forgot the ISB, so its TLBIs were not executed
Answer

A. The same operands invalidated PE1’s own entries (32 walks), so ASID, VA and regime are right, and the difference is whether the broadcast reached PE0. B is the tempting option, but walk caches typically hold table entries, not leaf descriptors, so re-walking an invalidated page still makes a translation table access and is counted; and PE1, with similar walk caches, did see 32 walks. C confuses it with ITLB_WALK. A missing ISB on PE1 (D) affects PE1’s own later instruction stream, not whether its broadcast TLBIs complete, which the DSB ISH guarantees.

Read more: Arm ARM (DDI0487), TLB maintenance instructions, broadcast; PMU common events DTLB_WALK and L1D_TLB_REFILL

Q16.5.3 Why should a validation tool read PMMIR_EL1 rather than hard-code constants from the core’s TRM?

  • A. PMMIR_EL1 reports which common events are implemented
  • B. PMMIR_EL1.SLOTS reports the number of event counters, which varies by core
  • C. It is needed to enable thresholding, which is otherwise UNDEFINED
  • D. It describes the scaling of slot and bus events (SLOTS, BUS_SLOTS, BUS_WIDTH), so that metrics such as slot-loss fraction and bytes transferred are computed correctly on any core
Answer

D. PMMIR_EL1 is the machine-description register for interpreting STALL_SLOT and BUS_ACCESS. Event presence (A) is in PMCEID0/1_EL0. The number of counters (B) is PMCR_EL0.N. THWIDTH reports the threshold width, but reading it is not what enables thresholding (C).

Read more: Arm ARM (DDI0487), PMMIR_EL1; PMCEID0_EL0; PMCR_EL0

16.6 Profiling and trace

Four self-hosted mechanisms record what a PE did without halting it. The PMU (16.3) counts. The three covered here record samples, program flow or recent branches. Two of them (SPE, and ETE when its output goes through TRBE) write into memory buffers that a lower EL owns. BRBE keeps its records in System registers:

MechanismFEAT_RecordsOutputOwner control at EL3
Statistical Profiling (SPE)FEAT_SPE, permitted from v8.1one sampled operation: PC, VA/PA, latencies, events, data sourceProfiling Buffer in memoryMDCR_EL3.NSPB/NSPBE
Embedded Trace (ETE)FEAT_ETE, permitted from v9.0the full program flow (waypoints), with optional timestamps and contexttrace sink, or TRBEMDCR_EL3.STE/TTRF, CPTR_EL3.TTA
Trace Buffer (TRBE)FEAT_TRBE, permitted from v9.0(ETE’s output)Trace Buffer in memoryMDCR_EL3.NSTB/NSTBE
Branch Record Buffer (BRBE)FEAT_BRBE, permitted from v9.1the last n taken branches and exceptionssystem registersMDCR_EL3.SBRBE

From the firmware point of view, the same three questions apply to each. Who owns it? What can leak across a Security state boundary? What must be drained or saved when the owner changes? The bit-by-bit EL3 enable table is in 17.3, and the external authentication signals (NIDEN, SPNIDEN, RLPIDEN) are in 16.2.

SPE

SPE selects one operation every interval (with optional random perturbation), follows it through the pipeline, and writes a record of packets to the Profiling Buffer when it completes.

RegisterRole
PMSCR_EL1 / PMSCR_EL2enables per EL (E0SPE, E1SPE, E0HSPE, E2SPE). PA collects physical addresses, TS timestamps, CX the CONTEXTIDR
PMSIRR_EL1sampling INTERVAL and RND
PMSICR_EL1the internal interval counter, saved and restored on a context switch
PMSFCR_EL1, PMSEVFR_EL1, PMSLATFR_EL1filtering by operation type (B, LD, ST), by events (for example “L1D refill” or “TLB walk”) and by minimum latency
PMBLIMITR_EL1buffer LIMIT, enable E, fill mode FM
PMBPTR_EL1write pointer (a VA in the owning EL’s translation regime)
PMBSR_EL1buffer management status: EC (buffer full, stage 1 or stage 2 fault, GPC fault), S (service), COLL (collision), DL (data lost)
PMSIDR_EL1, PMBIDR_EL1features. PMBIDR_EL1.P = 1 means the buffer is unusable at this EL because of ownership

A buffer management event (buffer full, or a fault on a buffer write) stops collection and asserts the Profiling Buffer management interrupt, a PPI. PSB CSYNC (Profiling Synchronization Barrier) makes sure that all sampled operations before it have written their records, so it is required before reading the buffer and before changing who owns it. It is followed by a DSB so that the buffer writes complete.

Version deltas:

FeatureVersion (per the Arm feature list)Adds
FEAT_SPEv1p1permitted from v8.2alignment-flag event and filter; SVE operation profiling
FEAT_SPEv1p2permitted from v8.6 (v8.7 feature)freeze the PMU on a buffer management event (PMBLIMITR_EL1.PMFZ); discard mode (FM). The separately optional FEAT_SPE_FnE, which requires v1p2, adds the inverted event filter PMSNEVFR_EL1, trapped by MDCR_EL3.EnPMSN
FEAT_SPEv1p3permitted from v8.7 (v8.8 feature)sampling of MTE tag operations and of CPY*/SET* (FEAT_MOPS)
FEAT_SPEv1p4permitted from v8.8 (v8.9 feature)extra data-source information in the Events packet and matching filter bits; data-source filtering (FEAT_SPE_FDS, PMSDSFR_EL1) is a companion feature

v9.5 adds further optional pieces (FEAT_SPE_EXC, which reports buffer events as profiling exceptions, and FEAT_SPE_nVM, which allows a physically addressed buffer). Each new control register comes with its own MDCR_EL3 enable bit (EnPMS3, EnPMS4 and so on), and an EL3 that does not know about one leaves the lower EL trapping.

Security note: with PMSCR_ELx.PA == 1 SPE records physical addresses and data-source information (which cache level or which remote die satisfied a load). That is a strong side channel if the records cover another world’s execution, so EL3 must ensure that SPE never samples in a Security state that does not own the buffer. The ownership encoding does this: profiling is disabled in every Security state that does not own the Profiling Buffer.

ETE, TRBE and FEAT_TRF

ETE is the Armv9 trace unit, and in v9 any PE trace unit must be ETE. It is programmed through TRC* System registers (TRCPRGCTLR, TRCCONFIGR, address comparators and so on), and those accesses are trapped by CPTR_EL3.TTA, CPTR_EL2.TTA and CPACR_EL1.TTA. Its output goes either to an external CoreSight trace sink (ETR or ETF over ATB, see 16.2) or to TRBE, a per-PE unit that writes trace into memory:

RegisterRole
TRBLIMITR_EL1LIMIT, enable E, fill mode FM (fill, wrap, circular), trigger mode TM, nVM (physically addressed buffer)
TRBPTR_EL1, TRBBASER_EL1write pointer and base
TRBSR_EL1management status (EC, IRQ, TRG, WRAP, S, and the buffer or fault status code)
TRBMAR_EL1memory attributes for trace writes
TRBTRG_EL1trigger counter
TRBIDR_EL1features. P = 1 means owned by another EL or state, so programming is not allowed

FEAT_TRF (permitted from v8.3, the v8.4 feature) adds self-hosted trace filtering. TRFCR_EL1 (E0TRE, E1TRE) and TRFCR_EL2 (E0HTRE, E2TRE, CX) prohibit trace generation per EL. TS selects the timestamp (virtual, guest-physical or physical). TSB CSYNC (Trace Synchronization Barrier) orders trace operations against later System register writes. EL3’s controls are MDCR_EL3.STE (when 0, trace is prohibited in Secure state unless the IMPLEMENTATION DEFINED authentication interface overrides it), MDCR_EL3.RLTE for Realm state with RME, and MDCR_EL3.TTRF to trap TRFCR_ELx accesses.

Trace is prohibited by default at EL3, and in Secure state if external authentication does not permit it. A prohibited region produces no trace. It is not hidden later: it is never generated.

BRBE

BRBE keeps the last n taken branches (BRBIDR0_EL1.NUMREC) in three register arrays, readable in banks of 32 selected by BRBFCR_EL1.BANK:

  • BRBSRC<n>_EL1: source address;
  • BRBTGT<n>_EL1: target address;
  • BRBINF<n>_EL1: TYPE (direct, indirect, call, return, ERET, and exception types such as IRQ, SError or trap), the source and target EL, misprediction (MPRED), and an elapsed-cycle count (CC_EXP/CC_MANT).

Controls: BRBCR_EL1/BRBCR_EL2 enable recording per EL (E0BRE, E1BRE, E0HBRE, E2BRE) and select what is captured (CC, MPRED, EXCEPTION, ERTN, TS). FZP freezes recording when a PMU counter overflows, which makes BRBE the “what led to this PMU interrupt” record. BRBFCR_EL1 filters branch types and shows PAUSED. BRB IALL invalidates all records, and BRB INJ injects one from BRBINFINJ_EL1/BRBSRCINJ_EL1/BRBTGTINJ_EL1, which a hypervisor uses to restore a guest’s buffer.

MDCR_EL3.SBRBE [33:32]:

SBRBEAccesses from EL0–EL2Prohibited regions
0b00trapped to EL3 in all Security statesSecure and Non-secure EL0–EL2
0b01trapped to EL3 in Secure state onlySecure state
0b10trapped to EL3 in all statesnone
0b11not trappednone

TF-A programs 0b01. Non-secure software uses BRBE, Secure state neither records nor accesses it, and so a Non-secure reader cannot obtain Secure branch addresses. EL3 itself does not record by default. FEAT_BRBEv1p1 (permitted from v9.2) adds MDCR_EL3.E3BREC/E3BREW, which together enable EL3 recording.

What EL3 must enable and context-switch

TF-A builds per-world MDCR_EL3/CPTR_EL3 values (ENABLE_SPE_FOR_NS, ENABLE_TRBE_FOR_NS, ENABLE_TRF_FOR_NS, ENABLE_SYS_REG_TRACE_FOR_NS, ENABLE_BRBE_FOR_NS). It switches ownership on a world switch rather than saving the units’ contents:

UnitNon-secure world valueSecure/Realm world valueDrain on EL3 entry
SPENSPB = 0b11 (NS owns, NS EL1/EL2 may program), NSPBE = 0, enable bits for the newer PMS* registers setNSPB = 0b10 (NS still owns the buffer, so profiling is disabled in Secure and Realm, and their accesses trap)PSB CSYNC
TRBENSTB = 0b11, NSTBE = 0NSTB = 0b10TSB CSYNC
ETE/TRFCPTR_EL3.TTA = 0; MDCR_EL3.STE = 0, TTRF = 0same (trace prohibited in Secure by STE)TSB CSYNC
BRBESBRBE = 0b01samenone needed (no memory buffer); ISB

The MDCR_EL3 encodings follow one pattern: in NSPB/NSTB, bit [1] selects the owning Security state (1 = Non-secure) and bit [0] allows the owner’s EL1/EL2 to access the controls. With RME, NSPBE/NSTBE = 1 makes Realm the owner.

TF-A’s EL3 entry path executes psb csync and tsb csync (when built with SPE/TRBE support) followed by isb, before saving the lower EL context. This makes sure that profiling and trace generated by the Non-secure code are written to memory before the world changes. Without the barriers, a buffer write could complete after the switch, or be attributed to the next owner.

The lower-EL control registers belong to the EL1/EL2 context and must be part of TF-A’s per-world EL1/EL2 save and restore when a Secure-EL1/EL2 exists: TRFCR_EL1, TRFCR_EL2, PMSCR_EL1/PMSCR_EL2, BRBCR_EL1/BRBCR_EL2. Otherwise a Non-secure “trace EL1” setting persists into S-EL1, and only the STE/ownership bits stop it from having effect. The buffer contents are not switched: Secure software cannot touch them while it does not own them.

When EL2 is not used by the Non-secure world, EL3 must also set up MDCR_EL2 so that EL1 owns the buffers (E2PB, E2TB) and EL1 accesses are not trapped (TPMS, TTRF). Otherwise Linux at EL1 sees SPE and TRBE in the ID registers but every access traps.

Bring-up note: “perf record with SPE or TRBE works on one core and not another” is usually an ownership problem. Read PMBIDR_EL1.P and TRBIDR_EL1.P at the OS EL: if either is 1, EL3 or EL2 left ownership elsewhere. Some cores also have errata that require TRBE to be disabled entirely or the buffer to be drained differently (TF-A has a per-core check for this), so check the errata notice before trusting trace on a new core revision (1.3).

Validation note: a minimal leak test for each world switch. Enable SPE with PA = 1 and the sampling interval at its minimum, run an SMC-heavy loop that enters a Secure payload, then parse the buffer. No record may have a PC in the Secure image’s address range or carry a Secure-state context. Do the same with ETE/TRBE (no trace packets between the SMC and the return) and with BRBE (no records with a Secure source or target address. The exception record for the SMC itself is still written, but because EL3 is a prohibited region its target address is not recorded). A failure means an MDCR_EL3 value per world is wrong, or that the barrier on the entry path is missing. PMBSR_EL1.DL (data lost) and an unexpected TRBSR_EL1.S (stopped) must not appear in normal operation.

Checkpoint

Q16.6.1 A Non-secure kernel is profiling with SPE when an SMC enters EL3, and EL3 switches MDCR_EL3.NSPB from 0b11 to 0b10 before entering the Secure payload. What is the purpose of the PSB CSYNC that TF-A executes on EL3 entry?

  • A. It disables SPE so that EL3 is not sampled
  • B. It ensures that records for operations sampled before it have been written to the Profiling Buffer, so they cannot complete after the change of world or ownership
  • C. It saves PMSICR_EL1 so that sampling resumes at the same interval
  • D. It invalidates the Profiling Buffer so that Secure data cannot be read
Answer

B. PSB CSYNC is the profiling synchronization barrier. Together with the following DSB/ISB it makes sure that pending sample records from before the barrier are written out. A is wrong because EL3 is excluded from sampling by its own rules, and in Secure/Realm state the ownership encoding is what disables profiling. Nothing saves registers (C), and nothing is invalidated (D).

Read more: Arm ARM (DDI0487), PSB CSYNC; MDCR_EL3.NSPB; The Statistical Profiling Extension, synchronization

Q16.6.2 Firmware sets MDCR_EL3.SBRBE = 0b11 instead of 0b01. Which new risk does this create?

  • A. Non-secure EL1 can no longer read BRBE records
  • B. Branches executed at EL3 are recorded
  • C. BRBE register accesses from the Non-secure world trap to EL3
  • D. Branches executed in Secure EL0–EL2 can be recorded, and the records can then be read by Non-secure software, exposing Secure control flow and addresses
Answer

D. 0b11 removes both the Secure prohibited region and the Secure trap, while the record buffer is shared by all Security states. A and C are the opposite of what 0b11 does. EL3 recording (B) is controlled separately by E3BREC/E3BREW (FEAT_BRBEv1p1) and stays disabled.

Read more: Arm ARM (DDI0487), MDCR_EL3.SBRBE; The Branch Record Buffer Extension, prohibited regions

Q16.6.3 On a new platform, Linux at Non-secure EL1 (no hypervisor) detects TRBE but every TRBLIMITR_EL1 write traps. MDCR_EL3.NSTB is 0b11. What is the most likely cause?

  • A. MDCR_EL2.E2TB selects EL2 as the owner of the trace buffer, because EL3 did not initialise MDCR_EL2 for an unused EL2
  • B. MDCR_EL3.STE is 0
  • C. TRFCR_EL1.E1TRE is 0
  • D. CPTR_EL3.TTA is 1
Answer

A. With NSTB = 0b11 the Non-secure state owns the buffer and EL3 is not trapping. The remaining owner choice is MDCR_EL2.E2TB (EL1 or EL2), which EL3 must program when EL2 is unused. STE (B) concerns Secure-state trace generation. E1TRE (C) prohibits generation, not register access. CPTR_EL3.TTA (D) traps the ETE TRC* registers, not the TRBE buffer registers.

Read more: Arm ARM (DDI0487), MDCR_EL2.E2TB; MDCR_EL3.NSTB; TRBIDR_EL1.P

16.7 RAS architecture

3.4 covers the PE side of RAS: SError syndrome, ESB, DISR_EL1 and IESB. This section covers the rest: the error records that say what failed and where, the error types that say how far the damage spread, poison as the containment mechanism, and the signals (in-band aborts and out-of-band interrupts) that connect a node to software. The authority is the RAS System Architecture (DDI0587). The Arm ARM defines the PE’s System-register view of it (FEAT_RAS, mandatory from v8.2) and the exception reporting.

Nodes, records and groups

An error node is a component that detects errors and reports them through one or more error records. Examples are a PE’s L1/L2 RAMs, a DSU’s L3, a CMN HN-F’s SLC slice, a DDR controller, a GIC’s RAMs and an SMMU’s TLBs. Each record is a standard set of 64-bit registers:

RegisterContent
ERR<n>FRFeature register, read-only: which controls exist (ED, UI, FI, UE, CFI, DUI), the corrected-error counter type (CEC), the repeat counter (RP), and whether the record is owned by another record in the node
ERR<n>CTLRControls: ED (detection and reporting enable), UE (in-band External-abort response for uncorrected errors), UI (Error Recovery Interrupt), FI (Fault Handling Interrupt on uncorrected or deferred errors), CFI (FHI on corrected errors), and their read/write-split variants. What is implemented is given by ERR<n>FR
ERR<n>STATUSSyndrome: V valid, AV/MV address/misc valid, UE, DE deferred, CE corrected (2 bits), UET UE type, PN poison, OF overflow, ER error reported, CI critical, IERR IMPLEMENTATION DEFINED type, SERR architected source class (for example data-cache data RAM, tag RAM, or a bus error)
ERR<n>ADDRError address (PADDR), with NS/NSE giving the physical address space, SI (Secure Incorrect: NS/NSE may be wrong), AI (Address Incorrect: PADDR may not be the address of the original access) and VA (the address is a virtual address)
ERR<n>MISC0..3IMPLEMENTATION DEFINED location (set/way/bank), the standard CE counter and its overflow, and an optional timestamp. MISC2/MISC3 arrived with v1.1

ERR<n>STATUS fields are write-one-to-clear. The standard idiom is: read STATUS; if V, read ADDR and MISC*; then write the read value back to STATUS. That clears only the bits you saw, and an error recorded in between sets OF or is preserved. Writing back the value you read is also how you avoid clearing the record while a new error is being recorded into it.

Access paths:

  • PE-local records through System registers. ERRIDR_EL1.NUM gives the count. Select a record with ERRSELR_EL1.SEL, then access ERXFR_EL1, ERXCTLR_EL1, ERXSTATUS_EL1, ERXADDR_EL1, ERXMISC0..3_EL1 (and ERXPFG*_EL1, 16.8). Which records exist is IMPLEMENTATION DEFINED. On many DynamIQ cores record 0 covers the core’s own RAMs and record 1 the shared DSU/L3. A record shared between PEs shows the same contents from each of them.
  • Memory-mapped groups for everything else. Records sit at 64-byte strides in a 4 KB group (16 KB and 64 KB layouts with RASv2), with ERR<n>PFG* at +0x800, a group status ERRGSR (one bit per record with V set, at 0xE00 in a 4 KB group), and identification registers (ERRDEVARCH, ERRDEVID, ERRIIDR). Optional ERRFHICR*/ERRERICR*/ERRCRICR* registers program message-signalled FHI/ERI/CRI.

The OS learns about memory-mapped nodes from the ACPI AEST table (or a platform description). Firmware learns about them from its own platform code (18.6).

Trap controls: SCR_EL3.TERR and HCR_EL2.TERR trap the ERR*/ERX* System registers to EL3 or EL2, and SCR_EL3.FIEN/HCR_EL2.FIEN gate the fault-injection registers. These bits decide whether the error records belong to firmware or to the OS (16.8).

Error types

The type is a statement about containment, meaning how far the corruption may have spread. It is not a statement about severity:

TypeMeaningTypical example
CE, Correcteddetected and corrected. Informational, but counted, because a rising CE rate predicts failuresingle-bit ECC on a cache line
DE, Deferreddetected, not corrected, but not silently propagated: the data has been marked (poisoned) so that whoever consumes it will be tolddouble-bit ECC found on an eviction or by a scrubber, with poison written onward
UE, Uncorrecteddetected, not corrected or deferred. UET subdivides it:
— UC, Uncontainablemay have silently propagated. Nothing can be trustedan error in a tag RAM, so the location of the data is unknown
— UEU, Unrecoverablecontained to the PE or component, but its state is lost. The interrupted context cannot continuecorrupted architectural state
— UER, Recoverable (signalled)contained, and signalled before the corrupt value was used architecturally. Software can recover by isolating the consumerconsumed poison reported precisely
— UEO, Restartable (latent)contained, and the PE state was not affected. Execution can restartan error in a prefetched line that was never used

Two properties matter for software: whether the error was silently propagated (only UC permits that), and whether the consumer is known. CE and DE require no action from the consumer of the data. UER requires software to find and kill the consumer. Linux treats an SError with AET = UER as fatal for exactly this reason, because an asynchronous report does not identify the consumer, as noted in 3.4.

Poison and containment

Poison is the mechanism that turns a UE into a DE. When a node detects an uncorrectable error in data it is forwarding (for example on an eviction, a snoop response or a scrub), it does not raise an exception. It marks the data as poisoned (in ECC syndrome bits, the CHI Poison field, or a memory-controller encoding) and records a DE. The poison travels with the data through caches and the interconnect. The architectural rule is that a PE that consumes poisoned data must not let it silently affect architectural state. It must report an error at the point of consumption.

A node on the way that logs the poison it received (whether it does is IMPLEMENTATION DEFINED) sets ERR<n>STATUS.PN = 1, so the record says “I saw poison” rather than “I detected the original error”. Triage follows the PN = 0 record back to the original fault.

Signalling: in-band and out-of-band

SignalGenerated whenDelivered asWho uses it
In-band error responsea request receives a response that carries an error (ERR<n>CTLR.UE), for example consumed poisona synchronous External abort or an SError at the requesting PEthe consuming context
FHI, Fault Handling Interruptany recorded UE/DE (FI), or CE counter overflow or CE (CFI)an SPI, a PPI, or a message-signalled interrupt (IMPLEMENTATION DEFINED wiring, described in AEST)firmware or OS RAS logging
ERI, Error Recovery Interrupta UE that could not be signalled in-band, for example a write-back of corrupt data (UI)an interrupta recovery agent
CRI, Critical Error Interruptan IMPLEMENTATION DEFINED critical conditionan interruptplatform

FHI is the normal logging path, and ERI tells software that something needs action that no exception will report. These interrupts are ordinary GIC interrupts, so they need the same configuration as any SPI (group, priority, routing, 4.3). Whether they are Group 0 or Secure Group 1 or Non-secure Group 1 is the firmware-first versus kernel-first choice (16.8).

Consumed poison becomes a synchronous External abort

A load that consumes poison should be reported precisely, as a synchronous External abort on the instruction that consumed it:

  • EC 0x24/0x25 (data abort) or 0x20/0x21 (instruction abort, for poison in the instruction stream), with FSC 0b010000 (synchronous External abort, not on a walk) or 0b0101xx (on a walk at level xx);
  • ISS.EA = IMPLEMENTATION DEFINED classification, and ISS.FnV = 0 if FAR_ELx is valid;
  • ISS.SET [12:11], the Synchronous Error Type: 0b00 UER (Recoverable), 0b10 UC (Uncontainable), 0b11 UEO (Restartable). There is no synchronous UEU, because a precise report means that the PE state is intact.

With FEAT_RAS, the separate “synchronous parity or ECC error” FSC encodings (0b011000, 0b0111xx) are not used. All of these errors are reported as External aborts, and the error record holds the detail. The handler pairs the exception with the record: ESR_ELx says which instruction, and ERR<n>STATUS/ADDR say which RAM and which location.

Whether a particular consumption is reported synchronously or as an SError is IMPLEMENTATION DEFINED. Loads into registers are usually synchronous. Poison consumed by a store merge, by a cache-line write-back or by an atomic executed in the interconnect (a far atomic) may surface only as an SError or an ERI.

Security note: Normal-world code can never consume poison in Secure or Realm memory, because the access is blocked before it reaches the data. A poisoned line in a shared buffer, however, is a cross-world signal. EL3’s handler must not leak ERR<n>ADDR for Secure PAs to the Non-secure world. Under firmware-first handling, the CPER record it builds must contain only what the receiver is allowed to see (16.8).

What changed in v1.1 and v2

FeatureVersion (per the Arm feature list)Changes
FEAT_RAS / RAS SA v1permitted from v8.0, mandatory from v8.2ESB, error synchronization events, the System-register record interface, architected SError and abort syndrome
FEAT_RASv1p1 (+ FEAT_RASSAv1p1)permitted from v8.2. In a v8.4 implementation with FEAT_RAS it is requiredERR<n>MISC2/3 and ERXMISC2/3_EL1, the Common Fault Injection Model (ERR<n>PFGF/PFGCTL/PFGCDN, 16.8), and timestamp and counter refinements. FEAT_DoubleFault, a separate feature (permitted from v8.3, required in v8.4 when EL3 is implemented), adds the NMEA/EASE controls (3.3)
FEAT_RASv2 (+ FEAT_RASSAv2)permitted from v8.8. In a v8.9 implementation with FEAT_RAS it is requiredERXGSR_EL1 (group status for System-register records); a trap to EL3 on writes to RAS System registers; the extra SError and abort syndrome (WU, ELS, VFV, see 3.4); System RAS Agents; a control to disable FHI for deferred errors; 16 KB and 64 KB group layouts; an Error Recovery reset status flag; a control to stop counting CEs; Fault Injection Groups; group interrupt control registers; more record types

The same v8.9 generation (each permitted from v8.8) brings the companion features FEAT_PFAR (PFAR_ELx, the physical address of a fault), FEAT_ADERR/FEAT_ANERR (SCTLR2_ELx controls for whether an error on a load from Device or Normal memory is reported precisely and synchronously or as an SError; both require FEAT_RASv2) and FEAT_DoubleFault2.

Validation note: for every node listed in the AEST (or in firmware’s table), check the record’s static properties before injecting anything. ERR<n>FR must advertise what the platform documentation claims, ERR<n>CTLR must reset with ED in the documented state, and writing back the value read from ERR<n>STATUS must leave it at 0. A record whose STATUS cannot be cleared (a sticky V) or whose ERRGSR bit does not track V breaks every polling handler. These failures show up on silicon as an interrupt storm on the FHI line right after the OS enables it.

Checkpoint

Q16.7.1 A DDR controller detects a double-bit error while returning a line for a PE’s prefetch. The line is installed in L2 with poison, and later evicted unused. Which record contents are consistent with correct RAS behaviour?

  • A. DDR controller: UE = 1, UET = UC. The PE takes an SError
  • B. DDR controller: CE = 1. No other record changes
  • C. DDR controller: DE = 1 (poison sent onward). PE’s L2 record, if it logs received poison: PN = 1. No exception is taken, because nothing consumed the data
  • D. PE: a synchronous External abort with SET = UEO on the prefetch instruction
Answer

C. The error was detected and contained by poisoning, which is the definition of a deferred error. Nobody consumed the data, so no in-band report is due. An FHI may still be raised for logging if FI is enabled. A treats a contained error as uncontainable. B would mean that the data was corrected. D is wrong because a prefetch is not an architectural consumer, and no instruction has a precise report owed to it.

Read more: RAS System Architecture (DDI0587), Deferred errors and poison; ERR<n>STATUS.DE and PN

Q16.7.2 An EL1 handler receives a data abort with FSC 0b010000, ISS.SET == 0b00 and FnV == 0. What does this justify?

  • A. The error was contained and reported before it affected architectural state. Recovery is possible by isolating the context that consumed the data at FAR_EL1, for example by killing the process and offlining the page
  • B. The PE state is intact and the instruction can simply be re-executed
  • C. The error is uncontainable and the system must be reset
  • D. The syndrome is IMPLEMENTATION DEFINED and nothing can be concluded
Answer

A. SET == 0b00 is UER (Recoverable): it was signalled precisely, but re-executing the load would consume the same poison again, so B (which describes the UEO response) does not work. C is SET == 0b10. ISS.EA is the IMPLEMENTATION DEFINED part, while SET is architected (D).

Read more: Arm ARM (DDI0487), ISS encoding for an exception from a Data Abort, SET field; RAS System Architecture (DDI0587), error types

Q16.7.3 A logging handler reads ERXSTATUS_EL1, decodes it, then writes 0xFFFF_FFFF to ERXSTATUS_EL1 to clear it. What is wrong with this?

  • A. Nothing. All STATUS fields are write-one-to-clear, so this clears the record
  • B. An error recorded between the read and the write is cleared without being logged. Writing back the value read clears only what was seen
  • C. ERXSTATUS_EL1 is read-only. Records are cleared through ERXCTLR_EL1
  • D. The handler must first write ERRSELR_EL1 to 0 to unlock the record
Answer

B. Write-one-to-clear makes “write back what you read” the race-free idiom. Writing all ones discards a new error, or its OF indication, that arrived after the read. A ignores the race. C and D describe mechanisms that do not exist. ERRSELR_EL1 only selects which record the ERX* registers access.

Read more: RAS System Architecture (DDI0587), ERR<n>STATUS, clearing error records

16.8 RAS handling and error injection

16.7 defined what the hardware records and signals. This section covers who handles it, how the result reaches the OS, and how to make errors happen on demand so that every path can be tested before a real DIMM fails in the field.

Firmware-first vs kernel-first

The split is set by three EL3 controls, plus the GIC group of the RAS interrupts:

ControlFirmware-first (FFH)Kernel-first (KFH)
SCR_EL3.EA1: External aborts and SErrors from all lower ELs go to EL30: they go to the OS’s EL (3.3)
SCR_EL3.TERR1: ERR*/ERX* System-register accesses from EL1 and EL2 trap to EL30: the OS reads records directly
Memory-mapped record framesSecure-only (TZC/PAS)Non-secure, described in AEST
FHI/ERI interruptsGroup 0 or Secure Group 1, handled at EL3 or in a Secure PartitionNon-secure Group 1, handled by the OS driver
What the OS seesCPER records in GHES status blocks, announced by a notificationthe raw records

FFH keeps one implementation of the platform-specific decode (which RAM, which DIMM, which die) in firmware, hides microarchitectural detail and Secure addresses, and can act on errors the OS cannot see (Secure memory, the SCP’s RAMs, interconnect errors). It costs latency and firmware complexity, and it needs a channel to the OS. KFH is simpler and faster. It needs an OS RAS driver that understands every node, and it cannot cover errors in Secure-only resources. Many servers mix the two: kernel-first for PE caches, firmware-first for memory and interconnect.

Even under KFH, EL3 is involved. An SError raised by lower-EL code can be pending when the PE enters EL3 (on an SMC, or on a Group 0 interrupt). With SCTLR_EL3.IESB, TF-A synchronizes it on entry (ESB, then DISR_EL1) and reflects it to the lower EL: it builds the exception entry to the lower EL’s SError vector as if the error had been taken there. TF-A detects a loop in which the reflected error is masked at its target and immediately re-enters EL3, and panics in that case. FEAT_E3DSE (delegated SError injection by EL3) is the architected fix for that corner case (3.4).

In TF-A the relevant build options are ENABLE_FEAT_RAS, HANDLE_EA_EL3_FIRST_NS (FFH), EL3_EXCEPTION_HANDLING (the Exception Handling Framework, EHF, which arbitrates RAS against other EL3 interrupts at PLAT_RAS_PRI), SDEI_SUPPORT, RAS_TRAP_NS_ERR_REC_ACCESS (sets TERR) and FAULT_INJECTION_SUPPORT (sets SCR_EL3.FIEN). Platforms describe their nodes with ERR_RECORD_SYSREG_V1(...) / ERR_RECORD_MEMMAP_V1(...) and map interrupts with REGISTER_RAS_INTERRUPTS().

The FFH hand-off: APEI, GHES and SDEI

ACPI’s Platform Error Interfaces (APEI) are the OS contract:

  • HEST lists error sources. For Arm, each is usually a GHESv2 entry: the address of an error status block that firmware fills with a UEFI CPER record (an ARM Processor Error section, a Memory Error section and so on), a notification method, and a Read Ack register that the OS writes when it has consumed the block.
  • BERT reports errors from the previous boot (for example a UC that reset the system).
  • ERST is persistent storage for error records. EINJ is the injection interface, described below.

Notification methods on Arm include an interrupt (GSIV), the “Arm SEA” and “Arm SEI” types (the OS is told during its own synchronous External abort or SError handling), and SDEI (Software Delegated Exception Interface, DEN0054). SDEI is the usual choice for asynchronous FFH. It gives firmware an NMI-like way into the OS:

  1. At boot the OS registers a handler for the event number taken from the HEST entry: SDEI_EVENT_REGISTER, SDEI_EVENT_ENABLE, then SDEI_PE_UNMASK on each PE.
  2. An FHI arrives as a Group 0 interrupt at EL3. EHF dispatches it to the RAS handler, which walks the records, builds the CPER record (in EL3, or in a Secure Partition reached over FF-A or MM, 12.3), clears the records and signals the event (sdei_dispatch_event() in TF-A).
  3. The SDEI dispatcher saves the interrupted Non-secure context and enters the OS handler at Non-secure EL1/EL2 with the event’s arguments. SDEI events are taken even when the OS has PSTATE.I masked, subject to the event’s priority (normal or critical) and the PE’s SDEI mask.
  4. The OS handler (in Linux, ghes_sdei_normal_callback/ghes_sdei_critical_callback) reads the status block, queues the CPER record, writes the Read Ack register, and calls SDEI_EVENT_COMPLETE (or SDEI_EVENT_COMPLETE_AND_RESUME). EL3 then restores the interrupted context.

For a synchronous External abort under FFH the same CPER is produced, but the notification is SEA. EL3 fills the block, then returns into the OS’s synchronous abort vector, as if the abort had been taken there. The OS finds the record through the HEST SEA source and runs memory_failure() on the page.

Bring-up note: the most common FFH failure is not in the RAS code. It is a GHES status block in memory that the OS maps with different attributes from the ones firmware used to write it, or a Read Ack that is never written, so that firmware considers the block busy and drops every later error. Check that the status block’s address is in memory the OS treats as reserved, that both sides agree on cacheability, and that the ack value matches the HEST Read Ack Preserve/Write fields.

Pseudo-fault generation

The Common Fault Injection Model (FEAT_RASv1p1, 16.7) gives each node that supports it (ERR<n>FR.INJ non-zero) three registers. They exist only in the node’s first record; for the node’s other records they read as RES0:

RegisterRole
ERR<n>PFGFFeatures, read-only: which error types and status bits can be injected (OF, UC, UEU, UER, UEO, DE, CE, CI, ER, PN, AV, MV), whether restart (repeat) mode exists (R), whether software supplies the IERR/SERR syndrome (SYN), and NA (whether an injected error needs an access to the protected structure to be recorded)
ERR<n>PFGCTLWhat to inject, using the same type bits (for example UC is bit 1). CDNEN (bit 31) loads the Error Generation Counter from PFGCDN and starts it, and R (bit 30) reloads it and repeats on reaching zero
ERR<n>PFGCDNCountdown value. When it reaches zero, the node generates the error

The PE-local versions are ERXPFGF_EL1, ERXPFGCTL_EL1 and ERXPFGCDN_EL1, accessible from EL1/EL2 only when SCR_EL3.FIEN == 1 (and HCR_EL2.FIEN == 1 for EL1 under a hypervisor). Otherwise they trap. The sequence (the same shape as TF-A’s test code):

    // inject an Uncontainable error into PE error record 0. Requires SCR_EL3.FIEN = 1
    msr   ERRSELR_EL1, xzr
    isb                             // the selection takes effect for later ERX* accesses
    mrs   x0, ERXCTLR_EL1
    orr   x0, x0, #1                // ED: enable error detection and reporting
    msr   ERXCTLR_EL1, x0
    mov   x0, #1
    msr   ERXPFGCDN_EL1, x0         // countdown of 1
    mrs   x1, ERXPFGF_EL1
    tbz   x1, #1, no_uc_injection   // PFGF.UC (bit 1): UC injection supported?
    ldr   x0, =0x80000002           // PFGCTL: CDNEN (bit 31) | UC (bit 1)
    msr   ERXPFGCTL_EL1, x0
    isb
1:  wfe                             // the SError arrives (SCR_EL3.EA decides where)
    b     1b

Two limits matter for test design:

  • It injects a report, not a fault. The node behaves as if it had detected the error. It sets up the record and raises the configured in-band or out-of-band signals, but it is IMPLEMENTATION DEFINED whether any data is actually corrupted or poisoned, and when, relative to the countdown, the error appears (PFGF.NA says whether the node waits for an access to the protected structure or records the error spontaneously). PFG tests the reporting and handling path. It does not test the ECC logic or real poison propagation, which need the memory controller’s or RAM’s own (IMPLEMENTATION DEFINED) injection.
  • The type is chosen by software, so incoherent combinations are possible. Validate that the handler copes with what hardware can really produce, and also with what PFG can produce. For example, a UER injected into a node that can never report precisely will still be reported as an SError.

ACPI EINJ and OS-driven injection

EINJ lets the OS ask firmware to inject an error, so that injection works without FIEN and on nodes whose PFG registers are Secure-only. The table holds a list of actions (BEGIN_INJECTION_OPERATION, SET_ERROR_TYPE, SET_ERROR_TYPE_WITH_ADDRESS, EXECUTE_OPERATION, CHECK_BUSY_STATUS, GET_COMMAND_STATUS, END_OPERATION, …), each implemented as register reads and writes. On Arm platforms EXECUTE_OPERATION usually rings a doorbell that runs firmware (EL3, Standalone MM or the SCP), and that firmware then programs PFG or a memory controller’s injector. From Linux:

modprobe einj
cd /sys/kernel/debug/apei/einj
cat available_error_type          # e.g. 0x00000008 Memory Correctable, 0x00000010 Memory Uncorrectable non-fatal
echo 0x10 > error_type
echo 0x2  > flags                 # param1/param2 (address and mask) are valid
echo $PA  > param1                # physical address of a page owned by a test process
echo 0xfffffffffffff000 > param2
echo 1 > error_inject             # firmware arms the error; the test process then reads $PA

The consumer then runs the normal path: an SEA or SDEI notification, GHES, memory_failure(), and SIGBUS to the process owning the page. The notrigger file suppresses the firmware trigger action where the platform supports it, so that the test’s own access is what triggers the error.

Injecting on FVP

The AEM FVP implements PE error records with the fault-injection registers, and TF-A’s CI tests both models on it with TFTF as the Non-secure payload:

# TF-A, firmware-first build with SDEI and fault injection
make PLAT=fvp DEBUG=1 ENABLE_FEAT_RAS=1 HANDLE_EA_EL3_FIRST_NS=1 \
     EL3_EXCEPTION_HANDLING=1 SDEI_SUPPORT=1 FAULT_INJECTION_SUPPORT=1 \
     BL33=<path-to>/tftf.bin all fip
# find the RAS-related model parameters for your FVP version
FVP_Base_RevC-2xAEMvA --list-params | grep -i -E 'ras|error'

The TFTF RAS test groups (fvp-single-fault, fvp-uncontainable, fvp-ras-ffh-nested, fvp-ras-kfh, fvp-ras-kfh-reflect) are good templates. The FVP reports injected errors functionally. It does not model ECC, timing or poison travelling through a modelled interconnect, so the cross-die and memory-controller rows below need RTL emulation or silicon (18.4).

A test matrix

#CaseInjectionExpected exception and syndromeExpected record and OS resultTypical failure signature
1CE below thresholdpreset the record’s standard CE counter (in ERR<n>MISC0) to two below its overflow point (all ones minus 1), then inject one CEnonecounter +1 (now all ones), STATUS.CE set. With a standard counter and CFI = 1, the CE FHI is raised only on counter overflow, so none yetan FHI per CE (no standard counter, or a node that ignores it), or a counter that does not move (PFG does not drive the counter)
2CE threshold crossinginject a second CEnonethe counter wraps and sets its overflow flag (ERR<n>MISC0.OF, not STATUS.OF), FHI raised once. The OS logs a corrected-error storm, or EL3 logs a CPER Corrected recordan FHI storm (overflow not cleared, or the counter not reloaded by the handler), or no FHI at all (interrupt not routed or not enabled in the GIC)
3UE on loadinject UER (or poison through the memory controller) on a line, then load it from a user processsync data abort, FSC 0b010000, SET = 0b00, FnV = 0, FAR = the VArecord UE, UET = UER, ADDR = the PA. KFH: SIGBUS and the page offlined. FFH: an SEA notification and then the same resultan SError instead of an abort (an IMPLEMENTATION DEFINED choice, so check against the TRM), FnV = 1, or a kernel panic because the error was classified fatal
4Poison into the instruction streampoison a line of a user text page, then branch to itsync instruction abort, EC 0x20, FSC 0b010000, SET validthe process is killed. For a clean page the OS may instead drop and re-read it. For kernel text: panicthe abort repeats forever (handler returns without isolating the page), or the error is silently corrected by an I-cache refetch, which is legal for clean lines but must then be logged as a CE
5Error in the interrupt patharm an injection with a short countdown, then trigger a Group 0 or Non-secure interrupt so the error is pending while EL3 or the OS is in its IRQ handler with PSTATE.A = 1SError taken after the handler’s ESB or when A is unmasked, attributed by ISS.IESB/DISR_EL1 to the right context (3.4)KFH: EL3 reflects to the lower EL (TFTF fvp-ras-kfh-reflect). FFH: EHF priority puts RAS above the in-progress interrupt, and the nested EA is handled on the SMC or IRQ entry path (fvp-ras-ffh-nested)a reflect loop and panic, a lost interrupt (an EOI skipped on the error path), or the SError blamed on the next world
6UCinject UCSError, AET = 0b000system panic or reset. BERT shows the error after rebootthe system continues, or no BERT record

For each row also check that the record is cleared (STATUS reads 0 afterwards), that ERRGSR agrees, and that a second identical injection behaves the same. Handlers that work once and then lose every later error are common.

Validation note: run rows 3–5 on every die of a multi-chiplet system, with the consumer on a different die from the memory controller that owns the line (17.5). The poison must cross the die-to-die link, and the error record that the OS sees must still name the original node (PN = 0 at the memory controller, PN = 1 along the path). A synchronous abort at the consumer that turns into an SError when it crosses a die means the link drops the poison attribute and reports a bus error instead. That is a containment bug, and the interconnect’s own error records will show a link error at the same time.

Checkpoint

Q16.8.1 A platform runs firmware-first for memory errors. Linux registers SDEI handlers, but after the first injected memory CE, all later CEs produce no OS log, although EL3 shows its RAS handler running each time. What is the most likely cause?

  • A. SCR_EL3.TERR is 1, so Linux cannot read the error records
  • B. The FHI is configured as Non-secure Group 1
  • C. SCR_EL3.FIEN is 0, so later injections fail
  • D. The OS never wrote the GHESv2 Read Ack register, or firmware does not check it correctly, so firmware considers the status block still owned by the OS and drops new records
Answer

D. The EL3 handler runs, so injection (C) and interrupt routing (B) work. Under FFH the OS is meant not to read the records, so A is by design. The symptom “only the first error arrives” is the signature of the GHESv2 acknowledgement handshake failing.

Read more: ACPI specification, APEI, Generic Hardware Error Source version 2 (GHESv2); SDEI (DEN0054), SDEI_EVENT_COMPLETE

Q16.8.2 A test injects UER with ERXPFGCTL_EL1 into a PE record and then performs a load, expecting a precise data abort. Instead, an SError arrives with AET = UER. What should the validation engineer conclude?

  • A. The core violates the architecture, because UER must always be reported synchronously
  • B. Nothing yet. PFG injects a report, and whether and how the error is signalled in-band is IMPLEMENTATION DEFINED. Check the core’s TRM for PFG behaviour before filing a bug, and use real poison to test precise reporting
  • C. SCR_EL3.EA was 0, which turns synchronous aborts into SErrors
  • D. The record’s ERXCTLR_EL1.UE bit converts aborts into SErrors
Answer

B. Pseudo-fault generation guarantees that the record is set up and the configured signals are raised. It does not have to tie the error to the next load as a precise abort, so A over-claims. SCR_EL3.EA changes the target EL, not the synchronous/asynchronous nature (C). UE enables the in-band error response at all, but does not choose between abort and SError (D).

Read more: RAS System Architecture (DDI0587), Common Fault Injection Model; Arm ARM (DDI0487), ERXPFGCTL_EL1

Q16.8.3 A kernel-first system (SCR_EL3.EA == 0) occasionally panics in TF-A with a “reflection loop” message while running an error-in-the-interrupt-path test. What sequence most likely causes it?

  • A. An SError caused by Non-secure code is pending when an interrupt enters EL3. EL3 reflects it to the lower EL, where PSTATE.A is masked in the interrupted context, so it stays pending and is synchronized again at the next EL3 entry
  • B. SCR_EL3.EA == 0 means that EL3 takes every SError, and the EL3 handler re-enables PSTATE.A too early
  • C. The FHI was configured as Group 0, so it preempts the reflection
  • D. IESB is disabled at EL3, so the SError is never synchronized
Answer

A. Under KFH EL3 can only hand an error to the lower EL. If that EL cannot take it (masked, or of lower priority than what is in progress), it comes back at every EL3 entry. This is the case that TF-A detects and that FEAT_E3DSE is meant to fix. With EA == 0, SErrors are not taken at EL3 (B). C does not create a loop. D removes EL3’s synchronization on entry, so EL3 would not see the error and would not reflect it at all. That is a different failure, not a loop.

Read more: Arm ARM (DDI0487), SCR_EL3.EA; Asynchronous exception masking; TF-A documentation, RAS support (Kernel First Handling)

Part 17: Boot and system bring-up

Prerequisites: 3.2, 3.3, 4.5, 8.8, 9.3, 12.2, 12.3. On the bring-up path, 17.1–17.3 can be read directly after Part 5, following their forward references.

If you already know: If you have ported TF-A’s BL31 to a new SoC, skim 17.1 and 17.2 for the UNKNOWN-state and X-propagation material, and read 17.3, 17.5 and the per-feature list in 17.6 in full.

Why this matters for bring-up/validation: every first-silicon milestone (first instruction, first UART output, all cores up, OS booted, suspend-resume stable) is gated by one of the sequences in this part, and most of their failures come from state that the architecture leaves UNKNOWN or that a higher EL forgot to enable.

This part follows a system from the first fetch at RVBAR_EL3 to the first instruction of the OS. It starts with what reset really defines: Cold and Warm reset, which state is architecturally UNKNOWN, why four-state simulation exposes reads of that state that two-state platforms hide, and the order of TF-A’s stackless entry code. It then sets up EL3 itself (SCTLR_EL3, SCR_EL3, CPTR_EL3, MDCR_EL3) on a deny-by-default principle, and turns that principle into an explicit checklist. Each feature arrives disabled behind an EL3 bit, needs an ID check before it is enabled, and needs its registers context-switched in every world that may use it. The checklist maps features to bits and shows what breaks when one is missed.

The second half scales out. Secondary cores are released through PSCI or a spin table, join coherency, and later go through retention and power-down states and come back through the GIC and timer wake-up paths. Multi-chiplet systems add steps the Arm ARM does not describe but software must respect: boot-core election across dies, address maps that must agree before any coherent access, ordered entry into the snoop and DVM domains, and cross-die GIC, SMMU, PoC, RAS and TLBI behaviour. The part ends with the Linux arm64 boot protocol, read as a list of architectural requirements, and with the device-tree versus ACPI decision.

17.1 Reset

Reset is the one point where the architecture tells you almost nothing about the machine’s state, and makes you responsible for all of it. This section covers where a PE starts executing, what the two kinds of PE reset do and don’t reset, which state is defined, IMPLEMENTATION DEFINED or UNKNOWN, why UNKNOWN state is the main source of “passes on FVP, fails in RTL” bugs, and the instruction sequence TF-A runs before it has a stack. EL3 register initialisation itself is in 17.2, and what each boot stage hands to the next is in 12.2.

Where execution starts: RVBAR_ELx

On reset, the PE enters the highest implemented Exception level. When that is AArch64 EL3, the PE starts in EL3h, with:

  • PC = RVBAR_EL3 (Reset Vector Base Address Register). RVBAR_EL3 is read-only and its value is IMPLEMENTATION DEFINED. On Arm Cortex-A and Neoverse cores it is sampled from a per-core input bus (RVBARADDR) when the core leaves reset, so the SoC decides it, usually through a strap or a system-control register.
  • PSTATE.{D,A,I,F} all set, PSTATE.SP = 1 (SP_EL3 selected), PSTATE.EL = 3.
  • No exception syndrome: ESR_EL3, ELR_EL3, SPSR_EL3 and FAR_EL3 are UNKNOWN. A debugger showing “an exception” right after reset is reading garbage.

If EL3 is not implemented, the same applies with RVBAR_EL2 or RVBAR_EL1 at the highest implemented EL. Only the RVBAR of the highest EL exists. On cores that implement AArch32 at EL3 (Armv8-A only, see 2.1), the execution state at reset is chosen by an IMPLEMENTATION DEFINED input (AA64nAA32 on Arm cores) for a cold reset and by RMR_EL3.AA64 for a software-requested warm reset.

Because RVBAR_EL3 is fixed by hardware, there are two common platform designs:

DesignReset vectorConsequence for firmware
Fixed ROM vectorAlways BL1 in ROMBL1 must distinguish cold boot from warm boot (a core resuming from power-down) and send warm boots to BL31. TF-A does this with a mailbox (PROGRAMMABLE_RESET_ADDRESS=0).
Programmable vectorSoC register, rewritten by BL31 after cold bootWarm boots go straight to bl31_warm_entrypoint, and BL1 never runs again (PROGRAMMABLE_RESET_ADDRESS=1).

Cold reset and Warm reset

The Arm ARM defines two PE resets:

  • Cold reset is what happens when the Core power domain is powered up. It resets all of the PE’s logic in that domain, including the self-hosted debug and trace state.
  • Warm reset resets the PE’s execution logic but not the debug state. A Cold reset includes everything a Warm reset does, so a register field documented as “On a Warm reset, resets to X” also takes X on a Cold reset.

The register XML makes the difference visible. Most fields of SCR_EL3, MDCR_EL3 and CPTR_EL3 are described “On a Warm reset”, while the breakpoint and watchpoint registers (DBGBCRn_EL1, DBGWCRn_EL1) and the OS lock state are described “On a Cold reset”. For example, OSLSR_EL1.OSLK resets to 1 on a Cold reset, so the OS lock is set after power-up and survives a Warm reset (16.1). A debugger’s breakpoints therefore survive a Warm reset, which is the point: you can debug the reset path.

A Warm reset can be requested by software through RMR_EL3.RR, if the implementation provides it (whether RMR_EL3 is implemented, and whether RR does anything, is IMPLEMENTATION DEFINED). The documented pattern is DSB, ISB, write RR=1, then loop on WFI. The reset is only a request to the system, and the reset controller may not honour it.

Two clarifications prevent confusion in bring-up conversations:

  1. Neither reset is a system reset. The GIC Distributor and Redistributors, the system counter (CNTCR, 4.6), the interconnect, system caches and DRAM controllers have their own reset domains. After a PE reset, the GIC may still hold pending interrupts and the system cache may still hold dirty lines.
  2. “Warm boot” in TF-A is a software term. When a core powers up again after CPU_OFF or a power-down CPU_SUSPEND, its Core power domain was off, so architecturally it takes a Cold reset. TF-A calls this a warm boot because the system is already initialised and the core resumes into the PSCI warm-boot path (17.4). When you write a test plan, separate the architectural reset type from the firmware path.

Reset values: defined, IMPLEMENTATION DEFINED, UNKNOWN

Each register field’s reset behaviour falls into one of three categories, and the category decides what firmware must do:

CategoryExamplesFirmware obligation
Architecturally definedSCTLR_EL3.M, .C, .I reset to 0 (MMU, D-cache and I-cache off at EL3); OSLSR_EL1.OSLK = 1 on Cold resetMay rely on it, but only at the reset EL and only for that field
IMPLEMENTATION DEFINEDRVBAR_EL3; SCTLR_EL3.EE (from a configuration input such as CFGEND); MIDR_EL1, MPIDR_EL1; the reset values of CPU-specific registers such as CPUACTLR_EL1Read the core TRM; treat as platform data
Architecturally UNKNOWNMost of SCR_EL3, CPTR_EL3 and MDCR_EL3; VBAR_ELx; all of SCTLR_EL2/SCTLR_EL1 and most other lower-EL registers; CNTFRQ_EL0; CNTVOFF_EL2; X0–X30, SP_ELxWrite before any use, as a whole register

“UNKNOWN” has a precise meaning in the Arm ARM. The value is unspecified, may differ from one reset to the next and from one PE to another, and must not be relied on. The only guarantee is that it does not expose information that the current Exception level and Security state could not otherwise access. It is not “zero in practice”. It is often zero on FVP and on emulators, which is exactly why it is dangerous.

TF-A states the consequence in its EL3 entry macros: SCR_EL3 and CPTR_EL3 are initialised “setting all fields rather than relying on hw. All fields are architecturally UNKNOWN on reset”, and MDCR_EL3 likewise because “some fields are architecturally UNKNOWN on reset”. The rule that follows is: never read-modify-write a register whose reset value is UNKNOWN until you have written all of it once. mrs x0, scr_el3; orr x0, x0, #SCR_NS_BIT; msr scr_el3, x0 carries every UNKNOWN bit forward, including, for example, an SCR_EL3.EA or TWI that you never meant to set.

UNKNOWN state in simulation: X-propagation

In four-state RTL simulation, a flop with no reset starts as X, so UNKNOWN architectural state really is unknown there. How an X is handled depends on the simulator mode and tells you different things:

  • X-optimism (the default Verilog semantics for if/case): an X condition takes one branch, usually the else. A firmware read-modify-write of an UNKNOWN register then appears to work, and the bug is masked.
  • X-propagation or pessimism modes (enabled per tool, for example VCS -xprop or Xcelium’s X-propagation options): the X flows into everything it touches. A branch on a value derived from an UNKNOWN register drives X onto the PC, and the simulation fails visibly at the first instruction that depends on it. This is what you want during firmware-in-RTL bring-up.

Typical findings when X-propagation is switched on:

  • A read-modify-write of SCR_EL3, CPTR_EL3, MDCR_EL3, ACTLR_EL3 or an IMPLEMENTATION DEFINED CPU*CTLR register before it was fully written.
  • Use of X0–X3 from the boot ROM as “arguments” on a path where nothing set them (cold boot).
  • Uninitialised SRAM. Reading stack or .bss before it is written returns X. On silicon the same bug reads an ECC-uncorrectable word, which returns an external abort or poisoned data and surfaces as an SError at “the first memory access” (18.3). ECC-protected SRAM and DRAM must be initialised (scrubbed) by writes before the first read.
  • A DC or TLBI loop bound computed from a register that has not been read yet (for example a CCSIDR_EL1 read before CSSELR_EL1 was written; CSSELR_EL1 is UNKNOWN at reset).

Two-state platforms (emulators, FPGAs, FVP) turn X into 0 or a pseudo-random value and hide this whole class of bug (18.4).

Validation note: Run the reset path at least once in four-state RTL with X-propagation enabled, and treat any X reaching the PC, a branch condition or a memory address as a firmware or RTL bug until proven otherwise. On FVP, a cheap partial substitute is to run the first stages with different values in UNKNOWN registers: halt at the reset vector and use the debugger to write non-zero patterns into the registers whose reset value is UNKNOWN (SCR_EL3, CPTR_EL3, MDCR_EL3, X0–X30), then let the firmware run. A firmware build that behaves differently with different UNKNOWN values has a read-before-write bug.

The first ~100 instructions: TF-A’s EL3 entry

TF-A’s BL1 (bl1_entrypoint) and, for warm boots or RESET_TO_BL31, BL31 (bl31_entrypoint and bl31_warm_entrypoint) all start with the el3_entrypoint_common macro. Its parameters switch steps on or off for each image. The order is constrained at every step by what is still unavailable: no stack, no initialised memory, no vectors and no caches.

// Shape of el3_entrypoint_common (TF-A include/arch/aarch64/el3_common_macros.S), simplified
reset:
    // 1. SCTLR_EL3 first: EE before any data access, everything else to a known value
    mov_imm x0, (SCTLR_RESET_VAL & ~(SCTLR_EE_BIT | SCTLR_WXN_BIT | \
                 SCTLR_SA_BIT | SCTLR_A_BIT | SCTLR_DSSBS_BIT))
    msr     sctlr_el3, x0
    isb
    // 2. Cold or warm? (only when the reset vector is fixed)
    bl      plat_get_my_entrypoint      // stackless: x0-x17 and x30 only
    cbz     x0, do_cold_boot
    br      x0                          // warm boot: jump to BL31 warm entry
do_cold_boot:
    // 3. Vectors before anything that can fault
    adr     x0, bl1_exceptions
    msr     vbar_el3, x0
    isb
    // 4. CPU and platform reset handlers: errata workarounds, SMPEN (pre-DynamIQ)
    bl      reset_handler
    // 5. el3_arch_init_common: SCTLR_EL3.{I,A,SA}, SCR_EL3, MDCR_EL3, CPTR_EL3 from constants
    // 6. EL3 execution context: DAIF.A cleared, SCR_EL3.{EA,SIF}, MDCR_EL3.SDD, CPTR_EL3 bits
    // 7. Primary or secondary?
    bl      plat_is_my_cpu_primary
    cbnz    w0, do_primary_cold_boot
    bl      plat_secondary_cold_boot_setup   // hold pen or power off; never returns
do_primary_cold_boot:
    // 8. platform_mem_init, then the C runtime:
    //    invalidate the RW data range, zero .bss, copy .data from ROM (BL1),
    //    msr spsel, #0 (TF-A runs C code on SP_EL0 at EL3), plat_set_my_stack,
    //    stack-protector canary
    bl      bl1_main                    // C from here; the MMU is enabled in bl1_plat_arch_setup

Why each step sits where it does:

  1. SCTLR_EL3 first. EE has an IMPLEMENTATION DEFINED reset value, and it determines the endianness of every data access, including the mailbox read in step 2. TF-A clears A and SA here and sets them in step 5, sets IESB when FEAT_RAS is enabled (as an errata workaround on several cores), and leaves M and C at 0. Step 5 turns on I.
  2. Mailbox before anything else. On a fixed-vector platform every power-up of every core enters here. A warm-booting core must leave before it touches cold-boot state, such as the .data and .bss that the primary core is using. plat_get_my_entrypoint therefore runs without a stack and reads a location that is valid with the caches off. On FVP this is a trusted mailbox in memory that the cold boot path clears.
  3. Vectors before the reset handler. CPU errata code writes IMPLEMENTATION DEFINED registers. If one of those writes UNDEFs on the wrong core revision, you want a vector that reports it, not a jump through an UNKNOWN VBAR_EL3 (3.1).
  4. Reset handler. reset_handler calls plat_reset_handler and then the CPU-specific reset_func selected by MIDR_EL1. That function applies the errata workarounds that must be in place before caches or coherency are enabled (1.3) and, on Cortex-A53/A57/A72-class cores, sets CPUECTLR_EL1.SMPEN (8.8). It runs on every reset, cold or warm, because none of this state survives power-down.
  5. Architectural EL3 initialisation writes whole registers from constants (17.2).
  6. EL3 execution context. Only now, with vectors installed, does TF-A unmask SError at EL3 (msr daifclr, #DAIF_ABT_BIT) and route External aborts to EL3. An SError taken earlier would have gone through an UNKNOWN vector.
  7. Secondary cores leave before memory initialisation, because only the primary core may initialise shared memory.
  8. C runtime. The RW data range is invalidated by VA before use. TF-A’s comment gives the reason: an earlier boot stage may have left dirty lines for this memory in a system cache, and a later eviction would write them back over the freshly zeroed .bss. The PE’s own caches are invalidated by hardware at reset on Arm cores, but a system cache is outside the PE reset domain (9.3). With the MMU off, data accesses are Device-nGnRnE, so the zeromem and memcpy16 routines used here are written to avoid unaligned accesses and DC ZVA.

The MMU and D-cache are enabled only from C, in bl1_plat_arch_setup or bl31_plat_arch_setup. Everything before that runs uncached from ROM or SRAM, which is why the reset path is slow on silicon and painfully slow in RTL simulation.

Bring-up note: to see these instructions retire, put a hardware breakpoint at RVBAR_EL3 with the core held in reset (the Reset Catch debug event, EDECR.RCE, or a CTI halt request, 16.2). On QEMU, -d int,cpu_reset,in_asm -S -s and a gdb breakpoint at the reset address do the same. If the core never reaches the first instruction, the problem is not firmware: check the reset controller, the clock and RVBARADDR, and whether the ROM is mapped where the vector points.

Checkpoint

Q17.1.1 On a platform with a fixed ROM reset vector, a core powers up again after CPU_OFF. Which statement is accurate?

  • A. The core takes an architectural Warm reset, so its breakpoint registers and OS lock state are preserved, and BL1 can skip the mailbox check
  • B. The core resumes at the instruction after its WFI, because PSCI CPU_OFF preserves PE state
  • C. The core’s power domain was off, so architecturally this is a Cold reset at RVBAR_EL3. BL1 must read the warm-boot mailbox and branch to BL31’s warm entry point before touching any cold-boot state
  • D. The core enters at the ELR_EL3 value saved before power-down
Answer

C. Powering up the Core power domain is a Cold reset, even though TF-A calls the resulting software path a “warm boot”. With a fixed vector, every power-up enters BL1, so the _warm_boot_mailbox step must divert the core before it touches .data/.bss. Option A confuses TF-A’s “warm boot” with the architectural Warm reset. A core that is powered off keeps no state, so it cannot resume after its WFI (B) or at a saved ELR_EL3 (D). Resuming in place only happens from a retention state.

Read more: Arm ARM (DDI0487), Reset (Cold and Warm reset), RVBAR_EL3; TF-A firmware design, “Platform initialization: warm boot”

Q17.1.2 Early EL3 code does mrs x0, mdcr_el3; orr x0, x0, #MDCR_SDD_BIT; msr mdcr_el3, x0 as its first access to MDCR_EL3. It works on FVP and the emulator. In four-state RTL simulation with X-propagation, a later branch drives X onto the PC. What is the root cause?

  • A. Many MDCR_EL3 fields reset to an architecturally UNKNOWN value, and the read-modify-write carries them forward, so later behaviour that depends on them (a trap decision, a debug enable) is undefined. The register must first be written in full from a constant
  • B. The RTL is wrong: system registers must reset to 0
  • C. An ISB is missing after the MSR, so the write is not visible to the branch
  • D. MDCR_EL3 cannot be accessed before VBAR_EL3 is set
Answer

A. The architecture allows UNKNOWN reset values, and non-reset flops implement them, so the RTL is not at fault (B). Two-state platforms turn the UNKNOWN bits into 0 and hide the bug. A missing ISB (C) would change when the new value takes effect, not make it undefined. TF-A writes MDCR_EL3 from MDCR_EL3_RESET_VAL before any read-modify-write for exactly this reason.

Read more: Arm ARM (DDI0487), MDCR_EL3 field reset behaviour; Glossary, UNKNOWN

Q17.1.3 Why does TF-A install VBAR_EL3 before calling the CPU reset handler, and unmask SError at EL3 only after el3_arch_init_common?

  • A. VBAR_EL3 must be written before any ISB can execute
  • B. The reset handler uses the stack, and the stack pointer is derived from VBAR_EL3
  • C. SError must stay masked until the MMU is on, because external aborts are reported only for Normal memory
  • D. The reset handler writes IMPLEMENTATION DEFINED registers that may fault on an unexpected core revision, so a valid vector is needed first. Unmasking SError is safe only once vectors exist and SCR_EL3 routing has been written from a constant instead of an UNKNOWN value
Answer

D. Synchronous exceptions cannot be masked, so the vector must exist before the first instruction that might UNDEF or abort. SError is maskable, and TF-A keeps PSTATE.A set until both the vector and SCR_EL3.EA are defined. C is wrong: with the MMU off every data access is Device-nGnRnE and can still return an external abort. The reset handler is stackless (B), and nothing about ISB depends on VBAR_EL3 (A).

Read more: Arm ARM (DDI0487), Asynchronous exception masking, VBAR_EL3; TF-A el3_entrypoint_common

17.2 Initialising EL3

EL3 is the root of every trap and routing decision in the system. Four registers set its own behaviour and the default treatment of everything below it: SCTLR_EL3, SCR_EL3, CPTR_EL3 and MDCR_EL3. This section explains what each one decides, the principle for choosing the initial values, where the MMU fits, and how EL3 builds the state for the first exception return to a lower EL. Per-feature enable bits are collected in 17.3, and the full handover contract is in 12.2. For the map of all trap registers across ELs, see 2.6.

The safe-defaults principle

Three rules cover almost every decision in this section:

  1. Write every field. Most of these registers reset to UNKNOWN values (17.1). The first write is a whole-register write from a constant built from named fields, with RES1 bits set and RES0 bits clear. Read-modify-write is allowed only after that.
  2. Deny by default, enable by evidence. Lower ELs start with every optional feature trapped or disabled. A feature is enabled only when the ID registers say it is implemented and the firmware is built to manage its state (17.3). Enabling something that firmware does not context-switch leaks state between worlds.
  3. Separate EL3’s own settings from per-world settings. Some bits configure EL3 itself and never change, such as SCTLR_EL3, SCR_EL3.EA while in EL3, and MDCR_EL3.SDD. Others describe the world EL3 is about to enter (SCR_EL3.NS, SCR_EL3.RW, most feature enables), and are rebuilt for every exception return. TF-A keeps the second kind in each world’s cpu_context_t and writes them in el3_exit.

SCTLR_EL3

SCTLR_EL3 controls only the EL3 translation regime. It does not affect lower ELs.

FieldBoot valueWhy
M, C0 until the EL3 tables exist, then 19.3
I1 earlyInstruction fetches with M=0 are to Normal memory; I=1 makes them cacheable, which speeds up ROM code considerably
A, SA1 (TF-A)Alignment and SP-alignment checks catch pointer bugs. Note that with M=0, data accesses are Device and unaligned accesses fault regardless of A
WXN0 early, optionally 1 with the MMU onForces writable memory to be execute-never
EEExplicitly 0 (little-endian)Its reset value is IMPLEMENTATION DEFINED
IESB1 when FEAT_IESB is usedImplicit error synchronization at exception entry and return (3.4); also required by errata workarounds on some Neoverse and Cortex-X cores
DSSBS0 in TF-AValue of PSTATE.SSBS on exception entry to EL3 (14.5)
EnIA, BTAs built (BRANCH_PROTECTION)PAuth and BTI for EL3 code itself (13.1)

The SCTLR_EL3 RES1 bits are 4, 5, 11, 16, 18, 22, 23, 28 and 29, which is why a “minimal” value looks like 0x30C50830 rather than 0. Writing 0 is not “everything off”: software must write RES1 bits as 1, and a value with them clear is not guaranteed to behave the same way on every implementation, or on the next architecture version, where a RES1 bit may become a real control.

SCR_EL3

SCR_EL3 is the register that defines a world. Its fields fall into four groups:

GroupFieldsTypical value
Security state and execution state of lower ELsNS, NSE (FEAT_RME), RW, EEL2 (FEAT_SEL2)Per world: NS=1, RW=1 for an AArch64 Normal world; NSE,NS = 1,1 for Realm
Routing to EL3 (3.3)IRQ, FIQ, EA, NMEA, EASEFIQ=1 when Group 0 or Secure interrupts must reach EL3 from a lower world; EA=1 for firmware-first RAS
Instruction controlsHCE (HVC enable), SMD (SMC disable), SIF (no Secure instruction fetch from Non-secure memory), TWE/TWI, ST (Secure EL1 access to CNTPS_*)HCE=1 for any world that has EL2 software; SMD=0; SIF=1
Feature enables and trapsHXEn, FGTEn, ECVEn, ATA, API/APK, TCR2En, …Only for implemented and managed features (17.3)

Points that the field names do not make obvious:

  • RW describes the Exception level immediately below EL3 in the target world (EL2 if it is enabled, otherwise EL1). HCR_EL2.RW then decides EL1. RW is writable only when AArch32 is supported at a lower EL; on a core with no AArch32 below EL3 it is RAO/WI, so a wrong value is silently corrected. Where AArch32 is supported at EL2, RW=0 with an AArch64 SPSR_EL3.M gives an illegal exception return at the first ERET (Q17.2.3).
  • SCR_EL3.IRQ/FIQ route physical interrupts when the PE is in a lower EL. At EL3 itself, an interrupt is taken only if it is routed to EL3 and unmasked in PSTATE. TF-A normally runs EL3 with interrupts masked, so these bits are part of the per-world routing model (get_scr_el3_from_routing_model()).
  • EEL2 enables Secure EL2. Changing it at run time interacts badly with some cores: TF-A notes errata (Neoverse V2 3099206, Neoverse N2 3099213) that require EEL2 to stay constant for the life of the core, and sets it once during el3_arch_init_common.
  • TID3/TID5 (with FEAT_IDTE3) trap ID-register reads to EL3, so that firmware can hide features from lower worlds.

CPTR_EL3

CPTR_EL3 controls access from all lower ELs, and from EL3 itself, to FP/SIMD, SVE, SME, the trace system registers and the Activity Monitors. The polarities are mixed, and mixed polarity is a common source of bugs:

Field1 meansBoot default
TCPAC (bit 31)Trap EL2 accesses to CPACR_EL1/CPTR_EL2 to EL30
TAM (bit 30)Trap Activity Monitor accesses1 until AMU support is enabled (16.4)
TTA (bit 20)Trap trace system register accesses1 unless trace is managed
ESM (bit 12)Enable SME (do not trap)0 unless SME is managed (15.3)
TFP (bit 10)Trap FP/SIMD0 for worlds that use FP
EZ (bit 8)Enable SVE (do not trap)0 unless SVE is managed

All fields are UNKNOWN at reset. In TF-A, CPTR_EL3 is a per-world value (per_world_context_t.ctx_cptr_el3) shared by all CPUs, because whether a world may use SVE or SME is a property of the world, not of a core.

MDCR_EL3

MDCR_EL3 decides who can debug, count and trace what. Its security-relevant defaults are prohibitions:

  • SDD=1 disables Secure self-hosted debug exceptions, apart from BRK (16.1).
  • SPME=0, together with SCCD (FEAT_PMUv3p5) and MCCD/MPMX (FEAT_PMUv3p7) where implemented, keeps the PMU from counting Secure and EL3 execution (16.3). TF-A additionally sets PMCR_EL0.DP, so that the cycle counter stops when event counting is prohibited, which covers PMUs where SCCD/MCCD don’t exist.
  • TDA, TDOSA and TPM trap debug, OS-lock/power-down and PMU register accesses to EL3. They are normally 0 for the Normal world, so that the kernel can use them.
  • NSPB, NSTB and SBRBE assign the SPE profiling buffer, the trace buffer and branch recording to a Security state (16.6).
  • EPMAD/EDAD disable access by a (Non-secure) external debugger to the PMU registers and to the breakpoint and watchpoint registers (16.2).

TF-A writes MDCR_EL3_RESET_VAL (which sets only MTPME) and then composes per-world values in each context. The Normal-world value grants SPE ownership, for example, while the Secure-world value removes access. A Secure world with Non-secure-owned SPE therefore cannot read the buffer registers, and its own execution is not profiled.

The rest of the early EL3 list

  • VBAR_EL3 before anything that can fault (17.1).
  • CNTFRQ_EL0. It is writable only at the highest implemented EL, so EL3 must program it on every core. The system counter itself (CNTCR.EN) is a memory-mapped, system-level control (4.6).
  • ICC_SRE_EL3: SRE=1 and Enable=1, so that EL3 can use the GIC system registers and lower ELs can enable them (4.5).
  • ACTLR_EL3 (IMPLEMENTATION DEFINED). On Arm cores it controls whether EL2 and EL1 may write the IMPLEMENTATION DEFINED ACTLR_EL2/ACTLR_EL1 and CPU*CTLR registers. Grant only what the kernel needs (usually nothing).
  • CPU-specific registers and errata workarounds, applied by the reset handler on every reset (1.3).
  • PSTATE.DIT at EL3 when FEAT_DIT is implemented, so that EL3’s crypto code runs with data-independent timing.

The early MMU

BL1 and BL31 turn on the EL3 MMU and caches as soon as they have a minimal memory map: ROM and SRAM as Normal, device regions as Device-nGnRnE, with execute-never everywhere except code. There are three reasons:

  • With M=0, data accesses are Device-nGnRnE, so C code that the compiler expects to do unaligned accesses or DC ZVA faults.
  • Image hashing during authentication is several times faster with the D-cache on.
  • Speculative accesses are confined to mapped regions only once the MMU is on, provided the map does not cover PA holes (14.2).

The sequence (invalidate TLBs, write MAIR_EL3, TCR_EL3 and TTBR0_EL3, DSB, ISB, then set SCTLR_EL3.{M,C}, ISB) and its failure modes are covered once, in 9.3.

Dropping to a lower EL

The only way down is an exception return. EL3 prepares the target state and executes ERET, which is a context synchronization event, so the system-register writes made before it are in effect for the code it returns to (7.8).

What EL3 must write for the target world:

  1. SCR_EL3 for that world, from the per-world context.
  2. SPSR_EL3: M[3:0] for the target EL and stack (EL2h = 0b1001, EL1h = 0b0101), M[4]=0 for AArch64, and DAIF all masked.
  3. ELR_EL3: the entry point.
  4. The target EL’s SCTLR_ELx, written to a clean MMU-off value. If EL2 is implemented but the world’s software starts at EL1, EL3 also writes the EL2 controls that still apply to EL1&0 (HCR_EL2, CNTHCTL_EL2, CNTVOFF_EL2, VTTBR_EL2, MDCR_EL2, CPTR_EL2, HCRX_EL2). See 12.2.
  5. The general-purpose registers the next stage expects as arguments. Everything else should be zeroed, so that no EL3 data leaks into the lower world.

TF-A splits this into cm_init_my_context() (build a cpu_context_t from an entry_point_info_t: SCR_EL3, SPSR_EL3, ELR_EL3, per-feature enables), cm_prepare_el3_exit() (write the EL2/EL1 system registers of that world) and el3_exit (restore SCR_EL3, MDCR_EL3, CPTR_EL3 and the GPRs from the context, then ERET). The same path runs for the first entry and for every later return from an SMC, so the boot-time values are the runtime values.

/* Normal-world SCR_EL3, as TF-A composes it (simplified) */
u_register_t scr = SCR_RES1_BITS;            /* bits 5:4 */
scr |= SCR_NS_BIT | SCR_RW_BIT;              /* Non-secure, lower EL is AArch64 */
scr |= SCR_HCE_BIT;                          /* BL33 runs at EL2 and may use HVC */
scr |= SCR_SIF_BIT;                          /* written at EL3 entry; kept */
scr |= get_scr_el3_from_routing_model(NON_SECURE); /* IRQ/FIQ/EA routing */
if (is_feat_hcx_supported())  scr |= SCR_HXEn_BIT;
if (is_feat_fgt_supported())  scr |= SCR_FGTEN_BIT;
/* ... one line per managed feature, see 17.3 ... */
write_ctx_reg(get_el3state_ctx(ctx), CTX_SCR_EL3, scr);

Bring-up note: if the core vanishes at the first ERET, decode the outcome from EL3’s point of view. An illegal exception return (SPSR_EL3.M naming an EL that is not implemented or not enabled, or SCR_EL3.RW disagreeing with M[4]) leaves the PE at EL3 with PSTATE.IL set. The instruction at ELR_EL3 then takes an Illegal Execution state exception (EC 0x0E) to EL3 itself, so it shows up in your vector with ELR_EL3 equal to the intended entry point (3.2). A clean return followed by a trap back into EL3 with EC 0x18 means a lower-EL register access hit an enable you forgot (17.3, 18.1).

Checkpoint

Q17.2.1 Firmware initialises CPTR_EL3 with msr cptr_el3, xzr on a core that implements SVE, SME and the AMU, and then lets the Normal world run Linux. What happens?

  • A. Nothing is trapped, because writing 0 clears every trap bit
  • B. FP/SIMD, trace and AMU accesses are not trapped (TFP=TTA=TAM=0), but SVE and SME are disabled (EZ=ESM=0), so their instructions and registers trap to EL3. The AMU is usable by the Normal world with no context management
  • C. All of FP, SVE, SME and AMU trap, because CPTR_EL3 bits are all enable bits
  • D. The write is CONSTRAINED UNPREDICTABLE, because CPTR_EL3 has RES1 bits
Answer

B. CPTR_EL3 mixes trap bits (TCPAC, TAM, TTA, TFP: 1 traps) and enable bits (EZ, ESM: 1 enables). Zero therefore enables FP, trace and AMU access and disables SVE and SME. A and C each assume a single polarity. Linux would see SVE in ID_AA64PFR0_EL1, and its first SVE access would trap to EL3 (EC 0x19). Leaving TAM=0 without AMU context handling is itself a bug (17.3).

Read more: Arm ARM (DDI0487), CPTR_EL3

Q17.2.2 Why does TF-A keep SCR_EL3 in each world’s cpu_context_t, instead of setting it once during boot?

  • A. SCR_EL3 is banked per Security state in hardware, so software must keep shadow copies
  • B. SCR_EL3 loses its value whenever the core executes WFI
  • C. The Arm ARM requires SCR_EL3 to be written before every ERET
  • D. Several fields describe the world being entered (NS, NSE, RW, interrupt routing, the feature enables that are allowed in that world), so they must change on every world switch. Keeping one value per world makes the boot-time handover and each later SMC return use the same path
Answer

D. There is one SCR_EL3, not a banked copy per state (A). It is not reset by WFI (B), though it is lost on power-down, which is another reason to keep it in memory. The architecture does not require a write per ERET (C). Firmware does that because the security state and permitted features depend on the destination world.

Read more: Arm ARM (DDI0487), SCR_EL3; TF-A firmware design, “CPU context management”

Q17.2.3 BL31 ERETs to BL33 with SPSR_EL3.M = 0b1001 (EL2h) on an Armv8-A core that implements EL2 and supports AArch32 at EL2 and EL1, but the Normal-world SCR_EL3 was built with NS=1, HCE=1 and, by mistake, RW=0. What does the hardware do?

  • A. It enters EL1 instead, because EL2 is not allowed in AArch32
  • B. It enters EL2 in AArch32 state, and the first A64 instruction is UNDEFINED
  • C. The ERET is an illegal exception return: SPSR_EL3.M[4]=0 (AArch64) conflicts with SCR_EL3.RW=0. The PE stays at EL3 with PSTATE.IL set, and the next instruction takes an Illegal Execution state exception
  • D. It enters AArch64 EL2 correctly, because RW only affects EL1
Answer

C. An exception return that targets an AArch64 EL whose execution state is configured as AArch32 is illegal. On an illegal return, PSTATE.EL and the execution state are left unchanged and PSTATE.IL is set, so the instruction at the ELR_EL3 target, executed at EL3, takes an Illegal Execution state exception (EC 0x0E). D is wrong because SCR_EL3.RW controls the EL below EL3, which is EL2 here. (On a core with no AArch32 at EL2 or EL1, RW would be RAO/WI and the return would succeed, which is why the question specifies AArch32 support.) No silent redirection to EL1 (A) or AArch32 (B) happens.

Read more: Arm ARM (DDI0487), Illegal return events from AArch64 state; SCR_EL3.RW

17.3 The EL3 feature-enable checklist

Almost every architecture extension since v8.4 that adds system registers or instructions reachable from below EL3 arrives disabled or trapped, with the controlling bit in an EL3 register. The reasons are compatibility and security. Firmware written before the feature existed leaves the new bit at a value that keeps the feature off, so new state cannot leak between worlds through firmware that does not know to context-switch it. The cost is that every new core needs an EL3 audit: each feature the OS will use needs its enable bit set, and each enabled feature needs its state saved and restored wherever two worlds share the PE. This section is that audit, as a method plus a table. The general trap map is in 2.6, the version timeline in Appendix A, and fine-grained traps in 11.1.

How the gating works

Four EL3 mechanisms cover nearly all features:

  • SCR_EL3 enable bits. Since v8.6 the convention is an ...En bit where 0 means “accesses from EL2 and below to this feature’s registers trap to EL3” and 1 means “no trap from this control”. Examples are HXEn, FGTEn, ECVEn, TCR2En, SCTLR2En, PIEn, GCSEn, D128En, MECEn and EnFPM. Older bits are less regular: ATA (allocation-tag access, 1 = allowed), API/APK (PAuth, 1 = don’t trap), and TRNDR (1 = trap RNDR/RNDRRS to EL3).
  • CPTR_EL3 bits: EZ and ESM are enables, and TFP, TTA, TAM and TCPAC are traps (17.2).
  • MDCR_EL3 fields for debug, PMU, SPE, TRBE and BRBE. These are mostly ownership fields that assign a resource to a Security state, rather than plain enables.
  • EL2 registers that EL3 must initialise when EL2 is implemented but the world starts at EL1, or when EL3 owns EL2’s initial state: HCRX_EL2, the HFG*TR_EL2 fine-grained trap registers, TCR2_EL2 and others. If SCR_EL3.HXEn=1 but nobody writes HCRX_EL2, its UNKNOWN fields (for example EnALS, EnASR, MSCEn, SMPME) apply to EL1&0. Conversely, with HXEn=0 the pseudocode treats HCRX_EL2 as disabled (IsHCRXEL2Enabled() returns FALSE), so every EL1 feature whose EL2-level enable lives in HCRX_EL2 is off as well: the two-level gating means EL1 needs both the EL3 bit and the EL2 bit.

When an enable is 0, the trap is usually reported to EL3 as EC 0x18 (trapped MSR, MRS or System instruction), with the ISS giving Op0, Op1, CRn, CRm, Op2 and Rt of the access. There are exceptions. SVE traps with EC 0x19, SME with EC 0x1D, FP/SIMD with EC 0x07, and some new instructions in the HINT space execute as NOP instead of trapping (2.3). The EC tells you which class of control to look at (Appendix D).

The ID-check-then-enable pattern in TF-A

TF-A treats each feature with the same three-part pattern.

1. Build flag. ENABLE_FEAT_<X> takes one of three values:

ValueMeaning (FEAT_STATE_*)Use
0DISABLED: no code for the feature is built; the enable bit stays 0Feature absent, or deliberately not supported
1ALWAYS: code built and the bit set unconditionallyFixed silicon known to implement it
2CHECKED: code built; enabled only if the ID register field says the feature is presentPlatforms that must run on several core types (FVP, reference designs)

2. Runtime predicate. is_feat_<x>_supported() folds the build flag and the ID check together: it is constant false for 0, constant true for 1, and reads the relevant ID_AA64*_EL1 field for 2 (1.1). Every enable site is guarded by it.

3. Enable and context. In the context-management library (lib/el3_runtime/aarch64/context_mgmt.c and lib/extensions/*), the guarded code does two things:

/* Pattern from TF-A's per-world SCR_EL3 composition (simplified) */
if (is_feat_tcr2_supported()) {
    scr_el3 |= SCR_TCR2EN_BIT;     /* EL2 and below may access TCR2_ELx */
}
if (is_feat_sxpie_supported() || is_feat_sxpoe_supported()) {
    scr_el3 |= SCR_PIEN_BIT;       /* one bit gates PIR_ELx, PIRE0_EL1 and POR_ELx */
}
/* ...and, separately, TCR2_EL1/TCR2_EL2 join the EL1/EL2 context save/restore */

The enable goes into a per-world SCR_EL3 (or MDCR_EL3/CPTR_EL3) value, and the feature’s registers join the save/restore lists that run on a world switch. TF-A has three context granularities, and each feature belongs in a specific one:

  • Per CPU, per world (cpu_context_t): GPRs, SCR_EL3, MDCR_EL3, the EL1 system registers (and the EL2 registers when CTX_INCLUDE_EL2_REGS is set because an SPMC runs at S-EL2), PAuth keys, and optionally FP registers.
  • Per world, shared by all CPUs (per_world_context_t): CPTR_EL3 and MPAM3_EL3 (plus the emulated ID-register values when FEAT_IDTE3 support is built). A world either may or may not use SVE/SME/AMU.
  • EL3 only, per CPU (cm_manage_extensions_el3()): settings for EL3 itself, such as ZCR_EL3, SMCR_EL3 and AMU counter enables.

FEATURE_DETECTION=1 is a debug build option that compares each ENABLE_FEAT_* setting with the ID registers at boot and reports any mismatch. TF-A’s documentation says it is intended for flexible platforms such as models and for hardware at bring-up time. Use it once per new core and per new FVP configuration, before trusting a =1 build.

Security note: “enable it for the Normal world” is never one bit. If a feature’s registers are enabled for the Normal world but not context-switched, the Secure or Realm world runs with the Normal world’s values (for example its TCR2_EL1, POR_EL1 or GCSPR_EL1), and can leak its own values back. Some combinations are architecturally security-sensitive. With SCR_EL3.ATA=1, MTE tag access works in the world, and if tag storage is not protected per world, a Normal-world STG to Secure memory is a confidentiality and integrity problem (13.6). Audit enable and context together.

What breaks when a bit is missed

The symptom depends on who owns the trap and which TF-A version is running:

Missed itemSymptom
Enable bit 0, feature visible in the ID registersThe kernel probes ID_AA64MMFR3_EL1 (for example) and finds TCR2 implemented, then writes TCR2_EL1. The access traps to EL3 with EC 0x18. Older TF-A panics in EL3 (report_unhandled_exception, then a console dump). In recent TF-A releases (the change landed in 2023), an unhandled EC 0x18 trap from an AArch64 lower EL is answered by injecting an UNDEF into that EL (inject_undef64), so Linux reports Internal error: Oops - Undefined instruction (EC 0x00 at EL1) at the first use, often in early cpufeature code or the first context switch
Enable bit set, ID register hiddenWith TID3 (FEAT_IDTE3) or a hypervisor hiding the feature, the OS won’t use it. Harmless, but sometimes surprising
Enable bit set, registers not context-switchedNo crash. State crosses worlds: the Secure world inherits Normal-world TCR2_EL1/PIR_EL1, PAuth keys or MTE GCR_EL1, and the Normal world finds its values changed after an SMC. Symptoms appear only after the first SMC that runs Secure EL1 code, and only intermittently
EL2 register not initialised (EL2 present, OS at EL1)Random behaviour of EL1&0 that depends on UNKNOWN HCRX_EL2, HFGRTR_EL2… fields: unexpected traps to an EL2 that has no handler, or features that silently don’t work
Feature enabled in one world, CPTR_EL3 per world wrongThe Secure world’s first FP or SVE instruction traps to EL3 (EC 0x07 or 0x19)
MDCR_EL3 ownership missedLinux perf sees SPE/TRBE/BRBE in the ID registers, then gets UNDEF or “no device”, or profiles Secure execution if ownership is too permissive

Bring-up note: when the kernel dies with an UNDEF on a system-register instruction that should exist on the core, decode the instruction (mrs/msr encoding, 2.5), look up which EL3 control gates that register in its XML “Accessibility” pseudocode, and check the bit in the Normal-world SCR_EL3, CPTR_EL3 or MDCR_EL3 value (halt in el3_exit and read the context, or add a debug print of the composed values). With an older BL31, the same bug appears as an EL3 panic whose ESR_EL3 has EC 0x18 and whose ISS names the register.

The checklist table

Bit positions are from the TF-A arch.h definitions and the register XML. “EL1/EL2 ctx” means the feature’s registers must be saved and restored as part of that world’s EL1 or EL2 system-register context.

FeatureEL3 controlLower-EL state it unlocksContext requirement
FEAT_HCX (v8.7)SCR_EL3.HXEn (38)HCRX_EL2EL2 ctx; write HCRX_EL2=0 when EL2 is unused
FEAT_FGT (v8.6)SCR_EL3.FGTEn (27)HFGRTR_EL2, HFGWTR_EL2, HFGITR_EL2, HDFGRTR_EL2, HDFGWTR_EL2, HAFGRTR_EL2EL2 ctx; safe init when EL2 is unused
FEAT_FGT2 (v8.9)SCR_EL3.FGTEn2 (59)HFGRTR2_EL2 and the other *2 registersEL2 ctx
FEAT_ECV (v8.6)SCR_EL3.ECVEn (28)CNTPOFF_EL2EL2 ctx
FEAT_TCR2 (v8.9)SCR_EL3.TCR2En (43)TCR2_EL1, TCR2_EL2EL1 and EL2 ctx
FEAT_SCTLR2 (v8.9)SCR_EL3.SCTLR2En (44)SCTLR2_EL1, SCTLR2_EL2EL1 and EL2 ctx; EL3 writes its own SCTLR2_EL3
FEAT_S1PIE, FEAT_S1POE (v8.9)SCR_EL3.PIEn (45)PIR_ELx, PIRE0_ELx, POR_ELxEL1 and EL2 ctx
FEAT_GCS (v9.4)SCR_EL3.GCSEn (39)GCSCR_ELx, GCSPR_ELx, GCSCRE0_EL1, GCSPR_EL0EL1 and EL2 ctx (13.2)
FEAT_THE (v8.9)SCR_EL3.RCWMASKEn (42)RCWMASK_EL1, RCWSMASK_EL1EL1 ctx
FEAT_D128, FEAT_SYSREG128 (v9.4)SCR_EL3.D128En (47)MRRS/MSRR to 128-bit TTBRn_ELx, PAR_EL1, VTTBR_EL2Context must save all 128 bits
FEAT_MTE2 (v8.5)SCR_EL3.ATA (26)Allocation-tag access; GCR_EL1, RGSR_EL1, TFSR_EL1, TFSRE0_EL1Per world, EL1 ctx; tag storage protected per world
FEAT_PAuth (v8.3)SCR_EL3.API (17), APK (16)PAC/AUT instructions; AP*Key*_EL1EL1 ctx (keys) per world (13.1)
FEAT_MEC (v9.2)SCR_EL3.MECEn (49)MECID_*_EL2, VMECID_*_EL2EL2 ctx, Realm world (12.5)
FEAT_FPMR (with FP8)SCR_EL3.EnFPM (50)FPMRPer world, with the FP state
FEAT_LS64_ACCDATA (v8.7)SCR_EL3.ADEn (37), EnAS0 (36)ACCDATA_EL1, ST64BV0EL1 ctx
FEAT_AMUv1p1 (v8.6)SCR_EL3.AMVOFFEN (35)AMEVCNTVOFF0n_EL2, AMEVCNTVOFF1n_EL2EL2 ctx (16.4)
FEAT_RNG_TRAP (v8.5)SCR_EL3.TRNDR (40), 1 = trapEL3 emulates RNDR/RNDRRSEL3 service only
FP/Advanced SIMDCPTR_EL3.TFP (10), 1 = trapV0–V31, FPCR, FPSRPer world (CTX_INCLUDE_FPREGS) or handled by the SPMC/SPD
FEAT_SVE (v8.2, mandatory in v9.0)CPTR_EL3.EZ (8), 1 = enable; ZCR_EL3.LENZCR_ELx, Z/P/FFRPer-world CPTR_EL3; Z/P state only if the Secure world uses SVE (15.3)
FEAT_SME (v9.2)CPTR_EL3.ESM (12), 1 = enable; SCR_EL3.EnTP2 (41); SMCR_EL3SMCR_ELx, SVCR, ZA, TPIDR2_EL0Per-world CPTR_EL3; streaming state must not survive into another world
FEAT_AMUv1 (v8.4)CPTR_EL3.TAM (30), 1 = trapAM*_EL0 countersSave/restore across power-down; per-world TAM
Trace (ETE/ETM system registers)CPTR_EL3.TTA (20), 1 = trapTRC* registersTrace unit state across power-down
FEAT_TRF (v8.4)MDCR_EL3.TTRF (19), 1 = trapTRFCR_EL1, TRFCR_EL2EL1 and EL2 ctx; prohibit Secure trace (16.6)
FEAT_SPE (v8.2)MDCR_EL3.NSPB (13:12), NSPBE (11) with RMEPMB*_EL1, PMS*_EL1Ownership per world in MDCR_EL3; drain the buffer before a world switch
FEAT_TRBE (v9.0)MDCR_EL3.NSTB (25:24), NSTBE (26) with RMETRB*_EL1Ownership per world in MDCR_EL3
FEAT_BRBE (v9.2)MDCR_EL3.SBRBE (33:32)BRB*_EL1, BRBCR_EL2Ownership and Secure prohibition in MDCR_EL3
FEAT_PMUv3MDCR_EL3.TPM (6), 1 = trap; SPME (17); SCCD (23); MCCD (34); MPMX (35)PM* registersMDCR_EL2 per world; Secure counting prohibited by default (16.3)
DebugMDCR_EL3.TDA (9), TDOSA (10), SDD (16)DBG*, OS lockSDD=1 keeps Secure self-hosted debug off

Version numbers in the first column are the earliest version in which the feature is permitted (Appendix A gives the “mandatory from” column). They do not tell you whether your core implements it. Only the ID registers do.

Validation note: for each new core or model configuration, a directed test at Normal-world EL2 should touch one register from every feature that the ID registers advertise, and expect no exception (18.5). Run it once with a Secure-world round trip between “write a pattern” and “read it back”, which checks context switching: any register that comes back changed is missing from the world switch. TFTF has tests of this shape for many features. On FVP, vary the feature parameters (SVE, SME, MTE and so on, in the cluster0.* parameter namespace; exact names differ between FVP releases, so list them with --list-params) and run with ENABLE_FEAT_*=2, which checks the CHECKED path on cores both with and without each feature.

Checkpoint

Q17.3.1 A new SoC’s Linux kernel runs at EL2 with VHE. Early boot dies with Oops - Undefined instruction at an msr to TCR2_EL2 (S3_4_C2_C0_3). ID_AA64MMFR3_EL1.TCRX reads 1, and BL31 is a recent TF-A. What is the most likely cause?

  • A. SCR_EL3.TCR2En is 0 in the Normal-world context (for example because ENABLE_FEAT_TCR2=0), so the access trapped to EL3 with EC 0x18, and BL31 converted the unhandled trap into an UNDEF injected into the kernel
  • B. The core does not implement TCR2_EL1, so the instruction is UNDEFINED in hardware
  • C. HCRX_EL2.TCR2En is 0, which traps the access to EL2
  • D. The kernel forgot an ISB after writing TCR_EL1
Answer

A. The ID register says the feature exists, so B contradicts the evidence. A recent BL31 injects an UNDEF for an EC 0x18 trap it does not handle, which explains why the kernel sees an UNDEF rather than a hang. C is wrong because HCRX_EL2.TCR2En controls EL1 accesses to TCR2_EL1. It cannot trap an access made at EL2, and the only control above EL2 is SCR_EL3.TCR2En. A missing ISB (D) cannot turn an access into an UNDEF.

Read more: Arm ARM (DDI0487), TCR2_EL1 accessibility pseudocode, SCR_EL3.TCR2En; TF-A build options, ENABLE_FEAT_TCR2

Q17.3.2 On a core with FEAT_HCX, BL31 sets SCR_EL3.HXEn=1 in the Normal-world context. EL2 is implemented, but the kernel is entered at EL1, and BL31 never writes HCRX_EL2. What is the risk?

  • A. None: HCRX_EL2 only affects software running at EL2
  • B. Every EL1 access to HCRX_EL2-controlled features traps to EL3, because HXEn=1 means “trap”
  • C. None, because the kernel reprograms HCRX_EL2 during its own EL1 setup
  • D. HCRX_EL2 resets to UNKNOWN values, and with HXEn=1 they take effect for EL1&0. Fields such as EnALS, EnASR, MSCEn or TCR2En then enable or trap features at random, so behaviour differs between cores and resets
Answer

D. HCRX_EL2 controls EL1&0 whenever EL2 is enabled in the Security state, whether or not software runs at EL2. Setting HXEn=1 makes its contents effective, so EL3 must write it (TF-A writes HCRX_EL2_INIT_VAL, 0, when it is not saving an EL2 context). A is the same misconception as with CNTVOFF_EL2 in 12.2. HXEn=1 means “do not trap” (B). A kernel at EL1 cannot write an EL2 register (C).

Read more: Arm ARM (DDI0487), HCRX_EL2 reset values, SCR_EL3.HXEn; TF-A lib/el3_runtime/aarch64/context_mgmt.c (EL2 initialisation when EL2 is unused)

Q17.3.3 Which TF-A ENABLE_FEAT_* setting is the right default for a firmware image that must run on an FVP whose feature parameters change between test runs, and why?

  • A. 1, because FVP implements every feature
  • B. 2 (FEAT_STATE_CHECKED): code is built in, and each enable is guarded by an ID-register check at run time, so the same binary is correct whether or not the model implements the feature
  • C. 0, because FVP traps every optional feature to EL3 anyway
  • D. 1 with FEATURE_DETECTION=1, which automatically downgrades absent features to 0
Answer

B. =1 sets enable bits and touches registers unconditionally, which on a model without the feature means writing a non-existent register (an UNDEF at EL3) or setting a bit whose effect is undefined there. FEATURE_DETECTION (D) reports mismatches at boot. It does not fix them. FVP implements only the features its parameters enable (A), and nothing makes it trap everything (C).

Read more: TF-A documentation, Build options (ENABLE_FEAT_*, FEATURE_DETECTION); Arm ARM (DDI0487), ID_AA64MMFR3_EL1

17.4 Secondary cores and CPU power states

After cold boot, one core is running and the rest are held somewhere. This section follows a secondary core from that holding state into the OS, and then follows any core from the OS into a low-power state and back. The PSCI interface itself (function IDs, the coordination rules at the interface level) is in 12.3. The cache and coherency steps of power-down are covered once, in 8.8. This section is about the sequence that connects them.

Naming a core: MPIDR_EL1 and affinity

PSCI, the GIC and the OS all address cores by affinity, taken from MPIDR_EL1:

FieldBitsMeaning
Aff0[7:0]Lowest affinity level
Aff1[15:8]
Aff2[23:16]
MT[24]1: Aff0 identifies threads of a multithreaded core, so the lowest level shares a core
U[30]1: uniprocessor system
Aff3[39:32]Highest affinity level

The values are IMPLEMENTATION DEFINED and fixed (by hardware configuration inputs). The architecture says only that affinity levels form a hierarchy and that lower levels are more closely coupled. Two layouts appear in practice, and code that hard-codes one breaks on the other:

  • Pre-DynamIQ (Cortex-A53/A57/A72 clusters): MT=0, Aff0 = core, Aff1 = cluster.
  • DynamIQ (Cortex-A55/A76 and later, Neoverse): MT=1 even on single-threaded cores, Aff0 = 0 (thread), Aff1 = core, Aff2 = cluster, and Aff3 is often used for a chip or socket (17.5).

TF-A maps an MPIDR to a linear core index with plat_core_pos_by_mpidr(). That function must reject MPIDRs that don’t exist, because PSCI CPU_ON takes an MPIDR from the Normal world and the index is used to address per-core arrays at EL3.

Security note: plat_core_pos_by_mpidr() is an EL3 bounds check on an attacker-controlled value. A version that masks fields instead of validating them can map a crafted target_cpu onto another core’s index or past the end of the psci_cpu_pd_nodes array. When you review a new platform port, this is one of the first functions to read.

Where secondaries wait: hold pens and power-off

On cold boot, every core may leave reset together, or only the primary may. TF-A’s plat_secondary_cold_boot_setup() (step 7 in 17.1) decides what non-primary cores do:

  • Powered off (FVP, most production SoCs). The secondary programs the power controller to turn itself off and executes WFI. It comes back only through CPU_ON, which powers it up from reset. This is the cleanest option: no code runs, and the core takes a fresh reset at RVBAR_EL3.
  • Hold pen (platforms without per-core power control). The secondary spins in EL3 in a WFE loop on a per-core mailbox in Secure memory, with caches off. CPU_ON writes the mailbox and issues SEV. Mailbox writes must be visible to a core that reads with the MMU and caches off, so the writer cleans the line to the PoC (or the mailbox is mapped Non-cacheable), then issues DSB and SEV (7.10).

Linux supports two enable methods (17.6):

enable-method = "psci"enable-method = "spin-table"
Where the secondary waitsIn firmware (powered off or in a Secure pen)In Normal-world reserved memory, polling cpu-release-addr
ReleaseCPU_ON(target_mpidr, entry, context_id) SMC/HVCKernel writes the entry address, then SEV
CPU hotplug, CPU_OFF, deep idleYesNo: a released core can never return to firmware
Errata and EL3 init on the secondaryDone by BL31 on the core’s own reset pathMust have been done before the core entered the spin loop
FitAny system with EL3 firmwareSimple systems with no PSCI implementation

CPU_ON end to end in TF-A

Caller core (Normal world)              Target core
--------------------------              -----------
SMC CPU_ON(mpidr, ep, ctx_id)
 psci_cpu_on()
  validate ep (plat validate_ns_entrypoint)
  validate mpidr -> core index
  psci_cpu_on_start():
   aff_info state OFF? else ALREADY_ON / ON_PENDING
   set ON_PENDING, clean it to PoC            (target reads it with caches off)
   cm_init_context_by_index(idx, ep)          (target's NS context built here)
   SPD hook (svc_on)
   plat_psci_ops->pwr_domain_on(mpidr)  --->  power controller releases reset
 return PSCI_E_SUCCESS                         RVBAR_EL3 -> bl31_warm_entrypoint
                                               el3_entrypoint_common (SCTLR, vectors,
                                                 reset_handler: errata, SMPEN)
                                               enable EL3 MMU and caches
                                               psci_warmboot_entrypoint()
                                                psci_cpu_on_finish():
                                                 plat pwr_domain_on_finish
                                                   (GIC Redistributor + CPU interface)
                                                 SPD hook (svc_on_finished)
                                                 aff_info state := ON
                                                cm_prepare_el3_exit_ns()
                                               el3_exit: ERET to ep, x0 = ctx_id

Three details matter in bring-up:

  1. CPU_ON returning success does not mean the core is running. It means the power-on request was accepted. The OS uses its own handshake (Linux waits on a completion signalled by the secondary), and can poll AFFINITY_INFO.
  2. The context is built by the caller. The target’s cpu_context_t (SCR_EL3, SPSR_EL3, ELR_EL3 = ep) is written by the calling core into memory the target will read after enabling its MMU and caches. TF-A relies on the system being coherent at that point (HW_ASSISTED_COHERENCY, or explicit cleaning of the shared PSCI data when it is not).
  3. Coherency entry happens on the target’s reset path, before its caches are enabled. On Cortex-A53/A57/A72-class cores, the CPU reset handler sets CPUECTLR_EL1.SMPEN. On DynamIQ cores there is no SMPEN: the core joins the cluster’s coherency domain automatically when it is powered on, under PPU and DSU control. If the cluster itself was off, the platform’s pwr_domain_on must first power the cluster and, on older interconnects, add it to the snoop and DVM domains (for example TF-A’s cci_enable_snoop_dvm_reqs() on CCI-400 platforms) (8.8, 17.5).

CPU_SUSPEND and CPU_OFF

CPU_SUSPEND(power_state, entry, context_id) asks for a low-power state described by power_state. In the original format, StateID is in bits [15:0], StateType in bit 16 (0 = standby or retention, 1 = power-down) and PowerLevel in [25:24]. In the extended format (PSCI 1.0 and later; which format the firmware uses is reported by PSCI_FEATURES(CPU_SUSPEND)), StateType is bit 30 and StateID is [27:0]. The difference between the two types determines the whole path:

Retention (standby)Power-down
PE statePreserved; clocks gated, possibly reduced voltageLost; the core takes a Cold reset on wake-up
CachesNormally retained, still coherent or not per TRMMust be cleaned (or flushed by hardware on DynamIQ)
ReturnExecution continues after the WFI; CPU_SUSPEND returns SUCCESS to the callerNever returns on success: the core restarts at entry with x0 = context_id
EL3 workProgram the power controller, WFISave context, cache steps, GIC sleep, program the power controller, WFI

In TF-A, a CPU-level retention state goes straight to plat_psci_ops->cpu_standby(), which is essentially a WFI with a power-controller hint. Anything deeper goes through psci_cpu_suspend_start():

  1. Coordinate. Under the power-domain locks, psci_do_state_coordination() computes, for each affected level (cluster, system), the shallowest state that every child has requested. This is platform-coordinated mode, the default. The last core of a cluster to request power-down is the one that powers the cluster down. In OS-initiated mode (PSCI_SET_SUSPEND_MODE, PSCI 1.0) the OS makes that decision and firmware checks it.
  2. Notify the SPD (svc_suspend) so that OP-TEE or the SPMC can save state or refuse.
  3. Power-down sequence for each level that loses power: psci_do_pwrdown_sequence() calls the CPU-specific core_pwr_dwn/cluster_pwr_dwn routines, which are the cache and coherency exit steps of 8.8. The EL3 context is already in memory. Extensions with state not in the context (for example AMU counters) are saved here.
  4. Platform suspend (pwr_domain_suspend): mark the Redistributor asleep, disable the GIC CPU interface, program the power controller (often through SCMI to an SCP) with the target state and the wake-up conditions.
  5. DSB and WFI (psci_power_down_wfi()). If the WFI falls through, for example because an interrupt was already pending and the power controller refused the request, TF-A treats it as an immediate wake-up.

CPU_OFF follows steps 1–5 with no entry point and no wake-up condition other than a later CPU_ON.

On wake-up from power-down, the core takes the same path as the target core of CPU_ON above. psci_warmboot_entrypoint() then calls psci_cpu_suspend_finish() instead of the CPU_ON finisher: it restores the extension state, lets the SPD resume, and ERETs to the entry given in CPU_SUSPEND. The Normal world sees this as a fresh entry, not a return from the SMC, which is why Linux’s cpu_suspend() saves its own context before the call and restores it at cpu_resume.

The wake-up path: GIC and timer

A powered-off core cannot see its interrupt signals, so something outside the core power domain has to wake it.

  • GIC Redistributor. Before power-down, firmware sets GICR_WAKER.ProcessorSleep=1 and waits for GICR_WAKER.ChildrenAsleep=1. While the bit is set, the Redistributor does not signal interrupts to the CPU interface. Instead, when an interrupt targeting that PE becomes pending, it raises a wake request to the power controller. The signal is IMPLEMENTATION DEFINED, but GIC-600/700 provide one per core. On resume, firmware clears ProcessorSleep, waits for ChildrenAsleep=0, then re-enables the CPU interface (4.5). An SPI with 1-of-N routing (GICD_IROUTER.IRM=1) can be delivered to an awake PE instead; whether the IRI chooses an awake PE in preference to waking a sleeping one is IMPLEMENTATION DEFINED. Where GICR_TYPER.DPGS=1, software can set GICR_CTLR.{DPG0,DPG1NS,DPG1S} before sleeping to exclude that PE from 1-of-N selection for each group, and clear them on resume.
  • Generic Timer. The per-PE timers (CNTP_*, CNTV_*) live in the core power domain. Their comparators stop and their state is lost when the core powers down, so a core-local timer interrupt cannot wake a core from a power-down state. The system counter is in an always-on domain and keeps counting, so CNTPCT_EL0 is continuous across suspend. The OS must therefore hand its next timer event to a timer that stays powered before entering such a state. Linux uses a broadcast timer for this, typically a memory-mapped timer frame (CNTBaseN), and the device-tree local-timer-stop property on the idle state tells it when this is required (4.6). On retention states, whether the local timer keeps running is IMPLEMENTATION DEFINED, so check the TRM.
  • Lower-EL timer state. CNTV_CVAL_EL0, CNTKCTL_EL1 and, at EL2, CNTHCTL_EL2 and CNTVOFF_EL2 are lost with the core. Whichever EL owns them must restore them. CNTFRQ_EL0 is lost too, and EL3 rewrites it on the warm-boot path.

Validation note: the PSCI stress test is a loop that randomly chooses a core and a state (retention, core power-down, cluster power-down, CPU_OFF/CPU_ON) while other cores generate SGIs, SPIs with 1-of-N routing, and timer interrupts aimed at the sleeping core. Check three things on each cycle: the core wakes for every interrupt aimed at it (a lost wake-up appears as a core that never returns, usually with GICR_WAKER.ProcessorSleep still 1); interrupts are neither lost nor duplicated (count them per core); and memory patterns survive (8.8). TFTF’s PSCI test suites implement much of this. PSCI’s PSCI_STAT_COUNT/PSCI_STAT_RESIDENCY (when implemented) and the AMU constant-frequency counter confirm that the core actually entered the state rather than falling through WFI.

Checkpoint

Q17.4.1 Linux calls CPU_SUSPEND with a power-down state. The SMC returns PSCI_E_SUCCESS to the instruction after the SMC, the core did not lose state, and the residency counters show no time in the state. What happened?

  • A. Normal behaviour: a power-down suspend always returns to the caller on wake-up
  • B. The request did not complete as a power-down. For example, an interrupt was already pending, the WFI fell through, and firmware treated it as an immediate wake-up. A real power-down wake-up restarts the core at the entry address, not after the SMC
  • C. The core entered power-down, but TF-A restored its registers and returned to the SMC site
  • D. The power_state was in the extended format, which only supports retention
Answer

B. Under PSCI, a power-down state that is actually entered never returns on success: execution resumes at the entry point given in the call. A return to the call site means retention or an aborted entry. TF-A does not resume the Normal world at the SMC site after a real power-down (C). It ERETs to the registered entry point. The extended format encodes both types (D).

Read more: PSCI (DEN0022), CPU_SUSPEND; TF-A psci_cpu_suspend_start

Q17.4.2 A core enters a core power-down idle state, and its next scheduled timer event is 2 ms away. It sleeps for 300 ms, until an unrelated device interrupt wakes it. GICR_WAKER handling is correct. What is the most likely cause?

  • A. CNTFRQ_EL0 was lost and the counter ran slow
  • B. The system counter stopped while the core was off
  • C. SCR_EL3.IRQ routed the timer interrupt to EL3
  • D. The core-local Generic Timer is in the core power domain and cannot raise its PPI while the core is off. The OS should have moved the event to an always-on broadcast timer (the idle state lacks local-timer-stop, or no broadcast timer is registered)
Answer

D. The Redistributor can only wake the core for an interrupt that becomes pending, and a powered-off core timer never makes its PPI pending. The system counter is always-on (B), so time stays correct after wake-up. A lost CNTFRQ_EL0 (A) affects time conversion after resume, not the wake-up. Routing to EL3 (C) would still produce a wake-up, just a different handler.

Read more: Arm ARM (DDI0487), The Generic Timer, power and reset; Linux DT bindings, arm,idle-state local-timer-stop

Q17.4.3 A platform ported from Cortex-A72 to Cortex-A78 clusters keeps its secondary release code. That code computes the core index as MPIDR_EL1.Aff0 + 4 * MPIDR_EL1.Aff1. On the new SoC, at most one secondary core starts, and CPU_ON to the others returns INVALID_PARAMETERS or ALREADY_ON. Why?

  • A. DynamIQ cores report MT=1 with Aff0=0 and the core number in Aff1, so the old formula maps cores 0, 1, 2… to indices 0, 4, 8… Most indices run past the number of cores (rejected), and any that land in range alias another core’s PSCI state
  • B. Cortex-A78 lacks CPUECTLR_EL1.SMPEN, so secondaries cannot become coherent
  • C. CPU_ON requires Aff3 to be non-zero
  • D. The A78 requires spin-table instead of PSCI
Answer

A. The affinity layout changed between pre-DynamIQ and DynamIQ cores. The index function must derive positions from the platform’s actual topology and reject impossible values. SMPEN (B) is indeed absent on DynamIQ cores, but coherency entry is then automatic, so it would not produce these PSCI errors. Nothing in PSCI requires Aff3 to be non-zero (C) or forbids PSCI on any core (D).

Read more: Arm ARM (DDI0487), MPIDR_EL1; Cortex-A78 TRM, MPIDR_EL1; TF-A porting guide, plat_core_pos_by_mpidr

17.5 Multi-chiplet bring-up

A multi-chiplet SoC (several dies in one package, joined by a die-to-die link) is architecturally still one system: one physical address space, one coherency domain if you build it that way, one set of Shareability domains. The Arm ARM has nothing to say about dies. Everything that is die-specific is IMPLEMENTATION DEFINED, in the interconnect, the GIC, the power controllers and the boot firmware. The architecture does fix the end state firmware must reach before the OS runs: every PE that will be in the Inner Shareable domain must be coherent and must receive broadcast maintenance (17.6). This section is the ordered list of steps that gets you there, and the places where a multi-die system behaves differently from a single die in ways software can see. The interconnect background (CHI, snoop filters, DVM) is in 8.3.

Examples below use Arm CMN-class meshes (CMN-700 and similar) and GIC-600/700 because their documentation and TF-A/SCP-firmware drivers are public. Other interconnects have equivalent steps under different names.

Reset release and boot-core election

At power-on, each die typically has its own system control processor (SCP, or an RSE/MCP-style security and management processor) that comes out of reset before any application PE. The order is decided by that layer, not by the Arm ARM:

  1. Each die’s SCP brings up its own clocks, power and local interconnect. One die, usually chosen by a package strap or a fuse, is the primary die.
  2. The die-to-die link is trained, and the SCPs agree on the chip count and chip IDs.
  3. Only the primary die releases its boot PE from reset. Application PEs on other dies stay in reset or powered off until the OS issues CPU_ON for them (17.4). The power request then travels from the primary die’s PSCI implementation to the remote die’s power controller, usually as an SCMI message to the local SCP that is forwarded across dies, or as a direct write into the remote power controller over the link.

Firmware must make the election deterministic. TF-A’s plat_is_my_cpu_primary() compares the full MPIDR, including the chip field, against one fixed value. If two dies both release a core whose MPIDR.Aff0–Aff2 matches “primary”, and the check ignores the chip field, two BL1s initialise shared memory concurrently. On silicon this shows up as a different hang on every boot.

Bring-up note: cold-boot all dies with only the primary die’s boot PE released, until the full system is coherent. Releasing remote-die PEs early “to save time” means they execute from a memory map that is not programmed yet, and their speculative fetches reach address ranges that the link or the remote SAM may fault. This is a typical source of an SError at boot that no instruction can explain (3.4).

Program the address map before any coherent access

In a CHI mesh, every request is steered by system address maps (SAMs):

  • An RN SAM at each requesting node (a CPU cluster port, an I/O port) maps each physical address to a target. Memory goes to a home node (HN-F, which contains the snoop filter and a slice of the system-level cache), device space to an HN-I or HN-D, and remote addresses to the gateway that carries traffic to another die (CCG on CMN-700, the CXL/CCIX gateway).
  • Memory ranges are usually hashed across a group of HN-Fs, so that consecutive cache lines go to different home nodes. The hash function and the set of HN-Fs in each group are programmed in the SAM.
  • An HN-F SAM maps each home node’s addresses to a memory controller (SN-F).

Two rules follow.

  • The maps must be consistent on every die. If die 0 hashes a range across its eight HN-Fs but die 1 sends the same range to die 0 through a different hash, two home nodes each believe they own the same line. Coherency then fails silently: two dirty copies, lost writes. Every requester must agree on exactly one home node per line.
  • No cacheable access to a range before its SAM entry is valid. That includes the PE’s own speculative and prefetch accesses once its MMU and caches are on. TF-A runs with the MMU on, so the platform code that programs remote ranges (on Arm reference designs it runs in the SCP firmware, before the application PEs are released) must finish before BL31 maps those ranges. An access with no SAM entry typically returns an error response, which arrives as an External abort or SError (18.3).

Join the coherency and DVM domains, in order

A cluster’s port has two separate memberships in the interconnect:

  • the snoop (coherency) domain: the home nodes’ snoop filters may hold its lines and will send it snoops;
  • the DVM domain: it receives broadcast TLB, branch-predictor and instruction-cache maintenance (TLBI ...IS, IC IVAU, …) and answers DVM Sync (9.1).

In CHI, a requester enters and leaves these domains with a hardware handshake (the SYSCOREQ/SYSCOACK coherency-connect signals). A DSU drives this automatically. Older interconnects needed explicit software writes, such as the CCI-400 snoop and DVM enables that TF-A sets with cci_enable_snoop_dvm_reqs(). Across dies, the gateways must also be configured to forward snoops and DVM messages to the remote die. That configuration is IMPLEMENTATION DEFINED and is part of link bring-up.

The required order, for each die or cluster that joins:

  1. Address maps programmed and the link up (previous step).
  2. Join the snoop domain before the cluster enables its caches. Otherwise it allocates lines the rest of the system will never snoop.
  3. Join the DVM domain before any other PE relies on broadcast maintenance reaching it, which in practice means before the OS brings the first PE of that cluster online.
  4. On the joining PEs: local TLBI ALLE3/ALLE2/VMALLE1 and, if required by the TRM, cache invalidation, after joining and before enabling the MMU. Anything they cached before joining missed every broadcast (8.8).

Leaving is the exact reverse, and it must complete before a die or cluster is powered down.

MPIDR affinity versus physical topology

The architecture does not tie MPIDR_EL1 to physical placement (17.4). On multi-die DynamIQ systems, Aff3 often carries the chip ID and Aff2 the cluster, but this is a convention set by the core’s configuration inputs. Three consumers depend on the choice:

  • The GIC. Affinity routing uses MPIDR values. GICR_TYPER.Affinity_Value of each Redistributor must equal its PE’s MPIDR_EL1 affinity, and GICD_IROUTER<n> names one PE by Aff3.Aff2.Aff1.Aff0 (or selects 1-of-N), and ICC_SGI1R_EL1 names Aff3.Aff2.Aff1 plus a 16-bit target list of Aff0 values. With DynamIQ’s Aff0=0, every core sits under its own Aff1 value, so an SGI to all cores on a die is one ICC_SGI1R_EL1 write per core (IRM=1 broadcasts to every PE in the system except the sender, not to one die).
  • Firmware indexing: plat_core_pos_by_mpidr() must include the chip field.
  • The OS scheduler. Linux arm64 does not derive topology from MPIDR. It uses the device-tree cpu-map or the ACPI PPTT. These tables, not MPIDR, have to describe dies, clusters and shared caches correctly (18.6).

GIC and SMMU across dies

GIC-600 and GIC-700 support a multichip configuration in which each die has its own Distributor instance and the instances keep their state consistent over the link. The firmware-visible pieces (driven by TF-A’s gic600_multichip driver) are as follows:

  • GICD_CHIPR<n> describes each chip: its address on the link and the SPI ID range it owns.
  • One chip is the routing-table owner. Configuration changes are made through it and propagated, and GICD_DCHIPR reports whether an update is still in progress (poll it before the next write). GICD_CHIPSR reports this chip’s routing-table (connection) status.
  • SPIs are owned by the die where the wire enters. They can still be routed (GICD_IROUTER) to any PE in the package, and the delivery crosses the link.

The rule is the same as for the address map: configure the multichip routing table, and see every chip report connected, before enabling any Distributor interrupt group. Configuration made while a remote chip is not yet connected may not reach it, and nothing at the CPU reports that.

For SMMUs, each die’s I/O subsystem typically has its own SMMU instances, and for each one the cross-die questions are:

  • Table walks. A walk for a device on die 1 may reach page tables homed on die 0. The SMMU must be a coherent requester (SMMU_IDR0.COHACC, with the walk attributes set accordingly), and its RN SAM must cover the remote range.
  • Broadcast TLB maintenance. If SMMU_IDR0.BTM is implemented and the SMMU is configured to use it, TLBI ...IS from any PE must reach it, so the SMMU must be in the DVM domain across dies. Otherwise the SMMU must ignore broadcast invalidation (SMMU_CR2.PTM=1, which is what Linux sets unless it uses BTM) and the OS must use command-queue invalidation (CMD_TLBI_*) (11.5).
  • MSIs. A device’s MSI targets an ITS (GITS_TRANSLATER) that may be on another die. That is an ordinary write crossing the link, and it is ordered behind the device’s earlier DMA writes only if the path preserves that order (4.4).

The Point of Coherency with per-die system caches

Each die’s HN-Fs contain a slice of the system-level cache (SLC), which caches lines homed on that die. Every coherent access to a line goes to its home HN-F, wherever the requester is. Two consequences need to be checked against the design, because the architecture only defines the PoC as the point where all observers, including non-coherent ones, see the same copy (8.4):

  • If every agent, including non-coherent DMA masters, reaches memory through the home HN-F, the PoC can be at the SLC (the SLC is transparent to every observer), and a DC CVAC to the PoC need not write data out of it. If any agent can reach DRAM directly, bypassing the home node (for example a die-local accelerator attached at the memory controller), the SLC is before the PoC for that agent. CMOs must then push data out of the SLC, and the interconnect must be configured to do so.
  • If a die can cache remote-homed lines locally (some gateways have a cache for remote data), that cache must be snooped by the home node, and it must honour CMOs. Otherwise a DC CIVAC on die 0 leaves a stale copy in die 1’s gateway cache.

Validation note: test CMOs across every pair of (die where the CPU runs, die where the line is homed, die where the observer sits). For each combination: write a pattern with the D-cache on, DC CVAC to the PoC, DSB SY, then have a non-coherent observer (a DMA engine configured non-snooping, or a debugger MEM-AP access to the physical address, 16.2) read memory. Repeat with invalidation in the other direction. A failure only for remote-homed lines points to the gateway or the CMO forwarding configuration. Interconnect PMU events (the HN-F and CCG counters exposed by CMN’s PMU) confirm whether the CMO reached the home node and the SN.

RAS reporting across dies

Each die has its own error records (cores, DSU, HN-Fs, memory controllers, the link controller), discovered through ACPI AEST or platform data (16.7). Multi-die systems add three problems:

  • Interrupt and record locality. The fault-handling interrupt for a remote die’s memory controller is an SPI on that die’s GIC. It can be routed to an EL3 handler on any PE, but the handler must then read error records through the link, which is the failing component if the link is the fault.
  • Link errors (CRC failures, retrains, an unresponsive remote die) have their own error records at the gateway. A dead link turns every outstanding remote access into an error response, which arrives as a burst of SErrors on many PEs at once. Firmware-first handling has to recognise this as one event.
  • Poison across dies. CHI carries poison with the data, so a poisoned line read by a die-0 PE from die-1 memory must arrive still marked as poison and be reported when it is consumed (typically as a synchronous External abort, though this is IMPLEMENTATION DEFINED), not used as silent bad data. That is a link and gateway property to test, using the pseudo-fault generators of the remote memory controller (16.8).

Barrier and TLBI broadcast latency

A DSB after a broadcast TLBI or IC IVAU completes only when every member of the DVM domain has answered the DVM Sync (7.6). Across a die-to-die link, that round trip is much longer than on a single die, so the cost of a TLB shootdown grows with both the number of PEs and the number of dies. A DSB that orders stores to remote Device memory similarly waits for completion responses from the other side of the link. The practical consequences are:

  • Measure, don’t assume: time TLBI VAE1IS + DSB ISH with all dies in the DVM domain, versus one die, using CNTPCT_EL0 or the PMU cycle counter. Expect a large difference.
  • OS-level mitigations (range invalidation with FEAT_TLBIRANGE, batching, keeping ASIDs live to avoid global invalidations) matter more on such systems (9.1).
  • A die that stops answering DVM messages (stuck in a power transition, or with its link down) makes every DSB after a broadcast maintenance operation hang on every die. In a hung-system dump, many cores stopped at a DSB after a TLBI point straight to a DVM participant (18.2).

NUMA

Memory placement is a firmware choice that the OS then has to be told about:

  • Die-local regions. Each die’s DRAM is a separate PA range, homed on that die. Local accesses are fast and remote ones cross the link. The OS is told through ACPI SRAT (proximity domains), SLIT/HMAT (distances, latency and bandwidth) or device-tree numa-node-id and distance-map.
  • Package-wide interleaving. The SAM hashes lines across the HN-Fs of all dies. Latency is uniform, but on average half of all traffic crosses the link (for two dies), and a link failure affects every address.

Many systems offer both as boot options. Whichever is chosen, the SRAT/HMAT or DT description must match the SAM programming. A mismatch makes the OS place memory badly. It does not cause a functional failure, so it only shows up in performance validation. MPAM partitioning of the SLC and memory bandwidth (8.9) must also be configured consistently on every die.

Checkpoint

Q17.5.1 On a two-die system, the remote die’s clusters are powered up and their PEs enable caches and the MMU. Later, the primary die’s OS remaps a page with break-before-make (TLBI VAE1IS, DSB ISH). A thread running on the remote die keeps using the old mapping. Which bring-up step was most likely skipped or misordered?

  • A. The remote die’s PEs did not set SCTLR_EL1.C
  • B. The SAMs hash the page’s PA to different HN-Fs on the two dies
  • C. The remote clusters were never added to the package-wide DVM domain (or the gateway does not forward DVM messages), so the broadcast TLBI never reached them
  • D. The remote die’s GIC multichip routing table was not programmed
Answer

C. TLB invalidation crosses dies as DVM messages. If the remote clusters are outside the DVM domain, the DSB can complete without them, and their TLBs keep the stale entry. If they were in the domain but the gateway dropped the Sync, the DSB would usually hang instead. Inconsistent SAMs (B) break data coherency, not TLB invalidation. The cache enable (A) and GIC routing (D) are not involved in TLB maintenance.

Read more: Arm ARM (DDI0487), TLB maintenance instructions, broadcast to the Inner Shareable domain; AMBA CHI specification, DVM operations

Q17.5.2 Why must the address maps of all dies be programmed consistently before any PE enables its D-cache for memory homed on another die?

  • A. Coherency relies on exactly one home node per cache line. If requesters disagree about which home node owns a line, two snoop filters each track their own copies, and writes can be lost with no error reported
  • B. The Arm ARM requires the SAM to be programmed before SCTLR_EL3.C is set
  • C. Otherwise DC CIVAC is UNDEFINED
  • D. The SLC is disabled until the SAM is valid, so caches would be bypassed anyway
Answer

A. The SAM is an interconnect structure the Arm ARM doesn’t know about (B, C). The danger is silent: a misprogrammed hash may still complete every transaction, but with two homes for one line, the “one coherent copy” property is lost. A missing SAM entry is the comparatively benign case, because it gives an error response. D invents a dependency that doesn’t exist.

Read more: AMBA CHI specification, Home Node and system address map; CMN TRM, RN SAM and HN-F SAM programming

Q17.5.3 After a link failure, every core of a two-die system takes an SError within a few microseconds, and many have been stuck in DSB instructions. What is the best first triage step?

  • A. Mask PSTATE.A on all cores and continue booting
  • B. Assume a memory ECC failure and offline the affected pages
  • C. Read each core’s DISR_EL1, since the SError was deferred by an ESB
  • D. Read the error records of the die-to-die gateway or link controller first. One link failure explains many SErrors (error responses to outstanding remote accesses) and DSB hangs (missing DVM Sync or completion responses), so per-core records are secondary
Answer

D. Many simultaneous SErrors on all cores point to a shared component. The link’s own records say whether it failed and why. Masking SError (A) hides the evidence. Offlining pages (B) addresses a different, local fault. DISR_EL1 (C) is relevant only when the error was deferred by an ESB, which these asynchronous aborts were not necessarily, and it is not the first record to read.

Read more: RAS (DDI0587), error records and error nodes; Arm ARM (DDI0487), SError exceptions, DISR_EL1

17.6 Handing off to the OS

The last firmware stage (BL33: U-Boot, UEFI/EDK2, or a minimal loader) hands the PE to an operating system. For Linux on arm64 this handover is specified in a single document, Documentation/arch/arm64/booting.rst in the kernel tree, and that document is effectively a checklist of architectural state. This section reads it as an architecture contract: what each requirement means in Arm ARM terms, which boot stage is responsible for it, and how a violation shows up. The general handover checklist is in 12.2, and the EL3 enables it relies on are in 17.3.

The loader’s part: memory, DTB, image placement

Before the jump, the loader must have:

  • Initialised all RAM the kernel will use, and described it (DT memory nodes, or the UEFI memory map). Anything described and not reserved is the kernel’s to overwrite, so firmware-resident memory (BL31, BL32, the RMM, the SCP’s shared memory) must be excluded or listed in /memreserve/ or reserved-memory.
  • Placed the DTB on an 8-byte boundary, no larger than 2 MB. The kernel maps it cacheable with blocks of up to 2 MB, so the DTB must not share a 2 MB region with anything that needs different attributes, such as a Device region or Non-cacheable shared memory. Otherwise you get the mismatched-attribute aliases of 6.6.
  • Decompressed the kernel (arm64 has no self-decompressor) and placed the Image at text_offset from a 2 MB-aligned base in usable RAM, with at least image_size bytes free after it. Both values come from the 64-byte image header (magic 0x644d5241, “ARM\x64”), whose flags field also gives the kernel’s endianness and page size.
  • Quiesced every DMA-capable device. A DMA engine still writing into memory the kernel now owns corrupts it with no fault. Firmware drivers that started DMA (network boot, storage) must stop it, and an SMMU left in bypass does not help.

The CPU state at entry

The architectural requirements for the primary CPU, and the stage that normally satisfies each one:

RequirementArchitectural meaningSet by
x0 = physical address of the DTB; x1–x3 = 0Plain convention; nonzero x1–x3 are reserved for future useBL33
All of PSTATE.DAIF maskedNo exception may be taken before the kernel installs VBAR_EL2/VBAR_EL1BL33 (and BL31’s SPSR_EL3 for BL33)
Non-secure state, at EL2 (recommended) or EL1EL2 entry gives the kernel the choice of running with VHE at EL2 (KVM host) or installing a stub and dropping to EL1BL31 SCR_EL3.NS=1, HCE=1; BL33 must not drop to EL1 unnecessarily
MMU off at the entry ELSCTLR_ELx.M=0: data accesses are Device-nGnRnE, instruction fetches NormalBL33
I-cache on or off, but no stale entries for the imageAfter writing the image, IC IALLU (or by VA to the PoU) and DSB and ISB (8.6)BL33
Image cleaned to the PoC, by VA when a system cache or other coherent masters with caches enabled existWith M=0 the kernel’s first data accesses bypass the caches, so the image must be in memory. Set/way only cleans the local hierarchy (8.5)BL33
System caches that obey VA CMOs: configured, may be enabled; caches that don’t: configured and disabledThe kernel’s VA maintenance must be sufficient for correctnessPlatform firmware
CNTFRQ_EL0 programmed; CNTVOFF_EL2 consistent on all CPUs; at EL1 entry, CNTHCTL_EL2.EL1PCTEN=1Only the highest EL can write CNTFRQ_EL0. An inconsistent CNTVOFF_EL2 makes the virtual counters of different CPUs disagree (4.7)BL31 (CNTFRQ), BL31/BL33 (EL2 state)
All booted CPUs in the same coherency domainTLBI ...IS, DC ... broadcasts and Inner Shareable ordering must reach every CPU; this may require IMPLEMENTATION DEFINED setupBL31 and platform (17.4, 17.5)
All writable architected system registers at or below the entry EL initialisedNothing may run in an UNKNOWN state. This is the general rule behind the per-feature list that followsBL31 and BL33

The document’s register-level list then names specific bits, grouped by feature, separately for “EL3 is present” and for “the kernel is entered at EL1 and EL2 is present”. It is the Linux side of the EL3 checklist in 17.3. A representative selection:

FeatureIf EL3 is presentIf the kernel is entered at EL1 with EL2 present
EL2 entrySCR_EL3.HCE=1—
GICv3 in v3 modeICC_SRE_EL3.{Enable,SRE}=1; SCR_EL3.FIQ identical on all CPUs and constantICC_SRE_EL2.{Enable,SRE}=1
FP/SIMDCPTR_EL3.TFP=0CPTR_EL2.TFP=0
SVECPTR_EL3.EZ=1; ZCR_EL3.LEN identical on all CPUsCPTR_EL2.TZ=0 (or ZEN=0b11); ZCR_EL2.LEN identical
SMECPTR_EL3.ESM=1, SCR_EL3.EnTP2=1, SMCR_EL3.LEN identicalCPTR_EL2 SME traps off, fine-grained traps for TPIDR2_EL0 off
PAuthSCR_EL3.{API,APK}=1HCR_EL2.{API,APK}=1
MTESCR_EL3.ATA=1HCR_EL2.ATA=1
AMUCPTR_EL3.TAM=0, CPTR_EL2.TAM=0, AMCNTENSET0_EL0/AMCNTENSET1_EL0 setAMCNTENSET0_EL0/AMCNTENSET1_EL0 set
FGT, FGT2, HCX, TCR2, S1PIE, GCSSCR_EL3.{FGTEn, FGTEn2, HXEn, TCR2En, PIEn, GCSEn}=1Corresponding HCRX_EL2 and HFG*TR_EL2 enables set
Debug, PMU, BRBEMDCR_EL3.TDA=0, TPM=0, SBRBE = 0b01 or 0b11Matching MDCR_EL2/HDFG*TR_EL2 fields

The document allows one relaxation: where a value is specified to disable a trap, firmware may leave the trap enabled, provided the higher EL handles it transparently, as if the documented value had been set. A hypervisor emulating a register is fine. EL3 panicking or injecting an UNDEF is not.

Always check the version of booting.rst that matches the kernel you boot. The per-feature list grows with every new extension the kernel supports, and older firmware will not know about the newest entries.

Secondary CPUs

Every CPU must enter the kernel at the same Exception level and meet the same CPU-state requirements (MMU off, DAIF masked, timers, coherency, system registers). The DTB’s cpu nodes must carry an enable-method:

  • "psci": the secondaries stay outside the kernel’s memory (in firmware, or in reserved memory), and the kernel issues CPU_ON as described in the PSCI specification. The DT needs a psci node giving the conduit (smc or hvc).
  • "spin-table": each secondary spins in reserved memory on its cpu-release-addr (a naturally aligned, zero-initialised 64-bit location) until the kernel writes an entry address there and issues SEV (17.4).

With PSCI, BL31 satisfies the per-CPU state requirements on each secondary’s warm-boot path, using the same context code as for the primary. With spin-table, whatever ran on the secondary before it started spinning has to have done all of that, and nothing can correct it later.

Booting through UEFI

When BL33 is UEFI firmware, the kernel image is also a PE/COFF executable (the header’s res5 field points at the PE header). It runs first as a UEFI application, the EFI stub. That changes what is visible at each point:

  • The stub runs under UEFI’s environment: MMU on with an identity map, caches enabled, at EL2 or EL1 as UEFI was entered.
  • The stub loads the initrd, fetches the DTB from the UEFI configuration table (or none, with ACPI), calls ExitBootServices(), and enters the kernel proper. Older kernels clean the image to the PoC and turn the MMU off first, then use the normal entry. Recent kernels (from around v6.2) can enter with UEFI’s identity map still live, through a kernel-internal path. Either way, this handover is internal to the kernel.

So with UEFI, the booting.rst MMU and cache rules are the stub’s concern, not the firmware’s, while the firmware’s obligations shift to the UEFI specification and to Arm’s BBR (Base Boot Requirements). The EL3-dependent items (SCR_EL3, CPTR_EL3, MDCR_EL3, CNTFRQ_EL0, GIC security configuration) remain BL31’s job in both paths.

Device tree or ACPI

The hardware description is the other half of the handover, and the choice is made by the platform class rather than by personal taste:

  • Device tree is the norm for embedded and SoC-specific platforms: U-Boot or a minimal loader, firmware and kernel often built together, and bindings maintained in the kernel tree. TF-A can pass a DTB (HW_CONFIG) through BL33 to the kernel.
  • ACPI (with UEFI) is required for Arm servers under SBSA/SystemReady SR. The OS discovers hardware through tables such as MADT (GIC and CPUs), GTDT (timers), IORT (SMMU and ITS topology), PPTT (cache and CPU topology), SRAT/HMAT (NUMA) and AEST (RAS), and runtime services go through firmware interfaces instead of OS drivers for platform-specific controllers.

The content requirements, the table-by-table mapping and the common mistakes found in compliance runs are in 18.6.

Bring-up note: when the kernel prints nothing at all, find out how far it got before guessing. Pass earlycon (for example earlycon=pl011,0x9000000 on QEMU virt), which uses a fixed MMIO console before the console driver probes. Without output, halt the core in the debugger: a PC in the kernel’s exception vectors with ESR_EL1/ESR_EL2 set means the kernel took an exception before its handlers were ready, often an EC 0x00 UNDEF from a missing EL3 enable (17.3). A PC near the image base with the MMU still off usually means a bad DTB pointer in x0 or an image that was not cleaned to the PoC. The full crash-decoding workflow is in 18.1.

Checkpoint

Q17.6.1 U-Boot loads Image with its D-cache enabled, invalidates the I-cache, and jumps to the kernel with the MMU and D-cache off. The kernel works on the development board, but on the production SoC, which adds a system-level cache, it crashes randomly in early boot. U-Boot cleans the kernel range with a set/way loop before jumping. What is wrong?

  • A. The I-cache must be disabled at kernel entry
  • B. The kernel must be entered with the D-cache on when a system cache exists
  • C. Set/way maintenance only affects the PE’s local cache hierarchy. Dirty lines can still sit in the system cache, while the kernel’s MMU-off accesses read the stale copy beyond it. The image must be cleaned by VA to the PoC, which the interconnect forwards through the system cache
  • D. The DTB is larger than 2 MB
Answer

C. booting.rst says this explicitly: in the presence of a system cache or other coherent masters with caches enabled, cleaning the image to the PoC “will typically require cache maintenance by VA rather than set/way operations”. Set/way is by definition local (8.8). The I-cache may be on or off (A). The D-cache must be off with the MMU off (B). D would break both boards.

Read more: Linux Documentation/arch/arm64/booting.rst, “Caches, MMUs”; Arm ARM (DDI0487), Data cache maintenance by set/way

Q17.6.2 A kernel that runs KVM boots on a new platform, but dmesg shows “CPU: All CPU(s) started at EL1”, and KVM is unavailable. EL2 is implemented. Which handover fault is most likely?

  • A. BL33 (or BL31’s entry point information for it) entered the kernel at EL1 instead of EL2, for example because BL33 dropped to EL1 itself or SPSR_EL3.M targets EL1h
  • B. SCR_EL3.RW=0
  • C. CNTHCTL_EL2.EL1PCTEN=0
  • D. The kernel was entered with the MMU on
Answer

A. Linux can use virtualization only if it is entered at EL2. It is the kernel’s choice to keep EL2 (VHE) or install a stub, so firmware must not decide by dropping to EL1. RW=0 (B) would make the lower ELs AArch32 or make the ERET illegal, not start the kernel at EL1. EL1PCTEN (C) affects counter access at EL1. A kernel entered with the MMU on (D) would most likely crash rather than report its EL.

Read more: Linux Documentation/arch/arm64/booting.rst, “CPU mode”; Arm ARM (DDI0487), SPSR_EL3.M

Q17.6.3 On an SVE-capable platform, Linux boots, but userspace programs sometimes see different maximum SVE vector lengths depending on the CPU they run on, and migrating SVE tasks between CPUs crashes. Firmware sets CPTR_EL3.EZ=1 on every CPU. Which requirement is violated?

  • A. SVE must be disabled at EL3 and enabled by the kernel
  • B. ZCR_EL3.LEN must be initialised to the same value on all CPUs. Otherwise EL3 caps the effective vector length differently per CPU, and the kernel’s assumption of a single system-wide maximum fails
  • C. CPTR_EL3.TFP must be 1 when SVE is used
  • D. SCR_EL3.EnTP2 must be set for SVE
Answer

B. The effective SVE vector length at a lower EL is constrained by ZCR_EL3.LEN. booting.rst therefore requires it to be identical on all CPUs, and similarly ZCR_EL2.LEN when entering at EL1. A contradicts the requirement that EZ be 1. TFP=1 (C) would trap FP and SVE register access entirely. EnTP2 (D) is an SME control.

Read more: Linux Documentation/arch/arm64/booting.rst, SVE requirements; Arm ARM (DDI0487), ZCR_EL3

Part 18: Debugging, validation and compliance

Prerequisites: 3.2 Entry and return, 3.4 SError, architecturally, 5.8 MMU faults and how to decode them, 9.3 Turning the MMU and caches on, 16.2 External debug and CoreSight, 16.7 RAS architecture, 17.3 The EL3 feature-enable checklist.

If you already know: how to decode ESR_ELx by hand and have triaged EL3 crashes before, skim 18.1 for its dumps and read the rest. If you have run the BSA/SBSA ACS and written ACPI tables, skim 18.6 for its list of common table mistakes.

Why this matters for bring-up/validation: this part turns the architecture in the rest of the book into procedures for finding out why a core crashed, hung or never started, and for proving that a system meets the specifications before an OS ever runs on it.

The first three sections are about failures. 18.1 works through five real crash dumps (a translation fault after MMU-on, an EC 0x18 trap, an SError, BTI and PAC failures, and an alignment fault in early C), reading each register only as far as the architecture says it is valid. 18.2 handles the case with no dump at all: a hung core. It sorts hangs into asleep, spinning on an exclusive, stalled on a Device access and stalled on a DVM sync, using PC sampling, CTI halts and MEM-AP reads, in increasing order of intrusiveness. 18.3 collects the signatures that recur on every new SoC, with the first check for each, and gives a procedure for triaging an SError from the error records outwards.

The last three sections are about validation. 18.4 compares FVP, RTL simulation, emulation, FPGA and silicon by the bug classes each can and cannot find, so that a pass on one platform is not mistaken for a pass on all of them. 18.5 builds a minimal self-checking test harness, with an expected-exception framework, signatures, OS-free multi-core synchronisation and seeded randomisation, and relates it to TF-A’s TFTF. 18.6 places the Arm ARM among the system specifications (BSA, SBSA, BBR, SystemReady, DEN0129), describes the ACS suites, and covers the ACPI and devicetree descriptions that compliance runs most often find wrong.

18.1 Decoding a crash end to end

A crash report is evidence, and it is only as good as your knowledge of when each register is valid. This section works through five realistic dumps, one bug class each. The field layouts come from 3.2 (EC, IL, ISS, the FAR_ELx validity rules), 5.8 (abort ISS fields) and Appendix D (the full EC and DFSC/IFSC card). Only the reasoning is shown here.

The decode procedure

Do these steps in the same order every time, because each one decides how to read the next:

  1. Which EL took it, and from where. Use the handler (which VBAR_ELx, which of the four vector groups), SPSR_ELx.M[4:0] (the EL and SP of the interrupted context, and AArch64 vs AArch32), and the EC’s own “lower EL” vs “same EL” split.
  2. EC = ESR[31:26]. This selects the ISS layout. Nothing else in ESR_ELx means anything until you have it.
  3. IL (bit 25). It is 1 for every exception from A64 code and for classes with no associated instruction. It is 0 only for a 16-bit T32 instruction, so if it reads 0 in pure A64 firmware, you have misread the register.
  4. ISS. Decode it per class, and check the “valid” bits (ISV, FnV, CV, IDS) before you trust any subfield.
  5. FAR_ELx. Read it only if the EC is one that writes it and FnV == 0. Otherwise it is UNKNOWN, which includes “still holds a value from an older fault”.
  6. ELR_ELx. This is the preferred return address. For synchronous exceptions it is the faulting instruction (SVC/HVC/SMC are the exceptions: there it is the next instruction). For asynchronous exceptions it is only where the PE happened to be.

A small decoder is worth keeping in every firmware image, because it lets the panic path print fields rather than a hex word:

static void decode_esr(uint64_t esr, uint64_t far, uint64_t elr, uint64_t spsr)
{
    unsigned ec  = (esr >> 26) & 0x3f;
    unsigned il  = (esr >> 25) & 1;
    unsigned iss = esr & 0x1ffffff;

    printf("ESR=%016lx EC=0x%02x IL=%u ISS=0x%07x\n", esr, ec, il, iss);
    printf("ELR=%016lx SPSR=%08lx (M=0x%lx)\n", elr, spsr, spsr & 0x1f);

    switch (ec) {
    case 0x20: case 0x21: case 0x24: case 0x25: {
        unsigned fsc = iss & 0x3f;
        printf("  xFSC=0x%02x WnR=%u S1PTW=%u CM=%u FnV=%u EA=%u\n", fsc,
               (iss >> 6) & 1, (iss >> 7) & 1, (iss >> 8) & 1,
               (iss >> 10) & 1, (iss >> 9) & 1);
        if (!((iss >> 10) & 1))
            printf("  FAR=%016lx\n", far);
        break;
    }
    case 0x18:
        printf("  %s S%u_%u_C%u_C%u_%u, x%u\n", (iss & 1) ? "MRS" : "MSR",
               (iss >> 20) & 3, (iss >> 14) & 7, (iss >> 10) & 0xf,
               (iss >> 1) & 0xf, (iss >> 17) & 7, (iss >> 5) & 0x1f);
        break;
    case 0x2f:
        printf("  IDS=%u AET=%u EA=%u DFSC=0x%02x\n", (iss >> 24) & 1,
               (iss >> 10) & 7, (iss >> 9) & 1, iss & 0x3f);
        break;
    }
}

Note that the FnV test applies to the data and instruction abort classes. For the other classes that write FAR_ELx (PC alignment, watchpoint) the rules in 3.2 apply.

Dump 1: translation fault just after MMU-on

The setting is BL31 on a new SoC, with the MMU enabled at EL3 a few hundred instructions earlier. The first printf after MMU-on never appears. The core is halted with the debugger, which finds it parked in the EL3 panic loop, and reads:

ESR_EL3 = 0x0000000096000046   ELR_EL3 = 0x000000000400a2c4
FAR_EL3 = 0x000000001c090000   SPSR_EL3 = 0x000003cd
  • SPSR.M = 0b01101 (from 0x3cd): EL3h, AArch64. The fault happened at EL3.
  • EC 0x25: Data Abort, same EL. IL = 1.
  • ISS 0x46: DFSC = 0b000110, a Translation fault at level 2. WnR = 1 (a store). S1PTW and CM are 0, so it was not the walk itself and not a cache maintenance instruction. FnV = 0, so FAR_EL3 is valid. ISV = 0, as the architecture requires for this fault at EL3 (ISV is 1 only for certain stage 2 aborts reported to EL2 and for FEAT_LS64 accesses), so do not look for the register number in the syndrome.
  • FAR = 0x1c090000 is the UART base. ELR is the str w1, [x0] in the UART driver.

Conclusion: the walk reached a level 2 table and found an invalid entry for the 2 MB block that covers the UART. The MMIO region was missing from the memory map (in TF-A, from plat_arm_mmap[] or the platform’s MAP_REGION_FLAT list). Because the level is 2, the walk started correctly. A wrong T0SZ or TTBR0_EL3 would fault at the start level or produce garbage instead (9.3).

Bring-up note: confirm by hand with AT S1E3W on the FAR, then read PAR_EL1. PAR_EL1.F == 1 with the same FST and level reproduces the fault without taking it (5.9). If AT succeeds but the store faults, suspect a stale TLB entry from an earlier table, which means a missing TLBI ALLE3 before enabling.

Dump 2: EC 0x18, a trapped system register access

Linux boots on a new board and dies before the console comes up. The panic arrives at TF-A’s EL3 unhandled-exception path:

ESR_EL3 = 0x0000000062360820   ELR_EL3 = 0xffff8000800a1b38
SPSR_EL3 = 0x000003c9          FAR_EL3 = (not valid for this EC)
  • SPSR.M = 0b01001: EL2h. The exception came from the kernel running at Non-secure EL2 with VHE. With HCR_EL2.E2H == 1, the TCR2_EL1 encoding executed at EL2 accesses TCR2_EL2, but the syndrome reports the encoding as issued.
  • EC 0x18: trapped MSR/MRS/system instruction, AArch64. Note that it was taken to EL3, not EL2. That alone tells you the trap bit lives in an EL3 register.
  • ISS 0x360820: Op0 = 3, Op2 = 3, Op1 = 0, CRn = 2, Rt = 1, CRm = 0, Direction = 0. That is MSR S3_0_C2_C0_3, x1, which is TCR2_EL1 (FEAT_TCR2).

Conclusion: the kernel saw ID_AA64MMFR3_EL1.TCRX != 0, enabled the feature, and wrote TCR2_EL1, but EL3 had left SCR_EL3.TCR2En == 0. This is the “feature arrives trapped until a higher EL enables it” pattern in its most common form (17.3). The fix is in EL3 (in TF-A, ENABLE_FEAT_TCR2), not in the kernel. The same signature with a different encoding points to other enables: an AMU register means CPTR_EL3.TAM, and HCRX_EL2 means SCR_EL3.HXEn.

The decode trap: had the kernel run at EL1 under a hypervisor, an EL2 control (HCRX_EL2.TCR2En, which also behaves as 0 while SCR_EL3.HXEn == 0, or a fine-grained trap) would take the same EC to EL2 first. The target EL is part of the diagnosis.

Dump 3: an SError with no obvious culprit

BL2 has just enabled the caches and is copying BL31 to DRAM when this appears:

ESR_EL3 = 0x00000000be000011   ELR_EL3 = 0x0000000004003a10
SPSR_EL3 = 0x000002cd          FAR_EL3 = (UNKNOWN)
  • EC 0x2F: SError. ISS: IDS = 0 (architected syndrome), DFSC = 0b010001 (asynchronous SError), AET = 0b000 (Uncontainable), EA = 0.
  • SPSR = 0x2cd: EL3h with only PSTATE.A clear (D, I, F set). The SError was taken as soon as it was unmasked.
  • ELR points at an ldp in memcpy. Ignore it: unless FEAT_RASv2 sets ISS.ELS, or an ESB synchronized the error, ELR says nothing about which access caused it (3.4).

What the dump does say: an error was signalled asynchronously, and the PE classed it as Uncontainable, so the PE could not limit its effects. What it does not say: which agent, which address, or whether it was a read or a write. The next evidence is outside the PE: the RAS error records (ERRSELR_EL1 and ERXSTATUS_EL1 for the core’s own nodes, the memory-mapped ERRnSTATUS and ERRnADDR of the DMC and interconnect nodes) and the interconnect’s own error logs. In this case the DMC node had ERRnSTATUS.{V,UE,AV} == 1 with ERRnADDR in the destination range: a cache linefill (or a partial-line write that forced a read-modify-write at the DMC) read ECC DRAM that had never been initialised. The fix was to scrub, that is write, all of DRAM before the first cacheable use. The procedure is in 18.3.

Dump 4: BTI and PAC failures

Two dumps from the same branch-protected (-mbranch-protection=standard) EL1 test payload.

4a: Branch Target exception.

ESR_EL1 = 0x0000000036000002   ELR_EL1 = 0xffff00000012a400   SPSR_EL1 = 0x00000805 (BTYPE=0b10)

EC 0x0D is a Branch Target exception. ISS.BTYPE = 0b10, which a BLR produces. ELR is the target of the indirect call, and the instruction there is not a BTI c/BTI jc/PACIASP landing pad. Typical causes are a hand-written assembly function without BTI c at its entry, or a function pointer into a data table. SPSR.BTYPE holds the same value. Note that FAR_ELx is not written: the faulting PC is ELR_ELx, and the branch that got you there is not recorded anywhere architectural. Use BRBE or ETE trace if you need it (16.6).

4b: Pointer authentication failure. What you see depends on FEAT_FPAC.

  • With FEAT_FPAC (an optional feature; see DDI0487 A2 for the versions that permit it), a failed AUTIASP faults immediately:

    ESR_EL1 = 0x0000000072000000   ELR_EL1 = <address of the AUTIASP or RETAA>
    

    EC 0x1C: ISS[1] (DnI) = 0 means an instruction key, and ISS[0] (BnA) = 0 means the A key. So the return address signed with APIAKey did not authenticate. Either the stack was corrupted, or the keys changed between sign and auth (a CPU-suspend path that does not restore APIAKeyLo/Hi_EL1 is the bring-up favourite).

  • Without FEAT_FPAC, AUT* does not fault. It produces a corrupted, non-canonical pointer, and the fault comes on the RET:

    ESR_EL1 = 0x0000000086000004   ELR_EL1 = 0x002000004012b8f0   FAR_EL1 = 0x002000004012b8f0
    

    EC 0x21, IFSC = 0b000100: a Translation fault at level 0 on an instruction fetch, the fault an out-of-range VA reports. ELR == FAR with corrupted upper bits is the PAC signature. The exact bit pattern differs between the original PAuth error-code scheme and FEAT_PAuth2, so do not try to decode it; the payload here runs from TTBR0 addresses around 0x4012_0000. Recover the caller from x30 in the saved frame record (x29 chain), not from ELR.

Dump 5: alignment fault in early C

The first C function in a new BL1 port, with the MMU still off at EL3:

ESR_EL3 = 0x0000000096000061   ELR_EL3 = 0x0000000000002f48   FAR_EL3 = 0x000000000400c010
  • EC 0x25, DFSC = 0b100001: Alignment fault. WnR = 1, CM = 0.
  • ELR points at dc zva, x0 inside the C library’s memset, called to zero .bss.

Why: with SCTLR_EL3.M == 0, data accesses are treated as Device-nGnRnE (6.2). Two A64 rules then bite, independently of SCTLR_EL3.A. Any unaligned access to Device memory takes an Alignment fault, and DC ZVA to Device memory always takes an Alignment fault. Compiled C freely emits both: memset/memcpy use DC ZVA and unaligned LDP/STP, and -O2 merges adjacent byte stores into unaligned wider ones. The fixes are to build early code with -mstrict-align and a memset that avoids DC ZVA, or to turn on the MMU and D-cache with .bss mapped Normal before running general C (TF-A clears .bss with its own assembly zeromem, which handles the MMU-off case).

Validation note: each of these five signatures makes a cheap directed test. Map a hole and store to it; write an EL3-gated register from EL1; inject a UE with the pseudo-fault generator (16.8); call a function without a landing pad; DC ZVA with the MMU off. Check that the reported EC, xFSC, FAR validity and target EL match the values above exactly. A mismatch in a field the architecture leaves UNKNOWN or IMPLEMENTATION DEFINED, such as a FAR value written for an EC that leaves it UNKNOWN, or the ELR of an SError, is not a bug, because those fields are permitted to vary. But the EC, xFSC and target EL are architecturally fixed, and any difference there is an RTL or model bug. The framework is in 18.5.

Checkpoint

Q18.1.1 A crash log shows EC 0x18 in ESR_EL3 with ISS decoding to MRS x0, S3_3_C13_C4_0 (AMEVCNTR00_EL0, an AMU counter register), taken from Non-secure EL1. Where do you look first?

  • A. HCR_EL2.TID3, because ID and feature registers are trapped by EL2
  • B. The kernel’s AMU driver, because EC 0x18 means the instruction was UNDEFINED
  • C. The EL3 configuration of AMU access (CPTR_EL3.TAM), because the exception was taken to EL3
  • D. ELR_EL3, because it holds the encoding of the register that was accessed
Answer

C. The target EL is part of the syndrome. A trap taken to EL3 is caused by an EL3 control. CPTR_EL3.TAM traps AMU register accesses from all lower ELs, so the fix is in firmware. A is tempting but describes a trap taken to EL2, and AMU counters are not ID registers. An UNDEFINED instruction would be EC 0x00, not 0x18.

Read more: Arm ARM (DDI0487), ESR_EL3, ISS encoding for an exception from MSR, MRS, or System instruction execution; CPTR_EL3

Q18.1.2 An SError arrives with ESR_EL3 = 0xBE000011. ELR_EL3 points into memcpy. What can you conclude from the PE’s state alone?

  • A. An Uncontainable error was signalled asynchronously. The instruction at ELR_EL3 need not have caused it, and the source must be found from the RAS error records and interconnect logs
  • B. The ldp at ELR_EL3 read poisoned memory, so the address is in FAR_EL3
  • C. The error is corrected (CE), so it is safe to ERET and continue
  • D. IDS == 1, so the rest of the syndrome is IMPLEMENTATION DEFINED and nothing can be concluded
Answer

A. DFSC = 0b010001 (asynchronous SError) with AET = 0b000 (UC) and IDS = 0. With no ESB synchronization and no FEAT_RASv2 ELS indication, ELR is just where the PE was. B describes a synchronous External abort, which would have EC 0x25. FAR_EL3 is UNKNOWN for this SError. D misreads bit 24, which is 0 in 0xBE000011.

Read more: Arm ARM (DDI0487), ESR_EL3, ISS encoding for an SError exception; RAS (DDI0587), error records

Q18.1.3 On a core without FEAT_FPAC, a function returns and the PE takes an Instruction Abort with IFSC = 0b000100 and ELR == FAR, where the FAR has unexpected bits set above the VA range. What is the most likely cause?

  • A. The vector table is not mapped
  • B. The function is missing a BTI c landing pad
  • C. TCR_EL1.T0SZ is too small for the return address
  • D. AUTIASP failed and produced a non-canonical return address, which faulted on the RET
Answer

D. Without FEAT_FPAC, an authentication failure does not fault. It corrupts the pointer’s upper bits so that its use faults: here, a level 0 translation fault on the fetch, at the bad address. B would be EC 0x0D at the landing site. C would affect every address, not only this return. A gives recursive exceptions at VBAR, not one clean abort.

Read more: Arm ARM (DDI0487), Pointer authentication in AArch64 state; FEAT_FPAC

18.2 Triage of a hung core

A hung core leaves no exception and no log. The aim of triage is to classify the hang with as little disturbance as possible, before halting anything: is the core asleep, spinning, or stalled? Each answer points at a different layer. This section assumes the external debug and CoreSight background in 16.2.

The four hang classes

ClassWhat the PE is doingPC behaviourCan it be halted?Typical root cause
Asleep in WFI/WFEWaiting for an event or interrupt, possibly in a low-power stateConstant, at or just after the WFI/WFEUsually yes, if the core is powered. A halt request is a wake-up event for WFI/WFEInterrupt never delivered (4.5), missing SEV, timer not counting (4.6), core powered down by the power controller
Spinning on an exclusiveRetrying LDAXR/STLXR with STLXR always returning 1Cycles over a few instructionsYesExclusives to memory that has no global monitor, or a monitor cleared every iteration (10.1)
Stalled on a Device accessOne load (or a store before a DSB) waiting for a response that never comesFrozen at one load, or at the DSB after the storeOften not: entering Debug state may wait for the access, and that behaviour is IMPLEMENTATION DEFINEDUnclocked or reset peripheral, wrong address that the interconnect does not terminate, a firewall that drops instead of erroring
Stalled on a DVM syncDSB after TLBI ...IS or IC IVAU broadcast, waiting for all DVM participants to completeFrozen at the DSBOften not, for the same reasonA participant in the DVM domain that does not respond: a powered-down cluster or chiplet that was not removed from the domain, or an SMMU or chiplet link not set up for DVM (17.5)

The first two are software bugs at heart, and the debugger handles them easily. The last two are system bugs, and the PE is the wrong place to look: the stuck transaction lives in the interconnect.

Step 1: is the core powered and accessible?

Read EDPRSR over the debug APB. This read does not need the core to be in any particular state, as long as the debug power domain is on.

  • EDPRSR.PU == 0: the core power domain is off. External debug registers other than the few in the debug power domain return an error. This is not a hang: something (PSCI CPU_OFF, the power controller, a reset you did not expect) turned it off. Set EDPRCR.COREPURQ if you need the core to stay powered for debugging.
  • EDPRSR.R == 1: the core is held in reset. A secondary that never left reset is a power-controller or RVBAR problem (18.3).
  • EDPRSR.HALTED == 1: it is already in Debug state, possibly because someone’s CTI cross-halt fired.
  • Check the OS Lock (EDPRSR.OSLK) and the OS Double Lock status. Firmware that set the OS Lock on the power-down path and never cleared it blocks most external debug accesses.

Step 2: sample the PC without halting

PC sampling reads the PC of a running core with no effect on its execution. It is the most useful non-intrusive hang tool, and it is optional.

FeatureRegistersWhere
FEAT_PCSRv8EDPCSR (lo at 0x0A0, hi at 0x0AC), EDCIDSR, EDVIDSRExternal debug register block
FEAT_PCSRv8p2PMPCSR (at 0x200), PMCID1SR, PMCID2SR, PMVIDSRExternal PMU register block

EDPCSR exists only when FEAT_PCSRv8 is implemented and FEAT_PCSRv8p2 is not. Discover which one you have from EDDEVID.PCSample and PMDEVID.PCSample. Reading the low word captures one sample and latches the matching high word, the context ID and the VMID/EL/Security information into the companion registers, so always read the low word first. A low word of 0xFFFFFFFF means the PE is in Debug state or sampling is prohibited (for example, sampling Secure state without the authentication signal that permits it). The value is UNKNOWN in some cases, including when no branch has retired since the last read, so a core that is truly stalled may return stale or UNKNOWN values. That is itself a signal.

Read it in a loop and build a histogram:

HistogramDiagnosis
One address, a WFI or WFEAsleep. Next: check the GIC pending state and the wake-up source
2–5 addresses spanning LDAXR…CBNZExclusive spin. Next: what memory type is the lock in, and is the MMU on?
A tight loop elsewhereA software poll: read the variable it polls via the MEM-AP
One address, a load or a DSB, and later reads return UNKNOWNStalled. Next: the interconnect
Reads return 0xFFFFFFFFHalted, or sampling not permitted in the current state

The most common exclusive-spin case in early boot is a spinlock taken with the MMU and caches off. Then the lock is in Device-nGnRnE memory (MMU off), or in Non-cacheable memory. Exclusives to such memory need a global exclusive monitor in the memory system, and many DRAM controllers and interconnects do not provide one for those types. With no monitor, the store-exclusive can fail forever, or its behaviour is IMPLEMENTATION DEFINED (10.1). LSE atomics behave the same way in principle: a far atomic to an agent that does not support it may fault, hang or be handled by the interconnect, depending on the system.

Step 3: read system state over the MEM-AP

A MEM-AP (an AXI-AP or AHB-AP on the system bus, or an APB-AP on the debug bus) issues transactions into the system without the core’s help. Use it before halting anything:

  • The variable the core polls: the mailbox, the lock word or the holding-pen entry address. MEM-AP accesses are usually configured as non-cacheable system accesses. They see the value at the memory side of the interconnect, not dirty data still in the core’s cache. If the core reads a stale line that the writer never cleaned, the MEM-AP will show the “right” value while the core spins on the wrong one. That difference is the diagnosis (8.7).
  • GIC state: GICR_WAKER, GICR_ISPENDR0, GICD_ISPENDRn and GICD_IROUTERn for the interrupt that should have woken a sleeping core.
  • RAS records and interconnect error logs: for a stalled access, an interconnect node may have logged a timeout or a decode error.
  • Power controller and clock status for the target peripheral.

Bring-up note: If the MEM-AP itself hangs (no ACK from the AP, or CSW.TrInProg stays set), the system bus is wedged at the same point the core is. Switch to the APB-AP and the debug APB, which normally use a separate path. If the interconnect exposes its configuration and error registers on a debug-accessible path, that is where to look next. Ask the SoC team at design time for such a “back door” into the interconnect. Without one, a wedged bus is invisible.

Step 4: halt, with the CTI

Halting gives you all of the register state, but it changes the core: it can wake it from WFI, change timing, and break the race you are chasing. Halt only once the non-intrusive evidence has been collected.

The architected CTI connections on each PE are: output trigger 0 = debug request (halt), output trigger 1 = restart; input trigger 0 = cross-halt (this PE entered Debug state). To halt every core at once:

for each core n:
    CTICONTROL.GLBEN    = 1
    CTIGATE             = 0x1           // let channel 0 out to the CTM
    CTIOUTEN0           = 0x1           // channel 0 -> output trigger 0 (debug request)
    CTIINEN0            = 0x1           // cross-halt -> channel 0 (optional: halting one halts all)
then, on any one core's CTI:
    CTIAPPPULSE         = 0x1           // pulse channel 0
then, on each core:
    poll EDPRSR.HALTED; read EDSCR.STATUS for the reason
    CTIINTACK           = 0x1           // acknowledge output trigger 0 before restarting

Halting debug must be permitted. For a Non-secure-only debugger, Secure state with SPIDEN low means a request is held pending until the core enters Non-secure state. A core spinning in EL3 then looks “unhaltable”. Check EDSCR and the authentication status (DBGAUTHSTATUS_EL1, or the external view) first.

Once halted, read state by executing instructions through EDITR. For example, MRS x0, ESR_EL3 followed by MSR DBGDTR_EL0, x0 moves the value into the DCC, where the debugger reads it through the external DTR registers (DBGDTRTX_EL0 and DBGDTRRX_EL0 together hold a 64-bit value). Prefer reading system registers this way to running memory accesses in Debug state: a load issued in Debug state allocates into the cache and changes what you are looking at (16.2).

If the halt never completes (EDPRSR.HALTED stays 0 while the PC samples are frozen), the core is very likely waiting on an outstanding access or DSB that it cannot abandon. Go back to step 3. Some cores provide an IMPLEMENTATION DEFINED way to force completion or to see outstanding transactions; check the TRM.

DVM sync hangs in more detail

A TLBI VAE1IS is broadcast to every PE (and SMMU) in the Inner Shareable domain as a DVM operation. The DSB ISH that follows does not complete until a DVM Sync has been acknowledged by all participants (9.1). If any participant cannot reply (it is powered off but still in the snoop/DVM domain, it is in a die whose link is down, or it was never configured to accept DVM), every PE that issues broadcast maintenance hangs at its DSB. The signature is distinctive:

  • Several cores frozen at a DSB immediately after a TLBI or IC IVAU.
  • No fault, no SError.
  • Often triggered by the first CPU hot-unplug, or by the first boot with a second chiplet present.

The check is to compare the interconnect’s DVM domain membership with the set of powered clusters. On a DynamIQ system, power-down must leave the coherency and DVM domains through the sequence the DSU and TF-A implement (8.8, 17.4).

Validation note: reproduce each class on purpose to prove the triage path works before you need it: a WFI with all interrupts disabled at the GIC; an LDXR/STXR loop to a Device-nGnRE page; a load from an address the interconnect leaves unterminated (agree on one with the RTL team); and a TLBI VMALLE1IS; DSB ISH with one cluster held out of the DVM domain. For each, record the PC-sample histogram, whether a CTI halt completes, and what the MEM-AP and interconnect logs show. The PMU confirms the exclusive case without a debugger: STREX_FAIL_SPEC (where implemented) climbs while INST_RETIRED keeps counting, while in the stalled cases both counters stop.

Checkpoint

Q18.2.1 PC sampling on a core in early boot returns a cycle of three addresses: an LDAXR, an STLXR and a CBNZ. The MMU is still off. What is the most likely cause?

  • A. A missing SEV, so the core never leaves WFE
  • B. The lock is in memory that, with the MMU off, is Device-nGnRnE, and the system provides no global exclusive monitor for it, so the store-exclusive never succeeds
  • C. Another core holds the lock and is stalled on a DVM sync
  • D. The core is halted and the samples are UNKNOWN
Answer

B. The histogram shows the core retrying a store-exclusive. With the MMU off, data accesses are Device-nGnRnE, and exclusives to such memory depend on a system global monitor that many systems lack. C is possible, but then the loop would be the “lock is held” path, typically spinning on the LDAXR and WFE without reaching STLXR often. A would show a single WFE address. D would read 0xFFFFFFFF.

Read more: Arm ARM (DDI0487), Synchronization and semaphores: exclusive access instructions and Non-shareable/Shareable memory

Q18.2.2 Four cores are frozen at a DSB ISH that follows a TLBI VAE1IS. CTI halt requests do not complete. What do you check first?

  • A. ESR_EL1 on each core, after forcing a warm reset
  • B. Whether the TLBI was issued with the right ASID
  • C. Whether SCTLR_EL1.M is set on all cores
  • D. Whether every participant in the DVM domain is powered and able to respond, using the interconnect’s configuration and status registers over a debug path
Answer

D. DSB ISH after a broadcast TLBI waits for every DVM participant to complete the sync. A wrong ASID (B) would cause stale translations, not a hang. A warm reset (A) destroys the evidence, and ESR_EL1 holds nothing because no exception was taken. The evidence is in the interconnect, not in the PEs.

Read more: Arm ARM (DDI0487), TLB maintenance instructions, and the completion requirements of DSB

Q18.2.3 Why should a MEM-AP read of a mailbox be interpreted with care when diagnosing a core that polls that mailbox?

  • A. The MEM-AP normally sees the memory-side value, while the polling core may hit a stale line in its own cache, or the writer’s data may still be dirty in another cache
  • B. MEM-AP reads always halt the core first
  • C. A MEM-AP read clears the exclusive monitor of every core
  • D. MEM-AP accesses bypass the MMU, so they read a different physical address
Answer

A. MEM-AP transactions are system accesses that usually do not look up the PE’s caches. A disagreement between what the MEM-AP sees and what the core acts on is the classic sign of missing cache maintenance. D is tempting, but the MEM-AP issues physical addresses directly, so a VA must be translated first. That is a lookup step, not a reason for divergence. B is false: MEM-AP accesses do not involve the core.

Read more: CoreSight Architecture Specification and ADIv5/ADIv6, MEM-AP; Arm ARM (DDI0487), External debug memory access

18.3 Bring-up failure signatures

The failures in this section recur on almost every new SoC. Each comes with a signature (what you observe), the first check (the one measurement that splits the cause space in two), and a pointer to the section that holds the full mechanism. The second half gives a procedure for SError triage, the case where the PE gives the least help.

Dead after SCTLR_ELx.M = 1

Signature: the UART goes quiet at the MSR SCTLR_EL3, x0; ISB. There is no exception output, because the handler would need the same translation tables to run.

First check: halt the core and read PC, ESR_EL3, ELR_EL3 and SPSR_EL3.

  • PC in the vector region with ESR_EL3 showing an Instruction Abort (EC 0x21): the tables do not map the code that runs after the ISB, or they do not map the vectors. Read the xFSC level. A fault at the start level points at TCR_EL3.T0SZ/TG0/PS or TTBR0_EL3. A fault at the last level points at the memory map entries (9.3).
  • PC far from anything: the next fetch used a VA that is not the identity of the PA that was executing. The trampoline must be identity-mapped.
  • No exception at all, PC advancing normally, but output stopped: the UART is now accessed through a mapping it lacks, or as Normal memory, so writes are merged or held in a cache. Map MMIO as Device-nGnRE (6.5).

On FVP, run with Tarmac trace and look at the first fetch after the ISB: the trace prints the translation result. A boot path that works on FVP but fails on silicon with garbage walks is the stale-table-line case (18.4).

Recursive exceptions at VBAR

Signature: the PC is always within the vector table. ELR_ELx also points into the vector table, SPSR_ELx.M is the current EL with SPx, and ESR_ELx changes every time you look, or is stuck at an abort on the vector address.

Each nested exception overwrites ELR, SPSR, ESR and FAR, so the original fault is gone after the first recursion. The usual causes, in order of frequency:

  1. The handler’s first memory access faults. The stack (SP_EL3) is not mapped, not yet set up, or not 16-byte aligned with SCTLR_ELx.SA == 1. The prologue’s STP takes a Data Abort, which vectors to the same handler, which does the same STP.
  2. The vector table itself is not executable. It is not mapped, it is mapped XN, or VBAR_ELx was written with a misaligned value (its low 11 bits are RES0, so the table must be 2 KB aligned).
  3. The handler uses a feature that is still trapped, such as FP/SIMD register saves with CPTR_EL3.TFP == 1, which takes EC 0x07 to EL3 from inside the EL3 handler.

First check: make the first instructions of each vector entry record the syndrome without touching memory, so the original fault survives:

    .balign 0x80
sync_spx:                       // bring-up build only: clobbers x0-x3
    mrs  x0, ESR_EL3
    mrs  x1, ELR_EL3
    mrs  x2, FAR_EL3
    mrs  x3, TPIDR_EL3          // reset code zeroes TPIDR_EL3 before anything can fault
    cbnz x3, 1f                 // non-zero: a fault is already recorded, so this is recursion
    msr  TPIDR_EL3, x0          // first fault: keep its ESR where nothing else writes it
    b    real_sync_handler
1:  b    .                      // park: TPIDR_EL3 = first ESR, x0-x2 = nested fault

Nothing here touches memory, so it runs even when the stack and data are unmapped. It catches recursion wherever the nested fault happens (in the stub or in real_sync_handler’s prologue), because it keys on “a fault is already recorded” rather than on ELR. TPIDR_EL3 resets to an UNKNOWN value, so the reset code must zero it, and a same-EL synchronous exception is treated as fatal. A debugger halt then reads x0–x2 and TPIDR_EL3 with EDITR. The recursion guard turns an endless loop into a parked core that still holds the first syndrome. This is for a bare-metal or bring-up build: in TF-A, TPIDR_EL3 already holds the per-CPU context pointer, so pick a different scratch location there.

SError at the first DRAM access

Signature: an SError (EC 0x2F) shortly after the first cacheable access to DRAM, with ELR_ELx in an unrelated place.

Typical causes:

  • DRAM not trained or not out of self-refresh. The DMC returns a slave error, or the interconnect times out.
  • The address map is wrong. The DMC region in the interconnect’s system address map does not match what software uses, so a request decodes to nothing (17.5).
  • ECC memory not initialised. A read of a location that was never written has random check bits, so it reports an uncorrectable error. Partial-line writes are the trap: a cache eviction of a partly written line, or a narrow non-cacheable write, makes the DMC do a read-modify-write, and the read half fails. Initialise (scrub) all ECC DRAM with full-line writes, usually with the DMC’s own init engine, before the first use.
  • Speculative accesses. A large Normal mapping covers a hole or a not-yet-ready region, and the core speculatively fetches or prefetches from it (9.3, 14.2).

First check: read the DMC’s error records before anything else (see the procedure below). They tell you whether the DMC saw the request at all. If the DMC has no error, the request never reached it, and the interconnect logs are next.

A secondary core that never arrives

Signature: PSCI CPU_ON returns SUCCESS (it only means the request was accepted), but the secondary never prints, never checks in, and never increments its counter.

Split the problem by asking whether the core left reset, and then whether it reached the entry point:

ObservationLikely causeFirst check
EDPRSR.PU == 0 or EDPRSR.R == 1The power controller did not power it up or release resetPower controller status registers; the PPU/SCP firmware log
Core running, PC near RVBAR but loopingIt reached BL31’s warm-boot path but is waiting in a holding pen or on a mailbox it never seesMEM-AP read of the mailbox vs what the core reads. Missing clean to the PoC by the writer, or a missing SEV after the write (10.4)
PC at an unexpected address from the startRVBAR_EL3/the reset-address configuration register was not programmed for this core, or is per-cluster and only the boot cluster was setThe SoC’s reset-vector registers
Arrives at BL31, faults in the warm-boot pathPer-core state not initialised: MPIDR not in the platform’s core-position table, errata workarounds faulting on a different revision, CPUECTLR_EL1.SMPEN (pre-DynamIQ)MPIDR_EL1 vs the platform topology; TF-A’s plat_core_pos_by_mpidr
Arrives in the kernel, then hangs at the first TLBI ...ISCore not in the DVM/coherency domain18.2

The second row is the most common, and it is a cache-maintenance bug: the primary writes the entry point with caches on, and the secondary reads it with its caches and MMU off, from memory. The primary must clean the line to the PoC (DC CVAC, then DSB) before signalling. The secondary must not hit a stale line of its own when it turns caches on (8.8, 17.4).

A timer that never ticks

Signature: the first udelay() hangs, or the scheduler never preempts. No faults.

First check: read CNTPCT_EL0 twice. If the values are equal, the system counter is stopped (CNTCR.EN == 0 in CNTControlBase). If they differ, check CNTFRQ_EL0 against the real clock, then the timer interrupt path (PPI group, enable and priority, PMR). The full list is in 4.6.

Triaging an SError

An SError is, by default, the least attributable failure there is (3.4). Use this procedure:

1. Read the error records first

Do this before you reset anything, because a reset can clear the records (it depends on the node’s reset domain).

  • PE-local nodes: for each record n below ERRIDR_EL1.NUM, write ERRSELR_EL1 = n, ISB, then read ERXSTATUS_EL1, ERXADDR_EL1 and ERXMISC0_EL1.
  • System nodes (DSU/L3, interconnect home nodes, DMCs, SMMU): read the memory-mapped ERRnSTATUS, ERRnADDR and ERRnMISCx in each node’s RAS register frame, via the PE or the MEM-AP. On ACPI systems, the AEST table lists where they are (18.6).

For each record with STATUS.V == 1, note UE, DE, CE, OF (overflow, meaning more than one error), AV and ADDR (an address is valid), MV (MISC is valid) and the SERR code. A record with UE == 1 and a valid address in a DMC node identifies the failing request. A PE-local record often shows only “an external error was received”, which tells you to look further out. The field definitions are in 16.7.

2. Correlate with interconnect error logs

The interconnect usually has its own error capture, outside the Arm RAS register model or in IMPLEMENTATION DEFINED RAS nodes: decode errors (no target for an address), timeouts, firewall or TZC/GPC violations, and parity or ECC errors on internal paths. Match the address and requester ID against the core’s memory map. A decode error at an address in a Normal mapping that no code touches is a speculation problem. A firewall error on a Non-secure request to a Secure carve-out is an attribute bug.

3. Bisect by masking PSTATE.A

If the records do not identify the access, make the PE localize it:

    msr  DAIFSet, #4            // mask SError: it now stays pending
    // ... suspect region ...
    dsb  sy                     // force outstanding accesses to complete
    mrs  x0, ISR_EL1            // ISR_EL1.A (bit 8) == 1: an SError is pending
    // with FEAT_RAS, use ESB instead and read DISR_EL1.A

Binary-search the code between checkpoints: move the DSB plus check until one access separates “pending” from “not pending”. ISR_EL1.A works on any v8.0 core. With FEAT_RAS, ESB defers the pending SError into DISR_EL1 with its syndrome, which is more convenient (3.4). Remember that the DSB changes timing and can hide a race. If the bug disappears once checkpoints are added, that is information too.

Bring-up note: SCR_EL3.EA == 1 routes SErrors to EL3 regardless of where they occur. During bring-up that is what you want: one handler that dumps the error records for every SError. Leave the dumping in place in production firmware, since firmware-first handling, which reports errors to the OS through APEI/HEST (16.8), needs the same code.

Checkpoint

Q18.3.1 After enabling the MMU at EL3, the core loops forever in the vector table. ESR_EL3 reads as a Data Abort on an address just below SP_EL3’s initial value. What is the most likely root cause?

  • A. VBAR_EL3 is not 2 KB aligned
  • B. TCR_EL3.T0SZ is wrong, so no address translates
  • C. The EL3 stack is not mapped, so the handler’s first STP faults and re-enters the same handler
  • D. The original fault was an SError, which always recurses
Answer

C. The faulting address is the stack, and the PC can fetch the vector table, so the table and the code are mapped but the stack is not. B would make the vector fetch fail too, giving Instruction Aborts. A misaligned VBAR (A) gives fetches from the wrong address, not a data abort on the stack. D is false: an SError is masked on entry because PSTATE.A is set.

Read more: Arm ARM (DDI0487), VBAR_EL3; Exception entry, PSTATE on taking an exception

Q18.3.2 A secondary core’s PC samples show it looping in BL31’s warm-boot holding code, waiting for its entry point. A MEM-AP read of the mailbox shows the correct entry point. What is the most likely bug?

  • A. The secondary’s RVBAR_EL3 is wrong
  • B. The primary wrote the mailbox with caches on and did not clean it to the PoC, or the secondary is reading a stale line in its own cache
  • C. The secondary is held in reset
  • D. The GIC redistributor of the secondary is asleep
Answer

B. The core is running the right code (so not A or C), and the value is in memory (the MEM-AP sees it), but the core does not see it. That is a cache visibility problem between a cacheable writer and a reader that is non-cacheable or stale. D matters only if the secondary waits for an interrupt rather than polling a mailbox.

Read more: Arm ARM (DDI0487), Data cache maintenance instructions and the Point of Coherency

Q18.3.3 You are bisecting an imprecise SError. Which step makes a pending SError observable at a chosen point, without taking it?

  • A. Mask PSTATE.A, execute DSB SY, then read ISR_EL1.A (or, with FEAT_RAS, execute ESB and read DISR_EL1)
  • B. Set SCR_EL3.EA = 0 so the SError stays at EL1
  • C. Execute ISB, which makes all outstanding errors synchronous
  • D. Read FAR_EL3 after each store
Answer

A. With PSTATE.A masked the SError stays pending. The DSB waits for outstanding accesses so that errors they produce are signalled, and ISR_EL1.A or the ESB/DISR_EL1 path reports it. B changes routing, not attribution. ISB (C) is a context synchronization event, not an error synchronization barrier. FAR_EL3 (D) is not written for SErrors without FEAT_RASv2 indications.

Read more: Arm ARM (DDI0487), ISR_EL1; RAS Extension, Error synchronization barrier and DISR_EL1

18.4 Pre-silicon environments and their blind spots

Every pre-silicon platform answers some questions and is blind to others. A boot that works on FVP shows that the code follows the architecture as the model implements it. It does not show that the code has the barriers, cache maintenance and initialisation that real hardware needs. Bring-up goes faster when you know in advance which bug classes each platform can find, so that each one is used where it is strong.

FVP and Fast Models

Arm’s Fixed Virtual Platforms (FVP_Base_RevC-2xAEMvA, and the core-specific FVPs for a Neoverse or Cortex reference design) are built from Fast Models. They are programmer’s-view, instruction-accurate models. They are not cycle-accurate, and they are not a description of any particular microarchitecture.

What that means in practice:

  • Execution is in order and, per PE, one instruction at a time. Each instruction’s memory effects happen when it executes. There is no store buffer, no out-of-order completion and no reordering visible to other observers. In multi-core models, PEs are interleaved in quanta: one PE runs a block of instructions, then the next. The model therefore shows a sequentially consistent (in fact, coarsely interleaved) memory system. A missing DMB or acquire/release, a message-passing bug or a missing DSB before SEV almost never fails on FVP. Use herd7 for the ordering question (7.3, 7.11).
  • Caches are not modelled by default. With cache state modelling off, every access sees memory, and data and instruction cache maintenance has no visible effect. Missing DC CVAC, DC IVAC or IC IVAU, stale table walks after building tables with the MMU off (9.3), mismatched-attribute aliases (6.6) and cross-modifying code all pass. Set -C cache_state_modelled=1 (check the exact parameter names for your FVP with --list-params) for any run that is meant to test a boot path’s cache handling. It slows the model down noticeably, which is why it is off by default.
  • No speculation. The model does not speculatively fetch or load, so a Normal mapping over a PA hole, or an executable mapping of an unclocked device, causes no SError. On silicon it can (14.2).
  • UNKNOWN is usually deterministic. Where the architecture says a reset value or result is UNKNOWN, the model picks a value, often zero, and picks it consistently. Code that reads an uninitialised register, or depends on an UNKNOWN field, works every time.
  • IMPLEMENTATION DEFINED choices are parameters. The AEM implements many architecturally permitted behaviours and selects them through parameters (feature support levels such as cluster0.memory_tagging_support_level, PA size, cache geometry, TLB sizes). Make the parameter file part of your test record, because the result depends on it.
  • System components are functional. The GIC, SMMU, timers and interconnect behave correctly and quickly. Back-pressure, timeouts, a DVM participant that never answers and decode errors that only an interconnect configuration produces are absent.

Its strengths are real: it boots a full software stack at tens to hundreds of MIPS, it implements new FEAT_s before any silicon exists, and its Tarmac trace (the TarmacTrace plugin) records every executed instruction, register write, memory access and exception. Tarmac is the fastest way to answer “what was the last instruction before the core went wrong?” for architectural bugs: wrong trap enables, wrong ESR decoding, missing feature enables, bad exception returns.

FVP_Base_RevC-2xAEMvA \
  -C bp.secureflashloader.fname=bl1.bin -C bp.flashloader0.fname=fip.bin \
  -C cache_state_modelled=1 \
  -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 \
  --plugin "$PVLIB_HOME/plugins/Linux64_GCC-9.3/TarmacTrace.so" \
  -C TRACE.TarmacTrace.trace-file=boot.tarmac

The plugin path and the exact parameter names differ between FVP releases. Check them with --list-params and --list-instances.

RTL simulation

RTL simulation (VCS, Xcelium, Questa) runs the actual design with timing at cycle level, usually with four-state logic (0, 1, X, Z).

  • X-propagation. Flops without reset come up as X. If software reads state the architecture calls UNKNOWN after reset (a register field it never wrote, an uninitialised SRAM, a cache tag array that has not been invalidated), the X flows into data paths and eventually into a branch decision or an address. In simulation this shows up as X on a bus, an assertion, or an X-pessimism stall. This is the only platform that tells you, directly, that you depended on UNKNOWN state (17.1). It is also why RTL teams are strict about “invalidate before enable” sequences in reset code: on silicon the same bug gives a random value instead.
  • Real microarchitecture. Store buffers, reordering, speculation, real caches and the real interconnect are all present. Ordering bugs and missing maintenance can appear, but only if the test causes the right interleaving within a very small number of cycles.
  • Speed. Full-SoC RTL simulation typically runs at a few hundred Hz to a few kHz. You will not boot Linux, and probably not all of TF-A. Directed tests of a few thousand instructions are the right size (18.5).
  • Visibility. Every signal is visible. A hang is debugged by looking at the outstanding transaction in the waveform, which silicon can never give you.

Emulation

Hardware emulators (Cadence Palladium, Synopsys ZeBu, Siemens Veloce) map the RTL onto dedicated hardware and typically run at around 1 MHz, enough to boot firmware and, slowly, an OS.

  • Usually two-state. X becomes 0 or 1, so X-propagation bugs disappear or become deterministic-but-wrong. Some emulators offer limited X modelling at a cost.
  • Same RTL timing ratios as silicon, within the emulated clock domains, so many ordering and coherency races can appear. But memories, PHYs and analog blocks are replaced by models or speed bridges, and their timing is not real.
  • Good visibility through triggers and waveform capture over a window, and good for running the same software as silicon, including ACS suites (18.6).

FPGA prototypes

FPGA platforms (HAPS, or in-house boards) run the RTL, partitioned over several FPGAs, at roughly 10–100 MHz.

  • Fast enough to boot Linux and run long stress tests, which makes them the first platform where rare races appear at all.
  • Clock ratios are distorted. The core may run at 20 MHz against DDR at a much higher relative speed, or the reverse, and inter-FPGA links add latency. A race may be hidden, or a new one created that silicon does not have.
  • DDR, PCIe and other PHYs are usually FPGA-vendor IP, not the real ones. DDR training, PHY bring-up and power management are not tested.
  • Visibility is limited to what was instrumented at build time: internal logic analysers and CoreSight, much like silicon.

What only silicon finds

  • Timing-dependent races at real frequency and with real latencies: barrier omissions that need a particular interleaving, coherency races between cores at different DVFS points, and DVM sync storms.
  • Power-management races: a core power-down that interacts with snoops, a retention entry that races an interrupt, clock-gating and voltage-domain crossings. Emulation often models power domains functionally, without the analog behaviour.
  • Physical effects: PVT corners, marginal DDR training, metastability on asynchronous crossings, and real ECC errors.
  • Real peripherals: their reset timing, their response to speculative or unaligned accesses, and their error responses.

Which platform finds which bug class

Bug classFVP (default)FVP + cache modellingherd7RTL simEmulationFPGASilicon
Wrong trap/feature enables, ESR decoding, ERET legalityYesYes–Yes (slowly)YesYesYes
Missing cache maintenance (CMOs, MMU-off tables)NoYes (logic only)–YesYesYesYes
Missing barrier, ordering bugNoNoYes (proves allowed outcomes)RarelySometimesSometimesSometimes, intermittently
Dependence on UNKNOWN stateNoNo–Yes (X-prop)RarelyRandomRandom
Speculative access to holes or devicesNoNo–Yes, if the test triggers itYesYesYes
Interconnect address map, decode errors, DVM membershipOnly if modelledOnly if modelled–YesYesYesYes
DDR training, PHYs, analogNoNo–NoNoNoYes
Long-running races, stressFunctional onlyFunctional only–NoSlowlyYesYes
Power-management racesNoNo–PartiallyPartiallyPartiallyYes

The “Yes” in bold marks the cheapest platform for each class. “Sometimes” means the platform can show the bug but gives no assurance when it does not.

Validation note: a pass on FVP with default parameters is not a pass on the memory system. For every boot path and test, record the platform and its configuration: the FVP parameter file with cache_state_modelled, the emulator build, the FPGA clock ratios. Re-run anything that touches caches, translation tables or ordering on a platform that models them. On silicon, confirm the CMO paths with the PMU: L1D_CACHE_REFILL and L1D_CACHE_WB counts should change when maintenance is added or removed, and if they do not, the test is not exercising the cache at all (16.5).

Checkpoint

Q18.4.1 A boot path builds translation tables with the MMU off, never invalidates them, then enables the MMU with cacheable walks. It passes on FVP_Base_RevC with default parameters. Why?

  • A. FVP walks are always Non-cacheable regardless of TCR_ELx.IRGN0
  • B. FVP implements FEAT_BBM level 2, which removes the need for maintenance
  • C. Cache state is not modelled by default, so the walk always sees memory and there are no stale lines to hit
  • D. The architecture guarantees that caches are invalid at reset
Answer

C. With cache_state_modelled off, the model has no cache contents, so stale lines cannot exist. D is the tempting answer, but the architecture does not guarantee that caches are invalid out of reset, and stale lines can also come from an earlier boot stage or a warm reset. BBM (B) is about changing live translation entries, not about cache coherency of the tables.

Read more: Arm ARM (DDI0487), Cache behavior at reset; Arm Fast Models / FVP Reference Guide, cache modelling parameters

Q18.4.2 Which platform is best placed to reveal that reset code reads an UNKNOWN register field before writing it?

  • A. Four-state RTL simulation, because the field comes up as X and its propagation is visible
  • B. FVP, because it randomises UNKNOWN values on every run
  • C. A two-state emulator, because X is reported as an error
  • D. herd7, because it enumerates all values a register can hold
Answer

A. Only four-state simulation carries “unknown” as a value through the logic. B is false: FVP chooses deterministic values. C is backwards, because two-state emulation resolves X to 0 or 1. herd7 (D) models memory ordering, not reset state.

Read more: Arm ARM (DDI0487), Glossary: UNKNOWN; Reset behavior

Q18.4.3 A message-passing sequence between two cores lacks a DMB between the data store and the flag store. It passes millions of iterations on FVP. What should you conclude?

  • A. The sequence is correct, because FVP is the architecture’s reference model
  • B. Nothing about correctness. FVP executes in order and interleaves cores in quanta, so it cannot show the reordering the architecture permits. Check with herd7 and stress on hardware
  • C. The sequence is correct only for Inner Shareable memory
  • D. The model must have cache modelling enabled to show reordering
Answer

B. The Arm memory model allows the flag to be observed before the data without a barrier. FVP’s in-order, quantum-interleaved execution never produces that outcome, so a pass tells you nothing. A confuses an instruction-accurate model with an axiomatic memory model. D is wrong: cache modelling adds cache state but not reordering.

Read more: Arm ARM (DDI0487), The AArch64 Application Level Memory Model; herdtools7 documentation

18.5 Writing directed architectural tests

A directed architectural test sets up a precise architectural state, performs one operation, and checks that the outcome is one the Arm ARM allows. Tests of this kind are small enough to run on RTL simulation (18.4), self-checking so that no human reads a log, and deterministic or seed-reproducible. This section builds the minimum harness: EL setup, an expected-exception framework, result signatures, multi-core synchronisation without an OS, and controlled randomisation. It then maps the same ideas onto TF-A’s test framework (TFTF).

A minimal EL3/EL2/EL1 harness

The harness owns the vectors at every EL, sets safe defaults, and drops to the EL under test. Everything not under test is either enabled or explicitly trapped, never left at its reset value, because many reset values are UNKNOWN (17.1).

    .globl _start
_start:
    mrs   x0, MPIDR_EL1
    and   x0, x0, #0xffff                 // Aff1:Aff0; adapt to the platform
    bl    core_index                      // x0 -> linear core id in x19
    adr   x1, stacks_top
    sub   x1, x1, x19, lsl #12            // 4 KB stack per core
    mov   sp, x1                          // (SUB shifted-register cannot write SP)

    adr   x0, vectors_el3
    msr   VBAR_EL3, x0
    mov   x0, #(1 << 10) | (1 << 0)       // SCR_EL3: RW=1 (lower ELs AArch64), NS=1
    orr   x0, x0, #(1 << 8)               // HCE=1: HVC enabled
    orr   x0, x0, #(3 << 4)               // bits [5:4] are RES1
    msr   SCR_EL3, x0
    msr   CPTR_EL3, xzr                   // no FP/SVE/AMU traps (adjust per test)
    // Write every SCTLR_ELx explicitly. Do not inherit reset values.
    ldr   x0, =SCTLR_EL2_TEST_VALUE
    msr   SCTLR_EL2, x0
    isb
    // Drop to EL2h with DAIF masked
    mov   x0, #0x3c9
    msr   SPSR_EL3, x0
    adr   x0, el2_entry
    msr   ELR_EL3, x0
    eret

Two habits matter more than the code. First, a test states its architectural preconditions (the feature it needs from the ID registers, the EL it runs at, the memory type of each buffer) and checks them at run time. A test that is skipped because ID_AA64PFR1_EL1.MTE == 0 reports “skipped”, not “passed”. Second, the harness has a single exit path that writes a result to a location the testbench watches (below), so a test never ends in an unbounded loop.

The expected-exception framework

Most architectural tests are about exceptions: “this access must fault with this syndrome”, “this instruction must trap to EL2, not EL3”, “this one must not trap”. The framework gives the test a way to declare what it expects before running the operation, and makes the vector record what actually happened.

struct exc_record {
    uint64_t esr, far, elr, spsr;
    uint32_t el;        /* EL the exception was taken to */
    uint32_t taken;     /* number of exceptions since arm */
};

struct exc_expect {
    uint32_t el;        /* expected target EL */
    uint32_t ec;        /* expected ESR_ELx.EC */
    uint32_t iss_mask, iss_val;
    uint64_t far;       /* expected FAR, or ~0 if FAR must not be checked */
    int      skip;      /* bytes to advance ELR on return (4 = skip the faulting insn) */
};

volatile struct exc_record exc_log[NCPU];
volatile struct exc_expect exc_exp[NCPU];

The synchronous handler at each EL saves the general-purpose registers, then:

void sync_handler(uint32_t el, uint64_t esr, uint64_t far, uint64_t elr, uint64_t spsr)
{
    unsigned cpu = this_cpu();
    exc_log[cpu] = (struct exc_record){ esr, far, elr, spsr, el, exc_log[cpu].taken + 1 };

    if (exc_exp[cpu].ec == EXC_NONE)          /* nothing expected: unexpected exception */
        test_fail(cpu, FAIL_UNEXPECTED_EXC);

    write_elr(el, elr + exc_exp[cpu].skip);   /* step over the faulting instruction */
}

and the test reads:

    expect_exception(/*el=*/2, /*ec=*/0x18, ISS_SYSREG_MASK, ISS_SYSREG(TCR2_EL1, WRITE), ~0ULL, 4);
    write_tcr2_el1(0);                       /* from EL1, with HCRX_EL2.TCR2En == 0 */
    check_exception_taken();                 /* compares exc_log with exc_exp, clears both */

Rules that keep the framework honest:

  • Check the target EL, and that exactly one exception was taken. A trap taken to the wrong EL is the most common category of real architectural bug, and a double fault (the handler faulting) is otherwise invisible.
  • Check only architecturally fixed fields. EC, the xFSC, the fault level, WnR and the trapped encoding are fixed. FAR when FnV == 1 or for an EC that does not write it, ELR for an asynchronous exception, and the IMPLEMENTATION DEFINED parts of an SError syndrome (IDS == 1) are not (18.1). Masks exist for that reason.
  • Return via ELR + skip only for synchronous exceptions. For tests that expect an SError or an interrupt, the handler must return to ELR unchanged, and the test must bound the wait (a DSB/ESB, a timer, or a loop count) and report “not taken” as a failure.
  • Keep the vector path minimal. The handler’s own memory accesses must not disturb the state under test. For cache and TLB tests, put the log in a separate Device or Non-cacheable page so that logging does not allocate lines.

Self-checking with signatures

On RTL simulation and emulation, there is no console, or it is too slow to use. Tests reduce their results to a signature: a running checksum (CRC32 or a simple multiply-xor) over every observed value, compared at the end with a golden value.

static uint32_t sig = 0x811c9dc5u;
static inline void sig_add(uint64_t v)          /* FNV-1a over 8 bytes */
{
    for (int i = 0; i < 8; i++) { sig ^= (uint8_t)(v >> (8 * i)); sig *= 16777619u; }
}

void test_end(void)
{
    mmio_write_32(TB_MAILBOX, sig == GOLDEN_SIG ? TB_PASS : (TB_FAIL | (sig & 0xffff)));
    for (;;) wfi();
}

The testbench watches TB_MAILBOX (often a magic address decoded by a simulation-only agent) and ends the run. Golden values come from running the same binary on a reference: the AEM FVP for architectural results, or a previous known-good RTL release. Only put deterministic values into the signature: syndrome fields, data values, pass/fail of each check. Timer values, cycle counts and IMPLEMENTATION DEFINED fields go in a separate log or not at all. For tests whose outcome can legally vary (ordering tests, for example), hash the set of allowed outcomes into a pass/fail bit rather than the raw outcome.

Multi-core synchronisation without an OS

Many architectural tests need several PEs to act at the same moment: a TLBI broadcast observed by another core, a store observed by a load, a message-passing pattern. The harness needs a barrier that works before any OS and, often, with caches off.

/* Sense-reversing barrier. Requires the counter to be in memory where
 * atomics work for every participant: normally Inner Shareable WB Normal, MMU on. */
void cpu_barrier(volatile uint32_t *count, volatile uint32_t *sense, uint32_t n, uint32_t *local_sense)
{
    *local_sense ^= 1;
    if (__atomic_add_fetch(count, 1, __ATOMIC_ACQ_REL) == n) {
        *count = 0;
        __atomic_store_n(sense, *local_sense, __ATOMIC_RELEASE);
        __asm__ volatile("dsb ish; sev" ::: "memory");
    } else {
        while (__atomic_load_n(sense, __ATOMIC_ACQUIRE) != *local_sense)
            __asm__ volatile("wfe");
    }
}
  • Memory type. The barrier variables must be in memory where exclusives or LSE atomics work for all participants. That normally means the MMU is on and they are mapped Normal Inner Shareable Write-Back. With the MMU off they are Device, and whether exclusives work depends on the system (10.1, 18.2). If the test itself must run with the MMU off, synchronise through a simulation-provided hardware semaphore or through per-core flags with a single writer each, which need no atomics.
  • Wake-ups. SEV after the releasing store, with a DSB so the store is observed before the event (10.4). WFE loops must always re-check the condition, because WFE can wake spuriously.
  • Skew. A barrier aligns PEs to within some hundreds of cycles, which is far coarser than the window most ordering bugs need. For ordering tests, run many iterations with a small per-iteration random delay on each PE, as litmus7 does, to cover the interleavings (7.11).

Randomising addresses and attributes

Directed tests find the bug you thought of. Constrained randomisation inside a directed test finds its neighbours. Randomise only within the space the test’s precondition allows, and make every run reproducible from its seed.

  • Addresses: offset within a page, which page in a pool, cache-set aliasing (addresses that map to the same set), and crossing a page or a cache line.
  • Attributes: MAIR index (Normal WB/WT/NC, Device-nGnRE/nGnRnE), shareability, access permissions, nG and ASID, and the stage 2 attributes when EL2 is in use. Pick only legal combinations, or include mismatched attributes deliberately and check only what the architecture still guarantees (6.6).
  • Instruction variants: access size, LDP vs LDR, acquire/release vs plain, exclusive vs LSE, and DC by VA vs DC ZVA.
  • Seeds: use a simple LFSR or xorshift generator, seeded from the testbench (a plusarg or a memory word written before reset), and write the seed into the first word of the log. A failing seed must reproduce on every platform, which rules out seeding from the timer.

Validation note: pair every directed test with its PMU expectation where one exists. A test that maps a buffer Non-cacheable and reads it should see L1D_CACHE_REFILL stay flat. A TLBI test should see DTLB_WALK increase on the next access (16.5). If the PMU contradicts the architectural result, the test may be passing for the wrong reason: for example, a cache test that never allocated a line.

The TF-A test framework (TFTF)

TF-A Tests (the tf-a-tests repository) is the open source suite for TF-A itself. It is useful both as a test suite and as a reference harness.

  • What it is. TFTF runs as the Non-secure BL33 image, at NS-EL2 (or NS-EL1), on top of a real TF-A build. It tests the firmware interfaces from the normal world: PSCI (CPU_ON/OFF/SUSPEND, system suspend), SMCCC and the SMCCC_ARCH_WORKAROUND_* calls, SDEI, FF-A and the SPM, the TRNG and Errata ABIs, RAS and EA handling, and the EL3 feature enables, for example tests that access a newly enabled register and expect no trap. Secure partitions for SPM tests (Cactus, Ivy) and a Realm payload for RME are built from the same tree.
  • Test lists. Tests are grouped into XML test lists (tftf/tests/tests-*.xml), and a build selects one with TESTS=. make help_tests lists the sets, and the default is the standard set.
  • Multi-core and reboot. TFTF has its own CPU-on, barrier and timer services, and it can reboot the platform between tests, keeping state in non-volatile storage. It is a worked example of the synchronisation and expected-result patterns above.
# Build TFTF for FVP with the standard tests, then use it as BL33
cd tf-a-tests
make PLAT=fvp TESTS=standard tftf
cd ../trusted-firmware-a
make PLAT=fvp BL33=../tf-a-tests/build/fvp/release/tftf.bin all fip

TFTF tests the firmware against the architecture and the firmware specifications. It is not a CPU architecture compliance suite. For a new platform port, getting the standard TFTF set to pass on FVP, then on emulation, is a strong check that PSCI, the interrupt handling and the feature enables are wired correctly before any OS is involved.

Checkpoint

Q18.5.1 A directed test expects MSR TCR2_EL1, x0 at EL1 to trap to EL2 with EC 0x18. The exception log shows one exception, EC 0x18, with the correct ISS, taken to EL3. What should the test report?

  • A. Pass, because the EC and ISS match
  • B. Pass, because the target EL is IMPLEMENTATION DEFINED
  • C. Skip, because EL3 interfered
  • D. Fail: the target EL is part of the expected result, and a trap to EL3 means an EL3 control (SCR_EL3.TCR2En) is trapping, so the test precondition or the implementation is wrong
Answer

D. Which EL a trap is taken to is architecturally determined by which control causes it. A test that ignores the target EL misses exactly the class of bug it was written for. The harness should have set SCR_EL3.TCR2En = 1 as a precondition, and if it did, the implementation is wrong. B is false: the trap priority and routing are defined by the architecture.

Read more: Arm ARM (DDI0487), TCR2_EL1 accessibility pseudocode; SCR_EL3.TCR2En; HCRX_EL2.TCR2En

Q18.5.2 Which value is safe to include in a test’s golden signature?

  • A. FAR_EL1 after a synchronous External abort with FnV == 1
  • B. The DFSC and WnR of a translation fault on a store to an unmapped page
  • C. CNTPCT_EL0 at the end of the test
  • D. The ISS of an SError taken to EL1 with ESR_EL1.IDS == 1
Answer

B. The fault status code, level and direction of a translation fault are architecturally fixed. A is UNKNOWN by definition. C is timing-dependent. D is the tempting one, because it is still an ESR_EL1 value, but with IDS == 1 the rest of the ISS is IMPLEMENTATION DEFINED, so the golden value would differ between the reference model and the implementation under test.

Read more: Arm ARM (DDI0487), ISS encoding for an exception from a Data Abort; ISS encoding for an SError exception

Q18.5.3 A four-core test must synchronise before the MMU is enabled. Which approach is safe on an arbitrary system?

  • A. An LDAXR/STLXR counter in DRAM, since exclusives always work on DRAM
  • B. An LDADD counter in DRAM, since LSE atomics do not need a monitor
  • C. One flag per core, each written only by its owner and polled by the others, with a DSB and SEV after each write
  • D. No synchronisation: cores leave reset at the same cycle
Answer

C. With the MMU off, data accesses are Device-nGnRnE. Exclusives (A) then depend on a global monitor in the system, and far atomics (B) depend on the target supporting them, neither of which is guaranteed. Single-writer flags need only ordinary stores and loads. D is false on any real system, where reset release is staggered.

Read more: Arm ARM (DDI0487), Exclusive access instructions and Shareable memory locations; Atomic instructions

18.6 Conformance and platform standards

The Arm ARM defines a PE. An OS needs a system: a timer it can find, an interrupt controller with a known programming model, an SMMU, coherent memory, error reporting, and firmware that describes all of it in a standard form. Arm’s system architecture specifications define that system, and the Architecture Compliance Suites (ACS) test it. For a validation engineer, conformance is the cheapest broad test there is, because someone else has already written thousands of tests against a public spec.

The specification layers

LayerSpecificationWhat it constrains
PE architectureArm ARM (DDI0487)Instructions, exception model, memory model, system registers
Companion architecturesGICv3/v4 (IHI0069), SMMUv3 (IHI0070), RAS (DDI0587), PSCI (DEN0022), SMCCC (DEN0028), FF-A (DEN0077)The interrupt controller, IOMMU, error records and firmware interfaces, each as an architecture with its own options
Base System ArchitectureBSA (DEN0094)The minimum system an OS can rely on: PE features, GIC version and configuration, Generic Timer and system counter (including a memory-mapped timer for wake-up), watchdog, PCIe integration, SMMU, power and wake-up semantics
Server Base System ArchitectureSBSA (DEN0029)BSA plus server requirements, organised in numbered levels. Each level is a superset of the one below and requires newer PE and system features (for example, a minimum architecture version, SMMU and PCIe features, and RAS)
Boot requirementsBBR (DEN0044)Firmware interfaces: UEFI, ACPI or devicetree, SMBIOS, PSCI, and their required subsets, organised as recipes (SBBR for ACPI servers, EBBR for embedded devicetree systems)
RME system architectureDEN0129The system side of Arm CCA: granule protection at completers, the PAS tags carried on the interconnect, Realm-aware SMMUs and debug, MEC (12.4)
Compliance programmeArm SystemReadyA named combination of BSA (and SBSA where applicable), BBR and the ACS results

SystemReady bands. The programme was restructured in late 2024 (requirements specification v3.0). There are now two bands: the SystemReady band, for UEFI plus ACPI systems (it absorbs the former SR and ES bands), and the SystemReady Devicetree band, for UEFI plus devicetree systems (formerly IR). The former LS band is deprecated. Older documents and many vendor pages still use the four-band names, so check the date of anything you read.

Two points that matter when reading these specs:

  • BSA and SBSA select options that the Arm ARM leaves open. The Arm ARM allows a system with no memory-mapped timer and permits the GIC to be configured in many ways. BSA requires a memory-mapped wake-up timer where PEs can enter power states that lose their local timer, and recommends a particular interrupt-ID allocation for the architected PPIs. A design can be fully compliant with the Arm ARM and still fail BSA.
  • The rules are written as numbered requirements (in BSA, IDs such as B_PE_01), and the ACS tests and logs reference them. Use those IDs when you file a failure with the RTL team.

The Arm ACS suites

SuiteTestsWhere it runsAvailability
Architecture compliance for the PE (often called ACK)The PE against the Arm ARM: instructions, exceptions, memory model, registersPre-silicon and silicon, in the licensee’s environmentArm licensees only, under licence. Implementations of Arm-designed cores rely on Arm’s own verification
BSA ACS and SBSA ACSThe system against BSA and SBSA: PE features visible to the OS, GIC and ITS behaviour, timers and watchdog, PCIe (ECAM, MSIs, ATS/PRI where required), SMMU, peripheral DMA coherency, power and wake-up, RAS (SBSA)UEFI application (the main form), plus Linux kernel-module tests for PCIe and DMA paths; also a bare-metal form for pre-siliconOpen source. The BSA and SBSA repositories were consolidated in 2025 into Arm’s sysarch-acs repository
RME ACS (rme-sysarch-acs)The DEN0129 invariants: GPC at completers, PAS propagation, Realm-aware SMMUBare-metal at EL3Open source
SystemReady ACS imageBSA/SBSA ACS plus the UEFI SCT, FWTS and BBR checks. OS installation is a separate step of certification, not part of the imagePrebuilt bootable imageOpen source

The ACS projects say this themselves: compliance tests are not a substitute for design verification. A pass means the system meets the rules the suite checks, in the configurations it reached. Treat the ACS as a broad smoke test, then target what it does not cover with directed tests (18.5).

Bring-up note: BSA and SBSA ACS have bare-metal and “pre-silicon” builds that run on emulation, given a platform abstraction layer (PAL) you write for your platform’s addresses and interrupt IDs. Run them before tape-out. A wrong PPI allocation or a missing wake-up timer is a cheap RTL change on emulation and an erratum on silicon.

What a validation engineer checks first

In this order, because each step depends on the one before:

  1. ID registers against the specification. Read every ID_AA64*_EL1 register on every core type and compare it with the core’s TRM and the SoC’s feature sheet: FEAT_ levels, PA size (ID_AA64MMFR0_EL1.PARange), granule support, GIC CPU interface (ID_AA64PFR0_EL1.GIC), RAS and AMU versions. Check them against what EL3 actually enables (1.1, 17.3). A heterogeneous system whose cores report different values for fields the OS treats as system-wide is a finding in itself.
  2. Timer frequency. CNTFRQ_EL0 on every core equals the system counter’s real frequency (measure it against an external reference), the counter is enabled and running (4.6), and the timer PPIs use BSA’s recommended IDs. Check BSA for the current list. The usual assignment is 30 for the EL1 physical timer, 27 for the EL1 virtual timer, 26 and 28 for the EL2 physical and virtual timers, and 29 for the Secure EL1 physical timer.
  3. GIC and ITS. Affinity routing on, GICD_TYPER and GICR_TYPER consistent with the topology, every Redistributor present and wakeable, and an LPI delivered through the ITS from a real device (4.4, 4.5).
  4. SMMU. SMMU_IDR0–IDR5 against the claimed features, stage 1 and stage 2 both working, StreamIDs as documented, and the PCIe RID-to-StreamID mapping as the firmware will describe it (11.5).
  5. PE coherency and memory. Multi-core coherency across clusters and dies, DMA coherency for masters claimed as coherent, and exclusives and atomics in every memory region an OS will place a lock in (8.10, 10.1).
  6. RAS injection. Every RAS node reachable, its records as described, and a pseudo-fault from each node delivered to firmware and reported to the OS (16.8).

Describing the hardware to the OS

Silicon that passes every architectural test can still fail compliance because firmware describes it wrongly. The OS knows the platform only through ACPI tables or a devicetree.

ACPI tableDescribesDT equivalent
MADTGIC Distributor, Redistributors, ITSs; one GICC entry per PE with its MPIDR, ACPI Processor UID, PMU and VGIC maintenance interruptsinterrupt-controller (arm,gic-v3) node, cpus node with reg = MPIDR affinity
GTDTArchitected timer interrupts and flags, CNTControlBase, memory-mapped timer frames, watchdogsarm,armv8-timer, arm,armv7-timer-mem, arm,sbsa-gwdt
IORTITS groups, SMMUv3 nodes, PCIe root complexes and named components, and the ID mappings between them (RID → StreamID → DeviceID)iommu-map, msi-map, iommus, msi-parent
PPTTProcessor hierarchy (package, cluster, core, thread) and cache propertiescpu-map, next-level-cache and cache nodes
SRAT, SLIT, HMATNUMA proximity domains for memory and PEs, distances, and bandwidth and latency attributesnuma-node-id, distance-map
AESTRAS error nodes: type (PE, memory, SMMU, GIC, vendor), interface (system register or memory-mapped), record ranges and interruptsNo standard binding in common use
APMTSystem PMUs: CMN, SMMU PMCG, and other Arm CoreSight PMU-architecture countersVendor-specific compatible nodes
MPAMMPAM MSCs: base address, interrupts, and the resource each controls (8.9)Proposed bindings

Others that appear in every compliance run: SPCR and DBG2 (the console), MCFG (PCIe ECAM), FADT (the HW_REDUCED_ACPI flag and the PSCI-compliant boot flags), and SDEI and HEST for error handling (16.8).

Common mistakes found in compliance runs

  • MADT GICC MPIDR does not match the hardware, often because the Aff fields are packed differently from what the cores report (for example, multi-threaded cores where Aff0 is the thread). The OS then brings up the wrong core or fails CPU_ON. The cross-check is MPIDR_EL1 read on each core against the table.
  • PPTT and MADT disagree. The PPTT processor’s ACPI Processor ID does not match the MADT UID, or caches are described without the “valid” flags set, so the OS’s scheduler topology and cache sizes are wrong without anything failing loudly.
  • GTDT timer flags. The architected timers are level-sensitive. Marking them edge-triggered, or giving the wrong polarity, causes lost or stuck timer interrupts. CNTControlBase must be set to 0xFFFFFFFFFFFFFFFF when not provided, not to 0.
  • IORT ID mappings off by one or misdirected. A RID range mapped to the wrong StreamID base, an output reference pointing at the ITS instead of the SMMU, or a missing single mapping for the SMMU’s own MSIs. PCIe devices enumerate, but DMA faults in the SMMU or MSIs never arrive.
  • NUMA domains that do not match the hardware, or SRAT without HMAT on systems where latency differences are large. This is not a functional failure, but it is a performance finding.
  • AEST and MPAM base addresses copied from a different SoC revision. The OS probes a RAS node or MSC that is not there, and takes an SError at boot.
  • Devicetree specific: a clock-frequency property in the arm,armv8-timer node that overrides CNTFRQ_EL0 (it exists only as a workaround for firmware that does not program CNTFRQ_EL0), PPI numbers given as INTIDs rather than PPI indices (devicetree uses INTID - 16), and missing dma-coherent on coherent masters, or present on non-coherent ones.

Validation note: make the tables testable. Generate the MADT, PPTT and IORT from the same source of truth as the RTL configuration (the topology, the address map and the StreamID allocation), not by hand. Then run the BSA ACS and FWTS on every firmware build. A failure in FWTS’s MADT or IORT checks, or an ACS PE test reporting “MPIDR mismatch”, is a firmware bug. A failure in an ACS GIC, timer or SMMU behavioural test is a hardware or integration bug. Classifying each failure this way before filing it saves a round trip.

Checkpoint

Q18.6.1 A design passes Arm’s PE compliance tests but fails a BSA ACS check because the system has no memory-mapped wake-up timer. How should this be classified?

  • A. An Arm ARM violation, since the Generic Timer architecture requires memory-mapped frames
  • B. A BSA non-compliance: the Arm ARM permits such a system, but BSA requires a timer that can wake PEs whose local timers are powered off
  • C. An ACS bug, because the PE tests passed
  • D. A devicetree problem, because the frame is not described
Answer

B. BSA constrains the options that the Arm ARM leaves open. The memory-mapped timer frames are described in the Arm ARM but are a system-level option there. BSA makes a wake-up-capable timer mandatory. D could cause a similar failure if the timer exists but is not described, but here it does not exist.

Read more: Arm Base System Architecture (DEN0094), Generic Timer and wake-up requirements; Arm ARM (DDI0487), The Generic Timer memory-mapped registers

Q18.6.2 On an ACPI system, PCIe devices enumerate correctly, but DMA from them faults in the SMMU with “unknown StreamID” events. Which table is most likely wrong?

  • A. MADT
  • B. GTDT
  • C. PPTT
  • D. IORT
Answer

D. The IORT holds the ID mappings from PCIe Requester IDs to SMMU StreamIDs (and on to ITS DeviceIDs). If a mapping is wrong, the OS programs the SMMU stream table for StreamIDs that the hardware does not emit. MADT (A) describes the GIC and PEs. It would matter for MSIs only through the ITS entries, not for SMMU StreamIDs.

Read more: Arm IO Remapping Table specification (DEN0049), ID mappings; SMMUv3 (IHI0070), Stream table

Q18.6.3 After a firmware update, Linux on a devicetree board reports a timer frequency that differs from CNTFRQ_EL0. What is the most likely cause?

  • A. A clock-frequency property in the arm,armv8-timer node, which the kernel uses in place of CNTFRQ_EL0
  • B. CNTCR.EN was cleared
  • C. The GTDT has the wrong timer flags
  • D. CNTVOFF_EL2 is non-zero
Answer

A. The property exists for firmware that fails to program CNTFRQ_EL0, and when present it overrides the register. B stops the counter but does not change the reported frequency. C is an ACPI table and does not apply to a devicetree boot. D shifts the virtual count, not its frequency.

Read more: Linux devicetree binding arm,arch_timer; Arm ARM (DDI0487), CNTFRQ_EL0

Appendices

The appendices collect the lookup material that the parts link to. They summarise and point back; the reasoning behind every entry is in the linked section, and the Arm ARM (DDI0487) remains the authority for every encoding and version.

  • A. Feature timeline: FEAT_ names from v8.0 to v9.6+, with permitted-from and mandatory-from versions, the ID register field that reports each one, the EL3/EL2 enable bit, and the section that covers it.
  • B. Register cheat sheet: the most-used system registers and their key fields, ID register field tables, and the AArch32 register mapping.
  • C. Barrier and maintenance recipes: one-line sequences for each common ordering, cache, TLB and power-transition case, each stating its PoU/PoC and ISH/OSH choice, plus the Linux barrier API mapping.
  • D. ESR and fault-status decode card: ESR_ELx EC values, the DFSC/IFSC codes, and a fault-signature table.
  • E. Bring-up checklists: EL3 initialisation, MMU on, GIC on, secondary CPU on, and caches off before power-down.
  • F. Glossary: the architectural qualifiers and the terms used in the book, each linked to its section.
  • G. References: DDI0487 and where to look in it, companion specifications, firmware interfaces, Arm learning guides, herdtools7, TF-A and the Linux sources.

Use C and E with the part they condense: C with Parts 7–9, E with Part 17. When an appendix and a section disagree, the section is the one that was derived step by step; report the discrepancy.

Appendix A: Feature timeline

This appendix lists the AArch64 features this book uses, with the two version attributes from DDI0487 section A2, the ID register field that reports each one, the higher-EL control that gates it, and the section that covers it. 1.1 explains how to read these attributes. 17.3 explains how to act on the enable column.

How to read the tables

  • Permitted from is A2’s “OPTIONAL from ArmvX”. It is often one version earlier than the extension set that introduced the feature, because A2 lets an Armv8.x implementation include features of Armv8.(x+1). It is sometimes much earlier: features that describe behaviour older cores already had, or infrastructure such as FEAT_TCR2, are permitted from v8.0. Several chapters, and the version tags in 17.3’s checklist, name the introducing extension instead (for example “FEAT_FGT (v8.6)”). Where the two differ, this table is the reference.
  • Mandatory from is A2’s “mandatory from ArmvY”. A condition in parentheses means A2 makes the feature mandatory at that version only if the named feature is implemented: “v8.1 (EL2)” means “every v8.1 PE that implements AArch64 EL2”. A dash means A2 never makes it mandatory.
  • ID field gives the AArch64 field and, where the encoding distinguishes levels, the minimum value. Apply the field rules of 1.1: test with >=, and remember the signed fields.
  • Control is the main EL3 or EL2 enable or trap. A dash means the feature has no higher-EL gate (an instruction that is simply present, or a behaviour change). Bit positions for the EL3 controls are in 17.3 and Appendix B.

Sources: the version and dependency values were taken from Arm’s Feature names in A-profile architecture (document 109697, issue 2025_03), which reproduces the A2 feature descriptions, and the ID-field encodings were cross-checked against the Linux arch/arm64/tools/sysreg description. A2 changes with each DDI0487 issue, and features newer than the issue you hold are on Arm’s A-profile Architecture Extensions page. When a value here matters for a product decision, confirm it in the DDI0487 issue the project is pinned to.

What each version makes mandatory

This is the useful direction for bring-up: “the core claims v8.n, so these must be present”. A feature mandatory at v8.n is also mandatory at v9.(n−5) and later, and v9.0 requires the v8.5 set (1.2).

VersionMandatory (unconditionally)Mandatory if the named feature is present
v8.1FEAT_LSE, FEAT_PAN, FEAT_LOR, FEAT_HPDS, FEAT_CRC32FEAT_VHE (EL2), FEAT_RDM (AdvSIMD), FEAT_PMUv3p1 (PMUv3)
v8.2FEAT_RAS, FEAT_PAN2, FEAT_UAO, FEAT_DPB, FEAT_TTCNP, FEAT_ASMv8p2, FEAT_Debugv8p2FEAT_XNX (EL2), FEAT_FP16 (SVE or FHM)
v8.3FEAT_PAuth, FEAT_LRCPCFEAT_FCMA, FEAT_JSCVT (FP)
v8.4FEAT_LSE2, FEAT_LRCPC2, FEAT_DIT, FEAT_IDST, FEAT_BBM, FEAT_TTL, FEAT_TLBIOS, FEAT_TLBIRANGE, FEAT_FlagM, FEAT_Debugv8p4FEAT_SEL2 (EL2 and Secure state), FEAT_S2FWB (EL2), FEAT_DoubleFault (EL3), FEAT_RASv1p1 (RAS), FEAT_TRF (ETMv4), FEAT_DotProd (AdvSIMD), FEAT_FHM (FP16), FEAT_PMUv3p4 (PMUv3)
v8.5FEAT_BTI, FEAT_SB, FEAT_CSV2, FEAT_CSV3, FEAT_SPECRES, FEAT_DPB2, FEAT_E0PDFEAT_EVT (EL2), FEAT_FRINTTS (FP), FEAT_PMUv3p5 (PMUv3), FEAT_SPEv1p1 (SPE)
v8.6FEAT_ECV, FEAT_PAuth2, FEAT_I8MMFEAT_FGT (EL2 or EL3), FEAT_BF16 (FP)
v8.7FEAT_WFxT, FEAT_XS, FEAT_PAN3FEAT_HCX (EL2), FEAT_AFP (FP), FEAT_MTE3 (MTE asynchronous faults), FEAT_PMUv3p7, FEAT_SPEv1p2
v8.8FEAT_MOPS, FEAT_NMI, FEAT_HBC, FEAT_CMOW, FEAT_TIDCP1, FEAT_ETS2, FEAT_Debugv8p8FEAT_HPMN0 (PMUv3 and EL2), FEAT_PMUv3p8, FEAT_SPEv1p3
v8.9FEAT_CLRBHB, FEAT_SPECRES2, FEAT_ECBHB, FEAT_CSSC, FEAT_TCR2, FEAT_SCTLR2, FEAT_Debugv8p9FEAT_FGT2 (EL2), FEAT_RASv2 (RAS), FEAT_MTE4 and FEAT_MTE_PERM (MTE2), FEAT_PMUv3p9, FEAT_SPEv1p4
v9.0the v8.5 set; AArch64 at EL0 and EL1 (FEAT_AA64EL0, FEAT_AA64EL1)FEAT_RDM, FEAT_FP16, FEAT_DotProd, FEAT_FHM, FEAT_FCMA, FEAT_JSCVT, FEAT_FlagM2, FEAT_FRINTTS (FP and AdvSIMD). FEAT_SVE2 is OPTIONAL in A2 but required in systems running rich operating systems (1.2)
v9.1–v9.3the v8.6–v8.8 setsat v9.3: FEAT_BRBEv1p1 (BRBE), FEAT_EBEP (PMUv3p9)
v9.4the v8.9 set, FEAT_CHKFEAT_SVE2p1 (SVE2), FEAT_SME2p1 (SME2)
v9.5FEAT_ASID2, FEAT_CPA, FEAT_ETS3, FEAT_STEP2FEAT_E3DSE (EL3), FEAT_FAMINMAX (FP), FEAT_LUT (AdvSIMD)
v9.6FEAT_CMPBR, FEAT_LSUI, FEAT_OCCMO, FEAT_SRMASK, FEAT_UINJFEAT_IDTE3 (EL3), FEAT_NV2p1 (NV), FEAT_SVE2p2 (SVE2), FEAT_SME2p2 (SME), FEAT_SPEv1p5 (SPE), FEAT_TRBEv1p1 (TRBE)

Nothing on the v9 line makes FEAT_RME, FEAT_SME, FEAT_MTE2, FEAT_GCS, FEAT_D128 or FEAT_BRBE mandatory. A2 also has negative rules: FEAT_DoubleLock is not implemented in any Armv9.0 PE, and FEAT_SEL2 and FEAT_RME each exclude FEAT_PCSRv8 (the external-debug PC sample registers, 18.2).

Bring-up note: Use the left column of this table as the first ID-register test on new silicon or a new FVP configuration. If a core claims v8.n and any unconditional feature for v8.n or below reads as not implemented, the claim, the RTL configuration or the model parameters are wrong, and that is worth finding before any firmware is debugged (18.6).

Memory model, atomics and barriers

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_LSEv8.0v8.1ID_AA64ISAR0_EL1.Atomic ≥ 0b0010–10.2
FEAT_LSE2v8.2v8.4ID_AA64MMFR2_EL1.AT–7.2, 10.3
FEAT_LSE128v9.3–ID_AA64ISAR0_EL1.Atomic = 0b0011–10.3
FEAT_LRCPCv8.2v8.3ID_AA64ISAR1_EL1.LRCPC ≥ 0b0001–7.7
FEAT_LRCPC2v8.2v8.4ID_AA64ISAR1_EL1.LRCPC ≥ 0b0010–7.7
FEAT_LRCPC3v8.2–ID_AA64ISAR1_EL1.LRCPC ≥ 0b0011–7.7, 10.3
FEAT_LS64v8.6–ID_AA64ISAR1_EL1.LS64 ≥ 0b0001HCRX_EL2.EnALS, SCTLR_EL1.EnALS10.3
FEAT_LS64_Vv8.6–ID_AA64ISAR1_EL1.LS64 ≥ 0b0010HCRX_EL2.EnASR, SCTLR_EL1.EnASR10.3
FEAT_LS64_ACCDATAv8.6–ID_AA64ISAR1_EL1.LS64 ≥ 0b0011SCR_EL3.ADEn, SCR_EL3.EnAS0, HCRX_EL2.EnAS010.3, 17.3
FEAT_MOPSv8.7v8.8ID_AA64ISAR2_EL1.MOPSHCRX_EL2.MSCEn, SCTLR_EL1.MSCEn2.3
FEAT_CSSCv8.7v8.9ID_AA64ISAR2_EL1.CSSC ≥ 0b0001–2.3
FEAT_WFxTv8.6v8.7ID_AA64ISAR2_EL1.WFxT = 0b0010(traps as WFI/WFE: HCR_EL2.TWI/TWE, SCR_EL3.TWI/TWE)10.4
FEAT_TWEDv8.5–ID_AA64MMFR1_EL1.TWEDSCR_EL3.TWEDEn, HCR_EL2.TWEDEn10.4
FEAT_XSv8.6v8.7ID_AA64ISAR1_EL1.XSHCRX_EL2.FnXS, HCRX_EL2.FGTnXS7.6, 9.1
FEAT_ExSv8.4–ID_AA64MMFR0_EL1.ExSSCTLR_ELx.EIS, SCTLR_ELx.EOS7.8
FEAT_ETS2v8.0v8.8ID_AA64MMFR1_EL1.ETS ≥ 0b0010–9.1
FEAT_ETS3v8.0v9.5ID_AA64MMFR1_EL1.ETS ≥ 0b0011–9.1

Caches and coherency

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_DPB (DC CVAP)v8.1v8.2ID_AA64ISAR1_EL1.DPB ≥ 0b0001HCR_EL2.TPCP traps it8.4, 8.5
FEAT_DPB2 (DC CVADP)v8.1v8.5ID_AA64ISAR1_EL1.DPB ≥ 0b0010HCR_EL2.TPCP8.4, 8.5
FEAT_CCIDXv8.2–ID_AA64MMFR2_EL1.CCIDX (0b0001 = 64-bit CCSIDR_EL1 format)–8.1
FEAT_EVTv8.2v8.5 (EL2)ID_AA64MMFR2_EL1.EVTHCR_EL2.TOCU, TICAB, TID4, TTLBIS, TTLBOS8.1
FEAT_CMOWv8.7v8.8ID_AA64MMFR1_EL1.CMOWSCTLR_EL1.CMOW, HCRX_EL2.CMOW8.6
FEAT_MPAMv8.2–ID_AA64PFR0_EL1.MPAM with ID_AA64PFR1_EL1.MPAM_fracMPAM3_EL3.TRAPLOWER, MPAM2_EL2 traps8.9
FEAT_OCCMOv9.5v9.6ID_AA64ISAR3_EL1.OCCMOsee DDI04878.4
FEAT_PoPSv9.5–ID_AA64MMFR4_EL1.PoPSsee DDI04878.4

Translation

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_HPDSv8.0v8.1ID_AA64MMFR1_EL1.HPDS ≥ 0b0001TCR_ELx.HPDn5.2
FEAT_HPDS2v8.1–ID_AA64MMFR1_EL1.HPDS ≥ 0b0010TCR_ELx.HWUnnn5.2
FEAT_HAFDBSv8.0–ID_AA64MMFR1_EL1.HAFDBS: 0b0001 AF only, 0b0010 AF and dirtyTCR_ELx.HA, TCR_ELx.HD5.6
FEAT_HAFTv8.7–ID_AA64MMFR1_EL1.HAFDBS ≥ 0b0011TCR2_ELx.HAFT5.6
FEAT_HDBSSv9.4–ID_AA64MMFR1_EL1.HAFDBS ≥ 0b0100SCR_EL3.HDBSSEn5.6
FEAT_HACDBSv9.4–ID_AA64MMFR4_EL1.HACDBSSCR_EL3.HACDBSEn5.6
FEAT_TTSTv8.3–ID_AA64MMFR2_EL1.ST–5.3
FEAT_LPAv8.1–ID_AA64MMFR0_EL1.PARange = 0b0110 (52-bit PA, 64K granule)TCR_ELx.IPS/PS5.7
FEAT_LVAv8.1–ID_AA64MMFR2_EL1.VARange = 0b0001TCR_ELx.TnSZ5.7
FEAT_LPA2v8.6–ID_AA64MMFR0_EL1.TGran4 = 0b0001, .TGran16 = 0b0010 (and the _2 fields for stage 2)TCR_ELx.DS5.7
FEAT_LVA3v9.3–ID_AA64MMFR2_EL1.VARange = 0b0010 (56-bit VAs, VMSAv9-128)–5.7
FEAT_D128v9.3–ID_AA64MMFR3_EL1.D128SCR_EL3.D128En, HCRX_EL2.D128En, TCR2_ELx.D1285.7
FEAT_SYSREG128v9.3–ID_AA64ISAR2_EL1.SYSREG_128SCR_EL3.D128En (traps report EC 0x14)2.5
FEAT_SYSINSTR128v9.3–ID_AA64ISAR2_EL1.SYSINSTR_128see DDI04875.7
FEAT_TCR2v8.0v8.9ID_AA64MMFR3_EL1.TCRXSCR_EL3.TCR2En, HCRX_EL2.TCR2En5.2
FEAT_SCTLR2v8.0v8.9ID_AA64MMFR3_EL1.SCTLRXSCR_EL3.SCTLR2En, HCRX_EL2.SCTLR2En17.3
FEAT_PANv8.0v8.1ID_AA64MMFR1_EL1.PAN ≥ 0b0001SCTLR_ELx.SPAN5.5
FEAT_PAN2v8.1v8.2ID_AA64MMFR1_EL1.PAN ≥ 0b0010–5.5
FEAT_PAN3v8.1v8.7ID_AA64MMFR1_EL1.PAN ≥ 0b0011SCTLR_ELx.EPAN5.5
FEAT_UAOv8.1v8.2ID_AA64MMFR2_EL1.UAO–5.5
FEAT_XNXv8.1v8.2 (EL2)ID_AA64MMFR1_EL1.XNX–11.3
FEAT_S1PIEv8.8–ID_AA64MMFR3_EL1.S1PIESCR_EL3.PIEn, TCR2_ELx.PIE5.5
FEAT_S1POEv8.8–ID_AA64MMFR3_EL1.S1POESCR_EL3.PIEn, TCR2_ELx.POE5.5
FEAT_S2PIE, FEAT_S2POEv8.8–ID_AA64MMFR3_EL1.S2PIE, .S2POEVTCR_EL2 enables (see DDI0487)11.3
FEAT_AIEv8.8–ID_AA64MMFR3_EL1.AIESCR_EL3.AIEn, TCR2_ELx.AIE6.5
FEAT_ATS1Av8.8–ID_AA64ISAR2_EL1.ATS1A–5.9
FEAT_PFARv8.8–ID_AA64PFR1_EL1.PFARSCR_EL3.PFAREn5.8
FEAT_ASID2v9.4v9.5ID_AA64MMFR4_EL1.ASID2–5.2
FEAT_TTCNPv8.1v8.2ID_AA64MMFR2_EL1.CnPTTBRn_ELx.CnP9.1
FEAT_VMID16v8.0–ID_AA64MMFR1_EL1.VMIDBits = 0b0010VTCR_EL2.VS9.1
FEAT_TTLv8.3v8.4ID_AA64MMFR2_EL1.TTL–9.1
FEAT_TLBIOSv8.3v8.4ID_AA64ISAR0_EL1.TLB ≥ 0b0001HCR_EL2.TTLBOS9.1
FEAT_TLBIRANGEv8.3v8.4ID_AA64ISAR0_EL1.TLB ≥ 0b0010–9.1
FEAT_BBMv8.3v8.4ID_AA64MMFR2_EL1.BBM (level 0, 1 or 2)–9.2

Exceptions, interrupts, timers and RAS

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_RASv8.0v8.2ID_AA64PFR0_EL1.RAS ≥ 0b0001SCR_EL3.TERR, SCR_EL3.EA, HCR_EL2.TERR, HCR_EL2.TEA3.4, 16.7
FEAT_RASv1p1v8.2v8.4 (RAS)ID_AA64PFR0_EL1.RAS ≥ 0b0010, or 0b0001 with ID_AA64PFR1_EL1.RAS_frac = 0b0001–16.7
FEAT_RASv2v8.8v8.9 (RAS)ID_AA64PFR0_EL1.RAS ≥ 0b0011–16.7
FEAT_IESBv8.1–ID_AA64MMFR2_EL1.IESBSCTLR_ELx.IESB3.4
FEAT_DoubleFaultv8.3v8.4 (EL3)ID_AA64PFR0_EL1.RAS ≥ 0b0010 (on a PE with EL3)SCR_EL3.NMEA, SCR_EL3.EASE3.3
FEAT_DoubleFault2v8.8–ID_AA64PFR1_EL1.DF2SCTLR2_ELx.NMEA, SCTLR2_ELx.EASE, SCR_EL3.TMEA3.3
FEAT_ADERR, FEAT_ANERRv8.8–ID_AA64MMFR3_EL1.ADERR/SDERR, .ANERR/SNERRSCTLR2_ELx.EnADERR, .EnANERR16.7
FEAT_E3DSEv9.4v9.5 (EL3)ID_AA64MMFR4_EL1.E3DSESCR_EL3.EnDSE, SCR_EL3.DSE3.4, 16.8
FEAT_NMIv8.7v8.8ID_AA64PFR1_EL1.NMISCTLR_ELx.NMI, HCRX_EL2.TALLINT4.3
FEAT_ECVv8.5v8.6ID_AA64MMFR0_EL1.ECV ≥ 0b0001SCR_EL3.ECVEn, CNTHCTL_EL2.ECV4.7
FEAT_ECV_POFFv8.5–ID_AA64MMFR0_EL1.ECV = 0b0010SCR_EL3.ECVEn (CNTPOFF_EL2)4.7
FEAT_CNTSCv8.3–CNTID.CNTSC (memory-mapped CNTControlBase frame)CNTCR.SCEN4.7
FEAT_IDSTv8.3v8.4ID_AA64MMFR2_EL1.IDS ≥ 0b0001HCR_EL2.TID31.1
FEAT_IDTE3v9.0v9.6 (EL3)ID_AA64MMFR2_EL1.IDS = 0b0010SCR_EL3.TID3, SCR_EL3.TID517.3
FEAT_UINJv9.0v9.6ID_AA64PFR2_EL1.UINJ–2.4
FEAT_EBEPv9.3v9.3 (PMUv3p9)ID_AA64DFR1_EL1.EBEPsee DDI0487 (PMU exception, EC 0x3D)2.4

Virtualization and Secure EL2

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_VHEv8.0v8.1 (EL2)ID_AA64MMFR1_EL1.VHHCR_EL2.E2H11.2
FEAT_E2H0v8.0–ID_AA64MMFR4_EL1.E2H0 (signed: 0b0000 means E2H == 0 is still supported)–11.2
FEAT_NVv8.2–ID_AA64MMFR2_EL1.NV ≥ 0b0001HCR_EL2.NV, HCR_EL2.NV111.2
FEAT_NV2v8.3–ID_AA64MMFR2_EL1.NV ≥ 0b0010HCR_EL2.NV2, VNCR_EL211.2
FEAT_SEL2v8.3v8.4 (EL2 and Secure)ID_AA64PFR0_EL1.SEL2SCR_EL3.EEL212.1
FEAT_S2FWBv8.3v8.4 (EL2)ID_AA64MMFR2_EL1.FWBHCR_EL2.FWB11.3
FEAT_FGTv8.5v8.6 (EL2 or EL3)ID_AA64MMFR0_EL1.FGT ≥ 0b0001SCR_EL3.FGTEn11.1
FEAT_FGT2v8.8v8.9 (EL2)ID_AA64MMFR0_EL1.FGT ≥ 0b0010SCR_EL3.FGTEn211.1
FEAT_HCXv8.6v8.7 (EL2)ID_AA64MMFR1_EL1.HCXSCR_EL3.HXEn11.1, 17.3

Security: PAuth, BTI, MTE, GCS, RME

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_PAuthv8.2v8.3ID_AA64ISAR1_EL1.APA/.API or ID_AA64ISAR2_EL1.APA3 ≥ 0b0001SCR_EL3.API, SCR_EL3.APK, HCR_EL2.API, HCR_EL2.APK13.1
FEAT_EPACv8.2–same fields, 0b0010–13.1
FEAT_PAuth2v8.2v8.6same fields ≥ 0b0011–13.1
FEAT_FPACv8.2–same fields ≥ 0b0100– (fault reports EC 0x1C)13.1
FEAT_FPACCOMBINEv8.2–same fields ≥ 0b0101–13.1
FEAT_PAuth_LRv9.4–same fields ≥ 0b0110SCTLR2_ELx.EnPACM13.1
FEAT_PACQARMA3v8.2–ID_AA64ISAR2_EL1.APA3, .GPA3–13.1
FEAT_BTIv8.4v8.5ID_AA64PFR1_EL1.BTSCTLR_EL1.BT0/BT1, SCTLR_EL2/EL3.BT13.1
FEAT_MTEv8.4–ID_AA64PFR1_EL1.MTE = 0b0001 (instructions only)–13.4
FEAT_MTE2v8.4–ID_AA64PFR1_EL1.MTE ≥ 0b0010SCR_EL3.ATA, HCR_EL2.ATA13.4, 13.6
FEAT_MTE3v8.5v8.7 (asynchronous faults)ID_AA64PFR1_EL1.MTE ≥ 0b0011–13.5
FEAT_MTE4v8.7v8.9 (MTE2)ID_AA64PFR1_EL1.MTEX and the ID_AA64PFR2_EL1 MTE fields–13.6
FEAT_MTE_PERMv8.7v8.9 (MTE2)ID_AA64PFR2_EL1.MTEPERM–13.6
FEAT_MTE_TAGGED_FAROPTIONAL (requires MTE4)–ID_AA64PFR2_EL1.MTEFAR–13.5
FEAT_GCSv9.3–ID_AA64PFR1_EL1.GCSSCR_EL3.GCSEn, HCRX_EL2.GCSEn13.2
FEAT_CHKv8.0v9.4– (CHKFEAT is a hint)–13.2
FEAT_THEv8.8–ID_AA64PFR1_EL1.THESCR_EL3.RCWMASKEn13.2
FEAT_CPAv9.4v9.5ID_AA64ISAR3_EL1.CPAsee DDI04871.2
FEAT_RMEv9.1–ID_AA64PFR0_EL1.RME ≥ 0b0001SCR_EL3.NSE, GPCCR_EL3.GPC12.4
FEAT_RME_GPC2v9.4–ID_AA64PFR0_EL1.RME ≥ 0b0010GPCCR_EL312.4
FEAT_RME_GPC3v9.5–ID_AA64PFR0_EL1.RME (higher value, see DDI0487)GPCCR_EL312.4
FEAT_MECv9.2–ID_AA64MMFR3_EL1.MECSCR_EL3.MECEn12.5
FEAT_RNGv8.4–ID_AA64ISAR0_EL1.RNDR–2.3
FEAT_RNG_TRAPv8.4–ID_AA64PFR1_EL1.RNDR_trapSCR_EL3.TRNDR (1 = trap)17.3

Speculation

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_CSV2v8.0v8.5ID_AA64PFR0_EL1.CSV2 ≥ 0b0001–14.4
FEAT_CSV2_2v8.0–ID_AA64PFR0_EL1.CSV2 ≥ 0b0010SCXTNUM_ELx access: SCTLR_ELx.TSCXT, HCR_EL2.EnSCXT, SCR_EL3.EnSCXT14.7
FEAT_CSV2_3v8.0–ID_AA64PFR0_EL1.CSV2 = 0b0011–14.4
FEAT_CSV3v8.0v8.5ID_AA64PFR0_EL1.CSV3–14.6
FEAT_SBv8.0v8.5ID_AA64ISAR1_EL1.SB–14.3
FEAT_SSBSv8.0–ID_AA64PFR1_EL1.SSBS ≥ 0b0001SCTLR_ELx.DSSBS (value of PSTATE.SSBS on entry)14.5
FEAT_SSBS2v8.0–ID_AA64PFR1_EL1.SSBS ≥ 0b0010–14.5
FEAT_SPECRESv8.0v8.5ID_AA64ISAR1_EL1.SPECRES ≥ 0b0001SCTLR_EL1.EnRCTX (EL0 use)14.7
FEAT_SPECRES2v8.0v8.9ID_AA64ISAR1_EL1.SPECRES ≥ 0b0010SCTLR_EL1.EnRCTX14.7
FEAT_CLRBHBv8.0v8.9ID_AA64ISAR2_EL1.CLRBHB–14.4
FEAT_ECBHBv8.0v8.9ID_AA64MMFR1_EL1.ECBHB–14.4
FEAT_E0PDv8.4v8.5ID_AA64MMFR2_EL1.E0PDTCR_EL1.E0PD0/E0PD114.6
FEAT_DITv8.3v8.4ID_AA64PFR0_EL1.DITPSTATE.DIT14.6

SIMD, floating point, SVE and SME

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_FP16v8.2v8.2 (SVE or FHM)ID_AA64PFR0_EL1.FP and .AdvSIMD = 0b0001 (signed fields)CPTR_EL3.TFP, CPACR_EL1.FPEN15.1
FEAT_DotProdv8.1v8.4 (AdvSIMD)ID_AA64ISAR0_EL1.DPas FP15.1
FEAT_FHMv8.1v8.4 (FP16)ID_AA64ISAR0_EL1.FHMas FP15.1
FEAT_BF16v8.2v8.6 (FP)ID_AA64ISAR1_EL1.BF16as FP15.1
FEAT_I8MMv8.1v8.6ID_AA64ISAR1_EL1.I8MMas FP15.1
FEAT_AFPv8.6v8.7 (FP)ID_AA64MMFR1_EL1.AFPFPCR.AH, FIZ, NEP15.1
FEAT_SVEv8.2–ID_AA64PFR0_EL1.SVECPTR_EL3.EZ, CPTR_EL2.ZEN/TZ, CPACR_EL1.ZEN, ZCR_ELx.LEN15.2, 15.3
FEAT_SVE2v9.0– (see v9.0 row above)ID_AA64ZFR0_EL1.SVEver ≥ 0b0001as SVE1.2, 15.2
FEAT_SVE2p1v9.2v9.4 (SVE2)ID_AA64ZFR0_EL1.SVEver ≥ 0b0010as SVE15.2
FEAT_SMEv9.2–ID_AA64PFR1_EL1.SME ≥ 0b0001CPTR_EL3.ESM, SCR_EL3.EnTP2, SMCR_ELx15.2, 15.3
FEAT_SME2v9.2–ID_AA64PFR1_EL1.SME ≥ 0b0010, ID_AA64SMFR0_EL1.SMEver ≥ 0b0001as SME, plus SMCR_ELx.EZT015.2
FEAT_SME_FA64v9.2–ID_AA64SMFR0_EL1.FA64SMCR_ELx.FA6415.3
FEAT_FP8v9.2–ID_AA64FPFR0_EL1 fieldsneeds FEAT_FPMR15.2
FEAT_FPMRv9.2–ID_AA64PFR2_EL1.FPMRSCR_EL3.EnFPM, HCRX_EL2.EnFPM, SCTLR_EL1.EnFPM15.2, 17.3

Debug, PMU, trace and activity monitors

FeaturePermitted fromMandatory fromID fieldControlSection
FEAT_Debugv8p2v8.1v8.2ID_AA64DFR0_EL1.DebugVer ≥ 0b1000–16.1
FEAT_Debugv8p4v8.3v8.4ID_AA64DFR0_EL1.DebugVer ≥ 0b1001–16.2
FEAT_Debugv8p8v8.7v8.8ID_AA64DFR0_EL1.DebugVer ≥ 0b1010–16.1
FEAT_Debugv8p9v8.8v8.9ID_AA64DFR0_EL1.DebugVer ≥ 0b1011MDCR_EL3.EBWE16.1
FEAT_DoubleLockv8.0 (not in any v9 PE)–ID_AA64DFR0_EL1.DoubleLock (signed: 0b0000 = present)OSDLR_EL1.DLK16.1
FEAT_PMUv3v8.0–ID_AA64DFR0_EL1.PMUVer ≥ 0b0001 (0b1111 = IMPLEMENTATION DEFINED PMU)MDCR_EL3.TPM, MDCR_EL2.TPM, MDCR_EL2.HPMN16.3
FEAT_PMUv3p1v8.0v8.1 (PMUv3)PMUVer ≥ 0b0100–16.3
FEAT_PMUv3p4v8.3v8.4 (PMUv3)PMUVer ≥ 0b0101–16.3
FEAT_PMUv3p5v8.4v8.5 (PMUv3)PMUVer ≥ 0b0110MDCR_EL3.SCCD, MDCR_EL2.HCCD16.3
FEAT_PMUv3p7v8.6v8.7 (PMUv3)PMUVer ≥ 0b0111MDCR_EL3.MCCD, MDCR_EL3.MPMX16.3
FEAT_PMUv3p8, FEAT_PMUv3p9v8.7, v8.8v8.8, v8.9 (PMUv3)PMUVer ≥ 0b1000, ≥ 0b1001–16.3
FEAT_PMUv3_THv8.7–PMMIR_EL1.THWIDTH–16.5
FEAT_PMUv3_EDGEv8.8–PMMIR_EL1.EDGE–16.5
FEAT_PMUv3_SSv8.8–ID_AA64DFR0_EL1.PMSS–16.3
FEAT_PMUv3_ICNTRv8.8–ID_AA64DFR1_EL1.PMICNTR–16.3
FEAT_HPMN0v8.5v8.8 (PMUv3 and EL2)ID_AA64DFR0_EL1.HPMN0MDCR_EL2.HPMN16.3
FEAT_MTPMUv8.5–ID_AA64DFR0_EL1.MTPMU (signed)MDCR_EL3.MTPME, MDCR_EL2.MTPME16.3
FEAT_SPMUv8.8–ID_AA64DFR1_EL1.SPMUsee DDI048716.5
FEAT_AMUv1v8.3–ID_AA64PFR0_EL1.AMU ≥ 0b0001CPTR_EL3.TAM, CPTR_EL2.TAM16.4
FEAT_AMUv1p1v8.5–ID_AA64PFR0_EL1.AMU ≥ 0b0010SCR_EL3.AMVOFFEN, HCR_EL2.AMVOFFEN16.4
FEAT_SPEv8.1–ID_AA64DFR0_EL1.PMSVer ≥ 0b0001MDCR_EL3.NSPB, MDCR_EL3.NSPBE, MDCR_EL2.E2PB16.6
FEAT_SPEv1p1 … FEAT_SPEv1p4v8.2, v8.6, v8.7, v8.8v8.5, v8.7, v8.8, v8.9 (SPE)PMSVer ≥ 0b0010 … 0b0101–16.6
FEAT_TRFv8.3v8.4 (ETMv4)ID_AA64DFR0_EL1.TraceFiltMDCR_EL3.TTRF, MDCR_EL2.TTRF16.6
FEAT_ETEv9.0–ID_AA64DFR0_EL1.TraceVer (System register trace interface)CPTR_EL3.TTA, CPTR_EL2.TTA, CPACR_EL1.TTA16.6
FEAT_TRBEv9.0–ID_AA64DFR0_EL1.TraceBuffer ≥ 0b0001MDCR_EL3.NSTB, MDCR_EL3.NSTBE, MDCR_EL2.E2TB16.6
FEAT_BRBEv9.1–ID_AA64DFR0_EL1.BRBE ≥ 0b0001MDCR_EL3.SBRBE16.6
FEAT_BRBEv1p1v9.2v9.3 (BRBE)ID_AA64DFR0_EL1.BRBE ≥ 0b0010–16.6
FEAT_PCSRv8p2v8.1–PMDEVID.PCSample–18.2

A2 also lists dependencies between these features. Examples that matter for configuration checks: FEAT_ETE requires FEAT_TRBE and FEAT_TRF; FEAT_D128 requires FEAT_SYSREG128, FEAT_SYSINSTR128, FEAT_LSE128, FEAT_S1PIE, FEAT_AIE and FEAT_TCR2; FEAT_GCS requires FEAT_CHK and FEAT_S1PIE; FEAT_MEC requires FEAT_RME, FEAT_SCTLR2 and FEAT_TCR2; FEAT_LPA2 requires FEAT_LVA; FEAT_IESB requires FEAT_RAS. A model or RTL configuration that violates one of these is not a legal implementation.

Validation note: Turn the dependency list into a static check over the ID-register dump from every core (1.1): for each implemented feature, assert that every feature it requires is also reported, and that no excluded pair (for example FEAT_SEL2 with FEAT_PCSRv8) is reported together. A violation is a bug in the RTL configuration, the fuse settings or the FVP parameters. It also shows up later as a TF-A FEATURE_DETECTION=1 mismatch or a Linux SANITY CHECK warning, which are harder to trace back to the cause.

Appendix B: Register cheat sheet

This appendix is for looking things up during bring-up and code review. It gives the most used AArch64 control registers with their key fields, the ID register field layouts that 1.1 refers to, and the AArch32-to-AArch64 register mapping that 2.1 refers to. It is not a substitute for the register XML: before writing a new value, read the field’s full description, including its reset value and any RES0/RES1 rules (Reading the Arm ARM).

Bit positions are from the Arm register XML, cross-checked against TF-A’s include/arch/aarch64/arch.h and Linux’s arch/arm64/tools/sysreg. A field shown without a feature is present from v8.0. Fields belonging to a feature are RES0 (or RES1, as the XML says) when the feature is not implemented. Appendix A gives the versions of each feature.

Identification

RegisterFieldsNotes
MIDR_EL1Implementer [31:24], Variant [23:20], Architecture [19:16], PartNum [15:4], Revision [3:0]Architecture reads 0b1111 (“use the ID registers”). Implementer 0x41 is Arm Ltd. rVpR = Variant, Revision (1.3)
MPIDR_EL1Aff3 [39:32], U [30], MT [24], Aff2 [23:16], Aff1 [15:8], Aff0 [7:0]A logical ID. Platform mapping in 17.5
REVIDR_EL1IMPLEMENTATION DEFINEDECO and erratum-fix bits, defined by the core TRM
CTR_EL0DIC [29], IDC [28], CWG [27:24], ERG [23:20], DminLine [19:16], L1Ip [15:14], IminLine [3:0]Line sizes are log2(words). IDC/DIC relax the I-cache maintenance sequence (8.6)
CLIDR_EL1, CCSIDR_EL1, CSSELR_EL1cache hierarchy and geometryFormat changes with FEAT_CCIDX (8.1)
DCZID_EL0DZP [4], BS [3:0]DC ZVA block size and prohibit bit

System control: SCTLR_EL1 (and SCTLR_EL2 with E2H == 1)

SCTLR_EL2 with E2H == 0 and SCTLR_EL3 implement a subset, with several bits RES1. The fields most often involved in bring-up bugs:

BitFieldMeaning (1 =)Section
0MStage 1 MMU on9.3
1AAlignment checking on5.8
2CData and unified caches may allocate (Normal memory cacheable as mapped)9.3
3, 4SA, SA0SP alignment check at ELx / EL03.1
11EOSERET is a context synchronization event (FEAT_ExS; RES1 without it)7.8
12IInstruction caches may allocate8.6
19WXNWritable implies execute-never5.5
21IESBImplicit error synchronization barrier on entry and return (FEAT_IESB)3.4
22EISException entry is a context synchronization event (FEAT_ExS)7.8
23SPAN0 = set PSTATE.PAN on exception entry (FEAT_PAN)5.5
25, 24EE, E0EBig-endian data at ELx / EL0
26UCIEL0 cache maintenance by VA allowed8.5
31, 30, 27, 13EnIA, EnIB, EnDA, EnDBPAuth keys enabled for instruction A/B and data A/B13.1
35, 36BT0, BT1BTI guarding for EL0 / EL1 (FEAT_BTI; BT at EL2/EL3)13.1
37ITFSBTag check faults synchronized on entry (FEAT_MTE2)13.5
39:38, 41:40TCF0, TCFTag check fault mode for EL0 / ELx13.5
42, 43ATA0, ATAAllocation tag access at EL0 / ELx13.4
44DSSBSValue of PSTATE.SSBS on exception entry14.5
57EPANEnhanced PAN: PAN also covers execute-only EL0 pages (FEAT_PAN3)5.5
61, 62NMI, SPINTMASKNon-maskable interrupts (FEAT_NMI)4.3

SCTLR2_ELx (FEAT_SCTLR2) holds the overflow: NMEA [2] and EASE [5] (FEAT_DoubleFault2), EnADERR [3], EnANERR [4], EnPACM [7] and EnPACM0 [8] (FEAT_PAuth_LR), and the CPTA/CPTM checked-pointer controls [12:9] (FEAT_CPA).

Translation control: TCR_EL1

TCR_EL2 with E2H == 0 and TCR_EL3 have a single range and different positions for PS, TBI and HPD. Use the XML for those. 5.2 covers the fields.

BitsFieldBitsField
[5:0]T0SZ[21:16]T1SZ
[7]EPD0[22]A1 (which TTBR holds the ASID)
[9:8]IRGN0[23]EPD1
[11:10]ORGN0[25:24]IRGN1
[13:12]SH0[27:26]ORGN1
[15:14]TG0 (0b00 4K, 0b01 64K, 0b10 16K)[29:28]SH1
[34:32]IPS[31:30]TG1 (0b01 16K, 0b10 4K, 0b11 64K: a different encoding from TG0)
[36]AS (16-bit ASID)[38:37]TBI1, TBI0
[39]HA (hardware Access flag)[40]HD (hardware dirty state)
[42:41]HPD1, HPD0[50:43]HWU bits (FEAT_HPDS2)
[52:51]TBID1, TBID0[54:53]NFD1, NFD0 (SVE non-fault)
[56:55]E0PD1, E0PD0[58:57]TCMA1, TCMA0 (MTE)
[59]DS (FEAT_LPA2)[61:60]MTX1, MTX0 (FEAT_MTE_NO_ADDRESS_TAGS)

TCR2_EL1 (FEAT_TCR2): PnCH [0], PIE [1], E0POE [2], POE [3], AIE [4], D128 [5], PTTWI [10], HAFT [11], DisCH0/DisCH1 [14]/[15], A2 [16], FNG0/FNG1 [17]/[18].

TTBRn_ELx: ASID [63:48], BADDR [47:1], CnP [0]. With FEAT_D128 the register is 128 bits wide and is accessed with MRRS/MSRR (5.7).

MAIR_ELx attribute bytes in common use (6.5): 0x00 Device-nGnRnE, 0x04 Device-nGnRE, 0x08 Device-nGRE, 0x0C Device-GRE, 0x44 Normal Non-cacheable, 0xBB Normal Write-Through, 0xFF Normal Write-Back read/write-allocate, 0xF0 Tagged Normal Write-Back (FEAT_MTE2).

PAR_EL1 after AT (5.9): F [0]. If F == 0: SH [8:7], NS [9], PA from bit 12 upward, ATTR [63:56]. If F == 1: FST [6:1] (a DFSC-style code, Appendix D), PTW [8], S [9] (stage 2).

EL3 controls

SCR_EL3

BitFieldBitField
0NS25EnSCXT (FEAT_CSV2_2)
1IRQ (route to EL3)26ATA (FEAT_MTE2)
2FIQ (route to EL3)27FGTEn (FEAT_FGT)
3EA (route External aborts and SError to EL3)28ECVEn (FEAT_ECV)
5:4RES129TWEDEn (FEAT_TWED), with TWEDEL [33:30]
7SMD (disable SMC)35AMVOFFEN (FEAT_AMUv1p1)
8HCE (enable HVC)36EnAS0 (FEAT_LS64_ACCDATA)
9SIF (Secure instruction fetch from Non-secure memory faults)37ADEn (FEAT_LS64_ACCDATA)
10RW (next lower EL is AArch64)38HXEn (FEAT_HCX)
11ST (Secure EL1 access to CNTPS_*_EL1)39GCSEn (FEAT_GCS)
12TWI40TRNDR (FEAT_RNG_TRAP; 1 = trap)
13TWE41EnTP2 (FEAT_SME)
14TLOR (FEAT_LOR)42RCWMASKEn (FEAT_THE)
15TERR (trap error record accesses, FEAT_RAS)43TCR2En (FEAT_TCR2)
16APK (FEAT_PAuth; 1 = don’t trap key registers)44SCTLR2En (FEAT_SCTLR2)
17API (FEAT_PAuth; 1 = don’t trap PAC instructions)45PIEn (FEAT_S1PIE/S1POE)
18EEL2 (FEAT_SEL2)46AIEn (FEAT_AIE)
19EASE (FEAT_DoubleFault)47D128En (FEAT_D128)
20NMEA (FEAT_DoubleFault)48GPF (route GPFs to EL3, FEAT_RME)
21FIEN (fault injection, FEAT_RASv1p1)49MECEn (FEAT_MEC)
22TID3 (FEAT_IDTE3)50EnFPM (FEAT_FPMR)
23TID5 (FEAT_IDTE3)51TMEA (FEAT_DoubleFault2)
52TWERR (trap error-record writes, FEAT_RASv2)
53PFAREn (FEAT_PFAR)
54SRMASKEn (FEAT_SRMASK)
55EnIDCP128 (IMPLEMENTATION DEFINED 128-bit registers, FEAT_SYSREG128)
57, 58DSE, EnDSE (delegated SError, FEAT_E3DSE)
59FGTEn2 (FEAT_FGT2)
60, 61HDBSSEn, HACDBSEn
62NSE (with NS: Secure, Non-secure, Root, Realm; FEAT_RME)

The Security state encoding with FEAT_RME is {NSE, NS}: 00 Secure, 01 Non-secure, 11 Realm, 10 reserved (Root is EL3 itself) (12.4). 17.3 explains which bits need a per-world value.

CPTR_EL3, MDCR_EL3

RegisterBitFieldMeaning
CPTR_EL38EZ1 = SVE not trapped
10TFP1 = trap FP/SIMD (and SVE/SME)
12ESM1 = SME not trapped
20TTA1 = trap trace System registers
30TAM1 = trap AMU registers
31TCPAC1 = trap EL2/EL1 accesses to CPTR_EL2/CPACR_EL1
MDCR_EL36TPMTrap PMU registers
9, 10TDA, TDOSATrap debug registers, OS-lock and power-down registers
11, 13:12NSPBE, NSPBSPE buffer owner
16SDDDisable Secure self-hosted debug
17SPMEAllow Secure PMU counting
19TTRFTrap trace filter registers
23SCCDProhibit cycle counting in Secure state
25:24, 26NSTB, NSTBETrace buffer owner
28MTPMEMulti-threaded PMU enable
33:32SBRBEBRBE Secure prohibition and ownership
34, 35MCCD, MPMXCycle counting and PMU prohibition at EL3

EL2 controls

HCR_EL2

BitFieldBitField
0VM (stage 2 on)32CD (stage 2 data non-cacheable)
1SWIO33ID (stage 2 instruction non-cacheable)
2PTW34E2H (FEAT_VHE)
3, 4, 5FMO, IMO, AMO (route physical FIQ/IRQ/SError to EL2, enable virtual ones)35TLOR
6, 7, 8VF, VI, VSE (pend virtual FIQ/IRQ/SError)36, 37TERR, TEA
9, 11:10FB, BSU (broadcast and upgrade shareability)40, 41APK, API
12DC (default cacheable)42, 43NV, NV1
13, 14TWI, TWE44AT
15–18TID0–TID345NV2
19TSC (trap SMC)46FWB (FEAT_S2FWB)
20TIDCP47FIEN
21TACR48GPF (FEAT_RME)
22TSW (trap set/way CMOs)49TID4 (FEAT_EVT)
23TPCP (trap CMOs to PoC/PoP)50TICAB
24TPU51AMVOFFEN
25TTLB52TOCU
26TVM (trap EL1 MMU register writes)53EnSCXT
27TGE54, 55TTLBIS, TTLBOS
28TDZ56ATA (FEAT_MTE2)
29HCD57DCT
30TRVM (trap EL1 MMU register reads)58TID5
31RW (EL1 is AArch64)59, 63:60TWEDEn, TWEDEL

HCRX_EL2 (FEAT_HCX)

EnAS0 [0], EnALS [1], EnASR [2] (FEAT_LS64); FnXS [3], FGTnXS [4] (FEAT_XS); SMPME [5]; TALLINT [6], VINMI [7], VFNMI [8] (FEAT_NMI); CMOW [9]; MCE2 [10], MSCEn [11] (FEAT_MOPS); TCR2En [14]; SCTLR2En [15]; PTTWI [16]; D128En [17]; EnSNERR [18]; TMEA [19]; EnSDERR [20]; EnIDCP128 [21]; GCSEn [22]; EnFPM [23]; PACMEn [24]; SRMASKEn [26]. Write it explicitly (usually 0 plus the enables you want) whenever SCR_EL3.HXEn == 1 (17.3).

CPTR_EL2, CPACR_EL1, MDCR_EL2

RegisterFields
CPACR_EL1 (and CPTR_EL2 when E2H == 1)ZEN [17:16], FPEN [21:20], SMEN [25:24] (0b11 = no trap; 0b01 = trap EL0 only), TTA [28], E0POE [29]; in the CPTR_EL2 view also TAM [30], TCPAC [31]
CPTR_EL2 (E2H == 0)TZ [8], TFP [10], TSM [12], TTA [20], TAM [30], TCPAC [31]; 1 = trap
MDCR_EL2HPMN [4:0], TPMCR [5], TPM [6], HPME [7], TDE [8], TDA [9], TDOSA [10], TDRA [11], E2PB [13:12], TPMS [14], HPMD [17], TTRF [19], HCCD [23], E2TB [25:24], HLP [26], TDCC [27], MTPME [28]

Registers covered elsewhere

RegisterWhere
PSTATE, SPSR_ELx2.4, 3.2
ESR_ELx, FAR_ELx, HPFAR_EL2, PFAR_ELxAppendix D, 5.8
VTCR_EL2, VTTBR_EL2, stage 2 descriptors11.3
CNTFRQ_EL0, CNT*_EL0, CNTHCTL_EL2, CNTKCTL_EL14.6, 4.7
ICC_*_EL1, ICC_*_EL3, ICH_*_EL24.1–4.3, 11.4
GPCCR_EL3, GPTBR_EL312.4
PM*, AM*, PMS*, TRB*, BRB*16.3, 16.4, 16.6
ERR* (RAS error records)16.7
Fine-grained traps (HFG*TR_EL2, HDFG*TR_EL2, HAFGRTR_EL2)11.1

ID register field layouts

The 4-bit field at bits [n+3:n] is written here as its bit range. “(s)” marks a signed field (1.1, rule 2). Empty ranges are RES0 in the current XML and may be allocated in later issues, which is why they read as zero today. All these registers are read-only and readable at EL1 and above. EL0 access is trapped, and Linux emulates it with sanitised values.

Processor features

Register[63:60][59:56][55:52][51:48][47:44][43:40][39:36][35:32]
ID_AA64PFR0_EL1CSV3CSV2RMEDITAMUMPAMSEL2SVE
ID_AA64PFR1_EL1PFARDF2MTEXTHEGCSMTE_fracNMICSV2_frac
ID_AA64PFR2_EL1FPMR
Register[31:28][27:24][23:20][19:16][15:12][11:8][7:4][3:0]
ID_AA64PFR0_EL1RASGICAdvSIMD (s)FP (s)EL3EL2EL1EL0
ID_AA64PFR1_EL1RNDR_trapSMEMPAM_fracRAS_fracMTESSBSBT
ID_AA64PFR2_EL1UINJGCIEMTEFARMTESTOREONLYMTEPERM

ID_AA64PFR0_EL1.EL0–EL3: 0b0000 not implemented (EL2/EL3 only), 0b0001 AArch64 only, 0b0010 AArch64 and AArch32 (2.1). GIC: 0b0001 GICv3/v4 CPU interface System registers, 0b0011 GICv4.1. GCIE reports the GICv5 CPU interface (4.1).

Instruction set

Register[63:60][59:56][55:52][51:48][47:44][43:40][39:36][35:32]
ID_AA64ISAR0_EL1RNDRTLBTSFHMDPSM4SM3SHA3
ID_AA64ISAR1_EL1LS64XSI8MMDGHBF16SPECRESSBFRINTTS
ID_AA64ISAR2_EL1ATS1ALUTCSSCRPRFMPCDPHINTPRFMSLCSYSINSTR_128SYSREG_128
Register[31:28][27:24][23:20][19:16][15:12][11:8][7:4][3:0]
ID_AA64ISAR0_EL1RDMAtomicCRC32SHA2SHA1AES
ID_AA64ISAR1_EL1GPIGPALRCPCFCMAJSCVTAPIAPADPB
ID_AA64ISAR2_EL1CLRBHBPAC_fracBCMOPSAPA3GPA3RPRESWFxT
ID_AA64ISAR3_EL1FPRCVTLSUIOCCMOLSFEPACMTLBIWFAMINMAXCPA

ID_AA64ISAR3_EL1 [63:32] is RES0 at the time of writing. ID_AA64ISAR0_EL1.SHA2 distinguishes SHA-256 (0b0001) from SHA-512 (0b0010). AES distinguishes AES (0b0001) from AES plus PMULL (0b0010).

Memory model

Register[63:60][59:56][55:52][51:48][47:44][43:40][39:36][35:32]
ID_AA64MMFR0_EL1ECVFGTExSTGran4_2TGran64_2TGran16_2
ID_AA64MMFR1_EL1ECBHBCMOWTIDCP1nTLBPAAFPHCXETSTWED
ID_AA64MMFR2_EL1E0PDEVTBBMTTLFWBIDSAT
ID_AA64MMFR3_EL1Spec_FPACCADERRSDERRANERRSNERRD128_2D128
ID_AA64MMFR4_EL1MTEFGTSCRXTEVTPSSRMASKTLBIDE3DSEEAESR
Register[31:28][27:24][23:20][19:16][15:12][11:8][7:4][3:0]
ID_AA64MMFR0_EL1TGran4 (s)TGran64 (s)TGran16BigEndEL0SNSMemBigEndASIDBitsPARange
ID_AA64MMFR1_EL1XNXSpecSEIPANLOHPDSVHVMIDBitsHAFDBS
ID_AA64MMFR2_EL1STNVCCIDXVARangeIESBLSMUAOCnP
ID_AA64MMFR3_EL1MECAIES2POES1POES2PIES1PIESCTLRXTCRX
ID_AA64MMFR4_EL1RMEGDIE2H0 (s)NV_fracFGWTE3HACDBSASID2EIESBPoPS

Encodings that are easy to get wrong:

  • PARange: 0b0000 32 bits, 0b0001 36, 0b0010 40, 0b0011 42, 0b0100 44, 0b0101 48, 0b0110 52, 0b0111 56 (5.7).
  • TGran4 and TGran64 are signed: 0b0000 supported, 0b1111 not supported, and TGran4 = 0b0001 adds 52-bit addresses (FEAT_LPA2). TGran16 is unsigned: 0b0000 not supported, 0b0001 supported, 0b0010 with 52-bit. The _2 fields describe stage 2 and use 0b0000 to mean “same as the stage 1 field”, 0b0001 not supported, 0b0010 supported, 0b0011 with 52-bit.
  • ASIDBits: 0b0000 8 bits, 0b0010 16 bits. VMIDBits: 0b0000 8 bits, 0b0010 16 bits.
  • HAFDBS: 0b0001 Access flag only, 0b0010 plus dirty state, 0b0011 plus table Access flag (FEAT_HAFT), 0b0100 plus HDBSS.
  • CCIDX and VARange describe formats and sizes, not “more is better” in the usual sense: CCIDX = 0b0001 means the 64-bit CCSIDR_EL1 format, and VARange = 0b0001 means 52-bit VAs with the 64K granule.

Debug and monitoring

Register[63:60][59:56][55:52][51:48][47:44][43:40][39:36][35:32]
ID_AA64DFR0_EL1HPMN0ExtTrcBuffBRBEMTPMU (s)TraceBufferTraceFiltDoubleLock (s)PMSVer
Register[31:28][27:24][23:20][19:16][15:12][11:8][7:4][3:0]
ID_AA64DFR0_EL1CTX_CMPsSEBEPWRPsPMSSBRPsPMUVerTraceVerDebugVer

ID_AA64DFR1_EL1 has wider fields: SYSPMUID [7:0], BRPs [15:8], WRPs [23:16], CTX_CMPs [31:24] (the 8-bit forms used when the 4-bit fields in DFR0 saturate), SPMU [35:32], PMICNTR [39:36], ABLE [43:40], ITE [47:44], EBEP [51:48], DPFZS [55:52], ABL_CMPs [63:56]. In ID_AA64DFR0_EL1, BRPs, WRPs and CTX_CMPs hold the count minus one; check DDI0487 for the DFR1 encodings.

PMUVer: 0b0001 PMUv3, 0b0100 v3p1, 0b0101 v3p4, 0b0110 v3p5, 0b0111 v3p7, 0b1000 v3p8, 0b1001 v3p9, 0b1111 IMPLEMENTATION DEFINED (not PMUv3). PMSVer: 0b0001 SPE, then 0b0010–0b0110 for SPEv1p1–v1p5. DebugVer: 0b0110 v8.0, 0b0111 v8.1 (with VHE), 0b1000 v8.2, 0b1001 v8.4, 0b1010 v8.8, 0b1011 v8.9.

SVE, SME and FP8

RegisterFields
ID_AA64ZFR0_EL1SVEver [3:0] (0b0000 SVE, 0b0001 SVE2, 0b0010 SVE2p1, 0b0011 SVE2p2), AES [7:4], EltPerm [15:12], BitPerm [19:16], BF16 [23:20], B16B16 [27:24], SHA3 [35:32], SM4 [43:40], I8MM [47:44], F16MM [51:48], F32MM [55:52], F64MM [59:56]
ID_AA64SMFR0_EL1FA64 [63], SMEver [59:56] (0b0000 SME, 0b0001 SME2, 0b0010 SME2p1, 0b0011 SME2p2), I16I64 [55:52], F64F64 [48], I16I32 [47:44], B16B16 [43], F16F16 [42], F8F16 [41], F8F32 [40], I8I32 [39:36], and single-bit fields below for the other data-type combinations
ID_AA64FPFR0_EL1F8CVT [31], F8FMA [30], F8DP4 [29], F8DP2 [28], F8E4M3 [1], F8E5M2 [0] and others

ID_AA64ZFR0_EL1 and ID_AA64SMFR0_EL1 read as zero unless SVE or SME (respectively) is implemented, so a zero SVEver means “SVE” only if ID_AA64PFR0_EL1.SVE != 0 (15.2).

AArch32 register mapping

When EL1 or EL0 can run AArch32 under an AArch64 higher EL, the AArch32 System registers are architecturally mapped onto AArch64 registers: the two names access the same storage, so writing one changes the other. This is what makes an AArch32 guest or process context-switchable from AArch64 code (2.1). In Armv9 only EL0 can be AArch32, so most of the EL1 rows below matter only for Armv8 cores with AArch32 at EL1.

AArch32 registerAArch64 registerNotes
SCTLR (Non-secure)SCTLR_EL1[31:0]
ACTLR, ACTLR2ACTLR_EL1[31:0], ACTLR_EL1[63:32]IMPLEMENTATION DEFINED contents
CPACRCPACR_EL1
TTBR0, TTBR1TTBR0_EL1, TTBR1_EL1
TTBCR, TTBCR2TCR_EL1[31:0], TCR_EL1[63:32]
DACRDACR32_EL2AArch64 EL1 has no domains, so this has its own EL2 register
PRRR/MAIR0, NMRR/MAIR1MAIR_EL1[31:0], MAIR_EL1[63:32]
AMAIR0, AMAIR1AMAIR_EL1[31:0], AMAIR_EL1[63:32]
DFSRESR_EL1
IFSRIFSR32_EL2
DFAR, IFARFAR_EL1[31:0], FAR_EL1[63:32]
PARPAR_EL1
VBAR (Non-secure)VBAR_EL1
CONTEXTIDRCONTEXTIDR_EL1
TPIDRURW, TPIDRURO, TPIDRPRWTPIDR_EL0, TPIDRRO_EL0, TPIDR_EL1the EL0 thread pointers an AArch64 kernel must switch for AArch32 tasks
FPSCRFPCR and FPSRthe AArch32 register combines the two
FPEXCFPEXC32_EL2
SPSR_svc, SPSR_abt, SPSR_und, SPSR_irq, SPSR_fiqSPSR_EL1, SPSR_abt, SPSR_und, SPSR_irq, SPSR_fiqthe last four are AArch64 registers accessible at EL2 and EL3
HSCTLR, HTCR, HTTBR, HMAIR0/1, HVBARSCTLR_EL2, TCR_EL2, TTBR0_EL2, MAIR_EL2, VBAR_EL2only when EL2 itself is AArch32-capable
HCR, HCR2HCR_EL2[31:0], HCR_EL2[63:32]
HSRESR_EL2
HDFAR, HIFAR, HPFARFAR_EL2[31:0], FAR_EL2[63:32], HPFAR_EL2
VTCR, VTTBRVTCR_EL2, VTTBR_EL2
CNTKCTL, CNTP_*, CNTV_*CNTKCTL_EL1, CNTP_*_EL0, CNTV_*_EL0
MIDR, MPIDR, ID_*MIDR_EL1[31:0], MPIDR_EL1[31:0], ID_*_EL1the AArch32 ID_PFR0, ID_ISAR0… are readable from AArch64 as ID_PFR0_EL1, ID_ISAR0_EL1…

The registers of Secure AArch32 EL3 (Monitor mode) and the Secure banked copies of SCTLR, VBAR and so on only exist when EL3 itself is AArch32. That configuration is outside this book’s scope. Check the “Mapping of AArch32 System registers to AArch64” text in DDI0487 for those, and for the rows above if you depend on a specific bit range.

Bring-up note: Two mappings are commonly missed when an AArch64 hypervisor or kernel context-switches an AArch32 guest or task. One is the registers that have their own AArch64 copy at EL2 (DACR32_EL2, IFSR32_EL2, FPEXC32_EL2), which have no AArch64 EL1 equivalent to save “for free”. The other is TPIDRRO_EL0, which an AArch32 task uses as TPIDRURO for its TLS pointer. A missing save shows up as corruption that only affects 32-bit processes, and only after a context switch.

Appendix C: Barrier and maintenance recipes

This appendix is a lookup page. Each recipe gives the minimal sequence, which point (PoU, PoC, PoP, PoPA) and which domain (ISH, OSH, SY) it uses and why, and the section that derives it. The recipes assume AArch64, Normal Inner Shareable Write-Back memory for data shared between PEs, and Device-nGnRE for MMIO, unless they say otherwise. They do not replace the derivations: if your case differs from the stated assumptions, go back to the linked section.

How to read the domain and point choices

Four independent questions decide every recipe. Mixing them up causes most barrier bugs (7.8 separates the memory axes, ordering and completion, from context synchronization).

QuestionToolChoice
In what order must other observers see my accesses?DMB, LDAR/STLR, dependenciesThe access type (LD, ST or full) is what matters (7.5)
Must an access or maintenance operation have finished before something that is not a memory access (a system-register write, SEV, WFI, a TLBI taking effect, a non-coherent master reading DRAM)?DSBThe scope must cover every PE or master that the TLBI or IC broadcast must reach: ISH for PEs, OSH when TLBI ...OS or a master outside the Inner Shareable domain is involved, SY when in doubt (7.6)
Must later instructions run with a new context (system registers, translation, fetched code)?ISB or another context synchronization eventLocal to the PE that executes it (7.8)
Where must data reach for a given observer to see it?DC / IC by VA (or by PA at EL3)PoU for this PE’s or the Inner Shareable domain’s instruction fetch; PoC for any master that does not snoop; PoP/PoDP for persistence; PoPA for a change of physical address space (8.4)

The domain on a DMB: this book follows the position, described in 7.5, that the DMB shareability argument has no functional effect in an other-multi-copy-atomic model. The recipes below still write DMB OSH* for anything involving Device memory or a DMA master and DMB ISH* between PEs. That spelling is correct under both the classical reading and the current one, and it matches what TF-A and Linux emit. Where the choice really matters is on a DSB that completes a TLBI or IC operation, and on whether a cache maintenance operation reaches the right point.

1. Ordering between PEs (coherent memory)

#CaseSequenceDomain and whySee
1.1Message passing: payload, then flagProducer: payload stores; STLR flag. Consumer: LDAR flag; payload loads. Equivalent: DMB ISHST before the flag store and DMB ISHLD after the flag loadISH: both ends are PEs in one Inner Shareable domain7.3, 7.7
1.2Lock releaseSTLR on the lock word, or DMB ISH; STR. Not DMB ISHST: the critical section’s loads must also be ordered before the releaseISH; full barrier because load→store order is needed7.5, 10.4
1.3Consumer-side ordering by dependencyLDR flag/pointer; address dependency into the payload loadNo barrier; a control dependency alone orders only later stores, so add ISB (control+ISB) to order a later load7.4
1.4Store-buffering (Dekker): each side writes its flag and then reads the other’sSTLR then LDAR (RCsc), or STR; DMB ISH; LDR. LDAPR is not enoughFull barrier: store→load order7.3, 7.7
1.5Wake a waiter with an eventProducer: STLR flag; DSB ISH; SEV. Consumer: SEVL; 1: WFE; LDAR; CBZ 1bDSB because SEV is not a memory access; without it, a lost wake-up7.10 §4
1.6Wait without SEVConsumer: LDAXR the flag; WFE. The producer’s store to the monitored granule clears the monitor and generates the eventNo barrier on the producer side beyond release semantics10.4
1.7Send an SGI after writing dataData stores; DSB ISHST; MSR ICC_SGI1R_EL1, x0; ISBDSB: a DMB cannot order a system-register write7.10 §4
1.8Seqlock writerSTR seq (odd); DMB ISHST; data stores; STLR seq (even)The first increment cannot be a release; it needs store→store order after it7.10 §6
1.9Seqlock readerLDAR seq; data loads; DMB ISHLD; LDR seq; compare and retryThe re-read cannot be LDAR: earlier loads must be ordered before it7.10 §6
1.10Mailbox between dies in one coherent domainAs 1.1 or 1.5Same as on one die; only latency changes7.10 §5
1.11Mailbox between agents that are not mutually coherentMap the buffer Normal Non-cacheable on both sides (identical attributes); payload stores; DSB SY; doorbell store. Receiver: doorbell interrupt, or poll then DMB OSHLD; payload loadsDSB SY makes the payload complete regardless of whether the far agent is in this PE’s Outer Shareable domain7.10 §5, 10.4

2. Device memory and DMA

#CaseSequencePoint / domain and whySee
2.1Doorbell after descriptors, coherent masterDescriptor stores (ownership bit last); DMB OSHST; doorbell STR. Or STLR to the doorbellOSH: Device and Normal Non-cacheable memory are always Outer Shareable, and the master may be outside the Inner Shareable domain7.9, 7.10 §1
2.2To-device buffer, non-coherent masterDC CVAC over the buffer (step CTR_EL0.DminLine); DSB SY (or DSB OSH if the master is known to be in the Outer Shareable domain); doorbellPoC, because the master reads DRAM. A DMB would not do: the clean must have completed8.7
2.3From-device buffer, non-coherent masterBefore: DC CIVAC (or DC CVAC) over the buffer; DSB SY; start DMA. After completion: DC IVAC over the buffer; DSB SY; readPoC both times. The post-DMA invalidate is mandatory, because the PE may allocate lines speculatively during the transfer8.7
2.4Buffer edges not aligned to CTR_EL0.CWGAlign and pad DMA buffers to CWG; otherwise use DC CIVAC on the partial edge lines, and never let both sides write an edge line at onceDC IVAC on a shared line destroys the neighbour’s dirty data8.7
2.5Read completions after a status or index readDevice LDR of index; DMB OSHLD; entry loads. Or LDAR for the index readLD orders the earlier load against later loads and stores7.10 §2
2.6Give ring slots back after reading entriesEntry loads; DMB OSHLD; consumer-index STRload→store order is all that is needed7.10 §2
2.7Two writes to one peripheralProgram order, no barrier (Device-nR arrival order)The extent of “one peripheral” is IMPLEMENTATION DEFINED7.9
2.8Configure peripheral A, then act on peripheral BWrite A; read back from A or poll A’s own completion status; DSB SY; write BnR does not span peripherals; a DSB on an E mapping only says that a buffer accepted the write7.9
2.9Clear an interrupt source, then EOISTR to the device’s clear register; LDR read-back from the same device; DSB SY; MSR ICC_EOIR1_EL1DSB before a system-register write; the read-back proves arrival even on nGnRE7.9
2.10SMMU tables and queues when SMMU_IDR0.COHACC == 0 (or Non-cacheable attributes in SMMU_CR1)Write STE/CD/page tables/commands; DC CVAC to the PoC; DSB SY; CMD_CFGI_* or SMMU_CMDQ_PROD updatePoC: the SMMU does not snoop8.7, 11.5
2.11Persistent memory recordRecord stores; DC CVAP (or DC CVADP); DSB; then publish “durable”PoP / PoDP; on a system without them the operations fall back to PoC / PoP8.5

3. Instruction-side maintenance

#CaseSequencePoint / domain and whySee
3.1New code, executed by this PESTR; DC CVAU; DSB ISH; IC IVAU; DSB ISH; ISBPoU, where instruction fetch meets the data side. The first DSB orders the invalidate after the clean8.6
3.2Same, rangeLoop DC CVAU by CTR_EL0.DminLine; DSB ISH; loop IC IVAU by CTR_EL0.IminLine; DSB ISH; ISBRead line sizes from CTR_EL0; use the system-wide minimum on heterogeneous systems8.6
3.3CTR_EL0.IDC == 1Omit DC CVAU; keep DSB ISH before IC IVAUThe store must still be visible before the invalidate8.6
3.4CTR_EL0.IDC == 1 and DIC == 1STR; DSB ISH; ISBDSB and ISB are never optional. Check the core’s errata before trusting DIC8.6
3.5New code, executed by other PEsModifier: 3.1 without the ISB, then publish a flag. Each executor: observe the flag; ISB (or take an exception, or IPI); branchThe IC IVAU broadcast covers the Inner Shareable domain; the ISB is per PE8.6
3.6Patch code that may be executing (CMODX)Only between instructions in the CMODX set (B, BL, NOP, BRK, SVC, HVC, SMC, ISB), with one aligned 32-bit store; then 3.5 before relying on the new instructionAnything else is CONSTRAINED UNPREDICTABLE8.6
3.7Loader: image written by this PE with caches on, next stage runs with caches onClean the image to PoU (DC CVAU); DSB ISH; IC IALLU (or IC IVAU over the range); DSB ISH; ISB or ERET into itPoU8.6
3.8Loader: next stage starts with caches off, or on another masterDC CVAC (or DC CIVAC) over the image to the PoC; DSB SY; IC IALLU; DSB; ISB/ERETThe next reader bypasses the caches8.6, 6.6
3.9Image written by DMA or by a debugger into memory this PE has cachedDC IVAC over the image to the PoC (drop stale data lines); DSB; IC IALLU; DSB; ISBThe writer bypassed the PE’s D-cache, but stale lines may still be there on both sides6.6, 8.6

4. System registers and context

#CaseSequenceSee
4.1System-register write that changes how later instructions execute (SCTLR_ELx, TCR_ELx, TTBRn_ELx, MAIR_ELx, CPACR_EL1/CPTR_ELx, ZCR_ELx, SMCR_ELx, VBAR_ELx, MDSCR_EL1, PMCR_EL0)MSR; ISB before the first instruction that depends on it7.8
4.2Registers that configure the lower EL, at the end of an EL3 or EL2 exit pathMSR…; ERET (the exception return is the CSE, unless SCTLR_ELx.EOS == 0 under FEAT_ExS)7.8
4.3ICC_SRE_ELxTop down, EL3 then EL2 then EL1; MSR; ISB after each; read back SRE4.5
4.4Counter read after an earlier load or branchISB; MRS CNTVCT_EL0 (or a self-synchronized CNTVCTSS_EL0 with FEAT_ECV)4.7
4.5Counter read after an earlier store has completedDSB SY; ISB; MRS4.7
4.6Counter read before a later loadMRS; artificial address dependency into the load (EOR, ADD sp, dummy LDR), or ISB4.7
4.7PSTATE fields written with MSR (immediate) (PAN, UAO, SSBS, DIT, TCO)No ISB needed for later instructions; check the register’s own text7.8
4.8Unmask interrupts and bound when a pending one is takenMSR DAIFClr, #...; ISB7.8

5. Translation tables and TLBs

#CaseSequenceDomain and whySee
5.1Invalid → validSTR descriptor; DSB ISHST; ISBNo TLBI: faulting translations are never cached. With FEAT_ETS2, the ISB is not needed for later data accesses; keep it for code9.1
5.2Valid → invalid, or a permission-only changeSTR; DSB ISHST; TLBI VAE1IS, x0 (or VALE1IS for a leaf); DSB ISH; ISBISH for the broadcast and its completion; OS forms with DSB OSH when the sharing PEs are only Outer Shareable9.1
5.3Change of OA, memory type, shareability or block size on a live entryBreak-before-make: STR xzr; DSB ISHST; non-leaf TLBI over the whole old range; DSB ISH; STR new; DSB ISHST; ISBAny other order allows two valid translations at once9.2
5.4Block → table split with ID_AA64MMFR2_EL1.BBM ≥ 2, equivalent mappingBuild the table; DSB ISHST; write the table descriptor over the block; DSB ISHST; TLBI the block range; DSB ISH; ISBThe TLBI is still required9.2
5.5Free a translation-table pageOnly after the non-leaf TLBI that removes walk-cache references to it, and its DSB, have completedOtherwise a hardware use-after-free9.2
5.6Stage 2 change (at EL2, current VMID loaded)STR; DSB ISHST; TLBI IPAS2E1IS, x0; DSB ISH; TLBI VMALLE1IS; DSB ISH; ISBThe middle DSB stops a fresh combined entry being built from the old stage 2 entry9.1, 11.3
5.7Translation walks that are Non-cacheable (TCR_ELx.IRGNn/ORGNn)Add DC CVAC on the descriptor before the DSB of 5.1–5.3PoC: the walker reads memory9.1
5.8Local-only flush (this PE, e.g. before enabling the MMU)TLBI ALLE3 (or ALLE2, VMALLE1); DSB NSH or DSB ISH; ISBA local TLBI completes with any scope9.3
5.9TLB conflict abort handler (DFSC 0b110000)Local TLBI VMALLE1 (or by the faulting VA); DSB NSH; ISB; ERETRemoves the duplicate entries on this PE only9.2
5.10Shootdown that must not wait for slow (XS=1) accessesTLBI ...nXS; DSB ...nXSA correctness claim: nothing afterwards may depend on XS=1 accesses through the old mapping having completed9.1
5.11Change of a granule’s physical address space (RME, at EL3)DC CIPAPA per line; DSB OSH; GPT write; DSB OSHST; TLBI RPALOS; DSB OSH; DC CIPAPA (NS alias); DSB OSH. The full delegate and undelegate orders are in 12.4PoPA; OSH because PEs and SMMUs cache GPT information12.4

6. MMU, caches and power transitions

#CaseSequenceSee
6.1MMU on at EL3TLBI ALLE3; MSR MAIR_EL3, TCR_EL3, TTBR0_EL3 (any order); DSB ISH; ISB; set SCTLR_EL3.{M,C} (I usually earlier); ISB. The enabling code, stack and vectors must be identity-mapped9.3
6.2Tables or data written with the MMU or D-cache off, read later with caches onDC IVAC the region to the PoC before writing it (no stale dirty line can be evicted over it) and again after (drop lines allocated in between). Not a clean9.3, 6.6
6.3MMU and caches off before handing to a caches-off stageClear SCTLR_ELx.{M,C} together; ISB; DC CIVAC to the PoC over the data the next stage reads; DSB SY. Code must be identity-mapped9.3
6.4Core power-down, pre-DynamIQ (Cortex-A53/A57/A72 class)Clear SCTLR_EL3.C; ISB; set/way clean+invalidate L1 (DC CISW, levels from CLIDR_EL1); last core: also L2; clear CPUECTLR_EL1.SMPEN; ISB; DSB SY; program power controller; WFI8.8
6.5Core power-down, DynamIQSet CPUPWRCTLR_EL1.CORE_PWRDN_EN; ISB; program power controller; DSB SY; WFI. Hardware flushes and leaves coherency8.8
6.6Data the warm-boot path reads before caches are onDC CIVAC (TF-A flush_dcache_range) to the PoC after every update; DSB8.8, 17.4
6.7IdleDSB SY; WFI7.6, 7.10 §3
6.8System reset through an SoC registerClean to the PoC anything that must survive; DSB SY; reset STR; DSB SY; WFI loop7.10 §3
6.9Warm reset through RMR_EL3.RRDSB SY; ISB; MSR RMR_EL3; ISB; WFI loop (IMPLEMENTATION DEFINED whether RR acts)17.1
6.10Release a secondary from a caches-off hold penWrite the per-core mailbox; DC CVAC it to the PoC (or map it Non-cacheable); DSB SY; SEV17.4

Bring-up note: Set/way operations (DC ISW, CSW, CISW) appear in this appendix only in 6.4. They are local and not atomic with respect to allocation, so they are never a way to make an address visible to anyone (8.5).

7. Linux barrier API on arm64

Linux is a reference mapping here. The lowering is from arch/arm64/include/asm/barrier.h, io.h, tlbflush.h and cacheflush.h in recent kernels. Check your tree, because these definitions have changed over time (for example dma_mb() is a relatively recent addition).

Linux APIarm64 loweringMeaningBare-metal / TF-A equivalent
mb()DSB SYFull completion barrier, including for MMIO and DMAdsb sy (dsb() / dsbsy())
rmb()DSB LDEarlier loads completedsb ld
wmb()DSB STEarlier stores completedsb st
dma_mb()DMB OSHFull ordering for coherent DMA memorydmb osh
dma_rmb()DMB OSHLDOrder reads of a coherent DMA buffer (status, then data)dmb oshld
dma_wmb()DMB OSHSTOrder writes to a coherent DMA buffer (data, then ownership flag)dmb oshst (dmboshst())
smp_mb()DMB ISHFull ordering between CPUsdmb ish (dmbish())
smp_rmb()DMB ISHLDLoad→load and load→store between CPUsdmb ishld
smp_wmb()DMB ISHSTStore→store between CPUsdmb ishst
smp_load_acquire()LDARAcquire (RCsc)ldar
smp_store_release()STLRReleasestlr
smp_cond_load_acquire()Loop: smp_load_acquire() (LDAR) re-read; while the condition fails, __cmpwait (SEVL; WFE; LDXR; compare; WFE)Wait for a value with acquire1.6 above
readl()LDR; DMB OSHLD; dummy control dependency (EOR; CBNZ) on the loaded valueMMIO read ordered before later loads, and before a following udelay()mmio_read_32() + dmb oshld
writel()DMB OSHST; STREarlier memory writes (DMA buffers) ordered before the MMIO writedmb oshst + mmio_write_32()
readl_relaxed() / writel_relaxed()LDR / STR onlyDevice-nR order to the same peripheral, nothing elseTF-A mmio_read_32() / mmio_write_32()
ioremap() / ioremap_np()Device-nGnRE / Device-nGnRnEMapping type for MMIO / non-posted MMIOTF-A MT_DEVICE (nGnRE)
io_stop_wc()DGH (FEAT_DGH; a NOP where not implemented)Stop write-combining of earlier Normal-NC stores with later onesdgh
__arch_counter_get_cntvct()ISB; MRS CNTVCT_EL0 (or MRS CNTVCTSS_EL0 with FEAT_ECV); dummy address-dependent loadCounter read ordered after earlier and before later instructions4.4 and 4.6 above
flush_icache_range()DC CVAU loop (skipped if IDC); DSB ISH; IC IVAU loop (skipped if DIC); DSB ISH; ISB; then an IPI to all CPUs (kick_all_cpus_sync())3.2 + 3.53.2 above
dcache_clean_poc()DC CVAC loop; DSB SYClean to the PoCTF-A clean_dcache_range()
dcache_inval_poc()DC CIVAC on partial edge lines, DC IVAC on whole lines; DSB SYInvalidate to the PoCTF-A inv_dcache_range() (no edge handling: align your buffers)
dcache_clean_inval_poc()DC CIVAC loop; DSB SYClean and invalidate to the PoCTF-A flush_dcache_range()
arch_sync_dma_for_device()dcache_clean_poc()Before a non-coherent master reads or writes2.2, first half of 2.3
arch_sync_dma_for_cpu()dcache_inval_poc() for DMA_FROM_DEVICE and DMA_BIDIRECTIONALAfter a non-coherent master wrotesecond half of 2.3
flush_tlb_all()DSB ISHST; TLBI VMALLE1IS; DSB ISH; ISBAll EL1&0 entries, all CPUs5.2
local_flush_tlb_all()DSB NSHST; TLBI VMALLE1; DSB NSH; ISBThis CPU only5.8
flush_tlb_mm()DSB ISHST; TLBI ASIDE1IS; DSB ISHOne ASID, all CPUs5.2
flush_tlb_page()DSB ISHST; TLBI VALE1IS; DSB ISHOne leaf entry, all CPUs5.2

Three notes on the table:

  • mb(), rmb() and wmb() are DSBs, not DMBs, because Linux defines them to order against DMA and MMIO in every case, including non-coherent ones. In firmware, the DMB forms are usually what you want, with an explicit DSB where a recipe above asks for completion.
  • The Linux smp_* barriers carry no DSB, so they never complete cache or TLB maintenance. The TLB flush helpers carry their own DSBs.
  • C11 stdatomic.h lowers everything to the ISH forms (7.7). It is not the right tool for DMA, MMIO or non-coherent agents.

Appendix D: ESR and fault-status decode card

This card is for decoding ESR_ELx with a crash dump open. 3.2 explains when ESR, ELR and FAR are written and valid. 5.8 explains the abort fields and the fault-address registers. 18.1 works through five complete dumps using this card. Values were checked against the ESR_EL1/ESR_EL2 register XML. When a class here says “see DDI0487”, its ISS has more structure than a card can hold.

Layout and decode order

 63      56 55          32 31    26 25  24                     0
+----------+--------------+--------+---+------------------------+
|   RES0   |     ISS2     |   EC   |IL |          ISS           |
+----------+--------------+--------+---+------------------------+
  1. Which ESR. The exception went to the EL whose ESR_ELx you are reading. “Lower EL” and “same EL” in the class names are relative to that EL.
  2. EC = ESR[31:26], then pick the ISS layout below.
  3. IL = ESR[25] is 1 for every A64 instruction and for exceptions not tied to an instruction length (SError, Instruction Aborts, alignment faults, most debug exceptions). It is 0 only when the trapped or faulting instruction is a 16-bit T32 instruction.
  4. ISS = ESR[24:0], then ISS2 = ESR[55:32], which only some classes use.
  5. The address registers, only where the class says they are valid: FAR_ELx (VA), HPFAR_EL2 (IPA), PFAR_ELx (PA, FEAT_PFAR) (5.8).

A quick way to read a 32-bit value: ESR >> 26 is the EC, and with IL = 1 the top byte of the value is (EC << 2) | 0b10. So 0x96… is EC 0x25, 0x92… is 0x24, 0x86… is 0x21, 0x62… is 0x18 and 0xBE… is 0x2F.

Exception classes

“Taken to” lists the ELs at which an exception of this class can be reported. AArch32-only classes are listed for completeness at the end.

ECESR (IL = 1, ISS = 0)ClassTaken toISSSection
0x000x02000000Unknown reason: UNDEFINED instruction, or an access that is UNDEFINED at this ELEL1, EL2, EL3RES02.3, 17.3
0x010x06000000 + ISSTrapped WFI, WFE, WFIT, WFETEL1, EL2, EL3below10.4, 11.1
0x070x1E000000Access to SME, SVE, Advanced SIMD or FP trapped by CPACR_EL1, CPTR_EL2 or CPTR_EL3EL1, EL2, EL3CV/COND for AArch32; otherwise no detail15.3
0x090x26000000PAuth instruction trapped by HCR_EL2.API or SCR_EL3.APIEL2, EL3RES013.1
0x0A0x2A000000 + ISSLD64B/ST64B* trapped (FEAT_LS64)EL1, EL2, EL30x0 ST64BV, 0x1 ST64BV0, 0x2 LD64B/ST64B; recent issues add 0x3/0x4 for trapped TSB CSYNC/PSB CSYNC10.3
0x0D0x36000000 + BTYPEBranch Target exception (FEAT_BTI)EL1, EL2, EL3BTYPE [1:0]13.1
0x0E0x3A000000Illegal Execution state (PSTATE.IL was set by an illegal exception return)EL1, EL2, EL3RES03.2
0x140x52000000 + ISSTrapped MRRS, MSRR, SYSP (FEAT_SYSREG128, FEAT_SYSINSTR128)EL1, EL2, EL3like 0x18, with a second register; see DDI04872.5, 5.7
0x150x56000000 + immSVC from AArch64EL1, EL2, EL3imm16 [15:0]3.1
0x160x5A000000 + immHVC from AArch64EL2, EL3imm16 [15:0]11.1
0x170x5E000000 + immSMC from AArch64, at EL3, or trapped to EL2 by HCR_EL2.TSCEL2, EL3imm16 [15:0]12.3
0x180x62000000 + ISSTrapped MSR, MRS or System instructionEL1, EL2, EL3below2.5, 17.3
0x190x66000000SVE access trapped by CPACR_EL1.ZEN, CPTR_EL2.ZEN/TZ or CPTR_EL3.EZEL1, EL2, EL3RES015.3
0x1A0x6A000000 + ISSTrapped ERET, ERETAA, ERETAB (FEAT_NV, or FEAT_PAuth with HCR_EL2.API == 0)EL2ERET vs ERETAx, and key; see DDI048711.2
0x1B–TSTART access (FEAT_TME)EL1, EL2, EL3see DDI0487–
0x1C0x72000000 + keyPAC authentication failure (FEAT_FPAC)EL1, EL2, EL3[1]: 0 instruction key, 1 data key; [0]: 0 A key, 1 B key13.1, 18.1
0x1D0x76000000 + SMTCSME trap or illegal SME useEL1, EL2, EL3SMTC [2:0], below15.3
0x1E0x7A000000 + ISSGranule Protection Check exception (FEAT_RME)EL3GPC fault status, level, S2PTW, InD, WnR; see DDI048712.4
0x1F–IMPLEMENTATION DEFINEDEL3IMPLEMENTATION DEFINEDcore TRM
0x200x82000000 + IFSCInstruction Abort from a lower ELEL1, EL2, EL3below5.8
0x210x86000000 + IFSCInstruction Abort, same ELEL1, EL2, EL3below5.8
0x220x8A000000PC alignment faultEL1, EL2, EL3RES0 (FAR holds the PC)3.2
0x240x92000000 + ISSData Abort from a lower ELEL1, EL2, EL3below5.8
0x250x96000000 + ISSData Abort, same ELEL1, EL2, EL3below5.8
0x260x9A000000SP alignment faultEL1, EL2, EL3RES03.1
0x270x9E000000 + ISSMemory Operation exception (FEAT_MOPS)EL1, EL2, EL3MemInst [24], isSETG [23], Options [22:19], FromEpilogue [18], WrongOption [17], OptionA [16], destreg [14:10], srcreg [9:5], sizereg [4:0]2.3
0x2C0xB2000000 + ISSTrapped floating-point exception (AArch64), with FPCR trap enables setEL1, EL2, EL3exception flags; see DDI048715.1
0x2D0xB6000000 + ISSGCS exception (FEAT_GCS)EL1, EL2, EL3ExType [23:20], below13.2
0x2F0xBE000000 + ISSSErrorEL1, EL2, EL3below3.4, 16.8
0x30, 0x310xC2000022, 0xC6000022Breakpoint, lower / same ELEL1, EL2IFSC 0x2216.1
0x32, 0x330xCA000022, 0xCE000022Software Step, lower / same ELEL1, EL2ISV [24], EX [6], IFSC 0x2216.1
0x34, 0x350xD2000022, 0xD6000022Watchpoint, lower / same ELEL1, EL2below16.1
0x3C0xF2000000 + immBRK (AArch64)EL1, EL2, EL3Comment [15:0]16.1
0x3D0xF6000000PMU exception (FEAT_EBEP)EL1, EL2, EL3SYNC [0] (FEAT_SEBEP: 1 = taken synchronously because PSTATE.PPEND was set); rest RES02.4

AArch32 classes, seen only when a lower EL runs AArch32: 0x03/0x04 (MCR/MRC, MCRR/MRRC to CP15), 0x05/0x06/0x0C (CP14 accesses, LDC/STC), 0x08 (VMRS trapped by HCR_EL2.TID0/TID3, to EL2), 0x11/0x12/0x13 (SVC/HVC/SMC), 0x28 (trapped FP exception), 0x38 (BKPT) and 0x3A (Vector Catch, to EL2). Their ISS carries CV [24] and COND [23:20] for conditional instructions. All other EC values are reserved, and an unexpected one usually means the value being decoded is not an ESR (for example a corrupted save area).

ISS layouts by class

0x18: trapped MSR, MRS, System instruction

ISS bits[21:20][19:17][16:14][13:10][9:5][4:1][0]
FieldOp0Op2Op1CRnRtCRmDirection: 1 = read (MRS), 0 = write

The fields are not in instruction order (2.5). Rebuild the name as S<Op0>_<Op1>_C<CRn>_C<CRm>_<Op2> and look it up. Op0 = 1 is a System instruction (DC, IC, TLBI, AT), and Op0 = 3 is a System register. Worked example: ISS 0x360820 is Op0 3, Op2 3, Op1 0, CRn 2, Rt 1, CRm 0, a write: MSR TCR2_EL1, X1 (18.1). Bits [24:22] are RES0.

0x01: trapped WFx

TI [1:0]: 0b00 WFI, 0b01 WFE, 0b10 WFIT, 0b11 WFET. RV [2] = 1 when RN [9:5] holds the timeout register (FEAT_WFxT). From AArch64, CV [24] = 1 and COND [23:20] = 0b1110, so a trapped AArch64 WFI reads 0x07E00000 and a trapped WFE reads 0x07E00001.

0x1D: SME

SMTC [2:0]: 0b000 access trapped by CPACR_EL1.SMEN, CPTR_EL2.SMEN/TSM or CPTR_EL3.ESM; 0b001 Advanced SIMD, SVE or SVE2 instruction illegal because PSTATE.SM == 1; 0b010 SME instruction illegal because PSTATE.SM == 0; 0b011 instruction illegal because PSTATE.ZA == 0; 0b100 ZT0 access trapped by SMCR_ELx.EZT0 (FEAT_SME2).

0x2D: GCS

ExType [23:20]: 0b0000 GCS data check (a return address did not match the GCS), 0b0001 EXLOCK exception, 0b0010 trapped GCSSTR/GCSSTTR. For a data check, IT [4:0] gives the instruction type (0b00000 RET without PAC, 0b00010/0b00011 RETAA/RETAB, 0b00001 GCSPOPM, and others) and Rn [9:5] the register (13.2).

0x20, 0x21: Instruction Abort

BitsFieldMeaning
[12:11]SETWith FEAT_RAS, error state of a synchronous External abort
[10]FnVFAR not valid
[9]EAIMPLEMENTATION DEFINED External abort classification
[7]S1PTWStage 2 fault on a stage 1 table walk
[5:0]IFSCFault status, table below

0x24, 0x25: Data Abort

BitsFieldMeaning
[24]ISV[23:14] hold a valid instruction syndrome
[23:22]SASAccess size: byte, halfword, word, doubleword
[21]SSEThe load sign-extends
[20:16]SRTTransfer register
[15]SF64-bit register
[14]ARAcquire/release semantics
[13]VNCRFault on a VNCR_EL2-redirected access (FEAT_NV2)
[12:11]SET (or LST for LS64 faults)Error state of a synchronous External abort (FEAT_RAS)
[10]FnVFAR not valid
[9]EAIMPLEMENTATION DEFINED External abort classification
[8]CMCache maintenance or AT instruction
[7]S1PTWStage 2 fault on a stage 1 table walk
[6]WnR1 = write. For a cache maintenance fault (CM = 1) it is 1
[5:0]DFSCFault status, table below

ISV = 1 is mainly a stage 2 feature: a hypervisor gets a decoded syndrome for a single-register load or store without writeback, so it can emulate the MMIO access without fetching the instruction. It is 0 for faults on stage 1 walks, External aborts with FEAT_RAS, MOPS instructions and Allocation Tag accesses, and the LS64 instructions are a special case. Do not rely on ISV in an EL1 or EL3 handler.

ISS2 [55:32] for Data Aborts: Xs [4:0] (status register of ST64BV/ST64BV0), DirtyBit [5] (FEAT_S1PIE), Overlay [6] (a permission-overlay fault, FEAT_S1POE), AssuredOnly [7] (FEAT_THE), GCS [8] (the access was a GCS access), TagAccess [9] (FEAT_MTE_PERM), TnD [10] (tag, not data), HDBSSF [11] (FEAT_HDBSS). A Permission fault is ambiguous until you have read ISS2: the same DFSC 0x0F can be an ordinary AP/XN failure, an overlay failure or a GCS-page failure (5.5, 13.2).

0x34, 0x35: Watchpoint

WPT [23:18] and WPTV [17] give the watchpoint number (FEAT_Debugv8p2), WPF [16] and FnP [15] qualify the address, FnV [10], CM [8], WnR [6], and DFSC [5:0] = 0x22 (Debug exception). FAR holds an address that the access touched, which is not necessarily the watched address. ISS2 GCS [8] (FEAT_GCS) marks a watchpoint hit by a GCS data access.

0x2F: SError

BitsFieldMeaning
[24]IDS1 = bits [23:0] are IMPLEMENTATION DEFINED (read the core TRM). 0 = the architected fields below
[13]IESBSynchronized by an implicit error synchronization event and taken immediately (FEAT_IESB)
[12:10]AET0b000 Uncontainable (UC), 0b001 Unrecoverable (UEU), 0b010 Restartable (UEO), 0b011 Recoverable (UER), 0b110 Corrected (CE)
[9]EAIMPLEMENTATION DEFINED classification
[5:0]DFSC0x00 uncategorized, 0x11 asynchronous SError. Other values reserved

FEAT_RASv2 and FEAT_PFAR add, when DFSC == 0x11: ELS [18], WU [17:16], VFV [15] (FAR valid), PFV [14] (PFAR valid), WnRV [7] and WnR [6].

AET, EA and IESB are only valid when DFSC == 0x11, and all of them require FEAT_RAS. So 0xBE000011 means “an architected, uncategorized-by-source, Uncontainable asynchronous SError”. The PE has said all it can, and the error records hold the rest (3.4, 16.7, 18.3).

DFSC and IFSC values

The same 6-bit encoding is used by DFSC, IFSC, PAR_EL1.FST and several other fault-status fields. “Data only” marks values that cannot appear in an IFSC.

ValueFaultLevel or noteRequires
0x00–0x03Address size faultlevel 0 (or the TTBR itself) to level 3–
0x04–0x07Translation faultlevel 0–3–
0x08Access flag faultlevel 0FEAT_LPA2
0x09–0x0BAccess flag faultlevel 1–3–
0x0CPermission faultlevel 0FEAT_LPA2
0x0D–0x0FPermission faultlevel 1–3–
0x10Synchronous External abort, not on a translation table walk or hardware update––
0x11Synchronous Tag Check Fault (data only). In an SError ISS, 0x11 instead means “asynchronous SError”–FEAT_MTE2
0x12Synchronous External abort on a walk or hardware updatelevel −2FEAT_D128
0x13Synchronous External abort on a walk or hardware updatelevel −1FEAT_LPA2
0x14–0x17Synchronous External abort on a walk or hardware updatelevel 0–3–
0x18Synchronous parity or ECC error on the access, not on a walk–only without FEAT_RAS
0x1BSynchronous parity or ECC error on a walklevel −1FEAT_LPA2, only without FEAT_RAS
0x1C–0x1FSynchronous parity or ECC error on a walklevel 0–3only without FEAT_RAS
0x21Alignment fault (data only; a misaligned PC is EC 0x22)––
0x22Data Abort: Granule Protection Fault on a walk, level −2. Debug classes: Debug exceptioncontext-dependentFEAT_D128 and FEAT_RME
0x23Granule Protection Fault on a walk or hardware updatelevel −1FEAT_RME, FEAT_LPA2
0x24–0x27Granule Protection Fault on a walk or hardware updatelevel 0–3FEAT_RME
0x28Granule Protection Fault, not on a walk–FEAT_RME
0x29Address size faultlevel −1FEAT_LPA2
0x2ATranslation faultlevel −2FEAT_D128
0x2BTranslation faultlevel −1FEAT_LPA2
0x2CAddress size faultlevel −2FEAT_D128
0x30TLB conflict abort––
0x31Unsupported atomic hardware update fault (data only)–FEAT_HAFDBS
0x34IMPLEMENTATION DEFINED fault (Lockdown)––
0x35IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access, data only)––

All other values are reserved. A walk-level fault reports the level of the descriptor that caused it: a level 0 Translation fault means the walk stopped at level 0 (or the VA was outside the TxSZ range), not that the leaf is at level 0.

Bring-up note: Software that decodes the level as DFSC & 0x3 gets levels −1 and −2 wrong, because those encodings (0x29–0x2C, 0x12, 0x13, 0x1B, 0x22, 0x23) are not in the 4-value groups. Decode by table, as Linux’s ESR_ELx_FSC_* helpers do, if the platform can have FEAT_LPA2 or FEAT_D128 enabled.

Fault signatures

The first suspect for each common syndrome during bring-up, with the section that explains the diagnosis. The ESR values assume IL = 1.

SyndromeTypical contextFirst suspectSection
EC 0x00 (0x02000000) at EL1 on an MRS/MSR that the core should supportLinux early boot, cpufeature probeEL3 left the feature’s enable bit at 0, and a recent TF-A injected the trap back as an UNDEF. Older TF-A shows the next row instead17.3
EC 0x18 in ESR_EL3, ISS names a system registerEL3 panic during kernel bootMissing SCR_EL3/CPTR_EL3/MDCR_EL3 enable for that register’s feature17.3, 18.1
EC 0x18 in ESR_EL2Guest boot under a hypervisorHCR_EL2/HCRX_EL2/fine-grained trap, or HCRX_EL2 behaving as 0 because SCR_EL3.HXEn == 011.1, 18.1
EC 0x07 (0x1E000000) on the first FP/SIMD instructionmemcpy, printf or compiler-vectorised code in firmwareCPTR_EL3.TFP == 1 or CPACR_EL1.FPEN not enabled; or firmware built without -mgeneral-regs-only15.3
EC 0x19 or 0x1DFirst SVE/SME use by the OS or the Secure worldCPTR_EL3.EZ/ESM, ZCR_EL3/SMCR_EL3, per-world CPTR_EL315.3, 17.3
EC 0x21, IFSC 0x04–0x07, FAR = the instruction after the MMU-enable MSRFirst instruction after SCTLR_ELx.M = 1Enabling code not identity-mapped, or wrong TTBR0/T0SZ5.8, 9.3, 18.3
EC 0x25, DFSC 0x04–0x07First data access after MMU-onTTBR0/TTBR1 range, EPDn, or page tables not cleaned to the PoC while caches were off5.8, 9.3
EC 0x25, DFSC 0x00–0x03SameTCR_ELx.PS/IPS smaller than the table or output address5.8
EC 0x25, DFSC 0x09–0x0BHand-built tablesDescriptor AF (bit 10) clear, hardware AF not enabled5.6
EC 0x25, DFSC 0x0D–0x0FWrite to a page that should be writableAP bits, PAN, WXN, or (read ISS2) an overlay or GCS-page fault5.5
EC 0x25, DFSC 0x21 (0x96000021/0x96000061)Early C with MMU offData accesses are Device-nGnRnE with the MMU off; unaligned access from compiler code5.8, 18.1
EC 0x25, DFSC 0x10MMIO accessUnclocked, powered-down or unmapped peripheral; interconnect or firewall error response3.4, 16.7
DFSC 0x14–0x17Any walkPage tables in DRAM that is not trained yet, or behind a firewall for the walk’s PAS5.8
DFSC 0x30Remapping a live regionBreak-before-make violation (block to table, or output address change)9.2
DFSC 0x35Spinlock before the MMU and caches are onExclusive or atomic on Device or Non-cacheable memory10.1, 10.4
DFSC 0x11MTE-enabled kernel or allocatorA real tag mismatch, or tags not initialised for the granule (STG/DC GZVA missing)13.5
DFSC 0x23–0x28, or EC 0x1E in ESR_EL3RME system, first Realm or Non-secure access to a granuleGPT entry marks the PA for another PAS, or GPCCR_EL3/GPTBR_EL3 set up wrong12.4
EC 0x0D (0x3600000n)Indirect branch into assembly or a JIT regionTarget lacks a BTI landing pad on a guarded page (n is the BTYPE)13.1, 18.1
EC 0x1C (0x72000000–0x72000003)Function returnCorrupted LR or stack, or PAuth keys changed under the code (missing key save/restore across a world switch)13.1, 17.3
EC 0x2D, ExType = 0Function return with GCS enabledReturn address does not match the GCS: stack corruption, or unmatched setjmp/longjmp-style code13.2
EC 0x22RET or ERETCorrupted LR or ELR_ELx (often a smashed stack)3.2
EC 0x26Handler entry or early CSP not 16-byte aligned while SCTLR_ELx.SA == 13.1
EC 0x0EInstruction after an ERETIllegal exception return: SPSR.M names an EL that is not implemented or enabled, or an execution state that EL cannot use3.2, 2.1
EC 0x2F, 0xBE000011After enabling caches, or at the first DRAM accessUncontainable error from the memory system: DRAM not ready, or a write-back to bad memory3.4, 18.3
EC 0x2F with IDS = 1 (0xBF……)AnyIMPLEMENTATION DEFINED syndrome: decode from the core TRM16.7
The same EC repeating, ELR inside the vector tableAny early handlerRecursive exception: the handler itself faults (stack unmapped, VBAR wrong)18.3

Validation note: A directed test for each class above should check three things, not one: the EC, the ISS fields the class defines (for example WnR, S1PTW and the level for aborts, Op0…Rt for 0x18), and the address registers’ validity (FAR written or not, FnV). Syndrome bugs in RTL often get the EC right and an ISS field wrong, such as a reported level off by one for a level −1 walk, or WnR set for a read-modify-write atomic. Run the same test with the fault taken to EL1, EL2 and EL3 to cover each ESR_ELx (18.5).

Appendix E: Bring-up checklists

These checklists condense Part 17 and the sections it builds on into lists you can tick off against a new port, a code review or a failing boot. Each item says what to do, how to confirm it, and what a miss looks like. The reasoning is in the linked sections, and the sequences themselves are in Appendix C. TF-A function names are given as the reference implementation, not as the only correct one.

Conventions: “whole-register write” means a write from a constant built from named fields, with RES1 bits set and RES0 bits clear, before any read-modify-write (17.1). “Per world” means the value is rebuilt for every exception return to that Security state (17.2).

E.1 EL3 initialisation (every core, every reset)

#ItemConfirmSymptom of a missSee
1The core reaches RVBAR_EL3. If it does not, check the reset controller, the clocks, RVBARADDR and the ROM mapping before suspecting firmwareReset Catch (EDECR.RCE) or a CTI halt; QEMU -d int,cpu_reset,in_asm -S -sNo instruction retires17.1
2SCTLR_EL3 whole-register write first: EE explicit, M=C=0, RES1 bits set, and EIS/EOS = 1 (RES1 without FEAT_ExS, real controls with it); ISBRead back; compare with the RES1 maskWrong endianness on the first load; non-synchronizing exception entry/return on FEAT_ExS cores17.2, 7.8
3On a fixed reset vector: cold/warm decision (plat_get_my_entrypoint) before touching any shared state, stackless, from a location valid with caches offWarm-boot a secondary while the primary runsWarm-booting core corrupts the primary’s .data/.bss17.1
4VBAR_EL3 written, then ISB, before anything that can faultA deliberate BRK reports through your vectorJump through an UNKNOWN vector on the first UNDEF17.1, 3.1
5CPU reset handler selected by MIDR_EL1: errata workarounds for this variant/revision, IMPLEMENTATION DEFINED CPU*CTLR settings, CPUECTLR_EL1.SMPEN=1 on pre-DynamIQ coresPrint MIDR and the applied errata list (TF-A ERRATA_*, errata reporting)Rare corruption, hangs under load; on pre-DynamIQ cores, incoherent L11.3, 8.8
6SCR_EL3, CPTR_EL3, MDCR_EL3 whole-register writes from constants. No read-modify-write before thatRun once with debugger-planted non-zero values in these registers; behaviour must not changeRandom traps (TWI, EA), FP traps (EC 0x07), debug or PMU leaking into Secure state17.1, 17.2
7MDCR_EL3: SDD=1; SPME=0 and SCCD/MCCD where implemented; SPE/TRBE/BRBE ownership fields per worldCount cycles across an SMC: Secure time must not be countedSecure execution visible to Normal-world perf17.2, 16.3
8Only then unmask SError at EL3 (DAIFClr A) and set SCR_EL3.EA per the RAS modelInject an SError with the RAS error-injection registers, if presentSError through an UNKNOWN vector, or lost17.1, 3.4, 16.8
9Secondaries leave (power off or hold pen) before the primary initialises memoryRelease order in a traceTwo cores zeroing .bss17.4
10C runtime with MMU off: SRAM/DRAM scrubbed if ECC-protected; RW range invalidated by VA (system-cache leftovers); .bss zeroed with aligned stores and no DC ZVA; firmware built with -mstrict-alignFour-state RTL with X-propagation; FVP with cache modellingSError at “the first memory access”; Alignment faults in memset17.1, 6.5
11CNTFRQ_EL0 written on every core (only the highest EL can); system counter enabled once (CNTCR.EN in CNTControlBase)CNTPCT_EL0 advances; same frequency on all coresTimeouts that never expire; time running at the wrong rate4.6, 17.2
12ICC_SRE_EL3.{SRE,Enable}=1; ISB; read backSRE reads 1Kernel dies in early GIC probe4.5
13ACTLR_EL3: grant lower ELs only the IMPLEMENTATION DEFINED register access they need (usually none)Lower-EL write to ACTLR_EL1 trapsKernel or guest can change core tuning and errata bits17.2
14EL3 MMU and caches on as early as a minimal map exists (E.2)E.2Slow boot; unaligned or DC ZVA faults in C17.2
15Feature audit: for every feature the ID registers advertise and the OS will use, the EL3 enable bit is set and its registers are context-switched per world. Build with FEATURE_DETECTION=1 once per new coreDirected test touching one register per advertised feature from Normal-world EL2, with a Secure round trip in betweenEC 0x18 trap to EL3, or an injected UNDEF in the kernel (EC 0x00 at EL1); silent state leakage between worlds17.3
16First exception return: per-world SCR_EL3 (NS, RW, HCE, routing, feature enables); SPSR_EL3 (M = EL2h 0b1001 or EL1h 0b0101, AArch64, DAIF masked); ELR_EL3; target SCTLR_ELx clean; EL2 controls written if EL2 exists but software starts at EL1; GPRs zeroed except argumentsHalt at el3_exit and read the contextIllegal exception return: the PE stays at EL3 with PSTATE.IL, and the next instruction takes EC 0x0E with ELR_EL3 = intended entry17.2, 3.2, 12.2

E.2 MMU on (any EL)

#ItemConfirmSymptom of a missSee
1Translation tables built in memory the walker will read coherently. If built with the MMU or D-cache off: DC IVAC the table region to the PoC before and after buildingPoison the table lines through a cacheable alias first; boot must still succeed (cache modelling on)Garbage walks or random faults on silicon only9.3
2TCR_ELx: T0SZ and TG0 match the starting level the tables were built for (TG0 and TG1 encodings differ); PS/IPS ≤ ID_AA64MMFR0_EL1.PARange and ≥ the largest output address; IRGN0/ORGN0/SH0 match how the tables are mappedRecompute the starting level by hand (5.4)Level-0 (starting-level) Translation fault on the first fetch; Address size fault5.2, 5.3
3MAIR_ELx attribute indices agree with every descriptor’s AttrIndxDecode a few leaf descriptors by handCode mapped Device (faults or no speculation); MMIO mapped Normal6.5
4Leaf descriptors: AF=1 (unless hardware AF is enabled), blocks aligned to their size, SH consistent across aliases, code not XN, SCTLR.WXN consistent with writable code pagesAT S1ExR + PAR_EL1 after the MMU is on (not before: with M=0, AT reports the flat mapping)Access flag fault; Permission fault on the first fetch5.9, 5.5
5Map only memory that exists and is ready: no PA holes, untrained DDR or Secure carve-outs inside large Normal blocks; MMIO as Device and XNReview the memory map against the SoC mapAsynchronous SErrors or bus hangs with no instruction to blame9.3, 14.2
6The enabling code, the stack and the vectors are mapped at VA = PA (or the code branches to its new VA from an identity-mapped page)Disassemble the enable routine; check its page in the tablesRecursive exceptions at VBAR right after M=19.3
7Local TLB invalidate (TLBI ALLE3/ALLE2/VMALLE1) before enablingIn the disassemblyStale entries from an earlier stage or a warm reset9.3
8DSB ISH; ISB between the MAIR/TCR/TTBR writes and the SCTLR write; ISB after itIn the disassembly; compiler-generated MSR needs an explicit isb()Works single-stepping, fails at speed9.3, 7.8
9Data written before the D-cache was enabled and read after: invalidate (not clean) by VA to the PoC before enablingChecker pattern written with caches off, read with caches onData “disappears” after enabling9.3, 6.6
10Every later change to a live mapping uses the 9.1 sequence, or break-before-make for OA/type/size changes, and is not done while another PE uses the mappingCode review of every remap helperSporadic Translation faults on secondaries; TLB conflict aborts (DFSC 0b110000)9.1, 9.2

E.3 GIC on (GICv3)

#ItemConfirmSymptom of a missSee
1Each PE: ICC_SRE_EL3, then ICC_SRE_EL2, then ICC_SRE_EL1, SRE=1 (and Enable=1 at EL3 and EL2), ISB after eachRead back SREICC_* accesses UNDEF or trap4.5
2Boot PE, Secure: GICD_CTLR.ARE_S/ARE_NS set while the group enables are clear; DS=0 if there is a Secure world; poll RWPRead GICD_CTLRLegacy routing (8-PE limit, no LPIs); Secure registers reachable from Non-secure4.5
3Multi-chip GICs (GIC-600/GIC-700, IMPLEMENTATION DEFINED registers): chip routing table (GICD_DCHIPR, GICD_CHIPRn) programmed before any Distributor enable, SPI block ranges disjoint and completeGICD_CHIPSR.RTS reports consistentSPIs pending on one chip and invisible on another4.5, 17.5
4Every SPI configured while disabled: IGROUPR/IGRPMODR, IPRIORITYR, ICFGR (level vs edge), IROUTER (affinity matching the real MPIDR_EL1 layout)Dump the registers; compare IROUTER with each target’s MPIDR_EL1Interrupt pending forever (no matching Redistributor); level interrupt firing once4.5
5GICD_CTLR.EnableGrp0/EnableGrp1NS/EnableGrp1S; poll RWPRead backNothing forwarded, including SGIs/PPIs under affinity routing4.5
6Each PE, Secure: power the Redistributor (GICR_PWRR on GIC-600 class, IMPLEMENTATION DEFINED); GICR_WAKER.ProcessorSleep=0; poll ChildrenAsleep==0Read GICR_WAKERInterrupts held back for this PE only4.5
7Find this PE’s Redistributor by matching GICR_TYPER.Affinity_Value with MPIDR_EL1; frame stride 128 KB (256 KB with VLPIS); stop at GICR_TYPER.LastLog the frame index found per PEWalk runs off the end (looks like an early-boot hang)4.5
8SGIs/PPIs in the SGI_base frame: group, priority, ICFGR1, GICR_ISENABLER0Timer PPI firesNo timer tick4.5
9CPU interface: ICC_PMR_EL1 above the priorities in use (it resets to 0, masking everything), ICC_BPR*, ICC_CTLR_EL1/EL3 (EOImode), ICC_IGRPEN0_EL1/ICC_IGRPEN1_EL1 (or ICC_IGRPEN1_EL3)ICC_HPPIR*_EL1 shows the pending INTIDPending but never signalled4.5, 4.3
10Routing and masking: SCR_EL3.IRQ/FIQ, HCR_EL2.IMO/FMO, PSTATE.I/F match the intended model; SCR_EL3.FIQ identical on all CPUsForce pending with GICD_ISPENDR/GICR_ISPENDR0FIQ at EL3 instead of IRQ at EL1 (wrong group); nothing taken3.3, 4.3
11Handler: acknowledge, clear the source with a read-back, DSB, EOI; deactivate if EOImode=1GICD_ISACTIVER not stuckDelivered once, never again4.2, 7.9
12LPIs (if used): property and pending tables allocated and cleaned (or coherent), GICR_CTLR.EnableLPIs last; ITS tables and command queue set up per IHI0069INT command delivers an LPILPIs silently never arrive4.4

E.4 Secondary CPU on (PSCI CPU_ON)

#ItemConfirmSymptom of a missSee
1plat_core_pos_by_mpidr() validates every field of the requested MPIDR, for the real affinity layout (MT, Aff0 as thread on DynamIQ)Fuzz CPU_ON with invalid MPIDRs: expect INVALID_PARAMETERSWrong core started; out-of-bounds index at EL317.4
2Entry point validated (validate_ns_entrypoint)Pass an address outside Non-secure DRAMEL3 jumps the core into arbitrary memory17.4
3PSCI state the target reads with caches off (ON_PENDING, entry point, context) cleaned to the PoC, unless the platform is hardware-coherent from resetCache-modelled FVP or siliconTarget reads stale state and goes back to sleep or uses the wrong entry17.4, 8.8
4Cluster power and interconnect membership: if the cluster was off, power it and (older interconnects) add it to the snoop and DVM domains before the core enables cachesInterconnect snoop counters for the clusterIncoherent caches; TLBI broadcasts not reaching the new core17.4, 17.5
5Target reset path runs all of E.1 that is per core: SCTLR_EL3, vectors, reset handler (errata, SMPEN on pre-DynamIQ), CNTFRQ_EL0, ICC_SRE_EL3, EL3 MMUErrata report on every core, not only the primaryErrata applied only on core 017.1
6Redistributor wake and CPU interface init on the target (pwr_domain_on_finish)Send an SGI to the new coreCore runs but receives no interrupts4.5
7Target’s Non-secure context (SCR_EL3, SPSR_EL3, ELR_EL3 = entry, x0 = context ID) built by the caller and visible to the target after its MMU is onHalt the target at el3_exitWrong EL or wrong entry on the secondary only17.4
8The OS treats CPU_ON success as “request accepted” and runs its own handshake or polls AFFINITY_INFOOS logBoot hangs waiting for a core that never came up17.4
9Hold-pen platforms only: mailbox write cleaned to the PoC (or Non-cacheable), DSB SY, SEVRelease from a cold pen in RTLSecondary never leaves the pen17.4, 7.10

E.5 Caches off before power-down (CPU_OFF, power-down CPU_SUSPEND)

#ItemConfirmSymptom of a missSee
1State coordination done under the power-domain locks; the last core of a cluster (or the OS, in OS-initiated mode) decides the cluster statePSCI stats (PSCI_STAT_COUNT/RESIDENCY)Cluster powered off under a running core17.4
2SPD/SPMC notified and its state saved; extension state not in the context (for example AMU counters) savedResume a core and compareSecure world loses state; counters reset17.4
3Timers: the OS’s next event moved to an always-on timer (broadcast timer, CNTBaseN frame); owners of CNTV_CVAL_EL0, CNTKCTL_EL1, CNTHCTL_EL2, CNTVOFF_EL2 restore them on resume; EL3 rewrites CNTFRQ_EL0Wake from a timer-only idle periodCore never wakes; virtual time jumps17.4, 4.6
4Pre-DynamIQ: clear SCTLR_EL3.C; ISB; set/way clean+invalidate L1 (and L2 on the last core of the cluster) with levels from CLIDR_EL1; then clear CPUECTLR_EL1.SMPEN; ISB; DSB SY. In that orderStress with another core writing lines the target holds dirty during power-downLost dirty lines; stale data on other cores (SMPEN cleared too early)8.8
5DynamIQ: CPUPWRCTLR_EL1.CORE_PWRDN_EN=1; ISB; hardware flushes and leaves coherency. Cluster hints in CLUSTERPWRDN_EL1 are advisoryPMU L1D_CACHE_WB (0x15) on the target before WFICore retains power, or the request is ignored8.8
6No cacheable writes of data needed later after the flush (stack spills included); data the warm-boot path reads with caches off is clean to the PoCChecker patterns on the power-down stack surviveCorruption after many suspend cycles8.8
7GIC: GICR_WAKER.ProcessorSleep=1, poll ChildrenAsleep==1; CPU interface disabled; SPIs targeted at this core migrated (OS) or 1-of-N participation removed (GICR_CTLR.DPG* where GICR_TYPER.DPGS=1)Wake by an SPI aimed at the sleeping coreLost wake-up; SPI pending until the core returns17.4, 4.5
8Cache-related errata for this core revision applied (for example clean-as-clean+invalidate workarounds)SDEN cache, CMO and power-down categories reviewedCorruption only after thousands of cycles8.8, 1.3
9Power controller programmed (often SCMI to an SCP); DSB SY; WFI. A WFI that falls through is handled as an immediate wake-upCount fall-throughsCore spins in EL3 or returns with caches off17.4, 7.6
10Last cluster or chiplet down: cluster cache flushed (by the last core or by hardware) before the cluster leaves the snoop and DVM domain; on return, invalidate TLBs and caches as from resetInterconnect counters show snoops stop and restartStale TLB entries or lines after cluster power-up8.8, 17.5

Validation note: Each checklist has a matching stress test in the linked sections. In short: X-propagation RTL runs and planted UNKNOWN values for E.1 (17.1); a poisoned-cache MMU-on test for E.2 (9.3); forced-pending plus real-device tests on every die, before and after a power cycle, for E.3 (4.5); and a randomised PSCI loop with interrupts aimed at sleeping cores and checker patterns for E.4 and E.5 (17.4, 8.8). Run the cache-related tests on silicon or with FVP cache-state modelling enabled; without it, none of the dirty-line failures can occur. For what the kernel expects at handover, see the entry-state table in 17.6.

Appendix F: Glossary

Short definitions of the terms this book uses, with the section that treats each one. Where a term is defined in the Arm ARM, the wording here follows DDI0487, and the DDI0487 glossary entry is the definition that counts (Reading the Arm ARM). Terms that are Arm or industry usage rather than architecture (for example DSU, CMN, hold pen) are marked (non-architectural).

Architectural qualifiers

These words, set in small capitals in the Arm ARM, decide what software may rely on.

TermMeaningSee
IMPLEMENTATION DEFINEDBehaviour that the architecture does not fix, and that the implementation must document. Software may rely on it only for that implementationReading the Arm ARM
UNKNOWNAn unspecified value that may differ between resets and between PEs, that must not be relied on, and that does not expose information the current EL and Security state could not otherwise access. “Zero on the model” is not a definition17.1
UNPREDICTABLEBehaviour that software must never cause and must not rely on. It cannot be a security hole beyond what the current EL and Security state can already doReading the Arm ARM
CONSTRAINED UNPREDICTABLEUNPREDICTABLE behaviour limited to a listed set of permitted outcomes (Part K of DDI0487 lists them; ConstrainUnpredictable() in pseudocode)Reading the Arm ARM, 8.6
RES0 / RES1Reserved bits. Software writes RES1 bits as 1 and RES0 bits as 0, and must not rely on reading them back, because a later version may give them meaning17.2
RAZ/WI, RAO/WIRead-as-zero (or one), writes ignoredReading the Arm ARM
Permitted from / mandatory fromThe first architecture version in which an implementation may include a feature, and the first in which a compliant implementation must. Taken from DDI0487 chapter A21.1
FEAT_xxxThe architecture’s name for an extension. Presence is discovered only from ID registers, never from the version number1.1

Terms

Access flag (AF). Descriptor bit that records that a page or block has been accessed. If AF=0 and hardware management is off, an access takes an Access flag fault. 5.6

Acquire / release. One-way barriers carried by a load (LDAR, LDAPR) or a store (STLR). Acquire orders later accesses after the load; release orders earlier accesses before the store. RCsc (LDAR/STLR) additionally orders a release before a later acquire; RCpc (LDAPR, FEAT_LRCPC) does not. 7.7

Affinity. The hierarchical core address in MPIDR_EL1 (Aff3.Aff2.Aff1.Aff0), used by PSCI and by GICv3 routing. Its layout is IMPLEMENTATION DEFINED. 17.4

Affinity routing. GICv3 mode (GICD_CTLR.ARE_*) in which SPIs are routed by GICD_IROUTER<n> affinity values rather than the legacy 8-bit target mask. 4.1, 4.5

AMU (Activity Monitors Unit). Architected, always-counting event counters (AMEVCNTR0n_EL0 and auxiliary counters) for power and performance management. 16.4

ASID (Address Space Identifier). Tag on non-global TLB entries for regimes with two VA ranges, taken from TTBR0_EL1 or TTBR1_EL1 per TCR_EL1.A1. 9.1

Barrier. An instruction that constrains order (DMB), completion (DSB), context (ISB), speculation (CSDB, SB, SSBB, PSSBB) or trace and profiling (TSB, PSB). 7.5, 7.6, 7.8, 14.1

BBM (break-before-make). Replacing a valid descriptor by first writing an invalid one, invalidating the TLBs, and only then writing the new one. Required for changes of output address, memory type, shareability or block size. FEAT_BBM levels relax the block-size case. 9.2

BHB (branch history buffer). Prediction state indexed by recent branch history. Its cross-context training is the Spectre-BHB problem. 14.4

BL1, BL2, BL31, BL32, BL33 (TF-A). Boot ROM stage, trusted boot loader, EL3 runtime firmware, Secure-world payload (for example OP-TEE or an SPMC), and Non-secure boot loader (for example UEFI or U-Boot). 12.2, 17.1

BTI (Branch Target Identification). FEAT_BTI: indirect branches must land on a BTI (or another landing-pad instruction) in guarded pages. 13.1

Cache maintenance operation (CMO). DC or IC instruction that cleans, invalidates, or both, by VA, by set/way, or (at EL3) by PA, to a named point. 8.5

CHI, ACE (AMBA). Arm’s coherent interconnect protocols: CHI (packet-based, used by CMN meshes) and ACE (the AXI coherency extension). ACE-Lite is the IO-coherent subset. 8.3

Clean / invalidate. Clean writes a dirty line back towards the named point and leaves it valid. Invalidate discards the line, including any dirty data. 8.5

CMN (non-architectural). Arm’s Coherent Mesh Network interconnect, with home nodes (HN-F) holding the snoop filter and system-level cache. 8.3

CMODX. Concurrent modification and execution of instructions: changing code another PE may be fetching. Defined only for a small set of instructions. 8.6

Coherence order. For each location, the single total order of all writes to it, agreed by all observers. 7.1

Cold reset, Warm reset. Cold reset resets all PE logic in the Core power domain, including debug state. Warm reset resets the execution logic but not the debug state. Neither resets the system (GIC, counter, interconnect). 17.1

Complete. A read or write is complete for a shareability domain when it is globally observed in that domain and any associated walks are complete. TLB and cache maintenance have their own completion rules. DSB waits for completion. 7.1, 7.6

Context synchronization event (CSE). ISB, exception entry (unless SCTLR_ELx.EIS=0 with FEAT_ExS), exception return (unless EOS=0), exit from Debug state, and DCPS/DRPS in Debug state. After a CSE, later instructions see all earlier context-changing operations. 7.8

Contiguous bit. Descriptor hint that a naturally aligned set of entries maps a contiguous range with identical attributes, so one TLB entry can cover it. 5.3

CWG, ERG, DminLine, IminLine. Fields of CTR_EL0: cache writeback granule (largest block a writeback may cover), exclusives reservation granule, and the smallest data and instruction cache line sizes. 8.1, 10.1

DBM (dirty bit modifier). Descriptor bit that lets hardware (FEAT_HAFDBS) mark a page dirty by clearing its read-only state. 5.6

Dependency (address, data, control). A register dataflow from a load into the address of a later access, into the data of a later store, or into a branch condition before a later access. Address and data dependencies order the later access; a control dependency orders only later stores, unless followed by an ISB. 7.4

Device memory (nGnRnE, nGnRE, nGRE, GRE). Memory type for peripherals: never speculatively read, with the Gathering, Reordering and Early write acknowledgement attributes each either permitted (G, R, E) or not (nG, nR, nE). 6.2, 7.9

DSU (DynamIQ Shared Unit) (non-architectural). The cluster-level block of DynamIQ cores: L3 cache, snoop control and power control. 8.8

DVM (Distributed Virtual Memory) messages. Interconnect messages that carry broadcast TLBI, IC and related operations, and the DVM Sync that a DSB waits for. 8.3, 9.1

EC (Exception Class). ESR_ELx[31:26]: what kind of exception was taken, which determines how the ISS is decoded. 3.2, Appendix D

ESB, IESB. Error Synchronization Barrier, and Implicit ESB at exception entry and return (SCTLR_ELx.IESB), which make pending SErrors visible at a defined point. 3.4

Exception level (EL0–EL3). Privilege level. Each EL has its own system registers with the _ELx suffix. 2.1

Exclusive monitor. Local and global state that makes LDXR/STXR pairs atomic: the store fails if the reservation granule may have been written since the load. 10.1

FAR, HPFAR, PFAR. Fault address registers: the faulting VA (FAR_ELx), the faulting IPA for stage 2 (HPFAR_EL2), and the faulting PA (PFAR_ELx, FEAT_PFAR). 5.8

FF-A, PSCI, SMCCC, SDEI, SCMI. Firmware interfaces: the Firmware Framework for A-profile (partition messaging, DEN0077), power state coordination (DEN0022), the SMC/HVC calling convention (DEN0028), software-delegated exceptions (DEN0054), and the system control and management interface to an SCP (DEN0056). 12.3, Appendix G

Fine-grained traps (FGT). FEAT_FGT registers (HFGRTR_EL2 and others) that trap individual system-register and instruction accesses to EL2. 11.1

Firmware-first / kernel-first error handling. Whether a RAS error is first taken by EL3 firmware (SCR_EL3.EA=1) or by the OS. 16.8

GCS (Guarded Control Stack). FEAT_GCS: a hardware-protected shadow stack of return addresses. 13.2

Globally observed. Observed by every observer in a given shareability domain. 7.1

GPT, GPC, GPI. Granule Protection Table, Granule Protection Check and Granule Protection Information: the RME mechanism that assigns each physical granule to a physical address space and checks every access against it. 12.4

Granule. The translation granule (4 KB, 16 KB or 64 KB) that sets page size and table geometry. Also, in RME, the unit of physical memory a GPT entry describes. 5.2

Hold pen (non-architectural). A loop in which a secondary core waits (usually in WFE) for a mailbox write that releases it. 17.4

Identity map (idmap). A mapping with VA = PA, needed for the code that turns the MMU on or off. 9.3

Illegal exception return. An ERET to a state that is not permitted (for example an EL not implemented or not enabled). The PE stays at the current EL with PSTATE.IL set, and the next instruction takes an Illegal Execution state exception (EC 0x0E). 3.2

Inner / Outer. The two cacheability levels a memory type describes. Which caches are “inner” is IMPLEMENTATION DEFINED. 6.3

IPA (intermediate physical address). Output of stage 1 and input of stage 2 when EL2 virtualization is active. 5.1, 11.3

ISS (Instruction Specific Syndrome). ESR_ELx[24:0], decoded according to the EC. For aborts it holds the DFSC/IFSC fault status code and fields such as WnR, S1PTW and CM. 5.8, Appendix D

ITS (Interrupt Translation Service). GICv3 block that translates an MSI (DeviceID, EventID) into an LPI for a target Redistributor. 4.4

Litmus test. A small multi-threaded program with a question about a final state, used to state and test memory-model rules (MP, SB, LB, WRC, IRIW). 7.3, 7.11

LSE (Large System Extensions). FEAT_LSE single-instruction atomics (LDADD, CAS, SWP and related), which may be performed “far” in the interconnect. 10.2

MEC (Memory Encryption Contexts). FEAT_MEC: per-Realm memory encryption selected by a MECID. 12.5

Mismatched attributes. Two mappings of one PA with different memory type, cacheability or shareability. The architecture defines only limited guarantees for them. 6.6

MPAM. Memory System Resource Partitioning and Monitoring: PARTID and PMG labels on requests, acted on by memory-system components (MSCs). 8.9

MTE (Memory Tagging Extension). FEAT_MTE2 and related: 4-bit allocation tags per 16-byte granule, checked against pointer tags. 13.4, 13.5

Multi-copy atomicity (other-multi-copy atomic). The Armv8 property that once a write is observed by any observer other than the writing PE, it is observed by all of them. 7.2

nG (not global). Descriptor bit making a translation ASID-specific. 9.1

Normal memory. Memory type for RAM: may be accessed speculatively, merged and reordered, with Inner and Outer cacheability attributes. 6.2

Observer; observed by. An observer is any agent that can access memory. A write is observed by an observer when a later read by that observer returns it (or a coherence-later value), and a later write by it is coherence-after it. A read is observed when a later write by that observer can no longer affect it. 7.1

PAC (Pointer Authentication). FEAT_PAuth: a cryptographic signature in a pointer’s unused upper bits, added with PAC* and checked with AUT*. 13.1

PAN, UAO, EPAN. Privileged Access Never (privileged accesses to EL0-accessible memory fault), User Access Override (LDTR/STTR behave as normal accesses), and Enhanced PAN (also for execute-only EL0 pages). 5.5

PAS (physical address space). Under RME, one of four: Secure, Non-secure, Realm, Root. The PAS is effectively part of the physical address up to the PoPA. 12.4

PE (processing element). The architecture’s word for whatever executes instructions: a core, or a hardware thread of a multithreaded core. 2.1

PIE, POE. Permission indirection (FEAT_S1PIE/S2PIE: descriptor bits index a permission table in PIR_ELx/S2PIR_EL2) and permission overlays (FEAT_S1POE/S2POE: POR_ELx, or S2POR_EL1 for stage 2, restricts permissions per POIndex). 5.5

PMU (Performance Monitors). PMUv3 event counters and cycle counter (PMEVCNTRn_EL0, PMCCNTR_EL0). 16.3, 16.5

Point of Coherency (PoC). The point at which all observers that can access memory (PEs, DMA masters and others) are guaranteed to see the same copy of a location. Cleaning to the PoC is what a non-coherent master needs. 8.4

Point of Unification (PoU). The point at which a PE’s instruction caches, data caches and translation table walks are guaranteed to see the same copy. PoU for the Inner Shareable domain extends this to every PE in that domain. 8.4

PoP, PoDP, PoPA, PoE, PoPS. Further points: Persistence (FEAT_DPB), Deep Persistence (FEAT_DPB2), Physical Aliasing (FEAT_RME, where all PAS aliases of a PA meet), Encryption (FEAT_MEC), and Physical Storage (FEAT_PoPS). 8.4

PPU (non-architectural). Power Policy Unit: the hardware power-state controller for a core or cluster domain. 8.8

Program order. The order of instructions in one PE’s execution as the sequential ISA semantics define it. 7.1

RAS. Reliability, Availability and Serviceability: the error-record architecture (ERRnSTATUS and related), error synchronization and reporting. 16.7

Realm, Root. The Security states added by RME: Realm for confidential VMs, Root for EL3. 12.4

Redistributor. Per-PE GICv3 block that holds SGI, PPI and LPI state and connects to the CPU interface. 4.1

RME (Realm Management Extension). FEAT_RME: Realm and Root states, four physical address spaces, and granule protection checks. 12.4

Running priority. The priority of the highest-priority active interrupt at a CPU interface (ICC_RPR_EL1). Only higher-priority interrupts can preempt. 4.3

SDEN (non-architectural). Software Developer Errata Notice: Arm’s per-core errata document, matched to MIDR_EL1 variant and revision. 1.3

Security state. Secure, Non-secure, and with RME also Realm and Root. Determined by EL and SCR_EL3.{NS,NSE}. 2.1, 12.1

SError. The asynchronous System Error exception, usually an external abort that could not be reported synchronously. 3.4

Set/way operation. A DC ISW/CSW/CISW that names a cache line by level, set and way. Local, not broadcast, and correct only for initialisation and power-down of the local hierarchy. 8.5

SGI, PPI, SPI, LPI. GICv3 interrupt types: software-generated (INTID 0–15), private peripheral (16–31), shared peripheral (32–1019, plus the extended ranges), and locality-specific peripheral (message-based, INTID 8192 and up). 4.2

Shareability domain (Non-shareable, Inner Shareable, Outer Shareable, Full system). A set of observers. Hardware keeps data coherent among the observers in the domain of a cacheable mapping. Device and Normal Non-cacheable memory are always treated as Outer Shareable. 6.4

Single-copy atomicity. A single access whose effect is observed whole or not at all: aligned accesses up to 64 bits, plus the wider forms the feature set adds. 7.2, 10.3

SMMU (System MMU). SMMUv3: translation and protection for DMA masters, configured through stream table entries (STEs) and context descriptors (CDs). 11.5

SPMC, SPD (firmware). The FF-A Secure Partition Manager Core (at S-EL2, S-EL1 or, in TF-A’s EL3 SPMC, EL3), and TF-A’s Secure Payload Dispatcher that connects BL31 to a Secure OS such as OP-TEE. 12.3

Stage 1, stage 2. The two translation stages: stage 1 (VA to IPA or PA, owned by the OS or firmware) and stage 2 (IPA to PA, owned by EL2). 5.1

System register encoding. op0, op1, CRn, CRm, op2, written S<op0>_<op1>_C<n>_C<m>_<op2> when the assembler lacks a name. 2.5

Tarmac trace (tool). The FVP’s instruction-level trace, including register writes, memory accesses and translation walks. Lab setup, 5.9

TLB conflict abort. Fault (fault status 0b110000) that an implementation may raise when more than one TLB entry matches an access. 9.2

TLBI. TLB maintenance instruction: TLBI <type><level>{IS|OS}{nXS}. It is complete only after a following DSB. 9.1

Translation regime. The set of translation tables, registers and stages used for an access at a given EL: EL1&0 (in each Security state, with or without stage 2), EL2, EL2&0 (VHE) and EL3. Only the EL1&0 regime has a stage 2. 5.1

TTL hint. FEAT_TTL field in a TLBI operand that gives the level and granule of the leaf being invalidated. A wrong value may leave the entry in place. 9.1

VHE (Virtualization Host Extensions). FEAT_VHE: HCR_EL2.E2H=1 lets a host OS run at EL2, with _EL12/_EL02 aliases for the EL1 registers. 11.2

VMID. Tag on the EL1&0 regime’s stage 1, stage 2 and combined TLB entries for a guest, from VTTBR_EL2.VMID. 9.1

Walk cache. TLB storage for intermediate (table-level) walk results. Removed by non-leaf TLBI forms, not by the ...L (last-level) forms. 9.1, 9.2

Warm boot (TF-A). A core’s return through the PSCI warm-boot path after CPU_ON or a power-down suspend. Architecturally this is usually a Cold reset of that core, because its power domain was off. 17.1

WFE, WFI, SEV, event register. Wait-for-event and wait-for-interrupt hints. WFE sleeps until the event register is set (by SEV, a cleared global monitor, the event stream, or an interrupt). 10.4

XS attribute, nXS. FEAT_XS: marks accesses that may be slow to complete, so that TLBI ...nXS and DSB ...nXS need not wait for them. 9.1

Appendix G: References

The documents this book cites, grouped by what you would go to them for. Arm document numbers are stable across issues, so they are the best search key on developer.arm.com. Always use the latest issue unless a section says it depends on a specific one. The book tracks DDI0487 issue M.a and its Known Issues document (Introduction). How to navigate the Arm ARM itself is covered in Reading the Arm ARM.

The Arm ARM and its satellites

DocumentNumberUse it for
Arm Architecture Reference Manual for A-profile architectureDDI0487The authority for everything in this book
Arm ARM Known Issues102105Corrections and clarifications against a given DDI0487 issue (for example the DMB shareability redefinition in 7.5)
Arm A-profile Architecture RegistersDDI0601One page per system register, per release, with the Accessing pseudocode (traps and ECs)
A64 Instruction Set ArchitectureDDI0602Per-release instruction descriptions
Arm Architecture Machine Readable Specification(XML / JSON releases)Generated headers, disassemblers and test generators
Feature names in A-profile architecture109697Quick map of FEAT_ names to versions; check against DDI0487 A2
Arm A-profile Architecture Extensions pages(web)Features newer than the tracked DDI0487 issue
Armv8-M Architecture Reference ManualDDI0553Only for comparison with the M-profile book

Where to look in DDI0487

Chapter numbers move between issues, so look things up by part and title. Chapter A2 is the one chapter cited by number.

TopicPart and section titleBook sections
FEAT_ list, permitted-from and mandatory-from versions, feature dependenciesChapter A2, the list of architecture extensions1.1, Appendix A
Memory model: observability, completion, barriers, atomicity, the formal definitionPart B, the AArch64 application-level memory modelParts 6, 7, 10
Caches and cache maintenance; points of coherencyPart B, caches and memory hierarchy; Part D, cache maintenance instructionsPart 8
Individual instructions (LDAPR, DC CIVAC, TLBI RVAE1IS…)Part C, alphabetical instruction descriptionsthroughout
Exceptions, routing, ESR encodingsPart D, the AArch64 exception model; ESR_ELx register descriptionPart 3, Appendix D
Translation (VMSA), TLB maintenance, break-before-makePart D, the AArch64 virtual memory system architectureParts 5, 9
System register synchronization requirementsPart D, “Synchronization requirements for AArch64 System registers”7.8
Generic TimerPart D (system registers) and Part I (memory-mapped frames)4.6
Self-hosted debug, PMU, AMU, MTE, RMEPart D, the corresponding chaptersParts 12, 13, 16
External debugPart H16.2
Pseudocode libraryPart Jwhen the prose is ambiguous
Barrier litmus tests, recommended sequences, constraints on UNPREDICTABLEPart K appendices7.3, Appendix C
Definitions of IMPLEMENTATION DEFINED, UNKNOWN and the other qualifiersGlossaryAppendix F

Companion architecture specifications

SpecificationNumberBook sections
GICv3 and GICv4 architectureIHI0069Part 4, 11.4
GICv5 architectureAES00704.1
SMMUv3 architectureIHI00708.7, 11.5
RAS extension (Reliability, Availability, Serviceability)DDI05873.4, 16.7, 16.8
RME system architectureDEN012912.4
RME and MEC example software flows (granule transitions, MECID handling)10983912.4, 12.5
AMBA CHI protocolIHI00508.3
CoreSight PMU architectureIHI009116.5
MPAM architecturesee the MPAM supplement on developer.arm.com8.9

Firmware interfaces and platform standards

SpecificationNumberBook sections
Power State Coordination Interface (PSCI)DEN002212.3, 17.4
SMC Calling Convention (SMCCC)DEN00281.3, 12.3
Firmware Framework for A-profile (FF-A)DEN007712.3
Software Delegated Exception Interface (SDEI)DEN005416.8
System Control and Management Interface (SCMI)DEN005610.4, 17.4
Errata Management Firmware Interface (Errata ABI)DEN01001.3
Trusted Board Boot Requirements (TBBR)DEN000612.2
IO Remapping Table (IORT)DEN00494.4, 11.5
Arm Performance Monitoring Unit Table (APMT)DEN011716.5
Base System Architecture (BSA)DEN009418.6
Server Base System Architecture (SBSA)DEN002918.6
Base Boot Requirements (BBR)DEN004418.6

Implementation documents

  • Core Technical Reference Manuals (TRMs): IMPLEMENTATION DEFINED registers (CPUACTLR_EL1, CPUECTLR_EL1, CPUPWRCTLR_EL1), reset behaviour, cache geometry, PMU event lists (1.3).
  • Software Developer Errata Notices (SDENs): per-core errata with category and fixed-in revision (1.3).
  • DSU and CMN TRMs: cluster and interconnect power, cache and PMU controls (8.3, 8.8).
  • GIC-600 / GIC-700 TRMs: GICR_PWRR, multichip registers, error records (4.5).

Arm “Learn the architecture” guides

Introductory, not normative. When a guide and DDI0487 disagree, DDI0487 wins. Search for the title on developer.arm.com.

GuideNumberPairs with
Memory Systems, Ordering, and Barriers102336Part 7
AArch64 memory management101811Part 5, Part 9
AArch64 memory attributes and properties102376Part 6
AArch64 Exception Model102412Part 3
Generic Timer1023794.6
Arm GIC v3 and v4: Overview (formerly the GICv3 and GICv4 Software Overview, DAI0492)198123Part 4
AArch64 virtualization102142Part 11
TrustZone for AArch6410241812.1
Realm Management ExtensionDEN012612.4

The memory model as code: herdtools7

  • herdtools7 (herd7, litmus7, diy7): github.com/herd/herdtools7. herd7 evaluates a litmus test against a model; litmus7 runs it on hardware; diy7 generates test families (7.11, Lab setup).
  • aarch64.cat: the Arm memory model in herd’s cat language, shipped in the herdtools7 herd/libdir directory. It is the executable form of the definition in DDI0487 Part B (7.3).
  • Background papers: Pulte, Flur, Deacon et al., “Simplifying ARM Concurrency: Multicopy-Atomic Axiomatic and Operational Models for ARMv8” (POPL 2018), which describes the 2017 move to other-multi-copy atomicity (7.2); Alglave, Maranget, Tautschnig, “Herding Cats” (TOPLAS 2014), on the cat modelling approach.

Firmware and OS sources

  • Trusted Firmware-A: source at git.trustedfirmware.org/TF-A/trusted-firmware-a.git, documentation at trustedfirmware-a.readthedocs.io. The book’s worked examples come from bl1/, bl31/, include/arch/aarch64/el3_common_macros.S, lib/xlat_tables_v2/, lib/cpus/aarch64/ (errata and power-down), lib/el3_runtime/aarch64/context_mgmt.c, lib/psci/ and drivers/arm/gic/v3/. The Firmware Design, Porting Guide, Build Options and CPU Specific Build Macros pages are the ones to read first.
  • TF-A Tests (TFTF): git.trustedfirmware.org/TF-A/tf-a-tests.git, directed tests for PSCI, features and context switching (18.5).
  • TF-RMM: the Realm Management Monitor reference implementation, for RME and MEC flows (12.4).
  • Linux arm64 (reference mapping only): arch/arm64/include/asm/barrier.h, io.h, tlbflush.h, cacheflush.h, arch_timer.h; arch/arm64/mm/cache.S and dma-mapping.c; arch/arm64/kernel/head.S and cpufeature.c; and Documentation/arch/arm64/booting.rst for the kernel entry contract (17.6). The kernel’s tools/memory-model/ holds the Linux kernel memory model, also in cat form.

Models and tools

  • QEMU qemu-system-aarch64, machine virt (secure=on,virtualization=on), with -d int,mmu,guest_errors and the gdbstub (Lab setup).
  • Arm Fixed Virtual Platforms (FVP_Base_RevC-2xAEMvA): feature parameters, Tarmac trace, and cache-state modelling (cache_state_modelled) (Lab setup, 18.4).
  • Arm Architecture Compliance Suites (ACS for BSA, SBSA and SystemReady) (18.6).