Skip to content

P3 (aarch64): kernel-entry refinement over the syscall, fault and VM-exit entries, with a mechanized non-vacuity witness (Stage 3) - #155

Merged
losfair merged 1 commit into
losfair:mainfrom
CommaBot:a64-p3-stage3
Dec 5, 2026

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Stage 3 of the AArch64 P3 refinement proof: FL4's slow-path kernel entries refine the spec's call_kernel body, end to end
from the entry's kBodyA through syscall.finish, for the system-call groups listed below, the fault and VM-exit entries
and the preempted exit. No Rust or extraction change: the PR changes proofs/Fl4ProofsA64/**, proofs/Fl4SpecA64/** (see "Spec port changes"), DESIGN.md §9 and README.md. It is based on main 82371d591 (#154 included: lift3 merges main).
Everything is stated against the Aeneas extraction (Fl4CoreA64) and the AArch64 spec port (Fl4SpecA64), which this PR also extends (see "Spec port changes").

What it proves (top theorems, proofs/Fl4ProofsA64/P3/)

Theorem File Statement
kernelEntry_stage3A Stage3KEntryTopA the composition lemma (body + finish): if the body refines kOpA and leaves the record, and finish is the producer's (hfin), then the entry refines kOpA >>= fl4Finish and the next record (KExitA) holds
kernelEntry_recGA Stage3SysTopA the same for bodies that change the ghost sets (system calls, VM exits): the ghost sets float existentially in A64RelS3
kernelEntry_recA (+ userException_recFinA, vmFault_recFinA, unknownSyscall_recFinA) Stage3KEntryFaultFinA the three fault entries with finish discharged
kernelEntrySend_recGA / syscallSend_refinesA Stage3SysSendA Send, NBSend, Call
kernelEntryRecv_recGA / syscallRecv_refinesA Stage3SysRecvA Recv, NBRecv, Wait, NBWait
kernelEntryComb_recGA / syscallComb_refinesA Stage3SysCombA ReplyRecv, NBSendRecv, NBSendWait
kernelEntry_runExitA, kernelEntry_runVppiA Stage3VcpuExitWireA the VM-exit entries end to end
JSyscallA.dispatchA Stage3DispTopA the invocation dispatch over the groups below
afterPreemptA, hPre_ofA, HPreA.ofEnv Stage3AfterPreemptA, Stage3HPreA the preempted exit (after_invocation (.Err .Preempted)), the callers' hPre discharged from HPreEnvA
JSyscallA.decErrSpecA, JSyscallA.sendBodyErrAllA Stage3DecErrAllA, Stage3SendErrAllA decode errors closed (all Err arms of decode, hSpec discharged)
JSyscallA.setIpcBufZeroA, JSyscallA.setIpcBufNzA Stage3LiftTcbBufA, Stage3LiftTcbBufNzA, Stage3TcbReschedA TCB SetIPCBuffer: zero and non-zero addresses, any target thread (the current thread included, with its reschedule_required), non-device Frame source; a device-frame source or a misaligned / invalid buffer is a decode error (DecErrSpecPA.thread, decErrSpecA, sendBodyErrAllA)
RecvPreA.recvPushUnbA, RecvPreA.recvSendUnbA, RecvPreA.unbCoreA Stage3RecvUnbArmA, Stage3RecvPushCancelA, Stage3RecvSendA the blocking receive of a passive receiver (BndUnbA) against a waiting sender, with or without a reply push; a reply object linked to another thread is cancelled first (case B of take_reply), so the receive scope no longer assumes an unlinked reply object

Dispatch groups (DispScopeA, Stage3DispTopA): CNode, VSpace, IPC, SchedContext, TCB, cache maintenance, IRQ (IRQAck,
IRQSetHandler, IRQClearHandler), one-word reply (ARMPageGetAddress, ARMPageTestAndClearAccessed), Domain (DomainSetSet), VCPU (labels 60–69, body/dispatch level: VcpuScopeA), and the non-arch Err group.
Not covered ([S] scope limits, see DESIGN §9): Untyped Retype / RetypeShared (UtScopeA has no constructor), TCB Configure / SetSpace / Read-, Write-, CopyRegisters / SetTimer / SetHighVSpace / breakpoints and single stepping, the SetSchedParams cases with a changed SC or another handler cap kind, DomainSchedule*, ARMASIDControlMakePool, ARMPageDeriveSubframe, Stage-2 and high-window map extensions, the T2 unmap shrink, Notification send to a bound thread running a VCPU. An uncovered invocation whose decode succeeds makes the top's scope premise false at that state.
The interrupt entry arm is proved (interrupt_serviceA, Stage3KEntryIrqA) but is not assembled into a top yet.
Spec side FinWorkHyp, reply and fault paths: see the DESIGN §9 text for what stays [J].

Named premises at the tops

Every premise is a named hypothesis or record field with a tag in its docstring; none is sorry/axiom. Axioms (#print axioms over all 2,454 modules): propext, Classical.choice, Quot.sound.

  • [P] platform, architecture and fl4-sync facts: ArchTotal, MaxSpi, ArchPlat, IrqPlatA (maxSpi only), FaultEnvA (hCs, h1, hmb, hmax, htu), FinPlatA (arK, toUs, hmax, htu), ArchSwFA (backend realizes ordered root writes and the per-core register view), the four preemption-path agreements (hlimit, hag, hconv, GICv2 v2), PlainStore, A64FrameMasks, IrqArchA and hMax (maxIRQ = 5375), SchedGapFreeA's minAgree and ticks (hGap, below), PollAgreeA (the poll; since aarch64: Defer EL2 guest PPIs to IRQ entry #154 it carries the clause that a polled line is never a VGIC-maintenance or vppi-event line: aarch64: Defer EL2 guest PPIs to IRQ entry #154).
  • [J] facts about the entry state (the record), each guarded by the reached state: hGap = SchedGapFreeA at the body's reached record (Stage3SysTopA): [S] oneDomain, [P] minAgree (fl4MinBudget = MIN_BUDGET), [P] ticks (ScCfgTimeAgreeA), [J] timer (the schedule-timer inputs and SniHypA after switch_sched_context, guarded by the run awaken → select → switch; the witness discharges hGap, wit2b_hGapA, at any record state);
    JSyscallA / JStage3A (the syscall-entry record), JStage3EntryA and EntryBaseA (current-thread, idle and clock facts), VcpuEntryA (a guest entry), SysChargeA (the budget-exhausted branch after the FAULT_IP write), hSend / SendPA (the timeout send without a waiting receiver, guarded by the run that reaches the preempted state), IrqLineBaseA (active), NdOKA (domain-schedule words, including the node-count word NUM_NODES = numNodes: F1).
  • [S] declared scope limits: numNodes = 1, oneDomain/numDomains = 1, hCs, noResched, the receive scope limits E1–E6, N1, N2, the cap-fault handler endpoint and ntfnSc = curSc (Stage3RecvScopeA), the combined-call limit F2/F3 (Stage3SysCombA), the reserved clause of the interrupt entry's IrqLineA, and the faulted-caller Reply form (JSyscallA.replyFaultA, fault_w1 = 0 / short UnknownSyscall).
  • [S4] deferred to the guest-lifecycle follow-up: hNative / hNat (a finish after which the current thread runs no guest: an ARMVCPU_Run that resumes the guest is outside the top) and the guest entries vgic, vppi, vcpuExit, vcpuFault.
  • witness-world [P] OpaqueWA (P3/A64Wit2ArchA), the only hypothesis of the non-vacuity witness wit_send_nonvacuous: facts about opaque spec constants that no Lean term proves or refutes (any value of the constant's type is a model; P3/A64Wit2PlatA gives the model values): one domain, maxIRQ = 5375, GICv2, numNodes = 1, maxTicksToUs = U64::MAX, kernel WCET 10 µs, 1000 ticks per timer unit, timer unit 1, a 10^9 Hz counter, fl4MaxPeriodUs = MAX_PERIOD_US, a monotone raw counter; and two properties of the witness world, not of FL4's platform: irq (the IRQ oracle only yields the VGIC maintenance line, a non-kernel IRQ) and hNow (the spec's clock and the raw counter agree at a state whose last observation is the next raw sample; both oracles are 0). It is not a premise of any top theorem.

Non-vacuity

A witness gate was run against the tops: a concrete store, arch and spec state satisfying every premise of kernelEntrySend_recGA (par/a64-p3-wit for plan B; par/a64-p3-wit2 + par/a64-p3-archsw for the mechanized one). It found nine problems, all fixed:

Problem Fix
U1 IrqPlatA.nodes was a ∀ over all store states on a memory word, unsatisfiable F1 17b9eca13: dropped; NUM_NODES = numNodes is a record fact (NdOKA.nodes) kept by every write set
U2 Send/NBSend/Call hScope was an unpinned ∀ over JSyscallA states dedupe C aca88db91: pinned like Recv/Comb by the three entry equations (fl4SyscallFaultIP, post-write budget_ok, fl4BudgetOk)
U3 HPreEnvA.hSend was guarded by the relation, not the run dedupe C: guarded by DispatchInvokeAtA ∧ handle_invocation = ok (.Err .Preempted …)
U4 the old model arch contradicted FaultEnvA a new model arch (P3/A64Wit2ArchA) that satisfies FaultEnvA, NowAgreeA, FinPlatA and the platform agreements (ArchTotal, MaxSpi, ArchPlat, IrqArchA, SniHypA, ArRootKeepA)
U5 ArchSwFA had no inhabitant par/a64-p3-archsw + archsw2 (2c3b1c72e): A64ArchSwA–H; witArchSwOf : ArchSwFA st AR1 is unconditional (P3/A64ArchSwH), proving set_vm_root / set_kernel_vm_root against threadRootWritesA / kernelRootWritesA on core 0
U6 KERNEL_ROOT tie between the record and ArchSwFA F4 0c232114b: KERNEL_ROOT is a record fact (NdOKA.kroot, JStage3A.kroot); ArchSwFA.exec* take it from the record (ArchTieA)
U7 ArchSwFA's ∀ core quantifier unsatisfiable multicore guard fields with (L.cpu s).val = 0, callers discharge it from the record (numNodes = 1); the SMP note is in §9
U8 Z.Y ∌ 0 antecedent of ArchSwFA.exec*, derived from the record (F4: h0 : H 0 = none + Z.Y membership)
U9 RunLinkA antecedent of ArchSwFA.exec*, derived from the record (F4: VcRunA.run / .vtcb)

Also the premise dedupe (b17d946aa, aca88db91): reserved moved from [S] to a [P] clause of PollAgreeA on the preemption path, SendPA guarded at the reached record (no ∀ over records), ExitPlatA replaces the platform facts HPreEnvA copied from FaultEnvA, EntryBaseA shared by VcpuEntryA and JStage3EntryA.
Mechanized witness: Wit.wit_send_nonvacuous (P3/A64Wit2TopA): for the model arch and the w1 boot state it exhibits a store, an arch state, a spec state and the ghost sets satisfying every premise of kernelEntrySend_recGA (SendEntryHyps is the theorem's binder list), with witArchSwOf as the ArchSwFA; wit_top_send also derives the theorem's conclusion there. Everything is existential except OpaqueWA (witness-world [P]). The witness covers the Send/NBSend/Call top (CNode Copy at w1); the Recv, Comb and VM-exit tops share its platform premises but are not instantiated.

Declared limits (DESIGN §9, "AArch64 P3 Stage 3")

Stage-4 ([S4]) list above; single-core ArchSwFA (U7: per-core guard (L.cpu s).val = 0; multicore is not claimed); OpaqueWA (the witness world; not a premise of any top); still open within Stage 3 and marked in progress, not as limits: the interrupt top assembly and the shared IrqEnvA dedupe.

Spec port changes (proofs/Fl4SpecA64/**, 27 files, +2,451/−260 vs main)

The PR also changes the AArch64 spec port, which PORTING.md documents (generations 6, 7, 8; each change has an Architect ruling there).
New Ext/* modules (FL4 differences from l4v, outside the port): Ext/FaultReply (FL4's reply to a fault: the Timeout reply register order, sanitise_vcpu_spsr), Ext/IrqSignal (a signalled IRQ is masked and ack unmasks it, whatever the GIC version), Ext/Reply (reply budget and timeout delivery with FL4's minimum and counter conversion), Ext/SchedBudget and Ext/SchedControl (the platform release-time limit and the minimum in counter ticks), Ext/SchedTail (the schedule and reprogram decision, the timer view), Ext/Timestamp (the raw counter as the clock, CNTPCT_EL0 / CNTVCT_EL0), Ext/UntypedVirt (the untyped decode's virtualization check), Ext/UserTop (fl4UserVtop). Modified Ext/* modules: ARMVCPURun, ArchTypes, Entry, Finalise, Invocation, IrqControl, Stage2, Tcb, Timer, VSpace.
In-port hooks (one-line -- FL4 hook changes inside the l4v-derived modules; all documented in PORTING.md):

File Generation Change PORTING.md
AARCH64/Structs.lean 6 the frame functions' arms for a Stage-2 frame cap (acap_rights, acap_fsize, acap_is_device, acap_map_data, update_map_data, arch_cap_is_device, acap_rights_update) "The frame hooks (generation 6)", table ll. 369–372
AARCH64/VSpace.lean 6 is_FrameCap, arch_derive_cap, arch_same_region_as, same_aobject_as for a Stage-2 frame ll. 353–354, 368, 373–375
AARCH64/VSpace.lean 7 find_vspace_for_asid hides FL4's Stage-2 and high roots (the vspaceOpt filter) "Two FL4 hooks (generation 7)"
Machine.lean 7 userVtop := fl4UserVtop: FL4's USER_TOP (2^47 − 1), not l4v's pptrUserTop (a difference in value, not in shape: FL4's AArch64 kernel runs at EL1 with a 48-bit Stage-1 user half, l4v's AARCH64 at EL2) same section
Decode.lean 8 decode_vs_inv_flush compares end with userVtop (FL4 vspace.rs 933 uses USER_TOP) same section, generation 8
AARCH64/Arch.lean, AARCH64/VCPU.lean, AARCH64/VSpace.lean transcription fix non-tail return () → pure () at 3 + 5 + 1 sites (Lean do return is an early exit; Isabelle's is a no-op); not a semantic extension "No non-tail return ()" (l. 55) and the VCPU fixes (l. 750)

The semantic one to review is userVtop: it makes the l4v decoders decode_fr_inv_map, decode_pt_inv_map and decode_vs_inv_flush reject exactly what FL4's decode_page_map, decode_page_table and the flush decode reject.

Kernel-change dependency

losfair/FL4#154 (82371d591, on main; lift3 contains it): after it, the preemption-point poll leaves the EL2 VGIC-maintenance and virtual-timer PPIs pending (like REMOTE_CALL), so a polled line is never reserved. The proof takes this as the [P] clause of PollAgreeA; it is false against a kernel without #154.

Build and reproduce

At 0a29cfba1 (the last Lean change; later commits touch only docs, files and one docstring, with a MODE=mod check of Stage3SysTopA): root Fl4ProofsA64 Build completed successfully (8671 jobs), 0 errors, 0 sorry, no skipped jobs. Axiom audit over all 2,468 modules / 131,253 declarations: [propext, Classical.choice, Quot.sound] (AX_EXIT 0).
Reproduce: cd proofs && lake build Fl4ProofsA64, then a file with import Fl4ProofsA64, a DFS over env.constants collecting axioms (as proofs/scratch/a64/…_ax.lean did; kept out of the PR) or #print axioms Fl4ProofsA64.P3.JSyscallA.dispatchA / …Sched.kernelEntry_stage3A / …kernelEntryComb_recGA / …hPre_ofA.
CI note: the gate workflow re-extracts and checks only x86_64; this tree is checked by lake build Fl4ProofsA64 (README).

Size

git diff --shortstat 82371d591 643ec103a: 1277 files changed, 417,297 insertions(+), 419 deletions(−): proofs/Fl4ProofsA64/** 1,247 files, +413,569/−82 (1,228 new files, mostly new modules); proofs/Fl4SpecA64/** 27 files, +2,451/−260; DESIGN.md, README.md. No file outside proofs/ other than those two; crates/ and xtask/ are identical to main. No proofs/scratch file differs from main.
The PR carries the whole AArch64 P3 tree that is not on main yet: about 414k lines under proofs/Fl4ProofsA64/**, almost all of it new modules, plus the DESIGN.md §9 / README.md status. It is one combined PR for the stage and is published as one CommaBot commit (git commit-tree <lift3 tip>^{tree} -p <main>).

Review notes

Every merge into par/a64-p3-lift3 was built with the root Fl4ProofsA64 plus an axiom audit; the numbers above are the last full root build + AX, which ran at 0a29cfba1; the commits after it (merge of main 82371d591, removal of five stray files, docstring tags on SchedGapFreeA, docs) are Rust-only, docs, files and one docstring (MODE=mod of Stage3SysTopA: 7,160 jobs, 0 errors).

🤖 Generated with Claude Code

…exit entries, with a mechanized non-vacuity witness (Stage 3)

Stage 3 of the AArch64 P3 refinement proof (Lean 4, `proofs/Fl4ProofsA64`): FL4's slow-path
kernel entries refine the spec's `call_kernel` body from `kBodyA` through `syscall.finish`, for
the syscall dispatch groups, the fault and VM-exit entries, the preempted exit and decode errors.
Every hypothesis is a named premise tagged [P]/[J]/[S]/[S4], and `kernelEntrySend_recGA`'s
premises are shown jointly satisfiable (`wit_send_nonvacuous`, under the witness-world
hypothesis `OpaqueWA`).

Also extends the AArch64 spec port (`proofs/Fl4SpecA64`, documented in its PORTING.md), updates
DESIGN.md section 9 and the README status, and relies on losfair#154 (already on main). No Rust or
extraction change. Root `lake build Fl4ProofsA64` (last full build at the witness merge; later commits are docs and the losfair#154 merge): 8671 jobs, 0 errors, 0 sorry; axioms:
propext, Classical.choice, Quot.sound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants