Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,15 @@ The proof is staged so each level is useful by itself and later levels build on
- Scheduling contexts (MCS): SchedContext and SchedControl, budget checks, `set_priority`, and binding and unbinding SCs.
- VSpace: native frames and page tables, native-root ASID assignment, ASID pools and control, DeriveSubframe, with the VSpace cap-placement invariant (`VsMdbInv`). Guest-tagged pool entries stay occupied during allocation and are rejected by native lookup. `FrameLabel.native` excludes EPT mapping, and ASID-assignment leaves require a native extra cap.
- Endpoints and notifications: the IPC and signal paths are in progress. The native idle-bound notification leaf excludes a thread running a VM.
- VCPU / EPT (the extended spec `Fl4Spec/Ext/Virt*`), on the joint state `VmEptState` (P3's relation with the VCPU list, the VCPU images and the EPT tables): retype of all 19 object types, the decoded untyped invocation including reset; the EPT syscall suite through FL4's dispatcher (`TCBSetEPTRoot`, EPT table map and unmap, `X86PageMapEPT`, the unmap of an EPT-mapped frame, `X86ASIDPoolAssign` of an EPT root); the VCPU report and detach chain; the IO-port cap's owner (`ArchCap.ioPortCap` carries it, decision Q2) and its revoke, finalisation and delete; a final thread cap's finalisation (VCPU detach, then the native tail); and FL4's `delete(slot, true)` against `capDeleteVF` for every cap (`VmEptState.capDelete`, the deletion loop with zombies, swaps and preemption); and every CNode invocation (labels 25–32: Revoke, Delete, CancelBadgedSends, Copy, Mint, Move, Mutate, Rotate) through FL4's dispatcher against `invokeCnodeVF` (`VmEptState.cnodeDecodeAll`): an error leaves the state unchanged, an `Ok` outcome is back at `VmEptState`, a preempted Revoke or Delete keeps the VM side's pre-state facts (`CnAllPostVE`). Not proved yet: the VM-side `kernel_entry` wiring of `cnodeDecodeAll`.
- VCPU / EPT (the extended spec `Fl4Spec/Ext/Virt*`), on the joint state `VmEptState` (P3's relation with the VCPU list, the VCPU images and the EPT tables): retype of all 19 object types, the decoded untyped invocation including reset; the EPT syscall suite through FL4's dispatcher (`TCBSetEPTRoot`, EPT table map and unmap, `X86PageMapEPT`, the unmap of an EPT-mapped frame, `X86ASIDPoolAssign` of an EPT root); the VCPU report and detach chain; the IO-port cap's owner (`ArchCap.ioPortCap` carries it, decision Q2) and its revoke, finalisation and delete; a final thread cap's finalisation (VCPU detach, then the native tail); and FL4's `delete(slot, true)` against `capDeleteVF` for every cap (`VmEptState.capDelete`, the deletion loop with zombies, swaps and preemption); and every CNode invocation (labels 25–32: Revoke, Delete, CancelBadgedSends, Copy, Mint, Move, Mutate, Rotate) through FL4's dispatcher against `invokeCnodeVF` (`VmEptState.cnodeDecodeAll`): an error leaves the state unchanged, an `Ok` outcome is back at `VmEptState`, a preempted Revoke or Delete keeps the VM side's pre-state facts (`CnAllPostVE`).
- x86 VM Stage 2 reaches kernel entry. `VmEptState.decodeDisp` assembles the proved VM/EPT and common capability arms. The entry uses `VmEptState.dispatchAt`, which discharges the VCPU, EPT-table, EPT-mapped frame and owned I/O-port cap arms and takes the native-capability cases as a premise (`VDispNativeAt`). CNode, untyped, EPT-root assignment and SetEPTRoot have separate decode theorems, and their native-capability routing at entry is covered by that premise. `VmEptState.handleInvocationE` and `afterV` carry the invocation outcomes and preemption through the VM relation. `VmEptState.kernel_entry` composes the native syscall ABI paths with the dispatcher and VM-aware finish. The separate `vmEnterEntry`, `unknownSyscallEntry`, `trapSyscallEntry`, `interruptEntry`, `userExceptionEntry`, `vmFaultEntry`, `vcpuExitStalled` and `vcpuExitUnstalled` cover the other x86 core entry arms. They start from `VmEptState` and return a related extended-spec outcome at `VEAny`. The finish includes awakening, scheduling, activation and checking the current VCPU.
- Stage 2's [S] scope is the serial core entry after the gate, with one scheduling domain and the single-core IRQ view. Host interrupts use the native fresh-read `IrqHw` contract and `ValidIrqMasks`. Both fresh host and saved guest-exit vectors exclude remote-call IPI 126 and reschedule IPI 127. `VirtExitIrqF` covers an absent saved vector, active and inactive device lines, and saved non-IPI vectors above the device range. The trusted boundary includes entry/exit assembly, hardware guest execution, and the captured vector and VCPU image. Native syscall numbers are −11 through −1 with the trap flag clear. VMEnter (−23) requires a clear trap flag, an agreed enabled backend, and a bound VCPU. The ordinary unknown syscall theorem uses `UnkSys` (out-of-range number or set trap flag), `NoDbgSys` (excludes debug/TLS calls and requires a disabled backend or lack of a VCPU binding for −23), and the spec's ordinary-fault selection guard. Trap vectors are below 256 and follow FL4's zero-extended payload convention. The joint-state, native-capability, IPC and finish premises are listed in the entry and dispatcher modules.
- Hypotheses still to discharge are named in each file. The main ones: the state facts after the TCB fault-handler install, finalisation of a final Endpoint, Notification, Reply, Thread or SchedContext cap on the spec side (`FinWorkHyp`; FL4's side and the VSpace cases are proved), the reply and fault paths, and the placement link between P3's typed heap and P1's object sets.
- The proofs so far found no disagreement between FL4 and the spec.

### The abstract spec

Decided: we port seL4's Isabelle abstract specification (the MCS version, from `l4v/spec/abstract`) to Lean 4 as a nondeterministic state monad. It is long but close to a transliteration, and it keeps FL4 tied to the meaning the seL4 proofs have already validated. The semantic port covers the MCS native paths; non-MCS paths and IO page tables remain excluded. The cap and object representations include VCPU/EPT objects, and ASID pools retain guest tags as occupied entries while native lookup rejects them. VMEnter, SetEPTRoot, EPT mapping, guest-root ASID assignment, and the VCPU/EPT invocation families still need their own functional refinement; their extracted core functions are covered by P0. Where FL4 must differ, such as per-core state, the difference is written down in the spec and listed in one place.
Decided: we port seL4's Isabelle abstract specification (the MCS version, from `l4v/spec/abstract`) to Lean 4 as a nondeterministic state monad. It is long but close to a transliteration, and it keeps FL4 tied to the meaning the seL4 proofs have already validated. The semantic port covers the MCS native paths; non-MCS paths and IO page tables remain excluded. The cap and object representations include VCPU/EPT objects, and ASID pools retain guest tags as occupied entries while native lookup rejects them. The FL4 x86 extension supplies the VMEnter, SetEPTRoot, EPT mapping, guest-root ASID assignment, and VCPU/EPT operations used by the Stage 2 refinement over `VmEptState`. Its boundary and remaining hypotheses are listed above. Where FL4 must differ, such as per-core state, the difference is written down in the spec and listed in one place.

- The port goes subsystem by subsystem in P3 order. Each Lean definition carries a comment naming the Isabelle definition it comes from, so reviewers can compare them side by side.
- The Lean spec is executable where the Isabelle spec is deterministic. Those parts double as a reference model in the simulator and the differential fuzzer.
Expand Down
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,26 @@ syscalls through the dispatcher, the VCPU report and detach, the IO-port
cap's owner, revoke and delete, capability delete of every cap
(`VmEptState.capDelete`), and every CNode invocation (labels 25–32:
Revoke, Delete, CancelBadgedSends, Copy, Mint, Move, Mutate, Rotate) at
that state through FL4's dispatcher (`VmEptState.cnodeDecodeAll`); the
VM-side `kernel_entry` wiring of that dispatcher top is not proved yet
(DESIGN.md §9).
that state through FL4's dispatcher (`VmEptState.cnodeDecodeAll`).
Stage 2 proves the native x86 syscall entry and VM-aware scheduler
finish. The entry discharges the VM-specific capability routes and
takes the native-capability dispatcher cases as a premise. Separate
refinements cover VMEnter on VMX and SVM, ordinary unknown and trapped
syscalls, host interrupts, user exceptions, VM faults, and stalled and
unstalled VCPU exits. The proofs start from the joint VM state under
the entry and platform premises in [DESIGN.md §9](DESIGN.md#9-proof-plan).

The [S] scope is serial core entry after the gate, with one scheduling
domain and the single-core IRQ view. Assembly, hardware guest execution
and the capture of the VCPU image and vector lie at the trusted boundary.
Both fresh host and saved guest interrupt vectors exclude cross-core IPIs
126 and 127. The saved path covers no vector, active and inactive device
lines, and non-IPI vectors above the device range. Native syscall numbers
are −11 through −1 with the trap flag clear. VMEnter (−23) also requires
an agreed enabled backend and a bound VCPU. Ordinary unknown syscalls use
`UnkSys`, exclude debug/TLS calls, and require the spec to select the
ordinary fault case. Software-trap vectors are below 256 and use FL4's
zero-extended payload.

## x86 virtualization

Expand Down Expand Up @@ -331,9 +348,11 @@ most 3 words and at most 255 entries, which its only caller
leaf, extracting its address and removing the visibility bits recovers the
frame's aligned GPA. The store laws admit private and shared address masks.
The native l4v page and untyped refinements assume plain frame addresses.
The l4v semantic scope excludes SEV memory sharing, VMEnter, SetEPTRoot, EPT
mapping, guest-root ASID assignment, and VCPU/EPT refinement. The entry/exit
assembly and architecture backend are trusted. See [DESIGN.md §9](DESIGN.md#9-proof-plan) for the exact claims.
The x86 proofs refine VMEnter, SetEPTRoot, EPT mapping, guest-root ASID
assignment, and VCPU operations against FL4's extended specification.
SEV memory sharing is outside the native l4v refinement scope. The
entry/exit assembly, hardware guest execution, and the architecture
backend are trusted. See [DESIGN.md §9](DESIGN.md#9-proof-plan) for the exact claims.

Real-guest execution passes on AMD-V under QEMU/KVM, including SMP,
release, reduced-feature and no-PMU configurations. The retained Intel
Expand Down
15 changes: 15 additions & 0 deletions proofs/Fl4Proofs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ import Fl4Proofs.P3.XTopJointVsSub
import Fl4Proofs.P3.XTopJointMakePoolSpec
import Fl4Proofs.P3.XTopJointMakePool
import Fl4Proofs.P3.SpecPerfCur
import Fl4Proofs.P3.HandleTopG
import Fl4Proofs.P3.XTopJointEntry
import Fl4Proofs.P3.JEntryKs
import Fl4Proofs.P3.JEntryIrq
Expand Down Expand Up @@ -2816,6 +2817,20 @@ import Fl4Proofs.P3.VmCnodeVtxSpec
import Fl4Proofs.P3.VmCnodeVtx
import Fl4Proofs.P3.VmCnodeCp
import Fl4Proofs.P3.VmCnodeAll
import Fl4Proofs.P3.VmDisp
import Fl4Proofs.P3.VmHandle
import Fl4Proofs.P3.VmPerfCur
import Fl4Proofs.P3.VmHandleTop
import Fl4Proofs.P3.VmSignal
import Fl4Proofs.P3.VmOracle
import Fl4Proofs.P3.VmPerfRvm
import Fl4Proofs.P3.VmPreempt
import Fl4Proofs.P3.VmSchedule
import Fl4Proofs.P3.VmCheck
import Fl4Proofs.P3.VmFinish
import Fl4Proofs.P3.VmHiErr
import Fl4Proofs.P3.VmInvAfter
import Fl4Proofs.P3.VmKEntry
import Fl4Proofs.P3.NatFoot
import Fl4Proofs.P3.EptSetRoot
import Fl4Proofs.P3.EptSetRootDec
Expand Down
54 changes: 48 additions & 6 deletions proofs/Fl4Proofs/P1/QueueIpc.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,26 @@ def XferOK (st : machine.Store S) [L : LawfulStore st] {A : Type _} (ar : machin
SchedQueuesInvX st T Cs Ω H X s' Q R ∧ BoundInv st T Ac s' ∧ XInv st T Cs Ω Sg Rp Scs Nt Z s' ∧
SCsOK st T Ω Sg Scs Z Ac s' ∧ SgOK st Ω Sg s' ∧ XferFr st T Rp s s' ∧ G s' ⦄

/-- (mmuAD gen 42b77) **`XferOK` for one sender `snd`, without the guard after**: what `send_ipc` asks of the
transfer from its own sender (`endpoint.send_ipc.ipcT`). `XferOK.at` gives it for every sender of `T`. -/
def XferOKAt (st : machine.Store S) [L : LawfulStore st] {A : Type _} (ar : machine.Arch A)
(T Cs Ω : Set U64) (H : Heap) (Sg Rp Scs Nt : Set U64) (Z : U64 → Nat) (U : Set U64) (G : S → Prop)
(snd : U64) : Prop :=
∀ (Ac X : Set U64) (Q : U64 → U64 → List U64) (R : U64 → List U64) (s : S) (a : A) (ep badge : U64)
(grant : Bool) (rcv : U64), rcv ∈ T →
SchedQueuesInvX st T Cs Ω H X s Q R → BoundInv st T Ac s → XInv st T Cs Ω Sg Rp Scs Nt Z s →
SCsOK st T Ω Sg Scs Z Ac s → SgOK st Ω Sg s → UserOK st T Cs Ω H U s → G s →
ipc.do_ipc_transfer st ar s a snd ep badge grant rcv ⦃ s' =>
SchedQueuesInvX st T Cs Ω H X s' Q R ∧ BoundInv st T Ac s' ∧ XInv st T Cs Ω Sg Rp Scs Nt Z s' ∧
SCsOK st T Ω Sg Scs Z Ac s' ∧ SgOK st Ω Sg s' ∧ XferFr st T Rp s s' ⦄

theorem XferOK.at {A : Type _} {ar : machine.Arch A} {U : Set U64} {G : S → Prop}
(hxf : XferOK st ar T Cs Ω H Sg Rp Scs Nt Z U G) {snd : U64} (hs : snd ∈ T) :
XferOKAt st ar T Cs Ω H Sg Rp Scs Nt Z U G snd :=
fun Ac X Q R s a ep badge grant rcv hr h hB hX hS hSg hU hG =>
WP.spec_mono (hxf Ac X Q R s a snd ep badge grant rcv hs hr h hB hX hS hSg hU hG)
fun _ h' => ⟨h'.1, h'.2.1, h'.2.2.1, h'.2.2.2.1, h'.2.2.2.2.1, h'.2.2.2.2.2.1⟩

/-- seL4 `receiveIPC`'s end on a sending endpoint: the head sender is
dequeued, the message transferred, and the sender either becomes blocked on
the receiver's reply (a call, with the reply bookkeeping and SC donation),
Expand Down Expand Up @@ -3384,13 +3404,19 @@ runs. Caller-level preconditions: `t` can block (`CanBlock`: not blocked,
queued, the switch-to candidate or the idle thread), and if it may donate it
is bound (`hdon`): on the syscall path the sender is the current thread,
which has an SC in MCS, and on the fault path FL4 sets `can_donate` to
`t.sc != 0`. -/
theorem endpoint.send_ipc.ipc {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64}
{G : S → Prop} (hxf : XferOK st ar T Cs Ω H Sg Rp Scs Nt Z U G) (s : S) (a : A) (blocking do_call : Bool)
`t.sc != 0`. (mmuAD gen 42b77) The transfer asked only from the sender `t` (`XferOKAt`); (gen 42b77) its guard
`G` after the receiver's dequeue may use the dequeue's frame (every TCB word but the two queue links, the key-space
base); `send_ipc.ipc` is it by `XferOK.at`. -/
theorem endpoint.send_ipc.ipcT {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64}
{G : S → Prop} (s : S) (a : A) (blocking do_call : Bool)
(badge : U64) (can_grant can_grant_reply can_donate : Bool) (t e : U64)
(hxf : XferOKAt st ar T Cs Ω H Sg Rp Scs Nt Z U G t)
(Q : U64 → U64 → List U64) (R : U64 → List U64)
(hG : ∀ s1, H e = some .ep → (L.epState s e = 1#u64 ∨ L.epState s e = 2#u64) →
endpoint.ep_dequeue st s e (L.epQ s e).head = ok s1 → G s1)
endpoint.ep_dequeue st s e (L.epQ s e).head = ok s1 →
(∀ y ∈ T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 →
L.mem s1 (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) →
L.ksb s1 = L.ksb s → G s1)
(h : SchedQueuesInv st T Cs Ω H s Q R) (hB : BoundInv st T Ac s) (hX : XInv st T Cs Ω Sg Rp Scs Nt Z s)
(hS : SCsOK st T Ω Sg Scs Z Ac s) (hSg : SgOK st Ω Sg s) (hU : UserOK st T Cs Ω H U s)
(hc : CanBlock st T Ac s t) (hdon : can_donate = true → L.mem s (scA t) ≠ 0#u64)
Expand Down Expand Up @@ -3431,8 +3457,8 @@ theorem endpoint.send_ipc.ipc {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTo
obtain ⟨hB1, hX1, hS1, hSg1, ea1, ec1, ei1⟩ := frame_bx h hB hX hS hSg f1 o1 n1 k1
(TmFr.mk0 ⟨k1, fun y hy K a b c => f1 y hy K (by omega) c (by omega) (by omega),
fun c hc o ho => nc1 c hc o (by omega) (by omega), fun n' hn' => o1 _ (hSg.sub _ (hX.1.ntB n' hn').2)⟩)
refine WP.spec_bind (hxf _ _ _ _ s1 a t e badge can_grant hd ht hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) (hG s1 hH (Or.inr e0) eq1)) ?_
rintro s2 ⟨h2, hB2, hX2, hS2, hSg2, ⟨ea2, ec2, ei2, ecs2, f2, o2, -⟩, -⟩
refine WP.spec_bind (hxf _ _ _ _ s1 a e badge can_grant hd hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) (hG s1 hH (Or.inr e0) eq1 f1 k1)) ?_
rintro s2 ⟨h2, hB2, hX2, hS2, hSg2, ⟨ea2, ec2, ei2, ecs2, f2, o2, -⟩⟩
have F : ∀ y ∈ T, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 →
L.mem s2 (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K) :=
fun y hy K h0 hK hK8 h1' h2' => (f2 y hy K h0 hK hK8).trans (f1 y hy K hK hK8 h1' h2')
Expand Down Expand Up @@ -3606,6 +3632,22 @@ theorem endpoint.send_ipc.ipc {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTo
| exact Pdon (by assumption)
| exact Pok

/-- seL4 `sendIPC` keeps the invariants (statement before gen 42b77): `send_ipc.ipcT` with `XferOK.at`. -/
theorem endpoint.send_ipc.ipc {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64}
{G : S → Prop} (hxf : XferOK st ar T Cs Ω H Sg Rp Scs Nt Z U G) (s : S) (a : A) (blocking do_call : Bool)
(badge : U64) (can_grant can_grant_reply can_donate : Bool) (t e : U64)
(Q : U64 → U64 → List U64) (R : U64 → List U64)
(hG : ∀ s1, H e = some .ep → (L.epState s e = 1#u64 ∨ L.epState s e = 2#u64) →
endpoint.ep_dequeue st s e (L.epQ s e).head = ok s1 → G s1)
(h : SchedQueuesInv st T Cs Ω H s Q R) (hB : BoundInv st T Ac s) (hX : XInv st T Cs Ω Sg Rp Scs Nt Z s)
(hS : SCsOK st T Ω Sg Scs Z Ac s) (hSg : SgOK st Ω Sg s) (hU : UserOK st T Cs Ω H U s)
(hc : CanBlock st T Ac s t) (hdon : can_donate = true → L.mem s (scA t) ≠ 0#u64)
(hH : H e = some .ep) :
endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e
⦃ s' _ => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s' ⦄ :=
endpoint.send_ipc.ipcT hA s a blocking do_call badge can_grant can_grant_reply can_donate t e (hxf.at hc.mem) Q R
(fun s1 h1 h2 h3 _ _ => hG s1 h1 h2 h3) h hB hX hS hSg hU hc hdon hH

/-! ## `complete_signal` -/

theorem ntfn_idle_val0 : obj.NTFN_IDLE &&& 3#u64 = 0#u64 := by unfold obj.NTFN_IDLE; decide
Expand Down
Loading
Loading