Skip to content

TCB: AArch64 barriers (DSB SY, ISB, SB) - #4373

Closed
reaperhulk wants to merge 2 commits into
claude/dit-scopefrom
claude/dit-barrier-tcb
Closed

reaperhulk wants to merge 2 commits into
claude/dit-scopefrom
claude/dit-barrier-tcb

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4357. This is a trust change (TCB/): it adds three instructions to the AArch64 model.

What

Instr.barrier b, with Barrier.dsbSy (dsb sy), .isb (isb) and .sb (sb, FEAT_SB). The follow-up PR uses them to put a speculation barrier after msr DIT, #1 on Apple's targets.

Why

The two vendors disagree on whether a barrier is needed after turning PSTATE.DIT on:

  • Arm says writes to PSTATE fields "always occur in program order relative to other instructions" and need no ISB (Learn the architecture: Barriers).
  • Apple says: "To ensure that subsequent instruction timing reflects the updated DIT processor state, add a speculation barrier after turning on DIT" (Writing ARM64 code for Apple platforms). Its corecrypto uses sb where the CPU has FEAT_SB, else dsb sy; isb (cc/src/cc_timing_safe.c).

Go's runtime followed both, using the barrier on darwin/arm64 only (golang/go#77776, src/internal/runtime/sys/dit_arm64.s). The follow-up does the same.

Semantics, with citations

DDI 0602 2026-03 (A64 ISA):

  • "DSB": for CRm = '1111' (SY), the operation is DataSynchronizationBarrier(scope, types, nXS).
  • "ISB": InstructionSynchronizationBarrier().
  • "SB": decode if !IsFeatureImplemented(FEAT_SB) then EndOfDecode(Decode_UNDEF); end;, operation SpeculationBarrier().

The model has no memory ordering, pipeline or speculation, which is all these act on. So each leaves the state as it is (exec (.barrier _) s = some s) and leaks nothing (addrs is []). They have no operands, so their timing can't depend on data. Their time depends only on the instructions before them, whose leakage the model already accounts for.

Requirements and encodings

  • sb requires Rust's sb (FEAT_SB), as above. DSB and ISB are baseline.
  • Encodings follow the layout 11010101000000110011 CRm 1 opc 11111:
    • dsb sy: 0xD5033F9F
    • isb: 0xD5033FDF
    • sb: 0xD50330FF
  • These are the words GNU as 2.46 gives for the printed text (-march=armv8.5-a). With -march=armv8-a it refuses sb ("selected processor does not support `sb'").

Changes

  • TCB/AArch64/Isa.lean:
    • Barrier and Instr.barrier.
    • exec, with the pseudocode cited.
    • requires (.barrier .sb => ["sb"]), and its docs citing the SB decode.
    • A module-docs paragraph on barriers.
  • TCB/AArch64/Encode.lean, Print.lean: the encodings and the text.
  • Framework (so the proofs compile; no trust):
    • Inline.dstOf and exec_gpr.
    • The taint step (unchanged taint) and its soundness case.
    • Lit: ToExpr for Barrier, so materialize_code can write code that contains one.
  • VerifiedGarbageTest/AArch64Barrier.lean checks:
    • No effect on any state field, PSTATE.DIT included.
    • No addresses.
    • The text, encodings, requirements and taint.

No artifact uses them yet, so src/asm/ is unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq

reaperhulk and others added 2 commits November 7, 2026 01:11
`Instr.barrier b`, with `Barrier.dsbSy`, `.isb` and `.sb`, for a speculation
barrier after setting PSTATE.DIT, which Apple's documentation asks for
("To ensure that subsequent instruction timing reflects the updated DIT
processor state, add a speculation barrier after turning on DIT"), with DSB
SY and ISB where FEAT_SB is missing, as Apple's corecrypto does.

Each leaves the model's state as it is and leaks nothing: DDI 0602 2026-03
gives their operations as DataSynchronizationBarrier,
InstructionSynchronizationBarrier and SpeculationBarrier, which act on
memory ordering, context synchronization and speculation, none of which
the model has. They have no operands. SB requires FEAT_SB ("SB": `if
!IsFeatureImplemented(FEAT_SB) then EndOfDecode(Decode_UNDEF)`), Rust's
`sb`; DSB and ISB are baseline. Encodings 0xD5033F9F, 0xD5033FDF and
0xD50330FF, checked with GNU as 2.46.

Framework: Inline.dstOf and exec_gpr, and the taint step (no change) with
its soundness case. VerifiedGarbageTest.AArch64Barrier checks the
semantics, text, encodings, requirements and taint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
@reaperhulk

Copy link
Copy Markdown
Member Author

Replaced by #4483, which carries this change together with the other DIT TCB change, based on main so it can be reviewed and merged on its own. The branch stays, since the DIT stack above it still builds on it.

@reaperhulk reaperhulk closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant