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

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”