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

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