Skip to content

AArch64: vg_dit_enter and vg_dit_clear, with their effect on PSTATE.DIT proven - #4168

Merged
reaperhulk merged 5 commits into
mainfrom
claude/vigilant-cori-v8lf1d-impl
Nov 7, 2026
Merged

reaperhulk merged 5 commits into
mainfrom
claude/vigilant-cori-v8lf1d-impl

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

The AArch64 implementation of vg_dit_enter and vg_dit_clear, against the spec merged in #4157. It changes nothing in TCB/ or Spec/. It now also includes the change from #4328 (closed): vg_dit_enter writes PSTATE.DIT only if it was off.

The DIT stack is now four PRs: #4157 (Spec, merged), this PR, #4210 (the Dit tokens), and #4543 (dit::scope and the speculation barrier on Apple's targets).

The code (Impl/Dit/AArch64.lean)

vg_dit_enter:

mrs   x0, DIT
lsr   x0, x0, #24
cbz   x0, 1f      // off: turn it on
b     2f
1: msr DIT, #1
2: ret

vg_dit_clear: msr DIT, #0; ret.

The emitted words are in crates/verified-garbage-asm-aarch64/src/dit.rs, and their text is in assembly/dit.s. vg_dit_enter needs FEAT_DIT, so the emitter gives it no dispatcher.

The proofs (Proof/Dit/AArch64.lean)

  • enter_verified, clear_verified: the spec's contracts, like every artifact's: no memory written, the calling convention's preserved state kept, constant time. vg_dit_enter's contract makes the mode public (pubMode, Spec: vg_dit_enter and vg_dit_clear, entering and leaving data independent timing #4157).
  • enter_leak: every run of vg_dit_enter leaks exactly [.branch (!s.dit)]. So ConstantTime.of_leakage gives constant time under that contract.
  • enter_dit, clear_dit: what the contracts can't name.
    • Every run of vg_dit_enter ends with PSTATE.DIT on, and x0 is 1 if DIT was on and 0 if it was off.
    • Every run of vg_dit_clear ends with DIT off.
    • Both hold from any starting state, and of every run (Exec.det).

The registration (Artifacts/Dit/AArch64.lean) binds the code and its proofs with features := ["dit"].

Rust

  • Feature bit: feature::DIT, bit 21 in verified-garbage-cpu, which the generated VG_DIT_*_FEATURES name.
  • Detection: crates/verified-garbage-cpu/src/detect.rs, where main now detects features, uses is_aarch64_feature_detected!("dit"). Without std it uses the target's dit feature, which aarch64-apple-darwin enables and aarch64-unknown-linux-gnu doesn't. VG_CPU_FEATURES accepts dit.
  • Test: for now src/dit.rs holds only a test that runs both functions on the CPU. It checks that entering turns DIT on and reports whether it was on, that entering again with DIT on (the path without the write) reports 1, and that clearing turns it off. The new dit group in ci/cpu_tests.py runs it on the AArch64 runner unrestricted, and under none, where it calls neither function.
  • Not yet: the Guard and the Dit token arrive with their callers in Rust: every verified function takes a Dit token #4210, so this PR adds no unused code.

Checked locally (on main after #4157 merged)

  • Lean: the full lake build, Emit.lean and Emit.lean --check (only dit.rs, dit.s and the crate's module list change), the import, module, registration, speed, variant, arch-gate, vector and MCDT checks, and cpu_tests.py lint.
  • Rust: cargo fmt --check and clippy --all-targets --features cpu-features-env -D warnings for the host, aarch64-unknown-linux-gnu and aarch64-apple-darwin; the host's cpu tests.
  • Under QEMU: the dit and cpu tests pass with -cpu max (FEAT_DIT) and -cpu cortex-a72 (no FEAT_DIT, where the test calls neither function).

🤖 Generated with Claude Code

https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with claude/vigilant-cori-v8lf1d, found after d6762a2 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

Base automatically changed from claude/vigilant-cori-v8lf1d to main November 7, 2026 19:54
claude and others added 5 commits November 7, 2026 19:57
…IT proven

The code (`Impl/Dit/AArch64.lean`):

* `vg_dit_enter`: `mrs x0, DIT; lsr x0, x0, #24; msr DIT, #1; ret`
* `vg_dit_clear`: `msr DIT, #0; ret`

The proofs (`Proof/Dit/AArch64.lean`):

* `enter_verified`, `clear_verified`: the spec's contracts (no memory
  written, the calling convention's preserved state kept, constant time),
  like every artifact's.
* `enter_dit`, `clear_dit`: what those contracts cannot name. Every run of
  `vg_dit_enter` in the model ends with PSTATE.DIT on and `x0` 1 if it was
  on and 0 if it was off; every run of `vg_dit_clear` ends with it off. They
  hold of every run (`Exec.det`), from any state.

Registered with `features := ["dit"]` (`Artifacts/Dit/AArch64.lean`); the
regenerated crate gains `dit.rs`, whose `VG_DIT_*_FEATURES` name the new
`feature::DIT` (bit 21 of `verified-garbage-cpu`), which `src/cpu.rs` detects
with `is_aarch64_feature_detected!("dit")` (or, without `std`, the target's
`dit` feature, which `aarch64-apple-darwin` has) and `VG_CPU_FEATURES` can
name.

`src/dit.rs` holds, for now, only a test that runs the two functions on the
CPU: entering reports the mode and turns it on, clearing turns it off. The
`dit` group runs it on the AArch64 runner unrestricted (with FEAT_DIT) and
under `none` (without it, where it calls neither). The guard that uses them
comes with its callers, in the next PR. `RegUpd.dit_write` is the frame lemma
of the new field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWyoNrCuvSgWWUoNG6S
CI's coverage left the closing brace of `if was == 0` uncovered: every
runner starts the test's thread with PSTATE.DIT off, so the branch's false
side never ran. The test now ends with `vg_dit_clear` whatever the mode was,
which needs no branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWyoNrCuvSgWWUoNG6S
…ions now do

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
`mrs`, then `cbz` past the `msr` when data independent timing is already on.
Its contract makes the mode public (`Spec/Dit.lean`), and the proof shows
that it leaks only whether the mode was off (`enter_leak`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
@reaperhulk
reaperhulk force-pushed the claude/vigilant-cori-v8lf1d-impl branch from 118378d to ebbe51c Compare November 7, 2026 20:32
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 6139f0b Nov 7, 2026
53 checks passed
@reaperhulk
reaperhulk deleted the claude/vigilant-cori-v8lf1d-impl branch November 7, 2026 21:23
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.

2 participants