diff --git a/DESIGN.md b/DESIGN.md index cf68d478f..9b8c292fa 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -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. diff --git a/README.md b/README.md index 8a8305c61..d2c24ed56 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/proofs/Fl4Proofs.lean b/proofs/Fl4Proofs.lean index c164ed5ea..245e8d981 100644 --- a/proofs/Fl4Proofs.lean +++ b/proofs/Fl4Proofs.lean @@ -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 @@ -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 diff --git a/proofs/Fl4Proofs/P1/QueueIpc.lean b/proofs/Fl4Proofs/P1/QueueIpc.lean index 1189f8df8..8ab97ae30 100644 --- a/proofs/Fl4Proofs/P1/QueueIpc.lean +++ b/proofs/Fl4Proofs/P1/QueueIpc.lean @@ -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), @@ -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) @@ -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') @@ -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 diff --git a/proofs/Fl4Proofs/P1/QueueRecv.lean b/proofs/Fl4Proofs/P1/QueueRecv.lean index bd2cdf8e2..7b1aed7ac 100644 --- a/proofs/Fl4Proofs/P1/QueueRecv.lean +++ b/proofs/Fl4Proofs/P1/QueueRecv.lean @@ -367,10 +367,11 @@ theorem faults.set_fault.blk {U : Set U64} (s : S) (t : obj.Tcb) (f : error.Faul /-- seL4 `handleTimeout`: the fault goes to the thread's timeout handler as a fault IPC (`send_fault_ipc`, no donation), if the handler cap is an endpoint. From the hypotheses at the call: the handler cap is typed, the -thread can block, `UserOK` and `XferOK`. -/ -theorem faults.handle_timeout.bxi {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) {Ac : Set U64} (s : S) (a : A) (t : obj.Tcb) - (f : error.Fault) +thread can block, `UserOK` and `XferOK`. (mmuAD gen 42b77) The transfer asked only from the faulting thread `t` +(`XferOKAt`); `handle_timeout.bxi` is it by `XferOK.at`. -/ +theorem faults.handle_timeout.bxiT {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64} + {G : S → Prop} {Ac : Set U64} (s : S) (a : A) (t : obj.Tcb) + (f : error.Fault) (hxf : XferOKAt st ar T Cs Ω H Sg Rp Scs Nt Z U G t) (hG : FaultG st H G s t f) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) (hU : UserOK st T Cs Ω H U s) (hc : CanBlock st T Ac s t) (hcap : obj.Tcb.slot t layout.tcb.SLOT_TIMEOUT_HANDLER ⦃ sl => @@ -389,13 +390,26 @@ theorem faults.handle_timeout.bxi {A : Type _} {ar : machine.Arch A} (hA : P0.Ar refine WP.spec_bind (spec_eq' (faults.set_fault.blk s t f h ht hU hc)) ?_ rintro s1 ⟨eq1, h1, hU1, hc1⟩ obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := h1 - refine WP.spec_bind (endpoint.send_ipc.ipc hA hxf s1 a true false b g gr false t p Q1 R1 (fun s2 => hG s1 p s2 eq1) q1 hB1 hX1 hS1 hSg1 + refine WP.spec_bind (endpoint.send_ipc.ipcT hA s1 a true false b g gr false t p hxf Q1 R1 + (fun s2 h1 h2 h3 _ _ => hG s1 p s2 eq1 h1 h2 h3) q1 hB1 hX1 hS1 hSg1 hU1 hc1 (fun e => by cases e) hpH) ?_ rintro ⟨s2, a1⟩ h2 exact (WP.spec_ok _).2 (by simpa using h2) · rintro ⟨x, s2, a2⟩ h2 exact (WP.spec_ok _).2 h2 +/-- seL4 `handleTimeout` keeps the invariants (statement before gen 42b77): `handle_timeout.bxiT` with +`XferOK.at`. -/ +theorem faults.handle_timeout.bxi {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) {Ac : Set U64} (s : S) (a : A) (t : obj.Tcb) + (f : error.Fault) + (hG : FaultG st H G s t f) + (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) (hU : UserOK st T Cs Ω H U s) (hc : CanBlock st T Ac s t) + (hcap : obj.Tcb.slot t layout.tcb.SLOT_TIMEOUT_HANDLER ⦃ sl => + obj.Slot.cap st sl s ⦃ c => CapTyped H Rp Nt c ⦄ ⦄) : + faults.handle_timeout st ar s a t f ⦃ s' _ => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s' ⦄ := + faults.handle_timeout.bxiT hA s a t f (hxf.at hc.mem) hG h hU hc hcap + /-- `set_fault` writes only `t`'s fault and lookup-failure fields, so every thread's `SC` field is kept. -/ diff --git a/proofs/Fl4Proofs/P1/QueueXfer.lean b/proofs/Fl4Proofs/P1/QueueXfer.lean index d95a72772..a852be509 100644 --- a/proofs/Fl4Proofs/P1/QueueXfer.lean +++ b/proofs/Fl4Proofs/P1/QueueXfer.lean @@ -695,6 +695,25 @@ theorem xferOK_of {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (E : exact ipc.do_normal_transfer.xs E h0 hs hr hb hG · exact ipc.do_fault_transfer.xs hA h0 hs hr hb +/-- (mmuAD gen 42b77) **The transfer from a faulting sender keeps the invariants within `XferFr`**, premise-free: +the receiver's buffer by `BufAt`, the fault branch by the sender's fault type (not `NullFault`), then +`do_fault_transfer.xs` (`xferOK_of`'s fault branch). -/ +theorem xferOKAt_fault {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64} {snd : U64} + (hs : snd ∈ T) : + XferOKAt st ar T Cs Ω H Sg Rp Scs Nt Z U (fun s => BufAt st T Cs H Sg Scs Z U s ∧ + obj.Tcb.fault_type st snd s ⦃ i => i ≠ fl4_abi.consts.fault.NullFault ⦄) snd := by + intro Ac X Q R s a ep badge grant rcv hr h hB hX hS hSg hU hG0 + obtain ⟨hBA, hft⟩ := hG0 + have h0 : XS st T Cs Ω H Sg Rp Scs Nt Z U Ac X Q R s s := XS.start ⟨h, hB, hX, hS, hSg, hU⟩ + refine WP.spec_mono (P₀ := fun s' => XS st T Cs Ω H Sg Rp Scs Nt Z U Ac X Q R s s') ?_ + fun s' h'' => ⟨h''.1.1, h''.1.2.1, h''.1.2.2.1, h''.1.2.2.2.1, h''.1.2.2.2.2.1, h''.fr⟩ + unfold ipc.do_ipc_transfer + refine WP.spec_bind (hBA.2 rcv hr) fun rb hb => ?_ + refine WP.spec_bind hft fun ft hft' => ?_ + split + · exact absurd (by assumption) hft' + · exact ipc.do_fault_transfer.xs hA h0 hs hr hb + end end Fl4Proofs.P1 diff --git a/proofs/Fl4Proofs/P2/FootN3.lean b/proofs/Fl4Proofs/P2/FootN3.lean index 4f9e62cfa..c958b958d 100644 --- a/proofs/Fl4Proofs/P2/FootN3.lean +++ b/proofs/Fl4Proofs/P2/FootN3.lean @@ -8,6 +8,11 @@ the timeout faults keep it (P1's `TmoKG`, unchanged). With `G` = "an `IpcW` footprint from the start without node identity words" (`P2/FootN5.lean`) this is the budget path's frame: no core's idle words, no other core's current thread, action or current SC are written. No premise. + +(mmuAD gen 42b74) **`TmoKCv`**: the timeout faults are asked only where `end_timeslice` raises one (the current SC +not round-robin, its period kept from the start, the current thread's timeout handler valid, `can_timeout_fault`): +`end_timeslice.allGNv`, `charge_budget.allGNv` (`htmo` only when `can_timeout_fault`), `check_budget.allGNv`; the +`allGN` names are their `TmoKC` corollaries (`TmoKC.v`), statements unchanged. -/ import Fl4Proofs.P2.FootN2 import Fl4Proofs.P1.QueueBudgetG @@ -83,14 +88,35 @@ def TmoKC (st : machine.Store S) [L : LawfulStore st] {A : Type _} (ar : machine SCsOK st T Ω Sg Scs Z Ac s → WritesIn st s0 s (ChgW st Scs Z s0) → CurOK st T s → G s → faults.handle_timeout st ar s a (L.curW s) (error.Fault.Timeout f) ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ -/-- seL4 `endTimeslice` (`KWN` frame). -/ -theorem sched.end_timeslice.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (cto : Bool) +/-- (mmuAD gen 42b74) **`TmoKC` asked only where `end_timeslice` raises the fault**: at a state `s` reached from `s0` +by `ChgW` writes with the current SC's period kept, the SC not round-robin (`PERIOD ≠ 0`) and the current thread's +timeout handler valid (an endpoint cap). `TmoKC.v`: `TmoKC` gives it. -/ +def TmoKCv (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) (Ac : Set U64) (s0 : S) (G : S → Prop) : Prop := + ∀ (s : S) (a : A) (f : U64) (Q : U64 → U64 → List U64) (R : U64 → List U64), + SchedQueuesInv st T Cs Ω H s Q R → BoundInv st T Ac s → XInv st T Cs Ω Sg Rp Scs Nt Z s → SgOK st Ω Sg s → + SCsOK st T Ω Sg Scs Z Ac s → WritesIn st s0 s (ChgW st Scs Z s0) → + L.rperiod s (L.cscW s) = L.rperiod s0 (L.cscW s0) → CurOK st T s → G s → + L.rperiod s (L.cscW s) ≠ 0#u64 → faults.valid_timeout_handler st s (L.curW s) = ok true → + faults.handle_timeout st ar s a (L.curW s) (error.Fault.Timeout f) ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ + +theorem TmoKC.v {A : Type _} {ar : machine.Arch A} {s0 : S} {G : S → Prop} + (h : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s0 G) : TmoKCv st ar T Cs Ω H Sg Rp Scs Nt Z Ac s0 G := + fun s a f Q R q b x g c w _ o hG _ _ => h s a f Q R q b x g c w o hG + +/-- seL4 `endTimeslice` (`KWN` frame). (mmuAD gen 42b74) The timeout fault asked only where FL4 raises it +(`htmo`: `can_timeout_fault`, the current SC not round-robin, the current thread's timeout handler valid, at the +start state); `end_timeslice.allGN` is its `TmoKC` corollary. -/ +theorem sched.end_timeslice.allGNv (hA : P0.ArchTotal ar) (s : S) (a : A) (cto : Bool) (Q : U64 → U64 → List U64) (R : U64 → List U64) (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) (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) (hc : CurOK st T s) {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) - (htmo : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + (htmo : ∀ f : U64, cto = true → L.rperiod s (L.cscW s) ≠ 0#u64 → + faults.valid_timeout_handler st s (L.curW s) = ok true → + faults.handle_timeout st ar s a (L.curW s) (error.Fault.Timeout f) ⦃ s' _ => + BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄) : sched.end_timeslice st ar s a cto ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ := by have E := end_suffGN hA s a Q R h hB hX hSg hS hc hGF hGA hG unfold sched.end_timeslice @@ -99,24 +125,43 @@ theorem sched.end_timeslice.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (cto : have e1 : sc = L.cscW s := sc_post have e2 : ct = L.curW s := ct_post subst e1 e2 - step with sporadic.is_round_robin.spec as ⟨rr⟩ + step with sporadic.is_round_robin.spec as ⟨rr, hrr⟩ step with obj.Tcb.state.spec - refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun valid _ => ?_ + refine WP.spec_bind (Pₘ := fun v => v = true → faults.valid_timeout_handler st s (L.curW s) = ok true) ?_ + fun valid hvalid => ?_ · split - · exact P0.faults.valid_timeout_handler.p0 st s _ L.total + · exact WP.spec_mono (spec_eq' (P0.faults.valid_timeout_handler.p0 st s _ L.total)) fun v hv e => by + rw [hv.1, e] · simp split - · split + · rename_i hcto + split · exact E - · split - · step with P0.obj.Sc.badge.p0 st _ s L.total as ⟨badge⟩ - exact htmo s a _ Q R h hB hX hSg hS (WritesIn.refl _ _) hc hG + · rename_i hrr0 + split + · rename_i hv0 + step with P0.obj.Sc.badge.p0 st _ s L.total as ⟨badge⟩ + exact htmo badge hcto (fun e => hrr0 (by rw [hrr, e]; rfl)) (hvalid hv0) · exact E · exact E +/-- seL4 `endTimeslice` (`KWN` frame): `end_timeslice.allGNv` with `TmoKC` (statement unchanged). -/ +theorem sched.end_timeslice.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (cto : Bool) + (Q : U64 → U64 → List U64) (R : U64 → List U64) + (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) + (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) (hc : CurOK st T s) + {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) + (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) + (htmo : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + sched.end_timeslice st ar s a cto ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ := + sched.end_timeslice.allGNv hA s a cto Q R h hB hX hSg hS hc hGF hGA hG + fun f _ _ _ => htmo s a f Q R h hB hX hSg hS (WritesIn.refl _ _) hc hG + set_option maxHeartbeats 1000000 in -/-- seL4 `chargeBudget` (`KWN` frame; P1 `charge_budget.allG`). -/ -theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : U64) (cto : Bool) +/-- seL4 `chargeBudget` (`KWN` frame; P1 `charge_budget.allG`). (mmuAD gen 42b74) The timeout faults asked as +`TmoKCv` and only when `can_timeout_fault` (`end_timeslice.allGNv`); `charge_budget.allGN` is its `TmoKC` +corollary. -/ +theorem sched.charge_budget.allGNv (hA : P0.ArchTotal ar) (s : S) (a : A) (used : U64) (cto : Bool) (Q : U64 → U64 → List U64) (R : U64 → List U64) (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) (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) @@ -124,7 +169,7 @@ theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : (hna : L.actionW s ≠ L.curW s) (hcA : L.cscW s ∈ Ac) {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) - (htmo : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + (htmo : cto = true → TmoKCv st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : sched.charge_budget st ar s a used cto ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ := by have hcS : L.cscW s ∈ Scs := hX.2.2.cur have hcT0 : L.curW s ∈ T := h.curT @@ -241,6 +286,27 @@ theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : · rw [nodeAt_of_ksb w2.1, w2.2.1] exact ⟨kw_node h.cur (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]), notIdW_node h.nodes h.cur (by simp [layout.node.CONSUMED]) (idOff_ge (by simp [layout.node.CONSUMED]))⟩ + have P3 : L.rperiod s3 (L.cscW s3) = L.rperiod s (L.cscW s) := by + obtain ⟨hP, hz⟩ := hX.1.sc _ hcS + obtain ⟨h8, h128, -⟩ := sc_lo hP hz + have hv := sc_word_val hP hz (o := layout.sc.CONSUMED) (by simp [layout.sc.CONSUMED]) + have hv0 := sc_word_val hP hz (o := layout.sc.PERIOD) (by simp [layout.sc.PERIOD]) + have hN2 := h2.nodes _ h2.cur + have wn : WritesIn st s2 s3 (fun b => b = L.nodeAt s2 (L.cpu s2) layout.node.CONSUMED) := by + rw [s3_post]; exact writesIn_wr (nodeAt_aligned hN2 (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED])) + have hal : Aligned (periodA (L.cscW s)) := by + unfold Aligned periodA; rw [hv0]; simp [layout.sc.PERIOD]; omega + have hin : InSC (L.cscW s) (Z (L.cscW s)) (periodA (L.cscW s)) := by + unfold periodA; refine ⟨by rw [hv0]; simp, by rw [hv0]; simp [layout.sc.PERIOD]⟩ + rw [ecs3, ecs2] + unfold LawfulStore.rperiod + refine (w2.trans wn).mem_eq hal ?_ + rintro ((hh | e) | e) + · have h1 := hh.1; unfold periodA at h1; rw [hv0] at h1; simp [layout.sc.PERIOD] at h1 + · have h1 := congrArg UScalar.val e; unfold periodA at h1; rw [hv0, hv] at h1 + simp [layout.sc.PERIOD, layout.sc.CONSUMED] at h1 + · exact out_ne_node (h2.omega _ (hX.1.scW _ hcS _ hal hin)) h2.cur hN2 (by simp [layout.node.CONSUMED]) + (congrArg UScalar.val e).symm step with sched.cur_thread.spec as ⟨ct, ct_post⟩ have e2 : ct = L.curW s3 := ct_post subst e2 @@ -253,9 +319,8 @@ theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : rw [ec3, ec2, (f3 _ hcT).1, (f2 _ hcT).1] have hc : CurOK st T s3 := ⟨hrun, hbd, hrl, by rw [ecs3, ecs2, esc]; exact hcsc (by rw [← esc]; exact hbd), by rw [ea3, ea2, ec3, ec2]; exact hna, hrm⟩ - refine WP.spec_bind (sched.end_timeslice.allGN hA s3 a cto Q R h3 hB3 hX3 hSg3 hS3 hc hGF hGA G3 - (fun s' a' f' Q' R' q' b' x' g' c' w' o' G' => htmo s' a' f' Q' R' q' b' x' g' c' ((W3.trans w').mono fun b hb => - hb.elim id fun hb => hb.imp id fun e => by rw [e, nodeAt_of_ksb W3.1, W3.2.1]) o' G')) ?_ + refine WP.spec_bind (sched.end_timeslice.allGNv hA s3 a cto Q R h3 hB3 hX3 hSg3 hS3 hc hGF hGA G3 + (fun f' hcto hp hv => htmo hcto s3 a f' Q R h3 hB3 hX3 hSg3 hS3 W3 P3 hc G3 hp hv)) ?_ rintro ⟨s4, a1⟩ ⟨⟨⟨Q4, R4, h4⟩, hB4, hX4, hSg4, hS4⟩, g4⟩ try simp only [WP.uncurry'_pair] refine WP.spec_bind (WP.spec_and (sched.reschedule_required.sch s4 Q4 R4 h4 hB4 hSg4) @@ -270,8 +335,8 @@ theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : · simp only [WP.spec_ok, WP.uncurry'_pair] exact ⟨⟨⟨Q, R, h3⟩, hB3, hX3, hSg3, hS3⟩, G3⟩ -/-- seL4 `checkBudget` (`KWN` frame). -/ -theorem sched.check_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) +/-- seL4 `chargeBudget` (`KWN` frame): `charge_budget.allGNv` with `TmoKC` (statement unchanged). -/ +theorem sched.charge_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) (used : U64) (cto : Bool) (Q : U64 → U64 → List U64) (R : U64 → List U64) (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) (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) @@ -280,6 +345,20 @@ theorem sched.check_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) (htmo : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + sched.charge_budget st ar s a used cto ⦃ s' _ => BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s' ⦄ := + sched.charge_budget.allGNv hA s a used cto Q R h hB hX hSg hS hcsc hna hcA hGF hGA hG fun _ => htmo.v + +/-- seL4 `checkBudget` (`KWN` frame). (mmuAD gen 42b74) The timeout faults asked as `TmoKCv` +(`charge_budget.allGNv`); `check_budget.allGN` is its `TmoKC` corollary. -/ +theorem sched.check_budget.allGNv (hA : P0.ArchTotal ar) (s : S) (a : A) + (Q : U64 → U64 → List U64) (R : U64 → List U64) + (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) + (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : L.actionW s ≠ L.curW s) (hcA : L.cscW s ∈ Ac) + {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) + (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) + (htmo : TmoKCv st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : sched.check_budget st ar s a ⦃ r s' _ => (BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s') ∧ (r = true → s' = s) ⦄ := by unfold sched.check_budget step with sched.cur_sc.spec as ⟨sc⟩ @@ -297,7 +376,8 @@ theorem sched.check_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) | exact ⟨⟨hb, hG⟩, fun _ => rfl⟩ | exact ⟨hb, hG, fun _ => rfl⟩ | exact ⟨hb, hG⟩ - · refine WP.spec_bind (sched.charge_budget.allGN hA s a c true Q R h hB hX hSg hS hcsc hna hcA hGF hGA hG htmo) ?_ + · refine WP.spec_bind (sched.charge_budget.allGNv hA s a c true Q R h hB hX hSg hS hcsc hna hcA hGF hGA hG + fun _ => htmo) ?_ rintro ⟨s1, a1⟩ h1 try simp only [WP.uncurry'_pair] at h1 obtain ⟨hb1, g1⟩ := h1 @@ -308,6 +388,19 @@ theorem sched.check_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) | exact ⟨hb1, g1, fun e => absurd e (by simp)⟩ | exact ⟨hb1, g1⟩ +/-- seL4 `checkBudget` (`KWN` frame): `check_budget.allGNv` with `TmoKC` (statement unchanged). -/ +theorem sched.check_budget.allGN (hA : P0.ArchTotal ar) (s : S) (a : A) + (Q : U64 → U64 → List U64) (R : U64 → List U64) + (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) + (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : L.actionW s ≠ L.curW s) (hcA : L.cscW s ∈ Ac) + {G : S → Prop} (hGF : ∀ s1 s2 : S, G s1 → FootN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) + (hGA : ∀ s1 : S, G s1 → ActOut st T Kp s1 ∧ (L.curW s1 ∉ Kp)) (hG : G s) + (htmo : TmoKC st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + sched.check_budget st ar s a ⦃ r s' _ => (BXI st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ G s') ∧ (r = true → s' = s) ⦄ := + sched.check_budget.allGNv hA s a Q R h hB hX hSg hS hcsc hna hcA hGF hGA hG htmo.v + end end Fl4Proofs.P1 diff --git a/proofs/Fl4Proofs/P2/FootN5.lean b/proofs/Fl4Proofs/P2/FootN5.lean index 3f4076c9f..5e91d4ada 100644 --- a/proofs/Fl4Proofs/P2/FootN5.lean +++ b/proofs/Fl4Proofs/P2/FootN5.lean @@ -201,24 +201,30 @@ replaced by `KWN` and the transfer's start a `FootN` step): under `send_ipc.ipc` property `Pst` of the states that holds at the start, is kept by `KW` steps (`hPK`) and holds after the message transfer from a state the receiver's dequeue (a `KW` step from `s`) reached (`hxP`), holds at the end -(`send_ipc.foot`: `IpcFoot` from `s`; `send_ipc.xg`: `XG`). -/ -theorem endpoint.send_ipc.footPN {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64} - {RS : S → S → Prop} (hxf : XferOKRS st ar T Cs Ω H Sg Rp Scs Nt Z U RS (XG st T Cs Ω H Sg Scs Z P3Ok)) - (hRSK : ∀ s0 s1 s2 : S, RS s0 s1 → WritesIn st s1 s2 (KW st T Cs Sg Scs Z (EH H) s1) → RS s2 s2) (s : S) (a : A) (blocking do_call : Bool) +(`send_ipc.foot`: `IpcFoot` from `s`; `send_ipc.xg`: `XG`). (mmuAD gen 42b77) The transfer asked only from the +sender `t` (P1's `XferOKAt` at a guard `G'` holding after the receiver's dequeue, `hG'`: a `FootN` step from `s` +keeping every TCB word but the two queue links; `hxP` at `t` with `G'`); `send_ipc.footPN` is it by `XferOK.at`. -/ +theorem endpoint.send_ipc.footPNT {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64} + (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) (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) (hG : XG st T Cs Ω H Sg Scs Z P3Ok s) (hRS0 : RS s s) - (hKt : t ∉ Kp) (hKB : ∀ y ∈ Kp, ¬ Blocked (L.mem s (stA y))) (hdK : can_donate = true → ¬ Nd) (hKa : ActOut st T Kp s) (Pst : S → Prop) + (hH : H e = some .ep) + (hKt : t ∉ Kp) (hKB : ∀ y ∈ Kp, ¬ Blocked (L.mem s (stA y))) (hdK : can_donate = true → ¬ Nd) (hKa : ActOut st T Kp s) + {G' : S → Prop} (hxf : XferOKAt st ar T Cs Ω H Sg Rp Scs Nt Z U G' t) + (hG' : ∀ s1 : S, FootN st Kp Nd T Cs Sg Scs Z (EH H) s 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)) → G' s1) + (Pst : S → Prop) (hPK : ∀ s1 s2 : S, Pst s1 → FootDN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → Pst s2) (hP0 : Pst s) - (hxP : ∀ (Ac X : Set U64) (Q : U64 → U64 → List U64) (R : U64 → List U64) (s1 : S) (a : A) (snd ep badge : U64) - (grant : Bool) (rcv : U64), snd ∈ T → rcv ∈ T → + (hxP : ∀ (Ac X : Set U64) (Q : U64 → U64 → List U64) (R : U64 → List U64) (s1 : S) (a : A) (ep badge : U64) + (grant : Bool) (rcv : U64), rcv ∈ T → SchedQueuesInvX st T Cs Ω H X s1 Q R → BoundInv st T Ac s1 → XInv st T Cs Ω Sg Rp Scs Nt Z s1 → SCsOK st T Ω Sg Scs Z Ac s1 → SgOK st Ω Sg s1 → UserOK st T Cs Ω H U s1 → - FootN st Kp Nd T Cs Sg Scs Z (EH H) s s1 → XG st T Cs Ω H Sg Scs Z P3Ok s1 → - ipc.do_ipc_transfer st ar s1 a snd ep badge grant rcv ⦃ s2 => Pst s2 ⦄) : + FootN st Kp Nd T Cs Sg Scs Z (EH H) s s1 → G' s1 → + ipc.do_ipc_transfer st ar s1 a t ep badge grant rcv ⦃ s2 => Pst s2 ⦄) : endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e ⦃ s' _ => Pst s' ⦄ := by have hidle := hc.ni @@ -263,10 +269,10 @@ theorem endpoint.send_ipc.footPN {A : Type _} {ar : machine.Arch A} (hA : P0.Arc 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 (WP.spec_and (hxf _ _ _ _ s1 a t e badge can_grant hd ht hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) - (hRSK s s s1 hRS0 F1.foot) (hG.foot F1.foot)) - (hxP _ _ _ _ s1 a t e badge can_grant hd ht hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) F1 (hG.foot F1.foot))) ?_ - rintro s2 ⟨⟨h2, hB2, hX2, hS2, hSg2, ⟨ea2, ec2, ei2, ecs2, f2, o2, -⟩, -⟩, F2⟩ + have hG1 : G' s1 := hG' s1 F1 fun y hy K hK hK8 h1' h2' => f1 y hy K hK hK8 h1' h2' + refine WP.spec_bind (WP.spec_and (hxf _ _ _ _ s1 a e badge can_grant hd hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) hG1) + (hxP _ _ _ _ s1 a e badge can_grant hd hdT h1 hB1 hX1 hS1 hSg1 (hU.ksb k1) F1 hG1)) ?_ + rintro s2 ⟨⟨h2, hB2, hX2, hS2, hSg2, ⟨ea2, ec2, ei2, ecs2, f2, o2, -⟩⟩, F2⟩ 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') @@ -466,6 +472,37 @@ theorem endpoint.send_ipc.footPN {A : Type _} {ar : machine.Arch A} (hA : P0.Arc + +/-- `send_ipc.footPNT` from the all-sender `XferOKRS` (statement before gen 42b77): the guard `XGR` after the +dequeue by `XG.foot` and `hRSK`. -/ +theorem endpoint.send_ipc.footPN {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {U : Set U64} + {RS : S → S → Prop} (hxf : XferOKRS st ar T Cs Ω H Sg Rp Scs Nt Z U RS (XG st T Cs Ω H Sg Scs Z P3Ok)) + (hRSK : ∀ s0 s1 s2 : S, RS s0 s1 → WritesIn st s1 s2 (KW st T Cs Sg Scs Z (EH H) s1) → RS s2 s2) (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) + (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) (hG : XG st T Cs Ω H Sg Scs Z P3Ok s) (hRS0 : RS s s) + (hKt : t ∉ Kp) (hKB : ∀ y ∈ Kp, ¬ Blocked (L.mem s (stA y))) (hdK : can_donate = true → ¬ Nd) (hKa : ActOut st T Kp s) (Pst : S → Prop) + (hPK : ∀ s1 s2 : S, Pst s1 → FootDN st Kp Nd T Cs Sg Scs Z (EH H) s1 s2 → Pst s2) (hP0 : Pst s) + (hxP : ∀ (Ac X : Set U64) (Q : U64 → U64 → List U64) (R : U64 → List U64) (s1 : S) (a : A) (snd ep badge : U64) + (grant : Bool) (rcv : U64), snd ∈ T → rcv ∈ T → + SchedQueuesInvX st T Cs Ω H X s1 Q R → BoundInv st T Ac s1 → XInv st T Cs Ω Sg Rp Scs Nt Z s1 → + SCsOK st T Ω Sg Scs Z Ac s1 → SgOK st Ω Sg s1 → UserOK st T Cs Ω H U s1 → + FootN st Kp Nd T Cs Sg Scs Z (EH H) s s1 → XG st T Cs Ω H Sg Scs Z P3Ok s1 → + ipc.do_ipc_transfer st ar s1 a snd ep badge grant rcv ⦃ s2 => Pst s2 ⦄) : + endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e + ⦃ s' _ => Pst s' ⦄ := + endpoint.send_ipc.footPNT hA s a blocking do_call badge can_grant can_grant_reply can_donate t e Q R h hB hX hS hSg + hU hc hdon hH hKt hKB hdK hKa (G' := fun s1 => XG st T Cs Ω H Sg Scs Z P3Ok s1 ∧ RS s1 s1) + (fun Ac X Q R s1 a ep badge grant rcv hr h1 hB1 hX1 hS1 hSg1 hU1 hG1 => + WP.spec_mono (hxf Ac X Q R s1 a t ep badge grant rcv hc.mem hr h1 hB1 hX1 hS1 hSg1 hU1 hG1.2 hG1.1) + 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⟩) + (fun s1 F1 _ => ⟨hG.foot F1.foot, hRSK s s s1 hRS0 F1.foot⟩) Pst hPK hP0 + fun Ac X Q R s1 a ep badge grant rcv hr h1 hB1 hX1 hS1 hSg1 hU1 F1 _ => + hxP Ac X Q R s1 a t ep badge grant rcv hc.mem hr h1 hB1 hX1 hS1 hSg1 hU1 F1 (hG.foot F1.foot) + /-- A `KWN`/`IpcWN` footprint keeps the `STATE` of the protected threads. -/ theorem IpcFootN.stK {s s' : S} (f : IpcFootN st Kp Nd T Cs Ω Sg Scs Z Es U s s') (hT : TcbPlaced T) {y : U64} (hyT : y ∈ T) (hy : y ∈ Kp) : L.mem s' (stA y) = L.mem s (stA y) := diff --git a/proofs/Fl4Proofs/P2/FootN8.lean b/proofs/Fl4Proofs/P2/FootN8.lean index 1f8a45e5f..e2621b68b 100644 --- a/proofs/Fl4Proofs/P2/FootN8.lean +++ b/proofs/Fl4Proofs/P2/FootN8.lean @@ -27,6 +27,11 @@ word: words `KWN Kp True` protects. So the footprint is * `schedcontext.donate.ff`: a donation of an unbound SC (`maybe_donate`'s case) to a thread outside `Kp`/`Il`, of an SC outside `Ks`, is an `FFoot`. +(mmuAD gen 42b73) **`send_signal.ffG`**: `send_signal` in `FFoot` over any `Kp` / `Il` / `Ks` the woken thread is +outside (`send_signal.fk` its `KI` / `IlAt` / `KsAt` instance, statement unchanged), with `vcpu.report.ff` (the report +over any `Kp`), `FFoot.tcbK` (the `TCB` words of `Ks` kept), and for the VM side's `AffK` (P3/VmOracle) +`FFoot.affK` (the `AFFINITY` of `Kp` and `Il` kept) and `FFoot.curK` (other cores' `CUR_THREAD` kept). + No premise. -/ import Fl4Proofs.P2.AllSched @@ -235,6 +240,61 @@ theorem FFoot.cur {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List exact out_ne_node (hq.omega _ (hO.scW _ hk _ a2 i2)) hq.cur hN (by rw [curth0]; omega) (congrArg UScalar.val hbk) +/-- (mmuAD gen 42b73) **An `FFoot` footprint keeps the `TCB` word of every SC of `Ks`** (protected under `Nd`; a +donation word is the `TCB` word of an SC outside `Ks`). -/ +theorem FFoot.tcbK {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} + (hq : SchedQueuesInvX st T Cs Ω H X s Q R) (hO : ObjsOK st Ω Sg Rp Scs Nt Z s) + (f : FFoot st Kp Il Ks T Cs Sg Scs Z Es U s s') {k : U64} (hk : k ∈ Scs) (hkK : k ∈ Ks) : + L.mem s' (scTcbA k) = L.mem s (scTcbA k) := by + obtain ⟨-, ⟨a2, i2⟩⟩ := sclink_in hO hk + have hout : OutsideObjs st T Cs s (scTcbA k) := hq.omega _ (hO.scW _ hk _ a2 i2) + refine f.mem_eq a2 ?_ + rintro (⟨-, hn⟩ | ⟨y, hyT, -, -, e | e⟩ | ⟨k', hk', hk'K, e⟩) + · exact hn (Or.inr (Or.inr ⟨trivial, Or.inr (Or.inl ⟨k, hk, Or.inr rfl, hout⟩)⟩)) + · rw [scA_eq] at e + exact out_ne_field hout hyT (hq.tcbs y hyT) (by simp) (congrArg UScalar.val e.symm) + · rw [affA_eq] at e + exact out_ne_field hout hyT (hq.tcbs y hyT) (by simp) (congrArg UScalar.val e.symm) + · exact (tcb_ne_hdr hO hk' hk fun h => hk'K (h ▸ hkK)).2 e.symm + +/-- (mmuAD gen 42b73) **An `FFoot` footprint keeps the `AFFINITY` of a thread of `Kp` or `Il`** (protected under +`Nd`; a donation word is the `AFFINITY` of a thread outside both). -/ +theorem FFoot.affK {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} + (hq : SchedQueuesInvX st T Cs Ω H X s Q R) (hO : ObjsOK st Ω Sg Rp Scs Nt Z s) + (f : FFoot st Kp Il Ks T Cs Sg Scs Z Es U s s') {y : U64} (hy : y ∈ T) (hyI : y ∈ Kp ∨ y ∈ Il) : + L.mem s' (affA y) = L.mem s (affA y) := by + have hT := hq.tcbs + refine f.mem_eq (by rw [affA_eq]; exact field_aligned (hT y hy) (by simp) (by simp)) ?_ + rintro (⟨-, hn⟩ | ⟨y', hyT', hK', hI', e | e⟩ | ⟨k, hk, -, e⟩) + · exact hn (Or.inr (Or.inr ⟨trivial, Or.inl ⟨y, hy, hT y hy, Or.inr rfl⟩⟩)) + · rw [affA_eq, scA_eq] at e + exact field_ne (hT y hy) (hT y' hyT') (by simp) (by simp) (fun _ => by simp) e + · rw [affA_eq, affA_eq] at e + exact field_ne (hT y hy) (hT y' hyT') (by simp) (by simp) + (fun h => by subst h; rcases hyI with h1 | h1; exact absurd h1 hK'; exact absurd h1 hI') e + · obtain ⟨-, ⟨a2, i2⟩⟩ := sclink_in hO hk + rw [affA_eq] at e + exact out_ne_field (hq.omega _ (hO.scW _ hk _ a2 i2)) hy (hT y hy) (by simp) (congrArg UScalar.val e) + +/-- (mmuAD gen 42b73) **An `FFoot` footprint keeps another core's `CUR_THREAD`** (a node identity word). -/ +theorem FFoot.curK {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} + (hq : SchedQueuesInvX st T Cs Ω H X s Q R) (hO : ObjsOK st Ω Sg Rp Scs Nt Z s) + (f : FFoot st Kp Il Ks T Cs Sg Scs Z Es U s s') {c : U64} (hc : c ∈ Cs) (hne : c ≠ L.cpu s) : + L.mem s' (L.nodeAt s' c layout.node.CUR_THREAD) = L.mem s (L.nodeAt s c layout.node.CUR_THREAD) := by + have hN := hq.nodes c hc + rw [nodeAt_of_ksb f.1] + refine f.mem_eq (nodeAt_aligned hN (by rw [curth0]; omega) (by rw [curth0])) fun hb => ?_ + rcases hb with ⟨-, hn⟩ | ⟨y, hyT, -, -, hby⟩ | ⟨k, hk, -, hbk⟩ + · exact hn (Or.inl ⟨c, hc, _, Or.inr (Or.inr (Or.inl ⟨hne, Or.inl (by rw [curth0])⟩)), rfl⟩) + · rcases hby with e | e + · rw [scA_eq] at e + exact node_ne_field hN (by rw [curth0]; omega) hyT (hq.tcbs y hyT) (by simp) e + · rw [affA_eq] at e + exact node_ne_field hN (by rw [curth0]; omega) hyT (hq.tcbs y hyT) (by simp) e + · obtain ⟨-, ⟨a2, i2⟩⟩ := sclink_in hO hk + exact out_ne_node (hq.omega _ (hO.scW _ hk _ a2 i2)) hc hN (by rw [curth0]; omega) + (congrArg UScalar.val hbk) + /-- **An `FFoot` footprint of `fire` gives `FireKeep`**, from `ActOut` and the current thread outside `OtherK` at `fire`'s start. -/ theorem FireKeep.ofFF {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} @@ -848,6 +908,26 @@ theorem sched.set_thread_state.kwNP {Nd : Prop} (s : S) (t : obj.Tcb) (v : U64) rw [stA_eq]; exact footN_field hT NP hc ht (by simp) (by simp) (by simp) (by simp) (PrF.of_nk hKt (by simp) (by simp)) exact f1.trans f2 +/-- (mmuAD gen 42b73) **`vcpu.report` in `FFoot` over any protected threads** not containing the reported thread +(P1 `vcpu.report.xf`'s `RepW` words, `RepW.ff`, then its `set_thread_state`). -/ +theorem vcpu.report.ff {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (s : S) (a : A) + (t badge : U64) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) (ht : t ∈ T) + (hvm : L.mem s (stA t) = sched.TS_RUNNING_VM) + (hc : L.mem s (core.num.U64.wrapping_add t 3664#u64) ≠ 0#u64 → + L.mem s (core.num.U64.wrapping_add (L.mem s (core.num.U64.wrapping_add t 3664#u64)) vcpu.PENDING) = 0#u64) + (hU : ∀ b ∈ U, UsrW st T Cs H Sg Scs Z s b) (hbuf : msg.lookup_ipc_buffer st s true t ⦃ b => BufOK U b ⦄) + (htK : t ∉ Kp) : + vcpu.report st ar s a t badge ⦃ s' => FFoot st Kp Il Ks T Cs Sg Scs Z Es U s s' ⦄ := by + have h0 := h + obtain ⟨⟨Q, R, hq⟩, -, hX, -, -⟩ := h0 + refine WP.spec_mono (vcpu.report.xf hA s a t badge h ht hvm hc hU hbuf) ?_ + rintro s' ⟨s1, h1, -, w1, e⟩ + obtain ⟨⟨Q1, R1, hq1⟩, -, -, -, -⟩ := h1 + have K2 := sched.set_thread_state.kwNP (Sg := Sg) (Kp := Kp) (Nd := True) (Scs := Scs) (Z := Z) (Es := Es) s1 t + sched.TS_RUNNING hq1.tcbs hq1.nodes hq1.cur ht htK + rw [e, WP.spec_ok] at K2 + exact (RepW.ff hq hX.1 ht hU w1).trans (FootN.ff K2) + /-- `reply_unlink.kwN` from `ObjsOK` (no `XInv`). -/ theorem ipc.reply_unlink.kwNO {Nd : Prop} {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} (s : S) (r t : U64) (h : SchedQueuesInvX st T Cs Ω H X s Q R) (hO : ObjsOK st Ω Sg Rp Scs Nt Z s) @@ -1199,24 +1279,31 @@ theorem notification.set_active.fn {Nd : Prop} {Q : U64 → U64 → List U64} {R exact (ntfn_ts.fn s n _ h hX hSg.sub hH).trans (ntfn_bd.fn n badge (fun c hc => (h.nodes c hc).ksb (L.ksb_wr _ _ _)) (by rw [L.cpu_wr]; exact h.cur) hX.1.ksb hn ((h.omega _ hm).ksb (L.ksb_wr _ _ _))) -/-- **`send_signal` is an `FKI` step** (P1 `send_signal.tinvFK`): the woken -thread is blocked or a `RUNNING_VM` thread `signal_completes` accepts, so none -of `KI` and no idle thread (`FCtx.blk`, `FCtx.vm`). -/ -theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) +/-- (mmuAD gen 42b73) **`send_signal` in `FFoot` over any protected threads `Kp`, idle-like threads `Il` and SCs +`Ks`** (P1 `send_signal.tinvFK`): the woken thread — the bound thread of an idle notification blocked on receive +(`hWr`), the bound `RUNNING_VM` thread `signal_completes` accepts (`hWv`, a fact of that read), the waiting +notification's head (`hWw`) — is in neither; the action is unprotected (`hKa`); the SCs of `Ks` have a thread (`hKsS`, +`hKs`). `send_signal.fk` is its `KI` / `IlAt` / `KsAt` instance. -/ +theorem notification.send_signal.ffG {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (s : S) (a : A) (n badge : U64) (h : TInv st T Cs Ω H Sg Rp Scs Nt Z Ac s) (hn : n ∈ Nt) (hH : H n = some .ntfn) (hU : ∀ b ∈ U, UsrW st T Cs H Sg Scs Z s b) (hbuf : ∀ y ∈ T, msg.lookup_ipc_buffer st s true y ⦃ b => BufOK U b ⦄) - (c : FCtx st T Cs Scs (L.cpu s) s) : - notification.send_signal st ar s a n badge ⦃ s' _ => FKI st T Cs (L.cpu s) s s' ⦄ := by + (hKa : ActOut st T Kp s) (hKsS : ∀ k ∈ Ks, k ∈ Scs) (hKs : ∀ k ∈ Ks, L.mem s (scTcbA k) ≠ 0#u64) + (hWr : ∀ i, L.epState s n = obj.NTFN_IDLE → L.mem s (ntfnBtA n) = i → + L.mem s (stA i) = sched.TS_BLOCKED_ON_RECV → i ∉ Kp ∧ i ∉ Il) + (hWv : ∀ i, L.epState s n = obj.NTFN_IDLE → L.mem s (ntfnBtA n) = i → L.mem s (stA i) = sched.TS_RUNNING_VM → + vcpu.signal_completes st s i ⦃ v => v = true → i ∉ Kp ∧ i ∉ Il ⦄) + (hWw : L.epState s n = 1#u64 → (L.epQ s n).head ∉ Kp ∧ (L.epQ s n).head ∉ Il) : + notification.send_signal st ar s a n badge ⦃ s' _ => FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s' ⦄ := by have hI := h obtain ⟨⟨Q, R, h0⟩, hB, hX, hS, hSg⟩ := h have hNb := hX.2.2.ntb have hT := h0.tcbs have hb0 : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s := ⟨⟨Q, R, h0⟩, hB, hX, hS, hSg⟩ - have he := c.he - have saK : notification.set_active st s n badge ⦃ s' => FKI st T Cs (L.cpu s) s s' ⦄ := - WP.spec_mono (notification.set_active.fn (Kp := KI st T Cs (L.cpu s) s) (Nd := True) s n badge h0 hX hSg hn hH) - fun s' f => c.fkiN h0 hX.1 f + have hKs' : ∀ s1 : S, FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s1 → ∀ k ∈ Ks, L.mem s1 (scTcbA k) ≠ 0#u64 := + fun _ F k hk => by rw [F.tcbK h0 hX.1 (hKsS k hk) hk]; exact hKs k hk + have saK : notification.set_active st s n badge ⦃ s' => FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s' ⦄ := + WP.spec_mono (notification.set_active.fn (Kp := Kp) (Nd := True) s n badge h0 hX hSg hn hH) fun _ f => FootN.ff f unfold notification.send_signal step with obj.Ntfn.state.spec as ⟨v, hv⟩ refine sig_if _ _ _ _ (fun hidl => ?_) (fun hnidl => ?_) @@ -1229,7 +1316,7 @@ theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0. else do let i2 ← obj.Tcb.state st i s1 if i2 = sched.TS_RUNNING_VM then notification.kick_guest st ar s1 a i else ok (s1, a)) - ⦃ s' _ => FKI st T Cs (L.cpu s) s s' ⦄ := by + ⦃ s' _ => FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s' ⦄ := by refine WP.spec_bind saK fun s1 k1 => ?_ refine sig_if _ _ _ _ (fun _ => (WP.spec_ok _).2 k1) (fun _ => ?_) step with obj.Tcb.state.spec @@ -1255,18 +1342,16 @@ theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0. refine sig_if _ _ _ _ (fun hrecv => ?_) (fun hnrecv => ?_) · have hst : L.mem s (stA i) = sched.TS_BLOCKED_ON_RECV := by rw [← ei1, hrecv] have hbl : Blocked (L.mem s (stA i)) := by rw [hst]; exact Or.inr (Or.inl rfl) - obtain ⟨hiK, hiI⟩ := c.blk hbl + obtain ⟨hiK, hiI⟩ := hWr i (hv.symm.trans hidl) ei.symm hst obtain ⟨dq, dr, da⟩ := blocked_out h0 hiT (not_runnable_of_blocked hbl) refine WP.spec_bind (WP.spec_and (ipc.cancel_ipc.all s a i Q R h0 hiT hB hX hSg.sub) - (ipc.cancel_ipc.kwNR (Kp := KI st T Cs (L.cpu s) s) (Nd := True) (Sg := Sg) (Scs := Scs) (Z := Z) s a i h0 + (ipc.cancel_ipc.kwNR (Kp := Kp) (Nd := True) (Sg := Sg) (Scs := Scs) (Z := Z) s a i h0 hiT hX hSg.sub hst (fun h0' => (hX.2.1.recv i hiT hst h0').1) hiK)) ?_ rintro ⟨s1, a1⟩ ⟨⟨h1, hB1, hX1, nb1, nr1, -, k1, -⟩, F1⟩ try simp only [WP.uncurry'_pair] have hS1 := hS.keepT hX k1 have hSg1 : SgOK st Ω Sg s1 := ⟨hSg.sub, fun b hb => by rw [k1.ksb]; exact hSg.ks b hb, fun o h1' h2' => by rw [k1.ksb]; exact hSg.ksΩ o h1' h2'⟩ - have K1 : FKI st T Cs (L.cpu s) s s1 := c.fkiN h0 hX.1 F1 - have c1 := c.step K1 F1.2.1 have dq1 : (L.mem s1 (inqA i) &&& sched.Q_QUEUED) = 0#u64 := by rw [k1.inqf hiT]; exact dq have dr1 : (L.mem s1 (inqA i) &&& sched.Q_RELEASE) = 0#u64 := by rw [k1.inqf hiT]; exact dr have da1 : L.actionW s1 ≠ i := by @@ -1276,56 +1361,52 @@ theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0. refine WP.spec_bind (WP.spec_and (sts_all s1 i _ Q R h1 hB1 hX1 hS1 hSg1 hiT not_blocked_running running_ne (Or.inr nb1) (hX1.noref hta nr1 (fun e => nb1 (by rw [e]; exact Or.inr (Or.inl rfl)))) ⟨fun _ _ _ _ _ => runnable_running, fun _ _ _ => runnable_running, fun _ => runnable_running⟩) - (sched.set_thread_state.kwNP (Sg := Sg) (Kp := KI st T Cs (L.cpu s) s1) (Nd := True) (Scs := Scs) (Z := Z) - (Es := ∅) s1 i _ hT h1.nodes h1.cur hiT (by rw [K1.kiEq he]; exact hiK))) ?_ + (sched.set_thread_state.kwNP (Sg := Sg) (Kp := Kp) (Nd := True) (Scs := Scs) (Z := Z) + (Es := EH H) s1 i _ hT h1.nodes h1.cur hiT hiK)) ?_ rintro s2 ⟨⟨h2, hB2, hX2, hS2, hSg2, st2, k2⟩, F2⟩ have h2' : SchedQueuesInv st T Cs Ω H s2 Q R := h2.congrX empty_congr - have K2 : FKI st T Cs (L.cpu s) s1 s2 := c1.fkiN h1 hX1.1 F2 - have c2 := c1.step K2 F2.2.1 - have K02 := K1.trans he K2 + have F02 : FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s2 := (FootN.ff F1).trans (FootN.ff F2) have dq2 : (L.mem s2 (inqA i) &&& sched.Q_QUEUED) = 0#u64 := by rw [k2.inqf hiT]; exact dq1 have dr2 : (L.mem s2 (inqA i) &&& sched.Q_RELEASE) = 0#u64 := by rw [k2.inqf hiT]; exact dr1 have da2 : L.actionW s2 ≠ i := by rcases k2.act with e | e · rw [e]; exact da1 · rw [e]; exact fun e' => notT_small hT (by simp) (e' ▸ hiT) - refine WP.spec_mono (signal_tail.ff (Kp := KI st T Cs (L.cpu s) s2) (Il := IlAt st Cs s2) (Ks := KsAt st Cs s2) - (Es := ∅) (U := ∅) hA s2 a1 i n badge Q R h2' hB2 hX2 hS2 hSg2 hiT hn dq2 dr2 da2 + refine WP.spec_mono (signal_tail.ff (Kp := Kp) (Il := Il) (Ks := Ks) (Es := EH H) (U := U) hA s2 a1 i n badge + Q R h2' hB2 hX2 hS2 hSg2 hiT hn dq2 dr2 da2 (fun e => hB.idleNB (by rw [← k1.idleW, ← k2.idleW, e]; exact Or.inl hbl)) (by rw [st2]; rintro (hb | hb); exact not_blocked_running hb; exact running_ne.1 hb) - (by rw [K02.kiEq he]; exact hiK) (by rw [K02.ilEq]; exact hiI) c2.ksS (c2.ks0 hT hX2) (c2.aoK h2')) ?_ + hiK hiI hKsS (hKs' s2 F02) (F02.out hKa)) ?_ rintro ⟨s', a'⟩ ⟨-, F'⟩ - exact K02.trans he (c2.fki h2' hX2.1 F') + exact F02.trans F' · -- not receiving: the `RunningVM` completion, else active (and kicked) rw [if_neg hb] refine sig_if _ _ _ _ (fun hvm => ?_) (fun _ => OLD) - refine WP.spec_bind (WP.spec_and (vcpu.signal_completes.blk s i) (vcpu.signal_completes.aff s i)) ?_ - rintro b1 ⟨hb1, ha1⟩ - refine sig_if _ _ _ _ (fun hb1t => ?_) (fun _ => OLD) have hvmS : L.mem s (stA i) = sched.TS_RUNNING_VM := by rw [← ei1]; exact hvm - obtain ⟨hiK, hiI⟩ := c.vm hvmS (ha1 hb1t) - refine WP.spec_bind (WP.spec_and (vcpu.report.fki hA s a i badge hb0 hiT hvmS (hb1 hb1t) hU (hbuf i hiT) - c.KT c.iT c.iS (c.iSt _ h0.cur)) (vcpu.report.stk hA s a i badge hb0 hiT hvmS (hb1 hb1t) hU (hbuf i hiT))) ?_ - rintro s1 ⟨⟨h1, st1, K1⟩, -, hc1⟩ - have c1 := c.step K1 hc1 - have h1' := h1 - obtain ⟨⟨Q1, R1, q1⟩, -, hX1, -, -⟩ := h1' - refine WP.spec_mono (signal_vm.ff (Kp := KI st T Cs (L.cpu s) s1) (Il := IlAt st Cs s1) (Ks := KsAt st Cs s1) - (Es := ∅) (U := ∅) hA s1 a i n h1 hiT hn st1 (by rw [K1.kiEq he]; exact hiK) (by rw [K1.ilEq]; exact hiI) - c1.ksS (c1.ks0 hT hX1) (c1.aoK q1)) ?_ + refine WP.spec_bind (WP.spec_and (vcpu.signal_completes.blk s i) + (hWv i (hv.symm.trans hidl) ei.symm hvmS)) ?_ + rintro b1 ⟨hb1, hw1⟩ + refine sig_if _ _ _ _ (fun hb1t => ?_) (fun _ => OLD) + obtain ⟨hiK, hiI⟩ := hw1 hb1t + refine WP.spec_bind (WP.spec_and (vcpu.report.ff (Kp := Kp) (Il := Il) (Ks := Ks) (Es := EH H) hA s a i badge + hb0 hiT hvmS (hb1 hb1t) hU (hbuf i hiT) hiK) + (vcpu.report.blk hA s a i badge hb0 hiT hvmS (hb1 hb1t) hU (hbuf i hiT))) ?_ + rintro s1 ⟨F1, h1, st1⟩ + refine WP.spec_mono (signal_vm.ff (Kp := Kp) (Il := Il) (Ks := Ks) (Es := EH H) (U := U) hA s1 a i n h1 hiT hn st1 + hiK hiI hKsS (hKs' s1 F1) (F1.out hKa)) ?_ rintro ⟨s', a'⟩ ⟨-, F'⟩ - exact K1.trans he (c1.fki q1 hX1.1 F') + exact F1.trans F' · split · -- a waiting notification rename_i hwait have hst1 : L.epState s n = 1#u64 := by rw [← hv, hwait]; unfold obj.NTFN_WAITING; rfl obtain ⟨hdT, hbe, hds⟩ := ntfn_head h0 hH hst1 + obtain ⟨hdK, hdI⟩ := hWw hst1 step with notification.get_queue.spec as ⟨q, eq⟩ subst eq set hd := (L.epQ s n).head with hhd have hta := hT hd hdT have hbl : Blocked (L.mem s (stA hd)) := by rw [hds]; exact Or.inr (Or.inr rfl) - obtain ⟨hdK, hdI⟩ := c.blk hbl obtain ⟨dq, dr, da⟩ := blocked_out h0 hdT (not_runnable_of_blocked hbl) obtain ⟨E, EQ, hEW⟩ := h0.eps obtain ⟨he', hmem⟩ := hEW.2.2.2.2.1 hd hdT (by simp) hbl @@ -1337,11 +1418,9 @@ theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0. rw [hbe] at hinv refine WP.spec_bind (WP.spec_and hinv (notification.ntfn_dequeue.foot s n hd _ hT hE hq hmem)) ?_ rintro s1 ⟨⟨h1, f1, o1, n1, k1, -, nc1⟩, w1⟩ - have F1 : FootN st (KI st T Cs (L.cpu s) s) True T Cs Sg Scs Z (EH H) s s1 := + have F1 : FootN st Kp True T Cs Sg Scs Z (EH H) s s1 := FootN.of' w1 (fun b _ hb => EpFoot.kwN hT h0.nodes hq.mem hHe hE hEN hEΩ (hdrΩ_of hX hSg.sub) hb) (AcK.of_eq (EpFoot.act hT h0.nodes h0.cur hq.mem hE hEN w1)) - have K1 : FKI st T Cs (L.cpu s) s s1 := c.fkiN h0 hX.1 F1 - have cc1 := c.step K1 F1.2.1 have tm1 : TmFr st T Cs Nt s s1 := 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)⟩ obtain ⟨hB1, hX1, hS1, hSg1, ea1, ec1, ei1⟩ := frame_bx h0 hB hX hS hSg f1 o1 n1 k1 tm1 @@ -1354,33 +1433,51 @@ theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0. (Or.inl (Or.inr rfl)) (hX1.noref hta (by rw [st1]; exact blocked_ne_reply (Or.inr (Or.inr rfl))) (by rw [st1, r3, r6]; decide)) ⟨fun _ _ _ _ _ => runnable_running, fun _ _ _ => runnable_running, fun _ => runnable_running⟩) - (sched.set_thread_state.kwNP (Sg := Sg) (Kp := KI st T Cs (L.cpu s) s1) (Nd := True) (Scs := Scs) (Z := Z) - (Es := ∅) s1 hd _ hT h1.nodes h1.cur hdT (by rw [K1.kiEq he]; exact hdK))) ?_ + (sched.set_thread_state.kwNP (Sg := Sg) (Kp := Kp) (Nd := True) (Scs := Scs) (Z := Z) + (Es := EH H) s1 hd _ hT h1.nodes h1.cur hdT hdK)) ?_ rintro s2 ⟨⟨h2, hB2, hX2, hS2, hSg2, st2, k2⟩, F2⟩ have h2' : SchedQueuesInv st T Cs Ω H s2 Q R := h2.congrX empty_congr' - have K2 : FKI st T Cs (L.cpu s) s1 s2 := cc1.fkiN h1 hX1.1 F2 - have cc2 := cc1.step K2 F2.2.1 - have K02 := K1.trans he K2 + have F02 : FFoot st Kp Il Ks T Cs Sg Scs Z (EH H) U s s2 := (FootN.ff F1).trans (FootN.ff F2) have dq2 : (L.mem s2 (inqA hd) &&& sched.Q_QUEUED) = 0#u64 := by rw [k2.inqf hdT, iq1]; exact dq have dr2 : (L.mem s2 (inqA hd) &&& sched.Q_RELEASE) = 0#u64 := by rw [k2.inqf hdT, iq1]; exact dr have da2 : L.actionW s2 ≠ hd := by rcases k2.act with e | e · rw [e, ea1]; exact da · rw [e]; exact fun e' => notT_small hT (by simp) (e' ▸ hdT) - refine WP.spec_mono (signal_tail.ff (Kp := KI st T Cs (L.cpu s) s2) (Il := IlAt st Cs s2) (Ks := KsAt st Cs s2) - (Es := ∅) (U := ∅) hA s2 a hd n badge Q R h2' hB2 hX2 hS2 hSg2 hdT hn dq2 dr2 da2 + refine WP.spec_mono (signal_tail.ff (Kp := Kp) (Il := Il) (Ks := Ks) (Es := EH H) (U := U) hA s2 a hd n badge + Q R h2' hB2 hX2 hS2 hSg2 hdT hn dq2 dr2 da2 (fun e => hB.idleNB (by rw [← ei1, ← k2.idleW, e]; exact Or.inl hbl)) (by rw [st2]; rintro (hb | hb); exact not_blocked_running hb; exact running_ne.1 hb) - (by rw [K02.kiEq he]; exact hdK) (by rw [K02.ilEq]; exact hdI) cc2.ksS (cc2.ks0 hT hX2) (cc2.aoK h2')) ?_ + hdK hdI hKsS (hKs' s2 F02) (F02.out hKa)) ?_ rintro ⟨s', a'⟩ ⟨-, F'⟩ - exact K02.trans he (cc2.fki h2' hX2.1 F') + exact F02.trans F' · -- an active notification step with obj.Ntfn.badge.val as ⟨i, ei⟩ simp only [lift, Aeneas.Std.bind_ok] refine WP.spec_bind (obj.Ntfn.set_badge.wr s n _) fun s1 e1 => ?_ subst e1 - exact (WP.spec_ok _).2 (c.fkiN h0 hX.1 (ntfn_bd.fn (Kp := KI st T Cs (L.cpu s) s) (Nd := True) (Sg := Sg) - (Scs := Scs) (Z := Z) (Es := ∅) n _ h0.nodes h0.cur hX.1 hn (h0.omega _ (hSg.sub _ (hX.1.ntB n hn).1)))) + exact (WP.spec_ok _).2 (FootN.ff (ntfn_bd.fn (Kp := Kp) (Nd := True) (Sg := Sg) (Scs := Scs) (Z := Z) + (Es := EH H) n _ h0.nodes h0.cur hX.1 hn (h0.omega _ (hSg.sub _ (hX.1.ntB n hn).1)))) + +/-- **`send_signal` is an `FKI` step** (P1 `send_signal.tinvFK`): the woken +thread is blocked or a `RUNNING_VM` thread `signal_completes` accepts, so none +of `KI` and no idle thread (`FCtx.blk`, `FCtx.vm`). (mmuAD gen 42b73) `send_signal.ffG` at `KI` / `IlAt` / `KsAt`, +statement unchanged. -/ +theorem notification.send_signal.fk {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) + (s : S) (a : A) (n badge : U64) (h : TInv st T Cs Ω H Sg Rp Scs Nt Z Ac s) (hn : n ∈ Nt) + (hH : H n = some .ntfn) (hU : ∀ b ∈ U, UsrW st T Cs H Sg Scs Z s b) + (hbuf : ∀ y ∈ T, msg.lookup_ipc_buffer st s true y ⦃ b => BufOK U b ⦄) + (c : FCtx st T Cs Scs (L.cpu s) s) : + notification.send_signal st ar s a n badge ⦃ s' _ => FKI st T Cs (L.cpu s) s s' ⦄ := by + have hI := h + obtain ⟨⟨Q, R, h0⟩, -, hX, -, -⟩ := h + refine WP.spec_mono (notification.send_signal.ffG (Kp := KI st T Cs (L.cpu s) s) (Il := IlAt st Cs s) + (Ks := KsAt st Cs s) hA s a n badge hI hn hH hU hbuf (c.aoK h0) c.ksS (c.ks0 h0.tcbs hX) + (fun _ _ _ hst => c.blk (by rw [hst]; exact Or.inr (Or.inl rfl))) + (fun i _ _ hst => WP.spec_mono (vcpu.signal_completes.aff s i) fun _ ha hv => c.vm hst (ha hv)) + (fun hst1 => c.blk (by rw [(ntfn_head h0 hH hst1).2.2]; exact Or.inr (Or.inr rfl)))) ?_ + rintro ⟨s', a'⟩ F + exact c.fki h0 hX.1 F end diff --git a/proofs/Fl4Proofs/P3/DeadKeep.lean b/proofs/Fl4Proofs/P3/DeadKeep.lean index 7b0918b5d..a1c40bcdb 100644 --- a/proofs/Fl4Proofs/P3/DeadKeep.lean +++ b/proofs/Fl4Proofs/P3/DeadKeep.lean @@ -298,9 +298,9 @@ theorem JAtZ.ksW_scKeep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.He /-- **`H`'s SC words are kept by scheduler writes** (`H`'s objects disjoint from the TCBs, apart from the node and the kernel-state block). -/ -theorem JAtZ.schW_scKeep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +theorem JAtZB.schW_scKeep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) {q : U64} {z : Nat} (hq : H q = some (.sc z)) {K : U64} (hK8 : K.val % 8 = 0) (hK : K.val < 128) : L.mem s' (scW q K) = L.mem s (scW q K) := by obtain ⟨hal, hv, hf⟩ := J.scW_in hq hK8 hK @@ -322,6 +322,14 @@ theorem JAtZ.schW_scKeep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.H · omega · omega +/-- `JAtZB.schW_scKeep` at `JAtZ` (mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem JAtZ.schW_scKeep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) + {q : U64} {z : Nat} (hq : H q = some (.sc z)) {K : U64} (hK8 : K.val % 8 = 0) (hK : K.val < 128) : + L.mem s' (scW q K) = L.mem s (scW q K) := + J.toB.schW_scKeep hw hq hK8 hK + /-- **The dead stay dead across a heap-keeping step** (`deadP_keep` with every object but the CNodes kept, `HStep`). -/ theorem JAtZB.deadP_hstep {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} diff --git a/proofs/Fl4Proofs/P3/EpSched.lean b/proofs/Fl4Proofs/P3/EpSched.lean index 3911daba2..bcc269b47 100644 --- a/proofs/Fl4Proofs/P3/EpSched.lean +++ b/proofs/Fl4Proofs/P3/EpSched.lean @@ -95,14 +95,16 @@ theorem EpStateRel.at_reply {m : U64 → U64} {σ : Fl4Spec.State Unit} (hR : Ep /-- A related TCB with a new state whose payload the relation ignores, from memory that agrees on all of its fields but the state word. -/ -theorem TcbRelE.with_state {m m' : U64 → U64} {t : U64} {x : Fl4Spec.Tcb} (ht : TcbAddr t) - (h : TcbRelE R m t x) (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) +theorem TcbRelE.with_stateVM {m m' : U64 → U64} {t : U64} {x : Fl4Spec.Tcb} (ht : TcbAddr t) + (h : TcbRelE R m t x) (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3 ∨ ts = .runningVM) (hst : (m' (tStA t)).val = tsCode ts) (hA : Agree m m' (fun b => TF t b ∧ b.val ≠ (tStA t).val)) : TcbRelE R m' t { x with tcbState := ts } := by have g : ∀ {b}, Aligned b ∧ TF t b → b.val ≠ (tStA t).val → m' b = m b := fun hb hne => hA _ hb.1 ⟨hb.2, hne⟩ have v := val_st ht refine ⟨hst, fun e he => ?_, fun e d he => ?_, fun e r d he => ?_, fun r he => ?_, fun r => ?_, ?_, ?_, ?_, ?_, ?_⟩ - · cases ts <;> simp [tsCode, Fl4Spec.epBlocked] at hts he + · rcases hts with hts | rfl + · cases ts <;> simp [tsCode, Fl4Spec.epBlocked] at hts he + · cases he · subst he; simp [tsCode] at hts · subst he; simp [tsCode] at hts · subst he; simp [tsCode] at hts @@ -113,6 +115,13 @@ theorem TcbRelE.with_state {m m' : U64 → U64} {t : U64} {x : Fl4Spec.Tcb} (ht · rw [g (a_bound ht) (by rw [val_bound ht, v]; omega)]; exact h.bound · exact h.faultR.congr (g (a_fault ht) (by rw [val_fault ht, v]; omega)) (g (a_fw0 ht) (by rw [val_fw0 ht, v]; omega)) (g (a_fw1 ht) (by rw [val_fw1 ht, v]; omega)) (g (a_lf ht) (by rw [val_lf ht, v]; omega)) (g (a_lf0 ht) (by rw [val_lf0 ht, v]; omega)) (g (a_lf1 ht) (by rw [val_lf1 ht, v]; omega)) (g (a_fw2 ht) (by rw [val_fw2 ht, v]; omega)) +/-- The native-state instance. -/ +theorem TcbRelE.with_state {m m' : U64 → U64} {t : U64} {x : Fl4Spec.Tcb} (ht : TcbAddr t) + (h : TcbRelE R m t x) (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) + (hst : (m' (tStA t)).val = tsCode ts) (hA : Agree m m' (fun b => TF t b ∧ b.val ≠ (tStA t).val)) : + TcbRelE R m' t { x with tcbState := ts } := + h.with_stateVM ht ts (Or.inl hts) hst hA + theorem tf_ne_of {t a b : U64} (hb : ¬ TF t b) (ha : TF t a) : b.val ≠ a.val := fun e => hb (ha.of_val e) section @@ -121,10 +130,10 @@ variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulSt /-- Writing the state word of a TCB in no endpoint queue: related to the spec's TCB with the new (unblocked) state. -/ -theorem write_state_rel (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) +theorem write_state_relVM (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hq : ∀ e ∈ E, ∀ z, σ.kheap e.bv = some (.endpoint z) → t.bv ∉ z.epQueue) - (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) (code : U64) (hcode : code.val = tsCode ts) : + (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3 ∨ ts = .runningVM) (code : U64) (hcode : code.val = tsCode ts) : EpStateRel T E R B (L.mem (L.wr s (tStA t) code)) (updK σ t.bv (.tcb { x with tcbState := ts })) ∧ WritesIn st s (L.wr s (tStA t) code) (EWrite T E R B) ∧ EpStep σ (updK σ t.bv (.tcb { x with tcbState := ts })) := by @@ -133,13 +142,23 @@ theorem write_state_rel (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) have ha := a_st hta have hag := agree_wr (L := L) (s := s) (v := code) ha.1 refine ⟨hR.upd_tcb hP ht _ (hag.mono fun b hb => tf_ne_of hb.2 ha.2) (Or.inl hq) - (hx.with_state hta ts hts (by rw [rd_wr_eq ha.1]; exact hcode) (hag.mono fun b hb => hb.2)), ?_, + (hx.with_stateVM hta ts hts (by rw [rd_wr_eq ha.1]; exact hcode) (hag.mono fun b hb => hb.2)), ?_, EpStep.tcb hk ts x.tcbArch⟩ refine (writesIn_wr ha.1).mono fun b hb => ?_ subst hb refine Or.inr (Or.inr (Or.inl ⟨t, ht, Or.inl ⟨ha.2.1, ?_⟩⟩)) rw [val_st hta]; unfold TWOffN; omega +/-- The native-state instance. -/ +theorem write_state_rel (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) + {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hq : ∀ e ∈ E, ∀ z, σ.kheap e.bv = some (.endpoint z) → t.bv ∉ z.epQueue) + (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) (code : U64) (hcode : code.val = tsCode ts) : + EpStateRel T E R B (L.mem (L.wr s (tStA t) code)) (updK σ t.bv (.tcb { x with tcbState := ts })) ∧ + WritesIn st s (L.wr s (tStA t) code) (EWrite T E R B) ∧ + EpStep σ (updK σ t.bv (.tcb { x with tcbState := ts })) := + write_state_relVM hP s σ hR ht hk hq ts (Or.inl hts) code hcode + /-- **`set_thread_state t ts`** for a thread in no endpoint queue and a state that is `Inactive`, `Running` or `Restart`. -/ theorem set_thread_state_rel (hH : EpHyps st T E R B SR) (hP : EPlaced T E R B) (s : S) diff --git a/proofs/Fl4Proofs/P3/EptFinIo.lean b/proofs/Fl4Proofs/P3/EptFinIo.lean index 2ed2bb66b..0843a2bc5 100644 --- a/proofs/Fl4Proofs/P3/EptFinIo.lean +++ b/proofs/Fl4Proofs/P3/EptFinIo.lean @@ -33,6 +33,7 @@ through `JAtZV3`. New file; the in-place generalisation it uses is P3/JAtZV3VDio -/ import Fl4Proofs.P3.EptDelVcpu import Fl4Proofs.P3.JAtZV3VDio +import Fl4Proofs.P3.JAtZV3SlotIo open Aeneas Aeneas.Std Result namespace Fl4Proofs.P3 @@ -288,30 +289,28 @@ theorem VmEptState.portsAt (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X (ioWOf_ne Ly.vfit Ly.vv hw hv (by omega)) exact ⟨Ac, Lst, J.ofF J4 htc, J4.ss, J4.fw.1, hw4⟩ +/-- The decoder walks the same list as finalisation, with the arguments reordered. -/ +theorem decode_loop3_eq_revoke (s : S) (a : A) (f l w head fuel : U64) : + vcpu.decode_loop3 st arI s a f l w head fuel = + vcpu.revoke_ports_loop st arI s a w f l head fuel := rfl + set_option maxHeartbeats 4000000 in -/-- **`vcpu::revoke_ports` at `VmEptState`, the four owner cases** (module docstring). -/ -theorem VmEptState.revokeV (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) - {f l w : U64} (hfl : f.val ≤ l.val) (hl : l.val < 65536) : - vcpu.revoke_ports st arI s a w f l ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), +/-- The list walk shared by finalisation and EnableIOPort. A zero owner is absent from the list. -/ +theorem VmEptState.revokeWalk (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {f l w : U64} (hfl : f.val ≤ l.val) (hl : l.val < 65536) + {a1 : A} (har1 : AR a1 σ.archState.x64CurrentCr3) : + (do + let head ← obj.ks_get st s layout.ks.VCPU_HEAD + vcpu.revoke_ports_loop st arI s a1 w f l head layout.WALK_FUEL) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.ioPortRevoke (Z := Unit) (.ioPortCap (BitVec.ofNat 16 f.val) (BitVec.ofNat 16 l.val) (ioOwnerOf w)) σ = ({((), σ')}, False) ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ SlotsSame Z.th (L.mem s) (L.mem r.1) ∧ L.ksb r.1 = L.ksb s ⦄ := by have B := J.1.1 have C := J.1.2 - have har := B.ar - unfold vcpu.revoke_ports - split - · rename_i hw0 - subst hw0 - rw [WP.spec_ok] - exact ⟨σ, Ac, Lst, Fl4Spec.ioPortRevoke_eq fun _ h => by simp [Fl4Spec.ioPortOwner] at h, J, - SlotsSame.refl _ _, rfl⟩ - rename_i hw0 - have hwv : w.val ≠ 0 := fun e => hw0 (UScalar.eq_of_val_eq (by rw [e]; rfl)) - have hown : ioOwnerOf w = some w.bv := by simp [ioOwnerOf, hwv] - rw [hown] - refine WP.spec_bind (hK.vcpu_barrier a _ har) fun a1 har1 => ?_ + have hown : w ≠ 0#u64 → ioOwnerOf w = some w.bv := fun hw => by + have hv : w.val ≠ 0 := fun e => hw (UScalar.eq_of_val_eq (by rw [e]; rfl)) + simp [ioOwnerOf, hv] refine WP.spec_bind (obj.ks_get.spec s _) fun v ev => ?_ have ev' : v = L.mem s (P1.vHeadA st s) := ev subst ev' @@ -353,6 +352,7 @@ theorem VmEptState.revokeV (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X (ioWOf_ne Ly.vfit Ly.vv hwV huV (by omega))) _ hfuel har1) ?_ rintro r ⟨Ac', Lst', J', hSS, hks, -⟩ + rw [hown (C.extv.nz w hwV)] exact ⟨_, Ac', Lst', ioPortRevoke_live hk, J', hSS, hks⟩ · -- a stale owner: no FL4 write refine WP.spec_mono (revoke_loop_list (Ra := fun a2 => AR a2 σ.archState.x64CurrentCr3) @@ -363,6 +363,11 @@ theorem VmEptState.revokeV (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X simp only at e har' subst s' have J1 : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a' σ := ⟨⟨J.1.1.archV har', J.1.2⟩, J.2⟩ + by_cases hw0 : w = 0#u64 + · subst w + exact ⟨σ, Ac, Lst, Fl4Spec.ioPortRevoke_eq fun _ h => by simp [Fl4Spec.ioPortOwner, ioOwnerOf] at h, + J1, SlotsSame.refl _ _, rfl⟩ + rw [hown hw0] cases hv : Fl4Spec.vcpuAt σ w.bv with | none => exact ⟨σ, Ac, Lst, Fl4Spec.ioPortRevoke_eq fun u h => by @@ -377,6 +382,116 @@ theorem VmEptState.revokeV (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X exact ⟨_, Ac, Lst, ioPortRevoke_live hk, J1.deadSpec hwV hk _ rfl, SlotsSame.refl _ _, rfl⟩ +set_option maxHeartbeats 4000000 in +/-- **`vcpu::revoke_ports` at `VmEptState`, the four owner cases** (module docstring). -/ +theorem VmEptState.revokeV (hK : ARKeep arI AR) (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {f l w : U64} (hfl : f.val ≤ l.val) (hl : l.val < 65536) : + vcpu.revoke_ports st arI s a w f l ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.ioPortRevoke (Z := Unit) (.ioPortCap (BitVec.ofNat 16 f.val) (BitVec.ofNat 16 l.val) (ioOwnerOf w)) σ = + ({((), σ')}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ + SlotsSame Z.th (L.mem s) (L.mem r.1) ∧ L.ksb r.1 = L.ksb s ⦄ := by + unfold vcpu.revoke_ports + split + · rename_i hw0 + subst w + rw [WP.spec_ok] + exact ⟨σ, Ac, Lst, Fl4Spec.ioPortRevoke_eq fun _ h => by simp [Fl4Spec.ioPortOwner, ioOwnerOf] at h, + J, SlotsSame.refl _ _, rfl⟩ + exact WP.spec_bind (hK.vcpu_barrier a _ J.1.1.ar) fun _ har1 => J.revokeWalk hK hfl hl har1 + + +set_option maxHeartbeats 4000000 in +/-- Write an EnableIOPort owner while retaining the VCPU and EPT relations. -/ +theorem VmEptState.ioOwnJ (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {pc : U64} {r : Nat} {idx : List Bool} (hpc : Z.th pc = some (.cnode r)) (hidx : idx.length = r) + {f l prior : U64} (hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort f l prior) + {p : U64} (hcan : Canonical p) : + obj.Slot.set_cap st (cslotAddr (pc.bv, idx)) s (.IoPort f l p) ⦃ s' => + ∃ σ', Fl4Spec.setCap (Z := Unit) (absCap (.IoPort f l p)) (pc.bv, idx) σ = ({((), σ')}, False) ∧ + (∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a σ' ⦄ := by + have B := J.1.1 + have C := J.1.2 + have E := J.2 + refine WP.spec_mono (J.toB.ioOwnJ hpc hidx hcx hcan) ?_ + rintro s' ⟨σ', hsc, hvk, J', F, hc', hw⟩ + let x := cslotAddr (pc.bv, idx) + have hcap : ∀ y, IsSlot Z.th y → ∀ p lv mm a v, + capV (L.mem s') y = .Ept p lv mm a v ↔ capV (L.mem s) y = .Ept p lv mm a v := by + intro y hy p lv mm a v + by_cases e : y = x + · subst y + simp [hcx, hc', x] + · rw [F.cap y hy e] + have hframe : ∀ y, IsSlot Z.th y → ∀ p sz r d a v, + capV (L.mem s') y = .Frame p sz r d true true a v → capV (L.mem s) y = .Frame p sz r d true true a v := by + intro y hy p sz r d a v h + by_cases e : y = x + · subst y + rw [show x = cslotAddr (pc.bv, idx) from rfl, hc'] at h + cases h + · rwa [F.cap y hy e] at h + have hExt : JExtEpt (L := L) X Z.th s' := + ⟨fun y hy => by + by_cases e : y = x + · rw [e, show x = cslotAddr (pc.bv, idx) from rfl, hc']; trivial + · rw [F.cap y hy e]; exact E.exte.cap y hy, + ⟨fun y hy p l a v h => E.exte.vtop.1 y hy p l a v ((hcap y hy p l true a v).1 h), + fun y hy p sz r d a v h => E.exte.vtop.2 y hy p sz r d a v (hframe y hy p sz r d a v h)⟩, + fun y hy p l a v h => E.exte.anz y hy p l a v ((hcap y hy p l true a v).1 h)⟩ + have hPool : ∀ hi lo e, PoolAt σ' hi lo e → PoolAt σ hi lo e := by + rintro hi lo e ⟨p, f, h1, h2, h3⟩ + exact ⟨p, f, by simpa only [F.asid] using h1, (F.archObj p _).1 h2, h3⟩ + have hObj : ∀ q lv es, σ'.kheap q = some (.archObj (.ept lv es)) → + σ.kheap q = some (.archObj (.ept lv es)) := fun q lv es => (F.archObj q (.ept lv es)).1 + have E' : EptCore (L := L) X XL Z.th s' σ' := by + refine E.frame hw (fun b hb t ht => ?_) (fun y hy p l a v mm hc => ⟨hy, (hcap y hy p l mm a v).1 hc⟩) + hExt (fun t ht => ?_) (fun q l es h => ⟨l, es, hObj q l es h⟩) + (fun e ⟨hi, p, f, lo, h1, h2, h3⟩ => ⟨hi, p, f, lo, by simpa only [F.asid] using h1, (F.archObj p _).1 h2, h3⟩) + F.size (fun t ht => Or.inr (Or.inr ⟨ht, ?_⟩)) ?_ + · have hH := (B.cslot_other hpc hidx).1 + have hne : pc ≠ t := fun e => by + subst pc + obtain ⟨_, ht', _⟩ := E.rel.obj t ht + obtain ⟨cn, hk, -⟩ := B.xtop.rel.2.1.1.cnode t r hpc + rw [hk] at ht' + cases ht' + have hap := B.eptApartH E ht pc _ hH hne + obtain ⟨h1, h2, -, -⟩ := B.cslotW_val hpc hidx hb + simp only [P1.HKind.bits] at hap + rcases hap with h | h <;> omega + · obtain ⟨es, hk, -⟩ := E.rel.obj t ht + exact ((F.archObj t.bv _).2 hk).trans hk.symm + · have he : cslotAddr (t.bv, Fl4Spec.tcbCnodeIndex 5) = slotOf t 5 := by + show slotAddr t.bv (Fl4Spec.ofBl _) = _ + rw [slotAddr_ofBl, tcbCnodeIndex_blVal 5 (by decide)] + rw [he] + exact F.tcbSlot t ht 5 (by decide) + · exact E.named.frameA F.asid (fun hi lo e h _ => hPool hi lo e h) hObj + (fun y p lv a v hy hc _ => ⟨y, hy, (hcap y hy p lv true a v).2 hc⟩) + (fun y p lv mm a v hy hc => ⟨y, hy, (hcap y hy p lv mm a v).1 hc⟩) + (fun _ _ _ _ _ _ y p lv a v hy _ hl hc => ⟨y, lv, a, v, hy, hl, (hcap y hy p lv true a v).2 hc⟩) + refine ⟨σ', hsc, hvk, ⟨⟨J'.base, J'.extv, J'.vo, J'.vr, ?_, J'.rvm, J'.vm, J'.vl, J'.vb, ?_, ?_⟩, E'⟩⟩ + · have hM := B.xtop.rel.2.1.2.2.1 + refine VirtRngOne.rngOne_congr C.rngOne fun y hy _ => ?_ + by_cases e : y = x + · subst y + rw [show x = cslotAddr (pc.bv, idx) from rfl, hc', hcx] + exact ⟨rfl, rfl, rfl, rfl, rfl⟩ + · rw [F.cap y ((hM.members y).1 hy).1 e] + exact NoA.refl _ + · intro u hu + obtain ⟨y, hy, hc⟩ := C.vcap u hu + have hne : y ≠ x := by + rintro rfl + rw [show x = cslotAddr (pc.bv, idx) from rfl, hcx] at hc + cases hc + exact ⟨y, hy, (F.cap y hy hne).trans hc⟩ + · exact C.tcap.of_update F.bound (fun t e => by + rw [hcx] at e + cases e) F.cap + /-- FL4's `finalise_cap` of an IO-port cap (objects.rs): `revoke_ports`, then the cap as the cleanup cap when final. -/ theorem finCap_ioPort_eq (s : S) (a : A) (f l w : U64) (fin : Bool) : objects.finalise_cap st arI s a (.IoPort f l w) fin false = (do diff --git a/proofs/Fl4Proofs/P3/EptReport.lean b/proofs/Fl4Proofs/P3/EptReport.lean index 7664c9337..7e0baf174 100644 --- a/proofs/Fl4Proofs/P3/EptReport.lean +++ b/proofs/Fl4Proofs/P3/EptReport.lean @@ -132,12 +132,11 @@ theorem EptCore.ofFoot (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (Jv : (fun y p lv mm a v hy hc => ⟨y, hy, by rw [← hS.capV hy]; exact hc⟩) (fun _ _ _ _ _ _ y _ _ _ _ hy _ hl hc => ⟨y, _, _, _, hy, hl, by rw [hS.capV hy]; exact hc⟩) -/-- **`VmEptState` at the end of a run from a `VmEptState` state** (module docstring): `htc`, no bound VCPU's `TCB` -word changed. -/ -theorem VmEptState.ofF (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {Ac' : Set U64} +/-- Rebuild the VM relation after a run with a witness for each bound TCB. -/ +theorem VmEptState.ofFTCap (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} (J' : VmBaseF (L := L) arI s σ V AR Z H Cs Ac' Lst' D' s' a' σ') - (htc : ∀ v ∈ V, L.mem s' (vTcbA v) ≠ 0#u64 → L.mem s' (vTcbA v) = L.mem s (vTcbA v)) : + (htc : TCappedM V Z.th (L.mem s')) : VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' s' a' σ' := by have hS := J'.ss obtain ⟨-, ⟨-, -, hM, -, -⟩, -⟩ := J.1.1.xtop.rel @@ -147,9 +146,47 @@ theorem VmEptState.ofF (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s J'.rvm, J'.vm, J'.vl, J'.vb, fun v hv => by obtain ⟨y, hy, hc⟩ := J.1.2.vcap v hv exact ⟨y, hy, (hS.capV hy).trans hc⟩, - J.1.2.tcap.of_caps (fun v hv h => ⟨hv, htc v hv h⟩) fun y hy _ hc => ⟨y, hy, (hS.capV hy).trans hc⟩⟩, + htc⟩, J.2.ofFoot J.1.1 J.1.2.vm J'.base J'.toVmFoot⟩ +/-- **`VmEptState` at the end of a run from a `VmEptState` state** (module docstring): `htc`, no bound VCPU's `TCB` +word changed. -/ +theorem VmEptState.ofF (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {Ac' : Set U64} + {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} + (J' : VmBaseF (L := L) arI s σ V AR Z H Cs Ac' Lst' D' s' a' σ') + (htc : ∀ v ∈ V, L.mem s' (vTcbA v) ≠ 0#u64 → L.mem s' (vTcbA v) = L.mem s (vTcbA v)) : + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' s' a' σ' := + J.ofFTCap J' (J.1.2.tcap.of_caps (fun v hv h => ⟨hv, htc v hv h⟩) fun y hy _ hc => + ⟨y, hy, (J'.ss.capV hy).trans hc⟩) + +/-- Matching spec bindings determine the concrete bound-thread words. -/ +theorem VBind.word_eq {σ' : Fl4Spec.State Unit} {m m' : U64 → U64} + (h : VBind V σ m) (h' : VBind V σ' m') {v : U64} (hv : v ∈ V) + (ht : ∀ old new, σ.kheap v.bv = some (.archObj (.vcpu old)) → + σ'.kheap v.bv = some (.archObj (.vcpu new)) → old.tcb = new.tcb) : + m' (vTcbA v) = m (vTcbA v) := by + obtain ⟨old, ho, hb⟩ := h v hv + obtain ⟨new, hn, hb'⟩ := h' v hv + have ht := ht old new ho hn + rcases hb with ⟨e, hm⟩ | ⟨t, -, e, hm⟩ <;> + rcases hb' with ⟨e', hm'⟩ | ⟨t', -, e', hm'⟩ + · exact hm'.trans hm.symm + · rw [e, e'] at ht + cases ht + · rw [e, e'] at ht + cases ht + · rw [e, e', Option.some.injEq] at ht + rw [hm', hm, P1.eq_of_bv ht] + +/-- Rebuild the VM relation when only the contents of VCPUs change. -/ +theorem VmEptState.ofFBind (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {Ac' : Set U64} + {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} + (J' : VmBaseF (L := L) arI s σ V AR Z H Cs Ac' Lst' D' s' a' σ') + (ht : ∀ v ∈ V, ∀ old new, σ.kheap v.bv = some (.archObj (.vcpu old)) → + σ'.kheap v.bv = some (.archObj (.vcpu new)) → old.tcb = new.tcb) : + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' s' a' σ' := + J.ofF J' fun v hv _ => J.1.2.vb.word_eq J'.vb hv (ht v hv) + /-- **A native step's words miss every VCPU image of `V`** (module docstring): an `OObj` word by `JAtZB.oobjV`, a timer head (below `ksb + 288000`) by `JVm.ks`. -/ theorem JAtZB.natV (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (Jv : JVm (L := L) V H s σ) {b : U64} @@ -247,6 +284,33 @@ theorem VmEptState.detachF2 (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ DetMem st V Z.th t s r.1 ⦄ := WP.spec_mono (J.detachF2S hA hVA hK ht) fun _ ⟨σ', Ac', Lst', h1, J', DM, _, _⟩ => ⟨σ', Ac', Lst', h1, J', DM⟩ + +/-- The two binding writes preserve the VM relation when the extra slot names the target thread. -/ +theorem VmEptState.bind (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {t v x : U64} + (ht : Z.th t = some .tcb) (hv : v ∈ V) (hw0 : L.mem s (tVcpuA t) = 0#u64) + (hb0 : L.mem s (vTcbA v) = 0#u64) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap v.bv = some (.archObj (.vcpu vs))) (hx : IsSlot Z.th x) + (hc : capV (L.mem s) x = .Thread t) : + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D (L.wr (L.wr s (vTcbA v) t) (tVcpuA t) v) a + (Notif.updK σ v.bv (.archObj (.vcpu { vs with tcb := some t.bv }))) := by + have J' := J.toF.bind ht hv hw0 hb0 hk { vs with tcb := some t.bv } rfl + have P := J.1.1.jwPl J.1.2.vm + have halv := P.jw _ (Or.inr (Or.inr ⟨v, hv, rfl⟩)) + have halt := P.jw _ (Or.inr (Or.inl ⟨t, ht, rfl⟩)) + refine J.ofFTCap J' ?_ + intro u hu h0 + have halu := P.jw _ (Or.inr (Or.inr ⟨u, hu, rfl⟩)) + have hne := P.vb t ht u hu + rw [L.mem_wr_ne halt halu (fun e => hne (UScalar.eq_of_val_eq e))] at h0 ⊢ + by_cases e : v = u + · subst u + rw [L.mem_wr_same halv] + exact ⟨x, hx, (J'.ss.capV hx).trans hc⟩ + · have hvu : (vTcbA v).val ≠ (vTcbA u).val := fun he => e (vTcbA_inj (UScalar.eq_of_val_eq he)) + rw [L.mem_wr_ne halv halu hvu] at h0 ⊢ + obtain ⟨y, hy, he⟩ := J.1.2.tcap u hu h0 + exact ⟨y, hy, (J'.ss.capV hy).trans he⟩ + end end diff --git a/proofs/Fl4Proofs/P3/G7dVsRoot.lean b/proofs/Fl4Proofs/P3/G7dVsRoot.lean index 38cb8399e..22fba6461 100644 --- a/proofs/Fl4Proofs/P3/G7dVsRoot.lean +++ b/proofs/Fl4Proofs/P3/G7dVsRoot.lean @@ -62,20 +62,28 @@ section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} {AR : A → Fl4Spec.Cr3 → Prop} -/-- **`VsRootOK` at a `JAtZR` state** (module docstring). -/ -theorem JAtZR.vsRootOK {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} - {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) : +/-- **`VsRootOK` at a joint state** (module docstring; (mmuAD gen 42b80) `JAtZR.vsRootOK`'s proof over the fields +it reads, shared by `JAtZR` and `JAtZB`). -/ +theorem vsRootOK_ofJ {Z : XSets} {H : P1.Heap} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (hX : XTopAt (L := L) AR Z s a σ) (hjpl : ∃ Tr Cq, Sched.JPlaced (L := L) Z.th H Tr Cq s σ) + (hzH : ∀ t ∈ Z.T, H t = some .tcb) (hvsc : Vs.VsSlotsW Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s)) : VsRootOK Z.T σ := by - refine vsRootOK_of J.xtop.rel.2.1.1 J.xtop.fin.2.1 fun t ht => ?_ - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hth : Z.th t = some .tcb := (hJ.tcb t).2 (J.zH.1 t ht) + refine vsRootOK_of hX.rel.2.1.1 hX.fin.2.1 fun t ht => ?_ + obtain ⟨Tr, Cq, hJ⟩ := hjpl + have hth : Z.th t = some .tcb := (hJ.tcb t).2 (hzH t ht) refine ⟨hth, fun p asid hc => ?_⟩ have hx : IsSlot Z.th (slotOf t 1) := ⟨t, 1, Or.inr ⟨hth, by decide⟩, rfl⟩ - have h := J.vsc _ hx + have h := hvsc _ hx rw [capV_of_capAt hc] at h have h' : (true = false → p ∈ _) ∧ p ≠ 0#u64 ∧ (true = true → asid ≠ 0#u64 ∧ asid.val < 2 ^ 20) := h exact (h'.2.2 rfl).1 +/-- **`VsRootOK` at a `JAtZR` state** (module docstring; `vsRootOK_ofJ`). -/ +theorem JAtZR.vsRootOK {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) : + VsRootOK Z.T σ := + vsRootOK_ofJ J.xtop J.jpl J.zH.1 J.vsc + end end diff --git a/proofs/Fl4Proofs/P3/G7eChain.lean b/proofs/Fl4Proofs/P3/G7eChain.lean index 9e9a21f50..407a1422a 100644 --- a/proofs/Fl4Proofs/P3/G7eChain.lean +++ b/proofs/Fl4Proofs/P3/G7eChain.lean @@ -575,7 +575,8 @@ theorem schedule_refinesWP0FRA (hRef : ArchRefines ar AR) (hSt : P0.StoreTotal s (hK : ARKeep ar AR) {N T C P : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hnd : Fl4Spec.numDomains = 1) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW0R T C σ1 ∧ ((σ1.domainTime ≠ 0 ∨ NdOK (L := L) r.1 σ1) ∧ (∀ n ∈ N, n.val + 40 ≤ (L.ksb r.1).val ∨ (L.ksb r.1).val + 13568 ≤ n.val) ∧ Pf r σ1) ⦄) @@ -585,7 +586,7 @@ theorem schedule_refinesWP0FRA (hRef : ArchRefines ar AR) (hSt : P0.StoreTotal s (hA : ArchSwF st ar N T C c) (hAN : ArchNdF st N T C c) (hsni : SniHyp st ar N T C c) (hsend : SendHyp st ar N T C c) (hT : TimeAgree ar) : - sched.schedule st ar s a ⦃ r => ∃ σ1 σ', Fires σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + sched.schedule st ar s a ⦃ r => ∃ σ1 σ', F σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1 ∧ WritesIn st rf.1 r.1 (KFootN st T N C c rf.1 σ1) ∧ ∃ σ3 : Fl4Spec.State Unit, OffOK σ3 ∧ (RunM σ1 → RunW σ3) ∧ @@ -657,7 +658,7 @@ theorem schedule_refinesWP0FRA (hRef : ArchRefines ar AR) (hSt : P0.StoreTotal s let s8 ← obj.node_set st s7 c layout.node.REPROGRAM 0#u64 ok (s8, a5) else ok (s5, a3) - smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', Fires σ σ1' ∧ + smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', F σ σ1' ∧ Fl4Spec.schedule (Z := Unit) σ1' = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1' ∧ WritesIn st rf.1 r.1 (KFootN st T N C c rf.1 σ1') ∧ diff --git a/proofs/Fl4Proofs/P3/G7eRoot.lean b/proofs/Fl4Proofs/P3/G7eRoot.lean index 8873d22bd..826847844 100644 --- a/proofs/Fl4Proofs/P3/G7eRoot.lean +++ b/proofs/Fl4Proofs/P3/G7eRoot.lean @@ -110,35 +110,39 @@ theorem sfootN_kr {N T C : Set U64} {c : U64} {s : S} {σ : Fl4Spec.State Unit} variable {arI : machine.Arch A} {AR : A → Fl4Spec.Cr3 → Prop} set_option maxHeartbeats 2000000 in -/-- **`RootFr` at a `JAtZR` state** (module docstring). -/ -theorem JAtZR.rootFr {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} - {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hIV : IdleVt σ) : +/-- **`RootFr` at a joint state** (module docstring; (mmuAD gen 42b80) `JAtZR.rootFr`'s proof over the fields it +reads, shared by `JAtZR` and `JAtZB`). -/ +theorem rootFr_of {Z : XSets} {H : P1.Heap} {Cs D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (hX : XTopAt (L := L) AR Z s a σ) (hK : JKern (L := L) arI H Cs D Z.th s σ) + (hnk : ∀ n ∈ Z.N, n.val + 40 ≤ (L.ksb s).val ∨ (L.ksb s).val + 13568 ≤ n.val) + (hjpl : ∃ Tr Cq, Sched.JPlaced (L := L) Z.th H Tr Cq s σ) (hzH : ∀ t ∈ Z.T, H t = some .tcb) + (hvsc : Vs.VsSlotsW Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s)) (hIV : IdleVt σ) : RootFr (L := L) AR Z.T Z.P Z.c s a σ := by intro s' σ' hw hk hc - have hS := J.xtop.fin.1.1.1 - have hTP := J.xtop.fin.1.2 - have hkf := J.kern.ksbFit - have hka := J.kern.ksbAl + have hS := hX.fin.1.1.1 + have hTP := hX.fin.1.2 + have hkf := hK.ksbFit + have hka := hK.ksbAl have hks : L.ksb s' = L.ksb s := hw.1 have hat : σ'.archState.x64AsidTable = σ.archState.x64AsidTable := congrArg (fun q => q.2.1) hc have hgp : σ'.archState.x64GlobalPml4 = σ.archState.x64GlobalPml4 := congrArg (fun q => q.2.2.1) hc have hid : σ'.idleThread = σ.idleThread := congrArg (fun q => q.2.2.2.1) hc have hout : ∀ b, P1.Aligned b → Vs.VObj Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.ksb s) b → L.mem s' b = L.mem s b := fun b hb hv => hw.mem_eq hb fun hf => hTP.disj b (sfootN_oobj hS hkf hf) hv - refine ⟨⟨_, J.xtop.fin.1.1.2.2.2.2.2.2⟩, ?_, ?_, ?_, hIV.frame hk hid⟩ + refine ⟨⟨_, hX.fin.1.1.2.2.2.2.2.2⟩, ?_, ?_, ?_, hIV.frame hk hid⟩ · rw [hks] - exact VsRel.frame J.xtop.fin.2.1 (fun b hb => hout b (VsWrite.aligned hTP.vs hb) (vsWrite_vobj hTP.vs hb)) hat + exact VsRel.frame hX.fin.2.1 (fun b hb => hout b (VsWrite.aligned hTP.vs hb) (vsWrite_vobj hTP.vs hb)) hat (fun p hp => by - obtain ⟨f, hf, -⟩ := J.xtop.fin.2.1.pool p hp + obtain ⟨f, hf, -⟩ := hX.fin.2.1.pool p hp rw [hf]; exact (hk.ntcb (fun _ e => by cases e)).2 hf) - · obtain ⟨hR, hH⟩ := J.xtop.fin.1.1.2.2.2.2.2.1 + · obtain ⟨hR, hH⟩ := hX.fin.1.1.2.2.2.2.2.1 have hhu : σ'.archState.x64Plat = σ.archState.x64Plat := congrArg (fun q => q.2.2.2.2) hc unfold KRootRel refine ⟨?_, ?_⟩ · unfold KRootW at hR ⊢ have e : core.num.U64.wrapping_add (L.ksb s) layout.ks.KERNEL_ROOT = ksW (L.ksb s) 48#u64 := by unfold layout.ks.KERNEL_ROOT; rfl - rw [hks, e, hw.mem_eq (ksW_al hkf hka (by decide) (by decide)) (sfootN_kr hS J.nk hkf)] + rw [hks, e, hw.mem_eq (ksW_al hkf hka (by decide) (by decide)) (sfootN_kr hS hnk hkf)] rw [e] at hR rw [hR]; unfold globCr3; rw [hgp] · rw [hks] @@ -146,18 +150,18 @@ theorem JAtZR.rootFr {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → have e72 : core.num.U64.wrapping_add (L.ksb s) layout.ks.FEATURES = ksW (L.ksb s) 72#u64 := by unfold layout.ks.FEATURES; rfl rw [e72] - exact hw.mem_eq (ksW_al hkf hka (by decide) (by decide)) (sfootN_feat hS J.nk hkf) + exact hw.mem_eq (ksW_al hkf hka (by decide) (by decide)) (sfootN_feat hS hnk hkf) · intro t ht - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hth : Z.th t = some .tcb := (hJ.tcb t).2 (J.zH.1 t ht) - obtain ⟨x, hkx, hsl⟩ := J.xtop.rel.2.1.1.tcb t hth + obtain ⟨Tr, Cq, hJ⟩ := hjpl + have hth : Z.th t = some .tcb := (hJ.tcb t).2 (hzH t ht) + obtain ⟨x, hkx, hsl⟩ := hX.rel.2.1.1.tcb t hth obtain ⟨cp, ac, hcp, hac, hca⟩ := hsl 1 (by decide) rw [tcbCnodeMap_one] at hac have hv : x.tcbVtable = absCap cp := by injection hac with h; rw [h, hca.2] have hcp' : capAt (L.mem s) (slotOf t 1) = ok cp := hcp obtain ⟨y, hy, ey⟩ := hk.tcb hkx have e1 : y.tcbVtable = x.tcbVtable := by have e2 := congrArg Fl4Spec.Tcb.tcbVtable ey.1; exact e2 - have hP := J.xtop.rel.1 + have hP := hX.rel.1 have hx : IsSlot Z.th (slotOf t 1) := ⟨t, 1, Or.inr ⟨hth, by decide⟩, rfl⟩ have hsv : (slotOf t 1).val = t.val + 32 * 1 := (show IsSlotAt Z.th t 1 from Or.inr ⟨hth, by decide⟩).val hP @@ -171,62 +175,25 @@ theorem JAtZR.rootFr {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → unfold Fl4Proofs.P3.capAt; rw [h0]; exact congrArg _ h8 refine ⟨y, cp, hy, hcap.trans hcp', e1.trans hv, fun p asid hpe => ?_⟩ subst hpe - have h := J.vsc _ hx + have h := hvsc _ hx rw [capV_of_capAt hcp'] at h have h' : (true = false → p ∈ _) ∧ p ≠ 0#u64 ∧ (true = true → asid ≠ 0#u64 ∧ asid.val < 2 ^ 20) := h exact (h'.2.2 rfl).1 +/-- **`RootFr` at a `JAtZR` state** (module docstring; `rootFr_of`). -/ +theorem JAtZR.rootFr {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hIV : IdleVt σ) : + RootFr (L := L) AR Z.T Z.P Z.c s a σ := + rootFr_of J.xtop J.kern J.nk J.jpl J.zH.1 J.vsc hIV + /-- **FL4's timers keep the kernel-global words** (`JAtZR.ndOK_fire`'s -argument). -/ +argument; (mmuAD gen 42b80) `JKern.fire_ks` at `kern`). -/ theorem JAtZR.fire_ks {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) {s1 : S} {U : Set U64} (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) : - ∀ o : U64, o.val < 256 → o.val % 8 = 0 → L.mem s1 (ksW (L.ksb s) o) = L.mem s (ksW (L.ksb s) o) := by - have hkf := J.kern.ksbFit - have hka := J.kern.ksbAl - have hks := J.kern.hks - have hH := J.kern.heap - have hKW := J.kwApartJ (s' := s) rfl (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) - intro o ho h8 - refine hf.mem_eq (ksW_al hkf hka ho h8) fun hb => ?_ - rcases hb with hb | hu - swap - · exact hU _ hu o (by omega) h8 rfl - have hv := ksW_val (kb := L.ksb s) (o := o) (by omega) - rcases hb with hb | hb - · rcases hKW _ (ksW_al hkf hka ho h8) hb with e | e <;> rw [hv] at e <;> omega - · rcases hb with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ - · have hy' : H y = some .tcb := hy - have hfit := hH.fits y _ hy' - simp only [P1.HKind.bits] at hfit - have h12 : (2 : Nat) ^ 12 = 4096 := by norm_num - rw [h12] at hfit - have hdv : (P1.dnA y).val = y.val + 3576 := by - unfold P1.dnA; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega - have h3 := hks y .tcb hy' (fun z h => by cases h) - simp only [P1.HKind.bits, h12] at h3 - have := congrArg UScalar.val e - rw [hv, hdv] at this - omega - · have hy' : H y = some .tcb := hy - have hfit := hH.fits y _ hy' - simp only [P1.HKind.bits] at hfit - have h12 : (2 : Nat) ^ 12 = 4096 := by norm_num - rw [h12] at hfit - have hdv : (P1.dpA y).val = y.val + 3584 := by - unfold P1.dpA; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega - have h3 := hks y .tcb hy' (fun z h => by cases h) - simp only [P1.HKind.bits, h12] at h3 - have := congrArg UScalar.val e - rw [hv, hdv] at this - omega - · have hnv := P1.nodeAt_val (J.blk.2.2.1.2.2.tm.npl c hc) (off := layout.node.DEBUG_TCBS) (by simp) - unfold P1.LawfulStore.nodeBase at hnv - have := congrArg UScalar.val e - rw [hv, hnv] at this - simp [layout.node.DEBUG_TCBS] at this - omega + ∀ o : U64, o.val < 256 → o.val % 8 = 0 → L.mem s1 (ksW (L.ksb s) o) = L.mem s (ksW (L.ksb s) o) := + J.kern.fire_ks (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) hf hU /-- The domain time read from the kernel-global word. -/ theorem fire_dt {N T C : Set U64} {c : U64} {s s1 : S} {σ σ1 : Fl4Spec.State Unit} @@ -238,18 +205,19 @@ theorem fire_dt {N T C : Set U64} {c : U64} {s s1 : S} {σ σ1 : Fl4Spec.State U rw [hs1.domTime, hs.domTime, dtA_ks, dtA_ks, hk, hm 16#u64 (by decide) (by decide)] set_option maxHeartbeats 2000000 in -/-- **`IdleVt` after FL4's timers** (module docstring). -/ -theorem JAtZR.idleVt_fire (hAT : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} - {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hIV : IdleVt σ) {s1 : S} {a1 : A} - (hfr : timer.fire st arI s a = ok (s1, a1)) {σ1 : Fl4Spec.State Unit} (hF : Fires σ σ1) - {V1 : XVs} {Ac1 : Set U64} {Lst1 : U64 → List U64} {D1 : Set U64} - (J1 : JAtZR (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1) : IdleVt σ1 := by - obtain ⟨Q, R, hc, hs⟩ := J.xtop.fin.1.1.1.lists +/-- **`IdleVt` after a step keeping the idle thread and the TCB slots** ((mmuAD gen 42b80) `JAtZR.idleVt_fire`'s +proof over the fields it reads: the relation before and after, `jpl`, `zH`, the slots kept (`SlotsSame`) and the +idle thread kept; shared by `JAtZR` and `JAtZB`). -/ +theorem idleVt_ofSlots {Z : XSets} {H : P1.Heap} {s s1 : S} {a a1 : A} {σ σ1 : Fl4Spec.State Unit} {V1 : XVs} + (hX : XTopAt (L := L) AR Z s a σ) (hjpl : ∃ Tr Cq, Sched.JPlaced (L := L) Z.th H Tr Cq s σ) + (hzH : ∀ t ∈ Z.T, H t = some .tcb) (hX1 : XTopAt (L := L) AR (Z.mv Z.G V1) s1 a1 σ1) + (hSS : SlotsSame Z.th (L.mem s) (L.mem s1)) (hid : σ1.idleThread = σ.idleThread) (hIV : IdleVt σ) : + IdleVt σ1 := by + obtain ⟨Q, R, hc, hs⟩ := hX.fin.1.1.1.lists have hit := hc.idleT - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hth : Z.th (nodeW st s Z.c layout.node.IDLE_THREAD) = some .tcb := (hJ.tcb _).2 (J.zH.1 _ hit) - obtain ⟨x, hkx, hsl⟩ := J.xtop.rel.2.1.1.tcb _ hth + obtain ⟨Tr, Cq, hJ⟩ := hjpl + have hth : Z.th (nodeW st s Z.c layout.node.IDLE_THREAD) = some .tcb := (hJ.tcb _).2 (hzH _ hit) + obtain ⟨x, hkx, hsl⟩ := hX.rel.2.1.1.tcb _ hth obtain ⟨cp, ac, hcp, hac, hca⟩ := hsl 1 (by decide) rw [tcbCnodeMap_one] at hac have hv : x.tcbVtable = absCap cp := by injection hac with h; rw [h, hca.2] @@ -259,14 +227,9 @@ theorem JAtZR.idleVt_fire (hAT : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs cases hx0 have hnp : ∀ p asid, cp ≠ .Pml4 p true asid := fun p asid e => by subst e; exact hv0 p.bv asid.bv hv - have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h - have hfk := spec_ok_post (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a J.blk J.bufAtJ) hfr - simp only [WP.uncurry'_pair] at hfk - obtain ⟨⟨Q', R', hq⟩, -⟩ := J.blk - have hSS := slotsSame_of_footDU J.xtop.rel.1 (hJ.kwOutBlk J.blk) hq.tcbs hq.nodes hfk J.bufU_noSlot have hx : IsSlot Z.th (slotOf (nodeW st s Z.c layout.node.IDLE_THREAD) 1) := ⟨_, 1, Or.inr ⟨hth, by decide⟩, rfl⟩ have hc1 := (hSS.capAt hx).trans hcp' - obtain ⟨y, hky, hsl1⟩ := J1.xtop.rel.2.1.1.tcb _ hth + obtain ⟨y, hky, hsl1⟩ := hX1.rel.2.1.1.tcb _ hth obtain ⟨cp1, ac1, hcp1, hac1, hca1⟩ := hsl1 1 (by decide) rw [tcbCnodeMap_one] at hac1 have hv1 : y.tcbVtable = absCap cp1 := by injection hac1 with h; rw [h, hca1.2] @@ -274,10 +237,25 @@ theorem JAtZR.idleVt_fire (hAT : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs have e : cp1 = cp := by have := hcp1'.symm.trans hc1 simpa using this - have hid : σ1.idleThread = σ.idleThread := congrArg (fun q => q.2.2.2.1) (Sched.crF_fires hF) refine ⟨y, by rw [hid, hs.idleTh]; exact hky, ?_⟩ rw [hv1, e]; exact absCap_not_pml4 hnp +/-- **`IdleVt` after FL4's timers** (module docstring; `idleVt_ofSlots`). -/ +theorem JAtZR.idleVt_fire (hAT : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hIV : IdleVt σ) {s1 : S} {a1 : A} + (hfr : timer.fire st arI s a = ok (s1, a1)) {σ1 : Fl4Spec.State Unit} (hF : Fires σ σ1) + {V1 : XVs} {Ac1 : Set U64} {Lst1 : U64 → List U64} {D1 : Set U64} + (J1 : JAtZR (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1) : IdleVt σ1 := by + obtain ⟨Tr, Cq, hJ⟩ := J.jpl + have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h + have hfk := spec_ok_post (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a J.blk J.bufAtJ) hfr + simp only [WP.uncurry'_pair] at hfk + obtain ⟨⟨Q', R', hq⟩, -⟩ := J.blk + exact idleVt_ofSlots J.xtop J.jpl J.zH.1 J1.xtop + (slotsSame_of_footDU J.xtop.rel.1 (hJ.kwOutBlk J.blk) hq.tcbs hq.nodes hfk J.bufU_noSlot) + (congrArg (fun q => q.2.2.2.1) (Sched.crF_fires hF)) hIV + end end diff --git a/proofs/Fl4Proofs/P3/G7eTail.lean b/proofs/Fl4Proofs/P3/G7eTail.lean index 38704d233..f88664b3a 100644 --- a/proofs/Fl4Proofs/P3/G7eTail.lean +++ b/proofs/Fl4Proofs/P3/G7eTail.lean @@ -34,7 +34,42 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a {AR : A → Fl4Spec.Cr3 → Prop} set_option maxHeartbeats 4000000 in -/-- **The narrowed tail at a finish state** (module docstring). -/ +/-- (mmuAD gen 42b80) **The tail's CR3 at a pinned timers' outcome** (`kfin_tail_of`'s step, shared with +VmSchedTail's `kfin_tail_ofB`): FL4's `schedule` run `r`, its timers' outcome `rf` related to `σ1` (an `F`-outcome +of `σ` with `schedule σ1 = {σ'}`) by the facts `schedule_refinesWP0FRA` reads; that lemma run with the fire predicate +pinned to `(rf, σ1)` gives `AR r.2 σ'.cr3`. -/ +theorem kfin_tail_at {N T C P : Set U64} {c : U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) + (hnd : Fl4Spec.numDomains = 1) (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) (hRef : ArchRefines arI AR) + (hA : ArchSwF st arI N T C c) (hAN : ArchNdF st N T C c) + (hsni : SniHyp st arI N T C c) (hsend : SendHyp st arI N T C c) (hT : TimeAgree arI) + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} {r rf : S × A} {σ1 σ' : Fl4Spec.State Unit} + (hr : sched.schedule st arI s a = ok r) (hfr : timer.fire st arI s a = ok rf) (hF : F σ σ1) + (hsc : Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False)) + (hS1 : SchedRel st N T C c rf.1 σ1) (hR1 : NtfnStateRel N T (L.mem rf.1) σ1) (hN1 : NSC N C σ1) + (hW1 : SchedPreW0R T C σ1) (hdt1 : σ1.domainTime ≠ 0 ∨ NdOK (L := L) rf.1 σ1) + (hnk1 : ∀ n ∈ N, n.val + 40 ≤ (L.ksb rf.1).val ∨ (L.ksb rf.1).val + 13568 ≤ n.val) + (hFO1 : FpuOwnOK σ1) (hV1 : VsRootOK T σ1) (hRF1 : RootFr (L := L) AR T P c rf.1 rf.2 σ1) + (hAR1 : AR rf.2 σ1.archState.x64CurrentCr3) : AR r.2 σ'.archState.x64CurrentCr3 := by + have hSt : P0.StoreTotal st := P1.LawfulStore.total + have hfire : timer.fire st arI s a ⦃ r => ∃ σ1', F σ σ1' ∧ SchedRel st N T C c r.1 σ1' ∧ + NtfnStateRel N T (L.mem r.1) σ1' ∧ NSC N C σ1' ∧ SchedPreW0R T C σ1' ∧ + ((σ1'.domainTime ≠ 0 ∨ NdOK (L := L) r.1 σ1') ∧ + (∀ n ∈ N, n.val + 40 ≤ (L.ksb r.1).val ∨ (L.ksb r.1).val + 13568 ≤ n.val) ∧ + (σ1' = σ1 ∧ FpuOwnOK σ1' ∧ VsRootOK T σ1' ∧ + (RootFr (L := L) AR T P c r.1 r.2 σ1' ∧ AR r.2 σ1'.archState.x64CurrentCr3))) ⦄ := by + rw [hfr, WP.spec_ok] + exact ⟨σ1, hF, hS1, hR1, hN1, hW1, hdt1, hnk1, rfl, hFO1, hV1, hRF1, hAR1⟩ + have hC := spec_ok_post (schedule_refinesWP0FRA hRef hSt hAT hK s a σ hS hR hN + hnd hfire (fun _ _ h => h.2.1) (fun _ _ h => h.2.2.1) (fun _ _ h => h.2.2.2) hA hAN hsni hsend hT) hr + obtain ⟨σ1', σ'', -, hsc', -, -, -, -, -, -, rf', ⟨e1, -⟩, -, σ3, -, -, -, hAR⟩ := hC + rw [e1, hsc] at hsc' + have e2 : ((), σ') = ((), σ'') := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hsc') + have e3 : σ' = σ'' := congrArg Prod.snd e2 + rw [e3]; exact hAR + +set_option maxHeartbeats 4000000 in +/-- **The narrowed tail at a finish state** (module docstring; (mmuAD gen 42b80) its step is `kfin_tail_at`). -/ theorem kfin_tail_of {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ) (hnd : Fl4Spec.numDomains = 1) @@ -68,23 +103,10 @@ theorem kfin_tail_of {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → have hdt1 : σ1.domainTime ≠ 0 ∨ NdOK (L := L) s1 σ1 := hd.imp (fun h => by rw [fire_dt J.xtop.fin.1.1.1 J1.xtop.fin.1.1.1 hfk.1 hm]; exact h) (fun h => J.ndOK_fire h hfk hUk hF) - have hfire : timer.fire st arI s a ⦃ r => ∃ σ1', Fires σ σ1' ∧ SchedRel st Z.N Z.T Z.C Z.c r.1 σ1' ∧ - NtfnStateRel Z.N Z.T (L.mem r.1) σ1' ∧ NSC Z.N Z.C σ1' ∧ SchedPreW0R Z.T Z.C σ1' ∧ - ((σ1'.domainTime ≠ 0 ∨ NdOK (L := L) r.1 σ1') ∧ - (∀ n ∈ Z.N, n.val + 40 ≤ (L.ksb r.1).val ∨ (L.ksb r.1).val + 13568 ≤ n.val) ∧ - (σ1' = σ1 ∧ FpuOwnOK σ1' ∧ VsRootOK Z.T σ1' ∧ - (RootFr (L := L) AR Z.T (Z.mv Z.G V1).P Z.c r.1 r.2 σ1' ∧ AR r.2 σ1'.archState.x64CurrentCr3))) ⦄ := by - rw [hfr, WP.spec_ok] - exact ⟨σ1, hF, J1.xtop.fin.1.1.1, J1.xtop.fin.1.1.2.2.1, J1.nsc, ⟨J1.inv, J1.cur, J1.off, J1.act, J1.own⟩, - hdt1, J1.nk, rfl, fpuOwnOK_firesZR J hF J1.xtop.fin.1.1.2.2.1 hFO, J1.vsRootOK, - J1.rootFr (J.idleVt_fire hAT hIV hfr hF J1), J1.xtop.fin.1.1.2.2.2.2.2.2⟩ - have hC := spec_ok_post (schedule_refinesWP0FRA hRef hSt hAT hK s a σ J.xtop.fin.1.1.1 J.xtop.fin.1.1.2.2.1 J.nsc - hnd hfire (fun _ _ h => h.2.1) (fun _ _ h => h.2.2.1) (fun _ _ h => h.2.2.2) hA hAN hsni hsend hT) hr - obtain ⟨σ1', σ'', -, hsc', -, -, -, -, -, -, rf', ⟨e1, -⟩, -, σ3, -, -, -, hAR⟩ := hC - rw [e1, hsc] at hsc' - have e2 : ((), σ') = ((), σ'') := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hsc') - have e3 : σ' = σ'' := congrArg Prod.snd e2 - exact ⟨by rw [e3]; exact hAR⟩ + exact ⟨kfin_tail_at J.xtop.fin.1.1.1 J.xtop.fin.1.1.2.2.1 J.nsc hnd hAT hK hRef hA hAN hsni hsend hT hr hfr hF hsc + J1.xtop.fin.1.1.1 J1.xtop.fin.1.1.2.2.1 J1.nsc ⟨J1.inv, J1.cur, J1.off, J1.act, J1.own⟩ hdt1 J1.nk + (fpuOwnOK_firesZR J hF J1.xtop.fin.1.1.2.2.1 hFO) J1.vsRootOK (J1.rootFr (J.idleVt_fire hAT hIV hfr hF J1)) + J1.xtop.fin.1.1.2.2.2.2.2.2⟩ variable (arI) diff --git a/proofs/Fl4Proofs/P3/HandleTopG.lean b/proofs/Fl4Proofs/P3/HandleTopG.lean new file mode 100644 index 000000000..ad9161d19 --- /dev/null +++ b/proofs/Fl4Proofs/P3/HandleTopG.lean @@ -0,0 +1,468 @@ +/- +P3 (line mmuAD, gen 42b66, option (b) step b1): **`handle_invocation` generic over the spec's decoder and +dispatcher** (`handle_invocation_refinesMXPG`). + +FL4's `syscall::handle_invocation` decodes every cap with one `decode_invocation`; the spec has two top-level +handlers that differ only there: `fl4HandleInvocationR` (Ext/ReplyError: `fl4DecodeInvocation`, +`fl4PerformInvocation`) and `fl4HandleInvocationVF` (Ext/VirtKernelF: `fl4DecodeInvocationV`, +`fl4PerformInvocationVF onCore remoteCur`). This module states the composition once, over an invocation type `ι` +with a decoder `dec` and a dispatcher `perf`: + +* **`hiG dec perf rep`**: the spec's handler with `dec` / `perf`; `fl4HandleInvocationR_hiG` and + `fl4HandleInvocationVF_hiG` (both `rfl`). The phases `hiMEG` / `hiMFinG` (HandleTop's `hiME` / `hiMFin`; + JAtZV3HiTop's `hiMEV` / `hiMFinVF` are their instances at the extended dispatcher), `hi_memG`, `hiMEG_run`, + `hiMFinG_ok`, `hiMFinG_pre` (the lookup phase `hiMF` does not depend on `dec` / `perf`). +* The posts over `perf`: **`TopPostDMXG`** (an empty result on success: HandleTopX's `TopPostDMX`), + `TopPostDMXPG` (XTopJointCnDel's `TopPostDMXP`), **`TopPostRMXG`** (a decode that replies itself, with data: + VsDecReply's `TopPostRMX`), `DecOKDMXPG`, `DecOKRMXG`, **`XCapPG`** (XTopJointCnDel's `XCapP`: both arms), + **`HIPostMXPG`** (XTopJointEntry's `HIPostMXP`). Each native def is the instance at `fl4DecodeInvocation` / + `fl4PerformInvocation` by `rfl` (`TopPostDMX_G`, `TopPostRMX_G`, `XCapP_G`); the native defs are unchanged. +* **`handle_invocation_refinesMXPG`**: XTopJointEntry's `handle_invocation_refinesMXP` over `(dec, perf)` (its + proof moved here; the native theorem is now its instance). The premises are the native theorem's with `hPK` over + `perf` and `hDec` asking `XCapPG dec perf`. + +`ifP_ok` / `ifP_X` moved here from XTopJointEntry (statements unchanged). + +No named premise; no existing statement changed. +-/ +import Fl4Proofs.P3.XTopJointCnDel +import Fl4Spec.Ext.VirtKernelF +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core Classical + +noncomputable section + +/-! ## The spec's handler over a decoder and a dispatcher -/ + +section +open Fl4Spec +variable {Z : Type} [StateExt Z] {ι : Type} + +/-- **`fl4HandleInvocationR` over a decoder `dec` and a dispatcher `perf`** (module docstring). -/ +def hiG (dec : Bool → Data → List Data → CapRef → CslotPtr → Cap → List (Cap × CslotPtr) → Option ObjRef → + SEMonad Z ι) + (perf : Bool → Bool → Bool → ι → PMonad Z (List Data)) (reportError : Bool) + (calling blocking canDonate firstPhase : Bool) (cptr : CapRef) : PMonad Z Unit := do + let thread ← NonDetE.liftE <| NonDet.gets fun s : State Z => s.curThread + let info ← withoutPreemption <| getMessageInfo thread + syscall + (do + let (cap, slot) ← capFaultOnFailure (ofBl cptr) false <| + lookupCapAndSlot thread cptr + let buffer ← NonDetE.liftE <| lookupIpcBuffer false thread + let extracaps ← lookupExtraCaps thread buffer info + NonDetE.returnOk (slot, cap, extracaps, buffer)) + (fun fault => NonDet.when blocking <| handleFault thread fault) + (fun (slot, cap, extracaps, buffer) => do + let args ← NonDetE.liftE <| getMrs thread buffer info + dec firstPhase info.miLabel args cptr slot cap extracaps buffer) + (fun err => NonDet.when calling <| + fl4ReplyFromKernelError reportError thread <| msgFromSyscallError err) + (fun oper => do + withoutPreemption <| setThreadState thread .restart + let reply ← perf blocking calling canDonate oper + withoutPreemption <| do + let state ← getThreadState thread + match state with + | .restart => do + NonDet.when calling <| + replyFromKernel thread (0, reply) + setThreadState thread .running + | _ => return ()) + +/-- `fl4HandleInvocationR` is `hiG` at the native decoder and dispatcher. -/ +theorem fl4HandleInvocationR_hiG (rep calling blocking canDonate firstPhase : Bool) (cptr : CapRef) : + fl4HandleInvocationR (Z := Z) rep calling blocking canDonate firstPhase cptr = + hiG fl4DecodeInvocation fl4PerformInvocation rep calling blocking canDonate firstPhase cptr := rfl + +/-- `fl4HandleInvocationVF` is `hiG` at the extended decoder and dispatcher. -/ +theorem fl4HandleInvocationVF_hiG (onCore remoteCur : ObjRef → Bool) (rep calling blocking canDonate firstPhase : Bool) + (cptr : CapRef) : + fl4HandleInvocationVF (Z := Z) onCore remoteCur rep calling blocking canDonate firstPhase cptr = + hiG fl4DecodeInvocationV (fl4PerformInvocationVF onCore remoteCur) rep calling blocking canDonate firstPhase + cptr := rfl + +end + +section +open Fl4Spec +variable {ι : Type} + +/-- The decode phase over `dec` (HandleTop's `hiME`). -/ +def hiMEG (dec : Bool → Data → List Data → CapRef → CslotPtr → Cap → List (Cap × CslotPtr) → Option ObjRef → + SEMonad Unit ι) + (thread : ObjRef) (info : MessageInfo) (cptr : CapRef) (firstPhase : Bool) : + CslotPtr × Cap × List (Cap × CslotPtr) × Option ObjRef → SEMonad Unit ι := + fun (slot, cap, extracaps, buffer) => do + let args ← NonDetE.liftE <| getMrs thread buffer info + dec firstPhase info.miLabel args cptr slot cap extracaps buffer + +/-- The invocation phase over `perf` (HandleTop's `hiMFin`). -/ +def hiMFinG (perf : Bool → Bool → Bool → ι → PMonad Unit (List Data)) (thread : ObjRef) + (calling blocking canDonate : Bool) : ι → PMonad Unit Unit := + fun oper => do + withoutPreemption <| setThreadState thread .restart + let reply ← perf blocking calling canDonate oper + withoutPreemption <| do + let state ← getThreadState thread + match state with + | .restart => do + NonDet.when calling <| + replyFromKernel thread (0, reply) + setThreadState thread .running + | _ => return () + +theorem hi_memG (dec : Bool → Data → List Data → CapRef → CslotPtr → Cap → List (Cap × CslotPtr) → + Option ObjRef → SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → PMonad Unit (List Data)) (rep : Bool) {σ : State Unit} + {calling blocking canDonate firstPhase : Bool} {cptr : CapRef} {mi : MessageInfo} {t : ObjRef} + (hcur : σ.curThread = t) (hmi : getMessageInfo (Z := Unit) t σ = ({(mi, σ)}, False)) + {y : Except Unit Unit × State Unit} + (h : y ∈ ((syscall (hiMF t mi cptr) (fun fault => NonDet.when blocking <| handleFault t fault) + (hiMEG dec t mi cptr firstPhase) + (fun err => NonDet.when calling <| fl4ReplyFromKernelError rep t <| msgFromSyscallError err) + (hiMFinG perf t calling blocking canDonate)).run σ).1) : + y ∈ ((hiG (Z := Unit) dec perf rep calling blocking canDonate firstPhase cptr).run σ).1 := by + unfold hiG + refine mem_bindE_ok (a := σ.curThread) (s' := σ) (mem_liftE (x := (σ.curThread, σ)) rfl) ?_ + refine mem_bindE_ok (a := mi) (s' := σ) (mem_liftE (x := (mi, σ)) (by rw [hcur, hmi]; rfl)) ?_ + rw [hcur] + exact h + +theorem hiMEG_run {dec : Bool → Data → List Data → CapRef → CslotPtr → Cap → List (Cap × CslotPtr) → + Option ObjRef → SEMonad Unit ι} + {σ : State Unit} {t : ObjRef} {mi : MessageInfo} {cptr : CapRef} {fp : Bool} {a : Cap} + {sl : CslotPtr} {buffer : Option ObjRef} {exs : List (Cap × CslotPtr)} {args : List Data} + (hm : getMrs (Z := Unit) t buffer mi σ = ({(args, σ)}, False)) : + ExceptT.run (hiMEG dec t mi cptr fp (sl, a, exs, buffer)) σ = + (dec fp mi.miLabel args cptr sl a exs buffer).run σ := by + unfold hiMEG + exact run_bind_ok (run_liftE hm) _ + +theorem hiMFinG_ok {perf : Bool → Bool → Bool → ι → PMonad Unit (List Data)} + {σ σ1 σy : State Unit} {t : ObjRef} {calling blocking canDonate : Bool} {inv : ι} + {rr : List Data} {z : Unit × State Unit} + (hst : setThreadState (Z := Unit) t .restart σ = ({((), σ1)}, False)) + (hy : (.ok rr, σy) ∈ ((perf blocking calling canDonate inv).run σ1).1) + (hz : z ∈ (specTail calling t rr σy).1) : + ((.ok z.1, z.2) : Except Unit Unit × State Unit) ∈ ((hiMFinG perf t calling blocking canDonate inv).run σ).1 := by + unfold hiMFinG withoutPreemption + refine mem_bindE_ok (a := ()) (s' := σ1) (mem_liftE (x := ((), σ1)) (by rw [hst]; rfl)) ?_ + refine mem_bindE_ok (a := rr) (s' := σy) hy ?_ + exact mem_liftE hz + +theorem hiMFinG_pre {perf : Bool → Bool → Bool → ι → PMonad Unit (List Data)} + {σ σ1 σy : State Unit} {t : ObjRef} {calling blocking canDonate : Bool} {inv : ι} + (hst : setThreadState (Z := Unit) t .restart σ = ({((), σ1)}, False)) + (hy : (.error (), σy) ∈ ((perf blocking calling canDonate inv).run σ1).1) : + ((.error (), σy) : Except Unit Unit × State Unit) ∈ ((hiMFinG perf t calling blocking canDonate inv).run σ).1 := by + unfold hiMFinG withoutPreemption + refine mem_bindE_ok (a := ()) (s' := σ1) (mem_liftE (x := ((), σ1)) (by rw [hst]; rfl)) ?_ + exact mem_bindE_err hy + +end + +/-! ## The posts over the dispatcher -/ + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) {ι : Type} + +/-- **HandleTopX's `TopPostDMX` over a dispatcher `perf`** (an empty result on success). -/ +def TopPostDMXG (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X : S → A → Fl4Spec.State Unit → Prop) (σ : Fl4Spec.State Unit) (blk call don : Bool) + (m : Fl4Spec.SEMonad Unit ι) (s : S) (res : core.result.Result Unit error.Exc × S × A) : Prop := + (∃ e, res.1 = .Err e ∧ res.2.1 = s ∧ (∃ e', m.run σ = ({(.error e', σ)}, False) ∧ ErrRel e e') ∧ + X res.2.1 res.2.2 σ) ∨ + (∃ inv, DecOut m σ inv ∧ ∃ σ1, + Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + ∃ y ∈ ((perf blk call don inv).run σ1).1, (∃ th' G', + ((res.1 = .Ok () ∧ y.1 = .ok []) ∨ (res.1 = .Err .Preempted ∧ y.1 = .error ())) ∧ + Placed th' ∧ CRel th' (L.mem res.2.1) y.2 G' ∧ FinInv th' (L.mem res.2.1) y.2 G' ∧ + DomRel (L.mem res.2.1) (L.ksb res.2.1) y.2 ∧ MdbOKV (L.ksb res.2.1) (L.mem res.2.1) G') ∧ + X res.2.1 res.2.2 y.2) + +theorem TopPostDMX_G {X : S → A → Fl4Spec.State Unit → Prop} {σ : Fl4Spec.State Unit} {blk call don : Bool} + {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4Invocation} {s : S} {res : core.result.Result Unit error.Exc × S × A} : + TopPostDMX (L := L) X σ blk call don m s res = + TopPostDMXG (L := L) Fl4Spec.fl4PerformInvocation X σ blk call don m s res := rfl + +/-- XTopJointCnDel's `TopPostDMXP` over `perf`: `XP` after a preempted invocation. -/ +def TopPostDMXPG (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X XP : S → A → Fl4Spec.State Unit → Prop) (σ : Fl4Spec.State Unit) (blk call don : Bool) + (m : Fl4Spec.SEMonad Unit ι) (s : S) (res : core.result.Result Unit error.Exc × S × A) : Prop := + TopPostDMXG (L := L) perf (fun s a σ => if res.1 = .Err .Preempted then XP s a σ else X s a σ) σ blk call don m s res + +/-- **VsDecReply's `TopPostRMX` over `perf`**: a decode that replies itself (the result's data written by FL4's +decode, `Running` set). -/ +def TopPostRMXG (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X : S → A → Fl4Spec.State Unit → Prop) (σ : Fl4Spec.State Unit) (blk call don : Bool) + (m : Fl4Spec.SEMonad Unit ι) (ct : U64) (s : S) + (res : core.result.Result Unit error.Exc × S × A) : Prop := + (∃ e, res.1 = .Err e ∧ res.2.1 = s ∧ (∃ e', m.run σ = ({(.error e', σ)}, False) ∧ ErrRel e e') ∧ + X res.2.1 res.2.2 σ) ∨ + res.1 = .Ok () ∧ L.mem res.2.1 (stA ct) ≠ sched.TS_RESTART ∧ + ∃ inv, DecOut m σ inv ∧ ∃ σ1, + Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + ∃ rr σy, (.ok rr, σy) ∈ ((perf blk call don inv).run σ1).1 ∧ + ∃ z ∈ (specTail call ct.bv rr σy).1, RelTopM (L := L) res.2.1 z.2 ∧ X res.2.1 res.2.2 z.2 + +theorem TopPostRMX_G {X : S → A → Fl4Spec.State Unit → Prop} {σ : Fl4Spec.State Unit} {blk call don : Bool} + {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4Invocation} {ct : U64} {s : S} + {res : core.result.Result Unit error.Exc × S × A} : + TopPostRMX (L := L) X σ blk call don m ct s res = + TopPostRMXG (L := L) Fl4Spec.fl4PerformInvocation X σ blk call don m ct s res := rfl + +/-- XTopJointCnDel's `DecOKDMXP` over `(dec, perf)`. -/ +abbrev DecOKDMXPG (dec : Bool → Fl4Spec.Data → List Fl4Spec.Data → Fl4Spec.CapRef → Fl4Spec.CslotPtr → Fl4Spec.Cap → + List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Option Fl4Spec.ObjRef → Fl4Spec.SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X XP : S → A → Fl4Spec.State Unit → Prop) (s : S) (ar : A) (σ : Fl4Spec.State Unit) + (lbl length slot : U64) (c : capability.Cap) (blk call don fp : Bool) (buf : U64) + (extra : Aeneas.Std.Array obj.Slot 3#usize) (slbl : Fl4Spec.Data) + (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) + (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) : Prop := + syscall.decode_invocation st arI s ar lbl length slot c blk call don fp buf extra ⦃ res => + TopPostDMXPG (L := L) perf X XP σ blk call don (dec fp slbl args ci sl (absCap c) excaps buffer) s res ⦄ + +/-- VsDecReply's `DecOKRMX` over `(dec, perf)`. -/ +abbrev DecOKRMXG (dec : Bool → Fl4Spec.Data → List Fl4Spec.Data → Fl4Spec.CapRef → Fl4Spec.CslotPtr → Fl4Spec.Cap → + List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Option Fl4Spec.ObjRef → Fl4Spec.SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X : S → A → Fl4Spec.State Unit → Prop) (s : S) (ar : A) (σ : Fl4Spec.State Unit) + (lbl length slot : U64) (c : capability.Cap) + (blk call don fp : Bool) (buf : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) (slbl : Fl4Spec.Data) + (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) + (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (ct : U64) : Prop := + syscall.decode_invocation st arI s ar lbl length slot c blk call don fp buf extra ⦃ res => + TopPostRMXG (L := L) perf X σ blk call don (dec fp slbl args ci sl (absCap c) excaps buffer) ct s res ⦄ + +/-- **XTopJointCnDel's `XCapP` over `(dec, perf)`**: the decode and invocation of the cap, with an empty result +(`DecOKDMXPG`) or replying itself with data (`DecOKRMXG`). -/ +def XCapPG (dec : Bool → Fl4Spec.Data → List Fl4Spec.Data → Fl4Spec.CapRef → Fl4Spec.CslotPtr → Fl4Spec.Cap → + List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Option Fl4Spec.ObjRef → Fl4Spec.SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X XP : S → A → Fl4Spec.State Unit → Prop) (s : S) (ar : A) (σ : Fl4Spec.State Unit) (lbl length slot : U64) + (c : capability.Cap) (blk call don fp : Bool) (buf : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) + (slbl : Fl4Spec.Data) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) + (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (ct : U64) : Prop := + DecOKDMXPG (L := L) arI dec perf X XP s ar σ lbl length slot c blk call don fp buf extra slbl args ci sl excaps + buffer ∨ + DecOKRMXG (L := L) arI dec perf X s ar σ lbl length slot c blk call don fp buf extra slbl args ci sl excaps buffer ct + +theorem XCapP_G {X XP : S → A → Fl4Spec.State Unit → Prop} {s : S} {ar : A} {σ : Fl4Spec.State Unit} + {lbl length slot : U64} {c : capability.Cap} {blk call don fp : Bool} {buf : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slbl : Fl4Spec.Data} {args : List Fl4Spec.Data} + {ci : Fl4Spec.CapRef} {sl : Fl4Spec.CslotPtr} {excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)} + {buffer : Option Fl4Spec.ObjRef} {ct : U64} : + XCapP (L := L) arI X XP s ar σ lbl length slot c blk call don fp buf extra slbl args ci sl excaps buffer ct = + XCapPG (L := L) arI Fl4Spec.fl4DecodeInvocation Fl4Spec.fl4PerformInvocation X XP s ar σ lbl length slot c blk + call don fp buf extra slbl args ci sl excaps buffer ct := rfl + +/-- **XTopJointEntry's `HIPostMXP` over `(dec, perf)`**: an outcome of `hiG dec perf rep` of FL4's kind, related, +with `XP` after a preempted invocation and `X` after any other. -/ +def HIPostMXPG (dec : Bool → Fl4Spec.Data → List Fl4Spec.Data → Fl4Spec.CapRef → Fl4Spec.CslotPtr → Fl4Spec.Cap → + List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Option Fl4Spec.ObjRef → Fl4Spec.SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X XP : S → A → Fl4Spec.State Unit → Prop) (rep : Bool) (σ : Fl4Spec.State Unit) + (calling blocking canDonate firstPhase : Bool) (cptr : Fl4Spec.CapRef) + (res : core.result.Result Unit error.Exc × S × A) : Prop := + ∃ y ∈ ((hiG (Z := Unit) dec perf rep calling blocking canDonate firstPhase cptr).run σ).1, + ((res.1 = .Ok () ∧ y.1 = .ok ()) ∨ (res.1 = .Err .Preempted ∧ y.1 = .error ())) ∧ + RelTopM (L := L) res.2.1 y.2 ∧ + (if res.1 = .Err .Preempted then XP res.2.1 res.2.2 y.2 else X res.2.1 res.2.2 y.2) + +theorem ifP_ok {X XP : S → A → Fl4Spec.State Unit → Prop} {r : core.result.Result Unit error.Exc} {s : S} {a : A} + {σ : Fl4Spec.State Unit} (h : r = .Ok ()) (hx : X s a σ) : + (if r = .Err .Preempted then XP s a σ else X s a σ) := by + subst h; rw [if_neg (fun h => by cases h)]; exact hx + +theorem ifP_X {X XP : S → A → Fl4Spec.State Unit → Prop} {r : core.result.Result Unit error.Exc} {s : S} {a : A} + {σ : Fl4Spec.State Unit} (h : r ≠ .Err .Preempted) + (hx : if r = .Err .Preempted then XP s a σ else X s a σ) : X s a σ := by + rw [if_neg h] at hx; exact hx + +/-! ## The composition -/ + +/-- **`handle_invocation` refines `hiG dec perf rep`, keeping `X` (`XP` if preempted)**: XTopJointEntry's +`handle_invocation_refinesMXP` over the spec's decoder and dispatcher (module docstring). -/ +theorem handle_invocation_refinesMXPG + (dec : Bool → Fl4Spec.Data → List Fl4Spec.Data → Fl4Spec.CapRef → Fl4Spec.CslotPtr → Fl4Spec.Cap → + List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Option Fl4Spec.ObjRef → Fl4Spec.SEMonad Unit ι) + (perf : Bool → Bool → Bool → ι → Fl4Spec.PMonad Unit (List Fl4Spec.Data)) + (X XP : S → A → Fl4Spec.State Unit → Prop) (rep : Bool) (s : S) (ar : A) (σ : Fl4Spec.State Unit) (th : TypedHeap) (G : MdbGhost) + (hP : Placed th) (hCR : CRel th (L.mem s) σ G) (hFI : FinInv th (L.mem s) σ G) + (hDR : DomRel (L.mem s) (L.ksb s) σ) (hFR : MdbOKV (L.ksb s) (L.mem s) G) + (hX0 : X s ar σ) + (ct : U64) (hct : sched.cur_thread st s = ok ct) (hcur : σ.curThread = ct.bv) (htcb : th ct = some .tcb) + (is_call blocking can_donate first_phase : Bool) (cptr : U64) + -- the front end's reads (`HIRead`) + (info : msginfo.MessageInfo) (hinfo : msg.msg_info st s ct = ok info) + (mi : Fl4Spec.MessageInfo) (hmi : Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False)) + (buf : U64) (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) + (buffer : Option Fl4Spec.ObjRef) + (hbuffer : Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False)) + (r2 : core.result.Result (Aeneas.Std.Array obj.Slot 3#usize) error.Fault) + (hr2 : ipc.lookup_extra_caps st s ct buf info = ok r2) + (er : Except Fl4Spec.Fault (List (Fl4Spec.Cap × Fl4Spec.CslotPtr))) + (her : (Fl4Spec.lookupExtraCaps (Z := Unit) ct.bv buffer mi).run σ = ({(er, σ)}, False)) + (hrr : (∃ e exs, r2 = .Ok e ∧ er = .ok exs) ∨ + (∃ f f', r2 = .Err f ∧ er = .error f' ∧ (blocking = true → faults.handle_fault st arI s ar ct f ⦃ r => + ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, RelTopM (L := L) r.1 z.2 ∧ X r.1 r.2 z.2 ⦄))) + (args : List Fl4Spec.Data) (hmrs : Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(args, σ)}, False)) + -- the fault of a failed lookup + (hFL : blocking = true → ∀ lf lf', LookupFaultRel lf lf' → + faults.handle_fault st arI s ar ct (.Cap cptr false lf) ⦃ r => + ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv (.capFault (Fl4Spec.ofBl (Fl4Spec.toBl cptr.bv)) false lf') σ).1, + RelTopM (L := L) r.1 z.2 ∧ X r.1 r.2 z.2 ⦄) + -- the success tail (from `X` with the invoker still current) and the error reply (at the entry state) + (hRepS : ∀ (s1 : S) (a1 : A) (σ' : Fl4Spec.State Unit), RelTopM (L := L) s1 σ' → X s1 a1 σ' → + σ'.curThread = ct.bv → flTail (st := st) ct is_call s1 a1 ⦃ res => res.1 = .Ok () ∧ + ∃ z ∈ (specTail is_call ct.bv [] σ').1, RelTopM (L := L) res.2.1 z.2 ∧ X res.2.1 res.2.2 z.2 ⦄) + (hRepF : ∀ (a1 : A) (e : error.SysError) (e' : Fl4Spec.SyscallError), X s a1 σ → ErrRel (.Sys e) e' → + ((if is_call then do + let s2 ← syscall.reply_error st s ct e + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s2, a1) + else ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s, a1)) : + Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ res => + res.1 = .Ok () ∧ ∃ z ∈ ((Fl4Spec.NonDet.when is_call <| + Fl4Spec.fl4ReplyFromKernelError rep ct.bv (Fl4Spec.msgFromSyscallError e')) σ).1, + RelTopM (L := L) res.2.1 z.2 ∧ X res.2.1 res.2.2 z.2 ⦄) + -- the invocation keeps the current thread + (hPK : ∀ inv σ1 y, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) → + y ∈ ((perf blocking is_call can_donate inv).run σ1).1 → + y.2.curThread = ct.bv) + -- the decode and invocation of the cap + (hDec : ∀ (sl : Fl4Spec.CslotPtr) (c : capability.Cap) (e : Aeneas.Std.Array obj.Slot 3#usize) + (exs : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), (∃ p, sl.1 = p.bv ∧ th p = some (.cnode sl.2.length)) → + capAt (L.mem s) (cslotAddr sl) = ok c → + Fl4Spec.getCap (Z := Unit) sl σ = ({(absCap c, σ)}, False) → r2 = .Ok e → er = .ok exs → + XCapPG (L := L) arI dec perf X XP s ar σ info.label (msgLen info buf) (cslotAddr sl) c blocking is_call + can_donate first_phase buf e mi.miLabel args (Fl4Spec.toBl cptr.bv) sl exs buffer ct) : + syscall.handle_invocation st arI s ar is_call blocking can_donate first_phase cptr ⦃ res => + HIPostMXPG (L := L) dec perf X XP rep σ is_call blocking can_donate first_phase (Fl4Spec.toBl cptr.bv) res ⦄ := by + have hRT0 : RelTopM (L := L) s σ := ⟨th, G, hP, hCR, hFI, hDR, hFR⟩ + unfold syscall.handle_invocation + rw [hct]; simp only [bind_ok, hinfo] + refine WP.spec_bind (lookup_slot_refines (Z := Unit) th s σ hCR.1 hCR.2.1 ct htcb cptr) ?_ + rintro r ⟨e, he, hrel, hok⟩ + cases r with + | Err lf => + cases e with + | ok v => exact hrel.elim + | error lf' => + simp only + have hl : (Fl4Spec.lookupCapAndSlot (Z := Unit) ct.bv (Fl4Spec.toBl cptr.bv)).run σ = + ({(.error lf', σ)}, False) := by + unfold Fl4Spec.lookupCapAndSlot; exact run_bind_error (s := σ) he _ + have hmF := hiMF_lookup_err (mi := mi) hl + cases blocking + · simp only [Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + exact ⟨(.ok (), σ), hi_memG dec perf rep hcur hmi (mem_syscall_fault (z := ((), σ)) hmF + (mem_when (fun h => by cases h) (fun _ => rfl))), Or.inl ⟨rfl, rfl⟩, hRT0, ifP_ok rfl hX0⟩ + · simp only [↓reduceIte] + refine WP.spec_bind (hFL rfl lf lf' hrel) ?_ + rintro ⟨s1, a1⟩ ⟨z, hz, hRT, hXz⟩ + refine (WP.spec_ok _).2 ?_ + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_fault hmF + (mem_when (fun _ => hz) (fun h => by cases h))), Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ + | Ok r1 => + cases e with + | error lf' => exact hrel.elim + | ok v => + obtain ⟨sl, rest⟩ := v + obtain ⟨hsl, -⟩ := hrel + obtain ⟨p, hp, hth, -⟩ := hok + obtain ⟨c, a, hc, hca, hget⟩ := hCR.1.slot_cap hp hth + have hl : (Fl4Spec.lookupCapAndSlot (Z := Unit) ct.bv (Fl4Spec.toBl cptr.bv)).run σ = + ({(.ok (a, sl), σ)}, False) := by + unfold Fl4Spec.lookupCapAndSlot + rw [run_bind_ok he] + simp only + rw [run_bind_ok (run_liftE hget)] + rfl + simp only + rw [slot_cap_eq, hsl, hc] + simp only [bind_ok, hbuf, hr2] + rcases hrr with ⟨ex, exs, rfl, rfl⟩ | ⟨f, f', rfl, rfl, hfh⟩ + · simp only + rw [msgLen_eq]; simp only [bind_ok] + have hca' : absCap c = a := hca.2 + subst hca' + have hmF := hiMF_ok (mi := mi) hl hbuffer her + have hmE := hiMEG_run (dec := dec) (cptr := Fl4Spec.toBl cptr.bv) (fp := first_phase) (a := absCap c) + (sl := sl) (exs := exs) hmrs + rcases hDec sl c ex exs ⟨p, hp, hth⟩ hc hget rfl rfl with hD | hD + swap + · refine WP.spec_bind hD ?_ + rintro ⟨r3, s1, a1⟩ (⟨e3, he3, hs1, ⟨e', hdec, herr⟩, hXe⟩ | ⟨hok3, hne, inv, hdec, σ1, hst, rr, σy, hy, z, hz, hRT, hXz⟩) + · simp only at he3 hs1 + subst he3 hs1 + cases e3 with + | Sys e2 => + refine WP.spec_mono (hRepF a1 e2 e' hXe herr) ?_ + rintro res ⟨hres, z, hz, hRT, hXz⟩ + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_err hmF (by rw [hmE, hdec]; rfl) hz), + Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ + | Fault _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + | Lookup _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + | Preempted => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + simp only at hok3; subst hok3 + refine WP.spec_bind (tcb_state_spec' (st := st) s1 ct) ?_ + rintro v rfl + rw [if_neg hne] + refine (WP.spec_ok _).2 ?_ + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) + (hiMFinG_ok (by rw [← hcur]; exact hst) hy hz)), Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ + refine WP.spec_bind hD ?_ + rintro ⟨r3, s1, a1⟩ hq + rcases hq with ⟨e3, he3, hs1, ⟨e', hdec, herr⟩, hXe⟩ | + ⟨inv, hdec, σ1, hst, y, hy, ⟨th', G', hcase, hP', hCR', hFI', hDR', hFR'⟩, hXy⟩ + · simp only at he3 hs1 + subst he3 hs1 + cases e3 with + | Sys e2 => + refine WP.spec_mono (hRepF a1 e2 e' (ifP_X (r := .Err (.Sys e2)) (fun h => by cases h) hXe) herr) ?_ + rintro res ⟨hres, z, hz, hRT, hXz⟩ + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_err hmF (by rw [hmE, hdec]; rfl) hz), + Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ + | Fault _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + | Lookup _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + | Preempted => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) + · rcases hcase with ⟨hok3, hyr⟩ | ⟨hpre, hyr⟩ + · simp only at hok3 + subst hok3 + refine WP.spec_mono (hRepS s1 a1 y.2 ⟨th', G', hP', hCR', hFI', hDR', hFR'⟩ + (ifP_X (r := .Ok ()) (fun h => by cases h) hXy) (hPK inv σ1 y hst hy)) ?_ + rintro res ⟨hres, z, hz, hRT, hXz⟩ + obtain ⟨y1, y2⟩ := y + simp only at hyr; subst hyr + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) + (hiMFinG_ok (by rw [← hcur]; exact hst) hy hz)), Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ + · simp only at hpre + subst hpre + refine (WP.spec_ok _).2 ?_ + obtain ⟨y1, y2⟩ := y + simp only at hyr; subst hyr + exact ⟨(.error (), y2), hi_memG dec perf rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) + (hiMFinG_pre (by rw [← hcur]; exact hst) hy)), Or.inr ⟨rfl, rfl⟩, + ⟨th', G', hP', hCR', hFI', hDR', hFR'⟩, hXy⟩ + · simp only + have hmF := hiMF_extra_err (cptr := Fl4Spec.toBl cptr.bv) hl hbuffer her + cases blocking + · simp only [Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + exact ⟨(.ok (), σ), hi_memG dec perf rep hcur hmi (mem_syscall_fault (z := ((), σ)) hmF + (mem_when (fun h => by cases h) (fun _ => rfl))), Or.inl ⟨rfl, rfl⟩, hRT0, ifP_ok rfl hX0⟩ + · simp only [↓reduceIte] + refine WP.spec_bind (hfh rfl) ?_ + rintro ⟨s1, a1⟩ ⟨z, hz, hRT, hXz⟩ + refine (WP.spec_ok _).2 ?_ + exact ⟨(.ok z.1, z.2), hi_memG dec perf rep hcur hmi (mem_syscall_fault hmF + (mem_when (fun _ => hz) (fun h => by cases h))), Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/IpcCancel.lean b/proofs/Fl4Proofs/P3/IpcCancel.lean index 1225cf8ea..f7024f1f6 100644 --- a/proofs/Fl4Proofs/P3/IpcCancel.lean +++ b/proofs/Fl4Proofs/P3/IpcCancel.lean @@ -88,12 +88,12 @@ theorem ep_dequeue_c (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (h exact ⟨h1, h2, ⟨h3, ntfn_frame_ep hP0.toC hSR.2 he hW hQA hkv⟩, h4⟩ /-- `set_thread_state` to a state below 3, with the notification relation. -/ -theorem set_thread_state_cq (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) +theorem set_thread_state_cqVM (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) (hSR : SRN st N T (SRS st T SR) s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hq : ∀ e ∈ E, ∀ z, σ.kheap e.bv = some (.endpoint z) → t.bv ∉ z.epQueue) (hqn : ∀ n ∈ N, ∀ z, σ.kheap n.bv = some (.notification z) → t.bv ∉ z.ntfnObj.ntfnQueue) - (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) (code : U64) (hcode : code.val = tsCode ts) : + (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3 ∨ ts = .runningVM) (code : U64) (hcode : code.val = tsCode ts) : sched.set_thread_state st s t code ⦃ s' => EpStateRel T E R B (L.mem s') (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ∧ SRN st N T (SRS st T SR) s' (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ⦄ := by @@ -117,12 +117,34 @@ theorem set_thread_state_cq (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E unfold sched.set_thread_state step subst s1_post - obtain ⟨hR1, hW1, hS1⟩ := write_state_rel hP s σ hR ht hk hq ts hts code hcode + obtain ⟨hR1, hW1, hS1⟩ := write_state_relVM hP s σ hR ht hk hq ts hts code hcode refine WP.spec_mono ((hH.schedC hP0 _ _ t hR1 ((hH.epHyps hP0).stable _ _ _ _ hSR.1 hW1 hS1) ht)) ?_ rintro s2 ⟨hf, hfN, hS⟩ exact ⟨hR1.frame hP hf (KView.stsAct' _ _), hS, hN1.frame hP0.n hfN (Notif.KView.stsAct _ _)⟩ +/-- The native-state instance. -/ +theorem set_thread_state_cq (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) + (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) (hSR : SRN st N T (SRS st T SR) s σ) {t : U64} (ht : t ∈ T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hq : ∀ e ∈ E, ∀ z, σ.kheap e.bv = some (.endpoint z) → t.bv ∉ z.epQueue) + (hqn : ∀ n ∈ N, ∀ z, σ.kheap n.bv = some (.notification z) → t.bv ∉ z.ntfnObj.ntfnQueue) + (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3) (code : U64) (hcode : code.val = tsCode ts) : + sched.set_thread_state st s t code ⦃ s' => + EpStateRel T E R B (L.mem s') (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ∧ + SRN st N T (SRS st T SR) s' (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ⦄ := + set_thread_state_cqVM hH hP0 hP s σ hR hSR ht hk hq hqn ts (Or.inl hts) code hcode + +theorem set_thread_state_cVM (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) + (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) (hSR : SRN st N T (SRS st T SR) s σ) {t : U64} (ht : t ∈ T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hq : ∀ e ∈ E, ∀ z, σ.kheap e.bv = some (.endpoint z) → t.bv ∉ z.epQueue) (hns : tsCode x.tcbState ≠ 6) + (ts : Fl4Spec.ThreadState) (hts : tsCode ts < 3 ∨ ts = .runningVM) (code : U64) (hcode : code.val = tsCode ts) : + sched.set_thread_state st s t code ⦃ s' => + EpStateRel T E R B (L.mem s') (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ∧ + SRN st N T (SRS st T SR) s' (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ⦄ := + set_thread_state_cqVM hH hP0 hP s σ hR hSR ht hk hq (not_member hSR.2 ht hk (tsCode_ne6 hns)) ts hts code hcode +/-- The native-state instance. -/ theorem set_thread_state_c (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) (hSR : SRN st N T (SRS st T SR) s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) @@ -131,7 +153,7 @@ theorem set_thread_state_c (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R sched.set_thread_state st s t code ⦃ s' => EpStateRel T E R B (L.mem s') (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ∧ SRN st N T (SRS st T SR) s' (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ⦄ := - set_thread_state_cq hH hP0 hP s σ hR hSR ht hk hq (not_member hSR.2 ht hk (tsCode_ne6 hns)) ts hts code hcode + set_thread_state_cVM hH hP0 hP s σ hR hSR ht hk hq hns ts (Or.inl hts) code hcode /-- **`reply_unlink`**, with the notification relation. -/ theorem reply_unlink_c (hH : IpcCore st N T E R B SR) (hP0 : IPlaced N T E R B) (hP : EPlaced T E R B) (s : S) diff --git a/proofs/Fl4Proofs/P3/IpcTcbJAll.lean b/proofs/Fl4Proofs/P3/IpcTcbJAll.lean index 3573613e4..6467e3624 100644 --- a/proofs/Fl4Proofs/P3/IpcTcbJAll.lean +++ b/proofs/Fl4Proofs/P3/IpcTcbJAll.lean @@ -2,6 +2,8 @@ P3 (DESIGN.md §9), TCB invocations: **the IPC side's TCB leaves from `JAtZ`, bundled** (`TcbXIpc`, CSpace's `decode_invocation_threadJAt`'s `hI`): `tcbXIpc_ofJ`. + +(mmuAD gen 42b71) `JAtZB.capN`: `JAtZ.capN` at `JAtZB`; the `JAtZ` name its corollary. -/ import Fl4Proofs.P3.IpcSchedTailJ import Fl4Proofs.P3.IpcReadRegsJ @@ -17,10 +19,11 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a open Fl4Proofs.P3.Notif (inClass inClassR released) /-- A notification cap's object in a slot is one of `JAtZ`'s notifications, -not at address 0 (`JPlaced.typed`, `JKern.h0`). -/ -theorem JAtZ.capN {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +not at address 0 (`JPlaced.typed`, `JKern.h0`). (mmuAD gen 42b71) Over `JAtZB` in place; `JAtZ.capN` its +corollary. -/ +theorem JAtZB.capN {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {q : U64} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {q : U64} (hq : ∃ x b w r, IsSlot Z.th x ∧ capV (L.mem s) x = .Notification q b w r) : q ∈ Z.N ∧ q ≠ 0#u64 := by obtain ⟨x, b, w, r, hx, hc⟩ := hq obtain ⟨Tr, Cq, hJ⟩ := J.jpl @@ -28,6 +31,13 @@ theorem JAtZ.capN {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {C refine ⟨J.hset.2.1 q hH, fun e => ?_⟩ rw [e, J.kern.h0] at hH; cases hH +/-- `JAtZB.capN` at `JAtZ`. -/ +theorem JAtZ.capN {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {q : U64} + (hq : ∃ x b w r, IsSlot Z.th x ∧ capV (L.mem s) x = .Notification q b w r) : q ∈ Z.N ∧ q ≠ 0#u64 := + J.toB.capN hq + set_option maxHeartbeats 8000000 in /-- **`TcbXIpc` from `JAtZ`** at the decode's state (module docstring). Named, besides `JAtZ` and CSpace's `JStepHyps`: no reschedule pending diff --git a/proofs/Fl4Proofs/P3/JAtZBSchedR.lean b/proofs/Fl4Proofs/P3/JAtZBSchedR.lean index 5e19ae0de..8d0725bec 100644 --- a/proofs/Fl4Proofs/P3/JAtZBSchedR.lean +++ b/proofs/Fl4Proofs/P3/JAtZBSchedR.lean @@ -42,26 +42,39 @@ set_option maxHeartbeats 4000000 in /-- **FL4's `schedule` refines the spec's at `J`** (KENTRY-PLAN.md M7): `jat_scheduleF`'s proof with the spec outcome kept: some `Fires σ σ1`, then `Fl4Spec.schedule σ1 = {((), σ')}`, with `JAtZB`, `CurInv` and -`CurRunW` at `σ'` (`XTopJointSchedR.jat_scheduleFR` over `JAtZB`, gen 32: `RJ` dropped, it packs a `JAtZ`). -/ -theorem JAtZB.jat_scheduleFR {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +`CurRunW` at `σ'` (`XTopJointSchedR.jat_scheduleFR` over `JAtZB`, gen 32: `RJ` dropped, it packs a `JAtZ`). +(mmuAD gen 42b76) Over any fire relation `F` and record `Pf` of the timers' outcome (`hfJ`: `F`, the domain time +kept, `JAtZB` and `Pf` after `timer.fire`); the post adds the timers' outcome `rf` (`Pf`), the scheduler's native +footprint from it (`TFoot`) and its spec step (`SchStep`). `jat_scheduleFR` is it at `F := Fires` by `fireJ`. +(mmuAD gen 42b80) The tail `hTail` also receives FL4's timers' outcome `rf` (`timer.fire s a = ok rf`), `JAtZB` and +`Pf` at `(rf, σ1)`, so it can be discharged at the actual outcome (VmSchedTail's `kfin_tail_ofB`). -/ +theorem JAtZB.jat_scheduleFRG {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hd : σ.domainTime ≠ 0) (hnd : Fl4Spec.numDomains = 1) (hAT : P0.ArchTotal arI) (hVt : ∀ (V1 : XVs) (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1 → ∀ t ∈ Z.T, Z.th t = some .tcb ∧ ∀ p asid, capAt (L.mem s1) (slotOf t 1) = ok (.Pml4 p true asid) → asid ≠ 0#u64) - (hSig : SignalJHypB (L := L) arI AR H Cs) + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} {Pf : S × A → Fl4Spec.State Unit → Prop} + (hfJ : timer.fire st arI s a ⦃ r => ∃ σ1 : Fl4Spec.State Unit, F σ σ1 ∧ σ1.domainTime = σ.domainTime ∧ + (∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 r.1 r.2 σ1) ∧ Pf r σ1 ⦄) (hA : ArchSw st arI Z.N Z.T Z.C Z.c) (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) - (hTail : sched.schedule st arI s a ⦃ r => ∀ (rf : S × A) σ1 σ' (D1 : Set U64), Fires σ σ1 → + (hTail : sched.schedule st arI s a ⦃ r => ∀ (rf : S × A) σ1 σ' (D1 : Set U64), F σ σ1 → + timer.fire st arI s a = ok rf → + (∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D2 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D2 rf.1 rf.2 σ1) → Pf rf σ1 → Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) → P1.WritesIn st rf.1 r.1 (KFoot st Z.T Z.N Z.C Z.c rf.1 σ1) → SchedRel st Z.N Z.T Z.C Z.c r.1 σ' → Inv σ' → CurInv σ' → ActIdle σ' → SchTailHypsR AR Z H D1 r.1 r.2 σ' ⦄) : - sched.schedule st arI s a ⦃ r => ∃ (σ1 σ' : Fl4Spec.State Unit), Fires σ σ1 ∧ + sched.schedule st arI s a ⦃ r => ∃ (σ1 σ' : Fl4Spec.State Unit), F σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ') ∧ CurInv σ' ∧ CurRunW σ' ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ') ∧ CurInv σ' ∧ CurRunW σ' ∧ + ∃ rf : S × A, Pf rf σ1 ∧ P1.WritesIn st rf.1 r.1 (TFoot st Z.T Z.N Z.C Z.c rf.1 σ1) ∧ + SchStep (fun _ => False) σ1 σ' ⦄ := by have h0Cs : 0#u64 ∈ Cs := J.kern.cs0 have hX := J.xtop have hS := hX.fin.1.1.1 @@ -71,26 +84,26 @@ theorem JAtZB.jat_scheduleFR {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h have hal : P1.Aligned (L.nodeAt s 0#u64 layout.node.DEBUG_TCBS) := P1.nodeAt_aligned (hq.nodes 0#u64 h0Cs) (by simp) (by simp) - have hfire2 : timer.fire st arI s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st Z.N Z.T Z.C Z.c r.1 σ1 ∧ + have hfire2 : timer.fire st arI s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st Z.N Z.T Z.C Z.c r.1 σ1 ∧ NtfnStateRel Z.N Z.T (L.mem r.1) σ1 ∧ NSC Z.N Z.C σ1 ∧ SchedPreW Z.T Z.C σ1 ∧ ((∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 r.1 r.2 σ1) ∧ - timer.fire st arI s a = ok r ∧ L.ksb r.1 = L.ksb s) ⦄ := by - refine WP.spec_mono (P1.spec_eq' (WP.spec_and (J.fireJ hSig) (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a hB J.bufAtJ))) ?_ - rintro ⟨s1, a1⟩ ⟨hf, ⟨σ1, V1, Ac1, Lst1, D1, h1, hd1, J1⟩, hk⟩ + timer.fire st arI s a = ok r ∧ L.ksb r.1 = L.ksb s ∧ Pf r σ1) ⦄ := by + refine WP.spec_mono (P1.spec_eq' (WP.spec_and hfJ (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a hB J.bufAtJ))) ?_ + rintro ⟨s1, a1⟩ ⟨hf, ⟨σ1, h1, hd1, ⟨V1, Ac1, Lst1, D1, J1⟩, hPf⟩, hk⟩ simp only [WP.uncurry'_pair] at hk have hd1' : σ1.domainTime ≠ 0 := by rw [hd1]; exact hd exact ⟨σ1, h1, J1.xtop.fin.1.1.1, J1.xtop.fin.1.1.2.2.1, J1.nsc, J1.schedPreW hd1', - ⟨V1, Ac1, Lst1, D1, J1⟩, hf, hk.1⟩ + ⟨V1, Ac1, Lst1, D1, J1⟩, hf, hk.1, hPf⟩ refine WP.spec_mono (WP.spec_and (WP.spec_and (schedule_refinesWP s a σ hS hR J.nsc hnd hfire2 hA hsni hsend hT) (P1.sched.schedule.kw hAT (P1.ibKeep_holds hAT) hNt s a hB J.bufAtJ)) (WP.spec_and (P1.sched.schedule.tinv hAT (P1.ibKeep_holds hAT) hNt s a Q R hq hBd hSc hXi hSg J.bufAtJ) hTail)) ?_ - rintro ⟨s', a'⟩ ⟨⟨⟨σ1, σ', hF, hsc, hS', hR', hN', hI', hC', hA', rf, ⟨⟨V1, Ac1, Lst1, D1, J1⟩, hfr, hkf⟩, hw, hrun⟩, + rintro ⟨s', a'⟩ ⟨⟨⟨σ1, σ', hF, hsc, hS', hR', hN', hI', hC', hA', rf, ⟨⟨V1, Ac1, Lst1, D1, J1⟩, hfr, hkf, hPf⟩, hw, hrun⟩, hkw⟩, ⟨htinv, hRest⟩⟩ simp only [WP.uncurry'_pair] at hkw htinv obtain ⟨rf', hrf', -, hkw⟩ := hkw obtain rfl : rf = rf' := by simpa using (hrf'.symm.trans hfr).symm - have hTl := hRest rf σ1 σ' D1 hF hsc hw hS' hI' hC' hA' + have hTl := hRest rf σ1 σ' D1 hF hfr ⟨V1, Ac1, Lst1, D1, J1⟩ hPf hsc hw hS' hI' hC' hA' obtain ⟨⟨Q', R', hq'⟩, hBd', hXi', hSc', -, -, -, -⟩ := htinv have hks' : L.ksb s' = L.ksb s := hkw.1.trans hkf have hnA : L.nodeAt rf.1 0#u64 layout.node.DEBUG_TCBS = L.nodeAt s 0#u64 layout.node.DEBUG_TCBS := @@ -139,7 +152,35 @@ theorem JAtZB.jat_scheduleFR {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} obtain ⟨Lst', J'⟩ := J1.sch_tail hsc hw hS' hR' hN' hI' hC' hA' (RunW.scAndTimer (hr3 J1.curRun) he3) (OffOK.scAndTimer ho3 he3) (bsa_schedule J1.bsa hsc) hT2 exact ⟨σ1, σ', hF, hsc, ⟨V1, Ac, Lst', D1, J'⟩, hC', - RunW.scAndTimer (hr3 J1.curRun) he3⟩ + RunW.scAndTimer (hr3 J1.curRun) he3, rf, hPf, hwT, hK1⟩ + +/-- **FL4's `schedule` refines the spec's at `J`** (KENTRY-PLAN.md M7; statement of gen 32): `jat_scheduleFRG` +(mmuAD gen 42b76) at `F := Fires`, the timers by `fireJ` (`SignalJHypB` [J]). -/ +theorem JAtZB.jat_scheduleFR {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hd : σ.domainTime ≠ 0) (hnd : Fl4Spec.numDomains = 1) + (hAT : P0.ArchTotal arI) + (hVt : ∀ (V1 : XVs) (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (Ac1 : Set U64) (Lst1 : U64 → List U64) + (D1 : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1 → ∀ t ∈ Z.T, + Z.th t = some .tcb ∧ ∀ p asid, capAt (L.mem s1) (slotOf t 1) = ok (.Pml4 p true asid) → asid ≠ 0#u64) + (hSig : SignalJHypB (L := L) arI AR H Cs) + (hA : ArchSw st arI Z.N Z.T Z.C Z.c) + (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) + (hTail : sched.schedule st arI s a ⦃ r => ∀ (rf : S × A) σ1 σ' (D1 : Set U64), Fires σ σ1 → + Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) → + P1.WritesIn st rf.1 r.1 (KFoot st Z.T Z.N Z.C Z.c rf.1 σ1) → + SchedRel st Z.N Z.T Z.C Z.c r.1 σ' → Inv σ' → CurInv σ' → ActIdle σ' → + SchTailHypsR AR Z H D1 r.1 r.2 σ' ⦄) : + sched.schedule st arI s a ⦃ r => ∃ (σ1 σ' : Fl4Spec.State Unit), Fires σ σ1 ∧ + Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ') ∧ CurInv σ' ∧ CurRunW σ' ⦄ := + WP.spec_mono (J.jat_scheduleFRG (Pf := fun _ _ => True) s a σ hd hnd hAT hVt + (WP.spec_mono (J.fireJ hSig) fun _ h => by + obtain ⟨σ1, V1, Ac1, Lst1, D1, h1, hd1, J1⟩ := h + exact ⟨σ1, h1, hd1, ⟨V1, Ac1, Lst1, D1, J1⟩, trivial⟩) hA hsni hsend hT + (WP.spec_mono hTail fun _ h rf σ1 σ' D1 hF _ _ _ => h rf σ1 σ' D1 hF)) + fun _ ⟨σ1, σ', h1, h2, h3, h4, h5, _⟩ => ⟨σ1, σ', h1, h2, h3, h4, h5⟩ end diff --git a/proofs/Fl4Proofs/P3/JAtZV3.lean b/proofs/Fl4Proofs/P3/JAtZV3.lean index 7224b77e4..7111ea2d1 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3.lean @@ -690,7 +690,7 @@ set_option maxHeartbeats 4000000 in /-- **`VmBase` across a native step that may change the spec heap, from the slots kept and the writes' VCPU apartness** (gen 42b46: `VmBase.ofBS`'s proof with `hSS` / `nV` for `hO`, the end state at any `Z.mv Z.G V'`, for P3/NatFoot's `TmNode` words; `VmBase.ofBS` its corollary). -/ -theorem VmBase.ofBSS (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) +theorem VmBase.ofBSSCore (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} {V' : XVs} (B' : JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' s' a' σ') {W : U64 → Prop} (hw : P1.WritesIn st s s' W) (hSS : SlotsSame Z.th (L.mem s) (L.mem s')) @@ -698,8 +698,7 @@ theorem VmBase.ofBSS (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) (hv : VKeep (L := L) Z.th s s') (hvk : ∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv) (hsz : ∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko) - (hrv : ∀ o x', σ'.kheap o = some (.tcb x') → x'.tcbState = .runningVM → - ∃ x, σ.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM) + (hRun : RunVmB (L := L) Z.th s') (hnv : ∀ p (vs : Fl4Spec.VcpuState), σ'.kheap p = some (.archObj (.vcpu vs)) → σ.kheap p = some (.archObj (.vcpu vs))) : VmBase (L := L) arI V AR (Z.mv Z.G V') H Cs Ac' Lst' D' s' a' σ' := by @@ -708,6 +707,34 @@ theorem VmBase.ofBSS (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) have kV := B.kVn J.vm hw nV have E' : JExtVcpu (L := L) V Z.th s' := (J.extv.toV2u.of_eq (fun y hy => hSS.capV hy) hv kV).vcpu + have Jv' : JVm (L := L) V H s' σ' := + J.vm.step (fun _ h => h) (fun _ _ => rfl) hw.1 (fun u hu => by rw [hvk u hu]; exact J.vm.spec u hu) + (fun o ko' ho => Or.inl (hsz o ko' ho)) + have Vl' : VList st V Z.th s' := J.vl.writes hw fun b hb => by + refine ⟨J.vl.lw_al Ly.vfit hb, fun hW => ?_⟩ + rcases hb with rfl | ⟨u, hu, rfl | rfl⟩ + · exact hh _ hW rfl + · have := lay_next_val (Ly.vfit u hu).2 + rcases nV u hu _ hW with h | h <;> omega + · have := lay_prev_val (Ly.vfit u hu).2 + rcases nV u hu _ hW with h | h <;> omega + exact ⟨B', E', hRun, Jv', Vl', J.vb.ofV hvk kV, J.vo.frame hnv, + J.vr.frame (fun u _ vs hu => hnv _ vs hu) (v3_agreeW (L := L) hw (fun u hu => (Ly.vfit u hu).2) nV)⟩ + +/-- A native step uses the old binding of every surviving VM thread. -/ +theorem VmBase.ofBSS (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + {Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} {V' : XVs} + (B' : JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' s' a' σ') {W : U64 → Prop} (hw : P1.WritesIn st s s' W) + (hSS : SlotsSame Z.th (L.mem s) (L.mem s')) + (nV : ∀ u ∈ V, ∀ b, W b → b.val < u.val ∨ u.val + 32768 ≤ b.val) (hh : ∀ b, W b → b ≠ P1.vHeadA st s) + (hv : VKeep (L := L) Z.th s s') + (hvk : ∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv) + (hsz : ∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko) + (hrv : ∀ o x', σ'.kheap o = some (.tcb x') → x'.tcbState = .runningVM → + ∃ x, σ.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM) + (hnv : ∀ p (vs : Fl4Spec.VcpuState), σ'.kheap p = some (.archObj (.vcpu vs)) → + σ.kheap p = some (.archObj (.vcpu vs))) : + VmBase (L := L) arI V AR (Z.mv Z.G V') H Cs Ac' Lst' D' s' a' σ' := by have R' : RunVmB (L := L) Z.th s' := by intro t ht h8 rw [hv t ht] @@ -719,23 +746,12 @@ theorem VmBase.ofBSS (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) have hx' : x'.tcbState = .runningVM := by cases hx : x'.tcbState <;> rw [hx] at w' <;> simp_all [Notif.tsCode] obtain ⟨x, hk, hx⟩ := hrv _ x' hk' hx' - have w0 := (B.xtop.fin.1.1.2.2.1.at_tcb (B.thT t ht) hk).st + have w0 := (J.base.xtop.fin.1.1.2.2.1.at_tcb (J.base.thT t ht) hk).st rw [hx] at w0 apply UScalar.eq_of_val_eq rw [w0]; simp [Notif.tsCode] - have Jv' : JVm (L := L) V H s' σ' := - J.vm.step (fun _ h => h) (fun _ _ => rfl) hw.1 (fun u hu => by rw [hvk u hu]; exact J.vm.spec u hu) - (fun o ko' ho => Or.inl (hsz o ko' ho)) - have Vl' : VList st V Z.th s' := J.vl.writes hw fun b hb => by - refine ⟨J.vl.lw_al Ly.vfit hb, fun hW => ?_⟩ - rcases hb with rfl | ⟨u, hu, rfl | rfl⟩ - · exact hh _ hW rfl - · have := lay_next_val (Ly.vfit u hu).2 - rcases nV u hu _ hW with h | h <;> omega - · have := lay_prev_val (Ly.vfit u hu).2 - rcases nV u hu _ hW with h | h <;> omega - exact ⟨B', E', R', Jv', Vl', J.vb.ofV hvk kV, J.vo.frame hnv, - J.vr.frame (fun u _ vs hu => hnv _ vs hu) (v3_agreeW (L := L) hw (fun u hu => (Ly.vfit u hu).2) nV)⟩ + exact J.ofBSSCore B' hw hSS nV hh hv hvk hsz R' hnv + /-- **`VmBase` across a native step that may change the spec heap** (gen 42b42: P3/VmState's `VcpuCore.ofBS` proof, moved here; `VcpuCore.ofBS` and `JAtZV3.ofBS` are its corollaries; gen 42b46: `VmBase.ofBSS`'s corollary). -/ diff --git a/proofs/Fl4Proofs/P3/JAtZV3Check.lean b/proofs/Fl4Proofs/P3/JAtZV3Check.lean index 6487683f3..01301ee63 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3Check.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3Check.lean @@ -18,6 +18,10 @@ check as FL4 does it). Premises: [P] `ZvVirtAgree arI`, `P0.ArchTotal arI` (gen 34's, through `reportJ3`). Scope: `hcur`. No [J]; no existing statement changed. +(mmuAD gen 42b81) Generalised in place over the record: **`vmCheckNPG`** / **`vmCheckG`** take any `P` with `VmBase` +(`hB`), a report step (`CkRep`) and the notification idling (`CkIdle`); `JAtZV3.checkNP` / `JAtZV3.checkJ` are their +instances (`JAtZV3.ckRep`, `JAtZV3.ckIdle`), statements unchanged; `JAtZB.repCur` is `JAtZV3.repCur` read off the +base (`JAtZV3.repCur` its corollary). P3/VmCheck instantiates them at `VmEptState`. -/ import Fl4Proofs.P3.JAtZV3Ntfn import Fl4Proofs.P3.JAtZV3ReportJ3 @@ -165,13 +169,30 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} +/-- (gen 42b81) **The report step `vmCheckG` needs at a record `P`**: FL4's `vcpu.report` of a `runningVM` TCB +against `vmReportF`, `P` after (the `Ac` / `Lst` sets fresh). -/ +def CkRep (st : machine.Store S) (arI : machine.Arch A) (th : TypedHeap) + (P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop) : Prop := + ∀ {Ac Lst s a σ}, P Ac Lst s a σ → ∀ {t : U64}, th t = some .tcb → + (∃ x, σ.kheap t.bv = some (.tcb x) ∧ x.tcbState = .runningVM) → ∀ badge : U64, + vcpu.report st arI s a t badge ⦃ s' => ∃ (σr : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vmReportF (Z := Unit) t.bv badge.bv σ = ({((), σr)}, False) ∧ P Ac' Lst' s' a σr ⦄ + +/-- (gen 42b81) **An active notification of `N` made idle at a record `P`** (FL4's `set_state(NTFN_IDLE)`). -/ +def CkIdle (st : machine.Store S) (N : Set U64) + (P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop) : Prop := + ∀ {Ac Lst s a σ}, P Ac Lst s a σ → ∀ {n : U64}, n ∈ N → ∀ {x : Fl4Spec.Notification}, + σ.kheap n.bv = some (.notification x) → ∀ {b0 : Fl4Spec.Badge}, x.ntfnObj = .activeNtfn b0 → + obj.Ntfn.set_state st n s obj.NTFN_IDLE ⦃ s1 => ∃ (Ac' : Set U64) (Lst' : U64 → List U64), + P Ac' Lst' s1 a (updK σ n.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) x))) ⦄ + set_option maxHeartbeats 4000000 in -/-- **The spec's report keeps the current thread** (module docstring). -/ -theorem JAtZV3.repCur (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} +/-- **The spec's report keeps the current thread** (module docstring; gen 42b81: read off the base `JAtZB`, +`JAtZV3.repCur` its corollary). -/ +theorem JAtZB.repCur (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {b : Fl4Spec.Word} {σr : Fl4Spec.State Unit} (hr : Fl4Spec.vmReportF (Z := Unit) t.bv b σ = ({((), σr)}, False)) : σr.curThread = σ.curThread := by - have B := J.z2.zv.base have htT := B.thT t ht have hOK := B.bok have hBC := bufCover_of_frameCover (T := Z.T) B.bok B.fcov @@ -200,10 +221,19 @@ theorem JAtZV3.repCur (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t exact v3_jMrSt_cur _ _ _ _ _ · exact v3_jMrSt_cur _ _ _ _ _ +theorem JAtZV3.repCur (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} + (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {b : Fl4Spec.Word} + {σr : Fl4Spec.State Unit} (hr : Fl4Spec.vmReportF (Z := Unit) t.bv b σ = ({((), σr)}, False)) : + σr.curThread = σ.curThread := + J.z2.zv.base.repCur ht hk hr + set_option maxHeartbeats 8000000 in -/-- **`vcpu::check`'s tail without a pending exit** (module docstring). `v` is FL4's TCB VCPU word. -/ -theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) +/-- **`vcpu::check`'s tail without a pending exit** (module docstring). `v` is FL4's TCB VCPU word. (gen 42b81) Over +any record `P` giving `VmBase` (`hB`) with a report step (`CkRep`) and the notification made idle (`CkIdle`); +`JAtZV3.checkNP` its instance. -/ +theorem vmCheckNPG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB : ∀ {Ac Lst s a σ}, P Ac Lst s a σ → VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hRep : CkRep st arI Z.th P) (hIdle : CkIdle st Z.N P) (J : P Ac Lst s a σ) {t : U64} (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) (hcur : σ.curThread = t.bv) (hnp : NoPend σ t.bv) {v : U64} (hv0 : v = 0#u64 ↔ Fl4Spec.tcbVcpuOf σ t.bv = none) : @@ -231,8 +261,8 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) ok (s1, a) else ok (s, a)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by - have B := J.z2.zv.base + P Ac' Lst' r.1 r.2 σ' ∧ r.2 = a ⦄ := by + have B := (hB J).base have htT := B.thT t ht have hI := B.xtop.irelK B.ks B.buf obtain ⟨x', hk', hR⟩ := B.xtop.ipc.tcb t htT @@ -244,10 +274,10 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) let s1 ← vcpu.report st arI s a t 0#u64 ok (s1, a)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by + P Ac' Lst' r.1 r.2 σ' ∧ r.2 = a ⦄ := by intro hna hvo - refine WP.spec_bind (J.reportJ3 hA hVA ht ⟨x, hk, hrs⟩ 0#u64) ?_ - rintro s1 ⟨σr, Ac', Lst', hr, J1, -, -⟩ + refine WP.spec_bind (hRep J ht ⟨x, hk, hrs⟩ 0#u64) ?_ + rintro s1 ⟨σr, Ac', Lst', hr, J1⟩ refine (WP.spec_ok _).2 ⟨σr, Ac', Lst', ?_, J1, rfl⟩ rw [v3_vmCheckF_noact hk hrs hnp hna] unfold Fl4Spec.NonDet.when @@ -256,7 +286,7 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) have KEEP : NoAct σ x → Fl4Spec.tcbVcpuOf σ t.bv ≠ none → (ok (s, a) : Result (S × A)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by + P Ac' Lst' r.1 r.2 σ' ∧ r.2 = a ⦄ := by intro hna hvo refine (WP.spec_ok _).2 ⟨σ, Ac, Lst, ?_, J, rfl⟩ rw [v3_vmCheckF_noact hk hrs hnp hna] @@ -270,7 +300,7 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) ok (s1, a) else ok (s, a)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by + P Ac' Lst' r.1 r.2 σ' ∧ r.2 = a ⦄ := by intro hna by_cases e : v = 0#u64 · rw [if_pos e]; exact REP0 hna (hv0.1 e) @@ -300,16 +330,15 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) have := hx.obj; rw [ho] at this; exact this.2.2 refine WP.spec_bind (Notif.obj.Ntfn.badge.spec s i1) fun bd ebd => ?_ subst ebd - refine WP.spec_bind (J.ntfnIdle hnN hkn ho) fun s1 J1 => ?_ + refine WP.spec_bind (hIdle J hnN hkn ho) fun s1 ⟨Ac1, Lst1, J1⟩ => ?_ have hnt : i1.bv ≠ t.bv := by intro e; rw [e, hk] at hkn; cases hkn have hk1 : (updK σ i1.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) y))).kheap t.bv = some (.tcb x) := by simp [updK, hnt.symm, hk] - refine WP.spec_bind (J1.reportJ3 hA hVA ht ⟨x, hk1, hrs⟩ (L.mem s (nBadgeA i1))) - ?_ - rintro s2 ⟨σr, Ac', Lst', hr, J2, -, -⟩ + refine WP.spec_bind (hRep J1 ht ⟨x, hk1, hrs⟩ (L.mem s (nBadgeA i1))) ?_ + rintro s2 ⟨σr, Ac', Lst', hr, J2⟩ refine (WP.spec_ok _).2 ⟨σr, Ac', Lst', ?_, J2, rfl⟩ rw [hb0] at hr - exact v3_vmCheckF_act hk hrs hnp hbn hkn ho hr ((J1.repCur ht hk1 hr).trans hcur) + exact v3_vmCheckF_act hk hrs hnp hbn hkn ho hr (((hB J1).base.repCur ht hk1 hr).trans hcur) | idleNtfn => have hst : i2 ≠ obj.NTFN_ACTIVE := by rw [ei2, stOf_idle hx.obj ho]; unfold obj.NTFN_ACTIVE obj.NTFN_IDLE; decide @@ -322,16 +351,18 @@ theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) exact NOACT (Or.inr ⟨i1.bv, y, hbn, hkn, fun b e => by rw [ho] at e; cases e⟩) set_option maxHeartbeats 8000000 in -/-- **`vcpu::check` of the current thread at `JAtZV3`, paired with `vmCheckF`** (module docstring). -/ -theorem JAtZV3.checkJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) +/-- **`vcpu::check` of the current thread at `JAtZV3`, paired with `vmCheckF`** (module docstring). (gen 42b81) Over +any record `P` as `vmCheckNPG`; `JAtZV3.checkJ` its instance. -/ +theorem vmCheckG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB : ∀ {Ac Lst s a σ}, P Ac Lst s a σ → VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hRep : CkRep st arI Z.th P) (hIdle : CkIdle st Z.N P) (J : P Ac Lst s a σ) {t : U64} (ht : Z.th t = some .tcb) (hcur : σ.curThread = t.bv) : vcpu.check st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by - have Jz := J.z2.zv - have B := Jz.base - have hO := J.vo + P Ac' Lst' r.1 r.2 σ' ∧ r.2 = a ⦄ := by + have Jv := hB J + have B := Jv.base + have hO := Jv.vo obtain ⟨x, hk, hwst⟩ := B.specTcb ht unfold vcpu.check refine WP.spec_bind (P1.obj.Tcb.state.spec s t) fun i ei => ?_ @@ -357,38 +388,92 @@ theorem JAtZV3.checkJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) by_cases hv0 : v = 0#u64 · have h0 : L.mem s (tVcpuA t) = 0#u64 := ev'.symm.trans hv0 have hTV : Fl4Spec.tcbVcpuOf σ t.bv = none := zv_tcbVcpuOf_none fun w ws hw hwt => by - obtain ⟨u, hu, -, h1, -⟩ := J.z2.specBound hO ht hw hwt - exact Jz.extv.nz u hu (h1.symm.trans h0) + obtain ⟨u, hu, -, h1, -⟩ := Jv.specBound hO ht hw hwt + exact Jv.extv.nz u hu (h1.symm.trans h0) rw [if_neg (by simp [hv0])] - exact J.checkNP hA hVA ht hk hrs hcur (Or.inl hTV) ⟨fun _ => hTV, fun _ => hv0⟩ + exact vmCheckNPG hB hRep hIdle J ht hk hrs hcur (Or.inl hTV) ⟨fun _ => hTV, fun _ => hv0⟩ · have hne0 : L.mem s (tVcpuA t) ≠ 0#u64 := fun h => hv0 (ev'.trans h) - obtain ⟨hvV, hvt⟩ := (Jz.extv.bnd t ht).resolve_left hne0 + obtain ⟨hvV, hvt⟩ := (Jv.extv.bnd t ht).resolve_left hne0 rw [← ev'] at hvV hvt - obtain ⟨vs, hkv, hbv⟩ := J.z2.vb v hvV + obtain ⟨vs, hkv, hbv⟩ := Jv.vb v hvV have hvs : Fl4Spec.VcpuState.tcb vs = some t.bv := by rcases hbv with ⟨-, h0⟩ | ⟨t', -, h1, h2⟩ · have e : t = 0#u64 := hvt.symm.trans h0 subst e - exact absurd ht (B.detPl Jz.vm).h0 + exact absurd ht (B.detPl Jv.vm).h0 · have e : t' = t := h2.symm.trans hvt rw [h1, e] have hTV : Fl4Spec.tcbVcpuOf σ t.bv = some v.bv := zv_tcbVcpuOf_eq hkv hvs fun w ws hw hwt => by - obtain ⟨u, hu, rfl, h1, -⟩ := J.z2.specBound hO ht hw hwt + obtain ⟨u, hu, rfl, h1, -⟩ := Jv.specBound hO ht hw hwt rw [← h1, ← ev'] rw [if_pos (by simp [hv0]), v3_get_eq, bind_ok] - have hpd := J.rdPend hvV hkv + have hpd := Jv.toF.rdPend hvV hkv by_cases hp : vs.exit.pending = true · rw [if_pos (by rw [hpd, hp])] - refine WP.spec_bind (J.reportJ3 hA hVA ht ⟨x, hk, hrs⟩ 0#u64) ?_ - rintro s1 ⟨σr, Ac', Lst', hr, J1, -, -⟩ + refine WP.spec_bind (hRep J ht ⟨x, hk, hrs⟩ 0#u64) ?_ + rintro s1 ⟨σr, Ac', Lst', hr, J1⟩ refine (WP.spec_ok _).2 ⟨σr, Ac', Lst', ?_, J1, rfl⟩ rw [v3_vmCheckF_pend hk hrs hTV hkv hp] exact hr · have hp' : vs.exit.pending = false := by simpa using hp rw [if_neg (by rw [hpd, hp']; simp)] - exact J.checkNP hA hVA ht hk hrs hcur (Or.inr ⟨v.bv, vs, hTV, hkv, hp'⟩) + exact vmCheckNPG hB hRep hIdle J ht hk hrs hcur (Or.inr ⟨v.bv, vs, hTV, hkv, hp'⟩) ⟨fun e => absurd e hv0, fun e => by rw [hTV] at e; cases e⟩ +/-- `JAtZV3`'s report step and notification idling (gen 42b81: the records `vmCheckG` takes). -/ +theorem JAtZV3.ckRep (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) : + CkRep st arI Z.th fun Ac Lst s a σ => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ := + fun J _ ht hrun b => WP.spec_mono (J.reportJ3 hA hVA ht hrun b) fun _ ⟨σr, Ac', Lst', h1, J', _, _⟩ => + ⟨σr, Ac', Lst', h1, J'⟩ + +theorem JAtZV3.ckIdle : + CkIdle st Z.N fun Ac Lst s a σ => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ := + fun J _ hn _ hk _ hact => WP.spec_mono (J.ntfnIdle hn hk hact) fun _ J' => ⟨_, _, J'⟩ + +/-- **`vcpu::check`'s tail without a pending exit at `JAtZV3`** (`vmCheckNPG`'s instance). -/ +theorem JAtZV3.checkNP (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) + (hcur : σ.curThread = t.bv) (hnp : NoPend σ t.bv) {v : U64} + (hv0 : v = 0#u64 ↔ Fl4Spec.tcbVcpuOf σ t.bv = none) : + (do + let i1 ← obj.Tcb.bound_ntfn st t s + if i1 != 0#u64 + then + let i2 ← obj.Ntfn.state st i1 s + if i2 = obj.NTFN_ACTIVE + then + let badge ← obj.Ntfn.badge st i1 s + let s1 ← obj.Ntfn.set_state st i1 s obj.NTFN_IDLE + let s2 ← vcpu.report st arI s1 a t badge + ok (s2, a) + else + if v = 0#u64 + then + let s1 ← vcpu.report st arI s a t 0#u64 + ok (s1, a) + else ok (s, a) + else + if v = 0#u64 + then + let s1 ← vcpu.report st arI s a t 0#u64 + ok (s1, a) + else ok (s, a)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := + vmCheckNPG (P := fun Ac Lst s a σ => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) JAtZV3.toB + (JAtZV3.ckRep hA hVA) JAtZV3.ckIdle J ht hk hrs hcur hnp hv0 + +/-- **`vcpu::check` of the current thread at `JAtZV3`, paired with `vmCheckF`** (`vmCheckG`'s instance). -/ +theorem JAtZV3.checkJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) + (hcur : σ.curThread = t.bv) : + vcpu.check st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := + vmCheckG (P := fun Ac Lst s a σ => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) JAtZV3.toB + (JAtZV3.ckRep hA hVA) JAtZV3.ckIdle J ht hcur + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3FaultBlk.lean b/proofs/Fl4Proofs/P3/JAtZV3FaultBlk.lean index 6f7a33c75..b8555f519 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3FaultBlk.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3FaultBlk.lean @@ -11,7 +11,8 @@ P3 (line mmuAD, gen 42a2): **`handle_fault` with an endpoint fault handler and n and replies are `H`'s objects, off the kernel-global area). * **`zv_bfrt`**: the spec frame `BFrT t e` of a blocking send (only the sender's TCB, to `blockedOnSend`, and the endpoint change) keeps every arch object and every object's size, makes no `runningVM` thread and no VCPU object — - `JAtZV3.ofBS`'s `hvk` / `hsz` / `hrv` / `hnv` (as P3/JAtZV3Sched's `zv_qky`). + `JAtZV3.ofBS`'s `hvk` / `hsz` / `hrv` / `hnv` (as P3/JAtZV3Sched's `zv_qky`). (mmuAD gen 42b67: moved to + P3/XTopJointFaultEp, statement unchanged.) * **`JAtZV3.faultBlockJ3`**: P3/XTopJointFaultEp's `JAtZ.faultBlockJ` at `JAtZV3`: the proof verbatim over `J3.z2.zv.base` (`JCs.same` → `JCs.sameB`; no `[VxE Z]`), the post `ZvPost`: its `JAtZB.cs_frameI` result is at `Z.mv Z.G Z.vs` = `Z`, lifted by `JAtZV3.ofBS` with the `CnW` footprint and `zv_bfrt`. Heartbeats 4M (source @@ -33,36 +34,6 @@ open fl4_core noncomputable section -/-- **What a blocking send's spec frame keeps of the VM epoch** (module docstring). -/ -theorem zv_bfrt {t e : Fl4Spec.ObjRef} {σ σ' : Fl4Spec.State Unit} (h : Sched.BFrT t e σ σ') : - (∀ p ao, σ.kheap p = some (.archObj ao) → σ'.kheap p = σ.kheap p) ∧ - (∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko) ∧ - (∀ o x', σ'.kheap o = some (.tcb x') → x'.tcbState = .runningVM → - ∃ x, σ.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM) ∧ - (∀ p (vs : Fl4Spec.VcpuState), σ'.kheap p = some (.archObj (.vcpu vs)) → - σ.kheap p = some (.archObj (.vcpu vs))) := by - refine ⟨fun p ao hp => ?_, fun o ko' ho => ?_, fun o x' ho hx => ?_, fun p vs hp => ?_⟩ - · rcases h.kh p with k | ⟨o, o', h1, -, hc⟩ - · exact k - · rw [hp] at h1; cases h1 - rcases hc with ⟨_, _, _, _, e, -⟩ | ⟨_, _, e, -⟩ <;> cases e - · rcases h.kh o with k | ⟨o1, o2, h1, h2, hc⟩ - · exact ⟨ko', by rw [← k]; exact ho, rfl⟩ - · rw [ho] at h2; cases h2 - rcases hc with ⟨_, _, _, _, rfl, rfl, -⟩ | ⟨_, _, rfl, rfl, -⟩ - · exact ⟨_, h1, rfl⟩ - · exact ⟨_, h1, rfl⟩ - · rcases h.kh o with k | ⟨o1, o2, h1, h2, hc⟩ - · exact ⟨x', by rw [← k]; exact ho, hx⟩ - · rw [ho] at h2; cases h2 - rcases hc with ⟨_, _, _, _, rfl, e, -⟩ | ⟨_, _, rfl, e, -⟩ - · cases e; cases hx - · cases e - · rcases h.kh p with k | ⟨o1, o2, h1, h2, hc⟩ - · rw [← k]; exact hp - · rw [hp] at h2; cases h2 - rcases hc with ⟨_, _, _, _, -, e, -⟩ | ⟨_, _, -, e, -⟩ <;> cases e - section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} diff --git a/proofs/Fl4Proofs/P3/JAtZV3FaultRecvB.lean b/proofs/Fl4Proofs/P3/JAtZV3FaultRecvB.lean index 1ceb8c42f..98cb9638c 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3FaultRecvB.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3FaultRecvB.lean @@ -13,7 +13,8 @@ of gen 42a2's [W] `ZvFaultEpHyp`; the arms are P3/JAtZV3FaultRecv). `recvReplyHyp_holds` at one `JAtZB` state (same proof). * **`ZvK σ σ'`** (`JAtZV3.ofBS`'s spec side: arch objects kept, sizes kept, no new `runningVM`, no new or changed VCPU object), `ZvK.trans`, `ZvK.of_kheap`, `zvk_upd` (one object rewritten), **`zvk_dwfr`** (a wake frame `DWFr`: - `DChg` changes TCB state only within `TCX`, which makes no `runningVM` — `tcx_runVM`), `zvk_ciSt`, `zvk_pushSt`. + `DChg` changes TCB state only within `TCX`, which makes no `runningVM` — `tcx_runVM`), `zvk_ciSt`, `zvk_pushSt` + (the last three moved to P3/XTopJointFaultRecv in mmuAD gen 42b67, statements unchanged). **`JAtZV3.ofBSK`** (`ofBS` with `ZvK`), **`JAtZV3.ofCnW`** (the `CnW` footprint: `CnW.oobj`, `cnW_nh`, `cnW_nv`). * **`JAtZV3.bufWrites3`** / **`bufRebase3`** / **`bufRebaseX3`**: P3/XTopJointXferB's buffer rebase at `JAtZV3` (each buffer word by gen 33's `JAtZV3.userWr`, the rest of the proof verbatim over `J3.z2.zv.base`). @@ -44,59 +45,7 @@ noncomputable section /-! ## The spec side of `JAtZV3.ofBS` -/ -section -open Fl4Proofs.P3.Sched - -variable {σ σ1 σ2 σ3 : Fl4Spec.State Unit} - -/-- **A wake frame keeps the VM epoch's spec side** (module docstring). -/ -theorem zvk_dwfr {r t : Fl4Spec.ObjRef} (F : DWFr r t σ1 σ2) : ZvK σ1 σ2 := by - refine ⟨fun p ao hp => ?_, fun o ko' ho => ?_, fun o x' ho hx => ?_, fun p vs hp => ?_⟩ - · rcases F.kh p with k | ⟨o1, o2, h1, -, hc⟩ - · exact k - · rw [hp] at h1 - cases h1 - rcases hc with ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, _, _, e, -⟩ | ⟨_, _, e, -⟩ | ⟨_, _, e, -⟩ | ⟨_, e, -⟩ <;> - cases e - · rcases F.kh o with k | ⟨o1, o2, h1, h2, hc⟩ - · exact ⟨ko', by rw [← k]; exact ho, rfl⟩ - · rw [ho] at h2 - cases h2 - rcases hc with ⟨_, _, _, _, _, _, rfl, rfl, -⟩ | ⟨_, _, _, _, _, rfl, rfl, -⟩ | ⟨_, _, rfl, rfl, -⟩ | - ⟨_, _, rfl, rfl, -⟩ | ⟨_, rfl, rfl, -⟩ <;> exact ⟨_, h1, rfl⟩ - · rcases F.kh o with k | ⟨o1, o2, h1, h2, hc⟩ - · exact ⟨x', by rw [← k]; exact ho, hx⟩ - · rw [ho] at h2 - cases h2 - rcases hc with ⟨x, st, bn, fl, ar, sc, rfl, e, htc⟩ | ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | - ⟨_, _, _, e, -⟩ | ⟨_, _, e, -⟩ - · cases e - exact ⟨x, h1, tcx_runVM htc hx⟩ - all_goals cases e - · rcases F.kh p with k | ⟨o1, o2, h1, h2, hc⟩ - · rw [← k]; exact hp - · rw [hp] at h2 - cases h2 - rcases hc with ⟨_, _, _, _, _, _, _, e, -⟩ | ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | - ⟨_, _, e, -⟩ <;> cases e - -theorem zvk_ciSt {c : Fl4Spec.ObjRef} {x : Fl4Spec.Tcb} (hk : σ.kheap c = some (.tcb x)) : ZvK σ (ciSt σ c x) := - (zvk_upd (o' := .tcb { x with tcbState := .inactive }) hk rfl (fun _ e => by cases e) (fun _ e => by cases e) - (fun y e hy => by simp only [Fl4Spec.KernelObject.tcb.injEq] at e; subst e; simp at hy)).trans - (ZvK.of_kheap (by unfold ciSt; exact Notif.stsAct_kheap _ _)) - -theorem zvk_pushSt {t r : Fl4Spec.ObjRef} {xr : Fl4Spec.Reply} {xt : Fl4Spec.Tcb} - (hkr : σ.kheap r = some (.reply xr)) (hkt : σ.kheap t = some (.tcb xt)) (htr : t ≠ r) : - ZvK σ (Endp.pushSt σ t r xr xt) := by - have h1 : ZvK σ (Notif.updK σ r (.reply { xr with replyTcb := some t })) := - zvk_upd hkr rfl (fun _ e => by cases e) (fun _ e => by cases e) (fun y e _ => by cases e) - have hkt' : (Notif.updK σ r (.reply { xr with replyTcb := some t })).kheap t = some (.tcb xt) := by - simp [Notif.updK, htr, hkt] - have h2 := zvk_upd (o' := .tcb { xt with tcbState := .blockedOnReply r }) hkt' rfl (fun _ e => by cases e) - (fun _ e => by cases e) (fun y e hy => by simp only [Fl4Spec.KernelObject.tcb.injEq] at e; subst e; simp at hy) - exact (h1.trans h2).trans (ZvK.of_kheap (Notif.stsAct_kheap _ _)) - -end +-- (mmuAD gen 42b67) `zvk_dwfr`, `zvk_ciSt`, `zvk_pushSt` moved to P3/XTopJointFaultRecv (statements unchanged). section open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched diff --git a/proofs/Fl4Proofs/P3/JAtZV3HiRep.lean b/proofs/Fl4Proofs/P3/JAtZV3HiRep.lean index d47d2fe43..3f9fdf83e 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3HiRep.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3HiRep.lean @@ -85,12 +85,12 @@ theorem zv_setMr_ret {B : Set (U64 × Fl4Spec.Word)} {rcv rw : U64} {pb : Option set_option maxHeartbeats 4000000 in /-- **`reply_words` at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.replyWords3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} +theorem VmBaseF.replyWords3 {sA : S} {σA : Fl4Spec.State Unit} {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} {ms : List Fl4Spec.Word} - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) (n : U64) (hn : n.val = mrLen buf ms.length) (hn128 : n.val < 128) : tcb.reply_words st s ct n ⦃ s4 => - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s4 a (replyStateB σ0 ct.bv x0 buf ms) ⦄ := by + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s4 a (replyStateB σ0 ct.bv x0 buf ms) ⦄ := by have hkx := MrS_kheap_t σ0 ct.bv x0 buf ms unfold tcb.reply_words refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.BADGE 0#u64) ?_ @@ -118,18 +118,26 @@ theorem JAtZV3.replyWords3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.T rw [eR] at J2 exact J2 +theorem JAtZV3.replyWords3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} + {ms : List Fl4Spec.Word} + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) + (n : U64) (hn : n.val = mrLen buf ms.length) (hn128 : n.val < 128) : + tcb.reply_words st s ct n ⦃ s4 => + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s4 a (replyStateB σ0 ct.bv x0 buf ms) ⦄ := WP.spec_mono (J.toF.replyWords3 hct n hn hn128) fun _ J' => J.ofF J' + + theorem zv_jMrRet_le (pb : Option Fl4Spec.ObjRef) (n : Nat) : jMrRet pb n ≤ n := by cases pb <;> simp only [jMrRet] <;> omega set_option maxHeartbeats 4000000 in /-- **The word loop at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.wsLoop3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {pb : Option Fl4Spec.ObjRef} +theorem VmBaseF.wsLoop3 {sA : S} {σA : Fl4Spec.State Unit} {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {pb : Option Fl4Spec.ObjRef} (hct : ct ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) {b : U64} (hb : JBufR Z.B b pb) : ∀ (ws : List U64) (ms : List Fl4Spec.Word) (s : S) (i n : U64), - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ0 ct.bv x0 pb ms) → i.val = ms.length → + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ0 ct.bv x0 pb ms) → i.val = ms.length → n.val = jMrRet pb ms.length → ms.length + ws.length ≤ 120 → vcpuReplyWsLoop st ct b s ws i n ⦃ r => - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D r.1 a (jMrSt σ0 ct.bv x0 pb (ms ++ ws.map (·.bv))) ∧ + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D r.1 a (jMrSt σ0 ct.bv x0 pb (ms ++ ws.map (·.bv))) ∧ r.2.val = jMrRet pb (ms.length + ws.length) ⦄ | [], ms, s, i, n, J, _, hn, _ => by rw [vcpuReplyWsLoop_nil, WP.spec_ok] @@ -138,7 +146,7 @@ theorem JAtZV3.wsLoop3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} | w :: ws, ms, s, i, n, J, hi, hn, hl => by simp only [List.length_cons] at hl rw [vcpuReplyWsLoop_cons] - refine WP.spec_bind (WP.spec_and (setMrJ3 J hct hq hb i (by omega) (by omega) w) + refine WP.spec_bind (WP.spec_and (J.setMr hct hq hb i (by omega) (by omega) w) (zv_setMr_ret hb s i w (by omega))) ?_ rintro ⟨n1, s1⟩ ⟨J1, hn1⟩ try simp only [uncurry_apply_pair] @@ -148,7 +156,7 @@ theorem JAtZV3.wsLoop3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} obtain ⟨i2, h2e, h2v⟩ := P1.spec_ex_fd (U64.add_spec (x := i) (y := 1#u64) (by scalar_tac)) rw [h2e, bind_ok] have hi2 : i2.val = i.val + 1 := by simpa using h2v - refine WP.spec_mono (JAtZV3.wsLoop3 hct hq hb ws (ms ++ [w.bv]) s1 i2 n1 J1 + refine WP.spec_mono (VmBaseF.wsLoop3 hct hq hb ws (ms ++ [w.bv]) s1 i2 n1 J1 (by simp; omega) (by rw [hn1, hi]; simp) (by simp; omega)) ?_ rintro r ⟨Jr, hr⟩ refine ⟨?_, ?_⟩ @@ -156,28 +164,33 @@ theorem JAtZV3.wsLoop3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} · rw [hr]; simp only [List.length_append, List.length_cons, List.length_nil]; congr 1; omega /-- FL4's `flTail` does nothing when the caller is not `Restart` (its state word, by `IRel`). -/ -theorem JAtZV3.flTailNo (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) +theorem JAtZB.flTailNo (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState ≠ .restart) (call : Bool) : flTail (st := st) ct call s a ⦃ res => res = (.Ok (), s, a) ⦄ := by - have B := J.z2.zv.base - have hI := B.xtop.irelK B.ks B.buf - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct hct - rw [hk] at hk0; cases hk0 - have hst : (L.mem s (tStA ct)).val = tsCode x.tcbState := hTR.st - have hss : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by rw [P1.stA_eq, ← tStA_eq, hst] unfold flTail refine WP.spec_bind (tcb_state_spec' (st := st) s ct) ?_ rintro i rfl - have hr : L.mem s (stA ct) ≠ sched.TS_RESTART := by - intro h - apply hrs - apply tsCode_two - rw [← hss] - show (L.mem s (stA ct)).val = 2 - rw [h]; unfold sched.TS_RESTART; rfl - rw [if_neg hr, WP.spec_ok] + rw [if_neg (J.notRestart hct hk hrs), WP.spec_ok] + +theorem JAtZV3.flTailNo (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState ≠ .restart) (call : Bool) : + flTail (st := st) ct call s a ⦃ res => res = (.Ok (), s, a) ⦄ := + J.z2.zv.base.flTailNo hct hk hrs call set_option maxHeartbeats 4000000 in +theorem JAtZV3.wsLoop3 {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {pb : Option Fl4Spec.ObjRef} + (hct : ct ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) {b : U64} (hb : JBufR Z.B b pb) : + ∀ (ws : List U64) (ms : List Fl4Spec.Word) (s : S) (i n : U64), + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ0 ct.bv x0 pb ms) → i.val = ms.length → + n.val = jMrRet pb ms.length → ms.length + ws.length ≤ 120 → + vcpuReplyWsLoop st ct b s ws i n ⦃ r => + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D r.1 a (jMrSt σ0 ct.bv x0 pb (ms ++ ws.map (·.bv))) ∧ + r.2.val = jMrRet pb (ms.length + ws.length) ⦄ := by + intro ws ms s i n J hi hn hl + refine WP.spec_mono (VmBaseF.wsLoop3 hct hq hb ws ms s i n J.toF hi hn hl) ?_ + rintro r ⟨J', hlen⟩ + exact ⟨J.ofF J', hlen⟩ +set_option maxHeartbeats 4000000 in /-- **FL4's success tail for an empty result at `JAtZV3`** (module docstring; XTopJointReplyTail's `JAtZ.flTailJ`). -/ theorem JAtZV3.flTail3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) @@ -229,10 +242,10 @@ theorem JAtZV3.flTail3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) { rw [specTail_nil hk call, if_neg hrs]; exact Set.mem_singleton _ /-- The caller's buffer word for a reply (P3/JAtZV3VRvmcb's `readVmcbJ`). -/ -theorem JAtZV3.replyBuf (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) +theorem JAtZB.replyBuf (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) : msg.lookup_ipc_buffer st s true ct ⦃ bw => JBufR Z.B bw (Endp.ipcBufOf true x) ⦄ := by - have B := J.z2.zv.base + have B := J have hcth : Z.th ct = some .tcb := B.thTcb hct obtain ⟨x0, hkx, hwr⟩ := B.buf ct hct rw [hk] at hkx; cases hkx @@ -250,8 +263,28 @@ theorem JAtZV3.replyBuf (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) hBC ct hct x true rp hk hrb bw hrwv, hrwv⟩ exact hb +theorem JAtZV3.replyBuf (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) : + msg.lookup_ipc_buffer st s true ct ⦃ bw => JBufR Z.B bw (Endp.ipcBufOf true x) ⦄ := J.z2.zv.base.replyBuf hct hk + + set_option maxHeartbeats 4000000 in /-- **`reply_words` at `JAtZV3` with a continuation** (as `replyWords3`). -/ +theorem VmBaseF.replyWordsK {sA : S} {σA : Fl4Spec.State Unit} {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} + {ms : List Fl4Spec.Word} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) + (n : U64) (hn : n.val = mrLen buf ms.length) (hn128 : n.val < 128) {β : Type} (K : S → Result β) + {Q : β → Prop} + (hK : ∀ s4, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s4 a (replyStateB σ0 ct.bv x0 buf ms) → K s4 ⦃ Q ⦄) : + (do + let s3 ← obj.Tcb.set_reg st ct s layout.reg.BADGE 0#u64 + let mi ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 n + let s4 ← msg.set_msg_info st s3 ct mi + K s4) ⦃ Q ⦄ := by + simpa only [tcb.reply_words, Std.bind_assoc, bind_ok] using + WP.spec_bind (J.replyWords3 hct n hn hn128) hK + +set_option maxHeartbeats 4000000 in theorem JAtZV3.replyWordsK {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} {ms : List Fl4Spec.Word} (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) @@ -263,38 +296,16 @@ theorem JAtZV3.replyWordsK {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.T let mi ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 n let s4 ← msg.set_msg_info st s3 ct mi K s4) ⦃ Q ⦄ := by - have hkx := MrS_kheap_t σ0 ct.bv x0 buf ms - refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.BADGE 0#u64) ?_ - rintro s1 rfl - have J1 := J.regWr hct hkx Fl4Spec.badge_register 0#u64 - rw [Endp.regIdx_badge] at J1 - rw [mrS_setReg σ0 ct.bv x0 buf ms badge_not_mr] at J1 - have e0 : U64.bv 0#u64 = (0 : Fl4Spec.Word) := rfl - rw [e0] at J1 - set xA := Notif.setReg x0 Fl4Spec.badge_register 0 - unfold msginfo.MessageInfo.new - simp only [bind_ok] - refine WP.spec_bind (Endp.set_msg_info_spec _ ct 0#u64 n hn128) ?_ - rintro s2 ⟨v, rfl, hv⟩ - rw [← Endp.regIdx_msgInfo] - have hkA := MrS_kheap_t (Notif.updK σ0 ct.bv (.tcb xA)) ct.bv xA buf ms - have J2 := J1.regWr hct hkA Fl4Spec.msg_info_register v - have hvd : v.bv = Fl4Spec.messageInfoToData ⟨Fl4Spec.natToLen (mrLen buf ms.length), 0, 0, 0⟩ := by - rw [hv]; congr 2 - apply BitVec.eq_of_toNat_eq; simp only [Fl4Spec.natToLen, BitVec.toNat_ofNat, UScalar.bv_toNat, ← hn]; omega - have eR : Notif.updK (MrS (Notif.updK σ0 ct.bv (.tcb xA)) ct.bv xA buf ms) ct.bv - (.tcb (Notif.setReg (Endp.withRegs xA (Endp.mrRegs xA.tcbArch.tcbContext.userRegs ms)) - Fl4Spec.msg_info_register v.bv)) = replyStateB σ0 ct.bv x0 buf ms := by - unfold replyStateB; rw [hvd] - rw [eR] at J2 - exact hK _ J2 + refine J.toF.replyWordsK hct n hn hn128 K ?_ + exact fun s4 J' => hK s4 (J.ofF J') + set_option maxHeartbeats 4000000 in /-- **`vcpuReplyWs` from a `Running` caller at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.replyWsRun3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) +theorem VmBaseF.replyWsRun3 {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .running) (call : Bool) (ws : List U64) (hl : ws.length ≤ 120) : - vcpuReplyWs st s ct call ws ⦃ r => ∃ Lst' : U64 → List U64, JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r a + vcpuReplyWs st s ct call ws ⦃ r => ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D r a (stsAct (updK (if call then replyState σ ct.bv x (ws.map (·.bv)) else σ) ct.bv (.tcb { (if call then replyTcbB x (Endp.ipcBufOf true x) (ws.map (·.bv)) else x) with tcbState := .running })) ct.bv) ⦄ := by @@ -303,11 +314,11 @@ theorem JAtZV3.replyWsRun3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a · simp only [Bool.false_eq_true, ↓reduceIte] exact J.runRJ hct hk hrs · simp only [↓reduceIte] - refine WP.spec_bind (J.replyBuf hct hk) ?_ + refine WP.spec_bind (J.base.replyBuf hct hk) ?_ intro bw hb - have J0 : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x (Endp.ipcBufOf true x) []) := by + have J0 : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x (Endp.ipcBufOf true x) []) := by rw [jMrSt_nil hk]; exact J - refine WP.spec_bind (JAtZV3.wsLoop3 hct (fun p h => h) hb ws [] s 0#u64 0#u64 J0 rfl + refine WP.spec_bind (VmBaseF.wsLoop3 hct (fun p h => h) hb ws [] s 0#u64 0#u64 J0 rfl (by cases Endp.ipcBufOf true x <;> rfl) (by simpa using hl)) ?_ rintro ⟨s2, n⟩ ⟨J2, hn⟩ try simp only [uncurry_apply_pair] @@ -320,12 +331,21 @@ theorem JAtZV3.replyWsRun3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a exact J2.replyWordsK hct n hn' hn128 _ fun s4 J4 => J4.runRJ hct (replyStateB_kheap_t _ _ _ _ _) (by rw [replyTcbB_state, hrs]) +theorem JAtZV3.replyWsRun3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .running) (call : Bool) + (ws : List U64) (hl : ws.length ≤ 120) : + vcpuReplyWs st s ct call ws ⦃ r => ∃ Lst' : U64 → List U64, JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r a + (stsAct (updK (if call then replyState σ ct.bv x (ws.map (·.bv)) else σ) ct.bv + (.tcb { (if call then replyTcbB x (Endp.ipcBufOf true x) (ws.map (·.bv)) else x) with + tcbState := .running })) ct.bv) ⦄ := WP.spec_mono (J.toF.replyWsRun3 hct hk hrs call ws hl) fun _ ⟨Lst', J'⟩ => ⟨Lst', J.ofF J'⟩ + + set_option maxHeartbeats 4000000 in /-- **`vcpu.reply` from a `Running` caller at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.vreply3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} +theorem VmBaseF.vreply3 {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {ct : U64} (hcur : sched.cur_thread st s = ok ct) (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .running) (call : Bool) (y : U64) : - vcpu.reply st s call y ⦃ r => ∃ Lst' : U64 → List U64, JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r a + vcpu.reply st s call y ⦃ r => ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D r a (stsAct (updK (if call then replyState σ ct.bv x [y.bv] else σ) ct.bv (.tcb { (if call then replyTcbB x (Endp.ipcBufOf true x) [y.bv] else x) with tcbState := .running })) ct.bv) ⦄ := by @@ -335,13 +355,13 @@ theorem JAtZV3.vreply3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) { · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] exact J.runRJ hct hk hrs · simp only [↓reduceIte] - refine WP.spec_bind (Pₘ := fun s1 => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s1 a + refine WP.spec_bind (Pₘ := fun s1 => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s1 a (replyStateB σ ct.bv x (Endp.ipcBufOf true x) [y.bv])) ?_ ?_ - · refine WP.spec_bind (J.replyBuf hct hk) ?_ + · refine WP.spec_bind (J.base.replyBuf hct hk) ?_ intro bw hb - have J0 : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x (Endp.ipcBufOf true x) []) := by + have J0 : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x (Endp.ipcBufOf true x) []) := by rw [jMrSt_nil hk]; exact J - refine WP.spec_bind (setMrJ3 J0 hct (fun p h => h) hb 0#u64 (by simp) (by simp) y) ?_ + refine WP.spec_bind (J0.setMr hct (fun p h => h) hb 0#u64 (by simp) (by simp) y) ?_ rintro ⟨n1, s2⟩ J2 try simp only [uncurry_apply_pair] have em : mrUpd [] (0#u64 : U64).val y.bv = [y.bv] := by unfold mrUpd; simp @@ -351,6 +371,14 @@ theorem JAtZV3.vreply3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) { · intro s1 J1 exact J1.runRJ hct (replyStateB_kheap_t _ _ _ _ _) (by rw [replyTcbB_state, hrs]) +theorem JAtZV3.vreply3 (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hcur : sched.cur_thread st s = ok ct) (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .running) (call : Bool) (y : U64) : + vcpu.reply st s call y ⦃ r => ∃ Lst' : U64 → List U64, JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r a + (stsAct (updK (if call then replyState σ ct.bv x [y.bv] else σ) ct.bv + (.tcb { (if call then replyTcbB x (Endp.ipcBufOf true x) [y.bv] else x) with + tcbState := .running })) ct.bv) ⦄ := WP.spec_mono (J.toF.vreply3 hcur hct hk hrs call y) fun _ ⟨Lst', J'⟩ => ⟨Lst', J.ofF J'⟩ + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3HiRun.lean b/proofs/Fl4Proofs/P3/JAtZV3HiRun.lean index e6cc20391..2b5c0119f 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3HiRun.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3HiRun.lean @@ -21,6 +21,12 @@ the spec's `setThreadState ct .restart` / `.running` (the `stsAct` form, P3/Ntfn current thread. No named premise. No existing statement changed. + +(mmuAD gen 42b66) `JAtZB.runJDB` moved to P3/XTopJointReply (statement unchanged, source 16M kept), where +`JAtZ.runJD` is now its corollary. + +(mmuAD gen 42b70) `JAtZB.restartRest` and `JAtZB.restartJB` moved upstream to P3/XTopJointRest (statements and +proofs unchanged), where `jowes_restartD` is now `JAtZB.restartRest`'s corollary (the verbatim copy removed). -/ import Fl4Proofs.P3.JAtZV3VFront open Aeneas Aeneas.Std Result @@ -65,206 +71,6 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se section open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched -set_option maxHeartbeats 16000000 in -/-- **`set_thread_state Running` of a `Restart` thread at `JAtZB`** (XTopJointReply's `JAtZ.runJD` over `JAtZB`, -verbatim as P3/JAtZV3RunVm's `JAtZB.runVmJD`; the post adds the `TFoot` footprint). -/ -theorem JAtZB.runJDB (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .restart) : - sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), - JAtZB (L := L) arI AR Z H Cs Ac Lst' D s6 a - (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ - SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ∧ - P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) ⦄ := by - have hP0 := J.ip - have hI := J.xtop.irelK J.ks J.buf - have hS := J.xtop.fin.1.1.1 - have hT : TcbPlaced Z.T := hP0.e.tcb - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb t ht - rw [hk] at hk0; cases hk0 - have hst : (L.mem s (tStA t)).val = tsCode x.tcbState := hTR.st - have hq := IpcRel.not_ep_queued hI.1 (t := t) ⟨by rw [hst, hrs]; decide, by rw [hst, hrs]; decide⟩ - have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) - (c := Z.c) hP0.e - have hSR := IpcRel.toSRN hI.1 hI.2 - have hr0 : L.mem s (P1.stA t) = sched.TS_RESTART := by - apply UScalar.eq_of_val_eq - rw [P1.stA_eq, ← tStA_eq, hst, hrs]; unfold sched.TS_RESTART; rfl - refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (set_thread_state_c hH hP0 hP0.e s σ hI.1.toE hSR ht - hk hq (by rw [hrs]; decide) .running (by decide) sched.TS_RUNNING (by unfold sched.TS_RUNNING; rfl)) - (set_thread_state_sfoot hS ht _)) (set_thread_state_yw hS ht _)) - (P1.sched.set_thread_state.running_blk (Es := P1.EH H) s t J.blk htH hr0)) ?_ - rintro s6 ⟨⟨⟨⟨hR6, hS6r⟩, hw6⟩, hy6⟩, hblk, hfoot⟩ - have hX6 := IpcRel.ofSRN hR6 hS6r - have hDbg := J.kw_dbg hfoot - have hKd := J.kw_dbgKeep hfoot - set x6 : Fl4Spec.Tcb := { x with tcbState := .running } with hx6 - set σ1 := updK σ t.bv (.tcb x6) with hσ1 - set σ6 := stsAct σ1 t.bv with hσ6 - have hrec : σ6 = { σ1 with schedulerAction := σ6.schedulerAction } := stsAct_rec σ1 t.bv - have hk1 : σ1.kheap t.bv = some (.tcb x6) := by simp [hσ1, updK] - have hk6 : σ6.kheap t.bv = some (.tcb x6) := by rw [hσ6, stsAct_kheap]; exact hk1 - have hkp : ∀ p, p ≠ t.bv → σ6.kheap p = σ.kheap p := by - intro p hp; rw [hσ6, stsAct_kheap, hσ1]; simp [updK, hp] - have hact6 : σ6.schedulerAction = .chooseNewThread ∨ σ6.schedulerAction = σ.schedulerAction := - stsAct_action σ1 t.bv - have e_ct : σ6.curThread = σ.curThread := by rw [hrec]; rfl - have e_csc : σ6.curSc = σ.curSc := by rw [hrec]; rfl - have e_cons : σ6.consumedTime = σ.consumedTime := by rw [hrec]; rfl - have e_tm : σ6.curTime = σ.curTime := by rw [hrec]; rfl - have e_idle : σ6.idleThread = σ.idleThread := by rw [hrec]; rfl - have e_isc : σ6.idleSc = σ.idleSc := by rw [hrec]; rfl - have e_rel : σ6.releaseQueue = σ.releaseQueue := by rw [hrec]; rfl - have hW : P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) := WritesIn.tfoot_sfoot (P1.WritesIn.refl _ _) hw6 - have hfx : IpcFree x.tcbState := by - rw [hrs]; exact ⟨rfl, rfl, fun _ e => by cases e⟩ - have hK : ScTKw (fun p => p = t.bv) σ σ6 := by - refine ⟨fun p => ?_, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, - by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, e_ct, e_isc⟩ - by_cases hp : p = t.bv - · subst hp; rw [hk, hk6] - show TKObj _ _ _ - exact Or.inr (Or.inl ⟨x, x6, rfl, rfl, rfl, Or.inr ⟨rfl, hfx, rfl, rfl, fun _ e => by cases e⟩⟩) - · rw [hkp p hp]; exact OTK.refl _ _ - have hX' : XTopAt (L := L) AR Z s6 a σ6 := xtop_sc_step J.xtop hP0 J.nk hW hK hX6.2.2.1 hX6.1.toN id - -- `Inv` - have hI1 : Inv σ1 := by - refine J.inv.step (NtfnStep.tcb hk .running x.tcbArch) (fun u x0 y h1 h2 _ hr => ?_) - (fun u x0 y h1 h2 hc => ?_) - · by_cases e : u = t.bv - · subst e; rw [hk] at h1; cases h1; simp [hσ1, updK] at h2; subst h2; rfl - · have h2' : σ.kheap u = some (.tcb y) := by simpa [hσ1, updK, e] using h2 - rw [h1] at h2'; cases h2'; exact hr - · by_cases e : u = t.bv - · subst e; exact J.inv.rd _ x hk (Or.inl (by rw [hrs]; rfl)) - · have h2' : σ.kheap u = some (.tcb y) := by simpa [hσ1, updK, e] using h2 - exact J.inv.rd u y h2' hc - have hInv : Inv σ6 := hI1.qchange (qchange_stsAct σ1 t.bv) - -- the yield words - have hY6 : YieldRel Z.T Z.C (L.mem s6) σ6 := by - have h1 := J.yld.frame (m' := L.mem s6) (σ' := σ1) - (fun y hy => hy6.mem_eq (yieldA_aligned hT hy) fun h => h ⟨y, hy, rfl⟩) - (YK.YKS.updTcb (y := x6) hk rfl).ykeep - exact h1.frame (m' := L.mem s6) (σ' := σ6) (fun _ _ => rfl) (YKeep.of_kheap (stsAct_kheap _ _)) - have hYK6 : YKeep σ σ6 := (YK.YKS.updTcb (y := x6) hk rfl).ykeep.trans (YKeep.of_kheap (stsAct_kheap _ _)) - have hsp : Fl4Spec.setThreadState (Z := Unit) t.bv .running σ = ({((), σ6)}, False) := - Notif.setThreadState_eq .running hk - have hsok : SOK (false, true) σ σ6 := Pres.of_eq (pres_setThreadState _ _ _) hsp - have hNSC : NSC Z.N Z.C σ6 := by - intro n hn y p hy hp - by_cases e : n.bv = t.bv - · rw [e, hk6] at hy; cases hy - · rw [hkp _ e] at hy; exact J.nsc n hn y p hy hp - obtain ⟨-, hY', hM', ⟨Lst', hCR', hRF'⟩, hRP', -⟩ := - ScAll.of_tr hS J.rp J.mcp J.call J.rfree ⟨hX6.2.2.1, hX6.1.toN, hNSC, hInv⟩ hY6 (hW.mono fun _ h => Or.inl h) - hsok rfl - -- the scheduler facts - have hsched : ∀ u, Fl4Spec.schedulable u σ = true → Fl4Spec.schedulable u σ6 = true := by - intro u hs - obtain ⟨y, scp, z, n, hky, hsc, hrun, hkz, hac, hnr⟩ := schedulable_inv hs - have hzt : scp ≠ t.bv := by rintro rfl; rw [hk] at hkz; cases hkz - have hkz6 : σ6.kheap scp = some (.schedContext z n) := by rw [hkp _ hzt]; exact hkz - have hnr6 : u ∉ σ6.releaseQueue := by rw [e_rel]; exact hnr - by_cases e : u = t.bv - · subst e; rw [hk] at hky; cases hky - exact schedulable_of hk6 hsc rfl hkz6 hac hnr6 - · exact schedulable_of (by rw [hkp _ e]; exact hky) hsc hrun hkz6 hac hnr6 - have hidt : σ.idleThread ≠ t.bv := by - intro e - obtain ⟨y, h1, -, h3, -⟩ := J.act.2 - rw [e, hk] at h1; cases h1; rw [hrs] at h3; cases h3 - have hAI : ActIdle σ6 := by - refine ⟨fun u hu => ?_, ?_⟩ - · have hu0 : σ.schedulerAction = .switchThread u := by - rcases hact6 with e | e - · rw [e] at hu; cases hu - · rw [← e]; exact hu - exact hsched u (J.act.1 u hu0) - · obtain ⟨y, h1, h2, h3, h4⟩ := J.act.2 - exact ⟨y, by rw [e_idle, hkp _ hidt]; exact h1, by rw [e_isc]; exact h2, h3, by rw [e_idle, e_rel]; exact h4⟩ - have hoff : OffOK σ6 := by - intro h0 y n hy ha - rw [e_cons] at h0 ⊢; rw [e_tm]; rw [e_csc] at hy; rw [e_csc, e_isc] at ha - by_cases e : σ.curSc = t.bv - · rw [e, hk6] at hy; cases hy - · rw [hkp _ e] at hy; exact J.off h0 y n hy ha - have hcur6 : σ6.schedulerAction = .chooseNewThread ∨ CurInv σ6 := by - rcases J.cur with e | hC - · left - rcases hact6 with e' | e' - · exact e' - · rw [e', e] - · right - obtain ⟨xt, hkc, hcs, hnb⟩ := hC.tcb - obtain ⟨y1, n1, hk1'⟩ := hC.sc - have hne : σ.curSc ≠ t.bv := by intro e; rw [e, hk] at hk1'; cases hk1' - refine ⟨?_, ⟨y1, n1, by rw [e_csc, hkp _ hne]; exact hk1'⟩, fun hne' y n hy => ?_, - fun hm => hC.notRel (by rw [e_ct, e_rel] at hm; exact hm)⟩ - · by_cases hct : σ.curThread = t.bv - · rw [hct, hk] at hkc; cases hkc - have hnb6 : NotIpcBlk Fl4Spec.ThreadState.running := by - refine ⟨?_, ?_, ?_⟩ - · intro _ e; cases e - · intro _ _ e; cases e - · intro _ _ _ e; cases e - exact ⟨x6, by rw [e_ct, hct]; exact hk6, by rw [e_csc]; exact hcs, hnb6⟩ - · exact ⟨xt, by rw [e_ct, hkp _ hct]; exact hkc, by rw [e_csc]; exact hcs, hnb⟩ - · rw [e_csc, e_isc] at hne'; rw [e_csc] at hy - rw [hkp _ hne] at hy - exact hC.active hne' y n hy - have hown6 : CurOwnW Z.T Z.C σ6 := by - have hsc6 : ∀ y n, σ6.kheap σ6.curSc = some (.schedContext y n) → σ.kheap σ.curSc = some (.schedContext y n) := by - intro y n hy - rw [e_csc] at hy - by_cases e : σ.curSc = t.bv - · rw [e, hk6] at hy; cases hy - · rw [hkp _ e] at hy; exact hy - rcases J.own with ⟨u, hu, xt, hkt, hxs, hown, hnr⟩ | ⟨hcs, hun⟩ - · left - by_cases hut : u.bv = t.bv - · rw [hut, hk] at hkt; cases hkt - exact ⟨u, hu, x6, by rw [hut]; exact hk6, by rw [e_csc]; exact hxs, fun y n hy => hown y n (hsc6 y n hy), - fun h0 hm => hnr (by rw [← e_cons]; exact h0) (by rw [e_rel] at hm; exact hm)⟩ - · exact ⟨u, hu, xt, by rw [hkp _ hut]; exact hkt, by rw [e_csc]; exact hxs, fun y n hy => hown y n (hsc6 y n hy), - fun h0 hm => hnr (by rw [← e_cons]; exact h0) (by rw [e_rel] at hm; exact hm)⟩ - · exact Or.inr ⟨by rw [e_csc]; exact hcs, fun y n hy => hun y n (hsc6 y n hy)⟩ - have hcr6 : CurRunM σ6 := by - by_cases hnr : σ6.schedulerAction ≠ .resumeCurThread - · exact Or.inl hnr - have hr' : σ6.schedulerAction = .resumeCurThread := not_not.1 hnr - have ha : σ6.schedulerAction = σ.schedulerAction := hact6.resolve_left (by rw [hr']; intro e; cases e) - have h0 : ¬ σ.schedulerAction ≠ .resumeCurThread := fun e => e (by rw [← ha]; exact hr') - right - rcases J.curRun.resolve_left h0 with h | h - · left - intro y hy - rw [e_ct] at hy - by_cases hct : σ.curThread = t.bv - · rw [hct, hk6] at hy; cases hy; rfl - · rw [hkp _ hct] at hy; exact h y hy - · right; rw [e_ct, e_idle]; exact h - have hlk : LK (fun _ => False) σ σ6 := fun p => Or.inr (by - by_cases hp : p = t.bv - · subst hp; rw [hk, hk6] - show LObj _ _ - refine ⟨?_, ?_, ?_⟩ - · intro y ey; cases ey; exact ⟨_, rfl, Or.inl rfl⟩ - · intro y n ey; cases ey - · intro y ey; cases ey - · rw [hkp p hp]; exact OL.refl _) - have hfk : FK σ σ6 := ⟨e_csc, e_idle, e_isc⟩ - have hdead : ∀ q ∈ D, DeadP (L := L) H s6 q := fun q hq => - J.deadP_sc_stepG hX' hW hK (fun p x' hp hk' h0 y hy => by - subst hp; rw [hk] at hk'; cases hk'; rw [hrs] at h0; simp [tsCode] at h0) - hlk hfk hAI.1 hY' (hYK6.dk q.bv) (fun h => h) (J.jcov.dead q hq) - exact ⟨Lst', J.sc_frame hW hK hX' hCR' hRF' hY' hM' (J.sc_buf hW hK) hRP' (J.sc_apart hW hK) - (J.sc_jpl hW hK (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).2) (J.sc_jcov hW hdead (fun q hq hn => absurd hq hn) (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2) hKd subset_rfl) (J.sc_kern hW hK hfk hX' hDbg fun _ h => h) - (J.sc_utc hW hK hDbg) hNSC hInv hcur6 hown6 hoff hAI (BlockedScActive.tkw J.bsa hK fun p y n hp ha => by - by_cases e : p = t.bv - · rw [e, hk6] at hp; cases hp - · rw [hkp _ e] at hp; exact ⟨y, hp, ha, fun _ h => h, id⟩) hcr6 hblk hKd (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).1 J.zD, - J.xtop.slotsSame_of hW (fun b hb => tfoot_oobj hS hb), P1.Foot.dbgKeep J.blk (fun _ h => h) hfoot, hW⟩ - /-- **`set_thread_state Running` of a `Restart` thread at `JAtZV3`** (module docstring). -/ theorem JAtZV3.runJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .restart) : @@ -500,13 +306,13 @@ theorem JAtZB.runRJDB (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 · rw [hkp _ e] at hp; exact ⟨y, hp, ha, fun _ h => h, id⟩) hcr6 hblk hKd (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).1 J.zD, J.xtop.slotsSame_of hW (fun b hb => tfoot_oobj hS hb), P1.Foot.dbgKeep J.blk (fun _ h => h) hfoot, hW⟩ -/-- **`set_thread_state Running` of a `Running` thread at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.runRJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +/-- **`set_thread_state Running` of a `Running` thread at `VmBaseF`** (module docstring). -/ +theorem VmBaseF.runRJ {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .running) : sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ Lst' : U64 → List U64, - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D s6 a + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s6 a (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := by - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 refine WP.spec_mono (B.runRJDB ht hk hrs) fun s6 h6 => ?_ obtain ⟨Lst', B', -, -, hW⟩ := h6 @@ -516,15 +322,10 @@ theorem JAtZV3.runRJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t have hkp7 : ∀ p, p ≠ t.bv → (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv).kheap p = σ.kheap p := by intro p hp; rw [stsAct_kheap]; simp [updK, hp] refine J.ofBS B' hW (fun b hb => tfoot_oobj hS hb) (fun b hb => B.tfoot_nh hb) (VKeep.of_tfoot hS B.thT hW) - (fun u hu => ?_) (fun o ko' ho => ?_) (fun o x' ho hx => ?_) (fun o vs ho => ?_) - · obtain ⟨vu, hvu⟩ := J.z2.zv.vm.spec u hu + (fun u hu => ?_) (fun o x' ho hx => ?_) (fun o vs ho => ?_) ?_ + · obtain ⟨vu, hvu⟩ := J.vm.spec u hu refine hkp7 _ fun e => ?_ rw [e, hk] at hvu; cases hvu - · by_cases e : o = t.bv - · subst e - rw [hk7] at ho; cases ho - exact ⟨_, hk, rfl⟩ - · rw [hkp7 _ e] at ho; exact ⟨ko', ho, rfl⟩ · by_cases e : o = t.bv · subst e rw [hk7] at ho; cases ho @@ -534,142 +335,19 @@ theorem JAtZV3.runRJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t · subst e rw [hk7] at ho; cases ho · rw [hkp7 _ e] at ho; exact ho + · intro o + by_cases e : o = t.bv + · subst o + exact Or.inr ⟨_, _, hk, hk7, Or.inl ⟨x, { x with tcbState := .running }, rfl, rfl⟩⟩ + · exact Or.inl (hkp7 o e) -set_option maxHeartbeats 8000000 in -/-- **P3/XTopJointRest's `jowes_restartD` over `JAtZB`** (statement and proof verbatim, `J : JAtZ` read as -`J : JAtZB`; every `J.` / `J.` it reads exists over `JAtZB`; the source's `maxHeartbeats 8000000`). -/ -theorem JAtZB.restartRest (s : S) (a : A) (σ : Fl4Spec.State Unit) - (ct : U64) (x : Fl4Spec.Tcb) (s1 : S) (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) - (htcb : Z.th ct = some .tcb) (hrun : Fl4Spec.runnable x.tcbState = true) - (hs1 : sched.set_thread_state st s ct sched.TS_RESTART = ok s1) - (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) - (hX1 : XTopAt (L := L) AR Z s1 a (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv)) : - ∃ Lst' : U64 → List U64, JRest (L := L) arI Z H Cs Ac Lst' D s1 - (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) := by - set σ1 := Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv with hσ1 - have hX := J.xtop - have hS := hX.fin.1.1.1 - have hT : ct ∈ Z.T := J.thT ct htcb - have he1 : Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ = ({((), σ1)}, False) := setThreadState_eq' hk _ - have hm1 : ((), σ1) ∈ (Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ).1 := by - rw [he1]; exact Set.mem_singleton _ - have hK : ScTKw (fun p => p = ct.bv) σ σ1 := - tk_setThreadState hk (ipcFree_of_runnable hrun) ipcFree_restart _ hm1 - have hwS : P1.WritesIn st s s1 (SFoot st Z.T Z.c s) := by - have h := set_thread_state_sfoot (L := L) hS hT sched.TS_RESTART - rw [hs1, WP.spec_ok] at h; exact h - have hwK : P1.WritesIn st s s1 (KFoot st Z.T Z.N Z.C Z.c s σ) := hwS.mono fun b hb => KFoot.of_sfoot hb - have hwT : P1.WritesIn st s s1 (TFoot st Z.T Z.N Z.C Z.c s σ) := WritesIn.tfoot_of_kfoot hwK - have hS1 := hX1.fin.1.1.1 - have hN1 := hX1.fin.1.1.2.2.1 - have hNsc : NSC Z.N Z.C σ1 := nsc_updTcb J.nsc _ _ - have hI1 : Inv σ1 := Inv.restart J.inv hk hrun - have hSOK : SOK (true, true) σ σ1 := pres_setThreadState (f := (true, true)) _ _ σ _ hm1 - obtain ⟨-, hY', hM', ⟨Lst', hCR', hRF'⟩, hRP', -⟩ := - ScAll.of_k hS J.rp J.yld J.mcp J.call J.rfree ⟨⟨hS1, hN1, hNsc, hI1⟩, hwK, hSOK⟩ - have hRR' : RRecv (L.mem s1) Z.R σ1 := - J.rrecv.frame (TFoot.keep hS J.rp hwT).2.2 (KhRB.of_sctkw hK) - have hF : FK σ σ1 := (fk_setThreadState _ _).of_eq he1 - have hBK : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s1 ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s1 := by - obtain ⟨x', hk', hRt⟩ := J.xtop.ipc.tcb ct hT - rw [hk] at hk'; cases hk' - have hnbr : ¬ P1.BlockedR (L.mem s (P1.stA ct)) := fun hb => by - have hq := Sched.blockedR_queued hRt.st hb - cases hx : x.tcbState <;> simp_all [Fl4Spec.runnable, Fl4Spec.ipcQueuedThreadState] - have hTe : Z.T = P1.Heap.tcbs H := by - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - exact Set.ext fun t => ⟨fun h => J.zH.1 t h, fun h => J.thT t ((hJ.tcb t).2 h)⟩ - rw [hTe] at hT - have hr := P1.sched.set_thread_state.restart_ok (Es := ∅) J.blk hT (fun h => hnbr (Or.inl h)) - (fun h => hnbr (Or.inr h)) hs1 - exact ⟨hr.1, P1.Foot.dbgKeep J.blk (Set.empty_subset _) hr.2.1⟩ - have hBlk' := hBK.1 - have hKd := hBK.2 - have hDbg : L.mem s1 (L.nodeAt s 0#u64 layout.node.DEBUG_TCBS) = - L.mem s (L.nodeAt s 0#u64 layout.node.DEBUG_TCBS) := by - have hP := hX.rel.1 - have hctW : ct = L.curW s := P1.eq_of_bv (hcur.symm.trans J.kern.cur) - have htf := hP.fits ct _ htcb - have hta := hP.align ct _ htcb - have hstv : (stA ct).val = ct.val + 3328 := by - rw [stA_eq, wordOf_val (by simp [objSize] at htf; simp; omega)]; simp - have h := set_thread_state_frame (L := L) s ct sched.TS_RESTART (by unfold P1.Aligned; rw [hstv]; omega) - J.kern.act.1 - rw [hs1, WP.spec_ok] at h - exact h _ J.kern.dwAl (fun e => J.kern.dwNe.1 (by rw [← hctW]; exact e)) J.kern.dwNe.2 - have hkc : σ.kheap σ.curThread = some (.tcb x) := by rw [hcur]; exact hk - have hcur' : σ1.schedulerAction = .chooseNewThread ∨ CurInv σ1 := by - rcases J.cur with h | h - · left - show (Notif.stsAct _ ct.bv).schedulerAction = _ - unfold Notif.stsAct; split_ifs with hc - · rfl - · exact h - · right - have := CurInv.restart h hkc - rw [hcur] at this; exact this - have hB' : BlockedScActive σ1 := J.bsa.bk (bk_restart hk hrun hm1) hSOK - have hCR'' : CurRun σ1 := by - intro y hy - rw [show σ1.curThread = σ.curThread from (stsAct_fields _ _).2.1, hcur, stsAct_kheap, updK_kheap, - Function.update_self] at hy - cases hy; rfl - have hAI : ActIdle σ1 := (ActIdle.updState J.act hk hrun .restart rfl).ofSts ct.bv - have hL : LK (fun _ => False) σ σ1 := (lkm_setThreadState (W := fun _ => False) _ _).of_eq he1 - have hDead : ∀ q ∈ D, DeadP (L := L) H s1 q := fun q hq => - J.deadP_sc_step hX1 hwT hK (fun p y e hy => by subst e; rw [hk] at hy; cases hy; exact hrun) hL hF hAI.1 - hY' ((hSOK.ykeep rfl).dk q.bv) (fun h => h) (J.jcov.dead q hq) - refine ⟨Lst', ⟨hCR', hRF', hRR', hY', hM', J.sc_buf hwT hK, hRP', J.sc_apart hwT hK, J.sc_jpl hwT hK (J.idleW_keep hX1.fin.1.1.1 hF.2.1 hF.2.2).2, - J.sc_jcov hwT hDead (fun q hq hn => absurd hq hn) (J.idleW_keep hX1.fin.1.1.1 hF.2.1 hF.2.2) hKd subset_rfl, J.sc_kern hwT hK hF hX1 hDbg (fun _ h => h), - J.sc_utc hwT hK hDbg, hNsc, hI1, hcur', curOwnW_updTcb J.own hk _, OffOK.restart J.off _, hAI, hB', - J.isorted.tkw hK, Or.inr (Or.inl hCR''), hBlk'⟩⟩ - -set_option maxHeartbeats 4000000 in -/-- **The caller's restart at `JAtZB`** (P3/XTopJointStep's `JAtZ.restartSJ` over `JAtZB`: `jStepHyps`'s `restart` -field is `jowes_restartD`, here `JAtZB.restartRest`; `JAtZB.cs_frame` (no `VKeep` argument), `JCs.sameB`; the post -adds the `TFoot` footprint, as `jowes_restartD` derives it; source setting `maxHeartbeats 4000000`). -/ -theorem JAtZB.restartJB (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) - {ct : U64} {x : Fl4Spec.Tcb} {s1 : S} (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) - (htcb : Z.th ct = some .tcb) (hrun : Fl4Spec.runnable x.tcbState = true) - (hs1 : sched.set_thread_state st s ct sched.TS_RESTART = ok s1) : - ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s1 a - (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) ∧ - P1.WritesIn st s s1 (TFoot st Z.T Z.N Z.C Z.c s σ) := by - have h := XTopAt.restart J.xtop hcur hk hrun - rw [hs1, WP.spec_ok] at h - obtain ⟨hX1, hSS, hk1⟩ := h - obtain ⟨hkb, hkz⟩ := kback_ksz_upd (σ' := Notif.stsAct (Notif.updK σ ct.bv - (.tcb { x with tcbState := .restart })) ct.bv) hk (by rw [stsAct_kheap]; rfl) - obtain ⟨Lst', R⟩ := J.restartRest s a σ ct x s1 hcur hk htcb hrun hs1 hX1 - have hT : ct ∈ Z.T := J.thT ct htcb - have hK : P1.DbgKeep st (P1.Heap.tcbs H) Cs s s1 := by - obtain ⟨x', hk', hRt⟩ := J.xtop.ipc.tcb ct hT - rw [hk] at hk'; cases hk' - have hnbr : ¬ P1.BlockedR (L.mem s (P1.stA ct)) := fun hb => by - have hq := Sched.blockedR_queued hRt.st hb - cases hx : x.tcbState <;> simp_all [Fl4Spec.runnable, Fl4Spec.ipcQueuedThreadState] - have hT' : ct ∈ P1.Heap.tcbs H := by rw [← J.tcbs_eq.1]; exact hT - exact P1.Foot.dbgKeep J.blk (Set.empty_subset _) - (P1.sched.set_thread_state.restart_ok (Es := ∅) J.blk hT' (fun h => hnbr (Or.inl h)) - (fun h => hnbr (Or.inr h)) hs1).2.1 - have hid : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv).idleThread = - σ.idleThread := by unfold Notif.stsAct; split <;> rfl - have hwT : P1.WritesIn st s s1 (TFoot st Z.T Z.N Z.C Z.c s σ) := by - have h := set_thread_state_sfoot (L := L) J.xtop.fin.1.1.1 hT sched.TS_RESTART - rw [hs1, WP.spec_ok] at h - exact WritesIn.tfoot_of_kfoot (h.mono fun b hb => KFoot.of_sfoot hb) - refine ⟨Lst', ?_, hwT⟩ - exact J.cs_frame (G' := Z.G) (hvn := J.vsSS (G' := Z.G) hX1 hk1 hSS - (Vs.ArchShr.of_keep (Vs.sts_keep hk { x with tcbState := .restart }).1 (Vs.sts_keep hk _).2)) hk1 hX1 hkb - ((IpcFrKeep.of_updTcb (y := { x with tcbState := .restart }) hk rfl rfl).trans - (IpcFrKeep.of_kheap (by rw [stsAct_kheap]))) (J.carry.frame subset_rfl ((IpcFrKeep.of_updTcb (y := { x with tcbState := .restart }) hk rfl rfl).trans - (IpcFrKeep.of_kheap (by rw [stsAct_kheap]))) hkz) - (devFrom_same J.xtop.rel.2.1.2.2.1 hX1.rel.2.1.2.2.1 hSS) (JCs.sameB J hSS hkz) R (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) - (J.liveX hX1 rfl rfl rfl hSS hK - (orig_eq_of_slots J.xtop.rel.2.1.2.2.2.1 hX1.rel.2.1.2.2.2.1 J.kern.orig R.kern.orig hSS) - (XTopAt.idleW_eqS J.xtop hX1 hid) fun p hp => R.jcov.dead p (J.zD p hp)) - (J.zDX hSS J.zD) +/-- **`set_thread_state Running` of a `Running` thread at `JAtZV3`** (module docstring). -/ +theorem JAtZV3.runRJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .running) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ Lst' : U64 → List U64, + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D s6 a + (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := + WP.spec_mono (J.toF.runRJ ht hk hrs) fun _ ⟨Lst', J'⟩ => ⟨Lst', J.ofF J'⟩ /-- **The caller's restart at `JAtZV3`** (module docstring). -/ theorem JAtZV3.restartJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) diff --git a/proofs/Fl4Proofs/P3/JAtZV3HiTop.lean b/proofs/Fl4Proofs/P3/JAtZV3HiTop.lean index f544effe1..9a3d00c6d 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3HiTop.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3HiTop.lean @@ -5,7 +5,8 @@ spec's `fl4HandleInvocationVF onCore remoteCur true` (Ext/VirtKernelF; `reportEr `KERNEL_INVOCATION_REPORT_ERROR_IPC`, set). * The spec's phases with the extended decoder and dispatcher: `hiMEV`, `hiMFinVF` (HandleTop's `hiME` / `hiMFin` - with `fl4DecodeInvocationV` / `fl4PerformInvocationVF`), `hi_memVF`, `hiMEV_run`, `hiMFinVF_ok`. + with `fl4DecodeInvocationV` / `fl4PerformInvocationVF`), `hi_memVF`, `hiMEV_run`, `hiMFinVF_ok` (mmuAD 42b66: + instances of HandleTopG's `hiMEG`, `hiMFinG`, `hi_memG`, `hiMEG_run`, `hiMFinG_ok`; statements unchanged). * `zv_liftE_inv`: a single outcome of `liftE m` is one of `m`. * `JAtZV3.bufFrames`: the caller's receive-buffer words are aligned user-frame words (as `JAtZ.replyErrJ`'s `hfr`). * **`ZvPost`**: `JAtZV3` at some ghosts (`V`, `X` fixed). **`ZvFaultHyp` [W]**: FL4's `handle_fault ct f` at the @@ -51,24 +52,12 @@ open Fl4Spec /-- The decode phase with the extended decoder. -/ def hiMEV (thread : ObjRef) (info : MessageInfo) (cptr : CapRef) (firstPhase : Bool) : CslotPtr × Cap × List (Cap × CslotPtr) × Option ObjRef → SEMonad Unit Fl4InvocationV := - fun (slot, cap, extracaps, buffer) => do - let args ← NonDetE.liftE <| getMrs thread buffer info - fl4DecodeInvocationV firstPhase info.miLabel args cptr slot cap extracaps buffer + hiMEG fl4DecodeInvocationV thread info cptr firstPhase /-- The invocation phase with the extended dispatcher. -/ def hiMFinVF (onCore remoteCur : ObjRef → Bool) (thread : ObjRef) (calling blocking canDonate : Bool) : Fl4InvocationV → PMonad Unit Unit := - fun oper => do - withoutPreemption <| setThreadState thread .restart - let reply ← fl4PerformInvocationVF onCore remoteCur blocking calling canDonate oper - withoutPreemption <| do - let state ← getThreadState thread - match state with - | .restart => do - NonDet.when calling <| - replyFromKernel thread (0, reply) - setThreadState thread .running - | _ => return () + hiMFinG (fl4PerformInvocationVF onCore remoteCur) thread calling blocking canDonate theorem hi_memVF {σ : State Unit} (onCore remoteCur : ObjRef → Bool) (rep : Bool) {calling blocking canDonate firstPhase : Bool} {cptr : CapRef} {mi : MessageInfo} {t : ObjRef} @@ -79,19 +68,15 @@ theorem hi_memVF {σ : State Unit} (onCore remoteCur : ObjRef → Bool) (rep : B (fun err => NonDet.when calling <| fl4ReplyFromKernelError rep t <| msgFromSyscallError err) (hiMFinVF onCore remoteCur t calling blocking canDonate)).run σ).1) : y ∈ ((fl4HandleInvocationVF (Z := Unit) onCore remoteCur rep calling blocking canDonate firstPhase cptr).run σ).1 := by - unfold fl4HandleInvocationVF - refine mem_bindE_ok (a := σ.curThread) (s' := σ) (mem_liftE (x := (σ.curThread, σ)) rfl) ?_ - refine mem_bindE_ok (a := mi) (s' := σ) (mem_liftE (x := (mi, σ)) (by rw [hcur, hmi]; rfl)) ?_ - rw [hcur] - exact h + rw [fl4HandleInvocationVF_hiG] + exact hi_memG fl4DecodeInvocationV (fl4PerformInvocationVF onCore remoteCur) rep hcur hmi h theorem hiMEV_run {σ : State Unit} {t : ObjRef} {mi : MessageInfo} {cptr : CapRef} {fp : Bool} {a : Cap} {sl : CslotPtr} {buffer : Option ObjRef} {exs : List (Cap × CslotPtr)} {args : List Data} (hm : getMrs (Z := Unit) t buffer mi σ = ({(args, σ)}, False)) : ExceptT.run (hiMEV t mi cptr fp (sl, a, exs, buffer)) σ = - (fl4DecodeInvocationV (Z := Unit) fp mi.miLabel args cptr sl a exs buffer).run σ := by - unfold hiMEV - exact run_bind_ok (run_liftE hm) _ + (fl4DecodeInvocationV (Z := Unit) fp mi.miLabel args cptr sl a exs buffer).run σ := + hiMEG_run (dec := fl4DecodeInvocationV) hm theorem hiMFinVF_ok {σ σ1 σy : State Unit} (onCore remoteCur : ObjRef → Bool) {t : ObjRef} {calling blocking canDonate : Bool} {inv : Fl4InvocationV} {rr : List Data} {z : Unit × State Unit} @@ -99,11 +84,8 @@ theorem hiMFinVF_ok {σ σ1 σy : State Unit} (onCore remoteCur : ObjRef → Boo (hy : (.ok rr, σy) ∈ ((fl4PerformInvocationVF (Z := Unit) onCore remoteCur blocking calling canDonate inv).run σ1).1) (hz : z ∈ (specTail calling t rr σy).1) : ((.ok z.1, z.2) : Except Unit Unit × State Unit) ∈ - ((hiMFinVF onCore remoteCur t calling blocking canDonate inv).run σ).1 := by - unfold hiMFinVF withoutPreemption - refine mem_bindE_ok (a := ()) (s' := σ1) (mem_liftE (x := ((), σ1)) (by rw [hst]; rfl)) ?_ - refine mem_bindE_ok (a := rr) (s' := σy) hy ?_ - exact mem_liftE hz + ((hiMFinVF onCore remoteCur t calling blocking canDonate inv).run σ).1 := + hiMFinG_ok (perf := fl4PerformInvocationVF onCore remoteCur) hst hy hz set_option maxHeartbeats 4000000 in /-- An outcome `.ok (.enableIoPort …)` of the decoder writes the first extra cap's slot (decision Q2's owner write). -/ @@ -201,18 +183,23 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} /-- The caller's receive-buffer words are aligned user-frame words (module docstring). -/ -theorem JAtZV3.bufFrames (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) +theorem JAtZB.bufFrames (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) : ∀ p, Endp.ipcBufOf true x = some p → ∀ k, k < 128 → (Endp.bufAddr p k).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (Endp.bufAddr p k) σ := by - have B := J.z2.zv.base intro p hp k hk128 obtain ⟨w, hw, -⟩ := P1.spec_ex_fd (P0.msg.lookup_ipc_buffer.p0 st s true ct (P1.LawfulStore.total (st := st))) have hb := J.replyBuf hct hk rw [hw, WP.spec_ok] at hb have hb' : JBufR Z.B w (Endp.ipcBufOf true x) := hb rw [hp] at hb' - exact ⟨Endp.bufAddr_aligned B.xtop.fin.1.2.ep hb'.2.1 k, buf_frame_of_ok B.bok hk hp k hk128⟩ + exact ⟨Endp.bufAddr_aligned J.xtop.fin.1.2.ep hb'.2.1 k, buf_frame_of_ok J.bok hk hp k hk128⟩ + +theorem JAtZV3.bufFrames (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) : + ∀ p, Endp.ipcBufOf true x = some p → ∀ k, k < 128 → + (Endp.bufAddr p k).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (Endp.bufAddr p k) σ := + J.z2.zv.base.bufFrames hct hk end diff --git a/proofs/Fl4Proofs/P3/JAtZV3Msr.lean b/proofs/Fl4Proofs/P3/JAtZV3Msr.lean index eb0d41593..b7701f613 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3Msr.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3Msr.lean @@ -49,9 +49,9 @@ theorem v3_vmemW_al {p : U64} (hv : VFits p) {off : Fl4Spec.Word} (h1 : off.toNa omega /-- The MSR place `p + msrOff amd m` of a VCPU of `V` is aligned. -/ -theorem v3_msr_al (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) {amd : Bool} +theorem VmBase.msr_al (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) {amd : Bool} {m o : Fl4Spec.Word} (ho : VirtMsrEq.msrOff amd m = some o) {x : U64} (hx : x.bv = p.bv + o) : P1.Aligned x := by - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ obtain ⟨-, h1, h2, -, -⟩ := VirtMsrStore.msrOff_cases ho have e : x = ⟨p.bv + o⟩ := by rcases x with ⟨b⟩; exact congrArg (fun b => (⟨b⟩ : U64)) hx @@ -60,20 +60,24 @@ theorem v3_msr_al (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U have := hv.1 omega +theorem v3_msr_al (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) {amd : Bool} + {m o : Fl4Spec.Word} (ho : VirtMsrEq.msrOff amd m = some o) {x : U64} (hx : x.bv = p.bv + o) : P1.Aligned x := + J.toB.msr_al hp ho hx + set_option maxHeartbeats 4000000 in /-- **FL4's store at an MSR's place, paired with the spec's MSR update** (module docstring). -/ -theorem JAtZV3.msrWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBaseF.msrWr {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) {m o : Fl4Spec.Word} (ho : VirtMsrEq.msrOff (decide (Fl4Spec.virtKind = .svm)) m = some o) {x : U64} (hx : x.bv = p.bv + o) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.msr m) val.bv)))) := by - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ obtain ⟨-, h1, h2, h3, h4⟩ := VirtMsrStore.msrOff_cases ho have hxv : x.val = p.val + o.toNat := by have e : x = ⟨p.bv + o⟩ := by rcases x with ⟨b⟩; exact congrArg (fun b => (⟨b⟩ : U64)) hx rw [e, VirtInitWalk.vo_val hv h1] - have hal : P1.Aligned x := v3_msr_al J hp ho hx + have hal : P1.Aligned x := J.toVmBase.msr_al hp ho hx have hoN : o.toNat ≠ 20480 ∧ o.toNat ≠ 20488 ∧ o.toNat ≠ 20496 := by rcases Bool.eq_false_or_eq_true (decide (Fl4Spec.virtKind = .svm)) with hb | hb · have := h4 hb; omega @@ -99,6 +103,13 @@ theorem JAtZV3.msrWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p exact J.vcpuStep hp hal (by rw [hxv]; omega) (by rw [hxv]; omega) ⟨by rw [hxv]; omega, by rw [hxv]; omega, by rw [hxv]; omega⟩ val hk _ rfl hR +theorem JAtZV3.msrWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + {m o : Fl4Spec.Word} (ho : VirtMsrEq.msrOff (decide (Fl4Spec.virtKind = .svm)) m = some o) {x : U64} + (hx : x.bv = p.bv + o) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.msr m) val.bv)))) := + J.ofF (J.toF.msrWr hp ho hx val hk) + end /-! ## The spec side -/ @@ -142,7 +153,7 @@ theorem zv_wmsr_bv : fl4_abi.label.X86VCPUWriteMSR.bv = (50 : Fl4Spec.Data) := b set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteMSR at `JAtZV3`, paired with the spec's decode and perform** (module docstring). -/ -theorem JAtZV3.writeMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) +theorem VmBaseF.writeMsrJ {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) @@ -155,16 +166,16 @@ theorem JAtZV3.writeMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteMSR.bv args p.bv ec = Fl4Spec.NonDetE.throwError e' ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + r.2.1 = s ∧ VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s r.2.2 σ) ∨ (∃ (s3 : S) (σ' : Fl4Spec.State Unit), r.1 = .Ok () ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteMSR.bv args p.bv ec = Fl4Spec.NonDetE.returnOk (.writeMsr p.bv f.bv x.bv) ∧ Fl4Spec.performVcpuInvocation (Z := Unit) (.writeMsr p.bv f.bv x.bv) σ = ({([x.bv], σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call x = ok r.2.1) ⦄ := by - have B := J.z2.zv.base + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call x = ok r.2.1) ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) have g2 : ¬ len < 2#u64 := by scalar_tac rw [VirtMsrDec.decode_wrmsr_eq (st := st) hAT s a len p call buf ex g2] refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ @@ -206,7 +217,7 @@ theorem JAtZV3.writeMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) cases u obtain ⟨o, ho, hox⟩ := Option.map_eq_some_iff.1 (haddr w rfl) rw [hamd] at ho - have hwal : P1.Aligned w := v3_msr_al J hp ho hox.symm + have hwal : P1.Aligned w := J.toVmBase.msr_al hp ho hox.symm have J2 := J1.msrWr hp ho hox.symm x hk dsimp only rw [L.write_eq, bind_ok, L.read_eq, bind_ok, L.mem_wr _ _ _ _ hwal hwal, if_pos rfl] @@ -225,6 +236,32 @@ theorem JAtZV3.writeMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) exact Or.inl ⟨e, e', rfl, hrel, by rw [hD args ec hl h0 h1, hcm], rfl, J1⟩ · rw [hcm] at hrel; exact hrel.elim +theorem JAtZV3.writeMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) + (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteMSR len p call buf ex ⦃ r => ∃ ct f x : U64, + sched.cur_thread st s = ok ct ∧ msg.syscall_arg st s ct buf 0#u64 = ok f ∧ + msg.syscall_arg st s ct buf 1#u64 = ok x ∧ + ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), args.length = len.val → + args.getD 0 0 = f.bv → args.getD 1 0 = x.bv → + (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ + Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteMSR.bv args p.bv ec = + Fl4Spec.NonDetE.throwError e' ∧ + r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + (∃ (s3 : S) (σ' : Fl4Spec.State Unit), r.1 = .Ok () ∧ + Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteMSR.bv args p.bv ec = + Fl4Spec.NonDetE.returnOk (.writeMsr p.bv f.bv x.bv) ∧ + Fl4Spec.performVcpuInvocation (Z := Unit) (.writeMsr p.bv f.bv x.bv) σ = ({([x.bv], σ')}, False) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call x = ok r.2.1) ⦄ := by + refine WP.spec_mono (J.toF.writeMsrJ hAT hK hVA hCap hp hk hlen call buf ex) ?_ + rintro r ⟨ct, f, x, hct, hf, hx, ht⟩ + refine ⟨ct, f, x, hct, hf, hx, fun args ec hl h0 h1 => ?_⟩ + rcases ht args ec hl h0 h1 with ⟨e, e', he, hr, hd, hs, J'⟩ | ⟨s', σ', he, hd, hp, J', hr⟩ + · exact Or.inl ⟨e, e', he, hr, hd, hs, J.ofF J'⟩ + · exact Or.inr ⟨s', σ', he, hd, hp, J.ofF J', hr⟩ + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3Pend.lean b/proofs/Fl4Proofs/P3/JAtZV3Pend.lean index 187bdfcb5..eeec5a9f4 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3Pend.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3Pend.lean @@ -8,6 +8,7 @@ VcpuState.reported` (Ext/VirtReport; `reported` clears `exit.pending`, Ext/VirtS * **`JAtZV3.pendClr`**: FL4's write of 0 at `p + PENDING` (`p ∈ V`) paired with the spec's `updK p (vcpu vs.reported)` keeps `JAtZV3` (via gen 30's `JAtZV3.vcpuStep`). +VM entry also clears `VALID`. Both flags use the same frame proof. No named premise. No existing statement changed. (mmuAD gen 42b42, the Architect's ruling (B)) Every `JAtZV3.*` lemma here is stated over `VmBaseF` (P3/JAtZV3: the shared record `VmBase` with the run footprint) as `VmBaseF.*`, with the proof; the `JAtZV3.*` statement is unchanged and its corollary (`JAtZV3.toF` / `ofF`). @@ -25,42 +26,79 @@ open Fl4Spec theorem v3_ne_pend {o : Word} (h : o.toNat ≠ 20520) : o ≠ VcpuLay.PENDING := fun e => h (by rw [e]; rfl) -/-- **The relation across a change of the `PENDING` word only, to 0** (module docstring). -/ -theorem v3_pendR {k : VirtKind} {mem mem' : Word → Word} {v : Word} {vs : VcpuState} - (hm : ∀ o, o < VcpuLay.SIZE → o ≠ VcpuLay.PENDING → mem' (v + o) = mem (v + o)) - (h0 : mem' (v + VcpuLay.PENDING) = 0) (h : VcpuRel k mem v vs) : - VcpuRel k mem' v vs.reported := by +/-- Changes to either exit flag preserve the rest of the VCPU image. -/ +private theorem v3_exitFlagsR {k : VirtKind} {mem mem' : Word → Word} {v : Word} {vs : VcpuState} + {valid pending : Bool} + (hm : ∀ o, o < VcpuLay.SIZE → o ≠ VcpuLay.PENDING → o ≠ VcpuLay.VALID → + mem' (v + o) = mem (v + o)) + (hV : valid = decide (mem' (v + VcpuLay.VALID) ≠ 0)) + (hP : pending = decide (mem' (v + VcpuLay.PENDING) ≠ 0)) + (h : VcpuRel k mem v vs) : + VcpuRel k mem' v { vs with exit := { vs.exit with valid := valid, pending := pending } } := by + let vs' : VcpuState := { vs with exit := { vs.exit with valid := valid, pending := pending } } + change VcpuRel k mem' v vs' + have neqV {o : Word} (hn : o.toNat ≠ 20528) : o ≠ VcpuLay.VALID := fun e => hn (by rw [e]; rfl) obtain ⟨f0, f1, f2, f3, f4, f6⟩ := v3_fix_vals - have hc : VcpuRelCommon mem v vs → VcpuRelCommon mem' v vs.reported := fun h => { - tcb := by rw [hm _ VirtVcpuRel.tcb_lt (v3_ne_pend (by omega))]; exact h.tcb - valid := by rw [hm _ VirtVcpuRel.valid_lt (v3_ne_pend (by omega))]; exact h.valid - pending := by rw [h0]; simp [VcpuState.reported] + have hc : VcpuRelCommon mem v vs → VcpuRelCommon mem' v vs' := fun h => { + tcb := by rw [hm _ VirtVcpuRel.tcb_lt (v3_ne_pend (by omega)) (neqV (by omega))]; exact h.tcb + valid := hV + pending := hP mrs := fun j => by - rw [hm _ (VirtVcpuRel.exitOff_lt j) (v3_ne_pend (by have := v3_exit_ge j; omega))]; exact h.mrs j + rw [hm _ (VirtVcpuRel.exitOff_lt j) (v3_ne_pend (by have := v3_exit_ge j; omega)) (neqV (by have := v3_exit_ge j; omega))]; exact h.mrs j gpr := fun j => by - rw [hm _ (VirtVcpuRel.gprOff_lt j) (v3_ne_pend (by have := v3_gpr_ge j; omega))]; exact h.gpr j - xcr0 := by rw [hm _ VirtVcpuRel.xcr0_lt (v3_ne_pend (by omega))]; exact h.xcr0 - ibpb := by rw [hm _ VirtVcpuRel.ibpb_lt (v3_ne_pend (by omega))]; exact h.ibpb } + rw [hm _ (VirtVcpuRel.gprOff_lt j) (v3_ne_pend (by have := v3_gpr_ge j; omega)) (neqV (by have := v3_gpr_ge j; omega))]; exact h.gpr j + xcr0 := by rw [hm _ VirtVcpuRel.xcr0_lt (v3_ne_pend (by omega)) (neqV (by omega))]; exact h.xcr0 + ibpb := by rw [hm _ VirtVcpuRel.ibpb_lt (v3_ne_pend (by omega)) (neqV (by omega))]; exact h.ibpb } cases k with | vmx => have h : VcpuRelVmx mem v vs := h - exact show VcpuRelVmx mem' v vs.reported from { hc h.toVcpuRelCommon with + exact show VcpuRelVmx mem' v vs' from { hc h.toVcpuRelCommon with vmcs := fun f hf => by - rw [hm _ (VirtVcpuRel.vmcsOff_lt hf) (v3_ne_pend (by have := v3_vmcs_lt f; omega))]; exact h.vmcs f hf + rw [hm _ (VirtVcpuRel.vmcsOff_lt hf) (v3_ne_pend (by have := v3_vmcs_lt f; omega)) (neqV (by have := v3_vmcs_lt f; omega))]; exact h.vmcs f hf msr := fun m j hj => by - rw [hm _ (VirtVcpuRel.msrOff_lt hj) (v3_ne_pend (by have := v3_msr_ge hj; omega))]; exact h.msr m j hj - cr2 := by rw [hm _ VirtVcpuRel.cr2_lt (v3_ne_pend (by omega))]; exact h.cr2 + rw [hm _ (VirtVcpuRel.msrOff_lt hj) (v3_ne_pend (by have := v3_msr_ge hj; omega)) (neqV (by have := v3_msr_ge hj; omega))]; exact h.msr m j hj + cr2 := by rw [hm _ VirtVcpuRel.cr2_lt (v3_ne_pend (by omega)) (neqV (by omega))]; exact h.cr2 io := fun p => by - rw [hm _ (VirtVcpuRel.ioOff_lt p) (v3_ne_pend (by have := v3_io_ge p; omega))]; exact h.io p } + rw [hm _ (VirtVcpuRel.ioOff_lt p) (v3_ne_pend (by have := v3_io_ge p; omega)) (neqV (by have := v3_io_ge p; omega))]; exact h.io p } | svm => have h : VcpuRelSvm mem v vs := h - exact show VcpuRelSvm mem' v vs.reported from { hc h.toVcpuRelCommon with + exact show VcpuRelSvm mem' v vs' from { hc h.toVcpuRelCommon with vmcb := fun off hr hh hx => by - rw [hm _ (VirtVcpuRel.svmOff_lt hr) (v3_ne_pend (by have := v3_vmcb_lt hr; omega))] + rw [hm _ (VirtVcpuRel.svmOff_lt hr) (v3_ne_pend (by have := v3_vmcb_lt hr; omega)) (neqV (by have := v3_vmcb_lt hr; omega))] exact h.vmcb off hr hh hx } | none => exact h.elim | armEl2 => exact h.elim +/-- Clear the pending-exit flag and keep the remaining VCPU fields. -/ +theorem v3_pendR {k : VirtKind} {mem mem' : Word → Word} {v : Word} {vs : VcpuState} + (hm : ∀ o, o < VcpuLay.SIZE → o ≠ VcpuLay.PENDING → mem' (v + o) = mem (v + o)) + (h0 : mem' (v + VcpuLay.PENDING) = 0) (h : VcpuRel k mem v vs) : + VcpuRel k mem' v vs.reported := by + have hc : VcpuRelCommon mem v vs := by + cases k + · exact h.elim + · exact (show VcpuRelVmx mem v vs from h).toVcpuRelCommon + · exact (show VcpuRelSvm mem v vs from h).toVcpuRelCommon + · exact h.elim + have hV := hc.valid + rw [← hm _ VirtVcpuRel.valid_lt (v3_ne_pend (by decide))] at hV + exact v3_exitFlagsR (fun _ ho hp _ => hm _ ho hp) hV (by rw [h0]; rfl) h + +/-- Clear the valid-exit flag and keep the remaining VCPU fields. -/ +theorem v3_validR {k : VirtKind} {mem mem' : Word → Word} {v : Word} {vs : VcpuState} + (hm : ∀ o, o < VcpuLay.SIZE → o ≠ VcpuLay.VALID → mem' (v + o) = mem (v + o)) + (h0 : mem' (v + VcpuLay.VALID) = 0) (h : VcpuRel k mem v vs) : + VcpuRel k mem' v { vs with exit := { vs.exit with valid := false } } := by + have hc : VcpuRelCommon mem v vs := by + cases k + · exact h.elim + · exact (show VcpuRelVmx mem v vs from h).toVcpuRelCommon + · exact (show VcpuRelSvm mem v vs from h).toVcpuRelCommon + · exact h.elim + have hP := hc.pending + rw [← hm _ VirtVcpuRel.pending_lt (by decide)] at hP + exact v3_exitFlagsR (fun _ ho _ hv => hm _ ho hv) (by rw [h0]; rfl) hP h + end section @@ -70,34 +108,56 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} {sA : S} {σA : Fl4Spec.State Unit} -/-- **FL4's `PENDING := 0` paired with the spec's `VcpuState.reported`** (module docstring). -/ +private theorem VmBaseF.clearExitWord + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p w : U64} + (hp : p ∈ V) {o : Fl4Spec.Word} (hoff : o.toNat = 20520 ∨ o.toNat = 20528) + (hwp : w.val = p.val + o.toNat) + {vs vs' : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) + (ht : vs'.tcb = vs.tcb) + (hClear : ∀ {m m' : Fl4Spec.Word → Fl4Spec.Word}, + (∀ o', o' < Fl4Spec.VcpuLay.SIZE → o' ≠ o → m' (p.bv + o') = m (p.bv + o')) → + m' (p.bv + o) = 0 → Fl4Spec.VcpuRel Fl4Spec.virtKind m p.bv vs → + Fl4Spec.VcpuRel Fl4Spec.virtKind m' p.bv vs') : + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s w 0#u64) a + (Notif.updK σ p.bv (.archObj (.vcpu vs'))) := by + obtain ⟨hAlignment, hFit⟩ := (J.base.jvLay J.vm).vfit p hp + have hNat : o.toNat < 32768 := by omega + have hl : o < Fl4Spec.VcpuLay.SIZE := by + rw [BitVec.lt_def] + exact hNat + have hal : P1.Aligned w := by unfold P1.Aligned; omega + have hw := P1.writesIn_wr (st := st) (s := s) (v := 0#u64) hal + have eAdd := v3_toNat_add hFit hl + have h0 : vmemW (L.mem (L.wr s w 0#u64)) (p.bv + o) = 0 := by + have hAlign : (p.bv + o).toNat % 8 = 0 := by rw [eAdd]; omega + unfold vmemW + rw [if_pos hAlign] + have hAddr : (⟨p.bv + o⟩ : U64) = w := UScalar.eq_of_val_eq (eAdd.trans hwp.symm) + rw [hAddr, L.mem_wr s w 0#u64 w hal hal, if_pos rfl] + rfl + have hAgree := v3_agree (o0 := o) hFit + (m := L.mem s) (m' := L.mem (L.wr s w 0#u64)) + (fun b hb _ _ hne => hw.mem_eq hb (fun e => hne (by rw [e, hwp]))) + exact J.vcpuStep hp hal (by omega) (by omega) ⟨by omega, by omega, by omega⟩ 0#u64 hk vs' ht + (hClear hAgree h0 (J.vr p hp vs hk)) + +/-- The report clears a pending exit. -/ theorem VmBaseF.pendClr (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p w : U64} (hp : p ∈ V) (hwp : w.val = p.val + 20520) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s w 0#u64) a - (Notif.updK σ p.bv (.archObj (.vcpu vs.reported))) := by - have Ly := J.base.jvLay J.vm - have hf := Ly.vfit p hp - have hfu := hf.2 - have hal : P1.Aligned w := by - show w.val % 8 = 0 - have : p.val % 32768 = 0 := hf.1 - omega - have hW : P1.WritesIn st s (L.wr s w 0#u64) (· = w) := P1.writesIn_wr hal - have R0 := J.vr p hp vs hk - have hpv : Fl4Spec.VcpuLay.PENDING.toNat = 20520 := v3_fix_vals.2.2.1 - have e1 := v3_toNat_add hfu VirtVcpuRel.pending_lt - have h0 : vmemW (L.mem (L.wr s w 0#u64)) (p.bv + Fl4Spec.VcpuLay.PENDING) = 0 := by - have ha : (p.bv + Fl4Spec.VcpuLay.PENDING).toNat % 8 = 0 := by rw [e1, hpv]; omega - unfold vmemW - rw [if_pos ha] - rw [show (⟨p.bv + Fl4Spec.VcpuLay.PENDING⟩ : U64) = w from - UScalar.eq_of_val_eq (by show (p.bv + Fl4Spec.VcpuLay.PENDING).toNat = w.val; rw [e1, hpv, hwp])] - rw [L.mem_wr s w 0#u64 w hal hal, if_pos rfl] - rfl - have hR := v3_pendR (k := Fl4Spec.virtKind) (mem := vmemW (L.mem s)) (mem' := vmemW (L.mem (L.wr s w 0#u64))) - (v3_agree hfu fun b hb _ _ hne => hW.mem_eq hb fun e' => hne (by rw [e', hpv]; omega)) h0 R0 - exact J.vcpuStep hp hal (by omega) (by omega) ⟨by omega, by omega, by omega⟩ 0#u64 hk _ rfl hR + (Notif.updK σ p.bv (.archObj (.vcpu vs.reported))) := + J.clearExitWord hp (Or.inl v3_fix_vals.2.2.1) + (by rw [v3_fix_vals.2.2.1]; exact hwp) hk rfl fun hm h0 h => v3_pendR hm h0 h + +/-- Clear the saved-exit flag at VM entry. -/ +theorem VmBaseF.validClr (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p w : U64} (hp : p ∈ V) + (hwp : w.val = p.val + 20528) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s w 0#u64) a + (Notif.updK σ p.bv (.archObj (.vcpu { vs with exit := { vs.exit with valid := false } }))) := + J.clearExitWord hp (Or.inr v3_fix_vals.2.1) + (by rw [v3_fix_vals.2.1]; exact hwp) hk rfl fun hm h0 h => v3_validR hm h0 h /-- **FL4's `PENDING := 0` paired with the spec's `VcpuState.reported`** (module docstring). -/ theorem JAtZV3.pendClr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p w : U64} (hp : p ∈ V) diff --git a/proofs/Fl4Proofs/P3/JAtZV3RegW.lean b/proofs/Fl4Proofs/P3/JAtZV3RegW.lean index ea477e9a9..baf5db424 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3RegW.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3RegW.lean @@ -16,6 +16,10 @@ P3 (line mmuAD, gen 33): **TCB register words and IPC-buffer words at `JAtZV3`** No named premise. No existing statement changed. +(mmuAD gen 42b66) `JAtZB.regWrJZ` moved to P3/XTopJointReply (statement unchanged), where `JAtZ.regWrJ` is now its +corollary. `VmBaseF.userWr` reads its word's facts from XTopJointData's new `JAtZB.userW_nat` (the same three +subproofs, moved there). + (mmuAD gen 42b18) Removed (the originals are stated over `JAtZB` in place, the `JAtZ` names their corollaries with `ext` rebuilt): P3/XTopJointData `userWrJ`. @@ -40,48 +44,6 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se section open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched -set_option maxHeartbeats 8000000 in -/-- **One register write of a thread at `JAtZB`** (XTopJointReply's `JAtZ.regWrJ`, generated copy; post at `Z` with -the `FinW` footprint via `JAtZB.reg_frameFZ`). -/ -theorem JAtZB.regWrJZ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (r : Fl4Spec.Register) (v : U64) - (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (Endp.regA t (regIdx r)) v) - (updK σ t.bv (.tcb (setReg x r v.bv)))) : - P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) ∧ - JAtZB (L := L) arI AR Z H Cs Ac Lst D (L.wr s (Endp.regA t (regIdx r)) v) a - (updK σ t.bv (.tcb (setReg x r v.bv))) := by - have hP0 := J.ip - have hT : TcbPlaced Z.T := hP0.e.tcb - have hta := hT t ht - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hT - have hil := regIdx_lt r - set K : U64 := ⟨BitVec.ofNat 64 (256 + 8 * (regIdx r).val)⟩ with hKdef - have hKv : K.val = 256 + 8 * (regIdx r).val := by - show (BitVec.ofNat 64 (256 + 8 * (regIdx r).val)).toNat = _ - rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega) - have hra : (Endp.regA t (regIdx r)).val = t.val + 256 + 8 * (regIdx r).val := regA_val hta hil - have hKt : (core.num.U64.wrapping_add t K).val = t.val + K.val := tfield_val hta (by rw [hKv]; omega) - have hreq : Endp.regA t (regIdx r) = core.num.U64.wrapping_add t K := - UScalar.eq_of_val_eq (by rw [hra, hKt, hKv]; omega) - have hwr : P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (· = Endp.regA t (regIdx r)) := - writesIn_wr (a_reg hta r).1 - have hblk := (blk_rf J.blk (hwr.mono fun b hb => Or.inl ⟨t, htH, K, by rw [hKv]; omega, - by rw [hKv]; omega, by rw [hb, hreq]⟩)).1 - have hfoot : P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (P1.KW st (P1.Heap.tcbs H) Cs - (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) ∅ s) := by - rw [hreq] - exact foot_field hTH htH (by rw [hKv]; omega) (by rw [hKv]; omega) (by rw [hKv]; omega) - ⟨by rw [hKv]; omega, by rw [hKv]; omega⟩ - have hA : QKY σ (updK σ t.bv (.tcb (setReg x r v.bv))) := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun p => ?_⟩ - by_cases hp : p = t.bv - · subst hp; exact Or.inr (Or.inl ⟨x, setReg x r v.bv, hk, by simp [updK], rfl⟩) - · exact Or.inl (by simp [updK, hp]) - exact J.reg_frameFZ hX2 (hwr.mono fun b hb => Or.inl (Or.inl ⟨t, ht, by rw [hb, hra]; omega, - by rw [hb, hra]; omega⟩)) hA (YK.YKS.updTcb (y := setReg x r v.bv) hk rfl).ykeep - (J.inv.updSame (y := setReg x r v.bv) hk rfl rfl (Or.inl rfl)) hblk hfoot - end section @@ -123,27 +85,11 @@ theorem VmBaseF.userWr (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (Endp.setUm σ (Endp.storeMem σ.machineState.underlyingMemory wp.2 v.bv)) := by have B := J.base have hP := B.xtop.fin.1.2 - have hS := B.xtop.fin.1.1.1 have hal : P1.Aligned wp.1 := (hP.ep.balign wp hwB).1 have hW : P1.WritesIn st s (L.wr s wp.1 v) (· = wp.1) := P1.writesIn_wr hal - refine J.ofB (B.userWrJ hBP hwB hAp hObj v) hW (fun b hb => ?_) (fun b hb => ?_) - (B.vkeep_of hW fun b hb => ?_) rfl - · subst hb - exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨wp, hwB, le_refl _, by omega⟩)))))) - · subst hb - intro e - have hvh : (P1.vHeadA st s).val = (L.ksb s).val + 80 := vHead_val B.kern.ksbFit - have hnb : L.nodeBase s Z.c = (L.ksb s).val + 13568 + Z.c.val * 4288 := rfl - have hf := hBP.far wp hwB - rw [e, hvh, hnb] at hf - omega - · subst hb - intro t ht e - have hT := hS.placed.tcb - have hv : wp.1.val = t.val + 3664 := by rw [e]; exact tfield_val (hT t ht) (K := 3664#u64) (by simp) - rcases hAp t .tcb (B.zH.1 t ht) (fun _ e => by cases e) with e' | e' - · omega - · simp only [P1.HKind.bits] at e'; omega + obtain ⟨hO, hh, hv⟩ := B.userW_nat hBP hwB hAp + exact J.ofB (B.userWrJ hBP hwB hAp hObj v) hW (fun b hb => by subst hb; exact hO) (fun b hb => by subst hb; exact hh) + (B.vkeep_of hW fun b hb => by subst hb; exact hv) rfl /-- **An IPC-buffer word written at `JAtZV3`** (module docstring). -/ theorem JAtZV3.userWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) diff --git a/proofs/Fl4Proofs/P3/JAtZV3RepBrC.lean b/proofs/Fl4Proofs/P3/JAtZV3RepBrC.lean index 44b5fbeeb..3414fedaf 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3RepBrC.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3RepBrC.lean @@ -22,9 +22,9 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 4000000 in /-- **Branch: no pending exit, full-state caller, with a VCPU** (module docstring). -/ -theorem VmBaseF.repBrC2 (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) +theorem VmBaseF.repBrC2Running (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (htT : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - (hrs : x.tcbState = .runningVM) {b : U64} (hb : JBufR Z.B b (Endp.ipcBufOf true x)) + (hrs : x.tcbState = .running ∨ x.tcbState = .runningVM) {b : U64} (hb : JBufR Z.B b (Endp.ipcBufOf true x)) (hal : ∀ ms : List Fl4Spec.Word, ∀ p, Endp.ipcBufOf true x = some p → ∀ q ∈ Endp.mrPairs ms, (Endp.bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (Endp.bufAddr p q.1) σ) {v : U64} (hv0 : v ≠ 0#u64) (hvV : v ∈ V) {vs : Fl4Spec.VcpuState} @@ -248,7 +248,7 @@ theorem VmBaseF.repBrC2 (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA refine WP.spec_bind (VmBaseF.repLoop2 htT hq hb (v := v) (pending := false) (saved := saved) (vs := vs) (fun _ => ⟨hvV, hkv, hvt'⟩) 0#u64 (by simp) s J0') fun s1 J1 => ?_ refine v3_ite_spec (fun h => absurd h hv0) (fun _ => ?_) - refine WP.spec_mono (J1.repTail hVA htT hq hb hrs hvV hkv hvt' false saved true hsaved (fun _ => rfl) badge + refine WP.spec_mono (J1.repTailRunning hVA htT hq hb hrs hvV hkv hvt' false saved true hsaved (fun _ => rfl) badge (fun s4 => vcpu.report_loop3 st s4 t v b 0#u64) (fun sB σB => sB = sA ∧ σB = σA) ⟨rfl, rfl⟩ (fun s4 J4 => WP.spec_mono (VmBaseF.repLoop3 htT hq hb hvV hkv hvt' _ 0#u64 (by simp) s4 (by rw [v3_gpr0]; exact J4)) fun _ J5 => ⟨sA, σA, ⟨rfl, rfl⟩, J5⟩)) fun s' h' => ?_ @@ -257,6 +257,222 @@ theorem VmBaseF.repBrC2 (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA rw [v3_vmReportF_some hk hTV hkv badge.bv (hal _), v3_repR_full x vs badge.bv hpend.symm hfull.symm, hsaved] rfl +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repBrC2 (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) + {t : U64} (htT : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hrs : x.tcbState = .runningVM) {b : U64} (hb : JBufR Z.B b (Endp.ipcBufOf true x)) + (hal : ∀ ms : List Fl4Spec.Word, ∀ p, Endp.ipcBufOf true x = some p → ∀ q ∈ Endp.mrPairs ms, + (Endp.bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (Endp.bufAddr p q.1) σ) + {v : U64} (hv0 : v ≠ 0#u64) (hvV : v ∈ V) {vs : Fl4Spec.VcpuState} + (hkv : σ.kheap v.bv = some (.archObj (.vcpu vs))) (hvt' : v.bv ≠ t.bv) + (hTV : Fl4Spec.tcbVcpuOf σ t.bv = some v.bv) + {pending full : Bool} (hpend : pending = vs.exit.pending) (hp : pending = false) (hf : full = true) + (hfull : full = Fl4Proofs.P3.repFull x) (badge : U64) : + (do + let saved ← + if v != 0#u64 + then + do + let i ← vcpu.get st s v vcpu.VALID + ok (i != 0#u64) + else ok false + let s1 ← vcpu.report_loop2 st s t v pending b saved 0#u64 + if v = 0#u64 + then + vcpu.finish_notification st arI s1 a t b + badge false + else + let i ← vcpu.get st s1 v vcpu.VALID + if i = 0#u64 + then + let i1 ← arI.virtualization a + let ip ← + if i1 = 2#u64 + then do + let i2 ← vcpu.svm.RIP + vcpu.get st s1 v i2 + else vcpu.read_vmcs st s1 v vcpu.vmx.GUEST_RIP + let ctl ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.get st s1 v vcpu.svm.INTERCEPT_EXC + i2 >>> 32#i32 + else + vcpu.read_vmcs st s1 v + vcpu.vmx.CONTROL_PRIMARY_PROCESSOR_CONTROLS + let intr ← + if i1 = 2#u64 + then vcpu.get st s1 v vcpu.svm.EVENT_INJ + else + vcpu.read_vmcs st s1 v + vcpu.vmx.CONTROL_ENTRY_INTERRUPTION_INFO + let (_, s2) ← msg.set_mr st s1 t b 0#u64 ip + let (_, s3) ← msg.set_mr st s2 t b 1#u64 ctl + let (_, s4) ← msg.set_mr st s3 t b 2#u64 intr + let s5 ← vcpu.report_loop3 st s4 t v b 0#u64 + let i2 ← vcpu.get st s5 v vcpu.VALID + let s6 ← + if i2 = 0#u64 + then + do + let i3 ← arI.virtualization a + let flags ← + if i3 = 2#u64 + then + do + let i4 ← vcpu.svm.RFLAGS + vcpu.get st s5 v i4 + else vcpu.read_vmcs st s5 v vcpu.vmx.GUEST_RFLAGS + let int ← + if i3 = 2#u64 + then vcpu.get st s5 v vcpu.svm.INT_STATE + else + vcpu.read_vmcs st s5 v + vcpu.vmx.GUEST_INTERRUPTABILITY + let cr3 ← + if i3 = 2#u64 + then + do + let i4 ← vcpu.svm.CR3 + vcpu.get st s5 v i4 + else ok 0#u64 + let cr2 ← + if i3 = 2#u64 + then + do + let i4 ← vcpu.svm.CR2 + vcpu.get st s5 v i4 + else vcpu.get st s5 v vcpu.CR2 + let (_, s7) ← msg.set_mr st s5 t b 7#u64 flags + let (_, s8) ← msg.set_mr st s7 t b 8#u64 int + let (_, s9) ← msg.set_mr st s8 t b 9#u64 cr3 + let (_, s10) ← msg.set_mr st s9 t b 29#u64 cr2 + ok s10 + else ok s5 + if full + then + let i3 ← msg.syscall_arg st s6 t b 2#u64 + let descriptor ← lift (i3 &&& 4294967295#u64) + let (_, s7) ← msg.set_mr st s6 t b 2#u64 descriptor + if pending + then + let s8 ← vcpu.set st s7 v vcpu.PENDING 0#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.MSG_INFO 1#u64 + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s10 layout.reg.NEXT_IP + let s11 ← + obj.Tcb.set_reg st t s10 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s11 t sched.TS_RUNNING + else + let vectoring ← + if saved + then + do + let i4 ← 27#u64 * 8#u64 + let i5 ← vcpu.EXIT + i4 + let i6 ← vcpu.get st s7 v i5 + let i7 ← 1#u64 <<< 31#i32 + let i8 ← lift (i6 &&& i7) + ok (i8 != 0#u64) + else ok false + vcpu.finish_notification st arI s7 a t + b badge vectoring + else + let s7 ← vcpu.set st s6 v vcpu.PENDING 0#u64 + let s8 ← + obj.Tcb.set_reg st t s7 layout.reg.MSG_INFO 1#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s9 layout.reg.NEXT_IP + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s10 t sched.TS_RUNNING + else + let s2 ← + if i = 0#u64 + then + do + let i1 ← arI.virtualization a + let flags ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.svm.RFLAGS + vcpu.get st s1 v i2 + else vcpu.read_vmcs st s1 v vcpu.vmx.GUEST_RFLAGS + let int ← + if i1 = 2#u64 + then vcpu.get st s1 v vcpu.svm.INT_STATE + else + vcpu.read_vmcs st s1 v + vcpu.vmx.GUEST_INTERRUPTABILITY + let cr3 ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.svm.CR3 + vcpu.get st s1 v i2 + else ok 0#u64 + let cr2 ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.svm.CR2 + vcpu.get st s1 v i2 + else vcpu.get st s1 v vcpu.CR2 + let (_, s3) ← msg.set_mr st s1 t b 7#u64 flags + let (_, s4) ← msg.set_mr st s3 t b 8#u64 int + let (_, s5) ← msg.set_mr st s4 t b 9#u64 cr3 + let (_, s6) ← msg.set_mr st s5 t b 29#u64 cr2 + ok s6 + else ok s1 + if full + then + let i1 ← msg.syscall_arg st s2 t b 2#u64 + let descriptor ← lift (i1 &&& 4294967295#u64) + let (_, s3) ← msg.set_mr st s2 t b 2#u64 descriptor + if pending + then + let s4 ← vcpu.set st s3 v vcpu.PENDING 0#u64 + let s5 ← + obj.Tcb.set_reg st t s4 layout.reg.MSG_INFO 1#u64 + let s6 ← + obj.Tcb.set_reg st t s5 layout.reg.BADGE 0#u64 + let ip ← obj.Tcb.reg st t s6 layout.reg.NEXT_IP + let s7 ← + obj.Tcb.set_reg st t s6 layout.reg.FAULT_IP ip + sched.set_thread_state st s7 t sched.TS_RUNNING + else + let vectoring ← + if saved + then + do + let i2 ← 27#u64 * 8#u64 + let i3 ← vcpu.EXIT + i2 + let i4 ← vcpu.get st s3 v i3 + let i5 ← 1#u64 <<< 31#i32 + let i6 ← lift (i4 &&& i5) + ok (i6 != 0#u64) + else ok false + vcpu.finish_notification st arI s3 a t + b badge vectoring + else + let s3 ← vcpu.set st s2 v vcpu.PENDING 0#u64 + let s4 ← + obj.Tcb.set_reg st t s3 layout.reg.MSG_INFO 1#u64 + let s5 ← + obj.Tcb.set_reg st t s4 layout.reg.BADGE 0#u64 + let ip ← obj.Tcb.reg st t s5 layout.reg.NEXT_IP + let s6 ← + obj.Tcb.set_reg st t s5 layout.reg.FAULT_IP ip + sched.set_thread_state st s6 t sched.TS_RUNNING) ⦃ s' => ∃ (σr : Fl4Spec.State Unit) (Lst' : U64 → List U64), + Fl4Spec.vmReportF (Z := Unit) t.bv badge.bv σ = ({((), σr)}, False) ∧ + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a σr ⦄ := + J.repBrC2Running hVA htT hk (Or.inr hrs) hb hal hv0 hvV hkv hvt' hTV hpend hp hf hfull badge + set_option maxHeartbeats 4000000 in /-- **Branch: no pending exit, full-state caller, with a VCPU** (module docstring). -/ theorem JAtZV3.repBrC2 (hVA : ZvVirtAgree arI) (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) diff --git a/proofs/Fl4Proofs/P3/JAtZV3RepFin.lean b/proofs/Fl4Proofs/P3/JAtZV3RepFin.lean index c49214219..1574a395c 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3RepFin.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3RepFin.lean @@ -41,8 +41,8 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 8000000 in /-- **Message info, badge, FaultIP, `Running`** (module docstring). -/ -theorem VmBaseF.repFin (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .runningVM) (mi bd : U64) : +theorem VmBaseF.repFinRunning (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .running ∨ x1.tcbState = .runningVM) (mi bd : U64) : (do let s4 ← obj.Tcb.set_reg st t s layout.reg.MSG_INFO mi let s5 ← obj.Tcb.set_reg st t s4 layout.reg.BADGE bd @@ -83,7 +83,7 @@ theorem VmBaseF.repFin (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a some (.tcb (Notif.setReg (Notif.setReg (Notif.setReg x1 Fl4Spec.msg_info_register mi.bv) Fl4Spec.badge_register bd.bv) .faultIP (L.mem (L.wr (L.wr s (Endp.regA t layout.reg.MSG_INFO) mi) (Endp.regA t layout.reg.BADGE) bd) (Endp.regA t layout.reg.NEXT_IP)).bv))) - refine WP.spec_mono (J6.runVmJ ht hk6 hrs) fun s7 h7 => ?_ + refine WP.spec_mono (J6.reportRunningJ ht hk6 hrs) fun s7 h7 => ?_ obtain ⟨Lst', J7⟩ := h7 refine ⟨Lst', ?_⟩ unfold repTail @@ -92,6 +92,18 @@ theorem VmBaseF.repFin (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a rw [← hnx] exact J7 +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repFin (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .runningVM) (mi bd : U64) : + (do + let s4 ← obj.Tcb.set_reg st t s layout.reg.MSG_INFO mi + let s5 ← obj.Tcb.set_reg st t s4 layout.reg.BADGE bd + let next ← obj.Tcb.reg st t s5 layout.reg.NEXT_IP + let s6 ← obj.Tcb.set_reg st t s5 layout.reg.FAULT_IP next + sched.set_thread_state st s6 t sched.TS_RUNNING) ⦃ s' => ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a (repTail σ t.bv x1 mi.bv bd.bv) ⦄ := + J.repFinRunning ht hk (Or.inr hrs) mi bd + set_option maxHeartbeats 8000000 in /-- **Message info, badge, FaultIP, `Running`** (module docstring). -/ theorem JAtZV3.repFin (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) @@ -108,8 +120,8 @@ theorem JAtZV3.repFin (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t set_option maxHeartbeats 8000000 in /-- **`PENDING := 0`, message info 1, badge 0, FaultIP, `Running`** (module docstring). -/ -theorem VmBaseF.repFinP (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .runningVM) {v : U64} (hv : v ∈ V) +theorem VmBaseF.repFinPRunning (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .running ∨ x1.tcbState = .runningVM) {v : U64} (hv : v ∈ V) {vs : Fl4Spec.VcpuState} (hkv : σ.kheap v.bv = some (.archObj (.vcpu vs))) : (do let s8 ← vcpu.set st s v vcpu.PENDING 0#u64 @@ -134,7 +146,22 @@ theorem VmBaseF.repFinP (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s have J8 := J.pendClr hv hwp hkv have hk8 : (Notif.updK σ v.bv (.archObj (.vcpu vs.reported))).kheap t.bv = some (.tcb x1) := by simp only [Notif.updK_kheap]; rw [Function.update_of_ne (Ne.symm hvt)]; exact hk - exact J8.repFin ht hk8 hrs 1#u64 0#u64 + exact J8.repFinRunning ht hk8 hrs 1#u64 0#u64 + +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repFinP (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x1 : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x1)) (hrs : x1.tcbState = .runningVM) {v : U64} (hv : v ∈ V) + {vs : Fl4Spec.VcpuState} (hkv : σ.kheap v.bv = some (.archObj (.vcpu vs))) : + (do + let s8 ← vcpu.set st s v vcpu.PENDING 0#u64 + let s9 ← obj.Tcb.set_reg st t s8 layout.reg.MSG_INFO 1#u64 + let s10 ← obj.Tcb.set_reg st t s9 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s10 layout.reg.NEXT_IP + let s11 ← obj.Tcb.set_reg st t s10 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s11 t sched.TS_RUNNING) ⦃ s' => ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a + (repTail (Notif.updK σ v.bv (.archObj (.vcpu vs.reported))) t.bv x1 (1#u64 : U64).bv (0#u64 : U64).bv) ⦄ := + J.repFinPRunning ht hk (Or.inr hrs) hv hkv set_option maxHeartbeats 8000000 in /-- **`PENDING := 0`, message info 1, badge 0, FaultIP, `Running`** (module docstring). -/ @@ -178,10 +205,10 @@ theorem v3_repX_state (x0 : Fl4Spec.Tcb) (ms : List Fl4Spec.Word) : (repX x0 ms) set_option maxHeartbeats 16000000 in /-- `finish_notification`'s writes after the reason word `r` is chosen (module docstring). -/ -theorem VmBaseF.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} +theorem VmBaseF.repFinN0Running {t : U64} {F : Nat → Fl4Spec.Word} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B rw pb) - (hrs : x0.tcbState = .runningVM) (badge : U64) (vec : Bool) (r : U64) + (hrs : x0.tcbState = .running ∨ x0.tcbState = .runningVM) (badge : U64) (vec : Bool) (r : U64) (hrv : r.bv = Fl4Spec.vmNotifyReason Fl4Spec.virtKind) : (do let (_, s1) ← msg.set_mr st s t rw 3#u64 r @@ -239,7 +266,7 @@ theorem VmBaseF.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} rintro ⟨_, s6⟩ J6 try simp only [uncurry_apply_pair] rw [v3_map_congr 30 hG] at J6 - exact J6.repFin hr (jMrSt_rcv _ _ _ _ _) hrs 0#u64 badge + exact J6.repFinRunning hr (jMrSt_rcv _ _ _ _ _) hrs 0#u64 badge cases vec with | true => simp only [↓reduceIte, bind_ok] @@ -264,6 +291,35 @@ theorem VmBaseF.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} by_cases e3 : k = 3 <;> by_cases e4 : k = 4 <;> by_cases e5 : k = 5 <;> by_cases e6 : k = 6 <;> by_cases e25 : k = 25 <;> by_cases e26 : k = 26 <;> simp_all +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) + (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B rw pb) + (hrs : x0.tcbState = .runningVM) (badge : U64) (vec : Bool) (r : U64) + (hrv : r.bv = Fl4Spec.vmNotifyReason Fl4Spec.virtKind) : + (do + let (_, s1) ← msg.set_mr st s t rw 3#u64 r + let (_, s2) ← msg.set_mr st s1 t rw 4#u64 0#u64 + let s3 ← + if vec + then ok s2 + else + do + let (_, s4) ← msg.set_mr st s2 t rw 5#u64 0#u64 + ok s4 + let (_, s4) ← msg.set_mr st s3 t rw 6#u64 0#u64 + let (_, s5) ← msg.set_mr st s4 t rw 25#u64 0#u64 + let (_, s6) ← msg.set_mr st s5 t rw 26#u64 0#u64 + let s7 ← obj.Tcb.set_reg st t s6 layout.reg.MSG_INFO 0#u64 + let s8 ← obj.Tcb.set_reg st t s7 layout.reg.BADGE badge + let next ← obj.Tcb.reg st t s8 layout.reg.NEXT_IP + let s9 ← obj.Tcb.set_reg st t s8 layout.reg.FAULT_IP next + sched.set_thread_state st s9 t sched.TS_RUNNING) ⦃ s' => ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a + (repTail (jMrSt σ0 t.bv x0 pb ((List.range 30).map (repFinF vec F))) t.bv + (repX x0 ((List.range 30).map (repFinF vec F))) (0#u64 : U64).bv badge.bv) ⦄ := + J.repFinN0Running hr hq hb (Or.inr hrs) badge vec r hrv + set_option maxHeartbeats 16000000 in /-- `finish_notification`'s writes after the reason word `r` is chosen (module docstring). -/ theorem JAtZV3.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} @@ -296,10 +352,10 @@ theorem JAtZV3.repFinN0 {t : U64} {F : Nat → Fl4Spec.Word} fun _ ⟨Lst', J'⟩ => ⟨Lst', J.ofF J'⟩ /-- **`finish_notification` at `JAtZV3`** (module docstring). -/ -theorem VmBaseF.repFinN (hVA : ZvVirtAgree arI) {t : U64} {F : Nat → Fl4Spec.Word} +theorem VmBaseF.repFinNRunning (hVA : ZvVirtAgree arI) {t : U64} {F : Nat → Fl4Spec.Word} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B rw pb) - (hrs : x0.tcbState = .runningVM) (badge : U64) (vec : Bool) : + (hrs : x0.tcbState = .running ∨ x0.tcbState = .runningVM) (badge : U64) (vec : Bool) : vcpu.finish_notification st arI s a t rw badge vec ⦃ s' => ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a (repTail (jMrSt σ0 t.bv x0 pb ((List.range 30).map (repFinF vec F))) t.bv @@ -309,12 +365,23 @@ theorem VmBaseF.repFinN (hVA : ZvVirtAgree arI) {t : U64} {F : Nat → Fl4Spec.W rw [hvi, bind_ok] by_cases h2 : i = 2#u64 · rw [if_pos h2] - exact J.repFinN0 hr hq hb hrs badge vec 96#u64 (by + exact J.repFinN0Running hr hq hb hrs badge vec 96#u64 (by rw [Fl4Spec.vmNotifyReason, if_pos (hi.1 h2)]; rfl) · rw [if_neg h2] - exact J.repFinN0 hr hq hb hrs badge vec 1#u64 (by + exact J.repFinN0Running hr hq hb hrs badge vec 1#u64 (by rw [Fl4Spec.vmNotifyReason, if_neg (fun h => h2 (hi.2 h))]; rfl) +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repFinN (hVA : ZvVirtAgree arI) {t : U64} {F : Nat → Fl4Spec.Word} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) + (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B rw pb) + (hrs : x0.tcbState = .runningVM) (badge : U64) (vec : Bool) : + vcpu.finish_notification st arI s a t rw badge vec ⦃ s' => ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a + (repTail (jMrSt σ0 t.bv x0 pb ((List.range 30).map (repFinF vec F))) t.bv + (repX x0 ((List.range 30).map (repFinF vec F))) (0#u64 : U64).bv badge.bv) ⦄ := + J.repFinNRunning hVA hr hq hb (Or.inr hrs) badge vec + /-- **`finish_notification` at `JAtZV3`** (module docstring). -/ theorem JAtZV3.repFinN (hVA : ZvVirtAgree arI) {t : U64} {F : Nat → Fl4Spec.Word} (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) diff --git a/proofs/Fl4Proofs/P3/JAtZV3RepTail.lean b/proofs/Fl4Proofs/P3/JAtZV3RepTail.lean index de03540df..29ed2d8a7 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3RepTail.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3RepTail.lean @@ -57,10 +57,10 @@ variable {σ0 : Fl4Spec.State Unit} {x0 : Fl4Spec.Tcb} {pb : Option Fl4Spec.ObjR set_option maxHeartbeats 16000000 in /-- **The `if full …` block** (module docstring). -/ -theorem VmBaseF.repFull (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Spec.Word} {s6 : S} +theorem VmBaseF.repFullRunning (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Spec.Word} {s6 : S} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s6 a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B b pb) - (hrs : x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) + (hrs : x0.tcbState = .running ∨ x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) (hvt : v.bv ≠ t.bv) (pending saved full : Bool) (hsaved : saved = vs.exit.valid) (hpf : pending = false → full = true) (badge : U64) : (do @@ -119,7 +119,7 @@ theorem VmBaseF.repFull (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Sp have e : (List.range 30).map (rpFullF false F) = (List.range 30).map F := v3_map_congr 30 (fun k _ => by simp [rpFullF]) simp only [repEnd, ↓reduceIte, e] - exact J.repFinP hr hkt hrs hv hk + exact J.repFinPRunning hr hkt hrs hv hk | true => simp only [↓reduceIte] refine WP.spec_bind (v3_syscall_arg2 s6 t b) fun i3 hi3 => ?_ @@ -147,7 +147,7 @@ theorem VmBaseF.repFull (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Sp | true => simp only [↓reduceIte] simp only [repEnd, ↓reduceIte] - exact J7.repFinP hr (jMrSt_rcv _ _ _ _ _) hrs hv hk7 + exact J7.repFinPRunning hr (jMrSt_rcv _ _ _ _ _) hrs hv hk7 | false => simp only [Bool.false_eq_true, ↓reduceIte] simp only [repEnd, Bool.false_eq_true, ↓reduceIte] @@ -173,7 +173,58 @@ theorem VmBaseF.repFull (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Sp simp [rpVecOf, ← hsaved] · intro vec hvec subst hvec - exact J7.repFinN hVA hr hq hb hrs badge _ + exact J7.repFinNRunning hVA hr hq hb hrs badge _ + +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repFull (hVA : ZvVirtAgree arI) {t b v : U64} {F : Nat → Fl4Spec.Word} {s6 : S} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s6 a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F))) + (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B b pb) + (hrs : x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) + (hvt : v.bv ≠ t.bv) (pending saved full : Bool) (hsaved : saved = vs.exit.valid) + (hpf : pending = false → full = true) (badge : U64) : + (do + if full + then + let i3 ← msg.syscall_arg st s6 t b 2#u64 + let descriptor ← lift (i3 &&& 4294967295#u64) + let (_, s7) ← msg.set_mr st s6 t b 2#u64 descriptor + if pending + then + let s8 ← vcpu.set st s7 v vcpu.PENDING 0#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.MSG_INFO 1#u64 + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s10 layout.reg.NEXT_IP + let s11 ← + obj.Tcb.set_reg st t s10 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s11 t sched.TS_RUNNING + else + let vectoring ← + if saved + then + do + let i4 ← 27#u64 * 8#u64 + let i5 ← vcpu.EXIT + i4 + let i6 ← vcpu.get st s7 v i5 + let i7 ← 1#u64 <<< 31#i32 + let i8 ← lift (i6 &&& i7) + ok (i8 != 0#u64) + else ok false + vcpu.finish_notification st arI s7 a t b + badge vectoring + else + let s7 ← vcpu.set st s6 v vcpu.PENDING 0#u64 + let s8 ← + obj.Tcb.set_reg st t s7 layout.reg.MSG_INFO 1#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s9 layout.reg.NEXT_IP + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s10 t sched.TS_RUNNING) ⦃ s' => ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a + (repEnd σ0 t x0 pb v vs pending saved full badge F) ⦄ := + J.repFullRunning hVA hr hq hb (Or.inr hrs) hv hkv hvt pending saved full hsaved hpf badge set_option maxHeartbeats 16000000 in /-- **The `if full …` block** (module docstring). -/ @@ -234,10 +285,10 @@ def rpTailF (vs : Fl4Spec.VcpuState) (F0 : Nat → Fl4Spec.Word) : Nat → Fl4Sp set_option maxHeartbeats 32000000 in /-- **The tail of the report after its first loop, with a VCPU** (module docstring). -/ -theorem VmBaseF.repTail (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4Spec.Word} {s1 : S} +theorem VmBaseF.repTailRunning (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4Spec.Word} {s1 : S} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s1 a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F0))) (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B b pb) - (hrs : x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) + (hrs : x0.tcbState = .running ∨ x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) (hvt : v.bv ≠ t.bv) (pending saved full : Bool) (hsaved : saved = vs.exit.valid) (hpf : pending = false → full = true) (badge : U64) (lp : S → Result S) (R : S → Fl4Spec.State Unit → Prop) (hR : R sA σA) @@ -439,7 +490,7 @@ theorem VmBaseF.repTail (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4S rw [if_neg hi0, if_neg hi0, bind_ok] unfold rpTailF rw [if_pos hval] - exact WP.spec_mono (J.repFull hVA hr hq hb hrs hv hkv hvt pending saved full hsaved hpf badge) + exact WP.spec_mono (J.repFullRunning hVA hr hq hb hrs hv hkv hvt pending saved full hsaved hpf badge) fun _ h => ⟨sA, σA, hR, h⟩ · have hval' : vs.exit.valid = false := by simpa using hval have hi0 : L.mem s1 (core.num.U64.wrapping_add v vcpu.VALID) = 0#u64 := (J.rdValid0 hv hk).2 hval' @@ -471,9 +522,209 @@ theorem VmBaseF.repTail (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4S refine WP.spec_bind (J5.repCr hVA hr hq hb hv hkv hvt) fun s6 J6 => ?_ unfold rpTailF rw [if_neg hval] - exact WP.spec_mono (J6.repFull hVA hr hq hb hrs hv hkv hvt pending saved full hsaved hpf badge) + exact WP.spec_mono (J6.repFullRunning hVA hr hq hb hrs hv hkv hvt pending saved full hsaved hpf badge) fun _ h => ⟨sB, σB, hRB, h⟩ +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.repTail (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4Spec.Word} {s1 : S} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s1 a (jMrSt σ0 t.bv x0 pb ((List.range 30).map F0))) + (hr : t ∈ Z.T) (hq : ∀ p, pb = some p → Endp.ipcBufOf true x0 = some p) (hb : JBufR Z.B b pb) + (hrs : x0.tcbState = .runningVM) (hv : v ∈ V) (hkv : σ0.kheap v.bv = some (.archObj (.vcpu vs))) + (hvt : v.bv ≠ t.bv) (pending saved full : Bool) (hsaved : saved = vs.exit.valid) + (hpf : pending = false → full = true) (badge : U64) (lp : S → Result S) + (R : S → Fl4Spec.State Unit → Prop) (hR : R sA σA) + (hlp : ∀ s4, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s4 a + (jMrSt σ0 t.bv x0 pb ((List.range 30).map (rpEntF vs F0))) → + lp s4 ⦃ s5 => ∃ (sB : S) (σB : Fl4Spec.State Unit), R sB σB ∧ VmBaseF (L := L) arI sB σB V AR Z H Cs Ac Lst D + s5 a (jMrSt σ0 t.bv x0 pb ((List.range 30).map (gprOv vs (rpEntF vs F0) 15))) ⦄) : + (do + let i ← vcpu.get st s1 v vcpu.VALID + if i = 0#u64 + then + let i1 ← arI.virtualization a + let ip ← + if i1 = 2#u64 + then do + let i2 ← vcpu.svm.RIP + vcpu.get st s1 v i2 + else vcpu.read_vmcs st s1 v vcpu.vmx.GUEST_RIP + let ctl ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.get st s1 v vcpu.svm.INTERCEPT_EXC + i2 >>> 32#i32 + else + vcpu.read_vmcs st s1 v + vcpu.vmx.CONTROL_PRIMARY_PROCESSOR_CONTROLS + let intr ← + if i1 = 2#u64 + then vcpu.get st s1 v vcpu.svm.EVENT_INJ + else + vcpu.read_vmcs st s1 v + vcpu.vmx.CONTROL_ENTRY_INTERRUPTION_INFO + let (_, s2) ← msg.set_mr st s1 t b 0#u64 ip + let (_, s3) ← msg.set_mr st s2 t b 1#u64 ctl + let (_, s4) ← msg.set_mr st s3 t b 2#u64 intr + let s5 ← lp s4 + let i2 ← vcpu.get st s5 v vcpu.VALID + let s6 ← + if i2 = 0#u64 + then + do + let i3 ← arI.virtualization a + let flags ← + if i3 = 2#u64 + then + do + let i4 ← vcpu.svm.RFLAGS + vcpu.get st s5 v i4 + else vcpu.read_vmcs st s5 v vcpu.vmx.GUEST_RFLAGS + let int ← + if i3 = 2#u64 + then vcpu.get st s5 v vcpu.svm.INT_STATE + else + vcpu.read_vmcs st s5 v + vcpu.vmx.GUEST_INTERRUPTABILITY + let cr3 ← + if i3 = 2#u64 + then do + let i4 ← vcpu.svm.CR3 + vcpu.get st s5 v i4 + else ok 0#u64 + let cr2 ← + if i3 = 2#u64 + then do + let i4 ← vcpu.svm.CR2 + vcpu.get st s5 v i4 + else vcpu.get st s5 v vcpu.CR2 + let (_, s7) ← msg.set_mr st s5 t b 7#u64 flags + let (_, s8) ← msg.set_mr st s7 t b 8#u64 int + let (_, s9) ← msg.set_mr st s8 t b 9#u64 cr3 + let (_, s10) ← msg.set_mr st s9 t b 29#u64 cr2 + ok s10 + else ok s5 + if full + then + let i3 ← msg.syscall_arg st s6 t b 2#u64 + let descriptor ← lift (i3 &&& 4294967295#u64) + let (_, s7) ← msg.set_mr st s6 t b 2#u64 descriptor + if pending + then + let s8 ← vcpu.set st s7 v vcpu.PENDING 0#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.MSG_INFO 1#u64 + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s10 layout.reg.NEXT_IP + let s11 ← + obj.Tcb.set_reg st t s10 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s11 t sched.TS_RUNNING + else + let vectoring ← + if saved + then + do + let i4 ← 27#u64 * 8#u64 + let i5 ← vcpu.EXIT + i4 + let i6 ← vcpu.get st s7 v i5 + let i7 ← 1#u64 <<< 31#i32 + let i8 ← lift (i6 &&& i7) + ok (i8 != 0#u64) + else ok false + vcpu.finish_notification st arI s7 a t b + badge vectoring + else + let s7 ← vcpu.set st s6 v vcpu.PENDING 0#u64 + let s8 ← + obj.Tcb.set_reg st t s7 layout.reg.MSG_INFO 1#u64 + let s9 ← + obj.Tcb.set_reg st t s8 layout.reg.BADGE 0#u64 + let ip1 ← obj.Tcb.reg st t s9 layout.reg.NEXT_IP + let s10 ← + obj.Tcb.set_reg st t s9 layout.reg.FAULT_IP ip1 + sched.set_thread_state st s10 t sched.TS_RUNNING + else + let s2 ← + if i = 0#u64 + then + do + let i1 ← arI.virtualization a + let flags ← + if i1 = 2#u64 + then + do + let i2 ← vcpu.svm.RFLAGS + vcpu.get st s1 v i2 + else vcpu.read_vmcs st s1 v vcpu.vmx.GUEST_RFLAGS + let int ← + if i1 = 2#u64 + then vcpu.get st s1 v vcpu.svm.INT_STATE + else + vcpu.read_vmcs st s1 v + vcpu.vmx.GUEST_INTERRUPTABILITY + let cr3 ← + if i1 = 2#u64 + then do + let i2 ← vcpu.svm.CR3 + vcpu.get st s1 v i2 + else ok 0#u64 + let cr2 ← + if i1 = 2#u64 + then do + let i2 ← vcpu.svm.CR2 + vcpu.get st s1 v i2 + else vcpu.get st s1 v vcpu.CR2 + let (_, s3) ← msg.set_mr st s1 t b 7#u64 flags + let (_, s4) ← msg.set_mr st s3 t b 8#u64 int + let (_, s5) ← msg.set_mr st s4 t b 9#u64 cr3 + let (_, s6) ← msg.set_mr st s5 t b 29#u64 cr2 + ok s6 + else ok s1 + if full + then + let i1 ← msg.syscall_arg st s2 t b 2#u64 + let descriptor ← lift (i1 &&& 4294967295#u64) + let (_, s3) ← msg.set_mr st s2 t b 2#u64 descriptor + if pending + then + let s4 ← vcpu.set st s3 v vcpu.PENDING 0#u64 + let s5 ← + obj.Tcb.set_reg st t s4 layout.reg.MSG_INFO 1#u64 + let s6 ← + obj.Tcb.set_reg st t s5 layout.reg.BADGE 0#u64 + let ip ← obj.Tcb.reg st t s6 layout.reg.NEXT_IP + let s7 ← + obj.Tcb.set_reg st t s6 layout.reg.FAULT_IP ip + sched.set_thread_state st s7 t sched.TS_RUNNING + else + let vectoring ← + if saved + then + do + let i2 ← 27#u64 * 8#u64 + let i3 ← vcpu.EXIT + i2 + let i4 ← vcpu.get st s3 v i3 + let i5 ← 1#u64 <<< 31#i32 + let i6 ← lift (i4 &&& i5) + ok (i6 != 0#u64) + else ok false + vcpu.finish_notification st arI s3 a t b + badge vectoring + else + let s3 ← vcpu.set st s2 v vcpu.PENDING 0#u64 + let s4 ← + obj.Tcb.set_reg st t s3 layout.reg.MSG_INFO 1#u64 + let s5 ← + obj.Tcb.set_reg st t s4 layout.reg.BADGE 0#u64 + let ip ← obj.Tcb.reg st t s5 layout.reg.NEXT_IP + let s6 ← + obj.Tcb.set_reg st t s5 layout.reg.FAULT_IP ip + sched.set_thread_state st s6 t sched.TS_RUNNING) ⦃ s' => ∃ (sB : S) (σB : Fl4Spec.State Unit), R sB σB ∧ + ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sB σB V AR Z H Cs Ac Lst' D s' a + (repEnd σ0 t x0 pb v vs pending saved full badge (rpTailF vs F0)) ⦄ := + J.repTailRunning hVA hr hq hb (Or.inr hrs) hv hkv hvt pending saved full hsaved hpf badge lp R hR hlp + set_option maxHeartbeats 32000000 in /-- **The tail of the report after its first loop, with a VCPU** (module docstring). -/ theorem JAtZV3.repTail (hVA : ZvVirtAgree arI) {t b v : U64} {F0 : Nat → Fl4Spec.Word} {s1 : S} diff --git a/proofs/Fl4Proofs/P3/JAtZV3Report.lean b/proofs/Fl4Proofs/P3/JAtZV3Report.lean index 5998f5ec6..7d914379c 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3Report.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3Report.lean @@ -245,7 +245,7 @@ set_option maxHeartbeats 16000000 in 42b47; the proof of `JAtZV3.setTcbCoreF`): `Q` gives `VmBase` (`hB`), `vcpu.detach` keeps `Q` paired with `vcpuDetachF` (`hDet`), and the binding writes keep it (`hBd`). `JAtZV3.setTcbCoreF` (`Q` = `JAtZV3`, the detach by `JAtZV3.detachF`) and P3/JAtZV3ReportJ3's `VmBaseF.setTcbCoreF2` (`Q` = `VmBaseF sA σA`) are its instances. -/ -theorem setTcbCoreQ {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} +theorem setTcbCoreQK {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} (hB : ∀ Ac Lst s a σ, Q Ac Lst s a σ → VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) (hDet : ∀ Ac Lst s a σ t, Q Ac Lst s a σ → Z.th t = some .tcb → vcpu.detach st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), @@ -256,7 +256,10 @@ theorem setTcbCoreQ {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec. L.mem s (vTcbA v) = 0#u64 → σ.kheap v.bv = some (.archObj (.vcpu vs)) → Q Ac Lst (L.wr (L.wr s (vTcbA v) t) (tVcpuA t) v) a (Notif.updK σ v.bv (.archObj (.vcpu { vs with tcb := some t.bv })))) - (J : Q Ac Lst s a σ) : + (J : Q Ac Lst s a σ) {R : Type} (K : S → A → Result R) {Post : R → Prop} + (hK : ∀ s' a' σ' Ac' Lst', + Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = ({((), σ')}, False) → + Q Ac' Lst' s' a' σ' → K s' a' ⦃ Post ⦄) : (do let (s3, a2) ← smp.remote_tcb_stall st arI s a t let (s4, a3) ← vcpu.detach st arI s3 a2 t @@ -267,8 +270,7 @@ theorem setTcbCoreQ {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec. let i2 ← layout.tcb.VCPU let i3 ← lift (core.num.U64.wrapping_add t i2) let s7 ← st.write s6 i3 v - ok (s7, a4)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), - Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = ({((), σ')}, False) ∧ Q Ac' Lst' r.1 r.2 σ' ⦄ := by + K s7 a4) ⦃ Post ⦄ := by have Jz := hB _ _ _ _ _ J have B := Jz.base have P := B.jwPl Jz.vm @@ -340,8 +342,35 @@ theorem setTcbCoreQ {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec. try simp only [lift, bind_ok] refine WP.spec_bind (P1.LawfulStore.write_spec _ _ _) fun s7 e7 => ?_ subst e7 - refine (WP.spec_ok _).2 ⟨_, Ac2, Lst2, by rw [hA2]; exact zv_vcpuUpdate_eq hk2 _, - hBd _ _ _ _ _ _ J2 hw0 hb0 hk2⟩ + exact hK _ _ _ Ac2 Lst2 (by rw [hA2]; exact zv_vcpuUpdate_eq hk2 _) + (hBd _ _ _ _ _ _ J2 hw0 hb0 hk2) + +theorem setTcbCoreQ {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB : ∀ Ac Lst s a σ, Q Ac Lst s a σ → VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hDet : ∀ Ac Lst s a σ t, Q Ac Lst s a σ → Z.th t = some .tcb → + vcpu.detach st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vcpuDetachF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ Q Ac' Lst' r.1 r.2 σ' ∧ + DetMem st V Z.th t s r.1 ⦄) + {t v : U64} (ht : Z.th t = some .tcb) (hv : v ∈ V) + (hBd : ∀ Ac Lst s a σ (vs : Fl4Spec.VcpuState), Q Ac Lst s a σ → L.mem s (tVcpuA t) = 0#u64 → + L.mem s (vTcbA v) = 0#u64 → σ.kheap v.bv = some (.archObj (.vcpu vs)) → + Q Ac Lst (L.wr (L.wr s (vTcbA v) t) (tVcpuA t) v) a + (Notif.updK σ v.bv (.archObj (.vcpu { vs with tcb := some t.bv })))) + (J : Q Ac Lst s a σ) : + (do + let (s3, a2) ← smp.remote_tcb_stall st arI s a t + let (s4, a3) ← vcpu.detach st arI s3 a2 t + let i1 ← vcpu.get st s4 v vcpu.TCB + let b1 ← obj.Tcb.is_null i1 + let (s5, a4) ← if b1 then ok (s4, a3) else vcpu.detach st arI s4 a3 i1 + let s6 ← vcpu.set st s5 v vcpu.TCB t + let i2 ← layout.tcb.VCPU + let i3 ← lift (core.num.U64.wrapping_add t i2) + let s7 ← st.write s6 i3 v + ok (s7, a4)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = ({((), σ')}, False) ∧ Q Ac' Lst' r.1 r.2 σ' ⦄ := + setTcbCoreQK hB hDet ht hv hBd J (fun s' a' => ok (s', a')) fun _ _ σ' Ac' Lst' h J' => + (WP.spec_ok _).2 ⟨σ', Ac', Lst', h, J'⟩ /-- **The binding core of `X86VCPUSetTCB` at `JAtZV3`, paired with `associateVcpuTcbF`**, without the `hst` / `hso` scope (module docstring). -/ diff --git a/proofs/Fl4Proofs/P3/JAtZV3ReportJ3.lean b/proofs/Fl4Proofs/P3/JAtZV3ReportJ3.lean index f2e33c411..0cb9f6f38 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3ReportJ3.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3ReportJ3.lean @@ -55,9 +55,12 @@ theorem v3_bound (s : S) (t : U64) : vcpu.bound st s t ⦃ v => v = L.mem s (tVc set_option maxHeartbeats 8000000 in /-- **The refinement part of `ReportJ3`** (module docstring). -/ -theorem VmBaseF.reportJ3M (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} +theorem VmBaseF.reportRunnableJ (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - (hrs : x.tcbState = .runningVM) (badge : U64) : + (hrs : x.tcbState = .runningVM ∨ + (x.tcbState = .running ∧ Fl4Proofs.P3.repFull x = true ∧ ∃ v vs, + Fl4Spec.tcbVcpuOf σ t.bv = some v ∧ σ.kheap v = some (.archObj (.vcpu vs)) ∧ + vs.exit.pending = false)) (badge : U64) : vcpu.report st arI s a t badge ⦃ s' => ∃ (σr : Fl4Spec.State Unit) (Lst' : U64 → List U64), Fl4Spec.vmReportF (Z := Unit) t.bv badge.bv σ = ({((), σr)}, False) ∧ VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a σr ⦄ := by @@ -95,6 +98,10 @@ theorem VmBaseF.reportJ3M (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA have hTV : Fl4Spec.tcbVcpuOf σ t.bv = none := zv_tcbVcpuOf_none fun w ws hw hwt => by obtain ⟨u, hu, -, h1, -⟩ := J.specBound hO ht hw hwt exact Jz.extv.nz u hu (h1.symm.trans h0) + have hrs : x.tcbState = .runningVM := hrs.resolve_right (by + rintro ⟨_, _, v, vs, hv, _, _⟩ + rw [hTV] at hv + cases hv) refine WP.spec_bind (Pₘ := fun p => p = false) (by rw [if_neg (by simp [hv0])]; exact (WP.spec_ok _).2 rfl) fun pending hpend => ?_ subst hpend @@ -126,11 +133,42 @@ theorem VmBaseF.reportJ3M (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA refine WP.spec_bind (lookup_buf_full s σ B.xtop.rel.2.1.1 B.xtop.rel.2.1.2.1 ht hk hOK true) fun b hb0 => ?_ have hb := hbuf b hb0 refine WP.spec_bind (J.fullReply htT hk) fun full hfull => ?_ - refine v3_ite_spec (fun hp => J.repBrB hVA htT hk hrs hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp hfull badge) - (fun hp => ?_) - have hp' : pending = false := by simpa using hp - refine v3_ite_spec (fun hf => J.repBrC2 hVA htT hk hrs hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp' hf hfull badge) - (fun hf => J.repBrA2 hVA htT hk hrs hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp' (by simpa using hf) hfull badge) + have hRun : x.tcbState = .running ∨ x.tcbState = .runningVM := by + rcases hrs with he | ⟨he, -⟩ + · exact Or.inr he + · exact Or.inl he + have hHost : x.tcbState ≠ .runningVM → pending = false ∧ full = true := by + intro hNotVM + obtain ⟨_, hf, v', vs', hv', hk', hp'⟩ := hrs.resolve_left hNotVM + rw [hTV, Option.some.injEq] at hv' + subst v' + rw [hkv, Option.some.injEq, Fl4Spec.KernelObject.archObj.injEq, + Fl4Spec.ArchKernelObj.vcpu.injEq] at hk' + subst vs' + exact ⟨hpend.trans hp', hfull.trans hf⟩ + refine v3_ite_spec (fun hp => ?_) (fun hp => ?_) + · have hrs' : x.tcbState = .runningVM := by + by_contra hNotVM + rw [(hHost hNotVM).1] at hp + cases hp + exact J.repBrB hVA htT hk hrs' hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp hfull badge + · have hp' : pending = false := by simpa using hp + refine v3_ite_spec (fun hf => ?_) (fun hf => ?_) + · exact J.repBrC2Running hVA htT hk hRun hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp' hf hfull badge + · have hrs' : x.tcbState = .runningVM := by + by_contra hNotVM + exact hf (hHost hNotVM).2 + exact J.repBrA2 hVA htT hk hrs' hb (halF b hb) hv0 hvV hkv hvt' hTV hpend hp' (by simpa using hf) hfull badge + +/-- Report after a VCPU has exited to FL4. -/ +theorem VmBaseF.reportJ3M (hVA : ZvVirtAgree arI) (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} + (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hrs : x.tcbState = .runningVM) (badge : U64) : + vcpu.report st arI s a t badge ⦃ s' => ∃ (σr : Fl4Spec.State Unit) (Lst' : U64 → List U64), + Fl4Spec.vmReportF (Z := Unit) t.bv badge.bv σ = ({((), σr)}, False) ∧ + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s' a σr ⦄ + := + J.reportRunnableJ hVA ht hk (Or.inl hrs) badge set_option maxHeartbeats 8000000 in /-- **The refinement part of `ReportJ3`** (module docstring). -/ diff --git a/proofs/Fl4Proofs/P3/JAtZV3RunVm.lean b/proofs/Fl4Proofs/P3/JAtZV3RunVm.lean index b245913cc..a39386d32 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3RunVm.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3RunVm.lean @@ -35,20 +35,29 @@ theorem v3_not_blocked_rvm : ¬ Blocked sched.TS_RUNNING_VM := fun hb => blocked /-- **`set_thread_state Running` of a `RunningVM` thread keeps `BlkOK`**, with the footprint of `set_thread_state` (as `restart_blk`). -/ -theorem sched.set_thread_state.runningVM_blk (s : S) (t : obj.Tcb) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) - (ht : t ∈ T) (hr : L.mem s (stA t) = sched.TS_RUNNING_VM) : - sched.set_thread_state st s t sched.TS_RUNNING ⦃ s' => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ +theorem sched.set_thread_state.runnable_blk (s : S) (t : obj.Tcb) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) + (ht : t ∈ T) (hr : Runnable (L.mem s (stA t))) {v : U64} (hv : Runnable v) : + sched.set_thread_state st s t v ⦃ s' => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ Foot st T Cs Sg Scs Z Es s s' ⦄ := by obtain ⟨⟨Q, R, h0⟩, hB, hX, hS, hSg⟩ := h have hnoref : ∀ r ∈ Rp, L.mem s (rTcbA r) ≠ t := - hX.noref (h0.tcbs t ht) (by rw [hr]; exact v3_rvm_ne.1) (by rw [hr]; exact v3_rvm_ne.2) - refine WP.spec_mono (WP.spec_and (sts_all s t _ Q R h0 hB hX hS hSg ht not_blocked_running running_ne - (Or.inr (by rw [hr]; exact v3_not_blocked_rvm)) hnoref - ⟨fun _ _ _ _ _ => runnable_running, fun _ _ _ => runnable_running, fun _ => runnable_running⟩) + hX.noref (h0.tcbs t ht) (runnable_ne_reply hr) (runnable_ne_recv hr) + refine WP.spec_mono (WP.spec_and (sts_all s t _ Q R h0 hB hX hS hSg ht (fun h => blocked_not_runnable h hv) + ⟨runnable_ne_reply hv, runnable_ne_recv hv⟩ + (Or.inr (fun h => blocked_not_runnable h hr)) hnoref + ⟨fun _ _ _ _ _ => hv, fun _ _ _ => hv, fun _ => hv⟩) (sched.set_thread_state.kw (Sg := Sg) (Scs := Scs) (Z := Z) (Es := Es) s t _ h0 ht)) ?_ rintro s' ⟨⟨h1, hB1, hX1, hS1, hSg1, -, -⟩, f1⟩ exact ⟨⟨⟨Q, R, h1.congrX empty_congr⟩, hB1, hX1, hS1, hSg1⟩, f1⟩ +/-- Report completion sets the running state. -/ +theorem sched.set_thread_state.runningVM_blk (s : S) (t : obj.Tcb) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s) + (ht : t ∈ T) (hr : L.mem s (stA t) = sched.TS_RUNNING_VM) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s' => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s' ∧ + Foot st T Cs Sg Scs Z Es s s' ⦄ := + sched.set_thread_state.runnable_blk s t h ht (hr.symm ▸ v3_runnable_rvm) runnable_running + + end @@ -72,11 +81,13 @@ open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proof set_option maxHeartbeats 16000000 in /-- **`set_thread_state Running` of a `RunningVM` thread at `JAtZB`** (XTopJointReply's `JAtZ.runJD`, same proof; the post adds the `TFoot` footprint). -/ -theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) : - sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), +theorem JAtZB.setRunnableVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .running ∨ x.tcbState = .runningVM) + {ts : Fl4Spec.ThreadState} {raw : U64} (hts : ts = .running ∨ ts = .runningVM) + (hcode : raw.val = Notif.tsCode ts) : + sched.set_thread_state st s t raw ⦃ s6 => ∃ (Lst' : U64 → List U64), JAtZB (L := L) arI AR Z H Cs Ac Lst' D s6 a - (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ + (stsAct (updK σ t.bv (.tcb { x with tcbState := ts })) t.bv) ∧ SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ∧ P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) ⦄ := by have hP0 := J.ip @@ -87,22 +98,32 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb t ht rw [hk] at hk0; cases hk0 have hst : (L.mem s (tStA t)).val = tsCode x.tcbState := hTR.st - have hq := IpcRel.not_ep_queued hI.1 (t := t) ⟨by rw [hst, hrs]; decide, by rw [hst, hrs]; decide⟩ + have hq := IpcRel.not_ep_queued hI.1 (t := t) ⟨by rcases hrs with hrs | hrs <;> rw [hst, hrs] <;> decide, + by rcases hrs with hrs | hrs <;> rw [hst, hrs] <;> decide⟩ have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) (c := Z.c) hP0.e have hSR := IpcRel.toSRN hI.1 hI.2 - have hr0 : L.mem s (P1.stA t) = sched.TS_RUNNING_VM := by - apply UScalar.eq_of_val_eq - rw [P1.stA_eq, ← tStA_eq, hst, hrs]; unfold sched.TS_RUNNING_VM; rfl - refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (set_thread_state_c hH hP0 hP0.e s σ hI.1.toE hSR ht - hk hq (by rw [hrs]; decide) .running (by decide) sched.TS_RUNNING (by unfold sched.TS_RUNNING; rfl)) + have rawRun (v : U64) (ts : Fl4Spec.ThreadState) (hr : ts = .running ∨ ts = .runningVM) + (hcode : v.val = tsCode ts) : P1.Runnable v := by + rcases hr with rfl | rfl + · exact Or.inl (UScalar.eq_of_val_eq (by unfold sched.TS_RUNNING tsCode at *; exact hcode)) + · exact Or.inr (Or.inr (UScalar.eq_of_val_eq (by unfold sched.TS_RUNNING_VM tsCode at *; exact hcode))) + have hOld : P1.Runnable (L.mem s (P1.stA t)) := + rawRun _ _ hrs (by rw [P1.stA_eq, ← tStA_eq]; exact hst) + have hNew := rawRun _ _ hts hcode + have hNewSpec : Fl4Spec.runnable ts = true := by rcases hts with rfl | rfl <;> rfl + have hNewFree : IpcFree ts := by + rcases hts with rfl | rfl <;> exact ⟨rfl, rfl, fun _ e => by cases e⟩ + refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (set_thread_state_cVM hH hP0 hP0.e s σ hI.1.toE hSR ht + hk hq (by rcases hrs with hrs | hrs <;> rw [hrs] <;> decide) ts + (hts.imp (fun h => by rw [h]; decide) id) raw hcode) (set_thread_state_sfoot hS ht _)) (set_thread_state_yw hS ht _)) - (P1.sched.set_thread_state.runningVM_blk (Es := P1.EH H) s t J.blk htH hr0)) ?_ + (P1.sched.set_thread_state.runnable_blk (Es := P1.EH H) s t J.blk htH hOld hNew)) ?_ rintro s6 ⟨⟨⟨⟨hR6, hS6r⟩, hw6⟩, hy6⟩, hblk, hfoot⟩ have hX6 := IpcRel.ofSRN hR6 hS6r have hDbg := J.kw_dbg hfoot have hKd := J.kw_dbgKeep hfoot - set x6 : Fl4Spec.Tcb := { x with tcbState := .running } with hx6 + set x6 : Fl4Spec.Tcb := { x with tcbState := ts } with hx6 set σ1 := updK σ t.bv (.tcb x6) with hσ1 set σ6 := stsAct σ1 t.bv with hσ6 have hrec : σ6 = { σ1 with schedulerAction := σ6.schedulerAction } := stsAct_rec σ1 t.bv @@ -121,26 +142,26 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 have e_rel : σ6.releaseQueue = σ.releaseQueue := by rw [hrec]; rfl have hW : P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) := WritesIn.tfoot_sfoot (P1.WritesIn.refl _ _) hw6 have hfx : IpcFree x.tcbState := by - rw [hrs]; exact ⟨rfl, rfl, fun _ e => by cases e⟩ + rcases hrs with hrs | hrs <;> rw [hrs] <;> exact ⟨rfl, rfl, fun _ e => by cases e⟩ have hK : ScTKw (fun p => p = t.bv) σ σ6 := by refine ⟨fun p => ?_, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, by rw [hrec]; rfl, e_ct, e_isc⟩ by_cases hp : p = t.bv · subst hp; rw [hk, hk6] show TKObj _ _ _ - exact Or.inr (Or.inl ⟨x, x6, rfl, rfl, rfl, Or.inr ⟨rfl, hfx, rfl, rfl, fun _ e => by cases e⟩⟩) + exact Or.inr (Or.inl ⟨x, x6, rfl, rfl, rfl, Or.inr ⟨rfl, hfx, hNewFree⟩⟩) · rw [hkp p hp]; exact OTK.refl _ _ have hX' : XTopAt (L := L) AR Z s6 a σ6 := xtop_sc_step J.xtop hP0 J.nk hW hK hX6.2.2.1 hX6.1.toN id -- `Inv` have hI1 : Inv σ1 := by - refine J.inv.step (NtfnStep.tcb hk .running x.tcbArch) (fun u x0 y h1 h2 _ hr => ?_) + refine J.inv.step (NtfnStep.tcb hk ts x.tcbArch) (fun u x0 y h1 h2 _ hr => ?_) (fun u x0 y h1 h2 hc => ?_) · by_cases e : u = t.bv - · subst e; rw [hk] at h1; cases h1; simp [hσ1, updK] at h2; subst h2; rfl + · subst e; rw [hk] at h1; cases h1; simp [hσ1, updK] at h2; subst h2; exact hNewSpec · have h2' : σ.kheap u = some (.tcb y) := by simpa [hσ1, updK, e] using h2 rw [h1] at h2'; cases h2'; exact hr · by_cases e : u = t.bv - · subst e; exact J.inv.rd _ x hk (Or.inl (by rw [hrs]; rfl)) + · subst e; exact J.inv.rd _ x hk (Or.inl (by rcases hrs with hrs | hrs <;> rw [hrs] <;> rfl)) · have h2' : σ.kheap u = some (.tcb y) := by simpa [hσ1, updK, e] using h2 exact J.inv.rd u y h2' hc have hInv : Inv σ6 := hI1.qchange (qchange_stsAct σ1 t.bv) @@ -151,8 +172,8 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 (YK.YKS.updTcb (y := x6) hk rfl).ykeep exact h1.frame (m' := L.mem s6) (σ' := σ6) (fun _ _ => rfl) (YKeep.of_kheap (stsAct_kheap _ _)) have hYK6 : YKeep σ σ6 := (YK.YKS.updTcb (y := x6) hk rfl).ykeep.trans (YKeep.of_kheap (stsAct_kheap _ _)) - have hsp : Fl4Spec.setThreadState (Z := Unit) t.bv .running σ = ({((), σ6)}, False) := - Notif.setThreadState_eq .running hk + have hsp : Fl4Spec.setThreadState (Z := Unit) t.bv ts σ = ({((), σ6)}, False) := + Notif.setThreadState_eq ts hk have hsok : SOK (false, true) σ σ6 := Pres.of_eq (pres_setThreadState _ _ _) hsp have hNSC : NSC Z.N Z.C σ6 := by intro n hn y p hy hp @@ -171,12 +192,12 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 have hnr6 : u ∉ σ6.releaseQueue := by rw [e_rel]; exact hnr by_cases e : u = t.bv · subst e; rw [hk] at hky; cases hky - exact schedulable_of hk6 hsc rfl hkz6 hac hnr6 + exact schedulable_of hk6 hsc hNewSpec hkz6 hac hnr6 · exact schedulable_of (by rw [hkp _ e]; exact hky) hsc hrun hkz6 hac hnr6 have hidt : σ.idleThread ≠ t.bv := by intro e obtain ⟨y, h1, -, h3, -⟩ := J.act.2 - rw [e, hk] at h1; cases h1; rw [hrs] at h3; cases h3 + rw [e, hk] at h1; cases h1; rcases hrs with hrs | hrs <;> rw [hrs] at h3 <;> cases h3 have hAI : ActIdle σ6 := by refine ⟨fun u hu => ?_, ?_⟩ · have hu0 : σ.schedulerAction = .switchThread u := by @@ -206,11 +227,7 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 fun hm => hC.notRel (by rw [e_ct, e_rel] at hm; exact hm)⟩ · by_cases hct : σ.curThread = t.bv · rw [hct, hk] at hkc; cases hkc - have hnb6 : NotIpcBlk Fl4Spec.ThreadState.running := by - refine ⟨?_, ?_, ?_⟩ - · intro _ e; cases e - · intro _ _ e; cases e - · intro _ _ _ e; cases e + have hnb6 := NotIpcBlk.of_runnable hNewSpec exact ⟨x6, by rw [e_ct, hct]; exact hk6, by rw [e_csc]; exact hcs, hnb6⟩ · exact ⟨xt, by rw [e_ct, hkp _ hct]; exact hkc, by rw [e_csc]; exact hcs, hnb⟩ · rw [e_csc, e_isc] at hne'; rw [e_csc] at hy @@ -244,7 +261,7 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 intro y hy rw [e_ct] at hy by_cases hct : σ.curThread = t.bv - · rw [hct, hk6] at hy; cases hy; rfl + · rw [hct, hk6] at hy; cases hy; exact hNewSpec · rw [hkp _ hct] at hy; exact h y hy · right; rw [e_ct, e_idle]; exact h have hlk : LK (fun _ => False) σ σ6 := fun p => Or.inr (by @@ -259,7 +276,7 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 have hfk : FK σ σ6 := ⟨e_csc, e_idle, e_isc⟩ have hdead : ∀ q ∈ D, DeadP (L := L) H s6 q := fun q hq => J.deadP_sc_stepG hX' hW hK (fun p x' hp hk' h0 y hy => by - subst hp; rw [hk] at hk'; cases hk'; rw [hrs] at h0; simp [tsCode] at h0) + subst hp; rw [hk] at hk'; cases hk'; rcases hrs with hrs | hrs <;> rw [hrs] at h0 <;> simp [tsCode] at h0) hlk hfk hAI.1 hY' (hYK6.dk q.bv) (fun h => h) (J.jcov.dead q hq) exact ⟨Lst', J.sc_frame hW hK hX' hCR' hRF' hY' hM' (J.sc_buf hW hK) hRP' (J.sc_apart hW hK) (J.sc_jpl hW hK (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).2) (J.sc_jcov hW hdead (fun q hq hn => absurd hq hn) (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2) hKd subset_rfl) (J.sc_kern hW hK hfk hX' hDbg fun _ h => h) @@ -269,16 +286,26 @@ theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 · rw [hkp _ e] at hp; exact ⟨y, hp, ha, fun _ h => h, id⟩) hcr6 hblk hKd (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).1 J.zD, J.xtop.slotsSame_of hW (fun b hb => tfoot_oobj hS hb), P1.Foot.dbgKeep J.blk (fun _ h => h) hfoot, hW⟩ +/-- A VCPU report returns a running VM thread to host execution. -/ +theorem JAtZB.runVmJD (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s6 a + (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ + SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ∧ + P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) ⦄ := + J.setRunnableVmJD ht hk (Or.inr hrs) (Or.inl rfl) (raw := sched.TS_RUNNING) (by unfold sched.TS_RUNNING tsCode; rfl) + /-- **`set_thread_state Running` of a `RunningVM` thread at `JAtZV3`** (module docstring). -/ -theorem VmBaseF.runVmJ (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) : +theorem VmBaseF.reportRunningJ (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .running ∨ x.tcbState = .runningVM) : sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ Lst' : U64 → List U64, VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s6 a (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := by have B := J.base have hS := B.xtop.fin.1.1.1 - refine WP.spec_mono (B.runVmJD ht hk hrs) fun s6 h6 => ?_ + refine WP.spec_mono (B.setRunnableVmJD ht hk hrs (Or.inl rfl) (raw := sched.TS_RUNNING) (by unfold sched.TS_RUNNING tsCode; rfl)) fun s6 h6 => ?_ obtain ⟨Lst', B', -, -, hW⟩ := h6 refine ⟨Lst', ?_⟩ have hk7 : (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv).kheap t.bv = @@ -304,6 +331,14 @@ theorem VmBaseF.runVmJ (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a exact Or.inr ⟨_, _, hk, hk7, Or.inl ⟨_, _, rfl, rfl⟩⟩ · exact Or.inl (hkp7 _ e) +/-- The VM-exit instance of the shared report proof. -/ +theorem VmBaseF.runVmJ (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst' D s6 a + (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := + J.reportRunningJ ht hk (Or.inr hrs) + /-- **`set_thread_state Running` of a `RunningVM` thread at `JAtZV3`** (module docstring). -/ theorem JAtZV3.runVmJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .runningVM) : diff --git a/proofs/Fl4Proofs/P3/JAtZV3SetTcb.lean b/proofs/Fl4Proofs/P3/JAtZV3SetTcb.lean index f8dfe35fa..009e7b9a3 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SetTcb.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SetTcb.lean @@ -93,114 +93,65 @@ theorem JAtZV3.setTcbCoreK (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = ({((), σ')}, False) ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s7 r.2.2 σ' ∧ sched.set_thread_state st s7 ct sched.TS_RESTART = ok r.2.1 ⦄ := by - have Jz := J.z2.zv - have B := Jz.base - have P := B.jwPl Jz.vm - have hS := B.xtop.fin.1.1.1 - have hv0 : v ≠ 0#u64 := Jz.extv.nz v hv - have JWt : JW V Z.th (tVcpuA t) := Or.inr (Or.inl ⟨t, ht, rfl⟩) - refine WP.spec_bind (Sched.remote_tcb_stall_id (ar := arI) a hS (B.thT t ht)) ?_ - rintro ⟨s3, a2⟩ e - try simp only [uncurry_apply_pair] - simp only [Prod.mk.injEq] at e - obtain ⟨e1, e2⟩ := e - subst s3 - subst a2 - refine WP.spec_bind (J.detachF hK hR ht) ?_ - rintro ⟨s4, a3⟩ ⟨σ1, Ac1, Lst1, hD1, J1, DM1⟩ - try simp only [uncurry_apply_pair] - obtain ⟨vs1, hk1, hb1⟩ := J1.z2.vb v hv - unfold vcpu.get - simp only [lift, bind_ok] - refine WP.spec_bind (P1.LawfulStore.read_spec s4 _) fun i1 ei1 => ?_ - have ei1' : i1 = L.mem s4 (vTcbA v) := ei1 - refine WP.spec_bind (P1.obj.Tcb.is_null.spec i1) fun b1 eb1 => ?_ - refine WP.spec_bind (Pₘ := fun r => ∃ (σ2 : Fl4Spec.State Unit) (Ac2 : Set U64) (Lst2 : U64 → List U64), - Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = - Fl4Spec.vcpuUpdate (Z := Unit) v.bv (fun x : Fl4Spec.VcpuState => { x with tcb := some t.bv }) σ2 ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac2 Lst2 D r.1 r.2 σ2 ∧ L.mem r.1 (tVcpuA t) = 0#u64 ∧ - L.mem r.1 (vTcbA v) = 0#u64) ?_ ?_ - · split - · rename_i hb - have hi0 : i1 = 0#u64 := by rw [eb1] at hb; simpa using hb - have hm0 : L.mem s4 (vTcbA v) = 0#u64 := ei1'.symm.trans hi0 - have htc : Fl4Spec.VcpuState.tcb vs1 = none := by - rcases hb1 with ⟨h, -⟩ | ⟨o, ho0, -, hm⟩ - · exact h - · exact absurd (hm.symm.trans hm0) ho0 - refine (WP.spec_ok _).2 ⟨σ1, Ac1, Lst1, ?_, J1, DM1.w0, hm0⟩ - unfold Fl4Spec.associateVcpuTcbF - rw [Notif.nd_bind_one hD1, Notif.nd_bind_one (zv_getVcpu_eq hk1), htc] - try exact Notif.nd_pure_bind' _ _ _ - · rename_i hb - have hi0 : i1 ≠ 0#u64 := by rw [eb1] at hb; simpa using hb - obtain ⟨o, ho0, htc, hm⟩ : ∃ o : U64, o ≠ 0#u64 ∧ Fl4Spec.VcpuState.tcb vs1 = some o.bv ∧ - L.mem s4 (vTcbA v) = o := by - rcases hb1 with ⟨-, h⟩ | h - · exact absurd (ei1'.trans h) hi0 - · exact h - have eio : o = i1 := (ei1'.trans hm).symm - rw [eio] at ho0 htc hm - obtain ⟨hto, hov⟩ := (J1.z2.zv.extv.back v hv).resolve_left (by rw [hm]; exact ho0) - rw [hm] at hto hov - have hne : t ≠ i1 := fun e => hv0 (by rw [← hov, ← e]; exact DM1.w0) - refine WP.spec_mono (J1.detachF hK hR hto) ?_ - rintro ⟨s5, a4⟩ ⟨σ2, Ac2, Lst2, hD2, J2, DM2⟩ - refine ⟨σ2, Ac2, Lst2, ?_, J2, ?_, ?_⟩ - · unfold Fl4Spec.associateVcpuTcbF - rw [Notif.nd_bind_one hD1, Notif.nd_bind_one (zv_getVcpu_eq hk1), htc] - exact Notif.nd_bind_one hD2 _ - · rw [DM2.keep _ JWt (fun e => hne (tVcpuA_inj e)) (fun w hw _ => P.vb t ht w hw)] - exact DM1.w0 - · exact DM2.b0 v hv hov - rintro ⟨s5, a4⟩ ⟨σ2, Ac2, Lst2, hA2, J2, hw0, hb0⟩ - try simp only [uncurry_apply_pair] - obtain ⟨vs2, hk2, -⟩ := J2.z2.vb v hv - simp only [vcpu.set, lift, bind_ok] - refine WP.spec_bind (P1.LawfulStore.write_spec s5 _ _) fun s6 e6 => ?_ - subst e6 - step as ⟨o2, ho2⟩ - subst ho2 - try simp only [lift, bind_ok] - refine WP.spec_bind (P1.LawfulStore.write_spec _ _ _) fun s7 e7 => ?_ + refine setTcbCoreQK (Q := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun _ _ _ _ _ h => h.toB) (fun _ _ _ _ _ _ h ht => h.detachF hK hR ht) ht hv + (fun _ _ _ _ _ vs h h0 h1 hk => h.bind ht hv h0 h1 hk { vs with tcb := some t.bv } rfl) J _ ?_ + intro s7 a4 σ' Ac' Lst' hA J' obtain ⟨s8, h8, -⟩ := P1.spec_ex_fd (P0.sched.set_thread_state.p0 st s7 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) rw [h8, bind_ok, WP.spec_ok] - refine ⟨_, Ac2, Lst2, s7, rfl, by rw [hA2]; exact zv_vcpuUpdate_eq hk2 _, ?_, h8⟩ - rw [e7] - exact J2.bind ht hv hw0 hb0 hk2 { vs2 with tcb := some t.bv } rfl + exact ⟨σ', Ac', Lst', s7, rfl, hA, J', h8⟩ set_option maxHeartbeats 16000000 in /-- **X86VCPUSetTCB at `JAtZV3`, paired with the spec's decode and FL4's perform** (module docstring). -/ -theorem JAtZV3.setTcbJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) {p : U64} (hp : p ∈ V) +theorem VmBase.setTcbJ + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) (hA : P0.ArchTotal arI) + (hK : ARKeep arI AR) {p : U64} (hp : p ∈ V) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (len : U64) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) {sl : obj.Slot} {b : Bool} (hsl : Array.index_usize ex 0#usize = ok sl) (hb : obj.Slot.is_null sl = ok b) {c : capability.Cap} - (hc : b = false → obj.Slot.cap st sl s = ok c) (hct : ∀ t, c = .Thread t → Z.th t = some .tcb) : + (hc : b = false → obj.Slot.cap st sl s = ok c) (hCore : ∀ t a' ct, b = false → c = .Thread t → Q Ac Lst s a' σ → + (do + let (s3, a2) ← smp.remote_tcb_stall st arI s a' t + let (s4, a3) ← vcpu.detach st arI s3 a2 t + let i1 ← vcpu.get st s4 p vcpu.TCB + let b1 ← obj.Tcb.is_null i1 + let (s5, a4) ← if b1 then ok (s4, a3) else vcpu.detach st arI s4 a3 i1 + let s6 ← vcpu.set st s5 p vcpu.TCB t + let i2 ← layout.tcb.VCPU + let i3 ← lift (core.num.U64.wrapping_add t i2) + let s7 ← st.write s6 i3 p + let s8 ← sched.set_thread_state st s7 ct sched.TS_RESTART + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s8, a4)) ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) + (Lst' : U64 → List U64) (s7 : S), r.1 = .Ok () ∧ + Fl4Spec.associateVcpuTcbF (Z := Unit) p.bv t.bv σ = ({((), σ')}, False) ∧ + Q Ac' Lst' s7 r.2.2 σ' ∧ + sched.set_thread_state st s7 ct sched.TS_RESTART = ok r.2.1 ⦄) : vcpu.decode st arI s a fl4_abi.label.X86VCPUSetTCB len p call buf ex ⦃ r => ∃ ct : U64, sched.cur_thread st s = ok ct ∧ ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), StcbCaps b c ec → (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = Fl4Spec.NonDetE.throwError e' ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + r.2.1 = s ∧ Q Ac Lst s r.2.2 σ) ∨ (∃ (t : U64) (s7 : S) (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), r.1 = .Ok () ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = Fl4Spec.NonDetE.returnOk (.setTcb p.bv t.bv) ∧ Fl4Spec.performVcpuInvocationF (Z := Unit) (.setTcb p.bv t.bv) σ = ({([], σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s7 r.2.2 σ' ∧ + Q Ac' Lst' s7 r.2.2 σ' ∧ sched.set_thread_state st s7 ct sched.TS_RESTART = ok r.2.1) ⦄ := by - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct', -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct', bind_ok] obtain ⟨i, hi, -⟩ := P1.spec_ex_fd (hA.virtualization_spec a1) @@ -235,13 +186,13 @@ theorem JAtZV3.setTcbJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = Fl4Spec.NonDetE.throwError e' ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + r.2.1 = s ∧ Q Ac Lst s r.2.2 σ) ∨ (∃ (t : U64) (s7 : S) (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), r.1 = .Ok () ∧ Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = Fl4Spec.NonDetE.returnOk (.setTcb p.bv t.bv) ∧ Fl4Spec.performVcpuInvocationF (Z := Unit) (.setTcb p.bv t.bv) σ = ({([], σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s7 r.2.2 σ' ∧ + Q Ac' Lst' s7 r.2.2 σ' ∧ sched.set_thread_state st s7 ct' sched.TS_RESTART = ok r.2.1) ⦄ := by intro hnt simp only [error.illegal, bind_ok, WP.spec_ok] @@ -252,9 +203,8 @@ theorem JAtZV3.setTcbJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) · rw [hec, zv_stcb_bv, zv_decode_stcb_ill args p.bv hcr] cases c case Thread ptr => - have hth := hct ptr rfl dsimp only - refine WP.spec_mono (J1.setTcbCoreK hK (v3_reportJ3All hA hVA V X AR Z H Cs D) hth hp ct) ?_ + refine WP.spec_mono (hCore ptr a1 ct rfl rfl J1) ?_ rintro r ⟨σ', Ac', Lst', s7, hr1, hD, J7, h8⟩ refine ⟨ct, rfl, fun args ec hE => Or.inr ⟨ptr, s7, σ', Ac', Lst', hr1, ?_, zv_perform_stcbF hD, J7, h8⟩⟩ obtain ⟨cr, cp, rest, hec, hrel⟩ := hE.2 rfl @@ -264,6 +214,29 @@ theorem JAtZV3.setTcbJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) · exact absurd rfl (hnt ptr) all_goals (dsimp only; exact ILL (fun t e => by cases e)) +set_option maxHeartbeats 4000000 in +/-- **X86VCPUSetTCB at `JAtZV3`, paired with the spec's decode and FL4's perform** (module docstring). -/ +theorem JAtZV3.setTcbJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) {p : U64} (hp : p ∈ V) + (len : U64) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) {sl : obj.Slot} {b : Bool} + (hsl : Array.index_usize ex 0#usize = ok sl) (hb : obj.Slot.is_null sl = ok b) {c : capability.Cap} + (hc : b = false → obj.Slot.cap st sl s = ok c) (hct : ∀ t, c = .Thread t → Z.th t = some .tcb) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUSetTCB len p call buf ex ⦃ r => ∃ ct : U64, + sched.cur_thread st s = ok ct ∧ + ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), StcbCaps b c ec → + (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ + Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = + Fl4Spec.NonDetE.throwError e' ∧ + r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + (∃ (t : U64) (s7 : S) (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), r.1 = .Ok () ∧ + Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUSetTCB.bv args p.bv ec = + Fl4Spec.NonDetE.returnOk (.setTcb p.bv t.bv) ∧ + Fl4Spec.performVcpuInvocationF (Z := Unit) (.setTcb p.bv t.bv) σ = ({([], σ')}, False) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s7 r.2.2 σ' ∧ + sched.set_thread_state st s7 ct sched.TS_RESTART = ok r.2.1) ⦄ := + J.toB.setTcbJ (Q := fun Ac' Lst' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D) hA hK hp (fun _ h => J.archV h) len call buf ex hsl hb hc + (fun t _ ct _ hcap J' => J'.setTcbCoreK hK (v3_reportJ3All hA hVA V X AR Z H Cs D) (hct t hcap) hp ct) + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3SigComp.lean b/proofs/Fl4Proofs/P3/JAtZV3SigComp.lean index 28a38ec73..ce2d4f1df 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SigComp.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SigComp.lean @@ -14,6 +14,9 @@ extended spec's `sendSignalVF` (Fl4Spec/Ext/VirtReport: on x86 FL4's `send_signa t`), `v3_kick` (`kick_guest` writes nothing and keeps `AR`, by `ARKeep.send_reschedule`). No premise beyond those named in each statement ([P] `ARKeep`); no existing statement changed. + +(mmuAD gen 42b71, ruling (c2) item 2) **`VmBase.sigCompR`** and **`JAtZB.repKh`**: `sigCompR` / `repKh` over the +shared record (`VmBase`, P3/JAtZV3) resp. the base; the `JAtZV3` names their corollaries, statements unchanged. -/ import Fl4Proofs.P3.JAtZV3Check open Aeneas Aeneas.Std Result @@ -139,13 +142,13 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} set_option maxHeartbeats 4000000 in -/-- **The spec's report changes only the thread and a VCPU object; the thread ends `running`** (module docstring). -/ -theorem JAtZV3.repKh (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} +/-- **The spec's report changes only the thread and a VCPU object; the thread ends `running`** (module docstring). +(mmuAD gen 42b71) At a `JAtZB` state (only the base is read); `JAtZV3.repKh` its corollary. -/ +theorem JAtZB.repKh (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {b : Fl4Spec.Word} {σr : Fl4Spec.State Unit} (hr : Fl4Spec.vmReportF (Z := Unit) t.bv b σ = ({((), σr)}, False)) : (∀ o, o ≠ t.bv → (∀ vs, σ.kheap o ≠ some (.archObj (.vcpu vs))) → σr.kheap o = σ.kheap o) ∧ (∃ y, σr.kheap t.bv = some (.tcb y) ∧ y.tcbState = .running) ∧ σr.domainTime = σ.domainTime := by - have B := J.z2.zv.base have htT := B.thT t ht have hOK := B.bok have hBC := bufCover_of_frameCover (T := Z.T) B.bok B.fcov @@ -185,6 +188,14 @@ theorem JAtZV3.repKh (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t exact v3_jMrSt_kh _ _ _ _ _ ho · exact v3_jMrSt_kh _ _ _ _ _ ho +/-- `JAtZB.repKh` at `JAtZV3` (statement unchanged). -/ +theorem JAtZV3.repKh (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} + (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {b : Fl4Spec.Word} + {σr : Fl4Spec.State Unit} (hr : Fl4Spec.vmReportF (Z := Unit) t.bv b σ = ({((), σr)}, False)) : + (∀ o, o ≠ t.bv → (∀ vs, σ.kheap o ≠ some (.archObj (.vcpu vs))) → σr.kheap o = σ.kheap o) ∧ + (∃ y, σr.kheap t.bv = some (.tcb y) ∧ y.tcbState = .running) ∧ σr.domainTime = σ.domainTime := + J.z2.zv.base.repKh ht hk hr + /-- FL4's tail of `send_signal` after `vcpu::report` (verbatim from the extracted `send_signal`; since FL4 #114 the sporadic `unblock_check` is skipped for a thread in the release queue, `sched.in_release_queue`). -/ def sigVmTailF (st : machine.Store S) (arI : machine.Arch A) (s1 : S) (a : A) (i : obj.Tcb) (n_ptr : U64) : @@ -239,13 +250,13 @@ theorem v3_kick (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) {c : Fl4Spec.Cr3} set_option maxHeartbeats 8000000 in /-- **FL4's `signal_completes` is the spec's `vmSignalCompletes` with the oracles read off FL4's state** (module -docstring). -/ -theorem JAtZV3.sigCompR (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} +docstring). (mmuAD gen 42b71) At a `VmBase` state (the fields read are the shared record's); `JAtZV3.sigCompR` its +corollary. -/ +theorem VmBase.sigCompR (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) : vcpu.signal_completes st s t ⦃ b => Fl4Spec.vmSignalCompletes (Z := Unit) (v3OnCore st s) (v3RemCur st s) t.bv σ = ({(b, σ)}, False) ⦄ := by - have Jz := J.z2.zv - have B := Jz.base + have B := J.base have hO := J.vo have htT := B.thT t ht unfold vcpu.signal_completes @@ -254,27 +265,27 @@ theorem JAtZV3.sigCompR (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) by_cases hv0 : v = 0#u64 · have h0 : L.mem s (tVcpuA t) = 0#u64 := ev'.symm.trans hv0 have hTV : Fl4Spec.tcbVcpuOf σ t.bv = none := zv_tcbVcpuOf_none fun w ws hw hwt => by - obtain ⟨u, hu, -, h1, -⟩ := J.z2.specBound hO ht hw hwt - exact Jz.extv.nz u hu (h1.symm.trans h0) + obtain ⟨u, hu, -, h1, -⟩ := J.specBound hO ht hw hwt + exact J.extv.nz u hu (h1.symm.trans h0) rw [if_neg (by simp [hv0])] exact (WP.spec_ok _).2 (v3_sigComp_none _ _ hTV) have hne0 : L.mem s (tVcpuA t) ≠ 0#u64 := fun h => hv0 (ev'.trans h) - obtain ⟨hvV, hvt⟩ := (Jz.extv.bnd t ht).resolve_left hne0 + obtain ⟨hvV, hvt⟩ := (J.extv.bnd t ht).resolve_left hne0 rw [← ev'] at hvV hvt - obtain ⟨vs, hkv, hbv⟩ := J.z2.vb v hvV + obtain ⟨vs, hkv, hbv⟩ := J.vb v hvV have hvs : Fl4Spec.VcpuState.tcb vs = some t.bv := by rcases hbv with ⟨-, h0⟩ | ⟨t', -, h1, h2⟩ · have e : t = 0#u64 := hvt.symm.trans h0 subst e - exact absurd ht (B.detPl Jz.vm).h0 + exact absurd ht (B.detPl J.vm).h0 · have e : t' = t := h2.symm.trans hvt rw [h1, e] have hTV : Fl4Spec.tcbVcpuOf σ t.bv = some v.bv := zv_tcbVcpuOf_eq hkv hvs fun w ws hw hwt => by - obtain ⟨u, hu, rfl, h1, -⟩ := J.z2.specBound hO ht hw hwt + obtain ⟨u, hu, rfl, h1, -⟩ := J.specBound hO ht hw hwt rw [← h1, ← ev'] have hS := v3_sigComp_some (v3OnCore st s) (v3RemCur st s) hk hTV hkv rw [if_pos (by simp [hv0]), v3_get_eq, bind_ok] - have hpd := J.rdPend hvV hkv + have hpd := J.toF.rdPend hvV hkv by_cases hp : vs.exit.pending = true · have hi : ¬ L.mem s (core.num.U64.wrapping_add v vcpu.PENDING) = 0#u64 := by intro e; rw [e, hp] at hpd; simp at hpd @@ -297,7 +308,7 @@ theorem JAtZV3.sigCompR (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) rw [hS] simp [hp', hon, hcc] rw [if_neg hcc] - refine WP.spec_bind (v3_full_reply J htT hk) fun full hfull => ?_ + refine WP.spec_bind (J.fullReply htT hk) fun full hfull => ?_ subst hfull cases hf : Fl4Proofs.P3.repFull x with | false => @@ -324,6 +335,13 @@ theorem JAtZV3.sigCompR (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) · rw [decide_eq_false e, show (i2 != t) = true from bne_iff_ne.mpr e]; decide rw [hS, key] + +/-- `VmBase.sigCompR` at `JAtZV3` (statement unchanged). -/ +theorem JAtZV3.sigCompR (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t : U64} + (ht : Z.th t = some .tcb) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) : + vcpu.signal_completes st s t ⦃ b => + Fl4Spec.vmSignalCompletes (Z := Unit) (v3OnCore st s) (v3RemCur st s) t.bv σ = ({(b, σ)}, False) ⦄ := + J.toB.sigCompR ht hk end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3SigDon.lean b/proofs/Fl4Proofs/P3/JAtZV3SigDon.lean index 8f5e32d8d..b186a9a19 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SigDon.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SigDon.lean @@ -34,6 +34,9 @@ Premise diff: [J] `SigVmDonJ3` (gen 42a) discharged (the def stays); nothing add (mmuAD gen 42b18) Removed (the originals are stated over `JAtZB` in place, the `JAtZ` names their corollaries with `ext` rebuilt): P3/ScSignalDonJ `wake_postD`. + +(mmuAD gen 42b71, ruling (c2) item 2) **`sigVmDonG`**: the donation over any such `P` (`JAtZB.donJ` with `hTK`); +`sigVmDonJ3_of` its corollary, statement unchanged. -/ import Fl4Proofs.P3.JAtZV3SigTail import Fl4Proofs.P3.ScSignalDonJ @@ -171,15 +174,40 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} -/-- **Gen 42a's [J] `SigVmDonJ3`, proved** (module docstring), from the platform's totality and `MIN_BUDGET`. -/ -theorem sigVmDonJ3_of (hAT : P0.ArchTotal arI) +/-- (mmuAD gen 42b71, ruling (c2) item 2) **The donation over any VM-epoch record `P`** with a `JAtZB` base (`hB0`) +kept by an SC-code step (`hTK`): `SigVmDonJ3`'s statement at `P`, by `JAtZB.donJ`. -/ +theorem sigVmDonG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB0 : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → JAtZB (L := L) arI AR Z H Cs Ac' Lst' D s' a' σ') + (hTK : ∀ {Ac1 : Set U64} {Lst1 : U64 → List U64} {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} {Ac2 : Set U64} + {Lst2 : U64 → List U64} {s2 : S} {a2 : A} {σ2 : Fl4Spec.State Unit}, + P Ac1 Lst1 s1 a1 σ1 → JAtZB (L := L) arI AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P1.WritesIn st s1 s2 (Sched.TFoot st Z.T Z.N Z.C Z.c s1 σ1) → Sched.ScTKw (fun _ => False) σ1 σ2 → + P Ac2 Lst2 s2 a2 σ2) + (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) : - SigVmDonJ3 st arI V X AR Z H Cs D := by + ∀ (Ac : Set U64) (Lst : U64 → List U64) (s1 : S) (a : A) (σr : Fl4Spec.State Unit) (t n : U64), + P Ac Lst s1 a σr → Z.th t = some .tcb → n ∈ Z.N → + (∃ x, σr.kheap t.bv = some (.tcb x) ∧ x.tcbState = .running ∧ x.tcbSchedContext = none) → + (∃ y p yc k, σr.kheap n.bv = some (.notification y) ∧ y.ntfnObj = .idleNtfn ∧ y.ntfnBoundTcb = some t.bv ∧ + y.ntfnSc = some p ∧ σr.kheap p = some (.schedContext yc k) ∧ yc.scTcb = none) → + notification.maybe_donate_sched_context st arI s1 a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) + (Lst' : U64 → List U64), Fl4Spec.maybeDonateSc (Z := Unit) t.bv n.bv σr = ({((), σ')}, False) ∧ + σ'.domainTime = σr.domainTime ∧ P Ac' Lst' r.1 r.2 σ' ⦄ := by intro Ac Lst s1 a σr t n J hth hn hrun _ obtain ⟨x, hk, hxr, hx0⟩ := hrun - refine WP.spec_mono (J.donJ3 hAT hmb (J.z2.zv.base.thT t hth) hn hk hxr hx0) ?_ - rintro r ⟨σ', he, hdt, J'⟩ - exact ⟨σ', Ac, Lst, he, hdt, J'⟩ + refine WP.spec_mono ((hB0 J).donJ hAT hmb ((hB0 J).thT t hth) hn hk hxr hx0) ?_ + rintro r ⟨ha, σ', he, hdt, hK, hW, B'⟩ + rw [ha] + exact ⟨σ', Ac, Lst, he, hdt, hTK J B' hW hK⟩ + +/-- **Gen 42a's [J] `SigVmDonJ3`, proved** (module docstring), from the platform's totality and `MIN_BUDGET`. +(mmuAD gen 42b71) `sigVmDonG` at `JAtZV3`, statement unchanged. -/ +theorem sigVmDonJ3_of (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) : + SigVmDonJ3 st arI V X AR Z H Cs D := + sigVmDonG (P := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun J' => J'.z2.zv.base) (fun J1 B2 hw hK => J1.ofTK B2 hw hK) hAT hmb set_option maxHeartbeats 4000000 in /-- **`send_signal` to an idle notification bound to a `RunningVM` thread at `JAtZV3`, with no [J]** diff --git a/proofs/Fl4Proofs/P3/JAtZV3SigTail.lean b/proofs/Fl4Proofs/P3/JAtZV3SigTail.lean index 7d5db933f..c149eb2b3 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SigTail.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SigTail.lean @@ -32,6 +32,11 @@ ready sporadic SC unsorts the release queue). With #114 on both sides that shape Premise diff: `SigVmTailJ3` [J] (gen 35) is now derived from the narrower **`SigVmDonJ3`** [J]; nothing else. No existing statement changed by this module. + +(mmuAD gen 42b71, ruling (c2) item 2) **`sigSporG`**, **`sigRestG`**, **`sigVmTailG`**: `sigSporJ` / `sigRestJ` / +`sigVmTailJ3_of` over any VM-epoch record `P` with a `JAtZB` base kept by an SC-code step (`hTK`; the switch by +`JAtZB.switchJc` with its `TFoot` writes and `nkt_possibleSwitchTo`); the `JAtZV3` names their corollaries, statements +unchanged. -/ import Fl4Proofs.P3.JAtZV3SigVm import Fl4Proofs.P3.JAtZV3SwitchC @@ -202,9 +207,9 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} -set_option maxHeartbeats 4000000 in /-- **`unblock_check` at `JAtZB` for a thread in no release queue** (module docstring; P3/XTopJointUnblock's -`JAtZ.unblockJ` with `t ∉ releaseQueue` for `Inactive`, the post extended). -/ +`JAtZ.unblockJ` with `t ∉ releaseQueue` for `Inactive`, the post extended). (mmuAD gen 42b67) A corollary of +P3/XTopJointSendRecv's `JAtZB.unblockRJ` (its twin, restated there over `JAtZB` with this post's facts). -/ theorem JAtZB.unblockJR (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hnq : t.bv ∉ σ.releaseQueue) {p : U64} (hp : p ∈ Z.C) (hxsc : x.tcbSchedContext = some p.bv) (hpc : p.bv ≠ σ.curSc) @@ -213,125 +218,32 @@ theorem JAtZB.unblockJR (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : sporadic.unblock_check st s p ⦃ s' => ∃ σ', Fl4Spec.refillUnblockCheck (Z := Unit) p.bv σ = ({((), σ')}, False) ∧ (∀ q, q ≠ p.bv → σ'.kheap q = σ.kheap q) ∧ σ'.domainTime = σ.domainTime ∧ ScTKw (fun _ => False) σ σ' ∧ P1.WritesIn st s s' (TFoot st Z.T Z.N Z.C Z.c s σ) ∧ - ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := by - have hX := J.xtop - have hS := hX.fin.1.1.1 - have hR : NtfnStateRel Z.N Z.T (L.mem s) σ := hX.fin.1.1.2.2.1 - obtain ⟨Q, R0, hc, hs⟩ := hS.lists - obtain ⟨xt, hkt, -, -, hsct, -⟩ := hs.tcb t ht - rw [hk] at hkt; cases hkt - have h0 : L.mem s (scA t) ≠ 0#u64 := (Notif.optRef_some (hsct.symm.trans hxsc)).1 - have hst : L.mem s (scA t) = p := P1.eq_of_bv (Notif.optRef_some (hsct.symm.trans hxsc)).2 - obtain ⟨y', n', hky', hy'⟩ := hs.scs p hp - rw [hky] at hky'; cases hky' - have hmx : (L.rmax s p).val ≠ 0 := hy'.rmax_ne hya - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - obtain ⟨⟨Q1, R1, hq1⟩, hB, hXi, hSc, hSg⟩ := J.blk - obtain ⟨hiS, -, -⟩ := hXi.2.2.bound t htH h0 - rw [hst] at hiS - have hiA : p ∈ Ac := (hSc.act _ hiS).2 (fun e => hmx (by rw [e]; rfl)) - have hp0 : p ≠ 0#u64 := fun e => h0 (by rw [hst]; exact e) - refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (unblock_check_refines s σ hS hp hmx) - (unblock_check_kfoot hS hp hmx)) - (Fl4Proofs.P1.sporadic.unblock_check.all s t p hq1 hB hXi hSc hSg htH hst.symm hp0 hiA)) - (Fl4Proofs.P1.sporadic.unblock_check.kw (Es := P1.EH H) s t p hq1 hB hXi hSc hSg htH hst.symm hp0 hiA)) ?_ - rintro s' ⟨⟨⟨⟨σ', he, hfe, hkv, hS'⟩, hw⟩, hq2, hB2, hX2, hS2, hSg2, -⟩, hfoot⟩ - have mem : ((), σ') ∈ (Fl4Spec.refillUnblockCheck (Z := Unit) p.bv σ).1 := by rw [he]; exact Set.mem_singleton _ - have hne : y.scRefills ≠ [] := J.inv.ne _ y n hky hya - have hF : (∀ q, q ≠ p.bv → σ'.kheap q = σ.kheap q) ∧ σ'.curThread = σ.curThread ∧ σ'.curSc = σ.curSc ∧ - σ'.curTime = σ.curTime ∧ σ'.consumedTime = σ.consumedTime ∧ σ'.releaseQueue = σ.releaseQueue ∧ - σ'.idleThread = σ.idleThread ∧ σ'.schedulerAction = σ.schedulerAction ∧ - ∃ z, σ'.kheap p.bv = some (.schedContext z n) := by - rcases unblock_result hky hne mem with ⟨rfl, -⟩ | ⟨z, rfl, -, -, -, -⟩ - · exact ⟨fun _ _ => rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, y, hky⟩ - · exact ⟨fun q hq => by simp [updK, hq], rfl, rfl, rfl, rfl, rfl, rfl, rfl, z, by simp [updK]⟩ - obtain ⟨hkp, e_ct, e_csc, e_tm, e_cons, e_rel, e_idle, e_act, z, hkz⟩ := hF - have e_dt : σ'.domainTime = σ.domainTime := by - rcases unblock_result hky hne mem with ⟨rfl, -⟩ | ⟨z, rfl, -⟩ - · rfl - · rfl - -- the spec frame - have hK0 : ScTKw (fun _ => False) σ σ' := nkt_refillUnblockCheck p.bv σ _ mem - have hK : ScTKw (fun q => q = t.bv) σ σ' := hK0.ofFalse - have hL : LK (fun _ => False) σ σ' := lkm_refillUnblockCheck p.bv σ _ mem - have hFK : FK σ σ' := ⟨e_csc, e_idle, hK0.isc⟩ - have hsok : SOK (true, true) σ σ' := pres_refillUnblockCheck (f := (true, true)) p.bv σ _ mem - have hBK : BK σ σ' := bkm_of (nkt_refillUnblockCheck _) (MaxK.mk_refillUnblockCheck' _) σ _ mem - have hwT := WritesIn.tfoot_of_kfoot hw - have hR' : NtfnStateRel Z.N Z.T (L.mem s') σ' := hR.frame hS.placed hfe hkv - have hX' : XTopAt (L := L) AR Z s' a σ' := xtop_sc_step hX J.ip J.nk hwT hK hS' hR' id - have hN' : NSC Z.N Z.C σ' := nsc_of_lk J.nsc hK hL - -- the invariant: the only thread bound to `p` is `t`, `Inactive`, so in no release queue - have hI' : Inv σ' := by - refine J.inv.unblock hky hne (fun _ _ u hu xu hku hsu => ?_) mem - obtain ⟨y1, n1, hk1, hyt1⟩ := J.inv.back u xu p.bv hku hsu - obtain ⟨y2, n2, hk2, hyt2⟩ := J.inv.back t.bv x p.bv hk hxsc - rw [hk1] at hk2; cases hk2 - have hut : u = t.bv := Option.some.inj (hyt1.symm.trans hyt2) - subst hut - exact hnq hu - obtain ⟨-, hY', hM', ⟨Lst', hCR', hRF'⟩, hRP', -⟩ := - ScAll.of_k hS J.rp J.yld J.mcp J.call J.rfree ⟨⟨hS', hR', hN', hI'⟩, hw, hsok⟩ - -- the current thread's facts: only the SC at `p ≠ curSc` changes - have hkcs : σ'.kheap σ'.curSc = σ.kheap σ.curSc := by rw [e_csc]; exact hkp _ (Ne.symm hpc) - have htk : ∀ q xq, σ'.kheap q = some (.tcb xq) → σ.kheap q = some (.tcb xq) := by - intro q xq h - by_cases e : q = p.bv - · rw [e, hkz] at h; cases h - · rwa [hkp q e] at h - have htk' : ∀ q xq, σ.kheap q = some (.tcb xq) → σ'.kheap q = some (.tcb xq) := by - intro q xq h - by_cases e : q = p.bv - · rw [e, hky] at h; cases h - · rwa [hkp q e] - have hC' : σ'.schedulerAction = .chooseNewThread ∨ CurInv σ' := by - rcases J.cur with e | hC - · left; rw [e_act]; exact e - · right - obtain ⟨xc, hkc, hcs, hnb⟩ := hC.tcb - refine ⟨⟨xc, by rw [e_ct]; exact htk' _ _ hkc, by rw [e_csc]; exact hcs, hnb⟩, ?_, ?_, ?_⟩ - · rw [hkcs]; exact hC.sc - · intro hne' y2 n2 hy; rw [hkcs] at hy; rw [e_csc, hK0.isc] at hne'; exact hC.active hne' y2 n2 hy - · rw [e_ct, e_rel]; exact hC.notRel - have hown' : CurOwnW Z.T Z.C σ' := by - rcases J.own with ⟨u, hu, xu, hku, hxs, hown, hnr⟩ | ⟨hcs, hun⟩ - · exact Or.inl ⟨u, hu, xu, htk' _ _ hku, by rw [e_csc]; exact hxs, - fun y1 n1 hy => hown y1 n1 (by rw [← hkcs]; exact hy), by rw [e_cons, e_rel]; exact hnr⟩ - · exact Or.inr ⟨by rw [e_csc]; exact hcs, fun y1 n1 hy => hun y1 n1 (by rw [← hkcs]; exact hy)⟩ - have hoff : OffOK σ' := by - intro h0' y1 n1 hy ha - rw [e_cons] at h0' ⊢; rw [e_tm]; rw [hkcs] at hy; rw [e_csc, hK0.isc] at ha - exact J.off h0' y1 n1 hy ha - have hAI : ActIdle σ' := J.act.unblock hky hne mem - have hcr : CurRunM σ' := by - rcases J.curRun with h | h - · left; rw [e_act]; exact h - · right - rcases h with h | h - · left; intro y1 hy; rw [e_ct] at hy; exact h y1 (htk _ _ hy) - · right; rw [e_ct, e_idle]; exact h - have hdead : ∀ q ∈ D, DeadP (L := L) H s' q := fun q hq => - J.deadP_sc_stepQ hX' hwT hK0 (fun _ hp => hp.elim) hL hFK hAI.1 hY' ((hsok.ykeep rfl).dk q.bv) (fun h => h) (J.jcov.dead q hq) - have hDbg := J.kw_dbg hfoot - have hKd := J.kw_dbgKeep hfoot - exact ⟨σ', he, hkp, e_dt, hK0, hwT, Lst', J.sc_frame hwT hK hX' hCR' hRF' hY' hM' (J.sc_buf hwT hK) hRP' (J.sc_apart hwT hK) - (J.sc_jpl hwT hK (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2).2) (J.sc_jcov hwT hdead (fun q hq hn => absurd hq hn) (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2) hKd subset_rfl) - (J.sc_kern hwT hK hFK hX' hDbg fun _ h => h) (J.sc_utc hwT hK hDbg) hN' hI' hC' hown' hoff hAI - (J.bsa.bk hBK hsok) hcr ⟨⟨Q1, R1, hq2⟩, hB2, hX2, hS2, hSg2⟩ hKd (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2).1 J.zD⟩ + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := + WP.spec_mono (J.unblockRJ ht hk hnq hp hxsc hpc hky hya) + fun _ ⟨σ', he, hkp, _, _, _, _, hdt, hK, hw, Lst', B⟩ => ⟨σ', he, hkp, hdt, hK, hw, Lst', B⟩ /-! ## The tail at `JAtZV3` -/ variable {V X : Set U64} set_option maxHeartbeats 4000000 in -/-- **FL4's sporadic check refines `sigVmSporS` at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.sigSporJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t n : U64} (ht : t ∈ Z.T) +/-- **FL4's sporadic check refines `sigVmSporS` at `JAtZV3`** (module docstring). (mmuAD gen 42b71, ruling (c2) item 2) +Over any VM-epoch record `P` with a `JAtZB` base (`hB0`) kept by an SC-code step (`hTK`); `JAtZV3.sigSporJ` is it at +`JAtZV3`. -/ +theorem sigSporG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB0 : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → JAtZB (L := L) arI AR Z H Cs Ac' Lst' D s' a' σ') + (hTK : ∀ {Ac1 : Set U64} {Lst1 : U64 → List U64} {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} {Ac2 : Set U64} + {Lst2 : U64 → List U64} {s2 : S} {a2 : A} {σ2 : Fl4Spec.State Unit}, + P Ac1 Lst1 s1 a1 σ1 → JAtZB (L := L) arI AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P1.WritesIn st s1 s2 (TFoot st Z.T Z.N Z.C Z.c s1 σ1) → ScTKw (fun _ => False) σ1 σ2 → P Ac2 Lst2 s2 a2 σ2) + (J : P Ac Lst s a σ) {t n : U64} (ht : t ∈ Z.T) (hn : n ∈ Z.N) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {y : Fl4Spec.Notification} (hkn : σ.kheap n.bv = some (.notification y)) : sigVmSporF st s a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), sigVmSporS n.bv t.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r.1 r.2 σ' ⦄ := by - have B := J.z2.zv.base + P Ac Lst' r.1 r.2 σ' ⦄ := by + have B := hB0 J have hS := B.xtop.fin.1.1.1 have hR : NtfnStateRel Z.N Z.T (L.mem s) σ := B.xtop.fin.1.1.2.2.1 obtain ⟨Q, R0, hc, hs⟩ := hS.lists @@ -414,18 +326,37 @@ theorem JAtZV3.sigSporJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have hnq : t.bv ∉ σ.releaseQueue := fun h => hin (hrq.1 h) refine WP.spec_bind (B.unblockJR ht hk hnq hscC hxsc hpc hky ha) ?_ rintro s5 ⟨σ5, he5, -, hdt5, hK5, hW5, Lst5, B5⟩ - refine (WP.spec_ok _).2 ⟨σ5, Lst5, ?_, hdt5, J.ofTK B5 hW5 hK5⟩ + refine (WP.spec_ok _).2 ⟨σ5, Lst5, ?_, hdt5, hTK J B5 hW5 hK5⟩ rw [hSp, if_pos ⟨hcond1, hsp.2 hsw, hpc, by simp [Fl4Spec.inReleaseQueue, hnq]⟩, he5] +/-- `sigSporG` at `JAtZV3` (statement unchanged). -/ +theorem JAtZV3.sigSporJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t n : U64} (ht : t ∈ Z.T) + (hn : n ∈ Z.N) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {y : Fl4Spec.Notification} + (hkn : σ.kheap n.bv = some (.notification y)) : + sigVmSporF st s a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), + sigVmSporS n.bv t.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r.1 r.2 σ' ⦄ := + sigSporG (P := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun J' => J'.z2.zv.base) (fun J1 B2 hw hK => J1.ofTK B2 hw hK) J ht hn hk hkn + set_option maxHeartbeats 4000000 in -/-- **FL4's tail after `maybe_donate_sched_context` refines `sigVmRestS` at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t n : U64} (ht : t ∈ Z.T) +/-- **FL4's tail after `maybe_donate_sched_context` refines `sigVmRestS` at `JAtZV3`** (module docstring). (mmuAD gen +42b71) Over `P` as `sigSporG`, the switch by `JAtZB.switchJc` with its `TFoot` writes and `ScTKw` step; `JAtZV3.sigRestJ` +is it at `JAtZV3`. -/ +theorem sigRestG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB0 : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → JAtZB (L := L) arI AR Z H Cs Ac' Lst' D s' a' σ') + (hTK : ∀ {Ac1 : Set U64} {Lst1 : U64 → List U64} {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} {Ac2 : Set U64} + {Lst2 : U64 → List U64} {s2 : S} {a2 : A} {σ2 : Fl4Spec.State Unit}, + P Ac1 Lst1 s1 a1 σ1 → JAtZB (L := L) arI AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P1.WritesIn st s1 s2 (TFoot st Z.T Z.N Z.C Z.c s1 σ1) → ScTKw (fun _ => False) σ1 σ2 → P Ac2 Lst2 s2 a2 σ2) + (J : P Ac Lst s a σ) {t n : U64} (ht : t ∈ Z.T) (hn : n ∈ Z.N) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {y : Fl4Spec.Notification} (hkn : σ.kheap n.bv = some (.notification y)) : sigVmRestF st s a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), sigVmRestS n.bv t.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r.1 r.2 σ' ⦄ := by - have B := J.z2.zv.base + P Ac Lst' r.1 r.2 σ' ⦄ := by + have B := hB0 J have hS := B.xtop.fin.1.1.1 have hR : NtfnStateRel Z.N Z.T (L.mem s) σ := B.xtop.fin.1.1.2.2.1 unfold sigVmRestF @@ -434,7 +365,7 @@ theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) cases hsv : Fl4Spec.schedulable t.bv σ with | false => rw [hsch, hsv, if_neg Bool.false_ne_true, bind_ok] - refine WP.spec_mono (J.sigSporJ ht hn hk hkn) ?_ + refine WP.spec_mono (sigSporG hB0 hTK J ht hn hk hkn) ?_ rintro r ⟨σ', Lst', h1, h2, J'⟩ refine ⟨σ', Lst', ?_, h2, J'⟩ unfold sigVmRestS @@ -444,8 +375,10 @@ theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) exact (nd_bind_one (m := (Fl4Spec.NonDet.pure () : Fl4Spec.NonDet (Fl4Spec.State Unit) Unit)) rfl _).trans h1 | true => rw [hsch, hsv, if_pos rfl] - refine WP.spec_bind (J.switchJc ht hsv) ?_ - rintro s3 ⟨σ3, he3, Lst3, J3⟩ + refine WP.spec_bind (WP.spec_and (B.switchJc ht hsv) (possible_switch_to_sfoot hR hS B.inv.actReady ht)) ?_ + rintro s3 ⟨⟨σ3, he3, Lst3, B3⟩, hw3⟩ + have J3 := hTK J B3 (WritesIn.tfoot_of_kfoot (WritesIn.kfoot_of_sfoot hw3)) + (nkt_possibleSwitchTo t.bv σ _ (by rw [he3]; exact Set.mem_singleton _)) obtain ⟨σq, heq, rq, act, hq⟩ := Sched.pst_q hk B.inv.actReady have e3 : σ3 = σq := by have h := congrArg Prod.fst (he3.symm.trans heq) @@ -453,7 +386,7 @@ theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have hk3 : σ3.kheap t.bv = some (.tcb x) := by rw [e3, hq]; exact hk have hkn3 : σ3.kheap n.bv = some (.notification y) := by rw [e3, hq]; exact hkn have hdt3 : σ3.domainTime = σ.domainTime := by rw [e3, hq] - refine WP.spec_mono (J3.sigSporJ ht hn hk3 hkn3) ?_ + refine WP.spec_mono (sigSporG hB0 hTK J3 ht hn hk3 hkn3) ?_ rintro r ⟨σ', Lst', h1, h2, J'⟩ refine ⟨σ', Lst', ?_, h2.trans hdt3, J'⟩ unfold sigVmRestS @@ -462,6 +395,16 @@ theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) rw [if_pos rfl, nd_bind_one he3] exact h1 + +/-- `sigRestG` at `JAtZV3` (statement unchanged). -/ +theorem JAtZV3.sigRestJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {t n : U64} (ht : t ∈ Z.T) + (hn : n ∈ Z.N) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {y : Fl4Spec.Notification} + (hkn : σ.kheap n.bv = some (.notification y)) : + sigVmRestF st s a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), + sigVmRestS n.bv t.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst' D r.1 r.2 σ' ⦄ := + sigRestG (P := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun J' => J'.z2.zv.base) (fun J1 B2 hw hK => J1.ofTK B2 hw hK) J ht hn hk hkn end /-! ## The narrowed premise and the old one derived -/ @@ -496,12 +439,34 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} set_option maxHeartbeats 4000000 in -/-- **Gen 35's [J] `SigVmTailJ3` from the narrower `SigVmDonJ3`** (module docstring). -/ -theorem sigVmTailJ3_of (hDn : SigVmDonJ3 st arI V X AR Z H Cs D) : SigVmTailJ3 st arI V X AR Z H Cs D := by +/-- **Gen 35's [J] `SigVmTailJ3` from the narrower `SigVmDonJ3`** (module docstring). (mmuAD gen 42b71, ruling (c2) +item 2) Over `P` as `sigSporG`, the donation as `hDon` (`SigVmDonJ3`'s statement at `P`); `sigVmTailJ3_of` is it at +`JAtZV3`. -/ +theorem sigVmTailG {P : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (hB0 : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → JAtZB (L := L) arI AR Z H Cs Ac' Lst' D s' a' σ') + (hTK : ∀ {Ac1 : Set U64} {Lst1 : U64 → List U64} {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} {Ac2 : Set U64} + {Lst2 : U64 → List U64} {s2 : S} {a2 : A} {σ2 : Fl4Spec.State Unit}, + P Ac1 Lst1 s1 a1 σ1 → JAtZB (L := L) arI AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P1.WritesIn st s1 s2 (TFoot st Z.T Z.N Z.C Z.c s1 σ1) → ScTKw (fun _ => False) σ1 σ2 → P Ac2 Lst2 s2 a2 σ2) + (hDon : ∀ (Ac : Set U64) (Lst : U64 → List U64) (s1 : S) (a : A) (σr : Fl4Spec.State Unit) (t n : U64), + P Ac Lst s1 a σr → Z.th t = some .tcb → n ∈ Z.N → + (∃ x, σr.kheap t.bv = some (.tcb x) ∧ x.tcbState = .running ∧ x.tcbSchedContext = none) → + (∃ y p yc k, σr.kheap n.bv = some (.notification y) ∧ y.ntfnObj = .idleNtfn ∧ y.ntfnBoundTcb = some t.bv ∧ + y.ntfnSc = some p ∧ σr.kheap p = some (.schedContext yc k) ∧ yc.scTcb = none) → + notification.maybe_donate_sched_context st arI s1 a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) + (Lst' : U64 → List U64), Fl4Spec.maybeDonateSc (Z := Unit) t.bv n.bv σr = ({((), σ')}, False) ∧ + σ'.domainTime = σr.domainTime ∧ P Ac' Lst' r.1 r.2 σ' ⦄) : + ∀ (Ac : Set U64) (Lst : U64 → List U64) (s1 : S) (a : A) (σr : Fl4Spec.State Unit) (t n : U64), + P Ac Lst s1 a σr → Z.th t = some .tcb → n ∈ Z.N → + (∃ x, σr.kheap t.bv = some (.tcb x) ∧ x.tcbState = .running) → + (∃ y, σr.kheap n.bv = some (.notification y) ∧ y.ntfnObj = .idleNtfn ∧ y.ntfnBoundTcb = some t.bv) → + sigVmTailF st arI s1 a t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + sigVmTailS n.bv t.bv σr = ({((), σ')}, False) ∧ σ'.domainTime = σr.domainTime ∧ P Ac' Lst' r.1 r.2 σ' ⦄ := by intro Ac Lst s1 a σr t n J hth hn hrun hntf obtain ⟨x, hk, hxr⟩ := hrun obtain ⟨y, hkn, hidle, hb⟩ := hntf - have B := J.z2.zv.base + have B := hB0 J have ht : t ∈ Z.T := B.thT t hth have hS := B.xtop.fin.1.1.1 have hR : NtfnStateRel Z.N Z.T (L.mem s1) σr := B.xtop.fin.1.1.2.2.1 @@ -513,17 +478,17 @@ theorem sigVmTailJ3_of (hDn : SigVmDonJ3 st arI V X AR Z H Cs D) : SigVmTailJ3 s have hysc := hyr.sc have rest : ∀ (s2 : S) (a2 : A) (σ2 : Fl4Spec.State Unit) (Ac2 : Set U64) (Lst2 : U64 → List U64), Fl4Spec.maybeDonateSc (Z := Unit) t.bv n.bv σr = ({((), σ2)}, False) → σ2.domainTime = σr.domainTime → - JAtZV3 (L := L) arI V X AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P Ac2 Lst2 s2 a2 σ2 → sigVmRestF st s2 a2 t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), sigVmTailS n.bv t.bv σr = ({((), σ')}, False) ∧ σ'.domainTime = σr.domainTime ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ' ⦄ := by + P Ac' Lst' r.1 r.2 σ' ⦄ := by intro s2 a2 σ2 Ac2 Lst2 he2 hdt2 J2 - have B2 := J2.z2.zv.base + have B2 := hB0 J2 obtain ⟨Q2, R2, hc2, hs2⟩ := B2.xtop.fin.1.1.1.lists obtain ⟨x2, hk2, -⟩ := hs2.tcb t ht have hR2 : NtfnStateRel Z.N Z.T (L.mem s2) σ2 := B2.xtop.fin.1.1.2.2.1 obtain ⟨y2, hkn2, -⟩ := hR2.ntfn n hn - refine WP.spec_mono (J2.sigRestJ ht hn hk2 hkn2) ?_ + refine WP.spec_mono (sigRestG hB0 hTK J2 ht hn hk2 hkn2) ?_ rintro r ⟨σ', Lst', h1, h2, J'⟩ exact ⟨σ', Ac2, Lst', by rw [sigVmTailS_eq, nd_bind_one he2]; exact h1, h2.trans hdt2, J'⟩ rw [sigVmTailF_eq] @@ -536,7 +501,7 @@ theorem sigVmTailJ3_of (hDn : SigVmDonJ3 st arI V X AR Z H Cs D) : SigVmTailJ3 s subst hc' obtain ⟨yc, k, hky, hy⟩ := hs.scs _ hcC have hyt : yc.scTcb = none := by rw [hy.tcb, Sched.scW_tcb, h2, Notif.optRef_zero] - refine WP.spec_bind (hDn Ac Lst s1 a σr t n J hth hn ⟨x, hk, hxr, by rw [hsct, h0, Notif.optRef_zero]⟩ + refine WP.spec_bind (hDon Ac Lst s1 a σr t n J hth hn ⟨x, hk, hxr, by rw [hsct, h0, Notif.optRef_zero]⟩ ⟨y, _, yc, k, hkn, hidle, hb, hysc', hky, hyt⟩) ?_ rintro ⟨s2, a2⟩ ⟨σ2, Ac2, Lst2, he2, hdt2, J2⟩ exact rest s2 a2 σ2 Ac2 Lst2 he2 hdt2 J2 @@ -567,6 +532,12 @@ theorem sigVmTailJ3_of (hDn : SigVmDonJ3 st arI V X AR Z H Cs D) : SigVmTailJ3 s rw [hmd, bind_ok] exact rest s1 a σr Ac Lst hsp rfl J +/-- **Gen 35's [J] `SigVmTailJ3` from the narrower `SigVmDonJ3`** (module docstring; `sigVmTailG` at `JAtZV3`, +statement unchanged). -/ +theorem sigVmTailJ3_of (hDn : SigVmDonJ3 st arI V X AR Z H Cs D) : SigVmTailJ3 st arI V X AR Z H Cs D := + sigVmTailG (P := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun J' => J'.z2.zv.base) (fun J1 B2 hw hK => J1.ofTK B2 hw hK) hDn + set_option maxHeartbeats 4000000 in /-- **Gen 35's `JAtZV3.signalVmJ` with `SigVmDonJ3` for `SigVmTailJ3`** (module docstring). -/ theorem JAtZV3.signalVmJ2 (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) diff --git a/proofs/Fl4Proofs/P3/JAtZV3SigVm.lean b/proofs/Fl4Proofs/P3/JAtZV3SigVm.lean index 9a002b38c..2e4da434e 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SigVm.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SigVm.lean @@ -30,6 +30,9 @@ is the badge branch below. This module states and proves the branch against `sen completing: `vcpu::report` = `vmReportF` (gen 34's `reportJ3`), then `SigVmTailJ3`. Premises: `SigVmTailJ3` [J] (above), [P] `ZvVirtAgree`, `P0.ArchTotal`, `ARKeep`. No existing statement changed. + +(mmuAD gen 42b71, ruling (c2) item 2) **`signalVmWG`**: `signalVmW` over any VM-epoch record `P` (giving `VmBase`, kept by +FL4's report and by the tail); `JAtZV3.signalVmW` its corollary, statement unchanged. -/ import Fl4Proofs.P3.JAtZV3SigComp import Fl4Proofs.P3.JAtZBSchedR @@ -59,21 +62,41 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **FL4's walk of `send_signal` to the `RunningVM` branch** (module docstring): completing, the whole outcome; -not completing, the activation as `SingleRelI` with `AR` kept. -/ -theorem JAtZV3.signalVmW (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) - (hTl : SigVmTailJ3 st arI V X AR Z H Cs D) - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) +not completing, the activation as `SingleRelI` with `AR` kept. (mmuAD gen 42b71, ruling (c2) item 2) Over any VM-epoch +record `P` that gives `VmBase` (`hB`), is kept by FL4's report (`hRep`) and by the tail (`hTl`, `SigVmTailJ3`'s +statement at `P`); `JAtZV3.signalVmW` is it at `JAtZV3`, P3/VmSignal's `VmEptState.signalVmW` at `VmEptState`. +(gen 42b73) `hRep` / `hTl` only for the bound thread `t`, the report and the tail into records `Pm` / `Pf` of their +own, and the not-completing outcome records FL4's `signal_completes` result (`ok false`), for P3/VmSignal's +`VmEptState.signalVmK`. -/ +theorem signalVmWG {P Pm Pf : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} {t : U64} + (hB : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → VmBase (L := L) arI V AR Z H Cs Ac' Lst' D s' a' σ') + (hRep : ∀ {Ac' : Set U64} {Lst' : U64 → List U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit}, + P Ac' Lst' s' a' σ' → Z.th t = some .tcb → + (∃ x, σ'.kheap t.bv = some (.tcb x) ∧ x.tcbState = .runningVM) → ∀ badge : U64, + vcpu.report st arI s' a' t badge ⦃ s'' => ∃ (σr : Fl4Spec.State Unit) (Ac'' : Set U64) + (Lst'' : U64 → List U64), Fl4Spec.vmReportF (Z := Unit) t.bv badge.bv σ' = ({((), σr)}, False) ∧ + Pm Ac'' Lst'' s'' a' σr ⦄) + (hTl : ∀ (Ac' : Set U64) (Lst' : U64 → List U64) (s1 : S) (a' : A) (σr : Fl4Spec.State Unit) (n : U64), + Pm Ac' Lst' s1 a' σr → Z.th t = some .tcb → n ∈ Z.N → + (∃ x, σr.kheap t.bv = some (.tcb x) ∧ x.tcbState = .running) → + (∃ y, σr.kheap n.bv = some (.notification y) ∧ y.ntfnObj = .idleNtfn ∧ y.ntfnBoundTcb = some t.bv) → + sigVmTailF st arI s1 a' t n ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac'' : Set U64) (Lst'' : U64 → List U64), + sigVmTailS n.bv t.bv σr = ({((), σ')}, False) ∧ σ'.domainTime = σr.domainTime ∧ Pf Ac'' Lst'' r.1 r.2 σ' ⦄) + (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) + (J : P Ac Lst s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) - {t : U64} (hb : x.ntfnBoundTcb = some t.bv) {y : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb y)) + (hb : x.ntfnBoundTcb = some t.bv) {y : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb y)) (hrs : y.tcbState = .runningVM) (badge : U64) : notification.send_signal st arI s a n badge ⦃ r => (∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ - σ'.domainTime = σ.domainTime ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ') ∨ + σ'.domainTime = σ.domainTime ∧ Pf Ac' Lst' r.1 r.2 σ') ∨ (Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = Fl4Spec.sendSignal n.bv badge.bv σ ∧ AR r.2 σ.archState.x64CurrentCr3 ∧ - SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ (Fl4Spec.sendSignal n.bv badge.bv σ) r.1) ⦄ := by - have B := J.z2.zv.base + SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ (Fl4Spec.sendSignal n.bv badge.bv σ) r.1 ∧ + vcpu.signal_completes st s t = ok false) ⦄ := by + have B := (hB J).base have hI := B.xtop.irelK B.ks B.buf have hR := hI.1 have hAR : AR a σ.archState.x64CurrentCr3 := B.xtop.fin.1.1.2.2.2.2.2.2 @@ -104,17 +127,17 @@ theorem JAtZV3.signalVmW (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : have hns2 : i1 ≠ sched.TS_BLOCKED_ON_RECV := by rw [ei1]; exact hns have hvm2 : i1 = sched.TS_RUNNING_VM := by rw [ei1]; exact h8 rw [if_neg hns2, if_neg Bool.false_ne_true, if_pos hvm2] - refine WP.spec_bind (J.sigCompR hth hkt) fun c hc => ?_ + refine WP.spec_bind (WP.spec_and ((hB J).sigCompR hth hkt) (spec_self ((hB J).sigCompR hth hkt))) fun c ⟨hc, ec⟩ => ?_ cases c with | true => rw [if_pos rfl] - refine WP.spec_bind (J.reportJ3 hAT hVA hth ⟨y, hkt, hrs⟩ badge) ?_ - rintro s1 ⟨σr, Ac1, Lst1, hr, J1, -, -⟩ - obtain ⟨hkh, hrun, hdt⟩ := J.repKh hth hkt hr + refine WP.spec_bind (hRep J hth ⟨y, hkt, hrs⟩ badge) ?_ + rintro s1 ⟨σr, Ac1, Lst1, hr, J1⟩ + obtain ⟨hkh, hrun, hdt⟩ := B.repKh hth hkt hr have hnt : n.bv ≠ t.bv := by intro e; rw [e, hkt] at hk; cases hk have hkn : σr.kheap n.bv = some (.notification x) := by rw [hkh n.bv hnt (fun vs e => by rw [hk] at e; cases e)]; exact hk - refine WP.spec_mono (hTl Ac1 Lst1 s1 a σr t n J1 hth hn hrun ⟨x, hkn, hidle, hb⟩) ?_ + refine WP.spec_mono (hTl Ac1 Lst1 s1 a σr n J1 hth hn hrun ⟨x, hkn, hidle, hb⟩) ?_ rintro r ⟨σ', Ac', Lst', h1, h2, J'⟩ refine Or.inl ⟨σ', Ac', Lst', ?_, h2.trans hdt, J'⟩ rw [v3_ssVF_comp _ _ _ hk hidle hb hkt hc hrs hr] @@ -147,7 +170,30 @@ theorem JAtZV3.signalVmW (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : refine WP.spec_mono (v3_kick hAT hK _ a t hAR) ?_ rintro r ⟨e1, hA1⟩ rw [e1] - exact Or.inr ⟨hnc, hA1, hSR⟩ + exact Or.inr ⟨hnc, hA1, hSR, ec⟩ + +/-- **FL4's walk of `send_signal` to the `RunningVM` branch** at `JAtZV3` (`signalVmWG`; statement unchanged). -/ +theorem JAtZV3.signalVmW (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hTl : SigVmTailJ3 st arI V X AR Z H Cs D) + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) + {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) + {t : U64} (hb : x.ntfnBoundTcb = some t.bv) {y : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb y)) + (hrs : y.tcbState = .runningVM) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => + (∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D r.1 r.2 σ') ∨ + (Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = + Fl4Spec.sendSignal n.bv badge.bv σ ∧ AR r.2 σ.archState.x64CurrentCr3 ∧ + SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ (Fl4Spec.sendSignal n.bv badge.bv σ) r.1) ⦄ := + WP.spec_mono (signalVmWG (P := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (Pm := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (Pf := fun Ac' Lst' s' a' σ' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' a' σ') + (fun J' => J'.toB) + (@fun _ _ _ _ _ J' ht hr b => WP.spec_mono (J'.toF.reportJ3 hAT hVA ht hr b) fun _ ⟨σr, Ac', Lst', h1, J'', _, _⟩ => + ⟨σr, Ac', Lst', h1, J'.ofF J''⟩) + (fun Ac' Lst' s1 a' σr n' => hTl Ac' Lst' s1 a' σr t n') hAT hK J hn hk hidle hb hkt hrs badge) + fun _ h => h.imp id fun ⟨h1, h2, h3, _⟩ => ⟨h1, h2, h3⟩ set_option maxHeartbeats 16000000 in /-- **`send_signal` to an idle notification bound to a `RunningVM` thread, at `JAtZV3`, against diff --git a/proofs/Fl4Proofs/P3/JAtZV3SlotIo.lean b/proofs/Fl4Proofs/P3/JAtZV3SlotIo.lean index 44a34a1b0..3a2895b8f 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3SlotIo.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3SlotIo.lean @@ -221,19 +221,30 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} +/-- The slot and heap facts kept by the EnableIOPort owner write. -/ +structure IoOwnerPost (Z : XSets) (V : Set U64) (s s' : S) (σ σ' : Fl4Spec.State Unit) + (x : U64) : Prop where + cap : ∀ y, IsSlot Z.th y → y ≠ x → capV (L.mem s') y = capV (L.mem s) y + tcbSlot : ∀ t, Z.th t = some .tcb → ∀ i < tcbSlots, capV (L.mem s') (slotOf t i) = capV (L.mem s) (slotOf t i) + bound : ∀ v ∈ V, L.mem s' (vTcbA v) = L.mem s (vTcbA v) + archObj : ∀ p ao, σ'.kheap p = some (.archObj ao) ↔ σ.kheap p = some (.archObj ao) + asid : σ'.archState.x64AsidTable = σ.archState.x64AsidTable + size : ∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko + set_option maxHeartbeats 4000000 in -/-- **The EnableIOPort `set_cap` at `JAtZV3`** (module docstring): the spec writes the owner too (decision Q2). -/ -theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {pc : U64} {r : Nat} - {idx : List Bool} (hpc : Z.th pc = some (.cnode r)) (hidx : idx.length = r) {f l : U64} - (hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort f l 0#u64) {p : U64} (hp : p ∈ V) +/-- The EnableIOPort owner write at the common VM base, for any previous owner. -/ +theorem VmBase.ioOwnJ (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {pc : U64} {r : Nat} + {idx : List Bool} (hpc : Z.th pc = some (.cnode r)) (hidx : idx.length = r) {f l prior : U64} + (hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort f l prior) {p : U64} (hcan : Canonical p) : obj.Slot.set_cap st (cslotAddr (pc.bv, idx)) s (.IoPort f l p) ⦃ s' => ∃ σ', Fl4Spec.setCap (Z := Unit) (absCap (.IoPort f l p)) (pc.bv, idx) σ = ({((), σ')}, False) ∧ (∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s' a σ' ∧ + VmBase (L := L) arI V AR Z H Cs Ac Lst D s' a σ' ∧ + IoOwnerPost (L := L) Z V s s' σ σ' (cslotAddr (pc.bv, idx)) ∧ capV (L.mem s') (cslotAddr (pc.bv, idx)) = .IoPort f l p ∧ P1.WritesIn st s s' (fun b => b = cslotAddr (pc.bv, idx) ∨ b = wordOf (cslotAddr (pc.bv, idx)) 8#u64) ⦄ := by - have B := J.z2.zv.base + have B := J.base have hP : Placed Z.th := B.xtop.rel.1 have hA : AbsSlot Z.th (pc.bv, idx) := ⟨pc, rfl, Or.inl (by simpa [hidx] using hpc)⟩ have hx : IsSlot Z.th (cslotAddr (pc.bv, idx)) := hA.isSlot @@ -273,13 +284,15 @@ theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p -- the spec heap after: only the CNode `pc` changed have hothc : ∀ q, q ≠ pc.bv → σ'.kheap q = σ.kheap q := fun q hq => by simp [hσ', setCnodeSlot, hq] have hvpc : ∀ u ∈ V, u.bv ≠ pc.bv := fun u hu e => by - obtain ⟨vx, hvx⟩ := J.z2.zv.vm.spec u hu + obtain ⟨vx, hvx⟩ := J.vm.spec u hu rw [e, hkc] at hvx; cases hvx have hvk : ∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv := fun u hu => hothc _ (hvpc u hu) - have hnv : ∀ q (vs : Fl4Spec.VcpuState), σ'.kheap q = some (.archObj (.vcpu vs)) → - σ.kheap q = some (.archObj (.vcpu vs)) := fun q vs hq => by - have e : q ≠ pc.bv := fun e => by subst e; simp [hσ', setCnodeSlot] at hq - rw [hothc _ e] at hq; exact hq + have hao : ∀ q ao, σ'.kheap q = some (.archObj ao) ↔ σ.kheap q = some (.archObj ao) := by + intro q ao + by_cases e : q = pc.bv + · subst q + simp [hσ', setCnodeSlot, hkc] + · rw [hothc _ e] have hsz : ∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko := fun o ko' ho => by by_cases e : o = pc.bv @@ -305,20 +318,21 @@ theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p (fun P L4 L3 L2 L1 _ => by rw [hcv']; trivial) (fun z hz hne => hcap z ((hM.members z).1 hz).1 hne) (fun z hz => by unfold revOf; rw [(hF z ((hM.members z).1 hz).1).2.1])).okv B.xtop.rel.2.2.2.2.1 - have hTS : ∀ t, Z.th t = some .tcb → capAt (L.mem s') (slotOf t 1) = capAt (L.mem s) (slotOf t 1) := by - intro t ht - have hs : IsSlot Z.th (slotOf t 1) := ⟨t, 1, Or.inr ⟨ht, by simp [tcbSlots]⟩, rfl⟩ - have he : cslotAddr (t.bv, Fl4Spec.tcbCnodeIndex 1) = slotOf t 1 := by + have hTS : ∀ t, Z.th t = some .tcb → ∀ i < tcbSlots, + capV (L.mem s') (slotOf t i) = capV (L.mem s) (slotOf t i) := by + intro t ht i hi + have hs : IsSlot Z.th (slotOf t i) := ⟨t, i, Or.inr ⟨ht, hi⟩, rfl⟩ + have he : cslotAddr (t.bv, Fl4Spec.tcbCnodeIndex i) = slotOf t i := by show slotAddr t.bv (Fl4Spec.ofBl _) = _ - rw [slotAddr_ofBl, tcbCnodeIndex_blVal 1 (by decide)] - have hne : slotOf t 1 ≠ x := fun e => cnode_slot_ne_tcb hP hpc hidx ht 1 (by decide) (by rw [he, e]) - rw [capAt_capV, capAt_capV, hcap _ hs hne] + rw [slotAddr_ofBl, tcbCnodeIndex_blVal i hi] + exact hcap _ hs (fun e => cnode_slot_ne_tcb hP hpc hidx ht i hi (by rw [he, e])) have hX1 : XTopAt (L := L) AR { Z with G := Z.G } s' a σ' := XTopAt.slotStep B.xtop (hW.mono fun b hb => by rcases hb with rfl | rfl · exact ⟨x, hx, 0#u64, Or.inl rfl, (wordOf_zero x).symm⟩ · exact ⟨x, hx, 8#u64, Or.inr (Or.inl rfl), rfl⟩) - (cnK_setCnodeSlot hkc hwf hidx _) (keepC_setCnodeSlot hkc _) ⟨hSt2, hSV2, hM', hCd', hI'⟩ hFI' hMO' hTS + (cnK_setCnodeSlot hkc hwf hidx _) (keepC_setCnodeSlot hkc _) ⟨hSt2, hSV2, hM', hCd', hI'⟩ hFI' hMO' (fun t ht => by + rw [capAt_capV, capAt_capV, hTS t ht 1 (by decide)]) -- `JAtZB` after (`vsStepJXB`) have hvc : Vs.VsSlotsW Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s') := fun y hy => by by_cases e : y = x @@ -337,8 +351,8 @@ theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p (vsSFr_setCnodeSlot hkc hwf hidx _) (hW.mono fun b hb => Or.inl (Or.inr hb)) hcap hsh hok hnu hl hvc ⟨subset_rfl, subset_rfl, subset_rfl⟩ hvn -- the extension: `x`'s words miss every VCPU and every extension word - have Ly := B.jvLay J.z2.zv.vm - have Pw := B.jwPl J.z2.zv.vm + have Ly := B.jvLay J.vm + have Pw := B.jwPl J.vm have hxv : ∀ u ∈ V, ∀ b, (b = x ∨ b = wordOf x 8#u64) → b.val < u.val ∨ u.val + 32768 ≤ b.val := by intro u hu b hb obtain ⟨g1, g2, -, -⟩ := B.cslotW_val hpc hidx hb @@ -359,11 +373,11 @@ theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p · exact (Pw.slb x hx v hv).2 e.symm have kSt : ∀ t, Z.th t = some .tcb → L.mem s' (P1.stA t) = L.mem s (P1.stA t) := fun t ht => hW.mem_eq (Pw.sw _ ⟨t, ht, rfl⟩) fun hb => Pw.swjw _ ⟨t, ht, rfl⟩ (hjw _ hb) - have E0 := J.z2.zv.extv - have E' : JExtV (L := L) V X Z.th s' := + have E0 := J.extv + have E' : JExtVcpu (L := L) V Z.th s' := { cap := fun y hy => by by_cases e : y = x - · rw [e, hcv']; exact fun _ => hp + · rw [e, hcv']; trivial · rw [hcap y hy e]; exact E0.cap y hy bnd := fun t ht => by rcases E0.bnd t ht with h | ⟨h1, h2⟩ @@ -375,22 +389,46 @@ theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p · right; rw [kVT v hv]; exact ⟨h1, by rw [kTV _ h1]; exact h2⟩ nz := E0.nz } have R' : RunVmB (L := L) Z.th s' := fun t ht h8' => by - rw [kTV t ht]; exact J.z2.zv.rvm t ht (by rw [← kSt t ht]; exact h8') + rw [kTV t ht]; exact J.rvm t ht (by rw [← kSt t ht]; exact h8') have Jv' : JVm (L := L) V H s' σ' := - J.z2.zv.vm.step (fun _ h => h) (fun _ _ => rfl) hks (fun u hu => by rw [hvk u hu]; exact J.z2.zv.vm.spec u hu) + J.vm.step (fun _ h => h) (fun _ _ => rfl) hks (fun u hu => by rw [hvk u hu]; exact J.vm.spec u hu) (fun o ko' ho => Or.inl (hsz o ko' ho)) - have Vl' : VList st V Z.th s' := J.z2.zv.vl.writes hW fun b hb => by - refine ⟨J.z2.zv.vl.lw_al Ly.vfit hb, fun hWb => ?_⟩ + have Vl' : VList st V Z.th s' := J.vl.writes hW fun b hb => by + refine ⟨J.vl.lw_al Ly.vfit hb, fun hWb => ?_⟩ rcases hb with rfl | ⟨u, hu, rfl | rfl⟩ - · exact J.z2.zv.vl.hd.2.1 (hjw _ hWb) + · exact J.vl.hd.2.1 (hjw _ hWb) · have := lay_next_val (Ly.vfit u hu).2 rcases hxv u hu _ hWb with h | h <;> omega · have := lay_prev_val (Ly.vfit u hu).2 rcases hxv u hu _ hWb with h | h <;> omega - have vb' : VBind V σ' (L.mem s') := J.z2.vb.ofV hvk kVT + have vb' : VBind V σ' (L.mem s') := J.vb.ofV hvk kVT have vr' : VRel V σ' (L.mem s') := - J.vr.frame (fun u _ vs hu => hnv _ vs hu) (v3_agreeW hW (fun u hu => (Ly.vfit u hu).2) hxv) - exact ⟨σ', hsc, hvk, ⟨⟨⟨B', E', R', Jv', Vl'⟩, vb'⟩, J.vo.frame hnv, vr'⟩, hcv', hW⟩ + J.vr.frame (fun u _ vs hu => (hao _ _).1 hu) (v3_agreeW hW (fun u hu => (Ly.vfit u hu).2) hxv) + exact ⟨σ', hsc, hvk, ⟨B', E', R', Jv', Vl', vb', J.vo.frame (fun q vs h => (hao q _).1 h), vr'⟩, + ⟨hcap, hTS, kVT, hao, rfl, hsz⟩, hcv', hW⟩ + +set_option maxHeartbeats 4000000 in +/-- **The EnableIOPort `set_cap` at `JAtZV3`** (module docstring): the spec writes the owner too (decision Q2). -/ +theorem JAtZV3.ioOwnJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {pc : U64} {r : Nat} + {idx : List Bool} (hpc : Z.th pc = some (.cnode r)) (hidx : idx.length = r) {f l : U64} + (hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort f l 0#u64) {p : U64} (hp : p ∈ V) + (hcan : Canonical p) : + obj.Slot.set_cap st (cslotAddr (pc.bv, idx)) s (.IoPort f l p) ⦃ s' => + ∃ σ', Fl4Spec.setCap (Z := Unit) (absCap (.IoPort f l p)) (pc.bv, idx) σ = ({((), σ')}, False) ∧ + (∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s' a σ' ∧ + capV (L.mem s') (cslotAddr (pc.bv, idx)) = .IoPort f l p ∧ + P1.WritesIn st s s' (fun b => b = cslotAddr (pc.bv, idx) ∨ b = wordOf (cslotAddr (pc.bv, idx)) 8#u64) ⦄ := by + refine WP.spec_mono (J.toB.ioOwnJ hpc hidx hcx hcan) ?_ + rintro s' ⟨σ', hsc, hvk, J', F, hcv, hw⟩ + refine ⟨σ', hsc, hvk, ⟨⟨⟨J'.base, ⟨?_, J'.extv.bnd, J'.extv.back, J'.extv.nz⟩, + J'.rvm, J'.vm, J'.vl⟩, J'.vb⟩, J'.vo, J'.vr⟩, hcv, hw⟩ + intro y hy + by_cases e : y = cslotAddr (pc.bv, idx) + · rw [e, hcv] + exact fun _ => hp + · rw [F.cap y hy e] + exact J.z2.zv.extv.cap y hy end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VDec.lean b/proofs/Fl4Proofs/P3/JAtZV3VDec.lean index 5425d20e2..250f7c45e 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VDec.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VDec.lean @@ -109,24 +109,87 @@ def VDecTail (st : machine.Store S) (ct : U64) (call : Bool) (rep : List Fl4Spec (∃ y : U64, rep = [y.bv] ∧ vcpu.reply st s' call y = ok r2) ∨ (∃ ws : List U64, rep = ws.map (·.bv) ∧ vcpuReplyWs st s' ct call ws = ok r2) -/-- **The VCPU decode's post at `JAtZV3`** (module docstring). -/ -def VDecPost (arI : machine.Arch A) (V X : Set U64) (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) - (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s : S) (σ : Fl4Spec.State Unit) - (lbl len p : U64) (call : Bool) (buf : U64) (b : Bool) (c : capability.Cap) - (r : core.result.Result Unit error.Exc × S × A) : Prop := +/-- The pre- and post-state VCPU objects agree on their thread binding. -/ +def VcpuBindingKeep (σ σ' : Fl4Spec.State Unit) : Prop := + ∀ (v : U64) (old new : Fl4Spec.VcpuState), σ.kheap v.bv = some (.archObj (.vcpu old)) → + σ'.kheap v.bv = some (.archObj (.vcpu new)) → old.tcb = new.tcb + +theorem VcpuBindingKeep.refl (σ : Fl4Spec.State Unit) : VcpuBindingKeep σ σ := by + intro v old new ho hn + rw [ho] at hn + cases hn + rfl + +theorem VcpuBindingKeep.update {σ : Fl4Spec.State Unit} {p : Fl4Spec.ObjRef} {before after : Fl4Spec.VcpuState} + (hk : σ.kheap p = some (.archObj (.vcpu before))) (ht : before.tcb = after.tcb) : + VcpuBindingKeep σ (Notif.updK σ p (.archObj (.vcpu after))) := by + intro v old new ho hn + by_cases hv : v.bv = p + · rw [hv, hk] at ho + simp only [Notif.updK, hv, Function.update_self] at hn + cases ho + cases hn + exact ht + · have e : σ.kheap v.bv = some (.archObj (.vcpu new)) := by + simpa only [Notif.updK, Function.update_of_ne hv] using hn + exact VcpuBindingKeep.refl σ v old new ho e + +theorem VcpuBindingKeep.of_run {σ σ' : Fl4Spec.State Unit} {p : Fl4Spec.ObjRef} {before after : Fl4Spec.VcpuState} + {M : Fl4Spec.SMonad Unit (List Fl4Spec.Data)} {rep : List Fl4Spec.Data} + (hk : σ.kheap p = some (.archObj (.vcpu before))) + (h : M σ = ({(rep, σ')}, False)) + (h' : M σ = ({(rep, Notif.updK σ p (.archObj (.vcpu after)))}, False)) + (ht : before.tcb = after.tcb) : + VcpuBindingKeep σ σ' := by + have e := congrArg Prod.fst (h.symm.trans h') + obtain ⟨_, he⟩ := Prod.mk.inj (Set.singleton_eq_singleton_iff.mp e) + rw [he] + exact VcpuBindingKeep.update hk ht + +/-- The result of a VCPU decode for a state relation and an extra-cap agreement. -/ +def VDecPostQ (st : machine.Store S) + (Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop) + (extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop) + (Ac : Set U64) (Lst : U64 → List U64) (s : S) (σ : Fl4Spec.State Unit) + (lbl len p : U64) (call : Bool) (buf : U64) (r : core.result.Result Unit error.Exc × S × A) : Prop := ∃ ct : U64, sched.cur_thread st s = ok ct ∧ ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), VArgs st s ct buf len args → - StcbCaps b c ec → + extra ec → (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec) σ = ExceptT.run (Fl4Spec.NonDetE.throwError (σ := Fl4Spec.State Unit) (α := Fl4Spec.VcpuInvocation) e') σ ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + r.2.1 = s ∧ Q Ac Lst s r.2.2 σ) ∨ (∃ (inv : Fl4Spec.VcpuInvocation) (rep : List Fl4Spec.Data) (s' : S) (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), r.1 = .Ok () ∧ ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec) σ = ExceptT.run (Fl4Spec.NonDetE.returnOk (σ := Fl4Spec.State Unit) (ε := Fl4Spec.SyscallError) inv) σ ∧ Fl4Spec.performVcpuInvocationF (Z := Unit) inv σ = ({(rep, σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' r.2.2 σ' ∧ VDecTail st ct call rep s' r.2.1) + Q Ac' Lst' s' r.2.2 σ' ∧ VDecTail st ct call rep s' r.2.1) + +/-- **The VCPU decode's post at `JAtZV3`** (module docstring). -/ +def VDecPost (arI : machine.Arch A) (V X : Set U64) (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) + (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s : S) (σ : Fl4Spec.State Unit) + (lbl len p : U64) (call : Bool) (buf : U64) (b : Bool) (c : capability.Cap) + (r : core.result.Result Unit error.Exc × S × A) : Prop := + VDecPostQ st (fun Ac' Lst' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D) + (StcbCaps b c) Ac Lst s σ lbl len p call buf r + + +/-- Transport the state relation in a VCPU decoder post. -/ +theorem VDecPostQ.mono + {Q R : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} {Ac : Set U64} {Lst : U64 → List U64} + {s : S} {σ : Fl4Spec.State Unit} {lbl len p : U64} {call : Bool} {buf : U64} + {r : core.result.Result Unit error.Exc × S × A} + (h : VDecPostQ st Q extra Ac Lst s σ lbl len p call buf r) + (hQ : ∀ Ac' Lst' s' a' σ', Q Ac' Lst' s' a' σ' → R Ac' Lst' s' a' σ') : + VDecPostQ st R extra Ac Lst s σ lbl len p call buf r := by + obtain ⟨ct, hct, hh⟩ := h + refine ⟨ct, hct, fun args ec ha hx => ?_⟩ + rcases hh args ec ha hx with ⟨e, e', he, hr, hd, hs, hJ⟩ | + ⟨inv, rep, s', σ', Ac', Lst', hok, hd, hp, hJ, ht⟩ + · exact Or.inl ⟨e, e', he, hr, hd, hs, hQ _ _ _ _ _ hJ⟩ + · exact Or.inr ⟨inv, rep, s', σ', Ac', Lst', hok, hd, hp, hQ _ _ _ _ _ hJ, ht⟩ end @@ -137,6 +200,16 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} +/-- Report a VCPU decode error whose specification holds for each agreeing length. -/ +theorem VDecPostQ.err {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} {a1 : A} (hQ : Q Ac Lst s a1 σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) {e : error.Exc} {e' : Fl4Spec.SyscallError} (he : SysErrRel e e') + {lbl len p : U64} {call : Bool} {buf : U64} + (hD : ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), args.length = len.val → + Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec = Fl4Spec.NonDetE.throwError e') : + VDecPostQ st Q extra Ac Lst s σ lbl len p call buf (.Err e, s, a1) := + ⟨ct, hct, fun args ec hA _ => Or.inl ⟨e, e', rfl, he, by rw [hD args ec hA.1], rfl, hQ⟩⟩ + /-- **An error the decoder throws at every agreeing argument list** gives `VDecPost` (module docstring). -/ theorem JAtZV3.vdErr {a1 : A} (J1 : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a1 σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) {e : error.Exc} {e' : Fl4Spec.SyscallError} (he : SysErrRel e e') @@ -144,7 +217,7 @@ theorem JAtZV3.vdErr {a1 : A} (J1 : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s (hD : ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), args.length = len.val → Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec = Fl4Spec.NonDetE.throwError e') : VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ lbl len p call buf b c (.Err e, s, a1) := - ⟨ct, hct, fun args ec hA _ => Or.inl ⟨e, e', rfl, he, by rw [hD args ec hA.1], rfl, J1⟩⟩ + VDecPostQ.err J1 hct he hD /-- `setTcbJ` in `VDecPost` form. -/ theorem JAtZV3.vdStcb (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) @@ -162,64 +235,123 @@ theorem JAtZV3.vdStcb (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) · exact Or.inr ⟨.setTcb p.bv t.bv, [], s7, σ', Ac', Lst', h1, by rw [h2], h3, h4, Or.inl ⟨rfl, h5⟩⟩ /-- `writeRegsJ` in `VDecPost` form. -/ -theorem JAtZV3.vdWregs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBaseF.vdWregs {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hAT : P0.ArchTotal arI) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 15 ≤ len.val) (call : Bool) {buf : U64} - (hb : BufOut V buf) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (hb : BufOut V buf) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteRegisters len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf b c r ⦄ := by + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf r ⦄ := by refine WP.spec_mono (J.writeRegsJ hK hAT hp hk hlen call hb ex) ?_ rintro r ⟨ct, vals, hct, hv, h1, hD, s3, σ', h3, h4, h5⟩ - refine ⟨ct, hct, fun args ec hA _ => Or.inr ⟨.writeRegisters p.bv fun i => (vals i).bv, [], s3, σ', Ac, Lst, h1, ?_, h3, h4, Or.inl ⟨rfl, h5⟩⟩⟩ + refine ⟨ct, hct, fun args ec hA _ => Or.inr ⟨.writeRegisters p.bv fun i => (vals i).bv, [], s3, σ', Ac, Lst, h1, ?_, h3, ⟨h4, VcpuBindingKeep.of_run hk h3 (zv_perform_wregs hk _) rfl⟩, Or.inl ⟨rfl, h5⟩⟩⟩ rw [hD args ec hA.1 (fun i => hA.2 i.val (vals i) (by have := i.isLt; omega) (hv i))] +theorem JAtZV3.vdWregs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hAT : P0.ArchTotal arI) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 15 ≤ len.val) (call : Bool) {buf : U64} + (hb : BufOut V buf) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteRegisters len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.vdWregs (extra := StcbCaps b c) hK hAT hp hk hlen call hb ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 + /-- `writeVmcsJ` in `VDecPost` form. -/ -theorem JAtZV3.vdWvmcs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBaseF.vdWvmcs {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hvk : Fl4Spec.virtKind = .vmx) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := by + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf r ⦄ := by refine WP.spec_mono (J.writeVmcsJ hK hSy hVA hCap hvk hp hk hlen call buf ex) ?_ rintro r ⟨ct, f, x, hct, hf, hx, HH⟩ refine ⟨ct, hct, fun args ec hA _ => ?_⟩ rcases HH args ec hA.1 (hA.a0 (by omega) hf) (hA.a1 (by omega) hx) with ⟨e, e', h1, h2, h3, h4, h5⟩ | ⟨y, s3, σ', h1, h2, h3, h4, h5⟩ - · exact Or.inl ⟨e, e', h1, h2, by rw [h3], h4, h5⟩ - · exact Or.inr ⟨.writeVmcs p.bv f.bv y.bv, [y.bv], s3, σ', Ac, Lst, h1, by rw [h2], h3, h4, Or.inr (Or.inl ⟨y, rfl, h5⟩)⟩ + · exact Or.inl ⟨e, e', h1, h2, by rw [h3], h4, ⟨h5, VcpuBindingKeep.refl _⟩⟩ + · exact Or.inr ⟨.writeVmcs p.bv f.bv y.bv, [y.bv], s3, σ', Ac, Lst, h1, by rw [h2], h3, ⟨h4, VcpuBindingKeep.of_run hk h3 (zv_perform_wvmcs hk _ _) rfl⟩, Or.inr (Or.inl ⟨y, rfl, h5⟩)⟩ + +theorem JAtZV3.vdWvmcs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hvk : Fl4Spec.virtKind = .vmx) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.vdWvmcs (extra := StcbCaps b c) hK hSy hVA hCap hvk hp hk hlen call buf ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 /-- `writeMsrJ` in `VDecPost` form. -/ -theorem JAtZV3.vdWmsr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) +theorem VmBaseF.vdWmsr {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteMSR len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteMSR len p call buf b c r ⦄ := by + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUWriteMSR len p call buf r ⦄ := by refine WP.spec_mono (J.writeMsrJ hAT hK hVA hCap hp hk hlen call buf ex) ?_ rintro r ⟨ct, f, x, hct, hf, hx, HH⟩ refine ⟨ct, hct, fun args ec hA _ => ?_⟩ rcases HH args ec hA.1 (hA.a0 (by omega) hf) (hA.a1 (by omega) hx) with ⟨e, e', h1, h2, h3, h4, h5⟩ | ⟨s3, σ', h1, h2, h3, h4, h5⟩ - · exact Or.inl ⟨e, e', h1, h2, by rw [h3], h4, h5⟩ - · exact Or.inr ⟨.writeMsr p.bv f.bv x.bv, [x.bv], s3, σ', Ac, Lst, h1, by rw [h2], h3, h4, Or.inr (Or.inl ⟨x, rfl, h5⟩)⟩ + · exact Or.inl ⟨e, e', h1, h2, by rw [h3], h4, ⟨h5, VcpuBindingKeep.refl _⟩⟩ + · exact Or.inr ⟨.writeMsr p.bv f.bv x.bv, [x.bv], s3, σ', Ac, Lst, h1, by rw [h2], h3, ⟨h4, VcpuBindingKeep.of_run hk h3 (zv_perform_wmsr hk _ _) rfl⟩, Or.inr (Or.inl ⟨x, rfl, h5⟩)⟩ + +theorem JAtZV3.vdWmsr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hAT : P0.ArchTotal arI) + (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteMSR len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteMSR len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.vdWmsr (extra := StcbCaps b c) hAT hK hVA hCap hp hk hlen call buf ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 /-- `writeVmcbJ` in `VDecPost` form. -/ -theorem JAtZV3.vdWvmcb (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) +theorem VmBaseF.vdWvmcb {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := by + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf r ⦄ := by refine WP.spec_mono (J.writeVmcbJ hK hVA hCap hvk hp hk hlen call buf ex) ?_ rintro r ⟨ct, f, x, hct, hf, hx, HH⟩ refine ⟨ct, hct, fun args ec hA _ => ?_⟩ rcases HH args ec hA.1 (hA.a0 (by omega) hf) (hA.a1 (by omega) hx) with ⟨e, e', h1, h2, h3, h4, h5⟩ | ⟨y, s3, σ', h1, h2, h3, h4, h5⟩ - · exact Or.inl ⟨e, e', h1, h2, h3, h4, h5⟩ - · exact Or.inr ⟨.writeVmcb p.bv f.bv y.bv, [y.bv], s3, σ', Ac, Lst, h1, h2, h3, h4, Or.inr (Or.inl ⟨y, rfl, h5⟩)⟩ + · exact Or.inl ⟨e, e', h1, h2, h3, h4, ⟨h5, VcpuBindingKeep.refl _⟩⟩ + · exact Or.inr ⟨.writeVmcb p.bv f.bv y.bv, [y.bv], s3, σ', Ac, Lst, h1, h2, h3, ⟨h4, VcpuBindingKeep.of_run hk h3 (zv_perform_wvmcb2 hk _ _) rfl⟩, Or.inr (Or.inl ⟨y, rfl, h5⟩)⟩ + +theorem JAtZV3.vdWvmcb (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) + (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.vdWvmcb (extra := StcbCaps b c) hK hVA hCap hvk hp hk hlen call buf ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VDecE.lean b/proofs/Fl4Proofs/P3/JAtZV3VDecE.lean index 0e768af20..d7b69b11d 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VDecE.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VDecE.lean @@ -88,19 +88,32 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} +/-- The decoder reads an argument when present and uses zero otherwise. -/ +theorem vcpu_arg_or_zero (s : S) (ct buf len index : U64) : + ∃ word, (if len > index then msg.syscall_arg st s ct buf index else ok 0#u64) = ok word := by + split + · obtain ⟨word, hw, -⟩ := P1.spec_ex_fd + (P0.msg.syscall_arg.p0 st s ct buf index (P1.LawfulStore.total (st := st))) + exact ⟨word, hw⟩ + · exact ⟨0#u64, rfl⟩ + theorem zv_n (x y : U64) (h : x.val ≠ y.val) : ¬ x = y := zv_lbl_ne h set_option maxHeartbeats 16000000 in /-- **X86VCPUFlushTLB at `JAtZV3`** (module docstring). -/ -theorem JAtZV3.vdFlush (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBaseF.vdFlush {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUFlushTLB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUFlushTLB len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUFlushTLB len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ @@ -112,16 +125,8 @@ theorem JAtZV3.vdFlush (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) ( rw [hct, bind_ok] obtain ⟨i, hi, -⟩ := hVA a1 rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUFlushTLB fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUFlushTLB, fl4_abi.label.X86VCPUSetTCB]) @@ -130,20 +135,33 @@ theorem JAtZV3.vdFlush (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) ( simp only [if_neg n73, if_neg n81, eq_self_iff_true, ↓reduceIte] simp only [vcpu.set, lift, bind_ok] refine WP.spec_bind (P1.LawfulStore.write_spec _ _ _) fun s2 e2 => ?_ - have J2 : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s2 a1 σ := by rw [e2]; exact J1.svmWr hp 0#u64 + have J2 : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s2 a1 σ := by rw [e2]; exact J1.svmWr hp 0#u64 obtain ⟨s3, h3, -⟩ := P1.spec_ex_fd (P0.sched.set_thread_state.p0 st s2 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) rw [h3, bind_ok, WP.spec_ok] exact ⟨ct, hct, fun args ec _ _ => Or.inr ⟨.flushTlb p.bv, [], s2, σ, Ac, Lst, rfl, - by rw [zv_flush_bv, zv_decode_flush], zv_perform_flush σ _, J2, Or.inl ⟨rfl, h3⟩⟩⟩ + by rw [zv_flush_bv, zv_decode_flush], zv_perform_flush σ _, ⟨J2, VcpuBindingKeep.refl _⟩, Or.inl ⟨rfl, h3⟩⟩⟩ + +theorem JAtZV3.vdFlush (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUFlushTLB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUFlushTLB len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.vdFlush (extra := StcbCaps b c) hK hVA hp len call buf ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 set_option maxHeartbeats 16000000 in /-- **A label that is no VCPU label** (module docstring). -/ -theorem JAtZV3.vdOther (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdOther + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {lbl : U64} (hn : Fl4Spec.vcpuLabelOf lbl.bv = none) - (len : U64) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (len : U64) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a lbl len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ lbl len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ lbl len p call buf r ⦄ := by have n73 := zv_lbl_none zv_stcb_bv zv_label_stcb hn have n81 := zv_lbl_none zv_wregs_bv zv_label_wregs hn have n76 := zv_lbl_none zv_flush_bv zv_label_flush hn @@ -155,109 +173,109 @@ theorem JAtZV3.vdOther (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) ( have n50 := zv_lbl_none zv_wmsr_bv zv_label_wmsr hn have n79 := zv_lbl_none zv_eio_bv zv_label_eio hn have n80 := zv_lbl_none zv_dio_bv zv_label_dio hn - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, -⟩ := hVA a1 rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, if_neg n75, if_neg n77, if_neg n78, if_neg n49, if_neg n50, if_neg n79, if_neg n80, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => zv_decode_other hn args _ ec + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => zv_decode_other hn args _ ec + +/-- **A label that is no VCPU label** (module docstring). -/ +theorem JAtZV3.vdOther (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {lbl : U64} (hn : Fl4Spec.vcpuLabelOf lbl.bv = none) + (len : U64) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a lbl len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ lbl len p call buf b c r ⦄ := + J.toB.vdOther (fun _ h => J.archV h) hK hVA hp hn len call buf ex set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteRegisters, `len < 15`** (module docstring). -/ -theorem JAtZV3.vdWregsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWregsS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 15) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteRegisters len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf r ⦄ := by have g2 : len < 15#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, -⟩ := hVA a1 rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteRegisters fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteRegisters, fl4_abi.label.X86VCPUSetTCB]) simp only [if_neg n73, eq_self_iff_true, ↓reduceIte, if_pos g2, error.truncated, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by rw [zv_wregs_bv]; exact zv_decode_wregs_short (by omega) _ ec +/-- **X86VCPUWriteRegisters, `len < 15`** (module docstring). -/ +theorem JAtZV3.vdWregsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 15) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteRegisters len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteRegisters len p call buf b c r ⦄ := + J.toB.vdWregsS (fun _ h => J.archV h) hK hVA hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteVMCS on SVM** (module docstring). -/ -theorem JAtZV3.vdWvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWvmcsA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) - (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteVMCS fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteVMCS, fl4_abi.label.X86VCPUSetTCB]) @@ -269,43 +287,47 @@ theorem JAtZV3.vdWvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (by simp [fl4_abi.label.X86VCPUWriteVMCS, fl4_abi.label.X86VCPUReadVMCS]) simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, eq_self_iff_true, ↓reduceIte, if_pos h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => by rw [zv_wvmcs_bv]; exact zv_decode_wvmcs_amd hvk args _ ec +/-- **X86VCPUWriteVMCS on SVM** (module docstring). -/ +theorem JAtZV3.vdWvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) + (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := + J.toB.vdWvmcsA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteVMCS on VMX, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdWvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWvmcsS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .vmx) {p : U64} (hp : p ∈ V) {len : U64} - (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => by have := hi2.1 e; rw [hvk] at this; exact absurd this (by decide) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteVMCS fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteVMCS, fl4_abi.label.X86VCPUSetTCB]) @@ -317,42 +339,46 @@ theorem JAtZV3.vdWvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (by simp [fl4_abi.label.X86VCPUWriteVMCS, fl4_abi.label.X86VCPUReadVMCS]) simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, eq_self_iff_true, ↓reduceIte, if_neg h2, bind_ok, if_pos g2, error.illegal, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_wvmcs_bv]; exact zv_decode_wvmcs_short hvk (by omega) _ ec +/-- **X86VCPUWriteVMCS on VMX, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdWvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .vmx) {p : U64} (hp : p ∈ V) {len : U64} + (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCS len p call buf b c r ⦄ := + J.toB.vdWvmcsS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteVMCB off SVM** (module docstring). -/ -theorem JAtZV3.vdWvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWvmcbA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) - (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => hvk (hi2.1 e) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteVMCB fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteVMCB, fl4_abi.label.X86VCPUSetTCB]) @@ -368,43 +394,47 @@ theorem JAtZV3.vdWvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (by simp [fl4_abi.label.X86VCPUWriteVMCB, fl4_abi.label.X86VCPUReadVMCB]) simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, if_neg n75, if_neg n77, eq_self_iff_true, ↓reduceIte, if_neg h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec _ => by rw [zv_wvmcb_bv]; exact zv_decode_wvmcb_vmx hvk args _ ec +/-- **X86VCPUWriteVMCB off SVM** (module docstring). -/ +theorem JAtZV3.vdWvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) + (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := + J.toB.vdWvmcbA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteVMCB on SVM, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdWvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWvmcbS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {len : U64} - (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteVMCB fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteVMCB, fl4_abi.label.X86VCPUSetTCB]) @@ -420,42 +450,46 @@ theorem JAtZV3.vdWvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (by simp [fl4_abi.label.X86VCPUWriteVMCB, fl4_abi.label.X86VCPUReadVMCB]) simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, if_neg n75, if_neg n77, eq_self_iff_true, ↓reduceIte, if_pos h2, if_pos g2, error.truncated, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by rw [zv_wvmcb_bv]; exact zv_decode_wvmcb_short hvk (by omega) _ ec +/-- **X86VCPUWriteVMCB on SVM, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdWvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {len : U64} + (hlen : len.val < 2) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteVMCB len p call buf b c r ⦄ := + J.toB.vdWvmcbS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteMSR, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdWmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdWmsrS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteMSR len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteMSR len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUWriteMSR len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, -⟩ := hVA a1 rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have n73 := zv_n fl4_abi.label.X86VCPUWriteMSR fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUWriteMSR, fl4_abi.label.X86VCPUSetTCB]) @@ -475,9 +509,17 @@ theorem JAtZV3.vdWmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) ( (by simp [fl4_abi.label.X86VCPUWriteMSR, fl4_abi.label.X86VCPUReadMSR]) simp only [if_neg n73, if_neg n81, if_neg n76, if_neg n74, if_neg n75, if_neg n77, if_neg n78, if_neg n49, eq_self_iff_true, ↓reduceIte, bind_ok, if_pos g2, error.illegal, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_wmsr_bv]; exact zv_decode_wmsr_short (by omega) _ ec +/-- **X86VCPUWriteMSR, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdWmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteMSR len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUWriteMSR len p call buf b c r ⦄ := + J.toB.vdWmsrS (fun _ h => J.archV h) hK hVA hp hlen call buf ex + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VDecE2.lean b/proofs/Fl4Proofs/P3/JAtZV3VDecE2.lean index abad6a3b2..98f285c96 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VDecE2.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VDecE2.lean @@ -80,37 +80,33 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCS on SVM** (module docstring). -/ -theorem JAtZV3.vdRvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdRvmcsA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCS len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUReadVMCS fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUReadVMCS, fl4_abi.label.X86VCPUSetTCB]) @@ -119,43 +115,47 @@ theorem JAtZV3.vdRvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have nFlushTLB := zv_n fl4_abi.label.X86VCPUReadVMCS fl4_abi.label.X86VCPUFlushTLB (by simp [fl4_abi.label.X86VCPUReadVMCS, fl4_abi.label.X86VCPUFlushTLB]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, eq_self_iff_true, ↓reduceIte, if_pos h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_rvmcs_bv]; exact zv_decode_rvmcs_amd hvk args _ ec +/-- **X86VCPUReadVMCS on SVM** (module docstring). -/ +theorem JAtZV3.vdRvmcsA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := + J.toB.vdRvmcsA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCS off SVM, `len < 1`** (module docstring). -/ -theorem JAtZV3.vdRvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdRvmcsS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 1) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCS len p call buf r ⦄ := by have g2 : len < 1#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => hvk (hi2.1 e) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUReadVMCS fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUReadVMCS, fl4_abi.label.X86VCPUSetTCB]) @@ -166,42 +166,46 @@ theorem JAtZV3.vdRvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have nWriteVMCS := zv_n fl4_abi.label.X86VCPUReadVMCS fl4_abi.label.X86VCPUWriteVMCS (by simp [fl4_abi.label.X86VCPUReadVMCS, fl4_abi.label.X86VCPUWriteVMCS]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nWriteVMCS, eq_self_iff_true, ↓reduceIte, if_neg h2, bind_ok, if_pos g2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_rvmcs_bv]; exact zv_decode_rvmcs_short hvk (by omega) _ ec +/-- **X86VCPUReadVMCS off SVM, `len < 1`** (module docstring). -/ +theorem JAtZV3.vdRvmcsS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 1) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := + J.toB.vdRvmcsS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCB off SVM** (module docstring). -/ -theorem JAtZV3.vdRvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdRvmcbA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCB len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => hvk (hi2.1 e) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUReadVMCB fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUReadVMCB, fl4_abi.label.X86VCPUSetTCB]) @@ -214,43 +218,47 @@ theorem JAtZV3.vdRvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have nWriteVMCS := zv_n fl4_abi.label.X86VCPUReadVMCB fl4_abi.label.X86VCPUWriteVMCS (by simp [fl4_abi.label.X86VCPUReadVMCB, fl4_abi.label.X86VCPUWriteVMCS]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, eq_self_iff_true, ↓reduceIte, if_neg h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_rvmcb_bv]; exact zv_decode_rvmcb_vmx hvk args _ ec +/-- **X86VCPUReadVMCB off SVM** (module docstring). -/ +theorem JAtZV3.vdRvmcbA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := + J.toB.vdRvmcbA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCB on SVM, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdRvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdRvmcbS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCB len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUReadVMCB fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUReadVMCB, fl4_abi.label.X86VCPUSetTCB]) @@ -263,42 +271,46 @@ theorem JAtZV3.vdRvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have nWriteVMCS := zv_n fl4_abi.label.X86VCPUReadVMCB fl4_abi.label.X86VCPUWriteVMCS (by simp [fl4_abi.label.X86VCPUReadVMCB, fl4_abi.label.X86VCPUWriteVMCS]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, eq_self_iff_true, ↓reduceIte, if_pos h2, if_pos g2, error.truncated, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by rw [zv_rvmcb_bv]; exact zv_decode_rvmcb_short hvk (by omega) _ ec +/-- **X86VCPUReadVMCB on SVM, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdRvmcbS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := + J.toB.vdRvmcbS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUReadMSR, `len < 1`** (module docstring). -/ -theorem JAtZV3.vdRmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdRmsrS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 1) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadMSR len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadMSR len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadMSR len p call buf r ⦄ := by have g2 : len < 1#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUReadMSR fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUReadMSR, fl4_abi.label.X86VCPUSetTCB]) @@ -317,42 +329,46 @@ theorem JAtZV3.vdRmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) ( have nWriteMSR := zv_n fl4_abi.label.X86VCPUReadMSR fl4_abi.label.X86VCPUWriteMSR (by simp [fl4_abi.label.X86VCPUReadMSR, fl4_abi.label.X86VCPUWriteMSR]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, if_neg nReadVMCB, if_neg nWriteVMCB, if_neg nWriteMSR, eq_self_iff_true, ↓reduceIte, bind_ok, if_pos g2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_rmsr_bv]; exact zv_decode_rmsr_short (by omega) _ ec +/-- **X86VCPUReadMSR, `len < 1`** (module docstring). -/ +theorem JAtZV3.vdRmsrS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 1) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadMSR len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadMSR len p call buf b c r ⦄ := + J.toB.vdRmsrS (fun _ h => J.archV h) hK hVA hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUEnableIOPort on SVM** (module docstring). -/ -theorem JAtZV3.vdEioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdEioA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUEnableIOPort fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUEnableIOPort, fl4_abi.label.X86VCPUSetTCB]) @@ -373,43 +389,47 @@ theorem JAtZV3.vdEioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (h have nWriteMSR := zv_n fl4_abi.label.X86VCPUEnableIOPort fl4_abi.label.X86VCPUWriteMSR (by simp [fl4_abi.label.X86VCPUEnableIOPort, fl4_abi.label.X86VCPUWriteMSR]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, if_neg nReadVMCB, if_neg nWriteVMCB, if_neg nReadMSR, if_neg nWriteMSR, eq_self_iff_true, ↓reduceIte, if_pos h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_eio_bv]; exact zv_decode_eio_amd hvk args _ ec +/-- **X86VCPUEnableIOPort on SVM** (module docstring). -/ +theorem JAtZV3.vdEioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c r ⦄ := + J.toB.vdEioA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUEnableIOPort off SVM, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdEioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdEioS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => hvk (hi2.1 e) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUEnableIOPort fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUEnableIOPort, fl4_abi.label.X86VCPUSetTCB]) @@ -430,42 +450,46 @@ theorem JAtZV3.vdEioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (h have nWriteMSR := zv_n fl4_abi.label.X86VCPUEnableIOPort fl4_abi.label.X86VCPUWriteMSR (by simp [fl4_abi.label.X86VCPUEnableIOPort, fl4_abi.label.X86VCPUWriteMSR]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, if_neg nReadVMCB, if_neg nWriteVMCB, if_neg nReadMSR, if_neg nWriteMSR, eq_self_iff_true, ↓reduceIte, if_neg h2, if_pos g2, error.truncated, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by rw [zv_eio_bv]; exact zv_decode_eio_short hvk (by omega) _ ec +/-- **X86VCPUEnableIOPort off SVM, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdEioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c r ⦄ := + J.toB.vdEioS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUDisableIOPort on SVM** (module docstring). -/ -theorem JAtZV3.vdDioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdDioA + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := by - have B := J.z2.zv.base + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf r ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : i = 2#u64 := hi2.2 hvk rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUDisableIOPort fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUDisableIOPort, fl4_abi.label.X86VCPUSetTCB]) @@ -488,43 +512,47 @@ theorem JAtZV3.vdDioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (h have nEnableIOPort := zv_n fl4_abi.label.X86VCPUDisableIOPort fl4_abi.label.X86VCPUEnableIOPort (by simp [fl4_abi.label.X86VCPUDisableIOPort, fl4_abi.label.X86VCPUEnableIOPort]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, if_neg nReadVMCB, if_neg nWriteVMCB, if_neg nReadMSR, if_neg nWriteMSR, if_neg nEnableIOPort, eq_self_iff_true, ↓reduceIte, if_pos h2, error.illegal, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .IllegalOperation) (e' := .illegalOperation) hct trivial fun args ec hl => by rw [zv_dio_bv]; exact zv_decode_dio_amd hvk args _ ec +/-- **X86VCPUDisableIOPort on SVM** (module docstring). -/ +theorem JAtZV3.vdDioA (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) (len : U64) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := + J.toB.vdDioA (fun _ h => J.archV h) hK hVA hvk hp len call buf ex + set_option maxHeartbeats 16000000 in /-- **X86VCPUDisableIOPort off SVM, `len < 2`** (module docstring). -/ -theorem JAtZV3.vdDioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.vdDioS + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf r ⦄ := by have g2 : len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 have h2 : ¬ i = 2#u64 := fun e => hvk (hi2.1 e) rw [hi, bind_ok] - obtain ⟨f, hf⟩ : ∃ f, (if len > 0#u64 then msg.syscall_arg st s ct buf 0#u64 else ok 0#u64) = ok f := by - split - · obtain ⟨f, hf, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 0#u64 (P1.LawfulStore.total (st := st))) - exact ⟨f, hf⟩ - · exact ⟨_, rfl⟩ - obtain ⟨x, hx⟩ : ∃ x, (if len > 1#u64 then msg.syscall_arg st s ct buf 1#u64 else ok 0#u64) = ok x := by - split - · obtain ⟨x, hx, -⟩ := P1.spec_ex_fd (P0.msg.syscall_arg.p0 st s ct buf 1#u64 (P1.LawfulStore.total (st := st))) - exact ⟨x, hx⟩ - · exact ⟨_, rfl⟩ + obtain ⟨f, hf⟩ := vcpu_arg_or_zero (st := st) s ct buf len 0#u64 + obtain ⟨x, hx⟩ := vcpu_arg_or_zero (st := st) s ct buf len 1#u64 rw [hf, bind_ok, hx, bind_ok] have nSetTCB := zv_n fl4_abi.label.X86VCPUDisableIOPort fl4_abi.label.X86VCPUSetTCB (by simp [fl4_abi.label.X86VCPUDisableIOPort, fl4_abi.label.X86VCPUSetTCB]) @@ -547,9 +575,17 @@ theorem JAtZV3.vdDioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (h have nEnableIOPort := zv_n fl4_abi.label.X86VCPUDisableIOPort fl4_abi.label.X86VCPUEnableIOPort (by simp [fl4_abi.label.X86VCPUDisableIOPort, fl4_abi.label.X86VCPUEnableIOPort]) simp only [if_neg nSetTCB, if_neg nWriteRegisters, if_neg nFlushTLB, if_neg nReadVMCS, if_neg nWriteVMCS, if_neg nReadVMCB, if_neg nWriteVMCB, if_neg nReadMSR, if_neg nWriteMSR, if_neg nEnableIOPort, eq_self_iff_true, ↓reduceIte, if_neg h2, if_pos g2, error.truncated, bind_ok, WP.spec_ok] - exact J1.vdErr (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by + exact VDecPostQ.err J1 (e := .Sys .TruncatedMessage) (e' := .truncatedMessage) hct trivial fun args ec hl => by rw [zv_dio_bv]; exact zv_decode_dio_short hvk (by omega) _ ec +/-- **X86VCPUDisableIOPort off SVM, `len < 2`** (module docstring). -/ +theorem JAtZV3.vdDioS (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : len.val < 2) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := + J.toB.vdDioS (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VDio.lean b/proofs/Fl4Proofs/P3/JAtZV3VDio.lean index b696b9621..b925c07d6 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VDio.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VDio.lean @@ -393,19 +393,23 @@ theorem zv_mask_lt (f : U64) : (f &&& 65535#u64).val < 65536 := by set_option maxHeartbeats 16000000 in /-- **X86VCPUDisableIOPort at `JAtZV3`, VMX, `len ≥ 2`** (module docstring). -/ -theorem JAtZV3.disableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBaseF.disableIoPortJ {sA : S} {σA : Fl4Spec.State Unit} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := by + VDecPostQ st (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac' Lst' D s' a' σ' ∧ + VcpuBindingKeep σ σ') + extra Ac Lst s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf r ⦄ := by have g0 : len > 0#u64 := by scalar_tac have g1 : len > 1#u64 := by scalar_tac have g2 : ¬ len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ @@ -455,17 +459,17 @@ theorem JAtZV3.disableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s simp only [if_pos hlh, error.invalid_arg, bind_ok, WP.spec_ok] exact ⟨ct, hct, fun args ec hA _ => Or.inl ⟨_, .invalidArgument 0, rfl, rfl, by rw [zv_dio_bv, zv_decode_dio_inv hvk (by rw [hA.1]; exact hlen) (hf0 args hA) (hx1 args hA) hgt], - rfl, J1⟩⟩ + rfl, ⟨J1, VcpuBindingKeep.refl _⟩⟩⟩ · have hle : ¬ f.bv &&& 0xffff > x.bv &&& 0xffff := by rw [← zv_mask_bv, ← zv_mask_bv]; exact fun h => hlh ((Sched.gt_bv _ _).2 h) rw [if_neg hlh] unfold vcpu.ports have hlo : (f &&& 65535#u64).val ≤ (x &&& 65535#u64).val := by have := fun h => hlh ((gt_iff_lt).2 h); scalar_tac - have J1' : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a1 + have J1' : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a1 (Notif.updK σ p.bv (.archObj (.vcpu (vsIoLt vs (f &&& 65535#u64).val (f &&& 65535#u64).val true)))) := by rw [vsIoLt_self, v3_updK_self hk]; exact J1 - refine WP.spec_bind (J1'.portsLoopJ hvk hp (zv_mask_lt x) true hk _ s (f &&& 65535#u64) le_rfl + refine WP.spec_bind (J1'.portsLoop hp (zv_mask_lt x) true hk _ s (f &&& 65535#u64) le_rfl (by omega)) fun s6 J6 => ?_ obtain ⟨s7, h7, -⟩ := P1.spec_ex_fd (P0.sched.set_thread_state.p0 st s6 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) @@ -477,7 +481,17 @@ theorem JAtZV3.disableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s exact ⟨ct, hct, fun args ec hA _ => Or.inr ⟨.disableIoPort p.bv (f.bv &&& 0xffff) (x.bv &&& 0xffff), [], s6, _, Ac, Lst, rfl, by rw [zv_dio_bv, zv_decode_dio_ok hvk (by rw [hA.1]; exact hlen) (hf0 args hA) (hx1 args hA) hle], - zv_perform_dio hk _ _, J6, Or.inl ⟨rfl, h7⟩⟩⟩ + zv_perform_dio hk _ _, ⟨J6, VcpuBindingKeep.update hk rfl⟩, Or.inl ⟨rfl, h7⟩⟩⟩ + +theorem JAtZV3.disableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUDisableIOPort len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUDisableIOPort len p call buf b c r ⦄ := by + refine WP.spec_mono (J.toF.disableIoPortJ (extra := StcbCaps b c) hK hVA hvk hp hk hlen call buf ex) ?_ + intro _ h + exact h.mono fun _ _ _ _ _ h' => J.ofF h'.1 end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VDisp.lean b/proofs/Fl4Proofs/P3/JAtZV3VDisp.lean index a4d9fbf18..df59dd4f2 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VDisp.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VDisp.lean @@ -82,19 +82,8 @@ def VDecPostC (arI : machine.Arch A) (V X : Set U64) (AR : A → Fl4Spec.Cr3 → (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s : S) (σ : Fl4Spec.State Unit) (lbl len p : U64) (call : Bool) (buf : U64) (b : Bool) (c : capability.Cap) (x : U64) (r : core.result.Result Unit error.Exc × S × A) : Prop := - ∃ ct : U64, sched.cur_thread st s = ok ct ∧ - ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), VArgs st s ct buf len args → - VCaps Z.th x b c ec → - (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ - ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec) σ = - ExceptT.run (Fl4Spec.NonDetE.throwError (σ := Fl4Spec.State Unit) (α := Fl4Spec.VcpuInvocation) e') σ ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ - (∃ (inv : Fl4Spec.VcpuInvocation) (rep : List Fl4Spec.Data) (s' : S) (σ' : Fl4Spec.State Unit) - (Ac' : Set U64) (Lst' : U64 → List U64), r.1 = .Ok () ∧ - ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) lbl.bv args p.bv ec) σ = - ExceptT.run (Fl4Spec.NonDetE.returnOk (σ := Fl4Spec.State Unit) (ε := Fl4Spec.SyscallError) inv) σ ∧ - Fl4Spec.performVcpuInvocationF (Z := Unit) inv σ = ({(rep, σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D s' r.2.2 σ' ∧ VDecTail st ct call rep s' r.2.1) + VDecPostQ st (fun Ac' Lst' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D) + (VCaps Z.th x b c) Ac Lst s σ lbl len p call buf r theorem VDecPost.toC {arI : machine.Arch A} {V X : Set U64} {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {σ : Fl4Spec.State Unit} diff --git a/proofs/Fl4Proofs/P3/JAtZV3VEio.lean b/proofs/Fl4Proofs/P3/JAtZV3VEio.lean index 8c94f7a08..b161a44a9 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VEio.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VEio.lean @@ -154,30 +154,50 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **X86VCPUEnableIOPort at `JAtZV3`, VMX, `len ≥ 2`** (module docstring). -/ -theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) - (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (hcan : Canonical p) - {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) +theorem VmBase.enableIoPortJ + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) {sl : obj.Slot} {b : Bool} (hsl : Array.index_usize ex 0#usize = ok sl) (hbn : obj.Slot.is_null sl = ok b) {c : capability.Cap} - (hc : b = false → obj.Slot.cap st sl s = ok c) (hio : IoFresh b c) - (hsc : b = false → ∃ pc r idx, Z.th pc = some (.cnode r) ∧ idx.length = r ∧ sl = cslotAddr (pc.bv, idx)) : + (hc : b = false → obj.Slot.cap st sl s = ok c) + (hsc : b = false → ∃ pc r idx, Z.th pc = some (.cnode r) ∧ idx.length = r ∧ sl = cslotAddr (pc.bv, idx)) + (hCore : ∀ a' ct first last prior lo hi pc r idx, + Q Ac Lst s a' σ → Z.th pc = some (.cnode r) → idx.length = r → + sl = cslotAddr (pc.bv, idx) → b = false → c = .IoPort first last prior → + capV (L.mem s) sl = .IoPort first last prior → + first.val < 65536 → last.val < 65536 → first.val ≤ last.val → + lo.val ≤ hi.val → hi.val < 65536 → + (do + let old ← obj.ks_get st s layout.ks.VCPU_HEAD + let (s3, a2) ← vcpu.decode_loop3 st arI s a' first last prior old layout.WALK_FUEL + let s5 ← obj.Slot.set_cap st sl s3 (.IoPort first last p) + let s6 ← vcpu.ports st s5 p lo hi false + let s7 ← sched.set_thread_state st s6 ct sched.TS_RESTART + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s7, a2)) ⦃ res => + ∃ σ' Ac' Lst' s6, res.1 = .Ok () ∧ + Fl4Spec.performVcpuInvocationF (Z := Unit) (.enableIoPort p.bv lo.bv hi.bv + (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) (ioOwnerOf prior)) (pc.bv, idx)) σ = + ({([], σ')}, False) ∧ Q Ac' Lst' s6 res.2.2 σ' ∧ + sched.set_thread_state st s6 ct sched.TS_RESTART = ok res.2.1 ⦄) : vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ rr => - VDecPostC (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c (Ipc.exAt ex 0) + VDecPostQ st Q (VCaps Z.th (Ipc.exAt ex 0) b c) Ac Lst s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf rr ⦄ := by have g0 : len > 0#u64 := by scalar_tac have g1 : len > 1#u64 := by scalar_tac have g2 : ¬ len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 @@ -235,8 +255,8 @@ theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a have ILL : (∀ f' l' q, c ≠ .IoPort f' l' q) → (do let r ← error.illegal Unit - ok (r, s, a1)) ⦃ rr => VDecPostC (L := L) arI V X AR Z H Cs Ac Lst D s σ - fl4_abi.label.X86VCPUEnableIOPort len p call buf false c (Ipc.exAt ex 0) rr ⦄ := by + ok (r, s, a1)) ⦃ rr => VDecPostQ st Q (VCaps Z.th (Ipc.exAt ex 0) false c) Ac Lst s σ + fl4_abi.label.X86VCPUEnableIOPort len p call buf rr ⦄ := by intro hni simp only [error.illegal, bind_ok, WP.spec_ok] refine ⟨ct, hct, fun args ec hA hC => Or.inl ⟨_, .illegalOperation, rfl, trivial, ?_, rfl, J1⟩⟩ @@ -246,11 +266,9 @@ theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a cases c case IoPort first last prior => dsimp only - have hpr : prior = 0#u64 := hio rfl first last prior rfl - subst hpr obtain ⟨pc, r, idx, hpc, hidx, hsle⟩ := hsc rfl subst hsle - have hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort first last 0#u64 := by + have hcx : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort first last prior := by have h' := hc rfl rw [slot_cap_eq] at h' exact capV_of_capAt h' @@ -263,8 +281,8 @@ theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a exact hr0.1 have hfs : BitVec.setWidth 64 (BitVec.ofNat 16 first.val) = first.bv := zv_sw16 hwf.1 have hls : BitVec.setWidth 64 (BitVec.ofNat 16 last.val) = last.bv := zv_sw16 hwf.2.1 - have habs : absCap (.IoPort first last 0#u64) = - .archObjectCap (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) none) := rfl + have habs : absCap (.IoPort first last prior) = + .archObjectCap (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) (ioOwnerOf prior)) := rfl by_cases hl1 : (f &&& 65535#u64) < first · rw [if_pos hl1] simp only [error.invalid_arg, bind_ok, WP.spec_ok] @@ -287,41 +305,11 @@ theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a rintro (h | h) · exact hl1 ((Sched.lt_bv _ _).2 h) · exact hl2 ((Sched.gt_bv _ _).2 h) - obtain ⟨old, hold, -⟩ := P1.spec_ex_fd - (P0.obj.ks_get.p0 st s layout.ks.VCPU_HEAD (P1.LawfulStore.total (st := st))) - rw [hold, bind_ok] - refine WP.spec_bind (zv_walk0 (arI := arI) s a1 first last old layout.WALK_FUEL) ?_ - rintro r3 rfl - show (do - let s4 ← ok (cslotAddr (pc.bv, idx)) - let s5 ← obj.Slot.set_cap st s4 s (capability.Cap.IoPort first last p) - let s6 ← vcpu.ports st s5 p (f &&& 65535#u64) (x &&& 65535#u64) false - let s7 ← sched.set_thread_state st s6 ct sched.TS_RESTART - ok (core.result.Result.Ok (), s7, a1)) ⦃ rr => VDecPostC (L := L) arI V X AR Z H Cs Ac Lst D s σ - fl4_abi.label.X86VCPUEnableIOPort len p call buf false (.IoPort first last 0#u64) (Ipc.exAt ex 0) rr ⦄ - rw [bind_ok] - refine WP.spec_bind (J1.ioOwnJ hpc hidx hcx hp hcan) ?_ - rintro s5 ⟨σ5, hσ5, hvk5, J5, -, -⟩ - have hk5 : σ5.kheap p.bv = some (.archObj (.vcpu vs)) := by rw [hvk5 p hp]; exact hk - have hop : ioOwnerOf p = some p.bv := by - unfold ioOwnerOf - rw [if_neg (fun h => J.z2.zv.extv.nz p hp (UScalar.eq_of_val_eq (by rw [h]; rfl)))] - have hσ5' : Fl4Spec.setCap (Z := Unit) (.archObjectCap (.ioPortCap (BitVec.ofNat 16 first.val) - (BitVec.ofNat 16 last.val) (some p.bv))) (pc.bv, idx) σ = ({((), σ5)}, False) := by - rw [← hop]; exact hσ5 - unfold vcpu.ports - have J5' : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s5 a1 - (Notif.updK σ5 p.bv (.archObj (.vcpu (vsIoLt vs (f &&& 65535#u64).val (f &&& 65535#u64).val false)))) := by - rw [vsIoLt_self, v3_updK_self hk5]; exact J5 - refine WP.spec_bind (J5'.portsLoopJ hvk hp (zv_mask_lt x) false hk5 _ s5 (f &&& 65535#u64) le_rfl - (by omega)) fun s6 J6 => ?_ - obtain ⟨s7, h7, -⟩ := P1.spec_ex_fd - (P0.sched.set_thread_state.p0 st s6 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) - rw [h7, bind_ok, WP.spec_ok] - have eP : vsIoLt vs (f &&& 65535#u64).val ((x &&& 65535#u64).val + 1) false = - vs.setPorts (f.bv &&& 0xffff) (x.bv &&& 0xffff) false := - vsIoLt_setPorts vs false (by rw [← zv_mask_bv, UScalar.bv_toNat]) (by rw [← zv_mask_bv, UScalar.bv_toNat]) - rw [eP] at J6 + simp only [bind_ok] + refine WP.spec_mono (hCore a1 ct first last prior (f &&& 65535#u64) (x &&& 65535#u64) + pc r idx J1 hpc hidx rfl rfl rfl hcx hwf.1 hwf.2.1 hwf.2.2 + (by exact le_of_not_gt hlh) (zv_mask_lt x)) ?_ + rintro res ⟨σ', Ac', Lst', s6, hok, hperf, J6, h7⟩ refine ⟨ct, hct, fun args ec hA' hC => ?_⟩ obtain ⟨cp, rest, hec, hAc, hcxe⟩ := hC.2 rfl have hx0 : Ipc.exAt ex 0 = cslotAddr (pc.bv, idx) := by @@ -331,12 +319,56 @@ theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a have hcp : cp = (pc.bv, idx) := cslotAddr_inj B.xtop.rel.1 hAc hA (hcxe.trans hx0) subst hcp exact Or.inr ⟨.enableIoPort p.bv (f.bv &&& 0xffff) (x.bv &&& 0xffff) - (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) none) (pc.bv, idx), [], s6, _, Ac, Lst, rfl, + (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) (ioOwnerOf prior)) (pc.bv, idx), [], s6, σ', Ac', Lst', hok, by rw [hec, habs, zv_eio_bv, zv_decode_eio_ok hvk (by rw [hA'.1]; exact hlen) (hf0 args hA') (hx1 args hA') hle p.bv _ _ _ (pc.bv, idx) rest hr], - zv_perform_eio hk5 _ _ _ _ _ hσ5', J6, Or.inl ⟨rfl, h7⟩⟩ + by rw [← zv_mask_bv, ← zv_mask_bv]; exact hperf, J6, Or.inl ⟨rfl, h7⟩⟩ all_goals (dsimp only; exact ILL (fun f' l' q e => by cases e)) +/-- **X86VCPUEnableIOPort at `JAtZV3`, VMX, `len ≥ 2`** (module docstring). -/ +theorem JAtZV3.enableIoPortJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) (hcan : Canonical p) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) + (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) {sl : obj.Slot} {b : Bool} + (hsl : Array.index_usize ex 0#usize = ok sl) (hbn : obj.Slot.is_null sl = ok b) {c : capability.Cap} + (hc : b = false → obj.Slot.cap st sl s = ok c) (hio : IoFresh b c) + (hsc : b = false → ∃ pc r idx, Z.th pc = some (.cnode r) ∧ idx.length = r ∧ sl = cslotAddr (pc.bv, idx)) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUEnableIOPort len p call buf ex ⦃ rr => + VDecPostC (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUEnableIOPort len p call buf b c (Ipc.exAt ex 0) + rr ⦄ := by + refine J.toB.enableIoPortJ (Q := fun Ac' Lst' => JAtZV3 (L := L) arI V X AR Z H Cs Ac' Lst' D) (fun _ h => J.archV h) hK hVA hvk hp hlen call buf ex hsl hbn hc hsc ?_ + intro a1 ct first last prior lo hi pc r idx J1 hpc hidx hsle hb0 hC hcx _ _ _ hlo hhi + have hpr : prior = 0#u64 := hio hb0 first last prior hC + subst prior sl + obtain ⟨old, hold, -⟩ := P1.spec_ex_fd + (P0.obj.ks_get.p0 st s layout.ks.VCPU_HEAD (P1.LawfulStore.total (st := st))) + rw [hold, bind_ok] + refine WP.spec_bind (zv_walk0 (arI := arI) s a1 first last old layout.WALK_FUEL) ?_ + rintro r3 rfl + refine WP.spec_bind (J1.ioOwnJ hpc hidx hcx hp hcan) ?_ + rintro s5 ⟨σ5, hσ5, hvk5, J5, -, -⟩ + have hk5 : σ5.kheap p.bv = some (.archObj (.vcpu vs)) := by rw [hvk5 p hp]; exact hk + have hop : ioOwnerOf p = some p.bv := by + unfold ioOwnerOf + rw [if_neg (fun h => J1.z2.zv.extv.nz p hp (UScalar.eq_of_val_eq (by rw [h]; rfl)))] + have hσ5' : Fl4Spec.setCap (Z := Unit) (.archObjectCap (.ioPortCap (BitVec.ofNat 16 first.val) + (BitVec.ofNat 16 last.val) (some p.bv))) (pc.bv, idx) σ = ({((), σ5)}, False) := by + rw [← hop]; exact hσ5 + unfold vcpu.ports + have J5' : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s5 a1 + (Notif.updK σ5 p.bv (.archObj (.vcpu (vsIoLt vs lo.val lo.val false)))) := by + rw [vsIoLt_self, v3_updK_self hk5]; exact J5 + refine WP.spec_bind (J5'.portsLoopJ hvk hp hhi false hk5 _ s5 lo le_rfl + (by omega)) fun s6 J6 => ?_ + obtain ⟨s7, h7, -⟩ := P1.spec_ex_fd + (P0.sched.set_thread_state.p0 st s6 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) + rw [h7, bind_ok, WP.spec_ok] + have eP : vsIoLt vs lo.val (hi.val + 1) false = + vs.setPorts lo.bv hi.bv false := + vsIoLt_setPorts vs false (UScalar.bv_toNat lo).symm (by rw [UScalar.bv_toNat]) + rw [eP] at J6 + exact ⟨_, Ac, Lst, s6, rfl, zv_perform_eio hk5 _ _ _ _ _ hσ5', J6, h7⟩ + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VFront.lean b/proofs/Fl4Proofs/P3/JAtZV3VFront.lean index c734329ed..2df69d1c9 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VFront.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VFront.lean @@ -87,10 +87,10 @@ theorem JAtZV3.ipcBuf (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) : ⟨J.z2.zv.base.bok, bufCover_of_frameCover J.z2.zv.base.bok J.z2.zv.base.fcov⟩ /-- **The sending buffer's MR words are off every VCPU** (module docstring). -/ -theorem JAtZV3.bufOut (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) +theorem JAtZB.bufOut (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hVm : JVm (L := L) V H s σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) {buf : U64} (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) : BufOut V buf := by - have B := J.z2.zv.base obtain ⟨hcur, -⟩ := B.curEq hct obtain ⟨htcb, xs, hks⟩ := B.xtop.curTcb hcur have hctT : ct ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm @@ -108,7 +108,13 @@ theorem JAtZV3.bufOut (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) have hi : (core.num.U64.wrapping_add j 1#u64).val < 128 := by rw [core.num.U64.wrapping_add_val_eq] exact lt_of_le_of_lt (Nat.mod_le _ _) (by simp; omega) - exact B.bWord J.z2.zv.vm (hm _ hi) + exact B.bWord hVm (hm _ hi) + +/-- The sending buffer words at the V3 relation. -/ +theorem JAtZV3.bufOut (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) + {buf : U64} (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) : BufOut V buf := + J.z2.zv.base.bufOut J.z2.zv.vm hct hbuf theorem zv_map_mk (args : List Fl4Spec.Data) : (args.map fun d => (⟨d⟩ : U64)).map UScalar.bv = args := by induction args with @@ -118,7 +124,7 @@ theorem zv_map_mk (args : List Fl4Spec.Data) : (args.map fun d => (⟨d⟩ : U64 rw [ih] /-- **The spec's arguments against FL4's `syscall_arg` words** (module docstring). -/ -theorem JAtZV3.vargs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) +theorem JAtZB.vargs (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) {info : msginfo.MessageInfo} (hinfo : msg.msg_info st s ct = ok info) {mi : Fl4Spec.MessageInfo} (hmi : Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False)) @@ -129,7 +135,7 @@ theorem JAtZV3.vargs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) VArgs st s ct buf (msgLen info buf) args := by have hmrs' : Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({((args.map fun d => (⟨d⟩ : U64)).map UScalar.bv, σ)}, False) := by rw [zv_map_mk]; exact hmrs - obtain ⟨hlen, hget, -⟩ := J.z2.zv.base.argsJ J.ipcBuf.1 J.ipcBuf.2 hct hinfo hmi hbuf hbuffer hmrs' + obtain ⟨hlen, hget, -⟩ := J.argsJ J.xferH.1 J.xferH.2.1 hct hinfo hmi hbuf hbuffer hmrs' rw [List.length_map] at hlen refine ⟨hlen.symm, fun i w hi hw => ?_⟩ have hil : i < args.length := by omega @@ -146,6 +152,18 @@ theorem JAtZV3.vargs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) show args.getD i 0 = args[i] rw [List.getD_eq_getElem] +/-- The spec arguments at the V3 relation. -/ +theorem JAtZV3.vargs (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) + {info : msginfo.MessageInfo} (hinfo : msg.msg_info st s ct = ok info) + {mi : Fl4Spec.MessageInfo} (hmi : Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False)) + {buf : U64} (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) + {buffer : Option Fl4Spec.ObjRef} + (hbuffer : Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False)) + {args : List Fl4Spec.Data} (hmrs : Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(args, σ)}, False)) : + VArgs st s ct buf (msgLen info buf) args := + J.z2.zv.base.vargs hct hinfo hmi hbuf hbuffer hmrs + /-- **A VCPU cap of a slot names a VCPU of `V` with its spec object** (module docstring). -/ theorem JAtZV3.vcpuCapV (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {x p : U64} (hx : IsSlot Z.th x) (hc : capV (L.mem s) x = .Vcpu p) : diff --git a/proofs/Fl4Proofs/P3/JAtZV3VRmsr.lean b/proofs/Fl4Proofs/P3/JAtZV3VRmsr.lean index 64f0beb43..b8cd55397 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VRmsr.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VRmsr.lean @@ -62,25 +62,29 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **X86VCPUReadMSR at `JAtZV3`, `len ≥ 1`** (module docstring). -/ -theorem JAtZV3.readMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.readMsrJ + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 1 ≤ len.val) - (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadMSR len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadMSR len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadMSR len p call buf r ⦄ := by have g0 : len > 0#u64 := by scalar_tac have g1 : ¬ len < 1#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 @@ -167,7 +171,7 @@ theorem JAtZV3.readMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (P0.vcpu.reply.p0 st s call (L.mem s y) (P1.LawfulStore.total (st := st))) rw [h4, bind_ok, WP.spec_ok] have hin : f.bv ∈ Fl4Spec.vcpuMsrs := (VirtMsrEq.msrOff_isSome _ _).1 (by rw [ho']; rfl) - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ obtain ⟨-, b1, b2, -, -⟩ := VirtMsrStore.msrOff_cases ho' have ey : y = ⟨p.bv + o'⟩ := by rcases y with ⟨b⟩; exact congrArg (fun b => (⟨b⟩ : U64)) hyb @@ -191,6 +195,15 @@ theorem JAtZV3.readMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) Or.inr (Or.inl ⟨_, rfl, h4⟩)⟩⟩ rw [zv_rmsr_bv, zv_decode_rmsr_ok (by rw [hA.1]; exact hlen) (hA.a0 (by omega) hf) hfm hin] +/-- **X86VCPUReadMSR at `JAtZV3`, `len ≥ 1`** (module docstring). -/ +theorem JAtZV3.readMsrJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') {p : U64} (hp : p ∈ V) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 1 ≤ len.val) + (call : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadMSR len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadMSR len p call buf b c r ⦄ := + J.toB.readMsrJ (fun _ h => J.archV h) hK hVA hCap hp hk hlen call buf ex + end end diff --git a/proofs/Fl4Proofs/P3/JAtZV3VRvmcb.lean b/proofs/Fl4Proofs/P3/JAtZV3VRvmcb.lean index 5296800da..85775ad98 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VRvmcb.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VRvmcb.lean @@ -237,15 +237,15 @@ theorem zv_rvmcb_word (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hv : VFits p) { set_option maxHeartbeats 16000000 in /-- **FL4's `decode_loop1` is `vcpuReplyWsLoop` over the spec's words** (module docstring). -/ -theorem JAtZV3.rvmcbLoop (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} +theorem VmBaseF.rvmcbLoop {sA : S} {σA : Fl4Spec.State Unit} (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {ct : U64} (hct : ct ∈ Z.T) {x0 : Fl4Spec.Tcb} (hkx : σ.kheap ct.bv = some (.tcb x0)) {pb : Option Fl4Spec.ObjRef} (hq : ∀ q, pb = some q → Endp.ipcBufOf true x0 = some q) {b : U64} (hb : JBufR Z.B b pb) {f value : U64} (hf8 : f.val % 8 = 0) (hfv : f.val + 8 * value.val ≤ 1768) (hv64 : value.val ≤ 64) - (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) : + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) : vcpu.decode_loop1 st s p ct f value b 0#u64 0#u64 ⦃ r => vcpuReplyWsLoop st ct b s (rvWs vs f.bv value.val) 0#u64 0#u64 = ok r ⦄ := by - have hfv' := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv' := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv'.1, hfv'.2⟩ have hpc : p.bv ≠ ct.bv := by intro e; rw [e, hkx] at hk; simp at hk @@ -253,7 +253,7 @@ theorem JAtZV3.rvmcbLoop (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V unfold vcpu.decode_loop1 apply loop.spec_decr_nat (measure := fun y : S × U64 × U64 => value.val - y.2.1.val) (inv := fun y => y.2.1.val ≤ value.val ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D y.1 a + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D y.1 a (jMrSt σ ct.bv x0 pb (((rvWs vs f.bv value.val).take y.2.1.val).map (·.bv))) ∧ vcpuReplyWsLoop st ct b s (rvWs vs f.bv value.val) 0#u64 0#u64 = vcpuReplyWsLoop st ct b y.1 ((rvWs vs f.bv value.val).drop y.2.1.val) y.2.1 y.2.2) · rintro ⟨s1, i, n⟩ ⟨g1, J1, hE⟩ @@ -277,7 +277,7 @@ theorem JAtZV3.rvmcbLoop (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V refine WP.spec_bind (zv_rvmcb_word hvk hv R hf8 (by omega)) fun val hval => ?_ have hms : (((rvWs vs f.bv value.val).take i.val).map (·.bv)).length = i.val := by simp [hwl]; omega obtain ⟨r, hr, -⟩ := P1.spec_ex_fd (P0.msg.set_mr.p0 st s1 ct b i val (P1.LawfulStore.total (st := st))) - have hJ := setMrJ3 J1 hct hq hb i (by rw [hms]) (by rw [hms]; omega) val + have hJ := J1.setMr hct hq hb i (by rw [hms]) (by rw [hms]; omega) val rw [hr, WP.spec_ok] at hJ refine WP.spec_bind (Pₘ := fun r' => r' = r) (by rw [hr]; exact (WP.spec_ok _).2 rfl) ?_ rintro ⟨n1, s2⟩ e @@ -307,10 +307,21 @@ theorem JAtZV3.rvmcbLoop (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V rw [h2e, bind_ok] · show value.val - i2.val < value.val - i.val; omega · refine ⟨Nat.zero_le _, ?_, rfl⟩ - show JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x0 pb (((rvWs vs f.bv value.val).take 0).map (·.bv))) + show VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a (jMrSt σ ct.bv x0 pb (((rvWs vs f.bv value.val).take 0).map (·.bv))) rw [List.take_zero, List.map_nil, jMrSt_nil hkx] exact J +/-- **FL4's `decode_loop1` is `vcpuReplyWsLoop` over the spec's words** (module docstring). -/ +theorem JAtZV3.rvmcbLoop (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {ct : U64} (hct : ct ∈ Z.T) {x0 : Fl4Spec.Tcb} + (hkx : σ.kheap ct.bv = some (.tcb x0)) {pb : Option Fl4Spec.ObjRef} + (hq : ∀ q, pb = some q → Endp.ipcBufOf true x0 = some q) {b : U64} (hb : JBufR Z.B b pb) {f value : U64} + (hf8 : f.val % 8 = 0) (hfv : f.val + 8 * value.val ≤ 1768) (hv64 : value.val ≤ 64) + (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) : + vcpu.decode_loop1 st s p ct f value b 0#u64 0#u64 ⦃ r => + vcpuReplyWsLoop st ct b s (rvWs vs f.bv value.val) 0#u64 0#u64 = ok r ⦄ := + J.toF.rvmcbLoop hvk hp hk hct hkx hq hb hf8 hfv hv64 + end /-! ## The invocation -/ @@ -323,27 +334,31 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCB at `JAtZV3`, SVM, `len ≥ 2`** (module docstring). -/ -theorem JAtZV3.readVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.readVmcbJ + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCB len p call buf r ⦄ := by have g0 : len > 0#u64 := by scalar_tac have g1 : len > 1#u64 := by scalar_tac have g2 : ¬ len < 2#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) - obtain ⟨Q, R, hc, -⟩ := hS.lists + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) + obtain ⟨_, _, hc, -⟩ := hS.lists unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, ect⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) have hctT : ct ∈ Z.T := by rw [ect, hc.cur]; exact hc.curT rw [hct, bind_ok] @@ -376,7 +391,7 @@ theorem JAtZV3.readVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) rw [UScalar.bv_and, BitVec.toNat_eq, BitVec.toNat_and, show (7#u64 : U64).bv.toNat = 2 ^ 3 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod]; rfl have herr : (f.val % 8 ≠ 0 ∨ 1768 ≤ f.val ∨ x.val = 0 ∨ 64 < x.val ∨ (1768 - f.val) / 8 < x.val) → - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCB len p call buf (.Err (.Sys (.InvalidArgument 0#u64)), s, a1) := fun hC => ⟨ct, hct, fun args ec hA _ => Or.inl ⟨_, .invalidArgument 0, rfl, rfl, by rw [zv_rvmcb_bv, zv_decode_rvmcb_inv hvk (by rw [hA.1]; exact hlen) (hf0 args hA) (hx1 args hA) @@ -450,7 +465,7 @@ theorem JAtZV3.readVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) exact ⟨(fun e => by have := hrw0.1 e; rw [hrb] at this; cases this), hBC ct hctT x0 true rp hkx hrb bw hrwv, hrwv⟩ rw [hbw, bind_ok] - refine WP.spec_bind (J1.rvmcbLoop hvk hp hk hctT hkx (fun q h => h) hb c1 hx8 (by omega)) ?_ + refine WP.spec_bind ((J.archV hAR1).toF.rvmcbLoop hvk hp hk hctT hkx (fun q h => h) hb c1 hx8 (by omega)) ?_ rintro ⟨s2, n⟩ hL try simp only [uncurry_apply_pair] obtain ⟨s3, h3s, -⟩ := P1.spec_ex_fd @@ -477,6 +492,15 @@ theorem JAtZV3.readVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) sched.set_thread_state st s4 ct sched.TS_RUNNING) = ok s5 rw [h3s, bind_ok, hmi, bind_ok, h4s, bind_ok, h5s] +/-- **X86VCPUReadVMCB at `JAtZV3`, SVM, `len ≥ 2`** (module docstring). -/ +theorem JAtZV3.readVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hVA : ZvVirtAgree arI) (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCB len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCB len p call buf b c r ⦄ := + J.toB.readVmcbJ (fun _ h => J.archV h) hK hVA hvk hp hk hlen call buf ex + end section diff --git a/proofs/Fl4Proofs/P3/JAtZV3VRvmcs.lean b/proofs/Fl4Proofs/P3/JAtZV3VRvmcs.lean index 9af05d582..aefc084d0 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3VRvmcs.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3VRvmcs.lean @@ -155,26 +155,30 @@ theorem zv_rsupp {a2 : A} (hc : VirtSanEq.CapAgree arI a2) (f : U64) : set_option maxHeartbeats 16000000 in /-- **X86VCPUReadVMCS at `JAtZV3`, off SVM, `len ≥ 1`** (module docstring). -/ -theorem JAtZV3.readVmcsJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) +theorem VmBase.readVmcsJ + {Q : Set U64 → (U64 → List U64) → S → A → Fl4Spec.State Unit → Prop} + {extra : List (Fl4Spec.Cap × Fl4Spec.CslotPtr) → Prop} + (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + (hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ) (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 1 ≤ len.val) (call : Bool) (buf : U64) - (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + (ex : Array obj.Slot 3#usize) : vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => - VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := by + VDecPostQ st Q extra Ac Lst s σ fl4_abi.label.X86VCPUReadVMCS len p call buf r ⦄ := by have g0 : len > 0#u64 := by scalar_tac have g1 : ¬ len < 1#u64 := by scalar_tac - have B := J.z2.zv.base + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) unfold vcpu.decode refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ rintro ⟨s1, a1⟩ ⟨e1, hAR1⟩ try simp only [uncurry_apply_pair] try simp only at e1 hAR1 subst s1 - have J1 := J.archV hAR1 + have J1 := hQ _ hAR1 obtain ⟨ct, hct, -⟩ := P1.spec_ex_fd (P1.sched.cur_thread.spec (st := st) s) rw [hct, bind_ok] obtain ⟨i, hi, hi2, -⟩ := hVA a1 @@ -204,10 +208,10 @@ theorem JAtZV3.readVmcsJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) by_cases hrd : Fl4Spec.Vmx.readable f.bv = true · rw [if_pos hrd] refine WP.spec_bind (hSy a1 p f _ hAR1) fun a2 hAR2 => ?_ - have J2 := J.archV hAR2 + have J2 := hQ _ hAR2 rw [zv_rsupp (hCap a2) f, bind_ok] -- the word FL4 reads - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ have ho := VirtMsrStore.vmcsOff_nat f.bv have hval : (L.mem s ⟨p.bv + Fl4Spec.vmcsOff f.bv⟩).bv = vs.get Fl4Spec.virtKind (.vmcs f.bv) := by @@ -249,6 +253,16 @@ theorem JAtZV3.readVmcsJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) rw [zv_rvmcs_bv, zv_decode_rvmcs_bad hvk (by rw [hA.1]; exact hlen) (hf0 args hA) hrd' _ ec], rfl, J1⟩⟩ +/-- **X86VCPUReadVMCS at `JAtZV3`, off SVM, `len ≥ 1`** (module docstring). -/ +theorem JAtZV3.readVmcsJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hvk : Fl4Spec.virtKind ≠ .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 1 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) (b : Bool) (c : capability.Cap) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUReadVMCS len p call buf ex ⦃ r => + VDecPost (L := L) arI V X AR Z H Cs Ac Lst D s σ fl4_abi.label.X86VCPUReadVMCS len p call buf b c r ⦄ := + J.toB.readVmcsJ (fun _ h => J.archV h) hK hSy hVA hCap hvk hp hk hlen call buf ex + end section diff --git a/proofs/Fl4Proofs/P3/JAtZV3Vmcb.lean b/proofs/Fl4Proofs/P3/JAtZV3Vmcb.lean index f5202bbfd..02ed2d572 100644 --- a/proofs/Fl4Proofs/P3/JAtZV3Vmcb.lean +++ b/proofs/Fl4Proofs/P3/JAtZV3Vmcb.lean @@ -50,17 +50,22 @@ theorem v3_wrAtV {p : U64} (hv : VFits p) {o : Fl4Spec.Word} (h1 : o.toNat < 327 · rw [v3_vmemW_al hv h1 h2]; exact w1 · rw [v3_vmemW_al hv g1 g2, v3_vmemW_al hv g1 g2]; exact w2 off g1 g2 hne -theorem JAtZV3.relSvm (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBase.relSvm (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : Fl4Spec.VcpuRelSvm (vmemW (L.mem s)) p.bv vs := by have R0 := J.vr p hp vs hk rw [hvk] at R0 exact R0 -theorem JAtZV3.relSvmW (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem JAtZV3.relSvm (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + Fl4Spec.VcpuRelSvm (vmemW (L.mem s)) p.bv vs := + J.toB.relSvm hp hvk hk + +theorem VmBase.relSvmW (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : Fl4Spec.VcpuRelSvm (VirtInitWalk.memW st s) p.bv vs := by - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ refine VirtReplyKeep.VcpuRelSvm.congrA (fun o ho h2 => ?_) (J.relSvm hp hvk hk) have h1 : o.toNat < 32768 := by @@ -70,16 +75,21 @@ theorem JAtZV3.relSvmW (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) { rw [v3_vmemW_al hv h1 h2] rfl +theorem JAtZV3.relSvmW (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + Fl4Spec.VcpuRelSvm (VirtInitWalk.memW st s) p.bv vs := + J.toB.relSvmW hp hvk hk + set_option maxHeartbeats 4000000 in /-- **An aligned VCPU store paired with the spec VCPU it relates to keeps `JAtZV3`** (SVM; module docstring). -/ -theorem JAtZV3.svmStep (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBaseF.svmStep {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {o : Fl4Spec.Word} (h1 : o.toNat < 32768) (h2 : o.toNat % 8 = 0) (hl : o.toNat ≠ 20480 ∧ o.toNat ≠ 20488 ∧ o.toNat ≠ 20496) {x : U64} (hx : x.bv = p.bv + o) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) (vs' : Fl4Spec.VcpuState) (ht : Fl4Spec.VcpuState.tcb vs' = Fl4Spec.VcpuState.tcb vs) (hR : ∀ mem', VirtMsrStore.WrAt (vmemW (L.mem s)) mem' p.bv o val.bv → Fl4Spec.VcpuRelSvm mem' p.bv vs') : - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu vs'))) := by - have hfv := (J.z2.zv.base.jvLay J.z2.zv.vm).vfit p hp + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu vs'))) := by + have hfv := (J.base.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ have hxv : x.val = p.val + o.toNat := by have e : x = ⟨p.bv + o⟩ := by rcases x with ⟨b⟩; exact congrArg (fun b => (⟨b⟩ : U64)) hx @@ -90,41 +100,71 @@ theorem JAtZV3.svmStep (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) { exact J.vcpuStep hp hal (by rw [hxv]; omega) (by rw [hxv]; omega) ⟨by rw [hxv]; omega, by rw [hxv]; omega, by rw [hxv]; omega⟩ val hk vs' ht hR' +theorem JAtZV3.svmStep (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {o : Fl4Spec.Word} (h1 : o.toNat < 32768) (h2 : o.toNat % 8 = 0) + (hl : o.toNat ≠ 20480 ∧ o.toNat ≠ 20488 ∧ o.toNat ≠ 20496) {x : U64} (hx : x.bv = p.bv + o) (val : U64) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) (vs' : Fl4Spec.VcpuState) + (ht : Fl4Spec.VcpuState.tcb vs' = Fl4Spec.VcpuState.tcb vs) + (hR : ∀ mem', VirtMsrStore.WrAt (vmemW (L.mem s)) mem' p.bv o val.bv → Fl4Spec.VcpuRelSvm mem' p.bv vs') : + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu vs'))) := + J.ofF (J.toF.svmStep hp hvk h1 h2 hl hx val hk vs' ht hR) + theorem v3_updK_self {σ : Fl4Spec.State Unit} {p : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject} (hk : σ.kheap p = some o) : Notif.updK σ p o = σ := by unfold Notif.updK rw [show Function.update σ.kheap p (some o) = σ.kheap from by rw [← hk]; exact Function.update_eq_self _ _] /-- The VMCB RAX word stored: spec unchanged (`keep_word`). -/ -theorem JAtZV3.vmcbRaxWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBaseF.vmcbRaxWr {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {x : U64} (hx : x.bv = p.bv + Fl4Spec.Svm.rax) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a σ := by + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s x val) a σ := by have h := J.svmStep hp hvk (o := Fl4Spec.Svm.rax) (by decide) (by decide) (by decide) hx val hk vs rfl - (fun _ hw => VirtVmcbStore.VcpuRelSvm.keep_word (J.relSvm hp hvk hk) hw (Or.inl rfl)) + (fun _ hw => VirtVmcbStore.VcpuRelSvm.keep_word (J.toVmBase.relSvm hp hvk hk) hw (Or.inl rfl)) rwa [v3_updK_self hk] at h +theorem JAtZV3.vmcbRaxWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {x : U64} (hx : x.bv = p.bv + Fl4Spec.Svm.rax) (val : U64) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a σ := + J.ofF (J.toF.vmcbRaxWr hp hvk hx val hk) + /-- A writable VMCB word other than RAX stored, paired with the spec's field update (`store_vmcb`). -/ -theorem JAtZV3.vmcbWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBaseF.vmcbWr {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {f : Fl4Spec.Word} (hf : Fl4Spec.Svm.writable f = true) (hr : f ≠ Fl4Spec.Svm.rax) {x : U64} (hx : x.bv = p.bv + f) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.vmcb f) val.bv)))) := by obtain ⟨fa, fl⟩ := VirtVmcbStore.svm_writable_nat hf rw [hvk] exact J.svmStep hp hvk (o := f) (by omega) fa (by omega) hx val hk _ rfl - (fun _ hw => VirtVmcbStore.VcpuRelSvm.store_vmcb (J.relSvm hp hvk hk) hf hr hw) + (fun _ hw => VirtVmcbStore.VcpuRelSvm.store_vmcb (J.toVmBase.relSvm hp hvk hk) hf hr hw) + +theorem JAtZV3.vmcbWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {f : Fl4Spec.Word} (hf : Fl4Spec.Svm.writable f = true) (hr : f ≠ Fl4Spec.Svm.rax) + {x : U64} (hx : x.bv = p.bv + f) (val : U64) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.vmcb f) val.bv)))) := + J.ofF (J.toF.vmcbWr hp hvk hf hr hx val hk) /-- RAX's `REGS` copy stored after the RAX word, paired with the spec's RAX update (`store_rax`). -/ -theorem JAtZV3.regsWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) +theorem VmBaseF.regsWr {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) (hvk : Fl4Spec.virtKind = .svm) {x : U64} (hx : x.bv = p.bv + Fl4Spec.VcpuLay.REGS) (val : U64) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D (L.wr s x val) a (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.vmcb Fl4Spec.Svm.rax) val.bv)))) := by rw [hvk] exact J.svmStep hp hvk (o := Fl4Spec.VcpuLay.REGS) (by decide) (by decide) (by decide) hx val hk _ rfl - (fun _ hw => VirtVmcbStore.VcpuRelSvm.store_rax (J.relSvm hp hvk hk) hw) + (fun _ hw => VirtVmcbStore.VcpuRelSvm.store_rax (J.toVmBase.relSvm hp hvk hk) hw) + +theorem JAtZV3.regsWr (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) {p : U64} (hp : p ∈ V) + (hvk : Fl4Spec.virtKind = .svm) {x : U64} (hx : x.bv = p.bv + Fl4Spec.VcpuLay.REGS) (val : U64) + {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) : + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D (L.wr s x val) a + (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.vmcb Fl4Spec.Svm.rax) val.bv)))) := + J.ofF (J.toF.regsWr hp hvk hx val hk) end @@ -158,7 +198,7 @@ theorem zv_wvmcb_bv : fl4_abi.label.X86VCPUWriteVMCB.bv = (78 : Fl4Spec.Data) := set_option maxHeartbeats 16000000 in /-- **X86VCPUWriteVMCB at `JAtZV3`, paired with the spec's decode and perform** (module docstring). -/ -theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) +theorem VmBaseF.writeVmcbJ {sA : S} {σA : Fl4Spec.State Unit} (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) @@ -171,20 +211,20 @@ theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteVMCB.bv args p.bv ec) σ = ExceptT.run (Fl4Spec.NonDetE.throwError (σ := Fl4Spec.State Unit) (α := Fl4Spec.VcpuInvocation) e') σ ∧ - r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + r.2.1 = s ∧ VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s r.2.2 σ) ∨ (∃ (y : U64) (s3 : S) (σ' : Fl4Spec.State Unit), r.1 = .Ok () ∧ ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteVMCB.bv args p.bv ec) σ = ExceptT.run (Fl4Spec.NonDetE.returnOk (σ := Fl4Spec.State Unit) (ε := Fl4Spec.SyscallError) (.writeVmcb p.bv f.bv y.bv)) σ ∧ Fl4Spec.performVcpuInvocation (Z := Unit) (.writeVmcb p.bv f.bv y.bv) σ = ({([y.bv], σ')}, False) ∧ - JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call y = ok r.2.1) ⦄ := by - have B := J.z2.zv.base + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call y = ok r.2.1) ⦄ := by + have B := J.base have hS := B.xtop.fin.1.1.1 have hvt : L.mem s (vTcbA p) = 0#u64 ∨ L.mem s (vTcbA p) ∈ Z.T := - (J.z2.zv.extv.back p hp).imp id (fun h => B.thT _ h.1) - have hfv := (B.jvLay J.z2.zv.vm).vfit p hp + (J.extv.back p hp).imp id (fun h => B.thT _ h.1) + have hfv := (B.jvLay J.vm).vfit p hp have hv : VFits p := ⟨hfv.1, hfv.2⟩ - have hRm := J.relSvmW hp hvk hk + have hRm := J.toVmBase.relSvmW hp hvk hk have g2 : ¬ len < 2#u64 := by scalar_tac rw [VirtVmcbDec.decode_wrvmcb_eq (st := st) s a len p call buf ex g2] refine WP.spec_bind (zv_vcpu_stall_id (arI := arI) hK hS a B.ar hvt) ?_ @@ -259,7 +299,7 @@ theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun b _ => ?_ by_cases hra : f.bv = Fl4Spec.Svm.rax · have J2 := J1.vmcbRaxWr hp hvk (by rw [hx1, hra]) y hk - refine WP.spec_bind (Pₘ := fun s3 => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 a1 σ) ?_ fun s3 J3 => ?_ + refine WP.spec_bind (Pₘ := fun s3 => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s3 a1 σ) ?_ fun s3 J3 => ?_ · split · exact WP.spec_mono (vset_eq _ p vcpu.SVM_CPU 0#u64) fun s3 e3 => by rw [e3]; exact J2.svmWr hp 0#u64 @@ -275,7 +315,7 @@ theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ rw [← hra] exact zv_perform_wvmcb2 hk _ _ · have J2 := J1.vmcbWr hp hvk hwf hra hx1 y hk - refine WP.spec_bind (Pₘ := fun s3 => JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 a1 + refine WP.spec_bind (Pₘ := fun s3 => VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s3 a1 (Notif.updK σ p.bv (.archObj (.vcpu (vs.set Fl4Spec.virtKind (.vmcb f.bv) y.bv))))) ?_ fun s3 J3 => ?_ · split · exact WP.spec_mono (vset_eq _ p vcpu.SVM_CPU 0#u64) fun s3 e3 => by @@ -289,6 +329,33 @@ theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ by first | rfl | exact hx, fun args ec hl h0 h1 => Or.inr ⟨y, s3, _, rfl, hspec args ec hl h0 h1, zv_perform_wvmcb2 hk _ _, J3, h5⟩⟩ +theorem JAtZV3.writeVmcbJ (J : JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s a σ) + (hK : ARKeep arI AR) (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hvk : Fl4Spec.virtKind = .svm) {p : U64} (hp : p ∈ V) {vs : Fl4Spec.VcpuState} + (hk : σ.kheap p.bv = some (.archObj (.vcpu vs))) {len : U64} (hlen : 2 ≤ len.val) (call : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) : + vcpu.decode st arI s a fl4_abi.label.X86VCPUWriteVMCB len p call buf ex ⦃ r => ∃ ct f x : U64, + sched.cur_thread st s = ok ct ∧ msg.syscall_arg st s ct buf 0#u64 = ok f ∧ + msg.syscall_arg st s ct buf 1#u64 = ok x ∧ + ∀ (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), args.length = len.val → + args.getD 0 0 = f.bv → args.getD 1 0 = x.bv → + (∃ e e', r.1 = .Err e ∧ SysErrRel e e' ∧ + ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteVMCB.bv args p.bv ec) σ = + ExceptT.run (Fl4Spec.NonDetE.throwError (σ := Fl4Spec.State Unit) (α := Fl4Spec.VcpuInvocation) e') σ ∧ + r.2.1 = s ∧ JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s r.2.2 σ) ∨ + (∃ (y : U64) (s3 : S) (σ' : Fl4Spec.State Unit), r.1 = .Ok () ∧ + ExceptT.run (Fl4Spec.decodeVcpuInvocation (Z := Unit) fl4_abi.label.X86VCPUWriteVMCB.bv args p.bv ec) σ = + ExceptT.run (Fl4Spec.NonDetE.returnOk (σ := Fl4Spec.State Unit) (ε := Fl4Spec.SyscallError) + (.writeVmcb p.bv f.bv y.bv)) σ ∧ + Fl4Spec.performVcpuInvocation (Z := Unit) (.writeVmcb p.bv f.bv y.bv) σ = ({([y.bv], σ')}, False) ∧ + JAtZV3 (L := L) arI V X AR Z H Cs Ac Lst D s3 r.2.2 σ' ∧ vcpu.reply st s3 call y = ok r.2.1) ⦄ := by + refine WP.spec_mono (J.toF.writeVmcbJ hK hVA hCap hvk hp hk hlen call buf ex) ?_ + rintro r ⟨ct, f, x, hct, hf, hx, ht⟩ + refine ⟨ct, f, x, hct, hf, hx, fun args ec hl h0 h1 => ?_⟩ + rcases ht args ec hl h0 h1 with ⟨e, e', he, hr, hd, hs, J'⟩ | ⟨y, s', σ', he, hd, hp, J', hr⟩ + · exact Or.inl ⟨e, e', he, hr, hd, hs, J.ofF J'⟩ + · exact Or.inr ⟨y, s', σ', he, hd, hp, J.ofF J', hr⟩ + end end diff --git a/proofs/Fl4Proofs/P3/JProducers.lean b/proofs/Fl4Proofs/P3/JProducers.lean index b5dc2986b..459c36d3f 100644 --- a/proofs/Fl4Proofs/P3/JProducers.lean +++ b/proofs/Fl4Proofs/P3/JProducers.lean @@ -29,6 +29,8 @@ finalisation premises are re-scoped to the states the deletion loop carries. deleted). (mmuAD gen 42b56) Stated over `JAtZB` in place: `epFinPre`. + +(mmuAD gen 42b71) Stated over `JAtZB` in place: `slotN`. -/ import Fl4Proofs.P3.XTopJointFin import Fl4Proofs.P3.IpcCancelAllIpc @@ -61,12 +63,18 @@ theorem JAtZ.thOfT (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} ( obtain ⟨Tr, Cq, hJ⟩ := J.jpl exact (hJ.tcb t).2 (J.zH.1 t ht) -/-- A notification cap in a slot names one of the notifications, not 0. -/ -theorem JAtZ.slotN (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {sl : Fl4Spec.CslotPtr} +/-- A notification cap in a slot names one of the notifications, not 0. (mmuAD gen 42b71) Over `JAtZB` in place. -/ +theorem JAtZB.slotN (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {sl : Fl4Spec.CslotPtr} (hA : AbsSlot Z.th sl) {p b : U64} {w r : Bool} (hc : capAt (L.mem s) (cslotAddr sl) = ok (.Notification p b w r)) : p ∈ Z.N ∧ p ≠ 0#u64 := J.capN ⟨cslotAddr sl, b, w, r, hA.isSlot, capV_of_capAt hc⟩ +/-- `JAtZB.slotN` at `JAtZ`. -/ +theorem JAtZ.slotN (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {sl : Fl4Spec.CslotPtr} + (hA : AbsSlot Z.th sl) {p b : U64} {w r : Bool} + (hc : capAt (L.mem s) (cslotAddr sl) = ok (.Notification p b w r)) : p ∈ Z.N ∧ p ≠ 0#u64 := + J.toB.slotN hA hc + /-- An endpoint cap in a slot names one of the endpoints (`CapTyped`, `hset`). -/ theorem JAtZB.slotE (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {sl : Fl4Spec.CslotPtr} (hA : AbsSlot Z.th sl) {e b : U64} {x1 x2 x3 x4 : Bool} diff --git a/proofs/Fl4Proofs/P3/LiveFrame.lean b/proofs/Fl4Proofs/P3/LiveFrame.lean index ecf083b87..cea8a65e6 100644 --- a/proofs/Fl4Proofs/P3/LiveFrame.lean +++ b/proofs/Fl4Proofs/P3/LiveFrame.lean @@ -468,7 +468,7 @@ theorem JAtZ.ksW_notDbg {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L : /-- **A scheduler step's word is no debug word** (`SchW`: the TCBs' queue words, the current node but its debug head, the domain words). -/ -theorem JAtZ.schW_notDbg {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) +theorem JAtZB.schW_notDbg {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (hb : SchW (L := L) Z.T Z.c s b) : ¬ P1.DbgW st (P1.Heap.tcbs H) Cs s b := by have hS := J.xtop.fin.1.1.1 have hTe : Z.T = P1.Heap.tcbs H := J.tcbs_eq.1 @@ -495,6 +495,11 @@ theorem JAtZ.schW_notDbg {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L rw [e12]; rcases hq.ksOut p hp with h | h <;> omega · rw [hnb]; omega +/-- `JAtZB.schW_notDbg` at `JAtZ` (mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem JAtZ.schW_notDbg {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + {b : U64} (hb : SchW (L := L) Z.T Z.c s b) : ¬ P1.DbgW st (P1.Heap.tcbs H) Cs s b := + J.toB.schW_notDbg hb + set_option maxHeartbeats 4000000 in /-- **A step writing slot words at the slots `W` keeps `LiveDN` and `ZNoBlk`** (XTopJointLiveStep's `LiveDN.wstep`, with the `XTopAt` after @@ -678,8 +683,8 @@ set_option maxHeartbeats 4000000 in /-- **A step writing slot words at the slots `W` keeps `LiveDN` and `ZNoBlk`** (XTopJointLiveStep's `LiveDN.wstep`, with the `XTopAt` after and the TCB zombies' TCBs dead after). -/ -theorem LiveDN.wstepC {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hLv : LiveDN (L := L) Z.th H Cs Z.G s σ) +theorem LiveDN.wstepCB {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hLv : LiveDN (L := L) Z.th H Cs Z.G s σ) {G' : MdbGhost} {V' : XVs} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} (hX' : XTopAt (L := L) AR (Z.mv G' V') s' a' σ') (hdead : ∀ p ∈ ZTcb (L := L) Z.th s, Sched.DeadP (L := L) H s' p) @@ -798,6 +803,26 @@ theorem LiveDN.wstepC {s : S} {a : A} {σ : Fl4Spec.State Unit} · rw [hN sl hA h0] at ho'; cases ho' · exact absurd hm hsW +/-- Slot writes at the native joint relation. -/ +theorem LiveDN.wstepC {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hLv : LiveDN (L := L) Z.th H Cs Z.G s σ) + {G' : MdbGhost} {V' : XVs} {s' : S} {a' : A} + {σ' : Fl4Spec.State Unit} (hX' : XTopAt (L := L) AR (Z.mv G' V') s' a' σ') + (hdead : ∀ p ∈ ZTcb (L := L) Z.th s, Sched.DeadP (L := L) H s' p) + (hid : σ'.idleThread = σ.idleThread) (hw : P1.WritesIn st s s' (InSlot Z.th)) + (W : List Fl4Spec.CslotPtr) + (hW : ∀ sl ∈ W, ∃ p r, sl.1 = p.bv ∧ Z.th p = some (.cnode r) ∧ sl.2.length = r ∧ + DestCap Z.th (L.mem s) p) + (hcW : ∀ y, IsSlot Z.th y → (∀ sl ∈ W, y ≠ cslotAddr sl) → capV (L.mem s') y = capV (L.mem s) y) + (hoW : ∀ sl, σ'.isOriginalCap sl = true → σ.isOriginalCap sl = true ∨ sl ∈ W) + (hNO : ∀ sl ∈ W, capV (L.mem s') (cslotAddr sl) = .Null → σ'.isOriginalCap sl = false) + (hZ : ∀ y, IsSlot Z.th y → ∀ p zt n, capV (L.mem s') y = .Zombie p zt n → + ∃ y0, IsSlot Z.th y0 ∧ capV (L.mem s) y0 = .Zombie p zt n) + (hK2 : ∀ y0, IsSlot Z.th y0 → capV (L.mem s) y0 ≠ .Null → + ∃ y, IsSlot Z.th y ∧ capV (L.mem s') y ≠ .Null ∧ shape (capV (L.mem s') y) = shape (capV (L.mem s) y0)) : + LiveDN (L := L) Z.th H Cs G' s' σ' := + LiveDN.wstepCB J.toB hLv hX' hdead hid hw W hW hcW hoW hNO hZ hK2 + set_option maxHeartbeats 4000000 in /-- `wstepR` over `JAtZB` (mmuAD gen 42b21, in place; the `JAtZ` lemma is its corollary). -/ diff --git a/proofs/Fl4Proofs/P3/MdbStep.lean b/proofs/Fl4Proofs/P3/MdbStep.lean index 7a209f9da..f25da650a 100644 --- a/proofs/Fl4Proofs/P3/MdbStep.lean +++ b/proofs/Fl4Proofs/P3/MdbStep.lean @@ -347,8 +347,8 @@ inductive MdbStep : (U64 → U64) → MdbGhost → (U64 → U64) → MdbGhost inserted after it; the MDB's large frames 2 MiB aligned. -/ | frameAlias {th : TypedHeap} {mem mem' : U64 → U64} {G : MdbGhost} (hM : MdbLinks th mem G) (hI : MdbInv mem G) {src dest : U64} (b : Bool) (hsrc : src ∈ G.chains.flatten) (hdest : dest ∉ G.chains.flatten) - {ptr rt fa fv q0 vm : U64} {mm : Bool} - (hsC : capV mem src = .Frame ptr .Large rt false mm false fa fv) + {ptr rt fa fv q0 vm : U64} {mm epSrc : Bool} + (hsC : capV mem src = .Frame ptr .Large rt false mm epSrc fa fv) (hcd : capV mem' dest = .Frame q0 .Small vm false false false 0#u64 0#u64) (hq1 : ptr.val ≤ q0.val) (hq2 : q0.val < ptr.val + 2 ^ 21) (hcin : Within (capV mem' dest) (capV mem src)) (hcr : baseF (capV mem' dest) ≤ topF (capV mem' dest)) diff --git a/proofs/Fl4Proofs/P3/MdbStepInv.lean b/proofs/Fl4Proofs/P3/MdbStepInv.lean index 9f666c752..6143b6a44 100644 --- a/proofs/Fl4Proofs/P3/MdbStepInv.lean +++ b/proofs/Fl4Proofs/P3/MdbStepInv.lean @@ -262,8 +262,8 @@ theorem Vs.FrameInv.pool (hM : MdbLinks th mem G) (hI : MdbInv mem G) (hU : UtIn · have := hI.anc_ut e (by rw [hcx]; rfl); rw [hcy] at this; cases this theorem Vs.FrameInv.alias' (hV : Vs.FrameInv mem G) {src dest : U64} (b : Bool) (hsrc : src ∈ G.chains.flatten) - (hdest : dest ∉ G.chains.flatten) {ptr rt fa fv q0 vm : U64} {mm : Bool} - (hsC : capV mem src = .Frame ptr .Large rt false mm false fa fv) + (hdest : dest ∉ G.chains.flatten) {ptr rt fa fv q0 vm : U64} {mm epSrc : Bool} + (hsC : capV mem src = .Frame ptr .Large rt false mm epSrc fa fv) (hcd : capV mem' dest = .Frame q0 .Small vm false false false 0#u64 0#u64) (hq1 : ptr.val ≤ q0.val) (hq2 : q0.val < ptr.val + 2 ^ 21) (halg : ∀ x ∈ G.chains.flatten, ∀ p r m ep a va, capV mem x = .Frame p .Large r false m ep a va → p.val % 2 ^ 21 = 0) @@ -651,7 +651,7 @@ theorem MdbStep.inv {mem mem' : U64 → U64} {G G' : MdbGhost} (hS : MdbStep mem intro hF hU hN exact ⟨hF.rename' e (fun z hz => (ha z hz).1.frA), hU.rename hM e (fun z hz => (ha z hz).1.utEq), hN.rename e (fun z hz => ⟨(ha z hz).1.noA, (ha z hz).2⟩)⟩ - | @frameAlias th m m' g hM hI src dest b hsrc hdest ptr rt fa fv q0 vm mm hsC hcd hq1 hq2 hcin hcr halg hc hrd hr _ _ => + | @frameAlias th m m' g hM hI src dest b hsrc hdest ptr rt fa fv q0 vm mm epSrc hsC hcd hq1 hq2 hcin hcr halg hc hrd hr _ _ => intro hF hU hN have hsF : isFrame (capV m src) = true := by rw [hsC]; rfl have hcF : isFrame (capV m' dest) = true := by rw [hcd]; rfl diff --git a/proofs/Fl4Proofs/P3/NatFoot.lean b/proofs/Fl4Proofs/P3/NatFoot.lean index 544687635..f6da59926 100644 --- a/proofs/Fl4Proofs/P3/NatFoot.lean +++ b/proofs/Fl4Proofs/P3/NatFoot.lean @@ -158,11 +158,12 @@ theorem zvChg_ep {x y : Fl4Spec.Endpoint} : ZvChg (.endpoint x) (.endpoint y) := theorem zvChg_reply {x y : Fl4Spec.Reply} : ZvChg (.reply x) (.reply y) := ⟨rfl, fun _ e => (by cases e), fun _ e => (by cases e), fun _ e => (by cases e)⟩ -/-- **An SC-code spec step is a `ZvK` step** when no thread of `P` (whose state may change) ends `runningVM`. -/ -theorem natK_tkw {P : Fl4Spec.ObjRef → Prop} (h : Sched.ScTKw P σ1 σ2) +/-- (mmuAD gen 42b76) **A spec heap step of `OTK` changes is a `ZvK` step** when no thread of `P` (whose state may +change) ends `runningVM`: `natK_tkw`'s proof, asking only the heap clause (`ScTKw.kh`, `SchStep.kh`). -/ +theorem natK_otk {P : Fl4Spec.ObjRef → Prop} (h : ∀ p, Sched.OTK (P p) (σ1.kheap p) (σ2.kheap p)) (hP : ∀ p, P p → ∀ y, σ2.kheap p = some (.tcb y) → y.tcbState ≠ .runningVM) : NatK σ1 σ2 := natK_kh (R := fun _ o o' => ZvChg o o') (fun _ _ _ h => h) fun p => by - have k := h.kh p + have k := h p cases e1 : σ1.kheap p with | none => cases e2 : σ2.kheap p with @@ -184,6 +185,12 @@ theorem natK_tkw {P : Fl4Spec.ObjRef → Prop} (h : Sched.ScTKw P σ1 σ2) · exact Or.inr ⟨_, _, rfl, rfl, zvChg_ntfn⟩ · exact Or.inr ⟨_, _, rfl, rfl, zvChg_reply⟩ +/-- **An SC-code spec step is a `ZvK` step** when no thread of `P` (whose state may change) ends `runningVM` +(`natK_otk` at `ScTKw.kh`). -/ +theorem natK_tkw {P : Fl4Spec.ObjRef → Prop} (h : Sched.ScTKw P σ1 σ2) + (hP : ∀ p, P p → ∀ y, σ2.kheap p = some (.tcb y) → y.tcbState ≠ .runningVM) : NatK σ1 σ2 := + natK_otk h.kh hP + /-- `natK_tkw` with no thread-state change. -/ theorem natK_tk (h : Sched.ScTKw (fun _ => False) σ1 σ2) : NatK σ1 σ2 := natK_tkw h fun _ hp => hp.elim diff --git a/proofs/Fl4Proofs/P3/P3JMcFlt.lean b/proofs/Fl4Proofs/P3/P3JMcFlt.lean index 1bdb2f2d4..5b6b2bc04 100644 --- a/proofs/Fl4Proofs/P3/P3JMcFlt.lean +++ b/proofs/Fl4Proofs/P3/P3JMcFlt.lean @@ -26,6 +26,8 @@ thread; `faultProjW` is now its instance (statement unchanged). No premise beyond the stated hypotheses (all already globals of the clause tops); no sorry. New module; no existing statement changed. + +(mmuAD gen 42b71) `noBufCap_ckiB`: `noBufCap_cki` at `JAtZB`; the `JAtZ` name its corollary. -/ import Fl4Proofs.P3.P3JFltX import Fl4Proofs.P3.P3JMcFin @@ -76,8 +78,9 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} -/-- **At a `CKI` `JAtZ` state no TCB of `H` has a frame cap in its IPC-buffer slot.** -/ -theorem noBufCap_cki (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) : +/-- **At a `CKI` `JAtZ` state no TCB of `H` has a frame cap in its IPC-buffer slot.** (mmuAD gen 42b71) At a +`JAtZB` state; `noBufCap_cki` its `JAtZ` corollary. -/ +theorem noBufCap_ckiB (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) : P1.NoBufCap (L := L) (P1.Heap.tcbs H) s := by intro t ht have htT : Z.th t = some .tcb := J.thTcb (by rw [J.tcbs_eq.1]; exact ht) @@ -94,6 +97,11 @@ theorem noBufCap_cki (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SIn refine ⟨c, hc, ?_⟩ cases c <;> first | exact True.intro | (exfalso; simp [absCap, SInvCk.KW] at hk) +/-- `noBufCap_ckiB` at `JAtZ` (statement unchanged). -/ +theorem noBufCap_cki (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) : + P1.NoBufCap (L := L) (P1.Heap.tcbs H) s := + noBufCap_ckiB J.toB hC + set_option maxHeartbeats 4000000 in /-- (p3J gen 51) **`handle_fault` of the current thread writes only `ProjW`** at a `CKI` `JAtZ` state where the current thread can block (P1 `CanBlock`; no `Entered`: at a mid state with a pending switch or reschedule it comes diff --git a/proofs/Fl4Proofs/P3/P3JMcKwN.lean b/proofs/Fl4Proofs/P3/P3JMcKwN.lean index 31e2202c4..4e830b480 100644 --- a/proofs/Fl4Proofs/P3/P3JMcKwN.lean +++ b/proofs/Fl4Proofs/P3/P3JMcKwN.lean @@ -23,6 +23,8 @@ object), `node_projW` (a node word of a core of `Cs` at an offset `≠ 8, 32`), `capW_projW`. No premise; no sorry. New module; no existing statement changed. + +(mmuAD gen 42b71) `projW_of_cur0wNB`: `projW_of_cur0wN` at `JAtZB`; the `JAtZ` name its corollary. -/ import Fl4Proofs.P3.P3JMcFootC import Fl4Proofs.P2.FootN @@ -106,9 +108,9 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a {AR : A → Fl4Spec.Cr3 → Prop} /-- **At a `JAtZ` state: a `WritesIn` footprint into `KWN ∨ DbgW ∨ CapW` over `H`'s sets is a `ProjW` -footprint** (module docstring). -/ -theorem projW_of_cur0wN {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} - {s s' : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) +footprint** (module docstring). (mmuAD gen 42b71) At a `JAtZB` state; `projW_of_cur0wN` its `JAtZ` corollary. -/ +theorem projW_of_cur0wNB {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s s' : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {Kp : Set U64} {Nd : Prop} (hW : P1.WritesIn st s s' (fun b => KWN st Kp Nd (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (EH H) s b ∨ @@ -117,6 +119,16 @@ theorem projW_of_cur0wN {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 obtain ⟨Q, R, hq⟩ := J.blk.1 exact hW.mono fun b hb => cur0wN_projW J.kern.heap (SchedQueuesInvX.nodes hq) hb +/-- `projW_of_cur0wNB` at `JAtZ` (statement unchanged). -/ +theorem projW_of_cur0wN {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s s' : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + {Kp : Set U64} {Nd : Prop} + (hW : P1.WritesIn st s s' (fun b => + KWN st Kp Nd (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (EH H) s b ∨ + DbgW st (P1.Heap.tcbs H) Cs s b ∨ CapW (P1.Heap.tcbs H) (P1.Heap.omega H) (P1.Heap.frame H) b)) : + P1.WritesIn st s s' (ProjW (L := L) H Cs s) := + projW_of_cur0wNB J.toB hW + end end Fl4Proofs.P3.Mc diff --git a/proofs/Fl4Proofs/P3/P3JPreHole.lean b/proofs/Fl4Proofs/P3/P3JPreHole.lean index 57bec5cf7..2ba37a6ff 100644 --- a/proofs/Fl4Proofs/P3/P3JPreHole.lean +++ b/proofs/Fl4Proofs/P3/P3JPreHole.lean @@ -24,6 +24,13 @@ at the hole's sets (`JStab Z H Cs`), which is what P3JMidInv's `MidXP` needs. former inactive-SC proof), neither (XTopJointPreemptM's former active-SC proof). No premise; no sorry. New module; no existing statement changed. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2, item 2) `mcsCovSt`, `mcsInactSt`, `mcsUSt`, `mcsStK`, `mcsSt` take no +`JExt` at the hole's base (nor `VxE`): their post is `JAtN` from the hole's base (`JAtZB` plus `NatFoot`) in place +of `JStab`; **`JAtN.toJStab`** gives `JStab` back from `JAtZ` at the base (P3JPreSt's `afterInvSt`, which keeps `hE` +for its interrupt arm until (c2)). + +(mmuAD gen 42b71) `JAtN.toJStab` moved to P3/StPostIrqLeaf (statement unchanged). -/ import Fl4Proofs.P3.P3JDelMT open Aeneas Aeneas.Std Result @@ -46,28 +53,29 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **XTopJointMRPP's `ppJHM` over `MachPlatC`** (module docstring): every spec `error` outcome of -the preemption point is a `JHole` at the pre-state's sets, with `MR` and `ValidMachineTime`. -/ -theorem JAtZ.ppJHC {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) +the preemption point is a `JHole` at the pre-state's sets, with `MR` and `ValidMachineTime` +(Gen 42b69: from `JAtZB`; the hole's base `JExt` follows from the start's.) -/ +theorem JAtZB.ppJHC {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) (hR : MR a σ.machineState) (hV : ValidMachineTime σ) : sched.preemption_point st arI s a ⦃ r => r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by unfold sched.preemption_point step with obj.ks_get.spec as ⟨i, _⟩ step as ⟨w, _⟩ step with obj.ks_set.spec as ⟨s1, e1⟩ subst e1 - obtain ⟨Ac1, Lst1, J1⟩ := J.workUnitsJD arI w + obtain ⟨Ac1, Lst1, J1, hW1⟩ := J.workUnitsJD arI w split swap · rw [WP.spec_ok]; intro h; cases h step with obj.ks_set.spec as ⟨s2, e2⟩ subst e2 - obtain ⟨Ac2, Lst2, J2⟩ := J1.workUnitsJD arI 0#u64 + obtain ⟨Ac2, Lst2, J2, hW2⟩ := J1.workUnitsJD arI 0#u64 have hS0 := J2.xtop.fin.1.1.1 have hscC0 := cursc_in hS0 J2.own refine WP.spec_bind (WP.spec_and (J2.timestampJH hAK hA hnd (hM.nowAgree hR hV)) (update_timestamp_mrC hM hR _)) ?_ @@ -124,17 +132,17 @@ theorem JAtZ.ppJHC {s : S} {a : A} {σ : Fl4Spec.State Unit} r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by rw [WP.spec_ok] intro _ σ' hσ' rw [hfin σ' hσ'] - exact ⟨_, Ac2, Lst2, hK _ a2 hum' (fun _ => hAR2), hR2, hV2⟩ + exact ⟨_, Ac2, Lst2, hK _ a2 hum' (fun _ => hAR2), fun h => hW2 (hW1 h), hR2, hV2⟩ have hOk : (ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s3, a2) : Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ r => r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by rw [WP.spec_ok]; intro h; cases h cases hact : Fl4Spec.scActive x · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok, ite_self] @@ -149,6 +157,19 @@ theorem JAtZ.ppJHC {s : S} {a : A} {σ : Fl4Spec.State Unit} · exact hOk · exact hErr + +/-- `JAtZB.ppJHC` at `JAtZ` (gen 42b69: via `JAtZ.toB`, the hole's base `JExt` from `J.ext`). -/ +theorem JAtZ.ppJHC {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) + (hR : MR a σ.machineState) (hV : ValidMachineTime σ) : + sched.preemption_point st arI s a ⦃ r => r.1 = .Err .Preempted → ∀ σ', + (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → + ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), + JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ JExt (L := L) Z.th s0 ∧ + MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := + WP.spec_mono (J.toB.ppJHC hAK hA hnd hM hPA hR hV) fun _ h hr σ' hσ' => + let ⟨s0, Ac0, Lst0, Hh, hE, hR', hV'⟩ := h hr σ' hσ'; ⟨s0, Ac0, Lst0, Hh, hE J.ext, hR', hV'⟩ set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **The hole after a preempting preemption point from a fixed `JAtZ`** (module docstring; XTopJointMRHole's `jAtPreMV_holeQ` with the pre-state's sets kept). -/ @@ -160,22 +181,22 @@ theorem JAtZ.preHoleC {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : (hpp : sched.preemption_point st arI s0 a0 = ok (.Err .Preempted, s, a)) (hσ : (.error (), σ) ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ0).1) : ∃ (s1 : S) (Ac1 : Set U64) (Lst1 : U64 → List U64), - JHole (L := L) arI AR Z H Cs Ac1 Lst1 D s1 a0 σ0 s a σ ∧ TShift σ0 σ ∧ + JHole (L := L) arI AR Z H Cs Ac1 Lst1 D s1 a0 σ0 s a σ ∧ JExt (L := L) Z.th s1 ∧ TShift σ0 σ ∧ σ.curThread ≠ σ.idleThread ∧ Vs.NoSwitch σ ∧ CurScFree σ ∧ CtOK σ ∧ Chg σ ∧ CtNQ σ ∧ MR a σ.machineState ∧ ValidMachineTime σ ∧ ValidIrqMasks σ := by have h := J.ppJHC hAK hA hnd hM hPA hR0 hV0 rw [hpp, WP.spec_ok] at h - obtain ⟨s1, Ac1, Lst1, Hh, hR', hV'⟩ := h rfl σ hσ + obtain ⟨s1, Ac1, Lst1, Hh, hEx, hR', hV'⟩ := h rfl σ hσ have hE := Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ0.machineState)) have e : σ = _ := pp_err_eq hE (doMachineOp_single (getActiveIRQ_eq true _)) _ hσ rfl subst e have h0 : CurScFree σ0 := curScFree_of J.inv J.own hp00 - exact ⟨s1, Ac1, Lst1, Hh, ⟨vmt_le_gct hV0, rfl⟩, hp00.1.1, hns0, fun u xt hu hs => h0 u xt hu hs, hp00.1.2.2.1, + exact ⟨s1, Ac1, Lst1, Hh, hEx, ⟨vmt_le_gct hV0, rfl⟩, hp00.1.1, hns0, fun u xt hu hs => h0 u xt hu hs, hp00.1.2.2.1, hp00.1.2.2.2.1, hp00.1.2.2.2.2, hR', hV', fun i hi => hI0 i hi⟩ set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **XTopJointMRPath2's `mcsPPJZMF`, `PPCov` arm, at the hole's sets.** -/ -theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.mcsCovSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) @@ -184,7 +205,7 @@ theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := by obtain ⟨hC, hni, hnsw, hnt⟩ := hcov have hS := Hh.xtop.fin.1.1.1 @@ -216,7 +237,7 @@ theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : rw [hc.cur] at hcv subst hcv refine WP.spec_mono (Hh.chargeBudgetJ hAT hC hni hnsw hmrt hmb _) ?_ - rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J'⟩ + rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J', F'⟩ simp only at ha subst a' have hkx' : σ.kheap σ.curSc = some (.schedContext x n) := by rw [hs.curSc]; exact hkx @@ -225,7 +246,7 @@ theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : have h1' : Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime false σ = ({((), σ')}, False) := by rw [hs.consumed]; exact h1 have hs' : Fl4Spec.schedulable σ.curThread σ = false := by rw [ect]; exact hsch - refine ⟨σ', ?_, ?_, J'.stab, MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), + refine ⟨σ', ?_, ?_, JAtN.of J' F', MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), fun hN => SInv.ns_chargeBudget _ _ σ hN ((), σ') (by rw [h1']; rfl), fun hC0 => SInvCk.ck_chargeBudget _ _ σ hC0 ((), σ') (by rw [h1']; rfl)⟩ · exact fun y hy => mem_pp_charge hs' hga (by rw [h1']; rfl) hy @@ -236,15 +257,15 @@ theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs res.2.1 res.2.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 res.2.1 res.2.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := by refine WP.spec_mono (Hh.checkBudgetF hAT hC hni hnsw hmrt hmb hnt) ?_ rintro ⟨r, s', a'⟩ hF hr - obtain ⟨ha, σ', h1, -, Lst', J'⟩ := hF hr + obtain ⟨ha, σ', h1, -, Lst', J', F'⟩ := hF hr simp only at ha subst a' exact ⟨σ', fun y hy => mem_pp_sched hs' (by rw [h1]; rfl) hy, - fun hy => fail_pp_sched hs' (by rw [h1]; rfl) hy, J'.stab, + fun hy => fail_pp_sched hs' (by rw [h1]; rfl) hy, JAtN.of J' F', MachF.mfk_checkBudget σ (_, σ') (by rw [h1]; rfl), fun hN => SInv.ns_checkBudget σ hN (_, σ') (by rw [h1]; rfl), fun hC0 => SInvCk.ck_checkBudget σ hC0 (_, σ') (by rw [h1]; rfl)⟩ @@ -257,18 +278,18 @@ theorem JHole.mcsCovSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : simp only [Prod.mk.injEq] at e obtain ⟨rfl, rfl⟩ := e have hO := Hh.offOK_suff hT hC hni hs' hsufH - obtain ⟨Lst', J'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) + obtain ⟨Lst', J', F'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) exact ⟨σ, fun y hy => mem_pp_sched hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, - fun hy => fail_pp_sched hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, J'.stab, rfl, fun hN => hN, fun hC0 => hC0⟩ + fun hy => fail_pp_sched hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, JAtN.of J' F', rfl, fun hN => hN, fun hC0 => hC0⟩ set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **XTopJointPreemptI's former inactive-SC proof at the hole's sets** (inactive current SC). -/ theorem JHole.mcsInactSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hcov : PPCovI σ) : + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hcov : PPCovI σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := by obtain ⟨hsch, hin⟩ := hcov have J := Hh.j0 @@ -385,12 +406,12 @@ theorem JHole.mcsInactSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a · show _ = some σ.curSc; rw [hcs]; exact hxs · rw [← hk, ← hcs]; exact hy · exact Or.inr ⟨⟨c', hc', hcv'.trans hcs.symm⟩, fun y m hy => h2 y m (by rw [← hk, ← hcs]; exact hy)⟩ - obtain ⟨Lst', J'⟩ := Hh2.toJ hO hOw - exact ⟨cons0 σ, fun y hy => mem_pp_inact hs' hga hy, fun hy => fail_pp_inact hs' hga hy, J'.stab, rfl, fun hN => hN, fun hC0 => hC0⟩ + obtain ⟨Lst', J', F'⟩ := Hh2.toJ hO hOw + exact ⟨cons0 σ, fun y hy => mem_pp_inact hs' hga hy, fun hy => fail_pp_inact hs' hga hy, JAtN.of J' F', rfl, fun hN => hN, fun hC0 => hC0⟩ set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **XTopJointPreemptM's former active-SC proof at the hole's sets** (no `CurInv`, active current SC). -/ -theorem JHole.mcsUSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.mcsUSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -399,7 +420,7 @@ theorem JHole.mcsUSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := by have hax : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → Fl4Spec.scActive x = true := fun x n h => by cases e : Fl4Spec.scActive x with @@ -434,7 +455,7 @@ theorem JHole.mcsUSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S rw [hc.cur] at hcv subst hcv refine WP.spec_mono (Hh.chargeBudgetUJ hAT hnc hsch hct hf hg hax hmrt hmb _) ?_ - rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J'⟩ + rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J', F'⟩ simp only at ha subst a' have hga : Fl4Spec.getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False) := by @@ -442,12 +463,12 @@ theorem JHole.mcsUSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S have h1' : Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime false σ = ({((), σ')}, False) := by rw [hs.consumed]; exact h1 exact ⟨σ', fun y hy => mem_pp_charge hsch hga (by rw [h1']; rfl) hy, - fun hy => fail_pp_charge hsch hga (by rw [h1']; rfl) hy, J'.stab, MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), + fun hy => fail_pp_charge hsch hga (by rw [h1']; rfl) hy, JAtN.of J' F', MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), fun hN => SInv.ns_chargeBudget _ _ σ hN ((), σ') (by rw [h1']; rfl), fun hC0 => SInvCk.ck_chargeBudget _ _ σ hC0 ((), σ') (by rw [h1']; rfl)⟩ /-- (p3J gen 45) **The MCS preemption point from a round-robin hole, at the hole's sets** (module docstring). -/ -theorem JHole.mcsStK [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.mcsStK {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) @@ -457,7 +478,7 @@ theorem JHole.mcsStK [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := by by_cases hC : CurInv σ · exact Hh.mcsCovSt hT hAT hnd hmrt hmb ⟨hC, hni, hns σ.curThread, Or.inr fun x n hk => SInvRr.rr_period hRR hk⟩ @@ -470,7 +491,7 @@ theorem JHole.mcsStK [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S exact Hh.mcsUSt hAT hmrt hmb hC hct hf hg hsch hi /-- (p3J gen 45) **`mcsStK` with `MR` and `ValidIrqMasks` after** (module docstring). -/ -theorem JHole.mcsSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.mcsSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) @@ -481,7 +502,7 @@ theorem JHole.mcsSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JStab (L := L) arI AR Z H Cs r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ∧ (SInvCk.CKI σ → SInvCk.CKI σ') ⦄ := WP.spec_mono (WP.spec_and (Hh.mcsStK hT hAT hnd hmrt hmb hni hns hf hct hg hRR) (MK.syscall_mcs_preemption_point L.total hAT hK hR)) diff --git a/proofs/Fl4Proofs/P3/P3JPreSt.lean b/proofs/Fl4Proofs/P3/P3JPreSt.lean index 5d6a4c579..c271b3943 100644 --- a/proofs/Fl4Proofs/P3/P3JPreSt.lean +++ b/proofs/Fl4Proofs/P3/P3JPreSt.lean @@ -11,6 +11,8 @@ ends at an outcome of the spec's `preemptionPath` with `JStab Z H Cs`, `MR`, and thread (`hna`), FL4's `mcs_preemption_point` is a `FootN ∅ False` step: P1 QueueBudgetG's `mcs_preemption_point.allG` walk with P2 EntryIrq's round-robin `check_budget.rr` / `charge_budget.rr` (no timeout fault) and `footN_node` for the inactive-SC branch's `CONSUMED` write. + (mmuAD gen 42b74) Its body is now **`syscall.mcs_preemption_point.tmoN`** (any `Nd`, the timeout faults asked as + P2/FootN3's `TmoKCv`), `rrN` the corollary (statement unchanged). * **`JHole.mcsFt`**: at a hole (P3JPreHole) with `CtOK` (the current thread's SC word), `NoSwitch` and `RR`, the MCS preemption point writes only `ProjW H Cs s` (P3JMcKwN's `cur0wN_projW`). * **`Mc.JAtZ.handleIrqFt`**: at a `JAtZ` state whose spec state is `CKI`, FL4's `handle_interrupt` of **any** line @@ -31,6 +33,12 @@ Platform facts used (all [P], the stable tops' globals except `IrqPlatK`, which `IrqPlatK`, `TimeAgree` (`max_release_time`), `PPPlatA` (`irq_pending` keeps `AR`, `min_budget`). No premise; no sorry. New module; no existing statement changed. + +(mmuAD gen 42b70) the MCS part (`JHole.mcsSt`) now ends at `JAtN` from the hole's base, read back at `JStab` by +`JAtN.toJStab`. (gen 42b71, ruling (c2) item 4) **`JHole.afterInvSt` takes no `hE` (nor `VxE`)**: the IRQ step is over +`JAtZB` (P3/XTopJointKEntryEv2's `JAtZB.handleIrqJBM`; `Mc.JAtZB.handleIrqFt`, with P3/P3JMcFlt's `noBufCap_ckiB` and +P3/P3JMcKwN's `projW_of_cur0wNB`, the `JAtZ` names their corollaries), and it ends at `JAtN` from the hole's base (in +place of `JStab`); `midXP_of_pre` reads it back at `JStab` with the base's `JExt`. -/ import Fl4Proofs.P3.P3JPreHole open Aeneas Aeneas.Std Result @@ -44,15 +52,26 @@ variable {Cs Sg Rp Scs Nt : Set U64} {Z : U64 → Nat} {Ac : Set U64} variable {A : Type _} {ar : machine.Arch A} set_option maxHeartbeats 2000000 in -/-- (p3J gen 45) **`mcs_preemption_point` on a round-robin current SC is a `FootN ∅ False` step** (module -docstring). -/ -theorem syscall.mcs_preemption_point.rrN (hA : P0.ArchTotal ar) (s : S) (a : A) +/-- (mmuAD gen 42b74) **`mcs_preemption_point` is a `FootN ∅ Nd` step where the timeout faults it may raise are** +(`TmoKCv` at the `FootN ∅ Nd` footprint from the start, (gen 42b75) asked only where FL4's `is_schedulable` holds of +the current thread: the only arm calling `check_budget`; P2/FootN3's `check_budget.allGNv` / `charge_budget.allGNv`, +the latter with `can_timeout_fault = false`, and `footN_node` for the inactive-SC branch's `CONSUMED` write), with +P1's scheduler invariants, the current SC word linked to the current thread's (`hcsc`) and the action not the current +thread (`hna`). gen 45's `mcs_preemption_point.rrN` is its corollary (a round-robin SC raises none). +(mmuAD gen 42b77) Over any property `G` of the end states kept by `FootN ∅ Nd` steps and holding at the start +(`hGF`, `hG0`), the timeout faults asked as `TmoKCv … G`; `mcs_preemption_point.tmoN` is its `G := FootN` instance, +P3/VmPreempt's `IpcFootN` form another. -/ +theorem syscall.mcs_preemption_point.tmoNG {Nd : Prop} (hA : P0.ArchTotal ar) (s : S) (a : A) (Q : U64 → U64 → List U64) (R : U64 → List U64) (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) (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) - (hna : L.actionW s ≠ L.curW s) (hrr : L.rperiod s (L.cscW s) = 0#u64) : - syscall.mcs_preemption_point st ar s a ⦃ s' _ => FootN st ∅ False T Cs Sg Scs Z (EH H) s s' ⦄ := by + (hna : L.actionW s ≠ L.curW s) {G : S → Prop} + (hGF : ∀ s1 s2 : S, G s1 → FootN st ∅ Nd T Cs Sg Scs Z (EH H) s1 s2 → G s2) (hG0 : G s) + (htmo : (Runnable (L.mem s (stA (L.curW s))) ∧ L.mem s (scA (L.curW s)) ≠ 0#u64 ∧ + (L.mem s (inqA (L.curW s)) &&& sched.Q_RELEASE) = 0#u64 ∧ L.rmax s (L.mem s (scA (L.curW s))) ≠ 0#u64) → + TmoKCv st ar T Cs Ω H Sg Rp Scs Nt Z Ac s G) : + syscall.mcs_preemption_point st ar s a ⦃ s' _ => G s' ⦄ := by unfold syscall.mcs_preemption_point step with sched.cur_thread.spec as ⟨ct, ct_post⟩ have ect : ct = L.curW s := ct_post @@ -64,13 +83,13 @@ theorem syscall.mcs_preemption_point.rrN (hA : P0.ArchTotal ar) (s : S) (a : A) have hcA : L.cscW s ∈ Ac := by have e : L.mem s (scA (L.curW s)) = L.cscW s := (hcsc hbd).symm rw [← e]; exact (hS.act _ (hX.2.2.bound _ h.curT hbd).1).2 hrm - refine WP.spec_bind (sched.check_budget.rr (Kp := ∅) (Nd := False) (Es := (∅ : Set U64)) hA s a Q R h hB hX hSg - hS hcsc hna hcA (fun _ h => h) (fun _ _ _ => ⟨hrr, fun h => h⟩)) ?_ + refine WP.spec_bind (sched.check_budget.allGNv (Kp := ∅) (Nd := Nd) hA s a Q R h hB hX hSg hS hcsc hna hcA + (G := G) hGF (fun _ _ => ⟨fun _ h => h, fun h => h⟩) hG0 (htmo (eb hb))) ?_ rintro ⟨r, s1, a1⟩ h1 try simp only [WP.uncurry'_pair] at h1 refine (WP.spec_ok _).2 ?_ try simp only [WP.uncurry'_pair] - exact h1.2.1 + exact h1.1.2 · step with sched.cur_sc.spec as ⟨c, ec⟩ step with sporadic.sc_active.val as ⟨b1, eb1⟩ split @@ -78,19 +97,47 @@ theorem syscall.mcs_preemption_point.rrN (hA : P0.ArchTotal ar) (s : S) (a : A) have hcA : L.cscW s ∈ Ac := (hS.act _ hX.2.2.cur).2 (by have := eb1 hb1; rwa [ec] at this) step with sched.consumed.spec as ⟨u⟩ - refine WP.spec_mono (sched.charge_budget.rr (Kp := ∅) (Nd := False) (Es := (∅ : Set U64)) hA s a u false Q R h - hB hX hSg hS hcsc hna hcA (fun h => h) (fun _ h => h) hrr) ?_ + refine WP.spec_mono (sched.charge_budget.allGNv (Kp := ∅) (Nd := Nd) hA s a u false Q R h hB hX hSg hS hcsc hna + hcA (G := G) hGF (fun _ _ => ⟨fun _ h => h, fun h => h⟩) hG0 (fun e => by cases e)) ?_ rintro ⟨s1, a1⟩ h1 try simp only [WP.uncurry'_pair] at h1 ⊢ - exact h1.2.1 + exact h1.2 · step with LawfulStore.cur_cpu_spec as ⟨cpu, cpu_post⟩ subst cpu_post step with obj.node_set.spec as ⟨s2, e2⟩ subst e2 try simp only [WP.uncurry'_pair] - exact footN_node h.nodes h.cur (o := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) + exact hGF _ _ hG0 (footN_node h.nodes h.cur (o := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]) (by simp [IdOff, layout.node.CONSUMED]) - h.cur + h.cur) + +/-- (mmuAD gen 42b74) `mcs_preemption_point` is a `FootN ∅ Nd` step where the timeout faults it may raise are +(statement before gen 42b77): `mcs_preemption_point.tmoNG` at `G := FootN ∅ Nd` from the start. -/ +theorem syscall.mcs_preemption_point.tmoN {Nd : Prop} (hA : P0.ArchTotal ar) (s : S) (a : A) + (Q : U64 → U64 → List U64) (R : U64 → List U64) + (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) + (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : L.actionW s ≠ L.curW s) + (htmo : (Runnable (L.mem s (stA (L.curW s))) ∧ L.mem s (scA (L.curW s)) ≠ 0#u64 ∧ + (L.mem s (inqA (L.curW s)) &&& sched.Q_RELEASE) = 0#u64 ∧ L.rmax s (L.mem s (scA (L.curW s))) ≠ 0#u64) → + TmoKCv st ar T Cs Ω H Sg Rp Scs Nt Z Ac s (fun s' => FootN st ∅ Nd T Cs Sg Scs Z (EH H) s s')) : + syscall.mcs_preemption_point st ar s a ⦃ s' _ => FootN st ∅ Nd T Cs Sg Scs Z (EH H) s s' ⦄ := + syscall.mcs_preemption_point.tmoNG hA s a Q R h hB hX hSg hS hcsc hna + (G := fun s' => FootN st ∅ Nd T Cs Sg Scs Z (EH H) s s') (fun _ _ g f => g.trans f) (FootN.refl s) htmo + +/-- (p3J gen 45) **`mcs_preemption_point` on a round-robin current SC is a `FootN ∅ False` step** (module +docstring). (mmuAD gen 42b74) `mcs_preemption_point.tmoN`'s corollary: a round-robin SC raises no timeout fault +(`TmoKCv` asks a period kept from the start and nonzero); statement unchanged. -/ +theorem syscall.mcs_preemption_point.rrN (hA : P0.ArchTotal ar) (s : S) (a : A) + (Q : U64 → U64 → List U64) (R : U64 → List U64) + (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) + (hSg : SgOK st Ω Sg s) (hS : SCsOK st T Ω Sg Scs Z Ac s) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : L.actionW s ≠ L.curW s) (hrr : L.rperiod s (L.cscW s) = 0#u64) : + syscall.mcs_preemption_point st ar s a ⦃ s' _ => FootN st ∅ False T Cs Sg Scs Z (EH H) s s' ⦄ := + syscall.mcs_preemption_point.tmoN hA s a Q R h hB hX hSg hS hcsc hna + fun _ _ _ _ _ _ _ _ _ _ _ _ hper _ _ hp _ => absurd (hper.trans hrr) hp end @@ -156,16 +203,17 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a {AR : A → Fl4Spec.Cr3 → Prop} set_option maxHeartbeats 4000000 in -/-- (p3J gen 45) **At a `CKI` `JAtZ` state, the handler of any line writes only `ProjW`** (module docstring). -/ -theorem JAtZ.handleIrqFt (hA : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +/-- (p3J gen 45) **At a `CKI` `JAtZ` state, the handler of any line writes only `ProjW`** (module docstring). +(mmuAD gen 42b71) At a `JAtZB` state; `JAtZ.handleIrqFt` its corollary. -/ +theorem JAtZB.handleIrqFt (hA : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) (w : U64) : + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) (w : U64) : interrupt.handle_interrupt st arI s a w ⦃ r => P1.WritesIn st s r.1 (ProjW (L := L) H Cs s) ⦄ := by by_cases hsig : w.val ≤ 127 ∧ L.mem s (irqStA (L.ksb s) w) = 1#u64 swap · have hb := BlkOK.bxi J.blk exact WP.spec_mono (handle_interrupt_footN0 (Es := EH H) hA s a w hb fun hle e => hsig ⟨hle, e⟩) fun r hr => - projW_of_cur0wN J ((WritesA.w hr).mono fun _ hb => Or.inl hb) + projW_of_cur0wNB J ((WritesA.w hr).mono fun _ hb => Or.inl hb) obtain ⟨hle, hst⟩ := hsig have hi : w.val < 128 := by omega obtain ⟨Tr, Cq, hJ⟩ := J.jpl @@ -193,7 +241,7 @@ theorem JAtZ.handleIrqFt (hA : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs A cases wr · exact (WP.spec_ok _).2 (P1.WritesIn.refl _ _) · simp only [↓reduceIte] - exact sendSignalProjW hA J.kern.heap J.blk (noBufCap_cki J hC) (hty.2.1 p b true rr rfl).2 b + exact sendSignalProjW hA J.kern.heap J.blk (noBufCap_ckiB J hC) (hty.2.1 p b true rr rfl).2 b all_goals exact (WP.spec_ok _).2 (P1.WritesIn.refl _ _) · rintro ⟨s3, a2⟩ h3 try simp only [WP.uncurry'_pair] at h3 @@ -206,6 +254,13 @@ theorem JAtZ.handleIrqFt (hA : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs A refine WP.spec_bind (hA.ack_irq a1 w) fun a2 _ => ?_ exact (WP.spec_ok _).2 h1 +/-- `JAtZB.handleIrqFt` at `JAtZ` (statement unchanged). -/ +theorem JAtZ.handleIrqFt (hA : P0.ArchTotal arI) {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hC : SInvCk.CKI σ) (w : U64) : + interrupt.handle_interrupt st arI s a w ⦃ r => P1.WritesIn st s r.1 (ProjW (L := L) H Cs s) ⦄ := + JAtZB.handleIrqFt hA J.toB hC w + /-- (p3J gen 45) **P3JMcIrqF's `IrqSigFootJ` [J] holds at every `CKI` state** (`handleIrqFt`; the premise's antecedents include `CKI σ`). -/ theorem irqSigFootJ_of (hA : P0.ArchTotal arI) : IrqSigFootJ (st := st) (L := L) arI AR := @@ -228,7 +283,7 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 4000000 in /-- (p3J gen 45) **`after_invocation (Err _)` from a round-robin hole at the hole's sets, with footprint** (module docstring). -/ -theorem JHole.afterInvSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} +theorem JHole.afterInvSt {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hKD : MRKeepD arI MR) (hIP : IrqPlatA arI AR) (hTA : TimeAgree arI) @@ -238,18 +293,19 @@ theorem JHole.afterInvSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s (hC : SInvCk.CKI σ) (e : error.Exc) : syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ (∃ z ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1, - JStab (L := L) arI AR Z H Cs r.2.1 r.2.2 z.2 ∧ MR r.2.2 z.2.machineState) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.2.1 r.2.2 z.2 ∧ MR r.2.2 z.2.machineState) ∧ P1.WritesIn st s r.2.1 (Mc.ProjW (L := L) H Cs s) ⦄ := by unfold syscall.after_invocation refine WP.spec_bind (WP.spec_and (Hh.mcsSt hT hAT hnd (hTA.mrt a) (hmb a) hni hns hf hct hg hRR hM.toC hKD.toK hR hV) (Hh.mcsFt hAT hct hns hRR)) ?_ - rintro ⟨s1, a1⟩ ⟨⟨σ', hm, -, ⟨G1, V1, Ac1, Lst1, D1, J'⟩, hR1, hVI, hN', hC'⟩, hW1⟩ + rintro ⟨s1, a1⟩ ⟨⟨σ', hm, -, ⟨V1, Ac1, Lst1, D1, B1, F1⟩, hR1, hVI, hN', hC'⟩, hW1⟩ have hN1 : NativeScope σ' := hN' hN have hC1 : SInvCk.CKI σ' := hC' hC - have hAR1 : AR a1 σ'.archState.x64CurrentCr3 := J'.xtop.fin.1.1.2.2.2.2.2.2 + have hAR1 : AR a1 σ'.archState.x64CurrentCr3 := B1.xtop.fin.1.1.2.2.2.2.2.2 refine WP.spec_bind (WP.spec_and (WP.spec_and (hM.takeAt hR1) (hIP.takeAR a1 _ hAR1)) (hM.noIpi a1 _ hR1)) ?_ rintro ⟨w, a2⟩ ⟨⟨⟨irq, ms, hIq, hnone, hsome, hum, hR2⟩, hAR2⟩, h126, h127⟩ - obtain ⟨Lst2, J2⟩ := J'.msArJ ms a2 hum (fun _ => hAR2) + obtain ⟨Lst2, B2, F2⟩ := B1.msArJ ms a2 hum (fun _ => hAR2) + have F12 := Hh.j0.natTrans F1 F2.cast unfold syscall.check_interrupt by_cases hw : w = syscall.NO_IRQ · have hirq : irq = none := hnone.1 hw @@ -261,7 +317,7 @@ theorem JHole.afterInvSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s rw [e] simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] exact (WP.spec_ok _).2 ⟨rfl, ⟨((), { σ' with machineState := ms }), hm _ (mem_maybeHandle_none hIq), - JStab.mv J2.stab, hR2⟩, hW1⟩ + ⟨V1, Ac1, Lst2, D1, B2, F12⟩, hR2⟩, hW1⟩ · obtain ⟨i, rfl⟩ : ∃ i, irq = some i := by cases irq with | none => exact absurd (hnone.2 rfl) hw @@ -274,11 +330,11 @@ theorem JHole.afterInvSt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s rw [e] simp only [↓reduceIte] have hw256 : w.val < 256 := by rw [hwi]; exact i.isLt - refine WP.spec_bind (WP.spec_and (Fl4Proofs.P3.JAtZ.handleIrqJIMSt hARI hAT hIP hM hKD.toK hmb J2 hN1 hR2 w i hwi - hw256 h126 h127) (Mc.JAtZ.handleIrqFt hAT J2 hC1 w)) ?_ + refine WP.spec_bind (WP.spec_and (B2.handleIrqJBM hARI hAT hIP hM hKD.toK hmb hN1 hR2 w i hwi hw256 h126 h127) + (Mc.JAtZB.handleIrqFt hAT B2 hC1 w)) ?_ rintro ⟨s2, a3⟩ ⟨hf | ⟨z, hz, hJ, hRz⟩, hW2⟩ · exact absurd hf (gai_active hVI hIq i rfl) - · exact (WP.spec_ok _).2 ⟨rfl, ⟨z, hm _ (mem_maybeHandle_some hIq hz), JStab.mv hJ, hRz⟩, + · exact (WP.spec_ok _).2 ⟨rfl, ⟨z, hm _ (mem_maybeHandle_some hIq hz), JAtN.trans Hh.j0 F12 hJ, hRz⟩, hW1.projW_trans hW2⟩ set_option maxHeartbeats 4000000 in @@ -296,12 +352,12 @@ theorem midXP_of_pre [VxE Z] (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (h (hW : P1.WritesIn st s0 s (Mc.ProjW (L := L) H Cs s0)) : MidXP (L := L) arI AR MR Z H Cs s0 s a σ := by obtain ⟨hR0, hV0, hI0⟩ := hMV - obtain ⟨s1, Ac1, Lst1, Hh, hTs, hni, hns', hf, hct, hg, -, hR, -, hVI⟩ := + obtain ⟨s1, Ac1, Lst1, Hh, hEx, hTs, hni, hns', hf, hct, hg, -, hR, -, hVI⟩ := J.preHoleC hARI.toARKeep hAT hnd hM.toC hPA hns hp hR0 hV0 hI0 hpp hσ refine ⟨hW, WP.spec_mono (Hh.afterInvSt hTs hARI hAT hnd hM hKD hIP hTA hPA.minBudget hni hns' hf hct hg hRR hR hVI hN hC _) ?_⟩ rintro r ⟨h1, ⟨z, hz, hJ, hRz⟩, hW2⟩ - exact ⟨h1, ⟨z, hz, JStab.mv hJ, hRz⟩, hW.projW_trans hW2⟩ + exact ⟨h1, ⟨z, hz, JStab.mv (hJ.toJStab (Hh.j0.toJAtZ hEx)), hRz⟩, hW.projW_trans hW2⟩ /-- (p3J gen 45) **`MidXP` at the installs' preempted invariant** (P3JDelMT's `delHypsJLMftC` ends a preemption at `WFt s0 (WCk WJPMV)`): with `RR` and `NativeScope` at the preempted spec state. -/ diff --git a/proofs/Fl4Proofs/P3/ScAwaken.lean b/proofs/Fl4Proofs/P3/ScAwaken.lean index ea2646a38..1e0bfcba0 100644 --- a/proofs/Fl4Proofs/P3/ScAwaken.lean +++ b/proofs/Fl4Proofs/P3/ScAwaken.lean @@ -543,12 +543,14 @@ theorem SchedPre.toW {N C : Set U64} {c : U64} {s : S} {σ : Fl4Spec.State Unit} (hS : SchedRel st N T C c s σ) (h : SchedPre σ) : SchedPreW T C σ := ⟨h.1, Or.inr h.2.1, h.2.2.1, h.2.2.2.1, h.2.2.2.2, Or.inl (curOwn_of_curInv hS h.1 h.2.1)⟩ -/-- **`awaken_refines` from `SchedPreW`.** -/ +/-- **`awaken_refines` from `SchedPreW`** (mmuAD gen 42b76: over any fire relation `F`, the native one being +`Fires`, the extended spec's `ReflTransGen (fl4TimerFireVF on rc)`). -/ theorem awaken_refinesW {A : Type} {ar : machine.Arch A} {N C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW T C σ1 ∧ Pf r σ1 ⦄) : - sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, Fires σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ + sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, F σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ SchedRel st N T C c r.1 σ2 ∧ NtfnStateRel N T (L.mem r.1) σ2 ∧ NSC N C σ2 ∧ SchedPreW T C σ2 ∧ Calm σ1 σ2 ∧ (σ1.schedulerAction = .chooseNewThread → σ2.schedulerAction = .chooseNewThread) ∧ (σ1.schedulerAction ≠ .resumeCurThread → σ2.schedulerAction ≠ .resumeCurThread) ∧ diff --git a/proofs/Fl4Proofs/P3/ScChargeH.lean b/proofs/Fl4Proofs/P3/ScChargeH.lean index fe4e5ec35..1bcf3f91b 100644 --- a/proofs/Fl4Proofs/P3/ScChargeH.lean +++ b/proofs/Fl4Proofs/P3/ScChargeH.lean @@ -31,6 +31,14 @@ and XTopJointFaultTmo's `sendTmoRecvIJ`): (ScKFoot's `WritesIn.kfoot_trans`) and the spec steps composed (`ScTKw`/`SOK`/`LK`/`FK` `.trans`). `OffOK` after is vacuous (the charge zeroes the consumed time). + +(mmuAD gen 42b69, the Architect's ruling (c1)) **`JHole.j0 : JAtZB`** (was `JAtZ`): none of the hole's +constructions reads the base's `JExt`, so the hole is stated over `JAtZB` and the VM side (`VmEptState`, where the +VCPUs are live and `JExt` fails) can build one. `JAtZB.timestampJH` is `JAtZ.timestampJH` from `JAtZB` (the `JAtZ` +name its corollary via `JAtZ.toB`). `JHole.toJ`, `JHole.chargeBudgetJ` / `NJ` / `RJ` / `TJ` and `JHole.checkBudgetF` +end at `JAtZB` with the native footprint `NatFoot` from the base (P3/NatFoot; `NatFoot.ofT` of the composite +`TFoot` writes and `natK_tk` of the composite `ScTKw` step); a caller holding `JExt` at the base gets `JAtZ` back by +`JAtZB.toJN`. -/ import Fl4Proofs.P3.ScChargeR import Fl4Proofs.P3.XTopJointPP @@ -52,7 +60,8 @@ fact but `OffOK` and `CurOwnW`, as far as the charge reads them. -/ structure JHole (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s0 : S) (a0 : A) (σ0 : Fl4Spec.State Unit) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop where - j0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 + /-- `JAtZB` at the base (gen 42b69: was `JAtZ`; no construction from the hole reads `JExt`). -/ + j0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 spec : ∃ (ms : Fl4Spec.MachineState) (t c : Fl4Spec.Word), ms.underlyingMemory = σ0.machineState.underlyingMemory ∧ σ = { σ0 with machineState := ms, curTime := t, consumedTime := c } @@ -86,10 +95,10 @@ theorem JHole.sfacts {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A rfl, rfl, rfl, rfl, rfl, rfl, Hh.j0.curRun, Hh.j0.bsa.tkw hK fun p y n h hy => ⟨y, h, hy, fun _ h => h, id⟩⟩ set_option maxHeartbeats 8000000 in -/-- **`update_timestamp` from `JAtZ` ends at a `JHole`** (module docstring; -XTopJointPP's `JAtZ.timestampJD` without asking `OffOK`/`CurOwnW` after). -/ -theorem JAtZ.timestampJH {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) +/-- **`update_timestamp` from `JAtZB` ends at a `JHole`** (module docstring; +XTopJointPP's `JAtZ.timestampJD` without asking `OffOK`/`CurOwnW` after; gen 42b69: from `JAtZB`). -/ +theorem JAtZB.timestampJH {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hnow : NowAgree arI a σ) : sched.update_timestamp st arI s a ⦃ r => ∃ σ', Fl4Spec.updateTimeStamp (Z := Unit) σ = ({((), σ')}, False) ∧ σ'.kheap = σ.kheap ∧ σ'.curSc = σ.curSc ∧ σ'.releaseQueue = σ.releaseQueue ∧ σ'.curThread = σ.curThread ∧ @@ -167,6 +176,20 @@ theorem JAtZ.timestampJH {s : S} {a : A} {σ : Fl4Spec.State Unit} exact ⟨J, ⟨ms2, nv.bv, σ.consumedTime + (nv.bv - σ.curTime), hum2, rfl⟩, hwK, hX', hN2, hI2, J.cur.imp id hC2, hA2 J.act, hBlk', hDbg, hKd⟩ +/-- **`update_timestamp` from `JAtZ` ends at a `JHole`** (`JAtZB.timestampJH` via `JAtZ.toB`). -/ +theorem JAtZ.timestampJH {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) (hnow : NowAgree arI a σ) : + sched.update_timestamp st arI s a ⦃ r => ∃ σ', Fl4Spec.updateTimeStamp (Z := Unit) σ = ({((), σ')}, False) ∧ + σ'.kheap = σ.kheap ∧ σ'.curSc = σ.curSc ∧ σ'.releaseQueue = σ.releaseQueue ∧ σ'.curThread = σ.curThread ∧ + σ'.archState = σ.archState ∧ + σ'.machineState.underlyingMemory = σ.machineState.underlyingMemory ∧ + (Sched.OffReady σ → Sched.OffReady σ') ∧ + ∀ (ms2 : Fl4Spec.MachineState) (a2 : A), ms2.underlyingMemory = σ.machineState.underlyingMemory → + (AR r.2 σ.archState.x64CurrentCr3 → AR a2 σ.archState.x64CurrentCr3) → + JHole (L := L) arI AR Z H Cs Ac Lst D s a σ r.1 a2 { σ' with machineState := ms2 } ⦄ := + JAtZB.timestampJH J.toB hAK hA hnd hnow + /-- **`JHole.dbgK` across one more time-word write** (the consumed-time reset of the preemption path; KENTRY-PLAN g2i). -/ theorem JHole.dbgK_node {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} @@ -182,11 +205,12 @@ theorem JHole.dbgK_node {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a by simp [layout.node.CONSUMED], by simp [layout.node.CONSUMED], rfl⟩)) hb⟩ set_option maxHeartbeats 4000000 in -/-- **A `JHole` with `OffOK` and `CurOwnW` is a `JAtZ` state** (an SC step -from the base, as in `JAtZ.timestampJD`). -/ +/-- **A `JHole` with `OffOK` and `CurOwnW` is a `JAtZB` state** (an SC step +from the base, as in `JAtZ.timestampJD`), a native step from the base (gen 42b69: `JAtZB` and `NatFoot`, was +`JAtZ`). -/ theorem JHole.toJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hO : OffOK σ) (hOw : CurOwnW Z.T Z.C σ) : - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s a σ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s a σ ∧ NatFoot (L := L) Z s0 σ0 s σ := by have J := Hh.j0 obtain ⟨hK, hsok, hL, hF, -, -, -, -, -, -, hcr, hbsa⟩ := Hh.sfacts have hS0 := J.xtop.fin.1.1.1 @@ -204,7 +228,8 @@ theorem JHole.toJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} { exact ⟨Lst', J.sc_frame hwT hK hX' hCR' hRF' hY' hM' (J.sc_buf hwT hK) hRP' (J.sc_apart hwT hK) (J.sc_jpl hwT hK hidW.2) (J.sc_jcov hwT hDead (fun q hq hn => absurd hq hn) hidW Hh.dbgK subset_rfl) (J.sc_kern hwT hK hF hX' Hh.dbg fun _ h => h) - (J.sc_utc hwT hK Hh.dbg) Hh.nsc Hh.inv Hh.cur hOw hO hAI' hbsa hcr Hh.blk Hh.dbgK hidW.1 J.zD⟩ + (J.sc_utc hwT hK Hh.dbg) Hh.nsc Hh.inv Hh.cur hOw hO hAI' hbsa hcr Hh.blk Hh.dbgK hidW.1 J.zD, + NatFoot.ofT J.xtop hwT (fun _ h => J.tfoot_nh h) (natK_tk hK)⟩ set_option maxHeartbeats 32000000 in /-- **`charge_budget` without timeout faults from a `JHole`** (module @@ -218,7 +243,8 @@ theorem JHole.chargeBudgetJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (used : U64) : sched.charge_budget st arI s a used false ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv false σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have J := Hh.j0 obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, -, -, -, earch, -, hcrσ, hbsaσ⟩ := Hh.sfacts have hP0 := J.ip @@ -357,24 +383,25 @@ theorem JHole.chargeBudgetJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} (J.sc_jpl hW hKc hidW.2) (J.sc_jcov hW hdead (fun q hq hn => absurd hq hn) hidW hKd subset_rfl) (J.sc_kern hW hKc hfkc hX' hDbg fun _ h => h) (J.sc_utc hW hKc hDbg) hN' hI' hcur' hown' hoff hAI' hbsa hcr hblk' hKd - hidW.1 J.zD⟩ + hidW.1 J.zD, NatFoot.ofT J.xtop hW (fun _ h => J.tfoot_nh h) (natK_tk hKc)⟩ set_option maxHeartbeats 8000000 in /-- **`charge_budget` with `can_timeout_fault = true` from a `JHole`, when the current thread has no endpoint cap as its timeout handler**: ScChargeN's `JAtZ.chargeBudgetNJ` at the state after `update_timestamp`. -/ -theorem JHole.chargeBudgetNJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.chargeBudgetNJG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (hnt : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → Fl4Spec.isEpCap xt.tcbTimeoutHandler = false) + (hnt : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → Fl4Spec.isEpCap xt.tcbTimeoutHandler = false ∨ xt.tcbState = .runningVM) (used : U64) : sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have J := Hh.j0 have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 @@ -389,13 +416,29 @@ theorem JHole.chargeBudgetNJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S Fl4Spec.isValidTimeoutHandler (Z := Unit) (nodeW st s Z.c layout.node.CUR_THREAD).bv σ' = ({(b, σ')}, False) ⦄ := fun s' σ' _ hK => hval_of_rel Hh.xtop.rel.1 Hh.xtop.rel.2.1.1 hthc s' σ' hK - obtain ⟨e1, e2⟩ := charge_budget_noTmo (ar := arI) s a σ hS hR Hh.nsc Hh.inv hscC htw hS.idle hact hnr hmrt hmb + obtain ⟨e1, e2⟩ := charge_budget_noTmoG (ar := arI) s a σ hS hR Hh.nsc Hh.inv hscC htw hS.idle hact hnr hmrt hmb hval (fun xt hx => hnt xt (by rw [hs.curThread]; exact hx)) used rw [e1] refine WP.spec_mono (Hh.chargeBudgetJ hAT hC hni hnsw hmrt hmb used) ?_ rintro r ⟨h1, σ', h2, h3, h4⟩ exact ⟨h1, σ', by rw [e2]; exact h2, h3, h4⟩ +/-- The instance with no endpoint timeout handler. -/ +theorem JHole.chargeBudgetNJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) + (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnt : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → Fl4Spec.isEpCap xt.tcbTimeoutHandler = false) + (used : U64) : + sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', + Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := + Hh.chargeBudgetNJG hAT hC hni hnsw hmrt hmb (fun xt hx => Or.inl (hnt xt hx)) used + + set_option maxHeartbeats 8000000 in /-- **`charge_budget` with `can_timeout_fault = true` from a `JHole`, round-robin current SC**: ScChargeR's `JAtZ.chargeBudgetRJ` at the state after @@ -410,7 +453,8 @@ theorem JHole.chargeBudgetRJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (used : U64) : sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R0, hc, hs⟩ := hS.lists @@ -425,19 +469,40 @@ theorem JHole.chargeBudgetRJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S /-- **`charge_budget` with `can_timeout_fault = true` from a `JHole` when no timeout fault can be raised** (ScChargeR's `NoTmoSend`). -/ -theorem JHole.chargeBudgetTJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.chargeBudgetTJG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (hnt : NoTmoSend σ) (used : U64) : + (hnt : NoTmoSend σ ∨ ∃ xt, σ.kheap σ.curThread = some (.tcb xt) ∧ + xt.tcbState = .runningVM) (used : U64) : sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by - rcases hnt with h | h + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by + rcases hnt with (h | h) | ⟨xt, hk, hr⟩ · exact Hh.chargeBudgetNJ hAT hC hni hnsw hmrt hmb h used · exact Hh.chargeBudgetRJ hAT hC hni hnsw hmrt hmb h used + · refine Hh.chargeBudgetNJG hAT hC hni hnsw hmrt hmb (fun xt' hk' => Or.inr ?_) used + rw [hk] at hk' + cases hk' + exact hr + +/-- The instance with no endpoint timeout handler. -/ +theorem JHole.chargeBudgetTJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) + (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnt : NoTmoSend σ) (used : U64) : + sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', + Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := + Hh.chargeBudgetTJG hAT hC hni hnsw hmrt hmb (Or.inl hnt) used + set_option maxHeartbeats 8000000 in /-- **`check_budget` charging from a `JHole`** (KENTRY-PLAN item 10's false @@ -447,16 +512,18 @@ after `update_timestamp`, the head was insufficient, the spec's `check_budget` returns `false` too (the charge of the consumed time with `can_timeout_fault = true`, `JHole.chargeBudgetTJ`), the arch state is kept and `JAtZ` holds after. -/ -theorem JHole.checkBudgetF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.checkBudgetFG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (hnt : NoTmoSend σ) : + (hnt : NoTmoSend σ ∨ ∃ xt, σ.kheap σ.curThread = some (.tcb xt) ∧ + xt.tcbState = .runningVM) : sched.check_budget st arI s a ⦃ r => r.1 = false → r.2.2 = a ∧ ∃ σ', Fl4Spec.checkBudget (Z := Unit) σ = ({(false, σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.2.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.2.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.2.1 σ' ⦄ := by have hS := Hh.xtop.fin.1.1.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC @@ -480,7 +547,7 @@ theorem JHole.checkBudgetF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} · rw [if_neg hbt] have hbf : b = false := by simpa using hbt subst hbf - refine WP.spec_bind (Hh.chargeBudgetTJ hAT hC hni hnsw hmrt hmb hnt (nodeW st s Z.c layout.node.CONSUMED)) ?_ + refine WP.spec_bind (Hh.chargeBudgetTJG hAT hC hni hnsw hmrt hmb hnt (nodeW st s Z.c layout.node.CONSUMED)) ?_ rintro ⟨s1, a1⟩ ⟨ha1, σ', h1, hK, J'⟩ refine (WP.spec_ok _).2 fun _ => ⟨ha1, σ', ?_, hK, J'⟩ have hb' : Fl4Spec.getScRefillSufficient (Z := Unit) σ.curSc σ.consumedTime σ = ({(false, σ)}, False) := by @@ -493,6 +560,21 @@ theorem JHole.checkBudgetF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} rw [nd_gets_bind, Notif.nd_bind_one h1'] rfl +/-- The instance with no endpoint timeout handler. -/ +theorem JHole.checkBudgetF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) + (hnsw : σ.schedulerAction ≠ .switchThread σ.curThread) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnt : NoTmoSend σ) : + sched.check_budget st arI s a ⦃ r => r.1 = false → r.2.2 = a ∧ ∃ σ', + Fl4Spec.checkBudget (Z := Unit) σ = ({(false, σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.2.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.2.1 σ' ⦄ := + Hh.checkBudgetFG hAT hC hni hnsw hmrt hmb (Or.inl hnt) + + end end diff --git a/proofs/Fl4Proofs/P3/ScChargeN.lean b/proofs/Fl4Proofs/P3/ScChargeN.lean index 6cda247d2..b463a0c43 100644 --- a/proofs/Fl4Proofs/P3/ScChargeN.lean +++ b/proofs/Fl4Proofs/P3/ScChargeN.lean @@ -33,23 +33,32 @@ open Fl4Spec /-- **`endTimeslice` without a valid timeout handler** does not depend on `canTimeout`. -/ -theorem endTimeslice_noTmo {σ : State Unit} {x : SchedContext} {n : Nat} {xt : Tcb} +theorem endTimeslice_noTmoG {σ : State Unit} {x : SchedContext} {n : Nat} {xt : Tcb} (hk : σ.kheap σ.curSc = some (.schedContext x n)) (hkt : σ.kheap σ.curThread = some (.tcb xt)) - (hv : isEpCap xt.tcbTimeoutHandler = false) : + (hv : isEpCap xt.tcbTimeoutHandler = false ∨ xt.tcbState = .runningVM) : endTimeslice (Z := Unit) true σ = endTimeslice false σ := by unfold endTimeslice simp only [nd_gets_bind, nd_bind_one (isRoundRobin_eq hk), nd_bind_one (getThreadState_eq hkt)] by_cases hvm : xt.tcbState = .runningVM · simp only [hvm, ↓reduceIte, nd_pure_bind', Bool.false_eq_true, and_false] - · simp only [hvm, ↓reduceIte, nd_bind_one (Endp.isValidTimeoutHandler_eq hkt), hv, Bool.false_eq_true, + · have hv := hv.resolve_right hvm + simp only [hvm, ↓reduceIte, nd_bind_one (Endp.isValidTimeoutHandler_eq hkt), hv, Bool.false_eq_true, and_false] +/-- The instance with no endpoint timeout handler. -/ +theorem endTimeslice_noTmo {σ : State Unit} {x : SchedContext} {n : Nat} {xt : Tcb} + (hk : σ.kheap σ.curSc = some (.schedContext x n)) (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hv : isEpCap xt.tcbTimeoutHandler = false) : + endTimeslice (Z := Unit) true σ = endTimeslice false σ := + endTimeslice_noTmoG hk hkt (Or.inl hv) + + /-- **`chargeBudget` without a valid timeout handler** does not depend on `canTimeout` (the head keeps the current thread's TCB). -/ -theorem chargeBudget_noTmo {σ σ2 : State Unit} (u : Ticks) (h2 : chargeHead u σ = ({((), σ2)}, False)) +theorem chargeBudget_noTmoG {σ σ2 : State Unit} (u : Ticks) (h2 : chargeHead u σ = ({((), σ2)}, False)) (hK : HeadKeeps σ σ2 σ.curSc) {x : SchedContext} {n : Nat} (hk : σ.kheap σ.curSc = some (.schedContext x n)) {xt : Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) - (hne : σ.curThread ≠ σ.curSc) (hv : isEpCap xt.tcbTimeoutHandler = false) : + (hne : σ.curThread ≠ σ.curSc) (hv : isEpCap xt.tcbTimeoutHandler = false ∨ xt.tcbState = .runningVM) : chargeBudget (Z := Unit) u true σ = chargeBudget u false σ := by obtain ⟨hcs, hcc, -, -, -, -, -, -, hfr, hsk⟩ := hK obtain ⟨y, hy, -, -⟩ := hsk x n hk @@ -57,13 +66,22 @@ theorem chargeBudget_noTmo {σ σ2 : State Unit} (u : Ticks) (h2 : chargeHead u chargeTail_eq false σ2 rfl] split_ifs · refine nd_bind_congr ?_ - refine endTimeslice_noTmo (σ := { σ2 with consumedTime := 0 }) (x := y) (n := n) (xt := xt) ?_ ?_ hv + refine endTimeslice_noTmoG (σ := { σ2 with consumedTime := 0 }) (x := y) (n := n) (xt := xt) ?_ ?_ hv · show σ2.kheap σ2.curSc = _ rw [hcs]; exact hy · show σ2.kheap σ2.curThread = _ rw [hcc, hfr _ hne]; exact hkt · rfl +/-- The instance with no endpoint timeout handler. -/ +theorem chargeBudget_noTmo {σ σ2 : State Unit} (u : Ticks) (h2 : chargeHead u σ = ({((), σ2)}, False)) + (hK : HeadKeeps σ σ2 σ.curSc) {x : SchedContext} {n : Nat} + (hk : σ.kheap σ.curSc = some (.schedContext x n)) {xt : Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hne : σ.curThread ≠ σ.curSc) (hv : isEpCap xt.tcbTimeoutHandler = false) : + chargeBudget (Z := Unit) u true σ = chargeBudget u false σ := + chargeBudget_noTmoG u h2 hK hk hkt hne (Or.inl hv) + + end Spec section @@ -78,15 +96,21 @@ theorem bind_congr_spec {α β : Type} {m : Result α} {P : α → Prop} (hm : m /-- **FL4's `end_timeslice` without a valid timeout handler** does not depend on `can_timeout_fault`. -/ -theorem end_timeslice_noTmo (s : S) (a : A) {ct : U64} (hct : sched.cur_thread st s = ok ct) - (hv : faults.valid_timeout_handler st s ct = ok false) : +theorem end_timeslice_noTmoG (s : S) (a : A) {ct : U64} (hct : sched.cur_thread st s = ok ct) + (hv : faults.valid_timeout_handler st s ct = ok false ∨ + obj.Tcb.state st ct s = ok sched.TS_RUNNING_VM) : sched.end_timeslice st ar s a true = sched.end_timeslice st ar s a false := by obtain ⟨sc, hsc, -⟩ := spec_exists (sched.cur_sc.spec' (L := L) s) obtain ⟨rr, hrr, -⟩ := spec_exists (sporadic.is_round_robin.spec (L := L) s sc) obtain ⟨i, hi, -⟩ := spec_exists (Notif.obj.Tcb.state.spec (L := L) s ct) have hg : (if i != sched.TS_RUNNING_VM then faults.valid_timeout_handler st s ct else ok false) = ok false := by split - · exact hv + · rename_i hn + rcases hv with hv | he + · exact hv + · rw [hi, ok.injEq] at he + subst i + exact False.elim (by simpa using hn) · rfl unfold sched.end_timeslice rw [hsc, hct] @@ -96,10 +120,17 @@ theorem end_timeslice_noTmo (s : S) (a : A) {ct : U64} (hct : sched.cur_thread s rw [hg] simp only [bind_ok, ↓reduceIte, Bool.false_eq_true, ite_self] +/-- The instance with no endpoint timeout handler. -/ +theorem end_timeslice_noTmo (s : S) (a : A) {ct : U64} (hct : sched.cur_thread st s = ok ct) + (hv : faults.valid_timeout_handler st s ct = ok false) : + sched.end_timeslice st ar s a true = sched.end_timeslice st ar s a false := + end_timeslice_noTmoG s a hct (Or.inl hv) + + /-- **`charge_budget` with `can_timeout_fault = true` and no valid timeout handler** is `charge_budget` with `can_timeout_fault = false`, on both sides (module docstring; `charge_budget_refinesF`'s premises). -/ -theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) +theorem charge_budget_noTmoG {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hI : Inv σ) (hscC : nodeW st s c layout.node.CUR_SC ∈ C) (htw : L.mem s (scW (nodeW st s c layout.node.CUR_SC) 24#u64) = nodeW st s c layout.node.CUR_THREAD) @@ -115,7 +146,7 @@ theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl Fl4Spec.isValidTimeoutHandler (Z := Unit) (nodeW st s c layout.node.CUR_THREAD).bv σ' = ({(b, σ')}, False) ⦄) (hnt : ∀ xt, σ.kheap (nodeW st s c layout.node.CUR_THREAD).bv = some (.tcb xt) → - Fl4Spec.isEpCap xt.tcbTimeoutHandler = false) + Fl4Spec.isEpCap xt.tcbTimeoutHandler = false ∨ xt.tcbState = .runningVM) (used : U64) : sched.charge_budget st ar s a used true = sched.charge_budget st ar s a used false ∧ Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = Fl4Spec.chargeBudget used.bv false σ := by @@ -143,7 +174,7 @@ theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl rw [sc_ne_eq] simp only [bind_ok] refine bind_congr_spec H ?_ - rintro s2 ⟨σ2', -, hS2, -, -, -, hK, hTK, -⟩ + rintro s2 ⟨σ2', -, hS2, hR2, -, -, hK, hTK, -⟩ obtain ⟨-, hcc, -, -, -, -, -, -, hfr, -⟩ := hK have hc2 := hS2.lists.choose_spec.choose_spec.1.cur obtain ⟨s3, hs3e, hs3⟩ := spec_exists (sched.set_consumed.spec' (L := L) s2 0#u64) @@ -151,7 +182,7 @@ theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl subst hs3 rw [hs3e] simp only [bind_ok] - obtain ⟨hS3, -, -⟩ := hS2.set_node_consumed 0#u64 + obtain ⟨hS3, hF3, -⟩ := hS2.set_node_consumed 0#u64 have e1 : nodeW st (L.wr s2 (L.nodeAt s2 c layout.node.CONSUMED) 0#u64) c layout.node.CUR_THREAD = ct := eq_of_bv (by rw [← hS3.lists.choose_spec.choose_spec.2.curThread]; exact hcc.trans hs.curThread) have hc3 := hS3.lists.choose_spec.choose_spec.1.cur @@ -168,22 +199,62 @@ theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl have hkt3 : ({ σ2' with consumedTime := (0#u64).bv } : Fl4Spec.State Unit).kheap ct.bv = some (.tcb xt) := by show σ2'.kheap ct.bv = _ rw [hfr _ hcts]; exact hkt - have hb3 : b = false := by - have e := (Prod.mk.inj ((Endp.isValidTimeoutHandler_eq hkt3).symm.trans hbs)).1 - have e' := Set.singleton_eq_singleton_iff.1 e - rw [← hnt xt hkt]; exact (Prod.mk.inj e').1.symm - subst hb3 + have hv3' : faults.valid_timeout_handler st + (L.wr s2 (L.nodeAt s2 c layout.node.CONSUMED) 0#u64) ct = ok false ∨ + obj.Tcb.state st ct (L.wr s2 (L.nodeAt s2 c layout.node.CONSUMED) 0#u64) = ok sched.TS_RUNNING_VM := by + rcases hnt xt hkt with hnt | hvm + · left + have hb3 : b = false := by + have e := (Prod.mk.inj ((Endp.isValidTimeoutHandler_eq hkt3).symm.trans hbs)).1 + have e' := Set.singleton_eq_singleton_iff.1 e + rw [← hnt]; exact (Prod.mk.inj e').1.symm + rwa [hb3] at hbe + · right + have hR3 := hR2.frame hS2.placed hF3 (KView.of_kheap rfl) + have e := (hR3.at_tcb hct hkt3).st + rw [hvm] at e + obtain ⟨w, hw, ew⟩ := spec_exists (Notif.obj.Tcb.state.spec (L := L) _ ct) + have hv : w = sched.TS_RUNNING_VM := UScalar.eq_of_val_eq (by + rw [ew, e] + unfold Notif.tsCode sched.TS_RUNNING_VM + rfl) + exact hw.trans (congrArg ok hv) refine bind_congr_spec (sched.is_schedulable.spec' (L := L) _ ct) ?_ intro b1 _ cases b1 · simp only [Bool.false_eq_true, ↓reduceIte] · simp only [↓reduceIte] - rw [end_timeslice_noTmo _ a hv3 hbe] + rw [end_timeslice_noTmoG _ a hv3 hv3'] · have ecs : σ.curSc = sc.bv := hs.curSc have ecc : σ.curThread = ct.bv := hs.curThread - refine chargeBudget_noTmo used.bv h2 (by rw [ecs]; exact hK2) (by rw [ecs]; exact hk) (by rw [ecc]; exact hkt) + refine chargeBudget_noTmoG used.bv h2 (by rw [ecs]; exact hK2) (by rw [ecs]; exact hk) (by rw [ecc]; exact hkt) (by rw [ecs, ecc]; exact hcts) (hnt xt hkt) +/-- The instance with no endpoint timeout handler. -/ +theorem charge_budget_noTmo {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) + (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hI : Inv σ) + (hscC : nodeW st s c layout.node.CUR_SC ∈ C) + (htw : L.mem s (scW (nodeW st s c layout.node.CUR_SC) 24#u64) = nodeW st s c layout.node.CUR_THREAD) + (hidle : (nodeW st s c layout.node.IDLE_SC).bv = σ.idleSc) + (hact : (nodeW st s c layout.node.CUR_SC).bv ≠ σ.idleSc → ∀ x n, + σ.kheap (nodeW st s c layout.node.CUR_SC).bv = some (.schedContext x n) → Fl4Spec.scActive x = true) + (hnr : (nodeW st s c layout.node.CUR_THREAD).bv ∉ σ.releaseQueue) + (hmrt : sporadic.max_release_time ar a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hval : ∀ (s' : S) (σ' : Fl4Spec.State Unit), SchedRel st N T C c s' σ' → + TmoKeep st (nodeW st s c layout.node.CUR_THREAD) s σ s' σ' → + faults.valid_timeout_handler st s' (nodeW st s c layout.node.CUR_THREAD) ⦃ b => + Fl4Spec.isValidTimeoutHandler (Z := Unit) (nodeW st s c layout.node.CUR_THREAD).bv σ' = + ({(b, σ')}, False) ⦄) + (hnt : ∀ xt, σ.kheap (nodeW st s c layout.node.CUR_THREAD).bv = some (.tcb xt) → + Fl4Spec.isEpCap xt.tcbTimeoutHandler = false) + (used : U64) : + sched.charge_budget st ar s a used true = sched.charge_budget st ar s a used false ∧ + Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = Fl4Spec.chargeBudget used.bv false σ := + charge_budget_noTmoG s a σ hS hR hN hI hscC htw hidle hact hnr hmrt hmb hval + (fun xt hk => Or.inl (hnt xt hk)) used + + end end diff --git a/proofs/Fl4Proofs/P3/ScChargeT.lean b/proofs/Fl4Proofs/P3/ScChargeT.lean index 35f43e7a7..3a88ddc1b 100644 --- a/proofs/Fl4Proofs/P3/ScChargeT.lean +++ b/proofs/Fl4Proofs/P3/ScChargeT.lean @@ -35,6 +35,15 @@ Pieces (this module): Not covered: a timeout handler endpoint with waiting receivers (the timeout fault's transfer to a receiver for the current thread: an XTopJointFaultTmo `sendTmoRecvIJ`/`PJ` analogue from a `JTH`). +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) **`JTH.j0 : JAtZB`** (was `JAtZ`; the ruled structure change, +as `JHole.j0` in gen 42b69): nothing built from the state inside the charge reads the base's `JExt`. The posts are +`JAtZB` plus `NatFoot` from the base: `JTH.tmoBlockJA` (FL4's `CnW` writes from the base, the spec frame `ScOnly` then +`BFrT`: **`ScOnly.natK`**, `natK_bfrt`), `JTH.endTimesliceTmoJA`, `JHole.chargeBudgetTmoJA` (no `JExt` asked; the +tail by `JAtZB.reschedJ` / `JAtZB.reprogramJ`, the flag's footprint **`JAtZB.reprogramN`**). The three are ScChargeTA's +generalised copies (`hres` the disjunction) moved here in place of the originals, which are now their +`ResumeCurThread` corollaries (`tmoBlockJ`, `endTimesliceTmoJ`, `chargeBudgetTmoJ`). + +(mmuAD gen 42b71) `JAtZB.reprogramN` moved to P3/ScFireJ (statement unchanged). -/ import Fl4Proofs.P3.ScChargeH import Fl4Proofs.P3.XTopJointSendBlockG @@ -321,6 +330,11 @@ theorem ScOnly.ipcFr (h : ScOnly c σ σ') : IpcFrKeep σ σ' := by refine ⟨fun t x' hx => Or.inr ⟨x', h.tcbB hx, rfl, rfl⟩, fun p vms hp => h.othF hp (fun _ _ e => by cases e), fun p vms hp => h.othB hp (fun _ _ e => by cases e), fun p ao hp => ⟨ao, h.othF hp (fun _ _ e => by cases e), rfl⟩⟩ +/-- (mmuAD gen 42b70) **An `ScOnly` step is a native step** (P3/NatFoot's `natK_kh`: one SC changed in place, its +size kept). -/ +theorem ScOnly.natK (h : ScOnly c σ σ') : NatK σ σ' := + natK_kh (R := ScChgO c) (fun _ _ _ h => by obtain ⟨-, y, z, n, rfl, rfl, -⟩ := h; exact zvChg_sc) h + end end @@ -351,7 +365,8 @@ node-0 debug word. -/ structure JTH (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s0 : S) (a0 : A) (σ0 : Fl4Spec.State Unit) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop where - j0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 + /-- `JAtZB` at the base (mmuAD gen 42b70: was `JAtZ`; no construction from the state reads `JExt`). -/ + j0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 ws : P1.WritesIn st s0 s (KFoot st Z.T Z.N Z.C Z.c s0 σ0) xtop : XTopAt (L := L) AR Z s a σ buf : BufWordRel Z.T (L.mem s) σ @@ -385,7 +400,7 @@ XTopJointSendBlockG's `JAtZ.runTmoJ` tail for the current thread (no assembled from the base `JAtZ` with the composite frame (the head's `ScOnly`, then the send's `BFrT`); `Inv` after from `InvBut` at the hole by `InvBut.ik` and `inClassR`'s exemption of a sender with a timeout fault. -/ -theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JTH.tmoBlockJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrr : x.tcbState = .running ∨ x.tcbState = .restart) @@ -394,11 +409,12 @@ theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : (hya : Fl4Spec.scActive y = true) {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) - (hres : σ.schedulerAction = .resumeCurThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) (b : U64) : faults.handle_timeout st arI s a t (error.Fault.Timeout b) ⦃ res => ∃ z ∈ (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ⦄ := by + ∃ (V : XVs) (D' : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hj.j0 have hO := Hj.ksc have hP0 := J.ip @@ -477,7 +493,8 @@ theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : obtain rfl : g = g' := hg.symm obtain rfl : gr = gr' := hgr.symm refine WP.spec_bind (Pₘ := fun r : Bool × S × A => ∃ z ∈ (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' r.2.1 r.2.2 z.2) ?_ ?_ + ∃ (V : XVs) (D' : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' r.2.1 r.2.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 r.2.1 z.2) ?_ ?_ swap · rintro ⟨b0, s2, a2⟩ hr0 exact (WP.spec_ok _).2 hr0 @@ -519,7 +536,7 @@ theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : · by_contra hq' have hm := (hcq.released t ht).1 hq' exact hnq.2 (by rw [hs.rel, mem_map_bv]; exact hm) - · exact actionW_ne_of hS ht (by rw [hres]; intro e; cases e) + · exact actionW_ne_of hS ht (by rcases hres with e | e <;> rw [e] <;> intro e' <;> cases e') · intro h have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] @@ -675,7 +692,12 @@ theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : rw [← Hj.dbg] exact hfoot.mem_eq J.kern.dwAl fun hk => P1.dbg0_not_schedW Hj.blk J.kern.cs0 (Or.inl (by rw [eN]; exact hk)) have hS3 : SchedRel st Z.N Z.T Z.C Z.c s' σ' := hIR.2.2.1 - have hact3 : σ'.schedulerAction = .chooseNewThread := hact'' (by rw [hσf]; exact htc) (by rw [hσf]; exact hres) + have hact3 : σ'.schedulerAction = .chooseNewThread := by + rcases hres with e | e + · exact hact'' (by rw [hσf]; exact htc) (by rw [hσf]; exact e) + · rcases hact' with e' | e' + · exact e'.trans e + · exact e' have hAI3 : ActIdle σ' := ⟨fun u hu => (by rw [hact3] at hu; cases hu), F.idleOK Hj.act.2 hidt⟩ have hrun3 : CurRunM σ' := Or.inl (by rw [hact3]; intro e; cases e) @@ -753,20 +775,40 @@ theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : J.cnW_utc hW hF.1 e_cdt e_orig e_arch hDbg, F.nsc Hj.nsc, I3, Or.inl hact3, F.own Hj.own, hoff, hAI3, F.bsa Hj.bsa hscA, F.isorted Hj.isorted fun y1 hy1 => (hsrt y1 hy1).congr fun u _ => (hprf u).symm, hrun3, hblk⟩ - have hC0 := JCs.same J hF.1 hkszc + have hC0 := JCs.sameB J hF.1 hkszc have hCs : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ exact ⟨Z.vs, D \ {ptr}, J.cs_frameI hks hX3 hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) e_arch haoc hszc hF.1 hkbc hfkc hCs R hKd e_orig - (XTopAt.idleW_eqS J.xtop hX3 e_idle) (J.zD_diffE hpE)⟩ + (XTopAt.idleW_eqS J.xtop hX3 e_idle) (J.zD_diffE hpE), + NatFoot.ofW J.xtop hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) + (fun b hb => J.cnW_nh hb) (hO.natK.trans (natK_bfrt F))⟩ all_goals simp [absCap] at habs6 +/-- `JTH.tmoBlockJA` under `ResumeCurThread` (mmuAD gen 42b70: ScChargeTA's generalised copy is now the proof here). -/ +theorem JTH.tmoBlockJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) + (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hrr : x.tcbState = .running ∨ x.tcbState = .restart) + {sc : U64} (hsc : sc ∈ Z.C) (hxsc : x.tcbSchedContext = some sc.bv) + {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) + (hya : Fl4Spec.scActive y = true) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) + (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) + (hres : σ.schedulerAction = .resumeCurThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) + (b : U64) : + faults.handle_timeout st arI s a t (error.Fault.Timeout b) ⦃ res => ∃ z ∈ + (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, + ∃ (V : XVs) (D' : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := + Hj.tmoBlockJA ht htc hk hrr hsc hxsc hky hya hth hcb (Or.inl hres) hnq hidt b + set_option maxHeartbeats 16000000 in /-- **`end_timeslice` with `can_timeout_fault = true` at a `JTH` state, the current thread with an endpoint timeout handler on an idle or sending endpoint and a non-round-robin SC**: both sides take the timeout-fault branch (`handle_timeout` of the current thread with the SC's badge), then `JTH.tmoBlockJ`. -/ -theorem JTH.endTimesliceTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JTH.endTimesliceTmoJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrr : x.tcbState = .running ∨ x.tcbState = .restart) @@ -775,9 +817,10 @@ theorem JTH.endTimesliceTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (hya : Fl4Spec.scActive y = true) (hper : y.scPeriod ≠ 0) {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) - (hres : σ.schedulerAction = .resumeCurThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) : + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) : sched.end_timeslice st arI s a true ⦃ res => ∃ z ∈ (Fl4Spec.endTimeslice (Z := Unit) true σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ⦄ := by + ∃ (V : XVs) (D' : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hj.j0 have hS := Hj.xtop.fin.1.1.1 have hR := Hj.xtop.fin.1.1.2.2.1 @@ -835,11 +878,27 @@ theorem JTH.endTimesliceTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S simp only [↓reduceIte, Bool.false_eq_true] step with obj.Sc.badge.spec' as ⟨bd', hbd'⟩ subst hbd' - refine WP.spec_mono (Hj.tmoBlockJ ht htc hk hrr hsc hxsc hky hya hth hcb hres hnq hidt _) ?_ + refine WP.spec_mono (Hj.tmoBlockJA ht htc hk hrr hsc hxsc hky hya hth hcb hres hnq hidt _) ?_ rintro res ⟨z, hz, V, D', J'⟩ exact ⟨z, by rw [hspec]; exact hz, V, D', J'⟩ +/-- `JTH.endTimesliceTmoJA` under `ResumeCurThread` (mmuAD gen 42b70). -/ +theorem JTH.endTimesliceTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) + (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (hrr : x.tcbState = .running ∨ x.tcbState = .restart) + {sc : U64} (hsc : sc ∈ Z.C) (hcs : σ.curSc = sc.bv) (hxsc : x.tcbSchedContext = some sc.bv) + {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) + (hya : Fl4Spec.scActive y = true) (hper : y.scPeriod ≠ 0) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) + (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) + (hres : σ.schedulerAction = .resumeCurThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) : + sched.end_timeslice st arI s a true ⦃ res => ∃ z ∈ (Fl4Spec.endTimeslice (Z := Unit) true σ).1, + ∃ (V : XVs) (D' : Set U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := + Hj.endTimesliceTmoJA ht htc hk hrr hsc hcs hxsc hky hya hper hth hcb (Or.inl hres) hnq hidt + set_option maxHeartbeats 64000000 in /-- **`charge_budget` with `can_timeout_fault = true` from a `JHole`, the current thread's timeout fault blocking it** (module docstring): the current @@ -850,9 +909,9 @@ its SC is not round-robin. The head charge at the hole (SchedRel-level consumed-time reset, the `JTH` state there (`ScOnly` from the base), then `end_timeslice` (`JTH.endTimesliceTmoJ`), `reschedule_required` (`JAtZ.reschedJ`) and the reprogram flag (`JAtZ.reprogramJ`) at `J`. -/ -theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +theorem JHole.chargeBudgetTmoJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) - (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -863,7 +922,7 @@ theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) (used : U64) : sched.charge_budget st arI s a used true ⦃ res => ∃ z ∈ (Fl4Spec.chargeBudget (Z := Unit) used.bv true σ).1, ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hh.j0 obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, ect0, eact0, eidle0, earch0, erel0, -, hbsaσ⟩ := Hh.sfacts obtain ⟨ms0, tm0, cn0, -, eσ⟩ := Hh.spec @@ -1034,7 +1093,8 @@ theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : by rw [show σ3.releaseQueue = σ.releaseQueue from hrel2, hpt]; exact hC.notRel⟩ have hidt3 : σ3.idleThread ≠ ct.bv := by rw [show σ3.idleThread = σ.idleThread from hid2, hpt]; exact fun e => hni e.symm - have hres3 : σ3.schedulerAction = .resumeCurThread := hact2.trans hres + have hres3 : σ3.schedulerAction = .resumeCurThread ∨ σ3.schedulerAction = .chooseNewThread := + hres.imp (fun e => hact2.trans e) (fun e => hact2.trans e) have hp3 : ∀ xe, σ3.kheap p = some (.endpoint xe) → Endp.CanBlock false xe := fun xe h => by by_cases e : p = sc.bv · rw [e, hky3] at h; cases h @@ -1053,10 +1113,10 @@ theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : rw [hy'.period] at h1' exact P1.eq_of_bv h1' rw [e3, ← hx.period]; exact hper0 - refine WP.spec_bind (Hj.endTimesliceTmoJ hct hct3.symm hkt3 hrr hscC (hcs2.trans hpc.symm) hxs hky3 hya2 hper2 + refine WP.spec_bind (Hj.endTimesliceTmoJA hct hct3.symm hkt3 hrr hscC (hcs2.trans hpc.symm) hxs hky3 hya2 hper2 hth hp3 hres3 hnq3 hidt3) ?_ - rintro ⟨s4, a1⟩ ⟨z4, hz4, V4, D4, J4⟩ - obtain ⟨s5, hs5, σ5, h5, Ac5, Lst5, D5, J5⟩ := J4.reschedJ + rintro ⟨s4, a1⟩ ⟨z4, hz4, V4, D4, J4, F4⟩ + obtain ⟨s5, hs5, σ5, h5, Ac5, Lst5, D5, J5, F5⟩ := J4.reschedJ refine WP.spec_bind (show sched.reschedule_required st s4 ⦃ s' => s' = s5 ⦄ by rw [hs5]; exact (WP.spec_ok _).2 rfl) ?_ rintro _ rfl @@ -1064,11 +1124,30 @@ theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : rintro s6 rfl rw [WP.spec_ok] beta_reduce - refine ⟨((), { σ5 with reprogramTimer := true }), ?_, V4, Ac5, Lst5, D5, J5.reprogramJ⟩ + refine ⟨((), { σ5 with reprogramTimer := true }), ?_, V4, Ac5, Lst5, D5, J5.reprogramJ, + J.natTrans (J.natTrans F4 F5.cast) J5.reprogramN.cast⟩ rw [chargeBudget_eq, nd_bind_one h2, chargeTail_eq true σ2 (hcc2.trans hs.curThread), if_pos hsch] refine mem_bind_nd (x := z4) hz4 (mem_bind_nd (x := ((), σ5)) (show ((), σ5) ∈ (Fl4Spec.rescheduleRequired (Z := Unit) z4.2).1 by rw [h5]; exact Set.mem_singleton _) ?_) simp [Fl4Spec.NonDet.modify] + +/-- `JHole.chargeBudgetTmoJA` under `ResumeCurThread` (mmuAD gen 42b70). -/ +theorem JHole.chargeBudgetTmoJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) + (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) + (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) (used : U64) : + sched.charge_budget st arI s a used true ⦃ res => ∃ z ∈ (Fl4Spec.chargeBudget (Z := Unit) used.bv true σ).1, + ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := + Hh.chargeBudgetTmoJA hAT hC hni (Or.inl hres) hnq hmrt hmb hkt hrr hth hper hcb used + end end diff --git a/proofs/Fl4Proofs/P3/ScChargeTA.lean b/proofs/Fl4Proofs/P3/ScChargeTA.lean index 79a8d6a05..d211a315a 100644 --- a/proofs/Fl4Proofs/P3/ScChargeTA.lean +++ b/proofs/Fl4Proofs/P3/ScChargeTA.lean @@ -10,783 +10,10 @@ disjunction), P1's `CanBlock` asks only "no switch to the thread"; so the blocking send is the same as under `ResumeCurThread` (l4v `handle_timeout` → `send_fault_ipc` → `send_ipc`'s block, with `set_thread_state_act` a no-op when no `resume_cur_thread`). + +(mmuAD gen 42b70) The four copies are gone: their generalised proofs (`hres` the disjunction) replaced the originals +in place, `JTH.tmoBlockJA`, `JTH.endTimesliceTmoJA`, `JHole.chargeBudgetTmoJA` in P3/ScChargeT and +`JHole.checkBudgetTA` in P3/XTopJointBudgetT (over `JAtZB` with `NatFoot` from the base, the Architect's ruling (c1) +part 2), the unsuffixed names their `ResumeCurThread` corollaries. This module keeps the import for its users. -/ import Fl4Proofs.P3.XTopJointBudgetT -open Aeneas Aeneas.Std Result - -namespace Fl4Proofs.P3 -open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc - Fl4Proofs.P3.Sched - -noncomputable section - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} -variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} - {Lst : U64 → List U64} {D : Set U64} - -set_option maxHeartbeats 64000000 in -/-- **The current thread's timeout fault blocking it on its timeout -handler's endpoint, at the state inside `charge_budget`** (module docstring): -XTopJointSendBlockG's `JAtZ.runTmoJ` tail for the current thread (no -`set_thread_state` before), started at a `JTH` state; `JAtZ` after, -assembled from the base `JAtZ` with the composite frame (the head's -`ScOnly`, then the send's `BFrT`); `Inv` after from `InvBut` at the hole by -`InvBut.ik` and `inClassR`'s exemption of a sender with a timeout fault. -/ -theorem JTH.tmoBlockJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) - (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - (hrr : x.tcbState = .running ∨ x.tcbState = .restart) - {sc : U64} (hsc : sc ∈ Z.C) (hxsc : x.tcbSchedContext = some sc.bv) - {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) - (hya : Fl4Spec.scActive y = true) - {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) - (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) - (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) - (b : U64) : - faults.handle_timeout st arI s a t (error.Fault.Timeout b) ⦃ res => ∃ z ∈ - (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ⦄ := by - have J := Hj.j0 - have hO := Hj.ksc - have hP0 := J.ip - have hks0 : L.ksb s = L.ksb s0 := Hj.ws.1 - have hI0 := J.xtop.irelK J.ks J.buf - have hI' := Hj.xtop.irelK (by rw [hks0]; exact J.ks) Hj.buf - have hI : IRel st Z.th σ0.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s σ := by - rw [← Hj.arch]; exact hI' - have hS := Hj.xtop.fin.1.1.1 - have hT : TcbPlaced Z.T := hP0.e.tcb - have hta := hP0.e.tcb t ht - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb - have hk0 : σ0.kheap t.bv = some (.tcb x) := hO.tcbB hk - have hD : t ∉ D := fun h => by - have hd := J.jcov.dead t h - have h1 := (hd.1 htH).1 - obtain ⟨x1, hk1, hTR⟩ := hI0.1.tcb t ht - rw [hk0] at hk1; cases hk1 - have hst := hTR.st - rw [← stA_tStA, h1] at hst - unfold sched.TS_INACTIVE at hst - rcases hrr with e | e <;> rw [e] at hst <;> simp [tsCode] at hst - have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ0.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) - (c := Z.c) hP0.e - -- the handler cap at the base, its endpoint, the cover - obtain ⟨⟨G0, hB0⟩, -⟩ := hI0.2.1 - have hth0 : Z.th t = some .tcb := hB0.tcbT hk0 - obtain ⟨xh, cv, hkh, hcv, hca⟩ := hB0.2.1.1.timeoutCap hth0 - rw [hk0] at hkh; cases hkh - have habs := hca.2 - rw [hth] at habs - obtain ⟨ptr, bdg, sd, rv, g, gr, rfl⟩ : ∃ ptr bdg sd rv g gr, cv = .Endpoint ptr bdg sd rv g gr := by - cases cv <;> simp [absCap] at habs; exact ⟨_, _, _, _, _, _, rfl⟩ - simp only [absCap, Fl4Spec.Cap.endpointCap.injEq] at habs - obtain ⟨hp, hbd, hr⟩ := habs - subst hp hbd hr - have hAS : AbsSlot Z.th (t.bv, Fl4Spec.tcbCnodeIndex 4) := ⟨t, rfl, Or.inr ⟨hth0, 4, by decide, rfl⟩⟩ - have hcv' : capAt (L.mem s0) (cslotAddr (t.bv, Fl4Spec.tcbCnodeIndex 4)) = ok (.Endpoint ptr bdg sd rv g gr) := by - rw [tcbSlot4_eq]; exact hcv - have hpE : ptr ∈ Z.E := J.slotE hAS hcv' - obtain ⟨xe, hke0, -⟩ := hI0.1.ep ptr hpE - have hke : σ.kheap ptr.bv = some (.endpoint xe) := hO.othF hke0 (fun _ _ e => by cases e) - have hcbe : Endp.CanBlock false xe := hcb xe hke - have hpt : ptr.bv ≠ t.bv := fun e => by rw [e, hk] at hke; cases hke - have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE - have hfit := J.kern.heap.fits ptr _ hHe - simp only [P1.HKind.bits] at hfit - have hcov := J.cover_cap (P1.WritesIn.refl s0 _) hAS.isSlot hcv' (fun h => by cases h) (ok_inj (phys_eq _).symm) rfl - (range_ep ptr bdg sd rv g gr hfit) fun k hk' => by - rw [hHe] at hk'; cases hk' - exact ⟨by simp only [P1.HKind.bits]; omega, fun z h => by cases h⟩ - -- the FL4 step from the base to the hole (`CnStep`) - have hC1 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s0 σ0 s σ := - ⟨Hj.ws.mono fun b hb => Or.inl (Or.inl hb), SzKeepC.of hO.szKeep⟩ - -- `handle_timeout`: the handler cap at the hole - obtain ⟨⟨G6, hB6⟩, -⟩ := hI.2.1 - obtain ⟨xh6, cv6, hkh6, hcv6, hca6⟩ := hB6.2.1.1.timeoutCap (hB6.tcbT hk) - rw [hk] at hkh6; cases hkh6 - have habs6 := hca6.2 - rw [hth] at habs6 - unfold faults.handle_timeout - rw [tcb_slot_timeout] - apply ok_bind_spec - rw [slot_cap_eq, hcv6] - apply ok_bind_spec - cases cv6 - case Endpoint ptr' bdg' sd' rv' g' gr' => - simp only [absCap, Fl4Spec.Cap.endpointCap.injEq] at habs6 - obtain ⟨hp', hbd', hr'⟩ := habs6 - obtain rfl : ptr = ptr' := (P1.eq_of_bv hp').symm - obtain rfl : bdg = bdg' := (P1.eq_of_bv hbd').symm - have hg : g' = g := by have := congrArg (fun R => decide (Fl4Spec.Rights.allowGrant ∈ R)) hr'; simpa [rights_grant] using this - have hgr : gr' = gr := by - have := congrArg (fun R => decide (Fl4Spec.Rights.allowGrantReply ∈ R)) hr'; simpa [rights_grantReply] using this - obtain rfl : g = g' := hg.symm - obtain rfl : gr = gr' := hgr.symm - refine WP.spec_bind (Pₘ := fun r : Bool × S × A => ∃ z ∈ (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' r.2.1 r.2.2 z.2) ?_ ?_ - swap - · rintro ⟨b0, s2, a2⟩ hr0 - exact (WP.spec_ok _).2 hr0 - unfold faults.send_fault_ipc - dsimp only - -- `set_fault` - set x2 : Fl4Spec.Tcb := { x with tcbFault := some (.timeout b.bv) } with hx2 - set σf := updK σ t.bv (.tcb x2) with hσf - refine WP.spec_bind (WP.spec_and (WP.spec_and (set_fault_timeout_top hP0 hI ht hk b) - (set_fault_timeout_eq s t b)) (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s t (error.Fault.Timeout b) - (t0 := t) Hj.blk htH (fun _ h => by simp at h) ?hcb6) - (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s t (error.Fault.Timeout b) hTH htH))) ?_ - case hcb6 => - obtain ⟨Q, R0, hcq, hs⟩ := hS.lists - obtain ⟨x7, hk7, hTR7⟩ := hI.1.tcb t ht - rw [hk] at hk7; cases hk7 - have hv7 : (L.mem s (tStA t)).val = tsCode x.tcbState := hTR7.st - have hrr' : L.mem s (P1.stA t) = sched.TS_RUNNING ∨ L.mem s (P1.stA t) = sched.TS_RESTART := by - rcases hrr with e | e - · left; apply UScalar.eq_of_val_eq; rw [P1.stA_eq, ← tStA_eq, hv7, e]; unfold sched.TS_RUNNING; rfl - · right; apply UScalar.eq_of_val_eq; rw [P1.stA_eq, ← tStA_eq, hv7, e]; unfold sched.TS_RESTART; rfl - obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb t ht - rw [hk] at hkt6; cases hkt6 - have hst6 : L.mem s (scA t) = sc := P1.eq_of_bv (Notif.optRef_some (hsct6.symm.trans hxsc)).2 - obtain ⟨y', n', hky', hy'⟩ := hs.scs sc hsc - rw [hky] at hky'; cases hky' - have hmx : (L.rmax s (L.mem s (scA t))).val ≠ 0 := by rw [hst6]; exact hy'.rmax_ne hya - refine ⟨htH, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · rcases hrr' with h | h <;> rw [h] - · exact P1.not_blocked_running - · exact P1.not_blocked_restart - · rcases hrr' with h | h <;> rw [h] - · exact P1.running_ne.1 - · exact P1.restart_ne.1 - · by_contra hq' - have hm := (hcq.queued t ht).1 hq' - exact hnq.1 0 _ (by rw [hs.rq _ (hcq.prio t ht), mem_map_bv]; exact hm) - · by_contra hq' - have hm := (hcq.released t ht).1 hq' - exact hnq.2 (by rw [hs.rel, mem_map_bv]; exact hm) - · exact actionW_ne_of hS ht (by rcases hres with e | e <;> rw [e] <;> intro e' <;> cases e') - · intro h - have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by - unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] - exact hidt (by rw [hs.idleTh, ← ei, h]) - · intro hbd - obtain ⟨⟨Q', R', h0⟩, hBd, hXi, hSc, hSg⟩ := Hj.blk - obtain ⟨hiS, -, -⟩ := hXi.2.2.bound _ htH hbd - exact (hSc.act _ hiS).2 (fun e => hmx (by rw [e]; rfl)) - rintro s7 ⟨⟨⟨hsp7, hI7⟩, hs7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ - have hkf : σf.kheap t.bv = some (.tcb x2) := by simp [hσf, updK] - have hkfp : ∀ q, q ≠ t.bv → σf.kheap q = σ.kheap q := by - intro q hq'; rw [hσf]; simp only [updK, Function.update_of_ne hq'] - have hkef : σf.kheap ptr.bv = some (.endpoint xe) := by rw [hkfp _ hpt]; exact hke - -- the FL4 step of `set_fault` - have hC2 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ s7 σf := by - refine ⟨?_, SzKeepC.of (SzKeep.of_tcb (p := t.bv) (x' := x2) (fun q hq' => by simp [hσf, updK, hq']) hkf)⟩ - subst hs7 - have w := (((writesIn_wr (st := st) (s := s) (v := fl4_abi.consts.fault.Timeout) (a_fault hta).1).trans - (writesIn_wr (v := b) (a_fw0 hta).1)).trans (writesIn_wr (v := 0#u64) (a_fw1 hta).1)).trans - (writesIn_wr (v := 0#u64) (a_fw2 hta).1) - refine w.mono fun w0 hw0 => ?_ - have k : ∃ K : Nat, 256 ≤ K ∧ K < 4096 ∧ K ≠ 3440 ∧ K ≠ 3472 ∧ ((K ≠ 3512 ∧ K ≠ 3528) ∧ K ≠ 3664 ∧ K ≠ 3456) ∧ w0.val = t.val + K := by - rcases hw0 with ((h | h) | h) | h <;> subst h - · exact ⟨3376, by omega, by omega, by omega, by omega, by omega, val_fault hta⟩ - · exact ⟨3384, by omega, by omega, by omega, by omega, by omega, val_fw0 hta⟩ - · exact ⟨3392, by omega, by omega, by omega, by omega, by omega, val_fw1 hta⟩ - · exact ⟨3400, by omega, by omega, by omega, by omega, by omega, val_fw2 hta⟩ - obtain ⟨K, k1, k2, k3, k4, k5, k6⟩ := k - exact Or.inl (Or.inr ⟨t, ht, K, k1, k2, k3, k4, k5, k6⟩) - -- the spec's blocking send at `σf` - have hprf : ∀ u, Sched.prioOf σf u = Sched.prioOf σ u := by - intro u - by_cases hut : u = t.bv - · subst hut; exact (prioOf_eq hkf).trans (prioOf_eq hk).symm - · unfold Sched.prioOf; rw [tcbsOf_eq, tcbsOf_eq, hkfp u hut] - have hrun : Fl4Spec.runnable x.tcbState = true := by rcases hrr with e | e <;> rw [e] <;> rfl - have htq : t.bv ∉ xe.epQueue := - Endp.not_queued hI.1.toE ht hk (by rcases hrr with e | e <;> rw [e] <;> exact ⟨by decide, by decide⟩) ptr hpE xe hke - have hqm : ∀ u ∈ xe.epQueue, ∃ z, σf.kheap u = some (.tcb z) := fun u hu => by - obtain ⟨z, hz, -⟩ := (J.sv.epQ _ _ hke0).2 u hu - exact ⟨z, by rw [hkfp u (fun e => htq (e ▸ hu)), hO.tcbF hz]⟩ - have hsrt0 : SortedQ σ xe.epQueue := (Hj.isorted.1 _ _ hke) - obtain ⟨σ', heq, F0, hik0, ⟨ds, hkt'⟩, -, hact', hact'', hsrt⟩ := - sendIpcBlock_eq hkf hkef hcbe htq hqm hrun (hsrt0.congr fun u _ => hprf u) false bdg.bv g gr false - -- FL4's blocking send - have hIS : IpcSorted σf := QPK.QPS.sorted (QPK.qps_upd (ko := .tcb x2) hk rfl) Hj.isorted - obtain ⟨⟨Q0, R0, h0⟩, hB0', hX0, hS0, hSg0⟩ := hblk7 - have hst0 : L.epState s7 ptr = 0#u64 ∨ L.epState s7 ptr = 1#u64 := by - have hx := hI7.1.toE.at_ep hpE hkef - rw [epState_eq] - cases xe with - | idleEP => exact Or.inl hx.1 - | sendEP q => exact Or.inr hx.1 - | recvEP q => simp [Endp.CanBlock] at hcbe - have hnb : tsCode x2.tcbState ≠ 3 ∧ tsCode x2.tcbState ≠ 4 := by - show tsCode x.tcbState ≠ 3 ∧ tsCode x.tcbState ≠ 4 - rcases hrr with e | e <;> rw [e] <;> exact ⟨by decide, by decide⟩ - have hnn : ∀ m, x2.tcbState ≠ .blockedOnNotification m := fun m h => by - have h' : x.tcbState = .blockedOnNotification m := h - rcases hrr with e | e <;> rw [e] at h' <;> cases h' - have p1f : endpoint.send_ipc st arI s7 a true false bdg g gr false t ptr ⦃ s' _ => P1.Foot st (P1.Heap.tcbs H) Cs - (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s7 s' ⦄ := - P1.endpoint.send_ipc.blockFoot arI s7 a true false bdg g gr false t ptr h0 (fun _ => hcb7) hHe hst0 - refine WP.spec_bind (WP.spec_and (WP.spec_and (send_ipc_blockF (ar := arI) hP0 s7 a σf hI7 ht hkf hnb hnn hpE hkef - hcbe (Sched.qSorted_of_spec (L := L) hI7.1.toE hI7.1.toN hT hIS ptr (Or.inl hpE)) false bdg g gr false) - (P1.endpoint.send_ipc.block arI s7 a true false bdg g gr false t ptr Q0 R0 h0 hB0' hX0 hS0 hSg0 - (fun _ => hcb7) hHe hst0)) - p1f) ?_ - rintro ⟨s', a'⟩ ⟨⟨⟨ea, σ0', h0eq, hIR, hW3⟩, hbk⟩, hfoot3⟩ - simp only [WP.uncurry'_pair] at ea hbk hfoot3 hIR hW3 - subst a' - obtain rfl : σ' = σ0' := by - have e1 := (Prod.mk.inj (h0eq.symm.trans heq)).1 - exact (congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 e1)).symm - apply (WP.spec_ok _).2 - -- the spec's outcome - have hz : ((), σ') ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv - (decide (Fl4Spec.Rights.allowGrant ∈ rightsOf sd rv g gr)) - (decide (Fl4Spec.Rights.allowGrantReply ∈ rightsOf sd rv g gr)) false t.bv ptr.bv - (updK σ t.bv (.tcb { x with tcbFault := some (.timeout b.bv) }))).1 := by - rw [rights_grant, rights_grantReply] - show ((), σ') ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv g gr false t.bv ptr.bv σf).1 - rw [heq]; exact Set.mem_singleton _ - refine ⟨((), σ'), handleTimeout_mem hk hth _ hz, ?_⟩ - -- the frame from the hole - have hkt3 : σ'.kheap t.bv = - some (.tcb { x with tcbState := .blockedOnSend ptr.bv ds, tcbFault := some (.timeout b.bv) }) := hkt' - have hsk : Sk σ σ' := (show Sk σ σf from ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩).trans F0.sk - have F : BFrT t.bv ptr.bv σ σ' := by - refine ⟨hsk, fun q => ?_⟩ - by_cases hqt : q = t.bv - · subst hqt - exact Or.inr ⟨_, _, hk, hkt3, Or.inl ⟨x, ptr.bv, ds, some (.timeout b.bv), rfl, rfl, rfl⟩⟩ - · rcases F0.kh q with e | ⟨o, o', h1, h2, hc⟩ - · exact Or.inl (e.trans (hkfp q hqt)) - · rw [hkfp q hqt] at h1 - rcases hc with ⟨_, _, _, _, _, e3, -⟩ | ⟨x1, y1, rfl, rfl, e3⟩ - · exact absurd e3 hqt - · exact Or.inr ⟨_, _, h1, h2, Or.inr ⟨x1, y1, rfl, rfl, e3⟩⟩ - -- the FL4 footprint from the base - have hC3 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s7 σf s' σ' := ⟨hW3, SzKeepC.of F0.szKeep⟩ - have hW : P1.WritesIn st s0 s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s0 σ0) := - ((hC1.trans hC2).trans hC3).1 - have hfoot := P1.Foot.trans hfoot7 hfoot3 - have hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s' := ⟨⟨Q0, R0, hbk.1⟩, hbk.2⟩ - -- the composite frame from the base - have e_ct : σ'.curThread = σ0.curThread := F.sk.ct.trans Hj.ct - have e_idle : σ'.idleThread = σ0.idleThread := F.sk.idle.trans Hj.idle - have e_csc : σ'.curSc = σ0.curSc := F.sk.csc.trans Hj.csc - have e_cdt : σ'.cdt = σ0.cdt := F.sk.cdt.trans Hj.cdt - have e_orig : σ'.isOriginalCap = σ0.isOriginalCap := F.sk.orig.trans Hj.orig - have e_arch : σ'.archState = σ0.archState := F.sk.arch.trans Hj.arch - have e_isc : σ'.idleSc = σ0.idleSc := F.sk.isc.trans Hj.isc - have hszc : SzKeep σ0 σ' := SzKeep.trans' hO.szKeep F.szKeep - have hykc : YKeep σ0 σ' := hO.ykeep.trans F.ykeep - have hmkc : McpKeep σ0 σ' := hO.mcpKeep.trans F.mcpKeep - have hbkc : BufKeep σ0 σ' := BufKeep.trans hO.bufKeep F.bufKeep - have hkbc : KBack σ0 σ' := KBack.trans' hO.kback F.kback - have hkszc : KSz σ0 σ' := KSz.trans hO.ksz F.ksz - have hksubc : KSub σ0 σ' := KSub.trans hO.ksub F.ksub - have hrbc : KhRB σ0 σ' := KhRB.trans hO.khrb F.khrb - have hfkc : IpcFrKeep σ0 σ' := hO.ipcFr.trans F.ipcFr - have haoc : ∀ q ao, σ0.kheap q = some (.archObj ao) → σ'.kheap q = some (.archObj ao) := fun q ao h => - F.othF (hO.othF h (fun _ _ e => by cases e)) (fun _ e => by cases e) (fun _ e => by cases e) - have ck1 : ∀ q y n, σ0.kheap q = some (.schedContext y n) → ∃ y', σ'.kheap q = some (.schedContext y' n) ∧ - y'.scReplies = y.scReplies := fun q y n hq => by - obtain ⟨z, hz, -, -, -, hr, -⟩ := hO.scF hq - exact ⟨z, F.scF hz, hr⟩ - have ck2 : ∀ q x, σ0.kheap q = some (.reply x) → ∃ x', σ'.kheap q = some (.reply x') ∧ x'.replySc = x.replySc := - fun q x hq => ⟨x, F.replyF (hO.othF hq (fun _ _ e => by cases e)), rfl⟩ - -- the assembly (as `JAtZ.runTmoJ`) - have hAR' : AR a σ0.archState.x64CurrentCr3 := by - have h := Hj.xtop.fin.1.1.2.2.2.2.2.2; rw [Hj.arch] at h; exact h - have hF : IFrame (L := L) Z.th s0 s' := IRel.iframe_of hI0 hW fun b hb => CnW.oobj hI0.2.2.1 hb - have hIR' : IRel st Z.th σ0.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s' σ' := hIR - obtain ⟨V', hX3⟩ := XTopAt.irel_same J.xtop hIR' hAR' hF.1 e_cdt e_orig hksubc hF.2 - have hks : L.ksb s' = L.ksb s0 := hF.2 - obtain ⟨k1, k2, kb, k3, k4⟩ := J.cnW_keeps hW - have hCR' : CallRel (L.mem s') Z.R Z.C σ' Lst := - J.call.frame k3 k4 (fun q _ y n hy => ck1 _ y n hy) (fun d _ x hx => ck2 _ x hx) - have hRP' := J.rp.frame hks hszc - have hRF' : RFree (L.mem s') Z.R Z.C σ' Lst := by - intro d hd hfd - obtain ⟨y, hy, hyt⟩ := hfd - obtain ⟨e1, e2⟩ := k4 d hd - obtain ⟨h1, h2, h3⟩ := J.rfree d hd ⟨y, hO.othB (F.replyB hy) (fun _ _ e => by cases e), hyt⟩ - exact ⟨h1, by rw [e2]; exact h2, by rw [e1]; exact h3⟩ - have eN : L.nodeAt s 0#u64 layout.node.DEBUG_TCBS = L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS := - P1.nodeAt_of_ksb hks0 _ _ - have hDbg : L.mem s' (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) = - L.mem s0 (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) := by - rw [← Hj.dbg] - exact hfoot.mem_eq J.kern.dwAl fun hk => P1.dbg0_not_schedW Hj.blk J.kern.cs0 (Or.inl (by rw [eN]; exact hk)) - have hS3 : SchedRel st Z.N Z.T Z.C Z.c s' σ' := hIR.2.2.1 - have hact3 : σ'.schedulerAction = .chooseNewThread := by - rcases hres with e | e - · exact hact'' (by rw [hσf]; exact htc) (by rw [hσf]; exact e) - · rcases hact' with e' | e' - · exact e'.trans e - · exact e' - have hAI3 : ActIdle σ' := - ⟨fun u hu => (by rw [hact3] at hu; cases hu), F.idleOK Hj.act.2 hidt⟩ - have hrun3 : CurRunM σ' := Or.inl (by rw [hact3]; intro e; cases e) - -- the dead: the thread is not dead; the endpoint leaves the dead set - have hdead : ∀ q ∈ D \ {ptr}, DeadP (L := L) H s' q := fun q hq => by - have hd := J.jcov.dead q hq.1 - have hqt : q.bv ≠ t.bv := fun h => hD (by rw [← P1.eq_of_bv h]; exact hq.1) - have hqe : q.bv ≠ ptr.bv := fun h => hq.2 (P1.eq_of_bv h) - refine J.deadP_keep hS3 hIR.1 - (fun x hx h0 => ⟨_, F.tcbO hqt (hO.tcbF hx), rfl, rfl, Or.inl rfl⟩) (fun x hx => ?_) - (fun x hx => ⟨x, F.ntfnF (hO.othF hx (fun _ _ e => by cases e)), Or.inl rfl, rfl, Or.inl rfl⟩) - (fun x hx => ⟨x, F.replyF (hO.othF hx (fun _ _ e => by cases e)), rfl⟩) - (fun x n hx => by - obtain ⟨z, hz, k1', -, -, -, k5'⟩ := hO.scF hx - exact ⟨z, F.scF hz, Or.inl k1', k5'⟩) - (fun hqC => k3 q hqC) (fun z hz hqC K hK8 hK => J.cnW_scOut hW hz hqC hK8 hK) e_idle hAI3.1 - (J.yld.frame k2 hykc) (hykc.dk q.bv) hd - obtain ⟨y, hy, hc'⟩ := F.epF (hO.othF hx (fun _ _ e => by cases e)) - rcases hc' with rfl | e1 - · exact hy - · exact absurd e1 hqe - have hidl := J.idleW_keep hS3 e_idle e_isc - have hjpl : ∃ Tr Cq, JPlaced (L := L) Z.th H Tr Cq s' σ' := by - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - exact ⟨Tr, Cq, hJ.same hF.1 (fun q y n _ hq => hszc q.bv y n hq) hks (J.cnW_irq hW) hidl.2⟩ - have hkern := J.kern_keep hks hW.2.1 hS3 e_ct e_csc (fun sl h => Or.inl (by rw [← e_orig]; exact h)) - (by rw [e_arch]) haoc hDbg (D' := D \ {ptr}) - have hRR' := J.rrecv.frame k4 hrbc - have hKd : P1.DbgKeep st (P1.Heap.tcbs H) Cs s0 s' := - Hj.dbgK.trans (P1.Foot.dbgKeep Hj.blk (by first | exact fun _ h => h | exact Set.empty_subset _) hfoot) - have hDX : Sched.DXKeep (L := L) H Cs s0 s' := DXKeep.of_dbg hKd (J.cnW_td hW) - have hjcov : JCovD (L := L) Z.th H Z.G (D \ {ptr}) Cs s' := by - obtain ⟨-, ⟨-, -, hM, -, -⟩, -⟩ := J.xtop.rel - have hsl : ∀ x ∈ Z.G.chains.flatten, IsSlot Z.th x := fun x h => ((hM.members x).1 h).1 - exact (J.jcov.undead hcov.1 hcov.2).same (fun y hy _ _ => ⟨hy, hF.1.capV (hsl y hy)⟩) - (fun q hq _ => hdead q hq) - (J.jcov.ks.keep hks fun x hx p sb fi d hc => ⟨x, hx, fi, by rw [← hF.1.capV (hsl x hx)]; exact hc⟩) hidl hks - (J.jcov.idleOut.keep hidl fun x hx p sb fi d hc => ⟨x, hx, fi, by rw [← hF.1.capV (hsl x hx)]; exact hc⟩) - (fun q _ h => h.keep hDX) - -- `Inv` (`InvBut.ik` at the hole; the thread a sender with a timeout fault, `inClassR`) - have hts6 : Fl4Spec.threadSet (Z := Unit) (fun tcb => { tcb with tcbFault := some (.timeout b.bv) }) t.bv σ = - ({((), σf)}, False) := Notif.threadSet_eq _ hk - have hik : IK t.bv σ σ' := - ((ikm_threadSet (t := t.bv) (p := t.bv) - (g := fun tcb => { tcb with tcbFault := some (.timeout b.bv) }) - fun _ => ⟨rfl, fun h => absurd rfl h, fun h => absurd rfl h⟩).of_eq hts6).trans hik0 - have hIt : InvBut σ t.bv := by rw [htc]; exact Hj.inv - obtain ⟨hIB, -⟩ := hIt.ik hnq hik - have I3 : Inv σ' := hIB.inv fun x' hx' hc => by - rw [hkt3] at hx'; cases hx' - exact (inClassR.notTmoS hc ptr.bv ds b.bv rfl rfl).elim - -- `BlockedScActive`: an SC bound to the thread is its SC, active - have hscA : ∀ q y1 n1, σ.kheap q = some (.schedContext y1 n1) → y1.scTcb = some t.bv → - Fl4Spec.scActive y1 = true := by - intro q y1 n1 hq' hyt' - obtain ⟨xu, hku, hxu⟩ : ∃ xu : Fl4Spec.Tcb, - σ.kheap t.bv = some (.tcb xu) ∧ xu.tcbSchedContext = some q := by - obtain ⟨y0, hy0, ey1, -, -, -⟩ := hO.scB hq' - obtain ⟨c, hcC, eq⟩ := J.obj.sc q y0 n1 hy0 - subst eq - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hc0 := J.c0 c hcC - have hcS : c ∈ P1.Heap.scs H := ⟨_, (hJ.sc c y0 n1 hc0 hy0).2⟩ - obtain ⟨u, -, -, xu, hku, hxs⟩ := scBack_of J.xtop.fin.1.1.1 J.blk.2.2.1 J.tcbs_eq.1.symm hcC hcS hc0 hy0 - (by rw [← ey1]; exact hyt') - exact ⟨xu, hO.tcbF hku, hxs⟩ - rw [hk] at hku; cases hku - have e1 : q = sc.bv := Option.some.inj (hxu.symm.trans hxsc) - rw [e1, hky] at hq'; cases hq' - exact hya - have hoff : OffOK σ' := fun h0 => absurd h0 (by rw [F.sk.cons, Hj.cons]; decide) - have R : JRest (L := L) arI (Z.mv Z.G V') H Cs Ac Lst (D \ {ptr}) s' σ' := - ⟨hCR', hRF', hRR', J.yld.frame k2 hykc, J.mcp.frame k1 hmkc, J.buf.frame kb hbkc, hRP', - J.apart.sc_frame hks hszc, hjpl, hjcov, hkern, - J.cnW_utc hW hF.1 e_cdt e_orig e_arch hDbg, F.nsc Hj.nsc, I3, Or.inl hact3, F.own Hj.own, hoff, - hAI3, F.bsa Hj.bsa hscA, F.isorted Hj.isorted fun y1 hy1 => (hsrt y1 hy1).congr fun u _ => (hprf u).symm, - hrun3, hblk⟩ - have hC0 := JCs.same J hF.1 hkszc - have hCs : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ - exact ⟨Z.vs, D \ {ptr}, J.cs_frameI hks hX3 hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) e_arch haoc hszc - hF.1 hkbc hfkc hCs R hKd e_orig - (XTopAt.idleW_eqS J.xtop hX3 e_idle) (J.zD_diffE hpE)⟩ - all_goals simp [absCap] at habs6 - -set_option maxHeartbeats 16000000 in -/-- **`end_timeslice` with `can_timeout_fault = true` at a `JTH` state, the -current thread with an endpoint timeout handler on an idle or sending -endpoint and a non-round-robin SC**: both sides take the timeout-fault branch -(`handle_timeout` of the current thread with the SC's badge), then -`JTH.tmoBlockJ`. -/ -theorem JTH.endTimesliceTmoJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) {t : U64} (ht : t ∈ Z.T) - (htc : t.bv = σ.curThread) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - (hrr : x.tcbState = .running ∨ x.tcbState = .restart) - {sc : U64} (hsc : sc ∈ Z.C) (hcs : σ.curSc = sc.bv) (hxsc : x.tcbSchedContext = some sc.bv) - {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) - (hya : Fl4Spec.scActive y = true) (hper : y.scPeriod ≠ 0) - {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : x.tcbTimeoutHandler = .endpointCap p bd r) - (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) - (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) : - sched.end_timeslice st arI s a true ⦃ res => ∃ z ∈ (Fl4Spec.endTimeslice (Z := Unit) true σ).1, - ∃ (V : XVs) (D' : Set U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D' res.1 res.2 z.2 ⦄ := by - have J := Hj.j0 - have hS := Hj.xtop.fin.1.1.1 - have hR := Hj.xtop.fin.1.1.2.2.1 - obtain ⟨Q, R0, hc, hs⟩ := hS.lists - have ect : nodeW st s Z.c layout.node.CUR_THREAD = t := P1.eq_of_bv (by rw [← hs.curThread]; exact htc.symm) - have ecs : nodeW st s Z.c layout.node.CUR_SC = sc := P1.eq_of_bv (by rw [← hs.curSc]; exact hcs) - obtain ⟨y', n', hky', hy'⟩ := hs.scs sc hsc - rw [hky] at hky'; cases hky' - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hthc : Z.th t = some .tcb := (hJ.tcb _).2 (J.zH.1 _ ht) - have hvm : x.tcbState ≠ .runningVM := by rcases hrr with e | e <;> rw [e] <;> intro h <;> cases h - -- the spec: the timeout-fault branch - have hspec : Fl4Spec.endTimeslice (Z := Unit) true σ = - Fl4Spec.handleTimeout t.bv (.timeout (L.mem s (scW sc 48#u64)).bv) σ := by - unfold Fl4Spec.endTimeslice - rw [nd_gets_bind, hcs, nd_bind_one (isRoundRobin_eq hky), nd_gets_bind, ← htc, - nd_bind_one (getThreadState_eq hk)] - simp only [hvm, ↓reduceIte] - rw [nd_bind_one (Endp.isValidTimeoutHandler_eq hk), hth, if_pos, nd_bind_one (getSchedContext_eq hky), - hy'.badge] - simp [Fl4Spec.isEpCap] - exact hper - -- FL4: the reads - have hval := hval_of_rel Hj.xtop.rel.1 Hj.xtop.rel.2.1.1 hthc s σ (TmoKeep.refl _ _ _) - obtain ⟨tx, hkt, -⟩ := hs.tcb t ht - rw [hk] at hkt; cases hkt - have hst := (hR.at_tcb ht hk).st - have hnvm : (L.mem s (tStA t) != sched.TS_RUNNING_VM) = true := by - have e8 : sched.TS_RUNNING_VM = 8#u64 := by unfold sched.TS_RUNNING_VM; rfl - rw [bne_iff_ne, e8] - intro e - rw [e] at hst - rcases hrr with e' | e' <;> rw [e'] at hst <;> simp [tsCode] at hst - unfold sched.end_timeslice - step with sched.cur_sc.spec' as ⟨sc', hsc'⟩ - step with sched.cur_thread.spec' as ⟨ct', hct'⟩ - rw [hc.cur, ecs] at hsc' - rw [hc.cur, ect] at hct' - subst hsc' hct' - step with sporadic.is_round_robin.spec as ⟨rr, hrr'⟩ - have hrr0 : rr = false := by - rw [hrr'] - apply decide_eq_false - intro e - exact hper (by rw [hy'.period, e]; rfl) - subst hrr0 - step with Notif.obj.Tcb.state.spec as ⟨i, hi⟩ - rw [hi, if_pos hnvm] - refine WP.spec_bind hval ?_ - intro v hv - have hv' : v = true := by - rw [Endp.isValidTimeoutHandler_eq hk, hth] at hv - exact ((Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (Prod.mk.inj hv).1)).1).symm - subst hv' - simp only [↓reduceIte, Bool.false_eq_true] - step with obj.Sc.badge.spec' as ⟨bd', hbd'⟩ - subst hbd' - refine WP.spec_mono (Hj.tmoBlockJA ht htc hk hrr hsc hxsc hky hya hth hcb hres hnq hidt _) ?_ - rintro res ⟨z, hz, V, D', J'⟩ - exact ⟨z, by rw [hspec]; exact hz, V, D', J'⟩ - - -set_option maxHeartbeats 64000000 in -/-- **`charge_budget` with `can_timeout_fault = true` from a `JHole`, the -current thread's timeout fault blocking it** (module docstring): the current -thread (`Running` or `Restart`, not queued, the action `ResumeCurThread`) has -an endpoint cap as its timeout handler whose endpoint is idle or sending, and -its SC is not round-robin. The head charge at the hole (SchedRel-level -`charge_head_refinesK`, P1's `charge_head.ring`/`charge_pre_post`), the -consumed-time reset, the `JTH` state there (`ScOnly` from the base), then -`end_timeslice` (`JTH.endTimesliceTmoJ`), `reschedule_required` -(`JAtZ.reschedJ`) and the reprogram flag (`JAtZ.reprogramJ`) at `J`. -/ -theorem JHole.chargeBudgetTmoJA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) - (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) - (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) - (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) - (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) - (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) - {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) - (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) - (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) (used : U64) : - sched.charge_budget st arI s a used true ⦃ res => ∃ z ∈ (Fl4Spec.chargeBudget (Z := Unit) used.bv true σ).1, - ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ⦄ := by - have J := Hh.j0 - obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, ect0, eact0, eidle0, earch0, erel0, -, hbsaσ⟩ := Hh.sfacts - obtain ⟨ms0, tm0, cn0, -, eσ⟩ := Hh.spec - have ecs0 : σ.curSc = σ0.curSc := by rw [eσ] - have eisc0 : σ.idleSc = σ0.idleSc := by rw [eσ] - have ecdt0 : σ.cdt = σ0.cdt := by rw [eσ] - have eorig0 : σ.isOriginalCap = σ0.isOriginalCap := by rw [eσ] - have hP0 := J.ip - have hS := Hh.xtop.fin.1.1.1 - have hR := Hh.xtop.fin.1.1.2.2.1 - have hARs := Hh.xtop.fin.1.1.2.2.2.2.2.2 - have hT : TcbPlaced Z.T := hP0.e.tcb - obtain ⟨Q, R0, hc, hs⟩ := hS.lists - obtain ⟨hscC, hsc0, htw, hts, hact, hnr, hnb⟩ := CurInv.facts hS Hh.inv hC - set sc := nodeW st s Z.c layout.node.CUR_SC with hscd - set ct := nodeW st s Z.c layout.node.CUR_THREAD with hctd - have hct : ct ∈ Z.T := hc.curT - have ecur : L.curW s = ct := by - show L.mem s (L.nodeAt s (L.cpu s) _) = _; rw [hc.cur]; rfl - have ecsc : L.cscW s = sc := by - show L.mem s (L.nodeAt s (L.cpu s) _) = _; rw [hc.cur]; rfl - have hpc : sc.bv = σ.curSc := hs.curSc.symm - have hpt : ct.bv = σ.curThread := hs.curThread.symm - have hcsI := curSc_ne_idleSc_of Hh.inv Hh.act hC hni - obtain ⟨x, n, hk, hx⟩ := hs.scs _ hscC - have hxa : Fl4Spec.scActive x = true := hact (by rw [hpc]; exact hcsI) x n hk - have hkt' : σ.kheap ct.bv = some (.tcb xt) := by rw [hpt]; exact hkt - have hxs : xt.tcbSchedContext = some sc.bv := by - obtain ⟨xt1, hk1, hs1, -⟩ := hC.tcb - rw [hkt] at hk1; cases hk1; rw [hs1, hpc] - have hne : ct.bv ≠ sc.bv := fun e => by rw [e, hk] at hkt'; cases hkt' - have hper0 : x.scPeriod ≠ 0 := hper x n (by rw [← hpc]; exact hk) - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hscS : sc ∈ P1.Heap.scs H := ⟨_, (hJ.sc _ x n hsc0 (by rw [← ekh]; exact hk)).2⟩ - obtain ⟨⟨Q1, R1, h1⟩, hB1, hX1, hS1, hSg1⟩ := Hh.blk - have hcS : L.cscW s ∈ P1.Heap.scs H := hX1.2.2.cur - have hcA : L.cscW s ∈ Ac := by - rw [ecsc]; exact (hS1.act _ hscS).2 (fun e => hx.rmax_ne hxa (by rw [e]; rfl)) - have hW1 := hS1.wf hcS hcA - -- the program - unfold sched.charge_budget - step with sched.cur_sc.spec' as ⟨sc', hsc'⟩ - step with sched.idle_sc.spec' as ⟨id', hid'⟩ - rw [hc.cur] at hsc' hid' - subst hsc' hid' - rw [sc_ne_eq] - simp only [bind_ok] - have hb : decide (sc ≠ nodeW st s Z.c layout.node.IDLE_SC) = decide (sc.bv ≠ σ.idleSc) := by - rw [← hS.idle] - apply decide_eq_decide.2 - exact ⟨fun h e => h (P1.eq_of_bv e), fun h e => h (by rw [e])⟩ - refine WP.spec_bind (WP.spec_and (charge_head_refinesK s a σ hS hR Hh.nsc Hh.inv hscC htw hact hnr hmrt hmb - used _ hb) (P1.sched.charge_head.ring hAT s a used hX1 hcS hW1 ecsc.symm _)) ?_ - rintro s2 ⟨⟨σ2, h2, hS2, hR2, hN2, hI2, hK, hTK, hW2⟩, w2, wf2⟩ - have hK' := hK - obtain ⟨hcs2, hcc2, hrel2, hact2, -, hid2, hisc2, hrq2, hfr2, hsck2⟩ := hK' - obtain ⟨y2, hky2, hyt2, hym2⟩ := hsck2 x n hk - have mem2 : ((), σ2) ∈ (chargeHead used.bv σ).1 := by rw [h2]; exact Set.mem_singleton _ - have hKh : ScTKw (fun _ => False) σ σ2 := (nkt_chargeHead used.bv) σ _ mem2 - have hsokh : SOK (true, true) σ σ2 := pres_chargeHead _ _ σ _ mem2 - have hlkh : LK (fun _ => False) σ σ2 := lkm_chargeHead _ _ σ _ mem2 - have hfkh : FK σ σ2 := fk_chargeHead _ σ _ mem2 - have hc2 := hS2.lists.choose_spec.choose_spec.1.cur - have hN2' := hS2.lists.choose_spec.choose_spec.1.node - -- the consumed-time reset - step with sched.set_consumed.spec' as ⟨s3, hs3⟩ - rw [hc2] at hs3 - subst hs3 - have w3 := sfoot_wr_node hN2' (o := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) - (by simp [layout.node.CONSUMED]) 0#u64 - obtain ⟨hS3', hf3, -⟩ := hS2.set_node_consumed 0#u64 - set σ3 : Fl4Spec.State Unit := { σ2 with consumedTime := 0 } with hσ3 - set s3 := L.wr s2 (L.nodeAt s2 Z.c layout.node.CONSUMED) 0#u64 with hs3d - have hS3 : SchedRel st Z.N Z.T Z.C Z.c s3 σ3 := hS3' - have hR3 : NtfnStateRel Z.N Z.T (L.mem s3) σ3 := hR2.frame hS2.placed hf3 (KView.of_kheap rfl) - have hN3 : NSC Z.N Z.C σ3 := hN2 - have hI3 : InvBut σ3 ct.bv := hI2.congr rfl rfl rfl rfl - obtain ⟨Q3, R3, hc3, hs3⟩ := hS3.lists - have e1 : nodeW st s3 Z.c layout.node.CUR_THREAD = ct := - P1.eq_of_bv (by rw [← hs3.curThread]; exact hcc2.trans hs.curThread) - have e2 : nodeW st s3 Z.c layout.node.CUR_SC = sc := - P1.eq_of_bv (by rw [← hs3.curSc]; exact hcs2.trans hs.curSc) - -- P1 after the reset - obtain ⟨hblk3, hG3⟩ := P1.charge_pre_post (G := fun s' => P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) - (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s') h1 hB1 hX1 hSg1 hS1 w2 wf2 - (fun _ _ g1 g2 => g1.trans g2) (P1.WritesIn.refl _ _) - rw [hc2] at hblk3 hG3 - -- the spec state after the reset against the base - have hky3 : σ3.kheap sc.bv = some (.schedContext y2 n) := hky2 - have hkp3 : ∀ q, q ≠ sc.bv → σ3.kheap q = σ.kheap q := fun q hq => hfr2 q hq - have hO : ScOnly σ0.curSc σ0 σ3 := by - intro q - by_cases hq : q = sc.bv - · subst hq - right - have h0 : σ0.kheap sc.bv = some (.schedContext x n) := by rw [← ekh]; exact hk - have hpk : PK (true, true) (.schedContext x n) (.schedContext y2 n) := by - have h := hsokh.kh sc.bv; rw [hk, hky2] at h; exact h - obtain ⟨-, hyf, hrp⟩ := hpk - have hl : LObj (.schedContext x n) (.schedContext y2 n) := by - have h := (hlkh sc.bv).resolve_left id; rw [hk, hky2] at h; exact h - obtain ⟨y', e', -, hnt⟩ := hl.2.1 x n rfl - cases e' - exact ⟨_, _, h0, hky3, by rw [hpc, ecs0], x, y2, n, rfl, rfl, hyt2, hym2, hyf rfl, hrp rfl, hnt⟩ - · left - rw [hkp3 q hq, ekh] - have hzO : SzKeepC Z.C σ0 σ3 := SzKeepC.of hO.szKeep - -- FL4's writes from the base - have hWK : P1.WritesIn st s s3 (KFoot st Z.T Z.N Z.C Z.c s σ) := WritesIn.kfoot_sfoot hW2 w3 - have hWK0 : P1.WritesIn st s0 s3 (KFoot st Z.T Z.N Z.C Z.c s0 σ0) := - WritesIn.kfoot_trans Hh.ws (fun sc1 _ x1 n1 h => ⟨x1, by rw [← ekh]; exact h⟩) hWK - have hW0 : P1.WritesIn st s0 s3 (TFoot st Z.T Z.N Z.C Z.c s0 σ0) := WritesIn.tfoot_of_kfoot hWK0 - have hK3 : ScTKw (fun _ => False) σ2 σ3 := - ⟨fun p => OTK.refl _ _, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ - have hKc : ScTKw (fun _ => False) σ0 σ3 := (hK0.trans hKh).trans hK3 - have hX3 : XTopAt (L := L) AR Z s3 a σ3 := - xtop_sc_step (ct := σ0.curThread) J.xtop hP0 J.nk hW0 hKc.ofFalse hS3 hR3 fun _ => by - rw [← earch0]; exact hARs - -- the scheduler facts at the reset - have hA2 := Hh.act.headKeeps hK ⟨x, n, hk⟩ - have hAI3 : ActIdle σ3 := hA2.keep (TKeepE.of_kheap _ rfl) (fun _ h => h) (Or.inl rfl) rfl - have hya2 : Fl4Spec.scActive y2 = true := by simp only [Fl4Spec.scActive, hym2]; exact hxa - have hbsa3 : BlockedScActive σ3 := by - refine hbsaσ.back (fun q y1 n1 hq ha => ?_) (fun t x1 hx1 hq => ?_) - · by_cases e : q = sc.bv - · rw [e, hky3] at hq; cases hq; rw [hya2] at ha; cases ha - · exact ⟨y1, by rw [← hkp3 q e]; exact hq, ha, fun _ h => h, id⟩ - · have e : t ≠ sc.bv := fun e => by rw [e, hky3] at hx1; cases hx1 - exact ⟨x1, by rw [← hkp3 t e]; exact hx1, hq⟩ - have hown3 : CurOwnW Z.T Z.C σ3 := by - obtain ⟨u, hu, xu, hku, hxu, hou, -⟩ := curOwn_of_curInv hS Hh.inv hC - have hup : u.bv ≠ sc.bv := fun e => by rw [e, hk] at hku; cases hku - refine Or.inl ⟨u, hu, xu, by rw [hkp3 _ hup]; exact hku, - by rw [show σ3.curSc = σ.curSc from hfkh.1]; exact hxu, fun y1 n1 hy1 => ?_, - fun h0 => absurd h0 (by rw [show σ3.consumedTime = 0 from rfl]; decide)⟩ - rw [show σ3.curSc = σ.curSc from hfkh.1, ← hpc, hky3] at hy1; cases hy1 - rw [hyt2]; exact hou x n (by rw [← hpc]; exact hk) - have hsort3 : IpcSorted σ3 := - J.isorted.frame (fun q x' hq => ⟨x', hO.othB hq (fun _ _ e => by cases e), rfl⟩) - (fun q x' hq => ⟨x', hO.othB hq (fun _ _ e => by cases e), rfl⟩) hO.prio - have eN : L.nodeAt s 0#u64 layout.node.DEBUG_TCBS = L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS := - P1.nodeAt_of_ksb Hh.ws.1 _ _ - have hDbg3 : L.mem s3 (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) = - L.mem s0 (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) := by - rw [← Hh.dbg] - exact hG3.mem_eq J.kern.dwAl fun hk' => P1.dbg0_not_schedW Hh.blk J.kern.cs0 (Or.inl (by rw [eN]; exact hk')) - have hct3 : σ3.curThread = ct.bv := hcc2.trans hs.curThread - have Hj : JTH (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s3 a σ3 := - { j0 := J, ws := hWK0, xtop := hX3, buf := J.sc_buf hW0 hKc, nsc := hN3, - inv := by rw [hct3]; exact hI3, act := hAI3, bsa := hbsa3, own := hown3, isorted := hsort3, - blk := hblk3, dbg := hDbg3, dbgK := Hh.dbgK.trans (P1.Foot.dbgKeep Hh.blk (fun _ h => h) hG3), ksc := hO, ct := hcc2.trans ect0, idle := hid2.trans eidle0, - csc := hcs2.trans ecs0, rel := hrel2.trans erel0, cdt := hsokh.cdt.trans ecdt0, - orig := hsokh.orig.trans eorig0, arch := hKh.arch.trans earch0, isc := hisc2.trans eisc0, cons := rfl } - -- the tail: the current thread, schedulable - step with sched.cur_thread.spec' as ⟨ct', hct'⟩ - rw [hc3.cur, e1] at hct' - subst hct' - step with Fl4Proofs.P3.Sched.sched.is_schedulable.spec' as ⟨b1, hb1⟩ - rw [schedulable_eq hR3 hS3 hct] at hb1 - subst hb1 - have hkt3 : σ3.kheap ct.bv = some (.tcb xt) := by rw [hkp3 _ hne]; exact hkt' - have hrun : Fl4Spec.runnable xt.tcbState = true := by rcases hrr with e | e <;> rw [e] <;> rfl - have hsch : Fl4Spec.schedulable ct.bv σ3 = true := - schedulable_of hkt3 hxs hrun hky3 hya2 (by rw [show σ3.releaseQueue = σ.releaseQueue from hrel2]; rw [hpt]; exact hC.notRel) - simp only [hsch, ↓reduceIte] - have hnq3 : NotQueued σ3 ct.bv := - ⟨fun d q => by rw [show σ3.readyQueues = σ.readyQueues from hrq2, hpt]; exact hnq d q, - by rw [show σ3.releaseQueue = σ.releaseQueue from hrel2, hpt]; exact hC.notRel⟩ - have hidt3 : σ3.idleThread ≠ ct.bv := by - rw [show σ3.idleThread = σ.idleThread from hid2, hpt]; exact fun e => hni e.symm - have hres3 : σ3.schedulerAction = .resumeCurThread ∨ σ3.schedulerAction = .chooseNewThread := - hres.imp (fun e => hact2.trans e) (fun e => hact2.trans e) - have hp3 : ∀ xe, σ3.kheap p = some (.endpoint xe) → Endp.CanBlock false xe := fun xe h => by - by_cases e : p = sc.bv - · rw [e, hky3] at h; cases h - · rw [hkp3 _ e] at h; exact hcb xe h - have hper2 : y2.scPeriod ≠ 0 := by - obtain ⟨y', n', hky', hy'⟩ := hs3.scs sc hscC - rw [hky3] at hky'; cases hky' - rw [hy'.period] - have e3 : L.rperiod s3 sc = L.rperiod s sc := by - have hp2 : L.rperiod s2 sc = L.rperiod s sc := by - have := P1.rperiod_of_ring hX1 hcS w2; rw [ecsc] at this; exact this - rw [← hp2] - obtain ⟨y'', n'', hky'', hy''⟩ := (hS2.lists.choose_spec.choose_spec.2).scs sc hscC - rw [hky2] at hky''; cases hky'' - have h1' := hy''.period - rw [hy'.period] at h1' - exact P1.eq_of_bv h1' - rw [e3, ← hx.period]; exact hper0 - refine WP.spec_bind (Hj.endTimesliceTmoJA hct hct3.symm hkt3 hrr hscC (hcs2.trans hpc.symm) hxs hky3 hya2 hper2 - hth hp3 hres3 hnq3 hidt3) ?_ - rintro ⟨s4, a1⟩ ⟨z4, hz4, V4, D4, J4⟩ - obtain ⟨s5, hs5, σ5, h5, Ac5, Lst5, D5, J5⟩ := J4.reschedJ - refine WP.spec_bind (show sched.reschedule_required st s4 ⦃ s' => s' = s5 ⦄ by - rw [hs5]; exact (WP.spec_ok _).2 rfl) ?_ - rintro _ rfl - refine WP.spec_bind (sched.set_reprogram.spec' (L := L) _) ?_ - rintro s6 rfl - rw [WP.spec_ok] - beta_reduce - refine ⟨((), { σ5 with reprogramTimer := true }), ?_, V4, Ac5, Lst5, D5, J5.reprogramJ⟩ - rw [chargeBudget_eq, nd_bind_one h2, chargeTail_eq true σ2 (hcc2.trans hs.curThread), if_pos hsch] - refine mem_bind_nd (x := z4) hz4 (mem_bind_nd (x := ((), σ5)) - (show ((), σ5) ∈ (Fl4Spec.rescheduleRequired (Z := Unit) z4.2).1 by rw [h5]; exact Set.mem_singleton _) ?_) - simp [Fl4Spec.NonDet.modify] - -end - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} -variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} - {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - -set_option maxHeartbeats 8000000 in -/-- **`check_budget` charging from a `JHole`, the current thread's timeout -fault blocking it** (module docstring). -/ -theorem JHole.checkBudgetTA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) - (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) - (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) - (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) - (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) - (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) - {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) - (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) - (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) : - sched.check_budget st arI s a ⦃ res => res.1 = false → ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ).1, - z.1 = false ∧ ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ⦄ := by - have hS := Hh.xtop.fin.1.1.1 - obtain ⟨Q, R, hc, hs⟩ := hS.lists - obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC - obtain ⟨x, n, hk, hx⟩ := hs.scs _ hscC - unfold sched.check_budget - step with sched.cur_sc.spec' as ⟨sc', hsc'⟩ - step with sched.consumed.spec' as ⟨cn, hcn⟩ - rw [hc.cur] at hsc' hcn - subst hsc' hcn - have hax : Fl4Spec.scActive x = true := by - by_cases hi : (nodeW st s Z.c layout.node.CUR_SC).bv = σ.idleSc - · exact hx.active_of_rmax (hx.idle hi) - · exact hact hi x n hk - refine WP.spec_bind (sufficient_refines s a σ hS hscC hk hax _ hmb) ?_ - intro b hb - by_cases hbt : b = true - · rw [if_pos hbt, is_cur_domain_expired_eq] - simp only [bind_ok] - refine (WP.spec_ok _).2 ?_ - intro h; exact absurd h (by simp) - · rw [if_neg hbt] - have hbf : b = false := by simpa using hbt - subst hbf - refine WP.spec_bind (Hh.chargeBudgetTmoJA hAT hC hni hres hnq hmrt hmb hkt hrr hth hper hcb - (nodeW st s Z.c layout.node.CONSUMED)) ?_ - rintro ⟨s1, a1⟩ ⟨z, hz, V, Ac', Lst', D', J'⟩ - refine (WP.spec_ok _).2 fun _ => ⟨(false, z.2), ?_, rfl, V, Ac', Lst', D', J'⟩ - have hb' : Fl4Spec.getScRefillSufficient (Z := Unit) σ.curSc σ.consumedTime σ = ({(false, σ)}, False) := by - rw [hs.curSc, hs.consumed]; exact hb - have hz' : z ∈ (Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime true σ).1 := by - rw [hs.consumed]; exact hz - unfold Fl4Spec.checkBudget - rw [nd_gets_bind, nd_gets_bind, Notif.nd_bind_one hb'] - simp only [Bool.false_eq_true, ↓reduceIte] - rw [nd_gets_bind] - exact mem_bind_nd (x := z) hz' (by simp [pure, Fl4Spec.NonDet.pure]) - -end - -end - -end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/ScChargeTR.lean b/proofs/Fl4Proofs/P3/ScChargeTR.lean index 762c332bd..3bf27e4c9 100644 --- a/proofs/Fl4Proofs/P3/ScChargeTR.lean +++ b/proofs/Fl4Proofs/P3/ScChargeTR.lean @@ -7,6 +7,10 @@ ScChargeTA's `JTH.endTimesliceTmoJA`, `JHole.chargeBudgetTmoJA`, handler endpoint receiving (`hkl`) in place of idle/sending (`hcb`), the send ScTmoCtRecv's `JTH.tmoRecvJ` in place of `JTH.tmoBlockJA`, and the platform facts `hmax`/`htu` [P] (as XTopJointFaultTmo's `runTmoP_recv`). + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) Over `JAtZB` with `NatFoot` from the hole's base, no `JExt` +asked (`JTH.j0 : JAtZB`): `endTimesliceTmoJR`, `chargeBudgetTmoJR` (the tail by `JAtZB.reschedJ`, `reprogramJ`, +`reprogramN`), `checkBudgetTR`. -/ import Fl4Proofs.P3.ScTmoCtRecv import Fl4Proofs.P3.ScChargeTA @@ -44,7 +48,7 @@ theorem JTH.endTimesliceTmoJR {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) : sched.end_timeslice st arI s a true ⦃ res => ∃ z ∈ (Fl4Spec.endTimeslice (Z := Unit) true σ).1, ∃ (V : XVs) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' res.1 res.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' res.1 res.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hj.j0 have hS := Hj.xtop.fin.1.1.1 have hR := Hj.xtop.fin.1.1.2.2.1 @@ -131,7 +135,7 @@ theorem JHole.chargeBudgetTmoJR {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s (hkl : ∃ l, σ.kheap p = some (.endpoint (.recvEP l))) (used : U64) : sched.charge_budget st arI s a used true ⦃ res => ∃ z ∈ (Fl4Spec.chargeBudget (Z := Unit) used.bv true σ).1, ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.1 res.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hh.j0 obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, ect0, eact0, eidle0, earch0, erel0, -, hbsaσ⟩ := Hh.sfacts obtain ⟨ms0, tm0, cn0, -, eσ⟩ := Hh.spec @@ -325,8 +329,8 @@ theorem JHole.chargeBudgetTmoJR {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s rw [e3, ← hx.period]; exact hper0 refine WP.spec_bind (Hj.endTimesliceTmoJR hAT hmax (htu a) hct hct3.symm hkt3 hrr hscC (hcs2.trans hpc.symm) hxs hky3 hya2 hper2 hth hp3 hres3 hnq3 hidt3) ?_ - rintro ⟨s4, a1⟩ ⟨z4, hz4, V4, Lst4, D4, J4⟩ - obtain ⟨s5, hs5, σ5, h5, Ac5, Lst5, D5, J5⟩ := J4.reschedJ + rintro ⟨s4, a1⟩ ⟨z4, hz4, V4, Lst4, D4, J4, F4⟩ + obtain ⟨s5, hs5, σ5, h5, Ac5, Lst5, D5, J5, F5⟩ := J4.reschedJ refine WP.spec_bind (show sched.reschedule_required st s4 ⦃ s' => s' = s5 ⦄ by rw [hs5]; exact (WP.spec_ok _).2 rfl) ?_ rintro _ rfl @@ -334,7 +338,8 @@ theorem JHole.chargeBudgetTmoJR {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s rintro s6 rfl rw [WP.spec_ok] beta_reduce - refine ⟨((), { σ5 with reprogramTimer := true }), ?_, V4, Ac5, Lst5, D5, J5.reprogramJ⟩ + refine ⟨((), { σ5 with reprogramTimer := true }), ?_, V4, Ac5, Lst5, D5, J5.reprogramJ, + J.natTrans (J.natTrans F4 F5.cast) J5.reprogramN.cast⟩ rw [chargeBudget_eq, nd_bind_one h2, chargeTail_eq true σ2 (hcc2.trans hs.curThread), if_pos hsch] refine mem_bind_nd (x := z4) hz4 (mem_bind_nd (x := ((), σ5)) (show ((), σ5) ∈ (Fl4Spec.rescheduleRequired (Z := Unit) z4.2).1 by rw [h5]; exact Set.mem_singleton _) ?_) @@ -365,7 +370,8 @@ theorem JHole.checkBudgetTR {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} (hkl : ∃ l, σ.kheap p = some (.endpoint (.recvEP l))) : sched.check_budget st arI s a ⦃ res => res.1 = false → ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ).1, z.1 = false ∧ ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.2.1 z.2 ⦄ := by have hS := Hh.xtop.fin.1.1.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC diff --git a/proofs/Fl4Proofs/P3/ScFireJ.lean b/proofs/Fl4Proofs/P3/ScFireJ.lean index 106d12853..58ac357af 100644 --- a/proofs/Fl4Proofs/P3/ScFireJ.lean +++ b/proofs/Fl4Proofs/P3/ScFireJ.lean @@ -34,6 +34,8 @@ is a one-line corollary via `JAtZ.toB` with its statement unchanged (the `JAtZB` P3/JAtZBFire (statements unchanged), the copies there deleted. Named premises here: `SignalJHyp` [J], `SignalJHypB` [J] (moved, unchanged), `SignalJHypE` [J] (the generic form of the two; asked only by `fire_loopE`, given by `SignalJHyp.toE` / `SignalJHypB.toE`). + +(mmuAD gen 42b71) `JAtZB.reprogramN` moved here from P3/ScChargeT (statement unchanged). -/ import Fl4Proofs.P3.XTopJointFin import Fl4Proofs.P3.BufFr @@ -578,6 +580,17 @@ theorem JAtZB.reprogramJ {s : S} {a : A} {σ : Fl4Spec.State Unit} rw [e] at J' exact J' +/-- (mmuAD gen 42b70) **The `REPROGRAM` write is a native step** (a word of the current core's node, `SFoot`; the +spec's heap kept): `JAtZB.reprogramJ`'s footprint (moved here from P3/ScChargeT in gen 42b71). -/ +theorem JAtZB.reprogramN {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) : + NatFoot (L := L) Z s σ (L.wr s (L.nodeAt s (L.cpu s) layout.node.REPROGRAM) 1#u64) + { σ with reprogramTimer := true } := by + obtain ⟨Q, R0, hc, -⟩ := J.xtop.fin.1.1.1.lists + rw [hc.cur] + exact NatFoot.ofT J.xtop (WritesIn.tfoot_of_kfoot (WritesIn.kfoot_of_sfoot + (sfoot_wr_node hc.node (o := layout.node.REPROGRAM) (by simp) (by simp) 1#u64))) + (fun _ h => J.tfoot_nh h) (NatK.of_kheap rfl) + /-- `JAtZB.reprogramJ` at `JAtZ` (via `JAtZ.toB`). -/ theorem JAtZ.reprogramJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) : @@ -628,22 +641,46 @@ def SignalJHypE (E : TypedHeap → S → Prop) (AR : A → Fl4Spec.Cr3 → Prop) Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ∧ E Z.th r.1 ⦄ +/-- (mmuAD gen 42b72) **One fired TCB timer over a spec signal `sig`**: `Fire` (P3/ScAwaken) is it at `sendSignal`, +the extended spec's `fl4TimerFireVF on rc` at `sendSignalVF on rc`. -/ +def FireG (sig : Fl4Spec.ObjRef → Fl4Spec.Badge → Fl4Spec.SMonad Unit Unit) (σ σ' : Fl4Spec.State Unit) : Prop := + ∃ σ1, (σ1 = σ ∨ ∃ n b, sig n b σ = ({((), σ1)}, False)) ∧ σ' = { σ1 with reprogramTimer := true } + +/-- (mmuAD gen 42b72) **The fire loop's invariant over a record `P` and a spec signal `sig`**: some fired timers +(`FireG sig`), the domain time kept, `P` after. -/ +def FireInvG (P : S → A → Fl4Spec.State Unit → Prop) (sig : Fl4Spec.ObjRef → Fl4Spec.Badge → Fl4Spec.SMonad Unit Unit) + (σ : Fl4Spec.State Unit) (s : S) (a : A) : Prop := + ∃ σ1 : Fl4Spec.State Unit, Relation.ReflTransGen (FireG sig) σ σ1 ∧ σ1.domainTime = σ.domainTime ∧ P s a σ1 + set_option maxHeartbeats 4000000 in -/-- **The TCB timers' loop keeps `FireInvE`** (module docstring; mmuAD gen 42b18: the original `fire_loopJ`'s proof -over `JAtZB`, the state fact `E` carried across each timer step by `hE` and across the signal by `hSig`). -/ -theorem fire_loopE {E : TypedHeap → S → Prop} - (hE : ∀ {Z' : XSets} {Cs' Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s1 : S} {a1 : A} - {σ1 : Fl4Spec.State Unit} {s2 : S}, JAtZB (L := L) arI AR Z' H Cs' Ac' Lst' D' s1 a1 σ1 → E Z'.th s1 → - P1.WritesIn st s1 s2 (TmW (L := L) Z'.T Cs' Z'.c s1) → E Z'.th s2) - (hSig : SignalJHypE (L := L) arI E AR H Cs) {σ : Fl4Spec.State Unit} (s : S) (a : A) (now i : U64) - (h : FireInvE (L := L) (arI := arI) E AR Z H Cs σ s a) : - timer.fire_loop st arI s a now i ⦃ r => FireInvE (L := L) (arI := arI) E AR Z H Cs σ r.1 r.2 ⦄ := by +/-- (mmuAD gen 42b72) **The TCB timers' loop over any record `P` and spec signal `sig`**: the proof of gen 42b18's +`fire_loopE` with `P` giving the `JAtZB` the loop reads (`hB`), kept by the timer-word writes (`hTm`, given the +`JAtZB` after them) and by the `REPROGRAM` write (`hRep`), and the signal given (`hSig`: from `P` at a notification of +`N`, against `sig`, deterministic, the domain time kept). `fire_loopE` is it at `sig := sendSignal`, +`P := JAtZB … ∧ E`. -/ +theorem fire_loopG {P : S → A → Fl4Spec.State Unit → Prop} + {sig : Fl4Spec.ObjRef → Fl4Spec.Badge → Fl4Spec.SMonad Unit Unit} + (hB : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit}, P s1 a1 σ1 → + ∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1) + (hTm : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} {s2 : S} {V1 : XVs} {Ac1 : Set U64} + {Lst1 : U64 → List U64} {D1 : Set U64}, P s1 a1 σ1 → + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s2 a1 σ1 → + P1.WritesIn st s1 s2 (TmW (L := L) Z.T Cs Z.c s1) → P s2 a1 σ1) + (hRep : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit}, P s1 a1 σ1 → + P (L.wr s1 (L.nodeAt s1 (L.cpu s1) layout.node.REPROGRAM) 1#u64) a1 { σ1 with reprogramTimer := true }) + (hSig : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} (n b : U64), P s1 a1 σ1 → n ∈ Z.N → + notification.send_signal st arI s1 a1 n b ⦃ r => ∃ σ' : Fl4Spec.State Unit, + sig n.bv b.bv σ1 = ({((), σ')}, False) ∧ σ'.domainTime = σ1.domainTime ∧ P r.1 r.2 σ' ⦄) + {σ : Fl4Spec.State Unit} (s : S) (a : A) (now i : U64) (h : FireInvG P sig σ s a) : + timer.fire_loop st arI s a now i ⦃ r => FireInvG P sig σ r.1 r.2 ⦄ := by unfold timer.fire_loop apply loop.spec_decr_nat (measure := fun x => 32 - x.2.2.val) - (inv := fun x => FireInvE (L := L) (arI := arI) E AR Z H Cs σ x.1 x.2.1) + (inv := fun x => FireInvG P sig σ x.1 x.2.1) · rintro ⟨s1, a1, i1⟩ h1 try simp only at h1 - obtain ⟨σ1, V1, Ac1, Lst1, D1, hF1, hd1, J1, hE1⟩ := id h1 + obtain ⟨σ1, hF1, hd1, hP1⟩ := id h1 + obtain ⟨V1, Ac1, Lst1, D1, J1⟩ := hB hP1 have hTe : Z.T = P1.Heap.tcbs H := J1.tcbs_eq.1 unfold timer.fire_loop.body dsimp only @@ -702,7 +739,6 @@ theorem fire_loopE {E : TypedHeap → S → Prop} · have : Z.c.val * 4288 + 4288 ≤ c'.val * 4288 := by nlinarith omega obtain ⟨r2, J2⟩ := J1.tmw_step hw2' (Or.inl hR2) h2 hTd2 - have hE2 : E Z.th s2 := hE (Z' := Z.mv Z.G V1) J1 hE1 hw2' have e2 : (σ1.reprogramTimer || r2) = σ1.reprogramTimer := by have g1 : (σ1.reprogramTimer || r2) = decide (Sched.nodeW st s2 Z.c layout.node.REPROGRAM ≠ 0#u64) := J2.xtop.fin.1.1.1.repr @@ -712,33 +748,56 @@ theorem fire_loopE {E : TypedHeap → S → Prop} rw [P1.nodeAt_of_ksb hw2.1, hR2] rw [e2] at J2 have J2' : JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s2 a1 σ1 := J2 + have hP2 : P s2 a1 σ1 := hTm hP1 J2' hw2' step with P1.obj.Tcb.bound_ntfn.val as ⟨n, en⟩ - refine WP.spec_bind (Pₘ := fun r : S × A => ∃ (σ2 : Fl4Spec.State Unit) (V2 : XVs) (Ac2 : Set U64) - (Lst2 : U64 → List U64) (D2 : Set U64), (σ2 = σ1 ∨ Signal σ1 σ2) ∧ σ2.domainTime = σ1.domainTime ∧ - JAtZB (L := L) arI AR (Z.mv Z.G V2) H Cs Ac2 Lst2 D2 r.1 r.2 σ2 ∧ E Z.th r.1) ?_ ?_ + refine WP.spec_bind (Pₘ := fun r : S × A => ∃ σ2 : Fl4Spec.State Unit, + (σ2 = σ1 ∨ ∃ n b, sig n b σ1 = ({((), σ2)}, False)) ∧ σ2.domainTime = σ1.domainTime ∧ P r.1 r.2 σ2) ?_ ?_ · split · rename_i hn0 have hn0' : L.mem s2 (P1.boundA t) ≠ 0#u64 := by rw [← en]; exact P1.bne_ne hn0 have hnH : n ∈ P1.Heap.ntfns H := by rw [en]; exact h2.2.2.1.2.2.bnd t htT hn0' have hnN : n ∈ Z.N := J2'.hset.2.1 n hnH - refine WP.spec_mono (hSig _ _ _ _ _ _ _ n bd J2' hE2 hnN) ?_ - rintro r ⟨σ2, V2, Ac2, Lst2, D2, hss, hd2, J3, hE3⟩ - exact ⟨σ2, V2, Ac2, Lst2, D2, Or.inr ⟨n.bv, bd.bv, hss⟩, hd2, J3, hE3⟩ - · exact (WP.spec_ok _).2 ⟨σ1, V1, Ac1, Lst1, D1, Or.inl rfl, rfl, J2', hE2⟩ - rintro ⟨s3, a3⟩ ⟨σ2, V2, Ac2, Lst2, D2, hsig, hd2, J3, hE3⟩ - try simp only at J3 + refine WP.spec_mono (hSig n bd hP2 hnN) ?_ + rintro r ⟨σ2, hss, hd2, hP3⟩ + exact ⟨σ2, Or.inr ⟨n.bv, bd.bv, hss⟩, hd2, hP3⟩ + · exact (WP.spec_ok _).2 ⟨σ1, Or.inl rfl, rfl, hP2⟩ + rintro ⟨s3, a3⟩ ⟨σ2, hsig, hd2, hP3⟩ + try simp only at hP3 try simp only [WP.uncurry'_pair] step with P1.LawfulStore.cur_cpu_spec as ⟨c3, ec3⟩ step with P1.obj.node_set.spec as ⟨s4, es4⟩ step as ⟨i4, ei4⟩ try simp only [WP.spec_ok] subst es4 ec3 - refine ⟨⟨{ σ2 with reprogramTimer := true }, V2, Ac2, Lst2, D2, + refine ⟨⟨{ σ2 with reprogramTimer := true }, Relation.ReflTransGen.tail hF1 ⟨σ2, hsig, rfl⟩, (hd2.trans hd1 : σ2.domainTime = σ.domainTime), - J3.reprogramJ, hE (Z' := Z.mv Z.G V2) J3 hE3 J3.reprogram_w⟩, by omega⟩ + hRep hP3⟩, by omega⟩ · exact (WP.spec_ok _).2 h1 · exact h + +set_option maxHeartbeats 4000000 in +/-- **The TCB timers' loop keeps `FireInvE`** (module docstring; mmuAD gen 42b18: the original `fire_loopJ`'s proof +over `JAtZB`, the state fact `E` carried across each timer step by `hE` and across the signal by `hSig`). (gen 42b72) +`fire_loopG` at `sig := sendSignal`, `P := JAtZB … ∧ E` (`fireInvE_iffG`), statement unchanged. -/ +theorem fire_loopE {E : TypedHeap → S → Prop} + (hE : ∀ {Z' : XSets} {Cs' Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s1 : S} {a1 : A} + {σ1 : Fl4Spec.State Unit} {s2 : S}, JAtZB (L := L) arI AR Z' H Cs' Ac' Lst' D' s1 a1 σ1 → E Z'.th s1 → + P1.WritesIn st s1 s2 (TmW (L := L) Z'.T Cs' Z'.c s1) → E Z'.th s2) + (hSig : SignalJHypE (L := L) arI E AR H Cs) {σ : Fl4Spec.State Unit} (s : S) (a : A) (now i : U64) + (h : FireInvE (L := L) (arI := arI) E AR Z H Cs σ s a) : + timer.fire_loop st arI s a now i ⦃ r => FireInvE (L := L) (arI := arI) E AR Z H Cs σ r.1 r.2 ⦄ := + WP.spec_mono (fire_loopG (sig := Fl4Spec.sendSignal) + (P := fun s1 a1 σ1 => ∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1 ∧ E Z.th s1) + (fun ⟨V1, Ac1, Lst1, D1, J1, _⟩ => ⟨V1, Ac1, Lst1, D1, J1⟩) + (fun ⟨_, _, _, _, J1, hE1⟩ J2 hw => ⟨_, _, _, _, J2, hE (Z' := Z.mv Z.G _) J1 hE1 hw⟩) + (fun ⟨V1, Ac1, Lst1, D1, J1, hE1⟩ => ⟨V1, Ac1, Lst1, D1, J1.reprogramJ, hE (Z' := Z.mv Z.G V1) J1 hE1 J1.reprogram_w⟩) + (fun n b ⟨_, _, _, _, J1, hE1⟩ hn => WP.spec_mono (hSig _ _ _ _ _ _ _ n b J1 hE1 hn) + fun _ ⟨σ', V', Ac', Lst', D', h1, h2, J', hE'⟩ => ⟨σ', h1, h2, V', Ac', Lst', D', J', hE'⟩) + s a now i (let ⟨σ1, V1, Ac1, Lst1, D1, h1, h2, J1, hE1⟩ := h; ⟨σ1, h1, h2, V1, Ac1, Lst1, D1, J1, hE1⟩)) + fun _ ⟨σ1, h1, h2, V1, Ac1, Lst1, D1, J1, hE1⟩ => ⟨σ1, V1, Ac1, Lst1, D1, h1, h2, J1, hE1⟩ + theorem fireInv_iff {σ : Fl4Spec.State Unit} {s : S} {a : A} : FireInv (L := L) (arI := arI) AR Z H Cs σ s a ↔ FireInvE (L := L) (arI := arI) (fun th s => JExt (L := L) th s) AR Z H Cs σ s a := diff --git a/proofs/Fl4Proofs/P3/ScNextDomC.lean b/proofs/Fl4Proofs/P3/ScNextDomC.lean index 83d6bac08..961eb0274 100644 --- a/proofs/Fl4Proofs/P3/ScNextDomC.lean +++ b/proofs/Fl4Proofs/P3/ScNextDomC.lean @@ -36,9 +36,10 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {T : Set U64} theorem awaken_refinesW0 {A : Type} {ar : machine.Arch A} {N C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW0 T C σ1 ∧ Pf r σ1 ⦄) : - sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, Fires σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ + sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, F σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ SchedRel st N T C c r.1 σ2 ∧ NtfnStateRel N T (L.mem r.1) σ2 ∧ NSC N C σ2 ∧ SchedPreW0 T C σ2 ∧ Calm σ1 σ2 ∧ (σ1.schedulerAction = .chooseNewThread → σ2.schedulerAction = .chooseNewThread) ∧ (σ1.schedulerAction ≠ .resumeCurThread → σ2.schedulerAction ≠ .resumeCurThread) ∧ @@ -408,14 +409,15 @@ theorem switch_branch_refines0 {N T C : Set U64} {c : U64} (s : S) (a : A) (σ0 theorem schedule_refinesWP0 {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hnd : Fl4Spec.numDomains = 1) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW0 T C σ1 ∧ ((σ1.domainTime ≠ 0 ∨ NdOK (L := L) r.1 σ1) ∧ (∀ n ∈ N, n.val + 40 ≤ (L.ksb r.1).val ∨ (L.ksb r.1).val + 13568 ≤ n.val) ∧ Pf r σ1) ⦄) (hA : ArchSw st ar N T C c) (hAN : ArchNd st N T C c) (hsni : SniHyp st ar N T C c) (hsend : SendHyp st ar N T C c) (hT : TimeAgree ar) : - sched.schedule st ar s a ⦃ r => ∃ σ1 σ', Fires σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + sched.schedule st ar s a ⦃ r => ∃ σ1 σ', F σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1 ∧ WritesIn st rf.1 r.1 (KFootN st T N C c rf.1 σ1) ∧ ∃ σ3 : Fl4Spec.State Unit, OffOK σ3 ∧ (RunM σ1 → RunW σ3) ∧ @@ -478,7 +480,7 @@ theorem schedule_refinesWP0 {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl let s8 ← obj.node_set st s7 c layout.node.REPROGRAM 0#u64 ok (s8, a5) else ok (s5, a3) - smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', Fires σ σ1' ∧ + smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', F σ σ1' ∧ Fl4Spec.schedule (Z := Unit) σ1' = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1' ∧ WritesIn st rf.1 r.1 (KFootN st T N C c rf.1 σ1') ∧ diff --git a/proofs/Fl4Proofs/P3/ScNextDomCFR.lean b/proofs/Fl4Proofs/P3/ScNextDomCFR.lean index ff275a48d..29d0943e4 100644 --- a/proofs/Fl4Proofs/P3/ScNextDomCFR.lean +++ b/proofs/Fl4Proofs/P3/ScNextDomCFR.lean @@ -34,9 +34,10 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {T : Set U64} theorem awaken_refinesW0R {A : Type} {ar : machine.Arch A} {N C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW0R T C σ1 ∧ Pf r σ1 ⦄) : - sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, Fires σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ + sched.awaken st ar s a ⦃ r => ∃ σ1 σ2, F σ σ1 ∧ Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ SchedRel st N T C c r.1 σ2 ∧ NtfnStateRel N T (L.mem r.1) σ2 ∧ NSC N C σ2 ∧ SchedPreW0R T C σ2 ∧ Calm σ1 σ2 ∧ (σ1.schedulerAction = .chooseNewThread → σ2.schedulerAction = .chooseNewThread) ∧ (σ1.schedulerAction ≠ .resumeCurThread → σ2.schedulerAction ≠ .resumeCurThread) ∧ diff --git a/proofs/Fl4Proofs/P3/ScScheduleTop.lean b/proofs/Fl4Proofs/P3/ScScheduleTop.lean index fccc9299f..02a91602f 100644 --- a/proofs/Fl4Proofs/P3/ScScheduleTop.lean +++ b/proofs/Fl4Proofs/P3/ScScheduleTop.lean @@ -888,11 +888,12 @@ hypothesis is stated at `σ` (`hfire`, keeping `SchedPreW`). -/ theorem schedule_refinesWP {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hnd : Fl4Spec.numDomains = 1) {Pf : S × A → Fl4Spec.State Unit → Prop} - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW T C σ1 ∧ Pf r σ1 ⦄) (hA : ArchSw st ar N T C c) (hsni : SniHyp st ar N T C c) (hsend : SendHyp st ar N T C c) (hT : TimeAgree ar) : - sched.schedule st ar s a ⦃ r => ∃ σ1 σ', Fires σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + sched.schedule st ar s a ⦃ r => ∃ σ1 σ', F σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1 ∧ WritesIn st rf.1 r.1 (KFoot st T N C c rf.1 σ1) ∧ ∃ σ3 : Fl4Spec.State Unit, OffOK σ3 ∧ (RunM σ1 → RunW σ3) ∧ @@ -949,7 +950,7 @@ theorem schedule_refinesWP {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4 let s8 ← obj.node_set st s7 c layout.node.REPROGRAM 0#u64 ok (s8, a5) else ok (s5, a3) - smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', Fires σ σ1' ∧ + smp.send_pending st ar s6 a4) ⦃ r => ∃ σ1' σ', F σ σ1' ∧ Fl4Spec.schedule (Z := Unit) σ1' = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ∧ ∃ rf : S × A, Pf rf σ1' ∧ WritesIn st rf.1 r.1 (KFoot st T N C c rf.1 σ1') ∧ @@ -1080,11 +1081,12 @@ theorem schedule_refinesWP {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4 theorem schedule_refinesW {N T C : Set U64} {c : U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (hS : SchedRel st N T C c s σ) (hR : NtfnStateRel N T (L.mem s) σ) (hN : NSC N C σ) (hnd : Fl4Spec.numDomains = 1) - (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, Fires σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} + (hfire : timer.fire st ar s a ⦃ r => ∃ σ1, F σ σ1 ∧ SchedRel st N T C c r.1 σ1 ∧ NtfnStateRel N T (L.mem r.1) σ1 ∧ NSC N C σ1 ∧ SchedPreW T C σ1 ⦄) (hA : ArchSw st ar N T C c) (hsni : SniHyp st ar N T C c) (hsend : SendHyp st ar N T C c) (hT : TimeAgree ar) : - sched.schedule st ar s a ⦃ r => ∃ σ1 σ', Fires σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + sched.schedule st ar s a ⦃ r => ∃ σ1 σ', F σ σ1 ∧ Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ SchedRel st N T C c r.1 σ' ∧ NtfnStateRel N T (L.mem r.1) σ' ∧ NSC N C σ' ∧ Inv σ' ∧ CurInv σ' ∧ ActIdle σ' ⦄ := WP.spec_mono (schedule_refinesWP (Pf := fun _ _ => True) s a σ hS hR hN hnd diff --git a/proofs/Fl4Proofs/P3/ScSignalDonJ.lean b/proofs/Fl4Proofs/P3/ScSignalDonJ.lean index 12332f212..985d43035 100644 --- a/proofs/Fl4Proofs/P3/ScSignalDonJ.lean +++ b/proofs/Fl4Proofs/P3/ScSignalDonJ.lean @@ -26,6 +26,11 @@ unchanged (the `JAtZB` copies of gens 24-39 deleted). (mmuAD gen 42b18) `wake_postD` stated over `JAtZB` in place (post at `Z`); `JAtZ.wake_postD` its corollary (witness `Z.vs`, `ext` by `JAtZ.ext_oobj` over `CnW`). P3/JAtZV3SigDon's copy deleted. + +(mmuAD gen 42b71, ruling (c2) item 1) `signal_waitDJ` / `signal_boundDJ` stated over `JAtZB` in place, the post at `Z` +with the native footprint `NatFoot` (the wake's `CnW` writes, `natK_dwfr`); the `JAtZ` names their corollaries +(`JAtZB.toJN`), statements unchanged. `zvk_dwfr` / `natK_dwfr` moved here from P3/XTopJointFaultRecv (statements +unchanged). -/ import Fl4Proofs.P3.ScSignalBoundJ import Fl4Proofs.P3.IpcSignalDon @@ -41,6 +46,54 @@ open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4 noncomputable section +/-! ## The wake frame as a native step (mmuAD gen 42b71: moved here) -/ + +section +variable {σ1 σ2 : Fl4Spec.State Unit} + +/-- **A wake frame keeps the VM epoch's spec side** (moved here from P3/JAtZV3FaultRecvB in mmuAD gen 42b67, then from P3/XTopJointFaultRecv in gen 42b71). -/ +theorem zvk_dwfr {r t : Fl4Spec.ObjRef} (F : DWFr r t σ1 σ2) : ZvK σ1 σ2 := by + refine ⟨fun p ao hp => ?_, fun o ko' ho => ?_, fun o x' ho hx => ?_, fun p vs hp => ?_⟩ + · rcases F.kh p with k | ⟨o1, o2, h1, -, hc⟩ + · exact k + · rw [hp] at h1 + cases h1 + rcases hc with ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, _, _, e, -⟩ | ⟨_, _, e, -⟩ | ⟨_, _, e, -⟩ | ⟨_, e, -⟩ <;> + cases e + · rcases F.kh o with k | ⟨o1, o2, h1, h2, hc⟩ + · exact ⟨ko', by rw [← k]; exact ho, rfl⟩ + · rw [ho] at h2 + cases h2 + rcases hc with ⟨_, _, _, _, _, _, rfl, rfl, -⟩ | ⟨_, _, _, _, _, rfl, rfl, -⟩ | ⟨_, _, rfl, rfl, -⟩ | + ⟨_, _, rfl, rfl, -⟩ | ⟨_, rfl, rfl, -⟩ <;> exact ⟨_, h1, rfl⟩ + · rcases F.kh o with k | ⟨o1, o2, h1, h2, hc⟩ + · exact ⟨x', by rw [← k]; exact ho, hx⟩ + · rw [ho] at h2 + cases h2 + rcases hc with ⟨x, st, bn, fl, ar, sc, rfl, e, htc⟩ | ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | + ⟨_, _, _, e, -⟩ | ⟨_, _, e, -⟩ + · cases e + exact ⟨x, h1, tcx_runVM htc hx⟩ + all_goals cases e + · rcases F.kh p with k | ⟨o1, o2, h1, h2, hc⟩ + · rw [← k]; exact hp + · rw [hp] at h2 + cases h2 + rcases hc with ⟨_, _, _, _, _, _, _, e, -⟩ | ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | + ⟨_, _, e, -⟩ <;> cases e + +/-- **A wake frame is a native step** (`zvk_dwfr`; no `DChg` change makes or changes an arch object; moved here from P3/XTopJointFaultRecv in mmuAD gen 42b71). -/ +theorem natK_dwfr {r t : Fl4Spec.ObjRef} (F : DWFr r t σ1 σ2) : NatK σ1 σ2 := + ⟨zvk_dwfr F, fun p ao hp => by + rcases F.kh p with k | ⟨o1, o2, h1, h2, hc⟩ + · rw [← k]; exact hp + · rw [hp] at h2 + cases h2 + rcases hc with ⟨_, _, _, _, _, _, _, e, -⟩ | ⟨_, _, _, _, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | ⟨_, _, _, e, -⟩ | + ⟨_, _, e, -⟩ <;> cases e⟩ + +end + section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} @@ -288,16 +341,17 @@ theorem JAtZ.not_dead_of_st (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t set_option maxHeartbeats 8000000 in /-- **A waiting notification signalled, donating or not, keeps `JAtZ`** -(module docstring). -/ -theorem JAtZ.signal_waitDJ (hAT : P0.ArchTotal arI) +(module docstring). (mmuAD gen 42b71) Over `JAtZB` in place, the post at `Z` with the native footprint `NatFoot` (the +wake's `CnW` writes, `natK_dwfr`); `JAtZ.signal_waitDJ` its corollary. -/ +theorem JAtZB.signal_waitDJ (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) {l : List Fl4Spec.ObjRef} (ho : x.ntfnObj = .waitingNtfn l) (badge : U64) : - notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := by have hI := J.xtop.irelK J.ks J.buf have hNt : ∀ m ∈ P1.Heap.ntfns H, H m = some .ntfn := fun _ h => h have hnH : n ∈ P1.Heap.ntfns H := J.zH.2.2.2 n hn @@ -351,21 +405,36 @@ theorem JAtZ.signal_waitDJ (hAT : P0.ArchTotal arI) rw [hkd] at hk'; cases hk' rcases hs' with e | ⟨ep, dd, e⟩ <;> rw [hxs] at e <;> cases e have htD := J.not_dead_of_st hdT hkd (by rw [hxs]; simp [tsCode]) - obtain ⟨V', J'⟩ := J.wake_postD hIR hF hw hb hfoot FF I' B' AI' cur' run' hRR htD ⟨d, hdT, rfl⟩ - exact ⟨σ', V', Ac, Lst, D, hsend, FF.sk.dt, J'⟩ + exact ⟨σ', Ac, Lst, D, hsend, FF.sk.dt, J.wake_postD hIR hF hw hb hfoot FF I' B' AI' cur' run' hRR htD ⟨d, hdT, rfl⟩, + NatFoot.ofW J.xtop hw (fun _ hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun _ hb => J.cnW_nv hb) + (fun _ hb => J.cnW_nh hb) (natK_dwfr FF)⟩ + +/-- `JAtZB.signal_waitDJ` at `JAtZ` (mmuAD gen 42b71; `JAtZB.toJN`, statement unchanged). -/ +theorem JAtZ.signal_waitDJ (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} + (hk : σ.kheap n.bv = some (.notification x)) {l : List Fl4Spec.ObjRef} (ho : x.ntfnObj = .waitingNtfn l) + (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := + WP.spec_mono (J.toB.signal_waitDJ hAT hmb hn hk ho badge) fun _ ⟨σ', Ac', Lst', D', h1, h2, B', F⟩ => + ⟨σ', Z.vs, Ac', Lst', D', h1, h2, B'.toJN J F⟩ set_option maxHeartbeats 8000000 in /-- **The idle notification's bound receiver woken, donating or not, keeps -`JAtZ`** (module docstring; `JAtZ.signal_boundJ` with `wake_specG`). -/ -theorem JAtZ.signal_boundDJ (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} +`JAtZ`** (module docstring; `JAtZ.signal_boundJ` with `wake_specG`). (mmuAD gen 42b71) Over `JAtZB` in place, as +`JAtZB.signal_waitDJ`; `JAtZ.signal_boundDJ` its corollary. -/ +theorem JAtZB.signal_boundDJ (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) {t : U64} {tcb : Fl4Spec.Tcb} (hb : x.ntfnBoundTcb = some t.bv) (hkt : σ.kheap t.bv = some (.tcb tcb)) (hrb : Fl4Spec.receiveBlocked tcb.tcbState = true) (badge : U64) : - notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := by have hI := J.xtop.irelK J.ks J.buf have hNt : ∀ m ∈ P1.Heap.ntfns H, H m = some .ntfn := fun _ h => h have hnH : n ∈ P1.Heap.ntfns H := J.zH.2.2.2 n hn @@ -433,10 +502,25 @@ theorem JAtZ.signal_boundDJ (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic. fun b h => h.elim id Or.inl have hRR : ∀ q ∈ Z.R, ∀ xr, σ.kheap q.bv = some (.reply xr) → xr.replyTcb = some t.bv → Detached Z.C Lst q ∧ L.mem s (rNextA q) = 0#u64 ∧ L.mem s (rPrevA q) = 0#u64 := - fun q hq xr hx' hxt => recvReplyHyp_holds Z Ac Lst D s _ σ J q hq xr t.bv tcb hx' hxt hkt hrb + fun q hq xr hx' hxt => J.recvReplyB q hq xr t.bv tcb hx' hxt hkt hrb have htD := J.not_dead_of_st htT hkt (by rw [hst]; simp [tsCode]) - obtain ⟨V', J'⟩ := J.wake_postD hIR (hF1.trans hF2) hw hbk hfoot FF I' B' AI' cur' run' hRR htD ⟨t, htT, rfl⟩ - exact ⟨σ', V', Ac, Lst, D, hsend, FF.sk.dt, J'⟩ + exact ⟨σ', Ac, Lst, D, hsend, FF.sk.dt, + J.wake_postD hIR (hF1.trans hF2) hw hbk hfoot FF I' B' AI' cur' run' hRR htD ⟨t, htT, rfl⟩, + NatFoot.ofW J.xtop hw (fun _ hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun _ hb => J.cnW_nv hb) + (fun _ hb => J.cnW_nh hb) (natK_dwfr FF)⟩ + +/-- `JAtZB.signal_boundDJ` at `JAtZ` (mmuAD gen 42b71; `JAtZB.toJN`, statement unchanged). -/ +theorem JAtZ.signal_boundDJ (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) {x : Fl4Spec.Notification} + (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) {t : U64} {tcb : Fl4Spec.Tcb} + (hb : x.ntfnBoundTcb = some t.bv) (hkt : σ.kheap t.bv = some (.tcb tcb)) + (hrb : Fl4Spec.receiveBlocked tcb.tcbState = true) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := + WP.spec_mono (J.toB.signal_boundDJ hAT hmb hn hk hidle hb hkt hrb badge) fun _ ⟨σ', Ac', Lst', D', h1, h2, B', F⟩ => + ⟨σ', Z.vs, Ac', Lst', D', h1, h2, B'.toJN J F⟩ end diff --git a/proofs/Fl4Proofs/P3/ScSignalJN.lean b/proofs/Fl4Proofs/P3/ScSignalJN.lean index ee93b2bc6..91362bd95 100644 --- a/proofs/Fl4Proofs/P3/ScSignalJN.lean +++ b/proofs/Fl4Proofs/P3/ScSignalJN.lean @@ -6,6 +6,12 @@ g3b in XTopJointMRPath; moved here unchanged by g3e (a pointwise copy, so ScSignalJ's cone is untouched) so that the older IRQ handlers (XTopJointIrq, XTopJointIrqZR, XTopJointIrqZI) and the KEntry13P / 23P notification leaf (`notifLeafJN`) can use it. + +(mmuAD gen 42b71, ruling (c2) item 1) **`JAtZB.signal_atNV`** / **`JAtZB.signal_atN`**: the same at one `JAtZB` state +(no `JExt`; the `RunningVM` bound-thread case excluded for the signalled notification only, resp. by `NativeScope`), the post at +`Z` with the native footprint `NatFoot` from the start (the badge-only writes `NWrite` ⊆ `FinW`, one notification +rewritten in place; the wakes by P3/ScSignalDonJ's `JAtZB.signal_waitDJ` / `signal_boundDJ`); `JAtZ.signal_atN` is its +corollary (`JAtZB.toJN`), statement unchanged. No premise added. -/ import Fl4Proofs.P3.ScSignalJ import Fl4Proofs.P3.IpcLeaves @@ -23,17 +29,41 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} +/-- (mmuAD gen 42b71) **One notification rewritten in place is a native spec step.** -/ +theorem natK_ntfnUpd {σ : Fl4Spec.State Unit} {n : Fl4Spec.ObjRef} {x y : Fl4Spec.Notification} + (hk : σ.kheap n = some (.notification x)) : NatK σ (updK σ n (.notification y)) := + natK_kh (R := fun _ o o' => ZvChg o o') (fun _ _ _ h => h) fun p => by + by_cases e : p = n + · subst e; exact Or.inr ⟨_, .notification y, hk, by simp [updK], zvChg_ntfn⟩ + · exact Or.inl (by simp [updK, e]) + +/-- (mmuAD gen 42b71) **A badge-only signal is a native step** (IpcNtfnSend's `SingleRelI`: FL4's writes in `NWrite` +⊆ `FinW`, the notification rewritten in place). -/ +theorem JAtZB.badgeN {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {n : U64} {x y : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) {s' : S} + (hrel : SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ ({((), updK σ n.bv (.notification y))}, False) s') : + NatFoot (L := L) Z s σ s' (updK σ n.bv (.notification y)) := by + obtain ⟨-, -, -, -, hW, -⟩ := hrel + exact NatFoot.ofW J.xtop (hW.mono fun b hb => NWrite.finW J.xtop.fin.1.1.1.placed.tcb hb) + (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb) + (fun _ hb => J.finW_nh hb) (natK_ntfnUpd hk) + set_option maxHeartbeats 8000000 in /-- **ScSignalJ's `signalJHyp_of` at one `JAtZ` state with `NativeScope`** (g3b): -the `RunningVM` bound-thread case is absurd there, so no `SignalRestJHyp`. -/ -theorem JAtZ.signal_atN (hAT : P0.ArchTotal arI) +the `RunningVM` bound-thread case is absurd there, so no `SignalRestJHyp`. (mmuAD gen 42b71) Over `JAtZB` in place, the +post at `Z` with the native footprint `NatFoot` (module docstring), the `RunningVM` case excluded for this notification +only (`hVM`); `JAtZB.signal_atN` (`NativeScope`) and `JAtZ.signal_atN` its corollaries. -/ +theorem JAtZB.signal_atNV (hAT : P0.ArchTotal arI) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {s : S} {a : A} - {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) - (n badge : U64) (hn : n ∈ Z.N) : - notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (n badge : U64) (hn : n ∈ Z.N) + (hVM : ∀ (x : Fl4Spec.Notification) (t : Fl4Spec.ObjRef) (tcb : Fl4Spec.Tcb), + σ.kheap n.bv = some (.notification x) → x.ntfnObj = .idleNtfn → x.ntfnBoundTcb = some t → + σ.kheap t = some (.tcb tcb) → tcb.tcbState ≠ .runningVM) : + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := by obtain ⟨x, hk, hx⟩ := J.xtop.ipc.toN.ntfn n hn have hNt : ∀ m ∈ P1.Heap.ntfns H, H m = some .ntfn := fun _ h => h have hnH : n ∈ P1.Heap.ntfns H := J.zH.2.2.2 n hn @@ -44,17 +74,21 @@ theorem JAtZ.signal_atN (hAT : P0.ArchTotal arI) Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), updK σ n.bv (.notification y))}, False) → notification.send_signal st arI s a n badge ⦃ r => r.2 = a ∧ SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ (Fl4Spec.sendSignal n.bv badge.bv σ) r.1 ⦄ → - notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ - JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := by intro y hxw hyw hyb hys hspec hI refine WP.spec_mono (WP.spec_and hI hP1) ?_ rintro ⟨s', a'⟩ ⟨⟨ea, hrel⟩, hb⟩ try simp only [WP.uncurry'_pair] at hb subst ea - obtain ⟨σ', V', h1, h2, J'⟩ := J.signal_badge_post hn hk hxw hyw hyb hys hspec hrel hb - exact ⟨σ', V', Ac, Lst, D, h1, h2, J'⟩ + obtain ⟨σ', h1, h2, J'⟩ := J.signal_badge_post hn hk hxw hyw hyb hys hspec hrel hb + have e : σ' = updK σ n.bv (.notification y) := by + have h3 := (Prod.mk.inj (h1.symm.trans hspec)).1 + exact congrArg Prod.snd (Set.singleton_injective h3) + subst e + exact ⟨_, Ac, Lst, D, hspec, h2, J', J.badgeN hk (hspec ▸ hrel)⟩ have hI := J.xtop.irelK J.ks J.buf cases ho : x.ntfnObj with | activeNtfn b0 => @@ -79,13 +113,36 @@ theorem JAtZ.signal_atN (hAT : P0.ArchTotal arI) (by rw [hbt]; exact hkt) hrb badge by_cases hvm : tcb.tcbState = .runningVM - · exact absurd hvm (hN t tcb hkt) + · exact absurd hvm (hVM x t tcb hk ho hb hkt) have hrb' : Fl4Spec.receiveBlocked tcb.tcbState = false := by simpa using hrb exact post (Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn badge.bv) x) (by rw [ho]; intro l e; cases e) (fun l e => by simp [Fl4Spec.ntfnObjUpdate] at e) rfl rfl (sendSignal_activate hk ho (Or.inr ⟨t, tcb, hb, hkt, hrb'⟩) badge.bv) (send_signal_idle_bound_idleI (ar := arI) J.ip s a σ hI.1 hn hk ho hb hkt hrb' hvm badge) +/-- (mmuAD gen 42b71) `JAtZB.signal_atNV` in the native scope. -/ +theorem JAtZB.signal_atN (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {s : S} {a : A} + {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) + (n badge : U64) (hn : n ∈ Z.N) : + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) + (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := + J.signal_atNV hAT hmb n badge hn fun _ t tcb _ _ _ hkt => hN t tcb hkt + +/-- `JAtZB.signal_atN` at `JAtZ` (mmuAD gen 42b71; `JAtZB.toJN`, statement unchanged). -/ +theorem JAtZ.signal_atN (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {s : S} {a : A} + {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) + (n badge : U64) (hn : n ∈ Z.N) : + notification.send_signal st arI s a n badge ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (V' : XVs) (Ac' : Set U64) + (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ = ({((), σ')}, False) ∧ σ'.domainTime = σ.domainTime ∧ + JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := + WP.spec_mono (J.toB.signal_atN hAT hmb hN n badge hn) fun _ ⟨σ', Ac', Lst', D', h1, h2, B', F⟩ => + ⟨σ', Z.vs, Ac', Lst', D', h1, h2, B'.toJN J F⟩ + end end diff --git a/proofs/Fl4Proofs/P3/ScTmoCtBase.lean b/proofs/Fl4Proofs/P3/ScTmoCtBase.lean index 2ee29fb94..f4fa76f0c 100644 --- a/proofs/Fl4Proofs/P3/ScTmoCtBase.lean +++ b/proofs/Fl4Proofs/P3/ScTmoCtBase.lean @@ -19,6 +19,10 @@ The real send (`ScTmoCtRecv`) reads its frame from this base on the shadows `rhoT` (the thread's TCB and SC as here); the action differs from the shadow's only before the thread's own `set_thread_state`, and the frames (`CFr`, `IK`, `SKeep`) do not read the action. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) `JTH.tmoBaseCtJ` over `JAtZB` (`JTH.j0 : JAtZB`): the base is +`JAtZB` with `NatFoot` from the hole's base (the `CnW` writes; the spec frame `ScOnly`, `BFrT`, `KFr`, `ScOnly`, each a +native step: `ScOnly.natK`, `natK_bfrt`, the new **`natK_kfr`**). -/ import Fl4Proofs.P3.ScChargeTA import Fl4Proofs.P3.XTopJointFaultTmo @@ -58,6 +62,18 @@ open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proof noncomputable section +/-- (mmuAD gen 42b70) **A cancel frame `KFr` is a native step** (P3/NatFoot's `natK_kh`: the thread's TCB keeps its +state or becomes `Inactive`, endpoints and notifications change in place). -/ +theorem natK_kfr {t : Fl4Spec.ObjRef} {σ σ' : Fl4Spec.State Unit} (h : KFr t σ σ') : NatK σ σ' := + natK_kh (R := KChg t) (fun _ o o' hc => by + rcases hc with ⟨x, st, fl, rfl, rfl, -, -, hs⟩ | ⟨x, y, rfl, rfl, -⟩ | ⟨x, ob, rfl, rfl, -⟩ + · refine zvChg_tcb fun hy => ?_ + rcases hs with rfl | rfl + · cases hy + · exact hy + · exact zvChg_ep + · exact zvChg_ntfn) h.kh + /-- **The spec's base state** (module docstring): the thread `t` given the timeout fault and made `Inactive` (`set_thread_state`'s action step), then its SC's consumed time cleared. -/ @@ -89,7 +105,8 @@ theorem JTH.tmoBaseCtJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : ∃ sB : S, P1.WritesIn st s sB (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) ∧ P1.WritesIn st s sB (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s b ∨ False) ∧ - ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D sB a (tmoCtSt σ t sc x y n b) := by + ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D sB a (tmoCtSt σ t sc x y n b) ∧ + NatFoot (L := L) Z s0 σ0 sB (tmoCtSt σ t sc x y n b) := by have J := Hj.j0 have hO := Hj.ksc have hP0 := J.ip @@ -453,11 +470,13 @@ theorem JTH.tmoBaseCtJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : F3q.own (KFr.own F2 (F1.own Hj.own)), hoff, hAI3, F3q.bsa (KFr.bsa F2 (F1.bsa Hj.bsa hscA)), F3q.isorted hsrtT, hrun3, hblkB⟩ - have hC0 := JCs.same J hF.1 hkszc + have hC0 := JCs.sameB J hF.1 hkszc have hCs : JCs (L := L) (Z.mv Z.G V') sB σB := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ exact ⟨Z.vs, J.cs_frameI hks hX3 hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) e_arch haoc hszc hF.1 hkbc hfkc hCs R hKd e_orig - (XTopAt.idleW_eqS J.xtop hX3 e_idle) J.zD⟩ + (XTopAt.idleW_eqS J.xtop hX3 e_idle) J.zD, + NatFoot.ofW J.xtop hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) + (fun b hb => J.cnW_nh hb) (((hO.natK.trans (natK_bfrt F1)).trans (natK_kfr F2)).trans F3.natK)⟩ end diff --git a/proofs/Fl4Proofs/P3/ScTmoCtRecv.lean b/proofs/Fl4Proofs/P3/ScTmoCtRecv.lean index 4ece57f3c..2844cd01d 100644 --- a/proofs/Fl4Proofs/P3/ScTmoCtRecv.lean +++ b/proofs/Fl4Proofs/P3/ScTmoCtRecv.lean @@ -7,6 +7,10 @@ base), then the virtual base (ScTmoCtBase `JTH.tmoBaseCtJ`) and the send to the queue head: `JAtZ.sendTmoRecvCtIJ` (the sender left `Inactive`) or `JAtZ.sendTmoRecvCtPJ` (the reply pushed), as XTopJointFaultTmo's `JAtZ.runTmoRecvJ`. Platform facts `hmax`/`htu` [P] as there. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) Over `JAtZB` with `NatFoot` from the hole's base (`JTH.j0 : +JAtZB`): the virtual base's `NatFoot` (ScTmoCtBase) composed with the send's (ScTmoCtRecvI/P's +`JAtZB.sendTmoRecvCtIJ` / `PJ`, from the virtual base). -/ import Fl4Proofs.P3.ScTmoCtRecvP open Aeneas Aeneas.Std Result @@ -66,7 +70,7 @@ theorem JTH.tmoRecvJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A faults.handle_timeout st arI s a t (error.Fault.Timeout b) ⦃ res => ∃ z ∈ (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, ∃ (V : XVs) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' res.1 res.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' res.1 res.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 res.1 z.2 ⦄ := by have J := Hj.j0 have hO := Hj.ksc have hP0 := J.ip @@ -148,7 +152,7 @@ theorem JTH.tmoRecvJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A obtain rfl : gr = gr' := hgr.symm refine WP.spec_bind (Pₘ := fun r : Bool × S × A => ∃ z ∈ (Fl4Spec.handleTimeout (Z := Unit) t.bv (.timeout b.bv) σ).1, ∃ (V : XVs) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' r.2.1 r.2.2 z.2) ?_ ?_ + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D' r.2.1 r.2.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 r.2.1 z.2) ?_ ?_ swap · rintro ⟨b0, s2, a2⟩ hr0 exact (WP.spec_ok _).2 hr0 @@ -221,7 +225,7 @@ theorem JTH.tmoRecvJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A exact Or.inl (Or.inr ⟨t, ht, K, k1, k2, k3, k4, k5, k6⟩) have hW7 : P1.WritesIn st s s7 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hC2.1 have hst : sc.bv ≠ t.bv := fun e => by rw [e, hk] at hky; cases hky - obtain ⟨sB, hwB, hfB, V0, J0⟩ := Hj.tmoBaseCtJ hAT hmax htu ht htc hk hrr hsc hxsc hscc hky hya hres hnq hidt b + obtain ⟨sB, hwB, hfB, V0, J0, F0⟩ := Hj.tmoBaseCtJ hAT hmax htu ht htc hk hrr hsc hxsc hscc hky hya hres hnq hidt b have hrun : Fl4Spec.runnable x.tcbState = true := by rcases hrr with e | e <;> rw [e] <;> rfl have hI7' : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s7 (updK σ t.bv (.tcb { x with tcbState := x.tcbState, tcbFault := some (.timeout b.bv) })) := by @@ -245,8 +249,8 @@ theorem JTH.tmoRecvJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A · refine WP.spec_bind (J0.sendTmoRecvCtPJ hAT hmax htu ht hk htc hres hnq hidt hsc hxsc hky b (fun q h1 h2 => tmoCtSt_kh h1 h2) (tmoCtSt_kt hst) tmoCtSt_ksc tmoCtSt_sk tmoCtSt_rq hwB hfB (ts := x.tcbState) hrun hI7' hblk7 hW7 hfoot7 hcb7 hpE hke bdg g gr hpush.1 hD hya hpush.2) ?_ - rintro ⟨s', a'⟩ ⟨z, hz, V, Lst', hJ⟩ - exact (WP.spec_ok _).2 ⟨((), z.2), handleTimeout_mem hk hth _ (fin z hz), V, Lst', D, hJ⟩ + rintro ⟨s', a'⟩ ⟨z, hz, V, Lst', hJ, hF⟩ + exact (WP.spec_ok _).2 ⟨((), z.2), handleTimeout_mem hk hth _ (fin z hz), V, Lst', D, hJ, J.natTrans F0 hF.cast⟩ · have hno : (g = false ∧ gr = false) ∨ ∀ xd, σ.kheap d'.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none := by by_cases hgg : g = true ∨ gr = true @@ -264,8 +268,8 @@ theorem JTH.tmoRecvJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A refine WP.spec_bind (J0.sendTmoRecvCtIJ hmax htu ht hk htc hres hsc hxsc hky b (fun q h1 h2 => tmoCtSt_kh h1 h2) (tmoCtSt_kt hst) tmoCtSt_ksc tmoCtSt_sk tmoCtSt_rq hwB hfB (ts := x.tcbState) hrun hI7' hblk7 hW7 hfoot7 hcb7 hpE hke bdg g gr hno) ?_ - rintro ⟨s', a'⟩ ⟨z, hz, V, Lst', hJ⟩ - exact (WP.spec_ok _).2 ⟨((), z.2), handleTimeout_mem hk hth _ (fin z hz), V, Lst', D, hJ⟩ + rintro ⟨s', a'⟩ ⟨z, hz, V, Lst', hJ, hF⟩ + exact (WP.spec_ok _).2 ⟨((), z.2), handleTimeout_mem hk hth _ (fin z hz), V, Lst', D, hJ, J.natTrans F0 hF.cast⟩ all_goals simp [absCap] at habs6 end diff --git a/proofs/Fl4Proofs/P3/ScTmoCtRecvI.lean b/proofs/Fl4Proofs/P3/ScTmoCtRecvI.lean index 01079b316..e604bf906 100644 --- a/proofs/Fl4Proofs/P3/ScTmoCtRecvI.lean +++ b/proofs/Fl4Proofs/P3/ScTmoCtRecvI.lean @@ -16,6 +16,10 @@ state inside `charge_budget` (no `JAtZ` there). read on the shadow up to the action: the sender's `set_thread_state` leaves `ChooseNewThread` (`stsAct_cur`), which gives `ActIdle`, `CurRunM` and the `cur` disjunct directly. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) Stated over `JAtZB` in place (`JAtZB.sendTmoRecvCtIJ`, the base +`J0 : JAtZB`), post `JAtZB` plus `NatFoot` from the base: the wake's `CnW` writes by `NatFoot.ofW`, the spec frame +`DWFr` (`natK_dwfr`), the tail's by `JAtZB.sendTailJ`; `JAtZ.sendTmoRecvCtIJ` its corollary (`JAtZB.toJN`), statement unchanged. -/ import Fl4Proofs.P3.ScTmoCtBase open Aeneas Aeneas.Std Result @@ -80,8 +84,8 @@ thread `Inactive` with the fault, its SC's consumed time cleared, related to the pre-state `σ` by `hk0`/`hk0t`/`hk0s`/`hsk0`); the sender's own `set_thread_state` sets `ChooseNewThread` (`stsAct`), so the end is read on the shadow up to the action (`cfr_congrK`). -/ -theorem JAtZ.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} - (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) +theorem JAtZB.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) @@ -113,7 +117,8 @@ theorem JAtZ.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} endpoint.send_ipc st arI s7 a true false badge g gr false t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false badge.bv g gr false t.bv e.bv (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))).1, - ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ⦄ := by + ∃ (V : XVs) (Lst' : U64 → List U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 r.1 z.2 ⦄ := by set xt : Fl4Spec.Tcb := { x with tcbState := ts, tcbFault := some (.timeout b.bv) } with hxt set σf := updK σ t.bv (.tcb xt) with hσf set xT : Fl4Spec.Tcb := { x with tcbState := .inactive, tcbFault := some (.timeout b.bv) } with hxT @@ -662,9 +667,8 @@ theorem JAtZ.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} have htD := J0.not_dead_of_st hdT hkd0 (by rw [hstd]; simp [tsCode]) have hRR : ∀ q' ∈ Z.R, ∀ xr, σ0.kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem s0 (rNextA q') = 0#u64 ∧ L.mem s0 (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds _ Ac Lst D s0 _ σ0 J0 q' hq'' xr d'.bv xd hx' - hxt' hkd0 (by rw [hstd]; rfl) - obtain ⟨V', J5⟩ := J0.wake_postD (by rw [hsk0.arch]; exact hIR) hF hW05 hblk hfoot05 (DWFr.ofCFr Fr5) I5 (Fr5.bsa J0.bsa) hAI5 + fun q' hq'' xr hx' hxt' => J0.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd0 (by rw [hstd]; rfl) + have J5 := J0.wake_postD (by rw [hsk0.arch]; exact hIR) hF hW05 hblk hfoot05 (DWFr.ofCFr Fr5) I5 (Fr5.bsa J0.bsa) hAI5 hcur5 hrun5 hRR htD ⟨d', hdT, rfl⟩ -- the tail have hk5 : σ5.kheap d'.bv = some (.tcb x5) := by rw [hσ5, stsAct_kheap]; simp @@ -691,14 +695,54 @@ theorem JAtZ.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} have hspec := sendIpc_faultInactive_eq (don := false) hk hkd hde htd' hstd true badge.bv g gr hcond e2 hU hkt3 hkd3 (by rw [hft]; simp) (t := t.bv) refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7', a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ + rintro ⟨s7', a7⟩ ⟨ha7, σ7, h7, Lst7, J7, F7⟩ simp only at ha7 subst ha7 - refine ⟨((), σ7), ?_, V', Lst7, J7⟩ + have F05 : NatFoot (L := L) Z s0 σ0 s5 _ := NatFoot.ofW J0.xtop hW05 (fun b0 hb0 => CnW.oobj J0.xtop.fin.1.1.1 hb0) + (fun b0 hb0 => J0.cnW_nv hb0) (fun b0 hb0 => J0.cnW_nh hb0) (natK_dwfr (DWFr.ofCFr Fr5)) + refine ⟨((), σ7), ?_, Z.vs, Lst7, J7, J0.natTrans F05 F7⟩ rw [hspec] show ((), σ7) ∈ (Endp.specWakeTailE d'.bv σ5).1 rw [h7]; exact Set.mem_singleton _ + +/-- `JAtZB.sendTmoRecvCtIJ` at `JAtZ` (mmuAD gen 42b70: `JAtZB.toJN` from the base). -/ +theorem JAtZ.sendTmoRecvCtIJ {s0 : S} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (htc : t.bv = σ.curThread) + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) + {sc : U64} (hsc : sc ∈ Z.C) (hxsc : x.tcbSchedContext = some sc.bv) + {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) + (b : U64) + (hk0 : ∀ q, q ≠ t.bv → q ≠ sc.bv → σ0.kheap q = σ.kheap q) + (hk0t : σ0.kheap t.bv = some (.tcb { x with tcbState := .inactive, tcbFault := some (.timeout b.bv) })) + (hk0s : σ0.kheap sc.bv = some (.schedContext { y with scConsumed := (0#u64 : U64).bv } n)) + (hsk0 : Sk σ σ0) (hrq0 : σ0.readyQueues = σ.readyQueues) + (hwB : P1.WritesIn st s s0 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ)) + (hfB : P1.WritesIn st s s0 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) s b ∨ False)) + {ts : Fl4Spec.ThreadState} (hrun : Fl4Spec.runnable ts = true) {s7 : S} + (hI7 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s7 + (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))) + (hblk7 : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) + (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s7) + (hW7 : P1.WritesIn st s s7 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ)) + (hfoot7 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s7) + (hcb7 : P1.CanBlock st (P1.Heap.tcbs H) Ac s7 t) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hke : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (badge : U64) (g gr : Bool) + (hno : (g = false ∧ gr = false) ∨ + ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none) : + endpoint.send_ipc st arI s7 a true false badge g gr false t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false badge.bv g gr false t.bv e.bv + (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))).1, + ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ⦄ := + WP.spec_mono (J0.toB.sendTmoRecvCtIJ hmax htu ht hk htc hres hsc hxsc hky b hk0 hk0t hk0s hsk0 hrq0 hwB hfB hrun hI7 hblk7 hW7 hfoot7 hcb7 he hke badge g gr hno) fun _ ⟨z, hz, V, Lst', B, F⟩ => ⟨z, hz, V, Lst', B.toJN J0 F⟩ + end end diff --git a/proofs/Fl4Proofs/P3/ScTmoCtRecvP.lean b/proofs/Fl4Proofs/P3/ScTmoCtRecvP.lean index 0519ec564..680d6d07a 100644 --- a/proofs/Fl4Proofs/P3/ScTmoCtRecvP.lean +++ b/proofs/Fl4Proofs/P3/ScTmoCtRecvP.lean @@ -8,6 +8,10 @@ current thread by `t ≠ d`, the action resume or choose, the sender's queue bits from `NotQueued` at the hole, and after the push (`pushSt`, whose `set_thread_state` blocks the current thread on the reply) the action `ChooseNewThread` (`stsAct_cur`). + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) Stated over `JAtZB` in place (`JAtZB.sendTmoRecvCtPJ`, the base +`J0 : JAtZB`), post `JAtZB` plus `NatFoot` from the base: the wake's `CnW` writes by `NatFoot.ofW`, the spec frame +`DWFr` then the reply push (`natK_dwfr`, `natK_pushSt`), the tail's by `JAtZB.sendTailJ`; `JAtZ.sendTmoRecvCtPJ` its corollary (`JAtZB.toJN`), statement unchanged. -/ import Fl4Proofs.P3.ScTmoCtRecvI open Aeneas Aeneas.Std Result @@ -32,8 +36,8 @@ thread `Inactive` with the fault, its SC's consumed time cleared, related to the pre-state `σ` by `hk0`/`hk0t`/`hk0s`/`hsk0`); the sender's own `reply_push` (its `set_thread_state`) sets `ChooseNewThread` (`stsAct`): `ActIdle`, `CurRunM` and `cur` after from that. -/ -theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchTotal arI) - (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) +theorem JAtZB.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchTotal arI) + (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) @@ -66,7 +70,8 @@ theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchT endpoint.send_ipc st arI s7 a true false badge g gr false t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false badge.bv g gr false t.bv e.bv (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))).1, - ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ⦄ := by + ∃ (V : XVs) (Lst' : U64 → List U64), JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 r.1 z.2 ⦄ := by set xt : Fl4Spec.Tcb := { x with tcbState := ts, tcbFault := some (.timeout b.bv) } with hxt set σf := updK σ t.bv (.tcb xt) with hσf set xT : Fl4Spec.Tcb := { x with tcbState := .inactive, tcbFault := some (.timeout b.bv) } with hxT @@ -690,8 +695,7 @@ theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchT have htDd := J0.not_dead_of_st hdT hkd0 (by rw [hstd]; simp [tsCode]) have hRR : ∀ q' ∈ Z.R, ∀ xr, σ0.kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem s0 (rNextA q') = 0#u64 ∧ L.mem s0 (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds _ Ac Lst D s0 _ σ0 J0 q' hq'' xr d'.bv xd hx' - hxt' hkd0 (by rw [hstd]; rfl) + fun q' hq'' xr hx' hxt' => J0.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd0 (by rw [hstd]; rfl) have hcD : ∀ q0 ∈ D, q0.bv ≠ t.bv := fun q0 hq0 e0 => htD (by rw [← P1.eq_of_bv e0]; exact hq0) have hwD : ∀ q0 ∈ D, q0.bv ≠ w.bv := fun q0 hq0 e0 => by have hqw : q0 = w := P1.eq_of_bv e0 @@ -704,7 +708,7 @@ theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchT have hkq : ∀ q0 ∈ D, σ'.kheap q0.bv = σb.kheap q0.bv := fun q0 hq0 => ps_ko (hcD q0 hq0) (hwD q0 hq0) have ho : ∀ {q : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject}, (∀ x, o ≠ .tcb x) → (∀ x, o ≠ .reply x) → (σ'.kheap q = some o ↔ σb.kheap q = some o) := fun h1 h2 => ps_oth hkta hkwa hwt h1 h2 - obtain ⟨V', J5⟩ := J0.wake_postGR (by rw [hsk0.arch]; exact hIR) hF hW05 hblk hfoot05 (DWFr.ofCFr Fr5) ps_skD + have J5 := J0.wake_postGR (by rw [hsk0.arch]; exact hIR) hF hW05 hblk hfoot05 (DWFr.ofCFr Fr5) ps_skD (ps_ksub hkta hkwa hwt) (ps_szKeep hkta hkwa hwt) (ps_ykeep hkta hkwa hwt) (ps_mcpKeep hkta hkwa hwt) (ps_bufKeep hkta hkwa hwt) (fun d _ h => ps_recvB hkta hkwa hwt h) (ps_ksz hkta hkwa hwt) (ps_kback hkta hkwa hwt) (ps_ipcFr hkta hkwa hwt) (ps_ck hkta hkwa hwt) (fun d _ h => ps_free hkta hkwa hwt h) @@ -734,15 +738,53 @@ theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchT have hspec := sendIpc_faultPush_eq (don := false) hk hkd hde hstd true badge.bv g gr hg e2 hU hkt3 hkd3 hpush hkd4 (by rw [hft]; simp) (t := t.bv) refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7', a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ + rintro ⟨s7', a7⟩ ⟨ha7, σ7, h7, Lst7, J7, F7⟩ simp only at ha7 subst ha7 - refine ⟨((), σ7), ?_, V', Lst7, J7⟩ + have F05 : NatFoot (L := L) Z s0 σ0 s5 _ := NatFoot.ofW J0.xtop hW05 (fun b0 hb0 => CnW.oobj J0.xtop.fin.1.1.1 hb0) + (fun b0 hb0 => J0.cnW_nv hb0) (fun b0 hb0 => J0.cnW_nh hb0) ((natK_dwfr (DWFr.ofCFr Fr5)).trans (natK_pushSt hkwa hkta hwt.symm)) + refine ⟨((), σ7), ?_, Z.vs, Lst7, J7, J0.natTrans F05 F7⟩ rw [hspec, heq5, hpb] show ((), σ7) ∈ (Endp.specWakeTailE d'.bv σ').1 rw [h7]; exact Set.mem_singleton _ - +/-- `JAtZB.sendTmoRecvCtPJ` at `JAtZ` (mmuAD gen 42b70: `JAtZB.toJN` from the base). -/ +theorem JAtZ.sendTmoRecvCtPJ {s0 : S} {σ0 : Fl4Spec.State Unit} (hAT : P0.ArchTotal arI) + (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a σ0) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + (htc : t.bv = σ.curThread) + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) + (hnq : NotQueued σ t.bv) (hidt : σ.idleThread ≠ t.bv) + {sc : U64} (hsc : sc ∈ Z.C) (hxsc : x.tcbSchedContext = some sc.bv) + {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap sc.bv = some (.schedContext y n)) + (b : U64) + (hk0 : ∀ q, q ≠ t.bv → q ≠ sc.bv → σ0.kheap q = σ.kheap q) + (hk0t : σ0.kheap t.bv = some (.tcb { x with tcbState := .inactive, tcbFault := some (.timeout b.bv) })) + (hk0s : σ0.kheap sc.bv = some (.schedContext { y with scConsumed := (0#u64 : U64).bv } n)) + (hsk0 : Sk σ σ0) (hrq0 : σ0.readyQueues = σ.readyQueues) + (hwB : P1.WritesIn st s s0 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ)) + (hfB : P1.WritesIn st s s0 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) s b ∨ False)) + {ts : Fl4Spec.ThreadState} (hrun : Fl4Spec.runnable ts = true) {s7 : S} + (hI7 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s7 + (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))) + (hblk7 : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) + (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s7) + (hW7 : P1.WritesIn st s s7 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ)) + (hfoot7 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s7) + (hcb7 : P1.CanBlock st (P1.Heap.tcbs H) Ac s7 t) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hke : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (badge : U64) (g gr : Bool) + (hg : g = true ∨ gr = true) (htD : t ∉ D) (hya : Fl4Spec.scActive y = true) + (hrepn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none) : + endpoint.send_ipc st arI s7 a true false badge g gr false t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false badge.bv g gr false t.bv e.bv + (updK σ t.bv (.tcb { x with tcbState := ts, tcbFault := some (.timeout b.bv) }))).1, + ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 r.2 z.2 ⦄ := + WP.spec_mono (J0.toB.sendTmoRecvCtPJ hAT hmax htu ht hk htc hres hnq hidt hsc hxsc hky b hk0 hk0t hk0s hsk0 hrq0 hwB hfB hrun hI7 hblk7 hW7 hfoot7 hcb7 he hke badge g gr hg htD hya hrepn) fun _ ⟨z, hz, V, Lst', B, F⟩ => ⟨z, hz, V, Lst', B.toJN J0 F⟩ end diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO1.lean b/proofs/Fl4Proofs/P3/SpecInvAllO1.lean index aa62c58c9..7d2eb3cda 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO1.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO1.lean @@ -18,6 +18,16 @@ premise `OnlyIdle`. `fl4KernelEntrySyscall`, bottom-up (`oi_auto`), generated from the spec's call graph by invA's gen.py (scratch/g1c, untracked: `sh mkoi.sh`); the recursive ones by invA's manual.py texts. Parts 2-6: SpecInvAllO2..O6. + +(mmuAD gen 42b79, ruling item 2, route (B)) **Generalised in place over the +excluded state**: the family's parameter `N` is now an `OIx` — a thread state +`k` the spec never writes (`IdleThreadState` or `runningVM`, `OIx.hk`) and the +threads `E` exempt from it; `oiQ N p x := x.tcbState = N.k → N.E p`. An +`ObjRef` coerces to `OIx.idle` (`k := IdleThreadState`, `E := (· = N)`), so +`oiQ ↑N` is the old `oiQ N` definitionally and the statements read as before; +`oi_setThreadState`'s side condition is `ts ≠ N.k ∨ N.E t`. At `k := +runningVM` the family gives P3/VmPerfRvm's `RvmSub` frame of the extended +dispatcher. `OIx.ne` / `oiQ_of_ne`: a literal state other than both. -/ import Fl4Proofs.P3.SpecInvFaultTcbsT open Classical @@ -30,16 +40,37 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -/-- A TCB in `IdleThreadState` sits at `N`. -/ -def oiQ (N : ObjRef) (p : ObjRef) (x : Tcb) : Prop := x.tcbState = .idleThreadState → p = N +/-- (gen 42b79) **An excluded thread state and its exempt threads** (module docstring): `k` is a state no spec +write produces (`IdleThreadState`, written only at boot, or `runningVM`, written only by `vmEnterF`). -/ +structure OIx where + /-- The excluded state. -/ + k : ThreadState + /-- The threads allowed in it. -/ + E : ObjRef → Prop + hk : k = .idleThreadState ∨ k = .runningVM + +/-- The idle instance: only the thread at `N` is in `IdleThreadState`. -/ +def OIx.idle (N : ObjRef) : OIx := ⟨.idleThreadState, (· = N), Or.inl rfl⟩ + +instance : Coe ObjRef OIx := ⟨OIx.idle⟩ + +/-- A state other than `IdleThreadState` and `runningVM` is not the excluded one. -/ +theorem OIx.ne (N : OIx) {ts : ThreadState} (h1 : ts ≠ .idleThreadState) (h2 : ts ≠ .runningVM) : ts ≠ N.k := by + rcases N.hk with e | e <;> rw [e] <;> assumption + +/-- A TCB in `N.k` is one of `N.E` (gen 42b79; for `N := ↑n`: a TCB in `IdleThreadState` sits at `n`). -/ +def oiQ (N : OIx) (p : ObjRef) (x : Tcb) : Prop := x.tcbState = N.k → N.E p + +theorem oiQ_of_ne {N : OIx} {p : ObjRef} {x : Tcb} (h1 : x.tcbState ≠ .idleThreadState) + (h2 : x.tcbState ≠ .runningVM) : oiQ N p x := fun h => absurd h (N.ne h1 h2) -/-- Only the thread at `N` is in `IdleThreadState`. -/ -abbrev OIS (N : ObjRef) (σ : State Unit) : Prop := TP (oiQ N) σ +/-- Only the threads of `N.E` are in `N.k` (for `N := ↑n`: only the thread at `n` is in `IdleThreadState`). -/ +abbrev OIS (N : OIx) (σ : State Unit) : Prop := TP (oiQ N) σ -variable {N : ObjRef} +variable {N : OIx} -abbrev OIK {α : Type} (N : ObjRef) (m : NonDet (State Unit) α) : Prop := IK (OIS N) m -abbrev OIKE {ε α : Type} (N : ObjRef) (m : NonDetE (State Unit) ε α) : Prop := IKE (OIS N) m +abbrev OIK {α : Type} (N : OIx) (m : NonDet (State Unit) α) : Prop := IK (OIS N) m +abbrev OIKE {ε α : Type} (N : OIx) (m : NonDetE (State Unit) ε α) : Prop := IKE (OIS N) m /-- The side conditions of the TCB-writer leaves. -/ macro "oi_side" : tactic => `(tactic| first @@ -58,7 +89,13 @@ macro "oi_side" : tactic => `(tactic| first | (simp; done) | (split <;> simp <;> done) | (simp [oiQ, defaultTcb]; done) - | decide) + | decide + | (intro _ _; refine oiQ_of_ne ?_ ?_ <;> simp [defaultTcb] <;> done) + | (left; refine OIx.ne _ ?_ ?_ <;> decide) + | (left; refine OIx.ne _ ?_ ?_ <;> simp <;> done) + | (left; refine OIx.ne _ ?_ ?_ <;> split <;> simp <;> done) + | (intro _ _ _; refine oiQ_of_ne ?_ ?_ <;> simp <;> done) + | (refine oiQ_of_ne ?_ ?_ <;> simp [defaultTcb] <;> done)) syntax "oi_leaf" : tactic macro_rules | `(tactic| oi_leaf) => `(tactic| fail "no oi_leaf") @@ -79,9 +116,10 @@ macro_rules | `(tactic| oi_leaf) => `(tactic| ((with_reducible refine tp_retypeR macro_rules | `(tactic| oi_leaf) => `(tactic| ((with_reducible refine tp_retypeRegion _ _ _ _ _ ?_); oi_side)) macro_rules | `(tactic| oi_leaf) => `(tactic| with_reducible exact tp_deleteObjects _ _) -/-- **`set_thread_state`** (hand lemma): any state but `IdleThreadState` (no spec -call site writes it: every site passes another literal), or the idle thread itself. -/ -theorem oi_setThreadState (t : ObjRef) (ts : ThreadState) (h : ts ≠ .idleThreadState ∨ t = N) : +/-- **`set_thread_state`** (hand lemma): any state but `N.k` (no spec call site +writes `IdleThreadState` or `runningVM`: every site passes another literal), or an +exempt thread (for `N := ↑n`: the idle thread itself). -/ +theorem oi_setThreadState (t : ObjRef) (ts : ThreadState) (h : ts ≠ N.k ∨ N.E t) : OIK N (setThreadState (Z := Unit) t ts) := by unfold setThreadState refine ik_bind (tp_threadSet _ _ fun _ _ hs => h.resolve_left (not_not.2 hs)) fun _ => ?_ @@ -97,8 +135,8 @@ theorem oi_optionUpdateThread {α : Type} (t : ObjRef) (fn : α → Tcb → Tcb) macro_rules | `(tactic| oi_leaf) => `(tactic| ((with_reducible refine oi_optionUpdateThread _ _ _ ?_); oi_side)) /-- **Retype** (hand lemma): a new TCB is `defaultTcb` (Inactive). -/ -theorem oi_defaultTcb (p : ObjRef) (d : Domain) : oiQ N p (defaultTcb d) := by - simp [oiQ, defaultTcb] +theorem oi_defaultTcb (p : ObjRef) (d : Domain) : oiQ N p (defaultTcb d) := + oiQ_of_ne (by simp [defaultTcb]) (by simp [defaultTcb]) theorem oi_archActivateIdleThread (_t : ObjRef) : OIK N (archActivateIdleThread (Z := Unit) _t) := by unfold archActivateIdleThread; oi_auto diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO2.lean b/proofs/Fl4Proofs/P3/SpecInvAllO2.lean index 527ac0ec7..107f92124 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO2.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO2.lean @@ -10,7 +10,7 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -variable {N : ObjRef} +variable {N : OIx} theorem oi_setPt (ptr : ObjRef) (pt : BitVec 9 → PTE) : OIK N (setPt (Z := Unit) ptr pt) := by unfold setPt; oi_auto diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO3.lean b/proofs/Fl4Proofs/P3/SpecInvAllO3.lean index 0a2bd7ac5..2b149f21c 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO3.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO3.lean @@ -10,7 +10,7 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -variable {N : ObjRef} +variable {N : OIx} theorem oi_tcbEpDequeue (tptr epPtr : ObjRef) : OIK N (tcbEpDequeue (Z := Unit) tptr epPtr) := by unfold tcbEpDequeue; oi_auto diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO4.lean b/proofs/Fl4Proofs/P3/SpecInvAllO4.lean index 47ef1c0cc..4535b0ddd 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO4.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO4.lean @@ -10,7 +10,7 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -variable {N : ObjRef} +variable {N : OIx} theorem oi_getExtraCptrs (b : Option ObjRef) (mi : MessageInfo) : OIK N (getExtraCptrs (Z := Unit) b mi) := by unfold getExtraCptrs diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO5.lean b/proofs/Fl4Proofs/P3/SpecInvAllO5.lean index bbce650a3..363bc2835 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO5.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO5.lean @@ -11,7 +11,7 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -variable {N : ObjRef} +variable {N : OIx} theorem oi_subframeNode (nodeCap : Cap) (index depth : Data) : OIKE N (subframeNode (Z := Unit) nodeCap index depth) := by unfold subframeNode; oi_auto diff --git a/proofs/Fl4Proofs/P3/SpecInvAllO6.lean b/proofs/Fl4Proofs/P3/SpecInvAllO6.lean index 6f51372a0..d3604922d 100644 --- a/proofs/Fl4Proofs/P3/SpecInvAllO6.lean +++ b/proofs/Fl4Proofs/P3/SpecInvAllO6.lean @@ -10,7 +10,7 @@ noncomputable section set_option maxHeartbeats 1000000 set_option maxErrors 2000 -variable {N : ObjRef} +variable {N : OIx} theorem oi_updateWaitingNtfn (ntfnptr : ObjRef) (queue : List ObjRef) (badge : Badge) : OIK N (updateWaitingNtfn (Z := Unit) ntfnptr queue badge) := by unfold updateWaitingNtfn; oi_auto diff --git a/proofs/Fl4Proofs/P3/StPostIoLeaf.lean b/proofs/Fl4Proofs/P3/StPostIoLeaf.lean index 67c06c4e0..6b884b165 100644 --- a/proofs/Fl4Proofs/P3/StPostIoLeaf.lean +++ b/proofs/Fl4Proofs/P3/StPostIoLeaf.lean @@ -13,6 +13,8 @@ final packings adjusted (`J.stab` / `JStab.mv`). The IO port chain no longer tak -/ import Fl4Proofs.P3.StPostInv import Fl4Proofs.P3.XTopJointReplyTail +import Fl4Proofs.P3.XTopJointBudgetF +import Fl4Proofs.P3.XTopJointPreemptZ open Aeneas Aeneas.Std Result namespace Fl4Proofs.P3 @@ -30,80 +32,12 @@ set_option maxHeartbeats 16000000 in success tail has `JAt`. -/ theorem JAtZ.reply1JSt (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .restart) (call : Bool) (v : U64) : - vspace.reply1 st s ct call v ⦃ s2 => ∀ z ∈ (specTail call ct.bv [v.bv] σ).1, JStab (L := L) arI AR Z H Cs s2 a z.2 ⦄ := by - unfold vspace.reply1 - cases call - · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - refine WP.spec_mono (J.runJ hct hk hrs) ?_ - rintro s2 ⟨Lst', D', J2⟩ z hz - rw [specTail_restart hk hrs false v.bv] at hz - simp only [Bool.false_eq_true, ↓reduceIte] at hz - rw [Notif.setThreadState_eq .running hk] at hz - rw [Set.mem_singleton_iff.1 hz] - exact (by first | exact J2.stab | exact J2.stab.mv | exact J2.stab.mv.mv | exact J2.stab.mv.mv.mv) - · simp only [↓reduceIte] - have hin : (do - let buf ← msg.lookup_ipc_buffer st s true ct - let s2 ← obj.Tcb.set_reg st ct s layout.reg.BADGE 0#u64 - let (n, s3) ← msg.set_mr st s2 ct buf 0#u64 v - let mi ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 n - msg.set_msg_info st s3 ct mi) ⦃ s3 => ∃ w : U64, - s3 = L.wr (L.wr (L.wr s (Endp.regA ct (Endp.regIdx Fl4Spec.badge_register)) 0#u64) - (Endp.regA ct (Endp.regIdx (Endp.mrIdx 0))) v) (Endp.regA ct (Endp.regIdx Fl4Spec.msg_info_register)) w ∧ - w.bv = Fl4Spec.messageInfoToData ⟨Fl4Spec.natToLen 1, 0, 0, 0⟩ ⦄ := by - refine WP.spec_bind (Fl4Proofs.P0.msg.lookup_ipc_buffer.p0 st s true ct L.total) ?_ - rintro buf - - refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.BADGE 0#u64) ?_ - rintro s1 rfl - have hset : ∀ s1 : S, msg.set_mr st s1 ct buf 0#u64 v ⦃ r => - r = (1#u64, L.wr s1 (Endp.regA ct (Endp.regIdx (Endp.mrIdx 0))) v) ⦄ := by - intro s1 - unfold msg.set_mr - have h4 : (0#u64 : U64) < msg.N_MSG_REGISTERS := by unfold msg.N_MSG_REGISTERS; decide - simp only [h4, ↓reduceIte] - refine WP.spec_bind (Endp.msg_register_spec 0#u64 (by decide)) ?_ - rintro r0 rfl - refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec _ ct _ v) ?_ - rintro s2 rfl - simp only [lift, bind_ok, WP.spec_ok] - rfl - refine WP.spec_bind (hset _) ?_ - rintro r rfl - unfold msginfo.MessageInfo.new - simp only [bind_ok] - refine WP.spec_mono (Endp.set_msg_info_spec _ ct 0#u64 1#u64 (by decide)) ?_ - rintro s3 ⟨w, rfl, hw⟩ - refine ⟨w, ?_, by rw [hw]; exact msg_info_one_bv⟩ - rw [Endp.regIdx_badge, Endp.regIdx_msgInfo] - refine WP.spec_bind hin ?_ - rintro s3 ⟨w, rfl, hw⟩ - -- the badge register - have hXb := badge_wr_irel J.ip (J.xtop.irelK J.ks J.buf) hct hk 0#u64 - rw [badgeRegA_eq_regA] at hXb - obtain ⟨V1, J1⟩ := J.regWrJ hct hk Fl4Spec.badge_register 0#u64 hXb - set x1 := setReg x Fl4Spec.badge_register (0#u64 : U64).bv with hx1 - have hk1 : (updK σ ct.bv (.tcb x1)).kheap ct.bv = some (.tcb x1) := by simp [updK] - -- the message register - have hX2 := reg_wr_irel J1.ip (J1.xtop.irelK J1.ks J1.buf) hct hk1 (Endp.mrIdx 0) (by decide) v - obtain ⟨V2, J2⟩ := J1.regWrJ hct hk1 (Endp.mrIdx 0) v hX2 - set x2 := setReg x1 (Endp.mrIdx 0) v.bv with hx2 - have hk2 : (updK (updK σ ct.bv (.tcb x1)) ct.bv (.tcb x2)).kheap ct.bv = some (.tcb x2) := by simp [updK] - -- the message info - have hX3 := reg_wr_irel J2.ip (J2.xtop.irelK J2.ks J2.buf) hct hk2 Fl4Spec.msg_info_register (by decide) w - obtain ⟨V3, J3⟩ := J2.regWrJ hct hk2 Fl4Spec.msg_info_register w hX3 - have hxC : setReg x2 Fl4Spec.msg_info_register w.bv = Endp.replyTcb x v.bv := by - rw [hw]; rfl - rw [updK_updK, updK_updK, hxC] at J3 - have hkC : (updK σ ct.bv (.tcb (Endp.replyTcb x v.bv))).kheap ct.bv = some (.tcb (Endp.replyTcb x v.bv)) := by - simp [updK] - -- `Running` - refine WP.spec_mono (J3.runJ hct hkC hrs) ?_ - rintro s4 ⟨Lst', D', J4⟩ z hz - rw [specTail_restart hk hrs true v.bv] at hz - simp only [↓reduceIte] at hz - rw [Notif.setThreadState_eq .running hkC] at hz - rw [Set.mem_singleton_iff.1 hz] - exact (by first | exact J4.stab | exact J4.stab.mv | exact J4.stab.mv.mv | exact J4.stab.mv.mv.mv) + vspace.reply1 st s ct call v ⦃ s2 => ∀ z ∈ (specTail call ct.bv [v.bv] σ).1, JStab (L := L) arI AR Z H Cs s2 a z.2 ⦄ := + WP.spec_mono (J.toB.reply1JFoot hct hk hrs call v) fun _ ⟨_, σ2, _, hz, J', F⟩ z hz' => by + rw [hz] at hz' + rw [Set.mem_singleton_iff.mp hz'] + exact (J'.toJN J F).stab + end StIoA @@ -449,12 +383,11 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} -set_option maxHeartbeats 8000000 in -/-- (stable ghosts, `JStab`) **The `In` tail at `JAt`** (module docstring). -/ -theorem portInTail_jatSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR Z.th) - {s : S} {ar : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) [VxE Z] (hZB : ZNoBlk Z.th (L.mem s) (L.ksb s)) (hC : CurRun σ) - {ct : U64} (hcur : σ.curThread = ct.bv) (port z : U64) (call : Bool) +set_option maxHeartbeats 4000000 in +/-- Restart, perform an I/O-port read, and write its reply with a native footprint. -/ +theorem JAtZB.portInTailJFoot {s : S} {ar : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s ar σ) (hAM : ARMask arI AR) (hC : CurRun σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) (port z : U64) (call : Bool) (hin : ∀ (a : A) p z, ∃ v a', arI.port_in a p z = ok (v, a')) (hval : call = true → PortInValAt arI ar σ) : portInTail (st := st) arI s ar ct port z call ⦃ res => res.1 = .Ok () ∧ L.mem res.2.1 (stA ct) ≠ sched.TS_RESTART ∧ ∀ σ1, @@ -462,19 +395,17 @@ theorem portInTail_jatSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR ∃ rr σy, (.ok rr, σy) ∈ ((Fl4Spec.archPerformInvocation (Z := Unit) (.invokeIOPort (.ioPortInvocation (BitVec.ofNat 16 port.val) (inData z.val)))).run σ1).1 ∧ ∃ w ∈ (specTail call ct.bv rr σy).1, RelTopM (L := L) res.2.1 w.2 ∧ - JStab (L := L) arI AR Z H Cs res.2.1 res.2.2 w.2 ⦄ := by - have hX := J.xtop - obtain ⟨htcb, x, hk⟩ := hX.curTcb hcur - set σ1 := Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv with hσ1 - have hst : Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ = ({((), σ1)}, False) := - Notif.setThreadState_eq .restart hk + ∃ Ac' Lst' D', JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' res.2.1 res.2.2 w.2 ∧ + NatFoot (L := L) Z s σ res.2.1 w.2 ⦄ := by + obtain ⟨hcur, -, -⟩ := J.curEq hct + obtain ⟨htcb, x, hk⟩ := J.xtop.curTcb hcur + obtain ⟨s1, σ1, hst, hσ1, hr1, Ac1, Lst1, D1, B1, F1⟩ := + J.restartRunJ hct hk (hC x (by rw [hcur]; exact hk)) + rw [hcur] at hst unfold portInTail - have hts := WP.spec_and (set_thread_state_cpu (L := L) s ct sched.TS_RESTART) - (spec_self (set_thread_state_cpu (L := L) s ct sched.TS_RESTART)) - refine WP.spec_bind hts ?_ - rintro s1 ⟨⟨hk1, hc1⟩, hr1⟩ obtain ⟨v, a1, hv⟩ := hin ar port z - rw [hv]; simp only [bind_ok] + rw [hr1, bind_ok, hv] + simp only [bind_ok, uncurry_apply_pair] -- the spec's `In` obtain ⟨rr, ms, hu, hmem, hrr⟩ : ∃ rr, ∃ ms : Fl4Spec.MachineState, ms.underlyingMemory = σ1.machineState.underlyingMemory ∧ @@ -493,62 +424,67 @@ theorem portInTail_jatSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR · obtain ⟨ms, hu, hmem⟩ := hval rfl a1 port z v hv σ1 (by rw [hσ1]; unfold Notif.stsAct; split_ifs <;> rfl) exact ⟨[v.bv], ms, hu, hmem, rfl⟩ set σy : Fl4Spec.State Unit := { σ1 with machineState := ms } with hσy - -- the restart and the access, as primitive steps - have hstp : Steps (L := L) arI Z.th s ar σ s1 a1 σy := - ((Steps.restart arI hcur hk htcb hr1 (by rw [hcur]; exact hst) hC).trans arI - (Steps.ksSpec arI (s := s1) (σ := σ1) (σ' := σy) (by constructor <;> first | rfl | exact hu) rfl rfl - (fun h => ⟨h.st, h.node⟩) (fun h => h))).trans arI - (Steps.arch arI (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨port, z, v, hv⟩)))))) - obtain ⟨G', V', Ac', Lst', D', J', -⟩ := hstp _ (stepClosed_jat arI hAM hJS) Z H Cs Ac Lst D rfl J hZB - -- `reply1` - set Z' : XSets := Z.mv G' V' - have hXy := J'.xtop - have hI : Vs.RInv (L := L) Z'.th Z'.P Z'.L4 Z'.L3 Z'.L2 Z'.L1 Z'.N Z'.T Z'.C Z'.E Z'.R Z'.B Z'.c AR Z'.G s1 a1 σy := - ⟨hXy.rel.2.1, hXy.rel.2.2.1, hXy.rel.2.2.2.2.1, hXy.rel.2.2.2.1, hXy.fin⟩ + have har : ArchIrqStep arI ar a1 := Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨port, z, v, hv⟩)))) + obtain ⟨LstY, BY, FY⟩ := B1.msArJ ms a1 hu (fun h => hAM _ _ _ h har) have hkY : σy.kheap ct.bv = some (.tcb { x with tcbState := .restart }) := by - show σ1.kheap ct.bv = _; rw [hσ1, Notif.stsAct_kheap, Notif.updK_kheap, Function.update_self] - have hcurY : ct.bv = σy.curThread := by - show ct.bv = σ1.curThread; rw [hσ1, stsAct_cur]; exact hcur.symm - have hR1 := Vs.reply1_invT s1 a1 σy hI ct htcb hcurY hkY rfl J'.kern.act call v - refine spec_bind_assoc (WP.spec_and hR1 (spec_self hR1)) ?_ - rintro s3 ⟨⟨hne, hks3, w, hw, hI3, hz3⟩, heq⟩ + show σ1.kheap ct.bv = _ + rw [hσ1, Notif.stsAct_kheap, Notif.updK_kheap, Function.update_self] + refine spec_bind_assoc (BY.reply1JFoot (J.thT ct htcb) hkY rfl call v) ?_ + rintro s3 ⟨hne, σ3, Lst3, hz, B3, F3⟩ rw [WP.spec_ok] refine ⟨rfl, hne, fun σ1' hσ1' => ?_⟩ - have e : σ1' = σ1 := by - rw [hst] at hσ1' - exact ((Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hσ1'))).2).symm - subst e - have hSch := hI3.2.2.2.2.1.1.1 - have hXT : XTop (L := L) AR s3 a1 w.2 := ⟨Z', hI3.2.2.2.2, ⟨hXy.rel.1, hI3.1, hI3.2.1, - hI3.2.2.2.1, hI3.2.2.1, by rw [hks3]; exact hXy.rel.2.2.2.2.2.1, hXy.rel.2.2.2.2.2.2.mono hz3⟩, - IpcRel.of hI3.2.2.2.2.1.1.2.2.1 hI3.2.2.2.2.1.1.2.1 (sched_sc hSch), hXy.esa.mono hks3 hz3⟩ - refine ⟨rr, σy, hmem, w, by rw [hrr]; exact hw, hI3.relTop, ?_⟩ - have hctY : ct ∈ Z'.T := J'.thT ct (J'.xtop.curTcb hcurY.symm).1 - have hp := J'.reply1JSt hctY hkY rfl call v - have heq' : vspace.reply1 st s1 ct call v = ok s3 := by unfold vspace.reply1; exact heq - rw [heq', WP.spec_ok] at hp - exact (hp w hw).mv + rw [hst] at hσ1' + have e : σ1' = σ1 := (Prod.mk.inj (Set.singleton_eq_singleton_iff.mp (congrArg Prod.fst hσ1'))).2.symm + subst σ1' + refine ⟨rr, σy, hmem, ((), σ3), ?_, B3.xtop.relTop, Ac1, Lst3, D1, B3, + J.natTrans F1 (B1.natTrans FY F3)⟩ + rw [hrr, hz] + exact Set.mem_singleton _ set_option maxHeartbeats 8000000 in -/-- (stable ghosts, `JStab`) **IOPort `In`** (labels 64..66, any `call`) at `JAt`: the replying shape -(`DecOKRMX`), from `portInTail_jat` (as `decode_invocation_ioport_inX`). -/ -theorem decode_invocation_ioport_inJSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR Z.th) - (s : S) (ar : A) - (σ : Fl4Spec.State Unit) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) [VxE Z] - (hZB : ZNoBlk Z.th (L.mem s) (L.ksb s)) (lbl : U64) (hl : 64 ≤ lbl.val ∧ lbl.val ≤ 66) - (slbl : Fl4Spec.Data) (hlbl : Fl4Spec.invocationType slbl = .archInvocationLabel (inLabel (portSz lbl))) +/-- (stable ghosts, `JStab`) **The `In` tail at `JAt`** (module docstring). -/ +theorem portInTail_jatSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR Z.th) + {s : S} {ar : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) [VxE Z] (hZB : ZNoBlk Z.th (L.mem s) (L.ksb s)) (hC : CurRun σ) + {ct : U64} (hcur : σ.curThread = ct.bv) (port z : U64) (call : Bool) + (hin : ∀ (a : A) p z, ∃ v a', arI.port_in a p z = ok (v, a')) (hval : call = true → PortInValAt arI ar σ) : + portInTail (st := st) arI s ar ct port z call ⦃ res => res.1 = .Ok () ∧ + L.mem res.2.1 (stA ct) ≠ sched.TS_RESTART ∧ ∀ σ1, + Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ = ({((), σ1)}, False) → + ∃ rr σy, (.ok rr, σy) ∈ ((Fl4Spec.archPerformInvocation (Z := Unit) + (.invokeIOPort (.ioPortInvocation (BitVec.ofNat 16 port.val) (inData z.val)))).run σ1).1 ∧ + ∃ w ∈ (specTail call ct.bv rr σy).1, RelTopM (L := L) res.2.1 w.2 ∧ + JStab (L := L) arI AR Z H Cs res.2.1 res.2.2 w.2 ⦄ := by + obtain ⟨c, hc, -⟩ := P1.spec_ex_fd (P0.sched.cur_thread.p0 st s (P1.LawfulStore.total (st := st))) + have hcEq : c = ct := P1.eq_of_bv ((J.toB.curEq hc).1.symm.trans hcur) + subst c + refine WP.spec_mono (J.toB.portInTailJFoot arI hAM hC hc port z call hin hval) ?_ + rintro res ⟨hr, hnr, h⟩ + refine ⟨hr, hnr, fun σ1 hσ1 => ?_⟩ + obtain ⟨rr, σy, hy, w, hw, hRel, Ac', Lst', D', B', F⟩ := h σ1 hσ1 + exact ⟨rr, σy, hy, w, hw, hRel, (B'.toJN J F).stab⟩ + +set_option maxHeartbeats 4000000 in +/-- I/O-port input validation and dispatch, with a caller-supplied proof of the reply tail. -/ +theorem decode_invocation_ioport_inQ {Q : S → A → Fl4Spec.State Unit → Prop} + (s : S) (ar : A) (σ : Fl4Spec.State Unit) (hX : XTopAt (L := L) AR Z s ar σ) (hJ0 : Q s ar σ) + (lbl : U64) (hl : 64 ≤ lbl.val ∧ lbl.val ≤ 66) (slbl : Fl4Spec.Data) + (hlbl : Fl4Spec.invocationType slbl = .archInvocationLabel (inLabel (portSz lbl))) (length buf ct : U64) (hct : sched.cur_thread st s = ok ct) (args : List U64) (hlen : length.val = args.length) (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) (hcur : σ.curThread = ct.bv) (first last : U64) (hfl : first.val ≤ last.val) (hl16 : last.val < 65536) - (hC : CurRun σ) - (hin : ∀ (a : A) p z, ∃ v a', arI.port_in a p z = ok (v, a')) (call : Bool) - (hval : call = true → PortInValAt arI ar σ) - (slot : U64) (blk don fp : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) - (sl : Fl4Spec.CslotPtr) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) : - DecOKRMX (L := L) arI (JStab (L := L) arI AR Z H Cs) s ar σ lbl length slot (.IoPort first last 0#u64) blk call don fp buf + (call : Bool) (slot : U64) (blk don fp : Bool) (extra : Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (sl : Fl4Spec.CslotPtr) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) + (hTail : ∀ port, portInTail (st := st) arI s ar ct port ⟨BitVec.ofNat 64 (portSz lbl)⟩ call ⦃ res => + res.1 = .Ok () ∧ L.mem res.2.1 (stA ct) ≠ sched.TS_RESTART ∧ ∀ σ1, + Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ = ({((), σ1)}, False) → + ∃ rr σy, (.ok rr, σy) ∈ ((Fl4Spec.archPerformInvocation (Z := Unit) + (.invokeIOPort (.ioPortInvocation (BitVec.ofNat 16 port.val) + (inData (⟨BitVec.ofNat 64 (portSz lbl)⟩ : U64).val)))).run σ1).1 ∧ + ∃ w ∈ (specTail call ct.bv rr σy).1, RelTopM (L := L) res.2.1 w.2 ∧ Q res.2.1 res.2.2 w.2 ⦄) : + DecOKRMX (L := L) arI Q s ar σ lbl length slot (.IoPort first last 0#u64) blk call don fp buf extra slbl (args.map UScalar.bv) ci sl excaps buffer ct := by - have hJ0 : JStab (L := L) arI AR Z H Cs s ar σ := J.stab unfold DecOKRMX syscall.decode_invocation rw [hct]; simp only [bind_ok] have hsz : portSz lbl = 1 ∨ portSz lbl = 2 ∨ portSz lbl = 4 := by unfold portSz; split_ifs <;> simp @@ -613,10 +549,9 @@ theorem decode_invocation_ioport_inJSt (hAM : ARMask arI AR) (hJS : JStepHyps (L rw [if_neg hc] rw [if_neg hc] at hens simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] - refine WP.spec_mono (portInTail_jatSt arI hAM hJS J hZB hC hcur port ⟨BitVec.ofNat 64 (portSz lbl)⟩ - call hin hval) ?_ + refine WP.spec_mono (hTail port) ?_ rintro res ⟨hres, hne, hall⟩ - obtain ⟨htcb, x, hk⟩ := J.xtop.curTcb hcur + obtain ⟨htcb, x, hk⟩ := hX.curTcb hcur have hst : Fl4Spec.setThreadState (Z := Unit) ct.bv .restart σ = ({((), Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv)}, False) := Notif.setThreadState_eq .restart hk @@ -626,6 +561,29 @@ theorem decode_invocation_ioport_inJSt (hAM : ARMask arI AR) (hJS : JStepHyps (L (inData (portSz lbl))))), ?_, _, by rw [hcur]; exact hst, rr, σy, hy, z, hz, hRT, hXT⟩ exact DecOut.of_eq (run_liftME_ok (run_liftME_ok ((run_bind_ok hens _).trans rfl))) +set_option maxHeartbeats 8000000 in +/-- (stable ghosts, `JStab`) **IOPort `In`** (labels 64..66, any `call`) at `JAt`: the replying shape +(`DecOKRMX`), from `portInTail_jat` (as `decode_invocation_ioport_inX`). -/ +theorem decode_invocation_ioport_inJSt (hAM : ARMask arI AR) (hJS : JStepHyps (L := L) arI AR Z.th) + (s : S) (ar : A) + (σ : Fl4Spec.State Unit) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) [VxE Z] + (hZB : ZNoBlk Z.th (L.mem s) (L.ksb s)) (lbl : U64) (hl : 64 ≤ lbl.val ∧ lbl.val ≤ 66) + (slbl : Fl4Spec.Data) (hlbl : Fl4Spec.invocationType slbl = .archInvocationLabel (inLabel (portSz lbl))) + (length buf ct : U64) (hct : sched.cur_thread st s = ok ct) (args : List U64) + (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (hcur : σ.curThread = ct.bv) (first last : U64) (hfl : first.val ≤ last.val) (hl16 : last.val < 65536) + (hC : CurRun σ) + (hin : ∀ (a : A) p z, ∃ v a', arI.port_in a p z = ok (v, a')) (call : Bool) + (hval : call = true → PortInValAt arI ar σ) + (slot : U64) (blk don fp : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (sl : Fl4Spec.CslotPtr) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) : + DecOKRMX (L := L) arI (JStab (L := L) arI AR Z H Cs) s ar σ lbl length slot (.IoPort first last 0#u64) blk call don fp buf + extra slbl (args.map UScalar.bv) ci sl excaps buffer ct := + decode_invocation_ioport_inQ arI s ar σ J.xtop J.stab lbl hl slbl hlbl length buf ct hct args hlen hargs hcur + first last hfl hl16 call slot blk don fp extra ci sl excaps buffer + (fun port => portInTail_jatSt arI hAM hJS J hZB hC hcur port ⟨BitVec.ofNat 64 (portSz lbl)⟩ call hin hval) + set_option maxHeartbeats 4000000 in /-- (stable ghosts, `JStab`) **An IO port cap, `JAt` after, every label**: `Out`, the errors and the other labels by their primitive steps (`decode_invocation_ioportXS`, diff --git a/proofs/Fl4Proofs/P3/StPostIrqLeaf.lean b/proofs/Fl4Proofs/P3/StPostIrqLeaf.lean index 175012827..21401dfa1 100644 --- a/proofs/Fl4Proofs/P3/StPostIrqLeaf.lean +++ b/proofs/Fl4Proofs/P3/StPostIrqLeaf.lean @@ -12,6 +12,9 @@ and acknowledgement (`msArJ`: same ghosts), the signal (`signal_atN`: `Z.mv Z.G * `JAtZ.utCheckBSt`, `JAtZ.utCheckBISt`, `JAtZ.handleIrqJIMSt`. Premises: the originals' (no new premise). + +(mmuAD gen 42b71) `JAtZ.handleIrqJIMSt` is XTopJointKEntryEv2's `JAtZB.handleIrqJBM` corollary (`JAtN.toJStab`, moved +here from P3/P3JPreHole), statement unchanged, copy removed. -/ import Fl4Proofs.P3.StPostEv import Fl4Proofs.P3.XTopJointKEntryEv6 @@ -76,10 +79,10 @@ theorem JAtZ.utCheckBSt {s : S} {a : A} {σ0 : Fl4Spec.State Unit} by_cases hnt : NoTmoSend σ1 · refine WP.spec_mono (Hh.checkBudgetF hA hCH hni1 hnsw1 (hmrt a1) (hmb a1) hnt) ?_ rintro ⟨rb, s2, a2⟩ hB hf - obtain ⟨ea, σ2, hcb, -, Lst2, J2⟩ := hB hf - simp only at ea J2 + obtain ⟨ea, σ2, hcb, -, Lst2, J2, F2⟩ := hB hf + simp only at ea J2 F2 subst ea - exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, J2.stab⟩ + exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, (J2.toJN J0 F2).stab⟩ have hnq1 : ∀ d q, σ1.curThread ∉ σ1.readyQueues d q := by rcases hBu.tmo with hnt0 | hnq0 · exact absurd (hnt0.of_eq ekh ect ecs) hnt @@ -100,8 +103,8 @@ theorem JAtZ.utCheckBSt {s : S} {a : A} {σ0 : Fl4Spec.State Unit} · refine WP.spec_mono (Hh.checkBudgetTR hA hmax htu hCH hni1 (Or.inl hres1) hnq1 (hmrt a1) (hmb a1) hkt hrr hth hper hkl) ?_ rintro r hB hf - obtain ⟨z, hz, hz1, V, Ac', Lst', D', J'⟩ := hB hf - exact ⟨z, hz, hz1, Z.G, V, Ac', Lst', D', J'⟩ + obtain ⟨z, hz, hz1, V, Ac', Lst', D', J', F'⟩ := hB hf + exact ⟨z, hz, hz1, Z.G, V, Ac', Lst', D', J'.toJN J0 F'⟩ · have hcb : ∀ xe, σ1.kheap p = some (.endpoint xe) → Endp.CanBlock false xe := fun xe h => by cases xe with | idleEP => trivial @@ -109,8 +112,8 @@ theorem JAtZ.utCheckBSt {s : S} {a : A} {σ0 : Fl4Spec.State Unit} | recvEP q => exact absurd ⟨q, h⟩ hkl refine WP.spec_mono (Hh.checkBudgetT hA hCH hni1 hres1 hnq1 (hmrt a1) (hmb a1) hkt hrr hth hper hcb) ?_ rintro r hB hf - obtain ⟨z, hz, hz1, V, Ac', Lst', D', J'⟩ := hB hf - exact ⟨z, hz, hz1, Z.G, V, Ac', Lst', D', J'⟩ + obtain ⟨z, hz, hz1, V, Ac', Lst', D', J', F'⟩ := hB hf + exact ⟨z, hz, hz1, Z.G, V, Ac', Lst', D', J'.toJN J0 F'⟩ refine WP.spec_mono (WP.spec_and (check_budgetT hA s1 a1 σ1 hS1 hscC hact (hmb a1)) hFalse) ?_ rintro ⟨rb, s2, a2⟩ ⟨hT, hF⟩ cases rb with @@ -174,10 +177,10 @@ theorem JAtZ.utCheckBISt {s : S} {a : A} {σ0 : Fl4Spec.State Unit} JStab (L := L) arI AR Z H Cs r.2.1 r.2.2 z.2 ⦄ := by refine WP.spec_mono (Hh.checkBudgetFI hA hCH hid1 hnsw1 (hmrt a1) (hmb a1)) ?_ rintro ⟨rb, s2, a2⟩ hB hf - obtain ⟨ea, σ2, hcb, -, Lst2, J2⟩ := hB hf - simp only at ea J2 + obtain ⟨ea, σ2, hcb, -, Lst2, J2, F2⟩ := hB hf + simp only at ea J2 F2 subst ea - exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, J2.stab⟩ + exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, (J2.toJN J0 F2).stab⟩ refine WP.spec_mono (WP.spec_and (check_budgetT hA s1 a1 σ1 hS1 hscC hact (hmb a1)) hFalse) ?_ rintro ⟨rb, s2, a2⟩ ⟨hT, hF⟩ cases rb with @@ -201,7 +204,15 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} -set_option maxHeartbeats 16000000 in +/-- (mmuAD gen 42b70) **`JAtN` from a hole's base at stable ghosts** (`JStab`) given `JAtZ` at the base (`JAtZB.toJN`): +the native callers' form of the `mcs*St` posts restated over `JHole.j0 : JAtZB` (moved here from P3/P3JPreHole in gen +42b71, for `handleIrqJIMSt`). -/ +theorem JAtN.toJStab {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0) + {s : S} {a : A} {σ : Fl4Spec.State Unit} (h : JAtN (L := L) arI AR Z H Cs s0 σ0 s a σ) : + JStab (L := L) arI AR Z H Cs s a σ := + match h with + | ⟨V, Ac', Lst', D', B', F⟩ => ⟨Z.G, V, Ac', Lst', D', B'.toJN J0 F⟩ + /-- (stable ghosts, `JStab`) **Ev2's `handleIrqJIM`**: MRPath's `handleIrqJIAN` with `MR` after (module docstring): the masks FL4 writes are the spec's (`MachPlat.mask`), the acknowledgements and the signal keep `MR` (`MachPlat.ack`, MachKeep's `MRKeep`; the spec's @@ -216,179 +227,9 @@ theorem JAtZ.handleIrqJIMSt (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hI interrupt.handle_interrupt st arI s a w ⦃ r => σ.interruptStates i = .irqInactive ∨ ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - have hX := J.xtop - have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 - have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 - have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by - apply BitVec.eq_of_toNat_eq; simp [hwi] - have hwb : w.bv.setWidth 8 = i := setWidth8_eq hwi - have hmaskM : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → - arI.mask_irq a0 w true = ok a1 → MR a1 (maskMs σ0 i true).machineState := by - intro a0 a1 σ0 h0 he - have hm := hM.mask a0 w true σ0.machineState h0 hw256 - rw [he, WP.spec_ok, hwb] at hm - exact hm - -- the acknowledgement keeps `JAt` and `MR` - have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JStab (L := L) arI AR Z H Cs s1 a1 z.2 → MR a1 z.2.machineState → - (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - rintro s1 a1 z hz ⟨G1, V1, Ac1, Lst1, D1, J1⟩ hm1 - refine WP.spec_bind (WP.spec_and (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) (hM.ack a1 w _ hm1)) ?_ - rintro a2 ⟨hA2, hM2⟩ - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, ⟨G1, V1, Ac1, Lst2, D1, J2⟩, hM2⟩) - unfold interrupt.handle_interrupt - rw [irq_max_eq] - simp only [bind_ok] - by_cases hbig : w > 127#u64 - · -- above FL4's maximum - rw [if_pos hbig] - have hgt : i > Fl4Spec.maxIRQ := by - have : 127 < w.val := hbig - show (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - have hm1 := hmaskM a a1 σ hR ha1 - rw [ha1] - simp only [bind_ok] - have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) J1.stab hm1 - · rw [if_neg hbig] - have hw : w.val ≤ 125 := by - have : ¬ 127 < w.val := hbig - omega - have hw128 : w.val < 128 := by omega - have hle : ¬ i > Fl4Spec.maxIRQ := by - show ¬ (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - have hst : σ.interruptStates i = irqSt (L.mem s (irqStA (L.ksb s) w)) := by - rw [← hiw]; exact hIR.st w hw128 - rw [irq_state_eq'] - simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] - set v := L.mem s (irqStA (L.ksb s) w) with hv - -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ → - (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - intro m hm - refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1, hm1⟩) - · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ - intro a2 _ - exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 hm1 - refine key _ ?_ - by_cases h1 : v = 1#u64 - · -- a signal line - rw [if_pos h1] - have hsig : σ.interruptStates i = .irqSignal := by rw [hst, h1]; rfl - have hL : IntLayout Z.th (L.ksb s) := J.intL - have hnode := hL.node w hw128 - obtain ⟨cs, hkc, hwf, hsl⟩ := hX.rel.2.1.1.cnode _ 0 hnode - obtain ⟨c, ac, hcap, hcs, hCR⟩ := hsl [] rfl - rw [show slotAddr (nodeA (L.ksb s) w).bv (Fl4Spec.ofBl []) = nodeA (L.ksb s) w from - cslotAddr_nil _] at hcap - have hgc : Fl4Spec.getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False) := by - rw [← hiw, hIR.node w hw128]; exact getCap_cnode hkc hwf hcs - have hac : ac = absCap c := hCR.abs - rw [irq_slot_eq] - simp only [bind_ok] - rw [slot_cap_eq, hcap] - simp only [bind_ok] - -- the mask after the cap's case - have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JStab (L := L) arI AR Z H Cs s3 a2 σ1 → MR a2 σ1.machineState → - (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - rintro s3 a2 σ1 h1' ⟨G1, V1, Ac1, Lst1, D1, J1⟩ hm2 - obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true - have hm3 := hmaskM a2 a3 σ1 hm2 ha3 - rw [ha3] - simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', ⟨G1, V1, Ac1, Lst3, D1, J3⟩, - hm3⟩ - have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), - (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JStab (L := L) arI AR Z H Cs r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) J.stab hR - cases c with - | Notification p b sd rv => - cases sd with - | false => - simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap, Fl4Spec.capRights, Fl4Spec.AllowSend, rightsOf]) - | true => - simp only [↓reduceIte] - have hP : Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac := by - rw [hac]; exact ⟨rfl, rfl⟩ - have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl - have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by - intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h - have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (WP.spec_and (J.signal_atN hAT hmb hN p b hpN) - (MK.notification_send_signal L.total hAT hK hR)) ?_ - rintro ⟨s2, a2⟩ ⟨⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩, hm2⟩ - have hmem : ((), σ') ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 := by rw [hsp]; rfl - have hmF := MachF.mfk_sendSignal' p.bv b.bv σ _ hmem - exact hmask s2 a2 σ' (hwhen σ' hmem) ⟨Z.G, V', Ac', Lst'', D', J'⟩ (msF_mr hM hm2 hmF) - | _ => - simp only [bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) - rw [if_neg h1] - by_cases h2 : v = 2#u64 - · -- the timer line - rw [if_pos h2] - have htm : σ.interruptStates i = .irqTimer := by rw [hst, h2]; rfl - step with P1.LawfulStore.cur_cpu_spec as ⟨cc, ecc⟩ - step with P1.obj.node_set.spec as ⟨s2, es2⟩ - step with P1.obj.node_set.spec as ⟨s3, es3⟩ - subst es2 es3 ecc - have J2 := J.reprogramJ - obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 - try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, J3.stab, hR⟩ - rw [if_neg h2] - by_cases h3 : v = 3#u64 - · -- an IPI state on a line other than the IPI lines: reserved, nothing - rw [if_pos h3] - have hres : σ.interruptStates i = .irqReserved := by rw [hst, h3]; rfl - unfold smp.handle_ipi - rw [irq_resched_eq] - have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) - simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, J.stab, hR⟩ - rw [if_neg h3] - by_cases h0 : v = 0#u64 - · -- an inactive line: the spec fails - have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl hin - · have hres : σ.interruptStates i = .irqReserved := by - rw [hst]; unfold irqSt; simp [h0, h1, h2] - simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, J.stab, hR⟩ + MR r.2 z.2.machineState ⦄ := + WP.spec_mono (J.toB.handleIrqJBM hARI hAT hIP hM hK hmb hN hR w i hwi hw256 h126 h127) + fun _ h => h.imp id fun ⟨z, hz, hN', hm⟩ => ⟨z, hz, hN'.toJStab J, hm⟩ end diff --git a/proofs/Fl4Proofs/P3/VirtRngOne.lean b/proofs/Fl4Proofs/P3/VirtRngOne.lean index c95574514..cc3d72ba4 100644 --- a/proofs/Fl4Proofs/P3/VirtRngOne.lean +++ b/proofs/Fl4Proofs/P3/VirtRngOne.lean @@ -213,7 +213,7 @@ theorem mdbStep_rngOne {mem mem' : U64 → U64} {G G' : MdbGhost} (hS : MdbStep obtain ⟨d, hd, h1, h2⟩ := hO z hz0 z' hz0' (noA_key a k) (noA_key a' k') (by rw [← a.base, ← a'.base]; exact hb) (by rw [← a.top, ← a'.top]; exact ht) exact ⟨d.map e, List.mem_map.2 ⟨d, hd, rfl⟩, List.mem_map.2 ⟨z, h1, rfl⟩, List.mem_map.2 ⟨z', h2, rfl⟩⟩ - | @frameAlias th m m' g hM hI src dest b hsrc hdest ptr rt fa fv q0 vm mm hsC hcd hq1 hq2 hcin hcr halg hc hrd hr _ _ => + | @frameAlias th m m' g hM hI src dest b hsrc hdest ptr rt fa fv q0 vm mm epSrc hsC hcd hq1 hq2 hcin hcr halg hc hrd hr _ _ => intro hU hO have hsF : isFrame (capV m src) = true := by rw [hsC]; rfl have hcF : isFrame (capV m' dest) = true := by rw [hcd]; rfl diff --git a/proofs/Fl4Proofs/P3/VmCheck.lean b/proofs/Fl4Proofs/P3/VmCheck.lean new file mode 100644 index 000000000..a1fc0ed20 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmCheck.lean @@ -0,0 +1,96 @@ +/- +P3 (line mmuAD, gen 42b81, item 4 step 1): **`vcpu::check` at `VmEptState`, paired with `vmCheckF`** (the exit's +VCPU check of `finish`, spec `fl4KernelExitVF`'s last step), without routing through `JAtZV3`. + +* P3/JAtZV3Check's `vcpu::check` proof is generalised in place over the record (`vmCheckNPG` / `vmCheckG`, taking + `VmBase` of the record, a report step `CkRep` and the notification idling `CkIdle`; `JAtZV3.checkNP` / + `JAtZV3.checkJ` their instances, statements unchanged; `JAtZB.repCur` the base form of `JAtZV3.repCur`). +* **`VmEptState.ntfnIdle`**: FL4's `set_state(NTFN_IDLE)` of an active notification at `VmEptState` — a native step + (`set_idle_relI`, P1's `ntfn_idle_all`, `JAtZB.signal_badge_post`, the footprint by `JAtZB.badgeN`, + `VmEptState.ofNat`). +* `VmEptState.ckRep` (P3/EptReport's `VmEptState.reportJ3`), `VmEptState.ckIdle`. +* **`VmEptState.checkJ`**: FL4's `vcpu.check t` of the current thread `t` at `VmEptState`: one outcome + `vmCheckF t σ = {((), σ')}`, `VmEptState` after (the same `Z`, `H`, `Cs`, `D`), the arch state unchanged. + **`VmEptState.checkCur`**: the same for the thread `sched.cur_thread` reads (what `finish` checks). + +Premises: [P] `ZvVirtAgree arI`, `P0.ArchTotal arI` (those of `VmEptState.reportJ3`). No named premise; no existing +statement changed. New file. +-/ +import Fl4Proofs.P3.VmSignal +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} {XL : U64 → Nat} + +set_option maxHeartbeats 4000000 in +/-- **An active notification made idle at `VmEptState`** (module docstring). -/ +theorem VmEptState.ntfnIdle (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) + {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) {b0 : Fl4Spec.Badge} + (hact : x.ntfnObj = .activeNtfn b0) : + obj.Ntfn.set_state st n s obj.NTFN_IDLE ⦃ s1 => + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s1 a + (updK σ n.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) x))) ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + refine WP.spec_mono (P1.obj.Ntfn.set_state.val s n _) fun s1 e1 => ?_ + subst e1 + obtain ⟨hR2, hW2, hS2⟩ := set_idle_relI B.ip hI.1 hn hk hact + have hnH : n ∈ P1.Heap.ntfns H := B.zH.2.2.2 n hn + have hx := hI.1.toN.at_ntfn hn hk + have hst : L.epState s n = 2#u64 := by + rw [epState_eq, stOf_active hx.obj hact, P1.ntfn_active_val] + obtain ⟨⟨Q0, R0, h0'⟩, hB0, hX0, hS0, hSg0⟩ := B.blk + obtain ⟨h2, hB2, hX2, hS2', hSg2, -⟩ := P1.ntfn_idle_all h0' hB0 hX0 hS0 hSg0 hnH hst + have hrel : SingleRelI (st := st) Z.N Z.T Z.E Z.R Z.B s σ + ({((), updK σ n.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) x)))}, False) _ := + ⟨_, rfl, hR2, hS2, hW2, NoBlock.ntfnUpd _ _ _⟩ + obtain ⟨σ', h1, -, B'⟩ := B.signal_badge_post (y := Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) x) hn hk + (by rw [hact]; intro l e; cases e) (fun l e => by simp [Fl4Spec.ntfnObjUpdate] at e) rfl rfl rfl hrel + ⟨⟨Q0, R0, h2⟩, hB2, hX2, hS2', hSg2⟩ + have e : σ' = updK σ n.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .idleNtfn) x)) := + (congrArg Prod.snd (Set.singleton_injective (Prod.mk.inj h1).1)).symm + subst e + exact J.ofNat (V' := Z.vs) B' (B.badgeN hk hrel) + +theorem VmEptState.ckRep (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) : + CkRep st arI Z.th fun Ac Lst s a σ => VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ := + fun J _ ht hrun b => WP.spec_mono (J.reportJ3 hA hVA ht hrun b) fun _ ⟨σr, Ac', Lst', h1, J', _, _⟩ => + ⟨σr, Ac', Lst', h1, J'⟩ + +theorem VmEptState.ckIdle : + CkIdle st Z.N fun Ac Lst s a σ => VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ := + fun J _ hn _ hk _ hact => WP.spec_mono (J.ntfnIdle hn hk hact) fun _ J' => ⟨_, _, J'⟩ + +/-- **`vcpu::check` of the current thread at `VmEptState`, paired with `vmCheckF`** (module docstring). -/ +theorem VmEptState.checkJ (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : Z.th t = some .tcb) + (hcur : σ.curThread = t.bv) : + vcpu.check st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vmCheckF (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := + vmCheckG (P := fun Ac Lst s a σ => VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) VmEptState.toB + (VmEptState.ckRep hA hVA) VmEptState.ckIdle J ht hcur + +/-- **`vcpu::check` of the thread `sched.cur_thread` reads, at `VmEptState`** (module docstring). -/ +theorem VmEptState.checkCur (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {t : U64} (hct : sched.cur_thread st s = ok t) : + vcpu.check st arI s a t ⦃ r => ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.vmCheckF (Z := Unit) σ.curThread σ = ({((), σ')}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ r.2 = a ⦄ := by + obtain ⟨hcur, -⟩ := J.1.1.curEq hct + rw [hcur] + exact J.checkJ hA hVA (J.1.1.thTcb (TopSR.cur_mem J.1.1.xtop.fin.1 hcur.symm)) hcur + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmDisp.lean b/proofs/Fl4Proofs/P3/VmDisp.lean new file mode 100644 index 000000000..19c1bedc9 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmDisp.lean @@ -0,0 +1,1278 @@ +/- +P3 (line mmuAD, gen 42b65, the Architect's ruling 10:35Z, option (a)): **one dispatcher post for every VM-side arm +at `VmEptState`** — FL4's `syscall::decode_invocation` against the extended decoder `fl4DecodeInvocationV`, the +spec's restart, then the extended perform `fl4PerformInvocationVF`, in HandleTopX's `TopPostDMX` shape (so a later +`handle_invocation` at the record consumes it without reshaping). + +* **`VEAny`**: some `VmEptState` (every set existential) at FL4's state and the spec's. +* **`VDispPostVE`** [definition]: either FL4 returned an error with its store unchanged, the decoder's single + outcome is a related error (`ErrRel`) and `VEAny` holds at the decode's states (`TopPostDMX`'s first arm), or the + decoder decodes `inv` (`DecOut`), the spec restarts the caller (single outcome `σ1`), and an outcome `y` of + `fl4PerformInvocationVF onCore remoteCur blk call don inv` from `σ1` is either `.ok []` with FL4 `Ok ()` and + `VEAny`, or `.error ()` with FL4 `Preempted` and `VmEptPre` (`TopPostDMX`'s second arm with `X` = `VEAny` and the + preempted state's `VmEptPre`; the CSpace relation is inside `VmEptState`). +* Lifts of the existing posts: **`CnAllPostVE.toDisp`** (P3/VmCnodeCp; `MRV` dropped), **`EptInvPost.toDisp`** + (P3/EptDecVm; the restart split off the combined `setThreadState >>= performEptInvocation` by + `VmEptState.restartK`, so it takes `Entered σ`), **`SetEptDecPost.toDisp`** (P3/EptSetRootDec). +* **`decV_untyped_run`** (spec only): on an untyped cap `fl4DecodeInvocationV`'s single outcome is + `fl4DecodeUntypedInvocationV`'s, mapped to `.base (.invokeUntyped _)` (both gate outcomes). +* **`VmEptState.decodeUtDisp`**: P3/RetVmUtDec's `VmEptState.decodeUt` lifted to `syscall::decode_invocation` + (P3/VirtUtGate's `decode_invocation_untyped_eq`), post `VDispPostVE` (`UPost` / `VmUtPost` through + `decV_untyped_run`). +* **`VDispAll`** [definition] / **`VmEptState.decodeDisp`**: every existing `VmEptState` decode top in + `VDispPostVE`'s form, one field per arm, each with that top's own hypotheses: `cnode` (labels 25–32, + `VmEptState.cnodeDecodeAll`), `ept` (`eptDecode`), `frameEpt` (`frameEptDecode`), `frameUnmap` + (`frameUnmapDecode`), `pool` (`poolAssignDecode`), `setEpt` (`decodeSetEpt`), `ut` (`decodeUtDisp`). Shared: + `J`, `Entered σ`, `ArchRefines arI AR` [P], `ZvVirtAgree arI` [P]. + +* Gen 42b84 adds the VCPU, owned I/O-port and EPT-mapped frame arms to `VDispAll`. The + VCPU decoder runs at `VmEptState` with its existing binding and stale-owner semantics. + The reply-producing routes use `VDispReplyVE` for replies sent inside the decoder. + The other EPT-mapped frame labels use the native get-address, accessed-bit and + subframe implementations, the invalid-capability result for native map, and the + illegal-operation result for unsupported labels. + +Premises: each field uses its source top's hypotheses. The host caller's +`ZvCtRun` is the existing syscall entry scope. The I/O-port arms use the existing +`ARMask` and `PortInValAt` platform facts. +-/ +import Fl4Proofs.P3.VmCnodeAll +import Fl4Proofs.P3.EptDecVm +import Fl4Proofs.P3.EptSetRootDec +import Fl4Proofs.P3.RetVmUtDec +import Fl4Proofs.P3.VmVcpuDec +import Fl4Proofs.P3.JAtZV3HiTop +import Fl4Proofs.P3.HandleTopG +import Fl4Proofs.P3.XTopJointBudgetF +import Fl4Proofs.P3.XTopJointVsSub +import Fl4Proofs.P3.XTopJointReadFpu +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched Fl4Proofs.P1 + +/-- **Some `VmEptState`** at FL4's state and the spec's (module docstring). -/ +def VEAny (AR : A → Fl4Spec.Cr3 → Prop) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop := + ∃ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) + (D : Set U64), VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ + +/-- **The VM-side dispatcher post** (module docstring): `TopPostDMX` over `fl4DecodeInvocationV` / +`fl4PerformInvocationVF` with `VEAny`, and `VmEptPre` after a preemption. -/ +def VDispPostVE (AR : A → Fl4Spec.Cr3 → Prop) (MR : A → Fl4Spec.MachineState → Prop) + (onCore remoteCur : Fl4Spec.ObjRef → Bool) (σ : Fl4Spec.State Unit) (blk call don : Bool) + (m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV) (s : S) (res : core.result.Result Unit error.Exc × S × A) : + Prop := + (∃ e, res.1 = .Err e ∧ res.2.1 = s ∧ (∃ e', m.run σ = ({(.error e', σ)}, False) ∧ ErrRel e e') ∧ + VEAny (L := L) arI AR res.2.1 res.2.2 σ) ∨ + (∃ inv, DecOut m σ inv ∧ ∃ σ1, + Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + ∃ y ∈ ((Fl4Spec.fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv).run σ1).1, + (res.1 = .Ok () ∧ y.1 = .ok [] ∧ VEAny (L := L) arI AR res.2.1 res.2.2 y.2) ∨ + (res.1 = .Err .Preempted ∧ y.1 = .error () ∧ + ∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR res.2.1 res.2.2 y.2)) + +theorem VmEptState.any {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) : VEAny (L := L) arI AR s a σ := + ⟨V, X, XL, Z, H, Cs, Ac, Lst, D, J⟩ + +/-- An invocation whose perform is `M; returnOk []`: an `Ok` outcome of `M` gives `.ok []`. -/ +theorem perfNil_ok {M : Fl4Spec.PMonad Unit Unit} {σ1 σ' : Fl4Spec.State Unit} + (h : (.ok (), σ') ∈ (M.run σ1).1) : + ((.ok [], σ') : Except Unit (List Fl4Spec.Data) × Fl4Spec.State Unit) ∈ + ((M >>= fun _ => Fl4Spec.NonDetE.returnOk ([] : List Fl4Spec.Data)).run σ1).1 := + mem_bindE_ok h rfl + +/-- A preempted outcome of `M` is one of `M; returnOk []`. -/ +theorem perfNil_err {M : Fl4Spec.PMonad Unit Unit} {σ1 σ' : Fl4Spec.State Unit} + (h : (.error (), σ') ∈ (M.run σ1).1) : + ((.error (), σ') : Except Unit (List Fl4Spec.Data) × Fl4Spec.State Unit) ∈ + ((M >>= fun _ => Fl4Spec.NonDetE.returnOk ([] : List Fl4Spec.Data)).run σ1).1 := + mem_bindE_err h + +/-- **The CNode post gives the dispatcher post** (module docstring; `MRV` dropped). -/ +theorem CnAllPostVE.toDisp {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV} {res : core.result.Result Unit error.Exc × S × A} + (h : CnAllPostVE (L := L) arI AR MR Z H Cs σ m s a res) (onCore remoteCur : Fl4Spec.ObjRef → Bool) + (blk call don : Bool) : VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res := by + rcases h with ⟨e, e', rfl, he, hm⟩ | ⟨inv, σ1, hd, hst, σ', G', hr, -, hW⟩ + · exact Or.inl ⟨e, rfl, rfl, ⟨e', hm, he⟩, J.any arI⟩ + · refine Or.inr ⟨_, hd, σ1, hst, ?_⟩ + rcases hr with ⟨h1, hy⟩ | ⟨h1, hy⟩ + · rw [h1] at hW + obtain ⟨⟨V', X', XL', Vv, Ac', Lst', D', hJ⟩, -⟩ := hW + exact ⟨_, perfNil_ok hy, Or.inl ⟨h1, rfl, hJ.any arI⟩⟩ + · rw [h1] at hW + obtain ⟨V', X', XL', hP⟩ := hW + exact ⟨_, perfNil_err hy, Or.inr ⟨h1, rfl, V', X', XL', hP⟩⟩ + +/-- **The EPT post gives the dispatcher post** (module docstring). -/ +theorem EptInvPost.toDisp {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV} {res : core.result.Result Unit error.Exc × S × A} + (h : EptInvPost (L := L) arI V X XL AR Z H Cs Ac D σ m s a res) (onCore remoteCur : Fl4Spec.ObjRef → Bool) + (blk call don : Bool) : VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res := by + rcases h with ⟨e, e', rfl, he, hm⟩ | ⟨h1, inv, σ', hd, hb, Lst', hJ⟩ + · exact Or.inl ⟨e, rfl, rfl, ⟨e', hm, he⟩, J.any arI⟩ + · obtain ⟨-, σ1, -, -, -, -, -, hst, -⟩ := J.restartK hni + have hy : ∃ x ∈ (Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ).1, + ((), σ') ∈ (Fl4Spec.performEptInvocation (Z := Unit) inv x.2).1 := by + have : ((), σ') ∈ ((Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart >>= fun _ => + Fl4Spec.performEptInvocation (Z := Unit) inv) σ).1 := by rw [hb]; rfl + exact this + obtain ⟨x, hx, hpx⟩ := hy + rw [hst] at hx + obtain rfl : x = ((), σ1) := hx + refine Or.inr ⟨_, hd, σ1, hst, (.ok [], σ'), ?_, Or.inl ⟨h1, rfl, hJ.any arI⟩⟩ + show ((.ok [], σ') : Except Unit (List Fl4Spec.Data) × Fl4Spec.State Unit) ∈ + ((Fl4Spec.NonDetE.liftE (do Fl4Spec.performEptInvocation (Z := Unit) inv; return ([] : List Fl4Spec.Data))).run + σ1).1 + exact mem_liftE (x := (([] : List Fl4Spec.Data), σ')) (mem_bind_nd hpx rfl) + +/-- **The SetEPTRoot post gives the dispatcher post** (module docstring). -/ +theorem SetEptDecPost.toDisp {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {p : U64} + {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV} {res : core.result.Result Unit error.Exc × S × A} + (h : SetEptDecPost (L := L) arI V X XL AR Z H Cs σ s a p m res) (onCore remoteCur : Fl4Spec.ObjRef → Bool) + (blk call don : Bool) : VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res := by + rcases h with ⟨e, rfl, e', hm, he⟩ | ⟨ps, idxs, c, -, hm, h1, σ1, σ3, G', Ac', Lst', D', hst, hy, hJ, -⟩ + · exact Or.inl ⟨e, rfl, rfl, ⟨e', hm, he⟩, J.any arI⟩ + · exact Or.inr ⟨_, DecOut.of_eq hm, σ1, hst, _, perfNil_ok hy, Or.inl ⟨h1, rfl, hJ.any arI⟩⟩ + +end + +section +open Notif Endp Ipc Classical + +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +/-- The dispatcher post for a reply written within the decoder. -/ +abbrev VDispReplyVE (arI : machine.Arch A) {AR : A → Fl4Spec.Cr3 → Prop} (on rc : Fl4Spec.ObjRef → Bool) (σ : Fl4Spec.State Unit) (blk call don : Bool) + (m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV) (ct : U64) (s : S) + (res : core.result.Result Unit error.Exc × S × A) : Prop := + TopPostRMXG (L := L) (Fl4Spec.fl4PerformInvocationVF on rc) (VEAny (L := L) arI AR) + σ blk call don m ct s res + +private theorem VmEptState.replyTailPost + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) + (hrun : x.tcbState = .running) (hcur : σ.curThread = ct.bv) (call : Bool) (ms : List Fl4Spec.Data) + (hlen : ms.length ≤ Fl4Spec.msgMaxLength) {s' : S} {Lst' : U64 → List U64} + (B : VmBaseF (L := L) arI s σ V AR Z H Cs Ac Lst' D s' a + (stsAct (updK (if call then replyState σ ct.bv x ms else σ) ct.bv + (.tcb { (if call then replyTcbB x (ipcBufOf true x) ms else x) with + tcbState := .running })) ct.bv)) : + L.mem s' (stA ct) ≠ sched.TS_RESTART ∧ + ∃ z ∈ (specTail call ct.bv ms (zcR ct.bv σ)).1, RelTopM (L := L) s' z.2 ∧ + VEAny (L := L) arI AR s' a z.2 := by + let x' := { (if call then replyTcbB x (ipcBufOf true x) ms else x) with tcbState := .running } + let σ' := stsAct (updK (if call then replyState σ ct.bv x ms else σ) ct.bv (.tcb x')) ct.bv + have hk' : σ'.kheap ct.bv = some (.tcb x') := by + simp only [σ', stsAct_kheap, updK_kheap, Function.update_self] + have J' : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst' D s' a σ' := by + refine J.ofFBind B (fun v _ old new ho hn => ?_) + by_cases hv : v.bv = ct.bv + · rw [hv, hk] at ho + cases ho + · have hs : σ'.kheap v.bv = σ.kheap v.bv := by + simp only [σ', stsAct_kheap, updK_kheap, Function.update_of_ne hv] + cases call + · rfl + · exact replyStateB_kheap_ne σ ct.bv x (ipcBufOf true x) ms hv + rw [hs] at hn + exact VcpuBindingKeep.refl σ v old new ho hn + have hz : ((), σ') ∈ (specTail call ct.bv ms (zcR ct.bv σ)).1 := by + rw [zc_tail hk hrun hcur call ms hlen (fun p hp z hz => J.1.1.bufFrames hct hk p hp z.1 (mrPairs_lt hz))] + exact Set.mem_singleton _ + exact ⟨J'.1.1.notRestart hct hk' (by intro h; cases h), ((), σ'), hz, J'.1.1.xtop.relTop, J'.any arI⟩ + +set_option maxHeartbeats 4000000 in +private theorem VmEptState.replyWsTailPost + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) + (hrun : x.tcbState = .running) (hcur : σ.curThread = ct.bv) (call : Bool) (ws : List U64) + (hlen : (ws.map (·.bv)).length ≤ Fl4Spec.msgMaxLength) {s' : S} + (hs : vcpuReplyWs st s ct call ws = ok s') : + L.mem s' (stA ct) ≠ sched.TS_RESTART ∧ + ∃ z ∈ (specTail call ct.bv (ws.map (·.bv)) (zcR ct.bv σ)).1, + RelTopM (L := L) s' z.2 ∧ VEAny (L := L) arI AR s' a z.2 := by + let ms : List Fl4Spec.Data := ws.map (fun w => w.bv) + let σ1 := stsAct (updK (if call then replyState σ ct.bv x ms else σ) ct.bv + (.tcb { (if call then replyTcbB x (ipcBufOf true x) ms else x) with tcbState := .running })) ct.bv + let Q (r : S) := ∃ Lst' : U64 → List U64, + VmBaseF (L := L) arI s σ V AR Z H Cs Ac Lst' D r a σ1 + have hl : ws.length ≤ 120 := by + have hm : (ws.map (fun w : U64 => w.bv)).length ≤ 120 := hlen + simpa only [List.length_map] using hm + have hR : vcpuReplyWs st s ct call ws ⦃ Q ⦄ := + VmBaseF.replyWsRun3 (sA := s) (σA := σ) J.toF hct hk hrun call ws hl + obtain ⟨Lst', B⟩ : Q s' := spec_ok_post (P := Q) hR hs + exact VmEptState.replyTailPost (s' := s') (Lst' := Lst') J hct hk hrun hcur call ms hlen B + +set_option maxHeartbeats 4000000 in +/-- Lift both VCPU decoder tails to the VM/EPT dispatcher posts. -/ +theorem VmEptState.vcpuDisp (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) + (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hAT : P0.ArchTotal arI) + {p lbl len buf ct : U64} (hp : p ∈ V) (hcan : Canonical p) + (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (blk call don fp : Bool) (hbuf : BufOut V buf) (ex : Array obj.Slot 3#usize) + (args : List Fl4Spec.Data) (hargs : VArgs st s ct buf len args) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (he : ExtraOK Z.th (L.mem s) ex ec) + (on rc : Fl4Spec.ObjRef → Bool) (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) + (buffer : Option Fl4Spec.ObjRef) : + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Vcpu p) blk call don fp buf ex ⦃ res => + let m := specDecV fp lbl.bv args ci sl (.Vcpu p) ec buffer + VDispPostVE (L := L) arI AR MR on rc σ blk call don m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) on rc σ blk call don m ct s res ⦄ := by + have B := J.1.1 + obtain ⟨hcur, -, -⟩ := B.curEq hct + obtain ⟨htcb, x, hk⟩ := B.xtop.curTcb hcur + have ht : ct ∈ Z.T := B.thT ct htcb + have hrun := hRun x hk + have hsl := exAt_idx0 ex + obtain ⟨b, hbn, -⟩ := P1.spec_ex_fd (P0.obj.Slot.is_null.p0 (Ipc.exAt ex 0)) + have hex := ExtraOK.vcaps B.xtop.rel.1 he hsl hbn + have hslot := fun hb : b = false => ExtraOK.eioSlot B.xtop.rel.1 he (Ipc.exAt ex 0) hsl (hb ▸ hbn) + have hcap : b = false → obj.Slot.cap st (Ipc.exAt ex 0) s = ok (capV (L.mem s) (Ipc.exAt ex 0)) := by + intro hb + rw [slot_cap_eq, capAt_capV] + have hth : b = false → ∀ t, capV (L.mem s) (Ipc.exAt ex 0) = .Thread t → Z.th t = some .tcb := by + intro hb t h + obtain ⟨pc, r, idx, hpc, hidx, e⟩ := hslot hb + have Hs : AbsSlot Z.th (pc.bv, idx) := ⟨pc, rfl, Or.inl (by simpa [hidx] using hpc)⟩ + have hs : IsSlot Z.th (Ipc.exAt ex 0) := by rw [e]; exact Hs.isSlot + exact B.thrCap hs t h + rw [VirtDispVcpu.decode_invocation_vcpu_eq arI] + refine WP.spec_mono (J.vcpuDecodeJ hK hSy hVA hCap hAT hp hcan call hbuf ex hsl hbn hcap hslot hth) ?_ + rintro res ⟨ct', hct', hPost⟩ + have hctEq : ct' = ct := ok_inj (hct'.symm.trans hct) + subst ct' + rcases hPost args ec hargs hex with ⟨e, e', hr, he', hm, hs, J'⟩ | + ⟨inv, rep, s', σ', Ac', Lst', hr, hm, hperf, J', hTail⟩ + · exact Or.inl (Or.inl ⟨e, hr, hs, ⟨e', VirtDispVcpu.decV_err hm, Or.inl he'⟩, hs.symm ▸ J'.any arI⟩) + · have hde := VirtDispVcpu.decV_ok (fp := fp) (ci := ci) (slot := sl) (buffer := buffer) hm + have hkc : σ.kheap σ.curThread = some (.tcb x) := by rw [hcur]; exact hk + have hsl5 : ∀ v lo hi a sl', inv = .enableIoPort v lo hi a sl' → sl'.1 ≠ σ.curThread := by + rintro v lo hi a sl' rfl + have hd := zv_dec_eio_slot (zv_decV_mem hde) + obtain ⟨c0, rest, hec⟩ := hd + cases b + · obtain ⟨csl, rest', ee, hAs, haa⟩ := hex.2 rfl + obtain ⟨pc, r, idx, hpc, hidx, hps⟩ := hslot rfl + rw [hec] at ee + obtain rfl : sl' = csl := congrArg Prod.snd (List.cons.inj ee).1 + have hAs' : AbsSlot Z.th (pc.bv, idx) := ⟨pc, rfl, Or.inl (by simpa [hidx] using hpc)⟩ + rw [cslotAddr_inj B.xtop.rel.1 hAs hAs' (haa.trans hps), hcur] + intro e + have ep : pc = ct := VirtSanEq.u64_ext e + subst ep + rw [htcb] at hpc + cases hpc + · rw [hex.1 rfl] at hec + cases hec + obtain ⟨hst, hpR, hk', hc'⟩ := zc_restart_perform hperf hkc (by rw [hrun]; intro h; cases h) + hsl5 on rc blk call don + rw [hcur] at hst hpR hk' hc' + have hstCur : Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), zcR ct.bv σ)}, False) := by + rw [hcur] + exact hst + have hmem : (.ok rep, zcR ct.bv σ') ∈ + ((Fl4Spec.fl4PerformInvocationVF on rc blk call don (.vcpu inv)).run (zcR ct.bv σ)).1 := by + rw [hpR] + exact Set.mem_singleton _ + have hct' : sched.cur_thread st s' = ok ct := by + obtain ⟨c', heq, -⟩ := P1.spec_ex_fd (P0.sched.cur_thread.p0 st s' (P1.LawfulStore.total (st := st))) + rw [heq, VirtSanEq.u64_ext ((J'.1.1.curEq heq).1.symm.trans hc')] + rcases hTail with ⟨rfl, hs⟩ | ⟨y, rfl, hs⟩ | ⟨ws, rfl, hs⟩ + · obtain ⟨s1, σ1, -, eσ1, hs1, Ac1, Lst1, D1, B1, hF⟩ := + J'.1.1.restartRunJ hct' hk' (by rw [hrun]; rfl) + have eσ : σ1 = zcR ct.bv σ' := eσ1.trans (zcR_of hk').symm + rw [ok_inj (hs1.symm.trans hs), eσ] at B1 hF + have J1 := J'.ofNat (V' := Z.vs) B1 hF + exact Or.inl (Or.inr ⟨_, DecOut.of_eq hde, zcR ct.bv σ, hstCur, _, hmem, Or.inl ⟨hr, rfl, J1.any arI⟩⟩) + · have hR := J'.toF.vreply3 hct' ht hk' hrun call y + rw [hs, WP.spec_ok] at hR + obtain ⟨Lst1, B1⟩ := hR + obtain ⟨hn, hz⟩ := J'.replyTailPost ht hk' hrun hc' call [y.bv] (by simp [Fl4Spec.msgMaxLength]) B1 + exact Or.inr (Or.inr ⟨hr, hn, _, DecOut.of_eq hde, zcR ct.bv σ, hstCur, _, _, hmem, hz⟩) + · have hlen : (ws.map (·.bv)).length ≤ 64 := zv_rep_len (zv_decV_mem hde) hperf + have hmax : (ws.map (·.bv)).length ≤ Fl4Spec.msgMaxLength := + Nat.le_trans hlen (by decide) + obtain ⟨hn, hz⟩ := VmEptState.replyWsTailPost J' ht hk' hrun hc' call ws hmax hs + exact Or.inr (Or.inr ⟨hr, hn, _, DecOut.of_eq hde, zcR ct.bv σ, hstCur, _, _, hmem, hz⟩) + +end + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) + {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +open Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched Fl4Proofs.P3.Ipc Fl4Proofs.P1 + +private theorem pageMapEpt_label {lbl : U64} (hne : lbl ≠ fl4_abi.label.X86PageMapEPT) : + Fl4Spec.dataToNat lbl.bv ≠ Fl4Spec.fl4PageMapEptLabel := by + intro h + apply hne + apply UScalar.eq_of_val_eq + rw [← UScalar.bv_toNat, show fl4_abi.label.X86PageMapEPT.val = 60 by + unfold fl4_abi.label.X86PageMapEPT + rfl] + exact h + +/-- Native PageMap rejects an EPT-mapped frame before consulting the extra caps. -/ +theorem VmEptState.frameMapEptReject (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) (p rt asid va len buf : U64) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a fl4_abi.label.X86PageMap len (cslotAddr sl) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR on rc σ blk call don (specDecV fp fl4_abi.label.X86PageMap.bv + args ci sl (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ := by + have hne : fl4_abi.label.X86PageMap ≠ fl4_abi.label.X86PageMapEPT := by + unfold fl4_abi.label.X86PageMap fl4_abi.label.X86PageMapEPT + decide + have hmap : Fl4Spec.invocationType fl4_abi.label.X86PageMap.bv = .archInvocationLabel .x64PageMap := by + rw [invocationType_eq, dataToNat_bv, show fl4_abi.label.X86PageMap.val = 55 by + unfold fl4_abi.label.X86PageMap + rfl] + rfl + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + unfold vspace.decode + rw [hct] + simp only [bind_ok, vspace.decode_frame, vspace.as_frame, hne, ↓reduceIte, error.invalid_cap, WP.spec_ok] + refine Or.inl ⟨_, rfl, rfl, ⟨.invalidCapability 0, ?_, Or.inr ⟨0#u64, rfl, rfl⟩⟩, J.any arI⟩ + simp only [specDecV, absCap, Fl4Spec.fl4DecodeInvocationV, if_neg (pageMapEpt_label hne), hmap, and_self, + Option.isSome_some, ↓reduceIte] + rfl + +/-- Labels outside the frame decoder return IllegalOperation for EPT-mapped frames. -/ +theorem VmEptState.frameOtherDisp (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct lbl : U64} (hct : sched.cur_thread st s = ok ct) (hlbl : FrameLabel lbl lbl.bv) + (hm : lbl ≠ fl4_abi.label.X86PageMap) (hu : lbl ≠ fl4_abi.label.X86PageUnmap) + (hg : lbl ≠ fl4_abi.label.X86PageGetAddress) (ht : lbl ≠ fl4_abi.label.X86PageTestAndClearAccessed) + (hd : lbl ≠ fl4_abi.label.X86PageDeriveSubframe) (p rt asid va len buf : U64) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Frame p sz rt dev true true asid va) + blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR on rc σ blk call don + (specDecV fp lbl.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ := by + obtain ⟨o1, o2, o3⟩ := hlbl.other hm hu hg ht hd + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + unfold vspace.decode + rw [hct] + simp only [bind_ok, vspace.decode_frame, vspace.as_frame, hlbl.native, hm, hu, hg, ht, hd, ↓reduceIte, + error.illegal, WP.spec_ok] + refine Or.inl ⟨_, rfl, rfl, ⟨.illegalOperation, ?_, Or.inl trivial⟩, J.any arI⟩ + simp only [specDecV, absCap, Fl4Spec.fl4DecodeInvocationV, if_neg (pageMapEpt_label hlbl.native), o1, o2, + and_false, ↓reduceIte, Fl4Spec.fl4DecodeInvocation, Fl4Spec.fl4ArchDecodeInvocation, + if_neg (fun h => hd (hlbl.ds h)), if_neg (fun h => ht (hlbl.tac h))] + refine run_liftME_err (run_liftME_err (run_liftME_err ?_)) + unfold Fl4Spec.archDecodeInvocation + dsimp only + unfold Fl4Spec.decodePageInvocation + dsimp only + rw [if_neg o1, if_neg o2, if_neg o3] + rfl + +set_option maxHeartbeats 4000000 in +/-- A large EPT-mapped frame can derive ordinary unmapped subframe caps. -/ +theorem VmEptState.frameDeriveDisp + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + {ct len buf pc p rt asid va : U64} {idx : List Bool} (hpc : Z.th pc = some (.cnode idx.length)) + (hct : sched.cur_thread st s = ok ct) + {sz : capability.FrameSize} {dev : Bool} + (hc : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Frame p sz rt dev true true asid va)) + (args : List U64) (hlen : len.val = args.length) + (hargs : ∀ i : U64, ∀ v, args[i.val]? = some v → msg.syscall_arg st s ct buf i = ok v) + (blk call don fp : Bool) (ex : Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (hex : JVsExtra (L := L) Z s ex ec) + (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a fl4_abi.label.X86PageDeriveSubframe len (cslotAddr (pc.bv, idx)) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR on rc σ blk call don + (specDecV fp fl4_abi.label.X86PageDeriveSubframe.bv (args.map UScalar.bv) ci (pc.bv, idx) + (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ := by + let lbl := fl4_abi.label.X86PageDeriveSubframe + have hn : lbl ≠ fl4_abi.label.X86PageMapEPT := by + unfold lbl fl4_abi.label.X86PageDeriveSubframe fl4_abi.label.X86PageMapEPT + decide + have hm : lbl ≠ fl4_abi.label.X86PageMap := by + unfold lbl fl4_abi.label.X86PageDeriveSubframe fl4_abi.label.X86PageMap + decide + have hu : lbl ≠ fl4_abi.label.X86PageUnmap := by + unfold lbl fl4_abi.label.X86PageDeriveSubframe fl4_abi.label.X86PageUnmap + decide + have hg : lbl ≠ fl4_abi.label.X86PageGetAddress := by + unfold lbl fl4_abi.label.X86PageDeriveSubframe fl4_abi.label.X86PageGetAddress + decide + have ht : lbl ≠ fl4_abi.label.X86PageTestAndClearAccessed := by + unfold lbl fl4_abi.label.X86PageDeriveSubframe fl4_abi.label.X86PageTestAndClearAccessed + decide + have hl := frame_label lbl hn + have hi : Fl4Spec.invocationType lbl.bv = .genInvocationLabel .invalidInvocation := by + rw [invocationType_eq, dataToNat_bv, show lbl.val = 57 by simp [lbl, fl4_abi.label.X86PageDeriveSubframe]] + rfl + have hma : Fl4Spec.invocationType lbl.bv ≠ .archInvocationLabel .x64PageMap := by rw [hi]; intro h; cases h + have hua : Fl4Spec.invocationType lbl.bv ≠ .archInvocationLabel .x64PageUnmap := by rw [hi]; intro h; cases h + have hspec : specDecV fp lbl.bv (args.map UScalar.bv) ci (pc.bv, idx) + (.Frame p sz rt dev true true asid va) ec buffer = + Fl4Spec.NonDetE.liftME Fl4Spec.Fl4InvocationV.base + (Fl4Spec.NonDetE.liftME Fl4Spec.Fl4Invocation.invokeArchObject + (Fl4Spec.NonDetE.liftME Fl4Spec.Fl4ArchInvocation.deriveSubframe + (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pc.bv, idx) + (.pageCap dev p.bv (vmRightsOf rt) .vmEptMap (frameSizeOf sz) (some (asid.bv, va.bv))) ec))) := by + simp only [specDecV, absCap, Fl4Spec.fl4DecodeInvocationV, if_neg (pageMapEpt_label hn), hma, hua, + and_false, ↓reduceIte, Fl4Spec.fl4DecodeInvocation, Fl4Spec.fl4ArchDecodeInvocation, if_pos (hl.dsr rfl)] + change syscall.decode_invocation st arI s a lbl len _ _ blk call don fp buf ex ⦃ _ ⦄ + rw [hspec] + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + unfold vspace.decode + rw [hct] + simp only [bind_ok, vspace.decode_frame, vspace.as_frame, hm, hu, hg, ht, hn, if_pos (show lbl = fl4_abi.label.X86PageDeriveSubframe from rfl), ↓reduceIte] + rcases hex.hext with ⟨hex0, rfl⟩ | ⟨y, nc, nc', nsl, rest, hex0, hcy, hnr, rfl⟩ + · unfold vspace.derive_subframe + rw [hct, hex0] + simp only [bind_ok, error.truncated, WP.spec_ok] + exact Or.inl ⟨_, rfl, rfl, ⟨_, run_liftME_err (run_liftME_err (run_liftME_err + (decodeSub_trunc (Or.inl rfl) _ _ σ))), Or.inl trivial⟩, J.any arI⟩ + have B := J.1.1 + have hM := B.xtop.rel.2.1.2.2.1 + have hVC := B.vsc.caps hM + have hAs : AbsSlot Z.th (pc.bv, idx) := ⟨pc, rfl, Or.inl hpc⟩ + have hms := (hM.members _).2 ⟨hAs.isSlot, _, hc, by simp⟩ + have hno := NoOverlap.hno B.xtop.rel.2.2.2.2.1.1.2.2 hms (by rw [capV_of_capAt hc]; rfl) + rw [capV_of_capAt hc] at hno + have hy := hex.hxs y hex0 + have hnv : CapValid Z.th nc := by + have h := Vs.capValid_slot B.xtop.rel.2.1.2.1 hy + rwa [capV_of_capAt hcy] at h + let Q := fun G s' σ' => ∃ Ac' Lst' D', + VmEptState (L := L) arI V X XL AR (Z.mv G Z.vs) H Cs Ac' Lst' D' s' a σ' + have hRestart : ∃ s1 σ1, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + sched.set_thread_state st s ct sched.TS_RESTART = ok s1 ∧ Q Z.G s1 σ1 := by + obtain ⟨_, x, hk, hr⟩ := B.curRunnable hni hct + obtain ⟨s1, σ1, hst, _, hs1, Ac1, Lst1, D1, B1, F1⟩ := B.restartRunJ hct hk hr + exact ⟨s1, σ1, hst, hs1, Ac1, Lst1, D1, J.ofNat (V' := Z.vs) B1 F1⟩ + have hBase : ∀ {s1 σ1 G1}, Q G1 s1 σ1 → ∃ Ac1 Lst1 D1, + JAtZB (L := L) arI AR (Z.mv G1 Z.vs) H Cs Ac1 Lst1 D1 s1 a σ1 := by + rintro _ _ _ ⟨Ac1, Lst1, D1, J1⟩ + exact ⟨Ac1, Lst1, D1, J1.1.1⟩ + refine WP.spec_mono (derive_subframeQ arI B hpc rfl hc (fun _ _ => hno) hVC ct hct len buf args hlen hargs + ex hex0 hy hcy hnr hnv nsl rest (Q := Q) hRestart hBase ?_) ?_ + · rintro si σi hQi hSi hal dp r hdp hr first count base vm hfc hb1 hb2 hvm hbal hemp hDL + refine WP.spec_mono (insert_subframesQ (Z := Z) hQi hpc rfl hSi hal hdp hr hfc hb1 hb2 hvm hbal hemp hDL ?_) ?_ + · rintro sj σj Gj k q ⟨Acj, Lstj, Dj, Jj⟩ hSj hk hnull hq1 hq2 hqa hDLj + refine JAtZB.subInsQ (Z := Z.mv Gj Z.vs) Jj.1.1 hpc rfl hSj hal hdp hr hk hnull hq1 hq2 hvm hqa hDLj ?_ + intro sf σf Gf Bf hw hvT hcn hmdb hOther hNew hTCB + have hw' : P1.WritesIn st sj sf (SlotWd Z.th) := + ⟨hw.1, hw.2.1, fun b hb hn => hw.2.2 b hb fun h => hn (Sched.slotSpan_wd Bf.xtop.rel.1 hb h)⟩ + have hV : CnVtx Z.th (L.mem sj) (L.mem sf) := by + refine ⟨id, fun _ hy => hy, fun _ _ _ _ h => h, fun z hz => ⟨z, hz, rfl⟩, ?_⟩ + intro y hy + simp only [id_eq] + by_cases e : y = slotAddr dp.bv (BitVec.ofNat 64 k) + · subst y + rw [hNew, capV_of_capAt hnull] + exact Or.inl rfl + · exact Or.inl (congrArg vkeyF (hOther y hy e)) + have h5 : EptSlotStep Z.th Z.th (L.mem sj) (L.mem sf) := by + intro t ht + have he : cslotAddr (t.bv, Fl4Spec.tcbCnodeIndex 5) = slotOf t 5 := by + show slotAddr t.bv (Fl4Spec.ofBl _) = _ + rw [slotAddr_ofBl, tcbCnodeIndex_blVal 5 (by decide)] + rw [he] + have e := hTCB 5 (by decide) t ht + rw [capAt_capV, capAt_capV] at e + exact Or.inr (Or.inr ⟨ht, eq_of_ok_eq e⟩) + exact ⟨Acj, Lstj, Dj, Jj.ofCn Bf hw' hV hmdb h5 hcn⟩ + · rintro s' ⟨σ', G', hmap, _, _, _, hQ⟩ + exact ⟨σ', G', hmap, hQ⟩ + · rintro res (⟨e, e', h1, he, hD, hs, ha⟩ | ⟨h1, ha, iv, hD, σ', hp, G', Ac', Lst', D', J'⟩) + · exact Or.inl ⟨e, h1, hs, ⟨e', run_liftME_err (run_liftME_err (run_liftME_err hD)), Or.inl he⟩, + hs.symm ▸ ha.symm ▸ J.any arI⟩ + · obtain ⟨s1, σ1, hst, _, _⟩ := hRestart + rw [nd_bind_one hst] at hp + refine Or.inr ⟨_, DecOut.of_eq (run_liftME_ok (run_liftME_ok (run_liftME_ok hD))), σ1, hst, + (.ok [], σ'), ?_, Or.inl ⟨h1, rfl, ha.symm ▸ J'.any arI⟩⟩ + have h : ([], σ') ∈ (Fl4Spec.archNoReturn (Fl4Spec.performDeriveSubframe (Z := Unit) iv) σ1).1 := by + unfold Fl4Spec.archNoReturn + rw [nd_bind_one hp] + exact Set.mem_singleton _ + exact mem_liftE (ε := Unit) (x := ([], σ')) h + +set_option maxHeartbeats 4000000 in +/-- Clearing the hardware accessed bit preserves the VM/EPT relation. -/ +theorem VmEptState.clearAccessed + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {b : U64} + (hb : PtW Z.L1 b ∨ PdW Z.L2 b) (hal : Aligned b) : + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D + (L.wr s b (L.mem s b &&& ~~~32#u64)) a σ := by + let v := L.mem s b &&& ~~~32#u64 + let s1 := L.wr s b v + have B := J.1.1 + have hS := B.xtop.fin.1 + have hP := hS.2 + have hPT := B.xtop.fin.2.2.1 + have hbA : PtWAll Z.L4 Z.L3 Z.L2 Z.L1 b := hb.elim ptWA pdWA + have hbW : VsW Z (L.ksb s) b := Or.inl hbA + have hsingle : WritesIn st s s1 (· = b) := writesIn_wr hal + have hW : WritesIn st s s1 (VsW Z (L.ksb s)) := hsingle.mono fun _ e => e.symm ▸ hbW + have hk := hW.1 + have hpt : PtRel Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s1) σ := by + rcases hb with ⟨q, hq, i, hi, rfl⟩ | ⟨q, hq, i, hi, rfl⟩ + · obtain ⟨f, hf, hR⟩ := hPT.l1 q hq + have h := hPT.upd_l1 hP.pt hq hf hi _ _ (PTERel_clr5 (hR _ hi)) + (fun w hw hne => L.mem_wr_ne hal hw (fun hne' => hne (UScalar.eq_of_val_eq hne').symm)) + (L.mem_wr_same hal) + rwa [Function.update_eq_self, updK_self hf] at h + · obtain ⟨f, hf, hR⟩ := hPT.l2 q hq + have h := hPT.upd_l2 hP.pt hq hf hi _ _ (PDERel_clr5 (hR _ hi)) + (fun w hw hne => L.mem_wr_ne hal hw (fun hne' => hne (UScalar.eq_of_val_eq hne').symm)) + (L.mem_wr_same hal) + rwa [Function.update_eq_self, updK_self hf] at h + have hbO := hP.po b hbA + have hSS : SlotsSame Z.th (L.mem s) (L.mem s1) := by + refine slotsSame_wr (st := st) hP.pl s v hal fun w hw span => ?_ + obtain ⟨q, k, hq, h1, h2, -⟩ := slot_in_object hP.pl hw + have := hbO.2 q k hq + omega + have hbA' := hbA + obtain ⟨q, hq, i, hi, eq⟩ := hbA' + have hSR := TopSR.step0 hS (W := (· = b)) (fun _ e => by + rw [e, eq] + exact table_vobj hP.pt hq hi _) hsingle (OStep.refl' σ) rfl rfl + have hvs : VsRel Z.P (L.mem s1) (L.ksb s1) σ := by + rw [hk] + exact B.xtop.fin.2.1.frame (fun w hw => hsingle.mem_eq (hw.aligned hP.vs) (fun e => by + subst w + exact hP.pv b ⟨q, hq, i, hi, eq⟩ hw)) rfl (fun _ _ => rfl) + obtain ⟨hPl, hCR, hFI, hD, hMO, hIA, -⟩ := B.xtop.rel + have hK : KFoot σ σ := KFoot.refl σ + obtain ⟨hCR1, hFI1, hMO1⟩ := cspace_step hCR hFI hMO hSS hK (hCR.1.of_caps fun _ hy => hSS.capAt hy) + have hdom := dom_of_foot hS (Or.inr (hsingle.mono fun _ e => Or.inr (Or.inr (Or.inl (e.symm ▸ hbA))))) + have hPI := B.xtop.fin.2.2.2.1.of_writes hsingle hP.vs (fun _ e => e.symm ▸ hP.pv b hbA) + have hC := B.xtop.fin.2.2.2.2.of_same hSS rfl + have hX : XTopAt (L := L) AR Z s1 a σ := + ⟨⟨hSR, hvs, hpt, hPI, hC⟩, + ⟨hPl, hCR1, hFI1, by rw [hk]; exact hD.frame hdom.2 rfl rfl, + by rw [hk]; exact hMO1, by rw [hk]; exact hIA, ScApart.of_top hSR.2⟩, + IpcRel.of hSR.1.2.2.1 hSR.1.2.1 (sched_sc hSR.1.1), B.xtop.esa.mono hk (SzKeep.refl σ)⟩ + have hAp : ∀ p k, H p = some k → (∀ z, k ≠ .other z) → b.val + 8 ≤ p.val ∨ p.val + 2 ^ k.bits ≤ b.val := by + intro p k hp hkind + rcases B.vsObjW ⟨B.scOut⟩ hbW hp hkind with hlt | hle + · left + have hH := B.kern.heap + have hbits : 3 ≤ k.bits := by + cases k <;> simp only [P1.HKind.bits] <;> try decide + · exact Nat.le_trans (by decide) (hH.scmin p _ hp) + · exact (hkind _ rfl).elim + have ha := Nat.mod_mod_of_dvd p.val (Nat.pow_dvd_pow 2 hbits) + rw [hH.align p k hp] at ha + change b.val % 8 = 0 at hal + omega + · exact Or.inr hle + have hObj : ∃ o ko, σ.kheap o = some ko ∧ o.toNat ≤ b.val ∧ b.val < o.toNat + 2 ^ Fl4Spec.objBits ko := by + obtain ⟨ao, hqK, hbit, -, -⟩ := B.vsFrSpec (Or.inr hq) + have he := peA_val (tbl_fit (hP.pt q hq)) hi + refine ⟨q.bv, .archObj ao, hqK, ?_, ?_⟩ + · change q.val ≤ b.val + rw [eq, he] + omega + · change b.val < q.val + 2 ^ Fl4Spec.objBits (.archObj ao) + rw [eq, he, hbit] + omega + have hVK := B.vkeep_of hsingle fun w e t ht => by + rw [e] + intro he + have htyp : Z.th t = some .tcb := B.thTcb ht + have ho := hbO.2 t .tcb htyp + rw [he, tVcpuA_val B.ip.e.tcb ht] at ho + simp only [objSize] at ho + omega + have B1 := B.frameWrJCore hal hAp hObj (fun _ hc => B.vsNodeW hbW hc) (B.vsKsW hbW) v hSS hX + exact J.ofVsW (E := Z.vx) B1 hSS hW hVK (VsShr.refl σ) + +set_option maxHeartbeats 4000000 in +/-- The accessed-bit decoder's one-word reply, accounting for the spec restart before that reply. -/ +theorem VmEptState.clearAccessedReply + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {b ct : U64} (hb : PtW Z.L1 b ∨ PdW Z.L2 b) (hal : Aligned b) + (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) (call : Bool) (v : U64) : + vspace.reply1 st (L.wr s b (L.mem s b &&& ~~~32#u64)) ct call v ⦃ s2 => + L.mem s2 (stA ct) ≠ sched.TS_RESTART ∧ + ∀ σ1, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) → + ∃ z ∈ (specTail call ct.bv [v.bv] σ1).1, + RelTopM (L := L) s2 z.2 ∧ VEAny (L := L) arI AR s2 a z.2 ⦄ := by + have J0 := J.clearAccessed arI hb hal + obtain ⟨hcur, x, hk⟩ := J.1.1.curEq hct + have ht := J.1.1.thT ct (J.1.1.xtop.curTcb hcur).1 + have hr := hRun x hk + refine J0.1.1.reply1Prep ht hk call v ?_ + intro s1 B F + let y := if call then Endp.replyTcb x v.bv else x + have hy : (if call then Notif.updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ).kheap ct.bv = some (.tcb y) := by + cases call <;> simp [y, Notif.updK, hk] + have hyr : y.tcbState = .running := by + cases call <;> exact hr + refine WP.spec_mono (B.runRJDB ht hy hyr) ?_ + rintro s2 ⟨Lst2, B2, _, _, hW⟩ + let σy := if call then Notif.updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ + let ko : Fl4Spec.KernelObject := .tcb { y with tcbState := .running } + have hF2 : NatFoot (L := L) Z s1 σy s2 (Notif.stsAct (Notif.updK σy ct.bv ko) ct.bv) := + NatFoot.ofT B.xtop hW (fun _ h => B.tfoot_nh h) + (natK_tcbW hy (Notif.stsAct_kheap (Notif.updK σy ct.bv ko) ct.bv) (by intro h; cases h)) + have J2 := J0.ofNat (V' := Z.vs) B2 (J0.1.1.natTrans F hF2) + have he : Notif.stsAct (Notif.updK (if call then Notif.updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ) + ct.bv (.tcb { y with tcbState := .running })) ct.bv = + Notif.stsAct (Notif.updK σ ct.bv (.tcb { y with tcbState := .running })) ct.bv := by + cases call <;> simp only [Bool.false_eq_true, ↓reduceIte, updK_updK] + rw [he] at B2 J2 + have hk2 : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { y with tcbState := .running })) ct.bv).kheap ct.bv = + some (.tcb { y with tcbState := .running }) := by simp [Notif.stsAct_kheap, Notif.updK_kheap] + refine ⟨B2.notRestart ht hk2 (by intro e; cases e), fun σ1 hst => ?_⟩ + rw [hcur, Notif.setThreadState_eq .restart hk] at hst + have he1 : σ1 = Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hst))).2.symm + subst σ1 + exact ⟨_, specTail_one_after_restart σ ct x call v, B2.xtop.relTop, J2.any arI⟩ + +set_option maxHeartbeats 4000000 in +/-- TestAndClearAccessed on an EPT-mapped cap still walks the native ASID table. -/ +theorem VmEptState.frameTacDisp [PlainStore st] + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct len buf p rt asid va : U64} (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (hsl : AbsSlot Z.th sl) (hc : capV (L.mem s) (cslotAddr sl) = .Frame p sz rt dev true true asid va) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a fl4_abi.label.X86PageTestAndClearAccessed len (cslotAddr sl) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispReplyVE (L := L) arI (AR := AR) on rc σ blk call don + (specDecV fp fl4_abi.label.X86PageTestAndClearAccessed.bv args ci sl + (.Frame p sz rt dev true true asid va) ec buffer) ct s res ⦄ := by + let lbl := fl4_abi.label.X86PageTestAndClearAccessed + have hn : lbl ≠ fl4_abi.label.X86PageMapEPT := by + unfold lbl fl4_abi.label.X86PageTestAndClearAccessed fl4_abi.label.X86PageMapEPT + decide + have hm : lbl ≠ fl4_abi.label.X86PageMap := by + unfold lbl fl4_abi.label.X86PageTestAndClearAccessed fl4_abi.label.X86PageMap + decide + have hu : lbl ≠ fl4_abi.label.X86PageUnmap := by + unfold lbl fl4_abi.label.X86PageTestAndClearAccessed fl4_abi.label.X86PageUnmap + decide + have hg : lbl ≠ fl4_abi.label.X86PageGetAddress := by + unfold lbl fl4_abi.label.X86PageTestAndClearAccessed fl4_abi.label.X86PageGetAddress + decide + have hd : lbl ≠ fl4_abi.label.X86PageDeriveSubframe := by + unfold lbl fl4_abi.label.X86PageTestAndClearAccessed fl4_abi.label.X86PageDeriveSubframe + decide + have hl := frame_label lbl hn + have hi : Fl4Spec.invocationType lbl.bv = .genInvocationLabel .invalidInvocation := by + rw [invocationType_eq, dataToNat_bv, show lbl.val = 58 by simp [lbl, fl4_abi.label.X86PageTestAndClearAccessed]] + rfl + have hma : Fl4Spec.invocationType lbl.bv ≠ .archInvocationLabel .x64PageMap := by rw [hi]; intro h; cases h + have hua : Fl4Spec.invocationType lbl.bv ≠ .archInvocationLabel .x64PageUnmap := by rw [hi]; intro h; cases h + let f : vspace.FrameCap := ⟨p, sz, rt, dev, true, true, asid, va⟩ + let dec := Fl4Spec.NonDetE.liftME Fl4Spec.Fl4InvocationV.base + (Fl4Spec.NonDetE.liftME Fl4Spec.Fl4Invocation.invokeArchObject + (Fl4Spec.NonDetE.liftME Fl4Spec.Fl4ArchInvocation.testAndClearAccessed + (Fl4Spec.decodeTestAndClearAccessed (Z := Unit) (frameACapG f)))) + have hspec : specDecV fp lbl.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer = dec := by + simp only [specDecV, absCap, Fl4Spec.fl4DecodeInvocationV, if_neg (pageMapEpt_label hn), hma, hua, + and_false, ↓reduceIte, Fl4Spec.fl4DecodeInvocation, Fl4Spec.fl4ArchDecodeInvocation, + if_neg (fun h => hd (hl.ds h)), if_pos (hl.tacr rfl)] + rfl + change syscall.decode_invocation st arI s a lbl len _ _ blk call don fp buf ex ⦃ _ ⦄ + rw [hspec] + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + unfold vspace.decode + rw [hct] + simp only [bind_ok, vspace.decode_frame, vspace.as_frame, hm, hu, hg, hd, hn, if_pos (show lbl = fl4_abi.label.X86PageTestAndClearAccessed from rfl), ↓reduceIte] + have B := J.1.1 + obtain ⟨hcur, x, hk⟩ := B.curEq hct + obtain ⟨σ1, hst, -⟩ := setThreadState_eq σ ct.bv x hk .restart + have huv : UserV va := by + have hv := J.2.exte.vtop.2 _ hsl.isSlot p sz rt dev asid va hc + exact Nat.le_of_lt_succ hv + refine WP.spec_bind (tac_gen_leaf (L := L) s σ B.xtop.fin.2.1 B.xtop.fin.2.2.1 B.xtop.fin.1.2.pt + B.xtop.fin.2.2.2.1 ct hct f (fun _ => huv) call + (fun r => VDispReplyVE (L := L) arI (AR := AR) on rc σ blk call don dec ct s (r.1, r.2, a)) + (fun e e' he hD => Or.inl ⟨e, rfl, rfl, ⟨e', run_liftME_err (run_liftME_err (run_liftME_err hD)), he⟩, + J.any arI⟩) ?_) ?_ + · intro b hb hal slot hD v hv + refine WP.spec_mono (J.clearAccessedReply arI hb hal hct hRun call v) ?_ + rintro s2 ⟨hne, htail⟩ + have hst' : Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) := by + rw [hcur] + exact hst + have hsel : ([v.bv], σ1) ∈ (Fl4Spec.performTestAndClearAccessed (Z := Unit) slot σ1).1 := by + simp only [Fl4Spec.performTestAndClearAccessed, Fl4Spec.NonDet.select, Set.mem_setOf_eq, + Set.mem_insert_iff, Set.mem_singleton_iff, and_true] + rcases hv with rfl | rfl + · right + rfl + · left + rfl + exact Or.inr ⟨rfl, hne, _, DecOut.of_eq (run_liftME_ok (run_liftME_ok (run_liftME_ok hD))), σ1, hst', + [v.bv], σ1, mem_liftE (ε := Unit) (x := ([v.bv], σ1)) hsel, htail σ1 hst'⟩ + · rintro ⟨r, s2⟩ h + exact (WP.spec_ok _).2 h + +set_option maxHeartbeats 4000000 in +/-- GetAddress on an EPT-mapped frame replies with the frame's physical address. -/ +theorem VmEptState.frameGetAddrDisp (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct lbl p rt asid va len buf : U64} (hct : sched.cur_thread st s = ok ct) (hr : ZvCtRun σ ct) + (hlbl : FrameLabel lbl lbl.bv) (hg : lbl = fl4_abi.label.X86PageGetAddress) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Frame p sz rt dev true true asid va) + blk call don fp buf ex ⦃ res => + VDispReplyVE (L := L) arI (AR := AR) on rc σ blk call don + (specDecV fp lbl.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer) ct s res ⦄ := by + subst lbl + have hmap : fl4_abi.label.X86PageGetAddress ≠ fl4_abi.label.X86PageMap := by + unfold fl4_abi.label.X86PageGetAddress fl4_abi.label.X86PageMap + decide + have hun : fl4_abi.label.X86PageGetAddress ≠ fl4_abi.label.X86PageUnmap := by + unfold fl4_abi.label.X86PageGetAddress fl4_abi.label.X86PageUnmap + decide + have hds : fl4_abi.label.X86PageGetAddress ≠ fl4_abi.label.X86PageDeriveSubframe := by + unfold fl4_abi.label.X86PageGetAddress fl4_abi.label.X86PageDeriveSubframe + decide + have htac : fl4_abi.label.X86PageGetAddress ≠ fl4_abi.label.X86PageTestAndClearAccessed := by + unfold fl4_abi.label.X86PageGetAddress fl4_abi.label.X86PageTestAndClearAccessed + decide + have hl := hlbl.ga rfl + have hdec : DecOut + (specDecV fp fl4_abi.label.X86PageGetAddress.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer) σ + (.base (.invokeArchObject (.spec (.invokePage (.pageGetAddr p.bv))))) := by + apply DecOut.of_eq + simp only [specDecV, absCap, Fl4Spec.fl4DecodeInvocationV, if_neg (pageMapEpt_label hlbl.native), hl, + Fl4Spec.InvocationLabel.archInvocationLabel.injEq, reduceCtorEq, + ↓reduceIte, Fl4Spec.fl4DecodeInvocation, Fl4Spec.fl4ArchDecodeInvocation, + if_neg (fun h => hds (hlbl.ds h)), if_neg (fun h => htac (hlbl.tac h))] + exact run_liftME_ok (run_liftME_ok (run_liftME_ok + (decodeGetAddr_eq hl args sl dev p.bv (vmRightsOf rt) .vmEptMap (frameSizeOf sz) (some (asid.bv, va.bv)) ec σ))) + obtain ⟨hcur, -, -⟩ := J.1.1.curEq hct + obtain ⟨htcb, x, hk⟩ := J.1.1.xtop.curTcb hcur + have ht := J.1.1.thT ct htcb + obtain ⟨s1, σ1, hst, eσ1, hs1, Ac1, Lst1, D1, B1, F1⟩ := + J.1.1.restartRunJ hct hk (by rw [hr x hk]; rfl) + have J1 := J.ofNat (V' := Z.vs) B1 F1 + have hk1 : σ1.kheap ct.bv = some (.tcb { x with tcbState := .restart }) := by + simp only [eσ1, Notif.stsAct_kheap, Notif.updK_kheap, Function.update_self] + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + unfold vspace.decode + rw [hct] + simp only [bind_ok, vspace.decode_frame, vspace.as_frame, hlbl.native, hmap, hun, ↓reduceIte] + rw [hct, bind_ok, hs1, bind_ok] + unfold layout.paddr + simp only [lift, bind_ok] + refine WP.spec_bind (B1.reply1JFoot ht hk1 rfl call _) ?_ + rintro s2 ⟨hne, σ2, Lst2, hz, B2, F2⟩ + refine (WP.spec_ok _).2 (Or.inr ⟨rfl, hne, _, hdec, σ1, hst, [Fl4Spec.addrFromPPtr p.bv], σ1, ?_, ?_⟩) + · exact mem_liftE (ε := Unit) (x := ([Fl4Spec.addrFromPPtr p.bv], σ1)) rfl + · rw [paddr_bv] at hz + exact ⟨((), σ2), by rw [hz]; exact Set.mem_singleton _, B2.xtop.relTop, + (J1.ofNat (V' := Z.vs) B2 F2).any arI⟩ + +end + +section +open Notif Endp Ipc Sched + +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) + {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +private theorem noPortPreemption (blk call don : Bool) (i : Fl4Spec.Fl4ArchInvocation) (σ : Fl4Spec.State Unit) + (y : Except Unit (List Fl4Spec.Data) × Fl4Spec.State Unit) + (hy : y ∈ ((Fl4Spec.fl4PerformInvocation blk call don (.invokeArchObject i)).run σ).1) : + y.1 ≠ .error () := by + change y ∈ ((Fl4Spec.fl4ArchPerformInvocation i).run σ).1 at hy + have liftOk : ∀ (m : Fl4Spec.SMonad Unit (List Fl4Spec.Data)), + y ∈ ((Fl4Spec.NonDetE.liftE (ε := Unit) m).run σ).1 → y.1 ≠ .error () := by + intro m h + unfold Fl4Spec.NonDetE.liftE at h + rw [ExceptT.run_lift] at h + obtain ⟨x, -, hx⟩ := h + rw [Set.mem_singleton_iff.mp hx] + intro e + cases e + cases i <;> first + | exact liftOk _ hy + | exact liftOk _ (show y ∈ ((Fl4Spec.archPerformInvocation _).run σ).1 from hy) + +set_option maxHeartbeats 4000000 in +/-- Direct I/O-port dispatch is independent of the stored owner and preserves the VM/EPT relation. -/ +theorem VmEptState.ioPortDisp (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hAM : ARMask arI AR) (hAT : P0.ArchTotal arI) + {lbl len buf ct : U64} (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (hval : PortInValAt arI a σ) (args : List U64) (hlen : len.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (sl : Fl4Spec.CslotPtr) (hAs : AbsSlot Z.th sl) {first last owner : U64} + (hcap : capV (L.mem s) (cslotAddr sl) = .IoPort first last owner) + (blk call don fp : Bool) (ex : Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) (on rc : Fl4Spec.ObjRef → Bool) : + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.IoPort first last owner) blk call don fp buf ex ⦃ res => + let m := specDecV fp lbl.bv (args.map (·.bv)) ci sl (.IoPort first last owner) ec buffer + VDispPostVE (L := L) arI AR MR on rc σ blk call don m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) on rc σ blk call don m ct s res ⦄ := by + let m := specDec fp lbl.bv (args.map (·.bv)) ci sl (.IoPort first last 0#u64) ec buffer + have hm : specDecV fp lbl.bv (args.map (·.bv)) ci sl (.IoPort first last owner) ec buffer = + Fl4Spec.NonDetE.liftME Fl4Spec.Fl4InvocationV.base m := rfl + have hc : syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.IoPort first last owner) blk call don fp buf ex = + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.IoPort first last 0#u64) blk call don fp buf ex := by + unfold syscall.decode_invocation + rw [hct] + simp only [bind_ok] + rfl + simp only [hm, hc] + have B := J.1.1 + obtain ⟨hcur, -, -⟩ := B.curEq hct + have htcb := (B.xtop.curTcb hcur).1 + obtain ⟨⟨-, hl, hfl⟩, -⟩ := slot_cap_wf B.xtop hAs hcap + have hC : CurRun σ := fun x hx => by + rw [hcur] at hx + rw [hRun x hx] + rfl + let Q := VEAny (L := L) arI AR + have hX : ∀ s' a' σ', Q s' a' σ' → XTop (L := L) AR s' a' σ' := by + rintro s' a' σ' ⟨_, _, _, Z', _, _, _, _, _, J'⟩ + exact ⟨Z', J'.1.1.xtop⟩ + have hin : ∀ a p z, ∃ v a', arI.port_in a p z = ok (v, a') := by + intro a p z + obtain ⟨⟨v, a'⟩, h, -⟩ := P1.spec_ex_fd (hAT.port_in a p z) + exact ⟨v, a', h⟩ + have hout : ∀ a p z d, ∃ a', arI.port_out a p z d = ok a' := by + intro a p z d + obtain ⟨a', h, -⟩ := P1.spec_ex_fd (hAT.port_out a p z d) + exact ⟨a', h⟩ + have hOut : ∀ (s' : S) (a' : A) (σ1 : Fl4Spec.State Unit) (ms : Fl4Spec.MachineState) (p data : U64) + (x : Fl4Spec.Tcb), σ.kheap ct.bv = some (.tcb x) → + sched.set_thread_state st s ct sched.TS_RESTART = ok s' → + Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) → + ms.underlyingMemory = σ1.machineState.underlyingMemory → + arI.port_out a p ⟨BitVec.ofNat 64 (portSz lbl)⟩ data = ok a' → + Q s' a' { σ1 with machineState := ms } := by + intro s' a' σ1 ms p data x hk hs hst hu hport + obtain ⟨s1, σ2, hh, -, hs1, Ac1, Lst1, D1, B1, F1⟩ := + B.restartRunJ hct hk (by rw [hRun x hk]; rfl) + have es : s1 = s' := ok_inj (hs1.symm.trans hs) + have eσ : σ2 = σ1 := (Prod.mk.inj (Set.singleton_eq_singleton_iff.mp (congrArg Prod.fst (hh.symm.trans hst)))).2 + subst s1 σ2 + have J1 := J.ofNat (V' := Z.vs) B1 F1 + have hp : ArchIrqStep arI a a' := + Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨_, _, _, hport⟩))))) + obtain ⟨Lst2, B2, F2⟩ := B1.msArJ ms a' hu (fun h => hAM _ _ _ h hp) + exact (J1.ofNat (V' := Z.vs) B2 F2).any arI + have hD := decode_invocation_ioportXQ arI Z.th B.xtop.rel.1 s a σ lbl lbl.bv (port_label lbl) + len buf ct hct args hlen hargs hcur htcb B.kern.act first last hfl (by simpa using hl) call hout rfl B.xtop + (show Q s a σ from J.any arI) hOut hX (cslotAddr sl) blk don fp ex ci sl ec buffer (fun hI => by + refine Or.inr (decode_invocation_ioport_inQ arI s a σ B.xtop (J.any arI) lbl hI lbl.bv + ((port_label lbl).1 hI) len buf ct hct args hlen hargs hcur first last hfl (by simpa using hl) + call (cslotAddr sl) blk don fp ex ci sl ec buffer ?_) + intro p + refine WP.spec_mono (B.portInTailJFoot arI hAM hC hct p ⟨BitVec.ofNat 64 (portSz lbl)⟩ call hin + (fun _ => hval)) ?_ + rintro res ⟨hr, hn, hh⟩ + refine ⟨hr, hn, fun σ1 hs => ?_⟩ + obtain ⟨rr, σy, hY, w, hw, hR, _, _, _, B', F'⟩ := hh σ1 hs + exact ⟨rr, σy, hY, w, hw, hR, (J.ofNat (V' := Z.vs) B' F').any arI⟩) + have archOut {inv : Fl4Spec.Fl4Invocation} (h : DecOut m σ inv) : + ∃ i, inv = .invokeArchObject i := DecOut.liftME_inv h + rcases hD with hD | hD + · refine WP.spec_mono hD ?_ + rintro res (⟨e, hr, hs, ⟨e', hde, he⟩, hQ⟩ | ⟨inv, hde, σ1, hs, y, hy, ⟨_, _, hret, -⟩, hQ⟩) + · exact Or.inl (Or.inl ⟨e, hr, hs, ⟨e', run_liftME_err hde, he⟩, hQ⟩) + · obtain ⟨i, rfl⟩ := archOut hde + rcases hret with ⟨hr, hy1⟩ | ⟨_, hy1⟩ + · exact Or.inl (Or.inr ⟨_, hde.liftME, σ1, hs, y, hy, Or.inl ⟨hr, hy1, hQ⟩⟩) + · exact (noPortPreemption blk call don i σ1 y hy hy1).elim + · refine WP.spec_mono hD ?_ + rintro res (⟨e, hr, hs, ⟨e', hde, he⟩, hQ⟩ | ⟨hr, hn, inv, hde, σ1, hs, rr, σy, hy, z, hz, ht, hQ⟩) + · exact Or.inr (Or.inl ⟨e, hr, hs, ⟨e', run_liftME_err hde, he⟩, hQ⟩) + · obtain ⟨i, rfl⟩ := archOut hde + exact Or.inr (Or.inr ⟨hr, hn, _, hde.liftME, σ1, hs, rr, σy, hy, z, hz, ht, hQ⟩) + +end + +/-- **The extended decoder on an untyped cap** (module docstring): `fl4DecodeUntypedInvocationV`'s single outcome, +mapped to `.base (.invokeUntyped _)`. -/ +theorem decV_untyped_run {fp : Bool} {slbl : Fl4Spec.Data} {args : List Fl4Spec.Data} {ci : Fl4Spec.CapRef} + {sl : Fl4Spec.CslotPtr} {excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)} {buffer : Option Fl4Spec.ObjRef} + {dev : Bool} {p : Fl4Spec.ObjRef} {sb fi : Nat} {σ : Fl4Spec.State Unit} + {r : Except Fl4Spec.SyscallError Fl4Spec.UntypedInvocation} + (h : (Fl4Spec.fl4DecodeUntypedInvocationV (Z := Unit) slbl args sl (.untypedCap dev p sb fi) + (excaps.map Prod.fst)).run σ = ({(r, σ)}, False)) : + (Fl4Spec.fl4DecodeInvocationV (Z := Unit) fp slbl args ci sl (.untypedCap dev p sb fi) excaps buffer).run σ = + ({(r.map fun i => Fl4Spec.Fl4InvocationV.base (.invokeUntyped i), σ)}, False) := by + by_cases hg : Fl4Spec.untypedVtxGate slbl args (excaps.map Prod.fst) + · rw [decV_untyped_gate hg σ] + unfold Fl4Spec.fl4DecodeUntypedInvocationV at h + rw [if_pos hg] at h + have h2 : (({((.error (.invalidArgument 0) : Except Fl4Spec.SyscallError Fl4Spec.UntypedInvocation), σ)}, + False) : Set _ × Prop) = ({(r, σ)}, False) := h + simp only [Prod.mk.injEq, Set.singleton_eq_singleton_iff, and_true] at h2 + subst h2; rfl + · rw [fl4DecodeUntypedInvocationV_open hg] at h + unfold Fl4Spec.fl4DecodeInvocationV + dsimp only + rw [if_neg hg] + cases r with + | ok i => exact run_liftME_ok (run_liftME_ok h) + | error e => exact run_liftME_err (run_liftME_err h) + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {V X : Set U64} {XL : U64 → Nat} + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched + +set_option maxHeartbeats 4000000 in +/-- **The decoded untyped invocation through FL4's dispatcher at `VmEptState`** (module docstring): +`VmEptState.decodeUt` with the dispatcher's untyped arm and `decV_untyped_run`. -/ +theorem VmEptState.decodeUtDisp [Fl4Proofs.P1.PlainStore st] {s : S} {ar : A} {σ : Fl4Spec.State Unit} + {MR : A → Fl4Spec.MachineState → Prop} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s ar σ) [VxE Z] (hni : Entered σ) + (hA : P0.ArchTotal arI) (hag : ∀ r, arI.virtualization ar = ok r → r.val = Fl4Spec.virtKind.code) + (hVA : ZvVirtAgree arI) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (lbl : U64) (slbl : Fl4Spec.Data) + (hlbl : Fl4Spec.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf ct : U64) (hct : sched.cur_thread st s = ok ct) (args : List U64) + (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + {pp : U64} {rs : Nat} {idx : List Bool} (hpp : Z.th pp = some (.cnode rs)) (hidx : idx.length = rs) + {p sb fi : U64} {dev : Bool} (hcap : capAt (L.mem s) (cslotAddr (pp.bv, idx)) = ok (.Untyped p sb fi dev)) + (extra : Aeneas.Std.Array obj.Slot 3#usize) (x0 : U64) (hx0 : Aeneas.Std.Array.index_usize extra 0#usize = ok x0) + (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (hex : ExtraRel Z.th (L.mem s) x0 (excaps.map Prod.fst)) + (hfan : Fl4Spec.retypeFanOutLimit = 256#64) (hc0 : Z.c = 0#u64) + (hBO : BufObjHyp Z.B σ) (hAF : ArchFitHyp H σ) (hRU : RegionUnrefAt (L := L) H Cs D s) + (hUZ : dev = false → UtZero (L.mem s) Z.G σ) (hUN : dev = false → UtNodesJ (L.mem s) Z.G (L.ksb s)) + (hDA : dev = true → DevApart (L := L) Z.th H Z.G Cs s) (hDF : dev = true → DevFreeT (L.mem s) Z.G σ) + (hGP : dev = true → DevGpm (L.mem s) Z.G σ) + (hAK : ARKeep arI AR) (hnd : Fl4Spec.numDomains = 1) (hMP : MachPlat arI MR) (hPA : PPPlatA arI AR) + (hrcb : Fl4Spec.resetChunkBits = 16) + (hRd0 : σ.consumedTime = 0 → ∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → Fl4Spec.scActive y = true → + Fl4Spec.refillReady σ.curTime (Fl4Spec.refillHd y) = true) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hVM : (∀ y, ¬ Mdb.Desc Z.G.par y (cslotAddr (pp.bv, idx))) → ∀ s1, + sched.set_thread_state st s ct sched.TS_RESTART = ok s1 → + Vs.VsReachMiss p.val (p.val + 2 ^ sb.val) (L.mem s1) (L.ksb s1) + (Vs.NeedR Z.th (L.mem s1) 5) (Vs.NeedR Z.th (L.mem s1) 4) (Vs.NeedR Z.th (L.mem s1) 3) + (Vs.NeedR Z.th (L.mem s1) 2) (Vs.NeedR Z.th (L.mem s1) 1)) + (hMR : MR ar σ.machineState) (hVT : ValidMachineTime σ) (hVIM : ValidIrqMasks σ) + (onCore remoteCur : Fl4Spec.ObjRef → Bool) (blk call don fp : Bool) (ci : Fl4Spec.CapRef) + (buffer : Option Fl4Spec.ObjRef) : + syscall.decode_invocation st arI s ar lbl length (cslotAddr (pp.bv, idx)) (.Untyped p sb fi dev) blk call don fp + buf extra ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV fp slbl (args.map UScalar.bv) ci (pp.bv, idx) (.Untyped p sb fi dev) excaps buffer) s res ⦄ := by + rw [decode_invocation_untyped_eq arI s ar lbl length _ p sb fi dev blk call don fp buf extra ct hct] + refine WP.spec_mono (J.decodeUt hni hA hag hVA hCap lbl slbl hlbl length buf ct hct args hlen hargs hpp hidx hcap + extra x0 hx0 (excaps.map Prod.fst) hex hfan hc0 hBO hAF hRU hUZ hUN hDA hDF hGP hAK hnd hMP hPA hrcb hRd0 hnq hVM + hMR hVT hVIM) ?_ + rintro res (⟨e, e', rfl, hm, he⟩ | ⟨inv, hm, σ1, hst, hr⟩) + · exact Or.inl ⟨e, rfl, rfl, ⟨e', decV_untyped_run hm, Or.inl he⟩, J.any arI⟩ + · refine Or.inr ⟨_, DecOut.of_eq (decV_untyped_run hm), σ1, hst, ?_⟩ + rcases hr with ⟨h1, σ', hy, V', X', XL', Z', H', Cs', Ac', Lst', D', hJ⟩ | ⟨h1, σ', hy, V', X', XL', hP⟩ + · exact ⟨_, perfNil_ok hy, Or.inl ⟨h1, rfl, hJ.any arI⟩⟩ + · exact ⟨_, perfNil_err hy, Or.inr ⟨h1, rfl, V', X', XL', hP⟩⟩ + +end + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched Fl4Proofs.P3.Ipc Fl4Proofs.P1 + +/-- **Every VM-side arm of FL4's dispatcher at `VmEptState`, in `VDispPostVE`'s form** (module docstring): one +field per existing decode top, each with that top's own hypotheses. -/ +structure VDispAll (AR : A → Fl4Spec.Cr3 → Prop) (MR : A → Fl4Spec.MachineState → Prop) + (onCore remoteCur : Fl4Spec.ObjRef → Bool) (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) + (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop where + /-- CNode labels 25–32 (`VmEptState.cnodeDecodeAll`). -/ + cnode : ∀ (_hD : P0.StoreTotal st ∧ P0.ArchTotal arI ∧ MRKeepD arI AR) (_hK : ARKeep arI AR) + (_hticks : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv ∧ + ∀ (a : A) (v : U64), arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + (_hnd : Fl4Spec.numDomains = 1) (_hM : MachPlatC arI MR) (_hKD : MRKeepD arI MR) (_hPA : PPPlatA arI AR) + (_hAM : ARMask arI AR) [VxE Z] (_hsg : SpecGlob σ) (_hp0 : PPR0 σ) (_hmv : MRV MR a σ) + (_hQ : ∀ e, EpQPre σ e) (lbl : U64) (_hrd : 25 ≤ lbl.val ∧ lbl.val ≤ 32) (slbl : Fl4Spec.Data) + (_hlbl : Fl4Spec.genInvocationType slbl = cnodeLabelOf lbl) (length buf ct : U64) + (_hct : sched.cur_thread st s = ok ct) (args : List U64) (_hlen : length.val = args.length) + (_hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (sl : Fl4Spec.CslotPtr) (_hAs : AbsSlot Z.th sl) (p r gs g : U64) + (_hsc : capV (L.mem s) (cslotAddr sl) = .CNode p r gs g) (extra : Aeneas.Std.Array obj.Slot 3#usize) + (x0 x1 : U64) (_hx0 : Aeneas.Std.Array.index_usize extra 0#usize = ok x0) + (_hx1 : Aeneas.Std.Array.index_usize extra 1#usize = ok x1) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) + (_hex : ExtraRel2 Z.th (L.mem s) x0 x1 (excaps.map Prod.fst)) (blk call don fp : Bool) (ci : Fl4Spec.CapRef) + (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl length (cslotAddr sl) (.CNode p r gs g) blk call don fp buf extra + ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV fp slbl (args.map UScalar.bv) ci sl (.CNode p r gs g) excaps buffer) s res ⦄ + /-- A VCPU cap, including replies written by the decoder. -/ + vcpu : ∀ (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hAT : P0.ArchTotal arI) {p lbl len buf ct : U64} (hp : p ∈ V) (hcan : Canonical p) + (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (blk call don fp : Bool) (hbuf : BufOut V buf) (ex : Array obj.Slot 3#usize) + (args : List Fl4Spec.Data) (hargs : VArgs st s ct buf len args) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (he : ExtraOK Z.th (L.mem s) ex ec) + (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Vcpu p) blk call don fp buf ex ⦃ res => + let m := specDecV fp lbl.bv args ci sl (.Vcpu p) ec buffer + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) onCore remoteCur σ blk call don m ct s res ⦄ + /-- Direct invocation of an I/O port, including ports owned by a VCPU. -/ + ioPort : ∀ (hAM : ARMask arI AR) (hAT : P0.ArchTotal arI) {lbl len buf ct : U64} + (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) (hval : PortInValAt arI a σ) + (args : List U64) (hlen : len.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (sl : Fl4Spec.CslotPtr) (hAs : AbsSlot Z.th sl) {first last owner : U64} + (hcap : capV (L.mem s) (cslotAddr sl) = .IoPort first last owner) + (blk call don fp : Bool) (ex : Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.IoPort first last owner) blk call don fp buf ex ⦃ res => + let m := specDecV fp lbl.bv (args.map (·.bv)) ci sl (.IoPort first last owner) ec buffer + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) onCore remoteCur σ blk call don m ct s res ⦄ + /-- A native PageMap on an EPT-mapped frame is rejected. -/ + frameMapReject : ∀ {ct : U64} (hct : sched.cur_thread st s = ok ct) (p rt asid va len buf : U64) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a fl4_abi.label.X86PageMap len (cslotAddr sl) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don (specDecV fp fl4_abi.label.X86PageMap.bv + args ci sl (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ + /-- An EPT-mapped frame at GetAddress, which replies in the decoder. -/ + frameGetAddr : ∀ {ct lbl p rt asid va len buf : U64} (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (hlbl : FrameLabel lbl lbl.bv) (hg : lbl = fl4_abi.label.X86PageGetAddress) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Frame p sz rt dev true true asid va) + blk call don fp buf ex ⦃ res => + VDispReplyVE (L := L) arI (AR := AR) onCore remoteCur σ blk call don + (specDecV fp lbl.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer) ct s res ⦄ + /-- Labels outside the frame decoder on an EPT-mapped frame. -/ + frameOther : ∀ {ct lbl : U64} (hct : sched.cur_thread st s = ok ct) (hlbl : FrameLabel lbl lbl.bv) + (hm : lbl ≠ fl4_abi.label.X86PageMap) (hu : lbl ≠ fl4_abi.label.X86PageUnmap) + (hg : lbl ≠ fl4_abi.label.X86PageGetAddress) (ht : lbl ≠ fl4_abi.label.X86PageTestAndClearAccessed) + (hd : lbl ≠ fl4_abi.label.X86PageDeriveSubframe) (p rt asid va len buf : U64) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr sl) (.Frame p sz rt dev true true asid va) + blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV fp lbl.bv args ci sl (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ + /-- A large EPT-mapped frame can derive ordinary unmapped subframe caps. -/ + frameDerive : ∀ {ct len buf pc p rt asid va : U64} {idx : List Bool} (hpc : Z.th pc = some (.cnode idx.length)) + (hct : sched.cur_thread st s = ok ct) + {sz : capability.FrameSize} {dev : Bool} + (hc : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Frame p sz rt dev true true asid va)) + (args : List U64) (hlen : len.val = args.length) + (hargs : ∀ i : U64, ∀ v, args[i.val]? = some v → msg.syscall_arg st s ct buf i = ok v) + (blk call don fp : Bool) (ex : Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (hex : JVsExtra (L := L) Z s ex ec) + (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a fl4_abi.label.X86PageDeriveSubframe len (cslotAddr (pc.bv, idx)) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV fp fl4_abi.label.X86PageDeriveSubframe.bv (args.map UScalar.bv) ci (pc.bv, idx) + (.Frame p sz rt dev true true asid va) ec buffer) s res ⦄ + /-- TestAndClearAccessed on an EPT-mapped cap still walks the native ASID table. -/ + frameTac : ∀ {ct len buf p rt asid va : U64} (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (sz : capability.FrameSize) (dev blk call don fp : Bool) (sl : Fl4Spec.CslotPtr) + (hsl : AbsSlot Z.th sl) (hc : capV (L.mem s) (cslotAddr sl) = .Frame p sz rt dev true true asid va) + (ex : Array obj.Slot 3#usize) (args : List Fl4Spec.Data) (ci : Fl4Spec.CapRef) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a fl4_abi.label.X86PageTestAndClearAccessed len (cslotAddr sl) + (.Frame p sz rt dev true true asid va) blk call don fp buf ex ⦃ res => + VDispReplyVE (L := L) arI (AR := AR) onCore remoteCur σ blk call don + (specDecV fp fl4_abi.label.X86PageTestAndClearAccessed.bv args ci sl + (.Frame p sz rt dev true true asid va) ec buffer) ct s res ⦄ + /-- An invoked `Ept` cap, every label (`VmEptState.eptDecode`). -/ + ept : ∀ {lbl len ptr level asid va : U64} {m : Bool} (block call cd fp : Bool) (buf : U64) + (ex : Array obj.Slot 3#usize) {pc : U64} {r : Nat} (_hpc : Z.th pc = some (.cnode r)) {idx : List Bool} + (_hidx : idx.length = r) (_hcx : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Ept ptr level m asid va)) + (args : List Fl4Spec.Data) (_hV : VArgs st s (L.curW s) buf len args) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (_hex : ExtraSRel Z.th (L.mem s) (exAt ex 0) ec) + (fp' : Bool) (cref : Fl4Spec.CapRef) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr (pc.bv, idx)) (.Ept ptr level m asid va) block call cd fp + buf ex ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ block call cd + (specDecV fp' lbl.bv args cref (pc.bv, idx) (.Ept ptr level m asid va) ec buffer) s res ⦄ + /-- A `Frame` cap at `X86PageMapEPT` (`VmEptState.frameEptDecode`). -/ + frameEpt : ∀ {lbl len ptr rights asid va : U64} {size : capability.FrameSize} {dev m ep : Bool} + (_hlb : lbl.val = Fl4Spec.fl4PageMapEptLabel) (block call cd fp : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) + {pc : U64} {r : Nat} (_hpc : Z.th pc = some (.cnode r)) {idx : List Bool} (_hidx : idx.length = r) + (_hcx : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Frame ptr size rights dev m ep asid va)) + (args : List Fl4Spec.Data) (_hV : VArgs st s (L.curW s) buf len args) + (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (_hex : ExtraSRel Z.th (L.mem s) (exAt ex 0) ec) + (fp' : Bool) (cref : Fl4Spec.CapRef) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr (pc.bv, idx)) (.Frame ptr size rights dev m ep asid va) + block call cd fp buf ex ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ block call cd + (specDecV fp' lbl.bv args cref (pc.bv, idx) (.Frame ptr size rights dev m ep asid va) ec buffer) s res ⦄ + /-- An EPT-mapped `Frame` cap at `X86PageUnmap` (`VmEptState.frameUnmapDecode`). -/ + frameUnmap : ∀ {lbl len ptr rights asid va : U64} {size : capability.FrameSize} {dev : Bool} + (_hl : lbl = fl4_abi.label.X86PageUnmap) (block call cd fp : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) + {pc : U64} {r : Nat} (_hpc : Z.th pc = some (.cnode r)) {idx : List Bool} (_hidx : idx.length = r) + (_hcx : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Frame ptr size rights dev true true asid va)) + (args : List Fl4Spec.Data) (ec : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) + (fp' : Bool) (cref : Fl4Spec.CapRef) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len (cslotAddr (pc.bv, idx)) (.Frame ptr size rights dev true true asid va) + block call cd fp buf ex ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ block call cd + (specDecV fp' lbl.bv args cref (pc.bv, idx) (.Frame ptr size rights dev true true asid va) ec buffer) s res ⦄ + /-- An `AsidPool` cap at `X86ASIDPoolAssign` with an unmapped level-0 `Ept` first extra cap + (`VmEptState.poolAssignDecode`). -/ + pool : ∀ (ptr base : U64) {slot : U64} (_hsl : IsSlot Z.th slot) + (_hcap : capAt (L.mem s) slot = ok (.AsidPool ptr base)) {lbl : U64} (_hl : lbl = fl4_abi.label.X86ASIDPoolAssign) + (len : U64) (block call cd fp : Bool) (buf : U64) (ex : Array obj.Slot 3#usize) {pc : U64} {r : Nat} + (_hpc : Z.th pc = some (.cnode r)) {idx : List Bool} (_hidx : idx.length = r) + (_hex : vspace.extra ex 0#usize = ok (some (cslotAddr (pc.bv, idx)))) + {ptr1 asid0 va0 : U64} (_hcx : capAt (L.mem s) (cslotAddr (pc.bv, idx)) = ok (.Ept ptr1 0#u64 false asid0 va0)) + (args : List Fl4Spec.Data) (fp' : Bool) (cref : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) + (rest : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl len slot (.AsidPool ptr base) block call cd fp buf ex ⦃ res => + VDispPostVE (L := L) arI AR MR onCore remoteCur σ block call cd + (specDecV fp' lbl.bv args cref sl (.AsidPool ptr base) + ((absCap (.Ept ptr1 0#u64 false asid0 va0), (pc.bv, idx)) :: rest) buffer) s res ⦄ + /-- `TCBSetEPTRoot` on an invoked `Thread` cap (`VmEptState.decodeSetEpt`). -/ + setEpt : ∀ (length slot : U64) (p : U64) (blk call don : Bool) (buf : U64) + (extra : Aeneas.Std.Array obj.Slot 3#usize) (_hstall : smp.remote_tcb_stall st arI s a p = ok (s, a)) (x0 : U64) + (_hx0 : Aeneas.Std.Array.index_usize extra 0#usize = ok x0) + (cps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (_hex : ExtraSRel Z.th (L.mem s) x0 cps) + (slbl : Fl4Spec.Data) (_hl : Fl4Spec.dataToNat slbl = Fl4Spec.fl4SetEptRootLabel) (args : List Fl4Spec.Data) + (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) (buffer : Option Fl4Spec.ObjRef) + (_ht : Z.th p = some .tcb) (_hsl : IsSlot Z.th slot) (_hcs : capV (L.mem s) slot = .Thread p), + syscall.decode_invocation st arI s a fl4_abi.label.TCBSetEPTRoot length slot (.Thread p) blk call don false buf + extra ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV false slbl args ci sl (.Thread p) cps buffer) s res ⦄ + /-- An invoked `Untyped` cap, every label (`VmEptState.decodeUtDisp`). -/ + ut : ∀ [VxE Z] (_hAT : P0.ArchTotal arI) (_hag : ∀ r, arI.virtualization a = ok r → r.val = Fl4Spec.virtKind.code) + (_hCap : ∀ a', VirtSanEq.CapAgree arI a') (lbl : U64) (slbl : Fl4Spec.Data) + (_hlbl : Fl4Spec.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf ct : U64) (_hct : sched.cur_thread st s = ok ct) (args : List U64) + (_hlen : length.val = args.length) + (_hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + {pp : U64} {rs : Nat} {idx : List Bool} (_hpp : Z.th pp = some (.cnode rs)) (_hidx : idx.length = rs) + {p sb fi : U64} {dev : Bool} (_hcap : capAt (L.mem s) (cslotAddr (pp.bv, idx)) = ok (.Untyped p sb fi dev)) + (extra : Aeneas.Std.Array obj.Slot 3#usize) (x0 : U64) + (_hx0 : Aeneas.Std.Array.index_usize extra 0#usize = ok x0) + (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (_hex : ExtraRel Z.th (L.mem s) x0 (excaps.map Prod.fst)) + (_hfan : Fl4Spec.retypeFanOutLimit = 256#64) (_hc0 : Z.c = 0#u64) + (_hBO : BufObjHyp Z.B σ) (_hAF : ArchFitHyp H σ) (_hRU : RegionUnrefAt (L := L) H Cs D s) + (_hUZ : dev = false → UtZero (L.mem s) Z.G σ) (_hUN : dev = false → UtNodesJ (L.mem s) Z.G (L.ksb s)) + (_hDA : dev = true → DevApart (L := L) Z.th H Z.G Cs s) (_hDF : dev = true → DevFreeT (L.mem s) Z.G σ) + (_hGP : dev = true → DevGpm (L.mem s) Z.G σ) + (_hAK : ARKeep arI AR) (_hnd : Fl4Spec.numDomains = 1) (_hMP : MachPlat arI MR) (_hPA : PPPlatA arI AR) + (_hrcb : Fl4Spec.resetChunkBits = 16) + (_hRd0 : σ.consumedTime = 0 → ∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → Fl4Spec.scActive y = true → + Fl4Spec.refillReady σ.curTime (Fl4Spec.refillHd y) = true) + (_hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (_hVM : (∀ y, ¬ Mdb.Desc Z.G.par y (cslotAddr (pp.bv, idx))) → ∀ s1, + sched.set_thread_state st s ct sched.TS_RESTART = ok s1 → + Vs.VsReachMiss p.val (p.val + 2 ^ sb.val) (L.mem s1) (L.ksb s1) + (Vs.NeedR Z.th (L.mem s1) 5) (Vs.NeedR Z.th (L.mem s1) 4) (Vs.NeedR Z.th (L.mem s1) 3) + (Vs.NeedR Z.th (L.mem s1) 2) (Vs.NeedR Z.th (L.mem s1) 1)) + (_hMR : MR a σ.machineState) (_hVT : ValidMachineTime σ) (_hVIM : ValidIrqMasks σ) + (blk call don fp : Bool) (ci : Fl4Spec.CapRef) (buffer : Option Fl4Spec.ObjRef), + syscall.decode_invocation st arI s a lbl length (cslotAddr (pp.bv, idx)) (.Untyped p sb fi dev) blk call don fp + buf extra ⦃ res => VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don + (specDecV fp slbl (args.map UScalar.bv) ci (pp.bv, idx) (.Untyped p sb fi dev) excaps buffer) s res ⦄ + +set_option maxHeartbeats 4000000 in +/-- **Every existing `VmEptState` decode top through FL4's dispatcher, in `VDispPostVE`'s form** (module +docstring). Shared premises: `ArchRefines arI AR` [P], `ZvVirtAgree arI` [P] (existing); the rest per field. -/ +theorem VmEptState.decodeDisp [Fl4Proofs.P1.PlainStore st] {AR : A → Fl4Spec.Cr3 → Prop} + {MR : A → Fl4Spec.MachineState → Prop} (hA : ArchRefines arI AR) (hVA : ZvVirtAgree arI) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + (onCore remoteCur : Fl4Spec.ObjRef → Bool) : + VDispAll (L := L) arI AR MR onCore remoteCur V X XL Z H Cs Ac Lst D s a σ := by + constructor + · intro hD hK hticks hnd hM hKD hPA hAM _ hsg hp0 hmv hQ lbl hrd slbl hlbl length buf ct hct args hlen hargs sl + hAs p r gs g hsc extra x0 x1 hx0 hx1 excaps hex blk call don fp ci buffer + exact WP.spec_mono (VmEptState.cnodeDecodeAll arI hA hD hK hVA hticks hnd hM hKD hPA hAM J hni hsg hp0 hmv hQ + lbl hrd slbl hlbl length buf ct hct args hlen hargs sl hAs p r gs g hsc extra x0 x1 hx0 hx1 excaps hex + blk call don fp ci buffer) fun _ h => h.toDisp arI J onCore remoteCur blk call don + · intro hK hSy hCap hAT p lbl len buf ct hp hcan hct hRun blk call don fp hbuf ex args hargs ec he ci sl buffer + exact J.vcpuDisp hK hSy hVA hCap hAT hp hcan hct hRun blk call don fp hbuf ex args hargs ec he + onCore remoteCur ci sl buffer + · intro hAM hAT lbl len buf ct hct hRun hval args hlen hargs sl hAs first last owner hcap blk call don fp ex ci ec buffer + exact J.ioPortDisp arI hAM hAT hct hRun hval args hlen hargs sl hAs hcap blk call don fp ex ci ec buffer onCore remoteCur + · intro ct hct p rt asid va len buf sz dev blk call don fp sl ex args ci ec buffer + exact J.frameMapEptReject arI hct p rt asid va len buf sz dev blk call don fp sl ex args ci ec buffer onCore remoteCur + · intro ct lbl p rt asid va len buf hct hRun hlbl hg sz dev blk call don fp sl ex args ci ec buffer + exact J.frameGetAddrDisp arI hct hRun hlbl hg sz dev blk call don fp sl ex args ci ec buffer onCore remoteCur + · intro ct lbl hct hlbl hm hu hg ht hd p rt asid va len buf sz dev blk call don fp sl ex args ci ec buffer + exact J.frameOtherDisp arI hct hlbl hm hu hg ht hd p rt asid va len buf sz dev blk call don fp sl ex args ci ec buffer + onCore remoteCur + · intro ct len buf pc p rt asid va idx hpc hct sz dev hc args hlen hargs blk call don fp ex ci ec hex buffer + exact J.frameDeriveDisp arI hni hpc hct hc args hlen hargs blk call don fp ex ci ec hex buffer onCore remoteCur + · intro ct len buf p rt asid va hct hRun sz dev blk call don fp sl hsl hc ex args ci ec buffer + exact J.frameTacDisp arI hct hRun sz dev blk call don fp sl hsl hc ex args ci ec buffer onCore remoteCur + · intro lbl len ptr level asid va m block call cd fp buf ex pc r hpc idx hidx hcx args hV ec hex fp' cref buffer + exact WP.spec_mono (J.eptDecode hni hA block call cd fp buf ex hpc hidx hcx args hV ec hex fp' cref buffer) + fun _ h => h.toDisp arI J hni onCore remoteCur block call cd + · intro lbl len ptr rights asid va size dev m ep hlb block call cd fp buf ex pc r hpc idx hidx hcx args hV ec hex + fp' cref buffer + exact WP.spec_mono (J.frameEptDecode hni hVA hlb block call cd fp buf ex hpc hidx hcx args hV ec hex fp' cref + buffer) fun _ h => h.toDisp arI J hni onCore remoteCur block call cd + · intro lbl len ptr rights asid va size dev hl block call cd fp buf ex pc r hpc idx hidx hcx args ec fp' cref buffer + exact WP.spec_mono (J.frameUnmapDecode hni hA hl block call cd fp buf ex hpc hidx hcx args ec fp' cref buffer) + fun _ h => h.toDisp arI J hni onCore remoteCur block call cd + · intro ptr base slot hsl hcap lbl hl len block call cd fp buf ex pc r hpc idx hidx hex ptr1 asid0 va0 hcx args fp' + cref sl rest buffer + exact WP.spec_mono (J.poolAssignDecode hni ptr base hsl hcap hl len block call cd fp buf ex hpc hidx hex hcx args + fp' cref sl rest buffer) fun _ h => h.toDisp arI J hni onCore remoteCur block call cd + · intro length slot p blk call don buf extra hstall x0 hx0 cps hex slbl hl args ci sl buffer ht hsl hcs + exact WP.spec_mono (VmEptState.decodeSetEpt arI hA J hni length slot p blk call don buf extra hstall x0 hx0 cps + hex slbl hl args ci sl buffer ht hsl hcs) fun _ h => h.toDisp arI J onCore remoteCur blk call don + · intro _ hAT hag hCap lbl slbl hlbl length buf ct hct args hlen hargs pp rs idx hpp hidx p sb fi dev hcap extra x0 + hx0 excaps hex hfan hc0 hBO hAF hRU hUZ hUN hDA hDF hGP hAK hnd hMP hPA hrcb hRd0 hnq hVM hMR hVT hVIM blk call + don fp ci buffer + exact J.decodeUtDisp hni hAT hag hVA hCap lbl slbl hlbl length buf ct hct args hlen hargs hpp hidx hcap extra x0 + hx0 excaps hex hfan hc0 hBO hAF hRU hUZ hUN hDA hDF hGP hAK hnd hMP hPA hrcb hRd0 hnq hVM hMR hVT hVIM onCore + remoteCur blk call don fp ci buffer + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmEnterSetup.lean b/proofs/Fl4Proofs/P3/VmEnterSetup.lean new file mode 100644 index 000000000..424091a5d --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmEnterSetup.lean @@ -0,0 +1,292 @@ +import Fl4Proofs.P3.JAtZV3RepBr0 +import Fl4Proofs.P3.JAtZV3Vmcb +import Fl4Proofs.P2.AccessLvmEnterV + +/-! +The VMEnter writes to the bound VCPU before the notification check. +The VMX capability agreement is `VirtSanEq.CapAgree` [P] and the +backend code agreement is `ZvVirtAgree` [P]. +-/ + +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core Fl4Spec Notif Endp Fl4Proofs.P3.Vs +noncomputable section + +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] +variable {A : Type} {arI : machine.Arch A} {AR : A → Cr3 → Prop} +variable {s sA : S} {a : A} {σ σA : State Unit} +variable {V : Set U64} {Z : XSets} {H : P1.Heap} +variable {Cs Ac D : Set U64} {Lst : U64 → List U64} + +private theorem enterPrimary (hCap : VirtSanEq.CapAgree arI a) (ctl : U64) : + ∃ r, vcpu.sanitize_vmcs arI a vcpu.vmx.CONTROL_PRIMARY_PROCESSOR_CONTROLS ctl = ok r ∧ + (core.result.Result.unwrap_or r 2996308992#u64).bv = vmxEnterPrimary ctl.bv := by + obtain ⟨r, hr, hrel⟩ := + VirtSanEq.sanitize_vmcs_rel hCap vcpu.vmx.CONTROL_PRIMARY_PROCESSOR_CONTROLS ctl + rw [v3_vmx_ids.2.1] at hrel + refine ⟨r, hr, ?_⟩ + unfold vmxEnterPrimary + cases r <;> cases e : sanitizeVmcs Vmx.controlPrimaryProcessorControls ctl.bv <;> + simp_all [VirtSanEq.WordResRel, core.result.Result.unwrap_or, primaryForced] + +/-- VMX staging writes the sanitized primary controls and the two other +VMEnter fields. The saved-exit flags are cleared by the subsequent step. -/ +private theorem VmBaseF.enterVmxFields + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) + {v t : U64} (hv : v ∈ V) {vs : VcpuState} (hk : σ.kheap v.bv = some (.archObj (.vcpu vs))) + (hvk : virtKind = .vmx) {i : U64} (hi : i ≠ 2#u64) (hCap : VirtSanEq.CapAgree arI a) (ip ctl intr : U64) : + Fl4Proofs.P2.enterBlk st arI s a v ip ctl intr i t ⦃ s' => + let vs1 := vs.set virtKind (.vmcs Vmx.guestRip) ip.bv + let vs2 := vs1.set virtKind (.vmcs Vmx.controlPrimaryProcessorControls) (vmxEnterPrimary ctl.bv) + let vs3 := vs2.set virtKind (.vmcs Vmx.controlEntryInterruptionInfo) ((intr &&& 4294967295#u64).bv) + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s' a (updK σ v.bv (.archObj (.vcpu vs3))) ⦄ := by + obtain ⟨r, hr, he⟩ := enterPrimary hCap ctl + obtain ⟨hRip, hCtl, hIntr, -⟩ := v3_vmx_ids + have hRipW : Vmx.writable Vmx.guestRip = true := by decide + have hCtlW : Vmx.writable Vmx.controlPrimaryProcessorControls = true := by decide + have hIntrW : Vmx.writable Vmx.controlEntryInterruptionInfo = true := by decide + unfold Fl4Proofs.P2.enterBlk + rw [if_neg hi] + simp only [vcpu.write_vmcs, v3_vmcs_addr, hRip, hCtl, hIntr, bind_ok, L.write_eq, + hr, VirtSanEq.PRIMF_eq, lift, WP.spec_ok] + have J1 := J.vmcsWr hv hvk (f := Vmx.guestRip) hRipW ip hk + have J2 := J1.vmcsWr hv hvk (f := Vmx.controlPrimaryProcessorControls) hCtlW (core.result.Result.unwrap_or r 2996308992#u64) (by simp only [updK, Function.update_self] <;> rfl) + have J3 := J2.vmcsWr hv hvk (f := Vmx.controlEntryInterruptionInfo) hIntrW (intr &&& 4294967295#u64) (by simp only [updK, Function.update_self] <;> rfl) + simpa only [he, zv_updK_updK] using J3 + + +private theorem svmRipRead : vcpu.svm.RIP = ok 1400#u64 := + P1.eq_of_spec_fd P0.Consts.vcpu.svm.RIP.spec + +private theorem svmShl32 (v : U64) : v <<< 32#i32 = ok ⟨v.bv <<< (32 : Nat)⟩ := by + rw [shl_eq v 32#i32 (by decide) (by decide)] <;> rfl + +set_option maxRecDepth 2048 in +/-- The three staging writes before clearing the saved-exit flags. -/ +private theorem VmBaseF.enterSvmFields + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) + {v t : U64} (hv : v ∈ V) {vs : VcpuState} (hk : σ.kheap v.bv = some (.archObj (.vcpu vs))) + (hvk : virtKind = .svm) (ht : t ∈ Z.T) {x : Tcb} (hxt : σ.kheap t.bv = some (.tcb x)) + (ip ctl intr : U64) : + Fl4Proofs.P2.enterBlk st arI s a v ip ctl intr 2#u64 t ⦃ s' => + let vs1 := vs.set virtKind (.vmcb Svm.rip) ip.bv + let vs2 := vs1.set virtKind (.vmcb Svm.interceptExc) + (svmEnterIntercepts (vs1.get virtKind (.vmcb Svm.interceptExc)) ctl.bv) + let event := if Fl4Proofs.P3.repFull x then + (vs.get virtKind (.vmcb Svm.eventInj) &&& ~~~0xffff_ffff) ||| (intr.bv &&& 0xffff_ffff) + else intr.bv + let vs3 := vs2.set virtKind (.vmcb Svm.eventInj) (event &&& Svm.eventMask) + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s' a (updK σ v.bv (.archObj (.vcpu vs3))) ⦄ := by + let sr := L.wr s (core.num.U64.wrapping_add v 1400#u64) ip + let vs1 := vs.set virtKind (.vmcb Svm.rip) ip.bv + have hrW : Svm.writable Svm.rip = true := by decide + have hcW : Svm.writable Svm.interceptExc = true := by decide + have heW : Svm.writable Svm.eventInj = true := by decide + have h1 : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D sr a + (updK σ v.bv (.archObj (.vcpu vs1))) := + J.vmcbWr hv hvk (f := Svm.rip) hrW (by decide) + (x := core.num.U64.wrapping_add v 1400#u64) rfl ip hk + have hq1 : (updK σ v.bv (.archObj (.vcpu vs1))).kheap v.bv = some (.archObj (.vcpu vs1)) := + by simp only [updK, Function.update_self] + let old := L.mem sr (core.num.U64.wrapping_add v vcpu.svm.INTERCEPT_EXC) + have hold : old.bv = vs1.get virtKind (.vmcb Svm.interceptExc) := by + have e : vcpu.svm.INTERCEPT_EXC.bv = Svm.interceptExc := by unfold vcpu.svm.INTERCEPT_EXC; rfl + simpa only [old, e] using h1.rdVmcb hv hq1 hvk vcpu.svm.INTERCEPT_EXC + (by rw [e]; decide) (by rw [e]; decide) (by rw [e]; decide) (by unfold vcpu.svm.INTERCEPT_EXC; decide) + let bits := (ctl &&& vcpu.SVM_I1_WRITABLE) ||| vcpu.SVM_I1_FORCED + let ctl' : U64 := (old &&& 4294967295#u64) ||| ⟨bits.bv <<< (32 : Nat)⟩ + have hCtl : ctl'.bv = svmEnterIntercepts (vs1.get virtKind (.vmcb Svm.interceptExc)) ctl.bv := by + simp only [ctl', UScalar.bv_or, UScalar.bv_and] + rw [← hold] + unfold bits svmEnterIntercepts vcpu.SVM_I1_WRITABLE vcpu.SVM_I1_FORCED + rfl + let sc := L.wr sr (core.num.U64.wrapping_add v vcpu.svm.INTERCEPT_EXC) ctl' + let vs2 := vs1.set virtKind (.vmcb Svm.interceptExc) ctl'.bv + have h2 : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D sc a + (updK σ v.bv (.archObj (.vcpu vs2))) := by + simpa only [zv_updK_updK] using h1.vmcbWr hv hvk (f := Svm.interceptExc) hcW (by decide) + (x := core.num.U64.wrapping_add v vcpu.svm.INTERCEPT_EXC) + (by unfold vcpu.svm.INTERCEPT_EXC; rfl) ctl' hq1 + have hq2 : (updK σ v.bv (.archObj (.vcpu vs2))).kheap v.bv = some (.archObj (.vcpu vs2)) := + by simp only [updK, Function.update_self] + have hNe : t.bv ≠ v.bv := fun e => by rw [e, hk] at hxt; cases hxt + have hkt2 : (updK σ v.bv (.archObj (.vcpu vs2))).kheap t.bv = some (.tcb x) := + by simpa [updK, hNe] using hxt + obtain ⟨full, hFull, eFull⟩ := spec_exists (h2.toVmBase.fullReply ht hkt2) + have hGet (ipBits ctlBits : Word) : + (((vs.set virtKind (.vmcb Svm.rip) ipBits).set virtKind (.vmcb Svm.interceptExc) ctlBits).get + virtKind (.vmcb Svm.eventInj)) = vs.get virtKind (.vmcb Svm.eventInj) := by + have hi : VField.canon .svm (.vmcb Svm.eventInj) ≠ VField.canon .svm (.vmcb Svm.interceptExc) := by decide + have hr : VField.canon .svm (.vmcb Svm.eventInj) ≠ VField.canon .svm (.vmcb Svm.rip) := by decide + simp only [hvk, VcpuState.get, VcpuState.set, Function.update_of_ne hi, Function.update_of_ne hr] + have hEventRead : (L.mem sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ)).bv = + vs.get virtKind (.vmcb Svm.eventInj) := by + have e : vcpu.svm.EVENT_INJ.bv = Svm.eventInj := by unfold vcpu.svm.EVENT_INJ; rfl + have h := h2.rdVmcb hv hq2 hvk vcpu.svm.EVENT_INJ + (by rw [e]; decide) (by rw [e]; decide) (by rw [e]; decide) (by unfold vcpu.svm.EVENT_INJ; decide) + rw [h, e] + exact hGet ip.bv ctl'.bv + let event : U64 := if full then + (L.mem sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ) &&& ~~~4294967295#u64) ||| + (intr &&& 4294967295#u64) + else intr + have hE : event.bv = if Fl4Proofs.P3.repFull x then + (vs.get virtKind (.vmcb Svm.eventInj) &&& ~~~0xffff_ffff) ||| (intr.bv &&& 0xffff_ffff) + else intr.bv := by + by_cases hf : full = true + · have hx := eFull.symm.trans hf + rw [hx, if_pos rfl] + simp only [event, if_pos hf] + change ((L.mem sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ)).bv &&& ~~~0xffff_ffff) ||| + (intr.bv &&& 0xffff_ffff) = _ + rw [hEventRead] + · have hx : Fl4Proofs.P3.repFull x ≠ true := fun e => hf (eFull.trans e) + simp only [event, if_neg hf, if_neg hx] + have hOut := h2.vmcbWr hv hvk (f := Svm.eventInj) heW (by decide) + (x := core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ) + (by unfold vcpu.svm.EVENT_INJ; rfl) (event &&& vcpu.SVM_EVENT) hq2 + have heResult : Fl4Proofs.P2.enterBlk st arI s a v ip ctl intr 2#u64 t = + ok (L.wr sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ) (event &&& vcpu.SVM_EVENT)) := by + unfold Fl4Proofs.P2.enterBlk + rw [if_pos rfl] + simp only [svmRipRead, vcpu.get, vcpu.set, lift, L.read_eq, L.write_eq, bind_ok] + rw [svmShl32, bind_ok] + change Std.bind (vcpu.full_reply st sc t) (fun f => + Std.bind (if f then ok ((L.mem sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ) &&& + ~~~4294967295#u64) ||| (intr &&& 4294967295#u64)) else ok intr) (fun m => + ok (L.wr sc (core.num.U64.wrapping_add v vcpu.svm.EVENT_INJ) (m &&& vcpu.SVM_EVENT)))) = _ + rw [hFull, bind_ok] + cases full <;> simp only [event, Bool.false_eq_true, ↓reduceIte, bind_ok] + rw [heResult, WP.spec_ok] + have hMask : vcpu.SVM_EVENT.bv = Svm.eventMask := by unfold vcpu.SVM_EVENT Svm.eventMask; rfl + simpa only [zv_updK_updK, vs2, vs1, UScalar.bv_and, hE, hCtl, hMask] using hOut + +/-- Clear both saved-exit flags before checking the bound notification. -/ +private theorem VmBaseF.clearEnterFlags + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) + {v : U64} (hv : v ∈ V) {vs : VcpuState} (hk : σ.kheap v.bv = some (.archObj (.vcpu vs))) : + (do + let s1 ← vcpu.set st s v vcpu.VALID 0#u64 + vcpu.set st s1 v vcpu.PENDING 0#u64) ⦃ s' => + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s' a + (updK σ v.bv (.archObj (.vcpu { vs with exit := { vs.exit with valid := false, pending := false } }))) ⦄ := by + let w1 := core.num.U64.wrapping_add v vcpu.VALID + let w2 := core.num.U64.wrapping_add v vcpu.PENDING + have h1 : w1.val = v.val + 20528 := by + have h := v3_toNat_add (J.vfitV hv).2 VirtVcpuRel.valid_lt + show (v.bv + vcpu.VALID.bv).toNat = _ + have e : vcpu.VALID.bv = VcpuLay.VALID := by unfold vcpu.VALID; rfl + rw [e, h, v3_fix_vals.2.1] + have h2 : w2.val = v.val + 20520 := by + have h := v3_toNat_add (J.vfitV hv).2 VirtVcpuRel.pending_lt + show (v.bv + vcpu.PENDING.bv).toNat = _ + have e : vcpu.PENDING.bv = VcpuLay.PENDING := by unfold vcpu.PENDING; rfl + rw [e, h, v3_fix_vals.2.2.1] + unfold vcpu.set + simp only [lift, bind_ok, L.write_eq, WP.spec_ok] + have J1 := J.validClr hv h1 hk + have J2 := J1.pendClr hv h2 (by simp only [updK, Function.update_self] <;> rfl) + simpa only [zv_updK_updK, VcpuState.reported] using J2 + +/-- The notification and runnable-state part of the VMEnter spec step. -/ +def enterSpecTail (t : ObjRef) : SMonad Unit Unit := do + let nOpt ← getTcbObjRef Tcb.tcbBoundNotification t + let active ← match nOpt with + | some n => do + let ntfn ← getNotification n + pure (match ntfn.ntfnObj with + | .activeNtfn _ => true + | _ => false) + | none => pure false + match nOpt, active with + | some n, true => do + completeSignal n t + let full ← vmFullReply t + if full then do + let badge ← asUser t (getRegister badge_register) + vmReportF t badge + else asUser t (setRegister msg_info_register 0) + | _, _ => setThreadState t .runningVM + +theorem vmEnterF_staged {σ : State Unit} {t v : ObjRef} {x : Tcb} {vs : VcpuState} + (hkt : σ.kheap t = some (.tcb x)) (hvo : tcbVcpuOf σ t = some v) + (hkv : σ.kheap v = some (.archObj (.vcpu vs))) : + vmEnterF t σ = enterSpecTail t + (updK σ v (.archObj (.vcpu + (vs.enterF virtKind (Fl4Proofs.P3.repFull x) + (x.tcbArch.tcbContext.userRegs (Endp.mrIdx 0)) + (x.tcbArch.tcbContext.userRegs (Endp.mrIdx 1)) + (x.tcbArch.tcbContext.userRegs (Endp.mrIdx 2)))))) := by + unfold vmEnterF + rw [nd_bind_one (show getTcbVcpu t σ = ({(some v, σ)}, False) from by + rw [VirtReportEq.getTcbVcpu_eq, hvo])] + simp only + rw [nd_bind_one (asUser_getRegister_eq hkt _), + nd_bind_one (asUser_getRegister_eq hkt _), + nd_bind_one (asUser_getRegister_eq hkt _), + nd_bind_one (VirtReportEq.vmFullReply_eq hkt), + nd_bind_one (zv_vcpuUpdate_eq hkv _)] + rfl + +/-- Stage the VMEnter request and clear the exit flags before the +notification read. -/ +theorem VmBaseF.stageEnter + (J : VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s a σ) + {v t : U64} (hv : v ∈ V) {vs : VcpuState} (hk : σ.kheap v.bv = some (.archObj (.vcpu vs))) + (hVA : ZvVirtAgree arI) (hCap : VirtSanEq.CapAgree arI a) + (ht : t ∈ Z.T) {x : Tcb} (hkt : σ.kheap t.bv = some (.tcb x)) (ip ctl intr : U64) : + (do + let code ← arI.virtualization a + let s1 ← Fl4Proofs.P2.enterBlk st arI s a v ip ctl intr code t + let s2 ← vcpu.set st s1 v vcpu.VALID 0#u64 + vcpu.set st s2 v vcpu.PENDING 0#u64) ⦃ s' => + VmBaseF (L := L) arI sA σA V AR Z H Cs Ac Lst D s' a + (updK σ v.bv (.archObj (.vcpu (vs.enterF virtKind (Fl4Proofs.P3.repFull x) ip.bv ctl.bv intr.bv)))) ⦄ := by + obtain ⟨i, hi, hSvm, _⟩ := hVA a + rw [hi, bind_ok] + have hx : virtKind = .vmx ∨ virtKind = .svm := by + have hr := J.vr v hv vs hk + cases h : virtKind + · rw [h] at hr + exact hr.elim + · exact Or.inl rfl + · exact Or.inr rfl + · rw [h] at hr + exact hr.elim + have hLow : (4294967295#u64 : U64).bv = (0xffff_ffff : Word) := rfl + rcases hx with hVmx | hS + · refine WP.spec_bind (J.enterVmxFields hv hk hVmx (fun e => by + have h := hSvm.1 e + rw [hVmx] at h + cases h) hCap ip ctl intr) ?_ + intro s' J' + simp only at J' + refine WP.spec_mono (J'.clearEnterFlags hv (by simp only [updK, Function.update_self] <;> rfl)) ?_ + intro s'' J'' + simpa only [zv_updK_updK, VcpuState.enterF, VcpuState.enter, hVmx, + reduceCtorEq, false_and, ↓reduceIte, UScalar.bv_and, hLow] using J'' + · rw [hSvm.2 hS] + refine WP.spec_bind (J.enterSvmFields hv hk hS ht hkt ip ctl intr) ?_ + intro s' J' + simp only at J' + refine WP.spec_mono (J'.clearEnterFlags hv (by simp only [updK, Function.update_self] <;> rfl)) ?_ + intro s'' J'' + simpa only [zv_updK_updK, VcpuState.enterF, VcpuState.enter, hS, + true_and, ↓reduceIte] using J'' + +/-- FL4's first four syscall arguments are register reads irrespective +of the IPC-buffer pointer. -/ +theorem enterArg (s : S) (t b i : U64) (hi : i.val < 4) : + msg.syscall_arg st s t b i ⦃ r => r = L.mem s (regA t (regIdx (Endp.mrIdx i.val))) ⦄ := by + have hN : msg.N_MSG_REGISTERS.val = 4 := by unfold msg.N_MSG_REGISTERS; rfl + have h : i < msg.N_MSG_REGISTERS := (P1.gt_iff_val).2 (by rw [hN]; exact hi) + unfold msg.syscall_arg + rw [if_pos h] + refine WP.spec_bind (Endp.msg_register_spec i hi) ?_ + rintro r rfl + exact Endp.obj.Tcb.reg.spec s t _ + +end +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmExitClock.lean b/proofs/Fl4Proofs/P3/VmExitClock.lean new file mode 100644 index 000000000..fed6b13ae --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmExitClock.lean @@ -0,0 +1,1046 @@ +/- +# VCPU check between timestamp and budget charge + +The unstalled exit updates the clock, then runs `vcpu.check` before +`check_budget`. The concrete check stays outside the two scheduler +clock words. The abstract check commutes with those clock changes +and preserves the entry conditions needed by the charge. + +`VmEptState.checkTimestampHole` uses `ValidMachineTime` [J], +`Sched.OffReady` [J], and the existing `MachPlat` [P] clock agreement. +-/ +import Fl4Proofs.P3.VmCheck +import Fl4Proofs.P3.VmOracle +import Fl4Proofs.P3.XTopJointEntryInv29 +import Fl4Proofs.P1.VcpuCheckInv +import Fl4Proofs.P3.XTopJointKEntryEv2 +import Fl4Proofs.P2.AccessLvmFin +import Fl4Proofs.P2.AccessLvmDecodeR +import Fl4Proofs.P2.EntryVcpu +import Fl4Proofs.P2.ProgGenL35 +import Fl4Proofs.P2.E2EVCut +import Fl4Proofs.P2.E2EPU2P +import Fl4Proofs.P1.FastVmDecline +import Fl4Proofs.P1.LocalVmExit + +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core Fl4Spec Classical +open Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Sched Fl4Proofs.P3.Vs +open Fl4Proofs.P2 + +noncomputable section + +set_option maxHeartbeats 4000000 + +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] +variable {A : Type} {arI : machine.Arch A} {AR : A → Cr3 → Prop} +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} +variable {Cs Ac D : Set U64} {Lst : U64 → List U64} +variable {s : S} {a : A} {σ : State Unit} + +/-- Install the clock fields of an entry timestamp while preserving +the state produced by the intervening VCPU check. -/ +private def VMEntryClock (clock : State Unit) (σ : State Unit) : State Unit := + { σ with + curTime := clock.curTime + consumedTime := clock.consumedTime + machineState := { σ.machineState with + timeState := clock.machineState.timeState + lastMachineTime := clock.machineState.lastMachineTime } } + +private theorem clock_updK (clock σ : State Unit) (p : ObjRef) (o : KernelObject) : + updK (VMEntryClock clock σ) p o = VMEntryClock clock (updK σ p o) := rfl + +private theorem clock_stsAct (clock σ : State Unit) (t : ObjRef) : + stsAct (VMEntryClock clock σ) t = VMEntryClock clock (stsAct σ t) := by + unfold stsAct + by_cases h : t = σ.curThread ∧ σ.schedulerAction = .resumeCurThread ∧ ¬ schedulable t σ = true + · have hc : t = (VMEntryClock clock σ).curThread ∧ + (VMEntryClock clock σ).schedulerAction = .resumeCurThread ∧ + ¬ schedulable t (VMEntryClock clock σ) = true := h + simp only [if_pos hc, if_pos h] + rfl + · have hc : ¬ (t = (VMEntryClock clock σ).curThread ∧ + (VMEntryClock clock σ).schedulerAction = .resumeCurThread ∧ + ¬ schedulable t (VMEntryClock clock σ) = true) := h + simp only [if_neg hc, if_neg h] + +private theorem clock_repTail (clock σ : State Unit) (t : ObjRef) (x : Tcb) (mi badge : Word) : + repTail (VMEntryClock clock σ) t x mi badge = VMEntryClock clock (repTail σ t x mi badge) := by + simp only [repTail, clock_updK, clock_stsAct] + +private theorem clock_jMrSt (clock σ : State Unit) (t : ObjRef) (x : Tcb) + (buf : Option ObjRef) (ms : List Word) : + jMrSt (VMEntryClock clock σ) t x buf ms = VMEntryClock clock (jMrSt σ t x buf ms) := by + cases buf <;> rfl + +/-- A report can update the TCB, VCPU and reply buffer but uses the +same heap and buffer addresses on either side of the timestamp. -/ +private theorem clock_report {clock σ σ' : State Unit} {t : ObjRef} {x : Tcb} {badge : Word} + (hk : σ.kheap t = some (.tcb x)) + (hal : ∀ r : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs r, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σ) + (h : vmReportF t badge σ = ({((), σ')}, False)) : + vmReportF t badge (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) := by + have hkt : (VMEntryClock clock σ).kheap t = some (.tcb x) := hk + have hA (r : List Word) : ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs r, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) (VMEntryClock clock σ) := hal r + have et : tcbVcpuOf (VMEntryClock clock σ) t = tcbVcpuOf σ t := rfl + cases he : tcbVcpuOf σ t with + | none => + rw [v3_vmReportF_none hk he badge (hal _)] at h + rw [v3_vmReportF_none hkt (et.trans he) badge (hA _)] + simp only [clock_repTail, clock_jMrSt] + have e := congrArg Prod.snd (v3_out_eq h) + dsimp only at e + rw [← e] + | some v => + obtain ⟨vs, hV⟩ := v3_tcbVcpuOf_some he + have hV' : (VMEntryClock clock σ).kheap v = some (.archObj (.vcpu vs)) := hV + rw [v3_vmReportF_some hk he hV badge (hal _)] at h + rw [v3_vmReportF_some hkt (et.trans he) hV' badge (hA _)] + have e := congrArg Prod.snd (v3_out_eq h) + dsimp only at e + rw [← e] + split <;> simp only [clock_repTail, clock_updK, clock_jMrSt] + +private theorem clock_noPend {clock σ : State Unit} {t : ObjRef} (h : NoPend σ t) : + NoPend (VMEntryClock clock σ) t := h + +private theorem clock_noAct {clock σ : State Unit} {x : Tcb} (h : NoAct σ x) : + NoAct (VMEntryClock clock σ) x := h + +/-- A non-pending check with an inactive or absent notification either +returns immediately or reports an unbound VCPU. -/ +private theorem clock_check_noact {clock σ σ' : State Unit} {t : ObjRef} {x : Tcb} + (hk : σ.kheap t = some (.tcb x)) (hs : x.tcbState = .runningVM) + (hnp : NoPend σ t) (hna : NoAct σ x) + (hal : ∀ r : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs r, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σ) + (h : vmCheckF t σ = ({((), σ')}, False)) : + vmCheckF t (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) := by + have hk' : (VMEntryClock clock σ).kheap t = some (.tcb x) := hk + have e : tcbVcpuOf (VMEntryClock clock σ) t = tcbVcpuOf σ t := rfl + rw [v3_vmCheckF_noact hk hs hnp hna] at h + rw [v3_vmCheckF_noact hk' hs (clock_noPend hnp) (clock_noAct hna), e] + by_cases hvo : tcbVcpuOf σ t = none + · simp only [NonDet.when, if_pos hvo] at h ⊢ + exact clock_report hk hal h + · simp only [NonDet.when, if_neg hvo] at h ⊢ + change ({((), σ)}, False) = ({((), σ')}, False) at h + have hσ := congrArg Prod.snd (v3_out_eq h) + cases hσ + rfl + +private theorem clock_check_pending {clock σ σ' : State Unit} {t v : ObjRef} + {x : Tcb} {vs : VcpuState} + (hk : σ.kheap t = some (.tcb x)) (hs : x.tcbState = .runningVM) + (hvo : tcbVcpuOf σ t = some v) (hkv : σ.kheap v = some (.archObj (.vcpu vs))) + (hp : vs.exit.pending = true) + (hal : ∀ r : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs r, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σ) + (h : vmCheckF t σ = ({((), σ')}, False)) : + vmCheckF t (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) := by + have hk' : (VMEntryClock clock σ).kheap t = some (.tcb x) := hk + have hvo' : tcbVcpuOf (VMEntryClock clock σ) t = some v := hvo + have hkv' : (VMEntryClock clock σ).kheap v = some (.archObj (.vcpu vs)) := hkv + rw [v3_vmCheckF_pend hk hs hvo hkv hp] at h + rw [v3_vmCheckF_pend hk' hs hvo' hkv' hp] + exact clock_report hk hal h + +private theorem clock_check_active {clock σ σ' : State Unit} {t n : ObjRef} + {x : Tcb} {y : Notification} {b : Badge} + (hk : σ.kheap t = some (.tcb x)) (hs : x.tcbState = .runningVM) (hnp : NoPend σ t) + (hbn : x.tcbBoundNotification = some n) (hkn : σ.kheap n = some (.notification y)) + (hy : y.ntfnObj = .activeNtfn b) + (hr : vmReportF t b (updK σ n (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y))) = + ({((), σ')}, False)) (hcur : σ'.curThread = t) + (hal : ∀ r : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs r, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) + (updK σ n (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y)))) : + vmCheckF t (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) := by + have hn : n ≠ t := fun e => by rw [e, hk] at hkn; cases hkn + have hkr : (updK σ n (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y))).kheap t = + some (.tcb x) := by simp [updK, Ne.symm hn, hk] + have hk' : (VMEntryClock clock σ).kheap t = some (.tcb x) := hk + have hkn' : (VMEntryClock clock σ).kheap n = some (.notification y) := hkn + refine v3_vmCheckF_act hk' hs (clock_noPend hnp) hbn hkn' hy ?_ hcur + rw [clock_updK] + exact clock_report hkr hal hr + +/-- The buffer agreement needed by the existing deterministic report +calculation. -/ +private theorem JAtZB.reportBufAligned + (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} + (ht : Z.th t = some .tcb) {x : Tcb} (hk : σ.kheap t.bv = some (.tcb x)) : + ∀ ms : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs ms, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σ := by + have hBC := bufCover_of_frameCover (T := Z.T) B.bok B.fcov + intro ms p hp q hq + have hmr := (List.of_mem_zip hq).1 + simp at hmr + have hm : BufMap Z.B ({ bv := p } : U64) p := + hBC t (B.thT t ht) x true p hk hp { bv := p } rfl + exact ⟨bufAddr_aligned B.xtop.fin.1.2.ep hm _, buf_frame_of_ok B.bok hk hp _ (by omega)⟩ + +/-- The scheduler values and hardware fields read by the timestamp and +the budget proof across the intervening VCPU report. -/ +private def exitCheckFields (σ : State Unit) := + (σ.curSc, σ.kheap σ.curSc, σ.releaseQueue, σ.curThread, σ.idleThread, σ.idleSc, σ.curTime, + σ.consumedTime, σ.readyQueues, σ.archState, σ.interruptStates, + { σ.machineState with underlyingMemory := fun _ => 0 }) + +private theorem exitCheckFields_updK (σ : State Unit) (p : ObjRef) (o : KernelObject) + (hne : σ.curSc ≠ p) : + exitCheckFields (updK σ p o) = exitCheckFields σ := by + simp [exitCheckFields, updK, hne] + +private theorem exitCheckFields_stsAct (σ : State Unit) (t : ObjRef) : + exitCheckFields (stsAct σ t) = exitCheckFields σ := by + unfold stsAct + split <;> rfl + +private theorem exitCheckFields_jMrSt (σ : State Unit) (t : ObjRef) (x : Tcb) + (b : Option ObjRef) (ms : List Word) (hne : σ.curSc ≠ t) : + exitCheckFields (jMrSt σ t x b ms) = exitCheckFields σ := by + cases b <;> simp [exitCheckFields, jMrSt, Endp.mrState, Endp.mrStateN, setUm, updK, hne] + +private theorem exitCheckFields_repTail (σ : State Unit) (t : ObjRef) (x : Tcb) (mi badge : Word) + (hne : σ.curSc ≠ t) : + exitCheckFields (repTail σ t x mi badge) = exitCheckFields σ := by + unfold repTail + rw [exitCheckFields_updK _ _ _ (by + rw [stsAct_rec] + exact hne)] + rw [exitCheckFields_stsAct] + repeat' rw [exitCheckFields_updK _ _ _ (by change σ.curSc ≠ t; exact hne)] + +/-- A report returns the current thread to Running with the same active +scheduling context, so the state update keeps ResumeCurrentThread. -/ +private theorem repTail_action {σ : State Unit} {t sc : ObjRef} {x : Tcb} + {ctx : SchedContext} {n : Nat} (hsc : x.tcbSchedContext = some sc) + (hks : σ.kheap sc = some (.schedContext ctx n)) (ha : scActive ctx = true) + (hne : sc ≠ t) (hr : t ∉ σ.releaseQueue) (mi badge : Word) : + (repTail σ t x mi badge).schedulerAction = σ.schedulerAction := by + let x' := { setReg (setReg x msg_info_register mi) badge_register badge with tcbState := .running } + let σ' := updK (updK (updK σ t (.tcb (setReg x msg_info_register mi))) t + (.tcb (setReg (setReg x msg_info_register mi) badge_register badge))) t (.tcb x') + have hkt : σ'.kheap t = some (.tcb x') := by simp [σ', updK] + have hk' : σ'.kheap sc = some (.schedContext ctx n) := by simp [σ', updK, hne, hks] + have hS : schedulable t σ' = true := schedulable_of hkt hsc rfl hk' ha hr + change (stsAct σ' t).schedulerAction = _ + simp only [stsAct, hS, not_true_eq_false, and_false, ↓reduceIte] + rfl + +/-- The report keeps the clock, scheduling context, ready queues +and scheduler action for the current thread. -/ +private theorem vmReportExitFields {σ σ' : State Unit} {t : ObjRef} {x : Tcb} {b : Word} + (ht : σ.kheap t = some (.tcb x)) + (hal : ∀ ms : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs ms, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σ) + {sc : SchedContext} {n : Nat} + (hSc : σ.kheap σ.curSc = some (.schedContext sc n)) + (hRef : x.tcbSchedContext = some σ.curSc) (hA : scActive sc = true) (hRel : t ∉ σ.releaseQueue) + (hr : vmReportF t b σ = ({((), σ')}, False)) : + exitCheckFields σ' = exitCheckFields σ ∧ σ'.schedulerAction = σ.schedulerAction := by + have hne : σ.curSc ≠ t := fun e => by rw [e, ht] at hSc; cases hSc + have done {σ0 : State Unit} (ef : exitCheckFields σ0 = exitCheckFields σ) + (ea : σ0.schedulerAction = σ.schedulerAction) (ms : List Word) (mi badge : Word) : + exitCheckFields (repTail σ0 t (repX x ms) mi badge) = exitCheckFields σ ∧ + (repTail σ0 t (repX x ms) mi badge).schedulerAction = σ.schedulerAction := by + have ec := congrArg Prod.fst ef + have ek := congrArg (fun f => f.2.1) ef + have er := congrArg (fun f => f.2.2.1) ef + change σ0.curSc = σ.curSc at ec + change σ0.kheap σ0.curSc = σ.kheap σ.curSc at ek + change σ0.releaseQueue = σ.releaseQueue at er + have hks0 : σ0.kheap σ.curSc = some (.schedContext sc n) := by + change σ0.kheap σ.curSc = _ + rw [← ec] + exact ek.trans hSc + have hrel0 : t ∉ σ0.releaseQueue := by rwa [er] + have hRef0 : (repX x ms).tcbSchedContext = some σ.curSc := hRef + exact ⟨(exitCheckFields_repTail _ _ _ _ _ (ec.symm ▸ hne)).trans ef, + (repTail_action hRef0 hks0 hA hne hrel0 mi badge).trans ea⟩ + cases hv : tcbVcpuOf σ t with + | none => + rw [v3_vmReportF_none ht hv b (hal _)] at hr + have e := congrArg Prod.snd (v3_out_eq hr) + dsimp only at e + rw [← e] + exact done (exitCheckFields_jMrSt _ _ _ _ _ hne) + (by cases ipcBufOf true x <;> rfl) _ _ _ + | some v => + obtain ⟨vs, hkv⟩ := v3_tcbVcpuOf_some hv + have hnev : σ.curSc ≠ v := fun e => by rw [e, hkv] at hSc; cases hSc + rw [v3_vmReportF_some ht hv hkv b (hal _)] at hr + have e := congrArg Prod.snd (v3_out_eq hr) + dsimp only at e + rw [← e] + split + · apply done + · rw [exitCheckFields_updK _ _ _ (by cases ipcBufOf true x <;> exact hnev)] + exact exitCheckFields_jMrSt _ _ _ _ _ hne + · cases ipcBufOf true x <;> rfl + · exact done (exitCheckFields_jMrSt _ _ _ _ _ hne) (by cases ipcBufOf true x <;> rfl) _ _ _ + +/-- Checking the current VCPU commutes with substituting the clock fields +of the same timestamp update. -/ +private theorem VmEptState.vmCheckClock + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {clock σ' : State Unit} {t : U64} (ht : Z.th t = some .tcb) + (hcur : σ.curThread = t.bv) (hni : Entered σ) + (h : vmCheckF t.bv σ = ({((), σ')}, False)) : + vmCheckF t.bv (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) ∧ + exitCheckFields σ' = exitCheckFields σ ∧ σ'.schedulerAction = σ.schedulerAction := by + have B := J.1.1 + obtain ⟨x, hk, _⟩ := B.specTcb ht + by_cases hs : x.tcbState = .runningVM + swap + · rw [VirtReportEq.vmCheckF_not_runningVM hk hs] at h + have eq := congrArg Prod.snd (v3_out_eq h) + dsimp only at eq + subst σ' + exact ⟨VirtReportEq.vmCheckF_not_runningVM hk hs, rfl, rfl⟩ + have hCore : CurInv σ := B.cur.resolve_left (by rw [hni.2]; intro he; cases he) + obtain ⟨sc, nsc, hSc⟩ := hCore.sc + have hRef : x.tcbSchedContext = some σ.curSc := by + obtain ⟨x', hk', h, _⟩ := hCore.tcb + rw [hcur, hk] at hk' + cases hk' + exact h + have hA := hCore.active (B.curSc_ne_idle hCore hni.1) sc nsc hSc + have hRel : t.bv ∉ σ.releaseQueue := fun he => hCore.notRel (by rwa [hcur]) + have hal := B.reportBufAligned ht hk + by_cases hPending : ∃ v vs, tcbVcpuOf σ t.bv = some v ∧ + σ.kheap v = some (.archObj (.vcpu vs)) ∧ vs.exit.pending = true + · obtain ⟨v, vs, hvo, hkv, hp⟩ := hPending + refine ⟨clock_check_pending hk hs hvo hkv hp hal h, ?_⟩ + rw [v3_vmCheckF_pend hk hs hvo hkv hp] at h + exact vmReportExitFields hk hal hSc hRef hA hRel h + have hnp : NoPend σ t.bv := by + cases hvo : tcbVcpuOf σ t.bv with + | none => exact Or.inl hvo + | some v => + obtain ⟨vs, hkv⟩ := v3_tcbVcpuOf_some hvo + exact Or.inr ⟨v, vs, hvo, hkv, Bool.eq_false_iff.mpr + (fun hp => hPending ⟨v, vs, hvo, hkv, hp⟩)⟩ + have noact (hna : NoAct σ x) : + vmCheckF t.bv (VMEntryClock clock σ) = ({((), VMEntryClock clock σ')}, False) ∧ + exitCheckFields σ' = exitCheckFields σ ∧ σ'.schedulerAction = σ.schedulerAction := by + refine ⟨clock_check_noact hk hs hnp hna hal h, ?_⟩ + rw [v3_vmCheckF_noact hk hs hnp hna] at h + by_cases hvo : tcbVcpuOf σ t.bv = none + · rw [NonDet.when, if_pos hvo] at h + exact vmReportExitFields hk hal hSc hRef hA hRel h + · rw [NonDet.when, if_neg hvo] at h + change ({((), σ)}, False) = ({((), σ')}, False) at h + have hEq := congrArg Prod.snd (v3_out_eq h) + cases hEq + exact ⟨rfl, rfl⟩ + obtain ⟨x', hk', hR⟩ := B.xtop.ipc.tcb t (B.thT t ht) + rw [hk] at hk' + cases hk' + set n := L.mem s (P1.boundA t) with hn + have hbn : x.tcbBoundNotification = optRef n := hR.bound + by_cases he : n = 0#u64 + · exact noact (Or.inl (by rw [hbn, he, Notif.optRef_zero])) + obtain ⟨-, -, hX, -, -⟩ := B.blk + have hnH : n ∈ P1.Heap.ntfns H := hX.2.2.bnd t (B.zH.1 t (B.thT t ht)) he + have hnN : n ∈ Z.N := B.hset.2.1 n hnH + obtain ⟨y, hkn, _⟩ := B.xtop.ipc.toN.ntfn n hnN + have hbn' : x.tcbBoundNotification = some n.bv := by rw [hbn, Notif.optRef_ne he] + by_cases hActive : ∃ badge, y.ntfnObj = .activeNtfn badge + swap + · exact noact (Or.inr ⟨n.bv, y, hbn', hkn, fun b hb => hActive ⟨b, hb⟩⟩) + obtain ⟨badge, hact⟩ := hActive + let σn := updK σ n.bv (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y)) + have hne : t.bv ≠ n.bv := fun e => by rw [e, hkn] at hk; cases hk + have hkt : σn.kheap t.bv = some (.tcb x) := by simp [σn, updK, hne, hk] + have hAn : ∀ ms : List Word, ∀ p, ipcBufOf true x = some p → ∀ q ∈ mrPairs ms, + (bufAddr p q.1).toNat % 8 = 0 ∧ inUserFrame (bufAddr p q.1) σn := by + intro ms p hp q hq + obtain ⟨ha, hU⟩ := hal ms p hp q hq + exact ⟨ha, inUserFrame_updK hkn (fun _ e => by cases e) _ hU⟩ + obtain ⟨σr, hr⟩ : ∃ σr, vmReportF t.bv badge σn = ({((), σr)}, False) := by + cases hvo : tcbVcpuOf σn t.bv with + | none => exact ⟨_, v3_vmReportF_none hkt hvo badge (hAn _)⟩ + | some v => + obtain ⟨vs, hkv⟩ := v3_tcbVcpuOf_some hvo + exact ⟨_, v3_vmReportF_some hkt hvo hkv badge (hAn _)⟩ + obtain ⟨s1, _, J1⟩ := spec_exists (J.ntfnIdle hnN hkn hact) + have hcur' : σr.curThread = t.bv := (J1.1.1.repCur ht hkt hr).trans hcur + have he := congrArg Prod.snd (v3_out_eq ((v3_vmCheckF_act hk hs hnp hbn' hkn hact hr hcur').symm.trans h)) + dsimp only at he + subst σ' + refine ⟨clock_check_active hk hs hnp hbn' hkn hact hr hcur' hAn, ?_⟩ + have hneSc : σ.curSc ≠ n.bv := fun e => by rw [e, hkn] at hSc; cases hSc + have hScN : σn.kheap σn.curSc = some (.schedContext sc nsc) := by simp [σn, updK, hneSc, hSc] + obtain ⟨f, e⟩ := vmReportExitFields hkt hAn hScN hRef hA hRel hr + exact ⟨f.trans (exitCheckFields_updK _ _ _ hneSc), e⟩ + +/-- The two per-core scheduler words written by the entry timestamp. -/ +private def timestampWords (s : S) (b : U64) : Prop := + b = P1.ctA (L := L) s ∨ b = P1.cnA (L := L) s + +/-- Off-clock addresses for the VCPU check and its report. -/ +private def offEntryClock (s : S) (b : U64) : Prop := + P1.Aligned b ∧ ¬ timestampWords (L := L) s b + +/-- A closed-store replay needs a range-free run, but does not require +read-once restrictions for changing user memory. -/ +private theorem once_serial {Y : Type} (p : PathObl.SProg Y) (h : PathObl.NoZero p) : + ∀ (s : S) (a : A) (wd touched : Set U64), + E2E.Once st arI (fun _ => True) (fun _ => False) wd touched p s a := by + induction p with + | ret | err => intros; trivial + | zero | clr => exact h.elim + | rd q k ih => + intro s a wd touched + refine ⟨fun he => ?_, fun v _ => ih v (h v) _ _ _ _⟩ + simp [E2E.Racy] at he + | rdp q k ih => + intro s a wd touched + refine ⟨fun he => ?_, fun he => ?_, fun v _ => ih v (h v) _ _ _ _⟩ <;> + simp [E2E.Racy] at he + | wr q v k ih => intro s a wd touched s' _; exact ih h _ _ _ _ + | ksb k ih | cpu k ih | masks k ih => + intro s a wd touched v _ + exact ih v (h v) _ _ _ _ + | arch op k ih => + intro s a wd touched v a' _ + exact ih v (h v) _ _ _ _ + +/-- Every successful range-free run changes aligned memory only in +its guarded write footprint. -/ +private theorem writesIn_of_within {Y : Type} {G W : U64 → Prop} + (hW : ∀ w, W w → P1.Aligned w) (p : PathObl.SProg Y) + (h : PathObl.NoZero p) : + ∀ (s : S) (a : A) (r : Y × S × A), PathObl.Within st arI G W p s a → + PathObl.interp st arI p s a = ok r → P1.WritesIn st s r.2.1 W := by + induction p with + | ret x => + intro s a r _ hr + simp only [PathObl.interp] at hr + obtain rfl := Result.ok_injective hr + exact P1.WritesIn.refl _ _ + | err e => + intro s a r _ hr + exact absurd hr fail_not_ok + | zero | clr => exact h.elim + | wr q v k ih => + intro s a r hw hr + obtain ⟨s1, hs1, hk⟩ := PathObl.bok.mp hr + rw [L.write_eq] at hs1 + obtain rfl := Result.ok_injective hs1 + have hw1 : P1.WritesIn st s (L.wr s q v) W := + (P1.writesIn_wr (st := st) (s := s) (v := v) (hW q hw.1)).mono (fun _ e => e ▸ hw.1) + exact hw1.trans1 (ih h _ _ _ (hw.2 _ (L.write_eq _ _ _)) hk) + | rd q k ih => + intro s a r hw hr + obtain ⟨v, hv, hk⟩ := PathObl.bok.mp hr + exact ih v (h v) _ _ _ (hw.2 _ hv) hk + | rdp q k ih => + intro s a r hw hr + obtain ⟨v, hv, hk⟩ := PathObl.bok.mp hr + exact ih v (h v) _ _ _ (hw.2.2 _ hv) hk + | ksb k ih | cpu k ih | masks k ih => + intro s a r hw hr + obtain ⟨v, hv, hk⟩ := PathObl.bok.mp hr + exact ih v (h v) _ _ _ (hw _ hv) hk + | arch op k ih => + intro s a r hw hr + obtain ⟨⟨v, a1⟩, hv, hk⟩ := PathObl.bok.mp hr + exact ih v (h v) _ _ _ (hw _ _ hv) hk + +/-- Replay the checked guest on the real post-timestamp store. The two +time words remain as written by the timestamp, and all other aligned +words match the pre-timestamp run. -/ +private theorem replay_vcpuCheck [P1.PlainStore st] + {s sTime sCheck : S} {a aCheck : A} {t : U64} + (hAg : E2EV.AgOff st (timestampWords (L := L) s) sTime s) + (hc : vcpu.check st arI s a t = ok (sCheck, aCheck)) + (hR : PathObl.Within st arI + (fun b => P1.Aligned b ∧ ¬ timestampWords (L := L) s b) + (fun b => P1.Aligned b ∧ ¬ timestampWords (L := L) s b) + (PathObl.R.vcpu.check t) s a) : + ∃ sReal, vcpu.check st arI sTime a t = ok (sReal, aCheck) ∧ + E2EV.AgOff st (timestampWords (L := L) s) sReal sCheck ∧ + ∀ b, P1.Aligned b → timestampWords (L := L) s b → + L.mem sReal b = L.mem sTime b := by + let p := PathObl.R.vcpu.check t + have hn : PathObl.NoZero p := PathObl.R.vcpu.check_nz _ + have he : PathObl.interp st arI p s a = ok ((), sCheck, aCheck) := by + rw [show p = PathObl.R.vcpu.check t from rfl, PathObl.R.vcpu.check_eq, hc] + exact bind_ok _ _ + obtain ⟨hW, hC⟩ := E2EV.sim_off (E := timestampWords (L := L) s) (st := st) + (P2.E2EP.masksWr_plain st) (fun _ h => h) (fun _ h => h.1) + p sTime s a ∅ ∅ hAg hR (once_serial p hn _ _ _ _) + obtain ⟨sReal, hReal, hA⟩ := hC _ he + have hw := writesIn_of_within (fun _ h => h.1) p hn _ _ _ hW hReal + refine ⟨sReal, ?_, hA, fun b hal hb => hw.mem_eq hal (fun h => h.2 hb)⟩ + rw [show p = PathObl.R.vcpu.check t from rfl, PathObl.R.vcpu.check_eq] at hReal + obtain ⟨r, hr, hh⟩ := PathObl.bok.mp hReal + cases Result.ok_injective hh + exact hr + +/-- The real check and the clock writes applied to its pre-timestamp +counterpart agree on aligned memory. -/ +private theorem replay_timestamp_agree + {s sCheck sReal : S} (now : U64) + (hN : P1.NodePlaced st (P1.Heap.tcbs H) s (L.cpu s)) + (hC : P1.WritesIn st s sCheck (offEntryClock (L := L) s)) + (hAg : E2EV.AgOff st (timestampWords (L := L) s) sReal sCheck) + (hClock : ∀ b, P1.Aligned b → timestampWords (L := L) s b → + L.mem sReal b = L.mem (P1.utW (L := L) s now) b) : + P1.WritesIn st (P1.utW (L := L) sCheck now) sReal (fun _ => False) := by + have hN1 : P1.NodePlaced st (P1.Heap.tcbs H) sCheck (L.cpu sCheck) := + hC.2.1.symm ▸ Sched.nodePlaced_ksb hN hC.1 + have eCt : P1.ctA (L := L) sCheck = P1.ctA (L := L) s := by + unfold P1.ctA + rw [hC.2.1, P1.nodeAt_of_ksb hC.1] + have eCn : P1.cnA (L := L) sCheck = P1.cnA (L := L) s := by + unfold P1.cnA + rw [hC.2.1, P1.nodeAt_of_ksb hC.1] + obtain ⟨ha, hb, hab⟩ := P1.ct_cn hN + have hk1 := hC.mem_eq ha (fun g => g.2 (Or.inl rfl)) + have hk2 := hC.mem_eq hb (fun g => g.2 (Or.inr rfl)) + refine ⟨hAg.ksb.trans (P1.utW_ksb sCheck now).symm, + hAg.cpu.trans (P1.utW_cpu sCheck now).symm, ?_⟩ + intro b hal _ + by_cases h : timestampWords (L := L) s b + · rw [hClock b hal h] + rcases h with h | h + · rw [h] + unfold P1.utW + rw [eCt, eCn, P1.mem_wr_ne' hb ha hab.symm, P1.mem_wr_ne' hb ha hab.symm, + P1.LawfulStore.mem_wr_same ha, P1.LawfulStore.mem_wr_same ha] + · rw [h] + unfold P1.utW + rw [eCt, eCn, P1.LawfulStore.mem_wr_same hb, P1.LawfulStore.mem_wr_same hb, hk1, hk2] + · rw [hAg.mem b hal h] + exact (P1.utW_mem hN1 now hal (fun h' => h (Or.inl (h'.trans eCt))) + (fun h' => h (Or.inr (h'.trans eCn)))).symm + +private theorem offEntryClock_of_keep {s s' : S} (hk : L.ksb s' = L.ksb s) + (hc : L.cpu s' = L.cpu s) : + offEntryClock (L := L) s' = offEntryClock (L := L) s := by + funext b + unfold offEntryClock timestampWords P1.ctA P1.cnA + simp only [hc, nodeAt_ksb hk] + +private theorem offClock_tcb {T : Set U64} {s : S} {t o : U64} + (hN : P1.NodePlaced st T s (L.cpu s)) (ht : t ∈ T) (hT : P1.TcbAddr t) + (ho : o.val < 4096) (ha : o.val % 8 = 0) : + offEntryClock (L := L) s (core.num.U64.wrapping_add t o) := by + refine ⟨P1.field_aligned hT ho ha, ?_⟩ + rintro (h | h) + · exact P1.node_ne_field hN (o := layout.node.CUR_TIME) (by simp [layout.node.CUR_TIME]) ht hT ho h.symm + · exact P1.node_ne_field hN (o := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) ht hT ho h.symm + +private theorem offClock_node {T : Set U64} {s : S} {o : U64} + (hN : P1.NodePlaced st T s (L.cpu s)) (ho : o.val < 4288) (ha : o.val % 8 = 0) + (h40 : o.val ≠ 40) (h48 : o.val ≠ 48) : + offEntryClock (L := L) s (L.nodeAt s (L.cpu s) o) := by + refine ⟨P1.nodeAt_aligned hN ho ha, ?_⟩ + rintro (h | h) + · have e := congrArg UScalar.val h + rw [P1.nodeAt_val hN ho, P1.nodeAt_val hN (by simp [layout.node.CUR_TIME])] at e + simp [layout.node.CUR_TIME] at e + exact h48 (by omega) + · have e := congrArg UScalar.val h + rw [P1.nodeAt_val hN ho, P1.nodeAt_val hN (by simp [layout.node.CONSUMED])] at e + simp [layout.node.CONSUMED] at e + exact h40 (by omega) + +private theorem offClock_user {s : S} {b : U64} + (hN : P1.NodePlaced st (P1.Heap.tcbs H) s (L.cpu s)) (hc : L.cpu s ∈ Cs) + (hb : P1.OutsideObjs st (P1.Heap.tcbs H) Cs s b) : + offEntryClock (L := L) s b := by + refine ⟨hb.1, ?_⟩ + rintro (h | h) + · exact P1.out_ne_node hb hc hN (o := layout.node.CUR_TIME) (by simp [layout.node.CUR_TIME]) + (congrArg UScalar.val h.symm) + · exact P1.out_ne_node hb hc hN (o := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) + (congrArg UScalar.val h.symm) + +private theorem offClock_ntfn (B : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {n o : U64} (hn : H n = some .ntfn) (ho : o.val < 64) (ha : o.val % 8 = 0) : + offEntryClock (L := L) s (core.num.U64.wrapping_add n o) := by + have hN := B.nodePl + have hNa := B.kern.heap.align n _ hn + have hNf := B.kern.heap.fits n _ hn + simp only [P1.HKind.bits] at hNa hNf + have hVal := P1.ntfn_word_val hNa hNf ho + have hOut := B.kern.hnd n _ hn _ B.kern.cpuCs + simp only [P1.HKind.bits] at hOut + refine ⟨by unfold P1.Aligned; rw [hVal]; omega, ?_⟩ + rintro (h | h) + · have e := congrArg UScalar.val h + rw [hVal, P1.nodeAt_val hN (by simp [layout.node.CUR_TIME])] at e + simp [layout.node.CUR_TIME] at e + omega + · have e := congrArg UScalar.val h + rw [hVal, P1.nodeAt_val hN (by simp [layout.node.CONSUMED])] at e + simp [layout.node.CONSUMED] at e + omega + +private theorem VmBase.vcpuOffClock (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + {v : U64} (hv : v ∈ V) : P2.PathObl.VW (offEntryClock (L := L) s) v := by + have B := J.base + have hN := B.nodePl + have hOut := B.kern.hnd v _ (J.vm.heap v hv) _ B.kern.cpuCs + simp only [P1.HKind.bits] at hOut + obtain ⟨hVa, hVf⟩ := (B.jvLay J.vm).vfit v hv + intro o ho ha + have hVal := lay_vw_val hVf ho + refine ⟨by unfold P1.Aligned; rw [hVal]; omega, ?_⟩ + rintro (h | h) + · have e := congrArg UScalar.val h + rw [hVal, P1.nodeAt_val hN (by simp [layout.node.CUR_TIME])] at e + simp [layout.node.CUR_TIME] at e + omega + · have e := congrArg UScalar.val h + rw [hVal, P1.nodeAt_val hN (by simp [layout.node.CONSUMED])] at e + simp [layout.node.CONSUMED] at e + omega + +/-- The report reads the bound VCPU, current TCB and scheduling context. +Its IPC-buffer and register writes are covered by the same placement +facts as the existing report refinement. -/ +private theorem VmEptState.reportOffClock + (hA : P0.ArchTotal arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : Z.th t = some .tcb) (hct : σ.curThread = t.bv) + (hVM : L.mem s (P1.stA t) = sched.TS_RUNNING_VM) (hCore : CurInv σ) (badge : U64) : + vcpu.report (PathObl.guard st (offEntryClock (L := L) s) (offEntryClock (L := L) s)) arI s a t badge = + vcpu.report st arI s a t badge := by + have B := J.1.1 + have hN := B.nodePl + have hT := (B.detPl J.1.2.vm).ta t ht + have htT := B.thT t ht + have htH : t ∈ P1.Heap.tcbs H := B.zH.1 t htT + have hWord (o : U64) (ho : o.val < 4096) (ha : o.val % 8 = 0) : + offEntryClock (L := L) s (core.num.U64.wrapping_add t o) := offClock_tcb hN htH hT ho ha + have hReg : PathObl.Regs (offEntryClock (L := L) s) t := by + intro r hr + obtain ⟨off, e, h⟩ := P1.regA_eq hT hr + rw [h] + exact hWord off (by omega) (by omega) + let v := L.mem s (tVcpuA t) + have hv0 : v ≠ 0#u64 := J.1.2.rvm t ht + (by rw [hVM]; unfold sched.TS_RUNNING_VM; rfl) + have hv := ((J.toB.extv.bnd t ht).resolve_left hv0).1 + have hVW := J.toB.vcpuOffClock hv + let U := BufU Z σ ∪ {pendA v} + obtain ⟨⟨Q, R, hq⟩, -, hX, -, -⟩ := B.blk + have hU : ∀ b ∈ U, P1.UsrW st (P1.Heap.tcbs H) Cs H (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) s b := by + intro b hb + rcases hb with hb | hb + · exact B.usrWJ hb + · have e : b = pendA v := hb + subst b + exact P2.Stall.usrW_vcpu B.kern.heap + (fun c hc => by obtain ⟨n, hn⟩ := hc; simpa [P1.Heap.scBits, hn] using hn) + B.kern.hksIn hq (J.1.2.vm.heap v hv) + obtain ⟨b, hb, hbU⟩ := spec_exists (B.bufOK htH) + have hBU : P1.BufOK U b := fun nz i hi => Or.inl (hbU nz i hi) + have hBW : PathObl.BufW (offEntryClock (L := L) s) b := fun nz i hi => + offClock_user hN B.kern.cpuCs (hU _ (hBU nz i hi)).out + have hSt : offEntryClock (L := L) s (P1.stA t) := by + rw [P1.stA_eq] + exact hWord _ (by decide) (by decide) + have hSc := B.xtop.fin.1.1.1 + obtain ⟨qs, rs, hkC, hkS⟩ := hSc.lists + have et : t = nodeW st s Z.c layout.node.CUR_THREAD := + VirtSanEq.u64_ext (hct.symm.trans hkS.curThread) + have hCoreFacts := hCore.facts hSc B.inv + have hScC : L.mem s (P1.scA t) ∈ Z.C := by + rw [et, hCoreFacts.2.2.2.1] + exact hCoreFacts.1 + obtain ⟨x, n, hx, hsr⟩ := hkS.scs _ hScC + have hMax : offEntryClock (L := L) s (P1.maxA (L.mem s (P1.scA t))) := by + rw [maxA_eq] + obtain ⟨ha, hi⟩ := hsr.hdr (K := 72#u64) (by decide) (by decide) + obtain ⟨_, hOut, _, _⟩ := hSc.scOutIn hScC hi + have hc := hkC.cur + refine ⟨ha, ?_⟩ + rintro (h | h) + · have e := congrArg UScalar.val h + rw [P1.nodeAt_val hN (by simp [layout.node.CUR_TIME]), hc] at e + simp [layout.node.CUR_TIME] at e + omega + · have e := congrArg UScalar.val h + rw [P1.nodeAt_val hN (by simp [layout.node.CONSUMED]), hc] at e + simp [layout.node.CONSUMED] at e + omega + have hn : PathObl.NodeSt (L := L) (offEntryClock (L := L) s) (offEntryClock (L := L) s) s := by + have hr : offEntryClock (L := L) s (L.nodeAt s (L.cpu s) layout.node.SCHED_ACTION) := + offClock_node hN (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION]) + (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION]) + exact ⟨offClock_node hN (by simp [layout.node.CUR_THREAD]) (by simp [layout.node.CUR_THREAD]) + (by simp [layout.node.CUR_THREAD]) (by simp [layout.node.CUR_THREAD]), hr, hr⟩ + have hNoSc : P1.scA t ∉ U := by + intro h + exact P1.out_ne_field (hU _ h).out htH hT (K := 3464#u64) (by decide) rfl + have hSteps := P2.repFr_steps (Ω := P1.Heap.omega H) (Rp := P1.Heap.replies H) + (Nt := P1.Heap.ntfns H) (Ac := Ac) htH hU hBU + have hFin := P2.repFr_fin + (gS := PathObl.guard st (offEntryClock (L := L) s) (offEntryClock (L := L) s)) + (T := H.tcbs) (Cs := Cs) (H := H) (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) + (U := U) (Ω := P1.Heap.omega H) (Rp := P1.Heap.replies H) + (Nt := P1.Heap.ntfns H) (Ac := Ac) hT hNoSc hn hSt hSt + (by rw [P1.scA_eq]; exact hWord _ (by decide) (by decide)) hMax + (by rw [P1.inqA_eq]; exact hWord _ (by decide) (by decide)) + have hLookup := PathObl.msg.lookup_ipc_buffer.guard (st := st) + (gS := PathObl.guard st (offEntryClock (L := L) s) (offEntryClock (L := L) s)) s true t + (P2.tcb_slot_buf t) (hWord _ (by decide) (by decide)) + (by rw [P1.sbWordA_eq]; exact hWord _ (by decide) (by decide)) + (by rw [P1.sbWordA8_eq]; exact hWord _ (by decide) (by decide)) + refine PathObl.vcpu.report.guardP hA s a t badge v b hSteps hFin + ⟨B.blk, hVM, P1.WritesIn.refl _ _⟩ (hWord _ (by decide) (by decide)) rfl + hLookup hb (fun _ => Or.inr rfl) ?_ + exact ⟨hReg, hReg, hBW, fun _ => hVW, fun _ f w he => by + have hw := P1.vcpu.vmcs_addr.off v f + rw [he, WP.spec_ok] at hw + obtain ⟨off, hlt, ha, rfl⟩ := hw + exact hVW off (by omega) ha, + fun _ => hVW _ (by unfold vcpu.PENDING; decide) (by unfold vcpu.PENDING; decide)⟩ + +/-- The VCPU check does not consult either word written by the +timestamp, including when reporting an exit or an active notification. -/ +private theorem VmEptState.checkOffClock + (hA : P0.ArchTotal arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : Z.th t = some .tcb) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) : + PathObl.Within st arI (offEntryClock (L := L) s) (offEntryClock (L := L) s) + (PathObl.R.vcpu.check t) s a := by + let G := offEntryClock (L := L) s + let g := PathObl.guard st G G + have B := J.1.1 + have htH : t ∈ P1.Heap.tcbs H := B.zH.1 t (B.thT t ht) + have hT := (B.detPl J.1.2.vm).ta t ht + have hG (o : U64) (ho : o.val < 4096) (ha : o.val % 8 = 0) : + G (core.num.U64.wrapping_add t o) := offClock_tcb B.nodePl htH hT ho ha + have hSt : G (P1.stA t) := by rw [P1.stA_eq]; exact hG _ (by decide) (by decide) + have hCore : CurInv σ := B.cur.resolve_left (by rw [hres]; intro h; cases h) + have hg : vcpu.check g arI s a t = vcpu.check st arI s a t := by + unfold vcpu.check + rw [PathObl.obj.Tcb.state.guard t s hSt, PathObl.state_ok'] + simp only [bind_ok] + by_cases hRaw : L.mem s (P1.stA t) = sched.TS_RUNNING_VM + swap + · simp only [if_pos (bne_iff_ne.mpr hRaw)] + simp only [hRaw, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte] + let v := L.mem s (tVcpuA t) + have hv0 : v ≠ 0#u64 := J.1.2.rvm t ht + (by rw [hRaw]; unfold sched.TS_RUNNING_VM; rfl) + have hv := ((J.toB.extv.bnd t ht).resolve_left hv0).1 + have hp : G (core.num.U64.wrapping_add v vcpu.PENDING) := + J.toB.vcpuOffClock hv _ (by simp [vcpu.PENDING]) (by simp [vcpu.PENDING]) + have ev : vcpu.bound st s t = ok v := P1.eq_of_spec_fd (v3_bound (L := L) s t) + rw [P2.vcpu.bound.guardT s t (hG _ (by decide) (by decide)), ev] + simp only [bind_ok] + have ev0 : (v != 0#u64) = true := bne_iff_ne.mpr hv0 + simp only [if_pos ev0] + rw [P2.vcpu.get.guard s v _ hp] + unfold vcpu.get + simp only [lift, L.read_eq, bind_ok] + by_cases hp0 : L.mem s (core.num.U64.wrapping_add v vcpu.PENDING) = 0#u64 + swap + · simp only [if_pos (bne_iff_ne.mpr hp0)] + rw [J.reportOffClock hA ht hct hRaw hCore] + simp only [hp0, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte] + let n := L.mem s (P1.boundA t) + have en : obj.Tcb.bound_ntfn st t s = ok n := + P1.eq_of_spec_fd (P1.obj.Tcb.bound_ntfn.val (L := L) s t) + rw [PathObl.obj.Tcb.bound_ntfn.guard t s (hG _ (by decide) (by decide)), en] + simp only [bind_ok] + by_cases hn0 : n = 0#u64 + · simp only [hn0, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, if_neg hv0] + simp only [if_pos (bne_iff_ne.mpr hn0)] + obtain ⟨-, -, hX, -, -⟩ := B.blk + have hnH : n ∈ P1.Heap.ntfns H := hX.2.2.bnd t htH hn0 + have hnN : n ∈ Z.N := B.hset.2.1 n hnH + have hTail : G (core.num.U64.wrapping_add n layout.ntfn.TAIL_STATE) := + offClock_ntfn B hnH (by simp [layout.ntfn.TAIL_STATE]) (by simp [layout.ntfn.TAIL_STATE]) + obtain ⟨ns, hns, eNs⟩ := spec_exists (P1.obj.Ntfn.state.spec (L := L) s n) + rw [PathObl.obj.Ntfn.state.guard n s hTail, hns] + simp only [bind_ok] + by_cases hAct : ns = obj.NTFN_ACTIVE + swap + · simp only [if_neg hAct, if_neg hv0] + simp only [if_pos hAct] + obtain ⟨y, hy, _⟩ := B.xtop.ipc.toN.ntfn n hnN + have hnRel := (B.xtop.irelK B.ks B.buf).1.toN.at_ntfn hnN hy + have hAct' : ∃ badge, y.ntfnObj = .activeNtfn badge := by + rw [epState_eq] at eNs + cases ho : y.ntfnObj with + | activeNtfn b => exact ⟨b, rfl⟩ + | idleNtfn => + rw [eNs, stOf_idle hnRel.obj ho] at hAct + exact ((by unfold obj.NTFN_IDLE obj.NTFN_ACTIVE; decide : obj.NTFN_IDLE ≠ obj.NTFN_ACTIVE) hAct).elim + | waitingNtfn q => + rw [eNs, stOf_waiting hnRel.obj ho] at hAct + exact ((by unfold obj.NTFN_WAITING obj.NTFN_ACTIVE; decide : obj.NTFN_WAITING ≠ obj.NTFN_ACTIVE) hAct).elim + obtain ⟨badge, hBadge⟩ := hAct' + have hBadgeG : G (core.num.U64.wrapping_add n layout.ntfn.BADGE) := + offClock_ntfn B hnH (by simp [layout.ntfn.BADGE]) (by simp [layout.ntfn.BADGE]) + rw [PathObl.obj.Ntfn.badge.guard n s hBadgeG, + PathObl.lv_ntfn_set_state s n obj.NTFN_IDLE hTail hTail] + obtain ⟨bd, eBd, _⟩ := spec_exists (Notif.obj.Ntfn.badge.spec (L := L) s n) + obtain ⟨sN, eN, JN⟩ := spec_exists (J.ntfnIdle hnN hy hBadge) + rw [eBd, eN] + simp only [bind_ok] + have hN := Result.ok_injective (eN.symm.trans (spec_eq_ok (P1.obj.Ntfn.set_state.val (L := L) s n obj.NTFN_IDLE))) + have hDef : offEntryClock (L := L) sN = G := + offEntryClock_of_keep (by rw [hN, L.ksb_wr]) (by rw [hN, L.cpu_wr]) + obtain ⟨x, hx, hxCode⟩ := B.specTcb ht + have hxRun : x.tcbState = .runningVM := by + rw [hRaw] at hxCode + cases he : x.tcbState <;> simp [he, Notif.tsCode, sched.TS_RUNNING_VM] at hxCode ⊢ + have hneq : t.bv ≠ n.bv := fun e => by rw [e, hy] at hx; cases hx + have hxN : (updK σ n.bv (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y))).kheap t.bv = + some (.tcb x) := by simp [updK, hneq, hx] + obtain ⟨xN, hKN, hC⟩ := JN.1.1.specTcb ht + rw [hxN] at hKN + cases hKN + have hRawN : L.mem sN (P1.stA t) = sched.TS_RUNNING_VM := + UScalar.eq_of_val_eq (by rw [hC, hxRun]; unfold tsCode sched.TS_RUNNING_VM; rfl) + have hCoreN := JN.1.1.cur.resolve_left + (fun h => by change σ.schedulerAction = .chooseNewThread at h; rw [hres] at h; cases h) + have hRep := JN.reportOffClock hA ht hct hRawN hCoreN bd + rw [hDef] at hRep + rw [hRep] + obtain ⟨⟨sc, ac⟩, he, _⟩ := spec_exists (P0.vcpu.check.p0 st arI s a t L.total hA) + have hs : PathObl.interp g arI (PathObl.R.vcpu.check t) s a = ok ((), sc, ac) := by + rw [PathObl.R.vcpu.check_eq, hg, he] + exact bind_ok _ _ + exact (PathObl.interp_guard (PathObl.R.vcpu.check t) s a _ hs).2 + +/-- Transfer the timestamp hole to a store with the same aligned words +and node addresses. The execution can therefore retain the actual +store produced by the VCPU check. -/ +private theorem JHole.agreeStore + {s0 s1 s2 : S} {a0 a1 : A} {σ0 σ1 : State Unit} + (hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s1 a1 σ1) + (he : P1.WritesIn st s1 s2 (fun _ => False)) : + JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s2 a1 σ1 := by + have hS := hh.xtop.fin.1.1.1 + obtain ⟨Q, R, hc, hs⟩ := hS.lists + have hmem : ∀ b, P1.Aligned b → L.mem s2 b = L.mem s1 b := + fun _ hb => he.mem_eq hb (fun h => h) + have hsa : SAgree st Z.T Z.C Z.c s1 s2 := + ⟨he.1, he.2.1, + fun _ ho h8 _ _ _ _ _ => hmem _ (P1.nodeAt_aligned hc.node ho h8), + fun t ht o ho => by + obtain ⟨ho1, ho2, _⟩ := schedField_ok ho + exact hmem _ (P1.field_aligned (hc.tcbs t ht) ho1 ho2), + hmem _ (curDomA_aligned hc.node), hmem _ (dtA_aligned hc.node), + fun _ _ b hb _ => hmem b hb⟩ + have hnode (o : U64) (ho : o.val < 4288) (h8 : o.val % 8 = 0) : + nodeW st s2 Z.c o = nodeW st s1 Z.c o := by + unfold nodeW + rw [nodeAt_ksb he.1] + exact hmem _ (P1.nodeAt_aligned hc.node ho h8) + have hS2 := hS.of_sagree hsa + (hnode _ (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION])) + (hnode _ (by simp [layout.node.REPROGRAM]) (by simp [layout.node.REPROGRAM])) + (show NtfnStepW σ1 σ1 from ⟨rfl, by cases σ1; rfl, fun _ => Or.inl rfl⟩) + have hR2 := hh.xtop.fin.1.1.2.2.1.frame hS.placed + (fun b hb _ => hmem b hb) (KView.refl σ1) + have hK : ScTKw (fun _ => False) σ1 σ1 := + ⟨fun p => OTK.refl _ _, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ + have hN : ∀ n ∈ Z.N, n.val + 40 ≤ (L.ksb s1).val ∨ (L.ksb s1).val + 13568 ≤ n.val := by + rw [hh.ws.1] + exact hh.j0.nk + have hX := xtop_sc_step hh.xtop hh.j0.ip hN (he.mono fun _ h => h.elim) + (ct := σ1.curThread) (hK.mono fun _ h => h.elim) hS2 hR2 id + obtain ⟨⟨Q1, R1, q1⟩, _, hX1, _, _⟩ := hh.blk + have hD : P1.DbgTz st (P1.Heap.tcbs H) Cs s2 := + P1.DbgTz.of_writes q1.tcbs q1.nodes he (fun _ _ h => h.elim) hX1.dbg + have hB := hh.blk.agreeD (P1.agreeD_of_writes hh.blk he (fun _ h => h.elim)) hD + have hDbg : L.mem s2 (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) = + L.mem s0 (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS) := + (hmem _ hh.j0.kern.dwAl).trans hh.dbg + have hDkeep : P1.DbgKeep st (P1.Heap.tcbs H) Cs s1 s2 := + ⟨he.1, fun b hb => hmem b (P1.dbgW_aligned hh.blk hb)⟩ + exact ⟨hh.j0, hh.spec, hh.ws.trans1 (he.mono fun _ h => h.elim), hX, + hh.nsc, hh.inv, hh.cur, hh.act, hB, hDbg, hh.dbgK.trans hDkeep⟩ + +/-- A VCPU check keeps the oracle words for every thread in the post-state. -/ +private theorem VmEptState.checkVmOrc + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hA : P0.ArchTotal arI) (hres : σ.schedulerAction = .resumeCurThread) + {sc : S} {a' : A} {σc : State Unit} {Ac' : Set U64} {Lst' : U64 → List U64} + (hc : vcpu.check st arI s a (L.curW s) = ok (sc, a')) + (Jc : VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D sc a' σc) : + VmOrc st (v3OnCore st s) (v3RemCur st s) sc σc := by + have B := J.1.1 + let U := BufU Z σ ∪ {b | ∃ v ∈ V, b = pendA v} + obtain ⟨⟨Q, R, hq⟩, _, _, _, _⟩ := B.blk + have hU : ∀ b ∈ U, P1.UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := by + rintro b (hb | ⟨v, hv, rfl⟩) + · exact B.usrWJ hb + · exact P2.Stall.usrW_vcpu B.kern.heap (fun c hc => by obtain ⟨n, hn⟩ := hc; simpa [P1.Heap.scBits, hn] using hn) + B.kern.hksIn hq (J.1.2.vm.heap v hv) + have hbuf : msg.lookup_ipc_buffer st s true (L.curW s) ⦃ b => P1.BufOK U b ⦄ := + WP.spec_mono (B.bufOK B.kern.curH) fun _ h hne i hi => Or.inl (h hne i hi) + have hpw (hne : L.mem s (tVcpuA (L.curW s)) ≠ 0#u64) : + pendA (L.mem s (tVcpuA (L.curW s))) ∈ U := + Or.inr ⟨_, ((J.toB.extv.bnd _ B.kern.curT).resolve_left hne).1, rfl⟩ + have hInv := B.entryInv hres + have hW := P1.vcpu.check.vck hA (fun _ hn => hn) s a hInv hU hbuf hpw + rw [hc, WP.spec_ok] at hW + obtain ⟨hcpu, _, _, _, hfld, hnode⟩ := P1.VckW.frames hq B.kern.curH hW.2.1 + intro t y hk _ + obtain ⟨u, hu, rfl⟩ := Jc.1.1.obj.tcb t y hk + have huH : u ∈ H.tcbs := B.zH.1 u hu + have haf : L.mem sc (P1.affA u) = L.mem s (P1.affA u) := + hfld u huH 3520#u64 (by decide) (by decide) (fun _ => Or.inr (by decide)) + have hOn : v3OnCore st s u.bv = v3OnCore st sc u.bv := by + unfold v3OnCore + change decide (L.mem s (P1.affA u) = L.cpu s) = decide (L.mem sc (P1.affA u) = L.cpu sc) + rw [haf, hcpu] + refine ⟨hOn, fun hoff => ?_⟩ + have hne : L.mem s (P1.affA u) ≠ L.cpu s := by + intro he + change decide (L.mem s (P1.affA u) = L.cpu s) = false at hoff + simp [he] at hoff + have hcc := hq.aff u huH + unfold v3RemCur + change decide (L.mem s (L.nodeAt s (L.mem s (P1.affA u)) layout.node.CUR_THREAD) = u) = + decide (L.mem sc (L.nodeAt sc (L.mem sc (P1.affA u)) layout.node.CUR_THREAD) = u) + rw [haf, P1.nodeAt_of_ksb hW.2.1.1, + hnode _ hcc layout.node.CUR_THREAD (by simp [layout.node.CUR_THREAD]) + (by simp [layout.node.CUR_THREAD]) (fun he => (hne he).elim)] + +def checkAfterTimestamp (st : machine.Store S) (arI : machine.Arch A) (s : S) (a : A) : + Result (S × A) := do + let (s1, a1) ← sched.update_timestamp st arI s a + let ct ← sched.cur_thread st s1 + vcpu.check st arI s1 a1 ct + +def specCheckAfterTimestamp (σ : State Unit) : Set (Unit × State Unit) × Prop := + (updateTimeStamp (Z := Unit) >>= fun _ => + NonDet.gets (fun s : State Unit => s.curThread) >>= vmCheckF) σ + +theorem VmEptState.checkTimestampHole [P1.PlainStore st] + {MR : A → MachineState → Prop} + (hK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : numDomains = 1) (hM : MachPlat arI MR) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hMR : MR a σ.machineState) (hVTime : ValidMachineTime σ) (hOff : OffReady σ) : + checkAfterTimestamp st arI s a ⦃ r => ∃ sc σc Ac' Lst' σr, + specCheckAfterTimestamp σ = ({((), σr)}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D sc a σc ∧ + JHole (L := L) arI AR Z H Cs Ac' Lst' D sc a σc r.1 r.2 σr ∧ + P1.WritesIn st sc r.1 (timestampWords (L := L) sc) ∧ + VmOrc st (v3OnCore st s) (v3RemCur st s) sc σc ∧ + MR r.2 σr.machineState ∧ OffReady σr ∧ Entered σr ∧ + (∀ d p, σr.curThread ∉ σr.readyQueues d p) ⦄ := by + have B := J.1.1 + have hN := B.nodePl + let ct := L.curW s + have ht : Z.th ct = some .tcb := B.kern.curT + have hcur : σ.curThread = ct.bv := B.kern.cur + obtain ⟨⟨now, a1⟩, hn, hNow, ⟨hv, hMR1⟩, hAR⟩ := spec_exists + (WP.spec_and (hM.nowAgree hMR hVTime) + (WP.spec_and (hM.now a σ.machineState hMR) (hK.now a σ.archState.x64CurrentCr3 B.ar))) + obtain ⟨ms, hm, hLe, hu⟩ := hNow + change now.bv = gctVal σ.machineState at hv + let σ1 : State Unit := { σ with + curTime := now.bv + consumedTime := σ.consumedTime + (now.bv - σ.curTime) + machineState := gctState σ.machineState } + have hTime : updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) := by + have he := updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ.machineState)) + simpa only [σ1, hv] using he + let s1 := P1.utW (L := L) s now + have hUt : sched.update_timestamp st arI s a = ok (s1, a1) := + P1.update_timestamp_ok arI hN hn + have hUtW := update_timestamp_fr arI hK s a B.ar hN + rw [hUt, WP.spec_ok] at hUtW + have hAg : E2EV.AgOff st (timestampWords (L := L) s) s1 s := + ⟨hUtW.1.2.1, hUtW.1.1, by simp [P1.PlainStore.frame_masks_eq], + fun _ hb he => hUtW.1.mem_eq hb he⟩ + have hC := (J.archV hAR).checkJ hA hVA ht hcur + obtain ⟨⟨sc, aC⟩, hc, σc, Ac', Lst', hSpec, JC, haC⟩ := spec_exists hC + dsimp only at haC + subst aC + have hR := (J.archV hAR).checkOffClock hA ht hcur hni.2 + obtain ⟨sReal, hReal, hAgReal, hClk⟩ := replay_vcpuCheck hAg hc hR + have hI : PathObl.interp st arI (PathObl.R.vcpu.check ct) s a1 = ok ((), sc, a1) := by + rw [PathObl.R.vcpu.check_eq, hc] + exact bind_ok _ _ + have hWC := writesIn_of_within (fun _ h => h.1) _ (PathObl.R.vcpu.check_nz ct) _ _ _ hR hI + have hAgree := replay_timestamp_agree now hN hWC hAgReal hClk + obtain ⟨hCheck, hFields, hAct⟩ := J.vmCheckClock (clock := σ1) ht hcur hni hSpec + have fields := hFields + simp only [exitCheckFields, Prod.mk.injEq] at fields + obtain ⟨eSC, eHeap, eRel, eCur, eIdle, eIdleSc, eTime, eCons, eQ, eArch, eIRQ, eMachine⟩ := fields + have eTS := congrArg MachineState.timeState eMachine + change σc.machineState.timeState = σ.machineState.timeState at eTS + have eLM := congrArg MachineState.lastMachineTime eMachine + change σc.machineState.lastMachineTime = σ.machineState.lastMachineTime at eLM + have eVal : gctVal σc.machineState = gctVal σ.machineState := by simp [gctVal, gctNat, eTS, eLM] + let σr := VMEntryClock σ1 σc + have hTR : updateTimeStamp (Z := Unit) σc = ({((), σr)}, False) := by + have hOne := updateTimeStamp_eq' hnd (doMachineOp_single + (getCurrentTime_eq σc.machineState)) + simpa only [σr, σ1, VMEntryClock, gctState, eVal, eTS, eLM, eTime, eCons, hv] using hOne + have ARc : AR a σc.archState.x64CurrentCr3 := by rw [eArch]; exact B.ar + have Jc := JC.archV ARc + have hnc : NowAgree arI a σc := by + unfold NowAgree + rw [hn, WP.spec_ok] + refine ⟨gctState σc.machineState, ?_, ?_, rfl⟩ + · rw [hv, ← eVal] + exact doMachineOp_single (getCurrentTime_eq _) + · rw [eTime] + exact hLe + have hUtC := P1.update_timestamp_ok arI Jc.1.1.nodePl hn + have hUtCW := update_timestamp_fr arI hK sc a ARc Jc.1.1.nodePl + rw [hUtC, WP.spec_ok] at hUtCW + have hFr : P1.WritesIn st sc sReal (timestampWords (L := L) sc) := + (hUtCW.1.trans hAgree).mono fun _ h => h.elim id False.elim + have hOrc := (J.archV hAR).checkVmOrc hA hni.2 hc JC + have hHC := Jc.1.1.timestampJH hK hA hnd hnc + rw [hUtC, WP.spec_ok] at hHC + obtain ⟨σu, hSu, _, _, _, _, _, hMem, hOffC, hH⟩ := hHC + have eσ := congrArg Prod.snd (v3_out_eq (hSu.symm.trans hTR)) + dsimp only at eσ + subst σu + have hHole := (hH σr.machineState a1 hMem id).agreeStore hAgree + have hOff' : OffReady σc := by + intro x n hk + rw [eHeap] at hk + rw [eCons, eTime] + exact hOff x n hk + have hRState : MR a1 σr.machineState := by + refine hM.frame _ _ _ hMR1 ?_ ?_ rfl rfl + · have he := congrArg MachineState.irqMasks eMachine + exact he + · have he := congrArg MachineState.irqState eMachine + exact he + have hSpecR : specCheckAfterTimestamp σ = ({((), σr)}, False) := by + unfold specCheckAfterTimestamp + rw [nd_bind_one hTime, nd_gets_bind] + change vmCheckF σ.curThread σ1 = _ + rw [hcur] + exact hCheck + unfold checkAfterTimestamp + rw [hUt, bind_ok, uncurry_apply_pair, P1.cur_thread_ok, P1.lvm_curW_utW hN, bind_ok, hReal, WP.spec_ok] + exact ⟨sc, σc, Ac', Lst', σr, hSpecR, Jc, hHole, hFr, hOrc, hRState, hOffC hOff', + ⟨by change σc.curThread ≠ σc.idleThread; rw [eCur, eIdle]; exact hni.1, + hAct.trans hni.2⟩, + fun d p => by change σc.curThread ∉ σc.readyQueues d p; rw [eCur, eQ]; exact hnq d p⟩ + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmFinish.lean b/proofs/Fl4Proofs/P3/VmFinish.lean new file mode 100644 index 000000000..7b1aa5822 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmFinish.lean @@ -0,0 +1,232 @@ +/- +P3 (line mmuAD, gen 42b81, item 4 step 3): **FL4's `syscall::finish` at `VmEptState`, against the extended exit +`fl4KernelExitVF`** (`fl4AwakenVF`, `schedule`, `activateThreadV`, the current thread's `vmCheckF`). + +* Spec: `actRestSV` (`activateThreadV`'s state dispatch after the yield completion: XTopJointSchedR's `actRest` with + seL4's `RunningVM` case, nothing to do), `activateThreadV_eqY` (`activateThreadV` = the yield completion, then + `actRestSV` of the current thread). +* **`VmEptState.actRestV`**: FL4's state dispatch at `VmEptState`: a `Restart` current thread gets its fault IP as its + next IP (`JAtZB.regWrJ`) and runs (`JAtZB.runJ`), both native steps (`NatFoot`, `VmEptState.ofNat`); a `Running`, + `RunningVM` or idle one is left alone (FL4 tests `TS_RESTART` only). +* **`VmEptState.activateV`**: FL4's `activate_thread` from `CurRunW` (what `VmEptState.scheduleVF` gives): the yield + completion by `JAtZB.completeYieldJDN` (native step), then `VmEptState.actRestV`. Unlike the native + `JAtZ.activateJV`, no `RunningVM` exclusion: `activateThreadV` has the case. +* **`VmEptState.finishVF`**: `VmEptState.scheduleVF`, `VmEptState.activateV`, P3/VmCheck's `VmEptState.checkCur`; the + end state an outcome of `fl4KernelExitVF on rc σ`, `VmEptState` there. + +Premises: `VmEptState.scheduleVF`'s (its hypotheses, with the native `KFinAtR8` records `ArchRefines`, `ArchSwF`, +`ArchNdF`, `FpuOwnOK σ`, `IdleVt σ` [J] at the finish state, and the full domain-time disjunction), `VmEptState.checkCur`'s ([P] +`ZvVirtAgree`, `P0.ArchTotal`) and the platform's `ticks_to_us` / `getMaxTicksToUs` [P] (`hmax`, `htu`, as the native +`jat_finishJ`). Gen 42b83 routes the finish through the FPU-aware schedule. No new named premise. +-/ +import Fl4Proofs.P3.VmSchedule +import Fl4Proofs.P3.VmCheck +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section Spec +open Fl4Spec + +/-- `activateThreadV`'s state dispatch after the yield completion (module docstring). -/ +def actRestSV (t : ObjRef) : SMonad Unit Unit := do + let state ← getThreadState t + match state with + | .running => return () + | .runningVM => return () + | .restart => do + let pc ← asUser t getRestartPC + asUser t <| setNextPC pc + setThreadState t .running + | .idleThreadState => archActivateIdleThread t + | _ => NonDet.fail + +theorem activateThreadV_eqY {σ : State Unit} {x : Tcb} (hk : σ.kheap σ.curThread = some (.tcb x)) : + activateThreadV (Z := Unit) σ = + ((NonDet.when (x.tcbYieldTo ≠ none) (completeYieldTo σ.curThread) : SMonad Unit Unit) >>= fun _ => + actRestSV σ.curThread) σ := by + unfold activateThreadV + show (NonDet.gets _ >>= _) σ = _ + rw [Notif.nd_bind_one (show NonDet.gets (fun s : State Unit => s.curThread) σ = ({(σ.curThread, σ)}, False) from rfl)] + rw [Notif.nd_bind_one (Endp.getTcbObjRef_eq _ hk)] + rfl + +end Spec + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} {XL : U64 → Nat} + +set_option maxHeartbeats 4000000 in +/-- **`activate_thread`'s state dispatch at `VmEptState`** (module docstring). -/ +theorem VmEptState.actRestV (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hct : ct ∈ Z.T) (hcur : σ.curThread = ct.bv) (hcr : CurRunW σ) : + (do + let st0 ← obj.Tcb.state st ct s + if st0 = sched.TS_RESTART then + let pc ← obj.Tcb.reg st ct s layout.reg.FAULT_IP + let s2 ← obj.Tcb.set_reg st ct s layout.reg.NEXT_IP pc + let s3 ← sched.set_thread_state st s2 ct sched.TS_RUNNING + ok (s3, a) + else ok (s, a)) ⦃ r => ∃ σ', actRestSV ct.bv σ = ({((), σ')}, False) ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D r.1 r.2 σ' ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, hTR⟩ := hI.1.tcb ct hct + have hst : (L.mem s (tStA ct)).val = tsCode x.tcbState := hTR.st + have hk' : σ.kheap σ.curThread = some (.tcb x) := by rw [hcur]; exact hk + have hxs := hI.1.toE.at_tcb hct hk + have hrun : x.tcbState = .running ∨ x.tcbState = .restart ∨ x.tcbState = .idleThreadState ∨ + x.tcbState = .runningVM := by + rcases hcr with h | h + · have h1 := h x hk' + revert h1 + generalize x.tcbState = ts + cases ts <;> simp [Fl4Spec.runnable] + · obtain ⟨xi, hki, -, hsi, -⟩ := B.act.2 + rw [← h, hk'] at hki; cases hki; exact Or.inr (Or.inr (Or.inl hsi)) + step with Notif.obj.Tcb.state.spec as ⟨v, hv⟩ + subst hv + by_cases hrs : x.tcbState = .restart + · have hv2 : L.mem s (tStA ct) = sched.TS_RESTART := + UScalar.eq_of_val_eq (by rw [hst, hrs]; unfold sched.TS_RESTART; rfl) + rw [if_pos hv2] + step with Endp.obj.Tcb.reg.spec as ⟨pc, hpc⟩ + step with Endp.obj.Tcb.set_reg.spec as ⟨s2, hs2⟩ + subst hs2 + have hX2 := reg_wr_irel B.ip hI hct hk Fl4Spec.Register.nextIP (by decide) pc + rw [regIdx_nextIP] at hX2 + obtain ⟨V2, B2, F2⟩ := B.regWrJ hct hk Fl4Spec.Register.nextIP pc (by rw [regIdx_nextIP]; exact hX2) + rw [regIdx_nextIP] at B2 F2 + have J2 := J.ofNat B2 F2 + have hk2 : (updK σ ct.bv (.tcb (setReg x Fl4Spec.Register.nextIP pc.bv))).kheap ct.bv = + some (.tcb (setReg x Fl4Spec.Register.nextIP pc.bv)) := by simp [updK] + refine WP.spec_bind (B2.runJ hct hk2 hrs) ?_ + rintro s3 ⟨Lst3, B3, F3⟩ + refine (WP.spec_ok _).2 ⟨stsAct (updK (updK σ ct.bv (.tcb (setReg x Fl4Spec.Register.nextIP pc.bv))) ct.bv + (.tcb { setReg x Fl4Spec.Register.nextIP pc.bv with tcbState := .running })) ct.bv, ?_, V2, Ac, Lst3, ?_⟩ + swap + · have J3 := J2.ofNat (V' := V2) B3 F3 + (first | exact ⟨⟨(J3).1.1, (J3).1.2⟩, (J3).2⟩ | exact ⟨(J3).1.1, (J3).1.2, (J3).2⟩) + have hreg : x.tcbArch.tcbContext.userRegs .faultIP = pc.bv := by + rw [← hxs.regs .faultIP, regIdx_faultIP, hpc] + unfold actRestSV + rw [Notif.nd_bind_one (getThreadState_eq hk), hrs] + show (Fl4Spec.asUser ct.bv (Fl4Spec.getRegister .faultIP) >>= fun pc => + Fl4Spec.asUser ct.bv (Fl4Spec.setRegister .nextIP pc) >>= fun _ => + Fl4Spec.setThreadState ct.bv .running) σ = _ + rw [Notif.nd_bind_one (asUser_getRegister_eq hk .faultIP), hreg, + Notif.nd_bind_one (asUser_setRegister_eq .nextIP pc.bv hk), setThreadState_eq' hk2] + · have hv2 : L.mem s (tStA ct) ≠ sched.TS_RESTART := fun e => + hrs (Vs.tsCode_two (by rw [← hst, e]; unfold sched.TS_RESTART; rfl)) + rw [if_neg hv2] + refine (WP.spec_ok _).2 ⟨σ, ?_, Z.vs, Ac, Lst, ?_⟩ + swap + · (first | exact ⟨⟨(J).1.1, (J).1.2⟩, (J).2⟩ | exact ⟨(J).1.1, (J).1.2, (J).2⟩) + unfold actRestSV + rw [Notif.nd_bind_one (getThreadState_eq hk)] + rcases hrun with e | e | e | e + · rw [e]; rfl + · exact absurd e hrs + · rw [e]; rfl + · rw [e]; rfl + +set_option maxHeartbeats 4000000 in +/-- **FL4's `activate_thread` at `VmEptState` refines `activateThreadV`** (module docstring). -/ +theorem VmEptState.activateV (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hAT : P0.ArchTotal arI) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) (hcr : CurRunW σ) : + sched.activate_thread st arI s a ⦃ r => ∃ σ', Fl4Spec.activateThreadV (Z := Unit) σ = ({((), σ')}, False) ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D r.1 r.2 σ' ⦄ := by + have B := J.1.1 + unfold sched.activate_thread + step with Sched.sched.cur_thread.spec' as ⟨ct, ect⟩ + have hct : sched.cur_thread st s = ok ct := by rw [ect]; exact cur_thread_eq s + obtain ⟨hcur, -⟩ := B.curEq hct + have hctT : ct ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm + obtain ⟨xc, hkc, eyt⟩ := B.yld.tcb ct hctT + have hkc' : σ.kheap σ.curThread = some (.tcb xc) := by rw [hcur]; exact hkc + have hspec := activateThreadV_eqY hkc' + rw [hcur] at hspec + step with P1.obj.Tcb.yield_to.spec as ⟨i, hi⟩ + subst hi + refine WP.spec_bind (Pₘ := fun r : S × A => ∃ σ1, + (Fl4Spec.NonDet.when (xc.tcbYieldTo ≠ none) (Fl4Spec.completeYieldTo ct.bv) : Fl4Spec.SMonad Unit Unit) σ = + ({((), σ1)}, False) ∧ σ1.curThread = ct.bv ∧ CurRunW σ1 ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D r.1 r.2 σ1) ?_ ?_ + · by_cases h0 : L.mem s (P1.yieldA ct) = 0#u64 + · have hb : (L.mem s (P1.yieldA ct) != 0#u64) = false := by simp [h0] + simp only [hb, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + have hxn : xc.tcbYieldTo = none := by rw [eyt, h0, Notif.optRef_zero] + refine ⟨σ, ?_, hcur, hcr, Z.vs, Ac, Lst, J⟩ + rw [nd_when_false_y (by rw [hxn]; simp)]; rfl + · have hb : (L.mem s (P1.yieldA ct) != 0#u64) = true := by simp [h0] + simp only [hb, ↓reduceIte] + have hyt : xc.tcbYieldTo = some (L.mem s (P1.yieldA ct)).bv := by rw [eyt, Notif.optRef_ne h0] + obtain ⟨-, y, n, hky, -⟩ := B.yld.toSc ct hctT h0 + refine WP.spec_mono (B.completeYieldJDN hAT hmax htu hctT) ?_ + rintro ⟨s1, a1⟩ ⟨σ1, hcy, V1, Ac1, Lst1, B1, F1⟩ + obtain ⟨hsf, -, -⟩ := completeYieldTo_sframe hkc hyt hky hcy + have hcur1 : σ1.curThread = ct.bv := hsf.cur.trans hcur + obtain ⟨xc1, hkc1, hst1, -⟩ := hsf.tcb _ xc hkc + refine ⟨σ1, ?_, hcur1, ?_, V1, Ac1, Lst1, J.ofNat B1 F1⟩ + · unfold Fl4Spec.NonDet.when + rw [if_pos (by rw [hyt]; simp)] + exact hcy + · rcases hcr with h | h + · refine Or.inl fun x hx => ?_ + rw [hcur1, hkc1] at hx; cases hx + rw [hst1]; exact h xc hkc' + · exact Or.inr (by rw [hsf.cur, hsf.idle]; exact h) + rintro ⟨s1, a1⟩ ⟨σ1, hw1, hcur1, hcr1, V1, Ac1, Lst1, J1⟩ + rw [Notif.nd_bind_one hw1] at hspec + refine WP.spec_mono (J1.actRestV hctT hcur1 hcr1) ?_ + rintro r ⟨σ', he, V2, Ac2, Lst2, J2⟩ + refine ⟨σ', hspec.trans he, V2, Ac2, Lst2, ?_⟩ + (first | exact ⟨⟨(J2).1.1, (J2).1.2⟩, (J2).2⟩ | exact ⟨(J2).1.1, (J2).1.2, (J2).2⟩) + +set_option maxHeartbeats 4000000 in +/-- **FL4's `finish` at `VmEptState` against `fl4KernelExitVF`** (module docstring). -/ +theorem VmEptState.finishVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {on rc : Fl4Spec.ObjRef → Bool} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hO : VmOrc st on rc s σ) (hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ) (hnd : Fl4Spec.numDomains = 1) + (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) + (hRef : ArchRefines arI AR) (hAF : ArchSwF st arI Z.N Z.T Z.C Z.c) (hAN : ArchNdF st Z.N Z.T Z.C Z.c) + (hFO : FpuOwnOK σ) (hIV : IdleVt σ) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + syscall.finish st arI s a ⦃ r => ∃ σ' : Fl4Spec.State Unit, + ((), σ') ∈ (Fl4Spec.fl4KernelExitVF (Z := Unit) on rc σ).1 ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + unfold syscall.finish + refine WP.spec_bind (J.scheduleVF hAT hVA hK hmb hO hd hnd hsni hsend hT hRef hAF hAN hFO hIV) ?_ + rintro ⟨s1, a1⟩ ⟨σ1, σ2, h1, h2, ⟨V2, Ac2, Lst2, D2, J2⟩, -, hR⟩ + refine WP.spec_bind (J2.activateV hAT hmax (htu a1) hR) ?_ + rintro ⟨s3, a3⟩ ⟨σ3, h3, V3, Ac3, Lst3, J3⟩ + step with Sched.sched.cur_thread.spec' as ⟨ct, ect⟩ + have hct : sched.cur_thread st s3 = ok ct := by rw [ect]; exact cur_thread_eq s3 + refine WP.spec_mono (J3.checkCur hAT hVA hct) ?_ + rintro r ⟨σ4, Ac4, Lst4, h4, J4, -⟩ + refine ⟨σ4, ?_, V3, Ac4, Lst4, D2, ?_⟩ + swap + · (first | exact ⟨⟨(J4).1.1, (J4).1.2⟩, (J4).2⟩ | exact ⟨(J4).1.1, (J4).1.2, (J4).2⟩) + unfold Fl4Spec.fl4KernelExitVF + exact nd_mem_bind h1 (nd_mem_bind (by rw [h2]; exact Set.mem_singleton _) + (nd_mem_bind (by rw [h3]; exact Set.mem_singleton _) + (nd_mem_bind (Set.mem_singleton _) (by rw [h4]; exact Set.mem_singleton _)))) + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmHandle.lean b/proofs/Fl4Proofs/P3/VmHandle.lean new file mode 100644 index 000000000..1bf7cf3c8 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmHandle.lean @@ -0,0 +1,106 @@ +/- +P3 (line mmuAD, gen 42b67, option (b) step b4, first part): **`handle_invocation`'s native arms at `VmEptState`** — +the pieces HandleTopG's `handle_invocation_refinesMXPG` asks at `X` = `VEAny` (P3/VmDisp) besides the decode, +each a native `JAtZB` arm with the native footprint `NatFoot` transported by P3/EptReport's `VmEptState.ofNat`: + +* **`VmEptState.handleFaultV`**: `handle_fault` of a cap fault (`hFL` / the fault side of `hrr`): P3/XTopJointFaultRecv's + `JAtZB.faultHypJZ` (every handler cap; post `JAtN`, P3/XTopJointNoFault). **`VmEptState.extraV`**: the extra caps' + lookups both succeed or both fault with `CapFaultCorr` (P3/FrontEndExtra's `JAtZB.extraJ`). +* **`VmEptState.flTailV`**: the success tail (`hRepS`): P3/XTopJointReplyTail's `JAtZB.flTailJ`. +* **`VmEptState.replyFailV`**: the decode-error reply (`hRepF`, `rep = true`): `JAtZB.replyFailJ`. +* **`VEAny.repS`** / **`VEAny.repF`**: the two in `handle_invocation_refinesMXPG`'s shape (every `VEAny` state). + +No named premise; no route through `JAtZV3`. No existing statement changed. New file. +-/ +import Fl4Proofs.P3.VmDisp +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable {AR : A → Fl4Spec.Cr3 → Prop} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Endp + +/-- **`handle_fault` of a cap fault at `VmEptState`** (module docstring). -/ +theorem VmEptState.handleFaultV (hAT : P0.ArchTotal arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.1.1.faultHypJZ hAT hni hct hnq hvfh hf) fun _ ⟨z, hz, hR, _, _, _, _, B', F⟩ => + ⟨z, hz, hR, (J.ofNat B' F).any arI⟩ + +/-- **The extra caps' lookups at `VmEptState`** (module docstring). -/ +theorem VmEptState.extraV (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) + {info : msginfo.MessageInfo} (hinfo : msg.msg_info st s ct = ok info) + {mi : Fl4Spec.MessageInfo} (hmi : Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False)) + {buf : U64} (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) + {buffer : Option Fl4Spec.ObjRef} + (hbuffer : Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False)) + {r2 : core.result.Result (Aeneas.Std.Array obj.Slot 3#usize) error.Fault} + (hr2 : ipc.lookup_extra_caps st s ct buf info = ok r2) + {er : Except Fl4Spec.Fault (List (Fl4Spec.Cap × Fl4Spec.CslotPtr))} + (her : (Fl4Spec.lookupExtraCaps (Z := Unit) ct.bv buffer mi).run σ = ({(er, σ)}, False)) : + (∃ e exs, r2 = .Ok e ∧ er = .ok exs) ∨ (∃ f f', r2 = .Err f ∧ er = .error f' ∧ CapFaultCorr f f') := + J.1.1.extraJ J.1.1.xferH.1 J.1.1.xferH.2.1 hct hinfo hmi hbuf hbuffer hr2 her + +/-- **The success tail at `VmEptState`** (module docstring). -/ +theorem VmEptState.flTailV (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hcur : σ.curThread = ct.bv) (call : Bool) : + flTail (st := st) ct call s a ⦃ res => res.1 = .Ok () ∧ + ∃ z ∈ (specTail call ct.bv [] σ).1, RelTopM (L := L) res.2.1 z.2 ∧ VEAny (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + WP.spec_mono (J.1.1.flTailJ hcur call) fun _ ⟨h1, z, hz, hR, _, _, B', F⟩ => + ⟨h1, z, hz, hR, (J.ofNat B' F).any arI⟩ + +/-- **The decode-error reply at `VmEptState`** (module docstring). -/ +theorem VmEptState.replyFailV (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hcur : σ.curThread = ct.bv) (is_call : Bool) (e : error.SysError) (e' : Fl4Spec.SyscallError) + (he : ErrRel (.Sys e) e') : + ((if is_call then do + let s2 ← syscall.reply_error st s ct e + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s2, a) + else ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s, a)) : + Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ res => + res.1 = .Ok () ∧ ∃ z ∈ ((Fl4Spec.NonDet.when is_call <| + Fl4Spec.fl4ReplyFromKernelError true ct.bv (Fl4Spec.msgFromSyscallError e')) σ).1, + RelTopM (L := L) res.2.1 z.2 ∧ VEAny (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + WP.spec_mono (J.1.1.replyFailJ hcur is_call e e' he) fun _ ⟨h1, z, hz, hR, _, B', F⟩ => + ⟨h1, z, hz, hR, (J.ofNat B' F).any arI⟩ + +/-- `handle_invocation_refinesMXPG`'s `hRepS` at `VEAny` (`VmEptState.flTailV`). -/ +theorem VEAny.repS (ct : U64) (is_call : Bool) (s1 : S) (a1 : A) (σ' : Fl4Spec.State Unit) + (_ : RelTopM (L := L) s1 σ') (hX : VEAny (L := L) arI AR s1 a1 σ') (hcur : σ'.curThread = ct.bv) : + flTail (st := st) ct is_call s1 a1 ⦃ res => res.1 = .Ok () ∧ + ∃ z ∈ (specTail is_call ct.bv [] σ').1, RelTopM (L := L) res.2.1 z.2 ∧ + VEAny (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + match hX with + | ⟨_, _, _, _, _, _, _, _, _, J⟩ => J.flTailV arI hcur is_call + +/-- `handle_invocation_refinesMXPG`'s `hRepF` at `VEAny` (`VmEptState.replyFailV`, `rep = true`). -/ +theorem VEAny.repF {ct : U64} (hcur : σ.curThread = ct.bv) (is_call : Bool) (a1 : A) (e : error.SysError) + (e' : Fl4Spec.SyscallError) (hX : VEAny (L := L) arI AR s a1 σ) (he : ErrRel (.Sys e) e') : + ((if is_call then do + let s2 ← syscall.reply_error st s ct e + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s2, a1) + else ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s, a1)) : + Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ res => + res.1 = .Ok () ∧ ∃ z ∈ ((Fl4Spec.NonDet.when is_call <| + Fl4Spec.fl4ReplyFromKernelError true ct.bv (Fl4Spec.msgFromSyscallError e')) σ).1, + RelTopM (L := L) res.2.1 z.2 ∧ VEAny (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + match hX with + | ⟨_, _, _, _, _, _, _, _, _, J⟩ => J.replyFailV arI hcur is_call e e' he + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmHandleTop.lean b/proofs/Fl4Proofs/P3/VmHandleTop.lean new file mode 100644 index 000000000..f949067fa --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmHandleTop.lean @@ -0,0 +1,168 @@ +/- +P3 (line mmuAD, gen 42b68, option (b) step b4, the Architect's ruling 12:36Z): **`handle_invocation` at `VmEptState` +against the extended handler `fl4HandleInvocationVF`** (`VmEptState.handleInvocation`). + +* **`pp_err_uniq`** (spec): the spec's preemption point has one `error` outcome (XTopJointPPH's `pp_err_eq`, the + clock and the IRQ line being oracles of the machine state: `getCurrentTime_eq`, `getActiveIRQ_eq`). +* **`VmEptPre.relTopM`** (item 1): the preempted state of P3/RetVmReset's `VmEptPre` is related (`RelTopM`). The + preemption point's footprint at `JAtZB` is P3JDelMT's `JAtZB.ppJDMC` (gen 42b50 moved it to `JAtZB`; it gives + `XTopAt` at every outcome, preempted included), so nothing is generalised; its `σ'` is `VmEptPre`'s by + `pp_err_uniq`. Platform facts: the existing [P] records `ARKeep`, `ArchTotal`, `MachPlatC`, `PPPlatA` and + `numDomains = 1` (as at P3/VmCnodeAll's `cnodeDecodeAll`). +* **`VEAny.relTop`**; **`VDispPostVE.toG`**: P3/VmDisp's dispatcher post gives HandleTopG's `TopPostDMXPG` at the + extended dispatcher, `X` = `VEAny`, `XP` = some `VmEptPre` (the decode error is not `Preempted`: + `ErrRel.not_preempted`). `VDispPostVE` is unchanged. +* **`VmEptState.handleInvocation`** (item 3): HandleTopG's `handle_invocation_refinesMXPG` at + `(fl4DecodeInvocationV, fl4PerformInvocationVF onCore remoteCur)`, `rep = true`, from a `VmEptState` entry state: + the fault arms by P3/VmHandle's `VmEptState.handleFaultV` / `extraV`, the tails by `VEAny.repS` / `repF`, `hPK` by + P3/VmPerfCur's `perfCurKeepVF` (item 2), and the decode of the looked-up cap through `VDispPostVE.toG` from the + cap's dispatcher post `hDisp` (`VDispPostVE`: P3/VmDisp's `VmEptState.decodeDisp` gives it for every VM-side arm). + The post is `HIPostMXPG`'s, an outcome of `fl4HandleInvocationVF onCore remoteCur true` (HandleTopG's + `fl4HandleInvocationVF_hiG`, `rfl`) with `VEAny`, or some `VmEptPre` after a preemption. + +No named premise ([P] records only the existing ones listed above, [J] facts of the entry state `Entered`, the ready +queues and the fault handler as at `VmEptState.handleFaultV`). No route through `JAtZV3`. No existing statement +changed. New file. +-/ +import Fl4Proofs.P3.VmHandle +import Fl4Proofs.P3.VmPerfCur +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +/-- **The spec's preemption point has one `error` outcome** (module docstring). -/ +theorem pp_err_uniq (hnd : Fl4Spec.numDomains = 1) {σ σa σb : Fl4Spec.State Unit} + (ha : ((.error (), σa) : Except Unit Unit × Fl4Spec.State Unit) ∈ + ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1) + (hb : ((.error (), σb) : Except Unit Unit × Fl4Spec.State Unit) ∈ + ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1) : σa = σb := by + have h := pp_err_eq (Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ.machineState))) + (doMachineOp_single (getActiveIRQ_eq true _)) + exact (h _ ha rfl).trans (h _ hb rfl).symm + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched Fl4Proofs.P1 Fl4Proofs.P3.Endp + +/-- **The preempted state of `VmEptPre` is related** (module docstring). -/ +theorem VmEptPre.relTopM (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) {V X : Set U64} {XL : U64 → Nat} {s : S} {a : A} + {σ : Fl4Spec.State Unit} (h : VmEptPre (L := L) arI V X XL AR MR s a σ) : RelTopM (L := L) s σ := by + obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, ⟨J, -, -, hP0, hMR, hVT, -⟩, hpp, hy⟩ := h + have hw := J.1.1.ppJDMC hAK hA hnd hM hPA hMR hVT hP0 + rw [hpp, WP.spec_ok] at hw + obtain ⟨σ', hor, hX, -⟩ := hw + rcases hor with ⟨h1, -⟩ | ⟨-, hσ'⟩ + · cases h1 + · rw [← pp_err_uniq hnd hσ' hy]; exact hX.relTop + +/-- Every `VEAny` state is related. -/ +theorem VEAny.relTop {s : S} {a : A} {σ : Fl4Spec.State Unit} (h : VEAny (L := L) arI AR s a σ) : + RelTopM (L := L) s σ := + match h with + | ⟨_, _, _, _, _, _, _, _, _, J⟩ => J.1.1.xtop.relTop + +/-- **The VM-side dispatcher post in HandleTopG's form** (module docstring). -/ +theorem VDispPostVE.toG (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) {onCore remoteCur : Fl4Spec.ObjRef → Bool} + {σ : Fl4Spec.State Unit} {blk call don : Bool} {m : Fl4Spec.SEMonad Unit Fl4Spec.Fl4InvocationV} {s : S} + {res : core.result.Result Unit error.Exc × S × A} + (h : VDispPostVE (L := L) arI AR MR onCore remoteCur σ blk call don m s res) : + TopPostDMXPG (L := L) (Fl4Spec.fl4PerformInvocationVF (Z := Unit) onCore remoteCur) (VEAny (L := L) arI AR) + (fun s a σ => ∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR s a σ) + σ blk call don m s res := by + rcases h with ⟨e, h1, h2, ⟨e', h3, h3'⟩, h4⟩ | ⟨inv, hd, σ1, hst, y, hy, ⟨h1, hy1, hX⟩ | ⟨h1, hy1, V, X, XL, hP⟩⟩ + · have hne : res.1 ≠ .Err .Preempted := by + rw [h1]; intro he; cases he; exact ErrRel.not_preempted h3' + refine Or.inl ⟨e, h1, h2, ⟨e', h3, h3'⟩, ?_⟩ + try dsimp only + rw [if_neg hne]; exact h4 + · have hne : res.1 ≠ .Err .Preempted := by rw [h1]; intro he; cases he + obtain ⟨th, G, hR⟩ := hX.relTop arI + refine Or.inr ⟨inv, hd, σ1, hst, y, hy, ⟨th, G, Or.inl ⟨h1, hy1⟩, hR⟩, ?_⟩ + try dsimp only + rw [if_neg hne]; exact hX + · obtain ⟨th, G, hR⟩ := hP.relTopM arI hAK hA hnd hM hPA + refine Or.inr ⟨inv, hd, σ1, hst, y, hy, ⟨th, G, Or.inr ⟨h1, hy1⟩, hR⟩, ?_⟩ + try dsimp only + rw [if_pos h1]; exact ⟨V, X, XL, hP⟩ + +set_option maxHeartbeats 4000000 in +/-- **`handle_invocation` at `VmEptState` refines `fl4HandleInvocationVF onCore remoteCur true`** (module +docstring): `VEAny` after, some `VmEptPre` after a preemption. -/ +theorem VmEptState.handleInvocation (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) (onCore remoteCur : Fl4Spec.ObjRef → Bool) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} {s : S} {ar : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s ar σ) (hni : Entered σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (is_call blocking can_donate first_phase : Bool) (cptr : U64) + -- the front end's reads (`HIRead`) + (info : msginfo.MessageInfo) (hinfo : msg.msg_info st s ct = ok info) + (mi : Fl4Spec.MessageInfo) (hmi : Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False)) + (buf : U64) (hbuf : msg.lookup_ipc_buffer st s false ct = ok buf) + (buffer : Option Fl4Spec.ObjRef) + (hbuffer : Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False)) + (r2 : core.result.Result (Aeneas.Std.Array obj.Slot 3#usize) error.Fault) + (hr2 : ipc.lookup_extra_caps st s ct buf info = ok r2) + (er : Except Fl4Spec.Fault (List (Fl4Spec.Cap × Fl4Spec.CslotPtr))) + (her : (Fl4Spec.lookupExtraCaps (Z := Unit) ct.bv buffer mi).run σ = ({(er, σ)}, False)) + (args : List Fl4Spec.Data) (hmrs : Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(args, σ)}, False)) + -- the decode and invocation of the looked-up cap, in the dispatcher post's form + (hDisp : ∀ (sl : Fl4Spec.CslotPtr) (c : capability.Cap) (e : Aeneas.Std.Array obj.Slot 3#usize) + (exs : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), (∃ p, sl.1 = p.bv ∧ Z.th p = some (.cnode sl.2.length)) → + capAt (L.mem s) (cslotAddr sl) = ok c → + Fl4Spec.getCap (Z := Unit) sl σ = ({(absCap c, σ)}, False) → r2 = .Ok e → er = .ok exs → + syscall.decode_invocation st arI s ar info.label (msgLen info buf) (cslotAddr sl) c blocking is_call + can_donate first_phase buf e ⦃ res => + let m := specDecV first_phase mi.miLabel args (Fl4Spec.toBl cptr.bv) sl c exs buffer + VDispPostVE (L := L) arI AR MR onCore remoteCur σ blocking is_call can_donate m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) onCore remoteCur σ blocking is_call can_donate m ct s res ⦄) : + syscall.handle_invocation st arI s ar is_call blocking can_donate first_phase cptr ⦃ res => + ∃ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) onCore remoteCur true is_call blocking can_donate + first_phase (Fl4Spec.toBl cptr.bv)).run σ).1, + ((res.1 = .Ok () ∧ y.1 = .ok ()) ∨ (res.1 = .Err .Preempted ∧ y.1 = .error ())) ∧ + RelTopM (L := L) res.2.1 y.2 ∧ + (if res.1 = .Err .Preempted then + ∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR res.2.1 res.2.2 y.2 + else VEAny (L := L) arI AR res.2.1 res.2.2 y.2) ⦄ := by + obtain ⟨hcur, -⟩ := J.1.1.curEq hct + have hX := J.1.1.xtop + have htcb := (hX.curTcb hcur).1 + refine handle_invocation_refinesMXPG arI Fl4Spec.fl4DecodeInvocationV + (Fl4Spec.fl4PerformInvocationVF (Z := Unit) onCore remoteCur) (VEAny (L := L) arI AR) + (fun s a σ => ∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR s a σ) true s ar σ + Z.th Z.G hX.rel.1 hX.rel.2.1 hX.rel.2.2.1 hX.rel.2.2.2.1 hX.rel.2.2.2.2.1 (J.any arI) ct hct hcur htcb + is_call blocking can_donate first_phase cptr info hinfo mi hmi buf hbuf buffer hbuffer r2 hr2 er her ?rr + args hmrs ?fl ?repS ?repF ?pk ?dec + case rr => + exact (J.extraV arI hct hinfo hmi hbuf hbuffer hr2 her).imp id fun ⟨f, f', h1, h2, hf⟩ => + ⟨f, f', h1, h2, fun _ => J.handleFaultV arI hA hni hct hnq hvfh hf⟩ + case fl => exact fun _ _ _ hl => J.handleFaultV arI hA hni hct hnq hvfh (capFaultCorr_lookup cptr hl) + case repS => exact fun s1 a1 σ' hR hX1 hc => VEAny.repS arI ct is_call s1 a1 σ' hR hX1 hc + case repF => exact fun a1 e e' hX1 he => VEAny.repF arI hcur is_call a1 e e' hX1 he + case pk => + intro inv σ1 y hst hy + rw [perfCurKeepVF onCore remoteCur _ _ _ inv σ1 y hy, ← hcur] + exact (dk_setThreadState' _ _).ct + (show ((), σ1) ∈ (Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ).1 by + rw [hst]; exact Set.mem_singleton _) + case dec => + intro sl c e exs hsl hc hget he hexs + obtain ⟨res, hr, hp⟩ := P1.spec_ex_fd (hDisp sl c e exs hsl hc hget he hexs) + unfold XCapPG DecOKDMXPG DecOKRMXG + rcases hp with h | h + · exact Or.inl (by rw [hr, WP.spec_ok]; exact h.toG arI hAK hA hnd hM hPA) + · exact Or.inr (by rw [hr, WP.spec_ok]; exact h) + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmHiErr.lean b/proofs/Fl4Proofs/P3/VmHiErr.lean new file mode 100644 index 000000000..d48c8ceee --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmHiErr.lean @@ -0,0 +1,209 @@ +/- +P3 (line mmuAD, gen 42b82, the Architect's ruling item 2): **the error (preemption) outcomes of the extended +invocation handler leave the current thread not `runningVM`** (spec only; `hiVF_err_nrvm`). + +`fl4HandleInvocationVF` (HandleTopG's `hiG` at `fl4DecodeInvocationV` / `fl4PerformInvocationVF`) has an `error` +outcome only from its dispatcher, which starts after `setThreadState thread .restart` of the thread read at the entry; +the lookup and decode phases keep the current thread (P3/SpecInvNtfnQC's `CTK` frame), so the dispatcher starts from a +state whose current thread is `restart`, and P3/VmPerfRvm's `perfCtNVmVF` keeps that thread not `runningVM`. + +* The `CTK` leaves of the VCPU / EPT decoders (read-only: P3/VmDelFinSpec's `KeepSt` lookups `getVcpu`, `getEpt`, + `findGuestRoot`, `guestLookupSlot`), `ct_decodeVcpuInvocationV`, `ct_decodeEptInvocationV`, `ct_decodePageMapEptV`, + `ct_decodeEptAsidPoolAssignV`, `ct_decodeSetEptRootV`, **`ct_fl4DecodeInvocationV`** (as P3/VirtNoRunStep's + `ns_fl4DecodeInvocationV`). +* `ErrK P Q m`: every `error` outcome of `m` from a `P` state satisfies `Q`; `errK_liftE`, `errK_bind`. +* `sts_restart_nrvm`: `setThreadState t .restart` of the current thread leaves it not `runningVM`. +* **`hiG_err_nrvm`** (any decoder keeping the current thread, any dispatcher keeping `¬ RunningVM`), its instance + **`hiVF_err_nrvm`**: every `error` outcome `y` of `fl4HandleInvocationVF onCore remoteCur rep …` has + `¬ RunningVM y.2` (no hypothesis on the start state). + +No named premise. New file (spec only). +-/ +import Fl4Proofs.P3.VmPerfRvm +import Fl4Proofs.P3.SpecInvNtfnQC4 +import Fl4Proofs.P3.SpecInvNtfnQ +import Fl4Proofs.P3.SpecInvFaultTcbsH2 +import Fl4Proofs.P3.VmDelFinSpec +import Fl4Proofs.P3.VirtR7e +import Fl4Proofs.P3.HandleTopG +import Fl4Proofs.P3.ResetFin +import Fl4Proofs.P3.XTopJointMidRunS +open Classical + +namespace Fl4Proofs.P3.SInv +open Fl4Spec + +noncomputable section + +set_option maxHeartbeats 1000000 + +variable {cq : ObjRef} + +/-! ## The current-thread frame of the extended decoder -/ + +theorem ct_getVcpuV (v : ObjRef) : CTK cq (getVcpu (Z := Unit) v) := ik_of_keepSt (keepSt_getVcpu v) _ +macro_rules | `(tactic| ct_leaf) => `(tactic| with_reducible exact ct_getVcpuV _) + +theorem ct_getEptV (p : ObjRef) : CTK cq (getEpt (Z := Unit) p) := ik_of_keepSt (keepSt_getEpt p) _ +macro_rules | `(tactic| ct_leaf) => `(tactic| with_reducible exact ct_getEptV _) + +theorem ct_findGuestRootV (asid : Asid) : CTKE cq (findGuestRoot (Z := Unit) asid) := + ik_of_keepSt (keepSt_findGuestRoot asid) _ +macro_rules | `(tactic| ct_leaf) => `(tactic| with_reducible exact ct_findGuestRootV _) + +theorem ct_guestLookupSlotV (root : ObjRef) (gpa : Word) (level : Nat) : + CTKE cq (guestLookupSlot (Z := Unit) root gpa level) := + ik_of_keepSt (keepSt_guestLookupSlot root gpa level) _ +macro_rules | `(tactic| ct_leaf) => `(tactic| with_reducible exact ct_guestLookupSlotV _ _ _) + +theorem ct_decodeVcpuInvocationV (label : Data) (args : List Data) (v : ObjRef) (ex : List (Cap × CslotPtr)) : + CTKE cq (decodeVcpuInvocation (Z := Unit) label args v ex) := by + unfold decodeVcpuInvocation; ct_auto + +theorem ct_decodeEptInvocationV (label : Data) (args : List Data) (slot : CslotPtr) (c : ArchCap) + (ex : List (Cap × CslotPtr)) : CTKE cq (decodeEptInvocation (Z := Unit) label args slot c ex) := by + unfold decodeEptInvocation eptCapRoot guestSlot; ct_auto + +theorem ct_decodePageMapEptV (args : List Data) (slot : CslotPtr) (c : ArchCap) (ex : List (Cap × CslotPtr)) : + CTKE cq (decodePageMapEpt (Z := Unit) args slot c ex) := by + unfold decodePageMapEpt eptCapRoot guestSlot; ct_auto + +theorem ct_decodeEptAsidPoolAssignV (p : ObjRef) (b : Asid) (x : CslotPtr) : + CTKE cq (decodeEptAsidPoolAssign (Z := Unit) p b x) := by + unfold decodeEptAsidPoolAssign; ct_auto + +theorem ct_decodeSetEptRootV (t : ObjRef) (ex : List (Cap × CslotPtr)) : + CTKE cq (decodeSetEptRoot (Z := Unit) t ex) := by + unfold decodeSetEptRoot; ct_auto + +/-- **The extended decode keeps the current thread** (as `ns_fl4DecodeInvocationV`). -/ +theorem ct_fl4DecodeInvocationV (fp : Bool) (label : Data) (args : List Data) (ci : CapRef) (slot : CslotPtr) + (cap : Cap) (ex : List (Cap × CslotPtr)) (buf : Option ObjRef) : + CTKE cq (fl4DecodeInvocationV (Z := Unit) fp label args ci slot cap ex buf) := by + have hb : CTKE cq (NonDetE.liftME Fl4InvocationV.base + (fl4DecodeInvocation (Z := Unit) fp label args ci slot cap ex buf)) := + ike_liftME _ (ct_fl4DecodeInvocation _ _ _ _ _ _ _ _) + unfold fl4DecodeInvocationV + split + · exact ike_liftME _ (ct_decodeVcpuInvocationV _ _ _ _) + · exact ike_liftME _ (ct_decodeEptInvocationV _ _ _ _ _) + · split + · exact ike_liftME _ (ct_decodePageMapEptV _ _ _ _) + · split + · exact ike_throw _ + · split + · exact ike_returnOk _ + · exact hb + · split + · exact ike_liftME _ (ct_decodeEptAsidPoolAssignV _ _ _) + · exact hb + · split + · exact ike_liftME _ (ct_decodeSetEptRootV _ _) + · exact hb + · split + · exact ike_throw _ + · exact hb + · exact hb + +end + +end Fl4Proofs.P3.SInv + +namespace Fl4Proofs.P3 +open Fl4Spec Fl4Proofs.P3.SInv + +noncomputable section + +/-- Every `error` outcome of `m` from a `P` state satisfies `Q`. -/ +def ErrK (P Q : State Unit → Prop) {α : Type} (m : NonDetE (State Unit) Unit α) : Prop := + ∀ σ, P σ → ∀ y ∈ (m.run σ).1, y.1 = .error () → Q y.2 + +theorem errK_liftE {P Q : State Unit → Prop} {α : Type} (m : NonDet (State Unit) α) : + ErrK P Q (NonDetE.liftE (ε := Unit) m) := by + intro σ _ y hy he + obtain ⟨x, -, rfl⟩ := MidRun.mem_liftE_inv' hy + cases he + +theorem errK_bind {P Q : State Unit → Prop} {α β : Type} {m : NonDetE (State Unit) Unit α} + {f : α → NonDetE (State Unit) Unit β} (hm : IKE P m) (hm' : ErrK P Q m) (hf : ∀ a, ErrK P Q (f a)) : + ErrK P Q (m >>= f) := by + intro σ hP y hy he + obtain ⟨z, hz, ⟨a, hza, hy'⟩ | ⟨e, hze, rfl⟩⟩ := mem_bindE_inv hy + · exact hf a z.2 (hm σ hP z hz) y hy' he + · cases e; exact hm' σ hP z hz hze + +/-- `setThreadState t .restart` of the current thread leaves it not `runningVM`. -/ +theorem sts_restart_nrvm {t : ObjRef} {σ : State Unit} (hc : σ.curThread = t) {x : Unit × State Unit} + (hx : x ∈ (setThreadState (Z := Unit) t .restart σ).1) : ¬ RunningVM x.2 := by + unfold setThreadState at hx + obtain ⟨u, hu, hx'⟩ := mem_bind_elim hx + obtain ⟨x0, -, hu2⟩ := SInv.mem_threadSet hu + have hk : x.2.kheap t = some (.tcb { x0 with tcbState := .restart }) := + SInv.setThreadStateAct_kheap t (P := fun k => k t = some (.tcb { x0 with tcbState := .restart })) u.2 + (by rw [hu2]; simp) x hx' + have hct : x.2.curThread = t := + SInv.ct_setThreadStateAct (cq := t) t u.2 (by rw [hu2]; exact hc) x hx' + rintro ⟨xt, hk', hr⟩ + rw [hct, hk] at hk' + cases hk' + cases hr + +section +variable {ι : Type} + +/-- **An `error` outcome of `hiG` leaves the current thread not `runningVM`** (module docstring): for a decoder +keeping the current thread and a dispatcher keeping `¬ RunningVM`. -/ +theorem hiG_err_nrvm + {dec : Bool → Data → List Data → CapRef → CslotPtr → Cap → List (Cap × CslotPtr) → Option ObjRef → + SEMonad Unit ι} + {perf : Bool → Bool → Bool → ι → PMonad Unit (List Data)} + (hdec : ∀ c fp l args cptr sl cap ex buf, CTKE c (dec fp l args cptr sl cap ex buf)) + (hperf : ∀ blk call don inv σ1 y, y ∈ ((perf blk call don inv).run σ1).1 → ¬ RunningVM σ1 → ¬ RunningVM y.2) + {rep calling blocking canDonate firstPhase : Bool} {cptr : CapRef} {σ : State Unit} + {y : Except Unit Unit × State Unit} + (hy : y ∈ ((hiG (Z := Unit) dec perf rep calling blocking canDonate firstPhase cptr).run σ).1) + (he : y.1 = .error ()) : ¬ RunningVM y.2 := by + unfold hiG at hy + obtain ⟨z, hz, ⟨t, hzt, hy'⟩ | ⟨e, hze, rfl⟩⟩ := mem_bindE_inv hy + swap + · obtain ⟨x, -, rfl⟩ := MidRun.mem_liftE_inv' hz; cases hze + obtain ⟨x, hx, rfl⟩ := MidRun.mem_liftE_inv' hz + have hx1 : x = (σ.curThread, σ) := hx + subst hx1 + cases hzt + refine (?_ : ErrK (fun s => s.curThread = σ.curThread) (fun s => ¬ RunningVM s) _) σ rfl y hy' he + unfold syscall withoutPreemption + refine errK_bind (ike_liftE (ct_getMessageInfo _)) (errK_liftE _) fun info => ?_ + refine errK_bind (ike_liftE (VirtR7e.ik_lookupPart _ _ info (ct_capFaultOnFailure _ _ _ (ct_lookupCapAndSlot _ _)) + (ct_lookupIpcBuffer _ _) fun _ => ct_lookupExtraCaps _ _ _)) (errK_liftE _) fun r => ?_ + rcases r with f | ⟨slot, cap, ex, buf⟩ + · exact errK_liftE _ + refine errK_bind (ike_liftE (ike_bind (ike_liftE (ct_getMrs _ _ _)) fun args => hdec _ _ _ _ _ _ _ _ _)) + (errK_liftE _) fun r2 => ?_ + rcases r2 with e | oper + · exact errK_liftE _ + intro σ' hP' y hy he + obtain ⟨z, hz, ⟨u, -, hy2⟩ | ⟨e, hze, -⟩⟩ := mem_bindE_inv hy + · obtain ⟨x, hx, rfl⟩ := MidRun.mem_liftE_inv' hz + have hnr := sts_restart_nrvm hP' hx + obtain ⟨w, hw, ⟨r, -, hy3⟩ | ⟨e, hwe, rfl⟩⟩ := mem_bindE_inv hy2 + · obtain ⟨_, -, rfl⟩ := MidRun.mem_liftE_inv' hy3; cases he + · exact hperf _ _ _ _ _ _ hw hnr + · obtain ⟨_, -, rfl⟩ := MidRun.mem_liftE_inv' hz; cases hze + +end + +/-- **The error outcomes of `fl4HandleInvocationVF` keep the current thread out of `runningVM`** (module +docstring; ruling item 2). -/ +theorem hiVF_err_nrvm (onCore remoteCur : ObjRef → Bool) {rep calling blocking canDonate firstPhase : Bool} + {cptr : CapRef} {σ : State Unit} {y : Except Unit Unit × State Unit} + (hy : y ∈ ((fl4HandleInvocationVF (Z := Unit) onCore remoteCur rep calling blocking canDonate firstPhase + cptr).run σ).1) + (he : y.1 = .error ()) : ¬ RunningVM y.2 := by + rw [fl4HandleInvocationVF_hiG] at hy + exact hiG_err_nrvm (fun c _ _ _ _ _ _ _ _ => ct_fl4DecodeInvocationV (cq := c) _ _ _ _ _ _ _ _) + (fun blk call don inv σ1 y hy h => perfCtNVmVF onCore remoteCur blk call don inv σ1 y hy h) hy he + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmInvAfter.lean b/proofs/Fl4Proofs/P3/VmInvAfter.lean new file mode 100644 index 000000000..c018800eb --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmInvAfter.lean @@ -0,0 +1,233 @@ +/- +P3 (line mmuAD, gen 42b82, the Architect's ruling item 3): **`handle_invocation` then `after_invocation` at +`VmEptState`, the preempted arm's `VmOrc` asked at the post-invocation state** (`VmEptState.handleInvocationE`, +`VmEptState.afterV`). + +42b81's finding 7: P3/VmPreempt's `VmEptPre.preemptPathVFk` needs `VmOrc st on rc s1 σ1` at the PREEMPTED state of the +invocation; feeding it through FL4-outcome-dependent oracles (`onCoreEff st s0 s1`) would make +`VmEptState.handleInvocation`'s `hDisp` depend on FL4's own outcome. Here the oracles `on rc` are fixed parameters +(the entry's, those of `fl4KernelEntrySyscallVF on rc`), `hDisp` is asked at them, and `VmOrc` is asked only at the +preempted outcomes of the spec handler and their related FL4 states (`hO`), so the entry composes with +P3/VmFinish's `finishVF` at the same `on rc`. + +* `VDispAt on rc Z s ar σ ct call bl don fp cptr`: `VmEptState.handleInvocation`'s `hDisp` with the front reads + quantified (the reads' values and equations, then the looked-up slot / cap / extra caps). +* **`VmEptState.handleInvocationE`**: `VmEptState.handleInvocation` with the front reads discharged by + XTopJointDispatch's `JAtZB.frontEx` (generalised in place from `JAtZ.frontEx`, 42b82, which is now its instance) and + BufJ's `JAtZB.xferH`; post `HIPostVE` (`VmEptState.handleInvocation`'s, as a definition). +* **`VmEptState.afterV`**: `after_invocation` after it: not preempted, `(true, …)` with `VEAny` at the spec's + `.ok` outcome; preempted, `(false, …)` with `VEAny` at an outcome of `preemptionPathVF on rc` of the spec's + `.error` outcome (`VmEptPre.preemptPathVFk`, its `hnv` by P3/VmHiErr's `hiVF_err_nrvm`, its `hTU` from the + platform's `hmax` / `htu`, its `VmOrc` from `hO`) — `InvAfterVE`. + +Premises: the platform records of `VmEptState.handleInvocation` / `VmEptPre.preemptPathVFk` (existing [P]); `hDisp` and +`hO` are hypotheses here (named per-entry premises at P3/VmKEntry). No existing statement changed (`JAtZ.frontEx` +restated as `JAtZB.frontEx`'s instance, statement unchanged). New file. +-/ +import Fl4Proofs.P3.JAtZV3VFront +import Fl4Proofs.P3.VmHandleTop +import Fl4Proofs.P3.VmPreempt +import Fl4Proofs.P3.VmHiErr +import Fl4Proofs.P3.XTopJointDispatch +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable (AR : A → Fl4Spec.Cr3 → Prop) (MR : A → Fl4Spec.MachineState → Prop) + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Sched Fl4Proofs.P1 Fl4Proofs.P3.Endp + +/-- `VmEptState.handleInvocation`'s `hDisp` with the front reads quantified (module docstring). -/ +def VDispAtFor (scope : capability.Cap → Prop) (on rc : Fl4Spec.ObjRef → Bool) (Z : XSets) (s : S) (ar : A) (σ : Fl4Spec.State Unit) (ct : U64) + (is_call blocking can_donate first_phase : Bool) (cptr : U64) : Prop := + ∀ (info : msginfo.MessageInfo) (mi : Fl4Spec.MessageInfo) (buf : U64) (buffer : Option Fl4Spec.ObjRef) + (r2 : core.result.Result (Aeneas.Std.Array obj.Slot 3#usize) error.Fault) + (er : Except Fl4Spec.Fault (List (Fl4Spec.Cap × Fl4Spec.CslotPtr))) (args : List Fl4Spec.Data), + msg.msg_info st s ct = ok info → Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False) → + msg.lookup_ipc_buffer st s false ct = ok buf → + Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False) → + ipc.lookup_extra_caps st s ct buf info = ok r2 → + (Fl4Spec.lookupExtraCaps (Z := Unit) ct.bv buffer mi).run σ = ({(er, σ)}, False) → + Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(args, σ)}, False) → + ∀ (sl : Fl4Spec.CslotPtr) (c : capability.Cap) (e : Aeneas.Std.Array obj.Slot 3#usize) + (exs : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)), (∃ p, sl.1 = p.bv ∧ Z.th p = some (.cnode sl.2.length)) → + capAt (L.mem s) (cslotAddr sl) = ok c → + Fl4Spec.getCap (Z := Unit) sl σ = ({(absCap c, σ)}, False) → r2 = .Ok e → er = .ok exs → scope c → + syscall.decode_invocation st arI s ar info.label (msgLen info buf) (cslotAddr sl) c blocking is_call + can_donate first_phase buf e ⦃ res => + let m := specDecV first_phase mi.miLabel args (Fl4Spec.toBl cptr.bv) sl c exs buffer + VDispPostVE (L := L) arI AR MR on rc σ blocking is_call can_donate m s res ∨ + VDispReplyVE (L := L) arI (AR := AR) on rc σ blocking is_call can_donate m ct s res ⦄ + +/-- The full dispatcher post, assembled from native and VM/EPT producers. -/ +abbrev VDispAt := VDispAtFor (L := L) arI AR MR (fun _ => True) + +/-- The entry's native-cap decoder premise. -/ +abbrev VDispNativeAt := VDispAtFor (L := L) arI AR MR Vs.NativeCap + +set_option maxHeartbeats 4000000 in +/-- Assemble the invocation dispatcher from the native-cap premise and the VM/EPT producers. -/ +theorem VmEptState.dispatchAt [PlainStore st] + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + (hRef : ArchRefines arI AR) (hVA : ZvVirtAgree arI) + (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hAT : P0.ArchTotal arI) (hAM : ARMask arI AR) (hVal : PortInValAt arI a σ) + (on rc : Fl4Spec.ObjRef → Bool) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hRun : ZvCtRun σ ct) + (call blk don fp : Bool) (cptr : U64) + (hNative : VDispNativeAt (L := L) arI AR MR on rc Z s a σ ct call blk don fp cptr) : + VDispAt (L := L) arI AR MR on rc Z s a σ ct call blk don fp cptr := by + intro info mi buf buffer r2 er args hinfo hmi hbuf hbufS hr2 her hmrs sl c ex exs hsl hc hcs hr he _ + by_cases hN : Vs.NativeCap c + · exact hNative info mi buf buffer r2 er args hinfo hmi hbuf hbufS hr2 her hmrs sl c ex exs hsl hc hcs hr he hN + have B := J.1.1 + have hX := B.xferH + obtain ⟨hlbl, hExtra⟩ := B.frontJ hX.1 hX.2.1 hct hinfo hmi hbuf hbufS hr2 her + have heX := hExtra ex exs hr he + rw [← hlbl] + have hPl := B.xtop.rel.1 + obtain ⟨pc, hp, hpc⟩ := hsl + rcases sl with ⟨sp, idx⟩ + dsimp only at hp hpc + subst sp + have hAs : AbsSlot Z.th (pc.bv, idx) := ⟨pc, rfl, Or.inl hpc⟩ + have hV := B.vargs hct hinfo hmi hbuf hbufS hmrs + have hv' : VArgs st s (L.curW s) buf (msgLen info buf) args := by + have e : ct = L.curW s := ok_inj (hct.symm.trans (cur_thread_eq (L := L) s)) + exact e ▸ hV + let words := args.map fun x => (⟨x⟩ : U64) + have hmrs' : Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(words.map UScalar.bv, σ)}, False) := by + rw [show words.map UScalar.bv = args from zv_map_mk args] + exact hmrs + obtain ⟨hlen, hargs, -⟩ := B.argsJ hX.1 hX.2.1 hct hinfo hmi hbuf hbufS hmrs' + have hd := VmEptState.decodeDisp arI (MR := MR) hRef hVA J hni on rc + cases c <;> try exact (hN trivial).elim + case Vcpu p => + have hcap := capV_of_capAt hc + have hpv := J.1.2.extv.cap (cslotAddr (pc.bv, idx)) hAs.isSlot + rw [hcap] at hpv + exact hd.vcpu hK hSy hCap hAT hpv (capV_vcpu_canonical hcap) hct hRun blk call don fp + (B.bufOut J.1.2.vm hct hbuf) ex args hV exs heX (Fl4Spec.toBl cptr.bv) (pc.bv, idx) buffer + case Ept p level m asid va => + exact WP.spec_mono (hd.ept blk call don fp buf ex hpc rfl hc args hv' exs (ExtraOK.relS hPl heX) fp + (Fl4Spec.toBl cptr.bv) buffer) fun _ h => Or.inl h + case IoPort first last owner => + rw [← zv_map_mk args] + exact hd.ioPort hAM hAT hct hRun hVal words hlen hargs (pc.bv, idx) hAs (capV_of_capAt hc) + blk call don fp ex (Fl4Spec.toBl cptr.bv) exs buffer + case Frame p sz rt dev m ep asid va => + have hmep : m = true ∧ ep = true := Classical.byContradiction hN + obtain ⟨rfl, rfl⟩ := hmep + by_cases hE : info.label = fl4_abi.label.X86PageMapEPT + · have hEL : info.label.val = Fl4Spec.fl4PageMapEptLabel := by + rw [hE] + simp [fl4_abi.label.X86PageMapEPT, Fl4Spec.fl4PageMapEptLabel] + exact WP.spec_mono (hd.frameEpt hEL blk call don fp buf ex hpc rfl hc args hv' exs (ExtraOK.relS hPl heX) fp + (Fl4Spec.toBl cptr.bv) buffer) fun _ h => Or.inl h + have hFL := frame_label info.label hE + by_cases hu : info.label = fl4_abi.label.X86PageUnmap + · exact WP.spec_mono (hd.frameUnmap hu blk call don fp buf ex hpc rfl hc args exs fp + (Fl4Spec.toBl cptr.bv) buffer) fun _ h => Or.inl h + by_cases hm : info.label = fl4_abi.label.X86PageMap + · rw [hm] + exact WP.spec_mono (hd.frameMapReject hct p rt asid va (msgLen info buf) buf sz dev blk call don fp + (pc.bv, idx) ex args (Fl4Spec.toBl cptr.bv) exs buffer) fun _ h => Or.inl h + by_cases hg : info.label = fl4_abi.label.X86PageGetAddress + · exact WP.spec_mono (hd.frameGetAddr hct hRun hFL hg sz dev blk call don fp + (pc.bv, idx) ex args (Fl4Spec.toBl cptr.bv) exs buffer) fun _ h => Or.inr h + by_cases ht : info.label = fl4_abi.label.X86PageTestAndClearAccessed + · rw [ht] + exact WP.spec_mono (hd.frameTac hct hRun sz dev blk call don fp (pc.bv, idx) hAs (capV_of_capAt hc) + ex args (Fl4Spec.toBl cptr.bv) exs buffer) fun _ h => Or.inr h + by_cases hs : info.label = fl4_abi.label.X86PageDeriveSubframe + · rw [hs, ← zv_map_mk args] + exact WP.spec_mono (hd.frameDerive hpc hct hc words hlen hargs blk call don fp ex + (Fl4Spec.toBl cptr.bv) exs (ExtraOK.vsExtra hPl heX) buffer) fun _ h => Or.inl h + exact WP.spec_mono (hd.frameOther hct hFL hm hu hg ht hs p rt asid va (msgLen info buf) buf + sz dev blk call don fp (pc.bv, idx) ex args (Fl4Spec.toBl cptr.bv) exs buffer) fun _ h => Or.inl h + +/-- `VmEptState.handleInvocation`'s post. -/ +def HIPostVE (on rc : Fl4Spec.ObjRef → Bool) (σ : Fl4Spec.State Unit) (is_call blocking can_donate first_phase : Bool) + (cptr : U64) (res : core.result.Result Unit error.Exc × S × A) : Prop := + ∃ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true is_call blocking can_donate + first_phase (Fl4Spec.toBl cptr.bv)).run σ).1, + ((res.1 = .Ok () ∧ y.1 = .ok ()) ∨ (res.1 = .Err .Preempted ∧ y.1 = .error ())) ∧ + RelTopM (L := L) res.2.1 y.2 ∧ + (if res.1 = .Err .Preempted then + ∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR res.2.1 res.2.2 y.2 + else VEAny (L := L) arI AR res.2.1 res.2.2 y.2) + +/-- **`after_invocation`'s post** (module docstring) after an invocation `m` from `σ`. -/ +def InvAfterVE (on rc : Fl4Spec.ObjRef → Bool) (m : Fl4Spec.PMonad Unit Unit) (σ : Fl4Spec.State Unit) + (r : Bool × S × A) : Prop := + ∃ y ∈ (m.run σ).1, + (r.1 = true ∧ y.1 = .ok () ∧ VEAny (L := L) arI AR r.2.1 r.2.2 y.2) ∨ + (r.1 = false ∧ y.1 = .error () ∧ + ∃ z ∈ (Fl4Spec.preemptionPathVF (Z := Unit) on rc y.2).1, VEAny (L := L) arI AR r.2.1 r.2.2 z.2) + +variable {arI AR MR} + +/-- **`VmEptState.handleInvocation` with the front reads discharged** (module docstring). -/ +theorem VmEptState.handleInvocationE (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hM : MachPlatC arI MR) (hPA : PPPlatA arI AR) (on rc : Fl4Spec.ObjRef → Bool) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} {s : S} {ar : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s ar σ) (hni : Entered σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (is_call blocking can_donate first_phase : Bool) (cptr : U64) + (hD : VDispAt (L := L) arI AR MR on rc Z s ar σ ct is_call blocking can_donate first_phase cptr) : + syscall.handle_invocation st arI s ar is_call blocking can_donate first_phase cptr ⦃ res => + HIPostVE (L := L) arI AR MR on rc σ is_call blocking can_donate first_phase cptr res ⦄ := by + have hB := JAtZB.xferH (J := J.1.1) + obtain ⟨info, mi, buf, buffer, r2, er, argsU, h1, h2, h3, h4, h5, h6, h7⟩ := + JAtZB.frontEx arI J.1.1 hB.1 hB.2.1 hct + exact J.handleInvocation arI hAK hA hnd hM hPA on rc hni hct hnq hvfh is_call blocking can_donate first_phase + cptr info h1 mi h2 buf h3 buffer h4 r2 h5 er h6 _ h7 + (fun sl c e exs hsl hc hsc h2e hre => hD info mi buf buffer r2 er _ h1 h2 h3 h4 h5 h6 h7 sl c e exs hsl hc hsc h2e hre trivial) + +set_option maxHeartbeats 4000000 in +/-- **`after_invocation` after `VmEptState.handleInvocationE`** (module docstring): `VmOrc` asked at the preempted +outcomes only (`hO`). -/ +theorem VmEptState.afterV (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hPA : PPPlatA arI AR) (hIA : IrqPlatA arI AR) + (hmrt : ∀ a : A, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {σ : Fl4Spec.State Unit} {is_call blocking can_donate first_phase : Bool} + {cptr : U64} {res : core.result.Result Unit error.Exc × S × A} + (h : HIPostVE (L := L) arI AR MR on rc σ is_call blocking can_donate first_phase cptr res) + (hO : ∀ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true is_call blocking can_donate first_phase + (Fl4Spec.toBl cptr.bv)).run σ).1, y.1 = .error () → + ∀ (s1 : S) (a1 : A), (∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR s1 a1 y.2) → + VmOrc st on rc s1 y.2) : + syscall.after_invocation st arI res.2.1 res.2.2 res.1 ⦃ r => + InvAfterVE (L := L) arI AR on rc (Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true is_call blocking + can_donate first_phase (Fl4Spec.toBl cptr.bv)) σ r ⦄ := by + obtain ⟨y, hy, hres, -, hX⟩ := h + rcases hres with ⟨h1, hy1⟩ | ⟨h1, hy1⟩ + · rw [if_neg (by rw [h1]; intro e; cases e)] at hX + rw [h1] + unfold syscall.after_invocation + rw [WP.spec_ok] + exact ⟨y, hy, Or.inl ⟨rfl, hy1, hX⟩⟩ + · rw [if_pos h1] at hX + obtain ⟨V, X, XL, hP⟩ := hX + rw [h1] + refine WP.spec_mono (hP.preemptPathVFk hARI hAT hVA hARI.toARKeep hnd hM hMK hPA hIA hmrt + (fun _ => hiVF_err_nrvm on rc hy hy1) (fun _ => ⟨hmax, htu⟩) (hO y hy hy1 _ _ ⟨V, X, XL, hP⟩) .Preempted) ?_ + rintro r ⟨hr1, z, hz, ⟨Z', H', Cs', Ac', Lst', D', J'⟩, -, -⟩ + exact ⟨y, hy, Or.inr ⟨hr1, hy1, z, hz, V, X, XL, Z', H', Cs', Ac', Lst', D', J'⟩⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmKEntry.lean b/proofs/Fl4Proofs/P3/VmKEntry.lean new file mode 100644 index 000000000..239a3832f --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmKEntry.lean @@ -0,0 +1,2500 @@ +/- +P3 (mmuAD gen 42b84): **FL4's x86 kernel entry at `VmEptState`**. + +`VmEptState.kernel_entry` refines native syscall entry against +`fl4KernelEntrySyscallVF on rc true c`. The other arms cover VMEnter, ordinary +unknown and trapped syscalls, host interrupts, user and VM faults, and +both stalled and unstalled VCPU exit. + +The proved `VmEptState` pieces are wired end to end: the `FAULT_IP` write (`JAtZB.regWrJ`, `VmEptState.ofNat`), the +invoking syscalls' `handle_invocation` (P3/VmInvAfter's `VmEptState.handleInvocationE`, i.e. P3/VmHandleTop's +`VmEptState.handleInvocation` with the front reads discharged) and `after_invocation` (`VmEptState.afterV`: the +preempted arm by P3/VmPreempt's `VmEptPre.preemptPathVFk`, its `¬ RunningVM` by P3/VmHiErr's `hiVF_err_nrvm`), the +ReplyRecv / NBSendRecv / NBSendWait skeleton (invocation, `after_invocation`, the receive only when not preempted), +and the exit `syscall.finish` (P3/VmFinish's `VmEptState.finishVF`: `scheduleVF`, `activateV`, `checkCur`). + +* Spec: `specFrontVF on rc c σ` (the `FaultIP` write and the handled extended event, native `specFront`), + `mem_kentryVF`, `mem_hevVF`, `mem_frontVF_stop` / `_ok` / `_err`; `InvArgs`, `DispPostVE`. +* **`VmEptState.dispatchV`**: `dispatch_syscall` at a dispatch state for every native number, against + `fl4HandleSyscallVF on rc true c` (its preempted outcomes followed by `preemptionPathVF on rc`). +* `KFinVE` (the finish facts at one finish state) and **`KEntryArmsV`** (the per-entry arm premises), both [J]. +* **`VmEptState.kernel_entry`**: `handle_syscall n` from a `VmEptState` entry state, for a native number `n` with + the trap flag clear after the `FaultIP` write (exactly the native `kernel_entry_reachU8V`'s syscall conjunct: + `NativeSys n c` and its `hflag`; the `TRAP_SYSCALLS` / out-of-range numbers are U8V's separate unknown-syscall + event conjunct, see below), ends in an outcome of `fl4KernelEntrySyscallVF on rc true c σ` with `VEAny` after. + +Named premises (all [J], in the ONE record `KEntryArmsV on rc n c s a σ`, each a per-entry statement at the states +the entry reaches, pinned as the native `KDispHypsKVU7` / `KFinEv8` pin theirs by `KFrontB` / `KFrontF` / +`BudgetAt` / the spec outcomes): +* `budget` — `budget_ok` after the `FAULT_IP` write (native XTopJointKEntry8B `JAtZ.budgetOkB`, XTopJointBudgetOk* + `JAtZ.budgetOkJ` / `T` / `TR` / `F`; JAtZ only); +* `fast` — the `SysReplyRecv` fast path `fastpath.reply_recv` (native StPostRR* / P1 `FastAgree`, P3JSysSt's + `FastAcc.of_rrpre`; JAtZ only): accepted, an outcome of the entry; declined, the state unchanged; +* `disp` — the decode and invocation of the looked-up cap for Send / NBSend / Call and the first phase of the mid + syscalls, `VmEptState.handleInvocation`'s `hDisp` passed through (`VDispAt`; P3/VmDisp's `VDispPostVE`, proved by + `VmEptState.decodeDisp` for the VM-side caps; the native caps' producers are the JAtZ decode leaves, + XTopJointKEntry23P `decOK_JMU`, P3JInvCls `InvDecSt`); +* `orc` — ruling item 3: `VmOrc st on rc` at every preempted outcome of the invocation and its related FL4 state + (P3/VmOracle; native has no oracle); +* `recv` — `handle_recv` for Recv / NBRecv / Wait / NBWait at the dispatch state (native XTopJointRecv*, + IpcRecvTop(H), P3JRecvCls `handle_recvJStG`; JAtZ only); +* `recvMid` — `handle_recv` after a non-preempted first phase of ReplyRecv / NBSendRecv / NBSendWait (native + XTopJointKEntry8 `JMidRecvHyp`, P3JMidCls `MidRecvSw`; JAtZ only); +* `yield` — `handle_yield` (native XTopJointYieldSys; JAtZ only); +* `fin` — `KFinVE` at every finish state (native G7eTail `KFinEv8` / `KFinAtR8`: `hd`, `arch` = `ArchSwF`, `archNd`, + `idle` = `IdleVt`, `FpuOwnOK` (native: from `SInvB`), and `VmOrc` at the finish state). + +Other hypotheses: the entry facts `Entered σ`, the current thread in no ready queue, its fault handler valid (as +`VmEptState.handleFaultV`), the native `NativeSys n c` and `hflag`; the platform records of the proved pieces +([P] `ARIface`, `ArchTotal`, `ZvVirtAgree`, `MachPlat`, `MRKeep`, `PPPlatA`, `IrqPlatA`, `TimeAgree`, `ArchRefines`, +the `sporadic` / `ticks_to_us` constants, `numDomains = 1`) and `SetDlDet` (the timer's deadline write determinate; +native U8V derives it from its [P] `SetDlDetR MR` and `MR` at the entry, `setDlDet_of`; `sniHyp_of` / `sendHyp_of` +then give `finishVF`'s `SniHyp` / `SendHyp`). The unknown-syscall / `TRAP_SYSCALLS` entry (FL4's +`unknown_syscall_fault` / `handle_unknown_syscall`, the spec's `unknownSyscall` event, which includes VMEnter) is, +as in U8V, handled by the separate event theorems below. + +The fault, trap, ordinary unknown syscall and host IRQ entries use the native event +projections. `ValidMachineTime` [J] supplies the clock agreement through `MachPlat.nowAgree` +(or `nowAgree_gai` after a fresh IRQ read). `Sched.OffReady` [J] supplies the refill ordering for +the shared `ScChargeH` budget proof. Host IRQ uses `ValidIrqMasks` [J] and `IrqHw` [P]. +The fault arms reuse `UserHw` [P] and `VmfHw` [P]. The ordinary unknown syscall +uses the native `UnkSys` and `NoDbgSys` scope, `StoreExt` [P], and `FastFaultOK` [J] +for the outer entry equivalence. The ordinary trap requires the native (v < 256) +vector bound. The saved VCPU vector uses the Stage-2 single-core exclusion of +vectors 126 and 127 [S] and the separate `VirtExitIrqF` operation. +All entries use the same `KFinVE` finish facts, including `ArchSwF`, `ArchNdF`, +`NdOK`, `FpuOwnOK`, and `IdleVt`. + +No existing statement changed. New file. +-/ +import Fl4Proofs.P3.VmInvAfter +import Fl4Proofs.P3.VmEnterSetup +import Fl4Proofs.P3.VmExitClock +import Fl4Proofs.P3.XTopJointKEntryEv6 +import Fl4Spec.Ext.VirtExitIrqF +import Fl4Proofs.P3.VmFinish +import Fl4Proofs.P3.XTopJointKEntry8 +import Fl4Proofs.P3.XTopJointKEntry29 +import Fl4Proofs.P3.XTopJointKEntry26MD +import Fl4Proofs.P3.XTopJointKEntry27 +import Fl4Proofs.P3.ScSniProof +import Fl4Proofs.P3.XTopJointKEntry13P +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section Spec +open Fl4Spec + +/-- The `FaultIP` write then the handled extended event: what `fl4CallKernelVF` runs before the exit (native +`specFront`). -/ +def specFrontVF (on rc : ObjRef → Bool) (c : Syscall) (σ : State Unit) : Set (Except Unit Unit × State Unit) × Prop := + (fl4SyscallFaultIP (Z := Unit) σ.curThread >>= fun _ => + ExceptT.run (NonDetE.handleE (fl4HandleEventVF on rc true (.syscallEvent c)) + (fun _ => withoutPreemption (preemptionPathVF on rc)))) σ + +/-- An outcome of `specFrontVF` then of the exit is an outcome of the extended syscall entry (native `mem_kentry`). -/ +theorem mem_kentryVF {on rc : ObjRef → Bool} {σ σ' : State Unit} {c : Syscall} {x : Except Unit Unit × State Unit} + (hx : x ∈ (specFrontVF on rc c σ).1) (hT : ((), σ') ∈ (fl4KernelExitVF (Z := Unit) on rc x.2).1) : + ((), σ') ∈ (fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 := by + obtain ⟨u, hu, hh⟩ := mem_bind_elim hx + unfold fl4KernelEntrySyscallVF fl4CallKernelVF + exact mem_bind_nd (x := (σ.curThread, σ)) rfl (mem_bind_nd hu (mem_bind_nd hh hT)) + +/-- The handled extended syscall event from a budget outcome (native `mem_fl4HandleEvent`). -/ +theorem mem_hevVF {on rc : ObjRef → Bool} {σ0 σb : State Unit} {b : Bool} {c : Syscall} + (hb : (b, σb) ∈ (specBudget σ0).1) {y : Except Unit Unit × State Unit} + (hy : y ∈ ((NonDetE.whenE (b = true) (fl4HandleSyscallVF (Z := Unit) on rc true c)).run σb).1) : + y ∈ ((fl4HandleEventVF (Z := Unit) on rc true (.syscallEvent c)).run σ0).1 := by + obtain ⟨u, hu, hr⟩ := mem_bind_elim hb + unfold fl4HandleEventVF + exact mem_bindE_ok (mem_liftE hu) (mem_bindE_ok (mem_liftE hr) hy) + +theorem mem_frontVF_stop {on rc : ObjRef → Bool} {c : Syscall} {σ σ0 σb : State Unit} + (hF : ((), σ0) ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1) (hb : (false, σb) ∈ (specBudget σ0).1) : + ((.ok (), σb) : Except Unit Unit × State Unit) ∈ (specFrontVF on rc c σ).1 := + mem_bind_nd hF (mem_handleE_ok (mem_hevVF hb mem_whenE_false)) + +theorem mem_frontVF_ok {on rc : ObjRef → Bool} {c : Syscall} {σ σ0 σb : State Unit} + (hF : ((), σ0) ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1) (hb : (true, σb) ∈ (specBudget σ0).1) + {y : Except Unit Unit × State Unit} (hy : y ∈ ((fl4HandleSyscallVF (Z := Unit) on rc true c).run σb).1) + (hy1 : y.1 = .ok ()) : ((.ok (), y.2) : Except Unit Unit × State Unit) ∈ (specFrontVF on rc c σ).1 := by + have hy' : ((.ok (), y.2) : Except Unit Unit × State Unit) ∈ + ((fl4HandleSyscallVF (Z := Unit) on rc true c).run σb).1 := by rw [← hy1]; exact hy + exact mem_bind_nd hF (mem_handleE_ok (mem_hevVF hb (mem_whenE_true hy'))) + +theorem mem_frontVF_err {on rc : ObjRef → Bool} {c : Syscall} {σ σ0 σb : State Unit} + (hF : ((), σ0) ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1) (hb : (true, σb) ∈ (specBudget σ0).1) + {y : Except Unit Unit × State Unit} (hy : y ∈ ((fl4HandleSyscallVF (Z := Unit) on rc true c).run σb).1) + (hy1 : y.1 = .error ()) {z : Unit × State Unit} (hz : z ∈ (preemptionPathVF (Z := Unit) on rc y.2).1) : + ((.ok (), z.2) : Except Unit Unit × State Unit) ∈ (specFrontVF on rc c σ).1 := by + have hy' : ((.error (), y.2) : Except Unit Unit × State Unit) ∈ + ((fl4HandleSyscallVF (Z := Unit) on rc true c).run σb).1 := by rw [← hy1]; exact hy + exact mem_bind_nd hF (mem_handleE_err (mem_hevVF hb (mem_whenE_true hy')) (mem_liftE hz)) + +end Spec + +section +open Fl4Proofs.P1 Sched Ipc Notif Classical +open Fl4Spec in +private theorem saved_mask_ack (σ : State Unit) (i : Irq) : + doMachineOp (Z := Unit) (do maskInterrupt true i; ackInterrupt i) σ = + ({((), maskMs σ i true)}, False) := by + apply doMachineOp_single + unfold maskInterrupt ackInterrupt + rw [Notif.nd_bind_one (by rfl)] + rfl + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {MR : A → Fl4Spec.MachineState → Prop} +variable {Z : XSets} {H : Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D V X : Set U64} +variable {XL : U64 → Nat} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +/-- [S] The two cross-core IPI lines are outside the single-core-view +guest-exit boundary (`crates/fl4-core/src/arch/x86_64/layout.rs:111–122`, +`MachPlat.noIpi`, KENTRY-PLAN 1049–1057). Device vectors can have become +inactive by the time FL4 reads the IRQ state under the gate. -/ +def SavedIrqScope (w : U64) (i : Fl4Spec.Irq) : Prop := + w.val = i.toNat ∧ i ≠ 126 ∧ i ≠ 127 + +set_option maxHeartbeats 4000000 in +/-- Handle a saved host IRQ against the extended VCPU-exit handler. -/ +theorem VmEptState.handleSavedIrqV (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) + (hVA : ZvVirtAgree arI) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hIA : IrqPlatA arI AR) (hPA : PPPlatA arI AR) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) (hMR : MR a σ.machineState) + (w : U64) (i : Fl4Spec.Irq) (hs : SavedIrqScope w i) : + interrupt.handle_interrupt st arI s a w ⦃ r => + ∃ z ∈ (Fl4Spec.handleSavedIrqVF (Z := Unit) on rc i σ).1, + VEAny (L := L) arI AR r.1 r.2 z.2 ∧ MR r.2 z.2.machineState ⦄ := by + obtain ⟨hwi, h126, h127⟩ := hs + have hwide := setWidth8_eq hwi + have h256 : w.val < 256 := by rw [hwi]; exact i.isLt + have hwne126 : w.val ≠ 126 := fun e => h126 (BitVec.eq_of_toNat_eq (hwi.symm.trans e)) + have hwne127 : w.val ≠ 127 := fun e => h127 (BitVec.eq_of_toNat_eq (hwi.symm.trans e)) + by_cases hin : i ≤ Fl4Spec.maxIRQ ∧ σ.interruptStates i = .irqInactive + · obtain ⟨hle, hst⟩ := hin + have hlow : ¬ w > 127#u64 := by + have hn := BitVec.le_def.1 hle + change i.toNat ≤ 125 at hn + scalar_tac + have h128 : w.val < 128 := by + have hn := BitVec.le_def.1 hle + change i.toNat ≤ 125 at hn + omega + have B := J.1.1 + have hR : IrqRel (L.mem s) (L.ksb s) σ := B.xtop.fin.1.1.2.2.2.1 + have heSt := hR.st w h128 + have hei : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_ofNat, hwi, Nat.mod_eq_of_lt i.isLt] + rw [hei, hst] at heSt + have hz := (irqSt_inactive _).1 heSt.symm + unfold interrupt.handle_interrupt + rw [irq_max_eq, bind_ok, if_neg hlow, irq_state_eq', bind_ok, hz] + have hn1 : (0#u64 : U64) ≠ 1#u64 := by decide + have hn2 : (0#u64 : U64) ≠ 2#u64 := by decide + have hn3 : (0#u64 : U64) ≠ 3#u64 := by decide + simp only [irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq, if_neg hn1, if_neg hn2, if_neg hn3, + if_pos rfl, bind_ok, uncurry_apply_pair] + obtain ⟨a1, he, hm⟩ := P1.spec_ex_fd (hM.mask a w true σ.machineState hMR h256) + rw [hwide] at hm + have ha1 := hARI.mask _ _ _ B.ar (Or.inr (Or.inl ⟨w, true, he⟩)) + rw [he] + simp only [if_true, bind_ok, uncurry_apply_pair] + refine WP.spec_bind (WP.spec_and (hIA.ackAR a1 w _ ha1) (hM.ack a1 w _ hm)) ?_ + intro a2 ha2 + obtain ⟨Lst2, B2, F2⟩ := B.msArJ (maskMs σ i true).machineState a2 rfl (fun _ => ha2.1) + have hmem : ((), maskMs σ i true) ∈ (Fl4Spec.handleSavedIrqVF (Z := Unit) on rc i σ).1 := by + unfold Fl4Spec.handleSavedIrqVF + rw [if_pos ⟨hle, hst⟩, saved_mask_ack] + exact Set.mem_singleton _ + exact (WP.spec_ok _).2 ⟨_, hmem, (J.ofNat (V' := Z.vs) B2 F2).any arI, ha2.2⟩ + · have h : i > Fl4Spec.maxIRQ ∨ σ.interruptStates i ≠ .irqInactive := by + by_cases hi : i > Fl4Spec.maxIRQ + · exact Or.inl hi + · exact Or.inr fun hst => hin ⟨BitVec.not_lt.1 hi, hst⟩ + rw [Fl4Spec.handleSavedIrqVF_eq on rc i σ h] + refine WP.spec_mono (J.handleIrqVFk hARI hAT hVA hARI.toARKeep hPA.minBudget + (on := on) (rc := rc) hO hMR w i hwi hwne126 hwne127 + (fun a1 c ha => hIA.ackAR a1 w c ha) + (fun a0 a1 σ0 hm he => ?_) (fun a1 ms hm => hM.ack a1 w ms hm) + (msig_sendSignalVF hAT hM hMK on rc)) ?_ + · have hm1 := hM.mask a0 w true σ0.machineState hm h256 + rw [he, WP.spec_ok, hwide] at hm1 + exact hm1 + · rintro res (⟨hst, hfail⟩ | ⟨z, hz, ⟨⟨V1, Ac1, Lst1, D1, J1⟩, _⟩, hm⟩) + · have hgt := h.resolve_right (fun hne => hne hst) + rw [Fl4Spec.handleInterruptVF, if_pos hgt, saved_mask_ack] at hfail + exact hfail.elim + · exact ⟨z, hz, J1.any arI, hm⟩ + +end + + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable (AR : A → Fl4Spec.Cr3 → Prop) (MR : A → Fl4Spec.MachineState → Prop) + +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched + +/-- The invocation flags of an invoking syscall number: Send / NBSend / Call (first phase off), or the first phase +of ReplyRecv / NBSendRecv / NBSendWait. -/ +def InvArgs (n : I64) (c : Fl4Spec.Syscall) (call bl don fp : Bool) : Prop := + (InvSys n call bl don ∧ fp = false) ∨ (MidSys n c ∧ call = false ∧ bl = false ∧ don = true ∧ fp = true) + +/-- **The dispatch's post**: an outcome of `fl4HandleSyscallVF on rc true c`, `VEAny` after when not preempted, else +after an outcome of `preemptionPathVF on rc`. -/ +def DispPostVE (on rc : Fl4Spec.ObjRef → Bool) (c : Fl4Spec.Syscall) (σ : Fl4Spec.State Unit) (r : S × A) : Prop := + ∃ y ∈ ((Fl4Spec.fl4HandleSyscallVF (Z := Unit) on rc true c).run σ).1, + (y.1 = .ok () ∧ VEAny (L := L) arI AR r.1 r.2 y.2) ∨ + (y.1 = .error () ∧ ∃ z ∈ (Fl4Spec.preemptionPathVF (Z := Unit) on rc y.2).1, VEAny (L := L) arI AR r.1 r.2 z.2) + +/-- **[J] The finish facts at one finish state** (module docstring; native G7eTail `KFinAtR8` plus what +`VmEptState.scheduleVF` asks beyond it). -/ +structure KFinVE (on rc : Fl4Spec.ObjRef → Bool) (Z : XSets) (H : P1.Heap) (Cs : Set U64) (s : S) + (σ : Fl4Spec.State Unit) : Prop where + /-- [J] The native scheduler domain readiness condition. -/ + hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ + /-- [J] The oracles agree with FL4 at the finish state (P3/VmOracle `VmOrc`). -/ + orc : VmOrc st on rc s σ + /-- [J] native `KFinAtR8.arch`. -/ + arch : ArchSwF st arI Z.N Z.T Z.C Z.c + /-- [J] native `KFinAtR8.archNd`. -/ + archNd : ArchNdF st Z.N Z.T Z.C Z.c + /-- [J] the FPU owner (native: `SInvB`'s `sinvB_front_fo`). -/ + fo : FpuOwnOK σ + /-- [J] native `KFinAtR8.idle` (INV-PLAN §1.U3L D7). -/ + idle : IdleVt σ + +/-- **[J] The per-entry arm premises of `VmEptState.kernel_entry`** (module docstring: one field per unported +native arm, each naming the native lemma family it ports). -/ +structure KEntryArmsV (on rc : Fl4Spec.ObjRef → Bool) (n : I64) (c : Fl4Spec.Syscall) (s : S) (a : A) + (σ : Fl4Spec.State Unit) : Prop where + /-- [J] `budget_ok` after the `FAULT_IP` write (ports XTopJointKEntry8B `JAtZ.budgetOkB`, XTopJointBudgetOk*). -/ + budget : ∀ (ct v : U64) (σ0 : Fl4Spec.State Unit), sched.cur_thread st s = ok ct → + ((), σ0) ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1 → + VEAny (L := L) arI AR (L.wr s (regA ct layout.reg.FAULT_IP) v) a σ0 → + syscall.budget_ok st arI (L.wr s (regA ct layout.reg.FAULT_IP) v) a ⦃ r => + ∃ σb, (r.1, σb) ∈ (specBudget σ0).1 ∧ VEAny (L := L) arI AR r.2.1 r.2.2 σb ⦄ + /-- [J] the `SysReplyRecv` fast path (ports StPostRR*, P1 `FastAgree`): accepted, an outcome of the entry; + declined, the state unchanged. -/ + fast : n = fl4_abi.syscall.SysReplyRecv → ∀ (s2 : S) (a2 : A) (σb : Fl4Spec.State Unit), + KFrontB (L := L) arI s a s2 a2 → BudgetAt σ σb true → VEAny (L := L) arI AR s2 a2 σb → + fastpath.reply_recv st arI s2 a2 ⦃ r => + (r.1 = true → ∃ σ', ((), σ') ∈ (Fl4Spec.fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ') ∧ (r.1 = false → r.2 = (s2, a2)) ⦄ + /-- [J] the decode and invocation of the looked-up cap (`VmEptState.handleInvocation`'s `hDisp`; ports the native + decode leaves, XTopJointKEntry23P `decOK_JMU`, P3JInvCls `InvDecSt`, P3JMidInv `MidDecSt`). -/ + disp : ∀ (s2 : S) (a2 : A) (σb : Fl4Spec.State Unit), KFrontB (L := L) arI s a s2 a2 → BudgetAt σ σb true → + ∀ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) + (D : Set U64), VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s2 a2 σb → + ∀ (ct : U64), sched.cur_thread st s2 = ok ct → ZvCtRun σb ct → ∀ (call bl don fp : Bool) (cptr : U64), InvArgs n c call bl don fp → + VDispNativeAt (L := L) arI AR MR on rc Z s2 a2 σb ct call bl don fp cptr + /-- [J] ruling item 3: `VmOrc` at the invocation's preempted outcomes (P3/VmOracle). -/ + orc : ∀ (σb : Fl4Spec.State Unit), BudgetAt σ σb true → ∀ (call bl don fp : Bool) (cptr : Fl4Spec.CapRef), + InvArgs n c call bl don fp → + ∀ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true call bl don fp cptr).run σb).1, y.1 = .error () → + ∀ (s1 : S) (a1 : A), (∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR s1 a1 y.2) → + VmOrc st on rc s1 y.2 + /-- [J] `handle_recv` of Recv / NBRecv / Wait / NBWait (ports XTopJointRecv*, IpcRecvTop(H), P3JRecvCls). -/ + recv : ∀ (bl cr : Bool), RecvSys n bl cr → ∀ (s2 : S) (a2 : A) (σb : Fl4Spec.State Unit), + KFrontB (L := L) arI s a s2 a2 → BudgetAt σ σb true → VEAny (L := L) arI AR s2 a2 σb → + syscall.handle_recv st arI s2 a2 bl cr ⦃ r => + ∃ z ∈ (Fl4Spec.handleRecv (Z := Unit) bl cr σb).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ + /-- [J] `handle_recv` after a non-preempted first phase of ReplyRecv / NBSendRecv / NBSendWait (ports + XTopJointKEntry8 `JMidRecvHyp`, P3JMidCls `MidRecvSw`). -/ + recvMid : ∀ (rg : U64) (sr : Fl4Spec.Register) (cr : Bool), MidSysR n c rg sr cr → + ∀ (σb : Fl4Spec.State Unit), BudgetAt σ σb true → ∀ (cptr : Fl4Spec.CapRef), + ∀ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true false false true true cptr).run σb).1, + y.1 = .ok () → ∀ (s1 : S) (a1 : A), VEAny (L := L) arI AR s1 a1 y.2 → + syscall.handle_recv st arI s1 a1 true cr ⦃ r => + ∃ z ∈ (Fl4Spec.handleRecv (Z := Unit) true cr y.2).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ + /-- [J] `handle_yield` (ports XTopJointYieldSys). -/ + yield : n = fl4_abi.syscall.SysYield → ∀ (s2 : S) (a2 : A) (σb : Fl4Spec.State Unit), + KFrontB (L := L) arI s a s2 a2 → BudgetAt σ σb true → VEAny (L := L) arI AR s2 a2 σb → + syscall.handle_yield st arI s2 a2 ⦃ r => + ∃ z ∈ (Fl4Spec.handleYield (Z := Unit) σb).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ + /-- [J] the finish facts at every finish state (ports G7eTail `KFinEv8` / `KFinAtR8`). -/ + fin : ∀ x ∈ (specFrontVF on rc c σ).1, ∀ (s' : S) (a' : A), KFrontF (L := L) arI n s a s' a' → + ∀ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) + (D : Set U64), VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a' x.2 → + KFinVE (L := L) arI on rc Z H Cs s' x.2 + +variable {arI AR MR} + +/-- Compose a verified entry prefix with the VM-aware kernel exit. `P` +relates the concrete and spec states reached by this prefix. -/ +private theorem finishPrefixVF + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) + (hDL : SetDlDet) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {σ : Fl4Spec.State Unit} {T : Type} + {m : Result (S × A)} {pre : Fl4Spec.NonDet (Fl4Spec.State Unit) T} + (P : S → A → Fl4Spec.State Unit → Prop) + (hP : m ⦃ r => ∃ x ∈ (pre σ).1, P r.1 r.2 x.2 ∧ + VEAny (L := L) arI AR r.1 r.2 x.2 ⦄) + (hFin : ∀ x ∈ (pre σ).1, ∀ s' a', P s' a' x.2 → + ∀ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) + (Lst : U64 → List U64) (D : Set U64), + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a' x.2 → + KFinVE (L := L) arI on rc Z H Cs s' x.2) : + (do + let r ← m + syscall.finish st arI r.1 r.2) ⦃ r => ∃ σ', + ((), σ') ∈ ((pre >>= fun _ => Fl4Spec.fl4KernelExitVF on rc) σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + refine WP.spec_bind hP ?_ + rintro ⟨s', a'⟩ ⟨x, hx, hp, V, X, XL, Z, H, Cs, Ac, Lst, D, J⟩ + have F := hFin x hx s' a' hp V X XL Z H Cs Ac Lst D J + exact WP.spec_mono (J.finishVF hAT hVA hARI.toARKeep hmb F.orc F.hd hnd + (sniHyp_of hAT hDL) (sendHyp_of hAT) hT hRef F.arch F.archNd F.fo F.idle hmax htu) + fun _ ⟨σ', hmem, _, _, _, _, J'⟩ => ⟨σ', mem_bind_nd hx hmem, J'.any arI⟩ + +/-- The absent-vector sentinel or the saved vector at the guest boundary. -/ +def SavedIrqAt (w : U64) : Option Fl4Spec.Irq → Prop + | none => w = syscall.NO_IRQ + | some i => SavedIrqScope w i + +private theorem VmEptState.savedIrqPrefix + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hM : MachPlat arI MR) (hMK : MRKeep arI MR) (hIA : IrqPlatA arI AR) (hPA : PPPlatA arI AR) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) (hMR : MR a σ.machineState) + {w : U64} {irq : Option Fl4Spec.Irq} (hw : SavedIrqAt w irq) : + (if w != syscall.NO_IRQ then interrupt.handle_interrupt st arI s a w else ok (s, a)) ⦃ r => + ∃ z ∈ (Fl4Spec.NonDet.maybeM (Fl4Spec.handleSavedIrqVF (Z := Unit) on rc) irq σ).1, + VEAny (L := L) arI AR r.1 r.2 z.2 ∧ MR r.2 z.2.machineState ⦄ := by + cases irq with + | none => + change w = syscall.NO_IRQ at hw + subst w + simp only [bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + exact ⟨((), σ), Set.mem_singleton _, J.any arI, hMR⟩ + | some i => + have hne : w ≠ syscall.NO_IRQ := by + intro he + have hlt := i.isLt + have hwi : w.val = i.toNat := hw.1 + rw [he] at hwi + unfold syscall.NO_IRQ at hwi + change 18446744073709551615 = i.toNat at hwi + omega + have hb : (w != syscall.NO_IRQ) = true := by simpa using hne + rw [hb, if_pos rfl] + exact J.handleSavedIrqV hARI hAT hVA hM hMK hIA hPA hO hMR w i hw + +/-- Concrete guest-exit entry up to the scheduler finish. -/ +def vcpuExitFront (arI : machine.Arch A) (s : S) (a : A) (w : U64) (stalled : Bool) : + Result (S × A) := do + let (s', a') ← if stalled then ok (s, a) else do + let (s1, a1) ← sched.update_timestamp st arI s a + let ct ← sched.cur_thread st s1 + let (s2, a2) ← vcpu.check st arI s1 a1 ct + let (_, s3, a3) ← sched.check_budget st arI s2 a2 + ok (s3, a3) + if w != syscall.NO_IRQ then interrupt.handle_interrupt st arI s' a' w else ok (s', a') + +private theorem handle_vcpu_exit_eq (s : S) (a : A) (w : U64) (stalled : Bool) : + syscall.handle_vcpu_exit st arI s a w stalled = + (do let r ← vcpuExitFront (st := st) arI s a w stalled; syscall.finish st arI r.1 r.2) := by + unfold syscall.handle_vcpu_exit vcpuExitFront + simp only [Std.bind_assoc] + congr 1 + +/-- Finish facts at each state reached by the saved-vector guest-exit prefix. -/ +abbrev VcpuExitFinishVE + (on rc : Fl4Spec.ObjRef → Bool) (irq : Option Fl4Spec.Irq) (stalled : Bool) + (w : U64) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop := + let pre := Fl4Spec.vcpuExitPrefixVF (Z := Unit) stalled >>= fun _ => + Fl4Spec.NonDet.maybeM (Fl4Spec.handleSavedIrqVF on rc) irq + ∀ x ∈ (pre σ).1, ∀ s' a', vcpuExitFront (st := st) arI s a w stalled = ok (s', a') → + ∀ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) + (Lst : U64 → List U64) (D : Set U64), + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a' x.2 → + KFinVE (L := L) arI on rc Z H Cs s' x.2 + +/-- A stalled guest entry still delivers its saved vector and runs the finish. -/ +theorem VmEptState.vcpuExitStalled + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hM : MachPlat arI MR) (hMK : MRKeep arI MR) (hIA : IrqPlatA arI AR) (hPA : PPPlatA arI AR) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) + (hDL : SetDlDet) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hMR : MR a σ.machineState) {w : U64} {irq : Option Fl4Spec.Irq} (hw : SavedIrqAt w irq) + (hFin : VcpuExitFinishVE (L := L) (arI := arI) (AR := AR) + (v3OnCore st s) (v3RemCur st s) irq true w s a σ) : + syscall.handle_vcpu_exit st arI s a w true ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4VcpuExitSavedVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) irq true σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have hO : VmOrc st (v3OnCore st s) (v3RemCur st s) s σ := fun _ _ _ _ => ⟨rfl, fun _ => rfl⟩ + rw [handle_vcpu_exit_eq] + let pre := Fl4Spec.vcpuExitPrefixVF (Z := Unit) true >>= fun _ => + Fl4Spec.NonDet.maybeM (Fl4Spec.handleSavedIrqVF (v3OnCore st s) (v3RemCur st s)) irq + have h1 : vcpuExitFront (st := st) arI s a w true ⦃ r => + ∃ z ∈ (pre σ).1, VEAny (L := L) arI AR r.1 r.2 z.2 ∧ MR r.2 z.2.machineState ⦄ := by + have hstalled : Fl4Spec.vcpuExitPrefixVF (Z := Unit) true σ = ({((), σ)}, False) := by + simp [Fl4Spec.vcpuExitPrefixVF, Fl4Spec.NonDet.unless, Fl4Spec.NonDet.when] <;> rfl + dsimp only [pre] + rw [Notif.nd_bind_one hstalled] + simpa [vcpuExitFront, bind_ok] using + J.savedIrqPrefix hARI hAT hVA hM hMK hIA hPA hO hMR hw + have h2 : vcpuExitFront (st := st) arI s a w true ⦃ r => + ∃ z ∈ (pre σ).1, vcpuExitFront (st := st) arI s a w true = ok r ∧ + VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (spec_and_eq h1 fun _ h => h) fun r ⟨⟨z, hz, hv, _⟩, he⟩ => ⟨z, hz, he, hv⟩ + have h := finishPrefixVF hARI hAT hVA hPA.minBudget hnd hT hRef hDL hmax htu + (on := v3OnCore st s) (rc := v3RemCur st s) + (fun sf af _ => vcpuExitFront (st := st) arI s a w true = ok (sf, af)) h2 hFin + simpa only [pre, Fl4Spec.fl4VcpuExitSavedVF, Endp.nd_bind_assoc_fun] using h + +/-- A concrete fault prefix follows the spec's budget guard. -/ +private theorem entryGuardedVF + {on rc : Fl4Spec.ObjRef → Bool} {rep : Bool} {ev : Fl4Spec.Event} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + {B : S → A → Result (S × A)} {G : Fl4Spec.SMonad Unit Unit} + (hEv : (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev).run σ = + (Fl4Spec.withoutPreemption (do + Fl4Spec.updateTimeStamp + let restart ← Fl4Spec.checkBudgetRestart + Fl4Spec.NonDet.when restart G)).run σ) + (hBud : syscall.budget_ok st arI s a ⦃ r => + ∃ σb, (r.1, σb) ∈ (specBudget σ).1 ∧ VEAny (L := L) arI AR r.2.1 r.2.2 σb ⦄) + (hArm : ∀ s' a' σb, syscall.budget_ok st arI s a = ok (true, s', a') → + (true, σb) ∈ (specBudget σ).1 → VEAny (L := L) arI AR s' a' σb → + B s' a' ⦃ r => ∃ z ∈ (G σb).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄) : + (do + let (run, s', a') ← syscall.budget_ok st arI s a + if run then B s' a' else ok (s', a')) ⦃ r => + ∃ y ∈ ((Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev).run σ).1, + y.1 = .ok () ∧ KFrontF2 (st := st) arI B s a r.1 r.2 ∧ + VEAny (L := L) arI AR r.1 r.2 y.2 ⦄ := by + obtain ⟨⟨run, s', a'⟩, hbEq, σb, hb, hV⟩ := spec_exists hBud + rw [hbEq] + simp only [bind_ok] + have hMem : ∀ z ∈ (Fl4Spec.NonDet.when run G σb).1, + ((.ok (), z.2) : Except Unit Unit × Fl4Spec.State Unit) ∈ + ((Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev).run σ).1 := by + intro z hz + have hz' : ((), z.2) ∈ (Fl4Spec.NonDet.when run G σb).1 := by + obtain ⟨⟨⟩, _⟩ := z + exact hz + rw [hEv] + obtain ⟨u, hu, hcb⟩ := mem_bind_elim hb + exact mem_liftE (mem_bind_nd hu (mem_bind_nd hcb hz')) + cases run + · change ok (s', a') ⦃ r => _ ⦄ + rw [WP.spec_ok] + refine ⟨(.ok (), σb), hMem ((), σb) ?_, rfl, ?_, hV⟩ + · exact Set.mem_singleton _ + · unfold KFrontF2 + simp only [hbEq, bind_ok, uncurry_apply_pair, Bool.false_eq_true, ↓reduceIte] + · change B s' a' ⦃ r => _ ⦄ + refine WP.spec_mono (spec_and_eq (hArm s' a' σb hbEq hb hV) fun _ h => h) ?_ + rintro ⟨s2, a2⟩ ⟨⟨z, hz, hNext⟩, he⟩ + refine ⟨(.ok (), z.2), hMem z ?_, rfl, ?_, hNext⟩ + · exact hz + · unfold KFrontF2 + simp only [hbEq, bind_ok, uncurry_apply_pair, ↓reduceIte, he] + +/-- Finish a budget-guarded event using the finish facts at a reached state. -/ +private theorem finishGuardedVF + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) + (hDL : SetDlDet) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {rep : Bool} {ev : Fl4Spec.Event} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + {B : S → A → Result (S × A)} {G : Fl4Spec.SMonad Unit Unit} + (hEv : (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev).run σ = + (Fl4Spec.withoutPreemption (do + Fl4Spec.updateTimeStamp + let run ← Fl4Spec.checkBudgetRestart + Fl4Spec.NonDet.when run G)).run σ) + (hBud : syscall.budget_ok st arI s a ⦃ r => ∃ σb, (r.1, σb) ∈ (specBudget σ).1 ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σb ⦄) + (hArm : ∀ s' a' σb, syscall.budget_ok st arI s a = ok (true, s', a') → + (true, σb) ∈ (specBudget σ).1 → VEAny (L := L) arI AR s' a' σb → + B s' a' ⦃ r => ∃ z ∈ (G σb).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄) + (hFin : ∀ x ∈ ((Fl4Spec.NonDetE.handleE (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev) + (fun _ => Fl4Spec.withoutPreemption (Fl4Spec.preemptionPathVF on rc))).run σ).1, ∀ s' a', + KFrontF2 (st := st) arI B s a s' a' → ∀ (V X : Set U64) (XL : U64 → Nat) + (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64), + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a' x.2 → + KFinVE (L := L) arI on rc Z H Cs s' x.2) : + (do + let (run, s', a') ← syscall.budget_ok st arI s a + let (s2, a2) ← if run then B s' a' else ok (s', a') + syscall.finish st arI s2 a2) ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF on rc rep ev σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + let pre := (Fl4Spec.NonDetE.handleE (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc rep ev) + (fun _ => Fl4Spec.withoutPreemption (Fl4Spec.preemptionPathVF on rc))).run + have hPre := WP.spec_mono (entryGuardedVF hEv hBud hArm) fun r ⟨⟨x, σx⟩, hx, he, hFr, hV⟩ => by + dsimp only at he + subst x + exact (show ∃ y ∈ (pre σ).1, KFrontF2 (st := st) arI B s a r.1 r.2 ∧ + VEAny (L := L) arI AR r.1 r.2 y.2 from ⟨(.ok (), σx), mem_handleE_ok hx, hFr, hV⟩) + have h := finishPrefixVF hARI hAT hVA hmb hnd hT hRef hDL hmax htu + (on := on) (rc := rc) (fun sf af _ => KFrontF2 (st := st) arI B s a sf af) hPre hFin + obtain ⟨⟨run, s', a'⟩, he, _⟩ := spec_exists hBud + have hf : (fun r : S × A => syscall.finish st arI r.1 r.2) = + uncurry (fun s2 a2 => syscall.finish st arI s2 a2) := by + funext r + cases r + rfl + rw [hf] at h + simp only [he, bind_ok, uncurry_apply_pair, pre] at h + simpa only [he, bind_ok, uncurry_apply_pair, Fl4Spec.fl4CallKernelVF] using h + +private theorem VmEptState.budgetRestartV + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (r : Bool) : + (do + let ct ← sched.cur_thread st s + if r then ok (r, s, a) + else + let b ← sched.is_runnable st s ct + if b then + let s' ← sched.set_thread_state st s ct sched.TS_RESTART + ok (r, s', a) + else ok (r, s, a)) ⦃ res => + ∃ σ', (res.1, σ') ∈ ((do + let cur ← Fl4Spec.NonDet.gets fun z : Fl4Spec.State Unit => z.curThread + let ts ← Fl4Spec.getThreadState cur + Fl4Spec.NonDet.when (¬r ∧ Fl4Spec.runnable ts) <| Fl4Spec.setThreadState cur .restart + pure r) σ).1 ∧ VEAny (L := L) arI AR res.2.1 res.2.2 σ' ⦄ := by + obtain ⟨ct, hct, -⟩ := spec_exists (sched.cur_thread.spec' (L := L) s) + obtain ⟨hcur, x, hk⟩ := J.1.1.curEq hct + have ht := J.1.1.thT ct (J.1.1.xtop.curTcb hcur).1 + have hk' : σ.kheap σ.curThread = some (.tcb x) := by rwa [hcur] + rw [hct, bind_ok, nd_gets_bind, Notif.nd_bind_one (getThreadState_eq hk')] + cases r + · simp only [Bool.false_eq_true, ↓reduceIte, not_false_eq_true, true_and] + obtain ⟨b, he, hr⟩ := spec_exists (P1.sched.is_runnable.spec (L := L) s ct) + have hr' := runnable_iff (J.1.1.xtop.fin.1.1.2.2.1.at_tcb ht hk).st + have heb : b = Fl4Spec.runnable x.tcbState := by + rw [hr, Bool.eq_iff_iff, decide_eq_true_iff] + exact hr' + rw [he, bind_ok, heb] + by_cases hr : Fl4Spec.runnable x.tcbState = true + · rw [if_pos hr] + obtain ⟨s1, σ1, hst, -, hs, Ac1, Lst1, D1, B1, F1⟩ := J.1.1.restartRunJ hct hk hr + rw [hs, bind_ok, WP.spec_ok] + refine ⟨σ1, ?_, (J.ofNat (V' := Z.vs) B1 F1).any arI⟩ + unfold Fl4Spec.NonDet.when + rw [if_pos (show ¬false = true ∧ Fl4Spec.runnable x.tcbState = true from ⟨by decide, hr⟩), + Notif.nd_bind_one hst] + exact Set.mem_singleton _ + · rw [if_neg hr, WP.spec_ok] + refine ⟨σ, ?_, J.any arI⟩ + unfold Fl4Spec.NonDet.when + rw [if_neg (show ¬ (¬false = true ∧ Fl4Spec.runnable x.tcbState = true) from fun h => hr h.2)] + rw [Notif.nd_bind_one (rfl : Fl4Spec.NonDet.pure () σ = ({((), σ)}, False))] + exact Set.mem_singleton _ + · simp only [↓reduceIte, WP.spec_ok] + refine ⟨σ, ?_, J.any arI⟩ + unfold Fl4Spec.NonDet.when + rw [if_neg (by simp)] + rw [Notif.nd_bind_one (rfl : Fl4Spec.NonDet.pure () σ = ({((), σ)}, False))] + exact Set.mem_singleton _ + +/-- The VM budget guard, using the native entry's spec invariants +`ValidMachineTime` [J] and `Sched.OffReady` [J]. -/ +theorem VmEptState.budgetV + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) + (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (hK : ARKeep arI AR) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + syscall.budget_ok st arI s a ⦃ r => + ∃ σ', (r.1, σ') ∈ (specBudget σ).1 ∧ VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := by + have hC : CurInv σ := J.1.1.cur.resolve_left (by rw [hni.2]; intro e; cases e) + have hB : KBudgetB arI a σ := ⟨hM.nowAgree hMR hVM, hC, hOff, Or.inr hnq⟩ + obtain ⟨⟨su, au⟩, huEq, _⟩ := spec_exists (J.1.1.timestampJH hK hAT hnd hB.now) + obtain ⟨⟨r, s1, a1⟩, hbEq, z, hz, he, V', Ac', Lst', D', J', F'⟩ := + spec_exists (J.1.1.utCheckNat hni hB hK hAT hnd hmrt hmb hmax htu) + simp only [huEq, bind_ok, uncurry_apply_pair] at hbEq + unfold syscall.budget_ok sched.check_budget_restart + rw [huEq, bind_ok] + change (do + let (run, s', a') ← sched.check_budget st arI su au + let ct ← sched.cur_thread st s' + if run then ok (run, s', a') + else do + let runnable ← sched.is_runnable st s' ct + if runnable then + let sr ← sched.set_thread_state st s' ct sched.TS_RESTART + ok (run, sr, a') + else ok (run, s', a')) ⦃ _ ⦄ + rw [hbEq, bind_ok] + refine WP.spec_mono ((J.ofNat (V' := V') J' F').budgetRestartV r) ?_ + rintro res ⟨σ', hr, hVE⟩ + obtain ⟨u, hu, hb⟩ := mem_bind_elim hz + unfold specBudget Fl4Spec.checkBudgetRestart + refine ⟨σ', mem_bind_nd hu (mem_bind_nd hb ?_), hVE⟩ + rw [he] + exact hr + +section +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +private theorem VmEptState.handleFaultGen (hAT : P0.ArchTotal arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : + faults.handle_fault st arI s a ct f ⦃ r => + ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.1.1.faultHypJZG hAT hni hct hnq hvfh hf) fun _ ⟨z, hz, _, V', _, _, _, B', F⟩ => + ⟨z, hz, (J.ofNat (V' := V') B' F).any arI⟩ + +private theorem budgetTrueVE (hnd : Fl4Spec.numDomains = 1) {σ σb : Fl4Spec.State Unit} + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hb : (true, σb) ∈ (specBudget σ).1) : + Entered σb ∧ (∀ d p, σb.curThread ∉ σb.readyQueues d p) ∧ + (∀ x, σb.kheap σb.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) ∧ + σb.kheap σb.curThread = σ.kheap σ.curThread ∧ σb.curThread = σ.curThread ∧ + σb.machineState = gctState σ.machineState := by + obtain ⟨ek, ect, eid, erq, esa, ems⟩ := specBudget_true_shape hnd hb + refine ⟨⟨by rw [ect, eid]; exact hni.1, by rw [esa]; exact hni.2⟩, by rw [ect, erq]; exact hnq, + by rw [ek, ect]; exact hvfh, by rw [ek, ect], ect, ems⟩ + +end + +private theorem userFaultArmVF + (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + {s : S} {a : A} {σ : Fl4Spec.State Unit} (hni : Entered σ) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (n c : U64) (hU : UserHw n c) + {s' : S} {a' : A} {σb : Fl4Spec.State Unit} (hb : (true, σb) ∈ (specBudget σ).1) + (hV : VEAny (L := L) arI AR s' a' σb) : + brU (st := st) arI n c s' a' ⦃ r => ∃ z ∈ (brUS n c σb).1, + VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := by + obtain ⟨hni1, hnq1, hvfh1, -, -, -⟩ := budgetTrueVE hnd hni hnq hvfh hb + obtain ⟨V, X, XL, Z, H, Cs, Ac, Lst, D, J⟩ := hV + obtain ⟨ct, hct, -⟩ := spec_exists (sched.cur_thread.spec' (L := L) s') + have hcur := (J.1.1.curEq hct).1 + have hf : FaultCorrG (.UserException n c) (.userException n.bv c.bv) := + Or.inr (Or.inr (Or.inl ⟨n, c, rfl, rfl⟩)) + unfold brU + rw [hct, bind_ok] + refine WP.spec_mono (J.handleFaultGen hAT hni1 hct hnq1 hvfh1 hf) ?_ + rintro r ⟨z, hz, hV'⟩ + have en : n.bv &&& (Fl4Spec.mask 32 : BitVec 64) = n.bv := and_mask_lt n.bv (by decide) hU.1 + have ec : c.bv &&& (Fl4Spec.mask 28 : BitVec 64) = c.bv := and_mask_lt c.bv (by decide) hU.2 + refine ⟨z, mem_bind_nd (x := (σb.curThread, σb)) rfl ?_, hV'⟩ + rw [hcur, en, ec] + exact hz + +private theorem vmFaultArmVF + (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + {s : S} {a : A} {σ : Fl4Spec.State Unit} (hni : Entered σ) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (ad c : U64) (ft : Fl4Spec.VMFaultType) (hV : VmfHw ad c ft σ) + {s' : S} {a' : A} {σb : Fl4Spec.State Unit} (hb : (true, σb) ∈ (specBudget σ).1) + (hJ : VEAny (L := L) arI AR s' a' σb) : + brV (st := st) arI ad c s' a' ⦃ r => ∃ z ∈ (brVS ft σb).1, + VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := by + obtain ⟨hni1, hnq1, hvfh1, ek, _, ems⟩ := budgetTrueVE hnd hni hnq hvfh hb + obtain ⟨V, X, XL, Z, H, Cs, Ac, Lst, D, J⟩ := hJ + obtain ⟨ct, hct, -⟩ := spec_exists (sched.cur_thread.spec' (L := L) s') + obtain ⟨hcur, x0, hx0⟩ := J.1.1.curEq hct + have hkb : σb.kheap σb.curThread = some (.tcb x0) := by rwa [hcur] + have hk : σ.kheap σ.curThread = some (.tcb x0) := ek ▸ hkb + unfold brV + rw [hct, bind_ok, shr_eq c 4#i32 (by decide) (by decide), bind_ok] + simp only [lift, bind_ok, vspace.vm_fault] + generalize hins : (((⟨c.bv >>> (4#i32 : I32).toNat⟩ : U64) &&& 1#u64) != 0#u64) = ins + have hii := (ins_iff c).trans hV.kind.symm + rw [hins] at hii + have hf : FaultCorrG (.VmFault ad c ins) (.archFault (.vmFault ad.bv [(if ins then 1#u64 else 0#u64).bv, c.bv])) := + Or.inr (Or.inr (Or.inr ⟨ad, c, ins, rfl, rfl⟩)) + refine WP.spec_mono (J.handleFaultGen hAT hni1 hct hnq1 hvfh1 hf) ?_ + rintro r ⟨z, hz, hV'⟩ + have hb0 : (if ins then 1#u64 else 0#u64).bv = ftBit ft := by + cases ft <;> cases ins + · rfl + · exact absurd (hii.1 rfl) (by intro h; cases h) + · exact absurd (hii.2 rfl) (by intro h; cases h) + · rfl + have he := handleVmFault_err hkb ft hb0 + have e5 : x0.tcbArch.tcbContext.userRegs .errorRegister &&& (Fl4Spec.mask 5 : BitVec 64) = c.bv := by + rw [hV.err x0 hk] + exact and_mask_lt c.bv (by decide) hV.lt + rw [e5, ems, hV.addr] at he + refine ⟨z, mem_bind_nd (x := (σb.curThread, σb)) rfl ?_, hV'⟩ + exact mem_catch_err he (by rw [hcur]; exact hz) + +/-- Finish facts at outcomes of an event's concrete and spec prefixes, as +in the native event entry's `KFinEv`. -/ +abbrev EventFinishVE + (on rc : Fl4Spec.ObjRef → Bool) (ev : Fl4Spec.Event) + (P : S → A → Prop) (σ : Fl4Spec.State Unit) : Prop := + ∀ x ∈ ((Fl4Spec.NonDetE.handleE (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc true ev) + (fun _ => Fl4Spec.withoutPreemption (Fl4Spec.preemptionPathVF on rc))).run σ).1, + ∀ s' a', P s' a' → + ∀ (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) + (Lst : U64 → List U64) (D : Set U64), + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s' a' x.2 → + KFinVE (L := L) arI on rc Z H Cs s' x.2 + +section +open Fl4Spec + +private theorem mem_irqEventVF {on rc : ObjRef → Bool} {σ σ3 : State Unit} {rep : Bool} + {z : Bool × State Unit} {y : Unit × State Unit} {i : Irq} + (hz : z ∈ ((updateTimeStamp (Z := Unit) >>= fun _ => checkBudget) σ).1) + (hi : doMachineOp (Z := Unit) (getActiveIRQ false) z.2 = ({(some i, σ3)}, False)) + (hy : y ∈ (handleInterruptVF (Z := Unit) on rc i σ3).1) : + ((.ok (), y.2) : Except Unit Unit × State Unit) ∈ ((fl4HandleEventVF on rc rep .interrupt).run σ).1 := by + obtain ⟨u, hu, hb⟩ := mem_bind_elim hz + unfold fl4HandleEventVF maybeHandleInterruptVF + obtain ⟨⟨⟩, σ'⟩ := y + exact mem_liftE (mem_bind_nd hu (mem_bind_nd hb + (mem_bind_nd (x := (some i, σ3)) (by rw [hi]; exact Set.mem_singleton _) hy))) + +end + +private theorem footN_entryClock {s s' : S} {T Cs Sg Scs : Set U64} {Zb : U64 → Nat} {Es : Set U64} + (NP : ∀ c ∈ Cs, P1.NodePlaced st T s c) (hcpu : L.cpu s ∈ Cs) + (hw : P1.WritesIn st s s' (fun b => + b = L.nodeAt s (L.cpu s) layout.node.CUR_TIME ∨ + b = L.nodeAt s (L.cpu s) layout.node.CONSUMED)) : + P1.FootN st ∅ True T Cs Sg Scs Zb Es s s' := by + refine P1.FootN.of' hw (fun b _ hb => ?_) (fun _ h => ((Set.mem_empty_iff_false _).1 h).elim) + have hnode (o : U64) (hlt : o.val < 4288) (hDbg : o.val ≠ 88) + (hid : ¬ P1.IdOff (L.cpu s = L.cpu s) True o.val) : + P1.KW st T Cs Sg Scs Zb Es s (L.nodeAt s (L.cpu s) o) ∧ + ¬ P1.IdW st ∅ True T Cs Scs s (L.nodeAt s (L.cpu s) o) := + ⟨P1.kw_node hcpu hlt hDbg, P1.notIdW_node NP hcpu hlt hid⟩ + rcases hb with rfl | rfl + · exact hnode _ (by simp [layout.node.CUR_TIME]) (by simp [layout.node.CUR_TIME]) + (P1.idOff_cur (by simp [layout.node.CUR_TIME]) (by simp [layout.node.CUR_TIME]) + (fun _ => by simp [layout.node.CUR_TIME])) + · exact hnode _ (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]) + (P1.idOff_cur (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]) + (fun _ => by simp [layout.node.CONSUMED])) + +private theorem JHole.budgetIpcFoot + {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s0 s : S} {a0 a : A} {σ0 σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) + (hAT : P0.ArchTotal arI) (hni : Entered σ) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) : + sched.check_budget st arI s a ⦃ r => + P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs (OmegaB H Z σ0) (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) (BufU Z σ0) s r.2.1 ⦄ := by + have hc := Hh.cur.resolve_left (by rw [hni.2]; intro e; cases e) + obtain ⟨xt, hk, hsc, -⟩ := hc.tcb + obtain ⟨y, n, hky⟩ := hc.sc + obtain ⟨-, -, -, -, -, -, -, -, -, -, hr, -⟩ := Hh.sfacts + have hR := hr.run hni xt hk + have hca := hc.active (curSc_ne_idleSc_of Hh.inv Hh.act hc hni.1) y n hky + have hsched := schedulable_of hk hsc hR hky hca hc.notRel + have hcs (x : Fl4Spec.Tcb) (hx : σ.kheap σ.curThread = some (.tcb x)) : + x.tcbSchedContext = some σ.curSc ∨ x.tcbSchedContext = none := by + rw [hk] at hx + cases hx + exact Or.inl hsc + have hsw : σ.schedulerAction ≠ .switchThread σ.curThread := by rw [hni.2]; intro e; cases e + have hp := Hh.mcsIpcN hAT hcs hsw (fun _ => Or.inr ⟨hni.1, hnq⟩) + obtain ⟨Qr, Rr, hcr, hsr⟩ := Hh.xtop.fin.1.1.1.lists + obtain ⟨ct, hct, hctv⟩ := spec_exists (sched.cur_thread.spec' (L := L) s) + rw [hcr.cur] at hctv + have ht : ct ∈ Z.T := hctv.symm ▸ hcr.curT + have hcv : ct.bv = σ.curThread := by rw [hctv]; exact hsr.curThread.symm + obtain ⟨b, he, heb⟩ := spec_exists (Sched.sched.is_schedulable.spec' (L := L) s ct) + rw [schedulable_eq Hh.xtop.fin.1.1.2.2.1 Hh.xtop.fin.1.1.1 ht, hcv, hsched] at heb + subst b + unfold syscall.mcs_preemption_point at hp + rw [hct, bind_ok, he, bind_ok, if_pos rfl] at hp + obtain ⟨⟨b, s', a'⟩, hB, hP⟩ := spec_exists (P0.sched.check_budget.p0 st arI s a L.total hAT) + simp only [hB, bind_ok, uncurry_apply_pair, WP.spec_ok] at hp + rw [hB, WP.spec_ok] + exact hp + +private theorem JHole.idleBudgetClockFrame + {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s0 s : S} {a0 a : A} {σ0 σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) + (hAT : P0.ArchTotal arI) (hc : CurInv σ) (hi : σ.curThread = σ.idleThread) : + sched.check_budget st arI s a ⦃ r => + P1.WritesIn st s r.2.1 (fun b => + b = L.nodeAt s (L.cpu s) layout.node.CUR_TIME ∨ + b = L.nodeAt s (L.cpu s) layout.node.CONSUMED) ⦄ := by + have hS := Hh.xtop.fin.1.1.1 + have hR := Hh.xtop.fin.1.1.2.2.1 + obtain ⟨Q, R, hcr, hsr⟩ := hS.lists + have hsc := Hh.curSc_idle hc hi + have hsci : (nodeW st s Z.c layout.node.CUR_SC).bv = σ.idleSc := hsr.curSc.symm.trans hsc + obtain ⟨Q', R', h0⟩ := Hh.blk.1 + unfold sched.check_budget + refine WP.spec_bind (sched.cur_sc.spec' (L := L) s) ?_ + rintro sc - + refine WP.spec_bind (sched.consumed.spec' (L := L) s) ?_ + rintro used - + refine WP.spec_bind (P1.sporadic.sufficient.ok (st := st) hAT s a sc used) ?_ + intro b _ + cases b + · simp only [Bool.false_eq_true, ↓reduceIte] + simp only [charge_budget_idle (ar := arI) s a σ hS hR hsci hi Hh.act.2 used true, + bind_ok, uncurry_apply_pair, WP.spec_ok] + rw [← hcr.cur] + exact (P1.writesIn_wr (P1.nodeAt_aligned (h0.nodes _ h0.cur) (by simp [layout.node.CONSUMED]) + (by simp [layout.node.CONSUMED]))).mono fun _ e => Or.inr e + · simp only [↓reduceIte, is_cur_domain_expired_eq, bind_ok, WP.spec_ok] + exact P1.WritesIn.refl s _ + +/-- Carry the VM signal oracles through the timestamp and either budget +path, including a charge in the native idle case. -/ +private theorem VmEptState.entryBudgetOracles + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) + (hNow : NowAgree arI a σ) (hOff : OffReady σ) + (hres : σ.schedulerAction = .resumeCurThread) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hAK : ARKeep arI AR) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ).1, + VEAny (L := L) arI AR r.2.1 r.2.2 z.2 ∧ VmOrc st on rc r.2.1 z.2 ⦄ := by + have B := J.1.1 + have hc : CurInv σ := B.cur.resolve_left (by rw [hres]; intro e; cases e) + have hb : KBudgetB arI a σ := ⟨hNow, hc, hOff, Or.inr hnq⟩ + have hCharge : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ).1, + ∃ V' Ac' Lst' D', JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ + NatFoot (L := L) Z s σ r.2.1 z.2 ⦄ := by + by_cases hi : σ.curThread = σ.idleThread + · refine WP.spec_mono (B.utCheckIdleNat hres hi hb hAK hAT hnd hmrt hmb) ?_ + rintro r ⟨z, hz, _, Lst', B', F'⟩ + exact ⟨z, hz, Z.vs, Ac, Lst', D, B', F'⟩ + · exact WP.spec_mono (B.utCheckNat ⟨hi, hres⟩ hb hAK hAT hnd hmrt hmb hmax htu) + fun _ ⟨z, hz, _, V', Ac', Lst', D', B', F'⟩ => ⟨z, hz, V', Ac', Lst', D', B', F'⟩ + obtain ⟨Q, R, h0⟩ := B.blk.1 + have ht0 := update_timestamp_fr arI hAK s a B.ar (h0.nodes _ h0.cur) + have hConcrete : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs (OmegaB H Z σ) (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) (BufU Z σ) s r.2.1 ⦄ := by + refine WP.spec_bind (WP.spec_and (B.timestampJH hAK hAT hnd hNow) ht0) ?_ + rintro ⟨s1, a1⟩ ⟨⟨σ1, _, -, -, -, -, -, hum, _, hH⟩, hw, _⟩ + have Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ s1 a1 σ1 := + hH σ1.machineState a1 hum id + obtain ⟨-, -, -, -, -, ect, eact, eid, -, -, -, -⟩ := Hh.sfacts + have er := eact.trans hres + have hnq' : ∀ d p, σ1.curThread ∉ σ1.readyQueues d p := by + obtain ⟨_, _, _, _, e⟩ := Hh.spec + rw [e] + exact hnq + have fp : P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s1 := + footN_entryClock h0.nodes h0.cur hw + by_cases hi : σ1.curThread = σ1.idleThread + · have hc' := Hh.cur.resolve_left (by rw [er]; intro e; cases e) + obtain ⟨Q', R', h1⟩ := Hh.blk.1 + refine WP.spec_mono (Hh.idleBudgetClockFrame hAT hc' hi) ?_ + intro r fw + exact P1.FootN.ipc (fp.trans (footN_entryClock h1.nodes h1.cur fw)) + · exact WP.spec_mono (Hh.budgetIpcFoot hAT ⟨hi, er⟩ hnq') fun _ f => + P1.IpcFootN.trans (P1.FootN.ipc fp) f + refine WP.spec_mono (WP.spec_and hCharge hConcrete) ?_ + rintro r ⟨⟨z, hz, V', Ac', Lst', D', B', F'⟩, f⟩ + refine ⟨z, hz, (J.ofNat B' F').any arI, IpcFootN.vmOrc h0 hO f F'.fk.1.2.2.1 ?_⟩ + intro t y hy + obtain ⟨u, hu, he⟩ := B'.obj.tcb t y hy + exact ⟨u, B'.zH.1 u hu, he.symm⟩ + +/-- The unstalled guest exit checks the VCPU between the timestamp and the +budget charge, then delivers the saved IRQ before finishing. The timestamp +uses `ValidMachineTime` [J] and the charge uses `Sched.OffReady` [J], as in +the native entry. The saved vector has the same [S] IPI exclusion as the +stalled path. -/ +theorem VmEptState.vcpuExitUnstalled [P1.PlainStore st] + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hM : MachPlat arI MR) (hMK : MRKeep arI MR) (hIA : IrqPlatA arI AR) (hPA : PPPlatA arI AR) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hMR : MR a σ.machineState) (hVTime : ValidMachineTime σ) (hOff : OffReady σ) + {w : U64} {irq : Option Fl4Spec.Irq} (hw : SavedIrqAt w irq) + (hFin : VcpuExitFinishVE (L := L) (arI := arI) (AR := AR) + (v3OnCore st s) (v3RemCur st s) irq false w s a σ) : + syscall.handle_vcpu_exit st arI s a w false ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4VcpuExitSavedVF (Z := Unit) + (v3OnCore st s) (v3RemCur st s) irq false σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + let on := v3OnCore st s + let rc := v3RemCur st s + let saved := Fl4Spec.NonDet.maybeM (Fl4Spec.handleSavedIrqVF (Z := Unit) on rc) irq + let pre := Fl4Spec.vcpuExitPrefixVF (Z := Unit) false >>= fun _ => saved + have hpre : pre = (specCheckAfterTimestamp >>= fun _ => + (Fl4Spec.checkBudget >>= fun _ => pure ()) >>= fun _ => saved) := by + dsimp only [pre] + unfold Fl4Spec.vcpuExitPrefixVF Fl4Spec.NonDet.unless specCheckAfterTimestamp + simp only [Bool.false_eq_true, ↓reduceIte, Endp.nd_bind_assoc_fun] + let deliver (p : S × A) : Result (S × A) := + if w != syscall.NO_IRQ then interrupt.handle_interrupt st arI p.1 p.2 w else ok p + let concrete : Result (S × A) := do + let (s1, a1) ← checkAfterTimestamp st arI s a + let (_, s2, a2) ← sched.check_budget st arI s1 a1 + deliver (s2, a2) + have hFront : vcpuExitFront (st := st) arI s a w false = concrete := by + obtain ⟨⟨s1, a1⟩, hTime, _⟩ := spec_exists (P0.sched.update_timestamp.p0 st arI s a L.total hAT) + obtain ⟨ct, hCur, _⟩ := spec_exists (P0.sched.cur_thread.p0 st s1 L.total) + obtain ⟨⟨s2, a2⟩, hCheck, _⟩ := spec_exists (P0.vcpu.check.p0 st arI s1 a1 ct L.total hAT) + obtain ⟨⟨run, s3, a3⟩, hBudget, _⟩ := spec_exists (P0.sched.check_budget.p0 st arI s2 a2 L.total hAT) + simp only [vcpuExitFront, Bool.false_eq_true, ↓reduceIte, concrete, checkAfterTimestamp, deliver, + hTime, hCur, hCheck, hBudget, bind_ok, uncurry_apply_pair] + have hPrefix : concrete ⦃ r => ∃ x ∈ (pre σ).1, + VEAny (L := L) arI AR r.1 r.2 x.2 ⦄ := by + unfold concrete + refine WP.spec_bind (J.checkTimestampHole hARI.toARKeep hAT hVA hnd hM hni hnq hMR hVTime hOff) ?_ + rintro ⟨s1, a1⟩ ⟨sc, σc, Ac', Lst', σr, hs, Jc, Hh, hClock, hOrc, hMR1, hOff1, hEntered, hnq1⟩ + have Bc := Jc.1.1 + obtain ⟨Q, R, hq⟩ := Bc.blk.1 + have hCB := Hh.checkBudgetNat hEntered hOff1 (Or.inr hnq1) hAT hnd hmrt hPA.minBudget hmax htu + have hCBF := Hh.budgetIpcFoot hAT hEntered hnq1 + have hCBM := MK.sched_check_budget (s := s1) L.total hAT hMK hMR1 + refine WP.spec_bind (WP.spec_and hCB (WP.spec_and hCBF hCBM)) ?_ + rintro ⟨b, s2, a2⟩ ⟨⟨z, hz, _, V', Ac2, Lst2, D2, B2, F2⟩, hBud, hMR2⟩ + have J2 := Jc.ofNat B2 F2 + have hFO := P1.IpcFootN.trans (P1.FootN.ipc (footN_entryClock hq.nodes hq.cur hClock)) hBud + have hO2 := IpcFootN.vmOrc hq hOrc hFO F2.fk.1.2.2.1 (fun t y hy => by + obtain ⟨u, hu, he⟩ := B2.obj.tcb t y hy + exact ⟨u, B2.zH.1 u hu, he.symm⟩) + have hMF := MachF.mfk_checkBudget σr _ hz + simp only [MachF.msF, Prod.mk.injEq] at hMF + obtain ⟨hm1, hm2, hm3, hm4, _⟩ := hMF + have hMRz : MR a2 z.2.machineState := hM.frame _ _ _ hMR2 hm1 hm2 hm3 hm4 + change deliver (s2, a2) ⦃ r => _ ⦄ + refine WP.spec_mono (J2.savedIrqPrefix hARI hAT hVA hM hMK hIA hPA hO2 hMRz hw) ?_ + rintro r ⟨x, hx, hVE, _⟩ + refine ⟨x, ?_, hVE⟩ + rw [hpre, Notif.nd_bind_one hs, Endp.nd_bind_assoc_fun] + refine mem_bind_nd hz ?_ + rw [Notif.nd_pure_bind'] + exact hx + rw [handle_vcpu_exit_eq] + have hFrontSpec : vcpuExitFront (st := st) arI s a w false ⦃ r => ∃ x ∈ (pre σ).1, + VEAny (L := L) arI AR r.1 r.2 x.2 ⦄ := by + rw [hFront] + exact hPrefix + have h2 : vcpuExitFront (st := st) arI s a w false ⦃ r => + ∃ z ∈ (pre σ).1, vcpuExitFront (st := st) arI s a w false = ok r ∧ + VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (spec_and_eq hFrontSpec fun _ h => h) + fun _ ⟨⟨z, hz, hv⟩, he⟩ => ⟨z, hz, he, hv⟩ + have h := finishPrefixVF hARI hAT hVA hPA.minBudget hnd hT hRef hDL hmax htu (on := on) (rc := rc) + (fun sf af _ => vcpuExitFront (st := st) arI s a w false = ok (sf, af)) h2 hFin + simpa only [pre, Fl4Spec.fl4VcpuExitSavedVF, Endp.nd_bind_assoc_fun] using h + +/-- Ordinary host entry uses the native fresh-read IRQ agreement `IrqHw` [P] +and mask invariant `ValidIrqMasks` [J]. -/ +theorem VmEptState.interruptEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hM : MachPlat arI MR) (hMK : MRKeep arI MR) (hIA : IrqPlatA arI AR) (hPA : PPPlatA arI AR) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) + (hDL : SetDlDet) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a a' : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hres : σ.schedulerAction = .resumeCurThread) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hTime : ValidMachineTime σ) (hOff : OffReady σ) (hMask : ValidIrqMasks σ) + {w : U64} (hw : IrqHw AR MR a a' σ w) + (hFin : EventFinishVE (L := L) (arI := arI) (AR := AR) (v3OnCore st s) (v3RemCur st s) + .interrupt (KFrontI (st := st) arI s a' w) σ) : + syscall.handle_interrupt_entry st arI s a' w ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) true .interrupt σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + obtain ⟨i, hli, hwi⟩ := hw.line + let on := v3OnCore st s + let rc := v3RemCur st s + have hOrc : VmOrc st on rc s σ := fun _ _ _ _ => ⟨rfl, fun _ => rfl⟩ + obtain ⟨Lst0, B0, F0⟩ := J.1.1.msArJ σ.machineState a' rfl (hw.ar _) + have J0 := J.ofNat (V' := Z.vs) B0 F0 + let pre := (Fl4Spec.NonDetE.handleE (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc true .interrupt) + (fun _ => Fl4Spec.withoutPreemption (Fl4Spec.preemptionPathVF on rc))).run + let concrete : Result (S × A) := + Std.bind (Std.bind (sched.update_timestamp st arI s a') (uncurry fun s1 a1 => + sched.check_budget st arI s1 a1)) (uncurry fun _ => uncurry fun s2 a2 => + interrupt.handle_interrupt st arI s2 a2 w) + have hPrefix : concrete ⦃ r => ∃ x ∈ (pre σ).1, VEAny (L := L) arI AR r.1 r.2 x.2 ⦄ := by + refine WP.spec_bind (WP.spec_and + (J0.entryBudgetOracles hOrc (nowAgree_gai hM hw.mr hTime) hOff hres hnq hARI.toARKeep hAT hnd + hmrt hPA.minBudget hmax htu) + (ut_cb_mr hM hMK hAT hw.mr s)) ?_ + rintro ⟨b, s2, a2⟩ ⟨⟨z, hz, hVE, hO⟩, hMR2⟩ + obtain ⟨⟨u, σu⟩, hu, hcb⟩ := mem_bind_elim hz + rw [Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ.machineState))] at hu + have eu := congrArg Prod.snd (Set.mem_singleton_iff.1 hu) + dsimp only at eu + have hms : σu.machineState = gctState σ.machineState := by rw [eu] + have his : σu.interruptStates = σ.interruptStates := by rw [eu] + have hk := MachF.mfk_checkBudget σu _ hcb + have huMask : ValidIrqMasks σu := by + intro j hj + rw [hms] + exact hMask j (his ▸ hj) + have h2Mask := msF_vim huMask hk + simp only [MachF.msF, Prod.mk.injEq] at hk + obtain ⟨hm1, hm2, hm3, hm4, -⟩ := hk + have hl2 : gaiLine false z.2.machineState = some i := by + rw [gaiLine_congr (ms := σ.machineState) (by rw [hm1, hms]; rfl) (by rw [hm2, hms]; rfl)] + exact hli + let σ3 := { z.2 with machineState := gaiState z.2.machineState } + have hRead : Fl4Spec.doMachineOp (Z := Unit) (Fl4Spec.getActiveIRQ false) z.2 = ({(some i, σ3)}, False) := by + rw [doMachineOp_single (getActiveIRQ_eq false z.2.machineState), hl2] + have hAct : σ3.interruptStates i ≠ .irqInactive := by + intro hin + have := h2Mask i hin + rw [gaiLine_unmasked hl2] at this + cases this + have hMR3 : MR a2 σ3.machineState := hM.frame a2 _ _ hMR2 + (by show z.2.machineState.irqMasks = _; rw [hm1, hms]; rfl) + (by show z.2.machineState.irqState + 1 = _; rw [hm2, hms]; rfl) + (by show z.2.machineState.timeState = _; rw [hm3, hms]; rfl) + (by show z.2.machineState.lastMachineTime = _; rw [hm4, hms]; rfl) + obtain ⟨V1, X1, XL1, Z1, H1, Cs1, Ac1, Lst1, D1, J1⟩ := hVE + obtain ⟨Lst3, B3, F3⟩ := J1.1.1.msArJ σ3.machineState a2 rfl id + have J3 := J1.ofNat (V' := Z1.vs) B3 F3 + have hs : SavedIrqScope w i := ⟨hwi, + fun e => hw.n126 (by simpa [e] using hwi), + fun e => hw.n127 (by simpa [e] using hwi)⟩ + refine WP.spec_mono (J3.handleSavedIrqV hARI hAT hVA hM hMK hIA hPA hO hMR3 w i hs) ?_ + rintro r ⟨y, hy, hv, _⟩ + rw [Fl4Spec.handleSavedIrqVF_eq on rc i σ3 (Or.inr hAct)] at hy + exact ⟨(.ok (), y.2), mem_handleE_ok (mem_irqEventVF (rep := true) hz hRead hy), hv⟩ + have hP : concrete ⦃ r => ∃ x ∈ (pre σ).1, KFrontI (st := st) arI s a' w r.1 r.2 ∧ + VEAny (L := L) arI AR r.1 r.2 x.2 ⦄ := WP.spec_mono (spec_and_eq hPrefix fun _ h => h) fun r ⟨⟨x, hx, hve⟩, he⟩ => + ⟨x, hx, (show KFrontI (st := st) arI s a' w r.1 r.2 from he), hve⟩ + have h := finishPrefixVF hARI hAT hVA hPA.minBudget hnd hT hRef hDL hmax htu + (on := on) (rc := rc) (fun sf af _ => KFrontI (st := st) arI s a' w sf af) hP hFin + rw [handle_interrupt_entry_eq] + obtain ⟨⟨s1, a1⟩, h1, -⟩ := spec_exists (P0.sched.update_timestamp.p0 st arI s a' L.total hAT) + obtain ⟨⟨b, s2, a2⟩, h2, -⟩ := spec_exists (P0.sched.check_budget.p0 st arI s1 a1 L.total hAT) + obtain ⟨⟨s3, a3⟩, h3, -⟩ := spec_exists (P0.interrupt.handle_interrupt.p0 st arI s2 a2 w L.total hAT) + have hce : concrete = ok (s3, a3) := by + dsimp only [concrete] + simp only [h1, h2, h3, bind_ok, uncurry_apply_pair] + simp only [hce, bind_ok, uncurry_apply_pair, pre, on, rc] at h + simpa only [h1, h2, h3, bind_ok, uncurry_apply_pair, Fl4Spec.fl4CallKernelVF] using h + +section +variable {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +/-- `vcpu.bound` gives the concrete half of the VMEnter guard. -/ +theorem VmBase.boundIff (J : VmBase (L := L) arI V AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : Z.th t = some .tcb) : + vcpu.bound st s t ⦃ v => (v = 0#u64 ↔ Fl4Spec.tcbVcpuOf σ t.bv = none) ⦄ := by + refine WP.spec_mono (v3_bound s t) fun v hv => ?_ + constructor + · intro hz + exact zv_tcbVcpuOf_none fun w ws hw hwt => by + obtain ⟨u, hu, _, hm, _⟩ := J.specBound J.vo ht hw hwt + exact J.extv.nz u hu (hm.symm.trans (hv.symm.trans hz)) + · intro hn + by_contra hz + have hne : L.mem s (tVcpuA t) ≠ 0#u64 := fun h => hz (hv.trans h) + obtain ⟨hvV, hvt⟩ := (J.extv.bnd t ht).resolve_left hne + rw [← hv] at hvV hvt + obtain ⟨vs, hkv, hbv⟩ := J.vb v hvV + have hvs : Fl4Spec.VcpuState.tcb vs = some t.bv := by + rcases hbv with ⟨-, h0⟩ | ⟨t', -, h1, h2⟩ + · have e : t = 0#u64 := hvt.symm.trans h0 + subst e + exact absurd ht (J.base.detPl J.vm).h0 + · have e : t' = t := h2.symm.trans hvt + rw [h1, e] + have hTV := zv_tcbVcpuOf_eq hkv hvs fun w ws hw hwt => by + obtain ⟨u, hu, rfl, h1, -⟩ := J.specBound J.vo ht hw hwt + rw [← h1, ← hv] + rw [hTV] at hn + cases hn + +/-- The backend part of the guard uses the same pointwise agreement as +`VmEptState.decodeUtDisp`. -/ +theorem virtualizationGuard (hAT : P0.ArchTotal arI) {a : A} + (hag : ∀ r, arI.virtualization a = ok r → r.val = Fl4Spec.virtKind.code) : + arI.virtualization a ⦃ r => (r = 0#u64 ↔ Fl4Spec.virtKind = .none) ⦄ := by + obtain ⟨r, he, _⟩ := spec_exists (hAT.virtualization a) + rw [he, WP.spec_ok] + have hc := hag r he + constructor + · intro h + have hz : Fl4Spec.virtKind.code = 0 := hc.symm.trans (by rw [h]; rfl) + cases hKind : Fl4Spec.virtKind <;> simp [hKind, Fl4Spec.VirtKind.code] at hz ⊢ + · intro h + exact UScalar.eq_of_val_eq (by rw [hc, h]; rfl) + +/-- A bound, running host thread starts executing its VCPU. -/ +theorem VmEptState.enterRunning + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hr : x.tcbState = .running) + (hBound : L.mem s (tVcpuA t) ≠ 0#u64) : + sched.set_thread_state st s t sched.TS_RUNNING_VM ⦃ r => + ∃ σ' Lst', Fl4Spec.setThreadState (Z := Unit) t.bv .runningVM σ = ({((), σ')}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst' D r a σ' ⦄ := by + have B := J.1.1 + refine WP.spec_mono (B.setRunnableVmJD ht hk (Or.inl hr) (Or.inr rfl) + (raw := sched.TS_RUNNING_VM) (by unfold sched.TS_RUNNING_VM Notif.tsCode; rfl)) ?_ + rintro r ⟨Lst', B', hSS, _, hW⟩ + let y : Fl4Spec.Tcb := { x with tcbState := .runningVM } + let σ' := stsAct (updK σ t.bv (.tcb y)) t.bv + have hy : σ'.kheap t.bv = some (.tcb y) := by simp [σ', stsAct_kheap, updK] + have hp : ∀ p, p ≠ t.bv → σ'.kheap p = σ.kheap p := by + intro p hp + simp [σ', stsAct_kheap, updK, hp] + have hv := VKeep.of_tfoot B.xtop.fin.1.1.1 B.thT hW + have hvk : ∀ u ∈ V, σ'.kheap u.bv = σ.kheap u.bv := by + intro u hu + obtain ⟨vs, hvu⟩ := J.1.2.vm.spec u hu + exact hp _ (fun e => by rw [e, hk] at hvu; cases hvu) + have hK : VmKStep σ σ' := fun o => by + by_cases h : o = t.bv + · subst h + exact Or.inr ⟨_, _, hk, hy, Or.inl ⟨x, y, rfl, rfl⟩⟩ + · exact Or.inl (hp _ h) + have hNoV : ∀ o vs, σ'.kheap o = some (.archObj (.vcpu vs)) → σ.kheap o = some (.archObj (.vcpu vs)) := by + intro o vs hvo + by_cases e : o = t.bv + · rw [e, hy] at hvo + cases hvo + · rwa [hp o e] at hvo + have hRun : RunVmB (L := L) Z.th r := by + refine J.1.2.rvm.enter (t := t) (by rw [hv t (B.thTcb ht)]; exact hBound) ?_ + intro u hu hne h8 + have hne' : u.bv ≠ t.bv := fun e => hne (VirtSanEq.u64_ext e) + obtain ⟨x', hk', hst'⟩ := B'.specTcb hu + rw [h8] at hst' + have hr' : x'.tcbState = .runningVM := by + cases hx : x'.tcbState <;> rw [hx] at hst' <;> simp_all [Notif.tsCode] + have hst := (B.xtop.fin.1.1.2.2.1.at_tcb (B.thT u hu) (by rwa [hp u.bv hne'] at hk')).st + exact ⟨UScalar.eq_of_val_eq (by rw [Sched.stA_tStA, hst, hr']; rfl), hv u hu⟩ + have hO : ∀ b, TFoot st Z.T Z.N Z.C Z.c s σ b → OObj st Z.N Z.T Z.C Z.E Z.R Z.B Z.c s σ b := + fun b hb => tfoot_oobj B.xtop.fin.1.1.1 hb + have Bv := J.toB.ofBSSCore (V' := Z.vs) B' hW hSS + (fun u hu b hb => B.oobjV J.1.2.vm hu (hO b hb)) + (fun _ hb => B.tfoot_nh hb) hv hvk hK.sz hRun hNoV + have Fv : VmBaseF (L := L) arI s σ V AR Z H Cs Ac Lst' D r a σ' := + ⟨Bv, hSS, hW.mono (fun b hb => Or.inl (hO b hb)), hK⟩ + exact ⟨σ', Lst', Notif.setThreadState_eq .runningVM hk, + J.ofFBind Fv (fun u hu old new hOld hNew => by rw [hvk u hu, hOld] at hNew; cases hNew; rfl)⟩ + + +section +open Fl4Spec + +/-- VMEnter's active bound notification transfers the badge and clears the +notification. The running current thread already owns the current SC. -/ +private theorem VmEptState.completeEnterSignal + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {t n : U64} (ht : t ∈ Z.T) (hcur : σ.curThread = t.bv) (hn : n ∈ Z.N) + {x : Tcb} (hk : σ.kheap t.bv = some (.tcb x)) {y : Notification} + (hkn : σ.kheap n.bv = some (.notification y)) {badge : Badge} (hact : y.ntfnObj = .activeNtfn badge) : + notification.complete_signal st arI s a n t ⦃ r => + ∃ σ', completeSignal (Z := Unit) n.bv t.bv σ = ({((), σ')}, False) ∧ + (∃ Ac' Lst', VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ') ∧ + σ' = updK (updK σ t.bv (.tcb (setReg x badge_register badge))) n.bv + (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y)) ⦄ := by + have B := J.1.1 + have hC : CurInv σ := B.curInv (by rw [hni.2]; intro e; cases e) + obtain ⟨tc, hkc, hsc, -⟩ := hC.tcb + rw [hcur, hk] at hkc + cases hkc + obtain ⟨cs, i, hks⟩ := hC.sc + have hn_t : n.bv ≠ t.bv := fun e => by rw [e, hk] at hkn; cases hkn + have hc_t : σ.curSc ≠ t.bv := fun e => by rw [e, hk] at hks; cases hks + have hc_n : σ.curSc ≠ n.bv := fun e => by rw [e, hkn] at hks; cases hks + have hx := (B.xtop.irelK B.ks B.buf).1.toN.at_ntfn hn hkn + have hst : stOf (L.mem s) n = obj.NTFN_ACTIVE := stOf_active hx.obj hact + let data := L.mem s (nBadgeA n) + have eData : data.bv = badge := by + have hr := hx.obj + rw [hact] at hr + exact hr.2.2 + let x1 := setReg x badge_register badge + let σ1 := updK σ t.bv (.tcb x1) + let s1 := L.wr s (regA t (regIdx badge_register)) data + have hJF := J.toF.regWr ht hk badge_register data + rw [eData] at hJF + have J1 : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s1 a σ1 := + J.ofFBind hJF (fun u hu old new ho hn' => by + have ne : u.bv ≠ t.bv := fun e => by rw [e, hk] at ho; cases ho + simp [σ1, updK, ne, ho] at hn' + simp [hn']) + have hk1 : σ1.kheap n.bv = some (.notification y) := by simp [σ1, updK, hn_t, hkn] + let σ2 := updK σ1 n.bv (.notification (ntfnObjUpdate (fun _ => .idleNtfn) y)) + obtain ⟨s2, e2, J2⟩ := spec_exists (J1.ntfnIdle hn hk1 hact) + have eStore : s2 = recvActS st s t n := by + have e := spec_eq_ok (P1.obj.Ntfn.set_state.val (L := L) s1 n obj.NTFN_IDLE) + exact Result.ok_injective (e2.symm.trans e) + have hk2 : σ2.kheap t.bv = some (.tcb x1) := by simp [σ2, σ1, updK, hn_t.symm] + obtain ⟨Q, R, hc, hs⟩ := J2.1.1.xtop.fin.1.1.1.lists + obtain ⟨tc2, hc2, -, -, hsc2, -⟩ := hs.tcb t ht + rw [hk2] at hc2 + cases hc2 + have hsw : optRef (L.mem s2 (P1.scA t)) = some σ.curSc := hsc2.symm.trans hsc + have h0 : L.mem s2 (P1.scA t) ≠ 0#u64 := by + intro e + rw [e, optRef_zero] at hsw + cases hsw + have hcW : L.mem s2 (P1.scA t) = nodeW st s2 (L.cpu s2) layout.node.CUR_SC := by + apply P1.eq_of_bv + rw [Notif.optRef_ne h0] at hsw + rw [Option.some.inj hsw] + exact hs.curSc.trans (congrArg (fun q => (nodeW st s2 q layout.node.CUR_SC).bv) hc.cur).symm + have ht0 : t ≠ 0#u64 := by + obtain ⟨_, _, hc1, -⟩ := B.xtop.fin.1.1.1.lists + intro h + exact (hc1.tcbs t ht).ne0 (by rw [h]; rfl) + have hDone := complete_signal_cur_eq (arI := arI) (a := a) ht0 hst + (by rwa [← eStore]) (by rwa [← eStore]) + rw [← eStore] at hDone + refine WP.spec_mono hDone ?_ + rintro r rfl + exact ⟨σ2, completeSignal_cur hk hkn hact hsc hks hc_t hc_n hn_t, ⟨_, _, J2⟩, rfl⟩ + +private def vcpuEnterTail (st : machine.Store S) (arI : machine.Arch A) (s : S) (a : A) (t : U64) : + Result (S × A) := do + let n ← obj.Tcb.bound_ntfn st t s + if n != 0#u64 then + let ns ← obj.Ntfn.state st n s + if ns = obj.NTFN_ACTIVE then + let (s1, a1) ← notification.complete_signal st arI s a n t + let full ← vcpu.full_reply st s1 t + if full then + let badge ← obj.Tcb.reg st t s1 layout.reg.BADGE + let s2 ← vcpu.report st arI s1 a1 t badge + ok (s2, a1) + else + let s2 ← obj.Tcb.set_reg st t s1 layout.reg.MSG_INFO 0#u64 + ok (s2, a1) + else do + let s1 ← sched.set_thread_state st s t sched.TS_RUNNING_VM + ok (s1, a) + else do + let s1 ← sched.set_thread_state st s t sched.TS_RUNNING_VM + ok (s1, a) + +private theorem tcbVcpuOf_vcpuAt {σ σ' : State Unit} {t : ObjRef} + (h : ∀ v, vcpuAt σ v = vcpuAt σ' v) : + tcbVcpuOf σ t = tcbVcpuOf σ' t := by + simp only [tcbVcpuOf, h] + +private theorem vcpuAt_nonArch {σ : State Unit} {o : ObjRef} {ko : KernelObject} + (h : ∀ v, ko ≠ .archObj (.vcpu v)) (he : vcpuAt σ o = none) : + ∀ v, vcpuAt (updK σ o ko) v = vcpuAt σ v := by + intro v + by_cases e : v = o + · subst e + rw [he] + cases ko <;> try simp [vcpuAt, updK] + rename_i av + cases av <;> simp_all [vcpuAt, updK] + · simp [vcpuAt, updK, e] + +/-- The active notification branch of VMEnter, after both saved-exit +flags have been cleared. -/ +private theorem VmEptState.enterSignalTail (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {t n v : U64} (ht : t ∈ Z.T) (hcur : σ.curThread = t.bv) (hn : n ∈ Z.N) + {x : Tcb} (hkt : σ.kheap t.bv = some (.tcb x)) (hrun : x.tcbState = .running) + {y : Notification} (hkn : σ.kheap n.bv = some (.notification y)) + {badge : Badge} (hact : y.ntfnObj = .activeNtfn badge) + {vs : VcpuState} (hkv : σ.kheap v.bv = some (.archObj (.vcpu vs))) + (hvo : tcbVcpuOf σ t.bv = some v.bv) (hp : vs.exit.pending = false) : + (do + let (s1, a1) ← notification.complete_signal st arI s a n t + let full ← vcpu.full_reply st s1 t + if full then + let b ← obj.Tcb.reg st t s1 layout.reg.BADGE + let s2 ← vcpu.report st arI s1 a1 t b + ok (s2, a1) + else + let s2 ← obj.Tcb.set_reg st t s1 layout.reg.MSG_INFO 0#u64 + ok (s2, a1)) ⦃ r => ∃ σ', + ((do + completeSignal n.bv t.bv + let full ← vmFullReply t.bv + if full then do + let b ← asUser t.bv (getRegister badge_register) + vmReportF t.bv b + else asUser t.bv (setRegister msg_info_register 0)) σ) = ({((), σ')}, False) ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + refine WP.spec_bind (J.completeEnterSignal hni ht hcur hn hkt hkn hact) ?_ + rintro ⟨s1, a1⟩ ⟨σ1, hSig, ⟨Ac1, Lst1, J1⟩, e1⟩ + rw [nd_bind_one hSig] + have hnt : n.bv ≠ t.bv := fun h => by rw [h, hkt] at hkn; cases hkn + let x1 := setReg x badge_register badge + have hk1 : σ1.kheap t.bv = some (.tcb x1) := by rw [e1]; simp [updK, hnt.symm, x1] + have hnv : n.bv ≠ v.bv := fun h => by rw [h, hkv] at hkn; cases hkn + have htv : t.bv ≠ v.bv := fun h => by rw [h, hkv] at hkt; cases hkt + have hkv1 : σ1.kheap v.bv = some (.archObj (.vcpu vs)) := by + rw [e1] + simp [updK, hnv.symm, htv.symm, hkv] + have hA1 : ∀ u, vcpuAt σ1 u = vcpuAt σ u := by + intro u + rw [e1, vcpuAt_nonArch (fun _ h => by cases h) (by simp [vcpuAt, updK, hnt, hkn])] + exact vcpuAt_nonArch (fun _ h => by cases h) (by simp [vcpuAt, hkt]) u + have hvo1 := (tcbVcpuOf_vcpuAt (t := t.bv) hA1).trans hvo + obtain ⟨full, hf, eF⟩ := spec_exists (J1.toB.fullReply ht hk1) + dsimp only at hf + change (do + let full ← vcpu.full_reply st s1 t + if full then + let b ← obj.Tcb.reg st t s1 layout.reg.BADGE + let s2 ← vcpu.report st arI s1 a1 t b + ok (s2, a1) + else + let s2 ← obj.Tcb.set_reg st t s1 layout.reg.MSG_INFO 0#u64 + ok (s2, a1)) ⦃ r => _ ⦄ + rw [hf, bind_ok, nd_bind_one (VirtReportEq.vmFullReply_eq hk1)] + by_cases hFull : full = true + · have hfX : Fl4Proofs.P3.repFull x1 = true := eF.symm.trans hFull + rw [if_pos hFull, if_pos hfX] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s1 t layout.reg.BADGE) ?_ + rintro b rfl + have heB := ((J1.1.1.xtop.irelK J1.1.1.ks J1.1.1.buf).1.toE.at_tcb ht hk1).regs badge_register + rw [Endp.regIdx_badge] at heB + have hRep := J1.toF.reportRunnableJ hVA (J1.1.1.thTcb ht) hk1 + (Or.inr ⟨hrun, hfX, v.bv, vs, hvo1, hkv1, hp⟩) (L.mem s1 (regA t layout.reg.BADGE)) + refine WP.spec_bind (WP.spec_and hRep (J1.toF.reportFoot hAT (J1.1.1.thTcb ht) _)) ?_ + rintro s2 ⟨⟨σ2, Lst2, hSpec, J2⟩, _, hFoot⟩ + refine (WP.spec_ok _).2 ⟨σ2, ?_, (J1.ofF J2 + (fun v hv _ => hFoot _ (Or.inr (Or.inr ⟨v, hv, rfl⟩)))).any arI⟩ + rw [nd_bind_one (Endp.asUser_getRegister_eq hk1 badge_register), ← heB] + exact hSpec + · have hfX : Fl4Proofs.P3.repFull x1 ≠ true := fun h => hFull (eF.trans h) + rw [if_neg hFull, if_neg hfX] + refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s1 t layout.reg.MSG_INFO 0#u64) ?_ + rintro s2 rfl + have J2 := J1.toF.regWr ht hk1 msg_info_register 0#u64 + rw [Endp.regIdx_msgInfo] at J2 + let σ2 := updK σ1 t.bv (.tcb (setReg x1 msg_info_register 0)) + have JV : VmEptState (L := L) arI V X XL AR Z H Cs Ac1 Lst1 D _ a1 σ2 := + J1.ofFBind J2 fun u hu old new ho hn' => by + have ne : u.bv ≠ t.bv := fun e => by rw [e, hk1] at ho; cases ho + simp [σ2, updK, ne, ho] at hn' + simp [hn'] + exact (WP.spec_ok _).2 ⟨σ2, Notif.asUser_setRegister_eq _ _ hk1, JV.any arI⟩ + +private theorem VmEptState.enterTailJ (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {t v : U64} (ht : t ∈ Z.T) (hcur : σ.curThread = t.bv) + {x : Tcb} (hkt : σ.kheap t.bv = some (.tcb x)) (hrun : x.tcbState = .running) + {vs : VcpuState} (hkv : σ.kheap v.bv = some (.archObj (.vcpu vs))) + (hvo : tcbVcpuOf σ t.bv = some v.bv) (hp : vs.exit.pending = false) + (hBound : L.mem s (tVcpuA t) ≠ 0#u64) : + vcpuEnterTail st arI s a t ⦃ r => ∃ σ', + enterSpecTail t.bv σ = ({((), σ')}, False) ∧ VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + have hb := (hI.1.toE.at_tcb ht hkt).bound + have hRun := J.enterRunning ht hkt hrun hBound + have noAct : (do + let s1 ← sched.set_thread_state st s t sched.TS_RUNNING_VM + ok (s1, a)) ⦃ r => ∃ σ', + setThreadState (Z := Unit) t.bv .runningVM σ = ({((), σ')}, False) ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + refine WP.spec_bind hRun ?_ + rintro s1 ⟨σ', Lst1, he, J1⟩ + exact (WP.spec_ok _).2 ⟨σ', he, J1.any arI⟩ + unfold vcpuEnterTail + refine WP.spec_bind (P1.obj.Tcb.bound_ntfn.val s t) fun n en => ?_ + have en' : n = L.mem s (tBoundA t) := en + by_cases hn0 : n = 0#u64 + · rw [if_neg (by simp [hn0])] + have hN : x.tcbBoundNotification = none := by rw [hb, ← en', hn0] <;> rfl + refine WP.spec_mono noAct ?_ + rintro r ⟨σ', hR, hVE⟩ + refine ⟨σ', ?_, hVE⟩ + unfold enterSpecTail + rw [nd_bind_one (getTcbObjRef_eq _ hkt), hN] + dsimp only + rw [nd_pure_bind'] + exact hR + rw [if_pos (by simp [hn0])] + have hnH : n ∈ P1.Heap.ntfns H := by + obtain ⟨-, -, hX, -, -⟩ := B.blk + rw [en] + exact hX.2.2.bnd t (B.zH.1 t ht) (by rw [← en]; exact hn0) + have hnN := B.hset.2.1 n hnH + obtain ⟨y, hkn, -⟩ := B.xtop.ipc.toN.ntfn n hnN + have hn : x.tcbBoundNotification = some n.bv := by rw [hb, ← en', Notif.optRef_ne hn0] + have hNt := hI.1.toN.at_ntfn hnN hkn + have hTail : enterSpecTail t.bv σ = + (match y.ntfnObj with + | .activeNtfn _ => do + completeSignal n.bv t.bv + let full ← vmFullReply t.bv + if full then do + let b ← asUser t.bv (getRegister badge_register) + vmReportF t.bv b + else asUser t.bv (setRegister msg_info_register 0) + | _ => setThreadState t.bv .runningVM) σ := by + unfold enterSpecTail + rw [nd_bind_one (getTcbObjRef_eq _ hkt), hn] + dsimp only + rw [nd_bind_one (getNotification_eq hkn)] + cases y.ntfnObj <;> rw [nd_pure_bind'] + refine WP.spec_bind (P1.obj.Ntfn.state.spec s n) fun ns ens => ?_ + rw [epState_eq] at ens + cases hact : y.ntfnObj with + | activeNtfn badge => + rw [if_pos (ens.trans (stOf_active hNt.obj hact)), hTail, hact] + exact J.enterSignalTail hAT hVA hni ht hcur hnN hkt hrun hkn hact hkv hvo hp + | idleNtfn => + rw [if_neg (by rw [ens, stOf_idle hNt.obj hact]; unfold obj.NTFN_IDLE obj.NTFN_ACTIVE; decide), + hTail, hact] + exact noAct + | waitingNtfn q => + rw [if_neg (by rw [ens, stOf_waiting hNt.obj hact]; unfold obj.NTFN_WAITING obj.NTFN_ACTIVE; decide), + hTail, hact] + exact noAct + +/-- An accepted VMEnter against the extended spec, including either +the pending notification or the transition to RunningVM. -/ +private theorem VmEptState.vcpuEnterJ + (hK : ARKeep arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {t : U64} (hcur : σ.curThread = t.bv) + {x : Tcb} (hkt : σ.kheap t.bv = some (.tcb x)) (hrun : x.tcbState = .running) + (hSome : (tcbVcpuOf σ t.bv).isSome) : + vcpu.enter st arI s a t ⦃ r => ∃ σ', vmEnterF t.bv σ = ({((), σ')}, False) ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have B := J.1.1 + have ht : t ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm + have htyped := B.thTcb ht + cases hvo : tcbVcpuOf σ t.bv with + | none => rw [hvo] at hSome; cases hSome + | some ov => + obtain ⟨vs, hAt, hvs⟩ := Fl4Spec.tcbVcpuOf_some hvo + have hk0 := zv_vcpuAt_kheap hAt + obtain ⟨v, hv, rfl, hvMem, -⟩ := J.toB.specBound J.toB.vo htyped hk0 hvs + have hv0 : v ≠ 0#u64 := J.toB.extv.nz v hv + rw [Fl4Proofs.P2.vcpu.enter_eq] + refine WP.spec_bind (hK.vcpu_barrier a _ B.ar) fun a1 ha1 => ?_ + refine WP.spec_bind (v3_bound s t) fun v' hv' => ?_ + have heV := hv'.trans hvMem + rw [heV, if_neg hv0] + refine WP.spec_bind (P0.msg.lookup_ipc_buffer.p0 st s false t L.total) fun buf _ => ?_ + refine WP.spec_bind (enterArg (L := L) s t buf 0#u64 (by decide)) ?_ + intro ip hip + refine WP.spec_bind (enterArg (L := L) s t buf 1#u64 (by decide)) ?_ + intro ctl hctl + refine WP.spec_bind (enterArg (L := L) s t buf 2#u64 (by decide)) ?_ + intro intr hintr + have hI := (B.xtop.irelK B.ks B.buf).1.toE.at_tcb ht hkt + have hIP : ip.bv = x.tcbArch.tcbContext.userRegs (Endp.mrIdx 0) := by + rw [hip] + exact hI.regs _ + have hCTL : ctl.bv = x.tcbArch.tcbContext.userRegs (Endp.mrIdx 1) := by + rw [hctl] + exact hI.regs _ + have hINTR : intr.bv = x.tcbArch.tcbContext.userRegs (Endp.mrIdx 2) := by + rw [hintr] + exact hI.regs _ + let vf := vs.enterF virtKind (Fl4Proofs.P3.repFull x) ip.bv ctl.bv intr.bv + let σ3 := updK σ v.bv (.archObj (.vcpu vf)) + have hF : vmEnterF t.bv σ = enterSpecTail t.bv σ3 := by + rw [vmEnterF_staged hkt hvo hk0] + simp only [σ3, vf, hIP, hCTL, hINTR] + have hRes := (J.toF.archV ha1).stageEnter hv hk0 hVA (hCap a1) ht hkt ip ctl intr + have hTail : (do + let s1 ← (do + let i ← arI.virtualization a1 + let s0 ← Fl4Proofs.P2.enterBlk st arI s a1 v ip ctl intr i t + let s2 ← vcpu.set st s0 v vcpu.VALID 0#u64 + vcpu.set st s2 v vcpu.PENDING 0#u64) + vcpuEnterTail st arI s1 a1 t) ⦃ r => ∃ σ', vmEnterF t.bv σ = ({((), σ')}, False) ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + refine WP.spec_bind hRes ?_ + intro s3 J3 + have hKeep : ∀ u ∈ V, ∀ old new, σ.kheap u.bv = some (.archObj (.vcpu old)) → + σ3.kheap u.bv = some (.archObj (.vcpu new)) → old.tcb = new.tcb := by + intro u hu old new hOld hNew + by_cases e : u.bv = v.bv + · rw [e, hk0] at hOld + simp [σ3, updK, e] at hNew + cases hOld + subst new + unfold vf VcpuState.enterF VcpuState.enter + split <;> rfl + · simp [σ3, updK, e, hOld] at hNew + simp [hNew] + have JR := J.ofFBind J3 hKeep + have hvt : t.bv ≠ v.bv := fun e => by rw [e, hk0] at hkt; cases hkt + have hkt' : σ3.kheap t.bv = some (.tcb x) := by simp [σ3, updK, hvt, hkt] + have hkv' : σ3.kheap v.bv = some (.archObj (.vcpu vf)) := by simp [σ3, updK] + have hBnd : vf.tcb = some t.bv := + (hKeep v hv vs vf hk0 hkv').symm.trans hvs + have hvo' : tcbVcpuOf σ3 t.bv = some v.bv := by + refine zv_tcbVcpuOf_eq hkv' hBnd ?_ + intro w ws hw hwt + obtain ⟨u, _, he, hm, _⟩ := JR.toB.specBound JR.toB.vo htyped hw hwt + obtain ⟨u', _, he', hm', _⟩ := JR.toB.specBound JR.toB.vo htyped hkv' hBnd + rw [he, he', ← hm, ← hm'] + have eBound : L.mem s3 (tVcpuA t) ≠ 0#u64 := by + obtain ⟨u, hu, -, hm, -⟩ := JR.toB.specBound JR.toB.vo htyped hkv' hBnd + rw [hm] + exact JR.toB.extv.nz u hu + have hPend : vf.exit.pending = false := by + unfold vf VcpuState.enterF VcpuState.enter + rfl + rw [hF] + exact JR.enterTailJ hAT hVA hni ht hcur hkt' hrun hkv' hvo' hPend eBound + simpa only [Fl4Proofs.P2.enterFin, vcpuEnterTail, Std.bind_assoc] using hTail + +private theorem vmEnterEventGuard {on rc : ObjRef → Bool} {σ : State Unit} {n : Nat} + (h : isVmEnterCall n σ = true) : + (fl4HandleEventVF (Z := Unit) on rc true (.unknownSyscall n)).run σ = + (withoutPreemption (do + updateTimeStamp + let run ← checkBudgetRestart + NonDet.when run (NonDet.gets (fun z : State Unit => z.curThread) >>= vmEnterF))).run σ := by + unfold fl4HandleEventVF + rw [ExceptT.run_bind] + have hread : (NonDetE.liftE (ε := Unit) (NonDet.gets (isVmEnterCall (Z := Unit) n))).run σ = + ({(.ok true, σ)}, False) := by + refine run_liftE ?_ + show ({(isVmEnterCall n σ, σ)}, False) = _ + rw [h] + rw [nd_bind_single hread] + dsimp only + simp only [if_true] + have hWhen (run : Bool) : + (NonDet.gets (fun z : State Unit => z.curThread) >>= fun thread => + NonDet.when run (vmEnterF thread)) = + NonDet.when run (NonDet.gets (fun z : State Unit => z.curThread) >>= vmEnterF) := by + funext z + rw [nd_gets_bind] + cases run <;> simp only [NonDet.when, Bool.false_eq_true, ↓reduceIte, nd_gets_bind] + simp only [hWhen] + + +end + +end + +/-- The refined event with the native hardware agreement `UserHw` [P]. +The timestamp and budget boundary uses `ValidMachineTime` [J] and +`Sched.OffReady` [J], as in the native entry. -/ +theorem VmEptState.userExceptionEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (n c : U64) (hw : UserHw n c) + (hFin : EventFinishVE (L := L) (arI := arI) (AR := AR) on rc (.userLevelFault n.bv c.bv) + (KFrontF2 (st := st) arI (brU (st := st) arI n c) s a) σ) : + syscall.handle_user_exception st arI s a n c ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) on rc true (.userLevelFault n.bv c.bv) σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := + finishGuardedVF hARI hAT hVA hmb hnd hT hRef hDL hmax htu + (B := brU (st := st) arI n c) (G := brUS n c) rfl + (J.budgetV hni hnq hM hMR hVM hOff hARI.toARKeep hAT hnd hmrt hmb hmax htu) + (fun _ _ _ _ hb hv => userFaultArmVF hAT hnd (s := s) (a := a) hni hnq hvfh n c hw hb hv) hFin + +/-- The refined event with the native hardware agreement `VmfHw` [P]. +The timestamp and budget boundary uses `ValidMachineTime` [J] and +`Sched.OffReady` [J], as in the native entry. -/ +theorem VmEptState.vmFaultEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (ad c : U64) (ft : Fl4Spec.VMFaultType) (hw : VmfHw ad c ft σ) + (hFin : EventFinishVE (L := L) (arI := arI) (AR := AR) on rc (.vmFaultEvent ft) + (KFrontF2 (st := st) arI (brV (st := st) arI ad c) s a) σ) : + syscall.handle_vm_fault st arI s a ad c ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) on rc true (.vmFaultEvent ft) σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := + finishGuardedVF hARI hAT hVA hmb hnd hT hRef hDL hmax htu + (B := brV (st := st) arI ad c) (G := brVS ft) rfl + (J.budgetV hni hnq hM hMR hVM hOff hARI.toARKeep hAT hnd hmrt hmb hmax htu) + (fun _ _ _ _ hb hv => vmFaultArmVF hAT hnd (s := s) (a := a) hni hnq hvfh ad c ft hw hb hv) hFin + +private theorem unknownFaultArmVF + (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + {s : S} {a : A} {σ : Fl4Spec.State Unit} (hni : Entered σ) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (num : U64) {s' : S} {a' : A} {σb : Fl4Spec.State Unit} + (hb : (true, σb) ∈ (specBudget σ).1) (hV : VEAny (L := L) arI AR s' a' σb) : + brK (st := st) (arI := arI) num s' a' ⦃ r => ∃ z ∈ (brKS num.val σb).1, + VEAny (L := L) arI AR r.1 r.2 z.2 ⦄ := by + obtain ⟨hni', hnq', hvfh', -, -, -⟩ := budgetTrueVE hnd hni hnq hvfh hb + obtain ⟨V, X, XL, Z, H, Cs, Ac, Lst, D, J⟩ := hV + obtain ⟨ct, hct, -⟩ := spec_exists (sched.cur_thread.spec' (L := L) s') + have hcur := (J.1.1.curEq hct).1 + have hf : FaultCorrG (.UnknownSyscall num) (.unknownSyscallException num.bv) := + Or.inr (Or.inl ⟨num, rfl, rfl⟩) + unfold brK + rw [hct, bind_ok] + refine WP.spec_mono (J.handleFaultGen hAT hni' hct hnq' hvfh' hf) ?_ + rintro r ⟨z, hz, hV'⟩ + have hnum : (BitVec.ofNat 64 num.val : BitVec 64) = num.bv := by + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt num.bv.isLt + refine ⟨z, mem_bind_nd (x := (σb.curThread, σb)) rfl ?_, hV'⟩ + rw [hnum, hcur] + exact hz + +set_option maxHeartbeats 4000000 in +/-- The native unknown-syscall fault after the FaultIP write. The +extended event must select its ordinary fault branch. -/ +private theorem VmEptState.unknownFaultAfterFip + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (num : U64) (hNotEnter : Fl4Spec.isVmEnterCall num.val σ = false) + (hFin : EventFinishVE (L := L) (arI := arI) (AR := AR) on rc (.unknownSyscall num.val) + (KFrontF2 (st := st) arI (brK (st := st) (arI := arI) num) s a) σ) : + syscall.unknown_syscall_fault st arI s a num false ⦃ r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) on rc true (.unknownSyscall num.val) σ).1 ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := by + have hguard (z : Fl4Spec.State Unit) (hz : Fl4Spec.isVmEnterCall num.val z = false) : + (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc true (.unknownSyscall num.val)).run z = + (Fl4Spec.handleEvent (Z := Unit) (.unknownSyscall num.val)).run z := by + unfold Fl4Spec.fl4HandleEventVF + rw [ExceptT.run_bind] + have hread : (Fl4Spec.NonDetE.liftE (ε := Unit) + (Fl4Spec.NonDet.gets (Fl4Spec.isVmEnterCall (Z := Unit) num.val))).run z = + ({(.ok false, z)}, False) := by + refine run_liftE ?_ + show ({(Fl4Spec.isVmEnterCall num.val z, z)}, False) = _ + rw [hz] + rw [nd_bind_single hread] + rfl + -- The VM branch discriminator is read only at the event's entry. + have hEv : + (Fl4Spec.fl4HandleEventVF (Z := Unit) on rc true (.unknownSyscall num.val)).run σ = + (Fl4Spec.withoutPreemption (do + Fl4Spec.updateTimeStamp + let run ← Fl4Spec.checkBudgetRestart + Fl4Spec.NonDet.when run (brKS num.val))).run σ := + hguard σ hNotEnter + have hBud := J.budgetV hni hnq hM hMR hVM hOff hARI.toARKeep hAT hnd hmrt hmb hmax htu + refine usf_spec (st := st) (arI := arI) s a num (P := fun r => ∃ σ', + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) on rc true (.unknownSyscall num.val) σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ') ?_ + exact finishGuardedVF hARI hAT hVA hmb hnd hT hRef hDL hmax htu + (B := brK (st := st) (arI := arI) num) (G := brKS num.val) hEv hBud + (fun _ _ _ _ hb hv => unknownFaultArmVF hAT hnd (s := s) (a := a) hni hnq hvfh num hb hv) hFin + +private theorem VmEptState.faultIPEntry + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) : + ∃ x, σ.kheap σ.curThread = some (.tcb x) ∧ σ.curThread = ct.bv ∧ + ∃ V', VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac Lst D + (L.wr s (regA ct layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (L.mem s (regA ct layout.reg.NEXT_IP)) 2#u64)) + a (faultIPSt σ σ.curThread x) := by + have B := J.1.1 + obtain ⟨hcur, -⟩ := B.curEq hct + have ht : ct ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, -⟩ := hI.1.tcb ct ht + have hx := hI.1.toE.at_tcb ht hk + have hk' : σ.kheap σ.curThread = some (.tcb x) := by rwa [hcur] + generalize hv : core.num.U64.wrapping_sub (L.mem s (regA ct layout.reg.NEXT_IP)) 2#u64 = v + have hvb : v.bv = x.tcbArch.tcbContext.userRegs .nextIP - 2 := by + rw [← hv, core.num.U64.wrapping_sub_bv_eq, ← hx.regs .nextIP, regIdx_nextIP] + rfl + have hw := reg_wr_irel B.ip hI ht hk Fl4Spec.Register.faultIP (by decide) v + rw [regIdx_faultIP] at hw + obtain ⟨V', B', F⟩ := B.regWrJ ht hk Fl4Spec.Register.faultIP v (by rwa [regIdx_faultIP]) + rw [regIdx_faultIP] at B' F + have J' := J.ofNat B' F + rw [hvb, ← hcur] at J' + exact ⟨x, hk', hcur, V', J'⟩ + +/-- Outcome of a selected extended event, after the entry's FaultIP write. -/ +abbrev FaultIpOutVF (on rc : Fl4Spec.ObjRef → Bool) (ev : Fl4Spec.Event) + (σ σ' : Fl4Spec.State Unit) : Prop := + ∃ x ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, + ((), σ') ∈ (Fl4Spec.fl4CallKernelVF (Z := Unit) on rc true ev x.2).1 + +private theorem validFaultHandler_faultIPSt {σ : Fl4Spec.State Unit} {x : Fl4Spec.Tcb} + (hk : σ.kheap σ.curThread = some (.tcb x)) + (hv : ∀ y, σ.kheap σ.curThread = some (.tcb y) → Fl4Spec.validFaultHandler y.tcbFaultHandler) : + ∀ y, (faultIPSt σ σ.curThread x).kheap σ.curThread = some (.tcb y) → + Fl4Spec.validFaultHandler y.tcbFaultHandler := by + intro y hy + simp only [faultIPSt, Notif.updK, Function.update_self, Option.some.injEq, + Fl4Spec.KernelObject.tcb.injEq] at hy + subst y + exact hv x hk + +set_option maxHeartbeats 4000000 in +/-- The two x86 software-trap paths use the native vector width and +event selection, with the VM-aware finish. -/ +theorem VmEptState.trapSyscallEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (v : U64) (hv : v.val < 256) + (hFin : ∀ ev, KEvSpec (.trap v) true ev → + ∀ x ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, + EventFinishVE (L := L) (arI := arI) (AR := AR) on rc ev (KFrontTrap (st := st) arI s a) x.2) : + syscall.handle_trap_syscall st arI s a v ⦃ r => ∃ ev σ', + KEvSpec (.trap v) true ev ∧ FaultIpOutVF on rc ev σ σ' ∧ VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have hct := cur_thread_eq (L := L) s + generalize L.mem s (L.nodeAt s (L.cpu s) layout.node.CUR_THREAD) = ct at hct + obtain ⟨x, hk, -, V', J0⟩ := J.faultIPEntry hct + generalize hs : L.wr s (regA ct layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (L.mem s (regA ct layout.reg.NEXT_IP)) 2#u64) = s0 at J0 + let σ0 := faultIPSt σ σ.curThread x + have hF : ((), σ0) ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1 := by + rw [fl4SyscallFaultIP_eq hk] + exact Set.mem_singleton _ + have hf0 := validFaultHandler_faultIPSt hk hvfh + have hoff := SInvR.G4.offReady_faultIPSt (t := σ.curThread) (x := x) hOff + unfold syscall.handle_trap_syscall + rw [hct, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s ct layout.reg.NEXT_IP) ?_ + rintro nx rfl + simp only [lift, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.FAULT_IP _) ?_ + rintro s1 rfl + rw [hs] + obtain ⟨fl, hfl, -⟩ := spec_exists (Fl4Proofs.P0.obj.Tcb.flags.p0 st ct s0 L.total) + rw [hfl, bind_ok] + by_cases htr : (fl &&& fl4_abi.consts.tcb_flag.TRAP_SYSCALLS != 0#u64) = true + · rw [if_pos htr, shl_eq v 3#i32 (by decide) (by decide), bind_ok] + try simp only [lift, bind_ok] + generalize hcd : ((⟨v.bv <<< (3#i32 : I32).toNat⟩ : U64) ||| 2#u64) = code + have hcode : code.val < 2 ^ 28 := by + rw [← hcd, UScalar.val_or] + exact Nat.or_lt_two_pow (shl3_lt v hv) (by decide) + have hU : UserHw 13#u64 code := ⟨by decide, hcode⟩ + have hev : KEvSpec (.trap v) true (.userLevelFault (13#u64 : U64).bv code.bv) := KEvSpec.trapF _ _ _ + refine WP.spec_mono (J0.userExceptionEntry hARI hAT hVA hnd hT hRef hDL hmrt hmb hmax htu (on := on) (rc := rc) + hni hnq hf0 hM hMR hVM hoff _ _ hU ?_) ?_ + · intro z hz sf af hfr + exact hFin _ hev _ hF z hz sf af ⟨ct, _, hct, Or.inl ⟨13#u64, code, by rw [hs]; exact hfr⟩⟩ + · rintro r ⟨σ', hmem, hV⟩ + exact ⟨_, σ', hev, ⟨((), σ0), hF, hmem⟩, hV⟩ + · rw [if_neg htr] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s0 ct layout.reg.RAX) ?_ + rintro eax - + rw [shl_eq v 24#i32 (by decide) (by decide), bind_ok] + try simp only [lift, bind_ok] + generalize hnm : ((⟨v.bv <<< (24#i32 : I32).toNat⟩ : U64) ||| (eax &&& 16777215#u64)) = num + have hnum : num.val < 2 ^ 32 := by + rw [← hnm, UScalar.val_or] + refine Nat.or_lt_two_pow (shl24_lt v hv) ?_ + rw [UScalar.val_and] + exact lt_of_le_of_lt Nat.and_le_right (by decide) + have hne : num.val ≠ Fl4Spec.fl4SysVMEnterNum := by + unfold Fl4Spec.fl4SysVMEnterNum + omega + have hnx : Fl4Spec.isVmEnterCall num.val σ0 = false := by + unfold Fl4Spec.isVmEnterCall + simp [hne] + have hev : KEvSpec (.trap v) true (.unknownSyscall num.val) := KEvSpec.trapU _ _ + rw [handle_unknown_syscall_pos s0 a num hnum] + refine WP.spec_bind (J0.unknownFaultAfterFip hARI hAT hVA hnd hT hRef hDL hmrt hmb hmax htu (on := on) (rc := rc) + hni hnq hf0 hM hMR hVM hoff num hnx ?_) ?_ + · intro z hz sf af hfr + exact hFin _ hev _ hF z hz sf af ⟨ct, _, hct, Or.inr ⟨num, by rw [hs]; exact hfr⟩⟩ + · rintro ⟨b, sf, af⟩ ⟨σ', hmem, hV⟩ + exact (WP.spec_ok _).2 ⟨_, σ', hev, ⟨((), σ0), hF, hmem⟩, hV⟩ + +section +open Fl4Spec + +set_option maxRecDepth 1024 in +set_option maxHeartbeats 4000000 in +/-- Accepted VMEnter on the extended unknown-syscall event. The native +trap flag is clear and the backend code agrees with the spec [P]. -/ +theorem VmEptState.vmEnterEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hnd : numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {on rc : ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hRun : ∀ ct, sched.cur_thread st s = ok ct → ZvCtRun σ ct) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (hCode : ∀ i, arI.virtualization a = ok i → i.val = virtKind.code) + (hFlag : ∀ ct v, sched.cur_thread st s = ok ct → obj.Tcb.flags st ct (L.wr s (regA ct layout.reg.FAULT_IP) v) + ⦃ f => (f &&& fl4_abi.consts.tcb_flag.TRAP_SYSCALLS) = 0#u64 ⦄) + (hEnter : ∀ x ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, + isVmEnterCall fl4SysVMEnterNum x.2 = true) + (hFin : ∀ x ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, ∀ t v, sched.cur_thread st s = ok t → + EventFinishVE (L := L) (arI := arI) (AR := AR) on rc (.unknownSyscall fl4SysVMEnterNum) + (KFrontF2 (st := st) arI (fun s' a' => vcpu.enter st arI s' a' t) + (L.wr s (regA t layout.reg.FAULT_IP) v) a) x.2) : + syscall.handle_syscall st arI s a fl4_abi.syscall.SysVMEnter ⦃ r => ∃ σ', + FaultIpOutVF on rc (.unknownSyscall fl4SysVMEnterNum) σ σ' ∧ VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have hct := cur_thread_eq (L := L) s + generalize L.mem s (L.nodeAt s (L.cpu s) layout.node.CUR_THREAD) = t at hct + obtain ⟨x, hk, hcur, V', J0⟩ := J.faultIPEntry hct + let val := core.num.U64.wrapping_sub (L.mem s (regA t layout.reg.NEXT_IP)) 2#u64 + let s0 := L.wr s (regA t layout.reg.FAULT_IP) val + let σ0 := faultIPSt σ σ.curThread x + have hF : ((), σ0) ∈ (fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1 := by + rw [fl4SyscallFaultIP_eq hk] + exact Set.mem_singleton _ + have hSel : isVmEnterCall fl4SysVMEnterNum σ0 = true := hEnter ((), σ0) hF + have hGuards := decide_eq_true_eq.mp hSel + have hBack := hGuards.2.1 + have hBoundSpec : (tcbVcpuOf σ0 t.bv).isSome = true := by + have he : σ0.curThread = t.bv := hcur + rw [← he] + exact hGuards.2.2 + have hct0 : sched.cur_thread st s0 = ok t := by + have h := J0.1.1.xtop.fin.1.1.1.lists + obtain ⟨ct', hct', _⟩ := spec_exists (sched.cur_thread.spec' (L := L) s0) + have eq := (J0.1.1.curEq hct').1 + have et : ct' = t := VirtSanEq.u64_ext (eq.symm.trans hcur) + simpa only [et] using hct' + have ht0 := J0.1.1.thTcb (TopSR.cur_mem J0.1.1.xtop.fin.1 hcur.symm) + obtain ⟨i, hi, eI⟩ := spec_exists (virtualizationGuard (arI := arI) hAT hCode) + obtain ⟨v, hv, eV⟩ := spec_exists (J0.toB.boundIff ht0) + have hi0 : i ≠ 0#u64 := fun e => hBack (eI.1 e) + have hv0 : v ≠ 0#u64 := by + intro e + rw [eV.1 e] at hBoundSpec + cases hBoundSpec + have hOff0 := SInvR.G4.offReady_faultIPSt (t := σ.curThread) (x := x) hOff + have hBud := J0.budgetV hni hnq hM hMR hVM hOff0 hARI.toARKeep hAT hnd hmrt hmb hmax htu + have hBody := finishGuardedVF hARI hAT hVA hmb hnd hT hRef hDL hmax htu + (B := fun s' a' => vcpu.enter st arI s' a' t) + (G := NonDet.gets (fun z : State Unit => z.curThread) >>= vmEnterF) + (vmEnterEventGuard (on := on) (rc := rc) hSel) hBud + (fun s' a' σb _ hb hVE => by + obtain ⟨ek, ect, eid, erq, esa, ems⟩ := specBudget_true_shape hnd hb + have hni' : Entered σb := ⟨by rw [ect, eid]; exact hni.1, esa.trans hni.2⟩ + have hct' : σb.curThread = t.bv := ect.trans hcur + obtain ⟨Vb, Xb, XLb, Zb, Hb, Csb, Acb, Lb, Db, Jb⟩ := hVE + have hktb : σb.kheap t.bv = some (.tcb (setReg x .faultIP + (x.tcbArch.tcbContext.userRegs .nextIP - 2))) := by + rw [ek, ← hcur] + simp [σ0, faultIPSt, updK] + have hr := hRun t hct x (hcur ▸ hk) + have hvob : (tcbVcpuOf σb t.bv).isSome := by + have e : tcbVcpuOf σb t.bv = tcbVcpuOf σ0 t.bv := + tcbVcpuOf_vcpuAt (fun _ => by simp [vcpuAt, ek]) + rw [e] + exact hBoundSpec + refine WP.spec_mono (Jb.vcpuEnterJ hARI.toARKeep hAT hVA hCap hni' hct' hktb hr hvob) ?_ + rintro r ⟨σ', he, hR⟩ + refine ⟨((), σ'), ?_, hR⟩ + rw [nd_gets_bind, hct', he] + exact Set.mem_singleton _) + (hFin ((), σ0) hF t val hct) + unfold syscall.handle_syscall + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => ∃ σ', + FaultIpOutVF on rc (.unknownSyscall fl4SysVMEnterNum) σ σ' ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ') ?_ ?_ + · unfold syscall.syscall + rw [hct, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s t layout.reg.NEXT_IP) ?_ + rintro nx rfl + simp only [lift, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s t layout.reg.FAULT_IP val) ?_ + rintro sw rfl + refine WP.spec_bind (hFlag t val hct) ?_ + intro f hf0 + have hmin : fl4_abi.syscall.SysVMEnter < fl4_abi.syscall.SYSCALL_MIN := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SYSCALL_MIN + decide + simp only [lift, bind_ok, hf0, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, if_pos hmin] + have hct0' : sched.cur_thread st (L.wr s (regA t layout.reg.FAULT_IP) val) = ok t := hct0 + have hv' : vcpu.bound st (L.wr s (regA t layout.reg.FAULT_IP) val) t = ok v := hv + have hi' : (i != 0#u64) = true := bne_iff_ne.mpr hi0 + have hv0' : (v != 0#u64) = true := bne_iff_ne.mpr hv0 + have h1 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugPutChar := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugPutChar + decide + have h2 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugDumpScheduler := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugDumpScheduler + decide + have h3 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugHalt := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugHalt + decide + have h4 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugSnapshot := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugSnapshot + decide + have h5 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugCapIdentify := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugCapIdentify + decide + have h6 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugNameThread := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugNameThread + decide + have h7 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugGetThreadAffinity := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugGetThreadAffinity + decide + have h8 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysDebugSendIPI := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysDebugSendIPI + decide + have h9 : fl4_abi.syscall.SysVMEnter ≠ fl4_abi.syscall.SysSetTLSBase := by + unfold fl4_abi.syscall.SysVMEnter fl4_abi.syscall.SysSetTLSBase + decide + unfold syscall.handle_unknown_syscall syscall.debug_syscall + simp only [hct0', hi, hv', bind_ok, fl4_abi.config.PRINTING, fl4_abi.config.DEBUG_BUILD, + fl4_abi.config.SET_TLS_BASE_SELF, fl4_abi.config.ENABLE_SMP_SUPPORT, + h1, h2, h3, h4, h5, h6, h7, h8, h9, hi', hv0', if_pos rfl, ↓reduceIte, + Bool.false_eq_true, uncurry_apply_pair] + have hLift : Std.bind _ (fun r : S × A => ok (false, r.1, r.2)) ⦃ r => ∃ σ', + FaultIpOutVF on rc (.unknownSyscall fl4SysVMEnterNum) σ σ' ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := + WP.spec_bind hBody fun r ⟨σ', hmem, hVE⟩ => + (WP.spec_ok _).2 ⟨σ', ⟨((), σ0), hF, hmem⟩, hVE⟩ + obtain ⟨⟨run, sb, ab⟩, hBudget, _⟩ := spec_exists hBud + change syscall.budget_ok st arI (L.wr s (regA t layout.reg.FAULT_IP) val) a = + ok (run, sb, ab) at hBudget + have hBudgetRaw := hBudget + dsimp only [val] at hBudgetRaw + simp only [hBudget, hBudgetRaw, bind_ok, uncurry_apply_pair] at hLift ⊢ + have hEnter : (if run = true then vcpu.enter st arI sb ab t else ok (sb, ab)) ⦃ _ => True ⦄ := by + cases run + · exact (WP.spec_ok _).2 trivial + · exact P0.vcpu.enter.p0 st arI sb ab t L.total hAT + obtain ⟨⟨s2, a2⟩, he, _⟩ := spec_exists hEnter + obtain ⟨⟨s3, a3⟩, hf, _⟩ := spec_exists (P0.syscall.finish.p0 st arI s2 a2 L.total hAT) + simpa only [he, hf, bind_ok, uncurry_apply_pair] using hLift + · rintro ⟨_, sf, af⟩ ⟨σ', hm, hV⟩ + exact (WP.spec_ok _).2 ⟨σ', hm, hV⟩ + +end + +set_option maxRecDepth 1024 in +set_option maxHeartbeats 4000000 in +/-- The native unknown-syscall routes, including the trap flag. The +selected extended spec event is the ordinary fault case. -/ +theorem VmEptState.unknownSyscallEntry + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} + {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + (hM : MachPlat arI MR) (hMR : MR a σ.machineState) (hVM : ValidMachineTime σ) (hOff : OffReady σ) + (n : I64) (hU : UnkSys (L := L) n s) (hD : NoDbgSys (L := L) arI n s a) + (hSX : P1.StoreExt st) (hFF : P1.FastFaultOK (L := L) arI s a n) + (hNotEnter : ∀ x ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, + Fl4Spec.isVmEnterCall (IScalar.hcast .U64 n).val x.2 = false) + (hFin : ∀ ev, KEvSpec (.sysU n) true ev → + ∀ x ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1, + EventFinishVE (L := L) (arI := arI) (AR := AR) on rc ev (KFrontSysU (st := st) arI n s a) x.2) : + syscall.handle_syscall st arI s a n ⦃ r => ∃ ev σ', + KEvSpec (.sysU n) true ev ∧ FaultIpOutVF on rc ev σ σ' ∧ VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + rw [handle_syscall_unk_eq hAT hSX hFF hU] + have hct := cur_thread_eq (L := L) s + generalize L.mem s (L.nodeAt s (L.cpu s) layout.node.CUR_THREAD) = ct at hct + obtain ⟨x, hk, hcur, V', J0⟩ := J.faultIPEntry hct + let val := core.num.U64.wrapping_sub (L.mem s (regA ct layout.reg.NEXT_IP)) 2#u64 + generalize hs : L.wr s (regA ct layout.reg.FAULT_IP) val = s0 at J0 + let σ0 := faultIPSt σ σ.curThread x + have hF : ((), σ0) ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1 := by + rw [fl4SyscallFaultIP_eq hk] + exact Set.mem_singleton _ + have hf0 := validFaultHandler_faultIPSt hk hvfh + have hoff := SInvR.G4.offReady_faultIPSt (t := σ.curThread) (x := x) hOff + let num := IScalar.hcast .U64 n + have hev : KEvSpec (.sysU n) true (.unknownSyscall num.val) := KEvSpec.sysU _ _ + have hNot : Fl4Spec.isVmEnterCall num.val σ0 = false := hNotEnter ((), σ0) hF + have hFin0 : EventFinishVE (L := L) (arI := arI) (AR := AR) on rc (.unknownSyscall num.val) + (KFrontF2 (st := st) arI (brK (st := st) (arI := arI) num) s0 a) σ0 := by + intro z hz sf af hfr + exact hFin _ hev ((), σ0) hF z hz sf af ⟨ct, val, hct, by rw [hs]; exact hfr⟩ + have hUnknown := J0.unknownFaultAfterFip hARI hAT hVA hnd hT hRef hDL hmrt hmb hmax htu (on := on) (rc := rc) + hni hnq hf0 hM hMR hVM hoff num hNot hFin0 + unfold syscall.handle_syscall_general + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => ∃ σ', FaultIpOutVF on rc (.unknownSyscall num.val) σ σ' ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ') ?_ ?_ + · have hUSF : syscall.unknown_syscall_fault st arI s0 a num false ⦃ r => ∃ σ', + FaultIpOutVF on rc (.unknownSyscall num.val) σ σ' ∧ VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := + WP.spec_mono hUnknown fun _ ⟨σ', hmem, hVE⟩ => ⟨σ', ⟨((), σ0), hF, hmem⟩, hVE⟩ + unfold syscall.syscall + rw [hct, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s ct layout.reg.NEXT_IP) ?_ + rintro nx rfl + simp only [lift, bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.FAULT_IP _) ?_ + rintro s1 rfl + rw [hs] + obtain ⟨fl, hfl, -⟩ := spec_exists (Fl4Proofs.P0.obj.Tcb.flags.p0 st ct s0 L.total) + rw [hfl, bind_ok] + try simp only [lift, bind_ok] + by_cases htr : (fl &&& fl4_abi.consts.tcb_flag.TRAP_SYSCALLS != 0#u64) = true + · rw [if_pos htr] + exact hUSF + rw [if_neg htr] + have hrange : n < fl4_abi.syscall.SYSCALL_MIN ∨ n > fl4_abi.syscall.SYSCALL_MAX := by + rcases hU with hu | hu | hu + · exact Or.inl hu + · exact Or.inr hu + · exfalso + have h0 := hu ct val hct + rw [hs, hfl, WP.spec_ok] at h0 + exact h0 (by by_contra hne; exact htr (bne_iff_ne.2 hne)) + obtain ⟨d1, d2, d3, d4, d5, d6, d7, d8, d9, dv⟩ := hD + have hv : n = fl4_abi.syscall.SysVMEnter → arI.virtualization a = ok 0#u64 ∨ + ∀ t, sched.cur_thread st s0 = ok t → vcpu.bound st s0 t = ok 0#u64 := fun hn => by + rcases dv hn with e | e + · exact Or.inl e + · refine Or.inr fun t ht => ?_ + have e' : σ0.curThread = t.bv := (J0.1.1.curEq ht).1 + have ect : t = ct := VirtSanEq.u64_ext (e'.symm.trans hcur) + subst t + simpa only [hs] using e ct val hct + have hNd := handle_unknown_syscall_nd arI hAT s0 a n false d1 d2 d3 d4 d5 d6 d7 d8 d9 hv + rcases hrange with hlo | hhi + · rw [if_pos hlo, hNd] + exact hUSF + · by_cases hlo : n < fl4_abi.syscall.SYSCALL_MIN + · rw [if_pos hlo, hNd] + exact hUSF + · rw [if_neg hlo, if_pos hhi, hNd] + exact hUSF + · rintro ⟨b, sf, af⟩ ⟨σ', hmem, hVE⟩ + exact (WP.spec_ok _).2 ⟨_, σ', hev, hmem, hVE⟩ + +set_option maxHeartbeats 4000000 in +/-- **`dispatch_syscall` at `VmEptState`** (module docstring), from its arm hypotheses. -/ +theorem VmEptState.dispatchV (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hPA : PPPlatA arI AR) (hIA : IrqPlatA arI AR) + (hmrt : ∀ a : A, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {n : I64} {c : Fl4Spec.Syscall} (hn : NativeSys n c) + (hD : ∀ (call bl don fp : Bool) (cptr : U64), InvArgs n c call bl don fp → + VDispAt (L := L) arI AR MR on rc Z s a σ ct call bl don fp cptr) + (hO : ∀ (call bl don fp : Bool) (cptr : Fl4Spec.CapRef), InvArgs n c call bl don fp → + ∀ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true call bl don fp cptr).run σ).1, y.1 = .error () → + ∀ (s1 : S) (a1 : A), (∃ (V X : Set U64) (XL : U64 → Nat), VmEptPre (L := L) arI V X XL AR MR s1 a1 y.2) → + VmOrc st on rc s1 y.2) + (hRecv : ∀ (bl cr : Bool), RecvSys n bl cr → syscall.handle_recv st arI s a bl cr ⦃ r => + ∃ z ∈ (Fl4Spec.handleRecv (Z := Unit) bl cr σ).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄) + (hMid : ∀ (rg : U64) (sr : Fl4Spec.Register) (cr : Bool), MidSysR n c rg sr cr → ∀ (cptr : Fl4Spec.CapRef), + ∀ y ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true false false true true cptr).run σ).1, + y.1 = .ok () → ∀ (s1 : S) (a1 : A), VEAny (L := L) arI AR s1 a1 y.2 → + syscall.handle_recv st arI s1 a1 true cr ⦃ r => + ∃ z ∈ (Fl4Spec.handleRecv (Z := Unit) true cr y.2).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄) + (hY : n = fl4_abi.syscall.SysYield → syscall.handle_yield st arI s a ⦃ r => + ∃ z ∈ (Fl4Spec.handleYield (Z := Unit) σ).1, VEAny (L := L) arI AR r.1 r.2 z.2 ⦄) : + syscall.dispatch_syscall st arI s a n ⦃ r => DispPostVE (L := L) arI AR on rc c σ r ⦄ := by + have B := J.1.1 + obtain ⟨hcur, -⟩ := B.curEq hct + obtain ⟨-, xs, hks⟩ := B.xtop.curTcb hcur + have hctT : ct ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm + have hxs := (B.xtop.irelK B.ks B.buf).1.toE.at_tcb hctT hks + have hk' : σ.kheap σ.curThread = some (.tcb xs) := by rw [hcur]; exact hks + have hreg : ∀ r : Fl4Spec.Register, (Fl4Spec.toBl (L.mem s (regA ct (regIdx r))).bv, σ) ∈ + (Fl4Spec.getCapReg (Z := Unit) r σ).1 := by + intro r + have h := mem_getCapReg hk' r + rwa [show Fl4Spec.dataToCptr (xs.tcbArch.tcbContext.userRegs r) = + Fl4Spec.toBl (L.mem s (regA ct (regIdx r))).bv by rw [hxs.regs]; rfl] at h + have hI : ∀ (call bl don fp : Bool) (cptr : U64), InvArgs n c call bl don fp → + syscall.handle_invocation st arI s a call bl don fp cptr ⦃ res => + HIPostVE (L := L) arI AR MR on rc σ call bl don fp cptr res ⦄ := fun call bl don fp cptr hia => + J.handleInvocationE hARI.toARKeep hAT hnd hM.toC hPA on rc hni hct hnq hvfh call bl don fp cptr + (hD call bl don fp cptr hia) + have hAf : ∀ (call bl don fp : Bool) (cptr : U64), InvArgs n c call bl don fp → + ∀ res, HIPostVE (L := L) arI AR MR on rc σ call bl don fp cptr res → + syscall.after_invocation st arI res.2.1 res.2.2 res.1 ⦃ r => InvAfterVE (L := L) arI AR on rc + (Fl4Spec.fl4HandleInvocationVF (Z := Unit) on rc true call bl don fp (Fl4Spec.toBl cptr.bv)) σ r ⦄ := + fun call bl don fp cptr hia res h => VmEptState.afterV hARI hAT hVA hnd hM hMK hPA hIA hmrt hmax htu h + (hO call bl don fp _ hia) + have hC := hreg Fl4Spec.cap_register + rw [regIdx_cap] at hC + have hRp := hreg Fl4Spec.replyRegister + rw [regIdx_reply] at hRp + have hDs := hreg Fl4Spec.nbsendRecvDest + rw [regIdx_nbsendRecvDest] at hDs + unfold syscall.dispatch_syscall + rw [hct]; simp only [bind_ok] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s ct layout.reg.CAP) ?_ + rintro c0 rfl + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s ct layout.reg.REPLY) ?_ + rintro c1 rfl + rcases hn with ⟨call, bl, don, hi, rfl⟩ | ⟨bl, cr, hr, rfl⟩ | ⟨rfl, rfl⟩ | hm + · -- Send / NBSend / Call + have hia : InvArgs n (invSysOf call bl) call bl don false := Or.inl ⟨hi, rfl⟩ + have inv : (do + let (r, s1, a1) ← syscall.handle_invocation st arI s a call bl don false (L.mem s (regA ct layout.reg.CAP)) + let (_, s2, a2) ← syscall.after_invocation st arI s1 a1 r + ok (s2, a2)) ⦃ r => DispPostVE (L := L) arI AR on rc (invSysOf call bl) σ r ⦄ := by + refine WP.spec_bind (hI call bl don false _ hia) ?_ + rintro ⟨r, s1, a1⟩ h1 + refine WP.spec_bind (hAf call bl don false _ hia _ h1) ?_ + rintro ⟨b, s2, a2⟩ ⟨y, hy, ⟨-, hy1, hV⟩ | ⟨-, hy1, z, hz, hV⟩⟩ + · refine (WP.spec_ok _).2 ⟨y, ?_, Or.inl ⟨hy1, hV⟩⟩ + rcases hi with ⟨-, rfl, rfl, rfl⟩ | ⟨-, rfl, rfl, rfl⟩ | ⟨-, rfl, rfl, rfl⟩ <;> + exact mem_bindE_ok (mem_liftE hC) hy + · refine (WP.spec_ok _).2 ⟨y, ?_, Or.inr ⟨hy1, z, hz, hV⟩⟩ + rcases hi with ⟨-, rfl, rfl, rfl⟩ | ⟨-, rfl, rfl, rfl⟩ | ⟨-, rfl, rfl, rfl⟩ <;> + exact mem_bindE_ok (mem_liftE hC) hy + rcases hi with ⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩ + · rw [if_pos rfl]; exact inv + · rw [if_neg (show fl4_abi.syscall.SysNBSend ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysNBSend fl4_abi.syscall.SysSend; decide), if_pos rfl]; exact inv + · rw [if_neg (show fl4_abi.syscall.SysCall ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysCall fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysCall ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysCall fl4_abi.syscall.SysNBSend; decide), if_pos rfl]; exact inv + · -- Recv / NBRecv / Wait / NBWait + have rcv : syscall.handle_recv st arI s a bl cr ⦃ r => DispPostVE (L := L) arI AR on rc (recvSysOf bl cr) σ r ⦄ := by + refine WP.spec_mono (hRecv bl cr hr) ?_ + rintro r ⟨z, hz, hV⟩ + refine ⟨(.ok (), z.2), ?_, Or.inl ⟨rfl, hV⟩⟩ + rcases hr with ⟨-, rfl, rfl⟩ | ⟨-, rfl, rfl⟩ | ⟨-, rfl, rfl⟩ | ⟨-, rfl, rfl⟩ <;> exact mem_liftE hz + rcases hr with ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ + · rw [if_neg (show fl4_abi.syscall.SysRecv ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysRecv fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysRecv ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysRecv fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysRecv ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysRecv fl4_abi.syscall.SysCall; decide), if_pos rfl]; exact rcv + · rw [if_neg (show fl4_abi.syscall.SysNBRecv ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysNBRecv fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysNBRecv ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysNBRecv fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysNBRecv ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysNBRecv fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysNBRecv ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysNBRecv fl4_abi.syscall.SysRecv; decide), if_pos rfl]; exact rcv + · rw [if_neg (show fl4_abi.syscall.SysWait ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysWait fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysWait ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysWait fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysWait ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysWait fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysWait ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysWait fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysWait ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysWait fl4_abi.syscall.SysNBRecv; decide), if_pos rfl]; exact rcv + · rw [if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysNBRecv; decide), if_neg (show fl4_abi.syscall.SysNBWait ≠ fl4_abi.syscall.SysWait by + unfold fl4_abi.syscall.SysNBWait fl4_abi.syscall.SysWait; decide), if_pos rfl]; exact rcv + · -- Yield + rw [if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysNBRecv; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysWait by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysWait; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysNBWait by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysNBWait; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysReplyRecv by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysReplyRecv; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysNBSendRecv by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysNBSendRecv; decide), if_neg (show fl4_abi.syscall.SysYield ≠ fl4_abi.syscall.SysNBSendWait by + unfold fl4_abi.syscall.SysYield fl4_abi.syscall.SysNBSendWait; decide), if_pos rfl] + refine WP.spec_mono (hY rfl) ?_ + rintro r ⟨z, hz, hV⟩ + exact ⟨(.ok (), z.2), mem_liftE hz, Or.inl ⟨rfl, hV⟩⟩ + · -- ReplyRecv / NBSendRecv / NBSendWait + obtain ⟨rg, sr, cr, hmr⟩ := midSysR_of hm + have hia : InvArgs n c false false true true := Or.inr ⟨hm, rfl, rfl, rfl, rfl⟩ + have mid : ∀ (cptr : U64), (Fl4Spec.toBl cptr.bv, σ) ∈ (Fl4Spec.getCapReg (Z := Unit) sr σ).1 → + (do + let (r, s1, a1) ← syscall.handle_invocation st arI s a false false true true cptr + let (b, s2, a2) ← syscall.after_invocation st arI s1 a1 r + if b then syscall.handle_recv st arI s2 a2 true cr else ok (s2, a2)) ⦃ r => + DispPostVE (L := L) arI AR on rc c σ r ⦄ := by + intro cptr hrg + refine WP.spec_bind (hI false false true true _ hia) ?_ + rintro ⟨r, s1, a1⟩ h1 + refine WP.spec_bind (hAf false false true true _ hia _ h1) ?_ + rintro ⟨b, s2, a2⟩ ⟨y, hy, ⟨hb, hy1, hV⟩ | ⟨hb, hy1, z, hz, hV⟩⟩ <;> dsimp only at hb <;> subst hb + · try rw [if_pos rfl] + refine WP.spec_mono (hMid rg sr cr hmr _ y hy hy1 s2 a2 hV) ?_ + rintro r ⟨z, hz, hVz⟩ + have hy' : ((.ok (), y.2) : Except Unit Unit × Fl4Spec.State Unit) ∈ ((Fl4Spec.fl4HandleInvocationVF (Z := Unit) + on rc true false false true true (Fl4Spec.toBl cptr.bv)).run σ).1 := by rw [← hy1]; exact hy + refine ⟨(.ok (), z.2), ?_, Or.inl ⟨rfl, hVz⟩⟩ + rcases hmr with ⟨-, rfl, -, rfl, rfl⟩ | ⟨-, rfl, -, rfl, rfl⟩ | ⟨-, rfl, -, rfl, rfl⟩ <;> + exact mem_bindE_ok (mem_liftE hrg) (mem_bindE_ok hy' (mem_liftE hz)) + · try rw [if_neg (show ¬ (false = true) by decide)] + have hy' : ((.error (), y.2) : Except Unit Unit × Fl4Spec.State Unit) ∈ ((Fl4Spec.fl4HandleInvocationVF + (Z := Unit) on rc true false false true true (Fl4Spec.toBl cptr.bv)).run σ).1 := by rw [← hy1]; exact hy + refine (WP.spec_ok _).2 ⟨(.error (), y.2), ?_, Or.inr ⟨rfl, z, hz, hV⟩⟩ + rcases hmr with ⟨-, rfl, -, rfl, rfl⟩ | ⟨-, rfl, -, rfl, rfl⟩ | ⟨-, rfl, -, rfl, rfl⟩ <;> + exact mem_bindE_ok (mem_liftE hrg) (mem_bindE_err hy') + rcases hmr with ⟨rfl, rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl, rfl⟩ + · rw [if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysNBRecv; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysWait by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysWait; decide), if_neg (show fl4_abi.syscall.SysReplyRecv ≠ fl4_abi.syscall.SysNBWait by + unfold fl4_abi.syscall.SysReplyRecv fl4_abi.syscall.SysNBWait; decide), if_pos rfl]; exact mid _ hRp + · rw [if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysNBRecv; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysWait by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysWait; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysNBWait by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysNBWait; decide), if_neg (show fl4_abi.syscall.SysNBSendRecv ≠ fl4_abi.syscall.SysReplyRecv by + unfold fl4_abi.syscall.SysNBSendRecv fl4_abi.syscall.SysReplyRecv; decide), if_pos rfl] + refine WP.spec_bind (Endp.obj.Tcb.reg.spec s ct layout.reg.NBSEND_RECV_DEST) ?_ + rintro c2 rfl + exact mid _ hDs + · rw [if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysSend by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysSend; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysNBSend by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysNBSend; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysCall by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysCall; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysRecv by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysRecv; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysNBRecv by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysNBRecv; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysWait by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysWait; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysNBWait by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysNBWait; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysReplyRecv by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysReplyRecv; decide), if_neg (show fl4_abi.syscall.SysNBSendWait ≠ fl4_abi.syscall.SysNBSendRecv by + unfold fl4_abi.syscall.SysNBSendWait fl4_abi.syscall.SysNBSendRecv; decide), if_pos rfl]; exact mid _ hRp + +set_option maxHeartbeats 4000000 in +/-- **FL4's syscall entry at `VmEptState`** (module docstring): every outcome of `handle_syscall n` is related, by +`VEAny`, to an outcome of `fl4KernelEntrySyscallVF on rc true c σ`. -/ +theorem VmEptState.kernel_entry [P1.PlainStore st] (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hSy : ZvSyncKeep arI AR) (hCap : ∀ a', VirtSanEq.CapAgree arI a') + (hPI : PortInValMR arI MR) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hPA : PPPlatA arI AR) (hIA : IrqPlatA arI AR) + (hmrt : ∀ a : A, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + (hT : TimeAgree arI) (hRef : ArchRefines arI AR) (hDL : SetDlDet) + {on rc : Fl4Spec.ObjRef → Bool} + {V X : Set U64} {XL : U64 → Nat} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) (hMR : MR a σ.machineState) + (hRun : ∀ ct, sched.cur_thread st s = ok ct → ZvCtRun σ ct) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {n : I64} {c : Fl4Spec.Syscall} (hn : NativeSys n c) + (hflag : ∀ ct v, sched.cur_thread st s = ok ct → obj.Tcb.flags st ct (L.wr s (regA ct layout.reg.FAULT_IP) v) + ⦃ f => (f &&& fl4_abi.consts.tcb_flag.TRAP_SYSCALLS) = 0#u64 ⦄) + (K : KEntryArmsV (L := L) arI AR MR on rc n c s a σ) : + syscall.handle_syscall st arI s a n ⦃ r => ∃ σ' : Fl4Spec.State Unit, + ((), σ') ∈ (Fl4Spec.fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + have hAK := hARI.toARKeep + have hct := cur_thread_eq (L := L) s + generalize L.mem s (L.nodeAt s (L.cpu s) layout.node.CUR_THREAD) = ct at hct + have B := J.1.1 + obtain ⟨hcur, -⟩ := B.curEq hct + have hctT : ct ∈ Z.T := TopSR.cur_mem B.xtop.fin.1 hcur.symm + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, -⟩ := hI.1.tcb ct hctT + have hxs := hI.1.toE.at_tcb hctT hk + have hk' : σ.kheap σ.curThread = some (.tcb x) := by rw [hcur]; exact hk + have hF : ((), faultIPSt σ σ.curThread x) ∈ (Fl4Spec.fl4SyscallFaultIP (Z := Unit) σ.curThread σ).1 := by + rw [fl4SyscallFaultIP_eq hk']; exact Set.mem_singleton _ + -- the exit from every finish state + have fin : ∀ xo ∈ (specFrontVF on rc c σ).1, ∀ (s' : S) (a' : A), KFrontF (L := L) arI n s a s' a' → + VEAny (L := L) arI AR s' a' xo.2 → syscall.finish st arI s' a' ⦃ r => ∃ σ' : Fl4Spec.State Unit, + ((), σ') ∈ (Fl4Spec.fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 ∧ + VEAny (L := L) arI AR r.1 r.2 σ' ⦄ := by + rintro xo hxo s' a' hKF ⟨V', X', XL', Z', H', Cs', Ac', Lst', D', J'⟩ + have F := K.fin xo hxo s' a' hKF V' X' XL' Z' H' Cs' Ac' Lst' D' J' + refine WP.spec_mono (J'.finishVF hAT hVA hAK hmb F.orc F.hd hnd (sniHyp_of hAT hDL) (sendHyp_of hAT) + hT hRef F.arch F.archNd F.fo F.idle hmax htu) ?_ + rintro r ⟨σ', hmem, V2, Ac2, Lst2, D2, J2⟩ + exact ⟨σ', mem_kentryVF hxo hmem, J2.any arI⟩ + have hS : syscall.syscall st arI s a n true ⦃ r => ∃ σ' : Fl4Spec.State Unit, + ((), σ') ∈ (Fl4Spec.fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := by + unfold syscall.syscall + rw [hct]; simp only [bind_ok] + obtain ⟨nx, hnx, hnxv⟩ := spec_exists (Endp.obj.Tcb.reg.spec (L := L) s ct layout.reg.NEXT_IP) + rw [hnx]; simp only [lift, bind_ok] + obtain ⟨s1, hs1, rfl⟩ := spec_exists (Endp.obj.Tcb.set_reg.spec (L := L) s ct layout.reg.FAULT_IP + (core.num.U64.wrapping_sub nx 2#u64)) + rw [hs1]; simp only [bind_ok] + generalize hv : core.num.U64.wrapping_sub nx 2#u64 = v + have hvb : v.bv = x.tcbArch.tcbContext.userRegs .nextIP - 2 := by + rw [← hv, core.num.U64.wrapping_sub_bv_eq, hnxv, ← hxs.regs .nextIP, regIdx_nextIP]; rfl + have hX2 := reg_wr_irel B.ip hI hctT hk Fl4Spec.Register.faultIP (by decide) v + rw [regIdx_faultIP] at hX2 + obtain ⟨V0, B0, F0⟩ := B.regWrJ hctT hk Fl4Spec.Register.faultIP v (by rw [regIdx_faultIP]; exact hX2) + rw [regIdx_faultIP] at B0 F0 + have J0 := J.ofNat B0 F0 + rw [hvb, ← hcur] at J0 + obtain ⟨f, hf, hf0⟩ := spec_exists (hflag ct v hct) + rw [hf]; simp only [bind_ok, hf0, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte] + simp only [if_neg hn.range.1, if_neg hn.range.2] + obtain ⟨⟨b, s2, a2⟩, hbe, ⟨σb, hb, hVb⟩, hMRb⟩ := spec_exists + (WP.spec_and (K.budget ct v _ hct hF (J0.any arI)) (budget_ok_mr hM hMK hAT hMR _)) + rw [hbe]; simp only [bind_ok] + cases b + · -- the budget check stops the system call + try simp only [Bool.false_eq_true, ↓reduceIte] + refine WP.spec_bind (fin _ (mem_frontVF_stop hF hb) s2 a2 + ⟨ct, v, false, s2, a2, hct, hbe, Or.inl ⟨rfl, rfl, rfl⟩⟩ hVb) ?_ + rintro ⟨s3, a3⟩ h + exact (WP.spec_ok _).2 h + -- the system call runs + have hBA : BudgetAt σ σb true := ⟨_, hF, hb⟩ + have hfr : KFrontB (L := L) arI s a s2 a2 := ⟨ct, v, hct, hbe⟩ + have hnib : Entered σb := BudgetAt.entered hnd hk' hni hBA + obtain ⟨⟨σu, hu, hσu⟩, hkb, hcb, -, -, hrqb⟩ := BudgetAt.shape27 hnd hk' hBA + have hms : σb.machineState = gctState σ.machineState := by + rw [Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq (faultIPSt σ σ.curThread x).machineState))] at hu + have he := congrArg Prod.snd (Set.mem_singleton_iff.1 hu) + dsimp only at he + rw [hσu, he] + rfl + have hPort := hPI.at (hms.symm ▸ hMRb) + have hnqb : ∀ d p, σb.curThread ∉ σb.readyQueues d p := by rw [hcb, hrqb]; exact hnq + have hvfhb : ∀ x', σb.kheap σb.curThread = some (.tcb x') → + Fl4Spec.validFaultHandler x'.tcbFaultHandler := by + intro x' hx' + rw [hkb, hcb] at hx' + simp only [faultIPSt, updK, Function.update_self, Option.some.injEq, Fl4Spec.KernelObject.tcb.injEq] at hx' + subst hx' + exact hvfh x hk' + obtain ⟨Vb, Xb, XLb, Zb, Hb, Csb, Acb, Lstb, Db, Jb⟩ := hVb + have hct2 := cur_thread_eq (L := L) s2 + generalize L.mem s2 (L.nodeAt s2 (L.cpu s2) layout.node.CUR_THREAD) = ct2 at hct2 + have hRunB : ZvCtRun σb ct2 := by + obtain ⟨hcur2, -, -⟩ := Jb.1.1.curEq hct2 + intro xb hxb + rw [← hcur2, hcb, hkb] at hxb + simp only [faultIPSt, updK, Function.update_self, Option.some.injEq, + Fl4Spec.KernelObject.tcb.injEq] at hxb + subst xb + exact hRun ct hct x hk + have disp := Jb.dispatchV hARI hAT hVA hnd hM hMK hPA hIA hmrt hmax htu hnib hct2 hnqb hvfhb hn + (fun call bl don fp cptr hia => Jb.dispatchAt arI AR MR hnib hRef hVA hAK hSy hCap hAT hARI.toMask + hPort on rc hct2 hRunB call bl don fp cptr + (K.disp s2 a2 σb hfr hBA Vb Xb XLb Zb Hb Csb Acb Lstb Db Jb ct2 hct2 hRunB call bl don fp cptr hia)) + (fun call bl don fp cptr hia => K.orc σb hBA call bl don fp cptr hia) + (fun bl cr hr => K.recv bl cr hr s2 a2 σb hfr hBA (Jb.any arI)) + (fun rg sr cr hm => K.recvMid rg sr cr hm σb hBA) + (fun hy => K.yield hy s2 a2 σb hfr hBA (Jb.any arI)) + have dispFin : (do + let (s3, a3) ← syscall.dispatch_syscall st arI s2 a2 n + let (s4, a4) ← syscall.finish st arI s3 a3 + ok (false, s4, a4)) ⦃ r => ∃ σ' : Fl4Spec.State Unit, + ((), σ') ∈ (Fl4Spec.fl4KernelEntrySyscallVF (Z := Unit) on rc true c σ).1 ∧ + VEAny (L := L) arI AR r.2.1 r.2.2 σ' ⦄ := by + obtain ⟨⟨s3, a3⟩, hde, y, hy, hP⟩ := spec_exists disp + rw [hde]; simp only [bind_ok] + have hKF : KFrontF (L := L) arI n s a s3 a3 := ⟨ct, v, true, s2, a2, hct, hbe, Or.inr ⟨rfl, hde⟩⟩ + rcases hP with ⟨hy1, hV⟩ | ⟨hy1, z, hz, hV⟩ + · refine WP.spec_bind (fin _ (mem_frontVF_ok hF hb hy hy1) s3 a3 hKF hV) ?_ + rintro ⟨s4, a4⟩ h + exact (WP.spec_ok _).2 h + · refine WP.spec_bind (fin _ (mem_frontVF_err hF hb hy hy1 hz) s3 a3 hKF hV) ?_ + rintro ⟨s4, a4⟩ h + exact (WP.spec_ok _).2 h + change (if n = fl4_abi.syscall.SysReplyRecv then _ else _) ⦃ _ ⦄ + by_cases hrr : n = fl4_abi.syscall.SysReplyRecv + · rw [if_pos hrr] + obtain ⟨⟨b1, s3, a3⟩, hfe, hf1, hf2⟩ := spec_exists (K.fast hrr s2 a2 σb hfr hBA (Jb.any arI)) + rw [hfe]; simp only [bind_ok] + cases b1 + · have e : (s3, a3) = (s2, a2) := hf2 rfl + simp only [Prod.mk.injEq] at e + obtain ⟨rfl, rfl⟩ := e + exact dispFin + · exact (WP.spec_ok _).2 (hf1 rfl) + · rw [if_neg hrr] + exact dispFin + unfold syscall.handle_syscall + refine WP.spec_bind hS ?_ + rintro ⟨b0, s', a'⟩ h + exact (WP.spec_ok _).2 h + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmOracle.lean b/proofs/Fl4Proofs/P3/VmOracle.lean new file mode 100644 index 000000000..3e7389f80 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmOracle.lean @@ -0,0 +1,484 @@ +/- +P3 (line mmuAD, gen 42b72, the Architect's ruling 16:16Z, (c3) part 1): **the oracles of `sendSignalVF` for a whole +kernel entry**, and the IRQ handler at `VmEptState`. + +The extended spec's `fl4HandleEventVF` / `preemptionPathVF` / `fl4AwakenVF` read one pair of oracles `onCore`, +`remoteCur` for the whole entry, while FL4's `vcpu::signal_completes` reads the thread's `AFFINITY` and its core's +`CUR_THREAD` at each signal (P3/JAtZV3SigComp's `v3OnCore st s` / `v3RemCur st s` at the signal point `s`). + +* `isRunVMF st s t`: FL4's state word of `t` is `TS_RUNNING_VM` (8). **`onCoreEff st s0 s1`** (the ruling's oracle): + at a thread `runningVM` at `s1` (the state after the invocation) the reading at `s1`, at any other the reading at the + entry state `s0`. **`remCurEff st s0 s1`**: the same for `remoteCur` (finding of gen 42b72, see `# gen 42b72` of the + handoff: the ruling's `v3RemCur st s0` is false after a `SchedControl_ConfigureFlags` migrating a `runningVM` thread + that is current on its old core). +* `OrcAg on rc on' rc' σ`: two oracle pairs agree on every `runningVM` thread of `σ` (`remoteCur` only where `onCore` is + false: `vmSignalCompletes` reads it only there). `vmSC_congr`, **`sendSignalVF_congr`**: `sendSignalVF` reads its + oracles only there. **`VmOrc st on rc s σ`**: `OrcAg` against the reading at `s`. +* **`JAtZB.vmOrcEff`**: at the post-invocation state `s1`, `onCoreEff` / `remCurEff` are `VmOrc` (each `runningVM` + thread of the spec has state word 8, `JAtZB.specTcb`). **`VmOrc.keep`**: `VmOrc` is kept by a step that makes no + thread `runningVM`, keeps the executing core, the `AFFINITY` of every thread `runningVM` after and the `CUR_THREAD` + word of every other core such a thread has. +* **`VmEptState.signalVFo`**: P3/VmSignal's `VmEptState.signalVF` against any `VmOrc` oracles. +* `handleInterruptVF_hiS`: the extended handler is XTopJointIrq's `hiS` at `sendSignalVF`. **`VmEptState.handleIrqVF`**: + FL4's `handle_interrupt` from `VmEptState` against `handleInterruptVF on rc` (XTopJointIrqZR's `JAtZB.handleIrqJG` at + `Q := VmEptState`: native arms by `VmEptState.ofNat`, the signal by `signalVFo`; the handler reads its line before + signalling, so `VmOrc` at the start is all it needs). + +(gen 42b73, ruling 17:14Z option (i): a per-step `AffK`, no [J] premise) +* **`VmEptState.signalVFk`**: `send_signal` keeps `VmOrc` (`VmOrc.keep`'s four conditions): FL4 writes the `AFFINITY` + of the woken thread only and no other core's `CUR_THREAD` (P2/FootN8's `send_signal.ffG` at `Kp := ∅`, `Ks := ∅`, + `Il` = every thread `send_signal` does not wake; `FFoot.affK`, `FFoot.curK`), the spec makes no thread `runningVM` + (P3/VmSignal's `VmEptState.signalVFK`, `RvmSub`); a woken thread is blocked at the start, or is the bound thread + `signal_completes` accepts, which is `runningVM` after only if FL4's read refused it. +* `VmOrc.tmw` (timer-word and `REPROGRAM` writes keep `VmOrc`), `fireG_sendSignalVF` (`FireG (sendSignalVF on rc)` is + `fl4TimerFireVF on rc`), `VmFireP`, **`VmEptState.fire_loopVF`**: FL4's TCB timers at `VmEptState` against + `fl4TimerFireVF` (ScFireJ's `fire_loopG`; the timer words by P3/XTopJointFinThread's `JAtZB.tmwN`). + +(gen 42b75, ruling 19:49Z item 1) +* **`mfk_sendSignalVF`**: the extended signal keeps the machine fields (P3/MachFieldFam's `MFK`); + **`msig_sendSignalVF`**: with P3/MachKeep's `MRKeep` and `MachPlat`, the `MR` fact of the signal (`hMsig`) is no longer a given fact. +* `FootN.vmOrc` (moved here from P3/VmPreempt, statement unchanged), **`footN_tmArm`**: the timer line's `REPROGRAM` / + `ARMED` writes are a `FootN ∅ True` step. **`VmEptState.handleIrqVFk`**: `handleIrqVF` with `VmOrc` after (native + arms by `FootN.vmOrc` from XTopJointIrqZR's `hNQ` writes, the signal by `signalVFk`); `handleIrqVF` its corollary. + +Premises: those `VmEptState.signalVF` takes (`P0.ArchTotal`, [P] `ZvVirtAgree`, `ARKeep`, the platform's +`MIN_BUDGET`) and those `JAtZB.handleIrqJB` takes (`ARIface`, the acknowledgement's `AR` fact, the `MR` facts); the +platform records `MachPlat` / `MRKeep` [P] for `msig_sendSignalVF`. No named premise; no existing statement changed. +-/ +import Fl4Proofs.P3.VmSignal +import Fl4Proofs.P2.FootN8 +import Fl4Proofs.P3.XTopJointIrqZR +import Fl4Spec.Ext.VirtKernelF +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +variable {S : Type} + +/-- FL4's state word of `t` is `TS_RUNNING_VM`. -/ +def isRunVMF (st : machine.Store S) [L : P1.LawfulStore st] (s : S) (t : Fl4Spec.ObjRef) : Bool := + decide (L.mem s (P1.stA ({ bv := t } : U64)) = 8#u64) + +/-- **The entry's `onCore`** (module docstring): the reading after the invocation (`s1`) at a thread `runningVM` +there, the entry's (`s0`) at any other. -/ +def onCoreEff (st : machine.Store S) [L : P1.LawfulStore st] (s0 s1 : S) (t : Fl4Spec.ObjRef) : Bool := + if isRunVMF st s1 t then v3OnCore st s1 t else v3OnCore st s0 t + +/-- **The entry's `remoteCur`** (module docstring), as `onCoreEff`. -/ +def remCurEff (st : machine.Store S) [L : P1.LawfulStore st] (s0 s1 : S) (t : Fl4Spec.ObjRef) : Bool := + if isRunVMF st s1 t then v3RemCur st s1 t else v3RemCur st s0 t + +end + +section +open Fl4Spec Classical Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp + +/-- Two oracle pairs agree on every `runningVM` thread of `σ` (`remoteCur` where `onCore` is false). -/ +def OrcAg (on rc on' rc' : ObjRef → Bool) (σ : State Unit) : Prop := + ∀ t y, σ.kheap t = some (.tcb y) → y.tcbState = .runningVM → on t = on' t ∧ (on t = false → rc t = rc' t) + +/-- `vmSignalCompletes` reads `remoteCur` only where `onCore` is false. -/ +theorem vmSC_congr {on rc on' rc' : ObjRef → Bool} {t : ObjRef} (h1 : on t = on' t) + (h2 : on t = false → rc t = rc' t) : + vmSignalCompletes (Z := Unit) on rc t = vmSignalCompletes on' rc' t := by + unfold vmSignalCompletes + cases hon : on t + · rw [← h1, hon, h2 hon] + · rw [← h1, hon] + simp only [true_or, and_true] + +/-- **`sendSignalVF` reads its oracles only on `runningVM` threads** (module docstring). -/ +theorem sendSignalVF_congr {on rc on' rc' : ObjRef → Bool} {σ : State Unit} {n : ObjRef} {x : Notification} + (hk : σ.kheap n = some (.notification x)) (b : Badge) + (hbt : ∀ t, x.ntfnBoundTcb = some t → ∃ y, σ.kheap t = some (.tcb y)) + (h : OrcAg on rc on' rc' σ) : + sendSignalVF (Z := Unit) on rc n b σ = sendSignalVF on' rc' n b σ := by + by_cases hvm : x.ntfnObj = .idleNtfn ∧ ∃ t y, x.ntfnBoundTcb = some t ∧ σ.kheap t = some (.tcb y) ∧ + y.tcbState = .runningVM + · obtain ⟨hidle, t, y, hb, hkt, hrs⟩ := hvm + obtain ⟨h1, h2⟩ := h t y hkt hrs + have e := vmSC_congr (rc := rc) (rc' := rc') h1 h2 + unfold sendSignalVF + rw [nd_bind_one (getNotification_eq hk), nd_bind_one (getNotification_eq hk), hidle, hb] + dsimp only + rw [e] + · have hn : x.ntfnObj = .idleNtfn → ∀ t, x.ntfnBoundTcb = some t → + ∃ y, σ.kheap t = some (.tcb y) ∧ y.tcbState ≠ .runningVM := fun ho t hb => by + obtain ⟨y, hkt⟩ := hbt t hb + exact ⟨y, hkt, fun hr => hvm ⟨ho, t, y, hb, hkt, hr⟩⟩ + rw [v3_ssVF_nvm on rc b hk hn, v3_ssVF_nvm on' rc' b hk hn] + +/-- The extended handler is `hiS` at `sendSignalVF`. -/ +theorem handleInterruptVF_hiS (on rc : ObjRef → Bool) (i : Irq) : + handleInterruptVF (Z := Unit) on rc i = hiS (sendSignalVF on rc) i := rfl + +/-- (gen 42b75, ruling 19:49Z item 1) **The extended signal keeps the machine fields** (P3/MachFieldFam's `MFK`: the +IRQ masks, the IRQ and clock oracles, the last machine time and the interrupt table): its VMEnter report, donation, +switch and refill check are `MFK` leaves; the rest is the ported `sendSignal` (`mfk_sendSignal'`). -/ +theorem mfk_sendSignalVF (on rc : ObjRef → Bool) (n : ObjRef) (b : Badge) : + MachF.MFK (sendSignalVF (Z := Unit) on rc n b) := by + unfold sendSignalVF vmSignalCompletes vmReportF vcpuUpdate setVcpu getTcbVcpu vmFullReply vmFaultIpNext getVcpu + mfk_auto + +end + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] + +/-- **The oracles agree with FL4's reading at `s`** on every `runningVM` thread of `σ` (module docstring). -/ +def VmOrc (st : machine.Store S) [L : P1.LawfulStore st] (on rc : Fl4Spec.ObjRef → Bool) (s : S) + (σ : Fl4Spec.State Unit) : Prop := + OrcAg on rc (v3OnCore st s) (v3RemCur st s) σ + +/-- **`VmOrc` across a step** (module docstring): no thread becomes `runningVM`, the executing core is kept, and so +are the `AFFINITY` of every thread `runningVM` after and the `CUR_THREAD` word of its core when that core is another. -/ +theorem VmOrc.keep {on rc : Fl4Spec.ObjRef → Bool} {s s' : S} {σ σ' : Fl4Spec.State Unit} + (hO : VmOrc st on rc s σ) + (hvm : ∀ t y', σ'.kheap t = some (.tcb y') → y'.tcbState = .runningVM → + ∃ y, σ.kheap t = some (.tcb y) ∧ y.tcbState = .runningVM) + (hcpu : L.cpu s' = L.cpu s) + (haf : ∀ t y', σ'.kheap t = some (.tcb y') → y'.tcbState = .runningVM → + L.mem s' (P1.affA ({ bv := t } : U64)) = L.mem s (P1.affA ({ bv := t } : U64))) + (hcur : ∀ t y', σ'.kheap t = some (.tcb y') → y'.tcbState = .runningVM → + L.mem s (P1.affA ({ bv := t } : U64)) ≠ L.cpu s → + L.mem s' (L.nodeAt s' (L.mem s (P1.affA ({ bv := t } : U64))) layout.node.CUR_THREAD) = + L.mem s (L.nodeAt s (L.mem s (P1.affA ({ bv := t } : U64))) layout.node.CUR_THREAD)) : + VmOrc st on rc s' σ' := by + intro t y' hk' hr' + obtain ⟨y, hk, hr⟩ := hvm t y' hk' hr' + obtain ⟨h1, h2⟩ := hO t y hk hr + have eon : v3OnCore st s' t = v3OnCore st s t := by + unfold v3OnCore; rw [haf t y' hk' hr', hcpu] + refine ⟨h1.trans eon.symm, fun hf => ?_⟩ + have hne : L.mem s (P1.affA ({ bv := t } : U64)) ≠ L.cpu s := by + have h0 : v3OnCore st s t = false := h1 ▸ hf + unfold v3OnCore at h0 + simpa using h0 + rw [h2 hf] + unfold v3RemCur + rw [haf t y' hk' hr', hcur t y' hk' hr' hne] + +end + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {H : P1.Heap} {Cs : Set U64} + +/-- **A `FootN ∅ True` step keeps `VmOrc`** (P3/VmPreempt's module docstring; moved here in gen 42b75; (gen 42b77) +over any `IpcFootN ∅ True` step, `FootN.vmOrc` its corollary): the spec heap moves under `RvmSub`, every TCB of the spec after is one of `H`'s; FL4's `AFFINITY` words, +core and other cores' `CUR_THREAD` are protected words. -/ +theorem IpcFootN.vmOrc {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} {σ σ' : Fl4Spec.State Unit} + (h0 : P1.SchedQueuesInv st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H s Q R) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) {Ω U : Set U64} + (F : P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs Ω (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U + s s') + (hR : RvmSub σ σ') (hT : ∀ t y', σ'.kheap t = some (.tcb y') → ∃ u ∈ P1.Heap.tcbs H, t = u.bv) : + VmOrc st on rc s' σ' := by + refine hO.keep hR F.2.1 (fun t y' hk' _ => ?_) (fun t y' hk' _ hne => ?_) + · obtain ⟨u, hu, rfl⟩ := hT t y' hk' + exact F.idKeep (P1.field_aligned (h0.tcbs u hu) (by simp) (by simp)) + (Or.inr (Or.inr ⟨trivial, Or.inl ⟨u, hu, h0.tcbs u hu, Or.inr rfl⟩⟩)) + · obtain ⟨u, hu, rfl⟩ := hT t y' hk' + have hcs : L.mem s (P1.affA u) ∈ Cs := h0.aff u hu + have h0v : layout.node.CUR_THREAD.val = 0 := by simp [layout.node.CUR_THREAD] + show L.mem s' (L.nodeAt s' (L.mem s (P1.affA u)) layout.node.CUR_THREAD) = + L.mem s (L.nodeAt s (L.mem s (P1.affA u)) layout.node.CUR_THREAD) + rw [P1.nodeAt_of_ksb F.1] + exact F.idKeep (P1.nodeAt_aligned (h0.nodes _ hcs) (by omega) (by omega)) + (Or.inl ⟨_, hcs, layout.node.CUR_THREAD, Or.inr (Or.inr (Or.inl ⟨hne, Or.inl h0v⟩)), rfl⟩) + + +/-- `IpcFootN.vmOrc` at a `FootN ∅ True` step (statement before gen 42b77). -/ +theorem FootN.vmOrc {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} {σ σ' : Fl4Spec.State Unit} + (h0 : P1.SchedQueuesInv st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H s Q R) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) + (F : P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s') + (hR : RvmSub σ σ') (hT : ∀ t y', σ'.kheap t = some (.tcb y') → ∃ u ∈ P1.Heap.tcbs H, t = u.bv) : + VmOrc st on rc s' σ' := + IpcFootN.vmOrc h0 hO (P1.FootN.ipc (Ω := ∅) (U := ∅) F) hR hT + +/-- (gen 42b75) **The timer line's writes are a `FootN ∅ True` step**: `REPROGRAM` (56) and `ARMED` (80) of the +executing core's node are `KW` node words and no node identity word. -/ +theorem footN_tmArm {s s1 : S} {T Sg Scs : Set U64} {Zb : U64 → Nat} {Es : Set U64} + (NP : ∀ c ∈ Cs, P1.NodePlaced st T s c) (hcpu : L.cpu s ∈ Cs) + (hw : P1.WritesIn st s s1 (fun b => b = L.nodeAt s (L.cpu s) layout.node.REPROGRAM ∨ + b = L.nodeAt s (L.cpu s) layout.node.ARMED)) : + P1.FootN st ∅ True T Cs Sg Scs Zb Es s s1 := by + refine P1.FootN.of' hw (fun b _ hb => ?_) (fun _ h => ((Set.mem_empty_iff_false _).1 h).elim) + rcases hb with rfl | rfl + · exact ⟨P1.kw_node hcpu (by simp [layout.node.REPROGRAM]) (by simp [layout.node.REPROGRAM]), + P1.notIdW_node NP hcpu (by simp [layout.node.REPROGRAM]) + (P1.idOff_cur (by simp [layout.node.REPROGRAM]) (by simp [layout.node.REPROGRAM]) + (fun _ => by simp [layout.node.REPROGRAM]))⟩ + · exact ⟨P1.kw_node hcpu (by simp [layout.node.ARMED]) (by simp [layout.node.ARMED]), + P1.notIdW_node NP hcpu (by simp [layout.node.ARMED]) + (P1.idOff_cur (by simp [layout.node.ARMED]) (by simp [layout.node.ARMED]) + (fun _ => by simp [layout.node.ARMED]))⟩ + +end + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} {XL : U64 → Nat} + +/-- **`onCoreEff` / `remCurEff` are `VmOrc` at the state after the invocation** (module docstring). -/ +theorem JAtZB.vmOrcEff (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (s0 : S) : + VmOrc st (onCoreEff st s0 s) (remCurEff st s0 s) s σ := by + intro t y hk hr + obtain ⟨u, hu, rfl⟩ := J.obj.tcb t y hk + obtain ⟨x, hk', hw⟩ := J.specTcb (J.thTcb hu) + have e : x = y := by rw [hk] at hk'; simpa using hk'.symm + subst e + have h8 : L.mem s (P1.stA u) = 8#u64 := UScalar.eq_of_val_eq (by rw [hw, hr]; simp [Notif.tsCode]) + have hrv : isRunVMF st s u.bv = true := by + show decide (L.mem s (P1.stA u) = 8#u64) = true + exact decide_eq_true h8 + refine ⟨?_, fun _ => ?_⟩ <;> simp only [onCoreEff, remCurEff, hrv, ↓reduceIte] + +set_option maxHeartbeats 4000000 in +/-- **`send_signal` at `VmEptState` against `sendSignalVF` at any `VmOrc` oracles** (module docstring). -/ +theorem VmEptState.signalVFo (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) (badge : U64) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, hx⟩ := B.xtop.ipc.toN.ntfn n hn + have heq : Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv badge.bv σ = + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ := + sendSignalVF_congr hk _ (fun t hb => by + obtain ⟨hb0, hbt⟩ := Notif.optRef_some (hx.bound ▸ hb) + obtain ⟨tcb, hkt, -⟩ := hI.1.tcb _ (hx.bound_mem hb0) + rw [hbt] at hkt + exact ⟨tcb, hkt⟩) hO + exact WP.spec_mono (J.signalVF hAT hVA hK hmb hn badge) fun _ ⟨σ', Ac', Lst', D', h1, h2, J'⟩ => + ⟨σ', Ac', Lst', D', heq.trans h1, h2, J'⟩ + +set_option maxHeartbeats 4000000 in +/-- (gen 42b73, ruling 17:14Z option (i)) **`send_signal` keeps `VmOrc`** (module docstring): FL4's side writes the +`AFFINITY` of the thread it wakes only (P2/FootN8's `send_signal.ffG` at `Kp := ∅`, `Ks := ∅` and `Il` every thread +but the woken one: `FFoot.affK`), no other core's `CUR_THREAD` (`FFoot.curK`), keeps the core; the spec side makes no +thread `runningVM` (`VmEptState.signalVFK`'s `RvmSub`); a woken thread blocked at the start is no `runningVM` thread, +and the bound thread `signal_completes` accepts is `runningVM` after only if FL4's read refused it. -/ +theorem VmEptState.signalVFk (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) (badge : U64) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ + VmOrc st on rc r.1 σ' ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, hx⟩ := B.xtop.ipc.toN.ntfn n hn + have heq : Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv badge.bv σ = + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ := + sendSignalVF_congr hk _ (fun t hb => by + obtain ⟨hb0, hbt⟩ := Notif.optRef_some (hx.bound ▸ hb) + obtain ⟨tcb, hkt, -⟩ := hI.1.tcb _ (hx.bound_mem hb0) + rw [hbt] at hkt + exact ⟨tcb, hkt⟩) hO + have hnH : n ∈ P1.Heap.ntfns H := B.zH.2.2.2 n hn + have hB0 := B.blk + obtain ⟨⟨Q, R, h0⟩, -, hX, -, -⟩ := hB0 + have hT := h0.tcbs + -- the threads `send_signal` may wake + let W0 : U64 → Prop := fun y => + (L.epState s n = obj.NTFN_IDLE ∧ L.mem s (P1.ntfnBtA n) = y ∧ + (L.mem s (P1.stA y) = sched.TS_BLOCKED_ON_RECV ∨ vcpu.signal_completes st s y = ok true)) ∨ + (L.epState s n = 1#u64 ∧ (L.epQ s n).head = y) + have hF := Fl4Proofs.P2.Stall.notification.send_signal.ffG (Kp := ∅) (Il := {y | ¬ W0 y}) (Ks := ∅) hAT s a n + badge B.blk hnH hnH B.bufAtJ.1 B.bufAtJ.2 (fun _ h => ((Set.mem_empty_iff_false _).1 h).elim) + (fun _ h => ((Set.mem_empty_iff_false _).1 h).elim) (fun _ h => ((Set.mem_empty_iff_false _).1 h).elim) + (fun i hi hb hst => ⟨(Set.mem_empty_iff_false _).1, fun h => h (Or.inl ⟨hi, hb, Or.inl hst⟩)⟩) + (fun i hi hb _ => WP.spec_mono (spec_self (P1.vcpu.signal_completes.blk s i)) fun v e hv => + ⟨(Set.mem_empty_iff_false _).1, fun h => h (Or.inl ⟨hi, hb, Or.inr (hv ▸ e)⟩)⟩) + (fun hw => ⟨(Set.mem_empty_iff_false _).1, fun h => h (Or.inr ⟨hw, rfl⟩)⟩) + refine WP.spec_mono (WP.spec_and (J.signalVFK hAT hVA hK hmb hn badge) hF) ?_ + rintro ⟨s', a'⟩ ⟨⟨σ', Ac', Lst', D', h1, h2, J', R', BT⟩, F⟩ + refine ⟨σ', Ac', Lst', D', heq.trans h1, h2, J', hO.keep R' F.2.1 (fun t y' hk' hr' => ?_) (fun t y' hk' hr' hne => ?_)⟩ + · obtain ⟨u, hu, rfl⟩ := J'.1.1.obj.tcb t y' hk' + have huT : u ∈ P1.Heap.tcbs H := B.zH.1 u hu + obtain ⟨y0, hy0, hr0⟩ := R' _ y' hk' hr' + obtain ⟨x0, hk0, hw0⟩ := B.specTcb (B.thTcb hu) + rw [hy0] at hk0; cases hk0 + have h8 : (L.mem s (P1.stA u)).val = 8 := by rw [hw0, hr0]; rfl + show L.mem s' (P1.affA u) = L.mem s (P1.affA u) + by_cases hW : W0 u + · exfalso + rcases hW with ⟨hid, hbu, hrv | hcv⟩ | ⟨hw1, hhd⟩ + · rw [hrv] at h8; simp [sched.TS_BLOCKED_ON_RECV] at h8 + · have hidle : x.ntfnObj = .idleNtfn := by + have ho := hx.obj + rw [Notif.epState_eq] at hid + cases e : x.ntfnObj with + | idleNtfn => rfl + | activeNtfn b => + rw [e] at ho; exact absurd (hid.symm.trans ho.1) (by unfold obj.NTFN_IDLE; decide) + | waitingNtfn q => + rw [e] at ho; exact absurd (hid.symm.trans ho.1) (by unfold obj.NTFN_IDLE; decide) + have hu0 : u ≠ 0#u64 := fun e => (hT u huT).ne0 (by rw [e]; rfl) + have e2 : L.mem s (nBoundA n) = u := hbu + have hbnd : x.ntfnBoundTcb = some u.bv := by rw [hx.bound, e2]; simp [Notif.optRef, hu0] + have hf := BT x u hk hidle hbnd ⟨y', hk', hr'⟩ + rw [hcv] at hf; simp at hf + · obtain ⟨-, -, hds⟩ := P1.ntfn_head h0 hnH hw1 + rw [hhd] at hds; rw [hds] at h8; simp [sched.TS_BLOCKED_ON_NTFN] at h8 + · exact Fl4Proofs.P2.Stall.FFoot.affK h0 hX.1 F huT (Or.inr hW) + · obtain ⟨u, hu, rfl⟩ := J'.1.1.obj.tcb t y' hk' + exact Fl4Proofs.P2.Stall.FFoot.curK h0 hX.1 F (h0.aff u (B.zH.1 u hu)) hne + +/-- (gen 42b75, ruling 19:49Z item 1) **`hMsig` from `MachPlat` / `MRKeep`**: FL4's `send_signal` keeps `MR` at +the arch state (P3/MachKeep's `MRKeep`), the extended spec signal keeps the machine fields (`mfk_sendSignalVF`), so +`MR` holds after (XTopJointMRPath2's `msF_mr`), as XTopJointKEntryEv2's `JAtZB.handleIrqJBM` does for `sendSignal`. -/ +theorem msig_sendSignalVF {MR : A → Fl4Spec.MachineState → Prop} (hAT : P0.ArchTotal arI) (hM : MachPlat arI MR) + (hMK : MRKeep arI MR) (on rc : Fl4Spec.ObjRef → Bool) : + ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄ := + fun _ _ σ1 n b h1 => WP.spec_mono (MK.notification_send_signal L.total hAT hMK h1) fun _ hm2 σ' hmem => + msF_mr hM hm2 (mfk_sendSignalVF on rc n.bv b.bv σ1 _ hmem) + +set_option maxHeartbeats 4000000 in +/-- (gen 42b75, ruling 19:49Z item 1) **`handle_interrupt` at `VmEptState` against `handleInterruptVF`, `VmOrc` +kept** (module docstring): XTopJointIrqZR's `JAtZB.handleIrqJG` at `Q := VmEptState ∧ VmOrc`; the native arms write +nothing or the timer line's `REPROGRAM` / `ARMED` (`footN_tmArm`, `FootN.vmOrc`, the spec heap kept), the machine-state +arms keep the heap, the signal is `VmEptState.signalVFk`. -/ +theorem VmEptState.handleIrqVFk {MR : A → Fl4Spec.MachineState → Prop} (hARI : ARIface arI AR) + (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) (hR : MR a σ.machineState) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) + (hackAR : ∀ (a1 : A) (c : Fl4Spec.Cr3), AR a1 c → arI.ack_irq a1 w ⦃ a2 => AR a2 c ⦄) + (hMmask : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → arI.mask_irq a0 w true = ok a1 → + MR a1 (maskMs σ0 i true).machineState) + (hMack : ∀ (a1 : A) (ms : Fl4Spec.MachineState), MR a1 ms → arI.ack_irq a1 w ⦃ a2 => MR a2 ms ⦄) + (hMsig : ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄) : + interrupt.handle_interrupt st arI s a w ⦃ r => + (σ.interruptStates i = .irqInactive ∧ (Fl4Spec.handleInterruptVF (Z := Unit) on rc i σ).2) ∨ + ∃ z ∈ (Fl4Spec.handleInterruptVF (Z := Unit) on rc i σ).1, + ((∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 z.2) ∧ + VmOrc st on rc r.1 z.2) ∧ + MR r.2 z.2.machineState ⦄ := by + rw [handleInterruptVF_hiS] + have B := J.1.1 + obtain ⟨⟨Q0, R0, h0⟩, -⟩ := B.blk + exact B.handleIrqJG + (Q := fun s1 a1 σ1 => (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D' s1 a1 σ1) ∧ VmOrc st on rc s1 σ1) + hARI hAT hR + (fun ⟨V1, Ac1, Lst1, D1, B1, F1⟩ hw hk => ⟨⟨V1, Ac1, Lst1, D1, J.ofNat B1 F1⟩, + FootN.vmOrc h0 hO (footN_tmArm h0.nodes h0.cur hw) (fun t y' h hr => ⟨y', by rw [← hk]; exact h, hr⟩) + (fun t y' h => by + rw [hk] at h + obtain ⟨u, hu, rfl⟩ := B.obj.tcb t y' h + exact ⟨u, B.zH.1 u hu, rfl⟩)⟩) + (fun ms ⟨⟨V1, Ac1, Lst1, D1, J1⟩, O1⟩ hum hA => by + obtain ⟨Lst2, B2, F2⟩ := J1.1.1.msArJ ms _ hum (fun _ => hA) + exact ⟨⟨V1, Ac1, Lst2, D1, J1.ofNat (V' := V1) B2 F2⟩, O1⟩) + (fun ⟨⟨_, _, _, _, J1⟩, _⟩ => J1.1.1.xtop.fin.1.1.2.2.2.2.2.2) + (fun p b hp => WP.spec_mono (J.signalVFk hAT hVA hK hmb hp b hO) fun _ ⟨σ', Ac', Lst', D', h1, _, J', O'⟩ => + ⟨σ', h1, ⟨Z.vs, Ac', Lst', D', J'⟩, O'⟩) + w i hwi h126 h127 hackAR hMmask hMack hMsig + +set_option maxHeartbeats 4000000 in +/-- **`handle_interrupt` at `VmEptState` against `handleInterruptVF`** (module docstring): every branch ends at +`VmEptState` (fresh VSpace sets), a machine-state predicate `MR` carried as in `JAtZB.handleIrqJB`. (gen 42b75) +`VmEptState.handleIrqVFk`'s corollary, statement unchanged. -/ +theorem VmEptState.handleIrqVF {MR : A → Fl4Spec.MachineState → Prop} (hARI : ARIface arI AR) + (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) (hR : MR a σ.machineState) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) + (hackAR : ∀ (a1 : A) (c : Fl4Spec.Cr3), AR a1 c → arI.ack_irq a1 w ⦃ a2 => AR a2 c ⦄) + (hMmask : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → arI.mask_irq a0 w true = ok a1 → + MR a1 (maskMs σ0 i true).machineState) + (hMack : ∀ (a1 : A) (ms : Fl4Spec.MachineState), MR a1 ms → arI.ack_irq a1 w ⦃ a2 => MR a2 ms ⦄) + (hMsig : ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄) : + interrupt.handle_interrupt st arI s a w ⦃ r => + (σ.interruptStates i = .irqInactive ∧ (Fl4Spec.handleInterruptVF (Z := Unit) on rc i σ).2) ∨ + ∃ z ∈ (Fl4Spec.handleInterruptVF (Z := Unit) on rc i σ).1, + (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 z.2) ∧ + MR r.2 z.2.machineState ⦄ := + WP.spec_mono (J.handleIrqVFk hARI hAT hVA hK hmb hO hR w i hwi h126 h127 hackAR hMmask hMack hMsig) + fun _ h => h.imp id fun ⟨z, hz, ⟨hJ, _⟩, hm⟩ => ⟨z, hz, hJ, hm⟩ + +/-- (gen 42b73) **`VmOrc` across timer-word writes** (`TmW`: the TCBs' timer fields, every core's timer heads, this +core's `REPROGRAM`) with the spec heap kept: no `AFFINITY` word and no other core's `CUR_THREAD` is a timer word. -/ +theorem VmOrc.tmw (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {on rc : Fl4Spec.ObjRef → Bool} + (hO : VmOrc st on rc s σ) {s' : S} {σ' : Fl4Spec.State Unit} + (hw : P1.WritesIn st s s' (TmW (L := L) Z.T Cs Z.c s)) (hk : σ'.kheap = σ.kheap) : VmOrc st on rc s' σ' := by + obtain ⟨⟨Q, R, h0⟩, -⟩ := J.blk + refine hO.keep (fun t y' h hr => ⟨y', by rw [← hk]; exact h, hr⟩) hw.2.1 (fun t y' h hr => ?_) + (fun t y' h hr hne => ?_) + · rw [hk] at h + obtain ⟨u, hu, rfl⟩ := J.obj.tcb t y' h + have hta := h0.tcbs u (J.zH.1 u hu) + have hv : (P1.affA u).val = u.val + 3520 := by + rw [show P1.affA u = core.num.U64.wrapping_add u 3520#u64 from rfl, P1.field_val hta (by simp)]; simp + exact hw.mem_eq (P1.field_aligned hta (by simp) (by simp)) fun hb => J.tmw_ne_tcb hb hu hv (Or.inl (by omega)) rfl + · rw [hk] at h + obtain ⟨u, hu, rfl⟩ := J.obj.tcb t y' h + have hc : L.mem s (P1.affA u) ∈ Cs := h0.aff u (J.zH.1 u hu) + have hN : P1.NodePlaced st Z.T s (L.mem s (P1.affA u)) := by rw [J.tcbs_eq.1]; exact h0.nodes _ hc + have h0v : layout.node.CUR_THREAD.val = 0 := by simp [layout.node.CUR_THREAD] + show L.mem s' (L.nodeAt s' (L.mem s (P1.affA u)) layout.node.CUR_THREAD) = + L.mem s (L.nodeAt s (L.mem s (P1.affA u)) layout.node.CUR_THREAD) + rw [P1.nodeAt_of_ksb hw.1] + exact hw.mem_eq (P1.nodeAt_aligned hN (by omega) (by omega)) fun hb => + J.tmw_ne_node hb hc (by omega) (by omega) (by omega) (by omega) rfl + +/-- (gen 42b73) One fired timer of the extended spec is `FireG` at `sendSignalVF`. -/ +theorem fireG_sendSignalVF (on rc : Fl4Spec.ObjRef → Bool) : + FireG (Fl4Spec.sendSignalVF (Z := Unit) on rc) = Fl4Spec.fl4TimerFireVF (Z := Unit) on rc := rfl + +/-- (gen 42b73) The fire loop's record at `VmEptState` (fresh VSpace sets) with `VmOrc`. -/ +abbrev VmFireP (V X : Set U64) (XL : U64 → Nat) (Z : XSets) (H : P1.Heap) (Cs : Set U64) (on rc : Fl4Spec.ObjRef → Bool) + (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) : Prop := + ∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1 ∧ VmOrc st on rc s1 σ1 + +set_option maxHeartbeats 4000000 in +/-- (gen 42b73, ruling 17:14Z item 2) **FL4's TCB timers at `VmEptState` against the extended spec's +`fl4TimerFireVF`** (ScFireJ's `fire_loopG` at `P := VmFireP`, `sig := sendSignalVF on rc`): the timer-word and +`REPROGRAM` writes are native steps (`JAtZB.tmwN`, `JAtZB.reprogramN`) keeping `VmOrc` (`VmOrc.tmw`), each signal is +`VmEptState.signalVFk`. -/ +theorem VmEptState.fire_loopVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {on rc : Fl4Spec.ObjRef → Bool} + (s : S) (a : A) (now i : U64) + (h : FireInvG (VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc) (Fl4Spec.sendSignalVF (Z := Unit) on rc) σ s a) : + timer.fire_loop st arI s a now i ⦃ r => + FireInvG (VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc) (Fl4Spec.sendSignalVF (Z := Unit) on rc) σ r.1 r.2 ⦄ := + fire_loopG (Z := Z) (H := H) (Cs := Cs) (AR := AR) + (fun ⟨V1, Ac1, Lst1, D1, J1, _⟩ => ⟨V1, Ac1, Lst1, D1, J1.1.1⟩) + (@fun _ _ _ _ V1 Ac1 Lst1 D1 ⟨_, _, _, _, J0, O0⟩ B2 hw => + ⟨V1, Ac1, Lst1, D1, J0.ofNat (V' := V1) B2 (J0.1.1.tmwN hw), VmOrc.tmw J0.1.1 O0 hw rfl⟩) + (fun ⟨V1, Ac1, Lst1, D1, J1, O1⟩ => ⟨V1, Ac1, Lst1, D1, + J1.ofNat (V' := V1) J1.1.1.reprogramJ J1.1.1.reprogramN, VmOrc.tmw J1.1.1 O1 J1.1.1.reprogram_w rfl⟩) + (fun n b ⟨V1, _, _, _, J1, O1⟩ hn => WP.spec_mono (J1.signalVFk hAT hVA hK hmb hn b O1) + fun _ ⟨σ', Ac', Lst', D', h1, h2, J', O'⟩ => ⟨σ', h1, h2, V1, Ac', Lst', D', J', O'⟩) + s a now i h + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmPerfCur.lean b/proofs/Fl4Proofs/P3/VmPerfCur.lean new file mode 100644 index 000000000..54ceb9633 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmPerfCur.lean @@ -0,0 +1,185 @@ +/- +P3 (line mmuAD, gen 42b68, option (b) step b4, the ruling's item 2): **the extended dispatcher keeps the current +thread** (`perfCurKeepVF`, spec only): every outcome of Ext/VirtKernelF's `fl4PerformInvocationVF onCore remoteCur` +has its start state's `curThread` — HandleTopG's `handle_invocation_refinesMXPG`'s `hPK` at the extended dispatcher +(SpecPerfCur's `perfCurKeep` is the native one). + +Each VF arm keeps VsDom's `schedF` (`DK` / `DKE`, the domain schedule and `curThread`), one lemma per spec function by +`dk_auto` (the spec writes `curThread` only in `switchToThread` / `switchToIdleThread`, reached from `schedule` alone): +* the VCPU leaves: `dk_getVcpuV`, `dk_vcpuDetachF` (P3/VmDelFinSpec's `dk_vmReportF`, `dk_vcpuUpdateV`), + `dk_guestUnmapV` / `dk_ioPortRevokeV` (P3/VmDelFinSpec's `fk_guestUnmap` / `fk_ioPortRevoke` at `dk_setObject`), + **`dk_finaliseCapVF`** (`relk_finaliseCapVF`); +* the deletion loops over a spec finaliser / deletion (P3/DelSpec's `recDelFG`, P3/CnodeRevoke's `capRevokeFG`): + **`dk_recDelG`**, `dk_capDeleteG`, **`dk_capRevokeG`** (P3/DomRecDel's `dk_recDel` / `dk_capRevoke` pattern: a + pre-fixed point of the loop's equation, `lfp_le_prefixed`), at `finaliseCapVF` / `capDeleteVF`: `dk_capDeleteVF`, + `dk_capRevokeVF` (P3/DelVF's `capDeleteG_vf` / `capRevokeG_vf`, `rfl`); +* the arms: `dke_invokeCnodeVF`, `dke_invokeTcbVF` (`installTcbCapVF`, `installTcbFrameCapVF`), `dk_sendSignalVF`, + `dke_fl4InvokeUntypedV`, `dk_performVcpuInvocationF`, `dk_performEptInvocation`, `dke_invokeSetEptRootF`; +* **`perfCurKeepVF`**: every `fl4PerformInvocationVF` outcome keeps `curThread` (the `.base` arms the extended + dispatcher does not override are `perfCurKeep`'s). + +No named premise. No existing statement changed. New file (spec only). +-/ +import Fl4Proofs.P3.SpecPerfCur +import Fl4Proofs.P3.VmDelFinSpec +import Fl4Proofs.P3.DelVF +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3.Vs +open Fl4Spec Classical + +noncomputable section + +/-! ## The VCPU leaves and `finaliseCapVF` -/ + +theorem dk_getVcpuV (v : ObjRef) : DK (getVcpu (Z := Unit) v) := fk_of_keepSt (keepSt_getVcpu v) +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_getVcpuV _) +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_vcpuUpdateV _ _) +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_vmReportF _ _) + +theorem dk_vcpuDetachF (t : ObjRef) : DK (vcpuDetachF (Z := Unit) t) := by + unfold vcpuDetachF getTcbVcpu; dk_auto +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_vcpuDetachF _) + +theorem dk_guestUnmapV (asid : Asid) (gpa : Word) (ptr : ObjRef) (level : Nat) (table : Bool) : + DK (guestUnmap (Z := Unit) asid gpa ptr level table) := + fk_guestUnmap (fun p _ => dk_setObject p _) asid gpa ptr level table +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_guestUnmapV _ _ _ _ _) + +theorem dk_ioPortRevokeV (c : ArchCap) : DK (ioPortRevoke (Z := Unit) c) := + fk_ioPortRevoke (fun p _ => dk_setObject p _) c +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_ioPortRevokeV _) + +theorem dk_getEptV (p : ObjRef) : DK (getEpt (Z := Unit) p) := fk_of_keepSt (keepSt_getEpt p) +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_getEptV _) + +/-- **`finaliseCapVF` keeps the domain schedule and the current thread** (`relk_finaliseCapVF`). -/ +theorem dk_finaliseCapVF (c : Cap) (b : Bool) : DK (finaliseCapVF (Z := Unit) c b) := + relk_finaliseCapVF (R := fun σ σ' => schedF σ' = schedF σ) (fun _ => rfl) (fun _ _ _ h1 h2 => h2.trans h1) + dk_finaliseCap dk_vcpuDetachF dk_getVcpuV dk_guestUnmapV (fun c => dk_ioPortRevokeV c) c b + +/-! ## The deletion loops over a finaliser -/ + +/-- One step of `recDelFG Fn` keeps the schedule, `Fn` and the recursive calls keeping it. -/ +theorem dk_recDelFG {Fn : FinFn} (hFn : ∀ c b, DK (Fn c b)) + {f : RecDelCall → NonDet (State Unit) (Except Unit (Bool × Cap))} + (hrec : ∀ k, DK (f k)) (k : RecDelCall) : DKE (recDelFG Fn f k) := by + have hrec' : ∀ k, DKE (ε := Unit) (f k : NonDetE (State Unit) Unit (Bool × Cap)) := hrec + cases k with + | cTEDeleteCall sl e => unfold recDelFG withoutPreemption; dk_auto; all_goals exact hrec' _ + | finaliseSlotCall sl e => + unfold recDelFG withoutPreemption; dk_auto; all_goals first | apply hFn | apply hrec' + | reduceZombieCall c sl e => + unfold recDelFG withoutPreemption + split <;> dk_auto + all_goals first | apply hFn | apply hrec' + +/-- **`recDelG Fn` keeps the domain schedule** when `Fn` does. -/ +theorem dk_recDelG {Fn : FinFn} (hFn : ∀ c b, DK (Fn c b)) (c : RecDelCall) : DKE (recDelG Fn c) := by + intro σ x hx + let f : RecDelCall → NonDet (State Unit) (Except Unit (Bool × Cap)) := fun _ t => + ({y | schedF y.2 = schedF t}, True) + have hf : ∀ k t, RDFG Fn f k t ≤ f k t := fun k t => + ⟨fun y hy => dk_recDelFG hFn (f := f) (fun _ _ _ hz => hz) k t y hy, fun _ => trivial⟩ + exact (lfp_le_prefixed (RDFG Fn) f hf c σ).1 hx + +theorem dk_capDeleteG {Fn : FinFn} (hFn : ∀ c b, DK (Fn c b)) (sl : CslotPtr) : DKE (capDeleteG Fn sl) := by + unfold capDeleteG; exact dke_bind (dk_recDelG hFn _) fun _ => dke_returnOk _ + +/-- One step of `capRevokeFG Dl` keeps the schedule, `Dl` and the recursive calls keeping it. -/ +theorem dk_capRevokeFG {Dl : CslotPtr → PMonad Unit Unit} (hDl : ∀ sl, DKE (Dl sl)) + {f : CslotPtr → NonDet (State Unit) (Except Unit Unit)} (hrec : ∀ k, DK (f k)) (sl : CslotPtr) : + DKE (capRevokeFG Dl f sl) := by + have hrec' : ∀ k, DKE (ε := Unit) (f k : NonDetE (State Unit) Unit Unit) := hrec + unfold capRevokeFG withoutPreemption selectExt + dk_auto + all_goals first | apply hDl | apply hrec' + +/-- **`capRevokeG Dl` keeps the domain schedule** when `Dl` does. -/ +theorem dk_capRevokeG {Dl : CslotPtr → PMonad Unit Unit} (hDl : ∀ sl, DKE (Dl sl)) (sl : CslotPtr) : + DKE (capRevokeG Dl sl) := by + intro σ x hx + let f : CslotPtr → NonDet (State Unit) (Except Unit Unit) := fun _ t => ({y | schedF y.2 = schedF t}, True) + have hf : ∀ k t, (fun r c => capRevokeFG Dl r c) f k t ≤ f k t := fun k t => + ⟨fun y hy => dk_capRevokeFG hDl (f := f) (fun _ _ _ hz => hz) k t y hy, fun _ => trivial⟩ + exact (lfp_le_prefixed _ f hf sl σ).1 hx + +theorem dk_capDeleteVF (sl : CslotPtr) : DKE (capDeleteVF (Z := Unit) sl) := dk_capDeleteG dk_finaliseCapVF sl +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_capDeleteVF _) + +theorem dk_capRevokeVF (sl : CslotPtr) : DKE (capRevokeVF (Z := Unit) sl) := dk_capRevokeG dk_capDeleteVF sl +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_capRevokeVF _) + +/-! ## The arms of the extended dispatcher -/ + +theorem dke_invokeCnodeVF (i : CnodeInvocation) : DKE (invokeCnodeVF (Z := Unit) i) := by + cases i <;> first | exact dk_capRevokeVF _ | exact dk_capDeleteVF _ | exact dke_invokeCnode _ + +theorem dke_installTcbCapVF (t : ObjRef) (sl : CslotPtr) (n : Nat) (o : Option (Cap × CslotPtr)) : + DKE (installTcbCapVF (Z := Unit) t sl n o) := by + unfold installTcbCapVF; dk_auto +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dke_installTcbCapVF _ _ _ _) + +theorem dke_installTcbFrameCapVF (t : ObjRef) (sl : CslotPtr) (b : Option (VSpaceRef × Option (Cap × CslotPtr))) : + DKE (installTcbFrameCapVF (Z := Unit) t sl b) := by + unfold installTcbFrameCapVF; dk_auto +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dke_installTcbFrameCapVF _ _ _) + +theorem dke_invokeTcbVF (i : TcbInvocation) : DKE (invokeTcbVF (Z := Unit) i) := by + cases i <;> unfold invokeTcbVF <;> dk_auto + +theorem dk_sendSignalVF (onCore remoteCur : ObjRef → Bool) (n : ObjRef) (b : Badge) : + DK (sendSignalVF (Z := Unit) onCore remoteCur n b) := by + unfold sendSignalVF vmSignalCompletes getTcbVcpu vmFullReply; dk_auto +macro_rules | `(tactic| dk_leaf) => `(tactic| with_reducible exact dk_sendSignalVF _ _ _ _) + +theorem dke_fl4InvokeUntypedV (ui : UntypedInvocation) : DKE (fl4InvokeUntypedV (Z := Unit) ui) := by + unfold fl4InvokeUntypedV setVcpu; dk_auto + +theorem dk_performVcpuInvocationF (i : VcpuInvocation) : DK (performVcpuInvocationF (Z := Unit) i) := by + cases i <;> unfold performVcpuInvocationF <;> (try unfold associateVcpuTcbF) <;> (try unfold ioPortSetOwner) <;> + dk_auto + +theorem dk_performEptInvocation (i : EptInvocation) : DK (performEptInvocation (Z := Unit) i) := by + cases i <;> unfold performEptInvocation <;> (try unfold storeGuestEntry) <;> dk_auto + +theorem dke_invokeSetEptRootF (i : SetEptRootInvocation) : DKE (invokeSetEptRootF (Z := Unit) i) := by + unfold invokeSetEptRootF; dk_auto + +/-- `DKE` keeps the current thread (`FKE` form). -/ +theorem DKE.ctK {ε α : Type} {m : NonDetE (State Unit) ε α} (h : DKE m) : + FKE (fun σ : State Unit => σ.curThread) m := + fun σ x hx => congrArg (fun p => p.2.2) (h σ x hx) + +end + +end Fl4Proofs.P3.Vs + +namespace Fl4Proofs.P3 +open Fl4Spec Fl4Proofs.P3.Vs + +/-- **The extended dispatcher keeps the current thread** (module docstring): `PerfCurKeep` for +`fl4PerformInvocationVF onCore remoteCur`. -/ +theorem perfCurKeepVF (onCore remoteCur : ObjRef → Bool) (blk call don : Bool) (inv : Fl4InvocationV) + (σ1 : State Unit) (y : Except Unit (List Data) × State Unit) + (hy : y ∈ ((fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv).run σ1).1) : + y.2.curThread = σ1.curThread := by + have h : FKE (fun σ : State Unit => σ.curThread) + (fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv) := by + cases inv with + | base b => + cases b + case invokeUntyped i => + exact DKE.ctK (dke_bind (dke_fl4InvokeUntypedV i) fun _ => dke_returnOk _) + case invokeNotification n b => + exact DKE.ctK (dke_bind (dke_withoutPreemption' (dk_sendSignalVF onCore remoteCur n b)) fun _ => + dke_returnOk _) + case invokeTCB i => exact DKE.ctK (dke_invokeTcbVF i) + case invokeCNode i => exact DKE.ctK (dke_bind (dke_invokeCnodeVF i) fun _ => dke_returnOk _) + all_goals exact fun σ x hx => perfCurKeep blk call don _ σ x hx + | vcpu i => exact DKE.ctK (dke_liftE (dk_performVcpuInvocationF i)) + | ept i => exact DKE.ctK (dke_liftE (dk_bind (dk_performEptInvocation i) fun _ => dk_pure _)) + | setEptRoot i => exact DKE.ctK (dke_bind (dke_invokeSetEptRootF i) fun _ => dke_returnOk _) + exact h σ1 y hy + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmPerfRvm.lean b/proofs/Fl4Proofs/P3/VmPerfRvm.lean new file mode 100644 index 000000000..f0f5ac06c --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmPerfRvm.lean @@ -0,0 +1,220 @@ +/- +P3 (line mmuAD, gen 42b79, the Architect's ruling item 2, route (B)): **no thread becomes `runningVM` in the extended +dispatcher** (spec only): every outcome of Ext/VirtKernelF's `fl4PerformInvocationVF onCore remoteCur` is +P3/VmSignal's `RvmSub`-related to its start, so an invocation (preempted or not) leaves its current thread +`runningVM` only if it was at the entry (P3/VmPreempt's `VmEptPre.preemptPathVFk` asks `¬ RunningVM`). + +* The frame family is SpecInvAllO1..O6 (generalised in place over the excluded state, gen 42b79) at + `N := ⟨.runningVM, E, _⟩`: `OIS N σ` says every `runningVM` TCB is one of `E` (the spec writes `runningVM` only in + `vmEnterF`, which is no invocation). +* The VCPU / EPT leaves of the extended ops at any `N`: `oi_getVcpuV`, `oi_vcpuUpdateV`, `oi_vmReportF` (the report + writes `Running`), `oi_vcpuDetachF`, `oi_guestUnmapV`, `oi_ioPortRevokeV`, **`oi_finaliseCapVF`** (P3/VmDelFinSpec's + `relk_finaliseCapVF` at `OIS N σ → OIS N σ'`); +* the deletion loops over a finaliser (P3/DelSpec's `recDelFG`, P3/CnodeRevoke's `capRevokeFG`, by `ik_lfp`): + `oi_recDelG`, `oi_capDeleteG`, `oi_capRevokeG`, at `finaliseCapVF`: `oi_capDeleteVF`, `oi_capRevokeVF`; +* the arms: `oi_invokeCnodeVF`, `oi_invokeTcbVF`, `oi_sendSignalVF`, `oi_fl4InvokeUntypedV`, + `oi_performVcpuInvocationF`, `oi_performEptInvocation`, `oi_invokeSetEptRootF`, **`oi_fl4PerformInvocationVF`** + (the `.base` arms the extended dispatcher does not override are SpecInvAllO6's `oi_fl4PerformInvocation`). +* **`perfRvmVF`**: `RvmSub σ1 y.2` for every outcome `y` from `σ1` (`E` := the `runningVM` TCBs of `σ1`); + `RunningVM σ` (the current thread is `runningVM`); **`perfCtNVmVF`**: an outcome's current thread is not + `runningVM` when the start's is not (with P3/VmPerfCur's `perfCurKeepVF`). + +No named premise. New file (spec only). +-/ +import Fl4Proofs.P3.SpecInvAllO6 +import Fl4Proofs.P3.VmPerfCur +import Fl4Proofs.P3.VmSignal +open Classical + +namespace Fl4Proofs.P3.SInvAll +open Fl4Spec Fl4Proofs.P3.SInv Fl4Proofs.P3.Vs + +noncomputable section + +set_option maxHeartbeats 1000000 + +variable {N : OIx} + +open Lean in +/-- SpecInvAllO1's `oi_auto` (`oi_auto` / `oi_leaf` also name SpecInvFoG1's, imported here, so the leaves below give +the node kind). -/ +macro "orv_auto" : tactic => pure ⟨(mkNode ``Fl4Proofs.P3.SInvAll.tacticOi_auto #[mkAtom "oi_auto"]).raw⟩ + +/-! ## The VCPU and EPT leaves -/ + +theorem oi_getVcpuV (v : ObjRef) : OIK N (getVcpu (Z := Unit) v) := ik_of_keepSt (keepSt_getVcpu v) _ +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_getVcpuV _) + +theorem oi_vcpuUpdateV (v : ObjRef) (g : VcpuState → VcpuState) : OIK N (vcpuUpdate (Z := Unit) v g) := by + unfold vcpuUpdate setVcpu; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_vcpuUpdateV _ _) + +/-- The report writes `Running` (and registers, message words, the VCPU). -/ +theorem oi_vmReportF (t : ObjRef) (badge : Word) : OIK N (vmReportF (Z := Unit) t badge) := by + unfold vmReportF getTcbVcpu vmFullReply vmFaultIpNext; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_vmReportF _ _) + +theorem oi_vcpuDetachF (t : ObjRef) : OIK N (vcpuDetachF (Z := Unit) t) := by + unfold vcpuDetachF getTcbVcpu; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_vcpuDetachF _) + +theorem oi_guestUnmapV (asid : Asid) (gpa : Word) (ptr : ObjRef) (level : Nat) (table : Bool) : + OIK N (guestUnmap (Z := Unit) asid gpa ptr level table) := by + unfold guestUnmap + refine ik_bind (ik_of_keepSt (keepSt_findGuestRoot _) _) fun r => ?_ + rcases r with _ | root + · exact ik_pure _ + refine ik_bind (ik_of_keepSt (keepSt_guestLookupSlot _ _ _) _) fun t => ?_ + rcases t with _ | tbl + · exact ik_pure _ + refine ik_bind (ik_of_keepSt (keepSt_getEpt _) _) fun e => ?_ + obtain ⟨_, es⟩ := e + dsimp only + apply ik_unless + unfold storeGuestEntry + exact ik_bind (ik_of_keepSt (keepSt_getEpt _) _) fun _ => tp_setObject _ _ fun _ ht => by cases ht +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_guestUnmapV _ _ _ _ _) + +theorem oi_ioPortRevokeV (c : ArchCap) : OIK N (ioPortRevoke (Z := Unit) c) := by + unfold ioPortRevoke; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_ioPortRevokeV _) + +/-- An `OIK` step is `RelK`-related at `OIS N σ → OIS N σ'`. -/ +theorem relk_of_oi {α : Type} {m : NonDet (State Unit) α} (h : OIK N m) : + RelK (fun σ σ' => OIS N σ → OIS N σ') m := fun σ x hx hP => h σ hP x hx + +/-- **`finaliseCapVF`** (P3/VmDelFinSpec's `relk_finaliseCapVF`). -/ +theorem oi_finaliseCapVF (c : Cap) (b : Bool) : OIK N (finaliseCapVF (Z := Unit) c b) := fun σ hP x hx => + relk_finaliseCapVF (R := fun σ σ' => OIS N σ → OIS N σ') (fun _ h => h) (fun _ _ _ h1 h2 h => h2 (h1 h)) + (fun c b => relk_of_oi (oi_finaliseCap c b)) (fun t => relk_of_oi (oi_vcpuDetachF t)) + (fun v => relk_of_oi (oi_getVcpuV v)) (fun a g p l t => relk_of_oi (oi_guestUnmapV a g p l t)) + (fun c => relk_of_oi (oi_ioPortRevokeV c)) c b σ x hx hP +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_finaliseCapVF _ _) + +/-! ## The deletion loops over a finaliser -/ + +/-- One step of `recDelFG Fn`, `Fn` and the recursive calls `OIK`. -/ +theorem oi_recDelFG {Fn : FinFn} (hFn : ∀ c b, OIK N (Fn c b)) + {f : RecDelCall → NonDet (State Unit) (Except Unit (Bool × Cap))} + (hrec : ∀ k, OIK N (f k)) (k : RecDelCall) : OIKE N (recDelFG Fn f k) := by + have hrec' : ∀ k, OIKE N (ε := Unit) (f k : NonDetE (State Unit) Unit (Bool × Cap)) := hrec + cases k with + | cTEDeleteCall sl e => unfold recDelFG withoutPreemption; orv_auto; all_goals exact hrec' _ + | finaliseSlotCall sl e => + unfold recDelFG withoutPreemption; orv_auto; all_goals first | apply hFn | apply hrec' + | reduceZombieCall c sl e => + unfold recDelFG withoutPreemption + split <;> orv_auto + all_goals first | apply hFn | apply hrec' + +theorem oi_recDelG {Fn : FinFn} (hFn : ∀ c b, OIK N (Fn c b)) (c : RecDelCall) : OIKE N (recDelG Fn c) := by + unfold recDelG + exact ik_lfp (fun f hf k => oi_recDelFG hFn hf k) c + +theorem oi_capDeleteG {Fn : FinFn} (hFn : ∀ c b, OIK N (Fn c b)) (sl : CslotPtr) : OIKE N (capDeleteG Fn sl) := by + unfold capDeleteG; exact ike_bind (oi_recDelG hFn _) fun _ => ike_returnOk _ + +/-- One step of `capRevokeFG Dl`, `Dl` and the recursive calls `OIK`. -/ +theorem oi_capRevokeFG {Dl : CslotPtr → PMonad Unit Unit} (hDl : ∀ sl, OIKE N (Dl sl)) + {f : CslotPtr → NonDet (State Unit) (Except Unit Unit)} (hrec : ∀ k, OIK N (f k)) (sl : CslotPtr) : + OIKE N (capRevokeFG Dl f sl) := by + have hrec' : ∀ k, OIKE N (ε := Unit) (f k : NonDetE (State Unit) Unit Unit) := hrec + unfold capRevokeFG withoutPreemption selectExt + orv_auto + all_goals first | apply hDl | apply hrec' + +theorem oi_capRevokeG {Dl : CslotPtr → PMonad Unit Unit} (hDl : ∀ sl, OIKE N (Dl sl)) (sl : CslotPtr) : + OIKE N (capRevokeG Dl sl) := by + unfold capRevokeG + exact ik_lfp (fun f hf k => oi_capRevokeFG hDl hf k) sl + +theorem oi_capDeleteVF (sl : CslotPtr) : OIKE N (capDeleteVF (Z := Unit) sl) := oi_capDeleteG oi_finaliseCapVF sl +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_capDeleteVF _) + +theorem oi_capRevokeVF (sl : CslotPtr) : OIKE N (capRevokeVF (Z := Unit) sl) := oi_capRevokeG oi_capDeleteVF sl +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_capRevokeVF _) + +/-! ## The arms of the extended dispatcher -/ + +theorem oi_invokeCnodeVF (i : CnodeInvocation) : OIKE N (invokeCnodeVF (Z := Unit) i) := by + cases i <;> first | exact oi_capRevokeVF _ | exact oi_capDeleteVF _ | exact oi_invokeCnode _ + +theorem oi_installTcbCapVF (t : ObjRef) (sl : CslotPtr) (n : Nat) (o : Option (Cap × CslotPtr)) : + OIKE N (installTcbCapVF (Z := Unit) t sl n o) := by + unfold installTcbCapVF; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_installTcbCapVF _ _ _ _) + +theorem oi_installTcbFrameCapVF (t : ObjRef) (sl : CslotPtr) (b : Option (VSpaceRef × Option (Cap × CslotPtr))) : + OIKE N (installTcbFrameCapVF (Z := Unit) t sl b) := by + unfold installTcbFrameCapVF; orv_auto +macro_rules (kind := Fl4Proofs.P3.SInvAll.tacticOi_leaf) | `(tactic| oi_leaf) => `(tactic| with_reducible exact oi_installTcbFrameCapVF _ _ _) + +theorem oi_invokeTcbVF (i : TcbInvocation) : OIKE N (invokeTcbVF (Z := Unit) i) := by + cases i <;> unfold invokeTcbVF <;> orv_auto + +theorem oi_sendSignalVF (onCore remoteCur : ObjRef → Bool) (n : ObjRef) (b : Badge) : + OIK N (sendSignalVF (Z := Unit) onCore remoteCur n b) := by + unfold sendSignalVF vmSignalCompletes getTcbVcpu vmFullReply; orv_auto + +theorem oi_fl4InvokeUntypedV (ui : UntypedInvocation) : OIKE N (fl4InvokeUntypedV (Z := Unit) ui) := by + unfold fl4InvokeUntypedV setVcpu; orv_auto + +theorem oi_performVcpuInvocationF (i : VcpuInvocation) : OIK N (performVcpuInvocationF (Z := Unit) i) := by + cases i <;> unfold performVcpuInvocationF <;> (try unfold associateVcpuTcbF) <;> (try unfold ioPortSetOwner) <;> + orv_auto + +theorem oi_performEptInvocation (i : EptInvocation) : OIK N (performEptInvocation (Z := Unit) i) := by + cases i <;> unfold performEptInvocation <;> (try unfold storeGuestEntry) <;> orv_auto + +theorem oi_invokeSetEptRootF (i : SetEptRootInvocation) : OIKE N (invokeSetEptRootF (Z := Unit) i) := by + unfold invokeSetEptRootF; orv_auto + +/-- **The extended dispatcher** at any `N` (module docstring). -/ +theorem oi_fl4PerformInvocationVF (onCore remoteCur : ObjRef → Bool) (blk call don : Bool) (inv : Fl4InvocationV) : + OIKE N (fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv) := by + cases inv with + | base b => + cases b + case invokeUntyped i => exact ike_bind (oi_fl4InvokeUntypedV i) fun _ => ike_returnOk _ + case invokeNotification n b => + exact ike_bind (ike_liftE (oi_sendSignalVF onCore remoteCur n b)) fun _ => ike_returnOk _ + case invokeTCB i => exact oi_invokeTcbVF i + case invokeCNode i => exact ike_bind (oi_invokeCnodeVF i) fun _ => ike_returnOk _ + all_goals exact oi_fl4PerformInvocation _ _ _ _ + | vcpu i => exact ike_liftE (oi_performVcpuInvocationF i) + | ept i => exact ike_liftE (ik_bind (oi_performEptInvocation i) fun _ => ik_pure _) + | setEptRoot i => exact ike_bind (oi_invokeSetEptRootF i) fun _ => ike_returnOk _ + +end + +end Fl4Proofs.P3.SInvAll + +namespace Fl4Proofs.P3 +open Fl4Spec + +/-- (gen 42b79) **The current thread is `runningVM`.** -/ +def RunningVM (σ : State Unit) : Prop := + ∃ xt, σ.kheap σ.curThread = some (.tcb xt) ∧ xt.tcbState = .runningVM + +/-- **No thread becomes `runningVM` in the extended dispatcher** (module docstring): every outcome of +`fl4PerformInvocationVF onCore remoteCur` is `RvmSub`-related to its start. -/ +theorem perfRvmVF (onCore remoteCur : ObjRef → Bool) (blk call don : Bool) (inv : Fl4InvocationV) + (σ1 : State Unit) (y : Except Unit (List Data) × State Unit) + (hy : y ∈ ((fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv).run σ1).1) : + RvmSub σ1 y.2 := + SInvAll.oi_fl4PerformInvocationVF + (N := ⟨.runningVM, fun o => ∃ x, σ1.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM, Or.inr rfl⟩) + onCore remoteCur blk call don inv σ1 (fun _ x hp hs => ⟨x, hp, hs⟩) y hy + +/-- **The current thread of an outcome of the extended dispatcher is not `runningVM` when the start's is not** +(`perfCurKeepVF`, `perfRvmVF`); in particular at a preempted outcome (P3/VmPreempt's `VmEptPre.preemptPathVFk`). -/ +theorem perfCtNVmVF (onCore remoteCur : ObjRef → Bool) (blk call don : Bool) (inv : Fl4InvocationV) + (σ1 : State Unit) (y : Except Unit (List Data) × State Unit) + (hy : y ∈ ((fl4PerformInvocationVF (Z := Unit) onCore remoteCur blk call don inv).run σ1).1) + (h : ¬ RunningVM σ1) : ¬ RunningVM y.2 := by + rintro ⟨xt, hk, hr⟩ + rw [perfCurKeepVF onCore remoteCur _ _ _ inv σ1 y hy] at hk + obtain ⟨x, hx, hrx⟩ := perfRvmVF onCore remoteCur _ _ _ inv σ1 y hy _ xt hk hr + exact h ⟨x, hx, hrx⟩ + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmPreempt.lean b/proofs/Fl4Proofs/P3/VmPreempt.lean new file mode 100644 index 000000000..47b128312 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmPreempt.lean @@ -0,0 +1,911 @@ +/- +P3 (line mmuAD, gen 42b74, the Architect's ruling 18:47Z, (c3) part 3): **the MCS preemption point keeps `VmOrc`, the +preemption path at `VmEptState`, and the TCB timers against `fl4AwakenVF`**. + +* **`handle_timeout_blkN`**: a timeout fault whose handler cap names an endpoint idle or sending after the fault words + are written (`set_fault_timeout_eq`) blocks the thread: P1's `BXI` after and a `FootN Kp Nd` step (P1's + `send_ipc.block`, P2/FootN4's `send_ipc.blockFootN`; no transfer, so none of P2's transfer premises). +* **`JHole.mcsFootN`** (the ruling's `AffK` of the preemption point, items 1(a) and 1(b)): at a hole under + `PPCov ∨ PPCovT`, FL4's `mcs_preemption_point` is a `FootN ∅ True` step from the hole (P3JPreSt's + `syscall.mcs_preemption_point.tmoN`), so it keeps every TCB's `AFFINITY`, the core and every other core's + `CUR_THREAD`. `TmoKCv` is vacuous under `PPCov` (no endpoint timeout handler: `valid_timeout_handler` is the + hole's, `valid_timeout_handler_rel`; or a round-robin SC: the period word is the hole's, `ScRel1.period`), and + under `PPCovT` it is `handle_timeout_blkN` at the state `ChgW` writes reach: the handler slot and the endpoint's + state word are no SC word, no node word and no fault word of the thread (P1's `HeapOK.disj`, `JKern.hnd`, + `EPlaced.et`). +* **`FootN.vmOrc`**: a `FootN ∅ True` step with the spec heap moving under `RvmSub` keeps `VmOrc` (`VmOrc.keep`; + moved to P3/VmOracle in gen 42b75). +* `preemptionPathVF_ppG` (spec, `rfl`): the extended path is XTopJointPreempt's `ppG` at `maybeHandleInterruptVF`; + `mem_maybeHandleVF_none` / `mem_maybeHandleVF_some`. +* **`VmEptPre.preemptPathVF`** (item 2): from P3/RetVmReset's `VmEptPre` (the preempted state at `VmEptState`) under + `PPCov ∨ PPCovT`, with `VmOrc` at the preempted state, FL4's `after_invocation (Err _)` ends at an outcome of + `preemptionPathVF on rc` with `VmEptState` (fresh VSpace sets) and `MR`: the hole by XTopJointMRPP's + `JAtZB.ppJHM`, the MCS part by XTopJointMRPath2's `JHole.mcsPPJZMG` at the tail `maybeHandleInterruptVF` with + `JHole.mcsFootN` beside it (`VmOrc` after, `FootN.vmOrc`), `VmEptState.ofNat` along the composed native + footprint, the IRQ take (`MachPlat.takeAt`) and P3/VmOracle's `VmEptState.handleIrqVF` (an inactive line excluded + by `ValidIrqMasks`, `gai_active`). +* **`VmEptState.fireVF`** (item 3): FL4's `timer.fire` from `VmEptState` with `VmOrc` against `fl4AwakenVF on rc` + (P3/VmOracle's `VmEptState.fire_loopVF`). + +(gen 42b75, ruling 19:49Z items 1–2: every preemption hole but `PPRest`, zero new premises) +* `TmoBlk` (the current thread's endpoint timeout handler names an idle or sending endpoint) and **`PPRest`** (the holes + left: `CurInv`, schedulable, insufficient budget, a raisable timeout fault (`¬ NoTmoSend`) to a receiving endpoint + (`¬ TmoBlk`) or from a `runningVM` current thread — 42b76). +* `JHole.sched_of_F` (FL4's `is_schedulable` facts give the spec's `schedulable`, `schedulable_eq`); + **`JHole.mcsFootNG`**: the preemption point from any hole is a `FootN ∅ True` step under `CtOK`-style SC linkage, no + switch to the current thread and, where it is schedulable, `NoTmoSend` or `TmoBlk` (P3JPreSt's `tmoN`, whose + `htmo` is now asked only in the schedulable arm); `JHole.mcsFootN` its corollary. +* **`JHole.mcsPPVF`**: the MCS part from every hole outside `PPRest` (the cases of XTopJointMRHole's `hPre_ofZQIMN`, + each by its `ppG` form `mcsPPJZMG` / `mcsPPJIMG` / `mcsPPJSMG` / `mcsPPJAMG` / `mcsPPJCMG` / `mcsPPJUMG`) with its + footprint. **`VmEptPre.preemptPathVFk`**: the preemption path at `VmEptState` from every hole outside `PPRest`, + `VmOrc` after, no `hMsig` (P3/VmOracle's `handleIrqVFk`, `msig_sendSignalVF`); `VmEptPre.preemptPathVF` its + corollary (statement unchanged). + +(gen 42b78, ruling 23:24Z item 1: the receiving-endpoint holes, zero new premises) +* **`handle_timeout_ipcN`**: a timeout fault on any endpoint is P1's `BlkOK` after and an `IpcFootN ∅ True` step at + any word set `Ω` and user words `U` with `UserOK` / `BufAt` (P1's `send_ipc.ipcT` beside P2/FootN5's + `send_ipc.footPNT`, the transfer from the faulting thread by `xferOKAt_fault`, its guard after the dequeue from the + dequeue's TCB-word frame and the fault word written by `set_fault`). +* `OmegaB H Z σ` (the hole's word set without the IPC-buffer words `BufU`). **`JHole.mcsTmoG`**: `mcsFootNG`'s + prefix over any property `G` kept by `FootN ∅ True` steps (P3JPreSt's `tmoNG`), the endpoint handler read off the + hole; `JHole.mcsFootNG` (statement unchanged) and **`JHole.mcsIpcN`** (no `TmoBlk`: the fault at `OmegaB` with + `U := BufU Z σ0`, `BufAt` from the base's `JAtZB.bufAtJ` along `KFoot` and `ChgW` (`KFoot.ne_tcbw`), `BXI.reΩ` there + and back as `JAtZ.bxiU`) are its instances. +* `PPRest` narrowed to the `runningVM` case; **`PPRecv`** the receiving-endpoint holes. `JHole.mcsPPVF` takes them + by XTopJointMRPath4's `mcsPPJRMG` beside `mcsIpcN`, its footprint now `IpcFootN ∅ True` at `OmegaB` / `BufU` + (`IpcFootN.vmOrc` in `VmEptPre.preemptPathVFk`); both ask the platform's `ticks_to_us` / `maxTicksToUs` [P] + (existing, as P3/VmDisp / VmDelCap) only on `PPRecv` holes (`hTU`); `VmEptPre.preemptPathVF` unchanged. + +(gen 42b79, ruling 00:11Z item 2, route (B): every preemption hole, zero new premises) **`PPRest` is gone**: its +`runningVM` case is excluded by `hnv : ¬ NoTmoSend σ → ¬ RunningVM σ` (P3/VmPerfRvm's `RunningVM`), which +`JHole.mcsPPVF` and `VmEptPre.preemptPathVFk` take in place of `¬ PPRest σ` (statements changed); at a preempted +invocation it is P3/VmPerfRvm's `perfCtNVmVF` (the extended dispatcher makes no thread `runningVM`) from the +invocation's entry. `VmEptPre.preemptPathVF` unchanged (`PPCov` gives `NoTmoSend`, `PPCovT` a running or restarting +current thread). + +Premises: no named premise. The platform records are the existing [P] ones (`ARIface`, `ARKeep`, `ArchTotal`, +`MachPlat`, `MRKeep`, `PPPlatA`, `IrqPlatA`, `max_release_time`, `numDomains = 1`, [P] `ZvVirtAgree`, the platform's +`MIN_BUDGET`); `VmEptPre.preemptPathVF` takes `VmEptState.handleIrqVF`'s `hMsig` (the spec signal keeps `MR`) as given. +New file. +-/ +import Fl4Proofs.P3.VmOracle +import Fl4Proofs.P3.P3JPreSt +import Fl4Proofs.P3.RetVmReset +import Fl4Proofs.P3.VmPerfRvm +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section Spec +open Fl4Spec + +/-- The extended preemption path is `ppG` at the extended handler (module docstring). -/ +theorem preemptionPathVF_ppG (on rc : ObjRef → Bool) : + preemptionPathVF (Z := Unit) on rc = ppG (maybeHandleInterruptVF on rc true) := rfl + +/-- (gen 42b75) **The current thread's endpoint timeout handler, if any, names an endpoint idle or sending** (a +timeout fault to it blocks the thread: P1's `send_ipc.block`). -/ +def TmoBlk (σ : State Unit) : Prop := + ∀ xt p bd r, σ.kheap σ.curThread = some (.tcb xt) → xt.tcbTimeoutHandler = .endpointCap p bd r → + ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe + +/-- (gen 42b78) **The receiving-endpoint preemption holes**: the current thread `CurInv`, schedulable, with +insufficient budget, a timeout fault it may raise (`¬ NoTmoSend`), not `runningVM`, and its timeout fault going to a receiving endpoint (`¬ TmoBlk`), the only holes whose +spec side (ScChargeTR's `checkBudgetTR`) reads the platform's `ticks_to_us` and `maxTicksToUs`. -/ +def PPRecv (σ : State Unit) : Prop := + Sched.CurInv σ ∧ schedulable σ.curThread σ = true ∧ + ¬ (∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → + refillSufficient σ.consumedTime (refillHd y) = true) ∧ + ¬ Sched.NoTmoSend σ ∧ + ∃ xt, σ.kheap σ.curThread = some (.tcb xt) ∧ xt.tcbState ≠ .runningVM ∧ ¬ TmoBlk σ + +/-- `maybe_handle_interrupt` (extended) with no pending line. -/ +theorem mem_maybeHandleVF_none {on rc : ObjRef → Bool} {σ σ' : State Unit} + (h : doMachineOp (Z := Unit) (getActiveIRQ true) σ = ({(none, σ')}, False)) : + ((), σ') ∈ (maybeHandleInterruptVF (Z := Unit) on rc true σ).1 := by + unfold maybeHandleInterruptVF + exact mem_bind_nd (x := (none, σ')) (by rw [h]; rfl) rfl + +/-- `maybe_handle_interrupt` (extended) with a pending line. -/ +theorem mem_maybeHandleVF_some {on rc : ObjRef → Bool} {σ σ' : State Unit} {i : Irq} {z : Unit × State Unit} + (h : doMachineOp (Z := Unit) (getActiveIRQ true) σ = ({(some i, σ')}, False)) + (hz : z ∈ (handleInterruptVF (Z := Unit) on rc i σ').1) : + z ∈ (maybeHandleInterruptVF (Z := Unit) on rc true σ).1 := by + unfold maybeHandleInterruptVF + exact mem_bind_nd (x := (some i, σ')) (by rw [h]; rfl) hz + +end Spec + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + +set_option maxHeartbeats 4000000 in +/-- **A timeout fault on an idle or sending endpoint is a `FootN` step** (module docstring). -/ +theorem handle_timeout_blkN {T Cs Ω : Set U64} {H : P1.Heap} {Sg Rp Scs Nt : Set U64} {Zb : U64 → Nat} + {Ac Kp : Set U64} {Nd : Prop} (s : S) (a : A) (t f : U64) {cv : capability.Cap} + (h : P1.BlkOK st T Cs Ω H Sg Rp Scs Nt Zb Ac s) (hc : P1.CanBlock st T Ac s t) (hKt : t ∉ Kp) + (hHΩ : P1.HdrΩ Nd Ω Scs) (hcv : capAt (L.mem s) (slotOf t 4) = ok cv) + (hep : ∀ p b x y g gr, cv = .Endpoint p b x y g gr → H p = some .ep ∧ + ∀ s1 : S, P1.WritesIn st s s1 (fun w => ((w = tFaultA t ∨ w = tFw0A t) ∨ w = tFw1A t) ∨ w = tFw2A t) → + L.epState s1 p = 0#u64 ∨ L.epState s1 p = 1#u64) : + faults.handle_timeout st arI s a t (error.Fault.Timeout f) ⦃ s' _ => + P1.BXI st T Cs Ω H Sg Rp Scs Nt Zb Ac s' ∧ P1.FootN st Kp Nd T Cs Sg Scs Zb (P1.EH H) s s' ⦄ := by + have ht := hc.mem + obtain ⟨⟨Q, R, q0⟩, -, -, -, -⟩ := id h + have hta := q0.tcbs t ht + unfold faults.handle_timeout + rw [tcb_slot_timeout] + apply ok_bind_spec + rw [slot_cap_eq, hcv] + apply ok_bind_spec + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => P1.BXI st T Cs Ω H Sg Rp Scs Nt Zb Ac r.2.1 ∧ + P1.FootN st Kp Nd T Cs Sg Scs Zb (P1.EH H) s r.2.1) ?_ ?_ + · unfold faults.send_fault_ipc + cases cv + all_goals first | exact (WP.spec_ok _).2 ⟨P1.BlkOK.bxi h, P1.FootN.refl s⟩ | skip + rename_i p b x y g gr + obtain ⟨hpH, hst⟩ := hep p b x y g gr rfl + dsimp only + refine WP.spec_bind (WP.spec_and (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s t (error.Fault.Timeout f) h ht + (fun _ h => by simp at h) hc) (P1.faults.set_fault.kwN (Kp := Kp) (Nd := Nd) (Cs := Cs) (Sg := Sg) (Scs := Scs) + (Z := Zb) (Es := P1.EH H) s t _ q0.tcbs q0.nodes q0.cur ht)) + (set_fault_timeout_eq s t f)) ?_ + rintro s1 ⟨⟨⟨h1, -, hc1⟩, F1⟩, e1⟩ + have w1 : P1.WritesIn st s s1 (fun w => ((w = tFaultA t ∨ w = tFw0A t) ∨ w = tFw1A t) ∨ w = tFw2A t) := by + rw [e1] + exact (((P1.writesIn_wr (a_fault hta).1).trans (P1.writesIn_wr (a_fw0 hta).1)).trans + (P1.writesIn_wr (a_fw1 hta).1)).trans (P1.writesIn_wr (a_fw2 hta).1) + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := h1 + refine WP.spec_bind (WP.spec_and (P1.endpoint.send_ipc.block arI s1 a true false b g gr false t p Q1 R1 q1 hB1 hX1 + hS1 hSg1 (fun _ => hc1) hpH (hst s1 w1)) + (P1.endpoint.send_ipc.blockFootN (Kp := Kp) (Nd := Nd) (Sg := Sg) (Scs := Scs) (Z := Zb) arI s1 a true false b g gr + false t p q1 (fun _ => hc1) hpH (hst s1 w1) hKt hHΩ)) ?_ + rintro ⟨s2, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨⟨q2, hB2, hX2, hS2, hSg2⟩, F2⟩ := hh + exact (WP.spec_ok _).2 ⟨⟨⟨Q1, R1, q2⟩, hB2, hX2, hSg2, hS2⟩, F1.trans F2⟩ + · rintro ⟨x, s2, a2⟩ h2 + exact (WP.spec_ok _).2 h2 + +/-- (gen 42b78) **The hole's word set without the IPC-buffer words** (`BufU`): where the timeout fault's message +transfer runs (`JHole.mcsIpcN`; XTopJointKEntryFF's `OmegaU` without the VSpace words). -/ +def OmegaB (H : P1.Heap) (Z : XSets) (σ : Fl4Spec.State Unit) : Set U64 := + {b | b ∈ P1.Heap.omega H ∧ b ∉ BufU Z σ} + +set_option maxHeartbeats 4000000 in +/-- (gen 42b78, ruling 23:24Z item 1) **A timeout fault on any endpoint is an `IpcFootN` step** (module docstring): +`set_fault` (`set_fault_timeout_eq`, a `FootN` step), then P1's `send_ipc.ipcT` beside P2/FootN5's +`send_ipc.footPNT`, the transfer asked only from the faulting thread (`xferOKAt_fault`: its guard, the buffer +placement `BufAt` and the fault word `Timeout`, holds after the receiver's dequeue by its TCB-word frame), the +transfer's own footprint `do_fault_transfer.xsfc` / `XferWC.ipcN`. -/ +theorem handle_timeout_ipcN {T Cs Ω U : Set U64} {H : P1.Heap} {Sg Rp Scs Nt : Set U64} {Zb : U64 → Nat} + {Ac : Set U64} (hA : P0.ArchTotal arI) (s : S) (a : A) (t f : U64) {cv : capability.Cap} + (h : P1.BlkOK st T Cs Ω H Sg Rp Scs Nt Zb Ac s) (hU : P1.UserOK st T Cs Ω H U s) + (hBA : P1.BufAt st T Cs H Sg Scs Zb U s) (hc : P1.CanBlock st T Ac s t) + (hcv : capAt (L.mem s) (slotOf t 4) = ok cv) + (hep : ∀ p b x y g gr, cv = .Endpoint p b x y g gr → H p = some .ep) : + faults.handle_timeout st arI s a t (error.Fault.Timeout f) ⦃ s' _ => + P1.BlkOK st T Cs Ω H Sg Rp Scs Nt Zb Ac s' ∧ P1.IpcFootN st ∅ True T Cs Ω Sg Scs Zb (P1.EH H) U s s' ⦄ := by + have ht := hc.mem + obtain ⟨⟨Q, R, q0⟩, -, -, -, -⟩ := id h + have hta := q0.tcbs t ht + unfold faults.handle_timeout + rw [tcb_slot_timeout] + apply ok_bind_spec + rw [slot_cap_eq, hcv] + apply ok_bind_spec + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => P1.BlkOK st T Cs Ω H Sg Rp Scs Nt Zb Ac r.2.1 ∧ + P1.IpcFootN st ∅ True T Cs Ω Sg Scs Zb (P1.EH H) U s r.2.1) ?_ ?_ + · unfold faults.send_fault_ipc + cases cv + all_goals first | exact (WP.spec_ok _).2 ⟨h, P1.IpcFootN.refl s⟩ | skip + rename_i p b x y g gr + have hpH := hep p b x y g gr rfl + dsimp only + refine WP.spec_bind (WP.spec_and (WP.spec_and (P1.faults.set_fault.blk s t (error.Fault.Timeout f) h ht hU hc) + (P1.faults.set_fault.kwN (Kp := ∅) (Nd := True) (Cs := Cs) (Sg := Sg) (Scs := Scs) (Z := Zb) (Es := P1.EH H) + s t _ q0.tcbs q0.nodes q0.cur ht)) + (set_fault_timeout_eq s t f)) ?_ + rintro s1 ⟨⟨⟨h1, hU1, hc1⟩, F1⟩, e1⟩ + have w1 : P1.WritesIn st s s1 (fun w => ((w = tFaultA t ∨ w = tFw0A t) ∨ w = tFw1A t) ∨ w = tFw2A t) := by + rw [e1] + exact (((P1.writesIn_wr (a_fault hta).1).trans (P1.writesIn_wr (a_fw0 hta).1)).trans + (P1.writesIn_wr (a_fw1 hta).1)).trans (P1.writesIn_wr (a_fw2 hta).1) + -- `set_fault` writes only the four fault words of `t` + have k01 : ∀ y ∈ T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 3376 ∨ 3400 < K.val) → + L.mem s1 (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K) := by + intro y hy K hK hK8 hKo + have hn : ∀ K2 : U64, K2.val < 4096 → 3376 ≤ K2.val → K2.val ≤ 3400 → + core.num.U64.wrapping_add y K ≠ core.num.U64.wrapping_add t K2 := + fun K2 h2 h3 h4 => P1.field_ne (q0.tcbs y hy) hta hK h2 (fun _ => by omega) + refine w1.mem_eq (P1.field_aligned (q0.tcbs y hy) hK hK8) ?_ + unfold tFaultA tFw0A tFw1A tFw2A + rintro (((e | e) | e) | e) + · exact hn _ (by simp) (by simp) (by simp) e + · exact hn _ (by simp) (by simp) (by simp) e + · exact hn _ (by simp) (by simp) (by simp) e + · exact hn _ (by simp) (by simp) (by simp) e + -- the fault word reads `Timeout` + have ft1 : L.mem s1 (tFaultA t) = fl4_abi.consts.fault.Timeout := by + have hfv : ∀ K : U64, K.val < 4096 → K.val ≠ 3376 → + (core.num.U64.wrapping_add t K).val ≠ (tFaultA t).val := fun K hK hne e => + P1.field_ne hta hta hK (by simp) (fun _ => by simpa using hne) (UScalar.eq_of_val_eq e) + rw [e1, L.mem_wr_ne (a_fw2 hta).1 (a_fault hta).1 (hfv 3400#u64 (by simp) (by simp)), + L.mem_wr_ne (a_fw1 hta).1 (a_fault hta).1 (hfv 3392#u64 (by simp) (by simp)), + L.mem_wr_ne (a_fw0 hta).1 (a_fault hta).1 (hfv 3384#u64 (by simp) (by simp)), + L.mem_wr_same (a_fault hta).1] + -- the transfer's guard after the receiver's dequeue, from its TCB-word frame + have hGd : ∀ s2 : S, (∀ y ∈ T, ∀ K : U64, 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 s1 (core.num.U64.wrapping_add y K)) → + L.ksb s2 = L.ksb s1 → + P1.BufAt st T Cs H Sg Scs Zb U s2 ∧ + obj.Tcb.fault_type st t s2 ⦃ i => i ≠ fl4_abi.consts.fault.NullFault ⦄ := by + intro s2 fr hk + have k02 : ∀ y ∈ T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + (K.val < 3376 ∨ 3400 < K.val) → + L.mem s2 (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K) := + fun y hy K h1 h2 h3 h4 h5 => (fr y hy K h1 h2 h3 h4).trans (k01 y hy K h1 h2 h5) + refine ⟨hBA.of_fr ⟨hk.trans (by rw [e1]; simp), fun y hy => ⟨?_, ?_, ?_⟩⟩, ?_⟩ + · exact k02 y hy 3512#u64 (by simp) (by simp) (by simp) (by simp) (by simp) + · rw [P1.sbWordA_eq]; exact k02 y hy 64#u64 (by simp) (by simp) (by simp) (by simp) (by simp) + · rw [P1.sbWordA8_eq]; exact k02 y hy 72#u64 (by simp) (by simp) (by simp) (by simp) (by simp) + · refine WP.spec_mono (Fl4Proofs.P3.Endp.obj.Tcb.fault_type.spec s2 t) fun v hv => ?_ + have e3 : L.mem s2 (tFaultA t) = L.mem s1 (tFaultA t) := + fr t ht 3376#u64 (by simp) (by simp) (by simp) (by simp) + rw [hv, e3, ft1] + simp [fl4_abi.consts.fault.Timeout, fl4_abi.consts.fault.NullFault] + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := h1 + have hK1 : P1.IpcFootN st ∅ True T Cs Ω Sg Scs Zb (P1.EH H) U s s1 := P1.FootN.ipc F1 + refine WP.spec_bind (WP.spec_and (P1.endpoint.send_ipc.ipcT hA s1 a true false b g gr false t p + (P1.xferOKAt_fault hA ht) Q1 R1 (fun s2 _ _ _ fr hk => hGd s2 fr hk) q1 hB1 hX1 hS1 hSg1 hU1 hc1 + (fun e => by cases e) hpH) + (P1.endpoint.send_ipc.footPNT hA s1 a true false b g gr false t p Q1 R1 q1 hB1 hX1 hS1 hSg1 hU1 hc1 + (fun e => by cases e) hpH (fun h => h) (fun _ h => (h : False).elim) (fun e => by cases e) + (fun _ h => h) (P1.xferOKAt_fault hA ht) (fun s2 F2 fr => hGd s2 fr F2.1) + (fun s2 => P1.IpcFootN st ∅ True T Cs Ω Sg Scs Zb (P1.EH H) U s s2) + (fun _ _ h1 h2 => P1.IpcFootN.trans h1 (P1.FootDN.ipc h2)) hK1 ?_)) ?_ + · intro Ac' X Q' R' s2 a2 ep badge grant rcv hr hq hB2 hX2 hS2 hSg2 hU2 F2 hG2 + obtain ⟨hBA2, hft⟩ := hG2 + have h0 : P1.XSFC st T Cs Ω H Sg Rp Scs Nt Zb U (fun _ _ => True) Ac' X Q' R' s2 s2 := + P1.XSFC.start ⟨hq, hB2, hX2, hS2, hSg2, hU2⟩ trivial fun _ _ _ _ => trivial + unfold ipc.do_ipc_transfer + refine WP.spec_bind (hBA2.2 rcv hr) fun rb hb => ?_ + refine WP.spec_bind hft fun ft hft' => ?_ + split + · exact absurd (by assumption) hft' + · refine WP.spec_mono (P1.ipc.do_fault_transfer.xsfc hA h0 ht hr hb) fun s3 h3 => ?_ + exact P1.IpcFootN.trans (P1.IpcFootN.trans hK1 (P1.FootN.ipc F2)) + (P1.XferWC.ipcN hq hX2 hU2 hSg2.sub h3.2.2.1) + · rintro ⟨s2, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + exact (WP.spec_ok _).2 hh + · rintro ⟨x, s2, a2⟩ h2 + exact (WP.spec_ok _).2 h2 + +end + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} + +/-- (gen 42b75) **FL4's `is_schedulable` of the current thread at a hole is the spec's `schedulable`** (P3/SchedTcb's +`schedulable_eq`), in the form P1's `is_schedulable.spec'` gives it. -/ +theorem JHole.sched_of_F {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) + (h : P1.Runnable (L.mem s (P1.stA (L.curW s))) ∧ L.mem s (P1.scA (L.curW s)) ≠ 0#u64 ∧ + (L.mem s (P1.inqA (L.curW s)) &&& sched.Q_RELEASE) = 0#u64 ∧ L.rmax s (L.mem s (P1.scA (L.curW s))) ≠ 0#u64) : + Fl4Spec.schedulable σ.curThread σ = true := by + obtain ⟨h1, h2, h3, h4⟩ := h + have hS := Hh.xtop.fin.1.1.1 + have hR := Hh.xtop.fin.1.1.2.2.1 + obtain ⟨Qs, Rs, hc, hs⟩ := hS.lists + have ecur : L.curW s = nodeW st s Z.c layout.node.CUR_THREAD := by + unfold P1.LawfulStore.curW nodeW; rw [hc.cur] + rw [ecur] at h1 h2 h3 h4 + have h4' : L.rmax s (L.mem s (P1.scA (nodeW st s Z.c layout.node.CUR_THREAD))) > 0#u64 := by + generalize L.rmax s (L.mem s (P1.scA (nodeW st s Z.c layout.node.CUR_THREAD))) = x at h4 ⊢ + have hx : x.val ≠ 0 := fun e => h4 (UScalar.eq_of_val_eq (by simp [e])) + show (0#u64 : U64).val < x.val + simp; omega + rw [hs.curThread, ← schedulable_eq hR hS hc.curT] + exact decide_eq_true ⟨h1, h2, h4', h3⟩ + +set_option maxHeartbeats 4000000 in +/-- (gen 42b78, ruling 23:24Z item 1) **The MCS preemption point from any hole keeps a property `G` of the states +`FootN ∅ True` steps keep, given the timeout fault keeps it where it may be raised** (module docstring; the shared +prefix of `JHole.mcsFootNG` and `JHole.mcsIpcN`): the current thread's SC word is the current SC or none (`hcs`), +no switch to it pending (`hsw`), and, when the spec schedules it (P3JPreSt's `tmoNG`), `NoTmoSend` or `Pa`; under +`Pa` the fault (`harm`) is asked at the state `ChgW` writes reach, with the current thread's endpoint handler read +off the hole (its endpoint one of `Z.E`, the cap kept), every TCB field kept from the hole and the thread able to +block when it is neither idle nor queued. -/ +theorem JHole.mcsTmoG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hcs : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → + xt.tcbSchedContext = some σ.curSc ∨ xt.tcbSchedContext = none) + (hsw : σ.schedulerAction ≠ .switchThread σ.curThread) {G : S → Prop} + (hGF : ∀ s1 s2 : S, G s1 → P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) s1 s2 → G s2) (hG0 : G s) {Pa : Prop} + (htm : Fl4Spec.schedulable σ.curThread σ = true → NoTmoSend σ ∨ Pa) + (harm : Pa → ∀ (s' : S) (a' : A) (f : U64), P1.BXI st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) + (P1.Heap.replies H) (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s' → + P1.WritesIn st s s' (ChgW st (P1.Heap.scs H) (P1.Heap.scBits H) s) → G s' → + (∀ y ∈ P1.Heap.tcbs H, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → + L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) → + ∀ (xt : Fl4Spec.Tcb) (p bd : Fl4Spec.Word) (r : Fl4Spec.CapRights) (ptr : U64) (cv : capability.Cap), + σ.kheap σ.curThread = some (.tcb xt) → xt.tcbTimeoutHandler = .endpointCap p bd r → ptr.bv = p → ptr ∈ Z.E → + capAt (L.mem s') (slotOf (L.curW s') 4) = ok cv → + (∃ bdg sd rv g gr, cv = .Endpoint ptr bdg sd rv g gr) → L.curW s' = L.curW s → + (σ.curThread ≠ σ.idleThread → (∀ d p, σ.curThread ∉ σ.readyQueues d p) → + P1.CanBlock st (P1.Heap.tcbs H) Ac s' (L.curW s')) → + faults.handle_timeout st arI s' a' (L.curW s') (error.Fault.Timeout f) ⦃ s'' _ => + P1.BXI st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) (P1.Heap.scs H) + (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s'' ∧ G s'' ⦄) : + syscall.mcs_preemption_point st arI s a ⦃ s' _ => G s' ⦄ := by + have J := Hh.j0 + have hS := Hh.xtop.fin.1.1.1 + obtain ⟨Qs, Rs, hc, hs⟩ := hS.lists + obtain ⟨⟨Q1, R1, q⟩, hB, hX, hSc, hSg⟩ := id Hh.blk + have ecur : L.curW s = nodeW st s Z.c layout.node.CUR_THREAD := by + unfold P1.LawfulStore.curW nodeW; rw [hc.cur] + have ecsc : L.cscW s = nodeW st s Z.c layout.node.CUR_SC := by + unfold P1.LawfulStore.cscW P1.LawfulStore.nodeA nodeW; rw [hc.cur] + have hct : σ.curThread = (L.curW s).bv := by rw [ecur]; exact hs.curThread + have hcT : L.curW s ∈ Z.T := by rw [ecur]; exact hc.curT + have hpc : (nodeW st s Z.c layout.node.CUR_SC).bv = σ.curSc := hs.curSc.symm + have hcsc : L.mem s (P1.scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (P1.scA (L.curW s)) := fun h0 => by + obtain ⟨xt, hkt, -, -, hsct, -⟩ := hs.tcb _ hc.curT + rw [ecur] at h0 ⊢; rw [ecsc] + have hl := hcs xt (by rw [hs.curThread]; exact hkt) + rw [hsct, Notif.optRef_ne h0] at hl + rcases hl with hl | hl + · exact P1.eq_of_bv (hpc.trans (Option.some.inj hl).symm) + · cases hl + have hna : L.actionW s ≠ L.curW s := actionW_ne_of hS hcT (by rw [← hct]; exact hsw) + refine Fl4Proofs.P2.Stall.syscall.mcs_preemption_point.tmoNG (Nd := True) hAT s a Q1 R1 q hB hX hSg hSc hcsc hna + hGF hG0 ?_ + intro hsF s' a' f Q' R' q' hB' hX' hSg' hS' hw hper hok hG hp hv + -- the words `ChgW` writes are free words: the current thread and every TCB field kept + have wF : P1.WritesIn st s s' (L.Free s (P1.Heap.omega H) Cs) := hw.mono' fun b hb hh => by + rcases hh with ⟨c, hc', hin⟩ | e + · exact Or.inl (hX.1.scW c hc' b hb hin) + · exact e ▸ free_cur_node q.cur (by simp [layout.node.CONSUMED, LowFree]) + obtain ⟨-, kc, ki, -⟩ := free_keys q wF + have hT := q.tcbs + have hcTH : L.curW s ∈ P1.Heap.tcbs H := J.zH.1 _ hcT + have fldY : ∀ y ∈ P1.Heap.tcbs H, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → + L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K) := by + intro y hy K hK hK8 + refine wF.mem_eq (field_aligned (hT _ hy) hK hK8) ?_ + rintro (hm | ⟨c, hc', o, ho, e⟩) + · exact out_ne_field (q.omega _ hm) hy (hT _ hy) hK rfl + · exact node_ne_field (q.nodes c hc') (by simp only [LowFree] at ho; omega) hy (hT _ hy) hK e.symm + have fld := fldY _ hcTH + -- the timeout-handler slot of the current thread kept + have hta := hT _ hcTH + have hsl0 : slotOf (L.curW s) 4 = core.num.U64.wrapping_add (L.curW s) 128#u64 := by + apply UScalar.eq_of_val_eq + rw [slotOf_val (by have := hta.fits; norm_num at this ⊢; omega), field_val hta (by simp)]; simp + have hsl8 : core.num.U64.wrapping_add (slotOf (L.curW s) 4) 8#u64 = core.num.U64.wrapping_add (L.curW s) 136#u64 := by + apply UScalar.eq_of_val_eq + rw [hsl0, core.num.U64.wrapping_add_val_eq, field_val hta (by simp), field_val hta (by simp)] + have := hta.fits; simp [U64.size_def, U64.numBits] at this ⊢; omega + have hcapK : capAt (L.mem s') (slotOf (L.curW s') 4) = capAt (L.mem s) (slotOf (L.curW s) 4) := by + rw [kc]; unfold capAt; rw [hsl8, hsl0, fld _ (by simp) (by simp), fld _ (by simp) (by simp)] + have hval : faults.valid_timeout_handler st s' (L.curW s') = faults.valid_timeout_handler st s (L.curW s) := by + unfold faults.valid_timeout_handler + rw [tcb_slot_timeout, tcb_slot_timeout, bind_ok, bind_ok, slot_cap_eq, slot_cap_eq, hcapK] + have hthT : Z.th (L.curW s) = some .tcb := by + obtain ⟨xt, hkt, -⟩ := Hh.xtop.ipc.tcb _ hcT + exact Hh.xtop.rel.tcbT hkt + rw [hval] at hv + obtain ⟨-, xt, hkt, hvt⟩ := spec_at (valid_timeout_handler_rel s σ Hh.xtop.rel.2.1.1 hthT) hv + have hkt' : σ.kheap σ.curThread = some (.tcb xt) := by rw [hct]; exact hkt + obtain ⟨p, bd, r, hth⟩ : ∃ p bd r, xt.tcbTimeoutHandler = .endpointCap p bd r := by + revert hvt; cases xt.tcbTimeoutHandler <;> simp [Fl4Spec.isEpCap] + rcases htm (Hh.sched_of_F hsF) with (hnt | hnt) | hpa + · -- no endpoint timeout handler: `valid_timeout_handler` is false + have h1 := hnt xt hkt' + rw [hth] at h1 + simp [Fl4Spec.isEpCap] at h1 + · -- a round-robin current SC: its period word is `0` + exfalso + have hscC : nodeW st s Z.c layout.node.CUR_SC ∈ Z.C := Hh.curSc_in + obtain ⟨x, n, hkx, hx⟩ := hs.scs _ hscC + have hp0 : L.rperiod s (L.cscW s) = 0#u64 := by + rw [ecsc]; exact P1.eq_of_bv (by rw [← hx.period, hnt x n (by rw [hs.curSc]; exact hkx)]; rfl) + exact hp (hper.trans hp0) + · -- an endpoint timeout handler: its endpoint is one of `Z.E` (the base's slot, `JAtZB.slotE`) + have hkh0 : σ0.kheap (L.curW s).bv = some (.tcb xt) := by rw [← Hh.sfacts.2.2.2.2.1]; exact hkt + obtain ⟨x0, c0, hk0, hc0, hca0⟩ := J.xtop.rel.2.1.1.timeoutCap hthT + rw [hkh0] at hk0; cases hk0 + have habs0 := hca0.2 + rw [hth] at habs0 + obtain ⟨ptr0, b0, sd0, rv0, g0, gr0, rfl⟩ : ∃ ptr bdg sd rv g gr, c0 = .Endpoint ptr bdg sd rv g gr := by + cases c0 <;> simp [absCap] at habs0; exact ⟨_, _, _, _, _, _, rfl⟩ + simp only [absCap, Fl4Spec.Cap.endpointCap.injEq] at habs0 + have hAS : AbsSlot Z.th ((L.curW s).bv, Fl4Spec.tcbCnodeIndex 4) := ⟨L.curW s, rfl, Or.inr ⟨hthT, 4, by decide, rfl⟩⟩ + have hpE : ptr0 ∈ Z.E := J.slotE hAS (by rw [tcbSlot4_eq]; exact hc0) + -- the cap at the hole + obtain ⟨xh, cv, hkh, hcv, hca⟩ := Hh.xtop.rel.2.1.1.timeoutCap hthT + rw [hkt] at hkh; cases hkh + have habs := hca.2 + rw [hth] at habs + obtain ⟨ptr, bdg, sd, rv, g, gr, rfl⟩ : ∃ ptr bdg sd rv g gr, cv = .Endpoint ptr bdg sd rv g gr := by + cases cv <;> simp [absCap] at habs; exact ⟨_, _, _, _, _, _, rfl⟩ + simp only [absCap, Fl4Spec.Cap.endpointCap.injEq] at habs + obtain rfl : ptr = ptr0 := P1.eq_of_bv (habs.1.trans habs0.1.symm) + -- the thread can block at the state `ChgW` writes reach, when neither idle nor queued + have hcb' : σ.curThread ≠ σ.idleThread → (∀ d p, σ.curThread ∉ σ.readyQueues d p) → + P1.CanBlock st (P1.Heap.tcbs H) Ac s' (L.curW s') := fun hni hnq => by + have kq : L.mem s' (P1.inqA (L.curW s)) = L.mem s (P1.inqA (L.curW s)) := by + rw [P1.inqA_eq]; exact fld _ (by simp) (by simp) + have hnq0 : (L.mem s (P1.inqA (L.curW s)) &&& sched.Q_QUEUED) = 0#u64 := by + by_contra hq' + have hm := (hc.queued _ hcT).1 hq' + exact hnq 0 _ (by rw [hct, hs.rq _ (hc.prio _ hcT), mem_map_bv]; exact hm) + have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by + unfold P1.LawfulStore.idleW nodeW; rw [hc.cur] + have hni0 : L.idleW s ≠ L.curW s := fun e => hni (by rw [hct, hs.idleTh, ← ei, e]) + exact ⟨q'.curT, fun hb => blocked_not_runnable hb hok.run, runnable_ne_reply hok.run, by rw [kc, kq]; exact hnq0, + hok.rel, hok.act, by rw [ki, kc]; exact hni0, fun _ => (hS'.act _ (hX'.2.2.bound _ q'.curT hok.bnd).1).2 hok.rmx⟩ + exact harm hpa s' a' f ⟨⟨Q', R', q'⟩, hB', hX', hSg', hS'⟩ hw hG fldY xt p bd r ptr _ hkt' hth habs.1 hpE + (by rw [hcapK]; exact hcv) ⟨_, _, _, _, _, rfl⟩ kc hcb' + +set_option maxHeartbeats 4000000 in +/-- (gen 42b75, ruling 19:49Z item 2) **The MCS preemption point from any hole is a `FootN ∅ True` step where its +timeout fault cannot reach a receiving endpoint** (module docstring): the current thread's SC word is the current SC +or none (`hcs`, P3/ScPPR's `CtOK`), no switch to it pending (`hsw`), and, when the spec schedules it (the only arm +calling `check_budget`, P3JPreSt's `tmoN`), no endpoint timeout handler or a round-robin SC (`NoTmoSend`), or an +endpoint handler on an idle or sending endpoint (`TmoBlk`, with the thread not idle and not queued). 42b74's +`JHole.mcsFootN` is its `PPCov ∨ PPCovT` corollary. (gen 42b78) Through `JHole.mcsTmoG` at `G := FootN`. -/ +theorem JHole.mcsFootNG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hcs : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → + xt.tcbSchedContext = some σ.curSc ∨ xt.tcbSchedContext = none) + (hsw : σ.schedulerAction ≠ .switchThread σ.curThread) + (htm : Fl4Spec.schedulable σ.curThread σ = true → NoTmoSend σ ∨ + (σ.curThread ≠ σ.idleThread ∧ (∀ d p, σ.curThread ∉ σ.readyQueues d p) ∧ TmoBlk σ)) : + syscall.mcs_preemption_point st arI s a ⦃ s' _ => P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s' ⦄ := by + have J := Hh.j0 + refine Hh.mcsTmoG hAT hcs hsw (G := fun s' => P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s') (fun _ _ h1 h2 => P1.FootN.trans h1 h2) (P1.FootN.refl s) htm ?_ + rintro ⟨hni, hnq, htb⟩ s' a' f hB' hw hG - xt p bd r ptr cv hkt hth hpb hpE hcv ⟨bdg, sd, rv, g, gr, rfl⟩ kc hcb + obtain ⟨⟨Q1, R1, q⟩, -, -, -, -⟩ := id Hh.blk + have hS := Hh.xtop.fin.1.1.1 + obtain ⟨Qs, Rs, hc, hs⟩ := hS.lists + have hcT : L.curW s ∈ Z.T := by + have ecur : L.curW s = nodeW st s Z.c layout.node.CUR_THREAD := by + unfold P1.LawfulStore.curW nodeW; rw [hc.cur] + rw [ecur]; exact hc.curT + have hta := q.tcbs _ (J.zH.1 _ hcT) + -- the endpoint idle or sending at the hole + have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE + obtain ⟨xe, hke, hxe⟩ := Hh.xtop.ipc.ep ptr hpE + have hcbe : Endp.CanBlock false xe := htb xt p bd r hkt hth xe (by rw [← hpb]; exact hke) + have hst2 : stOf (L.mem s) ptr = 0#u64 ∨ stOf (L.mem s) ptr = 1#u64 := by + cases xe with + | idleEP => exact Or.inl hxe.1 + | sendEP q => exact Or.inr hxe.1 + | recvEP q => simp [Endp.CanBlock] at hcbe + -- its state word: no SC word, no node word, no fault word of the thread + have hpl := J.ip.e.ep ptr hpE + have hev : (epTSA ptr).val = ptr.val + 8 := by + unfold epTSA + rw [core.num.U64.wrapping_add_val_eq] + have e8 : layout.ep.TAIL_STATE.val = 8 := by unfold layout.ep.TAIL_STATE; rfl + rw [e8] + have hsz : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [U64.size_def, U64.numBits] + rw [hsz] + exact Nat.mod_eq_of_lt (by omega) + have hal1 : Aligned (epTSA ptr) := by + show (epTSA ptr).val % 8 = 0 + rw [hev]; omega + have hnc : ¬ ChgW st (P1.Heap.scs H) (P1.Heap.scBits H) s (epTSA ptr) := by + rintro (⟨c, ⟨z, hz⟩, hin⟩ | e) + · have hne : ptr ≠ c := fun e => by rw [e, hz] at hHe; cases hHe + have hd := J.kern.heap.disj ptr .ep c (.sc z) hHe hz hne + have hzb : P1.Heap.scBits H c = z := by unfold P1.Heap.scBits; rw [hz] + rw [hzb] at hin + obtain ⟨h1, h2⟩ := hin + simp only [P1.HKind.bits, show (2 : ℕ) ^ 4 = 16 from rfl] at hd + rw [hev] at h1 h2 + omega + · have hN := q.nodes _ q.cur + have hv := P1.nodeAt_val hN (off := layout.node.CONSUMED) (by simp [layout.node.CONSUMED]) + have hd := J.kern.hnd ptr .ep hHe (L.cpu s) q.cur + simp only [P1.HKind.bits, show (2 : ℕ) ^ 4 = 16 from rfl] at hd + have hnb : L.nodeBase s (L.cpu s) = L.nodeBase s0 (L.cpu s) := by + show (L.ksb s).val + 13568 + (L.cpu s).val * 4288 = (L.ksb s0).val + 13568 + (L.cpu s).val * 4288 + rw [Hh.ws.1] + have h40 : layout.node.CONSUMED.val = 40 := by simp [layout.node.CONSUMED] + have := congrArg UScalar.val e + rw [hev, hv, hnb, h40] at this + omega + have het := J.ip.e.et ptr hpE _ hcT + have hfv : ∀ K : U64, K.val < 4096 → (epTSA ptr).val ≠ (core.num.U64.wrapping_add (L.curW s) K).val := by + intro K hK + rw [hev, field_val hta hK] + omega + have hnf : ¬ (((epTSA ptr = tFaultA (L.curW s') ∨ epTSA ptr = tFw0A (L.curW s')) ∨ + epTSA ptr = tFw1A (L.curW s')) ∨ epTSA ptr = tFw2A (L.curW s')) := by + rw [kc] + rintro (((e | e) | e) | e) + · exact hfv 3376#u64 (by simp) (congrArg UScalar.val e) + · exact hfv 3384#u64 (by simp) (congrArg UScalar.val e) + · exact hfv 3392#u64 (by simp) (congrArg UScalar.val e) + · exact hfv 3400#u64 (by simp) (congrArg UScalar.val e) + refine WP.spec_mono (handle_timeout_blkN (Kp := ∅) (Nd := True) s' a' (L.curW s') f + ⟨hB'.1, hB'.2.1, hB'.2.2.1, hB'.2.2.2.2, hB'.2.2.2.1⟩ (hcb hni hnq) (fun h => h) + (hdrΩ_of hB'.2.2.1 hB'.2.2.2.2.sub) hcv ?_) ?_ + · intro p' b' x' y' g' gr' e + cases e + refine ⟨hHe, fun s1 w1 => ?_⟩ + have m1 : L.mem s1 (epTSA ptr) = L.mem s (epTSA ptr) := (w1.mem_eq hal1 hnf).trans (hw.mem_eq hal1 hnc) + show L.mem s1 (epTSA ptr) &&& 3#u64 = 0#u64 ∨ L.mem s1 (epTSA ptr) &&& 3#u64 = 1#u64 + rw [m1]; exact hst2 + · rintro ⟨s2, a2⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + exact ⟨hh.1, P1.FootN.trans hG hh.2⟩ + +set_option maxHeartbeats 4000000 in +/-- (gen 42b78, ruling 23:24Z item 1) **The MCS preemption point from any hole is an `IpcFootN ∅ True` step at +`OmegaB` and the IPC-buffer words, on any endpoint state** (module docstring): `JHole.mcsTmoG` at +`G := IpcFootN … (OmegaB H Z σ0) … (BufU Z σ0)`, the fault by `handle_timeout_ipcN` at `OmegaB` (`BXI.reΩ` there +and back, as XTopJointKEntryFF's `JAtZ.bxiU`); no `TmoBlk`. -/ +theorem JHole.mcsIpcN {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hcs : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → + xt.tcbSchedContext = some σ.curSc ∨ xt.tcbSchedContext = none) + (hsw : σ.schedulerAction ≠ .switchThread σ.curThread) + (htm : Fl4Spec.schedulable σ.curThread σ = true → NoTmoSend σ ∨ + (σ.curThread ≠ σ.idleThread ∧ (∀ d p, σ.curThread ∉ σ.readyQueues d p))) : + syscall.mcs_preemption_point st arI s a ⦃ s' _ => P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs (OmegaB H Z σ0) + (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) (BufU Z σ0) s s' ⦄ := by + have J := Hh.j0 + refine Hh.mcsTmoG hAT hcs hsw (G := fun s' => P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs (OmegaB H Z σ0) + (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) (BufU Z σ0) s s') + (fun _ _ h1 h2 => P1.IpcFootN.trans h1 (P1.FootN.ipc h2)) (P1.IpcFootN.refl s) htm ?_ + rintro ⟨hni, hnq⟩ s' a' f hB' hw hG fldY xt p bd r ptr cv hkt hth hpb hpE hcv ⟨bdg, sd, rv, g, gr, rfl⟩ kc hcb + have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE + have k1 : L.ksb s' = L.ksb s0 := hw.1.trans Hh.ws.1 + obtain ⟨Tr, Cq, hJ⟩ := J.jpl + have hTZ : ∀ y ∈ P1.Heap.tcbs H, y ∈ Z.T := fun y hy => J.thT y ((hJ.tcb y).2 hy) + -- the base's IPC-buffer facts at `s'`: the base's `KFoot` and `ChgW` keep every buffer-lookup word + have hS0 := J.xtop.fin.1.1.1 + have hfr : P1.IbFr (L := L) (P1.Heap.tcbs H) s0 s' := by + refine ⟨k1, fun y hy => ?_⟩ + obtain ⟨⟨Q0, R0, q0⟩, -⟩ := id Hh.blk + have hya := q0.tcbs y hy + have kw : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → ¬ SOff K → + L.mem s' (core.num.U64.wrapping_add y K) = L.mem s0 (core.num.U64.wrapping_add y K) := fun K hK hK8 hKs => + (fldY y hy K hK hK8).trans (Hh.ws.mem_eq (P1.field_aligned hya hK hK8) + fun hb => KFoot.ne_tcbw hS0 hb (hTZ y hy) hK hKs rfl) + refine ⟨kw 3512#u64 (by simp) (by simp) (by simp [SOff]), ?_, ?_⟩ + · rw [P1.sbWordA_eq]; exact kw 64#u64 (by simp) (by simp) (by simp [SOff]) + · rw [P1.sbWordA8_eq]; exact kw 72#u64 (by simp) (by simp) (by simp [SOff]) + have hBA : P1.BufAt st (P1.Heap.tcbs H) Cs H (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (BufU Z σ0) s' := + J.bufAtJ.of_fr hfr + -- the key-space block is no buffer word (`KsApart.buf`, as `JAtZ.bxiU`) + have hksU : ∀ {s1 : S}, L.ksb s1 = L.ksb s0 → ∀ o : U64, o.val < 13568 → + core.num.U64.wrapping_add (L.ksb s1) o ∉ BufU Z σ0 := fun {s1} e o h1 hu => by + obtain ⟨wp, hwp, e'⟩ := J.bufU_B hu + have h0 := J.ks.buf wp hwp + have hv : (core.num.U64.wrapping_add (L.ksb s1) o).val = (L.ksb s0).val + o.val := by + have := J.kern.ksbFit + rw [e]; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega + rw [e', hv] at h0; omega + -- `BXI` and `UserOK` at `OmegaB` + have hB1 := P1.BXI.reΩ hB' (Ω' := OmegaB H Z σ0) (V := ∅) (fun _ ha => Or.inl ha.1) (fun _ ha => ha.elim) + (fun b hb => ⟨P1.Heap.frame_omega hb, fun hu => (J.bufU_rbuf hu).2.2 hb⟩) + (fun o h1 h2 => ⟨hB'.2.2.2.1.ksΩ o h1 h2, hksU k1 o h1⟩) + have hU1 : P1.UserOK st (P1.Heap.tcbs H) Cs (OmegaB H Z σ0) H (BufU Z σ0) s' := fun b hb => + ⟨(J.bufU_rbuf hb).1.ksb k1, fun h => h.2 hb, (J.bufU_rbuf hb).2.1⟩ + refine WP.spec_mono (handle_timeout_ipcN hAT s' a' (L.curW s') f ⟨hB1.1, hB1.2.1, hB1.2.2.1, hB1.2.2.2.2, hB1.2.2.2.1⟩ + hU1 hBA (hcb hni hnq) hcv fun p' b' x' y' g' gr' e => by cases e; exact hHe) ?_ + rintro ⟨s2, a2⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨h2, F2⟩ := hh + have k2 : L.ksb s2 = L.ksb s' := F2.1 + -- `BXI` back at the hole's word set + refine ⟨P1.BXI.reΩ ⟨h2.1, h2.2.1, h2.2.2.1, h2.2.2.2.2, h2.2.2.2.1⟩ (V := BufU Z σ0) + (fun b hb => by by_cases hu : b ∈ BufU Z σ0; exacts [Or.inr hu, Or.inl ⟨hb, hu⟩]) + (fun b hb => ⟨(J.bufU_rbuf hb).1.ksb (k2.trans k1), (J.bufU_rbuf hb).2.1⟩) + (fun b hb => P1.Heap.frame_omega hb) (fun o h1 h3 => by rw [k2]; exact hB'.2.2.2.1.ksΩ o h1 h3), + P1.IpcFootN.trans hG F2⟩ + +/-- (ruling 18:47Z item 1) **The MCS preemption point from a hole under `PPCov ∨ PPCovT` is a `FootN ∅ True` +step** (module docstring). (gen 42b75) `JHole.mcsFootNG`'s corollary, statement unchanged. -/ +theorem JHole.mcsFootN {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hcov : PPCov σ ∨ PPCovT σ) : + syscall.mcs_preemption_point st arI s a ⦃ s' _ => P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s' ⦄ := by + have hC : CurInv σ := by rcases hcov with ⟨h, -⟩ | ⟨h, -⟩ <;> exact h + have hcs : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → + xt.tcbSchedContext = some σ.curSc ∨ xt.tcbSchedContext = none := fun xt hk => by + obtain ⟨x, hkx, hxs, -⟩ := hC.tcb + rw [hk] at hkx; cases hkx; exact Or.inl hxs + rcases hcov with ⟨-, -, hsw, hnt⟩ | ⟨-, hni, hres, hnq, -, xt', p', bd', r', hkt', -, hth', hcb'⟩ + · exact Hh.mcsFootNG hAT hcs hsw fun _ => Or.inl hnt + · refine Hh.mcsFootNG hAT hcs (by rw [hres]; exact fun h => by cases h) fun _ => Or.inr ⟨hni, hnq, ?_⟩ + intro xt p bd r hk hth xe hke + rw [hkt'] at hk; cases hk + rw [hth'] at hth; cases hth + exact hcb' xe hke + +set_option maxHeartbeats 4000000 in +/-- (gen 42b75, ruling 19:49Z item 2) **The MCS part of the preemption path from any hole, with its footprint** +(gen 42b79: the current thread not `runningVM` where a timeout fault is raisable, `hnv`, in place of `¬ PPRest`) (module docstring): the hole cases of P3/XTopJointMRHole's `hPre_ofZQIMN` (`PPCov ∨ PPCovT`, +`PPCovI`, schedulable with sufficient budget, schedulable with insufficient budget and a blocking timeout fault, not +schedulable under `CurInv`, no `CurInv`), each through its `ppG` form (XTopJointMRPath2/3/4's `…MG`) over any last +step, beside the `FootN ∅ True` footprint (`JHole.mcsFootNG`; FL4's state kept for sufficient budget). (gen 42b78, +ruling 23:24Z item 1) Also from the receiving-endpoint holes (`PPRecv`: XTopJointMRPath4's `mcsPPJRMG` beside +`JHole.mcsIpcN`, with the platform's `ticks_to_us` / `maxTicksToUs` asked there only, `hTU`); the footprint is +`IpcFootN ∅ True` at `OmegaB` and the IPC-buffer words (`FootN.ipc` on the other cases). -/ +theorem JHole.mcsPPVF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) + (hni : σ.curThread ≠ σ.idleThread) (hns : Vs.NoSwitch σ) (hfr : CurScFree σ) (hct : CtOK σ) (hcg : Chg σ) + (hnq : CtNQ σ) (hnv : ¬ Sched.NoTmoSend σ → ¬ RunningVM σ) + (hTU : PPRecv σ → Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv ∧ + ∀ (a : A) v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + syscall.mcs_preemption_point st arI s a ⦃ r => (∃ σ', + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ')) ∧ + P1.IpcFootN st ∅ True (P1.Heap.tcbs H) Cs (OmegaB H Z σ0) (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) (BufU Z σ0) s r.1 ⦄ := by + have hcs : ∀ xt, σ.kheap σ.curThread = some (.tcb xt) → + xt.tcbSchedContext = some σ.curSc ∨ xt.tcbSchedContext = none := fun xt hk => (hct xt hk).1 + have hsw : σ.schedulerAction ≠ .switchThread σ.curThread := hns σ.curThread + -- the cases whose timeout fault is not asked: FL4's footprint by `mcsFootNG` with `htm` vacuous + have hnsF : Fl4Spec.schedulable σ.curThread σ = false → + syscall.mcs_preemption_point st arI s a ⦃ s' _ => P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) + (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s' ⦄ := fun hf => + Hh.mcsFootNG hAT hcs hsw fun ht => absurd (hf.symm.trans ht) (by simp) + by_cases hc : PPCov σ ∨ PPCovT σ + · refine WP.spec_mono (WP.spec_and (Hh.mcsPPJZMG hT hAT hnd hmrt hmb hc hM hK hR hV) (Hh.mcsFootN hAT hc)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, P1.FootN.ipc h2⟩ + by_cases hi : PPCovI σ + · refine WP.spec_mono (WP.spec_and (Hh.mcsPPJIMG hi hAT hM hK hR hV) (hnsF hi.1)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, P1.FootN.ipc h2⟩ + by_cases hC : CurInv σ + · cases hsc : Fl4Spec.schedulable σ.curThread σ with + | true => + by_cases hsuf : ∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → + Fl4Spec.refillSufficient σ.consumedTime (Fl4Spec.refillHd y) = true + · refine WP.spec_mono (Hh.mcsPPJSMG hT hAT hnd hmb hC hni hsc hsuf hM hK hR hV) ?_ + rintro ⟨s2, a2⟩ ⟨σ', h1, hJ, hR', hV', hN, he⟩ + simp only at he + subst he + exact ⟨⟨σ', h1, hJ, hR', hV', hN⟩, P1.IpcFootN.refl _⟩ + · -- insufficient budget: a timeout fault to an endpoint (`runningVM` excluded: `hnv`) + have hnt0 : ¬ NoTmoSend σ := fun h => hc (Or.inl ⟨hC, hni, hsw, h⟩) + have hnt := hnt0 + unfold NoTmoSend at hnt + simp only [not_or, not_forall] at hnt + obtain ⟨⟨xt, hkt, hep⟩, ⟨x0, n0, hk0, hp0⟩⟩ := hnt + have hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0 := by + intro x n hk; rw [hk0] at hk; cases hk; exact hp0 + obtain ⟨p, bd, r, hth⟩ : ∃ p bd r, xt.tcbTimeoutHandler = .endpointCap p bd r := by + revert hep; cases xt.tcbTimeoutHandler <;> simp [Fl4Spec.isEpCap] + have hrr : xt.tcbState = .running ∨ xt.tcbState = .restart := by + obtain ⟨x1, -, -, -, hk1, -, hr1, -, -, -⟩ := schedulable_inv hsc + rw [hkt] at hk1; cases hk1 + by_cases hvm : xt.tcbState = .runningVM + · exact absurd ⟨xt, hkt, hvm⟩ (hnv hnt0) + · revert hr1 hvm; cases xt.tcbState <;> simp [Fl4Spec.runnable] + have hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread := by + rcases e : σ.schedulerAction with _ | u | _ + · exact Or.inl rfl + · exact absurd e (hns u) + · exact Or.inr rfl + have hvm : xt.tcbState ≠ .runningVM := by rcases hrr with e | e <;> rw [e] <;> exact fun h => by cases h + by_cases htb : TmoBlk σ + swap + · -- a receiving endpoint (`PPRecv`) + obtain ⟨hmax, htu⟩ := hTU ⟨hC, hsc, hsuf, hnt0, xt, hkt, hvm, htb⟩ + have hkl : ∃ l, σ.kheap p = some (.endpoint (.recvEP l)) := by + unfold TmoBlk at htb + simp only [not_forall] at htb + obtain ⟨xt', p', bd', r', hk', hth', xe, hke, hcbe⟩ := htb + rw [hkt] at hk'; cases hk' + rw [hth] at hth'; cases hth' + cases xe with + | recvEP l => exact ⟨l, hke⟩ + | _ => exact absurd (by simp [Endp.CanBlock]) hcbe + refine WP.spec_mono (WP.spec_and (Hh.mcsPPJRMG hAT hmax htu hmrt hmb hC hni hres hnq hsc hsuf hkt hrr hth + hper hkl hM hK hR hV) (Hh.mcsIpcN hAT hcs hsw fun _ => Or.inr ⟨hni, hnq⟩)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, h2⟩ + have hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe := htb xt p bd r hkt hth + refine WP.spec_mono (WP.spec_and (Hh.mcsPPJAMG hAT hmrt hmb hC hni hres hnq hsc hsuf hkt hrr hth hper hcb + hM hK hR hV) (Hh.mcsFootNG hAT hcs hsw fun _ => Or.inr ⟨hni, hnq, htb⟩)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, P1.FootN.ipc h2⟩ + | false => + refine WP.spec_mono (WP.spec_and (Hh.mcsPPJCMG hAT hmrt hmb hC hni hns hsc hM hK hR hV) (hnsF hsc)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, P1.FootN.ipc h2⟩ + · have hsch : Fl4Spec.schedulable σ.curThread σ = false := by + cases e : Fl4Spec.schedulable σ.curThread σ with + | false => rfl + | true => exact absurd (curInv_of_sched hct e) hC + refine WP.spec_mono (WP.spec_and (Hh.mcsPPJUMG hAT hmrt hmb hC hct hfr hcg hsch hi hM hK hR hV) (hnsF hsch)) ?_ + rintro ⟨s2, a2⟩ ⟨h1, h2⟩ + try simp only [WP.uncurry'_pair] at h2 + exact ⟨h1, P1.FootN.ipc h2⟩ + +set_option maxHeartbeats 4000000 in +/-- (gen 42b75, ruling 19:49Z items 1–2) **The preemption path at `VmEptState` against `preemptionPathVF`, `VmOrc` +kept, from every hole** (module docstring; gen 42b79: `hnv` in place of `¬ PPRest`, P3/VmPerfRvm's `perfCtNVmVF`): the hole by XTopJointMRPP's `JAtZB.ppJHM` (its spec facts +from `VmEptPre`'s `PPR0` / `NoSwitch`, as XTopJointMRHole's `jAtPreMV_holeQ`), the MCS part by `JHole.mcsPPVF`, +`VmEptState.ofNat` along the native footprint, `VmOrc` by `FootN.vmOrc`, the IRQ take and P3/VmOracle's +`VmEptState.handleIrqVFk` with its signal's `MR` fact from `MachPlat` / `MRKeep` (`msig_sendSignalVF`). -/ +theorem VmEptPre.preemptPathVFk (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hAK : ARKeep arI AR) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hPA : PPPlatA arI AR) (hIA : IrqPlatA arI AR) + (hmrt : ∀ a : A, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + {V X : Set U64} {XL : U64 → Nat} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (h : VmEptPre (L := L) arI V X XL AR MR s a σ) (hnv : ¬ Sched.NoTmoSend σ → ¬ RunningVM σ) + (hTU : PPRecv σ → Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv ∧ + ∀ (a : A) v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) (e : error.Exc) : + syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ + ∃ z ∈ (Fl4Spec.preemptionPathVF (Z := Unit) on rc σ).1, + (∃ (Z' : XSets) (H' : P1.Heap) (Cs' Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR Z' H' Cs' Ac' Lst' D' r.2.1 r.2.2 z.2) ∧ + VmOrc st on rc r.2.1 z.2 ∧ MR r.2.2 z.2.machineState ⦄ := by + obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, ⟨J, -, hns0, hp00, hR0, hV0, hI0⟩, hpp, hσ⟩ := h + have hw := J.1.1.ppJHM hAK hAT hnd hM hPA hR0 hV0 + rw [hpp, WP.spec_ok] at hw + obtain ⟨s1, Ac1, Lst1, Hh, -, F01, hR, -⟩ := hw rfl σ hσ + have hE := Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ0.machineState)) + have eσ : σ = _ := pp_err_eq hE (doMachineOp_single (getActiveIRQ_eq true _)) _ hσ rfl + have hTs : TShift σ0 σ := by rw [eσ]; exact ⟨vmt_le_gct hV0, rfl⟩ + have hVI : ValidIrqMasks σ := by rw [eσ]; exact fun i hi => hI0 i hi + -- the hole's spec facts (`jAtPreMV_holeQ`) + have hfr0 : CurScFree σ0 := curScFree_of J.1.1.inv J.1.1.own hp00 + have hni : σ.curThread ≠ σ.idleThread := by rw [eσ]; exact hp00.1.1 + have hns : Vs.NoSwitch σ := by rw [eσ]; exact hns0 + have hfr : CurScFree σ := by rw [eσ]; exact fun u xt hu hs => hfr0 u xt hu hs + have hct : CtOK σ := by rw [eσ]; exact hp00.1.2.2.1 + have hcg : Chg σ := by rw [eσ]; exact hp00.1.2.2.2.1 + have hnq : CtNQ σ := by rw [eσ]; exact hp00.1.2.2.2.2 + obtain ⟨⟨Qh, Rh, h0⟩, -⟩ := Hh.blk + unfold syscall.after_invocation + refine WP.spec_bind (Hh.mcsPPVF hTs hAT hnd (hmrt a) (hPA.minBudget a) hM hMK hR hVI hni hns hfr hct hcg hnq + hnv hTU) ?_ + rintro ⟨s2, a2⟩ ⟨⟨σ', hpp', ⟨V1, Ac2, Lst2, D2, B2, F12⟩, hR2, hVI2, -⟩, F⟩ + have J2 := J.ofNat B2 (J.1.1.natTrans F01 F12) + have hO2 : VmOrc st on rc s2 σ' := IpcFootN.vmOrc h0 hO F + (fun t y' hk' hr' => by + obtain ⟨y, hy, hry⟩ := ZvK.rvm F12.fk.1 t y' hk' hr' + exact ⟨y, by rw [Hh.sfacts.2.2.2.2.1]; exact hy, hry⟩) + (fun t y' hk' => by + obtain ⟨u, hu, rfl⟩ := B2.obj.tcb t y' hk' + exact ⟨u, J.1.1.zH.1 u hu, rfl⟩) + have hm : ∀ y, y ∈ (Fl4Spec.maybeHandleInterruptVF (Z := Unit) on rc true σ').1 → + y ∈ (Fl4Spec.preemptionPathVF (Z := Unit) on rc σ).1 := by + rw [preemptionPathVF_ppG]; exact (hpp' _).1 + -- the IRQ take and the handler (P3/XTopJointMRPath's `JAtZB.irqTailB` at `VmEptState`) + have hAR2 : AR a2 σ'.archState.x64CurrentCr3 := B2.xtop.fin.1.1.2.2.2.2.2.2 + refine WP.spec_bind (WP.spec_and (WP.spec_and (hM.takeAt hR2) (hIA.takeAR a2 _ hAR2)) (hM.noIpi a2 _ hR2)) ?_ + rintro ⟨w, a3⟩ ⟨⟨⟨irq, ms, hIq, hnone, hsome, hum, hR3⟩, hAR3⟩, h126, h127⟩ + obtain ⟨Lst3, B3, F3⟩ := B2.msArJ ms a3 hum (fun _ => hAR3) + have J3 := J2.ofNat (V' := V1) B3 F3 + unfold syscall.check_interrupt + by_cases hw : w = syscall.NO_IRQ + · have hirq : irq = none := hnone.1 hw + subst hirq + have e : (w != syscall.NO_IRQ) = false := by simp [hw] + show (do + let (s4, a4) ← (if (w != syscall.NO_IRQ) = true then interrupt.handle_interrupt st arI s2 a3 w else ok (s2, a3)) + ok (false, s4, a4)) ⦃ _ ⦄ + rw [e] + simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] + exact (WP.spec_ok _).2 ⟨rfl, ((), { σ' with machineState := ms }), hm _ (mem_maybeHandleVF_none hIq), + ⟨_, _, _, _, _, _, J3⟩, hO2, hR3⟩ + · obtain ⟨i, rfl⟩ : ∃ i, irq = some i := by + cases irq with + | none => exact absurd (hnone.2 rfl) hw + | some i => exact ⟨i, rfl⟩ + obtain ⟨hwi, -⟩ := hsome i rfl + have e : (w != syscall.NO_IRQ) = true := by simpa using hw + show (do + let (s4, a4) ← (if (w != syscall.NO_IRQ) = true then interrupt.handle_interrupt st arI s2 a3 w else ok (s2, a3)) + ok (false, s4, a4)) ⦃ _ ⦄ + rw [e] + simp only [↓reduceIte] + have hw256 : w.val < 256 := by rw [hwi]; exact i.isLt + have hwb : w.bv.setWidth 8 = i := setWidth8_eq hwi + refine WP.spec_bind (J3.handleIrqVFk hARI hAT hVA hAK hPA.minBudget (on := on) (rc := rc) hO2 hR3 w i hwi h126 + h127 (fun a1 c h => hIA.ackAR a1 w c h) (fun a0 a1 σ0 h0 he => ?_) (fun a1 ms h => hM.ack a1 w ms h) + (msig_sendSignalVF hAT hM hMK on rc)) ?_ + · have hmk := hM.mask a0 w true σ0.machineState h0 hw256 + rw [he, WP.spec_ok, hwb] at hmk + exact hmk + rintro ⟨s4, a4⟩ (⟨hin, -⟩ | ⟨z, hz, ⟨⟨V', Ac', Lst', D', J4⟩, O4⟩, hR4⟩) + · exact absurd hin (gai_active hVI2 hIq i rfl) + · exact (WP.spec_ok _).2 ⟨rfl, z, hm _ (mem_maybeHandleVF_some hIq hz), ⟨_, _, _, _, _, _, J4⟩, O4, hR4⟩ + +/-- (ruling 18:47Z item 2) **The preemption path at `VmEptState` against `preemptionPathVF`** (module docstring). +(gen 42b75) `VmEptPre.preemptPathVFk`'s corollary (`PPCov ∨ PPCovT` give `hnv`; `hMsig` no longer +read), statement unchanged. -/ +theorem VmEptPre.preemptPathVF (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) + (hAK : ARKeep arI AR) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hMK : MRKeep arI MR) + (hPA : PPPlatA arI AR) (hIA : IrqPlatA arI AR) + (hmrt : ∀ a : A, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + {V X : Set U64} {XL : U64 → Nat} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (h : VmEptPre (L := L) arI V X XL AR MR s a σ) (hcov : PPCov σ ∨ PPCovT σ) + {on rc : Fl4Spec.ObjRef → Bool} (hO : VmOrc st on rc s σ) + (hMsig : ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (Fl4Spec.sendSignalVF (Z := Unit) on rc n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄) + (e : error.Exc) : + syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ + ∃ z ∈ (Fl4Spec.preemptionPathVF (Z := Unit) on rc σ).1, + (∃ (Z' : XSets) (H' : P1.Heap) (Cs' Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR Z' H' Cs' Ac' Lst' D' r.2.1 r.2.2 z.2) ∧ MR r.2.2 z.2.machineState ⦄ := by + have hnv : ¬ Sched.NoTmoSend σ → ¬ RunningVM σ := by + rintro hnt ⟨xt, hk, hx⟩ + rcases hcov with ⟨-, -, -, h⟩ | ⟨-, -, -, -, -, xt', p', bd', r', hkt', hrr, hth', hcb'⟩ + · exact hnt h + · rw [hkt'] at hk; cases hk + rcases hrr with e | e <;> rw [e] at hx <;> cases hx + have hnr : ¬ PPRecv σ := by + rintro ⟨-, -, -, hnt, xt, hk, -, hx⟩ + rcases hcov with ⟨-, -, -, h⟩ | ⟨-, -, -, -, -, xt', p', bd', r', hkt', hrr, hth', hcb'⟩ + · exact hnt h + · refine hx fun xt p bd r hk hth xe hke => ?_ + rw [hkt'] at hk; cases hk + rw [hth'] at hth; cases hth + exact hcb' xe hke + exact WP.spec_mono (h.preemptPathVFk hARI hAT hVA hAK hnd hM hMK hPA hIA hmrt hnv (fun h => (hnr h).elim) hO e) + fun _ ⟨h1, z, hz, hJ, _, hm⟩ => ⟨h1, z, hz, hJ, hm⟩ + +end + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {V X : Set U64} {XL : U64 → Nat} + +set_option maxHeartbeats 4000000 in +/-- (ruling 18:47Z item 3) **FL4's TCB timers at `VmEptState` against `fl4AwakenVF`** (module docstring): the +outcome is `fl4AwakenVF on rc`'s, `VmEptState` (fresh VSpace sets) and `VmOrc` after. -/ +theorem VmEptState.fireVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {on rc : Fl4Spec.ObjRef → Bool} + {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hO : VmOrc st on rc s σ) : + timer.fire st arI s a ⦃ r => ∃ σ1 : Fl4Spec.State Unit, ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1 ∧ + σ1.domainTime = σ.domainTime ∧ VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc r.1 r.2 σ1 ⦄ := by + unfold timer.fire + refine WP.spec_bind (L.cur_cpu_spec s) fun c _ => ?_ + refine WP.spec_bind (P1.obj.node_get.spec s c _) fun now _ => ?_ + exact WP.spec_mono (VmEptState.fire_loopVF (V := V) (X := X) (XL := XL) (Z := Z) (H := H) (Cs := Cs) (AR := AR) + hAT hVA hK hmb s a now 0#u64 ⟨σ, Relation.ReflTransGen.refl, rfl, Z.vs, Ac, Lst, D, J, hO⟩) + fun _ ⟨σ1, h1, h2, hP⟩ => ⟨σ1, h1, h2, hP⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmSchedule.lean b/proofs/Fl4Proofs/P3/VmSchedule.lean new file mode 100644 index 000000000..3abff01d3 --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmSchedule.lean @@ -0,0 +1,539 @@ +/- +P3 (line mmuAD, gen 42b76, the Architect's ruling 20:50Z item 2): **`sched.awaken` and `schedule` at `VmEptState` +against the extended spec's TCB timers (`fl4AwakenVF`)**. + +The native scheduler chain is stated over a fire relation `F` (in place, gen 42b76: ScAwaken `awaken_refinesW`, +ScScheduleTop `schedule_refinesWP` / `schedule_refinesW`, ScNextDomC `awaken_refinesW0` / `schedule_refinesWP0`, +ScNextDomCFR `awaken_refinesW0R`, G7eChain `schedule_refinesWP0FRA`, JAtZBSchedR **`JAtZB.jat_scheduleFRG`**, whose +`F := Fires` instance is `jat_scheduleFR`), so the TCB timers enter as `VmEptState.fireVF` (P3/VmPreempt). + +* **`VmEptState.awakenVF`**: FL4's `sched.awaken` from `VmEptState ∧ VmOrc`: the timers are an outcome of + `fl4AwakenVF on rc`, then the spec's `awaken`, with `VmOrc` kept across the release-queue loop (P2/FootN6 + `awaken_loop.kwN`, a `FootN ∅ True` step, and `FootN.vmOrc`; the spec heap is kept, `Calm`) and the timers' + outcome `VmFireP`. +* **`VmEptState.scheduleVF`**: FL4's `schedule` from `VmEptState ∧ VmOrc`: some `fl4AwakenVF on rc` outcome `σ1`, + `Fl4Spec.schedule σ1 = {σ'}`, `VmEptState` (fresh VSpace sets), `CurInv` and `CurRunW` at `σ'`. The scheduler's + native writes after the timers are in `KFootN` and its spec step a `SchStep` without thread-state change, + so `VmEptState.ofNat` keeps the VCPU and EPT records. + +(gen 42b80, the Architect's ruling 01:07Z item 3) **The scheduler tail discharged**: +* `Vs.owk_sendSignalVF` / `Vs.crk_sendSignalVF` (with the `OWK` / `CRK` leaves `lookupIpcBuffer`, `zipWithMx`, + `storeWordOffs`, `setMrs`), `Vs.fk_fl4AwakenVF` (a field every `sendSignalVF` keeps is kept along + `fl4AwakenVF`), `Vs.owF_awakenVF`, `Vs.crF_awakenVF`, `Vs.awakenVF_dom` (FPU owner, CR3 / ASID table / global PML4 + / idle thread, domain fields kept by the extended timers). +* The `JAtZB` helpers, each the native core at `JAtZB`'s fields (the `JAtZR` names are 1-line corollaries of the + same cores): `JAtZB.vsRootOK` (`vsRootOK_ofJ`), `JAtZB.rootFr` (`rootFr_of`), `JAtZB.fire_ks` (`JKern.fire_ks`), + `JAtZB.ndOK_awakenVF` (`JKern.ndOK_fire`), `JAtZB.fpuOwnOK_awakenVF` (`fpuOwnOK_of_own`), `JAtZB.idleVt_awakenVF` + (`idleVt_ofSlots`). +* **`kfin_tail_ofB`**: native `kfin_tail_of` at `JAtZB` and `fl4AwakenVF` (its step `SInvR.G5.kfin_tail_at`), in the + form of `JAtZB.jat_scheduleFRG`'s `hTail` (which now receives FL4's timers' outcome, `JAtZB` and `Pf` there). + `scheduleVF` no longer takes `hTail`. + +(gen 42b83) **`JAtZB.jat_scheduleFRGF`** uses `schedule_refinesWP0FRA` for the schedule outcome and CR3. +It applies the joint scheduler tail from the state normalized by `ndF` and returns the native footprint from the +actual timer outcome, including the domain words. The VSpace-root cap fact follows from `JPlaced` and `VsSlotsW`. +`scheduleVF` uses the native domain disjunction, `ArchRefines` [P], `ArchSwF` [P], `ArchNdF` [P], `FpuOwnOK σ` [J], `IdleVt σ` [J], +`SniHyp`, `SendHyp`, `TimeAgree` and `fireVF`'s platform facts. +-/ +import Fl4Proofs.P3.VmPreempt +import Fl4Proofs.P3.JAtZBSchedR +import Fl4Proofs.P3.XTopJointSchedRF3 +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3.Vs +open Fl4Spec Classical + +noncomputable section + +/-! (gen 42b80) The FPU owner, domain index and `crF` (CR3, ASID table, global PML4, idle thread, platform record) +kept by the extended spec's TCB timers: `sendSignalVF`'s VMEnter report as `OWK` / `CRK` leaves. -/ + +theorem owk_lookupIpcBuffer' (b : Bool) (t : ObjRef) : OWK (lookupIpcBuffer (Z := Unit) b t) := by + unfold lookupIpcBuffer; owk_auto +macro_rules | `(tactic| owk_leaf) => `(tactic| with_reducible exact owk_lookupIpcBuffer' _ _) + +theorem owk_zipWithMx' {α β γ : Type} {g : α → β → NonDet (State Unit) γ} (h : ∀ a b, OWK (g a b)) : + ∀ l1 l2, OWK (NonDet.zipWithMx g l1 l2) + | a :: l1, b :: l2 => dk_bind (h a b) (fun _ => owk_zipWithMx' h l1 l2) + | [], _ => dk_pure' _ + | _ :: _, [] => dk_pure' _ +macro_rules | `(tactic| owk_leaf) => `(tactic| with_reducible refine owk_zipWithMx' (fun _ _ => ?_) _ _) + +theorem owk_storeWordOffs' (p : ObjRef) (o : Nat) (v : Word) : OWK (storeWordOffs (Z := Unit) p o v) := by + unfold storeWordOffs; owk_auto +macro_rules | `(tactic| owk_leaf) => `(tactic| with_reducible exact owk_storeWordOffs' _ _ _) + +theorem owk_setMrs' (t : ObjRef) (b : Option ObjRef) (m : List Message) : OWK (setMrs (Z := Unit) t b m) := by + unfold setMrs; owk_auto +macro_rules | `(tactic| owk_leaf) => `(tactic| with_reducible exact owk_setMrs' _ _ _) + +/-- **`sendSignalVF` keeps the FPU owner and the domain index.** -/ +theorem owk_sendSignalVF (on rc : ObjRef → Bool) (n : ObjRef) (b : Badge) : + OWK (sendSignalVF (Z := Unit) on rc n b) := by + unfold sendSignalVF vmSignalCompletes vmReportF vcpuUpdate setVcpu getTcbVcpu vmFullReply vmFaultIpNext getVcpu + try unfold getScActive + owk_auto + all_goals exact owk_sendSignal _ _ + +theorem crk_lookupIpcBuffer' (b : Bool) (t : ObjRef) : CRK (lookupIpcBuffer (Z := Unit) b t) := by + unfold lookupIpcBuffer; crk_auto +macro_rules | `(tactic| crk_leaf) => `(tactic| with_reducible exact crk_lookupIpcBuffer' _ _) + +theorem crk_zipWithMx' {α β γ : Type} {g : α → β → NonDet (State Unit) γ} (h : ∀ a b, CRK (g a b)) : + ∀ l1 l2, CRK (NonDet.zipWithMx g l1 l2) + | a :: l1, b :: l2 => dk_bind (h a b) (fun _ => crk_zipWithMx' h l1 l2) + | [], _ => dk_pure' _ + | _ :: _, [] => dk_pure' _ +macro_rules | `(tactic| crk_leaf) => `(tactic| with_reducible refine crk_zipWithMx' (fun _ _ => ?_) _ _) + +theorem crk_storeWordOffs' (p : ObjRef) (o : Nat) (v : Word) : CRK (storeWordOffs (Z := Unit) p o v) := by + unfold storeWordOffs; crk_auto +macro_rules | `(tactic| crk_leaf) => `(tactic| with_reducible exact crk_storeWordOffs' _ _ _) + +theorem crk_setMrs' (t : ObjRef) (b : Option ObjRef) (m : List Message) : CRK (setMrs (Z := Unit) t b m) := by + unfold setMrs; crk_auto +macro_rules | `(tactic| crk_leaf) => `(tactic| with_reducible exact crk_setMrs' _ _ _) + +/-- **`sendSignalVF` keeps `crF`.** -/ +theorem crk_sendSignalVF (on rc : ObjRef → Bool) (n : ObjRef) (b : Badge) : + CRK (sendSignalVF (Z := Unit) on rc n b) := by + unfold sendSignalVF vmSignalCompletes vmReportF vcpuUpdate setVcpu getTcbVcpu vmFullReply vmFaultIpNext getVcpu + try unfold getScActive + crk_auto + all_goals exact crk_sendSignal _ _ + +/-- **The extended spec's TCB timers keep any field every `sendSignalVF` keeps** (and `reprogramTimer` does not +read): induction along `fl4AwakenVF`'s `ReflTransGen`, as ScFpuOwnK's `owF_firesP` / G7cCr3K's `crF_fires`. -/ +theorem fk_fl4AwakenVF {β : Type} {f : State Unit → β} {on rc : ObjRef → Bool} + (hS : ∀ n b, FK f (sendSignalVF (Z := Unit) on rc n b)) + (hrt : ∀ σ : State Unit, f { σ with reprogramTimer := true } = f σ) + {σ σ1 : State Unit} (h : ((), σ1) ∈ (fl4AwakenVF (Z := Unit) on rc σ).1) : f σ1 = f σ := by + change Relation.ReflTransGen (fl4TimerFireVF (Z := Unit) on rc) σ σ1 at h + induction h with + | refl => rfl + | tail _ hf ih => + obtain ⟨σa, ho, rfl⟩ := hf + rw [hrt] + rcases ho with rfl | ⟨n, b, he⟩ + · exact ih + · exact (hS n b _ ((), σa) (by rw [he]; exact Set.mem_singleton _)).trans ih + +/-- `fl4AwakenVF` keeps the FPU owner and the domain index. -/ +theorem owF_awakenVF {on rc : ObjRef → Bool} {σ σ1 : State Unit} + (h : ((), σ1) ∈ (fl4AwakenVF (Z := Unit) on rc σ).1) : owF σ1 = owF σ := + fk_fl4AwakenVF (owk_sendSignalVF on rc) (fun _ => rfl) h + +/-- `fl4AwakenVF` keeps `crF`. -/ +theorem crF_awakenVF {on rc : ObjRef → Bool} {σ σ1 : State Unit} + (h : ((), σ1) ∈ (fl4AwakenVF (Z := Unit) on rc σ).1) : crF σ1 = crF σ := + fk_fl4AwakenVF (crk_sendSignalVF on rc) (fun _ => rfl) h + +/-- `fl4AwakenVF` keeps the domain schedule (`domain_list`, `domain_index`, `domain_start_index`; as ScFpuOwnK's +`fires_dom`). -/ +theorem awakenVF_dom {on rc : ObjRef → Bool} {σ σ1 : State Unit} + (h : ((), σ1) ∈ (fl4AwakenVF (Z := Unit) on rc σ).1) : + σ1.domainList = σ.domainList ∧ σ1.domainIndex = σ.domainIndex ∧ σ1.domainStartIndex = σ.domainStartIndex := by + have e := fk_fl4AwakenVF (f := schedF) (fun n b => dk_sendSignalVF on rc n b) (fun _ => rfl) h + simp only [schedF, Prod.mk.injEq] at e + exact ⟨e.1, congrArg Prod.snd (owF_awakenVF h), e.2.1⟩ + +end + +end Fl4Proofs.P3.Vs + +namespace Fl4Proofs.P3 +open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {V X : Set U64} {XL : U64 → Nat} + +/-! (gen 42b80) The `JAtZB` / `fl4AwakenVF` helper chain for the tail (G7eRoot / G7dVsRoot / XTopJointJAtZRB cores +at `JAtZB`'s fields). -/ + +/-- `VsRootOK` at a `JAtZB` state (`vsRootOK_ofJ`). -/ +theorem JAtZB.vsRootOK {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) : + VsRootOK Z.T σ := + vsRootOK_ofJ J.xtop J.jpl J.zH.1 J.vsc + +/-- `RootFr` at a `JAtZB` state, given `IdleVt` (`rootFr_of`). -/ +theorem JAtZB.rootFr {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hIV : IdleVt σ) : RootFr (L := L) AR Z.T Z.P Z.c s a σ := + rootFr_of J.xtop J.kern J.nk J.jpl J.zH.1 J.vsc hIV + +/-- FL4's timers keep the kernel-global words below 256 (`JKern.fire_ks`). -/ +theorem JAtZB.fire_ks {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {s1 : S} {U : Set U64} + (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) + (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) : + ∀ o : U64, o.val < 256 → o.val % 8 = 0 → L.mem s1 (ksW (L.ksb s) o) = L.mem s (ksW (L.ksb s) o) := + J.kern.fire_ks (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) hf hU + +/-- `NdOK` after FL4's timers, the spec's by `fl4AwakenVF` (`JKern.ndOK_fire`, the domain schedule by +`Vs.awakenVF_dom`). -/ +theorem JAtZB.ndOK_awakenVF {on rc : Fl4Spec.ObjRef → Bool} {s : S} {a : A} {σ σ1 : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hNd : NdOK (L := L) s σ) {s1 : S} {U : Set U64} + (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) + (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) + (hF : ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1) : NdOK (L := L) s1 σ1 := by + obtain ⟨hdl, hdi, hds⟩ := Vs.awakenVF_dom hF + exact J.kern.ndOK_fire (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) hNd hf hU hdl hdi hds + +/-- `FpuOwnOK` after `fl4AwakenVF` from `FpuOwnOK` before (`fpuOwnOK_of_own`, the owner by `Vs.owF_awakenVF`). -/ +theorem JAtZB.fpuOwnOK_awakenVF {on rc : Fl4Spec.ObjRef → Bool} {s : S} {a : A} {σ σ1 : Fl4Spec.State Unit} + {m : U64 → U64} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hF : ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1) (hN : NtfnStateRel Z.N Z.T m σ1) + (hfo : FpuOwnOK σ) : FpuOwnOK σ1 := + fpuOwnOK_of_own J.obj hN (congrArg Prod.fst (Vs.owF_awakenVF hF)) hfo + +set_option maxHeartbeats 2000000 in +/-- `IdleVt` after FL4's timers, the spec's by `fl4AwakenVF` (`idleVt_ofSlots`, the idle thread by +`Vs.crF_awakenVF`). -/ +theorem JAtZB.idleVt_awakenVF (hAT : P0.ArchTotal arI) {on rc : Fl4Spec.ObjRef → Bool} {s : S} {a : A} + {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hIV : IdleVt σ) {s1 : S} {a1 : A} + (hfr : timer.fire st arI s a = ok (s1, a1)) {σ1 : Fl4Spec.State Unit} + (hF : ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1) + {V1 : XVs} {Ac1 : Set U64} {Lst1 : U64 → List U64} {D1 : Set U64} + (J1 : JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 s1 a1 σ1) : IdleVt σ1 := by + obtain ⟨Tr, Cq, hJ⟩ := J.jpl + have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h + have hfk := spec_ok_post (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a J.blk J.bufAtJ) hfr + simp only [WP.uncurry'_pair] at hfk + obtain ⟨⟨Q', R', hq⟩, -⟩ := J.blk + exact idleVt_ofSlots J.xtop J.jpl J.zH.1 J1.xtop + (slotsSame_of_footDU J.xtop.rel.1 (hJ.kwOutBlk J.blk) hq.tcbs hq.nodes hfk J.bufU_noSlot) + (congrArg (fun q => q.2.2.2.1) (Vs.crF_awakenVF hF)) hIV + +set_option maxHeartbeats 4000000 in +/-- (ruling 01:07Z item 3) **The scheduler tail at a `JAtZB` state against `fl4AwakenVF`** (native G7eTail's +`kfin_tail_of`, at `JAtZB` and the extended spec's timers; module docstring): at FL4's actual timers' outcome +`rf` (related by `JAtZB` to an `fl4AwakenVF` outcome `σ1` with `schedule σ1 = {σ'}`), FL4's `schedule` loads a +CR3 `AR`-related to `σ'`'s (`SInvR.G5.kfin_tail_at`). Premises as native `KFinAtR8`: `hd`, `ArchSwF`, `ArchNdF`, +`IdleVt σ` [J] (INV-PLAN §1.U3L D7), and `FpuOwnOK σ`. -/ +theorem kfin_tail_ofB {on rc : Fl4Spec.ObjRef → Bool} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ) (hnd : Fl4Spec.numDomains = 1) + (hAT : P0.ArchTotal arI) (hK : ARKeep arI AR) (hRef : ArchRefines arI AR) + (hA : ArchSwF st arI Z.N Z.T Z.C Z.c) (hAN : ArchNdF st Z.N Z.T Z.C Z.c) + (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) + (hFO : FpuOwnOK σ) (hIV : IdleVt σ) {Pf : S × A → Fl4Spec.State Unit → Prop} : + sched.schedule st arI s a ⦃ r => ∀ (rf : S × A) σ1 σ' (D1 : Set U64), + ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1 → + timer.fire st arI s a = ok rf → + (∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D2 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D2 rf.1 rf.2 σ1) → Pf rf σ1 → + Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) → + P1.WritesIn st rf.1 r.1 (KFoot st Z.T Z.N Z.C Z.c rf.1 σ1) → + SchedRel st Z.N Z.T Z.C Z.c r.1 σ' → Inv σ' → CurInv σ' → ActIdle σ' → + SchTailHypsR AR Z H D1 r.1 r.2 σ' ⦄ := by + have hSt : P0.StoreTotal st := P1.LawfulStore.total + refine WP.spec_mono (P1.spec_eq' (Fl4Proofs.P0.sched.schedule.p0 st arI s a hSt hAT)) ?_ + rintro r ⟨hr, -⟩ ⟨s1, a1⟩ σ1 σ' D1 hF hfr ⟨V1, Ac1, Lst1, D2, J1⟩ - hsc - - - - - + have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h + have hfk := spec_ok_post (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a J.blk J.bufAtJ) hfr + simp only [WP.uncurry'_pair] at hfk + have hUk := fun b hb o ho h8 => (J.bufAtJ.1 b hb).ks o ho h8 + have hdt1 : σ1.domainTime ≠ 0 ∨ NdOK (L := L) s1 σ1 := + hd.imp (fun h => by rw [fire_dt J.xtop.fin.1.1.1 J1.xtop.fin.1.1.1 hfk.1 (J.fire_ks hfk hUk)]; exact h) + (fun h => J.ndOK_awakenVF h hfk hUk hF) + exact ⟨SInvR.G5.kfin_tail_at J.xtop.fin.1.1.1 J.xtop.fin.1.1.2.2.1 J.nsc hnd hAT hK hRef hA hAN hsni hsend hT + hr hfr hF hsc J1.xtop.fin.1.1.1 J1.xtop.fin.1.1.2.2.1 J1.nsc ⟨J1.inv, curInvR_of J1.cur, J1.off, J1.act, J1.own⟩ + hdt1 J1.nk (J.fpuOwnOK_awakenVF hF J1.xtop.fin.1.1.2.2.1 hFO) J1.vsRootOK + (J1.rootFr (J.idleVt_awakenVF hAT hIV hfr hF J1)) J1.xtop.fin.1.1.2.2.2.2.2.2⟩ + +set_option maxHeartbeats 4000000 in +/-- (ruling 20:50Z item 2) **FL4's `sched.awaken` at `VmEptState` against `fl4AwakenVF` and the spec's `awaken`** +(module docstring): `awaken_refinesW` at the timers of `fireVF`, `VmOrc` after the release-queue loop. -/ +theorem VmEptState.awakenVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {on rc : Fl4Spec.ObjRef → Bool} + {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hO : VmOrc st on rc s σ) (hd : σ.domainTime ≠ 0) : + sched.awaken st arI s a ⦃ r => ∃ σ1 σ2 : Fl4Spec.State Unit, ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1 ∧ + Fl4Spec.awaken (Z := Unit) σ1 = ({((), σ2)}, False) ∧ + SchedRel st Z.N Z.T Z.C Z.c r.1 σ2 ∧ NtfnStateRel Z.N Z.T (L.mem r.1) σ2 ∧ NSC Z.N Z.C σ2 ∧ + SchedPreW Z.T Z.C σ2 ∧ Calm σ1 σ2 ∧ VmOrc st on rc r.1 σ2 ∧ + ∃ rf : S × A, timer.fire st arI s a = ok rf ∧ r.2 = rf.2 ∧ + VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc rf.1 rf.2 σ1 ∧ + P1.WritesIn st rf.1 r.1 (SFoot st Z.T Z.c rf.1) ⦄ := by + have hF := P1.spec_eq' (VmEptState.fireVF hAT hVA hK hmb J hO) + -- the native release-queue loop is a `FootN ∅ True` step + have hN : sched.awaken st arI s a ⦃ r => ∃ rf : S × A, timer.fire st arI s a = ok rf ∧ + P1.FootN st ∅ True (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) + rf.1 r.1 ⦄ := by + unfold sched.awaken + refine WP.spec_bind hF ?_ + rintro ⟨s1, a1⟩ ⟨hf, σ1, -, -, V1, Ac1, Lst1, D1, J1, -⟩ + obtain ⟨⟨Q1, R1, h1⟩, hB1, -, -, hS1⟩ := J1.1.1.blk + refine WP.spec_bind (P1.sched.awaken_loop.kwN (Kp := (∅ : Set U64)) (Scs := P1.Heap.scs H) + (Z := P1.Heap.scBits H) s1 _ Q1 R1 h1 hB1 hS1 + (fun _ hy => absurd hy (Set.notMem_empty _)) (fun _ hy => absurd hy (Set.notMem_empty _))) ?_ + intro s2 F2 + rw [WP.spec_ok] + exact ⟨(s1, a1), hf, F2⟩ + have hfire : timer.fire st arI s a ⦃ r => ∃ σ1, ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1 ∧ + SchedRel st Z.N Z.T Z.C Z.c r.1 σ1 ∧ NtfnStateRel Z.N Z.T (L.mem r.1) σ1 ∧ NSC Z.N Z.C σ1 ∧ + SchedPreW Z.T Z.C σ1 ∧ (VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc r.1 r.2 σ1 ∧ + timer.fire st arI s a = ok r) ⦄ := by + refine WP.spec_mono hF ?_ + rintro r ⟨hf, σ1, h1, hd1, hP⟩ + obtain ⟨V1, Ac1, Lst1, D1, J1, -⟩ := id hP + have B1 := J1.1.1 + exact ⟨σ1, h1, B1.xtop.fin.1.1.1, B1.xtop.fin.1.1.2.2.1, B1.nsc, B1.schedPreW (by rw [hd1]; exact hd), hP, hf⟩ + refine WP.spec_mono (WP.spec_and (awaken_refinesW s a σ hfire) hN) ?_ + rintro r ⟨⟨σ1, σ2, h1, h2, hS2, hR2, hN2, hP2, hc2, -, -, -, rf, ⟨hP, hf⟩, hr2, hw⟩, rf', hf', F2⟩ + obtain rfl : rf = rf' := by rw [hf] at hf'; exact P1.ok_inj_ff hf' + obtain ⟨V1, Ac1, Lst1, D1, J1, hO1⟩ := id hP + have B1 := J1.1.1 + obtain ⟨⟨Q1, R1, h01⟩, -⟩ := B1.blk + have hk : σ2.kheap = σ1.kheap := hc2.1 + refine ⟨σ1, σ2, h1, h2, hS2, hR2, hN2, hP2, hc2, FootN.vmOrc h01 hO1 F2 + (fun t y' h hr => ⟨y', by rw [← hk]; exact h, hr⟩) + (fun t y' h => by + rw [hk] at h + obtain ⟨u, hu, rfl⟩ := B1.obj.tcb t y' h + exact ⟨u, B1.zH.1 u hu, rfl⟩), rf, hf, hr2, hP, hw⟩ + +private theorem NdW.val_bounds {kb b : U64} (h : NdW kb b) (hk : kb.val + 13568 ≤ 2 ^ 64) : + kb.val + 16 ≤ b.val ∧ b.val ≤ kb.val + 40 := by + rcases h with rfl | rfl | rfl + · rw [ksW_val (by change kb.val + 16 < 2 ^ 64; omega : kb.val + (16#u64 : U64).val < 2 ^ 64)]; simp <;> omega + · rw [ksW_val (by change kb.val + 24 < 2 ^ 64; omega : kb.val + (24#u64 : U64).val < 2 ^ 64)]; simp <;> omega + · rw [ksW_val (by change kb.val + 40 < 2 ^ 64; omega : kb.val + (40#u64 : U64).val < 2 ^ 64)]; simp <;> omega + +private theorem JAtZB.ndFBase (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (v16 v24 v40 : U64) (di : Nat) (h24 : v24 = 0#u64) : + ∃ (Ac0 : Set U64) (Lst0 : U64 → List U64) (D0 : Set U64), + JAtZB (L := L) arI AR Z H Cs Ac0 Lst0 D0 (ndF (L := L) s (L.ksb s) v16 v24 v40) a (ndFSt σ v16.bv di) := by + have hdom := schedStep_dom2 Z.th s σ v16 v24 di rfl J.kern.ksbFit J.kern.ksbAl h24 + obtain ⟨Ac1, Lst1, D1, J1⟩ := J.schedJ hdom + obtain ⟨Ac2, Lst2, J2, -⟩ := (J1.workUnitsJD_ws arI v40).2 + have e : core.num.U64.wrapping_add (L.ksb (ndF2 (L := L) s (L.ksb s) v16 v24)) layout.ks.WORK_UNITS = + ksW (L.ksb s) 40#u64 := by + simp only [ndF2, P1.LawfulStore.ksb_wr] + unfold layout.ks.WORK_UNITS + rfl + rw [e] at J2 + exact ⟨Ac2, Lst2, D1, J2⟩ + +private theorem JAtZB.ndFDbg (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (v16 v24 v40 : U64) : P1.DbgKeep st (P1.Heap.tcbs H) Cs + (ndF (L := L) s (L.ksb s) v16 v24 v40) s := by + have hks := ndF_ksb (L := L) s (L.ksb s) v16 v24 v40 + refine ⟨hks.symm, fun b hb => ?_⟩ + have hb' := P1.DbgW.ksb hks hb + refine (ndF_mem_ne s v16 v24 v40 J.kern.ksbFit J.kern.ksbAl (P1.dbgW_aligned J.blk hb') ?_).symm + intro hnd + have hval := hnd.val_bounds J.kern.ksbFit + exact J.notDbg' (fun p hp => by + obtain ⟨⟨_, _, hq⟩, -⟩ := J.blk + have hOut := hq.ksOut p hp + change b.val < p.val ∨ p.val + 4096 ≤ b.val + rcases hOut with h | h <;> omega) + (fun c _ => by + change b.val ≠ (L.ksb s).val + 13568 + c.val * 4288 + 88 + omega) hb' + +private theorem JAtZB.scheduleFootN (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {s' : S} {σ' : Fl4Spec.State Unit} + (hw : P1.WritesIn st s s' (KFootN st Z.T Z.N Z.C Z.c s σ)) + (hK : SchStep (fun _ => False) σ σ') : NatFoot (L := L) Z s σ s' σ' := by + have hS := J.xtop.fin.1.1.1 + have hb := fun b (h : NdW (L.ksb s) b) => h.val_bounds J.kern.ksbFit + refine NatFoot.ofW J.xtop hw (fun b h => ?_) (fun b h => ?_) (fun b h => ?_) + (natK_otk hK.kh fun _ h => h.elim) + · rcases h with h | h + · exact tfoot_oobj hS (Or.inl h) + · obtain ⟨hlo, hhi⟩ := hb b h + exact Or.inr (Or.inl ⟨by omega, by omega, Or.inl (by omega)⟩) + · rcases h with h | h + · exact tfoot_nv hS (Or.inl h) + · obtain ⟨hlo, hhi⟩ := hb b h + exact J.ks_nv (by omega) (by omega) + · rcases h with h | h + · exact J.tfoot_nh (Or.inl h) + · obtain ⟨-, hhi⟩ := hb b h + intro e + rw [e] at hhi + change (core.num.U64.wrapping_add (L.ksb s) layout.ks.VCPU_HEAD).val ≤ (L.ksb s).val + 40 at hhi + rw [vHead_val J.kern.ksbFit] at hhi + omega + +private theorem JAtZB.schTailF (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} {Ac' : Set U64} + (hSch : SchS σ σ') (hik : σ'.idleThread = σ.idleThread ∧ σ'.idleSc = σ.idleSc) + (hw : P1.WritesIn st s s' (KFoot st Z.T Z.N Z.C Z.c s σ)) + (hS : SchedRel st Z.N Z.T Z.C Z.c s' σ') (hR : NtfnStateRel Z.N Z.T (L.mem s') σ') + (hN : NSC Z.N Z.C σ') (hI : Inv σ') (hC : CurInv σ') (hA : ActIdle σ') + (hcr : CurRunW σ') (hoff : Sched.OffOK σ') (hbsa : Sched.BlockedScActive σ') + (hT : SchTailHyps (L := L) AR Z H Cs D s s' a' σ' Ac') : + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac' Lst' D s' a' σ' := by + have hK := hSch.1 + have hwT := WritesIn.tfoot_of_kfoot hw + have hX := xtop_sched_step J.xtop J.ip J.nk hwT (ct := σ.curThread) + { hK with kh := fun p => (hK.kh p).mono False.elim } hS hR hT.curOK hT.ar + obtain ⟨-, hY, hM, ⟨Lst', hCR, hRF⟩, hRP, -⟩ := + ScAll.of_k J.xtop.fin.1.1.1 J.rp J.yld J.mcp J.call J.rfree ⟨⟨hS, hR, hN, hI⟩, hw, hSch.2⟩ + have hIdle := J.idleW_keep hS hik.1 hik.2 + have hCov := J.sc_jcov (D' := D) hwT hT.dead (fun _ h hnot => (hnot h).elim) hIdle hT.dbgK subset_rfl + have hKern := J.sch_kern hwT hK hS hT.dbg hT.dwNe (J.sch_csc hwT hK hS hI hC hT.dead).1 + exact ⟨Lst', J.sch_frame hwT hK hX hCR hRF hY hM (J.sch_buf hwT hK) hRP (J.sch_apart hwT hK) + (J.sch_jpl hwT hK hIdle.2) hCov hKern (J.sch_utc hwT hK hT.dbg) hN hI (Or.inr hC) + (Or.inl (curOwn_of_curInv hS hI hC)) hoff hA hbsa (Or.inr hcr) hT.blk hT.dbgK hIdle.1 J.zD⟩ + +set_option maxHeartbeats 4000000 in +set_option maxRecDepth 2000 in +/-- The FPU-aware and domain-switching sibling of `JAtZB.jat_scheduleFRG`. -/ +theorem JAtZB.jat_scheduleFRGF (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ) (hnd : Fl4Spec.numDomains = 1) + (hAT : P0.ArchTotal arI) (hAK : ARKeep arI AR) (hRef : ArchRefines arI AR) + {F : Fl4Spec.State Unit → Fl4Spec.State Unit → Prop} {Pf : S × A → Fl4Spec.State Unit → Prop} + (hfJ : timer.fire st arI s a ⦃ r => ∃ σ1, F σ σ1 ∧ (σ1.domainTime ≠ 0 ∨ NdOK (L := L) r.1 σ1) ∧ + (∃ (V1 : XVs) (Ac1 : Set U64) (Lst1 : U64 → List U64) (D1 : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V1) H Cs Ac1 Lst1 D1 r.1 r.2 σ1) ∧ + FpuOwnOK σ1 ∧ IdleVt σ1 ∧ Pf r σ1 ⦄) + (hAF : ArchSwF st arI Z.N Z.T Z.C Z.c) (hAN : ArchNdF st Z.N Z.T Z.C Z.c) + (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) : + sched.schedule st arI s a ⦃ r => ∃ σ1 σ', F σ σ1 ∧ + Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ') ∧ CurInv σ' ∧ CurRunW σ' ∧ + ∃ rf, Pf rf σ1 ∧ NatFoot (L := L) Z rf.1 σ1 r.1 σ' ⦄ := by + have hB := J.blk + obtain ⟨⟨Q, R, hq⟩, hBd, hXi, hSc, hSg⟩ := id hB + have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h + obtain ⟨rf, hfr, σ1, hF, hdt, ⟨V1, Ac1, Lst1, D1, J1⟩, hFO, hIV, hPf⟩ := spec_exists hfJ + have hkf : L.ksb rf.1 = L.ksb s := by + obtain ⟨s1, a1⟩ := rf + exact (spec_ok_post (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a hB J.bufAtJ) hfr).1 + have hfire : timer.fire st arI s a ⦃ r => ∃ τ, F σ τ ∧ SchedRel st Z.N Z.T Z.C Z.c r.1 τ ∧ + NtfnStateRel Z.N Z.T (L.mem r.1) τ ∧ NSC Z.N Z.C τ ∧ SchedPreW0R Z.T Z.C τ ∧ + ((τ.domainTime ≠ 0 ∨ NdOK (L := L) r.1 τ) ∧ + (∀ n ∈ Z.N, n.val + 40 ≤ (L.ksb r.1).val ∨ (L.ksb r.1).val + 13568 ≤ n.val) ∧ + (r = rf ∧ τ = σ1)) ⦄ := by + rw [hfr, WP.spec_ok] + exact ⟨σ1, hF, J1.xtop.fin.1.1.1, J1.xtop.fin.1.1.2.2.1, J1.nsc, + ⟨J1.inv, curInvR_of J1.cur, J1.off, J1.act, J1.own⟩, hdt, J1.nk, rfl, rfl⟩ + have hSched := schedule_refinesWP0FRA (P := (Z.mv Z.G V1).P) hRef L.total hAT hAK s a σ J.xtop.fin.1.1.1 + J.xtop.fin.1.1.2.2.1 J.nsc hnd hfire + (fun _ _ h => h.2.symm ▸ hFO) (fun _ _ h => h.2.symm ▸ J1.vsRootOK) + (fun _ _ h => by + rcases h with ⟨rfl, rfl⟩ + exact ⟨J1.rootFr hIV, J1.xtop.fin.1.1.2.2.2.2.2.2⟩) + hAF hAN hsni hsend hT + have hIdx := P1.sched.schedule.idx hAT (P1.ibKeep_holds hAT) hNt s a hB J.kern.ksbFit J.kern.ksbAl + (J.kern.kwApartJ (s' := s) rfl (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc)) J.bufAtJ + (fun s1 hf => J.fire_ks hf (fun b hb o ho h8 => (J.bufAtJ.1 b hb).ks o ho h8)) + (idxI_of J.xtop.rel.2.2.2.1 J.xtop.fin.1.1.1 hd) + refine WP.spec_mono (WP.spec_and hSched + (WP.spec_and (P1.sched.schedule.kw hAT (P1.ibKeep_holds hAT) hNt s a hB J.bufAtJ) + (WP.spec_and (P1.sched.schedule.tinv hAT (P1.ibKeep_holds hAT) hNt s a Q R hq hBd hSc hXi hSg J.bufAtJ) hIdx))) ?_ + rintro ⟨s', a'⟩ ⟨⟨τ, σ', -, hsc, hS', hR', hN', hI', hC', hA', rf1, ⟨hRf, hτ⟩, hw, σ3, ho, hr, he, hAR⟩, + hkw, htinv, hidx⟩ + subst rf1 + subst τ + simp only [WP.uncurry'_pair] at hkw htinv + try simp only [WP.uncurry'_pair] at hidx + obtain ⟨rf', hrf', -, hkw⟩ := hkw + have er : rf = rf' := P1.ok_inj_ff (hfr.symm.trans hrf') + subst rf' + obtain ⟨⟨Q', R', hq'⟩, hBd', hXi', hSc', -, -, -, -⟩ := htinv + let v16 := L.mem s' (ksW (L.ksb rf.1) 16#u64) + let v24 := L.mem s' (ksW (L.ksb rf.1) 24#u64) + let v40 := L.mem s' (ksW (L.ksb rf.1) 40#u64) + let s0 := ndF (L := L) rf.1 (L.ksb rf.1) v16 v24 v40 + let σ0 := ndFSt σ1 v16.bv σ'.domainIndex + have hv24 : v24 = 0#u64 := by dsimp [v24]; rw [hkf]; exact hidx + obtain ⟨Ac0, Lst0, D0, J0⟩ := J1.ndFBase v16 v24 v40 σ'.domainIndex hv24 + have hw0 : P1.WritesIn st s0 s' (KFoot st Z.T Z.N Z.C Z.c s0 σ0) := + ndF_writes σ'.domainIndex J1.kern.ksbFit J1.kern.ksbAl hw + have hdbgK := (J1.ndFDbg v16 v24 v40).trans (P1.dbgKeep_schedW J1.blk J1.kern.ksbFit hkw) + have hdbg := hdbgK.2 _ (Or.inr ⟨0#u64, J0.kern.cs0, rfl⟩) + have hdw : (L.nodeAt s0 0#u64 layout.node.DEBUG_TCBS).val ≠ (P1.stA (L.curW s')).val := by + rw [← P1.nodeAt_of_ksb hdbgK.1] + have hNode := hq'.nodes 0#u64 J0.kern.cs0 + have ht : L.curW s' ∈ P1.Heap.tcbs H := hq'.curT + have hv := P1.field_val (hq'.tcbs _ ht) (K := 3328#u64) (by decide) + have hStateVal : (P1.stA (L.curW s')).val = (L.curW s').val + 3328 := by + rw [P1.stA_eq, hv] + rfl + rw [P1.nodeAt_val hNode (off := layout.node.DEBUG_TCBS) (by simp), P1.debug_val, hStateVal] + have := hNode.disj _ ht + simp only [Nat.reducePow] at this + omega + have hSch : SchS σ1 σ' := schs_schedule.of_eq hsc + have hSch0 : SchS σ0 σ' := SchS.ndF hSch v16.bv σ'.domainIndex + have hwT := WritesIn.tfoot_of_kfoot hw0 + have hSS := slotsSame_of_iw J0.xtop.rel.1 J0.xtop.rel.2.2.2.2.2.1 J0.xtop.rel.2.2.2.2.2.2 hwT + (fun b hb => tfoot_iw J0.xtop.fin.1.1.1 hb) + obtain ⟨_, _, hc, hcT⟩ := hS'.lists + let t := Sched.nodeW st s' Z.c layout.node.CUR_THREAD + have hth : Z.th t = some .tcb := J0.thTcb hc.curT + have hSlot : IsSlot Z.th (slotOf t 1) := ⟨t, 1, Or.inr ⟨hth, by decide⟩, rfl⟩ + have hCur : Vs.CurOK st Z.th s' σ' := by + refine ⟨t, hcT.curThread.symm, hth, fun p asid h => ?_⟩ + rw [hSS.capAt hSlot] at h + have hV := J0.vsc _ hSlot + rw [capV_of_capAt h] at hV + exact (hV.2.2 rfl).1 + have hX := xtop_sched_step J0.xtop J0.ip J0.nk hwT (ct := σ0.curThread) + { hSch0.1 with kh := fun p => (hSch0.1.kh p).mono False.elim } hS' hR' hCur hAR + have hY := (ScAll.of_k J0.xtop.fin.1.1.1 J0.rp J0.yld J0.mcp J0.call J0.rfree + ⟨⟨hS', hR', hN', hI'⟩, hw0, hSch0.2⟩).2.1 + have hL : LK (fun _ => False) σ0 σ' := lkm_schedule σ1 ((), σ') (by rw [hsc]; exact Set.mem_singleton _) + have hDead : ∀ q ∈ D0, Sched.DeadP (L := L) H s' q := fun q hq => + J0.deadP_sch_step hX hwT hSch0.1 hL hA' (J0.ymd hS' hY ((hSch0.2.ykeep rfl).dk q.bv)) + (fun h => h) (J0.jcov.dead q hq) + have hIdle : σ'.idleThread = σ0.idleThread ∧ σ'.idleSc = σ0.idleSc := + ik_schedule σ1 ((), σ') (by rw [hsc]; exact Set.mem_singleton _) + have hRun := RunW.scAndTimer (hr J1.curRun) he + have hTail : SchTailHyps (L := L) AR (Z.mv Z.G V1) H Cs D0 s0 s' a' σ' Ac := + ⟨hCur, hAR, hdbg, hdw, hDead, + ⟨⟨Q', R', hq'⟩, hBd', hXi', hSc', hSg.ksb' (hkw.1.trans hkf)⟩, hdbgK⟩ + obtain ⟨Lst', J'⟩ := J0.schTailF hSch0 hIdle hw0 hS' hR' hN' hI' hC' hA' hRun + (OffOK.scAndTimer ho he) (bsa_schedule J1.bsa hsc) hTail + exact ⟨σ1, σ', hF, hsc, ⟨V1, Ac, Lst', D0, J'⟩, hC', hRun, rf, hPf, (J1.scheduleFootN hw hSch.1).cast⟩ + + +set_option maxHeartbeats 4000000 in +/-- **FL4's FPU-aware `schedule` at `VmEptState`**, after `fl4AwakenVF` (module docstring). +The timer outcome supplies the facts for `jat_scheduleFRGF` and its native footprint carries the VM relations. -/ +theorem VmEptState.scheduleVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {on rc : Fl4Spec.ObjRef → Bool} + {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hO : VmOrc st on rc s σ) (hd : σ.domainTime ≠ 0 ∨ NdOK (L := L) s σ) (hnd : Fl4Spec.numDomains = 1) + (hsni : SniHyp st arI Z.N Z.T Z.C Z.c) (hsend : SendHyp st arI Z.N Z.T Z.C Z.c) (hT : TimeAgree arI) + (hRef : ArchRefines arI AR) (hAF : ArchSwF st arI Z.N Z.T Z.C Z.c) (hAN : ArchNdF st Z.N Z.T Z.C Z.c) + (hFO : FpuOwnOK σ) (hIV : IdleVt σ) : + sched.schedule st arI s a ⦃ r => ∃ σ1 σ' : Fl4Spec.State Unit, + ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1 ∧ + Fl4Spec.schedule (Z := Unit) σ1 = ({((), σ')}, False) ∧ + (∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + VmEptState (L := L) arI V X XL AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.1 r.2 σ') ∧ CurInv σ' ∧ CurRunW σ' ⦄ := by + have B := J.1.1 + have hNt : ∀ n ∈ P1.Heap.ntfns H, H n = some .ntfn := fun _ h => h + refine WP.spec_mono (B.jat_scheduleFRGF hd hnd hAT hK hRef + (F := fun σ σ1 => ((), σ1) ∈ (Fl4Spec.fl4AwakenVF (Z := Unit) on rc σ).1) + (Pf := fun r σ1 => VmFireP (st := st) (arI := arI) (AR := AR) V X XL Z H Cs on rc r.1 r.2 σ1) + (WP.spec_mono (P1.spec_eq' (WP.spec_and (J.fireVF hAT hVA hK hmb hO) + (P1.timer.fire.kw hAT (P1.ibKeep_holds hAT) hNt s a B.blk B.bufAtJ))) fun r h => by + obtain ⟨hfr, ⟨σ1, h1, hdt, hP⟩, hkw⟩ := h + obtain ⟨V1, Ac1, Lst1, D1, J1, -⟩ := id hP + obtain ⟨s1, a1⟩ := r + simp only [WP.uncurry'_pair] at hkw + have hdt1 : σ1.domainTime ≠ 0 ∨ NdOK (L := L) s1 σ1 := + hd.imp (fun h => by rw [hdt]; exact h) + (fun h => B.ndOK_awakenVF h hkw (fun b hb o ho h8 => (B.bufAtJ.1 b hb).ks o ho h8) h1) + exact ⟨σ1, h1, hdt1, ⟨V1, Ac1, Lst1, D1, J1.1.1⟩, + B.fpuOwnOK_awakenVF h1 J1.1.1.xtop.fin.1.1.2.2.1 hFO, B.idleVt_awakenVF hAT hIV hfr h1 J1.1.1, hP⟩) + hAF hAN hsni hsend hT) ?_ + rintro r ⟨σ1, σ', h1, h2, ⟨V', Ac', Lst', D', B'⟩, hC, hR, rf, ⟨V1, Ac1, Lst1, D1, J1, -⟩, NF⟩ + exact ⟨σ1, σ', h1, h2, ⟨V', Ac', Lst', D', J1.ofNat B' NF.cast⟩, hC, hR⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmSignal.lean b/proofs/Fl4Proofs/P3/VmSignal.lean new file mode 100644 index 000000000..5082f4c8b --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmSignal.lean @@ -0,0 +1,242 @@ +/- +P3 (line mmuAD, gen 42b71, the Architect's ruling (c2) item 2): **`send_signal` at `VmEptState`**, against the +extended spec's `sendSignalVF` with the oracles read off FL4's state (P3/JAtZV3SigComp's `v3OnCore st s`, +`v3RemCur st s`), without routing through `JAtZV3`. One lemma for both callers of the signal: `check_interrupt`'s +handler and the timers of `schedule` (`fl4AwakenVF`). + +* `v3_sigComp_one`: the spec's `vmSignalCompletes` of a TCB has one outcome (`v3_sigComp_none` / `v3_sigComp_some`). +* `v3_ssVF_nvm`: `sendSignalVF` is the ported `sendSignal` unless the notification is idle and bound to a + `runningVM` thread (`v3_ssVF_nc`). +* **`VmEptState.signalVm`**: an idle notification bound to a `runningVM` thread. P3/JAtZV3SigVm's `signalVmWG` at + `P := VmEptState` (`VmEptState.toB`; the report by P3/EptReport's `VmEptState.reportJ3`; the tail by + P3/JAtZV3SigTail's `sigVmTailG` with P3/JAtZV3SigDon's `sigVmDonG`, the SC-code steps by `VmEptState.ofTK`); when the + VMEnter does not complete, FL4's `set_active` + `kick_guest` is a native step (`JAtZB.signal_badge_post`, ScSignalJN's + `JAtZB.badgeN`, `VmEptState.ofNat`; the guest kick keeps `AR`, `VmEptState.archV`). +* **`VmEptState.signalVF`**: every arm. The others by ScSignalJN's `JAtZB.signal_atNV` (the `RunningVM` case excluded + for the signalled notification only) and `VmEptState.ofNat`. + +(gen 42b73) `RvmSub` (no thread becomes `runningVM`; `ZvK.rvm`); **`VmEptState.signalVmK`** / **`signalVFK`**: the two +lemmas with that frame, and the bound thread `runningVM` after only if FL4's `signal_completes` refused it (the report +by `JAtZB.repKh`, the tail by `natK_tkw`; P3/JAtZV3SigVm's `signalVmWG` with records `Pm` / `Pf` for the report and +the tail); `signalVm` / `signalVF` their corollaries (statements unchanged). + +Premises: `P0.ArchTotal`, and the [P] facts `JAtZV3.signalVmJ3` already takes (`ZvVirtAgree`, `ARKeep`, the +platform's `MIN_BUDGET`). No named premise; no existing statement changed. +-/ +import Fl4Proofs.P3.EptReport +import Fl4Proofs.P3.JAtZV3SigDon +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +section +open Fl4Spec Classical Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp + +/-- The spec's `vmSignalCompletes` of a TCB has one outcome, the state kept. -/ +theorem v3_sigComp_one (on rc : ObjRef → Bool) {σ : State Unit} {t : ObjRef} {x : Tcb} + (hk : σ.kheap t = some (.tcb x)) : ∃ c, vmSignalCompletes (Z := Unit) on rc t σ = ({(c, σ)}, False) := by + cases hvo : tcbVcpuOf σ t with + | none => exact ⟨false, v3_sigComp_none on rc hvo⟩ + | some v => + obtain ⟨vs, hkv⟩ := v3_tcbVcpuOf_some hvo + exact ⟨_, v3_sigComp_some on rc hk hvo hkv⟩ + +/-- **`sendSignalVF` is `sendSignal` off the `runningVM`-bound arm** (module docstring). -/ +theorem v3_ssVF_nvm (on rc : ObjRef → Bool) (b : Badge) {σ : State Unit} {n : ObjRef} {x : Notification} + (hk : σ.kheap n = some (.notification x)) + (h : x.ntfnObj = .idleNtfn → ∀ t, x.ntfnBoundTcb = some t → + ∃ y, σ.kheap t = some (.tcb y) ∧ y.tcbState ≠ .runningVM) : + sendSignalVF (Z := Unit) on rc n b σ = sendSignal n b σ := by + cases ho : x.ntfnObj + case idleNtfn => + cases hb : x.ntfnBoundTcb with + | none => + unfold sendSignalVF + rw [nd_bind_one (getNotification_eq hk), ho, hb] + | some t => + obtain ⟨y, hkt, hy⟩ := h ho t hb + obtain ⟨c, hc⟩ := v3_sigComp_one on rc hkt + exact v3_ssVF_nc on rc b hk ho hb hkt hc fun h' => hy h'.1 + all_goals + unfold sendSignalVF + rw [nd_bind_one (getNotification_eq hk), ho] + +end + +section +variable {σ1 σ2 σ3 : Fl4Spec.State Unit} + +/-- (gen 42b73) **No thread becomes `runningVM`** from `σ1` to `σ2` (P3/NatFoot's `ZvK`, third clause). -/ +def RvmSub (σ1 σ2 : Fl4Spec.State Unit) : Prop := + ∀ o x', σ2.kheap o = some (.tcb x') → x'.tcbState = .runningVM → + ∃ x, σ1.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM + +theorem RvmSub.refl (σ : Fl4Spec.State Unit) : RvmSub σ σ := fun _ x' h hr => ⟨x', h, hr⟩ + +theorem RvmSub.trans (h1 : RvmSub σ1 σ2) (h2 : RvmSub σ2 σ3) : RvmSub σ1 σ3 := fun o x h hr => + let ⟨y, hy, hry⟩ := h2 o x h hr; h1 o y hy hry + +theorem ZvK.rvm (h : ZvK σ1 σ2) : RvmSub σ1 σ2 := h.2.2.1 + +end + +section +open Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} {V X : Set U64} {XL : U64 → Nat} + +set_option maxHeartbeats 4000000 in +/-- (gen 42b73) **`VmEptState.signalVm` with the `runningVM` frame**: no thread becomes `runningVM` (`RvmSub`), and +the bound thread stays `runningVM` only when FL4's `signal_completes` refused it (the report and the tail by +`JAtZB.repKh` and `natK_tkw`; the activation is a native step). -/ +theorem VmEptState.signalVmK (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) + {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) + {t : U64} (hb : x.ntfnBoundTcb = some t.bv) {y : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb y)) + (hrs : y.tcbState = .runningVM) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ∧ + RvmSub σ σ' ∧ ((∃ x', σ'.kheap t.bv = some (.tcb x') ∧ x'.tcbState = .runningVM) → + vcpu.signal_completes st s t = ok false) ⦄ := by + have B := J.1.1 + have hNt : ∀ m ∈ P1.Heap.ntfns H, H m = some .ntfn := fun _ h => h + have hnH : n ∈ P1.Heap.ntfns H := B.zH.2.2.2 n hn + have hP1 := P1.notification.send_signal.tinv hAT s a n badge B.blk hnH (hNt n hnH) B.bufAtJ.1 B.bufAtJ.2 + have hTK : ∀ {Ac1 : Set U64} {Lst1 : U64 → List U64} {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} + {Ac2 : Set U64} {Lst2 : U64 → List U64} {s2 : S} {a2 : A} {σ2 : Fl4Spec.State Unit}, + (VmEptState (L := L) arI V X XL AR Z H Cs Ac1 Lst1 D s1 a1 σ1 ∧ RvmSub σ σ1 ∧ + ∀ x', σ1.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM) → + JAtZB (L := L) arI AR Z H Cs Ac2 Lst2 D s2 a2 σ2 → + P1.WritesIn st s1 s2 (Sched.TFoot st Z.T Z.N Z.C Z.c s1 σ1) → Sched.ScTKw (fun _ => False) σ1 σ2 → + VmEptState (L := L) arI V X XL AR Z H Cs Ac2 Lst2 D s2 a2 σ2 ∧ RvmSub σ σ2 ∧ + ∀ x', σ2.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM := + fun ⟨J1, R1, N1⟩ B2 hw hK' => + have R12 : RvmSub _ _ := ZvK.rvm (natK_tkw hK' fun _ h => h.elim).1 + ⟨J1.ofTK B2 hw hK', R1.trans R12, fun x' hx' hr => by + obtain ⟨x1, hx1, hr1⟩ := R12 _ x' hx' hr + exact N1 x1 hx1 hr1⟩ + have hW := signalVmWG (t := t) + (P := fun Ac' Lst' s' a' σ' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ RvmSub σ σ') + (Pm := fun Ac' Lst' s' a' σ' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ RvmSub σ σ' ∧ + ∀ x', σ'.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM) + (Pf := fun Ac' Lst' s' a' σ' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ RvmSub σ σ' ∧ + ∀ x', σ'.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM) + (fun J' => J'.1.toB) + (@fun _ _ _ _ σ1 J' ht hr b => WP.spec_mono (J'.1.reportJ3 hAT hVA ht hr b) fun _ ⟨σr, Ac', Lst', h1, J'', _, _⟩ => by + obtain ⟨x1, hk1, -⟩ := hr + obtain ⟨hkh, ⟨yr, hkr, hyr⟩, -⟩ := J'.1.1.1.repKh ht hk1 h1 + refine ⟨σr, Ac', Lst', h1, J'', fun o x' ho hx' => ?_, fun x' hx' => ?_⟩ + · obtain ⟨u, hu, rfl⟩ := J''.1.1.obj.tcb o x' ho + have hot : u.bv ≠ t.bv := fun e => by + rw [e, hkr] at ho; cases ho; rw [hyr] at hx'; cases hx' + obtain ⟨x0, hk0, -⟩ := J'.1.1.1.specTcb (J'.1.1.1.thTcb hu) + have e : σr.kheap u.bv = σ1.kheap u.bv := hkh u.bv hot (fun vs e => by rw [hk0] at e; cases e) + exact J'.2 u.bv x' (by rw [← e]; exact ho) hx' + · rw [hkr] at hx'; cases hx'; rw [hyr]; exact fun h => by cases h) + (sigVmTailG + (P := fun Ac' Lst' s' a' σ' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ RvmSub σ σ' ∧ + ∀ x', σ'.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM) + (fun J' => J'.1.1.1) hTK (sigVmDonG + (P := fun Ac' Lst' s' a' σ' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ RvmSub σ σ' ∧ + ∀ x', σ'.kheap t.bv = some (.tcb x') → x'.tcbState ≠ .runningVM) + (fun J' => J'.1.1.1) hTK hAT hmb) · · · · · t) + hAT hK ⟨J, RvmSub.refl σ⟩ hn hk hidle hb hkt hrs badge + refine WP.spec_mono (WP.spec_and hW hP1) ?_ + rintro ⟨s', a'⟩ ⟨h1, hbk⟩ + try simp only [WP.uncurry'_pair] at hbk + rcases h1 with ⟨σ', Ac', Lst', h1, h2, J', R', N'⟩ | ⟨hnc, hA1, hSR, hcf⟩ + · exact ⟨σ', Ac', Lst', h1, h2, J', R', fun ⟨x', hx', hr'⟩ => absurd hr' (N' x' hx')⟩ + · have hspec := sendSignal_activate hk hidle (Or.inr ⟨t.bv, y, hb, hkt, by rw [hrs]; rfl⟩) badge.bv + obtain ⟨σ1, h1, -, B1⟩ := B.signal_badge_post (y := Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn badge.bv) x) hn hk + (by rw [hidle]; intro l e; cases e) (fun l e => by simp [Fl4Spec.ntfnObjUpdate] at e) rfl rfl hspec hSR hbk + have e : σ1 = updK σ n.bv (.notification (Fl4Spec.ntfnObjUpdate (fun _ => .activeNtfn badge.bv) x)) := by + have h3 := (Prod.mk.inj (h1.symm.trans hspec)).1 + exact congrArg Prod.snd (Set.singleton_injective h3) + subst e + have F := B.badgeN hk (hspec ▸ hSR) + exact ⟨_, Ac, Lst, hnc.trans hspec, rfl, (J.ofNat (V' := Z.vs) B1 F).archV hA1, ZvK.rvm F.fk.1, fun _ => hcf⟩ + +/-- **`send_signal` to an idle notification bound to a `runningVM` thread at `VmEptState`, against `sendSignalVF`** +(module docstring). (gen 42b73) `signalVmK` without the frame. -/ +theorem VmEptState.signalVm (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) + {x : Fl4Spec.Notification} (hk : σ.kheap n.bv = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) + {t : U64} (hb : x.ntfnBoundTcb = some t.bv) {y : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb y)) + (hrs : y.tcbState = .runningVM) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64), + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D r.1 r.2 σ' ⦄ := + WP.spec_mono (J.signalVmK hAT hVA hK hmb hn hk hidle hb hkt hrs badge) fun _ ⟨σ', Ac', Lst', h1, h2, J', _⟩ => + ⟨σ', Ac', Lst', h1, h2, J'⟩ + +set_option maxHeartbeats 4000000 in +/-- (gen 42b73) **`VmEptState.signalVF` with the `runningVM` frame** (`signalVmK`; the other arms are native +steps, `ZvK`): no thread becomes `runningVM`, and the thread bound to an idle notification stays `runningVM` only when +FL4's `signal_completes` refused it. -/ +theorem VmEptState.signalVFK (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ∧ + RvmSub σ σ' ∧ ∀ (x : Fl4Spec.Notification) (t : U64), σ.kheap n.bv = some (.notification x) → + x.ntfnObj = .idleNtfn → x.ntfnBoundTcb = some t.bv → + (∃ x', σ'.kheap t.bv = some (.tcb x') ∧ x'.tcbState = .runningVM) → + vcpu.signal_completes st s t = ok false ⦄ := by + have B := J.1.1 + have hI := B.xtop.irelK B.ks B.buf + obtain ⟨x, hk, hx⟩ := B.xtop.ipc.toN.ntfn n hn + by_cases hvm : x.ntfnObj = .idleNtfn ∧ ∃ t y, x.ntfnBoundTcb = some t ∧ σ.kheap t = some (.tcb y) ∧ + y.tcbState = .runningVM + · obtain ⟨hidle, t, y, hb, hkt, hrs⟩ := hvm + obtain ⟨-, hbt⟩ := Notif.optRef_some (hx.bound ▸ hb) + refine WP.spec_mono (J.signalVmK hAT hVA hK hmb hn hk hidle (t := L.mem s (nBoundA n)) (by rw [hbt]; exact hb) + (by rw [hbt]; exact hkt) hrs badge) fun _ ⟨σ', Ac', Lst', h1, h2, J', R', hc⟩ => + ⟨σ', Ac', Lst', D, h1, h2, J', R', fun x1 t1 hk1 _ hb1 hr1 => ?_⟩ + rw [hk] at hk1; cases hk1 + have e : L.mem s (nBoundA n) = t1 := P1.eq_of_bv (hbt.trans (Option.some.inj (hb.symm.trans hb1))) + subst e + exact hc hr1 + · have heq : Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = + Fl4Spec.sendSignal n.bv badge.bv σ := v3_ssVF_nvm _ _ _ hk fun ho t hb => by + obtain ⟨hb0, hbt⟩ := Notif.optRef_some (hx.bound ▸ hb) + obtain ⟨tcb, hkt, -⟩ := hI.1.tcb _ (hx.bound_mem hb0) + rw [hbt] at hkt + exact ⟨tcb, hkt, fun hr => hvm ⟨ho, t, tcb, hb, hkt, hr⟩⟩ + refine WP.spec_mono (B.signal_atNV hAT hmb n badge hn fun x' t tcb hk' ho hb hkt hr => ?_) + fun _ ⟨σ', Ac', Lst', D', h1, h2, B', F⟩ => ⟨σ', Ac', Lst', D', heq.trans h1, h2, J.ofNat (V' := Z.vs) B' F, + ZvK.rvm F.fk.1, fun x1 t1 hk1 ho1 hb1 ⟨x', hx', hr'⟩ => by + obtain ⟨y0, hy0, hr0⟩ := ZvK.rvm F.fk.1 _ x' hx' hr' + rw [hk] at hk1; cases hk1 + exact absurd ⟨ho1, t1.bv, y0, hb1, hy0, hr0⟩ hvm⟩ + rw [hk] at hk' + cases hk' + exact hvm ⟨ho, t, tcb, hb, hkt, hr⟩ + +/-- **`send_signal` at `VmEptState`, every arm, against `sendSignalVF`** (module docstring). (gen 42b73) `signalVFK` +without the frame. -/ +theorem VmEptState.signalVF (hAT : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) {n : U64} (hn : n ∈ Z.N) (badge : U64) : + notification.send_signal st arI s a n badge ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + Fl4Spec.sendSignalVF (Z := Unit) (v3OnCore st s) (v3RemCur st s) n.bv badge.bv σ = ({((), σ')}, False) ∧ + σ'.domainTime = σ.domainTime ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D' r.1 r.2 σ' ⦄ := + WP.spec_mono (J.signalVFK hAT hVA hK hmb hn badge) fun _ ⟨σ', Ac', Lst', D', h1, h2, J', _⟩ => + ⟨σ', Ac', Lst', D', h1, h2, J'⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VmVcpuDec.lean b/proofs/Fl4Proofs/P3/VmVcpuDec.lean new file mode 100644 index 000000000..9fc7a110c --- /dev/null +++ b/proofs/Fl4Proofs/P3/VmVcpuDec.lean @@ -0,0 +1,248 @@ +/- +P3 VM/EPT VCPU decoding over the shared VCPU relations. +SetTCB uses the extra thread cap as a witness for the newly bound target. +-/ +import Fl4Proofs.P3.EptFinIo +import Fl4Proofs.P3.JAtZV3VDisp5 +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core + +noncomputable section + +open Fl4Proofs.P3.Vs + +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} + {arI : machine.Arch A} {AR : A → Fl4Spec.Cr3 → Prop} {V X : Set U64} {XL : U64 → Nat} + {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} + {s : S} {a : A} {σ : Fl4Spec.State Unit} + +set_option maxHeartbeats 4000000 in +/-- Refine the SetTCB body and its concrete restart at a VM/EPT state. The +detach and bind preserve the invoked thread cap's slot. -/ +theorem VmEptState.setTcbCoreK (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hA : P0.ArchTotal arI) (hVA : ZvVirtAgree arI) (hK : ARKeep arI AR) + {t v x : U64} (ht : Z.th t = some .tcb) (hv : v ∈ V) (hx : IsSlot Z.th x) + (hc : capV (L.mem s) x = .Thread t) (ct : U64) : + (do + let (s3, a2) ← smp.remote_tcb_stall st arI s a t + let (s4, a3) ← vcpu.detach st arI s3 a2 t + let i1 ← vcpu.get st s4 v vcpu.TCB + let b1 ← obj.Tcb.is_null i1 + let (s5, a4) ← if b1 then ok (s4, a3) else vcpu.detach st arI s4 a3 i1 + let s6 ← vcpu.set st s5 v vcpu.TCB t + let i2 ← layout.tcb.VCPU + let i3 ← lift (core.num.U64.wrapping_add t i2) + let s7 ← st.write s6 i3 v + let s8 ← sched.set_thread_state st s7 ct sched.TS_RESTART + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s8, a4)) ⦃ r => + ∃ (σ' : Fl4Spec.State Unit) (Ac' : Set U64) (Lst' : U64 → List U64) (s7 : S), r.1 = .Ok () ∧ + Fl4Spec.associateVcpuTcbF (Z := Unit) v.bv t.bv σ = ({((), σ')}, False) ∧ + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s7 r.2.2 σ' ∧ + sched.set_thread_state st s7 ct sched.TS_RESTART = ok r.2.1 ⦄ := by + let Q := fun Ac' Lst' s' a' σ' => + VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s' a' σ' ∧ SlotsSame Z.th (L.mem s) (L.mem s') + refine setTcbCoreQK (Q := Q) + (fun _ _ _ _ _ h => h.1.toB) + (fun _ _ _ _ _ t h ht => WP.spec_mono (h.1.detachF2S hA hVA hK ht) + fun _ ⟨σ', Ac', Lst', hD, J', hM, hSS, _⟩ => ⟨σ', Ac', Lst', hD, ⟨J', h.2.trans hSS⟩, hM⟩) + ht hv + (fun _ _ _ _ _ vs h hw0 hb0 hk => + ⟨h.1.bind ht hv hw0 hb0 hk hx ((h.2.capV hx).trans hc), + h.2.trans (h.1.toF.bind ht hv hw0 hb0 hk { vs with tcb := some t.bv } rfl).ss⟩) + (show Q Ac Lst s a σ from ⟨J, SlotsSame.refl _ _⟩) _ ?_ + intro s7 a4 σ' Ac' Lst' hA' J' + obtain ⟨s8, hs8, -⟩ := P1.spec_ex_fd + (P0.sched.set_thread_state.p0 st s7 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) + rw [hs8, bind_ok, WP.spec_ok] + exact ⟨σ', Ac', Lst', s7, rfl, hA', J'.1, hs8⟩ + + +set_option maxHeartbeats 4000000 in +/-- Revoke a prior grant, write the slot owner, and enable the requested ports. -/ +theorem VmEptState.enableIoPortCore + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) (hK : ARKeep arI AR) + {p : U64} (hp : p ∈ V) (hcan : Canonical p) + {pc : U64} {r : Nat} {idx : List Bool} (hpc : Z.th pc = some (.cnode r)) (hidx : idx.length = r) + {first last prior lo hi ct : U64} + (hc : capV (L.mem s) (cslotAddr (pc.bv, idx)) = .IoPort first last prior) + (hfl : first.val ≤ last.val) (hl : last.val < 65536) (hlo : lo.val ≤ hi.val) (hhi : hi.val < 65536) : + (do + let old ← obj.ks_get st s layout.ks.VCPU_HEAD + let (s3, a2) ← vcpu.decode_loop3 st arI s a first last prior old layout.WALK_FUEL + let s5 ← obj.Slot.set_cap st (cslotAddr (pc.bv, idx)) s3 (.IoPort first last p) + let s6 ← vcpu.ports st s5 p lo hi false + let s7 ← sched.set_thread_state st s6 ct sched.TS_RESTART + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s7, a2)) ⦃ res => + ∃ σ' Ac' Lst' s6, res.1 = .Ok () ∧ + Fl4Spec.performVcpuInvocationF (Z := Unit) (.enableIoPort p.bv lo.bv hi.bv + (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) (ioOwnerOf prior)) (pc.bv, idx)) σ = + ({([], σ')}, False) ∧ VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D s6 res.2.2 σ' ∧ + sched.set_thread_state st s6 ct sched.TS_RESTART = ok res.2.1 ⦄ := by + have hs : IsSlot Z.th (cslotAddr (pc.bv, idx)) := + AbsSlot.isSlot ⟨pc, rfl, Or.inl (by simpa [hidx] using hpc)⟩ + have hWalk := J.revokeWalk hK (w := prior) hfl hl J.1.1.ar + simp only [decode_loop3_eq_revoke] + rw [← Std.bind_assoc] + refine WP.spec_bind hWalk ?_ + rintro ⟨s3, a2⟩ ⟨σ3, Ac3, Lst3, hRev, J3, hSS, _⟩ + simp only [uncurry_apply_pair] + refine WP.spec_bind (J3.ioOwnJ hpc hidx ((hSS.capV hs).trans hc) hcan) ?_ + rintro s5 ⟨σ5, hSet, _, J5⟩ + obtain ⟨vs, hk5, _⟩ := J5.1.2.vb p hp + have hop : ioOwnerOf p = some p.bv := by + unfold ioOwnerOf + rw [if_neg (fun h => J5.1.2.extv.nz p hp (UScalar.eq_of_val_eq (by rw [h]; rfl)))] + have hσ5 : Fl4Spec.ioPortSetOwner (Z := Unit) + (.ioPortCap (BitVec.ofNat 16 first.val) (BitVec.ofNat 16 last.val) (ioOwnerOf prior)) + p.bv (pc.bv, idx) σ3 = ({((), σ5)}, False) := by + rw [Fl4Spec.ioPortSetOwner, ← hop] + exact hSet + unfold vcpu.ports + have J5' : VmBaseF (L := L) arI s5 σ5 V AR Z H Cs Ac3 Lst3 D s5 a2 + (Notif.updK σ5 p.bv (.archObj (.vcpu (vsIoLt vs lo.val lo.val false)))) := by + rw [vsIoLt_self, v3_updK_self hk5] + exact J5.toF + refine WP.spec_bind (J5'.portsLoop hp hhi false hk5 _ s5 lo le_rfl (by omega)) fun s6 J6 => ?_ + obtain ⟨s7, h7, -⟩ := P1.spec_ex_fd + (P0.sched.set_thread_state.p0 st s6 ct sched.TS_RESTART (P1.LawfulStore.total (st := st))) + rw [h7, bind_ok, WP.spec_ok] + have hPort : vsIoLt vs lo.val (hi.val + 1) false = vs.setPorts lo.bv hi.bv false := + vsIoLt_setPorts vs false (UScalar.bv_toNat lo).symm (by rw [UScalar.bv_toNat]) + rw [hPort] at J6 + refine ⟨_, Ac3, Lst3, s6, rfl, ?_, J5.ofFBind J6 (fun u _ => VcpuBindingKeep.update (after := vs.setPorts lo.bv hi.bv false) hk5 rfl u), h7⟩ + unfold Fl4Spec.performVcpuInvocationF + dsimp only + rw [Notif.nd_bind_one hRev, Notif.nd_bind_one hσ5, Notif.nd_bind_one (zv_vcpuUpdate_eq hk5 _)] + rfl + + +set_option maxHeartbeats 4000000 in +/-- Decode every VCPU label at VM/EPT state. The typed extra-cap lookup +provides the slot used by SetTCB and EnableIOPort. -/ +theorem VmEptState.vcpuDecodeJ + (J : VmEptState (L := L) arI V X XL AR Z H Cs Ac Lst D s a σ) + (hK : ARKeep arI AR) (hSy : ZvSyncKeep arI AR) (hVA : ZvVirtAgree arI) + (hCap : ∀ a', VirtSanEq.CapAgree arI a') (hAT : P0.ArchTotal arI) + {p : U64} (hp : p ∈ V) (hcan : Canonical p) {lbl len buf : U64} + (call : Bool) (hbuf : BufOut V buf) (ex : Array obj.Slot 3#usize) + {sl : obj.Slot} {b : Bool} (hsl : Array.index_usize ex 0#usize = ok sl) + (hbn : obj.Slot.is_null sl = ok b) {c : capability.Cap} + (hc : b = false → obj.Slot.cap st sl s = ok c) + (hslot : b = false → ∃ pc r idx, Z.th pc = some (.cnode r) ∧ idx.length = r ∧ sl = cslotAddr (pc.bv, idx)) + (hth : b = false → ∀ t, c = .Thread t → Z.th t = some .tcb) : + vcpu.decode st arI s a lbl len p call buf ex ⦃ res => + VDecPostQ st (fun Ac' Lst' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D) + (VCaps Z.th (Ipc.exAt ex 0) b c) Ac Lst s σ lbl len p call buf res ⦄ := by + let Q := fun Ac' Lst' => VmEptState (L := L) arI V X XL AR Z H Cs Ac' Lst' D + let extra := VCaps Z.th (Ipc.exAt ex 0) b c + have hQ : ∀ a', AR a' σ.archState.x64CurrentCr3 → Q Ac Lst s a' σ := fun _ h => J.archV h + have liftPost : ∀ {lbl'} {res}, VDecPostQ st + (fun Ac' Lst' s' a' σ' => VmBaseF (L := L) arI s σ V AR Z H Cs Ac' Lst' D s' a' σ' ∧ VcpuBindingKeep σ σ') + extra Ac Lst s σ lbl' len p call buf res → + VDecPostQ st Q extra Ac Lst s σ lbl' len p call buf res := + fun h => h.mono fun _ _ _ _ _ h' => J.ofFBind h'.1 (fun u _ => h'.2 u) + obtain ⟨vs, hk, _⟩ := J.1.2.vb p hp + have hvk : Fl4Spec.virtKind = .vmx ∨ Fl4Spec.virtKind = .svm := by + have hRel := J.1.2.vr p hp vs hk + revert hRel + cases Fl4Spec.virtKind + all_goals first | (intro h; exact h.elim) | (intro _; exact Or.inl rfl) | (intro _; exact Or.inr rfl) + rcases hl : Fl4Spec.vcpuLabelOf lbl.bv with _ | lab + · exact J.toB.vdOther hQ hK hVA hp hl len call buf ex + cases lab + case setTcb => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUSetTCB) (by unfold fl4_abi.label.X86VCPUSetTCB; rfl) + subst lbl + refine WP.spec_mono (J.toB.setTcbJ (Q := Q) hAT hK hp hQ len call buf ex hsl hbn hc ?_) ?_ + · intro t a' ct hb0 ht J' + obtain ⟨pc, r, idx, hpc, hidx, hxs⟩ := hslot hb0 + have hs : IsSlot Z.th sl := by + rw [hxs] + exact AbsSlot.isSlot ⟨pc, rfl, Or.inl (by simpa [hidx] using hpc)⟩ + have hcap := hc hb0 + rw [slot_cap_eq, ht] at hcap + exact J'.setTcbCoreK hAT hVA hK (hth hb0 t ht) hp hs (capV_of_capAt hcap) ct + · rintro res ⟨ct, hct, hD⟩ + refine ⟨ct, hct, fun args ec _ he => ?_⟩ + rcases hD args ec he.stcb with ⟨e, e', h1, h2, h3, h4, h5⟩ | ⟨t, s7, σ', Ac', Lst', h1, h2, h3, h4, h5⟩ + · exact Or.inl ⟨e, e', h1, h2, by rw [h3], h4, h5⟩ + · exact Or.inr ⟨.setTcb p.bv t.bv, [], s7, σ', Ac', Lst', h1, by rw [h2], h3, h4, Or.inl ⟨rfl, h5⟩⟩ + case writeRegisters => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUWriteRegisters) (by unfold fl4_abi.label.X86VCPUWriteRegisters; rfl) + subst lbl + by_cases h : 15 ≤ len.val + · exact WP.spec_mono (J.toF.vdWregs hK hAT hp hk h call hbuf ex) (fun _ => liftPost) + · exact J.toB.vdWregsS hQ hK hVA hp (by omega) call buf ex + case flushTlb => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUFlushTLB) (by unfold fl4_abi.label.X86VCPUFlushTLB; rfl) + subst lbl + exact WP.spec_mono (J.toF.vdFlush hK hVA hp len call buf ex) (fun _ => liftPost) + case readVmcs => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUReadVMCS) (by unfold fl4_abi.label.X86VCPUReadVMCS; rfl) + subst lbl + by_cases hs : Fl4Spec.virtKind = .svm + · exact J.toB.vdRvmcsA hQ hK hVA hs hp len call buf ex + by_cases h : 1 ≤ len.val + · exact J.toB.readVmcsJ hQ hK hSy hVA hCap hs hp hk h call buf ex + · exact J.toB.vdRvmcsS hQ hK hVA hs hp (by omega) call buf ex + case writeVmcs => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUWriteVMCS) (by unfold fl4_abi.label.X86VCPUWriteVMCS; rfl) + subst lbl + rcases hvk with hx | hs + · by_cases h : 2 ≤ len.val + · exact WP.spec_mono (J.toF.vdWvmcs hK hSy hVA hCap hx hp hk h call buf ex) (fun _ => liftPost) + · exact J.toB.vdWvmcsS hQ hK hVA hx hp (by omega) call buf ex + · exact J.toB.vdWvmcsA hQ hK hVA hs hp len call buf ex + case readVmcb => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUReadVMCB) (by unfold fl4_abi.label.X86VCPUReadVMCB; rfl) + subst lbl + by_cases hs : Fl4Spec.virtKind = .svm + · by_cases h : 2 ≤ len.val + · exact J.toB.readVmcbJ hQ hK hVA hs hp hk h call buf ex + · exact J.toB.vdRvmcbS hQ hK hVA hs hp (by omega) call buf ex + · exact J.toB.vdRvmcbA hQ hK hVA hs hp len call buf ex + case writeVmcb => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUWriteVMCB) (by unfold fl4_abi.label.X86VCPUWriteVMCB; rfl) + subst lbl + by_cases hs : Fl4Spec.virtKind = .svm + · by_cases h : 2 ≤ len.val + · exact WP.spec_mono (J.toF.vdWvmcb hK hVA hCap hs hp hk h call buf ex) (fun _ => liftPost) + · exact J.toB.vdWvmcbS hQ hK hVA hs hp (by omega) call buf ex + · exact J.toB.vdWvmcbA hQ hK hVA hs hp len call buf ex + case readMsr => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUReadMSR) (by unfold fl4_abi.label.X86VCPUReadMSR; rfl) + subst lbl + by_cases h : 1 ≤ len.val + · exact J.toB.readMsrJ hQ hK hVA hCap hp hk h call buf ex + · exact J.toB.vdRmsrS hQ hK hVA hp (by omega) call buf ex + case writeMsr => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUWriteMSR) (by unfold fl4_abi.label.X86VCPUWriteMSR; rfl) + subst lbl + by_cases h : 2 ≤ len.val + · exact WP.spec_mono (J.toF.vdWmsr hAT hK hVA hCap hp hk h call buf ex) (fun _ => liftPost) + · exact J.toB.vdWmsrS hQ hK hVA hp (by omega) call buf ex + case enableIoPort => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUEnableIOPort) (by unfold fl4_abi.label.X86VCPUEnableIOPort; rfl) + subst lbl + by_cases hs : Fl4Spec.virtKind = .svm + · exact J.toB.vdEioA hQ hK hVA hs hp len call buf ex + by_cases h : 2 ≤ len.val + · refine J.toB.enableIoPortJ (Q := Q) hQ hK hVA hs hp h call buf ex hsl hbn hc hslot ?_ + intro a' ct first last prior lo hi pc r idx J' hpc hidx hxs _ _ hc' _ hl hfl hlo hhi + subst sl + exact J'.enableIoPortCore hK hp hcan hpc hidx hc' hfl hl hlo hhi + · exact J.toB.vdEioS hQ hK hVA hs hp (by omega) call buf ex + case disableIoPort => + have e := zv_lbl_eqc hl rfl (c := fl4_abi.label.X86VCPUDisableIOPort) (by unfold fl4_abi.label.X86VCPUDisableIOPort; rfl) + subst lbl + by_cases hs : Fl4Spec.virtKind = .svm + · exact J.toB.vdDioA hQ hK hVA hs hp len call buf ex + by_cases h : 2 ≤ len.val + · exact WP.spec_mono (J.toF.disableIoPortJ hK hVA hs hp hk h call buf ex) (fun _ => liftPost) + · exact J.toB.vdDioS hQ hK hVA hs hp (by omega) call buf ex + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/VsCapOps.lean b/proofs/Fl4Proofs/P3/VsCapOps.lean index 2c0ea3563..34acc07de 100644 --- a/proofs/Fl4Proofs/P3/VsCapOps.lean +++ b/proofs/Fl4Proofs/P3/VsCapOps.lean @@ -127,8 +127,8 @@ theorem pam_iff_large (p : U64) : PaM p 4503599625273344#u64 ↔ pam_iff (by decide) mask_large_bits /-- **The alias of a page of a well-placed large frame is well placed.** -/ -theorem vcap_alias {P L4 L3 L2 L1 : Set U64} {ptr rt fa fv q vm : U64} {mm : Bool} - (h : VCapOK P L4 L3 L2 L1 (.Frame ptr .Large rt false mm false fa fv)) +theorem vcap_aliasMap {P L4 L3 L2 L1 : Set U64} {ptr rt fa fv q vm : U64} {mm ep : Bool} + (h : VCapOK P L4 L3 L2 L1 (.Frame ptr .Large rt false mm ep fa fv)) (hq1 : ptr.val ≤ q.val) (hq2 : q.val + 4096 ≤ ptr.val + 2 ^ 21) (hqal : q.val % 4096 = 0) : VCapOK P L4 L3 L2 L1 (.Frame q .Small vm false false false 0#u64 0#u64) := by have hp : PaM ptr 4503599625273344#u64 := by @@ -247,6 +247,14 @@ theorem UtKsOut.pool {th : TypedHeap} (h : UtKsOut ksb mem G) (hM : MdbLinks th have e : fl4_abi.consts.bits.ASID_POOL.val = 12 := by unfold fl4_abi.consts.bits.ASID_POOL; rfl rw [e] at this; simpa using this + +/-- The alias lemma for a native source frame. -/ +theorem vcap_alias {P L4 L3 L2 L1 : Set U64} {ptr rt fa fv q vm : U64} {mm : Bool} + (h : VCapOK P L4 L3 L2 L1 (.Frame ptr .Large rt false mm false fa fv)) + (hq1 : ptr.val ≤ q.val) (hq2 : q.val + 4096 ≤ ptr.val + 2 ^ 21) (hqal : q.val % 4096 = 0) : + VCapOK P L4 L3 L2 L1 (.Frame q .Small vm false false false 0#u64 0#u64) := + vcap_aliasMap h hq1 hq2 hqal + end end diff --git a/proofs/Fl4Proofs/P3/VsDecReply.lean b/proofs/Fl4Proofs/P3/VsDecReply.lean index ba0a9d1e8..93fc9a539 100644 --- a/proofs/Fl4Proofs/P3/VsDecReply.lean +++ b/proofs/Fl4Proofs/P3/VsDecReply.lean @@ -100,14 +100,14 @@ def TacHyp (L4 L3 L2 L1 : Set U64) (s : S) (σ : Fl4Spec.State Unit) (ct : U64) /-- **`TestAndClearAccessed`'s decode checks** against the model's, for any post `Q`: the errors are the model's; on success, the model's slot, and FL4 clears the accessed bit of a page-table word and replies 1 or 0. -/ -theorem tac_gen [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) (σ : Fl4Spec.State Unit) +theorem tac_gen_leaf [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) (σ : Fl4Spec.State Unit) (hR : VsRel P (L.mem s) (L.ksb s) σ) (hPt : PtRel L4 L3 L2 L1 (L.mem s) σ) (hPP : PtPlaced L4 L3 L2 L1) (hPI : PoolsIn P L4 (L.mem s)) (ct : U64) (hct : sched.cur_thread st s = ok ct) (f : vspace.FrameCap) (hfu : f.mapped = true → Vs.UserV f.vaddr) (call : Bool) (Q : core.result.Result Unit error.Exc × S → Prop) (herr : ∀ e e', VsErrRel e e' → ExceptT.run (Fl4Spec.decodeTestAndClearAccessed (Z := Unit) (frameACapG f)) σ = ({(.error e', σ)}, False) → Q (.Err e, s)) - (hok : ∀ b, PtWAll L4 L3 L2 L1 b → P1.Aligned b → ∀ slot, + (hok : ∀ b, (PtW L1 b ∨ PdW L2 b) → P1.Aligned b → ∀ slot, ExceptT.run (Fl4Spec.decodeTestAndClearAccessed (Z := Unit) (frameACapG f)) σ = ({(.ok slot, σ)}, False) → ∀ v : U64, (v = 1#u64 ∨ v = 0#u64) → vspace.reply1 st (L.wr s b (L.mem s b &&& ~~~32#u64)) ct call v ⦃ s2 => Q (.Ok (), s2) ⦄) : @@ -179,12 +179,12 @@ theorem tac_gen [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) ( have hj := vIdx_lt fv 12 have hea : P1.Aligned (peA q (vIdx fv 12)) := by show _ % 8 = 0; rw [peA_val (tbl_fit hqa) hj]; omega - have hb : PtWAll L4 L3 L2 L1 (peA q (vIdx fv 12)) := ⟨q, Or.inr (Or.inr (Or.inr hq)), _, hj, rfl⟩ + have hb : PtW L1 (peA q (vIdx fv 12)) := ⟨q, hq, _, hj, rfl⟩ split - · refine WP.spec_bind (hok _ hb hea _ (hdec.trans hfms) 1#u64 (Or.inl rfl)) ?_ + · refine WP.spec_bind (hok _ (Or.inl hb) hea _ (hdec.trans hfms) 1#u64 (Or.inl rfl)) ?_ rintro s2 h exact (WP.spec_ok _).2 h - · refine WP.spec_bind (hok _ hb hea _ (hdec.trans hfms) 0#u64 (Or.inr rfl)) ?_ + · refine WP.spec_bind (hok _ (Or.inl hb) hea _ (hdec.trans hfms) 0#u64 (Or.inr rfl)) ?_ rintro s2 h exact (WP.spec_ok _).2 h | Large => @@ -239,15 +239,32 @@ theorem tac_gen [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) ( have hj := vIdx_lt fv 21 have hea : P1.Aligned (peA q (vIdx fv 21)) := by show _ % 8 = 0; rw [peA_val (tbl_fit hqa) hj]; omega - have hb : PtWAll L4 L3 L2 L1 (peA q (vIdx fv 21)) := ⟨q, Or.inr (Or.inr (Or.inl hq)), _, hj, rfl⟩ + have hb : PdW L2 (peA q (vIdx fv 21)) := ⟨q, hq, _, hj, rfl⟩ split - · refine WP.spec_bind (hok _ hb hea _ (hdec.trans hfms) 1#u64 (Or.inl rfl)) ?_ + · refine WP.spec_bind (hok _ (Or.inr hb) hea _ (hdec.trans hfms) 1#u64 (Or.inl rfl)) ?_ rintro s2 h exact (WP.spec_ok _).2 h - · refine WP.spec_bind (hok _ hb hea _ (hdec.trans hfms) 0#u64 (Or.inr rfl)) ?_ + · refine WP.spec_bind (hok _ (Or.inr hb) hea _ (hdec.trans hfms) 0#u64 (Or.inr rfl)) ?_ rintro s2 h exact (WP.spec_ok _).2 h +/-- The accessed-bit operation exposes a write to one of the VSpace tables. -/ +theorem tac_gen [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) (σ : Fl4Spec.State Unit) + (hR : VsRel P (L.mem s) (L.ksb s) σ) (hPt : PtRel L4 L3 L2 L1 (L.mem s) σ) (hPP : PtPlaced L4 L3 L2 L1) + (hPI : PoolsIn P L4 (L.mem s)) (ct : U64) (hct : sched.cur_thread st s = ok ct) + (f : vspace.FrameCap) (hfu : f.mapped = true → Vs.UserV f.vaddr) (call : Bool) (Q : core.result.Result Unit error.Exc × S → Prop) + (herr : ∀ e e', VsErrRel e e' → + ExceptT.run (Fl4Spec.decodeTestAndClearAccessed (Z := Unit) (frameACapG f)) σ = ({(.error e', σ)}, False) → + Q (.Err e, s)) + (hok : ∀ b, PtWAll L4 L3 L2 L1 b → P1.Aligned b → ∀ slot, + ExceptT.run (Fl4Spec.decodeTestAndClearAccessed (Z := Unit) (frameACapG f)) σ = ({(.ok slot, σ)}, False) → + ∀ v : U64, (v = 1#u64 ∨ v = 0#u64) → + vspace.reply1 st (L.wr s b (L.mem s b &&& ~~~32#u64)) ct call v ⦃ s2 => Q (.Ok (), s2) ⦄) : + vspace.decode_test_and_clear_accessed st s f call ⦃ Q ⦄ := + tac_gen_leaf s σ hR hPt hPP hPI ct hct f hfu call Q herr + (fun b hw => hok b (hw.elim (fun ⟨q, hq, i, hi, e⟩ => ⟨q, Or.inr (Or.inr (Or.inr hq)), i, hi, e⟩) + (fun ⟨q, hq, i, hi, e⟩ => ⟨q, Or.inr (Or.inr (Or.inl hq)), i, hi, e⟩))) + /-- **Frame `TestAndClearAccessed`** (`DecOKR`, the reply `TacHyp`). -/ theorem decode_invocation_frame_tac [Fl4Proofs.P1.PlainStore st] {P L4 L3 L2 L1 : Set U64} (s : S) (ar : A) (σ : Fl4Spec.State Unit) (hR : VsRel P (L.mem s) (L.ksb s) σ) (hPt : PtRel L4 L3 L2 L1 (L.mem s) σ) (hPP : PtPlaced L4 L3 L2 L1) diff --git a/proofs/Fl4Proofs/P3/VsMdbInv.lean b/proofs/Fl4Proofs/P3/VsMdbInv.lean index db98db64c..3803baba7 100644 --- a/proofs/Fl4Proofs/P3/VsMdbInv.lean +++ b/proofs/Fl4Proofs/P3/VsMdbInv.lean @@ -171,14 +171,14 @@ theorem VsMdbInv.rename (h : VsMdbInv ksb mem G) (e : U64 ≃ U64) /-- **`frameAlias`**: a 4 KiB alias of a page of `src`'s well-placed large RAM frame, inside the window and 4 KiB aligned. -/ theorem VsMdbInv.frameAlias (h : VsMdbInv ksb mem G) {src dest : U64} (hsrc : src ∈ G.chains.flatten) (b : Bool) - {ptr rt fa fv q0 vm : U64} {mm : Bool} (hsC : capV mem src = .Frame ptr .Large rt false mm false fa fv) + {ptr rt fa fv q0 vm : U64} {mm epSrc : Bool} (hsC : capV mem src = .Frame ptr .Large rt false mm epSrc fa fv) (hcd : capV mem' dest = .Frame q0 .Small vm false false false 0#u64 0#u64) (hq1 : ptr.val ≤ q0.val) (hq2 : q0.val + 4096 ≤ ptr.val + 2 ^ 21) (hqal : q0.val % 4096 = 0) (hc : ∀ z ∈ G.chains.flatten, capV mem' z = capV mem z) : VsMdbInv ksb mem' (insG G src dest b) := by obtain ⟨⟨P, L4, L3, L2, L1, hV⟩, hU⟩ := h have hs := hV src hsrc rw [hsC] at hs - refine ⟨⟨P, L4, L3, L2, L1, hV.insert hsrc b (by rw [hcd]; exact vcap_alias hs hq1 hq2 hqal) + refine ⟨⟨P, L4, L3, L2, L1, hV.insert hsrc b (by rw [hcd]; exact vcap_aliasMap hs hq1 hq2 hqal) fun z hz _ hok => by rw [hc z hz]; exact hok⟩, hU.insert hsrc b (by rw [hcd]; trivial) fun z hz _ hok => by rw [hc z hz]; exact hok⟩ diff --git a/proofs/Fl4Proofs/P3/VsReplyTop.lean b/proofs/Fl4Proofs/P3/VsReplyTop.lean index f8e4de892..fad2f8fa8 100644 --- a/proofs/Fl4Proofs/P3/VsReplyTop.lean +++ b/proofs/Fl4Proofs/P3/VsReplyTop.lean @@ -931,6 +931,34 @@ theorem stsAct_twice {σ : Fl4Spec.State Unit} {t : Fl4Spec.ObjRef} {y1 y2 : Fl4 unfold Notif.stsAct; rw [if_neg c] rw [e1, updK_updK] +/-- The one-word reply absorbs the abstract Restart before returning to Running. -/ +theorem specTail_one_after_restart (σ : Fl4Spec.State Unit) (ct : U64) + (x : Fl4Spec.Tcb) (call : Bool) (v : U64) : + ((), Notif.stsAct (Notif.updK σ ct.bv + (.tcb { (if call then Endp.replyTcb x v.bv else x) with tcbState := .running })) ct.bv) ∈ + (specTail call ct.bv [v.bv] + (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv)).1 := by + have hk1 : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv).kheap ct.bv = + some (.tcb { x with tcbState := .restart }) := by simp [Notif.stsAct_kheap] + rw [specTail_restart hk1 rfl call v.bv] + have hsch : ∀ y : Fl4Spec.Tcb, y.tcbSchedContext = x.tcbSchedContext → Fl4Spec.runnable y.tcbState = true → + Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) = + Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb y)) := fun y h1 h2 => + schedulable_updK_tcb (by rw [h2]; rfl) h1.symm + cases call + · simp only [Bool.false_eq_true, ↓reduceIte] + rw [Notif.setThreadState_eq .running hk1, stsAct_twice (hsch { x with tcbState := .running } rfl rfl)] + exact Set.mem_singleton _ + · simp only [↓reduceIte] + have hkC : (Notif.updK (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) ct.bv + (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv))).kheap ct.bv = + some (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv)) := by simp + rw [Notif.setThreadState_eq .running hkC, updK_updK] + have ey : ({ Endp.replyTcb { x with tcbState := .restart } v.bv with tcbState := .running } : Fl4Spec.Tcb) = + { Endp.replyTcb x v.bv with tcbState := .running } := rfl + rw [ey, stsAct_twice (hsch { Endp.replyTcb x v.bv with tcbState := .running } rfl rfl)] + exact Set.mem_singleton _ + /-- **`TacHypX` at `FinX` of the composite relation is a theorem**: FL4 replies without `Restart` from the state with the accessed bit cleared; the spec's `Restart` before its reply is absorbed by the final `Running` @@ -978,29 +1006,10 @@ theorem tacHypX_top {A : Type} {AR : A → Fl4Spec.Cr3 → Prop} (s : S) (ar : A simp only [Set.singleton_eq_singleton_iff, Prod.mk.injEq, true_and] at this exact this.symm subst e - have hk1 : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv).kheap ct.bv = - some (.tcb { x with tcbState := .restart }) := by simp [Notif.stsAct_kheap] refine ⟨((), Notif.stsAct (Notif.updK σ ct.bv (.tcb { (if call then Endp.replyTcb x v.bv else x) with tcbState := .running })) ct.bv), ?_, hI2.relTop, hI2.2.2.2.2⟩ - rw [specTail_restart hk1 rfl call v.bv] - have hsch : ∀ y : Fl4Spec.Tcb, y.tcbSchedContext = x.tcbSchedContext → Fl4Spec.runnable y.tcbState = true → - Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) = - Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb y)) := fun y h1 h2 => - schedulable_updK_tcb (by rw [h2]; rfl) h1.symm - cases call - · simp only [Bool.false_eq_true, ↓reduceIte] - rw [Notif.setThreadState_eq .running hk1, stsAct_twice (hsch { x with tcbState := .running } rfl rfl)] - exact Set.mem_singleton _ - · simp only [↓reduceIte] - have hkC : (Notif.updK (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) ct.bv - (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv))).kheap ct.bv = - some (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv)) := by simp - rw [Notif.setThreadState_eq .running hkC, updK_updK] - have ey : ({ Endp.replyTcb { x with tcbState := .restart } v.bv with tcbState := .running } : Fl4Spec.Tcb) = - { Endp.replyTcb x v.bv with tcbState := .running } := rfl - rw [ey, stsAct_twice (hsch { Endp.replyTcb x v.bv with tcbState := .running } rfl rfl)] - exact Set.mem_singleton _ + exact specTail_one_after_restart σ ct x call v set_option maxHeartbeats 4000000 in /-- **`TacHypX` at `FinXT`.** -/ @@ -1049,29 +1058,10 @@ theorem tacHypX_topT {A : Type} {AR : A → Fl4Spec.Cr3 → Prop} (s : S) (ar : simp only [Set.singleton_eq_singleton_iff, Prod.mk.injEq, true_and] at this exact this.symm subst e - have hk1 : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv).kheap ct.bv = - some (.tcb { x with tcbState := .restart }) := by simp [Notif.stsAct_kheap] refine ⟨((), Notif.stsAct (Notif.updK σ ct.bv (.tcb { (if call then Endp.replyTcb x v.bv else x) with tcbState := .running })) ct.bv), ?_, hI2.relTop, hI2.2.2.2.2, ⟨G, hI2.1, hI2.2.1, hI2.2.2.1⟩, hks2.trans hksb, szKeep_stsAct_tcb _ _ _⟩ - rw [specTail_restart hk1 rfl call v.bv] - have hsch : ∀ y : Fl4Spec.Tcb, y.tcbSchedContext = x.tcbSchedContext → Fl4Spec.runnable y.tcbState = true → - Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) = - Fl4Spec.schedulable ct.bv (Notif.updK σ ct.bv (.tcb y)) := fun y h1 h2 => - schedulable_updK_tcb (by rw [h2]; rfl) h1.symm - cases call - · simp only [Bool.false_eq_true, ↓reduceIte] - rw [Notif.setThreadState_eq .running hk1, stsAct_twice (hsch { x with tcbState := .running } rfl rfl)] - exact Set.mem_singleton _ - · simp only [↓reduceIte] - have hkC : (Notif.updK (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) ct.bv - (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv))).kheap ct.bv = - some (.tcb (Endp.replyTcb { x with tcbState := .restart } v.bv)) := by simp - rw [Notif.setThreadState_eq .running hkC, updK_updK] - have ey : ({ Endp.replyTcb { x with tcbState := .restart } v.bv with tcbState := .running } : Fl4Spec.Tcb) = - { Endp.replyTcb x v.bv with tcbState := .running } := rfl - rw [ey, stsAct_twice (hsch { Endp.replyTcb x v.bv with tcbState := .running } rfl rfl)] - exact Set.mem_singleton _ + exact specTail_one_after_restart σ ct x call v end diff --git a/proofs/Fl4Proofs/P3/VsSubRel.lean b/proofs/Fl4Proofs/P3/VsSubRel.lean index 2a2e6ac06..678b5b5f4 100644 --- a/proofs/Fl4Proofs/P3/VsSubRel.lean +++ b/proofs/Fl4Proofs/P3/VsSubRel.lean @@ -275,13 +275,13 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] set_option maxHeartbeats 4000000 in /-- **One alias insert** (see the module docstring). -/ -theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S → A → Fl4Spec.State Unit → Prop} +theorem sub_stepMap {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S → A → Fl4Spec.State Unit → Prop} (hH : VsSubHyps st A P L4 L3 L2 L1 th SR) (hPl : Placed th) (hPP : PtPlaced L4 L3 L2 L1) {pp : U64} {rs : Nat} (hpp : th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) - {ptr rt fa fv : U64} {mm : Bool} {rv : Bool} (s : S) (a : A) (σ : Fl4Spec.State Unit) (G : MdbGhost) + {ptr rt fa fv : U64} {mm ep : Bool} {rv : Bool} (s : S) (a : A) (σ : Fl4Spec.State Unit) (G : MdbGhost) (hVP : VsPlaced P (L.ksb s)) (hVO : ∀ b, VsWrite P (L.ksb s) b → OutsideObjects th b) (hPO : ∀ b, PtWAll L4 L3 L2 L1 b → OutsideObjects th b) - (hS : SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm false fa fv) rv s a σ G) + (hS : SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm ep fa fv) rv s a σ G) (hal : ptr.val % 2 ^ 21 = 0) {dp : U64} {r : Nat} (hdp : th dp = some (.cnode r)) (hr : r < 64) {k : Nat} (hk : k < 2 ^ r) (hdst : capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 k)) = ok .Null) @@ -291,7 +291,7 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S (slotAddr dp.bv (BitVec.ofNat 64 k)) ⦃ s' => ∃ σ', Fl4Spec.capInsert (Z := Unit) (absCap (.Frame q .Small vm false false false 0#u64 0#u64)) (pp.bv, idx) (dp.bv, Fl4Spec.natToCref r k) σ = ({((), σ')}, False) ∧ - SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' + SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm ep fa fv) rv s' a σ' (insG G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ L.ksb s' = L.ksb s ∧ MdbStep (L.mem s) G (L.mem s') (insG G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ @@ -300,7 +300,7 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S set src := cslotAddr (pp.bv, idx) with hsrcdef set dest := slotAddr dp.bv (BitVec.ofNat 64 k) with hdestdef set c : capability.Cap := .Frame q .Small vm false false false 0#u64 0#u64 with hcdef - set srcC : capability.Cap := .Frame ptr .Large rt false mm false fa fv with hsrcCdef + set srcC : capability.Cap := .Frame ptr .Large rt false mm ep fa fv with hsrcCdef have hAs : AbsSlot th (pp.bv, idx) := ⟨pp, rfl, Or.inl (by simpa [hidx] using hpp)⟩ have hs : IsSlot th src := hAs.isSlot have hd : IsSlot th dest := ⟨dp, k, Or.inl ⟨r, hdp, hk⟩, rfl⟩ @@ -341,7 +341,7 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S set A := absCap c with hAdef have hsetd := setCap_cnode (Z := Unit) A hkd hwfd hlen have hci := capInsert_eq hgs hgd (setUntyped_skip (by simp [Fl4Spec.isUntypedCap, hAdef, absCap])) hsetd rfl rfl - have hbs : baseF srcC = ptr.val := (frame_range ptr .Large rt false mm fa fv false).1 + have hbs : baseF srcC = ptr.val := (frame_range ptr .Large rt false mm fa fv ep).1 have hov : ∀ w ∈ G.chains.flatten, Ovl (absCap c) (absCap (capV (L.mem s) w)) → isFrame (capV (L.mem s) w) = true ∧ ∃ ch ∈ G.chains, src ∈ ch ∧ w ∈ ch := fun w hw h => hfr w hw q vm (by rw [hbs]; exact hq1) (by rw [hbs]; omega) h @@ -382,7 +382,7 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S exact this.symm -- the alias's range have hsF : isFrame (capV (L.mem s) src) = true := by rw [capV_of_capAt hcap]; rfl - obtain ⟨bs, ts⟩ := frame_range ptr .Large rt false mm fa fv false + obtain ⟨bs, ts⟩ := frame_range ptr .Large rt false mm fa fv ep obtain ⟨bc, tc⟩ := frame_range q .Small vm false false 0#u64 0#u64 false have hmL : (maskF (fbitsF .Large)).val = 2 ^ 21 - 1 := by rw [maskF_val (by rw [fbitsF_val]; decide), fbitsF_val]; rfl @@ -461,7 +461,7 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S hq1 (by omega) (Vs.large_aligned hV hM) have hVC' : VsCapsW P L4 L3 L2 L1 (L.mem s') (insG G src dest rv) := hVC.insert_copy hsrcm rv (fun _ => by - rw [hctx.cd]; exact (vcap_alias (hVC.atOK hM hs hcap (by simp) (fun _ _ _ => by simp)) hq1 hq2 hqal).toW) + rw [hctx.cd]; exact (vcap_aliasMap (hVC.atOK hM hs hcap (by simp) (fun _ _ _ => by simp)) hq1 hq2 hqal).toW) (fun h => by rw [hctx.cz hsrcm]; exact h) (fun z hz _ _ => hctx.cz hz) have hMS : MdbStep (L.mem s) G (L.mem s') (insG G src dest rv) := MdbStep.frameAlias hM hI rv hsrcm hdestm (capV_of_capAt hcap) hctx.cd hq1 (by omega) @@ -477,6 +477,30 @@ theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S · rw [if_pos h2, h2, hcap]; rfl · rw [if_neg h2] +/-- One alias insert from a native-map source. -/ +theorem sub_step {A : Type} {th : TypedHeap} {P L4 L3 L2 L1 : Set U64} {SR : S → A → Fl4Spec.State Unit → Prop} + (hH : VsSubHyps st A P L4 L3 L2 L1 th SR) (hPl : Placed th) (hPP : PtPlaced L4 L3 L2 L1) + {pp : U64} {rs : Nat} (hpp : th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) + {ptr rt fa fv : U64} {mm : Bool} {rv : Bool} (s : S) (a : A) (σ : Fl4Spec.State Unit) (G : MdbGhost) + (hVP : VsPlaced P (L.ksb s)) + (hVO : ∀ b, VsWrite P (L.ksb s) b → OutsideObjects th b) (hPO : ∀ b, PtWAll L4 L3 L2 L1 b → OutsideObjects th b) + (hS : SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm false fa fv) rv s a σ G) + (hal : ptr.val % 2 ^ 21 = 0) + {dp : U64} {r : Nat} (hdp : th dp = some (.cnode r)) (hr : r < 64) {k : Nat} (hk : k < 2 ^ r) + (hdst : capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 k)) = ok .Null) + {q vm : U64} (hq1 : ptr.val ≤ q.val) (hq2 : q.val + 4096 ≤ ptr.val + 2 ^ 21) (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) + (hqal : q.val % 4096 = 0) : + cdt.insert st s (.Frame q .Small vm false false false 0#u64 0#u64) (cslotAddr (pp.bv, idx)) + (slotAddr dp.bv (BitVec.ofNat 64 k)) ⦃ s' => ∃ σ', + Fl4Spec.capInsert (Z := Unit) (absCap (.Frame q .Small vm false false false 0#u64 0#u64)) (pp.bv, idx) + (dp.bv, Fl4Spec.natToCref r k) σ = ({((), σ')}, False) ∧ + SubRel st th P L4 L3 L2 L1 SR (cslotAddr (pp.bv, idx)) (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' + (insG G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + L.ksb s' = L.ksb s ∧ + MdbStep (L.mem s) G (L.mem s') (insG G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + ∀ y, IsSlot th y → y ≠ slotAddr dp.bv (BitVec.ofNat 64 k) → capAt (L.mem s') y = capAt (L.mem s) y ⦄ := + sub_stepMap hH hPl hPP hpp hidx s a σ G hVP hVO hPO hS hal hdp hr hk hdst hq1 hq2 hvm hqal + /-- The spec's insert of alias `d.1` into slot `d.2`. -/ def subIns (src : Fl4Spec.CslotPtr) (base : Fl4Spec.ObjRef) (R : Fl4Spec.VMRights) (d : Nat × Fl4Spec.CslotPtr) : diff --git a/proofs/Fl4Proofs/P3/XTopIoPort.lean b/proofs/Fl4Proofs/P3/XTopIoPort.lean index 0ef5d1d4c..4185b4bb8 100644 --- a/proofs/Fl4Proofs/P3/XTopIoPort.lean +++ b/proofs/Fl4Proofs/P3/XTopIoPort.lean @@ -72,7 +72,7 @@ def PortInXHyp (AR : A → Fl4Spec.Cr3 → Prop) (s : S) (ar : A) (σ : Fl4Spec. /-- **The IO port cap at any `X` reached by the primitive steps** (as `decode_invocation_ioportX`; `In` given at `X`). -/ -theorem decode_invocation_ioportXS {AR : A → Fl4Spec.Cr3 → Prop} +theorem decode_invocation_ioportXQ {AR : A → Fl4Spec.Cr3 → Prop} (th : TypedHeap) (hP : Placed th) (s : S) (ar : A) (σ : Fl4Spec.State Unit) (lbl : U64) (slbl : Fl4Spec.Data) (hlbl : PortLabel lbl slbl) (length buf ct : U64) (hct : sched.cur_thread st s = ok ct) (args : List U64) @@ -82,9 +82,15 @@ theorem decode_invocation_ioportXS {AR : A → Fl4Spec.Cr3 → Prop} (hact : OutsideObjects th (L.nodeAt s (L.cpu s) layout.node.SCHED_ACTION)) (first last : U64) (hfl : first.val ≤ last.val) (hl16 : last.val < 65536) (call : Bool) (hout : ∀ (a : A) p z d, ∃ a', arI.port_out a p z d = ok a') - {Z : XSets} (hth : Z.th = th) (hXZ : XTopAt (L := L) AR Z s ar σ) (hC : CurRun σ) + {Z : XSets} (hth : Z.th = th) (hXZ : XTopAt (L := L) AR Z s ar σ) {X : S → A → Fl4Spec.State Unit → Prop} (hX0 : X s ar σ) - (hstep : ∀ s' a' σ', Steps (L := L) arI th s ar σ s' a' σ' → X s' a' σ') + (hOut : ∀ (s' : S) (a' : A) (σ1 : Fl4Spec.State Unit) (ms : Fl4Spec.MachineState) (p raw : U64) + (x : Fl4Spec.Tcb), σ.kheap ct.bv = some (.tcb x) → + sched.set_thread_state st s ct sched.TS_RESTART = ok s' → + Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) → + ms.underlyingMemory = σ1.machineState.underlyingMemory → + arI.port_out ar p ⟨BitVec.ofNat 64 (portSz lbl)⟩ raw = ok a' → + X s' a' { σ1 with machineState := ms }) (hXX : ∀ s' a' σ', X s' a' σ' → XTop (L := L) AR s' a' σ') (slot : U64) (blk don fp : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) (sl : Fl4Spec.CslotPtr) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) @@ -124,12 +130,7 @@ theorem decode_invocation_ioportXS {AR : A → Fl4Spec.Cr3 → Prop} have hst : Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) := by rw [hcur, Notif.setThreadState_eq .restart hk] obtain ⟨ms, hu, hmem⟩ := port_out_perform σ1 (BitVec.ofNat 16 port.val) raw.bv (portSz lbl) - have hstp : Steps (L := L) arI th s ar σ s' a' { σ1 with machineState := ms } := - (Steps.restart arI hcur hk htcb hr1 hst hC).trans arI - ((Steps.ksSpec arI (s := s') (σ := σ1) (σ' := { σ1 with machineState := ms }) - (by constructor <;> first | rfl | exact hu) rfl rfl (fun h => ⟨h.st, h.node⟩) (fun h => h)).trans arI - (Steps.arch arI (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨_, _, _, ha1⟩)))))))) - have hXa := hstep _ _ _ hstp + have hXa := hOut _ _ _ _ _ _ _ hk hr1 hst hu ha1 obtain ⟨Z', hZ'⟩ := hXX _ _ _ hXa exact Or.inr ⟨_, DecOut.of_eq (run_liftME_ok (run_liftME_ok hrun)), σ1, hst, (.ok [], { σ1 with machineState := ms }), hmem, ⟨Z'.th, Z'.G, Or.inl ⟨rfl, rfl⟩, hZ'.rel.1, hZ'.rel.2.1, hZ'.rel.2.2.1, hZ'.rel.2.2.2.1, @@ -139,6 +140,36 @@ theorem decode_invocation_ioportXS {AR : A → Fl4Spec.Cr3 → Prop} fun res h => herr res (fun _ _ _ _ h => h.elim) h +/-- I/O-port outputs and other labels at any relation closed under the native steps. -/ +theorem decode_invocation_ioportXS {AR : A → Fl4Spec.Cr3 → Prop} + (th : TypedHeap) (hP : Placed th) (s : S) (ar : A) (σ : Fl4Spec.State Unit) + (lbl : U64) (slbl : Fl4Spec.Data) (hlbl : PortLabel lbl slbl) + (length buf ct : U64) (hct : sched.cur_thread st s = ok ct) (args : List U64) + (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (hcur : σ.curThread = ct.bv) (htcb : th ct = some .tcb) + (hact : OutsideObjects th (L.nodeAt s (L.cpu s) layout.node.SCHED_ACTION)) + (first last : U64) (hfl : first.val ≤ last.val) (hl16 : last.val < 65536) (call : Bool) + (hout : ∀ (a : A) p z d, ∃ a', arI.port_out a p z d = ok a') + {Z : XSets} (hth : Z.th = th) (hXZ : XTopAt (L := L) AR Z s ar σ) (hC : CurRun σ) + {X : S → A → Fl4Spec.State Unit → Prop} (hX0 : X s ar σ) + (hstep : ∀ s' a' σ', Steps (L := L) arI th s ar σ s' a' σ' → X s' a' σ') + (hXX : ∀ s' a' σ', X s' a' σ' → XTop (L := L) AR s' a' σ') + (slot : U64) (blk don fp : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) (ci : Fl4Spec.CapRef) + (sl : Fl4Spec.CslotPtr) (excaps : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) (buffer : Option Fl4Spec.ObjRef) + (hIn : 64 ≤ lbl.val ∧ lbl.val ≤ 66 → XCap (L := L) arI X s ar σ lbl length slot (.IoPort first last 0#u64) blk + call don fp buf extra slbl (args.map UScalar.bv) ci sl excaps buffer ct) : + XCap (L := L) arI X s ar σ lbl length slot (.IoPort first last 0#u64) blk call don fp buf extra + slbl (args.map UScalar.bv) ci sl excaps buffer ct := + decode_invocation_ioportXQ arI th hP s ar σ lbl slbl hlbl length buf ct hct args hlen hargs hcur htcb + hact first last hfl hl16 call hout hth hXZ hX0 + (fun s' a' σ1 ms _ _ _ hk hr1 hst hu hp => + hstep _ _ _ ((Steps.restart arI hcur hk htcb hr1 hst hC).trans arI + ((Steps.ksSpec arI (s := s') (σ := σ1) (σ' := { σ1 with machineState := ms }) + (by constructor <;> first | rfl | exact hu) rfl rfl (fun h => ⟨h.st, h.node⟩) id).trans arI + (Steps.arch arI (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨_, _, _, hp⟩)))))))))) + hXX slot blk don fp extra ci sl excaps buffer hIn + /-- **`IoXHyp` for the IO port cap**: `Out`, the errors and the other labels proved; `In` from `PortInXHyp`. Beyond `port_out_refines`' hypotheses, `XTopAt` at its typed heap, `KsApart`, the current thread diff --git a/proofs/Fl4Proofs/P3/XTopJointBudgetF.lean b/proofs/Fl4Proofs/P3/XTopJointBudgetF.lean index 266960912..bd35c4984 100644 --- a/proofs/Fl4Proofs/P3/XTopJointBudgetF.lean +++ b/proofs/Fl4Proofs/P3/XTopJointBudgetF.lean @@ -48,14 +48,16 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 8000000 in /-- **The current thread's restart at `J` from a runnable current thread** -(XTopJointTcbInstall's `JAtZ.restartJ` without `Entered`). -/ -theorem JAtZ.restartRunJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} +(XTopJointTcbInstall's `JAtZ.restartJ` without `Entered`; (mmuAD gen 42b70) over `JAtZB` in place, by XTopJointRest's +`JAtZB.restartJB`, with the native footprint `NatFoot`: the `TFoot` writes, one TCB's state changed to `Restart`). -/ +theorem JAtZB.restartRunJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrun : Fl4Spec.runnable x.tcbState = true) : ∃ s1 σ1, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ σ1 = Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv ∧ sched.set_thread_state st s ct sched.TS_RESTART = ok s1 ∧ - ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s1 a σ1 := by + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' s1 a σ1 ∧ + NatFoot (L := L) Z s σ s1 σ1 := by obtain ⟨hcur, -, -⟩ := J.curEq hct have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 have hDS : DState (L := L) Z.th s σ Z.G := ⟨J.xtop.rel.2.1, J.del, J.xtop.rel.2.2.1⟩ @@ -67,15 +69,29 @@ theorem JAtZ.restartRunJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : have := congrArg (fun q => ((), σ1) ∈ q.1) hst simp only [Set.mem_singleton_iff, Prod.mk.injEq, true_and] at this exact of_eq_true this - have h := XTopAt.restart J.xtop hcur hk hrun - rw [hs1, WP.spec_ok] at h - obtain ⟨hX1, hSS, hk1⟩ := h - obtain ⟨hkb, hkz⟩ := kback_ksz_upd (σ' := Notif.stsAct (Notif.updK σ ct.bv - (.tcb { x with tcbState := .restart })) ct.bv) hk (by rw [stsAct_kheap]; rfl) - obtain ⟨Ac', Lst', J1⟩ := J.restartSJ (jStepHyps arI) hcur hk htcb hrun hs1 - refine ⟨s1, σ1, hst1, e, hs1, Ac', Lst', D, ?_⟩ + obtain ⟨Lst', J1, hwT⟩ := J.restartJB hcur hk htcb hrun hs1 + have hK1 : NatK σ (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) := + natK_kh (R := fun _ o o' => ZvChg o o') (fun _ _ _ h => h) fun p => by + rw [stsAct_kheap] + by_cases hp : p = ct.bv + · subst hp + refine Or.inr ⟨.tcb x, .tcb { x with tcbState := .restart }, hk, by simp [Notif.updK], ?_⟩ + exact zvChg_tcb fun h => by cases h + · exact Or.inl (by simp [Notif.updK, hp]) + refine ⟨s1, σ1, hst1, e, hs1, Ac, Lst', D, ?_⟩ subst e - exact J1 + exact ⟨J1, NatFoot.ofT J.xtop hwT (fun _ h => J.tfoot_nh h) hK1⟩ + +/-- `JAtZB.restartRunJ` at `JAtZ` (mmuAD gen 42b70: `JAtZB.toJN`). -/ +theorem JAtZ.restartRunJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) + (hrun : Fl4Spec.runnable x.tcbState = true) : + ∃ s1 σ1, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + σ1 = Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv ∧ + sched.set_thread_state st s ct sched.TS_RESTART = ok s1 ∧ + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s1 a σ1 := by + obtain ⟨s1, σ1, h1, h2, h3, Ac', Lst', D', B, F⟩ := J.toB.restartRunJ hct hk hrun + exact ⟨s1, σ1, h1, h2, h3, Ac', Lst', D', B.toJN J F⟩ set_option maxHeartbeats 16000000 in /-- **`budget_ok` at `J`, when it stops the system call** (KENTRY-PLAN item 10, @@ -115,9 +131,10 @@ theorem JAtZ.budgetOkF (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : · have hr' : r = false := by simpa using hr subst hr' simp only [Bool.false_eq_true, ↓reduceIte] - obtain ⟨ha2, σ2, hcb, hK, Lst2, J2⟩ := hB rfl - simp only at ha2 J2 + obtain ⟨ha2, σ2, hcb, hK, Lst2, J2, F2⟩ := hB rfl + simp only at ha2 J2 F2 subst ha2 + have J2 := J2.toJN J F2 have hct' : sched.cur_thread st s2 = ok ct := by rw [hct]; exact cur_thread_eq s2 obtain ⟨hcur2, -, -⟩ := J2.curEq hct' obtain ⟨xt, hkt, -, -⟩ := hC1.tcb diff --git a/proofs/Fl4Proofs/P3/XTopJointBudgetT.lean b/proofs/Fl4Proofs/P3/XTopJointBudgetT.lean index 3963adc5a..ceb43618c 100644 --- a/proofs/Fl4Proofs/P3/XTopJointBudgetT.lean +++ b/proofs/Fl4Proofs/P3/XTopJointBudgetT.lean @@ -5,7 +5,7 @@ fault blocks it** (KENTRY-PLAN item 10, the false branch, the case XTopJointBudgetF's `NoTmoSend` leaves: an endpoint timeout handler and a non-round-robin SC; here its endpoint idle or sending). -* `JHole.checkBudgetT`: FL4's `check_budget` returning `false` at the hole +* `JHole.checkBudgetT` (`checkBudgetTA` under `ResumeCurThread`): FL4's `check_budget` returning `false` at the hole after `update_timestamp`: the insufficient head, then ScChargeT's `JHole.chargeBudgetTmoJ`; the spec's `check_budget` has an outcome `false` at the state after. @@ -14,6 +14,10 @@ non-round-robin SC; here its endpoint idle or sending). returns `false`: the spec's `update_time_stamp; check_budget_restart` has an outcome `false` with `JAtZ` after (the restart branch for a still runnable current thread by `JAtZ.restartRunJ`, else nothing). + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2) `JHole.checkBudgetT` takes no `JExt` at the hole's base: it ends +at `JAtZB` with `NatFoot` from the base (ScChargeT's `JTH.j0 : JAtZB`); `JAtZ.budgetOkT` gets `JAtZ` back by +`JAtZB.toJN` (statement unchanged). -/ import Fl4Proofs.P3.ScChargeT import Fl4Proofs.P3.XTopJointBudgetF @@ -31,9 +35,9 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 8000000 in /-- **`check_budget` charging from a `JHole`, the current thread's timeout fault blocking it** (module docstring). -/ -theorem JHole.checkBudgetT {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} +theorem JHole.checkBudgetTA {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) - (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -44,7 +48,8 @@ theorem JHole.checkBudgetT {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) : sched.check_budget st arI s a ⦃ res => res.1 = false → ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ).1, z.1 = false ∧ ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ⦄ := by + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.2.1 z.2 ⦄ := by have hS := Hh.xtop.fin.1.1.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC @@ -68,7 +73,7 @@ theorem JHole.checkBudgetT {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} · rw [if_neg hbt] have hbf : b = false := by simpa using hbt subst hbf - refine WP.spec_bind (Hh.chargeBudgetTmoJ hAT hC hni hres hnq hmrt hmb hkt hrr hth hper hcb + refine WP.spec_bind (Hh.chargeBudgetTmoJA hAT hC hni hres hnq hmrt hmb hkt hrr hth hper hcb (nodeW st s Z.c layout.node.CONSUMED)) ?_ rintro ⟨s1, a1⟩ ⟨z, hz, V, Ac', Lst', D', J'⟩ refine (WP.spec_ok _).2 fun _ => ⟨(false, z.2), ?_, rfl, V, Ac', Lst', D', J'⟩ @@ -82,6 +87,24 @@ theorem JHole.checkBudgetT {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} rw [nd_gets_bind] exact mem_bind_nd (x := z) hz' (by simp [pure, Fl4Spec.NonDet.pure]) +/-- `JHole.checkBudgetTA` under `ResumeCurThread` (mmuAD gen 42b70: ScChargeTA's generalised copy is now the proof). -/ +theorem JHole.checkBudgetT {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hres : σ.schedulerAction = .resumeCurThread) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) + (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) + (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) : + sched.check_budget st arI s a ⦃ res => res.1 = false → ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ).1, + z.1 = false ∧ ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' res.2.1 res.2.2 z.2 ∧ + NatFoot (L := L) Z s0 σ0 res.2.1 z.2 ⦄ := + Hh.checkBudgetTA hAT hC hni (Or.inl hres) hnq hmrt hmb hkt hrr hth hper hcb + set_option maxHeartbeats 16000000 in /-- **`budget_ok` at `J`, when it stops the system call and the current thread's timeout fault blocks it** (module docstring; the clock [P] @@ -129,9 +152,10 @@ theorem JAtZ.budgetOkT (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : · have hr' : rb = false := by simpa using hr subst hr' simp only [Bool.false_eq_true, ↓reduceIte] - obtain ⟨⟨zb, σ2⟩, hz, hzb, V, Ac2, Lst2, D2, J2⟩ := hB rfl - simp only at hzb J2 + obtain ⟨⟨zb, σ2⟩, hz, hzb, V, Ac2, Lst2, D2, J2, F2⟩ := hB rfl + simp only at hzb J2 F2 subst hzb + have J2 := J2.toJN J F2 have hct' : sched.cur_thread st s2 = ok ct := by rw [hct]; exact cur_thread_eq s2 obtain ⟨hcur2, -, -⟩ := J2.curEq hct' have htcb : (Z.mv Z.G V).th ct = some .tcb := (J2.xtop.curTcb hcur2).1 diff --git a/proofs/Fl4Proofs/P3/XTopJointBudgetTR.lean b/proofs/Fl4Proofs/P3/XTopJointBudgetTR.lean index 718383091..6ed4fcce6 100644 --- a/proofs/Fl4Proofs/P3/XTopJointBudgetTR.lean +++ b/proofs/Fl4Proofs/P3/XTopJointBudgetTR.lean @@ -73,9 +73,10 @@ theorem JAtZ.budgetOkTR (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : · have hr' : rb = false := by simpa using hr subst hr' simp only [Bool.false_eq_true, ↓reduceIte] - obtain ⟨⟨zb, σ2⟩, hz, hzb, V, Ac2, Lst2, D2, J2⟩ := hB rfl - simp only at hzb J2 + obtain ⟨⟨zb, σ2⟩, hz, hzb, V, Ac2, Lst2, D2, J2, F2⟩ := hB rfl + simp only at hzb J2 F2 subst hzb + have J2 := J2.toJN J F2 have hct' : sched.cur_thread st s2 = ok ct := by rw [hct]; exact cur_thread_eq s2 obtain ⟨hcur2, -, -⟩ := J2.curEq hct' have htcb : (Z.mv Z.G V).th ct = some .tcb := (J2.xtop.curTcb hcur2).1 diff --git a/proofs/Fl4Proofs/P3/XTopJointCopyRegs.lean b/proofs/Fl4Proofs/P3/XTopJointCopyRegs.lean index 1db3fb89a..d20b5791d 100644 --- a/proofs/Fl4Proofs/P3/XTopJointCopyRegs.lean +++ b/proofs/Fl4Proofs/P3/XTopJointCopyRegs.lean @@ -32,35 +32,59 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 4000000 in /-- **A scheduler step at `J`** (`stepClosed_jat`'s scheduler case, with -XTopJointRest's `jowes_sched`, no premise). -/ -theorem JAtZ.schedJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) {s' : S} {σ' : Fl4Spec.State Unit} +XTopJointRest's `jowes_sched`, no premise; (mmuAD gen 42b70) over `JAtZB` in place, by `jowes_schedDB`). -/ +theorem JAtZB.schedJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s ar σ) {s' : S} {σ' : Fl4Spec.State Unit} (hS : SchedStep (L := L) Z.th s σ s' σ') : - ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' := by + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' := by have hX := J.xtop have hX1 := hX.schedStep J.ks J.thT hS have hW := (hS.2.1 Z.N Z.T Z.C Z.c J.thT hX.fin.1.1.1 hX.fin.1.1.2.2.1).2.1 have hSS : SlotsSame Z.th (L.mem s) (L.mem s') := hX.slotsSame_of hW fun b hb => schW_oobj hX.fin.1.1.1.placed.tcb hb - obtain ⟨Ac', Lst', R⟩ := jowes_sched arI s s' ar σ σ' hS Z H Cs Ac Lst D rfl J hX1 - exact ⟨Ac', Lst', D, J.cs_frameK (hvn := J.vsW hW fun b hb => schW_oobj hX.fin.1.1.1.placed.tcb hb) hW.1 hX1 (KBack.of_kheap hS.1.kh) (IpcFrKeep.of_kheap hS.1.kh) (J.carry.frame subset_rfl (IpcFrKeep.of_kheap hS.1.kh) ((KSz.of_kheap hS.1.kh))) (JCs.same J hSS (KSz.of_kheap hS.1.kh)) R (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) (J.vkeep_of hW fun _ hb => J.schW_nv hb) + obtain ⟨Ac', Lst', R⟩ := jowes_schedDB arI s s' ar σ σ' hS Z H Cs Ac Lst D rfl J hX1 + exact ⟨Ac', Lst', D, J.cs_frameK (hvn := J.vsW hW fun b hb => schW_oobj hX.fin.1.1.1.placed.tcb hb) hW.1 hX1 (KBack.of_kheap hS.1.kh) (IpcFrKeep.of_kheap hS.1.kh) (J.carry.frame subset_rfl (IpcFrKeep.of_kheap hS.1.kh) ((KSz.of_kheap hS.1.kh))) (JCs.sameB J hSS (KSz.of_kheap hS.1.kh)) R (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) hSS (dbgKeep_of_writes J.blk hW fun _ hb => J.schW_notDbg hb) hS.1.idle⟩ +/-- `JAtZB.schedJ` at `JAtZ` (mmuAD gen 42b70: `JExt` rebuilt from the slots and the VCPU words kept). -/ +theorem JAtZ.schedJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) {s' : S} {σ' : Fl4Spec.State Unit} + (hS : SchedStep (L := L) Z.th s σ s' σ') : + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' := by + have hX := J.xtop + have hW := (hS.2.1 Z.N Z.T Z.C Z.c J.thT hX.fin.1.1.1 hX.fin.1.1.2.2.1).2.1 + have hSS : SlotsSame Z.th (L.mem s) (L.mem s') := + hX.slotsSame_of hW fun b hb => schW_oobj hX.fin.1.1.1.placed.tcb hb + obtain ⟨Ac', Lst', D', B⟩ := J.toB.schedJ hS + exact ⟨Ac', Lst', D', B.toJAtZ (J.ext.step (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) + (J.vkeep_of hW fun _ hb => J.schW_nv hb))⟩ + set_option maxHeartbeats 4000000 in /-- **`reschedule_required` at `J`** (`ActReady` from `JAtZ`'s `Inv`; -`JAtZ.schedJ`). -/ -theorem JAtZ.reschedJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) : +`JAtZ.schedJ`; (mmuAD gen 42b70) over `JAtZB` in place, with the native footprint `NatFoot`: FL4's `SFootI` writes, +the spec's heap kept). -/ +theorem JAtZB.reschedJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s ar σ) : ∃ s', sched.reschedule_required st s = ok s' ∧ ∃ σ', Fl4Spec.rescheduleRequired (Z := Unit) σ = ({((), σ')}, False) ∧ - ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' := by + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' ∧ + NatFoot (L := L) Z s σ s' σ' := by have hA2 : Notif.ActReady σ := J.inv.actReady obtain ⟨σ', hres, hK', hdl', hds'⟩ := rescheduleRequired_k hA2 have hS := J.xtop.fin.1.1.1 have hN := J.xtop.fin.1.1.2.2.1 - obtain ⟨s3, hrun3, ⟨σ3, he3, -, -, -, -⟩, -⟩ := spec_exists (WP.spec_and + obtain ⟨s3, hrun3, ⟨σ3, he3, -, -, -, -⟩, hw3⟩ := spec_exists (WP.spec_and (Sched.reschedule_required_refines _ _ hN hS hA2) (Sched.reschedule_required_sfootI hS)) rw [hres] at he3 have e3 : σ3 = σ' := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst he3))).2.symm subst σ3 - exact ⟨s3, hrun3, _, hres, J.schedJ (schedStep_resched hA2 hrun3 hres hK' hdl' hds')⟩ + obtain ⟨Ac', Lst', D', B⟩ := J.schedJ (schedStep_resched hA2 hrun3 hres hK' hdl' hds') + exact ⟨s3, hrun3, _, hres, Ac', Lst', D', B, NatFoot.ofT J.xtop + (WritesIn.tfoot_of_kfoot (hw3.mono fun _ h => KFoot.of_sfoot (sfootI_sfoot h))) (fun _ h => J.tfoot_nh h) + (NatK.of_kheap hK'.kh)⟩ + +/-- `JAtZB.reschedJ` at `JAtZ` (mmuAD gen 42b70: `JAtZB.toJN`). -/ +theorem JAtZ.reschedJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) : + ∃ s', sched.reschedule_required st s = ok s' ∧ ∃ σ', Fl4Spec.rescheduleRequired (Z := Unit) σ = ({((), σ')}, False) ∧ + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' s' ar σ' := by + obtain ⟨s', h1, σ', h2, Ac', Lst', D', B, F⟩ := J.toB.reschedJ + exact ⟨s', h1, σ', h2, Ac', Lst', D', B.toJN J F⟩ /-- `JAtZ` at some VSpace sets, frame sets, call lists and dead set. -/ abbrev JAtV (arI : machine.Arch A) (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) (Cs : Set U64) diff --git a/proofs/Fl4Proofs/P3/XTopJointData.lean b/proofs/Fl4Proofs/P3/XTopJointData.lean index 6a2e09e3d..05cf79033 100644 --- a/proofs/Fl4Proofs/P3/XTopJointData.lean +++ b/proofs/Fl4Proofs/P3/XTopJointData.lean @@ -26,6 +26,10 @@ from `JAtZ` before to `JAt` after, against the spec's `specTail true`. `Running` (`JAtZ.runJ`), `JAt` at the spec's success tail with data (`specTail_data`). With XTopReply's `data_tail_core` by `WP.spec_and`. +(mmuAD gen 42b66, option (b) step b2) `setmrJ` and `replyTailJ` stated over `JAtZB` in place, the posts with the +native footprint `NatFoot` (P3/NatFoot); new `JAtZB.userW_nat` / `JAtZB.userWrN` (the buffer word's step a native +one). `JAtZ.setmrJ` / `JAtZ.replyTailJ` are one-line corollaries (`JAtZ.toB`, `JAtZB.toJN`), statements unchanged. + (mmuAD gen 42b18) `userWrJ` stated over `JAtZB` in place; `JAtZ.userWrJ` its corollary with new `JAtZB.ext_wr` (`ext` across one word written apart from every non-`other` object of `H`). P3/JAtZV3RegW's copy deleted. -/ @@ -255,6 +259,37 @@ theorem JAtZ.userWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) have hal : P1.Aligned wp.1 := (hP.ep.balign wp hwB).1 (Fl4Proofs.P3.JAtZB.userWrJ (J := J.toB) (hBP := hBP) (hwB := hwB) (hAp := hAp) (hObj := hObj) (v := v)).toJAtZ (J.toB.ext_wr J.ext hal v (slotsSame_wr hP.pl s v hal fun _ hx => BufPlaced.slot hP hwB hx) hAp) +/-- (mmuAD gen 42b66) **The IPC-buffer word `userWrJ` writes is a native-footprint word**: an `OObj` buffer word, +not the VCPU-list head (`BufPlaced.far`), no TCB's VCPU word (`hAp`). -/ +theorem JAtZB.userW_nat (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hBP : BufPlaced (L := L) Z.N Z.C Z.B Z.c s σ) {wp : U64 × Fl4Spec.Word} (hwB : wp ∈ Z.B) + (hAp : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → wp.1.val + 8 ≤ q.val ∨ q.val + 2 ^ k.bits ≤ wp.1.val) : + Vs.OObj st Z.N Z.T Z.C Z.E Z.R Z.B Z.c s σ wp.1 ∧ wp.1 ≠ P1.vHeadA st s ∧ ∀ t ∈ Z.T, wp.1 ≠ tVcpuA t := by + refine ⟨Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨wp, hwB, le_refl _, by omega⟩)))))), fun e => ?_, + fun t ht e => ?_⟩ + · have hvh : (P1.vHeadA st s).val = (L.ksb s).val + 80 := vHead_val J.kern.ksbFit + have hnb : L.nodeBase s Z.c = (L.ksb s).val + 13568 + Z.c.val * 4288 := rfl + have hf := hBP.far wp hwB + rw [e, hvh, hnb] at hf + omega + · have hT := J.xtop.fin.1.1.1.placed.tcb + have hv : wp.1.val = t.val + 3664 := by rw [e]; exact tfield_val (hT t ht) (K := 3664#u64) (by simp) + rcases hAp t .tcb (J.zH.1 t ht) (fun _ e => by cases e) with e' | e' + · omega + · simp only [P1.HKind.bits] at e'; omega + +/-- (mmuAD gen 42b66) **`userWrJ`'s step is a native step** (`NatFoot`: the word by `userW_nat`, the spec changes only +the machine state). -/ +theorem JAtZB.userWrN (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hBP : BufPlaced (L := L) Z.N Z.C Z.B Z.c s σ) {wp : U64 × Fl4Spec.Word} (hwB : wp ∈ Z.B) + (hAp : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → wp.1.val + 8 ≤ q.val ∨ q.val + 2 ^ k.bits ≤ wp.1.val) + (v : U64) : + NatFoot (L := L) Z s σ (L.wr s wp.1 v) (Endp.setUm σ (Endp.storeMem σ.machineState.underlyingMemory wp.2 v.bv)) := by + obtain ⟨hO, hh, hv⟩ := J.userW_nat hBP hwB hAp + have hal : P1.Aligned wp.1 := (J.xtop.fin.1.2.ep.balign wp hwB).1 + exact NatFoot.ofW J.xtop (P1.writesIn_wr hal) (fun b hb => by subst hb; exact hO) (fun b hb => by subst hb; exact hv) + (fun b hb => by subst hb; exact hh) (NatK.of_kheap rfl) + set_option maxHeartbeats 8000000 in /-- **A word of a TCB's receive buffer at `J`** (`JAtZ.bufWordG` for the receiver's lookup; lcv generalised it over the receiver flag). -/ @@ -278,14 +313,15 @@ set_option maxHeartbeats 16000000 in /-- **`set_mr` of the next message word at `J`** (VSpace's `setmr_inv` at `JAtZ`): a register (`JAtZ.regWrJ`) or a buffer word (`JAtZ.userWrJ`), the spec's `set_mrs` state growing by the word. -/ -theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} - {ms : List Fl4Spec.Word} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) +theorem JAtZB.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} + {ms : List Fl4Spec.Word} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) (hct : ct ∈ Z.T) (hk0 : σ0.kheap ct.bv = some (.tcb x0)) (w : U64) (hw0 : w = 0#u64 ↔ buf = none) (hbm : ∀ p, buf = some p → Endp.BufMap Z.B w p) (hBP : BufPlaced (L := L) Z.N Z.C Z.B Z.c s σ0) (hOK : ∀ p, buf = some p → ∀ i : U64, i.val < 128 → BufWordOK H σ0 (Endp.fl4BufA w i)) (i : U64) (hi : i.val = ms.length) (hi' : ms.length < 120) (v : U64) : msg.set_mr st s ct w i v ⦃ r => r.1.val = mrLen buf (ms.length + 1) ∧ L.ksb r.2 = L.ksb s ∧ - ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D r.2 a (MrS σ0 ct.bv x0 buf (ms ++ [v.bv])) ⦄ := by + ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D r.2 a (MrS σ0 ct.bv x0 buf (ms ++ [v.bv])) ∧ + NatFoot (L := L) Z s (MrS σ0 ct.bv x0 buf ms) r.2 (MrS σ0 ct.bv x0 buf (ms ++ [v.bv])) ⦄ := by have hkx := MrS_kheap_t σ0 ct.bv x0 buf ms have hN : msg.N_MSG_REGISTERS.val = 4 := by unfold msg.N_MSG_REGISTERS; rfl unfold msg.set_mr @@ -298,7 +334,7 @@ theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {bu rintro s1 rfl simp only [lift, bind_ok, WP.spec_ok] have hX := reg_wr_irel J.ip (J.xtop.irelK J.ks J.buf) hct hkx (Endp.mrIdx i.val) (mrIdx_ne_badge _) v - obtain ⟨V, J1⟩ := J.regWrJ hct hkx (Endp.mrIdx i.val) v hX + obtain ⟨V, J1, F1⟩ := J.regWrJ hct hkx (Endp.mrIdx i.val) v hX refine ⟨?_, L.ksb_wr _ _ _, V, ?_⟩ · have : (core.num.U64.wrapping_add i 1#u64).val = i.val + 1 := by simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega @@ -306,10 +342,10 @@ theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {bu · cases buf with | none => have e := Endp.mrStateN_snoc_lt σ0 ct.bv x0 ms v.bv i.val hi (by omega) - simp only [MrS] at J1 ⊢; rw [← e]; exact J1 + simp only [MrS] at J1 F1 ⊢; rw [← e]; exact ⟨J1, F1⟩ | some p => have e := Endp.mrState_snoc_lt σ0 ct.bv x0 p ms v.bv i.val hi (by omega) - simp only [MrS] at J1 ⊢; rw [← e]; exact J1 + simp only [MrS] at J1 F1 ⊢; rw [← e]; exact ⟨J1, F1⟩ · have hi4 : 4 ≤ i.val := by have : ¬ i.val < 4 := fun h => h4 ((P1.gt_iff_val).2 (by rw [hN]; exact h)); omega rw [if_neg h4] @@ -319,7 +355,7 @@ theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {bu simp only [hw, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] refine ⟨by rw [hN]; simp [mrLen]; omega, by first | rfl | trivial, Z.vs, ?_⟩ simp only [MrS] at J ⊢ - rw [Endp.mrStateN_append_ge _ _ _ _ _ (by omega)]; exact J + rw [Endp.mrStateN_append_ge _ _ _ _ _ (by omega)]; exact ⟨J, NatFoot.refl _ _ _⟩ | some p => have hw : w ≠ 0#u64 := fun h => by cases hw0.1 h have hb : (w != 0#u64) = true := by simp [hw] @@ -342,20 +378,33 @@ theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {bu exact ⟨_, _, MrS_kheap_t _ _ _ _ _, g1, g2⟩ · exact ⟨o, ko, by rw [MrS_kheap_ne _ _ _ _ _ e]; exact hko, g1, g2⟩ have J1 := J.userWrJ hBP' hwB hAp hObj v + have F1 := J.userWrN hBP' hwB hAp v simp only [lift, bind_ok, WP.spec_ok] refine ⟨by rw [hiv]; simp [mrLen], L.ksb_wr _ _ _, Z.vs, ?_⟩ - simp only [hiv] at J1 - simp only [MrS] at J1 ⊢ + simp only [hiv] at J1 F1 + simp only [MrS] at J1 F1 ⊢ rw [← Endp.mrState_snoc_ge _ _ _ _ _ _ (by omega) hi'] - exact J1 + exact ⟨J1, F1⟩ + +/-- `JAtZB.setmrJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.setmrJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {buf : Option Fl4Spec.ObjRef} + {ms : List Fl4Spec.Word} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 buf ms)) + (hct : ct ∈ Z.T) (hk0 : σ0.kheap ct.bv = some (.tcb x0)) (w : U64) (hw0 : w = 0#u64 ↔ buf = none) + (hbm : ∀ p, buf = some p → Endp.BufMap Z.B w p) (hBP : BufPlaced (L := L) Z.N Z.C Z.B Z.c s σ0) + (hOK : ∀ p, buf = some p → ∀ i : U64, i.val < 128 → BufWordOK H σ0 (Endp.fl4BufA w i)) + (i : U64) (hi : i.val = ms.length) (hi' : ms.length < 120) (v : U64) : + msg.set_mr st s ct w i v ⦃ r => r.1.val = mrLen buf (ms.length + 1) ∧ L.ksb r.2 = L.ksb s ∧ + ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D r.2 a (MrS σ0 ct.bv x0 buf (ms ++ [v.bv])) ⦄ := + WP.spec_mono (J.toB.setmrJ hct hk0 w hw0 hbm hBP hOK i hi hi' v) fun _ ⟨h1, h2, V, B', F⟩ => + ⟨h1, h2, V, B'.toJN J F⟩ set_option maxHeartbeats 16000000 in /-- **The reply tail at `J`** (`reply_words` then `Running`, as XTopReply's `reply_tail_inv`): from `JAtZ` at the spec's `set_mrs` state of the words `ms` (the caller `Restart`), `JAt` at the spec's success tail with data (`specTail_data`). -/ -theorem JAtZ.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {ms : List Fl4Spec.Word} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 (Endp.ipcBufOf true x0) ms)) [VxE Z] +theorem JAtZB.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {ms : List Fl4Spec.Word} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 (Endp.ipcBufOf true x0) ms)) (hct : ct ∈ Z.T) (hk0 : σ0.kheap ct.bv = some (.tcb x0)) (hrs : x0.tcbState = .restart) (hlen : ms.length ≤ Fl4Spec.msgMaxLength) (hfr : ∀ p, Endp.ipcBufOf true x0 = some p → ∀ z ∈ Endp.mrPairs ms, @@ -364,29 +413,32 @@ theorem JAtZ.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} (do let s4 ← tcb.reply_words st s ct n sched.set_thread_state st s4 ct sched.TS_RUNNING) ⦃ s5 => - ∀ z ∈ (specTail true ct.bv ms σ0).1, JAt (L := L) arI AR s5 a z.2 ⦄ := by + ∀ z ∈ (specTail true ct.bv ms σ0).1, ∃ (V : XVs) (Lst' : U64 → List U64), + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D s5 a z.2 ∧ + NatFoot (L := L) Z s (MrS σ0 ct.bv x0 (Endp.ipcBufOf true x0) ms) s5 z.2 ⦄ := by set buf := Endp.ipcBufOf true x0 have hkx := MrS_kheap_t σ0 ct.bv x0 buf ms - refine WP.spec_bind (Pₘ := fun s4 => ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s4 a - (replyStateB σ0 ct.bv x0 buf ms)) ?_ ?_ + refine WP.spec_bind (Pₘ := fun s4 => ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s4 a + (replyStateB σ0 ct.bv x0 buf ms) ∧ NatFoot (L := L) Z s (MrS σ0 ct.bv x0 buf ms) s4 (replyStateB σ0 ct.bv x0 buf ms)) + ?_ ?_ swap - · rintro s4 ⟨V2, J2⟩ + · rintro s4 ⟨V2, J2, F2⟩ refine WP.spec_mono (J2.runJ hct (replyStateB_kheap_t _ _ _ _ _) (by rw [replyTcbB_state, hrs])) ?_ - rintro s5 ⟨Lst', D', J5⟩ z hz + rintro s5 ⟨Lst', J5, F5⟩ z hz rw [specTail_data hk0 hrs ms hlen hfr] at hz rw [Set.mem_singleton_iff.1 hz] - exact ⟨_, _, _, _, _, _, J5, inferInstance⟩ + exact ⟨V2, Lst', J5, J.natTrans F2 F5.cast⟩ unfold tcb.reply_words refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.BADGE 0#u64) ?_ rintro s1 rfl -- the badge have hXb := badge_wr_irel J.ip (J.xtop.irelK J.ks J.buf) hct hkx 0#u64 rw [badgeRegA_eq_regA] at hXb - obtain ⟨V1, J1⟩ := J.regWrJ hct hkx Fl4Spec.badge_register 0#u64 hXb - rw [Endp.regIdx_badge] at J1 - rw [mrS_setReg σ0 ct.bv x0 buf ms badge_not_mr] at J1 + obtain ⟨V1, J1, F1⟩ := J.regWrJ hct hkx Fl4Spec.badge_register 0#u64 hXb + rw [Endp.regIdx_badge] at J1 F1 + rw [mrS_setReg σ0 ct.bv x0 buf ms badge_not_mr] at J1 F1 have e0 : U64.bv 0#u64 = (0 : Fl4Spec.Word) := rfl - rw [e0] at J1 + rw [e0] at J1 F1 set xA := Notif.setReg x0 Fl4Spec.badge_register 0 unfold msginfo.MessageInfo.new simp only [bind_ok] @@ -395,7 +447,7 @@ theorem JAtZ.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} rw [← Endp.regIdx_msgInfo] have hkA := MrS_kheap_t (Notif.updK σ0 ct.bv (.tcb xA)) ct.bv xA buf ms have hX2 := reg_wr_irel J1.ip (J1.xtop.irelK J1.ks J1.buf) hct hkA Fl4Spec.msg_info_register (by decide) v - obtain ⟨V2, J2⟩ := J1.regWrJ hct hkA Fl4Spec.msg_info_register v hX2 + obtain ⟨V2, J2, F2⟩ := J1.regWrJ hct hkA Fl4Spec.msg_info_register v hX2 have hvd : v.bv = Fl4Spec.messageInfoToData ⟨Fl4Spec.natToLen (mrLen buf ms.length), 0, 0, 0⟩ := by rw [hv]; congr 2 apply BitVec.eq_of_toNat_eq; simp only [Fl4Spec.natToLen, BitVec.toNat_ofNat, UScalar.bv_toNat, ← hn]; omega @@ -403,8 +455,24 @@ theorem JAtZ.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} (.tcb (Notif.setReg (Endp.withRegs xA (Endp.mrRegs xA.tcbArch.tcbContext.userRegs ms)) Fl4Spec.msg_info_register v.bv)) = replyStateB σ0 ct.bv x0 buf ms := by unfold replyStateB; rw [hvd] - rw [eR] at J2 - exact ⟨V2, J2⟩ + rw [eR] at J2 F2 + exact ⟨V2, J2, J.natTrans F1 F2.cast⟩ + +/-- `JAtZB.replyTailJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.replyTailJ {σ0 : Fl4Spec.State Unit} {ct : U64} {x0 : Fl4Spec.Tcb} {ms : List Fl4Spec.Word} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ0 ct.bv x0 (Endp.ipcBufOf true x0) ms)) [VxE Z] + (hct : ct ∈ Z.T) (hk0 : σ0.kheap ct.bv = some (.tcb x0)) (hrs : x0.tcbState = .restart) + (hlen : ms.length ≤ Fl4Spec.msgMaxLength) + (hfr : ∀ p, Endp.ipcBufOf true x0 = some p → ∀ z ∈ Endp.mrPairs ms, + (Endp.bufAddr p z.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (Endp.bufAddr p z.1) σ0) + (n : U64) (hn : n.val = mrLen (Endp.ipcBufOf true x0) ms.length) (hn128 : n.val < 128) : + (do + let s4 ← tcb.reply_words st s ct n + sched.set_thread_state st s4 ct sched.TS_RUNNING) ⦃ s5 => + ∀ z ∈ (specTail true ct.bv ms σ0).1, JAt (L := L) arI AR s5 a z.2 ⦄ := + WP.spec_mono (J.toB.replyTailJ hct hk0 hrs hlen hfr n hn hn128) fun _ h z hz => + match h z hz with + | ⟨_, _, B', F⟩ => ⟨_, _, _, _, _, _, B'.toJN J F, inferInstance⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointDispatch.lean b/proofs/Fl4Proofs/P3/XTopJointDispatch.lean index cd693e905..a7dad3bdd 100644 --- a/proofs/Fl4Proofs/P3/XTopJointDispatch.lean +++ b/proofs/Fl4Proofs/P3/XTopJointDispatch.lean @@ -2,7 +2,7 @@ P3 (DESIGN.md §9): **the syscall dispatch above `handle_invocation` at `J`** (proofs/KENTRY-PLAN.md, items 1–3). -* `JAtZ.frontEx`: at `JAtZ` (with BufJ's `JAtZ.xferH`: the IPC-buffer facts at the +* `JAtZB.frontEx` (42b82: at `JAtZB`; `JAtZ.frontEx` its instance): at `JAtZ` (with BufJ's `JAtZ.xferH`: the IPC-buffer facts at the entry), FL4's front-end reads (`msg_info`, `lookup_ipc_buffer`, `lookup_extra_caps`) succeed and the spec's (`getMessageInfo`, `lookupIpcBuffer`, `lookupExtraCaps`, `getMrs`) have exactly one outcome @@ -61,8 +61,9 @@ theorem map_bv_ofBv (l : List Fl4Spec.Data) : (l.map (fun b => (⟨b⟩ : U64))) set_option maxHeartbeats 4000000 in /-- **The front end's reads at `J`**: FL4's succeed, the spec's have one -outcome each (the equations of `handle_invocation_refinesJ`). -/ -theorem JAtZ.frontEx {s : S} {ar : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) +outcome each (the equations of `handle_invocation_refinesJ`). (mmuAD 42b82: stated at `JAtZB`, the fields it +reads; `JAtZ.frontEx` is its instance.) -/ +theorem JAtZB.frontEx {s : S} {ar : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s ar σ) (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover Z.T Z.B σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) : ∃ (info : msginfo.MessageInfo) (mi : Fl4Spec.MessageInfo) (buf : U64) (buffer : Option Fl4Spec.ObjRef) @@ -117,6 +118,22 @@ theorem JAtZ.frontEx {s : S} {ar : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := rw [map_bv_ofBv] exact getMrs_eq hks _ hal _ +/-- `JAtZB.frontEx` at `JAtZ` (via `JAtZ.toB`). -/ +theorem JAtZ.frontEx {s : S} {ar : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s ar σ) + (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover Z.T Z.B σ) + {ct : U64} (hct : sched.cur_thread st s = ok ct) : + ∃ (info : msginfo.MessageInfo) (mi : Fl4Spec.MessageInfo) (buf : U64) (buffer : Option Fl4Spec.ObjRef) + (r2 : core.result.Result (Aeneas.Std.Array obj.Slot 3#usize) error.Fault) + (er : Except Fl4Spec.Fault (List (Fl4Spec.Cap × Fl4Spec.CslotPtr))) (argsU : List U64), + msg.msg_info st s ct = ok info ∧ + Fl4Spec.getMessageInfo (Z := Unit) ct.bv σ = ({(mi, σ)}, False) ∧ + msg.lookup_ipc_buffer st s false ct = ok buf ∧ + Fl4Spec.lookupIpcBuffer (Z := Unit) false ct.bv σ = ({(buffer, σ)}, False) ∧ + ipc.lookup_extra_caps st s ct buf info = ok r2 ∧ + (Fl4Spec.lookupExtraCaps (Z := Unit) ct.bv buffer mi).run σ = ({(er, σ)}, False) ∧ + Fl4Spec.getMrs (Z := Unit) ct.bv buffer mi σ = ({(argsU.map UScalar.bv, σ)}, False) := + JAtZB.frontEx arI J.toB hOK hBC hct + /-- The spec's invoking syscalls with FL4's dispatcher: `handleSend bl` (`call = false`, `don = false`) and `handleCall` (`call = bl = don = true`) with `fl4HandleInvocationR true` for l4v's `handleInvocation`. -/ diff --git a/proofs/Fl4Proofs/P3/XTopJointEntry.lean b/proofs/Fl4Proofs/P3/XTopJointEntry.lean index 46e16f8d1..b26e5c533 100644 --- a/proofs/Fl4Proofs/P3/XTopJointEntry.lean +++ b/proofs/Fl4Proofs/P3/XTopJointEntry.lean @@ -15,7 +15,10 @@ spec's `callKernel`); P1 has only `handle_syscall.entry` (`EntryInv`). * `HIPostMXP`, `handle_invocation_refinesMXP`: `handle_invocation_refinesMX` with `XP` after a preempted invocation (`X` after any other), the decode's statement `XCapP` (XTopJointCnDel), and the invoked slot a CNode slot of - the typed heap (from the lookup, `WalkRel`) passed to `hDec`. Its reply + the typed heap (from the lookup, `WalkRel`) passed to `hDec`. (mmuAD + 42b66: the instance at the native decoder and dispatcher of HandleTopG's + `handle_invocation_refinesMXPG`, where its proof and `ifP_ok` / `ifP_X` + moved; `HIPostMXP_G`; statement unchanged.) Its reply premises are narrower than HandleTopX's `ReplyHypMX`: the success tail (`hRepS`) only from states whose current thread is still the invoker (`hPK`: the invocation keeps the current thread), the error reply @@ -53,6 +56,7 @@ import Fl4Proofs.P3.XTopJointTcb import Fl4Proofs.P3.JEntryKs import Fl4Proofs.P3.JEntryIrq import Fl4Proofs.P3.XTopJointCnDel +import Fl4Proofs.P3.HandleTopG import Fl4Proofs.P3.XTopJointIrqDel import Fl4Proofs.P3.XTopJointIrqL import Fl4Proofs.P3.ScMsgOK @@ -107,15 +111,13 @@ def HIPostMXP (X XP : S → A → Fl4Spec.State Unit → Prop) (rep : Bool) (σ RelTopM (L := L) res.2.1 y.2 ∧ (if res.1 = .Err .Preempted then XP res.2.1 res.2.2 y.2 else X res.2.1 res.2.2 y.2) -theorem ifP_ok {X XP : S → A → Fl4Spec.State Unit → Prop} {r : core.result.Result Unit error.Exc} {s : S} {a : A} - {σ : Fl4Spec.State Unit} (h : r = .Ok ()) (hx : X s a σ) : - (if r = .Err .Preempted then XP s a σ else X s a σ) := by - subst h; rw [if_neg (fun h => by cases h)]; exact hx - -theorem ifP_X {X XP : S → A → Fl4Spec.State Unit → Prop} {r : core.result.Result Unit error.Exc} {s : S} {a : A} - {σ : Fl4Spec.State Unit} (h : r ≠ .Err .Preempted) - (hx : if r = .Err .Preempted then XP s a σ else X s a σ) : X s a σ := by - rw [if_neg h] at hx; exact hx +/-- `HIPostMXP` is HandleTopG's `HIPostMXPG` at the native decoder and dispatcher. -/ +theorem HIPostMXP_G {X XP : S → A → Fl4Spec.State Unit → Prop} {rep : Bool} {σ : Fl4Spec.State Unit} + {calling blocking canDonate firstPhase : Bool} {cptr : Fl4Spec.CapRef} + {res : core.result.Result Unit error.Exc × S × A} : + HIPostMXP (L := L) X XP rep σ calling blocking canDonate firstPhase cptr res = + HIPostMXPG (L := L) Fl4Spec.fl4DecodeInvocation Fl4Spec.fl4PerformInvocation X XP rep σ calling blocking + canDonate firstPhase cptr res := rfl /-- **`handle_invocation` refines l4v's, keeping `X` (`XP` if preempted)** (`handle_invocation_refinesMX` with the decode's `XCapP`; `hDec` also gets @@ -170,125 +172,10 @@ theorem handle_invocation_refinesMXP (X XP : S → A → Fl4Spec.State Unit → XCapP (L := L) arI X XP s ar σ info.label (msgLen info buf) (cslotAddr sl) c blocking is_call can_donate first_phase buf e mi.miLabel args (Fl4Spec.toBl cptr.bv) sl exs buffer ct) : syscall.handle_invocation st arI s ar is_call blocking can_donate first_phase cptr ⦃ res => - HIPostMXP (L := L) X XP rep σ is_call blocking can_donate first_phase (Fl4Spec.toBl cptr.bv) res ⦄ := by - have hRT0 : RelTopM (L := L) s σ := ⟨th, G, hP, hCR, hFI, hDR, hFR⟩ - unfold syscall.handle_invocation - rw [hct]; simp only [bind_ok, hinfo] - refine WP.spec_bind (lookup_slot_refines (Z := Unit) th s σ hCR.1 hCR.2.1 ct htcb cptr) ?_ - rintro r ⟨e, he, hrel, hok⟩ - cases r with - | Err lf => - cases e with - | ok v => exact hrel.elim - | error lf' => - simp only - have hl : (Fl4Spec.lookupCapAndSlot (Z := Unit) ct.bv (Fl4Spec.toBl cptr.bv)).run σ = - ({(.error lf', σ)}, False) := by - unfold Fl4Spec.lookupCapAndSlot; exact run_bind_error (s := σ) he _ - have hmF := hiMF_lookup_err (mi := mi) hl - cases blocking - · simp only [Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - exact ⟨(.ok (), σ), hi_memR rep hcur hmi (mem_syscall_fault (z := ((), σ)) hmF - (mem_when (fun h => by cases h) (fun _ => rfl))), Or.inl ⟨rfl, rfl⟩, hRT0, ifP_ok rfl hX0⟩ - · simp only [↓reduceIte] - refine WP.spec_bind (hFL rfl lf lf' hrel) ?_ - rintro ⟨s1, a1⟩ ⟨z, hz, hRT, hXz⟩ - refine (WP.spec_ok _).2 ?_ - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_fault hmF (mem_when (fun _ => hz) (fun h => by cases h))), - Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ - | Ok r1 => - cases e with - | error lf' => exact hrel.elim - | ok v => - obtain ⟨sl, rest⟩ := v - obtain ⟨hsl, -⟩ := hrel - obtain ⟨p, hp, hth, -⟩ := hok - obtain ⟨c, a, hc, hca, hget⟩ := hCR.1.slot_cap hp hth - have hl : (Fl4Spec.lookupCapAndSlot (Z := Unit) ct.bv (Fl4Spec.toBl cptr.bv)).run σ = - ({(.ok (a, sl), σ)}, False) := by - unfold Fl4Spec.lookupCapAndSlot - rw [run_bind_ok he] - simp only - rw [run_bind_ok (run_liftE hget)] - rfl - simp only - rw [slot_cap_eq, hsl, hc] - simp only [bind_ok, hbuf, hr2] - rcases hrr with ⟨ex, exs, rfl, rfl⟩ | ⟨f, f', rfl, rfl, hfh⟩ - · simp only - rw [msgLen_eq]; simp only [bind_ok] - have hca' : absCap c = a := hca.2 - subst hca' - have hmF := hiMF_ok (mi := mi) hl hbuffer her - have hmE := hiME_run (cptr := Fl4Spec.toBl cptr.bv) (fp := first_phase) (a := absCap c) (sl := sl) - (exs := exs) hmrs - rcases hDec sl c ex exs ⟨p, hp, hth⟩ hc hget rfl rfl with hD | hD - swap - · refine WP.spec_bind hD ?_ - rintro ⟨r3, s1, a1⟩ (⟨e3, he3, hs1, ⟨e', hdec, herr⟩, hXe⟩ | ⟨hok3, hne, inv, hdec, σ1, hst, rr, σy, hy, z, hz, hRT, hXz⟩) - · simp only at he3 hs1 - subst he3 hs1 - cases e3 with - | Sys e2 => - refine WP.spec_mono (hRepF a1 e2 e' hXe herr) ?_ - rintro res ⟨hres, z, hz, hRT, hXz⟩ - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_err hmF (by rw [hmE, hdec]; rfl) hz), - Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ - | Fault _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - | Lookup _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - | Preempted => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - simp only at hok3; subst hok3 - refine WP.spec_bind (tcb_state_spec' (st := st) s1 ct) ?_ - rintro v rfl - rw [if_neg hne] - refine (WP.spec_ok _).2 ?_ - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) - (hiMFin_ok (by rw [← hcur]; exact hst) hy hz)), Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ - refine WP.spec_bind hD ?_ - rintro ⟨r3, s1, a1⟩ hq - rcases hq with ⟨e3, he3, hs1, ⟨e', hdec, herr⟩, hXe⟩ | - ⟨inv, hdec, σ1, hst, y, hy, ⟨th', G', hcase, hP', hCR', hFI', hDR', hFR'⟩, hXy⟩ - · simp only at he3 hs1 - subst he3 hs1 - cases e3 with - | Sys e2 => - refine WP.spec_mono (hRepF a1 e2 e' (ifP_X (r := .Err (.Sys e2)) (fun h => by cases h) hXe) herr) ?_ - rintro res ⟨hres, z, hz, hRT, hXz⟩ - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_err hmF (by rw [hmE, hdec]; rfl) hz), - Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ - | Fault _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - | Lookup _ => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - | Preempted => exact absurd herr (by rintro (h | ⟨n, h, -⟩) <;> cases h) - · rcases hcase with ⟨hok3, hyr⟩ | ⟨hpre, hyr⟩ - · simp only at hok3 - subst hok3 - refine WP.spec_mono (hRepS s1 a1 y.2 ⟨th', G', hP', hCR', hFI', hDR', hFR'⟩ (ifP_X (r := .Ok ()) (fun h => by cases h) hXy) - (hPK inv σ1 y hst hy)) ?_ - rintro res ⟨hres, z, hz, hRT, hXz⟩ - obtain ⟨y1, y2⟩ := y - simp only at hyr; subst hyr - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) - (hiMFin_ok (by rw [← hcur]; exact hst) hy hz)), Or.inl ⟨hres, rfl⟩, hRT, ifP_ok hres hXz⟩ - · simp only at hpre - subst hpre - refine (WP.spec_ok _).2 ?_ - obtain ⟨y1, y2⟩ := y - simp only at hyr; subst hyr - exact ⟨(.error (), y2), hi_memR rep hcur hmi (mem_syscall_fin hmF (by rw [hmE]; exact hdec.1) - (hiMFin_pre (by rw [← hcur]; exact hst) hy)), Or.inr ⟨rfl, rfl⟩, - ⟨th', G', hP', hCR', hFI', hDR', hFR'⟩, hXy⟩ - · simp only - have hmF := hiMF_extra_err (cptr := Fl4Spec.toBl cptr.bv) hl hbuffer her - cases blocking - · simp only [Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - exact ⟨(.ok (), σ), hi_memR rep hcur hmi (mem_syscall_fault (z := ((), σ)) hmF - (mem_when (fun h => by cases h) (fun _ => rfl))), Or.inl ⟨rfl, rfl⟩, hRT0, ifP_ok rfl hX0⟩ - · simp only [↓reduceIte] - refine WP.spec_bind (hfh rfl) ?_ - rintro ⟨s1, a1⟩ ⟨z, hz, hRT, hXz⟩ - refine (WP.spec_ok _).2 ?_ - exact ⟨(.ok z.1, z.2), hi_memR rep hcur hmi (mem_syscall_fault hmF (mem_when (fun _ => hz) (fun h => by cases h))), - Or.inl ⟨rfl, rfl⟩, hRT, ifP_ok rfl hXz⟩ + HIPostMXP (L := L) X XP rep σ is_call blocking can_donate first_phase (Fl4Spec.toBl cptr.bv) res ⦄ := + handle_invocation_refinesMXPG (L := L) arI Fl4Spec.fl4DecodeInvocation Fl4Spec.fl4PerformInvocation X XP rep s ar σ th G + hP hCR hFI hDR hFR hX0 ct hct hcur htcb is_call blocking can_donate first_phase cptr info hinfo mi hmi buf hbuf + buffer hbuffer r2 hr2 er her hrr args hmrs hFL hRepS hRepF hPK hDec end diff --git a/proofs/Fl4Proofs/P3/XTopJointEntryInv29.lean b/proofs/Fl4Proofs/P3/XTopJointEntryInv29.lean index a9698e3c6..f58a89b92 100644 --- a/proofs/Fl4Proofs/P3/XTopJointEntryInv29.lean +++ b/proofs/Fl4Proofs/P3/XTopJointEntryInv29.lean @@ -41,32 +41,39 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 4000000 in /-- **P1's `EntryInv` at a joint state with the action resume** (module docstring). -/ -theorem JAtZ.entryInv (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) +theorem JAtZB.entryInv (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hres : σ.schedulerAction = .resumeCurThread) : P1.EntryInv st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s := by - have hC : CurInv σ := J.curInv (by rw [hres]; intro e; cases e) + have hC : CurInv σ := J.cur.resolve_left (by rw [hres]; intro e; cases e) have hS := J.xtop.fin.1.1.1 obtain ⟨Q, R0, hc, hs⟩ := hS.lists obtain ⟨hscC, hsc0, htw, hts, hact, hnr, hnb⟩ := CurInv.facts hS J.inv hC - have hct : nodeW st s Z.c layout.node.CUR_THREAD ∈ Z.T := hc.curT + have hct : Sched.nodeW st s Z.c layout.node.CUR_THREAD ∈ Z.T := hc.curT obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have ecur : L.curW s = nodeW st s Z.c layout.node.CUR_THREAD := by + have ecur : L.curW s = Sched.nodeW st s Z.c layout.node.CUR_THREAD := by show L.mem s (L.nodeAt s (L.cpu s) _) = _; rw [hc.cur]; rfl - have ecsc : L.cscW s = nodeW st s Z.c layout.node.CUR_SC := by + have ecsc : L.cscW s = Sched.nodeW st s Z.c layout.node.CUR_SC := by show L.mem s (L.nodeAt s (L.cpu s) _) = _; rw [hc.cur]; rfl obtain ⟨x, n, hk, hx⟩ := hs.scs _ hscC have hxa : Fl4Spec.scActive x = true := by - by_cases hi : (nodeW st s Z.c layout.node.CUR_SC).bv = σ.idleSc + by_cases hi : (Sched.nodeW st s Z.c layout.node.CUR_SC).bv = σ.idleSc · exact hx.active_of_rmax (hx.idle hi) · exact hact hi x n hk - have hscS : nodeW st s Z.c layout.node.CUR_SC ∈ P1.Heap.scs H := ⟨_, (hJ.sc _ x n hsc0 hk).2⟩ + have hscS : Sched.nodeW st s Z.c layout.node.CUR_SC ∈ P1.Heap.scs H := ⟨_, (hJ.sc _ x n hsc0 hk).2⟩ have hcA : L.cscW s ∈ Ac := by rw [ecsc]; exact (J.blk.2.2.2.1.act _ hscS).2 (fun e => hx.rmax_ne hxa (by rw [e]; rfl)) refine ⟨J.blk.1, J.blk.2.1, J.blk.2.2.1, J.blk.2.2.2.1, J.blk.2.2.1.2.2.tm, hcA, ?_, fun _ => ?_⟩ · rw [ecur]; exact actionW_ne_of hS hct (by rw [hres]; intro e; cases e) · rw [ecur, ecsc, hts] +/-- P1’s entry invariant specialized to the native joint state. -/ +theorem JAtZ.entryInv (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hres : σ.schedulerAction = .resumeCurThread) : + P1.EntryInv st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) (P1.Heap.scs H) + (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s := + J.toB.entryInv hres + /-- `EntryInv` over some sets. -/ def EntInvAt (st : machine.Store S) [L : P1.LawfulStore st] (s : S) : Prop := ∃ (H : P1.Heap) (Cs Ac : Set U64), diff --git a/proofs/Fl4Proofs/P3/XTopJointFaultEp.lean b/proofs/Fl4Proofs/P3/XTopJointFaultEp.lean index e21c4d59f..f599c13e8 100644 --- a/proofs/Fl4Proofs/P3/XTopJointFaultEp.lean +++ b/proofs/Fl4Proofs/P3/XTopJointFaultEp.lean @@ -29,6 +29,11 @@ then `sendIpc` (blocking, call), then `return true`. pending reschedule after, `Inv.rd` of the now blocked sender carried from the runnable thread's `RelIfBound`; a cap fault is no timeout fault, so `inClassR` holds for it and `Inv.rd` must hold, and does). + +(mmuAD gen 42b67, option (b) step b3) `faultBlockJ` stated over `JAtZB` in place, post `JAtN` (FL4's `CnW` writes, +the spec frame `BFrT`: **`natK_bfrt`**, from `zv_bfrt`, moved here from P3/JAtZV3FaultBlk with its statement; +both moved on to P3/XTopJointSendBlockG in gen 42b70); +`JAtZ.faultBlockJ` its corollary (`JAtN.post`), statement unchanged. No named premise. -/ import Fl4Proofs.P3.XTopJointNoFault import Fl4Proofs.P3.XTopJointSendBlockG @@ -318,10 +323,210 @@ theorem set_fault_cap_top (hP0 : IPlaced N T E R B) {s : S} {σ : Fl4Spec.State end Fault +/-- **FL4's and the spec's non-cap fault** (module docstring). -/ +def FaultCorrN (f : error.Fault) (f' : Fl4Spec.Fault) : Prop := + (∃ n : U64, f = .UnknownSyscall n ∧ f' = .unknownSyscallException n.bv) ∨ + (∃ n c : U64, f = .UserException n c ∧ f' = .userException n.bv c.bv) ∨ + (∃ (ad fsr : U64) (ins : Bool), f = .VmFault ad fsr ins ∧ + f' = .archFault (.vmFault ad.bv [(if ins then 1#u64 else 0#u64).bv, fsr.bv])) + +/-- **Every fault kind the entries raise** (module docstring). -/ +def FaultCorrG (f : error.Fault) (f' : Fl4Spec.Fault) : Prop := CapFaultCorr f f' ∨ FaultCorrN f f' + +theorem FaultCorrG.nt {f : error.Fault} {f' : Fl4Spec.Fault} (h : FaultCorrG f f') : ∀ b, f' ≠ .timeout b := by + intro b e + subst e + rcases h with ⟨_, _, _, _, -, h, -⟩ | ⟨_, -, h⟩ | ⟨_, _, -, h⟩ | ⟨_, _, _, -, h⟩ <;> cases h + +theorem FaultCorrG.cap {f : error.Fault} {f' : Fl4Spec.Fault} (h : CapFaultCorr f f') : FaultCorrG f f' := Or.inl h + +/-- The fault-word range of the TCB at `t` (`[t + 3376, t + 3432)`). -/ +def FRng (t w : U64) : Prop := ∃ K : Nat, 3376 ≤ K ∧ K < 3432 ∧ w.val = t.val + K + +section Fault +open Fl4Proofs.P3.Sched +variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulStore st] +variable {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} {B : Set (U64 × Fl4Spec.Word)} {c : U64} + +/-- The four fault words written. -/ +def W4 (s : S) (t ty w0 w1 w2 : U64) : S := + L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) (tFw1A t) w1) (tFw2A t) w2 + +/-- **`set_fault` of a non-cap fault** writes the four fault words, which +encode the spec's fault. -/ +theorem set_fault_N_eq {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrN f f') (t : U64) : + ∃ ty w0 w1 w2 : U64, (ty ≠ 0#u64 ∧ ty ≠ 5#u64 ∧ (∀ b, f' ≠ .timeout b) ∧ + ∀ lt l0 l1, FaultRel' ty w0 w1 w2 lt l0 l1 (some f')) ∧ + ∀ s : S, faults.set_fault st s t f ⦃ s' => s' = W4 (L := L) s t ty w0 w1 w2 ⦄ := by + rcases hf with ⟨n, rfl, rfl⟩ | ⟨n, c, rfl, rfl⟩ | ⟨ad, fsr, ins, rfl, rfl⟩ + · refine ⟨fl4_abi.consts.fault.UnknownSyscall, n, 0#u64, 0#u64, + ⟨by unfold fl4_abi.consts.fault.UnknownSyscall; decide, by unfold fl4_abi.consts.fault.UnknownSyscall; decide, + fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.UnknownSyscall; exact ⟨rfl, rfl⟩⟩, + fun s => ?_⟩ + unfold faults.set_fault + simp only [bind_ok] + step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ + step with set_fault_w0_spec as ⟨s2, hs2⟩ + step with set_fault_w1_spec as ⟨s3, hs3⟩ + refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ + rintro s4 rfl + subst hs1 hs2 hs3 + rfl + · refine ⟨fl4_abi.consts.fault.UserException, n, c, 0#u64, + ⟨by unfold fl4_abi.consts.fault.UserException; decide, by unfold fl4_abi.consts.fault.UserException; decide, + fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.UserException; exact ⟨rfl, rfl, rfl⟩⟩, + fun s => ?_⟩ + unfold faults.set_fault + simp only [bind_ok] + step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ + step with set_fault_w0_spec as ⟨s2, hs2⟩ + step with set_fault_w1_spec as ⟨s3, hs3⟩ + refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ + rintro s4 rfl + subst hs1 hs2 hs3 + rfl + · refine ⟨fl4_abi.consts.fault.VMFault, ad, fsr, (if ins then 1#u64 else 0#u64), + ⟨by unfold fl4_abi.consts.fault.VMFault; decide, by unfold fl4_abi.consts.fault.VMFault; decide, + fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.VMFault; exact ⟨rfl, rfl, rfl⟩⟩, + fun s => ?_⟩ + unfold faults.set_fault + cases ins <;> simp only [bind_ok, Bool.false_eq_true, ↓reduceIte] <;> + · step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ + step with set_fault_w0_spec as ⟨s2, hs2⟩ + step with set_fault_w1_spec as ⟨s3, hs3⟩ + refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ + rintro s4 rfl + subst hs1 hs2 hs3 + rfl + +set_option maxHeartbeats 4000000 in +/-- **The four fault words of a non-timeout fault** refine l4v's `thread_set` +of the fault, on `IRel` (IpcTimeout's `set_fault_timeout_top` with the words +of any fault). -/ +theorem set_fault_N_top (hP0 : IPlaced N T E R B) {s : S} {σ : Fl4Spec.State Unit} + (hX : IRel st th cr N T C E R B c s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + {f' : Fl4Spec.Fault} {ty w0 w1 w2 : U64} (hty0 : ty ≠ 0#u64) (hty5 : ty ≠ 5#u64) (hnt : ∀ b, f' ≠ .timeout b) + (hfr : ∀ lt l0 l1, FaultRel' ty w0 w1 w2 lt l0 l1 (some f')) : + IRel st th cr N T C E R B c (W4 (L := L) s t ty w0 w1 w2) (updK σ t.bv (.tcb { x with tcbFault := some f' })) := by + obtain ⟨hIR, hSRT⟩ := hX + have hta := hP0.e.tcb t ht + set f : Option Fl4Spec.Fault := some f' + set y : Fl4Spec.Tcb := { x with tcbFault := f } + set σ' := updK σ t.bv (.tcb y) + have hk' : σ'.kheap t.bv = some (.tcb y) := by simp [σ'] + have hidem : updK σ' t.bv (.tcb { y with tcbFault := f }) = σ' := by + show updK (updK σ t.bv (.tcb y)) t.bv (.tcb y) = _; rw [updK_idem'] + unfold W4 + refine ⟨?_, ?_⟩ + · -- the IPC relation + have hfa := (a_fault hta).1 + have h0a := (a_fw0 hta).1 + have h1a := (a_fw1 hta).1 + have h2a := (a_fw2 hta).1 + have vf := val_fault hta + have v0 := val_fw0 hta + have v1 := val_fw1 hta + have v2 := val_fw2 hta + have rd : ∀ w, Aligned w → w ≠ tFw0A t → w ≠ tFw1A t → w ≠ tFw2A t → + L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) (tFw1A t) w1) + (tFw2A t) w2) w = L.mem (L.wr s (tFaultA t) ty) w := by + intro w hw n0 n1 n2 + rw [rd_wr_ne h2a hw (Ne.symm n2), rd_wr_ne h1a hw (Ne.symm n1), rd_wr_ne h0a hw (Ne.symm n0)] + have rft : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = ty := by + rw [rd (tFaultA t) hfa (fun e => by have := congrArg UScalar.val e; omega) + (fun e => by have := congrArg UScalar.val e; omega) (fun e => by have := congrArg UScalar.val e; omega)] + rw [rd_wr_eq hfa] + have rf0 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFw0A t) = w0 := by + rw [rd_wr_ne h2a h0a (fun e => by have := congrArg UScalar.val e; omega), + rd_wr_ne h1a h0a (fun e => by have := congrArg UScalar.val e; omega), rd_wr_eq h0a] + have rf1 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFw1A t) = w1 := by + rw [rd_wr_ne h2a h1a (fun e => by have := congrArg UScalar.val e; omega), rd_wr_eq h1a] + have rf2 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFw2A t) = w2 := by + rw [rd_wr_eq h2a] + have h0 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = 0#u64 ↔ f = none := + ⟨fun h => absurd (rft.symm.trans h) hty0, fun h => by simp [f] at h⟩ + have h5 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) + (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = 5#u64 ↔ ∃ b', f = some (.timeout b') := + ⟨fun h => absurd (rft.symm.trans h) hty5, fun ⟨b', hb⟩ => absurd (Option.some.inj hb) (hnt b')⟩ + refine fault_set_ipc hP0 hIR ht hk f (fun w hw hr => ?_) h0 h5 ?_ + · have n0 : w ≠ tFw0A t := fun e => by subst e; omega + have n1 : w ≠ tFw1A t := fun e => by subst e; omega + have n2 : w ≠ tFw2A t := fun e => by subst e; omega + rw [rd w hw n0 n1 n2, rd_wr_ne hfa hw (fun e => by subst e; omega)] + · show FaultRel' _ _ _ _ _ _ _ f + rw [rft, rf0, rf1, rf2] + exact hfr _ _ _ + · -- the scheduler and top relations + have e1 := fault_word_top hSRT ht hk f (K := 3376#u64) (Or.inl rfl) ty + have e2 := fault_word_top e1 ht hk' f (K := 3384#u64) (Or.inr (Or.inl rfl)) w0 + rw [hidem] at e2 + have e3 := fault_word_top e2 ht hk' f (K := 3392#u64) (Or.inr (Or.inr (Or.inl rfl))) w1 + rw [hidem] at e3 + have e4 := fault_word_top e3 ht hk' f (K := 3400#u64) (Or.inr (Or.inr (Or.inr rfl))) w2 + rw [hidem] at e4 + exact e4 + +set_option maxHeartbeats 8000000 in +/-- **`set_fault` of any fault with `FaultCorrG`** refines l4v's `thread_set` +of the fault on `IRel`, writing only the fault-word range. -/ +theorem set_fault_G_top (hP0 : IPlaced N T E R B) {s : S} {σ : Fl4Spec.State Unit} + (hX : IRel st th cr N T C E R B c s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : + faults.set_fault st s t f ⦃ s' => + (Fl4Spec.threadSet (Z := Unit) (fun tcb => { tcb with tcbFault := some f' }) t.bv σ = + ({((), updK σ t.bv (.tcb { x with tcbFault := some f' }))}, False) ∧ + IRel st th cr N T C E R B c s' (updK σ t.bv (.tcb { x with tcbFault := some f' }))) ∧ + P1.WritesIn st s s' (FRng t) ⦄ := by + have hta := hP0.e.tcb t ht + rcases hf with hc | hn + · obtain ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩ := hc + obtain ⟨⟨lt, l0, l1⟩, he, -⟩ := spec_exists (encode_lfRel hlf) + refine WP.spec_mono (WP.spec_and (set_fault_cap_top hP0 hX ht hk ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩) + (set_fault_cap_eq (L := L) s t a0 rp lf he)) ?_ + rintro s7 ⟨h1, hs7⟩ + refine ⟨h1, ?_⟩ + subst hs7 + have w := ((((((writesIn_wr (st := st) (s := s) (v := lt) (a_lf hta).1).trans + (writesIn_wr (v := l0) (a_lf0 hta).1)).trans (writesIn_wr (v := l1) (a_lf1 hta).1)).trans + (writesIn_wr (v := fl4_abi.consts.fault.CapFault) (a_fault hta).1)).trans (writesIn_wr (v := a0) (a_fw0 hta).1)).trans + (writesIn_wr (v := if rp then 1#u64 else 0#u64) (a_fw1 hta).1)).trans + (writesIn_wr (v := 0#u64) (a_fw2 hta).1) + refine w.mono fun w0 hw0 => ?_ + rcases hw0 with ((((((h | h) | h) | h) | h) | h) | h) <;> subst h + · exact ⟨3408, by omega, by omega, val_lf hta⟩ + · exact ⟨3416, by omega, by omega, val_lf0 hta⟩ + · exact ⟨3424, by omega, by omega, val_lf1 hta⟩ + · exact ⟨3376, by omega, by omega, val_fault hta⟩ + · exact ⟨3384, by omega, by omega, val_fw0 hta⟩ + · exact ⟨3392, by omega, by omega, val_fw1 hta⟩ + · exact ⟨3400, by omega, by omega, val_fw2 hta⟩ + · obtain ⟨ty, w0, w1, w2, ⟨h0, h5, hnt, hfr⟩, hs⟩ := set_fault_N_eq (st := st) (L := L) hn t + refine WP.spec_mono (hs s) ?_ + rintro s' rfl + refine ⟨⟨Notif.threadSet_eq _ hk, set_fault_N_top hP0 hX ht hk h0 h5 hnt hfr⟩, ?_⟩ + have w := (((writesIn_wr (st := st) (s := s) (v := ty) (a_fault hta).1).trans + (writesIn_wr (v := w0) (a_fw0 hta).1)).trans (writesIn_wr (v := w1) (a_fw1 hta).1)).trans + (writesIn_wr (v := w2) (a_fw2 hta).1) + refine w.mono fun u hu => ?_ + rcases hu with (((h | h) | h) | h) <;> subst h + · exact ⟨3376, by omega, by omega, val_fault hta⟩ + · exact ⟨3384, by omega, by omega, val_fw0 hta⟩ + · exact ⟨3392, by omega, by omega, val_fw1 hta⟩ + · exact ⟨3400, by omega, by omega, val_fw2 hta⟩ + +end Fault + end end Fl4Proofs.P3.Endp + + namespace Fl4Proofs.P3 open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched Fl4Proofs.P1 @@ -356,19 +561,85 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- The fault-entry thread can block, and its concrete SC word agrees with the spec's donation flag. -/ +theorem JAtZB.faultEntryBlock (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {ct : U64} (ht : ct ∈ Z.T) (hcur : σ.curThread = ct.bv) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrn : Fl4Spec.runnable x.tcbState = true) + (hnq : ∀ d p, ct.bv ∉ σ.readyQueues d p) : + P1.CanBlock st (P1.Heap.tcbs H) Ac s ct ∧ + (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by + have hI := J.xtop.irelK J.ks J.buf + have hS := J.xtop.fin.1.1.1 + obtain ⟨Q, R, hcq, hs⟩ := hS.lists + have htH : ct ∈ P1.Heap.tcbs H := J.zH.1 ct ht + have hC : CurInv σ := J.curInv (by rw [hni.2]; intro e; cases e) + have hnr : ct.bv ∉ σ.releaseQueue := by rw [← hcur]; exact hC.notRel + have hti : σ.curThread ≠ σ.idleThread := hni.1 + -- P1's `CanBlock` of the current thread + obtain ⟨bq, br⟩ := J.curBits ht hnq hnr + obtain ⟨hna, -⟩ := J.words_of_spec ht (fun u hu => by rw [hni.2] at hu; cases hu) + (fun e => hni.1 (by rw [hcur, e])) + obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct ht + rw [hk] at hk0; cases hk0 + have hv : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by + rw [P1.stA_eq, ← tStA_eq]; exact hTR.st + obtain ⟨hnb, hnrp⟩ := P1.run_word (w := L.mem s (P1.stA ct)) (by rw [hv]; exact runnable_code hrn) + have ha0 : L.actionW s = 0#u64 := by + have h := hS.act + rw [hni.2] at h + unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h + have hcw : L.curW s = ct := by + apply P1.eq_of_bv + rw [← hcur, hs.curThread] + unfold P1.LawfulStore.curW Sched.nodeW; rw [hcq.cur] + have hcbP : P1.CanBlock st (P1.Heap.tcbs H) Ac s ct := by + obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hS0, hSg0⟩ := J.blk + refine ⟨htH, hnb, hnrp, bq, br, hna, ?_, ?_⟩ + · intro h + have ei : L.idleW s = Sched.nodeW st s Z.c layout.node.IDLE_THREAD := by + unfold P1.LawfulStore.idleW Sched.nodeW; rw [hcq.cur] + exact hti (by rw [hcur, hs.idleTh, ← ei, h]) + · exact fun h1 => hB0.sact ct htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw⟩))))) h1 + -- the spec's donation flag is FL4's + obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb ct ht + rw [hk] at hkt6; cases hkt6 + have hdon : (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by + rw [hsct6] + by_cases h0 : L.mem s (scA ct) = 0#u64 + · simp [h0, Notif.optRef] + · simp [h0, Notif.optRef] + exact ⟨hcbP, hdon⟩ + +/-- A successful endpoint fault send returns directly from `handle_fault`. -/ +theorem handleFault_ep_wp {ct ptr bdg : U64} {sd rv g gr : Bool} {f : error.Fault} {P : S × A → Prop} + (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) + (h : faults.send_fault_ipc st arI s a ct (.Endpoint ptr bdg sd rv g gr) (L.mem s (scA ct) != 0#u64) f + ⦃ r => r.1 = true ∧ P r.2 ⦄) : faults.handle_fault st arI s a ct f ⦃ P ⦄ := by + unfold faults.handle_fault + rw [tcb_slot_fault] + apply ok_bind_spec + rw [slot_cap_eq, hep] + apply ok_bind_spec + step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ + subst hi + refine WP.spec_bind h ?_ + rintro ⟨b, s', a'⟩ ⟨hb, hp⟩ + simp only at hb hp + subst hb + exact (WP.spec_ok _).2 hp + set_option maxHeartbeats 64000000 in /-- **`handle_fault` with an endpoint handler and no waiting receiver at -`J`** (module docstring). -/ -theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} +`J`** (module docstring; (mmuAD gen 42b67) over `JAtZB` in place, post `JAtN`: FL4's writes `CnW`, the spec frame +`BFrT`, `natK_bfrt`). -/ +theorem JAtZB.faultBlockJG (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) {ptr bdg : U64} {sd rv g gr : Bool} (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) (hcb : ∀ xe, σ.kheap ptr.bv = some (.endpoint xe) → Endp.CanBlock false xe) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - obtain ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩ := hf - obtain ⟨⟨lt, l0, l1⟩, he, -⟩ := spec_exists (encode_lfRel hlf) + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by obtain ⟨hcur, x, hk, hrn⟩ := J.curRunnable hni hct have hP0 := J.ip have hI := J.xtop.irelK J.ks J.buf @@ -381,7 +652,6 @@ theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE have h := sched.cur_thread.spec' (L := L) s rw [hct, WP.spec_ok, hcq.cur] at h; exact h have ht : ct ∈ Z.T := by rw [hct']; exact hcq.curT - have hta := hP0.e.tcb ct ht have htH : ct ∈ P1.Heap.tcbs H := J.zH.1 ct ht have htD : ct ∉ D := fun h => J.notDead ht hk (by have := runnable_code hrn; omega) ct h rfl have hnq' : ∀ d p, ct.bv ∉ σ.readyQueues d p := by rw [← hcur]; exact hnq @@ -409,68 +679,19 @@ theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE (range_ep ptr bdg sd rv g gr hfit) fun k hk' => by rw [hHe] at hk'; cases hk' exact ⟨by simp only [P1.HKind.bits]; omega, fun z h => by cases h⟩ - -- P1's `CanBlock` of the current thread - obtain ⟨bq, br⟩ := J.curBits ht hnq' hnr - obtain ⟨hna, -⟩ := J.words_of_spec ht (fun u hu => by rw [hni.2] at hu; cases hu) - (fun e => hni.1 (by rw [hcur, e])) - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct ht - rw [hk] at hk0; cases hk0 - have hv : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by - rw [P1.stA_eq, ← tStA_eq]; exact hTR.st - obtain ⟨hnb, hnrp⟩ := P1.run_word (w := L.mem s (P1.stA ct)) (by rw [hv]; exact runnable_code hrn) - have ha0 : L.actionW s = 0#u64 := by - have h := hS.act - rw [hni.2] at h - unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h - have hcw : L.curW s = ct := by - apply P1.eq_of_bv - rw [← hcur, hs.curThread] - unfold P1.LawfulStore.curW nodeW; rw [hcq.cur] - have hcbP : P1.CanBlock st (P1.Heap.tcbs H) Ac s ct := by - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hS0, hSg0⟩ := J.blk - refine ⟨htH, hnb, hnrp, bq, br, hna, ?_, ?_⟩ - · intro h - have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by - unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] - exact hti (by rw [hcur, hs.idleTh, ← ei, h]) - · exact fun h1 => hB0.sact ct htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw⟩))))) h1 - -- the spec's donation flag is FL4's - obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb ct ht - rw [hk] at hkt6; cases hkt6 - have hdon : (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by - rw [hsct6] - by_cases h0 : L.mem s (scA ct) = 0#u64 - · simp [h0, Notif.optRef] - · simp [h0, Notif.optRef] - -- `handle_fault`: the handler cap - unfold faults.handle_fault - rw [tcb_slot_fault] - apply ok_bind_spec - rw [slot_cap_eq, hep] - apply ok_bind_spec - step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ - subst hi - refine WP.spec_bind (Pₘ := fun r : Bool × S × A => r.1 = true ∧ - ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv (.capFault a0.bv rp lf') σ).1, - RelTopM (L := L) r.2.1 z.2 ∧ JAt (L := L) arI AR r.2.1 r.2.2 z.2) ?_ ?_ - swap - · rintro ⟨b0, s2, a2⟩ ⟨hb, hr0⟩ - simp only at hb hr0 - subst hb - exact (WP.spec_ok _).2 hr0 + obtain ⟨hcbP, hdon⟩ := J.faultEntryBlock hni ht hcur hk hrn hnq' + refine handleFault_ep_wp hep ?_ unfold faults.send_fault_ipc dsimp only -- `set_fault` - set f' : Fl4Spec.Fault := .capFault a0.bv rp lf' with hf' set x2 : Fl4Spec.Tcb := { x with tcbFault := some f' } with hx2 set σf := updK σ ct.bv (.tcb x2) with hσf - refine WP.spec_bind (WP.spec_and (WP.spec_and (set_fault_cap_top hP0 hI ht hk ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩) - (set_fault_cap_eq (L := L) s ct a0 rp lf he)) - (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s ct (.Cap a0 rp lf) (t0 := ct) J.blk htH + refine WP.spec_bind (WP.spec_and (set_fault_G_top hP0 hI ht hk hf) + (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s ct f (t0 := ct) J.blk htH (fun _ h => by simp at h) hcbP) (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s ct (.Cap a0 rp lf) hTH htH))) ?_ - rintro s7 ⟨⟨⟨-, hI7⟩, hs7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ + (Es := P1.EH H) s ct f hTH htH))) ?_ + rintro s7 ⟨⟨⟨-, hI7⟩, hw7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ have hkf : σf.kheap ct.bv = some (.tcb x2) := by simp [hσf, updK] have hkfp : ∀ q, q ≠ ct.bv → σf.kheap q = σ.kheap q := by intro q hq'; rw [hσf]; simp only [updK, Function.update_of_ne hq'] @@ -478,24 +699,9 @@ theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE -- the FL4 step of `set_fault`: the seven words have hC2 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ s7 σf := by refine ⟨?_, SzKeepC.of (SzKeep.of_tcb (p := ct.bv) (x' := x2) (fun q hq' => by simp [hσf, updK, hq']) hkf)⟩ - subst hs7 - have w := ((((((writesIn_wr (st := st) (s := s) (v := lt) (a_lf hta).1).trans - (writesIn_wr (v := l0) (a_lf0 hta).1)).trans (writesIn_wr (v := l1) (a_lf1 hta).1)).trans - (writesIn_wr (v := fl4_abi.consts.fault.CapFault) (a_fault hta).1)).trans (writesIn_wr (v := a0) (a_fw0 hta).1)).trans - (writesIn_wr (v := if rp then 1#u64 else 0#u64) (a_fw1 hta).1)).trans - (writesIn_wr (v := 0#u64) (a_fw2 hta).1) - refine w.mono fun w0 hw0 => ?_ - have k : ∃ K : Nat, 256 ≤ K ∧ K < 4096 ∧ K ≠ 3440 ∧ K ≠ 3472 ∧ ((K ≠ 3512 ∧ K ≠ 3528) ∧ K ≠ 3664 ∧ K ≠ 3456) ∧ w0.val = ct.val + K := by - rcases hw0 with ((((((h | h) | h) | h) | h) | h) | h) <;> subst h - · exact ⟨3408, by omega, by omega, by omega, by omega, by omega, val_lf hta⟩ - · exact ⟨3416, by omega, by omega, by omega, by omega, by omega, val_lf0 hta⟩ - · exact ⟨3424, by omega, by omega, by omega, by omega, by omega, val_lf1 hta⟩ - · exact ⟨3376, by omega, by omega, by omega, by omega, by omega, val_fault hta⟩ - · exact ⟨3384, by omega, by omega, by omega, by omega, by omega, val_fw0 hta⟩ - · exact ⟨3392, by omega, by omega, by omega, by omega, by omega, val_fw1 hta⟩ - · exact ⟨3400, by omega, by omega, by omega, by omega, by omega, val_fw2 hta⟩ - obtain ⟨K, k1, k2, k3, k4, k5, k6⟩ := k - exact Or.inl (Or.inr ⟨ct, ht, K, k1, k2, k3, k4, k5, k6⟩) + refine hw7.mono fun w0 hw0 => ?_ + obtain ⟨K, k1, k2, k6⟩ := hw0 + exact Or.inl (Or.inr ⟨ct, ht, K, by omega, by omega, by omega, by omega, ⟨by omega, by omega⟩, k6⟩) -- the spec's blocking send at `σf` have hprf : ∀ u, Sched.prioOf σf u = Sched.prioOf σ u := by intro u @@ -662,12 +868,35 @@ theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE J.cnW_utc hW hF.1 F.sk.cdt F.sk.orig F.sk.arch hDbg, F.nsc J.nsc, I3, hcur3, F.own J.own, F.off J.off, hAI3, F.bsa J.bsa hscA, F.isorted J.isorted fun y1 hy1 => (hsrt y1 hy1).congr fun u _ => (hprf u).symm, hrun3, hblk⟩ - have hC0 := JCs.same J hF.1 F.ksz + have hC0 := JCs.sameB J hF.1 F.ksz have hCs : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ have J' := J.cs_frameI hks hX3 hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) F.sk.arch (fun q ao h => F.othF h (fun _ e => by cases e) (fun _ e => by cases e)) F.szKeep hF.1 F.kback F.ipcFr hCs R hKd F.sk.orig hidl.1 (J.zD_diffE hpE) exact ⟨⟨_, _, J'.xtop.rel.1, J'.xtop.rel.2.1, J'.xtop.rel.2.2.1, J'.xtop.rel.2.2.2.1, J'.xtop.rel.2.2.2.2.1⟩, - ⟨_, H, Cs, Ac, Lst, D \ {ptr}, J', inferInstance⟩⟩ + ⟨Z.vs, Ac, Lst, D \ {ptr}, J', NatFoot.ofW J.xtop hW (fun b hb => CnW.oobj hS hb) (fun b hb => J.cnW_nv hb) + (fun b hb => J.cnW_nh hb) (natK_bfrt F)⟩⟩ + +/-- The cap-fault instance of the endpoint blocking proof. -/ +theorem JAtZB.faultBlockJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + {ptr bdg : U64} {sd rv g gr : Bool} + (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) + (hcb : ∀ xe, σ.kheap ptr.bv = some (.endpoint xe) → Endp.CanBlock false xe) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.faultBlockJG hni hct hnq hep hcb (FaultCorrG.cap hf) + +/-- `JAtZB.faultBlockJ` at `JAtZ` (`JAtN.post`). -/ +theorem JAtZ.faultBlockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + {ptr bdg : U64} {sd rv g gr : Bool} + (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) + (hcb : ∀ xe, σ.kheap ptr.bv = some (.endpoint xe) → Endp.CanBlock false xe) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.faultBlockJ hni hct hnq hep hcb hf) fun _ h => JAtN.post J h end diff --git a/proofs/Fl4Proofs/P3/XTopJointFaultG.lean b/proofs/Fl4Proofs/P3/XTopJointFaultG.lean index ff017acf4..336f93470 100644 --- a/proofs/Fl4Proofs/P3/XTopJointFaultG.lean +++ b/proofs/Fl4Proofs/P3/XTopJointFaultG.lean @@ -1,243 +1,9 @@ /- -P3 (DESIGN.md §9), invariant line G4 (g4g, KENTRY-PLAN g4g; g4f's handoff (1)): -**`handle_fault` at `J` for every FL4 fault kind the entries raise**. - -XTopJointFaultEp / XTopJointFaultRecv prove FL4's `handle_fault` at `J` for a -cap fault (`CapFaultCorr`). The only cap-fault specific steps are `set_fault` -(seven words, with the lookup failure) and the transfer to a waiting receiver -(`xferFaultStepJ`). Here both are generalised: - -* `FaultCorrN f f'`: FL4's `UnknownSyscall n` / `UserException n c` / - `VmFault ad fsr ins` and l4v's `UnknownSyscallException n` / - `UserException n c` / `VMFault ad [ins, fsr]` (the words FL4 stores, as - `FaultRel'` reads them); `FaultCorrG := CapFaultCorr ∨ FaultCorrN` - (never a timeout: `FaultCorrG.nt`). -* `set_fault_N_eq` (the four fault words), `set_fault_N_top` (l4v's - `thread_set` of the fault on `IRel`, IpcTimeout's `set_fault_timeout_top` - for the other kinds), `set_fault_G_top` (both, with the footprint in the - fault-word range `FRng`). -* `JAtZ.setFaultJG`, `JAtZ.faultBlockJG`, `JAtZ.sendFaultIJG` / - `sendFaultPJG` / `sendFaultPDJG` (the transfer by XTopJointXferF's - `xferFaultStepGJ`, any fault but a timeout), `JAtZ.faultRecvJG`, - `JAtZ.faultHypJZG`: the cap-fault proofs with `FaultCorrG` (same proofs, - the `set_fault` and transfer steps replaced). +The native corollaries of the shared non-timeout fault-handler proof. -/ -import Fl4Proofs.P3.XTopJointXferF +import Fl4Proofs.P3.XTopJointFaultRecv open Aeneas Aeneas.Std Result -namespace Fl4Proofs.P3.Endp -open fl4_core Fl4Proofs.P1 Fl4Proofs.P3 Fl4Proofs.P3.Notif Fl4Proofs.P3.Ipc - -noncomputable section - -/-- **FL4's and the spec's non-cap fault** (module docstring). -/ -def FaultCorrN (f : error.Fault) (f' : Fl4Spec.Fault) : Prop := - (∃ n : U64, f = .UnknownSyscall n ∧ f' = .unknownSyscallException n.bv) ∨ - (∃ n c : U64, f = .UserException n c ∧ f' = .userException n.bv c.bv) ∨ - (∃ (ad fsr : U64) (ins : Bool), f = .VmFault ad fsr ins ∧ - f' = .archFault (.vmFault ad.bv [(if ins then 1#u64 else 0#u64).bv, fsr.bv])) - -/-- **Every fault kind the entries raise** (module docstring). -/ -def FaultCorrG (f : error.Fault) (f' : Fl4Spec.Fault) : Prop := CapFaultCorr f f' ∨ FaultCorrN f f' - -theorem FaultCorrG.nt {f : error.Fault} {f' : Fl4Spec.Fault} (h : FaultCorrG f f') : ∀ b, f' ≠ .timeout b := by - intro b e - subst e - rcases h with ⟨_, _, _, _, -, h, -⟩ | ⟨_, -, h⟩ | ⟨_, _, -, h⟩ | ⟨_, _, _, -, h⟩ <;> cases h - -theorem FaultCorrG.cap {f : error.Fault} {f' : Fl4Spec.Fault} (h : CapFaultCorr f f') : FaultCorrG f f' := Or.inl h - -theorem faultOK_nt {S : Type} {st : machine.Store S} [L : LawfulStore st] (s : S) (snd : U64) (x : Fl4Spec.Tcb) - {f : Fl4Spec.Fault} (h : ∀ b, f ≠ .timeout b) : FaultOK (L := L) s snd x f := by - cases f with - | timeout b => exact absurd rfl (h b) - | _ => trivial - -/-- The fault-word range of the TCB at `t` (`[t + 3376, t + 3432)`). -/ -def FRng (t w : U64) : Prop := ∃ K : Nat, 3376 ≤ K ∧ K < 3432 ∧ w.val = t.val + K - -section Fault -open Fl4Proofs.P3.Sched -variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulStore st] -variable {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} {B : Set (U64 × Fl4Spec.Word)} {c : U64} - -/-- The four fault words written. -/ -def W4 (s : S) (t ty w0 w1 w2 : U64) : S := - L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) (tFw1A t) w1) (tFw2A t) w2 - -/-- **`set_fault` of a non-cap fault** writes the four fault words, which -encode the spec's fault. -/ -theorem set_fault_N_eq {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrN f f') (t : U64) : - ∃ ty w0 w1 w2 : U64, (ty ≠ 0#u64 ∧ ty ≠ 5#u64 ∧ (∀ b, f' ≠ .timeout b) ∧ - ∀ lt l0 l1, FaultRel' ty w0 w1 w2 lt l0 l1 (some f')) ∧ - ∀ s : S, faults.set_fault st s t f ⦃ s' => s' = W4 (L := L) s t ty w0 w1 w2 ⦄ := by - rcases hf with ⟨n, rfl, rfl⟩ | ⟨n, c, rfl, rfl⟩ | ⟨ad, fsr, ins, rfl, rfl⟩ - · refine ⟨fl4_abi.consts.fault.UnknownSyscall, n, 0#u64, 0#u64, - ⟨by unfold fl4_abi.consts.fault.UnknownSyscall; decide, by unfold fl4_abi.consts.fault.UnknownSyscall; decide, - fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.UnknownSyscall; exact ⟨rfl, rfl⟩⟩, - fun s => ?_⟩ - unfold faults.set_fault - simp only [bind_ok] - step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ - step with set_fault_w0_spec as ⟨s2, hs2⟩ - step with set_fault_w1_spec as ⟨s3, hs3⟩ - refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ - rintro s4 rfl - subst hs1 hs2 hs3 - rfl - · refine ⟨fl4_abi.consts.fault.UserException, n, c, 0#u64, - ⟨by unfold fl4_abi.consts.fault.UserException; decide, by unfold fl4_abi.consts.fault.UserException; decide, - fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.UserException; exact ⟨rfl, rfl, rfl⟩⟩, - fun s => ?_⟩ - unfold faults.set_fault - simp only [bind_ok] - step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ - step with set_fault_w0_spec as ⟨s2, hs2⟩ - step with set_fault_w1_spec as ⟨s3, hs3⟩ - refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ - rintro s4 rfl - subst hs1 hs2 hs3 - rfl - · refine ⟨fl4_abi.consts.fault.VMFault, ad, fsr, (if ins then 1#u64 else 0#u64), - ⟨by unfold fl4_abi.consts.fault.VMFault; decide, by unfold fl4_abi.consts.fault.VMFault; decide, - fun b h => by injection h, fun _ _ _ => by unfold FaultRel' fl4_abi.consts.fault.VMFault; exact ⟨rfl, rfl, rfl⟩⟩, - fun s => ?_⟩ - unfold faults.set_fault - cases ins <;> simp only [bind_ok, Bool.false_eq_true, ↓reduceIte] <;> - · step with Fl4Proofs.P1.obj.Tcb.set_fault_type.spec as ⟨s1, hs1⟩ - step with set_fault_w0_spec as ⟨s2, hs2⟩ - step with set_fault_w1_spec as ⟨s3, hs3⟩ - refine WP.spec_mono (set_fault_w2_spec s3 t _) ?_ - rintro s4 rfl - subst hs1 hs2 hs3 - rfl - -set_option maxHeartbeats 4000000 in -/-- **The four fault words of a non-timeout fault** refine l4v's `thread_set` -of the fault, on `IRel` (IpcTimeout's `set_fault_timeout_top` with the words -of any fault). -/ -theorem set_fault_N_top (hP0 : IPlaced N T E R B) {s : S} {σ : Fl4Spec.State Unit} - (hX : IRel st th cr N T C E R B c s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - {f' : Fl4Spec.Fault} {ty w0 w1 w2 : U64} (hty0 : ty ≠ 0#u64) (hty5 : ty ≠ 5#u64) (hnt : ∀ b, f' ≠ .timeout b) - (hfr : ∀ lt l0 l1, FaultRel' ty w0 w1 w2 lt l0 l1 (some f')) : - IRel st th cr N T C E R B c (W4 (L := L) s t ty w0 w1 w2) (updK σ t.bv (.tcb { x with tcbFault := some f' })) := by - obtain ⟨hIR, hSRT⟩ := hX - have hta := hP0.e.tcb t ht - set f : Option Fl4Spec.Fault := some f' - set y : Fl4Spec.Tcb := { x with tcbFault := f } - set σ' := updK σ t.bv (.tcb y) - have hk' : σ'.kheap t.bv = some (.tcb y) := by simp [σ'] - have hidem : updK σ' t.bv (.tcb { y with tcbFault := f }) = σ' := by - show updK (updK σ t.bv (.tcb y)) t.bv (.tcb y) = _; rw [updK_idem'] - unfold W4 - refine ⟨?_, ?_⟩ - · -- the IPC relation - have hfa := (a_fault hta).1 - have h0a := (a_fw0 hta).1 - have h1a := (a_fw1 hta).1 - have h2a := (a_fw2 hta).1 - have vf := val_fault hta - have v0 := val_fw0 hta - have v1 := val_fw1 hta - have v2 := val_fw2 hta - have rd : ∀ w, Aligned w → w ≠ tFw0A t → w ≠ tFw1A t → w ≠ tFw2A t → - L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) (tFw1A t) w1) - (tFw2A t) w2) w = L.mem (L.wr s (tFaultA t) ty) w := by - intro w hw n0 n1 n2 - rw [rd_wr_ne h2a hw (Ne.symm n2), rd_wr_ne h1a hw (Ne.symm n1), rd_wr_ne h0a hw (Ne.symm n0)] - have rft : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = ty := by - rw [rd (tFaultA t) hfa (fun e => by have := congrArg UScalar.val e; omega) - (fun e => by have := congrArg UScalar.val e; omega) (fun e => by have := congrArg UScalar.val e; omega)] - rw [rd_wr_eq hfa] - have rf0 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFw0A t) = w0 := by - rw [rd_wr_ne h2a h0a (fun e => by have := congrArg UScalar.val e; omega), - rd_wr_ne h1a h0a (fun e => by have := congrArg UScalar.val e; omega), rd_wr_eq h0a] - have rf1 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFw1A t) = w1 := by - rw [rd_wr_ne h2a h1a (fun e => by have := congrArg UScalar.val e; omega), rd_wr_eq h1a] - have rf2 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFw2A t) = w2 := by - rw [rd_wr_eq h2a] - have h0 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = 0#u64 ↔ f = none := - ⟨fun h => absurd (rft.symm.trans h) hty0, fun h => by simp [f] at h⟩ - have h5 : L.mem (L.wr (L.wr (L.wr (L.wr s (tFaultA t) ty) (tFw0A t) w0) - (tFw1A t) w1) (tFw2A t) w2) (tFaultA t) = 5#u64 ↔ ∃ b', f = some (.timeout b') := - ⟨fun h => absurd (rft.symm.trans h) hty5, fun ⟨b', hb⟩ => absurd (Option.some.inj hb) (hnt b')⟩ - refine fault_set_ipc hP0 hIR ht hk f (fun w hw hr => ?_) h0 h5 ?_ - · have n0 : w ≠ tFw0A t := fun e => by subst e; omega - have n1 : w ≠ tFw1A t := fun e => by subst e; omega - have n2 : w ≠ tFw2A t := fun e => by subst e; omega - rw [rd w hw n0 n1 n2, rd_wr_ne hfa hw (fun e => by subst e; omega)] - · show FaultRel' _ _ _ _ _ _ _ f - rw [rft, rf0, rf1, rf2] - exact hfr _ _ _ - · -- the scheduler and top relations - have e1 := fault_word_top hSRT ht hk f (K := 3376#u64) (Or.inl rfl) ty - have e2 := fault_word_top e1 ht hk' f (K := 3384#u64) (Or.inr (Or.inl rfl)) w0 - rw [hidem] at e2 - have e3 := fault_word_top e2 ht hk' f (K := 3392#u64) (Or.inr (Or.inr (Or.inl rfl))) w1 - rw [hidem] at e3 - have e4 := fault_word_top e3 ht hk' f (K := 3400#u64) (Or.inr (Or.inr (Or.inr rfl))) w2 - rw [hidem] at e4 - exact e4 - -set_option maxHeartbeats 8000000 in -/-- **`set_fault` of any fault with `FaultCorrG`** refines l4v's `thread_set` -of the fault on `IRel`, writing only the fault-word range. -/ -theorem set_fault_G_top (hP0 : IPlaced N T E R B) {s : S} {σ : Fl4Spec.State Unit} - (hX : IRel st th cr N T C E R B c s σ) {t : U64} (ht : t ∈ T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : - faults.set_fault st s t f ⦃ s' => - (Fl4Spec.threadSet (Z := Unit) (fun tcb => { tcb with tcbFault := some f' }) t.bv σ = - ({((), updK σ t.bv (.tcb { x with tcbFault := some f' }))}, False) ∧ - IRel st th cr N T C E R B c s' (updK σ t.bv (.tcb { x with tcbFault := some f' }))) ∧ - P1.WritesIn st s s' (FRng t) ⦄ := by - have hta := hP0.e.tcb t ht - rcases hf with hc | hn - · obtain ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩ := hc - obtain ⟨⟨lt, l0, l1⟩, he, -⟩ := spec_exists (encode_lfRel hlf) - refine WP.spec_mono (WP.spec_and (set_fault_cap_top hP0 hX ht hk ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩) - (set_fault_cap_eq (L := L) s t a0 rp lf he)) ?_ - rintro s7 ⟨h1, hs7⟩ - refine ⟨h1, ?_⟩ - subst hs7 - have w := ((((((writesIn_wr (st := st) (s := s) (v := lt) (a_lf hta).1).trans - (writesIn_wr (v := l0) (a_lf0 hta).1)).trans (writesIn_wr (v := l1) (a_lf1 hta).1)).trans - (writesIn_wr (v := fl4_abi.consts.fault.CapFault) (a_fault hta).1)).trans (writesIn_wr (v := a0) (a_fw0 hta).1)).trans - (writesIn_wr (v := if rp then 1#u64 else 0#u64) (a_fw1 hta).1)).trans - (writesIn_wr (v := 0#u64) (a_fw2 hta).1) - refine w.mono fun w0 hw0 => ?_ - rcases hw0 with ((((((h | h) | h) | h) | h) | h) | h) <;> subst h - · exact ⟨3408, by omega, by omega, val_lf hta⟩ - · exact ⟨3416, by omega, by omega, val_lf0 hta⟩ - · exact ⟨3424, by omega, by omega, val_lf1 hta⟩ - · exact ⟨3376, by omega, by omega, val_fault hta⟩ - · exact ⟨3384, by omega, by omega, val_fw0 hta⟩ - · exact ⟨3392, by omega, by omega, val_fw1 hta⟩ - · exact ⟨3400, by omega, by omega, val_fw2 hta⟩ - · obtain ⟨ty, w0, w1, w2, ⟨h0, h5, hnt, hfr⟩, hs⟩ := set_fault_N_eq (st := st) (L := L) hn t - refine WP.spec_mono (hs s) ?_ - rintro s' rfl - refine ⟨⟨Notif.threadSet_eq _ hk, set_fault_N_top hP0 hX ht hk h0 h5 hnt hfr⟩, ?_⟩ - have w := (((writesIn_wr (st := st) (s := s) (v := ty) (a_fault hta).1).trans - (writesIn_wr (v := w0) (a_fw0 hta).1)).trans (writesIn_wr (v := w1) (a_fw1 hta).1)).trans - (writesIn_wr (v := w2) (a_fw2 hta).1) - refine w.mono fun u hu => ?_ - rcases hu with (((h | h) | h) | h) <;> subst h - · exact ⟨3376, by omega, by omega, val_fault hta⟩ - · exact ⟨3384, by omega, by omega, val_fw0 hta⟩ - · exact ⟨3392, by omega, by omega, val_fw1 hta⟩ - · exact ⟨3400, by omega, by omega, val_fw2 hta⟩ - -end Fault - -end - -end Fl4Proofs.P3.Endp - namespace Fl4Proofs.P3 open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc Fl4Proofs.P3.Sched @@ -250,44 +16,16 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} -set_option maxHeartbeats 16000000 in -/-- **`set_fault` of any fault with `FaultCorrG` at `J`** (module docstring): the thread not -blocked on send (so `Inv.rd`'s class is unchanged), P1's `CanBlock` of any -thread carried. -/ theorem JAtZ.setFaultJG (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.set_fault st s t f ⦃ s' => ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s' a - (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ⦄ := by - have hP0 := J.ip - have hI := J.xtop.irelK J.ks J.buf - have hta := hP0.e.tcb t ht - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb - refine WP.spec_mono (WP.spec_and (set_fault_G_top hP0 hI ht hk hf) - (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s t f (t0 := t0) J.blk htH - (fun _ h => by simp at h) hcb) - (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := ∅) s t f hTH htH))) ?_ - rintro s7 ⟨⟨⟨-, hI7⟩, hw7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ - have hwF : P1.WritesIn st s s7 (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) := by - refine hw7.mono fun w0 hw0 => ?_ - obtain ⟨K, k1, k2, k6⟩ := hw0 - exact Or.inr ⟨t, ht, K, by omega, by omega, by omega, by omega, ⟨by omega, by omega⟩, k6⟩ - set y : Fl4Spec.Tcb := { x with tcbFault := some f' } - have hA : QKY σ (updK σ t.bv (.tcb y)) := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun p => ?_⟩ - by_cases hp : p = t.bv - · subst hp; exact Or.inr (Or.inl ⟨x, y, hk, by simp [updK], rfl⟩) - · exact Or.inl (by simp [updK, hp]) - obtain ⟨V, J'⟩ := J.fin_frameF hI7 hwF hA (YK.YKS.updTcb (y := y) hk rfl).ykeep - (J.inv.updSame (y := y) hk rfl rfl (Or.inr hns)) hblk7 hfoot7 - exact ⟨V, J', hcb7⟩ + (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ⦄ := + WP.spec_mono (J.toB.setFaultJG ht hk hns hcb hf) fun _ ⟨B, hb, hw⟩ => + ⟨Z.vs, B.toJAtZ (J.ext_oobj hw (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) + (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb)), hb⟩ -set_option maxHeartbeats 64000000 in -/-- **`handle_fault` with an endpoint handler and no waiting receiver at -`J`** (module docstring). -/ theorem JAtZ.faultBlockJG (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) {ptr bdg : U64} {sd rv g gr : Bool} @@ -295,305 +33,9 @@ theorem JAtZ.faultBlockJG (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE (hcb : ∀ xe, σ.kheap ptr.bv = some (.endpoint xe) → Endp.CanBlock false xe) {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - obtain ⟨hcur, x, hk, hrn⟩ := J.curRunnable hni hct - have hP0 := J.ip - have hI := J.xtop.irelK J.ks J.buf - have hS := J.xtop.fin.1.1.1 - have hT : TcbPlaced Z.T := hP0.e.tcb - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb - have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 - obtain ⟨Q, R, hcq, hs⟩ := hS.lists - have hct' : ct = nodeW st s Z.c layout.node.CUR_THREAD := by - have h := sched.cur_thread.spec' (L := L) s - rw [hct, WP.spec_ok, hcq.cur] at h; exact h - have ht : ct ∈ Z.T := by rw [hct']; exact hcq.curT - have hta := hP0.e.tcb ct ht - have htH : ct ∈ P1.Heap.tcbs H := J.zH.1 ct ht - have htD : ct ∉ D := fun h => J.notDead ht hk (by have := runnable_code hrn; omega) ct h rfl - have hnq' : ∀ d p, ct.bv ∉ σ.readyQueues d p := by rw [← hcur]; exact hnq - have hC : CurInv σ := J.curInv (by rw [hni.2]; intro e; cases e) - have hnr : ct.bv ∉ σ.releaseQueue := by rw [← hcur]; exact hC.notRel - have hti : σ.curThread ≠ σ.idleThread := hni.1 - have hidt : σ.idleThread ≠ ct.bv := fun e => hti (by rw [hcur, e]) - -- the handler cap, its endpoint - obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb - rw [hk] at hk1; cases hk1 - have e1 : c1 = .Endpoint ptr bdg sd rv g gr := by rw [hep] at hc1; simpa using hc1.symm - subst e1 - have habs := hcr.2 - simp only [absCap] at habs - have hfh : x.tcbFaultHandler = .endpointCap ptr.bv bdg.bv (rightsOf sd rv g gr) := habs.symm - have hAS : AbsSlot Z.th (ct.bv, Fl4Spec.tcbCnodeIndex 3) := ⟨ct, rfl, Or.inr ⟨htcb, 3, by decide, rfl⟩⟩ - have hpE : ptr ∈ Z.E := J.slotE hAS hep - obtain ⟨xe, hke, -⟩ := hI.1.ep ptr hpE - have hcbe : Endp.CanBlock false xe := hcb xe hke - have hpt : ptr.bv ≠ ct.bv := fun e => by rw [e, hk] at hke; cases hke - have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE - have hfit := J.kern.heap.fits ptr _ hHe - simp only [P1.HKind.bits] at hfit - have hcov := J.cover_cap (P1.WritesIn.refl s _) hAS.isSlot hep (fun h => by cases h) (ok_inj (phys_eq _).symm) rfl - (range_ep ptr bdg sd rv g gr hfit) fun k hk' => by - rw [hHe] at hk'; cases hk' - exact ⟨by simp only [P1.HKind.bits]; omega, fun z h => by cases h⟩ - -- P1's `CanBlock` of the current thread - obtain ⟨bq, br⟩ := J.curBits ht hnq' hnr - obtain ⟨hna, -⟩ := J.words_of_spec ht (fun u hu => by rw [hni.2] at hu; cases hu) - (fun e => hni.1 (by rw [hcur, e])) - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct ht - rw [hk] at hk0; cases hk0 - have hv : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by - rw [P1.stA_eq, ← tStA_eq]; exact hTR.st - obtain ⟨hnb, hnrp⟩ := P1.run_word (w := L.mem s (P1.stA ct)) (by rw [hv]; exact runnable_code hrn) - have ha0 : L.actionW s = 0#u64 := by - have h := hS.act - rw [hni.2] at h - unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h - have hcw : L.curW s = ct := by - apply P1.eq_of_bv - rw [← hcur, hs.curThread] - unfold P1.LawfulStore.curW nodeW; rw [hcq.cur] - have hcbP : P1.CanBlock st (P1.Heap.tcbs H) Ac s ct := by - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hS0, hSg0⟩ := J.blk - refine ⟨htH, hnb, hnrp, bq, br, hna, ?_, ?_⟩ - · intro h - have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by - unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] - exact hti (by rw [hcur, hs.idleTh, ← ei, h]) - · exact fun h1 => hB0.sact ct htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw⟩))))) h1 - -- the spec's donation flag is FL4's - obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb ct ht - rw [hk] at hkt6; cases hkt6 - have hdon : (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by - rw [hsct6] - by_cases h0 : L.mem s (scA ct) = 0#u64 - · simp [h0, Notif.optRef] - · simp [h0, Notif.optRef] - -- `handle_fault`: the handler cap - unfold faults.handle_fault - rw [tcb_slot_fault] - apply ok_bind_spec - rw [slot_cap_eq, hep] - apply ok_bind_spec - step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ - subst hi - refine WP.spec_bind (Pₘ := fun r : Bool × S × A => r.1 = true ∧ - ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.2.1 z.2 ∧ JAt (L := L) arI AR r.2.1 r.2.2 z.2) ?_ ?_ - swap - · rintro ⟨b0, s2, a2⟩ ⟨hb, hr0⟩ - simp only at hb hr0 - subst hb - exact (WP.spec_ok _).2 hr0 - unfold faults.send_fault_ipc - dsimp only - -- `set_fault` - set x2 : Fl4Spec.Tcb := { x with tcbFault := some f' } with hx2 - set σf := updK σ ct.bv (.tcb x2) with hσf - refine WP.spec_bind (WP.spec_and (set_fault_G_top hP0 hI ht hk hf) - (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s ct f (t0 := ct) J.blk htH - (fun _ h => by simp at h) hcbP) - (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s ct f hTH htH))) ?_ - rintro s7 ⟨⟨⟨-, hI7⟩, hw7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ - have hkf : σf.kheap ct.bv = some (.tcb x2) := by simp [hσf, updK] - have hkfp : ∀ q, q ≠ ct.bv → σf.kheap q = σ.kheap q := by - intro q hq'; rw [hσf]; simp only [updK, Function.update_of_ne hq'] - have hkef : σf.kheap ptr.bv = some (.endpoint xe) := by rw [hkfp _ hpt]; exact hke - -- the FL4 step of `set_fault`: the seven words - have hC2 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ s7 σf := by - refine ⟨?_, SzKeepC.of (SzKeep.of_tcb (p := ct.bv) (x' := x2) (fun q hq' => by simp [hσf, updK, hq']) hkf)⟩ - refine hw7.mono fun w0 hw0 => ?_ - obtain ⟨K, k1, k2, k6⟩ := hw0 - exact Or.inl (Or.inr ⟨ct, ht, K, by omega, by omega, by omega, by omega, ⟨by omega, by omega⟩, k6⟩) - -- the spec's blocking send at `σf` - have hprf : ∀ u, Sched.prioOf σf u = Sched.prioOf σ u := by - intro u - by_cases hut : u = ct.bv - · subst hut; exact (prioOf_eq hkf).trans (prioOf_eq hk).symm - · unfold Sched.prioOf; rw [tcbsOf_eq, tcbsOf_eq, hkfp u hut] - have hnb0 : tsCode x.tcbState ≠ 3 ∧ tsCode x.tcbState ≠ 4 := by - have := runnable_code hrn; omega - have htq : ct.bv ∉ xe.epQueue := Endp.not_queued hI.1.toE ht hk hnb0 ptr hpE xe hke - have hqm : ∀ u ∈ xe.epQueue, ∃ z, σf.kheap u = some (.tcb z) := fun u hu => by - obtain ⟨z, hz, -⟩ := (J.sv.epQ _ _ hke).2 u hu - exact ⟨z, by rw [hkfp u (fun e => htq (e ▸ hu))]; exact hz⟩ - obtain ⟨σ', heq, F0, hik0, ⟨ds, hkt'⟩, -, -, hcn, hsrt⟩ := - sendIpcBlock_eq hkf hkef hcbe htq hqm hrn ((J.isorted.1 _ _ hke).congr fun u _ => hprf u) - false bdg.bv g gr (L.mem s (scA ct) != 0#u64) - -- FL4's blocking send - have hIS : IpcSorted σf := QPK.QPS.sorted (QPK.qps_upd (ko := .tcb x2) hk rfl) J.isorted - obtain ⟨⟨Q0, R0, h0⟩, hB0', hX0, hS0, hSg0⟩ := hblk7 - have hst0 : L.epState s7 ptr = 0#u64 ∨ L.epState s7 ptr = 1#u64 := by - have hx := hI7.1.toE.at_ep hpE hkef - rw [epState_eq] - cases xe with - | idleEP => exact Or.inl hx.1 - | sendEP q => exact Or.inr hx.1 - | recvEP q => simp [Endp.CanBlock] at hcbe - have hnn : ∀ m, x2.tcbState ≠ .blockedOnNotification m := fun m h => by - have h' : tsCode x.tcbState = 6 := congrArg tsCode h - have := runnable_code hrn; omega - have p1f : endpoint.send_ipc st arI s7 a true false bdg g gr (L.mem s (scA ct) != 0#u64) ct ptr ⦃ s' _ => - P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s7 s' ⦄ := - P1.endpoint.send_ipc.blockFoot arI s7 a true false bdg g gr _ ct ptr h0 (fun _ => hcb7) hHe hst0 - refine WP.spec_bind (WP.spec_and (WP.spec_and (send_ipc_blockF (ar := arI) hP0 s7 a σf hI7 ht hkf hnb0 hnn hpE hkef - hcbe (Sched.qSorted_of_spec (L := L) hI7.1.toE hI7.1.toN hT hIS ptr (Or.inl hpE)) false bdg g gr - (L.mem s (scA ct) != 0#u64)) - (P1.endpoint.send_ipc.block arI s7 a true false bdg g gr _ ct ptr Q0 R0 h0 hB0' hX0 hS0 hSg0 - (fun _ => hcb7) hHe hst0)) - p1f) ?_ - rintro ⟨s', a'⟩ ⟨⟨⟨ea, σ0, h0eq, hIR, hW3⟩, hbk⟩, hfoot3⟩ - simp only [WP.uncurry'_pair] at ea hbk hfoot3 hIR hW3 - subst a' - obtain rfl : σ' = σ0 := by - have e1 := (Prod.mk.inj (h0eq.symm.trans heq)).1 - exact (congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 e1)).symm - apply (WP.spec_ok _).2 - refine ⟨rfl, ?_⟩ - -- the spec's outcome - have hz : ((), σ') ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv - (decide (Fl4Spec.Rights.allowGrant ∈ rightsOf sd rv g gr)) - (decide (Fl4Spec.Rights.allowGrantReply ∈ rightsOf sd rv g gr)) (decide (x.tcbSchedContext ≠ none)) ct.bv - ptr.bv (updK σ ct.bv (.tcb { x with tcbFault := some f' }))).1 := by - rw [rights_grant, rights_grantReply, ← hdon] - show ((), σ') ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv g gr _ ct.bv ptr.bv σf).1 - rw [heq]; exact Set.mem_singleton _ - refine ⟨((), σ'), handleFault_ep_mem hk hfh _ hz, ?_⟩ - -- the frame from the start - have hkt3 : σ'.kheap ct.bv = - some (.tcb { x with tcbState := .blockedOnSend ptr.bv ds, tcbFault := some f' }) := hkt' - have hsk : Sk σ σ' := by - have h2 : Sk σ σf := ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ - exact h2.trans F0.sk - have F : BFrT ct.bv ptr.bv σ σ' := by - refine ⟨hsk, fun q => ?_⟩ - by_cases hqt : q = ct.bv - · subst hqt - exact Or.inr ⟨_, _, hk, hkt3, Or.inl ⟨x, ptr.bv, ds, some f', rfl, rfl, rfl⟩⟩ - · rcases F0.kh q with e | ⟨o, o', h1, h2, hc⟩ - · exact Or.inl (e.trans (hkfp q hqt)) - · rw [hkfp q hqt] at h1 - rcases hc with ⟨_, _, _, _, _, e3, -⟩ | ⟨x1, y1, rfl, rfl, e3⟩ - · exact absurd e3 hqt - · exact Or.inr ⟨_, _, h1, h2, Or.inr ⟨x1, y1, rfl, rfl, e3⟩⟩ - -- the FL4 footprint from the start - have hC3 : Ipc.CnStep (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s7 σf s' σ' := ⟨hW3, SzKeepC.of F0.szKeep⟩ - have hW : P1.WritesIn st s s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := (hC2.trans hC3).1 - have hfoot := P1.Foot.trans hfoot7 hfoot3 - have hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s' := ⟨⟨Q0, R0, hbk.1⟩, hbk.2⟩ - -- the assembly (as XTopJointSendBlockG's `JAtZ.runTmoJ`) - have hAR : AR a σ.archState.x64CurrentCr3 := J.xtop.fin.1.1.2.2.2.2.2.2 - have hF : IFrame (L := L) Z.th s s' := IRel.iframe_of hI hW fun b hb => CnW.oobj hI.2.2.1 hb - obtain ⟨V', hX3⟩ := XTopAt.irel_same J.xtop hIR hAR hF.1 F.sk.cdt F.sk.orig F.ksub hF.2 - have hks : L.ksb s' = L.ksb s := hF.2 - obtain ⟨k1, k2, kb, k3, k4⟩ := J.cnW_keeps hW - have ck := F.callKeep - have hCR' : CallRel (L.mem s') Z.R Z.C σ' Lst := - J.call.frame k3 k4 (fun q _ y n hy => ck.1 _ y n hy) (fun d _ x hx => ck.2.1 _ x hx) - have hRP' := J.rp.frame hks ck.2.2 - have hRF' : RFree (L.mem s') Z.R Z.C σ' Lst := by - intro d hd hfd - obtain ⟨y, hy, hyt⟩ := hfd - obtain ⟨e1, e2⟩ := k4 d hd - obtain ⟨h1, h2, h3⟩ := J.rfree d hd ⟨y, F.replyB hy, hyt⟩ - exact ⟨h1, by rw [e2]; exact h2, by rw [e1]; exact h3⟩ - have hDbg := J.kw_dbg hfoot - have hKd := J.kw_dbgKeep hfoot - have hS3 : SchedRel st Z.N Z.T Z.C Z.c s' σ' := hIR.2.2.1 - -- the scheduler: the current thread blocked, a reschedule pending - have hcn' : σ'.schedulerAction = .chooseNewThread := hcn hcur.symm hni.2 - have hAI3 : ActIdle σ' := ⟨fun u hu => (by rw [hcn'] at hu; cases hu), F.idleOK J.act.2 hidt⟩ - have hcur3 : σ'.schedulerAction = .chooseNewThread ∨ CurInv σ' := Or.inl hcn' - have hrun3 : CurRunM σ' := Or.inl (by rw [hcn']; intro h; cases h) - -- the dead: the thread is not dead; the endpoint leaves the dead set - have hdead : ∀ q ∈ D \ {ptr}, DeadP (L := L) H s' q := fun q hq => by - have hd := J.jcov.dead q hq.1 - have hqt : q.bv ≠ ct.bv := fun h => htD (by rw [← P1.eq_of_bv h]; exact hq.1) - have hqe : q.bv ≠ ptr.bv := fun h => hq.2 (P1.eq_of_bv h) - refine J.deadP_keep hS3 hIR.1 (fun x hx h0 => ⟨_, F.tcbO hqt hx, rfl, rfl, Or.inl rfl⟩) (fun x hx => ?_) - (fun x hx => ⟨x, F.ntfnF hx, Or.inl rfl, rfl, Or.inl rfl⟩) - (fun x hx => ⟨x, F.replyF hx, rfl⟩) (fun x n hx => ⟨x, F.scF hx, Or.inl rfl, Or.inl rfl⟩) - (fun hqC => k3 q hqC) (fun z hz hqC K hK8 hK => J.cnW_scOut hW hz hqC hK8 hK) F.sk.idle hAI3.1 - (J.yld.frame k2 F.ykeep) (F.ykeep.dk q.bv) hd - obtain ⟨y, hy, hc'⟩ := F.epF hx - rcases hc' with rfl | e1 - · exact hy - · exact absurd e1 hqe - have hidl := J.idleW_keep hS3 F.sk.idle F.sk.isc - have hjpl : ∃ Tr Cq, JPlaced (L := L) Z.th H Tr Cq s' σ' := by - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - exact ⟨Tr, Cq, hJ.same hF.1 (fun q y n _ hq => F.szKeep q.bv y n hq) hks (J.cnW_irq hW) hidl.2⟩ - have hkern := J.kern_keep hks hW.2.1 hS3 F.sk.ct F.sk.csc (fun sl h => Or.inl (by rw [← F.sk.orig]; exact h)) - (by rw [F.sk.arch]) - (fun q ao h => F.othF h (fun _ e => by cases e) (fun _ e => by cases e)) hDbg - (D' := D \ {ptr}) - have hRR' := J.rrecv.frame k4 F.khrb - have hjcov : JCovD (L := L) Z.th H Z.G (D \ {ptr}) Cs s' := by - obtain ⟨-, ⟨-, -, hM, -, -⟩, -⟩ := J.xtop.rel - have hsl : ∀ x ∈ Z.G.chains.flatten, IsSlot Z.th x := fun x h => ((hM.members x).1 h).1 - exact (J.jcov.undead hcov.1 hcov.2).same (fun y hy _ _ => ⟨hy, hF.1.capV (hsl y hy)⟩) - (fun q hq _ => hdead q hq) - (J.jcov.ks.keep hks fun x hx p sb fi d hc => ⟨x, hx, fi, by rw [← hF.1.capV (hsl x hx)]; exact hc⟩) hidl hks - (J.jcov.idleOut.keep hidl fun x hx p sb fi d hc => ⟨x, hx, fi, by rw [← hF.1.capV (hsl x hx)]; exact hc⟩) - (fun q _ h => h.keep (DXKeep.of_dbg hKd (J.cnW_td hW))) - -- `Inv` (`InvBut.ik`; the blocked sender's `RelIfBound` from the runnable thread's) - have hts6 : Fl4Spec.threadSet (Z := Unit) (fun tcb => { tcb with tcbFault := some f' }) ct.bv σ = - ({((), σf)}, False) := Notif.threadSet_eq _ hk - have hik : IK ct.bv σ σ' := - ((ikm_threadSet (t := ct.bv) (p := ct.bv) (g := fun tcb => { tcb with tcbFault := some f' }) - fun _ => ⟨rfl, fun h => absurd rfl h, fun h => absurd rfl h⟩).of_eq hts6).trans hik0 - have hnqT : NotQueued σ ct.bv := ⟨hnq', hnr⟩ - obtain ⟨hIB, -⟩ := (J.inv.toBut ct.bv).ik hnqT hik - have hskp : Ipc.SKeep σ σ' := ⟨F.sk.rel, F.sk.tm, fun p y hy => by - obtain ⟨x', hx', e, -⟩ := F.tcbScB hy; exact ⟨x', hx', e.symm⟩, fun p y n hy => F.scB hy⟩ - have hrib : RelIfBound σ' ct.bv := Ipc.RelIfBound.of_keep (J.inv.rd ct.bv x hk (Or.inl hrn)) hskp - have I3 : Inv σ' := hIB.inv fun _ _ _ => hrib - -- `BlockedScActive`: the thread's SC is the current SC, active - have hscA : ∀ p y n, σ.kheap p = some (.schedContext y n) → y.scTcb = some ct.bv → - Fl4Spec.scActive y = true := by - intro p y n hp hyt - obtain ⟨q, hqC, eq⟩ := J.obj.sc p y n hp - subst eq - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hq0 := J.c0 q hqC - have hqS : q ∈ P1.Heap.scs H := ⟨_, (hJ.sc q y n hq0 hp).2⟩ - obtain ⟨u, -, -, xu, hku, hxs⟩ := scBack_of hS J.blk.2.2.1 J.tcbs_eq.1.symm hqC hqS hq0 hp hyt - rw [hk] at hku; cases hku - obtain ⟨xc, hkc, hcs, -⟩ := hC.tcb - rw [hcur, hk] at hkc; cases hkc - have e1 : σ.curSc = q.bv := Option.some.inj (hcs.symm.trans hxs) - rw [← e1] at hp - exact hC.active (J.curSc_ne_idle hC hti) y n hp - have R : JRest (L := L) arI (Z.mv Z.G V') H Cs Ac Lst (D \ {ptr}) s' σ' := - ⟨hCR', hRF', hRR', J.yld.frame k2 F.ykeep, J.mcp.frame k1 F.mcpKeep, J.buf.frame kb F.bufKeep, hRP', - J.apart.sc_frame hks F.szKeep, hjpl, hjcov, hkern, - J.cnW_utc hW hF.1 F.sk.cdt F.sk.orig F.sk.arch hDbg, F.nsc J.nsc, I3, hcur3, F.own J.own, F.off J.off, - hAI3, F.bsa J.bsa hscA, F.isorted J.isorted fun y1 hy1 => (hsrt y1 hy1).congr fun u _ => (hprf u).symm, - hrun3, hblk⟩ - have hC0 := JCs.same J hF.1 F.ksz - have hCs : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ - have J' := J.cs_frameI hks hX3 hW (fun b hb => Ipc.CnW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => J.cnW_nv hb) F.sk.arch - (fun q ao h => F.othF h (fun _ e => by cases e) (fun _ e => by cases e)) F.szKeep hF.1 F.kback F.ipcFr hCs R hKd F.sk.orig hidl.1 (J.zD_diffE hpE) - exact ⟨⟨_, _, J'.xtop.rel.1, J'.xtop.rel.2.1, J'.xtop.rel.2.2.1, J'.xtop.rel.2.2.2.1, J'.xtop.rel.2.2.2.2.1⟩, - ⟨_, H, Cs, Ac, Lst, D \ {ptr}, J', inferInstance⟩⟩ - -set_option maxHeartbeats 64000000 in -/-- **A faulted sender (any fault but a timeout)'s `send_ipc` to a waiting receiver at `J` where -the sender gets no reply** (XTopJointSendCall's `JAtZ.sendCallIJ` for -`call = false` and a sender with a cap fault, running or restarting: FL4 reads -the fault word where the call flag is false; the transfer is the fault -transfer `do_ipc_transfer_capFJ`). + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.faultBlockJG hni hct hnq hep hcb hf) fun _ h => JAtN.post J h -Original docstring: -(module docstring): the receiver has no reply object, or the caller neither -the grant nor the grant-reply right (`hno`); as `JAtZ.sendRecvJ0` up to the -reply unlink, then the caller `Inactive` on `IRel` (its queue bits clear by -`JAtZ.curBits`: in no ready queue, `hnq`, l4v `ct_not_in_q`, and not in the -release queue, `CurInv.notRel`), the receiver `Running`, `JAtZ` by -`JAtZ.wake_postCI` (the spec's two state changes swapped, `ciSt_swap`), the -tail `JAtZ.sendTailJ`; the spec's outcome `sendIpc_callInactive_eq`. -/ theorem JAtZ.sendFaultIJG (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) (hrn : Fl4Spec.runnable xt.tcbState = true) {fq : Fl4Spec.Fault} @@ -607,450 +49,9 @@ theorem JAtZ.sendFaultIJG (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none) : endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - have hI := J.xtop.irelK J.ks J.buf - have hP0 := J.ip - have hP := hP0.e - have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) - (c := Z.c) hP - have hR := hI.1.toE - have hS0 := IpcRel.toSRN hI.1 hI.2 - have hTe : Z.T = P1.Heap.tcbs H := J.tcbs_eq.1 - have hRe : Z.R = P1.Heap.replies H := J.tcbs_eq.2 - have hx := hR.at_ep he hk - have hxt := hR.at_tcb ht hkt - obtain ⟨hst2, xs, hxs0, hq, hQ, hB⟩ := hx - obtain ⟨d', xs', rfl⟩ := List.exists_cons_of_ne_nil hxs0 - simp only [List.map_cons, List.cons.injEq] at hq - obtain ⟨hd', hq'⟩ := hq - have hdd : d' = d := eq_of_bv hd'.symm - subst hdd - have hdT : d' ∈ Z.T := hQ.mem d' (by simp) - have hda := hP.tcb d' hdT - obtain ⟨xd, hkd, -⟩ := hI.1.tcb d' hdT - have hxd := hR.at_tcb hdT hkd - have hd3 : (L.mem s (tStA d')).val = 3 := (hB d' (by simp)).1 - have hdb : L.mem s (tBlockA d') = e := (hB d' (by simp)).2 - obtain ⟨e', rep, dd, hstd⟩ := tsCode_three (hxd.st.symm.trans hd3) - have he' : e' = e.bv := by - have := hxd.blk e' (by rw [hstd]; rfl); rw [hdb] at this; exact this.symm - subst he' - obtain ⟨hrep, hrepR⟩ := hxd.recv _ _ _ hstd - have hnb : tsCode xt.tcbState ≠ 3 ∧ tsCode xt.tcbState ≠ 4 := by have := runnable_code hrn; omega - have htd : t ≠ d' := by intro h; subst h; exact hnb.1 (hxt.st.symm.trans hd3) - have hde : d'.bv ≠ e.bv := kheap_ne hkd hk (fun _ h1 h2 => by subst h1; cases h2) - have hte : t.bv ≠ e.bv := kheap_ne hkt hk (fun _ h1 h2 => by subst h1; cases h2) - have htd' : t.bv ≠ d'.bv := bv_ne htd - have hdc : d'.bv ≠ σ.curThread := by rw [hct]; exact Ne.symm htd' - -- P1's facts at the start - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hSc0, hSg0⟩ := J.blk - have hdH : d' ∈ P1.Heap.tcbs H := J.zH.1 d' hdT - have hHe : H e = some .ep := J.zH.2.1 e he - have hTP : P1.TcbPlaced (P1.Heap.tcbs H) := h0.tcbs - have hdta := hTP d' hdH - have hsub := hSg0.sub - have hds : L.mem s (P1.stA d') = sched.TS_BLOCKED_ON_RECV := by - rw [stA_tStA, tsVals.2.2.1]; exact UScalar.eq_of_val_eq hd3 - have hbe : L.mem s (P1.blockA d') = e := by rw [P1.blockA_eq, ← tBlockA_eq]; exact hdb - have hdq := P1.endpoint.ep_dequeue.inv s d' Q0 R0 h0 hdH (by simp) (Or.inr (Or.inl hds)) - rw [hbe] at hdq - obtain ⟨E0, EQ0, hEW0⟩ := h0.eps - have heE0 : e ∈ E0 := (hEW0.2.2.2.2.2.2.2.1 e).2 (Or.inl hHe) - obtain ⟨hE0, -, hq0'⟩ := hEW0.1 e heE0 - have hdm : d' ∈ EQ0 e := by - have := hEW0.2.2.2.2.1 d' hdH (by simp) (Or.inr (Or.inl hds)); rw [hbe] at this; exact this.2 - have pf := P1.endpoint.ep_dequeue.foot s e d' (EQ0 e) hTP hE0 hq0' hdm - -- FL4: the endpoint's state and queue - unfold endpoint.send_ipc - refine WP.spec_bind (Fl4Proofs.P1.obj.Ep.state.spec s e) ?_ - rintro _ rfl - rw [epState_eq, hst2] - rw [if_neg (by rw [ep_state_vals.1]; decide), if_neg (by rw [ep_state_vals.2.1]; decide)] - refine WP.spec_bind (Fl4Proofs.P1.endpoint.get_queue.spec s e) ?_ - rintro _ rfl - have hhead : (L.epQ s e).head = d' := by rw [epQ_eq]; exact hQ.head - rw [hhead] - -- the dequeue - refine WP.spec_bind (WP.spec_and (WP.spec_and (ep_dequeue_c hH hP0 hP s σ hR hS0 he hk (d := d') - (by simp [Fl4Spec.Endpoint.epQueue])) (ep_dequeue_full hP s he d' _ hQ (by simp))) - (WP.spec_and hdq pf)) ?_ - rintro s1 ⟨⟨⟨-, hR1, hS1, hA1⟩, -, -, hQA, hWE, -, -⟩, ⟨h1, f1, o1, n1, k1, c1, nc1⟩, w1⟩ - set σ1 := Notif.updK σ e.bv (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) with hσ1 - have hW1a : P1.WritesIn st s s1 (fun b => EW e b ∨ ∃ w ∈ (d' :: xs'), TL w b) := - ⟨hWE.1, hWE.2.1, fun b hb hn => hQA b hb ⟨fun h => hn (Or.inl h), fun h => hn (Or.inr h)⟩⟩ - have hW1 : P1.WritesIn st s s1 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hW1a.mono fun b hb => by - rcases hb with h | ⟨w, hw, h | h⟩ - · exact Or.inr (Or.inl ⟨e, he, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3496, by omega, by omega, by omega, by omega, by omega, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3504, by omega, by omega, by omega, by omega, by omega, h⟩) - have F1 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s1 := - P1.Foot.of w1 fun b hb => hb.kw hq0'.mem (Or.inl hHe) - obtain ⟨hB1, hX1, hS1', hSg1, -, -, -⟩ := P1.frame_bx h0 hB0 hX0 hSc0 hSg0 f1 o1 n1 k1 - (P1.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 _ (hSg0.sub _ (hX0.1.ntB n' hn').2)⟩) - have hkt1 : σ1.kheap t.bv = some (.tcb xt) := by simp [σ1, hte, hkt] - have hkd1 : σ1.kheap d'.bv = some (.tcb xd) := by simp [σ1, hde, hkd] - have hk1e : σ1.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by simp [σ1] - have hdb1 : L.mem s1 (tBlockA d') = e := by - rw [hA1 _ (a_blk hda).1 ⟨d', hdT, (a_blk hda).2⟩, hdb] - have hq1 := dequeued_not_queued hR1 he hdb1 hk1e (epDeq_not_mem _) - have Fr1 : CFr e.bv d'.bv σ σ1 := CFr.upd hk (Or.inr (Or.inr (Or.inl ⟨_, _, rfl, rfl, - by rw [epDeq_queue']; unfold Fl4Spec.removeAll; exact List.filter_sublist, - by simp [Fl4Spec.Endpoint.epQueue]⟩))) - have IK1 : IK d'.bv σ σ1 := IK.updOther (o' := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) hk (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩) - have SK1 : SKeep σ σ1 := SKeep.updK (p := e.bv) (o := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) (fun y h => by cases h) (fun _ _ h => by cases h) - have hOK1 : Endp.IpcBufCapOK σ1 := ipcBufCapOK_epStep (J.xferH).1 (EpStep.ep hk) - -- the transfer - have hdth : Z.th d' = some .tcb := by - obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 - exact Ipc.RelTopB.tcbT hB0' hkd - have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g - hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ - rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ - set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 - have hkd2 : σ2.kheap d'.bv = some (.tcb x2) := by simp [σ2] - have hkt2 : σ2.kheap t.bv = some (.tcb xt) := by simp [σ2, htd', hkt1] - have hst2' : x2.tcbState = .blockedOnReceive e.bv rep dd := by rw [hx2]; exact hstd - have hxsc : x2.tcbSchedContext = xd.tcbSchedContext := by rw [hx2] - have hN2 := ntfn_lift_rcv hP0.toC hS1.2 hR2 hdT hA2 (fun p hp => by simp [σ2, hp]) - hkd1 hkd2 (by rw [hx2]) - have hS2' : SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) s2 σ2 := ⟨hS2.1, hN2⟩ - have hk1e2 : σ2.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by - simp [σ2, Ne.symm hde, hk1e] - have hq2 : ∀ e'' ∈ Z.E, ∀ z, σ2.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := by - intro e'' he'' z hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h, hkd2] at hz; cases hz - exact hq1 e'' he'' z (by simpa [σ2, Ne.symm hne] using hz) - have hrw : L.mem s2 (tReplyA d') = L.mem s (tReplyA d') := by - rw [hA2 _ (a_reply hda).1 ⟨?_, ?_⟩, hA1 _ (a_reply hda).1 ⟨d', hdT, (a_reply hda).2⟩] - · rintro ⟨r', hr'⟩ - rw [val_reply hda, regA_val hda (regIdx_lt r')] at hr'; have := regIdx_lt r'; omega - · rintro ⟨wp, hwp, e'⟩ - have h1' := hP.bt wp hwp d' hdT - have h2' := val_reply hda - rw [← e'] at h1'; omega - have hW2 : P1.WritesIn st s s2 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - (hW1.mono fun b hb => Or.inl hb).trans1 (w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', -, eb⟩ | hb) | hb - · have hyT : y ∈ Z.T := by rw [hTe]; exact hy - refine Or.inl (Or.inl (Or.inr ⟨y, hyT, K.val, h1', by omega, by omega, by omega, by omega, ?_⟩)) - rw [eb]; exact tfield_val (hP.tcb y hyT) (by omega) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb) - have F2 : P1.WritesIn st s1 s2 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) (P1.EH H) s1 b ∨ RcvBufW xd b) := - w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', h3', eb⟩ | hb) | hb - · exact Or.inl (Or.inl ⟨y, hy, K, by omega, by omega, by omega, by omega, eb⟩) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb - have Fr2 : CFr e.bv d'.bv σ σ2 := (Fr1.trans (CFr.um _ _ σ1 um2)).trans (CFr.upd (σ := Endp.setUm σ1 um2) hkd1 - (Or.inl ⟨xd, xd.tcbState, xd.tcbBoundNotification, xd.tcbFault, x2.tcbArch, rfl, by rw [hx2], - Or.inr ⟨Or.inl rfl, rfl, Or.inl ⟨_, _, _, hstd⟩, Or.inr (Or.inr rfl)⟩⟩)) - have IK2 : IK d'.bv σ σ2 := IK1.trans ((IK.um _ σ1 um2).trans (IK.updSelf (σ := Endp.setUm σ1 um2) hkd1 hxsc)) - have SK2 : SKeep σ σ2 := SK1.trans ((SKeep.um σ1 um2).trans (SKeep.updK (σ := Endp.setUm σ1 um2) (p := d'.bv) - (o := .tcb x2) (fun y h => ⟨xd, hkd1, by cases h; exact hxsc.symm⟩) (fun _ _ h => by cases h))) - have hks2 : L.ksb s2 = L.ksb s := hW2.1 - have Fst2 : L.mem s2 (P1.stA d') = L.mem s (P1.stA d') := by - rw [P1.stA_eq] - exact (f2 d' hdH _ (by simp) (by simp) (by simp)).trans (f1 d' hdH _ (by simp) (by simp) (by simp) (by simp)) - have hds2 : L.mem s2 (P1.stA d') = sched.TS_BLOCKED_ON_RECV := Fst2.trans hds - -- the reply object - refine WP.spec_bind (Endp.obj.Tcb.reply_obj.spec s2 d') ?_ - rintro _ rfl - rw [hrw] - simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true] - refine WP.spec_bind (Pₘ := fun s3 => ∃ σ3 x3 X3, - Fl4Spec.NonDet.maybeM (Fl4Spec.replyUnlinkTcb (Z := Unit) d'.bv) rep σ2 = ({((), σ3)}, False) ∧ - EpStateRel Z.T Z.E Z.R Z.B (L.mem s3) σ3 ∧ - SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) s3 σ3 ∧ - σ3.kheap t.bv = some (.tcb xt) ∧ σ3.kheap d'.bv = some (.tcb x3) ∧ RbIn x3.tcbState ∧ - tsCode x3.tcbState ≠ 6 ∧ x3.tcbSchedContext = xd.tcbSchedContext ∧ - (∀ e'' ∈ Z.E, ∀ z, σ3.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue) ∧ - P1.WritesIn st s s3 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) ∧ - P1.WritesIn st s s3 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) (P1.EH H) s b ∨ RcvBufW xd b) ∧ - CFr e.bv d'.bv σ σ3 ∧ IK d'.bv σ σ3 ∧ SKeep σ σ3 ∧ σ3.curThread = σ.curThread ∧ - σ3.schedulerAction = σ.schedulerAction ∧ - P1.SchedQueuesInvX st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H X3 s3 Q0 R0 ∧ - P1.BoundInv st (P1.Heap.tcbs H) Ac s3 ∧ - P1.XInv st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) (P1.Heap.frame H) (P1.Heap.replies H) (P1.Heap.scs H) - (P1.Heap.ntfns H) (P1.Heap.scBits H) s3 ∧ - P1.SCsOK st (P1.Heap.tcbs H) (P1.Heap.omega H) (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) Ac s3 ∧ - P1.SgOK st (P1.Heap.omega H) (P1.Heap.frame H) s3 ∧ P1.ExcT X3 d' ∧ - (d' ∈ X3 ∨ ¬ P1.Blocked (L.mem s3 (P1.stA d'))) ∧ - (∀ r ∈ P1.Heap.replies H, L.mem s3 (P1.rTcbA r) ≠ d')) ?_ ?_ - · cases hrp : rep with - | none => - rw [hrp] at hrep - have h00 := optRef_none hrep - simp only [h00, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - have hrA : L.mem s2 (P1.replyA d') = 0#u64 := by - show L.mem s2 (tReplyA d') = 0#u64; rw [hrw]; exact h00 - exact ⟨σ2, x2, _, rfl, hR2, hS2', hkt2, hkd2, Or.inl ⟨_, _, _, hst2'⟩, - by rw [hst2']; simp [tsCode], hxsc, hq2, hW2, footW_trans (footW_of F1) F2, Fr2, IK2, SK2, rfl, rfl, h2, hB2, hX2, hS2'', - hSg2, fun y hy => by simpa using hy, Or.inl (Or.inr rfl), hX2.noref0 hdta hrA⟩ - | some r => - rw [hrp] at hrep hrepR hst2' - obtain ⟨hw0, hwr⟩ := Notif.optRef_some hrep - have hwR := hrepR (by simp) - have hne0 : (L.mem s (tReplyA d') != 0#u64) = true := by simp [hw0] - simp only [hne0, ↓reduceIte] - set w := L.mem s (tReplyA d') with hwdef - subst hwr - obtain ⟨xr, hkr, -⟩ := hR.reply w hwR - have hwe : w.bv ≠ e.bv := kheap_ne hkr hk (fun _ h1 h2 => by subst h1; cases h2) - have hwd : w.bv ≠ d'.bv := kheap_ne hkr hkd (fun _ h1 h2 => by subst h1; cases h2) - have hwt : w.bv ≠ t.bv := kheap_ne hkr hkt (fun _ h1 h2 => by subst h1; cases h2) - have hkr2 : σ2.kheap w.bv = some (.reply xr) := by simp [σ2, σ1, hwe, hwd, hkr] - have hb' : xr.replyTcb = some d'.bv := hback_of J.sv hkd e.bv w.bv dd xr (by rw [hstd, hrp]) hkr - have hX2' := IpcRel.ofSRN hR2 hS2' - have hrA : L.mem s2 (P1.replyA d') = w := by show L.mem s2 (tReplyA d') = w; rw [hrw] - obtain ⟨hiR, hit⟩ := hX2.2.1.recv d' hdH hds2 (by rw [hrA]; exact hw0) - rw [hrA] at hiR hit - refine WP.spec_mono (WP.spec_and (WP.spec_and (reply_unlink_c hH hP0 hP s2 σ2 hR2 hS2' hdT hkd2 hst2' hwR hkr2 - hb' hq2) (reply_unlink_cn hP0 hX2' hdT hwR hkr2)) - (WP.spec_and (P1.ipc.reply_unlink.inv s2 w d' Q0 R0 h2 hdH hX2.1 hsub hiR hit - (by rw [hds2]; exact P1.blocked_not_runnable (Or.inr (Or.inl rfl))) (Or.inl (Or.inr rfl))) - (P1.ipc.reply_unlink.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s2 w d' h2 hX2 hsub hiR hdH))) ?_ - rintro s3 ⟨⟨⟨e3, hR3, hS3⟩, hW3⟩, ⟨h3, e3', k3, z3⟩, fu3⟩ - have hclr : ∀ r ∈ P1.Heap.replies H, L.mem s2 (P1.rTcbA r) = d' → L.mem s3 (P1.rTcbA r) = 0#u64 := by - intro r hr er - obtain ⟨-, -, b2, -⟩ := hX2.2.1.back r hr (by rw [er]; exact fun e0 => hdta.ne0 (by rw [e0]; rfl)) - rw [er, hrA] at b2; rw [← b2]; exact z3 - set x3 : Fl4Spec.Tcb := { x2 with tcbState := .inactive } with hx3 - set σ3a := Notif.updK σ2 w.bv (.reply { xr with replyTcb := none }) with hσ3a - have hkd3a : σ3a.kheap d'.bv = some (.tcb (x2)) := by simp [σ3a, Ne.symm hwd, hkd2] - have hct3a : d'.bv ≠ (Notif.updK σ3a d'.bv (.tcb x3)).curThread := hdc - have e3s : Notif.stsAct (Notif.updK σ3a d'.bv (.tcb x3)) d'.bv = Notif.updK σ3a d'.bv (.tcb x3) := - stsAct_ne hct3a - have hW3' : P1.WritesIn st s s3 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW2.trans1 (hW3.mono fun b hb => Or.inl (cnW_back hks2 (SzKeepC.of Fr2.szKeep) hb)) - refine ⟨_, x3, _, e3, hR3, hS3, ?_, ?_, Or.inr rfl, by simp [x3, tsCode], by simp [x3, hxsc], ?_, hW3', - footW_trans (footW_trans (footW_of F1) F2) (footW_of fu3), ?_, ?_, ?_, ?_, ?_, h3, - hB2.keepT h2 k3 (by rw [e3']; exact P1.not_blocked_inactive) (by rw [e3']; exact P1.inactive_ne.1), - hX2.keepT k3 (by rw [e3']; exact P1.inactive_ne) hclr, hS2''.keepT hX2 k3, - ⟨hsub, fun b hb => by rw [k3.ksb]; exact hSg2.ks b hb, fun o h1' h2' => by rw [k3.ksb]; exact hSg2.ksΩ o h1' h2'⟩, - fun y hy => ?_, Or.inr (by rw [e3']; exact P1.not_blocked_inactive), - (hX2.keepT k3 (by rw [e3']; exact P1.inactive_ne) hclr).noref hdta (by rw [e3']; exact P1.inactive_ne.1) - (by rw [e3']; exact P1.inactive_ne.2)⟩ - · rw [stsAct_kheap]; simp [σ3a, htd', hwt.symm, hkt2] - · rw [stsAct_kheap]; simp - · intro e'' he'' z hz - rw [stsAct_kheap] at hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp at hz - have hne' : w.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp [σ3a, hwd] at hz - exact hq2 e'' he'' z (by simpa [σ3a, Ne.symm hne, Ne.symm hne'] using hz) - · exact (Fr2.trans (CFr.upd hkr2 (Or.inr (Or.inr (Or.inr ⟨xr, rfl, rfl, hb'⟩))))).trans - (CFr.stsIn hkd3a (Or.inl ⟨_, _, _, hst2'⟩)) - · have IK3a : IK d'.bv σ σ3a := IK2.trans (IK.updOther (o' := .reply { xr with replyTcb := none }) hkr2 (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩)) - have IK3b : IK d'.bv σ (Notif.updK σ3a d'.bv (.tcb x3)) := IK3a.trans (IK.updSelf (y := x3) hkd3a rfl) - exact IK3b.trans (IK.sts _ _ _) - · exact ((SK2.trans (SKeep.updK (p := w.bv) (o := .reply { xr with replyTcb := none }) (fun y h => by cases h) (fun _ _ h => by cases h))).trans - (SKeep.updK (p := d'.bv) (o := .tcb x3) (fun y h => ⟨_, hkd3a, by cases h; rfl⟩) (fun _ _ h => by cases h))).trans (SKeep.stsAct _ _) - · rw [e3s]; rfl - · rw [e3s]; rfl - · obtain ⟨hy1, hy2⟩ := hy - rcases hy1 with hy1 | hy1 - · exact absurd hy1 (Set.notMem_empty _) - · exact absurd hy1 hy2 - rintro s3 ⟨σ3, x3, X3, hU, hR3, hS3, hkt3, hkd3, hrb3, hns3, hsc3, hq3, hW3, F3, Fr3, IK3, SK3, hct3, hact3, - h3, hB3, hX3, hS3', hSg3, hXc3, hx3, hnr3⟩ - have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by - have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) - rw [hft] at h00; cases h00 - have hks3 : L.ksb s3 = L.ksb s := hW3.1 - -- the caller's facts for its `Inactive` - have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) - have hnrT : t.bv ∉ σ.releaseQueue := by rw [← hct]; exact hCI.notRel - obtain ⟨hqb, hrb'⟩ := J.curBits ht hnq hnrT - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hw3 : (L.mem s3 (P1.stA t)).val = tsCode xt.tcbState := by - rw [P1.stA_eq, ← tStA_eq, hxt3.st] - obtain ⟨hnbt3, hnrp3⟩ := P1.run_word (w := L.mem s3 (P1.stA t)) (by rw [hw3]; exact runnable_code hrn) - have hSR3 : SchedRel st Z.N Z.T Z.C Z.c s3 σ3 := (IpcRel.ofSRN hR3 hS3).2.2.1 - have hna3 : L.actionW s3 ≠ t := by - obtain ⟨Q, R', hcq, -⟩ := hSR3.lists - have h := hSR3.act - rw [hact3, hres] at h - have ha0 : L.actionW s3 = 0#u64 := by unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h - rw [ha0]; intro h'; exact (hcq.tcbs t ht).ne0 (by rw [← h']; rfl) - have hqt3 := Endp.not_queued hR3 ht hkt3 hnb - have hstsT := WP.spec_and (WP.spec_and (set_thread_state_c hH hP0 hP s3 σ3 hR3 hS3 ht hkt3 hqt3 - (by have := runnable_code hrn; omega) .inactive (by simp [tsCode]) sched.TS_INACTIVE (by unfold sched.TS_INACTIVE; rfl)) - (set_thread_state_sfoot hSR3 ht sched.TS_INACTIVE)) - (WP.spec_and (P1.sts_all s3 t _ Q0 R0 h3 hB3 hX3 hS3' hSg3 htH P1.not_blocked_inactive P1.inactive_ne - (Or.inr hnbt3) (hX3.noref (hTP t htH) hnrp3 (fun e0 => hnbt3 (Or.inr (Or.inl e0)))) - ⟨fun c hc' p hp hm => absurd hm (h0.notQ htH hqb hc' hp), fun c hc' hm => absurd hm (h0.notR htH hrb' hc'), - fun e0 => absurd e0 hna3⟩) - (P1.sched.set_thread_state.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s3 t sched.TS_INACTIVE h3 htH)) - -- FL4: no reply pushed, the caller `Inactive` - refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ sched.set_thread_state st s3 t sched.TS_INACTIVE = ok r.1) - ?_ ?_ - · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ - rintro i1 rfl - rw [if_pos (bne_iff_ne.2 hty3)] - by_cases hi : (L.mem s (tReplyA d') != 0#u64) = true - · rw [if_pos hi] - have hgg : g = false ∧ gr = false := by - rcases hno with h | hn - · exact h - · exfalso - have hr0 := hn xd hkd _ _ _ hstd - rw [hr0] at hrep - have h00 := optRef_none hrep - rw [h00] at hi - simp at hi - obtain ⟨rfl, rfl⟩ := hgg - simp only [Bool.false_eq_true, ↓reduceIte] - exact WP.spec_bind (spec_self hstsT) fun s4 h4 => (WP.spec_ok _).2 ⟨rfl, h4⟩ - · rw [if_neg hi] - exact WP.spec_bind (spec_self hstsT) fun s4 h4 => (WP.spec_ok _).2 ⟨rfl, h4⟩ - rintro ⟨s4, a4⟩ ⟨ha4, hs4⟩ - simp only at ha4 hs4 - subst ha4 - try dsimp only - have hpost := hstsT - rw [hs4] at hpost - obtain ⟨⟨⟨hR4, hS4⟩, hW4⟩, ⟨h4, hB4, hX4, hS4', hSg4, -, k4⟩, fu4⟩ := (WP.spec_ok _).1 hpost - have hkd4 : (ciSt σ3 t.bv xt).kheap d'.bv = some (.tcb x3) := by rw [ciSt_kh (Ne.symm htd')]; exact hkd3 - have hq4 : ∀ e'' ∈ Z.E, ∀ z, (ciSt σ3 t.bv xt).kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := - fun e'' he'' z hz => hq3 e'' he'' z (by rw [← ciSt_kh (ciSt_ne hz (fun _ h => by cases h))]; exact hz) - have hx4 : d' ∈ {y | y ∈ X3 ∧ y ≠ t} ∨ ¬ P1.Blocked (L.mem s4 (P1.stA d')) := by - rcases hx3 with h | h - · exact Or.inl ⟨h, Ne.symm htd⟩ - · right - have e0 : L.mem s4 (P1.stA d') = L.mem s3 (P1.stA d') := by - rw [P1.stA_eq] - exact k4.fld d' hdH _ (by simp) (by simp) (by simp) (by simp) (fun e1 => absurd e1 (Ne.symm htd)) - rw [e0]; exact h - have hnr4 : ∀ r ∈ P1.Heap.replies H, L.mem s4 (P1.rTcbA r) ≠ d' := fun r hr => by - rcases k4.rtcb r hr with e0 | ⟨-, e0⟩ - · rw [e0]; exact hnr3 r hr - · rw [e0]; intro h0'; exact hdta.ne0 (by rw [← h0']; rfl) - have hks4 : L.ksb s4 = L.ksb s := hW4.1.trans hks3 - -- the receiver runs - refine WP.spec_bind (WP.spec_and (WP.spec_and (set_thread_state_c hH hP0 hP s4 _ hR4 hS4 hdT hkd4 hq4 hns3 - .running (by simp [tsCode]) sched.TS_RUNNING (by unfold sched.TS_RUNNING; rfl)) - (set_thread_state_sfoot (IpcRel.ofSRN hR4 hS4).2.2.1 hdT sched.TS_RUNNING)) - (WP.spec_and (P1.sts_all s4 d' _ Q0 R0 h4 hB4 hX4 hS4' hSg4 hdH P1.not_blocked_running P1.running_ne hx4 hnr4 - ⟨fun _ _ _ _ _ => P1.runnable_running, fun _ _ _ => P1.runnable_running, fun _ => P1.runnable_running⟩) - (P1.sched.set_thread_state.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s4 d' sched.TS_RUNNING h4 hdH))) ?_ - rintro s5 ⟨⟨⟨hR5, hS5⟩, hW5⟩, ⟨h5, hB5, hX5, hS5', hSg5, -, -⟩, fu5⟩ - set x5 : Fl4Spec.Tcb := { x3 with tcbState := .running } with hx5 - set σa := Notif.stsAct (Notif.updK σ3 d'.bv (.tcb x5)) d'.bv with hσa - have hdc3 : d'.bv ≠ σ3.curThread := by rw [hct3]; exact hdc - have heq5 : Notif.stsAct (Notif.updK (ciSt σ3 t.bv xt) d'.bv (.tcb x5)) d'.bv = ciSt σa t.bv xt := - ciSt_swap htd' hdc3 - have hkta : σa.kheap t.bv = some (.tcb xt) := by rw [hσa, stsAct_kheap]; simp [Notif.updK, htd', hkt3] - have hIR0 := IpcRel.ofSRN hR5 hS5 - have hIR : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s5 (ciSt σa t.bv xt) := by - rw [← heq5]; exact hIR0 - have hW4' : P1.WritesIn st s s4 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW3.trans1 (hW4.mono fun b hb => Or.inl (Or.inl (Or.inl (KFoot.of_sfoot ((SFoot.ksb hks3).1 hb))))) - have hW5' : P1.WritesIn st s s5 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW4'.trans1 (hW5.mono fun b hb => Or.inl (Or.inl (Or.inl (KFoot.of_sfoot ((SFoot.ksb hks4).1 hb))))) - have hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s5 := - ⟨⟨Q0, R0, h5.congrX (P1.excT_congr (X := {y | y ∈ X3 ∧ y ≠ t}) (fun y hy => hXc3 y hy.1))⟩, hB5, hX5, hS5', hSg5⟩ - have hfoot := footW_trans (footW_trans F3 (footW_of fu4)) (footW_of fu5) - have Fr5 : CFr e.bv d'.bv σ σa := Fr3.trans (CFr.stsRun hkd3 hrb3) - have IK5a : IK d'.bv σ (Notif.updK σ3 d'.bv (.tcb x5)) := IK3.trans (IK.updSelf (y := x5) hkd3 rfl) - have IK5 : IK d'.bv σ σa := IK5a.trans (IK.sts _ _ _) - have SK5 : SKeep σ σa := (SK3.trans (SKeep.updK (p := d'.bv) (o := .tcb x5) (fun y h => ⟨x3, hkd3, by cases h; rfl⟩) - (fun _ _ h => by cases h))).trans (SKeep.stsAct _ _) - have hnqD : NotQueued σ d'.bv := by - refine ⟨fun dm p hm => ?_, fun hm => ?_⟩ - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rq dm p _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rel _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - have hrib : RelIfBound σa d'.bv := - Ipc.RelIfBound.of_keep (J.inv.rd d'.bv xd hkd (Or.inr (Or.inr (Or.inr ⟨_, _, _, hstd⟩)))) SK5 - have I5 : Inv σa := ((J.inv.toBut d'.bv).ik hnqD IK5).1.inv fun _ _ _ => hrib - have act5 : σa.schedulerAction = σ.schedulerAction := by - rw [hσa, stsAct_ne (by show d'.bv ≠ σ3.curThread; exact hdc3)]; exact hact3 - -- the caller's `Inactive` after the wake (`ciSt_swap`) - have hnqT : ∀ dm p, t.bv ∉ σa.readyQueues dm p := by rw [IK5.2.1]; exact hnq - have hnrT' : t.bv ∉ σa.releaseQueue := by rw [IK5.2.2.1]; exact hnrT - have I5' : Inv (ciSt σa t.bv xt) := ciSt_inv hkta I5 hnqT hnrT' - have B5' : BlockedScActive (ciSt σa t.bv xt) := ciSt_bsa (Fr5.bsa J.bsa) - have hcn : (ciSt σa t.bv xt).schedulerAction = .chooseNewThread := - ciSt_act (by rw [Fr5.sk.ct, hct]) (by rw [act5, hres]) - have hidT : σa.idleThread ≠ t.bv := by rw [Fr5.sk.idle, ← hct]; exact fun e0 => hti e0.symm - have hAI5 : ActIdle (ciSt σa t.bv xt) := - ⟨fun u hu => (by rw [hcn] at hu; cases hu), ciSt_idleOK hidT (Fr5.idleOK J.act.2)⟩ - have hrun5 : CurRunM (ciSt σa t.bv xt) := Or.inl (by rw [hcn]; intro h; cases h) - have hcD : ∀ q ∈ D, q.bv ≠ t.bv := J.notDead ht hkt (by have := runnable_code hrn; omega) - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot - have hIu := Ju.xtop.irelK Ju.ks Ju.buf - have htD := Ju.not_dead_of_st hdT hkd (by rw [hstd]; simp [tsCode]) - have hRR : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → - Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' - hxt' hkd (by rw [hstd]; rfl) - have hF : IFrame (L := L) Z.th su s5 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb - obtain ⟨V', J5⟩ := Ju.wake_postCI hkta hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) I5' B5' hAI5 - (Or.inl hcn) hrun5 hRR htD hcD ⟨d', hdT, rfl⟩ - -- the tail - have G := (ciSt_skD (σ := σa) (c := t.bv) (x := xt)) - have hk5 : (ciSt σa t.bv xt).kheap d'.bv = some (.tcb x5) := by - rw [ciSt_kh (Ne.symm htd'), hσa, stsAct_kheap]; simp - have hnr5 : d'.bv ∉ (ciSt σa t.bv xt).releaseQueue := by rw [ciSt_rel, SK5.1]; exact hnqD.2 - have hact5 : ∀ p y n, x5.tcbSchedContext = some p → (ciSt σa t.bv xt).kheap p = some (.schedContext y n) → - Fl4Spec.scActive y = true := by - intro p y n hp hy - have hya : σa.kheap p = some (.schedContext y n) := by - rw [← ciSt_kh (ciSt_ne hy (fun _ h => by cases h))]; exact hy - have hy0 := SK5.2.2.2 p y n hya - have hp' : xd.tcbSchedContext = some p := by rw [← hsc3]; exact hp - obtain ⟨y', n', hky', hyt⟩ := J.inv.back _ _ _ hkd hp' - rw [hy0] at hky'; cases hky' - exact J.bsa.tcb p y n d'.bv xd hy0 hyt hkd (by rw [hstd]; rfl) - have hti5 : d'.bv ≠ (ciSt σa t.bv xt).idleThread := by - rw [G.idle, Fr5.sk.idle] - intro h - obtain ⟨x, hkx, -, hxs, -⟩ := J.act.2 - rw [← h, hkd] at hkx; cases hkx; rw [hstd] at hxs; cases hxs - have htc5 : d'.bv ≠ (ciSt σa t.bv xt).curThread := by rw [G.ct, Fr5.sk.ct]; exact hdc - have hcond : ¬ ((g = true ∨ gr = true) ∧ rep ≠ none) := by - rintro ⟨hg, hr⟩ - rcases hno with ⟨rfl, rfl⟩ | hn - · rcases hg with h | h <;> cases h - · exact hr (hn xd hkd _ _ _ hstd) - have hspec := sendIpc_faultInactive_eq (don := don) hk hkd hde htd' hstd blk badge.bv g gr hcond e2 hU hkt3 hkd3 - (by rw [hft]; simp) (t := t.bv) - have hspec' : Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ = - Endp.specWakeTailE d'.bv (ciSt σa t.bv xt) := by - rw [hspec]; exact congrArg _ heq5 - refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ - simp only at ha7 - subst ha7 - exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ - + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.sendFaultIJG ht hkt hrn hft hnt hct hres hti hnq he hk blk badge g gr don hno) fun _ ⟨z, hz, h⟩ => ⟨z, hz, JAtN.toJAt J h⟩ -set_option maxHeartbeats 64000000 in -/-- **A faulted sender (any fault but a timeout)'s `send_ipc` to a waiting receiver at `J` that -pushes a reply without a donation** (XTopJointSendPush's `JAtZ.sendCallPJ` -for `call = false` and a sender with a cap fault, running or restarting; -the transfer `do_ipc_transfer_capFJ`). Original docstring: (module docstring): the caller has the grant or grant-reply right -(`hg`), the receiver a reply object (`hrepn`), and the call does not donate or -the receiver has an SC (`hnd`); as `JAtZ.sendCallIJ` up to the reply unlink, -then `reply_push` on `IRel` (`reply_push_iG`, no donation), P1's -`reply_push.ipc` and `reply_push.nd`, the receiver `Running`, `JAtZ` by -`JAtZ.wake_postGR` at `pushSt` (`ps_swap`), the tail `JAtZ.sendTailJ`; the -spec's outcome `sendIpc_call_eq`. -/ theorem JAtZ.sendFaultPJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) (hrn : Fl4Spec.runnable xt.tcbState = true) {fq : Fl4Spec.Fault} @@ -1065,517 +66,9 @@ theorem JAtZ.sendFaultPJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H (hnd : don = false ∨ ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none) : endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - have hI := J.xtop.irelK J.ks J.buf - have hP0 := J.ip - have hP := hP0.e - have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) - (c := Z.c) hP - have hR := hI.1.toE - have hS0 := IpcRel.toSRN hI.1 hI.2 - have hTe : Z.T = P1.Heap.tcbs H := J.tcbs_eq.1 - have hRe : Z.R = P1.Heap.replies H := J.tcbs_eq.2 - have hx := hR.at_ep he hk - have hxt := hR.at_tcb ht hkt - obtain ⟨hst2, xs, hxs0, hq, hQ, hB⟩ := hx - obtain ⟨d', xs', rfl⟩ := List.exists_cons_of_ne_nil hxs0 - simp only [List.map_cons, List.cons.injEq] at hq - obtain ⟨hd', hq'⟩ := hq - have hdd : d' = d := eq_of_bv hd'.symm - subst hdd - have hdT : d' ∈ Z.T := hQ.mem d' (by simp) - have hda := hP.tcb d' hdT - obtain ⟨xd, hkd, -⟩ := hI.1.tcb d' hdT - have hxd := hR.at_tcb hdT hkd - have hd3 : (L.mem s (tStA d')).val = 3 := (hB d' (by simp)).1 - have hdb : L.mem s (tBlockA d') = e := (hB d' (by simp)).2 - obtain ⟨e', rep, dd, hstd⟩ := tsCode_three (hxd.st.symm.trans hd3) - have he' : e' = e.bv := by - have := hxd.blk e' (by rw [hstd]; rfl); rw [hdb] at this; exact this.symm - subst he' - obtain ⟨hrep, hrepR⟩ := hxd.recv _ _ _ hstd - have hnb : tsCode xt.tcbState ≠ 3 ∧ tsCode xt.tcbState ≠ 4 := by have := runnable_code hrn; omega - have htd : t ≠ d' := by intro h; subst h; exact hnb.1 (hxt.st.symm.trans hd3) - have hde : d'.bv ≠ e.bv := kheap_ne hkd hk (fun _ h1 h2 => by subst h1; cases h2) - have hte : t.bv ≠ e.bv := kheap_ne hkt hk (fun _ h1 h2 => by subst h1; cases h2) - have htd' : t.bv ≠ d'.bv := bv_ne htd - have hdc : d'.bv ≠ σ.curThread := by rw [hct]; exact Ne.symm htd' - -- P1's facts at the start - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hSc0, hSg0⟩ := J.blk - have hdH : d' ∈ P1.Heap.tcbs H := J.zH.1 d' hdT - have hHe : H e = some .ep := J.zH.2.1 e he - have hTP : P1.TcbPlaced (P1.Heap.tcbs H) := h0.tcbs - have hdta := hTP d' hdH - have hsub := hSg0.sub - have hds : L.mem s (P1.stA d') = sched.TS_BLOCKED_ON_RECV := by - rw [stA_tStA, tsVals.2.2.1]; exact UScalar.eq_of_val_eq hd3 - have hbe : L.mem s (P1.blockA d') = e := by rw [P1.blockA_eq, ← tBlockA_eq]; exact hdb - have hdq := P1.endpoint.ep_dequeue.inv s d' Q0 R0 h0 hdH (by simp) (Or.inr (Or.inl hds)) - rw [hbe] at hdq - obtain ⟨E0, EQ0, hEW0⟩ := h0.eps - have heE0 : e ∈ E0 := (hEW0.2.2.2.2.2.2.2.1 e).2 (Or.inl hHe) - obtain ⟨hE0, -, hq0'⟩ := hEW0.1 e heE0 - have hdm : d' ∈ EQ0 e := by - have := hEW0.2.2.2.2.1 d' hdH (by simp) (Or.inr (Or.inl hds)); rw [hbe] at this; exact this.2 - have pf := P1.endpoint.ep_dequeue.foot s e d' (EQ0 e) hTP hE0 hq0' hdm - -- FL4: the endpoint's state and queue - unfold endpoint.send_ipc - refine WP.spec_bind (Fl4Proofs.P1.obj.Ep.state.spec s e) ?_ - rintro _ rfl - rw [epState_eq, hst2] - rw [if_neg (by rw [ep_state_vals.1]; decide), if_neg (by rw [ep_state_vals.2.1]; decide)] - refine WP.spec_bind (Fl4Proofs.P1.endpoint.get_queue.spec s e) ?_ - rintro _ rfl - have hhead : (L.epQ s e).head = d' := by rw [epQ_eq]; exact hQ.head - rw [hhead] - -- the dequeue - refine WP.spec_bind (WP.spec_and (WP.spec_and (ep_dequeue_c hH hP0 hP s σ hR hS0 he hk (d := d') - (by simp [Fl4Spec.Endpoint.epQueue])) (ep_dequeue_full hP s he d' _ hQ (by simp))) - (WP.spec_and hdq pf)) ?_ - rintro s1 ⟨⟨⟨-, hR1, hS1, hA1⟩, -, -, hQA, hWE, -, -⟩, ⟨h1, f1, o1, n1, k1, c1, nc1⟩, w1⟩ - set σ1 := Notif.updK σ e.bv (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) with hσ1 - have hW1a : P1.WritesIn st s s1 (fun b => EW e b ∨ ∃ w ∈ (d' :: xs'), TL w b) := - ⟨hWE.1, hWE.2.1, fun b hb hn => hQA b hb ⟨fun h => hn (Or.inl h), fun h => hn (Or.inr h)⟩⟩ - have hW1 : P1.WritesIn st s s1 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hW1a.mono fun b hb => by - rcases hb with h | ⟨w, hw, h | h⟩ - · exact Or.inr (Or.inl ⟨e, he, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3496, by omega, by omega, by omega, by omega, by omega, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3504, by omega, by omega, by omega, by omega, by omega, h⟩) - have F1 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s1 := - P1.Foot.of w1 fun b hb => hb.kw hq0'.mem (Or.inl hHe) - obtain ⟨hB1, hX1, hS1', hSg1, -, -, -⟩ := P1.frame_bx h0 hB0 hX0 hSc0 hSg0 f1 o1 n1 k1 - (P1.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 _ (hSg0.sub _ (hX0.1.ntB n' hn').2)⟩) - have hkt1 : σ1.kheap t.bv = some (.tcb xt) := by simp [σ1, hte, hkt] - have hkd1 : σ1.kheap d'.bv = some (.tcb xd) := by simp [σ1, hde, hkd] - have hk1e : σ1.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by simp [σ1] - have hdb1 : L.mem s1 (tBlockA d') = e := by - rw [hA1 _ (a_blk hda).1 ⟨d', hdT, (a_blk hda).2⟩, hdb] - have hq1 := dequeued_not_queued hR1 he hdb1 hk1e (epDeq_not_mem _) - have Fr1 : CFr e.bv d'.bv σ σ1 := CFr.upd hk (Or.inr (Or.inr (Or.inl ⟨_, _, rfl, rfl, - by rw [epDeq_queue']; unfold Fl4Spec.removeAll; exact List.filter_sublist, - by simp [Fl4Spec.Endpoint.epQueue]⟩))) - have IK1 : IK d'.bv σ σ1 := IK.updOther (o' := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) hk (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩) - have SK1 : SKeep σ σ1 := SKeep.updK (p := e.bv) (o := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) (fun y h => by cases h) (fun _ _ h => by cases h) - have hOK1 : Endp.IpcBufCapOK σ1 := ipcBufCapOK_epStep (J.xferH).1 (EpStep.ep hk) - -- the transfer - have hdth : Z.th d' = some .tcb := by - obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 - exact Ipc.RelTopB.tcbT hB0' hkd - have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g - hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ - rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ - set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 - have hkd2 : σ2.kheap d'.bv = some (.tcb x2) := by simp [σ2] - have hkt2 : σ2.kheap t.bv = some (.tcb xt) := by simp [σ2, htd', hkt1] - have hst2' : x2.tcbState = .blockedOnReceive e.bv rep dd := by rw [hx2]; exact hstd - have hxsc : x2.tcbSchedContext = xd.tcbSchedContext := by rw [hx2] - have hN2 := ntfn_lift_rcv hP0.toC hS1.2 hR2 hdT hA2 (fun p hp => by simp [σ2, hp]) - hkd1 hkd2 (by rw [hx2]) - have hS2' : SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) s2 σ2 := ⟨hS2.1, hN2⟩ - have hk1e2 : σ2.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by - simp [σ2, Ne.symm hde, hk1e] - have hq2 : ∀ e'' ∈ Z.E, ∀ z, σ2.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := by - intro e'' he'' z hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h, hkd2] at hz; cases hz - exact hq1 e'' he'' z (by simpa [σ2, Ne.symm hne] using hz) - have hrw : L.mem s2 (tReplyA d') = L.mem s (tReplyA d') := by - rw [hA2 _ (a_reply hda).1 ⟨?_, ?_⟩, hA1 _ (a_reply hda).1 ⟨d', hdT, (a_reply hda).2⟩] - · rintro ⟨r', hr'⟩ - rw [val_reply hda, regA_val hda (regIdx_lt r')] at hr'; have := regIdx_lt r'; omega - · rintro ⟨wp, hwp, e'⟩ - have h1' := hP.bt wp hwp d' hdT - have h2' := val_reply hda - rw [← e'] at h1'; omega - have hW2 : P1.WritesIn st s s2 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - (hW1.mono fun b hb => Or.inl hb).trans1 (w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', -, eb⟩ | hb) | hb - · have hyT : y ∈ Z.T := by rw [hTe]; exact hy - refine Or.inl (Or.inl (Or.inr ⟨y, hyT, K.val, h1', by omega, by omega, by omega, by omega, ?_⟩)) - rw [eb]; exact tfield_val (hP.tcb y hyT) (by omega) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb) - have F2 : P1.WritesIn st s1 s2 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) (P1.EH H) s1 b ∨ RcvBufW xd b) := - w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', h3', eb⟩ | hb) | hb - · exact Or.inl (Or.inl ⟨y, hy, K, by omega, by omega, by omega, by omega, eb⟩) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb - have Fr2 : CFr e.bv d'.bv σ σ2 := (Fr1.trans (CFr.um _ _ σ1 um2)).trans (CFr.upd (σ := Endp.setUm σ1 um2) hkd1 - (Or.inl ⟨xd, xd.tcbState, xd.tcbBoundNotification, xd.tcbFault, x2.tcbArch, rfl, by rw [hx2], - Or.inr ⟨Or.inl rfl, rfl, Or.inl ⟨_, _, _, hstd⟩, Or.inr (Or.inr rfl)⟩⟩)) - have IK2 : IK d'.bv σ σ2 := IK1.trans ((IK.um _ σ1 um2).trans (IK.updSelf (σ := Endp.setUm σ1 um2) hkd1 hxsc)) - have SK2 : SKeep σ σ2 := SK1.trans ((SKeep.um σ1 um2).trans (SKeep.updK (σ := Endp.setUm σ1 um2) (p := d'.bv) - (o := .tcb x2) (fun y h => ⟨xd, hkd1, by cases h; exact hxsc.symm⟩) (fun _ _ h => by cases h))) - have hks2 : L.ksb s2 = L.ksb s := hW2.1 - have Fst2 : L.mem s2 (P1.stA d') = L.mem s (P1.stA d') := by - rw [P1.stA_eq] - exact (f2 d' hdH _ (by simp) (by simp) (by simp)).trans (f1 d' hdH _ (by simp) (by simp) (by simp) (by simp)) - have hds2 : L.mem s2 (P1.stA d') = sched.TS_BLOCKED_ON_RECV := Fst2.trans hds - -- the reply object - obtain ⟨r, hrp⟩ := Option.ne_none_iff_exists'.1 (hrepn xd hkd _ _ _ hstd) - subst hrp - obtain ⟨hw0, hwr⟩ := Notif.optRef_some hrep - have hwR := hrepR (by simp) - refine WP.spec_bind (Endp.obj.Tcb.reply_obj.spec s2 d') ?_ - rintro _ rfl - rw [hrw] - have hne0 : (L.mem s (tReplyA d') != 0#u64) = true := by simp [hw0] - simp only [hne0, ↓reduceIte, Bool.false_eq_true, eq_self_iff_true, if_true] - set w := L.mem s (tReplyA d') with hwdef - subst hwr - obtain ⟨xr, hkr, -⟩ := hR.reply w hwR - have hwe : w.bv ≠ e.bv := kheap_ne hkr hk (fun _ h1 h2 => by subst h1; cases h2) - have hwd : w.bv ≠ d'.bv := kheap_ne hkr hkd (fun _ h1 h2 => by subst h1; cases h2) - have hwt : w.bv ≠ t.bv := kheap_ne hkr hkt (fun _ h1 h2 => by subst h1; cases h2) - have hkr2 : σ2.kheap w.bv = some (.reply xr) := by simp [σ2, σ1, hwe, hwd, hkr] - have hb' : xr.replyTcb = some d'.bv := hback_of J.sv hkd e.bv w.bv dd xr (by rw [hstd]) hkr - have hX2' := IpcRel.ofSRN hR2 hS2' - have hrA : L.mem s2 (P1.replyA d') = w := by show L.mem s2 (tReplyA d') = w; rw [hrw] - obtain ⟨hiR, hit⟩ := hX2.2.1.recv d' hdH hds2 (by rw [hrA]; exact hw0) - rw [hrA] at hiR hit - refine WP.spec_bind (WP.spec_and (WP.spec_and (reply_unlink_c hH hP0 hP s2 σ2 hR2 hS2' hdT hkd2 hst2' hwR hkr2 - hb' hq2) (reply_unlink_cn hP0 hX2' hdT hwR hkr2)) - (WP.spec_and (P1.ipc.reply_unlink.inv s2 w d' Q0 R0 h2 hdH hX2.1 hsub hiR hit - (by rw [hds2]; exact P1.blocked_not_runnable (Or.inr (Or.inl rfl))) (Or.inl (Or.inr rfl))) - (P1.ipc.reply_unlink.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s2 w d' h2 hX2 hsub hiR hdH))) ?_ - rintro s3 ⟨⟨⟨e3, hR3, hS3⟩, hW3⟩, ⟨h3, e3', k3, z3⟩, fu3⟩ - have hclr : ∀ r ∈ P1.Heap.replies H, L.mem s2 (P1.rTcbA r) = d' → L.mem s3 (P1.rTcbA r) = 0#u64 := by - intro r hr er - obtain ⟨-, -, b2, -⟩ := hX2.2.1.back r hr (by rw [er]; exact fun e0 => hdta.ne0 (by rw [e0]; rfl)) - rw [er, hrA] at b2; rw [← b2]; exact z3 - set x3 : Fl4Spec.Tcb := { x2 with tcbState := .inactive } with hx3 - set xr3 : Fl4Spec.Reply := { xr with replyTcb := none } with hxr3 - set σ3a := Notif.updK σ2 w.bv (.reply xr3) with hσ3a - have hkd3a : σ3a.kheap d'.bv = some (.tcb (x2)) := by simp [σ3a, Ne.symm hwd, hkd2] - have hct3a : d'.bv ≠ (Notif.updK σ3a d'.bv (.tcb x3)).curThread := hdc - have e3s : Notif.stsAct (Notif.updK σ3a d'.bv (.tcb x3)) d'.bv = Notif.updK σ3a d'.bv (.tcb x3) := - stsAct_ne hct3a - set σ3 := Notif.stsAct (Notif.updK σ3a d'.bv (.tcb x3)) d'.bv with hσ3 - have hU : Fl4Spec.NonDet.maybeM (Fl4Spec.replyUnlinkTcb (Z := Unit) d'.bv) (some w.bv) σ2 = - ({((), σ3)}, False) := e3 - have hW3' : P1.WritesIn st s s3 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW2.trans1 (hW3.mono fun b hb => Or.inl (cnW_back hks2 (SzKeepC.of Fr2.szKeep) hb)) - have hkt3 : σ3.kheap t.bv = some (.tcb xt) := by rw [stsAct_kheap]; simp [σ3a, htd', hwt.symm, hkt2] - have hkd3 : σ3.kheap d'.bv = some (.tcb x3) := by rw [stsAct_kheap]; simp - have hkr3 : σ3.kheap w.bv = some (.reply xr3) := by rw [stsAct_kheap]; simp [σ3a, hwd] - have hq3 : ∀ e'' ∈ Z.E, ∀ z, σ3.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := by - intro e'' he'' z hz - rw [stsAct_kheap] at hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp at hz - have hne' : w.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp [σ3a, hwd] at hz - exact hq2 e'' he'' z (by simpa [σ3a, Ne.symm hne, Ne.symm hne'] using hz) - have Fr3 : CFr e.bv d'.bv σ σ3 := (Fr2.trans (CFr.upd hkr2 (Or.inr (Or.inr (Or.inr ⟨xr, rfl, rfl, hb'⟩))))).trans - (CFr.stsIn hkd3a (Or.inl ⟨_, _, _, hst2'⟩)) - have IK3 : IK d'.bv σ σ3 := by - have IK3a : IK d'.bv σ σ3a := IK2.trans (IK.updOther (o' := .reply xr3) hkr2 (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩)) - have IK3b : IK d'.bv σ (Notif.updK σ3a d'.bv (.tcb x3)) := IK3a.trans (IK.updSelf (y := x3) hkd3a rfl) - exact IK3b.trans (IK.sts _ _ _) - have SK3 : SKeep σ σ3 := - ((SK2.trans (SKeep.updK (p := w.bv) (o := .reply xr3) (fun y h => by cases h) (fun _ _ h => by cases h))).trans - (SKeep.updK (p := d'.bv) (o := .tcb x3) (fun y h => ⟨_, hkd3a, by cases h; rfl⟩) (fun _ _ h => by cases h))).trans - (SKeep.stsAct _ _) - have hct3 : σ3.curThread = σ.curThread := by rw [e3s]; rfl - have hact3 : σ3.schedulerAction = σ.schedulerAction := by rw [e3s]; rfl - have hsc3 : x3.tcbSchedContext = xd.tcbSchedContext := by simp [x3, hxsc] - have hB3 := hB2.keepT h2 k3 (by rw [e3']; exact P1.not_blocked_inactive) (by rw [e3']; exact P1.inactive_ne.1) - have hX3 := hX2.keepT k3 (by rw [e3']; exact P1.inactive_ne) hclr - have hS3' := hS2''.keepT hX2 k3 - have hSg3 : P1.SgOK st (P1.Heap.omega H) (P1.Heap.frame H) s3 := - ⟨hsub, fun b hb => by rw [k3.ksb]; exact hSg2.ks b hb, fun o h1' h2' => by rw [k3.ksb]; exact hSg2.ksΩ o h1' h2'⟩ - have hnr3 : ∀ r ∈ P1.Heap.replies H, L.mem s3 (P1.rTcbA r) ≠ d' := - hX3.noref hdta (by rw [e3']; exact P1.inactive_ne.1) (by rw [e3']; exact P1.inactive_ne.2) - have F3 := footW_trans (footW_trans (footW_of F1) F2) (footW_of fu3) - have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by - have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) - rw [hft] at h00; cases h00 - have hks3 : L.ksb s3 = L.ksb s := hW3'.1 - -- the caller's and the receiver's words at `s3` - have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) - have hnrT : t.bv ∉ σ.releaseQueue := by rw [← hct]; exact hCI.notRel - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hw3 : (L.mem s3 (P1.stA t)).val = tsCode xt.tcbState := by - rw [P1.stA_eq, ← tStA_eq, hxt3.st] - obtain ⟨hnbt3, hnrp3⟩ := P1.run_word (w := L.mem s3 (P1.stA t)) (by rw [hw3]; exact runnable_code hrn) - have hX3' := IpcRel.ofSRN hR3 hS3 - have hSR3 : SchedRel st Z.N Z.T Z.C Z.c s3 σ3 := hX3'.2.2.1 - obtain ⟨Q3, R3', hcq3, hs3⟩ := hSR3.lists - have hSM := ScRelM.of hX3'.1 - have hnqD : NotQueued σ d'.bv := by - refine ⟨fun dm p hm => ?_, fun hm => ?_⟩ - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rq dm p _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rel _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - have hnqT3 : NotQueued σ3 t.bv := ⟨by rw [IK3.2.1]; exact hnq, by rw [IK3.2.2.1]; exact hnrT⟩ - have hnqD3 : NotQueued σ3 d'.bv := ⟨by rw [IK3.2.1]; exact hnqD.1, by rw [IK3.2.2.1]; exact hnqD.2⟩ - have bits3 : ∀ u ∈ Z.T, NotQueued σ3 u.bv → - (L.mem s3 (P1.inqA u) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s3 (P1.inqA u) &&& sched.Q_RELEASE) = 0#u64 := by - intro u hu hnu - refine ⟨Classical.byContradiction fun h => ?_, Classical.byContradiction fun h => ?_⟩ - · have hm := (hcq3.queued u hu).1 h - apply hnu.1 0 (specPrio (L.mem s3 (P1.prioA u))) - rw [hs3.rq _ (hcq3.prio u hu)] - exact List.mem_map_of_mem hm - · have hm := (hcq3.released u hu).1 h - apply hnu.2 - rw [hs3.rel] - exact List.mem_map_of_mem hm - obtain ⟨hqbT, hrbT⟩ := bits3 t ht hnqT3 - obtain ⟨hqbD, hrbD⟩ := bits3 d' hdT hnqD3 - have ha0 : L.actionW s3 = 0#u64 := by - have h := hSR3.act - rw [hact3, hres] at h - unfold P1.LawfulStore.actionW; rw [hcq3.cur]; exact h - have hna3 : ∀ u ∈ Z.T, L.actionW s3 ≠ u := fun u hu h' => by - rw [ha0] at h'; exact (hcq3.tcbs u hu).ne0 (by rw [← h']; rfl) - have hcw3 : L.curW s3 = t := by - have h : (nodeW st s3 Z.c layout.node.CUR_THREAD).bv = t.bv := by rw [← hs3.curThread, hct3, hct] - unfold P1.LawfulStore.curW; rw [hcq3.cur]; exact P1.eq_of_bv h - have hidl3 : σ3.idleThread = σ.idleThread := Fr3.sk.idle - have hiw3 : ∀ u ∈ Z.T, u.bv ≠ σ.idleThread → L.idleW s3 ≠ u := fun u hu hne h' => by - apply hne - rw [← hidl3, hs3.idleTh] - unfold P1.LawfulStore.idleW at h'; rw [hcq3.cur] at h' - exact congrArg _ (show nodeW st s3 Z.c layout.node.IDLE_THREAD = u from h').symm - have hit : t.bv ≠ σ.idleThread := by rw [← hct]; exact hti - have hid : d'.bv ≠ σ.idleThread := by - intro h - obtain ⟨x, hkx, -, hxs, -⟩ := J.act.2 - rw [← h, hkd] at hkx; cases hkx; rw [hstd] at hxs; cases hxs - have hcA : L.mem s3 (P1.scA t) ≠ 0#u64 → L.mem s3 (P1.scA t) ∈ Ac := fun h0 => - hB3.sact t htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw3⟩))))) h0 - have hwH : w ∈ P1.Heap.replies H := hRe ▸ hwR - have hw00 : w ≠ 0#u64 := (J.rp.align w hwR).2.1 - have hqt3 := Endp.not_queued hR3 ht hkt3 hnb - -- the receiver's SC: no donation - have hndF : don = true → x3.tcbSchedContext = none → False := fun hdon hx0 => by - rcases hnd with h | h - · rw [h] at hdon; cases hdon - · exact h xd hkd (by rw [← hsc3]; exact hx0) - obtain ⟨xd3, hkd3', hdsc⟩ := hSM d' hdT - rw [hkd3] at hkd3'; cases hkd3' - have hnd1 : don = false ∨ L.mem s3 (P1.scA d') ≠ 0#u64 := by - cases don - · exact Or.inl rfl - · right; intro h0; exact hndF rfl (by rw [hdsc, h0, optRef_zero]) - -- the push on `IRel`, at P1 - have hw1 : P1.WritesIn st s3 (L.wr s3 (P1.rTcbA w) t) (fun b => b.val = w.val) := by - obtain ⟨-, -, -, hA1⟩ := reply_write_rel (hH.epHyps hP0) hP s3 σ3 hR3 hS3.1 hwR hkr3 t - exact ⟨L.ksb_wr _ _ _, L.cpu_wr _ _ _, fun b hb hn => hA1 b hb hn⟩ - have hns3 : tsCode xt.tcbState ≠ 6 := by have := runnable_code hrn; omega - have hPush : ipc.reply_push st arI s3 a t d' w don ⦃ r => r.2 = a ∧ - Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv don σ3 = ({((), pushSt σ3 t.bv w.bv xr3 xt)}, False) ∧ - EpStateRel Z.T Z.E Z.R Z.B (L.mem r.1) (pushSt σ3 t.bv w.bv xr3 xt) ∧ - SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) r.1 (pushSt σ3 t.bv w.bv xr3 xt) ∧ - P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac r.1 ∧ - (∀ y ∈ P1.Heap.tcbs H, y ≠ t → L.mem r.1 (P1.stA y) = L.mem s3 (P1.stA y)) ∧ - P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s3 r.1 ∧ - sched.set_blocked_on_reply st (L.wr s3 (P1.rTcbA w) t) t w = ok r.1 ⦄ := by - refine WP.spec_mono (WP.spec_and (WP.spec_and - (reply_push_iC (don := don) (P := fun s' σ' => σ' = pushSt σ3 t.bv w.bv xr3 xt ∧ - EpStateRel Z.T Z.E Z.R Z.B (L.mem s') σ' ∧ - SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) s' σ') - hH hP0 hP s3 a σ3 hR3 hS3 ht hkt3 hkd3 hqt3 hns3 hwR hkr3 (fun _ => hdT) - (fun s' h1 h2 => ⟨rfl, h1, h2⟩) (fun hdon _ _ _ _ _ _ _ hx0 => (hndF hdon hx0).elim)) - (P1.ipc.reply_push.ipc hAT s3 a t d' w don Q0 R0 h3 (fun y hy => by - obtain ⟨hy1, hy2⟩ := hy - rcases hy1 with hy1 | hy1 - · exact absurd hy1 (Set.notMem_empty _) - · exact absurd hy1 hy2) (Or.inr hnbt3) hB3 hX3 hS3' hSg3 htH hqbT hrbT - (hna3 t ht) (hiw3 t ht hit) ⟨hnrp3, fun e0 => hnbt3 (Or.inr (Or.inl e0))⟩ hwH hw00 z3 (J.zH.1 d' hdT) - (Ne.symm htd) hqbD hrbD (hna3 d' hdT) (hiw3 d' hdT hid) hcA)) - (P1.ipc.reply_push.nd (Es := P1.EH H) s3 a t d' w don h3 (fun y hy => by - obtain ⟨hy1, hy2⟩ := hy - rcases hy1 with hy1 | hy1 - · exact absurd hy1 (Set.notMem_empty _) - · exact absurd hy1 hy2) (Or.inr hnbt3) hB3 hX3 hS3' hSg3 htH hqbT hrbT - (hna3 t ht) (hiw3 t ht hit) ⟨hnrp3, fun e0 => hnbt3 (Or.inr (Or.inl e0))⟩ hwH hw00 z3 (J.zH.1 d' hdT) - (Ne.symm htd) hcA hnd1)) ?_ - rintro ⟨s4, a4⟩ ⟨⟨⟨ha, σ', hm, e4, hR4, hS4⟩, hb1, hb2, -⟩, -, hf, hsb⟩ - subst e4 - exact ⟨ha, hm, hR4, hS4, hb1, hb2, hf, hsb⟩ - refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ - Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv don σ3 = ({((), pushSt σ3 t.bv w.bv xr3 xt)}, False) ∧ - EpStateRel Z.T Z.E Z.R Z.B (L.mem r.1) (pushSt σ3 t.bv w.bv xr3 xt) ∧ - SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) r.1 (pushSt σ3 t.bv w.bv xr3 xt) ∧ - P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac r.1 ∧ - (∀ y ∈ P1.Heap.tcbs H, y ≠ t → L.mem r.1 (P1.stA y) = L.mem s3 (P1.stA y)) ∧ - P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s3 r.1 ∧ - sched.set_blocked_on_reply st (L.wr s3 (P1.rTcbA w) t) t w = ok r.1) ?_ ?_ - · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ - rintro i1 rfl - rw [if_pos (bne_iff_ne.2 hty3)] - rcases hg with rfl | rfl - · simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true]; exact hPush - · cases g <;> simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true] <;> exact hPush - rintro ⟨s4, a4⟩ ⟨ha4, hpush, hR4, hS4, ⟨⟨Q4, R4, h4⟩, hB4, hX4, hS4', hSg4⟩, hst4, fu4, hsb4⟩ - simp only at ha4 hpush hR4 hS4 h4 hB4 hX4 hS4' hSg4 hst4 fu4 hsb4 ⊢ - subst ha4 - try dsimp only - have hW4 : P1.WritesIn st s3 s4 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s3 σ3) := by - have h := set_blocked_on_reply_cn (N := Z.N) (C := Z.C) (E := Z.E) hP hSR3 ht hwR hw1 - rw [hsb4, WP.spec_ok] at h; exact h - have hW4' : P1.WritesIn st s s4 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW3'.trans1 (hW4.mono fun b hb => Or.inl (cnW_back hks3 (SzKeepC.of Fr3.szKeep) hb)) - have hks4 : L.ksb s4 = L.ksb s := hW4'.1 - set σ4 := pushSt σ3 t.bv w.bv xr3 xt with hσ4 - have hkd4 : σ4.kheap d'.bv = some (.tcb x3) := by rw [ps_ko (Ne.symm htd') (Ne.symm hwd)]; exact hkd3 - have hq4 : ∀ e'' ∈ Z.E, ∀ z, σ4.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := - fun e'' he'' z hz => hq3 e'' he'' z ((ps_oth hkt3 hkr3 hwt (fun _ h => by cases h) (fun _ h => by cases h)).1 hz) - have hdH : d' ∈ P1.Heap.tcbs H := J.zH.1 d' hdT - have hst4d : L.mem s4 (P1.stA d') = sched.TS_INACTIVE := by rw [hst4 d' hdH (Ne.symm htd)]; exact e3' - have hx4 : d' ∈ (∅ : Set U64) ∨ ¬ P1.Blocked (L.mem s4 (P1.stA d')) := Or.inr (by rw [hst4d]; exact P1.not_blocked_inactive) - have hnr4 : ∀ r ∈ P1.Heap.replies H, L.mem s4 (P1.rTcbA r) ≠ d' := - hX4.noref hdta (by rw [hst4d]; exact P1.inactive_ne.1) (by rw [hst4d]; exact P1.inactive_ne.2) - -- the receiver runs - refine WP.spec_bind (WP.spec_and (WP.spec_and (set_thread_state_c hH hP0 hP s4 _ hR4 hS4 hdT hkd4 hq4 - (by simp [x3, tsCode]) .running (by simp [tsCode]) sched.TS_RUNNING (by unfold sched.TS_RUNNING; rfl)) - (set_thread_state_sfoot (IpcRel.ofSRN hR4 hS4).2.2.1 hdT sched.TS_RUNNING)) - (WP.spec_and (P1.sts_all s4 d' _ Q4 R4 h4 hB4 hX4 hS4' hSg4 hdH P1.not_blocked_running P1.running_ne hx4 hnr4 - ⟨fun _ _ _ _ _ => P1.runnable_running, fun _ _ _ => P1.runnable_running, fun _ => P1.runnable_running⟩) - (P1.sched.set_thread_state.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s4 d' sched.TS_RUNNING h4 hdH))) ?_ - rintro s5 ⟨⟨⟨hR5, hS5⟩, hW5⟩, ⟨h5, hB5, hX5, hS5', hSg5, -, -⟩, fu5⟩ - set x5 : Fl4Spec.Tcb := { x3 with tcbState := .running } with hx5 - set σa := Notif.stsAct (Notif.updK σ3 d'.bv (.tcb x5)) d'.bv with hσa - have hdc3 : d'.bv ≠ σ3.curThread := by rw [hct3]; exact hdc - have heq5 : Notif.stsAct (Notif.updK σ4 d'.bv (.tcb x5)) d'.bv = pushSt σa t.bv w.bv xr3 xt := - ps_swap htd' hwd hdc3 - have hIR0 := IpcRel.ofSRN hR5 hS5 - have hIR : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s5 (pushSt σa t.bv w.bv xr3 xt) := by - rw [← heq5]; exact hIR0 - have hW5' : P1.WritesIn st s s5 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW4'.trans1 (hW5.mono fun b hb => Or.inl (Or.inl (Or.inl (KFoot.of_sfoot ((SFoot.ksb hks4).1 hb))))) - have hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s5 := - ⟨⟨Q4, R4, h5.congrX P1.empty_congr⟩, hB5, hX5, hS5', hSg5⟩ - have hfoot := footW_trans (footW_trans F3 (footW_of fu4)) (footW_of fu5) - have hrb3 : RbIn x3.tcbState := Or.inr rfl - have Fr5 : CFr e.bv d'.bv σ σa := Fr3.trans (CFr.stsRun hkd3 hrb3) - have IK5a : IK d'.bv σ (Notif.updK σ3 d'.bv (.tcb x5)) := IK3.trans (IK.updSelf (y := x5) hkd3 rfl) - have IK5 : IK d'.bv σ σa := IK5a.trans (IK.sts _ _ _) - have SK5 : SKeep σ σa := (SK3.trans (SKeep.updK (p := d'.bv) (o := .tcb x5) (fun y h => ⟨x3, hkd3, by cases h; rfl⟩) - (fun _ _ h => by cases h))).trans (SKeep.stsAct _ _) - have hrib : RelIfBound σa d'.bv := - Ipc.RelIfBound.of_keep (J.inv.rd d'.bv xd hkd (Or.inr (Or.inr (Or.inr ⟨_, _, _, hstd⟩)))) SK5 - have I5 : Inv σa := ((J.inv.toBut d'.bv).ik hnqD IK5).1.inv fun _ _ _ => hrib - have act5 : σa.schedulerAction = σ.schedulerAction := by - rw [hσa, stsAct_ne (by show d'.bv ≠ σ3.curThread; exact hdc3)]; exact hact3 - -- the push after the wake (`ps_swap`) - have hkta : σa.kheap t.bv = some (.tcb xt) := by rw [hσa, stsAct_kheap]; simp [Notif.updK, htd', hkt3] - have hkwa : σa.kheap w.bv = some (.reply xr3) := by rw [hσa, stsAct_kheap]; simp [Notif.updK, hwd, hkr3] - have hnqT : ∀ dm p, t.bv ∉ σa.readyQueues dm p := by rw [IK5.2.1]; exact hnq - have hnrT' : t.bv ∉ σa.releaseQueue := by rw [IK5.2.2.1]; exact hnrT - set σ' := pushSt σa t.bv w.bv xr3 xt with hσ' - have I5' : Inv σ' := ps_inv hkta hkwa hwt I5 hnqT hnrT' - -- an SC bound to the caller is the current SC, active - have hscA : ∀ p y n, σa.kheap p = some (.schedContext y n) → y.scTcb = some t.bv → - Fl4Spec.scActive y = true := by - intro p y n hp hyt - have hp0 : σ.kheap p = some (.schedContext y n) := SK5.2.2.2 _ _ _ hp - obtain ⟨q, hqC, eq⟩ := J.obj.sc p y n hp0 - subst eq - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hq0 := J.c0 q hqC - have hqS : q ∈ P1.Heap.scs H := ⟨_, (hJ.sc q y n hq0 hp0).2⟩ - have hS := J.xtop.fin.1.1.1 - obtain ⟨u, -, -, xu, hku, hxs⟩ := scBack_of hS J.blk.2.2.1 J.tcbs_eq.1.symm hqC hqS hq0 hp0 hyt - rw [hkt] at hku; cases hku - obtain ⟨xc, hkc, hcs, -⟩ := hCI.tcb - rw [hct, hkt] at hkc; cases hkc - have e1 : σ.curSc = q.bv := Option.some.inj (hcs.symm.trans hxs) - rw [← e1] at hp0 - exact hCI.active (J.curSc_ne_idle hCI hti) y n hp0 - have B5' : BlockedScActive σ' := ps_bsa hkta hkwa hwt hscA (Fr5.bsa J.bsa) - have hcn : σ'.schedulerAction = .chooseNewThread := - ps_act (by rw [Fr5.sk.ct, hct]) (by rw [act5, hres]) - have hidT : σa.idleThread ≠ t.bv := by rw [Fr5.sk.idle, ← hct]; exact fun e0 => hti e0.symm - have hAI5 : ActIdle σ' := - ⟨fun u hu => (by rw [hcn] at hu; cases hu), ps_idleOK hkta hkwa hwt hidT (Fr5.idleOK J.act.2)⟩ - have hrun5 : CurRunM σ' := Or.inl (by rw [hcn]; intro h; cases h) - have htD := J.not_dead_of_st hdT hkd (by rw [hstd]; simp [tsCode]) - have hcD : ∀ q ∈ D, q.bv ≠ t.bv := J.notDead ht hkt (by have := runnable_code hrn; omega) - have hwD : ∀ q0 ∈ D, q0.bv ≠ w.bv := fun q0 hq0 e0 => by - have hqw : q0 = w := P1.eq_of_bv e0 - rw [hqw] at hq0 - have d1 : L.mem s (Endp.rTcbA w) = 0#u64 := (J.jcov.dead w hq0).2.2.2.1 hwH - obtain ⟨xr', hkr', hxr'⟩ := hR.reply w hwR - rw [hkr] at hkr'; cases hkr' - rw [hb', d1, optRef_zero] at hxr' - cases hxr' - have hkq : ∀ q ∈ D, σ'.kheap q.bv = σa.kheap q.bv := fun q hq => ps_ko (hcD q hq) (hwD q hq) - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot - have hIu := Ju.xtop.irelK Ju.ks Ju.buf - have hRR : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → - Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' - hxt' hkd (by rw [hstd]; rfl) - have hF : IFrame (L := L) Z.th su s5 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb - have ho : ∀ {q : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject}, (∀ x, o ≠ .tcb x) → (∀ x, o ≠ .reply x) → - (σ'.kheap q = some o ↔ σa.kheap q = some o) := fun h1 h2 => ps_oth hkta hkwa hwt h1 h2 - obtain ⟨V', J5⟩ := Ju.wake_postGR hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) ps_skD - (ps_ksub hkta hkwa hwt) (ps_szKeep hkta hkwa hwt) (ps_ykeep hkta hkwa hwt) (ps_mcpKeep hkta hkwa hwt) - (ps_bufKeep hkta hkwa hwt) (fun d _ h => ps_recvB hkta hkwa hwt h) (ps_ksz hkta hkwa hwt) - (ps_kback hkta hkwa hwt) (ps_ipcFr hkta hkwa hwt) (ps_ck hkta hkwa hwt) (fun d _ h => ps_free hkta hkwa hwt h) - (fun q ao h => (ho (fun _ e => by cases e) (fun _ e => by cases e)).2 h) hkq - I5' B5' hAI5 (Or.inl hcn) hrun5 (ps_own hkta hkwa hwt ((DWFr.ofCFr Fr5).own ⟨d', hdT, rfl⟩ J.own)) - (ps_off hkta hkwa hwt ((DWFr.ofCFr Fr5).off J.off)) (ps_nsc hkta hkwa hwt ((DWFr.ofCFr Fr5).nsc J.nsc)) - (ps_isorted hkta hkwa hwt ((DWFr.ofCFr Fr5).isorted J.isorted)) hRR htD - -- the tail - have hk5 : σ'.kheap d'.bv = some (.tcb x5) := by - rw [ps_ko (Ne.symm htd') (Ne.symm hwd), hσa, stsAct_kheap]; simp - have hnr5 : d'.bv ∉ σ'.releaseQueue := by rw [ps_rel, SK5.1]; exact hnqD.2 - have hact5 : ∀ p y n, x5.tcbSchedContext = some p → σ'.kheap p = some (.schedContext y n) → - Fl4Spec.scActive y = true := by - intro p y n hp hy - have hya : σa.kheap p = some (.schedContext y n) := - (ho (fun _ h => by cases h) (fun _ h => by cases h)).1 hy - have hy0 := SK5.2.2.2 p y n hya - have hp' : xd.tcbSchedContext = some p := by rw [← hsc3]; exact hp - obtain ⟨y', n', hky', hyt⟩ := J.inv.back _ _ _ hkd hp' - rw [hy0] at hky'; cases hky' - exact J.bsa.tcb p y n d'.bv xd hy0 hyt hkd (by rw [hstd]; rfl) - have hti5 : d'.bv ≠ σ'.idleThread := by - rw [(ps_skD (σ := σa) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).idle, Fr5.sk.idle] - exact hid - have htc5 : d'.bv ≠ σ'.curThread := by - rw [(ps_skD (σ := σa) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).ct, Fr5.sk.ct]; exact hdc - have hspec := sendIpc_faultPush_eq (don := don) hk hkd hde hstd blk badge.bv g gr hg e2 hU hkt3 hkd3 hpush hkd4 (by rw [hft]; simp) - (t := t.bv) - have hspec' : Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ = - Endp.specWakeTailE d'.bv σ' := by - rw [hspec]; exact congrArg _ heq5 - refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ - simp only at ha7 - subst ha7 - exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.sendFaultPJG hAT ht hkt hrn hft hnt hct hres hti hnq he hk blk badge g gr don hg hrepn hnd) fun _ ⟨z, hz, h⟩ => ⟨z, hz, JAtN.toJAt J h⟩ -set_option maxHeartbeats 64000000 in -/-- **A call to a waiting receiver at `J` that pushes a reply and donates -the caller's SC** (module docstring): the caller has the grant or grant-reply -right (`hg`), the receiver a reply object (`hrepn`) and no SC (`hxdn`), the -call donates; as `JAtZ.sendCallPJ` up to the reply unlink, then `reply_push` -(`reply_push_iC`): the link and block on `IRel` and P1 (`set_blocked_on_reply`), -`JAtZ` there by `JAtZ.wake_postGR` at `pushSt`, the donation by -XTopJointPushDon's `JAtZ.pushDonJ`; the receiver `Running` by XTopJointStsI's -`JAtZ.stsIJ` (released: the caller's SC, `Inv.rd`), the tail -`JAtZ.sendTailJ`; the spec's outcome `sendIpc_call_eq` with -`replyPush_don_eq`/`pd_eq`. -/ theorem JAtZ.sendFaultPDJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) (hrn : Fl4Spec.runnable xt.tcbState = true) {fq : Fl4Spec.Fault} @@ -1590,562 +83,9 @@ theorem JAtZ.sendFaultPDJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z (hxdn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext = none) : endpoint.send_ipc st arI s a blk false badge g gr true t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr true t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - have hI := J.xtop.irelK J.ks J.buf - have hP0 := J.ip - have hP := hP0.e - have hH := ipcCore_top (st := st) (th := Z.th) (cr := σ.archState.x64CurrentCr3) (N := Z.N) (C := Z.C) - (c := Z.c) hP - have hR := hI.1.toE - have hS0 := IpcRel.toSRN hI.1 hI.2 - have hTe : Z.T = P1.Heap.tcbs H := J.tcbs_eq.1 - have hRe : Z.R = P1.Heap.replies H := J.tcbs_eq.2 - have hx := hR.at_ep he hk - have hxt := hR.at_tcb ht hkt - obtain ⟨hst2, xs, hxs0, hq, hQ, hB⟩ := hx - obtain ⟨d', xs', rfl⟩ := List.exists_cons_of_ne_nil hxs0 - simp only [List.map_cons, List.cons.injEq] at hq - obtain ⟨hd', hq'⟩ := hq - have hdd : d' = d := eq_of_bv hd'.symm - subst hdd - have hdT : d' ∈ Z.T := hQ.mem d' (by simp) - have hda := hP.tcb d' hdT - obtain ⟨xd, hkd, -⟩ := hI.1.tcb d' hdT - have hxd := hR.at_tcb hdT hkd - have hd3 : (L.mem s (tStA d')).val = 3 := (hB d' (by simp)).1 - have hdb : L.mem s (tBlockA d') = e := (hB d' (by simp)).2 - obtain ⟨e', rep, dd, hstd⟩ := tsCode_three (hxd.st.symm.trans hd3) - have he' : e' = e.bv := by - have := hxd.blk e' (by rw [hstd]; rfl); rw [hdb] at this; exact this.symm - subst he' - obtain ⟨hrep, hrepR⟩ := hxd.recv _ _ _ hstd - have hnb : tsCode xt.tcbState ≠ 3 ∧ tsCode xt.tcbState ≠ 4 := by have := runnable_code hrn; omega - have htd : t ≠ d' := by intro h; subst h; exact hnb.1 (hxt.st.symm.trans hd3) - have hde : d'.bv ≠ e.bv := kheap_ne hkd hk (fun _ h1 h2 => by subst h1; cases h2) - have hte : t.bv ≠ e.bv := kheap_ne hkt hk (fun _ h1 h2 => by subst h1; cases h2) - have htd' : t.bv ≠ d'.bv := bv_ne htd - have hdc : d'.bv ≠ σ.curThread := by rw [hct]; exact Ne.symm htd' - -- P1's facts at the start - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hSc0, hSg0⟩ := J.blk - have hdH : d' ∈ P1.Heap.tcbs H := J.zH.1 d' hdT - have hHe : H e = some .ep := J.zH.2.1 e he - have hTP : P1.TcbPlaced (P1.Heap.tcbs H) := h0.tcbs - have hdta := hTP d' hdH - have hsub := hSg0.sub - have hds : L.mem s (P1.stA d') = sched.TS_BLOCKED_ON_RECV := by - rw [stA_tStA, tsVals.2.2.1]; exact UScalar.eq_of_val_eq hd3 - have hbe : L.mem s (P1.blockA d') = e := by rw [P1.blockA_eq, ← tBlockA_eq]; exact hdb - have hdq := P1.endpoint.ep_dequeue.inv s d' Q0 R0 h0 hdH (by simp) (Or.inr (Or.inl hds)) - rw [hbe] at hdq - obtain ⟨E0, EQ0, hEW0⟩ := h0.eps - have heE0 : e ∈ E0 := (hEW0.2.2.2.2.2.2.2.1 e).2 (Or.inl hHe) - obtain ⟨hE0, -, hq0'⟩ := hEW0.1 e heE0 - have hdm : d' ∈ EQ0 e := by - have := hEW0.2.2.2.2.1 d' hdH (by simp) (Or.inr (Or.inl hds)); rw [hbe] at this; exact this.2 - have pf := P1.endpoint.ep_dequeue.foot s e d' (EQ0 e) hTP hE0 hq0' hdm - -- FL4: the endpoint's state and queue - unfold endpoint.send_ipc - refine WP.spec_bind (Fl4Proofs.P1.obj.Ep.state.spec s e) ?_ - rintro _ rfl - rw [epState_eq, hst2] - rw [if_neg (by rw [ep_state_vals.1]; decide), if_neg (by rw [ep_state_vals.2.1]; decide)] - refine WP.spec_bind (Fl4Proofs.P1.endpoint.get_queue.spec s e) ?_ - rintro _ rfl - have hhead : (L.epQ s e).head = d' := by rw [epQ_eq]; exact hQ.head - rw [hhead] - -- the dequeue - refine WP.spec_bind (WP.spec_and (WP.spec_and (ep_dequeue_c hH hP0 hP s σ hR hS0 he hk (d := d') - (by simp [Fl4Spec.Endpoint.epQueue])) (ep_dequeue_full hP s he d' _ hQ (by simp))) - (WP.spec_and hdq pf)) ?_ - rintro s1 ⟨⟨⟨-, hR1, hS1, hA1⟩, -, -, hQA, hWE, -, -⟩, ⟨h1, f1, o1, n1, k1, c1, nc1⟩, w1⟩ - set σ1 := Notif.updK σ e.bv (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) with hσ1 - have hW1a : P1.WritesIn st s s1 (fun b => EW e b ∨ ∃ w ∈ (d' :: xs'), TL w b) := - ⟨hWE.1, hWE.2.1, fun b hb hn => hQA b hb ⟨fun h => hn (Or.inl h), fun h => hn (Or.inr h)⟩⟩ - have hW1 : P1.WritesIn st s s1 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hW1a.mono fun b hb => by - rcases hb with h | ⟨w, hw, h | h⟩ - · exact Or.inr (Or.inl ⟨e, he, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3496, by omega, by omega, by omega, by omega, by omega, h⟩) - · exact Or.inl (Or.inr ⟨w, hQ.mem w hw, 3504, by omega, by omega, by omega, by omega, by omega, h⟩) - have F1 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s s1 := - P1.Foot.of w1 fun b hb => hb.kw hq0'.mem (Or.inl hHe) - obtain ⟨hB1, hX1, hS1', hSg1, -, -, -⟩ := P1.frame_bx h0 hB0 hX0 hSc0 hSg0 f1 o1 n1 k1 - (P1.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 _ (hSg0.sub _ (hX0.1.ntB n' hn').2)⟩) - have hkt1 : σ1.kheap t.bv = some (.tcb xt) := by simp [σ1, hte, hkt] - have hkd1 : σ1.kheap d'.bv = some (.tcb xd) := by simp [σ1, hde, hkd] - have hk1e : σ1.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by simp [σ1] - have hdb1 : L.mem s1 (tBlockA d') = e := by - rw [hA1 _ (a_blk hda).1 ⟨d', hdT, (a_blk hda).2⟩, hdb] - have hq1 := dequeued_not_queued hR1 he hdb1 hk1e (epDeq_not_mem _) - have Fr1 : CFr e.bv d'.bv σ σ1 := CFr.upd hk (Or.inr (Or.inr (Or.inl ⟨_, _, rfl, rfl, - by rw [epDeq_queue']; unfold Fl4Spec.removeAll; exact List.filter_sublist, - by simp [Fl4Spec.Endpoint.epQueue]⟩))) - have IK1 : IK d'.bv σ σ1 := IK.updOther (o' := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) hk (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩) - have SK1 : SKeep σ σ1 := SKeep.updK (p := e.bv) (o := .endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) (fun y h => by cases h) (fun _ _ h => by cases h) - have hOK1 : Endp.IpcBufCapOK σ1 := ipcBufCapOK_epStep (J.xferH).1 (EpStep.ep hk) - -- the transfer - have hdth : Z.th d' = some .tcb := by - obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 - exact Ipc.RelTopB.tcbT hB0' hkd - have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g - hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ - rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ - set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 - have hkd2 : σ2.kheap d'.bv = some (.tcb x2) := by simp [σ2] - have hkt2 : σ2.kheap t.bv = some (.tcb xt) := by simp [σ2, htd', hkt1] - have hst2' : x2.tcbState = .blockedOnReceive e.bv rep dd := by rw [hx2]; exact hstd - have hxsc : x2.tcbSchedContext = xd.tcbSchedContext := by rw [hx2] - have hN2 := ntfn_lift_rcv hP0.toC hS1.2 hR2 hdT hA2 (fun p hp => by simp [σ2, hp]) - hkd1 hkd2 (by rw [hx2]) - have hS2' : SRN st Z.N Z.T (SRS st Z.T (SRT st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c - (SRE st Z.N Z.T Z.C Z.E Z.R Z.B Z.c))) s2 σ2 := ⟨hS2.1, hN2⟩ - have hk1e2 : σ2.kheap e.bv = some (.endpoint (epDeq (.recvEP (d'.bv :: q)) d'.bv)) := by - simp [σ2, Ne.symm hde, hk1e] - have hq2 : ∀ e'' ∈ Z.E, ∀ z, σ2.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := by - intro e'' he'' z hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h, hkd2] at hz; cases hz - exact hq1 e'' he'' z (by simpa [σ2, Ne.symm hne] using hz) - have hrw : L.mem s2 (tReplyA d') = L.mem s (tReplyA d') := by - rw [hA2 _ (a_reply hda).1 ⟨?_, ?_⟩, hA1 _ (a_reply hda).1 ⟨d', hdT, (a_reply hda).2⟩] - · rintro ⟨r', hr'⟩ - rw [val_reply hda, regA_val hda (regIdx_lt r')] at hr'; have := regIdx_lt r'; omega - · rintro ⟨wp, hwp, e'⟩ - have h1' := hP.bt wp hwp d' hdT - have h2' := val_reply hda - rw [← e'] at h1'; omega - have hW2 : P1.WritesIn st s s2 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - (hW1.mono fun b hb => Or.inl hb).trans1 (w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', -, eb⟩ | hb) | hb - · have hyT : y ∈ Z.T := by rw [hTe]; exact hy - refine Or.inl (Or.inl (Or.inr ⟨y, hyT, K.val, h1', by omega, by omega, by omega, by omega, ?_⟩)) - rw [eb]; exact tfield_val (hP.tcb y hyT) (by omega) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb) - have F2 : P1.WritesIn st s1 s2 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) (P1.EH H) s1 b ∨ RcvBufW xd b) := - w2.mono fun b hb => by - rcases hb with (⟨y, hy, K, h1', h2', h3', eb⟩ | hb) | hb - · exact Or.inl (Or.inl ⟨y, hy, K, by omega, by omega, by omega, by omega, eb⟩) - · exact absurd hb (Set.notMem_empty _) - · exact Or.inr hb - have Fr2 : CFr e.bv d'.bv σ σ2 := (Fr1.trans (CFr.um _ _ σ1 um2)).trans (CFr.upd (σ := Endp.setUm σ1 um2) hkd1 - (Or.inl ⟨xd, xd.tcbState, xd.tcbBoundNotification, xd.tcbFault, x2.tcbArch, rfl, by rw [hx2], - Or.inr ⟨Or.inl rfl, rfl, Or.inl ⟨_, _, _, hstd⟩, Or.inr (Or.inr rfl)⟩⟩)) - have IK2 : IK d'.bv σ σ2 := IK1.trans ((IK.um _ σ1 um2).trans (IK.updSelf (σ := Endp.setUm σ1 um2) hkd1 hxsc)) - have SK2 : SKeep σ σ2 := SK1.trans ((SKeep.um σ1 um2).trans (SKeep.updK (σ := Endp.setUm σ1 um2) (p := d'.bv) - (o := .tcb x2) (fun y h => ⟨xd, hkd1, by cases h; exact hxsc.symm⟩) (fun _ _ h => by cases h))) - have hks2 : L.ksb s2 = L.ksb s := hW2.1 - have Fst2 : L.mem s2 (P1.stA d') = L.mem s (P1.stA d') := by - rw [P1.stA_eq] - exact (f2 d' hdH _ (by simp) (by simp) (by simp)).trans (f1 d' hdH _ (by simp) (by simp) (by simp) (by simp)) - have hds2 : L.mem s2 (P1.stA d') = sched.TS_BLOCKED_ON_RECV := Fst2.trans hds - -- the reply object - obtain ⟨r, hrp⟩ := Option.ne_none_iff_exists'.1 (hrepn xd hkd _ _ _ hstd) - subst hrp - obtain ⟨hw0, hwr⟩ := Notif.optRef_some hrep - have hwR := hrepR (by simp) - refine WP.spec_bind (Endp.obj.Tcb.reply_obj.spec s2 d') ?_ - rintro _ rfl - rw [hrw] - have hne0 : (L.mem s (tReplyA d') != 0#u64) = true := by simp [hw0] - simp only [hne0, ↓reduceIte, Bool.false_eq_true, eq_self_iff_true, if_true] - set w := L.mem s (tReplyA d') with hwdef - subst hwr - obtain ⟨xr, hkr, -⟩ := hR.reply w hwR - have hwe : w.bv ≠ e.bv := kheap_ne hkr hk (fun _ h1 h2 => by subst h1; cases h2) - have hwd : w.bv ≠ d'.bv := kheap_ne hkr hkd (fun _ h1 h2 => by subst h1; cases h2) - have hwt : w.bv ≠ t.bv := kheap_ne hkr hkt (fun _ h1 h2 => by subst h1; cases h2) - have hkr2 : σ2.kheap w.bv = some (.reply xr) := by simp [σ2, σ1, hwe, hwd, hkr] - have hb' : xr.replyTcb = some d'.bv := hback_of J.sv hkd e.bv w.bv dd xr (by rw [hstd]) hkr - have hX2' := IpcRel.ofSRN hR2 hS2' - have hrA : L.mem s2 (P1.replyA d') = w := by show L.mem s2 (tReplyA d') = w; rw [hrw] - obtain ⟨hiR, hit⟩ := hX2.2.1.recv d' hdH hds2 (by rw [hrA]; exact hw0) - rw [hrA] at hiR hit - refine WP.spec_bind (WP.spec_and (WP.spec_and (reply_unlink_c hH hP0 hP s2 σ2 hR2 hS2' hdT hkd2 hst2' hwR hkr2 - hb' hq2) (reply_unlink_cn hP0 hX2' hdT hwR hkr2)) - (WP.spec_and (P1.ipc.reply_unlink.inv s2 w d' Q0 R0 h2 hdH hX2.1 hsub hiR hit - (by rw [hds2]; exact P1.blocked_not_runnable (Or.inr (Or.inl rfl))) (Or.inl (Or.inr rfl))) - (P1.ipc.reply_unlink.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := P1.EH H) s2 w d' h2 hX2 hsub hiR hdH))) ?_ - rintro s3 ⟨⟨⟨e3, hR3, hS3⟩, hW3⟩, ⟨h3, e3', k3, z3⟩, fu3⟩ - have hclr : ∀ r ∈ P1.Heap.replies H, L.mem s2 (P1.rTcbA r) = d' → L.mem s3 (P1.rTcbA r) = 0#u64 := by - intro r hr er - obtain ⟨-, -, b2, -⟩ := hX2.2.1.back r hr (by rw [er]; exact fun e0 => hdta.ne0 (by rw [e0]; rfl)) - rw [er, hrA] at b2; rw [← b2]; exact z3 - set x3 : Fl4Spec.Tcb := { x2 with tcbState := .inactive } with hx3 - set xr3 : Fl4Spec.Reply := { xr with replyTcb := none } with hxr3 - set σ3a := Notif.updK σ2 w.bv (.reply xr3) with hσ3a - have hkd3a : σ3a.kheap d'.bv = some (.tcb (x2)) := by simp [σ3a, Ne.symm hwd, hkd2] - have hct3a : d'.bv ≠ (Notif.updK σ3a d'.bv (.tcb x3)).curThread := hdc - have e3s : Notif.stsAct (Notif.updK σ3a d'.bv (.tcb x3)) d'.bv = Notif.updK σ3a d'.bv (.tcb x3) := - stsAct_ne hct3a - set σ3 := Notif.stsAct (Notif.updK σ3a d'.bv (.tcb x3)) d'.bv with hσ3 - have hU : Fl4Spec.NonDet.maybeM (Fl4Spec.replyUnlinkTcb (Z := Unit) d'.bv) (some w.bv) σ2 = - ({((), σ3)}, False) := e3 - have hW3' : P1.WritesIn st s s3 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW2.trans1 (hW3.mono fun b hb => Or.inl (cnW_back hks2 (SzKeepC.of Fr2.szKeep) hb)) - have hkt3 : σ3.kheap t.bv = some (.tcb xt) := by rw [stsAct_kheap]; simp [σ3a, htd', hwt.symm, hkt2] - have hkd3 : σ3.kheap d'.bv = some (.tcb x3) := by rw [stsAct_kheap]; simp - have hkr3 : σ3.kheap w.bv = some (.reply xr3) := by rw [stsAct_kheap]; simp [σ3a, hwd] - have hq3 : ∀ e'' ∈ Z.E, ∀ z, σ3.kheap e''.bv = some (.endpoint z) → d'.bv ∉ z.epQueue := by - intro e'' he'' z hz - rw [stsAct_kheap] at hz - have hne : d'.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp at hz - have hne' : w.bv ≠ e''.bv := by intro h; rw [← h] at hz; simp [σ3a, hwd] at hz - exact hq2 e'' he'' z (by simpa [σ3a, Ne.symm hne, Ne.symm hne'] using hz) - have Fr3 : CFr e.bv d'.bv σ σ3 := (Fr2.trans (CFr.upd hkr2 (Or.inr (Or.inr (Or.inr ⟨xr, rfl, rfl, hb'⟩))))).trans - (CFr.stsIn hkd3a (Or.inl ⟨_, _, _, hst2'⟩)) - have IK3 : IK d'.bv σ σ3 := by - have IK3a : IK d'.bv σ σ3a := IK2.trans (IK.updOther (o' := .reply xr3) hkr2 (fun o0 h => by - rcases h with rfl | rfl <;> exact ⟨fun _ h => (by cases h), fun _ _ h => (by cases h), fun _ h => (by cases h)⟩)) - have IK3b : IK d'.bv σ (Notif.updK σ3a d'.bv (.tcb x3)) := IK3a.trans (IK.updSelf (y := x3) hkd3a rfl) - exact IK3b.trans (IK.sts _ _ _) - have SK3 : SKeep σ σ3 := - ((SK2.trans (SKeep.updK (p := w.bv) (o := .reply xr3) (fun y h => by cases h) (fun _ _ h => by cases h))).trans - (SKeep.updK (p := d'.bv) (o := .tcb x3) (fun y h => ⟨_, hkd3a, by cases h; rfl⟩) (fun _ _ h => by cases h))).trans - (SKeep.stsAct _ _) - have hct3 : σ3.curThread = σ.curThread := by rw [e3s]; rfl - have hact3 : σ3.schedulerAction = σ.schedulerAction := by rw [e3s]; rfl - have hsc3 : x3.tcbSchedContext = xd.tcbSchedContext := by simp [x3, hxsc] - have hB3 := hB2.keepT h2 k3 (by rw [e3']; exact P1.not_blocked_inactive) (by rw [e3']; exact P1.inactive_ne.1) - have hX3 := hX2.keepT k3 (by rw [e3']; exact P1.inactive_ne) hclr - have hS3' := hS2''.keepT hX2 k3 - have hSg3 : P1.SgOK st (P1.Heap.omega H) (P1.Heap.frame H) s3 := - ⟨hsub, fun b hb => by rw [k3.ksb]; exact hSg2.ks b hb, fun o h1' h2' => by rw [k3.ksb]; exact hSg2.ksΩ o h1' h2'⟩ - have hnr3 : ∀ r ∈ P1.Heap.replies H, L.mem s3 (P1.rTcbA r) ≠ d' := - hX3.noref hdta (by rw [e3']; exact P1.inactive_ne.1) (by rw [e3']; exact P1.inactive_ne.2) - have F3 := footW_trans (footW_trans (footW_of F1) F2) (footW_of fu3) - have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by - have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) - rw [hft] at h00; cases h00 - have hks3 : L.ksb s3 = L.ksb s := hW3'.1 - -- the caller's and the receiver's words at `s3` - have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) - have hnrT : t.bv ∉ σ.releaseQueue := by rw [← hct]; exact hCI.notRel - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hw3 : (L.mem s3 (P1.stA t)).val = tsCode xt.tcbState := by - rw [P1.stA_eq, ← tStA_eq, hxt3.st] - obtain ⟨hnbt3, hnrp3⟩ := P1.run_word (w := L.mem s3 (P1.stA t)) (by rw [hw3]; exact runnable_code hrn) - have hX3' := IpcRel.ofSRN hR3 hS3 - have hSR3 : SchedRel st Z.N Z.T Z.C Z.c s3 σ3 := hX3'.2.2.1 - obtain ⟨Q3, R3', hcq3, hs3⟩ := hSR3.lists - have hSM := ScRelM.of hX3'.1 - have hnqD : NotQueued σ d'.bv := by - refine ⟨fun dm p hm => ?_, fun hm => ?_⟩ - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rq dm p _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - · obtain ⟨x, -, -, -, hkx, -, hrx, -, -⟩ := J.inv.rel _ hm - rw [hkd] at hkx; cases hkx; rw [hstd] at hrx; cases hrx - have hnqT3 : NotQueued σ3 t.bv := ⟨by rw [IK3.2.1]; exact hnq, by rw [IK3.2.2.1]; exact hnrT⟩ - have hnqD3 : NotQueued σ3 d'.bv := ⟨by rw [IK3.2.1]; exact hnqD.1, by rw [IK3.2.2.1]; exact hnqD.2⟩ - have bits3 : ∀ u ∈ Z.T, NotQueued σ3 u.bv → - (L.mem s3 (P1.inqA u) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s3 (P1.inqA u) &&& sched.Q_RELEASE) = 0#u64 := by - intro u hu hnu - refine ⟨Classical.byContradiction fun h => ?_, Classical.byContradiction fun h => ?_⟩ - · have hm := (hcq3.queued u hu).1 h - apply hnu.1 0 (specPrio (L.mem s3 (P1.prioA u))) - rw [hs3.rq _ (hcq3.prio u hu)] - exact List.mem_map_of_mem hm - · have hm := (hcq3.released u hu).1 h - apply hnu.2 - rw [hs3.rel] - exact List.mem_map_of_mem hm - obtain ⟨hqbT, hrbT⟩ := bits3 t ht hnqT3 - obtain ⟨hqbD, hrbD⟩ := bits3 d' hdT hnqD3 - have ha0 : L.actionW s3 = 0#u64 := by - have h := hSR3.act - rw [hact3, hres] at h - unfold P1.LawfulStore.actionW; rw [hcq3.cur]; exact h - have hna3 : ∀ u ∈ Z.T, L.actionW s3 ≠ u := fun u hu h' => by - rw [ha0] at h'; exact (hcq3.tcbs u hu).ne0 (by rw [← h']; rfl) - have hcw3 : L.curW s3 = t := by - have h : (nodeW st s3 Z.c layout.node.CUR_THREAD).bv = t.bv := by rw [← hs3.curThread, hct3, hct] - unfold P1.LawfulStore.curW; rw [hcq3.cur]; exact P1.eq_of_bv h - have hidl3 : σ3.idleThread = σ.idleThread := Fr3.sk.idle - have hiw3 : ∀ u ∈ Z.T, u.bv ≠ σ.idleThread → L.idleW s3 ≠ u := fun u hu hne h' => by - apply hne - rw [← hidl3, hs3.idleTh] - unfold P1.LawfulStore.idleW at h'; rw [hcq3.cur] at h' - exact congrArg _ (show nodeW st s3 Z.c layout.node.IDLE_THREAD = u from h').symm - have hit : t.bv ≠ σ.idleThread := by rw [← hct]; exact hti - have hid : d'.bv ≠ σ.idleThread := by - intro h - obtain ⟨x, hkx, -, hxs, -⟩ := J.act.2 - rw [← h, hkd] at hkx; cases hkx; rw [hstd] at hxs; cases hxs - have hcA : L.mem s3 (P1.scA t) ≠ 0#u64 → L.mem s3 (P1.scA t) ∈ Ac := fun h0 => - hB3.sact t htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw3⟩))))) h0 - have hwH : w ∈ P1.Heap.replies H := hRe ▸ hwR - have hw00 : w ≠ 0#u64 := (J.rp.align w hwR).2.1 - have hqt3 := Endp.not_queued hR3 ht hkt3 hnb - -- the caller's SC, donated - obtain ⟨xc, hkc, hcs, -⟩ := hCI.tcb - rw [hct, hkt] at hkc; cases hkc - obtain ⟨y, n, hky0⟩ := hCI.sc - have hya : Fl4Spec.scActive y = true := hCI.active (J.curSc_ne_idle hCI hti) y n hky0 - obtain ⟨sc, hsC, esc⟩ := J.obj.sc _ y n hky0 - rw [← esc] at hky0 hcs - obtain ⟨y1, n1, hky1, hyt⟩ := J.inv.back _ _ _ hkt hcs - rw [hky0] at hky1; cases hky1 - have hrelσ : Fl4Spec.scActive y = true → released σ y := fun ha => - J.inv.rd t.bv xt hkt (Or.inl hrn) xt sc.bv y n hkt hcs hky0 ha hnrT - have hse : sc.bv ≠ e.bv := kheap_ne hky0 hk (fun _ h1 h2 => by subst h1; cases h2) - have hsd : sc.bv ≠ d'.bv := kheap_ne hky0 hkd (fun _ h1 h2 => by subst h1; cases h2) - have hsw : sc.bv ≠ w.bv := kheap_ne hky0 hkr (fun _ h1 h2 => by subst h1; cases h2) - have hst : sc.bv ≠ t.bv := kheap_ne hky0 hkt (fun _ h1 h2 => by subst h1; cases h2) - have hky2 : σ2.kheap sc.bv = some (.schedContext y n) := by simp [σ2, σ1, hsd, hse, hky0] - have hky3 : σ3.kheap sc.bv = some (.schedContext y n) := by rw [stsAct_kheap]; simp [σ3a, hsd, hsw, hky2] - have hsw3 : L.mem s3 (P1.scA t) = sc := by - obtain ⟨x', hk', -, -, hscw, -⟩ := hs3.tcb t ht - rw [hkt3] at hk'; cases hk' - exact optRef_some_eq (hscw.symm.trans hcs) - have hxdn3 : x3.tcbSchedContext = none := by rw [hsc3]; exact hxdn xd hkd - -- the J state after the block - have hcD : ∀ q ∈ D, q.bv ≠ t.bv := J.notDead ht hkt (by have := runnable_code hrn; omega) - have htD := J.not_dead_of_st hdT hkd (by rw [hstd]; simp [tsCode]) - have hwD : ∀ q0 ∈ D, q0.bv ≠ w.bv := fun q0 hq0 e0 => by - have hqw : q0 = w := P1.eq_of_bv e0 - rw [hqw] at hq0 - have d1 : L.mem s (Endp.rTcbA w) = 0#u64 := (J.jcov.dead w hq0).2.2.2.1 hwH - obtain ⟨xr', hkr', hxr'⟩ := hR.reply w hwR - rw [hkr] at hkr'; cases hkr' - rw [hb', d1, optRef_zero] at hxr' - cases hxr' - have hRR : ∀ q' ∈ Z.R, ∀ xr, σ.kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → - Detached Z.C Lst q' ∧ L.mem s (rNextA q') = 0#u64 ∧ L.mem s (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D s _ σ J q' hq'' xr d'.bv xd hx' hxt' hkd - (by rw [hstd]; rfl) - have hrib3 : RelIfBound σ3 d'.bv := - Ipc.RelIfBound.of_keep (J.inv.rd d'.bv xd hkd (Or.inr (Or.inr (Or.inr ⟨_, _, _, hstd⟩)))) SK3 - have I3 : Inv σ3 := ((J.inv.toBut d'.bv).ik hnqD IK3).1.inv fun _ _ _ => hrib3 - have hscA3 : ∀ p y n, σ3.kheap p = some (.schedContext y n) → y.scTcb = some t.bv → - Fl4Spec.scActive y = true := by - intro p y n hp hyt - have hp0 : σ.kheap p = some (.schedContext y n) := SK3.2.2.2 _ _ _ hp - obtain ⟨q, hqC, eq⟩ := J.obj.sc p y n hp0 - subst eq - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hq0 := J.c0 q hqC - have hqS : q ∈ P1.Heap.scs H := ⟨_, (hJ.sc q y n hq0 hp0).2⟩ - have hS := J.xtop.fin.1.1.1 - obtain ⟨u, -, -, xu, hku, hxs⟩ := scBack_of hS J.blk.2.2.1 J.tcbs_eq.1.symm hqC hqS hq0 hp0 hyt - rw [hkt] at hku; cases hku - have e1 : σ.curSc = q.bv := by rw [← esc]; exact Option.some.inj (hcs.symm.trans hxs) - rw [← e1] at hp0 - exact hCI.active (J.curSc_ne_idle hCI hti) y n hp0 - set xtP : Fl4Spec.Tcb := { xt with tcbState := .blockedOnReply w.bv } with hxtP - set xwP : Fl4Spec.Reply := { xr3 with replyTcb := some t.bv } with hxwP - set σP := pushSt σ3 t.bv w.bv xr3 xt with hσP - set σD := pdSt σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n with hσD - have hktP : σP.kheap t.bv = some (.tcb xtP) := ps_kt - have hkwP : σP.kheap w.bv = some (.reply xwP) := ps_kw hwt - have hkdP : σP.kheap d'.bv = some (.tcb x3) := by rw [ps_ko (Ne.symm htd') (Ne.symm hwd)]; exact hkd3 - have hkyP : σP.kheap sc.bv = some (.schedContext y n) := by rw [ps_ko hst hsw]; exact hky3 - have hcnP : σP.schedulerAction = .chooseNewThread := ps_act (by rw [hct3, hct]) (by rw [hact3, hres]) - have hnsw : ∀ u, σP.schedulerAction ≠ .switchThread u := fun u e0 => by rw [hcnP] at e0; cases e0 - have hctP : σP.curThread = t.bv := - (ps_skD (σ := σ3) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).ct.trans (hct3.trans hct) - have hcscP : σP.curSc = sc.bv := - (ps_skD (σ := σ3) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).csc.trans (Fr3.sk.csc.trans esc.symm) - have hnqtP : NotQueued σP t.bv := ⟨by rw [ps_rq]; exact hnqT3.1, by rw [ps_rel]; exact hnqT3.2⟩ - have hnqdP : NotQueued σP d'.bv := ⟨by rw [ps_rq]; exact hnqD3.1, by rw [ps_rel]; exact hnqD3.2⟩ - have hhP := J.stackHead hsC hky0 (hRR w hwR xr hkr hb').1 - have hhP' : ∀ h l, y.scReplies = h :: l → h ≠ sc.bv ∧ h ≠ w.bv ∧ ∃ x, σP.kheap h = some (.reply x) := by - intro h l hr - obtain ⟨h1, h2, x, hx⟩ := hhP h l hr - refine ⟨h1, h2, x, ?_⟩ - have ht' : h ≠ t.bv := fun e0 => by rw [e0, hkt] at hx; cases hx - have hd' : h ≠ d'.bv := fun e0 => by rw [e0, hkd] at hx; cases hx - have he' : h ≠ e.bv := fun e0 => by rw [e0, hk] at hx; cases hx - rw [ps_ko ht' h2, stsAct_kheap] - simp [σ3a, hd', h2, σ2, σ1, he', hx] - have hpdE := pd_eq hktP hkdP hkyP hkwP (Ne.symm hsw) hhP' hyt htd' hst hsd hwt hwd - hctP.symm hnqtP hnsw - have hpushE : Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv true σ3 = ({((), σD)}, False) := by - rw [replyPush_don_eq hkt3 hkd3 hkr3 hwt hcs hxdn3]; exact hpdE - have hns3 : tsCode xt.tcbState ≠ 6 := by have := runnable_code hrn; omega - -- the push: link and block (`J` again), then the donation at `J` - have hPush : ipc.reply_push st arI s3 a t d' w true ⦃ r => r.2 = a ∧ ∃ σ', - Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv true σ3 = ({((), σ')}, False) ∧ - (σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 a σ') ⦄ := by - refine reply_push_iC (don := true) (P := fun s' σ' => σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D s' a σ') - hH hP0 hP s3 a σ3 hR3 hS3 ht hkt3 hkd3 hqt3 hns3 hwR hkr3 (fun _ => hdT) (fun s' _ _ e0 => ?_) ?_ - · exfalso - have h1 : σD.kheap t.bv = some (.tcb xtP) := by rw [← e0]; exact hktP - have h2 : σD.kheap t.bv = some (.tcb { xtP with tcbSchedContext := none }) := - @dn_kt (bdSt σP sc.bv w.bv y n xwP) t.bv d'.bv sc.bv xtP x3 { y with scReplies := w.bv :: y.scReplies } n - htd' hst - rw [h2] at h1 - have h3 : ({ xtP with tcbSchedContext := none } : Fl4Spec.Tcb) = xtP := by - injection h1 with h1; injection h1 - have h4 : (none : Option Fl4Spec.ObjRef) = some sc.bv := (congrArg Fl4Spec.Tcb.tcbSchedContext h3).trans hcs - cases h4 - · intro _ s4 hsb hR4 hS4 _ _ _ _ - rw [hsw3] - have hsb' : sched.set_blocked_on_reply st (L.wr s3 (P1.rTcbA w) t) t w = ok s4 := hsb - -- FL4's words and P1 at the block - have hw1 : P1.WritesIn st s3 (L.wr s3 (P1.rTcbA w) t) (fun b => b.val = w.val) := by - obtain ⟨-, -, -, hA1⟩ := reply_write_rel (hH.epHyps hP0) hP s3 σ3 hR3 hS3.1 hwR hkr3 t - exact ⟨L.ksb_wr _ _ _, L.cpu_wr _ _ _, fun b hb hn => hA1 b hb hn⟩ - have hW4 : P1.WritesIn st s3 s4 (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s3 σ3) := by - have h := set_blocked_on_reply_cn (N := Z.N) (C := Z.C) (E := Z.E) hP hSR3 ht hwR hw1 - rw [hsb', WP.spec_ok] at h; exact h - have hW4' : P1.WritesIn st s s4 (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b) := - hW3'.trans1 (hW4.mono fun b hb => Or.inl (cnW_back hks3 (SzKeepC.of Fr3.szKeep) hb)) - have hb4 := P1.sched.set_blocked_on_reply.ipc s3 t w Q0 R0 h3 (fun y hy => by - obtain ⟨hy1, hy2⟩ := hy - rcases hy1 with hy1 | hy1 - · exact absurd hy1 (Set.notMem_empty _) - · exact absurd hy1 hy2) (Or.inr hnbt3) hB3 hX3 hS3' hSg3 htH hqbT hrbT - (hna3 t ht) (hiw3 t ht hit) ⟨hnrp3, fun e0 => hnbt3 (Or.inr (Or.inl e0))⟩ hwH hw00 z3 hcA - rw [hsb', WP.spec_ok] at hb4 - obtain ⟨h4, hB4, hX4, hS4', hSg4, -, -, -, -, -, -⟩ := hb4 - have hO3 := hX3.1 - obtain ⟨hrΩ3, -⟩ := P1.objs_omega hO3 hSg3.sub - have f1 : P1.Foot st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) - s3 (L.wr s3 (P1.rTcbA w) t) := - P1.foot_wr (h3.omega _ (hrΩ3 w hwH).1).1 (P1.kw_sg (hO3.tcbW hwH)) - have q1 := (P1.omega_wr (v := t) h3 (hrΩ3 w hwH).1).1 - have f4 := P1.sched.set_blocked_on_reply.kw (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) - (Z := P1.Heap.scBits H) (Es := P1.EH H) _ t w q1 htH - rw [hsb', WP.spec_ok] at f4 - have hfoot4 : P1.WritesIn st s s4 (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) (P1.EH H) s b ∨ RcvBufW xd b) := - footW_trans (footW_trans F3 (footW_of f1)) (footW_of f4) - have hIR4 := IpcRel.ofSRN hR4 hS4 - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW4' hfoot4 - have hIu := Ju.xtop.irelK Ju.ks Ju.buf - have hRRu : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → - Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' - hxt' hkd (by rw [hstd]; rfl) - have hF4 : IFrame (L := L) Z.th su s4 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb - have hblk4 : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac s4 := ⟨⟨Q0, R0, h4⟩, hB4, hX4, hS4', hSg4⟩ - have I4 : Inv σP := ps_inv hkt3 hkr3 hwt I3 hnqT3.1 hnqT3.2 - have B4 : BlockedScActive σP := ps_bsa hkt3 hkr3 hwt hscA3 (Fr3.bsa J.bsa) - have hidT3 : σ3.idleThread ≠ t.bv := by rw [Fr3.sk.idle, ← hct]; exact fun e0 => hti e0.symm - have hAI4 : ActIdle σP := - ⟨fun u hu => (by rw [hcnP] at hu; cases hu), ps_idleOK hkt3 hkr3 hwt hidT3 (Fr3.idleOK J.act.2)⟩ - have hkq : ∀ q ∈ D, σP.kheap q.bv = σ3.kheap q.bv := fun q hq => ps_ko (hcD q hq) (hwD q hq) - have ho : ∀ {q : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject}, (∀ x, o ≠ .tcb x) → (∀ x, o ≠ .reply x) → - (σP.kheap q = some o ↔ σ3.kheap q = some o) := fun h1 h2 => ps_oth hkt3 hkr3 hwt h1 h2 - obtain ⟨V', J4⟩ := Ju.wake_postGR hIR4 hF4 hWu hblk4 hFu (DWFr.ofUm (DWFr.ofCFr Fr3) umu) ps_skD - (ps_ksub hkt3 hkr3 hwt) (ps_szKeep hkt3 hkr3 hwt) (ps_ykeep hkt3 hkr3 hwt) (ps_mcpKeep hkt3 hkr3 hwt) - (ps_bufKeep hkt3 hkr3 hwt) (fun d _ h => ps_recvB hkt3 hkr3 hwt h) (ps_ksz hkt3 hkr3 hwt) - (ps_kback hkt3 hkr3 hwt) (ps_ipcFr hkt3 hkr3 hwt) (ps_ck hkt3 hkr3 hwt) (fun d _ h => ps_free hkt3 hkr3 hwt h) - (fun q ao h => (ho (fun _ e => by cases e) (fun _ e => by cases e)).2 h) hkq - I4 B4 hAI4 (Or.inl hcnP) (Or.inl (by rw [hcnP]; intro h; cases h)) - (ps_own hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).own ⟨d', hdT, rfl⟩ J.own)) - (ps_off hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).off J.off)) (ps_nsc hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).nsc J.nsc)) - (ps_isorted hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).isorted J.isorted)) hRRu htD - -- the reply's links at the block - obtain ⟨hdet, hn0, hp0⟩ := hRRu w hwR xr hkr hb' - obtain ⟨-, -, -, -, k4⟩ := Ju.cnW_keeps hWu - refine WP.spec_mono (J4.pushDonJ hAT ht hdT hwR hsC htd hktP hkdP hkwP hkyP rfl hcs hyt hxdn3 rfl rfl - hctP hcscP hcnP hnqtP hnqdP hya hdet (by rw [(k4 w hwR).2]; exact hn0) (by rw [(k4 w hwR).1]; exact hp0) - htD) ?_ - rintro ⟨s5, a5⟩ ⟨ha5, hsp5, Lst5, J5⟩ - simp only at ha5 - subst a5 - exact ⟨rfl, _, hsp5, fun _ => ⟨V', Lst5, J5⟩⟩ - refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ ∃ σ', - Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv true σ3 = ({((), σ')}, False) ∧ - (σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 a σ')) - ?_ ?_ - · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ - rintro i1 rfl - rw [if_pos (bne_iff_ne.2 hty3)] - rcases hg with rfl | rfl - · simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true]; exact hPush - · cases g <;> simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true] <;> exact hPush - rintro ⟨s5, a5⟩ ⟨ha5, σ5', hpush, hPσ⟩ - simp only at ha5 hpush hPσ ⊢ - subst a5 - try dsimp only - have e5 : σ5' = σD := by - have h := hpush.symm.trans hpushE - exact congrArg Prod.snd (Set.singleton_injective (congrArg Prod.fst h)) - obtain ⟨V5, Lst5, J5⟩ := hPσ e5 - subst e5 - -- the receiver runs (`Inactive` with the donated SC) - set x4 : Fl4Spec.Tcb := { x3 with tcbSchedContext := some sc.bv } with hx4 - have hk5 : σD.kheap d'.bv = some (.tcb x4) := @pd_kd σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n - have hst5 : L.mem s5 (P1.stA d') = sched.TS_INACTIVE := by - have h := ((J5.xtop.irelK J5.ks J5.buf).1.toN.at_tcb hdT hk5).st - rw [stA_tStA, P1.ts_inactive] - exact UScalar.eq_of_val_eq (by rw [h]; rfl) - have htmD : σD.curTime = σ.curTime := (@pd_tm σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n).trans - ((ps_skD (σ := σ3) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).tm.trans SK3.2.1) - have hkpD : σD.kheap sc.bv = some (.schedContext { { y with scReplies := w.bv :: y.scReplies } with - scTcb := some d'.bv } n) := - @dn_kp (bdSt σP sc.bv w.bv y n xwP) t.bv d'.bv sc.bv xtP x3 { y with scReplies := w.bv :: y.scReplies } n hsd - have hrelD : RelIfBound σD d'.bv := by - intro x' scp y' n' hx' hsc' hky' ha' _ - rw [hk5] at hx'; cases hx' - simp only [x4, Option.some.injEq] at hsc' - subst hsc' - rw [hkpD] at hky' - cases hky' - have := hrelσ hya - unfold released at this ⊢ - rw [htmD]; exact this - refine WP.spec_bind (J5.stsIJ hdT (fun h => htD d' h rfl) hk5 rfl .running (by simp [tsCode]) sched.TS_RUNNING - (by unfold sched.TS_RUNNING; rfl) (fun _ => hrelD) - (P1.sched.set_thread_state.running_blkI (Es := P1.EH H) s5 d' J5.blk hdH hst5)) ?_ - rintro s6 ⟨Lst6, J6⟩ - set x6 : Fl4Spec.Tcb := { x4 with tcbState := .running } with hx6 - have hdcD : d'.bv ≠ σD.curThread := by - rw [show σD.curThread = t.bv from (@pd_ct σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n).trans hctP] - exact Ne.symm htd' - have e6 : stsAct (updK σD d'.bv (.tcb x6)) d'.bv = updK σD d'.bv (.tcb x6) := stsAct_ne hdcD - have hk6 : (stsAct (updK σD d'.bv (.tcb x6)) d'.bv).kheap d'.bv = some (.tcb x6) := by - rw [e6]; simp [updK] - have hnr6 : d'.bv ∉ (stsAct (updK σD d'.bv (.tcb x6)) d'.bv).releaseQueue := by - rw [e6] - show d'.bv ∉ σD.releaseQueue - rw [show σD.releaseQueue = σ.releaseQueue from (@pd_rel σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n).trans - ((@ps_rel σ3 t.bv w.bv xr3 xt).trans SK3.1)] - exact hnqD.2 - have hact6 : ∀ p y' n', x6.tcbSchedContext = some p → - (stsAct (updK σD d'.bv (.tcb x6)) d'.bv).kheap p = some (.schedContext y' n') → Fl4Spec.scActive y' = true := by - intro p y' n' hp hy' - simp only [x6, x4, Option.some.injEq] at hp - subst hp - rw [e6] at hy' - simp only [updK_kheap, Function.update_of_ne hsd] at hy' - rw [hkpD] at hy' - cases hy' - exact hya - have hti6 : d'.bv ≠ (stsAct (updK σD d'.bv (.tcb x6)) d'.bv).idleThread := by - rw [e6] - show d'.bv ≠ σD.idleThread - rw [show σD.idleThread = σ.idleThread from (@pd_idle σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n).trans - ((ps_skD (σ := σ3) (t := t.bv) (w := w.bv) (xr := xr3) (xt := xt)).idle.trans Fr3.sk.idle)] - exact hid - have htc6 : d'.bv ≠ (stsAct (updK σD d'.bv (.tcb x6)) d'.bv).curThread := by - rw [e6]; exact hdcD - have hspec := sendIpc_faultPush_eq (don := true) hk hkd hde hstd blk badge.bv g gr hg e2 hU hkt3 hkd3 hpushE hk5 (by rw [hft]; simp) - (t := t.bv) - refine WP.spec_mono (J6.sendTailJ hdT hk6 rfl hnr6 hact6 hti6 htc6) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ - simp only at ha7 - subst ha7 - exact ⟨((), σ7), by rw [hspec, h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.sendFaultPDJG hAT ht hkt hrn hft hnt hct hres hti hnq he hk blk badge g gr hg hrepn hxdn) fun _ ⟨z, hz, h⟩ => ⟨z, hz, JAtN.toJAt J h⟩ - -set_option maxHeartbeats 64000000 in -/-- **`handle_fault` with an endpoint handler and a waiting receiver at `J`, -with or without a receive buffer** (module docstring): XTopJointFaultEp's -`JAtZ.faultBlockJ` up to the handler cap, then `set_fault` at `J` -(`JAtZ.setFaultCapJ`) and the send to the receiver: `JAtZ.sendFaultIJ` (no -reply right or no reply object: the sender `Inactive`), `JAtZ.sendFaultPJ` -(the reply pushed, no donation: `can_donate` false or the receiver with an -SC), `JAtZ.sendFaultPDJ` (the reply pushed and the sender's SC donated). -/ theorem JAtZ.faultRecvJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) @@ -2154,194 +94,17 @@ theorem JAtZ.faultRecvJG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H {d : U64} {q : List Fl4Spec.ObjRef} (hkq : σ.kheap ptr.bv = some (.endpoint (.recvEP (d.bv :: q)))) {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - obtain ⟨hcur, x, hk, hrn⟩ := J.curRunnable hni hct - have hP0 := J.ip - have hI := J.xtop.irelK J.ks J.buf - have hS := J.xtop.fin.1.1.1 - have hT : TcbPlaced Z.T := hP0.e.tcb - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb - have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 - obtain ⟨Q, R, hcq, hs⟩ := hS.lists - have hct' : ct = nodeW st s Z.c layout.node.CUR_THREAD := by - have h := sched.cur_thread.spec' (L := L) s - rw [hct, WP.spec_ok, hcq.cur] at h; exact h - have ht : ct ∈ Z.T := by rw [hct']; exact hcq.curT - have hta := hP0.e.tcb ct ht - have htH : ct ∈ P1.Heap.tcbs H := J.zH.1 ct ht - have htD : ct ∉ D := fun h => J.notDead ht hk (by have := runnable_code hrn; omega) ct h rfl - have hnq' : ∀ d p, ct.bv ∉ σ.readyQueues d p := by rw [← hcur]; exact hnq - have hC : CurInv σ := J.curInv (by rw [hni.2]; intro e; cases e) - have hnr : ct.bv ∉ σ.releaseQueue := by rw [← hcur]; exact hC.notRel - have hti : σ.curThread ≠ σ.idleThread := hni.1 - have hidt : σ.idleThread ≠ ct.bv := fun e => hti (by rw [hcur, e]) - -- the handler cap, its endpoint - obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb - rw [hk] at hk1; cases hk1 - have e1 : c1 = .Endpoint ptr bdg sd rv g gr := by rw [hep] at hc1; simpa using hc1.symm - subst e1 - have habs := hcr.2 - simp only [absCap] at habs - have hfh : x.tcbFaultHandler = .endpointCap ptr.bv bdg.bv (rightsOf sd rv g gr) := habs.symm - have hAS : AbsSlot Z.th (ct.bv, Fl4Spec.tcbCnodeIndex 3) := ⟨ct, rfl, Or.inr ⟨htcb, 3, by decide, rfl⟩⟩ - have hpE : ptr ∈ Z.E := J.slotE hAS hep - obtain ⟨xe, hke, -⟩ := hI.1.ep ptr hpE - have hpt : ptr.bv ≠ ct.bv := fun e => by rw [e, hk] at hke; cases hke - have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE - have hfit := J.kern.heap.fits ptr _ hHe - simp only [P1.HKind.bits] at hfit - have hcov := J.cover_cap (P1.WritesIn.refl s _) hAS.isSlot hep (fun h => by cases h) (ok_inj (phys_eq _).symm) rfl - (range_ep ptr bdg sd rv g gr hfit) fun k hk' => by - rw [hHe] at hk'; cases hk' - exact ⟨by simp only [P1.HKind.bits]; omega, fun z h => by cases h⟩ - -- P1's `CanBlock` of the current thread - obtain ⟨bq, br⟩ := J.curBits ht hnq' hnr - obtain ⟨hna, -⟩ := J.words_of_spec ht (fun u hu => by rw [hni.2] at hu; cases hu) - (fun e => hni.1 (by rw [hcur, e])) - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct ht - rw [hk] at hk0; cases hk0 - have hv : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by - rw [P1.stA_eq, ← tStA_eq]; exact hTR.st - obtain ⟨hnb, hnrp⟩ := P1.run_word (w := L.mem s (P1.stA ct)) (by rw [hv]; exact runnable_code hrn) - have ha0 : L.actionW s = 0#u64 := by - have h := hS.act - rw [hni.2] at h - unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h - have hcw : L.curW s = ct := by - apply P1.eq_of_bv - rw [← hcur, hs.curThread] - unfold P1.LawfulStore.curW nodeW; rw [hcq.cur] - have hcbP : P1.CanBlock st (P1.Heap.tcbs H) Ac s ct := by - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hS0, hSg0⟩ := J.blk - refine ⟨htH, hnb, hnrp, bq, br, hna, ?_, ?_⟩ - · intro h - have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by - unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] - exact hti (by rw [hcur, hs.idleTh, ← ei, h]) - · exact fun h1 => hB0.sact ct htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw⟩))))) h1 - -- the spec's donation flag is FL4's - obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb ct ht - rw [hk] at hkt6; cases hkt6 - have hdon : (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by - rw [hsct6] - by_cases h0 : L.mem s (scA ct) = 0#u64 - · simp [h0, Notif.optRef] - · simp [h0, Notif.optRef] - -- `handle_fault`: the handler cap - unfold faults.handle_fault - rw [tcb_slot_fault] - apply ok_bind_spec - rw [slot_cap_eq, hep] - apply ok_bind_spec - step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ - subst hi - refine WP.spec_bind (Pₘ := fun r : Bool × S × A => r.1 = true ∧ - ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.2.1 z.2 ∧ JAt (L := L) arI AR r.2.1 r.2.2 z.2) ?_ ?_ - swap - · rintro ⟨b0, s2, a2⟩ ⟨hb, hr0⟩ - simp only at hb hr0 - subst hb - exact (WP.spec_ok _).2 hr0 - unfold faults.send_fault_ipc - dsimp only - -- `set_fault` - set x2 : Fl4Spec.Tcb := { x with tcbFault := some f' } with hx2 - set σf := updK σ ct.bv (.tcb x2) with hσf - -- `set_fault` at `J` - refine WP.spec_bind (J.setFaultJG ht hk (fun e0 d0 h => by - have := runnable_code hrn; rw [h] at this; simp [tsCode] at this) hcbP hf) ?_ - rintro s7 ⟨V, J7, -⟩ - have hkf : σf.kheap ct.bv = some (.tcb x2) := by simp [hσf, updK] - have hkfp : ∀ q, q ≠ ct.bv → σf.kheap q = σ.kheap q := by - intro q hq'; rw [hσf]; simp only [updK, Function.update_of_ne hq'] - have hkef : σf.kheap ptr.bv = some (.endpoint (.recvEP (d.bv :: q))) := by rw [hkfp _ hpt]; exact hkq - have hnb0 : tsCode x.tcbState ≠ 3 ∧ tsCode x.tcbState ≠ 4 := by - have := runnable_code hrn; omega - have htq : ct.bv ∉ (Fl4Spec.Endpoint.recvEP (d.bv :: q)).epQueue := - Endp.not_queued hI.1.toE ht hk hnb0 ptr hpE _ hkq - have hdc : d.bv ≠ ct.bv := fun e0 => htq (by rw [← e0]; simp [Fl4Spec.Endpoint.epQueue]) - have hpost : ∀ don : Bool, endpoint.send_ipc st arI s7 a true false bdg g gr don ct ptr ⦃ r => - ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv g gr don ct.bv ptr.bv σf).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - intro don - by_cases hgg : g = true ∨ gr = true - · by_cases hA : ∀ xd, σf.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, - xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none - · by_cases hS : don = false ∨ ∀ xd, σf.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none - · exact J7.sendFaultPJG hAT ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don hgg hA hS - · have hd1 : don = true := by - cases don - · exact absurd (Or.inl rfl) hS - · rfl - subst hd1 - refine J7.sendFaultPDJG hAT ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr hgg hA ?_ - intro xd hxd - by_contra hne - exact hS (Or.inr fun xd' hxd' => by rw [hxd] at hxd'; cases hxd'; exact hne) - · refine J7.sendFaultIJG ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don (Or.inr ?_) - intro xd hxd e' rep dd hst - by_contra hne - apply hA - intro xd' hxd' e'' rep' dd' hst' - rw [hxd] at hxd'; cases hxd' - rw [hst] at hst'; cases hst'; exact hne - · exact J7.sendFaultIJG ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don - (Or.inl ⟨Bool.eq_false_iff.2 fun h => hgg (Or.inl h), Bool.eq_false_iff.2 fun h => hgg (Or.inr h)⟩) - refine WP.spec_bind (hpost _) ?_ - rintro ⟨s', a'⟩ ⟨z, hz, hJ⟩ - apply (WP.spec_ok _).2 - refine ⟨rfl, ?_⟩ - have hz' : z ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv - (decide (Fl4Spec.Rights.allowGrant ∈ rightsOf sd rv g gr)) - (decide (Fl4Spec.Rights.allowGrantReply ∈ rightsOf sd rv g gr)) (decide (x.tcbSchedContext ≠ none)) ct.bv - ptr.bv (updK σ ct.bv (.tcb { x with tcbFault := some f' }))).1 := by - rw [rights_grant, rights_grantReply, ← hdon]; exact hz - obtain ⟨Z', H', Cs', Ac', Lst', D', J', _⟩ := hJ - exact ⟨((), z.2), handleFault_ep_mem hk hfh _ hz', - ⟨_, _, J'.xtop.rel.1, J'.xtop.rel.2.1, J'.xtop.rel.2.2.1, J'.xtop.rel.2.2.2.1, J'.xtop.rel.2.2.2.2.1⟩, - ⟨_, _, _, _, _, _, J', inferInstance⟩⟩ - + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.faultRecvJG hAT hni hct hnq hep hkq hf) fun _ h => JAtN.post J h -set_option maxHeartbeats 4000000 in -/-- **`handle_fault` at `J`** (XTopJointNoFault's `faultHypJ` at the given -`J`, every handler cap proved): a null handler by `JAtZ.noFaultJ`, an -endpoint by `JAtZ.faultRecvJ` (a waiting receiver, with or without a receive -buffer) or `JAtZ.faultBlockJ` (an idle or sending endpoint), any other cap -excluded by l4v `valid_fault_handler` (`hvfh`). -/ theorem JAtZ.faultHypJZG (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - obtain ⟨hcur, x, hk⟩ := J.curEq hct - have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 - obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb - rw [hk] at hk1; cases hk1 - have hv : Fl4Spec.validFaultHandler (absCap c1) := by - rw [hcr.2]; exact hvfh x (by rw [hcur]; exact hk) - by_cases hn : c1 = .Null - · subst hn - exact J.noFaultJ hni hct hnq hc1 f f' - obtain ⟨p, b, sd, rv, g, gr, rfl⟩ := vfh_ep hv hn - have hAS : AbsSlot Z.th (ct.bv, Fl4Spec.tcbCnodeIndex 3) := ⟨ct, rfl, Or.inr ⟨htcb, 3, by decide, rfl⟩⟩ - have hpE : p ∈ Z.E := J.slotE hAS hc1 - have hI := J.xtop.irelK J.ks J.buf - obtain ⟨xe, hke, -⟩ := hI.1.ep p hpE - cases xe with - | recvEP l => - obtain ⟨-, xs, hxs0, hq, -⟩ := hI.1.toE.at_ep hpE hke - obtain ⟨d', xs', rfl⟩ := List.exists_cons_of_ne_nil hxs0 - simp only [List.map_cons] at hq - subst hq - exact J.faultRecvJG hAT hni hct hnq hc1 hke hf - | idleEP => - exact J.faultBlockJG hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf - | sendEP q => - exact J.faultBlockJG hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf - + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.faultHypJZG hAT hni hct hnq hvfh hf) fun _ h => JAtN.post J h end diff --git a/proofs/Fl4Proofs/P3/XTopJointFaultRecv.lean b/proofs/Fl4Proofs/P3/XTopJointFaultRecv.lean index 7d1905e7b..110f8d559 100644 --- a/proofs/Fl4Proofs/P3/XTopJointFaultRecv.lean +++ b/proofs/Fl4Proofs/P3/XTopJointFaultRecv.lean @@ -1,52 +1,8 @@ /- -P3 (DESIGN.md §9), IPC: **a cap fault sent to an endpoint handler with a -waiting receiver at `J`**, with or without a receive buffer, and -`handle_fault` at `J` for every handler cap (`JAtZ.faultHypJZ`). - -FL4's `send_fault_ipc` with an endpoint cap: `set_fault`, then -`send_ipc(blocking, call = false, …)`: the receiver is dequeued, the transfer -is `do_fault_transfer` (the sender's fault word is set), then (as for a call: -FL4 reads the fault word where the call flag is false, l4v takes -`call ∨ fault ≠ none`) the reply push or the sender `Inactive`, the receiver -`Running` and the tail. - -* `JAtZ.fin_frameF`: XTopJointRegFrame's `JAtZ.reg_frameF` for a footprint - inside `FinW` (TCB words, not only registers and the fault word). -* `JAtZ.setFaultCapJ`: `set_fault` of a cap fault at `J` (the seven words, - the spec's `thread_set` of the fault: a quiet step `QKY`). -* `do_ipc_transfer_capF_rg` (FL4's footprint: the receiver's registers), - `fxTcb`/`doIpcTransfer_capF_eq` (the spec's outcome), `do_ipc_transfer_capFJ` - (on `IRel`, EpFaultNone's `do_ipc_transfer_faultN`): the fault transfer of a - cap fault to a receiver without a receive buffer. -* `sendIpc_faultInactive_eq`, `sendIpc_faultPush_eq`: the spec's `send_ipc` - of a faulted sender to a waiting receiver. -* `set_mr_rgB`, `set_mrs_lookup_failure_rgB`, `do_ipc_transfer_capF_rgB`: - FL4's footprint of the cap-fault transfer into a receive buffer (the - receiver's registers and its buffer words, XTopJointXferB's `XferBW`). -* `xferFaultStepJ`: XTopJointXferB's `xferStepJ` for the cap-fault transfer, - uniform in the receive buffer (with a buffer: EpFaultMore's - `do_ipc_transfer_fault`, the spec's outcome `updK (setUm σ um) rcv x'` by - `doFaultTransfer_eq`, P1 by `blkX_bufw`). -* `JAtZ.sendFaultIJ`, `JAtZ.sendFaultPJ`, `JAtZ.sendFaultPDJ`: XTopJointSendCall's - `sendCallIJ`, XTopJointSendPush's `sendCallPJ`, XTopJointSendPushD's - `sendCallPDJ` for `call = false` and a running or restarting sender with a - cap fault, the transfer `xferFaultStepJ`, back to `JAtZ` across the buffer - words by `JAtZ.bufRebaseX`. -* `JAtZ.faultRecvJ`: `handle_fault` with an endpoint handler with a waiting - receiver; `JAtZ.faultHypJZ`: `handle_fault` at a given `J` for every - handler cap (null, endpoint idle/sending/receiving), used by - XTopJointEntry's `handle_invocation_refinesJ`. - -(mmuAD gen 42b18) `fin_frameF`, `setFaultCapJ` stated over `JAtZB` in place with the copies' statements (post at `Z`; -`setFaultCapJ` also names its `FinW` footprint); the `JAtZ` names are corollaries (witness `Z.vs`, `ext` by -`JAtZ.ext_oobj` over `FinW`). P3/JAtZV3FaultRecvB's copies deleted. +Shared fault-transfer and fault-write refinements. The endpoint send proofs +use these leaves for any non-timeout fault. -/ -import Fl4Proofs.P3.XTopJointFaultEp -import Fl4Proofs.P3.XTopJointSendPushD -import Fl4Proofs.P3.EpSendF -import Fl4Proofs.P3.BufFr -import Fl4Proofs.P3.BufFrA -import Fl4Proofs.P3.BufJ +import Fl4Proofs.P3.XTopJointXferFCore open Aeneas Aeneas.Std Result namespace Fl4Proofs.P3 @@ -55,590 +11,6 @@ open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proof noncomputable section -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} -variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} - {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - -set_option maxHeartbeats 4000000 in -/-- **`JAtZ` across a quiet step writing `FinW` words** (XTopJointRegFrame's -`JAtZ.reg_frameF` with the footprint `FinW`). -/ -theorem JAtZB.fin_frameF (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {σ' : Fl4Spec.State Unit} - {Ac' : Set U64} - (hI3 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s' σ') - (hw : P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ)) (hA : QKY σ σ') (hyk : YKeep σ σ') - (hInv : Inv σ') - (hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac' s') - (hfoot : P1.WritesIn st s s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) ∅ s)) : - JAtZB (L := L) arI AR Z H Cs Ac' Lst D s' a σ' := by - have hI := J.xtop.irelK J.ks J.buf - have hwC : P1.WritesIn st s s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hw.mono fun b hb => Or.inl hb - have hF : IFrame (L := L) Z.th s s' := IRel.iframe_of hI hwC fun b hb => CnW.oobj hI.2.2.1 hb - have hwF := hw - have hck : Fl4Proofs.P3.CKeep σ σ' := hA.ckeepP - have hAR : AR a σ.archState.x64CurrentCr3 := J.xtop.fin.1.1.2.2.2.2.2.2 - obtain ⟨V', hX3⟩ := XTopAt.irel_same J.xtop hI3 hAR hF.1 hck.cdt hck.orig hck.ks hF.2 - have hks : L.ksb s' = L.ksb s := hF.2 - obtain ⟨k1, k2, kb, k3, k4⟩ := J.finW_keeps hwF - have ck := hA.callKeep - obtain ⟨hCR', hRP'⟩ := CallRel.carry J.call J.rp ⟨k3, k4⟩ hks ck - have hRF' := RFree.carry J.rfree J.call k4 ck - have hRR' := J.rrecv.frame k4 hA.khrb - have hDbg := J.kw_dbg (hfoot.mono fun b hb => kw_empty_mono hb _) - have hKd := J.kw_dbgKeep (hfoot.mono fun b hb => kw_empty_mono hb _) - have hS3 : SchedRel st Z.N Z.T Z.C Z.c s' σ' := hI3.2.2.1 - have hAI3 : ActIdle σ' := hA.actIdle J.act - have hdead : ∀ q ∈ D, DeadP (L := L) H s' q := J.deadP_qk hA hS3 hI3.1 hwF k3 hAI3.1 (J.yld.frame k2 hyk) hyk - have hjpl : ∃ Tr Cq, JPlaced (L := L) Z.th H Tr Cq s' σ' := by - obtain ⟨Tr, Cq, hJ⟩ := J.jpl - exact ⟨Tr, Cq, hJ.same hF.1 (fun q y n _ hq => hA.szKeep q.bv y n hq) hks (J.finW_irq hwF) - (J.idleW_keep hS3 hA.idle hA.isc).2⟩ - have hkern := J.kern_keep hks hwF.2.1 hS3 hA.ct hA.csc (fun sl h => Or.inl (by rw [← hA.orig]; exact h)) - (by rw [hA.arch]) - (fun q ao h => (hA.oth (fun _ e => by cases e) (fun _ _ e => by cases e)).2 h) hDbg - (D' := D) - have R : JRest (L := L) arI (Z.mv Z.G V') H Cs Ac' Lst D s' σ' := - ⟨hCR', hRF', hRR', J.yld.frame k2 hyk, J.mcp.frame k1 hA.mcpKeep, J.buf.frame kb hA.bufKeep, hRP', - J.apart.sc_frame hks hA.szKeep, hjpl, J.jcov_keep hks hF.1 hdead (J.idleW_keep hS3 hA.idle hA.isc) - (DXKeep.of_dbg hKd (J.tdkeep_of hwF fun _ hb => Ipc.FinW.ntd J.xtop.fin.1.1.1 hb)), hkern, - J.finW_utc hwF hF.1 hA.cdt hA.orig hA.arch hDbg, hA.nsc J.nsc, hInv, hA.cur J.cur, hA.own J.own, hA.off J.off, - hAI3, hA.bsa J.bsa, hA.isorted J.isorted, hA.curRunM J.curRun, hblk⟩ - have hC0 := JCs.sameB J hF.1 hA.ksz - have hC : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ - exact J.cs_frameI hks hX3 hwF (fun b hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb) hA.arch (fun q ao h => (hA.oth (fun _ e => by cases e) (fun _ _ e => by cases e)).2 h) hA.szKeep hF.1 hA.kback hA.ipcFr hC R hKd hck.orig (J.idleW_keep hS3 hA.idle hA.isc).1 J.zD - -/-- `JAtZB.fin_frameF` at `JAtZ` (via `JAtZ.toB`). -/ -theorem JAtZ.fin_frameF (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {σ' : Fl4Spec.State Unit} - {Ac' : Set U64} - (hI3 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s' σ') - (hw : P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ)) (hA : QKY σ σ') (hyk : YKeep σ σ') - (hInv : Inv σ') - (hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) - (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac' s') - (hfoot : P1.WritesIn st s s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) - (P1.Heap.scBits H) ∅ s)) : - ∃ V', JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst D s' a σ' := - ⟨Z.vs, (Fl4Proofs.P3.JAtZB.fin_frameF (J := J.toB) (hI3 := hI3) (hw := hw) (hA := hA) (hyk := hyk) (hInv := hInv) (hblk := hblk) (hfoot := hfoot)).toJAtZ (J.ext_oobj hw (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) - (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb))⟩ - -set_option maxHeartbeats 4000000 in -/-- **`set_fault` of a cap fault at `J`** (module docstring): the thread not -blocked on send (so `Inv.rd`'s class is unchanged), P1's `CanBlock` of any -thread carried. -/ -theorem JAtZB.setFaultCapJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) - {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : - faults.set_fault st s t f ⦃ s' => JAtZB (L := L) arI AR Z H Cs Ac Lst D s' a - (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ∧ - P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) ⦄ := by - have hP0 := J.ip - have hI := J.xtop.irelK J.ks J.buf - have hta := hP0.e.tcb t ht - have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb - obtain ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩ := hf - obtain ⟨⟨lt, l0, l1⟩, he, -⟩ := spec_exists (encode_lfRel hlf) - refine WP.spec_mono (WP.spec_and (WP.spec_and (set_fault_cap_top hP0 hI ht hk ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩) - (set_fault_cap_eq (L := L) s t a0 rp lf he)) - (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s t (.Cap a0 rp lf) (t0 := t0) J.blk htH - (fun _ h => by simp at h) hcb) - (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) - (Es := ∅) s t (.Cap a0 rp lf) hTH htH))) ?_ - rintro s7 ⟨⟨⟨-, hI7⟩, hs7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ - have hwF : P1.WritesIn st s s7 (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) := by - subst hs7 - have w := ((((((writesIn_wr (st := st) (s := s) (v := lt) (a_lf hta).1).trans - (writesIn_wr (v := l0) (a_lf0 hta).1)).trans (writesIn_wr (v := l1) (a_lf1 hta).1)).trans - (writesIn_wr (v := fl4_abi.consts.fault.CapFault) (a_fault hta).1)).trans (writesIn_wr (v := a0) (a_fw0 hta).1)).trans - (writesIn_wr (v := if rp then 1#u64 else 0#u64) (a_fw1 hta).1)).trans - (writesIn_wr (v := 0#u64) (a_fw2 hta).1) - refine w.mono fun w0 hw0 => ?_ - have k : ∃ K : Nat, 256 ≤ K ∧ K < 4096 ∧ K ≠ 3440 ∧ K ≠ 3472 ∧ ((K ≠ 3512 ∧ K ≠ 3528) ∧ K ≠ 3664 ∧ K ≠ 3456) ∧ w0.val = t.val + K := by - rcases hw0 with ((((((h | h) | h) | h) | h) | h) | h) <;> subst h - · exact ⟨3408, by omega, by omega, by omega, by omega, by omega, val_lf hta⟩ - · exact ⟨3416, by omega, by omega, by omega, by omega, by omega, val_lf0 hta⟩ - · exact ⟨3424, by omega, by omega, by omega, by omega, by omega, val_lf1 hta⟩ - · exact ⟨3376, by omega, by omega, by omega, by omega, by omega, val_fault hta⟩ - · exact ⟨3384, by omega, by omega, by omega, by omega, by omega, val_fw0 hta⟩ - · exact ⟨3392, by omega, by omega, by omega, by omega, by omega, val_fw1 hta⟩ - · exact ⟨3400, by omega, by omega, by omega, by omega, by omega, val_fw2 hta⟩ - obtain ⟨K, k1, k2, k3, k4, k5, k6⟩ := k - exact Or.inr ⟨t, ht, K, k1, k2, k3, k4, k5, k6⟩ - set y : Fl4Spec.Tcb := { x with tcbFault := some (.capFault a0.bv rp lf') } - have hA : QKY σ (updK σ t.bv (.tcb y)) := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun p => ?_⟩ - by_cases hp : p = t.bv - · subst hp; exact Or.inr (Or.inl ⟨x, y, hk, by simp [updK], rfl⟩) - · exact Or.inl (by simp [updK, hp]) - have J' := J.fin_frameF hI7 hwF hA (YK.YKS.updTcb (y := y) hk rfl).ykeep - (J.inv.updSame (y := y) hk rfl rfl (Or.inr hns)) hblk7 hfoot7 - exact ⟨J', hcb7, hwF⟩ - -/-- `JAtZB.setFaultCapJ` at `JAtZ` (via `JAtZ.toB`). -/ -theorem JAtZ.setFaultCapJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) - {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : - faults.set_fault st s t f ⦃ s' => ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s' a - (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ⦄ := - WP.spec_mono (Fl4Proofs.P3.JAtZB.setFaultCapJ (J := J.toB) (ht := ht) (hk := hk) (hns := hns) (hcb := hcb) (hf := hf)) fun _ ⟨B, hcb, hw⟩ => - ⟨Z.vs, B.toJAtZ (J.ext_oobj hw (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) - (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb)), hcb⟩ - -end - -/-! ## The fault transfer to a receiver without a receive buffer, on `IRel` -/ - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} - -theorem set_mr_rg0 {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv i v : U64} (hr : rcv ∈ T) - (h : P1.WritesIn st s0 s (XferRegW T ∅)) : - msg.set_mr st s rcv 0#u64 i v ⦃ r => P1.WritesIn st s0 r.2 (XferRegW T ∅) ⦄ := by - unfold msg.set_mr - split - · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ - refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ - simp only [lift, bind_ok, WP.spec_ok] - exact rg_trans h w2 - · simp only [bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - exact h - -theorem set_mrs_lookup_failure_rg0 {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv off : U64} - {lf : error.LookupFault} (hr : rcv ∈ T) (h : P1.WritesIn st s0 s (XferRegW T ∅)) : - faults.set_mrs_lookup_failure st s rcv 0#u64 lf off ⦃ r => P1.WritesIn st s0 r.2 (XferRegW T ∅) ⦄ := by - unfold faults.set_mrs_lookup_failure - refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ - refine WP.spec_bind (set_mr_rg0 (v := i) (i := off) hT hr h) ?_ - rintro ⟨i1, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - split - · exact (WP.spec_ok _).2 h1 - · try simp only [lift, bind_ok] - exact set_mr_rg0 hT hr h1 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rg0 hT hr h2 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rg0 hT hr h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rg0 hT hr h3 - -/-- **`do_ipc_transfer`'s footprint, a cap-faulted sender and a receiver -without a buffer**: the receiver's registers only. -/ -theorem do_ipc_transfer_capF_rg {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) (a : A) - (ep badge : U64) (grant : Bool) - (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄) - (hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' (XferRegW T ∅) ⦄ := by - have hS : P0.StoreTotal st := L.total - unfold ipc.do_ipc_transfer - refine WP.spec_bind hb ?_ - rintro rb rfl - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ft rfl - rw [hty, if_neg (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] - unfold ipc.do_fault_transfer - refine WP.spec_bind (Pₘ := fun r : U64 × S => P1.WritesIn st s r.2 (XferRegW T ∅)) ?_ ?_ - · unfold faults.set_mrs_fault - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ty rfl - refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ - rw [if_pos hty] - refine WP.spec_bind (set_mr_rg0 hT hr (P1.WritesIn.refl s _)) ?_ - rintro ⟨_, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rg0 hT hr h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ - exact set_mrs_lookup_failure_rg0 hT hr h3 - rintro ⟨sent, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ - refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ - refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 (XferRegW T ∅)) ?_ - fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr - (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => rg_trans h3 w4 - unfold msg.set_msg_info - exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => - WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) - fun s4 w4 => rg_trans h1 w4 - -end - -section SpecF -open Fl4Spec - -/-- The receiver's TCB after the fault transfer of a cap fault without a -receive buffer (EpFaultNone's `doFaultTransfer_eqN` with `makeFaultMsg_cap`). -/ -def fxTcb (xr xs : Tcb) (cf : ObjRef) (rp : Bool) (lf : LookupFailure) (b : Word) : Tcb := - Notif.setReg (Notif.setReg (withRegs xr (mrRegs xr.tcbArch.tcbContext.userRegs - (capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf))) msg_info_register - (messageInfoToData ⟨natToLen (min 4 (capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf).length), - 0, 0, 1⟩)) badge_register b - -theorem fxTcb_eqA (xr xs : Tcb) (cf : ObjRef) (rp : Bool) (lf : LookupFailure) (b : Word) : - fxTcb xr xs cf rp lf b = { xr with tcbArch := (fxTcb xr xs cf rp lf b).tcbArch } := rfl - -/-- The spec's `do_ipc_transfer` of a cap-faulted sender to a receiver -without a receive buffer. -/ -theorem doIpcTransfer_capF_eq {σ : State Unit} {snd rcv : ObjRef} {xs xr : Tcb} - (hks : σ.kheap snd = some (.tcb xs)) (hkr : σ.kheap rcv = some (.tcb xr)) {cf : ObjRef} {rp : Bool} - {lf : LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) (hrb : Endp.ipcBufOf true xr = none) - (ep : Option ObjRef) (badge : Word) (grant : Bool) : - doIpcTransfer (Z := Unit) snd ep badge grant rcv σ = - ({((), updK σ rcv (.tcb (fxTcb xr xs cf rp lf badge)))}, False) := by - have h0 : doIpcTransfer (Z := Unit) snd ep badge grant rcv σ = doFaultTransfer (Z := Unit) badge snd rcv none σ := by - unfold doIpcTransfer - rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] - rw [h0, doFaultTransfer_eqN hks hkr hf (makeFaultMsg_cap hks cf rp lf) badge] - simp only [mrStateN, updK, Function.update_idem] - rfl - -/-- The spec's `send_ipc` of a faulted sender (`call = false`) to a waiting -receiver when the sender gets no reply: it becomes `Inactive` (EpSendF's -`sendIpc_callInactiveF_eq` for any `canDonate`). -/ -theorem sendIpc_faultInactive_eq {σ : State Unit} {t e d : ObjRef} {q : List ObjRef} {don : Bool} - (hk : σ.kheap e = some (.endpoint (.recvEP (d :: q)))) {xd : Tcb} (hkd : σ.kheap d = some (.tcb xd)) - (hde : d ≠ e) (htd : t ≠ d) {e' : ObjRef} {rep : Option ObjRef} {dd : ReceiverPayload} - (hst : xd.tcbState = .blockedOnReceive e' rep dd) (blk : Bool) (badge : Badge) (g gr : Bool) - (hcond : ¬ ((g = true ∨ gr = true) ∧ rep ≠ none)) {σ2 σ3 : State Unit} - (hT : doIpcTransfer (Z := Unit) t (some e) badge g d (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))) = - ({((), σ2)}, False)) - (hU : NonDet.maybeM (replyUnlinkTcb (Z := Unit) d) rep σ2 = ({((), σ3)}, False)) - {xt3 x3 : Tcb} (hkt3 : σ3.kheap t = some (.tcb xt3)) (hkd3 : σ3.kheap d = some (.tcb x3)) - (hf3 : xt3.tcbFault ≠ none) : - sendIpc (Z := Unit) blk false badge g gr don t e σ = - specWakeTailE d (stsAct (updK (stsAct (updK σ3 t (.tcb { xt3 with tcbState := .inactive })) t) d - (.tcb { x3 with tcbState := .running })) d) := by - have hkd1 : (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))).kheap d = some (.tcb xd) := by - simp [hde, hkd] - have hkd3' : (stsAct (updK σ3 t (.tcb { xt3 with tcbState := .inactive })) t).kheap d = some (.tcb x3) := by - rw [stsAct_kheap]; simp [Ne.symm htd, hkd3] - unfold sendIpc - rw [nd_bind_one (getEndpoint_eq hk)] - cases blk <;> dsimp only <;> - · rw [nd_bind_one (tcbEpDequeue_eq hk (by simp [Endpoint.epQueue])), nd_bind_one (getThreadState_eq hkd1), hst] - dsimp only - rw [nd_pure_bind', nd_bind_one hT, nd_bind_one hU, nd_bind_one (getTcbObjRef_eq _ hkd3), - nd_bind_one (threadGet_eq _ hkt3)] - have hc : (false = true ∨ xt3.tcbFault ≠ none) := Or.inr hf3 - simp only [hc, ↓reduceIte] - rw [if_neg hcond, nd_bind_one (Notif.setThreadState_eq _ hkt3), nd_bind_one (Notif.setThreadState_eq _ hkd3')] - rfl - -/-- The spec's `send_ipc` of a faulted sender (`call = false`) to a waiting -receiver `d` with a reply object `r`, the grant or grant-reply right: the -reply push (EpCall's `sendIpc_call_eq` for the fault branch). -/ -theorem sendIpc_faultPush_eq {σ : State Unit} {t e d : ObjRef} {q : List ObjRef} {don : Bool} - (hk : σ.kheap e = some (.endpoint (.recvEP (d :: q)))) {xd : Tcb} (hkd : σ.kheap d = some (.tcb xd)) - (hde : d ≠ e) {e' r : ObjRef} {dd : ReceiverPayload} - (hst : xd.tcbState = .blockedOnReceive e' (some r) dd) (blk : Bool) (badge : Badge) (g gr : Bool) - (hg : g = true ∨ gr = true) {σ2 σ3 σ4 : State Unit} - (hT : doIpcTransfer (Z := Unit) t (some e) badge g d (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))) = - ({((), σ2)}, False)) - (hU : NonDet.maybeM (replyUnlinkTcb (Z := Unit) d) (some r) σ2 = ({((), σ3)}, False)) - {xt3 x3 : Tcb} (hkt3 : σ3.kheap t = some (.tcb xt3)) (hkd3 : σ3.kheap d = some (.tcb x3)) - (hPush : replyPush (Z := Unit) t d r don σ3 = ({((), σ4)}, False)) {x4 : Tcb} - (hkd4 : σ4.kheap d = some (.tcb x4)) (hf3 : xt3.tcbFault ≠ none) : - sendIpc (Z := Unit) blk false badge g gr don t e σ = - specWakeTailE d (stsAct (updK σ4 d (.tcb { x4 with tcbState := .running })) d) := by - have hkd1 : (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))).kheap d = some (.tcb xd) := by - simp [hde, hkd] - unfold sendIpc - rw [nd_bind_one (getEndpoint_eq hk)] - cases blk <;> dsimp only <;> - · rw [nd_bind_one (tcbEpDequeue_eq hk (by simp [Endpoint.epQueue])), nd_bind_one (getThreadState_eq hkd1), hst] - dsimp only - rw [nd_pure_bind', nd_bind_one hT, nd_bind_one hU, nd_bind_one (getTcbObjRef_eq _ hkd3), - nd_bind_one (threadGet_eq _ hkt3)] - have hg' : (g = true ∨ gr = true) ∧ (some r : Option ObjRef) ≠ none := ⟨hg, by simp⟩ - have hc : (false = true ∨ xt3.tcbFault ≠ none) := Or.inr hf3 - simp only [hc, ↓reduceIte, hg', the] - rw [if_pos ⟨trivial, by simp⟩] - rw [nd_bind_one hPush, nd_bind_one (Notif.setThreadState_eq _ hkd4)] - rfl - -end SpecF - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} - -/-- **`do_ipc_transfer` of a cap-faulted sender to a receiver without a -receive buffer**, on `SRN (SRS (SRT … SRE))` with `IpcBufCapOK` at the state -(EpFaultNone's `do_ipc_transfer_faultN` on XTopJointSendRecv's -`epHyps_buf`/`epBufHyps_buf`; the spec's outcome -`doIpcTransfer_capF_eq`). -/ -theorem do_ipc_transfer_capFJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} - {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP : EPlaced T E R B) - (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) - (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) - (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) - (hOK : Endp.IpcBufCapOK σ) - {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} - (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {cf : Fl4Spec.ObjRef} {rp : Bool} - {lf : Fl4Spec.LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) - (hrb : Endp.ipcBufOf true xr = none) (ep badge : U64) (grant : Bool) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => - Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - ({((), Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)))}, False) ∧ - EpStateRel T E R B (L.mem s') (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv))) ∧ - (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' - (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv))) ∧ - Endp.IpcBufCapOK (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)))) ∧ - Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ⦄ := by - have hspec := doIpcTransfer_capF_eq hks hkr hf hrb (some ep.bv) badge.bv grant - refine WP.spec_mono (do_ipc_transfer_faultN (ar := arI) (epHyps_buf hHE) - (epBufHyps_buf (st := st) (th := th) (cr := cr) (N := N) (T := T) (C := C) (E := E) (R := R) (B := B) (c := c)) - hP s a σ hR ⟨hSR.1, hOK⟩ hs hr hne hks hkr hf trivial hrb ep badge grant) ?_ - rintro s' ⟨σ', h1, h2, h3, h4, -⟩ - have e : σ' = Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)) := - (congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (h1.symm.trans hspec)))) - subst e - exact ⟨hspec, h2, h3, h4⟩ - -/-! ## The cap-fault transfer into a receive buffer -/ - -theorem updK_setUm_updK (σ0 : Fl4Spec.State Unit) (r : Fl4Spec.ObjRef) (o1 o2 : Fl4Spec.KernelObject) - (m : Fl4Spec.Word → Fl4Spec.Word8) : - Notif.updK (Endp.setUm (Notif.updK σ0 r o1) m) r o2 = Notif.updK (Endp.setUm σ0 m) r o2 := by - unfold Notif.updK Endp.setUm - simp only [Function.update_idem] - try rfl - -/-- `set_mr` of word `i < 127` into a receiver with a buffer at `rw`: the -receiver's registers or its buffer words. -/ -theorem set_mr_rgB {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw i v : U64} (hr : rcv ∈ T) - (hrw0 : rw ≠ 0#u64) (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hi : i.val < 127) - (h : P1.WritesIn st s0 s (XferBW T rw)) : - msg.set_mr st s rcv rw i v ⦃ r => P1.WritesIn st s0 r.2 (XferBW T rw) ⦄ := by - unfold msg.set_mr - split - · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ - refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ - simp only [lift, bind_ok, WP.spec_ok] - exact (h.trans w2).mono fun b hb => hb.elim id Or.inl - · have hb : (rw != 0#u64) = true := by simpa using hrw0 - simp only [hb, ↓reduceIte, lift, bind_ok] - have hv : (core.num.U64.wrapping_add i 1#u64).val = i.val + 1 := wadd_val i 1 (by omega) _ rfl - refine WP.spec_bind (Endp.msg.buf_set.spec s rw _ v) ?_ - rintro s1 rfl - simp only [WP.spec_ok] - exact (h.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => (⟨_, by omega, hb'⟩ : RBufW rw b))).mono - fun b hb' => hb'.elim id Or.inr - -theorem set_mrs_lookup_failure_rgB {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw off : U64} - {lf : error.LookupFault} (hr : rcv ∈ T) (hrw0 : rw ≠ 0#u64) - (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hoff : off.val ≤ 3) - (h : P1.WritesIn st s0 s (XferBW T rw)) : - faults.set_mrs_lookup_failure st s rcv rw lf off ⦃ r => P1.WritesIn st s0 r.2 (XferBW T rw) ⦄ := by - unfold faults.set_mrs_lookup_failure - refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ - refine WP.spec_bind (set_mr_rgB (v := i) (i := off) hT hr hrw0 hal (by omega) h) ?_ - rintro ⟨i1, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - split - · exact (WP.spec_ok _).2 h1 - · try simp only [lift, bind_ok] - exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 3 (by omega) _ rfl]; omega) h3 - -/-- **`do_ipc_transfer`'s footprint, a cap-faulted sender and a receiver -with a buffer at `rw`**: the receiver's registers and its buffer words. -/ -theorem do_ipc_transfer_capF_rgB {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) (a : A) - (ep badge : U64) (grant : Bool) {rw : U64} (hrw0 : rw ≠ 0#u64) - (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) - (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = rw ⦄) - (hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' (XferBW T rw) ⦄ := by - have hS : P0.StoreTotal st := L.total - unfold ipc.do_ipc_transfer - refine WP.spec_bind hb ?_ - rintro rb rfl - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ft rfl - rw [hty, if_neg (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] - unfold ipc.do_fault_transfer - refine WP.spec_bind (Pₘ := fun r : U64 × S => P1.WritesIn st s r.2 (XferBW T rb)) ?_ ?_ - · unfold faults.set_mrs_fault - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ty rfl - refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ - rw [if_pos hty] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal - (by rw [show (0#u64 : U64).val = 0 from rfl]; omega) (P1.WritesIn.refl s _)) ?_ - rintro ⟨_, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [show (1#u64 : U64).val = 1 from rfl]; omega) h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [show (2#u64 : U64).val = 2 from rfl]; omega) h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ - exact set_mrs_lookup_failure_rgB hT hr hrw0 hal (by rw [show (3#u64 : U64).val = 3 from rfl]) h3 - rintro ⟨sent, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ - refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ - refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 (XferBW T rb)) ?_ - fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr - (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => (h3.trans w4).mono fun b hb => hb.elim id Or.inl - unfold msg.set_msg_info - exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => - WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) - fun s4 w4 => (h1.trans w4).mono fun b hb => hb.elim id Or.inl - -set_option maxHeartbeats 16000000 in -/-- **The transfer step of a cap-faulted sender's `send_ipc` to a waiting -receiver, with or without a receive buffer** (XTopJointXferB's `xferStepJ` -for the fault transfer): on `IRel` by `do_ipc_transfer_capFJ` (no buffer) or -EpFaultMore's `do_ipc_transfer_fault` (a buffer; the spec's outcome by -`doFaultTransfer_eq`), the footprint `XferRegW ∪ RcvBufW` -(`do_ipc_transfer_capF_rg`, `do_ipc_transfer_capF_rgB`), P1's hole by -`xfer_all` or `blkX_bufw`. -/ -theorem xferFaultStepJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} - {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP0 : Ipc.IPlaced N T E R B) (hP : EPlaced T E R B) - (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) - (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) - (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) - (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover T B σ) - {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} - (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {cf : Fl4Spec.ObjRef} {rp : Bool} - {lf : Fl4Spec.LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) - (ep badge : U64) (grant : Bool) - {T1 Cs1 Ω Sg Rp Scs Nt Ac1 X : Set U64} {H1 : P1.Heap} {Zb : U64 → Nat} {Q : U64 → U64 → List U64} - {Rq : U64 → List U64} (hT1 : P1.TcbPlaced T1) (hr1 : rcv ∈ T1) - (h : P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s Q Rq) (hB : P1.BoundInv st T1 Ac1 s) - (hX : P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s) (hS : P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s) (hSg : P1.SgOK st Ω Sg s) - (hU : ∀ b, RcvBufW xr b → P1.OutsideObjs st T1 Cs1 s b ∧ - (∀ e, (H1 e = some .ep ∨ H1 e = some .ntfn) → b.val + 8 ≤ e.val ∨ e.val + 16 ≤ b.val) ∧ b ∉ Sg) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => ∃ (x' : Fl4Spec.Tcb) - (um : Fl4Spec.Word → Fl4Spec.Word8), - Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - ({((), Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))}, False) ∧ x' = { xr with tcbArch := x'.tcbArch } ∧ - EpStateRel T E R B (L.mem s') (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ - (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' - (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ - Endp.IpcBufCapOK (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))) ∧ - Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ∧ - P1.WritesIn st s s' (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) ∧ - P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s' Q Rq ∧ P1.BoundInv st T1 Ac1 s' ∧ P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s' ∧ - P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s' ∧ P1.SgOK st Ω Sg s' ∧ - (∀ y ∈ T1, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → - L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) ⦄ := by - have hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault := by - have hfr := (hR.at_tcb hs hks).faultR - unfold FaultRel at hfr; rw [hf] at hfr; rw [hfr.1]; unfold fl4_abi.consts.fault.CapFault; rfl - obtain ⟨⟨⟨G, hBt⟩, hBw⟩, -⟩ := hSR.1.1 - have hlb := lookup_buf_full s σ hBt.2.1.1 hBt.2.1.2.1 (Ipc.RelTopB.tcbT hBt hkr) hkr hOK true - cases hrb : Endp.ipcBufOf true xr with - | none => - have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄ := WP.spec_mono hlb fun w hw => hw.1.2 hrb - refine WP.spec_mono (WP.spec_and (do_ipc_transfer_capFJ hP hHE s a σ hR hSR hOK hs hr hne hks hkr hf hrb - ep badge grant) (do_ipc_transfer_capF_rg (arI := arI) hT1 hr1 s a ep badge grant hlk hty)) ?_ - rintro s2 ⟨⟨e2, hR2, hS2, hA2⟩, w2⟩ - obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2, -⟩ := - P1.xfer_all h hB hX hS hSg (U := ∅) (fun b hb => absurd hb (Set.notMem_empty _)) - (w2.mono fun b hb => P1.XferRegW.foot hb) - exact ⟨fxTcb xr xs cf rp lf badge.bv, σ.machineState.underlyingMemory, e2, fxTcb_eqA _ _ _ _ _ _, hR2, hS2, - hA2, w2.mono fun b hb => Or.inl hb, h2, hB2, hX2, hS2', hSg2, f2⟩ - | some p => - obtain ⟨x0, hk0, hbw⟩ := hBw.bw rcv hr - rw [hkr] at hk0; cases hk0 - have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = ⟨p⟩ ⦄ := WP.spec_mono hlb fun w hw => by - have hwb : w.bv = p := hw.2 hbw p hrb - rw [← hwb] - have hrw0 : (⟨p⟩ : U64) ≠ 0#u64 := by - obtain ⟨w0, -, hw0⟩ := spec_exists hlb - have hwb : w0.bv = p := hw0.2 hbw p hrb - intro e - have : w0 = 0#u64 := by rw [← e, ← hwb] - rw [hw0.1.1 this] at hrb; cases hrb - have hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA ⟨p⟩ i) := fun i hi => - (hP.balign _ (hBC rcv hr xr true p hkr hrb ⟨p⟩ rfl i hi)).1 - have hBm := epBufMapHyps_bufC (st := st) (th := th) (cr := cr) (C := C) (c := c) hP0 - obtain ⟨rw1, -, hrw1, hmr⟩ := spec_exists (hBm.lookupMap s σ rcv xr true p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb) - have hu := hBm.frame s σ rcv xr p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb - have hal' : ∀ q ∈ mrPairs (Endp.capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf), (bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (bufAddr p q.1) σ := by - intro q hq - have := (List.of_mem_zip hq).1 - simp at this - exact ⟨bufAddr_aligned hP hmr _, hu _ (by omega)⟩ - have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv (some p) σ := by - unfold Fl4Spec.doIpcTransfer - rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] - have hspec := hspec0.trans (doFaultTransfer_eq hks hkr hf (makeFaultMsg_cap hks cf rp lf) p hal' badge.bv) - refine WP.spec_mono (WP.spec_and (Endp.do_ipc_transfer_fault (ar := arI) (epHyps_bufC hHE T) hBm hP s a σ hR ⟨⟨hSR.1, hOK⟩, hBC⟩ - hs hr hne hks hkr hf trivial hrb ep badge grant) - (do_ipc_transfer_capF_rgB (arI := arI) hT1 hr1 s a ep badge grant hrw0 hal hlk hty)) ?_ - rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ - have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) - simp only [mrState, updK_setUm_updK] at eσ - subst eσ - have hW : P1.WritesIn st s s2 (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) := - w2.mono fun b hb => hb.imp_right fun h' => ⟨p, hrb, h'⟩ - obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2⟩ := blkX_bufw (l := rbList ⟨p⟩) h hB hX hS hSg - (fun b hb => hU b ⟨p, hrb, mem_rbList.1 hb⟩) (w2.mono fun b hb => hb.imp_right mem_rbList.2) - exact ⟨_, _, e2, rfl, hR2, hS2.1, hA2, hW, h2, hB2, hX2, hS2', hSg2, f2⟩ - -end - - /-! ## The fault send to a waiting receiver at `J` -/ theorem ipcBufCapOK_updT {σ : Fl4Spec.State Unit} {t : Fl4Spec.ObjRef} {x y : Fl4Spec.Tcb} (h : Endp.IpcBufCapOK σ) @@ -659,6 +31,46 @@ theorem ipcBufCapOK_updT {σ : Fl4Spec.State Unit} {t : Fl4Spec.ObjRef} {x y : F rw [← e2] exact Endp.inUserFrame_updK hk (fun sz e => by cases e) _ (h3 k hk') +/-! ## The native spec steps of the fault send (mmuAD gen 42b67) -/ + +section +variable {σ σ1 σ2 σ3 : Fl4Spec.State Unit} + +theorem zvk_ciSt {c : Fl4Spec.ObjRef} {x : Fl4Spec.Tcb} (hk : σ.kheap c = some (.tcb x)) : ZvK σ (ciSt σ c x) := + (zvk_upd (o' := .tcb { x with tcbState := .inactive }) hk rfl (fun _ e => by cases e) (fun _ e => by cases e) + (fun y e hy => by simp only [Fl4Spec.KernelObject.tcb.injEq] at e; subst e; simp at hy)).trans + (ZvK.of_kheap (by unfold ciSt; exact Notif.stsAct_kheap _ _)) + +theorem zvk_pushSt {t r : Fl4Spec.ObjRef} {xr : Fl4Spec.Reply} {xt : Fl4Spec.Tcb} + (hkr : σ.kheap r = some (.reply xr)) (hkt : σ.kheap t = some (.tcb xt)) (htr : t ≠ r) : + ZvK σ (Endp.pushSt σ t r xr xt) := by + have h1 : ZvK σ (Notif.updK σ r (.reply { xr with replyTcb := some t })) := + zvk_upd hkr rfl (fun _ e => by cases e) (fun _ e => by cases e) (fun y e _ => by cases e) + have hkt' : (Notif.updK σ r (.reply { xr with replyTcb := some t })).kheap t = some (.tcb xt) := by + simp [Notif.updK, htr, hkt] + have h2 := zvk_upd (o' := .tcb { xt with tcbState := .blockedOnReply r }) hkt' rfl (fun _ e => by cases e) + (fun _ e => by cases e) (fun y e hy => by simp only [Fl4Spec.KernelObject.tcb.injEq] at e; subst e; simp at hy) + exact (h1.trans h2).trans (ZvK.of_kheap (Notif.stsAct_kheap _ _)) + +/-- **The caller's `Inactive` (`ciSt`) is a native step** (`natK_tcbW`). -/ +theorem natK_ciSt {c : Fl4Spec.ObjRef} {x : Fl4Spec.Tcb} (hk : σ.kheap c = some (.tcb x)) : NatK σ (ciSt σ c x) := + natK_tcbW hk (by unfold ciSt; exact Notif.stsAct_kheap _ _) fun h => by simp at h + +/-- **The reply push's spec step (`pushSt`) is a native step** (the reply then the caller, in place). -/ +theorem natK_pushSt {t r : Fl4Spec.ObjRef} {xr : Fl4Spec.Reply} {xt : Fl4Spec.Tcb} + (hkr : σ.kheap r = some (.reply xr)) (hkt : σ.kheap t = some (.tcb xt)) (htr : t ≠ r) : + NatK σ (Endp.pushSt σ t r xr xt) := by + have h1 : NatK σ (Notif.updK σ r (.reply { xr with replyTcb := some t })) := + natK_kh (R := fun _ o o' => ZvChg o o') (fun _ _ _ h => h) fun p => by + by_cases e : p = r + · subst e; exact Or.inr ⟨_, .reply { xr with replyTcb := some t }, hkr, by simp [Notif.updK], zvChg_reply⟩ + · exact Or.inl (by simp [Notif.updK, e]) + have hkt' : (Notif.updK σ r (.reply { xr with replyTcb := some t })).kheap t = some (.tcb xt) := by + simp [Notif.updK, htr, hkt] + exact h1.trans (natK_tcbW hkt' (Notif.stsAct_kheap _ _) fun h => by simp at h) + +end + section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} @@ -679,10 +91,10 @@ reply unlink, then the caller `Inactive` on `IRel` (its queue bits clear by release queue, `CurInv.notRel`), the receiver `Running`, `JAtZ` by `JAtZ.wake_postCI` (the spec's two state changes swapped, `ciSt_swap`), the tail `JAtZ.sendTailJ`; the spec's outcome `sendIpc_callInactive_eq`. -/ -theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.sendFaultIJG (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) - (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} - (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hrn : Fl4Spec.runnable xt.tcbState = true) {f : Fl4Spec.Fault} + (hft : xt.tcbFault = some f) (hnt : ∀ b, f ≠ .timeout b) (hct : σ.curThread = t.bv) (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} @@ -692,7 +104,7 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none) : endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by have hI := J.xtop.irelK J.ks J.buf have hP0 := J.ip have hP := hP0.e @@ -791,8 +203,8 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 exact Ipc.RelTopB.tcbT hB0' hkd have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft e badge g + refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 + (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 @@ -949,9 +361,9 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE rintro s3 ⟨σ3, x3, X3, hU, hR3, hS3, hkt3, hkd3, hrb3, hns3, hsc3, hq3, hW3, F3, Fr3, IK3, SK3, hct3, hact3, h3, hB3, hX3, hS3', hSg3, hXc3, hx3, hnr3⟩ have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) = fl4_abi.consts.fault.CapFault := by - have hfr := hxt3.faultR - unfold FaultRel at hfr; rw [hft] at hfr; rw [hfr.1]; unfold fl4_abi.consts.fault.CapFault; rfl + have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by + have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) + rw [hft] at h00; cases h00 have hks3 : L.ksb s3 = L.ksb s := hW3.1 -- the caller's facts for its `Inactive` have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) @@ -983,7 +395,7 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE ?_ ?_ · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ rintro i1 rfl - rw [hty3, if_pos (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] + rw [if_pos (bne_iff_ne.2 hty3)] by_cases hi : (L.mem s (tReplyA d') != 0#u64) = true · rw [if_pos hi] have hgg : g = false ∧ gr = false := by @@ -1077,16 +489,18 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE ⟨fun u hu => (by rw [hcn] at hu; cases hu), ciSt_idleOK hidT (Fr5.idleOK J.act.2)⟩ have hrun5 : CurRunM (ciSt σa t.bv xt) := Or.inl (by rw [hcn]; intro h; cases h) have hcD : ∀ q ∈ D, q.bv ≠ t.bv := J.notDead ht hkt (by have := runnable_code hrn; omega) - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot + obtain ⟨su, umu, Ju, hWu, hFu, -, -, Fu⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot have hIu := Ju.xtop.irelK Ju.ks Ju.buf have htD := Ju.not_dead_of_st hdT hkd (by rw [hstd]; simp [tsCode]) have hRR : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' + fun q' hq'' xr hx' hxt' => Ju.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd (by rw [hstd]; rfl) have hF : IFrame (L := L) Z.th su s5 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb - obtain ⟨V', J5⟩ := Ju.wake_postCI hkta hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) I5' B5' hAI5 + have J5 := Ju.wake_postCI hkta hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) I5' B5' hAI5 (Or.inl hcn) hrun5 hRR htD hcD ⟨d', hdT, rfl⟩ + have N5 := NatFoot.ofW Ju.xtop hWu (fun b hb => CnW.oobj Ju.xtop.fin.1.1.1 hb) (fun b hb => Ju.cnW_nv hb) + (fun b hb => Ju.cnW_nh hb) ((natK_dwfr (DWFr.ofUm (DWFr.ofCFr Fr5) umu)).trans (natK_ciSt hkta)) -- the tail have G := (ciSt_skD (σ := σa) (c := t.bv) (x := xt)) have hk5 : (ciSt σa t.bv xt).kheap d'.bv = some (.tcb x5) := by @@ -1119,11 +533,46 @@ theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Endp.specWakeTailE d'.bv (ciSt σa t.bv xt) := by rw [hspec]; exact congrArg _ heq5 refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ + rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7, F7⟩ simp only at ha7 subst ha7 - exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ + exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, + ⟨Z.vs, _, _, _, J7, J.natTrans Fu (Ju.natTrans N5 F7)⟩⟩ + +/-- The cap-fault instance of the shared endpoint send. -/ +theorem JAtZB.sendFaultIJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr don : Bool) + (hno : (g = false ∧ gr = false) ∨ + ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none) : + endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.sendFaultIJG ht hkt hrn hft (fun _ h => by cases h) hct hres hti hnq he hk blk badge g gr don hno +/-- `JAtZB.sendFaultIJ` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtZ.sendFaultIJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr don : Bool) + (hno : (g = false ∧ gr = false) ∨ + ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep = none) : + endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.sendFaultIJ (J := J.toB) (ht := ht) (hkt := hkt) (hrn := hrn) (hft := hft) (hct := hct) (hres := hres) (hti := hti) (hnq := hnq) (he := he) (hk := hk) (blk := blk) (badge := badge) (g := g) (gr := gr) (don := don) (hno := hno)) + fun _ ⟨z, hz, h⟩ => ⟨z, hz, h.toJAt J⟩ set_option maxHeartbeats 64000000 in /-- **A cap-faulted sender's `send_ipc` to a waiting receiver at `J` that @@ -1136,10 +585,10 @@ then `reply_push` on `IRel` (`reply_push_iG`, no donation), P1's `reply_push.ipc` and `reply_push.nd`, the receiver `Running`, `JAtZ` by `JAtZ.wake_postGR` at `pushSt` (`ps_swap`), the tail `JAtZ.sendTailJ`; the spec's outcome `sendIpc_call_eq`. -/ -theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.sendFaultPJG (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) - (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} - (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hrn : Fl4Spec.runnable xt.tcbState = true) {f : Fl4Spec.Fault} + (hft : xt.tcbFault = some f) (hnt : ∀ b, f ≠ .timeout b) (hct : σ.curThread = t.bv) (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} @@ -1150,7 +599,7 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H (hnd : don = false ∨ ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none) : endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by have hI := J.xtop.irelK J.ks J.buf have hP0 := J.ip have hP := hP0.e @@ -1249,8 +698,8 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 exact Ipc.RelTopB.tcbT hB0' hkd have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft e badge g + refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 + (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 @@ -1379,9 +828,9 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H hX3.noref hdta (by rw [e3']; exact P1.inactive_ne.1) (by rw [e3']; exact P1.inactive_ne.2) have F3 := footW_trans (footW_trans (footW_of F1) F2) (footW_of fu3) have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) = fl4_abi.consts.fault.CapFault := by - have hfr := hxt3.faultR - unfold FaultRel at hfr; rw [hft] at hfr; rw [hfr.1]; unfold fl4_abi.consts.fault.CapFault; rfl + have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by + have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) + rw [hft] at h00; cases h00 have hks3 : L.ksb s3 = L.ksb s := hW3'.1 -- the caller's and the receiver's words at `s3` have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) @@ -1503,7 +952,7 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H sched.set_blocked_on_reply st (L.wr s3 (P1.rTcbA w) t) t w = ok r.1) ?_ ?_ · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ rintro i1 rfl - rw [hty3, if_pos (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] + rw [if_pos (bne_iff_ne.2 hty3)] rcases hg with rfl | rfl · simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true]; exact hPush · cases g <;> simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true] <;> exact hPush @@ -1603,16 +1052,16 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H rw [hb', d1, optRef_zero] at hxr' cases hxr' have hkq : ∀ q ∈ D, σ'.kheap q.bv = σa.kheap q.bv := fun q hq => ps_ko (hcD q hq) (hwD q hq) - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot + obtain ⟨su, umu, Ju, hWu, hFu, -, -, Fu⟩ := J.bufRebaseX hdT hdth hkd hW5' hfoot have hIu := Ju.xtop.irelK Ju.ks Ju.buf have hRR : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' + fun q' hq'' xr hx' hxt' => Ju.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd (by rw [hstd]; rfl) have hF : IFrame (L := L) Z.th su s5 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb have ho : ∀ {q : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject}, (∀ x, o ≠ .tcb x) → (∀ x, o ≠ .reply x) → (σ'.kheap q = some o ↔ σa.kheap q = some o) := fun h1 h2 => ps_oth hkta hkwa hwt h1 h2 - obtain ⟨V', J5⟩ := Ju.wake_postGR hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) ps_skD + have J5 := Ju.wake_postGR hIR hF hWu hblk hFu (DWFr.ofUm (DWFr.ofCFr Fr5) umu) ps_skD (ps_ksub hkta hkwa hwt) (ps_szKeep hkta hkwa hwt) (ps_ykeep hkta hkwa hwt) (ps_mcpKeep hkta hkwa hwt) (ps_bufKeep hkta hkwa hwt) (fun d _ h => ps_recvB hkta hkwa hwt h) (ps_ksz hkta hkwa hwt) (ps_kback hkta hkwa hwt) (ps_ipcFr hkta hkwa hwt) (ps_ck hkta hkwa hwt) (fun d _ h => ps_free hkta hkwa hwt h) @@ -1645,10 +1094,51 @@ theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Endp.specWakeTailE d'.bv σ' := by rw [hspec]; exact congrArg _ heq5 refine WP.spec_mono (J5.sendTailJ hdT hk5 rfl hnr5 hact5 hti5 htc5) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ + rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7, F7⟩ simp only at ha7 subst ha7 - exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ + have N5 := NatFoot.ofW Ju.xtop hWu (fun b hb => CnW.oobj Ju.xtop.fin.1.1.1 hb) (fun b hb => Ju.cnW_nv hb) + (fun b hb => Ju.cnW_nh hb) + ((natK_dwfr (DWFr.ofUm (DWFr.ofCFr Fr5) umu)).trans (natK_pushSt hkwa hkta (fun e0 => hwt e0.symm))) + exact ⟨((), σ7), by rw [hspec', h7]; exact Set.mem_singleton _, + ⟨Z.vs, _, _, _, J7, J.natTrans Fu (Ju.natTrans N5 F7)⟩⟩ + +/-- The cap-fault instance of the shared endpoint send. -/ +theorem JAtZB.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr don : Bool) + (hg : g = true ∨ gr = true) + (hrepn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none) + (hnd : don = false ∨ ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none) : + endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.sendFaultPJG hAT ht hkt hrn hft (fun _ h => by cases h) hct hres hti hnq he hk blk badge g gr don hg hrepn hnd + +/-- `JAtZB.sendFaultPJ` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtZ.sendFaultPJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr don : Bool) + (hg : g = true ∨ gr = true) + (hrepn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none) + (hnd : don = false ∨ ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none) : + endpoint.send_ipc st arI s a blk false badge g gr don t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr don t.bv e.bv σ).1, + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.sendFaultPJ (hAT := hAT) (J := J.toB) (ht := ht) (hkt := hkt) (hrn := hrn) (hft := hft) (hct := hct) (hres := hres) (hti := hti) (hnq := hnq) (he := he) (hk := hk) (blk := blk) (badge := badge) (g := g) (gr := gr) (don := don) (hg := hg) (hrepn := hrepn) (hnd := hnd)) + fun _ ⟨z, hz, h⟩ => ⟨z, hz, h.toJAt J⟩ set_option maxHeartbeats 64000000 in /-- **A call to a waiting receiver at `J` that pushes a reply and donates @@ -1661,10 +1151,10 @@ XTopJointPushDon's `JAtZ.pushDonJ`; the receiver `Running` by XTopJointStsI's `JAtZ.stsIJ` (released: the caller's SC, `Inv.rd`), the tail `JAtZ.sendTailJ`; the spec's outcome `sendIpc_call_eq` with `replyPush_don_eq`/`pd_eq`. -/ -theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.sendFaultPDJG (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) - (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} - (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hrn : Fl4Spec.runnable xt.tcbState = true) {f : Fl4Spec.Fault} + (hft : xt.tcbFault = some f) (hnt : ∀ b, f ≠ .timeout b) (hct : σ.curThread = t.bv) (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} @@ -1675,7 +1165,7 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H (hxdn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext = none) : endpoint.send_ipc st arI s a blk false badge g gr true t e ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr true t.bv e.bv σ).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by have hI := J.xtop.irelK J.ks J.buf have hP0 := J.ip have hP := hP0.e @@ -1774,8 +1264,8 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H obtain ⟨⟨⟨G0, hB0'⟩, -⟩, -⟩ := hS0.1.1 exact Ipc.RelTopB.tcbT hB0' hkd have hUd := J.rbufU hdT hdth hkd - refine WP.spec_bind (xferFaultStepJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 - (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft e badge g + refine WP.spec_bind (xferFaultStepGJ hP0 hP (hH.epHyps hP0) s1 a σ1 hR1 hS1 hOK1 + (bufCover_epStep (J.xferH).2.1 (EpStep.ep hk)) ht hdT htd hkt1 hkd1 hft (faultOK_nt (L := L) s1 t xt hnt) e badge g hTP hdH h1 hB1 hX1 hS1' hSg1 (fun b hb => ⟨(hUd b hb).1.ksb hW1.1, (hUd b hb).2⟩)) ?_ rintro s2 ⟨x2, um2, e2, hx2, hR2, hS2, hA2, w2, h2, hB2, hX2, hS2'', hSg2, f2⟩ set σ2 := Notif.updK (Endp.setUm σ1 um2) d'.bv (.tcb x2) with hσ2 @@ -1904,9 +1394,9 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H hX3.noref hdta (by rw [e3']; exact P1.inactive_ne.1) (by rw [e3']; exact P1.inactive_ne.2) have F3 := footW_trans (footW_trans (footW_of F1) F2) (footW_of fu3) have hxt3 := hR3.at_tcb ht hkt3 - have hty3 : L.mem s3 (tFaultA t) = fl4_abi.consts.fault.CapFault := by - have hfr := hxt3.faultR - unfold FaultRel at hfr; rw [hft] at hfr; rw [hfr.1]; unfold fl4_abi.consts.fault.CapFault; rfl + have hty3 : L.mem s3 (tFaultA t) ≠ fl4_abi.consts.fault.NullFault := fun e0 => by + have h00 := hxt3.fault0.1 (by rw [e0]; unfold fl4_abi.consts.fault.NullFault; rfl) + rw [hft] at h00; cases h00 have hks3 : L.ksb s3 = L.ksb s := hW3'.1 -- the caller's and the receiver's words at `s3` have hCI : CurInv σ := J.cur.resolve_left (by rw [hres]; intro h; cases h) @@ -2001,7 +1491,7 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H cases hxr' have hRR : ∀ q' ∈ Z.R, ∀ xr, σ.kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem s (rNextA q') = 0#u64 ∧ L.mem s (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D s _ σ J q' hq'' xr d'.bv xd hx' hxt' hkd + fun q' hq'' xr hx' hxt' => J.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd (by rw [hstd]; rfl) have hrib3 : RelIfBound σ3 d'.bv := Ipc.RelIfBound.of_keep (J.inv.rd d'.bv xd hkd (Or.inr (Or.inr (Or.inr ⟨_, _, _, hstd⟩)))) SK3 @@ -2055,9 +1545,10 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H -- the push: link and block (`J` again), then the donation at `J` have hPush : ipc.reply_push st arI s3 a t d' w true ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv true σ3 = ({((), σ')}, False) ∧ - (σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 a σ') ⦄ := by - refine reply_push_iC (don := true) (P := fun s' σ' => σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), - JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D s' a σ') + (σ' = σD → ∃ (Lst' : U64 → List U64), JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s σ r.1 σ') ⦄ := by + refine reply_push_iC (don := true) (P := fun s' σ' => σ' = σD → ∃ (Lst' : U64 → List U64), + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ∧ NatFoot (L := L) Z s σ s' σ') hH hP0 hP s3 a σ3 hR3 hS3 ht hkt3 hkd3 hqt3 hns3 hwR hkr3 (fun _ => hdT) (fun s' _ _ e0 => ?_) ?_ · exfalso have h1 : σD.kheap t.bv = some (.tcb xtP) := by rw [← e0]; exact hktP @@ -2102,11 +1593,11 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H (P1.Heap.scBits H) (P1.EH H) s b ∨ RcvBufW xd b) := footW_trans (footW_trans F3 (footW_of f1)) (footW_of f4) have hIR4 := IpcRel.ofSRN hR4 hS4 - obtain ⟨su, umu, Ju, hWu, hFu, -, -⟩ := J.bufRebaseX hdT hdth hkd hW4' hfoot4 + obtain ⟨su, umu, Ju, hWu, hFu, -, -, Fu⟩ := J.bufRebaseX hdT hdth hkd hW4' hfoot4 have hIu := Ju.xtop.irelK Ju.ks Ju.buf have hRRu : ∀ q' ∈ Z.R, ∀ xr, (Endp.setUm σ umu).kheap q'.bv = some (.reply xr) → xr.replyTcb = some d'.bv → Detached Z.C Lst q' ∧ L.mem su (rNextA q') = 0#u64 ∧ L.mem su (rPrevA q') = 0#u64 := - fun q' hq'' xr hx' hxt' => recvReplyHyp_holds Z Ac Lst D su _ (Endp.setUm σ umu) Ju q' hq'' xr d'.bv xd hx' + fun q' hq'' xr hx' hxt' => Ju.recvReplyB q' hq'' xr d'.bv xd hx' hxt' hkd (by rw [hstd]; rfl) have hF4 : IFrame (L := L) Z.th su s4 := IRel.iframe_of hIu hWu fun b hb => CnW.oobj hIu.2.2.1 hb have hblk4 : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) @@ -2119,7 +1610,7 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H have hkq : ∀ q ∈ D, σP.kheap q.bv = σ3.kheap q.bv := fun q hq => ps_ko (hcD q hq) (hwD q hq) have ho : ∀ {q : Fl4Spec.ObjRef} {o : Fl4Spec.KernelObject}, (∀ x, o ≠ .tcb x) → (∀ x, o ≠ .reply x) → (σP.kheap q = some o ↔ σ3.kheap q = some o) := fun h1 h2 => ps_oth hkt3 hkr3 hwt h1 h2 - obtain ⟨V', J4⟩ := Ju.wake_postGR hIR4 hF4 hWu hblk4 hFu (DWFr.ofUm (DWFr.ofCFr Fr3) umu) ps_skD + have J4 := Ju.wake_postGR hIR4 hF4 hWu hblk4 hFu (DWFr.ofUm (DWFr.ofCFr Fr3) umu) ps_skD (ps_ksub hkt3 hkr3 hwt) (ps_szKeep hkt3 hkr3 hwt) (ps_ykeep hkt3 hkr3 hwt) (ps_mcpKeep hkt3 hkr3 hwt) (ps_bufKeep hkt3 hkr3 hwt) (fun d _ h => ps_recvB hkt3 hkr3 hwt h) (ps_ksz hkt3 hkr3 hwt) (ps_kback hkt3 hkr3 hwt) (ps_ipcFr hkt3 hkr3 hwt) (ps_ck hkt3 hkr3 hwt) (fun d _ h => ps_free hkt3 hkr3 hwt h) @@ -2128,23 +1619,29 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H (ps_own hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).own ⟨d', hdT, rfl⟩ J.own)) (ps_off hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).off J.off)) (ps_nsc hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).nsc J.nsc)) (ps_isorted hkt3 hkr3 hwt ((DWFr.ofCFr Fr3).isorted J.isorted)) hRRu htD + have N4 := NatFoot.ofW Ju.xtop hWu (fun b hb => CnW.oobj Ju.xtop.fin.1.1.1 hb) (fun b hb => Ju.cnW_nv hb) + (fun b hb => Ju.cnW_nh hb) + ((natK_dwfr (DWFr.ofUm (DWFr.ofCFr Fr3) umu)).trans (natK_pushSt hkr3 hkt3 (fun e0 => hwt e0.symm))) -- the reply's links at the block obtain ⟨hdet, hn0, hp0⟩ := hRRu w hwR xr hkr hb' obtain ⟨-, -, -, -, k4⟩ := Ju.cnW_keeps hWu refine WP.spec_mono (J4.pushDonJ hAT ht hdT hwR hsC htd hktP hkdP hkwP hkyP rfl hcs hyt hxdn3 rfl rfl hctP hcscP hcnP hnqtP hnqdP hya hdet (by rw [(k4 w hwR).2]; exact hn0) (by rw [(k4 w hwR).1]; exact hp0) htD) ?_ - rintro ⟨s5, a5⟩ ⟨ha5, hsp5, Lst5, J5⟩ + rintro ⟨s5, a5⟩ ⟨ha5, hsp5, Lst5, J5, hW5r, hK5⟩ simp only at ha5 subst a5 - exact ⟨rfl, _, hsp5, fun _ => ⟨V', Lst5, J5⟩⟩ + have N5 := NatFoot.ofW J4.xtop hW5r (fun b hb => RmW.oobj J4.xtop.fin.1.1.1 hb) (fun b hb => J4.rmW_nv hb) + (fun b hb => J4.rmW_nh hb) (natK_tk hK5) + exact ⟨rfl, _, hsp5, fun _ => ⟨Lst5, J5, J.natTrans Fu (Ju.natTrans N4 N5)⟩⟩ refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ ∃ σ', Fl4Spec.replyPush (Z := Unit) t.bv d'.bv w.bv true σ3 = ({((), σ')}, False) ∧ - (σ' = σD → ∃ (V : XVs) (Lst' : U64 → List U64), JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D r.1 a σ')) + (σ' = σD → ∃ (Lst' : U64 → List U64), JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s σ r.1 σ')) ?_ ?_ · refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s3 t) ?_ rintro i1 rfl - rw [hty3, if_pos (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] + rw [if_pos (bne_iff_ne.2 hty3)] rcases hg with rfl | rfl · simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true]; exact hPush · cases g <;> simp only [Bool.false_eq_true, ↓reduceIte, eq_self_iff_true, if_true] <;> exact hPush @@ -2155,7 +1652,7 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H have e5 : σ5' = σD := by have h := hpush.symm.trans hpushE exact congrArg Prod.snd (Set.singleton_injective (congrArg Prod.fst h)) - obtain ⟨V5, Lst5, J5⟩ := hPσ e5 + obtain ⟨Lst5, J5, F5⟩ := hPσ e5 subst e5 -- the receiver runs (`Inactive` with the donated SC) set x4 : Fl4Spec.Tcb := { x3 with tcbSchedContext := some sc.bv } with hx4 @@ -2182,7 +1679,10 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H refine WP.spec_bind (J5.stsIJ hdT (fun h => htD d' h rfl) hk5 rfl .running (by simp [tsCode]) sched.TS_RUNNING (by unfold sched.TS_RUNNING; rfl) (fun _ => hrelD) (P1.sched.set_thread_state.running_blkI (Es := P1.EH H) s5 d' J5.blk hdH hst5)) ?_ - rintro s6 ⟨Lst6, J6⟩ + rintro s6 ⟨Lst6, J6, hW6⟩ + have N6 : NatFoot (L := L) Z s5 σD s6 (stsAct (updK σD d'.bv (.tcb { x4 with tcbState := .running })) d'.bv) := + NatFoot.ofT J5.xtop hW6 (fun b hb => J5.tfoot_nh hb) + (natK_tcbW (y := { x4 with tcbState := .running }) hk5 (Notif.stsAct_kheap _ _) fun h => by simp at h) set x6 : Fl4Spec.Tcb := { x4 with tcbState := .running } with hx6 have hdcD : d'.bv ≠ σD.curThread := by rw [show σD.curThread = t.bv from (@pd_ct σP t.bv d'.bv sc.bv w.bv xtP x3 xwP y n).trans hctP] @@ -2217,11 +1717,48 @@ theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H have hspec := sendIpc_faultPush_eq (don := true) hk hkd hde hstd blk badge.bv g gr hg e2 hU hkt3 hkd3 hpushE hk5 (by rw [hft]; simp) (t := t.bv) refine WP.spec_mono (J6.sendTailJ hdT hk6 rfl hnr6 hact6 hti6 htc6) ?_ - rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7⟩ + rintro ⟨s7, a7⟩ ⟨ha7, σ7, h7, Lst7, J7, F7⟩ simp only at ha7 subst ha7 - exact ⟨((), σ7), by rw [hspec, h7]; exact Set.mem_singleton _, ⟨_, _, _, _, _, _, J7, inferInstance⟩⟩ + exact ⟨((), σ7), by rw [hspec, h7]; exact Set.mem_singleton _, + ⟨Z.vs, _, _, _, J7, J.natTrans F5 (J5.natTrans N6 F7)⟩⟩ +/-- The cap-fault instance of the shared endpoint send. -/ +theorem JAtZB.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr : Bool) + (hg : g = true ∨ gr = true) + (hrepn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none) + (hxdn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext = none) : + endpoint.send_ipc st arI s a blk false badge g gr true t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr true t.bv e.bv σ).1, + JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.sendFaultPDJG hAT ht hkt hrn hft (fun _ h => by cases h) hct hres hti hnq he hk blk badge g gr hg hrepn hxdn + +/-- `JAtZB.sendFaultPDJ` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtZ.sendFaultPDJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + {t : U64} (ht : t ∈ Z.T) {xt : Fl4Spec.Tcb} (hkt : σ.kheap t.bv = some (.tcb xt)) + (hrn : Fl4Spec.runnable xt.tcbState = true) {cf : Fl4Spec.ObjRef} {rp : Bool} {lf : Fl4Spec.LookupFailure} + (hft : xt.tcbFault = some (.capFault cf rp lf)) (hct : σ.curThread = t.bv) + (hres : σ.schedulerAction = .resumeCurThread) (hti : σ.curThread ≠ σ.idleThread) + (hnq : ∀ dm p, t.bv ∉ σ.readyQueues dm p) + {e d : U64} (he : e ∈ Z.E) {q : List Fl4Spec.ObjRef} + (hk : σ.kheap e.bv = some (.endpoint (.recvEP (d.bv :: q)))) + (blk : Bool) (badge : U64) (g gr : Bool) + (hg : g = true ∨ gr = true) + (hrepn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none) + (hxdn : ∀ xd, σ.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext = none) : + endpoint.send_ipc st arI s a blk false badge g gr true t e ⦃ r => + ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) blk false badge.bv g gr true t.bv e.bv σ).1, + JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.sendFaultPDJ (hAT := hAT) (J := J.toB) (ht := ht) (hkt := hkt) (hrn := hrn) (hft := hft) (hct := hct) (hres := hres) (hti := hti) (hnq := hnq) (he := he) (hk := hk) (blk := blk) (badge := badge) (g := g) (gr := gr) (hg := hg) (hrepn := hrepn) (hxdn := hxdn)) + fun _ ⟨z, hz, h⟩ => ⟨z, hz, h.toJAt J⟩ set_option maxHeartbeats 64000000 in /-- **`handle_fault` with an endpoint handler and a waiting receiver at `J`, @@ -2231,37 +1768,26 @@ with or without a receive buffer** (module docstring): XTopJointFaultEp's reply right or no reply object: the sender `Inactive`), `JAtZ.sendFaultPJ` (the reply pushed, no donation: `can_donate` false or the receiver with an SC), `JAtZ.sendFaultPDJ` (the reply pushed and the sender's SC donated). -/ -theorem JAtZ.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.faultRecvJG (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) {ptr bdg : U64} {sd rv g gr : Bool} (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) {d : U64} {q : List Fl4Spec.ObjRef} (hkq : σ.kheap ptr.bv = some (.endpoint (.recvEP (d.bv :: q)))) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - obtain ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩ := hf - obtain ⟨⟨lt, l0, l1⟩, he, -⟩ := spec_exists (encode_lfRel hlf) + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by obtain ⟨hcur, x, hk, hrn⟩ := J.curRunnable hni hct - have hP0 := J.ip have hI := J.xtop.irelK J.ks J.buf have hS := J.xtop.fin.1.1.1 - have hT : TcbPlaced Z.T := hP0.e.tcb - have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 obtain ⟨Q, R, hcq, hs⟩ := hS.lists have hct' : ct = nodeW st s Z.c layout.node.CUR_THREAD := by have h := sched.cur_thread.spec' (L := L) s rw [hct, WP.spec_ok, hcq.cur] at h; exact h have ht : ct ∈ Z.T := by rw [hct']; exact hcq.curT - have hta := hP0.e.tcb ct ht - have htH : ct ∈ P1.Heap.tcbs H := J.zH.1 ct ht - have htD : ct ∉ D := fun h => J.notDead ht hk (by have := runnable_code hrn; omega) ct h rfl have hnq' : ∀ d p, ct.bv ∉ σ.readyQueues d p := by rw [← hcur]; exact hnq - have hC : CurInv σ := J.curInv (by rw [hni.2]; intro e; cases e) - have hnr : ct.bv ∉ σ.releaseQueue := by rw [← hcur]; exact hC.notRel have hti : σ.curThread ≠ σ.idleThread := hni.1 - have hidt : σ.idleThread ≠ ct.bv := fun e => hti (by rw [hcur, e]) -- the handler cap, its endpoint obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb rw [hk] at hk1; cases hk1 @@ -2272,74 +1798,21 @@ theorem JAtZ.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H C have hfh : x.tcbFaultHandler = .endpointCap ptr.bv bdg.bv (rightsOf sd rv g gr) := habs.symm have hAS : AbsSlot Z.th (ct.bv, Fl4Spec.tcbCnodeIndex 3) := ⟨ct, rfl, Or.inr ⟨htcb, 3, by decide, rfl⟩⟩ have hpE : ptr ∈ Z.E := J.slotE hAS hep - obtain ⟨xe, hke, -⟩ := hI.1.ep ptr hpE - have hpt : ptr.bv ≠ ct.bv := fun e => by rw [e, hk] at hke; cases hke - have hHe : H ptr = some .ep := J.zH.2.1 ptr hpE - have hfit := J.kern.heap.fits ptr _ hHe - simp only [P1.HKind.bits] at hfit - have hcov := J.cover_cap (P1.WritesIn.refl s _) hAS.isSlot hep (fun h => by cases h) (ok_inj (phys_eq _).symm) rfl - (range_ep ptr bdg sd rv g gr hfit) fun k hk' => by - rw [hHe] at hk'; cases hk' - exact ⟨by simp only [P1.HKind.bits]; omega, fun z h => by cases h⟩ - -- P1's `CanBlock` of the current thread - obtain ⟨bq, br⟩ := J.curBits ht hnq' hnr - obtain ⟨hna, -⟩ := J.words_of_spec ht (fun u hu => by rw [hni.2] at hu; cases hu) - (fun e => hni.1 (by rw [hcur, e])) - obtain ⟨x0, hk0, hTR⟩ := hI.1.tcb ct ht - rw [hk] at hk0; cases hk0 - have hv : (L.mem s (P1.stA ct)).val = tsCode x.tcbState := by - rw [P1.stA_eq, ← tStA_eq]; exact hTR.st - obtain ⟨hnb, hnrp⟩ := P1.run_word (w := L.mem s (P1.stA ct)) (by rw [hv]; exact runnable_code hrn) - have ha0 : L.actionW s = 0#u64 := by - have h := hS.act - rw [hni.2] at h - unfold P1.LawfulStore.actionW; rw [hcq.cur]; exact h - have hcw : L.curW s = ct := by - apply P1.eq_of_bv - rw [← hcur, hs.curThread] - unfold P1.LawfulStore.curW nodeW; rw [hcq.cur] - have hcbP : P1.CanBlock st (P1.Heap.tcbs H) Ac s ct := by - obtain ⟨⟨Q0, R0, h0⟩, hB0, hX0, hS0, hSg0⟩ := J.blk - refine ⟨htH, hnb, hnrp, bq, br, hna, ?_, ?_⟩ - · intro h - have ei : L.idleW s = nodeW st s Z.c layout.node.IDLE_THREAD := by - unfold P1.LawfulStore.idleW nodeW; rw [hcq.cur] - exact hti (by rw [hcur, hs.idleTh, ← ei, h]) - · exact fun h1 => hB0.sact ct htH (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨ha0, hcw⟩))))) h1 - -- the spec's donation flag is FL4's - obtain ⟨xt6, hkt6, -, -, hsct6, -⟩ := hs.tcb ct ht - rw [hk] at hkt6; cases hkt6 - have hdon : (L.mem s (scA ct) != 0#u64) = decide (x.tcbSchedContext ≠ none) := by - rw [hsct6] - by_cases h0 : L.mem s (scA ct) = 0#u64 - · simp [h0, Notif.optRef] - · simp [h0, Notif.optRef] - -- `handle_fault`: the handler cap - unfold faults.handle_fault - rw [tcb_slot_fault] - apply ok_bind_spec - rw [slot_cap_eq, hep] - apply ok_bind_spec - step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ - subst hi - refine WP.spec_bind (Pₘ := fun r : Bool × S × A => r.1 = true ∧ - ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv (.capFault a0.bv rp lf') σ).1, - RelTopM (L := L) r.2.1 z.2 ∧ JAt (L := L) arI AR r.2.1 r.2.2 z.2) ?_ ?_ - swap - · rintro ⟨b0, s2, a2⟩ ⟨hb, hr0⟩ - simp only at hb hr0 - subst hb - exact (WP.spec_ok _).2 hr0 + have hpt : ptr.bv ≠ ct.bv := fun e => by rw [e, hk] at hkq; cases hkq + obtain ⟨hcbP, hdon⟩ := J.faultEntryBlock hni ht hcur hk hrn hnq' + refine handleFault_ep_wp hep ?_ unfold faults.send_fault_ipc dsimp only -- `set_fault` - set f' : Fl4Spec.Fault := .capFault a0.bv rp lf' with hf' set x2 : Fl4Spec.Tcb := { x with tcbFault := some f' } with hx2 set σf := updK σ ct.bv (.tcb x2) with hσf -- `set_fault` at `J` - refine WP.spec_bind (J.setFaultCapJ ht hk (fun e0 d0 h => by - have := runnable_code hrn; rw [h] at this; simp [tsCode] at this) hcbP ⟨a0, rp, lf, lf', rfl, rfl, hlf⟩) ?_ - rintro s7 ⟨V, J7, -⟩ + refine WP.spec_bind (J.setFaultJG ht hk (fun e0 d0 h => by + have := runnable_code hrn; rw [h] at this; simp [tsCode] at this) hcbP hf) ?_ + rintro s7 ⟨J7, -, hwF⟩ + have F7 : NatFoot (L := L) Z s σ s7 (updK σ ct.bv (.tcb x2)) := + NatFoot.ofW J.xtop hwF (fun b hb => Ipc.FinW.oobj hS hb) (fun b hb => Ipc.FinW.nv hS hb) (fun b hb => J.finW_nh hb) + (natK_tcbW hk rfl fun h => h) have hkf : σf.kheap ct.bv = some (.tcb x2) := by simp [hσf, updK] have hkfp : ∀ q, q ≠ ct.bv → σf.kheap q = σ.kheap q := by intro q hq'; rw [hσf]; simp only [updK, Function.update_of_ne hq'] @@ -2351,30 +1824,30 @@ theorem JAtZ.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H C have hdc : d.bv ≠ ct.bv := fun e0 => htq (by rw [← e0]; simp [Fl4Spec.Endpoint.epQueue]) have hpost : ∀ don : Bool, endpoint.send_ipc st arI s7 a true false bdg g gr don ct ptr ⦃ r => ∃ z ∈ (Fl4Spec.sendIpc (Z := Unit) true false bdg.bv g gr don ct.bv ptr.bv σf).1, - JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + JAtN (L := L) arI AR Z H Cs s7 σf r.1 r.2 z.2 ⦄ := by intro don by_cases hgg : g = true ∨ gr = true · by_cases hA : ∀ xd, σf.kheap d.bv = some (.tcb xd) → ∀ e' rep dd, xd.tcbState = .blockedOnReceive e' rep dd → rep ≠ none · by_cases hS : don = false ∨ ∀ xd, σf.kheap d.bv = some (.tcb xd) → xd.tcbSchedContext ≠ none - · exact J7.sendFaultPJ hAT ht hkf hrn rfl hcur hni.2 hti hnq' hpE hkef true bdg g gr don hgg hA hS + · exact J7.sendFaultPJG hAT ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don hgg hA hS · have hd1 : don = true := by cases don · exact absurd (Or.inl rfl) hS · rfl subst hd1 - refine J7.sendFaultPDJ hAT ht hkf hrn rfl hcur hni.2 hti hnq' hpE hkef true bdg g gr hgg hA ?_ + refine J7.sendFaultPDJG hAT ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr hgg hA ?_ intro xd hxd by_contra hne exact hS (Or.inr fun xd' hxd' => by rw [hxd] at hxd'; cases hxd'; exact hne) - · refine J7.sendFaultIJ ht hkf hrn rfl hcur hni.2 hti hnq' hpE hkef true bdg g gr don (Or.inr ?_) + · refine J7.sendFaultIJG ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don (Or.inr ?_) intro xd hxd e' rep dd hst by_contra hne apply hA intro xd' hxd' e'' rep' dd' hst' rw [hxd] at hxd'; cases hxd' rw [hst] at hst'; cases hst'; exact hne - · exact J7.sendFaultIJ ht hkf hrn rfl hcur hni.2 hti hnq' hpE hkef true bdg g gr don + · exact J7.sendFaultIJG ht hkf hrn rfl hf.nt hcur hni.2 hti hnq' hpE hkef true bdg g gr don (Or.inl ⟨Bool.eq_false_iff.2 fun h => hgg (Or.inl h), Bool.eq_false_iff.2 fun h => hgg (Or.inr h)⟩) refine WP.spec_bind (hpost _) ?_ rintro ⟨s', a'⟩ ⟨z, hz, hJ⟩ @@ -2385,11 +1858,35 @@ theorem JAtZ.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H C (decide (Fl4Spec.Rights.allowGrantReply ∈ rightsOf sd rv g gr)) (decide (x.tcbSchedContext ≠ none)) ct.bv ptr.bv (updK σ ct.bv (.tcb { x with tcbFault := some f' }))).1 := by rw [rights_grant, rights_grantReply, ← hdon]; exact hz - obtain ⟨Z', H', Cs', Ac', Lst', D', J', _⟩ := hJ + obtain ⟨V', Ac', Lst', D', J', F'⟩ := hJ exact ⟨((), z.2), handleFault_ep_mem hk hfh _ hz', ⟨_, _, J'.xtop.rel.1, J'.xtop.rel.2.1, J'.xtop.rel.2.2.1, J'.xtop.rel.2.2.2.1, J'.xtop.rel.2.2.2.2.1⟩, - ⟨_, _, _, _, _, _, J', inferInstance⟩⟩ + ⟨V', Ac', Lst', D', J', J.natTrans F7 F'⟩⟩ + +/-- The cap-fault instance of the shared endpoint receive. -/ +theorem JAtZB.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + {ptr bdg : U64} {sd rv g gr : Bool} + (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) + {d : U64} {q : List Fl4Spec.ObjRef} (hkq : σ.kheap ptr.bv = some (.endpoint (.recvEP (d.bv :: q)))) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.faultRecvJG hAT hni hct hnq hep hkq (FaultCorrG.cap hf) +/-- `JAtZB.faultRecvJ` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtZ.faultRecvJ (hAT : P0.ArchTotal arI) (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + {ptr bdg : U64} {sd rv g gr : Bool} + (hep : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok (.Endpoint ptr bdg sd rv g gr)) + {d : U64} {q : List Fl4Spec.ObjRef} (hkq : σ.kheap ptr.bv = some (.endpoint (.recvEP (d.bv :: q)))) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.faultRecvJ (hAT := hAT) (J := J.toB) (hni := hni) (hct := hct) (hnq := hnq) (hep := hep) (hkq := hkq) (hf := hf)) + fun _ h => JAtN.post J h set_option maxHeartbeats 4000000 in /-- **`handle_fault` at `J`** (XTopJointNoFault's `faultHypJ` at the given @@ -2397,13 +1894,13 @@ set_option maxHeartbeats 4000000 in endpoint by `JAtZ.faultRecvJ` (a waiting receiver, with or without a receive buffer) or `JAtZ.faultBlockJ` (an idle or sending endpoint), any other cap excluded by l4v `valid_fault_handler` (`hvfh`). -/ -theorem JAtZ.faultHypJZ (hAT : P0.ArchTotal arI) - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} +theorem JAtZB.faultHypJZG (hAT : P0.ArchTotal arI) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) - {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by obtain ⟨hcur, x, hk⟩ := J.curEq hct have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb @@ -2424,12 +1921,32 @@ theorem JAtZ.faultHypJZ (hAT : P0.ArchTotal arI) obtain ⟨d', xs', rfl⟩ := List.exists_cons_of_ne_nil hxs0 simp only [List.map_cons] at hq subst hq - exact J.faultRecvJ hAT hni hct hnq hc1 hke hf + exact J.faultRecvJG hAT hni hct hnq hc1 hke hf | idleEP => - exact J.faultBlockJ hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf + exact J.faultBlockJG hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf | sendEP q => - exact J.faultBlockJ hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf + exact J.faultBlockJG hni hct hnq hc1 (fun xe h => by rw [hke] at h; cases h; trivial) hf +/-- The cap-fault instance of the shared fault-handler proof. -/ +theorem JAtZB.faultHypJZ (hAT : P0.ArchTotal arI) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + J.faultHypJZG hAT hni hct hnq hvfh (FaultCorrG.cap hf) + +/-- `JAtZB.faultHypJZ` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtZ.faultHypJZ (hAT : P0.ArchTotal arI) + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hvfh : ∀ x, σ.kheap σ.curThread = some (.tcb x) → Fl4Spec.validFaultHandler x.tcbFaultHandler) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.faultHypJZ (hAT := hAT) (J := J.toB) (hni := hni) (hct := hct) (hnq := hnq) (hvfh := hvfh) (hf := hf)) + fun _ h => JAtN.post J h end diff --git a/proofs/Fl4Proofs/P3/XTopJointFaultRecvBase.lean b/proofs/Fl4Proofs/P3/XTopJointFaultRecvBase.lean new file mode 100644 index 000000000..9836ea3b2 --- /dev/null +++ b/proofs/Fl4Proofs/P3/XTopJointFaultRecvBase.lean @@ -0,0 +1,596 @@ +/- +The register and buffer footprint proofs for cap-fault transfer, and the +shared fault write at the native state relation. +-/ +import Fl4Proofs.P3.XTopJointFaultEp +import Fl4Proofs.P3.XTopJointSendPushD +import Fl4Proofs.P3.EpSendF +import Fl4Proofs.P3.BufFr +import Fl4Proofs.P3.BufFrA +import Fl4Proofs.P3.BufJ +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc + Fl4Proofs.P3.Sched + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} +variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + +set_option maxHeartbeats 4000000 in +/-- **`JAtZ` across a quiet step writing `FinW` words** (XTopJointRegFrame's +`JAtZ.reg_frameF` with the footprint `FinW`). -/ +theorem JAtZB.fin_frameF (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {σ' : Fl4Spec.State Unit} + {Ac' : Set U64} + (hI3 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s' σ') + (hw : P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ)) (hA : QKY σ σ') (hyk : YKeep σ σ') + (hInv : Inv σ') + (hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) + (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac' s') + (hfoot : P1.WritesIn st s s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) ∅ s)) : + JAtZB (L := L) arI AR Z H Cs Ac' Lst D s' a σ' := by + have hI := J.xtop.irelK J.ks J.buf + have hwC : P1.WritesIn st s s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ) := hw.mono fun b hb => Or.inl hb + have hF : IFrame (L := L) Z.th s s' := IRel.iframe_of hI hwC fun b hb => CnW.oobj hI.2.2.1 hb + have hwF := hw + have hck : Fl4Proofs.P3.CKeep σ σ' := hA.ckeepP + have hAR : AR a σ.archState.x64CurrentCr3 := J.xtop.fin.1.1.2.2.2.2.2.2 + obtain ⟨V', hX3⟩ := XTopAt.irel_same J.xtop hI3 hAR hF.1 hck.cdt hck.orig hck.ks hF.2 + have hks : L.ksb s' = L.ksb s := hF.2 + obtain ⟨k1, k2, kb, k3, k4⟩ := J.finW_keeps hwF + have ck := hA.callKeep + obtain ⟨hCR', hRP'⟩ := CallRel.carry J.call J.rp ⟨k3, k4⟩ hks ck + have hRF' := RFree.carry J.rfree J.call k4 ck + have hRR' := J.rrecv.frame k4 hA.khrb + have hDbg := J.kw_dbg (hfoot.mono fun b hb => kw_empty_mono hb _) + have hKd := J.kw_dbgKeep (hfoot.mono fun b hb => kw_empty_mono hb _) + have hS3 : SchedRel st Z.N Z.T Z.C Z.c s' σ' := hI3.2.2.1 + have hAI3 : ActIdle σ' := hA.actIdle J.act + have hdead : ∀ q ∈ D, DeadP (L := L) H s' q := J.deadP_qk hA hS3 hI3.1 hwF k3 hAI3.1 (J.yld.frame k2 hyk) hyk + have hjpl : ∃ Tr Cq, JPlaced (L := L) Z.th H Tr Cq s' σ' := by + obtain ⟨Tr, Cq, hJ⟩ := J.jpl + exact ⟨Tr, Cq, hJ.same hF.1 (fun q y n _ hq => hA.szKeep q.bv y n hq) hks (J.finW_irq hwF) + (J.idleW_keep hS3 hA.idle hA.isc).2⟩ + have hkern := J.kern_keep hks hwF.2.1 hS3 hA.ct hA.csc (fun sl h => Or.inl (by rw [← hA.orig]; exact h)) + (by rw [hA.arch]) + (fun q ao h => (hA.oth (fun _ e => by cases e) (fun _ _ e => by cases e)).2 h) hDbg + (D' := D) + have R : JRest (L := L) arI (Z.mv Z.G V') H Cs Ac' Lst D s' σ' := + ⟨hCR', hRF', hRR', J.yld.frame k2 hyk, J.mcp.frame k1 hA.mcpKeep, J.buf.frame kb hA.bufKeep, hRP', + J.apart.sc_frame hks hA.szKeep, hjpl, J.jcov_keep hks hF.1 hdead (J.idleW_keep hS3 hA.idle hA.isc) + (DXKeep.of_dbg hKd (J.tdkeep_of hwF fun _ hb => Ipc.FinW.ntd J.xtop.fin.1.1.1 hb)), hkern, + J.finW_utc hwF hF.1 hA.cdt hA.orig hA.arch hDbg, hA.nsc J.nsc, hInv, hA.cur J.cur, hA.own J.own, hA.off J.off, + hAI3, hA.bsa J.bsa, hA.isorted J.isorted, hA.curRunM J.curRun, hblk⟩ + have hC0 := JCs.sameB J hF.1 hA.ksz + have hC : JCs (L := L) (Z.mv Z.G V') s' σ' := ⟨hC0.del, hC0.ut, hC0.finM, hC0.sfree⟩ + exact J.cs_frameI hks hX3 hwF (fun b hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) (fun b hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb) hA.arch (fun q ao h => (hA.oth (fun _ e => by cases e) (fun _ _ e => by cases e)).2 h) hA.szKeep hF.1 hA.kback hA.ipcFr hC R hKd hck.orig (J.idleW_keep hS3 hA.idle hA.isc).1 J.zD + +/-- `JAtZB.fin_frameF` at `JAtZ` (via `JAtZ.toB`). -/ +theorem JAtZ.fin_frameF (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {σ' : Fl4Spec.State Unit} + {Ac' : Set U64} + (hI3 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c s' σ') + (hw : P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ)) (hA : QKY σ σ') (hyk : YKeep σ σ') + (hInv : Inv σ') + (hblk : P1.BlkOK st (P1.Heap.tcbs H) Cs (P1.Heap.omega H) H (P1.Heap.frame H) (P1.Heap.replies H) + (P1.Heap.scs H) (P1.Heap.ntfns H) (P1.Heap.scBits H) Ac' s') + (hfoot : P1.WritesIn st s s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) ∅ s)) : + ∃ V', JAtZ (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst D s' a σ' := + ⟨Z.vs, (Fl4Proofs.P3.JAtZB.fin_frameF (J := J.toB) (hI3 := hI3) (hw := hw) (hA := hA) (hyk := hyk) (hInv := hInv) (hblk := hblk) (hfoot := hfoot)).toJAtZ (J.ext_oobj hw (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) + (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb))⟩ + +set_option maxHeartbeats 4000000 in +/-- **`set_fault` of a cap fault at `J`** (module docstring): the thread not +blocked on send (so `Inv.rd`'s class is unchanged), P1's `CanBlock` of any +thread carried. -/ +theorem JAtZB.setFaultJG (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) + {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : FaultCorrG f f') : + faults.set_fault st s t f ⦃ s' => JAtZB (L := L) arI AR Z H Cs Ac Lst D s' a + (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ∧ + P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) ⦄ := by + have hP0 := J.ip + have hI := J.xtop.irelK J.ks J.buf + have htH : t ∈ P1.Heap.tcbs H := J.zH.1 t ht + have hTH : P1.TcbPlaced (P1.Heap.tcbs H) := by rw [← J.tcbs_eq.1]; exact hP0.e.tcb + refine WP.spec_mono (WP.spec_and (set_fault_G_top hP0 hI ht hk hf) + (WP.spec_and (P1.faults.set_fault.blk (U := ∅) s t f (t0 := t0) J.blk htH + (fun _ h => by simp at h) hcb) + (P1.faults.set_fault.kw (Cs := Cs) (Sg := P1.Heap.frame H) (Scs := P1.Heap.scs H) (Z := P1.Heap.scBits H) + (Es := ∅) s t f hTH htH))) ?_ + rintro s7 ⟨⟨⟨-, hI7⟩, hw7⟩, ⟨hblk7, -, hcb7⟩, hfoot7⟩ + have hwF : P1.WritesIn st s s7 (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) := by + refine hw7.mono fun w0 hw0 => ?_ + obtain ⟨K, k1, k2, k6⟩ := hw0 + exact Or.inr ⟨t, ht, K, by omega, by omega, by omega, by omega, ⟨by omega, by omega⟩, k6⟩ + set y : Fl4Spec.Tcb := { x with tcbFault := some f' } + have hA : QKY σ (updK σ t.bv (.tcb y)) := by + refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun p => ?_⟩ + by_cases hp : p = t.bv + · subst hp; exact Or.inr (Or.inl ⟨x, y, hk, by simp [updK], rfl⟩) + · exact Or.inl (by simp [updK, hp]) + have J' := J.fin_frameF hI7 hwF hA (YK.YKS.updTcb (y := y) hk rfl).ykeep + (J.inv.updSame (y := y) hk rfl rfl (Or.inr hns)) hblk7 hfoot7 + exact ⟨J', hcb7, hwF⟩ + +/-- The cap-fault instance of the shared fault write. -/ +theorem JAtZB.setFaultCapJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) + {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.set_fault st s t f ⦃ s' => JAtZB (L := L) arI AR Z H Cs Ac Lst D s' a + (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ∧ + P1.WritesIn st s s' (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) ⦄ := + J.setFaultJG ht hk hns hcb (FaultCorrG.cap hf) + +/-- `JAtZB.setFaultCapJ` at `JAtZ` (via `JAtZ.toB`). -/ +theorem JAtZ.setFaultCapJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hns : ∀ e d, x.tcbState ≠ .blockedOnSend e d) + {t0 : U64} (hcb : P1.CanBlock st (P1.Heap.tcbs H) Ac s t0) + {f : error.Fault} {f' : Fl4Spec.Fault} (hf : CapFaultCorr f f') : + faults.set_fault st s t f ⦃ s' => ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s' a + (updK σ t.bv (.tcb { x with tcbFault := some f' })) ∧ P1.CanBlock st (P1.Heap.tcbs H) Ac s' t0 ⦄ := + WP.spec_mono (Fl4Proofs.P3.JAtZB.setFaultCapJ (J := J.toB) (ht := ht) (hk := hk) (hns := hns) (hcb := hcb) (hf := hf)) fun _ ⟨B, hcb, hw⟩ => + ⟨Z.vs, B.toJAtZ (J.ext_oobj hw (fun _ hb => Ipc.FinW.oobj J.xtop.fin.1.1.1 hb) + (fun _ hb => Ipc.FinW.nv J.xtop.fin.1.1.1 hb)), hcb⟩ + +end + +/-! ## The fault transfer to a receiver without a receive buffer, on `IRel` -/ + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + +theorem set_mr_rg0 {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv i v : U64} (hr : rcv ∈ T) + (h : P1.WritesIn st s0 s (XferRegW T ∅)) : + msg.set_mr st s rcv 0#u64 i v ⦃ r => P1.WritesIn st s0 r.2 (XferRegW T ∅) ⦄ := by + unfold msg.set_mr + split + · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ + simp only [lift, bind_ok, WP.spec_ok] + exact rg_trans h w2 + · simp only [bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + exact h + +theorem set_mrs_lookup_failure_rg0 {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv off : U64} + {lf : error.LookupFault} (hr : rcv ∈ T) (h : P1.WritesIn st s0 s (XferRegW T ∅)) : + faults.set_mrs_lookup_failure st s rcv 0#u64 lf off ⦃ r => P1.WritesIn st s0 r.2 (XferRegW T ∅) ⦄ := by + unfold faults.set_mrs_lookup_failure + refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ + refine WP.spec_bind (set_mr_rg0 (v := i) (i := off) hT hr h) ?_ + rintro ⟨i1, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + split + · exact (WP.spec_ok _).2 h1 + · try simp only [lift, bind_ok] + exact set_mr_rg0 hT hr h1 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rg0 hT hr h2 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rg0 hT hr h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rg0 hT hr h3 + +/-- **`do_ipc_transfer`'s footprint, a cap-faulted sender and a receiver +without a buffer**: the receiver's registers only. -/ +theorem do_ipc_transfer_capF_rg {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) (a : A) + (ep badge : U64) (grant : Bool) + (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄) + (hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' (XferRegW T ∅) ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold ipc.do_ipc_transfer + refine WP.spec_bind hb ?_ + rintro rb rfl + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ft rfl + rw [hty, if_neg (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] + unfold ipc.do_fault_transfer + refine WP.spec_bind (Pₘ := fun r : U64 × S => P1.WritesIn st s r.2 (XferRegW T ∅)) ?_ ?_ + · unfold faults.set_mrs_fault + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ty rfl + refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ + rw [if_pos hty] + refine WP.spec_bind (set_mr_rg0 hT hr (P1.WritesIn.refl s _)) ?_ + rintro ⟨_, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rg0 hT hr h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rg0 hT hr h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ + exact set_mrs_lookup_failure_rg0 hT hr h3 + rintro ⟨sent, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ + refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ + refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 (XferRegW T ∅)) ?_ + fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr + (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => rg_trans h3 w4 + unfold msg.set_msg_info + exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => + WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) + fun s4 w4 => rg_trans h1 w4 + +end + +section SpecF +open Fl4Spec + +/-- The receiver's TCB after the fault transfer of a cap fault without a +receive buffer (EpFaultNone's `doFaultTransfer_eqN` with `makeFaultMsg_cap`). -/ +def fxTcb (xr xs : Tcb) (cf : ObjRef) (rp : Bool) (lf : LookupFailure) (b : Word) : Tcb := + Notif.setReg (Notif.setReg (withRegs xr (mrRegs xr.tcbArch.tcbContext.userRegs + (capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf))) msg_info_register + (messageInfoToData ⟨natToLen (min 4 (capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf).length), + 0, 0, 1⟩)) badge_register b + +theorem fxTcb_eqA (xr xs : Tcb) (cf : ObjRef) (rp : Bool) (lf : LookupFailure) (b : Word) : + fxTcb xr xs cf rp lf b = { xr with tcbArch := (fxTcb xr xs cf rp lf b).tcbArch } := rfl + +/-- The spec's `do_ipc_transfer` of a cap-faulted sender to a receiver +without a receive buffer. -/ +theorem doIpcTransfer_capF_eq {σ : State Unit} {snd rcv : ObjRef} {xs xr : Tcb} + (hks : σ.kheap snd = some (.tcb xs)) (hkr : σ.kheap rcv = some (.tcb xr)) {cf : ObjRef} {rp : Bool} + {lf : LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) (hrb : Endp.ipcBufOf true xr = none) + (ep : Option ObjRef) (badge : Word) (grant : Bool) : + doIpcTransfer (Z := Unit) snd ep badge grant rcv σ = + ({((), updK σ rcv (.tcb (fxTcb xr xs cf rp lf badge)))}, False) := by + have h0 : doIpcTransfer (Z := Unit) snd ep badge grant rcv σ = doFaultTransfer (Z := Unit) badge snd rcv none σ := by + unfold doIpcTransfer + rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] + rw [h0, doFaultTransfer_eqN hks hkr hf (makeFaultMsg_cap hks cf rp lf) badge] + simp only [mrStateN, updK, Function.update_idem] + rfl + +/-- The spec's `send_ipc` of a faulted sender (`call = false`) to a waiting +receiver when the sender gets no reply: it becomes `Inactive` (EpSendF's +`sendIpc_callInactiveF_eq` for any `canDonate`). -/ +theorem sendIpc_faultInactive_eq {σ : State Unit} {t e d : ObjRef} {q : List ObjRef} {don : Bool} + (hk : σ.kheap e = some (.endpoint (.recvEP (d :: q)))) {xd : Tcb} (hkd : σ.kheap d = some (.tcb xd)) + (hde : d ≠ e) (htd : t ≠ d) {e' : ObjRef} {rep : Option ObjRef} {dd : ReceiverPayload} + (hst : xd.tcbState = .blockedOnReceive e' rep dd) (blk : Bool) (badge : Badge) (g gr : Bool) + (hcond : ¬ ((g = true ∨ gr = true) ∧ rep ≠ none)) {σ2 σ3 : State Unit} + (hT : doIpcTransfer (Z := Unit) t (some e) badge g d (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))) = + ({((), σ2)}, False)) + (hU : NonDet.maybeM (replyUnlinkTcb (Z := Unit) d) rep σ2 = ({((), σ3)}, False)) + {xt3 x3 : Tcb} (hkt3 : σ3.kheap t = some (.tcb xt3)) (hkd3 : σ3.kheap d = some (.tcb x3)) + (hf3 : xt3.tcbFault ≠ none) : + sendIpc (Z := Unit) blk false badge g gr don t e σ = + specWakeTailE d (stsAct (updK (stsAct (updK σ3 t (.tcb { xt3 with tcbState := .inactive })) t) d + (.tcb { x3 with tcbState := .running })) d) := by + have hkd1 : (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))).kheap d = some (.tcb xd) := by + simp [hde, hkd] + have hkd3' : (stsAct (updK σ3 t (.tcb { xt3 with tcbState := .inactive })) t).kheap d = some (.tcb x3) := by + rw [stsAct_kheap]; simp [Ne.symm htd, hkd3] + unfold sendIpc + rw [nd_bind_one (getEndpoint_eq hk)] + cases blk <;> dsimp only <;> + · rw [nd_bind_one (tcbEpDequeue_eq hk (by simp [Endpoint.epQueue])), nd_bind_one (getThreadState_eq hkd1), hst] + dsimp only + rw [nd_pure_bind', nd_bind_one hT, nd_bind_one hU, nd_bind_one (getTcbObjRef_eq _ hkd3), + nd_bind_one (threadGet_eq _ hkt3)] + have hc : (false = true ∨ xt3.tcbFault ≠ none) := Or.inr hf3 + simp only [hc, ↓reduceIte] + rw [if_neg hcond, nd_bind_one (Notif.setThreadState_eq _ hkt3), nd_bind_one (Notif.setThreadState_eq _ hkd3')] + rfl + +/-- The spec's `send_ipc` of a faulted sender (`call = false`) to a waiting +receiver `d` with a reply object `r`, the grant or grant-reply right: the +reply push (EpCall's `sendIpc_call_eq` for the fault branch). -/ +theorem sendIpc_faultPush_eq {σ : State Unit} {t e d : ObjRef} {q : List ObjRef} {don : Bool} + (hk : σ.kheap e = some (.endpoint (.recvEP (d :: q)))) {xd : Tcb} (hkd : σ.kheap d = some (.tcb xd)) + (hde : d ≠ e) {e' r : ObjRef} {dd : ReceiverPayload} + (hst : xd.tcbState = .blockedOnReceive e' (some r) dd) (blk : Bool) (badge : Badge) (g gr : Bool) + (hg : g = true ∨ gr = true) {σ2 σ3 σ4 : State Unit} + (hT : doIpcTransfer (Z := Unit) t (some e) badge g d (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))) = + ({((), σ2)}, False)) + (hU : NonDet.maybeM (replyUnlinkTcb (Z := Unit) d) (some r) σ2 = ({((), σ3)}, False)) + {xt3 x3 : Tcb} (hkt3 : σ3.kheap t = some (.tcb xt3)) (hkd3 : σ3.kheap d = some (.tcb x3)) + (hPush : replyPush (Z := Unit) t d r don σ3 = ({((), σ4)}, False)) {x4 : Tcb} + (hkd4 : σ4.kheap d = some (.tcb x4)) (hf3 : xt3.tcbFault ≠ none) : + sendIpc (Z := Unit) blk false badge g gr don t e σ = + specWakeTailE d (stsAct (updK σ4 d (.tcb { x4 with tcbState := .running })) d) := by + have hkd1 : (updK σ e (.endpoint (epDeq (.recvEP (d :: q)) d))).kheap d = some (.tcb xd) := by + simp [hde, hkd] + unfold sendIpc + rw [nd_bind_one (getEndpoint_eq hk)] + cases blk <;> dsimp only <;> + · rw [nd_bind_one (tcbEpDequeue_eq hk (by simp [Endpoint.epQueue])), nd_bind_one (getThreadState_eq hkd1), hst] + dsimp only + rw [nd_pure_bind', nd_bind_one hT, nd_bind_one hU, nd_bind_one (getTcbObjRef_eq _ hkd3), + nd_bind_one (threadGet_eq _ hkt3)] + have hg' : (g = true ∨ gr = true) ∧ (some r : Option ObjRef) ≠ none := ⟨hg, by simp⟩ + have hc : (false = true ∨ xt3.tcbFault ≠ none) := Or.inr hf3 + simp only [hc, ↓reduceIte, hg', the] + rw [if_pos ⟨trivial, by simp⟩] + rw [nd_bind_one hPush, nd_bind_one (Notif.setThreadState_eq _ hkd4)] + rfl + +end SpecF + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + +/-- **`do_ipc_transfer` of a cap-faulted sender to a receiver without a +receive buffer**, on `SRN (SRS (SRT … SRE))` with `IpcBufCapOK` at the state +(EpFaultNone's `do_ipc_transfer_faultN` on XTopJointSendRecv's +`epHyps_buf`/`epBufHyps_buf`; the spec's outcome +`doIpcTransfer_capF_eq`). -/ +theorem do_ipc_transfer_capFJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} + {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP : EPlaced T E R B) + (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) + (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) + (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) + (hOK : Endp.IpcBufCapOK σ) + {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} + (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {cf : Fl4Spec.ObjRef} {rp : Bool} + {lf : Fl4Spec.LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) + (hrb : Endp.ipcBufOf true xr = none) (ep badge : U64) (grant : Bool) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => + Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + ({((), Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)))}, False) ∧ + EpStateRel T E R B (L.mem s') (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv))) ∧ + (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' + (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv))) ∧ + Endp.IpcBufCapOK (Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)))) ∧ + Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ⦄ := by + have hspec := doIpcTransfer_capF_eq hks hkr hf hrb (some ep.bv) badge.bv grant + refine WP.spec_mono (do_ipc_transfer_faultN (ar := arI) (epHyps_buf hHE) + (epBufHyps_buf (st := st) (th := th) (cr := cr) (N := N) (T := T) (C := C) (E := E) (R := R) (B := B) (c := c)) + hP s a σ hR ⟨hSR.1, hOK⟩ hs hr hne hks hkr hf trivial hrb ep badge grant) ?_ + rintro s' ⟨σ', h1, h2, h3, h4, -⟩ + have e : σ' = Notif.updK σ rcv.bv (.tcb (fxTcb xr xs cf rp lf badge.bv)) := + (congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (h1.symm.trans hspec)))) + subst e + exact ⟨hspec, h2, h3, h4⟩ + +/-! ## The cap-fault transfer into a receive buffer -/ + +theorem updK_setUm_updK (σ0 : Fl4Spec.State Unit) (r : Fl4Spec.ObjRef) (o1 o2 : Fl4Spec.KernelObject) + (m : Fl4Spec.Word → Fl4Spec.Word8) : + Notif.updK (Endp.setUm (Notif.updK σ0 r o1) m) r o2 = Notif.updK (Endp.setUm σ0 m) r o2 := by + unfold Notif.updK Endp.setUm + simp only [Function.update_idem] + try rfl + +/-- `set_mr` of word `i < 127` into a receiver with a buffer at `rw`: the +receiver's registers or its buffer words. -/ +theorem set_mr_rgB {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw i v : U64} (hr : rcv ∈ T) + (hrw0 : rw ≠ 0#u64) (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hi : i.val < 127) + (h : P1.WritesIn st s0 s (XferBW T rw)) : + msg.set_mr st s rcv rw i v ⦃ r => P1.WritesIn st s0 r.2 (XferBW T rw) ⦄ := by + unfold msg.set_mr + split + · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ + simp only [lift, bind_ok, WP.spec_ok] + exact (h.trans w2).mono fun b hb => hb.elim id Or.inl + · have hb : (rw != 0#u64) = true := by simpa using hrw0 + simp only [hb, ↓reduceIte, lift, bind_ok] + have hv : (core.num.U64.wrapping_add i 1#u64).val = i.val + 1 := wadd_val i 1 (by omega) _ rfl + refine WP.spec_bind (Endp.msg.buf_set.spec s rw _ v) ?_ + rintro s1 rfl + simp only [WP.spec_ok] + exact (h.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => (⟨_, by omega, hb'⟩ : RBufW rw b))).mono + fun b hb' => hb'.elim id Or.inr + +theorem set_mrs_lookup_failure_rgB {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw off : U64} + {lf : error.LookupFault} (hr : rcv ∈ T) (hrw0 : rw ≠ 0#u64) + (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hoff : off.val ≤ 3) + (h : P1.WritesIn st s0 s (XferBW T rw)) : + faults.set_mrs_lookup_failure st s rcv rw lf off ⦃ r => P1.WritesIn st s0 r.2 (XferBW T rw) ⦄ := by + unfold faults.set_mrs_lookup_failure + refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ + refine WP.spec_bind (set_mr_rgB (v := i) (i := off) hT hr hrw0 hal (by omega) h) ?_ + rintro ⟨i1, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + split + · exact (WP.spec_ok _).2 h1 + · try simp only [lift, bind_ok] + exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rgB hT hr hrw0 hal (by rw [wadd_val off 3 (by omega) _ rfl]; omega) h3 + +/-- **`do_ipc_transfer`'s footprint, a cap-faulted sender and a receiver +with a buffer at `rw`**: the receiver's registers and its buffer words. -/ +theorem do_ipc_transfer_capF_rgB {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) (a : A) + (ep badge : U64) (grant : Bool) {rw : U64} (hrw0 : rw ≠ 0#u64) + (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) + (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = rw ⦄) + (hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' (XferBW T rw) ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold ipc.do_ipc_transfer + refine WP.spec_bind hb ?_ + rintro rb rfl + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ft rfl + rw [hty, if_neg (by unfold fl4_abi.consts.fault.CapFault fl4_abi.consts.fault.NullFault; decide)] + unfold ipc.do_fault_transfer + refine WP.spec_bind (Pₘ := fun r : U64 × S => P1.WritesIn st s r.2 (XferBW T rb)) ?_ ?_ + · unfold faults.set_mrs_fault + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ty rfl + refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ + rw [if_pos hty] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal + (by rw [show (0#u64 : U64).val = 0 from rfl]; omega) (P1.WritesIn.refl s _)) ?_ + rintro ⟨_, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [show (1#u64 : U64).val = 1 from rfl]; omega) h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgB hT hr hrw0 hal (by rw [show (2#u64 : U64).val = 2 from rfl]; omega) h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ + exact set_mrs_lookup_failure_rgB hT hr hrw0 hal (by rw [show (3#u64 : U64).val = 3 from rfl]) h3 + rintro ⟨sent, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ + refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ + refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 (XferBW T rb)) ?_ + fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr + (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => (h3.trans w4).mono fun b hb => hb.elim id Or.inl + unfold msg.set_msg_info + exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => + WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) + fun s4 w4 => (h1.trans w4).mono fun b hb => hb.elim id Or.inl + +set_option maxHeartbeats 16000000 in +/-- **The transfer step of a cap-faulted sender's `send_ipc` to a waiting +receiver, with or without a receive buffer** (XTopJointXferB's `xferStepJ` +for the fault transfer): on `IRel` by `do_ipc_transfer_capFJ` (no buffer) or +EpFaultMore's `do_ipc_transfer_fault` (a buffer; the spec's outcome by +`doFaultTransfer_eq`), the footprint `XferRegW ∪ RcvBufW` +(`do_ipc_transfer_capF_rg`, `do_ipc_transfer_capF_rgB`), P1's hole by +`xfer_all` or `blkX_bufw`. -/ +theorem xferFaultStepJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} + {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP0 : Ipc.IPlaced N T E R B) (hP : EPlaced T E R B) + (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) + (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) + (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) + (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover T B σ) + {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} + (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {cf : Fl4Spec.ObjRef} {rp : Bool} + {lf : Fl4Spec.LookupFailure} (hf : xs.tcbFault = some (.capFault cf rp lf)) + (ep badge : U64) (grant : Bool) + {T1 Cs1 Ω Sg Rp Scs Nt Ac1 X : Set U64} {H1 : P1.Heap} {Zb : U64 → Nat} {Q : U64 → U64 → List U64} + {Rq : U64 → List U64} (hT1 : P1.TcbPlaced T1) (hr1 : rcv ∈ T1) + (h : P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s Q Rq) (hB : P1.BoundInv st T1 Ac1 s) + (hX : P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s) (hS : P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s) (hSg : P1.SgOK st Ω Sg s) + (hU : ∀ b, RcvBufW xr b → P1.OutsideObjs st T1 Cs1 s b ∧ + (∀ e, (H1 e = some .ep ∨ H1 e = some .ntfn) → b.val + 8 ≤ e.val ∨ e.val + 16 ≤ b.val) ∧ b ∉ Sg) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => ∃ (x' : Fl4Spec.Tcb) + (um : Fl4Spec.Word → Fl4Spec.Word8), + Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + ({((), Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))}, False) ∧ x' = { xr with tcbArch := x'.tcbArch } ∧ + EpStateRel T E R B (L.mem s') (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ + (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' + (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ + Endp.IpcBufCapOK (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))) ∧ + Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ∧ + P1.WritesIn st s s' (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) ∧ + P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s' Q Rq ∧ P1.BoundInv st T1 Ac1 s' ∧ P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s' ∧ + P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s' ∧ P1.SgOK st Ω Sg s' ∧ + (∀ y ∈ T1, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → + L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) ⦄ := by + have hty : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault := by + have hfr := (hR.at_tcb hs hks).faultR + unfold FaultRel at hfr; rw [hf] at hfr; rw [hfr.1]; unfold fl4_abi.consts.fault.CapFault; rfl + obtain ⟨⟨⟨G, hBt⟩, hBw⟩, -⟩ := hSR.1.1 + have hlb := lookup_buf_full s σ hBt.2.1.1 hBt.2.1.2.1 (Ipc.RelTopB.tcbT hBt hkr) hkr hOK true + cases hrb : Endp.ipcBufOf true xr with + | none => + have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄ := WP.spec_mono hlb fun w hw => hw.1.2 hrb + refine WP.spec_mono (WP.spec_and (do_ipc_transfer_capFJ hP hHE s a σ hR hSR hOK hs hr hne hks hkr hf hrb + ep badge grant) (do_ipc_transfer_capF_rg (arI := arI) hT1 hr1 s a ep badge grant hlk hty)) ?_ + rintro s2 ⟨⟨e2, hR2, hS2, hA2⟩, w2⟩ + obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2, -⟩ := + P1.xfer_all h hB hX hS hSg (U := ∅) (fun b hb => absurd hb (Set.notMem_empty _)) + (w2.mono fun b hb => P1.XferRegW.foot hb) + exact ⟨fxTcb xr xs cf rp lf badge.bv, σ.machineState.underlyingMemory, e2, fxTcb_eqA _ _ _ _ _ _, hR2, hS2, + hA2, w2.mono fun b hb => Or.inl hb, h2, hB2, hX2, hS2', hSg2, f2⟩ + | some p => + obtain ⟨x0, hk0, hbw⟩ := hBw.bw rcv hr + rw [hkr] at hk0; cases hk0 + have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = ⟨p⟩ ⦄ := WP.spec_mono hlb fun w hw => by + have hwb : w.bv = p := hw.2 hbw p hrb + rw [← hwb] + have hrw0 : (⟨p⟩ : U64) ≠ 0#u64 := by + obtain ⟨w0, -, hw0⟩ := spec_exists hlb + have hwb : w0.bv = p := hw0.2 hbw p hrb + intro e + have : w0 = 0#u64 := by rw [← e, ← hwb] + rw [hw0.1.1 this] at hrb; cases hrb + have hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA ⟨p⟩ i) := fun i hi => + (hP.balign _ (hBC rcv hr xr true p hkr hrb ⟨p⟩ rfl i hi)).1 + have hBm := epBufMapHyps_bufC (st := st) (th := th) (cr := cr) (C := C) (c := c) hP0 + obtain ⟨rw1, -, hrw1, hmr⟩ := spec_exists (hBm.lookupMap s σ rcv xr true p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb) + have hu := hBm.frame s σ rcv xr p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb + have hal' : ∀ q ∈ mrPairs (Endp.capFaultMsg (xs.tcbArch.tcbContext.userRegs .faultIP) cf rp lf), (bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (bufAddr p q.1) σ := by + intro q hq + have := (List.of_mem_zip hq).1 + simp at this + exact ⟨bufAddr_aligned hP hmr _, hu _ (by omega)⟩ + have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv (some p) σ := by + unfold Fl4Spec.doIpcTransfer + rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] + have hspec := hspec0.trans (doFaultTransfer_eq hks hkr hf (makeFaultMsg_cap hks cf rp lf) p hal' badge.bv) + refine WP.spec_mono (WP.spec_and (Endp.do_ipc_transfer_fault (ar := arI) (epHyps_bufC hHE T) hBm hP s a σ hR ⟨⟨hSR.1, hOK⟩, hBC⟩ + hs hr hne hks hkr hf trivial hrb ep badge grant) + (do_ipc_transfer_capF_rgB (arI := arI) hT1 hr1 s a ep badge grant hrw0 hal hlk hty)) ?_ + rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ + have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) + simp only [mrState, updK_setUm_updK] at eσ + subst eσ + have hW : P1.WritesIn st s s2 (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) := + w2.mono fun b hb => hb.imp_right fun h' => ⟨p, hrb, h'⟩ + obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2⟩ := blkX_bufw (l := rbList ⟨p⟩) h hB hX hS hSg + (fun b hb => hU b ⟨p, hrb, mem_rbList.1 hb⟩) (w2.mono fun b hb => hb.imp_right mem_rbList.2) + exact ⟨_, _, e2, rfl, hR2, hS2.1, hA2, hW, h2, hB2, hX2, hS2', hSg2, f2⟩ + +end + + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/XTopJointFinThread.lean b/proofs/Fl4Proofs/P3/XTopJointFinThread.lean index acabfdc8d..a7f9e9d84 100644 --- a/proofs/Fl4Proofs/P3/XTopJointFinThread.lean +++ b/proofs/Fl4Proofs/P3/XTopJointFinThread.lean @@ -149,6 +149,32 @@ theorem JAtZB.tw_nh (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} rw [e] at g omega +/-- (mmuAD gen 42b73) **Timer-word writes are a native step** (`TmW`: the TCBs' timer fields, every core's timer +heads, `REPROGRAM` of `Z.c`; the spec state kept): moved out of `JAtZB.tmRemoveJ` (statement unchanged) for the +fire loop at `VmEptState` (P3/VmOracle). -/ +theorem JAtZB.tmwN (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s2 : S} + (hw2' : P1.WritesIn st s s2 (TmW (L := L) Z.T Cs Z.c s)) : NatFoot (L := L) Z s σ s2 σ := by + have hTe : Z.T = P1.Heap.tcbs H := J.tcbs_eq.1 + obtain ⟨Q, R0, hc, -⟩ := J.xtop.fin.1.1.1.lists + have hcC : Z.c ∈ Cs := by have := J.kern.cpuCs; rw [hc.cur] at this; exact this + have hN : P1.NodePlaced st Z.T s Z.c := by rw [hTe]; exact P1.TInv.nodes J.blk Z.c hcC + have hv := P1.nodeAt_val hN (off := layout.node.REPROGRAM) (by simp [layout.node.REPROGRAM]) + have h56 : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + refine NatFoot.ofWS (J.tmw_slots hw2') hw2' (fun b hb => ?_) + (fun b hb u hu => J.tmw_ne_tcb hb hu (Sched.tVcpuA_val J.ip.e.tcb hu) (by omega)) (fun b hb => by + rcases hb with hb | rfl + · exact J.tw_nh hb + · intro e + have hvh : (P1.vHeadA st s).val = (L.ksb s).val + 80 := vHead_val J.kern.ksbFit + have hnb : L.nodeBase s Z.c = (L.ksb s).val + 13568 + Z.c.val * 4288 := rfl + rw [e] at hv + omega) (NatK.of_kheap rfl) + rcases hb with hb | rfl + · rcases J.tw_word hb with ⟨y, hy, g1, g2⟩ | ⟨c', hc', o, ho, e⟩ + · exact Or.inl (Or.inr (Or.inr (Or.inl ⟨y, hy, by omega, by omega⟩))) + · exact Or.inr ⟨c', J.kern.csLt c' hc', by rcases ho with rfl | rfl; exacts [Or.inl e, Or.inr e]⟩ + · exact Or.inl (Or.inl ⟨by rw [hv]; omega, by rw [hv]; omega⟩) + set_option maxHeartbeats 4000000 in /-- **`timer::remove` at `J`** (as in ScFireJ's `fireJ`): P1's `timer.remove.tf` (footprint `TW`, `BlkOK` after), the `REPROGRAM` word @@ -197,26 +223,7 @@ theorem JAtZB.tmRemoveJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : rw [g1, g0]; unfold Sched.nodeW rw [P1.nodeAt_of_ksb hw2.1, hR2] rw [e2] at J2 - -- the footprint: the TCBs' timer fields, every core's timer heads, `REPROGRAM` of `Z.c` - obtain ⟨Q, R0, hc, -⟩ := J.xtop.fin.1.1.1.lists - have hcC : Z.c ∈ Cs := by have := J.kern.cpuCs; rw [hc.cur] at this; exact this - have hN : P1.NodePlaced st Z.T s Z.c := by rw [hTe]; exact P1.TInv.nodes J.blk Z.c hcC - have hv := P1.nodeAt_val hN (off := layout.node.REPROGRAM) (by simp [layout.node.REPROGRAM]) - have h56 : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] - refine ⟨J2, NatFoot.ofWS (J.tmw_slots hw2') hw2' (fun b hb => ?_) - (fun b hb u hu => J.tmw_ne_tcb hb hu (Sched.tVcpuA_val J.ip.e.tcb hu) (by omega)) (fun b hb => by - rcases hb with hb | rfl - · exact J.tw_nh hb - · intro e - have hvh : (P1.vHeadA st s).val = (L.ksb s).val + 80 := vHead_val J.kern.ksbFit - have hnb : L.nodeBase s Z.c = (L.ksb s).val + 13568 + Z.c.val * 4288 := rfl - rw [e] at hv - omega) (NatK.of_kheap rfl)⟩ - rcases hb with hb | rfl - · rcases J.tw_word hb with ⟨y, hy, g1, g2⟩ | ⟨c', hc', o, ho, e⟩ - · exact Or.inl (Or.inr (Or.inr (Or.inl ⟨y, hy, by omega, by omega⟩))) - · exact Or.inr ⟨c', J.kern.csLt c' hc', by rcases ho with rfl | rfl; exacts [Or.inl e, Or.inr e]⟩ - · exact Or.inl (Or.inl ⟨by rw [hv]; omega, by rw [hv]; omega⟩) + exact ⟨J2, J.tmwN hw2'⟩ /-- `JAtZB.tmRemoveJ` at `JAtZ` (via `JAtZ.toB`, `ext` by `JAtZB.toJN`). -/ theorem JAtZ.tmRemoveJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) : diff --git a/proofs/Fl4Proofs/P3/XTopJointIrq.lean b/proofs/Fl4Proofs/P3/XTopJointIrq.lean index e0a5a57f9..8b717007c 100644 --- a/proofs/Fl4Proofs/P3/XTopJointIrq.lean +++ b/proofs/Fl4Proofs/P3/XTopJointIrq.lean @@ -81,10 +81,34 @@ theorem mem_dmo_mask (i : Irq) (b : Bool) (σ : State Unit) : refine mem_bind_nd (x := ((), maskMs σ i b)) (Set.mem_singleton _) ?_ rfl -/-- A line above `maxIRQ`: masked and acknowledged. -/ -theorem mem_hi_big {i : Irq} (h : i > maxIRQ) (σ : State Unit) : - ((), maskMs σ i true) ∈ (handleInterrupt (Z := Unit) i σ).1 := by - unfold handleInterrupt +/-- (mmuAD gen 42b72) **`handleInterrupt` with the signal a parameter** (`handleInterrupt_hiS`: the port is it at +`sendSignal`; P3/VmOracle's `handleInterruptVF_hiS`: the VMEnter-report handler is it at `sendSignalVF`). -/ +def hiS (sig : ObjRef → Badge → SMonad Unit Unit) (irq : Irq) : SMonad Unit Unit := + if irq > maxIRQ then doMachineOp (do + maskInterrupt true irq + ackInterrupt irq) + else do + let st ← getIrqState irq + match st with + | .irqSignal => do + let slot ← getIrqSlot irq + let cap ← getCap slot + NonDet.when (isNtfnCap cap ∧ AllowSend ∈ capRights cap) <| + sig (objRefOf cap) (capEpBadge cap) + archMaskIrqSignal irq + | .irqTimer => do + doMachineOp ackDeadlineIRQ + NonDet.modify fun s : State Unit => { s with reprogramTimer := true } + | .irqInactive => NonDet.fail + | .irqReserved => handleReservedIrq irq + doMachineOp <| ackInterrupt irq + +theorem handleInterrupt_hiS (i : Irq) : handleInterrupt (Z := Unit) i = hiS sendSignal i := rfl + +/-- A line above `maxIRQ`: masked and acknowledged (any signal, gen 42b72). -/ +theorem mem_hiS_big (sig : ObjRef → Badge → SMonad Unit Unit) {i : Irq} (h : i > maxIRQ) (σ : State Unit) : + ((), maskMs σ i true) ∈ (hiS sig i σ).1 := by + unfold hiS rw [if_pos h] unfold doMachineOp maskInterrupt ackInterrupt refine mem_bind_nd (x := (σ.machineState, σ)) rfl ?_ @@ -93,41 +117,61 @@ theorem mem_hi_big {i : Irq} (h : i > maxIRQ) (σ : State Unit) : refine mem_bind_nd (x := ((), maskMs σ i true)) (Set.mem_singleton _) ?_ rfl -/-- An inactive line: the spec fails. -/ -theorem fail_hi_inactive {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} - (hst : σ.interruptStates i = .irqInactive) : (handleInterrupt (Z := Unit) i σ).2 := by - unfold handleInterrupt +/-- A line above `maxIRQ`: masked and acknowledged. -/ +theorem mem_hi_big {i : Irq} (h : i > maxIRQ) (σ : State Unit) : + ((), maskMs σ i true) ∈ (handleInterrupt (Z := Unit) i σ).1 := mem_hiS_big sendSignal h σ + +/-- An inactive line: the spec fails (any signal, gen 42b72). -/ +theorem fail_hiS_inactive (sig : ObjRef → Badge → SMonad Unit Unit) {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} + (hst : σ.interruptStates i = .irqInactive) : (hiS sig i σ).2 := by + unfold hiS rw [if_neg h] refine Or.inr ⟨(.irqInactive, σ), by show _ ∈ ({(σ.interruptStates i, σ)} : Set _); rw [hst]; rfl, ?_⟩ exact Or.inl trivial -/-- A reserved line: nothing but the acknowledgement. -/ -theorem mem_hi_reserved {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} - (hst : σ.interruptStates i = .irqReserved) : ((), σ) ∈ (handleInterrupt (Z := Unit) i σ).1 := by - unfold handleInterrupt +/-- An inactive line: the spec fails. -/ +theorem fail_hi_inactive {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} + (hst : σ.interruptStates i = .irqInactive) : (handleInterrupt (Z := Unit) i σ).2 := + fail_hiS_inactive sendSignal h hst + +/-- A reserved line: nothing but the acknowledgement (any signal, gen 42b72). -/ +theorem mem_hiS_reserved (sig : ObjRef → Badge → SMonad Unit Unit) {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} + (hst : σ.interruptStates i = .irqReserved) : ((), σ) ∈ (hiS sig i σ).1 := by + unfold hiS rw [if_neg h] refine mem_bind_nd (x := (.irqReserved, σ)) (by show _ ∈ ({(σ.interruptStates i, σ)} : Set _); rw [hst]; rfl) ?_ exact mem_bind_nd (x := ((), σ)) rfl (mem_dmo_ack i σ) -/-- The timer line: `reprogram_timer` set. -/ -theorem mem_hi_timer {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} +/-- A reserved line: nothing but the acknowledgement. -/ +theorem mem_hi_reserved {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} + (hst : σ.interruptStates i = .irqReserved) : ((), σ) ∈ (handleInterrupt (Z := Unit) i σ).1 := + mem_hiS_reserved sendSignal h hst + +/-- The timer line: `reprogram_timer` set (any signal, gen 42b72). -/ +theorem mem_hiS_timer (sig : ObjRef → Badge → SMonad Unit Unit) {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} (hst : σ.interruptStates i = .irqTimer) : - ((), { σ with reprogramTimer := true }) ∈ (handleInterrupt (Z := Unit) i σ).1 := by - unfold handleInterrupt + ((), { σ with reprogramTimer := true }) ∈ (hiS sig i σ).1 := by + unfold hiS rw [if_neg h] refine mem_bind_nd (x := (.irqTimer, σ)) (by show _ ∈ ({(σ.interruptStates i, σ)} : Set _); rw [hst]; rfl) ?_ refine mem_bind_nd (x := ((), σ)) (by unfold ackDeadlineIRQ; exact mem_dmo_ack deadlineIRQ σ) ?_ exact mem_bind_nd (x := ((), { σ with reprogramTimer := true })) (Set.mem_singleton _) (mem_dmo_ack i _) -/-- A signal line: the handler's notification signalled (when its cap is a -notification cap with the send right), then the line masked. -/ -theorem mem_hi_signal {i : Irq} (h : ¬ i > maxIRQ) {σ σ1 : State Unit} +/-- The timer line: `reprogram_timer` set. -/ +theorem mem_hi_timer {i : Irq} (h : ¬ i > maxIRQ) {σ : State Unit} + (hst : σ.interruptStates i = .irqTimer) : + ((), { σ with reprogramTimer := true }) ∈ (handleInterrupt (Z := Unit) i σ).1 := + mem_hiS_timer sendSignal h hst + +/-- A signal line: the handler's notification signalled by `sig` (when its cap is a notification cap with the send +right), then the line masked (gen 42b72). -/ +theorem mem_hiS_signal (sig : ObjRef → Badge → SMonad Unit Unit) {i : Irq} (h : ¬ i > maxIRQ) {σ σ1 : State Unit} (hst : σ.interruptStates i = .irqSignal) {ac : Cap} (hcap : getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False)) (h1 : ((), σ1) ∈ (NonDet.when (isNtfnCap ac ∧ AllowSend ∈ capRights ac) - (sendSignal (Z := Unit) (objRefOf ac) (capEpBadge ac)) σ).1) : - ((), maskMs σ1 i true) ∈ (handleInterrupt (Z := Unit) i σ).1 := by - unfold handleInterrupt + (sig (objRefOf ac) (capEpBadge ac)) σ).1) : + ((), maskMs σ1 i true) ∈ (hiS sig i σ).1 := by + unfold hiS rw [if_neg h] refine mem_bind_nd (x := (.irqSignal, σ)) (by show _ ∈ ({(σ.interruptStates i, σ)} : Set _); rw [hst]; rfl) ?_ refine mem_bind_nd (x := ((σ.interruptIrqNode i, []), σ)) rfl ?_ @@ -136,6 +180,16 @@ theorem mem_hi_signal {i : Irq} (h : ¬ i > maxIRQ) {σ σ1 : State Unit} exact mem_bind_nd (x := ((), maskMs σ1 i true)) (by unfold archMaskIrqSignal; exact mem_dmo_mask i true σ1) (mem_dmo_ack i _) +/-- A signal line: the handler's notification signalled (when its cap is a +notification cap with the send right), then the line masked. -/ +theorem mem_hi_signal {i : Irq} (h : ¬ i > maxIRQ) {σ σ1 : State Unit} + (hst : σ.interruptStates i = .irqSignal) {ac : Cap} + (hcap : getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False)) + (h1 : ((), σ1) ∈ (NonDet.when (isNtfnCap ac ∧ AllowSend ∈ capRights ac) + (sendSignal (Z := Unit) (objRefOf ac) (capEpBadge ac)) σ).1) : + ((), maskMs σ1 i true) ∈ (handleInterrupt (Z := Unit) i σ).1 := + mem_hiS_signal sendSignal h hst hcap h1 + /-- `when` with a false condition. -/ theorem mem_when_false {P : Prop} [Decidable P] (hP : ¬ P) (m : NonDet (State Unit) Unit) (σ : State Unit) : ((), σ) ∈ (NonDet.when P m σ).1 := by @@ -183,7 +237,7 @@ gap (the frames-from-the-base `send_signal`), not a missing invariant. -/ def JIrqSigHyp (AR : A → Fl4Spec.Cr3 → Prop) : Prop := ∀ (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s0 : S) (a0 : A) (σ0 : Fl4Spec.State Unit) (s : S) (a : A) (σ : Fl4Spec.State Unit) (w n badge : U64) (r : Bool), - JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ → ¬ (OffOK σ ∧ CurOwnW Z.T Z.C σ) → + JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ → JExt (L := L) Z.th s0 → ¬ (OffOK σ ∧ CurOwnW Z.T Z.C σ) → w.val < 128 → capAt (L.mem s) (nodeA (L.ksb s) w) = ok (.Notification n badge true r) → notification.send_signal st arI s a n badge ⦃ r' => ∃ z ∈ (Fl4Spec.sendSignal (Z := Unit) n.bv badge.bv σ).1, ∃ Z', XTopAt (L := L) AR Z' r'.1 r'.2 z.2 ⦄ @@ -192,7 +246,8 @@ set_option maxHeartbeats 16000000 in /-- **`handle_interrupt` from one `JHole`** (module docstring): the signal from the hole when it is not `JAtZ` (`¬ (OffOK ∧ CurOwnW)`) is the premise `hSig` of this hole only (`jIrqHyp_of` passes `JIrqSigHyp`; from a `JAtZ` -state it is vacuous, XTopJointPreemptZ). -/ +state it is vacuous, XTopJointPreemptZ). (mmuAD gen 42b71, ruling (c2) item 1) No `JExt` at the hole's base (gen +42b69's bridge `hE` dropped): the signal from `JHole.toJ`'s `JAtZB` by ScSignalJN's `JAtZB.signal_atN`. -/ theorem JHole.handleIrqJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlat arI AR) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} @@ -319,11 +374,11 @@ theorem JHole.handleIrqJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h by_cases hO : OffOK σ ∧ CurOwnW Z.T Z.C σ - · obtain ⟨Lst', J⟩ := Hh.toJ hO.1 hO.2 + · obtain ⟨Lst', JB, -⟩ := Hh.toJ hO.1 hO.2 have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (J.signal_atN hAT hmb hN p b hpN) ?_ - rintro ⟨s2, a2⟩ ⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩ + have hpN := (JB.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 + refine WP.spec_bind (JB.signal_atN hAT hmb hN p b hpN) ?_ + rintro ⟨s2, a2⟩ ⟨σ', Ac', Lst'', D', hsp, -, J', -⟩ exact hmask s2 a2 σ' _ (hwhen σ' (by rw [hsp]; rfl)) J'.xtop · refine WP.spec_bind (hSig hO w p b rv hw128 hcap) ?_ rintro ⟨s2, a2⟩ ⟨z, hz, Z', hX2⟩ @@ -404,9 +459,9 @@ theorem jIrqHyp_ofN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqP (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, ∃ Z', XTopAt (L := L) AR Z' r.1 r.2 z.2 ⦄ := by intro s a σ w i hJ hN hwi _ h126 h127 - obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, _⟩ := hJ + obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, _⟩ := hJ exact Hh.handleIrqJN hARI hAT hIP hmb hN - (fun hO w' n b r h1 h2 => hSig Z H Cs Ac Lst D s0 a0 σ0 s a σ w' n b r Hh hO h1 h2) w i hwi h126 h127 + (fun hO w' n b r h1 h2 => hSig Z H Cs Ac Lst D s0 a0 σ0 s a σ w' n b r Hh hEx hO h1 h2) w i hwi h126 h127 variable (arI) in /-- **`JPreemptRestHyp` in the native scope** [W] (module docstring): the diff --git a/proofs/Fl4Proofs/P3/XTopJointIrqZI.lean b/proofs/Fl4Proofs/P3/XTopJointIrqZI.lean index c6d779604..35d91bb0c 100644 --- a/proofs/Fl4Proofs/P3/XTopJointIrqZI.lean +++ b/proofs/Fl4Proofs/P3/XTopJointIrqZI.lean @@ -17,6 +17,9 @@ case of the preemption path closed by a platform fact** (`IrqPlatI` [P]). * `JHole.afterInvJZI`, `afterInv_of_mcsI`: the covered preemption paths end in `PPQJI` (`JAt` after the path, NO spec failure); `PPQCI := PPQJI ∨ (RestE ∧ PPQ)`; `hPre_ofZECI`, `dispatch_invokeJEPZECI`. + +(mmuAD gen 42b71) `JAtZ.handleIrqJIN` is XTopJointIrqZR's `JAtZB.handleIrqJBT` corollary (`JAtN.toJAt`), statement +unchanged (the ~180-line copy removed). -/ import Fl4Proofs.P3.XTopJointIrqZR open Aeneas Aeneas.Std Result @@ -42,7 +45,6 @@ structure IrqPlatI (AR : A → Fl4Spec.Cr3 → Prop) : Prop where Fl4Spec.doMachineOp (Z := Unit) (Fl4Spec.getActiveIRQ true) σ = ({(irq, { σ with machineState := ms })}, False) → ∀ i, irq = some i → σ.interruptStates i ≠ .irqInactive ⦄ -set_option maxHeartbeats 16000000 in /-- **`JAtZ.handleIrqJJ` with the inactive-line case named**: the spec fails only on an inactive line, so the post is `JAt` after or that line inactive. -/ theorem JAtZ.handleIrqJIN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlat arI AR) @@ -53,162 +55,9 @@ theorem JAtZ.handleIrqJIN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) : interrupt.handle_interrupt st arI s a w ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - have hX := J.xtop - have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 - have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 - have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by - apply BitVec.eq_of_toNat_eq; simp [hwi] - -- the acknowledgement keeps `JAt` - have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JAt (L := L) arI AR s1 a1 z.2 → - (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s1 a1 z hz ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ - refine WP.spec_bind (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) ?_ - intro a2 hA2 - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, Z1, H1, Cs1, Ac1, Lst2, D1, J2, inferInstance⟩) - unfold interrupt.handle_interrupt - rw [irq_max_eq] - simp only [bind_ok] - by_cases hbig : w > 127#u64 - · -- above FL4's maximum - rw [if_pos hbig] - have hgt : i > Fl4Spec.maxIRQ := by - have : 127 < w.val := hbig - show (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - rw [ha1] - simp only [bind_ok] - have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) ⟨Z, H, Cs, Ac, Lst1, D, J1, inferInstance⟩ - · rw [if_neg hbig] - have hw : w.val ≤ 125 := by - have : ¬ 127 < w.val := hbig - omega - have hw128 : w.val < 128 := by omega - have hle : ¬ i > Fl4Spec.maxIRQ := by - show ¬ (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - have hst : σ.interruptStates i = irqSt (L.mem s (irqStA (L.ksb s) w)) := by - rw [← hiw]; exact hIR.st w hw128 - rw [irq_state_eq'] - simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] - set v := L.mem s (irqStA (L.ksb s) w) with hv - -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ → - (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - intro m hm - refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1⟩) - · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ - intro a2 _ - exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 - refine key _ ?_ - by_cases h1 : v = 1#u64 - · -- a signal line - rw [if_pos h1] - have hsig : σ.interruptStates i = .irqSignal := by rw [hst, h1]; rfl - have hL : IntLayout Z.th (L.ksb s) := J.intL - have hnode := hL.node w hw128 - obtain ⟨cs, hkc, hwf, hsl⟩ := hX.rel.2.1.1.cnode _ 0 hnode - obtain ⟨c, ac, hcap, hcs, hCR⟩ := hsl [] rfl - rw [show slotAddr (nodeA (L.ksb s) w).bv (Fl4Spec.ofBl []) = nodeA (L.ksb s) w from - cslotAddr_nil _] at hcap - have hgc : Fl4Spec.getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False) := by - rw [← hiw, hIR.node w hw128]; exact getCap_cnode hkc hwf hcs - have hac : ac = absCap c := hCR.abs - rw [irq_slot_eq] - simp only [bind_ok] - rw [slot_cap_eq, hcap] - simp only [bind_ok] - -- the mask after the cap's case - have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JAt (L := L) arI AR s3 a2 σ1 → - (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s3 a2 σ1 h1' ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ - obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true - rw [ha3] - simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', Z1, H1, Cs1, Ac1, Lst3, D1, J3, inferInstance⟩ - have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), - (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ - cases c with - | Notification p b sd rv => - cases sd with - | false => - simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap, Fl4Spec.capRights, Fl4Spec.AllowSend, rightsOf]) - | true => - simp only [↓reduceIte] - have hP : Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac := by - rw [hac]; exact ⟨rfl, rfl⟩ - have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl - have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by - intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h - have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (J.signal_atN hAT hmb hN p b hpN) ?_ - rintro ⟨s2, a2⟩ ⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩ - exact hmask s2 a2 σ' (hwhen σ' (by rw [hsp]; rfl)) ⟨_, H, Cs, Ac', Lst'', D', J', inferInstance⟩ - | _ => - simp only [bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) - rw [if_neg h1] - by_cases h2 : v = 2#u64 - · -- the timer line - rw [if_pos h2] - have htm : σ.interruptStates i = .irqTimer := by rw [hst, h2]; rfl - step with P1.LawfulStore.cur_cpu_spec as ⟨cc, ecc⟩ - step with P1.obj.node_set.spec as ⟨s2, es2⟩ - step with P1.obj.node_set.spec as ⟨s3, es3⟩ - subst es2 es3 ecc - have J2 := J.reprogramJ - obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 - try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, Z, H, Cs, Ac3, Lst3, D3, J3, inferInstance⟩ - rw [if_neg h2] - by_cases h3 : v = 3#u64 - · -- an IPI state on a line other than the IPI lines: reserved, nothing - rw [if_pos h3] - have hres : σ.interruptStates i = .irqReserved := by rw [hst, h3]; rfl - unfold smp.handle_ipi - rw [irq_resched_eq] - have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) - simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ - rw [if_neg h3] - by_cases h0 : v = 0#u64 - · -- an inactive line: the spec fails - have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl hin - · have hres : σ.interruptStates i = .irqReserved := by - rw [hst]; unfold irqSt; simp [h0, h1, h2] - simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ - + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.handleIrqJBT hARI hAT hmb hN w i hwi h126 h127 fun a1 c h => hIP.ackAR a1 w c h) + fun _ h => h.imp And.left fun ⟨z, hz, hN'⟩ => ⟨z, hz, hN'.toJAt J⟩ variable (arI) in /-- What the covered preemption path ends in under `IrqPlatI`: `JAt` after an diff --git a/proofs/Fl4Proofs/P3/XTopJointIrqZR.lean b/proofs/Fl4Proofs/P3/XTopJointIrqZR.lean index ab90cc4ee..c069404a0 100644 --- a/proofs/Fl4Proofs/P3/XTopJointIrqZR.lean +++ b/proofs/Fl4Proofs/P3/XTopJointIrqZR.lean @@ -17,6 +17,15 @@ untouched): `BlkOK`; `JAtZ.armedJ` by `JAtZ.schedJ`); * reserved/IPI lines: nothing; an inactive line: the spec fails. +(mmuAD gen 42b71, ruling (c2) item 1) **`JAtZB.handleIrqJB`**: the handler from a `JAtZB` state (no `JExt`) in the +native scope, every branch a native step from the start (post `JAtN`, XTopJointNoFault): the signal by ScSignalJN's +`JAtZB.signal_atN`, the masks / acknowledgements by XTopJointPreemptZ's `JAtZB.msArJ`, the timer's two node words by +ScFireJ's `JAtZB.reprogramJ` / `reprogramN` and **`JAtZB.armedJ`** / **`armedN`**; a machine-state predicate `MR` is +carried by the facts given for the mask, the acknowledgement and the signal. `JAtZB.handleIrqJBT` is it at +`MR := True`. The six `JAtZ` handlers (`handleIrqJJN` here, `handleIrqJIN`, `handleIrqJIAN`, `handleIrqJIM`, +`handleIrqJIMSt`, `handleIrqJIANM`) were ~200-line copies of one proof; they are now its corollaries (`JAtN.toJAt` / +`JAtN.toJStab`), statements unchanged. No premise added. + `JIrqHypJ` / `jIrqHypJ_of` (no premise beyond `jIrqHypZ_of`'s); `JHole.afterInvJZJ` / `afterInv_of_mcsJ`: XTopJointPreemptZ/I's `afterInvJZ` / `afterInv_of_mcs` with `PPQJ` after (spec failure or `JAt`, no @@ -72,34 +81,94 @@ theorem JAtZ.armedJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) JAtZ (L := L) arI AR Z H Cs Ac' Lst' D' (L.wr s (L.nodeAt s c layout.node.ARMED) v) a σ := J.schedJ (armed_schedStep hc v) +/-- (mmuAD gen 42b71) **The `ARMED` write is a native step** (a word of the current core's node, `SFoot`; the spec's +heap kept): `JAtZB.armedJ`'s footprint. -/ +theorem JAtZB.armedN {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {c : U64} (hc : L.cpu s = c) (v : U64) : + NatFoot (L := L) Z s σ (L.wr s (L.nodeAt s c layout.node.ARMED) v) σ := by + subst hc + obtain ⟨Q, R0, hcc, -⟩ := J.xtop.fin.1.1.1.lists + rw [hcc.cur] + exact NatFoot.ofT J.xtop (WritesIn.tfoot_of_kfoot (WritesIn.kfoot_of_sfoot + (sfoot_wr_node hcc.node (o := layout.node.ARMED) (by simp [layout.node.ARMED]) (by simp [layout.node.ARMED]) v))) + (fun _ h => J.tfoot_nh h) (NatK.of_kheap rfl) + +/-- (mmuAD gen 42b71) **The `ARMED` write at `JAtZB`** (`JAtZB.schedJ`; `JAtZ.armedJ`'s `JAtZB` form). -/ +theorem JAtZB.armedJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {c : U64} (hc : L.cpu s = c) (v : U64) : + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' (L.wr s (L.nodeAt s c layout.node.ARMED) v) a σ := + J.schedJ (armed_schedStep hc v) + +/-- (mmuAD gen 42b75) **The timer line's two writes**: `REPROGRAM := 1` and `ARMED := 0` of the executing core's +node, the only words `handle_interrupt`'s timer arm writes. -/ +theorem JAtZB.tmArm_w {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) : + P1.WritesIn st s (L.wr (L.wr s (L.nodeAt s (L.cpu s) layout.node.REPROGRAM) 1#u64) + (L.nodeAt (L.wr s (L.nodeAt s (L.cpu s) layout.node.REPROGRAM) 1#u64) (L.cpu s) layout.node.ARMED) 0#u64) + (fun b => b = L.nodeAt s (L.cpu s) layout.node.REPROGRAM ∨ b = L.nodeAt s (L.cpu s) layout.node.ARMED) := by + obtain ⟨Q, R0, hc, -⟩ := J.xtop.fin.1.1.1.lists + have hN := hc.node + rw [hc.cur] + have hA1 : P1.Aligned (L.nodeAt s Z.c layout.node.REPROGRAM) := + P1.nodeAt_aligned hN (by simp [layout.node.REPROGRAM]) (by simp [layout.node.REPROGRAM]) + have hA2 : P1.Aligned (L.nodeAt s Z.c layout.node.ARMED) := + P1.nodeAt_aligned hN (by simp [layout.node.ARMED]) (by simp [layout.node.ARMED]) + rw [P1.nodeAt_of_ksb (L.ksb_wr _ _ _)] + exact (P1.writesIn_wr (s := s) hA1).trans + (P1.writesIn_wr (s := L.wr s (L.nodeAt s Z.c layout.node.REPROGRAM) 1#u64) hA2) + set_option maxHeartbeats 16000000 in -/-- **`handle_interrupt` from a `JAtZ` state** (module docstring; the -branches of XTopJointIrq's `JHole.handleIrqJ` at `JAtZ`). -/ -theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlat arI AR) - (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) +/-- (mmuAD gen 42b72) **`handle_interrupt` from a `JAtZB` state, over any spec signal `sig` and any post `Q`**: the +proof of gen 42b71's `JAtZB.handleIrqJB` with the signal arm given (`hSigQ`: FL4's `send_signal` at the start against +`sig`, deterministic, `Q` after) and the native arms closed into `Q` (`hNQ`: a native run `JAtN` from the start; +`hQms`: a machine-state change of the same memory and an `AR` arch state; `hQAR`: `Q` reads `AR`). The spec handler is +`hiS sig` (XTopJointIrq). `JAtZB.handleIrqJB` is it at `sig := sendSignal`, `Q := JAtN …` (P3/VmOracle's +`VmEptState.handleIrqVF` at `sendSignalVF`, `Q := VmEptState`). (gen 42b75) `hNQ` also gets the native arm's writes +(none, or the timer line's `REPROGRAM` / `ARMED`, `JAtZB.tmArm_w`) and the spec heap kept (P3/VmOracle's +`VmEptState.handleIrqVFk` keeps `VmOrc` with them). -/ +theorem JAtZB.handleIrqJG {MR : A → Fl4Spec.MachineState → Prop} + {sig : Fl4Spec.ObjRef → Fl4Spec.Badge → Fl4Spec.SMonad Unit Unit} {Q : S → A → Fl4Spec.State Unit → Prop} + (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] - (hN : NativeScope σ) - (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) : + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hR : MR a σ.machineState) + (hNQ : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit}, JAtN (L := L) arI AR Z H Cs s σ s1 a1 σ1 → + P1.WritesIn st s s1 (fun b => b = L.nodeAt s (L.cpu s) layout.node.REPROGRAM ∨ + b = L.nodeAt s (L.cpu s) layout.node.ARMED) → σ1.kheap = σ.kheap → Q s1 a1 σ1) + (hQms : ∀ {s1 : S} {a1 a2 : A} {σ1 : Fl4Spec.State Unit} (ms : Fl4Spec.MachineState), Q s1 a1 σ1 → + ms.underlyingMemory = σ1.machineState.underlyingMemory → AR a2 σ1.archState.x64CurrentCr3 → + Q s1 a2 { σ1 with machineState := ms }) + (hQAR : ∀ {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit}, Q s1 a1 σ1 → AR a1 σ1.archState.x64CurrentCr3) + (hSigQ : ∀ p b : U64, p ∈ Z.N → notification.send_signal st arI s a p b ⦃ r => + ∃ σ' : Fl4Spec.State Unit, sig p.bv b.bv σ = ({((), σ')}, False) ∧ Q r.1 r.2 σ' ⦄) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) + (hackAR : ∀ (a1 : A) (c : Fl4Spec.Cr3), AR a1 c → arI.ack_irq a1 w ⦃ a2 => AR a2 c ⦄) + (hMmask : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → arI.mask_irq a0 w true = ok a1 → + MR a1 (maskMs σ0 i true).machineState) + (hMack : ∀ (a1 : A) (ms : Fl4Spec.MachineState), MR a1 ms → arI.ack_irq a1 w ⦃ a2 => MR a2 ms ⦄) + (hMsig : ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (sig n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄) : interrupt.handle_interrupt st arI s a w ⦃ r => - (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ MR r.2 z.2.machineState ⦄ := by have hX := J.xtop have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by apply BitVec.eq_of_toNat_eq; simp [hwi] - -- the acknowledgement keeps `JAt` + -- the acknowledgement keeps `JAtN` and `MR` have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JAt (L := L) arI AR s1 a1 z.2 → + z ∈ (hiS sig i σ).1 → Q s1 a1 z.2 → + MR a1 z.2.machineState → (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s1 a1 z hz ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ - refine WP.spec_bind (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) ?_ - intro a2 hA2 - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, Z1, H1, Cs1, Ac1, Lst2, D1, J2, inferInstance⟩) + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := by + intro s1 a1 z hz hJ1 hm1 + refine WP.spec_bind (WP.spec_and (hackAR a1 _ (hQAR hJ1)) (hMack a1 _ hm1)) ?_ + rintro a2 ⟨hA2, hM2⟩ + exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, hQms z.2.machineState hJ1 rfl hA2, hM2⟩) + have J0 : Q s a σ := hNQ (JAtN.of J (NatFoot.refl Z s σ)) (P1.WritesIn.refl s _) rfl unfold interrupt.handle_interrupt rw [irq_max_eq] simp only [bind_ok] @@ -114,8 +183,7 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP rw [ha1] simp only [bind_ok] have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) ⟨Z, H, Cs, Ac, Lst1, D, J1, inferInstance⟩ + exact hack s a1 _ (mem_hiS_big sig hgt σ) (hQms _ J0 rfl hA1) (hMmask a a1 σ hR ha1) · rw [if_neg hbig] have hw : w.val ≤ 125 := by have : ¬ 127 < w.val := hbig @@ -130,18 +198,21 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] set v := L.mem s (irqStA (L.ksb s) w) with hv -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ → + have key : ∀ m : Result (S × A), m ⦃ r => + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ → (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := by intro m hm refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1⟩) + rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1, hm1⟩) · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ intro a2 _ exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 + · exact hack s1 a1 z hz hJ1 hm1 refine key _ ?_ by_cases h1 : v = 1#u64 · -- a signal line @@ -163,23 +234,25 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP -- the mask after the cap's case have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JAt (L := L) arI AR s3 a2 σ1 → + (sig (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → + Q s3 a2 σ1 → MR a2 σ1.machineState → (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s3 a2 σ1 h1' ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := by + intro s3 a2 σ1 h1' hJ1 hm2 obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true rw [ha3] simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', Z1, H1, Cs1, Ac1, Lst3, D1, J3, inferInstance⟩ + have hA3 := hARI.mask _ _ _ (hQAR hJ1) (Or.inr (Or.inl ⟨w, true, ha3⟩)) + exact Or.inr ⟨((), maskMs σ1 i true), mem_hiS_signal sig hle hsig hgc h1', + hQms _ hJ1 rfl hA3, hMmask a2 a3 σ1 hm2 ha3⟩ have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + (σ.interruptStates i = .irqInactive ∧ (hiS sig i σ).2) ∨ + ∃ z ∈ (hiS sig i σ).1, Q r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := + fun hP => hmask s a σ (mem_when_false hP _ σ) J0 hR cases c with | Notification p b sd rv => cases sd with @@ -192,15 +265,16 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP rw [hac]; exact ⟨rfl, rfl⟩ have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → + have hwhen : ∀ σ1, ((), σ1) ∈ (sig p.bv b.bv σ).1 → ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by + (sig (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (J.signal_atN hAT hmb hN p b hpN) ?_ - rintro ⟨s2, a2⟩ ⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩ - exact hmask s2 a2 σ' (hwhen σ' (by rw [hsp]; rfl)) ⟨_, H, Cs, Ac', Lst'', D', J', inferInstance⟩ + refine WP.spec_bind (WP.spec_and (hSigQ p b hpN) (hMsig s a σ p b hR)) ?_ + rintro ⟨s2, a2⟩ ⟨⟨σ', hsp, hQ'⟩, hm2⟩ + have hmem : ((), σ') ∈ (sig p.bv b.bv σ).1 := by rw [hsp]; rfl + exact hmask s2 a2 σ' (hwhen σ' hmem) hQ' (hm2 σ' hmem) | _ => simp only [bind_ok] exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) @@ -216,7 +290,8 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP have J2 := J.reprogramJ obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, Z, H, Cs, Ac3, Lst3, D3, J3, inferInstance⟩ + exact Or.inr ⟨_, mem_hiS_timer sig hle htm, + hNQ (JAtN.of J3 (J.natTrans J.reprogramN (J2.armedN (L.cpu_wr _ _ _) 0#u64))) J.tmArm_w rfl, hR⟩ rw [if_neg h2] by_cases h3 : v = 3#u64 · -- an IPI state on a line other than the IPI lines: reserved, nothing @@ -226,18 +301,90 @@ theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP rw [irq_resched_eq] have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + exact Or.inr ⟨_, mem_hiS_reserved sig hle hres, J0, hR⟩ rw [if_neg h3] by_cases h0 : v = 0#u64 · -- an inactive line: the spec fails have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl (fail_hi_inactive hle hin) + exact Or.inl ⟨hin, fail_hiS_inactive sig hle hin⟩ · have hres : σ.interruptStates i = .irqReserved := by rw [hst]; unfold irqSt; simp [h0, h1, h2] simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + exact Or.inr ⟨_, mem_hiS_reserved sig hle hres, J0, hR⟩ + +/-- (mmuAD gen 42b71, ruling (c2) item 1) **`handle_interrupt` from a `JAtZB` state in the native scope, every branch +a native step** (module docstring): the post `JAtN` from the start (no `JExt`), with a machine-state predicate `MR` +carried by the given facts of the mask (`hMmask`), the acknowledgement (`hMack`) and the signal (`hMsig`); the +`AR` fact of the acknowledgement is `hackAR` (`IrqPlat.ackAR` / `IrqPlatA.ackAR`). The `JAtZ` handlers +`handleIrqJJN`, `handleIrqJIN` (XTopJointIrqZI), `handleIrqJIAN` (XTopJointMRPath), `handleIrqJIM` +(XTopJointKEntryEv2), `handleIrqJIMSt` (StPostIrqLeaf) and `handleIrqJIANM` (XTopJointKEntry38) are its corollaries. +(gen 42b72) `JAtZB.handleIrqJG` at `sig := sendSignal`, `Q := JAtN …` (the signal by `JAtZB.signal_atN`). -/ +theorem JAtZB.handleIrqJB {MR : A → Fl4Spec.MachineState → Prop} (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) (hR : MR a σ.machineState) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) + (hackAR : ∀ (a1 : A) (c : Fl4Spec.Cr3), AR a1 c → arI.ack_irq a1 w ⦃ a2 => AR a2 c ⦄) + (hMmask : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → arI.mask_irq a0 w true = ok a1 → + MR a1 (maskMs σ0 i true).machineState) + (hMack : ∀ (a1 : A) (ms : Fl4Spec.MachineState), MR a1 ms → arI.ack_irq a1 w ⦃ a2 => MR a2 ms ⦄) + (hMsig : ∀ (s1 : S) (a1 : A) (σ1 : Fl4Spec.State Unit) (n b : U64), MR a1 σ1.machineState → + notification.send_signal st arI s1 a1 n b ⦃ r => ∀ σ', ((), σ') ∈ (Fl4Spec.sendSignal (Z := Unit) n.bv b.bv σ1).1 → + MR r.2 σ'.machineState ⦄) : + interrupt.handle_interrupt st arI s a w ⦃ r => + (σ.interruptStates i = .irqInactive ∧ (Fl4Spec.handleInterrupt (Z := Unit) i σ).2) ∨ + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := + J.handleIrqJG (sig := Fl4Spec.sendSignal) (Q := JAtN (L := L) arI AR Z H Cs s σ) hARI hAT hR (fun h _ _ => h) + (fun ms ⟨V, Ac1, Lst1, D1, B1, F1⟩ hum hA => by + obtain ⟨Lst2, B2, F2⟩ := B1.msArJ ms _ hum (fun _ => hA) + exact ⟨V, Ac1, Lst2, D1, B2, J.natTrans F1 F2.cast⟩) + (fun ⟨_, _, _, _, B1, _⟩ => B1.xtop.fin.1.1.2.2.2.2.2.2) + (fun p b hp => WP.spec_mono (J.signal_atN hAT hmb hN p b hp) fun _ ⟨σ', _, _, _, hsp, _, J', F'⟩ => + ⟨σ', hsp, JAtN.of J' F'⟩) + w i hwi h126 h127 hackAR hMmask hMack hMsig + +/-- (mmuAD gen 42b71) **`JAtN` composed**: a native run from a `JAtZB` base `(s0, σ0)` to `(s1, σ1)`, then a native +run at `Z.mv Z.G V` from `(s1, σ1)` (`JAtZB.natTrans`, `NatFoot.cast`). -/ +theorem JAtN.trans {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0) + {V : XVs} {s1 : S} {σ1 : Fl4Spec.State Unit} (F1 : NatFoot (L := L) Z s0 σ0 s1 σ1) {s2 : S} {a2 : A} + {σ2 : Fl4Spec.State Unit} (h : JAtN (L := L) arI AR (Z.mv Z.G V) H Cs s1 σ1 s2 a2 σ2) : + JAtN (L := L) arI AR Z H Cs s0 σ0 s2 a2 σ2 := + match h with + | ⟨V', Ac', Lst', D', B', F2⟩ => ⟨V', Ac', Lst', D', B', J0.natTrans F1 F2.cast⟩ + +/-- (mmuAD gen 42b71) `JAtZB.handleIrqJB` without a machine-state predicate (`MR := True`). -/ +theorem JAtZB.handleIrqJBT (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) + (hackAR : ∀ (a1 : A) (c : Fl4Spec.Cr3), AR a1 c → arI.ack_irq a1 w ⦃ a2 => AR a2 c ⦄) : + interrupt.handle_interrupt st arI s a w ⦃ r => + (σ.interruptStates i = .irqInactive ∧ (Fl4Spec.handleInterrupt (Z := Unit) i σ).2) ∨ + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.handleIrqJB (MR := fun _ _ => True) hARI hAT hmb hN trivial w i hwi h126 h127 hackAR + (fun _ _ _ _ _ => trivial) (fun a1 _ _ => WP.spec_mono (hAT.ack_irq a1 w) fun _ _ => trivial) + (fun s1 a1 _ n b _ => WP.spec_mono (Fl4Proofs.P0.notification.send_signal.p0 st arI s1 a1 n b L.total hAT) + fun _ _ _ _ => trivial)) + fun _ h => h.imp id fun ⟨z, hz, hN', _⟩ => ⟨z, hz, hN'⟩ + +/-- **`handle_interrupt` from a `JAtZ` state** (module docstring; the +branches of XTopJointIrq's `JHole.handleIrqJ` at `JAtZ`). (mmuAD gen 42b71) `JAtZB.handleIrqJBT`'s corollary +(`JAtN.toJAt`), statement unchanged. -/ +theorem JAtZ.handleIrqJJN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlat arI AR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + (hN : NativeScope σ) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) : + interrupt.handle_interrupt st arI s a w ⦃ r => + (Fl4Spec.handleInterrupt (Z := Unit) i σ).2 ∨ + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.handleIrqJBT hARI hAT hmb hN w i hwi h126 h127 fun a1 c h => hIP.ackAR a1 w c h) + fun _ h => h.imp And.right fun ⟨z, hz, hN'⟩ => ⟨z, hz, hN'.toJAt J⟩ /-- **`JIrqHypJ` per state** (g3e): at every `JAt` state with `NativeScope` there, no ∀-form `hNS`. -/ @@ -264,7 +411,7 @@ theorem PPQJ.toPPQ {σ1 : Fl4Spec.State Unit} {r : S × A} (h : PPQJ (L := L) ar PPQ (L := L) arI AR σ1 r := by rcases h with h | ⟨z, hz, ⟨Z, H, Cs, Ac, Lst, D, J, _⟩⟩ · exact Or.inl h - · exact Or.inr ⟨z, hz, Or.inl ⟨Z, H, Cs, Ac, Lst, D, _, _, _, J.toHole, inferInstance⟩⟩ + · exact Or.inr ⟨z, hz, Or.inl ⟨Z, H, Cs, Ac, Lst, D, _, _, _, J.toHole, J.ext, inferInstance⟩⟩ /-- **The holes `JPreemptRestHypE` covers** (kp14): outside `PPCov ∨ PPCovT ∨ PPCovI`, `CurInv`, a schedulable current thread, an insufficient head. -/ diff --git a/proofs/Fl4Proofs/P3/XTopJointJAtZRB.lean b/proofs/Fl4Proofs/P3/XTopJointJAtZRB.lean index 75bbbf26b..8da517699 100644 --- a/proofs/Fl4Proofs/P3/XTopJointJAtZRB.lean +++ b/proofs/Fl4Proofs/P3/XTopJointJAtZRB.lean @@ -1293,17 +1293,18 @@ section J variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} -namespace JAtZR -/-- **P1's kernel-write words of `JAtZR`'s sets miss the domain schedule** +namespace JKern +/-- **P1's kernel-write words of `JKern`'s heap miss the domain schedule** (IrqDom's `KWApart`), at any state with the same kernel-state base whose -cores' nodes are placed (P1's `TimerOK.npl`). -/ -theorem kwApartJ (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hk : L.ksb s' = L.ksb s) +cores' nodes are placed (P1's `TimerOK.npl`). (mmuAD gen 42b80) `JAtZR.kwApartJ`'s proof, which reads only `kern`, +moved here; `JAtZR.kwApartJ` is it at `J.kern`. -/ +theorem kwApartJ {th : TypedHeap} (J : JKern (L := L) arI H Cs D th s σ) {s' : S} (hk : L.ksb s' = L.ksb s) (hN : ∀ c ∈ Cs, P1.NodePlaced st (P1.Heap.tcbs H) s' c) : KWApart (L := L) (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s' := by - have hf := J.kern.ksbFit - have hal := J.kern.ksbAl - have hks := J.kern.hks - have hH := J.kern.heap + have hf := J.ksbFit + have hal := J.ksbAl + have hks := J.hks + have hH := J.heap intro b hb hkw unfold P1.Aligned at hb suffices h : b.val + 8 ≤ (L.ksb s).val ∨ (L.ksb s).val + 256 ≤ b.val by rw [hk]; exact h @@ -1359,6 +1360,13 @@ theorem kwApartJ (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hk omega · right; rw [hv]; omega +end JKern +namespace JAtZR +/-- **P1's kernel-write words of `JAtZR`'s sets miss the domain schedule** (`JKern.kwApartJ` at `kern`). -/ +theorem kwApartJ (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hk : L.ksb s' = L.ksb s) + (hN : ∀ c ∈ Cs, P1.NodePlaced st (P1.Heap.tcbs H) s' c) : + KWApart (L := L) (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s' := + J.kern.kwApartJ hk hN end JAtZR end J @@ -1924,6 +1932,19 @@ noncomputable section section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} +/-- (mmuAD gen 42b80) **`FpuOwnOK` kept by a step keeping the FPU owner** (`fpuOwnOK_firesZR`'s proof over the +fields it reads): the owner is a spec TCB before, hence a related TCB (ObjCover), and every related TCB is a spec +TCB after (`NtfnStateRel.tcb`). -/ +theorem fpuOwnOK_of_own {N T E R C : Set U64} {σ σ1 : Fl4Spec.State Unit} {m : U64 → U64} + (hO : Sched.ObjCover N T E R C σ) (hN : NtfnStateRel N T m σ1) + (how : σ1.archState.x64CurrentFpuOwner = σ.archState.x64CurrentFpuOwner) (hfo : FpuOwnOK σ) : FpuOwnOK σ1 := by + intro o ho + rw [how] at ho + obtain ⟨x, hx⟩ := hfo o ho + obtain ⟨t, ht, rfl⟩ := hO.tcb o x hx + obtain ⟨y, hy, -⟩ := hN.tcb t ht + exact ⟨y, hy⟩ + /-- **`FpuOwnOK` [J] after FL4's TCB timers from `FpuOwnOK` at the entry** (sch5 (A)): the timers keep the owner (`owF_fires`); the owner is a spec TCB at entry, hence a related TCB (`JAtZR.obj`, ObjCover), and every related TCB is a @@ -1931,13 +1952,8 @@ spec TCB after the timers (`NtfnStateRel.tcb`). -/ theorem fpuOwnOK_firesZR {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ σ1 : Fl4Spec.State Unit} {m : U64 → U64} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hF : Fires σ σ1) (hN : NtfnStateRel Z.N Z.T m σ1) - (hfo : FpuOwnOK σ) : FpuOwnOK σ1 := by - intro o ho - rw [owF_fires hF] at ho - obtain ⟨x, hx⟩ := hfo o ho - obtain ⟨t, ht, rfl⟩ := J.obj.tcb o x hx - obtain ⟨y, hy, -⟩ := hN.tcb t ht - exact ⟨y, hy⟩ + (hfo : FpuOwnOK σ) : FpuOwnOK σ1 := + fpuOwnOK_of_own J.obj hN (owF_fires hF) hfo @@ -1952,58 +1968,38 @@ noncomputable section section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} variable {AR : A → Fl4Spec.Cr3 → Prop} -/-- **`NdOK` after FL4's TCB timers** (module docstring). -/ +namespace JKern +/-- (mmuAD gen 42b80) **FL4's timers keep the kernel-global words** (G7eRoot's `JAtZR.fire_ks`, whose proof was +`JAtZR.ndOK_fire`'s: SchedIdx's `fire_ks_of` at the fields of `kern` and the cores' node placement). -/ +theorem fire_ks {H : P1.Heap} {Cs D : Set U64} {th : TypedHeap} {s : S} {σ : Fl4Spec.State Unit} + (J : JKern (L := L) arI H Cs D th s σ) (hN : ∀ c ∈ Cs, P1.NodePlaced st (P1.Heap.tcbs H) s c) {s1 : S} + {U : Set U64} (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) + (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) : + ∀ o : U64, o.val < 256 → o.val % 8 = 0 → L.mem s1 (ksW (L.ksb s) o) = L.mem s (ksW (L.ksb s) o) := + fire_ks_of J.ksbFit J.ksbAl J.hks J.heap (J.kwApartJ (s' := s) rfl hN) hN hf hU + +/-- (mmuAD gen 42b80) **`NdOK` after FL4's TCB timers** for any spec step keeping the domain schedule +(`JAtZR.ndOK_fire` over `kern`, the node placement and the domain fields). -/ +theorem ndOK_fire {H : P1.Heap} {Cs D : Set U64} {th : TypedHeap} {s : S} {σ σ1 : Fl4Spec.State Unit} + (J : JKern (L := L) arI H Cs D th s σ) (hN : ∀ c ∈ Cs, P1.NodePlaced st (P1.Heap.tcbs H) s c) + (hNd : NdOK (L := L) s σ) {s1 : S} + {U : Set U64} (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) + (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) + (hdl : σ1.domainList = σ.domainList) (hdi : σ1.domainIndex = σ.domainIndex) + (hds : σ1.domainStartIndex = σ.domainStartIndex) : NdOK (L := L) s1 σ1 := + hNd.keep hf.1 (J.fire_ks hN hf hU) hdl hdi hds +end JKern + +/-- **`NdOK` after FL4's TCB timers** (module docstring; `JKern.ndOK_fire` at `kern`, the domain schedule kept by +`fires_dom`). -/ theorem JAtZR.ndOK_fire {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ σ1 : Fl4Spec.State Unit} (J : JAtZR (L := L) arI AR Z H Cs Ac Lst D s a σ) (hNd : NdOK (L := L) s σ) {s1 : S} {U : Set U64} (hf : P1.FootDU st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) U s s1) (hU : ∀ b ∈ U, ∀ o : U64, o.val < 13568 → o.val % 8 = 0 → core.num.U64.wrapping_add (L.ksb s) o ≠ b) (hF : Fires σ σ1) : NdOK (L := L) s1 σ1 := by - have hkf := J.kern.ksbFit - have hka := J.kern.ksbAl - have hks := J.kern.hks - have hH := J.kern.heap - have hKW := J.kwApartJ (s' := s) rfl (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) obtain ⟨hdl, hdi, hds⟩ := fires_dom hF - refine hNd.keep hf.1 (fun o ho h8 => hf.mem_eq (ksW_al hkf hka ho h8) fun hb => ?_) hdl hdi hds - rcases hb with hb | hu - swap - · exact hU _ hu o (by omega) h8 rfl - have hv := ksW_val (kb := L.ksb s) (o := o) (by omega) - rcases hb with hb | hb - · rcases hKW _ (ksW_al hkf hka ho h8) hb with e | e <;> rw [hv] at e <;> omega - · rcases hb with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ - · have hy' : H y = some .tcb := hy - have hfit := hH.fits y _ hy' - simp only [P1.HKind.bits] at hfit - have h12 : (2 : Nat) ^ 12 = 4096 := by norm_num - rw [h12] at hfit - have hdv : (P1.dnA y).val = y.val + 3576 := by - unfold P1.dnA; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega - have h3 := hks y .tcb hy' (fun z h => by cases h) - simp only [P1.HKind.bits, h12] at h3 - have := congrArg UScalar.val e - rw [hv, hdv] at this - omega - · have hy' : H y = some .tcb := hy - have hfit := hH.fits y _ hy' - simp only [P1.HKind.bits] at hfit - have h12 : (2 : Nat) ^ 12 = 4096 := by norm_num - rw [h12] at hfit - have hdv : (P1.dpA y).val = y.val + 3584 := by - unfold P1.dpA; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega - have h3 := hks y .tcb hy' (fun z h => by cases h) - simp only [P1.HKind.bits, h12] at h3 - have := congrArg UScalar.val e - rw [hv, hdv] at this - omega - · have hnv := P1.nodeAt_val (J.blk.2.2.1.2.2.tm.npl c hc) (off := layout.node.DEBUG_TCBS) (by simp) - unfold P1.LawfulStore.nodeBase at hnv - have := congrArg UScalar.val e - rw [hv, hnv] at this - simp [layout.node.DEBUG_TCBS] at this - omega - + exact J.kern.ndOK_fire (fun c hc => J.blk.2.2.1.2.2.tm.npl c hc) hNd hf hU hdl hdi hds end end end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/XTopJointKEntry38.lean b/proofs/Fl4Proofs/P3/XTopJointKEntry38.lean index c1207362d..dfc44752c 100644 --- a/proofs/Fl4Proofs/P3/XTopJointKEntry38.lean +++ b/proofs/Fl4Proofs/P3/XTopJointKEntry38.lean @@ -38,6 +38,9 @@ P3 (DESIGN.md §9), invariant line G4 (g4d, KENTRY-PLAN g4d; g4b's handoff): without `hDM` (`JDispMRI`), with `hDL : JDecMRL` [W] at the same dispatch states; **`kernel_entry_reachMD`** = `kernel_entry_reachMI` with `hDL` for `hDM`. + +(mmuAD gen 42b71) `JAtZ.handleIrqJIANM` is XTopJointIrqZR's `JAtZB.handleIrqJB` corollary (the facts of `MR` given by +`mask_mr`, `MachPlat.ack`, `MKD.notification_send_signal` / `mtk_sendSignal'`), statement unchanged, copy removed. -/ import Fl4Proofs.P3.XTopJointKEntry37 import Fl4Proofs.P3.MachKeepG4d @@ -554,7 +557,7 @@ theorem mask_mr (hM : MachPlat arI MR) {a a1 : A} {σ : Fl4Spec.State Unit} {w : rw [← hiw, show (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = w.bv.setWidth 8 from BitVec.ofNat_toNat 8 w.bv] exact h -set_option maxHeartbeats 16000000 in +set_option maxHeartbeats 4000000 in /-- **`handleIrqJIAN` with `MR` at the chosen outcome**: the mask by `MachPlat.mask` (`mask_mr`), the acknowledgement by `MachPlat.ack`, the signal by `MKD.notification_send_signal` and `mtk_sendSignal'`. -/ @@ -566,163 +569,13 @@ theorem JAtZ.handleIrqJIANM (hM : MachPlat arI MR) (hKD : MRKeepD arI MR) (hARI interrupt.handle_interrupt st arI s a w ⦃ r => σ.interruptStates i = .irqInactive ∨ ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ := by - have hX := J.xtop - have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 - have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by apply BitVec.eq_of_toNat_eq; simp [hwi] - -- the acknowledgement keeps `JAt` - have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JAtM (L := L) arI AR MR s1 a1 z.2 → - (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ := by - rintro s1 a1 z hz ⟨⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩, hR1⟩ - refine WP.spec_bind (WP.spec_and (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) (hM.ack a1 w _ hR1)) ?_ - rintro a2 ⟨hA2, hR2⟩ - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, ⟨Z1, H1, Cs1, Ac1, Lst2, D1, J2, inferInstance⟩, hR2⟩) - unfold interrupt.handle_interrupt - rw [irq_max_eq] - simp only [bind_ok] - by_cases hbig : w > 127#u64 - · -- above FL4's maximum - rw [if_pos hbig] - have hgt : i > Fl4Spec.maxIRQ := by - have : 127 < w.val := hbig - show (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - rw [ha1] - simp only [bind_ok] - have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) ⟨⟨Z, H, Cs, Ac, Lst1, D, J1, inferInstance⟩, mask_mr hM hR ha1 (by rw [hwi]; exact i.isLt) hiw⟩ - · rw [if_neg hbig] - have hw : w.val ≤ 125 := by - have : ¬ 127 < w.val := hbig - omega - have hw128 : w.val < 128 := by omega - have hle : ¬ i > Fl4Spec.maxIRQ := by - show ¬ (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - have hst : σ.interruptStates i = irqSt (L.mem s (irqStA (L.ksb s) w)) := by - rw [← hiw]; exact hIR.st w hw128 - rw [irq_state_eq'] - simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] - set v := L.mem s (irqStA (L.ksb s) w) with hv - -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ → - (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ := by - intro m hm - refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1⟩) - · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ - intro a2 _ - exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 - refine key _ ?_ - by_cases h1 : v = 1#u64 - · -- a signal line - rw [if_pos h1] - have hsig : σ.interruptStates i = .irqSignal := by rw [hst, h1]; rfl - have hL : IntLayout Z.th (L.ksb s) := J.intL - have hnode := hL.node w hw128 - obtain ⟨cs, hkc, hwf, hsl⟩ := hX.rel.2.1.1.cnode _ 0 hnode - obtain ⟨c, ac, hcap, hcs, hCR⟩ := hsl [] rfl - rw [show slotAddr (nodeA (L.ksb s) w).bv (Fl4Spec.ofBl []) = nodeA (L.ksb s) w from - cslotAddr_nil _] at hcap - have hgc : Fl4Spec.getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False) := by - rw [← hiw, hIR.node w hw128]; exact getCap_cnode hkc hwf hcs - have hac : ac = absCap c := hCR.abs - rw [irq_slot_eq] - simp only [bind_ok] - rw [slot_cap_eq, hcap] - simp only [bind_ok] - -- the mask after the cap's case - have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JAtM (L := L) arI AR MR s3 a2 σ1 → - (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ := by - rintro s3 a2 σ1 h1' ⟨⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩, hR1⟩ - obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true - rw [ha3] - simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', ⟨Z1, H1, Cs1, Ac1, Lst3, D1, J3, inferInstance⟩, - mask_mr hM hR1 ha3 (by rw [hwi]; exact i.isLt) hiw⟩ - have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), - (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtM (L := L) arI AR MR r.1 r.2 z.2 ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) ⟨⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩, hR⟩ - cases c with - | Notification p b sd rv => - cases sd with - | false => - simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap, Fl4Spec.capRights, Fl4Spec.AllowSend, rightsOf]) - | true => - simp only [↓reduceIte] - have hP : Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac := by - rw [hac]; exact ⟨rfl, rfl⟩ - have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl - have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by - intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h - have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (WP.spec_and (J.signal_atN hAT hmb hN p b hpN) - (MKD.notification_send_signal L.total hAT hKD hR)) ?_ - rintro ⟨s2, a2⟩ ⟨⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩, hR2⟩ - exact hmask s2 a2 σ' (hwhen σ' (by rw [hsp]; rfl)) ⟨⟨_, H, Cs, Ac', Lst'', D', J', inferInstance⟩, msF_mr hM hR2 - (congrArg Prod.fst (MachT.mtk_sendSignal' p.bv b.bv σ ((), σ') (by rw [hsp]; exact Set.mem_singleton _)))⟩ - | _ => - simp only [bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) - rw [if_neg h1] - by_cases h2 : v = 2#u64 - · -- the timer line - rw [if_pos h2] - have htm : σ.interruptStates i = .irqTimer := by rw [hst, h2]; rfl - step with P1.LawfulStore.cur_cpu_spec as ⟨cc, ecc⟩ - step with P1.obj.node_set.spec as ⟨s2, es2⟩ - step with P1.obj.node_set.spec as ⟨s3, es3⟩ - subst es2 es3 ecc - have J2 := J.reprogramJ - obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 - try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, ⟨Z, H, Cs, Ac3, Lst3, D3, J3, inferInstance⟩, hR⟩ - rw [if_neg h2] - by_cases h3 : v = 3#u64 - · -- an IPI state on a line other than the IPI lines: reserved, nothing - rw [if_pos h3] - have hres : σ.interruptStates i = .irqReserved := by rw [hst, h3]; rfl - unfold smp.handle_ipi - rw [irq_resched_eq] - have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) - simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩, hR⟩ - rw [if_neg h3] - by_cases h0 : v = 0#u64 - · -- an inactive line: the spec fails - have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl hin - · have hres : σ.interruptStates i = .irqReserved := by - rw [hst]; unfold irqSt; simp [h0, h1, h2] - simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩, hR⟩ + exact WP.spec_mono (J.toB.handleIrqJB hARI hAT hmb hN hR w i hwi h126 h127 (fun a1 c h => hIP.ackAR a1 w c h) + (fun a0 a1 σ0 h0 he => mask_mr hM h0 he (by rw [hwi]; exact i.isLt) hiw) (fun a1 ms h => hM.ack a1 w ms h) + (fun s1 a1 σ1 n b h1 => WP.spec_mono (MKD.notification_send_signal L.total hAT hKD h1) fun _ hR2 σ' hmem => + msF_mr hM hR2 (congrArg Prod.fst (MachT.mtk_sendSignal' n.bv b.bv σ1 ((), σ') hmem)))) + fun _ h => h.imp And.left fun ⟨z, hz, hN', hm⟩ => ⟨z, hz, hN'.toJAt J, hm⟩ set_option maxHeartbeats 16000000 in @@ -792,7 +645,7 @@ theorem jPreemptRestHypEQ_ofIMM (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) r.1 = false ∧ PPQJIM (L := L) arI AR MR σ (r.2.1, r.2.2) ⦄ := by have hK := hKD.toK intro s a σ hJ hn hR hV hi hs hf hc hg hnq hC hsc hnsuf hcov - obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, _⟩ := hJ + obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, _⟩ := hJ have hnt : ¬ NoTmoSend σ := fun h => hcov (Or.inl ⟨hC, hi, hs σ.curThread, h⟩) unfold NoTmoSend at hnt simp only [not_or, not_forall] at hnt @@ -812,14 +665,14 @@ theorem jPreemptRestHypEQ_ofIMM (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) · exact absurd e (hs u) · exact Or.inr rfl by_cases hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe - · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hn (Hh.mcsPPJAM hA (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc hnsuf hkt - hrr hth hper hcb hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hn (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJAM hA (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc hnsuf hkt + hrr hth hper hcb hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · simp only [not_forall] at hcb obtain ⟨xe, hke, hncb⟩ := hcb obtain ⟨q, rfl⟩ : ∃ q, xe = .recvEP q := by revert hncb; cases xe <;> simp [Endp.CanBlock] - exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hn (Hh.mcsPPJRM hA hmax htu (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc - hnsuf hkt hrr hth hper ⟨q, hke⟩ hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hn (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJRM hA hmax htu (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc + hnsuf hkt hrr hth hper ⟨q, hke⟩ hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h set_option maxHeartbeats 4000000 in @@ -836,34 +689,34 @@ theorem hPre_ofZQIMNM (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4 r.1 = false ∧ PPQJIM (L := L) arI AR MR σ1 (r.2.1, r.2.2) ⦄ := by have hK := hKD.toK intro s1 a1 σ1 _ h hN1 - obtain ⟨⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hTs, _⟩, hni, hns, hfr, hct, hcg, hnq, hR, -, hV⟩ := + obtain ⟨⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, hTs, _⟩, hni, hns, hfr, hct, hcg, hnq, hR, -, hV⟩ := jAtPreMV_holeQ hARI.toARKeep hA hnd hM hPA h by_cases hc : PPCov σ1 ∨ PPCovT σ1 - · exact afterInv_of_mcsIMNM hKD (WP.spec_mono (Hh.mcsPPJZM hTs hA hnd (hmrt a1) (hPA.minBudget a1) hc hM hK hR hV) + · exact afterInv_of_mcsIMNM hKD (WP.spec_mono (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJZM hTs hA hnd (hmrt a1) (hPA.minBudget a1) hc hM hK hR hV)) fun _ ⟨σ', h1, h2, hJ, hR', hV', hn⟩ => ⟨σ', h1, h2, hJ, hR', hV', hn hN1⟩) hM hIA hARI hA hPA.minBudget _ by_cases hi : PPCovI σ1 - · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (Hh.mcsPPJIM hi hA hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) + · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJIM hi hA hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h by_cases hC : CurInv σ1 · cases hsc : Fl4Spec.schedulable σ1.curThread σ1 with | true => by_cases hsuf : ∀ y n, σ1.kheap σ1.curSc = some (.schedContext y n) → Fl4Spec.refillSufficient σ1.consumedTime (Fl4Spec.refillHd y) = true - · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (Hh.mcsPPJSM hTs hA hnd (hPA.minBudget a1) hC hni hsc hsuf hM hK hR hV)) + · exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJSM hTs hA hnd (hPA.minBudget a1) hC hni hsc hsuf hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · exact jPreemptRestHypEQ_ofIMM hARI hA hM hKD hPA hIA hmrt hmax htu s1 a1 σ1 - ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, inferInstance⟩ + ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, inferInstance⟩ hN1 hR hV hni hns hfr hct hcg hnq hC hsc hsuf fun h' => h'.elim (fun h2 => hc (Or.inl h2)) fun h2 => h2.elim (fun h3 => hc (Or.inr h3)) hi | false => - exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (Hh.mcsPPJCM hA (hmrt a1) (hPA.minBudget a1) hC hni hns hsc hM hK hR hV)) + exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJCM hA (hmrt a1) (hPA.minBudget a1) hC hni hns hsc hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · have hsch : Fl4Spec.schedulable σ1.curThread σ1 = false := by cases e : Fl4Spec.schedulable σ1.curThread σ1 with | false => rfl | true => exact absurd (curInv_of_sched hct e) hC - exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (Hh.mcsPPJUM hA (hmrt a1) (hPA.minBudget a1) hC hct hfr hcg hsch hi - hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + exact WP.spec_mono (afterInv_of_mcsIMNM hKD (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJUM hA (hmrt a1) (hPA.minBudget a1) hC hct hfr hcg hsch hi + hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h end diff --git a/proofs/Fl4Proofs/P3/XTopJointKEntryEv2.lean b/proofs/Fl4Proofs/P3/XTopJointKEntryEv2.lean index 82d49ef6b..11e8e595e 100644 --- a/proofs/Fl4Proofs/P3/XTopJointKEntryEv2.lean +++ b/proofs/Fl4Proofs/P3/XTopJointKEntryEv2.lean @@ -8,6 +8,9 @@ P3 (DESIGN.md §9), invariant line G4 (g4f, KENTRY-PLAN g4f; g4e's handoff): `JAtZ` holds after (XTopJointPP's `timestampJ` for the sufficient head, ScChargeH's `timestampJH` and the hole's `checkBudgetF` / `checkBudgetT` / `checkBudgetTR` for the charge: `budgetOkB`'s cases without the restart). + +(mmuAD gen 42b71) **`JAtZB.handleIrqJBM`**: XTopJointIrqZR's `JAtZB.handleIrqJB` under `MachPlat` / `MRKeep`; +`JAtZ.handleIrqJIM` its corollary (statement unchanged, copy removed). -/ import Fl4Proofs.P3.XTopJointKEntryEv import Fl4Proofs.P3.SpecInvG4f @@ -27,82 +30,63 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} -set_option maxHeartbeats 16000000 in -/-- **`update_timestamp; check_budget` at an entry state** (module -docstring). -/ -theorem JAtZ.utCheckB {s : S} {a : A} {σ0 : Fl4Spec.State Unit} - (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ0) [VxE Z] (hni0 : Entered σ0) (hBu : KBudgetB arI a σ0) - (hNS0 : NativeScope σ0) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) +set_option maxHeartbeats 4000000 in +/-- The budget check from a timestamp hole. A current VM thread suppresses +timeout delivery, as in both implementations of end timeslice. -/ +theorem JHole.checkBudgetNat {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} + {s1 : S} {a1 : A} {σ1 : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s1 a1 σ1) + (hni : Entered σ1) (hOff : OffReady σ1) + (hTmo : NoTmoSend σ1 ∨ ∀ d p, σ1.curThread ∉ σ1.readyQueues d p) + (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) - (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : - (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => - ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1, z.1 = r.1 ∧ - ∃ (Z' : XSets) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR Z' H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ VxE Z' ⦄ := by - have hnow := hBu.now - have hS := J0.xtop.fin.1.1.1 - have hR := J0.xtop.fin.1.1.2.2.1 - have hnow' : arI.now a ⦃ r => ∃ ms, Fl4Spec.doMachineOp (Z := Unit) Fl4Spec.getCurrentTime σ0 = - ({(r.1.bv, { σ0 with machineState := ms })}, False) ∧ σ0.curTime ≤ r.1.bv ⦄ := - WP.spec_mono hnow fun _ ⟨ms, h1, h2, _⟩ => ⟨ms, h1, h2⟩ - refine WP.spec_bind (WP.spec_and (WP.spec_and (J0.timestampJ arI hAK hA hnd hnow) (J0.timestampJH hAK hA hnd hnow)) - (update_timestamp_refines s a σ0 hS hR J0.nsc hnd hnow')) ?_ - rintro ⟨s1, a1⟩ ⟨⟨⟨σ1, h1, -, -, -, -, -, hum1, hO1, hJ1⟩, ⟨σ1', h1', -, -, -, -, -, hum1', -, hH⟩⟩, - ⟨σ1'', h1'', hS1, -, -, hI1, hC1, -, -⟩⟩ - have e1 : σ1 = σ1' := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (Prod.mk.inj (h1.symm.trans h1')).1) - have e2 : σ1 = σ1'' := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (Prod.mk.inj (h1.symm.trans h1'')).1) - subst e1 e2 - have hsp0 : ∀ y, y ∈ (Fl4Spec.checkBudget (Z := Unit) σ1).1 → - y ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1 := by - intro y hy; rw [Notif.nd_bind_one h1]; exact hy - have Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ0 s1 a1 σ1 := hH σ1.machineState a1 hum1' id - have hI1 := hI1 J0.inv - have hC1 := hC1 hBu.cur - obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS1 hI1 hC1 - obtain ⟨-, -, -, -, ekh, ect, eact, eidle, -, -, -, -⟩ := Hh.sfacts - obtain ⟨ms1, tm1, cn1, -, eσ1⟩ := Hh.spec - have erq : σ1.readyQueues = σ0.readyQueues := by rw [eσ1] - have ecs : σ1.curSc = σ0.curSc := by rw [eσ1] - have hres1 : σ1.schedulerAction = .resumeCurThread := eact.trans hni0.2 - have hCH : CurInv σ1 := Hh.cur.resolve_left (by rw [hres1]; exact fun h => by cases h) - have hni1 : σ1.curThread ≠ σ1.idleThread := by rw [ect, eidle]; exact hni0.1 - have hnsw1 : σ1.schedulerAction ≠ .switchThread σ1.curThread := by rw [hres1]; exact fun h => by cases h + sched.check_budget st arI s1 a1 ⦃ r => + ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ1).1, z.1 = r.1 ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 r.2.1 z.2 ⦄ := by + have hS1 := Hh.xtop.fin.1.1.1 + obtain ⟨-, -, -, -, -, -, -, -, -, -, hRun, -⟩ := Hh.sfacts + have hres1 := hni.2 + have hCH : CurInv σ1 := Hh.cur.resolve_left (by rw [hres1]; intro h; cases h) + obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS1 Hh.inv hCH + have hni1 := hni.1 + have hnsw1 : σ1.schedulerAction ≠ .switchThread σ1.curThread := by rw [hres1]; intro h; cases h -- the charge (the head is insufficient) have hFalse : sched.check_budget st arI s1 a1 ⦃ r => r.1 = false → ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ1).1, z.1 = false ∧ - ∃ (Z' : XSets) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR Z' H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ VxE Z' ⦄ := by - by_cases hnt : NoTmoSend σ1 - · refine WP.spec_mono (Hh.checkBudgetF hA hCH hni1 hnsw1 (hmrt a1) (hmb a1) hnt) ?_ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ NatFoot (L := L) Z s0 σ0 r.2.1 z.2 ⦄ := by + by_cases hnt : NoTmoSend σ1 ∨ ∃ x, σ1.kheap σ1.curThread = some (.tcb x) ∧ x.tcbState = .runningVM + · refine WP.spec_mono (Hh.checkBudgetFG hA hCH hni1 hnsw1 (hmrt a1) (hmb a1) hnt) ?_ rintro ⟨rb, s2, a2⟩ hB hf - obtain ⟨ea, σ2, hcb, -, Lst2, J2⟩ := hB hf - simp only at ea J2 + obtain ⟨ea, σ2, hcb, -, Lst2, J2, F2⟩ := hB hf + simp only at ea J2 F2 subst ea - exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, Z, Ac, Lst2, D, J2, inferInstance⟩ - have hnq1 : ∀ d q, σ1.curThread ∉ σ1.readyQueues d q := by - rcases hBu.tmo with hnt0 | hnq0 - · exact absurd (hnt0.of_eq ekh ect ecs) hnt - · rw [ect, erq]; exact hnq0 - unfold NoTmoSend at hnt - push_neg at hnt - obtain ⟨⟨xt, hkt, hep⟩, ⟨y, m, hky, hy⟩⟩ := hnt + exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, Z.vs, Ac, Lst2, D, J2, F2⟩ + have hnt0 := hnt + have hnq1 := hTmo.resolve_left (fun hn => hnt0 (Or.inl hn)) + have hnot : ¬ NoTmoSend σ1 := fun h => hnt (Or.inl h) + unfold NoTmoSend at hnot + push_neg at hnot + obtain ⟨⟨xt, hkt, hep⟩, ⟨y, m, hky, hy⟩⟩ := hnot have hper : ∀ x n, σ1.kheap σ1.curSc = some (.schedContext x n) → x.scPeriod ≠ 0 := fun x n h => by rw [hky] at h; cases h; exact hy obtain ⟨p, bd, rr, hth⟩ : ∃ p bd rr, xt.tcbTimeoutHandler = .endpointCap p bd rr := by revert hep; cases xt.tcbTimeoutHandler <;> simp [Fl4Spec.isEpCap] - have hkt0 : σ0.kheap σ0.curThread = some (.tcb xt) := by rw [← ekh, ← ect]; exact hkt have hrr : xt.tcbState = .running ∨ xt.tcbState = .restart := by - have hrun := J0.curRun.run hni0 xt hkt0 - have hvm := hNS0 _ xt hkt0 - revert hrun hvm; cases xt.tcbState <;> simp [Fl4Spec.runnable] + have hrun := hRun.run hni xt hkt + have hvm : xt.tcbState ≠ .runningVM := fun h => hnt0 (Or.inr ⟨xt, hkt, h⟩) + revert hrun hvm + cases xt.tcbState <;> simp [Fl4Spec.runnable] by_cases hkl : ∃ l, σ1.kheap p = some (.endpoint (.recvEP l)) · refine WP.spec_mono (Hh.checkBudgetTR hA hmax htu hCH hni1 (Or.inl hres1) hnq1 (hmrt a1) (hmb a1) hkt hrr hth hper hkl) ?_ rintro r hB hf - obtain ⟨z, hz, hz1, V, Ac', Lst', D', J'⟩ := hB hf - exact ⟨z, hz, hz1, _, Ac', Lst', D', J', inferInstance⟩ + obtain ⟨z, hz, hz1, V, Ac', Lst', D', J', F'⟩ := hB hf + exact ⟨z, hz, hz1, _, Ac', Lst', D', J', F'⟩ · have hcb : ∀ xe, σ1.kheap p = some (.endpoint xe) → Endp.CanBlock false xe := fun xe h => by cases xe with | idleEP => trivial @@ -110,23 +94,71 @@ theorem JAtZ.utCheckB {s : S} {a : A} {σ0 : Fl4Spec.State Unit} | recvEP q => exact absurd ⟨q, h⟩ hkl refine WP.spec_mono (Hh.checkBudgetT hA hCH hni1 hres1 hnq1 (hmrt a1) (hmb a1) hkt hrr hth hper hcb) ?_ rintro r hB hf - obtain ⟨z, hz, hz1, V, Ac', Lst', D', J'⟩ := hB hf - exact ⟨z, hz, hz1, _, Ac', Lst', D', J', inferInstance⟩ + obtain ⟨z, hz, hz1, V, Ac', Lst', D', J', F'⟩ := hB hf + exact ⟨z, hz, hz1, _, Ac', Lst', D', J', F'⟩ refine WP.spec_mono (WP.spec_and (check_budgetT hA s1 a1 σ1 hS1 hscC hact (hmb a1)) hFalse) ?_ rintro ⟨rb, s2, a2⟩ ⟨hT, hF⟩ cases rb with | false => - obtain ⟨z, hz, hz1, Z', Ac', Lst', D', J', _⟩ := hF rfl - exact ⟨z, hsp0 z hz, hz1, Z', Ac', Lst', D', J', inferInstance⟩ + obtain ⟨z, hz, hz1, V', Ac', Lst', D', J', F'⟩ := hF rfl + exact ⟨z, hz, hz1, V', Ac', Lst', D', J', F'⟩ | true => obtain ⟨e, hb, hsuf⟩ := hT rfl obtain ⟨rfl, rfl⟩ := Prod.mk.inj e - have hOR1 : OffReady σ1 := hO1 hBu.off - have hOK : OffOK σ1 := hOR1.ok hsuf - have hOw : CurOwnW Z.T Z.C σ1 := Or.inl (curOwn_of_curInv hS1 hI1 hC1) - obtain ⟨-, hJ⟩ := hJ1 σ1.machineState _ hum1 id - obtain ⟨Ac', Lst', D', J'⟩ := hJ hOK hOw - exact ⟨(true, σ1), hsp0 _ (by rw [checkBudget_suff hnd hb]; exact Set.mem_singleton _), rfl, Z, Ac', Lst', D', J', inferInstance⟩ + have hOK : OffOK σ1 := hOff.ok hsuf + have hOw : CurOwnW Z.T Z.C σ1 := Or.inl (curOwn_of_curInv hS1 Hh.inv hCH) + obtain ⟨Lst', J', F'⟩ := Hh.toJ hOK hOw + exact ⟨(true, σ1), by rw [checkBudget_suff hnd hb]; exact Set.mem_singleton _, + rfl, Z.vs, Ac, Lst', D, J', F'⟩ + +set_option maxHeartbeats 16000000 in +/-- **`update_timestamp; check_budget` at an entry state** (module +docstring). -/ +theorem JAtZB.utCheckNat {s : S} {a : A} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ0) (hni0 : Entered σ0) (hBu : KBudgetB arI a σ0) + (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1, z.1 = r.1 ∧ + ∃ (V' : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V') H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ NatFoot (L := L) Z s σ0 r.2.1 z.2 ⦄ := by + refine WP.spec_bind (J0.timestampJH hAK hA hnd hBu.now) ?_ + rintro ⟨s1, a1⟩ ⟨σ1, h1, -, -, -, -, -, hum1, hOff, hH⟩ + have Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ0 s1 a1 σ1 := + hH σ1.machineState a1 hum1 id + obtain ⟨-, -, -, -, ekh, ect, eact, eidle, -, -, -, -⟩ := Hh.sfacts + obtain ⟨ms, tm, cn, -, eσ1⟩ := Hh.spec + have hni : Entered σ1 := ⟨by rw [ect, eidle]; exact hni0.1, eact.trans hni0.2⟩ + have ht : NoTmoSend σ1 ∨ ∀ d p, σ1.curThread ∉ σ1.readyQueues d p := by + rcases hBu.tmo with h | h + · exact Or.inl (h.of_eq ekh ect (by rw [eσ1])) + · refine Or.inr ?_ + have erq : σ1.readyQueues = σ0.readyQueues := by rw [eσ1] + rw [ect, erq] + exact h + refine WP.spec_mono (Hh.checkBudgetNat hni (hOff hBu.off) ht hA hnd hmrt hmb hmax htu) ?_ + rintro r ⟨z, hz, he, V', Ac', Lst', D', B', F'⟩ + rw [Notif.nd_bind_one h1] + exact ⟨z, hz, he, V', Ac', Lst', D', B', F'⟩ + +/-- The native instance of the entry charge step. -/ +theorem JAtZ.utCheckB {s : S} {a : A} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ0) [VxE Z] (hni0 : Entered σ0) (hBu : KBudgetB arI a σ0) + (hNS0 : NativeScope σ0) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1, z.1 = r.1 ∧ + ∃ (Z' : XSets) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZ (L := L) arI AR Z' H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ VxE Z' ⦄ := + WP.spec_mono (J0.toB.utCheckNat hni0 hBu hAK hA hnd hmrt hmb hmax htu) + fun r ⟨z, hz, hb, V', Ac', Lst', D', J', F'⟩ => + ⟨z, hz, hb, Z.mv Z.G V', Ac', Lst', D', J'.toJN J0 F', inferInstance⟩ end @@ -144,11 +176,35 @@ theorem setWidth8_eq {w : U64} {i : Fl4Spec.Irq} (hwi : w.val = i.toNat) : w.bv. show w.val % 2 ^ 8 = _ rw [hwi]; exact Nat.mod_eq_of_lt i.isLt -set_option maxHeartbeats 16000000 in +set_option maxHeartbeats 4000000 in +/-- (mmuAD gen 42b71) **XTopJointIrqZR's `JAtZB.handleIrqJB` under `MachPlat` / `MRKeep`**: the masks FL4 writes are +the spec's (`MachPlat.mask`), the acknowledgements and the signal keep `MR` (`MachPlat.ack`, MachKeep's `MRKeep`; the +spec's `sendSignal` keeps `msF`); the post `JAtN` from the start. -/ +theorem JAtZB.handleIrqJBM (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlatA arI AR) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) + (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hN : NativeScope σ) (hR : MR a σ.machineState) + (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (hw256 : w.val < 256) (h126 : w.val ≠ 126) + (h127 : w.val ≠ 127) : + interrupt.handle_interrupt st arI s a w ⦃ r => + σ.interruptStates i = .irqInactive ∨ + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ∧ + MR r.2 z.2.machineState ⦄ := by + have hwb : w.bv.setWidth 8 = i := setWidth8_eq hwi + refine WP.spec_mono (J.handleIrqJB hARI hAT hmb hN hR w i hwi h126 h127 (fun a1 c h => hIP.ackAR a1 w c h) + (fun a0 a1 σ0 h0 he => ?_) (fun a1 ms h => hM.ack a1 w ms h) + (fun s1 a1 σ1 n b h1 => WP.spec_mono (MK.notification_send_signal L.total hAT hK h1) fun _ hm2 σ' hmem => + msF_mr hM hm2 (MachF.mfk_sendSignal' n.bv b.bv σ1 _ hmem))) + fun _ h => h.imp And.left id + have hm := hM.mask a0 w true σ0.machineState h0 hw256 + rw [he, WP.spec_ok, hwb] at hm + exact hm + /-- **MRPath's `handleIrqJIAN` with `MR` after** (module docstring): the masks FL4 writes are the spec's (`MachPlat.mask`), the acknowledgements and the signal keep `MR` (`MachPlat.ack`, MachKeep's `MRKeep`; the spec's -`sendSignal` keeps `msF`). -/ +`sendSignal` keeps `msF`). (mmuAD gen 42b71) `JAtZB.handleIrqJBM`'s corollary (`JAtN.toJAt`), statement unchanged. -/ theorem JAtZ.handleIrqJIM (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlatA arI AR) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hmb : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -159,179 +215,9 @@ theorem JAtZ.handleIrqJIM (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP interrupt.handle_interrupt st arI s a w ⦃ r => σ.interruptStates i = .irqInactive ∨ ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - have hX := J.xtop - have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 - have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 - have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by - apply BitVec.eq_of_toNat_eq; simp [hwi] - have hwb : w.bv.setWidth 8 = i := setWidth8_eq hwi - have hmaskM : ∀ (a0 a1 : A) (σ0 : Fl4Spec.State Unit), MR a0 σ0.machineState → - arI.mask_irq a0 w true = ok a1 → MR a1 (maskMs σ0 i true).machineState := by - intro a0 a1 σ0 h0 he - have hm := hM.mask a0 w true σ0.machineState h0 hw256 - rw [he, WP.spec_ok, hwb] at hm - exact hm - -- the acknowledgement keeps `JAt` and `MR` - have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JAt (L := L) arI AR s1 a1 z.2 → MR a1 z.2.machineState → - (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - rintro s1 a1 z hz ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ hm1 - refine WP.spec_bind (WP.spec_and (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) (hM.ack a1 w _ hm1)) ?_ - rintro a2 ⟨hA2, hM2⟩ - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, ⟨Z1, H1, Cs1, Ac1, Lst2, D1, J2, inferInstance⟩, hM2⟩) - unfold interrupt.handle_interrupt - rw [irq_max_eq] - simp only [bind_ok] - by_cases hbig : w > 127#u64 - · -- above FL4's maximum - rw [if_pos hbig] - have hgt : i > Fl4Spec.maxIRQ := by - have : 127 < w.val := hbig - show (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - have hm1 := hmaskM a a1 σ hR ha1 - rw [ha1] - simp only [bind_ok] - have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) ⟨Z, H, Cs, Ac, Lst1, D, J1, inferInstance⟩ hm1 - · rw [if_neg hbig] - have hw : w.val ≤ 125 := by - have : ¬ 127 < w.val := hbig - omega - have hw128 : w.val < 128 := by omega - have hle : ¬ i > Fl4Spec.maxIRQ := by - show ¬ (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - have hst : σ.interruptStates i = irqSt (L.mem s (irqStA (L.ksb s) w)) := by - rw [← hiw]; exact hIR.st w hw128 - rw [irq_state_eq'] - simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] - set v := L.mem s (irqStA (L.ksb s) w) with hv - -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ → - (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - intro m hm - refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1, hm1⟩) - · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ - intro a2 _ - exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 hm1 - refine key _ ?_ - by_cases h1 : v = 1#u64 - · -- a signal line - rw [if_pos h1] - have hsig : σ.interruptStates i = .irqSignal := by rw [hst, h1]; rfl - have hL : IntLayout Z.th (L.ksb s) := J.intL - have hnode := hL.node w hw128 - obtain ⟨cs, hkc, hwf, hsl⟩ := hX.rel.2.1.1.cnode _ 0 hnode - obtain ⟨c, ac, hcap, hcs, hCR⟩ := hsl [] rfl - rw [show slotAddr (nodeA (L.ksb s) w).bv (Fl4Spec.ofBl []) = nodeA (L.ksb s) w from - cslotAddr_nil _] at hcap - have hgc : Fl4Spec.getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False) := by - rw [← hiw, hIR.node w hw128]; exact getCap_cnode hkc hwf hcs - have hac : ac = absCap c := hCR.abs - rw [irq_slot_eq] - simp only [bind_ok] - rw [slot_cap_eq, hcap] - simp only [bind_ok] - -- the mask after the cap's case - have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JAt (L := L) arI AR s3 a2 σ1 → MR a2 σ1.machineState → - (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := by - rintro s3 a2 σ1 h1' ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ hm2 - obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true - have hm3 := hmaskM a2 a3 σ1 hm2 ha3 - rw [ha3] - simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', ⟨Z1, H1, Cs1, Ac1, Lst3, D1, J3, inferInstance⟩, - hm3⟩ - have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), - (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ∧ - MR r.2 z.2.machineState ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ hR - cases c with - | Notification p b sd rv => - cases sd with - | false => - simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap, Fl4Spec.capRights, Fl4Spec.AllowSend, rightsOf]) - | true => - simp only [↓reduceIte] - have hP : Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac := by - rw [hac]; exact ⟨rfl, rfl⟩ - have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl - have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by - intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h - have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (WP.spec_and (J.signal_atN hAT hmb hN p b hpN) - (MK.notification_send_signal L.total hAT hK hR)) ?_ - rintro ⟨s2, a2⟩ ⟨⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩, hm2⟩ - have hmem : ((), σ') ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 := by rw [hsp]; rfl - have hmF := MachF.mfk_sendSignal' p.bv b.bv σ _ hmem - exact hmask s2 a2 σ' (hwhen σ' hmem) ⟨_, H, Cs, Ac', Lst'', D', J', inferInstance⟩ (msF_mr hM hm2 hmF) - | _ => - simp only [bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) - rw [if_neg h1] - by_cases h2 : v = 2#u64 - · -- the timer line - rw [if_pos h2] - have htm : σ.interruptStates i = .irqTimer := by rw [hst, h2]; rfl - step with P1.LawfulStore.cur_cpu_spec as ⟨cc, ecc⟩ - step with P1.obj.node_set.spec as ⟨s2, es2⟩ - step with P1.obj.node_set.spec as ⟨s3, es3⟩ - subst es2 es3 ecc - have J2 := J.reprogramJ - obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 - try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, ⟨Z, H, Cs, Ac3, Lst3, D3, J3, inferInstance⟩, hR⟩ - rw [if_neg h2] - by_cases h3 : v = 3#u64 - · -- an IPI state on a line other than the IPI lines: reserved, nothing - rw [if_pos h3] - have hres : σ.interruptStates i = .irqReserved := by rw [hst, h3]; rfl - unfold smp.handle_ipi - rw [irq_resched_eq] - have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) - simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩, hR⟩ - rw [if_neg h3] - by_cases h0 : v = 0#u64 - · -- an inactive line: the spec fails - have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl hin - · have hres : σ.interruptStates i = .irqReserved := by - rw [hst]; unfold irqSt; simp [h0, h1, h2] - simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩, hR⟩ + MR r.2 z.2.machineState ⦄ := + WP.spec_mono (J.toB.handleIrqJBM hARI hAT hIP hM hK hmb hN hR w i hwi hw256 h126 h127) + fun _ h => h.imp id fun ⟨z, hz, hN', hm⟩ => ⟨z, hz, hN'.toJAt J, hm⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointKEntryEv6.lean b/proofs/Fl4Proofs/P3/XTopJointKEntryEv6.lean index 922ebcd8f..061166fc6 100644 --- a/proofs/Fl4Proofs/P3/XTopJointKEntryEv6.lean +++ b/proofs/Fl4Proofs/P3/XTopJointKEntryEv6.lean @@ -146,7 +146,8 @@ theorem JHole.chargeBudgetJ0 {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (used : U64) : sched.charge_budget st arI s a used false ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv false σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have J := Hh.j0 obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, -, -, -, earch, -, hcrσ, hbsaσ⟩ := Hh.sfacts have hP0 := J.ip @@ -280,7 +281,7 @@ theorem JHole.chargeBudgetJ0 {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (J.sc_jpl hW hKc hidW.2) (J.sc_jcov hW hdead (fun q hq hn => absurd hq hn) hidW hKd subset_rfl) (J.sc_kern hW hKc hfkc hX' hDbg fun _ h => h) (J.sc_utc hW hKc hDbg) hN' hI' hcur' hown' hoff hAI' hbsa hcr hblk' hKd - hidW.1 J.zD⟩ + hidW.1 J.zD, NatFoot.ofT J.xtop hW (fun _ h => J.tfoot_nh h) (natK_tk hKc)⟩ @@ -306,7 +307,8 @@ theorem JHole.chargeBudgetIJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (used : U64) : sched.charge_budget st arI s a used true ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv true σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R0, hc, hs⟩ := hS.lists @@ -333,7 +335,8 @@ theorem JHole.checkBudgetFI {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) : sched.check_budget st arI s a ⦃ r => r.1 = false → r.2.2 = a ∧ ∃ σ', Fl4Spec.checkBudget (Z := Unit) σ = ({(false, σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.2.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.2.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.2.1 σ' ⦄ := by have hS := Hh.xtop.fin.1.1.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC @@ -370,6 +373,48 @@ theorem JHole.checkBudgetFI {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} rw [nd_gets_bind, Notif.nd_bind_one h1'] rfl +set_option maxHeartbeats 4000000 in +/-- The shared idle entry charge, with the native write footprint. -/ +theorem JAtZB.utCheckIdleNat {s : S} {a : A} {σ0 : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ0) + (hres : σ0.schedulerAction = .resumeCurThread) (hidle : σ0.curThread = σ0.idleThread) + (hBu : KBudgetB arI a σ0) (hAK : ARKeep arI AR) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) + (hmrt : ∀ a, sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : ∀ a, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) : + (do let (s1, a1) ← sched.update_timestamp st arI s a; sched.check_budget st arI s1 a1) ⦃ r => + ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1, + z.1 = r.1 ∧ ∃ Lst' : U64 → List U64, + JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.2.1 r.2.2 z.2 ∧ + NatFoot (L := L) Z s σ0 r.2.1 z.2 ⦄ := by + refine WP.spec_bind (J.timestampJH hAK hAT hnd hBu.now) ?_ + rintro ⟨s1, a1⟩ ⟨σ1, h1, -, -, -, -, -, hum, hOff, hH⟩ + have Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ0 s1 a1 σ1 := + hH σ1.machineState a1 hum id + obtain ⟨-, -, -, -, -, ect, eact, eid, -, -, -, -⟩ := Hh.sfacts + have hr := eact.trans hres + have hi : σ1.curThread = σ1.idleThread := by rw [ect, eid]; exact hidle + have hC := Hh.cur.resolve_left (by rw [hr]; intro e; cases e) + have hnsw : σ1.schedulerAction ≠ .switchThread σ1.curThread := by rw [hr]; intro e; cases e + have hS := Hh.xtop.fin.1.1.1 + obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS Hh.inv hC + refine WP.spec_mono (WP.spec_and (check_budgetT hAT s1 a1 σ1 hS hscC hact (hmb a1)) + (Hh.checkBudgetFI hAT hC hi hnsw (hmrt a1) (hmb a1))) ?_ + rintro ⟨rb, s2, a2⟩ ⟨hT, hF⟩ + rw [Notif.nd_bind_one h1] + cases rb with + | false => + obtain ⟨ea, σ2, hcb, -, Lst2, J2, F2⟩ := hF rfl + simp only at ea + subst a2 + exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, Lst2, J2, F2⟩ + | true => + obtain ⟨e, hb, hsuf⟩ := hT rfl + obtain ⟨rfl, rfl⟩ := Prod.mk.inj e + have hOwn : CurOwnW Z.T Z.C σ1 := Or.inl (curOwn_of_curInv hS Hh.inv hC) + obtain ⟨Lst', J', F'⟩ := Hh.toJ ((hOff hBu.off).ok hsuf) hOwn + exact ⟨(true, σ1), by rw [checkBudget_suff hnd hb]; exact Set.mem_singleton _, rfl, Lst', J', F'⟩ + + set_option maxHeartbeats 16000000 in /-- **`update_timestamp; check_budget` at an entry state of the idle thread** (`JAtZ.utCheckB` with `ct = idle` and a resumed scheduler action in place of `Entered`). -/ @@ -384,60 +429,9 @@ theorem JAtZ.utCheckBI {s : S} {a : A} {σ0 : Fl4Spec.State Unit} ∃ z ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1, z.1 = r.1 ∧ ∃ (Z' : XSets) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), JAtZ (L := L) arI AR Z' H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ VxE Z' ⦄ := by - have hnow := hBu.now - have hS := J0.xtop.fin.1.1.1 - have hR := J0.xtop.fin.1.1.2.2.1 - have hnow' : arI.now a ⦃ r => ∃ ms, Fl4Spec.doMachineOp (Z := Unit) Fl4Spec.getCurrentTime σ0 = - ({(r.1.bv, { σ0 with machineState := ms })}, False) ∧ σ0.curTime ≤ r.1.bv ⦄ := - WP.spec_mono hnow fun _ ⟨ms, h1, h2, _⟩ => ⟨ms, h1, h2⟩ - refine WP.spec_bind (WP.spec_and (WP.spec_and (J0.timestampJ arI hAK hA hnd hnow) (J0.timestampJH hAK hA hnd hnow)) - (update_timestamp_refines s a σ0 hS hR J0.nsc hnd hnow')) ?_ - rintro ⟨s1, a1⟩ ⟨⟨⟨σ1, h1, -, -, -, -, -, hum1, hO1, hJ1⟩, ⟨σ1', h1', -, -, -, -, -, hum1', -, hH⟩⟩, - ⟨σ1'', h1'', hS1, -, -, hI1, hC1, -, -⟩⟩ - have e1 : σ1 = σ1' := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (Prod.mk.inj (h1.symm.trans h1')).1) - have e2 : σ1 = σ1'' := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (Prod.mk.inj (h1.symm.trans h1'')).1) - subst e1 e2 - have hsp0 : ∀ y, y ∈ (Fl4Spec.checkBudget (Z := Unit) σ1).1 → - y ∈ ((Fl4Spec.updateTimeStamp (Z := Unit) >>= fun _ => Fl4Spec.checkBudget) σ0).1 := by - intro y hy; rw [Notif.nd_bind_one h1]; exact hy - have Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ0 s1 a1 σ1 := hH σ1.machineState a1 hum1' id - have hI1 := hI1 J0.inv - have hC1 := hC1 hBu.cur - obtain ⟨hscC, -, -, -, hact, -, -⟩ := CurInv.facts hS1 hI1 hC1 - obtain ⟨-, -, -, -, ekh, ect, eact, eidle, -, -, -, -⟩ := Hh.sfacts - obtain ⟨ms1, tm1, cn1, -, eσ1⟩ := Hh.spec - have erq : σ1.readyQueues = σ0.readyQueues := by rw [eσ1] - have ecs : σ1.curSc = σ0.curSc := by rw [eσ1] - have hres1 : σ1.schedulerAction = .resumeCurThread := eact.trans hres0 - have hCH : CurInv σ1 := Hh.cur.resolve_left (by rw [hres1]; exact fun h => by cases h) - have hid1 : σ1.curThread = σ1.idleThread := by rw [ect, eidle]; exact hid0 - have hnsw1 : σ1.schedulerAction ≠ .switchThread σ1.curThread := by rw [hres1]; exact fun h => by cases h - -- the charge (the head is insufficient) - have hFalse : sched.check_budget st arI s1 a1 ⦃ r => r.1 = false → - ∃ z ∈ (Fl4Spec.checkBudget (Z := Unit) σ1).1, z.1 = false ∧ - ∃ (Z' : XSets) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR Z' H Cs Ac' Lst' D' r.2.1 r.2.2 z.2 ∧ VxE Z' ⦄ := by - refine WP.spec_mono (Hh.checkBudgetFI hA hCH hid1 hnsw1 (hmrt a1) (hmb a1)) ?_ - rintro ⟨rb, s2, a2⟩ hB hf - obtain ⟨ea, σ2, hcb, -, Lst2, J2⟩ := hB hf - simp only at ea J2 - subst ea - exact ⟨(false, σ2), by rw [hcb]; exact Set.mem_singleton _, rfl, Z, Ac, Lst2, D, J2, inferInstance⟩ - refine WP.spec_mono (WP.spec_and (check_budgetT hA s1 a1 σ1 hS1 hscC hact (hmb a1)) hFalse) ?_ - rintro ⟨rb, s2, a2⟩ ⟨hT, hF⟩ - cases rb with - | false => - obtain ⟨z, hz, hz1, Z', Ac', Lst', D', J', _⟩ := hF rfl - exact ⟨z, hsp0 z hz, hz1, Z', Ac', Lst', D', J', inferInstance⟩ - | true => - obtain ⟨e, hb, hsuf⟩ := hT rfl - obtain ⟨rfl, rfl⟩ := Prod.mk.inj e - have hOR1 : OffReady σ1 := hO1 hBu.off - have hOK : OffOK σ1 := hOR1.ok hsuf - have hOw : CurOwnW Z.T Z.C σ1 := Or.inl (curOwn_of_curInv hS1 hI1 hC1) - obtain ⟨-, hJ⟩ := hJ1 σ1.machineState _ hum1 id - obtain ⟨Ac', Lst', D', J'⟩ := hJ hOK hOw - exact ⟨(true, σ1), hsp0 _ (by rw [checkBudget_suff hnd hb]; exact Set.mem_singleton _), rfl, Z, Ac', Lst', D', J', inferInstance⟩ + exact WP.spec_mono (J0.toB.utCheckIdleNat hres0 hid0 hBu hAK hA hnd hmrt hmb) + fun _ ⟨z, hz, hb, Lst', J', F'⟩ => + ⟨z, hz, hb, Z, Ac, Lst', D, J'.toJN J0 F', inferInstance⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointMRHole.lean b/proofs/Fl4Proofs/P3/XTopJointMRHole.lean index 38adabe4c..28667dba0 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRHole.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRHole.lean @@ -19,6 +19,9 @@ no `PPPlat` / `IrqPlat` / `IrqPlatI`. `afterInvJZIM` / `afterInv_of_mcsIM ∘ mcsPPJ{I,S,C,U}M`. Platform premises: `MachPlat` [P], `MRKeep` [P] (arch-only), `PPPlatA` [P], `IrqPlatA` [P] (arch-only); all satisfied by `modelArch` for the MR part. + +(mmuAD gen 42b71) `hPre_ofZQIMN` reads `JHole.afterInvJZIMN`'s `JAtN` post back at `JAt` (`JAtN.toJAt` with the +base's `JExt`). -/ import Fl4Proofs.P3.XTopJointMRPath4 open Aeneas Aeneas.Std Result @@ -63,12 +66,12 @@ theorem jAtPreMV_holeQ (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4S obtain ⟨s0, a0, σ0, ⟨⟨Z, H, Cs, Ac, Lst, D, J, _⟩, hns0, hp00, hR0, hV0, hI0⟩, hpp, hσ⟩ := h have h := J.ppJHM hAK hA hnd hM hPA hR0 hV0 rw [hpp, WP.spec_ok] at h - obtain ⟨s1, Ac1, Lst1, Hh, hR', hV'⟩ := h rfl σ hσ + obtain ⟨s1, Ac1, Lst1, Hh, hEx, hR', hV'⟩ := h rfl σ hσ have hE := Sched.updateTimeStamp_eq' hnd (doMachineOp_single (getCurrentTime_eq σ0.machineState)) have e : σ = _ := pp_err_eq hE (doMachineOp_single (getActiveIRQ_eq true _)) _ hσ rfl subst e have h0 : CurScFree σ0 := curScFree_of J.inv J.own hp00 - refine ⟨⟨Z, H, Cs, Ac1, Lst1, D, s1, a0, σ0, Hh, ⟨vmt_le_gct hV0, rfl⟩, inferInstance⟩, hp00.1.1, hns0, + refine ⟨⟨Z, H, Cs, Ac1, Lst1, D, s1, a0, σ0, Hh, hEx, ⟨vmt_le_gct hV0, rfl⟩, inferInstance⟩, hp00.1.1, hns0, fun u xt hu hs => h0 u xt hu hs, hp00.1.2.2.1, hp00.1.2.2.2.1, hp00.1.2.2.2.2, hR', hV', ?_⟩ intro i hi exact hI0 i hi @@ -103,7 +106,7 @@ theorem jPreemptRestHypEQ_ofIM (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) syscall.after_invocation st arI s a (.Err .Preempted) ⦃ r => r.1 = false ∧ PPQJI (L := L) arI AR σ (r.2.1, r.2.2) ⦄ := by intro s a σ hJ hn hR hV hi hs hf hc hg hnq hC hsc hnsuf hcov - obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, _⟩ := hJ + obtain ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, _⟩ := hJ have hnt : ¬ NoTmoSend σ := fun h => hcov (Or.inl ⟨hC, hi, hs σ.curThread, h⟩) unfold NoTmoSend at hnt simp only [not_or, not_forall] at hnt @@ -123,14 +126,14 @@ theorem jPreemptRestHypEQ_ofIM (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) · exact absurd e (hs u) · exact Or.inr rfl by_cases hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe - · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hn (Hh.mcsPPJAM hA (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc hnsuf hkt - hrr hth hper hcb hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hn (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJAM hA (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc hnsuf hkt + hrr hth hper hcb hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · simp only [not_forall] at hcb obtain ⟨xe, hke, hncb⟩ := hcb obtain ⟨q, rfl⟩ : ∃ q, xe = .recvEP q := by revert hncb; cases xe <;> simp [Endp.CanBlock] - exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hn (Hh.mcsPPJRM hA hmax htu (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc - hnsuf hkt hrr hth hper ⟨q, hke⟩ hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hn (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJRM hA hmax htu (hmrt a) (hPA.minBudget a) hC hi hres hnq hsc + hnsuf hkt hrr hth hper ⟨q, hke⟩ hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h set_option maxHeartbeats 4000000 in /-- **`hPre_ofZQI` under `MachPlat`**: every preemption hole of a related @@ -147,34 +150,34 @@ theorem hPre_ofZQIMN (hARI : ARIface arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4S syscall.after_invocation st arI s1 a1 (.Err .Preempted) ⦃ r => r.1 = false ∧ PPQJI (L := L) arI AR σ1 (r.2.1, r.2.2) ⦄ := by intro s1 a1 σ1 _ h hN1 - obtain ⟨⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hTs, _⟩, hni, hns, hfr, hct, hcg, hnq, hR, -, hV⟩ := + obtain ⟨⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, hTs, _⟩, hni, hns, hfr, hct, hcg, hnq, hR, -, hV⟩ := jAtPreMV_holeQ hARI.toARKeep hA hnd hM hPA h by_cases hc : PPCov σ1 ∨ PPCovT σ1 · exact WP.spec_mono (Hh.afterInvJZIMN hTs hA hnd (hmrt a1) (hPA.minBudget a1) hM hK hIA hARI hPA.minBudget hN1 - hc hR hV _) fun _ h => h + hc hR hV _) fun _ ⟨h1, z, hz, hN⟩ => ⟨h1, z, hz, hN.toJAt (Hh.j0.toJAtZ hEx)⟩ by_cases hi : PPCovI σ1 - · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (Hh.mcsPPJIM hi hA hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) + · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJIM hi hA hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h by_cases hC : CurInv σ1 · cases hsc : Fl4Spec.schedulable σ1.curThread σ1 with | true => by_cases hsuf : ∀ y n, σ1.kheap σ1.curSc = some (.schedContext y n) → Fl4Spec.refillSufficient σ1.consumedTime (Fl4Spec.refillHd y) = true - · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (Hh.mcsPPJSM hTs hA hnd (hPA.minBudget a1) hC hni hsc hsuf hM hK hR hV)) + · exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJSM hTs hA hnd (hPA.minBudget a1) hC hni hsc hsuf hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · exact jPreemptRestHypEQ_ofIM hARI hA hM hK hPA hIA hmrt hmax htu s1 a1 σ1 - ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, inferInstance⟩ + ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, inferInstance⟩ hN1 hR hV hni hns hfr hct hcg hnq hC hsc hsuf fun h' => h'.elim (fun h2 => hc (Or.inl h2)) fun h2 => h2.elim (fun h3 => hc (Or.inr h3)) hi | false => - exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (Hh.mcsPPJCM hA (hmrt a1) (hPA.minBudget a1) hC hni hns hsc hM hK hR hV)) + exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJCM hA (hmrt a1) (hPA.minBudget a1) hC hni hns hsc hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h · have hsch : Fl4Spec.schedulable σ1.curThread σ1 = false := by cases e : Fl4Spec.schedulable σ1.curThread σ1 with | false => rfl | true => exact absurd (curInv_of_sched hct e) hC - exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (Hh.mcsPPJUM hA (hmrt a1) (hPA.minBudget a1) hC hct hfr hcg hsch hi - hM hK hR hV)) hM hIA hARI hA hPA.minBudget _) fun _ h => h + exact WP.spec_mono (afterInv_of_mcsIMN (mcsNS hN1 (mcsN_toJAt (Hh.j0.toJAtZ hEx) (Hh.mcsPPJUM hA (hmrt a1) (hPA.minBudget a1) hC hct hfr hcg hsch hi + hM hK hR hV))) hM hIA hARI hA hPA.minBudget _) fun _ h => h end diff --git a/proofs/Fl4Proofs/P3/XTopJointMRPP.lean b/proofs/Fl4Proofs/P3/XTopJointMRPP.lean index f0f65e181..183a981eb 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRPP.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRPP.lean @@ -31,6 +31,11 @@ degenerate `IrqPlat.take`. * `afterInv_of_mcsJM`: XTopJointIrqZR's `afterInv_of_mcsJ` with `MachPlat.takeAt` at the `take_pending_irq` read (`MR` after the MCS preemption point asked in its hypothesis) in place of `IrqPlat.take`. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2, item 3) **`JAtZB.workUnitsN`**: each `WORK_UNITS` write is a +native step; `JAtZB.ppJHM`'s post carries `NatFoot Z s σ s0 σ` from the entry state to the hole's base (the two +writes, composed by `JAtZB.natTrans`), beside the `JExt` carry, for the VM side's preempted path ((c3)). +`JAtZ.ppJHM` unchanged. -/ import Fl4Proofs.P3.XTopJointMachRel open Aeneas Aeneas.Std Result @@ -277,30 +282,49 @@ theorem JAtZ.ppJDM {s : S} {a : A} {σ : Fl4Spec.State Unit} ⟨σ', h1, h2, fun h => let ⟨⟨Ac', Lst', B, hE⟩, hp⟩ := h3 h; ⟨⟨Ac', Lst', B.toJAtZ (hE J.ext)⟩, hp⟩, h4, h5⟩ +/-- (mmuAD gen 42b70, the Architect's ruling (c1) part 2, item 3) **A write of `WORK_UNITS` is a native step** +(`NatFoot`: a kernel-state word below the IRQ node, off the VCPU words and the VCPU-list head; the spec state kept): +the entry → hole-base carry of `JAtZB.ppJHM`. -/ +theorem JAtZB.workUnitsN {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + (v : U64) : + NatFoot (L := L) Z s σ (L.wr s (core.num.U64.wrapping_add (L.ksb s) layout.ks.WORK_UNITS) v) σ := by + have hf := J.kern.ksbFit + have hv := workUnits_val hf + have hvh : (P1.vHeadA st s).val = (L.ksb s).val + 80 := vHead_val hf + refine NatFoot.ofW J.xtop (J.workUnitsJD_ws arI v).1 (fun b hb => ?_) (fun b hb => ?_) (fun b hb e => ?_) + (NatK.of_kheap rfl) + · subst hb; exact Or.inr (Or.inl ⟨by rw [hv]; omega, by rw [hv]; omega, Or.inl (by rw [hv]; omega)⟩) + · subst hb; exact J.ks_nv (by rw [hv]; omega) (by rw [hv]; omega) + · subst hb; have := congrArg UScalar.val e; rw [hv, hvh] at this; omega + set_option maxHeartbeats 16000000 in /-- **XTopJointPPH's `ppJH` under `MachPlat`** (module docstring): every spec -`error` outcome is a `JHole` with `MR` and `ValidMachineTime`. -/ -theorem JAtZ.ppJHM {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) +`error` outcome is a `JHole` with `MR` and `ValidMachineTime` +(Gen 42b69: from `JAtZB`; the hole's base `JExt` follows from the start's.) -/ +theorem JAtZB.ppJHM {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hPA : PPPlatA arI AR) (hR : MR a σ.machineState) (hV : ValidMachineTime σ) : sched.preemption_point st arI s a ⦃ r => r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ NatFoot (L := L) Z s σ s0 σ ∧ MR r.2.2 σ'.machineState ∧ + ValidMachineTime σ' ⦄ := by unfold sched.preemption_point step with obj.ks_get.spec as ⟨i, _⟩ step as ⟨w, _⟩ step with obj.ks_set.spec as ⟨s1, e1⟩ subst e1 - obtain ⟨Ac1, Lst1, J1⟩ := J.workUnitsJD arI w + obtain ⟨Ac1, Lst1, J1, hW1⟩ := J.workUnitsJD arI w + have F1 := J.workUnitsN w split swap · rw [WP.spec_ok]; intro h; cases h step with obj.ks_set.spec as ⟨s2, e2⟩ subst e2 - obtain ⟨Ac2, Lst2, J2⟩ := J1.workUnitsJD arI 0#u64 + obtain ⟨Ac2, Lst2, J2, hW2⟩ := J1.workUnitsJD arI 0#u64 + have F2 := J1.workUnitsN 0#u64 have hS0 := J2.xtop.fin.1.1.1 have hscC0 := cursc_in hS0 J2.own refine WP.spec_bind (WP.spec_and (J2.timestampJH hAK hA hnd (hM.nowAgree hR hV)) (update_timestamp_mr hM hR _)) ?_ @@ -357,17 +381,19 @@ theorem JAtZ.ppJHM {s : S} {a : A} {σ : Fl4Spec.State Unit} r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ NatFoot (L := L) Z s σ s0 σ ∧ MR r.2.2 σ'.machineState ∧ + ValidMachineTime σ' ⦄ := by rw [WP.spec_ok] intro _ σ' hσ' rw [hfin σ' hσ'] - exact ⟨_, Ac2, Lst2, hK _ a2 hum' (fun _ => hAR2), hR2, hV2⟩ + exact ⟨_, Ac2, Lst2, hK _ a2 hum' (fun _ => hAR2), fun h => hW2 (hW1 h), J.natTrans F1 F2, hR2, hV2⟩ have hOk : (ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s3, a2) : Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ r => r.1 = .Err .Preempted → ∀ σ', (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ - MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := by + (JExt (L := L) Z.th s → JExt (L := L) Z.th s0) ∧ NatFoot (L := L) Z s σ s0 σ ∧ MR r.2.2 σ'.machineState ∧ + ValidMachineTime σ' ⦄ := by rw [WP.spec_ok]; intro h; cases h cases hact : Fl4Spec.scActive x · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok, ite_self] @@ -382,6 +408,19 @@ theorem JAtZ.ppJHM {s : S} {a : A} {σ : Fl4Spec.State Unit} · exact hOk · exact hErr +/-- `JAtZB.ppJHM` at `JAtZ` (gen 42b69: via `JAtZ.toB`, the hole's base `JExt` from `J.ext`). -/ +theorem JAtZ.ppJHM {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hAK : ARKeep arI AR) (hA : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) (hM : MachPlat arI MR) (hPA : PPPlatA arI AR) + (hR : MR a σ.machineState) (hV : ValidMachineTime σ) : + sched.preemption_point st arI s a ⦃ r => r.1 = .Err .Preempted → ∀ σ', + (.error (), σ') ∈ ((Fl4Spec.preemptionPoint (Z := Unit)).run σ).1 → + ∃ (s0 : S) (Ac0 : Set U64) (Lst0 : U64 → List U64), + JHole (L := L) arI AR Z H Cs Ac0 Lst0 D s0 a σ r.2.1 r.2.2 σ' ∧ JExt (L := L) Z.th s0 ∧ + MR r.2.2 σ'.machineState ∧ ValidMachineTime σ' ⦄ := + WP.spec_mono (J.toB.ppJHM hAK hA hnd hM hPA hR hV) fun _ h hr σ' hσ' => + let ⟨s0, Ac0, Lst0, Hh, hE, _, hR', hV'⟩ := h hr σ' hσ'; ⟨s0, Ac0, Lst0, Hh, hE J.ext, hR', hV'⟩ + end diff --git a/proofs/Fl4Proofs/P3/XTopJointMRPath.lean b/proofs/Fl4Proofs/P3/XTopJointMRPath.lean index ac8f11763..e4298be8a 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRPath.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRPath.lean @@ -18,6 +18,11 @@ take and handler under `MachPlat`, ending in `PPQJI`** (no `IrqPlat`, no * `afterInv_of_mcsIM`: XTopJointIrqZI's `afterInv_of_mcsI` with `MR r.2 σ'.ms ∧ ValidIrqMasks σ'` after the MCS preemption point asked in its hypothesis, `MachPlat.takeAt` for `IrqPlat.take`, `IrqPlatA` for the rest. + +(mmuAD gen 42b71, ruling (c2) items 1 and 4) `JAtZ.handleIrqJIAN` is XTopJointIrqZR's `JAtZB.handleIrqJBT` corollary +(statement unchanged, copy removed). **`JAtZB.irqTailB`**: the IRQ take and handler from `JAtN` at a `JAtZB` base; +**`afterInv_of_mcsIMNB`**: `afterInv_of_mcsIMN` from such a base, posts `JAtN` (no `JExt`); `afterInv_of_mcsIMN` now +runs `irqTailB` from the state after the MCS part (statement unchanged). -/ import Fl4Proofs.P3.MachKeep import Fl4Proofs.P3.XTopJointMRMcs @@ -56,7 +61,6 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} -set_option maxHeartbeats 16000000 in /-- `handleIrqJI` with `IrqPlatA` (module docstring), `NativeScope` at its own state (g3b). -/ theorem JAtZ.handleIrqJIAN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP : IrqPlatA arI AR) @@ -66,181 +70,33 @@ theorem JAtZ.handleIrqJIAN (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) (hIP (w : U64) (i : Fl4Spec.Irq) (hwi : w.val = i.toNat) (h126 : w.val ≠ 126) (h127 : w.val ≠ 127) : interrupt.handle_interrupt st arI s a w ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - have hX := J.xtop - have hIR : IrqRel (L.mem s) (L.ksb s) σ := hX.fin.1.1.2.2.2.1 - have hARa : AR a σ.archState.x64CurrentCr3 := hX.fin.1.1.2.2.2.2.2.2 - have hiw : (BitVec.ofNat 8 w.val : Fl4Spec.Irq) = i := by - apply BitVec.eq_of_toNat_eq; simp [hwi] - -- the acknowledgement keeps `JAt` - have hack : ∀ (s1 : S) (a1 : A) (z : Unit × Fl4Spec.State Unit), - z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1 → JAt (L := L) arI AR s1 a1 z.2 → - (do let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s1 a1 z hz ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ - refine WP.spec_bind (hIP.ackAR a1 w _ J1.xtop.fin.1.1.2.2.2.2.2.2) ?_ - intro a2 hA2 - obtain ⟨Lst2, J2⟩ := J1.msArJ z.2.machineState a2 rfl (fun _ => hA2) - exact (WP.spec_ok _).2 (Or.inr ⟨z, hz, Z1, H1, Cs1, Ac1, Lst2, D1, J2, inferInstance⟩) - unfold interrupt.handle_interrupt - rw [irq_max_eq] - simp only [bind_ok] - by_cases hbig : w > 127#u64 - · -- above FL4's maximum - rw [if_pos hbig] - have hgt : i > Fl4Spec.maxIRQ := by - have : 127 < w.val := hbig - show (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - rw [ha1] - simp only [bind_ok] - have hA1 : AR a1 σ.archState.x64CurrentCr3 := hARI.mask _ _ _ hARa (Or.inr (Or.inl ⟨w, true, ha1⟩)) - obtain ⟨Lst1, J1⟩ := J.msArJ (maskMs σ i true).machineState a1 rfl (fun _ => hA1) - exact hack s a1 _ (mem_hi_big hgt σ) ⟨Z, H, Cs, Ac, Lst1, D, J1, inferInstance⟩ - · rw [if_neg hbig] - have hw : w.val ≤ 125 := by - have : ¬ 127 < w.val := hbig - omega - have hw128 : w.val < 128 := by omega - have hle : ¬ i > Fl4Spec.maxIRQ := by - show ¬ (125 : BitVec 8) < i - rw [BitVec.lt_def]; simp; omega - have hst : σ.interruptStates i = irqSt (L.mem s (irqStA (L.ksb s) w)) := by - rw [← hiw]; exact hIR.st w hw128 - rw [irq_state_eq'] - simp only [bind_ok, irqSig_eq, irqTimer_eq, irqIpi_eq, irqInactive_eq] - set v := L.mem s (irqStA (L.ksb s) w) with hv - -- the branches before the acknowledgement - have key : ∀ m : Result (S × A), m ⦃ r => σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ → - (do let (s1, a1) ← m; let a2 ← arI.ack_irq a1 w; ok (s1, a2)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - intro m hm - refine WP.spec_bind hm ?_ - rintro ⟨s1, a1⟩ (hf | ⟨z, hz, hJ1⟩) - · refine WP.spec_bind (hAT.ack_irq a1 w) ?_ - intro a2 _ - exact (WP.spec_ok _).2 (Or.inl hf) - · exact hack s1 a1 z hz hJ1 - refine key _ ?_ - by_cases h1 : v = 1#u64 - · -- a signal line - rw [if_pos h1] - have hsig : σ.interruptStates i = .irqSignal := by rw [hst, h1]; rfl - have hL : IntLayout Z.th (L.ksb s) := J.intL - have hnode := hL.node w hw128 - obtain ⟨cs, hkc, hwf, hsl⟩ := hX.rel.2.1.1.cnode _ 0 hnode - obtain ⟨c, ac, hcap, hcs, hCR⟩ := hsl [] rfl - rw [show slotAddr (nodeA (L.ksb s) w).bv (Fl4Spec.ofBl []) = nodeA (L.ksb s) w from - cslotAddr_nil _] at hcap - have hgc : Fl4Spec.getCap (Z := Unit) (σ.interruptIrqNode i, []) σ = ({(ac, σ)}, False) := by - rw [← hiw, hIR.node w hw128]; exact getCap_cnode hkc hwf hcs - have hac : ac = absCap c := hCR.abs - rw [irq_slot_eq] - simp only [bind_ok] - rw [slot_cap_eq, hcap] - simp only [bind_ok] - -- the mask after the cap's case - have hmask : ∀ (s3 : S) (a2 : A) (σ1 : Fl4Spec.State Unit), - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 → - JAt (L := L) arI AR s3 a2 σ1 → - (do let a3 ← arI.mask_irq a2 w true; ok (s3, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by - rintro s3 a2 σ1 h1' ⟨Z1, H1, Cs1, Ac1, Lst1, D1, J1, _⟩ - obtain ⟨a3, ha3⟩ := maskIrq_total arI hAT a2 w true - rw [ha3] - simp only [bind_ok, WP.spec_ok] - have hA3 := hARI.mask _ _ _ J1.xtop.fin.1.1.2.2.2.2.2.2 (Or.inr (Or.inl ⟨w, true, ha3⟩)) - obtain ⟨Lst3, J3⟩ := J1.msArJ (maskMs σ1 i true).machineState a3 rfl (fun _ => hA3) - exact Or.inr ⟨((), maskMs σ1 i true), mem_hi_signal hle hsig hgc h1', Z1, H1, Cs1, Ac1, Lst3, D1, J3, inferInstance⟩ - have hnone : ∀ (hP : ¬ (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac)), - (do let a3 ← arI.mask_irq a w true; ok (s, a3)) ⦃ r => - σ.interruptStates i = .irqInactive ∨ - ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := - fun hP => hmask s a σ (mem_when_false hP _ σ) ⟨Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ - cases c with - | Notification p b sd rv => - cases sd with - | false => - simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap, Fl4Spec.capRights, Fl4Spec.AllowSend, rightsOf]) - | true => - simp only [↓reduceIte] - have hP : Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac := by - rw [hac]; exact ⟨rfl, rfl⟩ - have hobj : Fl4Spec.objRefOf ac = p.bv := by rw [hac]; rfl - have hbd : Fl4Spec.capEpBadge ac = b.bv := by rw [hac]; rfl - have hwhen : ∀ σ1, ((), σ1) ∈ (Fl4Spec.sendSignal (Z := Unit) p.bv b.bv σ).1 → - ((), σ1) ∈ (Fl4Spec.NonDet.when (Fl4Spec.isNtfnCap ac ∧ Fl4Spec.AllowSend ∈ Fl4Spec.capRights ac) - (Fl4Spec.sendSignal (Z := Unit) (Fl4Spec.objRefOf ac) (Fl4Spec.capEpBadge ac)) σ).1 := by - intro σ1 h; unfold Fl4Spec.NonDet.when; rw [if_pos hP, hobj, hbd]; exact h - have hA : AbsSlot Z.th ((nodeA (L.ksb s) w).bv, []) := ⟨_, rfl, Or.inl hnode⟩ - have hpN := (J.slotN hA (by rw [cslotAddr_nil]; exact hcap)).1 - refine WP.spec_bind (J.signal_atN hAT hmb hN p b hpN) ?_ - rintro ⟨s2, a2⟩ ⟨σ', V', Ac', Lst'', D', hsp, -, J'⟩ - exact hmask s2 a2 σ' (hwhen σ' (by rw [hsp]; rfl)) ⟨_, H, Cs, Ac', Lst'', D', J', inferInstance⟩ - | _ => - simp only [bind_ok] - exact hnone (by rw [hac]; simp [absCap, Fl4Spec.isNtfnCap]) - rw [if_neg h1] - by_cases h2 : v = 2#u64 - · -- the timer line - rw [if_pos h2] - have htm : σ.interruptStates i = .irqTimer := by rw [hst, h2]; rfl - step with P1.LawfulStore.cur_cpu_spec as ⟨cc, ecc⟩ - step with P1.obj.node_set.spec as ⟨s2, es2⟩ - step with P1.obj.node_set.spec as ⟨s3, es3⟩ - subst es2 es3 ecc - have J2 := J.reprogramJ - obtain ⟨Ac3, Lst3, D3, J3⟩ := J2.armedJ (L.cpu_wr _ _ _) 0#u64 - try simp only [WP.spec_ok] - exact Or.inr ⟨_, mem_hi_timer hle htm, Z, H, Cs, Ac3, Lst3, D3, J3, inferInstance⟩ - rw [if_neg h2] - by_cases h3 : v = 3#u64 - · -- an IPI state on a line other than the IPI lines: reserved, nothing - rw [if_pos h3] - have hres : σ.interruptStates i = .irqReserved := by rw [hst, h3]; rfl - unfold smp.handle_ipi - rw [irq_resched_eq] - have hne : ¬ w = 127#u64 := fun e => h127 (by rw [e]; rfl) - simp only [bind_ok, hne, ↓reduceIte, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ - rw [if_neg h3] - by_cases h0 : v = 0#u64 - · -- an inactive line: the spec fails - have hin : σ.interruptStates i = .irqInactive := by rw [hst, h0]; rfl - obtain ⟨a1, ha1⟩ := maskIrq_total arI hAT a w true - simp only [h0, ↓reduceIte, ha1, bind_ok, WP.spec_ok] - exact Or.inl hin - · have hres : σ.interruptStates i = .irqReserved := by - rw [hst]; unfold irqSt; simp [h0, h1, h2] - simp only [h0, ↓reduceIte, bind_ok, WP.spec_ok] - exact Or.inr ⟨_, mem_hi_reserved hle hres, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + ∃ z ∈ (Fl4Spec.handleInterrupt (Z := Unit) i σ).1, JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.handleIrqJBT hARI hAT hmb hN w i hwi h126 h127 fun a1 c h => hIP.ackAR a1 w c h) + fun _ h => h.imp And.left fun ⟨z, hz, hN'⟩ => ⟨z, hz, hN'.toJAt J⟩ -set_option maxHeartbeats 16000000 in -/-- **`afterInv_of_mcsI` under `MachPlat`** (module docstring), `NativeScope` at the -state after the MCS part from `hmcs` (g3b). -/ -theorem afterInv_of_mcsIMN {s : S} {a : A} {σ : Fl4Spec.State Unit} - (hmcs : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ NativeScope σ' ⦄) +set_option maxHeartbeats 8000000 in +/-- (mmuAD gen 42b71, ruling (c2) item 4) **The IRQ take and handler of the preemption path from a native run**: after +the MCS part, at `JAtN` from a `JAtZB` base `(s0, σ0)`, with `MR`, `ValidIrqMasks` and `NativeScope` there, FL4's +`take_pending_irq` and `check_interrupt` end at an outcome of the spec's `preemption_path` (through `hm`) with `JAtN` +from the base (`JAtZB.msArJ`, `JAtZB.handleIrqJBT`, `JAtN.trans`). -/ +theorem JAtZB.irqTailB {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0) {s1 : S} {a1 : A} {σ σ' : Fl4Spec.State Unit} + (hm : ∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) + (hJ : JAtN (L := L) arI AR Z H Cs s0 σ0 s1 a1 σ') (hR1 : MR a1 σ'.machineState) (hVI : ValidIrqMasks σ') + (hN' : NativeScope σ') (hM : MachPlat arI MR) (hIP : IrqPlatA arI AR) (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) - (hmbA : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) - (e : error.Exc) : - syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ PPQJI (L := L) arI AR σ (r.2.1, r.2.2) ⦄ := by - unfold syscall.after_invocation - refine WP.spec_bind hmcs ?_ - rintro ⟨s1, a1⟩ ⟨σ', hm, hmf, ⟨Z', H', Cs', Ac', Lst', D', J', _⟩, hR1, hVI, hN'⟩ - have hAR1 : AR a1 σ'.archState.x64CurrentCr3 := J'.xtop.fin.1.1.2.2.2.2.2.2 + (hmbA : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) : + (do + let (irq, a2) ← arI.take_pending_irq a1 + let (s2, a3) ← syscall.check_interrupt st arI s1 a2 irq + ok (false, s2, a3)) ⦃ r => r.1 = false ∧ + ∃ z ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1, JAtN (L := L) arI AR Z H Cs s0 σ0 r.2.1 r.2.2 z.2 ⦄ := by + obtain ⟨V1, Ac1, Lst1, D1, B1, F1⟩ := hJ + have hAR1 : AR a1 σ'.archState.x64CurrentCr3 := B1.xtop.fin.1.1.2.2.2.2.2.2 refine WP.spec_bind (WP.spec_and (WP.spec_and (hM.takeAt hR1) (hIP.takeAR a1 _ hAR1)) (hM.noIpi a1 _ hR1)) ?_ rintro ⟨w, a2⟩ ⟨⟨⟨irq, ms, hIq, hnone, hsome, hum, -⟩, hAR2⟩, h126, h127⟩ - obtain ⟨Lst2, J2⟩ := J'.msArJ ms a2 hum (fun _ => hAR2) + obtain ⟨Lst2, B2, F2⟩ := B1.msArJ ms a2 hum (fun _ => hAR2) + have F12 := J0.natTrans F1 F2.cast unfold syscall.check_interrupt by_cases hw : w = syscall.NO_IRQ · have hirq : irq = none := hnone.1 hw @@ -251,24 +107,59 @@ theorem afterInv_of_mcsIMN {s : S} {a : A} {σ : Fl4Spec.State Unit} ok (false, s2, a3)) ⦃ _ ⦄ rw [e] simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - refine (WP.spec_ok _).2 ⟨rfl, ⟨((), { σ' with machineState := ms }), - hm _ (mem_maybeHandle_none hIq), ⟨Z', H', Cs', Ac', Lst2, D', J2, inferInstance⟩⟩⟩ + exact (WP.spec_ok _).2 ⟨rfl, ((), { σ' with machineState := ms }), hm _ (mem_maybeHandle_none hIq), + V1, Ac1, Lst2, D1, B2, F12⟩ · obtain ⟨i, rfl⟩ : ∃ i, irq = some i := by cases irq with | none => exact absurd (hnone.2 rfl) hw | some i => exact ⟨i, rfl⟩ - obtain ⟨hwi, hmask⟩ := hsome i rfl + obtain ⟨hwi, -⟩ := hsome i rfl have e : (w != syscall.NO_IRQ) = true := by simpa using hw show (do let (s2, a3) ← (if (w != syscall.NO_IRQ) = true then interrupt.handle_interrupt st arI s1 a2 w else ok (s1, a2)) ok (false, s2, a3)) ⦃ _ ⦄ rw [e] simp only [↓reduceIte] - refine WP.spec_bind (J2.handleIrqJIAN hARI hAT hIP hmbA hN' w i hwi h126 h127) ?_ - rintro ⟨s2, a3⟩ (hf | ⟨z, hz, hJ⟩) - · exact absurd hf (gai_active hVI hIq i rfl) - · exact (WP.spec_ok _).2 ⟨rfl, ⟨z, hm _ (mem_maybeHandle_some hIq hz), hJ⟩⟩ + refine WP.spec_bind (B2.handleIrqJBT hARI hAT hmbA hN' w i hwi h126 h127 fun a c h => hIP.ackAR a w c h) ?_ + rintro ⟨s2, a3⟩ (hf | ⟨z, hz, hJ2⟩) + · exact absurd hf.1 (gai_active hVI hIq i rfl) + · exact (WP.spec_ok _).2 ⟨rfl, z, hm _ (mem_maybeHandle_some hIq hz), JAtN.trans J0 F12 hJ2⟩ +/-- (mmuAD gen 42b71, ruling (c2) item 4) **`afterInv_of_mcsIMN` from a native base**: the MCS part ends at `JAtN` +from a `JAtZB` base, so does the whole path (`JAtZB.irqTailB`); no `JExt` anywhere. -/ +theorem afterInv_of_mcsIMNB {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0) {s : S} {a : A} {σ : Fl4Spec.State Unit} + (hmcs : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ NativeScope σ' ⦄) + (hM : MachPlat arI MR) (hIP : IrqPlatA arI AR) (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) + (hmbA : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (e : error.Exc) : + syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ + ∃ z ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1, JAtN (L := L) arI AR Z H Cs s0 σ0 r.2.1 r.2.2 z.2 ⦄ := by + unfold syscall.after_invocation + refine WP.spec_bind hmcs ?_ + rintro ⟨s1, a1⟩ ⟨σ', hm, -, hJ, hR1, hVI, hN'⟩ + exact J0.irqTailB hm hJ hR1 hVI hN' hM hIP hARI hAT hmbA + +/-- **`afterInv_of_mcsI` under `MachPlat`** (module docstring), `NativeScope` at the +state after the MCS part from `hmcs` (g3b). (mmuAD gen 42b71) The IRQ part is `JAtZB.irqTailB` from the state after +the MCS part (`JAtN.toJAt`); statement unchanged. -/ +theorem afterInv_of_mcsIMN {s : S} {a : A} {σ : Fl4Spec.State Unit} + (hmcs : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ NativeScope σ' ⦄) + (hM : MachPlat arI MR) (hIP : IrqPlatA arI AR) (hARI : ARIface arI AR) (hAT : P0.ArchTotal arI) + (hmbA : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (e : error.Exc) : + syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ PPQJI (L := L) arI AR σ (r.2.1, r.2.2) ⦄ := by + unfold syscall.after_invocation + refine WP.spec_bind hmcs ?_ + rintro ⟨s1, a1⟩ ⟨σ', hm, -, ⟨Z', H', Cs', Ac', Lst', D', J', _⟩, hR1, hVI, hN'⟩ + exact WP.spec_mono (J'.toB.irqTailB hm (JAtN.of J'.toB (NatFoot.refl _ _ _)) hR1 hVI hN' hM hIP hARI hAT hmbA) + fun _ ⟨h1, z, hz, hN⟩ => ⟨h1, z, hz, hN.toJAt J'⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointMRPath2.lean b/proofs/Fl4Proofs/P3/XTopJointMRPath2.lean index 98dab4f22..457128883 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRPath2.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRPath2.lean @@ -16,6 +16,15 @@ path under `MachPlat`, both branches** (mr1 NEXT (a)): `MR` and state), then `MachPlat.frame`. * `JHole.afterInvJZIM`: XTopJointIrqZI's `afterInvJZI` under `MachPlat` (`afterInv_of_mcsIM`): no `IrqPlat`, no `IrqPlatI`, no `PPPlat`. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2, item 2) `mcsPPJZMF` / `mcsPPJZM` take no `JExt` at the hole's +base (nor `VxE`): they end at `JAtN` from the hole's base (`JAtZB` plus `NatFoot`; the charges' posts). `mcsN_toJAt` +moved here from P3/XTopJointMRPath3 (statement unchanged). (gen 42b71, ruling (c2) item 4) `afterInvJZIMN` drops `hE` and `VxE` too: the IRQ step is +over `JAtZB` (P3/XTopJointMRPath's `afterInv_of_mcsIMNB`), and it ends at `JAtN` from the hole's base (in place of +`PPQJI`); the native caller (P3/XTopJointMRHole) reads it back at `JAt` with `JAtN.toJAt`. +(gen 42b74) **`mcsPPJZMFG` / `mcsPPJZMG`**: the two over any last step `tl` of the path (XTopJointPreempt's `ppG`), +for the extended spec's `preemptionPathVF` (P3/VmPreempt); `mcsPPJZMF` / `mcsPPJZM` their corollaries (statements +unchanged). -/ import Fl4Proofs.P3.XTopJointMRPath import Fl4Proofs.P3.MachFieldFam @@ -44,18 +53,35 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} +/-- (mmuAD gen 42b69) **An MCS part's post from a hole, `JAtN` from the hole's base, back at `JAt`** given `JAtZ` +at the base (`JAtN.toJAt`): the native callers' form of the `mcsPPJ*M` lemmas restated over `JHole.j0 : JAtZB`; moved here from +P3/XTopJointMRPath3 in gen 42b70). -/ +theorem mcsN_toJAt [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} + (J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0) {s : S} {a : A} {σ : Fl4Spec.State Unit} + (h : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono h fun _ ⟨σ', h1, h2, hJ, hR', hV', hn⟩ => ⟨σ', h1, h2, hJ.toJAt J0, hR', hV', hn⟩ + set_option maxHeartbeats 16000000 in -/-- **`mcsPPJZ` with the spec step keeping `msF`** (module docstring). -/ -theorem JHole.mcsPPJZMF [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- **`mcsPPJZ` with the spec step keeping `msF`** (module docstring). (mmuAD gen 42b74) The spec side over any last +step `tl` of the path (`ppG tl`): `mcsPPJZMF` is it at `maybeHandleInterrupt true`. -/ +theorem JHole.mcsPPJZMFG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (hcov : PPCov σ ∨ PPCovT σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by obtain ⟨hC, hni, hnsw⟩ : CurInv σ ∧ σ.curThread ≠ σ.idleThread ∧ σ.schedulerAction ≠ .switchThread σ.curThread := by rcases hcov with ⟨h1, h2, h3, -⟩ | ⟨h1, h2, h3, -⟩ @@ -90,7 +116,7 @@ theorem JHole.mcsPPJZMF [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s rw [hc.cur] at hcv subst hcv refine WP.spec_mono (Hh.chargeBudgetJ hAT hC hni hnsw hmrt hmb _) ?_ - rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J'⟩ + rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J', F'⟩ simp only at ha subst a' have hkx' : σ.kheap σ.curSc = some (.schedContext x n) := by rw [hs.curSc]; exact hkx @@ -99,32 +125,31 @@ theorem JHole.mcsPPJZMF [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s have h1' : Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime false σ = ({((), σ')}, False) := by rw [hs.consumed]; exact h1 have hs' : Fl4Spec.schedulable σ.curThread σ = false := by rw [ect]; exact hsch - refine ⟨σ', ?_, ?_, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), + refine ⟨σ', fun tl => ⟨fun y hy => mem_ppG_charge (tl := tl) hs' hga (by rw [h1']; rfl) hy, + fun hy => fail_ppG_charge (tl := tl) hs' hga (by rw [h1']; rfl) hy⟩, JAtN.of J' F', + MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), fun hN => SInv.ns_chargeBudget _ _ σ hN ((), σ') (by rw [h1']; rfl)⟩ - · exact fun y hy => mem_pp_charge hs' hga (by rw [h1']; rfl) hy - · exact fun hy => fail_pp_charge hs' hga (by rw [h1']; rfl) hy · simp only [↓reduceIte] have hs' : Fl4Spec.schedulable σ.curThread σ = true := by rw [ect]; exact hsch have hFT : sched.check_budget st arI s a ⦃ res => res.1 = false → ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → - y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR res.2.1 res.2.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 res.2.1 res.2.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by rcases hcov with ⟨-, -, -, hnt⟩ | ⟨-, -, hres, hnq, hper, xt, p, bd, r, hkt, hrr, hth, hcb⟩ · refine WP.spec_mono (Hh.checkBudgetF hAT hC hni hnsw hmrt hmb hnt) ?_ rintro ⟨r, s', a'⟩ hF hr - obtain ⟨ha, σ', h1, -, Lst', J'⟩ := hF hr + obtain ⟨ha, σ', h1, -, Lst', J', F'⟩ := hF hr simp only at ha subst a' - exact ⟨σ', fun y hy => mem_pp_sched hs' (by rw [h1]; rfl) hy, - fun hy => fail_pp_sched hs' (by rw [h1]; rfl) hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, + exact ⟨σ', fun tl => ⟨fun y hy => mem_ppG_sched (tl := tl) hs' (by rw [h1]; rfl) hy, + fun hy => fail_ppG_sched (tl := tl) hs' (by rw [h1]; rfl) hy⟩, JAtN.of J' F', MachF.mfk_checkBudget σ (_, σ') (by rw [h1]; rfl), fun hN => SInv.ns_checkBudget σ hN (_, σ') (by rw [h1]; rfl)⟩ · refine WP.spec_mono (Hh.checkBudgetT hAT hC hni hres hnq hmrt hmb hkt hrr hth hper hcb) ?_ rintro ⟨r, s', a'⟩ hF hr - obtain ⟨z, hz, -, V, Ac', Lst', D', J'⟩ := hF hr - exact ⟨z.2, fun y hy => mem_pp_sched hs' hz hy, fun hy => fail_pp_sched hs' hz hy, - ⟨Z.mv Z.G V, H, Cs, Ac', Lst', D', J', inferInstance⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ + obtain ⟨z, hz, -, V, Ac', Lst', D', J', F'⟩ := hF hr + exact ⟨z.2, fun tl => ⟨fun y hy => mem_ppG_sched (tl := tl) hs' hz hy, + fun hy => fail_ppG_sched (tl := tl) hs' hz hy⟩, + ⟨V, Ac', Lst', D', J', F'⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ refine WP.spec_bind (WP.spec_and (check_budgetT hAT s a σ hS hscC hact hmb) hFT) ?_ rintro ⟨r, s', a'⟩ ⟨hT', hF⟩ refine (WP.spec_ok _).2 ?_ @@ -134,13 +159,47 @@ theorem JHole.mcsPPJZMF [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s simp only [Prod.mk.injEq] at e obtain ⟨rfl, rfl⟩ := e have hO := Hh.offOK_suff hT hC hni hs' hsufH - obtain ⟨Lst', J'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) - exact ⟨σ, fun y hy => mem_pp_sched hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, - fun hy => fail_pp_sched hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, rfl, fun hN => hN⟩ + obtain ⟨Lst', J', F'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) + exact ⟨σ, fun tl => ⟨fun y hy => mem_ppG_sched (tl := tl) hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy, + fun hy => fail_ppG_sched (tl := tl) hs' (by rw [checkBudget_suff hnd hsuf]; rfl) hy⟩, JAtN.of J' F', rfl, + fun hN => hN⟩ + +/-- **`mcsPPJZ` with the spec step keeping `msF`** (module docstring): `mcsPPJZMFG` at `maybeHandleInterrupt true` +(statement unchanged). -/ +theorem JHole.mcsPPJZMF {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hcov : PPCov σ ∨ PPCovT σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJZMFG hT hAT hnd hmrt hmb hcov) fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ -/-- **`mcsPPJZ` with `MR` and `ValidIrqMasks` after** (module docstring). -/ +/-- **`mcsPPJZ` with `MR` and `ValidIrqMasks` after** (module docstring); (mmuAD gen 42b74) over any last step +`tl` of the path (`mcsPPJZMFG`). -/ +theorem JHole.mcsPPJZMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hcov : PPCov σ ∨ PPCovT σ) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) + (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := by + refine WP.spec_mono (WP.spec_and (Hh.mcsPPJZMFG hT hAT hnd hmrt hmb hcov) + (MK.syscall_mcs_preemption_point L.total hAT hK hR)) ?_ + rintro r ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ + exact ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- **`mcsPPJZ` with `MR` and `ValidIrqMasks` after** (module docstring): `mcsPPJZMG` at `maybeHandleInterrupt true` +(statement unchanged). -/ theorem JHole.mcsPPJZM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -149,18 +208,16 @@ theorem JHole.mcsPPJZM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ - (NativeScope σ → NativeScope σ') ⦄ := by - refine WP.spec_mono (WP.spec_and (Hh.mcsPPJZMF hT hAT hnd hmrt hmb hcov) - (MK.syscall_mcs_preemption_point L.total hAT hK hR)) ?_ - rintro r ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ - exact ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJZMG hT hAT hnd hmrt hmb hcov hM hK hR hV) fun _ ⟨σ', hT', rest⟩ => + ⟨σ', (hT' _).1, (hT' _).2, rest⟩ set_option maxHeartbeats 16000000 in /-- **The covered preemption path under `MachPlat`** (module docstring), `NativeScope` at the hole (g3b). -/ theorem JHole.afterInvJZIMN {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -168,8 +225,9 @@ theorem JHole.afterInvJZIMN {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} (hmbA : ∀ a : A, sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (hN : NativeScope σ) (hcov : PPCov σ ∨ PPCovT σ) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) (e : error.Exc) : - syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ PPQJI (L := L) arI AR σ (r.2.1, r.2.2) ⦄ := - afterInv_of_mcsIMN (WP.spec_mono (Hh.mcsPPJZM hT hAT hnd hmrt hmb hcov hM hK hR hV) + syscall.after_invocation st arI s a (.Err e) ⦃ r => r.1 = false ∧ + ∃ z ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1, JAtN (L := L) arI AR Z H Cs s0 σ0 r.2.1 r.2.2 z.2 ⦄ := + afterInv_of_mcsIMNB Hh.j0 (WP.spec_mono (Hh.mcsPPJZM hT hAT hnd hmrt hmb hcov hM hK hR hV) fun _ ⟨σ', h1, h2, hJ, hR', hV', hn⟩ => ⟨σ', h1, h2, hJ, hR', hV', hn hN⟩) hM hIA hARI hAT hmbA e diff --git a/proofs/Fl4Proofs/P3/XTopJointMRPath3.lean b/proofs/Fl4Proofs/P3/XTopJointMRPath3.lean index 4890c88d7..3b6f9adcf 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRPath3.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRPath3.lean @@ -8,6 +8,10 @@ ValidIrqMasks σ'` after. Scripted copies (scratch/mr2/mcscopy.py): the original proof becomes a `have key` with `msF σ' = msF σ` added at its endpoint, combined with MachKeep's FL4 walk as in XTopJointMRPath2's `mcsPPJZM`. + +(mmuAD gen 42b75) **`mcsPPJSMG` / `mcsPPJCMG` / `mcsPPJUMG`**: the three over any last step `tl` of the path +(XTopJointPreempt's `ppG`), `mcsPPJSMG` also with FL4's state kept (sufficient budget), for P3/VmPreempt's +`JHole.mcsPPVF`; the old names their corollaries (statements unchanged). -/ import Fl4Proofs.P3.XTopJointMRPath2 open Aeneas Aeneas.Std Result @@ -23,8 +27,9 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJS` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJSM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- (mmuAD gen 42b75) `JHole.mcsPPJS` with `MR` and `ValidIrqMasks` after (module docstring), over +any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJSMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) (hnd : Fl4Spec.numDomains = 1) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -33,14 +38,13 @@ theorem JHole.mcsPPJSM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : Fl4Spec.refillSufficient σ.consumedTime (Fl4Spec.refillHd y) = true) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ - (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ∧ r.1 = s ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ∧ + r.1 = s ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists @@ -65,15 +69,35 @@ theorem JHole.mcsPPJSM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : simp only [Prod.mk.injEq] at e obtain ⟨rfl, rfl⟩ := e have hO := Hh.offOK_suff hT hC hni hsch hsufH - obtain ⟨Lst', J'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) - exact ⟨σ, fun y hy => mem_pp_sched hsch (by rw [checkBudget_suff hnd hsuf']; rfl) hy, - fun hy => fail_pp_sched hsch (by rw [checkBudget_suff hnd hsuf']; rfl) hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, rfl, fun hN => hN⟩ + obtain ⟨Lst', J', F'⟩ := Hh.toJ hO (Or.inl (curOwn_of_curInv hS Hh.inv hC)) + exact ⟨σ, fun tl => ⟨fun y hy => mem_ppG_sched hsch (by rw [checkBudget_suff hnd hsuf']; rfl) hy, + fun hy => fail_ppG_sched hsch (by rw [checkBudget_suff hnd hsuf']; rfl) hy⟩, + JAtN.of J' F', rfl, fun hN => hN, rfl⟩ exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs, he⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs, he⟩ + +/-- `JHole.mcsPPJS` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b75) +`mcsPPJSMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJSM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hT : TShift σ0 σ) (hAT : P0.ArchTotal arI) + (hnd : Fl4Spec.numDomains = 1) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hsch : Fl4Spec.schedulable σ.curThread σ = true) + (hsuf : ∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → + Fl4Spec.refillSufficient σ.consumedTime (Fl4Spec.refillHd y) = true) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJSMG hT hAT hnd hmb hC hni hsch hsuf hM hK hR hV) + fun _ ⟨σ', hT', hJ, hR', hV', hN, _⟩ => ⟨σ', (hT' _).1, (hT' _).2, hJ, hR', hV', hN⟩ set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJC` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJCM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- (mmuAD gen 42b75) `JHole.mcsPPJC` with `MR` and `ValidIrqMasks` after (module docstring), over +any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJCMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -81,14 +105,12 @@ theorem JHole.mcsPPJCM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : (hsch : Fl4Spec.schedulable σ.curThread σ = false) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists @@ -119,22 +141,41 @@ theorem JHole.mcsPPJCM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : rw [hc.cur] at hcv subst hcv refine WP.spec_mono (Hh.chargeBudgetJ hAT hC hni (hns σ.curThread) hmrt hmb _) ?_ - rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J'⟩ + rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J', F'⟩ simp only at ha subst a' have hga : Fl4Spec.getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False) := by unfold Fl4Spec.getScActive Fl4Spec.NonDet.getsThe; rw [readScActive_eq' hkx', hax']; rfl have h1' : Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime false σ = ({((), σ')}, False) := by rw [hs.consumed]; exact h1 - exact ⟨σ', fun y hy => mem_pp_charge hsch hga (by rw [h1']; rfl) hy, - fun hy => fail_pp_charge hsch hga (by rw [h1']; rfl) hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), + exact ⟨σ', fun tl => ⟨fun y hy => mem_ppG_charge hsch hga (by rw [h1']; rfl) hy, + fun hy => fail_ppG_charge hsch hga (by rw [h1']; rfl) hy⟩, + JAtN.of J' F', MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), fun hN => SInv.ns_chargeBudget _ _ σ hN ((), σ') (by rw [h1']; rfl)⟩ exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- `JHole.mcsPPJC` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b75) +`mcsPPJCMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJCM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) (hns : Vs.NoSwitch σ) + (hsch : Fl4Spec.schedulable σ.curThread σ = false) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJCMG hAT hmrt hmb hC hni hns hsch hM hK hR hV) + fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJU` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJUM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- (mmuAD gen 42b75) `JHole.mcsPPJU` with `MR` and `ValidIrqMasks` after (module docstring), over +any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJUMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -142,14 +183,12 @@ theorem JHole.mcsPPJUM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : (hsch : Fl4Spec.schedulable σ.curThread σ = false) (hin : ¬ PPCovI σ) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by have hax : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → Fl4Spec.scActive x = true := fun x n h => by cases e : Fl4Spec.scActive x with | true => rfl @@ -183,18 +222,36 @@ theorem JHole.mcsPPJUM [VxE Z] {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : rw [hc.cur] at hcv subst hcv refine WP.spec_mono (Hh.chargeBudgetUJ hAT hnc hsch hct hf hg hax hmrt hmb _) ?_ - rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J'⟩ + rintro ⟨s', a'⟩ ⟨ha, σ', h1, -, Lst', J', F'⟩ simp only at ha subst a' have hga : Fl4Spec.getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False) := by unfold Fl4Spec.getScActive Fl4Spec.NonDet.getsThe; rw [readScActive_eq' hkx', hax']; rfl have h1' : Fl4Spec.chargeBudget (Z := Unit) σ.consumedTime false σ = ({((), σ')}, False) := by rw [hs.consumed]; exact h1 - exact ⟨σ', fun y hy => mem_pp_charge hsch hga (by rw [h1']; rfl) hy, - fun hy => fail_pp_charge hsch hga (by rw [h1']; rfl) hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), + exact ⟨σ', fun tl => ⟨fun y hy => mem_ppG_charge hsch hga (by rw [h1']; rfl) hy, + fun hy => fail_ppG_charge hsch hga (by rw [h1']; rfl) hy⟩, + JAtN.of J' F', MachF.mfk_chargeBudget _ _ σ ((), σ') (by rw [h1']; rfl), fun hN => SInv.ns_chargeBudget _ _ σ hN ((), σ') (by rw [h1']; rfl)⟩ exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- `JHole.mcsPPJU` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b75) +`mcsPPJUMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJUM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hnc : ¬ CurInv σ) (hct : CtOK σ) (hf : CurScFree σ) (hg : Chg σ) + (hsch : Fl4Spec.schedulable σ.curThread σ = false) (hin : ¬ PPCovI σ) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJUMG hAT hmrt hmb hnc hct hf hg hsch hin hM hK hR hV) + fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointMRPath4.lean b/proofs/Fl4Proofs/P3/XTopJointMRPath4.lean index d98a7c269..89384945f 100644 --- a/proofs/Fl4Proofs/P3/XTopJointMRPath4.lean +++ b/proofs/Fl4Proofs/P3/XTopJointMRPath4.lean @@ -6,6 +6,14 @@ XTopJointPreemptA's `mcsPPJA` and ScChargeTR's `mcsPPJR` (insufficient budget: `checkBudget`'s charge with a timeout fault to an endpoint handler, idle/sending resp. receiving; `mfk_checkBudget`), with `MR r.2 σ'.ms ∧ ValidIrqMasks σ'` after. Scripted copies as in XTopJointMRPath3. + +(mmuAD gen 42b70, the Architect's ruling (c1) part 2, item 2) `mcsPPJAM` / `mcsPPJRM` take no `JExt` at the hole's +base (nor `VxE`): they end at `JAtN` from the hole's base, as `mcsPPJIM` (the timeout charges' posts, ScChargeT / +ScChargeTR over `JTH.j0 : JAtZB`). +(mmuAD gen 42b75) **`mcsPPJIMG` / `mcsPPJAMG`**: the two over any last step `tl` of the path (XTopJointPreempt's +`ppG`, XTopJointPreemptI's `mem_ppG_inact`), for P3/VmPreempt's `JHole.mcsPPVF`; `mcsPPJIM` / `mcsPPJAM` their +corollaries (statements unchanged). +(mmuAD gen 42b78) **`mcsPPJRMG`** likewise, for `JHole.mcsPPVF`'s receiving-endpoint holes; `mcsPPJRM` its corollary. -/ import Fl4Proofs.P3.XTopJointMRPath3 open Aeneas Aeneas.Std Result @@ -20,20 +28,19 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {MR : A → Fl4Spec.MachineState → Prop} set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJI` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJIM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hcov : PPCovI σ) +/-- (mmuAD gen 42b75) `JHole.mcsPPJI` with `MR` and `ValidIrqMasks` after (module docstring), over +any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJIMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hcov : PPCovI σ) (hAT : P0.ArchTotal arI) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by obtain ⟨hsch, hin⟩ := hcov have J := Hh.j0 have hS := Hh.xtop.fin.1.1.1 @@ -149,15 +156,32 @@ theorem JHole.mcsPPJIM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : · show _ = some σ.curSc; rw [hcs]; exact hxs · rw [← hk, ← hcs]; exact hy · exact Or.inr ⟨⟨c', hc', hcv'.trans hcs.symm⟩, fun y m hy => h2 y m (by rw [← hk, ← hcs]; exact hy)⟩ - obtain ⟨Lst', J'⟩ := Hh2.toJ hO hOw - exact ⟨cons0 σ, fun y hy => mem_pp_inact hs' hga hy, fun hy => fail_pp_inact hs' hga hy, ⟨Z, H, Cs, Ac, Lst', D, J', inferInstance⟩, rfl, fun hN => hN⟩ + obtain ⟨Lst', J', F'⟩ := Hh2.toJ hO hOw + exact ⟨cons0 σ, fun tl => ⟨fun y hy => mem_ppG_inact hs' hga hy, + fun hy => fail_ppG_inact hs' hga hy⟩, + JAtN.of J' F', rfl, fun hN => hN⟩ exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- `JHole.mcsPPJI` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b75) +`mcsPPJIMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJIM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hcov : PPCovI σ) + (hAT : P0.ArchTotal arI) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJIMG hcov hAT hM hK hR hV) + fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJA` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJAM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hAT : P0.ArchTotal arI) +/-- (mmuAD gen 42b75) `JHole.mcsPPJA` with `MR` and `ValidIrqMasks` after (module docstring), over +any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJAMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) @@ -172,14 +196,12 @@ theorem JHole.mcsPPJAM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists @@ -199,17 +221,43 @@ theorem JHole.mcsPPJAM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : rintro ⟨r, s', a'⟩ ⟨hT, hF⟩ refine (WP.spec_ok _).2 ?_ cases r - · obtain ⟨z, hz, -, V, Ac', Lst', D', J'⟩ := hF rfl - exact ⟨z.2, fun y hy => mem_pp_sched hsch hz hy, fun hy => fail_pp_sched hsch hz hy, - ⟨Z.mv Z.G V, H, Cs, Ac', Lst', D', J', inferInstance⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ + · obtain ⟨z, hz, -, V, Ac', Lst', D', J', F'⟩ := hF rfl + exact ⟨z.2, fun tl => ⟨fun y hy => mem_ppG_sched hsch hz hy, + fun hy => fail_ppG_sched hsch hz hy⟩, + ⟨V, Ac', Lst', D', J', F'⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ · exact absurd (hT rfl).2.2 hnsuf exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- `JHole.mcsPPJA` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b75) +`mcsPPJAMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJAM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hsch : Fl4Spec.schedulable σ.curThread σ = true) + (hnsuf : ¬ (∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → + Fl4Spec.refillSufficient σ.consumedTime (Fl4Spec.refillHd y) = true)) + {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) + (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) + (hcb : ∀ xe, σ.kheap p = some (.endpoint xe) → Endp.CanBlock false xe) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJAMG hAT hmrt hmb hC hni hres hnq hsch hnsuf hkt hrr hth hper hcb hM hK hR hV) + fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ set_option maxHeartbeats 16000000 in -/-- `JHole.mcsPPJR` with `MR` and `ValidIrqMasks` after (module docstring). -/ -theorem JHole.mcsPPJRM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) [VxE Z] (hAT : P0.ArchTotal arI) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) +/-- (mmuAD gen 42b78) `JHole.mcsPPJR` with `MR` and `ValidIrqMasks` after (module docstring), over any last step `tl` of the path (`ppG`). -/ +theorem JHole.mcsPPJRMG {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ (a : A) v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) @@ -225,14 +273,12 @@ theorem JHole.mcsPPJRM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : (hkl : ∃ l, σ.kheap p = some (.endpoint (.recvEP l))) (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ (NativeScope σ → NativeScope σ') ⦄ := by have key : syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', - (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ - ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ - JAt (L := L) arI AR r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by + (∀ tl : Fl4Spec.SMonad Unit Unit, (∀ y, y ∈ (tl σ').1 → y ∈ (ppG tl σ).1) ∧ ((tl σ').2 → (ppG tl σ).2)) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MachF.msF σ' = MachF.msF σ ∧ (NativeScope σ → NativeScope σ') ⦄ := by have hS := Hh.xtop.fin.1.1.1 have hR := Hh.xtop.fin.1.1.2.2.1 obtain ⟨Q, R, hc, hs⟩ := hS.lists @@ -252,12 +298,37 @@ theorem JHole.mcsPPJRM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : rintro ⟨r, s', a'⟩ ⟨hT, hF⟩ refine (WP.spec_ok _).2 ?_ cases r - · obtain ⟨z, hz, -, V, Ac', Lst', D', J'⟩ := hF rfl - exact ⟨z.2, fun y hy => mem_pp_sched hsch hz hy, fun hy => fail_pp_sched hsch hz hy, - ⟨Z.mv Z.G V, H, Cs, Ac', Lst', D', J', inferInstance⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ + · obtain ⟨z, hz, -, V, Ac', Lst', D', J', F'⟩ := hF rfl + exact ⟨z.2, fun tl => ⟨fun y hy => mem_ppG_sched hsch hz hy, fun hy => fail_ppG_sched hsch hz hy⟩, + ⟨V, Ac', Lst', D', J', F'⟩, MachF.mfk_checkBudget σ z hz, fun hN => SInv.ns_checkBudget σ hN z hz⟩ · exact absurd (hT rfl).2.2 hnsuf exact WP.spec_mono (WP.spec_and key (MK.syscall_mcs_preemption_point L.total hAT hK hR)) - fun _ ⟨⟨σ', h1, h2, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, h2, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + fun _ ⟨⟨σ', h1, hJ, hF, hNs⟩, hR'⟩ => ⟨σ', h1, hJ, msF_mr hM hR' hF, msF_vim hV hF, hNs⟩ + +/-- `JHole.mcsPPJR` with `MR` and `ValidIrqMasks` after (module docstring). (mmuAD gen 42b78) `mcsPPJRMG`'s corollary, statement unchanged. -/ +theorem JHole.mcsPPJRM {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (Hh : JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ) (hAT : P0.ArchTotal arI) (hmax : Fl4Spec.maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ (a : A) v, arI.ticks_to_us a v ⦃ r => r.bv = Fl4Spec.ticksToUs v.bv ⦄) + (hmrt : sporadic.max_release_time arI a ⦃ mrt => mrt.bv = Fl4Spec.MAX_RELEASE_TIME ⦄) + (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) + (hC : CurInv σ) (hni : σ.curThread ≠ σ.idleThread) + (hres : σ.schedulerAction = .resumeCurThread ∨ σ.schedulerAction = .chooseNewThread) + (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hsch : Fl4Spec.schedulable σ.curThread σ = true) + (hnsuf : ¬ (∀ y n, σ.kheap σ.curSc = some (.schedContext y n) → + Fl4Spec.refillSufficient σ.consumedTime (Fl4Spec.refillHd y) = true)) + {xt : Fl4Spec.Tcb} (hkt : σ.kheap σ.curThread = some (.tcb xt)) + (hrr : xt.tcbState = .running ∨ xt.tcbState = .restart) + {p bd : Fl4Spec.Word} {r : Fl4Spec.CapRights} (hth : xt.tcbTimeoutHandler = .endpointCap p bd r) + (hper : ∀ x n, σ.kheap σ.curSc = some (.schedContext x n) → x.scPeriod ≠ 0) + (hkl : ∃ l, σ.kheap p = some (.endpoint (.recvEP l))) + (hM : MachPlat arI MR) (hK : MRKeep arI MR) (hR : MR a σ.machineState) (hV : ValidIrqMasks σ) : + syscall.mcs_preemption_point st arI s a ⦃ r => ∃ σ', + (∀ y, y ∈ (Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').1 → y ∈ (Fl4Spec.preemptionPath (Z := Unit) σ).1) ∧ + ((Fl4Spec.maybeHandleInterrupt (Z := Unit) true σ').2 → (Fl4Spec.preemptionPath (Z := Unit) σ).2) ∧ + JAtN (L := L) arI AR Z H Cs s0 σ0 r.1 r.2 σ' ∧ MR r.2 σ'.machineState ∧ ValidIrqMasks σ' ∧ + (NativeScope σ → NativeScope σ') ⦄ := + WP.spec_mono (Hh.mcsPPJRMG hAT hmax htu hmrt hmb hC hni hres hnq hsch hnsuf hkt hrr hth hper hkl hM hK hR hV) + fun _ ⟨σ', hT', rest⟩ => ⟨σ', (hT' _).1, (hT' _).2, rest⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointNoFault.lean b/proofs/Fl4Proofs/P3/XTopJointNoFault.lean index 968dd18f7..52ab92bc8 100644 --- a/proofs/Fl4Proofs/P3/XTopJointNoFault.lean +++ b/proofs/Fl4Proofs/P3/XTopJointNoFault.lean @@ -32,6 +32,11 @@ deleted). (mmuAD gen 42b18) `stsCurJ` stated over `JAtZB` in place (the copy's post, with the `TFoot` footprint); `JAtZ.stsCurJ` its corollary (`ext` by `JAtZ.ext_tfoot`). P3/JAtZV3HiFault's copy deleted. + +(mmuAD gen 42b67, option (b) step b3) **`JAtN`** [definition]: `JAtZB (Z.mv Z.G V) H Cs …` after a native step +(`NatFoot` from the start), the post of the cap-fault arm over `JAtZB`; `JAtN.toJAt` / `JAtN.post` (back to `JAt` from +a `JAtZ` start), `JAtN.of`. `noFaultJ` stated over `JAtZB` in place with post `JAtN` (`natK_tcbW`); `JAtZ.noFaultJ` +its corollary, statement unchanged. No named premise. -/ import Fl4Proofs.P3.XTopJointStsI open Aeneas Aeneas.Std Result @@ -325,14 +330,42 @@ theorem fhCap_rel {th : TypedHeap} {m : U64 → U64} {σ' : Fl4Spec.State Unit} rw [slotAddr_ofBl, tcbCnodeIndex_blVal 3 (by decide)] exact ⟨x, c, hkx, by rw [he]; exact hc, hca⟩ +/-- (mmuAD gen 42b67) **`JAtZB` after a native step from `(s, σ)`**: at `Z.mv Z.G V` with `H`, `Cs` kept (any `Ac`, +`Lst`, `D`), FL4's and the spec's step from `(s, σ)` inside the native footprint `NatFoot` (P3/NatFoot) — the post +of the cap-fault arm over `JAtZB`, from which P3/EptReport's `VmEptState.ofNat` rebuilds a `VmEptState`. -/ +def JAtN (arI : machine.Arch A) (AR : A → Fl4Spec.Cr3 → Prop) (Z : XSets) (H : P1.Heap) (Cs : Set U64) (s : S) + (σ : Fl4Spec.State Unit) (s' : S) (a' : A) (σ' : Fl4Spec.State Unit) : Prop := + ∃ (V : XVs) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac' Lst' D' s' a' σ' ∧ NatFoot (L := L) Z s σ s' σ' + +/-- `JAtN` from a `JAtZ` start is `JAt` (`JAtZB.toJN`, `VxE.mv`). -/ +theorem JAtN.toJAt (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {s' : S} {a' : A} + {σ' : Fl4Spec.State Unit} (h : JAtN (L := L) arI AR Z H Cs s σ s' a' σ') : JAt (L := L) arI AR s' a' σ' := + match h with + | ⟨_, _, _, _, B', F⟩ => ⟨_, _, _, _, _, _, B'.toJN J F, inferInstance⟩ + +/-- `JAtN` of a native step from the start (`V := Z.vs`). -/ +theorem JAtN.of {Ac' : Set U64} {Lst' : U64 → List U64} {D' : Set U64} {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} + (B' : JAtZB (L := L) arI AR Z H Cs Ac' Lst' D' s' a' σ') (F : NatFoot (L := L) Z s σ s' σ') : + JAtN (L := L) arI AR Z H Cs s σ s' a' σ' := + ⟨Z.vs, Ac', Lst', D', B', F⟩ + +/-- The cap-fault arm's post from `JAtN` at `JAtZ` (`JAtN.toJAt`). -/ +theorem JAtN.post (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {P : Set (Unit × Fl4Spec.State Unit)} + {r : S × A} (h : ∃ z ∈ P, RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2) : + ∃ z ∈ P, RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 := + match h with + | ⟨z, hz, hR, hN⟩ => ⟨z, hz, hR, hN.toJAt J⟩ + set_option maxHeartbeats 8000000 in -/-- **`handle_fault` with a null fault handler at `J`** (module docstring). -/ -theorem JAtZ.noFaultJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} +/-- **`handle_fault` with a null fault handler at `J`** (module docstring; (mmuAD gen 42b67) over `JAtZB` in place, +post `JAtN`: the current thread's `Inactive` is a native step, `natK_tcbW`). -/ +theorem JAtZB.noFaultJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) {ct : U64} (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) (hnull : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok .Null) (f : error.Fault) (f' : Fl4Spec.Fault) : faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, - RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := by + RelTopM (L := L) r.1 z.2 ∧ JAtN (L := L) arI AR Z H Cs s σ r.1 r.2 z.2 ⦄ := by obtain ⟨hcur, x, hk, hrn⟩ := J.curRunnable hni hct have htcb : Z.th ct = some .tcb := (J.xtop.curTcb hcur).1 obtain ⟨x1, c1, hk1, hc1, hcr⟩ := fhCap_rel J.xtop.rel.2.1.1 htcb @@ -371,10 +404,20 @@ theorem JAtZ.noFaultJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] dsimp only simp only [bind_ok, Bool.false_eq_true, ↓reduceIte] refine WP.spec_bind (J.stsCurJ hni hT hD hk hcur hrn hnq' hB) ?_ - rintro s6 ⟨Lst', J6⟩ + rintro s6 ⟨Lst', J6, hW⟩ refine (WP.spec_ok _).2 ⟨_, by rw [hspec]; exact Set.mem_singleton _, ⟨Z.th, Z.G, J6.xtop.rel.1, J6.xtop.rel.2.1, J6.xtop.rel.2.2.1, J6.xtop.rel.2.2.2.1, J6.xtop.rel.2.2.2.2.1⟩, - ⟨Z, H, Cs, Ac, Lst', D, J6, inferInstance⟩⟩ + JAtN.of J6 (NatFoot.ofT J.xtop hW (fun b hb => J.tfoot_nh hb) + (natK_tcbW hk (Notif.stsAct_kheap _ _) fun h => by simp at h))⟩ + +/-- `JAtZB.noFaultJ` at `JAtZ` (`JAtN.post`). -/ +theorem JAtZ.noFaultJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] (hni : Entered σ) {ct : U64} + (hct : sched.cur_thread st s = ok ct) (hnq : ∀ d p, σ.curThread ∉ σ.readyQueues d p) + (hnull : capAt (L.mem s) (cslotAddr (ct.bv, Fl4Spec.tcbCnodeIndex 3)) = ok .Null) + (f : error.Fault) (f' : Fl4Spec.Fault) : + faults.handle_fault st arI s a ct f ⦃ r => ∃ z ∈ (Fl4Spec.handleFault (Z := Unit) ct.bv f' σ).1, + RelTopM (L := L) r.1 z.2 ∧ JAt (L := L) arI AR r.1 r.2 z.2 ⦄ := + WP.spec_mono (J.toB.noFaultJ hni hct hnq hnull f f') fun _ h => JAtN.post J h /-- **[W] The fault handler at `JAt` when the faulting thread's fault-handler slot holds an endpoint cap**: FL4's `set_fault` then the diff --git a/proofs/Fl4Proofs/P3/XTopJointPPH.lean b/proofs/Fl4Proofs/P3/XTopJointPPH.lean index 205d55265..943ae5f67 100644 --- a/proofs/Fl4Proofs/P3/XTopJointPPH.lean +++ b/proofs/Fl4Proofs/P3/XTopJointPPH.lean @@ -117,9 +117,9 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} -/-- **A `JAtZ` state is a `JHole` over itself.** -/ -theorem JAtZ.toHole {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) : +/-- **A `JAtZB` state is a `JHole` over itself** (gen 42b69: from `JAtZB`, `JHole.j0` being `JAtZB`). -/ +theorem JAtZB.toHole {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) : JHole (L := L) arI AR Z H Cs Ac Lst D s a σ s a σ where j0 := J spec := ⟨σ.machineState, σ.curTime, σ.consumedTime, rfl, rfl⟩ @@ -133,6 +133,12 @@ theorem JAtZ.toHole {s : S} {a : A} {σ : Fl4Spec.State Unit} dbg := rfl dbgK := P1.DbgKeep.refl s +/-- **A `JAtZ` state is a `JHole` over itself** (`JAtZB.toHole` via `JAtZ.toB`). -/ +theorem JAtZ.toHole {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) : + JHole (L := L) arI AR Z H Cs Ac Lst D s a σ s a σ := + J.toB.toHole + end end diff --git a/proofs/Fl4Proofs/P3/XTopJointPreempt.lean b/proofs/Fl4Proofs/P3/XTopJointPreempt.lean index a93df6920..f88bc4914 100644 --- a/proofs/Fl4Proofs/P3/XTopJointPreempt.lean +++ b/proofs/Fl4Proofs/P3/XTopJointPreempt.lean @@ -48,6 +48,10 @@ state (XTopJointPPH's `jAtPre_hole`: a `JHole`). [P], `JIrqHyp` [W] and `JPreemptRestHyp` [W]; `dispatch_invokeJP` / `dispatch_invokeJEP` are `dispatch_invokeJ` / `dispatch_invokeJE` with it (no `hPre`). + +(mmuAD gen 42b74) **`ppG tl`**: `preemption_path` with its last step (`maybe_handle_interrupt true`) a parameter +(`preemptionPath_ppG`, `rfl`); `mem_ppG_sched` / `mem_ppG_charge` / `fail_ppG_sched` / `fail_ppG_charge` over any last +step, the `mem_pp_*` / `fail_pp_*` names their corollaries (statements unchanged). -/ import Fl4Proofs.P3.XTopJointPPH import Fl4Proofs.P3.XTopJointBudgetT @@ -62,26 +66,43 @@ noncomputable section section Spec open Fl4Spec -/-- **An outcome of `preemption_path`, schedulable current thread**: an -outcome of `check_budget`, then of `maybe_handle_interrupt true`. -/ -theorem mem_pp_sched {σ σ' : State Unit} {b : Bool} {y : Unit × State Unit} +/-- (mmuAD gen 42b74) **`preemption_path` with its last step `tl` a parameter** (module docstring). -/ +def ppG (tl : SMonad Unit Unit) : SMonad Unit Unit := do + let ct ← NonDet.gets fun s : State Unit => s.curThread + let sched ← NonDet.gets (schedulable ct) + if sched then do + let _ ← checkBudget + pure () + else do + let csc ← NonDet.gets fun s : State Unit => s.curSc + let active ← getScActive csc + if active + then do + let consumed ← NonDet.gets fun s : State Unit => s.consumedTime + chargeBudget consumed false + else NonDet.modify fun s : State Unit => { s with consumedTime := 0 } + tl + +theorem preemptionPath_ppG : preemptionPath (Z := Unit) = ppG (maybeHandleInterrupt true) := rfl + +/-- **An outcome of `ppG tl`, schedulable current thread**: an outcome of `check_budget`, then of `tl`. -/ +theorem mem_ppG_sched {tl : SMonad Unit Unit} {σ σ' : State Unit} {b : Bool} {y : Unit × State Unit} (hs : schedulable σ.curThread σ = true) (h1 : (b, σ') ∈ (checkBudget (Z := Unit) σ).1) - (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true σ').1) : y ∈ (preemptionPath (Z := Unit) σ).1 := by - unfold preemptionPath + (h2 : y ∈ (tl σ').1) : y ∈ (ppG tl σ).1 := by + unfold ppG refine mem_bind_nd (x := (σ.curThread, σ)) rfl (mem_bind_nd (x := (schedulable σ.curThread σ, σ)) rfl ?_) show y ∈ ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).1 rw [if_pos hs] exact mem_bind_nd h1 h2 -/-- **An outcome of `preemption_path`, current thread not schedulable, active -current SC**: an outcome of `charge_budget consumed false`, then of -`maybe_handle_interrupt true`. -/ -theorem mem_pp_charge {σ σ' : State Unit} {y : Unit × State Unit} +/-- **An outcome of `ppG tl`, current thread not schedulable, active current SC**: an outcome of +`charge_budget consumed false`, then of `tl`. -/ +theorem mem_ppG_charge {tl : SMonad Unit Unit} {σ σ' : State Unit} {y : Unit × State Unit} (hs : schedulable σ.curThread σ = false) (hga : getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False)) (h1 : ((), σ') ∈ (chargeBudget (Z := Unit) σ.consumedTime false σ).1) - (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true σ').1) : y ∈ (preemptionPath (Z := Unit) σ).1 := by - unfold preemptionPath + (h2 : y ∈ (tl σ').1) : y ∈ (ppG tl σ).1 := by + unfold ppG refine mem_bind_nd (x := (σ.curThread, σ)) rfl (mem_bind_nd (x := (schedulable σ.curThread σ, σ)) rfl ?_) show y ∈ ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).1 rw [if_neg (by simp [hs])] @@ -90,21 +111,21 @@ theorem mem_pp_charge {σ σ' : State Unit} {y : Unit × State Unit} rw [if_pos rfl] exact mem_bind_nd (x := (σ.consumedTime, σ)) rfl (mem_bind_nd h1 h2) -theorem fail_pp_sched {σ σ' : State Unit} {b : Bool} +theorem fail_ppG_sched {tl : SMonad Unit Unit} {σ σ' : State Unit} {b : Bool} (hs : schedulable σ.curThread σ = true) (h1 : (b, σ') ∈ (checkBudget (Z := Unit) σ).1) - (h2 : (maybeHandleInterrupt (Z := Unit) true σ').2) : (preemptionPath (Z := Unit) σ).2 := by - unfold preemptionPath + (h2 : (tl σ').2) : (ppG tl σ).2 := by + unfold ppG refine Or.inr ⟨(σ.curThread, σ), rfl, Or.inr ⟨(schedulable σ.curThread σ, σ), rfl, ?_⟩⟩ show ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).2 rw [if_pos hs] exact Or.inr ⟨_, h1, h2⟩ -theorem fail_pp_charge {σ σ' : State Unit} +theorem fail_ppG_charge {tl : SMonad Unit Unit} {σ σ' : State Unit} (hs : schedulable σ.curThread σ = false) (hga : getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False)) (h1 : ((), σ') ∈ (chargeBudget (Z := Unit) σ.consumedTime false σ).1) - (h2 : (maybeHandleInterrupt (Z := Unit) true σ').2) : (preemptionPath (Z := Unit) σ).2 := by - unfold preemptionPath + (h2 : (tl σ').2) : (ppG tl σ).2 := by + unfold ppG refine Or.inr ⟨(σ.curThread, σ), rfl, Or.inr ⟨(schedulable σ.curThread σ, σ), rfl, ?_⟩⟩ show ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).2 rw [if_neg (by simp [hs])] @@ -113,6 +134,35 @@ theorem fail_pp_charge {σ σ' : State Unit} rw [if_pos rfl] exact Or.inr ⟨(σ.consumedTime, σ), rfl, Or.inr ⟨_, h1, h2⟩⟩ +/-- **An outcome of `preemption_path`, schedulable current thread**: an +outcome of `check_budget`, then of `maybe_handle_interrupt true`. -/ +theorem mem_pp_sched {σ σ' : State Unit} {b : Bool} {y : Unit × State Unit} + (hs : schedulable σ.curThread σ = true) (h1 : (b, σ') ∈ (checkBudget (Z := Unit) σ).1) + (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true σ').1) : y ∈ (preemptionPath (Z := Unit) σ).1 := + mem_ppG_sched hs h1 h2 + +/-- **An outcome of `preemption_path`, current thread not schedulable, active +current SC**: an outcome of `charge_budget consumed false`, then of +`maybe_handle_interrupt true`. -/ +theorem mem_pp_charge {σ σ' : State Unit} {y : Unit × State Unit} + (hs : schedulable σ.curThread σ = false) + (hga : getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False)) + (h1 : ((), σ') ∈ (chargeBudget (Z := Unit) σ.consumedTime false σ).1) + (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true σ').1) : y ∈ (preemptionPath (Z := Unit) σ).1 := + mem_ppG_charge hs hga h1 h2 + +theorem fail_pp_sched {σ σ' : State Unit} {b : Bool} + (hs : schedulable σ.curThread σ = true) (h1 : (b, σ') ∈ (checkBudget (Z := Unit) σ).1) + (h2 : (maybeHandleInterrupt (Z := Unit) true σ').2) : (preemptionPath (Z := Unit) σ).2 := + fail_ppG_sched hs h1 h2 + +theorem fail_pp_charge {σ σ' : State Unit} + (hs : schedulable σ.curThread σ = false) + (hga : getScActive (Z := Unit) σ.curSc σ = ({(true, σ)}, False)) + (h1 : ((), σ') ∈ (chargeBudget (Z := Unit) σ.consumedTime false σ).1) + (h2 : (maybeHandleInterrupt (Z := Unit) true σ').2) : (preemptionPath (Z := Unit) σ).2 := + fail_ppG_charge hs hga h1 h2 + theorem checkBudget_suff {σ : State Unit} (hnd : numDomains = 1) (hb : getScRefillSufficient (Z := Unit) σ.curSc σ.consumedTime σ = ({(true, σ)}, False)) : checkBudget (Z := Unit) σ = ({(true, σ)}, False) := by @@ -177,7 +227,7 @@ variable (arI) in path carries (its outcomes become kernel exits, where `JAt` asks `VxE`). -/ def JHoleAtV (AR : A → Fl4Spec.Cr3 → Prop) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop := ∃ (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s0 : S) (a0 : A) - (σ0 : Fl4Spec.State Unit), JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ ∧ VxE Z + (σ0 : Fl4Spec.State Unit), JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ ∧ JExt (L := L) Z.th s0 ∧ VxE Z /-- **The cases of the preemption path proved here**: `CurInv`, the current thread not idle, no switch to it pending, no timeout fault raisable. -/ diff --git a/proofs/Fl4Proofs/P3/XTopJointPreemptI.lean b/proofs/Fl4Proofs/P3/XTopJointPreemptI.lean index c8b4d6b68..4fe23fe81 100644 --- a/proofs/Fl4Proofs/P3/XTopJointPreemptI.lean +++ b/proofs/Fl4Proofs/P3/XTopJointPreemptI.lean @@ -28,6 +28,8 @@ inactive idle SC). `CurInv` is not needed: the step touches one node word. the preemption point's base, XTopJointPreemptZ's `jAtPre_holeTN`; `jPreemptRestHypJ_of`), `hPre_ofZJ`, `dispatch_invokeJPZJ` / `dispatch_invokeJEPZJ`. +* (mmuAD gen 42b75) `mem_ppG_inact` / `fail_ppG_inact`: the inactive-SC outcomes of XTopJointPreempt's `ppG tl` + over any last step; `mem_pp_inact` / `fail_pp_inact` their corollaries (statements unchanged). -/ import Fl4Proofs.P3.XTopJointPreemptZ open Aeneas Aeneas.Std Result @@ -40,12 +42,14 @@ noncomputable section section Spec open Fl4Spec -theorem mem_pp_inact {σ : State Unit} {y : Unit × State Unit} +/-- (mmuAD gen 42b75) **An outcome of `ppG tl`, inactive current SC** (XTopJointPreempt's `ppG`): `consumedTime := 0`, +then `tl`. `mem_pp_inact` is it at `maybeHandleInterrupt true`. -/ +theorem mem_ppG_inact {tl : SMonad Unit Unit} {σ : State Unit} {y : Unit × State Unit} (hs : schedulable σ.curThread σ = false) (hga : getScActive (Z := Unit) σ.curSc σ = ({(false, σ)}, False)) - (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true { σ with consumedTime := 0 }).1) : - y ∈ (preemptionPath (Z := Unit) σ).1 := by - unfold preemptionPath + (h2 : y ∈ (tl { σ with consumedTime := 0 }).1) : + y ∈ (ppG tl σ).1 := by + unfold ppG refine mem_bind_nd (x := (σ.curThread, σ)) rfl (mem_bind_nd (x := (schedulable σ.curThread σ, σ)) rfl ?_) show y ∈ ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).1 rw [if_neg (by simp [hs])] @@ -54,12 +58,13 @@ theorem mem_pp_inact {σ : State Unit} {y : Unit × State Unit} rw [if_neg (by simp)] exact mem_bind_nd (Set.mem_singleton _) h2 -theorem fail_pp_inact {σ : State Unit} +/-- (mmuAD gen 42b75) `ppG tl` fails where `tl` fails after the inactive-SC branch; `fail_pp_inact` its corollary. -/ +theorem fail_ppG_inact {tl : SMonad Unit Unit} {σ : State Unit} (hs : schedulable σ.curThread σ = false) (hga : getScActive (Z := Unit) σ.curSc σ = ({(false, σ)}, False)) - (h2 : (maybeHandleInterrupt (Z := Unit) true { σ with consumedTime := 0 }).2) : - (preemptionPath (Z := Unit) σ).2 := by - unfold preemptionPath + (h2 : (tl { σ with consumedTime := 0 }).2) : + (ppG tl σ).2 := by + unfold ppG refine Or.inr ⟨(σ.curThread, σ), rfl, Or.inr ⟨(schedulable σ.curThread σ, σ), rfl, ?_⟩⟩ show ((if schedulable σ.curThread σ = true then (_ : SMonad Unit Unit) else _) σ).2 rw [if_neg (by simp [hs])] @@ -68,6 +73,20 @@ theorem fail_pp_inact {σ : State Unit} rw [if_neg (by simp)] exact Or.inr ⟨_, Set.mem_singleton _, h2⟩ +theorem mem_pp_inact {σ : State Unit} {y : Unit × State Unit} + (hs : schedulable σ.curThread σ = false) + (hga : getScActive (Z := Unit) σ.curSc σ = ({(false, σ)}, False)) + (h2 : y ∈ (maybeHandleInterrupt (Z := Unit) true { σ with consumedTime := 0 }).1) : + y ∈ (preemptionPath (Z := Unit) σ).1 := + mem_ppG_inact hs hga h2 + +theorem fail_pp_inact {σ : State Unit} + (hs : schedulable σ.curThread σ = false) + (hga : getScActive (Z := Unit) σ.curSc σ = ({(false, σ)}, False)) + (h2 : (maybeHandleInterrupt (Z := Unit) true { σ with consumedTime := 0 }).2) : + (preemptionPath (Z := Unit) σ).2 := + fail_ppG_inact hs hga h2 + end Spec section diff --git a/proofs/Fl4Proofs/P3/XTopJointPreemptM.lean b/proofs/Fl4Proofs/P3/XTopJointPreemptM.lean index 228b67ba5..712580cfb 100644 --- a/proofs/Fl4Proofs/P3/XTopJointPreemptM.lean +++ b/proofs/Fl4Proofs/P3/XTopJointPreemptM.lean @@ -63,7 +63,8 @@ theorem JHole.chargeBudgetUJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (hmb : sporadic.min_budget arI a ⦃ mb => mb.bv = Fl4Spec.MIN_BUDGET ⦄) (used : U64) : sched.charge_budget st arI s a used false ⦃ r => r.2 = a ∧ ∃ σ', Fl4Spec.chargeBudget (Z := Unit) used.bv false σ = ({((), σ')}, False) ∧ ScTKw (fun _ => False) σ σ' ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ + NatFoot (L := L) Z s0 σ0 r.1 σ' ⦄ := by have J := Hh.j0 obtain ⟨hK0, hsok0, hlk0, hfk0, ekh, -, -, -, earch, -, -, hbsaσ⟩ := Hh.sfacts have hP0 := J.ip @@ -193,7 +194,7 @@ theorem JHole.chargeBudgetUJ {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S (J.sc_jpl hW hKc hidW.2) (J.sc_jcov hW hdead (fun q hq hn => absurd hq hn) hidW hKd subset_rfl) (J.sc_kern hW hKc hfkc hX' hDbg fun _ h => h) (J.sc_utc hW hKc hDbg) hN' hI' (Or.inl hcn') hown' hoff hAI' hbsa hcr hblk' hKd - hidW.1 J.zD⟩ + hidW.1 J.zD, NatFoot.ofT J.xtop hW (fun _ h => J.tfoot_nh h) (natK_tk hKc)⟩ variable (arI) in diff --git a/proofs/Fl4Proofs/P3/XTopJointPreemptZ.lean b/proofs/Fl4Proofs/P3/XTopJointPreemptZ.lean index 980900924..4a9f74b36 100644 --- a/proofs/Fl4Proofs/P3/XTopJointPreemptZ.lean +++ b/proofs/Fl4Proofs/P3/XTopJointPreemptZ.lean @@ -38,6 +38,9 @@ update, without carrying anything through the invocation: `hPre_ofI` / `dispatch_invokeJPI` / `dispatch_invokeJEPI` without `JIrqSigHyp` (remaining: `IrqPlat`, `PPPlat` [P], `hNS` [S], `JPreemptRestHypN` [W], as there). + +(mmuAD gen 42b71) **`JAtZB.msArJ`**: `JAtZ.msArJ` at `JAtZB` with the native footprint; `JAtZ.msArJ` its corollary. +`jIrqHypZ_ofN` calls `JHole.handleIrqJN` without `JExt` (its `hE` dropped, XTopJointIrq). -/ import Fl4Proofs.P3.XTopJointIrq open Aeneas Aeneas.Std Result @@ -64,11 +67,11 @@ variable (arI) in /-- Some `JHole` with `TShift` from its base ends at `(s, a, σ)`. -/ def JHoleAtT (AR : A → Fl4Spec.Cr3 → Prop) (s : S) (a : A) (σ : Fl4Spec.State Unit) : Prop := ∃ (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64) (s0 : S) (a0 : A) - (σ0 : Fl4Spec.State Unit), JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ ∧ TShift σ0 σ ∧ VxE Z + (σ0 : Fl4Spec.State Unit), JHole (L := L) arI AR Z H Cs Ac Lst D s0 a0 σ0 s a σ ∧ JExt (L := L) Z.th s0 ∧ TShift σ0 σ ∧ VxE Z theorem JHoleAtT.hole {s : S} {a : A} {σ : Fl4Spec.State Unit} (h : JHoleAtT (L := L) arI AR s a σ) : JHoleAtV (L := L) arI AR s a σ := - let ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, _, _⟩ := h; ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, inferInstance⟩ + let ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, _, _⟩ := h; ⟨Z, H, Cs, Ac, Lst, D, s0, a0, σ0, Hh, hEx, inferInstance⟩ /-- **`OffOK` at a shifted hole with a sufficient head** (module docstring). -/ theorem JHole.offOK_suff {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a : A} {σ : Fl4Spec.State Unit} @@ -101,14 +104,25 @@ theorem JHole.offOK_suff {s0 : S} {a0 : A} {σ0 : Fl4Spec.State Unit} {s : S} {a rw [show c = σ0.consumedTime + (t - σ0.curTime) from hT.2]; exact hs1 · simp only [Fl4Spec.refillReady, Fl4Spec.refillReady', decide_eq_true_eq, bv_add0]; exact hs2 +/-- (mmuAD gen 42b71) **A `JAtZB` state at another machine state (same memory) and arch state keeping `AR`**, a +native step (`JHole.msAr` / `JHole.toJ` over `JAtZB.toHole`). -/ +theorem JAtZB.msArJ {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (ms : Fl4Spec.MachineState) (a' : A) + (hum : ms.underlyingMemory = σ.machineState.underlyingMemory) + (hAR : AR a σ.archState.x64CurrentCr3 → AR a' σ.archState.x64CurrentCr3) : + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s a' { σ with machineState := ms } ∧ + NatFoot (L := L) Z s σ s { σ with machineState := ms } := + (J.toHole.msAr ms a' hum hAR).toJ J.off J.own + /-- **A `JAtZ` state at another machine state (same memory) and arch state -keeping `AR`** (the IRQ check). -/ +keeping `AR`** (the IRQ check). (mmuAD gen 42b71) `JAtZB.msArJ`'s corollary. -/ theorem JAtZ.msArJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (ms : Fl4Spec.MachineState) (a' : A) (hum : ms.underlyingMemory = σ.machineState.underlyingMemory) (hAR : AR a σ.archState.x64CurrentCr3 → AR a' σ.archState.x64CurrentCr3) : ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s a' { σ with machineState := ms } := - (J.toHole.msAr ms a' hum hAR).toJ J.off J.own + let ⟨Lst', B', F'⟩ := J.toB.msArJ ms a' hum hAR + ⟨Lst', B'.toJN J F'⟩ /-- **`JIrqHypZ` per state** (g3e): at every `JAt` state with `NativeScope` there, no ∀-form `hNS`. -/ diff --git a/proofs/Fl4Proofs/P3/XTopJointReadFpu.lean b/proofs/Fl4Proofs/P3/XTopJointReadFpu.lean index dfa1662ca..55cf534dc 100644 --- a/proofs/Fl4Proofs/P3/XTopJointReadFpu.lean +++ b/proofs/Fl4Proofs/P3/XTopJointReadFpu.lean @@ -97,23 +97,20 @@ open Fl4Proofs.P1 in set_option maxHeartbeats 16000000 in /-- **A frame word that is not an IPC-buffer word, written at `J`** (module docstring; the spec state kept). -/ -theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U64} - (hu : UserW (L := L) Z s σ w) (hnB : ∀ wp ∈ Z.B, wp.1 ≠ w) +theorem JAtZB.frameWrJCore (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U64} + (hal : P1.Aligned w) (hAp : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → w.val + 8 ≤ q.val ∨ q.val + 2 ^ k.bits ≤ w.val) (hObj : ∃ o ko, σ.kheap o = some ko ∧ o.toNat ≤ w.val ∧ w.val < o.toNat + 2 ^ Fl4Spec.objBits ko) - (hks : w.val + 8 ≤ (L.ksb s).val ∨ (L.ksb s).val + 304384 ≤ w.val) (v : U64) : + (hKn : ∀ c ∈ Cs, w.val + 8 ≤ L.nodeBase s c ∨ L.nodeBase s c + 4288 ≤ w.val) + (hKi : w.val < (L.ksb s).val + 1248 ∨ (L.ksb s).val + 5344 ≤ w.val) (v : U64) + (hSS : SlotsSame Z.th (L.mem s) (L.mem (L.wr s w v))) + (hX1 : XTopAt (L := L) AR Z (L.wr s w v) a σ) : JAtZB (L := L) arI AR Z H Cs Ac Lst D (L.wr s w v) a σ := by set s1 := L.wr s w v with hs1 have F : ArFr σ σ := ⟨fun _ => Or.inl rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ - have hP := J.xtop.fin.1.2 - have hal : P1.Aligned w := hu.al have hW : P1.WritesIn st s s1 (· = w) := P1.writesIn_wr hal have hkb : L.ksb s1 = L.ksb s := hW.1 have hcpu : L.cpu s1 = L.cpu s := hW.2.1 - have hSS : SlotsSame Z.th (L.mem s) (L.mem s1) := - slotsSame_wr hP.pl s v hal fun x hx ⟨h1, h2⟩ => - hu.vobj (vobj_of_slot hP.pl Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.ksb s) hx h1 h2) - have hX1 : XTopAt (L := L) AR Z s1 a σ := J.xtop.userWr hu hnB v -- the frame words obtain ⟨Q, R0, hcq, -⟩ := J.xtop.fin.1.1.1.lists have hT := hcq.tcbs @@ -164,17 +161,15 @@ theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U exact scw q z hq _ (by show (scW q K).val % 8 = 0; rw [hv]; omega) (by omega) (by omega) -- the debug word and the IRQ node: in the kernel-global data, which the word misses have hN0 : P1.NodePlaced st Z.T s 0#u64 := by rw [J.tcbs_eq.1]; exact P1.TInv.nodes J.blk _ J.kern.cs0 - have hnb0 : L.nodeBase s 0#u64 = (L.ksb s).val + 13568 := by - show (L.ksb s).val + 13568 + (0#u64 : U64).val * 4288 = _; simp have hDbg : L.mem s1 (L.nodeAt s 0#u64 layout.node.DEBUG_TCBS) = L.mem s (L.nodeAt s 0#u64 layout.node.DEBUG_TCBS) := by have hdv := P1.nodeAt_val hN0 (off := layout.node.DEBUG_TCBS) (by simp [layout.node.DEBUG_TCBS]) have hdo : layout.node.DEBUG_TCBS.val < 4288 := by simp [layout.node.DEBUG_TCBS] exact hW.mem_eq J.kern.dwAl fun hb => by - rw [hb, hnb0] at hdv; omega + rw [hb] at hdv + rcases hKn 0#u64 J.kern.cs0 with e | e <;> omega have hirq : ∀ i : U64, i.val < 128 → capV (L.mem s1) (nodeA (L.ksb s) i) = capV (L.mem s) (nodeA (L.ksb s) i) := - irqNode_keep hW J.kern.ksbFit J.kern.ksbAl fun b hb => by - rw [hb]; omega + irqNode_keep hW J.kern.ksbFit J.kern.ksbAl fun b hb => hb.symm ▸ hKi -- the dead stay dead have hAI : ActIdle σ := J.act.ar F have yk : YKeep σ σ := ⟨fun p x hp => ⟨x, (F.look (fun _ e => by cases e)).2 hp, rfl⟩, @@ -197,9 +192,7 @@ theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U · left; omega · right; simpa [P1.HKind.bits] using e · subst hb - have hcl := J.kern.csLt c hc - have hnb : L.nodeBase s c = (L.ksb s).val + 13568 + c.val * 4288 := rfl - omega + exact (hKn c hc).imp (fun h => by omega) id · subst hb rcases he with he | he · rcases hAp e _ he (fun _ e => by cases e) with e | e @@ -254,13 +247,10 @@ theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U have hkern := J.kern_keepA hkb hcpu hX1.fin.1.1.1 F hDbg have hKd : P1.DbgKeep st (P1.Heap.tcbs H) Cs s s1 := dbgKeep_of_writes J.blk hW fun b hb => by subst hb - refine J.notDbg (fun t ht => ?_) (fun c hc => ?_) - · rcases hAp t .tcb ht (fun _ e => by cases e) with e | e - · left; omega - · right; simpa [P1.HKind.bits] using e - · have hcl := J.kern.csLt c hc - have hnb : L.nodeBase s c = (L.ksb s).val + 13568 + c.val * 4288 := rfl - omega + refine J.notDbg (fun t ht => ?_) hKn + rcases hAp t .tcb ht (fun _ e => by cases e) with e | e + · left; omega + · right; simpa [P1.HKind.bits] using e have hTd : Sched.TdKeep (L := L) H s s1 := fun q hq => tcbK q (J.tcbZ hq) _ (P1.field_aligned (J.ip.e.tcb q (J.tcbZ hq)) (K := 3528#u64) (by simp) (by simp)) (by rw [J.tdA_val' (J.tcbZ hq)]; omega) (by rw [J.tdA_val' (J.tcbZ hq)]; omega) @@ -273,6 +263,24 @@ theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U exact J.cs_frameK (hvn := J.vsSS (G' := Z.G) hX1 hkb hSS (Vs.ArchShr.refl _)) hkb hX1 F.kback F.ipcFr (J.carry.frame subset_rfl F.ipcFr F.ksz) (JCs.sameB J hSS F.ksz) R (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) hSS hKd F.idle +open Fl4Proofs.P1 in +/-- A write to a frame word outside the IPC buffers. -/ +theorem JAtZB.frameWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U64} + (hu : UserW (L := L) Z s σ w) (hnB : ∀ wp ∈ Z.B, wp.1 ≠ w) + (hAp : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → w.val + 8 ≤ q.val ∨ q.val + 2 ^ k.bits ≤ w.val) + (hObj : ∃ o ko, σ.kheap o = some ko ∧ o.toNat ≤ w.val ∧ w.val < o.toNat + 2 ^ Fl4Spec.objBits ko) + (hks : w.val + 8 ≤ (L.ksb s).val ∨ (L.ksb s).val + 304384 ≤ w.val) (v : U64) : + JAtZB (L := L) arI AR Z H Cs Ac Lst D (L.wr s w v) a σ := by + have hKn : ∀ c ∈ Cs, w.val + 8 ≤ L.nodeBase s c ∨ L.nodeBase s c + 4288 ≤ w.val := by + intro c hc + have hcl := J.kern.csLt c hc + have hnb : L.nodeBase s c = (L.ksb s).val + 13568 + c.val * 4288 := rfl + omega + have hP := J.xtop.fin.1.2 + have hSS := slotsSame_wr (st := st) hP.pl s v hu.al fun _ hx ⟨h1, h2⟩ => + hu.vobj (vobj_of_slot hP.pl Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.ksb s) hx h1 h2) + exact J.frameWrJCore hu.al hAp hObj hKn (by omega) v hSS (J.xtop.userWr hu hnB v) + open Fl4Proofs.P1 in /-- `JAtZB.frameWrJ` at `JAtZ` (via `JAtZ.toB`). -/ theorem JAtZ.frameWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {w : U64} diff --git a/proofs/Fl4Proofs/P3/XTopJointReply.lean b/proofs/Fl4Proofs/P3/XTopJointReply.lean index dc72602b7..008dea3e5 100644 --- a/proofs/Fl4Proofs/P3/XTopJointReply.lean +++ b/proofs/Fl4Proofs/P3/XTopJointReply.lean @@ -20,6 +20,11 @@ the spec's success tail (`specTail`), from `JAtZ` before to `JAtZ` after. by `running_blk`. * `JAtZ.reply1J`, `jReplyHyp`: the three register writes (when called), then `runJ`; the spec's tail is deterministic (`specTail_restart`). +(mmuAD gen 42b66, option (b) step b2) The register write and `Running` over `JAtZB` with the native footprint +(P3/NatFoot): `JAtZB.regWrJZ` (moved here from P3/JAtZV3RegW, statement unchanged) and `JAtZB.runJDB` (moved here +from P3/JAtZV3HiRun, statement unchanged; the source's 16M kept) carry the proofs; the new **`JAtZB.regWrJ`** / +**`JAtZB.runJ`** add `NatFoot` (`natK_tcbW`: one TCB rewritten in place). `JAtZ.regWrJ` / `JAtZ.runJD` are now their +corollaries (`JAtZB.toJN`; `JAtZB.toJAtZ` with `JExt.ss`), statements unchanged. -/ import Fl4Proofs.P3.XTopJointPortIn import Fl4Proofs.P3.XTopJointSuspend @@ -65,15 +70,26 @@ variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {a variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} +/-- (mmuAD gen 42b66) **One TCB rewritten in place is a native spec step** (`natK_kh`): the state's heap is +`σ`'s with the TCB at `t` replaced by one not newly `runningVM`. -/ +theorem natK_tcbW {σ σ' : Fl4Spec.State Unit} {t : Fl4Spec.ObjRef} {x y : Fl4Spec.Tcb} + (hk : σ.kheap t = some (.tcb x)) (hk' : σ'.kheap = (updK σ t (.tcb y)).kheap) + (hs : y.tcbState = .runningVM → x.tcbState = .runningVM) : NatK σ σ' := + natK_kh (R := fun _ o o' => ZvChg o o') (fun _ _ _ h => h) fun p => by + by_cases e : p = t + · subst e; exact Or.inr ⟨_, _, hk, by rw [hk']; simp [updK], zvChg_tcb hs⟩ + · exact Or.inl (by rw [hk']; simp [updK, e]) + set_option maxHeartbeats 8000000 in -/-- **One register write of a thread at `J`** (module docstring), given -`IRel` after (`reg_wr_irel`, `badge_wr_irel`). -/ -theorem JAtZ.regWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +/-- **One register write of a thread at `JAtZB`** (XTopJointReply's `JAtZ.regWrJ`, generated copy; post at `Z` with +the `FinW` footprint via `JAtZB.reg_frameFZ`). -/ +theorem JAtZB.regWrJZ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (r : Fl4Spec.Register) (v : U64) - (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (regA t (regIdx r)) v) + (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (Endp.regA t (regIdx r)) v) (updK σ t.bv (.tcb (setReg x r v.bv)))) : - ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D (L.wr s (regA t (regIdx r)) v) a - (updK σ t.bv (.tcb (setReg x r v.bv))) := by + P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (Ipc.FinW (st := st) Z.T Z.N Z.C Z.c s σ) ∧ + JAtZB (L := L) arI AR Z H Cs Ac Lst D (L.wr s (Endp.regA t (regIdx r)) v) a + (updK σ t.bv (.tcb (setReg x r v.bv))) := by have hP0 := J.ip have hT : TcbPlaced Z.T := hP0.e.tcb have hta := hT t ht @@ -84,15 +100,15 @@ theorem JAtZ.regWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} have hKv : K.val = 256 + 8 * (regIdx r).val := by show (BitVec.ofNat 64 (256 + 8 * (regIdx r).val)).toNat = _ rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega) - have hra : (regA t (regIdx r)).val = t.val + 256 + 8 * (regIdx r).val := regA_val hta hil + have hra : (Endp.regA t (regIdx r)).val = t.val + 256 + 8 * (regIdx r).val := regA_val hta hil have hKt : (core.num.U64.wrapping_add t K).val = t.val + K.val := tfield_val hta (by rw [hKv]; omega) - have hreq : regA t (regIdx r) = core.num.U64.wrapping_add t K := + have hreq : Endp.regA t (regIdx r) = core.num.U64.wrapping_add t K := UScalar.eq_of_val_eq (by rw [hra, hKt, hKv]; omega) - have hwr : P1.WritesIn st s (L.wr s (regA t (regIdx r)) v) (· = regA t (regIdx r)) := + have hwr : P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (· = Endp.regA t (regIdx r)) := writesIn_wr (a_reg hta r).1 have hblk := (blk_rf J.blk (hwr.mono fun b hb => Or.inl ⟨t, htH, K, by rw [hKv]; omega, by rw [hKv]; omega, by rw [hb, hreq]⟩)).1 - have hfoot : P1.WritesIn st s (L.wr s (regA t (regIdx r)) v) (P1.KW st (P1.Heap.tcbs H) Cs + have hfoot : P1.WritesIn st s (L.wr s (Endp.regA t (regIdx r)) v) (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) ∅ s) := by rw [hreq] exact foot_field hTH htH (by rw [hKv]; omega) (by rw [hKv]; omega) (by rw [hKv]; omega) @@ -102,20 +118,57 @@ theorem JAtZ.regWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} by_cases hp : p = t.bv · subst hp; exact Or.inr (Or.inl ⟨x, setReg x r v.bv, hk, by simp [updK], rfl⟩) · exact Or.inl (by simp [updK, hp]) - exact J.reg_frameF hX2 (hwr.mono fun b hb => Or.inl (Or.inl ⟨t, ht, by rw [hb, hra]; omega, + exact J.reg_frameFZ hX2 (hwr.mono fun b hb => Or.inl (Or.inl ⟨t, ht, by rw [hb, hra]; omega, by rw [hb, hra]; omega⟩)) hA (YK.YKS.updTcb (y := setReg x r v.bv) hk rfl).ykeep (J.inv.updSame (y := setReg x r v.bv) hk rfl rfl (Or.inl rfl)) hblk hfoot +/-- (mmuAD gen 42b66) **One register write of a thread at `JAtZB`, with the native footprint** (`regWrJZ`; the +spec step one TCB's registers, `natK_tcbW`). -/ +theorem JAtZB.regWrJFixed (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (r : Fl4Spec.Register) (v : U64) + (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (regA t (regIdx r)) v) + (updK σ t.bv (.tcb (setReg x r v.bv)))) : + JAtZB (L := L) arI AR Z H Cs Ac Lst D (L.wr s (regA t (regIdx r)) v) a + (updK σ t.bv (.tcb (setReg x r v.bv))) ∧ + NatFoot (L := L) Z s σ (L.wr s (regA t (regIdx r)) v) (updK σ t.bv (.tcb (setReg x r v.bv))) := by + have hS := J.xtop.fin.1.1.1 + obtain ⟨hwF, B'⟩ := J.regWrJZ ht hk r v hX2 + exact ⟨B', NatFoot.ofW J.xtop hwF (fun b hb => Ipc.FinW.oobj hS hb) (fun b hb => Ipc.FinW.nv hS hb) + (fun b hb => J.finW_nh hb) (natK_tcbW hk rfl fun h => h)⟩ + +/-- (mmuAD gen 42b66) **One register write of a thread at `JAtZB`, with the native footprint** (`regWrJZ`; the +spec step one TCB's registers, `natK_tcbW`). -/ +theorem JAtZB.regWrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (r : Fl4Spec.Register) (v : U64) + (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (regA t (regIdx r)) v) + (updK σ t.bv (.tcb (setReg x r v.bv)))) : + ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D (L.wr s (regA t (regIdx r)) v) a + (updK σ t.bv (.tcb (setReg x r v.bv))) ∧ + NatFoot (L := L) Z s σ (L.wr s (regA t (regIdx r)) v) (updK σ t.bv (.tcb (setReg x r v.bv))) := + let ⟨B', F⟩ := J.regWrJFixed ht hk r v hX2 + ⟨Z.vs, B', F⟩ + +/-- **One register write of a thread at `J`** (module docstring), given +`IRel` after (`reg_wr_irel`, `badge_wr_irel`). -/ +theorem JAtZ.regWrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (r : Fl4Spec.Register) (v : U64) + (hX2 : IRel st Z.th σ.archState.x64CurrentCr3 Z.N Z.T Z.C Z.E Z.R Z.B Z.c (L.wr s (regA t (regIdx r)) v) + (updK σ t.bv (.tcb (setReg x r v.bv)))) : + ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D (L.wr s (regA t (regIdx r)) v) a + (updK σ t.bv (.tcb (setReg x r v.bv))) := + match J.toB.regWrJ ht hk r v hX2 with + | ⟨V, B', F⟩ => ⟨V, B'.toJN J F⟩ + set_option maxHeartbeats 16000000 in -/-- **`set_thread_state Running` of a `Restart` thread at `J`, the dead set -kept** (XTopJointReply's `JAtZ.runJ`, same proof; the post names the dead -set `D` and adds the slot and debug-word frames). -/ -theorem JAtZ.runJD (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +/-- **`set_thread_state Running` of a `Restart` thread at `JAtZB`** (XTopJointReply's `JAtZ.runJD` over `JAtZB`, +verbatim as P3/JAtZV3RunVm's `JAtZB.runVmJD`; the post adds the `TFoot` footprint). -/ +theorem JAtZB.runJDB (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .restart) : sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), - JAtZ (L := L) arI AR Z H Cs Ac Lst' D s6 a + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s6 a (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ - SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ⦄ := by + SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ∧ + P1.WritesIn st s s6 (TFoot st Z.T Z.N Z.C Z.c s σ) ⦄ := by have hP0 := J.ip have hI := J.xtop.irelK J.ks J.buf have hS := J.xtop.fin.1.1.1 @@ -304,7 +357,32 @@ theorem JAtZ.runJD (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} ( by_cases e : p = t.bv · rw [e, hk6] at hp; cases hp · rw [hkp _ e] at hp; exact ⟨y, hp, ha, fun _ h => h, id⟩) hcr6 hblk hKd (J.idleW_keep hX'.fin.1.1.1 hfk.2.1 hfk.2.2).1 J.zD, - J.xtop.slotsSame_of hW (fun b hb => tfoot_oobj hS hb), P1.Foot.dbgKeep J.blk (fun _ h => h) hfoot⟩ + J.xtop.slotsSame_of hW (fun b hb => tfoot_oobj hS hb), P1.Foot.dbgKeep J.blk (fun _ h => h) hfoot, hW⟩ + +/-- (mmuAD gen 42b66) **`set_thread_state Running` of a `Restart` thread at `JAtZB`, with the native footprint** +(`runJDB`; the spec step one TCB's state, `natK_tcbW`). -/ +theorem JAtZB.runJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .restart) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s6 a + (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ + NatFoot (L := L) Z s σ s6 (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := + WP.spec_mono (J.runJDB ht hk hrs) fun _ ⟨Lst', B', _, _, hW⟩ => + ⟨Lst', B', NatFoot.ofT J.xtop hW (fun _ h => J.tfoot_nh h) + (natK_tcbW (y := { x with tcbState := .running }) hk (by rw [stsAct_kheap]) fun h => by cases h)⟩ + +set_option maxHeartbeats 16000000 in +/-- **`set_thread_state Running` of a `Restart` thread at `J`, the dead set +kept** (XTopJointReply's `JAtZ.runJ`, same proof; the post names the dead +set `D` and adds the slot and debug-word frames). -/ +theorem JAtZ.runJD (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrs : x.tcbState = .restart) : + sched.set_thread_state st s t sched.TS_RUNNING ⦃ s6 => ∃ (Lst' : U64 → List U64), + JAtZ (L := L) arI AR Z H Cs Ac Lst' D s6 a + (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ∧ + SlotsSame Z.th (L.mem s) (L.mem s6) ∧ P1.DbgKeep st (P1.Heap.tcbs H) Cs s s6 ⦄ := + WP.spec_mono (J.toB.runJDB ht hk hrs) fun _ ⟨Lst', B', hss, hdk, hW⟩ => + ⟨Lst', B'.toJAtZ (J.ext.ss hss (J.toB.tfoot_vkeep hW)), hss, hdk⟩ /-- **`set_thread_state Running` of a `Restart` thread at `J`** (module docstring; `runJD` with the dead set hidden). -/ @@ -315,22 +393,19 @@ theorem JAtZ.runJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (h (stsAct (updK σ t.bv (.tcb { x with tcbState := .running })) t.bv) ⦄ := WP.spec_mono (J.runJD ht hk hrs) fun _ ⟨Lst', J', _⟩ => ⟨Lst', D, J'⟩ -set_option maxHeartbeats 16000000 in -/-- **`reply1` at `J`** (module docstring): every outcome of the spec's -success tail has `JAt`. -/ -theorem JAtZ.reply1J (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {ct : U64} (hct : ct ∈ Z.T) - {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .restart) (call : Bool) (v : U64) : - vspace.reply1 st s ct call v ⦃ s2 => ∀ z ∈ (specTail call ct.bv [v.bv] σ).1, JAt (L := L) arI AR s2 a z.2 ⦄ := by +set_option maxHeartbeats 4000000 in +/-- The register writes preceding the final Running state in `reply1`. -/ +theorem JAtZB.reply1Prep (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (call : Bool) (v : U64) {Q : S → Prop} + (hK : ∀ s1, JAtZB (L := L) arI AR Z H Cs Ac Lst D s1 a + (if call then updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ) → + NatFoot (L := L) Z s σ s1 (if call then updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ) → + sched.set_thread_state st s1 ct sched.TS_RUNNING ⦃ Q ⦄) : + vspace.reply1 st s ct call v ⦃ Q ⦄ := by unfold vspace.reply1 cases call · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] - refine WP.spec_mono (J.runJ hct hk hrs) ?_ - rintro s2 ⟨Lst', D', J2⟩ z hz - rw [specTail_restart hk hrs false v.bv] at hz - simp only [Bool.false_eq_true, ↓reduceIte] at hz - rw [Notif.setThreadState_eq .running hk] at hz - rw [Set.mem_singleton_iff.1 hz] - exact ⟨_, _, _, _, _, _, J2, inferInstance⟩ + exact hK s J (NatFoot.refl Z s σ) · simp only [↓reduceIte] have hin : (do let buf ← msg.lookup_ipc_buffer st s true ct @@ -370,30 +445,72 @@ theorem JAtZ.reply1J (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] { -- the badge register have hXb := badge_wr_irel J.ip (J.xtop.irelK J.ks J.buf) hct hk 0#u64 rw [badgeRegA_eq_regA] at hXb - obtain ⟨V1, J1⟩ := J.regWrJ hct hk Fl4Spec.badge_register 0#u64 hXb + obtain ⟨J1, F1⟩ := J.regWrJFixed hct hk Fl4Spec.badge_register 0#u64 hXb set x1 := setReg x Fl4Spec.badge_register (0#u64 : U64).bv with hx1 have hk1 : (updK σ ct.bv (.tcb x1)).kheap ct.bv = some (.tcb x1) := by simp [updK] -- the message register have hX2 := reg_wr_irel J1.ip (J1.xtop.irelK J1.ks J1.buf) hct hk1 (Endp.mrIdx 0) (by decide) v - obtain ⟨V2, J2⟩ := J1.regWrJ hct hk1 (Endp.mrIdx 0) v hX2 + obtain ⟨J2, F2⟩ := J1.regWrJFixed hct hk1 (Endp.mrIdx 0) v hX2 set x2 := setReg x1 (Endp.mrIdx 0) v.bv with hx2 have hk2 : (updK (updK σ ct.bv (.tcb x1)) ct.bv (.tcb x2)).kheap ct.bv = some (.tcb x2) := by simp [updK] -- the message info have hX3 := reg_wr_irel J2.ip (J2.xtop.irelK J2.ks J2.buf) hct hk2 Fl4Spec.msg_info_register (by decide) w - obtain ⟨V3, J3⟩ := J2.regWrJ hct hk2 Fl4Spec.msg_info_register w hX3 + obtain ⟨J3, F3⟩ := J2.regWrJFixed hct hk2 Fl4Spec.msg_info_register w hX3 have hxC : setReg x2 Fl4Spec.msg_info_register w.bv = Endp.replyTcb x v.bv := by rw [hw]; rfl - rw [updK_updK, updK_updK, hxC] at J3 - have hkC : (updK σ ct.bv (.tcb (Endp.replyTcb x v.bv))).kheap ct.bv = some (.tcb (Endp.replyTcb x v.bv)) := by - simp [updK] - -- `Running` - refine WP.spec_mono (J3.runJ hct hkC hrs) ?_ - rintro s4 ⟨Lst', D', J4⟩ z hz - rw [specTail_restart hk hrs true v.bv] at hz - simp only [↓reduceIte] at hz - rw [Notif.setThreadState_eq .running hkC] at hz - rw [Set.mem_singleton_iff.1 hz] - exact ⟨_, _, _, _, _, _, J4, inferInstance⟩ + have F := J.natTrans F1 (J1.natTrans F2 F3) + rw [updK_updK, updK_updK, hxC] at J3 F + exact hK _ J3 F + +/-- The concrete TCB state word excludes Restart when its abstract state does. -/ +theorem JAtZB.notRestart (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState ≠ .restart) : + L.mem s (stA ct) ≠ sched.TS_RESTART := by + obtain ⟨x0, hk0, hTR⟩ := (J.xtop.irelK J.ks J.buf).1.tcb ct hct + rw [hk] at hk0 + cases hk0 + have hst : (L.mem s (tStA ct)).val = tsCode x.tcbState := hTR.st + have hss : (L.mem s (stA ct)).val = tsCode x.tcbState := by rw [stA_eq, ← tStA_eq, hst] + intro h + apply hrs + apply tsCode_two + rw [← hss] + show (L.mem s (stA ct)).val = 2 + rw [h] + unfold sched.TS_RESTART + rfl + +/-- `reply1` from Restart, with the VM-preserving footprint. -/ +theorem JAtZB.reply1JFoot (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} + (hct : ct ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) + (hrs : x.tcbState = .restart) (call : Bool) (v : U64) : + vspace.reply1 st s ct call v ⦃ s2 => L.mem s2 (stA ct) ≠ sched.TS_RESTART ∧ + ∃ σ2 Lst', specTail call ct.bv [v.bv] σ = ({((), σ2)}, False) ∧ + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s2 a σ2 ∧ NatFoot (L := L) Z s σ s2 σ2 ⦄ := by + refine J.reply1Prep hct hk call v ?_ + intro s1 J1 F1 + let σ1 := if call then updK σ ct.bv (.tcb (Endp.replyTcb x v.bv)) else σ + let y := if call then Endp.replyTcb x v.bv else x + have hk1 : σ1.kheap ct.bv = some (.tcb y) := by + cases call <;> simp [σ1, y, updK, hk] + have hr1 : y.tcbState = .restart := by cases call <;> exact hrs + refine WP.spec_mono (J1.runJ hct hk1 hr1) ?_ + rintro s2 ⟨Lst', J2, F2⟩ + have hk2 : (stsAct (updK σ1 ct.bv (.tcb { y with tcbState := .running })) ct.bv).kheap ct.bv = + some (.tcb { y with tcbState := .running }) := by simp only [stsAct_kheap, updK_kheap, Function.update_self] + refine ⟨J2.notRestart hct hk2 (by intro h; cases h), _, Lst', ?_, J2, J.natTrans F1 F2⟩ + rw [specTail_restart hk hrs call v.bv, Notif.setThreadState_eq .running hk1] + +set_option maxHeartbeats 16000000 in +/-- **`reply1` at `J`** (module docstring): every outcome of the spec's +success tail has `JAt`. -/ +theorem JAtZ.reply1J (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {ct : U64} (hct : ct ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap ct.bv = some (.tcb x)) (hrs : x.tcbState = .restart) (call : Bool) (v : U64) : + vspace.reply1 st s ct call v ⦃ s2 => ∀ z ∈ (specTail call ct.bv [v.bv] σ).1, JAt (L := L) arI AR s2 a z.2 ⦄ := + WP.spec_mono (J.toB.reply1JFoot hct hk hrs call v) fun _ ⟨_, σ2, Lst', hz, J', F⟩ z hz' => by + rw [hz] at hz' + rw [Set.mem_singleton_iff.mp hz'] + exact ⟨Z, H, Cs, Ac, Lst', D, J'.toJN J F, inferInstance⟩ end diff --git a/proofs/Fl4Proofs/P3/XTopJointReplyTail.lean b/proofs/Fl4Proofs/P3/XTopJointReplyTail.lean index 9b82171e2..8019e5226 100644 --- a/proofs/Fl4Proofs/P3/XTopJointReplyTail.lean +++ b/proofs/Fl4Proofs/P3/XTopJointReplyTail.lean @@ -19,6 +19,12 @@ XTopJointEntry's `handle_invocation_refinesJ`, replacing HandleTopX's itself (BufJ's `JAtZ.xferH`). * `JAtZ.replyFailJ`: the error reply when called (`ReplyHypMX.fail`'s program), at `JAt`. + +(mmuAD gen 42b66, option (b) step b2) `flTailJ`, `replyErrJ`, `replyFailJ` stated over `JAtZB` in place (sources' +heartbeat options kept), their posts `∃ V …, JAtZB (Z.mv Z.G V) …` with the native footprint `NatFoot Z s σ` +(P3/NatFoot: composed by `JAtZB.natTrans` from XTopJointReply's `JAtZB.regWrJ` / `JAtZB.runJ` and XTopJointData's +`JAtZB.setmrJ` / `JAtZB.replyTailJ` / `JAtZB.userWrN`), toward the VM-side `handle_invocation` (`VmEptState.ofNat`). +The `JAtZ` names are one-line corollaries (`JAtZ.toB`, `JAtZB.toJN`), statements unchanged. No named premise. -/ import Fl4Proofs.P3.XTopJointData import Fl4Proofs.P3.BufJ @@ -205,10 +211,12 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **FL4's success tail for an empty result at `J`** (module docstring). -/ -theorem JAtZ.flTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {ct : U64} (hcur : σ.curThread = ct.bv) +theorem JAtZB.flTailJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hcur : σ.curThread = ct.bv) (call : Bool) : flTail (st := st) ct call s a ⦃ res => res.1 = .Ok () ∧ - ∃ z ∈ (specTail call ct.bv [] σ).1, RelTopM (L := L) res.2.1 z.2 ∧ JAt (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := by + ∃ z ∈ (specTail call ct.bv [] σ).1, RelTopM (L := L) res.2.1 z.2 ∧ ∃ (V : XVs) (Lst' : U64 → List U64), + JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst' D res.2.1 res.2.2 z.2 ∧ + NatFoot (L := L) Z s σ res.2.1 z.2 ⦄ := by have hct : ct ∈ Z.T := TopSR.cur_mem J.xtop.fin.1 hcur.symm obtain ⟨htcb, x, hk⟩ := J.xtop.curTcb hcur have hI := J.xtop.irelK J.ks J.buf @@ -230,12 +238,12 @@ theorem JAtZ.flTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] { cases call · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok] refine WP.spec_bind (J.runJ hct hk hrs) ?_ - rintro s2 ⟨Lst', D', J2⟩ + rintro s2 ⟨Lst', J2, F2⟩ refine (WP.spec_ok _).2 ⟨rfl, ((), stsAct (updK σ ct.bv (.tcb { x with tcbState := .running })) ct.bv), ?_, - J2.xtop.relTop, _, _, _, _, _, _, J2, inferInstance⟩ + J2.xtop.relTop, Z.vs, Lst', J2, F2⟩ rw [Notif.setThreadState_eq .running hk]; exact Set.mem_singleton _ · simp only [↓reduceIte] - have J0 : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ ct.bv x (Endp.ipcBufOf true x) []) := by + have J0 : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a (MrS σ ct.bv x (Endp.ipcBufOf true x) []) := by rw [MrS_nil hk]; exact J have hR := J0.replyTailJ hct hk hrs (by simp) (fun p _ z hz => by simp [Endp.mrPairs] at hz) 0#u64 (by cases Endp.ipcBufOf true x <;> rfl) (by decide) @@ -252,9 +260,9 @@ theorem JAtZ.flTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] { rw [specTail_nil hk true, if_pos hrs] simp only [↓reduceIte] rw [Notif.setThreadState_eq .running hkN]; exact Set.mem_singleton _ - have hJ := h5 _ hz - obtain ⟨Z5, H5, Cs5, Ac5, Lst5, D5, J5, _⟩ := hJ - refine (WP.spec_ok _).2 ⟨rfl, _, ?_, J5.xtop.relTop, Z5, H5, Cs5, Ac5, Lst5, D5, J5, inferInstance⟩ + obtain ⟨V5, Lst5, J5, F5⟩ := h5 _ hz + rw [MrS_nil hk] at F5 + refine (WP.spec_ok _).2 ⟨rfl, _, ?_, J5.xtop.relTop, V5, Lst5, J5, F5⟩ rw [Notif.setThreadState_eq .running hkN]; exact Set.mem_singleton _ · rw [if_neg hr] have hrs : x.tcbState ≠ .restart := by @@ -263,17 +271,26 @@ theorem JAtZ.flTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] { apply UScalar.eq_of_val_eq show (L.mem s (P1.stA ct)).val = _ rw [hss, h]; unfold sched.TS_RESTART; rfl - refine (WP.spec_ok _).2 ⟨rfl, ((), σ), ?_, J.xtop.relTop, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + refine (WP.spec_ok _).2 ⟨rfl, ((), σ), ?_, J.xtop.relTop, Z.vs, Lst, J, NatFoot.refl _ _ _⟩ rw [specTail_nil hk call, if_neg hrs]; exact Set.mem_singleton _ +/-- `JAtZB.flTailJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.flTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] {ct : U64} (hcur : σ.curThread = ct.bv) + (call : Bool) : + flTail (st := st) ct call s a ⦃ res => res.1 = .Ok () ∧ + ∃ z ∈ (specTail call ct.bv [] σ).1, RelTopM (L := L) res.2.1 z.2 ∧ JAt (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + WP.spec_mono (J.toB.flTailJ hcur call) fun _ ⟨h1, z, hz, hRT, _, _, B', F⟩ => + ⟨h1, z, hz, hRT, _, _, _, _, _, _, B'.toJN J F, inferInstance⟩ + set_option maxHeartbeats 64000000 in /-- **FL4's `reply_error` at `J`** (module docstring). -/ -theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.replyErrJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hcur : σ.curThread = ct.bv) (e : error.SysError) (e' : Fl4Spec.SyscallError) (he : ErrRel (.Sys e) e') : syscall.reply_error st s ct e ⦃ s2 => ∃ z ∈ (Fl4Spec.fl4ReplyFromKernelError (Z := Unit) true ct.bv (Fl4Spec.msgFromSyscallError e') σ).1, - RelTopM (L := L) s2 z.2 ∧ JAt (L := L) arI AR s2 a z.2 ⦄ := by + RelTopM (L := L) s2 z.2 ∧ ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s2 a z.2 ∧ + NatFoot (L := L) Z s σ s2 z.2 ⦄ := by have hct : ct ∈ Z.T := TopSR.cur_mem J.xtop.fin.1 hcur.symm obtain ⟨htcb, x, hk⟩ := J.xtop.curTcb hcur obtain ⟨x', hk', hwx⟩ := J.buf ct hct @@ -316,22 +333,24 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] let i ← error.SysError.code e let mi ← msginfo.MessageInfo.new i 0#u64 0#u64 len1 msg.set_msg_info st s3 ct mi) ⦃ s2 => - JAt (L := L) arI AR s2 a (replyErrState σ ct.bv x (Fl4Spec.msgFromSyscallError e').1 + ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s2 a (replyErrState σ ct.bv x + (Fl4Spec.msgFromSyscallError e').1 (Fl4Spec.msgFromSyscallError e').2) ∧ + NatFoot (L := L) Z s σ s2 (replyErrState σ ct.bv x (Fl4Spec.msgFromSyscallError e').1 (Fl4Spec.msgFromSyscallError e').2) ⦄ by refine WP.spec_mono hsuf ?_ - rintro s2 ⟨Z2, H2, Cs2, Ac2, Lst2, D2, J2, _⟩ + rintro s2 ⟨V2, J2, F2⟩ refine ⟨((), replyErrState σ ct.bv x (Fl4Spec.msgFromSyscallError e').1 (Fl4Spec.msgFromSyscallError e').2), - ?_, J2.xtop.relTop, Z2, H2, Cs2, Ac2, Lst2, D2, J2, inferInstance⟩ + ?_, J2.xtop.relTop, V2, J2, F2⟩ rw [hspec]; exact Set.mem_singleton _ refine WP.spec_bind (Endp.obj.Tcb.set_reg.spec s ct layout.reg.BADGE 0#u64) ?_ rintro s1 rfl -- the badge have hXb := badge_wr_irel J.ip (J.xtop.irelK J.ks J.buf) hct hk 0#u64 rw [badgeRegA_eq_regA] at hXb - obtain ⟨V1, J1⟩ := J.regWrJ hct hk Fl4Spec.badge_register 0#u64 hXb - rw [Endp.regIdx_badge] at J1 + obtain ⟨V1, J1, F1⟩ := J.regWrJ hct hk Fl4Spec.badge_register 0#u64 hXb + rw [Endp.regIdx_badge] at J1 F1 have e0 : U64.bv 0#u64 = (0 : Fl4Spec.Word) := rfl - rw [e0] at J1 + rw [e0] at J1 F1 set xA := Notif.setReg x Fl4Spec.badge_register 0 with hxA set σA := Notif.updK σ ct.bv (.tcb xA) with hσA have hkA : σA.kheap ct.bv = some (.tcb xA) := by simp [σA, Notif.updK] @@ -345,27 +364,28 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] have hOK1 := J1.xferH.1 have hWOK : ∀ q, Endp.ipcBufOf true x = some q → ∀ i : U64, i.val < 128 → BufWordOK H σA (fl4BufA w i) := fun q hq i hi => - J1.bufWord hOK1 htcb hkA hq i.val hi (by rw [fl4BufA_bv, hwp hwx q hq]) + J1.bufWordG hOK1 htcb hkA hq i.val hi (by rw [fl4BufA_bv, hwp hwx q hq]) set buf := Endp.ipcBufOf true x with hbuf -- the words let I : S → List Fl4Spec.Word → Prop := fun s' ms => L.ksb s' = L.ksb s ∧ - ∃ V, JAtZ (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s' a (MrS σA ct.bv xA buf ms) - have hI0 : I s1 [] := ⟨hks1, V1, by rw [MrS_nil hkA]; exact J1⟩ + ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D s' a (MrS σA ct.bv xA buf ms) ∧ + NatFoot (L := L) Z s σ s' (MrS σA ct.bv xA buf ms) + have hI0 : I s1 [] := ⟨hks1, V1, by rw [MrS_nil hkA]; exact ⟨J1, F1⟩⟩ have step : ∀ (s' : S) (ms1 : List Fl4Spec.Word), I s' ms1 → ∀ (i : U64), i.val = ms1.length → ms1.length < 120 → ∀ v : U64, msg.set_mr st s' ct w i v ⦃ r => r.1.val = mrLen buf (ms1.length + 1) ∧ I r.2 (ms1 ++ [v.bv]) ⦄ := by - rintro s' ms1 ⟨hk', V, J'⟩ i hi hi' v + rintro s' ms1 ⟨hk', V, J', F'⟩ i hi hi' v refine WP.spec_mono (J'.setmrJ hct hkA w hw0 hbm (hBPA s' hk') hWOK i hi hi' v) ?_ - rintro r ⟨h1, h2, V', J''⟩ - exact ⟨h1, h2.trans hk', V', J''⟩ + rintro r ⟨h1, h2, V', J'', F''⟩ + exact ⟨h1, h2.trans hk', V', J'', J.natTrans F' F''.cast⟩ refine WP.spec_bind (error_mrs_gen ct buf w I step s1 hI0 e e' he) ?_ - rintro ⟨len, s3⟩ ⟨hlen, hk3, V3, J3⟩ - simp only at hlen hk3 J3 + rintro ⟨len, s3⟩ ⟨hlen, hk3, V3, J3, F3⟩ + simp only at hlen hk3 J3 F3 have hkM := MrS_kheap_t σA ct.bv xA buf (Fl4Spec.msgFromSyscallError e').2 cases hb : Endp.ipcBufOf true x with | none => have hbn : buf = none := hb - rw [hbn] at J3 hlen hkM + rw [hbn] at J3 F3 hlen hkM have hw : w = 0#u64 := hw0.2 hb simp only [hflag, hw, bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, bind_ok] refine WP.spec_bind (code_label he) ?_ @@ -377,17 +397,17 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] rintro s4 ⟨v, rfl, hv⟩ rw [← Endp.regIdx_msgInfo] have hX4 := reg_wr_irel J3.ip (J3.xtop.irelK J3.ks J3.buf) hct hkM Fl4Spec.msg_info_register (by decide) v - obtain ⟨V4, J4⟩ := J3.regWrJ hct hkM Fl4Spec.msg_info_register v hX4 + obtain ⟨V4, J4, F4⟩ := J3.regWrJ hct hkM Fl4Spec.msg_info_register v hX4 have hvd : v.bv = Fl4Spec.messageInfoToData ⟨Fl4Spec.natToLen (mrLen none (Fl4Spec.msgFromSyscallError e').2.length), 0, 0, (Fl4Spec.msgFromSyscallError e').1⟩ := by rw [hv, hcd]; congr 2 apply BitVec.eq_of_toNat_eq; simp only [Fl4Spec.natToLen, BitVec.toNat_ofNat, UScalar.bv_toNat, hlen, mrLen]; omega unfold replyErrState simp only [hb] - rw [← hvd]; exact ⟨_, _, _, _, _, _, J4, inferInstance⟩ + rw [← hvd]; exact ⟨V4, J4, J.natTrans F3 F4.cast⟩ | some p => have hbs : buf = some p := hb - rw [hbs] at J3 hlen hkM + rw [hbs] at J3 F3 hlen hkM have hw : w ≠ 0#u64 := fun h => by rw [hbs] at hw0; cases hw0.1 h have hbw : (w != 0#u64) = true := by simp [hw] simp only [hflag, hbw, ↓reduceIte, hdm, bind_ok] @@ -423,7 +443,8 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] · exact ⟨o, ko, by rw [hσM, MrS_kheap_ne _ _ _ _ _ e]; exact hko, g1, g2⟩ have hBP3 : Vs.BufPlaced (L := L) Z.N Z.C Z.B Z.c s3 σM := (hBPA s3 hk3).mono rfl (MrS_sc hkA _ _) have J4 := J3.userWrJ hBP3 hpair hAp hObj (L.mem s3 (Endp.fl4BufA w 7#u64) &&& ~~~255#u64) - simp only [hval] at J4 + have F4 := J3.userWrN hBP3 hpair hAp (L.mem s3 (Endp.fl4BufA w 7#u64) &&& ~~~255#u64) + simp only [hval] at J4 F4 refine WP.spec_bind (code_label he) ?_ rintro cd hcd unfold msginfo.MessageInfo.new @@ -438,7 +459,7 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] some (.tcb (Endp.withRegs xA (Endp.mrRegs xA.tcbArch.tcbContext.userRegs (Fl4Spec.msgFromSyscallError e').2))) := hkM have hX5 := reg_wr_irel J4.ip (J4.xtop.irelK J4.ks J4.buf) hct hkD Fl4Spec.msg_info_register (by decide) v - obtain ⟨V5, J5⟩ := J4.regWrJ hct hkD Fl4Spec.msg_info_register v hX5 + obtain ⟨V5, J5, F5⟩ := J4.regWrJ hct hkD Fl4Spec.msg_info_register v hX5 have hvd : v.bv = Fl4Spec.messageInfoToData ⟨Fl4Spec.natToLen (mrLen (some p) (Fl4Spec.msgFromSyscallError e').2.length) + 1, 0, 0, (Fl4Spec.msgFromSyscallError e').1⟩ := by rw [hv, hcd]; congr 2 @@ -446,12 +467,22 @@ theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] simp [Fl4Spec.natToLen, core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits, hlen, mrLen] unfold replyErrState simp only [hb] - rw [← hvd]; exact ⟨_, _, _, _, _, _, J5, inferInstance⟩ + rw [← hvd]; exact ⟨V5, J5, J.natTrans (J.natTrans F3 F4.cast) F5.cast⟩ + +/-- `JAtZB.replyErrJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.replyErrJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + {ct : U64} (hcur : σ.curThread = ct.bv) (e : error.SysError) (e' : Fl4Spec.SyscallError) + (he : ErrRel (.Sys e) e') : + syscall.reply_error st s ct e ⦃ s2 => + ∃ z ∈ (Fl4Spec.fl4ReplyFromKernelError (Z := Unit) true ct.bv (Fl4Spec.msgFromSyscallError e') σ).1, + RelTopM (L := L) s2 z.2 ∧ JAt (L := L) arI AR s2 a z.2 ⦄ := + WP.spec_mono (J.toB.replyErrJ hcur e e' he) fun _ ⟨z, hz, hRT, _, B', F⟩ => + ⟨z, hz, hRT, _, _, _, _, _, _, B'.toJN J F, inferInstance⟩ set_option maxHeartbeats 4000000 in /-- **The error reply at `J`** (`ReplyHypMX.fail`'s program, module docstring). -/ -theorem JAtZ.replyFailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] +theorem JAtZB.replyFailJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {ct : U64} (hcur : σ.curThread = ct.bv) (is_call : Bool) (e : error.SysError) (e' : Fl4Spec.SyscallError) (he : ErrRel (.Sys e) e') : ((if is_call then do @@ -461,10 +492,11 @@ theorem JAtZ.replyFailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ res => res.1 = .Ok () ∧ ∃ z ∈ ((Fl4Spec.NonDet.when is_call <| Fl4Spec.fl4ReplyFromKernelError true ct.bv (Fl4Spec.msgFromSyscallError e')) σ).1, - RelTopM (L := L) res.2.1 z.2 ∧ JAt (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := by + RelTopM (L := L) res.2.1 z.2 ∧ ∃ V, JAtZB (L := L) arI AR (Z.mv Z.G V) H Cs Ac Lst D res.2.1 res.2.2 z.2 ∧ + NatFoot (L := L) Z s σ res.2.1 z.2 ⦄ := by cases is_call · simp only [Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - refine ⟨trivial, ((), σ), ?_, J.xtop.relTop, Z, H, Cs, Ac, Lst, D, J, inferInstance⟩ + refine ⟨trivial, ((), σ), ?_, J.xtop.relTop, Z.vs, J, NatFoot.refl _ _ _⟩ rw [Endp.nd_when_false (by simp)]; exact Set.mem_singleton _ simp only [↓reduceIte] refine WP.spec_bind (J.replyErrJ hcur e e' he) ?_ @@ -474,6 +506,21 @@ theorem JAtZ.replyFailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z simp only [↓reduceIte] exact hz +/-- `JAtZB.replyFailJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.replyFailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) [VxE Z] + {ct : U64} (hcur : σ.curThread = ct.bv) (is_call : Bool) (e : error.SysError) (e' : Fl4Spec.SyscallError) + (he : ErrRel (.Sys e) e') : + ((if is_call then do + let s2 ← syscall.reply_error st s ct e + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s2, a) + else ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s, a)) : + Result ((core.result.Result Unit error.Exc) × S × A)) ⦃ res => + res.1 = .Ok () ∧ ∃ z ∈ ((Fl4Spec.NonDet.when is_call <| + Fl4Spec.fl4ReplyFromKernelError true ct.bv (Fl4Spec.msgFromSyscallError e')) σ).1, + RelTopM (L := L) res.2.1 z.2 ∧ JAt (L := L) arI AR res.2.1 res.2.2 z.2 ⦄ := + WP.spec_mono (J.toB.replyFailJ hcur is_call e e' he) fun _ ⟨h1, z, hz, hRT, _, B', F⟩ => + ⟨h1, z, hz, hRT, _, _, _, _, _, _, B'.toJN J F, inferInstance⟩ + end end diff --git a/proofs/Fl4Proofs/P3/XTopJointRest.lean b/proofs/Fl4Proofs/P3/XTopJointRest.lean index 8b914dec7..f1892a665 100644 --- a/proofs/Fl4Proofs/P3/XTopJointRest.lean +++ b/proofs/Fl4Proofs/P3/XTopJointRest.lean @@ -132,19 +132,16 @@ end Spec section variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} (arI : machine.Arch A) +variable {arI} in set_option maxHeartbeats 8000000 in -/-- **`JStepHyps.restart` at a fixed dead set** (module docstring): with no -premise, the dead set kept (every dead object stays dead); P1's `BlkOK` -after by `set_thread_state.restart_ok` (the current thread runnable, so -neither blocked nor waiting for a reply), the node-0 `DEBUG_TCBS` word kept -(`set_thread_state` writes the TCB's state word and the scheduler-action -word only, `JKern.dwNe`). -/ -theorem jowes_restartD {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +/-- **`JStepHyps.restart` at a fixed dead set, over `JAtZB`** (`jowes_restartD`'s proof, mmuAD gen 42b70: moved here from +P3/JAtZV3HiRun, where it was a verbatim copy; `jowes_restartD` is now its corollary). -/ +theorem JAtZB.restartRest {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) (ct : U64) (x : Fl4Spec.Tcb) (s1 : S) (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) (htcb : Z.th ct = some .tcb) (hrun : Fl4Spec.runnable x.tcbState = true) (hs1 : sched.set_thread_state st s ct sched.TS_RESTART = ok s1) - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) (hX1 : XTopAt (L := L) AR Z s1 a (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv)) : ∃ Lst' : U64 → List U64, JRest (L := L) arI Z H Cs Ac Lst' D s1 (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) := by @@ -227,6 +224,23 @@ theorem jowes_restartD {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Hea J.sc_utc hwT hK hDbg, hNsc, hI1, hcur', curOwnW_updTcb J.own hk _, OffOK.restart J.off _, hAI, hB', J.isorted.tkw hK, Or.inr (Or.inl hCR''), hBlk'⟩⟩ +/-- **`JStepHyps.restart` at a fixed dead set** (module docstring; mmuAD gen 42b70: `JAtZB.restartRest` at `J.toB`): with no +premise, the dead set kept (every dead object stays dead); P1's `BlkOK` +after by `set_thread_state.restart_ok` (the current thread runnable, so +neither blocked nor waiting for a reply), the node-0 `DEBUG_TCBS` word kept +(`set_thread_state` writes the TCB's state word and the scheduler-action +word only, `JKern.dwNe`). -/ +theorem jowes_restartD {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} (s : S) (a : A) (σ : Fl4Spec.State Unit) + (ct : U64) (x : Fl4Spec.Tcb) (s1 : S) (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) + (htcb : Z.th ct = some .tcb) (hrun : Fl4Spec.runnable x.tcbState = true) + (hs1 : sched.set_thread_state st s ct sched.TS_RESTART = ok s1) + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + (hX1 : XTopAt (L := L) AR Z s1 a (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv)) : + ∃ Lst' : U64 → List U64, JRest (L := L) arI Z H Cs Ac Lst' D s1 + (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) := + JAtZB.restartRest s a σ ct x s1 hcur hk htcb hrun hs1 J.toB hX1 + /-- **`JStepHyps.restart`** (`jowes_restartD`, at the same dead set). -/ theorem jowes_restart {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s : S) (a : A) (σ : Fl4Spec.State Unit) (ct : U64) (x : Fl4Spec.Tcb) (s1 : S) (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) @@ -239,6 +253,54 @@ theorem jowes_restart {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s : S) obtain ⟨Lst', R⟩ := jowes_restartD arI s a σ ct x s1 hcur hk htcb hrun hs1 J hX1 exact ⟨Ac, Lst', D, R⟩ +variable {arI} in +set_option maxHeartbeats 4000000 in +/-- **The caller's restart at `JAtZB`** (P3/XTopJointStep's `JAtZ.restartSJ` over `JAtZB`: `jStepHyps`'s `restart` +field is `jowes_restartD`, here `JAtZB.restartRest`; mmuAD gen 42b70: moved here from P3/JAtZV3HiRun; `JAtZB.cs_frame` (no `VKeep` argument), `JCs.sameB`; the post +adds the `TFoot` footprint, as `jowes_restartD` derives it; source setting `maxHeartbeats 4000000`). -/ +theorem JAtZB.restartJB {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) + {ct : U64} {x : Fl4Spec.Tcb} {s1 : S} (hcur : σ.curThread = ct.bv) (hk : σ.kheap ct.bv = some (.tcb x)) + (htcb : Z.th ct = some .tcb) (hrun : Fl4Spec.runnable x.tcbState = true) + (hs1 : sched.set_thread_state st s ct sched.TS_RESTART = ok s1) : + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s1 a + (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv) ∧ + P1.WritesIn st s s1 (TFoot st Z.T Z.N Z.C Z.c s σ) := by + have h := XTopAt.restart J.xtop hcur hk hrun + rw [hs1, WP.spec_ok] at h + obtain ⟨hX1, hSS, hk1⟩ := h + obtain ⟨hkb, hkz⟩ := kback_ksz_upd (σ' := Notif.stsAct (Notif.updK σ ct.bv + (.tcb { x with tcbState := .restart })) ct.bv) hk (by rw [stsAct_kheap]; rfl) + obtain ⟨Lst', R⟩ := J.restartRest s a σ ct x s1 hcur hk htcb hrun hs1 hX1 + have hT : ct ∈ Z.T := J.thT ct htcb + have hK : P1.DbgKeep st (P1.Heap.tcbs H) Cs s s1 := by + obtain ⟨x', hk', hRt⟩ := J.xtop.ipc.tcb ct hT + rw [hk] at hk'; cases hk' + have hnbr : ¬ P1.BlockedR (L.mem s (P1.stA ct)) := fun hb => by + have hq := Sched.blockedR_queued hRt.st hb + cases hx : x.tcbState <;> simp_all [Fl4Spec.runnable, Fl4Spec.ipcQueuedThreadState] + have hT' : ct ∈ P1.Heap.tcbs H := by rw [← J.tcbs_eq.1]; exact hT + exact P1.Foot.dbgKeep J.blk (Set.empty_subset _) + (P1.sched.set_thread_state.restart_ok (Es := ∅) J.blk hT' (fun h => hnbr (Or.inl h)) + (fun h => hnbr (Or.inr h)) hs1).2.1 + have hid : (Notif.stsAct (Notif.updK σ ct.bv (.tcb { x with tcbState := .restart })) ct.bv).idleThread = + σ.idleThread := by unfold Notif.stsAct; split <;> rfl + have hwT : P1.WritesIn st s s1 (TFoot st Z.T Z.N Z.C Z.c s σ) := by + have h := set_thread_state_sfoot (L := L) J.xtop.fin.1.1.1 hT sched.TS_RESTART + rw [hs1, WP.spec_ok] at h + exact WritesIn.tfoot_of_kfoot (h.mono fun b hb => KFoot.of_sfoot hb) + refine ⟨Lst', ?_, hwT⟩ + exact J.cs_frame (G' := Z.G) (hvn := J.vsSS (G' := Z.G) hX1 hk1 hSS + (Vs.ArchShr.of_keep (Vs.sts_keep hk { x with tcbState := .restart }).1 (Vs.sts_keep hk _).2)) hk1 hX1 hkb + ((IpcFrKeep.of_updTcb (y := { x with tcbState := .restart }) hk rfl rfl).trans + (IpcFrKeep.of_kheap (by rw [stsAct_kheap]))) (J.carry.frame subset_rfl ((IpcFrKeep.of_updTcb (y := { x with tcbState := .restart }) hk rfl rfl).trans + (IpcFrKeep.of_kheap (by rw [stsAct_kheap]))) hkz) + (devFrom_same J.xtop.rel.2.1.2.2.1 hX1.rel.2.1.2.2.1 hSS) (JCs.sameB J hSS hkz) R (Vs.VsSlotsT.of_eq fun y hy => hSS.capV hy) + (J.liveX hX1 rfl rfl rfl hSS hK + (orig_eq_of_slots J.xtop.rel.2.1.2.2.2.1 hX1.rel.2.1.2.2.2.1 J.kern.orig R.kern.orig hSS) + (XTopAt.idleW_eqS J.xtop hX1 hid) fun p hp => R.jcov.dead p (J.zD p hp)) + (J.zDX hSS J.zD) + /-! ## The slot steps (an insertion, a CNode-only step) -/ /-- **A word outside every slot is kept by writes of slot words** (the slot @@ -1157,9 +1219,9 @@ theorem jowes_ks {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s s' : S) ( /-- **The scheduler's words a scheduler step keeps** (as `inSlot_keeps`, for `SchW`: the TCBs' queue words, the node, the domain words). -/ -theorem schW_keeps {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +theorem schW_keepsB {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) : + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) : (∀ t ∈ Z.T, L.mem s' (mcpA t) = L.mem s (mcpA t) ∧ L.mem s' (flagsA t) = L.mem s (flagsA t)) ∧ (∀ t ∈ Z.T, L.mem s' (yieldA t) = L.mem s (yieldA t)) ∧ (∀ t ∈ Z.T, L.mem s' (tIpcBufA t) = L.mem s (tIpcBufA t)) ∧ (∀ q ∈ Z.C, L.mem s' (scReplyA q) = L.mem s (scReplyA q)) ∧ @@ -1213,6 +1275,16 @@ theorem schW_keeps {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} { · rcases ht y hy with h | h <;> omega · rcases ht y hy with h | h <;> omega +/-- `schW_keepsB` at `JAtZ` (mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem schW_keeps {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} (hw : P1.WritesIn st s s' (SchW (L := L) Z.T Z.c s)) : + (∀ t ∈ Z.T, L.mem s' (mcpA t) = L.mem s (mcpA t) ∧ L.mem s' (flagsA t) = L.mem s (flagsA t)) ∧ (∀ t ∈ Z.T, L.mem s' (yieldA t) = L.mem s (yieldA t)) ∧ + (∀ t ∈ Z.T, L.mem s' (tIpcBufA t) = L.mem s (tIpcBufA t)) ∧ + (∀ q ∈ Z.C, L.mem s' (scReplyA q) = L.mem s (scReplyA q)) ∧ + (∀ r ∈ Z.R, L.mem s' (rPrevA r) = L.mem s (rPrevA r) ∧ L.mem s' (rNextA r) = L.mem s (rNextA r)) := + schW_keepsB arI J.toB hw + set_option maxHeartbeats 4000000 in /-- **`JStepHyps.sched`**, with no premise: FL4 writes the scheduler's words (`schW_keeps`), the spec keeps the heap (`SchedK`, so `HStep`); `Inv`, the @@ -1220,15 +1292,17 @@ current thread's invariant and `ActIdle` after (`SchedQOK`: the ready queues gain schedulable threads only, the action kept or `chooseNewThread`); P1's `BlkOK` after (`BlkKeep`); the node-0 debug word and the untyped caps' facts kept (the footprint `SchW` misses them). -/ -theorem jowes_sched {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s s' : S) (a : A) (σ σ' : Fl4Spec.State Unit) +theorem jowes_schedDB {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s s' : S) (a : A) (σ σ' : Fl4Spec.State Unit) (hS : SchedStep (L := L) th s σ s' σ') : - JOwesD (L := L) arI AR th s a σ s' a σ' := by + ∀ (Z : XSets) (H : P1.Heap) (Cs Ac : Set U64) (Lst : U64 → List U64) (D : Set U64), Z.th = th → + JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ → XTopAt (L := L) AR Z s' a σ' → + ∃ (Ac' : Set U64) (Lst' : U64 → List U64), JRest (L := L) arI Z H Cs Ac' Lst' D s' σ' := by intro Z H Cs Ac Lst D hth J hX' subst hth obtain ⟨hK, hS2, hQ, hBK⟩ := hS have hw := (hS2 Z.N Z.T Z.C Z.c J.thT J.xtop.fin.1.1.1 J.xtop.fin.1.1.2.2.1).2.1 have hC : HStep σ σ' := ⟨fun p => Or.inl (by rw [hK.kh]), hK.rel, hK.ct, hK.csc, hK.ctime, hK.cons, hK.idle, hK.isc⟩ - obtain ⟨k1, k2, kb, k3, k4⟩ := schW_keeps arI J hw + obtain ⟨k1, k2, kb, k3, k4⟩ := schW_keepsB arI J hw have ck : Sched.CKeep σ σ' := ⟨fun q y n hq => ⟨y, hC.sc.2 hq, rfl⟩, fun q x hq => ⟨x, (hC.look (fun _ _ e => by cases e) (fun _ e => by cases e)).2 hq, rfl, rfl⟩, fun p x n hp => ⟨x, hC.sc.1 hp⟩⟩ have yk : YKeep σ σ' := ⟨fun p x hp => let ⟨y, hy, hc⟩ := hC.tcbF hp; ⟨y, hy, hc.yld⟩, fun p x n hp => ⟨x, hC.sc.2 hp, rfl⟩, @@ -1341,6 +1415,12 @@ theorem jowes_sched {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s s' : S hkern, hutc, J.nsc.cn hC, hI', hcur', J.own.cn hC, J.off.cn hC, hA', J.bsa.cn hC, J.isorted.cn hC, J.curRun.cn hC hQ.2, hblk⟩⟩ +/-- `jowes_schedDB` at `JAtZ` (`JOwesD`; mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem jowes_sched {AR : A → Fl4Spec.Cr3 → Prop} {th : TypedHeap} (s s' : S) (a : A) (σ σ' : Fl4Spec.State Unit) + (hS : SchedStep (L := L) th s σ s' σ') : + JOwesD (L := L) arI AR th s a σ s' a σ' := + fun Z H Cs Ac Lst D hth J hX' => jowes_schedDB arI s s' a σ σ' hS Z H Cs Ac Lst D hth J.toB hX' + /-- **`JStepHyps`, proved**: every primitive step's residue is discharged (`jowes_restart`, `jowes_ks`, `jowes_ins`, `jowes_sched`, `jowes_cn`); a diff --git a/proofs/Fl4Proofs/P3/XTopJointSendBlockG.lean b/proofs/Fl4Proofs/P3/XTopJointSendBlockG.lean index 4f87dd4a2..587bc08b6 100644 --- a/proofs/Fl4Proofs/P3/XTopJointSendBlockG.lean +++ b/proofs/Fl4Proofs/P3/XTopJointSendBlockG.lean @@ -27,6 +27,9 @@ released, so `Inv.rd` fails there). steps) and the weakened `Inv.rd` (the thread is a sender with a timeout fault, `inClassR`, l4v `valid_sender_sc_tcb_at`); `BlockedScActive` from the thread's active SC. + +(mmuAD gen 42b70) `zv_bfrt` / `natK_bfrt` (a blocking send's spec frame `BFrT` is a native step) moved here from +P3/XTopJointFaultEp, statements unchanged (ScChargeT's timeout-fault send needs them). -/ import Fl4Proofs.P3.XTopJointSendBlock import Fl4Proofs.P3.XTopJointStsI @@ -804,4 +807,44 @@ end end +/-- **What a blocking send's spec frame keeps of the VM epoch** (moved here from P3/JAtZV3FaultBlk in mmuAD gen 42b67, +then from P3/XTopJointFaultEp in gen 42b70). -/ +theorem zv_bfrt {t e : Fl4Spec.ObjRef} {σ σ' : Fl4Spec.State Unit} (h : Sched.BFrT t e σ σ') : + (∀ p ao, σ.kheap p = some (.archObj ao) → σ'.kheap p = σ.kheap p) ∧ + (∀ o ko', σ'.kheap o = some ko' → ∃ ko, σ.kheap o = some ko ∧ Fl4Spec.objBits ko' = Fl4Spec.objBits ko) ∧ + (∀ o x', σ'.kheap o = some (.tcb x') → x'.tcbState = .runningVM → + ∃ x, σ.kheap o = some (.tcb x) ∧ x.tcbState = .runningVM) ∧ + (∀ p (vs : Fl4Spec.VcpuState), σ'.kheap p = some (.archObj (.vcpu vs)) → + σ.kheap p = some (.archObj (.vcpu vs))) := by + refine ⟨fun p ao hp => ?_, fun o ko' ho => ?_, fun o x' ho hx => ?_, fun p vs hp => ?_⟩ + · rcases h.kh p with k | ⟨o, o', h1, -, hc⟩ + · exact k + · rw [hp] at h1; cases h1 + rcases hc with ⟨_, _, _, _, e, -⟩ | ⟨_, _, e, -⟩ <;> cases e + · rcases h.kh o with k | ⟨o1, o2, h1, h2, hc⟩ + · exact ⟨ko', by rw [← k]; exact ho, rfl⟩ + · rw [ho] at h2; cases h2 + rcases hc with ⟨_, _, _, _, rfl, rfl, -⟩ | ⟨_, _, rfl, rfl, -⟩ + · exact ⟨_, h1, rfl⟩ + · exact ⟨_, h1, rfl⟩ + · rcases h.kh o with k | ⟨o1, o2, h1, h2, hc⟩ + · exact ⟨x', by rw [← k]; exact ho, hx⟩ + · rw [ho] at h2; cases h2 + rcases hc with ⟨_, _, _, _, rfl, e, -⟩ | ⟨_, _, rfl, e, -⟩ + · cases e; cases hx + · cases e + · rcases h.kh p with k | ⟨o1, o2, h1, h2, hc⟩ + · rw [← k]; exact hp + · rw [hp] at h2; cases h2 + rcases hc with ⟨_, _, _, _, -, e, -⟩ | ⟨_, _, -, e, -⟩ <;> cases e + +/-- (mmuAD gen 42b67; moved here from P3/XTopJointFaultEp in gen 42b70) **A blocking send's spec frame is a native step** (`zv_bfrt`; no arch object on either side of +a `BChgT` change). -/ +theorem natK_bfrt {t e : Fl4Spec.ObjRef} {σ σ' : Fl4Spec.State Unit} (h : Sched.BFrT t e σ σ') : NatK σ σ' := + ⟨zv_bfrt h, fun p ao hp => by + rcases h.kh p with k | ⟨o1, o2, h1, h2, hc⟩ + · rw [← k]; exact hp + · rw [hp] at h2; cases h2 + rcases hc with ⟨_, _, _, _, -, e, -⟩ | ⟨_, _, -, e, -⟩ <;> cases e⟩ + end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/XTopJointSendRecv.lean b/proofs/Fl4Proofs/P3/XTopJointSendRecv.lean index e263350d2..25e8f6826 100644 --- a/proofs/Fl4Proofs/P3/XTopJointSendRecv.lean +++ b/proofs/Fl4Proofs/P3/XTopJointSendRecv.lean @@ -17,6 +17,12 @@ XTopJointIpcJ's `JSendRestHyp`). XTopJointXferG's `JAtZ.xferStepGJ` (any grant; the frames rebuilt from its base `σy`), back to `JAtZ` by `JAtZ.bufRebaseX` at its base before `JAtZ.wake_postD`. + +(mmuAD gen 42b67, option (b) step b3) `unblockRJ`, `sendUnblockJ`, `sendSwitchJ`, `sendTailJ` stated over `JAtZB` in +place: `unblockRJ`'s post extended by the domain time, `ScTKw` and the `TFoot` writes (P3/JAtZV3SigTail's twin +`JAtZB.unblockJR` is now its corollary), the other three with the native footprint `NatFoot` (`NatFoot.ofT`, +`natK_tk`, `nkt_possibleSwitchTo`). The `JAtZ` names are one-line corollaries (`JAtZ.ext_tfoot`, `JAtZB.toJN`), +statements unchanged. No named premise. -/ import Fl4Proofs.P3.XTopJointXferG import Fl4Proofs.P3.BufJ @@ -72,8 +78,9 @@ variable {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Se set_option maxHeartbeats 16000000 in /-- **`unblock_check` at `J`, the SC's thread in no release queue** (module -docstring). -/ -theorem JAtZ.unblockRJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +docstring). (mmuAD gen 42b67) Over `JAtZB` in place, the post extended by the domain time, the spec frame `ScTKw` +and FL4's `TFoot` writes (P3/JAtZV3SigTail's `JAtZB.unblockJR`, now its corollary). -/ +theorem JAtZB.unblockRJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hnr : t.bv ∉ σ.releaseQueue) {p : U64} (hp : p ∈ Z.C) (hxsc : x.tcbSchedContext = some p.bv) (hpc : p.bv ≠ σ.curSc) {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap p.bv = some (.schedContext y n)) @@ -82,7 +89,8 @@ theorem JAtZ.unblockRJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 (∀ q, q ≠ p.bv → σ'.kheap q = σ.kheap q) ∧ σ'.curThread = σ.curThread ∧ σ'.idleThread = σ.idleThread ∧ σ'.releaseQueue = σ.releaseQueue ∧ (∃ z, σ'.kheap p.bv = some (.schedContext z n) ∧ z.scRefillMax = y.scRefillMax ∧ z.scTcb = y.scTcb) ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := by + σ'.domainTime = σ.domainTime ∧ ScTKw (fun _ => False) σ σ' ∧ P1.WritesIn st s s' (TFoot st Z.T Z.N Z.C Z.c s σ) ∧ + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := by have hX := J.xtop have hS := hX.fin.1.1.1 have hR : NtfnStateRel Z.N Z.T (L.mem s) σ := hX.fin.1.1.2.2.1 @@ -116,7 +124,11 @@ theorem JAtZ.unblockRJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 · exact ⟨fun q hq => by simp [updK, hq], rfl, rfl, rfl, rfl, rfl, rfl, rfl, z, by simp [updK], by rw [hz], by rw [hz]⟩ obtain ⟨hkp, e_ct, e_csc, e_tm, e_cons, e_rel, e_idle, e_act, z, hkz, hzm, hzt⟩ := hF - refine ⟨σ', he, hkp, e_ct, e_idle, e_rel, ⟨z, hkz, hzm, hzt⟩, ?_⟩ + have e_dt : σ'.domainTime = σ.domainTime := by + rcases unblock_result hky hne mem with ⟨rfl, -⟩ | ⟨z, rfl, -⟩ + · rfl + · rfl + refine ⟨σ', he, hkp, e_ct, e_idle, e_rel, ⟨z, hkz, hzm, hzt⟩, e_dt, ?_⟩ -- the spec frame have hK0 : ScTKw (fun _ => False) σ σ' := nkt_refillUnblockCheck p.bv σ _ mem have hK : ScTKw (fun q => q = t.bv) σ σ' := hK0.ofFalse @@ -180,11 +192,26 @@ theorem JAtZ.unblockRJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 J.deadP_sc_stepQ hX' hwT hK0 (fun _ hp => hp.elim) hL hFK hAI.1 hY' ((hsok.ykeep rfl).dk q.bv) (fun h => h) (J.jcov.dead q hq) have hDbg := J.kw_dbg hfoot have hKd := J.kw_dbgKeep hfoot - exact ⟨Lst', J.sc_frame hwT hK hX' hCR' hRF' hY' hM' (J.sc_buf hwT hK) hRP' (J.sc_apart hwT hK) + exact ⟨hK0, hwT, Lst', J.sc_frame hwT hK hX' hCR' hRF' hY' hM' (J.sc_buf hwT hK) hRP' (J.sc_apart hwT hK) (J.sc_jpl hwT hK (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2).2) (J.sc_jcov hwT hdead (fun q hq hn => absurd hq hn) (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2) hKd subset_rfl) (J.sc_kern hwT hK hFK hX' hDbg fun _ h => h) (J.sc_utc hwT hK hDbg) hN' hI' hC' hown' hoff hAI (J.bsa.bk hBK hsok) hcr ⟨⟨Q1, R1, hq2⟩, hB2, hX2, hS2, hSg2⟩ hKd (J.idleW_keep hX'.fin.1.1.1 hFK.2.1 hFK.2.2).1 J.zD⟩ +/-- `JAtZB.unblockRJ` at `JAtZ` (via `JAtZ.toB`; `ext` across the `TFoot` writes). -/ +theorem JAtZ.unblockRJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hnr : t.bv ∉ σ.releaseQueue) + {p : U64} (hp : p ∈ Z.C) (hxsc : x.tcbSchedContext = some p.bv) (hpc : p.bv ≠ σ.curSc) + {y : Fl4Spec.SchedContext} {n : Nat} (hky : σ.kheap p.bv = some (.schedContext y n)) + (hya : Fl4Spec.scActive y = true) : + sporadic.unblock_check st s p ⦃ s' => ∃ σ', Fl4Spec.refillUnblockCheck (Z := Unit) p.bv σ = ({((), σ')}, False) ∧ + (∀ q, q ≠ p.bv → σ'.kheap q = σ.kheap q) ∧ σ'.curThread = σ.curThread ∧ + σ'.idleThread = σ.idleThread ∧ σ'.releaseQueue = σ.releaseQueue ∧ + (∃ z, σ'.kheap p.bv = some (.schedContext z n) ∧ z.scRefillMax = y.scRefillMax ∧ z.scTcb = y.scTcb) ∧ + ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := + WP.spec_mono (J.toB.unblockRJ ht hk hnr hp hxsc hpc hky hya) + fun _ ⟨σ', he, hkp, h1, h2, h3, hz, _, _, hwT, Lst', B⟩ => + ⟨σ', he, hkp, h1, h2, h3, hz, Lst', B.toJAtZ (J.ext_tfoot hwT)⟩ + /-- What `sendUnblockJ` keeps of the spec's state. -/ def UnblockKeep (σ σ' : Fl4Spec.State Unit) : Prop := (∀ q xq, σ.kheap q = some (.tcb xq) → σ'.kheap q = some (.tcb xq)) ∧ σ'.curThread = σ.curThread ∧ @@ -193,12 +220,12 @@ def UnblockKeep (σ σ' : Fl4Spec.State Unit) : Prop := y.scRefillMax = y0.scRefillMax ∧ y.scTcb = y0.scTcb) set_option maxHeartbeats 8000000 in -/-- **`unblock_sporadic` at `J`** (module docstring). -/ -theorem JAtZ.sendUnblockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +/-- **`unblock_sporadic` at `J`** (module docstring; (mmuAD gen 42b67) over `JAtZB` in place, with `NatFoot`). -/ +theorem JAtZB.sendUnblockJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hnr : t.bv ∉ σ.releaseQueue) : endpoint.unblock_sporadic st s t ⦃ s' => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), Fl4Spec.ifSporadicCurScTestRefillUnblockCheck (Z := Unit) x.tcbSchedContext σ = ({((), σ')}, False) ∧ - JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ∧ UnblockKeep σ σ' ⦄ := by + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ∧ UnblockKeep σ σ' ∧ NatFoot (L := L) Z s σ s' σ' ⦄ := by have hS := J.xtop.fin.1.1.1 obtain ⟨Q, R0, hc0, hs⟩ := hS.lists obtain ⟨xt, hkt, -, -, hsct, -⟩ := hs.tcb t ht @@ -206,8 +233,9 @@ theorem JAtZ.sendUnblockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : have skip : Fl4Spec.ifSporadicCurScTestRefillUnblockCheck (Z := Unit) (optRef (L.mem s (scA t))) σ = ({((), σ)}, False) → ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), Fl4Spec.ifSporadicCurScTestRefillUnblockCheck (Z := Unit) x.tcbSchedContext σ = ({((), σ')}, False) ∧ - JAtZ (L := L) arI AR Z H Cs Ac Lst' D s a σ' ∧ UnblockKeep σ σ' := fun h => - ⟨σ, Lst, by rw [hsct]; exact h, J, fun _ _ h => h, rfl, rfl, rfl, fun _ y _ h => ⟨y, h, rfl, rfl⟩⟩ + JAtZB (L := L) arI AR Z H Cs Ac Lst' D s a σ' ∧ UnblockKeep σ σ' ∧ NatFoot (L := L) Z s σ s σ' := fun h => + ⟨σ, Lst, by rw [hsct]; exact h, J, ⟨fun _ _ h => h, rfl, rfl, rfl, fun _ y _ h => ⟨y, h, rfl, rfl⟩⟩, + NatFoot.refl _ _ _⟩ unfold endpoint.unblock_sporadic step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i2, hi2⟩ step with sporadic.sc_sporadic.spec' as ⟨b, b_post⟩ @@ -255,8 +283,9 @@ theorem JAtZ.sendUnblockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : rw [hsct, Notif.optRef_ne h0] have hya : Fl4Spec.scActive y = true := hy.active_of_rmax (hy.spor hsp') refine WP.spec_mono (J.unblockRJ ht hk hnr hscC hxsc hpc hky hya) ?_ - rintro s' ⟨σ', he, hkp, hct, hid, hrl, ⟨z, hkz, hzm, hzt⟩, Lst', J'⟩ - refine ⟨σ', Lst', ?_, J', fun q xq hq => ?_, hct, hid, hrl, fun q y' n' hq => ?_⟩ + rintro s' ⟨σ', he, hkp, hct, hid, hrl, ⟨z, hkz, hzm, hzt⟩, -, hK0, hwT, Lst', J'⟩ + refine ⟨σ', Lst', ?_, J', ⟨fun q xq hq => ?_, hct, hid, hrl, fun q y' n' hq => ?_⟩, + NatFoot.ofT J.xtop hwT (fun b hb => J.tfoot_nh hb) (natK_tk hK0)⟩ · rw [hsct, hif, ite_t ⟨hsp.2 hsp', hpc⟩, he] · by_cases eq : q = (L.mem s (scA t)).bv · rw [eq, hky] at hq; cases hq @@ -268,18 +297,24 @@ theorem JAtZ.sendUnblockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : set_option maxHeartbeats 4000000 in /-- **`possible_switch_to` at `J`** of a runnable thread in no release queue -with an active SC or none (module docstring). -/ -theorem JAtZ.sendSwitchJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +with an active SC or none (module docstring; (mmuAD gen 42b67) over `JAtZB` in place, with `NatFoot`: the `TFoot` +writes of `possible_switch_to_sfoot`, the spec frame `nkt_possibleSwitchTo`). -/ +theorem JAtZB.sendSwitchJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrun : Fl4Spec.runnable x.tcbState = true) (hnr : t.bv ∉ σ.releaseQueue) (hact : ∀ p y n, x.tcbSchedContext = some p → σ.kheap p = some (.schedContext y n) → Fl4Spec.scActive y = true) (hti : t.bv ≠ σ.idleThread) (htc : t.bv ≠ σ.curThread) : sched.possible_switch_to st s t ⦃ s' => ∃ σ', Fl4Spec.possibleSwitchTo (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ∧ NatFoot (L := L) Z s σ s' σ' ⦄ := by cases hsc : x.tcbSchedContext with | some p => obtain ⟨y, n, hky, -⟩ := J.inv.back _ _ _ hk hsc - exact J.switchJ ht hti htc (schedulable_of hk hsc hrun hky (hact p y n hsc hky) hnr) + refine WP.spec_mono (WP.spec_and (J.switchJ ht hti htc (schedulable_of hk hsc hrun hky (hact p y n hsc hky) hnr)) + (possible_switch_to_sfoot J.xtop.fin.1.1.2.2.1 J.xtop.fin.1.1.1 J.inv.actReady ht)) ?_ + rintro s' ⟨⟨σ', he, Lst', B⟩, hw⟩ + have mem : ((), σ') ∈ (Fl4Spec.possibleSwitchTo (Z := Unit) t.bv σ).1 := by rw [he]; exact Set.mem_singleton _ + exact ⟨σ', he, Lst', B, NatFoot.ofT J.xtop (WritesIn.tfoot_of_kfoot (WritesIn.kfoot_of_sfoot hw)) + (fun b hb => J.tfoot_nh hb) (natK_tk (nkt_possibleSwitchTo t.bv σ _ mem))⟩ | none => have hS := J.xtop.fin.1.1.1 obtain ⟨Q, R0, hc0, hs⟩ := hS.lists @@ -293,7 +328,7 @@ theorem JAtZ.sendSwitchJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : step with Fl4Proofs.P1.obj.Tcb.sc.spec as ⟨i, hi⟩ rw [hi, h0] simp only [↓reduceIte, WP.spec_ok] - refine ⟨σ, ?_, Lst, J⟩ + refine ⟨σ, ?_, Lst, J, NatFoot.refl _ _ _⟩ unfold Fl4Spec.possibleSwitchTo Fl4Spec.getTcbObjRef rw [nd_bind_one (threadGet_eq _ hk)] simp only [hsc, nd_gets_bind] @@ -301,8 +336,9 @@ theorem JAtZ.sendSwitchJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : rfl set_option maxHeartbeats 4000000 in -/-- **The receiver's tail of `send_ipc` at `J`** (module docstring). -/ -theorem JAtZ.sendTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) +/-- **The receiver's tail of `send_ipc` at `J`** (module docstring; (mmuAD gen 42b67) over `JAtZB` in place, with +`NatFoot`). -/ +theorem JAtZB.sendTailJ (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrun : Fl4Spec.runnable x.tcbState = true) (hnr : t.bv ∉ σ.releaseQueue) (hact : ∀ p y n, x.tcbSchedContext = some p → σ.kheap p = some (.schedContext y n) → Fl4Spec.scActive y = true) @@ -311,9 +347,9 @@ theorem JAtZ.sendTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 let s6 ← endpoint.unblock_sporadic st s t let s7 ← sched.possible_switch_to st s6 t ok (s7, a)) ⦃ r => r.2 = a ∧ ∃ σ', Endp.specWakeTailE t.bv σ = ({((), σ')}, False) ∧ - ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := by + ∃ Lst' : U64 → List U64, JAtZB (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ∧ NatFoot (L := L) Z s σ r.1 σ' ⦄ := by refine WP.spec_bind (J.sendUnblockJ ht hk hnr) ?_ - rintro s6 ⟨σ6, Lst6, hU, J6, hkt6, hct6, hid6, hrl6, hsc6⟩ + rintro s6 ⟨σ6, Lst6, hU, J6, ⟨hkt6, hct6, hid6, hrl6, hsc6⟩, F6⟩ have hk6 := hkt6 _ _ hk have hact6 : ∀ p y n, x.tcbSchedContext = some p → σ6.kheap p = some (.schedContext y n) → Fl4Spec.scActive y = true := by @@ -324,11 +360,44 @@ theorem JAtZ.sendTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U6 rw [hm]; exact this refine WP.spec_bind (J6.sendSwitchJ ht hk6 hrun (by rw [hrl6]; exact hnr) hact6 (by rw [hid6]; exact hti) (by rw [hct6]; exact htc)) ?_ - rintro s7 ⟨σ7, h7, Lst7, J7⟩ - refine (WP.spec_ok _).2 ⟨rfl, σ7, ?_, Lst7, J7⟩ + rintro s7 ⟨σ7, h7, Lst7, J7, F7⟩ + refine (WP.spec_ok _).2 ⟨rfl, σ7, ?_, Lst7, J7, J.natTrans F6 F7⟩ unfold Endp.specWakeTailE Fl4Spec.getTcbObjRef rw [nd_bind_one (threadGet_eq _ hk), nd_bind_one hU, h7] +/-- `JAtZB.sendUnblockJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.sendUnblockJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hnr : t.bv ∉ σ.releaseQueue) : + endpoint.unblock_sporadic st s t ⦃ s' => ∃ (σ' : Fl4Spec.State Unit) (Lst' : U64 → List U64), + Fl4Spec.ifSporadicCurScTestRefillUnblockCheck (Z := Unit) x.tcbSchedContext σ = ({((), σ')}, False) ∧ + JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ∧ UnblockKeep σ σ' ⦄ := + WP.spec_mono (J.toB.sendUnblockJ ht hk hnr) fun _ ⟨σ', Lst', h, B, hU, F⟩ => ⟨σ', Lst', h, B.toJN J F, hU⟩ + +/-- `JAtZB.sendSwitchJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.sendSwitchJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrun : Fl4Spec.runnable x.tcbState = true) + (hnr : t.bv ∉ σ.releaseQueue) + (hact : ∀ p y n, x.tcbSchedContext = some p → σ.kheap p = some (.schedContext y n) → Fl4Spec.scActive y = true) + (hti : t.bv ≠ σ.idleThread) (htc : t.bv ≠ σ.curThread) : + sched.possible_switch_to st s t ⦃ s' => ∃ σ', Fl4Spec.possibleSwitchTo (Z := Unit) t.bv σ = ({((), σ')}, False) ∧ + ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D s' a σ' ⦄ := + WP.spec_mono (J.toB.sendSwitchJ ht hk hrun hnr hact hti htc) fun _ ⟨σ', he, Lst', B, F⟩ => + ⟨σ', he, Lst', B.toJN J F⟩ + +/-- `JAtZB.sendTailJ` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.sendTailJ (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {t : U64} (ht : t ∈ Z.T) + {x : Fl4Spec.Tcb} (hk : σ.kheap t.bv = some (.tcb x)) (hrun : Fl4Spec.runnable x.tcbState = true) + (hnr : t.bv ∉ σ.releaseQueue) + (hact : ∀ p y n, x.tcbSchedContext = some p → σ.kheap p = some (.schedContext y n) → Fl4Spec.scActive y = true) + (hti : t.bv ≠ σ.idleThread) (htc : t.bv ≠ σ.curThread) : + (do + let s6 ← endpoint.unblock_sporadic st s t + let s7 ← sched.possible_switch_to st s6 t + ok (s7, a)) ⦃ r => r.2 = a ∧ ∃ σ', Endp.specWakeTailE t.bv σ = ({((), σ')}, False) ∧ + ∃ Lst' : U64 → List U64, JAtZ (L := L) arI AR Z H Cs Ac Lst' D r.1 a σ' ⦄ := + WP.spec_mono (J.toB.sendTailJ ht hk hrun hnr hact hti htc) fun _ ⟨h, σ', he, Lst', B, F⟩ => + ⟨h, σ', he, Lst', B.toJN J F⟩ + set_option maxHeartbeats 64000000 in /-- **`send_ipc` to a waiting receiver at `J`, without a call, a donation diff --git a/proofs/Fl4Proofs/P3/XTopJointStep.lean b/proofs/Fl4Proofs/P3/XTopJointStep.lean index 03c97d66a..01a7142a4 100644 --- a/proofs/Fl4Proofs/P3/XTopJointStep.lean +++ b/proofs/Fl4Proofs/P3/XTopJointStep.lean @@ -715,9 +715,9 @@ theorem schW_oobj {Z : XSets} {s : S} {σ : Fl4Spec.State Unit} (hT : P1.TcbPlac variable {arI} in /-- A scheduler-step word (`SchW`) is no TCB's VCPU word. -/ -theorem JAtZ.schW_nv {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +theorem JAtZB.schW_nv {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (h : SchW (L := L) Z.T Z.c s b) : + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (h : SchW (L := L) Z.T Z.c s b) : ∀ t ∈ Z.T, b ≠ tVcpuA t := by have hT : P1.TcbPlaced Z.T := J.ip.e.tcb intro u hu @@ -730,10 +730,18 @@ theorem JAtZ.schW_nv {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} exact J.ks_nv (by omega) (by omega) u hu variable {arI} in -/-- A scheduler-step word (`SchW`) is no TCB's deadline word (KENTRY-PLAN jc6e). -/ -theorem JAtZ.schW_ntd {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} +/-- `JAtZB.schW_nv` at `JAtZ` (mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem JAtZ.schW_nv {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (h : SchW (L := L) Z.T Z.c s b) : + ∀ t ∈ Z.T, b ≠ tVcpuA t := + J.toB.schW_nv h + +variable {arI} in +/-- A scheduler-step word (`SchW`) is no TCB's deadline word (KENTRY-PLAN jc6e). -/ +theorem JAtZB.schW_ntd {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (h : SchW (L := L) Z.T Z.c s b) : ∀ t ∈ Z.T, b ≠ P1.tdA t := by have hT : P1.TcbPlaced Z.T := J.ip.e.tcb intro u hu @@ -745,6 +753,14 @@ theorem JAtZ.schW_ntd {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap · have := domKW_val h exact J.ks_ntd (by omega) (by omega) u hu +variable {arI} in +/-- `JAtZB.schW_ntd` at `JAtZ` (mmuAD gen 42b70: via `JAtZ.toB`). -/ +theorem JAtZ.schW_ntd {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} + {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} + (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {b : U64} (h : SchW (L := L) Z.T Z.c s b) : + ∀ t ∈ Z.T, b ≠ P1.tdA t := + J.toB.schW_ntd h + variable {arI} in /-- **`set_thread_state` keeps the deadline words** (its scheduler footprint). -/ theorem JAtZ.td_sts {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} diff --git a/proofs/Fl4Proofs/P3/XTopJointVsSub.lean b/proofs/Fl4Proofs/P3/XTopJointVsSub.lean index 0176bc18c..023f71ab9 100644 --- a/proofs/Fl4Proofs/P3/XTopJointVsSub.lean +++ b/proofs/Fl4Proofs/P3/XTopJointVsSub.lean @@ -77,7 +77,7 @@ set_option maxHeartbeats 4000000 in /-- **XTopJointDel's `jowes_slotDF` with `TypedKeptH`.** -/ theorem jowes_slotDFH {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap} {Cs Ac : Set U64} {Lst : U64 → List U64} {D : Set U64} {s : S} {a : A} {σ : Fl4Spec.State Unit} - (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} + (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {s' : S} {a' : A} {σ' : Fl4Spec.State Unit} {G' : MdbGhost} {V' : XVs} (hX' : XTopAt (L := L) AR (Z.mv G' V') s' a' σ') (hcn : Ipc.CnK σ σ') (hkc : KeepCT σ σ') (hw : P1.WritesIn st s s' (InSlot Z.th)) {kb : U64} (hFI : FinInv Z.th (L.mem s') σ' G') (hMO : MdbOKV kb (L.mem s') G') (hkz : KSz σ σ') @@ -92,7 +92,7 @@ theorem jowes_slotDFH {AR : A → Fl4Spec.Cr3 → Prop} {Z : XSets} {H : P1.Heap UtCapP3 (L := L) arI Z.th s' σ' G' sl p sb fi) : JCs (L := L) (Z.mv G' V') s' σ' ∧ JRest (L := L) arI (Z.mv G' V') H Cs Ac Lst D' s' σ' := by have hC := CnStep.of_cnK hcn - obtain ⟨k1, k2, kb', k3, k4⟩ := inSlot_keeps arI J hw + obtain ⟨k1, k2, kb', k3, k4⟩ := inSlot_keepsB arI J hw have ck : Sched.CKeep σ σ' := ⟨fun q y n hq => ⟨y, hC.sc.2 hq, rfl⟩, fun q x hq => ⟨x, (hC.look (fun _ _ e => by cases e) (fun _ e => by cases e)).2 hq, rfl, rfl⟩, fun p x n hp => ⟨x, hC.sc.1 hp⟩⟩ have yk : YKeep σ σ' := ⟨fun p x hp => let ⟨y, hy, hc⟩ := hC.tcbF hp; ⟨y, hy, hc.yld⟩, fun p x n hp => ⟨x, hC.sc.2 hp, rfl⟩, @@ -142,29 +142,37 @@ abbrev subSRJ (st : machine.Store S) [L : P1.LawfulStore st] (Z : XSets) (AR : A set_option maxHeartbeats 16000000 in /-- **One alias insert at `J`** (module docstring). -/ -theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) +theorem JAtZB.subInsQ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) - {ptr rt fa fv : U64} {mm rv : Bool} + {ptr rt fa fv : U64} {mm ep rv : Bool} (hS : SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) rv s a σ Z.G) + (.Frame ptr .Large rt false mm ep fa fv) rv s a σ Z.G) (hal : ptr.val % 2 ^ 21 = 0) {dp : U64} {r : Nat} (hdp : Z.th dp = some (.cnode r)) (hr : r < 64) {k : Nat} (hk : k < 2 ^ r) (hdst : capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 k)) = ok .Null) {q vm : U64} (hq1 : ptr.val ≤ q.val) (hq2 : q.val + 4096 ≤ ptr.val + 2 ^ 21) (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) - (hqal : q.val % 4096 = 0) (hDLc : DestCap Z.th (L.mem s) dp) : + (hqal : q.val % 4096 = 0) (hDLc : DestCap Z.th (L.mem s) dp) + {Q : MdbGhost → S → Fl4Spec.State Unit → Prop} + (hQ : ∀ {s' σ' G'}, JAtZB (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac Lst D s' a σ' → + P1.WritesIn st s s' (InSlot Z.th) → Vs.VsSlotsT Z.th (L.mem s) (L.mem s') → + Ipc.CnK σ σ' → MdbStep (L.mem s) Z.G (L.mem s') G' → + (∀ y, IsSlot Z.th y → y ≠ slotAddr dp.bv (BitVec.ofNat 64 k) → + capV (L.mem s') y = capV (L.mem s) y) → + capV (L.mem s') (slotAddr dp.bv (BitVec.ofNat 64 k)) = .Frame q .Small vm false false false 0#u64 0#u64 → + (∀ n, n < tcbSlots → ∀ t, Z.th t = some .tcb → + capAt (L.mem s') (slotOf t n) = capAt (L.mem s) (slotOf t n)) → + Q G' s' σ') : cdt.insert st s (.Frame q .Small vm false false false 0#u64 0#u64) (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) ⦃ s' => ∃ σ', Fl4Spec.capInsert (Z := Unit) (absCap (.Frame q .Small vm false false false 0#u64 0#u64)) (pp.bv, idx) (dp.bv, Fl4Spec.natToCref r k) σ = ({((), σ')}, False) ∧ SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' + (.Frame ptr .Large rt false mm ep fa fv) rv s' a σ' (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ L.ksb s' = L.ksb s ∧ MdbStep (L.mem s) Z.G (L.mem s') (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ (∀ y, IsSlot Z.th y → y ≠ slotAddr dp.bv (BitVec.ofNat 64 k) → capAt (L.mem s') y = capAt (L.mem s) y) ∧ - ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) Z.vs) - H Cs Ac' Lst' D' s' a σ' ⦄ := by + Q (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) s' σ' ⦄ := by have hDL : DestLive Z.th (L.mem s) (L.ksb s) dp := Or.inl hDLc have hX := J.xtop obtain ⟨hPl, ⟨hSt, hV, hM, hC, hI⟩, hFI, -, hMO, -, -⟩ := hX.rel @@ -172,7 +180,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L set src := cslotAddr (pp.bv, idx) with hsrcdef set dest := slotAddr dp.bv (BitVec.ofNat 64 k) with hdestdef set c : capability.Cap := .Frame q .Small vm false false false 0#u64 0#u64 with hcdef - set srcC : capability.Cap := .Frame ptr .Large rt false mm false fa fv with hsrcCdef + set srcC : capability.Cap := .Frame ptr .Large rt false mm ep fa fv with hsrcCdef have hcap := hS.cap have hAs : AbsSlot Z.th (pp.bv, idx) := ⟨pp, rfl, Or.inl (by simpa [hidx] using hpp)⟩ have hs : IsSlot Z.th src := hAs.isSlot @@ -188,7 +196,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L have hdnm : dest ∉ Z.G.chains.flatten := by intro h; obtain ⟨-, c0, h0, hn⟩ := (hM.members dest).1 h rw [hdst] at h0; exact hn (eq_of_ok_eq h0).symm - refine WP.spec_mono (WP.spec_and (Vs.sub_step (L := L) (Vs.vsSubHyps_top (st := st) (L := L)) hTP.pl hTP.pt hpp + refine WP.spec_mono (WP.spec_and (Vs.sub_stepMap (L := L) (Vs.vsSubHyps_top (st := st) (L := L)) hTP.pl hTP.pt hpp hidx s a σ Z.G hTP.vs hTP.vo hTP.po hS hal hdp hr hk hdst hq1 hq2 hvm hqal) (WP.spec_and (Vs.insert_trace hPl s Z.G hM hsm hd hdnm hcap c he) (insert_delinv_imp hPl s Z.G hM hsm hd hdnm hcap c he (by simp [hcdef]) rfl))) ?_ @@ -238,9 +246,11 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L · left; rw [← capInsert_orig (absCap c) _ _ σ ((), σ') hmem sl e]; exact h have hgp : σ'.archState.x64GlobalPml4 = σ.archState.x64GlobalPml4 := by have e := congrArg (fun z => z.archState.x64GlobalPml4) hcn.1; exact e - have hutc := J.ins_utc arI (G' := G') hdp hlen (by rw [hdest']; exact hcapV) (by rw [hdest']; exact hdst) + have hAd : AbsSlot Z.th (dp.bv, Fl4Spec.natToCref r k) := ⟨dp, rfl, Or.inl (by rw [hlen]; exact hdp)⟩ + have hutc := J.ins_utcG arI (G' := G') hAd (by rw [hdest']; exact hcapV) (by rw [hdest']; exact hdst) (by rw [hdest']; exact hnu) hw (capInsert_cdt (absCap c) _ _ σ _ hmem) - (fun sl e => capInsert_orig (absCap c) _ _ σ ((), σ') hmem sl e) hgp hS'.M hDL + (fun sl e => capInsert_orig (absCap c) _ _ σ ((), σ') hmem sl e) hgp hS'.M + (fun _ _ _ _ _ hsl hcv hdv hnc => J.live_slot arI hsl hcv hdv hnc ⟨dp, r, rfl, hdp, hlen, hDL⟩) have hjc := J.jcov_cover hw.1 hS'.M hCK hUK (fun q hq => J.deadP_slot hX1' hcn hkcT hw (J.jcov.dead q hq)) (J.idleW_keep hX1'.fin.1.1.1 (CnStep.of_cnK hcn).idle (CnStep.of_cnK hcn).isc) @@ -254,7 +264,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L rw [capAt_capV, capAt_capV] at e rw [cslot_tcb3, eq_of_ok_eq e, ← cslot_tcb3]; exact hJ.fh t ht -- the alias's objects: inside the large frame's range - obtain ⟨bs, ts⟩ := frame_range ptr .Large rt false mm fa fv false + obtain ⟨bs, ts⟩ := frame_range ptr .Large rt false mm fa fv ep obtain ⟨bc, tc⟩ := frame_range q .Small vm false false 0#u64 0#u64 false have hmL : (maskF (fbitsF .Large)).val = 2 ^ 21 - 1 := by rw [maskF_val (by rw [fbitsF_val]; decide), fbitsF_val]; rfl @@ -267,7 +277,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L have tcv : topF c = q.val + 4095 := by rw [tc]; simp [core.num.U64.wrapping_add_val_eq, U64.size_def, UScalarTy.U64_numBits_eq, U64.numBits, hmS] omega - have tsv' : topF (.Frame ptr .Large rt false mm false fa fv) = ptr.val + 2 ^ 21 - 1 := tsv + have tsv' : topF (.Frame ptr .Large rt false mm ep fa fv) = ptr.val + 2 ^ 21 - 1 := tsv have tcv' : topF (.Frame q .Small vm false false false 0#u64 0#u64) = q.val + 4095 := tcv have hTKH : TypedKeptH Z.th H (Sched.idleScW (L := L) s) (L.mem s) (L.mem s') := by intro y hy @@ -275,7 +285,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L · right; right rw [e, hdc] obtain ⟨Tr, Cq, hJ⟩ := J.jpl - have hob : FrApartH H (.Frame ptr .Large rt false mm false fa fv) := by + have hob : FrApartH H (.Frame ptr .Large rt false mm ep fa fv) := by have h := hJ.cobj src hs; rw [capV_of_capAt hcap] at h; exact h refine ⟨⟨fun _ _ _ _ _ _ e => (by rw [hcdef] at e; cases e), fun _ _ _ _ e => (by rw [hcdef] at e; cases e), fun _ _ e => (by rw [hcdef] at e; cases e)⟩, ?_⟩ @@ -293,7 +303,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L have h0 := h src hs rw [capV_of_capAt hcap] at h0 rw [hdc] - exact (vcap_alias (h0.ok_of fun _ _ _ => ⟨by simp [hsrcCdef], by simp [hsrcCdef], by simp [hsrcCdef], by simp [hsrcCdef]⟩) hq1 hq2 hqal).toW) + exact (vcap_aliasMap (h0.ok_of fun _ _ _ => ⟨by simp [hsrcCdef], by simp [hsrcCdef], by simp [hsrcCdef], by simp [hsrcCdef]⟩) hq1 hq2 hqal).toW) (fun y _ e U h => by subst e have h0 := h src hs @@ -311,7 +321,7 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L by_cases e : y = dest · subst e; rw [hdc, hcdef] at h; cases h · exact ⟨y, hy, by rw [← hcapV y hy e]; exact h⟩ - have hLv' := LiveDN.wstepC J J.live hX1' (fun p hp => R.jcov.dead p (J.zD p hp)) hcn.idle hw + have hLv' := LiveDN.wstepCB J J.live hX1' (fun p hp => R.jcov.dead p (J.zD p hp)) hcn.idle hw [(dp.bv, Fl4Spec.natToCref r k)] (fun sl hsl => by simp only [List.mem_cons, List.not_mem_nil, or_false] at hsl @@ -328,15 +338,47 @@ theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L (fun y0 hy0 hn => by have e : y0 ≠ dest := fun e => hn (by rw [e]; exact hn0) exact ⟨y0, hy0, by rw [hcapV y0 hy0 e]; exact hn, by rw [hcapV y0 hy0 e]⟩) - exact ⟨σ', hci, hS', hks, hMS, hoth, Ac, Lst, D, - J.cs_frameV (hvn := J.vsShr hX1' hw.1 + have B' := J.cs_frameV (hvn := J.vsShr hX1' hw.1 (Vs.VsKeep.of_nokey (W := (· = dest)) (fun y hy hn => hcapV y hy hn) (fun y _ e => by subst e; rw [hn0]; rfl) (fun y _ e => by subst e; rw [hdc, hcdef]; rfl)) (Vs.ArchShr.of_objCn hcn.2 (by have e := congrArg Fl4Spec.AbstractState.archState hcn.1; exact e))) hw.1 hX1' (KBack.of_keepCT hkcT) - (J.bfK (J.slot2Fr hkcT hX1'.rel.2.1.1 fun q hq => Or.inl (hTS 2 (by decide) q hq)) hvT) hJC R (J.vsc.step hvT) (J.ext.step hvT (J.vkeep_slot hw)) + (J.bfK (J.slot2Fr hkcT hX1'.rel.2.1.1 fun q hq => Or.inl (hTS 2 (by decide) q hq)) hvT) hJC R (J.vsc.step hvT) hLv' (fun p hp => J.zD p (ZTcb.of_zombies hZf hp)) (J.carry.of_objCn hkcT) - (devFrom_kept J.mdbL hS'.M J.ut hUK) (J.carry.vsStep rfl hvT subset_rfl subset_rfl subset_rfl subset_rfl rfl hw.1 (ArchFwd.of_objCn hkcT)) (ArchFwd.of_objCn hkcT)⟩ + (devFrom_kept J.mdbL hS'.M J.ut hUK) (J.carry.vsStep rfl hvT subset_rfl subset_rfl subset_rfl subset_rfl rfl hw.1 (ArchFwd.of_objCn hkcT)) (ArchFwd.of_objCn hkcT) + exact ⟨σ', hci, hS', hks, hMS, hoth, hQ B' hw hvT hcn hMS hcapV hdc hTS⟩ + +set_option maxHeartbeats 4000000 in +/-- Insert one alias from a native frame. -/ +theorem JAtZ.subInsJ {s : S} {a : A} {σ : Fl4Spec.State Unit} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) + {ptr rt fa fv : U64} {mm rv : Bool} + (hS : SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm false fa fv) rv s a σ Z.G) + (hal : ptr.val % 2 ^ 21 = 0) + {dp : U64} {r : Nat} (hdp : Z.th dp = some (.cnode r)) (hr : r < 64) {k : Nat} (hk : k < 2 ^ r) + (hdst : capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 k)) = ok .Null) + {q vm : U64} (hq1 : ptr.val ≤ q.val) (hq2 : q.val + 4096 ≤ ptr.val + 2 ^ 21) (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) + (hqal : q.val % 4096 = 0) (hDLc : DestCap Z.th (L.mem s) dp) : + cdt.insert st s (.Frame q .Small vm false false false 0#u64 0#u64) (cslotAddr (pp.bv, idx)) + (slotAddr dp.bv (BitVec.ofNat 64 k)) ⦃ s' => ∃ σ', + Fl4Spec.capInsert (Z := Unit) (absCap (.Frame q .Small vm false false false 0#u64 0#u64)) (pp.bv, idx) + (dp.bv, Fl4Spec.natToCref r k) σ = ({((), σ')}, False) ∧ + SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' + (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + L.ksb s' = L.ksb s ∧ + MdbStep (L.mem s) Z.G (L.mem s') (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + (∀ y, IsSlot Z.th y → y ≠ slotAddr dp.bv (BitVec.ofNat 64 k) → capAt (L.mem s') y = capAt (L.mem s) y) ∧ + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZ (L := L) arI AR (Z.mv (insG Z.G (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) Z.vs) + H Cs Ac' Lst' D' s' a σ' ⦄ := by + refine J.toB.subInsQ hpp hidx hS hal hdp hr hk hdst hq1 hq2 hvm hqal hDLc + (Q := fun G' s' σ' => ∃ Ac' Lst' D', + JAtZ (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac' Lst' D' s' a σ') ?_ + intro s' σ' G' B' hw hvT _ _ _ _ _ + exact ⟨Ac, Lst, D, B'.toJAtZ (J.ext.step hvT (J.vkeep_slot hw))⟩ + end @@ -418,27 +460,44 @@ set_option maxHeartbeats 8000000 in /-- **The alias loop at `J`** (VsSubRel's `insert_subframes_rel`, each insert by `JAtZ.subInsJ`; the destination's CNode stays live: its naming cap is in no destination slot, those held nothing). -/ -theorem insert_subframesJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64} {Lst : U64 → List U64} - {D : Set U64} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) +theorem insert_subframesQ {s : S} {a : A} {σ : Fl4Spec.State Unit} + {Q : MdbGhost → S → Fl4Spec.State Unit → Prop} (hQ : Q Z.G s σ) {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) - {ptr rt fa fv : U64} {mm rv : Bool} + {ptr rt fa fv : U64} {mm ep rv : Bool} (hS : SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) rv s a σ Z.G) + (.Frame ptr .Large rt false mm ep fa fv) rv s a σ Z.G) (hal : ptr.val % 2 ^ 21 = 0) {dp : U64} {r : Nat} (hdp : Z.th dp = some (.cnode r)) (hr : r < 64) {first count base vm : U64} (hfc : first.val + count.val ≤ 2 ^ r) (hb1 : ptr.val ≤ base.val) (hb2 : base.val + count.val * 4096 ≤ ptr.val + 2 ^ 21) (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) (hbal : base.val % 4096 = 0) (hempty : ∀ j : Nat, first.val ≤ j → j < first.val + count.val → capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 j)) = ok .Null) - (hDL : DestCap Z.th (L.mem s) dp) : + (hDL : DestCap Z.th (L.mem s) dp) + (hAdd : ∀ {si σi Gi k q}, Q Gi si σi → + SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm ep fa fv) rv si a σi Gi → + k < 2 ^ r → capAt (L.mem si) (slotAddr dp.bv (BitVec.ofNat 64 k)) = ok .Null → + ptr.val ≤ q.val → q.val + 4096 ≤ ptr.val + 2 ^ 21 → q.val % 4096 = 0 → + DestCap Z.th (L.mem si) dp → + cdt.insert st si (.Frame q .Small vm false false false 0#u64 0#u64) (cslotAddr (pp.bv, idx)) + (slotAddr dp.bv (BitVec.ofNat 64 k)) ⦃ s' => ∃ σ', + Fl4Spec.capInsert (Z := Unit) (absCap (.Frame q .Small vm false false false 0#u64 0#u64)) + (pp.bv, idx) (dp.bv, Fl4Spec.natToCref r k) σi = ({((), σ')}, False) ∧ + SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm ep fa fv) rv s' a σ' + (insG Gi (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + L.ksb s' = L.ksb si ∧ + MdbStep (L.mem si) Gi (L.mem s') (insG Gi (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) ∧ + (∀ y, IsSlot Z.th y → y ≠ slotAddr dp.bv (BitVec.ofNat 64 k) → + capAt (L.mem s') y = capAt (L.mem si) y) ∧ + Q (insG Gi (cslotAddr (pp.bv, idx)) (slotAddr dp.bv (BitVec.ofNat 64 k)) rv) s' σ' ⦄) : vspace.insert_subframes st s (cslotAddr (pp.bv, idx)) dp first base count vm ⦃ s' => ∃ σ' G', Fl4Spec.NonDet.mapMx (subIns (pp.bv, idx) base.bv (vmRightsOf vm)) (subList dp r first.val count.val) σ = ({((), σ')}, False) ∧ SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' G' ∧ + (.Frame ptr .Large rt false mm ep fa fv) rv s' a σ' G' ∧ L.ksb s' = L.ksb s ∧ MdbStep (L.mem s) Z.G (L.mem s') G' ∧ - ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac' Lst' D' s' a σ' ⦄ := by + Q G' s' σ' ⦄ := by have hfit : ptr.val + 2 ^ 21 ≤ 2 ^ 64 := by have : ptr.val < 2 ^ 64 := ptr.hBounds; omega have hPl : Placed Z.th := hS.sr.2.pl set Lst0 := subList dp r first.val count.val with hLst @@ -447,16 +506,15 @@ theorem insert_subframesJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U6 apply loop.spec_decr_nat (measure := fun x : S × U64 => count.val - x.2.val) (inv := fun x : S × U64 => x.2.val ≤ count.val ∧ ∃ σi Gi, SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) rv x.1 a σi Gi ∧ + (.Frame ptr .Large rt false mm ep fa fv) rv x.1 a σi Gi ∧ MdbStep (L.mem s) Z.G (L.mem x.1) Gi ∧ L.ksb x.1 = L.ksb s ∧ (∀ j : Nat, first.val + x.2.val ≤ j → j < first.val + count.val → capAt (L.mem x.1) (slotAddr dp.bv (BitVec.ofNat 64 j)) = ok .Null) ∧ (∀ σf, Fl4Spec.NonDet.mapMx g (Lst0.drop x.2.val) σi = ({((), σf)}, False) → Fl4Spec.NonDet.mapMx g Lst0 σ = ({((), σf)}, False)) ∧ - (∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv Gi Z.vs) H Cs Ac' Lst' D' x.1 a σi) ∧ + Q Gi x.1 σi ∧ DestCap Z.th (L.mem x.1) dp) - · rintro ⟨si, i⟩ ⟨hic, σi, Gi, hSi, hMSi, hksi, hemp, hcont, ⟨Aci, Lsti, Di, Ji⟩, hDLi⟩ + · rintro ⟨si, i⟩ ⟨hic, σi, Gi, hSi, hMSi, hksi, hemp, hcont, hQi, hDLi⟩ unfold vspace.insert_subframes_loop.body simp only at hic hksi hemp hcont hDLi ⊢ by_cases hlt : i < count @@ -481,15 +539,15 @@ theorem insert_subframesJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U6 simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits, hi1v]; omega rw [hfiv] have hnull := hemp (first.val + i.val) (by omega) (by omega) - refine WP.spec_bind (JAtZ.subInsJ (Z := Z.mv Gi Z.vs) Ji hpp hidx hSi hal hdp hr hk2 hnull + refine WP.spec_bind (hAdd hQi hSi hk2 hnull (q := core.num.U64.wrapping_add base i1) (by rw [hqv]; omega) (by rw [hqv]; have := Nat.mul_le_mul_right 4096 (show i.val + 1 ≤ count.val by omega) - rw [Nat.add_mul] at this; omega) hvm (by rw [hqv]; omega) hDLi) ?_ - rintro s2 ⟨σ2, hci, hS2, hks2, hMS2, hoth, Ac2, Lst2, D2, J2⟩ + rw [Nat.add_mul] at this; omega) (by rw [hqv]; omega) hDLi) ?_ + rintro s2 ⟨σ2, hci, hS2, hks2, hMS2, hoth, hQ2⟩ step as ⟨i4, hi4⟩ have hi4v : i4.val = i.val + 1 := by simpa using hi4 refine ⟨by omega, ⟨σ2, _, hS2, hMSi.trans hMS2, hks2.trans hksi, fun j h1 h2 => ?_, fun σf hf => hcont σf ?_, - ⟨Ac2, Lst2, D2, J2⟩, ?_⟩, by omega⟩ + hQ2, ?_⟩, by omega⟩ · have hne : slotAddr dp.bv (BitVec.ofNat 64 j) ≠ slotAddr dp.bv (BitVec.ofNat 64 (first.val + i.val)) := by intro e have hj : IsSlotAt Z.th dp j := Or.inl ⟨r, hdp, by omega⟩ @@ -518,12 +576,38 @@ theorem insert_subframesJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U6 have hic' : i.val = count.val := by have : ¬ i.val < count.val := hlt omega - refine (WP.spec_ok _).2 ⟨σi, Gi, hcont σi ?_, hSi, hksi, hMSi, Aci, Lsti, Di, Ji⟩ + refine (WP.spec_ok _).2 ⟨σi, Gi, hcont σi ?_, hSi, hksi, hMSi, hQi⟩ rw [hic', subList_drop_all]; rfl · refine ⟨by simp, σ, Z.G, hS, MdbStep.refl hS.M, rfl, fun j h1 h2 => hempty j (by simpa using h1) h2, - fun σf hf => ?_, ⟨Ac, Lst, D, ?_⟩, hDL⟩ - · simpa using hf - · exact J + fun σf hf => ?_, hQ, hDL⟩ + simpa using hf + +/-- The alias loop at the native joint relation. -/ +theorem insert_subframesJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) + {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) + {ptr rt fa fv : U64} {mm rv : Bool} + (hS : SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm false fa fv) rv s a σ Z.G) + (hal : ptr.val % 2 ^ 21 = 0) + {dp : U64} {r : Nat} (hdp : Z.th dp = some (.cnode r)) (hr : r < 64) {first count base vm : U64} + (hfc : first.val + count.val ≤ 2 ^ r) (hb1 : ptr.val ≤ base.val) (hb2 : base.val + count.val * 4096 ≤ ptr.val + 2 ^ 21) + (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) (hbal : base.val % 4096 = 0) + (hempty : ∀ j : Nat, first.val ≤ j → j < first.val + count.val → + capAt (L.mem s) (slotAddr dp.bv (BitVec.ofNat 64 j)) = ok .Null) + (hDL : DestCap Z.th (L.mem s) dp) : + vspace.insert_subframes st s (cslotAddr (pp.bv, idx)) dp first base count vm ⦃ s' => ∃ σ' G', + Fl4Spec.NonDet.mapMx (subIns (pp.bv, idx) base.bv (vmRightsOf vm)) (subList dp r first.val count.val) σ = + ({((), σ')}, False) ∧ + SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm false fa fv) rv s' a σ' G' ∧ + L.ksb s' = L.ksb s ∧ MdbStep (L.mem s) Z.G (L.mem s') G' ∧ + ∃ (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZ (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac' Lst' D' s' a σ' ⦄ := by + refine insert_subframesQ (Z := Z) ⟨Ac, Lst, D, J⟩ hpp hidx hS hal hdp hr hfc hb1 hb2 hvm hbal hempty hDL ?_ + rintro si σi Gi k q ⟨Aci, Lsti, Di, Ji⟩ hSi hk hn hq1 hq2 hqa hDLi + exact JAtZ.subInsJ (Z := Z.mv Gi Z.vs) Ji hpp hidx hSi hal hdp hr hk hn hq1 hq2 hvm hqa hDLi + end @@ -541,45 +625,65 @@ set_option maxHeartbeats 8000000 in `insert_subframesJ`, the destination's CNode live by `subframe_dest_live`): an error with the states unchanged, or the spec's single invocation after the restart, its single outcome at `JAtZ`. -/ -theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64} {Lst : U64 → List U64} - {D : Set U64} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) +theorem derive_subframeQ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) - {ptr rt fa fv : U64} {sz : capability.FrameSize} {dev mm : Bool} - (hcap : capAt (L.mem s) (cslotAddr (pp.bv, idx)) = ok (.Frame ptr sz rt dev mm false fa fv)) + {ptr rt fa fv : U64} {sz : capability.FrameSize} {dev mm ep : Bool} + (hcap : capAt (L.mem s) (cslotAddr (pp.bv, idx)) = ok (.Frame ptr sz rt dev mm ep fa fv)) (hno : sz = .Large → dev = false → ∀ x ∈ Z.G.chains.flatten, physF (capV (L.mem s) x) = true → - Disj (capV (L.mem s) x) (.Frame ptr sz rt dev mm false fa fv) ∨ + Disj (capV (L.mem s) x) (.Frame ptr sz rt dev mm ep fa fv) ∨ (isFrame (capV (L.mem s) x) = true ∧ revOf (L.mem s) x = false) ∨ - Within (.Frame ptr sz rt dev mm false fa fv) (capV (L.mem s) x)) + Within (.Frame ptr sz rt dev mm ep fa fv) (capV (L.mem s) x)) (hVC : VsCapsW Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s) Z.G) (ct : U64) (hct : sched.cur_thread st s = ok ct) (length buf : U64) (args : List U64) (hlen : length.val = args.length) (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) (ex : Array obj.Slot 3#usize) {y : obj.Slot} (hex0 : vspace.extra ex 0#usize = ok (some y)) (hy : IsSlot Z.th y) {nc : capability.Cap} (hcy : capAt (L.mem s) y = ok nc) {nc' : Fl4Spec.Cap} (hnr : CapRel nc nc') - (hnv : CapValid Z.th nc) (nsl : Fl4Spec.CslotPtr) (rest : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) : - vspace.derive_subframe st arI s a length (cslotAddr (pp.bv, idx)) (.Frame ptr sz rt dev mm false fa fv) buf ex ⦃ res => + (hnv : CapValid Z.th nc) (nsl : Fl4Spec.CslotPtr) (rest : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) + {Q : MdbGhost → S → Fl4Spec.State Unit → Prop} + (hRestart : ∃ s1 σ1, Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + sched.set_thread_state st s ct sched.TS_RESTART = ok s1 ∧ Q Z.G s1 σ1) + (hBase : ∀ {s1 σ1 G1}, Q G1 s1 σ1 → ∃ Ac1 Lst1 D1, + JAtZB (L := L) arI AR (Z.mv G1 Z.vs) H Cs Ac1 Lst1 D1 s1 a σ1) + (hAlias : ∀ {s1 σ1}, + Q Z.G s1 σ1 → + SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) + (.Frame ptr .Large rt false mm ep fa fv) (revOf (L.mem s) (cslotAddr (pp.bv, idx))) s1 a σ1 Z.G → + ptr.val % 2 ^ 21 = 0 → + ∀ {dp : U64} {r : Nat}, Z.th dp = some (.cnode r) → r < 64 → + ∀ {first count base vm : U64}, first.val + count.val ≤ 2 ^ r → ptr.val ≤ base.val → + base.val + count.val * 4096 ≤ ptr.val + 2 ^ 21 → (1 ≤ vm.val ∧ vm.val ≤ 3) → + base.val % 4096 = 0 → + (∀ j : Nat, first.val ≤ j → j < first.val + count.val → + capAt (L.mem s1) (slotAddr dp.bv (BitVec.ofNat 64 j)) = ok .Null) → + DestCap Z.th (L.mem s1) dp → + vspace.insert_subframes st s1 (cslotAddr (pp.bv, idx)) dp first base count vm ⦃ s' => ∃ σ' G', + Fl4Spec.NonDet.mapMx (subIns (pp.bv, idx) base.bv (vmRightsOf vm)) (subList dp r first.val count.val) σ1 = + ({((), σ')}, False) ∧ Q G' s' σ' ⦄) : + vspace.derive_subframe st arI s a length (cslotAddr (pp.bv, idx)) (.Frame ptr sz rt dev mm ep fa fv) buf ex ⦃ res => (∃ e e', res.1 = .Err e ∧ SysErrRel e e' ∧ ExceptT.run (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pp.bv, idx) - (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) + (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then (if ep then .vmEptMap else .vmVSpaceMap) else .vmNoMap) (frameSizeOf sz) (if mm then some (fa.bv, fv.bv) else none)) ((nc', nsl) :: rest)) σ = ({(.error e', σ)}, False) ∧ res.2.1 = s ∧ res.2.2 = a) ∨ (res.1 = .Ok () ∧ res.2.2 = a ∧ ∃ iv, ExceptT.run (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pp.bv, idx) - (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) + (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then (if ep then .vmEptMap else .vmVSpaceMap) else .vmNoMap) (frameSizeOf sz) (if mm then some (fa.bv, fv.bv) else none)) ((nc', nsl) :: rest)) σ = ({(.ok iv, σ)}, False) ∧ ∃ σ', (Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart >>= fun _ => Fl4Spec.performDeriveSubframe iv) σ = ({((), σ')}, False) ∧ - ∃ (G' : MdbGhost) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), - JAtZ (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac' Lst' D' res.2.1 a σ') ⦄ := by + ∃ G', Q G' res.2.1 σ') ⦄ := by have hX := J.xtop obtain ⟨hPl, ⟨hSt, hSV, hM, hC, hI⟩, hFI, -, hMO, -, -⟩ := hX.rel have hU : UtInv (L.mem s) Z.G := J.ut have hFR : Vs.FrameInv (L.mem s) Z.G := hMO.1.1 - obtain ⟨hcur, htcb⟩ := J.ctTcb arI hct + have htcb := (J.xtop.curTcb (J.curEq hct).1).1 have hact := J.kern.act - obtain ⟨s1, σ1, x1, -, hst1, -, -, -, -, -, -, hs1, Ac1, Lst1, D1, J1⟩ := J.restartJ hni hct + obtain ⟨s1, σ1, hst1, hs1, hQ1⟩ := hRestart + obtain ⟨_, _, _, J1⟩ := hBase hQ1 generalize hD : ExceptT.run (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pp.bv, idx) - (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) + (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then (if ep then .vmEptMap else .vmVSpaceMap) else .vmNoMap) (frameSizeOf sz) (if mm then some (fa.bv, fv.bv) else none)) ((nc', nsl) :: rest)) σ = DD obtain ⟨cS, aS, hcS, hcaS, -⟩ := hSt.slot_cap (Z := Unit) (sl := (pp.bv, idx)) (p := pp) rfl (by simpa [hidx] using hpp) @@ -597,7 +701,7 @@ theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64 exact decodeSub_trunc (Or.inr (by rw [List.length_map, ← hlen]; scalar_tac)) _ _ σ rw [if_pos hl6] have hill : (∀ p r mt mp, (Fl4Spec.ArchCap.pageCap dev ptr.bv (vmRightsOf rt) - (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) (if mm then some (fa.bv, fv.bv) else none)) ≠ + (if mm then (if ep then .vmEptMap else .vmVSpaceMap) else .vmNoMap) (frameSizeOf sz) (if mm then some (fa.bv, fv.bv) else none)) ≠ .pageCap false p r mt .x64LargePage mp) → DD = ({(.error .illegalOperation, σ)}, False) := fun h => by rw [← hD]; exact decodeSub_illegal (by simp) (by rw [List.length_map, ← hlen]; scalar_tac) _ h σ cases sz <;> cases dev @@ -719,7 +823,7 @@ theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64 have hAs : AbsSlot Z.th (pp.bv, idx) := ⟨pp, rfl, Or.inl (by simpa [hidx] using hpp)⟩ have hs : IsSlot Z.th (cslotAddr (pp.bv, idx)) := hAs.isSlot have hSub1 : SubRel st Z.th Z.P Z.L4 Z.L3 Z.L2 Z.L1 (subSRJ st Z AR) (cslotAddr (pp.bv, idx)) - (.Frame ptr .Large rt false mm false fa fv) (revOf (L.mem s) (cslotAddr (pp.bv, idx))) s1 a σ1 Z.G := + (.Frame ptr .Large rt false mm ep fa fv) (revOf (L.mem s) (cslotAddr (pp.bv, idx))) s1 a σ1 Z.G := { R := hSt1, V := hSV1, M := hM1, C := hC1, I := hI1, U := UtInv.of_same hM hU hSS vs := J1.xtop.fin.2.1, pt := J1.xtop.fin.2.2.1, sr := J1.xtop.fin.1 cap := by rw [hSS.capAt hs]; exact hcap, rev := hSS.revOf hs @@ -730,7 +834,7 @@ theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64 fr := fun w hw q vm h1 h2 hov => by have hws := ((hM.members w).1 hw).1 rw [hSS.capV hws] at hov ⊢ - rw [(frame_range ptr .Large rt false mm fa fv false).1] at h1 h2 + rw [(frame_range ptr .Large rt false mm fa fv ep).1] at h1 h2 exact hfr0' w hw q vm h1 h2 hov FR := hFR.of_caps (fun z hz => hSS.capV ((hM.members z).1 hz).1) VC := hVC.of_caps (fun z hz => hSS.capV ((hM.members z).1 hz).1) } @@ -740,11 +844,11 @@ theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64 calc a4.val * 4096 ≤ (2 ^ 21 - a3.val) / 4096 * 4096 := Nat.mul_le_mul_right 4096 (by rw [← hmxv]; exact hc2') _ ≤ 2 ^ 21 - a3.val := Nat.div_mul_le_self _ _ - refine WP.spec_bind (insert_subframesJ (L := L) J1 hpp hidx hSub1 hal' hdp hr64 hfc (by rw [hbv]; omega) + refine WP.spec_bind (hAlias hQ1 hSub1 hal' hdp hr64 hfc (by rw [hbv]; omega) (by rw [hbv]; omega) ⟨hm1, hm3⟩ (by rw [hbv]; omega) (fun j h1 h2 => by rw [hSS.capAt ⟨dest, j, Or.inl ⟨rr, hdp, by omega⟩, rfl⟩]; exact hemp j h1 h2) (hDL.same hSS)) ?_ - rintro s2 ⟨σ', G', hmap, -, -, -, Ac2, Lst2, D2, J2⟩ + rintro s2 ⟨σ', G', hmap, hQ2⟩ have hbase : (core.num.U64.wrapping_add ptr a3).bv = ptr.bv + a3.bv := core.num.U64.wrapping_add_bv_eq _ _ have hrights : vmRightsOf m = Fl4Spec.maskVmRights (vmRightsOf rt) (Fl4Spec.dataToRights a5.bv) := by rw [hmv, rightsW_spec]; rfl @@ -761,7 +865,50 @@ theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64 (List.range' a2.val a4.val).map fun i => (dest.bv, Fl4Spec.natToCref rr i)⟩) σ = ({((), σ')}, False) := by rw [Fl4Proofs.P3.nd_bind_one hst1, hperf]; exact hmap - exact (WP.spec_ok _).2 (Or.inr ⟨rfl, rfl, _, hE, σ', hrun2, G', Ac2, Lst2, D2, J2⟩) + exact (WP.spec_ok _).2 (Or.inr ⟨rfl, rfl, _, hE, σ', hrun2, G', hQ2⟩) + +/-- Derive a subframe from a native frame. -/ +theorem derive_subframeJ {s : S} {a : A} {σ : Fl4Spec.State Unit} {Ac : Set U64} {Lst : U64 → List U64} + {D : Set U64} (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) (hni : Entered σ) + {pp : U64} {rs : Nat} (hpp : Z.th pp = some (.cnode rs)) {idx : List Bool} (hidx : idx.length = rs) + {ptr rt fa fv : U64} {sz : capability.FrameSize} {dev mm : Bool} + (hcap : capAt (L.mem s) (cslotAddr (pp.bv, idx)) = ok (.Frame ptr sz rt dev mm false fa fv)) + (hno : sz = .Large → dev = false → ∀ x ∈ Z.G.chains.flatten, physF (capV (L.mem s) x) = true → + Disj (capV (L.mem s) x) (.Frame ptr sz rt dev mm false fa fv) ∨ + (isFrame (capV (L.mem s) x) = true ∧ revOf (L.mem s) x = false) ∨ + Within (.Frame ptr sz rt dev mm false fa fv) (capV (L.mem s) x)) + (hVC : VsCapsW Z.P Z.L4 Z.L3 Z.L2 Z.L1 (L.mem s) Z.G) + (ct : U64) (hct : sched.cur_thread st s = ok ct) + (length buf : U64) (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s ct buf i = ok x) + (ex : Array obj.Slot 3#usize) {y : obj.Slot} (hex0 : vspace.extra ex 0#usize = ok (some y)) (hy : IsSlot Z.th y) + {nc : capability.Cap} (hcy : capAt (L.mem s) y = ok nc) {nc' : Fl4Spec.Cap} (hnr : CapRel nc nc') + (hnv : CapValid Z.th nc) (nsl : Fl4Spec.CslotPtr) (rest : List (Fl4Spec.Cap × Fl4Spec.CslotPtr)) : + vspace.derive_subframe st arI s a length (cslotAddr (pp.bv, idx)) (.Frame ptr sz rt dev mm false fa fv) buf ex ⦃ res => + (∃ e e', res.1 = .Err e ∧ SysErrRel e e' ∧ + ExceptT.run (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pp.bv, idx) + (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) + (if mm then some (fa.bv, fv.bv) else none)) ((nc', nsl) :: rest)) σ = ({(.error e', σ)}, False) ∧ + res.2.1 = s ∧ res.2.2 = a) ∨ + (res.1 = .Ok () ∧ res.2.2 = a ∧ ∃ iv, + ExceptT.run (Fl4Spec.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) (pp.bv, idx) + (.pageCap dev ptr.bv (vmRightsOf rt) (if mm then .vmVSpaceMap else .vmNoMap) (frameSizeOf sz) + (if mm then some (fa.bv, fv.bv) else none)) ((nc', nsl) :: rest)) σ = ({(.ok iv, σ)}, False) ∧ + ∃ σ', (Fl4Spec.setThreadState (Z := Unit) σ.curThread .restart >>= fun _ => + Fl4Spec.performDeriveSubframe iv) σ = ({((), σ')}, False) ∧ + ∃ (G' : MdbGhost) (Ac' : Set U64) (Lst' : U64 → List U64) (D' : Set U64), + JAtZ (L := L) arI AR (Z.mv G' Z.vs) H Cs Ac' Lst' D' res.2.1 a σ') ⦄ := by + let Q := fun G s' σ' => ∃ Ac' Lst' D', JAtZ (L := L) arI AR (Z.mv G Z.vs) H Cs Ac' Lst' D' s' a σ' + obtain ⟨s1, σ1, -, -, hst1, -, -, -, -, -, -, hs1, Ac1, Lst1, D1, J1⟩ := J.restartJ hni hct + refine derive_subframeQ arI J.toB hpp hidx hcap hno hVC ct hct length buf args hlen hargs ex hex0 hy hcy hnr hnv + nsl rest (Q := Q) ⟨s1, σ1, hst1, hs1, Ac1, Lst1, D1, J1⟩ ?_ ?_ + · rintro _ _ _ ⟨Aci, Lsti, Di, Ji⟩ + exact ⟨Aci, Lsti, Di, Ji.toB⟩ + · rintro _ _ ⟨Aci, Lsti, Di, Ji⟩ hS hal dp r hdp hr first count base vm hfc hb1 hb2 hvm hbal hemp hDL + refine WP.spec_mono (insert_subframesJ (Z := Z) Ji hpp hidx hS hal hdp hr hfc hb1 hb2 hvm hbal hemp hDL) ?_ + rintro s' ⟨σ', G', hmap, -, -, -, hQ⟩ + exact ⟨σ', G', hmap, hQ⟩ + end diff --git a/proofs/Fl4Proofs/P3/XTopJointXferB.lean b/proofs/Fl4Proofs/P3/XTopJointXferB.lean index 7c4e8c87c..41dd76741 100644 --- a/proofs/Fl4Proofs/P3/XTopJointXferB.lean +++ b/proofs/Fl4Proofs/P3/XTopJointXferB.lean @@ -25,6 +25,11 @@ blocked but in no queue, so no `JAtZ` state), and the way back to `JAtZ`. the words of `Ω`, `xfer_all`'s `UserOK` for the others), split by `mixS`. * `xferStepJ`: the transfer step of the send-to-receiver lemmas, uniform in the receive buffer (no cap transferred: `XferNoCap`). + +(mmuAD gen 42b67, option (b) step b3) `bufWrites`, `bufRebase`, `bufRebaseX` stated over `JAtZB` in place, each post +with the native footprint of the buffer words (`NatFoot` from the start to the virtual state, P3/NatFoot; every word +by XTopJointData's `JAtZB.userWrN`, composed by `JAtZB.natTrans`); the `JAtZ` names are one-line corollaries +(`JAtZ.toB`, `JAtZB.toJN`), statements unchanged. No named premise. -/ import Fl4Proofs.P3.XTopJointIpcJ import Fl4Proofs.P3.BufJ @@ -702,51 +707,68 @@ theorem do_ipc_transfer_bufE {T E R : Set U64} {B : Set (U64 × Fl4Spec.Word)} set_option maxHeartbeats 16000000 in /-- The receiver's buffer words of a list written at `J` with the values of -`t`, each by `JAtZ.userWrJ` (the spec changing only user memory). -/ -theorem JAtZ.bufWrites {d : U64} (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) +`t`, each by `JAtZB.userWrJ` (the spec changing only user memory); (mmuAD gen 42b67) over `JAtZB` in place, each +word's step native (`JAtZB.userWrN`), composed into `NatFoot`. -/ +theorem JAtZB.bufWrites {d : U64} (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) {rp : Fl4Spec.ObjRef} (hrp : Endp.ipcBufOf true xd = some rp) (t : S) : ∀ (l : List U64), (∀ b ∈ l, RBufW ⟨rp⟩ b) → ∀ (s0 : S) (um : Fl4Spec.Word → Fl4Spec.Word8), - JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a (Endp.setUm σ um) → - ∃ um', JAtZ (L := L) arI AR Z H Cs Ac Lst D (mixS (L := L) s0 t l) a (Endp.setUm σ um') := by + JAtZB (L := L) arI AR Z H Cs Ac Lst D s0 a (Endp.setUm σ um) → + ∃ um', JAtZB (L := L) arI AR Z H Cs Ac Lst D (mixS (L := L) s0 t l) a (Endp.setUm σ um') ∧ + NatFoot (L := L) Z s0 (Endp.setUm σ um) (mixS (L := L) s0 t l) (Endp.setUm σ um') := by intro l induction l with - | nil => intro _ s0 um J0; exact ⟨um, J0⟩ + | nil => intro _ s0 um J0; exact ⟨um, J0, NatFoot.refl _ _ _⟩ | cons b l ih => intro hl s0 um J0 obtain ⟨i, hi, rfl⟩ := hl _ (List.mem_cons_self ..) obtain ⟨hOK, hBC, hBP⟩ := J0.xferH have hkd' : (Endp.setUm σ um).kheap d.bv = some (.tcb xd) := hkd have hwB : (Endp.fl4BufA ⟨rp⟩ i, Endp.bufAddr rp i.val) ∈ Z.B := hBC d hdT xd true rp hkd' hrp ⟨rp⟩ rfl i hi - obtain ⟨hAp, hObj⟩ := J0.bufWord hOK hdth hkd' hrp i.val hi (b := Endp.fl4BufA ⟨rp⟩ i) (by rw [fl4BufA_bv]) + obtain ⟨hAp, hObj⟩ := J0.bufWordG hOK hdth hkd' hrp i.val hi (b := Endp.fl4BufA ⟨rp⟩ i) (by rw [fl4BufA_bv]) have J1 := J0.userWrJ hBP hwB hAp hObj (L.mem t (Endp.fl4BufA ⟨rp⟩ i)) - exact ih (fun x hx => hl x (List.mem_cons_of_mem _ hx)) _ _ J1 + have F1 := J0.userWrN hBP hwB hAp (L.mem t (Endp.fl4BufA ⟨rp⟩ i)) + obtain ⟨um', J2, F2⟩ := ih (fun x hx => hl x (List.mem_cons_of_mem _ hx)) _ _ J1 + exact ⟨um', J2, J0.natTrans F1 F2⟩ + +/-- `JAtZB.bufWrites` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.bufWrites {d : U64} (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) + {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) {rp : Fl4Spec.ObjRef} + (hrp : Endp.ipcBufOf true xd = some rp) (t : S) : + ∀ (l : List U64), (∀ b ∈ l, RBufW ⟨rp⟩ b) → ∀ (s0 : S) (um : Fl4Spec.Word → Fl4Spec.Word8), + JAtZ (L := L) arI AR Z H Cs Ac Lst D s0 a (Endp.setUm σ um) → + ∃ um', JAtZ (L := L) arI AR Z H Cs Ac Lst D (mixS (L := L) s0 t l) a (Endp.setUm σ um') := + fun l hl s0 um J0 => + match JAtZB.bufWrites hdT hdth hkd hrp t l hl s0 um J0.toB with + | ⟨um', B', F⟩ => ⟨um', B'.toJN J0 F⟩ set_option maxHeartbeats 16000000 in /-- **Back to `JAtZ` across the receiver's buffer words** (module docstring): from `J` at `s` and a state `s'` written from `s` in `CnW` (and `KW`) and the buffer words, `JAtZ` at `mixS s s'` (the buffer words of `s'` written at `J`, `JAtZ.bufWrites`) with the spec's user memory changed, from -which `s'` writes only in `CnW` and `KW`. -/ -theorem JAtZ.bufRebase (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} +which `s'` writes only in `CnW` and `KW`. (mmuAD gen 42b67) Over `JAtZB` in place, with the native footprint of +the buffer words (`NatFoot` from `(s, σ)` to the virtual state). -/ +theorem JAtZB.bufRebase (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) {rp : Fl4Spec.ObjRef} (hrp : Endp.ipcBufOf true xd = some rp) {s' : S} (hw : P1.WritesIn st s s' (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RBufW ⟨rp⟩ b)) (hfoot : P1.WritesIn st s s' (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s b ∨ RBufW ⟨rp⟩ b)) : - ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZ (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ + ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZB (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ P1.WritesIn st su s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c su (Endp.setUm σ um)) ∧ P1.WritesIn st su s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) su) ∧ - L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RBufW ⟨rp⟩ b → L.mem su b = L.mem s b) := by + L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RBufW ⟨rp⟩ b → L.mem su b = L.mem s b) ∧ + NatFoot (L := L) Z s σ su (Endp.setUm σ um) := by obtain ⟨-, hBC, -⟩ := J.xferH have hal : ∀ b ∈ rbList ⟨rp⟩, P1.Aligned b := fun b hb => by obtain ⟨i, hi, rfl⟩ := mem_rbList.1 hb exact (J.xtop.fin.1.2.ep.balign _ (hBC d hdT xd true rp hkd hrp ⟨rp⟩ rfl i hi)).1 - obtain ⟨um, Ju⟩ := JAtZ.bufWrites hdT hdth hkd hrp s' (rbList ⟨rp⟩) (fun b hb => mem_rbList.1 hb) s + obtain ⟨um, Ju, Fu⟩ := JAtZB.bufWrites hdT hdth hkd hrp s' (rbList ⟨rp⟩) (fun b hb => mem_rbList.1 hb) s σ.machineState.underlyingMemory J have hks : L.ksb (mixS (L := L) s s' (rbList ⟨rp⟩)) = L.ksb s := mixS_ksb _ _ _ - refine ⟨_, um, Ju, ?_, ?_, hks, fun b hb hn => ?_⟩ + refine ⟨_, um, Ju, ?_, ?_, hks, fun b hb hn => ?_, Fu⟩ · refine (mixS_writes hal (hw.mono fun b hb => hb.imp_right mem_rbList.2)).mono fun b hb => ?_ exact cnW_back (s := mixS (L := L) s s' (rbList ⟨rp⟩)) (s' := s) (σ := Endp.setUm σ um) (σ' := σ) hks.symm (fun sc _ x n hk => ⟨x, hk⟩) hb @@ -756,6 +778,20 @@ theorem JAtZ.bufRebase (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U6 simp only [e]; exact hb · rw [mixS_mem s s' _ hal hb, if_neg (fun h => hn (mem_rbList.1 h))] +/-- `JAtZB.bufRebase` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.bufRebase (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} + (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) + {rp : Fl4Spec.ObjRef} (hrp : Endp.ipcBufOf true xd = some rp) {s' : S} + (hw : P1.WritesIn st s s' (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RBufW ⟨rp⟩ b)) + (hfoot : P1.WritesIn st s s' (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) s b ∨ RBufW ⟨rp⟩ b)) : + ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZ (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ + P1.WritesIn st su s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c su (Endp.setUm σ um)) ∧ + P1.WritesIn st su s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) + (P1.EH H) su) ∧ + L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RBufW ⟨rp⟩ b → L.mem su b = L.mem s b) := + match J.toB.bufRebase hdT hdth hkd hrp hw hfoot with + | ⟨su, um, Ju, h1, h2, h3, h4, F⟩ => ⟨su, um, Ju.toJN J F, h1, h2, h3, h4⟩ /-! ## The uniform transfer step -/ @@ -769,26 +805,41 @@ def XferNoCap (g : Bool) (xs xd : Fl4Spec.Tcb) : Prop := theorem setUm_self (σ0 : Fl4Spec.State Unit) : Endp.setUm σ0 σ0.machineState.underlyingMemory = σ0 := rfl set_option maxHeartbeats 8000000 in -/-- `JAtZ.bufRebase` for the receiver's buffer words, none or some. -/ -theorem JAtZ.bufRebaseX (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} +/-- `JAtZB.bufRebase` for the receiver's buffer words, none or some ((mmuAD gen 42b67) over `JAtZB` in place, with +`NatFoot` to the virtual state). -/ +theorem JAtZB.bufRebaseX (J : JAtZB (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) {s' : S} (hw : P1.WritesIn st s s' (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b)) (hfoot : P1.WritesIn st s s' (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) (P1.EH H) s b ∨ RcvBufW xd b)) : - ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZ (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ + ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZB (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ P1.WritesIn st su s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c su (Endp.setUm σ um)) ∧ P1.WritesIn st su s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) - (P1.EH H) su) ∧ L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RcvBufW xd b → L.mem su b = L.mem s b) := by + (P1.EH H) su) ∧ L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RcvBufW xd b → L.mem su b = L.mem s b) ∧ + NatFoot (L := L) Z s σ su (Endp.setUm σ um) := by cases hrp : Endp.ipcBufOf true xd with | none => have hn : ∀ b, ¬ RcvBufW xd b := fun b ⟨rp, h, _⟩ => by rw [hrp] at h; cases h exact ⟨s, σ.machineState.underlyingMemory, J, hw.mono fun b hb => hb.resolve_right (hn b), - hfoot.mono fun b hb => hb.resolve_right (hn b), rfl, fun _ _ _ => rfl⟩ + hfoot.mono fun b hb => hb.resolve_right (hn b), rfl, fun _ _ _ => rfl, NatFoot.refl _ _ _⟩ | some rp => have hc : ∀ b, RcvBufW xd b → RBufW ⟨rp⟩ b := fun b ⟨rp', h, hb⟩ => by rw [hrp] at h; cases h; exact hb - obtain ⟨su, um, Ju, h1, h2, h3, h4⟩ := J.bufRebase hdT hdth hkd hrp + obtain ⟨su, um, Ju, h1, h2, h3, h4, F⟩ := J.bufRebase hdT hdth hkd hrp (hw.mono fun b hb => hb.imp_right (hc b)) (hfoot.mono fun b hb => hb.imp_right (hc b)) - exact ⟨su, um, Ju, h1, h2, h3, fun b hb hn => h4 b hb fun h => hn ⟨rp, hrp, h⟩⟩ + exact ⟨su, um, Ju, h1, h2, h3, fun b hb hn => h4 b hb fun h => hn ⟨rp, hrp, h⟩, F⟩ + +/-- `JAtZB.bufRebaseX` at `JAtZ` (via `JAtZ.toB`, `JAtZB.toJN`). -/ +theorem JAtZ.bufRebaseX (J : JAtZ (L := L) arI AR Z H Cs Ac Lst D s a σ) {d : U64} + (hdT : d ∈ Z.T) (hdth : Z.th d = some .tcb) {xd : Fl4Spec.Tcb} (hkd : σ.kheap d.bv = some (.tcb xd)) {s' : S} + (hw : P1.WritesIn st s s' (fun b => CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c s σ b ∨ RcvBufW xd b)) + (hfoot : P1.WritesIn st s s' (fun b => P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) + (P1.Heap.scBits H) (P1.EH H) s b ∨ RcvBufW xd b)) : + ∃ (su : S) (um : Fl4Spec.Word → Fl4Spec.Word8), JAtZ (L := L) arI AR Z H Cs Ac Lst D su a (Endp.setUm σ um) ∧ + P1.WritesIn st su s' (CnW (st := st) Z.T Z.N Z.C Z.E Z.R Z.c su (Endp.setUm σ um)) ∧ + P1.WritesIn st su s' (P1.KW st (P1.Heap.tcbs H) Cs (P1.Heap.frame H) (P1.Heap.scs H) (P1.Heap.scBits H) + (P1.EH H) su) ∧ L.ksb su = L.ksb s ∧ (∀ b, P1.Aligned b → ¬ RcvBufW xd b → L.mem su b = L.mem s b) := + match J.toB.bufRebaseX hdT hdth hkd hw hfoot with + | ⟨su, um, Ju, h1, h2, h3, h4, F⟩ => ⟨su, um, Ju.toJN J F, h1, h2, h3, h4⟩ set_option maxHeartbeats 16000000 in /-- **The transfer step of `send_ipc` to a waiting receiver, with or without diff --git a/proofs/Fl4Proofs/P3/XTopJointXferF.lean b/proofs/Fl4Proofs/P3/XTopJointXferF.lean index 5f42ddd98..dcfb9f980 100644 --- a/proofs/Fl4Proofs/P3/XTopJointXferF.lean +++ b/proofs/Fl4Proofs/P3/XTopJointXferF.lean @@ -1,449 +1 @@ -/- -P3 (DESIGN.md §9), IPC: **the fault transfer of any fault but a timeout with -an SC** (toward XTopJointRecvIpcLink's `JRecvSendHyp`, KENTRY-PLAN.md item 6 -(d4'); l4v `do_fault_transfer`): XTopJointFaultRecv's `xferFaultStepJ` for -every fault EpFaultNone/EpFaultMore relate (`FaultOK`). - -* `FW`, `set_mr_rgW`, `set_mrs_lookup_failure_rgW`, `copy_mrs_fault_rgW`, - `set_mrs_fault_rgW`, `do_ipc_transfer_fault_rgW`: FL4's footprint of the - fault transfer, uniform in the fault type and in the receive buffer - (`FW T rw W`: `W` holds the receiver's registers and, for a buffer - `rw ≠ 0`, its buffer words), a timeout only without an SC. -* `makeFaultMsg_pure`: the spec's fault message leaves the state unchanged - (a timeout without an SC); `doIpcTransfer_faultN_eq`, - `doIpcTransfer_faultB_eq`: the spec's outcome `updK (setUm σ um) rcv x'`. -* `xferFaultStepGJ`: `xferFaultStepJ` for a fault `f` with `FaultOK`. --/ import Fl4Proofs.P3.XTopJointFaultRecv -import Fl4Proofs.P3.EpFaultUs -open Aeneas Aeneas.Std Result - -namespace Fl4Proofs.P3 -open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc - Fl4Proofs.P3.Sched - -noncomputable section - -/-- A footprint `W` holding the receiver's registers and, for a receive -buffer `rw ≠ 0`, its (aligned) buffer words. -/ -def FW (T : Set U64) (rw : U64) (W : U64 → Prop) : Prop := - (∀ b, XferRegW T ∅ b → W b) ∧ - (rw ≠ 0#u64 → (∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) ∧ ∀ b, RBufW rw b → W b) - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} - -theorem set_mr_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw i v : U64} (hr : rcv ∈ T) - {W : U64 → Prop} (hW : FW T rw W) (hi : i.val < 127) (h : P1.WritesIn st s0 s W) : - msg.set_mr st s rcv rw i v ⦃ r => P1.WritesIn st s0 r.2 W ⦄ := by - unfold msg.set_mr - split - · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ - refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ - simp only [lift, bind_ok, WP.spec_ok] - exact (h.trans w2).mono fun b hb => hb.elim id (hW.1 b) - · by_cases hb : (rw != 0#u64) = true - · have hrw0 : rw ≠ 0#u64 := by simpa using hb - obtain ⟨hal, hWb⟩ := hW.2 hrw0 - simp only [hb, ↓reduceIte, lift, bind_ok] - have hv : (core.num.U64.wrapping_add i 1#u64).val = i.val + 1 := wadd_val i 1 (by omega) _ rfl - refine WP.spec_bind (Endp.msg.buf_set.spec s rw _ v) ?_ - rintro s1 rfl - simp only [WP.spec_ok] - exact (h.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => hWb b ⟨_, by omega, hb'⟩)).mono - fun b hb' => hb'.elim id id - · simp only [hb, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] - exact h - -theorem set_mrs_lookup_failure_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw off : U64} - {lf : error.LookupFault} (hr : rcv ∈ T) {W : U64 → Prop} (hW : FW T rw W) (hoff : off.val ≤ 3) - (h : P1.WritesIn st s0 s W) : - faults.set_mrs_lookup_failure st s rcv rw lf off ⦃ r => P1.WritesIn st s0 r.2 W ⦄ := by - unfold faults.set_mrs_lookup_failure - refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ - refine WP.spec_bind (set_mr_rgW (v := i) (i := off) hT hr hW (by omega) h) ?_ - rintro ⟨i1, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - split - · exact (WP.spec_ok _).2 h1 - · try simp only [lift, bind_ok] - exact set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rgW hT hr hW (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2 - · try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - try simp only [lift, bind_ok] - exact set_mr_rgW hT hr hW (by rw [wadd_val off 3 (by omega) _ rfl]; omega) h3 - -theorem copy_mrs_fault_loop0_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {snd rcv : U64} - {sl : Slice U64} {i : Usize} (hr : rcv ∈ T) {W : U64 → Prop} (hW : ∀ b, XferRegW T ∅ b → W b) - (h : P1.WritesIn st s0 s W) : - faults.copy_mrs_fault_loop0 st s snd rcv sl i ⦃ r => P1.WritesIn st s0 r.1 W ⦄ := by - have hS : P0.StoreTotal st := L.total - unfold faults.copy_mrs_fault_loop0 - apply loop.spec_decr_nat (measure := fun y => sl.val.length - y.2.val) - (inv := fun y => P1.WritesIn st s0 y.1 W) - · rintro ⟨s1, j⟩ h1 - simp only at h1 - dsimp only - unfold faults.copy_mrs_fault_loop0.body - dsimp only - split - · rename_i hj - have hj' : j.val < sl.val.length := by simpa using hj - simp only [lift, bind_ok] - split - · refine WP.spec_bind (Slice.index_usize_spec sl j hj') fun rg _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s1 rg hS) fun v _ => ?_ - refine WP.spec_bind (msg.msg_register.lt _) fun i5 hi5 => ?_ - refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s1) hT hr hi5) fun s2 w2 => ?_ - step as ⟨j2, hj2⟩ - refine ⟨(h1.trans w2).mono fun b hb => hb.elim id (hW b), ?_⟩ - omega - · exact (WP.spec_ok _).2 h1 - · exact (WP.spec_ok _).2 h1 - · exact h - -theorem copy_mrs_fault_loop1_rgW {rw : U64} {W : U64 → Prop} - (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hWb : ∀ b, RBufW rw b → W b) - {s0 : S} {snd : U64} {sl : Slice U64} (hn : sl.val.length ≤ 120) (s : S) (i : Usize) - (h : P1.WritesIn st s0 s W) : - faults.copy_mrs_fault_loop1 st s snd sl rw i ⦃ s' => P1.WritesIn st s0 s' W ⦄ := by - have hS : P0.StoreTotal st := L.total - unfold faults.copy_mrs_fault_loop1 - apply loop.spec_decr_nat (measure := fun y => sl.val.length - y.2.val) - (inv := fun y => P1.WritesIn st s0 y.1 W) - · rintro ⟨s1, j⟩ h1 - simp only at h1 - dsimp only - unfold faults.copy_mrs_fault_loop1.body - dsimp only - split - · rename_i hj - have hj' : j.val < sl.val.length := by simpa using hj - refine WP.spec_bind (Slice.index_usize_spec sl j hj') fun rg _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s1 rg hS) fun v _ => ?_ - simp only [lift, bind_ok] - have h3v : (UScalar.cast .U64 j : U64).val = j.val := cast_us j (by omega) - have hi4 : (core.num.U64.wrapping_add (UScalar.cast .U64 j) 1#u64).val = j.val + 1 := by - rw [wadd_val _ 1 (by omega) _ rfl, h3v] - refine WP.spec_bind (Endp.msg.buf_set.spec s1 rw _ v) ?_ - rintro s2 rfl - step as ⟨j2, hj2⟩ - refine ⟨(h1.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => hWb b ⟨_, by omega, hb'⟩)).mono - fun b hb' => hb'.elim id id, ?_⟩ - omega - · exact (WP.spec_ok _).2 h1 - · exact h - -theorem copy_mrs_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {snd rcv rw : U64} - {sl : Slice U64} (hn : sl.val.length ≤ 120) (hr : rcv ∈ T) {W : U64 → Prop} (hW : FW T rw W) - (h : P1.WritesIn st s0 s W) : - faults.copy_mrs_fault st s snd rcv sl rw ⦃ s' => P1.WritesIn st s0 s' W ⦄ := by - unfold faults.copy_mrs_fault - refine WP.spec_bind (copy_mrs_fault_loop0_rgW (snd := snd) (sl := sl) (i := 0#usize) hT hr hW.1 h) ?_ - rintro ⟨s1, i⟩ h1 - simp only at h1 - by_cases hb : (rw != 0#u64) = true - · have hrw0 : rw ≠ 0#u64 := by simpa using hb - obtain ⟨hal, hWb⟩ := hW.2 hrw0 - simp only [hb, ↓reduceIte] - exact copy_mrs_fault_loop1_rgW hal hWb hn s1 i h1 - · simp only [hb, Bool.false_eq_true, ↓reduceIte] - show (ok s1) ⦃ _ ⦄ - exact (WP.spec_ok _).2 h1 - -/-- **`set_mrs_fault`'s footprint** (any fault type; a timeout only without -an SC): the receiver's registers and buffer words (`FW`). -/ -theorem set_mrs_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv rw : U64} (hr : rcv ∈ T) (s : S) (a : A) - {W : U64 → Prop} (hW : FW T rw W) - (hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64) : - faults.set_mrs_fault st arI s a snd rcv rw ⦃ r => P1.WritesIn st s r.2 W ⦄ := by - have hS : P0.StoreTotal st := L.total - have h0 : P1.WritesIn st s s W := P1.WritesIn.refl s _ - unfold faults.set_mrs_fault - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ty rfl - refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ - refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ - by_cases h1 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault - · rw [if_pos h1] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ - rintro ⟨_, s1⟩ h1' - simp only at h1' - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ - rintro ⟨_, s2⟩ h2 - simp only at h2 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2) ?_ - rintro ⟨_, s3⟩ h3 - simp only at h3 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ - exact set_mrs_lookup_failure_rgW hT hr hW (by decide) h3 - rw [if_neg h1] - by_cases h2 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.UnknownSyscall - · rw [if_pos h2] - unfold lift - apply ok_bind_spec - refine WP.spec_bind (copy_mrs_fault_rgW (snd := snd) hT (by rw [syscall_slice_length]; omega) hr hW h0) ?_ - rintro s2 h2' - exact set_mr_rgW hT hr hW (by decide) h2' - rw [if_neg h2] - by_cases h3 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.UserException - · rw [if_pos h3] - unfold lift - apply ok_bind_spec - have hel : (Array.to_slice faults.EXCEPTION_MESSAGE).val.length ≤ 120 := by - rw [exc_slice_val]; simp [Fl4Spec.exceptionMessage] - refine WP.spec_bind (copy_mrs_fault_rgW (snd := snd) hT hel hr hW h0) ?_ - rintro s2 h2' - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ - rintro ⟨_, s3⟩ h3' - simp only at h3' - try simp only [WP.uncurry'_pair] - exact set_mr_rgW hT hr hW (by decide) h3' - rw [if_neg h3] - by_cases h4 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout - · rw [if_pos h4] - refine WP.spec_bind (Fl4Proofs.P1.obj.Tcb.sc.spec s snd) ?_ - rintro i rfl - unfold obj.Sc.is_null - apply ok_bind_spec - simp only [hto h4, decide_true, ↓reduceIte] - exact set_mr_rgW hT hr hW (by decide) h0 - rw [if_neg h4] - by_cases h5 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.DebugException - · rw [if_pos h5] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ - rintro ⟨_, s1⟩ h1' - simp only at h1' - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ - rintro ⟨ret, s2⟩ h2' - simp only at h2' - try simp only [WP.uncurry'_pair] - split - · split - · refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ - rintro ⟨_, s3⟩ h3' - simp only at h3' - try simp only [WP.uncurry'_pair] - exact set_mr_rgW hT hr hW (by decide) h3' - · exact (WP.spec_ok _).2 h2' - · exact (WP.spec_ok _).2 h2' - rw [if_neg h5] - by_cases h6 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.VMFault - · rw [if_pos h6] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ - rintro ⟨_, s1⟩ h1' - simp only at h1' - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ - rintro ⟨_, s2⟩ h2' - simp only at h2' - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ - rintro ⟨_, s3⟩ h3' - simp only at h3' - try simp only [WP.uncurry'_pair] - exact set_mr_rgW hT hr hW (by decide) h3' - rw [if_neg h6] - exact (WP.spec_ok _).2 h0 - -/-- **`do_ipc_transfer`'s footprint, a faulted sender** (any fault, a -timeout only without an SC), for the receive buffer `rw` the lookup -returns: `FW T rw W`. -/ -theorem do_ipc_transfer_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) - (a : A) (ep badge : U64) (grant : Bool) {rw : U64} {W : U64 → Prop} (hW : FW T rw W) - (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = rw ⦄) - (hty : L.mem s (tFaultA snd) ≠ fl4_abi.consts.fault.NullFault) - (hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' W ⦄ := by - have hS : P0.StoreTotal st := L.total - unfold ipc.do_ipc_transfer - refine WP.spec_bind hb ?_ - rintro rb rfl - refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ - rintro ft rfl - rw [if_neg hty] - unfold ipc.do_fault_transfer - refine WP.spec_bind (set_mrs_fault_rgW (arI := arI) hT hr s a hW hto) ?_ - rintro ⟨sent, s1⟩ h1 - simp only at h1 - try simp only [WP.uncurry'_pair] - refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ - refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ - refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 W) ?_ - fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr - (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => (h3.trans w4).mono fun b hb => hb.elim id (hW.1 b) - unfold msg.set_msg_info - exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => - WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) - fun s4 w4 => (h1.trans w4).mono fun b hb => hb.elim id (hW.1 b) - -end - -section SpecF -open Fl4Spec - -/-- The spec's fault message of any fault but a timeout with an SC leaves -the state unchanged. -/ -theorem makeFaultMsg_pure {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) (f : Fault) - (hto : ∀ b, f = .timeout b → x.tcbSchedContext = none) : - ∃ label ms, makeFaultMsg (Z := Unit) f t σ = ({((label, ms), σ)}, False) := by - cases f with - | capFault c rp lf => exact ⟨_, _, makeFaultMsg_cap hk c rp lf⟩ - | unknownSyscallException n => exact ⟨_, _, makeFaultMsg_unknown hk n⟩ - | userException e c => exact ⟨_, _, makeFaultMsg_user hk e c⟩ - | timeout b => exact ⟨_, _, makeFaultMsg_timeout hk (hto b rfl) b⟩ - | archFault af => - cases af with - | vmFault va d => exact ⟨_, _, makeFaultMsg_vm hk va d⟩ - -end SpecF - -section -variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} - -set_option maxHeartbeats 16000000 in -/-- **The transfer step of a faulted sender to a receiver, with or without a -receive buffer** (XTopJointFaultRecv's `xferFaultStepJ` for any fault with -`FaultOK`): on `IRel` by EpFaultNone's `do_ipc_transfer_faultN` (no buffer) -or EpFaultMore's `do_ipc_transfer_fault` (a buffer), the spec's outcome by -`makeFaultMsg_pure` and `doFaultTransfer_eqN`/`doFaultTransfer_eq`, the -footprint by `do_ipc_transfer_fault_rgW`, P1's hole by `xfer_all` or -`blkX_bufw`. -/ -theorem xferFaultStepGJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} - {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP0 : Ipc.IPlaced N T E R B) (hP : EPlaced T E R B) - (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) - (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) - (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) - (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover T B σ) - {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} - (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {f : Fl4Spec.Fault} - (hf : xs.tcbFault = some f) (hok : FaultOK (L := L) s snd xs f) - (ep badge : U64) (grant : Bool) - {T1 Cs1 Ω Sg Rp Scs Nt Ac1 X : Set U64} {H1 : P1.Heap} {Zb : U64 → Nat} {Q : U64 → U64 → List U64} - {Rq : U64 → List U64} (hT1 : P1.TcbPlaced T1) (hr1 : rcv ∈ T1) - (h : P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s Q Rq) (hB : P1.BoundInv st T1 Ac1 s) - (hX : P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s) (hS : P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s) (hSg : P1.SgOK st Ω Sg s) - (hU : ∀ b, RcvBufW xr b → P1.OutsideObjs st T1 Cs1 s b ∧ - (∀ e, (H1 e = some .ep ∨ H1 e = some .ntfn) → b.val + 8 ≤ e.val ∨ e.val + 16 ≤ b.val) ∧ b ∉ Sg) : - ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => ∃ (x' : Fl4Spec.Tcb) - (um : Fl4Spec.Word → Fl4Spec.Word8), - Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - ({((), Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))}, False) ∧ x' = { xr with tcbArch := x'.tcbArch } ∧ - EpStateRel T E R B (L.mem s') (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ - (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' - (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ - Endp.IpcBufCapOK (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))) ∧ - Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ∧ - P1.WritesIn st s s' (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) ∧ - P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s' Q Rq ∧ P1.BoundInv st T1 Ac1 s' ∧ P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s' ∧ - P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s' ∧ P1.SgOK st Ω Sg s' ∧ - (∀ y ∈ T1, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → - L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) ⦄ := by - have hxs := hR.at_tcb hs hks - have hty : L.mem s (tFaultA snd) ≠ fl4_abi.consts.fault.NullFault := by - intro e - have := hxs.fault0.1 (by rw [e]; unfold fl4_abi.consts.fault.NullFault; rfl) - rw [hf] at this; cases this - have hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64 := by - intro e - obtain ⟨b, hb⟩ := hxs.faultT.1 (by rw [e]; unfold fl4_abi.consts.fault.Timeout; rfl) - rw [hf] at hb; cases hb - exact hok.2 - have htoS : ∀ b, f = .timeout b → xs.tcbSchedContext = none := by - intro b hb; subst hb; exact hok.1 - obtain ⟨label, ms, hmsg⟩ := makeFaultMsg_pure hks f htoS - obtain ⟨⟨⟨G, hBt⟩, hBw⟩, -⟩ := hSR.1.1 - have hlb := lookup_buf_full s σ hBt.2.1.1 hBt.2.1.2.1 (Ipc.RelTopB.tcbT hBt hkr) hkr hOK true - cases hrb : Endp.ipcBufOf true xr with - | none => - have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄ := WP.spec_mono hlb fun w hw => hw.1.2 hrb - have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv none σ := by - unfold Fl4Spec.doIpcTransfer - rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] - have hspec := hspec0.trans (doFaultTransfer_eqN hks hkr hf hmsg badge.bv) - have uu : ∀ (σ0 : Fl4Spec.State Unit) (p : Fl4Spec.ObjRef) (o o' : Fl4Spec.KernelObject), - Notif.updK (Notif.updK σ0 p o) p o' = Notif.updK σ0 p o' := fun _ _ _ _ => by - simp only [Notif.updK, Function.update_idem] - simp only [mrStateN, uu] at hspec - have hW : FW T1 0#u64 (XferRegW T1 ∅) := ⟨fun _ h => h, fun h => absurd rfl h⟩ - refine WP.spec_mono (WP.spec_and (do_ipc_transfer_faultN (ar := arI) (epHyps_buf hHE) - (epBufHyps_buf (st := st) (th := th) (cr := cr) (N := N) (T := T) (C := C) (E := E) (R := R) (B := B) (c := c)) - hP s a σ hR ⟨hSR.1, hOK⟩ hs hr hne hks hkr hf hok hrb ep badge grant) - (do_ipc_transfer_fault_rgW (arI := arI) hT1 hr1 s a ep badge grant hW hlk hty hto)) ?_ - rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ - have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) - subst eσ - obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2, -⟩ := - P1.xfer_all h hB hX hS hSg (U := ∅) (fun b hb => absurd hb (Set.notMem_empty _)) - (w2.mono fun b hb => P1.XferRegW.foot hb) - exact ⟨_, σ.machineState.underlyingMemory, e2, rfl, hR2, hS2, hA2, w2.mono fun b hb => Or.inl hb, - h2, hB2, hX2, hS2', hSg2, f2⟩ - | some p => - obtain ⟨x0, hk0, hbw⟩ := hBw.bw rcv hr - rw [hkr] at hk0; cases hk0 - have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = ⟨p⟩ ⦄ := WP.spec_mono hlb fun w hw => by - have hwb : w.bv = p := hw.2 hbw p hrb - rw [← hwb] - have hrw0 : (⟨p⟩ : U64) ≠ 0#u64 := by - obtain ⟨w0, -, hw0⟩ := spec_exists hlb - have hwb : w0.bv = p := hw0.2 hbw p hrb - intro e - have : w0 = 0#u64 := by rw [← e, ← hwb] - rw [hw0.1.1 this] at hrb; cases hrb - have hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA ⟨p⟩ i) := fun i hi => - (hP.balign _ (hBC rcv hr xr true p hkr hrb ⟨p⟩ rfl i hi)).1 - have hBm := epBufMapHyps_bufC (st := st) (th := th) (cr := cr) (C := C) (c := c) hP0 - obtain ⟨rw1, -, hrw1, hmr⟩ := spec_exists (hBm.lookupMap s σ rcv xr true p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb) - have hu := hBm.frame s σ rcv xr p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb - have hal' : ∀ q ∈ mrPairs ms, (bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (bufAddr p q.1) σ := by - intro q hq - have := (List.of_mem_zip hq).1 - simp at this - exact ⟨bufAddr_aligned hP hmr _, hu _ (by omega)⟩ - have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = - Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv (some p) σ := by - unfold Fl4Spec.doIpcTransfer - rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] - have hspec := hspec0.trans (doFaultTransfer_eq hks hkr hf hmsg p hal' badge.bv) - have hW : FW T1 ⟨p⟩ (XferBW T1 ⟨p⟩) := ⟨fun _ h => Or.inl h, fun _ => ⟨hal, fun _ h => Or.inr h⟩⟩ - refine WP.spec_mono (WP.spec_and (Endp.do_ipc_transfer_fault (ar := arI) (epHyps_bufC hHE T) hBm hP s a σ hR - ⟨⟨hSR.1, hOK⟩, hBC⟩ hs hr hne hks hkr hf hok hrb ep badge grant) - (do_ipc_transfer_fault_rgW (arI := arI) hT1 hr1 s a ep badge grant hW hlk hty hto)) ?_ - rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ - have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) - simp only [mrState, updK_setUm_updK] at eσ - subst eσ - have hW' : P1.WritesIn st s s2 (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) := - w2.mono fun b hb => hb.imp_right fun h' => ⟨p, hrb, h'⟩ - obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2⟩ := blkX_bufw (l := rbList ⟨p⟩) h hB hX hS hSg - (fun b hb => hU b ⟨p, hrb, mem_rbList.1 hb⟩) (w2.mono fun b hb => hb.imp_right mem_rbList.2) - exact ⟨_, _, e2, rfl, hR2, hS2.1, hA2, hW', h2, hB2, hX2, hS2', hSg2, f2⟩ - -end - -end - -end Fl4Proofs.P3 diff --git a/proofs/Fl4Proofs/P3/XTopJointXferFCore.lean b/proofs/Fl4Proofs/P3/XTopJointXferFCore.lean new file mode 100644 index 000000000..078a5e414 --- /dev/null +++ b/proofs/Fl4Proofs/P3/XTopJointXferFCore.lean @@ -0,0 +1,455 @@ +/- +P3 (DESIGN.md §9), IPC: **the fault transfer of any fault but a timeout with +an SC** (toward XTopJointRecvIpcLink's `JRecvSendHyp`, KENTRY-PLAN.md item 6 +(d4'); l4v `do_fault_transfer`): XTopJointFaultRecv's `xferFaultStepJ` for +every fault EpFaultNone/EpFaultMore relate (`FaultOK`). + +* `FW`, `set_mr_rgW`, `set_mrs_lookup_failure_rgW`, `copy_mrs_fault_rgW`, + `set_mrs_fault_rgW`, `do_ipc_transfer_fault_rgW`: FL4's footprint of the + fault transfer, uniform in the fault type and in the receive buffer + (`FW T rw W`: `W` holds the receiver's registers and, for a buffer + `rw ≠ 0`, its buffer words), a timeout only without an SC. +* `makeFaultMsg_pure`: the spec's fault message leaves the state unchanged + (a timeout without an SC); `doIpcTransfer_faultN_eq`, + `doIpcTransfer_faultB_eq`: the spec's outcome `updK (setUm σ um) rcv x'`. +* `xferFaultStepGJ`: `xferFaultStepJ` for a fault `f` with `FaultOK`. +-/ +import Fl4Proofs.P3.XTopJointFaultRecvBase +import Fl4Proofs.P3.EpFaultUs +open Aeneas Aeneas.Std Result + +namespace Fl4Proofs.P3 +open fl4_core Classical Fl4Proofs.P3.Vs Fl4Proofs.P1 Fl4Proofs.P3.Notif Fl4Proofs.P3.Endp Fl4Proofs.P3.Ipc + Fl4Proofs.P3.Sched + +noncomputable section + +theorem Endp.faultOK_nt {S : Type} {st : machine.Store S} [L : LawfulStore st] (s : S) (snd : U64) (x : Fl4Spec.Tcb) + {f : Fl4Spec.Fault} (h : ∀ b, f ≠ .timeout b) : FaultOK (L := L) s snd x f := by + cases f with + | timeout b => exact absurd rfl (h b) + | _ => trivial + +/-- A footprint `W` holding the receiver's registers and, for a receive +buffer `rw ≠ 0`, its (aligned) buffer words. -/ +def FW (T : Set U64) (rw : U64) (W : U64 → Prop) : Prop := + (∀ b, XferRegW T ∅ b → W b) ∧ + (rw ≠ 0#u64 → (∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) ∧ ∀ b, RBufW rw b → W b) + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + +theorem set_mr_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw i v : U64} (hr : rcv ∈ T) + {W : U64 → Prop} (hW : FW T rw W) (hi : i.val < 127) (h : P1.WritesIn st s0 s W) : + msg.set_mr st s rcv rw i v ⦃ r => P1.WritesIn st s0 r.2 W ⦄ := by + unfold msg.set_mr + split + · refine WP.spec_bind (msg.msg_register.lt i) fun rg hrg => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s) hT hr hrg) fun s2 w2 => ?_ + simp only [lift, bind_ok, WP.spec_ok] + exact (h.trans w2).mono fun b hb => hb.elim id (hW.1 b) + · by_cases hb : (rw != 0#u64) = true + · have hrw0 : rw ≠ 0#u64 := by simpa using hb + obtain ⟨hal, hWb⟩ := hW.2 hrw0 + simp only [hb, ↓reduceIte, lift, bind_ok] + have hv : (core.num.U64.wrapping_add i 1#u64).val = i.val + 1 := wadd_val i 1 (by omega) _ rfl + refine WP.spec_bind (Endp.msg.buf_set.spec s rw _ v) ?_ + rintro s1 rfl + simp only [WP.spec_ok] + exact (h.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => hWb b ⟨_, by omega, hb'⟩)).mono + fun b hb' => hb'.elim id id + · simp only [hb, Bool.false_eq_true, ↓reduceIte, WP.spec_ok] + exact h + +theorem set_mrs_lookup_failure_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {rcv rw off : U64} + {lf : error.LookupFault} (hr : rcv ∈ T) {W : U64 → Prop} (hW : FW T rw W) (hoff : off.val ≤ 3) + (h : P1.WritesIn st s0 s W) : + faults.set_mrs_lookup_failure st s rcv rw lf off ⦃ r => P1.WritesIn st s0 r.2 W ⦄ := by + unfold faults.set_mrs_lookup_failure + refine WP.spec_bind (P0.error.LookupFault.type_code.p0 lf) fun i _ => ?_ + refine WP.spec_bind (set_mr_rgW (v := i) (i := off) hT hr hW (by omega) h) ?_ + rintro ⟨i1, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + split + · exact (WP.spec_ok _).2 h1 + · try simp only [lift, bind_ok] + exact set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rgW hT hr hW (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2 + · try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 1 (by omega) _ rfl]; omega) h1) ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + refine WP.spec_bind (set_mr_rgW hT hr hW (by rw [wadd_val off 2 (by omega) _ rfl]; omega) h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + try simp only [lift, bind_ok] + exact set_mr_rgW hT hr hW (by rw [wadd_val off 3 (by omega) _ rfl]; omega) h3 + +theorem copy_mrs_fault_loop0_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {snd rcv : U64} + {sl : Slice U64} {i : Usize} (hr : rcv ∈ T) {W : U64 → Prop} (hW : ∀ b, XferRegW T ∅ b → W b) + (h : P1.WritesIn st s0 s W) : + faults.copy_mrs_fault_loop0 st s snd rcv sl i ⦃ r => P1.WritesIn st s0 r.1 W ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold faults.copy_mrs_fault_loop0 + apply loop.spec_decr_nat (measure := fun y => sl.val.length - y.2.val) + (inv := fun y => P1.WritesIn st s0 y.1 W) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + dsimp only + unfold faults.copy_mrs_fault_loop0.body + dsimp only + split + · rename_i hj + have hj' : j.val < sl.val.length := by simpa using hj + simp only [lift, bind_ok] + split + · refine WP.spec_bind (Slice.index_usize_spec sl j hj') fun rg _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s1 rg hS) fun v _ => ?_ + refine WP.spec_bind (msg.msg_register.lt _) fun i5 hi5 => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.rg (v := v) (s := s1) hT hr hi5) fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + refine ⟨(h1.trans w2).mono fun b hb => hb.elim id (hW b), ?_⟩ + omega + · exact (WP.spec_ok _).2 h1 + · exact (WP.spec_ok _).2 h1 + · exact h + +theorem copy_mrs_fault_loop1_rgW {rw : U64} {W : U64 → Prop} + (hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA rw i)) (hWb : ∀ b, RBufW rw b → W b) + {s0 : S} {snd : U64} {sl : Slice U64} (hn : sl.val.length ≤ 120) (s : S) (i : Usize) + (h : P1.WritesIn st s0 s W) : + faults.copy_mrs_fault_loop1 st s snd sl rw i ⦃ s' => P1.WritesIn st s0 s' W ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold faults.copy_mrs_fault_loop1 + apply loop.spec_decr_nat (measure := fun y => sl.val.length - y.2.val) + (inv := fun y => P1.WritesIn st s0 y.1 W) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + dsimp only + unfold faults.copy_mrs_fault_loop1.body + dsimp only + split + · rename_i hj + have hj' : j.val < sl.val.length := by simpa using hj + refine WP.spec_bind (Slice.index_usize_spec sl j hj') fun rg _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s1 rg hS) fun v _ => ?_ + simp only [lift, bind_ok] + have h3v : (UScalar.cast .U64 j : U64).val = j.val := cast_us j (by omega) + have hi4 : (core.num.U64.wrapping_add (UScalar.cast .U64 j) 1#u64).val = j.val + 1 := by + rw [wadd_val _ 1 (by omega) _ rfl, h3v] + refine WP.spec_bind (Endp.msg.buf_set.spec s1 rw _ v) ?_ + rintro s2 rfl + step as ⟨j2, hj2⟩ + refine ⟨(h1.trans ((P1.writesIn_wr (hal _ (by omega))).mono fun b hb' => hWb b ⟨_, by omega, hb'⟩)).mono + fun b hb' => hb'.elim id id, ?_⟩ + omega + · exact (WP.spec_ok _).2 h1 + · exact h + +theorem copy_mrs_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {s0 s : S} {snd rcv rw : U64} + {sl : Slice U64} (hn : sl.val.length ≤ 120) (hr : rcv ∈ T) {W : U64 → Prop} (hW : FW T rw W) + (h : P1.WritesIn st s0 s W) : + faults.copy_mrs_fault st s snd rcv sl rw ⦃ s' => P1.WritesIn st s0 s' W ⦄ := by + unfold faults.copy_mrs_fault + refine WP.spec_bind (copy_mrs_fault_loop0_rgW (snd := snd) (sl := sl) (i := 0#usize) hT hr hW.1 h) ?_ + rintro ⟨s1, i⟩ h1 + simp only at h1 + by_cases hb : (rw != 0#u64) = true + · have hrw0 : rw ≠ 0#u64 := by simpa using hb + obtain ⟨hal, hWb⟩ := hW.2 hrw0 + simp only [hb, ↓reduceIte] + exact copy_mrs_fault_loop1_rgW hal hWb hn s1 i h1 + · simp only [hb, Bool.false_eq_true, ↓reduceIte] + show (ok s1) ⦃ _ ⦄ + exact (WP.spec_ok _).2 h1 + +/-- **`set_mrs_fault`'s footprint** (any fault type; a timeout only without +an SC): the receiver's registers and buffer words (`FW`). -/ +theorem set_mrs_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv rw : U64} (hr : rcv ∈ T) (s : S) (a : A) + {W : U64 → Prop} (hW : FW T rw W) + (hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64) : + faults.set_mrs_fault st arI s a snd rcv rw ⦃ r => P1.WritesIn st s r.2 W ⦄ := by + have hS : P0.StoreTotal st := L.total + have h0 : P1.WritesIn st s s W := P1.WritesIn.refl s _ + unfold faults.set_mrs_fault + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ty rfl + refine WP.spec_bind (P0.obj.Tcb.fault_w0.p0 st snd s hS) fun w0 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w1.p0 st snd s hS) fun w1 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.fault_w2.p0 st snd s hS) fun w2 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st snd s _ hS) fun pc _ => ?_ + by_cases h1 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.CapFault + · rw [if_pos h1] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ + rintro ⟨_, s1⟩ h1' + simp only at h1' + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ + rintro ⟨_, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2) ?_ + rintro ⟨_, s3⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.faults.lookup_failure.p0 st s3 snd hS) fun lf _ => ?_ + exact set_mrs_lookup_failure_rgW hT hr hW (by decide) h3 + rw [if_neg h1] + by_cases h2 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.UnknownSyscall + · rw [if_pos h2] + unfold lift + apply ok_bind_spec + refine WP.spec_bind (copy_mrs_fault_rgW (snd := snd) hT (by rw [syscall_slice_length]; omega) hr hW h0) ?_ + rintro s2 h2' + exact set_mr_rgW hT hr hW (by decide) h2' + rw [if_neg h2] + by_cases h3 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.UserException + · rw [if_pos h3] + unfold lift + apply ok_bind_spec + have hel : (Array.to_slice faults.EXCEPTION_MESSAGE).val.length ≤ 120 := by + rw [exc_slice_val]; simp [Fl4Spec.exceptionMessage] + refine WP.spec_bind (copy_mrs_fault_rgW (snd := snd) hT hel hr hW h0) ?_ + rintro s2 h2' + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ + rintro ⟨_, s3⟩ h3' + simp only at h3' + try simp only [WP.uncurry'_pair] + exact set_mr_rgW hT hr hW (by decide) h3' + rw [if_neg h3] + by_cases h4 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout + · rw [if_pos h4] + refine WP.spec_bind (Fl4Proofs.P1.obj.Tcb.sc.spec s snd) ?_ + rintro i rfl + unfold obj.Sc.is_null + apply ok_bind_spec + simp only [hto h4, decide_true, ↓reduceIte] + exact set_mr_rgW hT hr hW (by decide) h0 + rw [if_neg h4] + by_cases h5 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.DebugException + · rw [if_pos h5] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ + rintro ⟨_, s1⟩ h1' + simp only at h1' + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ + rintro ⟨ret, s2⟩ h2' + simp only at h2' + try simp only [WP.uncurry'_pair] + split + · split + · refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ + rintro ⟨_, s3⟩ h3' + simp only at h3' + try simp only [WP.uncurry'_pair] + exact set_mr_rgW hT hr hW (by decide) h3' + · exact (WP.spec_ok _).2 h2' + · exact (WP.spec_ok _).2 h2' + rw [if_neg h5] + by_cases h6 : L.mem s (tFaultA snd) = fl4_abi.consts.fault.VMFault + · rw [if_pos h6] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h0) ?_ + rintro ⟨_, s1⟩ h1' + simp only at h1' + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h1') ?_ + rintro ⟨_, s2⟩ h2' + simp only at h2' + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (set_mr_rgW hT hr hW (by decide) h2') ?_ + rintro ⟨_, s3⟩ h3' + simp only at h3' + try simp only [WP.uncurry'_pair] + exact set_mr_rgW hT hr hW (by decide) h3' + rw [if_neg h6] + exact (WP.spec_ok _).2 h0 + +/-- **`do_ipc_transfer`'s footprint, a faulted sender** (any fault, a +timeout only without an SC), for the receive buffer `rw` the lookup +returns: `FW T rw W`. -/ +theorem do_ipc_transfer_fault_rgW {T : Set U64} (hT : P1.TcbPlaced T) {snd rcv : U64} (hr : rcv ∈ T) (s : S) + (a : A) (ep badge : U64) (grant : Bool) {rw : U64} {W : U64 → Prop} (hW : FW T rw W) + (hb : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = rw ⦄) + (hty : L.mem s (tFaultA snd) ≠ fl4_abi.consts.fault.NullFault) + (hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => P1.WritesIn st s s' W ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold ipc.do_ipc_transfer + refine WP.spec_bind hb ?_ + rintro rb rfl + refine WP.spec_bind (Endp.obj.Tcb.fault_type.spec s snd) ?_ + rintro ft rfl + rw [if_neg hty] + unfold ipc.do_fault_transfer + refine WP.spec_bind (set_mrs_fault_rgW (arI := arI) hT hr s a hW hto) ?_ + rintro ⟨sent, s1⟩ h1 + simp only at h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s1 hS) fun ft _ => ?_ + refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ + refine WP.spec_bind (Pₘ := fun s3 => P1.WritesIn st s s3 W) ?_ + fun s3 h3 => WP.spec_mono (obj.Tcb.set_reg.rg (s := s3) (v := badge) hT hr + (by simp [layout.reg.BADGE, layout.reg.RDI])) fun s4 w4 => (h3.trans w4).mono fun b hb => hb.elim id (hW.1 b) + unfold msg.set_msg_info + exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => + WP.spec_mono (obj.Tcb.set_reg.rg (v := w) (s := s1) hT hr (by simp [layout.reg.MSG_INFO, layout.reg.RSI])) + fun s4 w4 => (h1.trans w4).mono fun b hb => hb.elim id (hW.1 b) + +end + +section SpecF +open Fl4Spec + +/-- The spec's fault message of any fault but a timeout with an SC leaves +the state unchanged. -/ +theorem makeFaultMsg_pure {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) (f : Fault) + (hto : ∀ b, f = .timeout b → x.tcbSchedContext = none) : + ∃ label ms, makeFaultMsg (Z := Unit) f t σ = ({((label, ms), σ)}, False) := by + cases f with + | capFault c rp lf => exact ⟨_, _, makeFaultMsg_cap hk c rp lf⟩ + | unknownSyscallException n => exact ⟨_, _, makeFaultMsg_unknown hk n⟩ + | userException e c => exact ⟨_, _, makeFaultMsg_user hk e c⟩ + | timeout b => exact ⟨_, _, makeFaultMsg_timeout hk (hto b rfl) b⟩ + | archFault af => + cases af with + | vmFault va d => exact ⟨_, _, makeFaultMsg_vm hk va d⟩ + +end SpecF + +section +variable {S : Type} {st : machine.Store S} [L : P1.LawfulStore st] {A : Type} {arI : machine.Arch A} + +set_option maxHeartbeats 16000000 in +/-- **The transfer step of a faulted sender to a receiver, with or without a +receive buffer** (XTopJointFaultRecv's `xferFaultStepJ` for any fault with +`FaultOK`): on `IRel` by EpFaultNone's `do_ipc_transfer_faultN` (no buffer) +or EpFaultMore's `do_ipc_transfer_fault` (a buffer), the spec's outcome by +`makeFaultMsg_pure` and `doFaultTransfer_eqN`/`doFaultTransfer_eq`, the +footprint by `do_ipc_transfer_fault_rgW`, P1's hole by `xfer_all` or +`blkX_bufw`. -/ +theorem xferFaultStepGJ {th : TypedHeap} {cr : Fl4Spec.Cr3} {N T C E R : Set U64} + {B : Set (U64 × Fl4Spec.Word)} {c : U64} (hP0 : Ipc.IPlaced N T E R B) (hP : EPlaced T E R B) + (hHE : EpHyps st T E R B (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)))) + (s : S) (a : A) (σ : Fl4Spec.State Unit) (hR : EpStateRel T E R B (L.mem s) σ) + (hSR : SRN st N T (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c))) s σ) + (hOK : Endp.IpcBufCapOK σ) (hBC : Endp.BufCover T B σ) + {snd rcv : U64} (hs : snd ∈ T) (hr : rcv ∈ T) (hne : snd ≠ rcv) {xs xr : Fl4Spec.Tcb} + (hks : σ.kheap snd.bv = some (.tcb xs)) (hkr : σ.kheap rcv.bv = some (.tcb xr)) {f : Fl4Spec.Fault} + (hf : xs.tcbFault = some f) (hok : FaultOK (L := L) s snd xs f) + (ep badge : U64) (grant : Bool) + {T1 Cs1 Ω Sg Rp Scs Nt Ac1 X : Set U64} {H1 : P1.Heap} {Zb : U64 → Nat} {Q : U64 → U64 → List U64} + {Rq : U64 → List U64} (hT1 : P1.TcbPlaced T1) (hr1 : rcv ∈ T1) + (h : P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s Q Rq) (hB : P1.BoundInv st T1 Ac1 s) + (hX : P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s) (hS : P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s) (hSg : P1.SgOK st Ω Sg s) + (hU : ∀ b, RcvBufW xr b → P1.OutsideObjs st T1 Cs1 s b ∧ + (∀ e, (H1 e = some .ep ∨ H1 e = some .ntfn) → b.val + 8 ≤ e.val ∨ e.val + 16 ≤ b.val) ∧ b ∉ Sg) : + ipc.do_ipc_transfer st arI s a snd ep badge grant rcv ⦃ s' => ∃ (x' : Fl4Spec.Tcb) + (um : Fl4Spec.Word → Fl4Spec.Word8), + Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + ({((), Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))}, False) ∧ x' = { xr with tcbArch := x'.tcbArch } ∧ + EpStateRel T E R B (L.mem s') (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ + (SRS st T (SRT st th cr N T C E R B c (SRE st N T C E R B c)) s' + (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x')) ∧ + Endp.IpcBufCapOK (Notif.updK (Endp.setUm σ um) rcv.bv (.tcb x'))) ∧ + Agree (L.mem s) (L.mem s') (fun b => ¬ RcvReg rcv b ∧ ¬ BufW B b) ∧ + P1.WritesIn st s s' (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) ∧ + P1.SchedQueuesInvX st T1 Cs1 Ω H1 X s' Q Rq ∧ P1.BoundInv st T1 Ac1 s' ∧ P1.XInv st T1 Cs1 Ω Sg Rp Scs Nt Zb s' ∧ + P1.SCsOK st T1 Ω Sg Scs Zb Ac1 s' ∧ P1.SgOK st Ω Sg s' ∧ + (∀ y ∈ T1, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → + L.mem s' (core.num.U64.wrapping_add y K) = L.mem s (core.num.U64.wrapping_add y K)) ⦄ := by + have hxs := hR.at_tcb hs hks + have hty : L.mem s (tFaultA snd) ≠ fl4_abi.consts.fault.NullFault := by + intro e + have := hxs.fault0.1 (by rw [e]; unfold fl4_abi.consts.fault.NullFault; rfl) + rw [hf] at this; cases this + have hto : L.mem s (tFaultA snd) = fl4_abi.consts.fault.Timeout → L.mem s (P1.scA snd) = 0#u64 := by + intro e + obtain ⟨b, hb⟩ := hxs.faultT.1 (by rw [e]; unfold fl4_abi.consts.fault.Timeout; rfl) + rw [hf] at hb; cases hb + exact hok.2 + have htoS : ∀ b, f = .timeout b → xs.tcbSchedContext = none := by + intro b hb; subst hb; exact hok.1 + obtain ⟨label, ms, hmsg⟩ := makeFaultMsg_pure hks f htoS + obtain ⟨⟨⟨G, hBt⟩, hBw⟩, -⟩ := hSR.1.1 + have hlb := lookup_buf_full s σ hBt.2.1.1 hBt.2.1.2.1 (Ipc.RelTopB.tcbT hBt hkr) hkr hOK true + cases hrb : Endp.ipcBufOf true xr with + | none => + have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = 0#u64 ⦄ := WP.spec_mono hlb fun w hw => hw.1.2 hrb + have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv none σ := by + unfold Fl4Spec.doIpcTransfer + rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] + have hspec := hspec0.trans (doFaultTransfer_eqN hks hkr hf hmsg badge.bv) + have uu : ∀ (σ0 : Fl4Spec.State Unit) (p : Fl4Spec.ObjRef) (o o' : Fl4Spec.KernelObject), + Notif.updK (Notif.updK σ0 p o) p o' = Notif.updK σ0 p o' := fun _ _ _ _ => by + simp only [Notif.updK, Function.update_idem] + simp only [mrStateN, uu] at hspec + have hW : FW T1 0#u64 (XferRegW T1 ∅) := ⟨fun _ h => h, fun h => absurd rfl h⟩ + refine WP.spec_mono (WP.spec_and (do_ipc_transfer_faultN (ar := arI) (epHyps_buf hHE) + (epBufHyps_buf (st := st) (th := th) (cr := cr) (N := N) (T := T) (C := C) (E := E) (R := R) (B := B) (c := c)) + hP s a σ hR ⟨hSR.1, hOK⟩ hs hr hne hks hkr hf hok hrb ep badge grant) + (do_ipc_transfer_fault_rgW (arI := arI) hT1 hr1 s a ep badge grant hW hlk hty hto)) ?_ + rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ + have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) + subst eσ + obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2, -⟩ := + P1.xfer_all h hB hX hS hSg (U := ∅) (fun b hb => absurd hb (Set.notMem_empty _)) + (w2.mono fun b hb => P1.XferRegW.foot hb) + exact ⟨_, σ.machineState.underlyingMemory, e2, rfl, hR2, hS2, hA2, w2.mono fun b hb => Or.inl hb, + h2, hB2, hX2, hS2', hSg2, f2⟩ + | some p => + obtain ⟨x0, hk0, hbw⟩ := hBw.bw rcv hr + rw [hkr] at hk0; cases hk0 + have hlk : msg.lookup_ipc_buffer st s true rcv ⦃ w => w = ⟨p⟩ ⦄ := WP.spec_mono hlb fun w hw => by + have hwb : w.bv = p := hw.2 hbw p hrb + rw [← hwb] + have hrw0 : (⟨p⟩ : U64) ≠ 0#u64 := by + obtain ⟨w0, -, hw0⟩ := spec_exists hlb + have hwb : w0.bv = p := hw0.2 hbw p hrb + intro e + have : w0 = 0#u64 := by rw [← e, ← hwb] + rw [hw0.1.1 this] at hrb; cases hrb + have hal : ∀ i : U64, i.val < 128 → P1.Aligned (Endp.fl4BufA ⟨p⟩ i) := fun i hi => + (hP.balign _ (hBC rcv hr xr true p hkr hrb ⟨p⟩ rfl i hi)).1 + have hBm := epBufMapHyps_bufC (st := st) (th := th) (cr := cr) (C := C) (c := c) hP0 + obtain ⟨rw1, -, hrw1, hmr⟩ := spec_exists (hBm.lookupMap s σ rcv xr true p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb) + have hu := hBm.frame s σ rcv xr p hR ⟨⟨hSR.1, hOK⟩, hBC⟩ hr hkr hrb + have hal' : ∀ q ∈ mrPairs ms, (bufAddr p q.1).toNat % 8 = 0 ∧ Fl4Spec.inUserFrame (bufAddr p q.1) σ := by + intro q hq + have := (List.of_mem_zip hq).1 + simp at this + exact ⟨bufAddr_aligned hP hmr _, hu _ (by omega)⟩ + have hspec0 : Fl4Spec.doIpcTransfer (Z := Unit) snd.bv (some ep.bv) badge.bv grant rcv.bv σ = + Fl4Spec.doFaultTransfer (Z := Unit) badge.bv snd.bv rcv.bv (some p) σ := by + unfold Fl4Spec.doIpcTransfer + rw [nd_bind_one (lookupIpcBuffer_eq hkr true), hrb, nd_bind_one (threadGet_eq _ hks), hf] + have hspec := hspec0.trans (doFaultTransfer_eq hks hkr hf hmsg p hal' badge.bv) + have hW : FW T1 ⟨p⟩ (XferBW T1 ⟨p⟩) := ⟨fun _ h => Or.inl h, fun _ => ⟨hal, fun _ h => Or.inr h⟩⟩ + refine WP.spec_mono (WP.spec_and (Endp.do_ipc_transfer_fault (ar := arI) (epHyps_bufC hHE T) hBm hP s a σ hR + ⟨⟨hSR.1, hOK⟩, hBC⟩ hs hr hne hks hkr hf hok hrb ep badge grant) + (do_ipc_transfer_fault_rgW (arI := arI) hT1 hr1 s a ep badge grant hW hlk hty hto)) ?_ + rintro s2 ⟨⟨σ', e2, hR2, hS2, hA2, -⟩, w2⟩ + have eσ := congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (e2.symm.trans hspec))) + simp only [mrState, updK_setUm_updK] at eσ + subst eσ + have hW' : P1.WritesIn st s s2 (fun b => XferRegW T1 ∅ b ∨ RcvBufW xr b) := + w2.mono fun b hb => hb.imp_right fun h' => ⟨p, hrb, h'⟩ + obtain ⟨h2, hB2, hX2, hS2', hSg2, -, -, -, -, f2⟩ := blkX_bufw (l := rbList ⟨p⟩) h hB hX hS hSg + (fun b hb => hU b ⟨p, hrb, mem_rbList.1 hb⟩) (w2.mono fun b hb => hb.imp_right mem_rbList.2) + exact ⟨_, _, e2, rfl, hR2, hS2.1, hA2, hW', h2, hB2, hX2, hS2', hSg2, f2⟩ + +end + +end + +end Fl4Proofs.P3 diff --git a/proofs/Fl4Spec/Ext/VirtExitIrqF.lean b/proofs/Fl4Spec/Ext/VirtExitIrqF.lean new file mode 100644 index 000000000..6a4fa5e7a --- /dev/null +++ b/proofs/Fl4Spec/Ext/VirtExitIrqF.lean @@ -0,0 +1,87 @@ +/- +FL4's saved host interrupt at VCPU exit (PORTING.md, “FL4 differences”). +The vector can already be in service when another core deactivates its +line before the exit handler takes the gate. +-/ +import Fl4Spec.Ext.VirtKernelF + +namespace Fl4Spec + +noncomputable section +open Classical + +variable {Z : Type} [StateExt Z] + +/-- A vector saved at VCPU exit still needs its acknowledgement after +the line has become inactive. -/ +def handleSavedIrqVF (onCore remoteCur : ObjRef → Bool) (irq : Irq) : SMonad Z Unit := fun s => + if irq ≤ maxIRQ ∧ s.interruptStates irq = .irqInactive then + doMachineOp (do maskInterrupt true irq; ackInterrupt irq) s + else handleInterruptVF onCore remoteCur irq s + +/-- A saved device vector is masked and acknowledged even after deletion +deactivates its line. -/ +theorem handleSavedIrqVF_inactive (onCore remoteCur : ObjRef → Bool) (irq : Irq) (s : State Z) + (hi : irq ≤ maxIRQ) (hs : s.interruptStates irq = .irqInactive) : + handleSavedIrqVF onCore remoteCur irq s = + doMachineOp (do maskInterrupt true irq; ackInterrupt irq) s := by + exact if_pos ⟨hi, hs⟩ + +theorem handleSavedIrqVF_eq (onCore remoteCur : ObjRef → Bool) (irq : Irq) (s : State Z) + (h : irq > maxIRQ ∨ s.interruptStates irq ≠ .irqInactive) : + handleSavedIrqVF onCore remoteCur irq s = handleInterruptVF onCore remoteCur irq s := by + unfold handleSavedIrqVF + apply if_neg + rintro ⟨hi, hs⟩ + exact h.elim (fun hgt => (BitVec.not_lt.2 hi) hgt) (fun ha => ha hs) + +/-- Timestamp, VCPU check and budget charge on an unstalled exit. -/ +def vcpuExitPrefixVF (stalled : Bool) : SMonad Z Unit := + NonDet.unless stalled <| do + updateTimeStamp + let ct ← NonDet.gets fun s : State Z => s.curThread + vmCheckF ct + let _ ← checkBudget + pure () + +/-- FL4 `handle_vcpu_exit` with the saved interrupt delivered under the gate. -/ +def fl4VcpuExitSavedVF (onCore remoteCur : ObjRef → Bool) (irq : Option Irq) (stalled : Bool) : SMonad Z Unit := do + vcpuExitPrefixVF stalled + NonDet.maybeM (handleSavedIrqVF onCore remoteCur) irq + fl4KernelExitVF onCore remoteCur + +private theorem bind_congr_at {S α β : Type} (m : NonDet S α) (k k' : α → NonDet S β) (s : S) + (h : ∀ x ∈ (m s).1, k x.1 x.2 = k' x.1 x.2) : + NonDet.bind m k s = NonDet.bind m k' s := by + have congrOutcome (P : (Set (β × S) × Prop) → Prop) : + (∃ x ∈ (m s).1, P (k x.1 x.2)) ↔ ∃ x ∈ (m s).1, P (k' x.1 x.2) := + exists_congr fun x => and_congr_right fun hx => by rw [h x hx] + exact Prod.ext (Set.ext fun r => congrOutcome fun p => r ∈ p.1) + (propext (or_congr Iff.rfl (congrOutcome Prod.snd))) + +theorem fl4VcpuExitSavedVF_none (onCore remoteCur : ObjRef → Bool) (stalled : Bool) : + fl4VcpuExitSavedVF (Z := Z) onCore remoteCur none stalled = + fl4VcpuExitVF onCore remoteCur none stalled := by + funext s + unfold fl4VcpuExitSavedVF fl4VcpuExitVF + refine bind_congr_at _ _ _ s fun x _ => ?_ + simp [Bind.bind, Pure.pure, NonDet.maybeM, NonDet.bind, NonDet.pure] + +/-- The two VCPU-exit entries agree whenever the saved vector is still +active at delivery, or lies above the IRQ table. -/ +theorem fl4VcpuExitSavedVF_eq (onCore remoteCur : ObjRef → Bool) (irq : Irq) (stalled : Bool) (s : State Z) + (h : ∀ x ∈ (vcpuExitPrefixVF stalled s).1, irq > maxIRQ ∨ x.2.interruptStates irq ≠ .irqInactive) : + fl4VcpuExitSavedVF onCore remoteCur (some irq) stalled s = + fl4VcpuExitVF onCore remoteCur (some irq) stalled s := by + unfold fl4VcpuExitSavedVF fl4VcpuExitVF + refine bind_congr_at _ _ _ s fun x hx => ?_ + change NonDet.bind (handleSavedIrqVF onCore remoteCur irq) + (fun _ => fl4KernelExitVF onCore remoteCur) x.2 = + NonDet.bind (handleInterruptVF onCore remoteCur irq) + (fun _ => fl4KernelExitVF onCore remoteCur) x.2 + unfold NonDet.bind + rw [handleSavedIrqVF_eq onCore remoteCur irq x.2 (h x hx)] + +end + +end Fl4Spec diff --git a/proofs/Fl4Spec/PORTING.md b/proofs/Fl4Spec/PORTING.md index b66129a86..e524405b2 100644 --- a/proofs/Fl4Spec/PORTING.md +++ b/proofs/Fl4Spec/PORTING.md @@ -487,6 +487,16 @@ details. Where the owner decided (2026-11-21) that FL4 should follow seL4 and the kernel does not yet, the spec states seL4's behaviour and the place is marked `-- FL4 code differs until V1/V2/V3` (VIRT-PLAN.md §12). +- **Saved host IRQs at VCPU exit** (`Ext/VirtExitIrqF`). The x86 + exit path captures or polls the host vector before taking the gate + (`crates/fl4-kernel/src/entry.rs:774–812`). By the time the + handler reads the IRQ table, the saved device line may be inactive. + In that case FL4 masks and acknowledges the line + (`crates/fl4-core/src/interrupt.rs:125–128`). The saved-IRQ + entry models this case and uses the existing `handleInterruptVF` + behavior for other vectors. The refinement's single-core-view scope + excludes the cross-core IPIs 126 and 127 at the trusted guest-exit + boundary. - **`runningVM` and timeout faults** (FL4 `sched.rs` `end_timeslice`, VIRT-PLAN.md FINDING V8, kept by the owner's decision of 2026-11-21): a thread whose budget expires while `runningVM` gets no timeout fault; it diff --git a/proofs/scratch/mmuAD_ax.lean b/proofs/scratch/mmuAD_ax.lean index d27ea7e86..57ff518ad 100644 --- a/proofs/scratch/mmuAD_ax.lean +++ b/proofs/scratch/mmuAD_ax.lean @@ -113,7 +113,227 @@ import Fl4Proofs.P3.VmDelHyps import Fl4Proofs.P3.VmDelCap import Fl4Proofs.P3.VmCnodeRD import Fl4Proofs.P3.VmCnodeAll +import Fl4Proofs.P3.VmDisp +import Fl4Proofs.P3.HandleTopG +import Fl4Proofs.P3.XTopJointReplyTail +import Fl4Proofs.P3.XTopJointXferB +import Fl4Proofs.P3.XTopJointSendRecv +import Fl4Proofs.P3.JAtZV3SigTail +import Fl4Proofs.P3.XTopJointNoFault +import Fl4Proofs.P3.XTopJointFaultEp +import Fl4Proofs.P3.XTopJointFaultRecv +import Fl4Proofs.P3.JAtZV3FaultDon +import Fl4Proofs.P3.VmHandle +import Fl4Proofs.P3.VmPerfCur +import Fl4Proofs.P3.VmHandleTop +import Fl4Proofs.P3.XTopJointMRHole +import Fl4Proofs.P3.XTopJointKEntry38 +import Fl4Proofs.P3.P3JPreSt +import Fl4Proofs.P3.JProducers +import Fl4Proofs.P3.VmSignal +import Fl4Proofs.P3.VmOracle +import Fl4Proofs.P2.FootN3 +import Fl4Proofs.P3.XTopJointMRPath2 +import Fl4Proofs.P3.VmPreempt +import Fl4Proofs.P3.VmSchedule +import Fl4Proofs.P3.G7eTail +import Fl4Proofs.P3.ScNextDomCFR +import Fl4Proofs.P3.VmPerfRvm +import Fl4Proofs.P3.SpecInvAllO +import Fl4Proofs.P3.VmCheck +import Fl4Proofs.P3.VmFinish +import Fl4Proofs.P3.VmHiErr +import Fl4Proofs.P3.VmInvAfter +import Fl4Spec.Ext.VirtExitIrqF +import Fl4Proofs.P3.XTopJointRest +import Fl4Proofs.P3.ZNoBlkJ +import Fl4Proofs.P3.XTopCnode +import Fl4Proofs.P3.XTopJointCbs +import Fl4Proofs.P3.VmCnodeVtx +import Fl4Proofs.P3.VmCnodeVtxSpec +import Fl4Proofs.P3.VmCnodeCp +import Fl4Proofs.P3.CnodeRevoke +import Fl4Proofs.P3.DelFull +import Fl4Proofs.P3.XTopJointWJLPP +import Fl4Proofs.P3.XTopJointWJLRd +import Fl4Proofs.P3.XTopJointDelR +import Fl4Proofs.P3.XTopJointZombie +import Fl4Proofs.P3.XTopJointLive +import Fl4Proofs.P3.XTopJointWJLFin +import Fl4Proofs.P3.XTopJointWJLFinT +import Fl4Proofs.P3.XTopPostDel +import Fl4Proofs.P3.XTopJointFinVs +import Fl4Proofs.P3.XTopJointFinEp +import Fl4Proofs.P3.XTopJointFin +import Fl4Proofs.P3.XTopJointFinReply +import Fl4Proofs.P3.XTopJointFinScAll +import Fl4Proofs.P3.XTopJointFinScNtfn +import Fl4Proofs.P3.XTopJointFinScInact +import Fl4Proofs.P3.XTopJointFinScReply +import Fl4Proofs.P3.XTopJointFinSc +import Fl4Proofs.P3.XTopJointEmpty +import Fl4Proofs.P3.JointAt +import Fl4Proofs.P3.UtAddSpec +import Fl4Proofs.P3.UtRetJ +import Fl4Proofs.P3.UtRetLive +import Fl4Proofs.P3.XTopJointUtEp +import Fl4Proofs.P3.UtEpSets +import Fl4Proofs.P3.UntypedRetype +import Fl4Proofs.P3.UtCnAdd +import Fl4Proofs.P3.UtScAdd +import Fl4Proofs.P3.UtTcbSets +import Fl4Proofs.P3.UtTcbP1 +import Fl4Proofs.P3.UtTcbLive +import Fl4Proofs.P3.UtTcbUtc +import Fl4Proofs.P3.UtTcbRest +import Fl4Proofs.P3.UtPmKeep +import Fl4Proofs.P3.RetypeBridge +import Fl4Proofs.P3.UtPmAdd +import Fl4Proofs.P3.XTopJointFinVt +import Fl4Proofs.P3.VirtRetypeLoop +import Fl4Proofs.P3.DeadKeep +import Fl4Proofs.P3.JAtZV3 +import Fl4Proofs.P3.XTopJointCnDel +import Fl4Proofs.P3.VirtUtDecV +import Fl4Proofs.P3.VirtUtGateV +import Fl4Proofs.P3.JAtZV3EptE +import Fl4Proofs.P3.JAtZV3EptG +import Fl4Spec.Ext.VirtP3x +import Fl4Proofs.P3.CapRel +import Fl4Proofs.P3.JAtZV3SlotIo +import Fl4Proofs.P3.JAtZV3VEio +import Fl4Proofs.P3.JAtZV3HiComm +import Fl4Proofs.P3.JAtZV3VDisp5 +import Fl4Proofs.P3.VirtNoRunDel +import Fl4Proofs.P3.SpecInvIoPortsX +import Fl4Proofs.P3.JAtZBDetach +import Fl4Proofs.P3.JAtZBBind +import Fl4Proofs.P3.JAtZBSched2 +import Fl4Proofs.P3.JAtZBSched +import Fl4Proofs.P3.JAtZBVcpu +import Fl4Proofs.P3.JAtZBWr +import Fl4Proofs.P3.JAtZV3RepBr0 +import Fl4Proofs.P3.JAtZV3Sched +import Fl4Proofs.P3.JAtZV3Report +import Fl4Proofs.P3.JAtZV3ReportJ3 +import Fl4Proofs.P3.JAtZV3Detach +import Fl4Proofs.P3.JAtZV3Gpr +import Fl4Proofs.P3.JAtZV3RepVal +import Fl4Proofs.P3.JAtZV3MrJ +import Fl4Proofs.P3.JAtZV3Pend +import Fl4Proofs.P3.JAtZV3VRead +import Fl4Proofs.P3.JAtZV3RegW +import Fl4Proofs.P3.JAtZV3RepBrA +import Fl4Proofs.P3.JAtZV3RepBrB +import Fl4Proofs.P3.JAtZV3RepBrC +import Fl4Proofs.P3.JAtZV3RepFin +import Fl4Proofs.P3.JAtZV3RepTail +import Fl4Proofs.P3.JAtZV3RepLoop +import Fl4Proofs.P3.JAtZV3RepFoot +import Fl4Proofs.P3.JAtZV3RunVm +import Fl4Proofs.P3.JAtZV3Regs +import Fl4Proofs.P3.NatFoot +import Fl4Proofs.P3.XTopJointSuspend +import Fl4Proofs.P3.XTopJointCancel +import Fl4Proofs.P3.XTopJointCancelRecv +import Fl4Proofs.P3.XTopJointCancelReply +import Fl4Proofs.P3.XTopJointFinThread +import Fl4Proofs.P3.ScSignalBoundJ +import Fl4Proofs.P3.XTopJointFpu +import Fl4Proofs.P3.XTopJointFinThreadSc +import Fl4Proofs.P3.XTopJointYield +import Fl4Proofs.P3.XTopJointRegFrame +import Fl4Proofs.P3.IpcSuspendJ +import Fl4Proofs.P3.ScJointFrame +import Fl4Proofs.P3.DelEmpty +import Fl4Proofs.P3.DelSpec +import Fl4Proofs.P3.DelW +import Fl4Proofs.P3.DelFinStep +import Fl4Proofs.P3.DelDelete +import Fl4Proofs.P3.DelDef +import Fl4Proofs.P3.DelImm +import Fl4Proofs.P3.XTopJointWJL +import Fl4Proofs.P3.XTopJointDbgKeep +import Fl4Proofs.P3.XTopJointEntry +import Fl4Proofs.P3.XTopJointReply +import Fl4Proofs.P3.XTopJointData +import Fl4Proofs.P3.XTopJointSendBlockG +import Fl4Proofs.P3.ScSignalDonJ +import Fl4Proofs.P3.ScChargeH +import Fl4Proofs.P3.XTopJointPPH +import Fl4Proofs.P3.P3JPreHole +import Fl4Proofs.P3.XTopJointPreemptM +import Fl4Proofs.P3.XTopJointKEntryEv6 +import Fl4Proofs.P3.XTopJointMRPath3 +import Fl4Proofs.P3.XTopJointMRPath4 +import Fl4Proofs.P3.XTopJointCopyRegs +import Fl4Proofs.P3.XTopJointBudgetF +import Fl4Proofs.P3.ScChargeT +import Fl4Proofs.P3.ScFireJ +import Fl4Proofs.P3.XTopJointBudgetT +import Fl4Proofs.P3.ScChargeTR +import Fl4Proofs.P3.ScTmoCtBase +import Fl4Proofs.P3.ScTmoCtRecvI +import Fl4Proofs.P3.ScTmoCtRecvP +import Fl4Proofs.P3.ScTmoCtRecv +import Fl4Proofs.P3.XTopJointBudgetTR +import Fl4Proofs.P3.StPostIrqLeaf +import Fl4Proofs.P3.IpcTcbJAll +import Fl4Proofs.P3.ScSignalJN +import Fl4Proofs.P3.XTopJointIrq +import Fl4Proofs.P3.VmKEntry +import Fl4Proofs.P3.XTopJointFaultG +import Fl4Proofs.P3.XTopJointPreemptZ +import Fl4Proofs.P3.XTopJointIrqZR +import Fl4Proofs.P3.XTopJointIrqZI +import Fl4Proofs.P3.XTopJointMRPath +import Fl4Proofs.P3.XTopJointKEntryEv2 +import Fl4Proofs.P3.P3JMcKwN +import Fl4Proofs.P3.P3JMcFlt +import Fl4Proofs.P3.JAtZV3SigComp +import Fl4Proofs.P3.JAtZV3SigVm +import Fl4Proofs.P3.JAtZV3SigDon +import Fl4Proofs.P2.FootN8 +import Fl4Proofs.P3.XTopJointPreempt +import Fl4Proofs.P3.XTopJointPreemptI +import Fl4Proofs.P3.JAtZBSchedR +import Fl4Proofs.P3.ScAwaken +import Fl4Proofs.P3.ScScheduleTop +import Fl4Proofs.P3.ScNextDomC +import Fl4Proofs.P3.G7eChain +import Fl4Proofs.P1.QueueIpc +import Fl4Proofs.P1.QueueRecv +import Fl4Proofs.P1.QueueXfer +import Fl4Proofs.P2.FootN5 +import Fl4Proofs.P3.SpecInvAllO1 +import Fl4Proofs.P3.SpecInvAllO6 +import Fl4Proofs.P3.XTopJointJAtZRB +import Fl4Proofs.P3.G7eRoot +import Fl4Proofs.P3.G7dVsRoot +import Fl4Proofs.P3.XTopJointDispatch +import Fl4Proofs.P3.VsMdbInv +import Fl4Proofs.P3.MdbStepInv +import Fl4Proofs.P3.XTopJointVsSub +import Fl4Proofs.P3.JAtZV3VDecE +import Fl4Proofs.P3.VmVcpuDec +import Fl4Proofs.P3.VsReplyTop +import Fl4Proofs.P3.VsDecReply +import Fl4Proofs.P3.XTopJointReadFpu + open Fl4Proofs.P3 + +#print axioms Fl4Proofs.P3.VEAny +#print axioms Fl4Proofs.P3.VDispPostVE +#print axioms Fl4Proofs.P3.VmEptState.any +#print axioms Fl4Proofs.P3.perfNil_ok +#print axioms Fl4Proofs.P3.perfNil_err +#print axioms Fl4Proofs.P3.CnAllPostVE.toDisp +#print axioms Fl4Proofs.P3.EptInvPost.toDisp +#print axioms Fl4Proofs.P3.SetEptDecPost.toDisp +#print axioms Fl4Proofs.P3.decV_untyped_run +#print axioms Fl4Proofs.P3.VmEptState.decodeUtDisp +#print axioms Fl4Proofs.P3.VDispAll +#print axioms Fl4Proofs.P3.VmEptState.decodeDisp #print axioms Fl4Proofs.P3.LiveDN.wstepXB #print axioms Fl4Proofs.P3.LiveDN.wstepX #print axioms Fl4Proofs.P3.JAtZB.cslotB @@ -288,15 +508,11 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.VmEptDelSt.deleteOneV #print axioms Fl4Proofs.P3.VmEptDelSt.finIrqL #print axioms Fl4Proofs.P3.finHypVE -#print axioms Fl4Proofs.P3.WxVE.empty #print axioms Fl4Proofs.P3.VmEptState.emptyCores #print axioms Fl4Proofs.P3.VcpuCore.ofSetWT #print axioms Fl4Proofs.P3.VcpuCore.ofSetW #print axioms Fl4Proofs.P3.VmEptState.delVcpuStep #print axioms Fl4Proofs.P3.FinPostVE.x -#print axioms Fl4Proofs.P3.VmEptDelSt.finPoolL -#print axioms Fl4Proofs.P3.VmEptDelSt.finVcpuL -#print axioms Fl4Proofs.P3.VmEptDelSt.finLift #print axioms Fl4Proofs.P3.PoolInj.monoT #print axioms Fl4Proofs.P3.PoolInj.mono #print axioms Fl4Proofs.P3.EptNamed.frameT @@ -322,13 +538,9 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZB.vs_tcbReady #print axioms Fl4Proofs.P3.JAtZ.vs_tcbReady #print axioms Fl4Proofs.P3.VmEptState.finVsK -#print axioms Fl4Proofs.P3.VmEptDelSt.finVsL #print axioms Fl4Proofs.P3.VmEptDelSt.finFrVsL #print axioms Fl4Proofs.P3.ppr0_finaliseCapVF_vcpu #print axioms Fl4Proofs.P3.WVE.x -#print axioms Fl4Proofs.P3.FinPostVE.x -#print axioms Fl4Proofs.P3.VmEptDelSt.finPoolL -#print axioms Fl4Proofs.P3.VmEptDelSt.finVcpuL #print axioms Fl4Proofs.P3.JAtZB.epFinPre #print axioms Fl4Proofs.P3.JAtZB.deadP_efr #print axioms Fl4Proofs.P3.efr_zvk @@ -364,8 +576,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZ.finScJD #print axioms Fl4Proofs.P3.JAtZ.replyRemoveJD #print axioms Fl4Proofs.P3.jFinPPHyp -#print axioms Fl4Proofs.P3.VmEptDelSt.finLiftR -#print axioms Fl4Proofs.P3.VmEptDelSt.finNatL #print axioms Fl4Proofs.P3.VmEptDelSt.finEpL #print axioms Fl4Proofs.P3.VmEptDelSt.finNtfnL #print axioms Fl4Proofs.P3.VmEptDelSt.finReplyL @@ -714,7 +924,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZ.utResetJMM #print axioms Fl4Proofs.P3.ResetPostQ.vmPre #print axioms Fl4Proofs.P3.VmQ.zero -#print axioms Fl4Proofs.P3.JAtZB.dropAD #print axioms Fl4Proofs.P3.TCappedM.of_caps #print axioms Fl4Proofs.P3.TCappedM.of_update #print axioms Fl4Proofs.P3.TCappedM.of_chains @@ -747,16 +956,13 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.ResetQObl.vm #print axioms Fl4Proofs.P3.VmEptState.reset_untyped #print axioms Fl4Proofs.P3.retEntry_of_reset -#print axioms Fl4Proofs.P3.RetCtx.restart #print axioms Fl4Proofs.P3.JAtZB.reset_untypedDQ #print axioms Fl4Proofs.P3.JAtZ.reset_untypedDJ #print axioms Fl4Proofs.P3.JAtZ.utDevResetJ -#print axioms Fl4Proofs.P3.JAtZ.utResetJM #print axioms Fl4Proofs.P3.JAtZB.ppr0_start #print axioms Fl4Proofs.P3.JAtZ.ppr0_start #print axioms Fl4Proofs.P3.VmEptState.restartK #print axioms Fl4Proofs.P3.VmEptState.retypeRG -#print axioms Fl4Proofs.P3.VmEptState.retypeR #print axioms Fl4Proofs.P3.fl4InvokeUntypedV_reset_ok #print axioms Fl4Proofs.P3.fl4InvokeUntypedV_reset_err #print axioms Fl4Proofs.P3.ZvVirtAgree.code @@ -918,7 +1124,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.VmBaseF.wrLoop #print axioms Fl4Proofs.P3.VmBaseF.writeRegsJ #print axioms Fl4Proofs.P3.VmBaseF.writeVmcsJ -#print axioms Fl4Proofs.P3.VmEptState.detachF2 #print axioms Fl4Proofs.P3.VmEptState.ofF #print axioms Fl4Proofs.P3.VmEptState.reportJ3 #print axioms Fl4Proofs.P3.VmEptState.toB @@ -940,7 +1145,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZV3.vcpuStep #print axioms Fl4Proofs.P3.JAtZV3.bind #print axioms Fl4Proofs.P3.JAtZV3.unbind -#print axioms Fl4Proofs.P3.VcpuCore.ofBS #print axioms Fl4Proofs.P3.JAtZV.vcpuWr #print axioms Fl4Proofs.P3.JAtZV2.bind #print axioms Fl4Proofs.P3.JAtZV2.unbind @@ -949,10 +1153,8 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZB.vcpuWrB #print axioms Fl4Proofs.P3.JAtZB.vheadJD #print axioms Fl4Proofs.P3.JAtZB.vlSlot -#print axioms Fl4Proofs.P3.VcpuCore.ofSetW #print axioms Fl4Proofs.P3.JAtZB.delStep #print axioms Fl4Proofs.P3.JAtZB.vcpuApart -#print axioms Fl4Proofs.P3.VmEptState.delVcpuStep #print axioms Fl4Proofs.P3.finCapVF_vcpu_true #print axioms Fl4Proofs.P3.finCapVF_vcpu_false #print axioms Fl4Proofs.P3.finCapVF_vcpu_none @@ -1093,10 +1295,7 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.jCancel_send #print axioms Fl4Proofs.P3.kfr_zvk #print axioms Fl4Proofs.P3.natK_qky -#print axioms Fl4Proofs.P3.nchg_zv -#print axioms Fl4Proofs.P3.nfr_zvk #print axioms Fl4Proofs.P3.oobj_back -#print axioms Fl4Proofs.P3.tchg_runVM #print axioms Fl4Proofs.P3.tcx_runVM #print axioms Fl4Proofs.P3.tfoot_nv #print axioms Fl4Proofs.P3.zvChg_ep @@ -1114,8 +1313,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.ioBW_nh #print axioms Fl4Proofs.P3.post_io_eq #print axioms Fl4Proofs.P3.post_io_foot -#print axioms Fl4Proofs.P3.JAtZB.postIo -#print axioms Fl4Proofs.P3.VmEptState.postIo #print axioms Fl4Proofs.P3.VmEptState.ofEmptyIo #print axioms Fl4Proofs.P3.VmEptState.delIoPort #print axioms Fl4Proofs.P3.JAtZB.rdOf @@ -1150,14 +1347,12 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.VmEptState.finThread #print axioms Fl4Proofs.P3.JAtZB.dbgSuccCov_of_live #print axioms Fl4Proofs.P3.JAtZ.dbgSuccCov_of_live -#print axioms Fl4Proofs.P3.ak_vmReportF #print axioms Fl4Proofs.P3.setTcbCoreQ #print axioms Fl4Proofs.P3.VmBaseF.setTcbCoreF2 #print axioms Fl4Proofs.P3.JAtZV3.setTcbCoreF #print axioms Fl4Proofs.P3.JAtZV3.setTcbCoreF2 #print axioms Fl4Proofs.P3.VmEptState.finThreadZ #print axioms Fl4Proofs.P3.JAtZB.finThreadTailZ -#print axioms Fl4Proofs.P3.JAtZB.finThreadTail #print axioms Fl4Proofs.P3.recDelFG_cap #print axioms Fl4Proofs.P3.recDelG_cap #print axioms Fl4Proofs.P3.capDeleteG_cap @@ -1225,10 +1420,7 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.JAtZB.ppJDMC #print axioms Fl4Proofs.P3.JAtZ.ppJDMC #print axioms Fl4Proofs.P3.VcpuCore.ofSlots -#print axioms Fl4Proofs.P3.VcpuCore.ofSetW -#print axioms Fl4Proofs.P3.UnmappedEmpty.keepG #print axioms Fl4Proofs.P3.UnmappedEmpty.keepI -#print axioms Fl4Proofs.P3.EptCore.frameG #print axioms Fl4Proofs.P3.EptCore.frameI #print axioms Fl4Proofs.P3.swapRen #print axioms Fl4Proofs.P3.VcpuCore.ofZombie @@ -1249,8 +1441,6 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.VmEptDelSt.ppStep #print axioms Fl4Proofs.P3.JAtZB.dbgWF_thread #print axioms Fl4Proofs.P3.JAtZ.dbgWF_thread -#print axioms Fl4Proofs.P3.VmEptState.finThreadZ_rz -#print axioms Fl4Proofs.P3.VmEptState.finThreadZ #print axioms Fl4Proofs.P3.VirtNoRunDel.ik_guestLookupSlot #print axioms Fl4Proofs.P3.VirtNoRunDel.ns_guestLookupSlot #print axioms Fl4Proofs.P3.relk_finaliseCapVF @@ -1279,6 +1469,518 @@ open Fl4Proofs.P3 #print axioms Fl4Proofs.P3.VmEptState.finEptK #print axioms Fl4Proofs.P3.fa_finaliseCapVF_arch #print axioms Fl4Proofs.P3.ppr0_finaliseCapVF_arch -#print axioms Fl4Proofs.P3.VmEptDelSt.finLift #print axioms Fl4Proofs.P3.VmEptDelSt.finEptL #print axioms Fl4Proofs.P3.VmEptDelSt.finIoL +#print axioms Fl4Proofs.P3.hiG +#print axioms Fl4Proofs.P3.fl4HandleInvocationR_hiG +#print axioms Fl4Proofs.P3.fl4HandleInvocationVF_hiG +#print axioms Fl4Proofs.P3.hiMEG +#print axioms Fl4Proofs.P3.hiMFinG +#print axioms Fl4Proofs.P3.hi_memG +#print axioms Fl4Proofs.P3.hiMEG_run +#print axioms Fl4Proofs.P3.hiMFinG_ok +#print axioms Fl4Proofs.P3.hiMFinG_pre +#print axioms Fl4Proofs.P3.TopPostDMXG +#print axioms Fl4Proofs.P3.TopPostDMX_G +#print axioms Fl4Proofs.P3.TopPostDMXPG +#print axioms Fl4Proofs.P3.TopPostRMXG +#print axioms Fl4Proofs.P3.TopPostRMX_G +#print axioms Fl4Proofs.P3.DecOKDMXPG +#print axioms Fl4Proofs.P3.DecOKRMXG +#print axioms Fl4Proofs.P3.XCapPG +#print axioms Fl4Proofs.P3.XCapP_G +#print axioms Fl4Proofs.P3.HIPostMXPG +#print axioms Fl4Proofs.P3.ifP_ok +#print axioms Fl4Proofs.P3.ifP_X +#print axioms Fl4Proofs.P3.handle_invocation_refinesMXPG +#print axioms Fl4Proofs.P3.HIPostMXP_G +#print axioms Fl4Proofs.P3.handle_invocation_refinesMXP +#print axioms Fl4Proofs.P3.hi_memVF +#print axioms Fl4Proofs.P3.hiMEV_run +#print axioms Fl4Proofs.P3.hiMFinVF_ok +#print axioms Fl4Proofs.P3.natK_tcbW +#print axioms Fl4Proofs.P3.JAtZB.regWrJZ +#print axioms Fl4Proofs.P3.JAtZB.regWrJ +#print axioms Fl4Proofs.P3.JAtZ.regWrJ +#print axioms Fl4Proofs.P3.JAtZB.runJDB +#print axioms Fl4Proofs.P3.JAtZB.runJ +#print axioms Fl4Proofs.P3.JAtZ.runJD +#print axioms Fl4Proofs.P3.JAtZ.runJ +#print axioms Fl4Proofs.P3.JAtZB.userW_nat +#print axioms Fl4Proofs.P3.JAtZB.userWrN +#print axioms Fl4Proofs.P3.JAtZB.setmrJ +#print axioms Fl4Proofs.P3.JAtZ.setmrJ +#print axioms Fl4Proofs.P3.JAtZB.replyTailJ +#print axioms Fl4Proofs.P3.JAtZ.replyTailJ +#print axioms Fl4Proofs.P3.JAtZB.flTailJ +#print axioms Fl4Proofs.P3.JAtZ.flTailJ +#print axioms Fl4Proofs.P3.JAtZB.replyErrJ +#print axioms Fl4Proofs.P3.JAtZ.replyErrJ +#print axioms Fl4Proofs.P3.JAtZB.replyFailJ +#print axioms Fl4Proofs.P3.JAtZ.replyFailJ +#print axioms Fl4Proofs.P3.JAtZB.bufWrites +#print axioms Fl4Proofs.P3.JAtZ.bufWrites +#print axioms Fl4Proofs.P3.JAtZB.bufRebase +#print axioms Fl4Proofs.P3.JAtZ.bufRebase +#print axioms Fl4Proofs.P3.JAtZB.bufRebaseX +#print axioms Fl4Proofs.P3.JAtZ.bufRebaseX +#print axioms Fl4Proofs.P3.JAtZB.unblockRJ +#print axioms Fl4Proofs.P3.JAtZ.unblockRJ +#print axioms Fl4Proofs.P3.JAtZB.unblockJR +#print axioms Fl4Proofs.P3.JAtZB.sendUnblockJ +#print axioms Fl4Proofs.P3.JAtZ.sendUnblockJ +#print axioms Fl4Proofs.P3.JAtZB.sendSwitchJ +#print axioms Fl4Proofs.P3.JAtZ.sendSwitchJ +#print axioms Fl4Proofs.P3.JAtZB.sendTailJ +#print axioms Fl4Proofs.P3.JAtZ.sendTailJ +#print axioms Fl4Proofs.P3.JAtN +#print axioms Fl4Proofs.P3.JAtN.toJAt +#print axioms Fl4Proofs.P3.JAtN.of +#print axioms Fl4Proofs.P3.JAtN.post +#print axioms Fl4Proofs.P3.JAtZB.noFaultJ +#print axioms Fl4Proofs.P3.JAtZ.noFaultJ +#print axioms Fl4Proofs.P3.zv_bfrt +#print axioms Fl4Proofs.P3.natK_bfrt +#print axioms Fl4Proofs.P3.JAtZB.faultBlockJ +#print axioms Fl4Proofs.P3.JAtZ.faultBlockJ +#print axioms Fl4Proofs.P3.zvk_dwfr +#print axioms Fl4Proofs.P3.zvk_ciSt +#print axioms Fl4Proofs.P3.zvk_pushSt +#print axioms Fl4Proofs.P3.natK_dwfr +#print axioms Fl4Proofs.P3.natK_ciSt +#print axioms Fl4Proofs.P3.natK_pushSt +#print axioms Fl4Proofs.P3.JAtZB.sendFaultIJ +#print axioms Fl4Proofs.P3.JAtZ.sendFaultIJ +#print axioms Fl4Proofs.P3.JAtZB.sendFaultPJ +#print axioms Fl4Proofs.P3.JAtZ.sendFaultPJ +#print axioms Fl4Proofs.P3.JAtZB.sendFaultPDJ +#print axioms Fl4Proofs.P3.JAtZ.sendFaultPDJ +#print axioms Fl4Proofs.P3.JAtZB.faultRecvJ +#print axioms Fl4Proofs.P3.JAtZ.faultRecvJ +#print axioms Fl4Proofs.P3.JAtZB.faultHypJZ +#print axioms Fl4Proofs.P3.JAtZ.faultHypJZ +#print axioms Fl4Proofs.P3.VmEptState.handleFaultV +#print axioms Fl4Proofs.P3.VmEptState.extraV +#print axioms Fl4Proofs.P3.VmEptState.flTailV +#print axioms Fl4Proofs.P3.VmEptState.replyFailV +#print axioms Fl4Proofs.P3.VEAny.repS +#print axioms Fl4Proofs.P3.VEAny.repF +#print axioms Fl4Proofs.P3.Vs.dk_getVcpuV +#print axioms Fl4Proofs.P3.Vs.dk_vcpuDetachF +#print axioms Fl4Proofs.P3.Vs.dk_guestUnmapV +#print axioms Fl4Proofs.P3.Vs.dk_ioPortRevokeV +#print axioms Fl4Proofs.P3.Vs.dk_getEptV +#print axioms Fl4Proofs.P3.Vs.dk_finaliseCapVF +#print axioms Fl4Proofs.P3.Vs.dk_recDelFG +#print axioms Fl4Proofs.P3.Vs.dk_recDelG +#print axioms Fl4Proofs.P3.Vs.dk_capDeleteG +#print axioms Fl4Proofs.P3.Vs.dk_capRevokeFG +#print axioms Fl4Proofs.P3.Vs.dk_capRevokeG +#print axioms Fl4Proofs.P3.Vs.dk_capDeleteVF +#print axioms Fl4Proofs.P3.Vs.dk_capRevokeVF +#print axioms Fl4Proofs.P3.Vs.dke_invokeCnodeVF +#print axioms Fl4Proofs.P3.Vs.dke_installTcbCapVF +#print axioms Fl4Proofs.P3.Vs.dke_installTcbFrameCapVF +#print axioms Fl4Proofs.P3.Vs.dke_invokeTcbVF +#print axioms Fl4Proofs.P3.Vs.dk_sendSignalVF +#print axioms Fl4Proofs.P3.Vs.dke_fl4InvokeUntypedV +#print axioms Fl4Proofs.P3.Vs.dk_performVcpuInvocationF +#print axioms Fl4Proofs.P3.Vs.dk_performEptInvocation +#print axioms Fl4Proofs.P3.Vs.dke_invokeSetEptRootF +#print axioms Fl4Proofs.P3.Vs.DKE.ctK +#print axioms Fl4Proofs.P3.perfCurKeepVF +#print axioms Fl4Proofs.P3.pp_err_uniq +#print axioms Fl4Proofs.P3.VmEptPre.relTopM +#print axioms Fl4Proofs.P3.VEAny.relTop +#print axioms Fl4Proofs.P3.VDispPostVE.toG +#print axioms Fl4Proofs.P3.VmEptState.handleInvocation +#print axioms Fl4Proofs.P3.JAtZB.timestampJH +#print axioms Fl4Proofs.P3.JAtZB.toHole +#print axioms Fl4Proofs.P3.JAtZB.ppJHM +#print axioms Fl4Proofs.P3.JAtZB.ppJHC +#print axioms Fl4Proofs.P3.mcsN_toJAt +#print axioms Fl4Proofs.P3.JHole.toJ +#print axioms Fl4Proofs.P3.JHole.chargeBudgetJ +#print axioms Fl4Proofs.P3.JHole.checkBudgetF +#print axioms Fl4Proofs.P3.JHole.chargeBudgetUJ +#print axioms Fl4Proofs.P3.JHole.checkBudgetFI +#print axioms Fl4Proofs.P3.JHole.mcsPPJSM +#print axioms Fl4Proofs.P3.JHole.mcsPPJCM +#print axioms Fl4Proofs.P3.JHole.mcsPPJUM +#print axioms Fl4Proofs.P3.JHole.mcsPPJIM +#print axioms Fl4Proofs.P3.JHole.mcsPPJZM +#print axioms Fl4Proofs.P3.JAtZ.ppJHM +#print axioms Fl4Proofs.P3.hPre_ofZQIMNM +#print axioms Fl4Proofs.P3.JAtZB.schW_nv +#print axioms Fl4Proofs.P3.JAtZB.schW_ntd +#print axioms Fl4Proofs.P3.JAtZB.schW_scKeep +#print axioms Fl4Proofs.P3.JAtZB.schW_notDbg +#print axioms Fl4Proofs.P3.schW_keepsB +#print axioms Fl4Proofs.P3.jowes_schedDB +#print axioms Fl4Proofs.P3.JAtZB.restartRest +#print axioms Fl4Proofs.P3.JAtZB.restartJB +#print axioms Fl4Proofs.P3.JAtZB.schedJ +#print axioms Fl4Proofs.P3.JAtZB.reschedJ +#print axioms Fl4Proofs.P3.JAtZB.restartRunJ +#print axioms Fl4Proofs.P3.JAtZ.schedJ +#print axioms Fl4Proofs.P3.JAtZ.reschedJ +#print axioms Fl4Proofs.P3.JAtZ.restartRunJ +#print axioms Fl4Proofs.P3.jowes_sched +#print axioms Fl4Proofs.P3.jowes_restartD +#print axioms Fl4Proofs.P3.Sched.ScOnly.natK +#print axioms Fl4Proofs.P3.JAtZB.reprogramN +#print axioms Fl4Proofs.P3.JTH.tmoBlockJA +#print axioms Fl4Proofs.P3.JTH.tmoBlockJ +#print axioms Fl4Proofs.P3.JTH.endTimesliceTmoJA +#print axioms Fl4Proofs.P3.JTH.endTimesliceTmoJ +#print axioms Fl4Proofs.P3.JHole.chargeBudgetTmoJA +#print axioms Fl4Proofs.P3.JHole.chargeBudgetTmoJ +#print axioms Fl4Proofs.P3.JHole.checkBudgetTA +#print axioms Fl4Proofs.P3.JHole.checkBudgetT +#print axioms Fl4Proofs.P3.JHole.checkBudgetTR +#print axioms Fl4Proofs.P3.JHole.chargeBudgetTmoJR +#print axioms Fl4Proofs.P3.JTH.endTimesliceTmoJR +#print axioms Fl4Proofs.P3.natK_kfr +#print axioms Fl4Proofs.P3.JTH.tmoBaseCtJ +#print axioms Fl4Proofs.P3.JAtZB.sendTmoRecvCtIJ +#print axioms Fl4Proofs.P3.JAtZB.sendTmoRecvCtPJ +#print axioms Fl4Proofs.P3.JAtZ.sendTmoRecvCtIJ +#print axioms Fl4Proofs.P3.JAtZ.sendTmoRecvCtPJ +#print axioms Fl4Proofs.P3.JTH.tmoRecvJ +#print axioms Fl4Proofs.P3.JAtZ.budgetOkT +#print axioms Fl4Proofs.P3.JAtZ.budgetOkTR +#print axioms Fl4Proofs.P3.JHole.mcsPPJZMF +#print axioms Fl4Proofs.P3.JHole.afterInvJZIMN +#print axioms Fl4Proofs.P3.JHole.mcsPPJAM +#print axioms Fl4Proofs.P3.JHole.mcsPPJRM +#print axioms Fl4Proofs.P3.JAtN.toJStab +#print axioms Fl4Proofs.P3.JHole.mcsCovSt +#print axioms Fl4Proofs.P3.JHole.mcsInactSt +#print axioms Fl4Proofs.P3.JHole.mcsUSt +#print axioms Fl4Proofs.P3.JHole.mcsStK +#print axioms Fl4Proofs.P3.JHole.mcsSt +#print axioms Fl4Proofs.P3.JHole.afterInvSt +#print axioms Fl4Proofs.P3.JAtZB.workUnitsN +#print axioms Fl4Proofs.P3.hPre_ofZQIMN +#print axioms Fl4Proofs.P3.JAtZB.capN +#print axioms Fl4Proofs.P3.JAtZB.slotN +#print axioms Fl4Proofs.P3.JAtZB.signal_waitDJ +#print axioms Fl4Proofs.P3.JAtZB.signal_boundDJ +#print axioms Fl4Proofs.P3.JAtZ.signal_waitDJ +#print axioms Fl4Proofs.P3.JAtZ.signal_boundDJ +#print axioms Fl4Proofs.P3.JAtZB.signal_atN +#print axioms Fl4Proofs.P3.JAtZ.signal_atN +#print axioms Fl4Proofs.P3.JHole.handleIrqJN +#print axioms Fl4Proofs.P3.JAtZB.msArJ +#print axioms Fl4Proofs.P3.JAtZB.armedN +#print axioms Fl4Proofs.P3.JAtZB.armedJ +#print axioms Fl4Proofs.P3.JAtZB.handleIrqJB +#print axioms Fl4Proofs.P3.JAtN.trans +#print axioms Fl4Proofs.P3.JAtZB.handleIrqJBT +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJJN +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJIN +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJIAN +#print axioms Fl4Proofs.P3.JAtZB.irqTailB +#print axioms Fl4Proofs.P3.afterInv_of_mcsIMNB +#print axioms Fl4Proofs.P3.afterInv_of_mcsIMN +#print axioms Fl4Proofs.P3.JAtZB.handleIrqJBM +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJIM +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJIMSt +#print axioms Fl4Proofs.P3.JAtZ.handleIrqJIANM +#print axioms Fl4Proofs.P3.Mc.projW_of_cur0wNB +#print axioms Fl4Proofs.P3.Mc.noBufCap_ckiB +#print axioms Fl4Proofs.P3.Mc.JAtZB.handleIrqFt +#print axioms Fl4Proofs.P3.midXP_of_pre +#print axioms Fl4Proofs.P3.natK_ntfnUpd +#print axioms Fl4Proofs.P3.JAtZB.badgeN +#print axioms Fl4Proofs.P3.JAtZB.signal_atNV +#print axioms Fl4Proofs.P3.JAtZB.repKh +#print axioms Fl4Proofs.P3.JAtZV3.repKh +#print axioms Fl4Proofs.P3.VmBase.sigCompR +#print axioms Fl4Proofs.P3.JAtZV3.sigCompR +#print axioms Fl4Proofs.P3.signalVmWG +#print axioms Fl4Proofs.P3.JAtZV3.signalVmW +#print axioms Fl4Proofs.P3.sigSporG +#print axioms Fl4Proofs.P3.JAtZV3.sigSporJ +#print axioms Fl4Proofs.P3.sigRestG +#print axioms Fl4Proofs.P3.JAtZV3.sigRestJ +#print axioms Fl4Proofs.P3.sigVmTailG +#print axioms Fl4Proofs.P3.sigVmTailJ3_of +#print axioms Fl4Proofs.P3.sigVmDonG +#print axioms Fl4Proofs.P3.sigVmDonJ3_of +#print axioms Fl4Proofs.P3.JAtZV3.signalVmJ3 +#print axioms Fl4Proofs.P3.v3_sigComp_one +#print axioms Fl4Proofs.P3.v3_ssVF_nvm +#print axioms Fl4Proofs.P3.VmEptState.signalVm +#print axioms Fl4Proofs.P3.VmEptState.signalVF +#print axioms Fl4Proofs.P3.hiS +#print axioms Fl4Proofs.P3.handleInterrupt_hiS +#print axioms Fl4Proofs.P3.mem_hiS_big +#print axioms Fl4Proofs.P3.fail_hiS_inactive +#print axioms Fl4Proofs.P3.mem_hiS_reserved +#print axioms Fl4Proofs.P3.mem_hiS_timer +#print axioms Fl4Proofs.P3.mem_hiS_signal +#print axioms Fl4Proofs.P3.mem_hi_big +#print axioms Fl4Proofs.P3.fail_hi_inactive +#print axioms Fl4Proofs.P3.mem_hi_reserved +#print axioms Fl4Proofs.P3.mem_hi_timer +#print axioms Fl4Proofs.P3.mem_hi_signal +#print axioms Fl4Proofs.P3.JAtZB.handleIrqJG +#print axioms Fl4Proofs.P3.isRunVMF +#print axioms Fl4Proofs.P3.onCoreEff +#print axioms Fl4Proofs.P3.remCurEff +#print axioms Fl4Proofs.P3.OrcAg +#print axioms Fl4Proofs.P3.vmSC_congr +#print axioms Fl4Proofs.P3.sendSignalVF_congr +#print axioms Fl4Proofs.P3.handleInterruptVF_hiS +#print axioms Fl4Proofs.P3.VmOrc +#print axioms Fl4Proofs.P3.VmOrc.keep +#print axioms Fl4Proofs.P3.JAtZB.vmOrcEff +#print axioms Fl4Proofs.P3.VmEptState.signalVFo +#print axioms Fl4Proofs.P3.VmEptState.handleIrqVF +#print axioms Fl4Proofs.P3.FireG +#print axioms Fl4Proofs.P3.FireInvG +#print axioms Fl4Proofs.P3.fire_loopG +#print axioms Fl4Proofs.P3.fire_loopE +#print axioms Fl4Proofs.P3.fire_loopJ +#print axioms Fl4Proofs.P3.fire_loopJB +#print axioms Fl4Proofs.P2.Stall.FFoot.tcbK +#print axioms Fl4Proofs.P2.Stall.FFoot.affK +#print axioms Fl4Proofs.P2.Stall.FFoot.curK +#print axioms Fl4Proofs.P2.Stall.vcpu.report.ff +#print axioms Fl4Proofs.P2.Stall.notification.send_signal.ffG +#print axioms Fl4Proofs.P2.Stall.notification.send_signal.fk +#print axioms Fl4Proofs.P3.RvmSub.trans +#print axioms Fl4Proofs.P3.RvmSub.refl +#print axioms Fl4Proofs.P3.ZvK.rvm +#print axioms Fl4Proofs.P3.VmEptState.signalVmK +#print axioms Fl4Proofs.P3.VmEptState.signalVFK +#print axioms Fl4Proofs.P3.VmEptState.signalVFk +#print axioms Fl4Proofs.P3.JAtZB.tmwN +#print axioms Fl4Proofs.P3.VmOrc.tmw +#print axioms Fl4Proofs.P3.fireG_sendSignalVF +#print axioms Fl4Proofs.P3.VmEptState.fire_loopVF +#print axioms Fl4Proofs.P1.TmoKC.v +#print axioms Fl4Proofs.P1.sched.end_timeslice.allGNv +#print axioms Fl4Proofs.P1.sched.end_timeslice.allGN +#print axioms Fl4Proofs.P1.sched.charge_budget.allGNv +#print axioms Fl4Proofs.P1.sched.charge_budget.allGN +#print axioms Fl4Proofs.P1.sched.check_budget.allGNv +#print axioms Fl4Proofs.P1.sched.check_budget.allGN +#print axioms Fl4Proofs.P3.ppG +#print axioms Fl4Proofs.P3.preemptionPath_ppG +#print axioms Fl4Proofs.P3.mem_ppG_sched +#print axioms Fl4Proofs.P3.mem_ppG_charge +#print axioms Fl4Proofs.P3.fail_ppG_sched +#print axioms Fl4Proofs.P3.fail_ppG_charge +#print axioms Fl4Proofs.P3.mem_pp_sched +#print axioms Fl4Proofs.P3.fail_pp_charge +#print axioms Fl4Proofs.P3.JHole.mcsPPJZMFG +#print axioms Fl4Proofs.P3.JHole.mcsPPJZMG +#print axioms Fl4Proofs.P2.Stall.syscall.mcs_preemption_point.tmoN +#print axioms Fl4Proofs.P2.Stall.syscall.mcs_preemption_point.rrN +#print axioms Fl4Proofs.P3.preemptionPathVF_ppG +#print axioms Fl4Proofs.P3.mem_maybeHandleVF_none +#print axioms Fl4Proofs.P3.mem_maybeHandleVF_some +#print axioms Fl4Proofs.P3.handle_timeout_blkN +#print axioms Fl4Proofs.P3.JHole.mcsFootN +#print axioms Fl4Proofs.P3.FootN.vmOrc +#print axioms Fl4Proofs.P3.VmEptPre.preemptPathVF +#print axioms Fl4Proofs.P3.VmEptState.fireVF +#print axioms Fl4Proofs.P3.JAtZB.tmArm_w +#print axioms Fl4Proofs.P3.mfk_sendSignalVF +#print axioms Fl4Proofs.P3.footN_tmArm +#print axioms Fl4Proofs.P3.msig_sendSignalVF +#print axioms Fl4Proofs.P3.VmEptState.handleIrqVFk +#print axioms Fl4Proofs.P3.mem_ppG_inact +#print axioms Fl4Proofs.P3.fail_ppG_inact +#print axioms Fl4Proofs.P3.mem_pp_inact +#print axioms Fl4Proofs.P3.fail_pp_inact +#print axioms Fl4Proofs.P3.JHole.mcsPPJSMG +#print axioms Fl4Proofs.P3.JHole.mcsPPJCMG +#print axioms Fl4Proofs.P3.JHole.mcsPPJUMG +#print axioms Fl4Proofs.P3.JHole.mcsPPJIMG +#print axioms Fl4Proofs.P3.JHole.mcsPPJAMG +#print axioms Fl4Proofs.P3.TmoBlk +#print axioms Fl4Proofs.P3.JHole.sched_of_F +#print axioms Fl4Proofs.P3.JHole.mcsFootNG +#print axioms Fl4Proofs.P3.JHole.mcsPPVF +#print axioms Fl4Proofs.P3.VmEptPre.preemptPathVFk +#print axioms Fl4Proofs.P3.VmEptState.awakenVF +#print axioms Fl4Proofs.P3.VmEptState.scheduleVF +#print axioms Fl4Proofs.P3.JAtZB.jat_scheduleFRG +#print axioms Fl4Proofs.P3.JAtZB.jat_scheduleFR +#print axioms Fl4Proofs.P3.natK_otk +#print axioms Fl4Proofs.P3.Sched.awaken_refinesW +#print axioms Fl4Proofs.P3.Sched.schedule_refinesWP +#print axioms Fl4Proofs.P3.Sched.schedule_refinesW +#print axioms Fl4Proofs.P3.Sched.awaken_refinesW0 +#print axioms Fl4Proofs.P3.Sched.schedule_refinesWP0 +#print axioms Fl4Proofs.P3.Sched.awaken_refinesW0R +#print axioms Fl4Proofs.P3.Sched.schedule_refinesWP0FRA +#print axioms Fl4Proofs.P1.XferOK.at +#print axioms Fl4Proofs.P1.endpoint.send_ipc.ipcT +#print axioms Fl4Proofs.P1.faults.handle_timeout.bxiT +#print axioms Fl4Proofs.P1.xferOKAt_fault +#print axioms Fl4Proofs.P1.endpoint.send_ipc.footPNT +#print axioms Fl4Proofs.P2.Stall.syscall.mcs_preemption_point.tmoNG +#print axioms Fl4Proofs.P3.IpcFootN.vmOrc +#print axioms Fl4Proofs.P3.JHole.mcsPPJRMG +#print axioms Fl4Proofs.P3.handle_timeout_ipcN +#print axioms Fl4Proofs.P3.OmegaB +#print axioms Fl4Proofs.P3.JHole.mcsTmoG +#print axioms Fl4Proofs.P3.JHole.mcsIpcN +#print axioms Fl4Proofs.P3.PPRecv +#print axioms Fl4Proofs.P3.SInvAll.OIx.ne +#print axioms Fl4Proofs.P3.SInvAll.oiQ_of_ne +#print axioms Fl4Proofs.P3.SInvAll.oi_setThreadState +#print axioms Fl4Proofs.P3.SInvAll.oi_defaultTcb +#print axioms Fl4Proofs.P3.SInvAll.oi_fl4PerformInvocation +#print axioms Fl4Proofs.P3.SInvAll.oi_getVcpuV +#print axioms Fl4Proofs.P3.SInvAll.oi_vcpuUpdateV +#print axioms Fl4Proofs.P3.SInvAll.oi_vmReportF +#print axioms Fl4Proofs.P3.SInvAll.oi_vcpuDetachF +#print axioms Fl4Proofs.P3.SInvAll.oi_guestUnmapV +#print axioms Fl4Proofs.P3.SInvAll.oi_ioPortRevokeV +#print axioms Fl4Proofs.P3.SInvAll.relk_of_oi +#print axioms Fl4Proofs.P3.SInvAll.oi_finaliseCapVF +#print axioms Fl4Proofs.P3.SInvAll.oi_recDelFG +#print axioms Fl4Proofs.P3.SInvAll.oi_recDelG +#print axioms Fl4Proofs.P3.SInvAll.oi_capDeleteG +#print axioms Fl4Proofs.P3.SInvAll.oi_capRevokeFG +#print axioms Fl4Proofs.P3.SInvAll.oi_capRevokeG +#print axioms Fl4Proofs.P3.SInvAll.oi_capDeleteVF +#print axioms Fl4Proofs.P3.SInvAll.oi_capRevokeVF +#print axioms Fl4Proofs.P3.SInvAll.oi_invokeCnodeVF +#print axioms Fl4Proofs.P3.SInvAll.oi_installTcbCapVF +#print axioms Fl4Proofs.P3.SInvAll.oi_installTcbFrameCapVF +#print axioms Fl4Proofs.P3.SInvAll.oi_invokeTcbVF +#print axioms Fl4Proofs.P3.SInvAll.oi_sendSignalVF +#print axioms Fl4Proofs.P3.SInvAll.oi_fl4InvokeUntypedV +#print axioms Fl4Proofs.P3.SInvAll.oi_performVcpuInvocationF +#print axioms Fl4Proofs.P3.SInvAll.oi_performEptInvocation +#print axioms Fl4Proofs.P3.SInvAll.oi_invokeSetEptRootF +#print axioms Fl4Proofs.P3.SInvAll.oi_fl4PerformInvocationVF +#print axioms Fl4Proofs.P3.SInvAll.kentry_onlyIdle +#print axioms Fl4Proofs.P3.RunningVM +#print axioms Fl4Proofs.P3.perfRvmVF +#print axioms Fl4Proofs.P3.perfCtNVmVF +#print axioms Fl4Proofs.P3.JKern.kwApartJ +#print axioms Fl4Proofs.P3.JKern.fire_ks +#print axioms Fl4Proofs.P3.JKern.ndOK_fire +#print axioms Fl4Proofs.P3.fpuOwnOK_of_own +#print axioms Fl4Proofs.P3.rootFr_of +#print axioms Fl4Proofs.P3.idleVt_ofSlots +#print axioms Fl4Proofs.P3.vsRootOK_ofJ +#print axioms Fl4Proofs.P3.SInvR.G5.kfin_tail_at +#print axioms Fl4Proofs.P3.Vs.owk_lookupIpcBuffer' +#print axioms Fl4Proofs.P3.Vs.owk_zipWithMx' +#print axioms Fl4Proofs.P3.Vs.owk_storeWordOffs' +#print axioms Fl4Proofs.P3.Vs.owk_setMrs' +#print axioms Fl4Proofs.P3.Vs.owk_sendSignalVF +#print axioms Fl4Proofs.P3.Vs.crk_lookupIpcBuffer' +#print axioms Fl4Proofs.P3.Vs.crk_zipWithMx' +#print axioms Fl4Proofs.P3.Vs.crk_storeWordOffs' +#print axioms Fl4Proofs.P3.Vs.crk_setMrs' +#print axioms Fl4Proofs.P3.Vs.crk_sendSignalVF +#print axioms Fl4Proofs.P3.Vs.fk_fl4AwakenVF +#print axioms Fl4Proofs.P3.Vs.owF_awakenVF +#print axioms Fl4Proofs.P3.Vs.crF_awakenVF +#print axioms Fl4Proofs.P3.Vs.awakenVF_dom +#print axioms Fl4Proofs.P3.JAtZB.vsRootOK +#print axioms Fl4Proofs.P3.JAtZB.rootFr +#print axioms Fl4Proofs.P3.JAtZB.fire_ks +#print axioms Fl4Proofs.P3.JAtZB.ndOK_awakenVF +#print axioms Fl4Proofs.P3.JAtZB.fpuOwnOK_awakenVF +#print axioms Fl4Proofs.P3.JAtZB.idleVt_awakenVF +#print axioms Fl4Proofs.P3.kfin_tail_ofB +#print axioms Fl4Proofs.P3.VmEptState.ntfnIdle +#print axioms Fl4Proofs.P3.VmEptState.ckRep +#print axioms Fl4Proofs.P3.VmEptState.ckIdle +#print axioms Fl4Proofs.P3.VmEptState.checkJ +#print axioms Fl4Proofs.P3.VmEptState.checkCur +#print axioms Fl4Proofs.P3.vmCheckNPG +#print axioms Fl4Proofs.P3.vmCheckG +#print axioms Fl4Proofs.P3.JAtZB.repCur +#print axioms Fl4Proofs.P3.JAtZV3.ckRep +#print axioms Fl4Proofs.P3.JAtZV3.ckIdle +#print axioms Fl4Proofs.P3.JAtZV3.checkJ +#print axioms Fl4Proofs.P3.JAtZV3.checkNP +#print axioms Fl4Proofs.P3.activateThreadV_eqY +#print axioms Fl4Proofs.P3.actRestSV +#print axioms Fl4Proofs.P3.VmEptState.actRestV +#print axioms Fl4Proofs.P3.VmEptState.activateV +#print axioms Fl4Proofs.P3.VmEptState.finishVF +#print axioms Fl4Proofs.P3.SInv.ct_fl4DecodeInvocationV +#print axioms Fl4Proofs.P3.errK_bind +#print axioms Fl4Proofs.P3.sts_restart_nrvm +#print axioms Fl4Proofs.P3.hiG_err_nrvm +#print axioms Fl4Proofs.P3.hiVF_err_nrvm +#print axioms Fl4Proofs.P3.JAtZB.frontEx +#print axioms Fl4Proofs.P3.JAtZ.frontEx +#print axioms Fl4Proofs.P3.VmEptState.handleInvocationE +#print axioms Fl4Proofs.P3.VmEptState.afterV +#print axioms Fl4Proofs.P3.JAtZB.jat_scheduleFRGF +#print axioms Fl4Proofs.P3.decode_loop3_eq_revoke +#print axioms Fl4Proofs.P3.VmEptState.revokeWalk +#print axioms Fl4Proofs.P3.VmBase.ioOwnJ +#print axioms Fl4Proofs.P3.VmEptState.ioOwnJ +#print axioms Fl4Proofs.P3.MdbStep.frameAlias +#print axioms Fl4Proofs.P3.Vs.VsMdbInv.frameAlias +#print axioms Fl4Proofs.P3.Vs.FrameInv.alias' +#print axioms Fl4Proofs.P3.jowes_slotDFH +#print axioms Fl4Proofs.P3.vcpu_arg_or_zero +#print axioms Fl4Proofs.P3.VmEptState.vcpuDecodeJ +#print axioms Fl4Proofs.P3.VmEptState.vcpuDisp +#print axioms Fl4Proofs.P3.VmEptState.frameMapEptReject +#print axioms Fl4Proofs.P3.VmEptState.frameOtherDisp +#print axioms Fl4Proofs.P3.VmEptState.frameGetAddrDisp +#print axioms Fl4Proofs.P3.VmEptState.frameTacDisp +#print axioms Fl4Proofs.P3.VmEptState.frameDeriveDisp +#print axioms Fl4Proofs.P3.VmEptState.ioPortDisp +#print axioms Fl4Proofs.P3.VmEptState.dispatchAt +#print axioms Fl4Proofs.P3.JAtZB.subInsQ +#print axioms Fl4Proofs.P3.insert_subframesQ +#print axioms Fl4Proofs.P3.derive_subframeQ +#print axioms Fl4Proofs.P3.Vs.specTail_one_after_restart +#print axioms Fl4Proofs.P3.tac_gen_leaf +#print axioms Fl4Proofs.P3.JAtZB.frameWrJCore +#print axioms Fl4Spec.handleSavedIrqVF +#print axioms Fl4Spec.handleSavedIrqVF_inactive +#print axioms Fl4Spec.handleSavedIrqVF_eq +#print axioms Fl4Spec.fl4VcpuExitSavedVF +#print axioms Fl4Spec.fl4VcpuExitSavedVF_none +#print axioms Fl4Spec.fl4VcpuExitSavedVF_eq +#print axioms Fl4Proofs.P3.JAtZ.utCheckB +#print axioms Fl4Proofs.P3.JAtZB.entryInv +#print axioms Fl4Proofs.P3.JAtZB.faultEntryBlock +#print axioms Fl4Proofs.P3.JAtZB.faultHypJZG +#print axioms Fl4Proofs.P3.JAtZB.setRunnableVmJD +#print axioms Fl4Proofs.P3.JAtZB.utCheckNat +#print axioms Fl4Proofs.P3.JHole.checkBudgetFG +#print axioms Fl4Proofs.P3.JHole.checkBudgetNat +#print axioms Fl4Proofs.P3.VmBase.boundIff +#print axioms Fl4Proofs.P3.VmBase.ofBSSCore +#print axioms Fl4Proofs.P3.VmBaseF.reportRunnableJ +#print axioms Fl4Proofs.P3.VmBaseF.reportRunningJ +#print axioms Fl4Proofs.P3.VmBaseF.stageEnter +#print axioms Fl4Proofs.P3.VmBaseF.validClr +#print axioms Fl4Proofs.P3.VmEptState.budgetV +#print axioms Fl4Proofs.P3.VmEptState.checkTimestampHole +#print axioms Fl4Proofs.P3.VmEptState.dispatchV +#print axioms Fl4Proofs.P3.VmEptState.enterRunning +#print axioms Fl4Proofs.P3.VmEptState.handleSavedIrqV +#print axioms Fl4Proofs.P3.VmEptState.interruptEntry +#print axioms Fl4Proofs.P3.VmEptState.kernel_entry +#print axioms Fl4Proofs.P3.VmEptState.trapSyscallEntry +#print axioms Fl4Proofs.P3.VmEptState.unknownSyscallEntry +#print axioms Fl4Proofs.P3.VmEptState.userExceptionEntry +#print axioms Fl4Proofs.P3.VmEptState.vcpuExitStalled +#print axioms Fl4Proofs.P3.VmEptState.vcpuExitUnstalled +#print axioms Fl4Proofs.P3.VmEptState.vmEnterEntry +#print axioms Fl4Proofs.P3.VmEptState.vmFaultEntry +#print axioms Fl4Proofs.P3.enterArg +#print axioms Fl4Proofs.P3.handleFault_ep_wp +#print axioms Fl4Proofs.P3.v3_validR +#print axioms Fl4Proofs.P3.virtualizationGuard +#print axioms Fl4Proofs.P3.vmEnterF_staged