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:
| Tag | Source | Width | Notes |
|---|---|---|---|
| ASID | TTBR0_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 |
| VMID | VTTBR_EL2.VMID | 8 bits, or 16 with FEAT_VMID16 (v8.1) and VTCR_EL2.VS=1 | Tags EL1&0 entries, both stage 1 and combined, while stage 2 is in use or EL2 is enabled |
| Global / non-global | descriptor nG (bit 11 of a block/page descriptor) | 1 bit | nG=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.FBforces 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.
| Type | Matches | Typical forms |
|---|---|---|
| VA | One VA, for the given ASID, plus global entries for that VA | VAE1, VAE2, VAE3 |
| VAA | One VA, any ASID | VAAE1 |
| VAL / VAAL | Same as VA/VAA, but only last-level (leaf) entries; walk-cache entries may survive | VALE1, VAALE1, VALE3 |
| ASID | All non-global entries for one ASID | ASIDE1 |
| VMALL | All EL1&0 entries for the current VMID (stage 1 only, or combined) | VMALLE1 |
| VMALLS12 | All stage 1 and stage 2 entries for the current VMID (EL2 only) | VMALLS12E1 |
| IPA | Stage 2 entries for one IPA, current VMID (EL2 only) | IPAS2E1, IPAS2LE1 |
| ALL | Everything for the regime | ALLE1 (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:
- 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).
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/SHmatch 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.TLBI ...IS. This removes the entry from every TLB in the domain, including walk caches for a non-Lform.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). ForOSforms useDSB OSH.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 (
MAIR0b0000dd00) has XS=1, and new encodings0b0000dd01give Device with XS=0. Normal Inner and Outer Write-Back memory has XS=0.0b01000000(Normal Non-cacheable) and0b10100000(Normal Write-Through) gain an XS=0 meaning that is UNPREDICTABLE without the feature. See theMAIR_ELxencoding table and 6.5. TLBI ...nXS(for exampleTLBI VAE1ISNXS). It behaves as the normal form except that its completion does not wait for accesses with XS=1.DSB <option>nXS(for exampleDSB 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 theHFGITR_EL2TLBI 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 ISHis 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) andDTLB_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_TLBIworks around it by issuing the TLBI, aDSB 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
ISBonly synchronises the local PE, and the other PE needed its own ISB - B.
VAE1ISmisses global entries, soVAAE1ISwas 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
OSsuffix 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.
VMALLE1ISalso 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 VAE1after the DSB to evict the cached invalid entry - B. Replace
DSB ISHSTwithDMB ISH - C. Clean the descriptor to PoC with
DC CVAC, whatever the walk attributes - D. Add an
ISBafter 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