From ec5ae0ad4c1106279554707e1ac3eaaeab6bcec0 Mon Sep 17 00:00:00 2001 From: CommaBot Date: Thu, 3 Dec 2026 16:08:29 +0900 Subject: [PATCH] P1 (aarch64): complete the S1A step over every decode arm and the non-decode kernel functions Extends #151's s1aStepR2K: - syscall.decode_invocation.s1aStepR2All: the S1a step (S1aR2, S1aKtUt, S1aHiK) over every AArch64 decode arm (DecArmS1aAll), adding the rejected and unknown-label arms, TCB WriteFPU / SetTimer / BindNotification / Resume / Write/CopyRegisters, CNode CancelBadgedSends, SchedContext Bind / YieldTo, SchedControl ConfigureFlags and Reply. Frame DeriveSubframe stays open (FrObj exact size, SysL.sub_false). - Boot: SymL at w0/w1 and DelIn at w0/w1 under a new [P] BootCanon (boot objects in the kernel window, witness bootCanon_ex), so w1K_bundleOf is unconditional. - Non-decode kernel functions: faults and timeouts, budget checks, yield, receive, interrupts and VCPU exits, reply_error / reply_success, the MCS preemption point, each re-establishing the S1a step. - S1aStepEnt / s1aStepEntAll: the entry-invariant fields in P1 terms on the fixed-heap arms (Retype and MakePool-create open). Entry wrappers are composed at the entry level. Every statement already on main is unchanged. Co-Authored-By: Claude Opus 5.5 --- DESIGN.md | 2 +- README.md | 53 +- proofs/Fl4ProofsA64.lean | 42 + proofs/Fl4ProofsA64/P1/S1aBootDel0.lean | 107 ++ proofs/Fl4ProofsA64/P1/S1aBootDel1.lean | 140 ++ proofs/Fl4ProofsA64/P1/S1aCAll.lean | 164 +++ proofs/Fl4ProofsA64/P1/S1aCBootSym.lean | 129 ++ proofs/Fl4ProofsA64/P1/S1aCBudget.lean | 476 +++++++ proofs/Fl4ProofsA64/P1/S1aCBufAt.lean | 39 + proofs/Fl4ProofsA64/P1/S1aCCbs.lean | 345 +++++ proofs/Fl4ProofsA64/P1/S1aCCopyRegs.lean | 353 +++++ proofs/Fl4ProofsA64/P1/S1aCDm2.lean | 60 + proofs/Fl4ProofsA64/P1/S1aCEnt.lean | 191 +++ proofs/Fl4ProofsA64/P1/S1aCFault.lean | 156 +++ proofs/Fl4ProofsA64/P1/S1aCFinish.lean | 360 ++++++ proofs/Fl4ProofsA64/P1/S1aCFpu.lean | 195 +++ proofs/Fl4ProofsA64/P1/S1aCIrq.lean | 329 +++++ proofs/Fl4ProofsA64/P1/S1aCKeep.lean | 39 + proofs/Fl4ProofsA64/P1/S1aCNScW.lean | 127 ++ proofs/Fl4ProofsA64/P1/S1aCNtfnBind.lean | 211 +++ proofs/Fl4ProofsA64/P1/S1aCRecv.lean | 1422 +++++++++++++++++++++ proofs/Fl4ProofsA64/P1/S1aCRegs.lean | 233 ++++ proofs/Fl4ProofsA64/P1/S1aCRej.lean | 113 ++ proofs/Fl4ProofsA64/P1/S1aCReplyA.lean | 60 + proofs/Fl4ProofsA64/P1/S1aCReplyErr.lean | 146 +++ proofs/Fl4ProofsA64/P1/S1aCReplyM.lean | 266 ++++ proofs/Fl4ProofsA64/P1/S1aCReplyRm.lean | 181 +++ proofs/Fl4ProofsA64/P1/S1aCReplyT.lean | 123 ++ proofs/Fl4ProofsA64/P1/S1aCReplyTl.lean | 151 +++ proofs/Fl4ProofsA64/P1/S1aCReplyTo.lean | 111 ++ proofs/Fl4ProofsA64/P1/S1aCReplyW.lean | 61 + proofs/Fl4ProofsA64/P1/S1aCRestart.lean | 273 ++++ proofs/Fl4ProofsA64/P1/S1aCScBind.lean | 322 +++++ proofs/Fl4ProofsA64/P1/S1aCSched.lean | 920 +++++++++++++ proofs/Fl4ProofsA64/P1/S1aCSchedCtlA.lean | 105 ++ proofs/Fl4ProofsA64/P1/S1aCSchedCtlB.lean | 158 +++ proofs/Fl4ProofsA64/P1/S1aCSchedCtlC.lean | 352 +++++ proofs/Fl4ProofsA64/P1/S1aCSchedCtlD.lean | 166 +++ proofs/Fl4ProofsA64/P1/S1aCStall.lean | 126 ++ proofs/Fl4ProofsA64/P1/S1aCStepD.lean | 48 + proofs/Fl4ProofsA64/P1/S1aCTime.lean | 161 +++ proofs/Fl4ProofsA64/P1/S1aCTimer.lean | 195 +++ proofs/Fl4ProofsA64/P1/S1aCXferTy.lean | 169 +++ proofs/Fl4ProofsA64/P1/S1aCYield.lean | 184 +++ proofs/Fl4ProofsA64/P1/S1aCYieldTo.lean | 545 ++++++++ 45 files changed, 10088 insertions(+), 21 deletions(-) create mode 100644 proofs/Fl4ProofsA64/P1/S1aBootDel0.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aBootDel1.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCAll.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCBootSym.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCBudget.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCBufAt.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCCbs.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCCopyRegs.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCDm2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCEnt.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCFault.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCFinish.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCFpu.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCIrq.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCKeep.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCNScW.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCNtfnBind.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCRecv.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCRegs.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCRej.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyA.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyErr.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyM.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyRm.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyT.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyTl.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyTo.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCReplyW.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCRestart.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCScBind.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCSched.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCSchedCtlA.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCSchedCtlB.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCSchedCtlC.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCSchedCtlD.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCStall.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCStepD.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCTime.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCTimer.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCXferTy.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCYield.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aCYieldTo.lean diff --git a/DESIGN.md b/DESIGN.md index 466f388f2..4894b3028 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -423,7 +423,7 @@ The proof is staged so each level is useful by itself and later levels build on - Write footprints and frames for the native operations used by P3: cap-slot writes, installs, delete and finalisation, and VSpace operations. The native thread-finalisation leaf requires an unbound VCPU link. None of them breaks the invariant, and finalisation writes no cap slot. - The two conditions seL4's C code relies on without checking are P1 invariants, kept by every kernel entry: the current thread has an SC when `switch_sched_context` runs (`BoundInv.resume`, l4v `active_sc_tcb_at`), and a thread blocked on reply has a reply object (`ReplyInv0.reply`). - Typed-heap layout, object alignment and non-overlap appear as hypotheses (the sets P1 is parameterised by). CDT and untyped invariants are proved in P3 (`MdbOK`), not yet as P1 invariants. - - AArch64 (`proofs/Fl4ProofsA64/P1`, in progress): one capability invocation at a time, from P1's syscall-level bundle `SysL` (with `SymL`, the deletion input `DelIn` and the decode's placement facts). `syscall.decode_invocation.armQHAt` (`MdbArmQHD`) proves that every arm of `DecArmQH` ends in `ArmQIAt` (`SysL`, `SymL` and `BlkOK` at the result, plus the cap-only carries, including the page-table cap placement `PtCap`) and keeps the ASID table or zeroes an entry: CNode and deletion arms, TCB SetSchedParams / Suspend / ReadRegisters, IRQ control, Notification and Endpoint send, every VCPU invocation, and the VSpace arms (Stage-1 and `HighVSpace` Page / PageTable Map and Unmap, TestAndClearAccessed, the flushes, GetAddress, and every Stage-2 (EPT) operation). The step theorem is `syscall.decode_invocation.s1aStepR2K` (`S1aStepR2K`): on every arm of `DecArmS1aH` (`DecArmQH` plus Untyped Retype, ASIDPool Assign and ASIDControl MakePool) it takes, at entry, `S1aR2` (the VSpace record over the tables reachable from the ASID table: lookup, walks, root agreement, the Stage-1 and Stage-2 typings narrowed to reachable tables, exact path backing, footprint and placement), `S1aKtUt` (the kernel TTBR1 tables outside every Untyped) and `S1aHiK` (the levels of the kernel tables `Kt` and of the `HighVSpace` headers' copied descriptors, at the levels `KLv` of the platform contract `KTab`), and returns all three at the end, with `S1aStep`'s columns (`SysL`, `SymL`, the arm and cap columns, `PtCap`, `PtHG`, `HiCap511`, …; `S1aStepR2K.toR2` is `s1aStepR2`'s post). The boot witnesses give the entry (`w0_s1aStepEntryK`, `w1K_s1aStepEntryK`). Full typing of every live table is false on reachable states: `delete_asid_pool` leaves a mapped `HighVSpace` root whose private table still names a page table that can then be deleted and its memory retyped. So the deletion typing is the reachable one (`HiDelTyR`, a projection of `S1aR2`), and the tables an ASIDPool Assign makes reachable are typed by relabelling `S1aR2`'s levels on unreachable tables (`S1aR2.relabel`). Named premises: [P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), `KTab`, `A64FrameMasks`. Covered arms: Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and ASIDControl MakePool. Not covered on AArch64: Reply and SchedControl caps, direct `HighVSpace` invocations, CNode CancelBadgedSends, the TCB labels WriteRegisters, CopyRegisters, Resume, BindNotification, ConfigureSingleStepping, Set / Get / UnsetBreakpoint, SetTimer and WriteFPU, SchedContext Bind and YieldTo, Frame DeriveSubframe, and the unknown-label error branches. `IoPortControl`, `IoPort` and `TdxControl` are x86_64 only and do not apply on AArch64. Boundary: the theorem is about one `decode_invocation` of a `DecArmS1aH` arm, not `kernel_entry`, and it still takes entry-layer inputs its post does not return (`DelIn`, `DecPre`, `SysPlace`, the IRQ and slot-coverage facts `hIq` / `hSC`, and the thread facts `mcp`, `cs`, `fh`). The earlier tops `s1aStepH` / `s1aStepPt` / `s1aStepR2` remain, with their per-step inputs. + - AArch64 (`proofs/Fl4ProofsA64/P1`, in progress): one capability invocation at a time, from P1's syscall-level bundle `SysL` (with `SymL`, the deletion input `DelIn` and the decode's placement facts). `syscall.decode_invocation.armQHAt` (`MdbArmQHD`) proves that every arm of `DecArmQH` ends in `ArmQIAt` (`SysL`, `SymL` and `BlkOK` at the result, plus the cap-only carries, including the page-table cap placement `PtCap`) and keeps the ASID table or zeroes an entry: CNode and deletion arms, TCB SetSchedParams / Suspend / ReadRegisters, IRQ control, Notification and Endpoint send, every VCPU invocation, and the VSpace arms (Stage-1 and `HighVSpace` Page / PageTable Map and Unmap, TestAndClearAccessed, the flushes, GetAddress, and every Stage-2 (EPT) operation). The step theorem is `syscall.decode_invocation.s1aStepR2K` (`S1aStepR2K`): on every arm of `DecArmS1aH` (`DecArmQH` plus Untyped Retype, ASIDPool Assign and ASIDControl MakePool) it takes, at entry, `S1aR2` (the VSpace record over the tables reachable from the ASID table: lookup, walks, root agreement, the Stage-1 and Stage-2 typings narrowed to reachable tables, exact path backing, footprint and placement), `S1aKtUt` (the kernel TTBR1 tables outside every Untyped) and `S1aHiK` (the levels of the kernel tables `Kt` and of the `HighVSpace` headers' copied descriptors, at the levels `KLv` of the platform contract `KTab`), and returns all three at the end, with `S1aStep`'s columns (`SysL`, `SymL`, the arm and cap columns, `PtCap`, `PtHG`, `HiCap511`, …; `S1aStepR2K.toR2` is `s1aStepR2`'s post). The boot witnesses give the entry (`w0_s1aStepEntryK`, `w1K_s1aStepEntryK`). Full typing of every live table is false on reachable states: `delete_asid_pool` leaves a mapped `HighVSpace` root whose private table still names a page table that can then be deleted and its memory retyped. So the deletion typing is the reachable one (`HiDelTyR`, a projection of `S1aR2`), and the tables an ASIDPool Assign makes reachable are typed by relabelling `S1aR2`'s levels on unreachable tables (`S1aR2.relabel`). Named premises: [P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), `KTab`, `A64FrameMasks`, and at boot `BootCanon` (the boot objects lie in the kernel window). Covered arms of `DecArmS1aH`: Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and ASIDControl MakePool. The sibling `syscall.decode_invocation.s1aStepR2All` (`S1aCAll`, same hypotheses and post) covers `DecArmS1aAll` = `DecArmS1aH` plus `DecArmS1aC`: the rejected invocations (direct `HighVSpace`, the unknown CNode / IRQ-handler / Frame / PageTable / ASID / VCPU labels, `IoPortControl` and `TdxControl` under `lbl < 2^52`, `IoPort` by `SysL.ci`), the unknown TCB and SchedContext labels (a stall only), TCB WriteFPU, SetTimer, BindNotification, Resume, WriteRegisters and CopyRegisters, CNode CancelBadgedSends, SchedContext Bind and YieldTo, SchedControl ConfigureFlags and the Reply cap. Each new arm but Reply exports `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` and is closed by `S1aStepR2K.ofKeep'`; `migrate_tcb`'s debug-list and `OWNER_CPU` writes (SchedContext Bind, ConfigureFlags) go through the Suspend footprint `SusW` (`DMR`, `ArmQIAt.ofSusW`). ConfigureFlags (`S1aCSchedCtlD`) takes two case facts, [J] cap well-formedness for a future cap-typing column: the SchedControl cap's core is a core (`cpu ∈ Cs`) and an extra SchedContext cap carries its object's size (`sz.val = H.scBits p`); neither follows from `SlotTy` / `CapTy`. The Reply arm (`S1aCReplyA`) exports `XferSlots2` (the reply's transfer, then the timeout fault IPC's) instead of `OSKeep` and is closed by `S1aStepR2K.ofXfer2`; the timeout IPC's placement after the first transfer comes from `SlotTy.ofXfer` (`S1aCXferTy`: a derived copy is the source cap, `Null`, `Domain` or a frame cap, the source keeps its cap or turns full). ConfigureSingleStepping and Set / Get / UnsetBreakpoint share SetEPTRoot's label `U64::MAX` and decode as it. Not covered on AArch64: Frame DeriveSubframe, by ruling: `FrameOK` requires every frame object to be the exact size of its cap (`FrObj`), which a 4 KiB subframe beside its 2 MiB source violates (MdbVsGaQ's `SysL.sub_false`); generalising `FrObj` to containment is a backlog item with its own review. Boot (`S1aCBootSym`, `S1aBootDel0`, `S1aBootDel1`): `boot_symL`, `w1_symL` and `w1K_symL` give `SymL` at w0, w1 and the kernel-table extension; `w0_delIn` / `w1_delIn` give `DelIn` from [P] `BootCanon` (non-vacuous: `bootCanon_ex` exhibits `BootLay1 ∧ BootCanon` at `kb = PPTR_BASE`), so `w1K_bundleU` is the boot bundle with no further input. Non-decode steps: each kernel function has its own theorem from the same per-state inputs to `S1aStepR2K`: `update_timestamp`, `commit_time`, `postpone`, `end_timeslice`, `charge_budget` (`S1aCTime`, `S1aCBudget`), `check_budget` / `check_budget_restart` (`.rpw` to the Reply-walk post `RpPost`, `.s1a` by `S1aStepR2K.ofRpPost`; `S1aCBudget`, `S1aCYield`), `schedule`, `activate_thread`, `vcpu::check` and `syscall::finish` (`S1aCSched`, `S1aCFinish`), `handle_fault` / `handle_timeout` (`S1aCFault`), `handle_yield` and `mcs_preemption_point` (`S1aCYield`), and `handle_recv` (`S1aCRecv`: `receive_ipc` with `take_reply`, the wait, `receive_from_sender` and `complete_signal`; `receive_signal`; the cap faults; a looked-up cap is a typed `OS` slot's cap, `cspace.lookup_cap.os`; the notification states are the existing [J] of `recvOK`), and the interrupt side (`S1aCIrq`): `handle_interrupt` (the IRQ slot's notification typed and named by its `OS` slot), `vcpu::complete_run`, `handle_vgic_maintenance` and `handle_vppi_event` (the `VPPI_MASKED` word as a VCPU-word step); `reply_error` and `msg.reply_success_empty` (`S1aCReplyErr`: registers and IPC-buffer words over the normal transfer's carry). The entry wrappers (`budget_ok` / `update_timestamp` / `check_budget`, a kernel function, `finish`; the fault, interrupt, VGIC, vPPI and VCPU-run entries, `set_tls_base_self`, the debug syscalls) are not composed on this line: by ruling they are composed at entry level, from the per-function theorems, whose inputs are stated at each function's own start state. The entry facts after a decode arm (`S1aCEnt`): `syscall.decode_invocation.s1aStepEntAll` gives, beside `s1aStepR2All`'s post, `S1aStepEnt` at the decode's heap and slot set (`SysL`, `HeapOK`, `BXI`, `OSOK`, `UserOK` of the entry's user words, `VsTy` of the reachable tables via `VsTyR.toVsTy`, the state block's width), the fields of P2's `EntryInvA` and P3's `SysInvA`, on the arms that keep the heap (`DecArmS1aEnt`). Untyped Retype and ASIDControl MakePool are not covered: `UserOK` leaves the user words an arbitrary set disjoint from the heap objects, with nothing tying them to frame caps, so it does not follow over the grown heap. The non-decode steps' per-state facts are the queue-level ones (`CurOK`, the current thread's SC and blocking facts, [J] `RunVcpuInv`, on the receive side [J] `nvm` and the notification states of `recvOK`); `schedule` is walked with a bundle `SW` (`RpW` with every slot kept and the VCPU words kept, `VKeep`), each step a `DMD` step or a queue step writing low state-block words. Boundary: the decode theorems (`s1aStepR2All`, `s1aStepEntAll`) are about one `decode_invocation` of a `DecArmS1aAll` arm, not `kernel_entry`, and they still take entry-layer inputs their posts do not return (`DelIn`, `DecPre`, `SysPlace`, the IRQ and slot-coverage facts `hIq` / `hSC`, the thread facts `mcp`, `cs`, `fh`, and the SchedControl case fact `hScC`). The earlier tops `s1aStepH` / `s1aStepPt` / `s1aStepR2` remain, with their per-step inputs. - **P2**: for x86_64, not started. The transaction-soundness theorem it replaces (`proofs/Fl4Proofs/P2/Runtime.lean`, `sound` and `snapshot`) is complete, but about the transactional runtime removed on 2026-11-21 (§7); the Lean tree still builds it. - AArch64: the architecture-independent gate model (`Serial`, `SerialSafe`, `SafeCert`, and the hardware-step model `SerialHw`) is one library, `proofs/Fl4P2Base`, shared by both trees (the x86_64 `Fl4Proofs/P2` modules of the same names re-export it); the core-generic x86_64 guard and local-path modules are copied into `Fl4ProofsA64/P2` only by `xtask/scripts/port_p2_a64.py` (`--check` verifies the copies). - AArch64 serializability, first form: `serializable_fl4_localVXb` (`Fl4ProofsA64/P2/E2EFl4VXS.lean`). Every execution that starts with an empty log and no local path in progress, made of core steps (serial entries under the gate, and local paths) and hardware steps (a running guest's VCPU words, rules 7 and 8), and that ends with no local path in progress, has a log whose entries, run one after another from the initial memory, give the final memory (`RunAll`). Its local paths are each an `E2E.LocalPath` (refinement of the general path, footprint, read-once), cut and lifted to the VCPU ownership map: the VM fault, the VM ReplyRecv, `TCB_SetTimer`, the timer interrupt (including the fire case), the local syscall path, NBWait, the `ARMVCPURun` exit, the VM-timer interrupt and `arm_vm_entry_ready`. The run is under an epoch predicate, `EpochA`: the boot layout and every serial entry's result are a typed layout linked to memory on the aligned non-user words, and a local path starts in that epoch (`StartAtE`). diff --git a/README.md b/README.md index 4b3d2f364..331dbe7b9 100644 --- a/README.md +++ b/README.md @@ -191,29 +191,42 @@ and by the proof extractions (`proofs/Fl4Core` for x86_64, `proofs/Fl4CoreA64` for AArch64). P0 (no failure) covers both builds; P3 is about the x86_64 build, one serial kernel entry at a time; P1 covers the x86_64 entries and, on AArch64, the decode step of the capability -invocations in `DecArmS1aH` (`syscall.decode_invocation.s1aStepR2K`; DESIGN.md -§9): from the reachable VSpace record `S1aR2`, the kernel-table / Untyped -separation and the kernel-table level column `S1aHiK` it returns all three -with the syscall-level bundle, and the boot witnesses give them at entry. The -arms covered are Null and Zombie caps, Endpoint and Notification sends, Domain, +invocations in `DecArmS1aAll` (`syscall.decode_invocation.s1aStepR2All`, a +sibling of `s1aStepR2K` over `DecArmS1aH`; DESIGN.md §9): from the reachable +VSpace record `S1aR2`, the kernel-table / Untyped separation and the +kernel-table level column `S1aHiK` it returns all three with the +syscall-level bundle, and the boot witnesses give them at entry. The arms +covered are Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / -Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, -SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, -SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, -SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / -UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, -Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache -operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` -invocations, ASIDPool Assign and ASIDControl MakePool. Not covered on AArch64: -Reply and SchedControl caps, direct `HighVSpace` invocations, CNode -CancelBadgedSends, the TCB labels WriteRegisters, CopyRegisters, Resume, -BindNotification, ConfigureSingleStepping, Set / Get / UnsetBreakpoint, -SetTimer and WriteFPU, SchedContext Bind and YieldTo, Frame DeriveSubframe, -and the unknown-label error branches. `IoPortControl`, `IoPort` and -`TdxControl` are x86_64 only (not applicable on AArch64). The step still +Mutate / Rotate / Revoke / Delete / CancelBadgedSends, every TCB label +(SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, +SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, +Resume, ReadRegisters, WriteRegisters, CopyRegisters, SetTLSBase, +SetPACKeys, SetFlags, ReadFPU, WriteFPU, SetTimer, BindNotification and +UnbindNotification; ConfigureSingleStepping and Set / Get / UnsetBreakpoint +share SetEPTRoot's label `U64::MAX` on AArch64 and decode as it), SchedContext +Unbind / UnbindObject / Consumed / Bind / YieldTo, SchedControl +ConfigureFlags (with two cap well-formedness case facts: the core and the SC +cap's size), the Reply cap (its transfer and timeout fault), every VCPU label, every +Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / +TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, +the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and +ASIDControl MakePool, direct `HighVSpace` invocations and every unknown-label +error branch (all rejected), and the `IoPortControl`, `IoPort` and +`TdxControl` caps, which AArch64 rejects. Not covered on AArch64: Frame +DeriveSubframe (`FrameOK`'s exact-size frame objects, which a subframe beside +its source violates; generalising them is a backlog item). The step still takes entry-layer inputs its post does not return (`DelIn`, `DecPre`, -`SysPlace`, `hIq`, `hSC`, `mcp`, `cs`, `fh`), so it is not yet an induction +`SysPlace`, `hIq`, `hSC`, `mcp`, `cs`, `fh`, and `s1aStepR2All`'s `hScC`), so it is not yet an induction over `kernel_entry`. +Outside the decode, the time and budget functions, `schedule`, +`activate_thread`, `vcpu::check`, `syscall::finish`, the fault handlers, +yield, the MCS preemption point, `handle_recv`, `handle_interrupt` and +the VCPU completion / VGIC / vPPI events, `reply_error` and `reply_success_empty` each have a theorem +from the same inputs to the same post; the entry wrappers around them are +composed at entry level. On the decode arms that keep the heap, a sibling +post also gives the entry facts (`S1aStepEnt`: `HeapOK`, `BXI`, `OSOK`, +`UserOK`, `VsTy`, `SysL`). The existing x86_64 P2 theorem is about the transactional runtime that was removed (DESIGN.md §9). On AArch64, P2 proves serializability for the serial gate and the local paths that run SMP today diff --git a/proofs/Fl4ProofsA64.lean b/proofs/Fl4ProofsA64.lean index ec18e929a..90cfdcb13 100644 --- a/proofs/Fl4ProofsA64.lean +++ b/proofs/Fl4ProofsA64.lean @@ -1101,6 +1101,11 @@ import Fl4ProofsA64.P1.S1aKtPoolArms import Fl4ProofsA64.P1.S1aKtRetype import Fl4ProofsA64.P1.S1aStepR2K import Fl4ProofsA64.P1.S1aStepR2KBoot +import Fl4ProofsA64.P1.S1aCKeep +import Fl4ProofsA64.P1.S1aCBootSym +import Fl4ProofsA64.P1.S1aCRej +import Fl4ProofsA64.P1.S1aCStall +import Fl4ProofsA64.P1.S1aCFpu import Fl4ProofsA64.P2.GlueAdeqA import Fl4ProofsA64.P2.GlueRepA import Fl4ProofsA64.P2.MdbEditA @@ -1111,3 +1116,40 @@ import Fl4ProofsA64.P2.BufWireA import Fl4ProofsA64.P2.DelLkA import Fl4ProofsA64.P2.GateExecA import Fl4ProofsA64.P2.GateBootA +import Fl4ProofsA64.P1.S1aCNtfnBind +import Fl4ProofsA64.P1.S1aCTimer +import Fl4ProofsA64.P1.S1aCCbs +import Fl4ProofsA64.P1.S1aCRestart +import Fl4ProofsA64.P1.S1aCRegs +import Fl4ProofsA64.P1.S1aCCopyRegs +import Fl4ProofsA64.P1.S1aCScBind +import Fl4ProofsA64.P1.S1aCYieldTo +import Fl4ProofsA64.P1.S1aCReplyRm +import Fl4ProofsA64.P1.S1aCReplyT +import Fl4ProofsA64.P1.S1aCNScW +import Fl4ProofsA64.P1.S1aCSchedCtlA +import Fl4ProofsA64.P1.S1aCSchedCtlB +import Fl4ProofsA64.P1.S1aCSchedCtlC +import Fl4ProofsA64.P1.S1aCSchedCtlD +import Fl4ProofsA64.P1.S1aCXferTy +import Fl4ProofsA64.P1.S1aCReplyW +import Fl4ProofsA64.P1.S1aCReplyTo +import Fl4ProofsA64.P1.S1aCReplyTl +import Fl4ProofsA64.P1.S1aCReplyM +import Fl4ProofsA64.P1.S1aCReplyA +import Fl4ProofsA64.P1.S1aCAll +import Fl4ProofsA64.P1.S1aBootDel0 +import Fl4ProofsA64.P1.S1aBootDel1 +import Fl4ProofsA64.P1.S1aCStepD +import Fl4ProofsA64.P1.S1aCTime +import Fl4ProofsA64.P1.S1aCBudget +import Fl4ProofsA64.P1.S1aCBufAt +import Fl4ProofsA64.P1.S1aCSched +import Fl4ProofsA64.P1.S1aCFinish +import Fl4ProofsA64.P1.S1aCFault +import Fl4ProofsA64.P1.S1aCYield +import Fl4ProofsA64.P1.S1aCDm2 +import Fl4ProofsA64.P1.S1aCRecv +import Fl4ProofsA64.P1.S1aCIrq +import Fl4ProofsA64.P1.S1aCReplyErr +import Fl4ProofsA64.P1.S1aCEnt diff --git a/proofs/Fl4ProofsA64/P1/S1aBootDel0.lean b/proofs/Fl4ProofsA64/P1/S1aBootDel0.lean new file mode 100644 index 000000000..789a84081 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aBootDel0.lean @@ -0,0 +1,107 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2, D5; Architect rulings 04:32Z / 04:36Z): **the deletion inputs `DelIn` at the +boot witness `w0`**. + +* **[P] `BootCanon kb ib nc`** (new layout premise, beside the unchanged `BootLay` / `BootLay1`): the state block and + the idle TCBs lie in the kernel window `[PPTR_BASE, PPTR_TOP)`. **`bootCanon_ex`**: it holds with `BootLay1` at + concrete addresses (the combined boot premises are not vacuous). +* **`boot_dcan`** (every `OS` slot is canonical: `canon_of_ge`), **`boot_wuApart`** (the `WORK_UNITS` word is off every + slot, as BootIrq's `boot_irqStApart`), **`boot_delS`** (`DelS` at `D := OSN OS kb`). +* **`w0_delIn`**: `DelIn` at `w0` with `K := S2Q` and `Ty := VsTyR ∧ S2TyR` (S1aHiDelR's `finKT_s2R`, `tyk_s2R`, the + typing from S1aStepR2Boot's `w0_s1aStepEntry` witness). + +Named premises: [P] `P0.ArchTotal`, `ArchPlat`, `BootCanon`. +-/ +import Fl4ProofsA64.P1.S1aStepR2KBoot +import Fl4ProofsA64.P1.S1aHiDelR +import Fl4ProofsA64.P1.BootScAp +import Fl4ProofsA64.P1.S1aCReplyA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +/-- **[P] The boot objects lie in the kernel window** (module docstring). -/ +structure BootCanon (kb ib : U64) (nc : Nat) : Prop where + kbB : layout.PPTR_BASE.val ≤ kb.val + ibB : layout.PPTR_BASE.val ≤ ib.val + kbT : kb.val + 788736 ≤ layout.PPTR_TOP.val + ibT : ib.val + nc * 8192 ≤ layout.PPTR_TOP.val + +namespace BootWit + +noncomputable section + +/-- **`BootCanon` holds together with `BootLay1`** at concrete kernel-window addresses (`kb = PPTR_BASE`, +`ib = PPTR_BASE + 2^20`, one core). -/ +theorem bootCanon_ex : + BootLay1 18446603336221196288#u64 18446603336222244864#u64 1 ∧ + BootCanon 18446603336221196288#u64 18446603336222244864#u64 1 := by + have e1 : (18446603336221196288#u64 : U64).val = 18446603336221196288 := by simp + have e2 : (18446603336222244864#u64 : U64).val = 18446603336222244864 := by simp + refine ⟨⟨⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩, ?_, ?_, ?_, ?_⟩ + all_goals (try simp only [e1, e2, layout.PPTR_BASE.val_eq, layout.PPTR_TOP.val_eq]) + all_goals omega + +variable {kb ib r now mt : U64} {nc : Nat} + +/-- **Every `OS` slot of `w0` is canonical.** -/ +theorem boot_dcan (P : BootLay kb ib nc) (Q : BootCanon kb ib nc) : DCan (bootOS kb ib nc) := fun y hy => + canon_of_ge y (by + have := Q.kbB; have := Q.ibB + rcases bootOS_val P hy with ⟨t, c, i, -, -, et, -, -, ey⟩ | ⟨j, -, -, ey⟩ <;> omega) + +theorem wu_val {kb : U64} (hk : kb.val + 788736 ≤ 2 ^ 64) : (wa kb layout.ks.WORK_UNITS).val = kb.val + 40 := by + have e : layout.ks.WORK_UNITS.val = 40 := by simp [layout.ks.WORK_UNITS] + rw [wadd_val (by rw [e]; omega), e] + +/-- **The `WORK_UNITS` word is off every slot of `w0`.** -/ +theorem boot_wuApart (P : BootLay kb ib nc) : WuApart (bootOS kb ib nc) kb := by + intro y hy ⟨g1, g2⟩ + have hk := P.kbw + have hA := P.apart + have hv := wu_val hk + rcases bootOS_val P hy with ⟨t, c, i, -, hc, et, hi, -, ey⟩ | ⟨j, hj, -, ey⟩ <;> omega + +/-- **`DelS` at `w0`.** -/ +theorem boot_delS {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (P : BootLay kb ib nc) + (Q : BootCanon kb ib nc) : + DelS ar (bootH kb ib nc) (bootOS kb ib nc) (OSN (bootOS kb ib nc) kb) ∅ ∅ ∅ kb := + ⟨hA, bootH_ok P, boot_osOK P, boot_scApart P, VcOK.boot boot_sbW, fun _ hy => hy.1, + fun y hy => boot_dcan P Q y hy.1, fun _ h => h.elim, boot_vrOK P, boot_wuApart P, + boot_irqOK fun _ hy => hy.2, boot_irqStApart P⟩ + +theorem s2q_noVcpu {c : capability.Cap} (hc : S2Q c) : VcCapP ∅ c := fun v e => by + subst e; simp [S2Q, PtQ, VsQ, VsCap] at hc + +set_option maxHeartbeats 4000000 in +/-- **`DelIn` at `w0`** (module docstring). -/ +theorem w0_delIn {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (P : BootLay kb ib nc) (Q : BootCanon kb ib nc) (Lv Re bits : U64 → Nat) : + ∃ Pp : Set U64, DelIn bst ar (bootH kb ib nc) (bootCs nc) (bootOS kb ib nc) ∅ ∅ ∅ S2Q + (fun q => VsTyR bst kb Pp ∅ ∅ Lv q ∧ S2TyR bst hPl.ipa Pp ∅ ∅ Re bits q) (bootS kb ib nc r now mt) := by + obtain ⟨Pp, W0, -, -⟩ := w0_s1aStepEntry P Lv Re bits hPl.ipa (r := r) (now := now) (mt := mt) + have W := W0.toR + have B := bootItems P (r := r) (now := now) (mt := mt) + exact ⟨Pp, { + del := boot_delS hA P Q + fin := finKT_s2R hA hPl (boot_vrOK P) W.pools W.tables W.granules W.high W.stage2 + tyk := tyk_s2R W.pools W.tables W.granules W.high W.stage2 + kl := fun _ hc => s2q_noLive hc + kv := fun _ hc => s2q_noVcpu hc + s2 := fun _ h => h + ts := boot_tcbSlots + vty := VcTy.boot (fun t ht => (B.vw t ht).1) (fun t ht => (B.vw t ht).2) + ty := W.ty + irq := boot_irqN P + vcc := fun y hy v e => by rw [B.nl y hy] at e; cases e + fu := CapInv.empty (FrUbP.null ∅) B.nl }⟩ + +end + +end BootWit + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aBootDel1.lean b/proofs/Fl4ProofsA64/P1/S1aBootDel1.lean new file mode 100644 index 000000000..a6efab691 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aBootDel1.lean @@ -0,0 +1,140 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2, D5; Architect rulings 04:32Z / 04:36Z): **the deletion inputs `DelIn` at the +boot witness `w1`, and the kernel-table bundle at its extension without conditions**. + +* **`w1_dcan`**, **`w1_wuApart`**, **`w1_ub`** (the user words are `other`-object words), **`w1_frUb`** (every root frame + cap's page is user words: `FrPg` pages lie in `w1Ub`), **`w1_delS`**. +* **`w1_hiDelR`**: the guarded VSpace witness at `w1`'s own heap and `w1Pt` (the pool set: the root pool, S1aVsUnmB's + `w1_tab`; the stage-1 typing from BootW1Items's `w1_column`, the stage-2 typing from `w1K_s1aR2`). +* **`w1_delIn`**: `DelIn` at `w1` with `K := S2Q`, `Ty := VsTyR ∧ S2TyR` (S1aHiDelR's `finKT_s2R`, `tyk_s2R`). +* **`w1K_bundleU`**: S1aBootK's `w1K_bundleOf` at `w1_symL` and `w1_delIn`: the bundle at the kernel-table extension + from [P] premises only. + +Named premises: [P] `P0.ArchTotal`, `ArchPlat`, `BootCanon`. +-/ +import Fl4ProofsA64.P1.S1aBootDel0 +import Fl4ProofsA64.P1.S1aCBootSym +import Fl4ProofsA64.P1.S1aBootV +import Fl4ProofsA64.P1.S1aBootK +import Fl4ProofsA64.P1.S1aVsUnmB + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +namespace BootWit + +noncomputable section + +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) +include P + +/-- **Every `OS` slot of `w1` is canonical.** -/ +theorem w1_dcan (Q : BootCanon kb ib nc) : DCan (w1OS kb ib nc) := fun y hy => + canon_of_ge y (by + have := Q.kbB; have := Q.ibB; have := P.kbR; have := P.ibR + have := layout.PPTR_BASE.val_eq + rcases w1OS_val P hy with ⟨t, c, i, -, -, et, -, -, ey⟩ | ⟨i, -, -, ey⟩ | ⟨i, -, ey⟩ | ⟨j, -, -, ey⟩ <;> omega) + +/-- **The `WORK_UNITS` word is off every slot of `w1`.** -/ +theorem w1_wuApart : WuApart (w1OS kb ib nc) kb := by + intro y hy ⟨g1, g2⟩ + have hk := P.w0.kbw + have hA := P.w0.apart + have := P.kbR + have := P.ibR + have hv := wu_val hk + rcases w1OS_val P hy with ⟨t, c, i, -, hc, et, hi, -, ey⟩ | ⟨i, hi, -, ey⟩ | ⟨i, hi, ey⟩ | ⟨j, hj, -, ey⟩ <;> omega + +/-- **The user words of `w1` are `other`-object words.** -/ +theorem w1_ub : ∀ b ∈ w1Ub, b ∈ (w1H kb ib nc).omega := fun b hb => by + obtain ⟨q, z, hq, h1, h2⟩ := UbFr.inOther (w1_frameOK P (r := 0#u64) (now := 0#u64) (mt := 0#u64) (sl := 0#u64) (uw := fun _ => 0#u64)) + (w1_ubFr P) b hb + exact ⟨hb.1, q, .other z, hq, Or.inr (Or.inr (Or.inl ⟨z, rfl⟩)), h1, by simpa [HKind.bits] using h2⟩ + +/-- **Every root frame cap's page is user words.** -/ +theorem w1_frUb : FrUb bst w1Ub (w1OS kb ib nc) (w1S kb ib nc r now mt sl uw) := by + intro y hy ptr size rights x1 x2 x3 x4 hc bits hb b hal h1 h2 + obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc + rw [small_bits hb, bw_two12] at h2 + refine ⟨hal, ?_⟩ + unfold FrPg at hF + rcases hF with ⟨f1, f2, f3⟩ | e | e | e <;> omega + +/-- **`DelS` at `w1`.** -/ +theorem w1_delS {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (Q : BootCanon kb ib nc) : + DelS ar (w1H kb ib nc) (w1OS kb ib nc) (OSN (w1OS kb ib nc) kb) ∅ w1Ub w1Pt kb := + ⟨hA, w1H_ok P, w1_osOK P, w1_scApart P, + ((w1_items P (r := 0#u64) (now := 0#u64) (mt := 0#u64) (sl := 0#u64) (uw := fun _ => 0#u64)).columnV (w1H_ok P) (w1_frameOK P) + (w1_sysL P).fo (fun b hb => hb.1) P.w0.kbw).1, + fun _ hy => hy.1, fun y hy => w1_dcan P Q y hy.1, w1_ub P, + w1_vrOK P, w1_wuApart P, w1_irqOK fun _ hy => hy.2, w1_irqStApart P⟩ + +/-- The root pool is the one active pool of `w1`. -/ +theorem w1_poolW {p : U64} (hp : p ∈ PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) : p ∈ w1Pt := by + obtain ⟨_, o, h1, h2, h8, hm, hn⟩ := hp + have e : p = bwv PLb := hm.symm.trans (w1_tab P _ ⟨o, h1, h2, h8, rfl⟩ (fun hz => hn (hm.symm.trans hz))) + subst e + exact Or.inr (Or.inl vPL) + +/-- **The guarded VSpace witness at `w1`'s own heap** (module docstring). -/ +theorem w1_hiDelR (Re bits : U64 → Nat) (n : U64) : + HiDelTyR bst w1Pt (w1OS kb ib nc) (PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) w1Tb ∅ ∅ w1Lv Re bits n + (w1S kb ib nc r now mt sl uw) := by + have R := (w1K_s1aR2 P Re bits n (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw)).1.activePools + have h2 := R.core.stage2 + rw [PoolSet.idem] at h2 + refine ⟨fun p hp => w1_poolW P hp, fun p hp => ?_, ?_, ?_, ?_, fun x hx => ?_, + (w1_column P ∅ (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw)).1.2.2.2.2.1.toR, h2⟩ + · rcases hp with e | e | e | e + · exact Or.inl e + · exact Or.inr (Or.inr (Or.inl e)) + · exact Or.inr (Or.inr (Or.inr (Or.inl e))) + · exact Or.inr (Or.inr (Or.inr (Or.inr e))) + · rintro q ⟨p, hp, -⟩ + exact hp.elim + · exact ⟨Set.empty_subset _, fun _ h => h.elim, fun _ _ _ _ _ _ h => h.elim, fun _ _ _ _ _ _ h => h.elim, + fun _ h => h.elim⟩ + · exact ⟨fun _ h => h.elim, fun _ h => h.elim, fun _ _ _ h => h.elim⟩ + · rw [← R.highRoots] at hx + exact hx + +set_option maxHeartbeats 4000000 in +/-- **`DelIn` at `w1`** (module docstring). -/ +theorem w1_delIn {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (Q : BootCanon kb ib nc) (Re bits : U64 → Nat) : + DelIn bst ar (w1H kb ib nc) (bootCs nc) (w1OS kb ib nc) ∅ w1Ub w1Pt S2Q + (fun q => VsTyR bst kb (PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) ∅ w1Tb w1Lv q ∧ + S2TyR bst hPl.ipa (PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) ∅ ∅ Re bits q) + (w1S kb ib nc r now mt sl uw) := + have W := w1_hiDelR P Re bits hPl.ipa (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) + { del := w1_delS P hA Q + fin := finKT_s2R hA hPl (w1_vrOK P) W.pools W.tables W.granules W.high W.stage2 + tyk := tyk_s2R W.pools W.tables W.granules W.high W.stage2 + kl := fun _ hc => s2q_noLive hc + kv := fun _ hc => s2q_noVcpu hc + s2 := fun _ h => h + ts := w1_tcbSlots P + vty := ((w1_items P).columnV (w1H_ok P) (w1_frameOK P) (w1_sysL P).fo (fun b hb => hb.1) P.w0.kbw).2 + ty := W.ty + irq := w1_irqN P + vcc := VcCap.bootG (w1_caps P) + fu := w1_frUb P } + +/-- **The kernel-table bundle at `w1`'s extension, unconditional** (module docstring). -/ +theorem w1K_bundleU {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (Q : BootCanon kb ib nc) (Re bits : U64 → Nat) : + KtBundle bst ar (KtH (w1H kb ib nc) {bwv KTb}) (bootCs nc) (w1OS kb ib nc) ∅ w1Ub (w1Pt ∪ {bwv KTb}) S2Q + (fun q => VsTyR bst kb (PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) ∅ w1Tb w1Lv q ∧ + S2TyR bst hPl.ipa (PoolSet bst Set.univ (w1S kb ib nc r now mt sl uw)) ∅ ∅ Re bits q) + ib.val (ib.val + nc * 8192) (w1S kb ib nc r now mt sl uw) := + w1K_bundleOf P (w1_symL P) (w1_delIn P hA hPl Q Re bits) + +end + +end BootWit + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCAll.lean b/proofs/Fl4ProofsA64/P1/S1aCAll.lean new file mode 100644 index 000000000..b7e9bde6d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCAll.lean @@ -0,0 +1,164 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a16)): **the S1a step over every decode arm proved so far**. + +* **`S1aStepR2K.ofKeep'`**: S1aCKeep's `S1aStepR2K.ofKeep` with the deletion facts' frame set `Uq` (the `VrOK` / + `FrUb` that `ArmVsK` reads) apart from the column's `Ub`, as in `s1aStepR2K`. +* **`DecArmS1aC`**: the arms added by this wave — the rejected invocations (S1aCRej), the unknown TCB / SchedContext + labels (S1aCStall), TCB WriteFPU, SetTimer, BindNotification, Resume, WriteRegisters, CopyRegisters, CNode + CancelBadgedSends, SchedContext Bind and YieldTo, SchedControl ConfigureFlags (S1aCSchedCtlD), the Reply cap + (S1aCReplyA; closed by **`S1aStepR2K.ofXfer2`**: R2's image and the separation once per transfer). + **`DecArmS1aAll`** := `DecArmS1aH ∨ DecArmS1aC`. +* **`syscall.decode_invocation.s1aStepR2All`**: `s1aStepR2K`'s statement over `DecArmS1aAll` (a sibling; + `DecArmS1aH` and `s1aStepR2K` unchanged). The `DecArmS1aH` arms by `s1aStepR2K`; the new arms export + `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` (a rejected arm the unchanged state), closed by `ofKeep'`. + +Not covered: Frame DeriveSubframe (left out by ruling: `FrameOK`'s exact-size `FrObj`, MdbVsGaQ's `SysL.sub_false`). + +Named premises: those of `s1aStepR2K` ([P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat`, `KTab`, `A64FrameMasks`). Case fact [J] `hScC` (cap +well-formedness, on the SchedControl arm only; producer: the future cap-typing column): the invoked SchedControl +cap's core is a core and a non-null extra slot's SchedContext cap carries its object's size. +-/ +import Fl4ProofsA64.P1.S1aCKeep +import Fl4ProofsA64.P1.S1aCRej +import Fl4ProofsA64.P1.S1aCStall +import Fl4ProofsA64.P1.S1aCFpu +import Fl4ProofsA64.P1.S1aCTimer +import Fl4ProofsA64.P1.S1aCNtfnBind +import Fl4ProofsA64.P1.S1aCCbs +import Fl4ProofsA64.P1.S1aCRestart +import Fl4ProofsA64.P1.S1aCRegs +import Fl4ProofsA64.P1.S1aCCopyRegs +import Fl4ProofsA64.P1.S1aCScBind +import Fl4ProofsA64.P1.S1aCYieldTo +import Fl4ProofsA64.P1.S1aCSchedCtlD +import Fl4ProofsA64.P1.S1aCReplyA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- **`S1aStepR2K.ofKeep` with the deletion facts' own frame set** (module docstring). -/ +theorem S1aStepR2K.ofKeep' {s q : S} + (d : ArmQIAt st H Cs OS Vc ia ie s q ∧ TabKeepOrZero st s q ∧ ArmVsK st H OS Vc s q ∧ OSKeep st OS s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt) (fu : FrUb st Uq OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem, slots⟩ := d + have vs : VsKeep st (L.ksb s) Pt s q := mem.2 Uq Pt vr fu + have R' : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + R.ofImage mem.1 vs (.ofSame R.capRefs.refs fun _ hy => Or.inl (slots.capA hy)) + obtain ⟨Ub', hsub, hC, hK⟩ := (S1aColU.of arm.1 (S1aArmCol.ofTZ tab C)) + have col : S1aHiK st OS Kt KLv q := KC.keep ⟨EdgeKeepOn.ofVsKeep R vs, arm.hiRoots R.highHeaders⟩ + exact ⟨H, OS, Vc, Ub', Pt, ⟨arm.1, arm.2.1, hsub, arm.2.2.2.1 vcc, hC, hK, arm.ptCap R.pageTables, + arm.hvPt R.hvPt, R.footprint, arm.devFr Df, R'.highHeaders, arm.eptPlaced R.eptRoots, + arm.ptCap R.pageObjects, arm.hvObjects R.highObjects⟩, sep.keep slots, R'.ex, col⟩ + +/-- **The S1a step post from two transfers' slot facts** (the Reply arm: R2's image and the separation applied +per transfer, the column by `S1aColU`). -/ +theorem S1aStepR2K.ofXfer2 {s q : S} + (d : ArmQIAt st H Cs OS Vc ia ie s q ∧ TabKeepOrZero st s q ∧ ArmVsK st H OS Vc s q ∧ XferSlots2 st H OS Vc s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt) (fu : FrUb st Uq OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem, m, x1, v1, x2, v2⟩ := d + have vs : VsKeep st (L.ksb s) Pt s q := mem.2 Uq Pt vr fu + have Rm : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n m := + R.ofImage v1.1.1 (v1.1.2 Uq Pt vr fu) (x1.s1aImage R.capRefs.refs) + have vr' : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb m) Pt := by rw [v1.1.1]; exact vr + have R' : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + Rm.ofImage v2.1.1 (v2.1.2 Uq Pt vr' (v1.2 Uq fu)) (x2.s1aImage Rm.capRefs.refs) + obtain ⟨Ub', hsub, hC, hK⟩ := (S1aColU.of arm.1 (S1aArmCol.ofTZ tab C)) + have col : S1aHiK st OS Kt KLv q := KC.keep ⟨EdgeKeepOn.ofVsKeep R vs, arm.hiRoots R.highHeaders⟩ + exact ⟨H, OS, Vc, Ub', Pt, ⟨arm.1, arm.2.1, hsub, arm.2.2.2.1 vcc, hC, hK, arm.ptCap R.pageTables, + arm.hvPt R.hvPt, R.footprint, arm.devFr Df, R'.highHeaders, arm.eptPlaced R.eptRoots, + arm.ptCap R.pageObjects, arm.hvObjects R.highObjects⟩, x2.ktUt (x1.ktUt sep), R'.ex, col⟩ + +/-- **The arms added by the completion wave** (module docstring). -/ +def DecArmS1aC (cap : capability.Cap) (lbl : U64) : Prop := + DecArmRej cap lbl ∨ + (∃ t, cap = .Thread t ∧ UnknownTcbLbl lbl) ∨ + (∃ p b, cap = .SchedContext p b ∧ UnknownScLbl lbl) ∨ + (∃ t, cap = .Thread t ∧ (lbl = fl4_abi.label.TCBWriteFPU ∨ lbl = fl4_abi.label.TCBSetTimer ∨ + lbl = fl4_abi.label.TCBBindNotification ∨ lbl = fl4_abi.label.TCBResume ∨ + lbl = fl4_abi.label.TCBWriteRegisters ∨ lbl = fl4_abi.label.TCBCopyRegisters)) ∨ + (capFam cap = .cnode ∧ lbl = fl4_abi.label.CNodeCancelBadgedSends) ∨ + (∃ p b, cap = .SchedContext p b ∧ (lbl = fl4_abi.label.SchedContextBind ∨ + lbl = fl4_abi.label.SchedContextYieldTo)) ∨ + (∃ cpu, cap = .SchedControl cpu) ∨ + (∃ p g, cap = .Reply p g) + +/-- **Every arm proved to reach the S1a step post** (module docstring). -/ +def DecArmS1aAll (cap : capability.Cap) (lbl : U64) : Prop := + DecArmS1aH cap lbl ∨ DecArmS1aC cap lbl + +set_option maxHeartbeats 4000000 in +/-- **The S1a step over `DecArmS1aAll`** (module docstring): `s1aStepR2K`'s hypotheses, its post. -/ +theorem syscall.decode_invocation.s1aStepR2All (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (KT : KTab ar Kt KLv) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) (a : A) + {lbl : U64} (hc : DecArmS1aAll cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (hScC : ∀ cpu, cap = .SchedControl cpu → cpu ∈ Cs ∧ + ∀ x ∈ extra.val, x ≠ 0#u64 → ∀ p sz, capA st s x = .SchedContext p sz → sz.val = H.scBits p) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (KC : S1aHiK st OS Kt KLv s) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie hPl.ipa s' ⦄ := by + rcases hc with hc | hc + · exact syscall.decode_invocation.s1aStepR2K hA hM hPl KT I hPI D P B Y hcap hks hfm hPN C Kc hal a hc hIq hSC + mcp cs fh R sep Df KC len blk call don fp buf + have keep : ∀ {m : Result ((core.result.Result Unit error.Exc) × S × A)}, + m ⦃ _ s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄ → m ⦃ _ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie hPl.ipa s' ⦄ := fun t => + WP.spec_mono t fun r d => by + obtain ⟨_, _, _⟩ := r + exact S1aStepR2K.ofKeep' d I.del.vr I.fu I.vcc C Kc Df R sep KC + have hSA : ScApart H.scs H.scBits OS := I.del.sca + rcases hc with hr | ⟨t, rfl, hl⟩ | ⟨p, b, rfl, hl⟩ | ⟨t, rfl, hl | hl | hl | hl | hl | hl⟩ | ⟨hf, hl⟩ | + ⟨p, b, rfl, hl | hl⟩ | ⟨cpu, rfl⟩ | ⟨p, g, rfl⟩ + · refine WP.spec_mono (syscall.decode_invocation.rejected_eq hA hcap P.src B a hr len blk call don fp buf) + fun r e => ?_ + obtain ⟨_, s', _⟩ := r + have e' : s' = s := e + subst e' + exact S1aStepR2K.ofKeep' ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s', ArmVsK.refl s', OSKeep.rfl' s'⟩ + I.del.vr I.fu I.vcc C Kc Df R sep KC + · exact keep (syscall.decode_invocation.unknownTcb_armS hA I D P B Y a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.unknownSc_armS hA I D P B Y a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.writeFpu_armS hA I D P B Y a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.setTimer_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.bindN_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.resume_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.writeRegs_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.copyRegs_armS hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.cbs_armS I D P B Y hks hSA hcap hf a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.scBind_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keep (syscall.decode_invocation.scYieldTo_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · obtain ⟨hcpu, hsz⟩ := hScC cpu rfl + exact keep (syscall.decode_invocation.schedControl_armS hA I D P B Y hks hcpu hsz a lbl len blk call don fp buf) + · exact WP.spec_mono (syscall.decode_invocation.reply_armS hA I D P B Y hks a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact S1aStepR2K.ofXfer2 d I.del.vr I.fu I.vcc C Df R sep KC + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCBootSym.lean b/proofs/Fl4ProofsA64/P1/S1aCBootSym.lean new file mode 100644 index 000000000..e7383433d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCBootSym.lean @@ -0,0 +1,129 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (b)): **`SymL` at the boot witnesses**. + +* `w0`: each core's debug list is its idle thread alone (`DEBUG_TCBS` non-null, so `SymL.empty` does not apply); + no yield link. +* `w1`: core 0's list is `idle₀ → root` (head insertion), the other cores' lists their idle threads; no yield link. +* `w1K`: `SymL.addKt`. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.BootW1Bxi +import Fl4ProofsA64.P1.S1aBootK + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST +namespace BootWit + +noncomputable section + +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} + +set_option hygiene false in +local notation "S1" => w1S kb ib nc r now mt sl uw +set_option hygiene false in +local notation "S0" => bootS kb ib nc r now mt +set_option hygiene false in +local notation "H1" => w1H kb ib nc + +theorem bwv_core {c : U64} (h : c.val < 2 ^ 64) : bwv c.val = c := UScalar.eq_of_val_eq (wv h) + +/-- The head of core `c`'s debug list at `w0` is its idle TCB, whose affinity is `c`. -/ +theorem boot_head (P : BootLay kb ib nc) {c : U64} (hc : c ∈ bootCs nc) : + bL.mem S0 (bL.nodeAt S0 c layout.node.DEBUG_TCBS) = bwv (ib.val + c.val * 8192) ∧ + bL.mem S0 (affA (bwv (ib.val + c.val * 8192))) = c := by + refine ⟨node_t P hc debug_val (Or.inr (Or.inr rfl)), ?_⟩ + have h : c.val < nc := hc + exact ((tcbM (K := 3520#u64) P h (idT_v P h) (by simp)).trans (by simp [tcbW])).trans + (bwv_core (by scalar_tac)) + +/-- **`SymL` at the pre-user boot state.** -/ +theorem boot_symL (P : BootLay kb ib nc) : SymL bst (bootH kb ib nc) (bootCs nc) S0 := by + refine ⟨⟨fun y hy h => absurd (m_dn P hy) h, fun y hy h => absurd (m_dp P hy) h, fun c hc _ => ?_, + fun y hy h => absurd (m_dn P hy) h⟩, + ⟨fun c hc h => absurd (m_scYf P hc) h, fun t ht h => absurd (m_yield P ht) h⟩⟩ + obtain ⟨hd, ha⟩ := boot_head (r := r) (now := now) (mt := mt) P hc + rw [hd] + exact ⟨m_dp P (idT_mem P hc), ha⟩ + +/-- The only non-null `DEBUG_NEXT` at `w1` is `idle₀`'s, naming the root TCB. -/ +theorem w1_dn_cases (P : BootLay1 kb ib nc) {y : U64} (hy : y ∈ (H1).tcbs) (h : bL.mem S1 (dnA y) ≠ 0#u64) : + y = ib ∧ bL.mem S1 (dnA y) = bwv RTb := by + have hw := P.w0.ibw + have hn := P.w0.nc0 + rcases w1T P hy with ht | rfl + · by_cases e : y.val = ib.val + · refine ⟨UScalar.eq_of_val_eq e, w1M_dn0 P ?_⟩ + have v : (dnA y).val = y.val + 3576 := wadd_val (by simp; omega) + omega + · refine absurd ?_ h + exact (w1_tI P ht (K := 3576#u64) (by simp) (fun h' => absurd h' e)).trans (m_dn P.w0 ht) + · exact absurd ((w1_tR P (K := 3576#u64) (by simp)).trans (by simp [rtW])) h + +theorem w1_root_dp (P : BootLay1 kb ib nc) : bL.mem S1 (dpA (bwv RTb)) = ib := + (w1_tR P (K := 3584#u64) (by simp)).trans (by simp [rtW]) + +theorem w1_idle_dp (P : BootLay1 kb ib nc) {t : U64} (ht : t ∈ (bootH kb ib nc).tcbs) : + bL.mem S1 (dpA t) = 0#u64 := + (w1_tI P ht (K := 3584#u64) (by simp) (fun _ => by simp)).trans (m_dp P.w0 ht) + +theorem w1_ib_mem (P : BootLay1 kb ib nc) : ib ∈ (bootH kb ib nc).tcbs := by + have h := idT_mem P.w0 P.w0.nc0 + have e : bwv (ib.val + 0 * 8192) = ib := UScalar.eq_of_val_eq (by + rw [show ib.val + 0 * 8192 = ib.val by omega]; exact wv (by scalar_tac)) + rwa [e] at h + +/-- **`SymL` at the user boot state.** -/ +theorem w1_symL (P : BootLay1 kb ib nc) : SymL bst H1 (bootCs nc) S1 := by + have root_dn : bL.mem S1 (dnA ib) = bwv RTb := by + have v : (dnA ib).val = ib.val + 3576 := wadd_val (by have := P.w0.ibw; have := P.w0.nc0; simp; omega) + exact w1M_dn0 P v + refine ⟨⟨fun y hy h => ?_, fun y hy h => ?_, fun c hc _ => ?_, fun y hy h => ?_⟩, + ⟨fun c hc h => absurd (m1_scYf P hc) h, fun t ht h => absurd (m1_yield P ht) h⟩⟩ + · obtain ⟨e, v⟩ := w1_dn_cases P hy h + rw [v, w1_root_dp P, e] + · rcases w1T P hy with ht | rfl + · exact absurd (w1_idle_dp P ht) h + · rw [w1_root_dp P]; exact root_dn + · have h' : c.val < nc := hc + have head : bL.mem S1 (bL.nodeAt S1 c layout.node.DEBUG_TCBS) = bwv (ib.val + c.val * 8192) := + (w1_node P hc (by simp [layout.node.DEBUG_TCBS]) (by simp [layout.node.DEBUG_TCBS])).trans + (node_t P.w0 hc debug_val (Or.inr (Or.inr rfl))) + have mem := idT_mem P.w0 h' + rw [head] + refine ⟨w1_idle_dp P mem, ?_⟩ + exact (w1_tI P mem (K := 3520#u64) (by simp) (fun _ => by simp)).trans + (boot_head (r := r) (now := now) (mt := mt) P.w0 hc).2 + · obtain ⟨e, v⟩ := w1_dn_cases P hy h + rw [v, e] + have a0 : bL.mem S1 (affA ib) = 0#u64 := by + have h0 := (boot_head (r := r) (now := now) (mt := mt) P.w0 (c := 0#u64) + (show (0#u64 : U64).val < nc by simpa using P.w0.nc0)).2 + have e0 : bwv (ib.val + (0#u64 : U64).val * 8192) = ib := UScalar.eq_of_val_eq (by + rw [show ib.val + (0#u64 : U64).val * 8192 = ib.val by simp]; exact wv (by scalar_tac)) + rw [e0] at h0 + exact (w1_tI P (w1_ib_mem P) (K := 3520#u64) (by simp) (fun _ => by simp)).trans h0 + rw [a0] + exact (w1_tR P (K := 3520#u64) (by simp)).trans (by simp [rtW]) + +/-- **`SymL` at the user boot state with a kernel table.** -/ +theorem w1K_symL (P : BootLay1 kb ib nc) : + SymL bst (KtH H1 {bwv KTb}) (bootCs nc) S1 := + SymL.addKt (w1K_out (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P) (w1_symL P) + +end + +end BootWit +end ST +end R +end W7 + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aCBudget.lean b/proofs/Fl4ProofsA64/P1/S1aCBudget.lean new file mode 100644 index 000000000..68177e559 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCBudget.lean @@ -0,0 +1,476 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c1 part 2): **the end of a timeslice and the budget charge**. + +* **`sched.append.kwB8`**: QueueFootS's `append.kw` over QueueFoot8's `K8` words (as `enqueue.kwB8`). +* **`end_suff.dmd`**: QueueBudget2's `end_suff` block (the current thread appended, or its SC postponed) is a `DMD p` + step with `BlkOK` at its end (S1aCYieldTo's `qstep`; the postpone as S1aCReplyTl's `postpone.dmd`, from `CurOK`). +* **`sched.end_timeslice.s1a`** / **`.rpw`** (with its timeout fault IPC, S1aCReplyTo's `handle_timeout.rpw`), + **`sched.charge_budget.rpw`** / **`.s1a`**, **`sched.check_budget_restart.rpw`** (its `.s1a` in S1aCYield; the Reply-walk post + `RpPost`, closed by `S1aStepR2K.ofRpPost`). + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5). +-/ +import Fl4ProofsA64.P1.S1aCTime + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +theorem sched.append.kwB8 {T Ω Sg Scs Es X : Set U64} {Z : U64 → Nat} {Q : U64 → U64 → List U64} + {R : U64 → List U64} (s : S) (t : obj.Tcb) (h : SchedQueuesInvX st T Cs Ω H X s Q R) (ht : t ∈ T) : + sched.append st s t ⦃ s' => K8.FootB st T Cs Sg Scs Z Es s s' ⦄ := by + have hc := h.aff t ht + have hp := h.prio t ht + have hR1 := h.ready _ hc + refine WP.spec_mono (sched.append.foot s t _ h.tcbs ht hp (h.nodes _ hc) (h.nodes _ h.cur) (hR1.1.rel _ hp) + (fun h0 => h.notQ ht h0 hc hp)) fun s' hh => + K8.FootB.of hh.1 fun b hb => hb.kwB8 ?_ hc h.cur ht (fun o ho => by omega) + intro w hw + rcases List.mem_cons.1 hw with rfl | hw + · exact ht + · exact (hR1.1.rel _ hp).mem w hw + +set_option maxHeartbeats 4000000 in +/-- **The SC's postpone from `CurOK`** is a `DMD p` step. -/ +theorem end_postpone.dmd (p : U64) {s : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (hc : CurOK st H.tcbs s) : + sched.postpone st s (L.cscW s) ⦃ s' => DMD st H Cs p s s' ∧ BK s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hcT : L.curW s ∈ H.tcbs := q.curT + obtain ⟨hSc, htc, hcore⟩ := hX.2.2.bound (L.curW s) hcT hc.bnd + rw [← hc.csc] at hSc htc hcore + have hco : OutsideObjs st H.tcbs Cs s (scCoreA (L.cscW s)) := q.omega _ ((objs_omega hX.1 hSg.sub).2 _ hSc).2.1 + have ht' : L.mem s (scTcbA (L.cscW s)) ∈ H.tcbs := by rw [htc]; exact hcT + have hr0 : (L.mem s (inqA (L.mem s (scTcbA (L.cscW s)))) &&& sched.Q_RELEASE) = 0#u64 := by rw [htc]; exact hc.rel + have F := spec_all (P := fun (K : {K : U64 // K.val < 4096 ∧ K.val % 8 = 0 ∧ + (K.val < 224 ∨ K.val = 3512 ∨ K.val = 3664 ∨ K.val = 3672)}) (s' : S) => + ∀ y ∈ H.tcbs, L.mem s' (wa y K.1) = L.mem s (wa y K.1)) + (WP.spec_mono (sched.postpone.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s _ Q R q ht' hr0 + hco hcore) fun _ _ => trivial) + fun K => sched.postpone.fld s _ Q R q ht' hr0 hco hcore K.2.1 K.2.2.1 + (by have := K.2.2.2; omega) (by have := K.2.2.2; omega) + refine WP.spec_mono (WP.spec_and (WP.spec_and (sched.postpone.allF s _ Q R q ht' hB hX hSg hr0 hco hcore + (by rw [htc]; exact hc.run) (by rw [htc]; exact hc.act) (by rw [htc]; exact hc.bnd) + (by rw [htc]; exact (hS.act _ (hc.csc ▸ hSc)).2 hc.rmx)) + (sched.postpone.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s _ Q R q ht' hr0 hco hcore)) F) ?_ + rintro s' ⟨⟨⟨Q', R', q', hB', hX', hSg', f5, -⟩, f⟩, k⟩ + exact ⟨DMD.ofNone h h0 Y VR (K8.Foot.d (K8.Foot.ofQ C.tcb f fun y hy K h1 h2 h3 => k ⟨K, h1, h2, h3⟩ y hy)) + (LvF.of_fr C f5), ⟨⟨Q', R', q'⟩, hB', hX', hS.fr f5, hSg'⟩⟩ + +set_option maxHeartbeats 4000000 in +/-- **`end_suff`'s block is a `DMD p` step** (module docstring). -/ +theorem end_suff.dmd (hA : P0.ArchTotal ar) (p : U64) {s : S} (a : A) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hc : CurOK st H.tcbs s) : + (do + let b ← sporadic.ready st s (L.cscW s) + if b = true then do + let b1 ← sporadic.sufficient st ar s a (L.cscW s) 0#u64 + if b1 = true then do let s1 ← sched.append st s (L.curW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a)) ⦃ s' _ => DMD st H Cs p s s' ∧ BK s' ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hcT : L.curW s ∈ H.tcbs := q.curT + have PP : (do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a)) ⦃ s' _ => DMD st H Cs p s s' ∧ BK s' ⦄ := + WP.spec_bind (end_postpone.dmd p h h0 Y VR hc) fun s1 h1 => (WP.spec_ok _).2 h1 + step with sporadic.ready.spec as ⟨b⟩ + split + · step with sporadic.sufficient.ok (st := st) hA as ⟨b1⟩ + split + · refine WP.spec_bind (WP.spec_and (sched.append.sch s _ Q R q hB hSg hcT (fun _ => hc.rel) (fun _ => hc.run) + (fun _ => hc.bnd) (fun _ => (hS.act _ (hX.2.2.bound _ hcT hc.bnd).1).2 hc.rmx)) + (sched.append.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s _ q hcT)) ?_ + rintro s1 ⟨⟨p1, -, -, -⟩, f1⟩ + obtain ⟨b1', -, d1⟩ := qstep p h h0 Y VR p1 (K8.FootB.foot f1) + exact (WP.spec_ok _).2 ⟨d1, b1'⟩ + · exact PP + · exact PP + +section top +variable {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} + +/-- **A Reply-walk post gives the S1a step post** (S1aCAll's `S1aStepR2K.ofXfer2`). -/ +theorem S1aStepR2K.ofRpPost {K : capability.Cap → Prop} {Ty : S → Prop} {s s' : S} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (P : RpPost st H Cs OS Vc ia ie Ac s s') + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n s' := + S1aStepR2K.ofXfer2 ((fun h => ⟨h.1, h.2, P.2.2.2.2.1.1, P.2.2.2.2.2⟩) + (ArmQIAt.ofXC (Vc := Vc) ⟨P.1, P.2.1⟩ ⟨Ac, P.2.2.1⟩ P.2.2.2.1 P.2.2.2.2.1.1.toVs)) I.del.vr I.fu I.vcc C Df R sep KC + +set_option maxHeartbeats 8000000 in +/-- **`end_timeslice` keeps the S1a step post**: the append / postpone block (`end_suff.dmd`) or the timeout fault IPC +(S1aCReplyTo's `handle_timeout.rpw`). Per-state facts: `CurOK`, the placement `Pz` (any extra slots and invoked slot), +the current thread can block, `RunVcpuInv`. -/ +theorem sched.end_timeslice.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) (cto : Bool) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (hc : CurOK st H.tcbs s) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (hcb : CanBlock st H.tcbs Ac s (L.curW s)) + (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.end_timeslice st ar s a cto ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have h0 := B.ly.h0 + have R0 : RpW st H Cs OS Vc ia ie Ac s s := RpW.start B Y h + have E : (do + let b ← sporadic.ready st s (L.cscW s) + if b = true then do + let b1 ← sporadic.sufficient st ar s a (L.cscW s) 0#u64 + if b1 = true then do let s1 ← sched.append st s (L.curW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a)) ⦃ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (end_suff.dmd hA 0#u64 a h h0 Y B.vr hc) fun r d => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at d ⊢ + exact S1aStepR2K.ofRpPost I (R0.dmdK Pz.heap Pz.os I.del.sca Pz.core0 I.del.vr hks + (fun k hk => by rw [h0] at hk; cases hk) d.1 d.2).1.post C Df R sep KC + unfold sched.end_timeslice + step with sched.cur_sc.spec as ⟨sc, sc_post⟩ + step with sched.cur_thread.spec as ⟨ct, ct_post⟩ + 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 obj.Tcb.state.spec + refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun valid _ => ?_ + · split + · exact P0.faults.valid_timeout_handler.p0 st s _ L.total + · simp + split + · split + · exact E + · split + · step with P0.obj.Sc.badge.p0 st _ s L.total as ⟨badge⟩ + exact WP.spec_mono (faults.handle_timeout.rpw hA a (L.curW s) _ Pz R0 I.del.sca I.ts hks I.del.vr hcb + (fun e => not_runnable_inactive (e ▸ hc.run)) hRV) fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact S1aStepR2K.ofRpPost I P C Df R sep KC + · exact E + · exact E + +end top + +/-- **A `DMD p` step after the Reply-walk post keeps it** (S1aCReplyW's `RpW.dmdK` over `XferSlots2`). -/ +theorem RpPost.dmdK {Vc' Ub' Pt' : Set U64} {p : U64} {s0 s s' : S} (P : RpPost st H Cs OS Vc ia ie Ac s0 s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s0) Pt') (hks : HeapKsOff H (L.ksb s0)) + (hp : ∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) p k) + (d : DMD st H Cs p s s') (b : BK s') : RpPost st H Cs OS Vc ia ie Ac s0 s' ∧ OSKeep st OS s s' := by + obtain ⟨Sy, Ym, bk, xc, xv, q, x1, v1, x2, v2⟩ := P + obtain ⟨Q, Rq, qq⟩ := id bk.1 + have hk : L.ksb s = L.ksb s0 := xv.1.1 + have hvr' : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt' := by rw [hk]; exact hvr + have hks' : HeapKsOff H (L.ksb s) := by rw [hk]; exact hks + obtain ⟨k, t, v⟩ := FootD.oskTabV (Vc := Vc) hH hO hSA hvr' hks' Sy.ly.ksw hc0 qq bk.2.2.2.2.sub + (fun e he => he) d.w + obtain ⟨S', Y'⟩ := SysL.dfMDOr (Xq := ∅) hH hO bk hSA hp Sy d + exact ⟨⟨S', Y', b, xc.trans (XC.keep k t), xv.trans (XV.keep v k), q, x1, v1, x2.keep fun z hz => k.capA hz, + v2.trans (XV.keep v k)⟩, k⟩ + +set_option maxHeartbeats 8000000 in +/-- **`end_timeslice` from a Reply-walk bundle state** to the walk's post (`sched.end_timeslice.s1a`'s body, from +`RpW s0 s`; `Pz` the placement at `s0`). -/ +theorem sched.end_timeslice.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s0 s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) (cto : Bool) + (R : RpW st H Cs OS Vc ia ie Ac s0 s) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s0)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s0) Pt') (hc : CurOK st H.tcbs s) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) : + sched.end_timeslice st ar s a cto ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have h0 := R.sys.ly.h0 + have E : (do + let b ← sporadic.ready st s (L.cscW s) + if b = true then do + let b1 ← sporadic.sufficient st ar s a (L.cscW s) 0#u64 + if b1 = true then do let s1 ← sched.append st s (L.curW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a) + else do let s1 ← sched.postpone st s (L.cscW s); ok (s1, a)) ⦃ s' _ => + RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := + WP.spec_mono (end_suff.dmd hA 0#u64 a R.blk h0 R.sym R.sys.vr hc) fun r d => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at d ⊢ + exact (R.dmdK Pz.heap Pz.os hSA Pz.core0 hvr hks (fun k hk => by rw [h0] at hk; cases hk) d.1 d.2).1.post + unfold sched.end_timeslice + step with sched.cur_sc.spec as ⟨sc, sc_post⟩ + step with sched.cur_thread.spec as ⟨ct, ct_post⟩ + 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 obj.Tcb.state.spec + refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun valid _ => ?_ + · split + · exact P0.faults.valid_timeout_handler.p0 st s _ L.total + · simp + split + · split + · exact E + · split + · step with P0.obj.Sc.badge.p0 st _ s L.total as ⟨badge⟩ + exact faults.handle_timeout.rpw hA a (L.curW s) _ Pz R hSA hTS hks hvr hcb + (fun e => not_runnable_inactive (e ▸ hc.run)) hRV + · exact E + · exact E + +set_option maxHeartbeats 16000000 in +/-- **`charge_budget` to the Reply-walk post** (QueueBudget2's `charge_budget.all` walk with `RpW`: the ring and the SC's +`CONSUMED` word, the node's `CONSUMED` word, `end_timeslice.rpw`, `reschedule_required`, `set_reprogram`). Per-state +facts as `charge_budget.all`'s, the placement `Pz`, the current thread can block, `RunVcpuInv`. -/ +theorem sched.charge_budget.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) (used : U64) (cto : Bool) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) : + sched.charge_budget st ar s a used cto ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s s' ⦄ := by + have h0 := B.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hcS : L.cscW s ∈ H.scs := hX.2.2.cur + have hcT0 : L.curW s ∈ H.tcbs := q.curT + have hW : RefillsWF st s (L.cscW s) (H.scBits (L.cscW s)) := hS.wf hcS hcA + obtain ⟨hP, hz⟩ := hX.1.sc _ hcS + have R0 : RpW st H Cs OS Vc ia ie Ac s s := RpW.start B Y h + have hp0 : ∀ {s1 : S} k, H 0#u64 = some k → ¬ (ia ≤ (0#u64).val ∧ (0#u64).val < ie) → + ∃ x ∈ OS, NamesA (capA st s1 x) 0#u64 k := fun k hk => by rw [h0] at hk; cases hk + have dK : ∀ {s1 s2 : S}, RpW st H Cs OS Vc ia ie Ac s s1 → DMD st H Cs 0#u64 s1 s2 → (BK s2) → + RpW st H Cs OS Vc ia ie Ac s s2 ∧ OSKeep st OS s1 s2 := + fun R d b => R.dmdK Pz.heap Pz.os hSA Pz.core0 hvr hks hp0 d b + unfold sched.charge_budget + step with sched.cur_sc.spec as ⟨sc, sc_post⟩ + have e1 : sc = L.cscW s := sc_post + subst e1 + step with sched.idle_sc.spec as ⟨s1⟩ + step with sc_ne.spec as ⟨b⟩ + -- the ring and the SC's `CONSUMED` word + refine WP.spec_bind (Pₘ := fun s2 => WritesIn st s s2 (fun b => InRing (L.cscW s) (H.scBits (L.cscW s)) b ∨ + b = core.num.U64.wrapping_add (L.cscW s) layout.sc.CONSUMED) ∧ + RefillsWF st s2 (L.cscW s) (H.scBits (L.cscW s))) ?_ ?_ + · split + · step with sporadic.is_round_robin.spec as ⟨b1⟩ + refine WP.spec_bind (Pₘ := fun s3 => RefillsWF st s3 (L.cscW s) (H.scBits (L.cscW s)) ∧ + WritesIn st s s3 (InRing (L.cscW s) (H.scBits (L.cscW s)))) ?_ ?_ + · split + · step with obj.Sc.refill_head.spec as ⟨hi, hi_post⟩ + step with obj.Sc.refill_tail.spec as ⟨ti, ti_post⟩ + step with sporadic.get.spec as ⟨hh, hh_post⟩ + step with sporadic.get.spec as ⟨tt, tt_post⟩ + step as ⟨i, _⟩ + step with sporadic.put.spec as ⟨s4, s4_post⟩ + subst hi_post ti_post s4_post + have h4 := hW.putS (r := { hh with amount := i }) hW.head_lt + have w4 := hW.frame_putS (r := { hh with amount := i }) hW.head_lt + obtain ⟨h8, -, -⟩ := hW.bounds + have hfit : (L.cscW s).val + 96 + 16 * (L.rhead s (L.cscW s)).val + 16 ≤ 2 ^ 64 := by + have := hW.bounds.2.2; have := hW.inside; have := hW.head_lt; have := hW.le_abs + have := absMax_lt (H.scBits (L.cscW s)); obtain ⟨-, hm, -⟩ := hW.bounds; omega + have htl : (L.rtail s (L.cscW s)).val < (L.rmax (L.putS s (L.cscW s) (L.rhead s (L.cscW s)) + { hh with amount := i }) (L.cscW s)).val := by + rw [rmax_putS h8 hfit]; exact hW.tail_lt + step with sporadic.put.spec as ⟨s5, s5_post⟩ + subst s5_post + exact ⟨h4.putS htl, w4.trans1 (h4.frame_putS htl)⟩ + · exact WP.spec_mono (WP.spec_and (sporadic.budget_check.wf hA a used hW rfl) + (sporadic.budget_check.fr hA a used hW rfl)) fun s3 hh3 => hh3 + · rintro s3 ⟨h3, w3⟩ + step with obj.Sc.consumed.spec as ⟨ci⟩ + step as ⟨total, _⟩ + step with obj.Sc.set_consumed.spec as ⟨s4, s4_post⟩ + subst s4_post + have hal : Aligned (core.num.U64.wrapping_add (L.cscW s) layout.sc.CONSUMED) := by + obtain ⟨h8, -, -⟩ := sc_lo hP hz + unfold Aligned; rw [sc_word_val hP hz (by simp [layout.sc.CONSUMED])]; simp [layout.sc.CONSUMED]; omega + exact ⟨(w3.trans (writesIn_wr hal)).mono fun b hb => by + rcases hb with hb | hb + · exact Or.inl hb + · exact Or.inr hb, h3.wr_cons⟩ + · simp only [WP.spec_ok]; exact ⟨WritesIn.refl _ _, hW⟩ + rintro s2 ⟨w2, wf2⟩ + have hS2 := SCsOK.ringc q hS hX hcS w2 wf2 + obtain ⟨h2, hB2, hX2, hSg2, ea2, ec2, ecs2, f2⟩ := ring_bx q hB hX hSg hcS w2 + have b2 : BK s2 := ⟨⟨Q, R, h2⟩, hB2, hX2, hS2, hSg2⟩ + have hv := sc_word_val hP hz (o := layout.sc.CONSUMED) (by simp [layout.sc.CONSUMED]) + obtain ⟨-, h128, -⟩ := sc_lo hP hz + have inC : InSC (L.cscW s) (H.scBits (L.cscW s)) (core.num.U64.wrapping_add (L.cscW s) layout.sc.CONSUMED) := + ⟨by rw [hv]; simp, by rw [hv]; simp [layout.sc.CONSUMED]; omega⟩ + have d2 : DMD st H Cs 0#u64 s s2 := DMD.ofNSc h h0 Y B.vr (w2.mono fun b hb => by + rcases hb with hr | e + · have hv80 := hr.1 + exact NScW.ofSC hcS hP hz hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · rw [e] + exact NScW.ofSCo hcS hP hz (by simp [layout.sc.CONSUMED]) + ⟨by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], + by simp [layout.sc.CONSUMED], fun e => absurd e (by simp [layout.sc.CONSUMED])⟩) + obtain ⟨R2, -⟩ := dK R0 d2 b2 + have rv2 : ∀ y ∈ H.tcbs, L.mem s2 (runVcpuA y) = L.mem s (runVcpuA y) := fun y hy => + w2.mem_eq (field_aligned (K := 3672#u64) (q.tcbs y hy) (by simp) (by simp)) fun hb => by + have hal := field_aligned (K := 3672#u64) (q.tcbs y hy) (by simp) (by simp) + rcases hb with hr | e + · exact out_ne_field (q.omega _ (hX.1.scW _ hcS _ hal hr.inSC)) hy (q.tcbs y hy) (K := 3672#u64) (by simp) rfl + · exact out_ne_field (q.omega _ (hX.1.scW _ hcS _ hal (by rw [show wa y 3672#u64 = _ from e]; exact inC))) hy (q.tcbs y hy) (K := 3672#u64) + (by simp) rfl + -- the node's `CONSUMED` + step with sched.set_consumed.spec as ⟨s3, s3_post⟩ + rw [show L.nodeA s2 layout.node.CONSUMED = L.nodeAt s2 (L.cpu s2) layout.node.CONSUMED from rfl] at s3_post + obtain ⟨h3, hB3, hX3, hSg3, ea3, ec3, ecs3, f3⟩ := node_bx (o := layout.node.CONSUMED) (v := 0#u64) h2 hB2 hX2 hSg2 + (by simp [layout.node.CONSUMED, LowFree]) (by simp [layout.node.CONSUMED]) (by simp [layout.node.CONSUMED]) + have hN2 := h2.nodes _ h2.cur + have hco : (layout.node.CONSUMED).val = 40 := by simp [layout.node.CONSUMED] + have hS3 : SCsOK st H.tcbs H.omega H.frame H.scs H.scBits Ac + (L.wr s2 (L.nodeAt s2 (L.cpu s2) layout.node.CONSUMED) 0#u64) := by + obtain ⟨-, hc⟩ := objs_omega hX2.1 hS2.sub + refine SCsOK.wr h2 hS2 hX2 (nodeAt_aligned hN2 (by rw [hco]; omega) (by rw [hco])) (fun y hy => ?_) ?_ + (fun c hc' => ?_) (fun c hc' => out_ne_node (h2.omega _ (spor_omega hX2.1 hc')) h2.cur hN2 (by rw [hco]; omega)) + (fun c hc' e => absurd e (out_ne_node (h2.omega _ (hS2.sub _ (hX2.1.repW c hc'))) h2.cur hN2 (by rw [hco]; omega))) + · rw [scA_eq]; exact fun e => node_ne_field hN2 (by rw [hco]; omega) hy (h2.tcbs y hy) (by simp) + (UScalar.eq_of_val_eq e) + · intro e + simp only [LawfulStore.nodeA] at e + rw [nodeAt_val hN2 (by rw [hco]; omega), nodeAt_val hN2 (by simp [layout.node.CUR_SC]), hco] at e + simp [layout.node.CUR_SC] at e + · obtain ⟨-, -, c3, c4, c5⟩ := hc c hc' + exact ⟨out_ne_node (h2.omega _ c3) h2.cur hN2 (by rw [hco]; omega), + out_ne_node (h2.omega _ c4) h2.cur hN2 (by rw [hco]; omega), + out_ne_node (h2.omega _ c5) h2.cur hN2 (by rw [hco]; omega)⟩ + have d3 : DMD st H Cs 0#u64 s2 (L.wr s2 (L.nodeAt s2 (L.cpu s2) layout.node.CONSUMED) 0#u64) := + nodew_dmd b2 h0 R2.sym R2.sys.vr h2.cur (by rw [hco]; omega) (by rw [hco]) (by rw [hco]; omega) + (fun _ => by rw [hco]; omega) + have rv3 : ∀ y ∈ H.tcbs, L.mem (L.wr s2 (L.nodeAt s2 (L.cpu s2) layout.node.CONSUMED) 0#u64) (runVcpuA y) = + L.mem s2 (runVcpuA y) := fun y hy => + L.mem_wr_ne (nodeAt_aligned hN2 (by rw [hco]; omega) (by rw [hco])) + (field_aligned (K := 3672#u64) (h2.tcbs y hy) (by simp) (by simp)) + (fun e => node_ne_field hN2 (by rw [hco]; omega) hy (h2.tcbs y hy) (K := 3672#u64) (by simp) + (UScalar.eq_of_val_eq e)) + rw [← s3_post] at h3 hB3 hX3 hSg3 ea3 ec3 ecs3 f3 hS3 d3 rv3 + have b3 : BK s3 := ⟨⟨Q, R, h3⟩, hB3, hX3, hS3, hSg3⟩ + obtain ⟨R3, -⟩ := dK R2 d3 b3 + step with sched.cur_thread.spec as ⟨ct, ct_post⟩ + have e2 : ct = L.curW s3 := ct_post + subst e2 + step with sched.is_schedulable.spec' as ⟨b1, b1_post⟩ + split + · rename_i hb1 + obtain ⟨hrun, hbd, hrl, hrm⟩ := b1_post hb1 + have hcT : L.curW s ∈ H.tcbs := hcT0 + have esc : L.mem s3 (scA (L.curW s3)) = L.mem s (scA (L.curW s)) := by + rw [ec3, ec2, (f3 _ hcT).1, (f2 _ hcT).1] + have hc : CurOK st H.tcbs 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⟩ + have est : L.mem s3 (stA (L.curW s)) = L.mem s (stA (L.curW s)) := (f3 _ hcT).2.1.trans (f2 _ hcT).2.1 + have eq' : L.mem s3 (inqA (L.curW s)) = L.mem s (inqA (L.curW s)) := (f3 _ hcT).2.2.trans (f2 _ hcT).2.2 + have esa : L.mem s3 (scA (L.curW s)) = L.mem s (scA (L.curW s)) := (f3 _ hcT).1.trans (f2 _ hcT).1 + have hcb3 : CanBlock st H.tcbs Ac s3 (L.curW s3) := by + rw [ec3, ec2] + exact ⟨hcb.mem, by rw [est]; exact hcb.nb, by rw [est]; exact hcb.nrp, by rw [eq']; exact hcb.nq, + by rw [eq']; exact hcb.nr, by rw [ea3, ea2]; exact hcb.na, by rw [d3.idle, d2.idle]; exact hcb.ni, + by rw [esa]; exact hcb.ac⟩ + have hRV3 : RunVcpuInv st H.tcbs s3 := + hRV.keep (fun y hy => (f3 y hy).2.1.trans (f2 y hy).2.1) fun y hy => (rv3 y hy).trans (rv2 y hy) + refine WP.spec_bind (sched.end_timeslice.rpw hA a cto R3 Pz hSA hTS hks hvr hc hcb3 hRV3) ?_ + rintro ⟨s4, a1⟩ P4 + simp only [WP.uncurry'_pair] at P4 + try simp only [WP.uncurry'_pair] + obtain ⟨⟨Q4, R4, h4⟩, hB4, hX4, hS4, hSg4⟩ := id P4.2.2.1 + refine WP.spec_bind (WP.spec_and (sched.reschedule_required.sch s4 Q4 R4 h4 hB4 hSg4) + (K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s4 h4)) ?_ + rintro s5 ⟨⟨p5, -, -, -⟩, f5⟩ + obtain ⟨b5, -, d5⟩ := qstep 0#u64 P4.2.2.1 h0 P4.2.1 P4.1.vr p5 f5 + have P5 := (RpPost.dmdK P4 Pz.heap Pz.os hSA Pz.core0 hvr hks hp0 d5 b5).1 + obtain ⟨⟨Q5, R5, h5⟩, hB5, hX5, hS5, hSg5⟩ := id b5 + refine WP.spec_bind (sched.set_reprogram.spec s5) fun s6 e6 => ?_ + subst e6 + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + obtain ⟨b6, -⟩ := node_any_blk b5 h5.cur (by rw [rp]; unfold LowFree; omega) (by rw [rp]; omega) (by rw [rp]; omega) + have d6 := nodew_dmd (p := 0#u64) (v := 1#u64) b5 h0 P5.2.1 P5.1.vr h5.cur (o := layout.node.REPROGRAM) + (by rw [rp]; omega) (by rw [rp]) (by rw [rp]; omega) (fun _ => by rw [rp]; omega) + exact (WP.spec_ok _).2 (RpPost.dmdK P5 Pz.heap Pz.os hSA Pz.core0 hvr hks hp0 d6 b6).1 + · simp only [WP.spec_ok, WP.uncurry'_pair] + exact R3.post + +section top2 +variable {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} + +/-- **`charge_budget` keeps the S1a step post** (`charge_budget.rpw`, `S1aStepR2K.ofRpPost`). -/ +theorem sched.charge_budget.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) (used : U64) (cto : Bool) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.charge_budget st ar s a used cto ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.charge_budget.rpw (Vc := Vc) hA a used cto B Y h Pz I.del.sca I.ts hks I.del.vr hcsc hna hcA + hcb hRV) fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact S1aStepR2K.ofRpPost I P C Df R sep KC + +end top2 + +set_option maxHeartbeats 8000000 in +/-- **`check_budget` / `check_budget_restart` to the Reply-walk post** (`charge_budget.rpw`; the restart of a runnable +current thread as a `DMD ct` step, the thread named since live). -/ +theorem sched.check_budget_restart.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) : + sched.check_budget_restart st ar s a ⦃ r => RpPost st H Cs OS Vc ia ie Ac s r.2.1 ⦄ := by + have h0 := B.ly.h0 + have CB : sched.check_budget st ar s a ⦃ r => RpPost st H Cs OS Vc ia ie Ac s r.2.1 ⦄ := by + unfold sched.check_budget + step with sched.cur_sc.spec as ⟨sc⟩ + step with sched.consumed.spec as ⟨c⟩ + step with sporadic.sufficient.ok (st := st) hA as ⟨b⟩ + split + · unfold sched.is_cur_domain_expired + simp only [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + have hnd : ¬ ((1#u64) > (1#u64)) := by simp + simp only [hnd, ↓reduceIte, bind_ok, WP.spec_ok] + exact (RpW.start (Vc := Vc) B Y h).post + · refine WP.spec_bind (sched.charge_budget.rpw (Vc := Vc) hA a c true B Y h Pz hSA hTS hks hvr hcsc hna hcA + hcb hRV) ?_ + rintro ⟨s1, a1⟩ P1 + simp only [WP.uncurry'_pair] at P1 + exact (WP.spec_ok _).2 P1 + unfold sched.check_budget_restart + refine WP.spec_bind CB ?_ + rintro ⟨r, s1, a1⟩ P1 + try simp only [WP.uncurry'_pair] + step with sched.cur_thread.spec as ⟨ct, ct_post⟩ + have hct : ct ∈ H.tcbs := by rw [ct_post]; exact P1.2.2.1.1.choose_spec.choose_spec.curT + split + · exact (WP.spec_ok _).2 P1 + step with sched.is_runnable.spec' as ⟨b, b_post⟩ + split + · rename_i hb + have hrun := b_post hb + obtain ⟨hnb, hnr⟩ := runnable_ok hrun + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.restart_blk (Es := ∅) s1 ct P1.2.2.1 hct hnb hnr) + (sched.set_thread_state.dmdT ct _ P1.2.2.1 h0 P1.2.1 P1.1.vr hct hnr)) fun s2 hh => ?_ + obtain ⟨⟨b2, -, -, -⟩, d2⟩ := hh + refine (WP.spec_ok _).2 (RpPost.dmdK P1 Pz.heap Pz.os hSA Pz.core0 hvr hks (fun k hk hia => ?_) d2 b2).1 + have e : H ct = some .tcb := hct + rw [e] at hk; cases hk + exact P1.1.ln ct .tcb hct (LiveQ.tcb hct (Or.inl fun e' => not_runnable_inactive (e' ▸ hrun))) hia + · exact (WP.spec_ok _).2 P1 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCBufAt.lean b/proofs/Fl4ProofsA64/P1/S1aCBufAt.lean new file mode 100644 index 000000000..b94cec98d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCBufAt.lean @@ -0,0 +1,39 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c2 part 1): **`BufAt` from the deletion inputs** (contract §5: no new +premise). + +* **`BufAt.ofS1a`**: QueueSignal's `BufAt` at `U := Ub` (the deletion inputs' user frame words): the user words by + `DelIn.vty`'s `usr`; every thread's IPC buffer by MdbXferQ's `lookup_bufKC` (its 1024 bytes are words of an `OS` + slot's non-device frame, `BufCw`) and `DelIn.fu` (`FrUb`: those words are in `Ub`). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCBudget + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add + +/-- **`BufAt` from the deletion inputs** (module docstring). -/ +theorem BufAt.ofS1a {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (B : SysL st H Cs OS ia ie s) : BufAt st H.tcbs Cs H H.frame H.scs H.scBits Ub s := by + refine ⟨I.vty.usr, fun y hy => WP.spec_mono (lookup_bufKC B I.del.heap + (by rw [sbA_slotIdx]; exact I.ts y hy 2#u64 (by simp)) (B.ipc y hy)) fun b hb hb0 i hi => ?_⟩ + obtain ⟨⟨h1024, ptr0, z, hp0, hl0, hu0, -⟩, -, hcw⟩ := hb hb0 + have hfit := I.del.heap.fits ptr0 _ hp0 + simp only [HKind.bits] at hfit + have hm : (core.num.U64.wrapping_mul i 8#u64).val = i.val * 8 := by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega + have hv : (wa b (core.num.U64.wrapping_mul i 8#u64)).val = b.val + i.val * 8 := by + rw [wadd_val (by rw [hm]; omega), hm] + obtain ⟨y', hy', ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := hcw _ (by rw [hv]; omega) + (by rw [hv]; omega) + exact I.fu y' hy' ptr size rights x1 x2 x3 x4 hc bits hbits _ (by unfold Aligned; rw [hv]; omega) h1 h2 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCCbs.lean b/proofs/Fl4ProofsA64/P1/S1aCCbs.lean new file mode 100644 index 000000000..beadeb8d1 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCCbs.lean @@ -0,0 +1,345 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a7)): **CNode CancelBadgedSends keeps every capability** +(endpoint.rs `cancel_badged_sends`). + +* **`endpoint.cancel_badged_sends_loop.lv`**: the loop writes `STATE` words only (liveness-wise), keeps + `ValidReplies` and makes no thread active, no thread newly blocked (`StBM`). +* **`endpoint.cancel_badged_sends.dmE`**: no object becomes live. +* **`syscall.decode_invocation.cbs_armS`**: the caller's restart, then the walk when the badge is not zero. The + endpoint is typed by the destination slot's `SlotTy`. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCDm2 +import Fl4ProofsA64.P1.MdbArmDm +import Fl4ProofsA64.P1.MdbLiveE +import Fl4ProofsA64.P1.MdbCnDelArm +import Fl4ProofsA64.P1.QueueCbs + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add + +set_option maxHeartbeats 4000000 in +/-- **The badged walk**: `BlkOK`, the footprint, `STATE` words only, `ValidReplies`, `StBM`. -/ +theorem endpoint.cancel_badged_sends_loop.lv (s : S) (ep badge t fuel : U64) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hH : H ep = some .ep) + (ht : CbsAt st H.tcbs ep s t) (VR : ValidReplies st H s) : + endpoint.cancel_badged_sends_loop st s ep badge t fuel ⦃ s' => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits {ep} s s' ∧ + LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.sts s s' ∧ ValidReplies st H s' ∧ + StBM st H.tcbs H.replies s s' ⦄ := by + have hST : P0.StoreTotal st := L.total + unfold endpoint.cancel_badged_sends_loop + apply loop.spec_decr_nat (measure := fun x => x.2.2.val) + (inv := fun x => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac x.1 ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits {ep} s x.1 ∧ CbsAt st H.tcbs ep x.1 x.2.1 ∧ + LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.sts s x.1 ∧ ValidReplies st H x.1 ∧ + StBM st H.tcbs H.replies s x.1) + · rintro ⟨s1, y, f1⟩ ⟨hb1, hf1, ht1, hg1, hv1, hm1⟩ + simp only at hb1 hf1 ht1 hg1 hv1 hm1 + unfold endpoint.cancel_badged_sends_loop.body + step with obj.Tcb.is_null.spec as ⟨b, eb⟩ + split + · exact (WP.spec_ok _).2 ⟨hb1, hf1, hg1, hv1, hm1⟩ + rename_i hb + have hy0 : y ≠ 0#u64 := fun e => hb (by rw [eb, e]; rfl) + obtain ⟨hdT, hbe, hsend⟩ := ht1 hy0 + split + swap + · exact (WP.spec_ok _).2 ⟨hb1, hf1, hg1, hv1, hm1⟩ + rename_i hfuel + step as ⟨fuel1, efuel⟩ + have C1 := LvC.of_blk hb1 + have hRI := hb1.2.2.1.2.1 + obtain ⟨⟨Q, R, h0⟩, hB, hX, hS, hSg⟩ := hb1 + have hT := h0.tcbs + have hta := hT y hdT + obtain ⟨E, EQ, w1, w2, w5, w3, w4, ty⟩ := h0.eps + have hbl : Blocked (L.mem s1 (stA y)) := by rw [hsend]; exact Or.inl rfl + obtain ⟨heE, hyQ⟩ := w4 y hdT (by simp) hbl + rw [hbe] at heE hyQ + obtain ⟨hE, -, hq⟩ := w1 ep heE + unfold tcbqueue.next_of + step with tcbqueue.next.spec as ⟨next, enext⟩ + have hnext : next = 0#u64 ∨ (next ∈ EQ ep ∧ next ≠ y) := by + rw [enext]; exact seg_next hq.seg hq.nodup hyQ + have hN1 : CbsAt st H.tcbs ep s1 next := fun hn0 => by + rcases hnext with e | ⟨hm, -⟩ + · exact absurd e hn0 + obtain ⟨-, hbn, -⟩ := w3 ep heE next hm + exact ⟨hq.mem next hm, hbn, by rw [ty.2.2.2.1 ep heE next hm y hyQ, hsend]⟩ + step with P0.obj.Tcb.block_badge.p0 st y s1 hST as ⟨i⟩ + split + swap + · exact (WP.spec_ok _).2 ⟨⟨⟨Q, R, h0⟩, hB, hX, hS, hSg⟩, hf1, hN1, hg1, hv1, hm1, by simp only; omega⟩ + have hnrun := not_runnable_of_blocked hbl + obtain ⟨-, -, da⟩ := blocked_out h0 hdT hnrun + have hnQ : ∀ c ∈ Cs, ∀ p : U64, p.val < 256 → y ∉ Q c p := fun c hc p hp htq => hnrun (h0.runQ c hc p hp y htq) + have hnR : ∀ c ∈ Cs, y ∉ R c := fun c hc htr => hnrun (h0.runR c hc y htr) + have hdq := endpoint.ep_dequeue.inv s1 y Q R h0 hdT (by simp) hbl + rw [hbe] at hdq + refine WP.spec_bind (WP.spec_and hdq (endpoint.ep_dequeue.foot s1 ep y _ hT hE hq hyQ)) ?_ + rintro s2 ⟨⟨h2, f2, o2, n2, k2, c2, nc2⟩, w2'⟩ + have tm2 : TmFr st H.tcbs Cs H.ntfns s1 s2 := TmFr.mk0 ⟨k2, fun y hy K a b c => f2 y hy K (by omega) c (by omega) + (by omega), fun c hc o ho => nc2 c hc o (by omega) (by omega), fun n' hn' => o2 _ (hSg.sub _ (hX.1.ntB n' hn').2)⟩ + obtain ⟨hB2, hX2, hS2, hSg2, ea2, -, -⟩ := frame_bx h0 hB hX hS hSg f2 o2 n2 k2 tm2 + have g2 := LvF.of_dq C1 k2 c2 n2 nc2 f2 o2 + have C2 := C1.of_lv g2 + have fw2 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits {ep} s1 s2 := K8.Foot.of w2' fun b hb => hb.kw8 hq.mem rfl + have st2 : L.mem s2 (stA y) = L.mem s1 (stA y) := by + rw [stA_eq]; exact f2 y hdT _ (by simp) (by simp) (by simp) (by simp) + have da2 : L.actionW s2 ≠ y := by rw [ea2]; exact da + have hyA2 : L.mem s2 (scA y) ≠ 0#u64 → L.mem s2 (scA y) ∈ Ac := by + have esc2 : L.mem s2 (scA y) = L.mem s1 (scA y) := by + rw [scA_eq]; exact f2 y hdT _ (by simp) (by simp) (by simp) (by simp) + rw [esc2]; exact hB.sact y hdT (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl hbl)))))) + have cg1 : ∀ z ∈ {z : U64 | z ∈ (∅ : Set U64) ∨ z = y}, z = y := fun z hz => by simpa using hz + obtain ⟨-, -, r3, r4, -⟩ := ts_vals + have nrp : sched.TS_BLOCKED_ON_SEND ≠ sched.TS_BLOCKED_ON_REPLY := by + rw [r4]; unfold sched.TS_BLOCKED_ON_REPLY; decide + have nrc : sched.TS_BLOCKED_ON_SEND ≠ sched.TS_BLOCKED_ON_RECV := by rw [r4, r3]; decide + have hsend2 : L.mem s2 (stA y) = sched.TS_BLOCKED_ON_SEND := by rw [st2, hsend] + have noref := hX2.noref hta (by rw [hsend2]; exact nrp) (by rw [hsend2]; exact nrc) + refine WP.spec_bind (WP.spec_and + (K8.endpoint.restart_thread_if_no_fault.blk s2 y h2 cg1 hB2 hX2 hS2 hSg2 hdT (Or.inl (Or.inr rfl)) + noref hnQ hnR da2 hyA2) + (endpoint.restart_thread_if_no_fault.lv s2 y C2 h2 cg1 hB2 hX2 hS2 hSg2 hdT (Or.inl (Or.inr rfl)) + noref hnQ hnR da2 hyA2)) ?_ + rintro s3 ⟨⟨h3, fw3⟩, -, g3, nb3, b3⟩ + have g13 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.tc y 3328) s1 s3 := + (g2.trans g3).mono ⟨fun _ _ h => h.elim False.elim id, fun _ _ h => h.elim False.elim id, + fun _ _ h => h.elim False.elim id, fun _ _ h => h.elim False.elim id⟩ + have hnr : L.mem s1 (stA y) ≠ sched.TS_BLOCKED_ON_REPLY := by rw [hsend]; exact nrp + have kst : ∀ z ∈ H.tcbs, z ≠ y → L.mem s3 (stA z) = L.mem s1 (stA z) := fun z hz hzy => by + rw [stA_eq]; exact g13.t z hz 3328#u64 (by unfold LvO; simp) fun e => hzy e.1 + have m13 : StBM st H.tcbs H.replies s1 s3 := by + refine ⟨fun z hz h => ?_, fun z hz hb => ?_, fun r hr r0 h => ?_⟩ + · by_cases e : z = y + · subst e; exact blocked_ne_inactive hbl + · rwa [kst z hz e] at h + · have hzy : z ≠ y := fun e => by subst e; exact nb3 hb + refine ⟨kst z hz hzy, ?_⟩ + rw [b3 z hz hzy, blockA_eq]; exact f2 z hz _ (by simp) (by simp) (by simp) (by simp) + · have e : L.mem s3 (rTcbA r) = L.mem s1 (rTcbA r) := + g13.r r hr _ (by unfold LvRO; simp [layout.reply.TCB]) fun e => False.elim e + rwa [e] at h + refine (WP.spec_ok _).2 ⟨h3, hf1.trans (fw2.trans (fw3.mono (Set.empty_subset _))), fun hn0 => ?_, + (hg1.trans g13).mono ⟨fun _ _ h => h.elim id And.right, fun _ _ h => h.elim id id, + fun _ _ h => h.elim id id, fun _ _ h => h.elim id id⟩, + hv1.rnd hRI (g13.mono (RndX.le_tc s1 y)) hdT hnr, hm1.trans m13, by simp only; omega⟩ + obtain ⟨hnT, hnb, hns⟩ := hN1 hn0 + have hny : next ≠ y := by + rcases hnext with e | ⟨-, hne⟩ + · exact absurd e hn0 + · exact hne + refine ⟨hnT, ?_, ?_⟩ + · rw [b3 next hnT hny, blockA_eq, f2 next hnT _ (by simp) (by simp) (by simp) (by simp), ← blockA_eq]; exact hnb + · rw [kst next hnT hny]; exact hns + · exact ⟨h, K8.Foot.refl _, ht, LvF.refl _ _ |>.mono (LvF.none_le _), VR, StBM.refl s⟩ + +set_option maxHeartbeats 1000000 in +/-- **`cancel_badged_sends ep`** makes no object live. -/ +theorem endpoint.cancel_badged_sends.dmE {s : S} (ep badge : U64) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hH : H ep = some .ep) + (h0 : H 0#u64 = none) (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + endpoint.cancel_badged_sends st s ep badge ⦃ s' => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' ∧ DME st H Cs (fun _ => False) s s' ⦄ := by + have C := LvC.of_blk h + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + have done : ∀ s' : S, BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' → + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' → + LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.sts s s' → ValidReplies st H s' → + (∀ y ∈ H.tcbs, L.mem s' (stA y) ≠ sched.TS_INACTIVE → L.mem s (stA y) ≠ sched.TS_INACTIVE) → + (∀ r ∈ H.replies, r ≠ 0#u64 → L.mem s' (rTcbA r) ≠ 0#u64 → L.mem s (rTcbA r) ≠ 0#u64) → + EpM st H s s' → + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' ∧ DME st H Cs (fun _ => False) s s' := by + intro s' h' f g V' msta mr M + have Y' : YieldS st H.tcbs H.scs s' := Y.yld.lv hX.2.2.yt g + (fun y k hk => by have e : k = 3328 := hk; subst e; decide) (fun c k hk => hk.elim) + have D' := Y.dbg.lv hz g fun y k hk => by + have e : k = 3328 := hk + subst e; decide + have Ys : SymL st H Cs s' := ⟨D', Y'⟩ + have M1 := M.1 + have M2 := M.2 + have fl : ∀ y ∈ H.tcbs, ∀ o : U64, LvO o.val → o.val ≠ 3328 → L.mem s' (wa y o) = L.mem s (wa y o) := + fun y hy o hO hne => g.t y hy o hO hne + have nzx : NzX st H Cs (fun _ => False) s s' := by + refine ⟨fun y hy _ hs => msta y hy hs, fun y hy _ => ⟨NzW.eq (fl y hy 3464#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3368#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3472#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3528#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3576#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3584#u64 (by unfold LvO; simp) (by simp))⟩, + fun c hc _ => ⟨NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.TCB]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.REPLY]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.NTFN]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.YIELD_FROM]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.REFILL_MAX]) (fun h => h))⟩, + fun e he _ => M1 e he, fun n hn _ => M2 n hn, + fun n hn _ => ⟨NzW.eq (g.n n hn _ (by unfold LvNO; simp [layout.ntfn.BOUND_TCB]) (fun h => h)), + NzW.eq (g.n n hn _ (by unfold LvNO; simp [layout.ntfn.SC]) (fun h => h))⟩, + fun r hr _ => mr r hr (ne0_of_heap h0 hr), + fun c hc q _ _ e => Or.inr ⟨c, hc, (g.hd c hc).symm.trans e⟩⟩ + refine ⟨h', f, K8.Foot.d f, LvM.ofNzX nzx Y Ys hz h0, g.idle, ?_, V', Ys⟩ + rw [g.idle] + exact fl _ hI 3464#u64 (by unfold LvO; simp) (by simp) + unfold endpoint.cancel_badged_sends + step with obj.Ep.state.spec as ⟨v, hv⟩ + split + · exact (WP.spec_ok _).2 (done s h (K8.Foot.refl _) ((LvF.refl _ _).mono (LvF.none_le _)) VR + (fun _ _ h => h) (fun _ _ _ h => h) ⟨fun _ _ h => h, fun _ _ h => h⟩) + rename_i hsend + have hst : L.epState s ep = 1#u64 := by + rw [← hv]; apply UScalar.eq_of_val_eq; simpa [obj.EP_SEND] using hsend + step with endpoint.get_queue.spec as ⟨q, eq⟩ + subst eq + obtain ⟨hd, hbe, hs1, -⟩ := ep_head h.1.choose_spec.choose_spec hH (w := 1#u64) (Or.inl rfl) hst + refine WP.spec_bind (endpoint.cancel_badged_sends_loop.lv s ep badge _ _ h hH (fun _ => ⟨hd, hbe, hs1 rfl⟩) VR) ?_ + rintro s1 ⟨h1, f1, g1, v1, m1⟩ + have hb1 := h1 + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := h1 + refine WP.spec_mono (WP.spec_and (sched.reschedule_required.schX (Sg := H.frame) s1 Q1 R1 q1 hB1 hSg1) + (K8.sched.reschedule_required.blk s1 ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩)) ?_ + rintro s2 ⟨⟨-, -, f2, -⟩, h2, fw2⟩ + have g2 := LvF.of_fr (C.of_lv g1) f2 (Rp := H.replies) (Nt := H.ntfns) + have g12 : LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.sts s s2 := + (g1.trans g2).mono ⟨fun _ _ h => h.elim id False.elim, fun _ _ h => h.elim id False.elim, + fun _ _ h => h.elim id False.elim, fun _ _ h => h.elim id False.elim⟩ + have hsub : ({ep} : Set U64) ⊆ EH H := fun e he => by + rw [Set.mem_singleton_iff.1 he]; exact Or.inl hH + obtain ⟨M1, M2⟩ := epS_mono h hb1 m1.blk + have ek : ∀ e, (H e = some .ep ∨ H e = some .ntfn) → L.mem s2 (epTSA e) = L.mem s1 (epTSA e) := + ep_kept_kw hb1 fw2 + have er : ∀ r ∈ H.replies, L.mem s2 (rTcbA r) = L.mem s1 (rTcbA r) := fun r hr => + g2.r r hr _ (by unfold LvRO; simp [layout.reply.TCB]) fun e => False.elim e + refine done s2 h2 ((f1.mono hsub).trans (fw2.mono (Set.empty_subset _))) g12 + (v1.lv hX1.2.1 g2 (fun _ _ h => h.elim) (fun _ _ h => h) (BorK.of_lv g2 fun _ _ h => h.elim)) + (fun y hy hs => m1.sta y hy (by rwa [f2.st y hy] at hs)) + (fun r hr r0 hs => m1.rtcb r hr r0 (by rwa [er r hr] at hs)) + ⟨fun e he hs => M1 e he ?_, fun n hn hs => M2 n hn ?_⟩ + · unfold LawfulStore.epState at hs ⊢; rwa [ek e (Or.inl he)] at hs + · unfold LawfulStore.epState at hs ⊢; rwa [ek n (Or.inr hn)] at hs + +set_option maxHeartbeats 2000000 in +/-- **`cnode.decode` at CancelBadgedSends**: `SysL ∧ SymL`, `BlkOK` and the `DmW` frame. -/ +theorem cnode.decode.cbsLK {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hSA : ScApart H.scs H.scBits OS) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) + {lbl len buf : U64} (hl : lbl = fl4_abi.label.CNodeCancelBadgedSends) : + cnode.decode st ar s a lbl len cap buf extra ⦃ r => DmPost st H Cs OS ia ie Ac s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + have E0 : DmPost st H Cs OS ia ie Ac s s := DmPost.mk' ⟨B, Y⟩ D.bxi.blk (WritesIn.refl _ _) + have hc : RootOK OS cap := RootOK.of_slot P.ty P.src hcap + have hh : Held st OS s cap := ⟨slot, P.src, okinj ((capA_eq s slot).symm.trans hcap)⟩ + subst hl + unfold cnode.decode + simp only [error.illegal, error.truncated, bind_ok] + split + · exact (WP.spec_ok _).2 E0 + split + · exact (WP.spec_ok _).2 E0 + split + · exact (WP.spec_ok _).2 E0 + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e : ct = L.curW s := ect + subst e + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun idx _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun dep _ => ?_ + refine WP.spec_bind (lookup_tgt_irq P.heap P.ty B.cn cap hc hh idx dep) fun r hr => ?_ + rcases r with v | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 E0 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨hv, -, -, -⟩ := hr v rfl + have hep : ∀ p b x y z w, capA st s v = .Endpoint p b x y z w → H p = some .ep := fun p b x y z w e => by + have d : capability.Cap.decode (L.mem s v) (L.mem s (wa v 8#u64)) = ok (capA st s v) := by + rw [← DPF.slot_cap_dec]; exact capA_eq s v + exact ((P.ty v hv).1 _ d).1.1.1 p b x y z w e + repeat (first + | (refine spec_ite (fun hc => ?_) fun hc => ?_ <;> + try (exfalso; revert hc; first + | decide + | (simp only [fl4_abi.label.CNodeRevoke, fl4_abi.label.CNodeDelete, fl4_abi.label.CNodeCopy, + fl4_abi.label.CNodeMutate, fl4_abi.label.CNodeCancelBadgedSends, fl4_abi.label.CNodeRotate]; decide) + | (simp only [fl4_abi.label.CNodeRevoke, fl4_abi.label.CNodeDelete, fl4_abi.label.CNodeCopy, + fl4_abi.label.CNodeMutate, fl4_abi.label.CNodeCancelBadgedSends, fl4_abi.label.CNodeRotate]; done)))) + refine WP.spec_bind (Pₘ := fun r : (core.result.Result Unit error.Exc) × S => + DmPost st H Cs OS ia ie Ac s r.2) ?_ ?_ + swap + · rintro ⟨r, s2⟩ hr + exact (WP.spec_ok _).2 hr + unfold cnode.decode_cancel_badged_sends + rw [capA_eq s v, bind_ok] + refine WP.spec_bind (Pₘ := fun o => ∀ x, o = some x → H x.1 = some .ep) ?_ fun o ho => ?_ + · revert hep + generalize capA st s v = c + intro hep + unfold cnode.full_endpoint + cases c + all_goals first + | exact (WP.spec_ok _).2 fun x e => by cases e + | skip + case Endpoint p b x y z w => + cases x <;> cases y <;> cases z <;> cases w + all_goals (refine (WP.spec_ok _).2 fun x e => ?_; cases e) + all_goals (show H p = some .ep; exact hep p b _ _ _ _ rfl) + rcases o with _ | ⟨ptr, badge⟩ + · simp only [error.illegal, bind_ok] + exact (WP.spec_ok _).2 E0 + have hp : H ptr = some .ep := ho (ptr, badge) rfl + dsimp only + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e : ct = L.curW s := ect + subst e + have hst := tcb.restart_caller.restartRK D P B Y (Stalled.refl0 D) (DF.refl s) + have er : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by + unfold tcb.restart_caller; rw [cur_thread_ok, bind_ok] + rw [er] at hst + refine WP.spec_bind hst fun s1 ⟨R, d1⟩ => ?_ + split + · refine WP.spec_bind (endpoint.cancel_badged_sends.dmE ptr badge R.blk hp B.ly.h0 R.sys.vr R.sym) + fun s2 ⟨h2, f2, d2⟩ => ?_ + exact (WP.spec_ok _).2 (DmPost.mk' (SysL.dfE R.pl.heap R.pl.os R.blk.bxi.blk hSA (fun _ _ e => e.elim) R.sys d2) + h2 (DmW.trans (DmW.ofDF d1) (WritesIn.mono f2 fun _ hb => Or.inr hb))) + · exact (WP.spec_ok _).2 (DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + R.blk (DmW.ofDF d1)) + +/-- **CNode CancelBadgedSends** keeps every capability. -/ +theorem syscall.decode_invocation.cbs_armS {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok cap) (hf : capFam cap = .cnode) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.CNodeCancelBadgedSends) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := + syscall.decode_invocation.cnodeG (P := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ + ArmVsK st H OS Vc s x ∧ OSKeep st OS s x) + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩ + a len slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.cbsLK D P B Y hSA hcap a hl) fun r d => by + obtain ⟨_, s', _⟩ := r + have x := ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk + exact ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCCopyRegs.lean b/proofs/Fl4ProofsA64/P1/S1aCCopyRegs.lean new file mode 100644 index 000000000..2b093cdee --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCCopyRegs.lean @@ -0,0 +1,353 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a10)): **TCB CopyRegisters keeps every capability** (tcb.rs +`decode_copy_registers`, `copy_registers`). + +* **`obj.Tcb.set_reg.dmr`**: a register write from a `BlkOK` state is a MdbSspBind `DMR p q` step (any `p`, `q`): + MdbRegL's `set_reg.dfX` (its `K8` footprint, no SC word) and MdbLiveF's `regW_lv` (no liveness word), so MdbSigL's + `DMD.ofNone`; `BlkOK` by QueueDecTcb's `blk_rf`. +* **`tcb.copy_registers_loop0/1/2.dmr`**: the copy loops keep `BlkOK` and stay one `DMR p q` step. +* **`tcb.copy_registers.dmr`**: after the caller's restart (a `DelR` / `RsR` state), the whole `copy_registers` + (the optional `suspend src` by MdbSusQ's `sched.suspend.dmr`, the optional `restart dest` by S1aCRestart's + `sched.restart.dm`, the copy loops, the `NEXT_IP` write, S1aCRegs' `resched.dm`) is one `DMR dest src` step over + MdbSspTail's `SusW`, from `BlkOK` to `BlkOK`. +* Tops: **`tcb.decode_copy_registers.armSAt`** (the second stall by MdbVcRdL's `Stalled.stallD`, QueueVcTyThr's + `remote_tcb_stall.ds` and `vsk_node`; MdbHiVsArm's `restart_caller.delRP` / `armVsK`; then `SysL.dfMDR` with both + threads named by `OS` slots, `ArmQIAt.ofSusW`, `ArmVsK.ofSusW` and `ArmQIAt.transZ`, as MdbRegRQ's ReadRegisters), + **`tcb.decode.copyRegsSAt`**, **`syscall.decode_invocation.copyRegs_armS`** (the `*_armS` shape). + +Named premises: [P] `P0.ArchTotal`. Case facts: none new (`DelIn`, `HeapKsOff`, the invoked slot's cap). +-/ +import Fl4ProofsA64.P1.S1aCRegs +import Fl4ProofsA64.P1.MdbRegRQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- A `K8` word with no SC is a `K8` word with the heap's SCs. -/ +theorem kw8_scs {s0 : S} {b : U64} (h : K8.KW st H.tcbs Cs H.frame ∅ H.scBits ∅ s0 b) : + K8.KW st H.tcbs Cs H.frame H.scs H.scBits ∅ s0 b := by + rcases h with h | h | h | ⟨c, hc, -⟩ | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl h)) + · exact absurd hc (Set.notMem_empty c) + · exact Or.inr (Or.inr (Or.inr (Or.inr h))) + +/-- The empty `DMR p q` step. -/ +theorem DMR.refl' (p q : U64) {s : S} (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + DMR st H Cs Vc p q s s := + ⟨WritesIn.refl _ _, fun _ _ _ h => h, rfl, rfl, VR, Y⟩ + +/-- **A register write is a `DMR p q` step** (module docstring). -/ +theorem obj.Tcb.set_reg.dmr {p q : U64} {s : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) {t r v : U64} (ht : t ∈ H.tcbs) (hr : r.val < 384) : + obj.Tcb.set_reg st t s r v ⦃ s' => (BK s') ∧ DMR st H Cs Vc p q s s' ⦄ := by + have C := LvC.of_blk h + refine WP.spec_mono (WP.spec_and (obj.Tcb.set_reg.dfX (c := 0#u64) (Ko := ∅) (v := v) C ht hr) + (regW_lv C (v := v) ht hr)) ?_ + rintro s' ⟨⟨d, w⟩, g⟩ + have f : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' := K8.Foot.d (d.w.mono fun b hb => by + rcases hb with hb | ⟨o, ho, -⟩ + · exact kw8_scs hb + · exact absurd ho (Set.notMem_empty _)) + exact ⟨(blk_rf h w).1, DMV.toR (DMD.toV (q := q) (DMD.ofNone (p := p) h h0 Y VR f g))⟩ + +set_option maxHeartbeats 1000000 in +theorem tcb.copy_registers_loop0.dmr {p q : U64} {s0 s : S} {dest src i : U64} (h0 : H 0#u64 = none) + (hd : dest ∈ H.tcbs) (h : (BK s) ∧ DMR st H Cs Vc p q s0 s) : + tcb.copy_registers_loop0 st s dest src i ⦃ s' => (BK s') ∧ DMR st H Cs Vc p q s0 s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold tcb.copy_registers_loop0 + apply loop.spec_decr_nat (measure := fun y => 17 - y.2.val) + (inv := fun y => (BK y.1) ∧ DMR st H Cs Vc p q s0 y.1) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + try dsimp only + unfold tcb.copy_registers_loop0.body + try dsimp only + split + swap + · exact (WP.spec_ok _).2 h1 + rename_i hj + have hj' : j.val < 17 := by simpa [tcb.N_FRAME, tcb.N_GP] using hj + simp only [lift, bind_ok] + have hl : (UScalar.cast .Usize j : Usize).val < regs.FRAME_REGISTERS.val.length := by + rw [regs.FRAME_REGISTERS.property]; rw [cast_usize_small (by omega)]; simp; omega + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec _ _ hl) fun r hr => ?_ + have hr' : r.val < 384 := by + rw [hr]; unfold regs.FRAME_REGISTERS + exact regs_lt _ _ (by simp [layout.reg.FAULT_IP, layout.reg.SP_EL0, layout.reg.SPSR_EL1, layout.reg.X0, layout.reg.X1, layout.reg.X2, layout.reg.X3, layout.reg.X4, layout.reg.X5, layout.reg.X6, layout.reg.X7, layout.reg.X8, layout.reg.X16, layout.reg.X17, layout.reg.X18, layout.reg.X29, layout.reg.X30]) _ (List.getElem_mem _) + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st src s1 _ hS) fun v _ => ?_ + refine WP.spec_bind (P0.regs.sanitise_for_tcb.p0 st s1 dest r v hS) fun v5 _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.dmr (Vc := Vc) (p := p) (q := q) (v := v5) h1.1 h0 h1.2.sym h1.2.vr hd hr') + fun s2 ⟨b2, d2⟩ => ?_ + step as ⟨j2, hj2⟩ + exact ⟨b2, h1.2.trans d2, by omega⟩ + · exact h + +set_option maxHeartbeats 1000000 in +theorem tcb.copy_registers_loop1.dmr {p q : U64} {s0 s : S} {dest src i : U64} (h0 : H 0#u64 = none) + (hd : dest ∈ H.tcbs) (h : (BK s) ∧ DMR st H Cs Vc p q s0 s) : + tcb.copy_registers_loop1 st s dest src i ⦃ s' => (BK s') ∧ DMR st H Cs Vc p q s0 s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold tcb.copy_registers_loop1 + apply loop.spec_decr_nat (measure := fun y => 19 - y.2.val) + (inv := fun y => (BK y.1) ∧ DMR st H Cs Vc p q s0 y.1) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + try dsimp only + unfold tcb.copy_registers_loop1.body + try dsimp only + split + swap + · exact (WP.spec_ok _).2 h1 + rename_i hj + have hj' : j.val < 19 := by simpa [tcb.N_FRAME, tcb.N_GP] using hj + simp only [lift, bind_ok] + have hl : (UScalar.cast .Usize j : Usize).val < regs.GP_REGISTERS.val.length := by + rw [regs.GP_REGISTERS.property]; rw [cast_usize_small (by omega)]; simp; omega + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec _ _ hl) fun r hr => ?_ + have hr' : r.val < 384 := by + rw [hr]; unfold regs.GP_REGISTERS + exact regs_lt _ _ (by simp [layout.reg.X9, layout.reg.X10, layout.reg.X11, layout.reg.X12, layout.reg.X13, layout.reg.X14, layout.reg.X15, layout.reg.X19, layout.reg.X20, layout.reg.X21, layout.reg.X22, layout.reg.X23, layout.reg.X24, layout.reg.X25, layout.reg.X26, layout.reg.X27, layout.reg.X28, layout.reg.TPIDR_EL0, layout.reg.TPIDRRO_EL0] + ) _ (List.getElem_mem _) + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st src s1 _ hS) fun v _ => ?_ + refine WP.spec_bind (P0.regs.sanitise_for_tcb.p0 st s1 dest r v hS) fun v5 _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.dmr (Vc := Vc) (p := p) (q := q) (v := v5) h1.1 h0 h1.2.sym h1.2.vr hd hr') + fun s2 ⟨b2, d2⟩ => ?_ + step as ⟨j2, hj2⟩ + exact ⟨b2, h1.2.trans d2, by omega⟩ + · exact h + +set_option maxHeartbeats 1000000 in +theorem tcb.copy_registers_loop2.dmr {p q : U64} {s0 s : S} {dest src i : U64} (h0 : H 0#u64 = none) + (hd : dest ∈ H.tcbs) (h : (BK s) ∧ DMR st H Cs Vc p q s0 s) : + tcb.copy_registers_loop2 st s dest src i ⦃ s' => (BK s') ∧ DMR st H Cs Vc p q s0 s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold tcb.copy_registers_loop2 + apply loop.spec_decr_nat (measure := fun y => 19 - y.2.val) + (inv := fun y => (BK y.1) ∧ DMR st H Cs Vc p q s0 y.1) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + try dsimp only + unfold tcb.copy_registers_loop2.body + try dsimp only + split + swap + · exact (WP.spec_ok _).2 h1 + rename_i hj + have hj' : j.val < 19 := by simpa [tcb.N_FRAME, tcb.N_GP] using hj + simp only [lift, bind_ok] + have hl : (UScalar.cast .Usize j : Usize).val < regs.GP_REGISTERS.val.length := by + rw [regs.GP_REGISTERS.property]; rw [cast_usize_small (by omega)]; simp; omega + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec _ _ hl) fun r hr => ?_ + have hr' : r.val < 384 := by + rw [hr]; unfold regs.GP_REGISTERS + exact regs_lt _ _ (by simp [layout.reg.X9, layout.reg.X10, layout.reg.X11, layout.reg.X12, layout.reg.X13, layout.reg.X14, layout.reg.X15, layout.reg.X19, layout.reg.X20, layout.reg.X21, layout.reg.X22, layout.reg.X23, layout.reg.X24, layout.reg.X25, layout.reg.X26, layout.reg.X27, layout.reg.X28, layout.reg.TPIDR_EL0, layout.reg.TPIDRRO_EL0] + ) _ (List.getElem_mem _) + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st src s1 _ hS) fun v _ => ?_ + refine WP.spec_bind (P0.regs.sanitise_for_tcb.p0 st s1 dest r v hS) fun v5 _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.dmr (Vc := Vc) (p := p) (q := q) (v := v5) h1.1 h0 h1.2.sym h1.2.vr hd hr') + fun s2 ⟨b2, d2⟩ => ?_ + step as ⟨j2, hj2⟩ + exact ⟨b2, h1.2.trans d2, by omega⟩ + · exact h + +/-- `copy_registers`' tail: `post_modify_registers` and the reschedule if `dest` is current. -/ +theorem tcb.copy_tail.dmr {s2 s5 : S} (a2 : A) {dest src : U64} (h0 : H 0#u64 = none) (b5 : BK s5) + (d5 : DMR st H Cs Vc dest src s2 s5) : + (do + let s6 ← tcb.post_modify_registers st s5 dest + let t ← sched.cur_thread st s6 + let b ← obj.Tcb.Insts.CoreCmpPartialEqTcb.eq dest t + if b then do + let s7 ← sched.reschedule_required st s6 + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s7, a2) + else ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s6, a2)) ⦃ r => (BK r.2.1) ∧ DMR st H Cs Vc dest src s2 r.2.1 ⦄ := by + unfold tcb.post_modify_registers + simp only [bind_ok] + refine WP.spec_bind (sched.cur_thread.spec s5) fun t1 _ => ?_ + simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] + split + · refine WP.spec_bind (resched.dm dest b5 h0 d5.sym d5.vr) fun s7 h7 => ?_ + exact (WP.spec_ok _).2 ⟨h7.1, d5.trans (DMV.toR (DMD.toV (DM.toDMD h7.2.2)))⟩ + · exact (WP.spec_ok _).2 ⟨b5, d5⟩ + +set_option maxHeartbeats 4000000 in +/-- **`copy_registers` after the caller's restart is one `DMR dest src` step** (module docstring). -/ +theorem tcb.copy_registers.dmr (hA : P0.ArchTotal ar) {s0 s2 : S} {a : A} {dest src flags : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R2 : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s2) + (R : RsR st H Cs OS ia ie H.replies H.ntfns Ac extra slot s0 s2) (hd : dest ∈ H.tcbs) (hsrc : src ∈ H.tcbs) : + tcb.copy_registers st ar s2 a dest src flags ⦃ r => (BK r.2.1) ∧ DMR st H Cs Vc dest src s2 r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + have h0 : H 0#u64 = none := R.sys.ly.h0 + unfold tcb.copy_registers + simp only [lift, bind_ok] + refine WP.spec_bind (Pₘ := fun r : S × A => (BK r.1) ∧ DMR st H Cs Vc dest src s2 r.1) ?_ ?_ + · split + · refine WP.spec_mono (sched.suspend.dmr a src R.blk hsrc h0 R.sys.vr R.sym (R.na src hsrc) + (fun hnz => (R2.jv.2.run src hsrc).resolve_left hnz) hW hsrc) ?_ + rintro ⟨s3, a3⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨b3, d3, -, -⟩ := hh + exact ⟨b3, ⟨d3.w, fun x _ hq hl => d3.lv x hq hq hl, d3.idle, d3.isc, d3.vr, d3.sym⟩⟩ + · exact (WP.spec_ok _).2 ⟨R.blk, DMR.refl' dest src R.sys.vr R.sym⟩ + rintro ⟨s3, a1⟩ ⟨b3, d3⟩ + try simp only [uncurry_apply_pair] + refine WP.spec_bind (Pₘ := fun r : S × A => (BK r.1) ∧ DMR st H Cs Vc dest src s2 r.1) ?_ ?_ + · split + · refine WP.spec_mono (sched.restart.dm hA a1 dest b3 hd h0 d3.vr d3.sym) ?_ + rintro ⟨s4, a4⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨b4, -, d4⟩ := hh + exact ⟨b4, d3.trans (DMV.toR (DMD.toV (DM.toDMD d4)))⟩ + · exact (WP.spec_ok _).2 ⟨b3, d3⟩ + rintro ⟨s4, a2⟩ ⟨b4, d4⟩ + try simp only [uncurry_apply_pair] + split + · refine WP.spec_bind (tcb.copy_registers_loop0.dmr h0 hd ⟨b4, d4⟩) fun s5 ⟨b5, d5⟩ => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st dest s5 _ hS) fun pc _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.dmr (Vc := Vc) (p := dest) (q := src) (v := pc) b5 h0 d5.sym d5.vr hd + (by simp [layout.reg.NEXT_IP])) fun s6 ⟨b6, d6⟩ => ?_ + have d6' := d5.trans d6 + split + · refine WP.spec_bind (tcb.copy_registers_loop1.dmr h0 hd ⟨b6, d6'⟩) fun s7 ⟨b7, d7⟩ => ?_ + exact tcb.copy_tail.dmr a2 h0 b7 d7 + · exact tcb.copy_tail.dmr a2 h0 b6 d6' + · split + · refine WP.spec_bind (tcb.copy_registers_loop2.dmr h0 hd ⟨b4, d4⟩) fun s5 ⟨b5, d5⟩ => ?_ + exact tcb.copy_tail.dmr a2 h0 b5 d5 + · exact tcb.copy_tail.dmr a2 h0 b4 d4 + +set_option maxHeartbeats 4000000 in +/-- **CopyRegisters after the target's stall** (module docstring): the `*_armS` post. -/ +theorem tcb.decode_copy_registers.armSAt (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t len buf : U64} + {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_copy_registers st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + have q := D.bxi.1.choose_spec.choose_spec + have E1 : ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 ∧ ArmVsK st H OS Vc s s1 ∧ + OSKeep st OS s s1 := + (fun h => ⟨h.1, h.2, ArmVsK.ofDFI I D P B d1, ds1.1⟩) (ArmQIAt.ofStall I h1 d1 ds1 vk1 + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)) + unfold tcb.decode_copy_registers + refine WP.spec_bind (tcb.extra_with_length.mem _ 1#u64) ?_ + rintro r ⟨-, hx⟩ + rcases r with x | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 E1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨hxm, hx0⟩ := hx x rfl + have hxO : x ∈ OS := P.ext x hxm hx0 + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun flags _ => ?_ + refine WP.spec_bind (Pₘ := fun r : core.result.Result obj.Tcb error.Exc => + ∀ p, r = .Ok p → p ∈ H.tcbs ∧ capA st s1 x = .Thread p) ?_ ?_ + · unfold tcb.thread_arg + refine WP.spec_bind (WP.spec_and (D.extra s1 h1.node x hxm hx0) + (show obj.Slot.cap st x s1 ⦃ c => c = capA st s1 x ⦄ by rw [capA_eq]; exact (WP.spec_ok _).2 rfl)) + fun c ⟨hc, ec⟩ => ?_ + have H1 : ∀ p, c = .Thread p → p ∈ H.tcbs ∧ capA st s1 x = .Thread p := + fun p e => ⟨hc.2.1 p e, ec.symm.trans e⟩ + clear hc ec + cases c + all_goals first | (simp [error.invalid_cap, WP.spec_ok]; done) | skip + exact (WP.spec_ok _).2 fun p e => by cases e; exact H1 _ rfl + rintro r hr + rcases r with src | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 E1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨hsrc, hcx⟩ := hr src rfl + refine WP.spec_bind (WP.spec_and (Stalled.stallD hA (y := src) h1 d1) + (smp.remote_tcb_stall.ds hA I.del.os I.del.vc hW (Stalled.cur0 D h1) a1 src)) ?_ + rintro ⟨s1', a1'⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨⟨h1', d1'⟩, ds2⟩ := hh + try simp only [uncurry_apply_pair] + have ds1' : DS st H.tcbs OS Vc s s1' := ds1.trans ds2 + have vk1' : VsKeep st (L.ksb s) Pt s s1' := vsk_node I.del.vr q h1'.node + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1' d1' ds1' vk1') + (tcb.restart_caller.armVsK I D P B h1' d1' ds1')) ?_ + rintro s2 ⟨⟨⟨RS2, R2⟩, Q2, Z2⟩, K2⟩ + have hcs : obj.Slot.cap st x s = ok (.Thread src) := by + rw [capA_eq, ← ds1.1.capA hxO, hcx] + have hnS := namedT_keep hxO hcs hsrc K2.2 + refine WP.spec_mono (tcb.copy_registers.dmr (flags := flags) (a := a1') hA I R2 RS2 ht hsrc) ?_ + rintro ⟨r3, s3, a3⟩ ⟨b3, d3⟩ + have hS3 := SysL.dfMDR I.del.heap I.del.os I.del.vc (fun b hb => (R2.jv.2.w hb).2.1) RS2.blk I.del.sca + (RS2.namedT hcap ht) hnS R2.sys d3 + have A3 := ArmQIAt.ofSusW I R2 hks P.core0 RS2.blk d3.w hS3 b3 + have vk := (ArmVsK.ofSusW I R2 hks P.core0 RS2.blk d3.w).2 + exact (fun h => ⟨h.1, h.2, ArmVsK.trans K2.1 K2.2 vk.1, OSKeep.trans' K2.2 vk.2⟩) + (ArmQIAt.transZ (ArmQIAt.ofDelR R2 Q2 Z2.1.toVs) Z2 A3 vk) + +local macro "lbl_neC" : tactic => `(tactic| exact lbl_ne_of_val (by + simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, + fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetEPTRoot, + core.num.U64.MAX, U64.rMax])) + +set_option maxHeartbeats 2000000 in +/-- **TCB CopyRegisters** at `tcb.decode` (the `*_armS` post). -/ +theorem tcb.decode.copyRegsSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (hl : lbl = fl4_abi.label.TCBCopyRegisters) : + tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + iterate 5 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · lbl_neC + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + exact tcb.decode_copy_registers.armSAt hA I D P B Y hks hcap h1 d1 ds1 vk1 + +/-- **TCB CopyRegisters keeps every capability** (the Thread arm of `decode_invocation`, `*_armS` shape). -/ +theorem syscall.decode_invocation.copyRegs_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBCopyRegisters) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := + syscall.decode_invocation.tcbG + (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x) + ((fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s))) + a len blk call don fp buf + fun _ _ e => tcb.decode.copyRegsSAt hA I D P B Y hks hcap (e.trans hl) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCDm2.lean b/proofs/Fl4ProofsA64/P1/S1aCDm2.lean new file mode 100644 index 000000000..19389efbc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCDm2.lean @@ -0,0 +1,60 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1): **a liveness-dropping step with an exempt set of objects**. + +MdbDfM's `DM p` lets one object become live; a step that binds two objects needs both exempt. `SysL.dfE` is +`SysL.dfMDO` with the exempt set `E`: every object of `E` is named by an `OS` slot at the step's start. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCKeep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Ac : Set U64} {ia ie : Nat} + +/-- **A step that lets only the objects of `E` become live** (MdbDfM's `DMD` with a set for `p`). -/ +structure DME (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs : Set U64) (E : U64 → Prop) (s s' : S) : + Prop where + w : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' + lv : ∀ q, ¬ E q → LiveQ st H Cs s' q → LiveQ st H Cs s q + idle : L.idleW s' = L.idleW s + isc : L.mem s' (scA (L.idleW s')) = L.mem s (scA (L.idleW s)) + vr : ValidReplies st H s' + sym : SymL st H Cs s' + +set_option maxHeartbeats 1000000 in +/-- **A `DME E` step keeps `SysL ∧ SymL`** when every object of `E` is named. -/ +theorem SysL.dfE {Xq : Set U64} {E : U64 → Prop} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) + (hB : BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s) + (hSA : ScApart H.scs H.scBits OS) (hp : ∀ q k, E q → H q = some k → ∃ x ∈ OS, NamesA (capA st s x) q k) + (B : SysL st H Cs OS ia ie s) (d : DME st H Cs E s s') : + SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' := by + have h := hB + obtain ⟨Q, R, q⟩ := h.1 + have hSg := h.2.2.2.2 + have k : OSKeep st OS s s' := + OSKeep.of_kwd7 hO q hSg.sub hSA (fun _ he => he) (K8.FootD.to7 d.w) + obtain ⟨⟨⟨hS, hR, hV, hZ, hC⟩, hz, hK⟩, hfr, hcz, hur⟩ := B.sys + have u := UBm.keepO k + have hoff := HW.off (Vc := ∅) (Ub := ∅) hH hV hK q + (fun b hb => by obtain ⟨v, hv, -⟩ := hb; exact absurd hv (Set.notMem_empty v)) + (fun b hb => absurd hb (Set.notMem_empty b)) + have sys' : SysZ st H Cs OS s' := ⟨⟨⟨MdbST.keepO hO hS k, UtRev.keep hR k, ValidUntypedA.keepO hV k, + UtZeroA.writes hZ d.w (fun y0 hy0 p b i hc w hw => hoff w (hw.elim kw8_hw dbgw_hw) y0 hy0 p b i hc) u, + CoverA.keepO hC k d.w.1⟩, ZombiesFinal.recap hz fun _ hy => Or.inl (k.capA hy), KsOffA.of_ub hK d.w.1 u⟩, + FrameOK.keepO hfr k, CoverZ.keepO hcz k d.w.1, UtRV.keepO hur k⟩ + refine ⟨⟨sys', LiveNamed.transfer B.ln (fun q k' hq hl _ => ?_) (NamesKept.keepO k), d.vr, + B.ly.of_ub d.w.1 d.idle d.isc u, B.cn.keepO k, + fun x hx hb => by rw [k.capA hx]; exact B.bh x hx hb, (B.ci.keepO k).idleMv d.idle d.isc, + B.sc.keepO k, CtOff.ks d.w.1 (CapInv.keepO B.ct k), FrOff.ks d.w.1 (CapInv.keepO B.fo k), + fun x hx hb => by rw [k.capA hx]; exact B.ep x hx hb, B.ipc.keep (IbK.of_footDX h d.w)⟩, d.sym⟩ + by_cases e : E q + · obtain ⟨x, hx, hn⟩ := hp q k' e hq + exact Or.inr ⟨x, hx, by rw [k.capA hx]; exact hn⟩ + · exact Or.inl ⟨hq, d.lv q e hl⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCEnt.lean b/proofs/Fl4ProofsA64/P1/S1aCEnt.lean new file mode 100644 index 000000000..67518a3fb --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCEnt.lean @@ -0,0 +1,191 @@ +/- +P1 (aarch64, A64-P1 completion, Stage 2 D11, Architect rulings of 06:43Z / 06:45Z): **the entry facts after a decode +arm** (`S1aStepEnt`, a pure-P1 sibling of `S1aStepR2K`; P2's `EntryInvA` and P3's `SysInvA` spelled in P1 terms). + +* **`S1aStepEnt H Cs OS U ia ie s'`**: at the decode's own heap `H` and slot set `OS`: `SysL`, `HeapOK H`, `BXI` for + some `Ac'`, `OSOK`, `UserOK U` (the entry's user words, kept), `VsTy` over some `Pp' Tb' Lv'`, and the state block's + `ks::SIZE` width (`A64Layout.ksw`). These are the fields of `EntryInvA` and `SysInvA.sysl`. +* **`VsTyR.toVsTy`**: the narrowed Stage-1 typing is the full typing of the reachable tables (`VsRt`: `VsReach`'s + `root0` / `root2` / `step` close the set under `pool` and `desc`); **`S1aStepR2K.vsTy`**: so every `S1aStepR2K` + state has a `VsTy` (`S1aR2Core.stage1`). +* **`DecArmS1aEnt`**: the arms of `DecArmS1aAll` that keep the heap: `DecArmQH`, `DecArmQZ2`, ASIDPool Assign and + `DecArmS1aC`. **`syscall.decode_invocation.fixHeap`**: on them, `SysL` at `H` / `OS`, `BlkOK` and the state + block kept (each arm's `ArmQIAt ∧ TabKeepOrZero`, or `AsgPost`). +* **`syscall.decode_invocation.s1aStepEntAll`**: `s1aStepR2All`'s hypotheses and post, and `S1aStepEnt` (sibling; + `s1aStepR2K` / `s1aStepR2All` unchanged). + +Not covered (ruling (A) of 06:45Z): Untyped Retype and ASIDControl MakePool, the arms that grow the heap. P1's +`UserOK` leaves the user words an arbitrary set disjoint from the heap objects (`OutsideObjs`, `∉ Ω`, off the +endpoints); no fact ties them to frame caps (`DelIn.fu` / `FrUb` says the frames' words are in `Ub`, not that `U`'s +words are frame words), so `UserOK` over the grown heap does not follow (the gap S1aRetype records). + +Named premises: those of `s1aStepR2All`. No new premise. +-/ +import Fl4ProofsA64.P1.S1aCReplyErr +import Fl4ProofsA64.P1.S1aCAll + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +variable (st) in +/-- **The entry facts after a step** (module docstring). -/ +def S1aStepEnt (H : Heap) (Cs OS U : Set U64) (ia ie : Nat) (s : S) : Prop := + SysL st H Cs OS ia ie s ∧ HeapOK H ∧ + (∃ Ac', BXI st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s) ∧ + OSOK H.tcbs H.omega H.frame OS ∧ UserOK st H.tcbs Cs H.omega H U s ∧ + (∃ (Pp' Tb' : Set U64) (Lv' : U64 → Nat), VsTy st (L.ksb s) Pp' Tb' Lv' s) ∧ + (L.ksb s).val + 788736 ≤ 2 ^ 64 + +/-- **The narrowed Stage-1 typing is the full typing of the reachable tables.** -/ +theorem VsTyR.toVsTy {kb : U64} {Pp' Hr' Tb' : Set U64} {Lv' : U64 → Nat} {s : S} + (h : VsTyR st kb Pp' Hr' Tb' Lv' s) : VsTy st kb Pp' (VsRt st Pp' Hr' Tb' Lv' s) Lv' s := + ⟨h.tbl, fun p hp o ho h8 h0 => + ⟨fun e => ⟨⟨((h.pool p hp o ho h8 h0).1 e).1, VsReach.root0 hp ho h8 h0 e⟩, ((h.pool p hp o ho h8 h0).1 e).2⟩, + fun e => ⟨⟨((h.pool p hp o ho h8 h0).2 e).1, VsReach.root2 hp ho h8 e⟩, ((h.pool p hp o ho h8 h0).2 e).2⟩⟩, + fun p hp hl o ho h8 e => + ⟨⟨(h.desc p hp.1 hp.2 hl o ho h8 e).1, VsReach.step hp.2 hl ho h8 e⟩, (h.desc p hp.1 hp.2 hl o ho h8 e).2⟩⟩ + +/-- **Every `S1aStepR2K` state has a Stage-1 typing** (`S1aR2Core.stage1`, `VsTyR.toVsTy`). -/ +theorem S1aStepR2K.vsTy {s : S} (h : S1aStepR2K st Cs Ub Kt KLv ia ie n s) : + ∃ (Pp' Tb' : Set U64) (Lv' : U64 → Nat), VsTy st (L.ksb s) Pp' Tb' Lv' s := by + obtain ⟨_, _, _, _, _, _, _, ⟨_, _, _, _, _, _, _, R⟩, _⟩ := h + exact ⟨_, _, _, R.core.stage1.toVsTy⟩ + +/-- **The decode arms that keep the heap** (module docstring). -/ +def DecArmS1aEnt (cap : capability.Cap) (lbl : U64) : Prop := + DecArmQH cap lbl ∨ DecArmQZ2 cap lbl ∨ + (∃ pp ab, cap = .AsidPool pp ab ∧ lbl = fl4_abi.label.ARMASIDPoolAssign) ∨ DecArmS1aC cap lbl + +theorem DecArmS1aEnt.all {cap : capability.Cap} {lbl : U64} (h : DecArmS1aEnt cap lbl) : DecArmS1aAll cap lbl := by + rcases h with h | h | h | h + · exact Or.inl (Or.inl h) + · exact Or.inl (Or.inr (Or.inl h)) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inl h)))) + · exact Or.inr h + +set_option maxHeartbeats 4000000 in +/-- **On the heap-keeping arms: `SysL` at `H` / `OS`, `BlkOK`, the state block kept** (module docstring). -/ +theorem syscall.decode_invocation.fixHeap (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (C : S1aArmCol st H Cs OS Vc Ub s) (a : A) + {lbl : U64} (hc : DecArmS1aEnt cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (hScC : ∀ cpu, cap = .SchedControl cpu → cpu ∈ Cs ∧ + ∀ x ∈ extra.val, x ≠ 0#u64 → ∀ p sz, capA st s x = .SchedContext p sz → sz.val = H.scBits p) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (Df : DevFrAl st OS s) (KC : S1aHiK st OS Kt KLv s) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + SysL st H Cs OS ia ie s' ∧ + (∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') ∧ + L.ksb s' = L.ksb s ⦄ := by + have hSA : ScApart H.scs H.scBits OS := I.del.sca + have keepF : ∀ {m : Result ((core.result.Result Unit error.Exc) × S × A)}, + m ⦃ _ s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄ → + m ⦃ _ s' _ => SysL st H Cs OS ia ie s' ∧ + (∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') ∧ + L.ksb s' = L.ksb s ⦄ := fun t => + WP.spec_mono t fun r d => by + obtain ⟨_, _, _⟩ := r + exact ⟨d.1.1, d.1.2.2.1, d.2.1.1⟩ + have QH : DecArmQH cap lbl → syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + SysL st H Cs OS ia ie s' ∧ + (∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') ∧ + L.ksb s' = L.ksb s ⦄ := fun hq => by + replace R := R.relabel I.del.heap KC + have W := HiDelTyR.ofR2 R + replace R := R.activePools + have J := I.forHiDelR hPl W + have z := W.finKZ (hPl := hPl) I + obtain ⟨pools, tables, level, _, stage2, depth, width, hp, ht, he, ty, no3, hi, ty2, place2, heap2⟩ := + R.core.hvs W.pools W.tables W.granules W.stage2 + have dec := S1aDecHyps.of mcp cs fh + ⟨pools, tables, level, Gran stage2 width, s2gRe stage2 depth, hp, ht, he, ty, no3, hi, + S2DecTy.ofTeH P.heap ty2 place2 heap2⟩ ⟨R.pageTables, R.footprint, R.highHeaders⟩ P B hks hcap Df + exact WP.spec_mono (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl J z hPI D P B Y hcap hks + a hq hIq hSC dec len blk call don fp buf) fun r d => by + obtain ⟨_, _, _⟩ := r + exact ⟨d.1.1, d.1.2.2.1, d.2.1.1⟩ + rcases hc with hq | hc | ⟨pp, ab, rfl, hl⟩ | hc + · exact QH hq + · exact QH (Or.inl (hc.imp id Or.inl)) + · subst lbl + exact WP.spec_mono (syscall.decode_invocation.assignLW D P B Y C.case.po a rfl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact ⟨d.1.1, ⟨Ac, d.2.1⟩, d.2.2.ksb⟩ + · rcases hc with hr | ⟨t, rfl, hl⟩ | ⟨p, b, rfl, hl⟩ | ⟨t, rfl, hl | hl | hl | hl | hl | hl⟩ | ⟨hf, hl⟩ | + ⟨p, b, rfl, hl | hl⟩ | ⟨cpu, rfl⟩ | ⟨p, g, rfl⟩ + · refine WP.spec_mono (syscall.decode_invocation.rejected_eq hA hcap P.src B a hr len blk call don fp buf) + fun r e => ?_ + obtain ⟨_, s', _⟩ := r + have e' : s' = s := e + subst e' + exact ⟨B, ⟨Ac, D.bxi.blk⟩, rfl⟩ + · exact keepF (syscall.decode_invocation.unknownTcb_armS hA I D P B Y a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.unknownSc_armS hA I D P B Y a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.writeFpu_armS hA I D P B Y a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.setTimer_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.bindN_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.resume_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.writeRegs_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.copyRegs_armS hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.cbs_armS I D P B Y hks hSA hcap hf a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.scBind_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · exact keepF (syscall.decode_invocation.scYieldTo_armS hA I D P B Y hks hSA hcap a hl len blk call don fp buf) + · obtain ⟨hcpu, hsz⟩ := hScC cpu rfl + exact keepF (syscall.decode_invocation.schedControl_armS hA I D P B Y hks hcpu hsz a lbl len blk call don fp buf) + · exact WP.spec_mono (syscall.decode_invocation.reply_armS hA I D P B Y hks a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact ⟨d.1.1, d.1.2.2.1, d.2.1.1⟩ + +set_option maxHeartbeats 4000000 in +/-- **The S1a step and the entry facts over the heap-keeping arms** (module docstring): `s1aStepR2All`'s hypotheses; +its post and `S1aStepEnt` at the decode's `H` / `OS` and the entry's user words `U`. -/ +theorem syscall.decode_invocation.s1aStepEntAll (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (KT : KTab ar Kt KLv) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) (a : A) + {lbl : U64} (hc : DecArmS1aEnt cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (hScC : ∀ cpu, cap = .SchedControl cpu → cpu ∈ Cs ∧ + ∀ x ∈ extra.val, x ≠ 0#u64 → ∀ p sz, capA st s x = .SchedContext p sz → sz.val = H.scBits p) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (KC : S1aHiK st OS Kt KLv s) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie hPl.ipa s' ∧ S1aStepEnt st H Cs OS U ia ie s' ⦄ := + WP.spec_mono (WP.spec_and + (syscall.decode_invocation.s1aStepR2All hA hM hPl KT I hPI D P B Y hcap hks hfm hPN C Kc hal a hc.all hIq hSC + mcp cs fh hScC R sep Df KC len blk call don fp buf) + (syscall.decode_invocation.fixHeap hA hM hPl I hPI D P B Y hcap hks C a hc hIq hSC mcp cs fh hScC R Df KC + len blk call don fp buf)) fun r h => by + obtain ⟨_, s', _⟩ := r + obtain ⟨k, sl, ⟨Ac', bk⟩, ek⟩ := h + exact ⟨k, ⟨sl, I.del.heap, ⟨Ac', BlkOK.bxi bk⟩, I.del.os, D.user.ksb ek, k.vsTy, sl.ly.ksw⟩⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCFault.lean b/proofs/Fl4ProofsA64/P1/S1aCFault.lean new file mode 100644 index 000000000..d01653a58 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCFault.lean @@ -0,0 +1,156 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c3): **the faults** (frozen D4: one theorem per kernel function, from +per-state premises, with post `S1aStepR2K`). + +* **`faults.handle_fault.rpw`**: from S1aCReplyW's bundle `RpW s0 s`, the fault IPC to the thread's fault-handler + endpoint (S1aCReplyTo's `handle_timeout.rpw` with the fault slot and the thread's SC as donation), or, with no + endpoint handler, the thread made inactive (`set_thread_state.dmdT`, the thread named: live; QueueXferA's + `handle_fault.bxiA` inactive branch, `sts_all`). +* **`faults.handle_fault.s1a`**, **`faults.handle_timeout.s1a`**: the S1a step post (S1aCBudget's + `S1aStepR2K.ofRpPost`). + +Named premises: [P] `P0.ArchTotal`. Per-state facts: the faulting thread can block and is not inactive, the placement +`Pz`, [J] `RunVcpuInv` (as `handle_timeout.rpw`). +-/ +import Fl4ProofsA64.P1.S1aCFinish + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 8000000 in +/-- **The fault IPC or the faulting thread's stop** (module docstring). -/ +theorem faults.handle_fault.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s0 s : S} (a : A) (i : U64) (f : error.Fault) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (R : RpW st H Cs OS Vc ia ie Ac s0 s) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s0)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s0) Pt') + (hc : CanBlock st H.tcbs Ac s i) (hrun : L.mem s (stA i) ≠ sched.TS_INACTIVE) + (hRV : RunVcpuInv st H.tcbs s) : + faults.handle_fault st ar s a i f ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have ht := hc.mem + have h0 := R.sys.ly.h0 + have q0 := R.blk.1.choose_spec.choose_spec + have hT := q0.tcbs + have P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot := + SysPlace.ofXfer Pz R.sys.sys.stz.1.1.mdbS R.xs R.ksb + have hx : slotIdx i layout.tcb.SLOT_FAULT_HANDLER ∈ OS := + hTS i ht _ (by simp [layout.tcb.SLOT_FAULT_HANDLER]) + have hs : obj.Tcb.slot i layout.tcb.SLOT_FAULT_HANDLER = ok (slotIdx i layout.tcb.SLOT_FAULT_HANDLER) := by + simp [obj.Tcb.slot, lift, slotIdx, layout.cte.SIZE] + have hty := (P.ty _ hx).capTy + unfold faults.handle_fault + rw [hs, bind_ok, capA_eq, bind_ok] + step with obj.Tcb.sc.spec as ⟨sci, esci⟩ + unfold faults.send_fault_ipc + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => RpPost st H Cs OS Vc ia ie Ac s0 r.2.1 ∧ + (r.1 = false → r.2.1 = s)) ?_ ?_ + swap + · rintro ⟨x, s2, a2⟩ ⟨h2, e2⟩ + simp only [uncurry_apply_pair] + split + · exact (WP.spec_ok _).2 h2 + rename_i hb + have e2' : s2 = s := e2 (by simpa using hb) + subst e2' + obtain ⟨⟨Q3, R3, q3⟩, hB3, hX3, hS3, hSg3⟩ := id R.blk + refine WP.spec_bind (WP.spec_and (sts_all s2 i _ Q3 R3 q3 hB3 hX3 hS3 hSg3 ht not_blocked_inactive inactive_ne + (Or.inr hc.nb) (hX3.noref (q3.tcbs i ht) hc.nrp (fun e => hc.nb (Or.inr (Or.inl e)))) + ⟨fun c hc' p hp hm => absurd hm (q3.notQ ht hc.nq hc' hp), fun c hc' hm => absurd hm (q3.notR ht hc.nr hc'), + fun e => absurd e hc.na⟩) + (sched.set_thread_state.dmdT i sched.TS_INACTIVE R.blk h0 R.sym R.sys.vr ht hc.nrp)) ?_ + rintro s4 ⟨⟨h4, hB4, hX4, hS4, hSg4, -, -⟩, d4⟩ + have b4 : BK s4 := ⟨⟨Q3, R3, h4.congrX empty_congr⟩, hB4, hX4, hS4, hSg4⟩ + refine (WP.spec_ok _).2 (R.dmdK Pz.heap Pz.os hSA Pz.core0 hvr hks (fun k hk hia => ?_) d4 b4).1.post + have e : H i = some .tcb := ht + rw [e] at hk; cases hk + exact R.sys.ln _ .tcb ht (LiveQ.tcb ht (Or.inl hrun)) hia + split + all_goals first | exact (WP.spec_ok _).2 ⟨R.post, fun _ => rfl⟩ | skip + rename_i p b x y g gr hcx + have hpH : H p = some .ep := by + have := hty.1.1.1 p b x y g gr + rw [hcx] at this; exact this rfl + refine WP.spec_bind (spec_eq' (WP.spec_and (WP.spec_and (WP.spec_and + (faults.set_fault.blk (U := ∅) s i f R.blk ht (fun b hb => absurd hb (Set.notMem_empty b)) hc) + (faults.set_fault.rv s i f hT ht)) (faults.set_fault.fw s i f hT ht)) (faults.set_fault.sc s i f hT ht))) ?_ + rintro s1 ⟨-, ⟨⟨⟨b1, -, hc1⟩, rv1⟩, w1⟩, sc1⟩ + obtain ⟨R1, k1⟩ := R.dmdK (p := 0#u64) Pz.heap Pz.os hSA Pz.core0 hvr hks + (fun k hk => by rw [h0] at hk; cases hk) (DMD.ofFld 0#u64 R.blk h0 R.sym R.sys.vr w1) b1 + have P1 : SysPlace st H Cs H.frame H.replies H.ntfns OS s1 extra slot := + SysPlace.ofXfer Pz R1.sys.sys.stz.1.1.mdbS R1.xs R1.ksb + have hp : ∀ k, H p = some k → ∃ z ∈ OS, NamesA (capA st s1 z) p k := fun k hk => by + rw [hpH] at hk; cases hk + exact ⟨_, hx, by rw [k1.capA hx, hcx]; exact names_ep⟩ + have hr1 : L.mem s1 (stA i) ≠ sched.TS_INACTIVE := by rw [(rv1 i ht).1]; exact hrun + have hRV1 : RunVcpuInv st H.tcbs s1 := hRV.rvSt rv1 + have hks1 : HeapKsOff H (L.ksb s1) := by rw [R1.ksb]; exact hks + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s1) Pt' := by rw [R1.ksb]; exact hvr + have hdon : (sci != 0#u64) = true → L.mem s1 (scA i) ≠ 0#u64 := fun e => by + rw [sc1, ← esci]; simpa using e + by_cases hst1 : L.epState s1 p = 2#u64 + · refine WP.spec_bind (endpoint.send_ipc.recvS (Vc := Vc) (Vc' := Vc') (Ub := Ub') (Pt := Pt') hA a true false b g + gr (sci != 0#u64) i p P1 b1 hSA hTS R1.sys R1.sym hpH hst1 hp hc1 hr1 hdon hRV1) fun r hh => ?_ + obtain ⟨s2, a2⟩ := r + simp only [WP.uncurry'_pair] at hh + have carry := hh.2.2.2 hks1 hvr1 + exact (WP.spec_ok _).2 ⟨⟨hh.1, hh.2.1, hh.2.2.1, R1.xc.trans carry.1, R1.xv.trans carry.2.1, s1, R1.xs, + R1.xv, carry.2.2, carry.2.1⟩, fun e => by cases e⟩ + · obtain ⟨⟨Q2, R2, q2⟩, -⟩ := id b1 + have hst0 : L.epState s1 p = 0#u64 ∨ L.epState s1 p = 1#u64 := by + rcases ep_state3 q2 hpH with e0 | e0 | e0 + · exact Or.inl e0 + · exact Or.inr e0 + · exact absurd e0 hst1 + refine WP.spec_bind (endpoint.send_ipc.blockS (Vc := Vc) (Vc' := Vc') (Ub := Ub') (Pt := Pt') a true false b g gr + (sci != 0#u64) i p P1 b1 hSA R1.sys R1.sym hpH hst0 hp (fun _ => hc1) hr1) fun r hh => ?_ + obtain ⟨s2, a2⟩ := r + simp only [WP.uncurry'_pair] at hh + have carry := hh.2.2.2 hks1 hvr1 + exact (WP.spec_ok _).2 ⟨⟨hh.1, hh.2.1, hh.2.2.1, R1.xc.trans carry.1, R1.xv.trans carry.2.1, s1, R1.xs, + R1.xv, Or.inl fun z hz => carry.2.2.capA hz, carry.2.1⟩, fun e => by cases e⟩ + +section top +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} + {n : U64} + +/-- **`handle_fault` keeps the S1a step post** (`handle_fault.rpw`, `S1aStepR2K.ofRpPost`). -/ +theorem faults.handle_fault.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + {s : S} (a : A) (i : U64) (f : error.Fault) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hc : CanBlock st H.tcbs Ac s i) (hrun : L.mem s (stA i) ≠ sched.TS_INACTIVE) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + faults.handle_fault st ar s a i f ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (faults.handle_fault.rpw hA a i f Pz (RpW.start B Y h) I.del.sca I.ts hks I.del.vr hc hrun hRV) + fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact S1aStepR2K.ofRpPost I P C Df R sep KC + +/-- **`handle_timeout` keeps the S1a step post** (S1aCReplyTo's `handle_timeout.rpw`, `S1aStepR2K.ofRpPost`). -/ +theorem faults.handle_timeout.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + {s : S} (a : A) (i : U64) (f : error.Fault) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hc : CanBlock st H.tcbs Ac s i) (hrun : L.mem s (stA i) ≠ sched.TS_INACTIVE) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + faults.handle_timeout st ar s a i f ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (faults.handle_timeout.rpw hA a i f Pz (RpW.start B Y h) I.del.sca I.ts hks I.del.vr hc hrun hRV) + fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact S1aStepR2K.ofRpPost I P C Df R sep KC + +end top + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCFinish.lean b/proofs/Fl4ProofsA64/P1/S1aCFinish.lean new file mode 100644 index 000000000..d41d51cd2 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCFinish.lean @@ -0,0 +1,360 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c2 part 3): **`vcpu::check` of the current thread keeps the S1a step +post** (frozen D4: one theorem per kernel function, from per-state premises). + +* **`vcpu.check.rq0`**: MdbRunQ's `vcpu.check.rq` for a thread with no run VCPU (`RUN_VCPU` 0: `FAULT_IP := NEXT_IP`, + state `RUNNING`), its branch copied; no `vc ∈ Vc` needed. +* **`vcpu.check.s1a`**: off `TS_RUNNING_VM` nothing is written; on it the run's carry `RQ` (`rq0` / `rq`, the run + VCPU in `Vc` by `DelIn.vty.run`, the run frame in `Uq ∩ FrBw ∩ FrCw` by MdbRunQ's `runBuf_of`) is closed as in + MdbRunQ's `decode_run.runS` (`DMU.ofTc`, `SysL.dfMDU`, `ArmQIAt.ofRunW0`, `RunW.osk`), then S1aCAll's + `S1aStepR2K.ofKeep'`. +* **`sched.activate_thread.sw`** / **`.s1a`**: `complete_yield_to` (a `DMD sc` step, the SC named: live as a thread's + `YIELD_TO`), the restarting thread's `NEXT_IP` register (`DMD.ofFld`) and `TS_RUNNING` (`set_thread_state.dmdT`). +* **`vcpu.check.swS`**: `vcpu.check.s1a` at the end of a walk `SW s0 s` (`VcTy` at `s` by the walk's `VKeep`, `FrUb` + by its `XV`; `runBuf_of'`, MdbRunQ's `runBuf_of` from its parts). +* **`syscall.finish.s1a`**: `schedule.sw` (with QueueSchedule's `schedule.inv` for the action `0` and the current SC), + `activate_thread.sw` (with QueueKeeps's `activate_thread.entry`), `vcpu.check.swS`. Per-state fact: [J] + `RunVcpuInv`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5; `syscall.finish.s1a`). Per-state facts (the `Cur0` parts at the state): the current SC is the current +thread's, the action names no thread, the current thread is not blocked. The [P] `RunBuf` of VcpuCheckInv is not +needed: `runBuf_of` derives it from `DelIn.fu` (`FrUb`). +-/ +import Fl4ProofsA64.P1.S1aCSched +import Fl4ProofsA64.P1.MdbRunQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "C0" s0:max s:max => Cur0 st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s0 s + +set_option maxHeartbeats 4000000 in +/-- **`vcpu::check` of a thread with no run VCPU, with the run's carry** (module docstring). -/ +theorem vcpu.check.rq0 (hA : P0.ArchTotal ar) {U : Set U64} {s x : S} {ct : U64} (h : C0 s x) + (d : RQ st H Cs Vc U ct s x) (hy : ct ∈ H.tcbs) (hv0' : L.mem x (runVcpuA ct) = 0#u64) + (hW : ∀ v ∈ Vc, VcWords H.omega H.frame v) (hUs : ∀ b ∈ U, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b) + (a : A) : + vcpu.check st ar x a ct ⦃ s' _ => (C0 s s') ∧ RQ st H Cs Vc U ct s s' ⦄ := by + have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => by + obtain ⟨v, hv, o, ho, h8, rfl⟩ := hb + exact ⟨(hW v hv o ho h8).2.1, (hW v hv o ho h8).2.2⟩ + have hUx : ∀ {x1 : S}, RQ st H Cs Vc U ct s x1 → ∀ b ∈ U, UsrW st H.tcbs Cs H H.frame H.scs H.scBits x1 b := + fun d1 b hb => (hUs b hb).ksb d1.w.1 + obtain ⟨Ac1, hb1⟩ := h.bxi + obtain ⟨⟨Q, R, hq⟩, hB, hX, hS, hSg⟩ := hb1.blk + have hT := hq.tcbs + have hta := hT ct hy + have hN := hq.nodes _ hq.cur + have hct : L.curW x ∈ H.tcbs := hq.curT + unfold vcpu.check + step with obj.Tcb.state.spec as ⟨i, ei⟩ + split + · exact (WP.spec_ok _).2 (And.intro h d) + rename_i hvm0 + have hvm : L.mem x (stA ct) = sched.TS_RUNNING_VM := by + rw [← ei]; by_contra hne; exact hvm0 (bne_iff_ne.mpr hne) + rw [eq_of_spec_fd P0.Consts.layout.tcb.RUN_VCPU.spec] + simp only [lift, bind_ok, L.read_eq] + have hv0 : L.mem x (core.num.U64.wrapping_add ct 3672#u64) = 0#u64 := hv0' + rw [if_pos hv0] + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st _ x _ L.total) fun ip _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.regW x hta (by simp [layout.reg.FAULT_IP]) (WritesIn.refl _ _)) + fun s1 w1 => ?_ + obtain ⟨F1, -, S1⟩ := UbF.regs h hy w1 + have d1 := d.trans (RQ.ofV hb1.blk hy (hUx d) hWv (rnv_regs hy w1) F1.idle) + obtain ⟨_, _, _, q1⟩ := Cur0.q F1.cur + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.running_ub F1.cur hy (by rw [S1 ct hy]; exact hvm) + (F1.rv0 ct hy hv0)) (sts_fine s1 ct sched.TS_RUNNING (q1.nodes _ q1.cur) hta)) fun s2 hw2 => ?_ + obtain ⟨hh, w2⟩ := hw2 + obtain ⟨Ac2, hb2⟩ := F1.cur.bxi + have w2' : WritesIn st s1 s2 (RnV st H.tcbs Cs Vc U ct (L.ksb s1)) := rnv_sts q1.cur rfl w2 + exact (WP.spec_ok _).2 (And.intro hh.1.cur (d1.trans (RQ.ofV hb2.blk hy (hUx d1) hWv w2' hh.1.idle))) + +set_option maxHeartbeats 8000000 in +/-- **`vcpu::check` of the current thread keeps the S1a step post** (module docstring). -/ +theorem vcpu.check.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : ∀ y ∈ H.tcbs, L.actionW s ≠ y) (hnb : ¬ BlockedR (L.mem s (stA (L.curW s)))) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + vcpu.check st ar s a (L.curW s) ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have h0 := B.ly.h0 + have q := h.1.choose_spec.choose_spec + have hct : L.curW s ∈ H.tcbs := q.curT + have c0 : C0 s s := ⟨hcsc, Ac, BlkOK.bxi h, rfl, rfl, Or.inl rfl, hna, hnb, WritesIn.refl _ _⟩ + have hW' : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + let U0 : Set U64 := {b | b ∈ Uq ∧ FrBw H OS b ∧ FrCw st OS s b} + have hUs : ∀ b ∈ U0, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := fun b hb => I.vty.usr b hb.1 + have hUF : ∀ b ∈ U0, FrBw H OS b ∧ FrCw st OS s b := fun b hb => hb.2 + have hBuf : ∀ x', WritesIn st s x' (RnN st H Cs Vc U0 (L.curW s) (L.ksb s)) → RunBuf st U0 x' (L.curW s) := + fun x' w => runBuf_of I B (I.del.vc.bcov _ hct) + ((RunW.osk I h (w.mono fun b hb => rnn_runW hUF hct hb)).capA (I.del.vc.bcov _ hct)) + have fin : ∀ {x : S}, (C0 s x) → RQ st H Cs Vc U0 (L.curW s) s x → + L.mem s (stA (L.curW s)) = sched.TS_RUNNING_VM → S1aStepR2K st Cs Ub Kt KLv ia ie n x := fun {x} c d hvm => by + have f : WritesIn st s x (RunW st H Cs Vc OS s s) := d.w.mono fun b hb => rnn_runW hUF hct hb + have dm : DMU st H Cs Vc OS s (L.curW s) 0#u64 s x := + DMU.ofTc h h0 Y B.vr f d.lv d.ep (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_BLOCKED_ON_REPLY]) + have d0 : DMU st H Cs Vc OS s 0#u64 0#u64 s x := ⟨dm.w, fun z hp _ hl => by + by_cases hz : z = L.curW s + · subst hz; exact Or.inl ⟨hct, Or.inl (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_INACTIVE])⟩ + · exact dm.lv z hz hp hl, dm.idle, dm.isc, dm.vr, dm.sym⟩ + have hp0 : ∀ k, H 0#u64 = some k → ∃ y ∈ OS, NamesA (capA st s y) 0#u64 k := fun k hk => by + rw [h0] at hk; cases hk + have hS' := SysL.dfMDU I.del.heap I.del.os I.del.vc (fun b hb => (I.vty.w hb).2.1) h I.del.sca hp0 hp0 B d0 + obtain ⟨Ac', hb'⟩ := c.bxi + have A' := ArmQIAt.ofRunW0 I B hks hc0 h f hS' hb'.blk + exact S1aStepR2K.ofKeep' ⟨A'.1, A'.2.1.toDel, A'.2.2, RunW.osk I h f⟩ I.del.vr I.fu I.vcc C Kc Df R sep KC + by_cases hvm : L.mem s (stA (L.curW s)) = sched.TS_RUNNING_VM + · by_cases hv0 : L.mem s (runVcpuA (L.curW s)) = 0#u64 + · exact WP.spec_mono (vcpu.check.rq0 hA c0 (RQ.refl s) hct hv0 hW' hUs a) fun r hr => by + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + exact fin hr.1 hr.2 hvm + · have hvc : L.mem s (runVcpuA (L.curW s)) ∈ Vc := (I.vty.run _ hct).resolve_left hv0 + exact WP.spec_mono (vcpu.check.rq hA c0 (RQ.refl s) hct rfl hvc hW' hUs hBuf a) fun r hr => by + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + exact fin hr.1 hr.2 hvm + · unfold vcpu.check + step with obj.Tcb.state.spec as ⟨i, ei⟩ + rw [if_pos (by rw [ei]; exact bne_iff_ne.mpr hvm)] + simp only [WP.spec_ok, WP.uncurry'_pair] + exact S1aStepR2K.ofKeep' (S1aKeep.ofDMD (Vc' := Vc) (Ub := Uq) (Pt := Pt) (p := 0#u64) B Y h I.del.heap + I.del.os I.del.sca hc0 I.del.vr hks (fun k hk => by rw [h0] at hk; cases hk) (DMD.refl 0#u64 h h0 Y B.vr) h) + I.del.vr I.fu I.vcc C Kc Df R sep KC + +set_option maxHeartbeats 8000000 in +/-- **`activate_thread` keeps the walk bundle**: `complete_yield_to` (S1aCYieldTo's `complete_yield_to.dmS`, a `DMD sc` +step, the SC named: live as a thread's `YIELD_TO`), then for a restarting current thread its `NEXT_IP` register +(`DMD.ofFld`) and `TS_RUNNING` (`set_thread_state.dmdT`, the thread named: live). -/ +theorem sched.activate_thread.sw (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq : Set U64} {s0 s : S} (a : A) (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s0)) (W : SW st H Cs OS Vc ia ie Ac s0 s) : + sched.activate_thread st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ + (L.actionW s' = L.actionW s ∨ L.actionW s' = 1#u64) ⦄ := by + have h := W.1.blk + have h0 := W.1.sys.ly.h0 + have q := h.1.choose_spec.choose_spec + have hT := q.tcbs + have hct : L.curW s ∈ H.tcbs := q.curT + unfold sched.activate_thread + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e : ct = L.curW s := ect + subst e + step with obj.Tcb.yield_to.spec as ⟨i, ei⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => SW st H Cs OS Vc ia ie Ac s0 r.1 ∧ L.actionW r.1 = L.actionW s) ?_ ?_ + · split + · rename_i hi + have hy0 : L.mem s (yieldA (L.curW s)) ≠ 0#u64 := by rw [← ei]; simpa using hi + have hsc : L.mem s (yieldA (L.curW s)) ∈ H.scs := h.2.2.1.2.2.yt.2.1 _ hct hy0 + refine WP.spec_mono (schedcontext.complete_yield_to.dmS hA a _ _ h h0 W.1.sym W.1.sys.vr hct rfl hsc) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + exact ⟨W.dmd I hc0 hks (fun k hk hia => W.1.sys.ln _ k hk + (Or.inr (Or.inr (Or.inr (Or.inr ⟨hsc, Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, hct, rfl⟩))))⟩)))) hia) + hh.2.2.1 hh.1, hh.2.2.2.2.1.1⟩ + · exact (WP.spec_ok _).2 ⟨W, rfl⟩ + rintro ⟨s1, a1⟩ ⟨W1, ea1⟩ + try simp only [WP.uncurry'_pair] at W1 ea1 ⊢ + have h1 := W1.1.blk + step with obj.Tcb.state.spec as ⟨v, ev⟩ + split + · rename_i hv + step with obj.Tcb.reg.spec as ⟨pc, _⟩ + refine WP.spec_bind (obj.Tcb.set_reg.wrK s1 _ layout.reg.NEXT_IP pc (hT _ hct) + (by simp [layout.reg.NEXT_IP])) ?_ + rintro s2 ⟨K, hK, e2⟩ + subst e2 + have hK' : K.val < 3328 := by + have : layout.reg.NEXT_IP.val < 384 := by simp [layout.reg.NEXT_IP] + omega + obtain ⟨h2, -, n2⟩ := regW_all (K := K) (v := pc) h1 hct (by omega) hK' (by omega) + have d2 : DMD st H Cs 0#u64 s1 (L.wr s1 (wa (L.curW s) K) pc) := + DMD.ofFld 0#u64 h1 h0 W1.1.sym W1.1.sys.vr ((writesIn_wr (field_aligned (hT _ hct) (by omega) (by omega))).mono + fun b e => ⟨_, hct, K, by omega, by omega, by omega, by unfold LvO; omega, by omega, by omega, by omega, e⟩) + have W2 := W1.dmd0 I hc0 hks d2 h2 + have st2 : L.mem (L.wr s1 (wa (L.curW s) K) pc) (stA (L.curW s)) = sched.TS_RESTART := by + rw [stA_eq, L.mem_wr_ne (field_aligned (hT _ hct) (by omega) (by omega)) + (field_aligned (hT _ hct) (by simp) (by simp)) + (fun e => field_ne (hT _ hct) (hT _ hct) (by omega) (by simp) (fun _ => by simp; omega) + (UScalar.eq_of_val_eq e)), ← stA_eq, ← ev] + exact hv + obtain ⟨⟨Q2, R2, q2⟩, hB2, hX2, hS2, hSg2⟩ := id h2 + have hrun : Runnable sched.TS_RUNNING := Or.inl rfl + refine WP.spec_bind (WP.spec_and (sts_all _ _ _ Q2 R2 q2 hB2 hX2 hS2 hSg2 hct + (fun hb' => not_runnable_of_blocked hb' hrun) + ⟨runnable_ne_reply hrun, runnable_ne_recv hrun⟩ (Or.inr (by rw [st2]; exact not_blocked_restart)) + (hX2.noref (hT _ hct) (by rw [st2]; exact restart_ne.1) (by rw [st2]; exact restart_ne.2)) + ⟨fun _ _ _ _ _ => hrun, fun _ _ _ => hrun, fun _ => hrun⟩) + (sched.set_thread_state.dmdT (L.curW s) sched.TS_RUNNING h2 h0 W2.1.sym W2.1.sys.vr hct + (by rw [st2]; simp [sched.TS_RESTART, sched.TS_BLOCKED_ON_REPLY]))) ?_ + rintro s3 ⟨⟨h3, hB3, hX3, hS3, hSg3, -, k3⟩, d3⟩ + simp only [WP.spec_ok, WP.uncurry'_pair] + have b3 : BK s3 := ⟨⟨Q2, R2, h3.congrX empty_congr⟩, hB3, hX3, hS3, hSg3⟩ + refine ⟨W2.dmd I hc0 hks (fun k hk hia => ?_) d3 b3, ?_⟩ + · have e : H (L.curW s) = some .tcb := hct + rw [e] at hk; cases hk + exact W2.1.sys.ln _ .tcb hct (LiveQ.tcb hct (Or.inl (by rw [st2]; simp [sched.TS_RESTART, sched.TS_INACTIVE]))) + hia + · rcases k3.act with e | e + · exact Or.inl (e.trans (n2.1.trans ea1)) + · exact Or.inr e + · exact (WP.spec_ok _).2 ⟨W1, Or.inl ea1⟩ + +/-- **`activate_thread` keeps the S1a step post** (`activate_thread.sw`, S1aCStepD's `S1aStepR2K.ofRpW`). -/ +theorem sched.activate_thread.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.activate_thread st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.activate_thread.sw hA a I hc0 hks (SW.start B Y h)) fun r W => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at W ⊢ + exact S1aStepR2K.ofRpW W.1.1 W.1.2.1 I.del.vr I.fu I.vcc C Kc Df R sep KC + +/-- MdbRunQ's `runBuf_of` from the parts it reads (`HeapOK`, `FrUb` and `SysL` at the state). -/ +theorem runBuf_of' {Ub : Set U64} {s x : S} (hH : HeapOK H) (fu : FrUb st Ub OS s) (B : SysL st H Cs OS ia ie s) + {y : U64} (hx : sbWordA y ∈ OS) (hc : capA st x (sbWordA y) = capA st s (sbWordA y)) : + RunBuf st {b | b ∈ Ub ∧ FrBw H OS b ∧ FrCw st OS s b} x y := by + intro ptr size rights dev x1 x2 x3 x4 bits sz hcap hdev hrw hbits hsz h63 hlt hge + subst hdev + rw [capA_eq, hc] at hcap + have hcap0 := okinj hcap + have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits + have hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits).1 + have hb64 : 12 ≤ bits.val := by + cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp + intro i hi + obtain ⟨hal', hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi + show _ ∈ Ub ∧ FrBw H OS _ ∧ FrCw st OS s _ + refine And.intro (fu _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal' hin.1 hin.2) + (And.intro (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64, hin⟩ fun z hz g => ?_)) + ⟨_, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap0, hbits, hin⟩) + rcases hFo z hz with g' | g' <;> omega + +set_option maxHeartbeats 8000000 in +/-- **`vcpu::check` of the current thread at the end of a walk** (`vcpu.check.s1a` from the walk bundle `SW s0 s`: +`VcTy` by `VKeep`, `FrUb` by the walk's `XV`; the close from `s0`). -/ +theorem vcpu.check.swS (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s0 s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : ∀ y ∈ H.tcbs, L.actionW s ≠ y) + (C : S1aArmCol st H Cs OS Vc Ub s0) (Kc : S1aCapCol st H OS Ub s0) (Df : DevFrAl st OS s0) + (R2 : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s0) (sep : S1aKtUt st OS Kt s0) + (KC : S1aHiK st OS Kt KLv s0) : + vcpu.check st ar s a (L.curW s) ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have R := W.1 + have h := R.blk + have h0 := R.sys.ly.h0 + have q := h.1.choose_spec.choose_spec + have hct : L.curW s ∈ H.tcbs := q.curT + have hvx := I.vty.keep W.2.2 + have fux : FrUb st Uq OS s := R.xv.2 _ I.fu + have hks' : HeapKsOff H (L.ksb s) := by rw [R.ksb]; exact hks + have hvr' : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt := by rw [R.ksb]; exact I.del.vr + have hW' : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (hvx.obj v hv).1 + let U0 : Set U64 := {b | b ∈ Uq ∧ FrBw H OS b ∧ FrCw st OS s b} + have hUs : ∀ b ∈ U0, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := fun b hb => hvx.usr b hb.1 + have hUF : ∀ b ∈ U0, FrBw H OS b ∧ FrCw st OS s b := fun b hb => hb.2 + have hBuf : ∀ x', WritesIn st s x' (RnN st H Cs Vc U0 (L.curW s) (L.ksb s)) → RunBuf st U0 x' (L.curW s) := + fun x' w => runBuf_of' I.del.heap fux R.sys (I.del.vc.bcov _ hct) + ((RunB.osk I.del.os I.del.sca I.del.vc h ((w.mono fun b hb => rnn_runW hUF hct hb).mono + fun _ hb => Or.inl hb)).capA (I.del.vc.bcov _ hct)) + have fin : ∀ {x : S}, (C0 s x) → RQ st H Cs Vc U0 (L.curW s) s x → + L.mem s (stA (L.curW s)) = sched.TS_RUNNING_VM → S1aStepR2K st Cs Ub Kt KLv ia ie n x := fun {x} c d hvm => by + have f : WritesIn st s x (RunW st H Cs Vc OS s s) := d.w.mono fun b hb => rnn_runW hUF hct hb + have fB : WritesIn st s x (RunB st H Cs Vc OS s s) := f.mono fun _ hb => Or.inl hb + have dm : DMU st H Cs Vc OS s (L.curW s) 0#u64 s x := + DMU.ofTc h h0 R.sym R.sys.vr f d.lv d.ep (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_BLOCKED_ON_REPLY]) + have d0 : DMU st H Cs Vc OS s 0#u64 0#u64 s x := ⟨dm.w, fun z hp _ hl => by + by_cases hz : z = L.curW s + · subst hz; exact Or.inl ⟨hct, Or.inl (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_INACTIVE])⟩ + · exact dm.lv z hz hp hl, dm.idle, dm.isc, dm.vr, dm.sym⟩ + have hp0 : ∀ k, H 0#u64 = some k → ∃ y ∈ OS, NamesA (capA st s y) 0#u64 k := fun k hk => by + rw [h0] at hk; cases hk + obtain ⟨S', Y'⟩ := SysL.dfMDU I.del.heap I.del.os I.del.vc (fun b hb => (hvx.w hb).2.1) h I.del.sca hp0 hp0 + R.sys d0 + obtain ⟨Ac', hb'⟩ := c.bxi + have k : OSKeep st OS s x := RunB.osk I.del.os I.del.sca I.del.vc h fB + have A' := ArmQIAt.ofRunBK I.del.heap hvr' hks' (TabF.of hvr' q R.sys.ly.ksw hc0) h fB k ⟨S', Y'⟩ hb'.blk + have xc' := R.xc.trans (XC.keep k A'.2.1) + have xv' := R.xv.trans (XV.keep A'.2.2 k) + have Q' := ArmQIAt.ofXC (Vc := Vc) (ia := ia) (ie := ie) ⟨S', Y'⟩ ⟨Ac', hb'.blk⟩ xc' xv'.1.toVs + exact S1aStepR2K.ofKeep' ⟨Q'.1, Q'.2, xv'.1, W.2.1.trans' k⟩ I.del.vr I.fu I.vcc C Kc Df R2 sep KC + by_cases hvm : L.mem s (stA (L.curW s)) = sched.TS_RUNNING_VM + · have hnb : ¬ BlockedR (L.mem s (stA (L.curW s))) := by + rw [hvm]; simp [BlockedR, Blocked, sched.TS_RUNNING_VM, sched.TS_BLOCKED_ON_SEND, sched.TS_BLOCKED_ON_RECV, + sched.TS_BLOCKED_ON_NTFN, sched.TS_BLOCKED_ON_REPLY] + have c0 : C0 s s := ⟨hcsc, Ac, BlkOK.bxi h, rfl, rfl, Or.inl rfl, hna, hnb, WritesIn.refl _ _⟩ + by_cases hv0 : L.mem s (runVcpuA (L.curW s)) = 0#u64 + · exact WP.spec_mono (vcpu.check.rq0 hA c0 (RQ.refl s) hct hv0 hW' hUs a) fun r hr => by + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + exact fin hr.1 hr.2 hvm + · have hvc : L.mem s (runVcpuA (L.curW s)) ∈ Vc := (hvx.run _ hct).resolve_left hv0 + exact WP.spec_mono (vcpu.check.rq hA c0 (RQ.refl s) hct rfl hvc hW' hUs hBuf a) fun r hr => by + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + exact fin hr.1 hr.2 hvm + · unfold vcpu.check + step with obj.Tcb.state.spec as ⟨i, ei⟩ + rw [if_pos (by rw [ei]; exact bne_iff_ne.mpr hvm)] + simp only [WP.spec_ok, WP.uncurry'_pair] + exact S1aStepR2K.ofRpW W.1 W.2.1 I.del.vr I.fu I.vcc C Kc Df R2 sep KC + +set_option maxHeartbeats 16000000 in +/-- **`syscall::finish` keeps the S1a step post**: `schedule` (`schedule.sw`, with QueueSchedule's `schedule.inv` for +the action `0` and the current SC), `activate_thread` (`activate_thread.sw`, QueueKeeps's `activate_thread.entry` for +the current SC), `vcpu::check` of the current thread (`vcpu.check.swS`). Per-state fact: [J] `RunVcpuInv`. -/ +theorem syscall.finish.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + syscall.finish st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + obtain ⟨⟨Q, Rq, q⟩, hB, hX, hS, hSg⟩ := id h + unfold syscall.finish + refine WP.spec_bind (WP.spec_and (sched.schedule.sw hA a I B Y h hc0 hks hRV) + (sched.schedule.inv hA s a Q Rq q hB hS hX (WP.spec_mono (timer.fire.sw hA a I hc0 hks (SW.start B Y h) hRV) + fun r hr => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨⟨Q', R', q'⟩, hB', hX', hS', -⟩ := hr.1.1.blk + exact ⟨⟨Q', R', q'⟩, hB', hS', hX'⟩))) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨W1, -, -, -, -, hA1, ea1, hcs1⟩ := hh + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, -⟩ := id W1.1.blk + have E1 : EntryInv st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s1 := + ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hX1.2.2.tm, hA1, + fun e => notT_small (v := 0#u64) q1.tcbs (by simp) (by rw [← ea1, e]; exact q1.curT), fun _ => hcs1⟩ + refine WP.spec_bind (WP.spec_and (sched.activate_thread.sw hA a1 I hc0 hks W1) + (sched.activate_thread.entry hA s1 a1 E1)) ?_ + rintro ⟨s2, a2⟩ hh2 + simp only [WP.uncurry'_pair] at hh2 ⊢ + obtain ⟨⟨W2, ea2⟩, E2⟩ := hh2 + have q2 := W2.1.blk.1.choose_spec.choose_spec + step with sched.cur_thread.spec as ⟨t, et⟩ + have e : t = L.curW s2 := et + subst e + refine vcpu.check.swS hA a2 I hc0 hks W2 E2.2.2.2.2.2.2.2 (fun y hy e => ?_) C Kc Df R sep KC + rcases ea2 with e2 | e2 + · rw [e2, ea1] at e; exact notT_small (v := 0#u64) q2.tcbs (by simp) (by rw [e]; exact hy) + · rw [e2] at e; exact notT_small (v := 1#u64) q2.tcbs (by simp) (by rw [e]; exact hy) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCFpu.lean b/proofs/Fl4ProofsA64/P1/S1aCFpu.lean new file mode 100644 index 000000000..e6c62c9a0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCFpu.lean @@ -0,0 +1,195 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a4)): **TCB WriteFPU keeps every capability** (tcb.rs `fpu_transfer`, +`to_frame = false`). + +* **`armS_of_DF`**: a decode arm that is one `DF` step from the decode's state exports the cap-keeping record. +* **`LvF.ofFpu`**: writes to a TCB's FPU area write no liveness word. +* **`syscall.decode_invocation.writeFpu_armS`**: the stall, the caller's restart, then 65 words copied into the + target's FPU area (`K8.KW` words), so one `DF` step. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCStall +import Fl4ProofsA64.P1.MdbFpuL +import Fl4ProofsA64.P1.MdbRegL + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- **A decode arm that is one `DF` step** keeps every capability. -/ +theorem armS_of_DF {s s' : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (d : DF st H Cs (L.curW s) ∅ s s') + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') : + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := by + have kt := DF.osTab I.del.heap I.del.os D.bxi B I.del.vr P.core0 d + have hS := SysL.df P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d + have hK := ArmVsK.ofDFI I D P B d + obtain ⟨Q, Rq, q⟩ := D.bxi.1 + have F : TabF st H Cs OS s := TabF.of I.del.vr q B.ly.ksw P.core0 + have a := ArmQIAt.ofW (Vc := Vc) I.del.vr d.w + (fun b hd => DfW.notAsW I.del.heap F I.del.vr (fun c hc => q.nodes c hc) hd) kt.1 hS hb hK.toVs + exact ⟨a, kt.2.toDel, hK, kt.1⟩ + +/-- The words of the FPU area of `t` (TCB offsets `1088 … 1600`). -/ +def FpuArea (t b : U64) : Prop := ∃ K : U64, 1088 ≤ K.val ∧ K.val < 1608 ∧ K.val % 8 = 0 ∧ b = wa t K + +theorem fpuArea_of_cww {t b : U64} (ht : TcbAddr t) (h : CWW (wa t layout.tcb.FPU) 65#u64 b) : FpuArea t b := by + obtain ⟨k, hk, e⟩ := h + have hv := field_val ht (K := layout.tcb.FPU) (by simp [layout.tcb.FPU]) + have hk' : k < 65 := by simpa using hk + let K : U64 := ⟨BitVec.ofNat 64 (1088 + 8 * k)⟩ + have hK : K.val = 1088 + 8 * k := by + show (BitVec.ofNat 64 (1088 + 8 * k)).toNat = _ + simp; omega + refine ⟨K, by omega, by omega, by omega, UScalar.eq_of_val_eq ?_⟩ + rw [e, hv, field_val ht (by omega), hK]; simp [layout.tcb.FPU]; omega + +/-- **Writes to a TCB's FPU area write no liveness word.** -/ +theorem LvF.ofFpu {T Cs Ω Sg Rp Scs Nt : Set U64} {Z : U64 → Nat} {s s' : S} {t : U64} + (C : LvC st T Cs Ω Sg Rp Scs Nt Z s) (ht : t ∈ T) (w : WritesIn st s s' (FpuArea t)) : + LvF st T Cs Rp Scs Nt LvX.none s s' := by + have hT := C.tcb + have hta := hT t ht + have keep : ∀ b, Aligned b → ¬ FpuArea t b → L.mem s' b = L.mem s b := fun b ha hn => w.mem_eq ha hn + have hS : ∀ b ∈ Sg, ¬ FpuArea t b := by + rintro b hb ⟨K, h1, h2, -, e⟩ + have hK4 : K.val < 4096 := by omega + exact out_ne_field (C.om b (C.sub b hb)) ht hta hK4 (by rw [← e]) + have hN : ∀ c ∈ Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → + L.mem s' (L.nodeAt s c o) = L.mem s (L.nodeAt s c o) := by + intro c hc o ho h8 + refine keep _ (nodeAt_aligned (C.nodes c hc) ho h8) ?_ + rintro ⟨K, h1, h2, -, e⟩ + have hK4 : K.val < 4096 := by omega + exact node_ne_field (C.nodes c hc) ho ht hta hK4 e + refine ⟨w.1, w.2.1, ?_, fun c hc => ?_, fun y hy K hK _ => ?_, + fun c hc o hO _ => keep _ (C.al_c hc hO) (hS _ (C.sgC c hc o hO)), + fun n hn o hO _ => keep _ (C.al_n hn hO) (hS _ (C.sgN n hn o hO)), + fun r hr o hO _ => keep _ (C.al_r hr hO) (hS _ (C.obj.rword hr hO.lt.1 hO.lt.2))⟩ + · unfold LawfulStore.idleW + rw [w.2.1, nodeAt_of_ksb w.1] + exact hN _ C.cur _ (by rw [idle8]; omega) (by rw [idle8]) + · rw [nodeAt_of_ksb w.1] + exact hN c hc _ (by rw [debug_val]; omega) (by rw [debug_val]) + · have hK' := hK.lt + refine keep _ (C.al_t hy hK) ?_ + rintro ⟨K', h1, h2, -, e⟩ + refine field_ne (hT y hy) hta hK'.1 (by omega) (fun _ h => ?_) e + unfold LvO at hK; omega + +theorem DF.ofFpu {Cs : Set U64} {c t : U64} {Ko : Set Nat} {Ω Rp : Set U64} {s s' : S} + (C : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s) (ht : t ∈ H.tcbs) + (w : WritesIn st s s' (FpuArea t)) : DF st H Cs c Ko s s' := by + refine DF.ofKL (X := LvX.none) (w.mono ?_) (LvF.ofFpu C ht w) (LvF.none_le _) + rintro b ⟨K, h1, h2, -, e⟩ + exact Or.inl ⟨t, ht, K, by omega, by omega, by omega, ⟨by omega, by omega, by omega, by omega⟩, e⟩ + +/-- **TCB WriteFPU** keeps every capability. -/ +theorem syscall.decode_invocation.writeFpu_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBWriteFPU) (len : U64) + (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + refine syscall.decode_invocation.tcbG + (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x) + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩ a len blk call don fp buf + fun lbl' call' e => ?_ + have hl : lbl' = fl4_abi.label.TCBWriteFPU := e.trans hl + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + have hS : P0.StoreTotal st := L.total + have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, -, -⟩ + simp only [uncurry_apply_pair] + iterate 25 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBBindNotification, fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, fl4_abi.label.TCBGetBreakpoint, fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, fl4_abi.label.TCBWriteFPU, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + have done : ∀ {s' : S} (_ : DF st H Cs (L.curW s) ∅ s s') + (_ : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s'), + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := + fun d hb => armS_of_DF I D P B Y d hb + have E1 := done d1 h1.bxi.blk + unfold tcb.fpu_transfer + have E : ∀ (m : Result (core.result.Result Unit error.Exc)), m ⦃ _ => True ⦄ → + (do let r ← m; ok (r, s1, a1)) ⦃ r => ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ + ArmVsK st H OS Vc s r.2.1 ∧ OSKeep st OS s r.2.1 ⦄ := + fun m hm => WP.spec_bind hm fun _ _ => (WP.spec_ok _).2 E1 + refine WP.spec_bind (tcb.extra.mem0 _) fun o ho => ?_ + rcases o with _ | x + · exact E _ (P0.error.truncated.p0 _) + show (if len >= 1#u64 then _ else _) ⦃ _ ⦄ + by_cases hln : len >= 1#u64 + swap + · rw [if_neg hln]; exact E _ (P0.error.truncated.p0 _) + rw [if_pos hln] + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun off _ => ?_ + rw [capA_eq s1 x, bind_ok] + generalize capA st s1 x = cp + cases cp + all_goals first | exact E _ (P0.error.invalid_cap.p0 _ _) | skip + rename_i ptr sz r d m ep asid va + show (if d = true then _ else _) ⦃ _ ⦄ + by_cases hd : d = true + · rw [if_pos hd]; exact E _ (P0.error.invalid_cap.p0 _ _) + rw [if_neg hd] + show (if r = capability.VM_KERNEL_ONLY then _ else _) ⦃ _ ⦄ + by_cases hk : r = capability.VM_KERNEL_ONLY + · rw [if_pos hk]; exact E _ (P0.error.invalid_cap.p0 _ _) + rw [if_neg hk] + simp only [Bool.false_eq_true, ↓reduceIte] + refine fpu_chkO s1 a1 sz off _ (fun bits _ ho hob => ?_) (fun _ => E1) + beta_reduce + have run1 : Runnable (L.mem s1 (stA (L.curW s))) := by + rw [stA_eq, h1.fld _ hct _ (by simp) (by simp), ← stA_eq]; exact D.run + refine WP.spec_bind (Pₘ := fun s2 => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ + DF st H Cs (L.curW s) ∅ s s2) ?_ ?_ + · unfold tcb.restart_caller + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e : ct = L.curW s := (show ct = L.curW s1 from ect).trans h1.cur + subst e + refine WP.spec_mono (sched.set_thread_state.dfR s1 (L.curW s) h1.bxi.blk hct run1) ?_ + rintro s2 ⟨h2, fw2, l2⟩ + exact ⟨h2, d1.trans (DF.ofKL fw2 l2 (tc_le _ _))⟩ + rintro s2 ⟨h2, d2⟩ + refine WP.spec_bind (hA.fpu_flush a1 t) fun a2 _ => ?_ + step as ⟨i4, hi4⟩ + step as ⟨words, hw⟩ + have hw' : words = 65#u64 := by + apply UScalar.eq_of_val_eq; simp at hi4; simp at hw ⊢; omega + subst hw' + simp only [lift, bind_ok, obj.Tcb.fpu_addr, Bool.false_eq_true, ↓reduceIte] + have hT := (LvC.of_blk h2).tcb + have hta := hT t ht + have hfv := field_val hta (K := layout.tcb.FPU) (by simp [layout.tcb.FPU]) + have hfa : Aligned (wa t layout.tcb.FPU) := by + unfold Aligned; rw [hfv]; have := hta.align; simp [layout.tcb.FPU]; omega + have hff : (wa t layout.tcb.FPU).val + 8 * (65#u64 : U64).val ≤ 2 ^ 64 := by + rw [hfv]; have := hta.fits; simp [layout.tcb.FPU]; omega + unfold tcb.copy_words + refine WP.spec_bind (tcb.copy_words_loop.w s2 _ _ _ 0#u64 hfa hff) fun s3 w3 => ?_ + have w3' : WritesIn st s2 s3 (FpuArea t) := w3.mono fun b hb => fpuArea_of_cww hta hb + refine WP.spec_bind (hA.fpu_sanitise a2 t) fun a3 _ => ?_ + refine WP.spec_bind (hA.fpu_reload a3 t) fun a4 _ => ?_ + have d3 : DF st H Cs (L.curW s) ∅ s s3 := + d2.trans (DF.ofFpu (Ω := H.omega) (Rp := H.replies) (LvC.of_blk h2) ht w3') + have b3 := (blk_rf h2 (w3.mono fun b hb => fpu_area_xfer hT ht hb)).1 + exact (WP.spec_ok _).2 (done d3 b3) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCIrq.lean b/proofs/Fl4ProofsA64/P1/S1aCIrq.lean new file mode 100644 index 000000000..6ca6493cc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCIrq.lean @@ -0,0 +1,329 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c6): **`handle_interrupt`** to the S1a step post. + +* **`interrupt.handle_interrupt.sw`**: QueueEntry's `handle_interrupt.bxi` cases over the walk bundle `SW`: a signal + IRQ's notification (the IRQ slot is an `OS` slot, `DelIn.irq`; its cap typed by the slot's `SlotTy`, so the + notification is a heap notification named by that slot) is signalled (MdbSigL's `send_signal.dmd`, QueueSignal's + `send_signal.tinv0`); a timer IRQ writes the node's `REPROGRAM` and `ARMED` words (`nodeW_step`); a reschedule IPI + is `reschedule_required` (a queue step, `SW.q`); every other branch only touches the interrupt controller. +* **`interrupt.handle_interrupt.s1a`**: closed by `S1aStepR2K.ofRpPost`. +* **`vcpu.handle_vgic_maintenance.s1a`**: no write, or the current thread's fault (`handle_fault.s1a`). +* **`vcpu.handle_vppi_event.s1a`**: the virtual timer's `VPPI_MASKED` word (a VCPU-word `DFB` step, MdbVcArmQ's + AckVPPI route) to the Reply-walk bundle, then the current thread's fault (`handle_fault.rpw`). +* **`vcpu.complete_run.s1a`**: the VCPU run's completion for the current thread (MdbRunQ's `vcpu.check.rq` run + branch), closed as S1aCFinish's `vcpu.check.s1a`; per-state facts as there (the `Cur0` parts). + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5, as `handle_interrupt.bxi`). The IRQ slot cap +typing that `handle_interrupt.bxi` takes as `hirq` is derived here from `SysPlace.ty`. +-/ +import Fl4ProofsA64.P1.S1aCRecv +import Fl4ProofsA64.P1.S1aCFinish + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "C0" s0:max s:max => Cur0 st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s0 s + +section top +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} + {n : U64} + +set_option maxHeartbeats 16000000 in +/-- **`handle_interrupt` keeps the walk bundle** (module docstring). -/ +theorem interrupt.handle_interrupt.sw (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) (irq : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hRV : RunVcpuInv st H.tcbs s) : + interrupt.handle_interrupt st ar s a irq ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s s' ⦄ := by + have hST : P0.StoreTotal st := L.total + have h0 := B.ly.h0 + have hc0 := Pz.core0 + have W : SW st H Cs OS Vc ia ie Ac s s := SW.start B Y h + have q := h.1.choose_spec.choose_spec + unfold interrupt.handle_interrupt + step with layout.irq.MAX.spec as ⟨mx, emx⟩ + split + · refine WP.spec_bind (hA.mask_irq a irq true) fun a1 _ => ?_ + refine WP.spec_bind (hA.ack_irq a1 irq) fun a2 _ => ?_ + exact (WP.spec_ok _).2 W + step with P0.interrupt.irq_state.p0 st s irq hST as ⟨v⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => SW st H Cs OS Vc ia ie Ac s r.1) ?_ ?_ + · split + · rename_i hle _ + step with interrupt.irq_slot.val as ⟨sl, esl⟩ + subst esl + have hirq' : irq.val < 5376 := by + have : mx.val = 5375 := by rw [emx]; rfl + simp at hle; omega + have hy : irqSlotA (L.ksb s) irq ∈ OS := I.del.irq.1 irq hirq' + have hty := (Pz.ty _ hy).capTy.1.1 + rw [capA_eq, bind_ok] + refine WP.spec_bind (Pₘ := fun r : S × A => SW st H Cs OS Vc ia ie Ac s r.1) ?_ ?_ + · split + all_goals try exact (WP.spec_ok _).2 W + rename_i ptr badge b x hcx + split + · obtain ⟨hn, hH⟩ := hty.2.1 ptr badge b x hcx + refine WP.spec_mono (WP.spec_and (notification.send_signal.dmd hA a ptr badge h hn hH h0 Y B.vr + (fun y hy' hb => hRV.blocked hy' hb)) (notification.send_signal.tinv0 hA s a ptr badge h hn hH hRV)) ?_ + rintro ⟨s', a'⟩ hr + simp only [WP.uncurry'_pair] at hr ⊢ + exact W.dmd I hc0 hks (fun k hk _ => by + rw [hH] at hk; cases hk; exact ⟨_, hy, by rw [hcx]; exact names_ntfn⟩) hr.1 hr.2 + · exact (WP.spec_ok _).2 W + · rintro ⟨s3, a2⟩ h3 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (hA.mask_irq a2 irq true) fun a3 _ => ?_ + exact (WP.spec_ok _).2 h3 + split + · step with LawfulStore.cur_cpu_spec as ⟨c, ec⟩ + step with obj.node_set.spec as ⟨s2, e2⟩ + step with obj.node_set.spec as ⟨s3, e3⟩ + try simp only [WP.spec_ok] + subst ec + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have av : layout.node.ARMED.val = 80 := by simp [layout.node.ARMED] + have w2 : WritesIn st s s2 (· = L.nodeAt s (L.cpu s) layout.node.REPROGRAM) := by + rw [e2]; exact writesIn_wr (nodeAt_aligned (q.nodes _ q.cur) (by rw [rp]; omega) (by rw [rp])) + obtain ⟨d2, b2⟩ := nodeW_step 0#u64 h h0 Y B.vr (by rw [rp]; unfold LowFree; omega) + (by rw [rp]; omega) (by rw [rp]; omega) w2 + have W2 := W.dmd0 I hc0 hks d2 b2 + have q2 := b2.1.choose_spec.choose_spec + have ecpu : L.cpu s2 = L.cpu s := by rw [e2]; simp only [LawfulStore.cpu_wr] + have w3 : WritesIn st s2 s3 (· = L.nodeAt s2 (L.cpu s2) layout.node.ARMED) := by + rw [e3, ← ecpu]; exact writesIn_wr (nodeAt_aligned (q2.nodes _ q2.cur) (by rw [av]; omega) (by rw [av])) + obtain ⟨d3, b3⟩ := nodeW_step 0#u64 b2 h0 W2.1.sym W2.1.sys.vr (by rw [av]; unfold LowFree; omega) + (by rw [av]; omega) (by rw [av]; omega) w3 + exact W2.dmd0 I hc0 hks d3 b3 + split + · unfold smp.handle_ipi + refine WP.spec_bind (P0.layout.irq.id.p0 irq) fun ri _ => ?_ + split + · obtain ⟨⟨Q, R, h1⟩, hB, -, -, hSg⟩ := id h + refine WP.spec_bind (WP.spec_and (sched.reschedule_required.sch s Q R h1 hB hSg) + (K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s h1)) ?_ + rintro s1 ⟨⟨p1, -, -, -⟩, f1⟩ + exact (WP.spec_ok _).2 (W.q I hc0 hks p1 f1) + · exact (WP.spec_ok _).2 W + · refine WP.spec_bind (Pₘ := fun _ : A => True) ?_ fun t _ => (WP.spec_ok _).2 W + split + · exact WP.spec_mono (hA.mask_irq a irq true) fun _ _ => trivial + · exact (WP.spec_ok _).2 trivial + · rintro ⟨s1, a1⟩ h1 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (hA.ack_irq a1 irq) fun a2 _ => ?_ + exact (WP.spec_ok _).2 h1 + +/-- **`handle_interrupt` keeps the S1a step post** (`handle_interrupt.sw`, `S1aStepR2K.ofRpPost`). -/ +theorem interrupt.handle_interrupt.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) (irq : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + interrupt.handle_interrupt st ar s a irq ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (interrupt.handle_interrupt.sw hA a irq I B Y h hks Pz hRV) fun r W' => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at W' ⊢ + exact S1aStepR2K.ofRpPost I W'.1.post C Df R sep KC + +set_option maxHeartbeats 8000000 in +/-- **`complete_run` of the current thread keeps the S1a step post** (MdbRunQ's `vcpu.check.rq` run branch: +`complete_run.ub` / `.rnv` from the run VCPU (`DelIn.vty.run`) and the run frame (`runBuf_of`), closed as +`vcpu.check.s1a`; a thread with no run VCPU writes nothing). [J] `RunVcpuInv` gives `TS_RUNNING_VM` for a nonzero +`RUN_VCPU`. -/ +theorem vcpu.complete_run.s1a (hA : P0.ArchTotal ar) {s : S} (a : A) (stop m1 m2 m3 : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) + (hcsc : L.mem s (scA (L.curW s)) ≠ 0#u64 → L.cscW s = L.mem s (scA (L.curW s))) + (hna : ∀ y ∈ H.tcbs, L.actionW s ≠ y) (hnb : ¬ BlockedR (L.mem s (stA (L.curW s)))) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + vcpu.complete_run st ar s a (L.curW s) stop m1 m2 m3 ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have h0 := B.ly.h0 + have q := h.1.choose_spec.choose_spec + have hct : L.curW s ∈ H.tcbs := q.curT + have c0 : C0 s s := ⟨hcsc, Ac, BlkOK.bxi h, rfl, rfl, Or.inl rfl, hna, hnb, WritesIn.refl _ _⟩ + have hW' : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + let U0 : Set U64 := {b | b ∈ Uq ∧ FrBw H OS b ∧ FrCw st OS s b} + have hUs : ∀ b ∈ U0, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := fun b hb => I.vty.usr b hb.1 + have hUF : ∀ b ∈ U0, FrBw H OS b ∧ FrCw st OS s b := fun b hb => hb.2 + have hBuf : ∀ x', WritesIn st s x' (RnN st H Cs Vc U0 (L.curW s) (L.ksb s)) → RunBuf st U0 x' (L.curW s) := + fun x' w => runBuf_of I B (I.del.vc.bcov _ hct) + ((RunW.osk I h (w.mono fun b hb => rnn_runW hUF hct hb)).capA (I.del.vc.bcov _ hct)) + have fin : ∀ {x : S}, (C0 s x) → RQ st H Cs Vc U0 (L.curW s) s x → + L.mem s (stA (L.curW s)) = sched.TS_RUNNING_VM → S1aStepR2K st Cs Ub Kt KLv ia ie n x := fun {x} c d hvm => by + have f : WritesIn st s x (RunW st H Cs Vc OS s s) := d.w.mono fun b hb => rnn_runW hUF hct hb + have dm : DMU st H Cs Vc OS s (L.curW s) 0#u64 s x := + DMU.ofTc h h0 Y B.vr f d.lv d.ep (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_BLOCKED_ON_REPLY]) + have d0 : DMU st H Cs Vc OS s 0#u64 0#u64 s x := ⟨dm.w, fun z hp _ hl => by + by_cases hz : z = L.curW s + · subst hz; exact Or.inl ⟨hct, Or.inl (by rw [hvm]; simp [sched.TS_RUNNING_VM, sched.TS_INACTIVE])⟩ + · exact dm.lv z hz hp hl, dm.idle, dm.isc, dm.vr, dm.sym⟩ + have hp0 : ∀ k, H 0#u64 = some k → ∃ y ∈ OS, NamesA (capA st s y) 0#u64 k := fun k hk => by + rw [h0] at hk; cases hk + have hS' := SysL.dfMDU I.del.heap I.del.os I.del.vc (fun b hb => (I.vty.w hb).2.1) h I.del.sca hp0 hp0 B d0 + obtain ⟨Ac', hb'⟩ := c.bxi + have A' := ArmQIAt.ofRunW0 I B hks hc0 h f hS' hb'.blk + exact S1aStepR2K.ofKeep' ⟨A'.1, A'.2.1.toDel, A'.2.2, RunW.osk I h f⟩ I.del.vr I.fu I.vcc C Kc Df R sep KC + have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => by + obtain ⟨v, hv, o, ho, h8, rfl⟩ := hb + exact ⟨(hW' v hv o ho h8).2.1, (hW' v hv o ho h8).2.2⟩ + by_cases hv0 : L.mem s (runVcpuA (L.curW s)) = 0#u64 + · unfold vcpu.complete_run + rw [eq_of_spec_fd P0.Consts.layout.tcb.RUN_VCPU.spec] + simp only [lift, bind_ok, L.read_eq] + have hv0' : L.mem s (core.num.U64.wrapping_add (L.curW s) 3672#u64) = 0#u64 := hv0 + rw [if_pos hv0'] + refine (WP.spec_ok _).2 ?_ + exact S1aStepR2K.ofKeep' (S1aKeep.ofDMD (Vc' := Vc) (Ub := Uq) (Pt := Pt) (p := 0#u64) B Y h I.del.heap + I.del.os I.del.sca hc0 I.del.vr hks (fun k hk => by rw [h0] at hk; cases hk) (DMD.refl 0#u64 h h0 Y B.vr) h) + I.del.vr I.fu I.vcc C Kc Df R sep KC + · have hvm := hRV _ hct hv0 + have hvc : L.mem s (runVcpuA (L.curW s)) ∈ Vc := (I.vty.run _ hct).resolve_left hv0 + have hbuf := hBuf s (WritesIn.refl _ _) + refine WP.spec_mono (WP.spec_and (vcpu.complete_run.ub hA c0 a _ stop m1 m2 m3 hct hvm (fun _ => hW' _ hvc) hUs + hbuf) (vcpu.complete_run.rnv hA c0 hW' hUs a _ stop m1 m2 m3 hct (fun _ => hvc) (fun _ => hbuf))) fun r hr => ?_ + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + exact fin hr.1.1.cur (RQ.ofV h hct hUs hWv hr.2 hr.1.1.idle) hvm + +set_option maxHeartbeats 8000000 in +/-- **`handle_vgic_maintenance` keeps the S1a step post**: nothing is written, or the current thread's fault +(`handle_fault.s1a`; per-state facts as there). -/ +theorem vcpu.handle_vgic_maintenance.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) (eisr : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hc : CanBlock st H.tcbs Ac s (L.curW s)) (hrun : L.mem s (stA (L.curW s)) ≠ sched.TS_INACTIVE) + (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + vcpu.handle_vgic_maintenance st ar s a eisr ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have hST : P0.StoreTotal st := L.total + have ok0 : (ok (s, a) : Result (S × A)) ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + (WP.spec_ok _).2 (S1aStepR2K.ofRpPost I (RpW.start B Y h).post C Df R sep KC) + have HF : ∀ f, faults.handle_fault st ar s a (L.curW s) f ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + fun f => faults.handle_fault.s1a hA a _ f I B Y h hks Pz hc hrun hRV C Df R sep KC + unfold vcpu.handle_vgic_maintenance + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have ect' : ct = L.curW s := ect + subst ect' + step with P0.vcpu.bound.p0 st s _ hST as ⟨v⟩ + split + · exact ok0 + step with P0.sched.is_schedulable.p0 st s _ hST as ⟨b⟩ + split + · step with P0.obj.Tcb.in_queues.p0 st _ s hST as ⟨i1⟩ + split + · exact ok0 + · refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun r _ => ?_ + · split + · step with P0.core.num.U64.trailing_zeros.spec as ⟨i2, _⟩ + simp only [lift, bind_ok, WP.spec_ok] + · exact (WP.spec_ok _).2 trivial + · obtain ⟨idx, iv⟩ := r + exact HF _ + · exact ok0 + +set_option maxHeartbeats 16000000 in +/-- **`handle_vppi_event` keeps the S1a step post**: nothing is written, or (for the virtual timer) the bound VCPU's +`VPPI_MASKED` word — a VCPU-word `DFB` step (MdbVcArmQ's AckVPPI route: `SysL.dfB`, `ArmQIAt.ofRunW0`, `RunW.osk`), +giving the Reply-walk bundle — then the current thread's fault (`handle_fault.rpw`), closed by +`S1aStepR2K.ofRpPost`. Per-state facts as `handle_fault.s1a`, the current thread runnable (`SysL.dfB`'s). -/ +theorem vcpu.handle_vppi_event.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) (irq_id : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hc : CanBlock st H.tcbs Ac s (L.curW s)) (hrn : Runnable (L.mem s (stA (L.curW s)))) + (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + vcpu.handle_vppi_event st ar s a irq_id ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have hST : P0.StoreTotal st := L.total + have q := h.1.choose_spec.choose_spec + have hct := hc.mem + have hrun : L.mem s (stA (L.curW s)) ≠ sched.TS_INACTIVE := fun e => by + rw [e] at hrn; exact not_runnable_inactive hrn + have ok0 : (ok (s, a) : Result (S × A)) ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + (WP.spec_ok _).2 (S1aStepR2K.ofRpPost I (RpW.start B Y h).post C Df R sep KC) + have HF1 : ∀ (s1 : S) (a1 : A), RpW st H Cs OS Vc ia ie Ac s s1 → CanBlock st H.tcbs Ac s1 (L.curW s) → + L.mem s1 (stA (L.curW s)) ≠ sched.TS_INACTIVE → RunVcpuInv st H.tcbs s1 → + faults.handle_fault st ar s1 a1 (L.curW s) (.VppiEvent irq_id) ⦃ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := fun s1 a1 R1 hc1 hr1 hRV1 => + WP.spec_mono (faults.handle_fault.rpw hA a1 _ _ Pz R1 I.del.sca I.ts hks I.del.vr hc1 hr1 hRV1) fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact S1aStepR2K.ofRpPost I P C Df R sep KC + unfold vcpu.handle_vppi_event + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have ect' : ct = L.curW s := ect + subst ect' + step with vcpu.bound.spec as ⟨v, ev⟩ + split + · exact ok0 + rename_i hv0 + step with P0.sched.is_schedulable.p0 st s _ hST as ⟨b⟩ + split + · step with P0.obj.Tcb.in_queues.p0 st _ s hST as ⟨i1⟩ + split + · exact ok0 + have hvc : v ∈ Vc := by + rcases I.vty.bnd _ hct with e0 | e0 + · exact absurd (ev.trans e0) hv0 + · rw [ev]; exact e0 + have hw : VcWords H.omega H.frame v := (I.vty.obj v hvc).1 + have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => ⟨(I.vty.w hb).2.1, (I.vty.w hb).2.2⟩ + have VW : ∀ val : U64, RpW st H Cs OS Vc ia ie Ac s (L.wr s (wa v vcpu.VPPI_MASKED) val) ∧ + CanBlock st H.tcbs Ac (L.wr s (wa v vcpu.VPPI_MASKED) val) (L.curW s) ∧ + L.mem (L.wr s (wa v vcpu.VPPI_MASKED) val) (stA (L.curW s)) ≠ sched.TS_INACTIVE ∧ + RunVcpuInv st H.tcbs (L.wr s (wa v vcpu.VPPI_MASKED) val) := fun val => by + have hx := hw vcpu.VPPI_MASKED (by simp [vcpu.VPPI_MASKED]) (by simp [vcpu.VPPI_MASKED]) + have w := writesIn_wr (st := st) (s := s) (v := val) hx.1 + obtain ⟨b1, -, -, -, ea1, fl1, nd1, -⟩ := + Fl4ProofsA64.P1.blk_of_capw h w fun b e => by subst e; exact Or.inr ⟨hx.2.1, hx.2.2⟩ + have d : DFB st H Cs (L.curW s) ∅ (VcW Vc) s (L.wr s (wa v vcpu.VPPI_MASKED) val) := + DFB.ofBw (LvC.of_blk h) (w.mono fun b e => by + rw [e]; exact vcw_of hvc (by simp [vcpu.VPPI_MASKED]) (by simp [vcpu.VPPI_MASKED])) hWv + have hS := SysL.dfB Pz (BlkOK.bxi h) hrn (fun _ h => absurd h (Set.notMem_empty _)) + (fun b hb => (I.vty.w hb).2) (fun x hx b h1 h2 hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) B Y d + have f : WritesIn st s (L.wr s (wa v vcpu.VPPI_MASKED) val) (RunW st H Cs Vc OS s s) := + d.w.mono fun b hb => dfbv_runW hb + obtain ⟨-, tk, ak⟩ := ArmQIAt.ofRunW0 I B hks Pz.core0 h f hS b1 + have k := RunW.osk I h f + have st1 : ∀ y ∈ H.tcbs, L.mem (L.wr s (wa v vcpu.VPPI_MASKED) val) (stA y) = L.mem s (stA y) := + fun y hy => by rw [stA_eq]; exact fl1 y hy _ (by simp) (by simp) (by simp) + have ii1 : L.idleW (L.wr s (wa v vcpu.VPPI_MASKED) val) = L.idleW s := by + unfold LawfulStore.idleW; rw [LawfulStore.cpu_wr, nodeAt_wr] + exact nd1 _ q.cur _ (by rw [idle8]; omega) (by rw [idle8]) + refine ⟨⟨hS.1, hS.2, b1, XC.keep k tk, XV.keep ak k, + (RpW.start (Vc := Vc) (Ac := Ac) B Y h).xs.keep fun z hz => k.capA hz⟩, ?_, ?_, ?_⟩ + · exact hc.mrsc (by rw [inqA_eq]; exact fl1 _ hct _ (by simp) (by simp) (by simp)) (st1 _ hct) + (by rw [ea1]; exact hc.na) ii1 (Or.inl (by rw [scA_eq]; exact fl1 _ hct _ (by simp) (by simp) (by simp))) + · rw [st1 _ hct]; exact hrun + · exact hRV.keep st1 fun y hy => fl1 y hy 3672#u64 (by simp) (by simp) (by simp) + refine WP.spec_bind (Pₘ := fun s1 => RpW st H Cs OS Vc ia ie Ac s s1 ∧ + CanBlock st H.tcbs Ac s1 (L.curW s) ∧ L.mem s1 (stA (L.curW s)) ≠ sched.TS_INACTIVE ∧ + RunVcpuInv st H.tcbs s1) ?_ fun s1 hh => ?_ + · split + · simp only [lift, bind_ok, L.read_eq, L.write_eq] + exact (WP.spec_ok _).2 (VW _) + · exact (WP.spec_ok _).2 ⟨RpW.start B Y h, hc, hrun, hRV⟩ + · step with LawfulStore.cur_cpu_spec as ⟨c1, _⟩ + step with P0.layout.irq.of.p0 as ⟨i2⟩ + refine WP.spec_bind (hA.mask_irq a i2 true) fun a1 _ => ?_ + exact HF1 s1 a1 hh.1 hh.2.1 hh.2.2.1 hh.2.2.2 + · exact ok0 + +end top + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCKeep.lean b/proofs/Fl4ProofsA64/P1/S1aCKeep.lean new file mode 100644 index 000000000..37e8c3a80 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCKeep.lean @@ -0,0 +1,39 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1, c0): **the generic export of a cap-keeping arm or step**. + +A `decode_invocation` arm that keeps every capability slot exports +`ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` (the `*_armSAt` shape). `S1aStepR2K.ofKeep` turns that, with the entry +columns of `s1aStepR2K`, into `S1aStepR2K` at the end state. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aStepR2K + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + +/-- **A cap-keeping arm or step keeps the whole S1a step post.** -/ +theorem S1aStepR2K.ofKeep {s q : S} + (d : ArmQIAt st H Cs OS Vc ia ie s q ∧ TabKeepOrZero st s q ∧ ArmVsK st H OS Vc s q ∧ OSKeep st OS s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (fu : FrUb st Ub OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem, slots⟩ := d + have vs : VsKeep st (L.ksb s) Pt s q := mem.2 Ub Pt vr fu + have R' : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + R.ofImage mem.1 vs (.ofSame R.capRefs.refs fun _ hy => Or.inl (slots.capA hy)) + obtain ⟨Ub', hsub, hC, hK⟩ := (S1aColU.of arm.1 (S1aArmCol.ofTZ tab C)) + have kc' := S1aCapCol.ofOSK slots Kc + have col : S1aHiK st OS Kt KLv q := KC.keep ⟨EdgeKeepOn.ofVsKeep R vs, arm.hiRoots R.highHeaders⟩ + exact ⟨H, OS, Vc, Ub', Pt, ⟨arm.1, arm.2.1, hsub, arm.2.2.2.1 vcc, hC, hK, arm.ptCap R.pageTables, + arm.hvPt R.hvPt, R.footprint, arm.devFr Df, R'.highHeaders, arm.eptPlaced R.eptRoots, + arm.ptCap R.pageObjects, arm.hvObjects R.highObjects⟩, sep.keep slots, R'.ex, col⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCNScW.lean b/proofs/Fl4ProofsA64/P1/S1aCNScW.lean new file mode 100644 index 000000000..698861fc3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCNScW.lean @@ -0,0 +1,127 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a13), part 1): **node and SC words off the liveness words** (for +SchedControl ConfigureFlags: the remote reschedule, the reprogram flag, `commit_time`, the refills, the SC's core, +badge and sporadic words). + +* **`NScW p`**: a word of a core's node (not `DEBUG_TCBS`, not the current core's `IDLE_THREAD`) or a word of an SC + object that is no liveness word of an SC, but `p`'s `REFILL_MAX`. +* **`LvF.ofNSc`**: writing such words writes only `p`'s `REFILL_MAX` among the liveness words. +* **`DMD.ofNSc`**: such a step from a `BlkOK` state is a `DMD p` step. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCReplyT + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- **Node words and SC words off the liveness words** (module docstring). -/ +def NScW (st : machine.Store S) [L : LawfulStore st] (Cs Scs : Set U64) (Z : U64 → Nat) (p : U64) (s : S) + (b : U64) : Prop := + (∃ c ∈ Cs, ∃ o : U64, o.val < 4288 ∧ o.val % 8 = 0 ∧ o.val ≠ 88 ∧ (c = L.cpu s → o.val ≠ 8) ∧ + b = L.nodeAt s c o) ∨ + (∃ c ∈ Scs, InSC c (Z c) b ∧ ∀ o : U64, LvSO o.val → b = wa c o → c = p ∧ o.val = 72) + +theorem NScW.ksb {Scs : Set U64} {Z : U64 → Nat} {p : U64} {s0 s1 : S} {b : U64} (hk : L.ksb s1 = L.ksb s0) + (hc : L.cpu s1 = L.cpu s0) (h : NScW st Cs Scs Z p s1 b) : NScW st Cs Scs Z p s0 b := by + rcases h with ⟨c, hc', o, h1, h2, h3, h4, e⟩ | h + · exact Or.inl ⟨c, hc', o, h1, h2, h3, fun e' => h4 (e'.trans hc.symm), by rw [e, nodeAt_of_ksb hk]⟩ + · exact Or.inr h + +theorem NScW.trans {Scs : Set U64} {Z : U64 → Nat} {p : U64} {s1 s2 s3 : S} + (w1 : WritesIn st s1 s2 (NScW st Cs Scs Z p s1)) (w2 : WritesIn st s2 s3 (NScW st Cs Scs Z p s2)) : + WritesIn st s1 s3 (NScW st Cs Scs Z p s1) := + (w1.trans w2).mono fun _ hb => hb.elim id (NScW.ksb w1.1 w1.2.1) + +section atom +variable {T Ω Sg Rp Scs Nt : Set U64} {Z : U64 → Nat} {s : S} (C : LvC st T Cs Ω Sg Rp Scs Nt Z s) +include C + +/-- **Writing `NScW p` words writes only `p`'s `REFILL_MAX` among the liveness words.** -/ +theorem LvF.ofNSc {p : U64} {s' : S} (w : WritesIn st s s' (NScW st Cs Scs Z p s)) : + LvF st T Cs Rp Scs Nt (LvX.sc p 72) s s' := by + have scO : ∀ b, Aligned b → ∀ c ∈ Scs, InSC c (Z c) b → b ∈ Ω := fun b hb c hc h => C.obj.scW c hc b hb h + have nd : ∀ c ∈ Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → (o.val = 88 ∨ (o.val = 8 ∧ c = L.cpu s)) → + L.mem s' (L.nodeAt s' c o) = L.mem s (L.nodeAt s c o) := by + intro c hc o ho h8 h888 + rw [nodeAt_of_ksb w.1] + have hal := nodeAt_aligned (C.nodes c hc) ho h8 + refine w.mem_eq hal fun hb => ?_ + rcases hb with ⟨c', hc', o', ho', -, h88', h8', e⟩ | ⟨c', hc', hin, -⟩ + · refine node_ne_node (C.nodes c hc) (C.nodes c' hc') ho ho' (fun ec => ?_) (congrArg UScalar.val e) + rcases h888 with e1 | ⟨e1, ecpu⟩ + · omega + · have := h8' (ec.symm.trans ecpu); omega + · exact out_ne_node (C.om _ (scO _ hal c' hc' hin)) hc (C.nodes c hc) ho rfl + refine ⟨w.1, w.2.1, ?_, fun c hc => ?_, fun y hy K hK _ => ?_, fun c hc o hO hx => ?_, fun n hn o hO _ => ?_, + fun r hr o hO _ => ?_⟩ + · unfold LawfulStore.idleW; rw [w.2.1] + exact nd _ C.cur _ (by rw [idle8]; omega) (by rw [idle8]) (Or.inr ⟨idle8, rfl⟩) + · exact nd c hc _ (by rw [debug_val]; omega) (by rw [debug_val]) (Or.inl debug_val) + · have hal := C.al_t hy hK + refine w.mem_eq hal fun hb => ?_ + rcases hb with ⟨c', hc', o', ho', -, -, -, e⟩ | ⟨c', hc', hin, -⟩ + · exact node_ne_field (C.nodes c' hc') ho' hy (C.tcb y hy) hK.lt.1 e.symm + · exact out_ne_field (C.om _ (scO _ hal c' hc' hin)) hy (C.tcb y hy) hK.lt.1 rfl + · have hal : Aligned (wa c o) := (C.om _ (C.scO hc hO.lt.1 hO.lt.2)).1 + refine w.mem_eq hal fun hb => ?_ + rcases hb with ⟨c', hc', o', ho', -, -, -, e⟩ | ⟨c', hc', hin, hz⟩ + · exact out_ne_node (C.om _ (C.scO hc hO.lt.1 hO.lt.2)) hc' (C.nodes c' hc') ho' (congrArg UScalar.val e).symm + · by_cases e : c' = c + · subst e + obtain ⟨e1, e2⟩ := hz o hO rfl + exact hx ⟨e1, e2⟩ + · obtain ⟨hv, h128, -⟩ := C.scv hc hO.lt.1 + have := hO.lt; have := hin.1; have := hin.2 + rw [hv] at * + have := C.obj.scDisj c hc c' hc' (Ne.symm e); omega + · have hal : Aligned (wa n o) := (C.om _ (C.ntO hn hO)).1 + refine w.mem_eq hal fun hb => ?_ + rcases hb with ⟨c', hc', o', ho', -, -, -, e⟩ | ⟨c', hc', hin, -⟩ + · exact out_ne_node (C.om _ (C.ntO hn hO)) hc' (C.nodes c' hc') ho' (congrArg UScalar.val e).symm + · obtain ⟨hv, -⟩ := C.ntv hn hO.lt.1 + have := hO.lt; have := hin.1; have := hin.2; have := C.obj.ntOSc n hn c' hc' + rw [hv] at *; omega + · have hal : Aligned (wa r o) := (C.om _ (C.rpO hr hO.lt.1 hO.lt.2)).1 + refine w.mem_eq hal fun hb => ?_ + rcases hb with ⟨c', hc', o', ho', -, -, -, e⟩ | ⟨c', hc', hin, -⟩ + · exact out_ne_node (C.om _ (C.rpO hr hO.lt.1 hO.lt.2)) hc' (C.nodes c' hc') ho' (congrArg UScalar.val e).symm + · obtain ⟨hv, -⟩ := C.rpv hr hO.lt.1 + have := hO.lt; have := hin.1; have := hin.2; have := C.obj.rpSc r hr c' hc' + rw [hv] at *; omega + +end atom + +/-- **A `NScW p` step from a `BlkOK` state is a `DMD p` step.** -/ +theorem DMD.ofNSc {p : U64} {s s' : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (w : WritesIn st s s' (NScW st Cs H.scs H.scBits p s)) : DMD st H Cs p s s' := by + have C := LvC.of_blk h + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + have g : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.sc p 72) s s' := LvF.ofNSc C w + have f : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' := K8.Foot.d (w.mono fun b hb => by + rcases hb with ⟨c, hc, o, ho, -, h88, -, e⟩ | ⟨c, hc, hin, -⟩ + · exact Or.inr (Or.inl ⟨c, hc, o, ho, h88, e⟩) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨c, hc, hin⟩)))) + have Y' : SymL st H Cs s' := ⟨Y.dbg.lv hz g fun _ _ hk => (hk : False).elim, + Y.yld.lv hX.2.2.yt g (fun _ _ hk => (hk : False).elim) fun c k hk => by rw [hk.2]; decide⟩ + have V' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g (fun c k hk => by rw [hk.2]; decide) + (fun _ _ hk => hk) (BorK.of_lv g fun _ _ hk => (hk : False).elim) + refine DMD.ofK (E := fun q => q = p) h h0 Y Y' V' f + (LvK.ofLv g (fun _ _ e => (e : False).elim) (fun c k e => e.1) (fun _ _ e => (e : False).elim) + (fun _ e => (e : False).elim)) (fun q e => Or.inl e) (EpM.ofK (ep_keptX h w fun b _ hb => ?_)) g.idle + (g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => (e : False).elim) + rcases hb with ⟨c, hc, o, ho, -, -, -, e⟩ | ⟨c, hc, hin, -⟩ + · exact Or.inr (Or.inr (Or.inl ⟨c, hc, o, ho, s, rfl, e⟩)) + · exact Or.inl (h.2.2.1.1.scW c hc b (by assumption) hin) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCNtfnBind.lean b/proofs/Fl4ProofsA64/P1/S1aCNtfnBind.lean new file mode 100644 index 000000000..5cf44fa5e --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCNtfnBind.lean @@ -0,0 +1,211 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a6)): **TCB BindNotification keeps every capability** +(notification.rs `bind_notification`). + +* **`notification.bind_notification.dmE`**: the two writes (the notification's `BOUND_TCB`, the thread's + `BOUND_NTFN`) let only the thread and the notification become live. +* **`syscall.decode_invocation.bindN_armS`**: the stall, the lookup of the notification cap, the caller's restart, + then the bind. Both objects are named: the invoked slot and the extra cap's slot are in `OS`. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCDm2 +import Fl4ProofsA64.P1.MdbArmDm +import Fl4ProofsA64.P1.MdbSigL + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add + +/-- **`bind_notification`**, with its footprint and exact liveness frame. -/ +theorem notification.bind_notification.footL {s : S} (t n : U64) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (ht : t ∈ H.tcbs) + (hn : n ∈ H.ntfns) : + notification.bind_notification st s t n ⦃ s' => + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ∧ + LvF st H.tcbs Cs H.replies H.scs H.ntfns ((LvX.nt n 24).u (LvX.tc t 3368)) s s' ⦄ := by + have C := LvC.of_blk h + have hT := h.1.choose_spec.choose_spec.tcbs + have hm : ntfnBtA n ∈ H.frame := (h.2.2.1.1.ntB n hn).2 + unfold notification.bind_notification + refine WP.spec_bind (obj.Ntfn.set_bound_tcb.wr s n t) fun s1 e1 => ?_ + subst e1 + have f1 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s (L.wr s (ntfnBtA n) t) := + K8.foot_wr (h.1.choose_spec.choose_spec.omega _ (h.2.2.2.2.sub _ hm)).1 (K8.kw_sg hm) + have g1 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.nt n 24) s (L.wr s (ntfnBtA n) t) := + LvF.wrN C hn (o0 := layout.ntfn.BOUND_TCB) (v := t) (by simp [layout.ntfn.BOUND_TCB]) + (C.ntO hn (by unfold LvNO; simp [layout.ntfn.BOUND_TCB])) (by simp [layout.ntfn.BOUND_TCB]) + refine WP.spec_mono (obj.Tcb.set_bound_ntfn.wr _ t n) fun s2 e2 => ?_ + subst e2 + exact ⟨f1.trans (K8.foot_field (K := 3368#u64) hT ht (by simp) (by simp) (by simp) (by simp)), + g1.trans (LvF.wrT (C.wr _ _) ht (K0 := 3368#u64) (v := n) (by simp) (by simp) (j := 3368) (by simp))⟩ + +set_option maxHeartbeats 1000000 in +/-- **`bind_notification t n`** lets only `t` and `n` become live. -/ +theorem notification.bind_notification.dmE {s : S} (t n : U64) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (ht : t ∈ H.tcbs) + (hn : n ∈ H.ntfns) (h0t : L.mem s (boundA t) = 0#u64) (h0n : L.mem s (ntfnBtA n) = 0#u64) + (h0 : H 0#u64 = none) (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + notification.bind_notification st s t n ⦃ s' => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ∧ DME st H Cs (fun q => q = t ∨ q = n) s s' ⦄ := by + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + refine WP.spec_mono (WP.spec_and (notification.bind_notification.blk s t n h ht hn h0t h0n) + (notification.bind_notification.footL t n h ht hn)) ?_ + rintro s' ⟨h', f, g⟩ + have V' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g + (fun c k hk => by simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk) + (fun r k hk => by simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk) + (BorK.of_lv g fun y k hk => by rintro rfl; simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk) + have Y' : YieldS st H.tcbs H.scs s' := Y.yld.lv hX.2.2.yt g + (fun y k hk => by rintro rfl; simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk) + (fun c k hk => by rintro rfl; simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk) + have D' := Y.dbg.lv hz g fun y k hk => by + refine ⟨?_, ?_, ?_⟩ <;> rintro rfl <;> simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at hk + have Ys : SymL st H Cs s' := ⟨D', Y'⟩ + have Kk : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = t ∨ q = n) s s' := + LvK.ofLv g (fun y k e => by rcases e with e | e; exact (e : False).elim; exact Or.inl e.1) + (fun c k e => by rcases e with e | e <;> exact (e : False).elim) + (fun m k e => by + rcases e with e | e + · exact Or.inr e.1 + · exact (e : False).elim) + (fun r e => by rcases e with e | e <;> exact (e : False).elim) + have M := EpM.ofK (ep_kept_kw h f) + refine ⟨h', f, K8.Foot.d (WritesIn.mono f fun _ hb => kw8_es hb), + LvM.ofNzX (NzX.ofLvK Kk (fun e he _ => M.1 e he) (fun m hm _ => M.2 m hm)) Y Ys hz h0, g.idle, ?_, V', Ys⟩ + rw [g.idle] + exact g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by simp [LvX.u, LvX.tc, LvX.nt, LvX.none] at e + +/-- **`decode_bind_notification` after the stall**: `SysL ∧ SymL`, `BlkOK` and the `DmW` frame. -/ +theorem tcb.decode.bindNLK (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} + {slot : obj.Slot} {extra : Aeneas.Std.Array obj.Slot 3#usize} {Rp Nt Pt' Vc' Ub' : Set U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') + (hSA : ScApart H.scs H.scBits OS) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (hl : lbl = fl4_abi.label.TCBBindNotification) : + tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + DmPost st H Cs OS ia ie Ac s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.stS hA a t D.bxi) ?_ + rintro ⟨s1, a1⟩ ⟨h1, d1⟩ + try simp only [uncurry_apply_pair] + iterate 15 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBBindNotification, fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, fl4_abi.label.TCBGetBreakpoint, fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, fl4_abi.label.TCBWriteFPU, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + have E1 : DmPost st H Cs OS ia ie Ac s s1 := + DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + h1.bxi.blk (DmW.ofDF d1) + refine WP.spec_bind (Pₘ := fun r : (core.result.Result Unit error.Exc) × S => + DmPost st H Cs OS ia ie Ac s r.2) ?_ ?_ + swap + · rintro ⟨r, s2⟩ hr + exact (WP.spec_ok _).2 hr + unfold tcb.decode_bind_notification + refine WP.spec_bind (tcb.extra_with_length.mem _ 0#u64) ?_ + rintro r ⟨-, hx⟩ + rcases r with x | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 E1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨hxm, hx0⟩ := hx x rfl + refine WP.spec_bind (obj.Tcb.bound_ntfn.val s1 t) fun i ei => ?_ + split + · simp only [error.illegal, bind_ok] + exact (WP.spec_ok _).2 E1 + rename_i hi + have hb0 : L.mem s1 (boundA t) = 0#u64 := by rw [← ei]; exact UScalar.eq_of_val_eq (by simpa using hi) + refine WP.spec_bind (Pₘ := fun r : core.result.Result obj.Ntfn error.Exc => + ∀ n, r = .Ok n → n ∈ H.ntfns ∧ L.mem s1 (ntfnBtA n) = 0#u64 ∧ + ∃ b sd rv, capA st s1 x = .Notification n b sd rv) ?_ ?_ + · unfold tcb.bindable_ntfn + refine WP.spec_bind (WP.spec_and (D.extra s1 h1.node x hxm hx0) + (show obj.Slot.cap st x s1 ⦃ c => c = capA st s1 x ⦄ by rw [capA_eq]; exact (WP.spec_ok _).2 rfl)) + fun c ⟨hc, ec⟩ => ?_ + have H1 : ∀ p b y z, c = .Notification p b y z → p ∈ H.ntfns := fun p b y z e => (hc.1.2.1 p b y z e).1 + have H2 : ∀ p b y z, c = .Notification p b y z → ∃ b sd rv, capA st s1 x = .Notification p b sd rv := + fun p b y z e => ⟨b, y, z, ec.symm.trans e⟩ + clear hc ec + cases c <;> dsimp only + all_goals first | (simp [error.illegal, WP.spec_ok]; done) | skip + split + · refine WP.spec_bind (P0.obj.Ntfn.head.p0 st _ s1 hS) fun _ _ => ?_ + split + · simp [error.illegal, WP.spec_ok] + · refine WP.spec_bind (obj.Ntfn.bound_tcb.val s1 _) fun j ej => ?_ + split + · simp [error.illegal, WP.spec_ok] + · rename_i hj + exact (WP.spec_ok _).2 fun n' e => by + cases e + exact ⟨H1 _ _ _ _ rfl, by rw [← ej]; exact UScalar.eq_of_val_eq (by simpa using hj), H2 _ _ _ _ rfl⟩ + · simp [error.illegal, WP.spec_ok] + rintro r hr + rcases r with n | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 E1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨hn, hn0, bb, sd, rv, hcx⟩ := hr n rfl + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.restartRK D P B Y h1 d1) (h1.restart D)) + fun s2 ⟨⟨R, d2⟩, _, _, _, k⟩ => ?_ + have hb2 : L.mem s2 (boundA t) = 0#u64 := by rw [k.bndf ht]; exact hb0 + have hn2 : L.mem s2 (ntfnBtA n) = 0#u64 := by rw [k.ntb _ hn]; exact hn0 + refine WP.spec_bind (notification.bind_notification.dmE t n R.blk ht hn hb2 hn2 B.ly.h0 R.sys.vr R.sym) + fun s3 ⟨h3, f3, d3⟩ => ?_ + have hxO : x ∈ OS := P.ext x hxm hx0 + have kO1 : OSKeep st OS s s1 := (DF.osTab P.heap P.os D.bxi B hvr P.core0 d1).1 + have kO2 : OSKeep st OS s s2 := (DF.osTab P.heap P.os D.bxi B hvr P.core0 d2).1 + have named : ∀ q k', (q = t ∨ q = n) → H q = some k' → ∃ y ∈ OS, NamesA (capA st s2 y) q k' := by + rintro q k' (rfl | rfl) hq + · exact R.namedT hcap ht k' hq + · have e : H q = some .ntfn := hn + rw [e] at hq; cases hq + refine ⟨x, hxO, ?_⟩ + rw [kO2.capA hxO, ← kO1.capA hxO, hcx] + exact names_ntfn + exact (WP.spec_ok _).2 (DmPost.mk' (SysL.dfE R.pl.heap R.pl.os R.blk.bxi.blk hSA named R.sys d3) h3 + (DmW.trans (DmW.ofDF d2) (WritesIn.mono f3 fun _ hb => Or.inr (kw8_es hb)))) + +/-- **TCB BindNotification** keeps every capability. -/ +theorem syscall.decode_invocation.bindN_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBBindNotification) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono (tcb.decode.bindNLK hA D P B Y I.del.vr hSA hcap hl) fun r d => by + obtain ⟨_, s', a'⟩ := r + have x := ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk + exact ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCRecv.lean b/proofs/Fl4ProofsA64/P1/S1aCRecv.lean new file mode 100644 index 000000000..2f1abd294 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCRecv.lean @@ -0,0 +1,1422 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c4): **the receive side** (`handle_recv`) to the S1a step post (frozen D4: +one theorem per kernel function, from per-state premises). + +* **The blocking wait** (`wait_for_sender`): **`wait_for_sender.lvw`** (three segments, each by an existing frame: + the thread's fields and `schedule_tcb` by MdbSendB's `SBW.frame` / `SBW.kw8`, the reply's `TCB` word by MdbLiveF's + `LvF.wrR`, `ep_append` by `SBW.frame`) and **`wait_for_sender.dmE`** (a `DME {e, reply}` step to a `BlkOK` state); + **`RpW.dmeK`** / **`SW.dme`**: a `DME E` step keeps the walk bundles when every object of `E` is named (S1aCDm2's + `SysL.dfE`). +* **The notification side**: `SBW.frameN` / `SBW.kw8N` (the frames for a notification), **`maybe_return_sched_context.dmd`**, + **`ntfn_wait.dmd`**, **`receive_signal.activeD`**, **`complete_signal.dmd`** and **`receive_signal.sw`**. +* **The endpoint side**: **`endpoint.ep_dequeue.sysLS`** (a sending endpoint's head dequeued), **`receive_from_sender.rpw`** + (the transfer by MdbXferQ's `do_ipc_transfer.xjS`, `unblock_sporadic`, then the sender's `reply_push` / stop / wake), + **`take_reply.sw`** (`cancel_ipc.dmdC` of the reply's thread) and **`receive_ipc.rpw`** (QueueIpc's + `receive_ipc.inv_rp` walk); helpers `names_reply`, `XferSlots.keepCap`. +* **`cspace.lookup_cap.os`**: a looked-up cap is an `OS` slot's cap, typed by its `SlotTy`; **`syscall.handle_recv.s1a`**: + `receive_ipc.rpw`, `receive_signal.sw` or the cap fault (`handle_fault.rpw`), closed by `S1aStepR2K.ofRpPost`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5); [J] `hvm` (the receiver is not in +`TS_RUNNING_VM`, contract §5's `nvm`); [J] `h3` (every heap notification's state is not `3`; producer: QueueEntryA's +`recvOK`, as QueueXferA's `handle_recv.bxiA`). +-/ +import Fl4ProofsA64.P1.S1aCYield + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "BX" Xq "," s => BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s + +/-- **A `DME E` step keeps the Reply-walk bundle** (`RpW.dmdK` with S1aCDm2's `SysL.dfE`). -/ +theorem RpW.dmeK {Vc' Ub' Pt' : Set U64} {E : U64 → Prop} {s0 s s' : S} (R : RpW st H Cs OS Vc ia ie Ac s0 s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s0) Pt') (hks : HeapKsOff H (L.ksb s0)) + (hp : ∀ q k, E q → H q = some k → ∃ x ∈ OS, NamesA (capA st s x) q k) + (d : DME st H Cs E s s') (b : BK s') : RpW st H Cs OS Vc ia ie Ac s0 s' ∧ OSKeep st OS s s' := by + obtain ⟨Q, Rq, q⟩ := R.blk.1 + have hvr' : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt' := by rw [R.ksb]; exact hvr + have hks' : HeapKsOff H (L.ksb s) := by rw [R.ksb]; exact hks + obtain ⟨k, t, v⟩ := FootD.oskTabV (Vc := Vc) hH hO hSA hvr' hks' R.sys.ly.ksw hc0 q R.blk.2.2.2.2.sub + (fun e he => he) d.w + obtain ⟨S', Y'⟩ := SysL.dfE (Xq := ∅) hH hO R.blk hSA hp R.sys d + exact ⟨⟨S', Y', b, R.xc.trans (XC.keep k t), R.xv.trans (XV.keep v k), R.xs.keep fun z hz => k.capA hz⟩, k⟩ + +/-- **A `DME E` step keeps the walk bundle `SW`.** -/ +theorem SW.dme {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} {E : U64 → Prop} {s0 s s' : S} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hp : ∀ q k, E q → H q = some k → ∃ x ∈ OS, NamesA (capA st s x) q k) + (d : DME st H Cs E s s') (b : BK s') : SW st H Cs OS Vc ia ie Ac s0 s' := + have R := W.1.dmeK I.del.heap I.del.os I.del.sca hc0 I.del.vr hks hp d b + have h := W.1.blk + ⟨R.1, W.2.1.trans' R.2, W.2.2.trans (VKeep.of_kwd8 I.del.os I.del.vc I.del.sca h.1.choose_spec.choose_spec + h.2.2.1.1 h.2.2.2.2.sub (fun _ he => he) (I.vty.keep W.2.2) d.w)⟩ + +/-- The liveness words `wait_for_sender` may write: the thread's `STATE`, the reply's `TCB`. -/ +def WfX (t r : U64) : LvX := (LvX.tc t 3328).u (LvX.rp r 0) + +set_option maxHeartbeats 16000000 in +/-- **`wait_for_sender`'s frames** (module docstring). -/ +theorem wait_for_sender.lvw {s : S} (t e reply : U64) (h : BK s) (hc : CanBlock st H.tcbs Ac s t) + (hH : H e = some .ep) (hr : reply ≠ 0#u64 → reply ∈ H.replies) : + endpoint.wait_for_sender st s t e true reply ⦃ s' => + LvF st H.tcbs Cs H.replies H.scs H.ntfns (WfX t reply) s s' ∧ + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' ∧ + ∀ e', (H e' = some .ep ∨ H e' = some .ntfn) → e' ≠ e → L.mem s' (epTSA e') = L.mem s (epTSA e') ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have C := LvC.of_blk h + have ht := hc.mem + have hta := q.tcbs t ht + have hN := q.nodes _ q.cur + obtain ⟨E, EQ, hEW⟩ := q.eps + have heE : e ∈ E := (hEW.2.2.2.2.2.2.2.1 e).2 (Or.inl hH) + obtain ⟨hE, -, hq⟩ := hEW.1 e heE + have hn : t ∉ EQ e := fun hm => hc.nb (hEW.2.2.2.1 e heE t hm).2.2 + have hW : ∀ w ∈ t :: EQ e, w ∈ H.tcbs := fun w hw => by + rcases List.mem_cons.1 hw with rfl | hw + · exact ht + · exact hq.mem w hw + have hrΩ : reply ≠ 0#u64 → rTcbA reply ∈ H.omega := fun h0 => hSg.sub _ (hX.1.tcbW (hr h0)) + unfold endpoint.wait_for_sender + simp only [↓reduceIte] + step with obj.Tcb.set_state.spec as ⟨s1, e1⟩ + step with obj.Tcb.set_block_obj.wr as ⟨s2, e2⟩ + step with obj.Tcb.set_reply_obj.wr as ⟨s3, e3⟩ + have h1 : SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s1 Q R := by + rw [e1]; exact blk_set_state q hc + have h2 : SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s2 Q R := by + rw [e2]; exact inv_wr_fieldX (K := 3336#u64) h1 ht (Or.inr rfl) (by simp) (by simp) (by simp) + have h3 : SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s3 Q R := by + rw [e3]; exact inv_wr_fieldX (K := 3360#u64) h2 ht (Or.inr rfl) (by simp) (by simp) (by simp) + rw [stA_eq] at e1 + have w3 : ∀ r0 : U64, WritesIn st s s3 (BlkFoot st s t r0) := fun r0 => by + rw [e3, e2, e1] + exact blk_wr_field (K := 3360#u64) hta (blk_wr_field hta (blk_wr_field hta (WritesIn.refl _ _) (by simp)) + (by simp)) (by simp) + have v3 : L.mem s3 (stA t) = sched.TS_BLOCKED_ON_RECV := by + rw [e3, fld_wr_ne' (K := 3360#u64) (a := replyA t) hta rfl (stA_eq t) (by simp) (by simp) (by simp) (by simp) + (by simp), e2, fld_wr_ne' hta (blockA_eq t) (stA_eq t) (by simp) (by simp) (by simp) (by simp) (by simp), e1, + stA_eq] + exact L.mem_wr_same (field_aligned hta (by simp) (by simp)) + have a3 : L.actionW s3 = L.actionW s := by + rw [e3, act_wr_field (K := 3360#u64) (a := replyA t) (h2.nodes _ h2.cur) ht hta rfl (by simp) (by simp), + e2, act_wr_field (h1.nodes _ h1.cur) ht hta (blockA_eq t) (by simp) (by simp), + e1, act_wr_field hN ht hta rfl (by simp) (by simp)] + refine WP.spec_bind (sched.schedule_tcb.blk s3 t h3 (by rw [v3]; exact blocked_not_runnable (Or.inr (Or.inl rfl)))) + ?_ + rintro s4 ⟨h4, e4, -⟩ + have w4 : ∀ r0 : U64, WritesIn st s s4 (BlkFoot st s t r0) := fun r0 => (blk_sched h3 ht (w3 r0) a3 e4).1 + -- the first segment + obtain ⟨g1, k1⟩ := SBW.frame (W := []) q C ht (fun _ h => (List.not_mem_nil h).elim) hH + ((w4 0#u64).mono fun _ hb => Or.inl hb) + have f1 := SBW.kw8 (W := []) q ht (fun _ h => (List.not_mem_nil h).elim) hH ((w4 0#u64).mono fun _ hb => Or.inl hb) + -- the last segment, from a state `s6` after the first or the reply's word + have tail : ∀ s6 : S, SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s6 Q R → + WritesIn st s s6 (BlkFoot st s t reply) → + LvF st H.tcbs Cs H.replies H.scs H.ntfns (WfX t reply) s s6 → + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s6 → + (∀ e', (H e' = some .ep ∨ H e' = some .ntfn) → e' ≠ e → L.mem s6 (epTSA e') = L.mem s (epTSA e')) → + endpoint.ep_append st s6 e t obj.EP_RECV ⦃ s' => + LvF st H.tcbs Cs H.replies H.scs H.ntfns (WfX t reply) s s' ∧ + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' ∧ + ∀ e', (H e' = some .ep ∨ H e' = some .ntfn) → e' ≠ e → L.mem s' (epTSA e') = L.mem s (epTSA e') ⦄ := by + intro s6 h6 w6 g6 f6 k6 + obtain ⟨kf, -, -, ke⟩ := blkfoot_keep q hEW ht hrΩ w6 + have hqe : L.epQ s6 e = L.epQ s e := by simp only [LawfulStore.epQ, (ke e heE).1, (ke e heE).2] + have hq6 : QueueRel (L.mem s6) H.tcbs .Ep (L.epQ s6 e) (EQ e) := + ⟨hq.nodup, hq.mem, by rw [hqe]; exact hq.head, by rw [hqe]; exact hq.last, hq.seg.congr fun y hy => + ⟨kf y (hq.mem y hy) (prevOff .Ep) (by simp [prevOff]) (by simp [prevOff]) (fun _ => by simp [prevOff]), + kf y (hq.mem y hy) (nextOff .Ep) (by simp [nextOff]) (by simp [nextOff]) (fun _ => by simp [nextOff])⟩⟩ + have C6 := C.of_ksb g6.ksb g6.cpu + refine WP.spec_mono (endpoint.ep_append.foot s6 e t obj.EP_RECV (EQ e) q.tcbs hE hq6 ht hn) fun s' w' => ?_ + have w'' : WritesIn st s6 s' (SBW st s6 t e (t :: EQ e)) := w'.mono fun _ hb => Or.inr hb + obtain ⟨g', k'⟩ := SBW.frame h6 C6 ht hW hH w'' + refine ⟨(g6.trans g').mono (by refine ⟨?_, ?_, ?_, ?_⟩ <;> intro a k hk <;> simp_all [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none]), f6.trans (SBW.kw8 h6 ht hW hH w''), fun e' he' hne => ?_⟩ + rw [k' e' he' hne, k6 e' he' hne] + split + · rename_i hne + have h0 : reply ≠ 0#u64 := by simpa using hne + have hrp := hr h0 + have hm : rTcbA reply ∈ H.omega := hrΩ h0 + step with obj.Reply.set_tcb.spec as ⟨s6, e6⟩ + try simp only [Aeneas.Std.bind_ok] + obtain ⟨h6, -, -⟩ := omega_wr (v := t) h4 hm + rw [← e6] at h6 + have C4 := C.of_ksb g1.ksb g1.cpu + have g2 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.rp reply 0) s4 s6 := by + rw [e6]; exact LvF.wrR C4 hrp (o0 := layout.reply.TCB) (by simp [layout.reply.TCB]) + (by simp [layout.reply.TCB]) (by simp [layout.reply.TCB]) + have al : Aligned (rTcbA reply) := (h4.omega _ hm).1 + have f2 : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s4 s6 := by + rw [e6]; exact (writesIn_wr al).mono fun b hb => by + subst hb; exact Or.inl (Or.inr (Or.inr (Or.inl (hX.1.tcbW hrp)))) + have k2 : ∀ e', (H e' = some .ep ∨ H e' = some .ntfn) → L.mem s6 (epTSA e') = L.mem s4 (epTSA e') := by + intro e' he' + have he'E : e' ∈ E := (hEW.2.2.2.2.2.2.2.1 e').2 he' + obtain ⟨hP', -, -⟩ := hEW.1 e' he'E + rw [e6] + refine L.mem_wr_ne al (ep_aligned hP').2 fun hv => ?_ + rcases hEW.2.2.1 e' he'E _ hm with g | g <;> rw [epTSA_val hP'] at hv <;> omega + exact tail s6 h6 (by rw [e6]; exact blk_wr_reply al h0 (w4 reply)) + ((g1.trans g2).mono (by refine ⟨?_, ?_, ?_, ?_⟩ <;> intro a k hk <;> simp_all [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none])) + (f1.trans f2) fun e' he' hne => (k2 e' he').trans (k1 e' he' hne) + · rename_i hne + have h0 : reply = 0#u64 := by simp only [bne_iff_ne, ne_eq, Decidable.not_not] at hne; exact hne + try simp only [Aeneas.Std.bind_ok] + exact tail s4 h4 (w4 reply) (g1.mono (by refine ⟨?_, ?_, ?_, ?_⟩ <;> intro a k hk <;> simp_all [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none])) f1 k1 + +set_option maxHeartbeats 16000000 in +/-- **The blocking receive's wait is a `DME {e, reply}` step** (module docstring). -/ +theorem wait_for_sender.dmE {s : S} (t e reply : U64) (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (hc : CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) + (hH : H e = some .ep) (hst0 : L.epState s e = 0#u64 ∨ L.epState s e = 2#u64) + (hr : reply ≠ 0#u64 → reply ∈ H.replies ∧ (L.mem s (rTcbA reply) = 0#u64 ∨ L.mem s (rTcbA reply) = t)) : + endpoint.wait_for_sender st s t e true reply ⦃ s' => + (BK s') ∧ DME st H Cs (fun q => q = e ∨ q = reply) s s' ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have ht := hc.mem + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := q.idleT + refine WP.spec_mono (WP.spec_and (endpoint.wait_for_sender.inv s t e true reply Q R q hB hX hS hSg ht (fun _ => hc) + hH hst0 hr) (wait_for_sender.lvw t e reply h hc hH fun h0 => (hr h0).1)) ?_ + rintro s' ⟨⟨q', hB', hX', hS', hSg'⟩, g, f, kE⟩ + have Xt : ∀ y k, (WfX t reply).t y k → y = t ∧ k = 3328 := fun y k hk => by + simpa [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none] using hk + have Xr : ∀ r k, (WfX t reply).r r k → r = reply ∧ k = 0 := fun r k hk => by + simpa [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none] using hk + have Xc : ∀ c k, ¬ (WfX t reply).c c k := fun c k hk => by simp [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none] at hk + have Xn : ∀ c k, ¬ (WfX t reply).n c k := fun c k hk => by simp [WfX, LvX.u, LvX.tc, LvX.rp, LvX.none] at hk + have Y' : SymL st H Cs s' := ⟨Y.dbg.lv hz g fun y k hk => by + obtain ⟨-, rfl⟩ := Xt y k hk; exact ⟨by omega, by omega, by omega⟩, + Y.yld.lv hX.2.2.yt g (fun y k hk => by obtain ⟨-, rfl⟩ := Xt y k hk; omega) + (fun c k hk => (Xc c k hk).elim)⟩ + have bk : BorK st H.tcbs s s' := BorK.of_eq t hc.nrp fun z hz hzt => by + rw [stA_eq]; exact g.t z hz 3328#u64 (by unfold LvO; simp) fun hk => hzt (Xt _ _ hk).1 + have VR' : ValidReplies st H s' := VR.tr (RKeep.same hX.2.1.toReplyInv0 + (fun c hc' => g.c c hc' _ (by unfold LvSO; simp [layout.sc.REPLY]) (Xc _ _)) + (fun r hr' => g.r r hr' _ (by unfold LvRO; simp [layout.reply.NEXT]) fun hk => by + have := (Xr _ _ hk).2; simp [layout.reply.NEXT] at this) + (fun r hr' => g.r r hr' _ (by unfold LvRO; simp [layout.reply.PREV]) fun hk => by + have := (Xr _ _ hk).2; simp [layout.reply.PREV] at this) + fun r hr' _ hb => by + by_cases hre : r = reply + · subst hre + exfalso + have hn0 : r ≠ 0#u64 := ne0_of_heap h0 hr' + rcases (hr hn0).2 with e0 | et + · exact hb.tcb e0 + · have := hb.blk; rw [et] at this; exact hc.nrp this + · exact hb.keep hX.2.1.toReplyInv0 hr' (g.r r hr' _ (by unfold LvRO; simp [layout.reply.TCB]) + fun hk => hre (Xr _ _ hk).1) bk) + have Kk : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = e ∨ q = reply ∨ q = t) s s' := + LvK.ofLv g (fun y k hk => Or.inr (Or.inr (Xt y k hk).1)) (fun c k hk => (Xc c k hk).elim) + (fun n k hk => (Xn n k hk).elim) (fun r hk => Or.inr (Or.inl (Xr r 0 hk).1)) + have lvE := LvM.ofNzX (NzX.ofLvK Kk + (fun e' he' hE hs => by + unfold LawfulStore.epState at hs ⊢ + rwa [kE e' (Or.inl he') fun h' => hE (Or.inl h')] at hs) + (fun n hn hE hs => by + unfold LawfulStore.epState at hs ⊢ + rwa [kE n (Or.inr hn) fun h' => hE (Or.inl h')] at hs)) Y Y' hz h0 + refine ⟨⟨⟨Q, R, q'⟩, hB', hX', hS', hSg'⟩, f, fun z hz hl => ?_, g.idle, ?_, VR', Y'⟩ + · by_cases hzt : z = t + · subst hzt; exact LiveQ.tcb ht (Or.inl hrun) + · exact lvE z (by rintro (h' | h' | h'); exact hz (Or.inl h'); exact hz (Or.inr h'); exact hzt h') hl + · rw [g.idle] + exact g.t _ hI 3464#u64 (by unfold LvO; simp) fun hk => by have := (Xt _ _ hk).2; simp at this + +section frameN +variable {X : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s : S} {t e : U64} {W : List U64} + +set_option maxHeartbeats 2000000 in +/-- (`SBW.frame` for an endpoint or a notification.) **An `SBW` step writes only the sender's `STATE` among the liveness words and keeps every other endpoint's / +notification's state word** (module docstring). -/ +theorem SBW.frameN (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q R) + (C : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s) (ht : t ∈ H.tcbs) + (hW : ∀ w ∈ W, w ∈ H.tcbs) (hH : H e = some .ep ∨ H e = some .ntfn) {s' : S} (w : WritesIn st s s' (SBW st s t e W)) : + LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.tc t 3328) s s' ∧ + ∀ e', (H e' = some .ep ∨ H e' = some .ntfn) → e' ≠ e → L.mem s' (epTSA e') = L.mem s (epTSA e') := by + have hT := q.tcbs + have hN := q.nodes _ q.cur + have hta := hT t ht + obtain ⟨E, EQ, hEW⟩ := q.eps + have heE : e ∈ E := (hEW.2.2.2.2.2.2.2.1 e).2 hH + obtain ⟨hP, hon, -⟩ := hEW.1 e heE + have ha8 : layout.node.SCHED_ACTION.val < 4288 := by rw [act_val]; omega + -- an `Ω` word + have nO : ∀ a ∈ H.omega, ¬ SBW st s t e W a := by + intro a ha hb + have ho := q.omega a ha + rcases hb with (⟨K, hK, e1⟩ | e1 | ⟨h0, -⟩) | (⟨y, hy, e1 | e1⟩ | e1 | e1) + · exact out_ne_field ho ht hta (by omega) (congrArg UScalar.val e1).symm + · exact out_ne_node ho q.cur hN ha8 (congrArg UScalar.val e1).symm + · exact h0 rfl + · rw [nextA_eq'] at e1 + exact out_ne_field ho (hW y hy) (hT y (hW y hy)) (by simp [nextOff]) (congrArg UScalar.val e1).symm + · rw [prevA_eq'] at e1 + exact out_ne_field ho (hW y hy) (hT y (hW y hy)) (by simp [prevOff]) (congrArg UScalar.val e1).symm + · have v := congrArg UScalar.val e1; rw [epHeadA_val] at v + rcases hEW.2.2.1 e heE a ha with g | g <;> omega + · have v := congrArg UScalar.val e1; rw [epTSA_val hP] at v + rcases hEW.2.2.1 e heE a ha with g | g <;> omega + -- a liveness field other than the sender's `STATE` + have nF : ∀ y ∈ H.tcbs, ∀ K : U64, LvO K.val → ¬ (y = t ∧ K.val = 3328) → ¬ SBW st s t e W (wa y K) := by + intro y hy K hK hx hb + have hKl := hK.lt.1 + rcases hb with (⟨K', hK', e1⟩ | e1 | ⟨h0, -⟩) | (⟨w', hw, e1 | e1⟩ | e1 | e1) + · exact field_ne (hT y hy) hta hKl (by omega) (fun ey eK => hx ⟨ey, by unfold LvO at hK; omega⟩) e1 + · exact node_ne_field hN ha8 hy (hT y hy) hKl e1.symm + · exact h0 rfl + · rw [nextA_eq'] at e1 + exact field_ne (hT y hy) (hT w' (hW w' hw)) hKl (by simp [nextOff]) + (fun _ eK => by unfold LvO at hK; simp [nextOff] at eK; omega) e1 + · rw [prevA_eq'] at e1 + exact field_ne (hT y hy) (hT w' (hW w' hw)) hKl (by simp [prevOff]) + (fun _ eK => by unfold LvO at hK; simp [prevOff] at eK; omega) e1 + · have v := congrArg UScalar.val e1; rw [field_val (hT y hy) hKl, epHeadA_val] at v + rcases hP.disj y hy with g | g <;> omega + · have v := congrArg UScalar.val e1; rw [field_val (hT y hy) hKl, epTSA_val hP] at v + rcases hP.disj y hy with g | g <;> omega + -- the idle and debug node words + have nN : ∀ c ∈ Cs, ∀ o : U64, o.val < 4288 → (o.val = 8 ∨ o.val = 88) → ¬ SBW st s t e W (L.nodeAt s c o) := by + intro c hc o ho ho8 hb + have hNc := q.nodes c hc + rcases hb with (⟨K', hK', e1⟩ | e1 | ⟨h0, -⟩) | (⟨w', hw, e1 | e1⟩ | e1 | e1) + · exact node_ne_field hNc ho ht hta (by omega) e1 + · exact node_ne_node hNc hN ho ha8 (fun _ => by rw [act_val]; omega) (congrArg UScalar.val e1) + · exact h0 rfl + · rw [nextA_eq'] at e1 + exact node_ne_field hNc ho (hW w' hw) (hT w' (hW w' hw)) (by simp [nextOff]) e1 + · rw [prevA_eq'] at e1 + exact node_ne_field hNc ho (hW w' hw) (hT w' (hW w' hw)) (by simp [prevOff]) e1 + · have v := congrArg UScalar.val e1; rw [nodeAt_val hNc ho, epHeadA_val] at v + rcases hon.1 c hc with g | g <;> omega + · have v := congrArg UScalar.val e1; rw [nodeAt_val hNc ho, epTSA_val hP] at v + rcases hon.1 c hc with g | g <;> omega + refine ⟨⟨w.1, w.2.1, ?_, fun c hc => ?_, fun y hy K hK hx => w.mem_eq (C.al_t hy hK) (nF y hy K hK hx), + fun c hc o hO _ => w.mem_eq (C.al_c hc hO) (nO _ (C.scO hc hO.lt.1 hO.lt.2)), + fun n hn o hO _ => w.mem_eq (C.al_n hn hO) (nO _ (C.ntO hn hO)), + fun r hr o hO _ => w.mem_eq (C.al_r hr hO) (nO _ (C.rpO hr hO.lt.1 hO.lt.2))⟩, fun e' he' hne => ?_⟩ + · unfold LawfulStore.idleW + rw [w.2.1, nodeAt_of_ksb w.1] + exact w.mem_eq (nodeAt_aligned hN (by rw [idle8]; omega) (by rw [idle8])) + (nN _ q.cur _ (by rw [idle8]; omega) (Or.inl idle8)) + · rw [nodeAt_of_ksb w.1] + exact w.mem_eq (nodeAt_aligned (q.nodes c hc) (by rw [debug_val]; omega) (by rw [debug_val])) + (nN c hc _ (by rw [debug_val]; omega) (Or.inr debug_val)) + · have he'E : e' ∈ E := (hEW.2.2.2.2.2.2.2.1 e').2 he' + obtain ⟨hP', hon', -⟩ := hEW.1 e' he'E + have dj := hEW.2.1 e heE e' he'E (Ne.symm hne) + refine w.mem_eq (ep_aligned hP').2 fun hb => ?_ + rcases hb with (⟨K', hK', e1⟩ | e1 | ⟨h0, -⟩) | (⟨w', hw, e1 | e1⟩ | e1 | e1) + · have v := congrArg UScalar.val e1; rw [field_val hta (by omega), epTSA_val hP'] at v + rcases hP'.disj t ht with g | g <;> omega + · have v := congrArg UScalar.val e1; rw [nodeAt_val hN ha8, epTSA_val hP', act_val] at v + rcases hon'.1 _ q.cur with g | g <;> omega + · exact h0 rfl + · exact (ep_ne_link hP' (Or.inr rfl) (hW w' hw) (hT w' (hW w' hw)) .Ep).1 e1 + · exact (ep_ne_link hP' (Or.inr rfl) (hW w' hw) (hT w' (hW w' hw)) .Ep).2 e1 + · have v := congrArg UScalar.val e1; rw [epTSA_val hP', epHeadA_val] at v; omega + · have v := congrArg UScalar.val e1; rw [epTSA_val hP', epTSA_val hP] at v; omega + +/-- `SBW.kw8` for an endpoint or a notification. -/ +theorem SBW.kw8N (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q R) (ht : t ∈ H.tcbs) + (hW : ∀ w ∈ W, w ∈ H.tcbs) (hH : H e = some .ep ∨ H e = some .ntfn) {s' : S} (w : WritesIn st s s' (SBW st s t e W)) : + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' := + K8.Foot.d (K8.Foot.of w fun b hb => by + rcases hb with (⟨K, hK, rfl⟩ | rfl | ⟨h0, -⟩) | hb + · exact K8.kw_field ht (by omega) (by omega) (by omega) + · exact K8.kw_node q.cur (by rw [act_val]; omega) (by rw [act_val]; omega) + · exact absurd rfl h0 + · exact hb.kw8 hW (show e ∈ EH H from hH)) + +end frameN + +/-- The liveness words `maybe_return_sched_context` may write: the thread's `SC`, its SC's `TCB`. -/ +def MrX (t i : U64) : LvX := (LvX.tc t 3464).u (LvX.sc i 24) + +set_option maxHeartbeats 16000000 in +/-- **`maybe_return_sched_context`'s frames** (QueueBlock's `maybe_return_sched_context.inv` walk): the thread's +`SC`, its SC's `TCB` (`LvF.wrT`, `LvF.wrC`) and `reschedule_required` (the action word, or a queue step). -/ +theorem maybe_return_sched_context.lvw {s : S} (n t : U64) (h : BK s) (ht : t ∈ H.tcbs) + (hout : (L.mem s (inqA t) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s (inqA t) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.actionW s ≠ t) + (hidle : L.idleW s ≠ t) : + notification.maybe_return_sched_context st s n t ⦃ s' => + LvF st H.tcbs Cs H.replies H.scs H.ntfns (MrX t (L.mem s (scA t))) s s' ∧ + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have C := LvC.of_blk h + have hta := q.tcbs t ht + have ok0 : (ok s : Result S) ⦃ s' => LvF st H.tcbs Cs H.replies H.scs H.ntfns (MrX t (L.mem s (scA t))) s s' ∧ + K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ⦄ := + (WP.spec_ok _).2 ⟨(LvF.refl _ _).mono (LvF.none_le _), WritesIn.refl _ _⟩ + unfold notification.maybe_return_sched_context + step with obj.Ntfn.sc.any as ⟨i, _⟩ + step with obj.Sc.is_null.spec as ⟨b, eb⟩ + split + · exact ok0 + rename_i hb + have hi0 : i ≠ 0#u64 := fun e => hb (by rw [eb, e]; rfl) + step with obj.Tcb.sc.spec as ⟨i1, ei1⟩ + split + swap + · exact ok0 + rename_i hii + have hsc : L.mem s (scA t) = i := by rw [← ei1, hii] + obtain ⟨hiS, -, -⟩ := hX.2.2.bound t ht (by rw [hsc]; exact hi0) + rw [hsc] at hiS + step with obj.Tcb.set_sc.wr as ⟨s1, e1⟩ + step with obj.Sc.set_tcb.wr as ⟨s2, e2⟩ + have key := unbind_state q hB hX hS hSg ht hout hidle hsc hi0 + rw [← e1, ← e2] at key + obtain ⟨k1, kB, -, -, -, k5, -⟩ := key + have hm := q.omega _ (hSg.sub _ (hX.1.fixW i hiS).1) + have g12 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (MrX t (L.mem s (scA t))) s s2 := by + rw [e2, e1, hsc] + have g1 := LvF.wrT C ht (K0 := 3464#u64) (v := 0#u64) (by simp) (by simp) (j := 3464) (by simp) + rw [← scA_eq] at g1 + exact g1.trans (LvF.wrC (C.wr _ _) hiS (o0 := layout.sc.TCB) (v := 0#u64) (by simp [layout.sc.TCB]) + (by simp [layout.sc.TCB]) (j := 24) (by simp [layout.sc.TCB])) + have f12 : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s2 := by + rw [e2, e1] + exact ((writesIn_wr (scA_aligned hta)).trans (writesIn_wr hm.1)).mono fun b hb => by + rcases hb with rfl | rfl + · exact Or.inl (by rw [scA_eq]; exact K8.kw_field ht (by simp) (by simp) ⟨by simp, by simp, by simp, by simp, by simp⟩) + · exact Or.inl (Or.inr (Or.inr (Or.inl (hX.1.fixW i hiS).1))) + have C2 : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s2 := by + rw [e2, e1]; exact (C.wr _ _).wr _ _ + step with sched.cur_thread.spec as ⟨t1, et1⟩ + step with tcb_eq.blk as ⟨b1, eb1⟩ + split + · by_cases ha0 : L.actionW s2 = 0#u64 + · refine WP.spec_mono (sched.reschedule_required.resume s2 ha0) fun s3 e3 => ?_ + subst e3 + refine ⟨(g12.trans (LvF.wrNd C2 (by rw [act_val]; omega) (by rw [act_val]) (by rw [act_val]; omega) + (by rw [act_val]; omega))).mono ⟨fun _ _ h => h.elim id (fun h => (h : False).elim), fun _ _ h => h.elim id (fun h => (h : False).elim), + fun _ _ h => h.elim id (fun h => (h : False).elim), fun _ _ h => h.elim id (fun h => (h : False).elim)⟩, f12.trans ?_⟩ + exact K8.Foot.d (K8.foot_node (k1.nodes _ k1.cur) k1.cur (by rw [act_val]; omega) (by rw [act_val]) + (by rw [act_val]; omega)) + · have kB2 := kB (fun _ => ha0) + refine WP.spec_mono (WP.spec_and (sched.reschedule_required.sch s2 Q R k1 kB2 k5) + (K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s2 k1)) ?_ + rintro s3 ⟨hh, f3⟩ + exact ⟨(g12.trans (LvF.of_fr C2 hh.1.fr)).mono ⟨fun _ _ h => h.elim id (fun h => (h : False).elim), fun _ _ h => h.elim id (fun h => (h : False).elim), + fun _ _ h => h.elim id (fun h => (h : False).elim), fun _ _ h => h.elim id (fun h => (h : False).elim)⟩, f12.trans (K8.Foot.d f3)⟩ + · exact (WP.spec_ok _).2 ⟨g12, f12⟩ + +set_option maxHeartbeats 16000000 in +/-- **`maybe_return_sched_context` is a `DMD p` step** to a `BlkOK` state: it only drops liveness (the thread and its +SC, both live before). -/ +theorem maybe_return_sched_context.dmd (p : U64) {s : S} (n t : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (ht : t ∈ H.tcbs) (hlt : LiveQ st H Cs s t) + (hout : (L.mem s (inqA t) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s (inqA t) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.actionW s ≠ t) + (hidle : L.idleW s ≠ t) : + notification.maybe_return_sched_context st s n t ⦃ s' => DMD st H Cs p s s' ∧ (BK s') ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := q.idleT + refine WP.spec_mono (WP.spec_and (notification.maybe_return_sched_context.inv s n t Q R q hB hX hS hSg ht hout hidle) + (maybe_return_sched_context.lvw n t h ht hout hidle)) ?_ + rintro s' ⟨⟨⟨Q', R', q'⟩, hB', hX', hS', hSg', -⟩, g, f⟩ + have Xt : ∀ y k, (MrX t (L.mem s (scA t))).t y k → y = t ∧ k = 3464 := fun y k hk => by + simpa [MrX, LvX.u, LvX.tc, LvX.sc, LvX.none] using hk + have Xc : ∀ c k, (MrX t (L.mem s (scA t))).c c k → c = L.mem s (scA t) ∧ k = 24 := fun c k hk => by + simpa [MrX, LvX.u, LvX.tc, LvX.sc, LvX.none] using hk + have Xn : ∀ c k, ¬ (MrX t (L.mem s (scA t))).n c k := fun c k hk => by simp [MrX, LvX.u, LvX.tc, LvX.sc, LvX.none] at hk + have Xr : ∀ c k, ¬ (MrX t (L.mem s (scA t))).r c k := fun c k hk => by simp [MrX, LvX.u, LvX.tc, LvX.sc, LvX.none] at hk + have Y' : SymL st H Cs s' := ⟨Y.dbg.lv hz g fun y k hk => by + obtain ⟨-, rfl⟩ := Xt y k hk; exact ⟨by omega, by omega, by omega⟩, + Y.yld.lv hX.2.2.yt g (fun y k hk => by obtain ⟨-, rfl⟩ := Xt y k hk; omega) + (fun c k hk => by obtain ⟨-, rfl⟩ := Xc c k hk; omega)⟩ + have VR' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g (fun c k hk => by obtain ⟨-, rfl⟩ := Xc c k hk; omega) + Xr (BorK.of_lv g fun y k hk => by obtain ⟨-, rfl⟩ := Xt y k hk; omega) + have K := LvK.ofLv (E := fun q => q = t ∨ q = L.mem s (scA t)) g (fun y k hk => Or.inl (Xt y k hk).1) + (fun c k hk => Or.inr (Xc c k hk).1) (fun c k hk => (Xn c k hk).elim) (fun r hk => (Xr r 0 hk).elim) + refine ⟨DMD.ofK h h0 Y Y' VR' (footD_es f) K (fun z hz => ?_) (EpM.ofK (ep_kept_kwd h f)) g.idle + (g.t _ hI 3464#u64 (by unfold LvO; simp) fun hk => hidle (Xt _ _ hk).1), ⟨⟨Q', R', q'⟩, hB', hX', hS', hSg'⟩⟩ + rcases hz with rfl | rfl + · exact Or.inr (Or.inr hlt) + · by_cases h0' : L.mem s (scA t) = 0#u64 + · exact Or.inr (Or.inl h0') + · obtain ⟨hn, hntc, -⟩ := hX.2.2.bound t ht h0' + exact Or.inr (Or.inr (LiveQ.sc hn (Or.inl (by rw [hntc]; exact ne0_of_heap h0 ht)))) + +set_option maxHeartbeats 16000000 in +/-- **The notification wait** (`receive_signal`'s blocking branch up to `ntfn_append`; QueueBlock's `ntfn_block`) +**is a `DMD n` step** to a `BlkOK` state (MdbSendQ's `send_block.sysS` route: `SBW.frameN`, `SndT.dmdE`). -/ +theorem ntfn_wait.dmd {s : S} (t n : U64) (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (hc : CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) + (hH : H n = some .ntfn) (hst0 : L.epState s n = 0#u64 ∨ L.epState s n = 1#u64) : + (do + let s1 ← obj.Tcb.set_state st t s sched.TS_BLOCKED_ON_NTFN + let s2 ← obj.Tcb.set_block_obj st t s1 n + let s3 ← sched.schedule_tcb st s2 t + notification.ntfn_append st s3 n t) ⦃ s4 => DMD st H Cs n s s4 ∧ (BK s4) ∧ + L.mem s4 (stA t) = sched.TS_BLOCKED_ON_NTFN ∧ L.idleW s4 = L.idleW s ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have C := LvC.of_blk h + have ht := hc.mem + have hta := q.tcbs t ht + have hN := q.nodes _ q.cur + obtain ⟨E, EQ, hEW⟩ := q.eps + have heE : n ∈ E := (hEW.2.2.2.2.2.2.2.1 n).2 (Or.inr hH) + obtain ⟨hE, -, hq⟩ := hEW.1 n heE + have hn : t ∉ EQ n := fun hm => hc.nb (hEW.2.2.2.1 n heE t hm).2.2 + have hW : ∀ w ∈ t :: EQ n, w ∈ H.tcbs := fun w hw => by + rcases List.mem_cons.1 hw with rfl | hw + · exact ht + · exact hq.mem w hw + step with obj.Tcb.set_state.spec as ⟨s1, e1⟩ + step with obj.Tcb.set_block_obj.wr as ⟨s2, e2⟩ + have h1 : SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s1 Q R := by + rw [e1]; exact blk_set_state q hc + have h2 : SchedQueuesInvX st H.tcbs Cs H.omega H {y | y ∈ (∅ : Set U64) ∨ y = t} s2 Q R := by + rw [e2]; exact inv_wr_fieldX (K := 3336#u64) h1 ht (Or.inr rfl) (by simp) (by simp) (by simp) + rw [stA_eq] at e1 + have w2 : WritesIn st s s2 (BlkFoot st s t 0#u64) := by + rw [e2, e1]; exact blk_wr_field hta (blk_wr_field (K := 3328#u64) hta (WritesIn.refl _ _) (by simp)) (by simp) + have v2 : L.mem s2 (stA t) = sched.TS_BLOCKED_ON_NTFN := by + rw [e2, fld_wr_ne' hta (blockA_eq t) (stA_eq t) (by simp) (by simp) (by simp) (by simp) (by simp), e1, stA_eq] + exact L.mem_wr_same (field_aligned hta (by simp) (by simp)) + have b2 : L.mem s2 (blockA t) = n := by + rw [e2]; exact L.mem_wr_same (field_aligned hta (by simp) (by simp)) + have a2 : L.actionW s2 = L.actionW s := by + rw [e2, act_wr_field (h1.nodes _ h1.cur) ht hta (blockA_eq t) (by simp) (by simp), + e1, act_wr_field hN ht hta rfl (by simp) (by simp)] + have hbl : Blocked sched.TS_BLOCKED_ON_NTFN := Or.inr (Or.inr rfl) + refine WP.spec_bind (sched.schedule_tcb.blk s2 t h2 (by rw [v2]; exact blocked_not_runnable hbl)) ?_ + rintro s3 ⟨h3, e3, hc3⟩ + obtain ⟨w3, a3, v3, b3, -, -⟩ := blk_sched h2 ht w2 a2 e3 + rw [v2] at v3; rw [b2] at b3 + obtain ⟨-, -, r3, -, r6⟩ := ts_vals + obtain ⟨kf, -, -, ke⟩ := blkfoot_keep q hEW ht (fun h0 => absurd rfl h0) w3 + have hqe : L.epQ s3 n = L.epQ s n := by simp only [LawfulStore.epQ, (ke n heE).1, (ke n heE).2] + have hq3 : QueueRel (L.mem s3) H.tcbs .Ep (L.epQ s3 n) (EQ n) := + ⟨hq.nodup, hq.mem, by rw [hqe]; exact hq.head, by rw [hqe]; exact hq.last, hq.seg.congr fun y hy => + ⟨kf y (hq.mem y hy) (prevOff .Ep) (by simp [prevOff]) (by simp [prevOff]) (fun _ => by simp [prevOff]), + kf y (hq.mem y hy) (nextOff .Ep) (by simp [nextOff]) (by simp [nextOff]) (fun _ => by simp [nextOff])⟩⟩ + refine WP.spec_mono (WP.spec_and (blk_tail (f := notification.ntfn_append st s3 n t) (r0 := 0#u64) + (hidl := hc.ni) q hB hX hS hSg ht + (Or.inr (Or.inr ⟨rfl, hH, rfl⟩)) hst0 h3 w3 a3 v3 b3 (fun h0 => absurd rfl h0) + (fun h1 => absurd (v3.symm.trans h1) (by rw [r3, r6]; decide)) hc.old (fun h0 => absurd rfl h0) hc.ac + (fun xs hE' hq' hn' => WP.spec_mono (WP.spec_and + (notification.ntfn_append.rel s3 n t xs h3.tcbs hE' hq' ht hn') + (notification.ntfn_append.foot s3 n t xs h3.tcbs hE' hq' ht hn')) + fun s4 hh => ⟨hh.1.1, by rw [hh.1.2, ntfn_wait_val], hh.2⟩)) + (notification.ntfn_append.foot s3 n t (EQ n) q.tcbs hE hq3 ht hn)) ?_ + rintro s4 ⟨⟨h4, hB4, hX4, hS4, hSg4, ea4, ec4, v4, ei4⟩, w'⟩ + have w : WritesIn st s s4 (SBW st s t n (t :: EQ n)) := (w3.trans w').mono fun b hb => hb.elim Or.inl Or.inr + obtain ⟨g, kE⟩ := SBW.frameN q C ht hW (Or.inr hH) w + have f := SBW.kw8N q ht hW (Or.inr hH) w + have VR' : ValidReplies st H s4 := ValidReplies.lv VR hX.2.1 g (fun _ _ e => (e : False).elim) (fun _ _ e => e) + (BorK.of_eq t hc.nrp fun z hz hzt => by + rw [stA_eq]; exact g.t z hz 3328#u64 (by unfold LvO; simp) fun e => hzt e.1) + have T : SndT st H Cs (fun q => q = t) s s4 := SndT.ofLv h Y g (fun _ _ hk => ⟨hk.2, hk.1⟩) (fun _ _ e => e) + (fun _ _ e => e) (fun _ _ e => (e : False).elim) f VR' + have d : DMD st H Cs n s s4 := SndT.dmdE h h0 Y T + (fun q hq => Or.inr (Or.inr (by rw [hq]; exact LiveQ.tcb ht (Or.inl hrun)))) + (fun e' he' hne hs => by unfold LawfulStore.epState at hs ⊢; rwa [kE e' (Or.inl he') hne] at hs) + (fun m hm hne hs => by unfold LawfulStore.epState at hs ⊢; rwa [kE m (Or.inr hm) hne] at hs) + exact ⟨d, ⟨⟨Q, R, h4⟩, hB4, hX4, hS4, hSg4⟩, v4, ei4⟩ + +set_option maxHeartbeats 16000000 in +/-- **`receive_signal` on an active notification is a `DMD n` step** to a `BlkOK` state (QueueRecv's +`receive_signal.ipc` walk: the badge register (`reg_badge.dmd`), the notification made idle (`LvF.wrE`, MdbRunQ's +`RQ.ofN`), `maybe_donate_sched_context.dmd`, the sporadic SC's `unblock_check` (`DMD.ofNSc`)). The receiver runs no +VCPU (contract §5's [J] `nvm`). -/ +theorem receive_signal.activeD (hA : P0.ArchTotal ar) {s : S} (a : A) (t n : U64) (blocking : Bool) (h : BK s) + (h0 : H 0#u64 = none) (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hc : CanBlock st H.tcbs Ac s t) + (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) (hn : n ∈ H.ntfns) (hH : H n = some .ntfn) + (hact : L.epState s n = 2#u64) (hrv : L.mem s (runVcpuA t) = 0#u64) : + notification.receive_signal st ar s a t n blocking ⦃ s' _ => DMD st H Cs n s s' ∧ (BK s') ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have ht := hc.mem + have hT := q.tcbs + have hta := hT t ht + have hN := q.nodes _ q.cur + obtain ⟨E, EQ, hEW⟩ := q.eps + have he : n ∈ E := (hEW.2.2.2.2.2.2.2.1 n).2 (Or.inr hH) + obtain ⟨hE, -, -⟩ := hEW.1 n he + unfold notification.receive_signal + step with obj.Ntfn.state.spec as ⟨v, hv⟩ + rw [if_neg (by rw [hv, hact, ntfn_idle_val]; decide), if_neg (by rw [hv, hact, ntfn_wait_val']; decide)] + step with obj.Ntfn.badge.any as ⟨b1, _⟩ + refine WP.spec_bind (obj.Tcb.set_reg.badge s t b1 hta) fun s1 e1 => ?_ + subst e1 + obtain ⟨h1, hB1, hX1, hS1, hSg1⟩ := badge_all (v := b1) q hB hX hS hSg ht + have bk1 : BK (L.wr s (wa t 256#u64) b1) := ⟨⟨Q, R, h1⟩, hB1, hX1, hS1, hSg1⟩ + have d1 : DMD st H Cs n s (L.wr s (wa t 256#u64) b1) := reg_badge.dmd (v := b1) h h0 Y VR ht + have ha1 : Aligned (wa t 256#u64) := field_aligned hta (by simp) (by simp) + have f1 : ∀ y ∈ H.tcbs, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (y = t → K.val ≠ 256) → + L.mem (L.wr s (wa t 256#u64) b1) (wa y K) = L.mem s (wa y K) := fun y hy K hK hK8 hne => + L.mem_wr_ne ha1 (field_aligned (hT y hy) hK hK8) + (fun e => field_ne hta (hT y hy) (by simp) hK (fun e' => by subst e'; exact fun h' => hne rfl h'.symm) + (UScalar.eq_of_val_eq e)) + have ts1 : L.mem (L.wr s (wa t 256#u64) b1) (epTSA n) = L.mem s (epTSA n) := + L.mem_wr_ne ha1 (ep_aligned hE).2 (by + rw [field_val hta (by simp), epTSA_val hE]; have := hE.disj t ht; simp; omega) + have hact1 : L.epState (L.wr s (wa t 256#u64) b1) n = 2#u64 := by + simp only [LawfulStore.epState]; rw [ts1]; exact hact + have ei1 : L.idleW (L.wr s (wa t 256#u64) b1) = L.idleW s := d1.idle + set s1 := L.wr s (wa t 256#u64) b1 with hs1 + refine WP.spec_bind (obj.Ntfn.set_state.val s1 n _) fun s2 e2 => ?_ + subst e2 + obtain ⟨h2, hB2, hX2, hS2, hSg2, f2, o2, ea2, ei2, ec2⟩ := ntfn_idle_all h1 hB1 hX1 hS1 hSg1 hH hact1 + set s2 := L.wr s1 (epTSA n) ((L.mem s1 (epTSA n) &&& ~~~3#u64) ||| (obj.NTFN_IDLE &&& 3#u64)) with hs2 + have bk2 : BK s2 := ⟨⟨Q, R, h2⟩, hB2, hX2, hS2, hSg2⟩ + have d2 : DMD st H Cs n s1 s2 := DMD.ofNoneE bk1 h0 d1.sym d1.vr + ((writesIn_wr (ep_aligned hE).2).mono fun b hb => + Or.inl (Or.inr (Or.inr (Or.inr (Or.inr ⟨n, Or.inr hH, Or.inr hb⟩))))) + (LvF.wrE bk1 (Or.inr hH)) (RQ.ofN (Vc := ∅) (U := ∅) (ct := t) bk1 hH).ep + have F : ∀ y ∈ H.tcbs, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + (y = t → K.val ≠ 256) → L.mem s2 (wa y K) = L.mem s (wa y K) := + fun y hy K hK hK8 h1' h2' h3' => (f2 y hy K hK hK8 h1' h2').trans (f1 y hy K hK hK8 h3') + have iq2 : L.mem s2 (inqA t) = L.mem s (inqA t) := by + rw [inqA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have st2 : L.mem s2 (stA t) = L.mem s (stA t) := by + rw [stA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have ea2' : L.actionW s2 = L.actionW s := by + rw [ea2, hs1, act_wr_field hN ht hta rfl (by simp) (by simp)] + have sc2 : L.mem s2 (scA t) = L.mem s (scA t) := by + rw [scA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have hsA2 : L.mem s2 (scA t) = 0#u64 → ¬ Sch st s2 t := fun h0' hS2t => by + have f21 : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + L.mem s2 (wa t K) = L.mem s1 (wa t K) := fun K a1 a2 a3 a4 => f2 t ht K a1 a2 a3 a4 + have hS1t : Sch st s1 t := Sch.of_eq + (fun hf => by rwa [inqA_eq, f21 _ (by simp) (by simp) (by simp) (by simp)] at hf) + (fun hf => by rwa [inqA_eq, f21 _ (by simp) (by simp) (by simp) (by simp)] at hf) + ea2 ei2 ec2 (by rw [stA_eq]; exact f21 _ (by simp) (by simp) (by simp) (by simp)) hS2t + have hSt := Sch.wr_field q ht (by simp) (by simp) (by simp) ht hS1t + rcases hSt with e | e | e | e | ⟨e1, e2⟩ | e + · exact e hc.nq + · exact e hc.nr + · exact hc.na e + · exact hc.ni e + · exact hB.resume e1 (by rw [e2, ← sc2]; exact h0') + · rcases e with e | e + · exact hc.nb e + · exact hc.nrp e + refine WP.spec_bind (notification.maybe_donate_sched_context.dmd hA a t n bk2 h0 d2.sym d2.vr ht hn hH + (by rw [iq2]; exact hc.nq) (by rw [iq2]; exact hc.nr) (by rw [ea2']; exact hc.na) (by rw [ei2, ei1]; exact hc.ni) + (by rw [st2]; exact hrun) (ntfn_sc_ok hX2 hn hsA2) + ((F t ht 3672#u64 (by simp) (by simp) (by simp) (by simp) (fun _ => by simp)).trans hrv)) ?_ + rintro ⟨s3, a1⟩ ⟨d3, bk3⟩ + try simp only [WP.uncurry'_pair] + obtain ⟨⟨Q3, R3, h3⟩, hB3, hX3, hS3, hSg3⟩ := id bk3 + have D3 : DMD st H Cs n s s3 := d1.trans (d2.trans d3) + have ok3 : (ok (s3, a1) : Result (S × A)) ⦃ s' _ => DMD st H Cs n s s' ∧ (BK s') ⦄ := + (WP.spec_ok _).2 ⟨D3, bk3⟩ + step with obj.Tcb.sc.spec as ⟨i1, ei1⟩ + step with sched.cur_sc.spec as ⟨c4, _⟩ + step with sc_ne.spec as ⟨b3⟩ + split + · step with sporadic.sc_sporadic.spec as ⟨b2, eb2⟩ + split + · rename_i hb2 + have hi1S : i1 ∈ H.scs := (hX3.2.2.bound t ht (by rw [← ei1]; exact (eb2 hb2).1)).1 |> fun h => by + rw [← ei1] at h; exact h + have hiA := hS3.spor i1 hi1S (eb2 hb2).2 + have hW : RefillsWF st s3 i1 (H.scBits i1) := hS3.wf hi1S hiA + obtain ⟨hP, hz⟩ := hX3.1.sc _ hi1S + have hN3 := h3.nodes _ h3.cur + have rpv : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have hrep : Aligned (L.nodeA s3 layout.node.REPROGRAM) ∧ Outside (L.nodeA s3 layout.node.REPROGRAM) i1 + (H.scBits i1) := + ⟨nodeAt_aligned hN3 (by rw [rpv]; omega) (by rw [rpv]), + node_out_place (fun b hb hin => hX3.1.scW _ hi1S b hb hin) h3.omega h3.cur hN3 (by rw [rpv]; omega) + (by rw [rpv])⟩ + refine WP.spec_bind (WP.spec_and (sporadic.unblock_check.all s3 t i1 h3 hB3 hX3 hS3 hSg3 ht ei1 (eb2 hb2).1 hiA) + (sporadic.unblock_check.fr hW hrep)) fun s5 hh => ?_ + obtain ⟨⟨h5, hB5, hX5, hS5, hSg5, -⟩, w5⟩ := hh + refine (WP.spec_ok _).2 ⟨D3.trans (DMD.ofNSc bk3 h0 D3.sym D3.vr (w5.mono fun b hb => ?_)), + ⟨⟨Q3, R3, h5⟩, hB5, hX5, hS5, hSg5⟩⟩ + rcases hb with hr | e + · have hv80 := hr.1 + exact NScW.ofSC hi1S hP hz hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · unfold LawfulStore.nodeA at e + exact Or.inl ⟨L.cpu s3, h3.cur, layout.node.REPROGRAM, by rw [rpv]; omega, by rw [rpv], by rw [rpv]; omega, + fun _ => by rw [rpv]; omega, e⟩ + · exact ok3 + · exact ok3 + +set_option maxHeartbeats 16000000 in +/-- **`complete_signal` is a `DMD n` step** to a `BlkOK` state (QueueIpc's `complete_signal.ipc` walk; the active +branch is `receive_signal.activeD`'s: the badge register (`reg_badge.dmd`), the notification made idle (`LvF.wrE`, MdbRunQ's +`RQ.ofN`), `maybe_donate_sched_context.dmd`, the sporadic SC's `unblock_check` (`DMD.ofNSc`)). The receiver runs no +VCPU (contract §5's [J] `nvm`). -/ +theorem complete_signal.dmd (hA : P0.ArchTotal ar) {s : S} (a : A) (n t : U64) (h : BK s) + (h0 : H 0#u64 = none) (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hc : CanBlock st H.tcbs Ac s t) + (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) (hn : n ∈ H.ntfns) (hH : H n = some .ntfn) + (hrv : L.mem s (runVcpuA t) = 0#u64) : + notification.complete_signal st ar s a n t ⦃ s' _ => DMD st H Cs n s s' ∧ (BK s') ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have ht := hc.mem + have hT := q.tcbs + have hta := hT t ht + have hN := q.nodes _ q.cur + obtain ⟨E, EQ, hEW⟩ := q.eps + have he : n ∈ E := (hEW.2.2.2.2.2.2.2.1 n).2 (Or.inr hH) + obtain ⟨hE, -, -⟩ := hEW.1 n he + have rf : (ok (s, a) : Result (S × A)) ⦃ s' _ => DMD st H Cs n s s' ∧ (BK s') ⦄ := + (WP.spec_ok _).2 ⟨DMD.refl n h h0 Y VR, h⟩ + unfold notification.complete_signal + step with obj.Tcb.is_null.spec as ⟨b0, _⟩ + split + · exact rf + step with obj.Ntfn.state.spec as ⟨v, hv⟩ + split + · exact rf + rename_i hia + have hact : L.epState s n = 2#u64 := by rw [← hv]; exact ntfn_active_ne hia + step with obj.Ntfn.badge.any as ⟨b1, _⟩ + refine WP.spec_bind (obj.Tcb.set_reg.badge s t b1 hta) fun s1 e1 => ?_ + subst e1 + obtain ⟨h1, hB1, hX1, hS1, hSg1⟩ := badge_all (v := b1) q hB hX hS hSg ht + have bk1 : BK (L.wr s (wa t 256#u64) b1) := ⟨⟨Q, R, h1⟩, hB1, hX1, hS1, hSg1⟩ + have d1 : DMD st H Cs n s (L.wr s (wa t 256#u64) b1) := reg_badge.dmd (v := b1) h h0 Y VR ht + have ha1 : Aligned (wa t 256#u64) := field_aligned hta (by simp) (by simp) + have f1 : ∀ y ∈ H.tcbs, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (y = t → K.val ≠ 256) → + L.mem (L.wr s (wa t 256#u64) b1) (wa y K) = L.mem s (wa y K) := fun y hy K hK hK8 hne => + L.mem_wr_ne ha1 (field_aligned (hT y hy) hK hK8) + (fun e => field_ne hta (hT y hy) (by simp) hK (fun e' => by subst e'; exact fun h' => hne rfl h'.symm) + (UScalar.eq_of_val_eq e)) + have ts1 : L.mem (L.wr s (wa t 256#u64) b1) (epTSA n) = L.mem s (epTSA n) := + L.mem_wr_ne ha1 (ep_aligned hE).2 (by + rw [field_val hta (by simp), epTSA_val hE]; have := hE.disj t ht; simp; omega) + have hact1 : L.epState (L.wr s (wa t 256#u64) b1) n = 2#u64 := by + simp only [LawfulStore.epState]; rw [ts1]; exact hact + have ei1 : L.idleW (L.wr s (wa t 256#u64) b1) = L.idleW s := d1.idle + set s1 := L.wr s (wa t 256#u64) b1 with hs1 + refine WP.spec_bind (obj.Ntfn.set_state.val s1 n _) fun s2 e2 => ?_ + subst e2 + obtain ⟨h2, hB2, hX2, hS2, hSg2, f2, o2, ea2, ei2, ec2⟩ := ntfn_idle_all h1 hB1 hX1 hS1 hSg1 hH hact1 + set s2 := L.wr s1 (epTSA n) ((L.mem s1 (epTSA n) &&& ~~~3#u64) ||| (obj.NTFN_IDLE &&& 3#u64)) with hs2 + have bk2 : BK s2 := ⟨⟨Q, R, h2⟩, hB2, hX2, hS2, hSg2⟩ + have d2 : DMD st H Cs n s1 s2 := DMD.ofNoneE bk1 h0 d1.sym d1.vr + ((writesIn_wr (ep_aligned hE).2).mono fun b hb => + Or.inl (Or.inr (Or.inr (Or.inr (Or.inr ⟨n, Or.inr hH, Or.inr hb⟩))))) + (LvF.wrE bk1 (Or.inr hH)) (RQ.ofN (Vc := ∅) (U := ∅) (ct := t) bk1 hH).ep + have F : ∀ y ∈ H.tcbs, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + (y = t → K.val ≠ 256) → L.mem s2 (wa y K) = L.mem s (wa y K) := + fun y hy K hK hK8 h1' h2' h3' => (f2 y hy K hK hK8 h1' h2').trans (f1 y hy K hK hK8 h3') + have iq2 : L.mem s2 (inqA t) = L.mem s (inqA t) := by + rw [inqA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have st2 : L.mem s2 (stA t) = L.mem s (stA t) := by + rw [stA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have ea2' : L.actionW s2 = L.actionW s := by + rw [ea2, hs1, act_wr_field hN ht hta rfl (by simp) (by simp)] + have sc2 : L.mem s2 (scA t) = L.mem s (scA t) := by + rw [scA_eq]; exact F t ht _ (by simp) (by simp) (by simp) (by simp) (fun _ => by simp) + have hsA2 : L.mem s2 (scA t) = 0#u64 → ¬ Sch st s2 t := fun h0' hS2t => by + have f21 : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + L.mem s2 (wa t K) = L.mem s1 (wa t K) := fun K a1 a2 a3 a4 => f2 t ht K a1 a2 a3 a4 + have hS1t : Sch st s1 t := Sch.of_eq + (fun hf => by rwa [inqA_eq, f21 _ (by simp) (by simp) (by simp) (by simp)] at hf) + (fun hf => by rwa [inqA_eq, f21 _ (by simp) (by simp) (by simp) (by simp)] at hf) + ea2 ei2 ec2 (by rw [stA_eq]; exact f21 _ (by simp) (by simp) (by simp) (by simp)) hS2t + have hSt := Sch.wr_field q ht (by simp) (by simp) (by simp) ht hS1t + rcases hSt with e | e | e | e | ⟨e1, e2⟩ | e + · exact e hc.nq + · exact e hc.nr + · exact hc.na e + · exact hc.ni e + · exact hB.resume e1 (by rw [e2, ← sc2]; exact h0') + · rcases e with e | e + · exact hc.nb e + · exact hc.nrp e + refine WP.spec_bind (notification.maybe_donate_sched_context.dmd hA a t n bk2 h0 d2.sym d2.vr ht hn hH + (by rw [iq2]; exact hc.nq) (by rw [iq2]; exact hc.nr) (by rw [ea2']; exact hc.na) (by rw [ei2, ei1]; exact hc.ni) + (by rw [st2]; exact hrun) (ntfn_sc_ok hX2 hn hsA2) + ((F t ht 3672#u64 (by simp) (by simp) (by simp) (by simp) (fun _ => by simp)).trans hrv)) ?_ + rintro ⟨s3, a1⟩ ⟨d3, bk3⟩ + try simp only [WP.uncurry'_pair] + obtain ⟨⟨Q3, R3, h3⟩, hB3, hX3, hS3, hSg3⟩ := id bk3 + have D3 : DMD st H Cs n s s3 := d1.trans (d2.trans d3) + have ok3 : (ok (s3, a1) : Result (S × A)) ⦃ s' _ => DMD st H Cs n s s' ∧ (BK s') ⦄ := + (WP.spec_ok _).2 ⟨D3, bk3⟩ + step with obj.Tcb.sc.spec as ⟨i1, ei1⟩ + step with sporadic.sc_sporadic.spec as ⟨b2, eb2⟩ + split + · rename_i hb2 + step with obj.Ntfn.sc.val as ⟨i2, _⟩ + split + · step with sched.cur_sc.spec as ⟨c4, _⟩ + step with sc_ne.spec as ⟨b3⟩ + split + · have hi1S : i1 ∈ H.scs := (hX3.2.2.bound t ht (by rw [← ei1]; exact (eb2 hb2).1)).1 |> fun h => by + rw [← ei1] at h; exact h + have hiA := hS3.spor i1 hi1S (eb2 hb2).2 + have hW : RefillsWF st s3 i1 (H.scBits i1) := hS3.wf hi1S hiA + obtain ⟨hP, hz⟩ := hX3.1.sc _ hi1S + have hN3 := h3.nodes _ h3.cur + have rpv : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have hrep : Aligned (L.nodeA s3 layout.node.REPROGRAM) ∧ Outside (L.nodeA s3 layout.node.REPROGRAM) i1 + (H.scBits i1) := + ⟨nodeAt_aligned hN3 (by rw [rpv]; omega) (by rw [rpv]), + node_out_place (fun b hb hin => hX3.1.scW _ hi1S b hb hin) h3.omega h3.cur hN3 (by rw [rpv]; omega) + (by rw [rpv])⟩ + refine WP.spec_bind (WP.spec_and (sporadic.unblock_check.all s3 t i1 h3 hB3 hX3 hS3 hSg3 ht ei1 (eb2 hb2).1 hiA) + (sporadic.unblock_check.fr hW hrep)) fun s5 hh => ?_ + obtain ⟨⟨h5, hB5, hX5, hS5, hSg5, -⟩, w5⟩ := hh + refine (WP.spec_ok _).2 ⟨D3.trans (DMD.ofNSc bk3 h0 D3.sym D3.vr (w5.mono fun b hb => ?_)), + ⟨⟨Q3, R3, h5⟩, hB5, hX5, hS5, hSg5⟩⟩ + rcases hb with hr | e + · have hv80 := hr.1 + exact NScW.ofSC hi1S hP hz hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · unfold LawfulStore.nodeA at e + exact Or.inl ⟨L.cpu s3, h3.cur, layout.node.REPROGRAM, by rw [rpv]; omega, by rw [rpv], by rw [rpv]; omega, + fun _ => by rw [rpv]; omega, e⟩ + · exact ok3 + · exact ok3 + · exact ok3 + +set_option maxHeartbeats 16000000 in +/-- **`receive_signal` keeps the walk bundle** (QueueRecv's `receive_signal.ipc` cases): the wait (`ntfn_wait.dmd`, the +notification named; then `maybe_return_sched_context.dmd`), the badge-only non-blocking branch (`reg_badge.dmd`), the +active notification (`receive_signal.activeD`). -/ +theorem receive_signal.sw (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + {s0 s : S} (a : A) (t n : U64) (blocking : Bool) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hc : CanBlock st H.tcbs Ac s t) + (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) (hn : n ∈ H.ntfns) (hH : H n = some .ntfn) + (h3 : L.epState s n ≠ 3#u64) (hrv : L.mem s (runVcpuA t) = 0#u64) + (hpn : ∀ k, H n = some k → ¬ (ia ≤ n.val ∧ n.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) n k) : + notification.receive_signal st ar s a t n blocking ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have h := W.1.blk + have h0 := W.1.sys.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have ht := hc.mem + have hta := q.tcbs t ht + by_cases e01 : L.epState s n = 0#u64 ∨ L.epState s n = 1#u64 + · have Kc : ∀ s4, (DMD st H Cs n s s4 ∧ (BK s4) ∧ L.mem s4 (stA t) = sched.TS_BLOCKED_ON_NTFN ∧ + L.idleW s4 = L.idleW s) → (do + let s5 ← notification.maybe_return_sched_context st s4 n t + ok (s5, a)) ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + rintro s4 ⟨d4, b4, v4, ei4⟩ + have W4 := W.dmd I hc0 hks hpn d4 b4 + obtain ⟨⟨Q4, R4, q4⟩, -⟩ := id b4 + refine WP.spec_bind (maybe_return_sched_context.dmd 0#u64 n t b4 h0 W4.1.sym W4.1.sys.vr ht + (LiveQ.tcb ht (Or.inl (by rw [v4]; simp [sched.TS_BLOCKED_ON_NTFN, sched.TS_INACTIVE]))) + (blocked_out q4 ht (by rw [v4]; exact blocked_not_runnable (Or.inr (Or.inr rfl)))) + (by rw [ei4]; exact hc.ni)) fun s5 hh => ?_ + simp only [WP.spec_ok, WP.uncurry'_pair] + exact W4.dmd0 I hc0 hks hh.1 hh.2 + have BLK := WP.spec_bind (ntfn_wait.dmd t n h h0 W.1.sym W.1.sys.vr hc hrun hH e01) Kc + simp only [Std.bind_assoc] at BLK + have NB : (do let s1 ← obj.Tcb.set_reg st t s layout.reg.BADGE 0#u64; ok (s1, a)) ⦃ s' _ => + SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + refine WP.spec_bind (obj.Tcb.set_reg.badge s t 0#u64 hta) ?_ + rintro s1 rfl + simp only [WP.spec_ok, WP.uncurry'_pair] + obtain ⟨k1, k2, k3, k4, k5⟩ := badge0_all q hB hX hS hSg ht + exact W.dmd0 I hc0 hks (reg_badge.dmd (v := 0#u64) h h0 W.1.sym W.1.sys.vr ht) ⟨⟨Q, R, k1⟩, k2, k3, k4, k5⟩ + unfold notification.receive_signal + step with obj.Ntfn.state.spec as ⟨v, hv⟩ + split + · split + · exact BLK + · exact NB + · split + · split + · exact BLK + · exact NB + · exfalso + rename_i h1 h2 + clear BLK NB Kc + rw [ntfn_idle_val] at h1; rw [ntfn_wait_val'] at h2 + rcases e01 with e0 | e0 + · exact h1 (hv.trans e0) + · exact h2 (hv.trans e0) + · have hact : L.epState s n = 2#u64 := by + have := (L.mem s (epTSA n)).val + push_neg at e01 + simp only [LawfulStore.epState] at e01 h3 ⊢ + apply UScalar.eq_of_val_eq + have hb : (L.mem s (epTSA n) &&& 3#u64).val < 4 := by + rw [UScalar.val_and]; exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) + have e0 : (L.mem s (epTSA n) &&& 3#u64).val ≠ 0 := fun e => e01.1 (UScalar.eq_of_val_eq e) + have e1 : (L.mem s (epTSA n) &&& 3#u64).val ≠ 1 := fun e => e01.2 (UScalar.eq_of_val_eq e) + have e3 : (L.mem s (epTSA n) &&& 3#u64).val ≠ 3 := fun e => h3 (UScalar.eq_of_val_eq e) + show (L.mem s (epTSA n) &&& 3#u64).val = 2 + omega + refine WP.spec_mono (receive_signal.activeD hA a t n blocking h h0 W.1.sym W.1.sys.vr hc hrun hn hH hact hrv) + fun r hr => ?_ + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at hr ⊢ + exact W.dmd I hc0 hks hpn hr.1 hr.2 + +section dq +set_option maxHeartbeats 2000000 in +/-- (`ep_dequeue.sysL` for a sending endpoint.) **The dequeue of a sending endpoint's head is a `DMD e` step keeping `SysL ∧ SymL`** (module docstring); the +receiver `hd` stays blocked on receive, with every TCB field off the endpoint-queue links kept. -/ +theorem endpoint.ep_dequeue.sysLS {Rp Nt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot e : U64} + {s : S} (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hH : H e = some .ep) (hst : L.epState s e = 1#u64) + (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) : + endpoint.ep_dequeue st s e (L.epQ s e).head ⦃ s1 => + SysL st H Cs OS ia ie s1 ∧ SymL st H Cs s1 ∧ (BX {y | y ∈ (∅ : Set U64) ∨ y = (L.epQ s e).head}, s1) ∧ + SysPlace st H Cs H.frame Rp Nt OS s1 extra slot ∧ DMD st H Cs e s s1 ∧ + (∀ y ∈ H.tcbs, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + L.mem s1 (wa y K) = L.mem s (wa y K)) ∧ + L.actionW s1 = L.actionW s ∧ L.curW s1 = L.curW s ∧ L.idleW s1 = L.idleW s ∧ + (∀ x ∈ H.omega, L.mem s1 x = L.mem s x) ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hT := q.tcbs + obtain ⟨hdT, hbe, hds, -⟩ := ep_head q hH (Or.inl rfl) hst + have hds := hds rfl + set hd := (L.epQ s e).head with hhd + have hbl : Blocked (L.mem s (stA hd)) := by rw [hds]; exact Or.inl rfl + obtain ⟨xs, hE, hq, -, -, -⟩ := eps_list q (Or.inl hH) + have hmem : hd ∈ xs := by + obtain ⟨y, ys, rfl⟩ := List.exists_cons_of_ne_nil fun e' => (hT hd hdT).ne0 (by + have e0 := (hq.empty_iff hT).2 e' + rw [← hhd] at e0 + rw [e0]; rfl) + have hy : y = hd := by rw [hhd, hq.head]; rfl + rw [← hy]; exact List.mem_cons_self + have hdq := endpoint.ep_dequeue.inv s hd Q R q hdT (by simp) hbl + rw [hbe] at hdq + refine WP.spec_mono (WP.spec_and hdq (endpoint.ep_dequeue.foot s e hd xs hT hE hq hmem)) ?_ + rintro s1 ⟨⟨h1, f1, o1, n1, k1, c1, nc1⟩, w1⟩ + have tm1 : TmFr st H.tcbs Cs H.ntfns 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 q hB hX hS hSg f1 o1 n1 k1 tm1 + have b1 : BX {y | y ∈ (∅ : Set U64) ∨ y = hd}, s1 := ⟨⟨Q, R, h1⟩, hB1, hX1, hS1, hSg1⟩ + have g1 := LvF.of_dq C k1 c1 n1 nc1 f1 o1 + have VR := B.vr + have M : EpM st H s s1 := epS_monoX h b1 fun y hy hb => by + have es : L.mem s1 (stA y) = L.mem s (stA y) := by + rw [stA_eq, f1 y hy _ (by simp) (by simp) (by simp) (by simp), ← stA_eq] + exact ⟨es, by rw [blockA_eq, f1 y hy _ (by simp) (by simp) (by simp) (by simp)], Set.notMem_empty _⟩ + have f : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s1 := + WritesIn.mono w1 fun b hb => Or.inl (hb.kw8 hq.mem (show e ∈ EH H from Or.inl hH)) + have d : DMD st H Cs e s s1 := DMD.ofNoneE h B.ly.h0 Y VR f g1 M + have k : OSKeep st OS s s1 := OSKeep.of_kwd7 P.os q hSg.sub hSA (fun _ he => he) (K8.FootD.to7 d.w) + obtain ⟨B1, Y1⟩ := SysL.dfMDX P h hSA hp B d + exact ⟨B1, Y1, b1, P.keepO k k1, d, f1, ea1, ec1, ei1, o1⟩ + +end dq + +/-- A `Reply` cap names its reply object. -/ +theorem names_reply {r : U64} {g : Bool} : NamesA (.Reply r g) r .reply := by + have hp : physA (.Reply r g) = true := by + have h := physA_eq (.Reply r g); simp only [objects.cap_is_physical] at h; exact (okinj h).symm + have ep : ptrA (.Reply r g) = r := by + have h := ptrA_eq (.Reply r g); simp only [capability.Cap.ptr] at h; exact (okinj h).symm + refine ⟨⟨hp, rfl, rfl⟩, by rw [ep], ?_, by simp [kindA], by simp [KMatchA, kindA]⟩ + rw [ep]; have := Nat.one_le_two_pow (n := HKind.reply.bits); omega + +/-- A transfer keeps every slot holding a cap that is neither `Null` nor an `Untyped`. -/ +theorem XferSlots.keepCap {s r : S} (h : XferSlots st OS s r) {z : U64} (hz : z ∈ OS) + (h0 : capA st s z ≠ .Null) (hu : ∀ p b i e, capA st s z ≠ .Untyped p b i e) : capA st r z = capA st s z := by + rcases h with same | ⟨src, hs, dest, hd, ne, empty, -, turned, others⟩ + · exact same z hz + · by_cases e1 : z = src + · subst e1 + rcases turned with e | ⟨p, b, i, ee, i1, e2, -, -⟩ + · exact e + · exact absurd e2 (hu p b i ee) + · by_cases e2 : z = dest + · subst e2; exact absurd empty h0 + · exact others z hz e1 e2 + +set_option maxHeartbeats 64000000 in +/-- **`receive_from_sender` from the walk bundle to the Reply-walk bundle** (one transfer): the sending endpoint's +head dequeued (`ep_dequeue.sysLS`), the message (MdbXferQ's `do_ipc_transfer.xjS`), `unblock_sporadic`, then the +sender's reply bookkeeping (MdbSendD's `reply_push.snd`: the reply named by its cap's slot, live after), its stop +(`TS_INACTIVE`) or its wake (`TS_RUNNING`, `possible_switch_to`) — QueueXferA's `receive_from_sender.ipcA` cases; +each tail a `DMD` step from the state after `unblock_sporadic` (MdbSendL's `SndT.dmd`). -/ +theorem receive_from_sender.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s0 s : S} (a : A) (thread e reply : U64) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s0)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s0) Pt') + (hc : CanBlock st H.tcbs Ac s thread) (hrun : L.mem s (stA thread) ≠ sched.TS_INACTIVE) + (hH : H e = some .ep) (hst1 : L.epState s e = 1#u64) + (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) + (hr : reply ≠ 0#u64 → reply ∈ H.replies ∧ (L.mem s (rTcbA reply) = 0#u64 ∨ L.mem s (rTcbA reply) = thread)) + (hrc : reply ≠ 0#u64 → ∃ x ∈ OS, ∃ g, capA st s x = .Reply reply g) + (hRV : RunVcpuInv st H.tcbs s) (hvm : L.mem s (stA thread) ≠ sched.TS_RUNNING_VM) : + endpoint.receive_from_sender st ar s a thread e reply ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have R := W.1 + have h := R.blk + have h0 := R.sys.ly.h0 + have P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot := + SysPlace.ofXfer Pz R.sys.sys.stz.1.1.mdbS R.xs R.ksb + have hks' : HeapKsOff H (L.ksb s) := by rw [R.ksb]; exact hks + have hvr' : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt' := by rw [R.ksb]; exact hvr + obtain ⟨⟨Q, Rq, q⟩, hB, hX, hS, hSg⟩ := id h + have hT := q.tcbs + have ht := hc.mem + obtain ⟨hdT, hbe, hds, -⟩ := ep_head q hH (Or.inl rfl) hst1 + have hds := hds rfl + set hd := (L.epQ s e).head with hhd + have hdt : hd ≠ thread := fun e' => hc.nb (by rw [← e', hds]; exact Or.inl rfl) + have hdi : L.idleW s ≠ hd := fun e' => hB.idleNB (by rw [e', hds]; exact Or.inl (Or.inl rfl)) + have hr' : reply ≠ 0#u64 → reply ∈ H.replies ∧ L.mem s (rTcbA reply) = 0#u64 := fun h0' => by + obtain ⟨h1, h2⟩ := hr h0' + exact ⟨h1, h2.resolve_right fun e' => hX.noref (hT _ ht) hc.nrp (fun e2 => hc.nb (Or.inr (Or.inl e2))) _ h1 e'⟩ + unfold endpoint.receive_from_sender + step with endpoint.get_queue.spec as ⟨qq, eq⟩ + subst eq + refine WP.spec_bind (endpoint.ep_dequeue.sysLS P h hSA R.sys R.sym hH hst1 hp) ?_ + rintro s1 ⟨B1, Y1, b1, P1, d1, f1, ea1, -, ei1, o1⟩ + obtain ⟨k1, t1, v1⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA hvr' hks' R.sys.ly.ksw P.core0 q hSg.sub + (fun _ he => he) d1.w + have ek1 : L.ksb s1 = L.ksb s := d1.w.1 + step with obj.Tcb.block_badge.any as ⟨badge, _⟩ + step with obj.Tcb.block_flags.any as ⟨flags, _⟩ + simp only [lift, Aeneas.Std.bind_ok] + refine WP.spec_bind (ipc.do_ipc_transfer.xjS (Vc := Vc) hA a P1 hSA hTS (by rw [ek1]; exact hks') + (by rw [ek1]; exact hvr') B1 Y1 b1 hdT ht) ?_ + rintro s2 ⟨J, c2, x2, S2⟩ + have ek2 : L.ksb s2 = L.ksb s := J.lv.ksb.trans ek1 + obtain ⟨⟨Q2, R2, q2⟩, hB2, hX2, hS2, hSg2⟩ := id J.blk + refine WP.spec_bind (WP.spec_and (WP.spec_and (endpoint.unblock_sporadic.snd (E := fun _ => False) hd J.blk J.sys.vr + J.sym hdT) (endpoint.unblock_sporadic.all s2 hd q2 hB2 hX2 hS2 hSg2 hdT)) + (endpoint.unblock_sporadic.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s2 hd q2 hX2 hS2 hdT)) ?_ + rintro s3 ⟨⟨⟨T3, b3⟩, ⟨-, -, -, -, -, ea3, -, ei3, f3, r3⟩⟩, fk3⟩ + -- the step to `s3` (no liveness word written) and the bundle there + have d3 : DMD st H Cs 0#u64 s2 s3 := SndT.dmd J.blk h0 J.sym T3 (fun _ hq => (hq : False).elim) + (EpM.ofFootDX J.blk (Foot.d fk3)) + obtain ⟨B3, Y3⟩ := SysL.dfMDO P.heap P.os J.blk hSA (fun k hk => by rw [h0] at hk; cases hk) J.sys d3 + obtain ⟨k3, t3, v3⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA (by rw [ek2]; exact hvr') (by rw [ek2]; exact hks') + J.sys.ly.ksw P.core0 q2 hSg2.sub (fun _ he => he) d3.w + have ek3 : L.ksb s3 = L.ksb s := d3.w.1.trans ek2 + have k03 : ∀ z ∈ OS, capA st s1 z = capA st s0 z := fun z hz => ((W.2.1.trans' k1).capA hz) + -- the close from `s3` + have fin : ∀ {s' : S} {p : U64}, DMD st H Cs p s3 s' → (BK s') → + (∀ k, H p = some k → ∃ x ∈ OS, NamesA (capA st s3 x) p k) → RpW st H Cs OS Vc ia ie Ac s0 s' := by + intro s' p d b' hp3 + obtain ⟨⟨Q3, R3, q3⟩, -⟩ := id b3 + obtain ⟨S', Y'⟩ := SysL.dfMDO P.heap P.os b3 hSA hp3 B3 d + obtain ⟨k', t', v'⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA (by rw [ek3]; exact hvr') (by rw [ek3]; exact hks') + B3.ly.ksw P.core0 q3 b3.2.2.2.2.sub (fun _ he => he) d.w + exact ⟨S', Y', b', R.xc.trans ((XC.keep k1 t1).trans (c2.trans ((XC.keep k3 t3).trans (XC.keep k' t')))), + R.xv.trans ((XV.keep v1 k1).trans (x2.trans ((XV.keep v3 k3).trans (XV.keep v' k')))), + XferSlots.before k03 (S2.keep fun z hz => (k3.trans' k').capA hz)⟩ + -- facts at `s3` + have F : ∀ y ∈ H.tcbs, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3496 → K.val ≠ 3504 → + K.val ≠ 3392 → L.mem s3 (wa y K) = L.mem s (wa y K) := + fun y hy K h0' hK hK8 h1 h2' h9 => (f3 y hy K hK hK8).trans ((J.fr y hy K h0' hK hK8 h9).trans + (f1 y hy K hK hK8 h1 h2')) + have st3 : ∀ y ∈ H.tcbs, L.mem s3 (stA y) = L.mem s (stA y) := fun y hy => by + rw [stA_eq]; exact F y hy _ (by simp) (by simp) (by simp) (by simp) (by simp) (by simp) + have iq3 : ∀ y ∈ H.tcbs, L.mem s3 (inqA y) = L.mem s (inqA y) := fun y hy => by + rw [inqA_eq]; exact F y hy _ (by simp) (by simp) (by simp) (by simp) (by simp) (by simp) + have ea : L.actionW s3 = L.actionW s := ea3.trans (J.act.trans ea1) + have ei : L.idleW s3 = L.idleW s := ei3.trans (J.lv.idle.trans ei1) + have hds3 : L.mem s3 (stA hd) = sched.TS_BLOCKED_ON_SEND := (st3 hd hdT).trans hds + have rv3 : L.mem s3 (runVcpuA thread) = 0#u64 := + (F thread ht 3672#u64 (by simp) (by simp) (by simp) (by simp) (by simp) (by simp)).trans (hRV.zero ht hvm) + obtain ⟨⟨Q3, R3, q3⟩, hB3, hX3, hS3, hSg3⟩ := id b3 + obtain ⟨dq, dr, da⟩ := blocked_out q3 hdT (by rw [hds3]; exact blocked_not_runnable (Or.inl rfl)) + have hXc : ExcT {y | y ∈ (∅ : Set U64) ∨ y = hd} hd := fun y hy => by simpa using hy + have hx3 : hd ∈ {y | y ∈ (∅ : Set U64) ∨ y = hd} := Or.inr rfl + have rt3 : ∀ r ∈ H.replies, L.mem s3 (rTcbA r) = L.mem s (rTcbA r) := fun r hr0 => + (r3 r hr0).trans ((J.lv.r r hr0 _ (by unfold LvRO; simp [layout.reply.TCB]) id).trans + (o1 _ (hSg.sub _ (hX.1.tcbW hr0)))) + have sc3 : L.mem s3 (scA hd) = L.mem s (scA hd) := by + rw [scA_eq]; exact F hd hdT _ (by simp) (by simp) (by simp) (by simp) (by simp) (by simp) + have hdA : L.mem s3 (scA hd) ≠ 0#u64 → L.mem s3 (scA hd) ∈ Ac := fun h0' => by + rw [sc3] at h0' ⊢ + exact hB.sact hd hdT (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (by rw [hds]; exact Or.inl rfl))))))) + h0' + have hz3 : DbgTz st H.tcbs Cs s3 := XInv.dbg hX3 + have lhd : LiveQ st H Cs s3 hd := LiveQ.tcb hdT (Or.inl (by rw [hds3]; simp [sched.TS_BLOCKED_ON_SEND, + sched.TS_INACTIVE])) + have lth : LiveQ st H Cs s3 thread := LiveQ.tcb ht (Or.inl (by rw [st3 thread ht]; exact hrun)) + have n00 : ∀ k, H 0#u64 = some k → ∃ x ∈ OS, NamesA (capA st s3 x) 0#u64 k := fun k hk => by + rw [h0] at hk; cases hk + -- the tails + have E1 : ∀ cd : Bool, reply ≠ 0#u64 → ipc.reply_push st ar s3 a hd thread reply cd ⦃ s' _ => + RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := fun cd hne => by + obtain ⟨hrR, hrz⟩ := hr' hne + obtain ⟨x, hx, g, hxc⟩ := hrc hne + have hcap3 : capA st s3 x = .Reply reply g := by + have e1 : capA st s1 x = .Reply reply g := (k1.capA hx).trans hxc + have e2 : capA st s2 x = .Reply reply g := (S2.keepCap hx (by rw [e1]; exact fun h => by cases h) + (fun p b i ee => by rw [e1]; exact fun h => by cases h)).trans e1 + exact (k3.capA hx).trans e2 + refine WP.spec_mono (WP.spec_and (ipc.reply_push.snd hA a hd thread reply cd b3 B3.vr Y3 hXc (Or.inl hx3) hdT dq dr + da (by rw [ei]; exact hdi) (by rw [hds3]; exact send_ne) hrR hne (by rw [rt3 _ hrR]; exact hrz) ht (Ne.symm hdt) + (by rw [iq3 _ ht]; exact hc.nq) (by rw [iq3 _ ht]; exact hc.nr) (by rw [ea]; exact hc.na) + (by rw [ei]; exact hc.ni) hdA rv3) + (ipc.reply_push.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) hA s3 a hd thread reply cd q3 hXc + (Or.inl hx3) hB3 hX3 hS3 hSg3 hdT dq dr da (by rw [ei]; exact hdi) (by rw [hds3]; exact send_ne) hrR hne + (by rw [rt3 _ hrR]; exact hrz) ht hdA rv3)) ?_ + rintro ⟨s', a'⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨⟨T', b', -, -⟩, fk⟩ := hh + refine fin (p := reply) (SndT.dmd b3 h0 Y3 T' (fun z hz => ?_) (EpM.ofFootDX b3 fk)) b' (fun k hk => ?_) + · rcases hz with e' | e' | e' | e' | hz + · exact Or.inl e' + · rw [e']; exact Or.inr (Or.inr lhd) + · rw [e']; exact Or.inr (Or.inr lth) + · rw [e'] + by_cases h0' : L.mem s3 (scA hd) = 0#u64 + · exact Or.inr (Or.inl h0') + · obtain ⟨hn, hntc, -⟩ := hX3.2.2.bound hd hdT h0' + exact Or.inr (Or.inr (LiveQ.sc hn (Or.inl (by rw [hntc]; exact ne0_of_heap h0 hdT)))) + · exact (DbgIT.live hz3 hz).elim (fun e0 => Or.inr (Or.inl e0)) (fun l => Or.inr (Or.inr l)) + · have e : H reply = some .reply := hrR + rw [e] at hk; cases hk + exact ⟨x, hx, by rw [hcap3]; exact names_reply⟩ + have E1' : ∀ ftype : U64, reply ≠ 0#u64 → (do + let i3 ← obj.Tcb.sc st hd s3 + let can_donate ← if (i3 != 0#u64) = true then ok (ftype != fl4_abi.consts.fault.Timeout) else ok false + ipc.reply_push st ar s3 a hd thread reply can_donate) ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + intro ftype hne + step with obj.Tcb.sc.spec as ⟨i3, _⟩ + split <;> (try simp only [Aeneas.Std.bind_ok]) <;> exact E1 _ hne + have E2 : (do + let s4 ← sched.set_thread_state st s3 hd sched.TS_INACTIVE + ok (s4, a)) ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + refine WP.spec_bind (WP.spec_and (WP.spec_and (sched.set_thread_state.snd hd _ b3 B3.vr Y3 hdT + (by rw [hds3]; exact send_ne.1)) + (sts_all s3 hd _ Q3 R3 q3 hB3 hX3 hS3 hSg3 hdT not_blocked_inactive inactive_ne + (Or.inl hx3) (hX3.noref (q3.tcbs _ hdT) (by rw [hds3]; exact send_ne.1) (by rw [hds3]; exact send_ne.2)) + ⟨fun c hc' p hp hm => absurd hm (q3.notQ hdT dq hc' hp), + fun c hc' hm => absurd hm (q3.notR hdT dr hc'), fun e' => absurd e' da⟩)) + (sched.set_thread_state.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s3 hd _ q3 hdT)) + fun s4 hh => ?_ + obtain ⟨⟨⟨T4, -⟩, h4, hB4, hX4, hS4, hSg4, -, -⟩, fk4⟩ := hh + simp only [WP.spec_ok, WP.uncurry'_pair] + exact fin (p := 0#u64) (SndT.dmd b3 h0 Y3 T4 (fun z hz => by rw [hz]; exact Or.inr (Or.inr lhd)) + (EpM.ofFootDX b3 (Foot.d fk4))) ⟨⟨Q3, R3, h4.congrX empty_congr'⟩, hB4, hX4, hS4, hSg4⟩ n00 + have E3 : (do + let s4 ← sched.set_thread_state st s3 hd sched.TS_RUNNING + let s5 ← sched.possible_switch_to st s4 hd + ok (s5, a)) ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + refine WP.spec_bind (WP.spec_and (WP.spec_and (sched.set_thread_state.snd hd _ b3 B3.vr Y3 hdT + (by rw [hds3]; exact send_ne.1)) + (sts_all s3 hd _ Q3 R3 q3 hB3 hX3 hS3 hSg3 hdT not_blocked_running running_ne + (Or.inl hx3) (hX3.noref (q3.tcbs _ hdT) (by rw [hds3]; exact send_ne.1) (by rw [hds3]; exact send_ne.2)) + ⟨fun _ _ _ _ _ => runnable_running, fun _ _ _ => runnable_running, fun _ => runnable_running⟩)) + (sched.set_thread_state.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s3 hd _ q3 hdT)) + fun s4 hh => ?_ + obtain ⟨⟨⟨T4, e4⟩, h4, hB4, hX4, hS4, hSg4, -, k4⟩, fk4⟩ := hh + have h4' := h4.congrX empty_congr' + have b4 : BK s4 := ⟨⟨Q3, R3, h4'⟩, hB4, hX4, hS4, hSg4⟩ + refine WP.spec_bind (WP.spec_and (sched.possible_switch_to.snd (E := fun q => q = hd) hd b4 T4.vr T4.sym hdT + (by rw [e4]; exact runnable_running) (fun h0' => by rw [k4.scf hdT] at h0' ⊢; exact hdA h0')) + (sched.possible_switch_to.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s4 hd h4' hdT)) + fun s5 hh => ?_ + obtain ⟨⟨T5, b5⟩, fk5⟩ := hh + simp only [WP.spec_ok, WP.uncurry'_pair] + exact fin (p := 0#u64) (SndT.dmd b3 h0 Y3 (T4.trans T5) (fun z hz => by rw [hz]; exact Or.inr (Or.inr lhd)) + (EpM.ofFootDX b3 ((Foot.d fk4).trans (Foot.d fk5)))) b5 n00 + step with obj.Tcb.fault_type.any as ⟨ftype⟩ + repeat' split + all_goals first + | exact E2 + | exact E3 + | (rename_i hh; exact E1' ftype (by simpa using hh)) + +set_option maxHeartbeats 8000000 in +/-- **`take_reply` keeps the walk bundle**: a reply naming another thread has it taken off (`cancel_ipc.dmdC`, a +`DMD i` step; `i` named, live as blocked on the reply or a receive); the returned reply is null or the cap's. -/ +theorem take_reply.sw {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} {s0 s : S} (a : A) (t : U64) + (rc : capability.Cap) (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s0)) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hcap : ∀ p g, rc = .Reply p g → p ∈ H.replies) : + endpoint.take_reply st ar s a t rc ⦃ r s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ + (r = 0#u64 ∨ ∃ g, rc = .Reply r g) ⦄ := by + have h := W.1.blk + have h0 := W.1.sys.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + unfold endpoint.take_reply + split + case h_5 p g => + have hp := hcap p g rfl + step with obj.Reply.tcb.blk as ⟨i, ei⟩ + step with obj.Tcb.is_null.spec as ⟨b, eb⟩ + split + · exact (WP.spec_ok _).2 ⟨W, Or.inr ⟨g, rfl⟩⟩ + rename_i hb + have hi0 : i ≠ 0#u64 := fun e => hb (by rw [eb, e]; rfl) + step with tcb_ne.blk as ⟨b1, eb1⟩ + split + · obtain ⟨-, hiT, -, hist⟩ := hX.2.1.back p hp (by rw [← ei]; exact hi0) + rw [← ei] at hiT hist + have hna : L.actionW s ≠ i := fun ea => by + have := (q.actOK (ea ▸ hiT)).1 + rw [ea] at this + rcases hist with e | e <;> rw [e] at this + · exact not_runnable_reply this + · exact blocked_not_runnable (Or.inr (Or.inl rfl)) this + refine WP.spec_bind (ipc.cancel_ipc.dmdC a i h hiT h0 W.1.sys.vr W.1.sym hna) ?_ + rintro ⟨s1, a1⟩ ⟨b1', -, d1, -⟩ + try simp only [WP.uncurry'_pair] + refine (WP.spec_ok _).2 ⟨W.dmd I hc0 hks (fun k hk hia => ?_) d1 b1', Or.inr ⟨g, rfl⟩⟩ + have hiH : H i = some .tcb := hiT + rw [hiH] at hk; cases hk + exact W.1.sys.ln i .tcb hiH (LiveQ.tcb hiT (Or.inl (by + rcases hist with e | e <;> rw [e] <;> simp [sched.TS_BLOCKED_ON_REPLY, sched.TS_BLOCKED_ON_RECV, + sched.TS_INACTIVE]))) hia + · exact (WP.spec_ok _).2 ⟨W, Or.inr ⟨g, rfl⟩⟩ + all_goals exact (WP.spec_ok _).2 ⟨W, Or.inl rfl⟩ + +set_option maxHeartbeats 64000000 in +/-- **`receive_ipc` from the walk bundle to the Reply-walk bundle** (QueueIpc's `receive_ipc.inv_rp` walk): +`take_reply.sw`; the active bound notification (`complete_signal.dmd`, the notification named: live by its bound +thread); the bound notification's SC going back (`maybe_return_sched_context.dmd`); on an idle or receiving +endpoint the wait (`wait_for_sender.dmE`, the endpoint and the reply named by their caps) or the poll's badge +(`reg_badge.dmd`); on a sending one `receive_from_sender.rpw`. The facts `receive_from_sender.rpw` takes at its start +come from `take_reply.inv`/`.stt`, `maybe_return_sched_context.inv`, `RecvPre.rvi` (the existing [J] `RunVcpuInv`) +and the walk's `OSKeep` (the caps). -/ +theorem receive_ipc.rpw (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s0 s : S} (a : A) (t : U64) + (cap : capability.Cap) (blocking : Bool) (rc : capability.Cap) (e : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hc : CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) + (hptr : capability.Cap.ptr cap = ok e) (hH : H e = some .ep) + (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) + (hcap : ∀ p g, rc = .Reply p g → p ∈ H.replies ∧ ∃ x ∈ OS, ∃ g', capA st s x = .Reply p g') + (hRV : RunVcpuInv st H.tcbs s) (hvm : L.mem s (stA t) ≠ sched.TS_RUNNING_VM) : + endpoint.receive_ipc st ar s a t cap blocking rc ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have h := W.1.blk + have h0 := W.1.sys.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have ht := hc.mem + have hta := q.tcbs t ht + have hcR : ∀ p g, rc = .Reply p g → p ∈ H.replies := fun p g e => (hcap p g e).1 + have keepC : ∀ {s' : S}, SW st H Cs OS Vc ia ie Ac s0 s' → ∀ z ∈ OS, capA st s' z = capA st s z := + fun W' z hz => (W'.2.1.capA hz).trans (W.2.1.capA hz).symm + unfold endpoint.receive_ipc + rw [hptr] + simp only [Aeneas.Std.bind_ok] + refine WP.spec_bind (spec_eq' (WP.spec_and (WP.spec_and (endpoint.take_reply.inv ar s a t rc Q R q hB hX hS hSg hc hcR) + (take_reply.sw a t rc I hc0 hks W hcR)) (endpoint.take_reply.stt ar s a t rc Q R q hB hX hSg hc hcR))) ?_ + rintro ⟨reply, s1, a1⟩ ⟨eq1, ⟨⟨h1, hB1, hX1, hS1, hSg1, hc1, hi1, hr1, kb1, ib1⟩, W1, rret⟩, st1⟩ + try simp only [WP.uncurry'_pair] + have b1 : BK s1 := ⟨⟨Q, R, h1⟩, hB1, hX1, hS1, hSg1⟩ + have hrun1 : L.mem s1 (stA t) ≠ sched.TS_INACTIVE := by rw [st1]; exact hrun + -- the end on the endpoint + have tail : ∀ (s2 : S) (a2 : A), SW st H Cs OS Vc ia ie Ac s0 s2 → CanBlock st H.tcbs Ac s2 t → + L.mem s2 (stA t) = L.mem s (stA t) → RecvPre st ar s a t rc s2 → + (reply ≠ 0#u64 → reply ∈ H.replies ∧ (L.mem s2 (rTcbA reply) = 0#u64 ∨ L.mem s2 (rTcbA reply) = t)) → + (do + let st0 ← obj.Ep.state st e s2 + if st0 = obj.EP_IDLE then do + let s3 ← endpoint.wait_for_sender st s2 t e blocking reply + ok (s3, a2) + else if st0 = obj.EP_RECV then do + let s3 ← endpoint.wait_for_sender st s2 t e blocking reply + ok (s3, a2) + else endpoint.receive_from_sender st ar s2 a2 t e reply) ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + intro s2 a2 W2 hc2 st2 rp2 hr2 + have b2 := W2.1.blk + obtain ⟨⟨Q2, R2, q2⟩, hB2, hX2, hS2, hSg2⟩ := id b2 + have hrun2 : L.mem s2 (stA t) ≠ sched.TS_INACTIVE := by rw [st2]; exact hrun + have hp2 : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s2 x) e k := fun k hk => by + obtain ⟨x, hx, hn⟩ := hp k hk + exact ⟨x, hx, by rw [keepC W2 x hx]; exact hn⟩ + have hrn2 : ∀ k, H reply = some k → ∃ x ∈ OS, NamesA (capA st s2 x) reply k := fun k hk => by + rcases rret with e0 | ⟨g, eg⟩ + · rw [e0, h0] at hk; cases hk + · obtain ⟨hR, x, hx, g', hx'⟩ := hcap reply g eg + have hR' : H reply = some .reply := hR + rw [hR'] at hk; cases hk + exact ⟨x, hx, by rw [keepC W2 x hx, hx']; exact names_reply⟩ + have hrc2 : reply ≠ 0#u64 → ∃ x ∈ OS, ∃ g, capA st s2 x = .Reply reply g := fun hne => by + rcases rret with e0 | ⟨g, eg⟩ + · exact absurd e0 hne + · obtain ⟨-, x, hx, g', hx'⟩ := hcap reply g eg + exact ⟨x, hx, g', by rw [keepC W2 x hx, hx']⟩ + have WF : (L.epState s2 e = 0#u64 ∨ L.epState s2 e = 2#u64) → (do + let s3 ← endpoint.wait_for_sender st s2 t e blocking reply + ok (s3, a2)) ⦃ s' _ => RpW st H Cs OS Vc ia ie Ac s0 s' ⦄ := fun hst0 => by + cases blocking + · have NB : endpoint.wait_for_sender st s2 t e false reply ⦃ s3 => SW st H Cs OS Vc ia ie Ac s0 s3 ⦄ := by + unfold endpoint.wait_for_sender + simp only [Bool.false_eq_true, ↓reduceIte] + refine WP.spec_mono (obj.Tcb.set_reg.badge s2 t 0#u64 hta) ?_ + rintro s3 rfl + obtain ⟨k1, k2, k3, k4, k5⟩ := badge0_all q2 hB2 hX2 hS2 hSg2 ht + exact W2.dmd0 I hc0 hks (reg_badge.dmd (v := 0#u64) b2 h0 W2.1.sym W2.1.sys.vr ht) + ⟨⟨Q2, R2, k1⟩, k2, k3, k4, k5⟩ + refine WP.spec_bind NB fun s3 W3 => ?_ + exact (WP.spec_ok _).2 W3.1 + · refine WP.spec_bind (wait_for_sender.dmE t e reply b2 h0 W2.1.sym W2.1.sys.vr hc2 hrun2 hH hst0 hr2) + fun s3 hh => ?_ + refine (WP.spec_ok _).2 (W2.dme I hc0 hks (fun q k hq hk => ?_) hh.2 hh.1).1 + rcases hq with rfl | rfl + · exact hp2 k hk + · exact hrn2 k hk + step with obj.Ep.state.spec as ⟨v, hv⟩ + split + · rename_i h00 + exact WF (Or.inl (by rw [← hv, h00, ep_idle_val])) + · split + · rename_i _ h00 + exact WF (Or.inr (by rw [← hv, h00, ep_recv_val'])) + · rename_i h01 h02 + have hst1 : L.epState s2 e = 1#u64 := by + rcases ep_state3 q2 hH with e0 | e0 | e0 + · exact absurd (by rw [hv, e0, ep_idle_val]) h01 + · exact e0 + · exact absurd (by rw [hv, e0, ep_recv_val']) h02 + exact receive_from_sender.rpw hA a2 t e reply Pz W2 I.del.sca I.ts hks I.del.vr hc2 hrun2 hH hst1 hp2 + hr2 hrc2 (RecvPre.rvi Q R q hB hX hS hSg hc hcR hRV rp2) (by rw [st2]; exact hvm) + -- the bound notification's SC + have mid : ∀ (i : U64), (if blocking then notification.maybe_return_sched_context st s1 i t else ok s1) + ⦃ s2 => SW st H Cs OS Vc ia ie Ac s0 s2 ∧ CanBlock st H.tcbs Ac s2 t ∧ L.mem s2 (stA t) = L.mem s (stA t) ∧ + RecvPre st ar s a t rc s2 ∧ + (reply ≠ 0#u64 → reply ∈ H.replies ∧ (L.mem s2 (rTcbA reply) = 0#u64 ∨ L.mem s2 (rTcbA reply) = t)) ⦄ := by + intro i + split + · refine WP.spec_mono (spec_eq' (WP.spec_and (maybe_return_sched_context.dmd 0#u64 i t b1 h0 W1.1.sym + W1.1.sys.vr ht (LiveQ.tcb ht (Or.inl hrun1)) ⟨hc1.nq, hc1.nr, hc1.na⟩ (by rw [hi1]; exact hc.ni)) + (notification.maybe_return_sched_context.inv s1 i t Q R h1 hB1 hX1 hS1 hSg1 ht + ⟨hc1.nq, hc1.nr, hc1.na⟩ (by rw [hi1]; exact hc.ni)))) fun s2 ⟨eq2, ⟨d2, b2⟩, hh⟩ => ?_ + obtain ⟨-, -, -, -, -, q2, st2, na2, ii2, rt2, -, -, sc2⟩ := hh + refine ⟨W1.dmd0 I hc0 hks d2 b2, hc1.mrsc q2 st2 na2 ii2 sc2, st2.trans st1, + ⟨reply, s1, a1, eq1, Or.inr ⟨i, eq2⟩⟩, fun hn => ?_⟩ + obtain ⟨r1, r2⟩ := hr1 hn + rw [rt2 _ r1]; exact ⟨r1, r2⟩ + · exact (WP.spec_ok _).2 ⟨W1, hc1, st1, ⟨reply, s1, a1, eq1, Or.inl rfl⟩, hr1⟩ + step with obj.Tcb.bound_ntfn.val as ⟨i, ei⟩ + split + · rename_i hi0 + step with obj.Ntfn.state.spec as ⟨v1, hv1⟩ + split + · have hn0' : L.mem s1 (boundA t) ≠ 0#u64 := by rw [← ei]; exact bne_ne hi0 + have hn : i ∈ H.ntfns := by rw [ei]; exact hX1.2.2.bnd t ht hn0' + have hHn : H i = some .ntfn := hn + have bt : L.mem s1 (ntfnBtA i) = t := by rw [ei]; exact hX1.2.2.bs.tb t ht hn0' + have hRV1 : RunVcpuInv st H.tcbs s1 := RecvPre.rvi Q R q hB hX hS hSg hc hcR hRV ⟨reply, s1, a1, eq1, Or.inl rfl⟩ + refine WP.spec_mono (complete_signal.dmd hA a1 i t b1 h0 W1.1.sym W1.1.sys.vr hc1 hrun1 hn hHn + (hRV1.zero ht (by rw [st1]; exact hvm))) ?_ + rintro ⟨s3, a3⟩ hr + simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨d3, b3⟩ := hr + refine (W1.dmd I hc0 hks (fun k hk hia => ?_) d3 b3).1 + rw [hHn] at hk; cases hk + exact W1.1.sys.ln i .ntfn hHn (LiveQ.ntfn hHn (Or.inr (Or.inl (by rw [bt]; exact ne0_of_heap h0 ht)))) hia + · refine WP.spec_bind (mid i) ?_ + rintro s2 ⟨W2, hc2, st2, rp2, hr2⟩ + exact tail s2 a1 W2 hc2 st2 rp2 hr2 + · try simp only [Aeneas.Std.bind_ok] + exact tail s1 a1 W1 hc1 st1 ⟨reply, s1, a1, eq1, Or.inl rfl⟩ hr1 + +/-- **A looked-up cap is an `OS` slot's cap, typed** (MdbIrqH's `cspace.lookup_slot.cov`, the slot's `SlotTy`). -/ +theorem cspace.lookup_cap.os {s : S} (hT : SlotTy st H.tcbs H.omega H.frame H H.replies H.ntfns OS s) {t : U64} + (ht : t ∈ OS) (cptr : U64) : + cspace.lookup_cap st s t cptr ⦃ r => ∀ c, r = .Ok c → + ∃ x ∈ OS, capA st s x = c ∧ CapTyped H H.replies H.ntfns c ⦄ := by + unfold cspace.lookup_cap + refine WP.spec_bind (cspace.lookup_slot.cov hT ht cptr) fun r hr => ?_ + rcases r with r1 | lf + · obtain ⟨hin, -⟩ := hr r1 rfl + simp only + rw [capA_eq, bind_ok] + exact (WP.spec_ok _).2 fun c e => by cases e; exact ⟨r1.slot, hin, rfl, (hT _ hin).capTy.1.1⟩ + · exact (WP.spec_ok _).2 fun c e => by cases e + +section top +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} + {n : U64} + +set_option maxHeartbeats 64000000 in +/-- **`handle_recv` keeps the S1a step post** (QueueXferA's `handle_recv.bxiA` cases): the caps looked up are `OS` +slots' caps, typed (`cspace.lookup_cap.os`), so the endpoint, notification and reply they name are named; +`receive_ipc.rpw`, `receive_signal.sw`, the cap faults (`handle_fault.rpw`), closed by `S1aStepR2K.ofRpPost`. +Per-state facts: the current thread can block and is not inactive, its placement `Pz`, the existing [J] +`RunVcpuInv` and `nvm` (contract §5), and the notification states (the existing [J] of QueueEntryA's `recvOK`, +as `handle_recv.bxiA`'s `h3`). -/ +theorem syscall.handle_recv.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + {s : S} (a : A) (blk rep : Bool) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hc : CanBlock st H.tcbs Ac s (L.curW s)) (hrun : L.mem s (stA (L.curW s)) ≠ sched.TS_INACTIVE) + (h3 : ∀ n ∈ H.ntfns, L.epState s n ≠ 3#u64) (hRV : RunVcpuInv st H.tcbs s) + (hvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + syscall.handle_recv st ar s a blk rep ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have hc0 := Pz.core0 + have W : SW st H Cs OS Vc ia ie Ac s s := SW.start B Y h + have ht := hc.mem + have hcO : L.curW s ∈ OS := by have := I.ts _ ht 0#u64 (by simp); rwa [slotIdx0] at this + have fin : ∀ {r : S × A}, RpW st H Cs OS Vc ia ie Ac s r.1 → S1aStepR2K st Cs Ub Kt KLv ia ie n r.1 := + fun P => S1aStepR2K.ofRpPost I P.post C Df R sep KC + have CF : ∀ cptr lf, syscall.cap_fault_recv st ar s a cptr lf ⦃ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := fun cptr lf => by + unfold syscall.cap_fault_recv + step with sched.cur_thread.spec as ⟨t1, e1⟩ + have e1' : t1 = L.curW s := e1 + subst e1' + exact faults.handle_fault.s1a hA a _ _ I B Y h hks Pz hc hrun hRV C Df R sep KC + have ok0 : (ok (s, a) : Result (S × A)) ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + (WP.spec_ok _).2 (fin (r := (s, a)) W.1) + have RI : ∀ (c rc : capability.Cap) (e : U64), capability.Cap.ptr c = ok e → H e = some .ep → + (∃ x ∈ OS, NamesA (capA st s x) e .ep) → + (∀ p g, rc = .Reply p g → p ∈ H.replies ∧ ∃ x ∈ OS, ∃ g', capA st s x = .Reply p g') → + endpoint.receive_ipc st ar s a (L.curW s) c blk rc ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + fun c rc e hp hH hn hr => WP.spec_mono (receive_ipc.rpw hA a _ c blk rc e I hc0 hks Pz W hc hrun hp hH + (fun k hk => by rw [hH] at hk; cases hk; exact hn) hr hRV hvm) fun r hh => fin hh + have RS : ∀ p, p ∈ H.ntfns → H p = some .ntfn → (∃ x ∈ OS, NamesA (capA st s x) p .ntfn) → + notification.receive_signal st ar s a (L.curW s) p blk ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + fun p hn hH hx => WP.spec_mono (receive_signal.sw hA a _ p blk I hc0 hks W hc hrun hn hH (h3 p hn) + (hRV.zero ht hvm) (fun k hk _ => by rw [hH] at hk; cases hk; exact hx)) fun r hh => fin hh.1 + have hlk := cspace.lookup_cap.os (s := s) Pz.ty hcO + unfold syscall.handle_recv + step with sched.cur_thread.spec as ⟨t, et⟩ + have et' : t = L.curW s := et + subst et' + step with obj.Tcb.reg.spec as ⟨cptr⟩ + refine WP.spec_bind (hlk cptr) fun r hr => ?_ + split + · rename_i c + obtain ⟨xc, hxc, exc, hct⟩ := hr c rfl + split + all_goals first | exact CF _ _ | skip + · -- an endpoint cap + rename_i p b x rcv z w + have hpH := hct.1 p b x rcv z w rfl + have hn : ∃ y ∈ OS, NamesA (capA st s y) p .ep := ⟨xc, hxc, by rw [exc]; exact names_ep⟩ + split + · split + · step with obj.Tcb.reg.spec as ⟨rptr⟩ + refine WP.spec_bind (hlk rptr) fun r1 hr1 => ?_ + split + · rename_i c1 + obtain ⟨x1, hx1, ex1, hct1⟩ := hr1 c1 rfl + split + all_goals first | exact CF _ _ | skip + exact RI _ _ p rfl hpH hn (fun q g e => ⟨hct1.2.2 q g e, x1, hx1, g, by rw [ex1, e]⟩) + · split + all_goals first | exact ok0 | exact CF _ _ + · exact RI _ _ p rfl hpH hn (fun q g e => by cases e) + · exact CF _ _ + · -- a notification cap + rename_i p b x rcv + obtain ⟨hpN, hpH⟩ := hct.2.1 p b x rcv rfl + have hn : ∃ y ∈ OS, NamesA (capA st s y) p .ntfn := ⟨xc, hxc, by rw [exc]; exact names_ntfn⟩ + refine WP.spec_bind (obj.Ntfn.bound_tcb.val s p) fun bd _ => ?_ + split + · split + · split + · exact CF _ _ + · exact RS p hpN hpH hn + · exact RS p hpN hpH hn + · exact CF _ _ + · split + all_goals first | exact ok0 | exact CF _ _ + +end top + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCRegs.lean b/proofs/Fl4ProofsA64/P1/S1aCRegs.lean new file mode 100644 index 000000000..18833bcd9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCRegs.lean @@ -0,0 +1,233 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a9)): **TCB WriteRegisters keeps every capability** (tcb.rs +`write_registers`). + +* **`tcb.write_registers_loop0.dfR` / `loop1.dfR`**: the register loops are `DF` steps (QueueDecTcb's `.rf` loops + with `set_reg.dfX`). +* **`resched.dm`**: `reschedule_required` is a `DM p` step. +* **`syscall.decode_invocation.writeRegs_armS`**: the stall, the caller's restart and the register writes are one + `DF` step; then `restart` (S1aCRestart) if asked, and the reschedule. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCRestart + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "FK" => K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) + +set_option maxHeartbeats 1000000 in +theorem tcb.write_registers_loop0.dfR {c : U64} {Ko : Set Nat} {s0 s : S} {dest buf ct n i : U64} + (C : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s0) (hd : dest ∈ H.tcbs) + (h : DF st H Cs c Ko s0 s ∧ WritesIn st s0 s (XferFoot H.tcbs ∅)) : + tcb.write_registers_loop0 st s dest buf ct n i ⦃ s' => DF st H Cs c Ko s0 s' ∧ WritesIn st s0 s' (XferFoot H.tcbs ∅) ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold tcb.write_registers_loop0 + apply loop.spec_decr_nat (measure := fun y => 17 - y.2.val) + (inv := fun y => DF st H Cs c Ko s0 y.1 ∧ WritesIn st s0 y.1 (XferFoot H.tcbs ∅)) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + try dsimp only + unfold tcb.write_registers_loop0.body + try dsimp only + split + swap + · exact (WP.spec_ok _).2 h1 + rename_i hj + have hj' : j.val < 17 := by simpa [tcb.N_FRAME, tcb.N_GP] using hj + split + swap + · exact (WP.spec_ok _).2 h1 + simp only [lift, bind_ok] + have hl : (UScalar.cast .Usize j : Usize).val < regs.FRAME_REGISTERS.val.length := by + rw [regs.FRAME_REGISTERS.property]; rw [cast_usize_small (by omega)]; simp; omega + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec _ _ hl) fun r hr => ?_ + have hr' : r.val < 384 := by + rw [hr]; unfold regs.FRAME_REGISTERS + exact regs_lt _ _ (by simp [layout.reg.FAULT_IP, layout.reg.SP_EL0, layout.reg.SPSR_EL1, layout.reg.X0, layout.reg.X1, layout.reg.X2, layout.reg.X3, layout.reg.X4, layout.reg.X5, layout.reg.X6, layout.reg.X7, layout.reg.X8, layout.reg.X16, layout.reg.X17, layout.reg.X18, layout.reg.X29, layout.reg.X30]) _ (List.getElem_mem _) -- a64: A64 FRAME_REGISTERS + --]) _ (List.getElem_mem _) + step as ⟨i2, _⟩ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s1 ct buf _ hS) fun v _ => ?_ + refine WP.spec_bind (P0.regs.sanitise_for_tcb.p0 st s1 dest r v hS) fun v5 _ => ?_ -- a64 + refine WP.spec_bind (obj.Tcb.set_reg.dfX (c := c) (Ko := Ko) (v := v5) (s := s1) (C.of_lv h1.1.lv) hd hr') + fun s2 ⟨d2, w2⟩ => ?_ + step as ⟨j2, hj2⟩ + exact ⟨h1.1.trans d2, rf_trans h1.2 w2, by omega⟩ + · exact h + +set_option maxHeartbeats 1000000 in +theorem tcb.write_registers_loop1.dfR {c : U64} {Ko : Set Nat} {s0 s : S} {dest buf ct n i : U64} + (C : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s0) (hd : dest ∈ H.tcbs) + (h : DF st H Cs c Ko s0 s ∧ WritesIn st s0 s (XferFoot H.tcbs ∅)) : + tcb.write_registers_loop1 st s dest buf ct n i ⦃ s' => DF st H Cs c Ko s0 s' ∧ WritesIn st s0 s' (XferFoot H.tcbs ∅) ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold tcb.write_registers_loop1 + apply loop.spec_decr_nat (measure := fun y => 19 - y.2.val) + (inv := fun y => DF st H Cs c Ko s0 y.1 ∧ WritesIn st s0 y.1 (XferFoot H.tcbs ∅)) + · rintro ⟨s1, j⟩ h1 + simp only at h1 + try dsimp only + unfold tcb.write_registers_loop1.body + try dsimp only + split + swap + · exact (WP.spec_ok _).2 h1 + rename_i hj + have hj' : j.val < 19 := by simpa [tcb.N_FRAME, tcb.N_GP] using hj + step as ⟨i0, _⟩ + split + swap + · exact (WP.spec_ok _).2 h1 + simp only [lift, bind_ok] + have hl : (UScalar.cast .Usize j : Usize).val < regs.GP_REGISTERS.val.length := by + rw [regs.GP_REGISTERS.property]; rw [cast_usize_small (by omega)]; simp; omega + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec _ _ hl) fun r hr => ?_ + have hr' : r.val < 384 := by + rw [hr]; unfold regs.GP_REGISTERS + exact regs_lt _ _ (by simp [layout.reg.X9, layout.reg.X10, layout.reg.X11, layout.reg.X12, layout.reg.X13, layout.reg.X14, layout.reg.X15, layout.reg.X19, layout.reg.X20, layout.reg.X21, layout.reg.X22, layout.reg.X23, layout.reg.X24, layout.reg.X25, layout.reg.X26, layout.reg.X27, layout.reg.X28, layout.reg.TPIDR_EL0, layout.reg.TPIDRRO_EL0] -- a64: A64 GP_REGISTERS + ) _ (List.getElem_mem _) + step as ⟨i2, _⟩ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s1 ct buf _ hS) fun v _ => ?_ + refine WP.spec_bind (P0.regs.sanitise_for_tcb.p0 st s1 dest r v hS) fun v5 _ => ?_ -- a64 + refine WP.spec_bind (obj.Tcb.set_reg.dfX (c := c) (Ko := Ko) (v := v5) (s := s1) (C.of_lv h1.1.lv) hd hr') + fun s2 ⟨d2, w2⟩ => ?_ + step as ⟨j2, hj2⟩ + exact ⟨h1.1.trans d2, rf_trans h1.2 w2, by omega⟩ + · exact h + +/-- **`reschedule_required`** is a `DM p` step. -/ +theorem resched.dm (p : U64) {s : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) : + sched.reschedule_required st s ⦃ s' => (BK s') ∧ FK s s' ∧ DM st H Cs p s s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + refine WP.spec_mono (WP.spec_and (sched.reschedule_required.schX (Sg := H.frame) s Q R q hB hSg) + (K8.sched.reschedule_required.blk s h)) ?_ + rintro s' ⟨⟨-, -, f, -⟩, h', fw⟩ + have f' : FK s s' := fw.mono (Set.empty_subset _) + have d := DMD.ofNone (p := p) h h0 Y VR (K8.Foot.d fw) (LvF.of_fr C f) + exact ⟨h', f', ⟨f', d.lv, d.idle, d.isc, d.vr, d.sym⟩⟩ + +/-- The slot cap names the target thread at a state keeping the `OS` words. -/ +theorem namedT_keep {s s' : S} {slot t : U64} (hs : slot ∈ OS) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (ht : t ∈ H.tcbs) (k : OSKeep st OS s s') : + ∀ k', H t = some k' → ∃ x ∈ OS, NamesA (capA st s' x) t k' := fun k' hk => by + have e : H t = some .tcb := ht + rw [e] at hk; cases hk + refine ⟨slot, hs, ?_⟩ + rw [k.capA hs, okinj ((capA_eq s slot).symm.trans hcap)] + exact names_thread + +set_option maxHeartbeats 2000000 in +/-- **TCB WriteRegisters** keeps every capability. -/ +theorem syscall.decode_invocation.writeRegs_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBWriteRegisters) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + have hS : P0.StoreTotal st := L.total + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + have key : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + DmPost st H Cs OS ia ie Ac s r.2.1 ⦄ := by + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.stS hA a t D.bxi) ?_ + rintro ⟨s1, a1⟩ ⟨h1, d1⟩ + try simp only [uncurry_apply_pair] + iterate 4 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetEPTRoot, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + have E1 : DmPost st H Cs OS ia ie Ac s s1 := + DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + h1.bxi.blk (DmW.ofDF d1) + unfold tcb.decode_write_registers + refine spec_ite (fun _ => ?_) fun _ => ?_ + · simp only [error.truncated, bind_ok]; exact (WP.spec_ok _).2 E1 + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun flags _ => ?_ + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun w _ => ?_ + step as ⟨i, _⟩ + split + · simp only [error.truncated, bind_ok]; exact (WP.spec_ok _).2 E1 + refine WP.spec_bind (sched.cur_thread.spec s1) fun ct _ => ?_ + simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 E1 + refine WP.spec_bind (tcb.restart_caller.restartRK D P B Y h1 d1) fun s2 ⟨R, d2⟩ => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (Pₘ := fun r : S × A => DmPost st H Cs OS ia ie Ac s r.1) ?_ + (fun r hr => by obtain ⟨_, _⟩ := r; exact (WP.spec_ok _).2 hr) + unfold tcb.write_registers + refine WP.spec_bind (sched.cur_thread.spec s2) fun ct2 _ => ?_ + step as ⟨i2, _⟩ + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun nn _ => ?_ + have C2 := LvC.of_blk R.blk + have hT2 := C2.tcb + refine WP.spec_bind (tcb.write_registers_loop0.dfR (c := L.curW s) (Ko := ∅) (s0 := s2) C2 ht + ⟨DF.refl _, WritesIn.refl _ _⟩) fun s3 h3 => ?_ + refine WP.spec_bind (tcb.write_registers_loop1.dfR (c := L.curW s) (Ko := ∅) (s0 := s2) C2 ht h3) fun s4 h4 => ?_ + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st t s4 _ hS) fun pc _ => ?_ + refine WP.spec_bind (obj.Tcb.set_reg.dfX (c := L.curW s) (Ko := ∅) (v := pc) (s := s4) (C2.of_lv h4.1.lv) ht + (by simp [layout.reg.NEXT_IP])) fun s5 ⟨d5, w5⟩ => ?_ + unfold tcb.post_modify_registers + simp only [bind_ok] + have dr : DF st H Cs (L.curW s) ∅ s s5 := d2.trans (h4.1.trans d5) + have b5 := (blk_rf R.blk (rf_trans h4.2 w5)).1 + obtain ⟨B5, Y5⟩ := SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y dr + have k5 : OSKeep st OS s s5 := (DF.osTab I.del.heap I.del.os D.bxi B I.del.vr P.core0 dr).1 + have P5 := P.keepO k5 dr.w.1 + have fin : ∀ (s6 : S) (a6 : A), (BK s6) → FK s5 s6 → DM st H Cs t s5 s6 → + (do + let t_1 ← sched.cur_thread st s6 + let b ← obj.Tcb.Insts.CoreCmpPartialEqTcb.eq t t_1 + if b then do + let s7 ← sched.reschedule_required st s6 + ok (s7, a6) + else ok (s6, a6)) ⦃ r => (BK r.1) ∧ FK s5 r.1 ∧ DM st H Cs t s5 r.1 ⦄ := by + intro s6 a6 b6 f6 d6 + refine WP.spec_bind (sched.cur_thread.spec s6) fun t1 _ => ?_ + simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] + split + · refine WP.spec_bind (resched.dm t b6 B.ly.h0 d6.sym d6.vr) fun s7 ⟨b7, f7, d7⟩ => ?_ + exact (WP.spec_ok _).2 ⟨b7, f6.trans f7, d6.trans d7⟩ + · exact (WP.spec_ok _).2 ⟨b6, f6, d6⟩ + have rs : ∀ (flag : Bool), (if flag then sched.restart st ar s5 a1 t else ok (s5, a1)) ⦃ r => + (BK r.1) ∧ FK s5 r.1 ∧ DM st H Cs t s5 r.1 ⦄ := fun flag => by + cases flag + · have d := DMD.refl (st := st) (H := H) (Cs := Cs) t b5 B.ly.h0 Y5 B5.vr + exact (WP.spec_ok _).2 ⟨b5, WritesIn.refl _ _, ⟨WritesIn.refl _ _, d.lv, d.idle, d.isc, d.vr, d.sym⟩⟩ + · refine WP.spec_mono (sched.restart.dm hA a1 t b5 ht B.ly.h0 B5.vr Y5) ?_ + rintro ⟨s6, a6⟩ hh + simpa only [WP.uncurry'_pair] using hh + refine WP.spec_bind (rs _) ?_ + rintro ⟨s6, a6⟩ ⟨b6, f6, d6⟩ + refine WP.spec_mono (fin s6 a6 b6 f6 d6) ?_ + rintro ⟨s7, a7⟩ ⟨b7, f7, d7⟩ + exact DmPost.mk' (SysL.dfM P5 b5.bxi hSA (namedT_keep P.src hcap ht k5) B5 d7) b7 + (DmW.trans (DmW.ofDF dr) (WritesIn.mono f7 fun _ hb => Or.inr hb)) + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono key fun r d => by + obtain ⟨_, s', a'⟩ := r + have x := ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk + exact ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCRej.lean b/proofs/Fl4ProofsA64/P1/S1aCRej.lean new file mode 100644 index 000000000..6d16153a1 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCRej.lean @@ -0,0 +1,113 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a1, a3)): **the rejected invocations** (contract F2, F3, D1, D2). + +`DecArmRej`: direct `HighVSpace` invocations; unknown labels of CNode, IRQ handler, Frame, PageTable, ASIDControl, +ASIDPool and VCPU caps; `IoPortControl` and `TdxControl` (their labels are `U64::MAX` on AArch64, so a label below +`2^52`, which `MessageInfo` gives, is rejected); `IoPort`, of which no AArch64 cap exists (`SysL.ci`, `IdP`). +Each returns the state unchanged (`rejected_eq`), hence keeps the S1a step post (`rejected_s1a`). + +Named premises: [P] `P0.ArchTotal` (`tdx_active`). +-/ +import Fl4ProofsA64.P1.S1aCKeep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +/-- The invocations `decode_invocation` rejects without writing (module docstring). -/ +def DecArmRej (cap : capability.Cap) (lbl : U64) : Prop := + (∃ p m a, cap = .HighVSpace p m a) ∨ + (∃ p b c d, cap = .CNode p b c d ∧ (lbl < fl4_abi.label.CNodeRevoke ∨ lbl > fl4_abi.label.CNodeRotate)) ∨ + (∃ irq, cap = .IrqHandler irq ∧ lbl ≠ fl4_abi.label.IRQAckIRQ ∧ lbl ≠ fl4_abi.label.IRQSetIRQHandler ∧ + lbl ≠ fl4_abi.label.IRQClearIRQHandler) ∨ + (∃ fp fsz fr fd fm fe fa fv, cap = .Frame fp fsz fr fd fm fe fa fv ∧ lbl ≠ fl4_abi.label.ARMPageMap ∧ + lbl ≠ fl4_abi.label.ARMPageUnmap ∧ lbl ≠ fl4_abi.label.ARMPageClean_Data ∧ + lbl ≠ fl4_abi.label.ARMPageInvalidate_Data ∧ lbl ≠ fl4_abi.label.ARMPageCleanInvalidate_Data ∧ + lbl ≠ fl4_abi.label.ARMPageUnify_Instruction ∧ lbl ≠ fl4_abi.label.ARMPageGetAddress ∧ + lbl ≠ fl4_abi.label.ARMPageTestAndClearAccessed ∧ lbl ≠ fl4_abi.label.ARMPageDeriveSubframe) ∨ + (∃ p m a v, cap = .PageTable p m a v ∧ lbl ≠ fl4_abi.label.ARMPageTableUnmap ∧ + lbl ≠ fl4_abi.label.ARMPageTableMap) ∨ + (cap = .AsidControl ∧ lbl ≠ fl4_abi.label.ARMASIDControlMakePool) ∨ + (∃ p b, cap = .AsidPool p b ∧ lbl ≠ fl4_abi.label.ARMASIDPoolAssign) ∨ + (∃ v, cap = .Vcpu v ∧ lbl ≠ fl4_abi.label.ARMVCPUSetTCB ∧ lbl ≠ fl4_abi.label.ARMVCPUInjectIRQ ∧ + lbl ≠ fl4_abi.label.ARMVCPUReadReg ∧ lbl ≠ fl4_abi.label.ARMVCPUWriteReg ∧ + lbl ≠ fl4_abi.label.ARMVCPUAckVPPI ∧ lbl ≠ fl4_abi.label.ARMVCPUReadState ∧ + lbl ≠ fl4_abi.label.ARMVCPUWriteState ∧ lbl ≠ fl4_abi.label.ARMVCPURun) ∨ + ((cap = .IoPortControl ∨ cap = .TdxControl) ∧ lbl.val < 2 ^ 52) ∨ + (∃ f l o, cap = .IoPort f l o) + +theorem label_ne_max {lbl : U64} (h : lbl.val < 2 ^ 52) : lbl ≠ core.num.U64.MAX := by + intro e + subst e + simp [core.num.U64.MAX] at h + rw [show U64.rMax = 18446744073709551615 from rfl] at h + omega + +/-- **A rejected invocation returns the state unchanged.** -/ +theorem syscall.decode_invocation.rejected_eq (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (hc : obj.Slot.cap st slot s = ok cap) + (src : slot ∈ OS) (B : SysL st H Cs OS ia ie s) (a : A) {lbl : U64} (hr : DecArmRej cap lbl) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => s' = s ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + rcases hr with ⟨p, m, x, rfl⟩ | ⟨p, b, c, d, rfl, h⟩ | ⟨irq, rfl, h1, h2, h3⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, h1, h2, h3, h4, h5, h6, h7, h8, h9⟩ | ⟨p, m, x, v, rfl, h1, h2⟩ | + ⟨rfl, h⟩ | ⟨p, b, rfl, h⟩ | ⟨v, rfl, h1, h2, h3, h4, h5, h6, h7, h8⟩ | ⟨rfl | rfl, h⟩ | ⟨f, l, o, rfl⟩ + · simp [vspace.decode, cur_thread_ok, error.illegal, WP.spec_ok] + · cases fp + · simp only [Bool.false_eq_true, ↓reduceIte, cnode.decode] + rcases h with h | h + · simp [h, error.illegal, WP.spec_ok] + · by_cases h' : lbl < fl4_abi.label.CNodeRevoke + · simp [h', error.illegal, WP.spec_ok] + · simp [h', h, error.illegal, WP.spec_ok] + · simp [WP.spec_ok] + · simp [interrupt.decode_irq_handler, cur_thread_ok, h1, h2, h3, error.illegal, WP.spec_ok] + · simp [vspace.decode, vspace.decode_frame, vspace.as_frame, vspace.is_cache_label, cur_thread_ok, h1, h2, h3, h4, + h5, h6, h7, h8, h9, error.illegal, WP.spec_ok] + · simp [vspace.decode, vspace.decode_page_table, cur_thread_ok, h1, h2, error.illegal, WP.spec_ok] + · simp [vspace.decode, cur_thread_ok, h, error.illegal, WP.spec_ok] + · simp [vspace.decode, cur_thread_ok, h, error.illegal, WP.spec_ok] + · simp [vcpu.decode, h1, h2, h3, h4, h5, h6, h7, h8, error.illegal, WP.spec_ok] + · have e : lbl ≠ fl4_abi.label.X86IOPortControlIssue := by + simp only [fl4_abi.label.X86IOPortControlIssue]; exact label_ne_max h + simp [ioport.decode_control, e, error.illegal, WP.spec_ok] + · have e1 : lbl ≠ fl4_abi.label.X86TdxControlGetReport := by + simp only [fl4_abi.label.X86TdxControlGetReport]; exact label_ne_max h + have e2 : lbl ≠ fl4_abi.label.X86TdxControlExtendRTMR := by + simp only [fl4_abi.label.X86TdxControlExtendRTMR]; exact label_ne_max h + have e3 : lbl ≠ fl4_abi.label.X86TdxControlGetQuote := by + simp only [fl4_abi.label.X86TdxControlGetQuote]; exact label_ne_max h + simp only [tdx.decode] + refine WP.spec_bind (hA.tdx_active a) fun act _ => ?_ + cases act <;> simp [e1, e2, e3, error.illegal, WP.spec_ok] + · have bad := B.ci slot src + rw [show capA st s slot = .IoPort f l o from okinj ((capA_eq s slot).symm.trans hc)] at bad + exact (bad.2.2 f l o rfl).elim + +/-- **A rejected invocation keeps the S1a step post.** -/ +theorem syscall.decode_invocation.rejected_s1a (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (hc : obj.Slot.cap st slot s = ok cap) + (src : slot ∈ OS) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (fu : FrUb st Ub OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) (a : A) {lbl : U64} (hr : DecArmRej cap lbl) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (syscall.decode_invocation.rejected_eq hA hc src B a hr len blk call don fp buf) fun r e => by + obtain ⟨_, s', _⟩ := r + have e' : s' = s := e + subst e' + exact S1aStepR2K.ofKeep ⟨ArmQIAt.refl B Y hb, TabKeepOrZero.refl s', ⟨rfl, fun _ _ _ _ => VsKeep.refl s'⟩, + fun _ _ => ⟨rfl, rfl, rfl, rfl⟩⟩ vr fu vcc C Kc Df R sep KC + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyA.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyA.lean new file mode 100644 index 000000000..5df1fdbca --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyA.lean @@ -0,0 +1,60 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 8): **the Reply cap invocation keeps every capability but two +transfers' slots** (the Reply arm of `decode_invocation`). + +* **`syscall.decode_invocation.reply_armS`**: the caller's restart (MdbIrqCQ's `restartQ`, as MdbSendQ's + `ep_armSAt`), then S1aCReplyM's `do_reply_transfer.rpw`; posting `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK` and the two + transfers' slot fact `XferSlots2` from the decode's start. + +Named premises: [P] `P0.ArchTotal`. Case facts: none new (`DecPre.rv`'s `RunVcpuInv`, as `ep_armSAt`). +-/ +import Fl4ProofsA64.P1.S1aCReplyM + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc U Ac : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +set_option maxHeartbeats 4000000 in +/-- **The Reply arm of `decode_invocation`** (module docstring). -/ +theorem syscall.decode_invocation.reply_armS (hA : P0.ArchTotal ar) {Ub Pt : Set U64} {K : capability.Cap → Prop} + {Ty : S → Prop} {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p : U64} {g : Bool} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Reply p g) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Reply p g) blk call don fp buf extra + ⦃ _ s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + XferSlots2 st H OS Vc s s' ⦄ := by + have hSA : ScApart H.scs H.scBits OS := I.del.sca + have hTS : TcbSlotsOS H.tcbs OS := I.ts + have hpR : p ∈ H.replies := D.cap.1.2.2 p g rfl + have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e' : ct = L.curW s := ect + subst e' + try dsimp only + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.restartQ I D P B Y) + (sched.set_thread_state.restart_blk (Es := ∅) s _ D.bxi.blk hct (runnable_ok D.run).1 + (runnable_ok D.run).2)) ?_ + rintro s1 ⟨⟨R1, Q1, k1, a1⟩, h1, -, -, kt1⟩ + have kb1 : L.ksb s1 = L.ksb s := R1.jv.ksb + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s1) Pt := by rw [kb1]; exact I.del.vr + have hks1 : HeapKsOff H (L.ksb s1) := by rw [kb1]; exact hks + refine WP.spec_bind (ipc.do_reply_transfer.rpw (Vc := Vc) hA a (L.curW s) p g (P.keepO k1 kb1) R1.sys R1.sym h1 + hSA hTS hks1 hvr1 hpR hct (D.rv.restart kt1 (D.rv.zero hct D.nvm))) fun r hh => ?_ + obtain ⟨s2, a2⟩ := r + simp only [WP.uncurry'_pair] at hh + obtain ⟨S2, Y2, b2, xc, xv, q, x1, v1, x2, v2⟩ := hh + have A1 := ArmQIAt.ofDelR R1 Q1 a1.toVs + have A2 := ArmQIAt.ofXC (ia := ia) (ie := ie) ⟨S2, Y2⟩ ⟨Ac, b2⟩ xc xv.1.toVs + have vk := ArmVsK.trans a1 k1 xv.1 + exact (WP.spec_ok _).2 ⟨A1.1.transV A2.1 vk.toVs, A1.2.trans A2.2, vk, q, + XferSlots.before (fun z hz => k1.capA hz) x1, (XV.keep a1 k1).trans v1, x2, v2⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyErr.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyErr.lean new file mode 100644 index 000000000..8f60c1312 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyErr.lean @@ -0,0 +1,146 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c7): **`reply_error`** (the error reply of an invocation) to the S1a +step post. + +* **`syscall.reply_error.s1a`**: QueueInvAll's `reply_error.xs` walk over MdbXferQ's normal-transfer carry + (`XKoQ ∧ XV` from the start: `XJX`, every `OS` word and the tables kept): the thread's registers (`XJX.regT`), the + IPC buffer's words (`XJX.buf`, `msg.buf_set.tabK` / `.xv`; the buffer typed by `lookup_bufKC`, as S1aCBufAt), the + message words through MdbXferL's `msg.set_mr.gx` / `faults.set_mrs_lookup_failure.gx`; closed by + `S1aStepR2K.ofRpPost` (no slot changes, `XferSlots.refl`). + +* **`msg.reply_success_empty.s1a`**: the success reply's two registers, over the same carry. + +Named premises: none. Per-state facts: the replied-to thread is a TCB. +-/ +import Fl4ProofsA64.P1.S1aCIrq + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +section top +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} + {n : U64} + +set_option maxHeartbeats 16000000 in +/-- **`reply_error` keeps the S1a step post** (module docstring). -/ +theorem syscall.reply_error.s1a {s : S} (t : U64) (e : error.SysError) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) (ht : t ∈ H.tcbs) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + syscall.reply_error st s t e ⦃ s' => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have hS : P0.StoreTotal st := L.total + have hH := I.del.heap + have hO := I.del.os + have hvr := I.del.vr + have i0 : XKoQ st H Cs OS ia ie Ac ∅ s s ∧ XV st H OS Vc s s := + ⟨⟨⟨XJX.start B Y h, OSKeep.rfl' _⟩, TabKeep.refl s⟩, XV.refl s⟩ + have hR : ∀ s2 r v, (XKoQ st H Cs OS ia ie Ac ∅ s s2 ∧ XV st H OS Vc s s2) → r.val < 384 → + obj.Tcb.set_reg st t s2 r v ⦃ s3 => XKoQ st H Cs OS ia ie Ac ∅ s s3 ∧ XV st H OS Vc s s3 ⦄ := + fun s2 _ _ ⟨h2, x2⟩ hr' => by + have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr + exact WP.spec_mono (XJX.regT (Vc := Vc) hH hO hc0 h2.1.1 hvr2 ht hr') + fun _ ⟨h3, k3, t3, a3⟩ => ⟨⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩, x2.trans (XV.keep a3 k3)⟩ + unfold syscall.reply_error + refine WP.spec_bind (lookup_bufKC B hH (by rw [sbA_slotIdx]; exact I.ts t ht 2#u64 (by simp)) (B.ipc t ht)) + fun buf hb => ?_ + have hB : buf ≠ 0#u64 → ∀ s2 j v, (XKoQ st H Cs OS ia ie Ac ∅ s s2 ∧ XV st H OS Vc s s2) → j.val < 128 → + msg.buf_set st s2 buf j v ⦃ s3 => XKoQ st H Cs OS ia ie Ac ∅ s s3 ∧ XV st H OS Vc s s3 ⦄ := + fun h0 s2 _ _ ⟨h2, x2⟩ hj => by + have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr + have hks2 : HeapKsOff H (L.ksb s2) := by rw [h2.2.1]; exact hks + exact WP.spec_mono (WP.spec_and (WP.spec_and (XJX.buf hH hO h2.1.1 (hb h0).1 h0 hj) + (msg.buf_set.tabK hH hks2 h2.1.1.sys.ly.ksw hvr2 (hb h0).1 (hb h0).2.1 hj)) + (msg.buf_set.xv hH (hb h0).1 (hb h0).2.1 (hb h0).2.2 x2 hj)) + fun _ ⟨⟨⟨h3, k3⟩, t3⟩, x3⟩ => ⟨⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩, x3 k3⟩ + refine WP.spec_bind (hR s _ 0#u64 i0 (by simp [layout.reg.BADGE, layout.reg.X0])) fun s1 h1 => ?_ + refine WP.spec_bind (Pₘ := fun r : U64 × S => XKoQ st H Cs OS ia ie Ac ∅ s r.2 ∧ XV st H OS Vc s r.2) ?_ ?_ + · unfold syscall.error_mrs + split + · exact WP.spec_mono (msg.set_mr.gx h1 hR hB (by simp)) fun r hr => hr.1 + · exact WP.spec_mono (msg.set_mr.gx h1 hR hB (by simp)) fun r hr => hr.1 + · exact (WP.spec_ok _).2 h1 + · refine WP.spec_bind (msg.set_mr.gx h1 hR hB (by simp)) ?_ + rintro ⟨_, s2⟩ ⟨h2, -⟩ + try simp only [WP.uncurry'_pair] + exact WP.spec_mono (msg.set_mr.gx h2 hR hB (by simp)) fun r hr => hr.1 + · exact (WP.spec_ok _).2 h1 + · split + all_goals + refine WP.spec_bind (msg.set_mr.gx h1 hR hB (by simp)) ?_ + rintro ⟨_, s2⟩ ⟨h2, -⟩ + try simp only [WP.uncurry'_pair] + unfold faults.set_mrs_lookup_failure_at + exact faults.set_mrs_lookup_failure.gx + (I := fun x => XKoQ st H Cs OS ia ie Ac ∅ s x ∧ XV st H OS Vc s x) h2 hR hB (by simp) + · exact (WP.spec_ok _).2 h1 + · exact (WP.spec_ok _).2 h1 + · exact (WP.spec_ok _).2 h1 + · exact WP.spec_mono (msg.set_mr.gx h1 hR hB (by simp)) fun r hr => hr.1 + rintro ⟨len, s2⟩ h2 + simp only at h2 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (Pₘ := fun r : S × U64 => XKoQ st H Cs OS ia ie Ac ∅ s r.1 ∧ XV st H OS Vc s r.1) ?_ ?_ + · simp only [fl4_abi.config.KERNEL_INVOCATION_REPORT_ERROR_IPC, ↓reduceIte] + split + · rename_i hne + have h0 : buf ≠ 0#u64 := by simpa using hne + simp only [syscall.DEBUG_MESSAGE_START] + step as ⟨i, hi⟩ + refine WP.spec_bind (P0.msg.buf_get.p0 st s2 buf i hS) fun w _ => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (hB h0 s2 i (w &&& ~~~255#u64) h2 (by omega)) fun s4 h4 => ?_ + exact (WP.spec_ok _).2 h4 + · exact (WP.spec_ok _).2 h2 + rintro ⟨s3, len1⟩ h3 + simp only at h3 + try simp only [WP.uncurry'_pair] + refine WP.spec_bind (P0.error.SysError.code.p0 e) fun i _ => ?_ + refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ + unfold msg.set_msg_info + refine WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => ?_ + refine WP.spec_mono (hR s3 _ w h3 (by simp [layout.reg.MSG_INFO, layout.reg.X1])) fun s' hf => ?_ + obtain ⟨⟨⟨J, k⟩, tk⟩, x⟩ := hf + exact S1aStepR2K.ofRpPost I (RpW.post ⟨J.sys, J.sym, J.blk, XC.keep k tk, x, + (XferSlots.refl s).keep fun z hz => k.capA hz⟩) C Df R sep KC + +set_option maxHeartbeats 4000000 in +/-- **`reply_success_empty` keeps the S1a step post**: the `BADGE` and `MSG_INFO` registers (`XJX.regT` over the +same carry as `reply_error.s1a`). -/ +theorem msg.reply_success_empty.s1a {s : S} (t : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (ht : t ∈ H.tcbs) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + msg.reply_success_empty st s t ⦃ s' => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have hH := I.del.heap + have hO := I.del.os + have hvr := I.del.vr + have i0 : XKoQ st H Cs OS ia ie Ac ∅ s s ∧ XV st H OS Vc s s := + ⟨⟨⟨XJX.start B Y h, OSKeep.rfl' _⟩, TabKeep.refl s⟩, XV.refl s⟩ + have hR : ∀ s2 r v, (XKoQ st H Cs OS ia ie Ac ∅ s s2 ∧ XV st H OS Vc s s2) → r.val < 384 → + obj.Tcb.set_reg st t s2 r v ⦃ s3 => XKoQ st H Cs OS ia ie Ac ∅ s s3 ∧ XV st H OS Vc s s3 ⦄ := + fun s2 _ _ ⟨h2, x2⟩ hr' => by + have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr + exact WP.spec_mono (XJX.regT (Vc := Vc) hH hO hc0 h2.1.1 hvr2 ht hr') + fun _ ⟨h3, k3, t3, a3⟩ => ⟨⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩, x2.trans (XV.keep a3 k3)⟩ + unfold msg.reply_success_empty + refine WP.spec_bind (hR s _ 0#u64 i0 (by simp [layout.reg.BADGE, layout.reg.X0])) fun s1 h1 => ?_ + refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ + unfold msg.set_msg_info + refine WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => ?_ + refine WP.spec_mono (hR s1 _ w h1 (by simp [layout.reg.MSG_INFO, layout.reg.X1])) fun s' hf => ?_ + obtain ⟨⟨⟨J, k⟩, tk⟩, x⟩ := hf + exact S1aStepR2K.ofRpPost I (RpW.post ⟨J.sys, J.sym, J.blk, XC.keep k tk, x, + (XferSlots.refl s).keep fun z hz => k.capA hz⟩) C Df R sep KC + +end top + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyM.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyM.lean new file mode 100644 index 000000000..8a4f4f5ea --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyM.lean @@ -0,0 +1,266 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 7): **`do_reply_transfer` to the Reply walk's post** +(QueueReplyX's `do_reply_transfer.bxi` walk with S1aCReplyW's bundle). + +* **`sched.set_thread_state.dmdT`**: `set_thread_state t v` of a thread not blocked on a reply is a `DMD t` step + (S1aCRestart's `TS_RESTART` block, any state). +* **`names_xfer`**: a TCB named by an `OS` slot stays named across a transfer (the destination was `Null`, the source + is the same cap or an untyped). +* **`ipc.do_reply_transfer.rpw`**: S1aCReplyRm's `reply_remove.rp`; the unblock check (MdbSspBind's + `bind_tcb.dmv` block); the transfer (S1aCXferTy's `do_ipc_transfer.xjT`) or the fault reply + (QueueIpcFoot's `handle_fault_reply.rg`, S1aCReplyT's `DMD.ofFld`) and `clear_fault`; the new state as a `DMD i` + step, `i` named at the start (live: blocked on the reply); then S1aCReplyTl's `reply_tail.rpw`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5). +-/ +import Fl4ProofsA64.P1.S1aCReplyTl + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 2000000 in +/-- **`set_thread_state t v` is a `DMD t` step** (module docstring). -/ +theorem sched.set_thread_state.dmdT {s : S} (t v : U64) (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (ht : t ∈ H.tcbs) (nr : L.mem s (stA t) ≠ sched.TS_BLOCKED_ON_REPLY) : + sched.set_thread_state st s t v ⦃ s' => DMD st H Cs t s s' ⦄ := by + refine WP.spec_mono (sched.set_thread_state.dfA s t v h ht) fun s2 ⟨f2, g2⟩ => ?_ + have f2' : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s2 := foot_noSc f2 + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + have Y' : YieldS st H.tcbs H.scs s2 := Y.yld.lv hX.2.2.yt g2 + (fun y k hk => by rw [hk.2]; decide) (fun c k hk => (hk : False).elim) + have D' := Y.dbg.lv hz g2 fun y k hk => by rw [hk.2]; decide + have V' : ValidReplies st H s2 := ValidReplies.lv VR hX.2.1 g2 (fun _ _ hk => (hk : False).elim) + (fun _ _ hk => hk) (BorK.of_eq t nr fun z hz hzt => by + rw [stA_eq]; exact g2.t z hz 3328#u64 (by unfold LvO; simp) fun e => hzt e.1) + refine DMD.ofK (E := fun q => q = t) h h0 Y ⟨D', Y'⟩ V' (K8.Foot.d f2') + (LvK.ofLv g2 (fun y k e => e.1) (fun _ _ e => (e : False).elim) (fun _ _ e => (e : False).elim) + (fun _ e => (e : False).elim)) (fun q e => Or.inl e) (EpM.ofK (ep_kept_kw h (foot_noSc f2))) g2.idle ?_ + exact g2.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by + have e' : (3464#u64 : U64).val = 3328 := e.2 + simp at e' + +/-- **A TCB named by an `OS` slot stays named across a transfer** (module docstring). -/ +theorem names_xfer {s s' : S} {i : U64} (X : XferSlots st OS s s') + (h : ∃ x ∈ OS, NamesA (capA st s x) i .tcb) : ∃ x ∈ OS, NamesA (capA st s' x) i .tcb := by + obtain ⟨x, hx, hn⟩ := h + refine ⟨x, hx, ?_⟩ + have hk : kindA (capA st s x) = 6 := hn.2.2.2.2 + rcases X with same | ⟨src, hs, dest, hd, -, empty, -, turned, others⟩ + · rw [same x hx]; exact hn + · by_cases e1 : x = dest + · subst e1; rw [empty] at hk; simp [kindA] at hk + · by_cases e2 : x = src + · subst e2 + rcases turned with e | ⟨p, b, j, e, j1, hc, -, -⟩ + · rw [e]; exact hn + · rw [hc] at hk; simp [kindA] at hk + · rw [others x hx e2 e1]; exact hn + +set_option maxHeartbeats 16000000 in +/-- **`do_reply_transfer` to the Reply walk's post** (module docstring). -/ +theorem ipc.do_reply_transfer.rpw (hA : P0.ArchTotal ar) {Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (ct r : U64) (grant : Bool) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h : BK s) (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) + (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) + (hr : r ∈ H.replies) (hct : ct ∈ H.tcbs) (hRV : RunVcpuInv st H.tcbs s) : + ipc.do_reply_transfer st ar s a ct r grant ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s s' ⦄ := by + have hS : P0.StoreTotal st := L.total + have h0 := B.ly.h0 + have hT := h.1.choose_spec.choose_spec.tcbs + have R0 : RpW st H Cs OS Vc ia ie Ac s s := RpW.start B Y h + have dK : ∀ {p : U64} {s1 s2 : S}, RpW st H Cs OS Vc ia ie Ac s s1 → + (∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s1 x) p k) → + DMD st H Cs p s1 s2 → (BK s2) → RpW st H Cs OS Vc ia ie Ac s s2 ∧ OSKeep st OS s1 s2 := + fun R hp d b => R.dmdK P.heap P.os hSA P.core0 hvr hks hp d b + have hp0 : ∀ {s1 : S} k, H 0#u64 = some k → ¬ (ia ≤ (0#u64).val ∧ (0#u64).val < ie) → + ∃ x ∈ OS, NamesA (capA st s1 x) 0#u64 k := fun k hk => by rw [h0] at hk; cases hk + unfold ipc.do_reply_transfer + refine WP.spec_bind (obj.Reply.tcb.blk s r) fun i ei => ?_ + step with obj.Tcb.is_null.spec as ⟨b, eb⟩ + split + · exact (WP.spec_ok _).2 R0.post + rename_i hb + have hi0 : i ≠ 0#u64 := fun e => hb (by rw [eb, e]; rfl) + obtain ⟨-, hiT, -, -⟩ := h.2.2.1.2.1.back r hr (by rw [← ei]; exact hi0) + rw [← ei] at hiT + step with obj.Tcb.state.spec as ⟨v, ev⟩ + split + · exact (WP.spec_ok _).2 R0.post + rename_i hv + have hst : L.mem s (stA i) = sched.TS_BLOCKED_ON_REPLY := by + rw [← ev]; apply UScalar.eq_of_val_eq; simpa [sched.TS_BLOCKED_ON_REPLY] using hv + have hni : L.idleW s ≠ i := fun e => h.2.1.idleNB (by rw [e, hst]; exact Or.inr rfl) + -- `i` is live, so named at the start + have nm : ¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) i .tcb := fun hia => + B.ln i .tcb hiT (LiveQ.tcb hiT (Or.inl (by rw [hst]; simp [sched.TS_BLOCKED_ON_REPLY, sched.TS_INACTIVE]))) hia + have nmK : ∀ {s1 : S}, (¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s1 x) i .tcb) → + ∀ k, H i = some k → ¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s1 x) i k := + fun n k hk hia => by + have e : H i = some .tcb := hiT + rw [e] at hk; cases hk; exact n hia + -- the reply's removal + refine WP.spec_bind (ipc.reply_remove.rp hA a r i h h0 Y B.vr hRV hr hiT ei.symm hst) ?_ + rintro ⟨s3, a2⟩ ⟨b3, d3, st3, ac3, rv3⟩ + try simp only [WP.uncurry'_pair] + obtain ⟨R3, k3⟩ := dK R0 hp0 d3 b3 + have q3 := b3.1.choose_spec.choose_spec + obtain ⟨dq3, dr3, da3⟩ := blocked_out q3 hiT (by rw [st3]; exact not_runnable_inactive) + have P3 : RPre st H.tcbs Ac s3 i := ⟨hiT, st3, dq3, dr3, da3, by rw [d3.idle]; exact hni, ac3⟩ + -- the SC's refills + step with obj.Tcb.sc.spec as ⟨i2, ei2⟩ + refine WP.spec_bind (sporadic.sc_sporadic.spec s3 i2) fun b1 hb1 => ?_ + refine WP.spec_bind (Pₘ := fun s4 => RpW st H Cs OS Vc ia ie Ac s s4 ∧ OSKeep st OS s s4 ∧ + RPre st H.tcbs Ac s4 i ∧ RunVcpuInv st H.tcbs s4) ?_ ?_ + · have ok3 : (ok s3 : Result S) ⦃ s4 => RpW st H Cs OS Vc ia ie Ac s s4 ∧ OSKeep st OS s s4 ∧ + RPre st H.tcbs Ac s4 i ∧ RunVcpuInv st H.tcbs s4 ⦄ := (WP.spec_ok _).2 ⟨R3, k3, P3, rv3⟩ + split + · rename_i hb1t + have hi20 := (hb1 hb1t).1 + step with obj.Sc.cpu.spec as ⟨cpu, _⟩ + step with obj.node_get.spec as ⟨cs, _⟩ + split + · obtain ⟨⟨Q, R, q⟩, hB3, hX3, hS3, hSg3⟩ := id b3 + have hsc0 : L.mem s3 (scA i) ≠ 0#u64 := by rw [← ei2]; exact hi20 + obtain ⟨hcS, -, -⟩ := hX3.2.2.bound i hiT hsc0 + have hsc : i2 ∈ H.scs := by rw [ei2]; exact hcS + have hAc : i2 ∈ Ac := by rw [ei2]; exact ac3 hsc0 + have hW : RefillsWF st s3 i2 (H.scBits i2) := hS3.wf hsc hAc + have hSCin : SCin st s3 H.omega i2 (H.scBits i2) := ⟨hW, hX3.1.scW i2 hsc⟩ + have hN' := q.nodes _ q.cur + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have aR : Aligned (L.nodeA s3 layout.node.REPROGRAM) := + nodeAt_aligned hN' (by rw [rp]; omega) (by rw [rp]) + have oR : Outside (L.nodeA s3 layout.node.REPROGRAM) i2 (H.scBits i2) := + hSCin.node_out q.omega q.cur hN' (by rw [rp]; omega) (by rw [rp]) + refine WP.spec_mono (WP.spec_and (sporadic.unblock_check.all s3 i i2 q hB3 hX3 hS3 hSg3 hiT ei2 hi20 + (by rw [ei2]; exact ac3 hsc0)) (sporadic.unblock_check.fr hW ⟨aR, oR⟩)) fun s4 hh => ?_ + obtain ⟨⟨q4, hB4, hX4, hS4, hSg4, ea4, -, ei4, f4, -⟩, w4⟩ := hh + have b4 : BK s4 := ⟨⟨Q, R, q4⟩, hB4, hX4, hS4, hSg4⟩ + have dd : DMD st H Cs 0#u64 s3 s4 := DMD.ofNone b3 h0 R3.sym R3.sys.vr + (WritesIn.mono w4 fun b hb => by + rcases hb with hb | rfl + · exact Or.inl (K8.kw_sc hsc hb.inSC) + · exact Or.inl (K8.kw_node q.cur (by rw [rp]; omega) (by rw [rp]; omega))) + (LvF.of_wi (LvC.of_blk b3) w4 fun b hb => by + rcases hb with hb | rfl + · exact Or.inr ⟨i2, hsc, hb⟩ + · exact Or.inl ⟨layout.node.REPROGRAM, by rw [rp]; omega, by rw [rp]; omega, by rw [rp]; omega, rfl⟩) + obtain ⟨R4, k4⟩ := dK R3 hp0 dd b4 + refine ⟨R4, k3.trans' k4, P3.keep ?_ ?_ ?_ ea4 ei4, rv3.keep (fun y hy => ?_) fun y hy => ?_⟩ + · rw [stA_eq]; exact f4 i hiT _ (by simp) (by simp) + · rw [inqA_eq]; exact f4 i hiT _ (by simp) (by simp) + · rw [scA_eq]; exact f4 i hiT _ (by simp) (by simp) + · rw [stA_eq]; exact f4 y hy _ (by simp) (by simp) + · exact f4 y hy 3672#u64 (by simp) (by simp) + · exact ok3 + · exact ok3 + rintro s4 ⟨R4, k4, P4, rv4⟩ + have b4 := R4.blk + have nm4 : ¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s4 x) i .tcb := fun hia => by + obtain ⟨x, hx, hn⟩ := nm hia + exact ⟨x, hx, by rw [k4.capA hx]; exact hn⟩ + have rz : ∀ {s5 : S}, RunVcpuInv st H.tcbs s5 → L.mem s5 (stA i) = sched.TS_INACTIVE → + L.mem s5 (runVcpuA i) = 0#u64 := fun hR e => + hR.zero hiT (by rw [e]; simp [sched.TS_INACTIVE, sched.TS_RUNNING_VM]) + refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st i s4 hS) fun ft _ => ?_ + refine WP.spec_bind (Pₘ := fun r : S × A => RpW st H Cs OS Vc ia ie Ac s r.1 ∧ RTail st H.tcbs Ac r.1 i ∧ + RunVcpuInv st H.tcbs r.1) ?_ ?_ + · split + · -- the message + have hks4 : HeapKsOff H (L.ksb s4) := by rw [R4.ksb]; exact hks + have hvr4 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s4) Pt := by rw [R4.ksb]; exact hvr + refine WP.spec_bind (ipc.do_ipc_transfer.xjT (Vc := Vc) (Xq := ∅) hA a2 (P.keepO k4 R4.ksb) hSA hTS hks4 hvr4 + R4.sys R4.sym b4 hct hiT) ?_ + rintro s5 ⟨X5, xc5, xv5, xs5, -⟩ + have R5 : RpW st H Cs OS Vc ia ie Ac s s5 := + ⟨X5.sys, X5.sym, X5.blk, R4.xc.trans xc5, R4.xv.trans xv5, XferSlots.before (fun z hz => k4.capA hz) xs5⟩ + have fr5 : ∀ y ∈ H.tcbs, ∀ K : U64, 3328 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3392 → + L.mem s5 (wa y K) = L.mem s4 (wa y K) := X5.fr + have P5 : RPre st H.tcbs Ac s5 i := P4.keep + (by rw [stA_eq]; exact fr5 i hiT _ (by simp) (by simp) (by simp) (by simp)) + (by rw [inqA_eq]; exact fr5 i hiT _ (by simp) (by simp) (by simp) (by simp)) + (by rw [scA_eq]; exact fr5 i hiT _ (by simp) (by simp) (by simp) (by simp)) X5.act X5.lv.idle + have rv5 : RunVcpuInv st H.tcbs s5 := rv4.keep + (fun y hy => by rw [stA_eq]; exact fr5 y hy _ (by simp) (by simp) (by simp) (by simp)) + fun y hy => fr5 y hy 3672#u64 (by simp) (by simp) (by simp) (by simp) + have nm5 : ¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s5 x) i .tcb := fun hia => + names_xfer xs5 (nm4 hia) + obtain ⟨⟨Q5, R5q, q5⟩, -, hX5, -, hSg5⟩ := id R5.blk + refine WP.spec_bind (WP.spec_and (WP.spec_and (P5.set (BlkOK.bxi R5.blk) not_blocked_running running_ne) + (sched.set_thread_state.dmdT i _ R5.blk h0 R5.sym R5.sys.vr hiT (by rw [P5.st0]; exact inactive_ne.1))) + (sched.set_thread_state.rvi s5 i _ Q5 R5q q5 hiT hX5.1 hSg5.sub rv5 (Or.inr (rz rv5 P5.st0)))) + fun s6 ⟨⟨⟨h6, t6⟩, d6⟩, _e6, rv6⟩ => ?_ + exact (WP.spec_ok _).2 ⟨(dK R5 (nmK nm5) d6 h6.blk).1, t6, rv6⟩ + · -- the fault reply + refine WP.spec_bind (WP.spec_and (faults.handle_fault_reply.rf (s := s4) (a := a2) (snd := ct) hT hiT) + (faults.handle_fault_reply.rg (s := s4) (a := a2) (snd := ct) hT hiT)) ?_ + rintro ⟨rs, s5, a3⟩ ⟨w5, g5⟩ + try simp only [WP.uncurry'_pair] + obtain ⟨⟨Q, R, q4⟩, hB4, hX4, hS4, hSg4⟩ := id b4 + obtain ⟨q5, hB5, hX5, hS5, hSg5, ea5, -, ei5, -, f5, -⟩ := + xfer_all (U := ∅) q4 hB4 hX4 hS4 hSg4 (fun b hb => absurd hb (by simp)) w5 + have b5 : BK s5 := ⟨⟨Q, R, q5⟩, hB5, hX5, hS5, hSg5⟩ + obtain ⟨R5, k5⟩ := dK R4 hp0 (DMD.ofFld 0#u64 b4 h0 R4.sym R4.sys.vr (g5.mono fun _ hb => XferRegW.fld hb)) b5 + have P5 : RPre st H.tcbs Ac s5 i := P4.keep (by rw [stA_eq]; exact f5 i hiT _ (by simp) (by simp) (by simp)) + (by rw [inqA_eq]; exact f5 i hiT _ (by simp) (by simp) (by simp)) + (by rw [scA_eq]; exact f5 i hiT _ (by simp) (by simp) (by simp)) ea5 ei5 + have rv5 : RunVcpuInv st H.tcbs s5 := rv4.keep + (fun y hy => by rw [stA_eq]; exact f5 y hy _ (by simp) (by simp) (by simp)) + fun y hy => f5 y hy 3672#u64 (by simp) (by simp) (by simp) + have nm5 : ¬ (ia ≤ i.val ∧ i.val < ie) → ∃ x ∈ OS, NamesA (capA st s5 x) i .tcb := fun hia => by + obtain ⟨x, hx, hn⟩ := nm4 hia + exact ⟨x, hx, by rw [k5.capA hx]; exact hn⟩ + unfold faults.clear_fault + refine WP.spec_bind (obj.Tcb.set_fault_type.spec s5 i _) fun s6 e6 => ?_ + subst e6 + have al6 : Aligned (faultA i) := field_aligned (K := 3376#u64) (hT i hiT) (by simp) (by simp) + have h6 := bxi_field (K := 3376#u64) (v := fl4_abi.consts.fault.NullFault) (BlkOK.bxi b5) hiT (by simp) + (by simp) (by simp) (by simp) + have hN5 := q5.nodes _ q5.cur + have n6 := ani_field (K := 3376#u64) (v := fl4_abi.consts.fault.NullFault) hT hN5 hiT (by simp) (by simp) + have fw : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3376 → + L.mem (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) (wa i K) = L.mem s5 (wa i K) := fun K a1 a2 a3 => + L.mem_wr_ne al6 (field_aligned (hT i hiT) a1 a2) + (fun e => field_ne (K1 := 3376#u64) (hT i hiT) (hT i hiT) (by simp) a1 (fun _ => by simp; omega) + (UScalar.eq_of_val_eq e)) + have P6 : RPre st H.tcbs Ac (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) i := + P5.keep (by rw [stA_eq]; exact fw _ (by simp) (by simp) (by simp)) + (by rw [inqA_eq]; exact fw _ (by simp) (by simp) (by simp)) + (by rw [scA_eq]; exact fw _ (by simp) (by simp) (by simp)) n6.1 n6.2.1 + have d6 : DMD st H Cs 0#u64 s5 (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) := + DMD.ofFld 0#u64 b5 h0 R5.sym R5.sys.vr ((writesIn_wr al6).mono fun b hb => + ⟨i, hiT, 3376#u64, by simp, by simp, by simp, by unfold LvO; simp, by simp, by simp, by simp, hb⟩) + obtain ⟨R6, k6⟩ := dK R5 hp0 d6 h6.blk + have rv6 : RunVcpuInv st H.tcbs (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) := + rv5.rvSt (RvSt.wr_field hT hiT (K := 3376#u64) (by simp) (by simp) (by simp) (by simp)) + have nm6 : ¬ (ia ≤ i.val ∧ i.val < ie) → + ∃ x ∈ OS, NamesA (capA st (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) x) i .tcb := fun hia => by + obtain ⟨x, hx, hn⟩ := nm5 hia + exact ⟨x, hx, by rw [k6.capA hx]; exact hn⟩ + obtain ⟨⟨Q6, R6q, q6⟩, -, hX6, -, hSg6⟩ := id R6.blk + have fin : ∀ v : U64, ¬ Blocked v → (v ≠ sched.TS_BLOCKED_ON_REPLY ∧ v ≠ sched.TS_BLOCKED_ON_RECV) → + sched.set_thread_state st (L.wr s5 (faultA i) fl4_abi.consts.fault.NullFault) i v ⦃ s7 => + RpW st H Cs OS Vc ia ie Ac s s7 ∧ RTail st H.tcbs Ac s7 i ∧ RunVcpuInv st H.tcbs s7 ⦄ := + fun v hv1 hv2 => WP.spec_mono (WP.spec_and (WP.spec_and (P6.set h6 hv1 hv2) + (sched.set_thread_state.dmdT i v R6.blk h0 R6.sym R6.sys.vr hiT (by rw [P6.st0]; exact inactive_ne.1))) + (sched.set_thread_state.rvi _ i v Q6 R6q q6 hiT hX6.1 hSg6.sub rv6 (Or.inr (rz rv6 P6.st0)))) + fun s7 ⟨⟨⟨h7, t7⟩, d7⟩, _e7, rv7⟩ => ⟨(dK R6 (nmK nm6) d7 h7.blk).1, t7, rv7⟩ + split + · exact WP.spec_bind (fin _ not_blocked_restart restart_ne) fun s7 h7 => (WP.spec_ok _).2 h7 + · exact WP.spec_bind (fin _ not_blocked_inactive inactive_ne) fun s7 h7 => (WP.spec_ok _).2 h7 + rintro ⟨s6, a6⟩ ⟨R6, t6, rv6⟩ + try simp only [WP.uncurry'_pair] + exact reply_tail.rpw hA P R6 hSA hTS hks hvr t6 rv6 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyRm.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyRm.lean new file mode 100644 index 000000000..327b82054 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyRm.lean @@ -0,0 +1,181 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 1): **the reply's removal as a liveness-monotone step**, for the +Reply cap invocation (`ipc.do_reply_transfer`). + +* **`SysL.dfMDOr`**: MdbDfM's `SysL.dfMDO` with the exempt object named only off the idle area (`LiveNamed` asks no + more of it). +* **`ipc.reply_remove.rp`**: `reply_remove r i` of the reply's caller `i` (blocked on the reply) is a `DMD 0` step + with `BlkOK`: every object whose liveness words it writes is live before (MdbLiveP's `fin_reply.lvm` argument: the + reply, its caller, the stack head's SC and, when it donates, that SC's old thread and the debug-list members), + `SymL` / `ValidReplies` as MdbLiveR's `fin_reply.lv` / `fin_reply.don`, the idle thread's SC word by + QueueFinCur's `reply_remove.curR`, `RunVcpuInv` by QueueFinRvReply's `reply_remove.rvi`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` at the step's start (as `reply_remove.rvi`). +-/ +import Fl4ProofsA64.P1.S1aCYieldTo +import Fl4ProofsA64.P1.MdbLiveP +import Fl4ProofsA64.P1.QueueFinRvReply +import Fl4ProofsA64.P1.QueueScKeep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 1000000 in +/-- **`SysL.dfMDO` with the exempt object named off the idle area only** (module docstring). -/ +theorem SysL.dfMDOr {Xq : Set U64} {p : U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) + (hB : BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s) + (hSA : ScApart H.scs H.scBits OS) + (hp : ∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) p k) + (B : SysL st H Cs OS ia ie s) (d : DMD st H Cs p s s') : + SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' := by + have h := hB + obtain ⟨Q, R, q⟩ := h.1 + have hSg := h.2.2.2.2 + have k : OSKeep st OS s s' := + OSKeep.of_kwd7 hO q hSg.sub hSA (fun _ he => he) (K8.FootD.to7 d.w) + obtain ⟨⟨⟨hS, hR, hV, hZ, hC⟩, hz, hK⟩, hfr, hcz, hur⟩ := B.sys + have u := UBm.keepO k + have hoff := HW.off (Vc := ∅) (Ub := ∅) hH hV hK q + (fun b hb => by obtain ⟨v, hv, -⟩ := hb; exact absurd hv (Set.notMem_empty v)) + (fun b hb => absurd hb (Set.notMem_empty b)) + have sys' : SysZ st H Cs OS s' := ⟨⟨⟨MdbST.keepO hO hS k, UtRev.keep hR k, ValidUntypedA.keepO hV k, + UtZeroA.writes hZ d.w (fun y0 hy0 p b i hc w hw => hoff w (hw.elim kw8_hw dbgw_hw) y0 hy0 p b i hc) u, + CoverA.keepO hC k d.w.1⟩, ZombiesFinal.recap hz fun _ hy => Or.inl (k.capA hy), KsOffA.of_ub hK d.w.1 u⟩, + FrameOK.keepO hfr k, CoverZ.keepO hcz k d.w.1, UtRV.keepO hur k⟩ + refine ⟨⟨sys', LiveNamed.transfer B.ln (fun q k' hq hl hni => ?_) (NamesKept.keepO k), d.vr, + B.ly.of_ub d.w.1 d.idle d.isc u, B.cn.keepO k, + fun x hx hb => by rw [k.capA hx]; exact B.bh x hx hb, (B.ci.keepO k).idleMv d.idle d.isc, + B.sc.keepO k, CtOff.ks d.w.1 (CapInv.keepO B.ct k), FrOff.ks d.w.1 (CapInv.keepO B.fo k), + fun x hx hb => by rw [k.capA hx]; exact B.ep x hx hb, B.ipc.keep (IbK.of_footDX h d.w)⟩, d.sym⟩ + by_cases e : q = p + · subst e + obtain ⟨x, hx, hn⟩ := hp k' hq hni + exact Or.inr ⟨x, hx, by rw [k.capA hx]; exact hn⟩ + · exact Or.inl ⟨hq, d.lv q e hl⟩ + +/-- A `DMD p` step whose `p` is live before is a `DMD p'` step. -/ +theorem DMD.relabel {p p' : U64} {s s' : S} (d : DMD st H Cs p s s') (hp : LiveQ st H Cs s p) : + DMD st H Cs p' s s' := + ⟨d.w, fun q _ hl => by + by_cases e : q = p + · subst e; exact hp + · exact d.lv q e hl, d.idle, d.isc, d.vr, d.sym⟩ + +set_option maxHeartbeats 4000000 in +/-- **`reply_remove r i`** of the reply's blocked caller is a `DMD 0` step with `BlkOK` (module docstring). -/ +theorem ipc.reply_remove.rp (hA : P0.ArchTotal ar) {s : S} (a : A) (r i : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hRV : RunVcpuInv st H.tcbs s) (hr : r ∈ H.replies) + (hiT : i ∈ H.tcbs) (hri : L.mem s (rTcbA r) = i) (hbor : L.mem s (stA i) = sched.TS_BLOCKED_ON_REPLY) : + ipc.reply_remove st ar s a r i ⦃ s' _ => (BK s') ∧ DMD st H Cs 0#u64 s s' ∧ + L.mem s' (stA i) = sched.TS_INACTIVE ∧ (L.mem s' (scA i) ≠ 0#u64 → L.mem s' (scA i) ∈ Ac) ∧ + RunVcpuInv st H.tcbs s' ⦄ := by + have C := LvC.of_blk h + have hX := h.2.2.1 + have hRI := hX.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hr0 : r ≠ 0#u64 := ne0_of_heap h0 hr + have hiI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + have hine : i ≠ L.idleW s := fun e => h.2.1.idleNB (by rw [← e, hbor]; exact Or.inr rfl) + have hi0 : i ≠ 0#u64 := ne0_of_heap h0 hiT + have hrL : LiveQ st H Cs s r := LiveQ.reply hr (by rw [hri]; exact hi0) + -- the objects live before + have eD : ∀ q, DbgIT st H.tcbs Cs s q → q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q := fun q hq => by + by_cases q0 : q = 0#u64 + · exact Or.inr (Or.inl q0) + have hqT : q ∈ H.tcbs := by + rcases hq with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · have := hz.dn y hy; rw [e] at this; exact this.resolve_left q0 + · have := hz.dp y hy; rw [e] at this; exact this.resolve_left q0 + · have := hz.dh c hc; rw [e] at this; exact this.resolve_left q0 + exact Or.inr (Or.inr (LiveQ.tcb hqT (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl hq)))))))) + have eH : ∀ q, q = L.mem s (rNextA r) &&& ~~~1#u64 → headBit (L.mem s (rNextA r)) = true → + q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q := fun q e hb => by + by_cases q0 : q = 0#u64 + · exact Or.inr (Or.inl q0) + have hn0 : L.mem s (rNextA r) &&& ~~~1#u64 ≠ 0#u64 := by rw [← e]; exact q0 + have hnS := (hRI.next r hr hn0).1 hb + have hh := hRI.head r hr hb hn0 + rw [← e] at hnS hh + exact Or.inr (Or.inr (LiveQ.sc hnS (Or.inr (Or.inl (by rw [hh]; exact hr0))))) + have eB : ∀ c ∈ H.scs, ∀ q, q = L.mem s (scTcbA c) → q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q := fun c hc q e => by + by_cases q0 : q = 0#u64 + · exact Or.inr (Or.inl q0) + have hc0 : c ≠ 0#u64 := by obtain ⟨z, hz'⟩ := hc; exact ne0_of_heap h0 hz' + have ht0 : L.mem s (scTcbA c) ≠ 0#u64 := by rw [← e]; exact q0 + have hT := hX.2.2.yt.1 c hc ht0 + have b := hX.2.2.tsc c hc hc0 ht0 + rw [← e] at hT b + exact Or.inr (Or.inr (LiveQ.tcb hT (Or.inr (Or.inl (by rw [b]; exact hc0))))) + have hiE : ∀ q, q = i → q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q := fun q e => by + subst e + exact Or.inr (Or.inr (LiveQ.tcb hiT (Or.inl fun e => inactive_ne.1 (e.symm.trans hbor)))) + have rem : ∀ s1 : S, K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s1 → + LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q) s s1 → + NzX st H Cs (fun q => q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q) s s1 := fun s1 fd Kk => by + have ek := ep_kept_kwd h fd + refine NzX.ofLvK Kk (fun e he _ hs => ?_) (fun n hn _ hs => ?_) + · unfold LawfulStore.epState at hs ⊢; rwa [ek e (Or.inl he)] at hs + · unfold LawfulStore.epState at hs ⊢; rwa [ek n (Or.inr hn)] at hs + -- the common close + have fin : ∀ s1 : S, (BK s1) → K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s1 → + L.idleW s1 = L.idleW s → SymL st H Cs s1 → ValidReplies st H s1 → + NzX st H Cs (fun q => q = r ∨ q = 0#u64 ∨ LiveQ st H Cs s q) s s1 → + (L.mem s1 (scA (L.idleW s)) = L.mem s (scA (L.idleW s)) ∨ L.mem s1 (scA (L.idleW s)) = 0#u64) → + DMD st H Cs 0#u64 s s1 := fun s1 b1 fd ei Y1 V1 M c1 => + DMD.relabel ⟨footD_es fd, LvM.ofNzXL M Y Y1 hz h0, ei, idleSc_of_or ei c1 b1.2.1.idle, V1, Y1⟩ hrL + by_cases hnd : headBit (L.mem s (rNextA r)) = true → L.mem s (rNextA r) &&& ~~~1#u64 ≠ 0#u64 → + L.mem s (scA i) ≠ 0#u64 + · refine WP.spec_mono (WP.spec_and (WP.spec_and (ipc.reply_remove.lv C a r i hr hiT hRI.toReplyInv0 hnd) + (ipc.reply_remove.rvi (Es := ∅) hA s a r i h hr hiT hri hbor hRV)) + (WP.spec_and (K8.ipc.reply_remove.blk (Es := ∅) hA s a r i h hr hiT hri hbor hRV) + (ipc.reply_remove.curR hA s a r i _ h hr hiT hri hbor hiI hine + (hRV.zero hiT fun e => not_runnable_reply (by rw [← hbor, e]; exact Or.inr (Or.inr rfl)))))) ?_ + rintro ⟨s1, a1⟩ ⟨⟨⟨f, V⟩, ⟨-, -, -, -, -, rv1⟩⟩, ⟨b1, st1, fd, ac1, ei1⟩, c1⟩ + have f' : LvF st H.tcbs Cs H.replies H.scs H.ntfns FinRpX s s1 := + f.mono ⟨fun _ _ h => h.2, fun _ _ h => h.2.2, fun _ _ h => h, fun _ _ _ => trivial⟩ + have Y1 : SymL st H Cs s1 := ⟨Y.dbg.lv hz f' fun y j hj => by + have : j = 3328 := hj + refine ⟨?_, ?_, ?_⟩ <;> omega, + Y.yld.lv hX.2.2.yt f' (fun y j hj => by have : j = 3328 := hj; omega) + fun c j hj => by have : j = 32 := hj; omega⟩ + have V1 : ValidReplies st H s1 := VR.rem hRI h0 hr hiT hri f V + refine ⟨b1, fin s1 b1 fd ei1 Y1 V1 (rem s1 fd (LvK.ofLv f (fun y k hk => hiE y hk.1) + (fun c k hk => eH c hk.2.1 hk.1) (fun _ _ hk => (hk : False).elim) fun q hk => ?_)) c1.2.2.1, st1, ac1, rv1⟩ + rcases hk with ⟨e, -⟩ | ⟨-, e⟩ | ⟨-, -, e⟩ + · exact Or.inl e + · exact absurd e (by decide) + · exact absurd e (by decide) + · obtain ⟨hb', hn0, hsc⟩ : headBit (L.mem s (rNextA r)) = true ∧ L.mem s (rNextA r) &&& ~~~1#u64 ≠ 0#u64 ∧ + L.mem s (scA i) = 0#u64 := by + by_contra hc + exact hnd fun a1 a2 => Classical.byContradiction fun a3 => hc ⟨a1, a2, not_not.1 a3⟩ + have hnS : L.mem s (rNextA r) &&& ~~~1#u64 ∈ H.scs := (hRI.next r hr hn0).1 hb' + have P : DonP st H.tcbs Cs H.omega H.frame H (L.mem s (rNextA r) &&& ~~~1#u64) i s := + ⟨h.1, h.2.2.2.2, hX.2.2.yt.1 _ hnS, hX.2.2.core _ hnS, + hRV.zero hiT (fun hv' => runnable_ne_reply (Or.inr (Or.inr hv')) hbor), Y.dbg, hz⟩ + refine WP.spec_mono (WP.spec_and (WP.spec_and (ipc.reply_remove.don C hA a r i hr hiT hRI.toReplyInv0 hb' hn0 hsc P) + (ipc.reply_remove.rvi (Es := ∅) hA s a r i h hr hiT hri hbor hRV)) + (WP.spec_and (K8.ipc.reply_remove.blk (Es := ∅) hA s a r i h hr hiT hri hbor hRV) + (ipc.reply_remove.curR hA s a r i _ h hr hiT hri hbor hiI hine + (hRV.zero hiT fun e => not_runnable_reply (by rw [← hbor, e]; exact Or.inr (Or.inr rfl)))))) ?_ + rintro ⟨s1, a1⟩ ⟨⟨⟨Kr, V, D', -, k, Kk⟩, ⟨-, -, -, -, -, rv1⟩⟩, ⟨b1, st1, fd, ac1, ei1⟩, c1⟩ + have Y1 : SymL st H Cs s1 := ⟨D', YieldS.yk Y.yld hX.2.2.yt k⟩ + have V1 : ValidReplies st H s1 := VR.remK hRI h0 hr hiT hri Kr V + refine ⟨b1, fin s1 b1 fd ei1 Y1 V1 (rem s1 fd (Kk.mono fun q hq => ?_)) c1.2.2.1, st1, ac1, rv1⟩ + rcases hq with e | e | e | e | e + · exact Or.inl e + · exact hiE q e + · exact eH q e hb' + · exact eB _ hnS q e + · exact eD q e + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyT.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyT.lean new file mode 100644 index 000000000..24bb82a09 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyT.lean @@ -0,0 +1,123 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 2): **TCB field writes off the liveness offsets**, for the +Reply cap invocation's fault reply and timeout fault. + +* **`FldW`**: a TCB field from offset 224, off the liveness offsets (`LvO`) and off `IPC_BUFFER` / the VCPU links. + **`FldW.kw8`**: such a word is a `K8` word. **`LvF.ofFld`**: writing such words writes no liveness word. + **`DMD.ofFld`**: such a step from a `BlkOK` state is a `DMD p` step. +* **`XferRegW.fld`**: the register words (`handle_fault_reply`'s, QueueIpcFoot's `handle_fault_reply.rg`) are `FldW`. +* **`faults.set_fault.fw`**: `set_fault` writes only `FldW` words (the fault and lookup-failure words, 3376–3424). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCReplyRm +import Fl4ProofsA64.P1.QueueIpcFoot + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- **A TCB field off the liveness offsets** (module docstring). -/ +def FldW (T : Set U64) (b : U64) : Prop := + ∃ y ∈ T, ∃ K : U64, 224 ≤ K.val ∧ K.val < 4096 ∧ K.val % 8 = 0 ∧ ¬ LvO K.val ∧ K.val ≠ 3512 ∧ + K.val ≠ 3664 ∧ K.val ≠ 3672 ∧ b = wa y K + +theorem FldW.kw8 {T Cs Sg Scs Es : Set U64} {Z : U64 → Nat} {s : S} {b : U64} (h : FldW T b) : + K8.KW st T Cs Sg Scs Z Es s b := by + obtain ⟨y, hy, K, h1, h2, -, h4, h5, h6, h7, e⟩ := h + refine Or.inl ⟨y, hy, K, h1, h2, ?_, ⟨?_, h6, h7, h5⟩, e⟩ <;> intro e' <;> exact h4 (by unfold LvO; omega) + +theorem XferRegW.fld {T : Set U64} {b : U64} (h : XferRegW T ∅ b) : FldW T b := by + rcases h with ⟨y, hy, K, h1, h2, h3, e⟩ | h + · exact ⟨y, hy, K, by omega, by omega, h3, by unfold LvO; omega, by omega, by omega, by omega, e⟩ + · exact (h : False).elim + +section atom +variable {T Ω Sg Rp Scs Nt : Set U64} {Z : U64 → Nat} {s : S} (C : LvC st T Cs Ω Sg Rp Scs Nt Z s) +include C + +/-- **Writing `FldW` words writes no liveness word.** -/ +theorem LvF.ofFld {s' : S} (w : WritesIn st s s' (FldW T)) : LvF st T Cs Rp Scs Nt LvX.none s s' := by + have nd : ∀ c ∈ Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → + L.mem s' (L.nodeAt s' c o) = L.mem s (L.nodeAt s c o) := by + intro c hc o ho h8 + rw [nodeAt_of_ksb w.1] + refine w.mem_eq (nodeAt_aligned (C.nodes c hc) ho h8) fun hb => ?_ + obtain ⟨y, hy, K, -, h2, -, -, -, -, -, e⟩ := hb + exact node_ne_field (C.nodes c hc) ho hy (C.tcb y hy) h2 e + have om : ∀ a ∈ Ω, L.mem s' a = L.mem s a := by + intro a ha + refine w.mem_eq (C.om a ha).1 fun hb => ?_ + obtain ⟨y, hy, K, -, h2, -, -, -, -, -, e⟩ := hb + exact out_ne_field (C.om a ha) hy (C.tcb y hy) h2 (congrArg UScalar.val e).symm + refine ⟨w.1, w.2.1, ?_, fun c hc => ?_, fun y hy K hK _ => ?_, fun c hc o hO _ => om _ (C.scO hc hO.lt.1 hO.lt.2), + fun n hn o hO _ => om _ (C.ntO hn hO), fun r hr o hO _ => om _ (C.rpO hr hO.lt.1 hO.lt.2)⟩ + · unfold LawfulStore.idleW; rw [w.2.1] + exact nd _ C.cur _ (by rw [idle8]; omega) (by rw [idle8]) + · exact nd c hc _ (by rw [debug_val]; omega) (by rw [debug_val]) + · refine w.mem_eq (C.al_t hy hK) fun hb => ?_ + obtain ⟨y', hy', K', -, h2, -, h4, -, -, -, e⟩ := hb + refine field_ne (C.tcb y hy) (C.tcb y' hy') hK.lt.1 h2 (fun _ ev => h4 ?_) e + rw [← ev]; exact hK + +end atom + +/-- **A `FldW` step from a `BlkOK` state is a `DMD p` step.** -/ +theorem DMD.ofFld (p : U64) {s s' : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (w : WritesIn st s s' (FldW H.tcbs)) : DMD st H Cs p s s' := + DMD.ofNone h h0 Y VR (K8.Foot.d (w.mono fun _ hb => FldW.kw8 hb)) (LvF.ofFld (LvC.of_blk h) w) + +/-- **`set_fault` writes only `FldW` words** (module docstring). -/ +theorem faults.set_fault.fw {T : Set U64} (s : S) (t : obj.Tcb) (f : error.Fault) (hT : TcbPlaced T) (ht : t ∈ T) : + faults.set_fault st s t f ⦃ s' => WritesIn st s s' (FldW T) ⦄ := by + have W : ∀ {s₁ : S} (K v : U64), WritesIn st s s₁ (FldW T) → 3376 ≤ K.val → K.val < 3432 → + K.val % 8 = 0 → WritesIn st s (L.wr s₁ (core.num.U64.wrapping_add t K) v) (FldW T) := + fun K v e h1 h2 h3 => (e.trans (writesIn_wr (field_aligned (hT t ht) (by omega) h3))).mono fun b hb => + hb.elim id fun e' => ⟨t, ht, K, by omega, by omega, h3, by unfold LvO; omega, by omega, by omega, by omega, e'⟩ + unfold faults.set_fault + refine WP.spec_bind (Pₘ := fun r : S × U64 × U64 × U64 × U64 => WritesIn st s r.1 (FldW T)) ?_ ?_ + · split + all_goals first | exact (WP.spec_ok _).2 (WritesIn.refl _ _) | skip + · refine WP.spec_bind (P0.error.LookupFault.encode.p0 _) ?_ + rintro ⟨lt, l0, l1⟩ - + try simp only [uncurry_apply_pair] + refine WP.spec_bind (obj.Tcb.set_lf_type.wr s t lt) fun s2 e2 => ?_ + subst e2 + have h2 := W (s₁ := s) 3408#u64 lt (WritesIn.refl _ _) (by simp) (by simp) (by simp) + refine WP.spec_bind (obj.Tcb.set_lf_w0.wr _ t l0) fun s3 e3 => ?_ + subst e3 + have h3 := W 3416#u64 l0 h2 (by simp) (by simp) (by simp) + refine WP.spec_bind (obj.Tcb.set_lf_w1.wr _ t l1) fun s4 e4 => ?_ + subst e4 + have h4 := W 3424#u64 l1 h3 (by simp) (by simp) (by simp) + refine WP.spec_bind (Pₘ := fun _ : U64 => True) ?_ fun i _ => (WP.spec_ok _).2 h4 + split <;> exact (WP.spec_ok _).2 trivial + · refine WP.spec_bind (Pₘ := fun _ : U64 => True) ?_ fun i _ => + (WP.spec_ok _).2 (WritesIn.refl _ _) + split <;> exact (WP.spec_ok _).2 trivial + · refine WP.spec_bind (Pₘ := fun _ : U64 => True) ?_ fun i _ => + (WP.spec_ok _).2 (WritesIn.refl _ _) + split <;> exact (WP.spec_ok _).2 trivial + · rintro ⟨s1, ty, w0, w1, w2⟩ hh + try simp only [uncurry_apply_pair] + simp only at hh + refine WP.spec_bind (obj.Tcb.set_fault_type.spec s1 t ty) fun s2 e2 => ?_ + subst e2 + have h2 := W (s₁ := s1) 3376#u64 ty hh (by simp) (by simp) (by simp) + refine WP.spec_bind (obj.Tcb.set_fault_w0.wr _ t w0) fun s3 e3 => ?_ + subst e3 + have h3 := W 3384#u64 w0 h2 (by simp) (by simp) (by simp) + refine WP.spec_bind (obj.Tcb.set_fault_w1.wr _ t w1) fun s4 e4 => ?_ + subst e4 + have h4 := W 3392#u64 w1 h3 (by simp) (by simp) (by simp) + exact WP.spec_mono (obj.Tcb.set_fault_w2.wr _ t w2) fun s5 e5 => by + subst e5; exact W 3400#u64 w2 h4 (by simp) (by simp) (by simp) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyTl.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyTl.lean new file mode 100644 index 000000000..d15eee37f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyTl.lean @@ -0,0 +1,151 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 6): **the Reply's tail** (QueueReplyX's `reply_tail`). + +* **`sched.postpone.dmd`**: `postpone` of the replied-to thread's SC is a `DMD p` step (QueueYield's `postpone.allF`, + QueueFootS's `postpone.kw`, RunVcpuKeep's `postpone.fld`, MdbSigL's `K8.Foot.ofQ`, as `resume.dmd`). +* **`reply_tail.rpw`**: the tail from S1aCReplyW's bundle: the switch (MdbSigL's `possible_switch_to.dmd`), the + postpone, or the timeout fault IPC (S1aCReplyTo's `handle_timeout.rpw`), each to `RpPost`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5). +-/ +import Fl4ProofsA64.P1.S1aCReplyTo + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 4000000 in +/-- **`postpone` of the replied-to thread's SC is a `DMD p` step** (module docstring). -/ +theorem sched.postpone.dmd (p : U64) {s : S} (i : U64) (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (r : RTail st H.tcbs Ac s i) (hrun : Runnable (L.mem s (stA i))) + (hi0 : L.mem s (scA i) ≠ 0#u64) : + sched.postpone st s (L.mem s (scA i)) ⦃ s' => DMD st H Cs p s s' ∧ BK s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + obtain ⟨hcS, htc, hcc⟩ := hX.2.2.bound i r.mem hi0 + have hm : scCoreA (L.mem s (scA i)) ∈ H.omega := hSg.sub _ (hX.1.fixW _ hcS).2 + have ht' : L.mem s (scTcbA (L.mem s (scA i))) ∈ H.tcbs := by rw [htc]; exact r.mem + have hr0 : (L.mem s (inqA (L.mem s (scTcbA (L.mem s (scA i))))) &&& sched.Q_RELEASE) = 0#u64 := by + rw [htc]; exact r.nr + have hcore := q.omega _ hm + have F := spec_all (P := fun (K : {K : U64 // K.val < 4096 ∧ K.val % 8 = 0 ∧ + (K.val < 224 ∨ K.val = 3512 ∨ K.val = 3664 ∨ K.val = 3672)}) (s' : S) => + ∀ y ∈ H.tcbs, L.mem s' (wa y K.1) = L.mem s (wa y K.1)) + (WP.spec_mono (sched.postpone.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s _ Q R q ht' hr0 + hcore hcc) fun _ _ => trivial) + fun K => sched.postpone.fld s _ Q R q ht' hr0 hcore hcc K.2.1 K.2.2.1 + (by have := K.2.2.2; omega) (by have := K.2.2.2; omega) + refine WP.spec_mono (WP.spec_and (WP.spec_and (sched.postpone.allF s _ Q R q ht' hB hX hSg hr0 hcore hcc + (by rw [htc]; exact hrun) (by rw [htc]; exact r.na) (by rw [htc]; exact hi0) (by rw [htc]; exact r.ac hi0)) + (sched.postpone.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s _ Q R q ht' hr0 hcore hcc)) F) ?_ + rintro s' ⟨⟨⟨Q', R', q', hB', hX', hSg', f5, -⟩, f⟩, k⟩ + exact ⟨DMD.ofNone h h0 Y VR (K8.Foot.d (K8.Foot.ofQ C.tcb f fun y hy K h1 h2 h3 => k ⟨K, h1, h2, h3⟩ y hy)) + (LvF.of_fr C f5), ⟨⟨Q', R', q'⟩, hB', hX', hS.fr f5, hSg'⟩⟩ + +set_option maxHeartbeats 8000000 in +/-- **The Reply's tail to `RpPost`** (module docstring). -/ +theorem reply_tail.rpw (hA : P0.ArchTotal ar) {Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s0 s3 : S} {a2 : A} {i ft : U64} + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (R : RpW st H Cs OS Vc ia ie Ac s0 s3) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s0)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) + (r : RTail st H.tcbs Ac s3 i) (hRV : RunVcpuInv st H.tcbs s3) : + (do + let i3 ← obj.Tcb.sc st i s3 + let b2 ← obj.Sc.is_null i3 + if b2 then ok (s3, a2) + else + let b3 ← sched.is_runnable st s3 i + if b3 then + let b4 ← sporadic.ready st s3 i3 + if b4 then + let b5 ← sporadic.sufficient st ar s3 a2 i3 0#u64 + if b5 then + let s4 ← sched.possible_switch_to st s3 i + ok (s4, a2) + else + let b6 ← faults.valid_timeout_handler st s3 i + if b6 then + if ft != fl4_abi.consts.fault.Timeout then + let badge ← obj.Sc.badge st i3 s3 + faults.handle_timeout st ar s3 a2 i (error.Fault.Timeout badge) + else + let s4 ← sched.postpone st s3 i3 + ok (s4, a2) + else + let s4 ← sched.postpone st s3 i3 + ok (s4, a2) + else + let b5 ← faults.valid_timeout_handler st s3 i + if b5 then + if ft != fl4_abi.consts.fault.Timeout then + let badge ← obj.Sc.badge st i3 s3 + faults.handle_timeout st ar s3 a2 i (error.Fault.Timeout badge) + else + let s4 ← sched.postpone st s3 i3 + ok (s4, a2) + else + let s4 ← sched.postpone st s3 i3 + ok (s4, a2) + else ok (s3, a2)) ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have hS : P0.StoreTotal st := L.total + have h0 := R.sys.ly.h0 + have hp0 : ∀ k, H 0#u64 = some k → ¬ (ia ≤ (0#u64).val ∧ (0#u64).val < ie) → + ∃ x ∈ OS, NamesA (capA st s3 x) 0#u64 k := fun k hk => by rw [h0] at hk; cases hk + step with obj.Tcb.sc.spec as ⟨i3, ei3⟩ + step with obj.Sc.is_null.spec as ⟨b2, eb2⟩ + split + · exact (WP.spec_ok _).2 R.post + rename_i hb2 + have hi0 : L.mem s3 (scA i) ≠ 0#u64 := fun e => hb2 (by rw [eb2, ei3, e]; rfl) + subst ei3 + refine WP.spec_bind (sched.is_runnable.spec' s3 i) fun b3 hb3 => ?_ + split + swap + · exact (WP.spec_ok _).2 R.post + rename_i hb3t + have hrun := hb3 hb3t + have PP : (do + let s4 ← sched.postpone st s3 (L.mem s3 (scA i)) + ok (s4, a2)) ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := + WP.spec_bind (sched.postpone.dmd 0#u64 i R.blk h0 R.sym R.sys.vr r hrun hi0) fun s4 ⟨d4, b4⟩ => + (WP.spec_ok _).2 (R.dmdK Pz.heap Pz.os hSA Pz.core0 hvr hks hp0 d4 b4).1.post + have TO : ∀ badge : U64, faults.handle_timeout st ar s3 a2 i (error.Fault.Timeout badge) ⦃ s' _ => + RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := fun badge => + faults.handle_timeout.rpw hA a2 i _ Pz R hSA hTS hks hvr r.cb + (fun e => not_runnable_inactive (e ▸ hrun)) hRV + have VT : (do + let b6 ← faults.valid_timeout_handler st s3 i + if b6 then + if ft != fl4_abi.consts.fault.Timeout then + let badge ← obj.Sc.badge st (L.mem s3 (scA i)) s3 + faults.handle_timeout st ar s3 a2 i (error.Fault.Timeout badge) + else + let s4 ← sched.postpone st s3 (L.mem s3 (scA i)) + ok (s4, a2) + else + let s4 ← sched.postpone st s3 (L.mem s3 (scA i)) + ok (s4, a2)) ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + refine WP.spec_bind (P0.faults.valid_timeout_handler.p0 st s3 i hS) fun b6 _ => ?_ + split + · split + · exact WP.spec_bind (P0.obj.Sc.badge.p0 st _ s3 hS) fun badge _ => TO badge + · exact PP + · exact PP + refine WP.spec_bind (sporadic.ready.spec s3 _) fun b4 _ => ?_ + split + · refine WP.spec_bind (sporadic.sufficient.ok hA s3 a2 _ 0#u64) fun b5 _ => ?_ + split + · exact WP.spec_bind (sched.possible_switch_to.dmd 0#u64 i R.blk h0 R.sym R.sys.vr r.mem hrun r.ac) + fun s4 ⟨d4, b4⟩ => (WP.spec_ok _).2 (R.dmdK Pz.heap Pz.os hSA Pz.core0 hvr hks hp0 d4 b4).1.post + · exact VT + · exact VT + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyTo.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyTo.lean new file mode 100644 index 000000000..e73178d11 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyTo.lean @@ -0,0 +1,111 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 5): **the Reply's timeout fault after its transfer**. + +* **`XferSlots2`**: two transfers' slot facts in a row (Architect ruling 03:42Z, item 3). +* **`faults.handle_timeout.rpw`**: from S1aCReplyW's bundle `RpW s0 s` (one transfer since `s0`), the timeout fault + IPC to the thread's timeout-handler endpoint: `set_fault` (S1aCReplyT's `FldW`, `DMD.ofFld`, `RpW.dmdK`), then + MdbSendQ's `send_ipc.recvS` / `blockS` at the placement after the first transfer (`SysPlace.ofXfer`); the endpoint is + typed by the handler slot's `SlotTy` there and named by that slot (`TcbSlotsOS`). + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5). +-/ +import Fl4ProofsA64.P1.S1aCReplyW + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +variable (st) in +/-- **Two transfers' slot facts in a row**, each with its memory carry (for R2's image, applied twice). -/ +def XferSlots2 (H : Heap) (OS Vc : Set U64) (s r : S) : Prop := + ∃ q, XferSlots st OS s q ∧ XV st H OS Vc s q ∧ XferSlots st OS q r ∧ XV st H OS Vc q r + +variable (st) in +/-- The Reply walk's end post from `s0`. -/ +def RpPost (H : Heap) (Cs OS Vc : Set U64) (ia ie : Nat) (Ac : Set U64) (s0 s : S) : Prop := + SysL st H Cs OS ia ie s ∧ SymL st H Cs s ∧ + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s ∧ XC st OS Vc s0 s ∧ + XV st H OS Vc s0 s ∧ XferSlots2 st H OS Vc s0 s + +theorem RpW.post {s0 s : S} (R : RpW st H Cs OS Vc ia ie Ac s0 s) : RpPost st H Cs OS Vc ia ie Ac s0 s := + ⟨R.sys, R.sym, R.blk, R.xc, R.xv, s, R.xs, R.xv, XferSlots.refl s, XV.refl s⟩ + +set_option maxHeartbeats 8000000 in +/-- **The timeout fault IPC after the Reply's transfer** (module docstring). -/ +theorem faults.handle_timeout.rpw (hA : P0.ArchTotal ar) {Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s0 s : S} (a : A) (i : U64) (f : error.Fault) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (R : RpW st H Cs OS Vc ia ie Ac s0 s) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s0)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) + (hc : CanBlock st H.tcbs Ac s i) (hrun : L.mem s (stA i) ≠ sched.TS_INACTIVE) + (hRV : RunVcpuInv st H.tcbs s) : + faults.handle_timeout st ar s a i f ⦃ s' _ => RpPost st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have ht := hc.mem + have h0 := R.sys.ly.h0 + have q0 := R.blk.1.choose_spec.choose_spec + have hT := q0.tcbs + have P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot := + SysPlace.ofXfer Pz R.sys.sys.stz.1.1.mdbS R.xs R.ksb + have hx : slotIdx i layout.tcb.SLOT_TIMEOUT_HANDLER ∈ OS := + hTS i ht _ (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) + have hs : obj.Tcb.slot i layout.tcb.SLOT_TIMEOUT_HANDLER = ok (slotIdx i layout.tcb.SLOT_TIMEOUT_HANDLER) := by + simp [obj.Tcb.slot, lift, slotIdx, layout.cte.SIZE] + have hty := (P.ty _ hx).capTy + unfold faults.handle_timeout + rw [hs, bind_ok, capA_eq, bind_ok] + unfold faults.send_fault_ipc + refine WP.spec_bind (Pₘ := fun r : Bool × S × A => RpPost st H Cs OS Vc ia ie Ac s0 r.2.1) ?_ ?_ + swap + · rintro ⟨x, s2, a2⟩ h2 + exact (WP.spec_ok _).2 h2 + split + all_goals first | exact (WP.spec_ok _).2 R.post | skip + rename_i p b x y g gr hcx + have hpH : H p = some .ep := by + have := hty.1.1.1 p b x y g gr + rw [hcx] at this; exact this rfl + refine WP.spec_bind (spec_eq' (WP.spec_and (WP.spec_and + (faults.set_fault.blk (U := ∅) s i f R.blk ht (fun b hb => absurd hb (Set.notMem_empty b)) hc) + (faults.set_fault.rv s i f hT ht)) (faults.set_fault.fw s i f hT ht))) ?_ + rintro s1 ⟨-, ⟨⟨b1, -, hc1⟩, rv1⟩, w1⟩ + obtain ⟨R1, k1⟩ := R.dmdK (p := 0#u64) Pz.heap Pz.os hSA Pz.core0 hvr hks + (fun k hk => by rw [h0] at hk; cases hk) (DMD.ofFld 0#u64 R.blk h0 R.sym R.sys.vr w1) b1 + have P1 : SysPlace st H Cs H.frame H.replies H.ntfns OS s1 extra slot := + SysPlace.ofXfer Pz R1.sys.sys.stz.1.1.mdbS R1.xs R1.ksb + have hp : ∀ k, H p = some k → ∃ z ∈ OS, NamesA (capA st s1 z) p k := fun k hk => by + rw [hpH] at hk; cases hk + exact ⟨_, hx, by rw [k1.capA hx, hcx]; exact names_ep⟩ + have hr1 : L.mem s1 (stA i) ≠ sched.TS_INACTIVE := by rw [(rv1 i ht).1]; exact hrun + have hRV1 : RunVcpuInv st H.tcbs s1 := hRV.rvSt rv1 + have hks1 : HeapKsOff H (L.ksb s1) := by rw [R1.ksb]; exact hks + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s1) Pt := by rw [R1.ksb]; exact hvr + by_cases hst1 : L.epState s1 p = 2#u64 + · refine WP.spec_bind (endpoint.send_ipc.recvS (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) hA a true false b g + gr false i p P1 b1 hSA hTS R1.sys R1.sym hpH hst1 hp hc1 hr1 (fun e => by cases e) hRV1) fun r hh => ?_ + obtain ⟨s2, a2⟩ := r + simp only [WP.uncurry'_pair] at hh + have carry := hh.2.2.2 hks1 hvr1 + exact (WP.spec_ok _).2 ⟨hh.1, hh.2.1, hh.2.2.1, R1.xc.trans carry.1, R1.xv.trans carry.2.1, s1, R1.xs, + R1.xv, carry.2.2, carry.2.1⟩ + · obtain ⟨⟨Q2, R2, q2⟩, -⟩ := id b1 + have hst0 : L.epState s1 p = 0#u64 ∨ L.epState s1 p = 1#u64 := by + rcases ep_state3 q2 hpH with e0 | e0 | e0 + · exact Or.inl e0 + · exact Or.inr e0 + · exact absurd e0 hst1 + refine WP.spec_bind (endpoint.send_ipc.blockS (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) a true false b g gr + false i p P1 b1 hSA R1.sys R1.sym hpH hst0 hp (fun _ => hc1) hr1) fun r hh => ?_ + obtain ⟨s2, a2⟩ := r + simp only [WP.uncurry'_pair] at hh + have carry := hh.2.2.2 hks1 hvr1 + exact (WP.spec_ok _).2 ⟨hh.1, hh.2.1, hh.2.2.1, R1.xc.trans carry.1, R1.xv.trans carry.2.1, s1, R1.xs, + R1.xv, Or.inl fun z hz => carry.2.2.capA hz, carry.2.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCReplyW.lean b/proofs/Fl4ProofsA64/P1/S1aCReplyW.lean new file mode 100644 index 000000000..22f2883d8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCReplyW.lean @@ -0,0 +1,61 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 4): **the Reply walk's bundle**. + +* **`RpW s0 s`**: `SysL ∧ SymL ∧ BlkOK` at `s` and MdbXferQ's carry `XC ∧ XV` and slot fact `XferSlots` from `s0`. +* **`RpW.dmdK`**: a `DMD p` step (`p` named at `s` off the idle area) with `BlkOK` at its end keeps `RpW` (S1aCReplyRm's + `SysL.dfMDOr`, MdbXferQ's `FootD.oskTabV`). +* **`SysPlace.ofXfer`**: the decode's placement at a later state whose slots are a transfer's (S1aCXferTy's + `SlotTy.ofXfer`), the kernel base kept. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aCXferTy + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +variable (st) in +/-- **The Reply walk's bundle** (module docstring). -/ +structure RpW (H : Heap) (Cs OS Vc : Set U64) (ia ie : Nat) (Ac : Set U64) (s0 s : S) : Prop where + sys : SysL st H Cs OS ia ie s + sym : SymL st H Cs s + blk : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + xc : XC st OS Vc s0 s + xv : XV st H OS Vc s0 s + xs : XferSlots st OS s0 s + +theorem RpW.start {s : S} (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) : + RpW st H Cs OS Vc ia ie Ac s s := + ⟨B, Y, h, XC.refl s, XV.refl s, XferSlots.refl s⟩ + +theorem RpW.ksb {s0 s : S} (R : RpW st H Cs OS Vc ia ie Ac s0 s) : L.ksb s = L.ksb s0 := R.xv.1.1 + +/-- **A `DMD p` step keeps the bundle** (module docstring). -/ +theorem RpW.dmdK {Vc' Ub Pt : Set U64} {p : U64} {s0 s s' : S} (R : RpW st H Cs OS Vc ia ie Ac s0 s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) (hks : HeapKsOff H (L.ksb s0)) + (hp : ∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) p k) + (d : DMD st H Cs p s s') (b : BK s') : RpW st H Cs OS Vc ia ie Ac s0 s' ∧ OSKeep st OS s s' := by + obtain ⟨Q, Rq, q⟩ := R.blk.1 + have hvr' : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt := by rw [R.ksb]; exact hvr + have hks' : HeapKsOff H (L.ksb s) := by rw [R.ksb]; exact hks + obtain ⟨k, t, v⟩ := FootD.oskTabV (Vc := Vc) hH hO hSA hvr' hks' R.sys.ly.ksw hc0 q R.blk.2.2.2.2.sub + (fun e he => he) d.w + obtain ⟨S', Y'⟩ := SysL.dfMDOr (Xq := ∅) hH hO R.blk hSA hp R.sys d + exact ⟨⟨S', Y', b, R.xc.trans (XC.keep k t), R.xv.trans (XV.keep v k), R.xs.keep fun z hz => k.capA hz⟩, k⟩ + +/-- **The decode's placement after a transfer** (module docstring). -/ +theorem SysPlace.ofXfer {Rp Nt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s s' : S} + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hm : MdbS st OS s') (X : XferSlots st OS s s') + (hk : L.ksb s' = L.ksb s) : SysPlace st H Cs H.frame Rp Nt OS s' extra slot := + ⟨P.heap, P.os, P.win, SlotTy.ofXfer P.os P.ty hm X, P.core0, P.ext, P.src, P.slotw, by rw [hk]; exact P.wu⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCRestart.lean b/proofs/Fl4ProofsA64/P1/S1aCRestart.lean new file mode 100644 index 000000000..1335f5aac --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCRestart.lean @@ -0,0 +1,273 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a8)): **`restart t` and TCB Resume keep every capability** +(sched.rs `restart`). + +* **`ipc.cancel_ipc.dmdC`**: cancelling the IPC is a `DMD t` step. +* **`schedcontext.resume.footK8`**: `schedcontext.resume`'s footprint in `K8`. +* **`sched.restart.dm`**: `restart t` is a `DM t` step, with `BlkOK` and the `K8` footprint at its end (shared by + Resume, WriteRegisters and CopyRegisters). +* **`syscall.decode_invocation.resume_armS`**. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCDm2 +import Fl4ProofsA64.P1.MdbArmDm +import Fl4ProofsA64.P1.MdbSigL + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "FK" => K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) + +set_option maxHeartbeats 1000000 in +/-- A program with a triple returns a value satisfying it. -/ +theorem ok_of_spec {α : Type _} {m : Result α} {P : α → Prop} (h : m ⦃ P ⦄) : ∃ x, m = ok x ∧ P x := by + revert h + cases m <;> simp [WP.spec_vis, WP.spec_div, WP.spec_ok] + +/-- `set_thread_state`'s footprint (no SC word) inside the `K8` one. -/ +theorem foot_noSc {s s' : S} {Es : Set U64} (f : K8.Foot st H.tcbs Cs H.frame ∅ H.scBits ∅ s s') : + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits Es s s' := + WritesIn.mono f fun b hb => by + rcases hb with h | h | hm | ⟨c, hc, -⟩ | ⟨e, he, -⟩ + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl hm)) + · exact absurd hc (Set.notMem_empty _) + · exact absurd he (Set.notMem_empty _) + +/-- **`cancel_ipc t`** is a `DMD t` step. -/ +theorem ipc.cancel_ipc.dmdC {s : S} (a : A) (t : U64) (h : BK s) (ht : t ∈ H.tcbs) (h0 : H 0#u64 = none) + (VR : ValidReplies st H s) (Y : SymL st H Cs s) (hna : L.actionW s ≠ t) : + ipc.cancel_ipc st ar s a t ⦃ s' _ => (BK s') ∧ FK s s' ∧ DMD st H Cs t s s' ∧ + ¬ Blocked (L.mem s' (stA t)) ∧ L.mem s' (stA t) ≠ sched.TS_BLOCKED_ON_REPLY ∧ L.actionW s' ≠ t ⦄ := by + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + obtain ⟨Q, R, q⟩ := h.1 + obtain ⟨hO, hR, hE⟩ := id hX + have hSg := h.2.2.2.2 + have hreply : L.mem s (stA t) = sched.TS_BLOCKED_ON_REPLY → ReplyT st H.replies H.scs s t := fun hs => by + obtain ⟨h1, h2⟩ := hR.reply t ht hs + exact ⟨h1, h2, hR.next _ h1, hR.prev _ h1⟩ + refine WP.spec_mono (WP.spec_and (WP.spec_and (ipc.cancel_ipc.all s a t Q R q ht h.2.1 hX hSg.sub) + (ipc.cancel_ipc.lv a t h ht h0 VR)) (WP.spec_and (ipc.cancel_ipc.stbm s a t h ht) + (K8.ipc.cancel_ipc.kw8 s a t q ht hO hSg.sub hreply (fun a b => (hR.recv t ht a b).1)))) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨⟨⟨q1', -, -, nb, nr, hst, -, -⟩, g, V1, K1⟩, ⟨B1, m1⟩, f⟩ := hh + have M := epS_mono h B1 m1.blk + have Y' : YieldS st H.tcbs H.scs s1 := Y.yld.lv hX.2.2.yt g + (fun y k hk => by have e : k = 3328 := hk; subst e; decide) + (fun c k hk => by have e : k = 32 := hk; subst e; decide) + have D' := Y.dbg.lv hz g fun y k hk => by + have e : k = 3328 := hk + subst e; decide + have Ys : SymL st H Cs s1 := ⟨D', Y'⟩ + have na1 : L.actionW s1 ≠ t := by + rcases hst with e | ⟨-, e⟩ + · intro ea + have := (q1'.actOK (ea ▸ ht)).1; rw [ea, e] at this; exact not_runnable_inactive this + · rw [e]; exact hna + refine ⟨B1, f, DMD.ofK h h0 Y Ys V1 (K8.Foot.d f) K1 (fun q hq => canE_live h ht h0 Y.yld (Or.inl hq)) M g.idle ?_, nb, nr, na1⟩ + exact g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by + have e' : (3464#u64 : U64).val = 3328 := e + simp at e' + +/-- **`schedcontext.resume`'s footprint** in `K8`. -/ +theorem schedcontext.resume.footK8 (hA : P0.ArchTotal ar) {s : S} (a : A) (sc : U64) (h : BK s) + (hsc : sc ≠ 0#u64 → L.mem s (scTcbA sc) ≠ 0#u64 → + L.mem s (scTcbA sc) ∈ H.tcbs ∧ OutsideObjs st H.tcbs Cs s (scCoreA sc) ∧ L.mem s (scCoreA sc) ∈ Cs ∧ + L.actionW s ≠ L.mem s (scTcbA sc)) : + schedcontext.resume st ar s a sc ⦃ s' _ => FK s s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have F := spec_all (P := fun (K : {K : U64 // K.val < 4096 ∧ K.val % 8 = 0 ∧ + (K.val < 224 ∨ K.val = 3512 ∨ K.val = 3664 ∨ K.val = 3672)}) (r : S × A) => + ∀ y ∈ H.tcbs, L.mem r.1 (wa y K.1) = L.mem s (wa y K.1)) + (WP.spec_mono (schedcontext.resume.all hA s a sc Q R q hB hX hSg hS hsc) fun _ _ => trivial) + fun K => WP.spec_mono (schedcontext.resume.fld hA s a sc Q R q hsc K.2.1 K.2.2.1 (by omega) (by omega)) + fun r hr => by obtain ⟨_, _⟩ := r; exact hr + refine WP.spec_mono (WP.spec_and + (schedcontext.resume.kw (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) hA s a sc Q R q hsc) F) ?_ + rintro ⟨s', a'⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨f, k⟩ := hh + exact WritesIn.mono (K8.Foot.ofQ C.tcb f fun y hy K h1 h2 h3 => k ⟨K, h1, h2, h3⟩ y hy) fun _ hb => kw8_es hb + +set_option maxHeartbeats 2000000 in +/-- **`restart t`** is a `DM t` step. -/ +theorem sched.restart.dm (hA : P0.ArchTotal ar) {s : S} (a : A) (t : U64) (h : BK s) (ht : t ∈ H.tcbs) + (h0 : H 0#u64 = none) (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + sched.restart st ar s a t ⦃ s' _ => (BK s') ∧ FK s s' ∧ DM st H Cs t s s' ⦄ := by + have done : ∀ s' : S, (BK s') → FK s s' → DMD st H Cs t s s' → (BK s') ∧ FK s s' ∧ DM st H Cs t s s' := + fun s' b f d => ⟨b, f, ⟨f, d.lv, d.idle, d.isc, d.vr, d.sym⟩⟩ + unfold sched.restart + step with sched.is_stopped.spec as ⟨b, b_post⟩ + split + swap + · simp only [WP.spec_ok, WP.uncurry'_pair] + exact done s h (WritesIn.refl _ _) (DMD.refl t h h0 Y VR) + have hnr : ¬ Runnable (L.mem s (stA t)) := b_post (by assumption) + have hna : L.actionW s ≠ t := fun e => by + obtain ⟨Q, R, q⟩ := h.1 + exact hnr (by have := (q.actOK (e ▸ ht)).1; rwa [e] at this) + refine WP.spec_bind (ipc.cancel_ipc.dmdC a t h ht h0 VR Y hna) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + try simp only [uncurry_apply_pair] + obtain ⟨b1, f1, d1, nb, nr, na1⟩ := hh + -- `TS_RESTART` + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.dfA s1 t sched.TS_RESTART b1 ht) + (sched.set_thread_state.restart_blk (Es := ∅) s1 t b1 ht nb nr)) ?_ + rintro s2 ⟨⟨f2, g2⟩, b2, -, -, k2⟩ + have na2 : L.actionW s2 ≠ t := by + rcases k2.act with e | e + · rw [e]; exact na1 + · rw [e]; intro e' + obtain ⟨Q, R, q⟩ := b1.1 + exact notT_small q.tcbs (by simp) (e' ▸ ht) + have d2 : DMD st H Cs t s1 s2 ∧ FK s1 s2 := by + have f2' : FK s1 s2 := foot_noSc f2 + have hX := b1.2.2.1 + have hz : DbgTz st H.tcbs Cs s1 := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s1 ∈ H.tcbs := b1.1.choose_spec.choose_spec.idleT + have Y' : YieldS st H.tcbs H.scs s2 := d1.sym.yld.lv hX.2.2.yt g2 + (fun y k hk => by rw [hk.2]; decide) (fun c k hk => (hk : False).elim) + have D' := d1.sym.dbg.lv hz g2 fun y k hk => by rw [hk.2]; decide + have V' : ValidReplies st H s2 := ValidReplies.lv d1.vr hX.2.1 g2 (fun _ _ hk => (hk : False).elim) + (fun _ _ hk => hk) (BorK.of_eq t nr fun z hz hzt => by + rw [stA_eq]; exact g2.t z hz 3328#u64 (by unfold LvO; simp) fun e => hzt e.1) + refine ⟨DMD.ofK (E := fun q => q = t) b1 h0 d1.sym ⟨D', Y'⟩ V' (K8.Foot.d f2') + (LvK.ofLv g2 (fun y k e => e.1) (fun _ _ e => (e : False).elim) (fun _ _ e => (e : False).elim) + (fun _ e => (e : False).elim)) (fun q e => Or.inl e) (EpM.ofK (ep_kept_kw b1 (foot_noSc f2))) g2.idle ?_, f2'⟩ + exact g2.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by + have e' : (3464#u64 : U64).val = 3328 := e.2 + simp at e' + obtain ⟨d2, f2'⟩ := d2 + -- the unblock check, as `unblock_sporadic` + obtain ⟨i, ei, -⟩ := ok_of_spec (obj.Tcb.sc.spec (st := st) s2 t) + rw [ei, bind_ok] + have hX2 := b2.2.2.1 + obtain ⟨⟨Q2, R2, q2⟩, hB2, -, hS2, hSg2⟩ := id b2 + obtain ⟨b3', eb, -⟩ := ok_of_spec (sporadic.sc_sporadic.spec (st := st) s2 i) + rw [eb, bind_ok] + have eu : notification.unblock_sporadic st s2 t = (if b3' then do + let s4 ← sched.cur_sc st s2 + let b2 ← core.cmp.PartialEq.ne.trait_default obj.Sc.Insts.CoreCmpPartialEqSc i s4 + if b2 then sporadic.unblock_check st s2 i else ok s2 + else ok s2) := by + unfold notification.unblock_sporadic + rw [ei, bind_ok, eb, bind_ok] + rw [← eu] + refine WP.spec_bind (WP.spec_and (WP.spec_and (notification.unblock_sporadic.dmd t t b2 h0 d2.sym d2.vr ht) + (K8.notification.unblock_sporadic.kw8 (Es := ∅) s2 t q2 hX2 hS2 ht)) + (WP.spec_and (notification.unblock_sporadic.ring (Ac := Ac) s2 t q2 hX2 hS2 ht) + (notification.unblock_sporadic.lv (Ac := Ac) s2 t (LvC.of_blk b2) q2 hX2 hS2 ht))) ?_ + rintro s3 ⟨⟨⟨d3, b3⟩, f3⟩, w3, g3⟩ + have f3' : FK s2 s3 := WritesIn.mono f3 fun _ hb => kw8_es hb + -- `resume` + obtain ⟨⟨Q3, R3, q3⟩, hB3, hX3, hS3, hSg3⟩ := id b3 + have hT := q3.tcbs + have sc3 : L.mem s3 (scA t) = i := by + have e2 : L.mem s2 (scA t) = i := by + obtain ⟨j, ej, pj⟩ := ok_of_spec (obj.Tcb.sc.spec (st := st) s2 t) + rw [ei] at ej + cases ok_inj_ff ej + exact pj.symm + rw [← e2] + exact g3.t t ht 3464#u64 (by unfold LvO; simp) fun e => (e : False).elim + have hna3 : L.actionW s3 ≠ t := by + have e : L.actionW s3 = L.actionW s2 := by + unfold LawfulStore.actionW + rw [w3.2.1, nodeAt_of_ksb w3.1] + have hN := q2.nodes _ q2.cur + have o88 : layout.node.SCHED_ACTION.val < 4288 := by rw [act_val]; omega + have al := nodeAt_aligned hN o88 (by rw [act_val]) + refine w3.2.2 _ al ?_ + rintro (⟨j, hj, hr⟩ | e) + · have hm := hX2.1.scW j hj _ al hr.inSC + exact out_ne_node (q2.omega _ hm) q2.cur hN o88 rfl + · have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have := congrArg UScalar.val e + rw [nodeAt_val hN o88, nodeAt_val hN (by rw [rp]; omega), rp, act_val] at this; omega + rw [e]; exact na2 + have hsc : i ≠ 0#u64 → L.mem s3 (scTcbA i) ≠ 0#u64 → + L.mem s3 (scTcbA i) ∈ H.tcbs ∧ OutsideObjs st H.tcbs Cs s3 (scCoreA i) ∧ L.mem s3 (scCoreA i) ∈ Cs ∧ + L.actionW s3 ≠ L.mem s3 (scTcbA i) := fun hi0 _ => by + obtain ⟨hiS, hti, hci⟩ := hX3.2.2.bound t ht (by rw [sc3]; exact hi0) + rw [sc3] at hiS hti hci + rw [hti] + exact ⟨ht, q3.omega _ ((objs_omega hX3.1 hSg3.sub).2 i hiS).2.1, hci, hna3⟩ + refine WP.spec_bind (WP.spec_and (schedcontext.resume.dmd hA t a1 i b3 h0 d3.sym d3.vr hsc) + (schedcontext.resume.footK8 hA a1 i b3 hsc)) ?_ + rintro ⟨s4, a2⟩ hh + simp only [WP.uncurry'_pair] at hh + try simp only [uncurry_apply_pair] + obtain ⟨⟨d4, b4⟩, f4⟩ := hh + have d14 : DMD st H Cs t s s4 := d1.trans (d2.trans (d3.trans d4)) + have f14 : FK s s4 := f1.trans (f2'.trans (f3'.trans f4)) + obtain ⟨⟨Q4, R4, q4⟩, hB4, hX4, hS4, hSg4⟩ := id b4 + step with sched.is_schedulable.spec' as ⟨b5, hb5⟩ + split + · rename_i hb + refine WP.spec_bind (WP.spec_and (sched.possible_switch_to.dmd t t b4 h0 d4.sym d4.vr ht (hb5 hb).1 + (fun _ => (hS4.act _ (hX4.2.2.bound t ht (hb5 hb).2.1).1).2 (hb5 hb).2.2.2)) + (K8.sched.possible_switch_to.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s4 t q4 ht)) + fun s5 ⟨⟨d5, b5'⟩, f5⟩ => ?_ + simp only [WP.spec_ok, WP.uncurry'_pair] + exact done s5 b5' (f14.trans (WritesIn.mono f5 fun _ hb => kw8_es hb)) (d14.trans d5) + · simp only [WP.spec_ok, WP.uncurry'_pair] + exact done s4 b4 f14 d14 + +/-- **TCB Resume** keeps every capability. -/ +theorem syscall.decode_invocation.resume_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBResume) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + have key : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + DmPost st H Cs OS ia ie Ac s r.2.1 ⦄ := by + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.stS hA a t D.bxi) ?_ + rintro ⟨s1, a1⟩ ⟨h1, d1⟩ + try simp only [uncurry_apply_pair] + iterate 7 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetEPTRoot, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + refine WP.spec_bind (tcb.restart_caller.restartRK D P B Y h1 d1) fun s2 ⟨R, d2⟩ => ?_ + refine WP.spec_bind (sched.restart.dm hA a1 t R.blk ht B.ly.h0 R.sys.vr R.sym) ?_ + rintro ⟨s3, a3⟩ hh + simp only [WP.uncurry'_pair] at hh + try simp only [uncurry_apply_pair] + obtain ⟨h3, f3, d3⟩ := hh + exact (WP.spec_ok _).2 (DmPost.mk' (SysL.dfM R.pl R.blk.bxi hSA (R.namedT hcap ht) R.sys d3) h3 + (DmW.trans (DmW.ofDF d2) (WritesIn.mono f3 fun _ hb => Or.inr hb))) + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono key fun r d => by + obtain ⟨_, s', a'⟩ := r + have x := ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk + exact ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCScBind.lean b/proofs/Fl4ProofsA64/P1/S1aCScBind.lean new file mode 100644 index 000000000..cf4ce4261 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCScBind.lean @@ -0,0 +1,322 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a11)): **SchedContext Bind keeps every capability** (schedcontext.rs +`decode`, `bind_tcb`, `bind_ntfn`). + +* **`schedcontext.bind_ntfn.footL`** / **`.dmE`**: the two writes (the notification's `SC` word, the SC's `NTFN` + word) let only the SC and the notification become live (S1aCDm2's `DME`, as S1aCNtfnBind's + `bind_notification.dmE`). +* **`schedcontext.extra_cap.slot`**: the extra cap is the cap of a non-null extra slot, `CapOK` (QueueDecSc's + `extra_cap.ok` with the slot exported). +* **`schedcontext.decode.bindSAt`**: the stall of the SC's thread if any (MdbDelIn's `remote_tcb_stall.delS`), then + - Notification: the caller's restart (`RsR`), `bind_ntfn.dmE`, `SysL.dfE` with both objects named by `OS` slots, + the `DmW` frame, MdbArmDm's `ArmQIAt.ofDMK`; + - Thread: the target's stall (MdbVcRdL's `Stalled.stallD`, `remote_tcb_stall.ds`, `vsk_node`), the caller's + restart as MdbHiVsArm's `restart_caller.delRP` / `armVsK` (the decode's `set_thread_state (cur_thread)` is + `restart_caller`: VcpuHooks' `cur_thread_ok`), then MdbSspBind's `bind_tcb.dmv`. **`migrate_tcb` writes the + debug lists and the run VCPU's `OWNER_CPU` word**: the step is a `DMV t sc`, so a MdbSspBind `DMR` step over + MdbSspTail's `SusW` footprint (which has the debug-list words `DbgW` and the VCPU words `VcW`); `SysL.dfMDR`, + MdbSspTail's `ArmQIAt.ofSusW` / `ArmVsK.ofSusW` (the footprint lemma) and `ArmQIAt.transZ`, as MdbSusQ's + Suspend. No `DmPost` and no new premise. + The bind's case facts are read off the checks: the SC and the thread unbound, a blocked thread's SC released (so + active: `SCsOK`), the thread not current (the current thread has an SC: `BoundInv.resume`) nor idle + (`BoundInv.idle`), its run VCPU a `Vc` VCPU (`DelR`'s `VcTy.run`). +* **`syscall.decode_invocation.scBind_armS`** (the `*_armS` shape). + +Named premises: [P] `P0.ArchTotal`. Case facts: none new (`DelIn`, `HeapKsOff`, `ScApart`, the invoked slot's cap). +-/ +import Fl4ProofsA64.P1.S1aCCopyRegs +import Fl4ProofsA64.P1.S1aCNtfnBind +import Fl4ProofsA64.P1.MdbSspBind +import Fl4ProofsA64.P1.QueueDecSc +import Fl4ProofsA64.P1.VcpuHooks + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- **`bind_ntfn`**, with its footprint and exact liveness frame. -/ +theorem schedcontext.bind_ntfn.footL {s : S} (c n : U64) (h : BK s) (hc : c ∈ H.scs) (hn : n ∈ H.ntfns) : + schedcontext.bind_ntfn st s c n ⦃ s' => + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ∧ + LvF st H.tcbs Cs H.replies H.scs H.ntfns ((LvX.nt n 32).u (LvX.sc c 40)) s s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hO := hX.1 + have hmA : ntfnScA n ∈ H.frame := hO.ntW n hn + have hmB : scNtfnA c ∈ H.frame := hO.snW c hc + unfold schedcontext.bind_ntfn + refine WP.spec_bind (obj.Ntfn.set_sc.wr s n c) fun s1 e1 => ?_ + subst e1 + have f1 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s (L.wr s (ntfnScA n) c) := + K8.foot_wr (q.omega _ (hSg.sub _ hmA)).1 (K8.kw_sg hmA) + have g1 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.nt n 32) s (L.wr s (ntfnScA n) c) := + LvF.wrN C hn (o0 := layout.ntfn.SC) (v := c) (by simp [layout.ntfn.SC]) (hSg.sub _ hmA) + (by simp [layout.ntfn.SC]) + refine WP.spec_mono (obj.Sc.set_ntfn.wr _ c n) fun s2 e2 => ?_ + subst e2 + exact ⟨f1.trans (K8.foot_wr (q.omega _ (hSg.sub _ hmB)).1 (K8.kw_sg hmB)), + g1.trans (LvF.wrC (C.wr _ _) (v := n) hc (o0 := layout.sc.NTFN) (by simp [layout.sc.NTFN]) + (by simp [layout.sc.NTFN]) (j := 40) (by simp [layout.sc.NTFN]))⟩ + +set_option maxHeartbeats 1000000 in +/-- **`bind_ntfn c n`** lets only `c` and `n` become live. -/ +theorem schedcontext.bind_ntfn.dmE {s : S} (c n : U64) (h : BK s) (hc : c ∈ H.scs) (hc0 : c ≠ 0#u64) + (hn : n ∈ H.ntfns) (z1 : L.mem s (ntfnScA n) = 0#u64) (z2 : L.mem s (scNtfnA c) = 0#u64) + (h0 : H 0#u64 = none) (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + schedcontext.bind_ntfn st s c n ⦃ s' => (BK s') ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' ∧ DME st H Cs (fun q => q = c ∨ q = n) s s' ⦄ := by + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + refine WP.spec_mono (WP.spec_and (schedcontext.bind_ntfn.blk s c n h hc hc0 hn z1 z2) + (schedcontext.bind_ntfn.footL c n h hc hn)) ?_ + rintro s' ⟨h', f, g⟩ + have V' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g + (fun c' k hk => by + rcases hk with hk | hk + · exact (hk : False).elim + · have := hk.2; omega) + (fun r k hk => by rcases hk with hk | hk <;> exact (hk : False).elim) + (BorK.of_lv g fun y k hk => by rcases hk with hk | hk <;> exact (hk : False).elim) + have Y' : YieldS st H.tcbs H.scs s' := Y.yld.lv hX.2.2.yt g + (fun y k hk => by rcases hk with hk | hk <;> exact (hk : False).elim) + (fun c' k hk => by + rcases hk with hk | hk + · exact (hk : False).elim + · have := hk.2; omega) + have D' := Y.dbg.lv hz g fun y k hk => by rcases hk with hk | hk <;> exact (hk : False).elim + have Ys : SymL st H Cs s' := ⟨D', Y'⟩ + have Kk : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = c ∨ q = n) s s' := + LvK.ofLv g (fun y k e => by rcases e with e | e <;> exact (e : False).elim) + (fun c' k e => by + rcases e with e | e + · exact (e : False).elim + · exact Or.inl e.1) + (fun m k e => by + rcases e with e | e + · exact Or.inr e.1 + · exact (e : False).elim) + (fun r e => by rcases e with e | e <;> exact (e : False).elim) + have M := EpM.ofK (ep_kept_kw h f) + refine ⟨h', f, K8.Foot.d (WritesIn.mono f fun _ hb => kw8_es hb), + LvM.ofNzX (NzX.ofLvK Kk (fun e he _ => M.1 e he) (fun m hm _ => M.2 m hm)) Y Ys hz h0, g.idle, ?_, V', Ys⟩ + rw [g.idle] + exact g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by rcases e with e | e <;> exact (e : False).elim + +/-- **The SC decode's extra cap** is the cap of a non-null extra slot, and `CapOK`. -/ +theorem schedcontext.extra_cap.slot {s s1 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (hw : WritesIn st s s1 (NodeW st s)) : + schedcontext.extra_cap st s1 extra 0#usize ⦃ o => ∀ c, o = some c → ∃ x ∈ extra.val, x ≠ 0#u64 ∧ + capA st s1 x = c ∧ CapOK st H.tcbs H.replies H.scs H.ntfns H s1 c ⦄ := by + unfold schedcontext.extra_cap + have hl0 : (0#usize).val < extra.val.length := by rw [extra.property]; simp + split + · simp_all + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra 0#usize hl0) fun sl hsl => ?_ + simp only [obj.Slot.is_null, bind_ok] + split + · simp + rename_i hz + have hm : sl ∈ extra.val := hsl ▸ List.getElem_mem hl0 + have hz' : sl ≠ 0#u64 := by simpa using hz + refine WP.spec_bind (WP.spec_and (D.extra s1 hw sl hm hz') + (show obj.Slot.cap st sl s1 ⦃ c => c = capA st s1 sl ⦄ by rw [capA_eq]; exact (WP.spec_ok _).2 rfl)) + fun c ⟨hc, ec⟩ => ?_ + exact (WP.spec_ok _).2 fun c' e => by cases e; exact ⟨sl, hm, hz', ec.symm, hc⟩ + +set_option maxHeartbeats 8000000 in +/-- **SchedContext Bind keeps every capability** (module docstring), at `schedcontext.decode`. -/ +theorem schedcontext.decode.bindSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl p b : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedContext p b) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.SchedContext p b)) (hl : lbl = fl4_abi.label.SchedContextBind) : + schedcontext.decode st ar s a lbl p call extra ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + obtain ⟨hp, hp0, hpi⟩ := D.cap.2.2 p b rfl + have h0 := B.ly.h0 + have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + have q := D.bxi.1.choose_spec.choose_spec + have oT : LvSO layout.sc.TCB.val := by unfold LvSO; simp [layout.sc.TCB] + have Dm : ∀ {s' : S}, DmPost st H Cs OS ia ie Ac s s' → + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := + fun d => (fun x => ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩) + (ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk) + unfold schedcontext.decode + step with obj.Sc.tcb.spec as ⟨i, ei⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => + (Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s r.1 ∧ + DF st H Cs (L.curW s) ∅ s r.1) ∧ DS st H.tcbs OS Vc s r.1 ∧ VsKeep st (L.ksb s) Pt s r.1) ?_ ?_ + · split + · refine WP.spec_mono (smp.remote_tcb_stall.delS hA D I a i) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + exact hh + · exact (WP.spec_ok _).2 ⟨⟨Stalled.refl0 D, DF.refl _⟩, DS.refl _, VsKeep.refl _⟩ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + have E1 : DmPost st H Cs OS ia ie Ac s s1 := + DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + h1.bxi.blk (DmW.ofDF d1) + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have ect' : ct = L.curW s := (show ct = L.curW s1 from ect).trans h1.cur + subst ect' + refine spec_ite (fun hc => absurd (hl.symm.trans hc) (lbl_ne_of_val (by + simp [fl4_abi.label.SchedContextConsumed, fl4_abi.label.SchedContextBind]))) fun _ => ?_ + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + refine WP.spec_bind (schedcontext.extra_cap.slot D h1.node) ?_ + rintro o ho + rcases o with _ | c + · simp only [error.truncated, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + obtain ⟨x, hxm, hx0, hcx, hcO⟩ := ho c rfl + have hxO : x ∈ OS := P.ext x hxm hx0 + cases c + all_goals first + | (simp only [error.invalid_cap, bind_ok]; exact (WP.spec_ok _).2 (Dm E1)) + | skip + case Notification n nb nsd nrv => + dsimp only + obtain ⟨hn, -⟩ := hcO.1.2.1 n nb nsd nrv rfl + refine WP.spec_bind (obj.Sc.ntfn.val s1 p) fun j ej => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hj + refine WP.spec_bind (obj.Ntfn.sc.val s1 n) fun j2 ej2 => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hj2 + refine WP.spec_bind (sched.set_thread_state.restartRK D P B Y h1 d1) fun s2 ⟨R, d2⟩ => ?_ + have oN : LvNO layout.ntfn.SC.val := by unfold LvNO; simp [layout.ntfn.SC] + have oS : LvSO layout.sc.NTFN.val := by unfold LvSO; simp [layout.sc.NTFN] + have z1 : L.mem s2 (ntfnScA n) = 0#u64 := by + have e1 : L.mem s2 (ntfnScA n) = L.mem s (ntfnScA n) := R.lv.n n hn _ oN fun e => False.elim e + have e2 : L.mem s1 (ntfnScA n) = L.mem s (ntfnScA n) := d1.lv.n n hn _ oN fun e => False.elim e + rw [e1, ← e2, ← ej2]; exact UScalar.eq_of_val_eq (by simpa using hj2) + have z2 : L.mem s2 (scNtfnA p) = 0#u64 := by + have e1 : L.mem s2 (scNtfnA p) = L.mem s (scNtfnA p) := R.lv.c p hp _ oS fun e => False.elim e + have e2 : L.mem s1 (scNtfnA p) = L.mem s (scNtfnA p) := d1.lv.c p hp _ oS fun e => False.elim e + rw [e1, ← e2, ← ej]; exact UScalar.eq_of_val_eq (by simpa using hj) + refine WP.spec_bind (schedcontext.bind_ntfn.dmE p n R.blk hp hp0 hn z1 z2 h0 R.sys.vr R.sym) + fun s3 ⟨h3, f3, d3⟩ => ?_ + have kO1 : OSKeep st OS s s1 := (DF.osTab P.heap P.os D.bxi B I.del.vr P.core0 d1).1 + have kO2 : OSKeep st OS s s2 := (DF.osTab P.heap P.os D.bxi B I.del.vr P.core0 d2).1 + have named : ∀ q' k', (q' = p ∨ q' = n) → H q' = some k' → ∃ y ∈ OS, NamesA (capA st s2 y) q' k' := by + rintro q' k' (e | e) hq <;> subst e + · exact R.namedS hcap hp k' hq + · have e : H q' = some .ntfn := hn + rw [e] at hq; cases hq + refine ⟨x, hxO, ?_⟩ + rw [kO2.capA hxO, ← kO1.capA hxO, hcx] + exact names_ntfn + exact (WP.spec_ok _).2 (Dm (DmPost.mk' (SysL.dfE R.pl.heap R.pl.os R.blk.bxi.blk hSA named R.sys d3) h3 + (DmW.trans (DmW.ofDF d2) (WritesIn.mono f3 fun _ hb => Or.inr (kw8_es hb))))) + case Thread t => + dsimp only + have ht : t ∈ H.tcbs := hcO.2.1 t rfl + refine WP.spec_bind (obj.Sc.tcb.spec s1 p) fun j1 ej1 => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hj1 + refine WP.spec_bind (obj.Tcb.sc.spec s1 t) fun j2 ej2 => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hj2 + have z1 : L.mem s1 (scTcbA p) = 0#u64 := by rw [← ej1]; exact UScalar.eq_of_val_eq (by simpa using hj1) + have z2 : L.mem s1 (scA t) = 0#u64 := by rw [← ej2]; exact UScalar.eq_of_val_eq (by simpa using hj2) + have z2s : L.mem s (scA t) = 0#u64 := by + rw [scA_eq, ← h1.fld t ht _ (by simp) (by simp), ← scA_eq]; exact z2 + have hne : t ≠ L.curW s := fun e => D.bxi.blk.2.1.resume D.act (by rw [← e]; exact z2s) + refine WP.spec_bind (sched.is_blocked.br s1 t) fun bb hbb => ?_ + have fin : (BlockedR (L.mem s1 (stA t)) → p ∈ Ac) → + (do + let (s2, a2) ← smp.remote_tcb_stall st ar s1 a1 t + let s3 ← sched.set_thread_state st s2 (L.curW s) sched.TS_RESTART + let (s4, a3) ← schedcontext.bind_tcb st ar s3 a2 p t + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s4, a3)) ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + intro hbA + refine WP.spec_bind (WP.spec_and (Stalled.stallD hA (y := t) h1 d1) + (smp.remote_tcb_stall.ds hA I.del.os I.del.vc hW (Stalled.cur0 D h1) a1 t)) ?_ + rintro ⟨s1', a1'⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨⟨h1', d1'⟩, ds2⟩ := hh + try simp only [uncurry_apply_pair] + have ds1' : DS st H.tcbs OS Vc s s1' := ds1.trans ds2 + have vk1' : VsKeep st (L.ksb s) Pt s s1' := vsk_node I.del.vr q h1'.node + have hrc : ∀ {Q : S → Prop}, tcb.restart_caller st s1' ⦃ Q ⦄ → + sched.set_thread_state st s1' (L.curW s) sched.TS_RESTART ⦃ Q ⦄ := fun hq => by + unfold tcb.restart_caller at hq + rw [cur_thread_ok, bind_ok, h1'.cur] at hq + exact hq + refine WP.spec_bind (hrc (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1' d1' ds1' vk1') + (tcb.restart_caller.armVsK I D P B h1' d1' ds1'))) ?_ + rintro s2 ⟨⟨⟨RS2, R2⟩, Q2, Z2⟩, K2⟩ + have k2 : ∀ K : U64, LvO K.val → L.mem s2 (wa t K) = L.mem s (wa t K) := + fun K hK => RS2.lv.t t ht K hK fun e => hne e.1 + have ht0 : L.mem s2 (scA t) = 0#u64 := by + rw [scA_eq, k2 3464#u64 (by unfold LvO; simp), ← scA_eq]; exact z2s + have hc0 : L.mem s2 (scTcbA p) = 0#u64 := by + have e1 : L.mem s2 (scTcbA p) = L.mem s (scTcbA p) := RS2.lv.c p hp _ oT fun e => False.elim e + have e2 : L.mem s1 (scTcbA p) = L.mem s (scTcbA p) := d1.lv.c p hp _ oT fun e => False.elim e + rw [e1, ← e2]; exact z1 + have hbA2 : BlockedR (L.mem s2 (stA t)) → p ∈ Ac := fun hb => hbA (by + rw [stA_eq, h1.fld t ht _ (by simp) (by simp), ← k2 3328#u64 (by unfold LvO; simp), ← stA_eq]; exact hb) + have hti : L.idleW s2 ≠ t := fun e => RS2.blk.2.1.idle (by rw [e]; exact ht0) + refine WP.spec_bind (schedcontext.bind_tcb.dmv hA a1' p t RS2.blk h0 RS2.sym RS2.sys.vr ht hp hp0 ht0 hc0 + hbA2 hti (fun hnz => (R2.jv.2.run t ht).resolve_left hnz) hW) ?_ + rintro ⟨s3, a3⟩ ⟨b3, d3⟩ + try simp only [uncurry_apply_pair] + have hnT := namedT_keep hxO (show obj.Slot.cap st x s = ok (.Thread t) by + rw [capA_eq, ← ds1.1.capA hxO, hcx]) ht K2.2 + have d3' : DMR st H Cs Vc t p s2 s3 := DMV.toR d3 + have hS3 := SysL.dfMDR I.del.heap I.del.os I.del.vc (fun b hb => (R2.jv.2.w hb).2.1) RS2.blk I.del.sca + hnT (RS2.namedS hcap hp) R2.sys d3' + have A3 := ArmQIAt.ofSusW I R2 hks P.core0 RS2.blk d3'.w hS3 b3 + have vk := (ArmVsK.ofSusW I R2 hks P.core0 RS2.blk d3'.w).2 + exact (WP.spec_ok _).2 ((fun h => ⟨h.1, h.2, ArmVsK.trans K2.1 K2.2 vk.1, OSKeep.trans' K2.2 vk.2⟩) + (ArmQIAt.transZ (ArmQIAt.ofDelR R2 Q2 Z2.1.toVs) Z2 A3 vk)) + split + · refine WP.spec_bind (sporadic.sc_released.act s1 p) fun b1 hb1 => ?_ + split + · rename_i hb1t + exact fin fun _ => (h1.bxi.2.2.2.2.act p hp).2 (hb1 hb1t) + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + · rename_i hbf + exact fin fun hb => absurd hb (hbb (by simpa using hbf)) + +/-- **SchedContext Bind keeps every capability** (the SchedContext arm of `decode_invocation`, `*_armS` shape). -/ +theorem syscall.decode_invocation.scBind_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p b : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedContext p b) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.SchedContext p b)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.SchedContextBind) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.SchedContext p b) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono (schedcontext.decode.bindSAt hA I D P B Y hks hSA hcap hl) fun r d => by + obtain ⟨_, s', a'⟩ := r + exact d + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCSched.lean b/proofs/Fl4ProofsA64/P1/S1aCSched.lean new file mode 100644 index 000000000..052d881f7 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCSched.lean @@ -0,0 +1,920 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c2 part 2): **the scheduler's switch to a thread**. + +* **`sched.switch_to_thread.dmd`**: `switch_to_thread t` (`set_vm_root` writes nothing, QueueSwitch's + `set_vm_root_same`; `dequeue`; the current node's `CUR_THREAD` word) is a `DMD p` step with `BlkOK` at its end + (S1aCYieldTo's `qstep`, QueueSchedule's `set_cur_thread.sch`). +* **`timer.remove.dmd`**: the timer words written are those of the removed thread and of armed keys (live by their + nonzero deadline, TimerRBRmv's `timer.remove.rb`), so `timer.remove` is a `DMD p` step. +* The walk bundle **`SW s0 s`** (`RpW` with every `OS` slot kept): `SW.dmd` (a `DMD p` step, `p` named), + **`SW.dfK`** (a queue step writing `K8` words and low state-block words: S1aCTime's `update_timestamp` route, the + words off every slot by `A64Layout.kslo`), `SW.q` (a queue step), **`nodeW_step`** (a free word of the current node, + QueueSchedCtl's `node_any_blk` over a footprint). +* **`timer.fire.sw`** (each round: `timer.remove`, the bound notification's `send_signal` — named, live by its bound + thread —, `REPROGRAM`), **`awaken.sw`**, **`next_domain.sw`** (`DfW KsLo`), **`choose_thread.sw`**, + **`schedule_choose_new_thread.sw`**, **`switch_sched_context.sw`** (QueueSchedule's switch part as `blkW`; its words + through `DMD.ofNSc`), **`cand_choose.sw`**. +* **`sched.schedule.sw`** / **`sched.schedule.s1a`**: QueueSchedule's `schedule.inv` walk with `SW`, ending in the S1a + step post (S1aCStepD's `S1aStepR2K.ofRpW`). + +Named premises: [P] `P0.ArchTotal`. Per-state fact: [J] `RunVcpuInv` (QueueFire's, `timer.fire`'s signal). `BufAt` +is not needed (`send_signal.tinv0`). +-/ +import Fl4ProofsA64.P1.S1aCBufAt + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 4000000 in +/-- **`switch_to_thread t` is a `DMD p` step** (module docstring). -/ +theorem sched.switch_to_thread.dmd (hA : P0.ArchTotal ar) (p : U64) {s : S} (a : A) (t : U64) (h : BK s) + (h0 : H 0#u64 = none) (Y : SymL st H Cs s) (VR : ValidReplies st H s) (ht : t ∈ H.tcbs) + (hbd : L.mem s (scA t) ≠ 0#u64) (hta : L.mem s (scA t) ∈ Ac) : + sched.switch_to_thread st ar s a t ⦃ s' _ => DMD st H Cs p s s' ∧ BK s' ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + unfold sched.switch_to_thread + refine WP.spec_bind (set_vm_root_same hA s a t) ?_ + rintro ⟨s1, a1⟩ e + simp only [WP.uncurry'_pair] at e + subst e + refine WP.spec_bind (WP.spec_and (sched.dequeue.sch s1 t Q R q hB hSg ht) + (K8.sched.dequeue.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s1 t q ht)) ?_ + rintro s2 ⟨⟨p2, -, -⟩, f2⟩ + obtain ⟨b2, -, d2⟩ := qstep p h h0 Y VR p2 f2 + obtain ⟨⟨Q2, R2, q2⟩, hB2, -, -, hSg2⟩ := id b2 + refine WP.spec_bind (WP.spec_and (sched.set_cur_thread.sch s2 t Q2 R2 q2 hB2 hSg2 ht + (fun _ => by rw [p2.fr.sc t ht]; exact hbd) (fun _ => by rw [p2.fr.sc t ht]; exact hta)) + (sched.set_cur_thread.spec s2 t)) ?_ + rintro s3 ⟨⟨p3, -, -⟩, e3⟩ + have f3 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s2 s3 := by + rw [e3]; exact K8.foot_node (q2.nodes _ q2.cur) q2.cur (by rw [curth0]; omega) (by rw [curth0]) + (by rw [curth0]; omega) + obtain ⟨b3, -, d3⟩ := qstep p b2 h0 d2.sym d2.vr p3 f3 + simp only [WP.spec_ok, WP.uncurry'_pair] + exact ⟨d2.trans d3, b3⟩ + + +set_option maxHeartbeats 4000000 in +/-- **`timer.remove t` is a `DMD p` step**: it writes the timer words of `t` and of the armed keys of `t`'s core's tree +(TimerRBRmv's `timer.remove.rb`); those keys are live by their nonzero deadline, `t`'s deadline word becomes null. -/ +theorem timer.remove.dmd (p : U64) {s : S} (t : U64) (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (ht : t ∈ H.tcbs) : + timer.remove st s t ⦃ s' => DMD st H Cs p s s' ∧ BK s' ⦄ := by + have C := LvC.of_blk h + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + refine WP.spec_mono (WP.spec_and (WP.spec_and (timer.remove.lv s t h ht) + (K8.timer.remove.tf (s0 := s) s t (K8.TF.start h) ht)) (timer.remove.rb s t C.tcb ht (TInv.rb h) C.nodes)) ?_ + rintro s' ⟨⟨⟨h', g, -, -, -⟩, tf⟩, -, -, -, x⟩ + have f : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' := K8.Foot.d tf.2.1 + have Y' : SymL st H Cs s' := ⟨Y.dbg.lv hz g (fun y k hk => by + have hk' : k = 3528 := hk + exact ⟨by omega, by omega, by omega⟩), + Y.yld.lv hX.2.2.yt g (fun y k hk => by have hk' : k = 3528 := hk; omega) (fun c k hk => (hk : False).elim)⟩ + have VR' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g (fun _ _ e => (e : False).elim) (fun _ _ e => e) + (fun y hy e => by + rw [stA_eq, g.t y hy 3328#u64 (by unfold LvO; simp) (show ¬ ((3328#u64 : U64).val = 3528) by simp), ← stA_eq] + exact e) + have K : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q ∈ H.tcbs ∧ L.mem s (tdA q) ≠ 0#u64) s s' := by + refine ⟨fun y hy hE K hK => ?_, fun c hc _ o ho => g.c c hc o ho False.elim, + fun n hn _ o ho => g.n n hn o ho False.elim, + fun r hr _ => g.r r hr _ (by unfold LvRO; simp [layout.reply.TCB]) False.elim, + fun c hc _ _ e => (g.hd c hc).symm.trans e⟩ + by_cases hk : K.val = 3528 + · rcases x with ⟨-, rfl⟩ | ⟨c, hc, W, hW, -, w⟩ + · rfl + · have hyW : y ∉ W.keys := fun hyW => hE ⟨hy, hW.armed y hyW⟩ + exact (KeepOut.of_wi C.tcb (C.nodes c hc) w).fld y hy hyW K hK.lt.1 hK.lt.2 + · exact g.t y hy K hK hk + exact ⟨DMD.ofK (E := fun q => q ∈ H.tcbs ∧ L.mem s (tdA q) ≠ 0#u64) h h0 Y Y' VR' (footD_es f) K + (fun q hq => Or.inr (Or.inr (LiveQ.tcb hq.1 (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl hq.2)))))))) + (EpM.ofK (ep_kept_kwd h f)) g.idle + (g.t _ hI 3464#u64 (by unfold LvO; simp) (show ¬ ((3464#u64 : U64).val = 3528) by simp)), h'⟩ + +/-- A low state-block word (offset below 224) is an `Ω` word outside the frame words. -/ +theorem ks_lo {s : S} (h : BK s) {o : U64} (ho : o.val < 224) (h8 : o.val % 8 = 0) : + wa (L.ksb s) o ∈ H.omega ∧ wa (L.ksb s) o ∉ H.frame := by + have h0 := h.1.choose_spec.choose_spec + have hSg := h.2.2.2.2 + have hN := h0.nodes _ h0.cur + refine ⟨hSg.ksΩ _ (by omega) h8, fun hs => ?_⟩ + have hk := hSg.ks _ hs + have hf := hN.fits + simp only [LawfulStore.nodeBase] at hf + have hv : (wa (L.ksb s) o).val = (L.ksb s).val + o.val := by + simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega + rw [hv] at hk; omega + +/-- The walk bundle of a non-transferring step (S1aCReplyW's `RpW` with every `OS` slot kept, and QueueVcTy's +`VKeep`: the VCPU words, the TCBs' VCPU links and buffer caps kept, so `VcTy` moves along). -/ +def SW (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS Vc : Set U64) (ia ie : Nat) (Ac : Set U64) + (s0 s : S) : Prop := + RpW st H Cs OS Vc ia ie Ac s0 s ∧ OSKeep st OS s0 s ∧ VKeep st H.tcbs Vc s0 s + +/-- A `K8` word of an empty SC / endpoint set is one of any. -/ +theorem kw8_scsE {T Sg Scs Es : Set U64} {Z : U64 → Nat} {s : S} {b : U64} (h : K8.KW st T Cs Sg ∅ Z ∅ s b) : + K8.KW st T Cs Sg Scs Z Es s b := by + rcases h with h | h | h | ⟨c, hc, -⟩ | ⟨e, he, -⟩ + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl h)) + · exact hc.elim + · exact he.elim + +set_option maxHeartbeats 4000000 in +/-- **A `DfW` footprint keeps the `VcTy` words** (QueueVcTy's `VKeep.of_kwd8` with the low state-block words: off the +VCPU words by `VcTy.ks`, off the TCBs as `Ω` words, off the slots by `A64Layout.kslo`). -/ +theorem VKeep.ofDfW {Ko : Set Nat} {OS Vc Ub : Set U64} {s s' : S} (h : BK s) + (hO : OSOK H.tcbs H.omega H.frame OS) (hV : VcOK H.tcbs H.scs H.scBits OS Vc Ub) (hA : ScApart H.scs H.scBits OS) + (hv : VcTy st H.tcbs Cs H.omega H H.frame H.scs H.scBits Vc Ub s) + (kslo : ∀ o : U64, o.val < 224 → ∀ y ∈ OS, ¬ (y.val ≤ (wa (L.ksb s) o).val ∧ (wa (L.ksb s) o).val < y.val + 32)) + (w : WritesIn st s s' (DfW st H.tcbs Cs H.frame H.scBits Ko s)) : VKeep st H.tcbs Vc s s' := by + obtain ⟨Q, R, q⟩ := h.1 + have hob := h.2.2.1.1 + have hsub := h.2.2.2.2.sub + have hE : ∀ e ∈ (∅ : Set U64), H e = some .ep ∨ H e = some .ntfn := fun _ he => he.elim + have ksΩ : ∀ o : U64, o.val < 224 → o.val % 8 = 0 → OutsideObjs st H.tcbs Cs s (wa (L.ksb s) o) := + fun o ho h8 => q.omega _ (ks_lo h ho h8).1 + have lk : ∀ t ∈ H.tcbs, ∀ K' : U64, (K'.val = 3664 ∨ K'.val = 3672) → L.mem s' (wa t K') = L.mem s (wa t K') := + fun t ht K' hK => by + have hn := lnk_not_kw8 (Scs := H.scs) (Es := ∅) q hob hsub hE ht hK + refine WritesIn.mem_eq w (field_aligned (q.tcbs t ht) (by omega) (by omega)) fun hF => ?_ + rcases hF with hk | ⟨o, -, ho, h8, e⟩ + · exact hn.1 (kw8_scsE hk) + · have hK1 : K'.val < 4096 := by omega + exact out_ne_field (ksΩ o ho h8) ht (q.tcbs t ht) hK1 (by rw [e]) + have cw : ∀ y ∈ OS, ∀ b, W7.CapW H.tcbs H.omega H.frame b → y.val ≤ b.val → b.val < y.val + 32 → Aligned b → + L.mem s' b = L.mem s b := fun y hy b hb h1 h2 hal => + WritesIn.mem_eq w hal fun hF => by + rcases hF with hk | ⟨o, -, ho, h8, e⟩ + · exact kw7_not_os (Es := ∅) q hsub hA hE hy hb h1 h2 (K8.KW.to7 (kw8_scsE hk)) + · subst e; exact kslo o ho y hy ⟨h1, h2⟩ + refine ⟨w.1, fun b hb => ?_, fun t ht => lk t ht _ (Or.inl (by simp)), + fun t ht => lk t ht 3672#u64 (Or.inr (by simp)), fun t ht => Or.inl ?_⟩ + · obtain ⟨hal, hΩ, hS⟩ := hv.w hb + have hn := vcw_not_kw8 (Scs := H.scs) (Es := ∅) q hV hE ⟨hΩ, hS⟩ hb + refine WritesIn.mem_eq w hal fun hF => ?_ + rcases hF with hk | ⟨o, -, ho, h8, e⟩ + · exact hn.1 (kw8_scsE hk) + · exact hv.ks b hb o (by omega) e.symm + · have hy := hV.bcov t ht + obtain ⟨v8, -, -⟩ := vals hO hy + rw [DPF.slot_cap_dec, DPF.slot_cap_dec, cw _ hy _ (hO.cw0 hy) (by omega) (by omega) (hO.al0 hy), + cw _ hy _ (hO.cw hy (k := 8#u64) (by simp) (by simp)) (by omega) (by omega) + (hO.al hy (k := 8#u64) (by simp) (by simp))] + +section sw +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +theorem SW.start {s : S} (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) : + SW st H Cs OS Vc ia ie Ac s s := + ⟨RpW.start B Y h, fun _ _ => ⟨rfl, rfl, rfl, rfl⟩, VKeep.refl s⟩ + +/-- **A `DMD p` step keeps the walk bundle** (`p` named, or null or in the idle area). -/ +theorem SW.dmd {p : U64} {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s0)) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (hp : ∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) p k) + (d : DMD st H Cs p s s') (b : BK s') : SW st H Cs OS Vc ia ie Ac s0 s' := + have R := W.1.dmdK I.del.heap I.del.os I.del.sca hc0 I.del.vr hks hp d b + have h := W.1.blk + ⟨R.1, W.2.1.trans' R.2, W.2.2.trans (VKeep.of_kwd8 I.del.os I.del.vc I.del.sca h.1.choose_spec.choose_spec + h.2.2.1.1 h.2.2.2.2.sub (fun _ he => he) (I.vty.keep W.2.2) d.w)⟩ + +theorem SW.dmd0 {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s0)) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (d : DMD st H Cs 0#u64 s s') (b : BK s') : SW st H Cs OS Vc ia ie Ac s0 s' := + W.dmd I hc0 hks (fun k hk => by rw [W.1.sys.ly.h0] at hk; cases hk) d b + +set_option maxHeartbeats 4000000 in +/-- **A queue step writing `K8` words and low state-block words keeps the walk bundle** (S1aCTime's +`update_timestamp.keepS` route: `SysL.dfN`, `DFB.oskX`, `TabKeep.ofW`, `ArmVsK.ofFoot`; the state-block words are off +every slot by `A64Layout.kslo`). -/ +theorem SW.dfK {Ko : Set Nat} {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hKo : ∀ o ∈ Ko, o < 224 ∧ o % 8 = 0) + (P : Post st H.tcbs Cs H.omega H H.frame Ac s s') + (w : WritesIn st s s' (DfW st H.tcbs Cs H.frame H.scBits Ko s)) : SW st H Cs OS Vc ia ie Ac s0 s' := by + have R := W.1 + obtain ⟨Q, Rq, q⟩ := R.blk.1 + have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt := by rw [R.ksb]; exact I.del.vr + have hH := I.del.heap + have hO := I.del.os + have C := LvC.of_blk R.blk + have l : LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.none s s' := LvF.of_fr C P.fr + obtain ⟨-, -, hX1, hS1, hSg1⟩ := id R.blk + have b' : BK s' := ⟨P.inv, P.bnd, hX1.fr P.fr, hS1.fr P.fr, hSg1.fr P.fr⟩ + have d : DFB st H Cs (L.curW s) ∅ (fun b => ∃ o : U64, o.val ∈ Ko ∧ b = wa (L.ksb s) o) s s' := + ⟨w.mono fun b hb => by + rcases hb with hk | ⟨o, h1, -, -, e⟩ + · exact Or.inl (Or.inl hk) + · exact Or.inr ⟨o, h1, e⟩, l.mono (LvF.none_le _)⟩ + have hBw : ∀ b, (∃ o : U64, o.val ∈ Ko ∧ b = wa (L.ksb s) o) → b ∈ H.omega ∧ b ∉ H.frame := by + rintro b ⟨o, ho, rfl⟩ + exact ks_lo R.blk (hKo _ ho).1 (hKo _ ho).2 + have hBo : ∀ x ∈ OS, ∀ b, x.val ≤ b.val → b.val < x.val + 32 → ¬ ∃ o : U64, o.val ∈ Ko ∧ b = wa (L.ksb s) o := by + rintro x hx b h1 h2 ⟨o, ho, rfl⟩ + exact R.sys.ly.kslo o (hKo _ ho).1 x hx ⟨h1, h2⟩ + have k : OSKeep st OS s s' := DFB.oskX (Xq := ∅) hO R.blk hBo d + obtain ⟨S', Y'⟩ := SysL.dfN hH hO R.blk hBw hBo R.sys R.sym d l + have F : TabF st H Cs OS s := TabF.of hvr q R.sys.ly.ksw hc0 + have nA : ∀ b, DfW st H.tcbs Cs H.frame H.scBits Ko s b → ¬ AsW (L.ksb s) b := + fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd + have t : TabKeep st s s' := TabKeep.ofW hvr w nA + have v : ArmVsK st H OS Vc s s' := ArmVsK.ofFoot hH q w (fun b hd => Or.inl hd) nA + exact ⟨⟨S', Y', b', R.xc.trans (XC.keep k t), R.xv.trans (XV.keep v k), R.xs.keep fun z hz => k.capA hz⟩, + W.2.1.trans' k, W.2.2.trans (VKeep.ofDfW R.blk hO I.del.vc I.del.sca (I.vty.keep W.2.2) R.sys.ly.kslo w)⟩ + +end sw + +set_option maxHeartbeats 4000000 in +/-- **A write of a free word of the current core's node** (`LowFree`, not a timer-tree word, not `CUR_SC`) from a +`BlkOK` state is a `DMD p` step to a `BlkOK` state (QueueSchedCtl's `node_any_blk` over a `WritesIn` footprint). -/ +theorem nodeW_step (p : U64) {o : U64} {s s' : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (ho : LowFree o.val) (hto : o.val ≠ 88 ∧ o.val ≠ 104 ∧ o.val ≠ 112) + (h24 : o.val ≠ 24) (w : WritesIn st s s' (· = L.nodeAt s (L.cpu s) o)) : + DMD st H Cs p s s' ∧ BK s' := by + obtain ⟨⟨Q, R, h1⟩, hB, hX, hS, hSg⟩ := id h + have hO := hX.1 + have hN := h1.nodes _ h1.cur + have ho' : o.val < 4288 := by unfold LowFree at ho; omega + have h8 : o.val % 8 = 0 := by unfold LowFree at ho; omega + have hi8 : o.val ≠ 8 := by unfold LowFree at ho; omega + have wF : WritesIn st s s' (L.Free s H.omega Cs) := w.mono fun b hb => hb ▸ free_cur_node h1.cur ho + obtain ⟨h2, hB2⟩ := free_step h1 hB wF + have ki := (free_keys h1 wF).2.2.1 + have hcs : L.cscW s' = L.cscW s := by + unfold LawfulStore.cscW; rw [cscW_eq w.1 w.2.1]; unfold LawfulStore.nodeA + refine w.mem_eq (nodeAt_aligned hN (by simp [layout.node.CUR_SC]) (by simp [layout.node.CUR_SC])) ?_ + intro e; have := congrArg UScalar.val e + rw [nodeAt_val hN (by simp [layout.node.CUR_SC]), nodeAt_val hN ho'] at this + simp [layout.node.CUR_SC] at this; omega + have hX2 := hX.writes h1.tcbs w (fun b hb => hb ▸ not_prot_node h1 hO hSg.sub h1.cur ho') + (by rw [hcs]; exact hX.2.2.cur) + (hX.tn_writes h1 w (fun b _ e => by + subst e + exact notTmW_node h1.tcbs h1.nodes (fun n hn => h1.omega _ (hSg.sub _ (hO.ntB n hn).2)) h1.cur ho' hto)) ki + have hS2 := SCsOK.node (hi8 := hi8) h1 hS ho' h8 h24 hto w + have b' : BK s' := ⟨⟨Q, R, h2⟩, hB2, hX2, hS2, + ⟨hSg.sub, fun b hb => by rw [w.1]; exact hSg.ks b hb, fun o h1 h2 => by rw [w.1]; exact hSg.ksΩ o h1 h2⟩⟩ + exact ⟨DMD.ofNSc h h0 Y VR (w.mono fun b hb => Or.inl ⟨L.cpu s, h1.cur, o, ho', h8, hto.1, fun _ => hi8, hb⟩), b'⟩ + +section fire +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +set_option maxHeartbeats 8000000 in +/-- **`timer.fire`'s loop keeps the walk bundle**: each round `timer.remove` (`timer.remove.dmd`), the bound +notification's `send_signal` (`send_signal.dmd`, the notification named: live by its bound thread), the `REPROGRAM` +word (`nodeW_step`); [J] `RunVcpuInv` carried (QueueFire's `timer.fire_loop.tinv` keeps). -/ +theorem timer.fire_loop.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) (now i : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hRV : RunVcpuInv st H.tcbs s) : + timer.fire_loop st ar s a now i ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ RunVcpuInv st H.tcbs s' ⦄ := by + have h0 := W.1.sys.ly.h0 + unfold timer.fire_loop + apply loop.spec_decr_nat (measure := fun x => 32 - x.2.2.val) + (inv := fun x => SW st H Cs OS Vc ia ie Ac s0 x.1 ∧ RunVcpuInv st H.tcbs x.1) + · rintro ⟨s1, a1, i1⟩ ⟨W1, r1⟩ + simp only at W1 r1 + unfold timer.fire_loop.body + dsimp only + split + · rename_i hi + have hi32 : i1.val < 32 := by simpa using hi + step with LawfulStore.cur_cpu_spec as ⟨c, ec⟩ + step with obj.node_get.spec as ⟨t, et⟩ + step with obj.Tcb.is_null.spec as ⟨b, eb⟩ + split + · exact (WP.spec_ok _).2 ⟨W1, r1⟩ + rename_i hb + have ht0 : t ≠ 0#u64 := fun e => hb (by rw [eb, e]; rfl) + have h1 := W1.1.blk + obtain ⟨⟨Q1, R1, h1q⟩, -, hX1, -, -⟩ := id h1 + have htT : t ∈ H.tcbs := by + have := hX1.2.2.tm.min _ h1q.cur + rw [← ec] at this; rw [← et] at this + rcases this with e | e + · exact absurd e ht0 + · exact e + step with obj.Tcb.timer_deadline.val as ⟨d, ed⟩ + split + · exact (WP.spec_ok _).2 ⟨W1, r1⟩ + step with obj.Tcb.timer_badge.val as ⟨bd, ebd⟩ + refine WP.spec_bind (WP.spec_and (timer.remove.dmd 0#u64 t h1 h0 W1.1.sym W1.1.sys.vr htT) + (timer.remove.rvi s1 t h1 r1 htT)) fun s2 hh2 => ?_ + obtain ⟨⟨d2, b2⟩, r2⟩ := hh2 + have W2 := W1.dmd0 I hc0 hks d2 b2 + step with obj.Tcb.bound_ntfn.val as ⟨n, en⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => SW st H Cs OS Vc ia ie Ac s0 r.1 ∧ RunVcpuInv st H.tcbs r.1) ?_ ?_ + · split + · rename_i hn0 + have hn0' : L.mem s2 (boundA t) ≠ 0#u64 := by rw [← en]; exact bne_ne hn0 + have hn : n ∈ H.ntfns := by rw [en]; exact b2.2.2.1.2.2.bnd t htT hn0' + have hH : H n = some .ntfn := hn + have bt : L.mem s2 (ntfnBtA n) = t := by rw [en]; exact b2.2.2.1.2.2.bs.tb t htT hn0' + refine WP.spec_mono (WP.spec_and (WP.spec_and + (notification.send_signal.dmd hA a1 n bd b2 hn hH h0 W2.1.sym W2.1.sys.vr + (fun y hy hb => r2.blocked hy hb)) + (notification.send_signal.tinv0 hA s2 a1 n bd b2 hn hH r2)) + (notification.send_signal.rvi hA s2 a1 n bd b2 hn hH r2)) fun r hr => ?_ + obtain ⟨s3, a3⟩ := r + simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨⟨d3, b3⟩, r3⟩ := hr + refine ⟨W2.dmd I hc0 hks (fun k hk hia => ?_) d3 b3, r3⟩ + rw [hH] at hk; cases hk + exact W2.1.sys.ln n .ntfn hH (LiveQ.ntfn hH (Or.inr (Or.inl (by rw [bt]; exact ne0_of_heap h0 htT)))) hia + · exact (WP.spec_ok _).2 ⟨W2, r2⟩ + rintro ⟨s3, a3⟩ ⟨W3, r3⟩ + simp only at W3 r3 + try simp only [WP.uncurry'_pair] + step with LawfulStore.cur_cpu_spec as ⟨c3, ec3⟩ + step with obj.node_set.spec as ⟨s4, es4⟩ + step as ⟨i4, ei4⟩ + try simp only [WP.spec_ok] + subst es4 ec3 + have b3 := W3.1.blk + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + obtain ⟨d4, b4⟩ := nodeW_step 0#u64 b3 h0 W3.1.sym W3.1.sys.vr (by rw [rp]; unfold LowFree; omega) + (by rw [rp]; omega) (by rw [rp]; omega) + (writesIn_wr (nodeAt_aligned (b3.1.choose_spec.choose_spec.nodes _ b3.1.choose_spec.choose_spec.cur) + (by rw [rp]; omega) (by rw [rp]))) + exact ⟨W3.dmd0 I hc0 hks d4 b4, reprogram.rvi b3 r3, by omega⟩ + · exact (WP.spec_ok _).2 ⟨W1, r1⟩ + · exact ⟨W, hRV⟩ + +theorem timer.fire.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hRV : RunVcpuInv st H.tcbs s) : + timer.fire st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ RunVcpuInv st H.tcbs s' ⦄ := by + unfold timer.fire + refine WP.spec_bind (L.cur_cpu_spec s) fun c _ => ?_ + refine WP.spec_bind (obj.node_get.spec s c _) fun now _ => ?_ + exact timer.fire_loop.sw hA a now 0#u64 I hc0 hks W hRV + +end fire + +section awaken +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +set_option maxHeartbeats 8000000 in +/-- **`awaken`'s release loop keeps the walk bundle**: `release_remove` (a queue step, `qstep`) and +`possible_switch_to` (MdbSigL's `possible_switch_to.dmd`), as QueueSchedStep's `awaken_loop.sch`. -/ +theorem sched.awaken_loop.sw {s0 s : S} (fuel : U64) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) : + sched.awaken_loop st s fuel ⦃ s' => SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + have h0 := W.1.sys.ly.h0 + unfold sched.awaken_loop + apply loop.spec_decr_nat (measure := fun x => x.2.val) + (inv := fun x => SW st H Cs OS Vc ia ie Ac s0 x.1) + · rintro ⟨s1, fu⟩ W1 + simp only at W1 + have h1 := W1.1.blk + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := id h1 + dsimp only + unfold sched.awaken_loop.body + split + swap + · exact (WP.spec_ok _).2 W1 + step as ⟨fuel1, ef1⟩ + step with LawfulStore.cur_cpu_spec as ⟨c, ec⟩ + step with obj.node_get.spec as ⟨i1, ei1⟩ + step with obj.Tcb.is_null.spec as ⟨b, b_post⟩ + split + · exact (WP.spec_ok _).2 W1 + rename_i hb + step with obj.Tcb.sc.spec as ⟨i2, ei2⟩ + step with sporadic.ready.spec as ⟨b1, eb1⟩ + split <;> try (exact (WP.spec_ok _).2 W1) + have hR := q1.release _ q1.cur + have hhead : i1 = (L.relQ s1 (L.cpu s1)).head := by subst_vars; rfl + have hne : i1 ≠ 0#u64 := by simpa [b_post] using hb + have hmem : i1 ∈ R1 (L.cpu s1) := by + rw [hhead, hR.head] at hne ⊢ + cases hR' : R1 (L.cpu s1) with + | nil => rw [hR'] at hne; exact absurd rfl hne + | cons x xs => simp + have hT1 : i1 ∈ H.tcbs := q1.memTR q1.cur hmem + refine WP.spec_bind (WP.spec_and (sched.release_remove.sch s1 i1 Q1 R1 q1 hB1 hSg1 hT1) + (K8.sched.release_remove.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s1 i1 q1 hT1)) ?_ + rintro s2 ⟨⟨P2, -, -, hst2⟩, f2⟩ + obtain ⟨b2, -, d2⟩ := qstep 0#u64 h1 h0 W1.1.sym W1.1.sys.vr P2 f2 + have W2 := W1.dmd0 I hc0 hks d2 b2 + have hrun : Runnable (L.mem s2 (stA i1)) := by + rw [hst2 i1 hT1]; exact q1.runR _ q1.cur i1 hmem + have hrel : (L.mem s1 (inqA i1) &&& sched.Q_RELEASE) ≠ 0#u64 := + (q1.released i1 hT1).2 (by rw [q1.inR _ q1.cur i1 hmem]; exact hmem) + refine WP.spec_bind (sched.possible_switch_to.dmd 0#u64 i1 b2 h0 W2.1.sym W2.1.sys.vr hT1 hrun (fun hz => by + rw [P2.fr.sc i1 hT1] at hz ⊢; exact hB1.sact i1 hT1 (Or.inr (Or.inl hrel)) hz)) ?_ + rintro s3 ⟨d3, b3⟩ + simp only [WP.spec_ok] + exact ⟨W2.dmd0 I hc0 hks d3 b3, by omega⟩ + · exact W + +/-- **`awaken` keeps the walk bundle** (`timer.fire.sw`, `awaken_loop.sw`). -/ +theorem sched.awaken.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hRV : RunVcpuInv st H.tcbs s) : + sched.awaken st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + unfold sched.awaken + refine WP.spec_bind (timer.fire.sw hA a I hc0 hks W hRV) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + refine WP.spec_bind (sched.awaken_loop.sw _ I hc0 hks hh.1) fun s2 W2 => ?_ + simp only [WP.spec_ok, WP.uncurry'_pair] + exact W2 + +end awaken + +section choose +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +/-- The low state-block offsets (8-aligned, below 224). -/ +def KsLo : Set Nat := {n | n < 224 ∧ n % 8 = 0} + +theorem dfw_ks {Q : U64 → U64 → List U64} {R : U64 → List U64} {s : S} {o v : U64} + (q : SchedQueuesInv st H.tcbs Cs H.omega H s Q R) (ho : o.val < 224) (h8 : o.val % 8 = 0) : + WritesIn st s (L.wr s (wa (L.ksb s) o) v) (DfW st H.tcbs Cs H.frame H.scBits KsLo s) := + (writesIn_wr (ks_aligned q (by omega) h8)).mono fun _ hb => Or.inr ⟨o, ⟨ho, h8⟩, ho, h8, hb⟩ + +theorem DfW.step {Ko : Set Nat} {s1 s2 s3 : S} + (w1 : WritesIn st s1 s2 (DfW st H.tcbs Cs H.frame H.scBits Ko s1)) + (w2 : WritesIn st s2 s3 (DfW st H.tcbs Cs H.frame H.scBits Ko s2)) : + WritesIn st s1 s3 (DfW st H.tcbs Cs H.frame H.scBits Ko s1) := + (w1.trans w2).mono fun _ hb => hb.elim id (DfW.ksb w1.1) + +/-- **`next_domain` writes low state-block words and the `REPROGRAM` node word** (QueueFootS's `next_domain.sfoot` +over `DfW KsLo`). -/ +theorem sched.next_domain.dfw {s : S} (h : BK s) : + sched.next_domain st s ⦃ s' => WritesIn st s s' (DfW st H.tcbs Cs H.frame H.scBits KsLo s) ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, -, -, hS⟩ := id h + unfold sched.next_domain + have hST : P0.StoreTotal st := L.total + step with obj.ks_get.spec as ⟨i, _⟩ + step as ⟨idx, _⟩ + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> step*) fun idx1 _ => ?_ + refine WP.spec_bind (WP.spec_and (ks_set.sch s Q R q hB hS (o := layout.ks.DOM_SCHED_IDX) (v := idx1) + (by simp [layout.ks.DOM_SCHED_IDX]) (by simp [layout.ks.DOM_SCHED_IDX])) (obj.ks_set.spec s _ idx1)) ?_ + rintro s1 ⟨⟨⟨h1, hB1, f1⟩, -, -⟩, e1⟩ + have F1 : WritesIn st s s1 (DfW st H.tcbs Cs H.frame H.scBits KsLo s) := by + rw [e1]; exact dfw_ks q (by simp [layout.ks.DOM_SCHED_IDX]) (by simp [layout.ks.DOM_SCHED_IDX]) + refine WP.spec_bind (WP.spec_and (sched.set_reprogram.sch s1 Q R h1 hB1 (hS.fr f1)) + (sched.set_reprogram.spec s1)) ?_ + rintro s2 ⟨⟨⟨h2, hB2, f2⟩, -, -⟩, e2⟩ + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have F2 : WritesIn st s1 s2 (DfW st H.tcbs Cs H.frame H.scBits KsLo s1) := by + rw [e2]; unfold LawfulStore.nodeA + exact (writesIn_wr (nodeAt_aligned (h1.nodes _ h1.cur) (by rw [rp]; omega) (by rw [rp]))).mono fun b hb => by + subst hb; exact Or.inl (K8.kw_node h1.cur (by rw [rp]; omega) (by rw [rp]; omega)) + refine WP.spec_bind (WP.spec_and (ks_set.sch s2 Q R h2 hB2 ((hS.fr f1).fr f2) (o := layout.ks.WORK_UNITS) (v := 0#u64) + (by simp [layout.ks.WORK_UNITS]) (by simp [layout.ks.WORK_UNITS])) (obj.ks_set.spec s2 _ 0#u64)) ?_ + rintro s3 ⟨⟨⟨h3, hB3, f3⟩, -, -⟩, e3⟩ + have F3 : WritesIn st s2 s3 (DfW st H.tcbs Cs H.frame H.scBits KsLo s2) := by + rw [e3]; exact dfw_ks h2 (by simp [layout.ks.WORK_UNITS]) (by simp [layout.ks.WORK_UNITS]) + have hS3 := ((hS.fr f1).fr f2).fr f3 + step with sched.dom_sched_domain.spec as ⟨d⟩ + step with sched.dom_sched_duration.spec as ⟨t⟩ + refine WP.spec_bind (WP.spec_and (ks_set.sch s3 Q R h3 hB3 hS3 (o := layout.ks.CUR_DOMAIN) (v := d) + (by simp [layout.ks.CUR_DOMAIN]) (by simp [layout.ks.CUR_DOMAIN])) (obj.ks_set.spec s3 _ d)) ?_ + rintro s4 ⟨⟨⟨h4, -, -⟩, -, -⟩, e4⟩ + have F4 : WritesIn st s3 s4 (DfW st H.tcbs Cs H.frame H.scBits KsLo s3) := by + rw [e4]; exact dfw_ks h3 (by simp [layout.ks.CUR_DOMAIN]) (by simp [layout.ks.CUR_DOMAIN]) + refine WP.spec_mono (obj.ks_set.spec s4 _ t) ?_ + intro s5 e5 + have F5 : WritesIn st s4 s5 (DfW st H.tcbs Cs H.frame H.scBits KsLo s4) := by + rw [e5]; exact dfw_ks h4 (by simp [layout.ks.DOMAIN_TIME]) (by simp [layout.ks.DOMAIN_TIME]) + exact DfW.step F1 (DfW.step F2 (DfW.step F3 (DfW.step F4 F5))) + +/-- **`next_domain` keeps the walk bundle** (`SW.dfK`). -/ +theorem sched.next_domain.sw {s0 s : S} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (W : SW st H Cs OS Vc ia ie Ac s0 s) : + sched.next_domain st s ⦃ s' => SW st H Cs OS Vc ia ie Ac s0 s' ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, -, -, hSg⟩ := id W.1.blk + exact WP.spec_mono (WP.spec_and (sched.next_domain.sch s Q R q hB hSg) (sched.next_domain.dfw W.1.blk)) + fun s' hh => W.dfK I hc0 (fun _ ho => ho) hh.1.1 hh.2 + +set_option maxHeartbeats 4000000 in +/-- **`set_cur_thread t`** (one node word) is a `DMD p` step. -/ +theorem sched.set_cur_thread.dmd (p : U64) {s : S} (t : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (ht : t ∈ H.tcbs) (hbd : L.mem s (scA t) ≠ 0#u64) + (hta : L.mem s (scA t) ∈ Ac) : + sched.set_cur_thread st s t ⦃ s' => DMD st H Cs p s s' ∧ (BK s') ∧ L.curW s' = t ∧ + L.mem s' (scA t) = L.mem s (scA t) ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, -, -, hSg⟩ := id h + refine WP.spec_mono (WP.spec_and (sched.set_cur_thread.sch s t Q R q hB hSg ht (fun _ => hbd) (fun _ => hta)) + (sched.set_cur_thread.spec s t)) ?_ + rintro s' ⟨⟨P, ec, -⟩, e⟩ + have f : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' := by + rw [e] + exact K8.foot_node (q.nodes _ q.cur) q.cur (by rw [curth0]; omega) (by rw [curth0]) (by rw [curth0]; omega) + obtain ⟨b, -, d⟩ := qstep p h h0 Y VR P f + exact ⟨d, b, ec, P.fr.sc t ht⟩ + +set_option maxHeartbeats 8000000 in +/-- **`choose_thread` keeps the walk bundle**, the new current thread with an active SC (QueueSchedule's +`choose_thread.sch`; `switch_to_thread.dmd`, or the idle thread's `set_cur_thread.dmd`). -/ +theorem sched.choose_thread.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) : + sched.choose_thread st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ + L.mem s' (scA (L.curW s')) ≠ 0#u64 ∧ L.mem s' (scA (L.curW s')) ∈ Ac ⦄ := by + have h := W.1.blk + have h0 := W.1.sys.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, -, -, hS⟩ := id h + unfold sched.choose_thread + simp only [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + rw [ite_cond_eq_false _ _ (by simp)] + simp only [bind_ok] + step with LawfulStore.cur_cpu_spec as ⟨cpu, cpu_post⟩ + subst cpu_post + unfold sched.bitmap_dom + simp only [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + rw [ite_cond_eq_false _ _ (by simp)] + simp only [bind_ok] + step with l1_off_zero as ⟨i1, i1_post⟩ + subst i1_post + step with obj.node_get.spec as ⟨i2, i2_post⟩ + split + · have hne : L.l1W s (L.cpu s) ≠ 0#u64 := by + rw [show L.l1W s (L.cpu s) = i2 from i2_post.symm]; simpa using ‹(i2 != 0#u64) = true› + refine WP.spec_bind (sched.highest_prio.spec s 0#u64 _ (q.nodes _ q.cur) (q.ready _ q.cur).2 hne) ?_ + rintro p ⟨hp, hpne, -⟩ + step with sched.rq_head_off.spec as ⟨off, off_post, off_post1⟩ + step with sched.q_get.spec as ⟨qq, q_post⟩ + have hq : qq = L.rqQ s (L.cpu s) p := by rw [q_post, off_post1, off_post]; rfl + have hrel := (q.ready _ q.cur).1.rel p hp + have hmem : qq.head ∈ Q (L.cpu s) p := by rw [hq, hrel.head]; exact headD_mem hpne _ + have htT : qq.head ∈ H.tcbs := hrel.mem _ hmem + have hqq : (L.mem s (inqA qq.head) &&& sched.Q_QUEUED) ≠ 0#u64 := by + obtain ⟨e1, e2⟩ := q.inQ _ q.cur p hp _ hmem + exact (q.queued _ htT).2 (by rw [e1, e2]; exact hmem) + have hbd : L.mem s (scA qq.head) ≠ 0#u64 := hB.q _ htT hqq + refine WP.spec_mono (WP.spec_and (sched.switch_to_thread.dmd hA 0#u64 a qq.head h h0 W.1.sym W.1.sys.vr htT hbd + (hB.qA htT hqq)) (sched.switch_to_thread.sch hA s a qq.head Q R q hB hS htT hbd (hB.qA htT hqq))) fun r hr => ?_ + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨⟨d, b⟩, P, ec, -⟩ := hr + exact ⟨W.dmd0 I hc0 hks d b, by rw [ec, P.fr.sc _ htT]; exact hbd, by rw [ec, P.fr.sc _ htT]; exact hB.qA htT hqq⟩ + · unfold sched.switch_to_idle_thread + step with sched.idle_thread.spec' as ⟨idle, idle_post⟩ + refine WP.spec_bind (set_kernel_vm_root_same (st := st) hA s a) ?_ + rintro ⟨s1, a1⟩ e + simp only [WP.uncurry'_pair] at e + subst s1 + have hiT : idle ∈ H.tcbs := by rw [idle_post]; exact q.idleT + have hbd : L.mem s (scA idle) ≠ 0#u64 := by rw [idle_post]; exact hB.idle + have hia : L.mem s (scA idle) ∈ Ac := by rw [idle_post]; exact hB.idleA q.idleT + refine WP.spec_bind (sched.set_cur_thread.dmd 0#u64 idle h h0 W.1.sym W.1.sys.vr hiT hbd hia) ?_ + rintro s2 ⟨d, b, ec, esc⟩ + simp only [WP.spec_ok, WP.uncurry'_pair] + exact ⟨W.dmd0 I hc0 hks d b, by rw [ec, esc]; exact hbd, by rw [ec, esc]; exact hia⟩ + +/-- **`schedule_choose_new_thread` keeps the walk bundle** (`next_domain.sw`, `choose_thread.sw`). -/ +theorem sched.schedule_choose_new_thread.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) : + sched.schedule_choose_new_thread st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ + L.mem s' (scA (L.curW s')) ≠ 0#u64 ∧ L.mem s' (scA (L.curW s')) ∈ Ac ⦄ := by + unfold sched.schedule_choose_new_thread + step with sched.domain_time.spec as ⟨i⟩ + refine WP.spec_bind (Pₘ := fun s1 => SW st H Cs OS Vc ia ie Ac s0 s1) ?_ ?_ + · split + · exact sched.next_domain.sw I hc0 W + · exact (WP.spec_ok _).2 W + intro s1 W1 + exact sched.choose_thread.sw hA a I hc0 hks W1 + +end choose + +section ssc +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +set_option maxHeartbeats 16000000 in +/-- **`switch_sched_context` from a resuming state** keeps `BlkOK` and writes the two rings, the old SC's `CONSUMED` +word and the node's `REPROGRAM`, `CONSUMED`, `CUR_SC` words (QueueSchedule's `schedule.inv`, its switch part). -/ +theorem sched.switch_sched_context.blkW {T Ω Sg Rp Scs Nt : Set U64} {Z : U64 → Nat} (hA : P0.ArchTotal ar) + {s4 : S} (a2 : A) (h : BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s4) (ea4 : L.actionW s4 = 0#u64) : + sched.switch_sched_context st ar s4 a2 ⦃ s5 _ => BlkOK st T Cs Ω H Sg Rp Scs Nt Z Ac s5 ∧ + WritesIn st s4 s5 (fun b => InRing (L.mem s4 (scA (L.curW s4))) (Z (L.mem s4 (scA (L.curW s4)))) b ∨ + (InRing (L.cscW s4) (Z (L.cscW s4)) b ∨ b = core.num.U64.wrapping_add (L.cscW s4) layout.sc.CONSUMED) ∨ + b = L.nodeA s4 layout.node.REPROGRAM ∨ b = L.nodeA s4 layout.node.CONSUMED ∨ + b = L.nodeA s4 layout.node.CUR_SC) ∧ + L.mem s4 (scA (L.curW s4)) ∈ Scs ∧ L.cscW s4 ∈ Scs ⦄ := by + obtain ⟨⟨Q4, R4, h4⟩, hB4, hX4, hS4, hSg4⟩ := h + have hcT := h4.curT + have hb4 : L.mem s4 (scA (L.curW s4)) ≠ 0#u64 := hB4.resume ea4 + have hO4 := hX4.1 + have hsub4 := hS4.sub + have hts : L.mem s4 (scA (L.curW s4)) ∈ Scs := (hX4.2.2.bound _ hcT hb4).1 + have hcs : L.cscW s4 ∈ Scs := hX4.2.2.cur + have npn : ∀ o : U64, o.val < 4288 → ¬ Prot T Rp Scs Nt (L.nodeA s4 o) := fun o ho => + not_prot_node h4 hO4 hsub4 h4.cur ho + have hcq : SCq st s4 Ω (L.cscW s4) (Z (L.cscW s4)) := by + obtain ⟨hP, hz⟩ := hO4.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 hcv : layout.sc.CONSUMED.val = 8 := by simp [layout.sc.CONSUMED] + obtain ⟨a1, a2, a3⟩ := maxA_facts hO4 hcs + exact ⟨(hS4.all _ hcs).1, fun b hb hi => hsub4 _ ((hS4.all _ hcs).2.2 b hb hi), + ⟨⟨by rw [hv]; omega, by rw [hv, hcv]; omega⟩, by unfold Aligned; rw [hv, hcv]; omega⟩, ⟨a2, a3⟩, a1⟩ + have htin : SCin st s4 Ω (L.mem s4 (scA (L.curW s4))) (Z (L.mem s4 (scA (L.curW s4)))) := + (hS4.scin hts (hB4.curA hcT ea4)).mono hsub4 + refine WP.spec_mono (WP.spec_and (WP.spec_and (sched.switch_sched_context.free hA s4 a2 (zt := Z (L.mem s4 (scA (L.curW s4)))) + (zc := Z (L.cscW s4)) h4.cur (h4.nodes _ h4.cur) h4.omega hcq + (fun hne => ⟨htin, hS4.disj _ hcT hb4 hne⟩)) + (sched.switch_sched_context.fp hA s4 a2 (zt := Z (L.mem s4 (scA (L.curW s4)))) + (zc := Z (L.cscW s4)) (B := fun b => ¬ Prot T Rp Scs Nt b) h4.cur (h4.nodes _ h4.cur) h4.omega + hcq (fun hne => ⟨htin, hS4.disj _ hcT hb4 hne⟩) + (npn _ (by simp [layout.node.REPROGRAM])) (npn _ (by simp [layout.node.CONSUMED])) + (npn _ (by simp [layout.node.CUR_SC])) + (fun _ b hb hr => not_prot_ring h4 hO4 hts hb (Or.inl hr)) + (fun b hb hr => not_prot_ring h4 hO4 hcs hb hr))) + (sched.switch_sched_context.fp hA s4 a2 (zt := Z (L.mem s4 (scA (L.curW s4)))) + (zc := Z (L.cscW s4)) + (B := fun b => InRing (L.mem s4 (scA (L.curW s4))) (Z (L.mem s4 (scA (L.curW s4)))) b ∨ + (InRing (L.cscW s4) (Z (L.cscW s4)) b ∨ b = core.num.U64.wrapping_add (L.cscW s4) layout.sc.CONSUMED) ∨ + b = L.nodeA s4 layout.node.REPROGRAM ∨ b = L.nodeA s4 layout.node.CONSUMED ∨ + b = L.nodeA s4 layout.node.CUR_SC) h4.cur (h4.nodes _ h4.cur) h4.omega + hcq (fun hne => ⟨htin, hS4.disj _ hcT hb4 hne⟩) + (Or.inr (Or.inr (Or.inl rfl))) (Or.inr (Or.inr (Or.inr (Or.inl rfl)))) (Or.inr (Or.inr (Or.inr (Or.inr rfl)))) + (fun _ b _ hr => Or.inl hr) (fun b _ hr => Or.inr (Or.inl hr)))) ?_ + rintro ⟨s5, a3⟩ ⟨⟨w5, w5', e5, -, -⟩, w5'', e5', wfc5, wft5⟩ + simp only [WP.uncurry'_pair] at w5 w5' e5 w5'' e5' wfc5 wft5 ⊢ + have hS5 : SCsOK st T Ω Sg Scs Z Ac s5 := SCsOK.switch h4 hS4 hX4 hb4 w5'' e5' wfc5 wft5 + obtain ⟨h5, hB5⟩ := free_step h4 hB4 w5 + have hΩ4 : ∀ n ∈ Nt, OutsideObjs st T Cs s4 (ntfnBtA n) := fun n hn => h4.omega _ (hsub4 _ (hO4.ntB n hn).2) + have hX5 : XInv st T Cs Ω Sg Rp Scs Nt Z s5 := hX4.writes h4.tcbs w5' (fun b hb => hb) (by + unfold LawfulStore.cscW; rw [cscW_eq w5.1 w5.2.1, e5]; exact hts) + (hX4.tn_writes h4 w5'' (fun b hb hh => by + rcases hh with hh | (hh | hh) | hh | hh | hh + · exact notTmW_ring h4 hO4 hsub4 hts hb (Or.inl hh) + · exact notTmW_ring h4 hO4 hsub4 hcs hb (Or.inl hh) + · exact notTmW_ring h4 hO4 hsub4 hcs hb (Or.inr hh) + · subst hh; exact notTmW_node h4.tcbs h4.nodes hΩ4 h4.cur (by simp [layout.node.REPROGRAM]) + (by simp [layout.node.REPROGRAM]) + · subst hh; exact notTmW_node h4.tcbs h4.nodes hΩ4 h4.cur (by simp [layout.node.CONSUMED]) + (by simp [layout.node.CONSUMED]) + · subst hh; exact notTmW_node h4.tcbs h4.nodes hΩ4 h4.cur (by simp [layout.node.CUR_SC]) + (by simp [layout.node.CUR_SC]))) (free_keys h4 w5).2.2.1 + + exact ⟨⟨⟨Q4, R4, h5⟩, hB5, hX5, hS5, hS5.sg⟩, w5'', hts, hcs⟩ + +set_option maxHeartbeats 8000000 in +/-- **`switch_sched_context` keeps the walk bundle**: its words are node words and SC words off the liveness words +(S1aCNScW's `DMD.ofNSc`). -/ +theorem sched.switch_sched_context.sw (hA : P0.ArchTotal ar) {s0 s4 : S} (a2 : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s4) (ea4 : L.actionW s4 = 0#u64) : + sched.switch_sched_context st ar s4 a2 ⦃ s5 _ => SW st H Cs OS Vc ia ie Ac s0 s5 ⦄ := by + have h4 := W.1.blk + have h0 := W.1.sys.ly.h0 + have hO := h4.2.2.1.1 + have q := h4.1.choose_spec.choose_spec + refine WP.spec_mono (sched.switch_sched_context.blkW hA a2 h4 ea4) fun r hr => ?_ + obtain ⟨s5, a3⟩ := r + simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨b5, w, hts, hcs⟩ := hr + obtain ⟨hPt, hzt⟩ := hO.sc _ hts + obtain ⟨hPc, hzc⟩ := hO.sc _ hcs + refine W.dmd0 I hc0 hks (DMD.ofNSc h4 h0 W.1.sym W.1.sys.vr (w.mono fun b hb => ?_)) b5 + rcases hb with hr | (hr | e) | e | e | e + · have hv80 := hr.1 + exact NScW.ofSC hts hPt hzt hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · have hv80 := hr.1 + exact NScW.ofSC hcs hPc hzc hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · rw [e] + exact NScW.ofSCo hcs hPc hzc (by simp [layout.sc.CONSUMED]) + ⟨by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], + by simp [layout.sc.CONSUMED], fun e => absurd e (by simp [layout.sc.CONSUMED])⟩ + · unfold LawfulStore.nodeA at e + exact Or.inl ⟨L.cpu s4, q.cur, layout.node.REPROGRAM, by simp [layout.node.REPROGRAM], + by simp [layout.node.REPROGRAM], by simp [layout.node.REPROGRAM], fun _ => by simp [layout.node.REPROGRAM], e⟩ + · unfold LawfulStore.nodeA at e + exact Or.inl ⟨L.cpu s4, q.cur, layout.node.CONSUMED, by simp [layout.node.CONSUMED], + by simp [layout.node.CONSUMED], by simp [layout.node.CONSUMED], fun _ => by simp [layout.node.CONSUMED], e⟩ + · unfold LawfulStore.nodeA at e + exact Or.inl ⟨L.cpu s4, q.cur, layout.node.CUR_SC, by simp [layout.node.CUR_SC], + by simp [layout.node.CUR_SC], by simp [layout.node.CUR_SC], fun _ => by simp [layout.node.CUR_SC], e⟩ + +/-- A queue step (`Post`, a `K8` footprint) keeps the walk bundle (S1aCYieldTo's `qstep`). -/ +theorem SW.q {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s0)) (W : SW st H Cs OS Vc ia ie Ac s0 s) + (P : Post st H.tcbs Cs H.omega H H.frame Ac s s') (f : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s') : + SW st H Cs OS Vc ia ie Ac s0 s' := + have Z := qstep 0#u64 W.1.blk W.1.sys.ly.h0 W.1.sym W.1.sys.vr P f + W.dmd0 I hc0 hks Z.2.2 Z.1 + +end ssc + +section sched +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq : Set U64} + +set_option maxHeartbeats 8000000 in +/-- **The candidate's requeue and a new choice keep the walk bundle** (QueueSchedule's `cand_choose`). -/ +theorem cand_choose.sw (hA : P0.ArchTotal ar) {s0 s : S} (a : A) (act : obj.Tcb) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s0) (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s0)) + (W : SW st H Cs OS Vc ia ie Ac s0 s) (hact : L.actionW s = act) (hT : act ∈ H.tcbs) (app : Bool) : + (do + let s5 ← if app then sched.append st s act else sched.enqueue st s act + let s6 ← sched.set_action st s5 sched.ACTION_CHOOSE_NEW + sched.schedule_choose_new_thread st ar s6 a) ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s0 s' ∧ + L.mem s' (scA (L.curW s')) ≠ 0#u64 ∧ L.mem s' (scA (L.curW s')) ∈ Ac ⦄ := by + obtain ⟨⟨Q, R, h⟩, hB, -, -, hSg⟩ := id W.1.blk + have hok := h.actOK (hact ▸ hT) + rw [hact] at hok + have hr : (L.mem s (inqA act) &&& sched.Q_RELEASE) = 0#u64 := by + by_contra hc + exact hok.2 _ (h.aff act hT) ((h.released act hT).1 hc) + have hbd : L.mem s (scA act) ≠ 0#u64 := by have := hB.act (hact ▸ hT); rw [hact] at this; exact this + have hba : L.mem s (scA act) ∈ Ac := by have := hB.actA (hact ▸ hT); rwa [hact] at this + refine WP.spec_bind (Pₘ := fun s5 => SW st H Cs OS Vc ia ie Ac s0 s5) ?_ ?_ + · split + · exact WP.spec_mono (WP.spec_and (sched.append.sch s act Q R h hB hSg hT (fun _ => hr) (fun _ => hok.1) + (fun _ => hbd) (fun _ => hba)) (sched.append.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) + s act h hT)) fun s5 hh => W.q I hc0 hks hh.1.1 (K8.FootB.foot hh.2) + · exact WP.spec_mono (WP.spec_and (sched.enqueue.sch s act Q R h hB hSg hT (fun _ => hr) (fun _ => hok.1) + (fun _ => hbd) (fun _ => hba)) (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) + (Es := ∅) s act h hT)) fun s5 hh => W.q I hc0 hks hh.1.1 (K8.FootB.foot hh.2) + intro s5 W5 + obtain ⟨⟨Q5, R5, h5⟩, hB5, -, -, hSg5⟩ := id W5.1.blk + rw [choose_val] + refine WP.spec_bind (WP.spec_and (sched.set_action.sch s5 1#u64 Q5 R5 h5 hB5 hSg5 (Or.inr (Or.inl rfl)) + (fun hT => absurd hT (one_notT h5)) (fun hT => absurd hT (one_notT h5)) (fun e => by simp at e) + (fun hT => absurd hT (one_notT h5))) (K8.sched.set_action.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) + (Es := ∅) s5 1#u64 (h5.nodes _ h5.cur) h5.cur)) ?_ + rintro s6 ⟨⟨P6, -, -, -⟩, f6⟩ + exact sched.schedule_choose_new_thread.sw hA a I hc0 hks (W5.q I hc0 hks P6 (K8.FootB.foot f6)) + +set_option maxHeartbeats 16000000 in +/-- **`schedule` keeps the walk bundle** (QueueSchedule's `schedule.inv` walk with `SW`: `awaken.sw`, the action +block — `enqueue`, `cand_choose.sw`, `switch_to_thread.dmd`, `schedule_choose_new_thread.sw` —, `set_action`, +`switch_sched_context.sw`, `set_next_interrupt` and the `REPROGRAM` clear (`nodeW_step`), `send_pending`'s two node +words). Per-state fact: [J] `RunVcpuInv` (QueueFire's). -/ +theorem sched.schedule.sw (hA : P0.ArchTotal ar) {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) (hRV : RunVcpuInv st H.tcbs s) : + sched.schedule st ar s a ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s s' ⦄ := by + have h0 := B.ly.h0 + unfold sched.schedule + refine WP.spec_bind (sched.awaken.sw hA a I hc0 hks (SW.start B Y h) hRV) ?_ + rintro ⟨s1, a1⟩ W1 + simp only [WP.uncurry'_pair] at W1 + -- `check_domain_time` does nothing with one domain + unfold sched.check_domain_time sched.is_cur_domain_expired + simp only [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + have hnd : ¬ ((1#u64) > (1#u64)) := by simp + simp only [hnd, ↓reduceIte, bind_ok, Bool.false_eq_true] + step with sched.action.spec as ⟨act, act_post⟩ + obtain ⟨⟨Q1, R1, h1⟩, hB1, hX1, hS1, hSg1⟩ := id W1.1.blk + refine WP.spec_bind (Pₘ := fun r => SW st H Cs OS Vc ia ie Ac s r.1 ∧ L.mem r.1 (scA (L.curW r.1)) ≠ 0#u64 ∧ + L.mem r.1 (scA (L.curW r.1)) ∈ Ac) ?_ ?_ + · split + · rename_i hnr + step with sched.cur_thread.spec as ⟨ct, ct_post⟩ + have hctT : ct ∈ H.tcbs := by rw [ct_post]; exact h1.curT + step with sched.is_schedulable.spec' as ⟨wr, wr_post⟩ + refine WP.spec_bind (Pₘ := fun s4 => SW st H Cs OS Vc ia ie Ac s s4 ∧ L.actionW s4 = L.actionW s1) ?_ ?_ + · split + · exact WP.spec_mono (WP.spec_and (sched.enqueue.sch s1 ct Q1 R1 h1 hB1 hSg1 hctT + (fun _ => (wr_post ‹_›).2.2.1) (fun _ => (wr_post ‹_›).1) (fun _ => (wr_post ‹_›).2.1) + (fun _ => (hS1.act _ (hX1.2.2.bound _ hctT (wr_post ‹_›).2.1).1).2 (wr_post ‹_›).2.2.2)) + (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s1 ct h1 hctT)) + fun s4 hh => ⟨W1.q I hc0 hks hh.1.1 (K8.FootB.foot hh.2), hh.1.2.1⟩ + · exact (WP.spec_ok _).2 ⟨W1, rfl⟩ + rintro s4 ⟨W4, ea4⟩ + obtain ⟨⟨Q4, R4, h4⟩, hB4, hX4, hS4, hSg4⟩ := id W4.1.blk + have hact4 : L.actionW s4 = act := ea4.trans act_post.symm + split + · exact sched.schedule_choose_new_thread.sw hA a1 I hc0 hks W4 + rename_i hnc + have hT : act ∈ H.tcbs := by + rcases h4.action with e | e | e + · exfalso; rw [hact4] at e; rw [e, resume_val] at hnr; simp at hnr + · exfalso; rw [hact4] at e; rw [e, choose_val] at hnc; simp at hnc + · rw [hact4] at e; exact e + have hbd : L.mem s4 (scA act) ≠ 0#u64 := by have := hB4.act (hact4 ▸ hT); rw [hact4] at this; exact this + have hba : L.mem s4 (scA act) ∈ Ac := by have := hB4.actA (hact4 ▸ hT); rwa [hact4] at this + have L1 := cand_choose.sw hA a1 act I hc0 hks W4 hact4 hT true + have L3 := cand_choose.sw hA a1 act I hc0 hks W4 hact4 hT false + simp only [↓reduceIte, Bool.false_eq_true] at L1 L3 + have L2 : sched.switch_to_thread st ar s4 a1 act ⦃ s' _ => SW st H Cs OS Vc ia ie Ac s s' ∧ + L.mem s' (scA (L.curW s')) ≠ 0#u64 ∧ L.mem s' (scA (L.curW s')) ∈ Ac ⦄ := + WP.spec_mono (WP.spec_and (sched.switch_to_thread.dmd hA 0#u64 a1 act W4.1.blk h0 W4.1.sym W4.1.sys.vr hT hbd + hba) (sched.switch_to_thread.sch hA s4 a1 act Q4 R4 h4 hB4 hSg4 hT hbd hba)) fun r hr => by + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨⟨d, b⟩, P, ec, -⟩ := hr + exact ⟨W4.dmd0 I hc0 hks d b, by rw [ec, P.fr.sc act hT]; exact hbd, by rw [ec, P.fr.sc act hT]; exact hba⟩ + step with sched.cur_thread.spec as ⟨ct1, _⟩ + step with sched.idle_thread.spec' as ⟨t, _⟩ + step with tcb_eq.spec as ⟨b⟩ + refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun fastfail _ => ?_ + · split + · simp + · step with obj.Tcb.prio.spec as ⟨i, _⟩ + step with obj.Tcb.prio.spec as ⟨i1, _⟩ + split <;> simp + split + · step with sched.cur_domain.spec' as ⟨i⟩ + step with obj.Tcb.prio.spec as ⟨i1, _⟩ + step with sched.is_highest_prio.ok s4 Q4 R4 h4 as ⟨b1⟩ + split + · split + · step with obj.Tcb.prio.spec as ⟨i2, _⟩ + split + · exact L1 + · exact L2 + · exact L2 + · exact L3 + · split + · step with obj.Tcb.prio.spec as ⟨i, _⟩ + step with obj.Tcb.prio.spec as ⟨i1, _⟩ + split + · exact L1 + · exact L2 + · exact L2 + · rename_i hr0 + have e0 : L.actionW s1 = 0#u64 := by + rw [← act_post]; rw [resume_val] at hr0 + apply UScalar.eq_of_val_eq; simpa using hr0 + exact (WP.spec_ok _).2 ⟨W1, hB1.resume e0, hB1.curA h1.curT e0⟩ + rintro ⟨s3, a2⟩ ⟨W3, hcb, hcbA⟩ + try simp only [WP.uncurry'_pair] + rw [resume_val] + obtain ⟨⟨Q3, R3, h3⟩, hB3, -, -, hSg3⟩ := id W3.1.blk + refine WP.spec_bind (WP.spec_and (sched.set_action.sch s3 0#u64 Q3 R3 h3 hB3 hSg3 (Or.inl rfl) + (fun hT => absurd hT (notT_small h3.tcbs (by simp))) (fun hT => absurd hT (notT_small h3.tcbs (by simp))) + (fun _ => ⟨hcb, hcbA⟩) (fun hT => absurd hT (notT_small h3.tcbs (by simp)))) + (K8.sched.set_action.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s3 0#u64 + (h3.nodes _ h3.cur) h3.cur)) ?_ + rintro s4 ⟨⟨P4, ea4, -, -⟩, f4⟩ + have W4 := W3.q I hc0 hks P4 (K8.FootB.foot f4) + refine WP.spec_bind (sched.switch_sched_context.sw hA a2 I hc0 hks W4 ea4) ?_ + rintro ⟨s5, a3⟩ W5 + simp only [WP.uncurry'_pair] at W5 ⊢ + have b5 := W5.1.blk + have q5 := b5.1.choose_spec.choose_spec + step with LawfulStore.cur_cpu_spec as ⟨c, c_post⟩ + step with obj.node_get.spec as ⟨i, _⟩ + refine WP.spec_bind (Pₘ := fun r => SW st H Cs OS Vc ia ie Ac s r.1) ?_ ?_ + · split + · refine WP.spec_bind (sched.set_next_interrupt.fp hA s5 a3 + (B := (· = L.nodeAt s5 (L.cpu s5) layout.node.ARMED)) (q5.nodes _ q5.cur) rfl) ?_ + rintro ⟨s7, a5⟩ w7 + simp only [WP.uncurry'_pair] at w7 ⊢ + have av : layout.node.ARMED.val = 80 := by simp [layout.node.ARMED] + obtain ⟨d7, b7⟩ := nodeW_step 0#u64 b5 h0 W5.1.sym W5.1.sys.vr (by rw [av]; unfold LowFree; omega) + (by rw [av]; omega) (by rw [av]; omega) w7 + have W7 := W5.dmd0 I hc0 hks d7 b7 + step with obj.node_set.spec as ⟨s8, s8_post⟩ + try simp only [WP.spec_ok] + have q7 := b7.1.choose_spec.choose_spec + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have w8 : WritesIn st s7 s8 (· = L.nodeAt s7 (L.cpu s7) layout.node.REPROGRAM) := by + rw [s8_post, c_post, ← w7.2.1] + exact writesIn_wr (nodeAt_aligned (q7.nodes _ q7.cur) (by rw [rp]; omega) (by rw [rp])) + obtain ⟨d8, b8⟩ := nodeW_step 0#u64 b7 h0 W7.1.sym W7.1.sys.vr (by rw [rp]; unfold LowFree; omega) + (by rw [rp]; omega) (by rw [rp]; omega) w8 + exact W7.dmd0 I hc0 hks d8 b8 + · exact (WP.spec_ok _).2 W5 + rintro ⟨s6, a4⟩ W6 + try simp only [WP.uncurry'_pair] at W6 ⊢ + have b6 := W6.1.blk + have q6 := b6.1.choose_spec.choose_spec + refine WP.spec_mono (smp.send_pending.two hA s6 a4 (q6.nodes _ q6.cur)) fun r w' => ?_ + obtain ⟨s', a'⟩ := r + try simp only [WP.uncurry'_pair] at w' ⊢ + rcases w' with e | ⟨s7, w1, w2⟩ + · subst e; exact W6 + have pv : layout.node.IPI_PENDING.val = 120 := by simp [layout.node.IPI_PENDING] + have hv : layout.node.IPI_PENDING_HI.val = 128 := by simp [layout.node.IPI_PENDING_HI] + obtain ⟨d1, b1⟩ := nodeW_step 0#u64 b6 h0 W6.1.sym W6.1.sys.vr (by rw [pv]; unfold LowFree; omega) + (by rw [pv]; omega) (by rw [pv]; omega) w1 + have W7 := W6.dmd0 I hc0 hks d1 b1 + obtain ⟨d2, b2⟩ := nodeW_step 0#u64 b1 h0 W7.1.sym W7.1.sys.vr (by rw [hv]; unfold LowFree; omega) + (by rw [hv]; omega) (by rw [hv]; omega) w2 + exact W7.dmd0 I hc0 hks d2 b2 + +/-- **`schedule` keeps the S1a step post** (`schedule.sw`, S1aCStepD's `S1aStepR2K.ofRpW`). -/ +theorem sched.schedule.s1a {K : capability.Cap → Prop} {Ty : S → Prop} + {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} (hA : P0.ArchTotal ar) {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (hc0 : 0#u64 ∈ Cs) (hks : HeapKsOff H (L.ksb s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.schedule st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.schedule.sw hA a I B Y h hc0 hks hRV) fun r W => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at W ⊢ + exact S1aStepR2K.ofRpW W.1 W.2.1 I.del.vr I.fu I.vcc C Kc Df R sep KC + +end sched + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCSchedCtlA.lean b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlA.lean new file mode 100644 index 000000000..c84797c29 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlA.lean @@ -0,0 +1,105 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a13), part 2): **`configure_flags`' first block as a `DMD target` step**. + +* **`NScW.ofSC`**: an SC word off the SC liveness offsets (or the configured SC's `REFILL_MAX`) is an `NScW` word. +* **`cfA.dm`**: QueueSchedCtl's `cfA` block (the thread's stall, its release-queue and ready-queue removal, the + current SC's `commit_time`) is a `DMD target` step: the stall writes no liveness word (MdbLiveX's + `remote_tcb_stall.dfS`), the queue steps are S1aCYieldTo's `qstep`, `commit_time` writes ring, `CONSUMED` and node + words (QueueSc's `commit_time.fr`, S1aCNScW's `DMD.ofNSc`). + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCNScW +import Fl4ProofsA64.P1.QueueScBindV + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- **An SC word off the SC liveness offsets** (or `p`'s `REFILL_MAX`) is an `NScW p` word. -/ +theorem NScW.ofSC {p c b : U64} {s : S} (hc : c ∈ H.scs) (hP : Placed c (H.scBits c)) (hz : 7 ≤ H.scBits c) + (hin : InSC c (H.scBits c) b) + (hn : b.val ≠ c.val + 24 ∧ b.val ≠ c.val + 32 ∧ b.val ≠ c.val + 40 ∧ b.val ≠ c.val + 56 ∧ + (b.val = c.val + 72 → c = p)) : + NScW st Cs H.scs H.scBits p s b := + Or.inr ⟨c, hc, hin, fun o hO e => by + obtain ⟨h1, h2, h3, h4, h5⟩ := hn + have hv := sc_word_val hP hz (o := o) (by unfold LvSO at hO; omega) + rw [← e] at hv + unfold LvSO at hO + exact ⟨h5 (by omega), by omega⟩⟩ + +/-- An SC word at an offset below 128. -/ +theorem NScW.ofSCo {p c o : U64} {s : S} (hc : c ∈ H.scs) (hP : Placed c (H.scBits c)) (hz : 7 ≤ H.scBits c) + (ho : o.val < 128) (hn : o.val ≠ 24 ∧ o.val ≠ 32 ∧ o.val ≠ 40 ∧ o.val ≠ 56 ∧ (o.val = 72 → c = p)) : + NScW st Cs H.scs H.scBits p s (wa c o) := by + have hv := sc_word_val hP hz ho + obtain ⟨-, h128, -⟩ := sc_lo hP hz + obtain ⟨n1, n2, n3, n4, n5⟩ := hn + exact NScW.ofSC hc hP hz ⟨by rw [hv]; omega, by rw [hv]; omega⟩ + ⟨by rw [hv]; omega, by rw [hv]; omega, by rw [hv]; omega, by rw [hv]; omega, fun e => n5 (by rw [hv] at e; omega)⟩ + +set_option maxHeartbeats 4000000 in +/-- **`configure_flags`' first block is a `DMD target` step** (module docstring). -/ +theorem cfA.dm (hA : P0.ArchTotal ar) (a : A) (i target : U64) {s : S} (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hi : i ∈ H.tcbs) : + (do + let (s2, a2) ← smp.remote_tcb_stall st ar s a i + let s3 ← sched.release_remove st s2 i + let s4 ← sched.dequeue st s3 i + let s5 ← sched.cur_sc st s4 + let b1 ← obj.Sc.Insts.CoreCmpPartialEqSc.eq s5 target + let t ← if b1 then sched.commit_time st ar s4 a2 else ok s4 + ok (t, a2)) ⦃ r => DMD st H Cs target s r.1 ⦄ := by + refine WP.spec_bind (WP.spec_and (K8.smp.remote_tcb_stall.blk hA s a i h) + (smp.remote_tcb_stall.dfS hA s a i (BlkOK.bxi h))) ?_ + rintro ⟨s2, a2⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨⟨b2, -, -, -, -⟩, -, -, -, f2, l2⟩ := hh + have d2 : DMD st H Cs target s s2 := DMD.ofNone h h0 Y VR (K8.Foot.d (foot_noSc (Es := ∅) f2)) l2 + try simp only [uncurry_apply_pair] + obtain ⟨⟨Q2, R2, q2⟩, hB2, -, -, hSg2⟩ := id b2 + refine WP.spec_bind (WP.spec_and (sched.release_remove.sch s2 i Q2 R2 q2 hB2 hSg2 hi) + (K8.sched.release_remove.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s2 i q2 hi)) ?_ + rintro s3 ⟨hp3, f3⟩ + obtain ⟨b3, -, d3⟩ := qstep target b2 h0 d2.sym d2.vr hp3.1 f3 + obtain ⟨⟨Q3, R3, q3⟩, hB3, -, -, hSg3⟩ := id b3 + refine WP.spec_bind (WP.spec_and (sched.dequeue.sch s3 i Q3 R3 q3 hB3 hSg3 hi) + (K8.sched.dequeue.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s3 i q3 hi)) ?_ + rintro s4 ⟨hp4, f4⟩ + obtain ⟨b4, -, d4⟩ := qstep target b3 h0 d3.sym d3.vr hp4.1 f4 + step with sched.cur_sc.spec as ⟨c5, _⟩ + refine WP.spec_bind (Pₘ := fun _ => True) (by unfold obj.Sc.Insts.CoreCmpPartialEqSc.eq; simp) fun b1 _ => ?_ + refine WP.spec_bind (Pₘ := fun t5 => DMD st H Cs target s4 t5) ?_ + fun t5 d5 => (WP.spec_ok _).2 (d2.trans (d3.trans (d4.trans d5))) + split + · obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id b4 + have hO := hX.1 + have hc : L.cscW s4 ∈ H.scs := hX.2.2.cur + have hN' := q.nodes _ q.cur + obtain ⟨hP, hz⟩ := hO.sc _ hc + have cnv : layout.node.CONSUMED.val = 40 := by simp [layout.node.CONSUMED] + have aC : Aligned (L.nodeA s4 layout.node.CONSUMED) := nodeAt_aligned hN' (by rw [cnv]; omega) (by rw [cnv]) + have oC : Outside (L.nodeA s4 layout.node.CONSUMED) (L.cscW s4) (H.scBits (L.cscW s4)) := + node_out_place (fun b hb hin => hO.scW _ hc b hb hin) q.omega q.cur hN' (by rw [cnv]; omega) (by rw [cnv]) + refine WP.spec_mono (sched.commit_time.fr hA a2 (hS.all _ hc).1 rfl aC oC) fun s' hw => + DMD.ofNSc b4 h0 d4.sym d4.vr (hw.1.mono fun b hb => ?_) + rcases hb with (hr | e) | e + · have hv80 := hr.1 + exact NScW.ofSC hc hP hz hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · rw [e] + exact NScW.ofSCo hc hP hz (by simp [layout.sc.CONSUMED]) + ⟨by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], + by simp [layout.sc.CONSUMED], fun e => absurd e (by simp [layout.sc.CONSUMED])⟩ + · exact Or.inl ⟨L.cpu s4, q.cur, layout.node.CONSUMED, by rw [cnv]; omega, by rw [cnv], by rw [cnv]; omega, + fun _ => by rw [cnv]; omega, e⟩ + · exact (WP.spec_ok _).2 (DMD.refl target b4 h0 d4.sym d4.vr) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCSchedCtlB.lean b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlB.lean new file mode 100644 index 000000000..c7e06ac87 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlB.lean @@ -0,0 +1,158 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a13), part 3): **the SC's core write and the thread's migration as one +`DMV` step** (`configure_flags`: `set_cpu`, then `migrate_tcb` of its thread), as MdbSspBind's `bind_tcb.dmv` head. + +* **`cf_cpuMig.dmv`**: from a `BlkOK` state, the write of the SC's `CORE` word and `migrate_tcb` of its thread is a + `DMV i target` step with `BlkOK` at its end: `migrate_tcb` by QueueScBindV's `migrate_tail_fV` and MdbSspMig's + `symV`, liveness by MdbSspBind's `LvK.of_migV` / `DonK.of_migV`, the debug-list members live before. +* **`DMR.ofDMVlive`**: a `DMV i p` step whose `i` is live before is a `DMR p p` step. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCSchedCtlA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- A `DMV i p` step whose `i` is live before is a `DMR p p` step. -/ +theorem DMR.ofDMVlive {i p : U64} {s s' : S} (d : DMV st H Cs Vc i p s s') (hi : LiveQ st H Cs s i) : + DMR st H Cs Vc p p s s' := + ⟨d.w.mono fun _ h => Or.inl h, fun x hx _ hl => by + by_cases e : x = i + · subst e; exact hi + · exact d.lv x e hx hl, d.idle, d.isc, d.vr, d.sym⟩ + +/-- A `DMD p` step is a `DMR p p` step. -/ +theorem DMR.ofDMD {p : U64} {s s' : S} (d : DMD st H Cs p s s') : DMR st H Cs Vc p p s s' := + DMV.toR (DMD.toV d) + +set_option maxHeartbeats 8000000 in +/-- **`set_cpu` and `migrate_tcb` as one `DMV i target` step** (module docstring). -/ +theorem cf_cpuMig.dmv (hA : P0.ArchTotal ar) {s : S} (a : A) (target i cpu : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hi : i ∈ H.tcbs) (htS : target ∈ H.scs) (hTA : target ∈ Ac) + (hcpu : cpu ∈ Cs) (hsci : L.mem s (scA i) = target) (hu : ∀ y ∈ H.tcbs, L.mem s (scA y) = target → y = i) + (htq : (L.mem s (inqA i) &&& sched.Q_QUEUED) = 0#u64) (htr : (L.mem s (inqA i) &&& sched.Q_RELEASE) = 0#u64) + (hrv : L.mem s (runVcpuA i) ≠ 0#u64 → L.mem s (runVcpuA i) ∈ Vc) + (hVc : ∀ v ∈ Vc, VcWords H.omega H.frame v) : + smp.migrate_tcb st ar (L.wr s (scCoreA target) cpu) a i cpu ⦃ s' _ => + (BK s') ∧ L.actionW s' = L.actionW s ∧ L.mem s' (scA i) = target ∧ L.mem s' (scCoreA target) = cpu ∧ + DMV st H Cs Vc i target s s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hO := hX.1 + have hT := q.tcbs + have hta := hT i hi + obtain ⟨hP, hzz⟩ := hO.sc target htS + have hsg : scCoreA target ∈ H.frame := (hO.fixW target htS).2 + have hm : scCoreA target ∈ H.omega := hSg.sub _ hsg + have hal : Aligned (scCoreA target) := (q.omega _ hm).1 + set s2 := L.wr s (scCoreA target) cpu with hs2 + have W2 : WritesIn st s s2 (fun b => b = scCoreA target) := writesIn_wr hal + have G2 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.sc target 72) s s2 := + LvF.ofNSc C (W2.mono fun b hb => by + rw [hb] + exact NScW.ofSCo htS hP hzz (by simp [layout.sc.CORE]) + ⟨by simp [layout.sc.CORE], by simp [layout.sc.CORE], by simp [layout.sc.CORE], by simp [layout.sc.CORE], + fun e => absurd e (by simp [layout.sc.CORE])⟩) + obtain ⟨h3, ea2, -, -, fl3⟩ := scword_blkW (d := i) (a := scCoreA target) (v := cpu) h htS hTA (Or.inl (scCoreA_val hP hzz)) + (fun _ => ⟨hcpu, fun t ht hne e => hne (hu t ht e)⟩) + obtain ⟨⟨Q2, R2, q2⟩, hB2, hX2, hS2, hSg2⟩ := h3 + have C2 : LvC st H.tcbs Cs H.omega H.frame H.replies H.scs H.ntfns H.scBits s2 := C.of_lv G2 + have D2 : DbgS st H.tcbs Cs s2 := Y.dbg.lv hz G2 fun _ _ hk => (hk : False).elim + have z2 : DbgTz st H.tcbs Cs s2 := DbgTz.lv hz G2 fun _ _ hk => (hk : False).elim + have rv2 : L.mem s2 (runVcpuA i) = L.mem s (runVcpuA i) := by + unfold runVcpuA + exact L.mem_wr_ne hal (field_aligned (K := 3672#u64) hta (by simp) (by simp)) + (fun e => out_ne_field (q.omega _ hm) hi hta (K := 3672#u64) (by simp) e.symm) + have k2s : L.ksb s2 = L.ksb s := L.ksb_wr _ _ _ + have hpo2 : L.mem s2 (runVcpuA i) ≠ 0#u64 → VcWords H.omega H.frame (L.mem s2 (runVcpuA i)) := fun hnz => by + rw [rv2]; exact hVc _ (hrv (by rw [← rv2]; exact hnz)) + have howV : L.mem s2 (runVcpuA i) ≠ 0#u64 → ownA (L.mem s2 (runVcpuA i)) ∈ H.omega ∧ + ownA (L.mem s2 (runVcpuA i)) ∉ H.frame := fun hnz => ⟨(ownA_vc (hpo2 hnz)).2.1, (ownA_vc (hpo2 hnz)).2.2⟩ + have co2 : L.mem s2 (scCoreA target) = cpu := L.mem_wr_same hal + refine WP.spec_mono (WP.spec_and (migrate_tail_fV hA s2 a target i cpu Q2 R2 q2 hB2 hX2 hS2 hSg2 hi + (by rw [(fl3 i hi).2.2]; exact htq) (by rw [(fl3 i hi).2.2]; exact htr) hcpu htS + (fun _ => by rw [(fl3 i hi).1, hsci]; exact co2) hpo2) + (smp.migrate_tcb.symV hA s2 a i cpu q2.tcbs q2.nodes z2 D2 (q2.aff i hi) hcpu hi q2.omega hpo2)) ?_ + rintro ⟨s3, a1⟩ ⟨⟨⟨⟨Q3, R3, q3⟩, hB3, hX3, hS3, hSg3⟩, -, -, -, sc3, -, ea3⟩, D3, K3, z3, w3⟩ + have BK3 : BK s3 := ⟨⟨Q3, R3, q3⟩, hB3, hX3, hS3, hSg3⟩ + have dk : DonK st H.tcbs H.replies H.scs s s3 := + (DonK.of_lv G2 (fun _ _ hk => (hk : False).elim) (fun c k hk => by rw [hk.2]; decide) + fun _ _ hk => (hk : False).elim).trans (DonK.of_migV C2 hi howV w3) + have Y3 : SymL st H Cs s3 := ⟨D3, YieldS.yk Y.yld hX.2.2.yt dk.toYKeep⟩ + have K : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun x => x = i ∨ x = target ∨ DbgIT st H.tcbs Cs s x) s s3 := + (LvK.ofLv G2 (fun _ _ hk => (hk : False).elim) (fun c k hk => Or.inr (Or.inl hk.1)) + (fun _ _ hk => (hk : False).elim) (fun _ hk => (hk : False).elim)).trans + ((LvK.of_migV C2 hi howV w3 K3).mono fun x hx => by + rcases hx with e | hx + · exact Or.inl e + · exact Or.inr (Or.inr (DbgIT.lv G2 (fun _ _ hk => (hk : False).elim) hx))) + have WA : WritesIn st s s3 (fun b => b = scCoreA target ∨ (b = affA i ∨ DbgW st H.tcbs Cs s2 b ∨ + (L.mem s2 (runVcpuA i) ≠ 0#u64 ∧ b = ownA (L.mem s2 (runVcpuA i))))) := W2.trans w3 + have EM : EpM st H s s3 := EpM.ofK (ep_keptX h WA fun b _ hb => by + rcases hb with rfl | (rfl | (⟨y, hy, rfl | rfl⟩ | ⟨c, hc, rfl⟩) | ⟨h0', rfl⟩) + · exact Or.inl hm + · exact Or.inr (Or.inl ⟨i, hi, 3520#u64, by simp, rfl⟩) + · exact Or.inr (Or.inl ⟨y, hy, 3576#u64, by simp, rfl⟩) + · exact Or.inr (Or.inl ⟨y, hy, 3584#u64, by simp, rfl⟩) + · exact Or.inr (Or.inr (Or.inl ⟨c, hc, layout.node.DEBUG_TCBS, by rw [debug_val]; omega, s2, k2s, rfl⟩)) + · exact Or.inl (howV h0').1) + have M := NzX.ofLvK (E := fun x => x = i ∨ x = target ∨ x = 0#u64 ∨ LiveQ st H Cs s x) + (K.mono fun x hx => by + rcases hx with e | e | hq + · exact Or.inl e + · exact Or.inr (Or.inl e) + · by_cases q0 : x = 0#u64 + · exact Or.inr (Or.inr (Or.inl q0)) + · exact Or.inr (Or.inr (Or.inr (LiveW.q (Or.inl ⟨DbgIT.mem hz hq q0, Or.inr (Or.inr (Or.inr hq))⟩))))) + (fun e he _ => EM.1 e he) (fun n hn _ => EM.2 n hn) + have hI : L.idleW s ∈ H.tcbs := q.idleT + have isc3 : L.mem s3 (scA (L.idleW s3)) = L.mem s (scA (L.idleW s)) := by + rw [dk.idle] + have e1 : L.mem s2 (scA (L.idleW s)) = L.mem s (scA (L.idleW s)) := + G2.t _ hI 3464#u64 (by unfold LvO; simp) fun hk => (hk : False).elim + refine Eq.trans ?_ e1 + have hia := hT _ hI + refine w3.mem_eq (scA_aligned hia) ?_ + rintro (e | hd | ⟨h0', e⟩) + · exact field_ne (K1 := 3464#u64) (K2 := 3520#u64) hia hta (by simp) (by simp) (fun _ => by simp) e + · exact notDbgW_field (K := 3464#u64) hT q2.nodes hI (by simp) ⟨by simp, by simp⟩ hd + · exact out_ne_field (K := 3464#u64) (q.omega _ (howV h0').1) hI hia (by simp) + (congrArg UScalar.val e) + have co3 : L.mem s3 (scCoreA target) = cpu := by + have := (q3.omega _ hm).1 + refine Eq.trans (w3.mem_eq hal ?_) co2 + rintro (e | hd | ⟨h0', e⟩) + · exact out_ne_field (q.omega _ hm) hi hta (K := 3520#u64) (by simp) (congrArg UScalar.val e).symm + · rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact out_ne_field (q.omega _ hm) hy (hT y hy) (K := 3576#u64) (by simp) (congrArg UScalar.val e).symm + · exact out_ne_field (q.omega _ hm) hy (hT y hy) (K := 3584#u64) (by simp) (congrArg UScalar.val e).symm + · exact out_ne_node (q2.omega _ hm) hc (q2.nodes c hc) (by rw [debug_val]; omega) (congrArg UScalar.val e).symm + · exact (howV h0').2 (e ▸ hsg) + refine ⟨BK3, ea3.trans ea2, sc3.trans ((fl3 i hi).1.trans hsci), co3, SspW.trans (((W2.mono fun b hb => ?_) : WritesIn st s s2 (SspW st H Cs Vc s))) + (w3.mono fun b hb => ?_), fun x hxt hxs hl => ?_, dk.idle, isc3, VR.donK hX.2.1 dk, Y3⟩ + · rw [hb]; exact Or.inl (Or.inr (Or.inr (Or.inl hsg))) + · rcases hb with rfl | hd | ⟨h0', rfl⟩ + · exact Or.inl (Or.inl ⟨i, hi, 3520#u64, by simp, by simp, by simp, ⟨by simp, by simp, by simp, by simp⟩, rfl⟩) + · exact Or.inr (Or.inl hd) + · exact Or.inr (Or.inr ⟨_, by rw [rv2]; exact hrv (by rw [← rv2]; exact h0'), vcpu.OWNER_CPU, + by simp [vcpu.OWNER_CPU], by simp [vcpu.OWNER_CPU], rfl⟩) + · by_cases hq : LiveQ st H Cs s x + · exact hq + · exact LvM.ofNzX M Y Y3 hz h0 x (fun e => by + rcases e with e | e | e | e + · exact hxt e + · exact hxs e + · exact LiveQ.ne0 h0 hl e + · exact hq e) hl + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCSchedCtlC.lean b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlC.lean new file mode 100644 index 000000000..a8704081a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlC.lean @@ -0,0 +1,352 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a13), part 4): **SchedControl `configure_flags` as one `DMR target target` +step**. + +* **`cfT.dmd`**: `configure_flags`' tail for a bound SC after the migration (QueueScBindV's `cfDV` from `resume` on): + `resume` (MdbSigL's `resume.dmd`), `possible_switch_to` (`possible_switch_to.dmd`), `enqueue` and + `reschedule_required` (S1aCYieldTo's `qstep`), the reprogram flag and the remote reschedule (node words, + S1aCNScW's `DMD.ofNSc`) is a `DMD target` step with `BlkOK` at its end. +* **`schedcontext.configure_flags.dmr`**: the whole of `configure_flags` (QueueScBindV's `configure_flags.blkV` walk): + S1aCSchedCtlA's `cfA.dm`, the refills (`RFW` words, `DMD.ofNSc`), the core write and the migration (S1aCSchedCtlB's + `cf_cpuMig.dmv`, the thread live by its `SC` word), `cfT.dmd`, the badge and sporadic words (`DMD.ofNSc`) is a + `DMR target target` step. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCSchedCtlB + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +/-- An SC word below 128 at an 8-aligned offset is aligned. -/ +theorem scw_al {c o : U64} {z : Nat} (hP : Placed c z) (hz : 7 ≤ z) (ho : o.val < 128) (h8 : o.val % 8 = 0) : + Aligned (wa c o) := by + have hv := sc_word_val hP hz ho + obtain ⟨h8', -, -⟩ := sc_lo hP hz + unfold Aligned; rw [hv]; omega + +/-- A write of an SC word off the liveness offsets (below 128) from a `BlkOK` state is a `DMD p` step. -/ +theorem scw_dmd {p c o v : U64} {s : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (hc : c ∈ H.scs) (ho : o.val < 128) (h8 : o.val % 8 = 0) + (hn : o.val ≠ 24 ∧ o.val ≠ 32 ∧ o.val ≠ 40 ∧ o.val ≠ 56 ∧ (o.val = 72 → c = p)) : + DMD st H Cs p s (L.wr s (wa c o) v) := by + obtain ⟨hP, hz⟩ := h.2.2.1.1.sc c hc + exact DMD.ofNSc h h0 Y VR ((writesIn_wr (scw_al hP hz ho h8)).mono fun b hb => by + rw [hb]; exact NScW.ofSCo hc hP hz ho hn) + +/-- A write of a node word (below 4288, 8-aligned, not `DEBUG_TCBS`, not the current core's `IDLE_THREAD`) from a +`BlkOK` state is a `DMD p` step. -/ +theorem nodew_dmd {p c o v : U64} {s : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) + (VR : ValidReplies st H s) (hc : c ∈ Cs) (ho : o.val < 4288) (h8 : o.val % 8 = 0) (h88 : o.val ≠ 88) + (hi : c = L.cpu s → o.val ≠ 8) : + DMD st H Cs p s (L.wr s (L.nodeAt s c o) v) := by + have q := h.1.choose_spec.choose_spec + exact DMD.ofNSc h h0 Y VR ((writesIn_wr (nodeAt_aligned (q.nodes c hc) ho h8)).mono fun b hb => + Or.inl ⟨c, hc, o, ho, h8, h88, hi, hb⟩) + +set_option maxHeartbeats 8000000 in +/-- **`configure_flags`' tail after the migration is a `DMD target` step** (module docstring). -/ +theorem cfT.dmd (hA : P0.ArchTotal ar) {s5 : S} (a3 : A) (i target cpu : U64) (h : BK s5) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s5) (VR : ValidReplies st H s5) (hi : i ∈ H.tcbs) (htS : target ∈ H.scs) + (hsc : L.mem s5 (scA i) = target) (ht0 : target ≠ 0#u64) (htA : target ∈ Ac) (hcpu : cpu ∈ Cs) + (hna : L.actionW s5 ≠ i) : + (do + let (s6, a4) ← + schedcontext.resume st ar s5 a3 target + let i1 ← st.cur_cpu s6 + let (s7, a5) ← + if cpu = i1 + then + do + let b1 ← sched.is_runnable st s6 i + let t ← + if b1 + then + do + let t1 ← sched.cur_thread st s6 + let b2 ← + core.cmp.PartialEq.ne.trait_default + obj.Tcb.Insts.CoreCmpPartialEqTcb i t1 + if b2 + then sched.possible_switch_to st s6 i + else ok s6 + else ok s6 + ok (t, a4) + else + do + let b1 ← sched.is_schedulable st s6 i + if b1 + then + let s8 ← sched.enqueue st s6 i + smp.remote_reschedule st ar s8 a4 cpu + else + let s8 ← sched.set_reprogram_on st s6 cpu + smp.remote_reschedule st ar s8 a4 cpu + let t ← sched.cur_thread st s7 + let b1 ← obj.Tcb.Insts.CoreCmpPartialEqTcb.eq i t + let t1 ← + if b1 + then sched.reschedule_required st s7 + else ok s7 + ok (t1, a5)) ⦃ r => (BK r.1) ∧ DMD st H Cs target s5 r.1 ⦄ := by + obtain ⟨⟨Q5, R5, h5⟩, hB5, hX5, hS5, hSg5⟩ := id h + have tc5 : L.mem s5 (scTcbA target) = i := by + have := (hX5.2.2.bound i hi (by rw [hsc]; exact ht0)).2.1; rwa [hsc] at this + have hres : target ≠ 0#u64 → L.mem s5 (scTcbA target) ≠ 0#u64 → + L.mem s5 (scTcbA target) ∈ H.tcbs ∧ OutsideObjs st H.tcbs Cs s5 (scCoreA target) ∧ + L.mem s5 (scCoreA target) ∈ Cs ∧ L.actionW s5 ≠ L.mem s5 (scTcbA target) := fun _ _ => by + rw [tc5] + exact ⟨hi, h5.omega _ ((objs_omega hX5.1 hSg5.sub).2 target htS).2.1, hX5.2.2.core target htS, hna⟩ + refine WP.spec_bind (WP.spec_and (schedcontext.resume.dmd hA target a3 target h h0 Y VR hres) + (schedcontext.resume.all hA s5 a3 target Q5 R5 h5 hB5 hX5 hSg5 hS5 hres)) ?_ + rintro ⟨s6, a4⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨⟨d6, BK6⟩, -, -, -, -, -, -, f6⟩ := hh + have sc6 : L.mem s6 (scA i) = target := (f6.sc i hi).trans hsc + step with LawfulStore.cur_cpu_spec as ⟨i1, ei1⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => (BK r.1) ∧ DMD st H Cs target s5 r.1) ?_ ?_ + · split + · step with sched.is_runnable.spec' as ⟨b1, hb1⟩ + refine WP.spec_bind (Pₘ := fun t => (BK t) ∧ DMD st H Cs target s5 t) ?_ fun t ht => (WP.spec_ok _).2 ht + split + · rename_i hb1t + step with sched.cur_thread.spec as ⟨t1, _⟩ + step with tcb_ne.blk as ⟨b2, _⟩ + split + · exact WP.spec_mono (sched.possible_switch_to.dmd target i BK6 h0 d6.sym d6.vr hi (hb1 hb1t) + (fun _ => by rw [sc6]; exact htA)) fun s7 ⟨d7, b7⟩ => ⟨b7, d6.trans d7⟩ + · exact (WP.spec_ok _).2 ⟨BK6, d6⟩ + · exact (WP.spec_ok _).2 ⟨BK6, d6⟩ + · step with sched.is_schedulable.spec' as ⟨b1, eb1⟩ + have RR : ∀ (s8 : S) (a8 : A), (BK s8) → DMD st H Cs target s5 s8 → + smp.remote_reschedule st ar s8 a8 cpu ⦃ r => (BK r.1) ∧ DMD st H Cs target s5 r.1 ⦄ := by + intro s8 a8 b8 d8 + refine WP.spec_mono (WP.spec_and (smp.remote_reschedule.blk a8 cpu b8) + (smp.remote_reschedule.ipi s8 a8 cpu)) fun r hr => ?_ + obtain ⟨s9, a9⟩ := r + simp only [WP.uncurry'_pair] at hr ⊢ + obtain ⟨⟨b9, -⟩, hw⟩ := hr + refine ⟨b9, d8.trans ?_⟩ + rcases hw with e | ⟨o, v, ho, e⟩ + · subst e; exact DMD.refl target b8 h0 d8.sym d8.vr + · subst e + have q8 := b8.1.choose_spec.choose_spec + exact nodew_dmd b8 h0 d8.sym d8.vr q8.cur (by rcases ho with e | e <;> omega) + (by rcases ho with e | e <;> omega) (by rcases ho with e | e <;> omega) + (fun _ => by rcases ho with e | e <;> omega) + split + · rename_i hb1 + obtain ⟨hrun, hbd, hrl, hrm⟩ := eb1 hb1 + obtain ⟨⟨Q6, R6, h6⟩, hB6, hX6, hS6, hSg6⟩ := id BK6 + have hA6 : L.mem s6 (scA i) ∈ Ac := (hS6.act _ (hX6.2.2.bound i hi hbd).1).2 hrm + refine WP.spec_bind (WP.spec_and (sched.enqueue.sch s6 i Q6 R6 h6 hB6 hSg6 hi (fun _ => hrl) + (fun _ => hrun) (fun _ => hbd) (fun _ => hA6)) (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) + (Z := H.scBits) (Es := ∅) s6 i h6 hi)) ?_ + rintro s8 ⟨⟨p8, -, -, -⟩, fw8⟩ + obtain ⟨b8, -, d8⟩ := qstep target BK6 h0 d6.sym d6.vr p8 (K8.FootB.foot fw8) + exact RR s8 a4 b8 (d6.trans d8) + · refine WP.spec_bind (WP.spec_and (sched.set_reprogram_on.blk cpu BK6 hcpu) + (sched.set_reprogram_on.spec s6 cpu)) fun s8 hh8 => ?_ + obtain ⟨⟨b8, -⟩, e8⟩ := hh8 + refine RR s8 a4 b8 (d6.trans ?_) + rw [e8] + exact nodew_dmd BK6 h0 d6.sym d6.vr hcpu (by rw [repr_val]; omega) (by rw [repr_val]) + (by rw [repr_val]; omega) (fun _ => by rw [repr_val]; omega) + rintro ⟨s7, a5⟩ h7 + try simp only [WP.uncurry'_pair] at h7 ⊢ + obtain ⟨BK7, d7⟩ := h7 + step with sched.cur_thread.spec as ⟨t, _⟩ + step with tcb_eq.blk as ⟨b1, _⟩ + refine WP.spec_bind (Pₘ := fun t1 => (BK t1) ∧ DMD st H Cs target s5 t1) ?_ fun t1 h => (WP.spec_ok _).2 h + split + · obtain ⟨⟨Q7, R7, q7⟩, hB7, -, -, hSg7⟩ := id BK7 + refine WP.spec_mono (WP.spec_and (sched.reschedule_required.sch s7 Q7 R7 q7 hB7 hSg7) + (K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s7 q7)) + fun s' hh => ?_ + obtain ⟨⟨p', -, -, -⟩, f'⟩ := hh + obtain ⟨b', -, d'⟩ := qstep target BK7 h0 d7.sym d7.vr p' f' + exact ⟨b', d7.trans d'⟩ + · exact (WP.spec_ok _).2 ⟨BK7, d7⟩ + +set_option maxHeartbeats 16000000 in +/-- **`configure_flags` is a `DMR target target` step** (module docstring). -/ +theorem schedcontext.configure_flags.dmr (hA : P0.ArchTotal ar) {s : S} (a : A) + (target cpu budget period max_refills badge flags : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (htS : target ∈ H.scs) (ht0 : target ≠ 0#u64) + (hcpu : cpu ∈ Cs) (h2 : sporadic.MIN_REFILLS.val ≤ max_refills.val) + (hm : max_refills.val ≤ absMax (H.scBits target)) (hna : ∀ y ∈ H.tcbs, L.actionW s ≠ y) + (hrv : ∀ p ∈ H.tcbs, L.mem s (runVcpuA p) ≠ 0#u64 → L.mem s (runVcpuA p) ∈ Vc) + (hVc : ∀ v ∈ Vc, VcWords H.omega H.frame v) : + schedcontext.configure_flags st ar s a target cpu budget period max_refills badge flags ⦃ r => + DMR st H Cs Vc target target s r.1 ⦄ := by + have hX := h.2.2.1 + have hO := hX.1 + obtain ⟨hP, hz⟩ := hO.sc target htS + have hTA : target ∈ insert target Ac := Set.mem_insert _ _ + unfold schedcontext.configure_flags + step with obj.Sc.tcb.spec as ⟨i, ei⟩ + step with obj.Tcb.is_null.spec as ⟨b, eb⟩ + have hiT : i ≠ 0#u64 → i ∈ H.tcbs := fun h0 => by rw [ei]; exact hX.2.2.yt.1 target htS (by rw [← ei]; exact h0) + have hsci : i ≠ 0#u64 → L.mem s (scA i) = target := fun h0 => by + rw [ei]; exact hX.2.2.tsc target htS ht0 (by rw [← ei]; exact h0) + have hbi : b = false → i ≠ 0#u64 := fun hf e => by rw [eb, e] at hf; simp at hf + -- the thread out of the queues + refine WP.spec_bind (Pₘ := fun r : S × A => (BK r.1) ∧ DMD st H Cs target s r.1 ∧ + (b = false → (L.mem r.1 (inqA i) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem r.1 (inqA i) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.mem r.1 (scA i) = target) ∧ (∀ y ∈ H.tcbs, L.actionW r.1 ≠ y) ∧ + (∀ y ∈ H.tcbs, L.mem r.1 (scA y) = target → y = i) ∧ + (b = false → L.mem r.1 (runVcpuA i) = L.mem s (runVcpuA i)) ∧ L.ksb r.1 = L.ksb s) ?_ ?_ + · split + · rename_i hb + exact (WP.spec_ok _).2 ⟨h, DMD.refl target h h0 Y VR, fun hf => absurd (hf.symm.trans hb) (by simp), hna, + fun y hy e => by + have := (hX.2.2.bound y hy (by rw [e]; exact ht0)).2.1 + rw [e, ← ei] at this; exact this.symm, fun hf => absurd (hf.symm.trans hb) (by simp), rfl⟩ + · rename_i hb + have hi0 : i ≠ 0#u64 := hbi (by simpa using hb) + exact WP.spec_mono (WP.spec_and (cfA hA a i target h (hiT hi0) hna) (cfA.dm hA a i target h h0 Y VR (hiT hi0))) + fun r ⟨⟨h1, q1, r1, a1, s1, _, rv1, kb1⟩, d1⟩ => + ⟨h1, d1, fun _ => ⟨q1, r1, s1.trans (hsci hi0)⟩, a1, fun y hy e => by + have b1 := (h1.2.2.1.2.2.bound y hy (by rw [e]; exact ht0)).2.1 + have b2 := (h1.2.2.1.2.2.bound i (hiT hi0) (by rw [s1.trans (hsci hi0)]; exact ht0)).2.1 + rw [e] at b1; rw [s1.trans (hsci hi0)] at b2; exact b1.symm.trans b2, fun _ => rv1, kb1⟩ + rintro ⟨s1, a1⟩ ⟨h1, d1, hq1, ha1, hu1, rv1, kb1⟩ + try simp only [WP.uncurry'_pair] + -- the refills + have keep : ∀ s2 : S, BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) s2 → + L.actionW s2 = L.actionW s1 → + (∀ y ∈ H.tcbs, L.mem s2 (scA y) = L.mem s1 (scA y) ∧ L.mem s2 (stA y) = L.mem s1 (stA y) ∧ + L.mem s2 (inqA y) = L.mem s1 (inqA y)) → + (b = false → (L.mem s2 (inqA i) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s2 (inqA i) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.mem s2 (scA i) = target) ∧ (∀ y ∈ H.tcbs, L.actionW s2 ≠ y) ∧ + (∀ y ∈ H.tcbs, L.mem s2 (scA y) = target → y = i) := fun s2 h2' ea fl => + ⟨fun hf => by + have hiT' := hiT (hbi hf) + obtain ⟨q, r, sc⟩ := hq1 hf + rw [(fl i hiT').2.2, (fl i hiT').1]; exact ⟨q, r, sc⟩, fun y hy => by rw [ea]; exact ha1 y hy, + fun y hy e => hu1 y hy (by rw [← (fl y hy).1]; exact e)⟩ + have RD : ∀ s2 : S, WritesIn st s1 s2 (RFW target (H.scBits target)) → DMD st H Cs target s1 s2 := fun s2 w => + DMD.ofNSc h1 h0 d1.sym d1.vr (w.mono fun b hb => by + obtain ⟨o1, o2, o3, o4⟩ := RFW.offs hP hz hb + exact NScW.ofSC htS hP hz (RFW.insc hP hz hb) ⟨o1, o2, o3, o4, fun _ => rfl⟩) + have RN : ∀ m bud per : U64, sporadic.MIN_REFILLS.val ≤ m.val → m.val ≤ absMax (H.scBits target) → + sporadic.refill_new st s1 target m bud per ⦃ s2 => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) s2 ∧ + DMD st H Cs target s1 s2 ∧ + (b = false → (L.mem s2 (inqA i) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s2 (inqA i) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.mem s2 (scA i) = target) ∧ (∀ y ∈ H.tcbs, L.actionW s2 ≠ y) ∧ + (∀ y ∈ H.tcbs, L.mem s2 (scA y) = target → y = i) ∧ WritesIn st s1 s2 (RFW target (H.scBits target)) ⦄ := + fun m bud per hm2 hmm => + WP.spec_mono (sporadic.refill_new.fr m bud per hP hz hm2 hmm) fun s2 ⟨wf, w⟩ => by + obtain ⟨h2', ea, -, -, fl⟩ := refill_blk h1 htS w wf + obtain ⟨k2, k3, k4⟩ := keep s2 h2' ea fl + exact ⟨h2', RD s2 w, k2, k3, k4, w⟩ + have RU : ∀ per bud m : U64, sporadic.MIN_REFILLS.val ≤ m.val → m.val ≤ absMax (H.scBits target) → + sporadic.refill_update st s1 target per bud m ⦃ s2 => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) s2 ∧ + DMD st H Cs target s1 s2 ∧ + (b = false → (L.mem s2 (inqA i) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s2 (inqA i) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.mem s2 (scA i) = target) ∧ (∀ y ∈ H.tcbs, L.actionW s2 ≠ y) ∧ + (∀ y ∈ H.tcbs, L.mem s2 (scA y) = target → y = i) ∧ WritesIn st s1 s2 (RFW target (H.scBits target)) ⦄ := + fun per bud m hm2 hmm => + WP.spec_mono (sporadic.refill_update.fr per bud m hP hz hm2 hmm) fun s2 ⟨wf, w⟩ => by + obtain ⟨h2', ea, -, -, fl⟩ := refill_blk h1 htS w wf + obtain ⟨k2, k3, k4⟩ := keep s2 h2' ea fl + exact ⟨h2', RD s2 w, k2, k3, k4, w⟩ + have hmin : sporadic.MIN_REFILLS.val ≤ absMax (H.scBits target) := h2.trans hm + refine WP.spec_bind (Pₘ := fun s2 => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) s2 ∧ + DMD st H Cs target s1 s2 ∧ + (b = false → (L.mem s2 (inqA i) &&& sched.Q_QUEUED) = 0#u64 ∧ (L.mem s2 (inqA i) &&& sched.Q_RELEASE) = 0#u64 ∧ + L.mem s2 (scA i) = target) ∧ (∀ y ∈ H.tcbs, L.actionW s2 ≠ y) ∧ + (∀ y ∈ H.tcbs, L.mem s2 (scA y) = target → y = i) ∧ WritesIn st s1 s2 (RFW target (H.scBits target))) ?_ ?_ + · split + · exact RN _ _ _ (le_refl _) hmin + · step with obj.Sc.cpu.spec as ⟨i1, _⟩ + split + · step with sporadic.sc_active.val as ⟨b1, _⟩ + split + · split + · exact RN _ _ _ h2 hm + · step with sched.is_runnable.spec' as ⟨b2, _⟩ + split + · exact RU _ _ _ h2 hm + · exact RN _ _ _ h2 hm + · exact RN _ _ _ h2 hm + · exact RN _ _ _ h2 hm + rintro s2 ⟨h2', d2, hq2, ha2, hu2, w2⟩ + have d12 : DMD st H Cs target s s2 := d1.trans d2 + -- the core + refine WP.spec_bind (obj.Sc.set_cpu.wr s2 target cpu) fun s3 e3 => ?_ + subst e3 + obtain ⟨h3, ea3, -, -, fl3⟩ := scword_blkW (d := i) h2' htS hTA (Or.inl (scCoreA_val hP hz)) + (fun _ => ⟨hcpu, fun t ht hne e => hne (hu2 t ht e)⟩) + -- the thread + refine WP.spec_bind (Pₘ := fun r : S × A => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) r.1 ∧ + DMR st H Cs Vc target target s r.1) ?_ ?_ + · split + · rename_i hb + have hi0 : i = 0#u64 := by rw [eb] at hb; simpa using hb + have BK3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits (insert target Ac) + (L.wr s2 (scCoreA target) cpu) := ⟨h3.1, h3.2.1, h3.2.2.1.1.x h3.2.2.1.2.1 (h3.2.2.1.2.2.full fun hiT0 _ => + ((h3.1.choose_spec.choose_spec.tcbs _ hiT0).ne0 (by rw [hi0]; simp)).elim), h3.2.2.2⟩ + exact (WP.spec_ok _).2 ⟨BK3, DMR.ofDMD (d12.trans (scw_dmd h2' h0 d12.sym d12.vr htS + (by simp [layout.sc.CORE]) (by simp [layout.sc.CORE]) + ⟨by simp [layout.sc.CORE], by simp [layout.sc.CORE], by simp [layout.sc.CORE], by simp [layout.sc.CORE], + fun e => absurd e (by simp [layout.sc.CORE])⟩))⟩ + · rename_i hb + have hbf : b = false := by simpa using hb + have hiT' := hiT (hbi hbf) + obtain ⟨q2, r2, sc2⟩ := hq2 hbf + have q1 := h1.1.choose_spec.choose_spec + have hfa : Aligned (runVcpuA i) := field_aligned (K := 3672#u64) (q1.tcbs i hiT') (by simp) (by simp) + have hrv2 : L.mem s2 (runVcpuA i) = L.mem s1 (runVcpuA i) := + w2.mem_eq hfa fun hh => out_ne_field (q1.omega _ (h1.2.2.1.1.scW target htS _ hfa (RFW.insc hP hz hh))) + hiT' (q1.tcbs i hiT') (K := 3672#u64) (by simp) rfl + have hrvi : L.mem s2 (runVcpuA i) ≠ 0#u64 → L.mem s2 (runVcpuA i) ∈ Vc := fun hne => by + rw [hrv2, rv1 hbf] at hne ⊢; exact hrv i hiT' hne + have hl2 : LiveQ st H Cs s2 i := LiveQ.tcb hiT' (Or.inr (Or.inl (by rw [sc2]; exact ht0))) + refine WP.spec_bind (cf_cpuMig.dmv hA a1 target i cpu h2' h0 d12.sym d12.vr hiT' htS hTA hcpu sc2 hu2 q2 r2 + hrvi hVc) ?_ + rintro ⟨s5, a3⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨BK5, ea5, sc5, -, dv⟩ := hh + exact WP.spec_mono (cfT.dmd hA a3 i target cpu BK5 h0 dv.sym dv.vr hiT' htS sc5 ht0 hTA hcpu + (by rw [ea5]; exact ha2 i hiT')) fun r ⟨b', d'⟩ => + ⟨b', (DMR.ofDMD d12).trans ((DMR.ofDMVlive dv hl2).trans (DMR.ofDMD d'))⟩ + rintro ⟨s4, a2⟩ ⟨h4, d4⟩ + try simp only [WP.uncurry'_pair] + -- the badge and the sporadic flag + refine WP.spec_bind (obj.Sc.set_badge.wr s4 target badge) fun s5 e5 => ?_ + subst e5 + have h5 := (scword_blk (v := badge) h4 htS hTA (Or.inr (Or.inl (by + rw [sc_word_val hP hz (o := layout.sc.BADGE) (by simp [layout.sc.BADGE])]; simp [layout.sc.BADGE]))) + (fun e => by + have := congrArg UScalar.val e + rw [sc_word_val hP hz (o := layout.sc.BADGE) (by simp [layout.sc.BADGE]), scCoreA_val hP hz] at this + simp [layout.sc.BADGE] at this)).1 + have d5 : DMD st H Cs target s4 (L.wr s4 (wa target layout.sc.BADGE) badge) := + scw_dmd h4 h0 d4.sym d4.vr htS (by simp [layout.sc.BADGE]) (by simp [layout.sc.BADGE]) + ⟨by simp [layout.sc.BADGE], by simp [layout.sc.BADGE], by simp [layout.sc.BADGE], by simp [layout.sc.BADGE], + fun e => absurd e (by simp [layout.sc.BADGE])⟩ + have spv : ∀ v : U64, DMR st H Cs Vc target target s + (L.wr (L.wr s4 (wa target layout.sc.BADGE) badge) (wa target layout.sc.SPORADIC) v) := fun v => + d4.trans (DMR.ofDMD (d5.trans (scw_dmd h5 h0 d5.sym d5.vr htS (by simp [layout.sc.SPORADIC]) + (by simp [layout.sc.SPORADIC]) + ⟨by simp [layout.sc.SPORADIC], by simp [layout.sc.SPORADIC], by simp [layout.sc.SPORADIC], + by simp [layout.sc.SPORADIC], fun e => absurd e (by simp [layout.sc.SPORADIC])⟩))) + simp only [lift, bind_ok] + split + · exact WP.spec_bind (obj.Sc.set_sporadic.wr _ target 1#u64) fun s6 e6 => (WP.spec_ok _).2 (by subst e6; exact spv _) + · exact WP.spec_bind (obj.Sc.set_sporadic.wr _ target 0#u64) fun s6 e6 => (WP.spec_ok _).2 (by subst e6; exact spv _) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCSchedCtlD.lean b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlD.lean new file mode 100644 index 000000000..473e7f04a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCSchedCtlD.lean @@ -0,0 +1,166 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a13), part 5): **SchedControl ConfigureFlags keeps every capability** +(the SchedControl arm of `decode_invocation`, `*_armS` shape). + +* **`schedcontext.decode_sched_control.armSAt`**: the caller's restart as MdbHiVsArm's `restart_caller.delRP` / + `armVsK` (at the decode's start: `Stalled.refl0`), then S1aCSchedCtlC's `configure_flags.dmr` (a `DMR target target` + step, `target` the extra slot's SC, named by that slot) with QueueScBindV's `configure_flags.blkV`; closed by + `SysL.dfMDR`, `ArmQIAt.ofSusW` / `ArmVsK.ofSusW` and `ArmQIAt.transZ` (as S1aCScBind's Thread case). +* **`syscall.decode_invocation.schedControl_armS`**: the same at `decode_invocation`. + +Named premises: [P] `P0.ArchTotal`. Case facts [J] (cap well-formedness; producer: the future cap-typing column): +`hcpu` (the invoked SchedControl cap's core is a core, `cpu ∈ Cs`) and `hsz` (a non-null extra slot's SchedContext +cap carries its object's size, `sz.val = H.scBits p`). Neither is implied by `SlotTy` / `CapTy` (`DelCapOK ∧ CapIn`). +-/ +import Fl4ProofsA64.P1.S1aCSchedCtlC + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option hygiene false in +/-- An error leaf with the state unchanged. -/ +local macro "errC" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 R0 + | (simp only [error.range, error.illegal, error.truncated, error.invalid_cap, bind_ok] + exact (WP.spec_ok _).2 R0)) + +set_option maxHeartbeats 8000000 in +/-- **SchedControl ConfigureFlags keeps every capability** (module docstring), at `decode_sched_control`. -/ +theorem schedcontext.decode_sched_control.armSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl cpu len buf : U64} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedControl cpu) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcpu : cpu ∈ Cs) + (hsz : ∀ x ∈ extra.val, x ≠ 0#u64 → ∀ p sz, capA st s x = .SchedContext p sz → sz.val = H.scBits p) : + schedcontext.decode_sched_control st ar s a lbl cpu len buf extra ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + have h0 := B.ly.h0 + have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + have R0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ OSKeep st OS s s := + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩ + unfold schedcontext.decode_sched_control + split + · errC + step with sched.cur_thread.spec as ⟨ct, ect⟩ + refine WP.spec_bind (schedcontext.extra_cap.slot D (WritesIn.refl _ _)) ?_ + rintro o ho + rcases o with _ | c + · errC + obtain ⟨x, hxm, hx0, hcx, hcO⟩ := ho c rfl + have hxO : x ∈ OS := P.ext x hxm hx0 + simp only + split + · errC + refine WP.spec_bind (P0.sporadic.max_period_us.p0 ar a hA) fun max_us _ => ?_ + step with sporadic.min_budget_us.spec as ⟨min_us, _⟩ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf 0#u64 hS) fun budget_us _ => ?_ + split + · errC + refine WP.spec_bind (hA.us_to_ticks a budget_us) fun budget _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf 1#u64 hS) fun period_us _ => ?_ + split + · errC + refine WP.spec_bind (hA.us_to_ticks a period_us) fun period _ => ?_ + refine WP.spec_bind (sporadic.min_budget.ok hA a) fun mb _ => ?_ + split + · errC + split + · errC + split + · errC + cases c + all_goals first | errC | skip + rename_i ptr sz + obtain ⟨hpS, hp0, -⟩ := hcO.2.2 ptr sz rfl + have hszv := hsz x hxm hx0 ptr sz hcx + dsimp only + obtain ⟨hP, hz⟩ := D.bxi.2.2.1.1.sc ptr hpS + have h64 := hP.lt64 + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf 2#u64 hS) fun er _ => ?_ + refine WP.spec_bind (sporadic.refill_absolute_max.val sz) fun mr hmr => ?_ + rw [hszv] at hmr + have hab : 2 ≤ absMax (H.scBits ptr) := by + unfold absMax; rw [if_neg (by omega)] + have : 2 ^ 7 ≤ 2 ^ H.scBits ptr := Nat.pow_le_pow_right (by norm_num) hz + omega + have hlt := absMax_lt (H.scBits ptr) + simp only [lift, bind_ok] + split + · errC + rename_i hle + have hsub : (core.num.U64.wrapping_sub mr sporadic.MIN_REFILLS).val = mr.val - 2 := by + simp [core.num.U64.wrapping_sub_val_eq, sporadic.MIN_REFILLS, U64.size_def, U64.numBits]; omega + have hle' : er.val ≤ mr.val - 2 := by have := hle; rw [gt_iff_val, hsub] at this; omega + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf 3#u64 hS) fun badge _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf 4#u64 hS) fun flags _ => ?_ + have ect' : ct = L.curW s := ect + subst ect' + -- the caller's restart + have erc : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by + unfold tcb.restart_caller; rw [cur_thread_ok, bind_ok] + have RQ := WP.spec_and + (tcb.restart_caller.delRP I D P B Y (Stalled.refl0 D) (DF.refl s) (DS.refl s) (VsKeep.refl s)) + (tcb.restart_caller.armVsK I D P B (Stalled.refl0 D) (DF.refl s) (DS.refl s)) + rw [erc] at RQ + refine WP.spec_bind RQ ?_ + rintro s1 ⟨⟨⟨RS1, R1⟩, Q1, Z1⟩, K1⟩ + try simp only [lift, bind_ok] + have hadd : (core.num.U64.wrapping_add er sporadic.MIN_REFILLS).val = er.val + 2 := by + simp [core.num.U64.wrapping_add_val_eq, sporadic.MIN_REFILLS, U64.size_def, U64.numBits]; omega + have hpo1 : ∀ p ∈ H.tcbs, L.mem s1 (runVcpuA p) ≠ 0#u64 → L.mem s1 (runVcpuA p) ∈ Vc := fun p hp hne => + (R1.jv.2.run p hp).resolve_left hne + -- `configure_flags` + refine WP.spec_bind (WP.spec_and + (schedcontext.configure_flags.dmr hA a ptr cpu budget period _ badge flags RS1.blk h0 RS1.sym RS1.sys.vr hpS + hp0 hcpu (by rw [hadd]; simp [sporadic.MIN_REFILLS]) (by rw [hadd]; omega) RS1.na hpo1 hW) + (schedcontext.configure_flags.blkV hA a ptr cpu budget period _ badge flags RS1.blk hpS hp0 hcpu + (by rw [hadd]; simp [sporadic.MIN_REFILLS]) (by rw [hadd]; omega) RS1.na + fun p hp hne => hW _ (hpo1 p hp hne))) ?_ + rintro ⟨s2, a2⟩ ⟨d2, b2⟩ + -- the SC is named by the extra slot + have named : ∀ k, H ptr = some k → ∃ y ∈ OS, NamesA (capA st s1 y) ptr k := fun k hk => by + obtain ⟨z, hz'⟩ := hpS + rw [hz'] at hk + cases hk + exact ⟨x, hxO, by rw [K1.2.capA hxO, hcx]; exact names_sc⟩ + have hS2 := SysL.dfMDR I.del.heap I.del.os I.del.vc (fun b hb => (R1.jv.2.w hb).2.1) RS1.blk I.del.sca + named named R1.sys d2 + have A2 := ArmQIAt.ofSusW I R1 hks P.core0 RS1.blk d2.w hS2 b2 + have vk := (ArmVsK.ofSusW I R1 hks P.core0 RS1.blk d2.w).2 + exact (WP.spec_ok _).2 ((fun h => ⟨h.1, h.2, ArmVsK.trans K1.1 K1.2 vk.1, OSKeep.trans' K1.2 vk.2⟩) + (ArmQIAt.transZ (ArmQIAt.ofDelR R1 Q1 Z1.1.toVs) Z1 A2 vk)) + +/-- **SchedControl ConfigureFlags keeps every capability** (the SchedControl arm of `decode_invocation`, +`*_armS` shape; case facts [J] `hcpu`, `hsz`). -/ +theorem syscall.decode_invocation.schedControl_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot cpu : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedControl cpu) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcpu : cpu ∈ Cs) + (hsz : ∀ x ∈ extra.val, x ≠ 0#u64 → ∀ p sz, capA st s x = .SchedContext p sz → sz.val = H.scBits p) + (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.SchedControl cpu) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono (schedcontext.decode_sched_control.armSAt hA I D P B Y hks hcpu hsz) fun r d => by + obtain ⟨_, s', a'⟩ := r + exact d + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCStall.lean b/proofs/Fl4ProofsA64/P1/S1aCStall.lean new file mode 100644 index 000000000..e31a8c9ab --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCStall.lean @@ -0,0 +1,126 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a2)): **unknown TCB and SchedContext labels**. + +Both decoders may stall a remote thread (`remote_tcb_stall`) before they reject the label, so the state is not +unchanged: the stall is a cap-keeping step (`stall_armS`). + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCKeep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- A TCB label `tcb::decode` knows none of. -/ +def UnknownTcbLbl (lbl : U64) : Prop := + lbl ≠ fl4_abi.label.TCBSetPACKeys ∧ + lbl ≠ fl4_abi.label.TCBSetHighVSpace ∧ + lbl ≠ fl4_abi.label.TCBSetEPTRoot ∧ + lbl ≠ fl4_abi.label.TCBReadRegisters ∧ + lbl ≠ fl4_abi.label.TCBWriteRegisters ∧ + lbl ≠ fl4_abi.label.TCBCopyRegisters ∧ + lbl ≠ fl4_abi.label.TCBSuspend ∧ + lbl ≠ fl4_abi.label.TCBResume ∧ + lbl ≠ fl4_abi.label.TCBConfigure ∧ + lbl ≠ fl4_abi.label.TCBSetPriority ∧ + lbl ≠ fl4_abi.label.TCBSetMCPriority ∧ + lbl ≠ fl4_abi.label.TCBSetSchedParams ∧ + lbl ≠ fl4_abi.label.TCBSetIPCBuffer ∧ + lbl ≠ fl4_abi.label.TCBSetSpace ∧ + lbl ≠ fl4_abi.label.TCBSetTimeoutEndpoint ∧ + lbl ≠ fl4_abi.label.TCBBindNotification ∧ + lbl ≠ fl4_abi.label.TCBUnbindNotification ∧ + lbl ≠ fl4_abi.label.TCBConfigureSingleStepping ∧ + lbl ≠ fl4_abi.label.TCBSetBreakpoint ∧ + lbl ≠ fl4_abi.label.TCBGetBreakpoint ∧ + lbl ≠ fl4_abi.label.TCBUnsetBreakpoint ∧ + lbl ≠ fl4_abi.label.TCBSetTLSBase ∧ + lbl ≠ fl4_abi.label.TCBSetFlags ∧ + lbl ≠ fl4_abi.label.TCBSetTimer ∧ + lbl ≠ fl4_abi.label.TCBReadFPU ∧ + lbl ≠ fl4_abi.label.TCBWriteFPU + +/-- A SchedContext label `schedcontext::decode` knows none of. -/ +def UnknownScLbl (lbl : U64) : Prop := + lbl ≠ fl4_abi.label.SchedContextConsumed ∧ + lbl ≠ fl4_abi.label.SchedContextBind ∧ + lbl ≠ fl4_abi.label.SchedContextUnbindObject ∧ + lbl ≠ fl4_abi.label.SchedContextUnbind ∧ + lbl ≠ fl4_abi.label.SchedContextYieldTo + +/-- **The stall as a cap-keeping step**, from the decode's state. -/ +theorem stall_armS {s s1 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 ∧ ArmVsK st H OS Vc s s1 ∧ OSKeep st OS s s1 := by + have hS := SysL.df P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1 + have hK := ArmVsK.ofDFI I D P B d1 + have a := ArmQIAt.ofStall I h1 d1 ds1 vk1 hS hK + exact ⟨a.1, a.2, hK, ds1.1⟩ + +/-- **An unknown TCB label** keeps every capability. -/ +theorem syscall.decode_invocation.unknownTcb_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : UnknownTcbLbl lbl) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + refine syscall.decode_invocation.tcbG + (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x) + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩ a len blk call don fp buf + fun lbl' call' e => ?_ + subst e + obtain ⟨l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, l25⟩ := hl + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + have r := stall_armS I D P B Y h1 d1 ds1 vk1 + simp only [uncurry_apply_pair, l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, l25, ↓reduceIte, error.illegal, bind_ok] + exact (WP.spec_ok _).2 r + +/-- **An unknown SchedContext label** keeps every capability. -/ +theorem syscall.decode_invocation.unknownSc_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p b : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedContext p b) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : UnknownScLbl lbl) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.SchedContext p b) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + have r0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ OSKeep st OS s s := + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩ + obtain ⟨k0, k1, k2, k3, k4⟩ := hl + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + cases fp + swap + · simpa [WP.spec_ok] using r0 + simp only [Bool.false_eq_true, ↓reduceIte] + unfold schedcontext.decode + step with obj.Sc.tcb.spec as ⟨i, ei⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => + ArmQIAt st H Cs OS Vc ia ie s r.1 ∧ TabKeepOrZero st s r.1 ∧ ArmVsK st H OS Vc s r.1 ∧ + OSKeep st OS s r.1) ?_ ?_ + · split + · refine WP.spec_mono (smp.remote_tcb_stall.delS hA D I a i) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + exact stall_armS I D P B Y h1 d1 ds1 vk1 + · exact (WP.spec_ok _).2 r0 + rintro ⟨s1, a1⟩ r + simp only [uncurry_apply_pair, cur_thread_ok, bind_ok, k0, k1, k2, k3, k4, ↓reduceIte, error.illegal] + exact (WP.spec_ok _).2 r + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCStepD.lean b/proofs/Fl4ProofsA64/P1/S1aCStepD.lean new file mode 100644 index 000000000..64ac76ac3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCStepD.lean @@ -0,0 +1,48 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c0'): **the S1a step post of a non-decode step built from `DMD` steps**. + +* **`RpW.keepPost`**: S1aCReplyW's bundle `RpW s0 s` with every `OS` slot kept gives the `*_armSAt` shape + `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` (MdbXferQ's `ArmQIAt.ofXC`), no `DecPre` needed. +* **`S1aKeep.ofDMD`**: one `DMD p` step from a `BlkOK` state with `SysL ∧ SymL` (`p` named or in the idle area) gives + that shape. +* **`S1aStepR2K.ofRpW`**: the S1a step post at the end of such a walk (S1aCAll's `S1aStepR2K.ofKeep'`). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aBootDel1 +import Fl4ProofsA64.P1.S1aCAll + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + +/-- **A kept-slot walk gives the `*_armSAt` shape** (module docstring). -/ +theorem RpW.keepPost {s0 s : S} (R : RpW st H Cs OS Vc ia ie Ac s0 s) (k : OSKeep st OS s0 s) : + ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s ∧ ArmVsK st H OS Vc s0 s ∧ OSKeep st OS s0 s := + (fun h => ⟨h.1, h.2, R.xv.1, k⟩) (ArmQIAt.ofXC ⟨R.sys, R.sym⟩ ⟨Ac, R.blk⟩ R.xc R.xv.1.toVs) + +/-- **One `DMD p` step gives the `*_armSAt` shape** (module docstring). -/ +theorem S1aKeep.ofDMD {Vc' Ub Pt : Set U64} {p : U64} {s s' : S} (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) + (hp : ∀ k, H p = some k → ¬ (ia ≤ p.val ∧ p.val < ie) → ∃ x ∈ OS, NamesA (capA st s x) p k) + (d : DMD st H Cs p s s') (b : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') : + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := + have R := (RpW.start (Vc := Vc) B Y h).dmdK hH hO hSA hc0 hvr hks hp d b + R.1.keepPost R.2 + +/-- **The S1a step post at the end of a kept-slot walk.** -/ +theorem S1aStepR2K.ofRpW {s q : S} (R : RpW st H Cs OS Vc ia ie Ac s q) (k : OSKeep st OS s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt) (fu : FrUb st Uq OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) + (Df : DevFrAl st OS s) (R2 : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n q := + S1aStepR2K.ofKeep' (R.keepPost k) vr fu vcc C Kc Df R2 sep KC + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCTime.lean b/proofs/Fl4ProofsA64/P1/S1aCTime.lean new file mode 100644 index 000000000..99c7d7832 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCTime.lean @@ -0,0 +1,161 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c1 part 1): **`update_timestamp` keeps every capability**. + +`update_timestamp` writes the current core's `CUR_TIME` and `CONSUMED` node words and the state block's `WORK_UNITS` +word (QueueKeeps's `PPW`). The node words are `K8.KW` words; the `WORK_UNITS` word is an `Ω \ Sg` word of the state +block (QueueKeeps's `ks_work_units`), off every `OS` slot (`WuApart`), and a `DfW` word at `Ko = {40}`. + +* **`sched.update_timestamp.keepS`**: `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` and `BlkOK` at the end + (`SysL` by MdbXferL's `SysL.dfN`, `OSKeep` by `DFB.oskX`, `TabKeep.ofW` / `ArmVsK.ofFoot` over `DfW {40}`). +* **`sched.update_timestamp.s1a`**: the S1a step post (S1aCAll's `S1aStepR2K.ofKeep'`). + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCStepD + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add + +set_option maxHeartbeats 4000000 in +/-- **`update_timestamp` keeps every capability** (module docstring). -/ +theorem sched.update_timestamp.keepS (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s : S} (a : A) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') (hW : WuApart OS (L.ksb s)) : + sched.update_timestamp st ar s a ⦃ s' _ => + (ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s') ∧ + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ⦄ := by + obtain ⟨Q, R, q⟩ := id h.1 + have C := LvC.of_blk h + obtain ⟨-, wΩ, wnS⟩ := ks_work_units h + have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw hc0 + have e40 : layout.ks.WORK_UNITS.val = 40 := by simp [layout.ks.WORK_UNITS] + refine WP.spec_mono (WP.spec_and (sched.update_timestamp.w hA s a (q.nodes _ q.cur)) + (sched.update_timestamp.bxc hA s a (BlkOK.bxi h))) ?_ + rintro ⟨s', a'⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨w, ⟨hb, -, -⟩, -, -⟩ := hh + have b' := hb.blk + have Dw : ∀ b, PPW st s b → DfW st H.tcbs Cs H.frame H.scBits {40} s b := by + rintro b (rfl | rfl | rfl) + · exact Or.inr ⟨layout.ks.WORK_UNITS, by rw [e40]; rfl, by rw [e40]; omega, by rw [e40], rfl⟩ + · unfold LawfulStore.nodeA + exact Or.inl (Or.inr (Or.inl ⟨L.cpu s, q.cur, layout.node.CUR_TIME, by simp [layout.node.CUR_TIME], + by simp [layout.node.CUR_TIME], rfl⟩)) + · unfold LawfulStore.nodeA + exact Or.inl (Or.inr (Or.inl ⟨L.cpu s, q.cur, layout.node.CONSUMED, by simp [layout.node.CONSUMED], + by simp [layout.node.CONSUMED], rfl⟩)) + have w' : WritesIn st s s' (DfW st H.tcbs Cs H.frame H.scBits {40} s) := w.mono Dw + have nA : ∀ b, DfW st H.tcbs Cs H.frame H.scBits {40} s b → ¬ AsW (L.ksb s) b := + fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd + have t : TabKeep st s s' := TabKeep.ofW hvr w' nA + have v : ArmVsK st H OS Vc s s' := ArmVsK.ofFoot hH q w' (fun b hd => Or.inl hd) nA + have f : LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.none s s' := LvF.ofCwN C w fun b _ hb' => by + rcases hb' with rfl | rfl | rfl + · exact Or.inl (Or.inr ⟨wΩ, wnS⟩) + · unfold LawfulStore.nodeA + exact Or.inr ⟨_, q.cur, layout.node.CUR_TIME, by simp [layout.node.CUR_TIME], by simp [layout.node.CUR_TIME], + by simp [layout.node.CUR_TIME], s, rfl, rfl⟩ + · unfold LawfulStore.nodeA + exact Or.inr ⟨_, q.cur, layout.node.CONSUMED, by simp [layout.node.CONSUMED], by simp [layout.node.CONSUMED], + by simp [layout.node.CONSUMED], s, rfl, rfl⟩ + have d : DFB st H Cs (L.curW s) ∅ (fun b => b = wa (L.ksb s) layout.ks.WORK_UNITS) s s' := + ⟨w.mono fun b hb => by + rcases hb with rfl | rfl | rfl + · exact Or.inr rfl + · unfold LawfulStore.nodeA + exact Or.inl (Or.inl (Or.inr (Or.inl ⟨L.cpu s, q.cur, layout.node.CUR_TIME, by simp [layout.node.CUR_TIME], + by simp [layout.node.CUR_TIME], rfl⟩))) + · unfold LawfulStore.nodeA + exact Or.inl (Or.inl (Or.inr (Or.inl ⟨L.cpu s, q.cur, layout.node.CONSUMED, by simp [layout.node.CONSUMED], + by simp [layout.node.CONSUMED], rfl⟩))), + f.mono (LvF.none_le _)⟩ + have hBo : ∀ x ∈ OS, ∀ b, x.val ≤ b.val → b.val < x.val + 32 → ¬ (b = wa (L.ksb s) layout.ks.WORK_UNITS) := + fun x hx b h1 h2 e => hW x hx ⟨e ▸ h1, e ▸ h2⟩ + have k : OSKeep st OS s s' := DFB.oskX (Xq := ∅) hO h hBo d + obtain ⟨S', Y'⟩ := SysL.dfN hH hO h (fun b (e : b = wa (L.ksb s) layout.ks.WORK_UNITS) => by rw [e]; exact ⟨wΩ, wnS⟩) hBo B Y d f + have A2 := ArmQIAt.ofXC (Vc := Vc) (ia := ia) (ie := ie) ⟨S', Y'⟩ ⟨Ac, b'⟩ (XC.keep k t) v.toVs + exact ⟨⟨A2.1, A2.2, v, k⟩, b'⟩ + +/-- **`update_timestamp` keeps the S1a step post** (module docstring). -/ +theorem sched.update_timestamp.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} + (a : A) (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hc0 : 0#u64 ∈ Cs) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.update_timestamp st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.update_timestamp.keepS (Vc := Vc) hA a B Y h I.del.heap I.del.os hc0 I.del.vr I.del.wu) + fun r d => by + obtain ⟨_, _⟩ := r + exact S1aStepR2K.ofKeep' d.1 I.del.vr I.fu I.vcc C Kc Df R sep KC + +set_option maxHeartbeats 4000000 in +/-- **`commit_time` keeps every capability**: its ring, `CONSUMED` and node words are a `DMD` step (S1aCNScW's +`DMD.ofNSc`, as S1aCSchedCtlA's `cfA.dm`), closed by S1aCStepD's `S1aKeep.ofDMD`. -/ +theorem sched.commit_time.keepS (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s : S} (a : A) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hc0 : 0#u64 ∈ Cs) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') (hks : HeapKsOff H (L.ksb s)) : + sched.commit_time st ar s a ⦃ s' => + (ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s') ∧ + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ⦄ := by + have h0 := B.ly.h0 + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hO' := hX.1 + have hc : L.cscW s ∈ H.scs := hX.2.2.cur + have hN' := q.nodes _ q.cur + obtain ⟨hP, hz⟩ := hO'.sc _ hc + have cnv : layout.node.CONSUMED.val = 40 := by simp [layout.node.CONSUMED] + have aC : Aligned (L.nodeA s layout.node.CONSUMED) := nodeAt_aligned hN' (by rw [cnv]; omega) (by rw [cnv]) + have oC : Outside (L.nodeA s layout.node.CONSUMED) (L.cscW s) (H.scBits (L.cscW s)) := + node_out_place (fun b hb hin => hO'.scW _ hc b hb hin) q.omega q.cur hN' (by rw [cnv]; omega) (by rw [cnv]) + refine WP.spec_mono (WP.spec_and (sched.commit_time.fr hA a (hS.all _ hc).1 rfl aC oC) + (sched.commit_time.blk hA a h)) fun s' ⟨hw, hb⟩ => ⟨?_, hb.1⟩ + refine S1aKeep.ofDMD (p := 0#u64) B Y h hH hO hSA hc0 hvr hks (fun k hk => by rw [h0] at hk; cases hk) + (DMD.ofNSc h h0 Y B.vr (hw.1.mono fun b hb => ?_)) hb.1 + rcases hb with (hr | e) | e + · have hv80 := hr.1 + exact NScW.ofSC hc hP hz hr.inSC ⟨by omega, by omega, by omega, by omega, fun e => absurd e (by omega)⟩ + · rw [e] + exact NScW.ofSCo hc hP hz (by simp [layout.sc.CONSUMED]) + ⟨by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], + by simp [layout.sc.CONSUMED], fun e => absurd e (by simp [layout.sc.CONSUMED])⟩ + · exact Or.inl ⟨L.cpu s, q.cur, layout.node.CONSUMED, by rw [cnv]; omega, by rw [cnv], by rw [cnv]; omega, + fun _ => by rw [cnv]; omega, e⟩ + +/-- **`commit_time` keeps the S1a step post.** -/ +theorem sched.commit_time.s1a (hA : P0.ArchTotal ar) {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} + (a : A) (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s)) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.commit_time st ar s a ⦃ s' => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.commit_time.keepS (Vc := Vc) hA a B Y h I.del.heap I.del.os I.del.sca hc0 I.del.vr hks) + fun _ d => S1aStepR2K.ofKeep' d.1 I.del.vr I.fu I.vcc C Kc Df R sep KC + +/-- **`postpone` of a thread's SC keeps the S1a step post** (S1aCReplyTl's `sched.postpone.dmd`; per-state facts: +the thread's `RTail`, runnable, with an SC). -/ +theorem sched.postpone.s1a {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} {i : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hc0 : 0#u64 ∈ Cs) + (hks : HeapKsOff H (L.ksb s)) (r : RTail st H.tcbs Ac s i) (hrun : Runnable (L.mem s (stA i))) + (hi0 : L.mem s (scA i) ≠ 0#u64) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.postpone st s (L.mem s (scA i)) ⦃ s' => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := + WP.spec_mono (sched.postpone.dmd 0#u64 i h B.ly.h0 Y B.vr r hrun hi0) fun _ hh => + S1aStepR2K.ofKeep' (S1aKeep.ofDMD (Vc := Vc) B Y h I.del.heap I.del.os I.del.sca hc0 I.del.vr hks + (fun k hk => by rw [B.ly.h0] at hk; cases hk) hh.1 hh.2) I.del.vr I.fu I.vcc C Kc Df R sep KC + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCTimer.lean b/proofs/Fl4ProofsA64/P1/S1aCTimer.lean new file mode 100644 index 000000000..55505a877 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCTimer.lean @@ -0,0 +1,195 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a5)): **TCB SetTimer keeps every capability** (timer.rs `insert`). + +* **`timer.insert.nz`**: no other thread's deadline becomes nonzero. +* **`timer.insert.dmT`**: a `DM t` step (only `t` may become live). +* **`syscall.decode_invocation.setTimer_armS`**: the stall, the caller's restart, the insertion. + +Named premises: [P] `P0.ArchTotal`. +-/ +import Fl4ProofsA64.P1.S1aCDm2 +import Fl4ProofsA64.P1.MdbArmDm +import Fl4ProofsA64.P1.TimerRBRmv +import Fl4ProofsA64.P1.TimerRBInsF + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add + +/-- **No other thread's deadline becomes nonzero** under `timer::insert`. -/ +theorem timer.insert.nz {s : S} (t d bd : U64) {T Cs : Set U64} (hT : TcbPlaced T) (ht : t ∈ T) + (hR : TimerRB st T Cs s) (hN : ∀ c ∈ Cs, NodePlaced st T s c) (hc : L.cpu s ∈ Cs) : + timer.insert st s t d bd ⦃ s' => ∀ y ∈ T, y ≠ t → NzW st s s' (tdA y) ⦄ := by + have hrem : timer.remove st s t ⦃ s1 => (∀ y ∈ T, y ≠ t → NzW st s s1 (tdA y)) ∧ TimerRB st T Cs s1 ∧ + L.mem s1 (tdA t) = 0#u64 ∧ (∀ c ∈ Cs, NodePlaced st T s1 c) ∧ L.cpu s1 = L.cpu s ⦄ := by + refine WP.spec_mono (timer.remove.rb s t hT ht hR hN) ?_ + rintro s1 ⟨hR1, htd, hN1, h | ⟨c, hcC, W, ct, htW, wi⟩⟩ + · obtain ⟨-, e⟩ := h + subst e + exact ⟨fun _ _ _ h => h, hR1, htd, hN1, rfl⟩ + · refine ⟨fun y hy _ => ?_, hR1, htd, hN1, wi.2.1⟩ + by_cases hX : y ∈ W.keys + · exact NzW.old (ct.armed y hX) + · have k := KeepOut.of_wi hT (hN c hcC) wi + exact NzW.eq (k.fld y hy hX 3528#u64 (by simp) (by simp)) + refine WP.spec_mono (timer.insert.coreW s t d bd (P := fun s1 => (∀ y ∈ T, y ≠ t → NzW st s s1 (tdA y)) ∧ + TimerRB st T Cs s1 ∧ L.mem s1 (tdA t) = 0#u64 ∧ (∀ c ∈ Cs, NodePlaced st T s1 c) ∧ L.cpu s1 = L.cpu s) + hT ht hrem fun s1 h1 => ?_) ?_ + · obtain ⟨-, hR1, htd, hN1, ec⟩ := h1 + have hc1 : L.cpu s1 ∈ Cs := ec ▸ hc + obtain ⟨t0, ct⟩ := hR1.tree _ hc1 + exact ⟨hN1 _ hc1, t0, ct, fun hm => ct.armed t hm htd⟩ + rintro s' (⟨-, h⟩ | ⟨-, s1, ctx, W, h1, cto, -, -, wi⟩) + · exact h.1 + obtain ⟨nz, -, -, hN1, ec⟩ := h1 + have hc1 : L.cpu s1 ∈ Cs := ec ▸ hc + have k := KeepOut.of_wi hT (hN1 _ hc1) wi + intro y hy hyt h + by_cases hX : InsX ctx t y + · exact nz y hy hyt (hX.elim (fun e => absurd e hyt) fun ho => cto.armed y ho) + · have e : L.mem s' (tdA y) = L.mem s1 (tdA y) := k.fld y hy hX 3528#u64 (by simp) (by simp) + exact nz y hy hyt (by rwa [e] at h) + +/-- The deadline words. -/ +@[reducible] def DlX : LvX := ⟨fun _ k => k = 3528, fun _ _ => False, fun _ _ => False, fun _ _ => False⟩ + +set_option maxHeartbeats 1000000 in +/-- **`timer::insert t`** is a `DM t` step. -/ +theorem timer.insert.dmT {s : S} (t d bd : U64) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (ht : t ∈ H.tcbs) + (h0 : H 0#u64 = none) (VR : ValidReplies st H s) (Y : SymL st H Cs s) : + timer.insert st s t d bd ⦃ s' => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' ∧ DM st H Cs t s s' ⦄ := by + have C := LvC.of_blk h + have hT := C.tcb + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + refine WP.spec_mono (WP.spec_and (WP.spec_and (timer.insert.blk s t d bd h ht) + (timer.insert.footR s t d bd h.tinv ht)) (timer.insert.nz t d bd hT ht (TInv.rb h) C.nodes C.cur)) ?_ + rintro s' ⟨⟨h', -, f, w, -⟩, nz⟩ + have rp : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have kO : ∀ b ∈ H.omega, L.mem s' b = L.mem s b := fun b hb => w.2.2 b (C.om b hb).1 (by + rintro ((⟨y, hy, K, -, hK, e⟩ | ⟨c, hc, o, ho, e⟩) | e) + · exact out_ne_field (C.om b hb) hy (C.tcb y hy) (by omega) (congrArg UScalar.val e).symm + · exact out_ne_node (C.om b hb) hc (C.nodes c hc) (by omega) (congrArg UScalar.val e).symm + · exact out_ne_node (C.om b hb) C.cur (C.nodes _ C.cur) (by rw [rp]; omega) (congrArg UScalar.val e).symm) + have idl : L.idleW s' = L.idleW s := by + unfold LawfulStore.idleW + rw [w.2.1, nodeAt_of_ksb w.1] + have hN := C.nodes _ C.cur + have hi : layout.node.IDLE_THREAD.val < 4288 := by rw [idle8]; omega + refine w.2.2 _ (nodeAt_aligned hN hi (by rw [idle8])) ?_ + rintro ((⟨y, hy, K, -, hK, e⟩ | ⟨c, hc, o, ho, e⟩) | e) + · exact node_ne_field hN hi hy (hT y hy) (by omega) e + · exact node_ne_node hN (C.nodes c hc) hi (by omega) (fun _ => by rw [idle8]; omega) (congrArg UScalar.val e) + · exact node_ne_node hN hN hi (by rw [rp]; omega) (fun _ => by rw [idle8, rp]; omega) (congrArg UScalar.val e) + have g : LvF st H.tcbs Cs H.replies H.scs H.ntfns DlX s s' := by + refine ⟨f.1, f.2.1, idl, C.foot_hd f, fun y hy K hK hx => ?_, fun c hc o hO _ => kO _ (C.scO hc hO.lt.1 hO.lt.2), + fun n hn o hO _ => kO _ (C.ntO hn hO), fun r hr o hO _ => kO _ (C.rpO hr hO.lt.1 hO.lt.2)⟩ + have hx' : K.val ≠ 3528 := hx + have hK' := hK.lt + refine w.2.2 _ (C.al_t hy hK) ?_ + rintro ((⟨y', hy', K', h1, h2, e⟩ | ⟨c, hc, o, ho, e⟩) | e) + · refine field_ne (hT y hy) (hT y' hy') hK'.1 (by omega) (fun _ h => ?_) e + unfold LvO at hK; omega + · exact node_ne_field (C.nodes c hc) (by omega) hy (hT y hy) hK'.1 e.symm + · exact node_ne_field (C.nodes _ C.cur) (by rw [rp]; omega) hy (hT y hy) hK'.1 e.symm + have V' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g + (fun c k hk => hk.elim) (fun r k hk => hk.elim) + (BorK.of_lv g fun y k hk => by have e : k = 3528 := hk; subst e; decide) + have Y' : YieldS st H.tcbs H.scs s' := Y.yld.lv hX.2.2.yt g + (fun y k hk => by have e : k = 3528 := hk; subst e; decide) (fun c k hk => hk.elim) + have D' := Y.dbg.lv hz g fun y k hk => by + have e : k = 3528 := hk + subst e; decide + have Ys : SymL st H Cs s' := ⟨D', Y'⟩ + have fl : ∀ y ∈ H.tcbs, ∀ o : U64, LvO o.val → o.val ≠ 3528 → L.mem s' (wa y o) = L.mem s (wa y o) := + fun y hy o hO hne => g.t y hy o hO hne + have f0 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s s' := by + refine WritesIn.mono w fun b hb => ?_ + rcases hb with (⟨y, hy, K, h1, h2, e⟩ | ⟨c, hc, o, ho, e⟩) | e + · exact Or.inl ⟨y, hy, K, by omega, by omega, by omega, ⟨by omega, by omega, by omega, by omega⟩, e⟩ + · exact Or.inr (Or.inl ⟨c, hc, o, by omega, by intro h; rw [h] at ho; simp at ho, e⟩) + · exact Or.inr (Or.inl ⟨_, C.cur, _, by rw [rp]; omega, by intro h; rw [h] at rp; simp at rp, e⟩) + have M := EpM.ofK (ep_kept_kw h f0) + have fk : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' := + WritesIn.mono f0 fun _ hb => kw8_es hb + have nzx : NzX st H Cs (fun q => q = t) s s' := by + refine ⟨fun y hy _ hs => ?_, fun y hy hne => ⟨NzW.eq (fl y hy 3464#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3368#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3472#u64 (by unfold LvO; simp) (by simp)), nz y hy hne, + NzW.eq (fl y hy 3576#u64 (by unfold LvO; simp) (by simp)), + NzW.eq (fl y hy 3584#u64 (by unfold LvO; simp) (by simp))⟩, + fun c hc _ => ⟨NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.TCB]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.REPLY]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.NTFN]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.YIELD_FROM]) (fun h => h)), + NzW.eq (g.c c hc _ (by unfold LvSO; simp [layout.sc.REFILL_MAX]) (fun h => h))⟩, + fun e he _ => M.1 e he, fun n hn _ => M.2 n hn, + fun n hn _ => ⟨NzW.eq (g.n n hn _ (by unfold LvNO; simp [layout.ntfn.BOUND_TCB]) (fun h => h)), + NzW.eq (g.n n hn _ (by unfold LvNO; simp [layout.ntfn.SC]) (fun h => h))⟩, + fun r hr _ => NzW.eq (g.r r hr _ (by unfold LvRO; simp [layout.reply.TCB]) (fun h => h)), + fun c hc q _ _ e => Or.inr ⟨c, hc, (g.hd c hc).symm.trans e⟩⟩ + rw [stA_eq] at hs ⊢ + rwa [fl y hy 3328#u64 (by unfold LvO; simp) (by simp)] at hs + refine ⟨h', fk, fk, LvM.ofNzX nzx Y Ys hz h0, idl, ?_, V', Ys⟩ + rw [idl] + exact fl _ hI 3464#u64 (by unfold LvO; simp) (by simp) + +/-- **TCB SetTimer** keeps every capability. -/ +theorem syscall.decode_invocation.setTimer_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetTimer) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + have hS : P0.StoreTotal st := L.total + have ht : t ∈ H.tcbs := D.cap.2.1 t rfl + have key : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + DmPost st H Cs OS ia ie Ac s r.2.1 ⦄ := by + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.stS hA a t D.bxi) ?_ + rintro ⟨s1, a1⟩ ⟨h1, d1⟩ + try simp only [uncurry_apply_pair] + iterate 23 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ + · exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBBindNotification, fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, fl4_abi.label.TCBGetBreakpoint, fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, fl4_abi.label.TCBWriteFPU, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + have E1 : DmPost st H Cs OS ia ie Ac s s1 := + DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + h1.bxi.blk (DmW.ofDF d1) + refine spec_ite (fun _ => ?_) fun _ => ?_ + · simp only [error.truncated, bind_ok] + exact (WP.spec_ok _).2 E1 + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun deadline _ => ?_ + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun badge _ => ?_ + refine WP.spec_bind (tcb.restart_caller.restartRK D P B Y h1 d1) fun s2 ⟨R, d2⟩ => ?_ + refine WP.spec_bind (timer.insert.dmT t deadline badge R.blk ht B.ly.h0 R.sys.vr R.sym) fun s3 ⟨h3, f3, d3⟩ => ?_ + exact (WP.spec_ok _).2 (DmPost.mk' (SysL.dfM R.pl R.blk.bxi hSA (R.namedT hcap ht) R.sys d3) h3 + (DmW.trans (DmW.ofDF d2) (WritesIn.mono f3 fun _ hb => Or.inr hb))) + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono key fun r d => by + obtain ⟨_, s', a'⟩ := r + have x := ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk + exact ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCXferTy.lean b/proofs/Fl4ProofsA64/P1/S1aCXferTy.lean new file mode 100644 index 000000000..e2b8eec3b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCXferTy.lean @@ -0,0 +1,169 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a15), part 3; Architect ruling 03:42Z): **`SlotTy` across a transfer** +(reused by stage 2's c4). + +* **`objects.derive_cap.ty`**: `derive_cap` returns its argument, `Null`, `Domain` or a frame cap, at any state. +* **`capTy_triv`**: `Null`, `Domain`, frame and untyped caps are `CapTy` (no clause reads them). +* **`SlotOK.capTy`** / **`SlotOK.ofCap`**: `SlotOK`'s cap clause is `CapTy` of the slot's `capA`. +* **`SlotTy.ofXfer`**: `SlotTy` from a transfer's slot fact (MdbXferQ's `XferSlots`): a kept slot keeps its cap; the + destination holds a derived copy (`derive_cap.ty`); the source is the same or an untyped with a moved index + (`FullA`); the link words of every slot from the end state's MDB (`MdbS.lnk`). +* **`ipc.do_ipc_transfer.xjT`**: MdbXferQ's `do_ipc_transfer.xjS` with `SlotTy` at its end. + +Named premises: [P] `P0.ArchTotal` (`xjT`). No new one. +-/ +import Fl4ProofsA64.P1.S1aCSchedCtlD +import Fl4ProofsA64.P1.MdbSendQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +local notation "wa" => core.num.U64.wrapping_add + +set_option hygiene false in +/-- An `Ok` result of `derive_cap`. -/ +local macro "ty_ok" : tactic => `(tactic| ( + refine (WP.spec_ok _).2 fun nc h => ?_ + cases h + simp [isFrA])) + +set_option maxHeartbeats 1000000 in +/-- **`derive_cap` returns its argument, `Null`, `Domain` or a frame cap** (any state). -/ +theorem objects.derive_cap.ty (s : S) (slot : U64) (c : capability.Cap) : + objects.derive_cap st s slot c ⦃ r => ∀ nc, r = .Ok nc → + nc = c ∨ nc = .Null ∨ nc = .Domain ∨ isFrA nc = true ⦄ := by + have hS : P0.StoreTotal st := L.total + cases c + case Untyped p b i d => + simp only [objects.derive_cap] + refine WP.spec_bind (P0.cdt.ensure_no_children.p0 st s slot hS) fun r _ => ?_ + rcases r with _ | e + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + ty_ok + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + first + | exact (WP.spec_ok _).2 fun nc h => (by cases h) + | (simp only [WP.spec_ok]; intro nc h; cases h) + case PageTable p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + case PageDirectory p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + case Pdpt p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + case Pml4 p m a => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + case Ept p l m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + case HighVSpace p m a => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + ty_ok + all_goals (simp only [objects.derive_cap]; ty_ok) + +/-- **`Null`, `Domain`, frame and untyped caps are `CapTy`.** -/ +theorem capTy_triv {T Ω Sg Rp Nt : Set U64} {c : capability.Cap} + (h : c = .Null ∨ c = .Domain ∨ isFrA c = true ∨ isUtA c = true) : CapTy T Ω Sg H Rp Nt OS c := by + rcases h with rfl | rfl | h | h + · refine ⟨⟨⟨?_, ?_, ?_⟩, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩ <;> intros <;> simp_all + · refine ⟨⟨⟨?_, ?_, ?_⟩, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩ <;> intros <;> simp_all + · cases c <;> simp [isFrA] at h + refine ⟨⟨⟨?_, ?_, ?_⟩, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩ <;> intros <;> simp_all + · cases c <;> simp [isUtA] at h + refine ⟨⟨⟨?_, ?_, ?_⟩, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩ <;> intros <;> simp_all + +section slot +variable {T Ω Sg Rp Nt : Set U64} + +/-- `SlotOK`'s cap clause at the slot's `capA`. -/ +theorem SlotOK.capTy {s : S} {x : U64} (h : SlotOK st T Ω Sg H Rp Nt OS s x) : + CapTy T Ω Sg H Rp Nt OS (capA st s x) := + h.1 _ (CapRt.decode_eq _ _) + +theorem SlotOK.ofCap {s : S} {x : U64} (hc : CapTy T Ω Sg H Rp Nt OS (capA st s x)) + (hl : LinkOK OS (L.mem s (wa x 16#u64))) (hn : NextOK OS (L.mem s (wa x 24#u64))) : + SlotOK st T Ω Sg H Rp Nt OS s x := + ⟨fun c e => by + have e' := okinj ((CapRt.decode_eq _ _).symm.trans e) + subst e' + exact hc, hl, hn⟩ + +/-- **`SlotTy` from a transfer's slot fact** (module docstring). -/ +theorem SlotTy.ofXfer {s s' : S} (hO : OSOK T Ω Sg OS) (hT : SlotTy st T Ω Sg H Rp Nt OS s) + (hm : MdbS st OS s') (X : XferSlots st OS s s') : SlotTy st T Ω Sg H Rp Nt OS s' := by + have cap : ∀ z ∈ OS, CapTy T Ω Sg H Rp Nt OS (capA st s' z) := by + intro z hz + rcases X with same | ⟨src, hs, dest, hd, -, -, ⟨q, c, der, new⟩, turned, others⟩ + · rw [same z hz]; exact (hT z hz).capTy + · by_cases e1 : z = dest + · subst e1 + rw [new] + have D := objects.derive_cap.ty (st := st) q src (capA st s src) + rw [der] at D + rcases (WP.spec_ok _).1 D c rfl with e | h + · rw [e]; exact (hT src hs).capTy + · exact capTy_triv (by rcases h with h | h | h <;> simp [h]) + · by_cases e2 : z = src + · subst e2 + rcases turned with e | ⟨p, b, i, e, i1, -, hd', -⟩ + · rw [e]; exact (hT z hz).capTy + · rw [hd']; exact capTy_triv (Or.inr (Or.inr (Or.inr rfl))) + · rw [others z hz e2 e1]; exact (hT z hz).capTy + intro z hz + obtain ⟨l1, l2⟩ := hm.lnk hO hz + refine SlotOK.ofCap (cap z hz) ?_ fun n e => ?_ + · by_cases e : L.mem s' (wa z 16#u64) = 0#u64 + · exact Or.inl e + · exact Or.inr (l1 e) + · have e' : sxF (L.mem s' (wa z 24#u64)) = n := okinj ((sext48_eq _).symm.trans e) + subst e' + by_cases e0 : NxA st s' z = 0#u64 + · exact Or.inl e0 + · exact Or.inr (l2 e0) + +end slot + +set_option maxHeartbeats 4000000 in +/-- **`do_ipc_transfer` with the carry, the slot fact and `SlotTy` at its end** (module docstring). -/ +theorem ipc.do_ipc_transfer.xjT (hA : P0.ArchTotal ar) {Xq Rp Nt Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hSA : ScApart H.scs H.scBits OS) + (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hbk : BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s) + {snd ep badge rcv : U64} {grant : Bool} (hs : snd ∈ H.tcbs) (hr : rcv ∈ H.tcbs) : + ipc.do_ipc_transfer st ar s a snd ep badge grant rcv ⦃ s' => + XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s s' ∧ XferSlots st OS s s' ∧ + SlotTy st H.tcbs H.omega H.frame H Rp Nt OS s' ⦄ := + WP.spec_mono (ipc.do_ipc_transfer.xjS (Vc := Vc) hA a P hSA hTS hks hvr B Y hbk hs hr) fun _ h => + ⟨h.1, h.2.1, h.2.2.1, h.2.2.2, SlotTy.ofXfer P.os P.ty h.1.sys.sys.stz.1.1.mdbS h.2.2.2⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCYield.lean b/proofs/Fl4ProofsA64/P1/S1aCYield.lean new file mode 100644 index 000000000..a5f31f940 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCYield.lean @@ -0,0 +1,184 @@ +/- +P1 (aarch64, A64-P1 completion, stage 2 (c), c5): **`Yield`** (frozen D4: one theorem per kernel function). + +* **`syscall.handle_yield.s1a`**: S1aCBudget's `charge_budget.rpw` with the SC's head amount, then the current SC's + `CONSUMED` word (QueueKeeps's `handle_yield.bxi`: `ring_bx`, `SCsOK.ringc`; a `DMD` step by S1aCSchedCtlC's + `scw_dmd`), closed by `S1aStepR2K.ofRpPost`. + +* **`syscall.mcs_preemption_point.s1a`** (c7): `check_budget`, `charge_budget.rpw`, or the node's `CONSUMED` word. +* **`sched.check_budget.rpw`** / **`.s1a`**, **`sched.check_budget_restart.s1a`**: the budget checks, closed by + `S1aStepR2K.ofRpPost`. + +Named premises: [P] `P0.ArchTotal`; [J] `RunVcpuInv` (contract §5). Per-state facts: those of `charge_budget.s1a`. +-/ +import Fl4ProofsA64.P1.S1aCFault + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s + +set_option maxHeartbeats 8000000 in +/-- **`Yield` keeps the S1a step post** (module docstring). -/ +theorem syscall.handle_yield.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + syscall.handle_yield st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have h0 := B.ly.h0 + obtain ⟨⟨Q, Rq, q⟩, hB, hX, hS, hSg⟩ := id h + have hcS : L.cscW s ∈ H.scs := hX.2.2.cur + unfold syscall.handle_yield + step with sched.cur_sc.spec as ⟨csc, ecsc⟩ + have e1 : csc = L.cscW s := ecsc + subst e1 + step with obj.Sc.consumed.spec as ⟨i⟩ + step with sched.consumed.spec as ⟨i1⟩ + step as ⟨total, _⟩ + step with sporadic.head.spec as ⟨hd, ehd⟩ + refine WP.spec_bind (sched.charge_budget.rpw (Vc := Vc) hA a hd.amount false B Y h Pz I.del.sca I.ts hks + I.del.vr hcsc hna hcA hcb hRV) ?_ + rintro ⟨s1, a1⟩ P1 + simp only [WP.uncurry'_pair] at P1 ⊢ + step with obj.Sc.set_consumed.spec as ⟨s2, e2⟩ + subst e2 + obtain ⟨⟨Q1, R1, h1⟩, hB1, hX1, hS1, hSg1⟩ := id P1.2.2.1 + have hW1 : RefillsWF st s1 (L.cscW s) (H.scBits (L.cscW s)) := hS1.wf hcS hcA + obtain ⟨hP, hz⟩ := hX1.1.sc _ hcS + have hal : Aligned (wa (L.cscW s) layout.sc.CONSUMED) := by + obtain ⟨h8, -, -⟩ := sc_lo hP hz + unfold Aligned; rw [sc_word_val hP hz (by simp [layout.sc.CONSUMED])]; simp [layout.sc.CONSUMED]; omega + have w : WritesIn st s1 (L.wr s1 (wa (L.cscW s) layout.sc.CONSUMED) total) + (fun b => InRing (L.cscW s) (H.scBits (L.cscW s)) b ∨ b = wa (L.cscW s) layout.sc.CONSUMED) := + (writesIn_wr hal).mono fun b hb => Or.inr hb + have hS2 := SCsOK.ringc h1 hS1 hX1 hcS w hW1.wr_cons + obtain ⟨h2, hB2, hX2, hSg2, -⟩ := ring_bx h1 hB1 hX1 hSg1 hcS w + have b2 : BK (L.wr s1 (wa (L.cscW s) layout.sc.CONSUMED) total) := ⟨⟨Q1, R1, h2⟩, hB2, hX2, hS2, hSg2⟩ + have d2 : DMD st H Cs 0#u64 s1 (L.wr s1 (wa (L.cscW s) layout.sc.CONSUMED) total) := + scw_dmd P1.2.2.1 h0 P1.2.1 P1.1.vr hcS (by simp [layout.sc.CONSUMED]) (by simp [layout.sc.CONSUMED]) + ⟨by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], by simp [layout.sc.CONSUMED], + by simp [layout.sc.CONSUMED], fun e => absurd e (by simp [layout.sc.CONSUMED])⟩ + exact S1aStepR2K.ofRpPost I (P1.dmdK Pz.heap Pz.os I.del.sca Pz.core0 I.del.vr hks + (fun k hk => by rw [h0] at hk; cases hk) d2 b2).1 C Df R sep KC + +set_option maxHeartbeats 8000000 in +/-- **`check_budget` to the Reply-walk post** (S1aCBudget's `check_budget_restart.rpw`, its first part). -/ +theorem sched.check_budget.rpw (hA : P0.ArchTotal ar) {Vc' Ub' Pt' : Set U64} {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (a : A) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h : BK s) + (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) : + sched.check_budget st ar s a ⦃ r => RpPost st H Cs OS Vc ia ie Ac s r.2.1 ⦄ := by + unfold sched.check_budget + step with sched.cur_sc.spec as ⟨sc⟩ + step with sched.consumed.spec as ⟨c⟩ + step with sporadic.sufficient.ok (st := st) hA as ⟨b⟩ + split + · unfold sched.is_cur_domain_expired + simp only [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + have hnd : ¬ ((1#u64) > (1#u64)) := by simp + simp only [hnd, ↓reduceIte, bind_ok, WP.spec_ok] + exact (RpW.start (Vc := Vc) B Y h).post + · refine WP.spec_bind (sched.charge_budget.rpw (Vc := Vc) hA a c true B Y h Pz hSA hTS hks hvr hcsc hna hcA + hcb hRV) ?_ + rintro ⟨s1, a1⟩ P1 + simp only [WP.uncurry'_pair] at P1 + exact (WP.spec_ok _).2 P1 + +set_option maxHeartbeats 8000000 in +/-- **`mcs_preemption_point` keeps the S1a step post**: `check_budget` (as S1aCBudget's `check_budget_restart.rpw`), +`charge_budget.rpw`, or the node's `CONSUMED` word (`nodeW_step`). -/ +theorem syscall.mcs_preemption_point.s1a (hA : P0.ArchTotal ar) {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + syscall.mcs_preemption_point st ar s a ⦃ s' _ => S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + have h0 := B.ly.h0 + have fin : ∀ {s' : S}, RpPost st H Cs OS Vc ia ie Ac s s' → S1aStepR2K st Cs Ub Kt KLv ia ie n s' := + fun P => S1aStepR2K.ofRpPost I P C Df R sep KC + unfold syscall.mcs_preemption_point + step with sched.cur_thread.spec as ⟨ct⟩ + step with sched.is_schedulable.spec' as ⟨b⟩ + split + · refine WP.spec_bind (sched.check_budget.rpw (Vc := Vc) hA a B Y h Pz I.del.sca I.ts hks I.del.vr hcsc hna hcA + hcb hRV) ?_ + rintro ⟨x, s1, a1⟩ P1 + try simp only [WP.spec_ok, WP.uncurry'_pair] + first | exact fin P1 | exact (WP.spec_ok _).2 (fin P1) + · step with sched.cur_sc.spec as ⟨sc⟩ + step with sporadic.sc_active.spec as ⟨b1⟩ + split + · step with sched.consumed.spec as ⟨c⟩ + exact WP.spec_mono (sched.charge_budget.rpw (Vc := Vc) hA a c false B Y h Pz I.del.sca I.ts hks I.del.vr hcsc + hna hcA hcb hRV) fun r P => by + obtain ⟨s', a'⟩ := r + simp only [WP.uncurry'_pair] at P ⊢ + exact fin P + · step with LawfulStore.cur_cpu_spec as ⟨cpu, ecpu⟩ + step with obj.node_set.spec as ⟨s2, e2⟩ + try simp only [WP.spec_ok, WP.uncurry'_pair] + subst e2 ecpu + have q := h.1.choose_spec.choose_spec + have cv : layout.node.CONSUMED.val = 40 := by simp [layout.node.CONSUMED] + obtain ⟨d, b2⟩ := nodeW_step 0#u64 h h0 Y B.vr (by rw [cv]; unfold LowFree; omega) (by rw [cv]; omega) + (by rw [cv]; omega) (writesIn_wr (nodeAt_aligned (q.nodes _ q.cur) (by rw [cv]; omega) (by rw [cv]))) + have X := fin ((RpW.start (Vc := Vc) B Y h).dmdK Pz.heap Pz.os I.del.sca Pz.core0 I.del.vr hks + (fun k hk => by rw [h0] at hk; cases hk) d b2).1.post + first | exact X | exact (WP.spec_ok _).2 X + +section topCB +variable {K : capability.Cap → Prop} {Ty : S → Prop} {Uq Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} + {n : U64} + +/-- **`check_budget` keeps the S1a step post** (`check_budget.rpw`, `S1aStepR2K.ofRpPost`). -/ +theorem sched.check_budget.s1a (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.check_budget st ar s a ⦃ r => S1aStepR2K st Cs Ub Kt KLv ia ie n r.2.1 ⦄ := + WP.spec_mono (sched.check_budget.rpw (Vc := Vc) hA a B Y h Pz I.del.sca I.ts hks I.del.vr hcsc hna hcA hcb hRV) + fun _ P => S1aStepR2K.ofRpPost I P C Df R sep KC + +/-- **`check_budget_restart` keeps the S1a step post** (`check_budget_restart.rpw`, `S1aStepR2K.ofRpPost`). -/ +theorem sched.check_budget_restart.s1a (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} (a : A) + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (h : BK s) (hks : HeapKsOff H (L.ksb s)) (Pz : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (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) + (hcb : CanBlock st H.tcbs Ac s (L.curW s)) (hRV : RunVcpuInv st H.tcbs s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Df : DevFrAl st OS s) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) : + sched.check_budget_restart st ar s a ⦃ r => S1aStepR2K st Cs Ub Kt KLv ia ie n r.2.1 ⦄ := + WP.spec_mono (sched.check_budget_restart.rpw (Vc := Vc) hA a B Y h Pz I.del.sca I.ts hks I.del.vr hcsc hna hcA hcb + hRV) fun _ P => S1aStepR2K.ofRpPost I P C Df R sep KC + +end topCB + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aCYieldTo.lean b/proofs/Fl4ProofsA64/P1/S1aCYieldTo.lean new file mode 100644 index 000000000..83273a491 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aCYieldTo.lean @@ -0,0 +1,545 @@ +/- +P1 (aarch64, A64-P1 completion, stage 1 (a12)): **SchedContext YieldTo keeps every capability** (schedcontext.rs +`decode`, `yield_to`, `yield_switches`, `complete_yield_to`). + +Every step of `yield_to` is a MdbDfM `DM sc` step (`sc` the invoked SC), so the whole call is one `DmPost` from the +caller's restart: +* **`schedcontext.complete_yield_to.dmS`**: the previous yielder's `set_consumed` and `cancel_yield_to` (QueueFoot8's + `complete_yield_to.blkS`, QueueYield's `.yw`, MdbLiveF's `.lv`): the cut links are of `sc` and of the yielder, + which is live before (its `YIELD_TO` is `sc`), so MdbSigL's `DMD.ofK`; `YieldS` by MdbLiveT's `YieldS.cut`. +* `resume` (MdbSigL's `resume.dmd`, S1aCRestart's `resume.footK8`, QueueYield's `resume.allF` for the frame). +* **`schedcontext.yield_switches.dm`**: QueueYield's `yield_switches.blkY` walk with each queue step a + `DMD.ofNone` (`Post.fr`, QueueFoot8's `K8` footprints); the switch's two link writes (the caller's `YIELD_TO`, the + SC's `YIELD_FROM`) let only the caller (live: not inactive) and `sc` change, and **establish the link in + `YieldS`** (`yieldS_link`: the caller had no `YIELD_TO`, the SC no `YIELD_FROM` after `complete_yield_to`). +* The non-switching tail: `set_consumed` (MdbDfM's `DM.ofLv`, as SchedContext Consumed) and the caller set running + (a `DF` step at the end state, `SysL.df`). +* **`schedcontext.yield_to.dmPost`**, **`schedcontext.decode.yieldToSAt`** (the stall, the checks, the restart, + `yield_to`; MdbArmDm's `ArmQIAt.ofDMK`), **`syscall.decode_invocation.scYieldTo_armS`**. + +Named premises: [P] `P0.ArchTotal`. Case facts: none new (`DecPre.cb` for the caller's SC, as QueueDecSc). +-/ +import Fl4ProofsA64.P1.S1aCScBind +import Fl4ProofsA64.P1.QueueYield + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +local notation "wa" => core.num.U64.wrapping_add +local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s +local notation "FK" => K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) + +/-- An SC of the heap is not null. -/ +theorem scs_ne0 (h0 : H 0#u64 = none) {c : U64} (hc : c ∈ H.scs) : c ≠ 0#u64 := ne0_of_heap h0 hc.choose_spec + +/-- A scheduler-queue step (`Post`, a `K8` footprint): `BlkOK`, a `DMD p` step. -/ +theorem qstep (p : U64) {s1 s2 : S} (b1 : BK s1) (h0 : H 0#u64 = none) (Y1 : SymL st H Cs s1) + (V1 : ValidReplies st H s1) (P : Post st H.tcbs Cs H.omega H H.frame Ac s1 s2) + (f : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s1 s2) : + (BK s2) ∧ FK s1 s2 ∧ DMD st H Cs p s1 s2 := by + obtain ⟨-, -, hX1, hS1, hSg1⟩ := id b1 + exact ⟨⟨P.inv, P.bnd, hX1.fr P.fr, hS1.fr P.fr, hSg1.fr P.fr⟩, WritesIn.mono f fun _ hb => kw8_es hb, + DMD.ofNone b1 h0 Y1 V1 (K8.Foot.d f) (LvF.of_fr (LvC.of_blk b1) P.fr)⟩ + +set_option maxHeartbeats 2000000 in +/-- **`complete_yield_to y`** of the yielder `y` to `sc` is a `DMD sc` step; `sc`'s `YIELD_FROM` is null after. -/ +theorem schedcontext.complete_yield_to.dmS (hA : P0.ArchTotal ar) {s : S} (a : A) (y sc : U64) (h : BK s) + (h0 : H 0#u64 = none) (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hyT : y ∈ H.tcbs) + (hysc : L.mem s (yieldA y) = sc) (hsc : sc ∈ H.scs) : + schedcontext.complete_yield_to st ar s a y ⦃ s' _ => (BK s') ∧ FK s s' ∧ DMD st H Cs sc s s' ∧ + L.mem s' (scYieldFromA sc) = 0#u64 ∧ ANI st s s' ∧ L.mem s' (scTcbA sc) = L.mem s (scTcbA sc) ∧ + (∀ t ∈ H.tcbs, L.mem s' (scA t) = L.mem s (scA t) ∧ L.mem s' (stA t) = L.mem s (stA t) ∧ + L.mem s' (inqA t) = L.mem s (inqA t)) ∧ + (∀ t ∈ H.tcbs, t ≠ y → L.mem s' (yieldA t) = L.mem s (yieldA t)) ⦄ := by + have hX := h.2.2.1 + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT + have q0 := h.1.choose_spec.choose_spec + have hy0 : y ≠ 0#u64 := ne0_of_heap h0 hyT + have hsc0 : sc ≠ 0#u64 := scs_ne0 h0 hsc + have hYS : LvSO layout.sc.YIELD_FROM.val := by unfold LvSO; simp [layout.sc.YIELD_FROM] + refine WP.spec_mono (WP.spec_and (WP.spec_and (K8.schedcontext.complete_yield_to.blkS hA s a y sc h (fun _ => hyT) hsc) + (schedcontext.complete_yield_to.yw hA s a y h (fun _ => hyT))) + (schedcontext.complete_yield_to.lv hA s a y h (fun _ => hyT))) ?_ + rintro ⟨s', a'⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨⟨⟨h', f, n, k⟩, w⟩, g, yu, fu⟩ := hh + rw [hysc] at g fu + have kk := yw_keep q0 w + have kt : ∀ t ∈ H.tcbs, t ≠ y → L.mem s' (yieldA t) = L.mem s (yieldA t) := fun t ht hn => + g.t t ht 3472#u64 (by unfold LvO; simp) fun e => by + rcases e with e | e + · exact (e : False).elim + · exact hn e.1 + have Y' : YieldS st H.tcbs H.scs s' := YieldS.cut Y.yld hX.2.2.yt (fun c hc => scs_ne0 h0 hc) hyT kt + (fun c hc hn => g.c c hc _ hYS fun e => by + rcases e with e | e + · exact hn (by rw [hysc]; exact e.1) + · exact (e : False).elim) + (yu hy0) (fun hn => by rw [hysc]; exact fu hy0 hsc0) + have D' := Y.dbg.lv hz g fun t k hk => by + rcases hk with hk | hk + · exact (hk : False).elim + · rw [hk.2]; decide + have VR' : ValidReplies st H s' := ValidReplies.lv VR hX.2.1 g + (fun c k hk => by + rcases hk with hk | hk + · rw [hk.2]; decide + · exact (hk : False).elim) + (fun r k hk => by rcases hk with hk | hk <;> exact (hk : False).elim) + (BorK.of_lv g fun t k hk => by + rcases hk with hk | hk + · exact (hk : False).elim + · rw [hk.2]; decide) + have Kk : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = sc ∨ q = y) s s' := + LvK.ofLv g (fun t k e => by + rcases e with e | e + · exact (e : False).elim + · exact Or.inr e.1) + (fun c k e => by + rcases e with e | e + · exact Or.inl e.1 + · exact (e : False).elim) + (fun n k e => by rcases e with e | e <;> exact (e : False).elim) + (fun r e => by rcases e with e | e <;> exact (e : False).elim) + have hE : ∀ q, (q = sc ∨ q = y) → q = sc ∨ q = 0#u64 ∨ LiveQ st H Cs s q := by + rintro q (e | e) + · exact Or.inl e + · subst e + exact Or.inr (Or.inr (LiveQ.tcb hyT (Or.inr (Or.inr (Or.inr (Or.inl (by rw [hysc]; exact hsc0))))))) + have F : FK s s' := WritesIn.mono f fun _ hb => kw8_es hb + have d : DMD st H Cs sc s s' := DMD.ofK h h0 Y ⟨D', Y'⟩ VR' (K8.Foot.d F) Kk hE (EpM.ofK (ep_kept_kw h f)) + g.idle (g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by + rcases e with e | e + · exact (e : False).elim + · exact absurd e.2 (by simp)) + exact ⟨h', F, d, fu hy0 hsc0, n, k.1, fun t ht => ⟨(kk t ht).1, (kk t ht).2.2.1, (kk t ht).2.2.2⟩, kt⟩ + +/-- **`YieldS` gains the link `t → c`** when `t` had no `YIELD_TO` and `c` no `YIELD_FROM`. -/ +theorem yieldS_link {s s' : S} {t c : U64} (h0 : H 0#u64 = none) (Y : YieldS st H.tcbs H.scs s) + (hy : YT st H.tcbs H.scs s) (ht : t ∈ H.tcbs) (hy0 : L.mem s (yieldA t) = 0#u64) + (hf0 : L.mem s (scYieldFromA c) = 0#u64) + (v1 : L.mem s' (yieldA t) = c) (v2 : L.mem s' (scYieldFromA c) = t) + (kt : ∀ y ∈ H.tcbs, y ≠ t → L.mem s' (yieldA y) = L.mem s (yieldA y)) + (kc : ∀ d ∈ H.scs, d ≠ c → L.mem s' (scYieldFromA d) = L.mem s (scYieldFromA d)) : + YieldS st H.tcbs H.scs s' := by + refine ⟨fun d hd h1 => ?_, fun u hu h1 => ?_⟩ + · by_cases ed : d = c + · rw [ed, v2, v1] + · rw [kc d hd ed] at h1 ⊢ + have hft : L.mem s (scYieldFromA d) ∈ H.tcbs := hy.2.2 d hd h1 + have hnt : L.mem s (scYieldFromA d) ≠ t := fun e => by + have := Y.fy d hd h1 + rw [e, hy0] at this + exact scs_ne0 h0 hd this.symm + rw [kt _ hft hnt]; exact Y.fy d hd h1 + · by_cases eu : u = t + · rw [eu, v1, v2] + · rw [kt u hu eu] at h1 ⊢ + have hcs : L.mem s (yieldA u) ∈ H.scs := hy.2.1 u hu h1 + have hnc : L.mem s (yieldA u) ≠ c := fun e => by + have := Y.yf u hu h1 + rw [e, hf0] at this + exact ne0_of_heap h0 (show H u = some .tcb from hu) this.symm + rw [kc _ hcs hnc]; exact Y.yf u hu h1 + +set_option maxHeartbeats 8000000 in +/-- **`yield_switches`** is a `DMD sc` step with `BlkOK` (module docstring); when it does not switch, the caller's +state and the current thread are kept. -/ +theorem schedcontext.yield_switches.dm {s : S} (sc ct : U64) (h : BK s) (h0 : H 0#u64 = none) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) + (hsc : sc ∈ H.scs) (hct : ct ∈ H.tcbs) (hi0 : L.mem s (scTcbA sc) ≠ 0#u64) (hne : L.mem s (scTcbA sc) ≠ ct) + (hrun : Runnable (L.mem s (stA ct))) (hbd : L.mem s (scA ct) ≠ 0#u64) (hba : L.mem s (scA ct) ∈ Ac) + (hr : (L.mem s (inqA ct) &&& sched.Q_RELEASE) = 0#u64) + (hy0 : L.mem s (yieldA ct) = 0#u64) (hf0 : L.mem s (scYieldFromA sc) = 0#u64) : + schedcontext.yield_switches st s sc ct ⦃ r => (BK r.2) ∧ FK s r.2 ∧ DMD st H Cs sc s r.2 ∧ + (r.1 = false → L.mem r.2 (stA ct) = L.mem s (stA ct) ∧ L.curW r.2 = L.curW s) ⦄ := by + unfold schedcontext.yield_switches + step with obj.Sc.tcb.spec as ⟨i, ei⟩ + have hiT : i ∈ H.tcbs := by rw [ei]; exact h.2.2.1.2.2.yt.1 sc hsc hi0 + have hic : i ≠ ct := by rw [ei]; exact hne + step with sched.is_schedulable.spec' as ⟨b, hb⟩ + split + · rename_i hbt + obtain ⟨hrun_i, hbd_i, hr_i, hmx⟩ := hb hbt + have hba_i : L.mem s (scA i) ∈ Ac := (h.2.2.2.1.act _ (h.2.2.1.2.2.bound i hiT hbd_i).1).2 hmx + have rq : (do + let s1 ← sched.dequeue st s i + let s2 ← sched.enqueue st s1 i + ok (false, s2)) ⦃ r => (BK r.2) ∧ FK s r.2 ∧ DMD st H Cs sc s r.2 ∧ + (r.1 = false → L.mem r.2 (stA ct) = L.mem s (stA ct) ∧ L.curW r.2 = L.curW s) ⦄ := by + obtain ⟨⟨Q, R, q⟩, hB, -, -, hSg⟩ := id h + refine WP.spec_bind (WP.spec_and (WP.spec_and (sched.dequeue.blkY s i h hiT) + (sched.dequeue.sch s i Q R q hB hSg hiT)) + (K8.sched.dequeue.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s i q hiT)) ?_ + rintro s1 ⟨⟨⟨-, -, r1, k1⟩, p1, -, c1⟩, f1⟩ + obtain ⟨b1, F1, d1⟩ := qstep sc h h0 Y VR p1 f1 + obtain ⟨⟨Q1, R1, q1⟩, hB1, -, -, hSg1⟩ := id b1 + refine WP.spec_bind (WP.spec_and (sched.enqueue.sch s1 i Q1 R1 q1 hB1 hSg1 hiT (fun _ => r1 hr_i) + (fun _ => by rw [(k1 i hiT).1]; exact hrun_i) (fun _ => by rw [(k1 i hiT).2.1]; exact hbd_i) + (fun _ => by rw [(k1 i hiT).2.1]; exact hba_i)) + (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s1 i q1 hiT)) ?_ + rintro s2 ⟨⟨p2, -, c2, kp2⟩, f2⟩ + obtain ⟨b2, F2, d2⟩ := qstep sc b1 h0 d1.sym d1.vr p2 (K8.FootB.foot f2) + exact (WP.spec_ok _).2 ⟨b2, F1.trans F2, d1.trans d2, fun _ => ⟨(kp2.1 ct hct).trans (k1 ct hct).1, + c2.trans c1⟩⟩ + step with obj.Sc.cpu.spec as ⟨i1, _⟩ + step with LawfulStore.cur_cpu_spec as ⟨i2, _⟩ + split + · exact rq + step with obj.Tcb.prio.spec as ⟨i3, _⟩ + step with obj.Tcb.prio.spec as ⟨i4, _⟩ + split + · exact rq + -- the switch: the two link writes + refine WP.spec_bind (obj.Tcb.set_yield_to.spec s ct sc) fun s1 e1 => ?_ + subst e1 + refine WP.spec_bind (obj.Sc.set_yield_from.spec _ sc ct) fun s2 e2 => ?_ + subst e2 + obtain ⟨h2, k2⟩ := yield_link.blk h hct hsc + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h + have hO := hX.1 + have hT := q.tcbs + have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ + have hI : L.idleW s ∈ H.tcbs := q.idleT + have hYT : LvO (3472#u64).val := by unfold LvO; simp + have hYS : LvSO layout.sc.YIELD_FROM.val := by unfold LvSO; simp [layout.sc.YIELD_FROM] + have hmY : scYieldFromA sc ∈ H.frame := hO.syW sc hsc + have g1 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.tc ct 3472) s (L.wr s (yieldA ct) sc) := + LvF.wrT C (v := sc) hct (K0 := 3472#u64) (by simp) (by simp) (j := 3472) (by simp) + have g2 : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.sc sc 56) (L.wr s (yieldA ct) sc) + (L.wr (L.wr s (yieldA ct) sc) (scYieldFromA sc) ct) := + LvF.wrC (C.wr _ _) (v := ct) hsc (o0 := layout.sc.YIELD_FROM) (by simp [layout.sc.YIELD_FROM]) + (by simp [layout.sc.YIELD_FROM]) (j := 56) (by simp [layout.sc.YIELD_FROM]) + have g := g1.trans g2 + have f : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits ∅ s (L.wr (L.wr s (yieldA ct) sc) (scYieldFromA sc) ct) := + (K8.foot_field (K := 3472#u64) hT hct (by simp) (by simp) (by simp) (by simp)).trans + (K8.foot_wr (q.omega _ (hSg.sub _ hmY)).1 (K8.kw_sg hmY)) + set sL := L.wr (L.wr s (yieldA ct) sc) (scYieldFromA sc) ct with hsL + have v1 : L.mem sL (yieldA ct) = sc := + (g2.t ct hct 3472#u64 hYT fun e => (e : False).elim).trans (L.mem_wr_same (C.al_t (K := 3472#u64) hct hYT)) + have v2 : L.mem sL (scYieldFromA sc) = ct := L.mem_wr_same ((C.wr (yieldA ct) sc).al_c hsc hYS) + have kt : ∀ y ∈ H.tcbs, y ≠ ct → L.mem sL (yieldA y) = L.mem s (yieldA y) := fun y hy hn => + g.t y hy 3472#u64 hYT fun e => by + rcases e with e | e + · exact hn e.1 + · exact (e : False).elim + have kc : ∀ d ∈ H.scs, d ≠ sc → L.mem sL (scYieldFromA d) = L.mem s (scYieldFromA d) := fun d hd hn => + g.c d hd _ hYS fun e => by + rcases e with e | e + · exact (e : False).elim + · exact hn e.1 + have Y' : YieldS st H.tcbs H.scs sL := yieldS_link h0 Y.yld hX.2.2.yt hct hy0 hf0 v1 v2 kt kc + have D' := Y.dbg.lv hz g fun y k hk => by + rcases hk with hk | hk + · rw [hk.2]; decide + · exact (hk : False).elim + have VR' : ValidReplies st H sL := ValidReplies.lv VR hX.2.1 g + (fun c k hk => by + rcases hk with hk | hk + · exact (hk : False).elim + · rw [hk.2]; decide) + (fun r k hk => by rcases hk with hk | hk <;> exact (hk : False).elim) + (BorK.of_lv g fun y k hk => by + rcases hk with hk | hk + · rw [hk.2]; decide + · exact (hk : False).elim) + have Kk : LvK st H.tcbs Cs H.replies H.scs H.ntfns (fun q => q = sc ∨ q = ct) s sL := + LvK.ofLv g (fun y k e => by + rcases e with e | e + · exact Or.inr e.1 + · exact (e : False).elim) + (fun c k e => by + rcases e with e | e + · exact (e : False).elim + · exact Or.inl e.1) + (fun n k e => by rcases e with e | e <;> exact (e : False).elim) + (fun r e => by rcases e with e | e <;> exact (e : False).elim) + have hE : ∀ q, (q = sc ∨ q = ct) → q = sc ∨ q = 0#u64 ∨ LiveQ st H Cs s q := by + rintro q (e | e) + · exact Or.inl e + · subst e + exact Or.inr (Or.inr (LiveQ.tcb hct (Or.inl fun e => not_runnable_inactive (by rw [← e]; exact hrun)))) + have FL : FK s sL := WritesIn.mono f fun _ hb => kw8_es hb + have dL : DMD st H Cs sc s sL := DMD.ofK h h0 Y ⟨D', Y'⟩ VR' (K8.Foot.d FL) Kk hE (EpM.ofK (ep_kept_kw h f)) + g.idle (g.t _ hI 3464#u64 (by unfold LvO; simp) fun e => by + rcases e with e | e + · exact absurd e.2 (by simp) + · exact (e : False).elim) + -- dequeue the SC's thread, queue the caller and the SC's thread, reschedule + obtain ⟨⟨Q2, R2, q2⟩, hB2, -, -, hSg2⟩ := id h2 + refine WP.spec_bind (WP.spec_and (WP.spec_and (sched.dequeue.blkY _ i h2 hiT) + (sched.dequeue.sch _ i Q2 R2 q2 hB2 hSg2 hiT)) + (K8.sched.dequeue.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) _ i q2 hiT)) ?_ + rintro s3 ⟨⟨⟨-, -, r3, k3⟩, p3, -, -⟩, f3⟩ + obtain ⟨b3, F3, d3⟩ := qstep sc h2 h0 dL.sym dL.vr p3 f3 + obtain ⟨⟨Q3, R3, q3⟩, hB3, -, -, hSg3⟩ := id b3 + refine WP.spec_bind (WP.spec_and (WP.spec_and (sched.enqueue.blkY s3 ct b3 hct + (by rw [(k3 ct hct).1, (k2 ct hct).2.1]; exact hrun) + (by rw [(k3 ct hct).2.1, (k2 ct hct).1]; exact hbd) + (by rw [(k3 ct hct).2.1, (k2 ct hct).1]; exact hba) + (by rw [(k3 ct hct).2.2 (Ne.symm hic), (k2 ct hct).2.2]; exact hr)) + (sched.enqueue.sch s3 ct Q3 R3 q3 hB3 hSg3 hct + (fun _ => by rw [(k3 ct hct).2.2 (Ne.symm hic), (k2 ct hct).2.2]; exact hr) + (fun _ => by rw [(k3 ct hct).1, (k2 ct hct).2.1]; exact hrun) + (fun _ => by rw [(k3 ct hct).2.1, (k2 ct hct).1]; exact hbd) + (fun _ => by rw [(k3 ct hct).2.1, (k2 ct hct).1]; exact hba))) + (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s3 ct q3 hct)) ?_ + rintro s4 ⟨⟨⟨-, k4⟩, p4, -, -, -⟩, f4⟩ + obtain ⟨b4, F4, d4⟩ := qstep sc b3 h0 d3.sym d3.vr p4 (K8.FootB.foot f4) + obtain ⟨⟨Q4, R4, q4⟩, hB4, -, -, hSg4⟩ := id b4 + have ri : (L.mem s4 (inqA i) &&& sched.Q_RELEASE) = 0#u64 := by + rw [(k4 i hiT).2.2 hic]; exact r3 (by rw [(k2 i hiT).2.2]; exact hr_i) + have runi : Runnable (L.mem s4 (stA i)) := by rw [(k4 i hiT).1, (k3 i hiT).1, (k2 i hiT).2.1]; exact hrun_i + have bdi : L.mem s4 (scA i) ≠ 0#u64 := by rw [(k4 i hiT).2.1, (k3 i hiT).2.1, (k2 i hiT).1]; exact hbd_i + have bai : L.mem s4 (scA i) ∈ Ac := by rw [(k4 i hiT).2.1, (k3 i hiT).2.1, (k2 i hiT).1]; exact hba_i + refine WP.spec_bind (WP.spec_and (sched.enqueue.sch s4 i Q4 R4 q4 hB4 hSg4 hiT (fun _ => ri) (fun _ => runi) + (fun _ => bdi) (fun _ => bai)) + (K8.sched.enqueue.kwB8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s4 i q4 hiT)) ?_ + rintro s5 ⟨⟨p5, -, -, -⟩, f5⟩ + obtain ⟨b5, F5, d5⟩ := qstep sc b4 h0 d4.sym d4.vr p5 (K8.FootB.foot f5) + obtain ⟨⟨Q5, R5, q5⟩, hB5, -, -, hSg5⟩ := id b5 + refine WP.spec_bind (WP.spec_and (sched.reschedule_required.sch s5 Q5 R5 q5 hB5 hSg5) + (K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s5 q5)) ?_ + rintro s6 ⟨⟨p6, -, -, -⟩, f6⟩ + obtain ⟨b6, F6, d6⟩ := qstep sc b5 h0 d5.sym d5.vr p6 f6 + exact (WP.spec_ok _).2 ⟨b6, FL.trans (F3.trans (F4.trans (F5.trans F6))), + dL.trans (d3.trans (d4.trans (d5.trans d6))), fun e => absurd e (by simp)⟩ + · exact (WP.spec_ok _).2 ⟨h, WritesIn.refl _ _, DMD.refl sc h h0 Y VR, fun _ => ⟨rfl, rfl⟩⟩ + +set_option maxHeartbeats 8000000 in +/-- **`yield_to sc`** after the caller's restart (an `RsR` state): one `DmPost` (module docstring). -/ +theorem schedcontext.yield_to.dmPost (hA : P0.ArchTotal ar) {s0 s : S} (a : A) (sc : U64) (call : Bool) + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot b : U64} + (R : RsR st H Cs OS ia ie H.replies H.ntfns Ac extra slot s0 s) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s0 = ok (.SchedContext sc b)) (hsc : sc ∈ H.scs) + (hst : L.mem s (stA (L.curW s)) = sched.TS_RESTART) (hi0 : L.mem s (scTcbA sc) ≠ 0#u64) + (hne : L.mem s (scTcbA sc) ≠ L.curW s) (hy0 : L.mem s (yieldA (L.curW s)) = 0#u64) + (hbd : L.mem s (scA (L.curW s)) ≠ 0#u64) (hba : L.mem s (scA (L.curW s)) ∈ Ac) + (hnr : (L.mem s (inqA (L.curW s)) &&& sched.Q_RELEASE) = 0#u64) : + schedcontext.yield_to st ar s a sc call ⦃ r => DmPost st H Cs OS ia ie Ac s r.1 ⦄ := by + have h := R.blk + have h0 : H 0#u64 = none := R.sys.ly.h0 + have q0 := h.1.choose_spec.choose_spec + have hT := q0.tcbs + have hct : L.curW s ∈ H.tcbs := q0.curT + set ct := L.curW s with hctdef + have hX := h.2.2.1 + have hO := hX.1 + unfold schedcontext.yield_to + step with obj.Sc.yield_from.val as ⟨yf, eyf⟩ + step with obj.Tcb.is_null.spec as ⟨bn, ebn⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => (BK r.1) ∧ FK s r.1 ∧ DMD st H Cs sc s r.1 ∧ + L.mem r.1 (scYieldFromA sc) = 0#u64 ∧ L.actionW r.1 = L.actionW s ∧ L.curW r.1 = L.curW s ∧ + L.mem r.1 (scTcbA sc) = L.mem s (scTcbA sc) ∧ + (∀ t ∈ H.tcbs, L.mem r.1 (scA t) = L.mem s (scA t) ∧ L.mem r.1 (stA t) = L.mem s (stA t) ∧ + L.mem r.1 (inqA t) = L.mem s (inqA t)) ∧ + L.mem r.1 (yieldA ct) = 0#u64) ?_ ?_ + · split + · rename_i hb + have e0 : L.mem s (scYieldFromA sc) = 0#u64 := by rw [← eyf]; simpa [ebn] using hb + exact (WP.spec_ok _).2 ⟨h, WritesIn.refl _ _, DMD.refl sc h h0 R.sym R.sys.vr, e0, rfl, rfl, rfl, + fun _ _ => ⟨rfl, rfl, rfl⟩, hy0⟩ + · rename_i hb + have hyf0 : L.mem s (scYieldFromA sc) ≠ 0#u64 := fun e => hb (by rw [ebn, eyf, e]; rfl) + have hyT : yf ∈ H.tcbs := by rw [eyf]; exact hX.2.2.yt.2.2 sc hsc hyf0 + have hysc : L.mem s (yieldA yf) = sc := by rw [eyf]; exact R.sym.yld.fy sc hsc hyf0 + have hne' : ct ≠ yf := fun e => scs_ne0 h0 hsc (by rw [← hysc, ← e]; exact hy0) + refine WP.spec_mono (schedcontext.complete_yield_to.dmS hA a yf sc h h0 R.sym R.sys.vr hyT hysc hsc) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨b1, F1, d1, z1, n1, t1, k1, kt1⟩ := hh + exact ⟨b1, F1, d1, z1, n1.1, n1.2.2, t1, k1, (kt1 ct hct hne').trans hy0⟩ + rintro ⟨s1, a1⟩ ⟨b1, F1, d1, z1, ea1, ec1, t1, k1, y1⟩ + try simp only [WP.uncurry'_pair] + obtain ⟨⟨Q1, R1, q1⟩, hB1, hX1, hS1, hSg1⟩ := id b1 + have hiT : L.mem s1 (scTcbA sc) ∈ H.tcbs := hX1.2.2.yt.1 sc hsc (by rw [t1]; exact hi0) + have hres : sc ≠ 0#u64 → L.mem s1 (scTcbA sc) ≠ 0#u64 → + L.mem s1 (scTcbA sc) ∈ H.tcbs ∧ OutsideObjs st H.tcbs Cs s1 (scCoreA sc) ∧ L.mem s1 (scCoreA sc) ∈ Cs ∧ + L.actionW s1 ≠ L.mem s1 (scTcbA sc) := fun _ _ => + ⟨hiT, q1.omega _ (hSg1.sub _ (hX1.1.fixW sc hsc).2), hX1.2.2.core sc hsc, by rw [ea1]; exact R.na _ hiT⟩ + refine WP.spec_bind (WP.spec_and (WP.spec_and (schedcontext.resume.dmd hA sc a1 sc b1 h0 d1.sym d1.vr hres) + (schedcontext.resume.footK8 hA a1 sc b1 hres)) + (schedcontext.resume.allF hA s1 a1 sc Q1 R1 q1 hB1 hX1 hSg1 hS1 hres)) ?_ + rintro ⟨s2, a2⟩ hh + simp only [WP.uncurry'_pair] at hh + obtain ⟨⟨⟨d2, b2⟩, F2⟩, Q2, R2, q2, -, -, -, fr2, -, ec2, iq2⟩ := hh + try simp only [WP.uncurry'_pair] + have G2 := LvF.of_fr (Cs := Cs) (Rp := H.replies) (Nt := H.ntfns) (LvC.of_blk b1) fr2 + have ec : L.curW s2 = ct := ec2.trans ec1 + step with sched.cur_thread.spec as ⟨ct', ect'⟩ + have hc' : ct' = ct := by rw [ect']; exact ec + subst hc' + have t2 : L.mem s2 (scTcbA sc) = L.mem s (scTcbA sc) := (fr2.sig _ (hX1.1.fixW sc hsc).1).trans t1 + have hnei : ct ≠ L.mem s1 (scTcbA sc) := fun e => hne (by rw [← t1, ← e]) + have st2 : L.mem s2 (stA ct) = sched.TS_RESTART := by rw [fr2.st ct hct, (k1 ct hct).2.1, hst] + refine WP.spec_bind (schedcontext.yield_switches.dm sc ct b2 h0 d2.sym d2.vr hsc hct + (by rw [t2]; exact hi0) (by rw [t2]; exact hne) (by rw [st2]; exact runnable_restart) + (by rw [fr2.sc ct hct, (k1 ct hct).1]; exact hbd) (by rw [fr2.sc ct hct, (k1 ct hct).1]; exact hba) + (by rw [iq2 ct hct hnei, (k1 ct hct).2.2]; exact hnr) + (by + have e : L.mem s2 (yieldA ct) = L.mem s1 (yieldA ct) := G2.t ct hct 3472#u64 (by unfold LvO; simp) id + rw [e]; exact y1) + (by + have e : L.mem s2 (scYieldFromA sc) = L.mem s1 (scYieldFromA sc) := + G2.c sc hsc _ (by unfold LvSO; simp [layout.sc.YIELD_FROM]) id + rw [e]; exact z1)) ?_ + rintro ⟨b3, s3⟩ ⟨h3, F3, d3, k3⟩ + simp only at h3 F3 d3 k3 + have D3 : DMD st H Cs sc s s3 := d1.trans (d2.trans d3) + have FF3 : FK s s3 := F1.trans (F2.trans F3) + have M3 : DM st H Cs sc s s3 := ⟨FF3, D3.lv, D3.idle, D3.isc, D3.vr, D3.sym⟩ + obtain ⟨B3, Y3⟩ := SysL.dfM R.pl h.bxi hSA (R.namedS hcap hsc) R.sys M3 + cases b3 + · try simp only [Bool.false_eq_true, ↓reduceIte] + obtain ⟨st3, ec3⟩ := k3 rfl + rw [st2] at st3 + rw [ec] at ec3 + have C3 := LvC.of_blk h3 + have hX3 := h3.2.2.1 + refine WP.spec_bind (WP.spec_and + (K8.schedcontext.set_consumed.blkS hA s3 a2 sc ct sc call h3 hsc hct hsc) + (schedcontext.set_consumed.lv hA s3 a2 sc ct call C3 hsc hct)) ?_ + rintro s4 ⟨⟨h4, f4, n4, -⟩, g4⟩ + have d4 : DM st H Cs sc s3 s4 := + DM.ofLv h3 h0 D3.sym (ValidReplies.lv D3.vr hX3.2.1 g4 (fun _ _ hk => hk.elim) (fun _ _ hk => hk.elim) + (BorK.of_lv g4 fun _ _ hk => hk.elim)) f4 g4 (fun _ _ hk => hk.elim) (fun _ _ hk => hk.elim) + (fun _ _ hk => hk.elim) (fun _ _ hk => hk.elim) + have M4 : DM st H Cs sc s s4 := M3.trans d4 + obtain ⟨B4, Y4⟩ := SysL.dfM R.pl h.bxi hSA (R.namedS hcap hsc) R.sys M4 + have k4 : OSKeep st OS s s4 := by + obtain ⟨Q, Rq, q⟩ := h.1 + exact OSKeep.of_kw7 R.pl.os q h.2.2.2.2.sub hSA (fun _ he => he) + (WritesIn.mono M4.w fun _ hb => K8.KW.to7 hb) + have P4 := R.pl.keepO k4 M4.w.1 + have ec4 : L.curW s4 = ct := n4.2.2.trans ec3 + have e4 : L.mem s4 (stA ct) = sched.TS_RESTART := by + rw [stA_eq, g4.t _ hct 3328#u64 (by unfold LvO; simp) (fun e => False.elim e), ← stA_eq, st3] + have run4 : Runnable (L.mem s4 (stA (L.curW s4))) := by rw [ec4, e4]; exact runnable_restart + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.dfA s4 ct _ h4 hct) + (sched.set_thread_state.running_bxi h4.bxi hct e4)) fun s5 ⟨⟨f5, l5⟩, h5⟩ => ?_ + have d5 : DF st H Cs (L.curW s4) ∅ s4 s5 := by rw [ec4]; exact DF.ofKL f5 l5 (tc_le _ _) + exact (WP.spec_ok _).2 (DmPost.mk' + (SysL.df (Ko := ∅) P4 h4.bxi run4 (fun _ h => absurd h (Set.notMem_empty _)) B4 Y4 d5) + h5.blk (DmW.trans (DmW.ofDM M4) (DmW.ofDF d5))) + · try simp only [↓reduceIte] + exact (WP.spec_ok _).2 (DmPost.mk' ⟨B3, Y3⟩ h3 (DmW.ofDM M3)) + +set_option maxHeartbeats 8000000 in +/-- **SchedContext YieldTo keeps every capability** (module docstring), at `schedcontext.decode`. -/ +theorem schedcontext.decode.yieldToSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl p b : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedContext p b) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.SchedContext p b)) (hl : lbl = fl4_abi.label.SchedContextYieldTo) : + schedcontext.decode st ar s a lbl p call extra ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + obtain ⟨hp, hp0, hpi⟩ := D.cap.2.2 p b rfl + have h := D.bxi + have hct : L.curW s ∈ H.tcbs := h.1.choose_spec.choose_spec.curT + have Dm : ∀ {s' : S}, DmPost st H Cs OS ia ie Ac s s' → + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := + fun d => (fun x => ⟨x.1, x.2.1.toDel, x.2.2.2, x.2.2.1⟩) + (ArmQIAt.ofDMK (Vc := Vc) D P B I.del.vr hks hSA d.w d.sys d.blk) + unfold schedcontext.decode + step with obj.Sc.tcb.spec as ⟨i, ei⟩ + refine WP.spec_bind (Pₘ := fun r : S × A => + Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s r.1 ∧ + DF st H Cs (L.curW s) ∅ s r.1) ?_ ?_ + · split + · refine WP.spec_mono (smp.remote_tcb_stall.stS hA a i D.bxi) ?_ + rintro ⟨s1, a1⟩ hh + simp only [WP.uncurry'_pair] at hh + exact hh + · exact (WP.spec_ok _).2 ⟨Stalled.refl0 D, DF.refl _⟩ + rintro ⟨s1, a1⟩ ⟨h1, d1⟩ + try simp only [uncurry_apply_pair] + have E1 : DmPost st H Cs OS ia ie Ac s s1 := + DmPost.mk' (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + h1.bxi.blk (DmW.ofDF d1) + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have ect' : ct = L.curW s := (show ct = L.curW s1 from ect).trans h1.cur + subst ect' + iterate 4 + refine spec_ite (fun hc => absurd (hl.symm.trans hc) (lbl_ne_of_val (by + simp [fl4_abi.label.SchedContextConsumed, fl4_abi.label.SchedContextBind, + fl4_abi.label.SchedContextUnbindObject, fl4_abi.label.SchedContextUnbind, + fl4_abi.label.SchedContextYieldTo]))) fun _ => ?_ + refine spec_ite (fun _ => ?_) fun hc => absurd hl hc + refine WP.spec_bind (obj.Sc.tcb.spec s1 p) fun i1 ei1 => ?_ + refine WP.spec_bind (obj.Tcb.is_null.spec i1) fun bn ebn => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hbn + refine WP.spec_bind (tcb_eq.blk i1 (L.curW s)) fun be ebe => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hbe + refine WP.spec_bind (obj.Tcb.prio.spec s1 i1) fun i2 _ => ?_ + refine WP.spec_bind (P0.obj.Tcb.mcp.p0 st (L.curW s) s1 hS) fun i3 _ => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + refine WP.spec_bind (obj.Tcb.yield_to.spec s1 (L.curW s)) fun i4 ei4 => ?_ + split + · simp only [error.illegal, bind_ok]; exact (WP.spec_ok _).2 (Dm E1) + rename_i hi4 + have run1 : Runnable (L.mem s1 (stA (L.curW s))) := by + rw [stA_eq, h1.fld _ hct _ (by simp) (by simp), ← stA_eq]; exact D.run + refine WP.spec_bind (WP.spec_and (sched.set_thread_state.restartRK D P B Y h1 d1) + (sched.set_thread_state.restart_blk (Es := ∅) s1 (L.curW s) h1.bxi.blk hct (runnable_ok run1).1 + (runnable_ok run1).2)) ?_ + rintro s2 ⟨⟨R, d2⟩, -, -, e2, k2⟩ + have hc2 : L.curW s2 = L.curW s := (KeepT.curW k2).trans h1.cur + have t2 : L.mem s2 (scTcbA p) = i1 := (k2.fix p hp).1.trans ei1.symm + have y2 : L.mem s2 (yieldA (L.curW s)) = 0#u64 := by + unfold yieldA + rw [k2.fld _ hct _ (by simp) (by simp) (by simp) (by simp) (fun _ => ⟨by simp, by simp⟩)] + rw [← yieldA, ← ei4]; exact UScalar.eq_of_val_eq (by simpa using hi4) + have sc2 : L.mem s2 (scA (L.curW s)) = L.mem s (scA (L.curW s)) := by + rw [k2.scf hct, scA_eq, h1.fld _ hct _ (by simp) (by simp), ← scA_eq] + refine WP.spec_bind (schedcontext.yield_to.dmPost hA a1 p call R hSA hcap hp + (by rw [hc2]; exact e2) + (by rw [t2]; intro e; exact hbn (by rw [ebn, e]; rfl)) + (by rw [t2, hc2]; intro e; exact hbe (by rw [ebe, e]; simp)) + (by rw [hc2]; exact y2) + (by rw [hc2, sc2]; exact h.2.1.resume D.act) + (by rw [hc2, sc2]; exact D.cb.ac (h.2.1.resume D.act)) + (by rw [hc2, inqA_eq, k2.fld _ hct _ (by simp) (by simp) (by simp) (by simp) (fun _ => ⟨by simp, by simp⟩), + h1.fld _ hct _ (by simp) (by simp), ← inqA_eq]; exact D.cb.nr)) ?_ + rintro ⟨s3, a3⟩ d3 + try simp only [uncurry_apply_pair] + exact (WP.spec_ok _).2 (Dm (DmPost.mk' d3.sys d3.blk (DmW.trans (DmW.ofDF d2) d3.w))) + +/-- **SchedContext YieldTo keeps every capability** (the SchedContext arm of `decode_invocation`, `*_armS`). -/ +theorem syscall.decode_invocation.scYieldTo_armS (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p b : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.SchedContext p b) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hSA : ScApart H.scs H.scBits OS) + (hcap : obj.Slot.cap st slot s = ok (.SchedContext p b)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.SchedContextYieldTo) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.SchedContext p b) blk call don fp buf extra ⦃ _ s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + split + · refine (WP.spec_ok _).mpr ?_ + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeepOrZero.refl s, ArmVsK.refl s, OSKeep.rfl' s⟩) + · exact WP.spec_mono (schedcontext.decode.yieldToSAt hA I D P B Y hks hSA hcap hl) fun r d => by + obtain ⟨_, s', a'⟩ := r + exact d + +end Fl4ProofsA64.P1.W7.R.ST