Skip to content

AArch64: vg_dit_enter writes PSTATE.DIT only if it was off - #4328

Closed
reaperhulk wants to merge 1 commit into
claude/dit-mode-specfrom
claude/dit-skip
Closed

reaperhulk wants to merge 1 commit into
claude/dit-mode-specfrom
claude/dit-skip

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

vg_dit_enter now writes PSTATE.DIT only if it was off. It is stacked on the Spec change #4327, which is stacked on the TCB change #4326.

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

Proofs (Proof/Dit/AArch64.lean)

  • enter_leak: every run leaks exactly [.branch (!s.dit)].
  • Constant time: ConstantTime.of_leakage gives it under Spec.Dit.enterContract, whose pub now includes the mode (Spec/Dit: vg_dit_enter's contract makes the mode public #4327).
  • enter_wp and enter_dit: unchanged in meaning. Afterwards DIT is on, and x0 holds its old value.

Rust

No changes. src/dit.rs already calls vg_dit_clear only when vg_dit_enter returned 0. So when DIT is already on, an operation now costs one mrs and no msr. The existing test dit::tests::enter_and_clear calls vg_dit_enter with DIT both on and off, so it runs both paths. It passes under QEMU with -cpu max; with -cpu cortex-a72, which lacks FEAT_DIT, the code is never called.

What it does not speed up

It only helps when DIT is already on, for example when the application turns it on for the whole thread. #4210 never nests guards, so a library operation called with DIT off still pays one write to turn it on and one to turn it off.

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Member Author

Folded into #4168, which now carries the AArch64 implementation with the skip-write. The DIT stack is now four PRs: #4157 (Spec, merged), #4168, #4210, #4357.

@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

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

1 participant