#14442·wasmtime

jit-icache-coherence: aarch64 clear_cache skips dc cvau and assumes 64-byte cache lines

Author: doracawlCreated Sep 28, 2026Updated Sep 30, 2026

aarch64_flush_icache in crates/jit-icache-coherence/src/libc.rs (49.0.1, lines 144-173, added in #12133) issues ic ivau over the range with a fixed 64-byte stride, then dsb ish and isb. Two parts of the architectural sequence for making newly written instructions visible are missing:

  1. No dc cvau. When CTR_EL0.IDC == 0, the data cache must be cleaned to the point of unification (dc cvau per line, then dsb ish) before the instruction cache is invalidated; otherwise ic ivau can refetch stale bytes from a level below the dirty D-cache line. The comment above dsb ish says "Flush dcache", but a barrier does not clean anything. Cores such as Cortex-A53 and Cortex-A72 report IDC == 0.
  2. Fixed 64-byte line size. The minimum I-cache and D-cache line sizes come from CTR_EL0.IminLine / DminLine; a core with smaller lines would skip lines.

The sequence compiler-rt's __clear_cache uses (and that IDC/DIC let you skip on cores that don't need it):

if !CTR_EL0.IDC: for each DminLine: dc cvau, x
dsb ish
if !CTR_EL0.DIC: for each IminLine: ic ivau, x ; dsb ish
isb

In practice cranelift-jit mostly gets away with it on Linux because code goes into freshly mapped pages, and the kernel cleans a page's D-cache when it is first mapped executable. That stops holding once code memory is reused within a process: with cranelift-jit 0.124 (before #12133), a program that freed a JITModule and compiled into the reused allocation ran the old function's instructions on aarch64 (macOS and Linux); the fix on our side was the full sequence above.

Happy to send a PR that reads CTR_EL0 and adds the dc cvau loop if that is the preferred direction.

Source: bytecodealliance/wasmtime